1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2018, The Linux Foundation. All rights reserved.
4  */
5 
6 #include <linux/device.h>
7 #include <linux/delay.h>
8 #include <linux/gpio/consumer.h>
9 #include <linux/i2c.h>
10 #include <linux/media-bus-format.h>
11 #include <linux/regmap.h>
12 
13 #include <drm/drm_probe_helper.h>
14 #include <drm/drm_atomic_helper.h>
15 #include <drm/drm_edid.h>
16 #include <drm/drm_mipi_dsi.h>
17 #include <drm/drm_of.h>
18 
19 #include <video/videomode.h>
20 
21 #define I2C_MAIN 0
22 #define I2C_ADDR_MAIN 0x48
23 
24 #define I2C_CEC_DSI 1
25 #define I2C_ADDR_CEC_DSI 0x49
26 
27 #define I2C_MAX_IDX 2
28 
29 struct lt8912 {
30 	struct device *dev;
31 	struct drm_bridge bridge;
32 	struct drm_connector connector;
33 
34 	struct i2c_client *i2c_client[I2C_MAX_IDX];
35 	struct regmap *regmap[I2C_MAX_IDX];
36 
37 	struct device_node *host_node;
38 	struct drm_bridge *hdmi_port;
39 
40 	struct mipi_dsi_device *dsi;
41 
42 	struct gpio_desc *gp_reset;
43 
44 	struct videomode mode;
45 
46 	u8 data_lanes;
47 	bool is_power_on;
48 	bool is_attached;
49 };
50 
51 static int lt8912_write_init_config(struct lt8912 *lt)
52 {
53 	const struct reg_sequence seq[] = {
54 		/* Digital clock en*/
55 		{0x08, 0xff},
56 		{0x09, 0xff},
57 		{0x0a, 0xff},
58 		{0x0b, 0x7c},
59 		{0x0c, 0xff},
60 		{0x42, 0x04},
61 
62 		/*Tx Analog*/
63 		{0x31, 0xb1},
64 		{0x32, 0xb1},
65 		{0x33, 0x0e},
66 		{0x37, 0x00},
67 		{0x38, 0x22},
68 		{0x60, 0x82},
69 
70 		/*Cbus Analog*/
71 		{0x39, 0x45},
72 		{0x3a, 0x00},
73 		{0x3b, 0x00},
74 
75 		/*HDMI Pll Analog*/
76 		{0x44, 0x31},
77 		{0x55, 0x44},
78 		{0x57, 0x01},
79 		{0x5a, 0x02},
80 
81 		/*MIPI Analog*/
82 		{0x3e, 0xd6},
83 		{0x3f, 0xd4},
84 		{0x41, 0x3c},
85 		{0xB2, 0x00},
86 	};
87 
88 	return regmap_multi_reg_write(lt->regmap[I2C_MAIN], seq, ARRAY_SIZE(seq));
89 }
90 
91 static int lt8912_write_mipi_basic_config(struct lt8912 *lt)
92 {
93 	const struct reg_sequence seq[] = {
94 		{0x12, 0x04},
95 		{0x14, 0x00},
96 		{0x15, 0x00},
97 		{0x1a, 0x03},
98 		{0x1b, 0x03},
99 	};
100 
101 	return regmap_multi_reg_write(lt->regmap[I2C_CEC_DSI], seq, ARRAY_SIZE(seq));
102 };
103 
104 static int lt8912_write_dds_config(struct lt8912 *lt)
105 {
106 	const struct reg_sequence seq[] = {
107 		{0x4e, 0xff},
108 		{0x4f, 0x56},
109 		{0x50, 0x69},
110 		{0x51, 0x80},
111 		{0x1f, 0x5e},
112 		{0x20, 0x01},
113 		{0x21, 0x2c},
114 		{0x22, 0x01},
115 		{0x23, 0xfa},
116 		{0x24, 0x00},
117 		{0x25, 0xc8},
118 		{0x26, 0x00},
119 		{0x27, 0x5e},
120 		{0x28, 0x01},
121 		{0x29, 0x2c},
122 		{0x2a, 0x01},
123 		{0x2b, 0xfa},
124 		{0x2c, 0x00},
125 		{0x2d, 0xc8},
126 		{0x2e, 0x00},
127 		{0x42, 0x64},
128 		{0x43, 0x00},
129 		{0x44, 0x04},
130 		{0x45, 0x00},
131 		{0x46, 0x59},
132 		{0x47, 0x00},
133 		{0x48, 0xf2},
134 		{0x49, 0x06},
135 		{0x4a, 0x00},
136 		{0x4b, 0x72},
137 		{0x4c, 0x45},
138 		{0x4d, 0x00},
139 		{0x52, 0x08},
140 		{0x53, 0x00},
141 		{0x54, 0xb2},
142 		{0x55, 0x00},
143 		{0x56, 0xe4},
144 		{0x57, 0x0d},
145 		{0x58, 0x00},
146 		{0x59, 0xe4},
147 		{0x5a, 0x8a},
148 		{0x5b, 0x00},
149 		{0x5c, 0x34},
150 		{0x1e, 0x4f},
151 		{0x51, 0x00},
152 	};
153 
154 	return regmap_multi_reg_write(lt->regmap[I2C_CEC_DSI], seq, ARRAY_SIZE(seq));
155 }
156 
157 static int lt8912_write_rxlogicres_config(struct lt8912 *lt)
158 {
159 	int ret;
160 
161 	ret = regmap_write(lt->regmap[I2C_MAIN], 0x03, 0x7f);
162 	usleep_range(10000, 20000);
163 	ret |= regmap_write(lt->regmap[I2C_MAIN], 0x03, 0xff);
164 
165 	return ret;
166 };
167 
168 static int lt8912_write_lvds_config(struct lt8912 *lt)
169 {
170 	const struct reg_sequence seq[] = {
171 		{0x44, 0x30},
172 		{0x51, 0x05},
173 		{0x50, 0x24},
174 		{0x51, 0x2d},
175 		{0x52, 0x04},
176 		{0x69, 0x0e},
177 		{0x69, 0x8e},
178 		{0x6a, 0x00},
179 		{0x6c, 0xb8},
180 		{0x6b, 0x51},
181 		{0x04, 0xfb},
182 		{0x04, 0xff},
183 		{0x7f, 0x00},
184 		{0xa8, 0x13},
185 		{0x02, 0xf7},
186 		{0x02, 0xff},
187 		{0x03, 0xcf},
188 		{0x03, 0xff},
189 	};
190 
191 	return regmap_multi_reg_write(lt->regmap[I2C_CEC_DSI], seq, ARRAY_SIZE(seq));
192 };
193 
194 static inline struct lt8912 *bridge_to_lt8912(struct drm_bridge *b)
195 {
196 	return container_of(b, struct lt8912, bridge);
197 }
198 
199 static inline struct lt8912 *connector_to_lt8912(struct drm_connector *c)
200 {
201 	return container_of(c, struct lt8912, connector);
202 }
203 
204 static const struct regmap_config lt8912_regmap_config = {
205 	.reg_bits = 8,
206 	.val_bits = 8,
207 	.max_register = 0xff,
208 };
209 
210 static int lt8912_init_i2c(struct lt8912 *lt, struct i2c_client *client)
211 {
212 	unsigned int i;
213 	/*
214 	 * At this time we only initialize 2 chips, but the lt8912 provides
215 	 * a third interface for the audio over HDMI configuration.
216 	 */
217 	struct i2c_board_info info[] = {
218 		{ I2C_BOARD_INFO("lt8912p0", I2C_ADDR_MAIN), },
219 		{ I2C_BOARD_INFO("lt8912p1", I2C_ADDR_CEC_DSI), },
220 	};
221 
222 	if (!lt)
223 		return -ENODEV;
224 
225 	for (i = 0; i < ARRAY_SIZE(info); i++) {
226 		if (i > 0) {
227 			lt->i2c_client[i] = i2c_new_dummy_device(client->adapter,
228 								 info[i].addr);
229 			if (IS_ERR(lt->i2c_client[i]))
230 				return PTR_ERR(lt->i2c_client[i]);
231 		}
232 
233 		lt->regmap[i] = devm_regmap_init_i2c(lt->i2c_client[i],
234 						     &lt8912_regmap_config);
235 		if (IS_ERR(lt->regmap[i]))
236 			return PTR_ERR(lt->regmap[i]);
237 	}
238 	return 0;
239 }
240 
241 static int lt8912_free_i2c(struct lt8912 *lt)
242 {
243 	unsigned int i;
244 
245 	for (i = 1; i < I2C_MAX_IDX; i++)
246 		i2c_unregister_device(lt->i2c_client[i]);
247 
248 	return 0;
249 }
250 
251 static int lt8912_hard_power_on(struct lt8912 *lt)
252 {
253 	gpiod_set_value_cansleep(lt->gp_reset, 0);
254 	msleep(20);
255 
256 	return 0;
257 }
258 
259 static void lt8912_hard_power_off(struct lt8912 *lt)
260 {
261 	gpiod_set_value_cansleep(lt->gp_reset, 1);
262 	msleep(20);
263 	lt->is_power_on = false;
264 }
265 
266 static int lt8912_video_setup(struct lt8912 *lt)
267 {
268 	u32 hactive, h_total, hpw, hfp, hbp;
269 	u32 vactive, v_total, vpw, vfp, vbp;
270 	u8 settle = 0x08;
271 	int ret;
272 
273 	if (!lt)
274 		return -EINVAL;
275 
276 	hactive = lt->mode.hactive;
277 	hfp = lt->mode.hfront_porch;
278 	hpw = lt->mode.hsync_len;
279 	hbp = lt->mode.hback_porch;
280 	h_total = hactive + hfp + hpw + hbp;
281 
282 	vactive = lt->mode.vactive;
283 	vfp = lt->mode.vfront_porch;
284 	vpw = lt->mode.vsync_len;
285 	vbp = lt->mode.vback_porch;
286 	v_total = vactive + vfp + vpw + vbp;
287 
288 	if (vactive <= 600)
289 		settle = 0x04;
290 	else if (vactive == 1080)
291 		settle = 0x0a;
292 
293 	ret = regmap_write(lt->regmap[I2C_CEC_DSI], 0x10, 0x01);
294 	ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x11, settle);
295 	ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x18, hpw);
296 	ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x19, vpw);
297 	ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x1c, hactive & 0xff);
298 	ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x1d, hactive >> 8);
299 
300 	ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x2f, 0x0c);
301 
302 	ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x34, h_total & 0xff);
303 	ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x35, h_total >> 8);
304 
305 	ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x36, v_total & 0xff);
306 	ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x37, v_total >> 8);
307 
308 	ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x38, vbp & 0xff);
309 	ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x39, vbp >> 8);
310 
311 	ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x3a, vfp & 0xff);
312 	ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x3b, vfp >> 8);
313 
314 	ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x3c, hbp & 0xff);
315 	ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x3d, hbp >> 8);
316 
317 	ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x3e, hfp & 0xff);
318 	ret |= regmap_write(lt->regmap[I2C_CEC_DSI], 0x3f, hfp >> 8);
319 
320 	return ret;
321 }
322 
323 static int lt8912_soft_power_on(struct lt8912 *lt)
324 {
325 	if (!lt->is_power_on) {
326 		u32 lanes = lt->data_lanes;
327 
328 		lt8912_write_init_config(lt);
329 		regmap_write(lt->regmap[I2C_CEC_DSI], 0x13, lanes & 3);
330 
331 		lt8912_write_mipi_basic_config(lt);
332 
333 		lt->is_power_on = true;
334 	}
335 
336 	return 0;
337 }
338 
339 static int lt8912_video_on(struct lt8912 *lt)
340 {
341 	int ret;
342 
343 	ret = lt8912_video_setup(lt);
344 	if (ret < 0)
345 		goto end;
346 
347 	ret = lt8912_write_dds_config(lt);
348 	if (ret < 0)
349 		goto end;
350 
351 	ret = lt8912_write_rxlogicres_config(lt);
352 	if (ret < 0)
353 		goto end;
354 
355 	ret = lt8912_write_lvds_config(lt);
356 	if (ret < 0)
357 		goto end;
358 
359 end:
360 	return ret;
361 }
362 
363 static enum drm_connector_status lt8912_check_cable_status(struct lt8912 *lt)
364 {
365 	int ret;
366 	unsigned int reg_val;
367 
368 	ret = regmap_read(lt->regmap[I2C_MAIN], 0xC1, &reg_val);
369 	if (ret)
370 		return connector_status_unknown;
371 
372 	if (reg_val & BIT(7))
373 		return connector_status_connected;
374 
375 	return connector_status_disconnected;
376 }
377 
378 static enum drm_connector_status
379 lt8912_connector_detect(struct drm_connector *connector, bool force)
380 {
381 	struct lt8912 *lt = connector_to_lt8912(connector);
382 
383 	if (lt->hdmi_port->ops & DRM_BRIDGE_OP_DETECT)
384 		return drm_bridge_detect(lt->hdmi_port);
385 
386 	return lt8912_check_cable_status(lt);
387 }
388 
389 static const struct drm_connector_funcs lt8912_connector_funcs = {
390 	.detect = lt8912_connector_detect,
391 	.fill_modes = drm_helper_probe_single_connector_modes,
392 	.destroy = drm_connector_cleanup,
393 	.reset = drm_atomic_helper_connector_reset,
394 	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
395 	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
396 };
397 
398 static enum drm_mode_status
399 lt8912_connector_mode_valid(struct drm_connector *connector,
400 			    struct drm_display_mode *mode)
401 {
402 	if (mode->clock > 150000)
403 		return MODE_CLOCK_HIGH;
404 
405 	if (mode->hdisplay > 1920)
406 		return MODE_BAD_HVALUE;
407 
408 	if (mode->vdisplay > 1080)
409 		return MODE_BAD_VVALUE;
410 
411 	return MODE_OK;
412 }
413 
414 static int lt8912_connector_get_modes(struct drm_connector *connector)
415 {
416 	struct edid *edid;
417 	int ret = -1;
418 	int num = 0;
419 	struct lt8912 *lt = connector_to_lt8912(connector);
420 	u32 bus_format = MEDIA_BUS_FMT_RGB888_1X24;
421 
422 	edid = drm_bridge_get_edid(lt->hdmi_port, connector);
423 	if (edid) {
424 		drm_connector_update_edid_property(connector, edid);
425 		num = drm_add_edid_modes(connector, edid);
426 	} else {
427 		return ret;
428 	}
429 
430 	ret = drm_display_info_set_bus_formats(&connector->display_info,
431 					       &bus_format, 1);
432 	if (ret)
433 		num = ret;
434 
435 	kfree(edid);
436 	return num;
437 }
438 
439 static const struct drm_connector_helper_funcs lt8912_connector_helper_funcs = {
440 	.get_modes = lt8912_connector_get_modes,
441 	.mode_valid = lt8912_connector_mode_valid,
442 };
443 
444 static void lt8912_bridge_mode_set(struct drm_bridge *bridge,
445 				   const struct drm_display_mode *mode,
446 				   const struct drm_display_mode *adj)
447 {
448 	struct lt8912 *lt = bridge_to_lt8912(bridge);
449 
450 	drm_display_mode_to_videomode(adj, &lt->mode);
451 }
452 
453 static void lt8912_bridge_enable(struct drm_bridge *bridge)
454 {
455 	struct lt8912 *lt = bridge_to_lt8912(bridge);
456 
457 	lt8912_video_on(lt);
458 }
459 
460 static int lt8912_attach_dsi(struct lt8912 *lt)
461 {
462 	struct device *dev = lt->dev;
463 	struct mipi_dsi_host *host;
464 	struct mipi_dsi_device *dsi;
465 	int ret = -1;
466 	const struct mipi_dsi_device_info info = { .type = "lt8912",
467 						   .channel = 0,
468 						   .node = NULL,
469 						 };
470 
471 	host = of_find_mipi_dsi_host_by_node(lt->host_node);
472 	if (!host) {
473 		dev_err(dev, "failed to find dsi host\n");
474 		return -EPROBE_DEFER;
475 	}
476 
477 	dsi = devm_mipi_dsi_device_register_full(dev, host, &info);
478 	if (IS_ERR(dsi)) {
479 		ret = PTR_ERR(dsi);
480 		dev_err(dev, "failed to create dsi device (%d)\n", ret);
481 		return ret;
482 	}
483 
484 	lt->dsi = dsi;
485 
486 	dsi->lanes = lt->data_lanes;
487 	dsi->format = MIPI_DSI_FMT_RGB888;
488 
489 	dsi->mode_flags = MIPI_DSI_MODE_VIDEO |
490 			  MIPI_DSI_MODE_VIDEO_BURST |
491 			  MIPI_DSI_MODE_LPM |
492 			  MIPI_DSI_MODE_NO_EOT_PACKET;
493 
494 	ret = devm_mipi_dsi_attach(dev, dsi);
495 	if (ret < 0) {
496 		dev_err(dev, "failed to attach dsi to host\n");
497 		return ret;
498 	}
499 
500 	return 0;
501 }
502 
503 static int lt8912_bridge_connector_init(struct drm_bridge *bridge)
504 {
505 	int ret;
506 	struct lt8912 *lt = bridge_to_lt8912(bridge);
507 	struct drm_connector *connector = &lt->connector;
508 
509 	connector->polled = DRM_CONNECTOR_POLL_CONNECT |
510 			    DRM_CONNECTOR_POLL_DISCONNECT;
511 
512 	ret = drm_connector_init(bridge->dev, connector,
513 				 &lt8912_connector_funcs,
514 				 lt->hdmi_port->type);
515 	if (ret)
516 		goto exit;
517 
518 	drm_connector_helper_add(connector, &lt8912_connector_helper_funcs);
519 
520 	connector->dpms = DRM_MODE_DPMS_OFF;
521 	drm_connector_attach_encoder(connector, bridge->encoder);
522 
523 exit:
524 	return ret;
525 }
526 
527 static int lt8912_bridge_attach(struct drm_bridge *bridge,
528 				enum drm_bridge_attach_flags flags)
529 {
530 	struct lt8912 *lt = bridge_to_lt8912(bridge);
531 	int ret;
532 
533 	if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)) {
534 		ret = lt8912_bridge_connector_init(bridge);
535 		if (ret) {
536 			dev_err(lt->dev, "Failed to init bridge ! (%d)\n", ret);
537 			return ret;
538 		}
539 	}
540 
541 	ret = lt8912_hard_power_on(lt);
542 	if (ret)
543 		return ret;
544 
545 	ret = lt8912_soft_power_on(lt);
546 	if (ret)
547 		goto error;
548 
549 	lt->is_attached = true;
550 
551 	return 0;
552 
553 error:
554 	lt8912_hard_power_off(lt);
555 	return ret;
556 }
557 
558 static void lt8912_bridge_detach(struct drm_bridge *bridge)
559 {
560 	struct lt8912 *lt = bridge_to_lt8912(bridge);
561 
562 	if (lt->is_attached) {
563 		lt8912_hard_power_off(lt);
564 		drm_connector_unregister(&lt->connector);
565 		drm_connector_cleanup(&lt->connector);
566 	}
567 }
568 
569 static enum drm_connector_status
570 lt8912_bridge_detect(struct drm_bridge *bridge)
571 {
572 	struct lt8912 *lt = bridge_to_lt8912(bridge);
573 
574 	if (lt->hdmi_port->ops & DRM_BRIDGE_OP_DETECT)
575 		return drm_bridge_detect(lt->hdmi_port);
576 
577 	return lt8912_check_cable_status(lt);
578 }
579 
580 static struct edid *lt8912_bridge_get_edid(struct drm_bridge *bridge,
581 					   struct drm_connector *connector)
582 {
583 	struct lt8912 *lt = bridge_to_lt8912(bridge);
584 
585 	/*
586 	 * edid must be read through the ddc bus but it must be
587 	 * given to the hdmi connector node.
588 	 */
589 	if (lt->hdmi_port->ops & DRM_BRIDGE_OP_EDID)
590 		return drm_bridge_get_edid(lt->hdmi_port, connector);
591 
592 	dev_warn(lt->dev, "The connected bridge does not supports DRM_BRIDGE_OP_EDID\n");
593 	return NULL;
594 }
595 
596 static const struct drm_bridge_funcs lt8912_bridge_funcs = {
597 	.attach = lt8912_bridge_attach,
598 	.detach = lt8912_bridge_detach,
599 	.mode_set = lt8912_bridge_mode_set,
600 	.enable = lt8912_bridge_enable,
601 	.detect = lt8912_bridge_detect,
602 	.get_edid = lt8912_bridge_get_edid,
603 };
604 
605 static int lt8912_parse_dt(struct lt8912 *lt)
606 {
607 	struct gpio_desc *gp_reset;
608 	struct device *dev = lt->dev;
609 	int ret;
610 	int data_lanes;
611 	struct device_node *port_node;
612 
613 	gp_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
614 	if (IS_ERR(gp_reset)) {
615 		ret = PTR_ERR(gp_reset);
616 		if (ret != -EPROBE_DEFER)
617 			dev_err(dev, "Failed to get reset gpio: %d\n", ret);
618 		return ret;
619 	}
620 	lt->gp_reset = gp_reset;
621 
622 	data_lanes = drm_of_get_data_lanes_count_ep(dev->of_node, 0, -1, 1, 4);
623 	if (data_lanes < 0) {
624 		dev_err(lt->dev, "%s: Bad data-lanes property\n", __func__);
625 		return data_lanes;
626 	}
627 
628 	lt->data_lanes = data_lanes;
629 
630 	lt->host_node = of_graph_get_remote_node(dev->of_node, 0, -1);
631 	if (!lt->host_node) {
632 		dev_err(lt->dev, "%s: Failed to get remote port\n", __func__);
633 		return -ENODEV;
634 	}
635 
636 	port_node = of_graph_get_remote_node(dev->of_node, 1, -1);
637 	if (!port_node) {
638 		dev_err(lt->dev, "%s: Failed to get connector port\n", __func__);
639 		ret = -ENODEV;
640 		goto err_free_host_node;
641 	}
642 
643 	lt->hdmi_port = of_drm_find_bridge(port_node);
644 	if (!lt->hdmi_port) {
645 		dev_err(lt->dev, "%s: Failed to get hdmi port\n", __func__);
646 		ret = -ENODEV;
647 		goto err_free_host_node;
648 	}
649 
650 	if (!of_device_is_compatible(port_node, "hdmi-connector")) {
651 		dev_err(lt->dev, "%s: Failed to get hdmi port\n", __func__);
652 		ret = -EINVAL;
653 		goto err_free_host_node;
654 	}
655 
656 	of_node_put(port_node);
657 	return 0;
658 
659 err_free_host_node:
660 	of_node_put(port_node);
661 	of_node_put(lt->host_node);
662 	return ret;
663 }
664 
665 static int lt8912_put_dt(struct lt8912 *lt)
666 {
667 	of_node_put(lt->host_node);
668 	return 0;
669 }
670 
671 static int lt8912_probe(struct i2c_client *client,
672 			const struct i2c_device_id *id)
673 {
674 	static struct lt8912 *lt;
675 	int ret = 0;
676 	struct device *dev = &client->dev;
677 
678 	lt = devm_kzalloc(dev, sizeof(struct lt8912), GFP_KERNEL);
679 	if (!lt)
680 		return -ENOMEM;
681 
682 	lt->dev = dev;
683 	lt->i2c_client[0] = client;
684 
685 	ret = lt8912_parse_dt(lt);
686 	if (ret)
687 		goto err_dt_parse;
688 
689 	ret = lt8912_init_i2c(lt, client);
690 	if (ret)
691 		goto err_i2c;
692 
693 	i2c_set_clientdata(client, lt);
694 
695 	lt->bridge.funcs = &lt8912_bridge_funcs;
696 	lt->bridge.of_node = dev->of_node;
697 	lt->bridge.ops = (DRM_BRIDGE_OP_EDID |
698 			  DRM_BRIDGE_OP_DETECT);
699 
700 	drm_bridge_add(&lt->bridge);
701 
702 	ret = lt8912_attach_dsi(lt);
703 	if (ret)
704 		goto err_attach;
705 
706 	return 0;
707 
708 err_attach:
709 	drm_bridge_remove(&lt->bridge);
710 	lt8912_free_i2c(lt);
711 err_i2c:
712 	lt8912_put_dt(lt);
713 err_dt_parse:
714 	return ret;
715 }
716 
717 static int lt8912_remove(struct i2c_client *client)
718 {
719 	struct lt8912 *lt = i2c_get_clientdata(client);
720 
721 	lt8912_bridge_detach(&lt->bridge);
722 	drm_bridge_remove(&lt->bridge);
723 	lt8912_free_i2c(lt);
724 	lt8912_put_dt(lt);
725 	return 0;
726 }
727 
728 static const struct of_device_id lt8912_dt_match[] = {
729 	{.compatible = "lontium,lt8912b"},
730 	{}
731 };
732 MODULE_DEVICE_TABLE(of, lt8912_dt_match);
733 
734 static const struct i2c_device_id lt8912_id[] = {
735 	{"lt8912", 0},
736 	{},
737 };
738 MODULE_DEVICE_TABLE(i2c, lt8912_id);
739 
740 static struct i2c_driver lt8912_i2c_driver = {
741 	.driver = {
742 		.name = "lt8912",
743 		.of_match_table = lt8912_dt_match,
744 	},
745 	.probe = lt8912_probe,
746 	.remove = lt8912_remove,
747 	.id_table = lt8912_id,
748 };
749 module_i2c_driver(lt8912_i2c_driver);
750 
751 MODULE_AUTHOR("Adrien Grassein <adrien.grassein@gmail.com>");
752 MODULE_DESCRIPTION("lt8912 drm driver");
753 MODULE_LICENSE("GPL v2");
754