adv7511_drv.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  1. /*
  2. * Analog Devices ADV7511 HDMI transmitter driver
  3. *
  4. * Copyright 2012 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2.
  7. */
  8. #include <linux/device.h>
  9. #include <linux/gpio/consumer.h>
  10. #include <linux/module.h>
  11. #include <linux/of_device.h>
  12. #include <linux/slab.h>
  13. #include <drm/drmP.h>
  14. #include <drm/drm_atomic.h>
  15. #include <drm/drm_atomic_helper.h>
  16. #include <drm/drm_edid.h>
  17. #include "adv7511.h"
  18. /* ADI recommended values for proper operation. */
  19. static const struct reg_sequence adv7511_fixed_registers[] = {
  20. { 0x98, 0x03 },
  21. { 0x9a, 0xe0 },
  22. { 0x9c, 0x30 },
  23. { 0x9d, 0x61 },
  24. { 0xa2, 0xa4 },
  25. { 0xa3, 0xa4 },
  26. { 0xe0, 0xd0 },
  27. { 0xf9, 0x00 },
  28. { 0x55, 0x02 },
  29. };
  30. /* -----------------------------------------------------------------------------
  31. * Register access
  32. */
  33. static const uint8_t adv7511_register_defaults[] = {
  34. 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00 */
  35. 0x00, 0x00, 0x01, 0x0e, 0xbc, 0x18, 0x01, 0x13,
  36. 0x25, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 10 */
  37. 0x46, 0x62, 0x04, 0xa8, 0x00, 0x00, 0x1c, 0x84,
  38. 0x1c, 0xbf, 0x04, 0xa8, 0x1e, 0x70, 0x02, 0x1e, /* 20 */
  39. 0x00, 0x00, 0x04, 0xa8, 0x08, 0x12, 0x1b, 0xac,
  40. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 30 */
  41. 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xb0,
  42. 0x00, 0x50, 0x90, 0x7e, 0x79, 0x70, 0x00, 0x00, /* 40 */
  43. 0x00, 0xa8, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
  44. 0x00, 0x00, 0x02, 0x0d, 0x00, 0x00, 0x00, 0x00, /* 50 */
  45. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  46. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 60 */
  47. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  48. 0x01, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 70 */
  49. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  50. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 80 */
  51. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  52. 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, /* 90 */
  53. 0x0b, 0x02, 0x00, 0x18, 0x5a, 0x60, 0x00, 0x00,
  54. 0x00, 0x00, 0x80, 0x80, 0x08, 0x04, 0x00, 0x00, /* a0 */
  55. 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x40, 0x14,
  56. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b0 */
  57. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  58. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* c0 */
  59. 0x00, 0x03, 0x00, 0x00, 0x02, 0x00, 0x01, 0x04,
  60. 0x30, 0xff, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, /* d0 */
  61. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x01,
  62. 0x80, 0x75, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, /* e0 */
  63. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  64. 0x00, 0x00, 0x00, 0x00, 0x00, 0x75, 0x11, 0x00, /* f0 */
  65. 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  66. };
  67. static bool adv7511_register_volatile(struct device *dev, unsigned int reg)
  68. {
  69. switch (reg) {
  70. case ADV7511_REG_CHIP_REVISION:
  71. case ADV7511_REG_SPDIF_FREQ:
  72. case ADV7511_REG_CTS_AUTOMATIC1:
  73. case ADV7511_REG_CTS_AUTOMATIC2:
  74. case ADV7511_REG_VIC_DETECTED:
  75. case ADV7511_REG_VIC_SEND:
  76. case ADV7511_REG_AUX_VIC_DETECTED:
  77. case ADV7511_REG_STATUS:
  78. case ADV7511_REG_GC(1):
  79. case ADV7511_REG_INT(0):
  80. case ADV7511_REG_INT(1):
  81. case ADV7511_REG_PLL_STATUS:
  82. case ADV7511_REG_AN(0):
  83. case ADV7511_REG_AN(1):
  84. case ADV7511_REG_AN(2):
  85. case ADV7511_REG_AN(3):
  86. case ADV7511_REG_AN(4):
  87. case ADV7511_REG_AN(5):
  88. case ADV7511_REG_AN(6):
  89. case ADV7511_REG_AN(7):
  90. case ADV7511_REG_HDCP_STATUS:
  91. case ADV7511_REG_BCAPS:
  92. case ADV7511_REG_BKSV(0):
  93. case ADV7511_REG_BKSV(1):
  94. case ADV7511_REG_BKSV(2):
  95. case ADV7511_REG_BKSV(3):
  96. case ADV7511_REG_BKSV(4):
  97. case ADV7511_REG_DDC_STATUS:
  98. case ADV7511_REG_EDID_READ_CTRL:
  99. case ADV7511_REG_BSTATUS(0):
  100. case ADV7511_REG_BSTATUS(1):
  101. case ADV7511_REG_CHIP_ID_HIGH:
  102. case ADV7511_REG_CHIP_ID_LOW:
  103. return true;
  104. }
  105. return false;
  106. }
  107. static const struct regmap_config adv7511_regmap_config = {
  108. .reg_bits = 8,
  109. .val_bits = 8,
  110. .max_register = 0xff,
  111. .cache_type = REGCACHE_RBTREE,
  112. .reg_defaults_raw = adv7511_register_defaults,
  113. .num_reg_defaults_raw = ARRAY_SIZE(adv7511_register_defaults),
  114. .volatile_reg = adv7511_register_volatile,
  115. };
  116. /* -----------------------------------------------------------------------------
  117. * Hardware configuration
  118. */
  119. static void adv7511_set_colormap(struct adv7511 *adv7511, bool enable,
  120. const uint16_t *coeff,
  121. unsigned int scaling_factor)
  122. {
  123. unsigned int i;
  124. regmap_update_bits(adv7511->regmap, ADV7511_REG_CSC_UPPER(1),
  125. ADV7511_CSC_UPDATE_MODE, ADV7511_CSC_UPDATE_MODE);
  126. if (enable) {
  127. for (i = 0; i < 12; ++i) {
  128. regmap_update_bits(adv7511->regmap,
  129. ADV7511_REG_CSC_UPPER(i),
  130. 0x1f, coeff[i] >> 8);
  131. regmap_write(adv7511->regmap,
  132. ADV7511_REG_CSC_LOWER(i),
  133. coeff[i] & 0xff);
  134. }
  135. }
  136. if (enable)
  137. regmap_update_bits(adv7511->regmap, ADV7511_REG_CSC_UPPER(0),
  138. 0xe0, 0x80 | (scaling_factor << 5));
  139. else
  140. regmap_update_bits(adv7511->regmap, ADV7511_REG_CSC_UPPER(0),
  141. 0x80, 0x00);
  142. regmap_update_bits(adv7511->regmap, ADV7511_REG_CSC_UPPER(1),
  143. ADV7511_CSC_UPDATE_MODE, 0);
  144. }
  145. static int adv7511_packet_enable(struct adv7511 *adv7511, unsigned int packet)
  146. {
  147. if (packet & 0xff)
  148. regmap_update_bits(adv7511->regmap, ADV7511_REG_PACKET_ENABLE0,
  149. packet, 0xff);
  150. if (packet & 0xff00) {
  151. packet >>= 8;
  152. regmap_update_bits(adv7511->regmap, ADV7511_REG_PACKET_ENABLE1,
  153. packet, 0xff);
  154. }
  155. return 0;
  156. }
  157. static int adv7511_packet_disable(struct adv7511 *adv7511, unsigned int packet)
  158. {
  159. if (packet & 0xff)
  160. regmap_update_bits(adv7511->regmap, ADV7511_REG_PACKET_ENABLE0,
  161. packet, 0x00);
  162. if (packet & 0xff00) {
  163. packet >>= 8;
  164. regmap_update_bits(adv7511->regmap, ADV7511_REG_PACKET_ENABLE1,
  165. packet, 0x00);
  166. }
  167. return 0;
  168. }
  169. /* Coefficients for adv7511 color space conversion */
  170. static const uint16_t adv7511_csc_ycbcr_to_rgb[] = {
  171. 0x0734, 0x04ad, 0x0000, 0x1c1b,
  172. 0x1ddc, 0x04ad, 0x1f24, 0x0135,
  173. 0x0000, 0x04ad, 0x087c, 0x1b77,
  174. };
  175. static void adv7511_set_config_csc(struct adv7511 *adv7511,
  176. struct drm_connector *connector,
  177. bool rgb)
  178. {
  179. struct adv7511_video_config config;
  180. bool output_format_422, output_format_ycbcr;
  181. unsigned int mode;
  182. uint8_t infoframe[17];
  183. if (adv7511->edid)
  184. config.hdmi_mode = drm_detect_hdmi_monitor(adv7511->edid);
  185. else
  186. config.hdmi_mode = false;
  187. hdmi_avi_infoframe_init(&config.avi_infoframe);
  188. config.avi_infoframe.scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
  189. if (rgb) {
  190. config.csc_enable = false;
  191. config.avi_infoframe.colorspace = HDMI_COLORSPACE_RGB;
  192. } else {
  193. config.csc_scaling_factor = ADV7511_CSC_SCALING_4;
  194. config.csc_coefficents = adv7511_csc_ycbcr_to_rgb;
  195. if ((connector->display_info.color_formats &
  196. DRM_COLOR_FORMAT_YCRCB422) &&
  197. config.hdmi_mode) {
  198. config.csc_enable = false;
  199. config.avi_infoframe.colorspace =
  200. HDMI_COLORSPACE_YUV422;
  201. } else {
  202. config.csc_enable = true;
  203. config.avi_infoframe.colorspace = HDMI_COLORSPACE_RGB;
  204. }
  205. }
  206. if (config.hdmi_mode) {
  207. mode = ADV7511_HDMI_CFG_MODE_HDMI;
  208. switch (config.avi_infoframe.colorspace) {
  209. case HDMI_COLORSPACE_YUV444:
  210. output_format_422 = false;
  211. output_format_ycbcr = true;
  212. break;
  213. case HDMI_COLORSPACE_YUV422:
  214. output_format_422 = true;
  215. output_format_ycbcr = true;
  216. break;
  217. default:
  218. output_format_422 = false;
  219. output_format_ycbcr = false;
  220. break;
  221. }
  222. } else {
  223. mode = ADV7511_HDMI_CFG_MODE_DVI;
  224. output_format_422 = false;
  225. output_format_ycbcr = false;
  226. }
  227. adv7511_packet_disable(adv7511, ADV7511_PACKET_ENABLE_AVI_INFOFRAME);
  228. adv7511_set_colormap(adv7511, config.csc_enable,
  229. config.csc_coefficents,
  230. config.csc_scaling_factor);
  231. regmap_update_bits(adv7511->regmap, ADV7511_REG_VIDEO_INPUT_CFG1, 0x81,
  232. (output_format_422 << 7) | output_format_ycbcr);
  233. regmap_update_bits(adv7511->regmap, ADV7511_REG_HDCP_HDMI_CFG,
  234. ADV7511_HDMI_CFG_MODE_MASK, mode);
  235. hdmi_avi_infoframe_pack(&config.avi_infoframe, infoframe,
  236. sizeof(infoframe));
  237. /* The AVI infoframe id is not configurable */
  238. regmap_bulk_write(adv7511->regmap, ADV7511_REG_AVI_INFOFRAME_VERSION,
  239. infoframe + 1, sizeof(infoframe) - 1);
  240. adv7511_packet_enable(adv7511, ADV7511_PACKET_ENABLE_AVI_INFOFRAME);
  241. }
  242. static void adv7511_set_link_config(struct adv7511 *adv7511,
  243. const struct adv7511_link_config *config)
  244. {
  245. /*
  246. * The input style values documented in the datasheet don't match the
  247. * hardware register field values :-(
  248. */
  249. static const unsigned int input_styles[4] = { 0, 2, 1, 3 };
  250. unsigned int clock_delay;
  251. unsigned int color_depth;
  252. unsigned int input_id;
  253. clock_delay = (config->clock_delay + 1200) / 400;
  254. color_depth = config->input_color_depth == 8 ? 3
  255. : (config->input_color_depth == 10 ? 1 : 2);
  256. /* TODO Support input ID 6 */
  257. if (config->input_colorspace != HDMI_COLORSPACE_YUV422)
  258. input_id = config->input_clock == ADV7511_INPUT_CLOCK_DDR
  259. ? 5 : 0;
  260. else if (config->input_clock == ADV7511_INPUT_CLOCK_DDR)
  261. input_id = config->embedded_sync ? 8 : 7;
  262. else if (config->input_clock == ADV7511_INPUT_CLOCK_2X)
  263. input_id = config->embedded_sync ? 4 : 3;
  264. else
  265. input_id = config->embedded_sync ? 2 : 1;
  266. regmap_update_bits(adv7511->regmap, ADV7511_REG_I2C_FREQ_ID_CFG, 0xf,
  267. input_id);
  268. regmap_update_bits(adv7511->regmap, ADV7511_REG_VIDEO_INPUT_CFG1, 0x7e,
  269. (color_depth << 4) |
  270. (input_styles[config->input_style] << 2));
  271. regmap_write(adv7511->regmap, ADV7511_REG_VIDEO_INPUT_CFG2,
  272. config->input_justification << 3);
  273. regmap_write(adv7511->regmap, ADV7511_REG_TIMING_GEN_SEQ,
  274. config->sync_pulse << 2);
  275. regmap_write(adv7511->regmap, 0xba, clock_delay << 5);
  276. adv7511->embedded_sync = config->embedded_sync;
  277. adv7511->hsync_polarity = config->hsync_polarity;
  278. adv7511->vsync_polarity = config->vsync_polarity;
  279. adv7511->rgb = config->input_colorspace == HDMI_COLORSPACE_RGB;
  280. }
  281. static void __adv7511_power_on(struct adv7511 *adv7511)
  282. {
  283. adv7511->current_edid_segment = -1;
  284. regmap_update_bits(adv7511->regmap, ADV7511_REG_POWER,
  285. ADV7511_POWER_POWER_DOWN, 0);
  286. if (adv7511->i2c_main->irq) {
  287. /*
  288. * Documentation says the INT_ENABLE registers are reset in
  289. * POWER_DOWN mode. My 7511w preserved the bits, however.
  290. * Still, let's be safe and stick to the documentation.
  291. */
  292. regmap_write(adv7511->regmap, ADV7511_REG_INT_ENABLE(0),
  293. ADV7511_INT0_EDID_READY | ADV7511_INT0_HPD);
  294. regmap_write(adv7511->regmap, ADV7511_REG_INT_ENABLE(1),
  295. ADV7511_INT1_DDC_ERROR);
  296. }
  297. /*
  298. * Per spec it is allowed to pulse the HPD signal to indicate that the
  299. * EDID information has changed. Some monitors do this when they wakeup
  300. * from standby or are enabled. When the HPD goes low the adv7511 is
  301. * reset and the outputs are disabled which might cause the monitor to
  302. * go to standby again. To avoid this we ignore the HPD pin for the
  303. * first few seconds after enabling the output.
  304. */
  305. regmap_update_bits(adv7511->regmap, ADV7511_REG_POWER2,
  306. ADV7511_REG_POWER2_HPD_SRC_MASK,
  307. ADV7511_REG_POWER2_HPD_SRC_NONE);
  308. }
  309. static void adv7511_power_on(struct adv7511 *adv7511)
  310. {
  311. __adv7511_power_on(adv7511);
  312. /*
  313. * Most of the registers are reset during power down or when HPD is low.
  314. */
  315. regcache_sync(adv7511->regmap);
  316. if (adv7511->type == ADV7533)
  317. adv7533_dsi_power_on(adv7511);
  318. adv7511->powered = true;
  319. }
  320. static void __adv7511_power_off(struct adv7511 *adv7511)
  321. {
  322. /* TODO: setup additional power down modes */
  323. regmap_update_bits(adv7511->regmap, ADV7511_REG_POWER,
  324. ADV7511_POWER_POWER_DOWN,
  325. ADV7511_POWER_POWER_DOWN);
  326. regcache_mark_dirty(adv7511->regmap);
  327. }
  328. static void adv7511_power_off(struct adv7511 *adv7511)
  329. {
  330. __adv7511_power_off(adv7511);
  331. if (adv7511->type == ADV7533)
  332. adv7533_dsi_power_off(adv7511);
  333. adv7511->powered = false;
  334. }
  335. /* -----------------------------------------------------------------------------
  336. * Interrupt and hotplug detection
  337. */
  338. static bool adv7511_hpd(struct adv7511 *adv7511)
  339. {
  340. unsigned int irq0;
  341. int ret;
  342. ret = regmap_read(adv7511->regmap, ADV7511_REG_INT(0), &irq0);
  343. if (ret < 0)
  344. return false;
  345. if (irq0 & ADV7511_INT0_HPD) {
  346. regmap_write(adv7511->regmap, ADV7511_REG_INT(0),
  347. ADV7511_INT0_HPD);
  348. return true;
  349. }
  350. return false;
  351. }
  352. static void adv7511_hpd_work(struct work_struct *work)
  353. {
  354. struct adv7511 *adv7511 = container_of(work, struct adv7511, hpd_work);
  355. enum drm_connector_status status;
  356. unsigned int val;
  357. int ret;
  358. ret = regmap_read(adv7511->regmap, ADV7511_REG_STATUS, &val);
  359. if (ret < 0)
  360. status = connector_status_disconnected;
  361. else if (val & ADV7511_STATUS_HPD)
  362. status = connector_status_connected;
  363. else
  364. status = connector_status_disconnected;
  365. if (adv7511->connector.status != status) {
  366. adv7511->connector.status = status;
  367. drm_kms_helper_hotplug_event(adv7511->connector.dev);
  368. }
  369. }
  370. static int adv7511_irq_process(struct adv7511 *adv7511, bool process_hpd)
  371. {
  372. unsigned int irq0, irq1;
  373. int ret;
  374. ret = regmap_read(adv7511->regmap, ADV7511_REG_INT(0), &irq0);
  375. if (ret < 0)
  376. return ret;
  377. ret = regmap_read(adv7511->regmap, ADV7511_REG_INT(1), &irq1);
  378. if (ret < 0)
  379. return ret;
  380. regmap_write(adv7511->regmap, ADV7511_REG_INT(0), irq0);
  381. regmap_write(adv7511->regmap, ADV7511_REG_INT(1), irq1);
  382. if (process_hpd && irq0 & ADV7511_INT0_HPD && adv7511->bridge.encoder)
  383. schedule_work(&adv7511->hpd_work);
  384. if (irq0 & ADV7511_INT0_EDID_READY || irq1 & ADV7511_INT1_DDC_ERROR) {
  385. adv7511->edid_read = true;
  386. if (adv7511->i2c_main->irq)
  387. wake_up_all(&adv7511->wq);
  388. }
  389. return 0;
  390. }
  391. static irqreturn_t adv7511_irq_handler(int irq, void *devid)
  392. {
  393. struct adv7511 *adv7511 = devid;
  394. int ret;
  395. ret = adv7511_irq_process(adv7511, true);
  396. return ret < 0 ? IRQ_NONE : IRQ_HANDLED;
  397. }
  398. /* -----------------------------------------------------------------------------
  399. * EDID retrieval
  400. */
  401. static int adv7511_wait_for_edid(struct adv7511 *adv7511, int timeout)
  402. {
  403. int ret;
  404. if (adv7511->i2c_main->irq) {
  405. ret = wait_event_interruptible_timeout(adv7511->wq,
  406. adv7511->edid_read, msecs_to_jiffies(timeout));
  407. } else {
  408. for (; timeout > 0; timeout -= 25) {
  409. ret = adv7511_irq_process(adv7511, false);
  410. if (ret < 0)
  411. break;
  412. if (adv7511->edid_read)
  413. break;
  414. msleep(25);
  415. }
  416. }
  417. return adv7511->edid_read ? 0 : -EIO;
  418. }
  419. static int adv7511_get_edid_block(void *data, u8 *buf, unsigned int block,
  420. size_t len)
  421. {
  422. struct adv7511 *adv7511 = data;
  423. struct i2c_msg xfer[2];
  424. uint8_t offset;
  425. unsigned int i;
  426. int ret;
  427. if (len > 128)
  428. return -EINVAL;
  429. if (adv7511->current_edid_segment != block / 2) {
  430. unsigned int status;
  431. ret = regmap_read(adv7511->regmap, ADV7511_REG_DDC_STATUS,
  432. &status);
  433. if (ret < 0)
  434. return ret;
  435. if (status != 2) {
  436. adv7511->edid_read = false;
  437. regmap_write(adv7511->regmap, ADV7511_REG_EDID_SEGMENT,
  438. block);
  439. ret = adv7511_wait_for_edid(adv7511, 200);
  440. if (ret < 0)
  441. return ret;
  442. }
  443. /* Break this apart, hopefully more I2C controllers will
  444. * support 64 byte transfers than 256 byte transfers
  445. */
  446. xfer[0].addr = adv7511->i2c_edid->addr;
  447. xfer[0].flags = 0;
  448. xfer[0].len = 1;
  449. xfer[0].buf = &offset;
  450. xfer[1].addr = adv7511->i2c_edid->addr;
  451. xfer[1].flags = I2C_M_RD;
  452. xfer[1].len = 64;
  453. xfer[1].buf = adv7511->edid_buf;
  454. offset = 0;
  455. for (i = 0; i < 4; ++i) {
  456. ret = i2c_transfer(adv7511->i2c_edid->adapter, xfer,
  457. ARRAY_SIZE(xfer));
  458. if (ret < 0)
  459. return ret;
  460. else if (ret != 2)
  461. return -EIO;
  462. xfer[1].buf += 64;
  463. offset += 64;
  464. }
  465. adv7511->current_edid_segment = block / 2;
  466. }
  467. if (block % 2 == 0)
  468. memcpy(buf, adv7511->edid_buf, len);
  469. else
  470. memcpy(buf, adv7511->edid_buf + 128, len);
  471. return 0;
  472. }
  473. /* -----------------------------------------------------------------------------
  474. * ADV75xx helpers
  475. */
  476. static int adv7511_get_modes(struct adv7511 *adv7511,
  477. struct drm_connector *connector)
  478. {
  479. struct edid *edid;
  480. unsigned int count;
  481. /* Reading the EDID only works if the device is powered */
  482. if (!adv7511->powered) {
  483. unsigned int edid_i2c_addr =
  484. (adv7511->i2c_main->addr << 1) + 4;
  485. __adv7511_power_on(adv7511);
  486. /* Reset the EDID_I2C_ADDR register as it might be cleared */
  487. regmap_write(adv7511->regmap, ADV7511_REG_EDID_I2C_ADDR,
  488. edid_i2c_addr);
  489. }
  490. edid = drm_do_get_edid(connector, adv7511_get_edid_block, adv7511);
  491. if (!adv7511->powered)
  492. __adv7511_power_off(adv7511);
  493. kfree(adv7511->edid);
  494. adv7511->edid = edid;
  495. if (!edid)
  496. return 0;
  497. drm_mode_connector_update_edid_property(connector, edid);
  498. count = drm_add_edid_modes(connector, edid);
  499. adv7511_set_config_csc(adv7511, connector, adv7511->rgb);
  500. return count;
  501. }
  502. static enum drm_connector_status
  503. adv7511_detect(struct adv7511 *adv7511, struct drm_connector *connector)
  504. {
  505. enum drm_connector_status status;
  506. unsigned int val;
  507. bool hpd;
  508. int ret;
  509. ret = regmap_read(adv7511->regmap, ADV7511_REG_STATUS, &val);
  510. if (ret < 0)
  511. return connector_status_disconnected;
  512. if (val & ADV7511_STATUS_HPD)
  513. status = connector_status_connected;
  514. else
  515. status = connector_status_disconnected;
  516. hpd = adv7511_hpd(adv7511);
  517. /* The chip resets itself when the cable is disconnected, so in case
  518. * there is a pending HPD interrupt and the cable is connected there was
  519. * at least one transition from disconnected to connected and the chip
  520. * has to be reinitialized. */
  521. if (status == connector_status_connected && hpd && adv7511->powered) {
  522. regcache_mark_dirty(adv7511->regmap);
  523. adv7511_power_on(adv7511);
  524. adv7511_get_modes(adv7511, connector);
  525. if (adv7511->status == connector_status_connected)
  526. status = connector_status_disconnected;
  527. } else {
  528. /* Renable HPD sensing */
  529. regmap_update_bits(adv7511->regmap, ADV7511_REG_POWER2,
  530. ADV7511_REG_POWER2_HPD_SRC_MASK,
  531. ADV7511_REG_POWER2_HPD_SRC_BOTH);
  532. }
  533. adv7511->status = status;
  534. return status;
  535. }
  536. static int adv7511_mode_valid(struct adv7511 *adv7511,
  537. struct drm_display_mode *mode)
  538. {
  539. if (mode->clock > 165000)
  540. return MODE_CLOCK_HIGH;
  541. return MODE_OK;
  542. }
  543. static void adv7511_mode_set(struct adv7511 *adv7511,
  544. struct drm_display_mode *mode,
  545. struct drm_display_mode *adj_mode)
  546. {
  547. unsigned int low_refresh_rate;
  548. unsigned int hsync_polarity = 0;
  549. unsigned int vsync_polarity = 0;
  550. if (adv7511->embedded_sync) {
  551. unsigned int hsync_offset, hsync_len;
  552. unsigned int vsync_offset, vsync_len;
  553. hsync_offset = adj_mode->crtc_hsync_start -
  554. adj_mode->crtc_hdisplay;
  555. vsync_offset = adj_mode->crtc_vsync_start -
  556. adj_mode->crtc_vdisplay;
  557. hsync_len = adj_mode->crtc_hsync_end -
  558. adj_mode->crtc_hsync_start;
  559. vsync_len = adj_mode->crtc_vsync_end -
  560. adj_mode->crtc_vsync_start;
  561. /* The hardware vsync generator has a off-by-one bug */
  562. vsync_offset += 1;
  563. regmap_write(adv7511->regmap, ADV7511_REG_HSYNC_PLACEMENT_MSB,
  564. ((hsync_offset >> 10) & 0x7) << 5);
  565. regmap_write(adv7511->regmap, ADV7511_REG_SYNC_DECODER(0),
  566. (hsync_offset >> 2) & 0xff);
  567. regmap_write(adv7511->regmap, ADV7511_REG_SYNC_DECODER(1),
  568. ((hsync_offset & 0x3) << 6) |
  569. ((hsync_len >> 4) & 0x3f));
  570. regmap_write(adv7511->regmap, ADV7511_REG_SYNC_DECODER(2),
  571. ((hsync_len & 0xf) << 4) |
  572. ((vsync_offset >> 6) & 0xf));
  573. regmap_write(adv7511->regmap, ADV7511_REG_SYNC_DECODER(3),
  574. ((vsync_offset & 0x3f) << 2) |
  575. ((vsync_len >> 8) & 0x3));
  576. regmap_write(adv7511->regmap, ADV7511_REG_SYNC_DECODER(4),
  577. vsync_len & 0xff);
  578. hsync_polarity = !(adj_mode->flags & DRM_MODE_FLAG_PHSYNC);
  579. vsync_polarity = !(adj_mode->flags & DRM_MODE_FLAG_PVSYNC);
  580. } else {
  581. enum adv7511_sync_polarity mode_hsync_polarity;
  582. enum adv7511_sync_polarity mode_vsync_polarity;
  583. /**
  584. * If the input signal is always low or always high we want to
  585. * invert or let it passthrough depending on the polarity of the
  586. * current mode.
  587. **/
  588. if (adj_mode->flags & DRM_MODE_FLAG_NHSYNC)
  589. mode_hsync_polarity = ADV7511_SYNC_POLARITY_LOW;
  590. else
  591. mode_hsync_polarity = ADV7511_SYNC_POLARITY_HIGH;
  592. if (adj_mode->flags & DRM_MODE_FLAG_NVSYNC)
  593. mode_vsync_polarity = ADV7511_SYNC_POLARITY_LOW;
  594. else
  595. mode_vsync_polarity = ADV7511_SYNC_POLARITY_HIGH;
  596. if (adv7511->hsync_polarity != mode_hsync_polarity &&
  597. adv7511->hsync_polarity !=
  598. ADV7511_SYNC_POLARITY_PASSTHROUGH)
  599. hsync_polarity = 1;
  600. if (adv7511->vsync_polarity != mode_vsync_polarity &&
  601. adv7511->vsync_polarity !=
  602. ADV7511_SYNC_POLARITY_PASSTHROUGH)
  603. vsync_polarity = 1;
  604. }
  605. if (mode->vrefresh <= 24000)
  606. low_refresh_rate = ADV7511_LOW_REFRESH_RATE_24HZ;
  607. else if (mode->vrefresh <= 25000)
  608. low_refresh_rate = ADV7511_LOW_REFRESH_RATE_25HZ;
  609. else if (mode->vrefresh <= 30000)
  610. low_refresh_rate = ADV7511_LOW_REFRESH_RATE_30HZ;
  611. else
  612. low_refresh_rate = ADV7511_LOW_REFRESH_RATE_NONE;
  613. regmap_update_bits(adv7511->regmap, 0xfb,
  614. 0x6, low_refresh_rate << 1);
  615. regmap_update_bits(adv7511->regmap, 0x17,
  616. 0x60, (vsync_polarity << 6) | (hsync_polarity << 5));
  617. if (adv7511->type == ADV7533)
  618. adv7533_mode_set(adv7511, adj_mode);
  619. drm_mode_copy(&adv7511->curr_mode, adj_mode);
  620. /*
  621. * TODO Test first order 4:2:2 to 4:4:4 up conversion method, which is
  622. * supposed to give better results.
  623. */
  624. adv7511->f_tmds = mode->clock;
  625. }
  626. /* Connector funcs */
  627. static struct adv7511 *connector_to_adv7511(struct drm_connector *connector)
  628. {
  629. return container_of(connector, struct adv7511, connector);
  630. }
  631. static int adv7511_connector_get_modes(struct drm_connector *connector)
  632. {
  633. struct adv7511 *adv = connector_to_adv7511(connector);
  634. return adv7511_get_modes(adv, connector);
  635. }
  636. static enum drm_mode_status
  637. adv7511_connector_mode_valid(struct drm_connector *connector,
  638. struct drm_display_mode *mode)
  639. {
  640. struct adv7511 *adv = connector_to_adv7511(connector);
  641. return adv7511_mode_valid(adv, mode);
  642. }
  643. static struct drm_connector_helper_funcs adv7511_connector_helper_funcs = {
  644. .get_modes = adv7511_connector_get_modes,
  645. .mode_valid = adv7511_connector_mode_valid,
  646. };
  647. static enum drm_connector_status
  648. adv7511_connector_detect(struct drm_connector *connector, bool force)
  649. {
  650. struct adv7511 *adv = connector_to_adv7511(connector);
  651. return adv7511_detect(adv, connector);
  652. }
  653. static const struct drm_connector_funcs adv7511_connector_funcs = {
  654. .fill_modes = drm_helper_probe_single_connector_modes,
  655. .detect = adv7511_connector_detect,
  656. .destroy = drm_connector_cleanup,
  657. .reset = drm_atomic_helper_connector_reset,
  658. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  659. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  660. };
  661. /* Bridge funcs */
  662. static struct adv7511 *bridge_to_adv7511(struct drm_bridge *bridge)
  663. {
  664. return container_of(bridge, struct adv7511, bridge);
  665. }
  666. static void adv7511_bridge_enable(struct drm_bridge *bridge)
  667. {
  668. struct adv7511 *adv = bridge_to_adv7511(bridge);
  669. adv7511_power_on(adv);
  670. }
  671. static void adv7511_bridge_disable(struct drm_bridge *bridge)
  672. {
  673. struct adv7511 *adv = bridge_to_adv7511(bridge);
  674. adv7511_power_off(adv);
  675. }
  676. static void adv7511_bridge_mode_set(struct drm_bridge *bridge,
  677. struct drm_display_mode *mode,
  678. struct drm_display_mode *adj_mode)
  679. {
  680. struct adv7511 *adv = bridge_to_adv7511(bridge);
  681. adv7511_mode_set(adv, mode, adj_mode);
  682. }
  683. static int adv7511_bridge_attach(struct drm_bridge *bridge)
  684. {
  685. struct adv7511 *adv = bridge_to_adv7511(bridge);
  686. int ret;
  687. if (!bridge->encoder) {
  688. DRM_ERROR("Parent encoder object not found");
  689. return -ENODEV;
  690. }
  691. adv->connector.polled = DRM_CONNECTOR_POLL_HPD;
  692. ret = drm_connector_init(bridge->dev, &adv->connector,
  693. &adv7511_connector_funcs,
  694. DRM_MODE_CONNECTOR_HDMIA);
  695. if (ret) {
  696. DRM_ERROR("Failed to initialize connector with drm\n");
  697. return ret;
  698. }
  699. drm_connector_helper_add(&adv->connector,
  700. &adv7511_connector_helper_funcs);
  701. drm_mode_connector_attach_encoder(&adv->connector, bridge->encoder);
  702. if (adv->type == ADV7533)
  703. ret = adv7533_attach_dsi(adv);
  704. if (adv->i2c_main->irq)
  705. regmap_write(adv->regmap, ADV7511_REG_INT_ENABLE(0),
  706. ADV7511_INT0_HPD);
  707. return ret;
  708. }
  709. static const struct drm_bridge_funcs adv7511_bridge_funcs = {
  710. .enable = adv7511_bridge_enable,
  711. .disable = adv7511_bridge_disable,
  712. .mode_set = adv7511_bridge_mode_set,
  713. .attach = adv7511_bridge_attach,
  714. };
  715. /* -----------------------------------------------------------------------------
  716. * Probe & remove
  717. */
  718. static const char * const adv7511_supply_names[] = {
  719. "avdd",
  720. "dvdd",
  721. "pvdd",
  722. "bgvdd",
  723. "dvdd-3v",
  724. };
  725. static const char * const adv7533_supply_names[] = {
  726. "avdd",
  727. "dvdd",
  728. "pvdd",
  729. "a2vdd",
  730. "v3p3",
  731. "v1p2",
  732. };
  733. static int adv7511_init_regulators(struct adv7511 *adv)
  734. {
  735. struct device *dev = &adv->i2c_main->dev;
  736. const char * const *supply_names;
  737. unsigned int i;
  738. int ret;
  739. if (adv->type == ADV7511) {
  740. supply_names = adv7511_supply_names;
  741. adv->num_supplies = ARRAY_SIZE(adv7511_supply_names);
  742. } else {
  743. supply_names = adv7533_supply_names;
  744. adv->num_supplies = ARRAY_SIZE(adv7533_supply_names);
  745. }
  746. adv->supplies = devm_kcalloc(dev, adv->num_supplies,
  747. sizeof(*adv->supplies), GFP_KERNEL);
  748. if (!adv->supplies)
  749. return -ENOMEM;
  750. for (i = 0; i < adv->num_supplies; i++)
  751. adv->supplies[i].supply = supply_names[i];
  752. ret = devm_regulator_bulk_get(dev, adv->num_supplies, adv->supplies);
  753. if (ret)
  754. return ret;
  755. return regulator_bulk_enable(adv->num_supplies, adv->supplies);
  756. }
  757. static void adv7511_uninit_regulators(struct adv7511 *adv)
  758. {
  759. regulator_bulk_disable(adv->num_supplies, adv->supplies);
  760. }
  761. static int adv7511_parse_dt(struct device_node *np,
  762. struct adv7511_link_config *config)
  763. {
  764. const char *str;
  765. int ret;
  766. of_property_read_u32(np, "adi,input-depth", &config->input_color_depth);
  767. if (config->input_color_depth != 8 && config->input_color_depth != 10 &&
  768. config->input_color_depth != 12)
  769. return -EINVAL;
  770. ret = of_property_read_string(np, "adi,input-colorspace", &str);
  771. if (ret < 0)
  772. return ret;
  773. if (!strcmp(str, "rgb"))
  774. config->input_colorspace = HDMI_COLORSPACE_RGB;
  775. else if (!strcmp(str, "yuv422"))
  776. config->input_colorspace = HDMI_COLORSPACE_YUV422;
  777. else if (!strcmp(str, "yuv444"))
  778. config->input_colorspace = HDMI_COLORSPACE_YUV444;
  779. else
  780. return -EINVAL;
  781. ret = of_property_read_string(np, "adi,input-clock", &str);
  782. if (ret < 0)
  783. return ret;
  784. if (!strcmp(str, "1x"))
  785. config->input_clock = ADV7511_INPUT_CLOCK_1X;
  786. else if (!strcmp(str, "2x"))
  787. config->input_clock = ADV7511_INPUT_CLOCK_2X;
  788. else if (!strcmp(str, "ddr"))
  789. config->input_clock = ADV7511_INPUT_CLOCK_DDR;
  790. else
  791. return -EINVAL;
  792. if (config->input_colorspace == HDMI_COLORSPACE_YUV422 ||
  793. config->input_clock != ADV7511_INPUT_CLOCK_1X) {
  794. ret = of_property_read_u32(np, "adi,input-style",
  795. &config->input_style);
  796. if (ret)
  797. return ret;
  798. if (config->input_style < 1 || config->input_style > 3)
  799. return -EINVAL;
  800. ret = of_property_read_string(np, "adi,input-justification",
  801. &str);
  802. if (ret < 0)
  803. return ret;
  804. if (!strcmp(str, "left"))
  805. config->input_justification =
  806. ADV7511_INPUT_JUSTIFICATION_LEFT;
  807. else if (!strcmp(str, "evenly"))
  808. config->input_justification =
  809. ADV7511_INPUT_JUSTIFICATION_EVENLY;
  810. else if (!strcmp(str, "right"))
  811. config->input_justification =
  812. ADV7511_INPUT_JUSTIFICATION_RIGHT;
  813. else
  814. return -EINVAL;
  815. } else {
  816. config->input_style = 1;
  817. config->input_justification = ADV7511_INPUT_JUSTIFICATION_LEFT;
  818. }
  819. of_property_read_u32(np, "adi,clock-delay", &config->clock_delay);
  820. if (config->clock_delay < -1200 || config->clock_delay > 1600)
  821. return -EINVAL;
  822. config->embedded_sync = of_property_read_bool(np, "adi,embedded-sync");
  823. /* Hardcode the sync pulse configurations for now. */
  824. config->sync_pulse = ADV7511_INPUT_SYNC_PULSE_NONE;
  825. config->vsync_polarity = ADV7511_SYNC_POLARITY_PASSTHROUGH;
  826. config->hsync_polarity = ADV7511_SYNC_POLARITY_PASSTHROUGH;
  827. return 0;
  828. }
  829. static int adv7511_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
  830. {
  831. struct adv7511_link_config link_config;
  832. struct adv7511 *adv7511;
  833. struct device *dev = &i2c->dev;
  834. unsigned int main_i2c_addr = i2c->addr << 1;
  835. unsigned int edid_i2c_addr = main_i2c_addr + 4;
  836. unsigned int val;
  837. int ret;
  838. if (!dev->of_node)
  839. return -EINVAL;
  840. adv7511 = devm_kzalloc(dev, sizeof(*adv7511), GFP_KERNEL);
  841. if (!adv7511)
  842. return -ENOMEM;
  843. adv7511->i2c_main = i2c;
  844. adv7511->powered = false;
  845. adv7511->status = connector_status_disconnected;
  846. if (dev->of_node)
  847. adv7511->type = (enum adv7511_type)of_device_get_match_data(dev);
  848. else
  849. adv7511->type = id->driver_data;
  850. memset(&link_config, 0, sizeof(link_config));
  851. if (adv7511->type == ADV7511)
  852. ret = adv7511_parse_dt(dev->of_node, &link_config);
  853. else
  854. ret = adv7533_parse_dt(dev->of_node, adv7511);
  855. if (ret)
  856. return ret;
  857. ret = adv7511_init_regulators(adv7511);
  858. if (ret) {
  859. dev_err(dev, "failed to init regulators\n");
  860. return ret;
  861. }
  862. /*
  863. * The power down GPIO is optional. If present, toggle it from active to
  864. * inactive to wake up the encoder.
  865. */
  866. adv7511->gpio_pd = devm_gpiod_get_optional(dev, "pd", GPIOD_OUT_HIGH);
  867. if (IS_ERR(adv7511->gpio_pd)) {
  868. ret = PTR_ERR(adv7511->gpio_pd);
  869. goto uninit_regulators;
  870. }
  871. if (adv7511->gpio_pd) {
  872. mdelay(5);
  873. gpiod_set_value_cansleep(adv7511->gpio_pd, 0);
  874. }
  875. adv7511->regmap = devm_regmap_init_i2c(i2c, &adv7511_regmap_config);
  876. if (IS_ERR(adv7511->regmap)) {
  877. ret = PTR_ERR(adv7511->regmap);
  878. goto uninit_regulators;
  879. }
  880. ret = regmap_read(adv7511->regmap, ADV7511_REG_CHIP_REVISION, &val);
  881. if (ret)
  882. goto uninit_regulators;
  883. dev_dbg(dev, "Rev. %d\n", val);
  884. if (adv7511->type == ADV7511)
  885. ret = regmap_register_patch(adv7511->regmap,
  886. adv7511_fixed_registers,
  887. ARRAY_SIZE(adv7511_fixed_registers));
  888. else
  889. ret = adv7533_patch_registers(adv7511);
  890. if (ret)
  891. goto uninit_regulators;
  892. regmap_write(adv7511->regmap, ADV7511_REG_EDID_I2C_ADDR, edid_i2c_addr);
  893. regmap_write(adv7511->regmap, ADV7511_REG_PACKET_I2C_ADDR,
  894. main_i2c_addr - 0xa);
  895. regmap_write(adv7511->regmap, ADV7511_REG_CEC_I2C_ADDR,
  896. main_i2c_addr - 2);
  897. adv7511_packet_disable(adv7511, 0xffff);
  898. adv7511->i2c_edid = i2c_new_dummy(i2c->adapter, edid_i2c_addr >> 1);
  899. if (!adv7511->i2c_edid) {
  900. ret = -ENOMEM;
  901. goto uninit_regulators;
  902. }
  903. if (adv7511->type == ADV7533) {
  904. ret = adv7533_init_cec(adv7511);
  905. if (ret)
  906. goto err_i2c_unregister_edid;
  907. }
  908. INIT_WORK(&adv7511->hpd_work, adv7511_hpd_work);
  909. if (i2c->irq) {
  910. init_waitqueue_head(&adv7511->wq);
  911. ret = devm_request_threaded_irq(dev, i2c->irq, NULL,
  912. adv7511_irq_handler,
  913. IRQF_ONESHOT, dev_name(dev),
  914. adv7511);
  915. if (ret)
  916. goto err_unregister_cec;
  917. }
  918. /* CEC is unused for now */
  919. regmap_write(adv7511->regmap, ADV7511_REG_CEC_CTRL,
  920. ADV7511_CEC_CTRL_POWER_DOWN);
  921. adv7511_power_off(adv7511);
  922. i2c_set_clientdata(i2c, adv7511);
  923. if (adv7511->type == ADV7511)
  924. adv7511_set_link_config(adv7511, &link_config);
  925. adv7511->bridge.funcs = &adv7511_bridge_funcs;
  926. adv7511->bridge.of_node = dev->of_node;
  927. drm_bridge_add(&adv7511->bridge);
  928. adv7511_audio_init(dev, adv7511);
  929. return 0;
  930. err_unregister_cec:
  931. adv7533_uninit_cec(adv7511);
  932. err_i2c_unregister_edid:
  933. i2c_unregister_device(adv7511->i2c_edid);
  934. uninit_regulators:
  935. adv7511_uninit_regulators(adv7511);
  936. return ret;
  937. }
  938. static int adv7511_remove(struct i2c_client *i2c)
  939. {
  940. struct adv7511 *adv7511 = i2c_get_clientdata(i2c);
  941. if (adv7511->type == ADV7533) {
  942. adv7533_detach_dsi(adv7511);
  943. adv7533_uninit_cec(adv7511);
  944. }
  945. adv7511_uninit_regulators(adv7511);
  946. drm_bridge_remove(&adv7511->bridge);
  947. adv7511_audio_exit(adv7511);
  948. i2c_unregister_device(adv7511->i2c_edid);
  949. kfree(adv7511->edid);
  950. return 0;
  951. }
  952. static const struct i2c_device_id adv7511_i2c_ids[] = {
  953. { "adv7511", ADV7511 },
  954. { "adv7511w", ADV7511 },
  955. { "adv7513", ADV7511 },
  956. #ifdef CONFIG_DRM_I2C_ADV7533
  957. { "adv7533", ADV7533 },
  958. #endif
  959. { }
  960. };
  961. MODULE_DEVICE_TABLE(i2c, adv7511_i2c_ids);
  962. static const struct of_device_id adv7511_of_ids[] = {
  963. { .compatible = "adi,adv7511", .data = (void *)ADV7511 },
  964. { .compatible = "adi,adv7511w", .data = (void *)ADV7511 },
  965. { .compatible = "adi,adv7513", .data = (void *)ADV7511 },
  966. #ifdef CONFIG_DRM_I2C_ADV7533
  967. { .compatible = "adi,adv7533", .data = (void *)ADV7533 },
  968. #endif
  969. { }
  970. };
  971. MODULE_DEVICE_TABLE(of, adv7511_of_ids);
  972. static struct mipi_dsi_driver adv7533_dsi_driver = {
  973. .driver.name = "adv7533",
  974. };
  975. static struct i2c_driver adv7511_driver = {
  976. .driver = {
  977. .name = "adv7511",
  978. .of_match_table = adv7511_of_ids,
  979. },
  980. .id_table = adv7511_i2c_ids,
  981. .probe = adv7511_probe,
  982. .remove = adv7511_remove,
  983. };
  984. static int __init adv7511_init(void)
  985. {
  986. if (IS_ENABLED(CONFIG_DRM_MIPI_DSI))
  987. mipi_dsi_driver_register(&adv7533_dsi_driver);
  988. return i2c_add_driver(&adv7511_driver);
  989. }
  990. module_init(adv7511_init);
  991. static void __exit adv7511_exit(void)
  992. {
  993. i2c_del_driver(&adv7511_driver);
  994. if (IS_ENABLED(CONFIG_DRM_MIPI_DSI))
  995. mipi_dsi_driver_unregister(&adv7533_dsi_driver);
  996. }
  997. module_exit(adv7511_exit);
  998. MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
  999. MODULE_DESCRIPTION("ADV7511 HDMI transmitter driver");
  1000. MODULE_LICENSE("GPL");