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