51fd0abd13cebea1ac52a30f619ff2a11495642e
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / drm / panel / panel-simple.c
1 /*
2  * Copyright (C) 2013, NVIDIA Corporation.  All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sub license,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the
12  * next paragraph) shall be included in all copies or substantial portions
13  * of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23
24 #include <linux/backlight.h>
25 #include <linux/gpio/consumer.h>
26 #include <linux/module.h>
27 #include <linux/of_platform.h>
28 #include <linux/platform_device.h>
29 #include <linux/regulator/consumer.h>
30
31 #include <drm/drmP.h>
32 #include <drm/drm_crtc.h>
33 #include <drm/drm_mipi_dsi.h>
34 #include <drm/drm_panel.h>
35
36 #include <video/display_timing.h>
37 #include <video/of_display_timing.h>
38 #include <video/videomode.h>
39
40 struct panel_desc {
41         const struct drm_display_mode *modes;
42         unsigned int num_modes;
43         const struct display_timing *timings;
44         unsigned int num_timings;
45
46         unsigned int bpc;
47
48         struct {
49                 unsigned int width;
50                 unsigned int height;
51         } size;
52
53         /**
54          * @prepare: the time (in milliseconds) that it takes for the panel to
55          *           become ready and start receiving video data
56          * @enable: the time (in milliseconds) that it takes for the panel to
57          *          display the first valid frame after starting to receive
58          *          video data
59          * @disable: the time (in milliseconds) that it takes for the panel to
60          *           turn the display off (no content is visible)
61          * @unprepare: the time (in milliseconds) that it takes for the panel
62          *             to power itself down completely
63          */
64         struct {
65                 unsigned int prepare;
66                 unsigned int enable;
67                 unsigned int disable;
68                 unsigned int unprepare;
69         } delay;
70
71         u32 bus_format;
72 };
73
74 struct panel_simple {
75         struct drm_panel base;
76         bool prepared;
77         bool enabled;
78
79         struct device *dev;
80         const struct panel_desc *desc;
81
82         struct backlight_device *backlight;
83         struct regulator *supply;
84         struct i2c_adapter *ddc;
85
86         struct gpio_desc *enable_gpio;
87 };
88
89 static inline struct panel_simple *to_panel_simple(struct drm_panel *panel)
90 {
91         return container_of(panel, struct panel_simple, base);
92 }
93
94 static int panel_simple_get_fixed_modes(struct panel_simple *panel)
95 {
96         struct drm_connector *connector = panel->base.connector;
97         struct drm_device *drm = panel->base.drm;
98         struct drm_display_mode *mode;
99         unsigned int i, num = 0;
100
101         if (!panel->desc)
102                 return 0;
103
104         for (i = 0; i < panel->desc->num_timings; i++) {
105                 const struct display_timing *dt = &panel->desc->timings[i];
106                 struct videomode vm;
107
108                 videomode_from_timing(dt, &vm);
109                 mode = drm_mode_create(drm);
110                 if (!mode) {
111                         dev_err(drm->dev, "failed to add mode %ux%u\n",
112                                 dt->hactive.typ, dt->vactive.typ);
113                         continue;
114                 }
115
116                 drm_display_mode_from_videomode(&vm, mode);
117                 drm_mode_set_name(mode);
118
119                 drm_mode_probed_add(connector, mode);
120                 num++;
121         }
122
123         for (i = 0; i < panel->desc->num_modes; i++) {
124                 const struct drm_display_mode *m = &panel->desc->modes[i];
125
126                 mode = drm_mode_duplicate(drm, m);
127                 if (!mode) {
128                         dev_err(drm->dev, "failed to add mode %ux%u@%u\n",
129                                 m->hdisplay, m->vdisplay, m->vrefresh);
130                         continue;
131                 }
132
133                 drm_mode_set_name(mode);
134
135                 drm_mode_probed_add(connector, mode);
136                 num++;
137         }
138
139         connector->display_info.bpc = panel->desc->bpc;
140         connector->display_info.width_mm = panel->desc->size.width;
141         connector->display_info.height_mm = panel->desc->size.height;
142         if (panel->desc->bus_format)
143                 drm_display_info_set_bus_formats(&connector->display_info,
144                                                  &panel->desc->bus_format, 1);
145
146         return num;
147 }
148
149 static int panel_simple_of_get_native_mode(struct panel_simple *panel)
150 {
151         struct drm_connector *connector = panel->base.connector;
152         struct drm_device *drm = panel->base.drm;
153         struct drm_display_mode *mode;
154         int ret;
155
156         mode = drm_mode_create(drm);
157         if (!mode)
158                 return 0;
159
160         ret = of_get_drm_display_mode(panel->dev->of_node, mode,
161                                       OF_USE_NATIVE_MODE);
162         if (ret) {
163                 dev_dbg(panel->dev, "failed to find dts display timings\n");
164                 drm_mode_destroy(drm, mode);
165                 return 0;
166         }
167
168         drm_mode_set_name(mode);
169         mode->type |= DRM_MODE_TYPE_PREFERRED;
170         drm_mode_probed_add(connector, mode);
171
172         return 1;
173 }
174
175 static int panel_simple_disable(struct drm_panel *panel)
176 {
177         struct panel_simple *p = to_panel_simple(panel);
178
179         if (!p->enabled)
180                 return 0;
181
182         if (p->backlight) {
183                 p->backlight->props.power = FB_BLANK_POWERDOWN;
184                 backlight_update_status(p->backlight);
185         }
186
187         if (p->desc && p->desc->delay.disable)
188                 msleep(p->desc->delay.disable);
189
190         p->enabled = false;
191
192         return 0;
193 }
194
195 static int panel_simple_unprepare(struct drm_panel *panel)
196 {
197         struct panel_simple *p = to_panel_simple(panel);
198
199         if (!p->prepared)
200                 return 0;
201
202         if (p->enable_gpio)
203                 gpiod_direction_output(p->enable_gpio, 0);
204
205         regulator_disable(p->supply);
206
207         if (p->desc && p->desc->delay.unprepare)
208                 msleep(p->desc->delay.unprepare);
209
210         p->prepared = false;
211
212         return 0;
213 }
214
215 static int panel_simple_prepare(struct drm_panel *panel)
216 {
217         struct panel_simple *p = to_panel_simple(panel);
218         int err;
219
220         if (p->prepared)
221                 return 0;
222
223         err = regulator_enable(p->supply);
224         if (err < 0) {
225                 dev_err(panel->dev, "failed to enable supply: %d\n", err);
226                 return err;
227         }
228
229         if (p->enable_gpio)
230                 gpiod_direction_output(p->enable_gpio, 1);
231
232         if (p->desc && p->desc->delay.prepare)
233                 msleep(p->desc->delay.prepare);
234
235         p->prepared = true;
236
237         return 0;
238 }
239
240 static int panel_simple_enable(struct drm_panel *panel)
241 {
242         struct panel_simple *p = to_panel_simple(panel);
243
244         if (p->enabled)
245                 return 0;
246
247         if (p->desc && p->desc->delay.enable)
248                 msleep(p->desc->delay.enable);
249
250         if (p->backlight) {
251                 p->backlight->props.power = FB_BLANK_UNBLANK;
252                 backlight_update_status(p->backlight);
253         }
254
255         p->enabled = true;
256
257         return 0;
258 }
259
260 static int panel_simple_get_modes(struct drm_panel *panel)
261 {
262         struct panel_simple *p = to_panel_simple(panel);
263         int num = 0;
264
265         /* probe EDID if a DDC bus is available */
266         if (p->ddc) {
267                 struct edid *edid = drm_get_edid(panel->connector, p->ddc);
268                 drm_mode_connector_update_edid_property(panel->connector, edid);
269                 if (edid) {
270                         num += drm_add_edid_modes(panel->connector, edid);
271                         kfree(edid);
272                 }
273         }
274
275         /* add hard-coded panel modes */
276         num += panel_simple_get_fixed_modes(p);
277
278         /* add device node plane modes */
279         num += panel_simple_of_get_native_mode(p);
280
281         return num;
282 }
283
284 static int panel_simple_get_timings(struct drm_panel *panel,
285                                     unsigned int num_timings,
286                                     struct display_timing *timings)
287 {
288         struct panel_simple *p = to_panel_simple(panel);
289         unsigned int i;
290
291         if (!p->desc)
292                 return 0;
293
294         if (p->desc->num_timings < num_timings)
295                 num_timings = p->desc->num_timings;
296
297         if (timings)
298                 for (i = 0; i < num_timings; i++)
299                         timings[i] = p->desc->timings[i];
300
301         return p->desc->num_timings;
302 }
303
304 static const struct drm_panel_funcs panel_simple_funcs = {
305         .disable = panel_simple_disable,
306         .unprepare = panel_simple_unprepare,
307         .prepare = panel_simple_prepare,
308         .enable = panel_simple_enable,
309         .get_modes = panel_simple_get_modes,
310         .get_timings = panel_simple_get_timings,
311 };
312
313 static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
314 {
315         struct device_node *backlight, *ddc;
316         struct panel_simple *panel;
317         int err;
318
319         panel = devm_kzalloc(dev, sizeof(*panel), GFP_KERNEL);
320         if (!panel)
321                 return -ENOMEM;
322
323         panel->enabled = false;
324         panel->prepared = false;
325         panel->desc = desc;
326         panel->dev = dev;
327
328         panel->supply = devm_regulator_get(dev, "power");
329         if (IS_ERR(panel->supply))
330                 return PTR_ERR(panel->supply);
331
332         panel->enable_gpio = devm_gpiod_get_optional(dev, "enable", 0);
333         if (IS_ERR(panel->enable_gpio)) {
334                 err = PTR_ERR(panel->enable_gpio);
335                 dev_err(dev, "failed to request GPIO: %d\n", err);
336                 return err;
337         }
338
339         backlight = of_parse_phandle(dev->of_node, "backlight", 0);
340         if (backlight) {
341                 panel->backlight = of_find_backlight_by_node(backlight);
342                 of_node_put(backlight);
343
344                 if (!panel->backlight)
345                         return -EPROBE_DEFER;
346         }
347
348         ddc = of_parse_phandle(dev->of_node, "ddc-i2c-bus", 0);
349         if (ddc) {
350                 panel->ddc = of_find_i2c_adapter_by_node(ddc);
351                 of_node_put(ddc);
352
353                 if (!panel->ddc) {
354                         err = -EPROBE_DEFER;
355                         goto free_backlight;
356                 }
357         }
358
359         drm_panel_init(&panel->base);
360         panel->base.dev = dev;
361         panel->base.funcs = &panel_simple_funcs;
362
363         err = drm_panel_add(&panel->base);
364         if (err < 0)
365                 goto free_ddc;
366
367         dev_set_drvdata(dev, panel);
368
369         return 0;
370
371 free_ddc:
372         if (panel->ddc)
373                 put_device(&panel->ddc->dev);
374 free_backlight:
375         if (panel->backlight)
376                 put_device(&panel->backlight->dev);
377
378         return err;
379 }
380
381 static int panel_simple_remove(struct device *dev)
382 {
383         struct panel_simple *panel = dev_get_drvdata(dev);
384
385         drm_panel_detach(&panel->base);
386         drm_panel_remove(&panel->base);
387
388         panel_simple_disable(&panel->base);
389
390         if (panel->ddc)
391                 put_device(&panel->ddc->dev);
392
393         if (panel->backlight)
394                 put_device(&panel->backlight->dev);
395
396         return 0;
397 }
398
399 static void panel_simple_shutdown(struct device *dev)
400 {
401         struct panel_simple *panel = dev_get_drvdata(dev);
402
403         panel_simple_disable(&panel->base);
404 }
405
406 static const struct drm_display_mode ampire_am800480r3tmqwa1h_mode = {
407         .clock = 33333,
408         .hdisplay = 800,
409         .hsync_start = 800 + 0,
410         .hsync_end = 800 + 0 + 255,
411         .htotal = 800 + 0 + 255 + 0,
412         .vdisplay = 480,
413         .vsync_start = 480 + 2,
414         .vsync_end = 480 + 2 + 45,
415         .vtotal = 480 + 2 + 45 + 0,
416         .vrefresh = 60,
417         .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC,
418 };
419
420 static const struct panel_desc ampire_am800480r3tmqwa1h = {
421         .modes = &ampire_am800480r3tmqwa1h_mode,
422         .num_modes = 1,
423         .bpc = 6,
424         .size = {
425                 .width = 152,
426                 .height = 91,
427         },
428         .bus_format = MEDIA_BUS_FMT_RGB666_1X18,
429 };
430
431 static const struct drm_display_mode auo_b101aw03_mode = {
432         .clock = 51450,
433         .hdisplay = 1024,
434         .hsync_start = 1024 + 156,
435         .hsync_end = 1024 + 156 + 8,
436         .htotal = 1024 + 156 + 8 + 156,
437         .vdisplay = 600,
438         .vsync_start = 600 + 16,
439         .vsync_end = 600 + 16 + 6,
440         .vtotal = 600 + 16 + 6 + 16,
441         .vrefresh = 60,
442 };
443
444 static const struct panel_desc auo_b101aw03 = {
445         .modes = &auo_b101aw03_mode,
446         .num_modes = 1,
447         .bpc = 6,
448         .size = {
449                 .width = 223,
450                 .height = 125,
451         },
452 };
453
454 static const struct drm_display_mode auo_b101ean01_mode = {
455         .clock = 72500,
456         .hdisplay = 1280,
457         .hsync_start = 1280 + 119,
458         .hsync_end = 1280 + 119 + 32,
459         .htotal = 1280 + 119 + 32 + 21,
460         .vdisplay = 800,
461         .vsync_start = 800 + 4,
462         .vsync_end = 800 + 4 + 20,
463         .vtotal = 800 + 4 + 20 + 8,
464         .vrefresh = 60,
465 };
466
467 static const struct panel_desc auo_b101ean01 = {
468         .modes = &auo_b101ean01_mode,
469         .num_modes = 1,
470         .bpc = 6,
471         .size = {
472                 .width = 217,
473                 .height = 136,
474         },
475 };
476
477 static const struct drm_display_mode auo_b101ew05_mode = {
478         .clock = 71000,
479         .hdisplay = 1280,
480         .hsync_start = 1280 + 18,
481         .hsync_end = 1280 + 18 + 10,
482         .htotal = 1280 + 18 + 10 + 100,
483         .vdisplay = 800,
484         .vsync_start = 800 + 6,
485         .vsync_end = 800 + 6 + 2,
486         .vtotal = 800 + 6 + 2 + 8,
487         .vrefresh = 60,
488 };
489
490 static const struct panel_desc auo_b101ew05 = {
491         .modes = &auo_b101ew05_mode,
492         .num_modes = 1,
493         .bpc = 6,
494         .size = {
495                 .width = 217,
496                 .height = 136,
497         },
498 };
499
500 static const struct drm_display_mode auo_b101xtn01_mode = {
501         .clock = 72000,
502         .hdisplay = 1366,
503         .hsync_start = 1366 + 20,
504         .hsync_end = 1366 + 20 + 70,
505         .htotal = 1366 + 20 + 70,
506         .vdisplay = 768,
507         .vsync_start = 768 + 14,
508         .vsync_end = 768 + 14 + 42,
509         .vtotal = 768 + 14 + 42,
510         .vrefresh = 60,
511         .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
512 };
513
514 static const struct panel_desc auo_b101xtn01 = {
515         .modes = &auo_b101xtn01_mode,
516         .num_modes = 1,
517         .bpc = 6,
518         .size = {
519                 .width = 223,
520                 .height = 125,
521         },
522 };
523
524 static const struct drm_display_mode auo_b116xw03_mode = {
525         .clock = 70589,
526         .hdisplay = 1366,
527         .hsync_start = 1366 + 40,
528         .hsync_end = 1366 + 40 + 40,
529         .htotal = 1366 + 40 + 40 + 32,
530         .vdisplay = 768,
531         .vsync_start = 768 + 10,
532         .vsync_end = 768 + 10 + 12,
533         .vtotal = 768 + 10 + 12 + 6,
534         .vrefresh = 60,
535 };
536
537 static const struct panel_desc auo_b116xw03 = {
538         .modes = &auo_b116xw03_mode,
539         .num_modes = 1,
540         .bpc = 6,
541         .size = {
542                 .width = 256,
543                 .height = 144,
544         },
545 };
546
547 static const struct drm_display_mode auo_b133xtn01_mode = {
548         .clock = 69500,
549         .hdisplay = 1366,
550         .hsync_start = 1366 + 48,
551         .hsync_end = 1366 + 48 + 32,
552         .htotal = 1366 + 48 + 32 + 20,
553         .vdisplay = 768,
554         .vsync_start = 768 + 3,
555         .vsync_end = 768 + 3 + 6,
556         .vtotal = 768 + 3 + 6 + 13,
557         .vrefresh = 60,
558 };
559
560 static const struct panel_desc auo_b133xtn01 = {
561         .modes = &auo_b133xtn01_mode,
562         .num_modes = 1,
563         .bpc = 6,
564         .size = {
565                 .width = 293,
566                 .height = 165,
567         },
568 };
569
570 static const struct drm_display_mode auo_b133htn01_mode = {
571         .clock = 150660,
572         .hdisplay = 1920,
573         .hsync_start = 1920 + 172,
574         .hsync_end = 1920 + 172 + 80,
575         .htotal = 1920 + 172 + 80 + 60,
576         .vdisplay = 1080,
577         .vsync_start = 1080 + 25,
578         .vsync_end = 1080 + 25 + 10,
579         .vtotal = 1080 + 25 + 10 + 10,
580         .vrefresh = 60,
581 };
582
583 static const struct panel_desc auo_b133htn01 = {
584         .modes = &auo_b133htn01_mode,
585         .num_modes = 1,
586         .bpc = 6,
587         .size = {
588                 .width = 293,
589                 .height = 165,
590         },
591         .delay = {
592                 .prepare = 105,
593                 .enable = 20,
594                 .unprepare = 50,
595         },
596 };
597
598 static const struct drm_display_mode avic_tm070ddh03_mode = {
599         .clock = 51200,
600         .hdisplay = 1024,
601         .hsync_start = 1024 + 160,
602         .hsync_end = 1024 + 160 + 4,
603         .htotal = 1024 + 160 + 4 + 156,
604         .vdisplay = 600,
605         .vsync_start = 600 + 17,
606         .vsync_end = 600 + 17 + 1,
607         .vtotal = 600 + 17 + 1 + 17,
608         .vrefresh = 60,
609 };
610
611 static const struct panel_desc avic_tm070ddh03 = {
612         .modes = &avic_tm070ddh03_mode,
613         .num_modes = 1,
614         .bpc = 8,
615         .size = {
616                 .width = 154,
617                 .height = 90,
618         },
619         .delay = {
620                 .prepare = 20,
621                 .enable = 200,
622                 .disable = 200,
623         },
624 };
625
626 static const struct drm_display_mode chunghwa_claa070wp03xg_mode = {
627         .clock = 67000,
628         .hdisplay = 800,
629         .hsync_start = 800 + 24,
630         .hsync_end = 800 + 24 + 16,
631         .htotal = 800 + 24 + 16 + 24,
632         .vdisplay = 1280,
633         .vsync_start = 1280 + 2,
634         .vsync_end = 1280 + 2 + 2,
635         .vtotal = 1280 + 2 + 2 + 4,
636         .vrefresh = 60,
637 };
638
639 static const struct panel_desc chunghwa_claa070wp03xg = {
640         .modes = &chunghwa_claa070wp03xg_mode,
641         .num_modes = 1,
642         .bpc = 6,
643         .size = {
644                 .width = 94,
645                 .height = 151,
646         },
647 };
648
649 static const struct drm_display_mode chunghwa_claa101wa01a_mode = {
650         .clock = 72070,
651         .hdisplay = 1366,
652         .hsync_start = 1366 + 58,
653         .hsync_end = 1366 + 58 + 58,
654         .htotal = 1366 + 58 + 58 + 58,
655         .vdisplay = 768,
656         .vsync_start = 768 + 4,
657         .vsync_end = 768 + 4 + 4,
658         .vtotal = 768 + 4 + 4 + 4,
659         .vrefresh = 60,
660 };
661
662 static const struct panel_desc chunghwa_claa101wa01a = {
663         .modes = &chunghwa_claa101wa01a_mode,
664         .num_modes = 1,
665         .bpc = 6,
666         .size = {
667                 .width = 220,
668                 .height = 120,
669         },
670 };
671
672 static const struct drm_display_mode chunghwa_claa101wb01_mode = {
673         .clock = 69300,
674         .hdisplay = 1366,
675         .hsync_start = 1366 + 48,
676         .hsync_end = 1366 + 48 + 32,
677         .htotal = 1366 + 48 + 32 + 20,
678         .vdisplay = 768,
679         .vsync_start = 768 + 16,
680         .vsync_end = 768 + 16 + 8,
681         .vtotal = 768 + 16 + 8 + 16,
682         .vrefresh = 60,
683 };
684
685 static const struct panel_desc chunghwa_claa101wb01 = {
686         .modes = &chunghwa_claa101wb01_mode,
687         .num_modes = 1,
688         .bpc = 6,
689         .size = {
690                 .width = 223,
691                 .height = 125,
692         },
693 };
694
695 static const struct drm_display_mode edt_et057090dhu_mode = {
696         .clock = 25175,
697         .hdisplay = 640,
698         .hsync_start = 640 + 16,
699         .hsync_end = 640 + 16 + 30,
700         .htotal = 640 + 16 + 30 + 114,
701         .vdisplay = 480,
702         .vsync_start = 480 + 10,
703         .vsync_end = 480 + 10 + 3,
704         .vtotal = 480 + 10 + 3 + 32,
705         .vrefresh = 60,
706         .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
707 };
708
709 static const struct panel_desc edt_et057090dhu = {
710         .modes = &edt_et057090dhu_mode,
711         .num_modes = 1,
712         .bpc = 6,
713         .size = {
714                 .width = 115,
715                 .height = 86,
716         },
717 };
718
719 static const struct drm_display_mode edt_etm0700g0dh6_mode = {
720         .clock = 33260,
721         .hdisplay = 800,
722         .hsync_start = 800 + 40,
723         .hsync_end = 800 + 40 + 128,
724         .htotal = 800 + 40 + 128 + 88,
725         .vdisplay = 480,
726         .vsync_start = 480 + 10,
727         .vsync_end = 480 + 10 + 2,
728         .vtotal = 480 + 10 + 2 + 33,
729         .vrefresh = 60,
730         .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
731 };
732
733 static const struct panel_desc edt_etm0700g0dh6 = {
734         .modes = &edt_etm0700g0dh6_mode,
735         .num_modes = 1,
736         .bpc = 6,
737         .size = {
738                 .width = 152,
739                 .height = 91,
740         },
741 };
742
743 static const struct drm_display_mode foxlink_fl500wvr00_a0t_mode = {
744         .clock = 32260,
745         .hdisplay = 800,
746         .hsync_start = 800 + 168,
747         .hsync_end = 800 + 168 + 64,
748         .htotal = 800 + 168 + 64 + 88,
749         .vdisplay = 480,
750         .vsync_start = 480 + 37,
751         .vsync_end = 480 + 37 + 2,
752         .vtotal = 480 + 37 + 2 + 8,
753         .vrefresh = 60,
754 };
755
756 static const struct panel_desc foxlink_fl500wvr00_a0t = {
757         .modes = &foxlink_fl500wvr00_a0t_mode,
758         .num_modes = 1,
759         .bpc = 8,
760         .size = {
761                 .width = 108,
762                 .height = 65,
763         },
764         .bus_format = MEDIA_BUS_FMT_RGB888_1X24,
765 };
766
767 static const struct drm_display_mode giantplus_gpg482739qs5_mode = {
768         .clock = 9000,
769         .hdisplay = 480,
770         .hsync_start = 480 + 5,
771         .hsync_end = 480 + 5 + 1,
772         .htotal = 480 + 5 + 1 + 40,
773         .vdisplay = 272,
774         .vsync_start = 272 + 8,
775         .vsync_end = 272 + 8 + 1,
776         .vtotal = 272 + 8 + 1 + 8,
777         .vrefresh = 60,
778 };
779
780 static const struct panel_desc giantplus_gpg482739qs5 = {
781         .modes = &giantplus_gpg482739qs5_mode,
782         .num_modes = 1,
783         .bpc = 8,
784         .size = {
785                 .width = 95,
786                 .height = 54,
787         },
788         .bus_format = MEDIA_BUS_FMT_RGB888_1X24,
789 };
790
791 static const struct display_timing hannstar_hsd070pww1_timing = {
792         .pixelclock = { 64300000, 71100000, 82000000 },
793         .hactive = { 1280, 1280, 1280 },
794         .hfront_porch = { 1, 1, 10 },
795         .hback_porch = { 1, 1, 10 },
796         /*
797          * According to the data sheet, the minimum horizontal blanking interval
798          * is 54 clocks (1 + 52 + 1), but tests with a Nitrogen6X have shown the
799          * minimum working horizontal blanking interval to be 60 clocks.
800          */
801         .hsync_len = { 58, 158, 661 },
802         .vactive = { 800, 800, 800 },
803         .vfront_porch = { 1, 1, 10 },
804         .vback_porch = { 1, 1, 10 },
805         .vsync_len = { 1, 21, 203 },
806         .flags = DISPLAY_FLAGS_DE_HIGH,
807 };
808
809 static const struct panel_desc hannstar_hsd070pww1 = {
810         .timings = &hannstar_hsd070pww1_timing,
811         .num_timings = 1,
812         .bpc = 6,
813         .size = {
814                 .width = 151,
815                 .height = 94,
816         },
817         .bus_format = MEDIA_BUS_FMT_RGB666_1X7X3_SPWG,
818 };
819
820 static const struct display_timing hannstar_hsd100pxn1_timing = {
821         .pixelclock = { 55000000, 65000000, 75000000 },
822         .hactive = { 1024, 1024, 1024 },
823         .hfront_porch = { 40, 40, 40 },
824         .hback_porch = { 220, 220, 220 },
825         .hsync_len = { 20, 60, 100 },
826         .vactive = { 768, 768, 768 },
827         .vfront_porch = { 7, 7, 7 },
828         .vback_porch = { 21, 21, 21 },
829         .vsync_len = { 10, 10, 10 },
830         .flags = DISPLAY_FLAGS_DE_HIGH,
831 };
832
833 static const struct panel_desc hannstar_hsd100pxn1 = {
834         .timings = &hannstar_hsd100pxn1_timing,
835         .num_timings = 1,
836         .bpc = 6,
837         .size = {
838                 .width = 203,
839                 .height = 152,
840         },
841         .bus_format = MEDIA_BUS_FMT_RGB666_1X7X3_SPWG,
842 };
843
844 static const struct drm_display_mode hitachi_tx23d38vm0caa_mode = {
845         .clock = 33333,
846         .hdisplay = 800,
847         .hsync_start = 800 + 85,
848         .hsync_end = 800 + 85 + 86,
849         .htotal = 800 + 85 + 86 + 85,
850         .vdisplay = 480,
851         .vsync_start = 480 + 16,
852         .vsync_end = 480 + 16 + 13,
853         .vtotal = 480 + 16 + 13 + 16,
854         .vrefresh = 60,
855 };
856
857 static const struct panel_desc hitachi_tx23d38vm0caa = {
858         .modes = &hitachi_tx23d38vm0caa_mode,
859         .num_modes = 1,
860         .bpc = 6,
861         .size = {
862                 .width = 195,
863                 .height = 117,
864         },
865 };
866
867 static const struct drm_display_mode innolux_at043tn24_mode = {
868         .clock = 9000,
869         .hdisplay = 480,
870         .hsync_start = 480 + 2,
871         .hsync_end = 480 + 2 + 41,
872         .htotal = 480 + 2 + 41 + 2,
873         .vdisplay = 272,
874         .vsync_start = 272 + 2,
875         .vsync_end = 272 + 2 + 11,
876         .vtotal = 272 + 2 + 11 + 2,
877         .vrefresh = 60,
878         .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
879 };
880
881 static const struct panel_desc innolux_at043tn24 = {
882         .modes = &innolux_at043tn24_mode,
883         .num_modes = 1,
884         .bpc = 8,
885         .size = {
886                 .width = 95,
887                 .height = 54,
888         },
889         .bus_format = MEDIA_BUS_FMT_RGB888_1X24,
890 };
891
892 static const struct drm_display_mode innolux_g121i1_l01_mode = {
893         .clock = 71000,
894         .hdisplay = 1280,
895         .hsync_start = 1280 + 64,
896         .hsync_end = 1280 + 64 + 32,
897         .htotal = 1280 + 64 + 32 + 64,
898         .vdisplay = 800,
899         .vsync_start = 800 + 9,
900         .vsync_end = 800 + 9 + 6,
901         .vtotal = 800 + 9 + 6 + 9,
902         .vrefresh = 60,
903 };
904
905 static const struct panel_desc innolux_g121i1_l01 = {
906         .modes = &innolux_g121i1_l01_mode,
907         .num_modes = 1,
908         .bpc = 6,
909         .size = {
910                 .width = 261,
911                 .height = 163,
912         },
913 };
914
915 static const struct drm_display_mode innolux_n116bge_mode = {
916         .clock = 76420,
917         .hdisplay = 1366,
918         .hsync_start = 1366 + 136,
919         .hsync_end = 1366 + 136 + 30,
920         .htotal = 1366 + 136 + 30 + 60,
921         .vdisplay = 768,
922         .vsync_start = 768 + 8,
923         .vsync_end = 768 + 8 + 12,
924         .vtotal = 768 + 8 + 12 + 12,
925         .vrefresh = 60,
926         .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
927 };
928
929 static const struct panel_desc innolux_n116bge = {
930         .modes = &innolux_n116bge_mode,
931         .num_modes = 1,
932         .bpc = 6,
933         .size = {
934                 .width = 256,
935                 .height = 144,
936         },
937 };
938
939 static const struct drm_display_mode innolux_n156bge_l21_mode = {
940         .clock = 69300,
941         .hdisplay = 1366,
942         .hsync_start = 1366 + 16,
943         .hsync_end = 1366 + 16 + 34,
944         .htotal = 1366 + 16 + 34 + 50,
945         .vdisplay = 768,
946         .vsync_start = 768 + 2,
947         .vsync_end = 768 + 2 + 6,
948         .vtotal = 768 + 2 + 6 + 12,
949         .vrefresh = 60,
950 };
951
952 static const struct panel_desc innolux_n156bge_l21 = {
953         .modes = &innolux_n156bge_l21_mode,
954         .num_modes = 1,
955         .bpc = 6,
956         .size = {
957                 .width = 344,
958                 .height = 193,
959         },
960 };
961
962 static const struct drm_display_mode innolux_zj070na_01p_mode = {
963         .clock = 51501,
964         .hdisplay = 1024,
965         .hsync_start = 1024 + 128,
966         .hsync_end = 1024 + 128 + 64,
967         .htotal = 1024 + 128 + 64 + 128,
968         .vdisplay = 600,
969         .vsync_start = 600 + 16,
970         .vsync_end = 600 + 16 + 4,
971         .vtotal = 600 + 16 + 4 + 16,
972         .vrefresh = 60,
973 };
974
975 static const struct panel_desc innolux_zj070na_01p = {
976         .modes = &innolux_zj070na_01p_mode,
977         .num_modes = 1,
978         .bpc = 6,
979         .size = {
980                 .width = 1024,
981                 .height = 600,
982         },
983 };
984
985 static const struct drm_display_mode lg_lb070wv8_mode = {
986         .clock = 33246,
987         .hdisplay = 800,
988         .hsync_start = 800 + 88,
989         .hsync_end = 800 + 88 + 80,
990         .htotal = 800 + 88 + 80 + 88,
991         .vdisplay = 480,
992         .vsync_start = 480 + 10,
993         .vsync_end = 480 + 10 + 25,
994         .vtotal = 480 + 10 + 25 + 10,
995         .vrefresh = 60,
996 };
997
998 static const struct panel_desc lg_lb070wv8 = {
999         .modes = &lg_lb070wv8_mode,
1000         .num_modes = 1,
1001         .bpc = 16,
1002         .size = {
1003                 .width = 151,
1004                 .height = 91,
1005         },
1006         .bus_format = MEDIA_BUS_FMT_RGB888_1X7X4_SPWG,
1007 };
1008
1009 static const struct drm_display_mode lg_lp079qx1_sp0v_mode = {
1010         .clock = 200000,
1011         .hdisplay = 1536,
1012         .hsync_start = 1536 + 12,
1013         .hsync_end = 1536 + 12 + 16,
1014         .htotal = 1536 + 12 + 16 + 48,
1015         .vdisplay = 2048,
1016         .vsync_start = 2048 + 8,
1017         .vsync_end = 2048 + 8 + 4,
1018         .vtotal = 2048 + 8 + 4 + 8,
1019         .vrefresh = 60,
1020         .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
1021 };
1022
1023 static const struct panel_desc lg_lp079qx1_sp0v = {
1024         .modes = &lg_lp079qx1_sp0v_mode,
1025         .num_modes = 1,
1026         .size = {
1027                 .width = 129,
1028                 .height = 171,
1029         },
1030 };
1031
1032 static const struct drm_display_mode lg_lp097qx1_spa1_mode = {
1033         .clock = 205210,
1034         .hdisplay = 2048,
1035         .hsync_start = 2048 + 150,
1036         .hsync_end = 2048 + 150 + 5,
1037         .htotal = 2048 + 150 + 5 + 5,
1038         .vdisplay = 1536,
1039         .vsync_start = 1536 + 3,
1040         .vsync_end = 1536 + 3 + 1,
1041         .vtotal = 1536 + 3 + 1 + 9,
1042         .vrefresh = 60,
1043 };
1044
1045 static const struct panel_desc lg_lp097qx1_spa1 = {
1046         .modes = &lg_lp097qx1_spa1_mode,
1047         .num_modes = 1,
1048         .size = {
1049                 .width = 320,
1050                 .height = 187,
1051         },
1052 };
1053
1054 static const struct drm_display_mode lg_lp129qe_mode = {
1055         .clock = 285250,
1056         .hdisplay = 2560,
1057         .hsync_start = 2560 + 48,
1058         .hsync_end = 2560 + 48 + 32,
1059         .htotal = 2560 + 48 + 32 + 80,
1060         .vdisplay = 1700,
1061         .vsync_start = 1700 + 3,
1062         .vsync_end = 1700 + 3 + 10,
1063         .vtotal = 1700 + 3 + 10 + 36,
1064         .vrefresh = 60,
1065 };
1066
1067 static const struct panel_desc lg_lp129qe = {
1068         .modes = &lg_lp129qe_mode,
1069         .num_modes = 1,
1070         .bpc = 8,
1071         .size = {
1072                 .width = 272,
1073                 .height = 181,
1074         },
1075 };
1076
1077 static const struct drm_display_mode nec_nl4827hc19_05b_mode = {
1078         .clock = 10870,
1079         .hdisplay = 480,
1080         .hsync_start = 480 + 2,
1081         .hsync_end = 480 + 2 + 41,
1082         .htotal = 480 + 2 + 41 + 2,
1083         .vdisplay = 272,
1084         .vsync_start = 272 + 2,
1085         .vsync_end = 272 + 2 + 4,
1086         .vtotal = 272 + 2 + 4 + 2,
1087         .vrefresh = 74,
1088 };
1089
1090 static const struct panel_desc nec_nl4827hc19_05b = {
1091         .modes = &nec_nl4827hc19_05b_mode,
1092         .num_modes = 1,
1093         .bpc = 8,
1094         .size = {
1095                 .width = 95,
1096                 .height = 54,
1097         },
1098         .bus_format = MEDIA_BUS_FMT_RGB888_1X24
1099 };
1100
1101 static const struct display_timing okaya_rs800480t_7x0gp_timing = {
1102         .pixelclock = { 30000000, 30000000, 40000000 },
1103         .hactive = { 800, 800, 800 },
1104         .hfront_porch = { 40, 40, 40 },
1105         .hback_porch = { 40, 40, 40 },
1106         .hsync_len = { 1, 48, 48 },
1107         .vactive = { 480, 480, 480 },
1108         .vfront_porch = { 13, 13, 13 },
1109         .vback_porch = { 29, 29, 29 },
1110         .vsync_len = { 3, 3, 3 },
1111         .flags = DISPLAY_FLAGS_DE_HIGH,
1112 };
1113
1114 static const struct panel_desc okaya_rs800480t_7x0gp = {
1115         .timings = &okaya_rs800480t_7x0gp_timing,
1116         .num_timings = 1,
1117         .bpc = 6,
1118         .size = {
1119                 .width = 154,
1120                 .height = 87,
1121         },
1122         .delay = {
1123                 .prepare = 41,
1124                 .enable = 50,
1125                 .unprepare = 41,
1126                 .disable = 50,
1127         },
1128         .bus_format = MEDIA_BUS_FMT_RGB666_1X18,
1129 };
1130
1131 static const struct drm_display_mode ortustech_com43h4m85ulc_mode  = {
1132         .clock = 25000,
1133         .hdisplay = 480,
1134         .hsync_start = 480 + 10,
1135         .hsync_end = 480 + 10 + 10,
1136         .htotal = 480 + 10 + 10 + 15,
1137         .vdisplay = 800,
1138         .vsync_start = 800 + 3,
1139         .vsync_end = 800 + 3 + 3,
1140         .vtotal = 800 + 3 + 3 + 3,
1141         .vrefresh = 60,
1142 };
1143
1144 static const struct panel_desc ortustech_com43h4m85ulc = {
1145         .modes = &ortustech_com43h4m85ulc_mode,
1146         .num_modes = 1,
1147         .bpc = 8,
1148         .size = {
1149                 .width = 56,
1150                 .height = 93,
1151         },
1152         .bus_format = MEDIA_BUS_FMT_RGB888_1X24,
1153 };
1154
1155 static const struct drm_display_mode samsung_lsn122dl01_c01_mode = {
1156         .clock = 271560,
1157         .hdisplay = 2560,
1158         .hsync_start = 2560 + 48,
1159         .hsync_end = 2560 + 48 + 32,
1160         .htotal = 2560 + 48 + 32 + 80,
1161         .vdisplay = 1600,
1162         .vsync_start = 1600 + 2,
1163         .vsync_end = 1600 + 2 + 5,
1164         .vtotal = 1600 + 2 + 5 + 57,
1165         .vrefresh = 60,
1166 };
1167
1168 static const struct panel_desc samsung_lsn122dl01_c01 = {
1169         .modes = &samsung_lsn122dl01_c01_mode,
1170         .num_modes = 1,
1171         .size = {
1172                 .width = 2560,
1173                 .height = 1600,
1174         },
1175 };
1176
1177 static const struct drm_display_mode samsung_ltn101nt05_mode = {
1178         .clock = 54030,
1179         .hdisplay = 1024,
1180         .hsync_start = 1024 + 24,
1181         .hsync_end = 1024 + 24 + 136,
1182         .htotal = 1024 + 24 + 136 + 160,
1183         .vdisplay = 600,
1184         .vsync_start = 600 + 3,
1185         .vsync_end = 600 + 3 + 6,
1186         .vtotal = 600 + 3 + 6 + 61,
1187         .vrefresh = 60,
1188 };
1189
1190 static const struct panel_desc samsung_ltn101nt05 = {
1191         .modes = &samsung_ltn101nt05_mode,
1192         .num_modes = 1,
1193         .bpc = 6,
1194         .size = {
1195                 .width = 1024,
1196                 .height = 600,
1197         },
1198 };
1199
1200 static const struct drm_display_mode samsung_ltn140at29_301_mode = {
1201         .clock = 76300,
1202         .hdisplay = 1366,
1203         .hsync_start = 1366 + 64,
1204         .hsync_end = 1366 + 64 + 48,
1205         .htotal = 1366 + 64 + 48 + 128,
1206         .vdisplay = 768,
1207         .vsync_start = 768 + 2,
1208         .vsync_end = 768 + 2 + 5,
1209         .vtotal = 768 + 2 + 5 + 17,
1210         .vrefresh = 60,
1211 };
1212
1213 static const struct panel_desc samsung_ltn140at29_301 = {
1214         .modes = &samsung_ltn140at29_301_mode,
1215         .num_modes = 1,
1216         .bpc = 6,
1217         .size = {
1218                 .width = 320,
1219                 .height = 187,
1220         },
1221 };
1222
1223 static const struct drm_display_mode shelly_sca07010_bfn_lnn_mode = {
1224         .clock = 33300,
1225         .hdisplay = 800,
1226         .hsync_start = 800 + 1,
1227         .hsync_end = 800 + 1 + 64,
1228         .htotal = 800 + 1 + 64 + 64,
1229         .vdisplay = 480,
1230         .vsync_start = 480 + 1,
1231         .vsync_end = 480 + 1 + 23,
1232         .vtotal = 480 + 1 + 23 + 22,
1233         .vrefresh = 60,
1234 };
1235
1236 static const struct panel_desc shelly_sca07010_bfn_lnn = {
1237         .modes = &shelly_sca07010_bfn_lnn_mode,
1238         .num_modes = 1,
1239         .size = {
1240                 .width = 152,
1241                 .height = 91,
1242         },
1243         .bus_format = MEDIA_BUS_FMT_RGB666_1X18,
1244 };
1245
1246 static const struct of_device_id platform_of_match[] = {
1247         {
1248                 .compatible = "simple-panel",
1249                 .data = NULL,
1250         }, {
1251                 .compatible = "ampire,am800480r3tmqwa1h",
1252                 .data = &ampire_am800480r3tmqwa1h,
1253         }, {
1254                 .compatible = "auo,b101aw03",
1255                 .data = &auo_b101aw03,
1256         }, {
1257                 .compatible = "auo,b101ean01",
1258                 .data = &auo_b101ean01,
1259         }, {
1260                 .compatible = "auo,b101ew05",
1261                 .data = &auo_b101ew05,
1262         }, {
1263                 .compatible = "auo,b101xtn01",
1264                 .data = &auo_b101xtn01,
1265         }, {
1266                 .compatible = "auo,b116xw03",
1267                 .data = &auo_b116xw03,
1268         }, {
1269                 .compatible = "auo,b133htn01",
1270                 .data = &auo_b133htn01,
1271         }, {
1272                 .compatible = "auo,b133xtn01",
1273                 .data = &auo_b133xtn01,
1274         }, {
1275                 .compatible = "avic,tm070ddh03",
1276                 .data = &avic_tm070ddh03,
1277         }, {
1278                 .compatible = "chunghwa,claa070wp03xg",
1279                 .data = &chunghwa_claa070wp03xg,
1280         }, {
1281                 .compatible = "chunghwa,claa101wa01a",
1282                 .data = &chunghwa_claa101wa01a
1283         }, {
1284                 .compatible = "chunghwa,claa101wb01",
1285                 .data = &chunghwa_claa101wb01
1286         }, {
1287                 .compatible = "edt,et057090dhu",
1288                 .data = &edt_et057090dhu,
1289         }, {
1290                 .compatible = "edt,et070080dh6",
1291                 .data = &edt_etm0700g0dh6,
1292         }, {
1293                 .compatible = "edt,etm0700g0dh6",
1294                 .data = &edt_etm0700g0dh6,
1295         }, {
1296                 .compatible = "foxlink,fl500wvr00-a0t",
1297                 .data = &foxlink_fl500wvr00_a0t,
1298         }, {
1299                 .compatible = "giantplus,gpg482739qs5",
1300                 .data = &giantplus_gpg482739qs5
1301         }, {
1302                 .compatible = "hannstar,hsd070pww1",
1303                 .data = &hannstar_hsd070pww1,
1304         }, {
1305                 .compatible = "hannstar,hsd100pxn1",
1306                 .data = &hannstar_hsd100pxn1,
1307         }, {
1308                 .compatible = "hit,tx23d38vm0caa",
1309                 .data = &hitachi_tx23d38vm0caa
1310         }, {
1311                 .compatible = "innolux,at043tn24",
1312                 .data = &innolux_at043tn24,
1313         }, {
1314                 .compatible ="innolux,g121i1-l01",
1315                 .data = &innolux_g121i1_l01
1316         }, {
1317                 .compatible = "innolux,n116bge",
1318                 .data = &innolux_n116bge,
1319         }, {
1320                 .compatible = "innolux,n156bge-l21",
1321                 .data = &innolux_n156bge_l21,
1322         }, {
1323                 .compatible = "innolux,zj070na-01p",
1324                 .data = &innolux_zj070na_01p,
1325         }, {
1326                 .compatible = "lg,lb070wv8",
1327                 .data = &lg_lb070wv8,
1328         }, {
1329                 .compatible = "lg,lp079qx1-sp0v",
1330                 .data = &lg_lp079qx1_sp0v,
1331         }, {
1332                 .compatible = "lg,lp097qx1-spa1",
1333                 .data = &lg_lp097qx1_spa1,
1334         }, {
1335                 .compatible = "lg,lp129qe",
1336                 .data = &lg_lp129qe,
1337         }, {
1338                 .compatible = "nec,nl4827hc19-05b",
1339                 .data = &nec_nl4827hc19_05b,
1340         }, {
1341                 .compatible = "okaya,rs800480t-7x0gp",
1342                 .data = &okaya_rs800480t_7x0gp,
1343         }, {
1344                 .compatible = "ortustech,com43h4m85ulc",
1345                 .data = &ortustech_com43h4m85ulc,
1346         }, {
1347                 .compatible = "samsung,lsn122dl01-c01",
1348                 .data = &samsung_lsn122dl01_c01,
1349         }, {
1350                 .compatible = "samsung,ltn101nt05",
1351                 .data = &samsung_ltn101nt05,
1352         }, {
1353                 .compatible = "samsung,ltn140at29-301",
1354                 .data = &samsung_ltn140at29_301,
1355         }, {
1356                 .compatible = "shelly,sca07010-bfn-lnn",
1357                 .data = &shelly_sca07010_bfn_lnn,
1358         }, {
1359                 /* sentinel */
1360         }
1361 };
1362 MODULE_DEVICE_TABLE(of, platform_of_match);
1363
1364 static int panel_simple_platform_probe(struct platform_device *pdev)
1365 {
1366         const struct of_device_id *id;
1367
1368         id = of_match_node(platform_of_match, pdev->dev.of_node);
1369         if (!id)
1370                 return -ENODEV;
1371
1372         return panel_simple_probe(&pdev->dev, id->data);
1373 }
1374
1375 static int panel_simple_platform_remove(struct platform_device *pdev)
1376 {
1377         return panel_simple_remove(&pdev->dev);
1378 }
1379
1380 static void panel_simple_platform_shutdown(struct platform_device *pdev)
1381 {
1382         panel_simple_shutdown(&pdev->dev);
1383 }
1384
1385 static struct platform_driver panel_simple_platform_driver = {
1386         .driver = {
1387                 .name = "panel-simple",
1388                 .of_match_table = platform_of_match,
1389         },
1390         .probe = panel_simple_platform_probe,
1391         .remove = panel_simple_platform_remove,
1392         .shutdown = panel_simple_platform_shutdown,
1393 };
1394
1395 struct panel_desc_dsi {
1396         struct panel_desc desc;
1397
1398         unsigned long flags;
1399         enum mipi_dsi_pixel_format format;
1400         unsigned int lanes;
1401 };
1402
1403 static const struct drm_display_mode auo_b080uan01_mode = {
1404         .clock = 154500,
1405         .hdisplay = 1200,
1406         .hsync_start = 1200 + 62,
1407         .hsync_end = 1200 + 62 + 4,
1408         .htotal = 1200 + 62 + 4 + 62,
1409         .vdisplay = 1920,
1410         .vsync_start = 1920 + 9,
1411         .vsync_end = 1920 + 9 + 2,
1412         .vtotal = 1920 + 9 + 2 + 8,
1413         .vrefresh = 60,
1414 };
1415
1416 static const struct panel_desc_dsi auo_b080uan01 = {
1417         .desc = {
1418                 .modes = &auo_b080uan01_mode,
1419                 .num_modes = 1,
1420                 .bpc = 8,
1421                 .size = {
1422                         .width = 108,
1423                         .height = 272,
1424                 },
1425         },
1426         .flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_CLOCK_NON_CONTINUOUS,
1427         .format = MIPI_DSI_FMT_RGB888,
1428         .lanes = 4,
1429 };
1430
1431 static const struct drm_display_mode boe_tv080wum_nl0_mode = {
1432         .clock = 160000,
1433         .hdisplay = 1200,
1434         .hsync_start = 1200 + 120,
1435         .hsync_end = 1200 + 120 + 20,
1436         .htotal = 1200 + 120 + 20 + 21,
1437         .vdisplay = 1920,
1438         .vsync_start = 1920 + 21,
1439         .vsync_end = 1920 + 21 + 3,
1440         .vtotal = 1920 + 21 + 3 + 18,
1441         .vrefresh = 60,
1442         .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
1443 };
1444
1445 static const struct panel_desc_dsi boe_tv080wum_nl0 = {
1446         .desc = {
1447                 .modes = &boe_tv080wum_nl0_mode,
1448                 .num_modes = 1,
1449                 .size = {
1450                         .width = 107,
1451                         .height = 172,
1452                 },
1453         },
1454         .flags = MIPI_DSI_MODE_VIDEO |
1455                  MIPI_DSI_MODE_VIDEO_BURST |
1456                  MIPI_DSI_MODE_VIDEO_SYNC_PULSE,
1457         .format = MIPI_DSI_FMT_RGB888,
1458         .lanes = 4,
1459 };
1460
1461 static const struct drm_display_mode lg_ld070wx3_sl01_mode = {
1462         .clock = 71000,
1463         .hdisplay = 800,
1464         .hsync_start = 800 + 32,
1465         .hsync_end = 800 + 32 + 1,
1466         .htotal = 800 + 32 + 1 + 57,
1467         .vdisplay = 1280,
1468         .vsync_start = 1280 + 28,
1469         .vsync_end = 1280 + 28 + 1,
1470         .vtotal = 1280 + 28 + 1 + 14,
1471         .vrefresh = 60,
1472 };
1473
1474 static const struct panel_desc_dsi lg_ld070wx3_sl01 = {
1475         .desc = {
1476                 .modes = &lg_ld070wx3_sl01_mode,
1477                 .num_modes = 1,
1478                 .bpc = 8,
1479                 .size = {
1480                         .width = 94,
1481                         .height = 151,
1482                 },
1483         },
1484         .flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_CLOCK_NON_CONTINUOUS,
1485         .format = MIPI_DSI_FMT_RGB888,
1486         .lanes = 4,
1487 };
1488
1489 static const struct drm_display_mode lg_lh500wx1_sd03_mode = {
1490         .clock = 67000,
1491         .hdisplay = 720,
1492         .hsync_start = 720 + 12,
1493         .hsync_end = 720 + 12 + 4,
1494         .htotal = 720 + 12 + 4 + 112,
1495         .vdisplay = 1280,
1496         .vsync_start = 1280 + 8,
1497         .vsync_end = 1280 + 8 + 4,
1498         .vtotal = 1280 + 8 + 4 + 12,
1499         .vrefresh = 60,
1500 };
1501
1502 static const struct panel_desc_dsi lg_lh500wx1_sd03 = {
1503         .desc = {
1504                 .modes = &lg_lh500wx1_sd03_mode,
1505                 .num_modes = 1,
1506                 .bpc = 8,
1507                 .size = {
1508                         .width = 62,
1509                         .height = 110,
1510                 },
1511         },
1512         .flags = MIPI_DSI_MODE_VIDEO,
1513         .format = MIPI_DSI_FMT_RGB888,
1514         .lanes = 4,
1515 };
1516
1517 static const struct drm_display_mode panasonic_vvx10f004b00_mode = {
1518         .clock = 157200,
1519         .hdisplay = 1920,
1520         .hsync_start = 1920 + 154,
1521         .hsync_end = 1920 + 154 + 16,
1522         .htotal = 1920 + 154 + 16 + 32,
1523         .vdisplay = 1200,
1524         .vsync_start = 1200 + 17,
1525         .vsync_end = 1200 + 17 + 2,
1526         .vtotal = 1200 + 17 + 2 + 16,
1527         .vrefresh = 60,
1528 };
1529
1530 static const struct panel_desc_dsi panasonic_vvx10f004b00 = {
1531         .desc = {
1532                 .modes = &panasonic_vvx10f004b00_mode,
1533                 .num_modes = 1,
1534                 .bpc = 8,
1535                 .size = {
1536                         .width = 217,
1537                         .height = 136,
1538                 },
1539         },
1540         .flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE |
1541                  MIPI_DSI_CLOCK_NON_CONTINUOUS,
1542         .format = MIPI_DSI_FMT_RGB888,
1543         .lanes = 4,
1544 };
1545
1546
1547 static const struct of_device_id dsi_of_match[] = {
1548         {
1549                 .compatible = "simple-panel-dsi",
1550                 .data = NULL
1551         }, {
1552                 .compatible = "auo,b080uan01",
1553                 .data = &auo_b080uan01
1554         }, {
1555                 .compatible = "boe,tv080wum-nl0",
1556                 .data = &boe_tv080wum_nl0
1557         }, {
1558                 .compatible = "lg,ld070wx3-sl01",
1559                 .data = &lg_ld070wx3_sl01
1560         }, {
1561                 .compatible = "lg,lh500wx1-sd03",
1562                 .data = &lg_lh500wx1_sd03
1563         }, {
1564                 .compatible = "panasonic,vvx10f004b00",
1565                 .data = &panasonic_vvx10f004b00
1566         }, {
1567                 /* sentinel */
1568         }
1569 };
1570 MODULE_DEVICE_TABLE(of, dsi_of_match);
1571
1572 static int panel_simple_dsi_probe(struct mipi_dsi_device *dsi)
1573 {
1574         const struct panel_desc_dsi *desc;
1575         const struct of_device_id *id;
1576         const struct panel_desc *pdesc;
1577         u32 val;
1578         int err;
1579
1580         id = of_match_node(dsi_of_match, dsi->dev.of_node);
1581         if (!id)
1582                 return -ENODEV;
1583
1584         desc = id->data;
1585
1586         if (desc) {
1587                 dsi->mode_flags = desc->flags;
1588                 dsi->format = desc->format;
1589                 dsi->lanes = desc->lanes;
1590                 pdesc = &desc->desc;
1591         } else {
1592                 pdesc = NULL;
1593         }
1594
1595         err = panel_simple_probe(&dsi->dev, pdesc);
1596         if (err < 0)
1597                 return err;
1598
1599         if (!of_property_read_u32(dsi->dev.of_node, "dsi,flags", &val))
1600                 dsi->mode_flags = val;
1601
1602         if (!of_property_read_u32(dsi->dev.of_node, "dsi,format", &val))
1603                 dsi->format = val;
1604
1605         if (!of_property_read_u32(dsi->dev.of_node, "dsi,lanes", &val))
1606                 dsi->lanes = val;
1607
1608         return mipi_dsi_attach(dsi);
1609 }
1610
1611 static int panel_simple_dsi_remove(struct mipi_dsi_device *dsi)
1612 {
1613         int err;
1614
1615         err = mipi_dsi_detach(dsi);
1616         if (err < 0)
1617                 dev_err(&dsi->dev, "failed to detach from DSI host: %d\n", err);
1618
1619         return panel_simple_remove(&dsi->dev);
1620 }
1621
1622 static void panel_simple_dsi_shutdown(struct mipi_dsi_device *dsi)
1623 {
1624         panel_simple_shutdown(&dsi->dev);
1625 }
1626
1627 static struct mipi_dsi_driver panel_simple_dsi_driver = {
1628         .driver = {
1629                 .name = "panel-simple-dsi",
1630                 .of_match_table = dsi_of_match,
1631         },
1632         .probe = panel_simple_dsi_probe,
1633         .remove = panel_simple_dsi_remove,
1634         .shutdown = panel_simple_dsi_shutdown,
1635 };
1636
1637 static int __init panel_simple_init(void)
1638 {
1639         int err;
1640
1641         err = platform_driver_register(&panel_simple_platform_driver);
1642         if (err < 0)
1643                 return err;
1644
1645         if (IS_ENABLED(CONFIG_DRM_MIPI_DSI)) {
1646                 err = mipi_dsi_driver_register(&panel_simple_dsi_driver);
1647                 if (err < 0)
1648                         return err;
1649         }
1650
1651         return 0;
1652 }
1653 module_init(panel_simple_init);
1654
1655 static void __exit panel_simple_exit(void)
1656 {
1657         if (IS_ENABLED(CONFIG_DRM_MIPI_DSI))
1658                 mipi_dsi_driver_unregister(&panel_simple_dsi_driver);
1659
1660         platform_driver_unregister(&panel_simple_platform_driver);
1661 }
1662 module_exit(panel_simple_exit);
1663
1664 MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
1665 MODULE_DESCRIPTION("DRM Driver for Simple Panels");
1666 MODULE_LICENSE("GPL and additional rights");