blob: e33702bbd5d5be29f8ffa539b13a9daf01b3a752 [file] [log] [blame]
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +01001/*
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>
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +010011#include <linux/module.h>
Archit Taneja2437e7c2016-06-15 16:24:03 +053012#include <linux/of_device.h>
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +010013#include <linux/slab.h>
14
15#include <drm/drmP.h>
Archit Tanejae12c2f62016-01-09 14:24:54 +053016#include <drm/drm_atomic.h>
17#include <drm/drm_atomic_helper.h>
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +010018#include <drm/drm_edid.h>
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +010019
20#include "adv7511.h"
21
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +010022/* ADI recommended values for proper operation. */
Nariman Poushin8019ff62015-07-16 16:36:21 +010023static const struct reg_sequence adv7511_fixed_registers[] = {
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +010024 { 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:
Wolfram Sangcd38a332016-01-04 03:33:46 +0100105 case ADV7511_REG_EDID_READ_CTRL:
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100106 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,
202 bool rgb)
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
209 if (adv7511->edid)
210 config.hdmi_mode = drm_detect_hdmi_monitor(adv7511->edid);
211 else
212 config.hdmi_mode = false;
213
214 hdmi_avi_infoframe_init(&config.avi_infoframe);
215
216 config.avi_infoframe.scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
217
218 if (rgb) {
219 config.csc_enable = false;
220 config.avi_infoframe.colorspace = HDMI_COLORSPACE_RGB;
221 } else {
222 config.csc_scaling_factor = ADV7511_CSC_SCALING_4;
223 config.csc_coefficents = adv7511_csc_ycbcr_to_rgb;
224
225 if ((connector->display_info.color_formats &
226 DRM_COLOR_FORMAT_YCRCB422) &&
227 config.hdmi_mode) {
228 config.csc_enable = false;
229 config.avi_infoframe.colorspace =
230 HDMI_COLORSPACE_YUV422;
231 } else {
232 config.csc_enable = true;
233 config.avi_infoframe.colorspace = HDMI_COLORSPACE_RGB;
234 }
235 }
236
237 if (config.hdmi_mode) {
238 mode = ADV7511_HDMI_CFG_MODE_HDMI;
239
240 switch (config.avi_infoframe.colorspace) {
241 case HDMI_COLORSPACE_YUV444:
242 output_format_422 = false;
243 output_format_ycbcr = true;
244 break;
245 case HDMI_COLORSPACE_YUV422:
246 output_format_422 = true;
247 output_format_ycbcr = true;
248 break;
249 default:
250 output_format_422 = false;
251 output_format_ycbcr = false;
252 break;
253 }
254 } else {
255 mode = ADV7511_HDMI_CFG_MODE_DVI;
256 output_format_422 = false;
257 output_format_ycbcr = false;
258 }
259
260 adv7511_packet_disable(adv7511, ADV7511_PACKET_ENABLE_AVI_INFOFRAME);
261
262 adv7511_set_colormap(adv7511, config.csc_enable,
263 config.csc_coefficents,
264 config.csc_scaling_factor);
265
266 regmap_update_bits(adv7511->regmap, ADV7511_REG_VIDEO_INPUT_CFG1, 0x81,
267 (output_format_422 << 7) | output_format_ycbcr);
268
269 regmap_update_bits(adv7511->regmap, ADV7511_REG_HDCP_HDMI_CFG,
270 ADV7511_HDMI_CFG_MODE_MASK, mode);
271
272 hdmi_avi_infoframe_pack(&config.avi_infoframe, infoframe,
273 sizeof(infoframe));
274
275 /* The AVI infoframe id is not configurable */
276 regmap_bulk_write(adv7511->regmap, ADV7511_REG_AVI_INFOFRAME_VERSION,
277 infoframe + 1, sizeof(infoframe) - 1);
278
279 adv7511_packet_enable(adv7511, ADV7511_PACKET_ENABLE_AVI_INFOFRAME);
280}
281
282static void adv7511_set_link_config(struct adv7511 *adv7511,
283 const struct adv7511_link_config *config)
284{
285 /*
286 * The input style values documented in the datasheet don't match the
287 * hardware register field values :-(
288 */
289 static const unsigned int input_styles[4] = { 0, 2, 1, 3 };
290
291 unsigned int clock_delay;
292 unsigned int color_depth;
293 unsigned int input_id;
294
295 clock_delay = (config->clock_delay + 1200) / 400;
296 color_depth = config->input_color_depth == 8 ? 3
297 : (config->input_color_depth == 10 ? 1 : 2);
298
299 /* TODO Support input ID 6 */
300 if (config->input_colorspace != HDMI_COLORSPACE_YUV422)
301 input_id = config->input_clock == ADV7511_INPUT_CLOCK_DDR
302 ? 5 : 0;
303 else if (config->input_clock == ADV7511_INPUT_CLOCK_DDR)
304 input_id = config->embedded_sync ? 8 : 7;
305 else if (config->input_clock == ADV7511_INPUT_CLOCK_2X)
306 input_id = config->embedded_sync ? 4 : 3;
307 else
308 input_id = config->embedded_sync ? 2 : 1;
309
310 regmap_update_bits(adv7511->regmap, ADV7511_REG_I2C_FREQ_ID_CFG, 0xf,
311 input_id);
312 regmap_update_bits(adv7511->regmap, ADV7511_REG_VIDEO_INPUT_CFG1, 0x7e,
313 (color_depth << 4) |
314 (input_styles[config->input_style] << 2));
315 regmap_write(adv7511->regmap, ADV7511_REG_VIDEO_INPUT_CFG2,
316 config->input_justification << 3);
317 regmap_write(adv7511->regmap, ADV7511_REG_TIMING_GEN_SEQ,
318 config->sync_pulse << 2);
319
320 regmap_write(adv7511->regmap, 0xba, clock_delay << 5);
321
322 adv7511->embedded_sync = config->embedded_sync;
323 adv7511->hsync_polarity = config->hsync_polarity;
324 adv7511->vsync_polarity = config->vsync_polarity;
325 adv7511->rgb = config->input_colorspace == HDMI_COLORSPACE_RGB;
326}
327
Laurent Pinchartc6169e42015-03-02 14:38:52 +0200328static void adv7511_power_on(struct adv7511 *adv7511)
329{
330 adv7511->current_edid_segment = -1;
331
Laurent Pinchartc6169e42015-03-02 14:38:52 +0200332 regmap_update_bits(adv7511->regmap, ADV7511_REG_POWER,
333 ADV7511_POWER_POWER_DOWN, 0);
Wolfram Sangd0be8582016-01-04 03:33:45 +0100334 if (adv7511->i2c_main->irq) {
335 /*
336 * Documentation says the INT_ENABLE registers are reset in
337 * POWER_DOWN mode. My 7511w preserved the bits, however.
338 * Still, let's be safe and stick to the documentation.
339 */
340 regmap_write(adv7511->regmap, ADV7511_REG_INT_ENABLE(0),
341 ADV7511_INT0_EDID_READY);
342 regmap_write(adv7511->regmap, ADV7511_REG_INT_ENABLE(1),
343 ADV7511_INT1_DDC_ERROR);
344 }
Laurent Pinchartc6169e42015-03-02 14:38:52 +0200345
346 /*
Wolfram Sang29ce4ed2016-01-04 03:33:47 +0100347 * Per spec it is allowed to pulse the HPD signal to indicate that the
Laurent Pinchartc6169e42015-03-02 14:38:52 +0200348 * EDID information has changed. Some monitors do this when they wakeup
Wolfram Sang29ce4ed2016-01-04 03:33:47 +0100349 * from standby or are enabled. When the HPD goes low the adv7511 is
Laurent Pinchartc6169e42015-03-02 14:38:52 +0200350 * reset and the outputs are disabled which might cause the monitor to
Wolfram Sang29ce4ed2016-01-04 03:33:47 +0100351 * go to standby again. To avoid this we ignore the HPD pin for the
Laurent Pinchartc6169e42015-03-02 14:38:52 +0200352 * first few seconds after enabling the output.
353 */
354 regmap_update_bits(adv7511->regmap, ADV7511_REG_POWER2,
Wolfram Sang29ce4ed2016-01-04 03:33:47 +0100355 ADV7511_REG_POWER2_HPD_SRC_MASK,
356 ADV7511_REG_POWER2_HPD_SRC_NONE);
Laurent Pinchartc6169e42015-03-02 14:38:52 +0200357
358 /*
359 * Most of the registers are reset during power down or when HPD is low.
360 */
361 regcache_sync(adv7511->regmap);
362
Archit Taneja2437e7c2016-06-15 16:24:03 +0530363 if (adv7511->type == ADV7533)
364 adv7533_dsi_power_on(adv7511);
365
Laurent Pinchartc6169e42015-03-02 14:38:52 +0200366 adv7511->powered = true;
367}
368
369static void adv7511_power_off(struct adv7511 *adv7511)
370{
371 /* TODO: setup additional power down modes */
372 regmap_update_bits(adv7511->regmap, ADV7511_REG_POWER,
373 ADV7511_POWER_POWER_DOWN,
374 ADV7511_POWER_POWER_DOWN);
375 regcache_mark_dirty(adv7511->regmap);
376
Archit Taneja2437e7c2016-06-15 16:24:03 +0530377 if (adv7511->type == ADV7533)
378 adv7533_dsi_power_off(adv7511);
379
Laurent Pinchartc6169e42015-03-02 14:38:52 +0200380 adv7511->powered = false;
381}
382
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100383/* -----------------------------------------------------------------------------
384 * Interrupt and hotplug detection
385 */
386
387static bool adv7511_hpd(struct adv7511 *adv7511)
388{
389 unsigned int irq0;
390 int ret;
391
392 ret = regmap_read(adv7511->regmap, ADV7511_REG_INT(0), &irq0);
393 if (ret < 0)
394 return false;
395
Wolfram Sang29ce4ed2016-01-04 03:33:47 +0100396 if (irq0 & ADV7511_INT0_HPD) {
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100397 regmap_write(adv7511->regmap, ADV7511_REG_INT(0),
Wolfram Sang29ce4ed2016-01-04 03:33:47 +0100398 ADV7511_INT0_HPD);
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100399 return true;
400 }
401
402 return false;
403}
404
Archit Tanejaf0bfcc22016-06-15 16:20:45 +0530405static int adv7511_irq_process(struct adv7511 *adv7511, bool process_hpd)
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100406{
407 unsigned int irq0, irq1;
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100408 int ret;
409
410 ret = regmap_read(adv7511->regmap, ADV7511_REG_INT(0), &irq0);
411 if (ret < 0)
Laurent Pincharta5241282015-02-18 15:19:33 +0200412 return ret;
413
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100414 ret = regmap_read(adv7511->regmap, ADV7511_REG_INT(1), &irq1);
415 if (ret < 0)
Laurent Pincharta5241282015-02-18 15:19:33 +0200416 return ret;
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100417
Laurent Pincharta5241282015-02-18 15:19:33 +0200418 regmap_write(adv7511->regmap, ADV7511_REG_INT(0), irq0);
419 regmap_write(adv7511->regmap, ADV7511_REG_INT(1), irq1);
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100420
Archit Tanejaf0bfcc22016-06-15 16:20:45 +0530421 if (process_hpd && irq0 & ADV7511_INT0_HPD && adv7511->bridge.encoder)
Archit Tanejae12c2f62016-01-09 14:24:54 +0530422 drm_helper_hpd_irq_event(adv7511->connector.dev);
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100423
Laurent Pincharta5241282015-02-18 15:19:33 +0200424 if (irq0 & ADV7511_INT0_EDID_READY || irq1 & ADV7511_INT1_DDC_ERROR) {
425 adv7511->edid_read = true;
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100426
Laurent Pincharta5241282015-02-18 15:19:33 +0200427 if (adv7511->i2c_main->irq)
428 wake_up_all(&adv7511->wq);
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100429 }
430
Laurent Pincharta5241282015-02-18 15:19:33 +0200431 return 0;
432}
433
434static irqreturn_t adv7511_irq_handler(int irq, void *devid)
435{
436 struct adv7511 *adv7511 = devid;
437 int ret;
438
Archit Tanejaf0bfcc22016-06-15 16:20:45 +0530439 ret = adv7511_irq_process(adv7511, true);
Laurent Pincharta5241282015-02-18 15:19:33 +0200440 return ret < 0 ? IRQ_NONE : IRQ_HANDLED;
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100441}
442
443/* -----------------------------------------------------------------------------
444 * EDID retrieval
445 */
446
Laurent Pincharta5241282015-02-18 15:19:33 +0200447static int adv7511_wait_for_edid(struct adv7511 *adv7511, int timeout)
448{
449 int ret;
450
451 if (adv7511->i2c_main->irq) {
452 ret = wait_event_interruptible_timeout(adv7511->wq,
453 adv7511->edid_read, msecs_to_jiffies(timeout));
454 } else {
455 for (; timeout > 0; timeout -= 25) {
Archit Tanejaf0bfcc22016-06-15 16:20:45 +0530456 ret = adv7511_irq_process(adv7511, false);
Laurent Pincharta5241282015-02-18 15:19:33 +0200457 if (ret < 0)
458 break;
459
460 if (adv7511->edid_read)
461 break;
462
463 msleep(25);
464 }
465 }
466
467 return adv7511->edid_read ? 0 : -EIO;
468}
469
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100470static int adv7511_get_edid_block(void *data, u8 *buf, unsigned int block,
471 size_t len)
472{
473 struct adv7511 *adv7511 = data;
474 struct i2c_msg xfer[2];
475 uint8_t offset;
476 unsigned int i;
477 int ret;
478
479 if (len > 128)
480 return -EINVAL;
481
482 if (adv7511->current_edid_segment != block / 2) {
483 unsigned int status;
484
485 ret = regmap_read(adv7511->regmap, ADV7511_REG_DDC_STATUS,
486 &status);
487 if (ret < 0)
488 return ret;
489
490 if (status != 2) {
Laurent Pincharta5241282015-02-18 15:19:33 +0200491 adv7511->edid_read = false;
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100492 regmap_write(adv7511->regmap, ADV7511_REG_EDID_SEGMENT,
493 block);
Laurent Pincharta5241282015-02-18 15:19:33 +0200494 ret = adv7511_wait_for_edid(adv7511, 200);
495 if (ret < 0)
496 return ret;
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100497 }
498
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100499 /* Break this apart, hopefully more I2C controllers will
500 * support 64 byte transfers than 256 byte transfers
501 */
502
503 xfer[0].addr = adv7511->i2c_edid->addr;
504 xfer[0].flags = 0;
505 xfer[0].len = 1;
506 xfer[0].buf = &offset;
507 xfer[1].addr = adv7511->i2c_edid->addr;
508 xfer[1].flags = I2C_M_RD;
509 xfer[1].len = 64;
510 xfer[1].buf = adv7511->edid_buf;
511
512 offset = 0;
513
514 for (i = 0; i < 4; ++i) {
515 ret = i2c_transfer(adv7511->i2c_edid->adapter, xfer,
516 ARRAY_SIZE(xfer));
517 if (ret < 0)
518 return ret;
519 else if (ret != 2)
520 return -EIO;
521
522 xfer[1].buf += 64;
523 offset += 64;
524 }
525
526 adv7511->current_edid_segment = block / 2;
527 }
528
529 if (block % 2 == 0)
530 memcpy(buf, adv7511->edid_buf, len);
531 else
532 memcpy(buf, adv7511->edid_buf + 128, len);
533
534 return 0;
535}
536
537/* -----------------------------------------------------------------------------
Archit Tanejae12c2f62016-01-09 14:24:54 +0530538 * ADV75xx helpers
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100539 */
540
Archit Tanejae12c2f62016-01-09 14:24:54 +0530541static int adv7511_get_modes(struct adv7511 *adv7511,
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100542 struct drm_connector *connector)
543{
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100544 struct edid *edid;
545 unsigned int count;
546
547 /* Reading the EDID only works if the device is powered */
Laurent Pinchartc6169e42015-03-02 14:38:52 +0200548 if (!adv7511->powered) {
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100549 regmap_update_bits(adv7511->regmap, ADV7511_REG_POWER,
550 ADV7511_POWER_POWER_DOWN, 0);
Wolfram Sangd0be8582016-01-04 03:33:45 +0100551 if (adv7511->i2c_main->irq) {
552 regmap_write(adv7511->regmap, ADV7511_REG_INT_ENABLE(0),
553 ADV7511_INT0_EDID_READY);
554 regmap_write(adv7511->regmap, ADV7511_REG_INT_ENABLE(1),
555 ADV7511_INT1_DDC_ERROR);
556 }
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100557 adv7511->current_edid_segment = -1;
558 }
559
560 edid = drm_do_get_edid(connector, adv7511_get_edid_block, adv7511);
561
Laurent Pinchartc6169e42015-03-02 14:38:52 +0200562 if (!adv7511->powered)
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100563 regmap_update_bits(adv7511->regmap, ADV7511_REG_POWER,
564 ADV7511_POWER_POWER_DOWN,
565 ADV7511_POWER_POWER_DOWN);
566
567 kfree(adv7511->edid);
568 adv7511->edid = edid;
569 if (!edid)
570 return 0;
571
572 drm_mode_connector_update_edid_property(connector, edid);
573 count = drm_add_edid_modes(connector, edid);
574
575 adv7511_set_config_csc(adv7511, connector, adv7511->rgb);
576
577 return count;
578}
579
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100580static enum drm_connector_status
Archit Tanejae12c2f62016-01-09 14:24:54 +0530581adv7511_detect(struct adv7511 *adv7511, struct drm_connector *connector)
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100582{
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100583 enum drm_connector_status status;
584 unsigned int val;
585 bool hpd;
586 int ret;
587
588 ret = regmap_read(adv7511->regmap, ADV7511_REG_STATUS, &val);
589 if (ret < 0)
590 return connector_status_disconnected;
591
592 if (val & ADV7511_STATUS_HPD)
593 status = connector_status_connected;
594 else
595 status = connector_status_disconnected;
596
597 hpd = adv7511_hpd(adv7511);
598
599 /* The chip resets itself when the cable is disconnected, so in case
600 * there is a pending HPD interrupt and the cable is connected there was
601 * at least one transition from disconnected to connected and the chip
602 * has to be reinitialized. */
Laurent Pinchartc6169e42015-03-02 14:38:52 +0200603 if (status == connector_status_connected && hpd && adv7511->powered) {
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100604 regcache_mark_dirty(adv7511->regmap);
Laurent Pinchartc6169e42015-03-02 14:38:52 +0200605 adv7511_power_on(adv7511);
Archit Tanejae12c2f62016-01-09 14:24:54 +0530606 adv7511_get_modes(adv7511, connector);
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100607 if (adv7511->status == connector_status_connected)
608 status = connector_status_disconnected;
609 } else {
Wolfram Sang29ce4ed2016-01-04 03:33:47 +0100610 /* Renable HPD sensing */
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100611 regmap_update_bits(adv7511->regmap, ADV7511_REG_POWER2,
Wolfram Sang29ce4ed2016-01-04 03:33:47 +0100612 ADV7511_REG_POWER2_HPD_SRC_MASK,
613 ADV7511_REG_POWER2_HPD_SRC_BOTH);
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100614 }
615
616 adv7511->status = status;
617 return status;
618}
619
Archit Tanejae12c2f62016-01-09 14:24:54 +0530620static int adv7511_mode_valid(struct adv7511 *adv7511,
621 struct drm_display_mode *mode)
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100622{
623 if (mode->clock > 165000)
624 return MODE_CLOCK_HIGH;
625
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100626 return MODE_OK;
627}
628
Archit Tanejae12c2f62016-01-09 14:24:54 +0530629static void adv7511_mode_set(struct adv7511 *adv7511,
630 struct drm_display_mode *mode,
631 struct drm_display_mode *adj_mode)
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100632{
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100633 unsigned int low_refresh_rate;
634 unsigned int hsync_polarity = 0;
635 unsigned int vsync_polarity = 0;
636
637 if (adv7511->embedded_sync) {
638 unsigned int hsync_offset, hsync_len;
639 unsigned int vsync_offset, vsync_len;
640
641 hsync_offset = adj_mode->crtc_hsync_start -
642 adj_mode->crtc_hdisplay;
643 vsync_offset = adj_mode->crtc_vsync_start -
644 adj_mode->crtc_vdisplay;
645 hsync_len = adj_mode->crtc_hsync_end -
646 adj_mode->crtc_hsync_start;
647 vsync_len = adj_mode->crtc_vsync_end -
648 adj_mode->crtc_vsync_start;
649
650 /* The hardware vsync generator has a off-by-one bug */
651 vsync_offset += 1;
652
653 regmap_write(adv7511->regmap, ADV7511_REG_HSYNC_PLACEMENT_MSB,
654 ((hsync_offset >> 10) & 0x7) << 5);
655 regmap_write(adv7511->regmap, ADV7511_REG_SYNC_DECODER(0),
656 (hsync_offset >> 2) & 0xff);
657 regmap_write(adv7511->regmap, ADV7511_REG_SYNC_DECODER(1),
658 ((hsync_offset & 0x3) << 6) |
659 ((hsync_len >> 4) & 0x3f));
660 regmap_write(adv7511->regmap, ADV7511_REG_SYNC_DECODER(2),
661 ((hsync_len & 0xf) << 4) |
662 ((vsync_offset >> 6) & 0xf));
663 regmap_write(adv7511->regmap, ADV7511_REG_SYNC_DECODER(3),
664 ((vsync_offset & 0x3f) << 2) |
665 ((vsync_len >> 8) & 0x3));
666 regmap_write(adv7511->regmap, ADV7511_REG_SYNC_DECODER(4),
667 vsync_len & 0xff);
668
669 hsync_polarity = !(adj_mode->flags & DRM_MODE_FLAG_PHSYNC);
670 vsync_polarity = !(adj_mode->flags & DRM_MODE_FLAG_PVSYNC);
671 } else {
672 enum adv7511_sync_polarity mode_hsync_polarity;
673 enum adv7511_sync_polarity mode_vsync_polarity;
674
675 /**
676 * If the input signal is always low or always high we want to
677 * invert or let it passthrough depending on the polarity of the
678 * current mode.
679 **/
680 if (adj_mode->flags & DRM_MODE_FLAG_NHSYNC)
681 mode_hsync_polarity = ADV7511_SYNC_POLARITY_LOW;
682 else
683 mode_hsync_polarity = ADV7511_SYNC_POLARITY_HIGH;
684
685 if (adj_mode->flags & DRM_MODE_FLAG_NVSYNC)
686 mode_vsync_polarity = ADV7511_SYNC_POLARITY_LOW;
687 else
688 mode_vsync_polarity = ADV7511_SYNC_POLARITY_HIGH;
689
690 if (adv7511->hsync_polarity != mode_hsync_polarity &&
691 adv7511->hsync_polarity !=
692 ADV7511_SYNC_POLARITY_PASSTHROUGH)
693 hsync_polarity = 1;
694
695 if (adv7511->vsync_polarity != mode_vsync_polarity &&
696 adv7511->vsync_polarity !=
697 ADV7511_SYNC_POLARITY_PASSTHROUGH)
698 vsync_polarity = 1;
699 }
700
701 if (mode->vrefresh <= 24000)
702 low_refresh_rate = ADV7511_LOW_REFRESH_RATE_24HZ;
703 else if (mode->vrefresh <= 25000)
704 low_refresh_rate = ADV7511_LOW_REFRESH_RATE_25HZ;
705 else if (mode->vrefresh <= 30000)
706 low_refresh_rate = ADV7511_LOW_REFRESH_RATE_30HZ;
707 else
708 low_refresh_rate = ADV7511_LOW_REFRESH_RATE_NONE;
709
710 regmap_update_bits(adv7511->regmap, 0xfb,
711 0x6, low_refresh_rate << 1);
712 regmap_update_bits(adv7511->regmap, 0x17,
713 0x60, (vsync_polarity << 6) | (hsync_polarity << 5));
714
715 /*
716 * TODO Test first order 4:2:2 to 4:4:4 up conversion method, which is
717 * supposed to give better results.
718 */
719
720 adv7511->f_tmds = mode->clock;
721}
722
Archit Tanejae12c2f62016-01-09 14:24:54 +0530723/* Connector funcs */
724static struct adv7511 *connector_to_adv7511(struct drm_connector *connector)
725{
726 return container_of(connector, struct adv7511, connector);
727}
728
729static int adv7511_connector_get_modes(struct drm_connector *connector)
730{
731 struct adv7511 *adv = connector_to_adv7511(connector);
732
733 return adv7511_get_modes(adv, connector);
734}
735
736static enum drm_mode_status
737adv7511_connector_mode_valid(struct drm_connector *connector,
738 struct drm_display_mode *mode)
739{
740 struct adv7511 *adv = connector_to_adv7511(connector);
741
742 return adv7511_mode_valid(adv, mode);
743}
744
745static struct drm_connector_helper_funcs adv7511_connector_helper_funcs = {
746 .get_modes = adv7511_connector_get_modes,
747 .mode_valid = adv7511_connector_mode_valid,
748};
749
750static enum drm_connector_status
751adv7511_connector_detect(struct drm_connector *connector, bool force)
752{
753 struct adv7511 *adv = connector_to_adv7511(connector);
754
755 return adv7511_detect(adv, connector);
756}
757
758static struct drm_connector_funcs adv7511_connector_funcs = {
759 .dpms = drm_atomic_helper_connector_dpms,
760 .fill_modes = drm_helper_probe_single_connector_modes,
761 .detect = adv7511_connector_detect,
762 .destroy = drm_connector_cleanup,
763 .reset = drm_atomic_helper_connector_reset,
764 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
765 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
766};
767
768/* Bridge funcs */
769static struct adv7511 *bridge_to_adv7511(struct drm_bridge *bridge)
770{
771 return container_of(bridge, struct adv7511, bridge);
772}
773
774static void adv7511_bridge_enable(struct drm_bridge *bridge)
775{
776 struct adv7511 *adv = bridge_to_adv7511(bridge);
777
778 adv7511_power_on(adv);
779}
780
781static void adv7511_bridge_disable(struct drm_bridge *bridge)
782{
783 struct adv7511 *adv = bridge_to_adv7511(bridge);
784
785 adv7511_power_off(adv);
786}
787
788static void adv7511_bridge_mode_set(struct drm_bridge *bridge,
789 struct drm_display_mode *mode,
790 struct drm_display_mode *adj_mode)
791{
792 struct adv7511 *adv = bridge_to_adv7511(bridge);
793
794 adv7511_mode_set(adv, mode, adj_mode);
795}
796
797static int adv7511_bridge_attach(struct drm_bridge *bridge)
798{
799 struct adv7511 *adv = bridge_to_adv7511(bridge);
800 int ret;
801
802 if (!bridge->encoder) {
803 DRM_ERROR("Parent encoder object not found");
804 return -ENODEV;
805 }
806
807 adv->connector.polled = DRM_CONNECTOR_POLL_HPD;
808
809 ret = drm_connector_init(bridge->dev, &adv->connector,
810 &adv7511_connector_funcs,
811 DRM_MODE_CONNECTOR_HDMIA);
812 if (ret) {
813 DRM_ERROR("Failed to initialize connector with drm\n");
814 return ret;
815 }
816 drm_connector_helper_add(&adv->connector,
817 &adv7511_connector_helper_funcs);
818 drm_mode_connector_attach_encoder(&adv->connector, bridge->encoder);
819
820 return ret;
821}
822
823static struct drm_bridge_funcs adv7511_bridge_funcs = {
824 .enable = adv7511_bridge_enable,
825 .disable = adv7511_bridge_disable,
826 .mode_set = adv7511_bridge_mode_set,
827 .attach = adv7511_bridge_attach,
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100828};
829
830/* -----------------------------------------------------------------------------
831 * Probe & remove
832 */
833
834static int adv7511_parse_dt(struct device_node *np,
835 struct adv7511_link_config *config)
836{
837 const char *str;
838 int ret;
839
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100840 of_property_read_u32(np, "adi,input-depth", &config->input_color_depth);
841 if (config->input_color_depth != 8 && config->input_color_depth != 10 &&
842 config->input_color_depth != 12)
843 return -EINVAL;
844
845 ret = of_property_read_string(np, "adi,input-colorspace", &str);
846 if (ret < 0)
847 return ret;
848
849 if (!strcmp(str, "rgb"))
850 config->input_colorspace = HDMI_COLORSPACE_RGB;
851 else if (!strcmp(str, "yuv422"))
852 config->input_colorspace = HDMI_COLORSPACE_YUV422;
853 else if (!strcmp(str, "yuv444"))
854 config->input_colorspace = HDMI_COLORSPACE_YUV444;
855 else
856 return -EINVAL;
857
858 ret = of_property_read_string(np, "adi,input-clock", &str);
859 if (ret < 0)
860 return ret;
861
862 if (!strcmp(str, "1x"))
863 config->input_clock = ADV7511_INPUT_CLOCK_1X;
864 else if (!strcmp(str, "2x"))
865 config->input_clock = ADV7511_INPUT_CLOCK_2X;
866 else if (!strcmp(str, "ddr"))
867 config->input_clock = ADV7511_INPUT_CLOCK_DDR;
868 else
869 return -EINVAL;
870
871 if (config->input_colorspace == HDMI_COLORSPACE_YUV422 ||
872 config->input_clock != ADV7511_INPUT_CLOCK_1X) {
873 ret = of_property_read_u32(np, "adi,input-style",
874 &config->input_style);
875 if (ret)
876 return ret;
877
878 if (config->input_style < 1 || config->input_style > 3)
879 return -EINVAL;
880
881 ret = of_property_read_string(np, "adi,input-justification",
882 &str);
883 if (ret < 0)
884 return ret;
885
886 if (!strcmp(str, "left"))
887 config->input_justification =
888 ADV7511_INPUT_JUSTIFICATION_LEFT;
889 else if (!strcmp(str, "evenly"))
890 config->input_justification =
891 ADV7511_INPUT_JUSTIFICATION_EVENLY;
892 else if (!strcmp(str, "right"))
893 config->input_justification =
894 ADV7511_INPUT_JUSTIFICATION_RIGHT;
895 else
896 return -EINVAL;
897
898 } else {
899 config->input_style = 1;
900 config->input_justification = ADV7511_INPUT_JUSTIFICATION_LEFT;
901 }
902
903 of_property_read_u32(np, "adi,clock-delay", &config->clock_delay);
904 if (config->clock_delay < -1200 || config->clock_delay > 1600)
905 return -EINVAL;
906
907 config->embedded_sync = of_property_read_bool(np, "adi,embedded-sync");
908
909 /* Hardcode the sync pulse configurations for now. */
910 config->sync_pulse = ADV7511_INPUT_SYNC_PULSE_NONE;
911 config->vsync_polarity = ADV7511_SYNC_POLARITY_PASSTHROUGH;
912 config->hsync_polarity = ADV7511_SYNC_POLARITY_PASSTHROUGH;
913
914 return 0;
915}
916
917static const int edid_i2c_addr = 0x7e;
918static const int packet_i2c_addr = 0x70;
919static const int cec_i2c_addr = 0x78;
920
921static int adv7511_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
922{
923 struct adv7511_link_config link_config;
924 struct adv7511 *adv7511;
925 struct device *dev = &i2c->dev;
926 unsigned int val;
927 int ret;
928
929 if (!dev->of_node)
930 return -EINVAL;
931
932 adv7511 = devm_kzalloc(dev, sizeof(*adv7511), GFP_KERNEL);
933 if (!adv7511)
934 return -ENOMEM;
935
Laurent Pinchartc6169e42015-03-02 14:38:52 +0200936 adv7511->powered = false;
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100937 adv7511->status = connector_status_disconnected;
938
Archit Taneja2437e7c2016-06-15 16:24:03 +0530939 if (dev->of_node)
940 adv7511->type = (enum adv7511_type)of_device_get_match_data(dev);
941 else
942 adv7511->type = id->driver_data;
943
944 memset(&link_config, 0, sizeof(link_config));
945
946 if (adv7511->type == ADV7511) {
947 ret = adv7511_parse_dt(dev->of_node, &link_config);
948 if (ret)
949 return ret;
950 }
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100951
952 /*
953 * The power down GPIO is optional. If present, toggle it from active to
954 * inactive to wake up the encoder.
955 */
956 adv7511->gpio_pd = devm_gpiod_get_optional(dev, "pd", GPIOD_OUT_HIGH);
957 if (IS_ERR(adv7511->gpio_pd))
958 return PTR_ERR(adv7511->gpio_pd);
959
960 if (adv7511->gpio_pd) {
961 mdelay(5);
962 gpiod_set_value_cansleep(adv7511->gpio_pd, 0);
963 }
964
965 adv7511->regmap = devm_regmap_init_i2c(i2c, &adv7511_regmap_config);
966 if (IS_ERR(adv7511->regmap))
967 return PTR_ERR(adv7511->regmap);
968
969 ret = regmap_read(adv7511->regmap, ADV7511_REG_CHIP_REVISION, &val);
970 if (ret)
971 return ret;
972 dev_dbg(dev, "Rev. %d\n", val);
973
Archit Taneja2437e7c2016-06-15 16:24:03 +0530974 if (adv7511->type == ADV7511)
975 ret = regmap_register_patch(adv7511->regmap,
976 adv7511_fixed_registers,
977 ARRAY_SIZE(adv7511_fixed_registers));
978 else
979 ret = adv7533_patch_registers(adv7511);
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +0100980 if (ret)
981 return ret;
982
983 regmap_write(adv7511->regmap, ADV7511_REG_EDID_I2C_ADDR, edid_i2c_addr);
984 regmap_write(adv7511->regmap, ADV7511_REG_PACKET_I2C_ADDR,
985 packet_i2c_addr);
986 regmap_write(adv7511->regmap, ADV7511_REG_CEC_I2C_ADDR, cec_i2c_addr);
987 adv7511_packet_disable(adv7511, 0xffff);
988
989 adv7511->i2c_main = i2c;
990 adv7511->i2c_edid = i2c_new_dummy(i2c->adapter, edid_i2c_addr >> 1);
991 if (!adv7511->i2c_edid)
992 return -ENOMEM;
993
Archit Taneja2437e7c2016-06-15 16:24:03 +0530994 if (adv7511->type == ADV7533) {
995 ret = adv7533_init_cec(adv7511);
996 if (ret)
997 goto err_i2c_unregister_edid;
998 }
999
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +01001000 if (i2c->irq) {
1001 init_waitqueue_head(&adv7511->wq);
1002
1003 ret = devm_request_threaded_irq(dev, i2c->irq, NULL,
1004 adv7511_irq_handler,
1005 IRQF_ONESHOT, dev_name(dev),
1006 adv7511);
1007 if (ret)
Archit Taneja2437e7c2016-06-15 16:24:03 +05301008 goto err_unregister_cec;
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +01001009 }
1010
1011 /* CEC is unused for now */
1012 regmap_write(adv7511->regmap, ADV7511_REG_CEC_CTRL,
1013 ADV7511_CEC_CTRL_POWER_DOWN);
1014
Laurent Pinchartc6169e42015-03-02 14:38:52 +02001015 adv7511_power_off(adv7511);
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +01001016
1017 i2c_set_clientdata(i2c, adv7511);
1018
Archit Taneja2437e7c2016-06-15 16:24:03 +05301019 if (adv7511->type == ADV7511)
1020 adv7511_set_link_config(adv7511, &link_config);
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +01001021
Archit Tanejae12c2f62016-01-09 14:24:54 +05301022 adv7511->bridge.funcs = &adv7511_bridge_funcs;
1023 adv7511->bridge.of_node = dev->of_node;
1024
1025 ret = drm_bridge_add(&adv7511->bridge);
1026 if (ret) {
1027 dev_err(dev, "failed to add adv7511 bridge\n");
Archit Taneja2437e7c2016-06-15 16:24:03 +05301028 goto err_unregister_cec;
Archit Tanejae12c2f62016-01-09 14:24:54 +05301029 }
1030
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +01001031 return 0;
1032
Archit Taneja2437e7c2016-06-15 16:24:03 +05301033err_unregister_cec:
1034 adv7533_uninit_cec(adv7511);
1035err_i2c_unregister_edid:
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +01001036 i2c_unregister_device(adv7511->i2c_edid);
1037
1038 return ret;
1039}
1040
1041static int adv7511_remove(struct i2c_client *i2c)
1042{
1043 struct adv7511 *adv7511 = i2c_get_clientdata(i2c);
1044
Archit Tanejae12c2f62016-01-09 14:24:54 +05301045 drm_bridge_remove(&adv7511->bridge);
1046
Archit Taneja2437e7c2016-06-15 16:24:03 +05301047 adv7533_uninit_cec(adv7511);
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +01001048 i2c_unregister_device(adv7511->i2c_edid);
1049
1050 kfree(adv7511->edid);
1051
1052 return 0;
1053}
1054
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +01001055static const struct i2c_device_id adv7511_i2c_ids[] = {
Archit Taneja2437e7c2016-06-15 16:24:03 +05301056 { "adv7511", ADV7511 },
1057 { "adv7511w", ADV7511 },
1058 { "adv7513", ADV7511 },
1059#ifdef CONFIG_DRM_I2C_ADV7533
1060 { "adv7533", ADV7533 },
1061#endif
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +01001062 { }
1063};
1064MODULE_DEVICE_TABLE(i2c, adv7511_i2c_ids);
1065
1066static const struct of_device_id adv7511_of_ids[] = {
Archit Taneja2437e7c2016-06-15 16:24:03 +05301067 { .compatible = "adi,adv7511", .data = (void *)ADV7511 },
1068 { .compatible = "adi,adv7511w", .data = (void *)ADV7511 },
1069 { .compatible = "adi,adv7513", .data = (void *)ADV7511 },
1070#ifdef CONFIG_DRM_I2C_ADV7533
1071 { .compatible = "adi,adv7533", .data = (void *)ADV7533 },
1072#endif
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +01001073 { }
1074};
1075MODULE_DEVICE_TABLE(of, adv7511_of_ids);
1076
Archit Tanejae12c2f62016-01-09 14:24:54 +05301077static struct i2c_driver adv7511_driver = {
1078 .driver = {
1079 .name = "adv7511",
1080 .of_match_table = adv7511_of_ids,
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +01001081 },
Archit Tanejae12c2f62016-01-09 14:24:54 +05301082 .id_table = adv7511_i2c_ids,
1083 .probe = adv7511_probe,
1084 .remove = adv7511_remove,
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +01001085};
1086
Archit Tanejae12c2f62016-01-09 14:24:54 +05301087module_i2c_driver(adv7511_driver);
Lars-Peter Clausen9c8af882012-03-05 16:30:57 +01001088
1089MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
1090MODULE_DESCRIPTION("ADV7511 HDMI transmitter driver");
1091MODULE_LICENSE("GPL");