xref: /linux/drivers/gpu/drm/bridge/chrontel-ch7033.c (revision 570f7e331f5febb30f1384817463c7e42b65ca7d)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Chrontel CH7033 Video Encoder Driver
4  *
5  * Copyright (C) 2019,2020 Lubomir Rintel
6  */
7 
8 #include <linux/gpio/consumer.h>
9 #include <linux/i2c.h>
10 #include <linux/module.h>
11 #include <linux/regmap.h>
12 
13 #include <drm/drm_atomic_helper.h>
14 #include <drm/drm_bridge.h>
15 #include <drm/drm_edid.h>
16 #include <drm/drm_of.h>
17 #include <drm/drm_print.h>
18 #include <drm/drm_probe_helper.h>
19 
20 /* Page 0, Register 0x07 */
21 enum {
22 	DRI_PD		= BIT(3),
23 	IO_PD		= BIT(5),
24 };
25 
26 /* Page 0, Register 0x08 */
27 enum {
28 	DRI_PDDRI	= GENMASK(7, 4),
29 	PDDAC		= GENMASK(3, 1),
30 	PANEN		= BIT(0),
31 };
32 
33 /* Page 0, Register 0x09 */
34 enum {
35 	DPD		= BIT(7),
36 	GCKOFF		= BIT(6),
37 	TV_BP		= BIT(5),
38 	SCLPD		= BIT(4),
39 	SDPD		= BIT(3),
40 	VGA_PD		= BIT(2),
41 	HDBKPD		= BIT(1),
42 	HDMI_PD		= BIT(0),
43 };
44 
45 /* Page 0, Register 0x0a */
46 enum {
47 	MEMINIT		= BIT(7),
48 	MEMIDLE		= BIT(6),
49 	MEMPD		= BIT(5),
50 	STOP		= BIT(4),
51 	LVDS_PD		= BIT(3),
52 	HD_DVIB		= BIT(2),
53 	HDCP_PD		= BIT(1),
54 	MCU_PD		= BIT(0),
55 };
56 
57 /* Page 0, Register 0x18 */
58 enum {
59 	IDF		= GENMASK(7, 4),
60 	INTEN		= BIT(3),
61 	SWAP		= GENMASK(2, 0),
62 };
63 
64 enum {
65 	BYTE_SWAP_RGB	= 0,
66 	BYTE_SWAP_RBG	= 1,
67 	BYTE_SWAP_GRB	= 2,
68 	BYTE_SWAP_GBR	= 3,
69 	BYTE_SWAP_BRG	= 4,
70 	BYTE_SWAP_BGR	= 5,
71 };
72 
73 /* Page 0, Register 0x19 */
74 enum {
75 	HPO_I		= BIT(5),
76 	VPO_I		= BIT(4),
77 	DEPO_I		= BIT(3),
78 	CRYS_EN		= BIT(2),
79 	GCLKFREQ	= GENMASK(2, 0),
80 };
81 
82 /* Page 0, Register 0x2e */
83 enum {
84 	HFLIP		= BIT(7),
85 	VFLIP		= BIT(6),
86 	DEPO_O		= BIT(5),
87 	HPO_O		= BIT(4),
88 	VPO_O		= BIT(3),
89 	TE		= GENMASK(2, 0),
90 };
91 
92 /* Page 0, Register 0x2b */
93 enum {
94 	SWAPS		= GENMASK(7, 4),
95 	VFMT		= GENMASK(3, 0),
96 };
97 
98 /* Page 0, Register 0x54 */
99 enum {
100 	COMP_BP		= BIT(7),
101 	DAC_EN_T	= BIT(6),
102 	HWO_HDMI_HI	= GENMASK(5, 3),
103 	HOO_HDMI_HI	= GENMASK(2, 0),
104 };
105 
106 /* Page 0, Register 0x57 */
107 enum {
108 	FLDSEN		= BIT(7),
109 	VWO_HDMI_HI	= GENMASK(5, 3),
110 	VOO_HDMI_HI	= GENMASK(2, 0),
111 };
112 
113 /* Page 0, Register 0x7e */
114 enum {
115 	HDMI_LVDS_SEL	= BIT(7),
116 	DE_GEN		= BIT(6),
117 	PWM_INDEX_HI	= BIT(5),
118 	USE_DE		= BIT(4),
119 	R_INT		= GENMASK(3, 0),
120 };
121 
122 /* Page 1, Register 0x07 */
123 enum {
124 	BPCKSEL		= BIT(7),
125 	DRI_CMFB_EN	= BIT(6),
126 	CEC_PUEN	= BIT(5),
127 	CEC_T		= BIT(3),
128 	CKINV		= BIT(2),
129 	CK_TVINV	= BIT(1),
130 	DRI_CKS2	= BIT(0),
131 };
132 
133 /* Page 1, Register 0x08 */
134 enum {
135 	DACG		= BIT(6),
136 	DACKTST		= BIT(5),
137 	DEDGEB		= BIT(4),
138 	SYO		= BIT(3),
139 	DRI_IT_LVDS	= GENMASK(2, 1),
140 	DISPON		= BIT(0),
141 };
142 
143 /* Page 1, Register 0x0c */
144 enum {
145 	DRI_PLL_CP	= GENMASK(7, 6),
146 	DRI_PLL_DIVSEL	= BIT(5),
147 	DRI_PLL_N1_1	= BIT(4),
148 	DRI_PLL_N1_0	= BIT(3),
149 	DRI_PLL_N3_1	= BIT(2),
150 	DRI_PLL_N3_0	= BIT(1),
151 	DRI_PLL_CKTSTEN = BIT(0),
152 };
153 
154 /* Page 1, Register 0x6b */
155 enum {
156 	VCO3CS		= GENMASK(7, 6),
157 	ICPGBK2_0	= GENMASK(5, 3),
158 	DRI_VCO357SC	= BIT(2),
159 	PDPLL2		= BIT(1),
160 	DRI_PD_SER	= BIT(0),
161 };
162 
163 /* Page 1, Register 0x6c */
164 enum {
165 	PLL2N11		= GENMASK(7, 4),
166 	PLL2N5_4	= BIT(3),
167 	PLL2N5_TOP	= BIT(2),
168 	DRI_PLL_PD	= BIT(1),
169 	PD_I2CM		= BIT(0),
170 };
171 
172 /* Page 3, Register 0x28 */
173 enum {
174 	DIFF_EN		= GENMASK(7, 6),
175 	CORREC_EN	= GENMASK(5, 4),
176 	VGACLK_BP	= BIT(3),
177 	HM_LV_SEL	= BIT(2),
178 	HD_VGA_SEL	= BIT(1),
179 };
180 
181 /* Page 3, Register 0x2a */
182 enum {
183 	LVDSCLK_BP	= BIT(7),
184 	HDTVCLK_BP	= BIT(6),
185 	HDMICLK_BP	= BIT(5),
186 	HDTV_BP		= BIT(4),
187 	HDMI_BP		= BIT(3),
188 	THRWL		= GENMASK(2, 0),
189 };
190 
191 /* Page 4, Register 0x52 */
192 enum {
193 	PGM_ARSTB	= BIT(7),
194 	MCU_ARSTB	= BIT(6),
195 	MCU_RETB	= BIT(2),
196 	RESETIB		= BIT(1),
197 	RESETDB		= BIT(0),
198 };
199 
200 struct ch7033_priv {
201 	struct regmap *regmap;
202 	struct drm_bridge bridge;
203 	struct drm_connector connector;
204 };
205 
206 #define conn_to_ch7033_priv(x) \
207 	container_of(x, struct ch7033_priv, connector)
208 #define bridge_to_ch7033_priv(x) \
209 	container_of(x, struct ch7033_priv, bridge)
210 
211 
212 static enum drm_connector_status ch7033_connector_detect(
213 	struct drm_connector *connector, bool force)
214 {
215 	struct ch7033_priv *priv = conn_to_ch7033_priv(connector);
216 
217 	return drm_bridge_detect(priv->bridge.next_bridge, connector);
218 }
219 
220 static const struct drm_connector_funcs ch7033_connector_funcs = {
221 	.reset = drm_atomic_helper_connector_reset,
222 	.fill_modes = drm_helper_probe_single_connector_modes,
223 	.detect = ch7033_connector_detect,
224 	.destroy = drm_connector_cleanup,
225 	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
226 	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
227 };
228 
229 static int ch7033_connector_get_modes(struct drm_connector *connector)
230 {
231 	struct ch7033_priv *priv = conn_to_ch7033_priv(connector);
232 	const struct drm_edid *drm_edid;
233 	int ret;
234 
235 	drm_edid = drm_bridge_edid_read(priv->bridge.next_bridge, connector);
236 	drm_edid_connector_update(connector, drm_edid);
237 	if (drm_edid) {
238 		ret = drm_edid_connector_add_modes(connector);
239 		drm_edid_free(drm_edid);
240 	} else {
241 		ret = drm_add_modes_noedid(connector, 1920, 1080);
242 		drm_set_preferred_mode(connector, 1024, 768);
243 	}
244 
245 	return ret;
246 }
247 
248 static struct drm_encoder *ch7033_connector_best_encoder(
249 			struct drm_connector *connector)
250 {
251 	struct ch7033_priv *priv = conn_to_ch7033_priv(connector);
252 
253 	return priv->bridge.encoder;
254 }
255 
256 static const struct drm_connector_helper_funcs ch7033_connector_helper_funcs = {
257 	.get_modes = ch7033_connector_get_modes,
258 	.best_encoder = ch7033_connector_best_encoder,
259 };
260 
261 static void ch7033_hpd_event(void *arg, enum drm_connector_status status)
262 {
263 	struct ch7033_priv *priv = arg;
264 
265 	if (priv->bridge.dev)
266 		drm_helper_hpd_irq_event(priv->connector.dev);
267 }
268 
269 static int ch7033_bridge_attach(struct drm_bridge *bridge,
270 				struct drm_encoder *encoder,
271 				enum drm_bridge_attach_flags flags)
272 {
273 	struct ch7033_priv *priv = bridge_to_ch7033_priv(bridge);
274 	struct drm_connector *connector = &priv->connector;
275 	int ret;
276 
277 	ret = drm_bridge_attach(encoder, priv->bridge.next_bridge, bridge,
278 				DRM_BRIDGE_ATTACH_NO_CONNECTOR);
279 	if (ret)
280 		return ret;
281 
282 	if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)
283 		return 0;
284 
285 	if (priv->bridge.next_bridge->ops & DRM_BRIDGE_OP_DETECT) {
286 		connector->polled = DRM_CONNECTOR_POLL_HPD;
287 	} else {
288 		connector->polled = DRM_CONNECTOR_POLL_CONNECT |
289 				    DRM_CONNECTOR_POLL_DISCONNECT;
290 	}
291 
292 	if (priv->bridge.next_bridge->ops & DRM_BRIDGE_OP_HPD) {
293 		drm_bridge_hpd_enable(priv->bridge.next_bridge, ch7033_hpd_event,
294 				      priv);
295 	}
296 
297 	drm_connector_helper_add(connector,
298 				 &ch7033_connector_helper_funcs);
299 	ret = drm_connector_init_with_ddc(bridge->dev, &priv->connector,
300 					  &ch7033_connector_funcs,
301 					  priv->bridge.next_bridge->type,
302 					  priv->bridge.next_bridge->ddc);
303 	if (ret) {
304 		DRM_ERROR("Failed to initialize connector\n");
305 		return ret;
306 	}
307 
308 	return drm_connector_attach_encoder(&priv->connector, encoder);
309 }
310 
311 static void ch7033_bridge_detach(struct drm_bridge *bridge)
312 {
313 	struct ch7033_priv *priv = bridge_to_ch7033_priv(bridge);
314 
315 	if (priv->bridge.next_bridge->ops & DRM_BRIDGE_OP_HPD)
316 		drm_bridge_hpd_disable(priv->bridge.next_bridge);
317 	drm_connector_cleanup(&priv->connector);
318 }
319 
320 static enum drm_mode_status ch7033_bridge_mode_valid(struct drm_bridge *bridge,
321 				     const struct drm_display_info *info,
322 				     const struct drm_display_mode *mode)
323 {
324 	if (mode->clock > 165000)
325 		return MODE_CLOCK_HIGH;
326 	if (mode->hdisplay >= 1920)
327 		return MODE_BAD_HVALUE;
328 	if (mode->vdisplay >= 1080)
329 		return MODE_BAD_VVALUE;
330 	return MODE_OK;
331 }
332 
333 static void ch7033_bridge_disable(struct drm_bridge *bridge,
334 				  struct drm_atomic_commit *commit)
335 {
336 	struct ch7033_priv *priv = bridge_to_ch7033_priv(bridge);
337 
338 	regmap_write(priv->regmap, 0x03, 0x04);
339 	regmap_update_bits(priv->regmap, 0x52, RESETDB, 0x00);
340 }
341 
342 static void ch7033_bridge_enable(struct drm_bridge *bridge,
343 				 struct drm_atomic_commit *commit)
344 {
345 	struct ch7033_priv *priv = bridge_to_ch7033_priv(bridge);
346 
347 	regmap_write(priv->regmap, 0x03, 0x04);
348 	regmap_update_bits(priv->regmap, 0x52, RESETDB, RESETDB);
349 }
350 
351 static void ch7033_bridge_mode_set(struct drm_bridge *bridge,
352 				   const struct drm_display_mode *mode,
353 				   const struct drm_display_mode *adjusted_mode)
354 {
355 	struct ch7033_priv *priv = bridge_to_ch7033_priv(bridge);
356 	int hbporch = mode->hsync_start - mode->hdisplay;
357 	int hsynclen = mode->hsync_end - mode->hsync_start;
358 	int vbporch = mode->vsync_start - mode->vdisplay;
359 	int vsynclen = mode->vsync_end - mode->vsync_start;
360 
361 	/*
362 	 * Page 4
363 	 */
364 	regmap_write(priv->regmap, 0x03, 0x04);
365 
366 	/* Turn everything off to set all the registers to their defaults. */
367 	regmap_write(priv->regmap, 0x52, 0x00);
368 	/* Bring I/O block up. */
369 	regmap_write(priv->regmap, 0x52, RESETIB);
370 
371 	/*
372 	 * Page 0
373 	 */
374 	regmap_write(priv->regmap, 0x03, 0x00);
375 
376 	/* Bring up parts we need from the power down. */
377 	regmap_update_bits(priv->regmap, 0x07, DRI_PD | IO_PD, 0);
378 	regmap_update_bits(priv->regmap, 0x08, DRI_PDDRI | PDDAC | PANEN, 0);
379 	regmap_update_bits(priv->regmap, 0x09, DPD | GCKOFF |
380 					       HDMI_PD | VGA_PD, 0);
381 	regmap_update_bits(priv->regmap, 0x0a, HD_DVIB, 0);
382 
383 	/* Horizontal input timing. */
384 	regmap_write(priv->regmap, 0x0b, (mode->htotal >> 8) << 3 |
385 					 (mode->hdisplay >> 8));
386 	regmap_write(priv->regmap, 0x0c, mode->hdisplay);
387 	regmap_write(priv->regmap, 0x0d, mode->htotal);
388 	regmap_write(priv->regmap, 0x0e, (hsynclen >> 8) << 3 |
389 					 (hbporch >> 8));
390 	regmap_write(priv->regmap, 0x0f, hbporch);
391 	regmap_write(priv->regmap, 0x10, hsynclen);
392 
393 	/* Vertical input timing. */
394 	regmap_write(priv->regmap, 0x11, (mode->vtotal >> 8) << 3 |
395 					 (mode->vdisplay >> 8));
396 	regmap_write(priv->regmap, 0x12, mode->vdisplay);
397 	regmap_write(priv->regmap, 0x13, mode->vtotal);
398 	regmap_write(priv->regmap, 0x14, ((vsynclen >> 8) << 3) |
399 					 (vbporch >> 8));
400 	regmap_write(priv->regmap, 0x15, vbporch);
401 	regmap_write(priv->regmap, 0x16, vsynclen);
402 
403 	/* Input color swap. */
404 	regmap_update_bits(priv->regmap, 0x18, SWAP, BYTE_SWAP_BGR);
405 
406 	/* Input clock and sync polarity. */
407 	regmap_update_bits(priv->regmap, 0x19, 0x1, mode->clock >> 16);
408 	regmap_update_bits(priv->regmap, 0x19, HPO_I | VPO_I | GCLKFREQ,
409 			   (mode->flags & DRM_MODE_FLAG_PHSYNC) ? HPO_I : 0 |
410 			   (mode->flags & DRM_MODE_FLAG_PVSYNC) ? VPO_I : 0 |
411 			   mode->clock >> 16);
412 	regmap_write(priv->regmap, 0x1a, mode->clock >> 8);
413 	regmap_write(priv->regmap, 0x1b, mode->clock);
414 
415 	/* Horizontal output timing. */
416 	regmap_write(priv->regmap, 0x1f, (mode->htotal >> 8) << 3 |
417 					 (mode->hdisplay >> 8));
418 	regmap_write(priv->regmap, 0x20, mode->hdisplay);
419 	regmap_write(priv->regmap, 0x21, mode->htotal);
420 
421 	/* Vertical output timing. */
422 	regmap_write(priv->regmap, 0x25, (mode->vtotal >> 8) << 3 |
423 					 (mode->vdisplay >> 8));
424 	regmap_write(priv->regmap, 0x26, mode->vdisplay);
425 	regmap_write(priv->regmap, 0x27, mode->vtotal);
426 
427 	/* VGA channel bypass */
428 	regmap_update_bits(priv->regmap, 0x2b, VFMT, 9);
429 
430 	/* Output sync polarity. */
431 	regmap_update_bits(priv->regmap, 0x2e, HPO_O | VPO_O,
432 			   (mode->flags & DRM_MODE_FLAG_PHSYNC) ? HPO_O : 0 |
433 			   (mode->flags & DRM_MODE_FLAG_PVSYNC) ? VPO_O : 0);
434 
435 	/* HDMI horizontal output timing. */
436 	regmap_update_bits(priv->regmap, 0x54, HWO_HDMI_HI | HOO_HDMI_HI,
437 					       (hsynclen >> 8) << 3 |
438 					       (hbporch >> 8));
439 	regmap_write(priv->regmap, 0x55, hbporch);
440 	regmap_write(priv->regmap, 0x56, hsynclen);
441 
442 	/* HDMI vertical output timing. */
443 	regmap_update_bits(priv->regmap, 0x57, VWO_HDMI_HI | VOO_HDMI_HI,
444 					       (vsynclen >> 8) << 3 |
445 					       (vbporch >> 8));
446 	regmap_write(priv->regmap, 0x58, vbporch);
447 	regmap_write(priv->regmap, 0x59, vsynclen);
448 
449 	/* Pick HDMI, not LVDS. */
450 	regmap_update_bits(priv->regmap, 0x7e, HDMI_LVDS_SEL, HDMI_LVDS_SEL);
451 
452 	/*
453 	 * Page 1
454 	 */
455 	regmap_write(priv->regmap, 0x03, 0x01);
456 
457 	/* No idea what these do, but VGA is wobbly and blinky without them. */
458 	regmap_update_bits(priv->regmap, 0x07, CKINV, CKINV);
459 	regmap_update_bits(priv->regmap, 0x08, DISPON, DISPON);
460 
461 	/* DRI PLL */
462 	regmap_update_bits(priv->regmap, 0x0c, DRI_PLL_DIVSEL, DRI_PLL_DIVSEL);
463 	if (mode->clock <= 40000) {
464 		regmap_update_bits(priv->regmap, 0x0c, DRI_PLL_N1_1 |
465 						       DRI_PLL_N1_0 |
466 						       DRI_PLL_N3_1 |
467 						       DRI_PLL_N3_0,
468 						       0);
469 	} else if (mode->clock < 80000) {
470 		regmap_update_bits(priv->regmap, 0x0c, DRI_PLL_N1_1 |
471 						       DRI_PLL_N1_0 |
472 						       DRI_PLL_N3_1 |
473 						       DRI_PLL_N3_0,
474 						       DRI_PLL_N3_0 |
475 						       DRI_PLL_N1_0);
476 	} else {
477 		regmap_update_bits(priv->regmap, 0x0c, DRI_PLL_N1_1 |
478 						       DRI_PLL_N1_0 |
479 						       DRI_PLL_N3_1 |
480 						       DRI_PLL_N3_0,
481 						       DRI_PLL_N3_1 |
482 						       DRI_PLL_N1_1);
483 	}
484 
485 	/* This seems to be color calibration for VGA. */
486 	regmap_write(priv->regmap, 0x64, 0x29); /* LSB Blue */
487 	regmap_write(priv->regmap, 0x65, 0x29); /* LSB Green */
488 	regmap_write(priv->regmap, 0x66, 0x29); /* LSB Red */
489 	regmap_write(priv->regmap, 0x67, 0x00); /* MSB Blue */
490 	regmap_write(priv->regmap, 0x68, 0x00); /* MSB Green */
491 	regmap_write(priv->regmap, 0x69, 0x00); /* MSB Red */
492 
493 	regmap_update_bits(priv->regmap, 0x6b, DRI_PD_SER, 0x00);
494 	regmap_update_bits(priv->regmap, 0x6c, DRI_PLL_PD, 0x00);
495 
496 	/*
497 	 * Page 3
498 	 */
499 	regmap_write(priv->regmap, 0x03, 0x03);
500 
501 	/* More bypasses and apparently another HDMI/LVDS selector. */
502 	regmap_update_bits(priv->regmap, 0x28, VGACLK_BP | HM_LV_SEL,
503 					       VGACLK_BP | HM_LV_SEL);
504 	regmap_update_bits(priv->regmap, 0x2a, HDMICLK_BP | HDMI_BP,
505 					       HDMICLK_BP | HDMI_BP);
506 
507 	/*
508 	 * Page 4
509 	 */
510 	regmap_write(priv->regmap, 0x03, 0x04);
511 
512 	/* Output clock. */
513 	regmap_write(priv->regmap, 0x10, mode->clock >> 16);
514 	regmap_write(priv->regmap, 0x11, mode->clock >> 8);
515 	regmap_write(priv->regmap, 0x12, mode->clock);
516 }
517 
518 static const struct drm_bridge_funcs ch7033_bridge_funcs = {
519 	.atomic_create_state = drm_atomic_helper_bridge_create_state,
520 	.atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
521 	.atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
522 	.attach = ch7033_bridge_attach,
523 	.detach = ch7033_bridge_detach,
524 	.mode_valid = ch7033_bridge_mode_valid,
525 	.atomic_disable = ch7033_bridge_disable,
526 	.atomic_enable = ch7033_bridge_enable,
527 	.mode_set = ch7033_bridge_mode_set,
528 };
529 
530 static const struct regmap_config ch7033_regmap_config = {
531 	.reg_bits = 8,
532 	.val_bits = 8,
533 	.max_register = 0x7f,
534 };
535 
536 static int ch7033_probe(struct i2c_client *client)
537 {
538 	struct device *dev = &client->dev;
539 	struct ch7033_priv *priv;
540 	unsigned int val;
541 	int ret;
542 
543 	priv = devm_drm_bridge_alloc(dev, struct ch7033_priv, bridge,
544 				     &ch7033_bridge_funcs);
545 	if (IS_ERR(priv))
546 		return PTR_ERR(priv);
547 
548 	dev_set_drvdata(dev, priv);
549 
550 	priv->bridge.next_bridge = of_drm_get_bridge_by_endpoint(dev->of_node, 1, -1);
551 	if (IS_ERR(priv->bridge.next_bridge))
552 		return PTR_ERR(priv->bridge.next_bridge);
553 
554 	priv->regmap = devm_regmap_init_i2c(client, &ch7033_regmap_config);
555 	if (IS_ERR(priv->regmap)) {
556 		dev_err(&client->dev, "regmap init failed\n");
557 		return PTR_ERR(priv->regmap);
558 	}
559 
560 	ret = regmap_read(priv->regmap, 0x00, &val);
561 	if (ret < 0) {
562 		dev_err(&client->dev, "error reading the model id: %d\n", ret);
563 		return ret;
564 	}
565 	if ((val & 0xf7) != 0x56) {
566 		dev_err(&client->dev, "the device is not a ch7033\n");
567 		return -ENODEV;
568 	}
569 
570 	regmap_write(priv->regmap, 0x03, 0x04);
571 	ret = regmap_read(priv->regmap, 0x51, &val);
572 	if (ret < 0) {
573 		dev_err(&client->dev, "error reading the model id: %d\n", ret);
574 		return ret;
575 	}
576 	if ((val & 0x0f) != 3) {
577 		dev_err(&client->dev, "unknown revision %u\n", val);
578 		return -ENODEV;
579 	}
580 
581 	INIT_LIST_HEAD(&priv->bridge.list);
582 	priv->bridge.of_node = dev->of_node;
583 	drm_bridge_add(&priv->bridge);
584 
585 	dev_info(dev, "Chrontel CH7033 Video Encoder\n");
586 	return 0;
587 }
588 
589 static void ch7033_remove(struct i2c_client *client)
590 {
591 	struct device *dev = &client->dev;
592 	struct ch7033_priv *priv = dev_get_drvdata(dev);
593 
594 	drm_bridge_remove(&priv->bridge);
595 }
596 
597 static const struct of_device_id ch7033_dt_ids[] = {
598 	{ .compatible = "chrontel,ch7033", },
599 	{ }
600 };
601 MODULE_DEVICE_TABLE(of, ch7033_dt_ids);
602 
603 static const struct i2c_device_id ch7033_ids[] = {
604 	{ .name = "ch7033" },
605 	{ }
606 };
607 MODULE_DEVICE_TABLE(i2c, ch7033_ids);
608 
609 static struct i2c_driver ch7033_driver = {
610 	.probe = ch7033_probe,
611 	.remove = ch7033_remove,
612 	.driver = {
613 		.name = "ch7033",
614 		.of_match_table = ch7033_dt_ids,
615 	},
616 	.id_table = ch7033_ids,
617 };
618 
619 module_i2c_driver(ch7033_driver);
620 
621 MODULE_AUTHOR("Lubomir Rintel <lkundrak@v3.sk>");
622 MODULE_DESCRIPTION("Chrontel CH7033 Video Encoder Driver");
623 MODULE_LICENSE("GPL v2");
624