anx7625.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright(c) 2020, Analogix Semiconductor. All rights reserved.
  4. *
  5. */
  6. #ifndef __ANX7625_H__
  7. #define __ANX7625_H__
  8. #define ANX7625_DRV_VERSION "0.1.04"
  9. /* Loading OCM re-trying times */
  10. #define OCM_LOADING_TIME 10
  11. /********* ANX7625 Register **********/
  12. #define TX_P0_ADDR 0x70
  13. #define TX_P1_ADDR 0x7A
  14. #define TX_P2_ADDR 0x72
  15. #define RX_P0_ADDR 0x7e
  16. #define RX_P1_ADDR 0x84
  17. #define RX_P2_ADDR 0x54
  18. #define RSVD_00_ADDR 0x00
  19. #define RSVD_D1_ADDR 0xD1
  20. #define RSVD_60_ADDR 0x60
  21. #define RSVD_39_ADDR 0x39
  22. #define RSVD_7F_ADDR 0x7F
  23. #define TCPC_INTERFACE_ADDR 0x58
  24. /* Clock frequency in Hz */
  25. #define XTAL_FRQ (27 * 1000000)
  26. #define POST_DIVIDER_MIN 1
  27. #define POST_DIVIDER_MAX 16
  28. #define PLL_OUT_FREQ_MIN 520000000UL
  29. #define PLL_OUT_FREQ_MAX 730000000UL
  30. #define PLL_OUT_FREQ_ABS_MIN 300000000UL
  31. #define PLL_OUT_FREQ_ABS_MAX 800000000UL
  32. #define MAX_UNSIGNED_24BIT 16777215UL
  33. /***************************************************************/
  34. /* Register definition of device address 0x58 */
  35. #define PRODUCT_ID_L 0x02
  36. #define PRODUCT_ID_H 0x03
  37. #define INTR_ALERT_1 0xCC
  38. #define INTR_SOFTWARE_INT BIT(3)
  39. #define INTR_RECEIVED_MSG BIT(5)
  40. #define SYSTEM_STSTUS 0x45
  41. #define INTERFACE_CHANGE_INT 0x44
  42. #define HPD_STATUS_CHANGE 0x80
  43. #define HPD_STATUS 0x80
  44. /******** END of I2C Address 0x58 ********/
  45. /***************************************************************/
  46. /* Register definition of device address 0x70 */
  47. #define TX_HDCP_CTRL0 0x01
  48. #define STORE_AN BIT(7)
  49. #define RX_REPEATER BIT(6)
  50. #define RE_AUTHEN BIT(5)
  51. #define SW_AUTH_OK BIT(4)
  52. #define HARD_AUTH_EN BIT(3)
  53. #define ENC_EN BIT(2)
  54. #define BKSV_SRM_PASS BIT(1)
  55. #define KSVLIST_VLD BIT(0)
  56. #define SP_TX_WAIT_R0_TIME 0x40
  57. #define SP_TX_WAIT_KSVR_TIME 0x42
  58. #define SP_TX_SYS_CTRL1_REG 0x80
  59. #define HDCP2TX_FW_EN BIT(4)
  60. #define SP_TX_LINK_BW_SET_REG 0xA0
  61. #define SP_TX_LANE_COUNT_SET_REG 0xA1
  62. #define M_VID_0 0xC0
  63. #define M_VID_1 0xC1
  64. #define M_VID_2 0xC2
  65. #define N_VID_0 0xC3
  66. #define N_VID_1 0xC4
  67. #define N_VID_2 0xC5
  68. #define KEY_START_ADDR 0x9000
  69. #define KEY_RESERVED 416
  70. #define HDCP14KEY_START_ADDR (KEY_START_ADDR + KEY_RESERVED)
  71. #define HDCP14KEY_SIZE 624
  72. /***************************************************************/
  73. /* Register definition of device address 0x72 */
  74. #define AUX_RST 0x04
  75. #define RST_CTRL2 0x07
  76. #define SP_TX_TOTAL_LINE_STA_L 0x24
  77. #define SP_TX_TOTAL_LINE_STA_H 0x25
  78. #define SP_TX_ACT_LINE_STA_L 0x26
  79. #define SP_TX_ACT_LINE_STA_H 0x27
  80. #define SP_TX_V_F_PORCH_STA 0x28
  81. #define SP_TX_V_SYNC_STA 0x29
  82. #define SP_TX_V_B_PORCH_STA 0x2A
  83. #define SP_TX_TOTAL_PIXEL_STA_L 0x2B
  84. #define SP_TX_TOTAL_PIXEL_STA_H 0x2C
  85. #define SP_TX_ACT_PIXEL_STA_L 0x2D
  86. #define SP_TX_ACT_PIXEL_STA_H 0x2E
  87. #define SP_TX_H_F_PORCH_STA_L 0x2F
  88. #define SP_TX_H_F_PORCH_STA_H 0x30
  89. #define SP_TX_H_SYNC_STA_L 0x31
  90. #define SP_TX_H_SYNC_STA_H 0x32
  91. #define SP_TX_H_B_PORCH_STA_L 0x33
  92. #define SP_TX_H_B_PORCH_STA_H 0x34
  93. #define SP_TX_VID_CTRL 0x84
  94. #define SP_TX_BPC_MASK 0xE0
  95. #define SP_TX_BPC_6 0x00
  96. #define SP_TX_BPC_8 0x20
  97. #define SP_TX_BPC_10 0x40
  98. #define SP_TX_BPC_12 0x60
  99. #define VIDEO_BIT_MATRIX_12 0x4c
  100. #define AUDIO_CHANNEL_STATUS_1 0xd0
  101. #define AUDIO_CHANNEL_STATUS_2 0xd1
  102. #define AUDIO_CHANNEL_STATUS_3 0xd2
  103. #define AUDIO_CHANNEL_STATUS_4 0xd3
  104. #define AUDIO_CHANNEL_STATUS_5 0xd4
  105. #define AUDIO_CHANNEL_STATUS_6 0xd5
  106. #define TDM_SLAVE_MODE 0x10
  107. #define I2S_SLAVE_MODE 0x08
  108. #define AUDIO_LAYOUT 0x01
  109. #define HPD_DET_TIMER_BIT0_7 0xea
  110. #define HPD_DET_TIMER_BIT8_15 0xeb
  111. #define HPD_DET_TIMER_BIT16_23 0xec
  112. /* HPD debounce time 2ms for 27M clock */
  113. #define HPD_TIME 54000
  114. #define AUDIO_CONTROL_REGISTER 0xe6
  115. #define TDM_TIMING_MODE 0x08
  116. #define I2C_ADDR_72_DPTX 0x72
  117. #define HP_MIN 8
  118. #define HBLANKING_MIN 80
  119. #define SYNC_LEN_DEF 32
  120. #define HFP_HBP_DEF ((HBLANKING_MIN - SYNC_LEN_DEF) / 2)
  121. #define VIDEO_CONTROL_0 0x08
  122. #define ACTIVE_LINES_L 0x14
  123. #define ACTIVE_LINES_H 0x15 /* Bit[7:6] are reserved */
  124. #define VERTICAL_FRONT_PORCH 0x16
  125. #define VERTICAL_SYNC_WIDTH 0x17
  126. #define VERTICAL_BACK_PORCH 0x18
  127. #define HORIZONTAL_TOTAL_PIXELS_L 0x19
  128. #define HORIZONTAL_TOTAL_PIXELS_H 0x1A /* Bit[7:6] are reserved */
  129. #define HORIZONTAL_ACTIVE_PIXELS_L 0x1B
  130. #define HORIZONTAL_ACTIVE_PIXELS_H 0x1C /* Bit[7:6] are reserved */
  131. #define HORIZONTAL_FRONT_PORCH_L 0x1D
  132. #define HORIZONTAL_FRONT_PORCH_H 0x1E /* Bit[7:4] are reserved */
  133. #define HORIZONTAL_SYNC_WIDTH_L 0x1F
  134. #define HORIZONTAL_SYNC_WIDTH_H 0x20 /* Bit[7:4] are reserved */
  135. #define HORIZONTAL_BACK_PORCH_L 0x21
  136. #define HORIZONTAL_BACK_PORCH_H 0x22 /* Bit[7:4] are reserved */
  137. /******** END of I2C Address 0x72 *********/
  138. /***************************************************************/
  139. /* Register definition of device address 0x7a */
  140. #define DP_TX_SWING_REG_CNT 0x14
  141. #define DP_TX_LANE0_SWING_REG0 0x00
  142. #define DP_TX_LANE1_SWING_REG0 0x14
  143. /******** END of I2C Address 0x7a *********/
  144. /***************************************************************/
  145. /* Register definition of device address 0x7e */
  146. #define I2C_ADDR_7E_FLASH_CONTROLLER 0x7E
  147. #define R_BOOT_RETRY 0x00
  148. #define R_RAM_ADDR_H 0x01
  149. #define R_RAM_ADDR_L 0x02
  150. #define R_RAM_LEN_H 0x03
  151. #define R_RAM_LEN_L 0x04
  152. #define FLASH_LOAD_STA 0x05
  153. #define FLASH_LOAD_STA_CHK BIT(7)
  154. #define R_RAM_CTRL 0x05
  155. /* bit positions */
  156. #define FLASH_DONE BIT(7)
  157. #define BOOT_LOAD_DONE BIT(6)
  158. #define CRC_OK BIT(5)
  159. #define LOAD_DONE BIT(4)
  160. #define O_RW_DONE BIT(3)
  161. #define FUSE_BUSY BIT(2)
  162. #define DECRYPT_EN BIT(1)
  163. #define LOAD_START BIT(0)
  164. #define FLASH_ADDR_HIGH 0x0F
  165. #define FLASH_ADDR_LOW 0x10
  166. #define FLASH_LEN_HIGH 0x31
  167. #define FLASH_LEN_LOW 0x32
  168. #define R_FLASH_RW_CTRL 0x33
  169. /* bit positions */
  170. #define READ_DELAY_SELECT BIT(7)
  171. #define GENERAL_INSTRUCTION_EN BIT(6)
  172. #define FLASH_ERASE_EN BIT(5)
  173. #define RDID_READ_EN BIT(4)
  174. #define REMS_READ_EN BIT(3)
  175. #define WRITE_STATUS_EN BIT(2)
  176. #define FLASH_READ BIT(1)
  177. #define FLASH_WRITE BIT(0)
  178. #define FLASH_BUF_BASE_ADDR 0x60
  179. #define FLASH_BUF_LEN 0x20
  180. #define XTAL_FRQ_SEL 0x3F
  181. /* bit field positions */
  182. #define XTAL_FRQ_SEL_POS 5
  183. /* bit field values */
  184. #define XTAL_FRQ_19M2 (0 << XTAL_FRQ_SEL_POS)
  185. #define XTAL_FRQ_27M (4 << XTAL_FRQ_SEL_POS)
  186. #define R_DSC_CTRL_0 0x40
  187. #define READ_STATUS_EN 7
  188. #define CLK_1MEG_RB 6 /* 1MHz clock reset; 0=reset, 0=reset release */
  189. #define DSC_BIST_DONE 1 /* Bit[5:1]: 1=DSC MBIST pass */
  190. #define DSC_EN 0x01 /* 1=DSC enabled, 0=DSC disabled */
  191. #define OCM_FW_VERSION 0x31
  192. #define OCM_FW_REVERSION 0x32
  193. #define AP_AUX_ADDR_7_0 0x11
  194. #define AP_AUX_ADDR_15_8 0x12
  195. #define AP_AUX_ADDR_19_16 0x13
  196. /* Bit[0:3] AUX status, bit 4 op_en, bit 5 address only */
  197. #define AP_AUX_CTRL_STATUS 0x14
  198. #define AP_AUX_CTRL_OP_EN 0x10
  199. #define AP_AUX_CTRL_ADDRONLY 0x20
  200. #define AP_AUX_BUFF_START 0x15
  201. #define PIXEL_CLOCK_L 0x25
  202. #define PIXEL_CLOCK_H 0x26
  203. #define AP_AUX_COMMAND 0x27 /* com+len */
  204. #define LENGTH_SHIFT 4
  205. #define DPCD_CMD(len, cmd) ((((len) - 1) << LENGTH_SHIFT) | (cmd))
  206. /* Bit 0&1: 3D video structure */
  207. /* 0x01: frame packing, 0x02:Line alternative, 0x03:Side-by-side(full) */
  208. #define AP_AV_STATUS 0x28
  209. #define AP_VIDEO_CHG BIT(2)
  210. #define AP_AUDIO_CHG BIT(3)
  211. #define AP_MIPI_MUTE BIT(4) /* 1:MIPI input mute, 0: ummute */
  212. #define AP_MIPI_RX_EN BIT(5) /* 1: MIPI RX input in 0: no RX in */
  213. #define AP_DISABLE_PD BIT(6)
  214. #define AP_DISABLE_DISPLAY BIT(7)
  215. /***************************************************************/
  216. /* Register definition of device address 0x84 */
  217. #define MIPI_PHY_CONTROL_3 0x03
  218. #define MIPI_HS_PWD_CLK 7
  219. #define MIPI_HS_RT_CLK 6
  220. #define MIPI_PD_CLK 5
  221. #define MIPI_CLK_RT_MANUAL_PD_EN 4
  222. #define MIPI_CLK_HS_MANUAL_PD_EN 3
  223. #define MIPI_CLK_DET_DET_BYPASS 2
  224. #define MIPI_CLK_MISS_CTRL 1
  225. #define MIPI_PD_LPTX_CH_MANUAL_PD_EN 0
  226. #define MIPI_LANE_CTRL_0 0x05
  227. #define MIPI_TIME_HS_PRPR 0x08
  228. /*
  229. * After MIPI RX protocol layer received video frames,
  230. * Protocol layer starts to reconstruct video stream from PHY
  231. */
  232. #define MIPI_VIDEO_STABLE_CNT 0x0A
  233. #define MIPI_LANE_CTRL_10 0x0F
  234. #define MIPI_DIGITAL_ADJ_1 0x1B
  235. #define IVO_MID0 0x26
  236. #define IVO_MID1 0xCF
  237. #define MIPI_PLL_M_NUM_23_16 0x1E
  238. #define MIPI_PLL_M_NUM_15_8 0x1F
  239. #define MIPI_PLL_M_NUM_7_0 0x20
  240. #define MIPI_PLL_N_NUM_23_16 0x21
  241. #define MIPI_PLL_N_NUM_15_8 0x22
  242. #define MIPI_PLL_N_NUM_7_0 0x23
  243. #define MIPI_DIGITAL_PLL_6 0x2A
  244. /* Bit[7:6]: VCO band control, only effective */
  245. #define MIPI_M_NUM_READY 0x10
  246. #define MIPI_N_NUM_READY 0x08
  247. #define STABLE_INTEGER_CNT_EN 0x04
  248. #define MIPI_PLL_TEST_BIT 0
  249. /* Bit[1:0]: test point output select - */
  250. /* 00: VCO power, 01: dvdd_pdt, 10: dvdd, 11: vcox */
  251. #define MIPI_DIGITAL_PLL_7 0x2B
  252. #define MIPI_PLL_FORCE_N_EN 7
  253. #define MIPI_PLL_FORCE_BAND_EN 6
  254. #define MIPI_PLL_VCO_TUNE_REG 4
  255. /* Bit[5:4]: VCO metal capacitance - */
  256. /* 00: +20% fast, 01: +10% fast (default), 10: typical, 11: -10% slow */
  257. #define MIPI_PLL_VCO_TUNE_REG_VAL 0x30
  258. #define MIPI_PLL_PLL_LDO_BIT 2
  259. /* Bit[3:2]: vco_v2i power - */
  260. /* 00: 1.40V, 01: 1.45V (default), 10: 1.50V, 11: 1.55V */
  261. #define MIPI_PLL_RESET_N 0x02
  262. #define MIPI_FRQ_FORCE_NDET 0
  263. #define MIPI_ALERT_CLR_0 0x2D
  264. #define HS_link_error_clear 7
  265. /* This bit itself is S/C, and it clears 0x84:0x31[7] */
  266. #define MIPI_ALERT_OUT_0 0x31
  267. #define check_sum_err_hs_sync 7
  268. /* This bit is cleared by 0x84:0x2D[7] */
  269. #define MIPI_DIGITAL_PLL_8 0x33
  270. #define MIPI_POST_DIV_VAL 4
  271. /* N means divided by (n+1), n = 0~15 */
  272. #define MIPI_EN_LOCK_FRZ 3
  273. #define MIPI_FRQ_COUNTER_RST 2
  274. #define MIPI_FRQ_SET_REG_8 1
  275. /* Bit 0 is reserved */
  276. #define MIPI_DIGITAL_PLL_9 0x34
  277. #define MIPI_DIGITAL_PLL_16 0x3B
  278. #define MIPI_FRQ_FREEZE_NDET 7
  279. #define MIPI_FRQ_REG_SET_ENABLE 6
  280. #define MIPI_REG_FORCE_SEL_EN 5
  281. #define MIPI_REG_SEL_DIV_REG 4
  282. #define MIPI_REG_FORCE_PRE_DIV_EN 3
  283. /* Bit 2 is reserved */
  284. #define MIPI_FREF_D_IND 1
  285. #define REF_CLK_27000KHZ 1
  286. #define REF_CLK_19200KHZ 0
  287. #define MIPI_REG_PLL_PLL_TEST_ENABLE 0
  288. #define MIPI_DIGITAL_PLL_18 0x3D
  289. #define FRQ_COUNT_RB_SEL 7
  290. #define REG_FORCE_POST_DIV_EN 6
  291. #define MIPI_DPI_SELECT 5
  292. #define SELECT_DSI 1
  293. #define SELECT_DPI 0
  294. #define REG_BAUD_DIV_RATIO 0
  295. #define H_BLANK_L 0x3E
  296. /* For DSC only */
  297. #define H_BLANK_H 0x3F
  298. /* For DSC only; note: bit[7:6] are reserved */
  299. #define MIPI_SWAP 0x4A
  300. #define MIPI_SWAP_CH0 7
  301. #define MIPI_SWAP_CH1 6
  302. #define MIPI_SWAP_CH2 5
  303. #define MIPI_SWAP_CH3 4
  304. #define MIPI_SWAP_CLK 3
  305. /* Bit[2:0] are reserved */
  306. /******** END of I2C Address 0x84 *********/
  307. /* DPCD regs */
  308. #define DPCD_DPCD_REV 0x00
  309. #define DPCD_MAX_LINK_RATE 0x01
  310. #define DPCD_MAX_LANE_COUNT 0x02
  311. /********* ANX7625 Register End **********/
  312. /***************** Display *****************/
  313. enum audio_fs {
  314. AUDIO_FS_441K = 0x00,
  315. AUDIO_FS_48K = 0x02,
  316. AUDIO_FS_32K = 0x03,
  317. AUDIO_FS_882K = 0x08,
  318. AUDIO_FS_96K = 0x0a,
  319. AUDIO_FS_1764K = 0x0c,
  320. AUDIO_FS_192K = 0x0e
  321. };
  322. enum audio_wd_len {
  323. AUDIO_W_LEN_16_20MAX = 0x02,
  324. AUDIO_W_LEN_18_20MAX = 0x04,
  325. AUDIO_W_LEN_17_20MAX = 0x0c,
  326. AUDIO_W_LEN_19_20MAX = 0x08,
  327. AUDIO_W_LEN_20_20MAX = 0x0a,
  328. AUDIO_W_LEN_20_24MAX = 0x03,
  329. AUDIO_W_LEN_22_24MAX = 0x05,
  330. AUDIO_W_LEN_21_24MAX = 0x0d,
  331. AUDIO_W_LEN_23_24MAX = 0x09,
  332. AUDIO_W_LEN_24_24MAX = 0x0b
  333. };
  334. #define I2S_CH_2 0x01
  335. #define TDM_CH_4 0x03
  336. #define TDM_CH_6 0x05
  337. #define TDM_CH_8 0x07
  338. #define MAX_DPCD_BUFFER_SIZE 16
  339. #define ONE_BLOCK_SIZE 128
  340. #define FOUR_BLOCK_SIZE (128 * 4)
  341. #define MAX_EDID_BLOCK 3
  342. #define EDID_TRY_CNT 3
  343. #define SUPPORT_PIXEL_CLOCK 300000
  344. struct s_edid_data {
  345. int edid_block_num;
  346. u8 edid_raw_data[FOUR_BLOCK_SIZE];
  347. };
  348. /***************** Display End *****************/
  349. #define MAX_LANES_SUPPORT 4
  350. struct anx7625_platform_data {
  351. struct gpio_desc *gpio_p_on;
  352. struct gpio_desc *gpio_reset;
  353. struct regulator_bulk_data supplies[3];
  354. struct drm_bridge *panel_bridge;
  355. int intp_irq;
  356. int is_dpi;
  357. int mipi_lanes;
  358. int audio_en;
  359. int dp_lane0_swing_reg_cnt;
  360. u8 lane0_reg_data[DP_TX_SWING_REG_CNT];
  361. int dp_lane1_swing_reg_cnt;
  362. u8 lane1_reg_data[DP_TX_SWING_REG_CNT];
  363. u32 low_power_mode;
  364. struct device_node *mipi_host_node;
  365. };
  366. struct anx7625_i2c_client {
  367. struct i2c_client *tx_p0_client;
  368. struct i2c_client *tx_p1_client;
  369. struct i2c_client *tx_p2_client;
  370. struct i2c_client *rx_p0_client;
  371. struct i2c_client *rx_p1_client;
  372. struct i2c_client *rx_p2_client;
  373. struct i2c_client *tcpc_client;
  374. };
  375. struct anx7625_data {
  376. struct anx7625_platform_data pdata;
  377. struct platform_device *audio_pdev;
  378. int hpd_status;
  379. int hpd_high_cnt;
  380. int dp_en;
  381. int hdcp_cp;
  382. /* Lock for work queue */
  383. struct mutex lock;
  384. struct i2c_client *client;
  385. struct anx7625_i2c_client i2c;
  386. struct i2c_client *last_client;
  387. struct timer_list hdcp_timer;
  388. struct s_edid_data slimport_edid_p;
  389. struct device *codec_dev;
  390. hdmi_codec_plugged_cb plugged_cb;
  391. struct work_struct work;
  392. struct workqueue_struct *workqueue;
  393. struct delayed_work hdcp_work;
  394. struct workqueue_struct *hdcp_workqueue;
  395. /* Lock for hdcp work queue */
  396. struct mutex hdcp_wq_lock;
  397. char edid_block;
  398. struct display_timing dt;
  399. u8 display_timing_valid;
  400. struct drm_bridge bridge;
  401. u8 bridge_attached;
  402. struct drm_connector *connector;
  403. struct mipi_dsi_device *dsi;
  404. struct drm_dp_aux aux;
  405. u32 channel;
  406. bool out_of_hibr;
  407. };
  408. #endif /* __ANX7625_H__ */