adv7511_drv.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  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 struct drm_connector_funcs adv7511_connector_funcs = {
  654. .dpms = drm_atomic_helper_connector_dpms,
  655. .fill_modes = drm_helper_probe_single_connector_modes,
  656. .detect = adv7511_connector_detect,
  657. .destroy = drm_connector_cleanup,
  658. .reset = drm_atomic_helper_connector_reset,
  659. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  660. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  661. };
  662. /* Bridge funcs */
  663. static struct adv7511 *bridge_to_adv7511(struct drm_bridge *bridge)
  664. {
  665. return container_of(bridge, struct adv7511, bridge);
  666. }
  667. static void adv7511_bridge_enable(struct drm_bridge *bridge)
  668. {
  669. struct adv7511 *adv = bridge_to_adv7511(bridge);
  670. adv7511_power_on(adv);
  671. }
  672. static void adv7511_bridge_disable(struct drm_bridge *bridge)
  673. {
  674. struct adv7511 *adv = bridge_to_adv7511(bridge);
  675. adv7511_power_off(adv);
  676. }
  677. static void adv7511_bridge_mode_set(struct drm_bridge *bridge,
  678. struct drm_display_mode *mode,
  679. struct drm_display_mode *adj_mode)
  680. {
  681. struct adv7511 *adv = bridge_to_adv7511(bridge);
  682. adv7511_mode_set(adv, mode, adj_mode);
  683. }
  684. static int adv7511_bridge_attach(struct drm_bridge *bridge)
  685. {
  686. struct adv7511 *adv = bridge_to_adv7511(bridge);
  687. int ret;
  688. if (!bridge->encoder) {
  689. DRM_ERROR("Parent encoder object not found");
  690. return -ENODEV;
  691. }
  692. adv->connector.polled = DRM_CONNECTOR_POLL_HPD;
  693. ret = drm_connector_init(bridge->dev, &adv->connector,
  694. &adv7511_connector_funcs,
  695. DRM_MODE_CONNECTOR_HDMIA);
  696. if (ret) {
  697. DRM_ERROR("Failed to initialize connector with drm\n");
  698. return ret;
  699. }
  700. drm_connector_helper_add(&adv->connector,
  701. &adv7511_connector_helper_funcs);
  702. drm_mode_connector_attach_encoder(&adv->connector, bridge->encoder);
  703. if (adv->type == ADV7533)
  704. ret = adv7533_attach_dsi(adv);
  705. if (adv->i2c_main->irq)
  706. regmap_write(adv->regmap, ADV7511_REG_INT_ENABLE(0),
  707. ADV7511_INT0_HPD);
  708. return ret;
  709. }
  710. static struct drm_bridge_funcs adv7511_bridge_funcs = {
  711. .enable = adv7511_bridge_enable,
  712. .disable = adv7511_bridge_disable,
  713. .mode_set = adv7511_bridge_mode_set,
  714. .attach = adv7511_bridge_attach,
  715. };
  716. /* -----------------------------------------------------------------------------
  717. * Probe & remove
  718. */
  719. static const char * const adv7511_supply_names[] = {
  720. "avdd",
  721. "dvdd",
  722. "pvdd",
  723. "bgvdd",
  724. "dvdd-3v",
  725. };
  726. static const char * const adv7533_supply_names[] = {
  727. "avdd",
  728. "dvdd",
  729. "pvdd",
  730. "a2vdd",
  731. "v3p3",
  732. "v1p2",
  733. };
  734. static int adv7511_init_regulators(struct adv7511 *adv)
  735. {
  736. struct device *dev = &adv->i2c_main->dev;
  737. const char * const *supply_names;
  738. unsigned int i;
  739. int ret;
  740. if (adv->type == ADV7511) {
  741. supply_names = adv7511_supply_names;
  742. adv->num_supplies = ARRAY_SIZE(adv7511_supply_names);
  743. } else {
  744. supply_names = adv7533_supply_names;
  745. adv->num_supplies = ARRAY_SIZE(adv7533_supply_names);
  746. }
  747. adv->supplies = devm_kcalloc(dev, adv->num_supplies,
  748. sizeof(*adv->supplies), GFP_KERNEL);
  749. if (!adv->supplies)
  750. return -ENOMEM;
  751. for (i = 0; i < adv->num_supplies; i++)
  752. adv->supplies[i].supply = supply_names[i];
  753. ret = devm_regulator_bulk_get(dev, adv->num_supplies, adv->supplies);
  754. if (ret)
  755. return ret;
  756. return regulator_bulk_enable(adv->num_supplies, adv->supplies);
  757. }
  758. static void adv7511_uninit_regulators(struct adv7511 *adv)
  759. {
  760. regulator_bulk_disable(adv->num_supplies, adv->supplies);
  761. }
  762. static int adv7511_parse_dt(struct device_node *np,
  763. struct adv7511_link_config *config)
  764. {
  765. const char *str;
  766. int ret;
  767. of_property_read_u32(np, "adi,input-depth", &config->input_color_depth);
  768. if (config->input_color_depth != 8 && config->input_color_depth != 10 &&
  769. config->input_color_depth != 12)
  770. return -EINVAL;
  771. ret = of_property_read_string(np, "adi,input-colorspace", &str);
  772. if (ret < 0)
  773. return ret;
  774. if (!strcmp(str, "rgb"))
  775. config->input_colorspace = HDMI_COLORSPACE_RGB;
  776. else if (!strcmp(str, "yuv422"))
  777. config->input_colorspace = HDMI_COLORSPACE_YUV422;
  778. else if (!strcmp(str, "yuv444"))
  779. config->input_colorspace = HDMI_COLORSPACE_YUV444;
  780. else
  781. return -EINVAL;
  782. ret = of_property_read_string(np, "adi,input-clock", &str);
  783. if (ret < 0)
  784. return ret;
  785. if (!strcmp(str, "1x"))
  786. config->input_clock = ADV7511_INPUT_CLOCK_1X;
  787. else if (!strcmp(str, "2x"))
  788. config->input_clock = ADV7511_INPUT_CLOCK_2X;
  789. else if (!strcmp(str, "ddr"))
  790. config->input_clock = ADV7511_INPUT_CLOCK_DDR;
  791. else
  792. return -EINVAL;
  793. if (config->input_colorspace == HDMI_COLORSPACE_YUV422 ||
  794. config->input_clock != ADV7511_INPUT_CLOCK_1X) {
  795. ret = of_property_read_u32(np, "adi,input-style",
  796. &config->input_style);
  797. if (ret)
  798. return ret;
  799. if (config->input_style < 1 || config->input_style > 3)
  800. return -EINVAL;
  801. ret = of_property_read_string(np, "adi,input-justification",
  802. &str);
  803. if (ret < 0)
  804. return ret;
  805. if (!strcmp(str, "left"))
  806. config->input_justification =
  807. ADV7511_INPUT_JUSTIFICATION_LEFT;
  808. else if (!strcmp(str, "evenly"))
  809. config->input_justification =
  810. ADV7511_INPUT_JUSTIFICATION_EVENLY;
  811. else if (!strcmp(str, "right"))
  812. config->input_justification =
  813. ADV7511_INPUT_JUSTIFICATION_RIGHT;
  814. else
  815. return -EINVAL;
  816. } else {
  817. config->input_style = 1;
  818. config->input_justification = ADV7511_INPUT_JUSTIFICATION_LEFT;
  819. }
  820. of_property_read_u32(np, "adi,clock-delay", &config->clock_delay);
  821. if (config->clock_delay < -1200 || config->clock_delay > 1600)
  822. return -EINVAL;
  823. config->embedded_sync = of_property_read_bool(np, "adi,embedded-sync");
  824. /* Hardcode the sync pulse configurations for now. */
  825. config->sync_pulse = ADV7511_INPUT_SYNC_PULSE_NONE;
  826. config->vsync_polarity = ADV7511_SYNC_POLARITY_PASSTHROUGH;
  827. config->hsync_polarity = ADV7511_SYNC_POLARITY_PASSTHROUGH;
  828. return 0;
  829. }
  830. static int adv7511_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
  831. {
  832. struct adv7511_link_config link_config;
  833. struct adv7511 *adv7511;
  834. struct device *dev = &i2c->dev;
  835. unsigned int main_i2c_addr = i2c->addr << 1;
  836. unsigned int edid_i2c_addr = main_i2c_addr + 4;
  837. unsigned int val;
  838. int ret;
  839. if (!dev->of_node)
  840. return -EINVAL;
  841. adv7511 = devm_kzalloc(dev, sizeof(*adv7511), GFP_KERNEL);
  842. if (!adv7511)
  843. return -ENOMEM;
  844. adv7511->i2c_main = i2c;
  845. adv7511->powered = false;
  846. adv7511->status = connector_status_disconnected;
  847. if (dev->of_node)
  848. adv7511->type = (enum adv7511_type)of_device_get_match_data(dev);
  849. else
  850. adv7511->type = id->driver_data;
  851. memset(&link_config, 0, sizeof(link_config));
  852. if (adv7511->type == ADV7511)
  853. ret = adv7511_parse_dt(dev->of_node, &link_config);
  854. else
  855. ret = adv7533_parse_dt(dev->of_node, adv7511);
  856. if (ret)
  857. return ret;
  858. ret = adv7511_init_regulators(adv7511);
  859. if (ret) {
  860. dev_err(dev, "failed to init regulators\n");
  861. return ret;
  862. }
  863. /*
  864. * The power down GPIO is optional. If present, toggle it from active to
  865. * inactive to wake up the encoder.
  866. */
  867. adv7511->gpio_pd = devm_gpiod_get_optional(dev, "pd", GPIOD_OUT_HIGH);
  868. if (IS_ERR(adv7511->gpio_pd)) {
  869. ret = PTR_ERR(adv7511->gpio_pd);
  870. goto uninit_regulators;
  871. }
  872. if (adv7511->gpio_pd) {
  873. mdelay(5);
  874. gpiod_set_value_cansleep(adv7511->gpio_pd, 0);
  875. }
  876. adv7511->regmap = devm_regmap_init_i2c(i2c, &adv7511_regmap_config);
  877. if (IS_ERR(adv7511->regmap)) {
  878. ret = PTR_ERR(adv7511->regmap);
  879. goto uninit_regulators;
  880. }
  881. ret = regmap_read(adv7511->regmap, ADV7511_REG_CHIP_REVISION, &val);
  882. if (ret)
  883. goto uninit_regulators;
  884. dev_dbg(dev, "Rev. %d\n", val);
  885. if (adv7511->type == ADV7511)
  886. ret = regmap_register_patch(adv7511->regmap,
  887. adv7511_fixed_registers,
  888. ARRAY_SIZE(adv7511_fixed_registers));
  889. else
  890. ret = adv7533_patch_registers(adv7511);
  891. if (ret)
  892. goto uninit_regulators;
  893. regmap_write(adv7511->regmap, ADV7511_REG_EDID_I2C_ADDR, edid_i2c_addr);
  894. regmap_write(adv7511->regmap, ADV7511_REG_PACKET_I2C_ADDR,
  895. main_i2c_addr - 0xa);
  896. regmap_write(adv7511->regmap, ADV7511_REG_CEC_I2C_ADDR,
  897. main_i2c_addr - 2);
  898. adv7511_packet_disable(adv7511, 0xffff);
  899. adv7511->i2c_edid = i2c_new_dummy(i2c->adapter, edid_i2c_addr >> 1);
  900. if (!adv7511->i2c_edid) {
  901. ret = -ENOMEM;
  902. goto uninit_regulators;
  903. }
  904. if (adv7511->type == ADV7533) {
  905. ret = adv7533_init_cec(adv7511);
  906. if (ret)
  907. goto err_i2c_unregister_edid;
  908. }
  909. INIT_WORK(&adv7511->hpd_work, adv7511_hpd_work);
  910. if (i2c->irq) {
  911. init_waitqueue_head(&adv7511->wq);
  912. ret = devm_request_threaded_irq(dev, i2c->irq, NULL,
  913. adv7511_irq_handler,
  914. IRQF_ONESHOT, dev_name(dev),
  915. adv7511);
  916. if (ret)
  917. goto err_unregister_cec;
  918. }
  919. /* CEC is unused for now */
  920. regmap_write(adv7511->regmap, ADV7511_REG_CEC_CTRL,
  921. ADV7511_CEC_CTRL_POWER_DOWN);
  922. adv7511_power_off(adv7511);
  923. i2c_set_clientdata(i2c, adv7511);
  924. if (adv7511->type == ADV7511)
  925. adv7511_set_link_config(adv7511, &link_config);
  926. adv7511->bridge.funcs = &adv7511_bridge_funcs;
  927. adv7511->bridge.of_node = dev->of_node;
  928. ret = drm_bridge_add(&adv7511->bridge);
  929. if (ret) {
  930. dev_err(dev, "failed to add adv7511 bridge\n");
  931. goto err_unregister_cec;
  932. }
  933. adv7511_audio_init(dev, adv7511);
  934. return 0;
  935. err_unregister_cec:
  936. adv7533_uninit_cec(adv7511);
  937. err_i2c_unregister_edid:
  938. i2c_unregister_device(adv7511->i2c_edid);
  939. uninit_regulators:
  940. adv7511_uninit_regulators(adv7511);
  941. return ret;
  942. }
  943. static int adv7511_remove(struct i2c_client *i2c)
  944. {
  945. struct adv7511 *adv7511 = i2c_get_clientdata(i2c);
  946. if (adv7511->type == ADV7533) {
  947. adv7533_detach_dsi(adv7511);
  948. adv7533_uninit_cec(adv7511);
  949. }
  950. adv7511_uninit_regulators(adv7511);
  951. drm_bridge_remove(&adv7511->bridge);
  952. adv7511_audio_exit(adv7511);
  953. i2c_unregister_device(adv7511->i2c_edid);
  954. kfree(adv7511->edid);
  955. return 0;
  956. }
  957. static const struct i2c_device_id adv7511_i2c_ids[] = {
  958. { "adv7511", ADV7511 },
  959. { "adv7511w", ADV7511 },
  960. { "adv7513", ADV7511 },
  961. #ifdef CONFIG_DRM_I2C_ADV7533
  962. { "adv7533", ADV7533 },
  963. #endif
  964. { }
  965. };
  966. MODULE_DEVICE_TABLE(i2c, adv7511_i2c_ids);
  967. static const struct of_device_id adv7511_of_ids[] = {
  968. { .compatible = "adi,adv7511", .data = (void *)ADV7511 },
  969. { .compatible = "adi,adv7511w", .data = (void *)ADV7511 },
  970. { .compatible = "adi,adv7513", .data = (void *)ADV7511 },
  971. #ifdef CONFIG_DRM_I2C_ADV7533
  972. { .compatible = "adi,adv7533", .data = (void *)ADV7533 },
  973. #endif
  974. { }
  975. };
  976. MODULE_DEVICE_TABLE(of, adv7511_of_ids);
  977. static struct mipi_dsi_driver adv7533_dsi_driver = {
  978. .driver.name = "adv7533",
  979. };
  980. static struct i2c_driver adv7511_driver = {
  981. .driver = {
  982. .name = "adv7511",
  983. .of_match_table = adv7511_of_ids,
  984. },
  985. .id_table = adv7511_i2c_ids,
  986. .probe = adv7511_probe,
  987. .remove = adv7511_remove,
  988. };
  989. static int __init adv7511_init(void)
  990. {
  991. if (IS_ENABLED(CONFIG_DRM_MIPI_DSI))
  992. mipi_dsi_driver_register(&adv7533_dsi_driver);
  993. return i2c_add_driver(&adv7511_driver);
  994. }
  995. module_init(adv7511_init);
  996. static void __exit adv7511_exit(void)
  997. {
  998. i2c_del_driver(&adv7511_driver);
  999. if (IS_ENABLED(CONFIG_DRM_MIPI_DSI))
  1000. mipi_dsi_driver_unregister(&adv7533_dsi_driver);
  1001. }
  1002. module_exit(adv7511_exit);
  1003. MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
  1004. MODULE_DESCRIPTION("ADV7511 HDMI transmitter driver");
  1005. MODULE_LICENSE("GPL");