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