adv7511.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. /*
  2. * Analog Devices ADV7511 HDMI transmitter driver
  3. *
  4. * Copyright 2012 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2.
  7. */
  8. #ifndef __DRM_I2C_ADV7511_H__
  9. #define __DRM_I2C_ADV7511_H__
  10. #include <linux/hdmi.h>
  11. #include <linux/i2c.h>
  12. #include <linux/regmap.h>
  13. #include <linux/regulator/consumer.h>
  14. #include <drm/drm_crtc_helper.h>
  15. #include <drm/drm_mipi_dsi.h>
  16. #define ADV7511_REG_CHIP_REVISION 0x00
  17. #define ADV7511_REG_N0 0x01
  18. #define ADV7511_REG_N1 0x02
  19. #define ADV7511_REG_N2 0x03
  20. #define ADV7511_REG_SPDIF_FREQ 0x04
  21. #define ADV7511_REG_CTS_AUTOMATIC1 0x05
  22. #define ADV7511_REG_CTS_AUTOMATIC2 0x06
  23. #define ADV7511_REG_CTS_MANUAL0 0x07
  24. #define ADV7511_REG_CTS_MANUAL1 0x08
  25. #define ADV7511_REG_CTS_MANUAL2 0x09
  26. #define ADV7511_REG_AUDIO_SOURCE 0x0a
  27. #define ADV7511_REG_AUDIO_CONFIG 0x0b
  28. #define ADV7511_REG_I2S_CONFIG 0x0c
  29. #define ADV7511_REG_I2S_WIDTH 0x0d
  30. #define ADV7511_REG_AUDIO_SUB_SRC0 0x0e
  31. #define ADV7511_REG_AUDIO_SUB_SRC1 0x0f
  32. #define ADV7511_REG_AUDIO_SUB_SRC2 0x10
  33. #define ADV7511_REG_AUDIO_SUB_SRC3 0x11
  34. #define ADV7511_REG_AUDIO_CFG1 0x12
  35. #define ADV7511_REG_AUDIO_CFG2 0x13
  36. #define ADV7511_REG_AUDIO_CFG3 0x14
  37. #define ADV7511_REG_I2C_FREQ_ID_CFG 0x15
  38. #define ADV7511_REG_VIDEO_INPUT_CFG1 0x16
  39. #define ADV7511_REG_CSC_UPPER(x) (0x18 + (x) * 2)
  40. #define ADV7511_REG_CSC_LOWER(x) (0x19 + (x) * 2)
  41. #define ADV7511_REG_SYNC_DECODER(x) (0x30 + (x))
  42. #define ADV7511_REG_DE_GENERATOR (0x35 + (x))
  43. #define ADV7511_REG_PIXEL_REPETITION 0x3b
  44. #define ADV7511_REG_VIC_MANUAL 0x3c
  45. #define ADV7511_REG_VIC_SEND 0x3d
  46. #define ADV7511_REG_VIC_DETECTED 0x3e
  47. #define ADV7511_REG_AUX_VIC_DETECTED 0x3f
  48. #define ADV7511_REG_PACKET_ENABLE0 0x40
  49. #define ADV7511_REG_POWER 0x41
  50. #define ADV7511_REG_STATUS 0x42
  51. #define ADV7511_REG_EDID_I2C_ADDR 0x43
  52. #define ADV7511_REG_PACKET_ENABLE1 0x44
  53. #define ADV7511_REG_PACKET_I2C_ADDR 0x45
  54. #define ADV7511_REG_DSD_ENABLE 0x46
  55. #define ADV7511_REG_VIDEO_INPUT_CFG2 0x48
  56. #define ADV7511_REG_INFOFRAME_UPDATE 0x4a
  57. #define ADV7511_REG_GC(x) (0x4b + (x)) /* 0x4b - 0x51 */
  58. #define ADV7511_REG_AVI_INFOFRAME_VERSION 0x52
  59. #define ADV7511_REG_AVI_INFOFRAME_LENGTH 0x53
  60. #define ADV7511_REG_AVI_INFOFRAME_CHECKSUM 0x54
  61. #define ADV7511_REG_AVI_INFOFRAME(x) (0x55 + (x)) /* 0x55 - 0x6f */
  62. #define ADV7511_REG_AUDIO_INFOFRAME_VERSION 0x70
  63. #define ADV7511_REG_AUDIO_INFOFRAME_LENGTH 0x71
  64. #define ADV7511_REG_AUDIO_INFOFRAME_CHECKSUM 0x72
  65. #define ADV7511_REG_AUDIO_INFOFRAME(x) (0x73 + (x)) /* 0x73 - 0x7c */
  66. #define ADV7511_REG_INT_ENABLE(x) (0x94 + (x))
  67. #define ADV7511_REG_INT(x) (0x96 + (x))
  68. #define ADV7511_REG_INPUT_CLK_DIV 0x9d
  69. #define ADV7511_REG_PLL_STATUS 0x9e
  70. #define ADV7511_REG_HDMI_POWER 0xa1
  71. #define ADV7511_REG_HDCP_HDMI_CFG 0xaf
  72. #define ADV7511_REG_AN(x) (0xb0 + (x)) /* 0xb0 - 0xb7 */
  73. #define ADV7511_REG_HDCP_STATUS 0xb8
  74. #define ADV7511_REG_BCAPS 0xbe
  75. #define ADV7511_REG_BKSV(x) (0xc0 + (x)) /* 0xc0 - 0xc3 */
  76. #define ADV7511_REG_EDID_SEGMENT 0xc4
  77. #define ADV7511_REG_DDC_STATUS 0xc8
  78. #define ADV7511_REG_EDID_READ_CTRL 0xc9
  79. #define ADV7511_REG_BSTATUS(x) (0xca + (x)) /* 0xca - 0xcb */
  80. #define ADV7511_REG_TIMING_GEN_SEQ 0xd0
  81. #define ADV7511_REG_POWER2 0xd6
  82. #define ADV7511_REG_HSYNC_PLACEMENT_MSB 0xfa
  83. #define ADV7511_REG_SYNC_ADJUSTMENT(x) (0xd7 + (x)) /* 0xd7 - 0xdc */
  84. #define ADV7511_REG_TMDS_CLOCK_INV 0xde
  85. #define ADV7511_REG_ARC_CTRL 0xdf
  86. #define ADV7511_REG_CEC_I2C_ADDR 0xe1
  87. #define ADV7511_REG_CEC_CTRL 0xe2
  88. #define ADV7511_REG_CHIP_ID_HIGH 0xf5
  89. #define ADV7511_REG_CHIP_ID_LOW 0xf6
  90. #define ADV7511_CSC_ENABLE BIT(7)
  91. #define ADV7511_CSC_UPDATE_MODE BIT(5)
  92. #define ADV7511_INT0_HPD BIT(7)
  93. #define ADV7511_INT0_VSYNC BIT(5)
  94. #define ADV7511_INT0_AUDIO_FIFO_FULL BIT(4)
  95. #define ADV7511_INT0_EDID_READY BIT(2)
  96. #define ADV7511_INT0_HDCP_AUTHENTICATED BIT(1)
  97. #define ADV7511_INT1_DDC_ERROR BIT(7)
  98. #define ADV7511_INT1_BKSV BIT(6)
  99. #define ADV7511_INT1_CEC_TX_READY BIT(5)
  100. #define ADV7511_INT1_CEC_TX_ARBIT_LOST BIT(4)
  101. #define ADV7511_INT1_CEC_TX_RETRY_TIMEOUT BIT(3)
  102. #define ADV7511_INT1_CEC_RX_READY3 BIT(2)
  103. #define ADV7511_INT1_CEC_RX_READY2 BIT(1)
  104. #define ADV7511_INT1_CEC_RX_READY1 BIT(0)
  105. #define ADV7511_ARC_CTRL_POWER_DOWN BIT(0)
  106. #define ADV7511_CEC_CTRL_POWER_DOWN BIT(0)
  107. #define ADV7511_POWER_POWER_DOWN BIT(6)
  108. #define ADV7511_HDMI_CFG_MODE_MASK 0x2
  109. #define ADV7511_HDMI_CFG_MODE_DVI 0x0
  110. #define ADV7511_HDMI_CFG_MODE_HDMI 0x2
  111. #define ADV7511_AUDIO_SELECT_I2C 0x0
  112. #define ADV7511_AUDIO_SELECT_SPDIF 0x1
  113. #define ADV7511_AUDIO_SELECT_DSD 0x2
  114. #define ADV7511_AUDIO_SELECT_HBR 0x3
  115. #define ADV7511_AUDIO_SELECT_DST 0x4
  116. #define ADV7511_I2S_SAMPLE_LEN_16 0x2
  117. #define ADV7511_I2S_SAMPLE_LEN_20 0x3
  118. #define ADV7511_I2S_SAMPLE_LEN_18 0x4
  119. #define ADV7511_I2S_SAMPLE_LEN_22 0x5
  120. #define ADV7511_I2S_SAMPLE_LEN_19 0x8
  121. #define ADV7511_I2S_SAMPLE_LEN_23 0x9
  122. #define ADV7511_I2S_SAMPLE_LEN_24 0xb
  123. #define ADV7511_I2S_SAMPLE_LEN_17 0xc
  124. #define ADV7511_I2S_SAMPLE_LEN_21 0xd
  125. #define ADV7511_SAMPLE_FREQ_44100 0x0
  126. #define ADV7511_SAMPLE_FREQ_48000 0x2
  127. #define ADV7511_SAMPLE_FREQ_32000 0x3
  128. #define ADV7511_SAMPLE_FREQ_88200 0x8
  129. #define ADV7511_SAMPLE_FREQ_96000 0xa
  130. #define ADV7511_SAMPLE_FREQ_176400 0xc
  131. #define ADV7511_SAMPLE_FREQ_192000 0xe
  132. #define ADV7511_STATUS_POWER_DOWN_POLARITY BIT(7)
  133. #define ADV7511_STATUS_HPD BIT(6)
  134. #define ADV7511_STATUS_MONITOR_SENSE BIT(5)
  135. #define ADV7511_STATUS_I2S_32BIT_MODE BIT(3)
  136. #define ADV7511_PACKET_ENABLE_N_CTS BIT(8+6)
  137. #define ADV7511_PACKET_ENABLE_AUDIO_SAMPLE BIT(8+5)
  138. #define ADV7511_PACKET_ENABLE_AVI_INFOFRAME BIT(8+4)
  139. #define ADV7511_PACKET_ENABLE_AUDIO_INFOFRAME BIT(8+3)
  140. #define ADV7511_PACKET_ENABLE_GC BIT(7)
  141. #define ADV7511_PACKET_ENABLE_SPD BIT(6)
  142. #define ADV7511_PACKET_ENABLE_MPEG BIT(5)
  143. #define ADV7511_PACKET_ENABLE_ACP BIT(4)
  144. #define ADV7511_PACKET_ENABLE_ISRC BIT(3)
  145. #define ADV7511_PACKET_ENABLE_GM BIT(2)
  146. #define ADV7511_PACKET_ENABLE_SPARE2 BIT(1)
  147. #define ADV7511_PACKET_ENABLE_SPARE1 BIT(0)
  148. #define ADV7511_REG_POWER2_HPD_SRC_MASK 0xc0
  149. #define ADV7511_REG_POWER2_HPD_SRC_BOTH 0x00
  150. #define ADV7511_REG_POWER2_HPD_SRC_HPD 0x40
  151. #define ADV7511_REG_POWER2_HPD_SRC_CEC 0x80
  152. #define ADV7511_REG_POWER2_HPD_SRC_NONE 0xc0
  153. #define ADV7511_REG_POWER2_TDMS_ENABLE BIT(4)
  154. #define ADV7511_REG_POWER2_GATE_INPUT_CLK BIT(0)
  155. #define ADV7511_LOW_REFRESH_RATE_NONE 0x0
  156. #define ADV7511_LOW_REFRESH_RATE_24HZ 0x1
  157. #define ADV7511_LOW_REFRESH_RATE_25HZ 0x2
  158. #define ADV7511_LOW_REFRESH_RATE_30HZ 0x3
  159. #define ADV7511_AUDIO_CFG3_LEN_MASK 0x0f
  160. #define ADV7511_I2C_FREQ_ID_CFG_RATE_MASK 0xf0
  161. #define ADV7511_AUDIO_SOURCE_I2S 0
  162. #define ADV7511_AUDIO_SOURCE_SPDIF 1
  163. #define ADV7511_I2S_FORMAT_I2S 0
  164. #define ADV7511_I2S_FORMAT_RIGHT_J 1
  165. #define ADV7511_I2S_FORMAT_LEFT_J 2
  166. #define ADV7511_PACKET(p, x) ((p) * 0x20 + (x))
  167. #define ADV7511_PACKET_SDP(x) ADV7511_PACKET(0, x)
  168. #define ADV7511_PACKET_MPEG(x) ADV7511_PACKET(1, x)
  169. #define ADV7511_PACKET_ACP(x) ADV7511_PACKET(2, x)
  170. #define ADV7511_PACKET_ISRC1(x) ADV7511_PACKET(3, x)
  171. #define ADV7511_PACKET_ISRC2(x) ADV7511_PACKET(4, x)
  172. #define ADV7511_PACKET_GM(x) ADV7511_PACKET(5, x)
  173. #define ADV7511_PACKET_SPARE(x) ADV7511_PACKET(6, x)
  174. enum adv7511_input_clock {
  175. ADV7511_INPUT_CLOCK_1X,
  176. ADV7511_INPUT_CLOCK_2X,
  177. ADV7511_INPUT_CLOCK_DDR,
  178. };
  179. enum adv7511_input_justification {
  180. ADV7511_INPUT_JUSTIFICATION_EVENLY = 0,
  181. ADV7511_INPUT_JUSTIFICATION_RIGHT = 1,
  182. ADV7511_INPUT_JUSTIFICATION_LEFT = 2,
  183. };
  184. enum adv7511_input_sync_pulse {
  185. ADV7511_INPUT_SYNC_PULSE_DE = 0,
  186. ADV7511_INPUT_SYNC_PULSE_HSYNC = 1,
  187. ADV7511_INPUT_SYNC_PULSE_VSYNC = 2,
  188. ADV7511_INPUT_SYNC_PULSE_NONE = 3,
  189. };
  190. /**
  191. * enum adv7511_sync_polarity - Polarity for the input sync signals
  192. * @ADV7511_SYNC_POLARITY_PASSTHROUGH: Sync polarity matches that of
  193. * the currently configured mode.
  194. * @ADV7511_SYNC_POLARITY_LOW: Sync polarity is low
  195. * @ADV7511_SYNC_POLARITY_HIGH: Sync polarity is high
  196. *
  197. * If the polarity is set to either LOW or HIGH the driver will configure the
  198. * ADV7511 to internally invert the sync signal if required to match the sync
  199. * polarity setting for the currently selected output mode.
  200. *
  201. * If the polarity is set to PASSTHROUGH, the ADV7511 will route the signal
  202. * unchanged. This is used when the upstream graphics core already generates
  203. * the sync signals with the correct polarity.
  204. */
  205. enum adv7511_sync_polarity {
  206. ADV7511_SYNC_POLARITY_PASSTHROUGH,
  207. ADV7511_SYNC_POLARITY_LOW,
  208. ADV7511_SYNC_POLARITY_HIGH,
  209. };
  210. /**
  211. * struct adv7511_link_config - Describes adv7511 hardware configuration
  212. * @input_color_depth: Number of bits per color component (8, 10 or 12)
  213. * @input_colorspace: The input colorspace (RGB, YUV444, YUV422)
  214. * @input_clock: The input video clock style (1x, 2x, DDR)
  215. * @input_style: The input component arrangement variant
  216. * @input_justification: Video input format bit justification
  217. * @clock_delay: Clock delay for the input clock (in ps)
  218. * @embedded_sync: Video input uses BT.656-style embedded sync
  219. * @sync_pulse: Select the sync pulse
  220. * @vsync_polarity: vsync input signal configuration
  221. * @hsync_polarity: hsync input signal configuration
  222. */
  223. struct adv7511_link_config {
  224. unsigned int input_color_depth;
  225. enum hdmi_colorspace input_colorspace;
  226. enum adv7511_input_clock input_clock;
  227. unsigned int input_style;
  228. enum adv7511_input_justification input_justification;
  229. int clock_delay;
  230. bool embedded_sync;
  231. enum adv7511_input_sync_pulse sync_pulse;
  232. enum adv7511_sync_polarity vsync_polarity;
  233. enum adv7511_sync_polarity hsync_polarity;
  234. };
  235. /**
  236. * enum adv7511_csc_scaling - Scaling factor for the ADV7511 CSC
  237. * @ADV7511_CSC_SCALING_1: CSC results are not scaled
  238. * @ADV7511_CSC_SCALING_2: CSC results are scaled by a factor of two
  239. * @ADV7511_CSC_SCALING_4: CSC results are scalled by a factor of four
  240. */
  241. enum adv7511_csc_scaling {
  242. ADV7511_CSC_SCALING_1 = 0,
  243. ADV7511_CSC_SCALING_2 = 1,
  244. ADV7511_CSC_SCALING_4 = 2,
  245. };
  246. /**
  247. * struct adv7511_video_config - Describes adv7511 hardware configuration
  248. * @csc_enable: Whether to enable color space conversion
  249. * @csc_scaling_factor: Color space conversion scaling factor
  250. * @csc_coefficents: Color space conversion coefficents
  251. * @hdmi_mode: Whether to use HDMI or DVI output mode
  252. * @avi_infoframe: HDMI infoframe
  253. */
  254. struct adv7511_video_config {
  255. bool csc_enable;
  256. enum adv7511_csc_scaling csc_scaling_factor;
  257. const uint16_t *csc_coefficents;
  258. bool hdmi_mode;
  259. struct hdmi_avi_infoframe avi_infoframe;
  260. };
  261. enum adv7511_type {
  262. ADV7511,
  263. ADV7533,
  264. };
  265. struct adv7511 {
  266. struct i2c_client *i2c_main;
  267. struct i2c_client *i2c_edid;
  268. struct i2c_client *i2c_cec;
  269. struct regmap *regmap;
  270. struct regmap *regmap_cec;
  271. enum drm_connector_status status;
  272. bool powered;
  273. struct drm_display_mode curr_mode;
  274. unsigned int f_tmds;
  275. unsigned int f_audio;
  276. unsigned int audio_source;
  277. unsigned int current_edid_segment;
  278. uint8_t edid_buf[256];
  279. bool edid_read;
  280. wait_queue_head_t wq;
  281. struct work_struct hpd_work;
  282. struct drm_bridge bridge;
  283. struct drm_connector connector;
  284. bool embedded_sync;
  285. enum adv7511_sync_polarity vsync_polarity;
  286. enum adv7511_sync_polarity hsync_polarity;
  287. bool rgb;
  288. struct edid *edid;
  289. struct gpio_desc *gpio_pd;
  290. struct regulator_bulk_data *supplies;
  291. unsigned int num_supplies;
  292. /* ADV7533 DSI RX related params */
  293. struct device_node *host_node;
  294. struct mipi_dsi_device *dsi;
  295. u8 num_dsi_lanes;
  296. bool use_timing_gen;
  297. enum adv7511_type type;
  298. struct platform_device *audio_pdev;
  299. };
  300. #ifdef CONFIG_DRM_I2C_ADV7533
  301. void adv7533_dsi_power_on(struct adv7511 *adv);
  302. void adv7533_dsi_power_off(struct adv7511 *adv);
  303. void adv7533_mode_set(struct adv7511 *adv, struct drm_display_mode *mode);
  304. int adv7533_patch_registers(struct adv7511 *adv);
  305. void adv7533_uninit_cec(struct adv7511 *adv);
  306. int adv7533_init_cec(struct adv7511 *adv);
  307. int adv7533_attach_dsi(struct adv7511 *adv);
  308. void adv7533_detach_dsi(struct adv7511 *adv);
  309. int adv7533_parse_dt(struct device_node *np, struct adv7511 *adv);
  310. #else
  311. static inline void adv7533_dsi_power_on(struct adv7511 *adv)
  312. {
  313. }
  314. static inline void adv7533_dsi_power_off(struct adv7511 *adv)
  315. {
  316. }
  317. static inline void adv7533_mode_set(struct adv7511 *adv,
  318. struct drm_display_mode *mode)
  319. {
  320. }
  321. static inline int adv7533_patch_registers(struct adv7511 *adv)
  322. {
  323. return -ENODEV;
  324. }
  325. static inline void adv7533_uninit_cec(struct adv7511 *adv)
  326. {
  327. }
  328. static inline int adv7533_init_cec(struct adv7511 *adv)
  329. {
  330. return -ENODEV;
  331. }
  332. static inline int adv7533_attach_dsi(struct adv7511 *adv)
  333. {
  334. return -ENODEV;
  335. }
  336. static inline void adv7533_detach_dsi(struct adv7511 *adv)
  337. {
  338. }
  339. static inline int adv7533_parse_dt(struct device_node *np, struct adv7511 *adv)
  340. {
  341. return -ENODEV;
  342. }
  343. #endif
  344. #ifdef CONFIG_DRM_I2C_ADV7511_AUDIO
  345. int adv7511_audio_init(struct device *dev, struct adv7511 *adv7511);
  346. void adv7511_audio_exit(struct adv7511 *adv7511);
  347. #else /*CONFIG_DRM_I2C_ADV7511_AUDIO */
  348. static inline int adv7511_audio_init(struct device *dev, struct adv7511 *adv7511)
  349. {
  350. return 0;
  351. }
  352. static inline void adv7511_audio_exit(struct adv7511 *adv7511)
  353. {
  354. }
  355. #endif /* CONFIG_DRM_I2C_ADV7511_AUDIO */
  356. #endif /* __DRM_I2C_ADV7511_H__ */