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