1*04972362SLiu Ying // SPDX-License-Identifier: GPL-2.0 2*04972362SLiu Ying /* 3*04972362SLiu Ying * Copyright 2024 NXP 4*04972362SLiu Ying */ 5*04972362SLiu Ying 6*04972362SLiu Ying #include <linux/bitfield.h> 7*04972362SLiu Ying #include <linux/bits.h> 8*04972362SLiu Ying #include <linux/delay.h> 9*04972362SLiu Ying #include <linux/gpio/consumer.h> 10*04972362SLiu Ying #include <linux/hdmi.h> 11*04972362SLiu Ying #include <linux/i2c.h> 12*04972362SLiu Ying #include <linux/media-bus-format.h> 13*04972362SLiu Ying #include <linux/module.h> 14*04972362SLiu Ying #include <linux/of.h> 15*04972362SLiu Ying #include <linux/regmap.h> 16*04972362SLiu Ying #include <linux/regulator/consumer.h> 17*04972362SLiu Ying 18*04972362SLiu Ying #include <drm/display/drm_hdmi_helper.h> 19*04972362SLiu Ying #include <drm/display/drm_hdmi_state_helper.h> 20*04972362SLiu Ying #include <drm/drm_atomic.h> 21*04972362SLiu Ying #include <drm/drm_atomic_helper.h> 22*04972362SLiu Ying #include <drm/drm_atomic_state_helper.h> 23*04972362SLiu Ying #include <drm/drm_bridge.h> 24*04972362SLiu Ying #include <drm/drm_bridge_connector.h> 25*04972362SLiu Ying #include <drm/drm_connector.h> 26*04972362SLiu Ying #include <drm/drm_crtc.h> 27*04972362SLiu Ying #include <drm/drm_edid.h> 28*04972362SLiu Ying #include <drm/drm_of.h> 29*04972362SLiu Ying #include <drm/drm_probe_helper.h> 30*04972362SLiu Ying 31*04972362SLiu Ying /* ----------------------------------------------------------------------------- 32*04972362SLiu Ying * LVDS registers 33*04972362SLiu Ying */ 34*04972362SLiu Ying 35*04972362SLiu Ying /* LVDS software reset registers */ 36*04972362SLiu Ying #define LVDS_REG_05 0x05 37*04972362SLiu Ying #define REG_SOFT_P_RST BIT(1) 38*04972362SLiu Ying 39*04972362SLiu Ying /* LVDS system configuration registers */ 40*04972362SLiu Ying /* 0x0b */ 41*04972362SLiu Ying #define LVDS_REG_0B 0x0b 42*04972362SLiu Ying #define REG_SSC_PCLK_RF BIT(0) 43*04972362SLiu Ying #define REG_LVDS_IN_SWAP BIT(1) 44*04972362SLiu Ying 45*04972362SLiu Ying /* LVDS test pattern gen control registers */ 46*04972362SLiu Ying /* 0x2c */ 47*04972362SLiu Ying #define LVDS_REG_2C 0x2c 48*04972362SLiu Ying #define REG_COL_DEP GENMASK(1, 0) 49*04972362SLiu Ying #define BIT8 FIELD_PREP(REG_COL_DEP, 1) 50*04972362SLiu Ying #define OUT_MAP BIT(4) 51*04972362SLiu Ying #define JEIDA 0 52*04972362SLiu Ying #define REG_DESSC_ENB BIT(6) 53*04972362SLiu Ying #define DMODE BIT(7) 54*04972362SLiu Ying #define DISO BIT(7) 55*04972362SLiu Ying #define SISO 0 56*04972362SLiu Ying 57*04972362SLiu Ying #define LVDS_REG_3C 0x3c 58*04972362SLiu Ying #define LVDS_REG_3F 0x3f 59*04972362SLiu Ying #define LVDS_REG_47 0x47 60*04972362SLiu Ying #define LVDS_REG_48 0x48 61*04972362SLiu Ying #define LVDS_REG_4F 0x4f 62*04972362SLiu Ying #define LVDS_REG_52 0x52 63*04972362SLiu Ying 64*04972362SLiu Ying /* ----------------------------------------------------------------------------- 65*04972362SLiu Ying * HDMI registers are separated into three banks: 66*04972362SLiu Ying * 1) HDMI register common bank: 0x00 ~ 0x2f 67*04972362SLiu Ying */ 68*04972362SLiu Ying 69*04972362SLiu Ying /* HDMI genernal registers */ 70*04972362SLiu Ying #define HDMI_REG_SW_RST 0x04 71*04972362SLiu Ying #define SOFTREF_RST BIT(5) 72*04972362SLiu Ying #define SOFTA_RST BIT(4) 73*04972362SLiu Ying #define SOFTV_RST BIT(3) 74*04972362SLiu Ying #define AUD_RST BIT(2) 75*04972362SLiu Ying #define HDCP_RST BIT(0) 76*04972362SLiu Ying #define HDMI_RST_ALL (SOFTREF_RST | SOFTA_RST | SOFTV_RST | \ 77*04972362SLiu Ying AUD_RST | HDCP_RST) 78*04972362SLiu Ying 79*04972362SLiu Ying #define HDMI_REG_SYS_STATUS 0x0e 80*04972362SLiu Ying #define HPDETECT BIT(6) 81*04972362SLiu Ying #define TXVIDSTABLE BIT(4) 82*04972362SLiu Ying 83*04972362SLiu Ying #define HDMI_REG_BANK_CTRL 0x0f 84*04972362SLiu Ying #define REG_BANK_SEL BIT(0) 85*04972362SLiu Ying 86*04972362SLiu Ying /* HDMI System DDC control registers */ 87*04972362SLiu Ying #define HDMI_REG_DDC_MASTER_CTRL 0x10 88*04972362SLiu Ying #define MASTER_SEL_HOST BIT(0) 89*04972362SLiu Ying 90*04972362SLiu Ying #define HDMI_REG_DDC_HEADER 0x11 91*04972362SLiu Ying 92*04972362SLiu Ying #define HDMI_REG_DDC_REQOFF 0x12 93*04972362SLiu Ying #define HDMI_REG_DDC_REQCOUNT 0x13 94*04972362SLiu Ying #define HDMI_REG_DDC_EDIDSEG 0x14 95*04972362SLiu Ying 96*04972362SLiu Ying #define HDMI_REG_DDC_CMD 0x15 97*04972362SLiu Ying #define DDC_CMD_EDID_READ 0x3 98*04972362SLiu Ying #define DDC_CMD_FIFO_CLR 0x9 99*04972362SLiu Ying 100*04972362SLiu Ying #define HDMI_REG_DDC_STATUS 0x16 101*04972362SLiu Ying #define DDC_DONE BIT(7) 102*04972362SLiu Ying #define DDC_NOACK BIT(5) 103*04972362SLiu Ying #define DDC_WAITBUS BIT(4) 104*04972362SLiu Ying #define DDC_ARBILOSE BIT(3) 105*04972362SLiu Ying #define DDC_ERROR (DDC_NOACK | DDC_WAITBUS | DDC_ARBILOSE) 106*04972362SLiu Ying 107*04972362SLiu Ying #define HDMI_DDC_FIFO_BYTES 32 108*04972362SLiu Ying #define HDMI_REG_DDC_READFIFO 0x17 109*04972362SLiu Ying #define HDMI_REG_LVDS_PORT 0x1d /* LVDS input control I2C addr */ 110*04972362SLiu Ying #define HDMI_REG_LVDS_PORT_EN 0x1e 111*04972362SLiu Ying #define LVDS_INPUT_CTRL_I2C_ADDR 0x33 112*04972362SLiu Ying 113*04972362SLiu Ying /* ----------------------------------------------------------------------------- 114*04972362SLiu Ying * 2) HDMI register bank0: 0x30 ~ 0xff 115*04972362SLiu Ying */ 116*04972362SLiu Ying 117*04972362SLiu Ying /* HDMI AFE registers */ 118*04972362SLiu Ying #define HDMI_REG_AFE_DRV_CTRL 0x61 119*04972362SLiu Ying #define AFE_DRV_PWD BIT(5) 120*04972362SLiu Ying #define AFE_DRV_RST BIT(4) 121*04972362SLiu Ying 122*04972362SLiu Ying #define HDMI_REG_AFE_XP_CTRL 0x62 123*04972362SLiu Ying #define AFE_XP_GAINBIT BIT(7) 124*04972362SLiu Ying #define AFE_XP_ER0 BIT(4) 125*04972362SLiu Ying #define AFE_XP_RESETB BIT(3) 126*04972362SLiu Ying 127*04972362SLiu Ying #define HDMI_REG_AFE_ISW_CTRL 0x63 128*04972362SLiu Ying 129*04972362SLiu Ying #define HDMI_REG_AFE_IP_CTRL 0x64 130*04972362SLiu Ying #define AFE_IP_GAINBIT BIT(7) 131*04972362SLiu Ying #define AFE_IP_ER0 BIT(3) 132*04972362SLiu Ying #define AFE_IP_RESETB BIT(2) 133*04972362SLiu Ying 134*04972362SLiu Ying /* HDMI input data format registers */ 135*04972362SLiu Ying #define HDMI_REG_INPUT_MODE 0x70 136*04972362SLiu Ying #define IN_RGB 0x00 137*04972362SLiu Ying 138*04972362SLiu Ying /* HDMI general control registers */ 139*04972362SLiu Ying #define HDMI_REG_HDMI_MODE 0xc0 140*04972362SLiu Ying #define TX_HDMI_MODE BIT(0) 141*04972362SLiu Ying 142*04972362SLiu Ying #define HDMI_REG_GCP 0xc1 143*04972362SLiu Ying #define AVMUTE BIT(0) 144*04972362SLiu Ying #define HDMI_COLOR_DEPTH GENMASK(6, 4) 145*04972362SLiu Ying #define HDMI_COLOR_DEPTH_24 FIELD_PREP(HDMI_COLOR_DEPTH, 4) 146*04972362SLiu Ying 147*04972362SLiu Ying #define HDMI_REG_PKT_GENERAL_CTRL 0xc6 148*04972362SLiu Ying #define HDMI_REG_AVI_INFOFRM_CTRL 0xcd 149*04972362SLiu Ying #define ENABLE_PKT BIT(0) 150*04972362SLiu Ying #define REPEAT_PKT BIT(1) 151*04972362SLiu Ying 152*04972362SLiu Ying /* ----------------------------------------------------------------------------- 153*04972362SLiu Ying * 3) HDMI register bank1: 0x130 ~ 0x1ff (HDMI packet registers) 154*04972362SLiu Ying */ 155*04972362SLiu Ying 156*04972362SLiu Ying /* AVI packet registers */ 157*04972362SLiu Ying #define HDMI_REG_AVI_DB1 0x158 158*04972362SLiu Ying #define HDMI_REG_AVI_DB2 0x159 159*04972362SLiu Ying #define HDMI_REG_AVI_DB3 0x15a 160*04972362SLiu Ying #define HDMI_REG_AVI_DB4 0x15b 161*04972362SLiu Ying #define HDMI_REG_AVI_DB5 0x15c 162*04972362SLiu Ying #define HDMI_REG_AVI_CSUM 0x15d 163*04972362SLiu Ying #define HDMI_REG_AVI_DB6 0x15e 164*04972362SLiu Ying #define HDMI_REG_AVI_DB7 0x15f 165*04972362SLiu Ying #define HDMI_REG_AVI_DB8 0x160 166*04972362SLiu Ying #define HDMI_REG_AVI_DB9 0x161 167*04972362SLiu Ying #define HDMI_REG_AVI_DB10 0x162 168*04972362SLiu Ying #define HDMI_REG_AVI_DB11 0x163 169*04972362SLiu Ying #define HDMI_REG_AVI_DB12 0x164 170*04972362SLiu Ying #define HDMI_REG_AVI_DB13 0x165 171*04972362SLiu Ying 172*04972362SLiu Ying #define HDMI_AVI_DB_CHUNK1_SIZE (HDMI_REG_AVI_DB5 - HDMI_REG_AVI_DB1 + 1) 173*04972362SLiu Ying #define HDMI_AVI_DB_CHUNK2_SIZE (HDMI_REG_AVI_DB13 - HDMI_REG_AVI_DB6 + 1) 174*04972362SLiu Ying 175*04972362SLiu Ying /* IT6263 data sheet Rev0.8: LVDS RX supports input clock rate up to 150MHz. */ 176*04972362SLiu Ying #define MAX_PIXEL_CLOCK_KHZ 150000 177*04972362SLiu Ying 178*04972362SLiu Ying /* IT6263 programming guide Ver0.90: PCLK_HIGH for TMDS clock over 80MHz. */ 179*04972362SLiu Ying #define HIGH_PIXEL_CLOCK_KHZ 80000 180*04972362SLiu Ying 181*04972362SLiu Ying /* 182*04972362SLiu Ying * IT6263 data sheet Rev0.8: HDMI TX supports link speeds of up to 2.25Gbps 183*04972362SLiu Ying * (link clock rate of 225MHz). 184*04972362SLiu Ying */ 185*04972362SLiu Ying #define MAX_HDMI_TMDS_CHAR_RATE_HZ 225000000 186*04972362SLiu Ying 187*04972362SLiu Ying struct it6263 { 188*04972362SLiu Ying struct device *dev; 189*04972362SLiu Ying struct i2c_client *hdmi_i2c; 190*04972362SLiu Ying struct i2c_client *lvds_i2c; 191*04972362SLiu Ying struct regmap *hdmi_regmap; 192*04972362SLiu Ying struct regmap *lvds_regmap; 193*04972362SLiu Ying struct drm_bridge bridge; 194*04972362SLiu Ying struct drm_bridge *next_bridge; 195*04972362SLiu Ying int lvds_data_mapping; 196*04972362SLiu Ying bool lvds_dual_link; 197*04972362SLiu Ying bool lvds_link12_swap; 198*04972362SLiu Ying }; 199*04972362SLiu Ying 200*04972362SLiu Ying static inline struct it6263 *bridge_to_it6263(struct drm_bridge *bridge) 201*04972362SLiu Ying { 202*04972362SLiu Ying return container_of(bridge, struct it6263, bridge); 203*04972362SLiu Ying } 204*04972362SLiu Ying 205*04972362SLiu Ying static bool it6263_hdmi_writeable_reg(struct device *dev, unsigned int reg) 206*04972362SLiu Ying { 207*04972362SLiu Ying switch (reg) { 208*04972362SLiu Ying case HDMI_REG_SW_RST: 209*04972362SLiu Ying case HDMI_REG_BANK_CTRL: 210*04972362SLiu Ying case HDMI_REG_DDC_MASTER_CTRL: 211*04972362SLiu Ying case HDMI_REG_DDC_HEADER: 212*04972362SLiu Ying case HDMI_REG_DDC_REQOFF: 213*04972362SLiu Ying case HDMI_REG_DDC_REQCOUNT: 214*04972362SLiu Ying case HDMI_REG_DDC_EDIDSEG: 215*04972362SLiu Ying case HDMI_REG_DDC_CMD: 216*04972362SLiu Ying case HDMI_REG_LVDS_PORT: 217*04972362SLiu Ying case HDMI_REG_LVDS_PORT_EN: 218*04972362SLiu Ying case HDMI_REG_AFE_DRV_CTRL: 219*04972362SLiu Ying case HDMI_REG_AFE_XP_CTRL: 220*04972362SLiu Ying case HDMI_REG_AFE_ISW_CTRL: 221*04972362SLiu Ying case HDMI_REG_AFE_IP_CTRL: 222*04972362SLiu Ying case HDMI_REG_INPUT_MODE: 223*04972362SLiu Ying case HDMI_REG_HDMI_MODE: 224*04972362SLiu Ying case HDMI_REG_GCP: 225*04972362SLiu Ying case HDMI_REG_PKT_GENERAL_CTRL: 226*04972362SLiu Ying case HDMI_REG_AVI_INFOFRM_CTRL: 227*04972362SLiu Ying case HDMI_REG_AVI_DB1: 228*04972362SLiu Ying case HDMI_REG_AVI_DB2: 229*04972362SLiu Ying case HDMI_REG_AVI_DB3: 230*04972362SLiu Ying case HDMI_REG_AVI_DB4: 231*04972362SLiu Ying case HDMI_REG_AVI_DB5: 232*04972362SLiu Ying case HDMI_REG_AVI_CSUM: 233*04972362SLiu Ying case HDMI_REG_AVI_DB6: 234*04972362SLiu Ying case HDMI_REG_AVI_DB7: 235*04972362SLiu Ying case HDMI_REG_AVI_DB8: 236*04972362SLiu Ying case HDMI_REG_AVI_DB9: 237*04972362SLiu Ying case HDMI_REG_AVI_DB10: 238*04972362SLiu Ying case HDMI_REG_AVI_DB11: 239*04972362SLiu Ying case HDMI_REG_AVI_DB12: 240*04972362SLiu Ying case HDMI_REG_AVI_DB13: 241*04972362SLiu Ying return true; 242*04972362SLiu Ying default: 243*04972362SLiu Ying return false; 244*04972362SLiu Ying } 245*04972362SLiu Ying } 246*04972362SLiu Ying 247*04972362SLiu Ying static bool it6263_hdmi_readable_reg(struct device *dev, unsigned int reg) 248*04972362SLiu Ying { 249*04972362SLiu Ying if (it6263_hdmi_writeable_reg(dev, reg)) 250*04972362SLiu Ying return true; 251*04972362SLiu Ying 252*04972362SLiu Ying switch (reg) { 253*04972362SLiu Ying case HDMI_REG_SYS_STATUS: 254*04972362SLiu Ying case HDMI_REG_DDC_STATUS: 255*04972362SLiu Ying case HDMI_REG_DDC_READFIFO: 256*04972362SLiu Ying return true; 257*04972362SLiu Ying default: 258*04972362SLiu Ying return false; 259*04972362SLiu Ying } 260*04972362SLiu Ying } 261*04972362SLiu Ying 262*04972362SLiu Ying static bool it6263_hdmi_volatile_reg(struct device *dev, unsigned int reg) 263*04972362SLiu Ying { 264*04972362SLiu Ying switch (reg) { 265*04972362SLiu Ying case HDMI_REG_SW_RST: 266*04972362SLiu Ying case HDMI_REG_SYS_STATUS: 267*04972362SLiu Ying case HDMI_REG_DDC_STATUS: 268*04972362SLiu Ying case HDMI_REG_DDC_READFIFO: 269*04972362SLiu Ying return true; 270*04972362SLiu Ying default: 271*04972362SLiu Ying return false; 272*04972362SLiu Ying } 273*04972362SLiu Ying } 274*04972362SLiu Ying 275*04972362SLiu Ying static const struct regmap_range_cfg it6263_hdmi_range_cfg = { 276*04972362SLiu Ying .range_min = 0x00, 277*04972362SLiu Ying .range_max = HDMI_REG_AVI_DB13, 278*04972362SLiu Ying .selector_reg = HDMI_REG_BANK_CTRL, 279*04972362SLiu Ying .selector_mask = REG_BANK_SEL, 280*04972362SLiu Ying .selector_shift = 0, 281*04972362SLiu Ying .window_start = 0x00, 282*04972362SLiu Ying .window_len = 0x100, 283*04972362SLiu Ying }; 284*04972362SLiu Ying 285*04972362SLiu Ying static const struct regmap_config it6263_hdmi_regmap_config = { 286*04972362SLiu Ying .name = "it6263-hdmi", 287*04972362SLiu Ying .reg_bits = 8, 288*04972362SLiu Ying .val_bits = 8, 289*04972362SLiu Ying .writeable_reg = it6263_hdmi_writeable_reg, 290*04972362SLiu Ying .readable_reg = it6263_hdmi_readable_reg, 291*04972362SLiu Ying .volatile_reg = it6263_hdmi_volatile_reg, 292*04972362SLiu Ying .max_register = HDMI_REG_AVI_DB13, 293*04972362SLiu Ying .ranges = &it6263_hdmi_range_cfg, 294*04972362SLiu Ying .num_ranges = 1, 295*04972362SLiu Ying .cache_type = REGCACHE_MAPLE, 296*04972362SLiu Ying }; 297*04972362SLiu Ying 298*04972362SLiu Ying static bool it6263_lvds_writeable_reg(struct device *dev, unsigned int reg) 299*04972362SLiu Ying { 300*04972362SLiu Ying switch (reg) { 301*04972362SLiu Ying case LVDS_REG_05: 302*04972362SLiu Ying case LVDS_REG_0B: 303*04972362SLiu Ying case LVDS_REG_2C: 304*04972362SLiu Ying case LVDS_REG_3C: 305*04972362SLiu Ying case LVDS_REG_3F: 306*04972362SLiu Ying case LVDS_REG_47: 307*04972362SLiu Ying case LVDS_REG_48: 308*04972362SLiu Ying case LVDS_REG_4F: 309*04972362SLiu Ying case LVDS_REG_52: 310*04972362SLiu Ying return true; 311*04972362SLiu Ying default: 312*04972362SLiu Ying return false; 313*04972362SLiu Ying } 314*04972362SLiu Ying } 315*04972362SLiu Ying 316*04972362SLiu Ying static bool it6263_lvds_readable_reg(struct device *dev, unsigned int reg) 317*04972362SLiu Ying { 318*04972362SLiu Ying return it6263_lvds_writeable_reg(dev, reg); 319*04972362SLiu Ying } 320*04972362SLiu Ying 321*04972362SLiu Ying static bool it6263_lvds_volatile_reg(struct device *dev, unsigned int reg) 322*04972362SLiu Ying { 323*04972362SLiu Ying return reg == LVDS_REG_05; 324*04972362SLiu Ying } 325*04972362SLiu Ying 326*04972362SLiu Ying static const struct regmap_config it6263_lvds_regmap_config = { 327*04972362SLiu Ying .name = "it6263-lvds", 328*04972362SLiu Ying .reg_bits = 8, 329*04972362SLiu Ying .val_bits = 8, 330*04972362SLiu Ying .writeable_reg = it6263_lvds_writeable_reg, 331*04972362SLiu Ying .readable_reg = it6263_lvds_readable_reg, 332*04972362SLiu Ying .volatile_reg = it6263_lvds_volatile_reg, 333*04972362SLiu Ying .max_register = LVDS_REG_52, 334*04972362SLiu Ying .cache_type = REGCACHE_MAPLE, 335*04972362SLiu Ying }; 336*04972362SLiu Ying 337*04972362SLiu Ying static const char * const it6263_supplies[] = { 338*04972362SLiu Ying "ivdd", "ovdd", "txavcc18", "txavcc33", "pvcc1", "pvcc2", 339*04972362SLiu Ying "avcc", "anvdd", "apvdd" 340*04972362SLiu Ying }; 341*04972362SLiu Ying 342*04972362SLiu Ying static int it6263_parse_dt(struct it6263 *it) 343*04972362SLiu Ying { 344*04972362SLiu Ying struct device *dev = it->dev; 345*04972362SLiu Ying struct device_node *port0, *port1; 346*04972362SLiu Ying int ret = 0; 347*04972362SLiu Ying 348*04972362SLiu Ying it->lvds_data_mapping = drm_of_lvds_get_data_mapping(dev->of_node); 349*04972362SLiu Ying if (it->lvds_data_mapping < 0) { 350*04972362SLiu Ying dev_err(dev, "%pOF: invalid or missing %s DT property: %d\n", 351*04972362SLiu Ying dev->of_node, "data-mapping", it->lvds_data_mapping); 352*04972362SLiu Ying return it->lvds_data_mapping; 353*04972362SLiu Ying } 354*04972362SLiu Ying 355*04972362SLiu Ying it->next_bridge = devm_drm_of_get_bridge(dev, dev->of_node, 2, 0); 356*04972362SLiu Ying if (IS_ERR(it->next_bridge)) 357*04972362SLiu Ying return dev_err_probe(dev, PTR_ERR(it->next_bridge), 358*04972362SLiu Ying "failed to get next bridge\n"); 359*04972362SLiu Ying 360*04972362SLiu Ying port0 = of_graph_get_port_by_id(dev->of_node, 0); 361*04972362SLiu Ying port1 = of_graph_get_port_by_id(dev->of_node, 1); 362*04972362SLiu Ying if (port0 && port1) { 363*04972362SLiu Ying int order; 364*04972362SLiu Ying 365*04972362SLiu Ying it->lvds_dual_link = true; 366*04972362SLiu Ying order = drm_of_lvds_get_dual_link_pixel_order_sink(port0, port1); 367*04972362SLiu Ying if (order < 0) { 368*04972362SLiu Ying dev_err(dev, 369*04972362SLiu Ying "failed to get dual link pixel order: %d\n", 370*04972362SLiu Ying order); 371*04972362SLiu Ying ret = order; 372*04972362SLiu Ying } else if (order == DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS) { 373*04972362SLiu Ying it->lvds_link12_swap = true; 374*04972362SLiu Ying } 375*04972362SLiu Ying } else if (port1) { 376*04972362SLiu Ying ret = -EINVAL; 377*04972362SLiu Ying dev_err(dev, "single input LVDS port1 is not supported\n"); 378*04972362SLiu Ying } else if (!port0) { 379*04972362SLiu Ying ret = -EINVAL; 380*04972362SLiu Ying dev_err(dev, "no input LVDS port\n"); 381*04972362SLiu Ying } 382*04972362SLiu Ying 383*04972362SLiu Ying of_node_put(port0); 384*04972362SLiu Ying of_node_put(port1); 385*04972362SLiu Ying 386*04972362SLiu Ying return ret; 387*04972362SLiu Ying } 388*04972362SLiu Ying 389*04972362SLiu Ying static inline void it6263_hw_reset(struct gpio_desc *reset_gpio) 390*04972362SLiu Ying { 391*04972362SLiu Ying if (!reset_gpio) 392*04972362SLiu Ying return; 393*04972362SLiu Ying 394*04972362SLiu Ying gpiod_set_value_cansleep(reset_gpio, 0); 395*04972362SLiu Ying fsleep(1000); 396*04972362SLiu Ying gpiod_set_value_cansleep(reset_gpio, 1); 397*04972362SLiu Ying /* The chip maker says the low pulse should be at least 40ms. */ 398*04972362SLiu Ying fsleep(40000); 399*04972362SLiu Ying gpiod_set_value_cansleep(reset_gpio, 0); 400*04972362SLiu Ying /* addtional time to wait the high voltage to be stable */ 401*04972362SLiu Ying fsleep(5000); 402*04972362SLiu Ying } 403*04972362SLiu Ying 404*04972362SLiu Ying static inline int it6263_lvds_set_i2c_addr(struct it6263 *it) 405*04972362SLiu Ying { 406*04972362SLiu Ying int ret; 407*04972362SLiu Ying 408*04972362SLiu Ying ret = regmap_write(it->hdmi_regmap, HDMI_REG_LVDS_PORT, 409*04972362SLiu Ying LVDS_INPUT_CTRL_I2C_ADDR << 1); 410*04972362SLiu Ying if (ret) 411*04972362SLiu Ying return ret; 412*04972362SLiu Ying 413*04972362SLiu Ying return regmap_write(it->hdmi_regmap, HDMI_REG_LVDS_PORT_EN, BIT(0)); 414*04972362SLiu Ying } 415*04972362SLiu Ying 416*04972362SLiu Ying static inline void it6263_lvds_reset(struct it6263 *it) 417*04972362SLiu Ying { 418*04972362SLiu Ying /* AFE PLL reset */ 419*04972362SLiu Ying regmap_write_bits(it->lvds_regmap, LVDS_REG_3C, BIT(0), 0x0); 420*04972362SLiu Ying fsleep(1000); 421*04972362SLiu Ying regmap_write_bits(it->lvds_regmap, LVDS_REG_3C, BIT(0), BIT(0)); 422*04972362SLiu Ying 423*04972362SLiu Ying /* software pixel clock domain reset */ 424*04972362SLiu Ying regmap_write_bits(it->lvds_regmap, LVDS_REG_05, REG_SOFT_P_RST, 425*04972362SLiu Ying REG_SOFT_P_RST); 426*04972362SLiu Ying fsleep(1000); 427*04972362SLiu Ying regmap_write_bits(it->lvds_regmap, LVDS_REG_05, REG_SOFT_P_RST, 0x0); 428*04972362SLiu Ying fsleep(10000); 429*04972362SLiu Ying } 430*04972362SLiu Ying 431*04972362SLiu Ying static inline void it6263_lvds_set_interface(struct it6263 *it) 432*04972362SLiu Ying { 433*04972362SLiu Ying /* color depth */ 434*04972362SLiu Ying regmap_write_bits(it->lvds_regmap, LVDS_REG_2C, REG_COL_DEP, BIT8); 435*04972362SLiu Ying /* output mapping */ 436*04972362SLiu Ying regmap_write_bits(it->lvds_regmap, LVDS_REG_2C, OUT_MAP, JEIDA); 437*04972362SLiu Ying 438*04972362SLiu Ying if (it->lvds_dual_link) { 439*04972362SLiu Ying regmap_write_bits(it->lvds_regmap, LVDS_REG_2C, DMODE, DISO); 440*04972362SLiu Ying regmap_write_bits(it->lvds_regmap, LVDS_REG_52, BIT(1), BIT(1)); 441*04972362SLiu Ying } else { 442*04972362SLiu Ying regmap_write_bits(it->lvds_regmap, LVDS_REG_2C, DMODE, SISO); 443*04972362SLiu Ying regmap_write_bits(it->lvds_regmap, LVDS_REG_52, BIT(1), 0); 444*04972362SLiu Ying } 445*04972362SLiu Ying } 446*04972362SLiu Ying 447*04972362SLiu Ying static inline void it6263_lvds_set_afe(struct it6263 *it) 448*04972362SLiu Ying { 449*04972362SLiu Ying regmap_write(it->lvds_regmap, LVDS_REG_3C, 0xaa); 450*04972362SLiu Ying regmap_write(it->lvds_regmap, LVDS_REG_3F, 0x02); 451*04972362SLiu Ying regmap_write(it->lvds_regmap, LVDS_REG_47, 0xaa); 452*04972362SLiu Ying regmap_write(it->lvds_regmap, LVDS_REG_48, 0x02); 453*04972362SLiu Ying regmap_write(it->lvds_regmap, LVDS_REG_4F, 0x11); 454*04972362SLiu Ying 455*04972362SLiu Ying regmap_write_bits(it->lvds_regmap, LVDS_REG_0B, REG_SSC_PCLK_RF, 456*04972362SLiu Ying REG_SSC_PCLK_RF); 457*04972362SLiu Ying regmap_write_bits(it->lvds_regmap, LVDS_REG_3C, 0x07, 0); 458*04972362SLiu Ying regmap_write_bits(it->lvds_regmap, LVDS_REG_2C, REG_DESSC_ENB, 459*04972362SLiu Ying REG_DESSC_ENB); 460*04972362SLiu Ying } 461*04972362SLiu Ying 462*04972362SLiu Ying static inline void it6263_lvds_sys_cfg(struct it6263 *it) 463*04972362SLiu Ying { 464*04972362SLiu Ying regmap_write_bits(it->lvds_regmap, LVDS_REG_0B, REG_LVDS_IN_SWAP, 465*04972362SLiu Ying it->lvds_link12_swap ? REG_LVDS_IN_SWAP : 0); 466*04972362SLiu Ying } 467*04972362SLiu Ying 468*04972362SLiu Ying static inline void it6263_lvds_config(struct it6263 *it) 469*04972362SLiu Ying { 470*04972362SLiu Ying it6263_lvds_reset(it); 471*04972362SLiu Ying it6263_lvds_set_interface(it); 472*04972362SLiu Ying it6263_lvds_set_afe(it); 473*04972362SLiu Ying it6263_lvds_sys_cfg(it); 474*04972362SLiu Ying } 475*04972362SLiu Ying 476*04972362SLiu Ying static inline void it6263_hdmi_config(struct it6263 *it) 477*04972362SLiu Ying { 478*04972362SLiu Ying regmap_write(it->hdmi_regmap, HDMI_REG_SW_RST, HDMI_RST_ALL); 479*04972362SLiu Ying regmap_write(it->hdmi_regmap, HDMI_REG_INPUT_MODE, IN_RGB); 480*04972362SLiu Ying regmap_write_bits(it->hdmi_regmap, HDMI_REG_GCP, HDMI_COLOR_DEPTH, 481*04972362SLiu Ying HDMI_COLOR_DEPTH_24); 482*04972362SLiu Ying } 483*04972362SLiu Ying 484*04972362SLiu Ying static enum drm_connector_status it6263_detect(struct it6263 *it) 485*04972362SLiu Ying { 486*04972362SLiu Ying unsigned int val; 487*04972362SLiu Ying 488*04972362SLiu Ying regmap_read(it->hdmi_regmap, HDMI_REG_SYS_STATUS, &val); 489*04972362SLiu Ying if (val & HPDETECT) 490*04972362SLiu Ying return connector_status_connected; 491*04972362SLiu Ying else 492*04972362SLiu Ying return connector_status_disconnected; 493*04972362SLiu Ying } 494*04972362SLiu Ying 495*04972362SLiu Ying static int it6263_read_edid(void *data, u8 *buf, unsigned int block, size_t len) 496*04972362SLiu Ying { 497*04972362SLiu Ying struct it6263 *it = data; 498*04972362SLiu Ying struct regmap *regmap = it->hdmi_regmap; 499*04972362SLiu Ying unsigned int start = (block % 2) * EDID_LENGTH; 500*04972362SLiu Ying unsigned int segment = block >> 1; 501*04972362SLiu Ying unsigned int count, val; 502*04972362SLiu Ying int ret; 503*04972362SLiu Ying 504*04972362SLiu Ying regmap_write(regmap, HDMI_REG_DDC_MASTER_CTRL, MASTER_SEL_HOST); 505*04972362SLiu Ying regmap_write(regmap, HDMI_REG_DDC_HEADER, DDC_ADDR << 1); 506*04972362SLiu Ying regmap_write(regmap, HDMI_REG_DDC_EDIDSEG, segment); 507*04972362SLiu Ying 508*04972362SLiu Ying while (len) { 509*04972362SLiu Ying /* clear DDC FIFO */ 510*04972362SLiu Ying regmap_write(regmap, HDMI_REG_DDC_CMD, DDC_CMD_FIFO_CLR); 511*04972362SLiu Ying 512*04972362SLiu Ying ret = regmap_read_poll_timeout(regmap, HDMI_REG_DDC_STATUS, 513*04972362SLiu Ying val, val & DDC_DONE, 514*04972362SLiu Ying 2000, 10000); 515*04972362SLiu Ying if (ret) { 516*04972362SLiu Ying dev_err(it->dev, "failed to clear DDC FIFO:%d\n", ret); 517*04972362SLiu Ying return ret; 518*04972362SLiu Ying } 519*04972362SLiu Ying 520*04972362SLiu Ying count = len > HDMI_DDC_FIFO_BYTES ? HDMI_DDC_FIFO_BYTES : len; 521*04972362SLiu Ying 522*04972362SLiu Ying /* fire the read command */ 523*04972362SLiu Ying regmap_write(regmap, HDMI_REG_DDC_REQOFF, start); 524*04972362SLiu Ying regmap_write(regmap, HDMI_REG_DDC_REQCOUNT, count); 525*04972362SLiu Ying regmap_write(regmap, HDMI_REG_DDC_CMD, DDC_CMD_EDID_READ); 526*04972362SLiu Ying 527*04972362SLiu Ying start += count; 528*04972362SLiu Ying len -= count; 529*04972362SLiu Ying 530*04972362SLiu Ying ret = regmap_read_poll_timeout(regmap, HDMI_REG_DDC_STATUS, val, 531*04972362SLiu Ying val & (DDC_DONE | DDC_ERROR), 532*04972362SLiu Ying 20000, 250000); 533*04972362SLiu Ying if (ret && !(val & DDC_ERROR)) { 534*04972362SLiu Ying dev_err(it->dev, "failed to read EDID:%d\n", ret); 535*04972362SLiu Ying return ret; 536*04972362SLiu Ying } 537*04972362SLiu Ying 538*04972362SLiu Ying if (val & DDC_ERROR) { 539*04972362SLiu Ying dev_err(it->dev, "DDC error\n"); 540*04972362SLiu Ying return -EIO; 541*04972362SLiu Ying } 542*04972362SLiu Ying 543*04972362SLiu Ying /* cache to buffer */ 544*04972362SLiu Ying for (; count > 0; count--) { 545*04972362SLiu Ying regmap_read(regmap, HDMI_REG_DDC_READFIFO, &val); 546*04972362SLiu Ying *(buf++) = val; 547*04972362SLiu Ying } 548*04972362SLiu Ying } 549*04972362SLiu Ying 550*04972362SLiu Ying return 0; 551*04972362SLiu Ying } 552*04972362SLiu Ying 553*04972362SLiu Ying static int it6263_bridge_atomic_check(struct drm_bridge *bridge, 554*04972362SLiu Ying struct drm_bridge_state *bridge_state, 555*04972362SLiu Ying struct drm_crtc_state *crtc_state, 556*04972362SLiu Ying struct drm_connector_state *conn_state) 557*04972362SLiu Ying { 558*04972362SLiu Ying return drm_atomic_helper_connector_hdmi_check(conn_state->connector, 559*04972362SLiu Ying conn_state->state); 560*04972362SLiu Ying } 561*04972362SLiu Ying 562*04972362SLiu Ying static void 563*04972362SLiu Ying it6263_bridge_atomic_disable(struct drm_bridge *bridge, 564*04972362SLiu Ying struct drm_bridge_state *old_bridge_state) 565*04972362SLiu Ying { 566*04972362SLiu Ying struct it6263 *it = bridge_to_it6263(bridge); 567*04972362SLiu Ying 568*04972362SLiu Ying regmap_write_bits(it->hdmi_regmap, HDMI_REG_GCP, AVMUTE, AVMUTE); 569*04972362SLiu Ying regmap_write(it->hdmi_regmap, HDMI_REG_PKT_GENERAL_CTRL, 0); 570*04972362SLiu Ying regmap_write(it->hdmi_regmap, HDMI_REG_AFE_DRV_CTRL, 571*04972362SLiu Ying AFE_DRV_RST | AFE_DRV_PWD); 572*04972362SLiu Ying } 573*04972362SLiu Ying 574*04972362SLiu Ying static void 575*04972362SLiu Ying it6263_bridge_atomic_enable(struct drm_bridge *bridge, 576*04972362SLiu Ying struct drm_bridge_state *old_bridge_state) 577*04972362SLiu Ying { 578*04972362SLiu Ying struct drm_atomic_state *state = old_bridge_state->base.state; 579*04972362SLiu Ying struct it6263 *it = bridge_to_it6263(bridge); 580*04972362SLiu Ying const struct drm_crtc_state *crtc_state; 581*04972362SLiu Ying struct regmap *regmap = it->hdmi_regmap; 582*04972362SLiu Ying const struct drm_display_mode *mode; 583*04972362SLiu Ying struct drm_connector *connector; 584*04972362SLiu Ying bool is_stable = false; 585*04972362SLiu Ying struct drm_crtc *crtc; 586*04972362SLiu Ying unsigned int val; 587*04972362SLiu Ying bool pclk_high; 588*04972362SLiu Ying int i, ret; 589*04972362SLiu Ying 590*04972362SLiu Ying connector = drm_atomic_get_new_connector_for_encoder(state, 591*04972362SLiu Ying bridge->encoder); 592*04972362SLiu Ying crtc = drm_atomic_get_new_connector_state(state, connector)->crtc; 593*04972362SLiu Ying crtc_state = drm_atomic_get_new_crtc_state(state, crtc); 594*04972362SLiu Ying mode = &crtc_state->adjusted_mode; 595*04972362SLiu Ying 596*04972362SLiu Ying regmap_write(regmap, HDMI_REG_HDMI_MODE, TX_HDMI_MODE); 597*04972362SLiu Ying 598*04972362SLiu Ying drm_atomic_helper_connector_hdmi_update_infoframes(connector, state); 599*04972362SLiu Ying 600*04972362SLiu Ying /* HDMI AFE setup */ 601*04972362SLiu Ying pclk_high = mode->clock > HIGH_PIXEL_CLOCK_KHZ; 602*04972362SLiu Ying regmap_write(regmap, HDMI_REG_AFE_DRV_CTRL, AFE_DRV_RST); 603*04972362SLiu Ying if (pclk_high) 604*04972362SLiu Ying regmap_write(regmap, HDMI_REG_AFE_XP_CTRL, 605*04972362SLiu Ying AFE_XP_GAINBIT | AFE_XP_RESETB); 606*04972362SLiu Ying else 607*04972362SLiu Ying regmap_write(regmap, HDMI_REG_AFE_XP_CTRL, 608*04972362SLiu Ying AFE_XP_ER0 | AFE_XP_RESETB); 609*04972362SLiu Ying regmap_write(regmap, HDMI_REG_AFE_ISW_CTRL, 0x10); 610*04972362SLiu Ying if (pclk_high) 611*04972362SLiu Ying regmap_write(regmap, HDMI_REG_AFE_IP_CTRL, 612*04972362SLiu Ying AFE_IP_GAINBIT | AFE_IP_RESETB); 613*04972362SLiu Ying else 614*04972362SLiu Ying regmap_write(regmap, HDMI_REG_AFE_IP_CTRL, 615*04972362SLiu Ying AFE_IP_ER0 | AFE_IP_RESETB); 616*04972362SLiu Ying 617*04972362SLiu Ying /* HDMI software video reset */ 618*04972362SLiu Ying regmap_write_bits(regmap, HDMI_REG_SW_RST, SOFTV_RST, SOFTV_RST); 619*04972362SLiu Ying fsleep(1000); 620*04972362SLiu Ying regmap_write_bits(regmap, HDMI_REG_SW_RST, SOFTV_RST, 0); 621*04972362SLiu Ying 622*04972362SLiu Ying /* reconfigure LVDS and retry several times in case video is instable */ 623*04972362SLiu Ying for (i = 0; i < 3; i++) { 624*04972362SLiu Ying ret = regmap_read_poll_timeout(regmap, HDMI_REG_SYS_STATUS, val, 625*04972362SLiu Ying val & TXVIDSTABLE, 626*04972362SLiu Ying 20000, 500000); 627*04972362SLiu Ying if (!ret) { 628*04972362SLiu Ying is_stable = true; 629*04972362SLiu Ying break; 630*04972362SLiu Ying } 631*04972362SLiu Ying 632*04972362SLiu Ying it6263_lvds_config(it); 633*04972362SLiu Ying } 634*04972362SLiu Ying 635*04972362SLiu Ying if (!is_stable) 636*04972362SLiu Ying dev_warn(it->dev, "failed to wait for video stable\n"); 637*04972362SLiu Ying 638*04972362SLiu Ying /* HDMI AFE reset release and power up */ 639*04972362SLiu Ying regmap_write(regmap, HDMI_REG_AFE_DRV_CTRL, 0); 640*04972362SLiu Ying 641*04972362SLiu Ying regmap_write_bits(regmap, HDMI_REG_GCP, AVMUTE, 0); 642*04972362SLiu Ying 643*04972362SLiu Ying regmap_write(regmap, HDMI_REG_PKT_GENERAL_CTRL, ENABLE_PKT | REPEAT_PKT); 644*04972362SLiu Ying } 645*04972362SLiu Ying 646*04972362SLiu Ying static enum drm_mode_status 647*04972362SLiu Ying it6263_bridge_mode_valid(struct drm_bridge *bridge, 648*04972362SLiu Ying const struct drm_display_info *info, 649*04972362SLiu Ying const struct drm_display_mode *mode) 650*04972362SLiu Ying { 651*04972362SLiu Ying unsigned long long rate; 652*04972362SLiu Ying 653*04972362SLiu Ying rate = drm_hdmi_compute_mode_clock(mode, 8, HDMI_COLORSPACE_RGB); 654*04972362SLiu Ying if (rate == 0) 655*04972362SLiu Ying return MODE_NOCLOCK; 656*04972362SLiu Ying 657*04972362SLiu Ying return bridge->funcs->hdmi_tmds_char_rate_valid(bridge, mode, rate); 658*04972362SLiu Ying } 659*04972362SLiu Ying 660*04972362SLiu Ying static int it6263_bridge_attach(struct drm_bridge *bridge, 661*04972362SLiu Ying enum drm_bridge_attach_flags flags) 662*04972362SLiu Ying { 663*04972362SLiu Ying struct it6263 *it = bridge_to_it6263(bridge); 664*04972362SLiu Ying struct drm_connector *connector; 665*04972362SLiu Ying int ret; 666*04972362SLiu Ying 667*04972362SLiu Ying ret = drm_bridge_attach(bridge->encoder, it->next_bridge, bridge, 668*04972362SLiu Ying flags | DRM_BRIDGE_ATTACH_NO_CONNECTOR); 669*04972362SLiu Ying if (ret < 0) 670*04972362SLiu Ying return ret; 671*04972362SLiu Ying 672*04972362SLiu Ying if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) 673*04972362SLiu Ying return 0; 674*04972362SLiu Ying 675*04972362SLiu Ying connector = drm_bridge_connector_init(bridge->dev, bridge->encoder); 676*04972362SLiu Ying if (IS_ERR(connector)) { 677*04972362SLiu Ying ret = PTR_ERR(connector); 678*04972362SLiu Ying dev_err(it->dev, "failed to initialize bridge connector: %d\n", 679*04972362SLiu Ying ret); 680*04972362SLiu Ying return ret; 681*04972362SLiu Ying } 682*04972362SLiu Ying 683*04972362SLiu Ying drm_connector_attach_encoder(connector, bridge->encoder); 684*04972362SLiu Ying 685*04972362SLiu Ying return 0; 686*04972362SLiu Ying } 687*04972362SLiu Ying 688*04972362SLiu Ying static enum drm_connector_status it6263_bridge_detect(struct drm_bridge *bridge) 689*04972362SLiu Ying { 690*04972362SLiu Ying struct it6263 *it = bridge_to_it6263(bridge); 691*04972362SLiu Ying 692*04972362SLiu Ying return it6263_detect(it); 693*04972362SLiu Ying } 694*04972362SLiu Ying 695*04972362SLiu Ying static const struct drm_edid * 696*04972362SLiu Ying it6263_bridge_edid_read(struct drm_bridge *bridge, 697*04972362SLiu Ying struct drm_connector *connector) 698*04972362SLiu Ying { 699*04972362SLiu Ying struct it6263 *it = bridge_to_it6263(bridge); 700*04972362SLiu Ying 701*04972362SLiu Ying return drm_edid_read_custom(connector, it6263_read_edid, it); 702*04972362SLiu Ying } 703*04972362SLiu Ying 704*04972362SLiu Ying static u32 * 705*04972362SLiu Ying it6263_bridge_atomic_get_input_bus_fmts(struct drm_bridge *bridge, 706*04972362SLiu Ying struct drm_bridge_state *bridge_state, 707*04972362SLiu Ying struct drm_crtc_state *crtc_state, 708*04972362SLiu Ying struct drm_connector_state *conn_state, 709*04972362SLiu Ying u32 output_fmt, 710*04972362SLiu Ying unsigned int *num_input_fmts) 711*04972362SLiu Ying { 712*04972362SLiu Ying struct it6263 *it = bridge_to_it6263(bridge); 713*04972362SLiu Ying u32 *input_fmts; 714*04972362SLiu Ying 715*04972362SLiu Ying *num_input_fmts = 0; 716*04972362SLiu Ying 717*04972362SLiu Ying if (it->lvds_data_mapping != MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA) 718*04972362SLiu Ying return NULL; 719*04972362SLiu Ying 720*04972362SLiu Ying input_fmts = kmalloc(sizeof(*input_fmts), GFP_KERNEL); 721*04972362SLiu Ying if (!input_fmts) 722*04972362SLiu Ying return NULL; 723*04972362SLiu Ying 724*04972362SLiu Ying input_fmts[0] = MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA; 725*04972362SLiu Ying *num_input_fmts = 1; 726*04972362SLiu Ying 727*04972362SLiu Ying return input_fmts; 728*04972362SLiu Ying } 729*04972362SLiu Ying 730*04972362SLiu Ying static enum drm_mode_status 731*04972362SLiu Ying it6263_hdmi_tmds_char_rate_valid(const struct drm_bridge *bridge, 732*04972362SLiu Ying const struct drm_display_mode *mode, 733*04972362SLiu Ying unsigned long long tmds_rate) 734*04972362SLiu Ying { 735*04972362SLiu Ying if (mode->clock > MAX_PIXEL_CLOCK_KHZ) 736*04972362SLiu Ying return MODE_CLOCK_HIGH; 737*04972362SLiu Ying 738*04972362SLiu Ying if (tmds_rate > MAX_HDMI_TMDS_CHAR_RATE_HZ) 739*04972362SLiu Ying return MODE_CLOCK_HIGH; 740*04972362SLiu Ying 741*04972362SLiu Ying return MODE_OK; 742*04972362SLiu Ying } 743*04972362SLiu Ying 744*04972362SLiu Ying static int it6263_hdmi_clear_infoframe(struct drm_bridge *bridge, 745*04972362SLiu Ying enum hdmi_infoframe_type type) 746*04972362SLiu Ying { 747*04972362SLiu Ying struct it6263 *it = bridge_to_it6263(bridge); 748*04972362SLiu Ying 749*04972362SLiu Ying if (type == HDMI_INFOFRAME_TYPE_AVI) 750*04972362SLiu Ying regmap_write(it->hdmi_regmap, HDMI_REG_AVI_INFOFRM_CTRL, 0); 751*04972362SLiu Ying else 752*04972362SLiu Ying dev_dbg(it->dev, "unsupported HDMI infoframe 0x%x\n", type); 753*04972362SLiu Ying 754*04972362SLiu Ying return 0; 755*04972362SLiu Ying } 756*04972362SLiu Ying 757*04972362SLiu Ying static int it6263_hdmi_write_infoframe(struct drm_bridge *bridge, 758*04972362SLiu Ying enum hdmi_infoframe_type type, 759*04972362SLiu Ying const u8 *buffer, size_t len) 760*04972362SLiu Ying { 761*04972362SLiu Ying struct it6263 *it = bridge_to_it6263(bridge); 762*04972362SLiu Ying struct regmap *regmap = it->hdmi_regmap; 763*04972362SLiu Ying 764*04972362SLiu Ying if (type != HDMI_INFOFRAME_TYPE_AVI) { 765*04972362SLiu Ying dev_dbg(it->dev, "unsupported HDMI infoframe 0x%x\n", type); 766*04972362SLiu Ying return 0; 767*04972362SLiu Ying } 768*04972362SLiu Ying 769*04972362SLiu Ying /* write the first AVI infoframe data byte chunk(DB1-DB5) */ 770*04972362SLiu Ying regmap_bulk_write(regmap, HDMI_REG_AVI_DB1, 771*04972362SLiu Ying &buffer[HDMI_INFOFRAME_HEADER_SIZE], 772*04972362SLiu Ying HDMI_AVI_DB_CHUNK1_SIZE); 773*04972362SLiu Ying 774*04972362SLiu Ying /* write the second AVI infoframe data byte chunk(DB6-DB13) */ 775*04972362SLiu Ying regmap_bulk_write(regmap, HDMI_REG_AVI_DB6, 776*04972362SLiu Ying &buffer[HDMI_INFOFRAME_HEADER_SIZE + 777*04972362SLiu Ying HDMI_AVI_DB_CHUNK1_SIZE], 778*04972362SLiu Ying HDMI_AVI_DB_CHUNK2_SIZE); 779*04972362SLiu Ying 780*04972362SLiu Ying /* write checksum */ 781*04972362SLiu Ying regmap_write(regmap, HDMI_REG_AVI_CSUM, buffer[3]); 782*04972362SLiu Ying 783*04972362SLiu Ying regmap_write(regmap, HDMI_REG_AVI_INFOFRM_CTRL, ENABLE_PKT | REPEAT_PKT); 784*04972362SLiu Ying 785*04972362SLiu Ying return 0; 786*04972362SLiu Ying } 787*04972362SLiu Ying 788*04972362SLiu Ying static const struct drm_bridge_funcs it6263_bridge_funcs = { 789*04972362SLiu Ying .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state, 790*04972362SLiu Ying .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state, 791*04972362SLiu Ying .atomic_reset = drm_atomic_helper_bridge_reset, 792*04972362SLiu Ying .attach = it6263_bridge_attach, 793*04972362SLiu Ying .mode_valid = it6263_bridge_mode_valid, 794*04972362SLiu Ying .atomic_disable = it6263_bridge_atomic_disable, 795*04972362SLiu Ying .atomic_enable = it6263_bridge_atomic_enable, 796*04972362SLiu Ying .atomic_check = it6263_bridge_atomic_check, 797*04972362SLiu Ying .detect = it6263_bridge_detect, 798*04972362SLiu Ying .edid_read = it6263_bridge_edid_read, 799*04972362SLiu Ying .atomic_get_input_bus_fmts = it6263_bridge_atomic_get_input_bus_fmts, 800*04972362SLiu Ying .hdmi_tmds_char_rate_valid = it6263_hdmi_tmds_char_rate_valid, 801*04972362SLiu Ying .hdmi_clear_infoframe = it6263_hdmi_clear_infoframe, 802*04972362SLiu Ying .hdmi_write_infoframe = it6263_hdmi_write_infoframe, 803*04972362SLiu Ying }; 804*04972362SLiu Ying 805*04972362SLiu Ying static int it6263_probe(struct i2c_client *client) 806*04972362SLiu Ying { 807*04972362SLiu Ying struct device *dev = &client->dev; 808*04972362SLiu Ying struct gpio_desc *reset_gpio; 809*04972362SLiu Ying struct it6263 *it; 810*04972362SLiu Ying int ret; 811*04972362SLiu Ying 812*04972362SLiu Ying it = devm_kzalloc(dev, sizeof(*it), GFP_KERNEL); 813*04972362SLiu Ying if (!it) 814*04972362SLiu Ying return -ENOMEM; 815*04972362SLiu Ying 816*04972362SLiu Ying it->dev = dev; 817*04972362SLiu Ying it->hdmi_i2c = client; 818*04972362SLiu Ying 819*04972362SLiu Ying it->hdmi_regmap = devm_regmap_init_i2c(client, 820*04972362SLiu Ying &it6263_hdmi_regmap_config); 821*04972362SLiu Ying if (IS_ERR(it->hdmi_regmap)) 822*04972362SLiu Ying return dev_err_probe(dev, PTR_ERR(it->hdmi_regmap), 823*04972362SLiu Ying "failed to init I2C regmap for HDMI\n"); 824*04972362SLiu Ying 825*04972362SLiu Ying reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); 826*04972362SLiu Ying if (IS_ERR(reset_gpio)) 827*04972362SLiu Ying return dev_err_probe(dev, PTR_ERR(reset_gpio), 828*04972362SLiu Ying "failed to get reset gpio\n"); 829*04972362SLiu Ying 830*04972362SLiu Ying ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(it6263_supplies), 831*04972362SLiu Ying it6263_supplies); 832*04972362SLiu Ying if (ret) 833*04972362SLiu Ying return dev_err_probe(dev, ret, "failed to get power supplies\n"); 834*04972362SLiu Ying 835*04972362SLiu Ying ret = it6263_parse_dt(it); 836*04972362SLiu Ying if (ret) 837*04972362SLiu Ying return ret; 838*04972362SLiu Ying 839*04972362SLiu Ying it6263_hw_reset(reset_gpio); 840*04972362SLiu Ying 841*04972362SLiu Ying ret = it6263_lvds_set_i2c_addr(it); 842*04972362SLiu Ying if (ret) 843*04972362SLiu Ying return dev_err_probe(dev, ret, "failed to set I2C addr\n"); 844*04972362SLiu Ying 845*04972362SLiu Ying it->lvds_i2c = devm_i2c_new_dummy_device(dev, client->adapter, 846*04972362SLiu Ying LVDS_INPUT_CTRL_I2C_ADDR); 847*04972362SLiu Ying if (IS_ERR(it->lvds_i2c)) 848*04972362SLiu Ying dev_err_probe(it->dev, PTR_ERR(it->lvds_i2c), 849*04972362SLiu Ying "failed to allocate I2C device for LVDS\n"); 850*04972362SLiu Ying 851*04972362SLiu Ying it->lvds_regmap = devm_regmap_init_i2c(it->lvds_i2c, 852*04972362SLiu Ying &it6263_lvds_regmap_config); 853*04972362SLiu Ying if (IS_ERR(it->lvds_regmap)) 854*04972362SLiu Ying return dev_err_probe(dev, PTR_ERR(it->lvds_regmap), 855*04972362SLiu Ying "failed to init I2C regmap for LVDS\n"); 856*04972362SLiu Ying 857*04972362SLiu Ying it6263_lvds_config(it); 858*04972362SLiu Ying it6263_hdmi_config(it); 859*04972362SLiu Ying 860*04972362SLiu Ying i2c_set_clientdata(client, it); 861*04972362SLiu Ying 862*04972362SLiu Ying it->bridge.funcs = &it6263_bridge_funcs; 863*04972362SLiu Ying it->bridge.of_node = dev->of_node; 864*04972362SLiu Ying /* IT6263 chip doesn't support HPD interrupt. */ 865*04972362SLiu Ying it->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID | 866*04972362SLiu Ying DRM_BRIDGE_OP_HDMI; 867*04972362SLiu Ying it->bridge.type = DRM_MODE_CONNECTOR_HDMIA; 868*04972362SLiu Ying it->bridge.vendor = "ITE"; 869*04972362SLiu Ying it->bridge.product = "IT6263"; 870*04972362SLiu Ying 871*04972362SLiu Ying return devm_drm_bridge_add(dev, &it->bridge); 872*04972362SLiu Ying } 873*04972362SLiu Ying 874*04972362SLiu Ying static const struct of_device_id it6263_of_match[] = { 875*04972362SLiu Ying { .compatible = "ite,it6263", }, 876*04972362SLiu Ying { } 877*04972362SLiu Ying }; 878*04972362SLiu Ying MODULE_DEVICE_TABLE(of, it6263_of_match); 879*04972362SLiu Ying 880*04972362SLiu Ying static const struct i2c_device_id it6263_i2c_ids[] = { 881*04972362SLiu Ying { "it6263", 0 }, 882*04972362SLiu Ying { } 883*04972362SLiu Ying }; 884*04972362SLiu Ying MODULE_DEVICE_TABLE(i2c, it6263_i2c_ids); 885*04972362SLiu Ying 886*04972362SLiu Ying static struct i2c_driver it6263_driver = { 887*04972362SLiu Ying .probe = it6263_probe, 888*04972362SLiu Ying .driver = { 889*04972362SLiu Ying .name = "it6263", 890*04972362SLiu Ying .of_match_table = it6263_of_match, 891*04972362SLiu Ying }, 892*04972362SLiu Ying .id_table = it6263_i2c_ids, 893*04972362SLiu Ying }; 894*04972362SLiu Ying module_i2c_driver(it6263_driver); 895*04972362SLiu Ying 896*04972362SLiu Ying MODULE_DESCRIPTION("ITE Tech. Inc. IT6263 LVDS/HDMI bridge"); 897*04972362SLiu Ying MODULE_AUTHOR("Liu Ying <victor.liu@nxp.com>"); 898*04972362SLiu Ying MODULE_LICENSE("GPL"); 899