c7c5d15240a4fdd6049d878cc6e72220414b9427
[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_set_value_cansleep(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_set_value_cansleep(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",
333                                                      GPIOD_OUT_LOW);
334         if (IS_ERR(panel->enable_gpio)) {
335                 err = PTR_ERR(panel->enable_gpio);
336                 dev_err(dev, "failed to request GPIO: %d\n", err);
337                 return err;
338         }
339
340         backlight = of_parse_phandle(dev->of_node, "backlight", 0);
341         if (backlight) {
342                 panel->backlight = of_find_backlight_by_node(backlight);
343                 of_node_put(backlight);
344
345                 if (!panel->backlight)
346                         return -EPROBE_DEFER;
347         }
348
349         ddc = of_parse_phandle(dev->of_node, "ddc-i2c-bus", 0);
350         if (ddc) {
351                 panel->ddc = of_find_i2c_adapter_by_node(ddc);
352                 of_node_put(ddc);
353
354                 if (!panel->ddc) {
355                         err = -EPROBE_DEFER;
356                         goto free_backlight;
357                 }
358         }
359
360         drm_panel_init(&panel->base);
361         panel->base.dev = dev;
362         panel->base.funcs = &panel_simple_funcs;
363
364         err = drm_panel_add(&panel->base);
365         if (err < 0)
366                 goto free_ddc;
367
368         dev_set_drvdata(dev, panel);
369
370         return 0;
371
372 free_ddc:
373         if (panel->ddc)
374                 put_device(&panel->ddc->dev);
375 free_backlight:
376         if (panel->backlight)
377                 put_device(&panel->backlight->dev);
378
379         return err;
380 }
381
382 static int panel_simple_remove(struct device *dev)
383 {
384         struct panel_simple *panel = dev_get_drvdata(dev);
385
386         drm_panel_detach(&panel->base);
387         drm_panel_remove(&panel->base);
388
389         panel_simple_disable(&panel->base);
390
391         if (panel->ddc)
392                 put_device(&panel->ddc->dev);
393
394         if (panel->backlight)
395                 put_device(&panel->backlight->dev);
396
397         return 0;
398 }
399
400 static void panel_simple_shutdown(struct device *dev)
401 {
402         struct panel_simple *panel = dev_get_drvdata(dev);
403
404         panel_simple_disable(&panel->base);
405 }
406
407 static const struct drm_display_mode ampire_am800480r3tmqwa1h_mode = {
408         .clock = 33333,
409         .hdisplay = 800,
410         .hsync_start = 800 + 0,
411         .hsync_end = 800 + 0 + 255,
412         .htotal = 800 + 0 + 255 + 0,
413         .vdisplay = 480,
414         .vsync_start = 480 + 2,
415         .vsync_end = 480 + 2 + 45,
416         .vtotal = 480 + 2 + 45 + 0,
417         .vrefresh = 60,
418         .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC,
419 };
420
421 static const struct panel_desc ampire_am800480r3tmqwa1h = {
422         .modes = &ampire_am800480r3tmqwa1h_mode,
423         .num_modes = 1,
424         .bpc = 6,
425         .size = {
426                 .width = 152,
427                 .height = 91,
428         },
429         .bus_format = MEDIA_BUS_FMT_RGB666_1X18,
430 };
431
432 static const struct drm_display_mode auo_b101aw03_mode = {
433         .clock = 51450,
434         .hdisplay = 1024,
435         .hsync_start = 1024 + 156,
436         .hsync_end = 1024 + 156 + 8,
437         .htotal = 1024 + 156 + 8 + 156,
438         .vdisplay = 600,
439         .vsync_start = 600 + 16,
440         .vsync_end = 600 + 16 + 6,
441         .vtotal = 600 + 16 + 6 + 16,
442         .vrefresh = 60,
443 };
444
445 static const struct panel_desc auo_b101aw03 = {
446         .modes = &auo_b101aw03_mode,
447         .num_modes = 1,
448         .bpc = 6,
449         .size = {
450                 .width = 223,
451                 .height = 125,
452         },
453 };
454
455 static const struct drm_display_mode auo_b101ean01_mode = {
456         .clock = 72500,
457         .hdisplay = 1280,
458         .hsync_start = 1280 + 119,
459         .hsync_end = 1280 + 119 + 32,
460         .htotal = 1280 + 119 + 32 + 21,
461         .vdisplay = 800,
462         .vsync_start = 800 + 4,
463         .vsync_end = 800 + 4 + 20,
464         .vtotal = 800 + 4 + 20 + 8,
465         .vrefresh = 60,
466 };
467
468 static const struct panel_desc auo_b101ean01 = {
469         .modes = &auo_b101ean01_mode,
470         .num_modes = 1,
471         .bpc = 6,
472         .size = {
473                 .width = 217,
474                 .height = 136,
475         },
476 };
477
478 static const struct drm_display_mode auo_b101ew05_mode = {
479         .clock = 71000,
480         .hdisplay = 1280,
481         .hsync_start = 1280 + 18,
482         .hsync_end = 1280 + 18 + 10,
483         .htotal = 1280 + 18 + 10 + 100,
484         .vdisplay = 800,
485         .vsync_start = 800 + 6,
486         .vsync_end = 800 + 6 + 2,
487         .vtotal = 800 + 6 + 2 + 8,
488         .vrefresh = 60,
489 };
490
491 static const struct panel_desc auo_b101ew05 = {
492         .modes = &auo_b101ew05_mode,
493         .num_modes = 1,
494         .bpc = 6,
495         .size = {
496                 .width = 217,
497                 .height = 136,
498         },
499 };
500
501 static const struct drm_display_mode auo_b101xtn01_mode = {
502         .clock = 72000,
503         .hdisplay = 1366,
504         .hsync_start = 1366 + 20,
505         .hsync_end = 1366 + 20 + 70,
506         .htotal = 1366 + 20 + 70,
507         .vdisplay = 768,
508         .vsync_start = 768 + 14,
509         .vsync_end = 768 + 14 + 42,
510         .vtotal = 768 + 14 + 42,
511         .vrefresh = 60,
512         .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
513 };
514
515 static const struct panel_desc auo_b101xtn01 = {
516         .modes = &auo_b101xtn01_mode,
517         .num_modes = 1,
518         .bpc = 6,
519         .size = {
520                 .width = 223,
521                 .height = 125,
522         },
523 };
524
525 static const struct drm_display_mode auo_b116xw03_mode = {
526         .clock = 70589,
527         .hdisplay = 1366,
528         .hsync_start = 1366 + 40,
529         .hsync_end = 1366 + 40 + 40,
530         .htotal = 1366 + 40 + 40 + 32,
531         .vdisplay = 768,
532         .vsync_start = 768 + 10,
533         .vsync_end = 768 + 10 + 12,
534         .vtotal = 768 + 10 + 12 + 6,
535         .vrefresh = 60,
536 };
537
538 static const struct panel_desc auo_b116xw03 = {
539         .modes = &auo_b116xw03_mode,
540         .num_modes = 1,
541         .bpc = 6,
542         .size = {
543                 .width = 256,
544                 .height = 144,
545         },
546 };
547
548 static const struct drm_display_mode auo_b133xtn01_mode = {
549         .clock = 69500,
550         .hdisplay = 1366,
551         .hsync_start = 1366 + 48,
552         .hsync_end = 1366 + 48 + 32,
553         .htotal = 1366 + 48 + 32 + 20,
554         .vdisplay = 768,
555         .vsync_start = 768 + 3,
556         .vsync_end = 768 + 3 + 6,
557         .vtotal = 768 + 3 + 6 + 13,
558         .vrefresh = 60,
559 };
560
561 static const struct panel_desc auo_b133xtn01 = {
562         .modes = &auo_b133xtn01_mode,
563         .num_modes = 1,
564         .bpc = 6,
565         .size = {
566                 .width = 293,
567                 .height = 165,
568         },
569 };
570
571 static const struct drm_display_mode auo_b133htn01_mode = {
572         .clock = 150660,
573         .hdisplay = 1920,
574         .hsync_start = 1920 + 172,
575         .hsync_end = 1920 + 172 + 80,
576         .htotal = 1920 + 172 + 80 + 60,
577         .vdisplay = 1080,
578         .vsync_start = 1080 + 25,
579         .vsync_end = 1080 + 25 + 10,
580         .vtotal = 1080 + 25 + 10 + 10,
581         .vrefresh = 60,
582 };
583
584 static const struct panel_desc auo_b133htn01 = {
585         .modes = &auo_b133htn01_mode,
586         .num_modes = 1,
587         .bpc = 6,
588         .size = {
589                 .width = 293,
590                 .height = 165,
591         },
592         .delay = {
593                 .prepare = 105,
594                 .enable = 20,
595                 .unprepare = 50,
596         },
597 };
598
599 static const struct drm_display_mode avic_tm070ddh03_mode = {
600         .clock = 51200,
601         .hdisplay = 1024,
602         .hsync_start = 1024 + 160,
603         .hsync_end = 1024 + 160 + 4,
604         .htotal = 1024 + 160 + 4 + 156,
605         .vdisplay = 600,
606         .vsync_start = 600 + 17,
607         .vsync_end = 600 + 17 + 1,
608         .vtotal = 600 + 17 + 1 + 17,
609         .vrefresh = 60,
610 };
611
612 static const struct panel_desc avic_tm070ddh03 = {
613         .modes = &avic_tm070ddh03_mode,
614         .num_modes = 1,
615         .bpc = 8,
616         .size = {
617                 .width = 154,
618                 .height = 90,
619         },
620         .delay = {
621                 .prepare = 20,
622                 .enable = 200,
623                 .disable = 200,
624         },
625 };
626
627 static const struct drm_display_mode chunghwa_claa070wp03xg_mode = {
628         .clock = 67000,
629         .hdisplay = 800,
630         .hsync_start = 800 + 24,
631         .hsync_end = 800 + 24 + 16,
632         .htotal = 800 + 24 + 16 + 24,
633         .vdisplay = 1280,
634         .vsync_start = 1280 + 2,
635         .vsync_end = 1280 + 2 + 2,
636         .vtotal = 1280 + 2 + 2 + 4,
637         .vrefresh = 60,
638 };
639
640 static const struct panel_desc chunghwa_claa070wp03xg = {
641         .modes = &chunghwa_claa070wp03xg_mode,
642         .num_modes = 1,
643         .bpc = 6,
644         .size = {
645                 .width = 94,
646                 .height = 151,
647         },
648 };
649
650 static const struct drm_display_mode chunghwa_claa101wa01a_mode = {
651         .clock = 72070,
652         .hdisplay = 1366,
653         .hsync_start = 1366 + 58,
654         .hsync_end = 1366 + 58 + 58,
655         .htotal = 1366 + 58 + 58 + 58,
656         .vdisplay = 768,
657         .vsync_start = 768 + 4,
658         .vsync_end = 768 + 4 + 4,
659         .vtotal = 768 + 4 + 4 + 4,
660         .vrefresh = 60,
661 };
662
663 static const struct panel_desc chunghwa_claa101wa01a = {
664         .modes = &chunghwa_claa101wa01a_mode,
665         .num_modes = 1,
666         .bpc = 6,
667         .size = {
668                 .width = 220,
669                 .height = 120,
670         },
671 };
672
673 static const struct drm_display_mode chunghwa_claa101wb01_mode = {
674         .clock = 69300,
675         .hdisplay = 1366,
676         .hsync_start = 1366 + 48,
677         .hsync_end = 1366 + 48 + 32,
678         .htotal = 1366 + 48 + 32 + 20,
679         .vdisplay = 768,
680         .vsync_start = 768 + 16,
681         .vsync_end = 768 + 16 + 8,
682         .vtotal = 768 + 16 + 8 + 16,
683         .vrefresh = 60,
684 };
685
686 static const struct panel_desc chunghwa_claa101wb01 = {
687         .modes = &chunghwa_claa101wb01_mode,
688         .num_modes = 1,
689         .bpc = 6,
690         .size = {
691                 .width = 223,
692                 .height = 125,
693         },
694 };
695
696 static const struct drm_display_mode edt_et057090dhu_mode = {
697         .clock = 25175,
698         .hdisplay = 640,
699         .hsync_start = 640 + 16,
700         .hsync_end = 640 + 16 + 30,
701         .htotal = 640 + 16 + 30 + 114,
702         .vdisplay = 480,
703         .vsync_start = 480 + 10,
704         .vsync_end = 480 + 10 + 3,
705         .vtotal = 480 + 10 + 3 + 32,
706         .vrefresh = 60,
707         .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
708 };
709
710 static const struct panel_desc edt_et057090dhu = {
711         .modes = &edt_et057090dhu_mode,
712         .num_modes = 1,
713         .bpc = 6,
714         .size = {
715                 .width = 115,
716                 .height = 86,
717         },
718 };
719
720 static const struct drm_display_mode edt_etm0700g0dh6_mode = {
721         .clock = 33260,
722         .hdisplay = 800,
723         .hsync_start = 800 + 40,
724         .hsync_end = 800 + 40 + 128,
725         .htotal = 800 + 40 + 128 + 88,
726         .vdisplay = 480,
727         .vsync_start = 480 + 10,
728         .vsync_end = 480 + 10 + 2,
729         .vtotal = 480 + 10 + 2 + 33,
730         .vrefresh = 60,
731         .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
732 };
733
734 static const struct panel_desc edt_etm0700g0dh6 = {
735         .modes = &edt_etm0700g0dh6_mode,
736         .num_modes = 1,
737         .bpc = 6,
738         .size = {
739                 .width = 152,
740                 .height = 91,
741         },
742 };
743
744 static const struct drm_display_mode foxlink_fl500wvr00_a0t_mode = {
745         .clock = 32260,
746         .hdisplay = 800,
747         .hsync_start = 800 + 168,
748         .hsync_end = 800 + 168 + 64,
749         .htotal = 800 + 168 + 64 + 88,
750         .vdisplay = 480,
751         .vsync_start = 480 + 37,
752         .vsync_end = 480 + 37 + 2,
753         .vtotal = 480 + 37 + 2 + 8,
754         .vrefresh = 60,
755 };
756
757 static const struct panel_desc foxlink_fl500wvr00_a0t = {
758         .modes = &foxlink_fl500wvr00_a0t_mode,
759         .num_modes = 1,
760         .bpc = 8,
761         .size = {
762                 .width = 108,
763                 .height = 65,
764         },
765         .bus_format = MEDIA_BUS_FMT_RGB888_1X24,
766 };
767
768 static const struct drm_display_mode giantplus_gpg482739qs5_mode = {
769         .clock = 9000,
770         .hdisplay = 480,
771         .hsync_start = 480 + 5,
772         .hsync_end = 480 + 5 + 1,
773         .htotal = 480 + 5 + 1 + 40,
774         .vdisplay = 272,
775         .vsync_start = 272 + 8,
776         .vsync_end = 272 + 8 + 1,
777         .vtotal = 272 + 8 + 1 + 8,
778         .vrefresh = 60,
779 };
780
781 static const struct panel_desc giantplus_gpg482739qs5 = {
782         .modes = &giantplus_gpg482739qs5_mode,
783         .num_modes = 1,
784         .bpc = 8,
785         .size = {
786                 .width = 95,
787                 .height = 54,
788         },
789         .bus_format = MEDIA_BUS_FMT_RGB888_1X24,
790 };
791
792 static const struct display_timing hannstar_hsd070pww1_timing = {
793         .pixelclock = { 64300000, 71100000, 82000000 },
794         .hactive = { 1280, 1280, 1280 },
795         .hfront_porch = { 1, 1, 10 },
796         .hback_porch = { 1, 1, 10 },
797         /*
798          * According to the data sheet, the minimum horizontal blanking interval
799          * is 54 clocks (1 + 52 + 1), but tests with a Nitrogen6X have shown the
800          * minimum working horizontal blanking interval to be 60 clocks.
801          */
802         .hsync_len = { 58, 158, 661 },
803         .vactive = { 800, 800, 800 },
804         .vfront_porch = { 1, 1, 10 },
805         .vback_porch = { 1, 1, 10 },
806         .vsync_len = { 1, 21, 203 },
807         .flags = DISPLAY_FLAGS_DE_HIGH,
808 };
809
810 static const struct panel_desc hannstar_hsd070pww1 = {
811         .timings = &hannstar_hsd070pww1_timing,
812         .num_timings = 1,
813         .bpc = 6,
814         .size = {
815                 .width = 151,
816                 .height = 94,
817         },
818         .bus_format = MEDIA_BUS_FMT_RGB666_1X7X3_SPWG,
819 };
820
821 static const struct display_timing hannstar_hsd100pxn1_timing = {
822         .pixelclock = { 55000000, 65000000, 75000000 },
823         .hactive = { 1024, 1024, 1024 },
824         .hfront_porch = { 40, 40, 40 },
825         .hback_porch = { 220, 220, 220 },
826         .hsync_len = { 20, 60, 100 },
827         .vactive = { 768, 768, 768 },
828         .vfront_porch = { 7, 7, 7 },
829         .vback_porch = { 21, 21, 21 },
830         .vsync_len = { 10, 10, 10 },
831         .flags = DISPLAY_FLAGS_DE_HIGH,
832 };
833
834 static const struct panel_desc hannstar_hsd100pxn1 = {
835         .timings = &hannstar_hsd100pxn1_timing,
836         .num_timings = 1,
837         .bpc = 6,
838         .size = {
839                 .width = 203,
840                 .height = 152,
841         },
842         .bus_format = MEDIA_BUS_FMT_RGB666_1X7X3_SPWG,
843 };
844
845 static const struct drm_display_mode hitachi_tx23d38vm0caa_mode = {
846         .clock = 33333,
847         .hdisplay = 800,
848         .hsync_start = 800 + 85,
849         .hsync_end = 800 + 85 + 86,
850         .htotal = 800 + 85 + 86 + 85,
851         .vdisplay = 480,
852         .vsync_start = 480 + 16,
853         .vsync_end = 480 + 16 + 13,
854         .vtotal = 480 + 16 + 13 + 16,
855         .vrefresh = 60,
856 };
857
858 static const struct panel_desc hitachi_tx23d38vm0caa = {
859         .modes = &hitachi_tx23d38vm0caa_mode,
860         .num_modes = 1,
861         .bpc = 6,
862         .size = {
863                 .width = 195,
864                 .height = 117,
865         },
866 };
867
868 static const struct drm_display_mode innolux_at043tn24_mode = {
869         .clock = 9000,
870         .hdisplay = 480,
871         .hsync_start = 480 + 2,
872         .hsync_end = 480 + 2 + 41,
873         .htotal = 480 + 2 + 41 + 2,
874         .vdisplay = 272,
875         .vsync_start = 272 + 2,
876         .vsync_end = 272 + 2 + 11,
877         .vtotal = 272 + 2 + 11 + 2,
878         .vrefresh = 60,
879         .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
880 };
881
882 static const struct panel_desc innolux_at043tn24 = {
883         .modes = &innolux_at043tn24_mode,
884         .num_modes = 1,
885         .bpc = 8,
886         .size = {
887                 .width = 95,
888                 .height = 54,
889         },
890         .bus_format = MEDIA_BUS_FMT_RGB888_1X24,
891 };
892
893 static const struct drm_display_mode innolux_g121i1_l01_mode = {
894         .clock = 71000,
895         .hdisplay = 1280,
896         .hsync_start = 1280 + 64,
897         .hsync_end = 1280 + 64 + 32,
898         .htotal = 1280 + 64 + 32 + 64,
899         .vdisplay = 800,
900         .vsync_start = 800 + 9,
901         .vsync_end = 800 + 9 + 6,
902         .vtotal = 800 + 9 + 6 + 9,
903         .vrefresh = 60,
904 };
905
906 static const struct panel_desc innolux_g121i1_l01 = {
907         .modes = &innolux_g121i1_l01_mode,
908         .num_modes = 1,
909         .bpc = 6,
910         .size = {
911                 .width = 261,
912                 .height = 163,
913         },
914 };
915
916 static const struct drm_display_mode innolux_n116bge_mode = {
917         .clock = 76420,
918         .hdisplay = 1366,
919         .hsync_start = 1366 + 136,
920         .hsync_end = 1366 + 136 + 30,
921         .htotal = 1366 + 136 + 30 + 60,
922         .vdisplay = 768,
923         .vsync_start = 768 + 8,
924         .vsync_end = 768 + 8 + 12,
925         .vtotal = 768 + 8 + 12 + 12,
926         .vrefresh = 60,
927         .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
928 };
929
930 static const struct panel_desc innolux_n116bge = {
931         .modes = &innolux_n116bge_mode,
932         .num_modes = 1,
933         .bpc = 6,
934         .size = {
935                 .width = 256,
936                 .height = 144,
937         },
938 };
939
940 static const struct drm_display_mode innolux_n156bge_l21_mode = {
941         .clock = 69300,
942         .hdisplay = 1366,
943         .hsync_start = 1366 + 16,
944         .hsync_end = 1366 + 16 + 34,
945         .htotal = 1366 + 16 + 34 + 50,
946         .vdisplay = 768,
947         .vsync_start = 768 + 2,
948         .vsync_end = 768 + 2 + 6,
949         .vtotal = 768 + 2 + 6 + 12,
950         .vrefresh = 60,
951 };
952
953 static const struct panel_desc innolux_n156bge_l21 = {
954         .modes = &innolux_n156bge_l21_mode,
955         .num_modes = 1,
956         .bpc = 6,
957         .size = {
958                 .width = 344,
959                 .height = 193,
960         },
961 };
962
963 static const struct drm_display_mode innolux_zj070na_01p_mode = {
964         .clock = 51501,
965         .hdisplay = 1024,
966         .hsync_start = 1024 + 128,
967         .hsync_end = 1024 + 128 + 64,
968         .htotal = 1024 + 128 + 64 + 128,
969         .vdisplay = 600,
970         .vsync_start = 600 + 16,
971         .vsync_end = 600 + 16 + 4,
972         .vtotal = 600 + 16 + 4 + 16,
973         .vrefresh = 60,
974 };
975
976 static const struct panel_desc innolux_zj070na_01p = {
977         .modes = &innolux_zj070na_01p_mode,
978         .num_modes = 1,
979         .bpc = 6,
980         .size = {
981                 .width = 1024,
982                 .height = 600,
983         },
984 };
985
986 static const struct drm_display_mode lg_lb070wv8_mode = {
987         .clock = 33246,
988         .hdisplay = 800,
989         .hsync_start = 800 + 88,
990         .hsync_end = 800 + 88 + 80,
991         .htotal = 800 + 88 + 80 + 88,
992         .vdisplay = 480,
993         .vsync_start = 480 + 10,
994         .vsync_end = 480 + 10 + 25,
995         .vtotal = 480 + 10 + 25 + 10,
996         .vrefresh = 60,
997 };
998
999 static const struct panel_desc lg_lb070wv8 = {
1000         .modes = &lg_lb070wv8_mode,
1001         .num_modes = 1,
1002         .bpc = 16,
1003         .size = {
1004                 .width = 151,
1005                 .height = 91,
1006         },
1007         .bus_format = MEDIA_BUS_FMT_RGB888_1X7X4_SPWG,
1008 };
1009
1010 static const struct drm_display_mode lg_lp079qx1_sp0v_mode = {
1011         .clock = 200000,
1012         .hdisplay = 1536,
1013         .hsync_start = 1536 + 12,
1014         .hsync_end = 1536 + 12 + 16,
1015         .htotal = 1536 + 12 + 16 + 48,
1016         .vdisplay = 2048,
1017         .vsync_start = 2048 + 8,
1018         .vsync_end = 2048 + 8 + 4,
1019         .vtotal = 2048 + 8 + 4 + 8,
1020         .vrefresh = 60,
1021         .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
1022 };
1023
1024 static const struct panel_desc lg_lp079qx1_sp0v = {
1025         .modes = &lg_lp079qx1_sp0v_mode,
1026         .num_modes = 1,
1027         .size = {
1028                 .width = 129,
1029                 .height = 171,
1030         },
1031 };
1032
1033 static const struct drm_display_mode lg_lp097qx1_spa1_mode = {
1034         .clock = 205210,
1035         .hdisplay = 2048,
1036         .hsync_start = 2048 + 150,
1037         .hsync_end = 2048 + 150 + 5,
1038         .htotal = 2048 + 150 + 5 + 5,
1039         .vdisplay = 1536,
1040         .vsync_start = 1536 + 3,
1041         .vsync_end = 1536 + 3 + 1,
1042         .vtotal = 1536 + 3 + 1 + 9,
1043         .vrefresh = 60,
1044 };
1045
1046 static const struct panel_desc lg_lp097qx1_spa1 = {
1047         .modes = &lg_lp097qx1_spa1_mode,
1048         .num_modes = 1,
1049         .size = {
1050                 .width = 320,
1051                 .height = 187,
1052         },
1053 };
1054
1055 static const struct drm_display_mode lg_lp129qe_mode = {
1056         .clock = 285250,
1057         .hdisplay = 2560,
1058         .hsync_start = 2560 + 48,
1059         .hsync_end = 2560 + 48 + 32,
1060         .htotal = 2560 + 48 + 32 + 80,
1061         .vdisplay = 1700,
1062         .vsync_start = 1700 + 3,
1063         .vsync_end = 1700 + 3 + 10,
1064         .vtotal = 1700 + 3 + 10 + 36,
1065         .vrefresh = 60,
1066 };
1067
1068 static const struct panel_desc lg_lp129qe = {
1069         .modes = &lg_lp129qe_mode,
1070         .num_modes = 1,
1071         .bpc = 8,
1072         .size = {
1073                 .width = 272,
1074                 .height = 181,
1075         },
1076 };
1077
1078 static const struct drm_display_mode nec_nl4827hc19_05b_mode = {
1079         .clock = 10870,
1080         .hdisplay = 480,
1081         .hsync_start = 480 + 2,
1082         .hsync_end = 480 + 2 + 41,
1083         .htotal = 480 + 2 + 41 + 2,
1084         .vdisplay = 272,
1085         .vsync_start = 272 + 2,
1086         .vsync_end = 272 + 2 + 4,
1087         .vtotal = 272 + 2 + 4 + 2,
1088         .vrefresh = 74,
1089 };
1090
1091 static const struct panel_desc nec_nl4827hc19_05b = {
1092         .modes = &nec_nl4827hc19_05b_mode,
1093         .num_modes = 1,
1094         .bpc = 8,
1095         .size = {
1096                 .width = 95,
1097                 .height = 54,
1098         },
1099         .bus_format = MEDIA_BUS_FMT_RGB888_1X24
1100 };
1101
1102 static const struct display_timing okaya_rs800480t_7x0gp_timing = {
1103         .pixelclock = { 30000000, 30000000, 40000000 },
1104         .hactive = { 800, 800, 800 },
1105         .hfront_porch = { 40, 40, 40 },
1106         .hback_porch = { 40, 40, 40 },
1107         .hsync_len = { 1, 48, 48 },
1108         .vactive = { 480, 480, 480 },
1109         .vfront_porch = { 13, 13, 13 },
1110         .vback_porch = { 29, 29, 29 },
1111         .vsync_len = { 3, 3, 3 },
1112         .flags = DISPLAY_FLAGS_DE_HIGH,
1113 };
1114
1115 static const struct panel_desc okaya_rs800480t_7x0gp = {
1116         .timings = &okaya_rs800480t_7x0gp_timing,
1117         .num_timings = 1,
1118         .bpc = 6,
1119         .size = {
1120                 .width = 154,
1121                 .height = 87,
1122         },
1123         .delay = {
1124                 .prepare = 41,
1125                 .enable = 50,
1126                 .unprepare = 41,
1127                 .disable = 50,
1128         },
1129         .bus_format = MEDIA_BUS_FMT_RGB666_1X18,
1130 };
1131
1132 static const struct drm_display_mode ortustech_com43h4m85ulc_mode  = {
1133         .clock = 25000,
1134         .hdisplay = 480,
1135         .hsync_start = 480 + 10,
1136         .hsync_end = 480 + 10 + 10,
1137         .htotal = 480 + 10 + 10 + 15,
1138         .vdisplay = 800,
1139         .vsync_start = 800 + 3,
1140         .vsync_end = 800 + 3 + 3,
1141         .vtotal = 800 + 3 + 3 + 3,
1142         .vrefresh = 60,
1143 };
1144
1145 static const struct panel_desc ortustech_com43h4m85ulc = {
1146         .modes = &ortustech_com43h4m85ulc_mode,
1147         .num_modes = 1,
1148         .bpc = 8,
1149         .size = {
1150                 .width = 56,
1151                 .height = 93,
1152         },
1153         .bus_format = MEDIA_BUS_FMT_RGB888_1X24,
1154 };
1155
1156 static const struct drm_display_mode samsung_lsn122dl01_c01_mode = {
1157         .clock = 271560,
1158         .hdisplay = 2560,
1159         .hsync_start = 2560 + 48,
1160         .hsync_end = 2560 + 48 + 32,
1161         .htotal = 2560 + 48 + 32 + 80,
1162         .vdisplay = 1600,
1163         .vsync_start = 1600 + 2,
1164         .vsync_end = 1600 + 2 + 5,
1165         .vtotal = 1600 + 2 + 5 + 57,
1166         .vrefresh = 60,
1167 };
1168
1169 static const struct panel_desc samsung_lsn122dl01_c01 = {
1170         .modes = &samsung_lsn122dl01_c01_mode,
1171         .num_modes = 1,
1172         .size = {
1173                 .width = 2560,
1174                 .height = 1600,
1175         },
1176 };
1177
1178 static const struct drm_display_mode samsung_ltn101nt05_mode = {
1179         .clock = 54030,
1180         .hdisplay = 1024,
1181         .hsync_start = 1024 + 24,
1182         .hsync_end = 1024 + 24 + 136,
1183         .htotal = 1024 + 24 + 136 + 160,
1184         .vdisplay = 600,
1185         .vsync_start = 600 + 3,
1186         .vsync_end = 600 + 3 + 6,
1187         .vtotal = 600 + 3 + 6 + 61,
1188         .vrefresh = 60,
1189 };
1190
1191 static const struct panel_desc samsung_ltn101nt05 = {
1192         .modes = &samsung_ltn101nt05_mode,
1193         .num_modes = 1,
1194         .bpc = 6,
1195         .size = {
1196                 .width = 1024,
1197                 .height = 600,
1198         },
1199 };
1200
1201 static const struct drm_display_mode samsung_ltn140at29_301_mode = {
1202         .clock = 76300,
1203         .hdisplay = 1366,
1204         .hsync_start = 1366 + 64,
1205         .hsync_end = 1366 + 64 + 48,
1206         .htotal = 1366 + 64 + 48 + 128,
1207         .vdisplay = 768,
1208         .vsync_start = 768 + 2,
1209         .vsync_end = 768 + 2 + 5,
1210         .vtotal = 768 + 2 + 5 + 17,
1211         .vrefresh = 60,
1212 };
1213
1214 static const struct panel_desc samsung_ltn140at29_301 = {
1215         .modes = &samsung_ltn140at29_301_mode,
1216         .num_modes = 1,
1217         .bpc = 6,
1218         .size = {
1219                 .width = 320,
1220                 .height = 187,
1221         },
1222 };
1223
1224 static const struct drm_display_mode shelly_sca07010_bfn_lnn_mode = {
1225         .clock = 33300,
1226         .hdisplay = 800,
1227         .hsync_start = 800 + 1,
1228         .hsync_end = 800 + 1 + 64,
1229         .htotal = 800 + 1 + 64 + 64,
1230         .vdisplay = 480,
1231         .vsync_start = 480 + 1,
1232         .vsync_end = 480 + 1 + 23,
1233         .vtotal = 480 + 1 + 23 + 22,
1234         .vrefresh = 60,
1235 };
1236
1237 static const struct panel_desc shelly_sca07010_bfn_lnn = {
1238         .modes = &shelly_sca07010_bfn_lnn_mode,
1239         .num_modes = 1,
1240         .size = {
1241                 .width = 152,
1242                 .height = 91,
1243         },
1244         .bus_format = MEDIA_BUS_FMT_RGB666_1X18,
1245 };
1246
1247 static const struct of_device_id platform_of_match[] = {
1248         {
1249                 .compatible = "simple-panel",
1250                 .data = NULL,
1251         }, {
1252                 .compatible = "ampire,am800480r3tmqwa1h",
1253                 .data = &ampire_am800480r3tmqwa1h,
1254         }, {
1255                 .compatible = "auo,b101aw03",
1256                 .data = &auo_b101aw03,
1257         }, {
1258                 .compatible = "auo,b101ean01",
1259                 .data = &auo_b101ean01,
1260         }, {
1261                 .compatible = "auo,b101ew05",
1262                 .data = &auo_b101ew05,
1263         }, {
1264                 .compatible = "auo,b101xtn01",
1265                 .data = &auo_b101xtn01,
1266         }, {
1267                 .compatible = "auo,b116xw03",
1268                 .data = &auo_b116xw03,
1269         }, {
1270                 .compatible = "auo,b133htn01",
1271                 .data = &auo_b133htn01,
1272         }, {
1273                 .compatible = "auo,b133xtn01",
1274                 .data = &auo_b133xtn01,
1275         }, {
1276                 .compatible = "avic,tm070ddh03",
1277                 .data = &avic_tm070ddh03,
1278         }, {
1279                 .compatible = "chunghwa,claa070wp03xg",
1280                 .data = &chunghwa_claa070wp03xg,
1281         }, {
1282                 .compatible = "chunghwa,claa101wa01a",
1283                 .data = &chunghwa_claa101wa01a
1284         }, {
1285                 .compatible = "chunghwa,claa101wb01",
1286                 .data = &chunghwa_claa101wb01
1287         }, {
1288                 .compatible = "edt,et057090dhu",
1289                 .data = &edt_et057090dhu,
1290         }, {
1291                 .compatible = "edt,et070080dh6",
1292                 .data = &edt_etm0700g0dh6,
1293         }, {
1294                 .compatible = "edt,etm0700g0dh6",
1295                 .data = &edt_etm0700g0dh6,
1296         }, {
1297                 .compatible = "foxlink,fl500wvr00-a0t",
1298                 .data = &foxlink_fl500wvr00_a0t,
1299         }, {
1300                 .compatible = "giantplus,gpg482739qs5",
1301                 .data = &giantplus_gpg482739qs5
1302         }, {
1303                 .compatible = "hannstar,hsd070pww1",
1304                 .data = &hannstar_hsd070pww1,
1305         }, {
1306                 .compatible = "hannstar,hsd100pxn1",
1307                 .data = &hannstar_hsd100pxn1,
1308         }, {
1309                 .compatible = "hit,tx23d38vm0caa",
1310                 .data = &hitachi_tx23d38vm0caa
1311         }, {
1312                 .compatible = "innolux,at043tn24",
1313                 .data = &innolux_at043tn24,
1314         }, {
1315                 .compatible ="innolux,g121i1-l01",
1316                 .data = &innolux_g121i1_l01
1317         }, {
1318                 .compatible = "innolux,n116bge",
1319                 .data = &innolux_n116bge,
1320         }, {
1321                 .compatible = "innolux,n156bge-l21",
1322                 .data = &innolux_n156bge_l21,
1323         }, {
1324                 .compatible = "innolux,zj070na-01p",
1325                 .data = &innolux_zj070na_01p,
1326         }, {
1327                 .compatible = "lg,lb070wv8",
1328                 .data = &lg_lb070wv8,
1329         }, {
1330                 .compatible = "lg,lp079qx1-sp0v",
1331                 .data = &lg_lp079qx1_sp0v,
1332         }, {
1333                 .compatible = "lg,lp097qx1-spa1",
1334                 .data = &lg_lp097qx1_spa1,
1335         }, {
1336                 .compatible = "lg,lp129qe",
1337                 .data = &lg_lp129qe,
1338         }, {
1339                 .compatible = "nec,nl4827hc19-05b",
1340                 .data = &nec_nl4827hc19_05b,
1341         }, {
1342                 .compatible = "okaya,rs800480t-7x0gp",
1343                 .data = &okaya_rs800480t_7x0gp,
1344         }, {
1345                 .compatible = "ortustech,com43h4m85ulc",
1346                 .data = &ortustech_com43h4m85ulc,
1347         }, {
1348                 .compatible = "samsung,lsn122dl01-c01",
1349                 .data = &samsung_lsn122dl01_c01,
1350         }, {
1351                 .compatible = "samsung,ltn101nt05",
1352                 .data = &samsung_ltn101nt05,
1353         }, {
1354                 .compatible = "samsung,ltn140at29-301",
1355                 .data = &samsung_ltn140at29_301,
1356         }, {
1357                 .compatible = "shelly,sca07010-bfn-lnn",
1358                 .data = &shelly_sca07010_bfn_lnn,
1359         }, {
1360                 /* sentinel */
1361         }
1362 };
1363 MODULE_DEVICE_TABLE(of, platform_of_match);
1364
1365 static int panel_simple_platform_probe(struct platform_device *pdev)
1366 {
1367         const struct of_device_id *id;
1368
1369         id = of_match_node(platform_of_match, pdev->dev.of_node);
1370         if (!id)
1371                 return -ENODEV;
1372
1373         return panel_simple_probe(&pdev->dev, id->data);
1374 }
1375
1376 static int panel_simple_platform_remove(struct platform_device *pdev)
1377 {
1378         return panel_simple_remove(&pdev->dev);
1379 }
1380
1381 static void panel_simple_platform_shutdown(struct platform_device *pdev)
1382 {
1383         panel_simple_shutdown(&pdev->dev);
1384 }
1385
1386 static struct platform_driver panel_simple_platform_driver = {
1387         .driver = {
1388                 .name = "panel-simple",
1389                 .of_match_table = platform_of_match,
1390         },
1391         .probe = panel_simple_platform_probe,
1392         .remove = panel_simple_platform_remove,
1393         .shutdown = panel_simple_platform_shutdown,
1394 };
1395
1396 struct panel_desc_dsi {
1397         struct panel_desc desc;
1398
1399         unsigned long flags;
1400         enum mipi_dsi_pixel_format format;
1401         unsigned int lanes;
1402 };
1403
1404 static const struct drm_display_mode auo_b080uan01_mode = {
1405         .clock = 154500,
1406         .hdisplay = 1200,
1407         .hsync_start = 1200 + 62,
1408         .hsync_end = 1200 + 62 + 4,
1409         .htotal = 1200 + 62 + 4 + 62,
1410         .vdisplay = 1920,
1411         .vsync_start = 1920 + 9,
1412         .vsync_end = 1920 + 9 + 2,
1413         .vtotal = 1920 + 9 + 2 + 8,
1414         .vrefresh = 60,
1415 };
1416
1417 static const struct panel_desc_dsi auo_b080uan01 = {
1418         .desc = {
1419                 .modes = &auo_b080uan01_mode,
1420                 .num_modes = 1,
1421                 .bpc = 8,
1422                 .size = {
1423                         .width = 108,
1424                         .height = 272,
1425                 },
1426         },
1427         .flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_CLOCK_NON_CONTINUOUS,
1428         .format = MIPI_DSI_FMT_RGB888,
1429         .lanes = 4,
1430 };
1431
1432 static const struct drm_display_mode boe_tv080wum_nl0_mode = {
1433         .clock = 160000,
1434         .hdisplay = 1200,
1435         .hsync_start = 1200 + 120,
1436         .hsync_end = 1200 + 120 + 20,
1437         .htotal = 1200 + 120 + 20 + 21,
1438         .vdisplay = 1920,
1439         .vsync_start = 1920 + 21,
1440         .vsync_end = 1920 + 21 + 3,
1441         .vtotal = 1920 + 21 + 3 + 18,
1442         .vrefresh = 60,
1443         .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
1444 };
1445
1446 static const struct panel_desc_dsi boe_tv080wum_nl0 = {
1447         .desc = {
1448                 .modes = &boe_tv080wum_nl0_mode,
1449                 .num_modes = 1,
1450                 .size = {
1451                         .width = 107,
1452                         .height = 172,
1453                 },
1454         },
1455         .flags = MIPI_DSI_MODE_VIDEO |
1456                  MIPI_DSI_MODE_VIDEO_BURST |
1457                  MIPI_DSI_MODE_VIDEO_SYNC_PULSE,
1458         .format = MIPI_DSI_FMT_RGB888,
1459         .lanes = 4,
1460 };
1461
1462 static const struct drm_display_mode lg_ld070wx3_sl01_mode = {
1463         .clock = 71000,
1464         .hdisplay = 800,
1465         .hsync_start = 800 + 32,
1466         .hsync_end = 800 + 32 + 1,
1467         .htotal = 800 + 32 + 1 + 57,
1468         .vdisplay = 1280,
1469         .vsync_start = 1280 + 28,
1470         .vsync_end = 1280 + 28 + 1,
1471         .vtotal = 1280 + 28 + 1 + 14,
1472         .vrefresh = 60,
1473 };
1474
1475 static const struct panel_desc_dsi lg_ld070wx3_sl01 = {
1476         .desc = {
1477                 .modes = &lg_ld070wx3_sl01_mode,
1478                 .num_modes = 1,
1479                 .bpc = 8,
1480                 .size = {
1481                         .width = 94,
1482                         .height = 151,
1483                 },
1484         },
1485         .flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_CLOCK_NON_CONTINUOUS,
1486         .format = MIPI_DSI_FMT_RGB888,
1487         .lanes = 4,
1488 };
1489
1490 static const struct drm_display_mode lg_lh500wx1_sd03_mode = {
1491         .clock = 67000,
1492         .hdisplay = 720,
1493         .hsync_start = 720 + 12,
1494         .hsync_end = 720 + 12 + 4,
1495         .htotal = 720 + 12 + 4 + 112,
1496         .vdisplay = 1280,
1497         .vsync_start = 1280 + 8,
1498         .vsync_end = 1280 + 8 + 4,
1499         .vtotal = 1280 + 8 + 4 + 12,
1500         .vrefresh = 60,
1501 };
1502
1503 static const struct panel_desc_dsi lg_lh500wx1_sd03 = {
1504         .desc = {
1505                 .modes = &lg_lh500wx1_sd03_mode,
1506                 .num_modes = 1,
1507                 .bpc = 8,
1508                 .size = {
1509                         .width = 62,
1510                         .height = 110,
1511                 },
1512         },
1513         .flags = MIPI_DSI_MODE_VIDEO,
1514         .format = MIPI_DSI_FMT_RGB888,
1515         .lanes = 4,
1516 };
1517
1518 static const struct drm_display_mode panasonic_vvx10f004b00_mode = {
1519         .clock = 157200,
1520         .hdisplay = 1920,
1521         .hsync_start = 1920 + 154,
1522         .hsync_end = 1920 + 154 + 16,
1523         .htotal = 1920 + 154 + 16 + 32,
1524         .vdisplay = 1200,
1525         .vsync_start = 1200 + 17,
1526         .vsync_end = 1200 + 17 + 2,
1527         .vtotal = 1200 + 17 + 2 + 16,
1528         .vrefresh = 60,
1529 };
1530
1531 static const struct panel_desc_dsi panasonic_vvx10f004b00 = {
1532         .desc = {
1533                 .modes = &panasonic_vvx10f004b00_mode,
1534                 .num_modes = 1,
1535                 .bpc = 8,
1536                 .size = {
1537                         .width = 217,
1538                         .height = 136,
1539                 },
1540         },
1541         .flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE |
1542                  MIPI_DSI_CLOCK_NON_CONTINUOUS,
1543         .format = MIPI_DSI_FMT_RGB888,
1544         .lanes = 4,
1545 };
1546
1547
1548 static const struct of_device_id dsi_of_match[] = {
1549         {
1550                 .compatible = "simple-panel-dsi",
1551                 .data = NULL
1552         }, {
1553                 .compatible = "auo,b080uan01",
1554                 .data = &auo_b080uan01
1555         }, {
1556                 .compatible = "boe,tv080wum-nl0",
1557                 .data = &boe_tv080wum_nl0
1558         }, {
1559                 .compatible = "lg,ld070wx3-sl01",
1560                 .data = &lg_ld070wx3_sl01
1561         }, {
1562                 .compatible = "lg,lh500wx1-sd03",
1563                 .data = &lg_lh500wx1_sd03
1564         }, {
1565                 .compatible = "panasonic,vvx10f004b00",
1566                 .data = &panasonic_vvx10f004b00
1567         }, {
1568                 /* sentinel */
1569         }
1570 };
1571 MODULE_DEVICE_TABLE(of, dsi_of_match);
1572
1573 static int panel_simple_dsi_probe(struct mipi_dsi_device *dsi)
1574 {
1575         const struct panel_desc_dsi *desc;
1576         const struct of_device_id *id;
1577         const struct panel_desc *pdesc;
1578         u32 val;
1579         int err;
1580
1581         id = of_match_node(dsi_of_match, dsi->dev.of_node);
1582         if (!id)
1583                 return -ENODEV;
1584
1585         desc = id->data;
1586
1587         if (desc) {
1588                 dsi->mode_flags = desc->flags;
1589                 dsi->format = desc->format;
1590                 dsi->lanes = desc->lanes;
1591                 pdesc = &desc->desc;
1592         } else {
1593                 pdesc = NULL;
1594         }
1595
1596         err = panel_simple_probe(&dsi->dev, pdesc);
1597         if (err < 0)
1598                 return err;
1599
1600         if (!of_property_read_u32(dsi->dev.of_node, "dsi,flags", &val))
1601                 dsi->mode_flags = val;
1602
1603         if (!of_property_read_u32(dsi->dev.of_node, "dsi,format", &val))
1604                 dsi->format = val;
1605
1606         if (!of_property_read_u32(dsi->dev.of_node, "dsi,lanes", &val))
1607                 dsi->lanes = val;
1608
1609         return mipi_dsi_attach(dsi);
1610 }
1611
1612 static int panel_simple_dsi_remove(struct mipi_dsi_device *dsi)
1613 {
1614         int err;
1615
1616         err = mipi_dsi_detach(dsi);
1617         if (err < 0)
1618                 dev_err(&dsi->dev, "failed to detach from DSI host: %d\n", err);
1619
1620         return panel_simple_remove(&dsi->dev);
1621 }
1622
1623 static void panel_simple_dsi_shutdown(struct mipi_dsi_device *dsi)
1624 {
1625         panel_simple_shutdown(&dsi->dev);
1626 }
1627
1628 static struct mipi_dsi_driver panel_simple_dsi_driver = {
1629         .driver = {
1630                 .name = "panel-simple-dsi",
1631                 .of_match_table = dsi_of_match,
1632         },
1633         .probe = panel_simple_dsi_probe,
1634         .remove = panel_simple_dsi_remove,
1635         .shutdown = panel_simple_dsi_shutdown,
1636 };
1637
1638 static int __init panel_simple_init(void)
1639 {
1640         int err;
1641
1642         err = platform_driver_register(&panel_simple_platform_driver);
1643         if (err < 0)
1644                 return err;
1645
1646         if (IS_ENABLED(CONFIG_DRM_MIPI_DSI)) {
1647                 err = mipi_dsi_driver_register(&panel_simple_dsi_driver);
1648                 if (err < 0)
1649                         return err;
1650         }
1651
1652         return 0;
1653 }
1654 module_init(panel_simple_init);
1655
1656 static void __exit panel_simple_exit(void)
1657 {
1658         if (IS_ENABLED(CONFIG_DRM_MIPI_DSI))
1659                 mipi_dsi_driver_unregister(&panel_simple_dsi_driver);
1660
1661         platform_driver_unregister(&panel_simple_platform_driver);
1662 }
1663 module_exit(panel_simple_exit);
1664
1665 MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
1666 MODULE_DESCRIPTION("DRM Driver for Simple Panels");
1667 MODULE_LICENSE("GPL and additional rights");