Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright(c) 2020, Analogix Semiconductor. All rights reserved.
0004  *
0005  */
0006 
0007 #ifndef __ANX7625_H__
0008 #define __ANX7625_H__
0009 
0010 #define ANX7625_DRV_VERSION "0.1.04"
0011 
0012 /* Loading OCM re-trying times */
0013 #define OCM_LOADING_TIME 10
0014 
0015 /*********  ANX7625 Register  **********/
0016 #define TX_P0_ADDR              0x70
0017 #define TX_P1_ADDR              0x7A
0018 #define TX_P2_ADDR              0x72
0019 
0020 #define RX_P0_ADDR              0x7e
0021 #define RX_P1_ADDR              0x84
0022 #define RX_P2_ADDR              0x54
0023 
0024 #define RSVD_00_ADDR                0x00
0025 #define RSVD_D1_ADDR                0xD1
0026 #define RSVD_60_ADDR                0x60
0027 #define RSVD_39_ADDR                0x39
0028 #define RSVD_7F_ADDR                0x7F
0029 
0030 #define TCPC_INTERFACE_ADDR         0x58
0031 
0032 /* Clock frequency in Hz */
0033 #define XTAL_FRQ        (27 * 1000000)
0034 
0035 #define  POST_DIVIDER_MIN   1
0036 #define  POST_DIVIDER_MAX   16
0037 #define  PLL_OUT_FREQ_MIN   520000000UL
0038 #define  PLL_OUT_FREQ_MAX   730000000UL
0039 #define  PLL_OUT_FREQ_ABS_MIN   300000000UL
0040 #define  PLL_OUT_FREQ_ABS_MAX   800000000UL
0041 #define  MAX_UNSIGNED_24BIT 16777215UL
0042 
0043 /***************************************************************/
0044 /* Register definition of device address 0x58 */
0045 
0046 #define PRODUCT_ID_L 0x02
0047 #define PRODUCT_ID_H 0x03
0048 
0049 #define INTR_ALERT_1  0xCC
0050 #define INTR_SOFTWARE_INT BIT(3)
0051 #define INTR_RECEIVED_MSG BIT(5)
0052 
0053 #define SYSTEM_STSTUS 0x45
0054 #define INTERFACE_CHANGE_INT 0x44
0055 #define HPD_STATUS_CHANGE 0x80
0056 #define HPD_STATUS 0x80
0057 
0058 /******** END of I2C Address 0x58 ********/
0059 
0060 /***************************************************************/
0061 /* Register definition of device address 0x70 */
0062 #define TX_HDCP_CTRL0           0x01
0063 #define STORE_AN            BIT(7)
0064 #define RX_REPEATER         BIT(6)
0065 #define RE_AUTHEN           BIT(5)
0066 #define SW_AUTH_OK          BIT(4)
0067 #define HARD_AUTH_EN            BIT(3)
0068 #define ENC_EN              BIT(2)
0069 #define BKSV_SRM_PASS           BIT(1)
0070 #define KSVLIST_VLD         BIT(0)
0071 
0072 #define SP_TX_WAIT_R0_TIME      0x40
0073 #define SP_TX_WAIT_KSVR_TIME        0x42
0074 #define SP_TX_SYS_CTRL1_REG     0x80
0075 #define HDCP2TX_FW_EN           BIT(4)
0076 
0077 #define SP_TX_LINK_BW_SET_REG       0xA0
0078 #define SP_TX_LANE_COUNT_SET_REG    0xA1
0079 
0080 #define M_VID_0 0xC0
0081 #define M_VID_1 0xC1
0082 #define M_VID_2 0xC2
0083 #define N_VID_0 0xC3
0084 #define N_VID_1 0xC4
0085 #define N_VID_2 0xC5
0086 
0087 #define KEY_START_ADDR          0x9000
0088 #define KEY_RESERVED            416
0089 
0090 #define HDCP14KEY_START_ADDR        (KEY_START_ADDR + KEY_RESERVED)
0091 #define HDCP14KEY_SIZE          624
0092 
0093 /***************************************************************/
0094 /* Register definition of device address 0x72 */
0095 #define AUX_RST 0x04
0096 #define RST_CTRL2 0x07
0097 
0098 #define SP_TX_TOTAL_LINE_STA_L 0x24
0099 #define SP_TX_TOTAL_LINE_STA_H 0x25
0100 #define SP_TX_ACT_LINE_STA_L 0x26
0101 #define SP_TX_ACT_LINE_STA_H 0x27
0102 #define SP_TX_V_F_PORCH_STA 0x28
0103 #define SP_TX_V_SYNC_STA 0x29
0104 #define SP_TX_V_B_PORCH_STA 0x2A
0105 #define SP_TX_TOTAL_PIXEL_STA_L 0x2B
0106 #define SP_TX_TOTAL_PIXEL_STA_H 0x2C
0107 #define SP_TX_ACT_PIXEL_STA_L 0x2D
0108 #define SP_TX_ACT_PIXEL_STA_H 0x2E
0109 #define SP_TX_H_F_PORCH_STA_L 0x2F
0110 #define SP_TX_H_F_PORCH_STA_H 0x30
0111 #define SP_TX_H_SYNC_STA_L 0x31
0112 #define SP_TX_H_SYNC_STA_H 0x32
0113 #define SP_TX_H_B_PORCH_STA_L 0x33
0114 #define SP_TX_H_B_PORCH_STA_H 0x34
0115 
0116 #define SP_TX_VID_CTRL 0x84
0117 #define SP_TX_BPC_MASK 0xE0
0118 #define SP_TX_BPC_6    0x00
0119 #define SP_TX_BPC_8    0x20
0120 #define SP_TX_BPC_10   0x40
0121 #define SP_TX_BPC_12   0x60
0122 
0123 #define VIDEO_BIT_MATRIX_12 0x4c
0124 
0125 #define AUDIO_CHANNEL_STATUS_1 0xd0
0126 #define AUDIO_CHANNEL_STATUS_2 0xd1
0127 #define AUDIO_CHANNEL_STATUS_3 0xd2
0128 #define AUDIO_CHANNEL_STATUS_4 0xd3
0129 #define AUDIO_CHANNEL_STATUS_5 0xd4
0130 #define AUDIO_CHANNEL_STATUS_6 0xd5
0131 #define TDM_SLAVE_MODE 0x10
0132 #define I2S_SLAVE_MODE 0x08
0133 #define AUDIO_LAYOUT   0x01
0134 
0135 #define AUDIO_CONTROL_REGISTER 0xe6
0136 #define TDM_TIMING_MODE 0x08
0137 
0138 #define I2C_ADDR_72_DPTX              0x72
0139 
0140 #define HP_MIN          8
0141 #define HBLANKING_MIN       80
0142 #define SYNC_LEN_DEF        32
0143 #define HFP_HBP_DEF     ((HBLANKING_MIN - SYNC_LEN_DEF) / 2)
0144 #define VIDEO_CONTROL_0 0x08
0145 
0146 #define  ACTIVE_LINES_L         0x14
0147 #define  ACTIVE_LINES_H         0x15  /* Bit[7:6] are reserved */
0148 #define  VERTICAL_FRONT_PORCH   0x16
0149 #define  VERTICAL_SYNC_WIDTH    0x17
0150 #define  VERTICAL_BACK_PORCH    0x18
0151 
0152 #define  HORIZONTAL_TOTAL_PIXELS_L    0x19
0153 #define  HORIZONTAL_TOTAL_PIXELS_H    0x1A  /* Bit[7:6] are reserved */
0154 #define  HORIZONTAL_ACTIVE_PIXELS_L   0x1B
0155 #define  HORIZONTAL_ACTIVE_PIXELS_H   0x1C  /* Bit[7:6] are reserved */
0156 #define  HORIZONTAL_FRONT_PORCH_L     0x1D
0157 #define  HORIZONTAL_FRONT_PORCH_H     0x1E  /* Bit[7:4] are reserved */
0158 #define  HORIZONTAL_SYNC_WIDTH_L      0x1F
0159 #define  HORIZONTAL_SYNC_WIDTH_H      0x20  /* Bit[7:4] are reserved */
0160 #define  HORIZONTAL_BACK_PORCH_L      0x21
0161 #define  HORIZONTAL_BACK_PORCH_H      0x22  /* Bit[7:4] are reserved */
0162 
0163 /******** END of I2C Address 0x72 *********/
0164 
0165 /***************************************************************/
0166 /* Register definition of device address 0x7a */
0167 #define DP_TX_SWING_REG_CNT     0x14
0168 #define DP_TX_LANE0_SWING_REG0      0x00
0169 #define DP_TX_LANE1_SWING_REG0      0x14
0170 /******** END of I2C Address 0x7a *********/
0171 
0172 /***************************************************************/
0173 /* Register definition of device address 0x7e */
0174 
0175 #define  I2C_ADDR_7E_FLASH_CONTROLLER  0x7E
0176 
0177 #define R_BOOT_RETRY        0x00
0178 #define R_RAM_ADDR_H        0x01
0179 #define R_RAM_ADDR_L        0x02
0180 #define R_RAM_LEN_H     0x03
0181 #define R_RAM_LEN_L     0x04
0182 #define FLASH_LOAD_STA          0x05
0183 #define FLASH_LOAD_STA_CHK  BIT(7)
0184 
0185 #define R_RAM_CTRL              0x05
0186 /* bit positions */
0187 #define FLASH_DONE              BIT(7)
0188 #define BOOT_LOAD_DONE          BIT(6)
0189 #define CRC_OK                  BIT(5)
0190 #define LOAD_DONE               BIT(4)
0191 #define O_RW_DONE               BIT(3)
0192 #define FUSE_BUSY               BIT(2)
0193 #define DECRYPT_EN              BIT(1)
0194 #define LOAD_START              BIT(0)
0195 
0196 #define FLASH_ADDR_HIGH         0x0F
0197 #define FLASH_ADDR_LOW          0x10
0198 #define FLASH_LEN_HIGH          0x31
0199 #define FLASH_LEN_LOW           0x32
0200 #define R_FLASH_RW_CTRL         0x33
0201 /* bit positions */
0202 #define READ_DELAY_SELECT       BIT(7)
0203 #define GENERAL_INSTRUCTION_EN  BIT(6)
0204 #define FLASH_ERASE_EN          BIT(5)
0205 #define RDID_READ_EN            BIT(4)
0206 #define REMS_READ_EN            BIT(3)
0207 #define WRITE_STATUS_EN         BIT(2)
0208 #define FLASH_READ              BIT(1)
0209 #define FLASH_WRITE             BIT(0)
0210 
0211 #define FLASH_BUF_BASE_ADDR     0x60
0212 #define FLASH_BUF_LEN           0x20
0213 
0214 #define  XTAL_FRQ_SEL    0x3F
0215 /* bit field positions */
0216 #define  XTAL_FRQ_SEL_POS    5
0217 /* bit field values */
0218 #define  XTAL_FRQ_19M2   (0 << XTAL_FRQ_SEL_POS)
0219 #define  XTAL_FRQ_27M    (4 << XTAL_FRQ_SEL_POS)
0220 
0221 #define  R_DSC_CTRL_0    0x40
0222 #define  READ_STATUS_EN  7
0223 #define  CLK_1MEG_RB     6  /* 1MHz clock reset; 0=reset, 0=reset release */
0224 #define  DSC_BIST_DONE   1  /* Bit[5:1]: 1=DSC MBIST pass */
0225 #define  DSC_EN          0x01  /* 1=DSC enabled, 0=DSC disabled */
0226 
0227 #define OCM_FW_VERSION   0x31
0228 #define OCM_FW_REVERSION 0x32
0229 
0230 #define AP_AUX_ADDR_7_0   0x11
0231 #define AP_AUX_ADDR_15_8  0x12
0232 #define AP_AUX_ADDR_19_16 0x13
0233 
0234 /* Bit[0:3] AUX status, bit 4 op_en, bit 5 address only */
0235 #define AP_AUX_CTRL_STATUS 0x14
0236 #define AP_AUX_CTRL_OP_EN 0x10
0237 #define AP_AUX_CTRL_ADDRONLY 0x20
0238 
0239 #define AP_AUX_BUFF_START 0x15
0240 #define PIXEL_CLOCK_L   0x25
0241 #define PIXEL_CLOCK_H   0x26
0242 
0243 #define AP_AUX_COMMAND  0x27  /* com+len */
0244 #define LENGTH_SHIFT    4
0245 #define DPCD_CMD(len, cmd)  ((((len) - 1) << LENGTH_SHIFT) | (cmd))
0246 
0247 /* Bit 0&1: 3D video structure */
0248 /* 0x01: frame packing,  0x02:Line alternative, 0x03:Side-by-side(full) */
0249 #define AP_AV_STATUS 0x28
0250 #define AP_VIDEO_CHG  BIT(2)
0251 #define AP_AUDIO_CHG  BIT(3)
0252 #define AP_MIPI_MUTE  BIT(4) /* 1:MIPI input mute, 0: ummute */
0253 #define AP_MIPI_RX_EN BIT(5) /* 1: MIPI RX input in  0: no RX in */
0254 #define AP_DISABLE_PD BIT(6)
0255 #define AP_DISABLE_DISPLAY BIT(7)
0256 /***************************************************************/
0257 /* Register definition of device address 0x84 */
0258 #define  MIPI_PHY_CONTROL_3            0x03
0259 #define  MIPI_HS_PWD_CLK               7
0260 #define  MIPI_HS_RT_CLK                6
0261 #define  MIPI_PD_CLK                   5
0262 #define  MIPI_CLK_RT_MANUAL_PD_EN      4
0263 #define  MIPI_CLK_HS_MANUAL_PD_EN      3
0264 #define  MIPI_CLK_DET_DET_BYPASS       2
0265 #define  MIPI_CLK_MISS_CTRL            1
0266 #define  MIPI_PD_LPTX_CH_MANUAL_PD_EN  0
0267 
0268 #define  MIPI_LANE_CTRL_0       0x05
0269 #define  MIPI_TIME_HS_PRPR      0x08
0270 
0271 /*
0272  * After MIPI RX protocol layer received video frames,
0273  * Protocol layer starts to reconstruct video stream from PHY
0274  */
0275 #define  MIPI_VIDEO_STABLE_CNT           0x0A
0276 
0277 #define  MIPI_LANE_CTRL_10               0x0F
0278 #define  MIPI_DIGITAL_ADJ_1     0x1B
0279 #define  IVO_MID0               0x26
0280 #define  IVO_MID1               0xCF
0281 
0282 #define  MIPI_PLL_M_NUM_23_16   0x1E
0283 #define  MIPI_PLL_M_NUM_15_8    0x1F
0284 #define  MIPI_PLL_M_NUM_7_0     0x20
0285 #define  MIPI_PLL_N_NUM_23_16   0x21
0286 #define  MIPI_PLL_N_NUM_15_8    0x22
0287 #define  MIPI_PLL_N_NUM_7_0     0x23
0288 
0289 #define  MIPI_DIGITAL_PLL_6     0x2A
0290 /* Bit[7:6]: VCO band control, only effective */
0291 #define  MIPI_M_NUM_READY        0x10
0292 #define  MIPI_N_NUM_READY        0x08
0293 #define  STABLE_INTEGER_CNT_EN   0x04
0294 #define  MIPI_PLL_TEST_BIT       0
0295 /* Bit[1:0]: test point output select - */
0296 /* 00: VCO power, 01: dvdd_pdt, 10: dvdd, 11: vcox */
0297 
0298 #define  MIPI_DIGITAL_PLL_7      0x2B
0299 #define  MIPI_PLL_FORCE_N_EN     7
0300 #define  MIPI_PLL_FORCE_BAND_EN  6
0301 
0302 #define  MIPI_PLL_VCO_TUNE_REG   4
0303 /* Bit[5:4]: VCO metal capacitance - */
0304 /* 00: +20% fast, 01: +10% fast (default), 10: typical, 11: -10% slow */
0305 #define  MIPI_PLL_VCO_TUNE_REG_VAL   0x30
0306 
0307 #define  MIPI_PLL_PLL_LDO_BIT    2
0308 /* Bit[3:2]: vco_v2i power - */
0309 /* 00: 1.40V, 01: 1.45V (default), 10: 1.50V, 11: 1.55V */
0310 #define  MIPI_PLL_RESET_N        0x02
0311 #define  MIPI_FRQ_FORCE_NDET     0
0312 
0313 #define  MIPI_ALERT_CLR_0        0x2D
0314 #define  HS_link_error_clear     7
0315 /* This bit itself is S/C, and it clears 0x84:0x31[7] */
0316 
0317 #define  MIPI_ALERT_OUT_0        0x31
0318 #define  check_sum_err_hs_sync   7
0319 /* This bit is cleared by 0x84:0x2D[7] */
0320 
0321 #define  MIPI_DIGITAL_PLL_8    0x33
0322 #define  MIPI_POST_DIV_VAL     4
0323 /* N means divided by (n+1), n = 0~15 */
0324 #define  MIPI_EN_LOCK_FRZ      3
0325 #define  MIPI_FRQ_COUNTER_RST  2
0326 #define  MIPI_FRQ_SET_REG_8    1
0327 /* Bit 0 is reserved */
0328 
0329 #define  MIPI_DIGITAL_PLL_9    0x34
0330 
0331 #define  MIPI_DIGITAL_PLL_16   0x3B
0332 #define  MIPI_FRQ_FREEZE_NDET          7
0333 #define  MIPI_FRQ_REG_SET_ENABLE       6
0334 #define  MIPI_REG_FORCE_SEL_EN         5
0335 #define  MIPI_REG_SEL_DIV_REG          4
0336 #define  MIPI_REG_FORCE_PRE_DIV_EN     3
0337 /* Bit 2 is reserved */
0338 #define  MIPI_FREF_D_IND               1
0339 #define  REF_CLK_27000KHZ    1
0340 #define  REF_CLK_19200KHZ    0
0341 #define  MIPI_REG_PLL_PLL_TEST_ENABLE  0
0342 
0343 #define  MIPI_DIGITAL_PLL_18  0x3D
0344 #define  FRQ_COUNT_RB_SEL       7
0345 #define  REG_FORCE_POST_DIV_EN  6
0346 #define  MIPI_DPI_SELECT        5
0347 #define  SELECT_DSI  1
0348 #define  SELECT_DPI  0
0349 #define  REG_BAUD_DIV_RATIO     0
0350 
0351 #define  H_BLANK_L            0x3E
0352 /* For DSC only */
0353 #define  H_BLANK_H            0x3F
0354 /* For DSC only; note: bit[7:6] are reserved */
0355 #define  MIPI_SWAP  0x4A
0356 #define  MIPI_SWAP_CH0    7
0357 #define  MIPI_SWAP_CH1    6
0358 #define  MIPI_SWAP_CH2    5
0359 #define  MIPI_SWAP_CH3    4
0360 #define  MIPI_SWAP_CLK    3
0361 /* Bit[2:0] are reserved */
0362 
0363 /******** END of I2C Address 0x84 *********/
0364 
0365 /* DPCD regs */
0366 #define DPCD_DPCD_REV                  0x00
0367 #define DPCD_MAX_LINK_RATE             0x01
0368 #define DPCD_MAX_LANE_COUNT            0x02
0369 
0370 /*********  ANX7625 Register End  **********/
0371 
0372 /***************** Display *****************/
0373 enum audio_fs {
0374     AUDIO_FS_441K  = 0x00,
0375     AUDIO_FS_48K   = 0x02,
0376     AUDIO_FS_32K   = 0x03,
0377     AUDIO_FS_882K  = 0x08,
0378     AUDIO_FS_96K   = 0x0a,
0379     AUDIO_FS_1764K = 0x0c,
0380     AUDIO_FS_192K  = 0x0e
0381 };
0382 
0383 enum audio_wd_len {
0384     AUDIO_W_LEN_16_20MAX = 0x02,
0385     AUDIO_W_LEN_18_20MAX = 0x04,
0386     AUDIO_W_LEN_17_20MAX = 0x0c,
0387     AUDIO_W_LEN_19_20MAX = 0x08,
0388     AUDIO_W_LEN_20_20MAX = 0x0a,
0389     AUDIO_W_LEN_20_24MAX = 0x03,
0390     AUDIO_W_LEN_22_24MAX = 0x05,
0391     AUDIO_W_LEN_21_24MAX = 0x0d,
0392     AUDIO_W_LEN_23_24MAX = 0x09,
0393     AUDIO_W_LEN_24_24MAX = 0x0b
0394 };
0395 
0396 #define I2S_CH_2    0x01
0397 #define TDM_CH_4    0x03
0398 #define TDM_CH_6    0x05
0399 #define TDM_CH_8    0x07
0400 
0401 #define MAX_DPCD_BUFFER_SIZE    16
0402 
0403 #define ONE_BLOCK_SIZE      128
0404 #define FOUR_BLOCK_SIZE     (128 * 4)
0405 
0406 #define MAX_EDID_BLOCK  3
0407 #define EDID_TRY_CNT    3
0408 #define SUPPORT_PIXEL_CLOCK 300000
0409 
0410 struct s_edid_data {
0411     int edid_block_num;
0412     u8 edid_raw_data[FOUR_BLOCK_SIZE];
0413 };
0414 
0415 /***************** Display End *****************/
0416 
0417 #define MAX_LANES_SUPPORT   4
0418 
0419 struct anx7625_platform_data {
0420     struct gpio_desc *gpio_p_on;
0421     struct gpio_desc *gpio_reset;
0422     struct regulator_bulk_data supplies[3];
0423     struct drm_bridge *panel_bridge;
0424     int intp_irq;
0425     int is_dpi;
0426     int mipi_lanes;
0427     int audio_en;
0428     int dp_lane0_swing_reg_cnt;
0429     u8 lane0_reg_data[DP_TX_SWING_REG_CNT];
0430     int dp_lane1_swing_reg_cnt;
0431     u8 lane1_reg_data[DP_TX_SWING_REG_CNT];
0432     u32 low_power_mode;
0433     struct device_node *mipi_host_node;
0434 };
0435 
0436 struct anx7625_i2c_client {
0437     struct i2c_client *tx_p0_client;
0438     struct i2c_client *tx_p1_client;
0439     struct i2c_client *tx_p2_client;
0440     struct i2c_client *rx_p0_client;
0441     struct i2c_client *rx_p1_client;
0442     struct i2c_client *rx_p2_client;
0443     struct i2c_client *tcpc_client;
0444 };
0445 
0446 struct anx7625_data {
0447     struct anx7625_platform_data pdata;
0448     struct platform_device *audio_pdev;
0449     int hpd_status;
0450     int hpd_high_cnt;
0451     int dp_en;
0452     int hdcp_cp;
0453     /* Lock for work queue */
0454     struct mutex lock;
0455     struct i2c_client *client;
0456     struct anx7625_i2c_client i2c;
0457     struct i2c_client *last_client;
0458     struct timer_list hdcp_timer;
0459     struct s_edid_data slimport_edid_p;
0460     struct device *codec_dev;
0461     hdmi_codec_plugged_cb plugged_cb;
0462     struct work_struct work;
0463     struct workqueue_struct *workqueue;
0464     struct delayed_work hdcp_work;
0465     struct workqueue_struct *hdcp_workqueue;
0466     /* Lock for hdcp work queue */
0467     struct mutex hdcp_wq_lock;
0468     char edid_block;
0469     struct display_timing dt;
0470     u8 display_timing_valid;
0471     struct drm_bridge bridge;
0472     u8 bridge_attached;
0473     struct drm_connector *connector;
0474     struct mipi_dsi_device *dsi;
0475     struct drm_dp_aux aux;
0476 };
0477 
0478 #endif  /* __ANX7625_H__ */