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