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