Merge tag 'drm-misc-next-2022-06-23' of git://anongit.freedesktop.org/drm/drm-misc...
[linux-2.6-microblaze.git] / drivers / gpu / drm / bridge / lontium-lt8912b.c
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/regmap.h>
11
12 #include <drm/drm_probe_helper.h>
13 #include <drm/drm_atomic_helper.h>
14 #include <drm/drm_edid.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 = devm_mipi_dsi_device_register_full(dev, 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                 return ret;
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_NO_EOT_PACKET;
492
493         ret = devm_mipi_dsi_attach(dev, dsi);
494         if (ret < 0) {
495                 dev_err(dev, "failed to attach dsi to host\n");
496                 return ret;
497         }
498
499         return 0;
500 }
501
502 static int lt8912_bridge_connector_init(struct drm_bridge *bridge)
503 {
504         int ret;
505         struct lt8912 *lt = bridge_to_lt8912(bridge);
506         struct drm_connector *connector = &lt->connector;
507
508         connector->polled = DRM_CONNECTOR_POLL_CONNECT |
509                             DRM_CONNECTOR_POLL_DISCONNECT;
510
511         ret = drm_connector_init(bridge->dev, connector,
512                                  &lt8912_connector_funcs,
513                                  lt->hdmi_port->type);
514         if (ret)
515                 goto exit;
516
517         drm_connector_helper_add(connector, &lt8912_connector_helper_funcs);
518
519         connector->dpms = DRM_MODE_DPMS_OFF;
520         drm_connector_attach_encoder(connector, bridge->encoder);
521
522 exit:
523         return ret;
524 }
525
526 static int lt8912_bridge_attach(struct drm_bridge *bridge,
527                                 enum drm_bridge_attach_flags flags)
528 {
529         struct lt8912 *lt = bridge_to_lt8912(bridge);
530         int ret;
531
532         if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)) {
533                 ret = lt8912_bridge_connector_init(bridge);
534                 if (ret) {
535                         dev_err(lt->dev, "Failed to init bridge ! (%d)\n", ret);
536                         return ret;
537                 }
538         }
539
540         ret = lt8912_hard_power_on(lt);
541         if (ret)
542                 return ret;
543
544         ret = lt8912_soft_power_on(lt);
545         if (ret)
546                 goto error;
547
548         lt->is_attached = true;
549
550         return 0;
551
552 error:
553         lt8912_hard_power_off(lt);
554         return ret;
555 }
556
557 static void lt8912_bridge_detach(struct drm_bridge *bridge)
558 {
559         struct lt8912 *lt = bridge_to_lt8912(bridge);
560
561         if (lt->is_attached) {
562                 lt8912_hard_power_off(lt);
563                 drm_connector_unregister(&lt->connector);
564                 drm_connector_cleanup(&lt->connector);
565         }
566 }
567
568 static enum drm_connector_status
569 lt8912_bridge_detect(struct drm_bridge *bridge)
570 {
571         struct lt8912 *lt = bridge_to_lt8912(bridge);
572
573         if (lt->hdmi_port->ops & DRM_BRIDGE_OP_DETECT)
574                 return drm_bridge_detect(lt->hdmi_port);
575
576         return lt8912_check_cable_status(lt);
577 }
578
579 static struct edid *lt8912_bridge_get_edid(struct drm_bridge *bridge,
580                                            struct drm_connector *connector)
581 {
582         struct lt8912 *lt = bridge_to_lt8912(bridge);
583
584         /*
585          * edid must be read through the ddc bus but it must be
586          * given to the hdmi connector node.
587          */
588         if (lt->hdmi_port->ops & DRM_BRIDGE_OP_EDID)
589                 return drm_bridge_get_edid(lt->hdmi_port, connector);
590
591         dev_warn(lt->dev, "The connected bridge does not supports DRM_BRIDGE_OP_EDID\n");
592         return NULL;
593 }
594
595 static const struct drm_bridge_funcs lt8912_bridge_funcs = {
596         .attach = lt8912_bridge_attach,
597         .detach = lt8912_bridge_detach,
598         .mode_set = lt8912_bridge_mode_set,
599         .enable = lt8912_bridge_enable,
600         .detect = lt8912_bridge_detect,
601         .get_edid = lt8912_bridge_get_edid,
602 };
603
604 static int lt8912_parse_dt(struct lt8912 *lt)
605 {
606         struct gpio_desc *gp_reset;
607         struct device *dev = lt->dev;
608         int ret;
609         int data_lanes;
610         struct device_node *port_node;
611
612         gp_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
613         if (IS_ERR(gp_reset)) {
614                 ret = PTR_ERR(gp_reset);
615                 if (ret != -EPROBE_DEFER)
616                         dev_err(dev, "Failed to get reset gpio: %d\n", ret);
617                 return ret;
618         }
619         lt->gp_reset = gp_reset;
620
621         data_lanes = drm_of_get_data_lanes_count_ep(dev->of_node, 0, -1, 1, 4);
622         if (data_lanes < 0) {
623                 dev_err(lt->dev, "%s: Bad data-lanes property\n", __func__);
624                 return data_lanes;
625         }
626
627         lt->data_lanes = data_lanes;
628
629         lt->host_node = of_graph_get_remote_node(dev->of_node, 0, -1);
630         if (!lt->host_node) {
631                 dev_err(lt->dev, "%s: Failed to get remote port\n", __func__);
632                 return -ENODEV;
633         }
634
635         port_node = of_graph_get_remote_node(dev->of_node, 1, -1);
636         if (!port_node) {
637                 dev_err(lt->dev, "%s: Failed to get connector port\n", __func__);
638                 ret = -ENODEV;
639                 goto err_free_host_node;
640         }
641
642         lt->hdmi_port = of_drm_find_bridge(port_node);
643         if (!lt->hdmi_port) {
644                 dev_err(lt->dev, "%s: Failed to get hdmi port\n", __func__);
645                 ret = -ENODEV;
646                 goto err_free_host_node;
647         }
648
649         if (!of_device_is_compatible(port_node, "hdmi-connector")) {
650                 dev_err(lt->dev, "%s: Failed to get hdmi port\n", __func__);
651                 ret = -EINVAL;
652                 goto err_free_host_node;
653         }
654
655         of_node_put(port_node);
656         return 0;
657
658 err_free_host_node:
659         of_node_put(port_node);
660         of_node_put(lt->host_node);
661         return ret;
662 }
663
664 static int lt8912_put_dt(struct lt8912 *lt)
665 {
666         of_node_put(lt->host_node);
667         return 0;
668 }
669
670 static int lt8912_probe(struct i2c_client *client,
671                         const struct i2c_device_id *id)
672 {
673         static struct lt8912 *lt;
674         int ret = 0;
675         struct device *dev = &client->dev;
676
677         lt = devm_kzalloc(dev, sizeof(struct lt8912), GFP_KERNEL);
678         if (!lt)
679                 return -ENOMEM;
680
681         lt->dev = dev;
682         lt->i2c_client[0] = client;
683
684         ret = lt8912_parse_dt(lt);
685         if (ret)
686                 goto err_dt_parse;
687
688         ret = lt8912_init_i2c(lt, client);
689         if (ret)
690                 goto err_i2c;
691
692         i2c_set_clientdata(client, lt);
693
694         lt->bridge.funcs = &lt8912_bridge_funcs;
695         lt->bridge.of_node = dev->of_node;
696         lt->bridge.ops = (DRM_BRIDGE_OP_EDID |
697                           DRM_BRIDGE_OP_DETECT);
698
699         drm_bridge_add(&lt->bridge);
700
701         ret = lt8912_attach_dsi(lt);
702         if (ret)
703                 goto err_attach;
704
705         return 0;
706
707 err_attach:
708         drm_bridge_remove(&lt->bridge);
709         lt8912_free_i2c(lt);
710 err_i2c:
711         lt8912_put_dt(lt);
712 err_dt_parse:
713         return ret;
714 }
715
716 static int lt8912_remove(struct i2c_client *client)
717 {
718         struct lt8912 *lt = i2c_get_clientdata(client);
719
720         lt8912_bridge_detach(&lt->bridge);
721         drm_bridge_remove(&lt->bridge);
722         lt8912_free_i2c(lt);
723         lt8912_put_dt(lt);
724         return 0;
725 }
726
727 static const struct of_device_id lt8912_dt_match[] = {
728         {.compatible = "lontium,lt8912b"},
729         {}
730 };
731 MODULE_DEVICE_TABLE(of, lt8912_dt_match);
732
733 static const struct i2c_device_id lt8912_id[] = {
734         {"lt8912", 0},
735         {},
736 };
737 MODULE_DEVICE_TABLE(i2c, lt8912_id);
738
739 static struct i2c_driver lt8912_i2c_driver = {
740         .driver = {
741                 .name = "lt8912",
742                 .of_match_table = lt8912_dt_match,
743         },
744         .probe = lt8912_probe,
745         .remove = lt8912_remove,
746         .id_table = lt8912_id,
747 };
748 module_i2c_driver(lt8912_i2c_driver);
749
750 MODULE_AUTHOR("Adrien Grassein <adrien.grassein@gmail.com>");
751 MODULE_DESCRIPTION("lt8912 drm driver");
752 MODULE_LICENSE("GPL v2");