18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Silicon Image SiI8620 HDMI/MHL bridge driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2015, Samsung Electronics Co., Ltd.
68c2ecf20Sopenharmony_ci * Andrzej Hajda <a.hajda@samsung.com>
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <asm/unaligned.h>
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <drm/bridge/mhl.h>
128c2ecf20Sopenharmony_ci#include <drm/drm_bridge.h>
138c2ecf20Sopenharmony_ci#include <drm/drm_crtc.h>
148c2ecf20Sopenharmony_ci#include <drm/drm_edid.h>
158c2ecf20Sopenharmony_ci#include <drm/drm_encoder.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include <linux/clk.h>
188c2ecf20Sopenharmony_ci#include <linux/delay.h>
198c2ecf20Sopenharmony_ci#include <linux/extcon.h>
208c2ecf20Sopenharmony_ci#include <linux/gpio/consumer.h>
218c2ecf20Sopenharmony_ci#include <linux/i2c.h>
228c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
238c2ecf20Sopenharmony_ci#include <linux/irq.h>
248c2ecf20Sopenharmony_ci#include <linux/kernel.h>
258c2ecf20Sopenharmony_ci#include <linux/list.h>
268c2ecf20Sopenharmony_ci#include <linux/module.h>
278c2ecf20Sopenharmony_ci#include <linux/mutex.h>
288c2ecf20Sopenharmony_ci#include <linux/of_graph.h>
298c2ecf20Sopenharmony_ci#include <linux/regulator/consumer.h>
308c2ecf20Sopenharmony_ci#include <linux/slab.h>
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#include <media/rc-core.h>
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#include "sil-sii8620.h"
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#define SII8620_BURST_BUF_LEN 288
378c2ecf20Sopenharmony_ci#define VAL_RX_HDMI_CTRL2_DEFVAL VAL_RX_HDMI_CTRL2_IDLE_CNT(3)
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define MHL1_MAX_PCLK 75000
408c2ecf20Sopenharmony_ci#define MHL1_MAX_PCLK_PP_MODE 150000
418c2ecf20Sopenharmony_ci#define MHL3_MAX_PCLK 200000
428c2ecf20Sopenharmony_ci#define MHL3_MAX_PCLK_PP_MODE 300000
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cienum sii8620_mode {
458c2ecf20Sopenharmony_ci	CM_DISCONNECTED,
468c2ecf20Sopenharmony_ci	CM_DISCOVERY,
478c2ecf20Sopenharmony_ci	CM_MHL1,
488c2ecf20Sopenharmony_ci	CM_MHL3,
498c2ecf20Sopenharmony_ci	CM_ECBUS_S
508c2ecf20Sopenharmony_ci};
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_cienum sii8620_sink_type {
538c2ecf20Sopenharmony_ci	SINK_NONE,
548c2ecf20Sopenharmony_ci	SINK_HDMI,
558c2ecf20Sopenharmony_ci	SINK_DVI
568c2ecf20Sopenharmony_ci};
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cienum sii8620_mt_state {
598c2ecf20Sopenharmony_ci	MT_STATE_READY,
608c2ecf20Sopenharmony_ci	MT_STATE_BUSY,
618c2ecf20Sopenharmony_ci	MT_STATE_DONE
628c2ecf20Sopenharmony_ci};
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_cistruct sii8620 {
658c2ecf20Sopenharmony_ci	struct drm_bridge bridge;
668c2ecf20Sopenharmony_ci	struct device *dev;
678c2ecf20Sopenharmony_ci	struct rc_dev *rc_dev;
688c2ecf20Sopenharmony_ci	struct clk *clk_xtal;
698c2ecf20Sopenharmony_ci	struct gpio_desc *gpio_reset;
708c2ecf20Sopenharmony_ci	struct gpio_desc *gpio_int;
718c2ecf20Sopenharmony_ci	struct regulator_bulk_data supplies[2];
728c2ecf20Sopenharmony_ci	struct mutex lock; /* context lock, protects fields below */
738c2ecf20Sopenharmony_ci	int error;
748c2ecf20Sopenharmony_ci	unsigned int use_packed_pixel:1;
758c2ecf20Sopenharmony_ci	enum sii8620_mode mode;
768c2ecf20Sopenharmony_ci	enum sii8620_sink_type sink_type;
778c2ecf20Sopenharmony_ci	u8 cbus_status;
788c2ecf20Sopenharmony_ci	u8 stat[MHL_DST_SIZE];
798c2ecf20Sopenharmony_ci	u8 xstat[MHL_XDS_SIZE];
808c2ecf20Sopenharmony_ci	u8 devcap[MHL_DCAP_SIZE];
818c2ecf20Sopenharmony_ci	u8 xdevcap[MHL_XDC_SIZE];
828c2ecf20Sopenharmony_ci	bool feature_complete;
838c2ecf20Sopenharmony_ci	bool devcap_read;
848c2ecf20Sopenharmony_ci	bool sink_detected;
858c2ecf20Sopenharmony_ci	struct edid *edid;
868c2ecf20Sopenharmony_ci	unsigned int gen2_write_burst:1;
878c2ecf20Sopenharmony_ci	enum sii8620_mt_state mt_state;
888c2ecf20Sopenharmony_ci	struct extcon_dev *extcon;
898c2ecf20Sopenharmony_ci	struct notifier_block extcon_nb;
908c2ecf20Sopenharmony_ci	struct work_struct extcon_wq;
918c2ecf20Sopenharmony_ci	int cable_state;
928c2ecf20Sopenharmony_ci	struct list_head mt_queue;
938c2ecf20Sopenharmony_ci	struct {
948c2ecf20Sopenharmony_ci		int r_size;
958c2ecf20Sopenharmony_ci		int r_count;
968c2ecf20Sopenharmony_ci		int rx_ack;
978c2ecf20Sopenharmony_ci		int rx_count;
988c2ecf20Sopenharmony_ci		u8 rx_buf[32];
998c2ecf20Sopenharmony_ci		int tx_count;
1008c2ecf20Sopenharmony_ci		u8 tx_buf[32];
1018c2ecf20Sopenharmony_ci	} burst;
1028c2ecf20Sopenharmony_ci};
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_cistruct sii8620_mt_msg;
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_citypedef void (*sii8620_mt_msg_cb)(struct sii8620 *ctx,
1078c2ecf20Sopenharmony_ci				  struct sii8620_mt_msg *msg);
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_citypedef void (*sii8620_cb)(struct sii8620 *ctx, int ret);
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_cistruct sii8620_mt_msg {
1128c2ecf20Sopenharmony_ci	struct list_head node;
1138c2ecf20Sopenharmony_ci	u8 reg[4];
1148c2ecf20Sopenharmony_ci	u8 ret;
1158c2ecf20Sopenharmony_ci	sii8620_mt_msg_cb send;
1168c2ecf20Sopenharmony_ci	sii8620_mt_msg_cb recv;
1178c2ecf20Sopenharmony_ci	sii8620_cb continuation;
1188c2ecf20Sopenharmony_ci};
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_cistatic const u8 sii8620_i2c_page[] = {
1218c2ecf20Sopenharmony_ci	0x39, /* Main System */
1228c2ecf20Sopenharmony_ci	0x3d, /* TDM and HSIC */
1238c2ecf20Sopenharmony_ci	0x49, /* TMDS Receiver, MHL EDID */
1248c2ecf20Sopenharmony_ci	0x4d, /* eMSC, HDCP, HSIC */
1258c2ecf20Sopenharmony_ci	0x5d, /* MHL Spec */
1268c2ecf20Sopenharmony_ci	0x64, /* MHL CBUS */
1278c2ecf20Sopenharmony_ci	0x59, /* Hardware TPI (Transmitter Programming Interface) */
1288c2ecf20Sopenharmony_ci	0x61, /* eCBUS-S, eCBUS-D */
1298c2ecf20Sopenharmony_ci};
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_cistatic void sii8620_fetch_edid(struct sii8620 *ctx);
1328c2ecf20Sopenharmony_cistatic void sii8620_set_upstream_edid(struct sii8620 *ctx);
1338c2ecf20Sopenharmony_cistatic void sii8620_enable_hpd(struct sii8620 *ctx);
1348c2ecf20Sopenharmony_cistatic void sii8620_mhl_disconnected(struct sii8620 *ctx);
1358c2ecf20Sopenharmony_cistatic void sii8620_disconnect(struct sii8620 *ctx);
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_cistatic int sii8620_clear_error(struct sii8620 *ctx)
1388c2ecf20Sopenharmony_ci{
1398c2ecf20Sopenharmony_ci	int ret = ctx->error;
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci	ctx->error = 0;
1428c2ecf20Sopenharmony_ci	return ret;
1438c2ecf20Sopenharmony_ci}
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_cistatic void sii8620_read_buf(struct sii8620 *ctx, u16 addr, u8 *buf, int len)
1468c2ecf20Sopenharmony_ci{
1478c2ecf20Sopenharmony_ci	struct device *dev = ctx->dev;
1488c2ecf20Sopenharmony_ci	struct i2c_client *client = to_i2c_client(dev);
1498c2ecf20Sopenharmony_ci	u8 data = addr;
1508c2ecf20Sopenharmony_ci	struct i2c_msg msg[] = {
1518c2ecf20Sopenharmony_ci		{
1528c2ecf20Sopenharmony_ci			.addr = sii8620_i2c_page[addr >> 8],
1538c2ecf20Sopenharmony_ci			.flags = client->flags,
1548c2ecf20Sopenharmony_ci			.len = 1,
1558c2ecf20Sopenharmony_ci			.buf = &data
1568c2ecf20Sopenharmony_ci		},
1578c2ecf20Sopenharmony_ci		{
1588c2ecf20Sopenharmony_ci			.addr = sii8620_i2c_page[addr >> 8],
1598c2ecf20Sopenharmony_ci			.flags = client->flags | I2C_M_RD,
1608c2ecf20Sopenharmony_ci			.len = len,
1618c2ecf20Sopenharmony_ci			.buf = buf
1628c2ecf20Sopenharmony_ci		},
1638c2ecf20Sopenharmony_ci	};
1648c2ecf20Sopenharmony_ci	int ret;
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci	if (ctx->error)
1678c2ecf20Sopenharmony_ci		return;
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci	ret = i2c_transfer(client->adapter, msg, 2);
1708c2ecf20Sopenharmony_ci	dev_dbg(dev, "read at %04x: %*ph, %d\n", addr, len, buf, ret);
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci	if (ret != 2) {
1738c2ecf20Sopenharmony_ci		dev_err(dev, "Read at %#06x of %d bytes failed with code %d.\n",
1748c2ecf20Sopenharmony_ci			addr, len, ret);
1758c2ecf20Sopenharmony_ci		ctx->error = ret < 0 ? ret : -EIO;
1768c2ecf20Sopenharmony_ci	}
1778c2ecf20Sopenharmony_ci}
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_cistatic u8 sii8620_readb(struct sii8620 *ctx, u16 addr)
1808c2ecf20Sopenharmony_ci{
1818c2ecf20Sopenharmony_ci	u8 ret = 0;
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci	sii8620_read_buf(ctx, addr, &ret, 1);
1848c2ecf20Sopenharmony_ci	return ret;
1858c2ecf20Sopenharmony_ci}
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_cistatic void sii8620_write_buf(struct sii8620 *ctx, u16 addr, const u8 *buf,
1888c2ecf20Sopenharmony_ci			      int len)
1898c2ecf20Sopenharmony_ci{
1908c2ecf20Sopenharmony_ci	struct device *dev = ctx->dev;
1918c2ecf20Sopenharmony_ci	struct i2c_client *client = to_i2c_client(dev);
1928c2ecf20Sopenharmony_ci	u8 data[2];
1938c2ecf20Sopenharmony_ci	struct i2c_msg msg = {
1948c2ecf20Sopenharmony_ci		.addr = sii8620_i2c_page[addr >> 8],
1958c2ecf20Sopenharmony_ci		.flags = client->flags,
1968c2ecf20Sopenharmony_ci		.len = len + 1,
1978c2ecf20Sopenharmony_ci	};
1988c2ecf20Sopenharmony_ci	int ret;
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci	if (ctx->error)
2018c2ecf20Sopenharmony_ci		return;
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci	if (len > 1) {
2048c2ecf20Sopenharmony_ci		msg.buf = kmalloc(len + 1, GFP_KERNEL);
2058c2ecf20Sopenharmony_ci		if (!msg.buf) {
2068c2ecf20Sopenharmony_ci			ctx->error = -ENOMEM;
2078c2ecf20Sopenharmony_ci			return;
2088c2ecf20Sopenharmony_ci		}
2098c2ecf20Sopenharmony_ci		memcpy(msg.buf + 1, buf, len);
2108c2ecf20Sopenharmony_ci	} else {
2118c2ecf20Sopenharmony_ci		msg.buf = data;
2128c2ecf20Sopenharmony_ci		msg.buf[1] = *buf;
2138c2ecf20Sopenharmony_ci	}
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci	msg.buf[0] = addr;
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci	ret = i2c_transfer(client->adapter, &msg, 1);
2188c2ecf20Sopenharmony_ci	dev_dbg(dev, "write at %04x: %*ph, %d\n", addr, len, buf, ret);
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ci	if (ret != 1) {
2218c2ecf20Sopenharmony_ci		dev_err(dev, "Write at %#06x of %*ph failed with code %d.\n",
2228c2ecf20Sopenharmony_ci			addr, len, buf, ret);
2238c2ecf20Sopenharmony_ci		ctx->error = ret ?: -EIO;
2248c2ecf20Sopenharmony_ci	}
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ci	if (len > 1)
2278c2ecf20Sopenharmony_ci		kfree(msg.buf);
2288c2ecf20Sopenharmony_ci}
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_ci#define sii8620_write(ctx, addr, arr...) \
2318c2ecf20Sopenharmony_ci({\
2328c2ecf20Sopenharmony_ci	u8 d[] = { arr }; \
2338c2ecf20Sopenharmony_ci	sii8620_write_buf(ctx, addr, d, ARRAY_SIZE(d)); \
2348c2ecf20Sopenharmony_ci})
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_cistatic void __sii8620_write_seq(struct sii8620 *ctx, const u16 *seq, int len)
2378c2ecf20Sopenharmony_ci{
2388c2ecf20Sopenharmony_ci	int i;
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci	for (i = 0; i < len; i += 2)
2418c2ecf20Sopenharmony_ci		sii8620_write(ctx, seq[i], seq[i + 1]);
2428c2ecf20Sopenharmony_ci}
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ci#define sii8620_write_seq(ctx, seq...) \
2458c2ecf20Sopenharmony_ci({\
2468c2ecf20Sopenharmony_ci	const u16 d[] = { seq }; \
2478c2ecf20Sopenharmony_ci	__sii8620_write_seq(ctx, d, ARRAY_SIZE(d)); \
2488c2ecf20Sopenharmony_ci})
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci#define sii8620_write_seq_static(ctx, seq...) \
2518c2ecf20Sopenharmony_ci({\
2528c2ecf20Sopenharmony_ci	static const u16 d[] = { seq }; \
2538c2ecf20Sopenharmony_ci	__sii8620_write_seq(ctx, d, ARRAY_SIZE(d)); \
2548c2ecf20Sopenharmony_ci})
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_cistatic void sii8620_setbits(struct sii8620 *ctx, u16 addr, u8 mask, u8 val)
2578c2ecf20Sopenharmony_ci{
2588c2ecf20Sopenharmony_ci	val = (val & mask) | (sii8620_readb(ctx, addr) & ~mask);
2598c2ecf20Sopenharmony_ci	sii8620_write(ctx, addr, val);
2608c2ecf20Sopenharmony_ci}
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_cistatic inline bool sii8620_is_mhl3(struct sii8620 *ctx)
2638c2ecf20Sopenharmony_ci{
2648c2ecf20Sopenharmony_ci	return ctx->mode >= CM_MHL3;
2658c2ecf20Sopenharmony_ci}
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_cistatic void sii8620_mt_cleanup(struct sii8620 *ctx)
2688c2ecf20Sopenharmony_ci{
2698c2ecf20Sopenharmony_ci	struct sii8620_mt_msg *msg, *n;
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_ci	list_for_each_entry_safe(msg, n, &ctx->mt_queue, node) {
2728c2ecf20Sopenharmony_ci		list_del(&msg->node);
2738c2ecf20Sopenharmony_ci		kfree(msg);
2748c2ecf20Sopenharmony_ci	}
2758c2ecf20Sopenharmony_ci	ctx->mt_state = MT_STATE_READY;
2768c2ecf20Sopenharmony_ci}
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_cistatic void sii8620_mt_work(struct sii8620 *ctx)
2798c2ecf20Sopenharmony_ci{
2808c2ecf20Sopenharmony_ci	struct sii8620_mt_msg *msg;
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci	if (ctx->error)
2838c2ecf20Sopenharmony_ci		return;
2848c2ecf20Sopenharmony_ci	if (ctx->mt_state == MT_STATE_BUSY || list_empty(&ctx->mt_queue))
2858c2ecf20Sopenharmony_ci		return;
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci	if (ctx->mt_state == MT_STATE_DONE) {
2888c2ecf20Sopenharmony_ci		ctx->mt_state = MT_STATE_READY;
2898c2ecf20Sopenharmony_ci		msg = list_first_entry(&ctx->mt_queue, struct sii8620_mt_msg,
2908c2ecf20Sopenharmony_ci				       node);
2918c2ecf20Sopenharmony_ci		list_del(&msg->node);
2928c2ecf20Sopenharmony_ci		if (msg->recv)
2938c2ecf20Sopenharmony_ci			msg->recv(ctx, msg);
2948c2ecf20Sopenharmony_ci		if (msg->continuation)
2958c2ecf20Sopenharmony_ci			msg->continuation(ctx, msg->ret);
2968c2ecf20Sopenharmony_ci		kfree(msg);
2978c2ecf20Sopenharmony_ci	}
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_ci	if (ctx->mt_state != MT_STATE_READY || list_empty(&ctx->mt_queue))
3008c2ecf20Sopenharmony_ci		return;
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_ci	ctx->mt_state = MT_STATE_BUSY;
3038c2ecf20Sopenharmony_ci	msg = list_first_entry(&ctx->mt_queue, struct sii8620_mt_msg, node);
3048c2ecf20Sopenharmony_ci	if (msg->send)
3058c2ecf20Sopenharmony_ci		msg->send(ctx, msg);
3068c2ecf20Sopenharmony_ci}
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_cistatic void sii8620_enable_gen2_write_burst(struct sii8620 *ctx)
3098c2ecf20Sopenharmony_ci{
3108c2ecf20Sopenharmony_ci	u8 ctrl = BIT_MDT_RCV_CTRL_MDT_RCV_EN;
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci	if (ctx->gen2_write_burst)
3138c2ecf20Sopenharmony_ci		return;
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci	if (ctx->mode >= CM_MHL1)
3168c2ecf20Sopenharmony_ci		ctrl |= BIT_MDT_RCV_CTRL_MDT_DELAY_RCV_EN;
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci	sii8620_write_seq(ctx,
3198c2ecf20Sopenharmony_ci		REG_MDT_RCV_TIMEOUT, 100,
3208c2ecf20Sopenharmony_ci		REG_MDT_RCV_CTRL, ctrl
3218c2ecf20Sopenharmony_ci	);
3228c2ecf20Sopenharmony_ci	ctx->gen2_write_burst = 1;
3238c2ecf20Sopenharmony_ci}
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_cistatic void sii8620_disable_gen2_write_burst(struct sii8620 *ctx)
3268c2ecf20Sopenharmony_ci{
3278c2ecf20Sopenharmony_ci	if (!ctx->gen2_write_burst)
3288c2ecf20Sopenharmony_ci		return;
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci	sii8620_write_seq_static(ctx,
3318c2ecf20Sopenharmony_ci		REG_MDT_XMIT_CTRL, 0,
3328c2ecf20Sopenharmony_ci		REG_MDT_RCV_CTRL, 0
3338c2ecf20Sopenharmony_ci	);
3348c2ecf20Sopenharmony_ci	ctx->gen2_write_burst = 0;
3358c2ecf20Sopenharmony_ci}
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_cistatic void sii8620_start_gen2_write_burst(struct sii8620 *ctx)
3388c2ecf20Sopenharmony_ci{
3398c2ecf20Sopenharmony_ci	sii8620_write_seq_static(ctx,
3408c2ecf20Sopenharmony_ci		REG_MDT_INT_1_MASK, BIT_MDT_RCV_TIMEOUT
3418c2ecf20Sopenharmony_ci			| BIT_MDT_RCV_SM_ABORT_PKT_RCVD | BIT_MDT_RCV_SM_ERROR
3428c2ecf20Sopenharmony_ci			| BIT_MDT_XMIT_TIMEOUT | BIT_MDT_XMIT_SM_ABORT_PKT_RCVD
3438c2ecf20Sopenharmony_ci			| BIT_MDT_XMIT_SM_ERROR,
3448c2ecf20Sopenharmony_ci		REG_MDT_INT_0_MASK, BIT_MDT_XFIFO_EMPTY
3458c2ecf20Sopenharmony_ci			| BIT_MDT_IDLE_AFTER_HAWB_DISABLE
3468c2ecf20Sopenharmony_ci			| BIT_MDT_RFIFO_DATA_RDY
3478c2ecf20Sopenharmony_ci	);
3488c2ecf20Sopenharmony_ci	sii8620_enable_gen2_write_burst(ctx);
3498c2ecf20Sopenharmony_ci}
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_cistatic void sii8620_mt_msc_cmd_send(struct sii8620 *ctx,
3528c2ecf20Sopenharmony_ci				    struct sii8620_mt_msg *msg)
3538c2ecf20Sopenharmony_ci{
3548c2ecf20Sopenharmony_ci	if (msg->reg[0] == MHL_SET_INT &&
3558c2ecf20Sopenharmony_ci	    msg->reg[1] == MHL_INT_REG(RCHANGE) &&
3568c2ecf20Sopenharmony_ci	    msg->reg[2] == MHL_INT_RC_FEAT_REQ)
3578c2ecf20Sopenharmony_ci		sii8620_enable_gen2_write_burst(ctx);
3588c2ecf20Sopenharmony_ci	else
3598c2ecf20Sopenharmony_ci		sii8620_disable_gen2_write_burst(ctx);
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_ci	switch (msg->reg[0]) {
3628c2ecf20Sopenharmony_ci	case MHL_WRITE_STAT:
3638c2ecf20Sopenharmony_ci	case MHL_SET_INT:
3648c2ecf20Sopenharmony_ci		sii8620_write_buf(ctx, REG_MSC_CMD_OR_OFFSET, msg->reg + 1, 2);
3658c2ecf20Sopenharmony_ci		sii8620_write(ctx, REG_MSC_COMMAND_START,
3668c2ecf20Sopenharmony_ci			      BIT_MSC_COMMAND_START_WRITE_STAT);
3678c2ecf20Sopenharmony_ci		break;
3688c2ecf20Sopenharmony_ci	case MHL_MSC_MSG:
3698c2ecf20Sopenharmony_ci		sii8620_write_buf(ctx, REG_MSC_CMD_OR_OFFSET, msg->reg, 3);
3708c2ecf20Sopenharmony_ci		sii8620_write(ctx, REG_MSC_COMMAND_START,
3718c2ecf20Sopenharmony_ci			      BIT_MSC_COMMAND_START_MSC_MSG);
3728c2ecf20Sopenharmony_ci		break;
3738c2ecf20Sopenharmony_ci	case MHL_READ_DEVCAP_REG:
3748c2ecf20Sopenharmony_ci	case MHL_READ_XDEVCAP_REG:
3758c2ecf20Sopenharmony_ci		sii8620_write(ctx, REG_MSC_CMD_OR_OFFSET, msg->reg[1]);
3768c2ecf20Sopenharmony_ci		sii8620_write(ctx, REG_MSC_COMMAND_START,
3778c2ecf20Sopenharmony_ci			      BIT_MSC_COMMAND_START_READ_DEVCAP);
3788c2ecf20Sopenharmony_ci		break;
3798c2ecf20Sopenharmony_ci	default:
3808c2ecf20Sopenharmony_ci		dev_err(ctx->dev, "%s: command %#x not supported\n", __func__,
3818c2ecf20Sopenharmony_ci			msg->reg[0]);
3828c2ecf20Sopenharmony_ci	}
3838c2ecf20Sopenharmony_ci}
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_cistatic struct sii8620_mt_msg *sii8620_mt_msg_new(struct sii8620 *ctx)
3868c2ecf20Sopenharmony_ci{
3878c2ecf20Sopenharmony_ci	struct sii8620_mt_msg *msg = kzalloc(sizeof(*msg), GFP_KERNEL);
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci	if (!msg)
3908c2ecf20Sopenharmony_ci		ctx->error = -ENOMEM;
3918c2ecf20Sopenharmony_ci	else
3928c2ecf20Sopenharmony_ci		list_add_tail(&msg->node, &ctx->mt_queue);
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_ci	return msg;
3958c2ecf20Sopenharmony_ci}
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_cistatic void sii8620_mt_set_cont(struct sii8620 *ctx, sii8620_cb cont)
3988c2ecf20Sopenharmony_ci{
3998c2ecf20Sopenharmony_ci	struct sii8620_mt_msg *msg;
4008c2ecf20Sopenharmony_ci
4018c2ecf20Sopenharmony_ci	if (ctx->error)
4028c2ecf20Sopenharmony_ci		return;
4038c2ecf20Sopenharmony_ci
4048c2ecf20Sopenharmony_ci	if (list_empty(&ctx->mt_queue)) {
4058c2ecf20Sopenharmony_ci		ctx->error = -EINVAL;
4068c2ecf20Sopenharmony_ci		return;
4078c2ecf20Sopenharmony_ci	}
4088c2ecf20Sopenharmony_ci	msg = list_last_entry(&ctx->mt_queue, struct sii8620_mt_msg, node);
4098c2ecf20Sopenharmony_ci	msg->continuation = cont;
4108c2ecf20Sopenharmony_ci}
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_cistatic void sii8620_mt_msc_cmd(struct sii8620 *ctx, u8 cmd, u8 arg1, u8 arg2)
4138c2ecf20Sopenharmony_ci{
4148c2ecf20Sopenharmony_ci	struct sii8620_mt_msg *msg = sii8620_mt_msg_new(ctx);
4158c2ecf20Sopenharmony_ci
4168c2ecf20Sopenharmony_ci	if (!msg)
4178c2ecf20Sopenharmony_ci		return;
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ci	msg->reg[0] = cmd;
4208c2ecf20Sopenharmony_ci	msg->reg[1] = arg1;
4218c2ecf20Sopenharmony_ci	msg->reg[2] = arg2;
4228c2ecf20Sopenharmony_ci	msg->send = sii8620_mt_msc_cmd_send;
4238c2ecf20Sopenharmony_ci}
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_cistatic void sii8620_mt_write_stat(struct sii8620 *ctx, u8 reg, u8 val)
4268c2ecf20Sopenharmony_ci{
4278c2ecf20Sopenharmony_ci	sii8620_mt_msc_cmd(ctx, MHL_WRITE_STAT, reg, val);
4288c2ecf20Sopenharmony_ci}
4298c2ecf20Sopenharmony_ci
4308c2ecf20Sopenharmony_cistatic inline void sii8620_mt_set_int(struct sii8620 *ctx, u8 irq, u8 mask)
4318c2ecf20Sopenharmony_ci{
4328c2ecf20Sopenharmony_ci	sii8620_mt_msc_cmd(ctx, MHL_SET_INT, irq, mask);
4338c2ecf20Sopenharmony_ci}
4348c2ecf20Sopenharmony_ci
4358c2ecf20Sopenharmony_cistatic void sii8620_mt_msc_msg(struct sii8620 *ctx, u8 cmd, u8 data)
4368c2ecf20Sopenharmony_ci{
4378c2ecf20Sopenharmony_ci	sii8620_mt_msc_cmd(ctx, MHL_MSC_MSG, cmd, data);
4388c2ecf20Sopenharmony_ci}
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_cistatic void sii8620_mt_rap(struct sii8620 *ctx, u8 code)
4418c2ecf20Sopenharmony_ci{
4428c2ecf20Sopenharmony_ci	sii8620_mt_msc_msg(ctx, MHL_MSC_MSG_RAP, code);
4438c2ecf20Sopenharmony_ci}
4448c2ecf20Sopenharmony_ci
4458c2ecf20Sopenharmony_cistatic void sii8620_mt_rcpk(struct sii8620 *ctx, u8 code)
4468c2ecf20Sopenharmony_ci{
4478c2ecf20Sopenharmony_ci	sii8620_mt_msc_msg(ctx, MHL_MSC_MSG_RCPK, code);
4488c2ecf20Sopenharmony_ci}
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_cistatic void sii8620_mt_rcpe(struct sii8620 *ctx, u8 code)
4518c2ecf20Sopenharmony_ci{
4528c2ecf20Sopenharmony_ci	sii8620_mt_msc_msg(ctx, MHL_MSC_MSG_RCPE, code);
4538c2ecf20Sopenharmony_ci}
4548c2ecf20Sopenharmony_ci
4558c2ecf20Sopenharmony_cistatic void sii8620_mt_read_devcap_send(struct sii8620 *ctx,
4568c2ecf20Sopenharmony_ci					struct sii8620_mt_msg *msg)
4578c2ecf20Sopenharmony_ci{
4588c2ecf20Sopenharmony_ci	u8 ctrl = BIT_EDID_CTRL_DEVCAP_SELECT_DEVCAP
4598c2ecf20Sopenharmony_ci			| BIT_EDID_CTRL_EDID_FIFO_ADDR_AUTO
4608c2ecf20Sopenharmony_ci			| BIT_EDID_CTRL_EDID_MODE_EN;
4618c2ecf20Sopenharmony_ci
4628c2ecf20Sopenharmony_ci	if (msg->reg[0] == MHL_READ_XDEVCAP)
4638c2ecf20Sopenharmony_ci		ctrl |= BIT_EDID_CTRL_XDEVCAP_EN;
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_ci	sii8620_write_seq(ctx,
4668c2ecf20Sopenharmony_ci		REG_INTR9_MASK, BIT_INTR9_DEVCAP_DONE,
4678c2ecf20Sopenharmony_ci		REG_EDID_CTRL, ctrl,
4688c2ecf20Sopenharmony_ci		REG_TPI_CBUS_START, BIT_TPI_CBUS_START_GET_DEVCAP_START
4698c2ecf20Sopenharmony_ci	);
4708c2ecf20Sopenharmony_ci}
4718c2ecf20Sopenharmony_ci
4728c2ecf20Sopenharmony_ci/* copy src to dst and set changed bits in src */
4738c2ecf20Sopenharmony_cistatic void sii8620_update_array(u8 *dst, u8 *src, int count)
4748c2ecf20Sopenharmony_ci{
4758c2ecf20Sopenharmony_ci	while (--count >= 0) {
4768c2ecf20Sopenharmony_ci		*src ^= *dst;
4778c2ecf20Sopenharmony_ci		*dst++ ^= *src++;
4788c2ecf20Sopenharmony_ci	}
4798c2ecf20Sopenharmony_ci}
4808c2ecf20Sopenharmony_ci
4818c2ecf20Sopenharmony_cistatic void sii8620_identify_sink(struct sii8620 *ctx)
4828c2ecf20Sopenharmony_ci{
4838c2ecf20Sopenharmony_ci	static const char * const sink_str[] = {
4848c2ecf20Sopenharmony_ci		[SINK_NONE] = "NONE",
4858c2ecf20Sopenharmony_ci		[SINK_HDMI] = "HDMI",
4868c2ecf20Sopenharmony_ci		[SINK_DVI] = "DVI"
4878c2ecf20Sopenharmony_ci	};
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci	char sink_name[20];
4908c2ecf20Sopenharmony_ci	struct device *dev = ctx->dev;
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_ci	if (!ctx->sink_detected || !ctx->devcap_read)
4938c2ecf20Sopenharmony_ci		return;
4948c2ecf20Sopenharmony_ci
4958c2ecf20Sopenharmony_ci	sii8620_fetch_edid(ctx);
4968c2ecf20Sopenharmony_ci	if (!ctx->edid) {
4978c2ecf20Sopenharmony_ci		dev_err(ctx->dev, "Cannot fetch EDID\n");
4988c2ecf20Sopenharmony_ci		sii8620_mhl_disconnected(ctx);
4998c2ecf20Sopenharmony_ci		return;
5008c2ecf20Sopenharmony_ci	}
5018c2ecf20Sopenharmony_ci	sii8620_set_upstream_edid(ctx);
5028c2ecf20Sopenharmony_ci
5038c2ecf20Sopenharmony_ci	if (drm_detect_hdmi_monitor(ctx->edid))
5048c2ecf20Sopenharmony_ci		ctx->sink_type = SINK_HDMI;
5058c2ecf20Sopenharmony_ci	else
5068c2ecf20Sopenharmony_ci		ctx->sink_type = SINK_DVI;
5078c2ecf20Sopenharmony_ci
5088c2ecf20Sopenharmony_ci	drm_edid_get_monitor_name(ctx->edid, sink_name, ARRAY_SIZE(sink_name));
5098c2ecf20Sopenharmony_ci
5108c2ecf20Sopenharmony_ci	dev_info(dev, "detected sink(type: %s): %s\n",
5118c2ecf20Sopenharmony_ci		 sink_str[ctx->sink_type], sink_name);
5128c2ecf20Sopenharmony_ci}
5138c2ecf20Sopenharmony_ci
5148c2ecf20Sopenharmony_cistatic void sii8620_mr_devcap(struct sii8620 *ctx)
5158c2ecf20Sopenharmony_ci{
5168c2ecf20Sopenharmony_ci	u8 dcap[MHL_DCAP_SIZE];
5178c2ecf20Sopenharmony_ci	struct device *dev = ctx->dev;
5188c2ecf20Sopenharmony_ci
5198c2ecf20Sopenharmony_ci	sii8620_read_buf(ctx, REG_EDID_FIFO_RD_DATA, dcap, MHL_DCAP_SIZE);
5208c2ecf20Sopenharmony_ci	if (ctx->error < 0)
5218c2ecf20Sopenharmony_ci		return;
5228c2ecf20Sopenharmony_ci
5238c2ecf20Sopenharmony_ci	dev_info(dev, "detected dongle MHL %d.%d, ChipID %02x%02x:%02x%02x\n",
5248c2ecf20Sopenharmony_ci		 dcap[MHL_DCAP_MHL_VERSION] / 16,
5258c2ecf20Sopenharmony_ci		 dcap[MHL_DCAP_MHL_VERSION] % 16,
5268c2ecf20Sopenharmony_ci		 dcap[MHL_DCAP_ADOPTER_ID_H], dcap[MHL_DCAP_ADOPTER_ID_L],
5278c2ecf20Sopenharmony_ci		 dcap[MHL_DCAP_DEVICE_ID_H], dcap[MHL_DCAP_DEVICE_ID_L]);
5288c2ecf20Sopenharmony_ci	sii8620_update_array(ctx->devcap, dcap, MHL_DCAP_SIZE);
5298c2ecf20Sopenharmony_ci	ctx->devcap_read = true;
5308c2ecf20Sopenharmony_ci	sii8620_identify_sink(ctx);
5318c2ecf20Sopenharmony_ci}
5328c2ecf20Sopenharmony_ci
5338c2ecf20Sopenharmony_cistatic void sii8620_mr_xdevcap(struct sii8620 *ctx)
5348c2ecf20Sopenharmony_ci{
5358c2ecf20Sopenharmony_ci	sii8620_read_buf(ctx, REG_EDID_FIFO_RD_DATA, ctx->xdevcap,
5368c2ecf20Sopenharmony_ci			 MHL_XDC_SIZE);
5378c2ecf20Sopenharmony_ci}
5388c2ecf20Sopenharmony_ci
5398c2ecf20Sopenharmony_cistatic void sii8620_mt_read_devcap_recv(struct sii8620 *ctx,
5408c2ecf20Sopenharmony_ci					struct sii8620_mt_msg *msg)
5418c2ecf20Sopenharmony_ci{
5428c2ecf20Sopenharmony_ci	u8 ctrl = BIT_EDID_CTRL_DEVCAP_SELECT_DEVCAP
5438c2ecf20Sopenharmony_ci		| BIT_EDID_CTRL_EDID_FIFO_ADDR_AUTO
5448c2ecf20Sopenharmony_ci		| BIT_EDID_CTRL_EDID_MODE_EN;
5458c2ecf20Sopenharmony_ci
5468c2ecf20Sopenharmony_ci	if (msg->reg[0] == MHL_READ_XDEVCAP)
5478c2ecf20Sopenharmony_ci		ctrl |= BIT_EDID_CTRL_XDEVCAP_EN;
5488c2ecf20Sopenharmony_ci
5498c2ecf20Sopenharmony_ci	sii8620_write_seq(ctx,
5508c2ecf20Sopenharmony_ci		REG_INTR9_MASK, BIT_INTR9_DEVCAP_DONE | BIT_INTR9_EDID_DONE
5518c2ecf20Sopenharmony_ci			| BIT_INTR9_EDID_ERROR,
5528c2ecf20Sopenharmony_ci		REG_EDID_CTRL, ctrl,
5538c2ecf20Sopenharmony_ci		REG_EDID_FIFO_ADDR, 0
5548c2ecf20Sopenharmony_ci	);
5558c2ecf20Sopenharmony_ci
5568c2ecf20Sopenharmony_ci	if (msg->reg[0] == MHL_READ_XDEVCAP)
5578c2ecf20Sopenharmony_ci		sii8620_mr_xdevcap(ctx);
5588c2ecf20Sopenharmony_ci	else
5598c2ecf20Sopenharmony_ci		sii8620_mr_devcap(ctx);
5608c2ecf20Sopenharmony_ci}
5618c2ecf20Sopenharmony_ci
5628c2ecf20Sopenharmony_cistatic void sii8620_mt_read_devcap(struct sii8620 *ctx, bool xdevcap)
5638c2ecf20Sopenharmony_ci{
5648c2ecf20Sopenharmony_ci	struct sii8620_mt_msg *msg = sii8620_mt_msg_new(ctx);
5658c2ecf20Sopenharmony_ci
5668c2ecf20Sopenharmony_ci	if (!msg)
5678c2ecf20Sopenharmony_ci		return;
5688c2ecf20Sopenharmony_ci
5698c2ecf20Sopenharmony_ci	msg->reg[0] = xdevcap ? MHL_READ_XDEVCAP : MHL_READ_DEVCAP;
5708c2ecf20Sopenharmony_ci	msg->send = sii8620_mt_read_devcap_send;
5718c2ecf20Sopenharmony_ci	msg->recv = sii8620_mt_read_devcap_recv;
5728c2ecf20Sopenharmony_ci}
5738c2ecf20Sopenharmony_ci
5748c2ecf20Sopenharmony_cistatic void sii8620_mt_read_devcap_reg_recv(struct sii8620 *ctx,
5758c2ecf20Sopenharmony_ci		struct sii8620_mt_msg *msg)
5768c2ecf20Sopenharmony_ci{
5778c2ecf20Sopenharmony_ci	u8 reg = msg->reg[1] & 0x7f;
5788c2ecf20Sopenharmony_ci
5798c2ecf20Sopenharmony_ci	if (msg->reg[1] & 0x80)
5808c2ecf20Sopenharmony_ci		ctx->xdevcap[reg] = msg->ret;
5818c2ecf20Sopenharmony_ci	else
5828c2ecf20Sopenharmony_ci		ctx->devcap[reg] = msg->ret;
5838c2ecf20Sopenharmony_ci}
5848c2ecf20Sopenharmony_ci
5858c2ecf20Sopenharmony_cistatic void sii8620_mt_read_devcap_reg(struct sii8620 *ctx, u8 reg)
5868c2ecf20Sopenharmony_ci{
5878c2ecf20Sopenharmony_ci	struct sii8620_mt_msg *msg = sii8620_mt_msg_new(ctx);
5888c2ecf20Sopenharmony_ci
5898c2ecf20Sopenharmony_ci	if (!msg)
5908c2ecf20Sopenharmony_ci		return;
5918c2ecf20Sopenharmony_ci
5928c2ecf20Sopenharmony_ci	msg->reg[0] = (reg & 0x80) ? MHL_READ_XDEVCAP_REG : MHL_READ_DEVCAP_REG;
5938c2ecf20Sopenharmony_ci	msg->reg[1] = reg;
5948c2ecf20Sopenharmony_ci	msg->send = sii8620_mt_msc_cmd_send;
5958c2ecf20Sopenharmony_ci	msg->recv = sii8620_mt_read_devcap_reg_recv;
5968c2ecf20Sopenharmony_ci}
5978c2ecf20Sopenharmony_ci
5988c2ecf20Sopenharmony_cistatic inline void sii8620_mt_read_xdevcap_reg(struct sii8620 *ctx, u8 reg)
5998c2ecf20Sopenharmony_ci{
6008c2ecf20Sopenharmony_ci	sii8620_mt_read_devcap_reg(ctx, reg | 0x80);
6018c2ecf20Sopenharmony_ci}
6028c2ecf20Sopenharmony_ci
6038c2ecf20Sopenharmony_cistatic void *sii8620_burst_get_tx_buf(struct sii8620 *ctx, int len)
6048c2ecf20Sopenharmony_ci{
6058c2ecf20Sopenharmony_ci	u8 *buf = &ctx->burst.tx_buf[ctx->burst.tx_count];
6068c2ecf20Sopenharmony_ci	int size = len + 2;
6078c2ecf20Sopenharmony_ci
6088c2ecf20Sopenharmony_ci	if (ctx->burst.tx_count + size >= ARRAY_SIZE(ctx->burst.tx_buf)) {
6098c2ecf20Sopenharmony_ci		dev_err(ctx->dev, "TX-BLK buffer exhausted\n");
6108c2ecf20Sopenharmony_ci		ctx->error = -EINVAL;
6118c2ecf20Sopenharmony_ci		return NULL;
6128c2ecf20Sopenharmony_ci	}
6138c2ecf20Sopenharmony_ci
6148c2ecf20Sopenharmony_ci	ctx->burst.tx_count += size;
6158c2ecf20Sopenharmony_ci	buf[1] = len;
6168c2ecf20Sopenharmony_ci
6178c2ecf20Sopenharmony_ci	return buf + 2;
6188c2ecf20Sopenharmony_ci}
6198c2ecf20Sopenharmony_ci
6208c2ecf20Sopenharmony_cistatic u8 *sii8620_burst_get_rx_buf(struct sii8620 *ctx, int len)
6218c2ecf20Sopenharmony_ci{
6228c2ecf20Sopenharmony_ci	u8 *buf = &ctx->burst.rx_buf[ctx->burst.rx_count];
6238c2ecf20Sopenharmony_ci	int size = len + 1;
6248c2ecf20Sopenharmony_ci
6258c2ecf20Sopenharmony_ci	if (ctx->burst.rx_count + size >= ARRAY_SIZE(ctx->burst.rx_buf)) {
6268c2ecf20Sopenharmony_ci		dev_err(ctx->dev, "RX-BLK buffer exhausted\n");
6278c2ecf20Sopenharmony_ci		ctx->error = -EINVAL;
6288c2ecf20Sopenharmony_ci		return NULL;
6298c2ecf20Sopenharmony_ci	}
6308c2ecf20Sopenharmony_ci
6318c2ecf20Sopenharmony_ci	ctx->burst.rx_count += size;
6328c2ecf20Sopenharmony_ci	buf[0] = len;
6338c2ecf20Sopenharmony_ci
6348c2ecf20Sopenharmony_ci	return buf + 1;
6358c2ecf20Sopenharmony_ci}
6368c2ecf20Sopenharmony_ci
6378c2ecf20Sopenharmony_cistatic void sii8620_burst_send(struct sii8620 *ctx)
6388c2ecf20Sopenharmony_ci{
6398c2ecf20Sopenharmony_ci	int tx_left = ctx->burst.tx_count;
6408c2ecf20Sopenharmony_ci	u8 *d = ctx->burst.tx_buf;
6418c2ecf20Sopenharmony_ci
6428c2ecf20Sopenharmony_ci	while (tx_left > 0) {
6438c2ecf20Sopenharmony_ci		int len = d[1] + 2;
6448c2ecf20Sopenharmony_ci
6458c2ecf20Sopenharmony_ci		if (ctx->burst.r_count + len > ctx->burst.r_size)
6468c2ecf20Sopenharmony_ci			break;
6478c2ecf20Sopenharmony_ci		d[0] = min(ctx->burst.rx_ack, 255);
6488c2ecf20Sopenharmony_ci		ctx->burst.rx_ack -= d[0];
6498c2ecf20Sopenharmony_ci		sii8620_write_buf(ctx, REG_EMSC_XMIT_WRITE_PORT, d, len);
6508c2ecf20Sopenharmony_ci		ctx->burst.r_count += len;
6518c2ecf20Sopenharmony_ci		tx_left -= len;
6528c2ecf20Sopenharmony_ci		d += len;
6538c2ecf20Sopenharmony_ci	}
6548c2ecf20Sopenharmony_ci
6558c2ecf20Sopenharmony_ci	ctx->burst.tx_count = tx_left;
6568c2ecf20Sopenharmony_ci
6578c2ecf20Sopenharmony_ci	while (ctx->burst.rx_ack > 0) {
6588c2ecf20Sopenharmony_ci		u8 b[2] = { min(ctx->burst.rx_ack, 255), 0 };
6598c2ecf20Sopenharmony_ci
6608c2ecf20Sopenharmony_ci		if (ctx->burst.r_count + 2 > ctx->burst.r_size)
6618c2ecf20Sopenharmony_ci			break;
6628c2ecf20Sopenharmony_ci		ctx->burst.rx_ack -= b[0];
6638c2ecf20Sopenharmony_ci		sii8620_write_buf(ctx, REG_EMSC_XMIT_WRITE_PORT, b, 2);
6648c2ecf20Sopenharmony_ci		ctx->burst.r_count += 2;
6658c2ecf20Sopenharmony_ci	}
6668c2ecf20Sopenharmony_ci}
6678c2ecf20Sopenharmony_ci
6688c2ecf20Sopenharmony_cistatic void sii8620_burst_receive(struct sii8620 *ctx)
6698c2ecf20Sopenharmony_ci{
6708c2ecf20Sopenharmony_ci	u8 buf[3], *d;
6718c2ecf20Sopenharmony_ci	int count;
6728c2ecf20Sopenharmony_ci
6738c2ecf20Sopenharmony_ci	sii8620_read_buf(ctx, REG_EMSCRFIFOBCNTL, buf, 2);
6748c2ecf20Sopenharmony_ci	count = get_unaligned_le16(buf);
6758c2ecf20Sopenharmony_ci	while (count > 0) {
6768c2ecf20Sopenharmony_ci		int len = min(count, 3);
6778c2ecf20Sopenharmony_ci
6788c2ecf20Sopenharmony_ci		sii8620_read_buf(ctx, REG_EMSC_RCV_READ_PORT, buf, len);
6798c2ecf20Sopenharmony_ci		count -= len;
6808c2ecf20Sopenharmony_ci		ctx->burst.rx_ack += len - 1;
6818c2ecf20Sopenharmony_ci		ctx->burst.r_count -= buf[1];
6828c2ecf20Sopenharmony_ci		if (ctx->burst.r_count < 0)
6838c2ecf20Sopenharmony_ci			ctx->burst.r_count = 0;
6848c2ecf20Sopenharmony_ci
6858c2ecf20Sopenharmony_ci		if (len < 3 || !buf[2])
6868c2ecf20Sopenharmony_ci			continue;
6878c2ecf20Sopenharmony_ci
6888c2ecf20Sopenharmony_ci		len = buf[2];
6898c2ecf20Sopenharmony_ci		d = sii8620_burst_get_rx_buf(ctx, len);
6908c2ecf20Sopenharmony_ci		if (!d)
6918c2ecf20Sopenharmony_ci			continue;
6928c2ecf20Sopenharmony_ci		sii8620_read_buf(ctx, REG_EMSC_RCV_READ_PORT, d, len);
6938c2ecf20Sopenharmony_ci		count -= len;
6948c2ecf20Sopenharmony_ci		ctx->burst.rx_ack += len;
6958c2ecf20Sopenharmony_ci	}
6968c2ecf20Sopenharmony_ci}
6978c2ecf20Sopenharmony_ci
6988c2ecf20Sopenharmony_cistatic void sii8620_burst_tx_rbuf_info(struct sii8620 *ctx, int size)
6998c2ecf20Sopenharmony_ci{
7008c2ecf20Sopenharmony_ci	struct mhl_burst_blk_rcv_buffer_info *d =
7018c2ecf20Sopenharmony_ci		sii8620_burst_get_tx_buf(ctx, sizeof(*d));
7028c2ecf20Sopenharmony_ci	if (!d)
7038c2ecf20Sopenharmony_ci		return;
7048c2ecf20Sopenharmony_ci
7058c2ecf20Sopenharmony_ci	d->id = cpu_to_be16(MHL_BURST_ID_BLK_RCV_BUFFER_INFO);
7068c2ecf20Sopenharmony_ci	d->size = cpu_to_le16(size);
7078c2ecf20Sopenharmony_ci}
7088c2ecf20Sopenharmony_ci
7098c2ecf20Sopenharmony_cistatic u8 sii8620_checksum(void *ptr, int size)
7108c2ecf20Sopenharmony_ci{
7118c2ecf20Sopenharmony_ci	u8 *d = ptr, sum = 0;
7128c2ecf20Sopenharmony_ci
7138c2ecf20Sopenharmony_ci	while (size--)
7148c2ecf20Sopenharmony_ci		sum += *d++;
7158c2ecf20Sopenharmony_ci
7168c2ecf20Sopenharmony_ci	return sum;
7178c2ecf20Sopenharmony_ci}
7188c2ecf20Sopenharmony_ci
7198c2ecf20Sopenharmony_cistatic void sii8620_mhl_burst_hdr_set(struct mhl3_burst_header *h,
7208c2ecf20Sopenharmony_ci	enum mhl_burst_id id)
7218c2ecf20Sopenharmony_ci{
7228c2ecf20Sopenharmony_ci	h->id = cpu_to_be16(id);
7238c2ecf20Sopenharmony_ci	h->total_entries = 1;
7248c2ecf20Sopenharmony_ci	h->sequence_index = 1;
7258c2ecf20Sopenharmony_ci}
7268c2ecf20Sopenharmony_ci
7278c2ecf20Sopenharmony_cistatic void sii8620_burst_tx_bits_per_pixel_fmt(struct sii8620 *ctx, u8 fmt)
7288c2ecf20Sopenharmony_ci{
7298c2ecf20Sopenharmony_ci	struct mhl_burst_bits_per_pixel_fmt *d;
7308c2ecf20Sopenharmony_ci	const int size = sizeof(*d) + sizeof(d->desc[0]);
7318c2ecf20Sopenharmony_ci
7328c2ecf20Sopenharmony_ci	d = sii8620_burst_get_tx_buf(ctx, size);
7338c2ecf20Sopenharmony_ci	if (!d)
7348c2ecf20Sopenharmony_ci		return;
7358c2ecf20Sopenharmony_ci
7368c2ecf20Sopenharmony_ci	sii8620_mhl_burst_hdr_set(&d->hdr, MHL_BURST_ID_BITS_PER_PIXEL_FMT);
7378c2ecf20Sopenharmony_ci	d->num_entries = 1;
7388c2ecf20Sopenharmony_ci	d->desc[0].stream_id = 0;
7398c2ecf20Sopenharmony_ci	d->desc[0].pixel_format = fmt;
7408c2ecf20Sopenharmony_ci	d->hdr.checksum -= sii8620_checksum(d, size);
7418c2ecf20Sopenharmony_ci}
7428c2ecf20Sopenharmony_ci
7438c2ecf20Sopenharmony_cistatic void sii8620_burst_rx_all(struct sii8620 *ctx)
7448c2ecf20Sopenharmony_ci{
7458c2ecf20Sopenharmony_ci	u8 *d = ctx->burst.rx_buf;
7468c2ecf20Sopenharmony_ci	int count = ctx->burst.rx_count;
7478c2ecf20Sopenharmony_ci
7488c2ecf20Sopenharmony_ci	while (count-- > 0) {
7498c2ecf20Sopenharmony_ci		int len = *d++;
7508c2ecf20Sopenharmony_ci		int id = get_unaligned_be16(&d[0]);
7518c2ecf20Sopenharmony_ci
7528c2ecf20Sopenharmony_ci		switch (id) {
7538c2ecf20Sopenharmony_ci		case MHL_BURST_ID_BLK_RCV_BUFFER_INFO:
7548c2ecf20Sopenharmony_ci			ctx->burst.r_size = get_unaligned_le16(&d[2]);
7558c2ecf20Sopenharmony_ci			break;
7568c2ecf20Sopenharmony_ci		default:
7578c2ecf20Sopenharmony_ci			break;
7588c2ecf20Sopenharmony_ci		}
7598c2ecf20Sopenharmony_ci		count -= len;
7608c2ecf20Sopenharmony_ci		d += len;
7618c2ecf20Sopenharmony_ci	}
7628c2ecf20Sopenharmony_ci	ctx->burst.rx_count = 0;
7638c2ecf20Sopenharmony_ci}
7648c2ecf20Sopenharmony_ci
7658c2ecf20Sopenharmony_cistatic void sii8620_fetch_edid(struct sii8620 *ctx)
7668c2ecf20Sopenharmony_ci{
7678c2ecf20Sopenharmony_ci	u8 lm_ddc, ddc_cmd, int3, cbus;
7688c2ecf20Sopenharmony_ci	unsigned long timeout;
7698c2ecf20Sopenharmony_ci	int fetched, i;
7708c2ecf20Sopenharmony_ci	int edid_len = EDID_LENGTH;
7718c2ecf20Sopenharmony_ci	u8 *edid;
7728c2ecf20Sopenharmony_ci
7738c2ecf20Sopenharmony_ci	sii8620_readb(ctx, REG_CBUS_STATUS);
7748c2ecf20Sopenharmony_ci	lm_ddc = sii8620_readb(ctx, REG_LM_DDC);
7758c2ecf20Sopenharmony_ci	ddc_cmd = sii8620_readb(ctx, REG_DDC_CMD);
7768c2ecf20Sopenharmony_ci
7778c2ecf20Sopenharmony_ci	sii8620_write_seq(ctx,
7788c2ecf20Sopenharmony_ci		REG_INTR9_MASK, 0,
7798c2ecf20Sopenharmony_ci		REG_EDID_CTRL, BIT_EDID_CTRL_EDID_FIFO_ADDR_AUTO,
7808c2ecf20Sopenharmony_ci		REG_HDCP2X_POLL_CS, 0x71,
7818c2ecf20Sopenharmony_ci		REG_HDCP2X_CTRL_0, BIT_HDCP2X_CTRL_0_HDCP2X_HDCPTX,
7828c2ecf20Sopenharmony_ci		REG_LM_DDC, lm_ddc | BIT_LM_DDC_SW_TPI_EN_DISABLED,
7838c2ecf20Sopenharmony_ci	);
7848c2ecf20Sopenharmony_ci
7858c2ecf20Sopenharmony_ci	for (i = 0; i < 256; ++i) {
7868c2ecf20Sopenharmony_ci		u8 ddc_stat = sii8620_readb(ctx, REG_DDC_STATUS);
7878c2ecf20Sopenharmony_ci
7888c2ecf20Sopenharmony_ci		if (!(ddc_stat & BIT_DDC_STATUS_DDC_I2C_IN_PROG))
7898c2ecf20Sopenharmony_ci			break;
7908c2ecf20Sopenharmony_ci		sii8620_write(ctx, REG_DDC_STATUS,
7918c2ecf20Sopenharmony_ci			      BIT_DDC_STATUS_DDC_FIFO_EMPTY);
7928c2ecf20Sopenharmony_ci	}
7938c2ecf20Sopenharmony_ci
7948c2ecf20Sopenharmony_ci	sii8620_write(ctx, REG_DDC_ADDR, 0x50 << 1);
7958c2ecf20Sopenharmony_ci
7968c2ecf20Sopenharmony_ci	edid = kmalloc(EDID_LENGTH, GFP_KERNEL);
7978c2ecf20Sopenharmony_ci	if (!edid) {
7988c2ecf20Sopenharmony_ci		ctx->error = -ENOMEM;
7998c2ecf20Sopenharmony_ci		return;
8008c2ecf20Sopenharmony_ci	}
8018c2ecf20Sopenharmony_ci
8028c2ecf20Sopenharmony_ci#define FETCH_SIZE 16
8038c2ecf20Sopenharmony_ci	for (fetched = 0; fetched < edid_len; fetched += FETCH_SIZE) {
8048c2ecf20Sopenharmony_ci		sii8620_readb(ctx, REG_DDC_STATUS);
8058c2ecf20Sopenharmony_ci		sii8620_write_seq(ctx,
8068c2ecf20Sopenharmony_ci			REG_DDC_CMD, ddc_cmd | VAL_DDC_CMD_DDC_CMD_ABORT,
8078c2ecf20Sopenharmony_ci			REG_DDC_CMD, ddc_cmd | VAL_DDC_CMD_DDC_CMD_CLEAR_FIFO,
8088c2ecf20Sopenharmony_ci			REG_DDC_STATUS, BIT_DDC_STATUS_DDC_FIFO_EMPTY
8098c2ecf20Sopenharmony_ci		);
8108c2ecf20Sopenharmony_ci		sii8620_write_seq(ctx,
8118c2ecf20Sopenharmony_ci			REG_DDC_SEGM, fetched >> 8,
8128c2ecf20Sopenharmony_ci			REG_DDC_OFFSET, fetched & 0xff,
8138c2ecf20Sopenharmony_ci			REG_DDC_DIN_CNT1, FETCH_SIZE,
8148c2ecf20Sopenharmony_ci			REG_DDC_DIN_CNT2, 0,
8158c2ecf20Sopenharmony_ci			REG_DDC_CMD, ddc_cmd | VAL_DDC_CMD_ENH_DDC_READ_NO_ACK
8168c2ecf20Sopenharmony_ci		);
8178c2ecf20Sopenharmony_ci
8188c2ecf20Sopenharmony_ci		int3 = 0;
8198c2ecf20Sopenharmony_ci		timeout = jiffies + msecs_to_jiffies(200);
8208c2ecf20Sopenharmony_ci		for (;;) {
8218c2ecf20Sopenharmony_ci			cbus = sii8620_readb(ctx, REG_CBUS_STATUS);
8228c2ecf20Sopenharmony_ci			if (~cbus & BIT_CBUS_STATUS_CBUS_CONNECTED) {
8238c2ecf20Sopenharmony_ci				kfree(edid);
8248c2ecf20Sopenharmony_ci				edid = NULL;
8258c2ecf20Sopenharmony_ci				goto end;
8268c2ecf20Sopenharmony_ci			}
8278c2ecf20Sopenharmony_ci			if (int3 & BIT_DDC_CMD_DONE) {
8288c2ecf20Sopenharmony_ci				if (sii8620_readb(ctx, REG_DDC_DOUT_CNT)
8298c2ecf20Sopenharmony_ci				    >= FETCH_SIZE)
8308c2ecf20Sopenharmony_ci					break;
8318c2ecf20Sopenharmony_ci			} else {
8328c2ecf20Sopenharmony_ci				int3 = sii8620_readb(ctx, REG_INTR3);
8338c2ecf20Sopenharmony_ci			}
8348c2ecf20Sopenharmony_ci			if (time_is_before_jiffies(timeout)) {
8358c2ecf20Sopenharmony_ci				ctx->error = -ETIMEDOUT;
8368c2ecf20Sopenharmony_ci				dev_err(ctx->dev, "timeout during EDID read\n");
8378c2ecf20Sopenharmony_ci				kfree(edid);
8388c2ecf20Sopenharmony_ci				edid = NULL;
8398c2ecf20Sopenharmony_ci				goto end;
8408c2ecf20Sopenharmony_ci			}
8418c2ecf20Sopenharmony_ci			usleep_range(10, 20);
8428c2ecf20Sopenharmony_ci		}
8438c2ecf20Sopenharmony_ci
8448c2ecf20Sopenharmony_ci		sii8620_read_buf(ctx, REG_DDC_DATA, edid + fetched, FETCH_SIZE);
8458c2ecf20Sopenharmony_ci		if (fetched + FETCH_SIZE == EDID_LENGTH) {
8468c2ecf20Sopenharmony_ci			u8 ext = ((struct edid *)edid)->extensions;
8478c2ecf20Sopenharmony_ci
8488c2ecf20Sopenharmony_ci			if (ext) {
8498c2ecf20Sopenharmony_ci				u8 *new_edid;
8508c2ecf20Sopenharmony_ci
8518c2ecf20Sopenharmony_ci				edid_len += ext * EDID_LENGTH;
8528c2ecf20Sopenharmony_ci				new_edid = krealloc(edid, edid_len, GFP_KERNEL);
8538c2ecf20Sopenharmony_ci				if (!new_edid) {
8548c2ecf20Sopenharmony_ci					kfree(edid);
8558c2ecf20Sopenharmony_ci					ctx->error = -ENOMEM;
8568c2ecf20Sopenharmony_ci					return;
8578c2ecf20Sopenharmony_ci				}
8588c2ecf20Sopenharmony_ci				edid = new_edid;
8598c2ecf20Sopenharmony_ci			}
8608c2ecf20Sopenharmony_ci		}
8618c2ecf20Sopenharmony_ci	}
8628c2ecf20Sopenharmony_ci
8638c2ecf20Sopenharmony_ci	sii8620_write_seq(ctx,
8648c2ecf20Sopenharmony_ci		REG_INTR3_MASK, BIT_DDC_CMD_DONE,
8658c2ecf20Sopenharmony_ci		REG_LM_DDC, lm_ddc
8668c2ecf20Sopenharmony_ci	);
8678c2ecf20Sopenharmony_ci
8688c2ecf20Sopenharmony_ciend:
8698c2ecf20Sopenharmony_ci	kfree(ctx->edid);
8708c2ecf20Sopenharmony_ci	ctx->edid = (struct edid *)edid;
8718c2ecf20Sopenharmony_ci}
8728c2ecf20Sopenharmony_ci
8738c2ecf20Sopenharmony_cistatic void sii8620_set_upstream_edid(struct sii8620 *ctx)
8748c2ecf20Sopenharmony_ci{
8758c2ecf20Sopenharmony_ci	sii8620_setbits(ctx, REG_DPD, BIT_DPD_PDNRX12 | BIT_DPD_PDIDCK_N
8768c2ecf20Sopenharmony_ci			| BIT_DPD_PD_MHL_CLK_N, 0xff);
8778c2ecf20Sopenharmony_ci
8788c2ecf20Sopenharmony_ci	sii8620_write_seq_static(ctx,
8798c2ecf20Sopenharmony_ci		REG_RX_HDMI_CTRL3, 0x00,
8808c2ecf20Sopenharmony_ci		REG_PKT_FILTER_0, 0xFF,
8818c2ecf20Sopenharmony_ci		REG_PKT_FILTER_1, 0xFF,
8828c2ecf20Sopenharmony_ci		REG_ALICE0_BW_I2C, 0x06
8838c2ecf20Sopenharmony_ci	);
8848c2ecf20Sopenharmony_ci
8858c2ecf20Sopenharmony_ci	sii8620_setbits(ctx, REG_RX_HDMI_CLR_BUFFER,
8868c2ecf20Sopenharmony_ci			BIT_RX_HDMI_CLR_BUFFER_VSI_CLR_EN, 0xff);
8878c2ecf20Sopenharmony_ci
8888c2ecf20Sopenharmony_ci	sii8620_write_seq_static(ctx,
8898c2ecf20Sopenharmony_ci		REG_EDID_CTRL, BIT_EDID_CTRL_EDID_FIFO_ADDR_AUTO
8908c2ecf20Sopenharmony_ci			| BIT_EDID_CTRL_EDID_MODE_EN,
8918c2ecf20Sopenharmony_ci		REG_EDID_FIFO_ADDR, 0,
8928c2ecf20Sopenharmony_ci	);
8938c2ecf20Sopenharmony_ci
8948c2ecf20Sopenharmony_ci	sii8620_write_buf(ctx, REG_EDID_FIFO_WR_DATA, (u8 *)ctx->edid,
8958c2ecf20Sopenharmony_ci			  (ctx->edid->extensions + 1) * EDID_LENGTH);
8968c2ecf20Sopenharmony_ci
8978c2ecf20Sopenharmony_ci	sii8620_write_seq_static(ctx,
8988c2ecf20Sopenharmony_ci		REG_EDID_CTRL, BIT_EDID_CTRL_EDID_PRIME_VALID
8998c2ecf20Sopenharmony_ci			| BIT_EDID_CTRL_EDID_FIFO_ADDR_AUTO
9008c2ecf20Sopenharmony_ci			| BIT_EDID_CTRL_EDID_MODE_EN,
9018c2ecf20Sopenharmony_ci		REG_INTR5_MASK, BIT_INTR_SCDT_CHANGE,
9028c2ecf20Sopenharmony_ci		REG_INTR9_MASK, 0
9038c2ecf20Sopenharmony_ci	);
9048c2ecf20Sopenharmony_ci}
9058c2ecf20Sopenharmony_ci
9068c2ecf20Sopenharmony_cistatic void sii8620_xtal_set_rate(struct sii8620 *ctx)
9078c2ecf20Sopenharmony_ci{
9088c2ecf20Sopenharmony_ci	static const struct {
9098c2ecf20Sopenharmony_ci		unsigned int rate;
9108c2ecf20Sopenharmony_ci		u8 div;
9118c2ecf20Sopenharmony_ci		u8 tp1;
9128c2ecf20Sopenharmony_ci	} rates[] = {
9138c2ecf20Sopenharmony_ci		{ 19200, 0x04, 0x53 },
9148c2ecf20Sopenharmony_ci		{ 20000, 0x04, 0x62 },
9158c2ecf20Sopenharmony_ci		{ 24000, 0x05, 0x75 },
9168c2ecf20Sopenharmony_ci		{ 30000, 0x06, 0x92 },
9178c2ecf20Sopenharmony_ci		{ 38400, 0x0c, 0xbc },
9188c2ecf20Sopenharmony_ci	};
9198c2ecf20Sopenharmony_ci	unsigned long rate = clk_get_rate(ctx->clk_xtal) / 1000;
9208c2ecf20Sopenharmony_ci	int i;
9218c2ecf20Sopenharmony_ci
9228c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(rates) - 1; ++i)
9238c2ecf20Sopenharmony_ci		if (rate <= rates[i].rate)
9248c2ecf20Sopenharmony_ci			break;
9258c2ecf20Sopenharmony_ci
9268c2ecf20Sopenharmony_ci	if (rate != rates[i].rate)
9278c2ecf20Sopenharmony_ci		dev_err(ctx->dev, "xtal clock rate(%lukHz) not supported, setting MHL for %ukHz.\n",
9288c2ecf20Sopenharmony_ci			rate, rates[i].rate);
9298c2ecf20Sopenharmony_ci
9308c2ecf20Sopenharmony_ci	sii8620_write(ctx, REG_DIV_CTL_MAIN, rates[i].div);
9318c2ecf20Sopenharmony_ci	sii8620_write(ctx, REG_HDCP2X_TP1, rates[i].tp1);
9328c2ecf20Sopenharmony_ci}
9338c2ecf20Sopenharmony_ci
9348c2ecf20Sopenharmony_cistatic int sii8620_hw_on(struct sii8620 *ctx)
9358c2ecf20Sopenharmony_ci{
9368c2ecf20Sopenharmony_ci	int ret;
9378c2ecf20Sopenharmony_ci
9388c2ecf20Sopenharmony_ci	ret = regulator_bulk_enable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
9398c2ecf20Sopenharmony_ci	if (ret)
9408c2ecf20Sopenharmony_ci		return ret;
9418c2ecf20Sopenharmony_ci
9428c2ecf20Sopenharmony_ci	usleep_range(10000, 20000);
9438c2ecf20Sopenharmony_ci	ret = clk_prepare_enable(ctx->clk_xtal);
9448c2ecf20Sopenharmony_ci	if (ret)
9458c2ecf20Sopenharmony_ci		return ret;
9468c2ecf20Sopenharmony_ci
9478c2ecf20Sopenharmony_ci	msleep(100);
9488c2ecf20Sopenharmony_ci	gpiod_set_value(ctx->gpio_reset, 0);
9498c2ecf20Sopenharmony_ci	msleep(100);
9508c2ecf20Sopenharmony_ci
9518c2ecf20Sopenharmony_ci	return 0;
9528c2ecf20Sopenharmony_ci}
9538c2ecf20Sopenharmony_ci
9548c2ecf20Sopenharmony_cistatic int sii8620_hw_off(struct sii8620 *ctx)
9558c2ecf20Sopenharmony_ci{
9568c2ecf20Sopenharmony_ci	clk_disable_unprepare(ctx->clk_xtal);
9578c2ecf20Sopenharmony_ci	gpiod_set_value(ctx->gpio_reset, 1);
9588c2ecf20Sopenharmony_ci	return regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
9598c2ecf20Sopenharmony_ci}
9608c2ecf20Sopenharmony_ci
9618c2ecf20Sopenharmony_cistatic void sii8620_cbus_reset(struct sii8620 *ctx)
9628c2ecf20Sopenharmony_ci{
9638c2ecf20Sopenharmony_ci	sii8620_write(ctx, REG_PWD_SRST, BIT_PWD_SRST_CBUS_RST
9648c2ecf20Sopenharmony_ci		      | BIT_PWD_SRST_CBUS_RST_SW_EN);
9658c2ecf20Sopenharmony_ci	usleep_range(10000, 20000);
9668c2ecf20Sopenharmony_ci	sii8620_write(ctx, REG_PWD_SRST, BIT_PWD_SRST_CBUS_RST_SW_EN);
9678c2ecf20Sopenharmony_ci}
9688c2ecf20Sopenharmony_ci
9698c2ecf20Sopenharmony_cistatic void sii8620_set_auto_zone(struct sii8620 *ctx)
9708c2ecf20Sopenharmony_ci{
9718c2ecf20Sopenharmony_ci	if (ctx->mode != CM_MHL1) {
9728c2ecf20Sopenharmony_ci		sii8620_write_seq_static(ctx,
9738c2ecf20Sopenharmony_ci			REG_TX_ZONE_CTL1, 0x0,
9748c2ecf20Sopenharmony_ci			REG_MHL_PLL_CTL0, VAL_MHL_PLL_CTL0_HDMI_CLK_RATIO_1X
9758c2ecf20Sopenharmony_ci				| BIT_MHL_PLL_CTL0_CRYSTAL_CLK_SEL
9768c2ecf20Sopenharmony_ci				| BIT_MHL_PLL_CTL0_ZONE_MASK_OE
9778c2ecf20Sopenharmony_ci		);
9788c2ecf20Sopenharmony_ci	} else {
9798c2ecf20Sopenharmony_ci		sii8620_write_seq_static(ctx,
9808c2ecf20Sopenharmony_ci			REG_TX_ZONE_CTL1, VAL_TX_ZONE_CTL1_TX_ZONE_CTRL_MODE,
9818c2ecf20Sopenharmony_ci			REG_MHL_PLL_CTL0, VAL_MHL_PLL_CTL0_HDMI_CLK_RATIO_1X
9828c2ecf20Sopenharmony_ci				| BIT_MHL_PLL_CTL0_ZONE_MASK_OE
9838c2ecf20Sopenharmony_ci		);
9848c2ecf20Sopenharmony_ci	}
9858c2ecf20Sopenharmony_ci}
9868c2ecf20Sopenharmony_ci
9878c2ecf20Sopenharmony_cistatic void sii8620_stop_video(struct sii8620 *ctx)
9888c2ecf20Sopenharmony_ci{
9898c2ecf20Sopenharmony_ci	u8 val;
9908c2ecf20Sopenharmony_ci
9918c2ecf20Sopenharmony_ci	sii8620_write_seq_static(ctx,
9928c2ecf20Sopenharmony_ci		REG_TPI_INTR_EN, 0,
9938c2ecf20Sopenharmony_ci		REG_HDCP2X_INTR0_MASK, 0,
9948c2ecf20Sopenharmony_ci		REG_TPI_COPP_DATA2, 0,
9958c2ecf20Sopenharmony_ci		REG_TPI_INTR_ST0, ~0,
9968c2ecf20Sopenharmony_ci	);
9978c2ecf20Sopenharmony_ci
9988c2ecf20Sopenharmony_ci	switch (ctx->sink_type) {
9998c2ecf20Sopenharmony_ci	case SINK_DVI:
10008c2ecf20Sopenharmony_ci		val = BIT_TPI_SC_REG_TMDS_OE_POWER_DOWN
10018c2ecf20Sopenharmony_ci			| BIT_TPI_SC_TPI_AV_MUTE;
10028c2ecf20Sopenharmony_ci		break;
10038c2ecf20Sopenharmony_ci	case SINK_HDMI:
10048c2ecf20Sopenharmony_ci	default:
10058c2ecf20Sopenharmony_ci		val = BIT_TPI_SC_REG_TMDS_OE_POWER_DOWN
10068c2ecf20Sopenharmony_ci			| BIT_TPI_SC_TPI_AV_MUTE
10078c2ecf20Sopenharmony_ci			| BIT_TPI_SC_TPI_OUTPUT_MODE_0_HDMI;
10088c2ecf20Sopenharmony_ci		break;
10098c2ecf20Sopenharmony_ci	}
10108c2ecf20Sopenharmony_ci
10118c2ecf20Sopenharmony_ci	sii8620_write(ctx, REG_TPI_SC, val);
10128c2ecf20Sopenharmony_ci}
10138c2ecf20Sopenharmony_ci
10148c2ecf20Sopenharmony_cistatic void sii8620_set_format(struct sii8620 *ctx)
10158c2ecf20Sopenharmony_ci{
10168c2ecf20Sopenharmony_ci	u8 out_fmt;
10178c2ecf20Sopenharmony_ci
10188c2ecf20Sopenharmony_ci	if (sii8620_is_mhl3(ctx)) {
10198c2ecf20Sopenharmony_ci		sii8620_setbits(ctx, REG_M3_P0CTRL,
10208c2ecf20Sopenharmony_ci				BIT_M3_P0CTRL_MHL3_P0_PIXEL_MODE_PACKED,
10218c2ecf20Sopenharmony_ci				ctx->use_packed_pixel ? ~0 : 0);
10228c2ecf20Sopenharmony_ci	} else {
10238c2ecf20Sopenharmony_ci		if (ctx->use_packed_pixel) {
10248c2ecf20Sopenharmony_ci			sii8620_write_seq_static(ctx,
10258c2ecf20Sopenharmony_ci				REG_VID_MODE, BIT_VID_MODE_M1080P,
10268c2ecf20Sopenharmony_ci				REG_MHL_TOP_CTL, BIT_MHL_TOP_CTL_MHL_PP_SEL | 1,
10278c2ecf20Sopenharmony_ci				REG_MHLTX_CTL6, 0x60
10288c2ecf20Sopenharmony_ci			);
10298c2ecf20Sopenharmony_ci		} else {
10308c2ecf20Sopenharmony_ci			sii8620_write_seq_static(ctx,
10318c2ecf20Sopenharmony_ci				REG_VID_MODE, 0,
10328c2ecf20Sopenharmony_ci				REG_MHL_TOP_CTL, 1,
10338c2ecf20Sopenharmony_ci				REG_MHLTX_CTL6, 0xa0
10348c2ecf20Sopenharmony_ci			);
10358c2ecf20Sopenharmony_ci		}
10368c2ecf20Sopenharmony_ci	}
10378c2ecf20Sopenharmony_ci
10388c2ecf20Sopenharmony_ci	if (ctx->use_packed_pixel)
10398c2ecf20Sopenharmony_ci		out_fmt = VAL_TPI_FORMAT(YCBCR422, FULL);
10408c2ecf20Sopenharmony_ci	else
10418c2ecf20Sopenharmony_ci		out_fmt = VAL_TPI_FORMAT(RGB, FULL);
10428c2ecf20Sopenharmony_ci
10438c2ecf20Sopenharmony_ci	sii8620_write_seq(ctx,
10448c2ecf20Sopenharmony_ci		REG_TPI_INPUT, VAL_TPI_FORMAT(RGB, FULL),
10458c2ecf20Sopenharmony_ci		REG_TPI_OUTPUT, out_fmt,
10468c2ecf20Sopenharmony_ci	);
10478c2ecf20Sopenharmony_ci}
10488c2ecf20Sopenharmony_ci
10498c2ecf20Sopenharmony_cistatic int mhl3_infoframe_init(struct mhl3_infoframe *frame)
10508c2ecf20Sopenharmony_ci{
10518c2ecf20Sopenharmony_ci	memset(frame, 0, sizeof(*frame));
10528c2ecf20Sopenharmony_ci
10538c2ecf20Sopenharmony_ci	frame->version = 3;
10548c2ecf20Sopenharmony_ci	frame->hev_format = -1;
10558c2ecf20Sopenharmony_ci	return 0;
10568c2ecf20Sopenharmony_ci}
10578c2ecf20Sopenharmony_ci
10588c2ecf20Sopenharmony_cistatic ssize_t mhl3_infoframe_pack(struct mhl3_infoframe *frame,
10598c2ecf20Sopenharmony_ci		 void *buffer, size_t size)
10608c2ecf20Sopenharmony_ci{
10618c2ecf20Sopenharmony_ci	const int frm_len = HDMI_INFOFRAME_HEADER_SIZE + MHL3_INFOFRAME_SIZE;
10628c2ecf20Sopenharmony_ci	u8 *ptr = buffer;
10638c2ecf20Sopenharmony_ci
10648c2ecf20Sopenharmony_ci	if (size < frm_len)
10658c2ecf20Sopenharmony_ci		return -ENOSPC;
10668c2ecf20Sopenharmony_ci
10678c2ecf20Sopenharmony_ci	memset(buffer, 0, size);
10688c2ecf20Sopenharmony_ci	ptr[0] = HDMI_INFOFRAME_TYPE_VENDOR;
10698c2ecf20Sopenharmony_ci	ptr[1] = frame->version;
10708c2ecf20Sopenharmony_ci	ptr[2] = MHL3_INFOFRAME_SIZE;
10718c2ecf20Sopenharmony_ci	ptr[4] = MHL3_IEEE_OUI & 0xff;
10728c2ecf20Sopenharmony_ci	ptr[5] = (MHL3_IEEE_OUI >> 8) & 0xff;
10738c2ecf20Sopenharmony_ci	ptr[6] = (MHL3_IEEE_OUI >> 16) & 0xff;
10748c2ecf20Sopenharmony_ci	ptr[7] = frame->video_format & 0x3;
10758c2ecf20Sopenharmony_ci	ptr[7] |= (frame->format_type & 0x7) << 2;
10768c2ecf20Sopenharmony_ci	ptr[7] |= frame->sep_audio ? BIT(5) : 0;
10778c2ecf20Sopenharmony_ci	if (frame->hev_format >= 0) {
10788c2ecf20Sopenharmony_ci		ptr[9] = 1;
10798c2ecf20Sopenharmony_ci		ptr[10] = (frame->hev_format >> 8) & 0xff;
10808c2ecf20Sopenharmony_ci		ptr[11] = frame->hev_format & 0xff;
10818c2ecf20Sopenharmony_ci	}
10828c2ecf20Sopenharmony_ci	if (frame->av_delay) {
10838c2ecf20Sopenharmony_ci		bool sign = frame->av_delay < 0;
10848c2ecf20Sopenharmony_ci		int delay = sign ? -frame->av_delay : frame->av_delay;
10858c2ecf20Sopenharmony_ci
10868c2ecf20Sopenharmony_ci		ptr[12] = (delay >> 16) & 0xf;
10878c2ecf20Sopenharmony_ci		if (sign)
10888c2ecf20Sopenharmony_ci			ptr[12] |= BIT(4);
10898c2ecf20Sopenharmony_ci		ptr[13] = (delay >> 8) & 0xff;
10908c2ecf20Sopenharmony_ci		ptr[14] = delay & 0xff;
10918c2ecf20Sopenharmony_ci	}
10928c2ecf20Sopenharmony_ci	ptr[3] -= sii8620_checksum(buffer, frm_len);
10938c2ecf20Sopenharmony_ci	return frm_len;
10948c2ecf20Sopenharmony_ci}
10958c2ecf20Sopenharmony_ci
10968c2ecf20Sopenharmony_cistatic void sii8620_set_infoframes(struct sii8620 *ctx,
10978c2ecf20Sopenharmony_ci				   struct drm_display_mode *mode)
10988c2ecf20Sopenharmony_ci{
10998c2ecf20Sopenharmony_ci	struct mhl3_infoframe mhl_frm;
11008c2ecf20Sopenharmony_ci	union hdmi_infoframe frm;
11018c2ecf20Sopenharmony_ci	u8 buf[31];
11028c2ecf20Sopenharmony_ci	int ret;
11038c2ecf20Sopenharmony_ci
11048c2ecf20Sopenharmony_ci	ret = drm_hdmi_avi_infoframe_from_display_mode(&frm.avi,
11058c2ecf20Sopenharmony_ci						       NULL, mode);
11068c2ecf20Sopenharmony_ci	if (ctx->use_packed_pixel)
11078c2ecf20Sopenharmony_ci		frm.avi.colorspace = HDMI_COLORSPACE_YUV422;
11088c2ecf20Sopenharmony_ci
11098c2ecf20Sopenharmony_ci	if (!ret)
11108c2ecf20Sopenharmony_ci		ret = hdmi_avi_infoframe_pack(&frm.avi, buf, ARRAY_SIZE(buf));
11118c2ecf20Sopenharmony_ci	if (ret > 0)
11128c2ecf20Sopenharmony_ci		sii8620_write_buf(ctx, REG_TPI_AVI_CHSUM, buf + 3, ret - 3);
11138c2ecf20Sopenharmony_ci
11148c2ecf20Sopenharmony_ci	if (!sii8620_is_mhl3(ctx) || !ctx->use_packed_pixel) {
11158c2ecf20Sopenharmony_ci		sii8620_write(ctx, REG_TPI_SC,
11168c2ecf20Sopenharmony_ci			BIT_TPI_SC_TPI_OUTPUT_MODE_0_HDMI);
11178c2ecf20Sopenharmony_ci		sii8620_write(ctx, REG_PKT_FILTER_0,
11188c2ecf20Sopenharmony_ci			BIT_PKT_FILTER_0_DROP_CEA_GAMUT_PKT |
11198c2ecf20Sopenharmony_ci			BIT_PKT_FILTER_0_DROP_MPEG_PKT |
11208c2ecf20Sopenharmony_ci			BIT_PKT_FILTER_0_DROP_GCP_PKT,
11218c2ecf20Sopenharmony_ci			BIT_PKT_FILTER_1_DROP_GEN_PKT);
11228c2ecf20Sopenharmony_ci		return;
11238c2ecf20Sopenharmony_ci	}
11248c2ecf20Sopenharmony_ci
11258c2ecf20Sopenharmony_ci	sii8620_write(ctx, REG_PKT_FILTER_0,
11268c2ecf20Sopenharmony_ci		BIT_PKT_FILTER_0_DROP_CEA_GAMUT_PKT |
11278c2ecf20Sopenharmony_ci		BIT_PKT_FILTER_0_DROP_MPEG_PKT |
11288c2ecf20Sopenharmony_ci		BIT_PKT_FILTER_0_DROP_AVI_PKT |
11298c2ecf20Sopenharmony_ci		BIT_PKT_FILTER_0_DROP_GCP_PKT,
11308c2ecf20Sopenharmony_ci		BIT_PKT_FILTER_1_VSI_OVERRIDE_DIS |
11318c2ecf20Sopenharmony_ci		BIT_PKT_FILTER_1_DROP_GEN_PKT |
11328c2ecf20Sopenharmony_ci		BIT_PKT_FILTER_1_DROP_VSIF_PKT);
11338c2ecf20Sopenharmony_ci
11348c2ecf20Sopenharmony_ci	sii8620_write(ctx, REG_TPI_INFO_FSEL, BIT_TPI_INFO_FSEL_EN
11358c2ecf20Sopenharmony_ci		| BIT_TPI_INFO_FSEL_RPT | VAL_TPI_INFO_FSEL_VSI);
11368c2ecf20Sopenharmony_ci	ret = mhl3_infoframe_init(&mhl_frm);
11378c2ecf20Sopenharmony_ci	if (!ret)
11388c2ecf20Sopenharmony_ci		ret = mhl3_infoframe_pack(&mhl_frm, buf, ARRAY_SIZE(buf));
11398c2ecf20Sopenharmony_ci	sii8620_write_buf(ctx, REG_TPI_INFO_B0, buf, ret);
11408c2ecf20Sopenharmony_ci}
11418c2ecf20Sopenharmony_ci
11428c2ecf20Sopenharmony_cistatic void sii8620_start_video(struct sii8620 *ctx)
11438c2ecf20Sopenharmony_ci{
11448c2ecf20Sopenharmony_ci	struct drm_display_mode *mode =
11458c2ecf20Sopenharmony_ci		&ctx->bridge.encoder->crtc->state->adjusted_mode;
11468c2ecf20Sopenharmony_ci
11478c2ecf20Sopenharmony_ci	if (!sii8620_is_mhl3(ctx))
11488c2ecf20Sopenharmony_ci		sii8620_stop_video(ctx);
11498c2ecf20Sopenharmony_ci
11508c2ecf20Sopenharmony_ci	if (ctx->sink_type == SINK_DVI && !sii8620_is_mhl3(ctx)) {
11518c2ecf20Sopenharmony_ci		sii8620_write(ctx, REG_RX_HDMI_CTRL2,
11528c2ecf20Sopenharmony_ci			      VAL_RX_HDMI_CTRL2_DEFVAL);
11538c2ecf20Sopenharmony_ci		sii8620_write(ctx, REG_TPI_SC, 0);
11548c2ecf20Sopenharmony_ci		return;
11558c2ecf20Sopenharmony_ci	}
11568c2ecf20Sopenharmony_ci
11578c2ecf20Sopenharmony_ci	sii8620_write_seq_static(ctx,
11588c2ecf20Sopenharmony_ci		REG_RX_HDMI_CTRL2, VAL_RX_HDMI_CTRL2_DEFVAL
11598c2ecf20Sopenharmony_ci			| BIT_RX_HDMI_CTRL2_USE_AV_MUTE,
11608c2ecf20Sopenharmony_ci		REG_VID_OVRRD, BIT_VID_OVRRD_PP_AUTO_DISABLE
11618c2ecf20Sopenharmony_ci			| BIT_VID_OVRRD_M1080P_OVRRD);
11628c2ecf20Sopenharmony_ci	sii8620_set_format(ctx);
11638c2ecf20Sopenharmony_ci
11648c2ecf20Sopenharmony_ci	if (!sii8620_is_mhl3(ctx)) {
11658c2ecf20Sopenharmony_ci		u8 link_mode = MHL_DST_LM_PATH_ENABLED;
11668c2ecf20Sopenharmony_ci
11678c2ecf20Sopenharmony_ci		if (ctx->use_packed_pixel)
11688c2ecf20Sopenharmony_ci			link_mode |= MHL_DST_LM_CLK_MODE_PACKED_PIXEL;
11698c2ecf20Sopenharmony_ci		else
11708c2ecf20Sopenharmony_ci			link_mode |= MHL_DST_LM_CLK_MODE_NORMAL;
11718c2ecf20Sopenharmony_ci
11728c2ecf20Sopenharmony_ci		sii8620_mt_write_stat(ctx, MHL_DST_REG(LINK_MODE), link_mode);
11738c2ecf20Sopenharmony_ci		sii8620_set_auto_zone(ctx);
11748c2ecf20Sopenharmony_ci	} else {
11758c2ecf20Sopenharmony_ci		static const struct {
11768c2ecf20Sopenharmony_ci			int max_clk;
11778c2ecf20Sopenharmony_ci			u8 zone;
11788c2ecf20Sopenharmony_ci			u8 link_rate;
11798c2ecf20Sopenharmony_ci			u8 rrp_decode;
11808c2ecf20Sopenharmony_ci		} clk_spec[] = {
11818c2ecf20Sopenharmony_ci			{ 150000, VAL_TX_ZONE_CTL3_TX_ZONE_1_5GBPS,
11828c2ecf20Sopenharmony_ci			  MHL_XDS_LINK_RATE_1_5_GBPS, 0x38 },
11838c2ecf20Sopenharmony_ci			{ 300000, VAL_TX_ZONE_CTL3_TX_ZONE_3GBPS,
11848c2ecf20Sopenharmony_ci			  MHL_XDS_LINK_RATE_3_0_GBPS, 0x40 },
11858c2ecf20Sopenharmony_ci			{ 600000, VAL_TX_ZONE_CTL3_TX_ZONE_6GBPS,
11868c2ecf20Sopenharmony_ci			  MHL_XDS_LINK_RATE_6_0_GBPS, 0x40 },
11878c2ecf20Sopenharmony_ci		};
11888c2ecf20Sopenharmony_ci		u8 p0_ctrl = BIT_M3_P0CTRL_MHL3_P0_PORT_EN;
11898c2ecf20Sopenharmony_ci		int clk = mode->clock * (ctx->use_packed_pixel ? 2 : 3);
11908c2ecf20Sopenharmony_ci		int i;
11918c2ecf20Sopenharmony_ci
11928c2ecf20Sopenharmony_ci		for (i = 0; i < ARRAY_SIZE(clk_spec) - 1; ++i)
11938c2ecf20Sopenharmony_ci			if (clk < clk_spec[i].max_clk)
11948c2ecf20Sopenharmony_ci				break;
11958c2ecf20Sopenharmony_ci
11968c2ecf20Sopenharmony_ci		if (100 * clk >= 98 * clk_spec[i].max_clk)
11978c2ecf20Sopenharmony_ci			p0_ctrl |= BIT_M3_P0CTRL_MHL3_P0_UNLIMIT_EN;
11988c2ecf20Sopenharmony_ci
11998c2ecf20Sopenharmony_ci		sii8620_burst_tx_bits_per_pixel_fmt(ctx, ctx->use_packed_pixel);
12008c2ecf20Sopenharmony_ci		sii8620_burst_send(ctx);
12018c2ecf20Sopenharmony_ci		sii8620_write_seq(ctx,
12028c2ecf20Sopenharmony_ci			REG_MHL_DP_CTL0, 0xf0,
12038c2ecf20Sopenharmony_ci			REG_MHL3_TX_ZONE_CTL, clk_spec[i].zone);
12048c2ecf20Sopenharmony_ci		sii8620_setbits(ctx, REG_M3_P0CTRL,
12058c2ecf20Sopenharmony_ci			BIT_M3_P0CTRL_MHL3_P0_PORT_EN
12068c2ecf20Sopenharmony_ci			| BIT_M3_P0CTRL_MHL3_P0_UNLIMIT_EN, p0_ctrl);
12078c2ecf20Sopenharmony_ci		sii8620_setbits(ctx, REG_M3_POSTM, MSK_M3_POSTM_RRP_DECODE,
12088c2ecf20Sopenharmony_ci			clk_spec[i].rrp_decode);
12098c2ecf20Sopenharmony_ci		sii8620_write_seq_static(ctx,
12108c2ecf20Sopenharmony_ci			REG_M3_CTRL, VAL_M3_CTRL_MHL3_VALUE
12118c2ecf20Sopenharmony_ci				| BIT_M3_CTRL_H2M_SWRST,
12128c2ecf20Sopenharmony_ci			REG_M3_CTRL, VAL_M3_CTRL_MHL3_VALUE
12138c2ecf20Sopenharmony_ci		);
12148c2ecf20Sopenharmony_ci		sii8620_mt_write_stat(ctx, MHL_XDS_REG(AVLINK_MODE_CONTROL),
12158c2ecf20Sopenharmony_ci			clk_spec[i].link_rate);
12168c2ecf20Sopenharmony_ci	}
12178c2ecf20Sopenharmony_ci
12188c2ecf20Sopenharmony_ci	sii8620_set_infoframes(ctx, mode);
12198c2ecf20Sopenharmony_ci}
12208c2ecf20Sopenharmony_ci
12218c2ecf20Sopenharmony_cistatic void sii8620_disable_hpd(struct sii8620 *ctx)
12228c2ecf20Sopenharmony_ci{
12238c2ecf20Sopenharmony_ci	sii8620_setbits(ctx, REG_EDID_CTRL, BIT_EDID_CTRL_EDID_PRIME_VALID, 0);
12248c2ecf20Sopenharmony_ci	sii8620_write_seq_static(ctx,
12258c2ecf20Sopenharmony_ci		REG_HPD_CTRL, BIT_HPD_CTRL_HPD_OUT_OVR_EN,
12268c2ecf20Sopenharmony_ci		REG_INTR8_MASK, 0
12278c2ecf20Sopenharmony_ci	);
12288c2ecf20Sopenharmony_ci}
12298c2ecf20Sopenharmony_ci
12308c2ecf20Sopenharmony_cistatic void sii8620_enable_hpd(struct sii8620 *ctx)
12318c2ecf20Sopenharmony_ci{
12328c2ecf20Sopenharmony_ci	sii8620_setbits(ctx, REG_TMDS_CSTAT_P3,
12338c2ecf20Sopenharmony_ci			BIT_TMDS_CSTAT_P3_SCDT_CLR_AVI_DIS
12348c2ecf20Sopenharmony_ci			| BIT_TMDS_CSTAT_P3_CLR_AVI, ~0);
12358c2ecf20Sopenharmony_ci	sii8620_write_seq_static(ctx,
12368c2ecf20Sopenharmony_ci		REG_HPD_CTRL, BIT_HPD_CTRL_HPD_OUT_OVR_EN
12378c2ecf20Sopenharmony_ci			| BIT_HPD_CTRL_HPD_HIGH,
12388c2ecf20Sopenharmony_ci	);
12398c2ecf20Sopenharmony_ci}
12408c2ecf20Sopenharmony_ci
12418c2ecf20Sopenharmony_cistatic void sii8620_mhl_discover(struct sii8620 *ctx)
12428c2ecf20Sopenharmony_ci{
12438c2ecf20Sopenharmony_ci	sii8620_write_seq_static(ctx,
12448c2ecf20Sopenharmony_ci		REG_DISC_CTRL9, BIT_DISC_CTRL9_WAKE_DRVFLT
12458c2ecf20Sopenharmony_ci			| BIT_DISC_CTRL9_DISC_PULSE_PROCEED,
12468c2ecf20Sopenharmony_ci		REG_DISC_CTRL4, VAL_DISC_CTRL4(VAL_PUP_5K, VAL_PUP_20K),
12478c2ecf20Sopenharmony_ci		REG_CBUS_DISC_INTR0_MASK, BIT_MHL3_EST_INT
12488c2ecf20Sopenharmony_ci			| BIT_MHL_EST_INT
12498c2ecf20Sopenharmony_ci			| BIT_NOT_MHL_EST_INT
12508c2ecf20Sopenharmony_ci			| BIT_CBUS_MHL3_DISCON_INT
12518c2ecf20Sopenharmony_ci			| BIT_CBUS_MHL12_DISCON_INT
12528c2ecf20Sopenharmony_ci			| BIT_RGND_READY_INT,
12538c2ecf20Sopenharmony_ci		REG_MHL_PLL_CTL0, VAL_MHL_PLL_CTL0_HDMI_CLK_RATIO_1X
12548c2ecf20Sopenharmony_ci			| BIT_MHL_PLL_CTL0_CRYSTAL_CLK_SEL
12558c2ecf20Sopenharmony_ci			| BIT_MHL_PLL_CTL0_ZONE_MASK_OE,
12568c2ecf20Sopenharmony_ci		REG_MHL_DP_CTL0, BIT_MHL_DP_CTL0_DP_OE
12578c2ecf20Sopenharmony_ci			| BIT_MHL_DP_CTL0_TX_OE_OVR,
12588c2ecf20Sopenharmony_ci		REG_M3_CTRL, VAL_M3_CTRL_MHL3_VALUE,
12598c2ecf20Sopenharmony_ci		REG_MHL_DP_CTL1, 0xA2,
12608c2ecf20Sopenharmony_ci		REG_MHL_DP_CTL2, 0x03,
12618c2ecf20Sopenharmony_ci		REG_MHL_DP_CTL3, 0x35,
12628c2ecf20Sopenharmony_ci		REG_MHL_DP_CTL5, 0x02,
12638c2ecf20Sopenharmony_ci		REG_MHL_DP_CTL6, 0x02,
12648c2ecf20Sopenharmony_ci		REG_MHL_DP_CTL7, 0x03,
12658c2ecf20Sopenharmony_ci		REG_COC_CTLC, 0xFF,
12668c2ecf20Sopenharmony_ci		REG_DPD, BIT_DPD_PWRON_PLL | BIT_DPD_PDNTX12
12678c2ecf20Sopenharmony_ci			| BIT_DPD_OSC_EN | BIT_DPD_PWRON_HSIC,
12688c2ecf20Sopenharmony_ci		REG_COC_INTR_MASK, BIT_COC_PLL_LOCK_STATUS_CHANGE
12698c2ecf20Sopenharmony_ci			| BIT_COC_CALIBRATION_DONE,
12708c2ecf20Sopenharmony_ci		REG_CBUS_INT_1_MASK, BIT_CBUS_MSC_ABORT_RCVD
12718c2ecf20Sopenharmony_ci			| BIT_CBUS_CMD_ABORT,
12728c2ecf20Sopenharmony_ci		REG_CBUS_INT_0_MASK, BIT_CBUS_MSC_MT_DONE
12738c2ecf20Sopenharmony_ci			| BIT_CBUS_HPD_CHG
12748c2ecf20Sopenharmony_ci			| BIT_CBUS_MSC_MR_WRITE_STAT
12758c2ecf20Sopenharmony_ci			| BIT_CBUS_MSC_MR_MSC_MSG
12768c2ecf20Sopenharmony_ci			| BIT_CBUS_MSC_MR_WRITE_BURST
12778c2ecf20Sopenharmony_ci			| BIT_CBUS_MSC_MR_SET_INT
12788c2ecf20Sopenharmony_ci			| BIT_CBUS_MSC_MT_DONE_NACK
12798c2ecf20Sopenharmony_ci	);
12808c2ecf20Sopenharmony_ci}
12818c2ecf20Sopenharmony_ci
12828c2ecf20Sopenharmony_cistatic void sii8620_peer_specific_init(struct sii8620 *ctx)
12838c2ecf20Sopenharmony_ci{
12848c2ecf20Sopenharmony_ci	if (sii8620_is_mhl3(ctx))
12858c2ecf20Sopenharmony_ci		sii8620_write_seq_static(ctx,
12868c2ecf20Sopenharmony_ci			REG_SYS_CTRL1, BIT_SYS_CTRL1_BLOCK_DDC_BY_HPD,
12878c2ecf20Sopenharmony_ci			REG_EMSCINTRMASK1,
12888c2ecf20Sopenharmony_ci				BIT_EMSCINTR1_EMSC_TRAINING_COMMA_ERR
12898c2ecf20Sopenharmony_ci		);
12908c2ecf20Sopenharmony_ci	else
12918c2ecf20Sopenharmony_ci		sii8620_write_seq_static(ctx,
12928c2ecf20Sopenharmony_ci			REG_HDCP2X_INTR0_MASK, 0x00,
12938c2ecf20Sopenharmony_ci			REG_EMSCINTRMASK1, 0x00,
12948c2ecf20Sopenharmony_ci			REG_HDCP2X_INTR0, 0xFF,
12958c2ecf20Sopenharmony_ci			REG_INTR1, 0xFF,
12968c2ecf20Sopenharmony_ci			REG_SYS_CTRL1, BIT_SYS_CTRL1_BLOCK_DDC_BY_HPD
12978c2ecf20Sopenharmony_ci				| BIT_SYS_CTRL1_TX_CTRL_HDMI
12988c2ecf20Sopenharmony_ci		);
12998c2ecf20Sopenharmony_ci}
13008c2ecf20Sopenharmony_ci
13018c2ecf20Sopenharmony_ci#define SII8620_MHL_VERSION			0x32
13028c2ecf20Sopenharmony_ci#define SII8620_SCRATCHPAD_SIZE			16
13038c2ecf20Sopenharmony_ci#define SII8620_INT_STAT_SIZE			0x33
13048c2ecf20Sopenharmony_ci
13058c2ecf20Sopenharmony_cistatic void sii8620_set_dev_cap(struct sii8620 *ctx)
13068c2ecf20Sopenharmony_ci{
13078c2ecf20Sopenharmony_ci	static const u8 devcap[MHL_DCAP_SIZE] = {
13088c2ecf20Sopenharmony_ci		[MHL_DCAP_MHL_VERSION] = SII8620_MHL_VERSION,
13098c2ecf20Sopenharmony_ci		[MHL_DCAP_CAT] = MHL_DCAP_CAT_SOURCE | MHL_DCAP_CAT_POWER,
13108c2ecf20Sopenharmony_ci		[MHL_DCAP_ADOPTER_ID_H] = 0x01,
13118c2ecf20Sopenharmony_ci		[MHL_DCAP_ADOPTER_ID_L] = 0x41,
13128c2ecf20Sopenharmony_ci		[MHL_DCAP_VID_LINK_MODE] = MHL_DCAP_VID_LINK_RGB444
13138c2ecf20Sopenharmony_ci			| MHL_DCAP_VID_LINK_PPIXEL
13148c2ecf20Sopenharmony_ci			| MHL_DCAP_VID_LINK_16BPP,
13158c2ecf20Sopenharmony_ci		[MHL_DCAP_AUD_LINK_MODE] = MHL_DCAP_AUD_LINK_2CH,
13168c2ecf20Sopenharmony_ci		[MHL_DCAP_VIDEO_TYPE] = MHL_DCAP_VT_GRAPHICS,
13178c2ecf20Sopenharmony_ci		[MHL_DCAP_LOG_DEV_MAP] = MHL_DCAP_LD_GUI,
13188c2ecf20Sopenharmony_ci		[MHL_DCAP_BANDWIDTH] = 0x0f,
13198c2ecf20Sopenharmony_ci		[MHL_DCAP_FEATURE_FLAG] = MHL_DCAP_FEATURE_RCP_SUPPORT
13208c2ecf20Sopenharmony_ci			| MHL_DCAP_FEATURE_RAP_SUPPORT
13218c2ecf20Sopenharmony_ci			| MHL_DCAP_FEATURE_SP_SUPPORT,
13228c2ecf20Sopenharmony_ci		[MHL_DCAP_SCRATCHPAD_SIZE] = SII8620_SCRATCHPAD_SIZE,
13238c2ecf20Sopenharmony_ci		[MHL_DCAP_INT_STAT_SIZE] = SII8620_INT_STAT_SIZE,
13248c2ecf20Sopenharmony_ci	};
13258c2ecf20Sopenharmony_ci	static const u8 xdcap[MHL_XDC_SIZE] = {
13268c2ecf20Sopenharmony_ci		[MHL_XDC_ECBUS_SPEEDS] = MHL_XDC_ECBUS_S_075
13278c2ecf20Sopenharmony_ci			| MHL_XDC_ECBUS_S_8BIT,
13288c2ecf20Sopenharmony_ci		[MHL_XDC_TMDS_SPEEDS] = MHL_XDC_TMDS_150
13298c2ecf20Sopenharmony_ci			| MHL_XDC_TMDS_300 | MHL_XDC_TMDS_600,
13308c2ecf20Sopenharmony_ci		[MHL_XDC_ECBUS_ROLES] = MHL_XDC_DEV_HOST,
13318c2ecf20Sopenharmony_ci		[MHL_XDC_LOG_DEV_MAPX] = MHL_XDC_LD_PHONE,
13328c2ecf20Sopenharmony_ci	};
13338c2ecf20Sopenharmony_ci
13348c2ecf20Sopenharmony_ci	sii8620_write_buf(ctx, REG_MHL_DEVCAP_0, devcap, ARRAY_SIZE(devcap));
13358c2ecf20Sopenharmony_ci	sii8620_write_buf(ctx, REG_MHL_EXTDEVCAP_0, xdcap, ARRAY_SIZE(xdcap));
13368c2ecf20Sopenharmony_ci}
13378c2ecf20Sopenharmony_ci
13388c2ecf20Sopenharmony_cistatic void sii8620_mhl_init(struct sii8620 *ctx)
13398c2ecf20Sopenharmony_ci{
13408c2ecf20Sopenharmony_ci	sii8620_write_seq_static(ctx,
13418c2ecf20Sopenharmony_ci		REG_DISC_CTRL4, VAL_DISC_CTRL4(VAL_PUP_OFF, VAL_PUP_20K),
13428c2ecf20Sopenharmony_ci		REG_CBUS_MSC_COMPAT_CTRL,
13438c2ecf20Sopenharmony_ci			BIT_CBUS_MSC_COMPAT_CTRL_XDEVCAP_EN,
13448c2ecf20Sopenharmony_ci	);
13458c2ecf20Sopenharmony_ci
13468c2ecf20Sopenharmony_ci	sii8620_peer_specific_init(ctx);
13478c2ecf20Sopenharmony_ci
13488c2ecf20Sopenharmony_ci	sii8620_disable_hpd(ctx);
13498c2ecf20Sopenharmony_ci
13508c2ecf20Sopenharmony_ci	sii8620_write_seq_static(ctx,
13518c2ecf20Sopenharmony_ci		REG_EDID_CTRL, BIT_EDID_CTRL_EDID_FIFO_ADDR_AUTO,
13528c2ecf20Sopenharmony_ci		REG_DISC_CTRL9, BIT_DISC_CTRL9_WAKE_DRVFLT
13538c2ecf20Sopenharmony_ci			| BIT_DISC_CTRL9_WAKE_PULSE_BYPASS,
13548c2ecf20Sopenharmony_ci		REG_TMDS0_CCTRL1, 0x90,
13558c2ecf20Sopenharmony_ci		REG_TMDS_CLK_EN, 0x01,
13568c2ecf20Sopenharmony_ci		REG_TMDS_CH_EN, 0x11,
13578c2ecf20Sopenharmony_ci		REG_BGR_BIAS, 0x87,
13588c2ecf20Sopenharmony_ci		REG_ALICE0_ZONE_CTRL, 0xE8,
13598c2ecf20Sopenharmony_ci		REG_ALICE0_MODE_CTRL, 0x04,
13608c2ecf20Sopenharmony_ci	);
13618c2ecf20Sopenharmony_ci	sii8620_setbits(ctx, REG_LM_DDC, BIT_LM_DDC_SW_TPI_EN_DISABLED, 0);
13628c2ecf20Sopenharmony_ci	sii8620_write_seq_static(ctx,
13638c2ecf20Sopenharmony_ci		REG_TPI_HW_OPT3, 0x76,
13648c2ecf20Sopenharmony_ci		REG_TMDS_CCTRL, BIT_TMDS_CCTRL_TMDS_OE,
13658c2ecf20Sopenharmony_ci		REG_TPI_DTD_B2, 79,
13668c2ecf20Sopenharmony_ci	);
13678c2ecf20Sopenharmony_ci	sii8620_set_dev_cap(ctx);
13688c2ecf20Sopenharmony_ci	sii8620_write_seq_static(ctx,
13698c2ecf20Sopenharmony_ci		REG_MDT_XMIT_TIMEOUT, 100,
13708c2ecf20Sopenharmony_ci		REG_MDT_XMIT_CTRL, 0x03,
13718c2ecf20Sopenharmony_ci		REG_MDT_XFIFO_STAT, 0x00,
13728c2ecf20Sopenharmony_ci		REG_MDT_RCV_TIMEOUT, 100,
13738c2ecf20Sopenharmony_ci		REG_CBUS_LINK_CTRL_8, 0x1D,
13748c2ecf20Sopenharmony_ci	);
13758c2ecf20Sopenharmony_ci
13768c2ecf20Sopenharmony_ci	sii8620_start_gen2_write_burst(ctx);
13778c2ecf20Sopenharmony_ci	sii8620_write_seq_static(ctx,
13788c2ecf20Sopenharmony_ci		REG_BIST_CTRL, 0x00,
13798c2ecf20Sopenharmony_ci		REG_COC_CTL1, 0x10,
13808c2ecf20Sopenharmony_ci		REG_COC_CTL2, 0x18,
13818c2ecf20Sopenharmony_ci		REG_COC_CTLF, 0x07,
13828c2ecf20Sopenharmony_ci		REG_COC_CTL11, 0xF8,
13838c2ecf20Sopenharmony_ci		REG_COC_CTL17, 0x61,
13848c2ecf20Sopenharmony_ci		REG_COC_CTL18, 0x46,
13858c2ecf20Sopenharmony_ci		REG_COC_CTL19, 0x15,
13868c2ecf20Sopenharmony_ci		REG_COC_CTL1A, 0x01,
13878c2ecf20Sopenharmony_ci		REG_MHL_COC_CTL3, BIT_MHL_COC_CTL3_COC_AECHO_EN,
13888c2ecf20Sopenharmony_ci		REG_MHL_COC_CTL4, 0x2D,
13898c2ecf20Sopenharmony_ci		REG_MHL_COC_CTL5, 0xF9,
13908c2ecf20Sopenharmony_ci		REG_MSC_HEARTBEAT_CTRL, 0x27,
13918c2ecf20Sopenharmony_ci	);
13928c2ecf20Sopenharmony_ci	sii8620_disable_gen2_write_burst(ctx);
13938c2ecf20Sopenharmony_ci
13948c2ecf20Sopenharmony_ci	sii8620_mt_write_stat(ctx, MHL_DST_REG(VERSION), SII8620_MHL_VERSION);
13958c2ecf20Sopenharmony_ci	sii8620_mt_write_stat(ctx, MHL_DST_REG(CONNECTED_RDY),
13968c2ecf20Sopenharmony_ci			      MHL_DST_CONN_DCAP_RDY | MHL_DST_CONN_XDEVCAPP_SUPP
13978c2ecf20Sopenharmony_ci			      | MHL_DST_CONN_POW_STAT);
13988c2ecf20Sopenharmony_ci	sii8620_mt_set_int(ctx, MHL_INT_REG(RCHANGE), MHL_INT_RC_DCAP_CHG);
13998c2ecf20Sopenharmony_ci}
14008c2ecf20Sopenharmony_ci
14018c2ecf20Sopenharmony_cistatic void sii8620_emsc_enable(struct sii8620 *ctx)
14028c2ecf20Sopenharmony_ci{
14038c2ecf20Sopenharmony_ci	u8 reg;
14048c2ecf20Sopenharmony_ci
14058c2ecf20Sopenharmony_ci	sii8620_setbits(ctx, REG_GENCTL, BIT_GENCTL_EMSC_EN
14068c2ecf20Sopenharmony_ci					 | BIT_GENCTL_CLR_EMSC_RFIFO
14078c2ecf20Sopenharmony_ci					 | BIT_GENCTL_CLR_EMSC_XFIFO, ~0);
14088c2ecf20Sopenharmony_ci	sii8620_setbits(ctx, REG_GENCTL, BIT_GENCTL_CLR_EMSC_RFIFO
14098c2ecf20Sopenharmony_ci					 | BIT_GENCTL_CLR_EMSC_XFIFO, 0);
14108c2ecf20Sopenharmony_ci	sii8620_setbits(ctx, REG_COMMECNT, BIT_COMMECNT_I2C_TO_EMSC_EN, ~0);
14118c2ecf20Sopenharmony_ci	reg = sii8620_readb(ctx, REG_EMSCINTR);
14128c2ecf20Sopenharmony_ci	sii8620_write(ctx, REG_EMSCINTR, reg);
14138c2ecf20Sopenharmony_ci	sii8620_write(ctx, REG_EMSCINTRMASK, BIT_EMSCINTR_SPI_DVLD);
14148c2ecf20Sopenharmony_ci}
14158c2ecf20Sopenharmony_ci
14168c2ecf20Sopenharmony_cistatic int sii8620_wait_for_fsm_state(struct sii8620 *ctx, u8 state)
14178c2ecf20Sopenharmony_ci{
14188c2ecf20Sopenharmony_ci	int i;
14198c2ecf20Sopenharmony_ci
14208c2ecf20Sopenharmony_ci	for (i = 0; i < 10; ++i) {
14218c2ecf20Sopenharmony_ci		u8 s = sii8620_readb(ctx, REG_COC_STAT_0);
14228c2ecf20Sopenharmony_ci
14238c2ecf20Sopenharmony_ci		if ((s & MSK_COC_STAT_0_FSM_STATE) == state)
14248c2ecf20Sopenharmony_ci			return 0;
14258c2ecf20Sopenharmony_ci		if (!(s & BIT_COC_STAT_0_PLL_LOCKED))
14268c2ecf20Sopenharmony_ci			return -EBUSY;
14278c2ecf20Sopenharmony_ci		usleep_range(4000, 6000);
14288c2ecf20Sopenharmony_ci	}
14298c2ecf20Sopenharmony_ci	return -ETIMEDOUT;
14308c2ecf20Sopenharmony_ci}
14318c2ecf20Sopenharmony_ci
14328c2ecf20Sopenharmony_cistatic void sii8620_set_mode(struct sii8620 *ctx, enum sii8620_mode mode)
14338c2ecf20Sopenharmony_ci{
14348c2ecf20Sopenharmony_ci	int ret;
14358c2ecf20Sopenharmony_ci
14368c2ecf20Sopenharmony_ci	if (ctx->mode == mode)
14378c2ecf20Sopenharmony_ci		return;
14388c2ecf20Sopenharmony_ci
14398c2ecf20Sopenharmony_ci	switch (mode) {
14408c2ecf20Sopenharmony_ci	case CM_MHL1:
14418c2ecf20Sopenharmony_ci		sii8620_write_seq_static(ctx,
14428c2ecf20Sopenharmony_ci			REG_CBUS_MSC_COMPAT_CTRL, 0x02,
14438c2ecf20Sopenharmony_ci			REG_M3_CTRL, VAL_M3_CTRL_MHL1_2_VALUE,
14448c2ecf20Sopenharmony_ci			REG_DPD, BIT_DPD_PWRON_PLL | BIT_DPD_PDNTX12
14458c2ecf20Sopenharmony_ci				| BIT_DPD_OSC_EN,
14468c2ecf20Sopenharmony_ci			REG_COC_INTR_MASK, 0
14478c2ecf20Sopenharmony_ci		);
14488c2ecf20Sopenharmony_ci		ctx->mode = mode;
14498c2ecf20Sopenharmony_ci		break;
14508c2ecf20Sopenharmony_ci	case CM_MHL3:
14518c2ecf20Sopenharmony_ci		sii8620_write(ctx, REG_M3_CTRL, VAL_M3_CTRL_MHL3_VALUE);
14528c2ecf20Sopenharmony_ci		ctx->mode = mode;
14538c2ecf20Sopenharmony_ci		return;
14548c2ecf20Sopenharmony_ci	case CM_ECBUS_S:
14558c2ecf20Sopenharmony_ci		sii8620_emsc_enable(ctx);
14568c2ecf20Sopenharmony_ci		sii8620_write_seq_static(ctx,
14578c2ecf20Sopenharmony_ci			REG_TTXSPINUMS, 4,
14588c2ecf20Sopenharmony_ci			REG_TRXSPINUMS, 4,
14598c2ecf20Sopenharmony_ci			REG_TTXHSICNUMS, 0x14,
14608c2ecf20Sopenharmony_ci			REG_TRXHSICNUMS, 0x14,
14618c2ecf20Sopenharmony_ci			REG_TTXTOTNUMS, 0x18,
14628c2ecf20Sopenharmony_ci			REG_TRXTOTNUMS, 0x18,
14638c2ecf20Sopenharmony_ci			REG_PWD_SRST, BIT_PWD_SRST_COC_DOC_RST
14648c2ecf20Sopenharmony_ci				      | BIT_PWD_SRST_CBUS_RST_SW_EN,
14658c2ecf20Sopenharmony_ci			REG_MHL_COC_CTL1, 0xbd,
14668c2ecf20Sopenharmony_ci			REG_PWD_SRST, BIT_PWD_SRST_CBUS_RST_SW_EN,
14678c2ecf20Sopenharmony_ci			REG_COC_CTLB, 0x01,
14688c2ecf20Sopenharmony_ci			REG_COC_CTL0, 0x5c,
14698c2ecf20Sopenharmony_ci			REG_COC_CTL14, 0x03,
14708c2ecf20Sopenharmony_ci			REG_COC_CTL15, 0x80,
14718c2ecf20Sopenharmony_ci			REG_MHL_DP_CTL6, BIT_MHL_DP_CTL6_DP_TAP1_SGN
14728c2ecf20Sopenharmony_ci					 | BIT_MHL_DP_CTL6_DP_TAP1_EN
14738c2ecf20Sopenharmony_ci					 | BIT_MHL_DP_CTL6_DT_PREDRV_FEEDCAP_EN,
14748c2ecf20Sopenharmony_ci			REG_MHL_DP_CTL8, 0x03
14758c2ecf20Sopenharmony_ci		);
14768c2ecf20Sopenharmony_ci		ret = sii8620_wait_for_fsm_state(ctx, 0x03);
14778c2ecf20Sopenharmony_ci		sii8620_write_seq_static(ctx,
14788c2ecf20Sopenharmony_ci			REG_COC_CTL14, 0x00,
14798c2ecf20Sopenharmony_ci			REG_COC_CTL15, 0x80
14808c2ecf20Sopenharmony_ci		);
14818c2ecf20Sopenharmony_ci		if (!ret)
14828c2ecf20Sopenharmony_ci			sii8620_write(ctx, REG_CBUS3_CNVT, 0x85);
14838c2ecf20Sopenharmony_ci		else
14848c2ecf20Sopenharmony_ci			sii8620_disconnect(ctx);
14858c2ecf20Sopenharmony_ci		return;
14868c2ecf20Sopenharmony_ci	case CM_DISCONNECTED:
14878c2ecf20Sopenharmony_ci		ctx->mode = mode;
14888c2ecf20Sopenharmony_ci		break;
14898c2ecf20Sopenharmony_ci	default:
14908c2ecf20Sopenharmony_ci		dev_err(ctx->dev, "%s mode %d not supported\n", __func__, mode);
14918c2ecf20Sopenharmony_ci		break;
14928c2ecf20Sopenharmony_ci	}
14938c2ecf20Sopenharmony_ci
14948c2ecf20Sopenharmony_ci	sii8620_set_auto_zone(ctx);
14958c2ecf20Sopenharmony_ci
14968c2ecf20Sopenharmony_ci	if (mode != CM_MHL1)
14978c2ecf20Sopenharmony_ci		return;
14988c2ecf20Sopenharmony_ci
14998c2ecf20Sopenharmony_ci	sii8620_write_seq_static(ctx,
15008c2ecf20Sopenharmony_ci		REG_MHL_DP_CTL0, 0xBC,
15018c2ecf20Sopenharmony_ci		REG_MHL_DP_CTL1, 0xBB,
15028c2ecf20Sopenharmony_ci		REG_MHL_DP_CTL3, 0x48,
15038c2ecf20Sopenharmony_ci		REG_MHL_DP_CTL5, 0x39,
15048c2ecf20Sopenharmony_ci		REG_MHL_DP_CTL2, 0x2A,
15058c2ecf20Sopenharmony_ci		REG_MHL_DP_CTL6, 0x2A,
15068c2ecf20Sopenharmony_ci		REG_MHL_DP_CTL7, 0x08
15078c2ecf20Sopenharmony_ci	);
15088c2ecf20Sopenharmony_ci}
15098c2ecf20Sopenharmony_ci
15108c2ecf20Sopenharmony_cistatic void sii8620_hpd_unplugged(struct sii8620 *ctx)
15118c2ecf20Sopenharmony_ci{
15128c2ecf20Sopenharmony_ci	sii8620_disable_hpd(ctx);
15138c2ecf20Sopenharmony_ci	ctx->sink_type = SINK_NONE;
15148c2ecf20Sopenharmony_ci	ctx->sink_detected = false;
15158c2ecf20Sopenharmony_ci	ctx->feature_complete = false;
15168c2ecf20Sopenharmony_ci	kfree(ctx->edid);
15178c2ecf20Sopenharmony_ci	ctx->edid = NULL;
15188c2ecf20Sopenharmony_ci}
15198c2ecf20Sopenharmony_ci
15208c2ecf20Sopenharmony_cistatic void sii8620_disconnect(struct sii8620 *ctx)
15218c2ecf20Sopenharmony_ci{
15228c2ecf20Sopenharmony_ci	sii8620_disable_gen2_write_burst(ctx);
15238c2ecf20Sopenharmony_ci	sii8620_stop_video(ctx);
15248c2ecf20Sopenharmony_ci	msleep(100);
15258c2ecf20Sopenharmony_ci	sii8620_cbus_reset(ctx);
15268c2ecf20Sopenharmony_ci	sii8620_set_mode(ctx, CM_DISCONNECTED);
15278c2ecf20Sopenharmony_ci	sii8620_write_seq_static(ctx,
15288c2ecf20Sopenharmony_ci		REG_TX_ZONE_CTL1, 0,
15298c2ecf20Sopenharmony_ci		REG_MHL_PLL_CTL0, 0x07,
15308c2ecf20Sopenharmony_ci		REG_COC_CTL0, 0x40,
15318c2ecf20Sopenharmony_ci		REG_CBUS3_CNVT, 0x84,
15328c2ecf20Sopenharmony_ci		REG_COC_CTL14, 0x00,
15338c2ecf20Sopenharmony_ci		REG_COC_CTL0, 0x40,
15348c2ecf20Sopenharmony_ci		REG_HRXCTRL3, 0x07,
15358c2ecf20Sopenharmony_ci		REG_MHL_PLL_CTL0, VAL_MHL_PLL_CTL0_HDMI_CLK_RATIO_1X
15368c2ecf20Sopenharmony_ci			| BIT_MHL_PLL_CTL0_CRYSTAL_CLK_SEL
15378c2ecf20Sopenharmony_ci			| BIT_MHL_PLL_CTL0_ZONE_MASK_OE,
15388c2ecf20Sopenharmony_ci		REG_MHL_DP_CTL0, BIT_MHL_DP_CTL0_DP_OE
15398c2ecf20Sopenharmony_ci			| BIT_MHL_DP_CTL0_TX_OE_OVR,
15408c2ecf20Sopenharmony_ci		REG_MHL_DP_CTL1, 0xBB,
15418c2ecf20Sopenharmony_ci		REG_MHL_DP_CTL3, 0x48,
15428c2ecf20Sopenharmony_ci		REG_MHL_DP_CTL5, 0x3F,
15438c2ecf20Sopenharmony_ci		REG_MHL_DP_CTL2, 0x2F,
15448c2ecf20Sopenharmony_ci		REG_MHL_DP_CTL6, 0x2A,
15458c2ecf20Sopenharmony_ci		REG_MHL_DP_CTL7, 0x03
15468c2ecf20Sopenharmony_ci	);
15478c2ecf20Sopenharmony_ci	sii8620_hpd_unplugged(ctx);
15488c2ecf20Sopenharmony_ci	sii8620_write_seq_static(ctx,
15498c2ecf20Sopenharmony_ci		REG_M3_CTRL, VAL_M3_CTRL_MHL3_VALUE,
15508c2ecf20Sopenharmony_ci		REG_MHL_COC_CTL1, 0x07,
15518c2ecf20Sopenharmony_ci		REG_DISC_CTRL4, VAL_DISC_CTRL4(VAL_PUP_OFF, VAL_PUP_20K),
15528c2ecf20Sopenharmony_ci		REG_DISC_CTRL8, 0x00,
15538c2ecf20Sopenharmony_ci		REG_DISC_CTRL9, BIT_DISC_CTRL9_WAKE_DRVFLT
15548c2ecf20Sopenharmony_ci			| BIT_DISC_CTRL9_WAKE_PULSE_BYPASS,
15558c2ecf20Sopenharmony_ci		REG_INT_CTRL, 0x00,
15568c2ecf20Sopenharmony_ci		REG_MSC_HEARTBEAT_CTRL, 0x27,
15578c2ecf20Sopenharmony_ci		REG_DISC_CTRL1, 0x25,
15588c2ecf20Sopenharmony_ci		REG_CBUS_DISC_INTR0, (u8)~BIT_RGND_READY_INT,
15598c2ecf20Sopenharmony_ci		REG_CBUS_DISC_INTR0_MASK, BIT_RGND_READY_INT,
15608c2ecf20Sopenharmony_ci		REG_MDT_INT_1, 0xff,
15618c2ecf20Sopenharmony_ci		REG_MDT_INT_1_MASK, 0x00,
15628c2ecf20Sopenharmony_ci		REG_MDT_INT_0, 0xff,
15638c2ecf20Sopenharmony_ci		REG_MDT_INT_0_MASK, 0x00,
15648c2ecf20Sopenharmony_ci		REG_COC_INTR, 0xff,
15658c2ecf20Sopenharmony_ci		REG_COC_INTR_MASK, 0x00,
15668c2ecf20Sopenharmony_ci		REG_TRXINTH, 0xff,
15678c2ecf20Sopenharmony_ci		REG_TRXINTMH, 0x00,
15688c2ecf20Sopenharmony_ci		REG_CBUS_INT_0, 0xff,
15698c2ecf20Sopenharmony_ci		REG_CBUS_INT_0_MASK, 0x00,
15708c2ecf20Sopenharmony_ci		REG_CBUS_INT_1, 0xff,
15718c2ecf20Sopenharmony_ci		REG_CBUS_INT_1_MASK, 0x00,
15728c2ecf20Sopenharmony_ci		REG_EMSCINTR, 0xff,
15738c2ecf20Sopenharmony_ci		REG_EMSCINTRMASK, 0x00,
15748c2ecf20Sopenharmony_ci		REG_EMSCINTR1, 0xff,
15758c2ecf20Sopenharmony_ci		REG_EMSCINTRMASK1, 0x00,
15768c2ecf20Sopenharmony_ci		REG_INTR8, 0xff,
15778c2ecf20Sopenharmony_ci		REG_INTR8_MASK, 0x00,
15788c2ecf20Sopenharmony_ci		REG_TPI_INTR_ST0, 0xff,
15798c2ecf20Sopenharmony_ci		REG_TPI_INTR_EN, 0x00,
15808c2ecf20Sopenharmony_ci		REG_HDCP2X_INTR0, 0xff,
15818c2ecf20Sopenharmony_ci		REG_HDCP2X_INTR0_MASK, 0x00,
15828c2ecf20Sopenharmony_ci		REG_INTR9, 0xff,
15838c2ecf20Sopenharmony_ci		REG_INTR9_MASK, 0x00,
15848c2ecf20Sopenharmony_ci		REG_INTR3, 0xff,
15858c2ecf20Sopenharmony_ci		REG_INTR3_MASK, 0x00,
15868c2ecf20Sopenharmony_ci		REG_INTR5, 0xff,
15878c2ecf20Sopenharmony_ci		REG_INTR5_MASK, 0x00,
15888c2ecf20Sopenharmony_ci		REG_INTR2, 0xff,
15898c2ecf20Sopenharmony_ci		REG_INTR2_MASK, 0x00,
15908c2ecf20Sopenharmony_ci	);
15918c2ecf20Sopenharmony_ci	memset(ctx->stat, 0, sizeof(ctx->stat));
15928c2ecf20Sopenharmony_ci	memset(ctx->xstat, 0, sizeof(ctx->xstat));
15938c2ecf20Sopenharmony_ci	memset(ctx->devcap, 0, sizeof(ctx->devcap));
15948c2ecf20Sopenharmony_ci	memset(ctx->xdevcap, 0, sizeof(ctx->xdevcap));
15958c2ecf20Sopenharmony_ci	ctx->devcap_read = false;
15968c2ecf20Sopenharmony_ci	ctx->cbus_status = 0;
15978c2ecf20Sopenharmony_ci	sii8620_mt_cleanup(ctx);
15988c2ecf20Sopenharmony_ci}
15998c2ecf20Sopenharmony_ci
16008c2ecf20Sopenharmony_cistatic void sii8620_mhl_disconnected(struct sii8620 *ctx)
16018c2ecf20Sopenharmony_ci{
16028c2ecf20Sopenharmony_ci	sii8620_write_seq_static(ctx,
16038c2ecf20Sopenharmony_ci		REG_DISC_CTRL4, VAL_DISC_CTRL4(VAL_PUP_OFF, VAL_PUP_20K),
16048c2ecf20Sopenharmony_ci		REG_CBUS_MSC_COMPAT_CTRL,
16058c2ecf20Sopenharmony_ci			BIT_CBUS_MSC_COMPAT_CTRL_XDEVCAP_EN
16068c2ecf20Sopenharmony_ci	);
16078c2ecf20Sopenharmony_ci	sii8620_disconnect(ctx);
16088c2ecf20Sopenharmony_ci}
16098c2ecf20Sopenharmony_ci
16108c2ecf20Sopenharmony_cistatic void sii8620_irq_disc(struct sii8620 *ctx)
16118c2ecf20Sopenharmony_ci{
16128c2ecf20Sopenharmony_ci	u8 stat = sii8620_readb(ctx, REG_CBUS_DISC_INTR0);
16138c2ecf20Sopenharmony_ci
16148c2ecf20Sopenharmony_ci	if (stat & VAL_CBUS_MHL_DISCON)
16158c2ecf20Sopenharmony_ci		sii8620_mhl_disconnected(ctx);
16168c2ecf20Sopenharmony_ci
16178c2ecf20Sopenharmony_ci	if (stat & BIT_RGND_READY_INT) {
16188c2ecf20Sopenharmony_ci		u8 stat2 = sii8620_readb(ctx, REG_DISC_STAT2);
16198c2ecf20Sopenharmony_ci
16208c2ecf20Sopenharmony_ci		if ((stat2 & MSK_DISC_STAT2_RGND) == VAL_RGND_1K) {
16218c2ecf20Sopenharmony_ci			sii8620_mhl_discover(ctx);
16228c2ecf20Sopenharmony_ci		} else {
16238c2ecf20Sopenharmony_ci			sii8620_write_seq_static(ctx,
16248c2ecf20Sopenharmony_ci				REG_DISC_CTRL9, BIT_DISC_CTRL9_WAKE_DRVFLT
16258c2ecf20Sopenharmony_ci					| BIT_DISC_CTRL9_NOMHL_EST
16268c2ecf20Sopenharmony_ci					| BIT_DISC_CTRL9_WAKE_PULSE_BYPASS,
16278c2ecf20Sopenharmony_ci				REG_CBUS_DISC_INTR0_MASK, BIT_RGND_READY_INT
16288c2ecf20Sopenharmony_ci					| BIT_CBUS_MHL3_DISCON_INT
16298c2ecf20Sopenharmony_ci					| BIT_CBUS_MHL12_DISCON_INT
16308c2ecf20Sopenharmony_ci					| BIT_NOT_MHL_EST_INT
16318c2ecf20Sopenharmony_ci			);
16328c2ecf20Sopenharmony_ci		}
16338c2ecf20Sopenharmony_ci	}
16348c2ecf20Sopenharmony_ci	if (stat & BIT_MHL_EST_INT)
16358c2ecf20Sopenharmony_ci		sii8620_mhl_init(ctx);
16368c2ecf20Sopenharmony_ci
16378c2ecf20Sopenharmony_ci	sii8620_write(ctx, REG_CBUS_DISC_INTR0, stat);
16388c2ecf20Sopenharmony_ci}
16398c2ecf20Sopenharmony_ci
16408c2ecf20Sopenharmony_cistatic void sii8620_read_burst(struct sii8620 *ctx)
16418c2ecf20Sopenharmony_ci{
16428c2ecf20Sopenharmony_ci	u8 buf[17];
16438c2ecf20Sopenharmony_ci
16448c2ecf20Sopenharmony_ci	sii8620_read_buf(ctx, REG_MDT_RCV_READ_PORT, buf, ARRAY_SIZE(buf));
16458c2ecf20Sopenharmony_ci	sii8620_write(ctx, REG_MDT_RCV_CTRL, BIT_MDT_RCV_CTRL_MDT_RCV_EN |
16468c2ecf20Sopenharmony_ci		      BIT_MDT_RCV_CTRL_MDT_DELAY_RCV_EN |
16478c2ecf20Sopenharmony_ci		      BIT_MDT_RCV_CTRL_MDT_RFIFO_CLR_CUR);
16488c2ecf20Sopenharmony_ci	sii8620_readb(ctx, REG_MDT_RFIFO_STAT);
16498c2ecf20Sopenharmony_ci}
16508c2ecf20Sopenharmony_ci
16518c2ecf20Sopenharmony_cistatic void sii8620_irq_g2wb(struct sii8620 *ctx)
16528c2ecf20Sopenharmony_ci{
16538c2ecf20Sopenharmony_ci	u8 stat = sii8620_readb(ctx, REG_MDT_INT_0);
16548c2ecf20Sopenharmony_ci
16558c2ecf20Sopenharmony_ci	if (stat & BIT_MDT_IDLE_AFTER_HAWB_DISABLE)
16568c2ecf20Sopenharmony_ci		if (sii8620_is_mhl3(ctx))
16578c2ecf20Sopenharmony_ci			sii8620_mt_set_int(ctx, MHL_INT_REG(RCHANGE),
16588c2ecf20Sopenharmony_ci				MHL_INT_RC_FEAT_COMPLETE);
16598c2ecf20Sopenharmony_ci
16608c2ecf20Sopenharmony_ci	if (stat & BIT_MDT_RFIFO_DATA_RDY)
16618c2ecf20Sopenharmony_ci		sii8620_read_burst(ctx);
16628c2ecf20Sopenharmony_ci
16638c2ecf20Sopenharmony_ci	if (stat & BIT_MDT_XFIFO_EMPTY)
16648c2ecf20Sopenharmony_ci		sii8620_write(ctx, REG_MDT_XMIT_CTRL, 0);
16658c2ecf20Sopenharmony_ci
16668c2ecf20Sopenharmony_ci	sii8620_write(ctx, REG_MDT_INT_0, stat);
16678c2ecf20Sopenharmony_ci}
16688c2ecf20Sopenharmony_ci
16698c2ecf20Sopenharmony_cistatic void sii8620_status_dcap_ready(struct sii8620 *ctx)
16708c2ecf20Sopenharmony_ci{
16718c2ecf20Sopenharmony_ci	enum sii8620_mode mode;
16728c2ecf20Sopenharmony_ci
16738c2ecf20Sopenharmony_ci	mode = ctx->stat[MHL_DST_VERSION] >= 0x30 ? CM_MHL3 : CM_MHL1;
16748c2ecf20Sopenharmony_ci	if (mode > ctx->mode)
16758c2ecf20Sopenharmony_ci		sii8620_set_mode(ctx, mode);
16768c2ecf20Sopenharmony_ci	sii8620_peer_specific_init(ctx);
16778c2ecf20Sopenharmony_ci	sii8620_write(ctx, REG_INTR9_MASK, BIT_INTR9_DEVCAP_DONE
16788c2ecf20Sopenharmony_ci		      | BIT_INTR9_EDID_DONE | BIT_INTR9_EDID_ERROR);
16798c2ecf20Sopenharmony_ci}
16808c2ecf20Sopenharmony_ci
16818c2ecf20Sopenharmony_cistatic void sii8620_status_changed_path(struct sii8620 *ctx)
16828c2ecf20Sopenharmony_ci{
16838c2ecf20Sopenharmony_ci	u8 link_mode;
16848c2ecf20Sopenharmony_ci
16858c2ecf20Sopenharmony_ci	if (ctx->use_packed_pixel)
16868c2ecf20Sopenharmony_ci		link_mode = MHL_DST_LM_CLK_MODE_PACKED_PIXEL;
16878c2ecf20Sopenharmony_ci	else
16888c2ecf20Sopenharmony_ci		link_mode = MHL_DST_LM_CLK_MODE_NORMAL;
16898c2ecf20Sopenharmony_ci
16908c2ecf20Sopenharmony_ci	if (ctx->stat[MHL_DST_LINK_MODE] & MHL_DST_LM_PATH_ENABLED)
16918c2ecf20Sopenharmony_ci		link_mode |= MHL_DST_LM_PATH_ENABLED;
16928c2ecf20Sopenharmony_ci
16938c2ecf20Sopenharmony_ci	sii8620_mt_write_stat(ctx, MHL_DST_REG(LINK_MODE),
16948c2ecf20Sopenharmony_ci			      link_mode);
16958c2ecf20Sopenharmony_ci}
16968c2ecf20Sopenharmony_ci
16978c2ecf20Sopenharmony_cistatic void sii8620_msc_mr_write_stat(struct sii8620 *ctx)
16988c2ecf20Sopenharmony_ci{
16998c2ecf20Sopenharmony_ci	u8 st[MHL_DST_SIZE], xst[MHL_XDS_SIZE];
17008c2ecf20Sopenharmony_ci
17018c2ecf20Sopenharmony_ci	sii8620_read_buf(ctx, REG_MHL_STAT_0, st, MHL_DST_SIZE);
17028c2ecf20Sopenharmony_ci	sii8620_read_buf(ctx, REG_MHL_EXTSTAT_0, xst, MHL_XDS_SIZE);
17038c2ecf20Sopenharmony_ci
17048c2ecf20Sopenharmony_ci	sii8620_update_array(ctx->stat, st, MHL_DST_SIZE);
17058c2ecf20Sopenharmony_ci	sii8620_update_array(ctx->xstat, xst, MHL_XDS_SIZE);
17068c2ecf20Sopenharmony_ci
17078c2ecf20Sopenharmony_ci	if (ctx->stat[MHL_DST_CONNECTED_RDY] & st[MHL_DST_CONNECTED_RDY] &
17088c2ecf20Sopenharmony_ci	    MHL_DST_CONN_DCAP_RDY) {
17098c2ecf20Sopenharmony_ci		sii8620_status_dcap_ready(ctx);
17108c2ecf20Sopenharmony_ci
17118c2ecf20Sopenharmony_ci		if (!sii8620_is_mhl3(ctx))
17128c2ecf20Sopenharmony_ci			sii8620_mt_read_devcap(ctx, false);
17138c2ecf20Sopenharmony_ci	}
17148c2ecf20Sopenharmony_ci
17158c2ecf20Sopenharmony_ci	if (st[MHL_DST_LINK_MODE] & MHL_DST_LM_PATH_ENABLED)
17168c2ecf20Sopenharmony_ci		sii8620_status_changed_path(ctx);
17178c2ecf20Sopenharmony_ci}
17188c2ecf20Sopenharmony_ci
17198c2ecf20Sopenharmony_cistatic void sii8620_ecbus_up(struct sii8620 *ctx, int ret)
17208c2ecf20Sopenharmony_ci{
17218c2ecf20Sopenharmony_ci	if (ret < 0)
17228c2ecf20Sopenharmony_ci		return;
17238c2ecf20Sopenharmony_ci
17248c2ecf20Sopenharmony_ci	sii8620_set_mode(ctx, CM_ECBUS_S);
17258c2ecf20Sopenharmony_ci}
17268c2ecf20Sopenharmony_ci
17278c2ecf20Sopenharmony_cistatic void sii8620_got_ecbus_speed(struct sii8620 *ctx, int ret)
17288c2ecf20Sopenharmony_ci{
17298c2ecf20Sopenharmony_ci	if (ret < 0)
17308c2ecf20Sopenharmony_ci		return;
17318c2ecf20Sopenharmony_ci
17328c2ecf20Sopenharmony_ci	sii8620_mt_write_stat(ctx, MHL_XDS_REG(CURR_ECBUS_MODE),
17338c2ecf20Sopenharmony_ci			      MHL_XDS_ECBUS_S | MHL_XDS_SLOT_MODE_8BIT);
17348c2ecf20Sopenharmony_ci	sii8620_mt_rap(ctx, MHL_RAP_CBUS_MODE_UP);
17358c2ecf20Sopenharmony_ci	sii8620_mt_set_cont(ctx, sii8620_ecbus_up);
17368c2ecf20Sopenharmony_ci}
17378c2ecf20Sopenharmony_ci
17388c2ecf20Sopenharmony_cistatic void sii8620_mhl_burst_emsc_support_set(struct mhl_burst_emsc_support *d,
17398c2ecf20Sopenharmony_ci	enum mhl_burst_id id)
17408c2ecf20Sopenharmony_ci{
17418c2ecf20Sopenharmony_ci	sii8620_mhl_burst_hdr_set(&d->hdr, MHL_BURST_ID_EMSC_SUPPORT);
17428c2ecf20Sopenharmony_ci	d->num_entries = 1;
17438c2ecf20Sopenharmony_ci	d->burst_id[0] = cpu_to_be16(id);
17448c2ecf20Sopenharmony_ci}
17458c2ecf20Sopenharmony_ci
17468c2ecf20Sopenharmony_cistatic void sii8620_send_features(struct sii8620 *ctx)
17478c2ecf20Sopenharmony_ci{
17488c2ecf20Sopenharmony_ci	u8 buf[16];
17498c2ecf20Sopenharmony_ci
17508c2ecf20Sopenharmony_ci	sii8620_write(ctx, REG_MDT_XMIT_CTRL, BIT_MDT_XMIT_CTRL_EN
17518c2ecf20Sopenharmony_ci		| BIT_MDT_XMIT_CTRL_FIXED_BURST_LEN);
17528c2ecf20Sopenharmony_ci	sii8620_mhl_burst_emsc_support_set((void *)buf,
17538c2ecf20Sopenharmony_ci		MHL_BURST_ID_HID_PAYLOAD);
17548c2ecf20Sopenharmony_ci	sii8620_write_buf(ctx, REG_MDT_XMIT_WRITE_PORT, buf, ARRAY_SIZE(buf));
17558c2ecf20Sopenharmony_ci}
17568c2ecf20Sopenharmony_ci
17578c2ecf20Sopenharmony_cistatic bool sii8620_rcp_consume(struct sii8620 *ctx, u8 scancode)
17588c2ecf20Sopenharmony_ci{
17598c2ecf20Sopenharmony_ci	bool pressed = !(scancode & MHL_RCP_KEY_RELEASED_MASK);
17608c2ecf20Sopenharmony_ci
17618c2ecf20Sopenharmony_ci	scancode &= MHL_RCP_KEY_ID_MASK;
17628c2ecf20Sopenharmony_ci
17638c2ecf20Sopenharmony_ci	if (!IS_ENABLED(CONFIG_RC_CORE) || !ctx->rc_dev)
17648c2ecf20Sopenharmony_ci		return false;
17658c2ecf20Sopenharmony_ci
17668c2ecf20Sopenharmony_ci	if (pressed)
17678c2ecf20Sopenharmony_ci		rc_keydown(ctx->rc_dev, RC_PROTO_CEC, scancode, 0);
17688c2ecf20Sopenharmony_ci	else
17698c2ecf20Sopenharmony_ci		rc_keyup(ctx->rc_dev);
17708c2ecf20Sopenharmony_ci
17718c2ecf20Sopenharmony_ci	return true;
17728c2ecf20Sopenharmony_ci}
17738c2ecf20Sopenharmony_ci
17748c2ecf20Sopenharmony_cistatic void sii8620_msc_mr_set_int(struct sii8620 *ctx)
17758c2ecf20Sopenharmony_ci{
17768c2ecf20Sopenharmony_ci	u8 ints[MHL_INT_SIZE];
17778c2ecf20Sopenharmony_ci
17788c2ecf20Sopenharmony_ci	sii8620_read_buf(ctx, REG_MHL_INT_0, ints, MHL_INT_SIZE);
17798c2ecf20Sopenharmony_ci	sii8620_write_buf(ctx, REG_MHL_INT_0, ints, MHL_INT_SIZE);
17808c2ecf20Sopenharmony_ci
17818c2ecf20Sopenharmony_ci	if (ints[MHL_INT_RCHANGE] & MHL_INT_RC_DCAP_CHG) {
17828c2ecf20Sopenharmony_ci		switch (ctx->mode) {
17838c2ecf20Sopenharmony_ci		case CM_MHL3:
17848c2ecf20Sopenharmony_ci			sii8620_mt_read_xdevcap_reg(ctx, MHL_XDC_ECBUS_SPEEDS);
17858c2ecf20Sopenharmony_ci			sii8620_mt_set_cont(ctx, sii8620_got_ecbus_speed);
17868c2ecf20Sopenharmony_ci			break;
17878c2ecf20Sopenharmony_ci		case CM_ECBUS_S:
17888c2ecf20Sopenharmony_ci			sii8620_mt_read_devcap(ctx, true);
17898c2ecf20Sopenharmony_ci			break;
17908c2ecf20Sopenharmony_ci		default:
17918c2ecf20Sopenharmony_ci			break;
17928c2ecf20Sopenharmony_ci		}
17938c2ecf20Sopenharmony_ci	}
17948c2ecf20Sopenharmony_ci	if (ints[MHL_INT_RCHANGE] & MHL_INT_RC_FEAT_REQ)
17958c2ecf20Sopenharmony_ci		sii8620_send_features(ctx);
17968c2ecf20Sopenharmony_ci	if (ints[MHL_INT_RCHANGE] & MHL_INT_RC_FEAT_COMPLETE) {
17978c2ecf20Sopenharmony_ci		ctx->feature_complete = true;
17988c2ecf20Sopenharmony_ci		if (ctx->edid)
17998c2ecf20Sopenharmony_ci			sii8620_enable_hpd(ctx);
18008c2ecf20Sopenharmony_ci	}
18018c2ecf20Sopenharmony_ci}
18028c2ecf20Sopenharmony_ci
18038c2ecf20Sopenharmony_cistatic struct sii8620_mt_msg *sii8620_msc_msg_first(struct sii8620 *ctx)
18048c2ecf20Sopenharmony_ci{
18058c2ecf20Sopenharmony_ci	struct device *dev = ctx->dev;
18068c2ecf20Sopenharmony_ci
18078c2ecf20Sopenharmony_ci	if (list_empty(&ctx->mt_queue)) {
18088c2ecf20Sopenharmony_ci		dev_err(dev, "unexpected MSC MT response\n");
18098c2ecf20Sopenharmony_ci		return NULL;
18108c2ecf20Sopenharmony_ci	}
18118c2ecf20Sopenharmony_ci
18128c2ecf20Sopenharmony_ci	return list_first_entry(&ctx->mt_queue, struct sii8620_mt_msg, node);
18138c2ecf20Sopenharmony_ci}
18148c2ecf20Sopenharmony_ci
18158c2ecf20Sopenharmony_cistatic void sii8620_msc_mt_done(struct sii8620 *ctx)
18168c2ecf20Sopenharmony_ci{
18178c2ecf20Sopenharmony_ci	struct sii8620_mt_msg *msg = sii8620_msc_msg_first(ctx);
18188c2ecf20Sopenharmony_ci
18198c2ecf20Sopenharmony_ci	if (!msg)
18208c2ecf20Sopenharmony_ci		return;
18218c2ecf20Sopenharmony_ci
18228c2ecf20Sopenharmony_ci	msg->ret = sii8620_readb(ctx, REG_MSC_MT_RCVD_DATA0);
18238c2ecf20Sopenharmony_ci	ctx->mt_state = MT_STATE_DONE;
18248c2ecf20Sopenharmony_ci}
18258c2ecf20Sopenharmony_ci
18268c2ecf20Sopenharmony_cistatic void sii8620_msc_mr_msc_msg(struct sii8620 *ctx)
18278c2ecf20Sopenharmony_ci{
18288c2ecf20Sopenharmony_ci	struct sii8620_mt_msg *msg;
18298c2ecf20Sopenharmony_ci	u8 buf[2];
18308c2ecf20Sopenharmony_ci
18318c2ecf20Sopenharmony_ci	sii8620_read_buf(ctx, REG_MSC_MR_MSC_MSG_RCVD_1ST_DATA, buf, 2);
18328c2ecf20Sopenharmony_ci
18338c2ecf20Sopenharmony_ci	switch (buf[0]) {
18348c2ecf20Sopenharmony_ci	case MHL_MSC_MSG_RAPK:
18358c2ecf20Sopenharmony_ci		msg = sii8620_msc_msg_first(ctx);
18368c2ecf20Sopenharmony_ci		if (!msg)
18378c2ecf20Sopenharmony_ci			return;
18388c2ecf20Sopenharmony_ci		msg->ret = buf[1];
18398c2ecf20Sopenharmony_ci		ctx->mt_state = MT_STATE_DONE;
18408c2ecf20Sopenharmony_ci		break;
18418c2ecf20Sopenharmony_ci	case MHL_MSC_MSG_RCP:
18428c2ecf20Sopenharmony_ci		if (!sii8620_rcp_consume(ctx, buf[1]))
18438c2ecf20Sopenharmony_ci			sii8620_mt_rcpe(ctx,
18448c2ecf20Sopenharmony_ci					MHL_RCPE_STATUS_INEFFECTIVE_KEY_CODE);
18458c2ecf20Sopenharmony_ci		sii8620_mt_rcpk(ctx, buf[1]);
18468c2ecf20Sopenharmony_ci		break;
18478c2ecf20Sopenharmony_ci	default:
18488c2ecf20Sopenharmony_ci		dev_err(ctx->dev, "%s message type %d,%d not supported",
18498c2ecf20Sopenharmony_ci			__func__, buf[0], buf[1]);
18508c2ecf20Sopenharmony_ci	}
18518c2ecf20Sopenharmony_ci}
18528c2ecf20Sopenharmony_ci
18538c2ecf20Sopenharmony_cistatic void sii8620_irq_msc(struct sii8620 *ctx)
18548c2ecf20Sopenharmony_ci{
18558c2ecf20Sopenharmony_ci	u8 stat = sii8620_readb(ctx, REG_CBUS_INT_0);
18568c2ecf20Sopenharmony_ci
18578c2ecf20Sopenharmony_ci	if (stat & ~BIT_CBUS_HPD_CHG)
18588c2ecf20Sopenharmony_ci		sii8620_write(ctx, REG_CBUS_INT_0, stat & ~BIT_CBUS_HPD_CHG);
18598c2ecf20Sopenharmony_ci
18608c2ecf20Sopenharmony_ci	if (stat & BIT_CBUS_HPD_CHG) {
18618c2ecf20Sopenharmony_ci		u8 cbus_stat = sii8620_readb(ctx, REG_CBUS_STATUS);
18628c2ecf20Sopenharmony_ci
18638c2ecf20Sopenharmony_ci		if ((cbus_stat ^ ctx->cbus_status) & BIT_CBUS_STATUS_CBUS_HPD) {
18648c2ecf20Sopenharmony_ci			sii8620_write(ctx, REG_CBUS_INT_0, BIT_CBUS_HPD_CHG);
18658c2ecf20Sopenharmony_ci		} else {
18668c2ecf20Sopenharmony_ci			stat ^= BIT_CBUS_STATUS_CBUS_HPD;
18678c2ecf20Sopenharmony_ci			cbus_stat ^= BIT_CBUS_STATUS_CBUS_HPD;
18688c2ecf20Sopenharmony_ci		}
18698c2ecf20Sopenharmony_ci		ctx->cbus_status = cbus_stat;
18708c2ecf20Sopenharmony_ci	}
18718c2ecf20Sopenharmony_ci
18728c2ecf20Sopenharmony_ci	if (stat & BIT_CBUS_MSC_MR_WRITE_STAT)
18738c2ecf20Sopenharmony_ci		sii8620_msc_mr_write_stat(ctx);
18748c2ecf20Sopenharmony_ci
18758c2ecf20Sopenharmony_ci	if (stat & BIT_CBUS_HPD_CHG) {
18768c2ecf20Sopenharmony_ci		if (ctx->cbus_status & BIT_CBUS_STATUS_CBUS_HPD) {
18778c2ecf20Sopenharmony_ci			ctx->sink_detected = true;
18788c2ecf20Sopenharmony_ci			sii8620_identify_sink(ctx);
18798c2ecf20Sopenharmony_ci		} else {
18808c2ecf20Sopenharmony_ci			sii8620_hpd_unplugged(ctx);
18818c2ecf20Sopenharmony_ci		}
18828c2ecf20Sopenharmony_ci	}
18838c2ecf20Sopenharmony_ci
18848c2ecf20Sopenharmony_ci	if (stat & BIT_CBUS_MSC_MR_SET_INT)
18858c2ecf20Sopenharmony_ci		sii8620_msc_mr_set_int(ctx);
18868c2ecf20Sopenharmony_ci
18878c2ecf20Sopenharmony_ci	if (stat & BIT_CBUS_MSC_MT_DONE)
18888c2ecf20Sopenharmony_ci		sii8620_msc_mt_done(ctx);
18898c2ecf20Sopenharmony_ci
18908c2ecf20Sopenharmony_ci	if (stat & BIT_CBUS_MSC_MR_MSC_MSG)
18918c2ecf20Sopenharmony_ci		sii8620_msc_mr_msc_msg(ctx);
18928c2ecf20Sopenharmony_ci}
18938c2ecf20Sopenharmony_ci
18948c2ecf20Sopenharmony_cistatic void sii8620_irq_coc(struct sii8620 *ctx)
18958c2ecf20Sopenharmony_ci{
18968c2ecf20Sopenharmony_ci	u8 stat = sii8620_readb(ctx, REG_COC_INTR);
18978c2ecf20Sopenharmony_ci
18988c2ecf20Sopenharmony_ci	if (stat & BIT_COC_CALIBRATION_DONE) {
18998c2ecf20Sopenharmony_ci		u8 cstat = sii8620_readb(ctx, REG_COC_STAT_0);
19008c2ecf20Sopenharmony_ci
19018c2ecf20Sopenharmony_ci		cstat &= BIT_COC_STAT_0_PLL_LOCKED | MSK_COC_STAT_0_FSM_STATE;
19028c2ecf20Sopenharmony_ci		if (cstat == (BIT_COC_STAT_0_PLL_LOCKED | 0x02)) {
19038c2ecf20Sopenharmony_ci			sii8620_write_seq_static(ctx,
19048c2ecf20Sopenharmony_ci				REG_COC_CTLB, 0,
19058c2ecf20Sopenharmony_ci				REG_TRXINTMH, BIT_TDM_INTR_SYNC_DATA
19068c2ecf20Sopenharmony_ci					      | BIT_TDM_INTR_SYNC_WAIT
19078c2ecf20Sopenharmony_ci			);
19088c2ecf20Sopenharmony_ci		}
19098c2ecf20Sopenharmony_ci	}
19108c2ecf20Sopenharmony_ci
19118c2ecf20Sopenharmony_ci	sii8620_write(ctx, REG_COC_INTR, stat);
19128c2ecf20Sopenharmony_ci}
19138c2ecf20Sopenharmony_ci
19148c2ecf20Sopenharmony_cistatic void sii8620_irq_merr(struct sii8620 *ctx)
19158c2ecf20Sopenharmony_ci{
19168c2ecf20Sopenharmony_ci	u8 stat = sii8620_readb(ctx, REG_CBUS_INT_1);
19178c2ecf20Sopenharmony_ci
19188c2ecf20Sopenharmony_ci	sii8620_write(ctx, REG_CBUS_INT_1, stat);
19198c2ecf20Sopenharmony_ci}
19208c2ecf20Sopenharmony_ci
19218c2ecf20Sopenharmony_cistatic void sii8620_irq_edid(struct sii8620 *ctx)
19228c2ecf20Sopenharmony_ci{
19238c2ecf20Sopenharmony_ci	u8 stat = sii8620_readb(ctx, REG_INTR9);
19248c2ecf20Sopenharmony_ci
19258c2ecf20Sopenharmony_ci	sii8620_write(ctx, REG_INTR9, stat);
19268c2ecf20Sopenharmony_ci
19278c2ecf20Sopenharmony_ci	if (stat & BIT_INTR9_DEVCAP_DONE)
19288c2ecf20Sopenharmony_ci		ctx->mt_state = MT_STATE_DONE;
19298c2ecf20Sopenharmony_ci}
19308c2ecf20Sopenharmony_ci
19318c2ecf20Sopenharmony_cistatic void sii8620_irq_scdt(struct sii8620 *ctx)
19328c2ecf20Sopenharmony_ci{
19338c2ecf20Sopenharmony_ci	u8 stat = sii8620_readb(ctx, REG_INTR5);
19348c2ecf20Sopenharmony_ci
19358c2ecf20Sopenharmony_ci	if (stat & BIT_INTR_SCDT_CHANGE) {
19368c2ecf20Sopenharmony_ci		u8 cstat = sii8620_readb(ctx, REG_TMDS_CSTAT_P3);
19378c2ecf20Sopenharmony_ci
19388c2ecf20Sopenharmony_ci		if (cstat & BIT_TMDS_CSTAT_P3_SCDT)
19398c2ecf20Sopenharmony_ci			sii8620_start_video(ctx);
19408c2ecf20Sopenharmony_ci	}
19418c2ecf20Sopenharmony_ci
19428c2ecf20Sopenharmony_ci	sii8620_write(ctx, REG_INTR5, stat);
19438c2ecf20Sopenharmony_ci}
19448c2ecf20Sopenharmony_ci
19458c2ecf20Sopenharmony_cistatic void sii8620_got_xdevcap(struct sii8620 *ctx, int ret)
19468c2ecf20Sopenharmony_ci{
19478c2ecf20Sopenharmony_ci	if (ret < 0)
19488c2ecf20Sopenharmony_ci		return;
19498c2ecf20Sopenharmony_ci
19508c2ecf20Sopenharmony_ci	sii8620_mt_read_devcap(ctx, false);
19518c2ecf20Sopenharmony_ci}
19528c2ecf20Sopenharmony_ci
19538c2ecf20Sopenharmony_cistatic void sii8620_irq_tdm(struct sii8620 *ctx)
19548c2ecf20Sopenharmony_ci{
19558c2ecf20Sopenharmony_ci	u8 stat = sii8620_readb(ctx, REG_TRXINTH);
19568c2ecf20Sopenharmony_ci	u8 tdm = sii8620_readb(ctx, REG_TRXSTA2);
19578c2ecf20Sopenharmony_ci
19588c2ecf20Sopenharmony_ci	if ((tdm & MSK_TDM_SYNCHRONIZED) == VAL_TDM_SYNCHRONIZED) {
19598c2ecf20Sopenharmony_ci		ctx->mode = CM_ECBUS_S;
19608c2ecf20Sopenharmony_ci		ctx->burst.rx_ack = 0;
19618c2ecf20Sopenharmony_ci		ctx->burst.r_size = SII8620_BURST_BUF_LEN;
19628c2ecf20Sopenharmony_ci		sii8620_burst_tx_rbuf_info(ctx, SII8620_BURST_BUF_LEN);
19638c2ecf20Sopenharmony_ci		sii8620_mt_read_devcap(ctx, true);
19648c2ecf20Sopenharmony_ci		sii8620_mt_set_cont(ctx, sii8620_got_xdevcap);
19658c2ecf20Sopenharmony_ci	} else {
19668c2ecf20Sopenharmony_ci		sii8620_write_seq_static(ctx,
19678c2ecf20Sopenharmony_ci			REG_MHL_PLL_CTL2, 0,
19688c2ecf20Sopenharmony_ci			REG_MHL_PLL_CTL2, BIT_MHL_PLL_CTL2_CLKDETECT_EN
19698c2ecf20Sopenharmony_ci		);
19708c2ecf20Sopenharmony_ci	}
19718c2ecf20Sopenharmony_ci
19728c2ecf20Sopenharmony_ci	sii8620_write(ctx, REG_TRXINTH, stat);
19738c2ecf20Sopenharmony_ci}
19748c2ecf20Sopenharmony_ci
19758c2ecf20Sopenharmony_cistatic void sii8620_irq_block(struct sii8620 *ctx)
19768c2ecf20Sopenharmony_ci{
19778c2ecf20Sopenharmony_ci	u8 stat = sii8620_readb(ctx, REG_EMSCINTR);
19788c2ecf20Sopenharmony_ci
19798c2ecf20Sopenharmony_ci	if (stat & BIT_EMSCINTR_SPI_DVLD) {
19808c2ecf20Sopenharmony_ci		u8 bstat = sii8620_readb(ctx, REG_SPIBURSTSTAT);
19818c2ecf20Sopenharmony_ci
19828c2ecf20Sopenharmony_ci		if (bstat & BIT_SPIBURSTSTAT_EMSC_NORMAL_MODE)
19838c2ecf20Sopenharmony_ci			sii8620_burst_receive(ctx);
19848c2ecf20Sopenharmony_ci	}
19858c2ecf20Sopenharmony_ci
19868c2ecf20Sopenharmony_ci	sii8620_write(ctx, REG_EMSCINTR, stat);
19878c2ecf20Sopenharmony_ci}
19888c2ecf20Sopenharmony_ci
19898c2ecf20Sopenharmony_cistatic void sii8620_irq_ddc(struct sii8620 *ctx)
19908c2ecf20Sopenharmony_ci{
19918c2ecf20Sopenharmony_ci	u8 stat = sii8620_readb(ctx, REG_INTR3);
19928c2ecf20Sopenharmony_ci
19938c2ecf20Sopenharmony_ci	if (stat & BIT_DDC_CMD_DONE) {
19948c2ecf20Sopenharmony_ci		sii8620_write(ctx, REG_INTR3_MASK, 0);
19958c2ecf20Sopenharmony_ci		if (sii8620_is_mhl3(ctx) && !ctx->feature_complete)
19968c2ecf20Sopenharmony_ci			sii8620_mt_set_int(ctx, MHL_INT_REG(RCHANGE),
19978c2ecf20Sopenharmony_ci					   MHL_INT_RC_FEAT_REQ);
19988c2ecf20Sopenharmony_ci		else
19998c2ecf20Sopenharmony_ci			sii8620_enable_hpd(ctx);
20008c2ecf20Sopenharmony_ci	}
20018c2ecf20Sopenharmony_ci	sii8620_write(ctx, REG_INTR3, stat);
20028c2ecf20Sopenharmony_ci}
20038c2ecf20Sopenharmony_ci
20048c2ecf20Sopenharmony_ci/* endian agnostic, non-volatile version of test_bit */
20058c2ecf20Sopenharmony_cistatic bool sii8620_test_bit(unsigned int nr, const u8 *addr)
20068c2ecf20Sopenharmony_ci{
20078c2ecf20Sopenharmony_ci	return 1 & (addr[nr / BITS_PER_BYTE] >> (nr % BITS_PER_BYTE));
20088c2ecf20Sopenharmony_ci}
20098c2ecf20Sopenharmony_ci
20108c2ecf20Sopenharmony_cistatic irqreturn_t sii8620_irq_thread(int irq, void *data)
20118c2ecf20Sopenharmony_ci{
20128c2ecf20Sopenharmony_ci	static const struct {
20138c2ecf20Sopenharmony_ci		int bit;
20148c2ecf20Sopenharmony_ci		void (*handler)(struct sii8620 *ctx);
20158c2ecf20Sopenharmony_ci	} irq_vec[] = {
20168c2ecf20Sopenharmony_ci		{ BIT_FAST_INTR_STAT_DISC, sii8620_irq_disc },
20178c2ecf20Sopenharmony_ci		{ BIT_FAST_INTR_STAT_G2WB, sii8620_irq_g2wb },
20188c2ecf20Sopenharmony_ci		{ BIT_FAST_INTR_STAT_COC, sii8620_irq_coc },
20198c2ecf20Sopenharmony_ci		{ BIT_FAST_INTR_STAT_TDM, sii8620_irq_tdm },
20208c2ecf20Sopenharmony_ci		{ BIT_FAST_INTR_STAT_MSC, sii8620_irq_msc },
20218c2ecf20Sopenharmony_ci		{ BIT_FAST_INTR_STAT_MERR, sii8620_irq_merr },
20228c2ecf20Sopenharmony_ci		{ BIT_FAST_INTR_STAT_BLOCK, sii8620_irq_block },
20238c2ecf20Sopenharmony_ci		{ BIT_FAST_INTR_STAT_EDID, sii8620_irq_edid },
20248c2ecf20Sopenharmony_ci		{ BIT_FAST_INTR_STAT_DDC, sii8620_irq_ddc },
20258c2ecf20Sopenharmony_ci		{ BIT_FAST_INTR_STAT_SCDT, sii8620_irq_scdt },
20268c2ecf20Sopenharmony_ci	};
20278c2ecf20Sopenharmony_ci	struct sii8620 *ctx = data;
20288c2ecf20Sopenharmony_ci	u8 stats[LEN_FAST_INTR_STAT];
20298c2ecf20Sopenharmony_ci	int i, ret;
20308c2ecf20Sopenharmony_ci
20318c2ecf20Sopenharmony_ci	mutex_lock(&ctx->lock);
20328c2ecf20Sopenharmony_ci
20338c2ecf20Sopenharmony_ci	sii8620_read_buf(ctx, REG_FAST_INTR_STAT, stats, ARRAY_SIZE(stats));
20348c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(irq_vec); ++i)
20358c2ecf20Sopenharmony_ci		if (sii8620_test_bit(irq_vec[i].bit, stats))
20368c2ecf20Sopenharmony_ci			irq_vec[i].handler(ctx);
20378c2ecf20Sopenharmony_ci
20388c2ecf20Sopenharmony_ci	sii8620_burst_rx_all(ctx);
20398c2ecf20Sopenharmony_ci	sii8620_mt_work(ctx);
20408c2ecf20Sopenharmony_ci	sii8620_burst_send(ctx);
20418c2ecf20Sopenharmony_ci
20428c2ecf20Sopenharmony_ci	ret = sii8620_clear_error(ctx);
20438c2ecf20Sopenharmony_ci	if (ret) {
20448c2ecf20Sopenharmony_ci		dev_err(ctx->dev, "Error during IRQ handling, %d.\n", ret);
20458c2ecf20Sopenharmony_ci		sii8620_mhl_disconnected(ctx);
20468c2ecf20Sopenharmony_ci	}
20478c2ecf20Sopenharmony_ci	mutex_unlock(&ctx->lock);
20488c2ecf20Sopenharmony_ci
20498c2ecf20Sopenharmony_ci	return IRQ_HANDLED;
20508c2ecf20Sopenharmony_ci}
20518c2ecf20Sopenharmony_ci
20528c2ecf20Sopenharmony_cistatic void sii8620_cable_in(struct sii8620 *ctx)
20538c2ecf20Sopenharmony_ci{
20548c2ecf20Sopenharmony_ci	struct device *dev = ctx->dev;
20558c2ecf20Sopenharmony_ci	u8 ver[5];
20568c2ecf20Sopenharmony_ci	int ret;
20578c2ecf20Sopenharmony_ci
20588c2ecf20Sopenharmony_ci	ret = sii8620_hw_on(ctx);
20598c2ecf20Sopenharmony_ci	if (ret) {
20608c2ecf20Sopenharmony_ci		dev_err(dev, "Error powering on, %d.\n", ret);
20618c2ecf20Sopenharmony_ci		return;
20628c2ecf20Sopenharmony_ci	}
20638c2ecf20Sopenharmony_ci
20648c2ecf20Sopenharmony_ci	sii8620_read_buf(ctx, REG_VND_IDL, ver, ARRAY_SIZE(ver));
20658c2ecf20Sopenharmony_ci	ret = sii8620_clear_error(ctx);
20668c2ecf20Sopenharmony_ci	if (ret) {
20678c2ecf20Sopenharmony_ci		dev_err(dev, "Error accessing I2C bus, %d.\n", ret);
20688c2ecf20Sopenharmony_ci		return;
20698c2ecf20Sopenharmony_ci	}
20708c2ecf20Sopenharmony_ci
20718c2ecf20Sopenharmony_ci	dev_info(dev, "ChipID %02x%02x:%02x%02x rev %02x.\n", ver[1], ver[0],
20728c2ecf20Sopenharmony_ci		 ver[3], ver[2], ver[4]);
20738c2ecf20Sopenharmony_ci
20748c2ecf20Sopenharmony_ci	sii8620_write(ctx, REG_DPD,
20758c2ecf20Sopenharmony_ci		      BIT_DPD_PWRON_PLL | BIT_DPD_PDNTX12 | BIT_DPD_OSC_EN);
20768c2ecf20Sopenharmony_ci
20778c2ecf20Sopenharmony_ci	sii8620_xtal_set_rate(ctx);
20788c2ecf20Sopenharmony_ci	sii8620_disconnect(ctx);
20798c2ecf20Sopenharmony_ci
20808c2ecf20Sopenharmony_ci	sii8620_write_seq_static(ctx,
20818c2ecf20Sopenharmony_ci		REG_MHL_CBUS_CTL0, VAL_MHL_CBUS_CTL0_CBUS_DRV_SEL_STRONG
20828c2ecf20Sopenharmony_ci			| VAL_MHL_CBUS_CTL0_CBUS_RGND_VBIAS_734,
20838c2ecf20Sopenharmony_ci		REG_MHL_CBUS_CTL1, VAL_MHL_CBUS_CTL1_1115_OHM,
20848c2ecf20Sopenharmony_ci		REG_DPD, BIT_DPD_PWRON_PLL | BIT_DPD_PDNTX12 | BIT_DPD_OSC_EN,
20858c2ecf20Sopenharmony_ci	);
20868c2ecf20Sopenharmony_ci
20878c2ecf20Sopenharmony_ci	ret = sii8620_clear_error(ctx);
20888c2ecf20Sopenharmony_ci	if (ret) {
20898c2ecf20Sopenharmony_ci		dev_err(dev, "Error accessing I2C bus, %d.\n", ret);
20908c2ecf20Sopenharmony_ci		return;
20918c2ecf20Sopenharmony_ci	}
20928c2ecf20Sopenharmony_ci
20938c2ecf20Sopenharmony_ci	enable_irq(to_i2c_client(ctx->dev)->irq);
20948c2ecf20Sopenharmony_ci}
20958c2ecf20Sopenharmony_ci
20968c2ecf20Sopenharmony_cistatic void sii8620_init_rcp_input_dev(struct sii8620 *ctx)
20978c2ecf20Sopenharmony_ci{
20988c2ecf20Sopenharmony_ci	struct rc_dev *rc_dev;
20998c2ecf20Sopenharmony_ci	int ret;
21008c2ecf20Sopenharmony_ci
21018c2ecf20Sopenharmony_ci	if (!IS_ENABLED(CONFIG_RC_CORE))
21028c2ecf20Sopenharmony_ci		return;
21038c2ecf20Sopenharmony_ci
21048c2ecf20Sopenharmony_ci	rc_dev = rc_allocate_device(RC_DRIVER_SCANCODE);
21058c2ecf20Sopenharmony_ci	if (!rc_dev) {
21068c2ecf20Sopenharmony_ci		dev_err(ctx->dev, "Failed to allocate RC device\n");
21078c2ecf20Sopenharmony_ci		ctx->error = -ENOMEM;
21088c2ecf20Sopenharmony_ci		return;
21098c2ecf20Sopenharmony_ci	}
21108c2ecf20Sopenharmony_ci
21118c2ecf20Sopenharmony_ci	rc_dev->input_phys = "sii8620/input0";
21128c2ecf20Sopenharmony_ci	rc_dev->input_id.bustype = BUS_VIRTUAL;
21138c2ecf20Sopenharmony_ci	rc_dev->map_name = RC_MAP_CEC;
21148c2ecf20Sopenharmony_ci	rc_dev->allowed_protocols = RC_PROTO_BIT_CEC;
21158c2ecf20Sopenharmony_ci	rc_dev->driver_name = "sii8620";
21168c2ecf20Sopenharmony_ci	rc_dev->device_name = "sii8620";
21178c2ecf20Sopenharmony_ci
21188c2ecf20Sopenharmony_ci	ret = rc_register_device(rc_dev);
21198c2ecf20Sopenharmony_ci
21208c2ecf20Sopenharmony_ci	if (ret) {
21218c2ecf20Sopenharmony_ci		dev_err(ctx->dev, "Failed to register RC device\n");
21228c2ecf20Sopenharmony_ci		ctx->error = ret;
21238c2ecf20Sopenharmony_ci		rc_free_device(rc_dev);
21248c2ecf20Sopenharmony_ci		return;
21258c2ecf20Sopenharmony_ci	}
21268c2ecf20Sopenharmony_ci	ctx->rc_dev = rc_dev;
21278c2ecf20Sopenharmony_ci}
21288c2ecf20Sopenharmony_ci
21298c2ecf20Sopenharmony_cistatic void sii8620_cable_out(struct sii8620 *ctx)
21308c2ecf20Sopenharmony_ci{
21318c2ecf20Sopenharmony_ci	disable_irq(to_i2c_client(ctx->dev)->irq);
21328c2ecf20Sopenharmony_ci	sii8620_hw_off(ctx);
21338c2ecf20Sopenharmony_ci}
21348c2ecf20Sopenharmony_ci
21358c2ecf20Sopenharmony_cistatic void sii8620_extcon_work(struct work_struct *work)
21368c2ecf20Sopenharmony_ci{
21378c2ecf20Sopenharmony_ci	struct sii8620 *ctx =
21388c2ecf20Sopenharmony_ci		container_of(work, struct sii8620, extcon_wq);
21398c2ecf20Sopenharmony_ci	int state = extcon_get_state(ctx->extcon, EXTCON_DISP_MHL);
21408c2ecf20Sopenharmony_ci
21418c2ecf20Sopenharmony_ci	if (state == ctx->cable_state)
21428c2ecf20Sopenharmony_ci		return;
21438c2ecf20Sopenharmony_ci
21448c2ecf20Sopenharmony_ci	ctx->cable_state = state;
21458c2ecf20Sopenharmony_ci
21468c2ecf20Sopenharmony_ci	if (state > 0)
21478c2ecf20Sopenharmony_ci		sii8620_cable_in(ctx);
21488c2ecf20Sopenharmony_ci	else
21498c2ecf20Sopenharmony_ci		sii8620_cable_out(ctx);
21508c2ecf20Sopenharmony_ci}
21518c2ecf20Sopenharmony_ci
21528c2ecf20Sopenharmony_cistatic int sii8620_extcon_notifier(struct notifier_block *self,
21538c2ecf20Sopenharmony_ci			unsigned long event, void *ptr)
21548c2ecf20Sopenharmony_ci{
21558c2ecf20Sopenharmony_ci	struct sii8620 *ctx =
21568c2ecf20Sopenharmony_ci		container_of(self, struct sii8620, extcon_nb);
21578c2ecf20Sopenharmony_ci
21588c2ecf20Sopenharmony_ci	schedule_work(&ctx->extcon_wq);
21598c2ecf20Sopenharmony_ci
21608c2ecf20Sopenharmony_ci	return NOTIFY_DONE;
21618c2ecf20Sopenharmony_ci}
21628c2ecf20Sopenharmony_ci
21638c2ecf20Sopenharmony_cistatic int sii8620_extcon_init(struct sii8620 *ctx)
21648c2ecf20Sopenharmony_ci{
21658c2ecf20Sopenharmony_ci	struct extcon_dev *edev;
21668c2ecf20Sopenharmony_ci	struct device_node *musb, *muic;
21678c2ecf20Sopenharmony_ci	int ret;
21688c2ecf20Sopenharmony_ci
21698c2ecf20Sopenharmony_ci	/* get micro-USB connector node */
21708c2ecf20Sopenharmony_ci	musb = of_graph_get_remote_node(ctx->dev->of_node, 1, -1);
21718c2ecf20Sopenharmony_ci	/* next get micro-USB Interface Controller node */
21728c2ecf20Sopenharmony_ci	muic = of_get_next_parent(musb);
21738c2ecf20Sopenharmony_ci
21748c2ecf20Sopenharmony_ci	if (!muic) {
21758c2ecf20Sopenharmony_ci		dev_info(ctx->dev, "no extcon found, switching to 'always on' mode\n");
21768c2ecf20Sopenharmony_ci		return 0;
21778c2ecf20Sopenharmony_ci	}
21788c2ecf20Sopenharmony_ci
21798c2ecf20Sopenharmony_ci	edev = extcon_find_edev_by_node(muic);
21808c2ecf20Sopenharmony_ci	of_node_put(muic);
21818c2ecf20Sopenharmony_ci	if (IS_ERR(edev)) {
21828c2ecf20Sopenharmony_ci		if (PTR_ERR(edev) == -EPROBE_DEFER)
21838c2ecf20Sopenharmony_ci			return -EPROBE_DEFER;
21848c2ecf20Sopenharmony_ci		dev_err(ctx->dev, "Invalid or missing extcon\n");
21858c2ecf20Sopenharmony_ci		return PTR_ERR(edev);
21868c2ecf20Sopenharmony_ci	}
21878c2ecf20Sopenharmony_ci
21888c2ecf20Sopenharmony_ci	ctx->extcon = edev;
21898c2ecf20Sopenharmony_ci	ctx->extcon_nb.notifier_call = sii8620_extcon_notifier;
21908c2ecf20Sopenharmony_ci	INIT_WORK(&ctx->extcon_wq, sii8620_extcon_work);
21918c2ecf20Sopenharmony_ci	ret = extcon_register_notifier(edev, EXTCON_DISP_MHL, &ctx->extcon_nb);
21928c2ecf20Sopenharmony_ci	if (ret) {
21938c2ecf20Sopenharmony_ci		dev_err(ctx->dev, "failed to register notifier for MHL\n");
21948c2ecf20Sopenharmony_ci		return ret;
21958c2ecf20Sopenharmony_ci	}
21968c2ecf20Sopenharmony_ci
21978c2ecf20Sopenharmony_ci	return 0;
21988c2ecf20Sopenharmony_ci}
21998c2ecf20Sopenharmony_ci
22008c2ecf20Sopenharmony_cistatic inline struct sii8620 *bridge_to_sii8620(struct drm_bridge *bridge)
22018c2ecf20Sopenharmony_ci{
22028c2ecf20Sopenharmony_ci	return container_of(bridge, struct sii8620, bridge);
22038c2ecf20Sopenharmony_ci}
22048c2ecf20Sopenharmony_ci
22058c2ecf20Sopenharmony_cistatic int sii8620_attach(struct drm_bridge *bridge,
22068c2ecf20Sopenharmony_ci			  enum drm_bridge_attach_flags flags)
22078c2ecf20Sopenharmony_ci{
22088c2ecf20Sopenharmony_ci	struct sii8620 *ctx = bridge_to_sii8620(bridge);
22098c2ecf20Sopenharmony_ci
22108c2ecf20Sopenharmony_ci	sii8620_init_rcp_input_dev(ctx);
22118c2ecf20Sopenharmony_ci
22128c2ecf20Sopenharmony_ci	return sii8620_clear_error(ctx);
22138c2ecf20Sopenharmony_ci}
22148c2ecf20Sopenharmony_ci
22158c2ecf20Sopenharmony_cistatic void sii8620_detach(struct drm_bridge *bridge)
22168c2ecf20Sopenharmony_ci{
22178c2ecf20Sopenharmony_ci	struct sii8620 *ctx = bridge_to_sii8620(bridge);
22188c2ecf20Sopenharmony_ci
22198c2ecf20Sopenharmony_ci	if (!IS_ENABLED(CONFIG_RC_CORE))
22208c2ecf20Sopenharmony_ci		return;
22218c2ecf20Sopenharmony_ci
22228c2ecf20Sopenharmony_ci	rc_unregister_device(ctx->rc_dev);
22238c2ecf20Sopenharmony_ci}
22248c2ecf20Sopenharmony_ci
22258c2ecf20Sopenharmony_cistatic int sii8620_is_packing_required(struct sii8620 *ctx,
22268c2ecf20Sopenharmony_ci				       const struct drm_display_mode *mode)
22278c2ecf20Sopenharmony_ci{
22288c2ecf20Sopenharmony_ci	int max_pclk, max_pclk_pp_mode;
22298c2ecf20Sopenharmony_ci
22308c2ecf20Sopenharmony_ci	if (sii8620_is_mhl3(ctx)) {
22318c2ecf20Sopenharmony_ci		max_pclk = MHL3_MAX_PCLK;
22328c2ecf20Sopenharmony_ci		max_pclk_pp_mode = MHL3_MAX_PCLK_PP_MODE;
22338c2ecf20Sopenharmony_ci	} else {
22348c2ecf20Sopenharmony_ci		max_pclk = MHL1_MAX_PCLK;
22358c2ecf20Sopenharmony_ci		max_pclk_pp_mode = MHL1_MAX_PCLK_PP_MODE;
22368c2ecf20Sopenharmony_ci	}
22378c2ecf20Sopenharmony_ci
22388c2ecf20Sopenharmony_ci	if (mode->clock < max_pclk)
22398c2ecf20Sopenharmony_ci		return 0;
22408c2ecf20Sopenharmony_ci	else if (mode->clock < max_pclk_pp_mode)
22418c2ecf20Sopenharmony_ci		return 1;
22428c2ecf20Sopenharmony_ci	else
22438c2ecf20Sopenharmony_ci		return -1;
22448c2ecf20Sopenharmony_ci}
22458c2ecf20Sopenharmony_ci
22468c2ecf20Sopenharmony_cistatic enum drm_mode_status sii8620_mode_valid(struct drm_bridge *bridge,
22478c2ecf20Sopenharmony_ci					 const struct drm_display_info *info,
22488c2ecf20Sopenharmony_ci					 const struct drm_display_mode *mode)
22498c2ecf20Sopenharmony_ci{
22508c2ecf20Sopenharmony_ci	struct sii8620 *ctx = bridge_to_sii8620(bridge);
22518c2ecf20Sopenharmony_ci	int pack_required = sii8620_is_packing_required(ctx, mode);
22528c2ecf20Sopenharmony_ci	bool can_pack = ctx->devcap[MHL_DCAP_VID_LINK_MODE] &
22538c2ecf20Sopenharmony_ci			MHL_DCAP_VID_LINK_PPIXEL;
22548c2ecf20Sopenharmony_ci
22558c2ecf20Sopenharmony_ci	switch (pack_required) {
22568c2ecf20Sopenharmony_ci	case 0:
22578c2ecf20Sopenharmony_ci		return MODE_OK;
22588c2ecf20Sopenharmony_ci	case 1:
22598c2ecf20Sopenharmony_ci		return (can_pack) ? MODE_OK : MODE_CLOCK_HIGH;
22608c2ecf20Sopenharmony_ci	default:
22618c2ecf20Sopenharmony_ci		return MODE_CLOCK_HIGH;
22628c2ecf20Sopenharmony_ci	}
22638c2ecf20Sopenharmony_ci}
22648c2ecf20Sopenharmony_ci
22658c2ecf20Sopenharmony_cistatic bool sii8620_mode_fixup(struct drm_bridge *bridge,
22668c2ecf20Sopenharmony_ci			       const struct drm_display_mode *mode,
22678c2ecf20Sopenharmony_ci			       struct drm_display_mode *adjusted_mode)
22688c2ecf20Sopenharmony_ci{
22698c2ecf20Sopenharmony_ci	struct sii8620 *ctx = bridge_to_sii8620(bridge);
22708c2ecf20Sopenharmony_ci
22718c2ecf20Sopenharmony_ci	mutex_lock(&ctx->lock);
22728c2ecf20Sopenharmony_ci
22738c2ecf20Sopenharmony_ci	ctx->use_packed_pixel = sii8620_is_packing_required(ctx, adjusted_mode);
22748c2ecf20Sopenharmony_ci
22758c2ecf20Sopenharmony_ci	mutex_unlock(&ctx->lock);
22768c2ecf20Sopenharmony_ci
22778c2ecf20Sopenharmony_ci	return true;
22788c2ecf20Sopenharmony_ci}
22798c2ecf20Sopenharmony_ci
22808c2ecf20Sopenharmony_cistatic const struct drm_bridge_funcs sii8620_bridge_funcs = {
22818c2ecf20Sopenharmony_ci	.attach = sii8620_attach,
22828c2ecf20Sopenharmony_ci	.detach = sii8620_detach,
22838c2ecf20Sopenharmony_ci	.mode_fixup = sii8620_mode_fixup,
22848c2ecf20Sopenharmony_ci	.mode_valid = sii8620_mode_valid,
22858c2ecf20Sopenharmony_ci};
22868c2ecf20Sopenharmony_ci
22878c2ecf20Sopenharmony_cistatic int sii8620_probe(struct i2c_client *client,
22888c2ecf20Sopenharmony_ci			 const struct i2c_device_id *id)
22898c2ecf20Sopenharmony_ci{
22908c2ecf20Sopenharmony_ci	struct device *dev = &client->dev;
22918c2ecf20Sopenharmony_ci	struct sii8620 *ctx;
22928c2ecf20Sopenharmony_ci	int ret;
22938c2ecf20Sopenharmony_ci
22948c2ecf20Sopenharmony_ci	ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
22958c2ecf20Sopenharmony_ci	if (!ctx)
22968c2ecf20Sopenharmony_ci		return -ENOMEM;
22978c2ecf20Sopenharmony_ci
22988c2ecf20Sopenharmony_ci	ctx->dev = dev;
22998c2ecf20Sopenharmony_ci	mutex_init(&ctx->lock);
23008c2ecf20Sopenharmony_ci	INIT_LIST_HEAD(&ctx->mt_queue);
23018c2ecf20Sopenharmony_ci
23028c2ecf20Sopenharmony_ci	ctx->clk_xtal = devm_clk_get(dev, "xtal");
23038c2ecf20Sopenharmony_ci	if (IS_ERR(ctx->clk_xtal))
23048c2ecf20Sopenharmony_ci		return dev_err_probe(dev, PTR_ERR(ctx->clk_xtal),
23058c2ecf20Sopenharmony_ci				     "failed to get xtal clock from DT\n");
23068c2ecf20Sopenharmony_ci
23078c2ecf20Sopenharmony_ci	if (!client->irq) {
23088c2ecf20Sopenharmony_ci		dev_err(dev, "no irq provided\n");
23098c2ecf20Sopenharmony_ci		return -EINVAL;
23108c2ecf20Sopenharmony_ci	}
23118c2ecf20Sopenharmony_ci	irq_set_status_flags(client->irq, IRQ_NOAUTOEN);
23128c2ecf20Sopenharmony_ci	ret = devm_request_threaded_irq(dev, client->irq, NULL,
23138c2ecf20Sopenharmony_ci					sii8620_irq_thread,
23148c2ecf20Sopenharmony_ci					IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
23158c2ecf20Sopenharmony_ci					"sii8620", ctx);
23168c2ecf20Sopenharmony_ci	if (ret < 0)
23178c2ecf20Sopenharmony_ci		return dev_err_probe(dev, ret,
23188c2ecf20Sopenharmony_ci				     "failed to install IRQ handler\n");
23198c2ecf20Sopenharmony_ci
23208c2ecf20Sopenharmony_ci	ctx->gpio_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
23218c2ecf20Sopenharmony_ci	if (IS_ERR(ctx->gpio_reset))
23228c2ecf20Sopenharmony_ci		return dev_err_probe(dev, PTR_ERR(ctx->gpio_reset),
23238c2ecf20Sopenharmony_ci				     "failed to get reset gpio from DT\n");
23248c2ecf20Sopenharmony_ci
23258c2ecf20Sopenharmony_ci	ctx->supplies[0].supply = "cvcc10";
23268c2ecf20Sopenharmony_ci	ctx->supplies[1].supply = "iovcc18";
23278c2ecf20Sopenharmony_ci	ret = devm_regulator_bulk_get(dev, 2, ctx->supplies);
23288c2ecf20Sopenharmony_ci	if (ret)
23298c2ecf20Sopenharmony_ci		return ret;
23308c2ecf20Sopenharmony_ci
23318c2ecf20Sopenharmony_ci	ret = sii8620_extcon_init(ctx);
23328c2ecf20Sopenharmony_ci	if (ret < 0) {
23338c2ecf20Sopenharmony_ci		dev_err(ctx->dev, "failed to initialize EXTCON\n");
23348c2ecf20Sopenharmony_ci		return ret;
23358c2ecf20Sopenharmony_ci	}
23368c2ecf20Sopenharmony_ci
23378c2ecf20Sopenharmony_ci	i2c_set_clientdata(client, ctx);
23388c2ecf20Sopenharmony_ci
23398c2ecf20Sopenharmony_ci	ctx->bridge.funcs = &sii8620_bridge_funcs;
23408c2ecf20Sopenharmony_ci	ctx->bridge.of_node = dev->of_node;
23418c2ecf20Sopenharmony_ci	drm_bridge_add(&ctx->bridge);
23428c2ecf20Sopenharmony_ci
23438c2ecf20Sopenharmony_ci	if (!ctx->extcon)
23448c2ecf20Sopenharmony_ci		sii8620_cable_in(ctx);
23458c2ecf20Sopenharmony_ci
23468c2ecf20Sopenharmony_ci	return 0;
23478c2ecf20Sopenharmony_ci}
23488c2ecf20Sopenharmony_ci
23498c2ecf20Sopenharmony_cistatic int sii8620_remove(struct i2c_client *client)
23508c2ecf20Sopenharmony_ci{
23518c2ecf20Sopenharmony_ci	struct sii8620 *ctx = i2c_get_clientdata(client);
23528c2ecf20Sopenharmony_ci
23538c2ecf20Sopenharmony_ci	if (ctx->extcon) {
23548c2ecf20Sopenharmony_ci		extcon_unregister_notifier(ctx->extcon, EXTCON_DISP_MHL,
23558c2ecf20Sopenharmony_ci					   &ctx->extcon_nb);
23568c2ecf20Sopenharmony_ci		flush_work(&ctx->extcon_wq);
23578c2ecf20Sopenharmony_ci		if (ctx->cable_state > 0)
23588c2ecf20Sopenharmony_ci			sii8620_cable_out(ctx);
23598c2ecf20Sopenharmony_ci	} else {
23608c2ecf20Sopenharmony_ci		sii8620_cable_out(ctx);
23618c2ecf20Sopenharmony_ci	}
23628c2ecf20Sopenharmony_ci	drm_bridge_remove(&ctx->bridge);
23638c2ecf20Sopenharmony_ci
23648c2ecf20Sopenharmony_ci	return 0;
23658c2ecf20Sopenharmony_ci}
23668c2ecf20Sopenharmony_ci
23678c2ecf20Sopenharmony_cistatic const struct of_device_id sii8620_dt_match[] = {
23688c2ecf20Sopenharmony_ci	{ .compatible = "sil,sii8620" },
23698c2ecf20Sopenharmony_ci	{ },
23708c2ecf20Sopenharmony_ci};
23718c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, sii8620_dt_match);
23728c2ecf20Sopenharmony_ci
23738c2ecf20Sopenharmony_cistatic const struct i2c_device_id sii8620_id[] = {
23748c2ecf20Sopenharmony_ci	{ "sii8620", 0 },
23758c2ecf20Sopenharmony_ci	{ },
23768c2ecf20Sopenharmony_ci};
23778c2ecf20Sopenharmony_ci
23788c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, sii8620_id);
23798c2ecf20Sopenharmony_cistatic struct i2c_driver sii8620_driver = {
23808c2ecf20Sopenharmony_ci	.driver = {
23818c2ecf20Sopenharmony_ci		.name	= "sii8620",
23828c2ecf20Sopenharmony_ci		.of_match_table = of_match_ptr(sii8620_dt_match),
23838c2ecf20Sopenharmony_ci	},
23848c2ecf20Sopenharmony_ci	.probe		= sii8620_probe,
23858c2ecf20Sopenharmony_ci	.remove		= sii8620_remove,
23868c2ecf20Sopenharmony_ci	.id_table = sii8620_id,
23878c2ecf20Sopenharmony_ci};
23888c2ecf20Sopenharmony_ci
23898c2ecf20Sopenharmony_cimodule_i2c_driver(sii8620_driver);
23908c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2");
2391