1ce6e153fSAndrzej Hajda /* 2ce6e153fSAndrzej Hajda * Silicon Image SiI8620 HDMI/MHL bridge driver 3ce6e153fSAndrzej Hajda * 4ce6e153fSAndrzej Hajda * Copyright (C) 2015, Samsung Electronics Co., Ltd. 5ce6e153fSAndrzej Hajda * Andrzej Hajda <a.hajda@samsung.com> 6ce6e153fSAndrzej Hajda * 7ce6e153fSAndrzej Hajda * This program is free software; you can redistribute it and/or modify 8ce6e153fSAndrzej Hajda * it under the terms of the GNU General Public License version 2 as 9ce6e153fSAndrzej Hajda * published by the Free Software Foundation. 10ce6e153fSAndrzej Hajda */ 11ce6e153fSAndrzej Hajda 12e19e9c69SAndrzej Hajda #include <asm/unaligned.h> 13e19e9c69SAndrzej Hajda 14ce6e153fSAndrzej Hajda #include <drm/bridge/mhl.h> 15ce6e153fSAndrzej Hajda #include <drm/drm_crtc.h> 16ce6e153fSAndrzej Hajda #include <drm/drm_edid.h> 17ce6e153fSAndrzej Hajda 18ce6e153fSAndrzej Hajda #include <linux/clk.h> 19ce6e153fSAndrzej Hajda #include <linux/delay.h> 20ce6e153fSAndrzej Hajda #include <linux/gpio/consumer.h> 21ce6e153fSAndrzej Hajda #include <linux/i2c.h> 22ce6e153fSAndrzej Hajda #include <linux/interrupt.h> 23ce6e153fSAndrzej Hajda #include <linux/irq.h> 24ce6e153fSAndrzej Hajda #include <linux/kernel.h> 25ce6e153fSAndrzej Hajda #include <linux/list.h> 26ce6e153fSAndrzej Hajda #include <linux/module.h> 27ce6e153fSAndrzej Hajda #include <linux/mutex.h> 28ce6e153fSAndrzej Hajda #include <linux/regulator/consumer.h> 29ce6e153fSAndrzej Hajda #include <linux/slab.h> 30ce6e153fSAndrzej Hajda 31e25f1f7cSMaciej Purski #include <media/rc-core.h> 32e25f1f7cSMaciej Purski 33ce6e153fSAndrzej Hajda #include "sil-sii8620.h" 34ce6e153fSAndrzej Hajda 35e19e9c69SAndrzej Hajda #define SII8620_BURST_BUF_LEN 288 36ce6e153fSAndrzej Hajda #define VAL_RX_HDMI_CTRL2_DEFVAL VAL_RX_HDMI_CTRL2_IDLE_CNT(3) 37bf1722caSAndrzej Hajda #define MHL1_MAX_LCLK 225000 38bf1722caSAndrzej Hajda #define MHL3_MAX_LCLK 600000 39ce6e153fSAndrzej Hajda 40ce6e153fSAndrzej Hajda enum sii8620_mode { 41ce6e153fSAndrzej Hajda CM_DISCONNECTED, 42ce6e153fSAndrzej Hajda CM_DISCOVERY, 43ce6e153fSAndrzej Hajda CM_MHL1, 44ce6e153fSAndrzej Hajda CM_MHL3, 45ce6e153fSAndrzej Hajda CM_ECBUS_S 46ce6e153fSAndrzej Hajda }; 47ce6e153fSAndrzej Hajda 48ce6e153fSAndrzej Hajda enum sii8620_sink_type { 49ce6e153fSAndrzej Hajda SINK_NONE, 50ce6e153fSAndrzej Hajda SINK_HDMI, 51ce6e153fSAndrzej Hajda SINK_DVI 52ce6e153fSAndrzej Hajda }; 53ce6e153fSAndrzej Hajda 54ce6e153fSAndrzej Hajda enum sii8620_mt_state { 55ce6e153fSAndrzej Hajda MT_STATE_READY, 56ce6e153fSAndrzej Hajda MT_STATE_BUSY, 57ce6e153fSAndrzej Hajda MT_STATE_DONE 58ce6e153fSAndrzej Hajda }; 59ce6e153fSAndrzej Hajda 60ce6e153fSAndrzej Hajda struct sii8620 { 61ce6e153fSAndrzej Hajda struct drm_bridge bridge; 62ce6e153fSAndrzej Hajda struct device *dev; 63e25f1f7cSMaciej Purski struct rc_dev *rc_dev; 64ce6e153fSAndrzej Hajda struct clk *clk_xtal; 65ce6e153fSAndrzej Hajda struct gpio_desc *gpio_reset; 66ce6e153fSAndrzej Hajda struct gpio_desc *gpio_int; 67ce6e153fSAndrzej Hajda struct regulator_bulk_data supplies[2]; 68ce6e153fSAndrzej Hajda struct mutex lock; /* context lock, protects fields below */ 69ce6e153fSAndrzej Hajda int error; 70bf1722caSAndrzej Hajda int pixel_clock; 71bf1722caSAndrzej Hajda unsigned int use_packed_pixel:1; 72bf1722caSAndrzej Hajda int video_code; 73ce6e153fSAndrzej Hajda enum sii8620_mode mode; 74ce6e153fSAndrzej Hajda enum sii8620_sink_type sink_type; 75ce6e153fSAndrzej Hajda u8 cbus_status; 76ce6e153fSAndrzej Hajda u8 stat[MHL_DST_SIZE]; 77ce6e153fSAndrzej Hajda u8 xstat[MHL_XDS_SIZE]; 78ce6e153fSAndrzej Hajda u8 devcap[MHL_DCAP_SIZE]; 79ce6e153fSAndrzej Hajda u8 xdevcap[MHL_XDC_SIZE]; 80bf1722caSAndrzej Hajda u8 avif[HDMI_INFOFRAME_SIZE(AVI)]; 81ce6e153fSAndrzej Hajda struct edid *edid; 82ce6e153fSAndrzej Hajda unsigned int gen2_write_burst:1; 83ce6e153fSAndrzej Hajda enum sii8620_mt_state mt_state; 84ce6e153fSAndrzej Hajda struct list_head mt_queue; 85e19e9c69SAndrzej Hajda struct { 86e19e9c69SAndrzej Hajda int r_size; 87e19e9c69SAndrzej Hajda int r_count; 88e19e9c69SAndrzej Hajda int rx_ack; 89e19e9c69SAndrzej Hajda int rx_count; 90e19e9c69SAndrzej Hajda u8 rx_buf[32]; 91e19e9c69SAndrzej Hajda int tx_count; 92e19e9c69SAndrzej Hajda u8 tx_buf[32]; 93e19e9c69SAndrzej Hajda } burst; 94ce6e153fSAndrzej Hajda }; 95ce6e153fSAndrzej Hajda 96ce6e153fSAndrzej Hajda struct sii8620_mt_msg; 97ce6e153fSAndrzej Hajda 98ce6e153fSAndrzej Hajda typedef void (*sii8620_mt_msg_cb)(struct sii8620 *ctx, 99ce6e153fSAndrzej Hajda struct sii8620_mt_msg *msg); 100ce6e153fSAndrzej Hajda 1010c2d1875SAndrzej Hajda typedef void (*sii8620_cb)(struct sii8620 *ctx, int ret); 1020c2d1875SAndrzej Hajda 103ce6e153fSAndrzej Hajda struct sii8620_mt_msg { 104ce6e153fSAndrzej Hajda struct list_head node; 105ce6e153fSAndrzej Hajda u8 reg[4]; 106ce6e153fSAndrzej Hajda u8 ret; 107ce6e153fSAndrzej Hajda sii8620_mt_msg_cb send; 108ce6e153fSAndrzej Hajda sii8620_mt_msg_cb recv; 1090c2d1875SAndrzej Hajda sii8620_cb continuation; 110ce6e153fSAndrzej Hajda }; 111ce6e153fSAndrzej Hajda 112ce6e153fSAndrzej Hajda static const u8 sii8620_i2c_page[] = { 113ce6e153fSAndrzej Hajda 0x39, /* Main System */ 114ce6e153fSAndrzej Hajda 0x3d, /* TDM and HSIC */ 115ce6e153fSAndrzej Hajda 0x49, /* TMDS Receiver, MHL EDID */ 116ce6e153fSAndrzej Hajda 0x4d, /* eMSC, HDCP, HSIC */ 117ce6e153fSAndrzej Hajda 0x5d, /* MHL Spec */ 118ce6e153fSAndrzej Hajda 0x64, /* MHL CBUS */ 119ce6e153fSAndrzej Hajda 0x59, /* Hardware TPI (Transmitter Programming Interface) */ 120ce6e153fSAndrzej Hajda 0x61, /* eCBUS-S, eCBUS-D */ 121ce6e153fSAndrzej Hajda }; 122ce6e153fSAndrzej Hajda 123ce6e153fSAndrzej Hajda static void sii8620_fetch_edid(struct sii8620 *ctx); 124ce6e153fSAndrzej Hajda static void sii8620_set_upstream_edid(struct sii8620 *ctx); 125ce6e153fSAndrzej Hajda static void sii8620_enable_hpd(struct sii8620 *ctx); 126ce6e153fSAndrzej Hajda static void sii8620_mhl_disconnected(struct sii8620 *ctx); 1272c8fb853SAndrzej Hajda static void sii8620_disconnect(struct sii8620 *ctx); 128ce6e153fSAndrzej Hajda 129ce6e153fSAndrzej Hajda static int sii8620_clear_error(struct sii8620 *ctx) 130ce6e153fSAndrzej Hajda { 131ce6e153fSAndrzej Hajda int ret = ctx->error; 132ce6e153fSAndrzej Hajda 133ce6e153fSAndrzej Hajda ctx->error = 0; 134ce6e153fSAndrzej Hajda return ret; 135ce6e153fSAndrzej Hajda } 136ce6e153fSAndrzej Hajda 137ce6e153fSAndrzej Hajda static void sii8620_read_buf(struct sii8620 *ctx, u16 addr, u8 *buf, int len) 138ce6e153fSAndrzej Hajda { 139ce6e153fSAndrzej Hajda struct device *dev = ctx->dev; 140ce6e153fSAndrzej Hajda struct i2c_client *client = to_i2c_client(dev); 141ce6e153fSAndrzej Hajda u8 data = addr; 142ce6e153fSAndrzej Hajda struct i2c_msg msg[] = { 143ce6e153fSAndrzej Hajda { 144ce6e153fSAndrzej Hajda .addr = sii8620_i2c_page[addr >> 8], 145ce6e153fSAndrzej Hajda .flags = client->flags, 146ce6e153fSAndrzej Hajda .len = 1, 147ce6e153fSAndrzej Hajda .buf = &data 148ce6e153fSAndrzej Hajda }, 149ce6e153fSAndrzej Hajda { 150ce6e153fSAndrzej Hajda .addr = sii8620_i2c_page[addr >> 8], 151ce6e153fSAndrzej Hajda .flags = client->flags | I2C_M_RD, 152ce6e153fSAndrzej Hajda .len = len, 153ce6e153fSAndrzej Hajda .buf = buf 154ce6e153fSAndrzej Hajda }, 155ce6e153fSAndrzej Hajda }; 156ce6e153fSAndrzej Hajda int ret; 157ce6e153fSAndrzej Hajda 158ce6e153fSAndrzej Hajda if (ctx->error) 159ce6e153fSAndrzej Hajda return; 160ce6e153fSAndrzej Hajda 161ce6e153fSAndrzej Hajda ret = i2c_transfer(client->adapter, msg, 2); 162ce6e153fSAndrzej Hajda dev_dbg(dev, "read at %04x: %*ph, %d\n", addr, len, buf, ret); 163ce6e153fSAndrzej Hajda 164ce6e153fSAndrzej Hajda if (ret != 2) { 165ce6e153fSAndrzej Hajda dev_err(dev, "Read at %#06x of %d bytes failed with code %d.\n", 166ce6e153fSAndrzej Hajda addr, len, ret); 167ce6e153fSAndrzej Hajda ctx->error = ret < 0 ? ret : -EIO; 168ce6e153fSAndrzej Hajda } 169ce6e153fSAndrzej Hajda } 170ce6e153fSAndrzej Hajda 171ce6e153fSAndrzej Hajda static u8 sii8620_readb(struct sii8620 *ctx, u16 addr) 172ce6e153fSAndrzej Hajda { 173ce6e153fSAndrzej Hajda u8 ret; 174ce6e153fSAndrzej Hajda 175ce6e153fSAndrzej Hajda sii8620_read_buf(ctx, addr, &ret, 1); 176ce6e153fSAndrzej Hajda return ret; 177ce6e153fSAndrzej Hajda } 178ce6e153fSAndrzej Hajda 179ce6e153fSAndrzej Hajda static void sii8620_write_buf(struct sii8620 *ctx, u16 addr, const u8 *buf, 180ce6e153fSAndrzej Hajda int len) 181ce6e153fSAndrzej Hajda { 182ce6e153fSAndrzej Hajda struct device *dev = ctx->dev; 183ce6e153fSAndrzej Hajda struct i2c_client *client = to_i2c_client(dev); 184ce6e153fSAndrzej Hajda u8 data[2]; 185ce6e153fSAndrzej Hajda struct i2c_msg msg = { 186ce6e153fSAndrzej Hajda .addr = sii8620_i2c_page[addr >> 8], 187ce6e153fSAndrzej Hajda .flags = client->flags, 188ce6e153fSAndrzej Hajda .len = len + 1, 189ce6e153fSAndrzej Hajda }; 190ce6e153fSAndrzej Hajda int ret; 191ce6e153fSAndrzej Hajda 192ce6e153fSAndrzej Hajda if (ctx->error) 193ce6e153fSAndrzej Hajda return; 194ce6e153fSAndrzej Hajda 195ce6e153fSAndrzej Hajda if (len > 1) { 196ce6e153fSAndrzej Hajda msg.buf = kmalloc(len + 1, GFP_KERNEL); 197ce6e153fSAndrzej Hajda if (!msg.buf) { 198ce6e153fSAndrzej Hajda ctx->error = -ENOMEM; 199ce6e153fSAndrzej Hajda return; 200ce6e153fSAndrzej Hajda } 201ce6e153fSAndrzej Hajda memcpy(msg.buf + 1, buf, len); 202ce6e153fSAndrzej Hajda } else { 203ce6e153fSAndrzej Hajda msg.buf = data; 204ce6e153fSAndrzej Hajda msg.buf[1] = *buf; 205ce6e153fSAndrzej Hajda } 206ce6e153fSAndrzej Hajda 207ce6e153fSAndrzej Hajda msg.buf[0] = addr; 208ce6e153fSAndrzej Hajda 209ce6e153fSAndrzej Hajda ret = i2c_transfer(client->adapter, &msg, 1); 210ce6e153fSAndrzej Hajda dev_dbg(dev, "write at %04x: %*ph, %d\n", addr, len, buf, ret); 211ce6e153fSAndrzej Hajda 212ce6e153fSAndrzej Hajda if (ret != 1) { 213ce6e153fSAndrzej Hajda dev_err(dev, "Write at %#06x of %*ph failed with code %d.\n", 214ce6e153fSAndrzej Hajda addr, len, buf, ret); 215ce6e153fSAndrzej Hajda ctx->error = ret ?: -EIO; 216ce6e153fSAndrzej Hajda } 217ce6e153fSAndrzej Hajda 218ce6e153fSAndrzej Hajda if (len > 1) 219ce6e153fSAndrzej Hajda kfree(msg.buf); 220ce6e153fSAndrzej Hajda } 221ce6e153fSAndrzej Hajda 222ce6e153fSAndrzej Hajda #define sii8620_write(ctx, addr, arr...) \ 223ce6e153fSAndrzej Hajda ({\ 224ce6e153fSAndrzej Hajda u8 d[] = { arr }; \ 225ce6e153fSAndrzej Hajda sii8620_write_buf(ctx, addr, d, ARRAY_SIZE(d)); \ 226ce6e153fSAndrzej Hajda }) 227ce6e153fSAndrzej Hajda 228ce6e153fSAndrzej Hajda static void __sii8620_write_seq(struct sii8620 *ctx, const u16 *seq, int len) 229ce6e153fSAndrzej Hajda { 230ce6e153fSAndrzej Hajda int i; 231ce6e153fSAndrzej Hajda 232ce6e153fSAndrzej Hajda for (i = 0; i < len; i += 2) 233ce6e153fSAndrzej Hajda sii8620_write(ctx, seq[i], seq[i + 1]); 234ce6e153fSAndrzej Hajda } 235ce6e153fSAndrzej Hajda 236ce6e153fSAndrzej Hajda #define sii8620_write_seq(ctx, seq...) \ 237ce6e153fSAndrzej Hajda ({\ 238ce6e153fSAndrzej Hajda const u16 d[] = { seq }; \ 239ce6e153fSAndrzej Hajda __sii8620_write_seq(ctx, d, ARRAY_SIZE(d)); \ 240ce6e153fSAndrzej Hajda }) 241ce6e153fSAndrzej Hajda 242ce6e153fSAndrzej Hajda #define sii8620_write_seq_static(ctx, seq...) \ 243ce6e153fSAndrzej Hajda ({\ 244ce6e153fSAndrzej Hajda static const u16 d[] = { seq }; \ 245ce6e153fSAndrzej Hajda __sii8620_write_seq(ctx, d, ARRAY_SIZE(d)); \ 246ce6e153fSAndrzej Hajda }) 247ce6e153fSAndrzej Hajda 248ce6e153fSAndrzej Hajda static void sii8620_setbits(struct sii8620 *ctx, u16 addr, u8 mask, u8 val) 249ce6e153fSAndrzej Hajda { 250ce6e153fSAndrzej Hajda val = (val & mask) | (sii8620_readb(ctx, addr) & ~mask); 251ce6e153fSAndrzej Hajda sii8620_write(ctx, addr, val); 252ce6e153fSAndrzej Hajda } 253ce6e153fSAndrzej Hajda 254bb4954c7SAndrzej Hajda static inline bool sii8620_is_mhl3(struct sii8620 *ctx) 255bb4954c7SAndrzej Hajda { 256bb4954c7SAndrzej Hajda return ctx->mode >= CM_MHL3; 257bb4954c7SAndrzej Hajda } 258bb4954c7SAndrzej Hajda 259ce6e153fSAndrzej Hajda static void sii8620_mt_cleanup(struct sii8620 *ctx) 260ce6e153fSAndrzej Hajda { 261ce6e153fSAndrzej Hajda struct sii8620_mt_msg *msg, *n; 262ce6e153fSAndrzej Hajda 263ce6e153fSAndrzej Hajda list_for_each_entry_safe(msg, n, &ctx->mt_queue, node) { 264ce6e153fSAndrzej Hajda list_del(&msg->node); 265ce6e153fSAndrzej Hajda kfree(msg); 266ce6e153fSAndrzej Hajda } 267ce6e153fSAndrzej Hajda ctx->mt_state = MT_STATE_READY; 268ce6e153fSAndrzej Hajda } 269ce6e153fSAndrzej Hajda 270ce6e153fSAndrzej Hajda static void sii8620_mt_work(struct sii8620 *ctx) 271ce6e153fSAndrzej Hajda { 272ce6e153fSAndrzej Hajda struct sii8620_mt_msg *msg; 273ce6e153fSAndrzej Hajda 274ce6e153fSAndrzej Hajda if (ctx->error) 275ce6e153fSAndrzej Hajda return; 276ce6e153fSAndrzej Hajda if (ctx->mt_state == MT_STATE_BUSY || list_empty(&ctx->mt_queue)) 277ce6e153fSAndrzej Hajda return; 278ce6e153fSAndrzej Hajda 279ce6e153fSAndrzej Hajda if (ctx->mt_state == MT_STATE_DONE) { 280ce6e153fSAndrzej Hajda ctx->mt_state = MT_STATE_READY; 281ce6e153fSAndrzej Hajda msg = list_first_entry(&ctx->mt_queue, struct sii8620_mt_msg, 282ce6e153fSAndrzej Hajda node); 283d6d59c5aSAndrzej Hajda list_del(&msg->node); 284ce6e153fSAndrzej Hajda if (msg->recv) 285ce6e153fSAndrzej Hajda msg->recv(ctx, msg); 2860c2d1875SAndrzej Hajda if (msg->continuation) 2870c2d1875SAndrzej Hajda msg->continuation(ctx, msg->ret); 288ce6e153fSAndrzej Hajda kfree(msg); 289ce6e153fSAndrzej Hajda } 290ce6e153fSAndrzej Hajda 291ce6e153fSAndrzej Hajda if (ctx->mt_state != MT_STATE_READY || list_empty(&ctx->mt_queue)) 292ce6e153fSAndrzej Hajda return; 293ce6e153fSAndrzej Hajda 294ce6e153fSAndrzej Hajda ctx->mt_state = MT_STATE_BUSY; 295ce6e153fSAndrzej Hajda msg = list_first_entry(&ctx->mt_queue, struct sii8620_mt_msg, node); 296ce6e153fSAndrzej Hajda if (msg->send) 297ce6e153fSAndrzej Hajda msg->send(ctx, msg); 298ce6e153fSAndrzej Hajda } 299ce6e153fSAndrzej Hajda 30026a4cef8SAndrzej Hajda static void sii8620_enable_gen2_write_burst(struct sii8620 *ctx) 30126a4cef8SAndrzej Hajda { 30226a4cef8SAndrzej Hajda u8 ctrl = BIT_MDT_RCV_CTRL_MDT_RCV_EN; 30326a4cef8SAndrzej Hajda 30426a4cef8SAndrzej Hajda if (ctx->gen2_write_burst) 30526a4cef8SAndrzej Hajda return; 30626a4cef8SAndrzej Hajda 30726a4cef8SAndrzej Hajda if (ctx->mode >= CM_MHL1) 30826a4cef8SAndrzej Hajda ctrl |= BIT_MDT_RCV_CTRL_MDT_DELAY_RCV_EN; 30926a4cef8SAndrzej Hajda 31026a4cef8SAndrzej Hajda sii8620_write_seq(ctx, 31126a4cef8SAndrzej Hajda REG_MDT_RCV_TIMEOUT, 100, 31226a4cef8SAndrzej Hajda REG_MDT_RCV_CTRL, ctrl 31326a4cef8SAndrzej Hajda ); 31426a4cef8SAndrzej Hajda ctx->gen2_write_burst = 1; 31526a4cef8SAndrzej Hajda } 31626a4cef8SAndrzej Hajda 31726a4cef8SAndrzej Hajda static void sii8620_disable_gen2_write_burst(struct sii8620 *ctx) 31826a4cef8SAndrzej Hajda { 31926a4cef8SAndrzej Hajda if (!ctx->gen2_write_burst) 32026a4cef8SAndrzej Hajda return; 32126a4cef8SAndrzej Hajda 32226a4cef8SAndrzej Hajda sii8620_write_seq_static(ctx, 32326a4cef8SAndrzej Hajda REG_MDT_XMIT_CTRL, 0, 32426a4cef8SAndrzej Hajda REG_MDT_RCV_CTRL, 0 32526a4cef8SAndrzej Hajda ); 32626a4cef8SAndrzej Hajda ctx->gen2_write_burst = 0; 32726a4cef8SAndrzej Hajda } 32826a4cef8SAndrzej Hajda 32926a4cef8SAndrzej Hajda static void sii8620_start_gen2_write_burst(struct sii8620 *ctx) 33026a4cef8SAndrzej Hajda { 33126a4cef8SAndrzej Hajda sii8620_write_seq_static(ctx, 33226a4cef8SAndrzej Hajda REG_MDT_INT_1_MASK, BIT_MDT_RCV_TIMEOUT 33326a4cef8SAndrzej Hajda | BIT_MDT_RCV_SM_ABORT_PKT_RCVD | BIT_MDT_RCV_SM_ERROR 33426a4cef8SAndrzej Hajda | BIT_MDT_XMIT_TIMEOUT | BIT_MDT_XMIT_SM_ABORT_PKT_RCVD 33526a4cef8SAndrzej Hajda | BIT_MDT_XMIT_SM_ERROR, 33626a4cef8SAndrzej Hajda REG_MDT_INT_0_MASK, BIT_MDT_XFIFO_EMPTY 33726a4cef8SAndrzej Hajda | BIT_MDT_IDLE_AFTER_HAWB_DISABLE 33826a4cef8SAndrzej Hajda | BIT_MDT_RFIFO_DATA_RDY 33926a4cef8SAndrzej Hajda ); 34026a4cef8SAndrzej Hajda sii8620_enable_gen2_write_burst(ctx); 34126a4cef8SAndrzej Hajda } 34226a4cef8SAndrzej Hajda 343ce6e153fSAndrzej Hajda static void sii8620_mt_msc_cmd_send(struct sii8620 *ctx, 344ce6e153fSAndrzej Hajda struct sii8620_mt_msg *msg) 345ce6e153fSAndrzej Hajda { 34626a4cef8SAndrzej Hajda if (msg->reg[0] == MHL_SET_INT && 34726a4cef8SAndrzej Hajda msg->reg[1] == MHL_INT_REG(RCHANGE) && 34826a4cef8SAndrzej Hajda msg->reg[2] == MHL_INT_RC_FEAT_REQ) 34926a4cef8SAndrzej Hajda sii8620_enable_gen2_write_burst(ctx); 35026a4cef8SAndrzej Hajda else 35126a4cef8SAndrzej Hajda sii8620_disable_gen2_write_burst(ctx); 35226a4cef8SAndrzej Hajda 353ce6e153fSAndrzej Hajda switch (msg->reg[0]) { 354ce6e153fSAndrzej Hajda case MHL_WRITE_STAT: 355ce6e153fSAndrzej Hajda case MHL_SET_INT: 356ce6e153fSAndrzej Hajda sii8620_write_buf(ctx, REG_MSC_CMD_OR_OFFSET, msg->reg + 1, 2); 357ce6e153fSAndrzej Hajda sii8620_write(ctx, REG_MSC_COMMAND_START, 358ce6e153fSAndrzej Hajda BIT_MSC_COMMAND_START_WRITE_STAT); 359ce6e153fSAndrzej Hajda break; 360ce6e153fSAndrzej Hajda case MHL_MSC_MSG: 361ce6e153fSAndrzej Hajda sii8620_write_buf(ctx, REG_MSC_CMD_OR_OFFSET, msg->reg, 3); 362ce6e153fSAndrzej Hajda sii8620_write(ctx, REG_MSC_COMMAND_START, 363ce6e153fSAndrzej Hajda BIT_MSC_COMMAND_START_MSC_MSG); 364ce6e153fSAndrzej Hajda break; 365e9c6da27SAndrzej Hajda case MHL_READ_DEVCAP_REG: 366e9c6da27SAndrzej Hajda case MHL_READ_XDEVCAP_REG: 367e9c6da27SAndrzej Hajda sii8620_write(ctx, REG_MSC_CMD_OR_OFFSET, msg->reg[1]); 368e9c6da27SAndrzej Hajda sii8620_write(ctx, REG_MSC_COMMAND_START, 369e9c6da27SAndrzej Hajda BIT_MSC_COMMAND_START_READ_DEVCAP); 370e9c6da27SAndrzej Hajda break; 371ce6e153fSAndrzej Hajda default: 372ce6e153fSAndrzej Hajda dev_err(ctx->dev, "%s: command %#x not supported\n", __func__, 373ce6e153fSAndrzej Hajda msg->reg[0]); 374ce6e153fSAndrzej Hajda } 375ce6e153fSAndrzej Hajda } 376ce6e153fSAndrzej Hajda 377ce6e153fSAndrzej Hajda static struct sii8620_mt_msg *sii8620_mt_msg_new(struct sii8620 *ctx) 378ce6e153fSAndrzej Hajda { 379ce6e153fSAndrzej Hajda struct sii8620_mt_msg *msg = kzalloc(sizeof(*msg), GFP_KERNEL); 380ce6e153fSAndrzej Hajda 381ce6e153fSAndrzej Hajda if (!msg) 382ce6e153fSAndrzej Hajda ctx->error = -ENOMEM; 383ce6e153fSAndrzej Hajda else 384ce6e153fSAndrzej Hajda list_add_tail(&msg->node, &ctx->mt_queue); 385ce6e153fSAndrzej Hajda 386ce6e153fSAndrzej Hajda return msg; 387ce6e153fSAndrzej Hajda } 388ce6e153fSAndrzej Hajda 3890c2d1875SAndrzej Hajda static void sii8620_mt_set_cont(struct sii8620 *ctx, sii8620_cb cont) 3900c2d1875SAndrzej Hajda { 3910c2d1875SAndrzej Hajda struct sii8620_mt_msg *msg; 3920c2d1875SAndrzej Hajda 3930c2d1875SAndrzej Hajda if (ctx->error) 3940c2d1875SAndrzej Hajda return; 3950c2d1875SAndrzej Hajda 3960c2d1875SAndrzej Hajda if (list_empty(&ctx->mt_queue)) { 3970c2d1875SAndrzej Hajda ctx->error = -EINVAL; 3980c2d1875SAndrzej Hajda return; 3990c2d1875SAndrzej Hajda } 4000c2d1875SAndrzej Hajda msg = list_last_entry(&ctx->mt_queue, struct sii8620_mt_msg, node); 4010c2d1875SAndrzej Hajda msg->continuation = cont; 4020c2d1875SAndrzej Hajda } 4030c2d1875SAndrzej Hajda 404ce6e153fSAndrzej Hajda static void sii8620_mt_msc_cmd(struct sii8620 *ctx, u8 cmd, u8 arg1, u8 arg2) 405ce6e153fSAndrzej Hajda { 406ce6e153fSAndrzej Hajda struct sii8620_mt_msg *msg = sii8620_mt_msg_new(ctx); 407ce6e153fSAndrzej Hajda 408ce6e153fSAndrzej Hajda if (!msg) 409ce6e153fSAndrzej Hajda return; 410ce6e153fSAndrzej Hajda 411ce6e153fSAndrzej Hajda msg->reg[0] = cmd; 412ce6e153fSAndrzej Hajda msg->reg[1] = arg1; 413ce6e153fSAndrzej Hajda msg->reg[2] = arg2; 414ce6e153fSAndrzej Hajda msg->send = sii8620_mt_msc_cmd_send; 415ce6e153fSAndrzej Hajda } 416ce6e153fSAndrzej Hajda 417ce6e153fSAndrzej Hajda static void sii8620_mt_write_stat(struct sii8620 *ctx, u8 reg, u8 val) 418ce6e153fSAndrzej Hajda { 419ce6e153fSAndrzej Hajda sii8620_mt_msc_cmd(ctx, MHL_WRITE_STAT, reg, val); 420ce6e153fSAndrzej Hajda } 421ce6e153fSAndrzej Hajda 422ce6e153fSAndrzej Hajda static inline void sii8620_mt_set_int(struct sii8620 *ctx, u8 irq, u8 mask) 423ce6e153fSAndrzej Hajda { 424ce6e153fSAndrzej Hajda sii8620_mt_msc_cmd(ctx, MHL_SET_INT, irq, mask); 425ce6e153fSAndrzej Hajda } 426ce6e153fSAndrzej Hajda 427ce6e153fSAndrzej Hajda static void sii8620_mt_msc_msg(struct sii8620 *ctx, u8 cmd, u8 data) 428ce6e153fSAndrzej Hajda { 429ce6e153fSAndrzej Hajda sii8620_mt_msc_cmd(ctx, MHL_MSC_MSG, cmd, data); 430ce6e153fSAndrzej Hajda } 431ce6e153fSAndrzej Hajda 432ce6e153fSAndrzej Hajda static void sii8620_mt_rap(struct sii8620 *ctx, u8 code) 433ce6e153fSAndrzej Hajda { 434ce6e153fSAndrzej Hajda sii8620_mt_msc_msg(ctx, MHL_MSC_MSG_RAP, code); 435ce6e153fSAndrzej Hajda } 436ce6e153fSAndrzej Hajda 437e25f1f7cSMaciej Purski static void sii8620_mt_rcpk(struct sii8620 *ctx, u8 code) 438e25f1f7cSMaciej Purski { 439e25f1f7cSMaciej Purski sii8620_mt_msc_msg(ctx, MHL_MSC_MSG_RCPK, code); 440e25f1f7cSMaciej Purski } 441e25f1f7cSMaciej Purski 442e25f1f7cSMaciej Purski static void sii8620_mt_rcpe(struct sii8620 *ctx, u8 code) 443e25f1f7cSMaciej Purski { 444e25f1f7cSMaciej Purski sii8620_mt_msc_msg(ctx, MHL_MSC_MSG_RCPE, code); 445e25f1f7cSMaciej Purski } 446e25f1f7cSMaciej Purski 447ce6e153fSAndrzej Hajda static void sii8620_mt_read_devcap_send(struct sii8620 *ctx, 448ce6e153fSAndrzej Hajda struct sii8620_mt_msg *msg) 449ce6e153fSAndrzej Hajda { 450ce6e153fSAndrzej Hajda u8 ctrl = BIT_EDID_CTRL_DEVCAP_SELECT_DEVCAP 451ce6e153fSAndrzej Hajda | BIT_EDID_CTRL_EDID_FIFO_ADDR_AUTO 452ce6e153fSAndrzej Hajda | BIT_EDID_CTRL_EDID_MODE_EN; 453ce6e153fSAndrzej Hajda 454ce6e153fSAndrzej Hajda if (msg->reg[0] == MHL_READ_XDEVCAP) 455ce6e153fSAndrzej Hajda ctrl |= BIT_EDID_CTRL_XDEVCAP_EN; 456ce6e153fSAndrzej Hajda 457ce6e153fSAndrzej Hajda sii8620_write_seq(ctx, 458ce6e153fSAndrzej Hajda REG_INTR9_MASK, BIT_INTR9_DEVCAP_DONE, 459ce6e153fSAndrzej Hajda REG_EDID_CTRL, ctrl, 460ce6e153fSAndrzej Hajda REG_TPI_CBUS_START, BIT_TPI_CBUS_START_GET_DEVCAP_START 461ce6e153fSAndrzej Hajda ); 462ce6e153fSAndrzej Hajda } 463ce6e153fSAndrzej Hajda 464ce6e153fSAndrzej Hajda /* copy src to dst and set changed bits in src */ 465ce6e153fSAndrzej Hajda static void sii8620_update_array(u8 *dst, u8 *src, int count) 466ce6e153fSAndrzej Hajda { 467ce6e153fSAndrzej Hajda while (--count >= 0) { 468ce6e153fSAndrzej Hajda *src ^= *dst; 469ce6e153fSAndrzej Hajda *dst++ ^= *src++; 470ce6e153fSAndrzej Hajda } 471ce6e153fSAndrzej Hajda } 472ce6e153fSAndrzej Hajda 4739a466cd1SAndrzej Hajda static void sii8620_sink_detected(struct sii8620 *ctx, int ret) 474ce6e153fSAndrzej Hajda { 475ce6e153fSAndrzej Hajda static const char * const sink_str[] = { 476ce6e153fSAndrzej Hajda [SINK_NONE] = "NONE", 477ce6e153fSAndrzej Hajda [SINK_HDMI] = "HDMI", 478ce6e153fSAndrzej Hajda [SINK_DVI] = "DVI" 479ce6e153fSAndrzej Hajda }; 480ce6e153fSAndrzej Hajda 481ce6e153fSAndrzej Hajda char sink_name[20]; 482ce6e153fSAndrzej Hajda struct device *dev = ctx->dev; 483ce6e153fSAndrzej Hajda 4849a466cd1SAndrzej Hajda if (ret < 0) 485ce6e153fSAndrzej Hajda return; 486ce6e153fSAndrzej Hajda 487ce6e153fSAndrzej Hajda sii8620_fetch_edid(ctx); 488ce6e153fSAndrzej Hajda if (!ctx->edid) { 489ce6e153fSAndrzej Hajda dev_err(ctx->dev, "Cannot fetch EDID\n"); 490ce6e153fSAndrzej Hajda sii8620_mhl_disconnected(ctx); 491ce6e153fSAndrzej Hajda return; 492ce6e153fSAndrzej Hajda } 493ce6e153fSAndrzej Hajda 494ce6e153fSAndrzej Hajda if (drm_detect_hdmi_monitor(ctx->edid)) 495ce6e153fSAndrzej Hajda ctx->sink_type = SINK_HDMI; 496ce6e153fSAndrzej Hajda else 497ce6e153fSAndrzej Hajda ctx->sink_type = SINK_DVI; 498ce6e153fSAndrzej Hajda 499ce6e153fSAndrzej Hajda drm_edid_get_monitor_name(ctx->edid, sink_name, ARRAY_SIZE(sink_name)); 500ce6e153fSAndrzej Hajda 501ce6e153fSAndrzej Hajda dev_info(dev, "detected sink(type: %s): %s\n", 502ce6e153fSAndrzej Hajda sink_str[ctx->sink_type], sink_name); 503263b5c93SAndrzej Hajda } 504263b5c93SAndrzej Hajda 505a21e658bSAndrzej Hajda static void sii8620_hsic_init(struct sii8620 *ctx) 506a21e658bSAndrzej Hajda { 507a21e658bSAndrzej Hajda if (!sii8620_is_mhl3(ctx)) 508a21e658bSAndrzej Hajda return; 509a21e658bSAndrzej Hajda 510a21e658bSAndrzej Hajda sii8620_write(ctx, REG_FCGC, 511a21e658bSAndrzej Hajda BIT_FCGC_HSIC_HOSTMODE | BIT_FCGC_HSIC_ENABLE); 512a21e658bSAndrzej Hajda sii8620_setbits(ctx, REG_HRXCTRL3, 513a21e658bSAndrzej Hajda BIT_HRXCTRL3_HRX_STAY_RESET | BIT_HRXCTRL3_STATUS_EN, ~0); 514a21e658bSAndrzej Hajda sii8620_setbits(ctx, REG_TTXNUMB, MSK_TTXNUMB_TTX_NUMBPS, 4); 515a21e658bSAndrzej Hajda sii8620_setbits(ctx, REG_TRXCTRL, BIT_TRXCTRL_TRX_FROM_SE_COC, ~0); 516a21e658bSAndrzej Hajda sii8620_setbits(ctx, REG_HTXCTRL, BIT_HTXCTRL_HTX_DRVCONN1, 0); 517a21e658bSAndrzej Hajda sii8620_setbits(ctx, REG_KEEPER, MSK_KEEPER_MODE, VAL_KEEPER_MODE_HOST); 518a21e658bSAndrzej Hajda sii8620_write_seq_static(ctx, 519a21e658bSAndrzej Hajda REG_TDMLLCTL, 0, 520a21e658bSAndrzej Hajda REG_UTSRST, BIT_UTSRST_HRX_SRST | BIT_UTSRST_HTX_SRST | 521a21e658bSAndrzej Hajda BIT_UTSRST_KEEPER_SRST | BIT_UTSRST_FC_SRST, 522a21e658bSAndrzej Hajda REG_UTSRST, BIT_UTSRST_HRX_SRST | BIT_UTSRST_HTX_SRST, 523a21e658bSAndrzej Hajda REG_HRXINTL, 0xff, 524a21e658bSAndrzej Hajda REG_HRXINTH, 0xff, 525a21e658bSAndrzej Hajda REG_TTXINTL, 0xff, 526a21e658bSAndrzej Hajda REG_TTXINTH, 0xff, 527a21e658bSAndrzej Hajda REG_TRXINTL, 0xff, 528a21e658bSAndrzej Hajda REG_TRXINTH, 0xff, 529a21e658bSAndrzej Hajda REG_HTXINTL, 0xff, 530a21e658bSAndrzej Hajda REG_HTXINTH, 0xff, 531a21e658bSAndrzej Hajda REG_FCINTR0, 0xff, 532a21e658bSAndrzej Hajda REG_FCINTR1, 0xff, 533a21e658bSAndrzej Hajda REG_FCINTR2, 0xff, 534a21e658bSAndrzej Hajda REG_FCINTR3, 0xff, 535a21e658bSAndrzej Hajda REG_FCINTR4, 0xff, 536a21e658bSAndrzej Hajda REG_FCINTR5, 0xff, 537a21e658bSAndrzej Hajda REG_FCINTR6, 0xff, 538a21e658bSAndrzej Hajda REG_FCINTR7, 0xff 539a21e658bSAndrzej Hajda ); 540a21e658bSAndrzej Hajda } 541a21e658bSAndrzej Hajda 542263b5c93SAndrzej Hajda static void sii8620_edid_read(struct sii8620 *ctx, int ret) 543263b5c93SAndrzej Hajda { 544263b5c93SAndrzej Hajda if (ret < 0) 545263b5c93SAndrzej Hajda return; 546263b5c93SAndrzej Hajda 547ce6e153fSAndrzej Hajda sii8620_set_upstream_edid(ctx); 548a21e658bSAndrzej Hajda sii8620_hsic_init(ctx); 549ce6e153fSAndrzej Hajda sii8620_enable_hpd(ctx); 550ce6e153fSAndrzej Hajda } 551ce6e153fSAndrzej Hajda 5529a466cd1SAndrzej Hajda static void sii8620_mr_devcap(struct sii8620 *ctx) 5539a466cd1SAndrzej Hajda { 5549a466cd1SAndrzej Hajda u8 dcap[MHL_DCAP_SIZE]; 5559a466cd1SAndrzej Hajda struct device *dev = ctx->dev; 5569a466cd1SAndrzej Hajda 5579a466cd1SAndrzej Hajda sii8620_read_buf(ctx, REG_EDID_FIFO_RD_DATA, dcap, MHL_DCAP_SIZE); 5589a466cd1SAndrzej Hajda if (ctx->error < 0) 5599a466cd1SAndrzej Hajda return; 5609a466cd1SAndrzej Hajda 5619a466cd1SAndrzej Hajda dev_info(dev, "detected dongle MHL %d.%d, ChipID %02x%02x:%02x%02x\n", 5629a466cd1SAndrzej Hajda dcap[MHL_DCAP_MHL_VERSION] / 16, 5639a466cd1SAndrzej Hajda dcap[MHL_DCAP_MHL_VERSION] % 16, 5649a466cd1SAndrzej Hajda dcap[MHL_DCAP_ADOPTER_ID_H], dcap[MHL_DCAP_ADOPTER_ID_L], 5659a466cd1SAndrzej Hajda dcap[MHL_DCAP_DEVICE_ID_H], dcap[MHL_DCAP_DEVICE_ID_L]); 5669a466cd1SAndrzej Hajda sii8620_update_array(ctx->devcap, dcap, MHL_DCAP_SIZE); 5679a466cd1SAndrzej Hajda } 5689a466cd1SAndrzej Hajda 569ce6e153fSAndrzej Hajda static void sii8620_mr_xdevcap(struct sii8620 *ctx) 570ce6e153fSAndrzej Hajda { 571ce6e153fSAndrzej Hajda sii8620_read_buf(ctx, REG_EDID_FIFO_RD_DATA, ctx->xdevcap, 572ce6e153fSAndrzej Hajda MHL_XDC_SIZE); 573ce6e153fSAndrzej Hajda } 574ce6e153fSAndrzej Hajda 575ce6e153fSAndrzej Hajda static void sii8620_mt_read_devcap_recv(struct sii8620 *ctx, 576ce6e153fSAndrzej Hajda struct sii8620_mt_msg *msg) 577ce6e153fSAndrzej Hajda { 578ce6e153fSAndrzej Hajda u8 ctrl = BIT_EDID_CTRL_DEVCAP_SELECT_DEVCAP 579ce6e153fSAndrzej Hajda | BIT_EDID_CTRL_EDID_FIFO_ADDR_AUTO 580ce6e153fSAndrzej Hajda | BIT_EDID_CTRL_EDID_MODE_EN; 581ce6e153fSAndrzej Hajda 582ce6e153fSAndrzej Hajda if (msg->reg[0] == MHL_READ_XDEVCAP) 583ce6e153fSAndrzej Hajda ctrl |= BIT_EDID_CTRL_XDEVCAP_EN; 584ce6e153fSAndrzej Hajda 585ce6e153fSAndrzej Hajda sii8620_write_seq(ctx, 586ce6e153fSAndrzej Hajda REG_INTR9_MASK, BIT_INTR9_DEVCAP_DONE | BIT_INTR9_EDID_DONE 587ce6e153fSAndrzej Hajda | BIT_INTR9_EDID_ERROR, 588ce6e153fSAndrzej Hajda REG_EDID_CTRL, ctrl, 589ce6e153fSAndrzej Hajda REG_EDID_FIFO_ADDR, 0 590ce6e153fSAndrzej Hajda ); 591ce6e153fSAndrzej Hajda 592ce6e153fSAndrzej Hajda if (msg->reg[0] == MHL_READ_XDEVCAP) 593ce6e153fSAndrzej Hajda sii8620_mr_xdevcap(ctx); 594ce6e153fSAndrzej Hajda else 595ce6e153fSAndrzej Hajda sii8620_mr_devcap(ctx); 596ce6e153fSAndrzej Hajda } 597ce6e153fSAndrzej Hajda 598ce6e153fSAndrzej Hajda static void sii8620_mt_read_devcap(struct sii8620 *ctx, bool xdevcap) 599ce6e153fSAndrzej Hajda { 600ce6e153fSAndrzej Hajda struct sii8620_mt_msg *msg = sii8620_mt_msg_new(ctx); 601ce6e153fSAndrzej Hajda 602ce6e153fSAndrzej Hajda if (!msg) 603ce6e153fSAndrzej Hajda return; 604ce6e153fSAndrzej Hajda 605ce6e153fSAndrzej Hajda msg->reg[0] = xdevcap ? MHL_READ_XDEVCAP : MHL_READ_DEVCAP; 606ce6e153fSAndrzej Hajda msg->send = sii8620_mt_read_devcap_send; 607ce6e153fSAndrzej Hajda msg->recv = sii8620_mt_read_devcap_recv; 608ce6e153fSAndrzej Hajda } 609ce6e153fSAndrzej Hajda 610e9c6da27SAndrzej Hajda static void sii8620_mt_read_devcap_reg_recv(struct sii8620 *ctx, 611e9c6da27SAndrzej Hajda struct sii8620_mt_msg *msg) 612e9c6da27SAndrzej Hajda { 61379964dbaSMaciej Purski u8 reg = msg->reg[1] & 0x7f; 614e9c6da27SAndrzej Hajda 61579964dbaSMaciej Purski if (msg->reg[1] & 0x80) 616e9c6da27SAndrzej Hajda ctx->xdevcap[reg] = msg->ret; 617e9c6da27SAndrzej Hajda else 618e9c6da27SAndrzej Hajda ctx->devcap[reg] = msg->ret; 619e9c6da27SAndrzej Hajda } 620e9c6da27SAndrzej Hajda 621e9c6da27SAndrzej Hajda static void sii8620_mt_read_devcap_reg(struct sii8620 *ctx, u8 reg) 622e9c6da27SAndrzej Hajda { 623e9c6da27SAndrzej Hajda struct sii8620_mt_msg *msg = sii8620_mt_msg_new(ctx); 624e9c6da27SAndrzej Hajda 625e9c6da27SAndrzej Hajda if (!msg) 626e9c6da27SAndrzej Hajda return; 627e9c6da27SAndrzej Hajda 628e9c6da27SAndrzej Hajda msg->reg[0] = (reg & 0x80) ? MHL_READ_XDEVCAP_REG : MHL_READ_DEVCAP_REG; 629e9c6da27SAndrzej Hajda msg->reg[1] = reg; 630e9c6da27SAndrzej Hajda msg->send = sii8620_mt_msc_cmd_send; 631e9c6da27SAndrzej Hajda msg->recv = sii8620_mt_read_devcap_reg_recv; 632e9c6da27SAndrzej Hajda } 633e9c6da27SAndrzej Hajda 634e9c6da27SAndrzej Hajda static inline void sii8620_mt_read_xdevcap_reg(struct sii8620 *ctx, u8 reg) 635e9c6da27SAndrzej Hajda { 636e9c6da27SAndrzej Hajda sii8620_mt_read_devcap_reg(ctx, reg | 0x80); 637e9c6da27SAndrzej Hajda } 638e9c6da27SAndrzej Hajda 639e19e9c69SAndrzej Hajda static void *sii8620_burst_get_tx_buf(struct sii8620 *ctx, int len) 640e19e9c69SAndrzej Hajda { 641e19e9c69SAndrzej Hajda u8 *buf = &ctx->burst.tx_buf[ctx->burst.tx_count]; 642e19e9c69SAndrzej Hajda int size = len + 2; 643e19e9c69SAndrzej Hajda 644e19e9c69SAndrzej Hajda if (ctx->burst.tx_count + size > ARRAY_SIZE(ctx->burst.tx_buf)) { 645e19e9c69SAndrzej Hajda dev_err(ctx->dev, "TX-BLK buffer exhausted\n"); 646e19e9c69SAndrzej Hajda ctx->error = -EINVAL; 647e19e9c69SAndrzej Hajda return NULL; 648e19e9c69SAndrzej Hajda } 649e19e9c69SAndrzej Hajda 650e19e9c69SAndrzej Hajda ctx->burst.tx_count += size; 651e19e9c69SAndrzej Hajda buf[1] = len; 652e19e9c69SAndrzej Hajda 653e19e9c69SAndrzej Hajda return buf + 2; 654e19e9c69SAndrzej Hajda } 655e19e9c69SAndrzej Hajda 656e19e9c69SAndrzej Hajda static u8 *sii8620_burst_get_rx_buf(struct sii8620 *ctx, int len) 657e19e9c69SAndrzej Hajda { 658e19e9c69SAndrzej Hajda u8 *buf = &ctx->burst.rx_buf[ctx->burst.rx_count]; 659e19e9c69SAndrzej Hajda int size = len + 1; 660e19e9c69SAndrzej Hajda 661e19e9c69SAndrzej Hajda if (ctx->burst.tx_count + size > ARRAY_SIZE(ctx->burst.tx_buf)) { 662e19e9c69SAndrzej Hajda dev_err(ctx->dev, "RX-BLK buffer exhausted\n"); 663e19e9c69SAndrzej Hajda ctx->error = -EINVAL; 664e19e9c69SAndrzej Hajda return NULL; 665e19e9c69SAndrzej Hajda } 666e19e9c69SAndrzej Hajda 667e19e9c69SAndrzej Hajda ctx->burst.rx_count += size; 668e19e9c69SAndrzej Hajda buf[0] = len; 669e19e9c69SAndrzej Hajda 670e19e9c69SAndrzej Hajda return buf + 1; 671e19e9c69SAndrzej Hajda } 672e19e9c69SAndrzej Hajda 673e19e9c69SAndrzej Hajda static void sii8620_burst_send(struct sii8620 *ctx) 674e19e9c69SAndrzej Hajda { 675e19e9c69SAndrzej Hajda int tx_left = ctx->burst.tx_count; 676e19e9c69SAndrzej Hajda u8 *d = ctx->burst.tx_buf; 677e19e9c69SAndrzej Hajda 678e19e9c69SAndrzej Hajda while (tx_left > 0) { 679e19e9c69SAndrzej Hajda int len = d[1] + 2; 680e19e9c69SAndrzej Hajda 681e19e9c69SAndrzej Hajda if (ctx->burst.r_count + len > ctx->burst.r_size) 682e19e9c69SAndrzej Hajda break; 683e19e9c69SAndrzej Hajda d[0] = min(ctx->burst.rx_ack, 255); 684e19e9c69SAndrzej Hajda ctx->burst.rx_ack -= d[0]; 685e19e9c69SAndrzej Hajda sii8620_write_buf(ctx, REG_EMSC_XMIT_WRITE_PORT, d, len); 686e19e9c69SAndrzej Hajda ctx->burst.r_count += len; 687e19e9c69SAndrzej Hajda tx_left -= len; 688e19e9c69SAndrzej Hajda d += len; 689e19e9c69SAndrzej Hajda } 690e19e9c69SAndrzej Hajda 691e19e9c69SAndrzej Hajda ctx->burst.tx_count = tx_left; 692e19e9c69SAndrzej Hajda 693e19e9c69SAndrzej Hajda while (ctx->burst.rx_ack > 0) { 694e19e9c69SAndrzej Hajda u8 b[2] = { min(ctx->burst.rx_ack, 255), 0 }; 695e19e9c69SAndrzej Hajda 696e19e9c69SAndrzej Hajda if (ctx->burst.r_count + 2 > ctx->burst.r_size) 697e19e9c69SAndrzej Hajda break; 698e19e9c69SAndrzej Hajda ctx->burst.rx_ack -= b[0]; 699e19e9c69SAndrzej Hajda sii8620_write_buf(ctx, REG_EMSC_XMIT_WRITE_PORT, b, 2); 700e19e9c69SAndrzej Hajda ctx->burst.r_count += 2; 701e19e9c69SAndrzej Hajda } 702e19e9c69SAndrzej Hajda } 703e19e9c69SAndrzej Hajda 704e19e9c69SAndrzej Hajda static void sii8620_burst_receive(struct sii8620 *ctx) 705e19e9c69SAndrzej Hajda { 706e19e9c69SAndrzej Hajda u8 buf[3], *d; 707e19e9c69SAndrzej Hajda int count; 708e19e9c69SAndrzej Hajda 709e19e9c69SAndrzej Hajda sii8620_read_buf(ctx, REG_EMSCRFIFOBCNTL, buf, 2); 710e19e9c69SAndrzej Hajda count = get_unaligned_le16(buf); 711e19e9c69SAndrzej Hajda while (count > 0) { 712e19e9c69SAndrzej Hajda int len = min(count, 3); 713e19e9c69SAndrzej Hajda 714e19e9c69SAndrzej Hajda sii8620_read_buf(ctx, REG_EMSC_RCV_READ_PORT, buf, len); 715e19e9c69SAndrzej Hajda count -= len; 716e19e9c69SAndrzej Hajda ctx->burst.rx_ack += len - 1; 717e19e9c69SAndrzej Hajda ctx->burst.r_count -= buf[1]; 718e19e9c69SAndrzej Hajda if (ctx->burst.r_count < 0) 719e19e9c69SAndrzej Hajda ctx->burst.r_count = 0; 720e19e9c69SAndrzej Hajda 721e19e9c69SAndrzej Hajda if (len < 3 || !buf[2]) 722e19e9c69SAndrzej Hajda continue; 723e19e9c69SAndrzej Hajda 724e19e9c69SAndrzej Hajda len = buf[2]; 725e19e9c69SAndrzej Hajda d = sii8620_burst_get_rx_buf(ctx, len); 726e19e9c69SAndrzej Hajda if (!d) 727e19e9c69SAndrzej Hajda continue; 728e19e9c69SAndrzej Hajda sii8620_read_buf(ctx, REG_EMSC_RCV_READ_PORT, d, len); 729e19e9c69SAndrzej Hajda count -= len; 730e19e9c69SAndrzej Hajda ctx->burst.rx_ack += len; 731e19e9c69SAndrzej Hajda } 732e19e9c69SAndrzej Hajda } 733e19e9c69SAndrzej Hajda 734e19e9c69SAndrzej Hajda static void sii8620_burst_tx_rbuf_info(struct sii8620 *ctx, int size) 735e19e9c69SAndrzej Hajda { 736e19e9c69SAndrzej Hajda struct mhl_burst_blk_rcv_buffer_info *d = 737e19e9c69SAndrzej Hajda sii8620_burst_get_tx_buf(ctx, sizeof(*d)); 738e19e9c69SAndrzej Hajda if (!d) 739e19e9c69SAndrzej Hajda return; 740e19e9c69SAndrzej Hajda 741e19e9c69SAndrzej Hajda d->id = cpu_to_be16(MHL_BURST_ID_BLK_RCV_BUFFER_INFO); 742e19e9c69SAndrzej Hajda d->size = cpu_to_le16(size); 743e19e9c69SAndrzej Hajda } 744e19e9c69SAndrzej Hajda 745bf1722caSAndrzej Hajda static u8 sii8620_checksum(void *ptr, int size) 746bf1722caSAndrzej Hajda { 747bf1722caSAndrzej Hajda u8 *d = ptr, sum = 0; 748bf1722caSAndrzej Hajda 749bf1722caSAndrzej Hajda while (size--) 750bf1722caSAndrzej Hajda sum += *d++; 751bf1722caSAndrzej Hajda 752bf1722caSAndrzej Hajda return sum; 753bf1722caSAndrzej Hajda } 754bf1722caSAndrzej Hajda 755bf1722caSAndrzej Hajda static void sii8620_mhl_burst_hdr_set(struct mhl3_burst_header *h, 756bf1722caSAndrzej Hajda enum mhl_burst_id id) 757bf1722caSAndrzej Hajda { 758bf1722caSAndrzej Hajda h->id = cpu_to_be16(id); 759bf1722caSAndrzej Hajda h->total_entries = 1; 760bf1722caSAndrzej Hajda h->sequence_index = 1; 761bf1722caSAndrzej Hajda } 762bf1722caSAndrzej Hajda 763bf1722caSAndrzej Hajda static void sii8620_burst_tx_bits_per_pixel_fmt(struct sii8620 *ctx, u8 fmt) 764bf1722caSAndrzej Hajda { 765bf1722caSAndrzej Hajda struct mhl_burst_bits_per_pixel_fmt *d; 766bf1722caSAndrzej Hajda const int size = sizeof(*d) + sizeof(d->desc[0]); 767bf1722caSAndrzej Hajda 768bf1722caSAndrzej Hajda d = sii8620_burst_get_tx_buf(ctx, size); 769bf1722caSAndrzej Hajda if (!d) 770bf1722caSAndrzej Hajda return; 771bf1722caSAndrzej Hajda 772bf1722caSAndrzej Hajda sii8620_mhl_burst_hdr_set(&d->hdr, MHL_BURST_ID_BITS_PER_PIXEL_FMT); 773bf1722caSAndrzej Hajda d->num_entries = 1; 774bf1722caSAndrzej Hajda d->desc[0].stream_id = 0; 775bf1722caSAndrzej Hajda d->desc[0].pixel_format = fmt; 776bf1722caSAndrzej Hajda d->hdr.checksum -= sii8620_checksum(d, size); 777bf1722caSAndrzej Hajda } 778bf1722caSAndrzej Hajda 779e19e9c69SAndrzej Hajda static void sii8620_burst_rx_all(struct sii8620 *ctx) 780e19e9c69SAndrzej Hajda { 781e19e9c69SAndrzej Hajda u8 *d = ctx->burst.rx_buf; 782e19e9c69SAndrzej Hajda int count = ctx->burst.rx_count; 783e19e9c69SAndrzej Hajda 784e19e9c69SAndrzej Hajda while (count-- > 0) { 785e19e9c69SAndrzej Hajda int len = *d++; 786e19e9c69SAndrzej Hajda int id = get_unaligned_be16(&d[0]); 787e19e9c69SAndrzej Hajda 788e19e9c69SAndrzej Hajda switch (id) { 789e19e9c69SAndrzej Hajda case MHL_BURST_ID_BLK_RCV_BUFFER_INFO: 790e19e9c69SAndrzej Hajda ctx->burst.r_size = get_unaligned_le16(&d[2]); 791e19e9c69SAndrzej Hajda break; 792e19e9c69SAndrzej Hajda default: 793e19e9c69SAndrzej Hajda break; 794e19e9c69SAndrzej Hajda } 795e19e9c69SAndrzej Hajda count -= len; 796e19e9c69SAndrzej Hajda d += len; 797e19e9c69SAndrzej Hajda } 798e19e9c69SAndrzej Hajda ctx->burst.rx_count = 0; 799e19e9c69SAndrzej Hajda } 800e19e9c69SAndrzej Hajda 801ce6e153fSAndrzej Hajda static void sii8620_fetch_edid(struct sii8620 *ctx) 802ce6e153fSAndrzej Hajda { 803ce6e153fSAndrzej Hajda u8 lm_ddc, ddc_cmd, int3, cbus; 804ce6e153fSAndrzej Hajda int fetched, i; 805ce6e153fSAndrzej Hajda int edid_len = EDID_LENGTH; 806ce6e153fSAndrzej Hajda u8 *edid; 807ce6e153fSAndrzej Hajda 808ce6e153fSAndrzej Hajda sii8620_readb(ctx, REG_CBUS_STATUS); 809ce6e153fSAndrzej Hajda lm_ddc = sii8620_readb(ctx, REG_LM_DDC); 810ce6e153fSAndrzej Hajda ddc_cmd = sii8620_readb(ctx, REG_DDC_CMD); 811ce6e153fSAndrzej Hajda 812ce6e153fSAndrzej Hajda sii8620_write_seq(ctx, 813ce6e153fSAndrzej Hajda REG_INTR9_MASK, 0, 814ce6e153fSAndrzej Hajda REG_EDID_CTRL, BIT_EDID_CTRL_EDID_FIFO_ADDR_AUTO, 815ce6e153fSAndrzej Hajda REG_HDCP2X_POLL_CS, 0x71, 816ce6e153fSAndrzej Hajda REG_HDCP2X_CTRL_0, BIT_HDCP2X_CTRL_0_HDCP2X_HDCPTX, 817ce6e153fSAndrzej Hajda REG_LM_DDC, lm_ddc | BIT_LM_DDC_SW_TPI_EN_DISABLED, 818ce6e153fSAndrzej Hajda ); 819ce6e153fSAndrzej Hajda 820ce6e153fSAndrzej Hajda for (i = 0; i < 256; ++i) { 821ce6e153fSAndrzej Hajda u8 ddc_stat = sii8620_readb(ctx, REG_DDC_STATUS); 822ce6e153fSAndrzej Hajda 823ce6e153fSAndrzej Hajda if (!(ddc_stat & BIT_DDC_STATUS_DDC_I2C_IN_PROG)) 824ce6e153fSAndrzej Hajda break; 825ce6e153fSAndrzej Hajda sii8620_write(ctx, REG_DDC_STATUS, 826ce6e153fSAndrzej Hajda BIT_DDC_STATUS_DDC_FIFO_EMPTY); 827ce6e153fSAndrzej Hajda } 828ce6e153fSAndrzej Hajda 829ce6e153fSAndrzej Hajda sii8620_write(ctx, REG_DDC_ADDR, 0x50 << 1); 830ce6e153fSAndrzej Hajda 831ce6e153fSAndrzej Hajda edid = kmalloc(EDID_LENGTH, GFP_KERNEL); 832ce6e153fSAndrzej Hajda if (!edid) { 833ce6e153fSAndrzej Hajda ctx->error = -ENOMEM; 834ce6e153fSAndrzej Hajda return; 835ce6e153fSAndrzej Hajda } 836ce6e153fSAndrzej Hajda 837ce6e153fSAndrzej Hajda #define FETCH_SIZE 16 838ce6e153fSAndrzej Hajda for (fetched = 0; fetched < edid_len; fetched += FETCH_SIZE) { 839ce6e153fSAndrzej Hajda sii8620_readb(ctx, REG_DDC_STATUS); 840ce6e153fSAndrzej Hajda sii8620_write_seq(ctx, 841ce6e153fSAndrzej Hajda REG_DDC_CMD, ddc_cmd | VAL_DDC_CMD_DDC_CMD_ABORT, 842ce6e153fSAndrzej Hajda REG_DDC_CMD, ddc_cmd | VAL_DDC_CMD_DDC_CMD_CLEAR_FIFO, 843ce6e153fSAndrzej Hajda REG_DDC_STATUS, BIT_DDC_STATUS_DDC_FIFO_EMPTY 844ce6e153fSAndrzej Hajda ); 845ce6e153fSAndrzej Hajda sii8620_write_seq(ctx, 846ce6e153fSAndrzej Hajda REG_DDC_SEGM, fetched >> 8, 847ce6e153fSAndrzej Hajda REG_DDC_OFFSET, fetched & 0xff, 848ce6e153fSAndrzej Hajda REG_DDC_DIN_CNT1, FETCH_SIZE, 849ce6e153fSAndrzej Hajda REG_DDC_DIN_CNT2, 0, 850ce6e153fSAndrzej Hajda REG_DDC_CMD, ddc_cmd | VAL_DDC_CMD_ENH_DDC_READ_NO_ACK 851ce6e153fSAndrzej Hajda ); 852ce6e153fSAndrzej Hajda 853ce6e153fSAndrzej Hajda do { 854ce6e153fSAndrzej Hajda int3 = sii8620_readb(ctx, REG_INTR3); 855ce6e153fSAndrzej Hajda cbus = sii8620_readb(ctx, REG_CBUS_STATUS); 856ce6e153fSAndrzej Hajda 857ce6e153fSAndrzej Hajda if (int3 & BIT_DDC_CMD_DONE) 858ce6e153fSAndrzej Hajda break; 859ce6e153fSAndrzej Hajda 860ce6e153fSAndrzej Hajda if (!(cbus & BIT_CBUS_STATUS_CBUS_CONNECTED)) { 861ce6e153fSAndrzej Hajda kfree(edid); 862ce6e153fSAndrzej Hajda edid = NULL; 863ce6e153fSAndrzej Hajda goto end; 864ce6e153fSAndrzej Hajda } 865ce6e153fSAndrzej Hajda } while (1); 866ce6e153fSAndrzej Hajda 867ce6e153fSAndrzej Hajda sii8620_readb(ctx, REG_DDC_STATUS); 868ce6e153fSAndrzej Hajda while (sii8620_readb(ctx, REG_DDC_DOUT_CNT) < FETCH_SIZE) 869ce6e153fSAndrzej Hajda usleep_range(10, 20); 870ce6e153fSAndrzej Hajda 871ce6e153fSAndrzej Hajda sii8620_read_buf(ctx, REG_DDC_DATA, edid + fetched, FETCH_SIZE); 872ce6e153fSAndrzej Hajda if (fetched + FETCH_SIZE == EDID_LENGTH) { 873ce6e153fSAndrzej Hajda u8 ext = ((struct edid *)edid)->extensions; 874ce6e153fSAndrzej Hajda 875ce6e153fSAndrzej Hajda if (ext) { 876ce6e153fSAndrzej Hajda u8 *new_edid; 877ce6e153fSAndrzej Hajda 878ce6e153fSAndrzej Hajda edid_len += ext * EDID_LENGTH; 879ce6e153fSAndrzej Hajda new_edid = krealloc(edid, edid_len, GFP_KERNEL); 880ce6e153fSAndrzej Hajda if (!new_edid) { 881ce6e153fSAndrzej Hajda kfree(edid); 882ce6e153fSAndrzej Hajda ctx->error = -ENOMEM; 883ce6e153fSAndrzej Hajda return; 884ce6e153fSAndrzej Hajda } 885ce6e153fSAndrzej Hajda edid = new_edid; 886ce6e153fSAndrzej Hajda } 887ce6e153fSAndrzej Hajda } 888ce6e153fSAndrzej Hajda } 889ce6e153fSAndrzej Hajda 890263b5c93SAndrzej Hajda sii8620_write_seq(ctx, 891263b5c93SAndrzej Hajda REG_INTR3_MASK, BIT_DDC_CMD_DONE, 892263b5c93SAndrzej Hajda REG_LM_DDC, lm_ddc 893263b5c93SAndrzej Hajda ); 894ce6e153fSAndrzej Hajda 895ce6e153fSAndrzej Hajda end: 896ce6e153fSAndrzej Hajda kfree(ctx->edid); 897ce6e153fSAndrzej Hajda ctx->edid = (struct edid *)edid; 898ce6e153fSAndrzej Hajda } 899ce6e153fSAndrzej Hajda 900ce6e153fSAndrzej Hajda static void sii8620_set_upstream_edid(struct sii8620 *ctx) 901ce6e153fSAndrzej Hajda { 902ce6e153fSAndrzej Hajda sii8620_setbits(ctx, REG_DPD, BIT_DPD_PDNRX12 | BIT_DPD_PDIDCK_N 903ce6e153fSAndrzej Hajda | BIT_DPD_PD_MHL_CLK_N, 0xff); 904ce6e153fSAndrzej Hajda 905ce6e153fSAndrzej Hajda sii8620_write_seq_static(ctx, 906ce6e153fSAndrzej Hajda REG_RX_HDMI_CTRL3, 0x00, 907ce6e153fSAndrzej Hajda REG_PKT_FILTER_0, 0xFF, 908ce6e153fSAndrzej Hajda REG_PKT_FILTER_1, 0xFF, 909ce6e153fSAndrzej Hajda REG_ALICE0_BW_I2C, 0x06 910ce6e153fSAndrzej Hajda ); 911ce6e153fSAndrzej Hajda 912ce6e153fSAndrzej Hajda sii8620_setbits(ctx, REG_RX_HDMI_CLR_BUFFER, 913ce6e153fSAndrzej Hajda BIT_RX_HDMI_CLR_BUFFER_VSI_CLR_EN, 0xff); 914ce6e153fSAndrzej Hajda 915ce6e153fSAndrzej Hajda sii8620_write_seq_static(ctx, 916ce6e153fSAndrzej Hajda REG_EDID_CTRL, BIT_EDID_CTRL_EDID_FIFO_ADDR_AUTO 917ce6e153fSAndrzej Hajda | BIT_EDID_CTRL_EDID_MODE_EN, 918ce6e153fSAndrzej Hajda REG_EDID_FIFO_ADDR, 0, 919ce6e153fSAndrzej Hajda ); 920ce6e153fSAndrzej Hajda 921ce6e153fSAndrzej Hajda sii8620_write_buf(ctx, REG_EDID_FIFO_WR_DATA, (u8 *)ctx->edid, 922ce6e153fSAndrzej Hajda (ctx->edid->extensions + 1) * EDID_LENGTH); 923ce6e153fSAndrzej Hajda 924ce6e153fSAndrzej Hajda sii8620_write_seq_static(ctx, 925ce6e153fSAndrzej Hajda REG_EDID_CTRL, BIT_EDID_CTRL_EDID_PRIME_VALID 926ce6e153fSAndrzej Hajda | BIT_EDID_CTRL_EDID_FIFO_ADDR_AUTO 927ce6e153fSAndrzej Hajda | BIT_EDID_CTRL_EDID_MODE_EN, 928ce6e153fSAndrzej Hajda REG_INTR5_MASK, BIT_INTR_SCDT_CHANGE, 929ce6e153fSAndrzej Hajda REG_INTR9_MASK, 0 930ce6e153fSAndrzej Hajda ); 931ce6e153fSAndrzej Hajda } 932ce6e153fSAndrzej Hajda 933ce6e153fSAndrzej Hajda static void sii8620_xtal_set_rate(struct sii8620 *ctx) 934ce6e153fSAndrzej Hajda { 935ce6e153fSAndrzej Hajda static const struct { 936ce6e153fSAndrzej Hajda unsigned int rate; 937ce6e153fSAndrzej Hajda u8 div; 938ce6e153fSAndrzej Hajda u8 tp1; 939ce6e153fSAndrzej Hajda } rates[] = { 940ce6e153fSAndrzej Hajda { 19200, 0x04, 0x53 }, 941ce6e153fSAndrzej Hajda { 20000, 0x04, 0x62 }, 942ce6e153fSAndrzej Hajda { 24000, 0x05, 0x75 }, 943ce6e153fSAndrzej Hajda { 30000, 0x06, 0x92 }, 944ce6e153fSAndrzej Hajda { 38400, 0x0c, 0xbc }, 945ce6e153fSAndrzej Hajda }; 946ce6e153fSAndrzej Hajda unsigned long rate = clk_get_rate(ctx->clk_xtal) / 1000; 947ce6e153fSAndrzej Hajda int i; 948ce6e153fSAndrzej Hajda 949ce6e153fSAndrzej Hajda for (i = 0; i < ARRAY_SIZE(rates) - 1; ++i) 950ce6e153fSAndrzej Hajda if (rate <= rates[i].rate) 951ce6e153fSAndrzej Hajda break; 952ce6e153fSAndrzej Hajda 953ce6e153fSAndrzej Hajda if (rate != rates[i].rate) 954ce6e153fSAndrzej Hajda dev_err(ctx->dev, "xtal clock rate(%lukHz) not supported, setting MHL for %ukHz.\n", 955ce6e153fSAndrzej Hajda rate, rates[i].rate); 956ce6e153fSAndrzej Hajda 957ce6e153fSAndrzej Hajda sii8620_write(ctx, REG_DIV_CTL_MAIN, rates[i].div); 958ce6e153fSAndrzej Hajda sii8620_write(ctx, REG_HDCP2X_TP1, rates[i].tp1); 959ce6e153fSAndrzej Hajda } 960ce6e153fSAndrzej Hajda 961ce6e153fSAndrzej Hajda static int sii8620_hw_on(struct sii8620 *ctx) 962ce6e153fSAndrzej Hajda { 963ce6e153fSAndrzej Hajda int ret; 964ce6e153fSAndrzej Hajda 965ce6e153fSAndrzej Hajda ret = regulator_bulk_enable(ARRAY_SIZE(ctx->supplies), ctx->supplies); 966ce6e153fSAndrzej Hajda if (ret) 967ce6e153fSAndrzej Hajda return ret; 968ce6e153fSAndrzej Hajda usleep_range(10000, 20000); 969ce6e153fSAndrzej Hajda return clk_prepare_enable(ctx->clk_xtal); 970ce6e153fSAndrzej Hajda } 971ce6e153fSAndrzej Hajda 972ce6e153fSAndrzej Hajda static int sii8620_hw_off(struct sii8620 *ctx) 973ce6e153fSAndrzej Hajda { 974ce6e153fSAndrzej Hajda clk_disable_unprepare(ctx->clk_xtal); 975ce6e153fSAndrzej Hajda gpiod_set_value(ctx->gpio_reset, 1); 976ce6e153fSAndrzej Hajda return regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies); 977ce6e153fSAndrzej Hajda } 978ce6e153fSAndrzej Hajda 979ce6e153fSAndrzej Hajda static void sii8620_hw_reset(struct sii8620 *ctx) 980ce6e153fSAndrzej Hajda { 981ce6e153fSAndrzej Hajda usleep_range(10000, 20000); 982ce6e153fSAndrzej Hajda gpiod_set_value(ctx->gpio_reset, 0); 983ce6e153fSAndrzej Hajda usleep_range(5000, 20000); 984ce6e153fSAndrzej Hajda gpiod_set_value(ctx->gpio_reset, 1); 985ce6e153fSAndrzej Hajda usleep_range(10000, 20000); 986ce6e153fSAndrzej Hajda gpiod_set_value(ctx->gpio_reset, 0); 987ce6e153fSAndrzej Hajda msleep(300); 988ce6e153fSAndrzej Hajda } 989ce6e153fSAndrzej Hajda 990ce6e153fSAndrzej Hajda static void sii8620_cbus_reset(struct sii8620 *ctx) 991ce6e153fSAndrzej Hajda { 9924dc3c071SAndrzej Hajda sii8620_write(ctx, REG_PWD_SRST, BIT_PWD_SRST_CBUS_RST 9934dc3c071SAndrzej Hajda | BIT_PWD_SRST_CBUS_RST_SW_EN); 9944dc3c071SAndrzej Hajda usleep_range(10000, 20000); 9954dc3c071SAndrzej Hajda sii8620_write(ctx, REG_PWD_SRST, BIT_PWD_SRST_CBUS_RST_SW_EN); 996ce6e153fSAndrzej Hajda } 997ce6e153fSAndrzej Hajda 998ce6e153fSAndrzej Hajda static void sii8620_set_auto_zone(struct sii8620 *ctx) 999ce6e153fSAndrzej Hajda { 1000ce6e153fSAndrzej Hajda if (ctx->mode != CM_MHL1) { 1001ce6e153fSAndrzej Hajda sii8620_write_seq_static(ctx, 1002ce6e153fSAndrzej Hajda REG_TX_ZONE_CTL1, 0x0, 1003ce6e153fSAndrzej Hajda REG_MHL_PLL_CTL0, VAL_MHL_PLL_CTL0_HDMI_CLK_RATIO_1X 1004ce6e153fSAndrzej Hajda | BIT_MHL_PLL_CTL0_CRYSTAL_CLK_SEL 1005ce6e153fSAndrzej Hajda | BIT_MHL_PLL_CTL0_ZONE_MASK_OE 1006ce6e153fSAndrzej Hajda ); 1007ce6e153fSAndrzej Hajda } else { 1008ce6e153fSAndrzej Hajda sii8620_write_seq_static(ctx, 1009ce6e153fSAndrzej Hajda REG_TX_ZONE_CTL1, VAL_TX_ZONE_CTL1_TX_ZONE_CTRL_MODE, 1010ce6e153fSAndrzej Hajda REG_MHL_PLL_CTL0, VAL_MHL_PLL_CTL0_HDMI_CLK_RATIO_1X 1011ce6e153fSAndrzej Hajda | BIT_MHL_PLL_CTL0_ZONE_MASK_OE 1012ce6e153fSAndrzej Hajda ); 1013ce6e153fSAndrzej Hajda } 1014ce6e153fSAndrzej Hajda } 1015ce6e153fSAndrzej Hajda 1016ce6e153fSAndrzej Hajda static void sii8620_stop_video(struct sii8620 *ctx) 1017ce6e153fSAndrzej Hajda { 1018ce6e153fSAndrzej Hajda u8 uninitialized_var(val); 1019ce6e153fSAndrzej Hajda 1020ce6e153fSAndrzej Hajda sii8620_write_seq_static(ctx, 1021ce6e153fSAndrzej Hajda REG_TPI_INTR_EN, 0, 1022ce6e153fSAndrzej Hajda REG_HDCP2X_INTR0_MASK, 0, 1023ce6e153fSAndrzej Hajda REG_TPI_COPP_DATA2, 0, 1024ce6e153fSAndrzej Hajda REG_TPI_INTR_ST0, ~0, 1025ce6e153fSAndrzej Hajda ); 1026ce6e153fSAndrzej Hajda 1027ce6e153fSAndrzej Hajda switch (ctx->sink_type) { 1028ce6e153fSAndrzej Hajda case SINK_DVI: 1029ce6e153fSAndrzej Hajda val = BIT_TPI_SC_REG_TMDS_OE_POWER_DOWN 1030ce6e153fSAndrzej Hajda | BIT_TPI_SC_TPI_AV_MUTE; 1031ce6e153fSAndrzej Hajda break; 1032ce6e153fSAndrzej Hajda case SINK_HDMI: 1033ef822a07SAndrzej Hajda default: 1034ce6e153fSAndrzej Hajda val = BIT_TPI_SC_REG_TMDS_OE_POWER_DOWN 1035ce6e153fSAndrzej Hajda | BIT_TPI_SC_TPI_AV_MUTE 1036ce6e153fSAndrzej Hajda | BIT_TPI_SC_TPI_OUTPUT_MODE_0_HDMI; 1037ce6e153fSAndrzej Hajda break; 1038ce6e153fSAndrzej Hajda } 1039ce6e153fSAndrzej Hajda 1040ce6e153fSAndrzej Hajda sii8620_write(ctx, REG_TPI_SC, val); 1041ce6e153fSAndrzej Hajda } 1042ce6e153fSAndrzej Hajda 1043bf1722caSAndrzej Hajda static void sii8620_set_format(struct sii8620 *ctx) 1044bf1722caSAndrzej Hajda { 1045bf1722caSAndrzej Hajda u8 out_fmt; 1046bf1722caSAndrzej Hajda 1047bf1722caSAndrzej Hajda if (sii8620_is_mhl3(ctx)) { 1048bf1722caSAndrzej Hajda sii8620_setbits(ctx, REG_M3_P0CTRL, 1049bf1722caSAndrzej Hajda BIT_M3_P0CTRL_MHL3_P0_PIXEL_MODE_PACKED, 1050bf1722caSAndrzej Hajda ctx->use_packed_pixel ? ~0 : 0); 1051bf1722caSAndrzej Hajda } else { 1052bf1722caSAndrzej Hajda if (ctx->use_packed_pixel) 1053bf1722caSAndrzej Hajda sii8620_write_seq_static(ctx, 1054bf1722caSAndrzej Hajda REG_VID_MODE, BIT_VID_MODE_M1080P, 1055bf1722caSAndrzej Hajda REG_MHL_TOP_CTL, BIT_MHL_TOP_CTL_MHL_PP_SEL | 1, 1056bf1722caSAndrzej Hajda REG_MHLTX_CTL6, 0x60 1057bf1722caSAndrzej Hajda ); 1058bf1722caSAndrzej Hajda else 1059bf1722caSAndrzej Hajda sii8620_write_seq_static(ctx, 1060bf1722caSAndrzej Hajda REG_VID_MODE, 0, 1061bf1722caSAndrzej Hajda REG_MHL_TOP_CTL, 1, 1062bf1722caSAndrzej Hajda REG_MHLTX_CTL6, 0xa0 1063bf1722caSAndrzej Hajda ); 1064bf1722caSAndrzej Hajda } 1065bf1722caSAndrzej Hajda 1066bf1722caSAndrzej Hajda if (ctx->use_packed_pixel) 1067bf1722caSAndrzej Hajda out_fmt = VAL_TPI_FORMAT(YCBCR422, FULL) | 1068bf1722caSAndrzej Hajda BIT_TPI_OUTPUT_CSCMODE709; 1069bf1722caSAndrzej Hajda else 1070bf1722caSAndrzej Hajda out_fmt = VAL_TPI_FORMAT(RGB, FULL); 1071bf1722caSAndrzej Hajda 1072bf1722caSAndrzej Hajda sii8620_write_seq(ctx, 1073bf1722caSAndrzej Hajda REG_TPI_INPUT, VAL_TPI_FORMAT(RGB, FULL), 1074bf1722caSAndrzej Hajda REG_TPI_OUTPUT, out_fmt, 1075bf1722caSAndrzej Hajda ); 1076bf1722caSAndrzej Hajda } 1077bf1722caSAndrzej Hajda 1078bf1722caSAndrzej Hajda static int mhl3_infoframe_init(struct mhl3_infoframe *frame) 1079bf1722caSAndrzej Hajda { 1080bf1722caSAndrzej Hajda memset(frame, 0, sizeof(*frame)); 1081bf1722caSAndrzej Hajda 1082bf1722caSAndrzej Hajda frame->version = 3; 1083bf1722caSAndrzej Hajda frame->hev_format = -1; 1084bf1722caSAndrzej Hajda return 0; 1085bf1722caSAndrzej Hajda } 1086bf1722caSAndrzej Hajda 1087bf1722caSAndrzej Hajda static ssize_t mhl3_infoframe_pack(struct mhl3_infoframe *frame, 1088bf1722caSAndrzej Hajda void *buffer, size_t size) 1089bf1722caSAndrzej Hajda { 1090bf1722caSAndrzej Hajda const int frm_len = HDMI_INFOFRAME_HEADER_SIZE + MHL3_INFOFRAME_SIZE; 1091bf1722caSAndrzej Hajda u8 *ptr = buffer; 1092bf1722caSAndrzej Hajda 1093bf1722caSAndrzej Hajda if (size < frm_len) 1094bf1722caSAndrzej Hajda return -ENOSPC; 1095bf1722caSAndrzej Hajda 1096bf1722caSAndrzej Hajda memset(buffer, 0, size); 1097bf1722caSAndrzej Hajda ptr[0] = HDMI_INFOFRAME_TYPE_VENDOR; 1098bf1722caSAndrzej Hajda ptr[1] = frame->version; 1099bf1722caSAndrzej Hajda ptr[2] = MHL3_INFOFRAME_SIZE; 1100bf1722caSAndrzej Hajda ptr[4] = MHL3_IEEE_OUI & 0xff; 1101bf1722caSAndrzej Hajda ptr[5] = (MHL3_IEEE_OUI >> 8) & 0xff; 1102bf1722caSAndrzej Hajda ptr[6] = (MHL3_IEEE_OUI >> 16) & 0xff; 1103bf1722caSAndrzej Hajda ptr[7] = frame->video_format & 0x3; 1104bf1722caSAndrzej Hajda ptr[7] |= (frame->format_type & 0x7) << 2; 1105bf1722caSAndrzej Hajda ptr[7] |= frame->sep_audio ? BIT(5) : 0; 1106bf1722caSAndrzej Hajda if (frame->hev_format >= 0) { 1107bf1722caSAndrzej Hajda ptr[9] = 1; 1108bf1722caSAndrzej Hajda ptr[10] = (frame->hev_format >> 8) & 0xff; 1109bf1722caSAndrzej Hajda ptr[11] = frame->hev_format & 0xff; 1110bf1722caSAndrzej Hajda } 1111bf1722caSAndrzej Hajda if (frame->av_delay) { 1112bf1722caSAndrzej Hajda bool sign = frame->av_delay < 0; 1113bf1722caSAndrzej Hajda int delay = sign ? -frame->av_delay : frame->av_delay; 1114bf1722caSAndrzej Hajda 1115bf1722caSAndrzej Hajda ptr[12] = (delay >> 16) & 0xf; 1116bf1722caSAndrzej Hajda if (sign) 1117bf1722caSAndrzej Hajda ptr[12] |= BIT(4); 1118bf1722caSAndrzej Hajda ptr[13] = (delay >> 8) & 0xff; 1119bf1722caSAndrzej Hajda ptr[14] = delay & 0xff; 1120bf1722caSAndrzej Hajda } 1121bf1722caSAndrzej Hajda ptr[3] -= sii8620_checksum(buffer, frm_len); 1122bf1722caSAndrzej Hajda return frm_len; 1123bf1722caSAndrzej Hajda } 1124bf1722caSAndrzej Hajda 1125bf1722caSAndrzej Hajda static void sii8620_set_infoframes(struct sii8620 *ctx) 1126bf1722caSAndrzej Hajda { 1127bf1722caSAndrzej Hajda struct mhl3_infoframe mhl_frm; 1128bf1722caSAndrzej Hajda union hdmi_infoframe frm; 1129bf1722caSAndrzej Hajda u8 buf[31]; 1130bf1722caSAndrzej Hajda int ret; 1131bf1722caSAndrzej Hajda 1132bf1722caSAndrzej Hajda if (!sii8620_is_mhl3(ctx) || !ctx->use_packed_pixel) { 1133bf1722caSAndrzej Hajda sii8620_write(ctx, REG_TPI_SC, 1134bf1722caSAndrzej Hajda BIT_TPI_SC_TPI_OUTPUT_MODE_0_HDMI); 1135bf1722caSAndrzej Hajda sii8620_write_buf(ctx, REG_TPI_AVI_CHSUM, ctx->avif + 3, 1136bf1722caSAndrzej Hajda ARRAY_SIZE(ctx->avif) - 3); 1137bf1722caSAndrzej Hajda sii8620_write(ctx, REG_PKT_FILTER_0, 1138bf1722caSAndrzej Hajda BIT_PKT_FILTER_0_DROP_CEA_GAMUT_PKT | 1139bf1722caSAndrzej Hajda BIT_PKT_FILTER_0_DROP_MPEG_PKT | 1140bf1722caSAndrzej Hajda BIT_PKT_FILTER_0_DROP_GCP_PKT, 1141bf1722caSAndrzej Hajda BIT_PKT_FILTER_1_DROP_GEN_PKT); 1142bf1722caSAndrzej Hajda return; 1143bf1722caSAndrzej Hajda } 1144bf1722caSAndrzej Hajda 1145bf1722caSAndrzej Hajda ret = hdmi_avi_infoframe_init(&frm.avi); 1146bf1722caSAndrzej Hajda frm.avi.colorspace = HDMI_COLORSPACE_YUV422; 1147bf1722caSAndrzej Hajda frm.avi.active_aspect = HDMI_ACTIVE_ASPECT_PICTURE; 1148bf1722caSAndrzej Hajda frm.avi.picture_aspect = HDMI_PICTURE_ASPECT_16_9; 1149bf1722caSAndrzej Hajda frm.avi.colorimetry = HDMI_COLORIMETRY_ITU_709; 1150bf1722caSAndrzej Hajda frm.avi.video_code = ctx->video_code; 1151bf1722caSAndrzej Hajda if (!ret) 1152bf1722caSAndrzej Hajda ret = hdmi_avi_infoframe_pack(&frm.avi, buf, ARRAY_SIZE(buf)); 1153bf1722caSAndrzej Hajda if (ret > 0) 1154bf1722caSAndrzej Hajda sii8620_write_buf(ctx, REG_TPI_AVI_CHSUM, buf + 3, ret - 3); 1155bf1722caSAndrzej Hajda sii8620_write(ctx, REG_PKT_FILTER_0, 1156bf1722caSAndrzej Hajda BIT_PKT_FILTER_0_DROP_CEA_GAMUT_PKT | 1157bf1722caSAndrzej Hajda BIT_PKT_FILTER_0_DROP_MPEG_PKT | 1158bf1722caSAndrzej Hajda BIT_PKT_FILTER_0_DROP_AVI_PKT | 1159bf1722caSAndrzej Hajda BIT_PKT_FILTER_0_DROP_GCP_PKT, 1160bf1722caSAndrzej Hajda BIT_PKT_FILTER_1_VSI_OVERRIDE_DIS | 1161bf1722caSAndrzej Hajda BIT_PKT_FILTER_1_DROP_GEN_PKT | 1162bf1722caSAndrzej Hajda BIT_PKT_FILTER_1_DROP_VSIF_PKT); 1163bf1722caSAndrzej Hajda 1164bf1722caSAndrzej Hajda sii8620_write(ctx, REG_TPI_INFO_FSEL, BIT_TPI_INFO_FSEL_EN 1165bf1722caSAndrzej Hajda | BIT_TPI_INFO_FSEL_RPT | VAL_TPI_INFO_FSEL_VSI); 1166bf1722caSAndrzej Hajda ret = mhl3_infoframe_init(&mhl_frm); 1167bf1722caSAndrzej Hajda if (!ret) 1168bf1722caSAndrzej Hajda ret = mhl3_infoframe_pack(&mhl_frm, buf, ARRAY_SIZE(buf)); 1169bf1722caSAndrzej Hajda sii8620_write_buf(ctx, REG_TPI_INFO_B0, buf, ret); 1170bf1722caSAndrzej Hajda } 1171bf1722caSAndrzej Hajda 1172*5c632e22SMaciej Purski static void sii8620_start_video(struct sii8620 *ctx) 1173ce6e153fSAndrzej Hajda { 1174*5c632e22SMaciej Purski if (!sii8620_is_mhl3(ctx)) 1175*5c632e22SMaciej Purski sii8620_stop_video(ctx); 1176*5c632e22SMaciej Purski 1177*5c632e22SMaciej Purski if (ctx->sink_type == SINK_DVI && !sii8620_is_mhl3(ctx)) { 1178*5c632e22SMaciej Purski sii8620_write(ctx, REG_RX_HDMI_CTRL2, 1179*5c632e22SMaciej Purski VAL_RX_HDMI_CTRL2_DEFVAL); 1180*5c632e22SMaciej Purski sii8620_write(ctx, REG_TPI_SC, 0); 1181*5c632e22SMaciej Purski return; 1182*5c632e22SMaciej Purski } 1183*5c632e22SMaciej Purski 1184ce6e153fSAndrzej Hajda sii8620_write_seq_static(ctx, 1185ce6e153fSAndrzej Hajda REG_RX_HDMI_CTRL2, VAL_RX_HDMI_CTRL2_DEFVAL 1186ce6e153fSAndrzej Hajda | BIT_RX_HDMI_CTRL2_USE_AV_MUTE, 1187ce6e153fSAndrzej Hajda REG_VID_OVRRD, BIT_VID_OVRRD_PP_AUTO_DISABLE 1188bf1722caSAndrzej Hajda | BIT_VID_OVRRD_M1080P_OVRRD); 1189bf1722caSAndrzej Hajda sii8620_set_format(ctx); 1190ce6e153fSAndrzej Hajda 1191bf1722caSAndrzej Hajda if (!sii8620_is_mhl3(ctx)) { 1192ce6e153fSAndrzej Hajda sii8620_mt_write_stat(ctx, MHL_DST_REG(LINK_MODE), 1193bf1722caSAndrzej Hajda MHL_DST_LM_CLK_MODE_NORMAL | MHL_DST_LM_PATH_ENABLED); 1194ce6e153fSAndrzej Hajda sii8620_set_auto_zone(ctx); 1195bf1722caSAndrzej Hajda } else { 1196bf1722caSAndrzej Hajda static const struct { 1197bf1722caSAndrzej Hajda int max_clk; 1198bf1722caSAndrzej Hajda u8 zone; 1199bf1722caSAndrzej Hajda u8 link_rate; 1200bf1722caSAndrzej Hajda u8 rrp_decode; 1201bf1722caSAndrzej Hajda } clk_spec[] = { 1202bf1722caSAndrzej Hajda { 150000, VAL_TX_ZONE_CTL3_TX_ZONE_1_5GBPS, 1203bf1722caSAndrzej Hajda MHL_XDS_LINK_RATE_1_5_GBPS, 0x38 }, 1204bf1722caSAndrzej Hajda { 300000, VAL_TX_ZONE_CTL3_TX_ZONE_3GBPS, 1205bf1722caSAndrzej Hajda MHL_XDS_LINK_RATE_3_0_GBPS, 0x40 }, 1206bf1722caSAndrzej Hajda { 600000, VAL_TX_ZONE_CTL3_TX_ZONE_6GBPS, 1207bf1722caSAndrzej Hajda MHL_XDS_LINK_RATE_6_0_GBPS, 0x40 }, 1208bf1722caSAndrzej Hajda }; 1209bf1722caSAndrzej Hajda u8 p0_ctrl = BIT_M3_P0CTRL_MHL3_P0_PORT_EN; 1210bf1722caSAndrzej Hajda int clk = ctx->pixel_clock * (ctx->use_packed_pixel ? 2 : 3); 1211bf1722caSAndrzej Hajda int i; 1212ce6e153fSAndrzej Hajda 1213bf1722caSAndrzej Hajda for (i = 0; i < ARRAY_SIZE(clk_spec); ++i) 1214bf1722caSAndrzej Hajda if (clk < clk_spec[i].max_clk) 1215bf1722caSAndrzej Hajda break; 1216ce6e153fSAndrzej Hajda 1217bf1722caSAndrzej Hajda if (100 * clk >= 98 * clk_spec[i].max_clk) 1218bf1722caSAndrzej Hajda p0_ctrl |= BIT_M3_P0CTRL_MHL3_P0_UNLIMIT_EN; 1219ce6e153fSAndrzej Hajda 1220bf1722caSAndrzej Hajda sii8620_burst_tx_bits_per_pixel_fmt(ctx, ctx->use_packed_pixel); 1221bf1722caSAndrzej Hajda sii8620_burst_send(ctx); 1222bf1722caSAndrzej Hajda sii8620_write_seq(ctx, 1223bf1722caSAndrzej Hajda REG_MHL_DP_CTL0, 0xf0, 1224bf1722caSAndrzej Hajda REG_MHL3_TX_ZONE_CTL, clk_spec[i].zone); 1225bf1722caSAndrzej Hajda sii8620_setbits(ctx, REG_M3_P0CTRL, 1226bf1722caSAndrzej Hajda BIT_M3_P0CTRL_MHL3_P0_PORT_EN 1227bf1722caSAndrzej Hajda | BIT_M3_P0CTRL_MHL3_P0_UNLIMIT_EN, p0_ctrl); 1228bf1722caSAndrzej Hajda sii8620_setbits(ctx, REG_M3_POSTM, MSK_M3_POSTM_RRP_DECODE, 1229bf1722caSAndrzej Hajda clk_spec[i].rrp_decode); 1230bf1722caSAndrzej Hajda sii8620_write_seq_static(ctx, 1231bf1722caSAndrzej Hajda REG_M3_CTRL, VAL_M3_CTRL_MHL3_VALUE 1232bf1722caSAndrzej Hajda | BIT_M3_CTRL_H2M_SWRST, 1233bf1722caSAndrzej Hajda REG_M3_CTRL, VAL_M3_CTRL_MHL3_VALUE 1234bf1722caSAndrzej Hajda ); 1235bf1722caSAndrzej Hajda sii8620_mt_write_stat(ctx, MHL_XDS_REG(AVLINK_MODE_CONTROL), 1236bf1722caSAndrzej Hajda clk_spec[i].link_rate); 1237bf1722caSAndrzej Hajda } 1238bf1722caSAndrzej Hajda 1239bf1722caSAndrzej Hajda sii8620_set_infoframes(ctx); 1240ce6e153fSAndrzej Hajda } 1241ce6e153fSAndrzej Hajda 1242ce6e153fSAndrzej Hajda static void sii8620_disable_hpd(struct sii8620 *ctx) 1243ce6e153fSAndrzej Hajda { 1244ce6e153fSAndrzej Hajda sii8620_setbits(ctx, REG_EDID_CTRL, BIT_EDID_CTRL_EDID_PRIME_VALID, 0); 1245ce6e153fSAndrzej Hajda sii8620_write_seq_static(ctx, 1246ce6e153fSAndrzej Hajda REG_HPD_CTRL, BIT_HPD_CTRL_HPD_OUT_OVR_EN, 1247ce6e153fSAndrzej Hajda REG_INTR8_MASK, 0 1248ce6e153fSAndrzej Hajda ); 1249ce6e153fSAndrzej Hajda } 1250ce6e153fSAndrzej Hajda 1251ce6e153fSAndrzej Hajda static void sii8620_enable_hpd(struct sii8620 *ctx) 1252ce6e153fSAndrzej Hajda { 1253ce6e153fSAndrzej Hajda sii8620_setbits(ctx, REG_TMDS_CSTAT_P3, 1254ce6e153fSAndrzej Hajda BIT_TMDS_CSTAT_P3_SCDT_CLR_AVI_DIS 1255ce6e153fSAndrzej Hajda | BIT_TMDS_CSTAT_P3_CLR_AVI, ~0); 1256ce6e153fSAndrzej Hajda sii8620_write_seq_static(ctx, 1257ce6e153fSAndrzej Hajda REG_HPD_CTRL, BIT_HPD_CTRL_HPD_OUT_OVR_EN 1258ce6e153fSAndrzej Hajda | BIT_HPD_CTRL_HPD_HIGH, 1259ce6e153fSAndrzej Hajda ); 1260ce6e153fSAndrzej Hajda } 1261ce6e153fSAndrzej Hajda 1262ce6e153fSAndrzej Hajda static void sii8620_mhl_discover(struct sii8620 *ctx) 1263ce6e153fSAndrzej Hajda { 1264ce6e153fSAndrzej Hajda sii8620_write_seq_static(ctx, 1265ce6e153fSAndrzej Hajda REG_DISC_CTRL9, BIT_DISC_CTRL9_WAKE_DRVFLT 1266ce6e153fSAndrzej Hajda | BIT_DISC_CTRL9_DISC_PULSE_PROCEED, 1267ce6e153fSAndrzej Hajda REG_DISC_CTRL4, VAL_DISC_CTRL4(VAL_PUP_5K, VAL_PUP_20K), 1268ce6e153fSAndrzej Hajda REG_CBUS_DISC_INTR0_MASK, BIT_MHL3_EST_INT 1269ce6e153fSAndrzej Hajda | BIT_MHL_EST_INT 1270ce6e153fSAndrzej Hajda | BIT_NOT_MHL_EST_INT 1271ce6e153fSAndrzej Hajda | BIT_CBUS_MHL3_DISCON_INT 1272ce6e153fSAndrzej Hajda | BIT_CBUS_MHL12_DISCON_INT 1273ce6e153fSAndrzej Hajda | BIT_RGND_READY_INT, 1274ce6e153fSAndrzej Hajda REG_MHL_PLL_CTL0, VAL_MHL_PLL_CTL0_HDMI_CLK_RATIO_1X 1275ce6e153fSAndrzej Hajda | BIT_MHL_PLL_CTL0_CRYSTAL_CLK_SEL 1276ce6e153fSAndrzej Hajda | BIT_MHL_PLL_CTL0_ZONE_MASK_OE, 1277ce6e153fSAndrzej Hajda REG_MHL_DP_CTL0, BIT_MHL_DP_CTL0_DP_OE 1278ce6e153fSAndrzej Hajda | BIT_MHL_DP_CTL0_TX_OE_OVR, 1279ce6e153fSAndrzej Hajda REG_M3_CTRL, VAL_M3_CTRL_MHL3_VALUE, 1280ce6e153fSAndrzej Hajda REG_MHL_DP_CTL1, 0xA2, 1281ce6e153fSAndrzej Hajda REG_MHL_DP_CTL2, 0x03, 1282ce6e153fSAndrzej Hajda REG_MHL_DP_CTL3, 0x35, 1283ce6e153fSAndrzej Hajda REG_MHL_DP_CTL5, 0x02, 1284ce6e153fSAndrzej Hajda REG_MHL_DP_CTL6, 0x02, 1285ce6e153fSAndrzej Hajda REG_MHL_DP_CTL7, 0x03, 1286ce6e153fSAndrzej Hajda REG_COC_CTLC, 0xFF, 1287ce6e153fSAndrzej Hajda REG_DPD, BIT_DPD_PWRON_PLL | BIT_DPD_PDNTX12 1288ce6e153fSAndrzej Hajda | BIT_DPD_OSC_EN | BIT_DPD_PWRON_HSIC, 1289ce6e153fSAndrzej Hajda REG_COC_INTR_MASK, BIT_COC_PLL_LOCK_STATUS_CHANGE 1290ce6e153fSAndrzej Hajda | BIT_COC_CALIBRATION_DONE, 1291ce6e153fSAndrzej Hajda REG_CBUS_INT_1_MASK, BIT_CBUS_MSC_ABORT_RCVD 1292ce6e153fSAndrzej Hajda | BIT_CBUS_CMD_ABORT, 1293ce6e153fSAndrzej Hajda REG_CBUS_INT_0_MASK, BIT_CBUS_MSC_MT_DONE 1294ce6e153fSAndrzej Hajda | BIT_CBUS_HPD_CHG 1295ce6e153fSAndrzej Hajda | BIT_CBUS_MSC_MR_WRITE_STAT 1296ce6e153fSAndrzej Hajda | BIT_CBUS_MSC_MR_MSC_MSG 1297ce6e153fSAndrzej Hajda | BIT_CBUS_MSC_MR_WRITE_BURST 1298ce6e153fSAndrzej Hajda | BIT_CBUS_MSC_MR_SET_INT 1299ce6e153fSAndrzej Hajda | BIT_CBUS_MSC_MT_DONE_NACK 1300ce6e153fSAndrzej Hajda ); 1301ce6e153fSAndrzej Hajda } 1302ce6e153fSAndrzej Hajda 1303ce6e153fSAndrzej Hajda static void sii8620_peer_specific_init(struct sii8620 *ctx) 1304ce6e153fSAndrzej Hajda { 1305bb4954c7SAndrzej Hajda if (sii8620_is_mhl3(ctx)) 1306ce6e153fSAndrzej Hajda sii8620_write_seq_static(ctx, 1307ce6e153fSAndrzej Hajda REG_SYS_CTRL1, BIT_SYS_CTRL1_BLOCK_DDC_BY_HPD, 1308ce6e153fSAndrzej Hajda REG_EMSCINTRMASK1, 1309ce6e153fSAndrzej Hajda BIT_EMSCINTR1_EMSC_TRAINING_COMMA_ERR 1310ce6e153fSAndrzej Hajda ); 1311ce6e153fSAndrzej Hajda else 1312ce6e153fSAndrzej Hajda sii8620_write_seq_static(ctx, 1313ce6e153fSAndrzej Hajda REG_HDCP2X_INTR0_MASK, 0x00, 1314ce6e153fSAndrzej Hajda REG_EMSCINTRMASK1, 0x00, 1315ce6e153fSAndrzej Hajda REG_HDCP2X_INTR0, 0xFF, 1316ce6e153fSAndrzej Hajda REG_INTR1, 0xFF, 1317ce6e153fSAndrzej Hajda REG_SYS_CTRL1, BIT_SYS_CTRL1_BLOCK_DDC_BY_HPD 1318ce6e153fSAndrzej Hajda | BIT_SYS_CTRL1_TX_CTRL_HDMI 1319ce6e153fSAndrzej Hajda ); 1320ce6e153fSAndrzej Hajda } 1321ce6e153fSAndrzej Hajda 1322ce6e153fSAndrzej Hajda #define SII8620_MHL_VERSION 0x32 1323ce6e153fSAndrzej Hajda #define SII8620_SCRATCHPAD_SIZE 16 1324ce6e153fSAndrzej Hajda #define SII8620_INT_STAT_SIZE 0x33 1325ce6e153fSAndrzej Hajda 1326ce6e153fSAndrzej Hajda static void sii8620_set_dev_cap(struct sii8620 *ctx) 1327ce6e153fSAndrzej Hajda { 1328ce6e153fSAndrzej Hajda static const u8 devcap[MHL_DCAP_SIZE] = { 1329ce6e153fSAndrzej Hajda [MHL_DCAP_MHL_VERSION] = SII8620_MHL_VERSION, 1330ce6e153fSAndrzej Hajda [MHL_DCAP_CAT] = MHL_DCAP_CAT_SOURCE | MHL_DCAP_CAT_POWER, 1331ce6e153fSAndrzej Hajda [MHL_DCAP_ADOPTER_ID_H] = 0x01, 1332ce6e153fSAndrzej Hajda [MHL_DCAP_ADOPTER_ID_L] = 0x41, 1333ce6e153fSAndrzej Hajda [MHL_DCAP_VID_LINK_MODE] = MHL_DCAP_VID_LINK_RGB444 1334ce6e153fSAndrzej Hajda | MHL_DCAP_VID_LINK_PPIXEL 1335ce6e153fSAndrzej Hajda | MHL_DCAP_VID_LINK_16BPP, 1336ce6e153fSAndrzej Hajda [MHL_DCAP_AUD_LINK_MODE] = MHL_DCAP_AUD_LINK_2CH, 1337ce6e153fSAndrzej Hajda [MHL_DCAP_VIDEO_TYPE] = MHL_DCAP_VT_GRAPHICS, 1338ce6e153fSAndrzej Hajda [MHL_DCAP_LOG_DEV_MAP] = MHL_DCAP_LD_GUI, 1339ce6e153fSAndrzej Hajda [MHL_DCAP_BANDWIDTH] = 0x0f, 1340ce6e153fSAndrzej Hajda [MHL_DCAP_FEATURE_FLAG] = MHL_DCAP_FEATURE_RCP_SUPPORT 1341ce6e153fSAndrzej Hajda | MHL_DCAP_FEATURE_RAP_SUPPORT 1342ce6e153fSAndrzej Hajda | MHL_DCAP_FEATURE_SP_SUPPORT, 1343ce6e153fSAndrzej Hajda [MHL_DCAP_SCRATCHPAD_SIZE] = SII8620_SCRATCHPAD_SIZE, 1344ce6e153fSAndrzej Hajda [MHL_DCAP_INT_STAT_SIZE] = SII8620_INT_STAT_SIZE, 1345ce6e153fSAndrzej Hajda }; 1346ce6e153fSAndrzej Hajda static const u8 xdcap[MHL_XDC_SIZE] = { 1347ce6e153fSAndrzej Hajda [MHL_XDC_ECBUS_SPEEDS] = MHL_XDC_ECBUS_S_075 1348ce6e153fSAndrzej Hajda | MHL_XDC_ECBUS_S_8BIT, 1349ce6e153fSAndrzej Hajda [MHL_XDC_TMDS_SPEEDS] = MHL_XDC_TMDS_150 1350ce6e153fSAndrzej Hajda | MHL_XDC_TMDS_300 | MHL_XDC_TMDS_600, 1351ce6e153fSAndrzej Hajda [MHL_XDC_ECBUS_ROLES] = MHL_XDC_DEV_HOST, 1352ce6e153fSAndrzej Hajda [MHL_XDC_LOG_DEV_MAPX] = MHL_XDC_LD_PHONE, 1353ce6e153fSAndrzej Hajda }; 1354ce6e153fSAndrzej Hajda 1355ce6e153fSAndrzej Hajda sii8620_write_buf(ctx, REG_MHL_DEVCAP_0, devcap, ARRAY_SIZE(devcap)); 1356ce6e153fSAndrzej Hajda sii8620_write_buf(ctx, REG_MHL_EXTDEVCAP_0, xdcap, ARRAY_SIZE(xdcap)); 1357ce6e153fSAndrzej Hajda } 1358ce6e153fSAndrzej Hajda 1359ce6e153fSAndrzej Hajda static void sii8620_mhl_init(struct sii8620 *ctx) 1360ce6e153fSAndrzej Hajda { 1361ce6e153fSAndrzej Hajda sii8620_write_seq_static(ctx, 1362ce6e153fSAndrzej Hajda REG_DISC_CTRL4, VAL_DISC_CTRL4(VAL_PUP_OFF, VAL_PUP_20K), 1363ce6e153fSAndrzej Hajda REG_CBUS_MSC_COMPAT_CTRL, 1364ce6e153fSAndrzej Hajda BIT_CBUS_MSC_COMPAT_CTRL_XDEVCAP_EN, 1365ce6e153fSAndrzej Hajda ); 1366ce6e153fSAndrzej Hajda 1367ce6e153fSAndrzej Hajda sii8620_peer_specific_init(ctx); 1368ce6e153fSAndrzej Hajda 1369ce6e153fSAndrzej Hajda sii8620_disable_hpd(ctx); 1370ce6e153fSAndrzej Hajda 1371ce6e153fSAndrzej Hajda sii8620_write_seq_static(ctx, 1372ce6e153fSAndrzej Hajda REG_EDID_CTRL, BIT_EDID_CTRL_EDID_FIFO_ADDR_AUTO, 1373ce6e153fSAndrzej Hajda REG_DISC_CTRL9, BIT_DISC_CTRL9_WAKE_DRVFLT 1374ce6e153fSAndrzej Hajda | BIT_DISC_CTRL9_WAKE_PULSE_BYPASS, 1375ce6e153fSAndrzej Hajda REG_TMDS0_CCTRL1, 0x90, 1376ce6e153fSAndrzej Hajda REG_TMDS_CLK_EN, 0x01, 1377ce6e153fSAndrzej Hajda REG_TMDS_CH_EN, 0x11, 1378ce6e153fSAndrzej Hajda REG_BGR_BIAS, 0x87, 1379ce6e153fSAndrzej Hajda REG_ALICE0_ZONE_CTRL, 0xE8, 1380ce6e153fSAndrzej Hajda REG_ALICE0_MODE_CTRL, 0x04, 1381ce6e153fSAndrzej Hajda ); 1382ce6e153fSAndrzej Hajda sii8620_setbits(ctx, REG_LM_DDC, BIT_LM_DDC_SW_TPI_EN_DISABLED, 0); 1383ce6e153fSAndrzej Hajda sii8620_write_seq_static(ctx, 1384ce6e153fSAndrzej Hajda REG_TPI_HW_OPT3, 0x76, 1385ce6e153fSAndrzej Hajda REG_TMDS_CCTRL, BIT_TMDS_CCTRL_TMDS_OE, 1386ce6e153fSAndrzej Hajda REG_TPI_DTD_B2, 79, 1387ce6e153fSAndrzej Hajda ); 1388ce6e153fSAndrzej Hajda sii8620_set_dev_cap(ctx); 1389ce6e153fSAndrzej Hajda sii8620_write_seq_static(ctx, 1390ce6e153fSAndrzej Hajda REG_MDT_XMIT_TIMEOUT, 100, 1391ce6e153fSAndrzej Hajda REG_MDT_XMIT_CTRL, 0x03, 1392ce6e153fSAndrzej Hajda REG_MDT_XFIFO_STAT, 0x00, 1393ce6e153fSAndrzej Hajda REG_MDT_RCV_TIMEOUT, 100, 1394ce6e153fSAndrzej Hajda REG_CBUS_LINK_CTRL_8, 0x1D, 1395ce6e153fSAndrzej Hajda ); 1396ce6e153fSAndrzej Hajda 1397ce6e153fSAndrzej Hajda sii8620_start_gen2_write_burst(ctx); 1398ce6e153fSAndrzej Hajda sii8620_write_seq_static(ctx, 1399ce6e153fSAndrzej Hajda REG_BIST_CTRL, 0x00, 1400ce6e153fSAndrzej Hajda REG_COC_CTL1, 0x10, 1401ce6e153fSAndrzej Hajda REG_COC_CTL2, 0x18, 1402ce6e153fSAndrzej Hajda REG_COC_CTLF, 0x07, 1403ce6e153fSAndrzej Hajda REG_COC_CTL11, 0xF8, 1404ce6e153fSAndrzej Hajda REG_COC_CTL17, 0x61, 1405ce6e153fSAndrzej Hajda REG_COC_CTL18, 0x46, 1406ce6e153fSAndrzej Hajda REG_COC_CTL19, 0x15, 1407ce6e153fSAndrzej Hajda REG_COC_CTL1A, 0x01, 1408ce6e153fSAndrzej Hajda REG_MHL_COC_CTL3, BIT_MHL_COC_CTL3_COC_AECHO_EN, 1409ce6e153fSAndrzej Hajda REG_MHL_COC_CTL4, 0x2D, 1410ce6e153fSAndrzej Hajda REG_MHL_COC_CTL5, 0xF9, 1411ce6e153fSAndrzej Hajda REG_MSC_HEARTBEAT_CTRL, 0x27, 1412ce6e153fSAndrzej Hajda ); 1413ce6e153fSAndrzej Hajda sii8620_disable_gen2_write_burst(ctx); 1414ce6e153fSAndrzej Hajda 14159fc6ade8SAndrzej Hajda sii8620_mt_write_stat(ctx, MHL_DST_REG(VERSION), SII8620_MHL_VERSION); 1416ce6e153fSAndrzej Hajda sii8620_mt_write_stat(ctx, MHL_DST_REG(CONNECTED_RDY), 1417ce6e153fSAndrzej Hajda MHL_DST_CONN_DCAP_RDY | MHL_DST_CONN_XDEVCAPP_SUPP 1418ce6e153fSAndrzej Hajda | MHL_DST_CONN_POW_STAT); 1419ce6e153fSAndrzej Hajda sii8620_mt_set_int(ctx, MHL_INT_REG(RCHANGE), MHL_INT_RC_DCAP_CHG); 1420ce6e153fSAndrzej Hajda } 1421ce6e153fSAndrzej Hajda 14222c8fb853SAndrzej Hajda static void sii8620_emsc_enable(struct sii8620 *ctx) 14232c8fb853SAndrzej Hajda { 14242c8fb853SAndrzej Hajda u8 reg; 14252c8fb853SAndrzej Hajda 14262c8fb853SAndrzej Hajda sii8620_setbits(ctx, REG_GENCTL, BIT_GENCTL_EMSC_EN 14272c8fb853SAndrzej Hajda | BIT_GENCTL_CLR_EMSC_RFIFO 14282c8fb853SAndrzej Hajda | BIT_GENCTL_CLR_EMSC_XFIFO, ~0); 14292c8fb853SAndrzej Hajda sii8620_setbits(ctx, REG_GENCTL, BIT_GENCTL_CLR_EMSC_RFIFO 14302c8fb853SAndrzej Hajda | BIT_GENCTL_CLR_EMSC_XFIFO, 0); 14312c8fb853SAndrzej Hajda sii8620_setbits(ctx, REG_COMMECNT, BIT_COMMECNT_I2C_TO_EMSC_EN, ~0); 14322c8fb853SAndrzej Hajda reg = sii8620_readb(ctx, REG_EMSCINTR); 14332c8fb853SAndrzej Hajda sii8620_write(ctx, REG_EMSCINTR, reg); 14342c8fb853SAndrzej Hajda sii8620_write(ctx, REG_EMSCINTRMASK, BIT_EMSCINTR_SPI_DVLD); 14352c8fb853SAndrzej Hajda } 14362c8fb853SAndrzej Hajda 14372c8fb853SAndrzej Hajda static int sii8620_wait_for_fsm_state(struct sii8620 *ctx, u8 state) 14382c8fb853SAndrzej Hajda { 14392c8fb853SAndrzej Hajda int i; 14402c8fb853SAndrzej Hajda 14412c8fb853SAndrzej Hajda for (i = 0; i < 10; ++i) { 14422c8fb853SAndrzej Hajda u8 s = sii8620_readb(ctx, REG_COC_STAT_0); 14432c8fb853SAndrzej Hajda 14442c8fb853SAndrzej Hajda if ((s & MSK_COC_STAT_0_FSM_STATE) == state) 14452c8fb853SAndrzej Hajda return 0; 14462c8fb853SAndrzej Hajda if (!(s & BIT_COC_STAT_0_PLL_LOCKED)) 14472c8fb853SAndrzej Hajda return -EBUSY; 14482c8fb853SAndrzej Hajda usleep_range(4000, 6000); 14492c8fb853SAndrzej Hajda } 14502c8fb853SAndrzej Hajda return -ETIMEDOUT; 14512c8fb853SAndrzej Hajda } 14522c8fb853SAndrzej Hajda 1453ce6e153fSAndrzej Hajda static void sii8620_set_mode(struct sii8620 *ctx, enum sii8620_mode mode) 1454ce6e153fSAndrzej Hajda { 14552c8fb853SAndrzej Hajda int ret; 14562c8fb853SAndrzej Hajda 1457ce6e153fSAndrzej Hajda if (ctx->mode == mode) 1458ce6e153fSAndrzej Hajda return; 1459ce6e153fSAndrzej Hajda 1460ce6e153fSAndrzej Hajda switch (mode) { 1461ce6e153fSAndrzej Hajda case CM_MHL1: 1462ce6e153fSAndrzej Hajda sii8620_write_seq_static(ctx, 1463ce6e153fSAndrzej Hajda REG_CBUS_MSC_COMPAT_CTRL, 0x02, 1464ce6e153fSAndrzej Hajda REG_M3_CTRL, VAL_M3_CTRL_MHL1_2_VALUE, 1465ce6e153fSAndrzej Hajda REG_DPD, BIT_DPD_PWRON_PLL | BIT_DPD_PDNTX12 1466ce6e153fSAndrzej Hajda | BIT_DPD_OSC_EN, 1467ce6e153fSAndrzej Hajda REG_COC_INTR_MASK, 0 1468ce6e153fSAndrzej Hajda ); 14692c8fb853SAndrzej Hajda ctx->mode = mode; 1470ce6e153fSAndrzej Hajda break; 1471ce6e153fSAndrzej Hajda case CM_MHL3: 1472dd123129SAndrzej Hajda sii8620_write(ctx, REG_M3_CTRL, VAL_M3_CTRL_MHL3_VALUE); 14732c8fb853SAndrzej Hajda ctx->mode = mode; 14742c8fb853SAndrzej Hajda return; 14752c8fb853SAndrzej Hajda case CM_ECBUS_S: 14762c8fb853SAndrzej Hajda sii8620_emsc_enable(ctx); 14772c8fb853SAndrzej Hajda sii8620_write_seq_static(ctx, 14782c8fb853SAndrzej Hajda REG_TTXSPINUMS, 4, 14792c8fb853SAndrzej Hajda REG_TRXSPINUMS, 4, 14802c8fb853SAndrzej Hajda REG_TTXHSICNUMS, 0x14, 14812c8fb853SAndrzej Hajda REG_TRXHSICNUMS, 0x14, 14822c8fb853SAndrzej Hajda REG_TTXTOTNUMS, 0x18, 14832c8fb853SAndrzej Hajda REG_TRXTOTNUMS, 0x18, 14842c8fb853SAndrzej Hajda REG_PWD_SRST, BIT_PWD_SRST_COC_DOC_RST 14852c8fb853SAndrzej Hajda | BIT_PWD_SRST_CBUS_RST_SW_EN, 14862c8fb853SAndrzej Hajda REG_MHL_COC_CTL1, 0xbd, 14872c8fb853SAndrzej Hajda REG_PWD_SRST, BIT_PWD_SRST_CBUS_RST_SW_EN, 14882c8fb853SAndrzej Hajda REG_COC_CTLB, 0x01, 14892c8fb853SAndrzej Hajda REG_COC_CTL0, 0x5c, 14902c8fb853SAndrzej Hajda REG_COC_CTL14, 0x03, 14912c8fb853SAndrzej Hajda REG_COC_CTL15, 0x80, 14922c8fb853SAndrzej Hajda REG_MHL_DP_CTL6, BIT_MHL_DP_CTL6_DP_TAP1_SGN 14932c8fb853SAndrzej Hajda | BIT_MHL_DP_CTL6_DP_TAP1_EN 14942c8fb853SAndrzej Hajda | BIT_MHL_DP_CTL6_DT_PREDRV_FEEDCAP_EN, 14952c8fb853SAndrzej Hajda REG_MHL_DP_CTL8, 0x03 14962c8fb853SAndrzej Hajda ); 14972c8fb853SAndrzej Hajda ret = sii8620_wait_for_fsm_state(ctx, 0x03); 14982c8fb853SAndrzej Hajda sii8620_write_seq_static(ctx, 14992c8fb853SAndrzej Hajda REG_COC_CTL14, 0x00, 15002c8fb853SAndrzej Hajda REG_COC_CTL15, 0x80 15012c8fb853SAndrzej Hajda ); 15022c8fb853SAndrzej Hajda if (!ret) 15032c8fb853SAndrzej Hajda sii8620_write(ctx, REG_CBUS3_CNVT, 0x85); 15042c8fb853SAndrzej Hajda else 15052c8fb853SAndrzej Hajda sii8620_disconnect(ctx); 1506dd123129SAndrzej Hajda return; 1507ce6e153fSAndrzej Hajda case CM_DISCONNECTED: 15082c8fb853SAndrzej Hajda ctx->mode = mode; 1509ce6e153fSAndrzej Hajda break; 1510ce6e153fSAndrzej Hajda default: 1511ce6e153fSAndrzej Hajda dev_err(ctx->dev, "%s mode %d not supported\n", __func__, mode); 1512ce6e153fSAndrzej Hajda break; 15133a81e960Skbuild test robot } 1514ce6e153fSAndrzej Hajda 1515ce6e153fSAndrzej Hajda sii8620_set_auto_zone(ctx); 1516ce6e153fSAndrzej Hajda 1517ce6e153fSAndrzej Hajda if (mode != CM_MHL1) 1518ce6e153fSAndrzej Hajda return; 1519ce6e153fSAndrzej Hajda 1520ce6e153fSAndrzej Hajda sii8620_write_seq_static(ctx, 1521ce6e153fSAndrzej Hajda REG_MHL_DP_CTL0, 0xBC, 1522ce6e153fSAndrzej Hajda REG_MHL_DP_CTL1, 0xBB, 1523ce6e153fSAndrzej Hajda REG_MHL_DP_CTL3, 0x48, 1524ce6e153fSAndrzej Hajda REG_MHL_DP_CTL5, 0x39, 1525ce6e153fSAndrzej Hajda REG_MHL_DP_CTL2, 0x2A, 1526ce6e153fSAndrzej Hajda REG_MHL_DP_CTL6, 0x2A, 1527ce6e153fSAndrzej Hajda REG_MHL_DP_CTL7, 0x08 1528ce6e153fSAndrzej Hajda ); 1529ce6e153fSAndrzej Hajda } 1530ce6e153fSAndrzej Hajda 1531ce6e153fSAndrzej Hajda static void sii8620_disconnect(struct sii8620 *ctx) 1532ce6e153fSAndrzej Hajda { 1533ce6e153fSAndrzej Hajda sii8620_disable_gen2_write_burst(ctx); 1534ce6e153fSAndrzej Hajda sii8620_stop_video(ctx); 1535003f9929SAndrzej Hajda msleep(100); 1536ce6e153fSAndrzej Hajda sii8620_cbus_reset(ctx); 1537ce6e153fSAndrzej Hajda sii8620_set_mode(ctx, CM_DISCONNECTED); 1538ce6e153fSAndrzej Hajda sii8620_write_seq_static(ctx, 1539003f9929SAndrzej Hajda REG_TX_ZONE_CTL1, 0, 1540003f9929SAndrzej Hajda REG_MHL_PLL_CTL0, 0x07, 1541ce6e153fSAndrzej Hajda REG_COC_CTL0, 0x40, 1542ce6e153fSAndrzej Hajda REG_CBUS3_CNVT, 0x84, 1543ce6e153fSAndrzej Hajda REG_COC_CTL14, 0x00, 1544ce6e153fSAndrzej Hajda REG_COC_CTL0, 0x40, 1545ce6e153fSAndrzej Hajda REG_HRXCTRL3, 0x07, 1546ce6e153fSAndrzej Hajda REG_MHL_PLL_CTL0, VAL_MHL_PLL_CTL0_HDMI_CLK_RATIO_1X 1547ce6e153fSAndrzej Hajda | BIT_MHL_PLL_CTL0_CRYSTAL_CLK_SEL 1548ce6e153fSAndrzej Hajda | BIT_MHL_PLL_CTL0_ZONE_MASK_OE, 1549ce6e153fSAndrzej Hajda REG_MHL_DP_CTL0, BIT_MHL_DP_CTL0_DP_OE 1550ce6e153fSAndrzej Hajda | BIT_MHL_DP_CTL0_TX_OE_OVR, 1551ce6e153fSAndrzej Hajda REG_MHL_DP_CTL1, 0xBB, 1552ce6e153fSAndrzej Hajda REG_MHL_DP_CTL3, 0x48, 1553ce6e153fSAndrzej Hajda REG_MHL_DP_CTL5, 0x3F, 1554ce6e153fSAndrzej Hajda REG_MHL_DP_CTL2, 0x2F, 1555ce6e153fSAndrzej Hajda REG_MHL_DP_CTL6, 0x2A, 1556ce6e153fSAndrzej Hajda REG_MHL_DP_CTL7, 0x03 1557ce6e153fSAndrzej Hajda ); 1558ce6e153fSAndrzej Hajda sii8620_disable_hpd(ctx); 1559ce6e153fSAndrzej Hajda sii8620_write_seq_static(ctx, 1560ce6e153fSAndrzej Hajda REG_M3_CTRL, VAL_M3_CTRL_MHL3_VALUE, 1561ce6e153fSAndrzej Hajda REG_MHL_COC_CTL1, 0x07, 1562ce6e153fSAndrzej Hajda REG_DISC_CTRL4, VAL_DISC_CTRL4(VAL_PUP_OFF, VAL_PUP_20K), 1563ce6e153fSAndrzej Hajda REG_DISC_CTRL8, 0x00, 1564ce6e153fSAndrzej Hajda REG_DISC_CTRL9, BIT_DISC_CTRL9_WAKE_DRVFLT 1565ce6e153fSAndrzej Hajda | BIT_DISC_CTRL9_WAKE_PULSE_BYPASS, 1566ce6e153fSAndrzej Hajda REG_INT_CTRL, 0x00, 1567ce6e153fSAndrzej Hajda REG_MSC_HEARTBEAT_CTRL, 0x27, 1568ce6e153fSAndrzej Hajda REG_DISC_CTRL1, 0x25, 1569ce6e153fSAndrzej Hajda REG_CBUS_DISC_INTR0, (u8)~BIT_RGND_READY_INT, 1570ce6e153fSAndrzej Hajda REG_CBUS_DISC_INTR0_MASK, BIT_RGND_READY_INT, 1571ce6e153fSAndrzej Hajda REG_MDT_INT_1, 0xff, 1572ce6e153fSAndrzej Hajda REG_MDT_INT_1_MASK, 0x00, 1573ce6e153fSAndrzej Hajda REG_MDT_INT_0, 0xff, 1574ce6e153fSAndrzej Hajda REG_MDT_INT_0_MASK, 0x00, 1575ce6e153fSAndrzej Hajda REG_COC_INTR, 0xff, 1576ce6e153fSAndrzej Hajda REG_COC_INTR_MASK, 0x00, 1577ce6e153fSAndrzej Hajda REG_TRXINTH, 0xff, 1578ce6e153fSAndrzej Hajda REG_TRXINTMH, 0x00, 1579ce6e153fSAndrzej Hajda REG_CBUS_INT_0, 0xff, 1580ce6e153fSAndrzej Hajda REG_CBUS_INT_0_MASK, 0x00, 1581ce6e153fSAndrzej Hajda REG_CBUS_INT_1, 0xff, 1582ce6e153fSAndrzej Hajda REG_CBUS_INT_1_MASK, 0x00, 1583ce6e153fSAndrzej Hajda REG_EMSCINTR, 0xff, 1584ce6e153fSAndrzej Hajda REG_EMSCINTRMASK, 0x00, 1585ce6e153fSAndrzej Hajda REG_EMSCINTR1, 0xff, 1586ce6e153fSAndrzej Hajda REG_EMSCINTRMASK1, 0x00, 1587ce6e153fSAndrzej Hajda REG_INTR8, 0xff, 1588ce6e153fSAndrzej Hajda REG_INTR8_MASK, 0x00, 1589ce6e153fSAndrzej Hajda REG_TPI_INTR_ST0, 0xff, 1590ce6e153fSAndrzej Hajda REG_TPI_INTR_EN, 0x00, 1591ce6e153fSAndrzej Hajda REG_HDCP2X_INTR0, 0xff, 1592ce6e153fSAndrzej Hajda REG_HDCP2X_INTR0_MASK, 0x00, 1593ce6e153fSAndrzej Hajda REG_INTR9, 0xff, 1594ce6e153fSAndrzej Hajda REG_INTR9_MASK, 0x00, 1595ce6e153fSAndrzej Hajda REG_INTR3, 0xff, 1596ce6e153fSAndrzej Hajda REG_INTR3_MASK, 0x00, 1597ce6e153fSAndrzej Hajda REG_INTR5, 0xff, 1598ce6e153fSAndrzej Hajda REG_INTR5_MASK, 0x00, 1599ce6e153fSAndrzej Hajda REG_INTR2, 0xff, 1600ce6e153fSAndrzej Hajda REG_INTR2_MASK, 0x00, 1601ce6e153fSAndrzej Hajda ); 1602ce6e153fSAndrzej Hajda memset(ctx->stat, 0, sizeof(ctx->stat)); 1603ce6e153fSAndrzej Hajda memset(ctx->xstat, 0, sizeof(ctx->xstat)); 1604ce6e153fSAndrzej Hajda memset(ctx->devcap, 0, sizeof(ctx->devcap)); 1605ce6e153fSAndrzej Hajda memset(ctx->xdevcap, 0, sizeof(ctx->xdevcap)); 1606ce6e153fSAndrzej Hajda ctx->cbus_status = 0; 1607ce6e153fSAndrzej Hajda ctx->sink_type = SINK_NONE; 1608ce6e153fSAndrzej Hajda kfree(ctx->edid); 1609ce6e153fSAndrzej Hajda ctx->edid = NULL; 1610ce6e153fSAndrzej Hajda sii8620_mt_cleanup(ctx); 1611ce6e153fSAndrzej Hajda } 1612ce6e153fSAndrzej Hajda 1613ce6e153fSAndrzej Hajda static void sii8620_mhl_disconnected(struct sii8620 *ctx) 1614ce6e153fSAndrzej Hajda { 1615ce6e153fSAndrzej Hajda sii8620_write_seq_static(ctx, 1616ce6e153fSAndrzej Hajda REG_DISC_CTRL4, VAL_DISC_CTRL4(VAL_PUP_OFF, VAL_PUP_20K), 1617ce6e153fSAndrzej Hajda REG_CBUS_MSC_COMPAT_CTRL, 1618ce6e153fSAndrzej Hajda BIT_CBUS_MSC_COMPAT_CTRL_XDEVCAP_EN 1619ce6e153fSAndrzej Hajda ); 1620ce6e153fSAndrzej Hajda sii8620_disconnect(ctx); 1621ce6e153fSAndrzej Hajda } 1622ce6e153fSAndrzej Hajda 1623ce6e153fSAndrzej Hajda static void sii8620_irq_disc(struct sii8620 *ctx) 1624ce6e153fSAndrzej Hajda { 1625ce6e153fSAndrzej Hajda u8 stat = sii8620_readb(ctx, REG_CBUS_DISC_INTR0); 1626ce6e153fSAndrzej Hajda 1627ce6e153fSAndrzej Hajda if (stat & VAL_CBUS_MHL_DISCON) 1628ce6e153fSAndrzej Hajda sii8620_mhl_disconnected(ctx); 1629ce6e153fSAndrzej Hajda 1630ce6e153fSAndrzej Hajda if (stat & BIT_RGND_READY_INT) { 1631ce6e153fSAndrzej Hajda u8 stat2 = sii8620_readb(ctx, REG_DISC_STAT2); 1632ce6e153fSAndrzej Hajda 1633ce6e153fSAndrzej Hajda if ((stat2 & MSK_DISC_STAT2_RGND) == VAL_RGND_1K) { 1634ce6e153fSAndrzej Hajda sii8620_mhl_discover(ctx); 1635ce6e153fSAndrzej Hajda } else { 1636ce6e153fSAndrzej Hajda sii8620_write_seq_static(ctx, 1637ce6e153fSAndrzej Hajda REG_DISC_CTRL9, BIT_DISC_CTRL9_WAKE_DRVFLT 1638ce6e153fSAndrzej Hajda | BIT_DISC_CTRL9_NOMHL_EST 1639ce6e153fSAndrzej Hajda | BIT_DISC_CTRL9_WAKE_PULSE_BYPASS, 1640ce6e153fSAndrzej Hajda REG_CBUS_DISC_INTR0_MASK, BIT_RGND_READY_INT 1641ce6e153fSAndrzej Hajda | BIT_CBUS_MHL3_DISCON_INT 1642ce6e153fSAndrzej Hajda | BIT_CBUS_MHL12_DISCON_INT 1643ce6e153fSAndrzej Hajda | BIT_NOT_MHL_EST_INT 1644ce6e153fSAndrzej Hajda ); 1645ce6e153fSAndrzej Hajda } 1646ce6e153fSAndrzej Hajda } 1647ce6e153fSAndrzej Hajda if (stat & BIT_MHL_EST_INT) 1648ce6e153fSAndrzej Hajda sii8620_mhl_init(ctx); 1649ce6e153fSAndrzej Hajda 1650ce6e153fSAndrzej Hajda sii8620_write(ctx, REG_CBUS_DISC_INTR0, stat); 1651ce6e153fSAndrzej Hajda } 1652ce6e153fSAndrzej Hajda 1653581a9237SAndrzej Hajda static void sii8620_read_burst(struct sii8620 *ctx) 1654581a9237SAndrzej Hajda { 1655581a9237SAndrzej Hajda u8 buf[17]; 1656581a9237SAndrzej Hajda 1657581a9237SAndrzej Hajda sii8620_read_buf(ctx, REG_MDT_RCV_READ_PORT, buf, ARRAY_SIZE(buf)); 1658581a9237SAndrzej Hajda sii8620_write(ctx, REG_MDT_RCV_CTRL, BIT_MDT_RCV_CTRL_MDT_RCV_EN | 1659581a9237SAndrzej Hajda BIT_MDT_RCV_CTRL_MDT_DELAY_RCV_EN | 1660581a9237SAndrzej Hajda BIT_MDT_RCV_CTRL_MDT_RFIFO_CLR_CUR); 1661581a9237SAndrzej Hajda sii8620_readb(ctx, REG_MDT_RFIFO_STAT); 1662581a9237SAndrzej Hajda } 1663581a9237SAndrzej Hajda 1664ce6e153fSAndrzej Hajda static void sii8620_irq_g2wb(struct sii8620 *ctx) 1665ce6e153fSAndrzej Hajda { 1666ce6e153fSAndrzej Hajda u8 stat = sii8620_readb(ctx, REG_MDT_INT_0); 1667ce6e153fSAndrzej Hajda 1668ce6e153fSAndrzej Hajda if (stat & BIT_MDT_IDLE_AFTER_HAWB_DISABLE) 1669581a9237SAndrzej Hajda if (sii8620_is_mhl3(ctx)) 1670581a9237SAndrzej Hajda sii8620_mt_set_int(ctx, MHL_INT_REG(RCHANGE), 1671581a9237SAndrzej Hajda MHL_INT_RC_FEAT_COMPLETE); 1672581a9237SAndrzej Hajda 1673581a9237SAndrzej Hajda if (stat & BIT_MDT_RFIFO_DATA_RDY) 1674581a9237SAndrzej Hajda sii8620_read_burst(ctx); 1675581a9237SAndrzej Hajda 1676581a9237SAndrzej Hajda if (stat & BIT_MDT_XFIFO_EMPTY) 1677581a9237SAndrzej Hajda sii8620_write(ctx, REG_MDT_XMIT_CTRL, 0); 1678ce6e153fSAndrzej Hajda 1679ce6e153fSAndrzej Hajda sii8620_write(ctx, REG_MDT_INT_0, stat); 1680ce6e153fSAndrzej Hajda } 1681ce6e153fSAndrzej Hajda 16829fc6ade8SAndrzej Hajda static void sii8620_status_dcap_ready(struct sii8620 *ctx) 1683ce6e153fSAndrzej Hajda { 16849fc6ade8SAndrzej Hajda enum sii8620_mode mode; 16859fc6ade8SAndrzej Hajda 16869fc6ade8SAndrzej Hajda mode = ctx->stat[MHL_DST_VERSION] >= 0x30 ? CM_MHL3 : CM_MHL1; 16879fc6ade8SAndrzej Hajda if (mode > ctx->mode) 16889fc6ade8SAndrzej Hajda sii8620_set_mode(ctx, mode); 1689ce6e153fSAndrzej Hajda sii8620_peer_specific_init(ctx); 1690ce6e153fSAndrzej Hajda sii8620_write(ctx, REG_INTR9_MASK, BIT_INTR9_DEVCAP_DONE 1691ce6e153fSAndrzej Hajda | BIT_INTR9_EDID_DONE | BIT_INTR9_EDID_ERROR); 1692ce6e153fSAndrzej Hajda } 1693ce6e153fSAndrzej Hajda 1694ce6e153fSAndrzej Hajda static void sii8620_status_changed_path(struct sii8620 *ctx) 1695ce6e153fSAndrzej Hajda { 1696ce6e153fSAndrzej Hajda if (ctx->stat[MHL_DST_LINK_MODE] & MHL_DST_LM_PATH_ENABLED) { 1697ce6e153fSAndrzej Hajda sii8620_mt_write_stat(ctx, MHL_DST_REG(LINK_MODE), 1698ce6e153fSAndrzej Hajda MHL_DST_LM_CLK_MODE_NORMAL 1699ce6e153fSAndrzej Hajda | MHL_DST_LM_PATH_ENABLED); 1700e3a65487SAndrzej Hajda if (!sii8620_is_mhl3(ctx)) 1701ce6e153fSAndrzej Hajda sii8620_mt_read_devcap(ctx, false); 17029a466cd1SAndrzej Hajda sii8620_mt_set_cont(ctx, sii8620_sink_detected); 1703ce6e153fSAndrzej Hajda } else { 1704ce6e153fSAndrzej Hajda sii8620_mt_write_stat(ctx, MHL_DST_REG(LINK_MODE), 1705ce6e153fSAndrzej Hajda MHL_DST_LM_CLK_MODE_NORMAL); 1706ce6e153fSAndrzej Hajda } 1707ce6e153fSAndrzej Hajda } 1708ce6e153fSAndrzej Hajda 1709ce6e153fSAndrzej Hajda static void sii8620_msc_mr_write_stat(struct sii8620 *ctx) 1710ce6e153fSAndrzej Hajda { 1711ce6e153fSAndrzej Hajda u8 st[MHL_DST_SIZE], xst[MHL_XDS_SIZE]; 1712ce6e153fSAndrzej Hajda 1713ce6e153fSAndrzej Hajda sii8620_read_buf(ctx, REG_MHL_STAT_0, st, MHL_DST_SIZE); 1714ce6e153fSAndrzej Hajda sii8620_read_buf(ctx, REG_MHL_EXTSTAT_0, xst, MHL_XDS_SIZE); 1715ce6e153fSAndrzej Hajda 1716ce6e153fSAndrzej Hajda sii8620_update_array(ctx->stat, st, MHL_DST_SIZE); 1717ce6e153fSAndrzej Hajda sii8620_update_array(ctx->xstat, xst, MHL_XDS_SIZE); 1718ce6e153fSAndrzej Hajda 17199fc6ade8SAndrzej Hajda if (ctx->stat[MHL_DST_CONNECTED_RDY] & MHL_DST_CONN_DCAP_RDY) 17209fc6ade8SAndrzej Hajda sii8620_status_dcap_ready(ctx); 1721ce6e153fSAndrzej Hajda 1722ce6e153fSAndrzej Hajda if (st[MHL_DST_LINK_MODE] & MHL_DST_LM_PATH_ENABLED) 1723ce6e153fSAndrzej Hajda sii8620_status_changed_path(ctx); 1724ce6e153fSAndrzej Hajda } 1725ce6e153fSAndrzej Hajda 17262c8fb853SAndrzej Hajda static void sii8620_ecbus_up(struct sii8620 *ctx, int ret) 17272c8fb853SAndrzej Hajda { 17282c8fb853SAndrzej Hajda if (ret < 0) 17292c8fb853SAndrzej Hajda return; 17302c8fb853SAndrzej Hajda 17312c8fb853SAndrzej Hajda sii8620_set_mode(ctx, CM_ECBUS_S); 17322c8fb853SAndrzej Hajda } 17332c8fb853SAndrzej Hajda 17342c8fb853SAndrzej Hajda static void sii8620_got_ecbus_speed(struct sii8620 *ctx, int ret) 17352c8fb853SAndrzej Hajda { 17362c8fb853SAndrzej Hajda if (ret < 0) 17372c8fb853SAndrzej Hajda return; 17382c8fb853SAndrzej Hajda 17392c8fb853SAndrzej Hajda sii8620_mt_write_stat(ctx, MHL_XDS_REG(CURR_ECBUS_MODE), 17402c8fb853SAndrzej Hajda MHL_XDS_ECBUS_S | MHL_XDS_SLOT_MODE_8BIT); 17412c8fb853SAndrzej Hajda sii8620_mt_rap(ctx, MHL_RAP_CBUS_MODE_UP); 17422c8fb853SAndrzej Hajda sii8620_mt_set_cont(ctx, sii8620_ecbus_up); 17432c8fb853SAndrzej Hajda } 17442c8fb853SAndrzej Hajda 1745269ed8eeSAndrzej Hajda static void sii8620_mhl_burst_emsc_support_set(struct mhl_burst_emsc_support *d, 1746269ed8eeSAndrzej Hajda enum mhl_burst_id id) 1747269ed8eeSAndrzej Hajda { 1748269ed8eeSAndrzej Hajda sii8620_mhl_burst_hdr_set(&d->hdr, MHL_BURST_ID_EMSC_SUPPORT); 1749269ed8eeSAndrzej Hajda d->num_entries = 1; 1750269ed8eeSAndrzej Hajda d->burst_id[0] = cpu_to_be16(id); 1751269ed8eeSAndrzej Hajda } 1752269ed8eeSAndrzej Hajda 1753269ed8eeSAndrzej Hajda static void sii8620_send_features(struct sii8620 *ctx) 1754269ed8eeSAndrzej Hajda { 1755269ed8eeSAndrzej Hajda u8 buf[16]; 1756269ed8eeSAndrzej Hajda 1757269ed8eeSAndrzej Hajda sii8620_write(ctx, REG_MDT_XMIT_CTRL, BIT_MDT_XMIT_CTRL_EN 1758269ed8eeSAndrzej Hajda | BIT_MDT_XMIT_CTRL_FIXED_BURST_LEN); 1759269ed8eeSAndrzej Hajda sii8620_mhl_burst_emsc_support_set((void *)buf, 1760269ed8eeSAndrzej Hajda MHL_BURST_ID_HID_PAYLOAD); 1761269ed8eeSAndrzej Hajda sii8620_write_buf(ctx, REG_MDT_XMIT_WRITE_PORT, buf, ARRAY_SIZE(buf)); 1762269ed8eeSAndrzej Hajda } 1763269ed8eeSAndrzej Hajda 1764e25f1f7cSMaciej Purski static bool sii8620_rcp_consume(struct sii8620 *ctx, u8 scancode) 1765e25f1f7cSMaciej Purski { 1766e25f1f7cSMaciej Purski bool pressed = !(scancode & MHL_RCP_KEY_RELEASED_MASK); 1767e25f1f7cSMaciej Purski 1768e25f1f7cSMaciej Purski scancode &= MHL_RCP_KEY_ID_MASK; 1769e25f1f7cSMaciej Purski 1770e25f1f7cSMaciej Purski if (!ctx->rc_dev) { 1771e25f1f7cSMaciej Purski dev_dbg(ctx->dev, "RCP input device not initialized\n"); 1772e25f1f7cSMaciej Purski return false; 1773e25f1f7cSMaciej Purski } 1774e25f1f7cSMaciej Purski 1775e25f1f7cSMaciej Purski if (pressed) 1776e25f1f7cSMaciej Purski rc_keydown(ctx->rc_dev, RC_PROTO_CEC, scancode, 0); 1777e25f1f7cSMaciej Purski else 1778e25f1f7cSMaciej Purski rc_keyup(ctx->rc_dev); 1779e25f1f7cSMaciej Purski 1780e25f1f7cSMaciej Purski return true; 1781e25f1f7cSMaciej Purski } 1782e25f1f7cSMaciej Purski 1783ce6e153fSAndrzej Hajda static void sii8620_msc_mr_set_int(struct sii8620 *ctx) 1784ce6e153fSAndrzej Hajda { 1785ce6e153fSAndrzej Hajda u8 ints[MHL_INT_SIZE]; 1786ce6e153fSAndrzej Hajda 1787ce6e153fSAndrzej Hajda sii8620_read_buf(ctx, REG_MHL_INT_0, ints, MHL_INT_SIZE); 1788ce6e153fSAndrzej Hajda sii8620_write_buf(ctx, REG_MHL_INT_0, ints, MHL_INT_SIZE); 17892c8fb853SAndrzej Hajda 17902c8fb853SAndrzej Hajda if (ints[MHL_INT_RCHANGE] & MHL_INT_RC_DCAP_CHG) { 17912c8fb853SAndrzej Hajda switch (ctx->mode) { 17922c8fb853SAndrzej Hajda case CM_MHL3: 17932c8fb853SAndrzej Hajda sii8620_mt_read_xdevcap_reg(ctx, MHL_XDC_ECBUS_SPEEDS); 17942c8fb853SAndrzej Hajda sii8620_mt_set_cont(ctx, sii8620_got_ecbus_speed); 17952c8fb853SAndrzej Hajda break; 17962c8fb853SAndrzej Hajda case CM_ECBUS_S: 17972c8fb853SAndrzej Hajda sii8620_mt_read_devcap(ctx, true); 17982c8fb853SAndrzej Hajda break; 17992c8fb853SAndrzej Hajda default: 18002c8fb853SAndrzej Hajda break; 18012c8fb853SAndrzej Hajda } 18022c8fb853SAndrzej Hajda } 1803269ed8eeSAndrzej Hajda if (ints[MHL_INT_RCHANGE] & MHL_INT_RC_FEAT_REQ) 1804269ed8eeSAndrzej Hajda sii8620_send_features(ctx); 1805269ed8eeSAndrzej Hajda if (ints[MHL_INT_RCHANGE] & MHL_INT_RC_FEAT_COMPLETE) 1806269ed8eeSAndrzej Hajda sii8620_edid_read(ctx, 0); 1807ce6e153fSAndrzej Hajda } 1808ce6e153fSAndrzej Hajda 1809ce6e153fSAndrzej Hajda static struct sii8620_mt_msg *sii8620_msc_msg_first(struct sii8620 *ctx) 1810ce6e153fSAndrzej Hajda { 1811ce6e153fSAndrzej Hajda struct device *dev = ctx->dev; 1812ce6e153fSAndrzej Hajda 1813ce6e153fSAndrzej Hajda if (list_empty(&ctx->mt_queue)) { 1814ce6e153fSAndrzej Hajda dev_err(dev, "unexpected MSC MT response\n"); 1815ce6e153fSAndrzej Hajda return NULL; 1816ce6e153fSAndrzej Hajda } 1817ce6e153fSAndrzej Hajda 1818ce6e153fSAndrzej Hajda return list_first_entry(&ctx->mt_queue, struct sii8620_mt_msg, node); 1819ce6e153fSAndrzej Hajda } 1820ce6e153fSAndrzej Hajda 1821ce6e153fSAndrzej Hajda static void sii8620_msc_mt_done(struct sii8620 *ctx) 1822ce6e153fSAndrzej Hajda { 1823ce6e153fSAndrzej Hajda struct sii8620_mt_msg *msg = sii8620_msc_msg_first(ctx); 1824ce6e153fSAndrzej Hajda 1825ce6e153fSAndrzej Hajda if (!msg) 1826ce6e153fSAndrzej Hajda return; 1827ce6e153fSAndrzej Hajda 1828ce6e153fSAndrzej Hajda msg->ret = sii8620_readb(ctx, REG_MSC_MT_RCVD_DATA0); 1829ce6e153fSAndrzej Hajda ctx->mt_state = MT_STATE_DONE; 1830ce6e153fSAndrzej Hajda } 1831ce6e153fSAndrzej Hajda 1832ce6e153fSAndrzej Hajda static void sii8620_msc_mr_msc_msg(struct sii8620 *ctx) 1833ce6e153fSAndrzej Hajda { 1834e25f1f7cSMaciej Purski struct sii8620_mt_msg *msg; 1835ce6e153fSAndrzej Hajda u8 buf[2]; 1836ce6e153fSAndrzej Hajda 1837ce6e153fSAndrzej Hajda sii8620_read_buf(ctx, REG_MSC_MR_MSC_MSG_RCVD_1ST_DATA, buf, 2); 1838ce6e153fSAndrzej Hajda 1839ce6e153fSAndrzej Hajda switch (buf[0]) { 1840ce6e153fSAndrzej Hajda case MHL_MSC_MSG_RAPK: 1841e25f1f7cSMaciej Purski msg = sii8620_msc_msg_first(ctx); 1842e25f1f7cSMaciej Purski if (!msg) 1843e25f1f7cSMaciej Purski return; 1844ce6e153fSAndrzej Hajda msg->ret = buf[1]; 1845ce6e153fSAndrzej Hajda ctx->mt_state = MT_STATE_DONE; 1846ce6e153fSAndrzej Hajda break; 1847e25f1f7cSMaciej Purski case MHL_MSC_MSG_RCP: 1848e25f1f7cSMaciej Purski if (!sii8620_rcp_consume(ctx, buf[1])) 1849e25f1f7cSMaciej Purski sii8620_mt_rcpe(ctx, 1850e25f1f7cSMaciej Purski MHL_RCPE_STATUS_INEFFECTIVE_KEY_CODE); 1851e25f1f7cSMaciej Purski sii8620_mt_rcpk(ctx, buf[1]); 1852e25f1f7cSMaciej Purski break; 1853ce6e153fSAndrzej Hajda default: 1854ce6e153fSAndrzej Hajda dev_err(ctx->dev, "%s message type %d,%d not supported", 1855ce6e153fSAndrzej Hajda __func__, buf[0], buf[1]); 1856ce6e153fSAndrzej Hajda } 1857ce6e153fSAndrzej Hajda } 1858ce6e153fSAndrzej Hajda 1859ce6e153fSAndrzej Hajda static void sii8620_irq_msc(struct sii8620 *ctx) 1860ce6e153fSAndrzej Hajda { 1861ce6e153fSAndrzej Hajda u8 stat = sii8620_readb(ctx, REG_CBUS_INT_0); 1862ce6e153fSAndrzej Hajda 1863ce6e153fSAndrzej Hajda if (stat & ~BIT_CBUS_HPD_CHG) 1864ce6e153fSAndrzej Hajda sii8620_write(ctx, REG_CBUS_INT_0, stat & ~BIT_CBUS_HPD_CHG); 1865ce6e153fSAndrzej Hajda 1866ce6e153fSAndrzej Hajda if (stat & BIT_CBUS_HPD_CHG) { 1867ce6e153fSAndrzej Hajda u8 cbus_stat = sii8620_readb(ctx, REG_CBUS_STATUS); 1868ce6e153fSAndrzej Hajda 1869ce6e153fSAndrzej Hajda if ((cbus_stat ^ ctx->cbus_status) & BIT_CBUS_STATUS_CBUS_HPD) { 1870ce6e153fSAndrzej Hajda sii8620_write(ctx, REG_CBUS_INT_0, BIT_CBUS_HPD_CHG); 1871ce6e153fSAndrzej Hajda } else { 1872ce6e153fSAndrzej Hajda stat ^= BIT_CBUS_STATUS_CBUS_HPD; 1873ce6e153fSAndrzej Hajda cbus_stat ^= BIT_CBUS_STATUS_CBUS_HPD; 1874ce6e153fSAndrzej Hajda } 1875ce6e153fSAndrzej Hajda ctx->cbus_status = cbus_stat; 1876ce6e153fSAndrzej Hajda } 1877ce6e153fSAndrzej Hajda 1878ce6e153fSAndrzej Hajda if (stat & BIT_CBUS_MSC_MR_WRITE_STAT) 1879ce6e153fSAndrzej Hajda sii8620_msc_mr_write_stat(ctx); 1880ce6e153fSAndrzej Hajda 1881ce6e153fSAndrzej Hajda if (stat & BIT_CBUS_MSC_MR_SET_INT) 1882ce6e153fSAndrzej Hajda sii8620_msc_mr_set_int(ctx); 1883ce6e153fSAndrzej Hajda 1884ce6e153fSAndrzej Hajda if (stat & BIT_CBUS_MSC_MT_DONE) 1885ce6e153fSAndrzej Hajda sii8620_msc_mt_done(ctx); 1886ce6e153fSAndrzej Hajda 1887ce6e153fSAndrzej Hajda if (stat & BIT_CBUS_MSC_MR_MSC_MSG) 1888ce6e153fSAndrzej Hajda sii8620_msc_mr_msc_msg(ctx); 1889ce6e153fSAndrzej Hajda } 1890ce6e153fSAndrzej Hajda 1891ce6e153fSAndrzej Hajda static void sii8620_irq_coc(struct sii8620 *ctx) 1892ce6e153fSAndrzej Hajda { 1893ce6e153fSAndrzej Hajda u8 stat = sii8620_readb(ctx, REG_COC_INTR); 1894ce6e153fSAndrzej Hajda 1895e19e9c69SAndrzej Hajda if (stat & BIT_COC_CALIBRATION_DONE) { 1896e19e9c69SAndrzej Hajda u8 cstat = sii8620_readb(ctx, REG_COC_STAT_0); 1897e19e9c69SAndrzej Hajda 1898e19e9c69SAndrzej Hajda cstat &= BIT_COC_STAT_0_PLL_LOCKED | MSK_COC_STAT_0_FSM_STATE; 1899e19e9c69SAndrzej Hajda if (cstat == (BIT_COC_STAT_0_PLL_LOCKED | 0x02)) { 1900e19e9c69SAndrzej Hajda sii8620_write_seq_static(ctx, 1901e19e9c69SAndrzej Hajda REG_COC_CTLB, 0, 1902e19e9c69SAndrzej Hajda REG_TRXINTMH, BIT_TDM_INTR_SYNC_DATA 1903e19e9c69SAndrzej Hajda | BIT_TDM_INTR_SYNC_WAIT 1904e19e9c69SAndrzej Hajda ); 1905e19e9c69SAndrzej Hajda } 1906e19e9c69SAndrzej Hajda } 1907e19e9c69SAndrzej Hajda 1908ce6e153fSAndrzej Hajda sii8620_write(ctx, REG_COC_INTR, stat); 1909ce6e153fSAndrzej Hajda } 1910ce6e153fSAndrzej Hajda 1911ce6e153fSAndrzej Hajda static void sii8620_irq_merr(struct sii8620 *ctx) 1912ce6e153fSAndrzej Hajda { 1913ce6e153fSAndrzej Hajda u8 stat = sii8620_readb(ctx, REG_CBUS_INT_1); 1914ce6e153fSAndrzej Hajda 1915ce6e153fSAndrzej Hajda sii8620_write(ctx, REG_CBUS_INT_1, stat); 1916ce6e153fSAndrzej Hajda } 1917ce6e153fSAndrzej Hajda 1918ce6e153fSAndrzej Hajda static void sii8620_irq_edid(struct sii8620 *ctx) 1919ce6e153fSAndrzej Hajda { 1920ce6e153fSAndrzej Hajda u8 stat = sii8620_readb(ctx, REG_INTR9); 1921ce6e153fSAndrzej Hajda 1922ce6e153fSAndrzej Hajda sii8620_write(ctx, REG_INTR9, stat); 1923ce6e153fSAndrzej Hajda 1924ce6e153fSAndrzej Hajda if (stat & BIT_INTR9_DEVCAP_DONE) 1925ce6e153fSAndrzej Hajda ctx->mt_state = MT_STATE_DONE; 1926ce6e153fSAndrzej Hajda } 1927ce6e153fSAndrzej Hajda 1928ce6e153fSAndrzej Hajda static void sii8620_scdt_high(struct sii8620 *ctx) 1929ce6e153fSAndrzej Hajda { 1930ce6e153fSAndrzej Hajda sii8620_write_seq_static(ctx, 1931ce6e153fSAndrzej Hajda REG_INTR8_MASK, BIT_CEA_NEW_AVI | BIT_CEA_NEW_VSI, 1932ce6e153fSAndrzej Hajda REG_TPI_SC, BIT_TPI_SC_TPI_OUTPUT_MODE_0_HDMI, 1933ce6e153fSAndrzej Hajda ); 1934ce6e153fSAndrzej Hajda } 1935ce6e153fSAndrzej Hajda 1936ce6e153fSAndrzej Hajda static void sii8620_irq_scdt(struct sii8620 *ctx) 1937ce6e153fSAndrzej Hajda { 1938ce6e153fSAndrzej Hajda u8 stat = sii8620_readb(ctx, REG_INTR5); 1939ce6e153fSAndrzej Hajda 1940ce6e153fSAndrzej Hajda if (stat & BIT_INTR_SCDT_CHANGE) { 1941ce6e153fSAndrzej Hajda u8 cstat = sii8620_readb(ctx, REG_TMDS_CSTAT_P3); 1942ce6e153fSAndrzej Hajda 1943*5c632e22SMaciej Purski if (cstat & BIT_TMDS_CSTAT_P3_SCDT) { 1944*5c632e22SMaciej Purski if (ctx->sink_type == SINK_HDMI) 1945*5c632e22SMaciej Purski /* enable infoframe interrupt */ 1946ce6e153fSAndrzej Hajda sii8620_scdt_high(ctx); 1947*5c632e22SMaciej Purski else 1948*5c632e22SMaciej Purski sii8620_start_video(ctx); 1949*5c632e22SMaciej Purski } 1950ce6e153fSAndrzej Hajda } 1951ce6e153fSAndrzej Hajda 1952ce6e153fSAndrzej Hajda sii8620_write(ctx, REG_INTR5, stat); 1953ce6e153fSAndrzej Hajda } 1954ce6e153fSAndrzej Hajda 1955ce6e153fSAndrzej Hajda static void sii8620_new_vsi(struct sii8620 *ctx) 1956ce6e153fSAndrzej Hajda { 1957ce6e153fSAndrzej Hajda u8 vsif[11]; 1958ce6e153fSAndrzej Hajda 1959ce6e153fSAndrzej Hajda sii8620_write(ctx, REG_RX_HDMI_CTRL2, 1960ce6e153fSAndrzej Hajda VAL_RX_HDMI_CTRL2_DEFVAL | 1961ce6e153fSAndrzej Hajda BIT_RX_HDMI_CTRL2_VSI_MON_SEL_VSI); 1962ce6e153fSAndrzej Hajda sii8620_read_buf(ctx, REG_RX_HDMI_MON_PKT_HEADER1, vsif, 1963ce6e153fSAndrzej Hajda ARRAY_SIZE(vsif)); 1964ce6e153fSAndrzej Hajda } 1965ce6e153fSAndrzej Hajda 1966ce6e153fSAndrzej Hajda static void sii8620_new_avi(struct sii8620 *ctx) 1967ce6e153fSAndrzej Hajda { 1968ce6e153fSAndrzej Hajda sii8620_write(ctx, REG_RX_HDMI_CTRL2, VAL_RX_HDMI_CTRL2_DEFVAL); 1969ce6e153fSAndrzej Hajda sii8620_read_buf(ctx, REG_RX_HDMI_MON_PKT_HEADER1, ctx->avif, 1970ce6e153fSAndrzej Hajda ARRAY_SIZE(ctx->avif)); 1971ce6e153fSAndrzej Hajda } 1972ce6e153fSAndrzej Hajda 1973ce6e153fSAndrzej Hajda static void sii8620_irq_infr(struct sii8620 *ctx) 1974ce6e153fSAndrzej Hajda { 1975ce6e153fSAndrzej Hajda u8 stat = sii8620_readb(ctx, REG_INTR8) 1976ce6e153fSAndrzej Hajda & (BIT_CEA_NEW_VSI | BIT_CEA_NEW_AVI); 1977ce6e153fSAndrzej Hajda 1978ce6e153fSAndrzej Hajda sii8620_write(ctx, REG_INTR8, stat); 1979ce6e153fSAndrzej Hajda 1980ce6e153fSAndrzej Hajda if (stat & BIT_CEA_NEW_VSI) 1981ce6e153fSAndrzej Hajda sii8620_new_vsi(ctx); 1982ce6e153fSAndrzej Hajda 1983ce6e153fSAndrzej Hajda if (stat & BIT_CEA_NEW_AVI) 1984ce6e153fSAndrzej Hajda sii8620_new_avi(ctx); 1985ce6e153fSAndrzej Hajda 1986ce6e153fSAndrzej Hajda if (stat & (BIT_CEA_NEW_VSI | BIT_CEA_NEW_AVI)) 1987ce6e153fSAndrzej Hajda sii8620_start_video(ctx); 1988ce6e153fSAndrzej Hajda } 1989ce6e153fSAndrzej Hajda 1990e3a65487SAndrzej Hajda static void sii8620_got_xdevcap(struct sii8620 *ctx, int ret) 1991e3a65487SAndrzej Hajda { 1992e3a65487SAndrzej Hajda if (ret < 0) 1993e3a65487SAndrzej Hajda return; 1994e3a65487SAndrzej Hajda 1995e3a65487SAndrzej Hajda sii8620_mt_read_devcap(ctx, false); 1996e3a65487SAndrzej Hajda } 1997e3a65487SAndrzej Hajda 1998e19e9c69SAndrzej Hajda static void sii8620_irq_tdm(struct sii8620 *ctx) 1999e19e9c69SAndrzej Hajda { 2000e19e9c69SAndrzej Hajda u8 stat = sii8620_readb(ctx, REG_TRXINTH); 2001e19e9c69SAndrzej Hajda u8 tdm = sii8620_readb(ctx, REG_TRXSTA2); 2002e19e9c69SAndrzej Hajda 2003e19e9c69SAndrzej Hajda if ((tdm & MSK_TDM_SYNCHRONIZED) == VAL_TDM_SYNCHRONIZED) { 2004e19e9c69SAndrzej Hajda ctx->mode = CM_ECBUS_S; 2005e19e9c69SAndrzej Hajda ctx->burst.rx_ack = 0; 2006e19e9c69SAndrzej Hajda ctx->burst.r_size = SII8620_BURST_BUF_LEN; 2007e19e9c69SAndrzej Hajda sii8620_burst_tx_rbuf_info(ctx, SII8620_BURST_BUF_LEN); 2008e19e9c69SAndrzej Hajda sii8620_mt_read_devcap(ctx, true); 2009e3a65487SAndrzej Hajda sii8620_mt_set_cont(ctx, sii8620_got_xdevcap); 2010e19e9c69SAndrzej Hajda } else { 2011e19e9c69SAndrzej Hajda sii8620_write_seq_static(ctx, 2012e19e9c69SAndrzej Hajda REG_MHL_PLL_CTL2, 0, 2013e19e9c69SAndrzej Hajda REG_MHL_PLL_CTL2, BIT_MHL_PLL_CTL2_CLKDETECT_EN 2014e19e9c69SAndrzej Hajda ); 2015e19e9c69SAndrzej Hajda } 2016e19e9c69SAndrzej Hajda 2017e19e9c69SAndrzej Hajda sii8620_write(ctx, REG_TRXINTH, stat); 2018e19e9c69SAndrzej Hajda } 2019e19e9c69SAndrzej Hajda 2020e19e9c69SAndrzej Hajda static void sii8620_irq_block(struct sii8620 *ctx) 2021e19e9c69SAndrzej Hajda { 2022e19e9c69SAndrzej Hajda u8 stat = sii8620_readb(ctx, REG_EMSCINTR); 2023e19e9c69SAndrzej Hajda 2024e19e9c69SAndrzej Hajda if (stat & BIT_EMSCINTR_SPI_DVLD) { 2025e19e9c69SAndrzej Hajda u8 bstat = sii8620_readb(ctx, REG_SPIBURSTSTAT); 2026e19e9c69SAndrzej Hajda 2027e19e9c69SAndrzej Hajda if (bstat & BIT_SPIBURSTSTAT_EMSC_NORMAL_MODE) 2028e19e9c69SAndrzej Hajda sii8620_burst_receive(ctx); 2029e19e9c69SAndrzej Hajda } 2030e19e9c69SAndrzej Hajda 2031e19e9c69SAndrzej Hajda sii8620_write(ctx, REG_EMSCINTR, stat); 2032e19e9c69SAndrzej Hajda } 2033e19e9c69SAndrzej Hajda 2034263b5c93SAndrzej Hajda static void sii8620_irq_ddc(struct sii8620 *ctx) 2035263b5c93SAndrzej Hajda { 2036263b5c93SAndrzej Hajda u8 stat = sii8620_readb(ctx, REG_INTR3); 2037263b5c93SAndrzej Hajda 2038263b5c93SAndrzej Hajda if (stat & BIT_DDC_CMD_DONE) { 2039263b5c93SAndrzej Hajda sii8620_write(ctx, REG_INTR3_MASK, 0); 2040263b5c93SAndrzej Hajda if (sii8620_is_mhl3(ctx)) 2041263b5c93SAndrzej Hajda sii8620_mt_set_int(ctx, MHL_INT_REG(RCHANGE), 2042263b5c93SAndrzej Hajda MHL_INT_RC_FEAT_REQ); 2043263b5c93SAndrzej Hajda else 2044263b5c93SAndrzej Hajda sii8620_edid_read(ctx, 0); 2045263b5c93SAndrzej Hajda } 2046263b5c93SAndrzej Hajda sii8620_write(ctx, REG_INTR3, stat); 2047263b5c93SAndrzej Hajda } 2048263b5c93SAndrzej Hajda 2049ce6e153fSAndrzej Hajda /* endian agnostic, non-volatile version of test_bit */ 2050ce6e153fSAndrzej Hajda static bool sii8620_test_bit(unsigned int nr, const u8 *addr) 2051ce6e153fSAndrzej Hajda { 2052ce6e153fSAndrzej Hajda return 1 & (addr[nr / BITS_PER_BYTE] >> (nr % BITS_PER_BYTE)); 2053ce6e153fSAndrzej Hajda } 2054ce6e153fSAndrzej Hajda 2055ce6e153fSAndrzej Hajda static irqreturn_t sii8620_irq_thread(int irq, void *data) 2056ce6e153fSAndrzej Hajda { 2057ce6e153fSAndrzej Hajda static const struct { 2058ce6e153fSAndrzej Hajda int bit; 2059ce6e153fSAndrzej Hajda void (*handler)(struct sii8620 *ctx); 2060ce6e153fSAndrzej Hajda } irq_vec[] = { 2061ce6e153fSAndrzej Hajda { BIT_FAST_INTR_STAT_DISC, sii8620_irq_disc }, 2062ce6e153fSAndrzej Hajda { BIT_FAST_INTR_STAT_G2WB, sii8620_irq_g2wb }, 2063ce6e153fSAndrzej Hajda { BIT_FAST_INTR_STAT_COC, sii8620_irq_coc }, 2064e19e9c69SAndrzej Hajda { BIT_FAST_INTR_STAT_TDM, sii8620_irq_tdm }, 2065ce6e153fSAndrzej Hajda { BIT_FAST_INTR_STAT_MSC, sii8620_irq_msc }, 2066ce6e153fSAndrzej Hajda { BIT_FAST_INTR_STAT_MERR, sii8620_irq_merr }, 2067e19e9c69SAndrzej Hajda { BIT_FAST_INTR_STAT_BLOCK, sii8620_irq_block }, 2068ce6e153fSAndrzej Hajda { BIT_FAST_INTR_STAT_EDID, sii8620_irq_edid }, 2069263b5c93SAndrzej Hajda { BIT_FAST_INTR_STAT_DDC, sii8620_irq_ddc }, 2070ce6e153fSAndrzej Hajda { BIT_FAST_INTR_STAT_SCDT, sii8620_irq_scdt }, 2071ce6e153fSAndrzej Hajda { BIT_FAST_INTR_STAT_INFR, sii8620_irq_infr }, 2072ce6e153fSAndrzej Hajda }; 2073ce6e153fSAndrzej Hajda struct sii8620 *ctx = data; 2074ce6e153fSAndrzej Hajda u8 stats[LEN_FAST_INTR_STAT]; 2075ce6e153fSAndrzej Hajda int i, ret; 2076ce6e153fSAndrzej Hajda 2077ce6e153fSAndrzej Hajda mutex_lock(&ctx->lock); 2078ce6e153fSAndrzej Hajda 2079ce6e153fSAndrzej Hajda sii8620_read_buf(ctx, REG_FAST_INTR_STAT, stats, ARRAY_SIZE(stats)); 2080ce6e153fSAndrzej Hajda for (i = 0; i < ARRAY_SIZE(irq_vec); ++i) 2081ce6e153fSAndrzej Hajda if (sii8620_test_bit(irq_vec[i].bit, stats)) 2082ce6e153fSAndrzej Hajda irq_vec[i].handler(ctx); 2083ce6e153fSAndrzej Hajda 2084e19e9c69SAndrzej Hajda sii8620_burst_rx_all(ctx); 2085ce6e153fSAndrzej Hajda sii8620_mt_work(ctx); 2086e19e9c69SAndrzej Hajda sii8620_burst_send(ctx); 2087ce6e153fSAndrzej Hajda 2088ce6e153fSAndrzej Hajda ret = sii8620_clear_error(ctx); 2089ce6e153fSAndrzej Hajda if (ret) { 2090ce6e153fSAndrzej Hajda dev_err(ctx->dev, "Error during IRQ handling, %d.\n", ret); 2091ce6e153fSAndrzej Hajda sii8620_mhl_disconnected(ctx); 2092ce6e153fSAndrzej Hajda } 2093ce6e153fSAndrzej Hajda mutex_unlock(&ctx->lock); 2094ce6e153fSAndrzej Hajda 2095ce6e153fSAndrzej Hajda return IRQ_HANDLED; 2096ce6e153fSAndrzej Hajda } 2097ce6e153fSAndrzej Hajda 2098ce6e153fSAndrzej Hajda static void sii8620_cable_in(struct sii8620 *ctx) 2099ce6e153fSAndrzej Hajda { 2100ce6e153fSAndrzej Hajda struct device *dev = ctx->dev; 2101ce6e153fSAndrzej Hajda u8 ver[5]; 2102ce6e153fSAndrzej Hajda int ret; 2103ce6e153fSAndrzej Hajda 2104ce6e153fSAndrzej Hajda ret = sii8620_hw_on(ctx); 2105ce6e153fSAndrzej Hajda if (ret) { 2106ce6e153fSAndrzej Hajda dev_err(dev, "Error powering on, %d.\n", ret); 2107ce6e153fSAndrzej Hajda return; 2108ce6e153fSAndrzej Hajda } 2109ce6e153fSAndrzej Hajda sii8620_hw_reset(ctx); 2110ce6e153fSAndrzej Hajda 2111ce6e153fSAndrzej Hajda sii8620_read_buf(ctx, REG_VND_IDL, ver, ARRAY_SIZE(ver)); 2112ce6e153fSAndrzej Hajda ret = sii8620_clear_error(ctx); 2113ce6e153fSAndrzej Hajda if (ret) { 2114ce6e153fSAndrzej Hajda dev_err(dev, "Error accessing I2C bus, %d.\n", ret); 2115ce6e153fSAndrzej Hajda return; 2116ce6e153fSAndrzej Hajda } 2117ce6e153fSAndrzej Hajda 2118ce6e153fSAndrzej Hajda dev_info(dev, "ChipID %02x%02x:%02x%02x rev %02x.\n", ver[1], ver[0], 2119ce6e153fSAndrzej Hajda ver[3], ver[2], ver[4]); 2120ce6e153fSAndrzej Hajda 2121ce6e153fSAndrzej Hajda sii8620_write(ctx, REG_DPD, 2122ce6e153fSAndrzej Hajda BIT_DPD_PWRON_PLL | BIT_DPD_PDNTX12 | BIT_DPD_OSC_EN); 2123ce6e153fSAndrzej Hajda 2124ce6e153fSAndrzej Hajda sii8620_xtal_set_rate(ctx); 2125ce6e153fSAndrzej Hajda sii8620_disconnect(ctx); 2126ce6e153fSAndrzej Hajda 2127ce6e153fSAndrzej Hajda sii8620_write_seq_static(ctx, 2128ce6e153fSAndrzej Hajda REG_MHL_CBUS_CTL0, VAL_MHL_CBUS_CTL0_CBUS_DRV_SEL_STRONG 2129ce6e153fSAndrzej Hajda | VAL_MHL_CBUS_CTL0_CBUS_RGND_VBIAS_734, 2130ce6e153fSAndrzej Hajda REG_MHL_CBUS_CTL1, VAL_MHL_CBUS_CTL1_1115_OHM, 2131ce6e153fSAndrzej Hajda REG_DPD, BIT_DPD_PWRON_PLL | BIT_DPD_PDNTX12 | BIT_DPD_OSC_EN, 2132ce6e153fSAndrzej Hajda ); 2133ce6e153fSAndrzej Hajda 2134ce6e153fSAndrzej Hajda ret = sii8620_clear_error(ctx); 2135ce6e153fSAndrzej Hajda if (ret) { 2136ce6e153fSAndrzej Hajda dev_err(dev, "Error accessing I2C bus, %d.\n", ret); 2137ce6e153fSAndrzej Hajda return; 2138ce6e153fSAndrzej Hajda } 2139ce6e153fSAndrzej Hajda 2140ce6e153fSAndrzej Hajda enable_irq(to_i2c_client(ctx->dev)->irq); 2141ce6e153fSAndrzej Hajda } 2142ce6e153fSAndrzej Hajda 2143e25f1f7cSMaciej Purski static void sii8620_init_rcp_input_dev(struct sii8620 *ctx) 2144e25f1f7cSMaciej Purski { 2145e25f1f7cSMaciej Purski struct rc_dev *rc_dev; 2146e25f1f7cSMaciej Purski int ret; 2147e25f1f7cSMaciej Purski 2148e25f1f7cSMaciej Purski rc_dev = rc_allocate_device(RC_DRIVER_SCANCODE); 2149e25f1f7cSMaciej Purski if (!rc_dev) { 2150e25f1f7cSMaciej Purski dev_err(ctx->dev, "Failed to allocate RC device\n"); 2151e25f1f7cSMaciej Purski ctx->error = -ENOMEM; 2152e25f1f7cSMaciej Purski return; 2153e25f1f7cSMaciej Purski } 2154e25f1f7cSMaciej Purski 2155e25f1f7cSMaciej Purski rc_dev->input_phys = "sii8620/input0"; 2156e25f1f7cSMaciej Purski rc_dev->input_id.bustype = BUS_VIRTUAL; 2157e25f1f7cSMaciej Purski rc_dev->map_name = RC_MAP_CEC; 2158e25f1f7cSMaciej Purski rc_dev->allowed_protocols = RC_PROTO_BIT_CEC; 2159e25f1f7cSMaciej Purski rc_dev->driver_name = "sii8620"; 2160e25f1f7cSMaciej Purski rc_dev->device_name = "sii8620"; 2161e25f1f7cSMaciej Purski 2162e25f1f7cSMaciej Purski ret = rc_register_device(rc_dev); 2163e25f1f7cSMaciej Purski 2164e25f1f7cSMaciej Purski if (ret) { 2165e25f1f7cSMaciej Purski dev_err(ctx->dev, "Failed to register RC device\n"); 2166e25f1f7cSMaciej Purski ctx->error = ret; 2167e25f1f7cSMaciej Purski rc_free_device(ctx->rc_dev); 2168e25f1f7cSMaciej Purski return; 2169e25f1f7cSMaciej Purski } 2170e25f1f7cSMaciej Purski ctx->rc_dev = rc_dev; 2171e25f1f7cSMaciej Purski } 2172e25f1f7cSMaciej Purski 2173ce6e153fSAndrzej Hajda static inline struct sii8620 *bridge_to_sii8620(struct drm_bridge *bridge) 2174ce6e153fSAndrzej Hajda { 2175ce6e153fSAndrzej Hajda return container_of(bridge, struct sii8620, bridge); 2176ce6e153fSAndrzej Hajda } 2177ce6e153fSAndrzej Hajda 2178e25f1f7cSMaciej Purski static int sii8620_attach(struct drm_bridge *bridge) 2179e25f1f7cSMaciej Purski { 2180e25f1f7cSMaciej Purski struct sii8620 *ctx = bridge_to_sii8620(bridge); 2181e25f1f7cSMaciej Purski 2182e25f1f7cSMaciej Purski sii8620_init_rcp_input_dev(ctx); 2183e25f1f7cSMaciej Purski 2184e25f1f7cSMaciej Purski return sii8620_clear_error(ctx); 2185e25f1f7cSMaciej Purski } 2186e25f1f7cSMaciej Purski 2187e25f1f7cSMaciej Purski static void sii8620_detach(struct drm_bridge *bridge) 2188e25f1f7cSMaciej Purski { 2189e25f1f7cSMaciej Purski struct sii8620 *ctx = bridge_to_sii8620(bridge); 2190e25f1f7cSMaciej Purski 2191e25f1f7cSMaciej Purski rc_unregister_device(ctx->rc_dev); 2192e25f1f7cSMaciej Purski } 2193e25f1f7cSMaciej Purski 2194e7c2e4d3SMarek Szyprowski static enum drm_mode_status sii8620_mode_valid(struct drm_bridge *bridge, 2195e7c2e4d3SMarek Szyprowski const struct drm_display_mode *mode) 2196e7c2e4d3SMarek Szyprowski { 2197e7c2e4d3SMarek Szyprowski struct sii8620 *ctx = bridge_to_sii8620(bridge); 2198e7c2e4d3SMarek Szyprowski bool can_pack = ctx->devcap[MHL_DCAP_VID_LINK_MODE] & 2199e7c2e4d3SMarek Szyprowski MHL_DCAP_VID_LINK_PPIXEL; 2200e7c2e4d3SMarek Szyprowski unsigned int max_pclk = sii8620_is_mhl3(ctx) ? MHL3_MAX_LCLK : 2201e7c2e4d3SMarek Szyprowski MHL1_MAX_LCLK; 2202e7c2e4d3SMarek Szyprowski max_pclk /= can_pack ? 2 : 3; 2203e7c2e4d3SMarek Szyprowski 2204e7c2e4d3SMarek Szyprowski return (mode->clock > max_pclk) ? MODE_CLOCK_HIGH : MODE_OK; 2205e7c2e4d3SMarek Szyprowski } 2206e7c2e4d3SMarek Szyprowski 2207ce6e153fSAndrzej Hajda static bool sii8620_mode_fixup(struct drm_bridge *bridge, 2208ce6e153fSAndrzej Hajda const struct drm_display_mode *mode, 2209ce6e153fSAndrzej Hajda struct drm_display_mode *adjusted_mode) 2210ce6e153fSAndrzej Hajda { 2211ce6e153fSAndrzej Hajda struct sii8620 *ctx = bridge_to_sii8620(bridge); 2212bf1722caSAndrzej Hajda int max_lclk; 2213bf1722caSAndrzej Hajda bool ret = true; 2214bf1722caSAndrzej Hajda 2215ce6e153fSAndrzej Hajda mutex_lock(&ctx->lock); 2216ce6e153fSAndrzej Hajda 2217bf1722caSAndrzej Hajda max_lclk = sii8620_is_mhl3(ctx) ? MHL3_MAX_LCLK : MHL1_MAX_LCLK; 2218bf1722caSAndrzej Hajda if (max_lclk > 3 * adjusted_mode->clock) { 2219bf1722caSAndrzej Hajda ctx->use_packed_pixel = 0; 2220bf1722caSAndrzej Hajda goto end; 2221bf1722caSAndrzej Hajda } 2222bf1722caSAndrzej Hajda if ((ctx->devcap[MHL_DCAP_VID_LINK_MODE] & MHL_DCAP_VID_LINK_PPIXEL) && 2223bf1722caSAndrzej Hajda max_lclk > 2 * adjusted_mode->clock) { 2224bf1722caSAndrzej Hajda ctx->use_packed_pixel = 1; 2225bf1722caSAndrzej Hajda goto end; 2226bf1722caSAndrzej Hajda } 2227bf1722caSAndrzej Hajda ret = false; 2228bf1722caSAndrzej Hajda end: 2229bf1722caSAndrzej Hajda if (ret) { 2230bf1722caSAndrzej Hajda u8 vic = drm_match_cea_mode(adjusted_mode); 2231ce6e153fSAndrzej Hajda 2232bf1722caSAndrzej Hajda if (!vic) { 2233bf1722caSAndrzej Hajda union hdmi_infoframe frm; 2234bf1722caSAndrzej Hajda u8 mhl_vic[] = { 0, 95, 94, 93, 98 }; 2235ce6e153fSAndrzej Hajda 2236bf1722caSAndrzej Hajda drm_hdmi_vendor_infoframe_from_display_mode( 2237bf1722caSAndrzej Hajda &frm.vendor.hdmi, adjusted_mode); 2238bf1722caSAndrzej Hajda vic = frm.vendor.hdmi.vic; 2239bf1722caSAndrzej Hajda if (vic >= ARRAY_SIZE(mhl_vic)) 2240bf1722caSAndrzej Hajda vic = 0; 2241bf1722caSAndrzej Hajda vic = mhl_vic[vic]; 2242bf1722caSAndrzej Hajda } 2243bf1722caSAndrzej Hajda ctx->video_code = vic; 2244bf1722caSAndrzej Hajda ctx->pixel_clock = adjusted_mode->clock; 2245bf1722caSAndrzej Hajda } 2246ce6e153fSAndrzej Hajda mutex_unlock(&ctx->lock); 2247ce6e153fSAndrzej Hajda return ret; 2248ce6e153fSAndrzej Hajda } 2249ce6e153fSAndrzej Hajda 2250ce6e153fSAndrzej Hajda static const struct drm_bridge_funcs sii8620_bridge_funcs = { 2251e25f1f7cSMaciej Purski .attach = sii8620_attach, 2252e25f1f7cSMaciej Purski .detach = sii8620_detach, 2253ce6e153fSAndrzej Hajda .mode_fixup = sii8620_mode_fixup, 2254e7c2e4d3SMarek Szyprowski .mode_valid = sii8620_mode_valid, 2255ce6e153fSAndrzej Hajda }; 2256ce6e153fSAndrzej Hajda 2257ce6e153fSAndrzej Hajda static int sii8620_probe(struct i2c_client *client, 2258ce6e153fSAndrzej Hajda const struct i2c_device_id *id) 2259ce6e153fSAndrzej Hajda { 2260ce6e153fSAndrzej Hajda struct device *dev = &client->dev; 2261ce6e153fSAndrzej Hajda struct sii8620 *ctx; 2262ce6e153fSAndrzej Hajda int ret; 2263ce6e153fSAndrzej Hajda 2264ce6e153fSAndrzej Hajda ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); 2265ce6e153fSAndrzej Hajda if (!ctx) 2266ce6e153fSAndrzej Hajda return -ENOMEM; 2267ce6e153fSAndrzej Hajda 2268ce6e153fSAndrzej Hajda ctx->dev = dev; 2269ce6e153fSAndrzej Hajda mutex_init(&ctx->lock); 2270ce6e153fSAndrzej Hajda INIT_LIST_HEAD(&ctx->mt_queue); 2271ce6e153fSAndrzej Hajda 2272ce6e153fSAndrzej Hajda ctx->clk_xtal = devm_clk_get(dev, "xtal"); 2273ce6e153fSAndrzej Hajda if (IS_ERR(ctx->clk_xtal)) { 2274ce6e153fSAndrzej Hajda dev_err(dev, "failed to get xtal clock from DT\n"); 2275ce6e153fSAndrzej Hajda return PTR_ERR(ctx->clk_xtal); 2276ce6e153fSAndrzej Hajda } 2277ce6e153fSAndrzej Hajda 2278ce6e153fSAndrzej Hajda if (!client->irq) { 2279ce6e153fSAndrzej Hajda dev_err(dev, "no irq provided\n"); 2280ce6e153fSAndrzej Hajda return -EINVAL; 2281ce6e153fSAndrzej Hajda } 2282ce6e153fSAndrzej Hajda irq_set_status_flags(client->irq, IRQ_NOAUTOEN); 2283ce6e153fSAndrzej Hajda ret = devm_request_threaded_irq(dev, client->irq, NULL, 2284ce6e153fSAndrzej Hajda sii8620_irq_thread, 2285ce6e153fSAndrzej Hajda IRQF_TRIGGER_HIGH | IRQF_ONESHOT, 2286ce6e153fSAndrzej Hajda "sii8620", ctx); 2287e0ba12eaSAndrzej Hajda if (ret < 0) { 2288e0ba12eaSAndrzej Hajda dev_err(dev, "failed to install IRQ handler\n"); 2289e0ba12eaSAndrzej Hajda return ret; 2290e0ba12eaSAndrzej Hajda } 2291ce6e153fSAndrzej Hajda 2292ce6e153fSAndrzej Hajda ctx->gpio_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); 2293ce6e153fSAndrzej Hajda if (IS_ERR(ctx->gpio_reset)) { 2294ce6e153fSAndrzej Hajda dev_err(dev, "failed to get reset gpio from DT\n"); 2295ce6e153fSAndrzej Hajda return PTR_ERR(ctx->gpio_reset); 2296ce6e153fSAndrzej Hajda } 2297ce6e153fSAndrzej Hajda 2298ce6e153fSAndrzej Hajda ctx->supplies[0].supply = "cvcc10"; 2299ce6e153fSAndrzej Hajda ctx->supplies[1].supply = "iovcc18"; 2300ce6e153fSAndrzej Hajda ret = devm_regulator_bulk_get(dev, 2, ctx->supplies); 2301ce6e153fSAndrzej Hajda if (ret) 2302ce6e153fSAndrzej Hajda return ret; 2303ce6e153fSAndrzej Hajda 2304ce6e153fSAndrzej Hajda i2c_set_clientdata(client, ctx); 2305ce6e153fSAndrzej Hajda 2306ce6e153fSAndrzej Hajda ctx->bridge.funcs = &sii8620_bridge_funcs; 2307ce6e153fSAndrzej Hajda ctx->bridge.of_node = dev->of_node; 2308ce6e153fSAndrzej Hajda drm_bridge_add(&ctx->bridge); 2309ce6e153fSAndrzej Hajda 2310ce6e153fSAndrzej Hajda sii8620_cable_in(ctx); 2311ce6e153fSAndrzej Hajda 2312ce6e153fSAndrzej Hajda return 0; 2313ce6e153fSAndrzej Hajda } 2314ce6e153fSAndrzej Hajda 2315ce6e153fSAndrzej Hajda static int sii8620_remove(struct i2c_client *client) 2316ce6e153fSAndrzej Hajda { 2317ce6e153fSAndrzej Hajda struct sii8620 *ctx = i2c_get_clientdata(client); 2318ce6e153fSAndrzej Hajda 2319ce6e153fSAndrzej Hajda disable_irq(to_i2c_client(ctx->dev)->irq); 2320ce6e153fSAndrzej Hajda sii8620_hw_off(ctx); 2321e25f1f7cSMaciej Purski drm_bridge_remove(&ctx->bridge); 2322ce6e153fSAndrzej Hajda 2323ce6e153fSAndrzej Hajda return 0; 2324ce6e153fSAndrzej Hajda } 2325ce6e153fSAndrzej Hajda 2326ce6e153fSAndrzej Hajda static const struct of_device_id sii8620_dt_match[] = { 2327ce6e153fSAndrzej Hajda { .compatible = "sil,sii8620" }, 2328ce6e153fSAndrzej Hajda { }, 2329ce6e153fSAndrzej Hajda }; 2330ce6e153fSAndrzej Hajda MODULE_DEVICE_TABLE(of, sii8620_dt_match); 2331ce6e153fSAndrzej Hajda 2332ce6e153fSAndrzej Hajda static const struct i2c_device_id sii8620_id[] = { 2333ce6e153fSAndrzej Hajda { "sii8620", 0 }, 2334ce6e153fSAndrzej Hajda { }, 2335ce6e153fSAndrzej Hajda }; 2336ce6e153fSAndrzej Hajda 2337ce6e153fSAndrzej Hajda MODULE_DEVICE_TABLE(i2c, sii8620_id); 2338ce6e153fSAndrzej Hajda static struct i2c_driver sii8620_driver = { 2339ce6e153fSAndrzej Hajda .driver = { 2340ce6e153fSAndrzej Hajda .name = "sii8620", 2341ce6e153fSAndrzej Hajda .of_match_table = of_match_ptr(sii8620_dt_match), 2342ce6e153fSAndrzej Hajda }, 2343ce6e153fSAndrzej Hajda .probe = sii8620_probe, 2344ce6e153fSAndrzej Hajda .remove = sii8620_remove, 2345ce6e153fSAndrzej Hajda .id_table = sii8620_id, 2346ce6e153fSAndrzej Hajda }; 2347ce6e153fSAndrzej Hajda 2348ce6e153fSAndrzej Hajda module_i2c_driver(sii8620_driver); 2349ce6e153fSAndrzej Hajda MODULE_LICENSE("GPL v2"); 2350