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 struct panel_desc {
37 const struct drm_display_mode *modes;
38 unsigned int num_modes;
39
40 unsigned int bpc;
41
42 struct {
43 unsigned int width;
44 unsigned int height;
45 } size;
46
47 /**
48 * @prepare: the time (in milliseconds) that it takes for the panel to
49 * become ready and start receiving video data
50 * @enable: the time (in milliseconds) that it takes for the panel to
51 * display the first valid frame after starting to receive
52 * video data
53 * @disable: the time (in milliseconds) that it takes for the panel to
54 * turn the display off (no content is visible)
55 * @unprepare: the time (in milliseconds) that it takes for the panel
56 * to power itself down completely
57 */
58 struct {
59 unsigned int prepare;
60 unsigned int enable;
61 unsigned int disable;
62 unsigned int unprepare;
63 } delay;
64 };
65
66 struct panel_simple {
67 struct drm_panel base;
68 bool prepared;
69 bool enabled;
70
71 const struct panel_desc *desc;
72
73 struct backlight_device *backlight;
74 struct regulator *supply;
75 struct i2c_adapter *ddc;
76
77 struct gpio_desc *enable_gpio;
78 };
79
to_panel_simple(struct drm_panel * panel)80 static inline struct panel_simple *to_panel_simple(struct drm_panel *panel)
81 {
82 return container_of(panel, struct panel_simple, base);
83 }
84
panel_simple_get_fixed_modes(struct panel_simple * panel)85 static int panel_simple_get_fixed_modes(struct panel_simple *panel)
86 {
87 struct drm_connector *connector = panel->base.connector;
88 struct drm_device *drm = panel->base.drm;
89 struct drm_display_mode *mode;
90 unsigned int i, num = 0;
91
92 if (!panel->desc)
93 return 0;
94
95 for (i = 0; i < panel->desc->num_modes; i++) {
96 const struct drm_display_mode *m = &panel->desc->modes[i];
97
98 mode = drm_mode_duplicate(drm, m);
99 if (!mode) {
100 dev_err(drm->dev, "failed to add mode %ux%u@%u\n",
101 m->hdisplay, m->vdisplay, m->vrefresh);
102 continue;
103 }
104
105 drm_mode_set_name(mode);
106
107 drm_mode_probed_add(connector, mode);
108 num++;
109 }
110
111 connector->display_info.bpc = panel->desc->bpc;
112 connector->display_info.width_mm = panel->desc->size.width;
113 connector->display_info.height_mm = panel->desc->size.height;
114
115 return num;
116 }
117
panel_simple_disable(struct drm_panel * panel)118 static int panel_simple_disable(struct drm_panel *panel)
119 {
120 struct panel_simple *p = to_panel_simple(panel);
121
122 if (!p->enabled)
123 return 0;
124
125 if (p->backlight) {
126 p->backlight->props.power = FB_BLANK_POWERDOWN;
127 backlight_update_status(p->backlight);
128 }
129
130 if (p->desc->delay.disable)
131 msleep(p->desc->delay.disable);
132
133 p->enabled = false;
134
135 return 0;
136 }
137
panel_simple_unprepare(struct drm_panel * panel)138 static int panel_simple_unprepare(struct drm_panel *panel)
139 {
140 struct panel_simple *p = to_panel_simple(panel);
141
142 if (!p->prepared)
143 return 0;
144
145 if (p->enable_gpio)
146 gpiod_set_value_cansleep(p->enable_gpio, 0);
147
148 regulator_disable(p->supply);
149
150 if (p->desc->delay.unprepare)
151 msleep(p->desc->delay.unprepare);
152
153 p->prepared = false;
154
155 return 0;
156 }
157
panel_simple_prepare(struct drm_panel * panel)158 static int panel_simple_prepare(struct drm_panel *panel)
159 {
160 struct panel_simple *p = to_panel_simple(panel);
161 int err;
162
163 if (p->prepared)
164 return 0;
165
166 err = regulator_enable(p->supply);
167 if (err < 0) {
168 dev_err(panel->dev, "failed to enable supply: %d\n", err);
169 return err;
170 }
171
172 if (p->enable_gpio)
173 gpiod_set_value_cansleep(p->enable_gpio, 1);
174
175 if (p->desc->delay.prepare)
176 msleep(p->desc->delay.prepare);
177
178 p->prepared = true;
179
180 return 0;
181 }
182
panel_simple_enable(struct drm_panel * panel)183 static int panel_simple_enable(struct drm_panel *panel)
184 {
185 struct panel_simple *p = to_panel_simple(panel);
186
187 if (p->enabled)
188 return 0;
189
190 if (p->desc->delay.enable)
191 msleep(p->desc->delay.enable);
192
193 if (p->backlight) {
194 p->backlight->props.power = FB_BLANK_UNBLANK;
195 backlight_update_status(p->backlight);
196 }
197
198 p->enabled = true;
199
200 return 0;
201 }
202
panel_simple_get_modes(struct drm_panel * panel)203 static int panel_simple_get_modes(struct drm_panel *panel)
204 {
205 struct panel_simple *p = to_panel_simple(panel);
206 int num = 0;
207
208 /* probe EDID if a DDC bus is available */
209 if (p->ddc) {
210 struct edid *edid = drm_get_edid(panel->connector, p->ddc);
211 drm_mode_connector_update_edid_property(panel->connector, edid);
212 if (edid) {
213 num += drm_add_edid_modes(panel->connector, edid);
214 kfree(edid);
215 }
216 }
217
218 /* add hard-coded panel modes */
219 num += panel_simple_get_fixed_modes(p);
220
221 return num;
222 }
223
224 static const struct drm_panel_funcs panel_simple_funcs = {
225 .disable = panel_simple_disable,
226 .unprepare = panel_simple_unprepare,
227 .prepare = panel_simple_prepare,
228 .enable = panel_simple_enable,
229 .get_modes = panel_simple_get_modes,
230 };
231
panel_simple_probe(struct device * dev,const struct panel_desc * desc)232 static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
233 {
234 struct device_node *backlight, *ddc;
235 struct panel_simple *panel;
236 int err;
237
238 panel = devm_kzalloc(dev, sizeof(*panel), GFP_KERNEL);
239 if (!panel)
240 return -ENOMEM;
241
242 panel->enabled = false;
243 panel->prepared = false;
244 panel->desc = desc;
245
246 panel->supply = devm_regulator_get(dev, "power");
247 if (IS_ERR(panel->supply))
248 return PTR_ERR(panel->supply);
249
250 panel->enable_gpio = devm_gpiod_get_optional(dev, "enable");
251 if (IS_ERR(panel->enable_gpio)) {
252 err = PTR_ERR(panel->enable_gpio);
253 dev_err(dev, "failed to request GPIO: %d\n", err);
254 return err;
255 }
256
257 if (panel->enable_gpio) {
258 err = gpiod_direction_output(panel->enable_gpio, 0);
259 if (err < 0) {
260 dev_err(dev, "failed to setup GPIO: %d\n", err);
261 return err;
262 }
263 }
264
265 backlight = of_parse_phandle(dev->of_node, "backlight", 0);
266 if (backlight) {
267 panel->backlight = of_find_backlight_by_node(backlight);
268 of_node_put(backlight);
269
270 if (!panel->backlight)
271 return -EPROBE_DEFER;
272 }
273
274 ddc = of_parse_phandle(dev->of_node, "ddc-i2c-bus", 0);
275 if (ddc) {
276 panel->ddc = of_find_i2c_adapter_by_node(ddc);
277 of_node_put(ddc);
278
279 if (!panel->ddc) {
280 err = -EPROBE_DEFER;
281 goto free_backlight;
282 }
283 }
284
285 drm_panel_init(&panel->base);
286 panel->base.dev = dev;
287 panel->base.funcs = &panel_simple_funcs;
288
289 err = drm_panel_add(&panel->base);
290 if (err < 0)
291 goto free_ddc;
292
293 dev_set_drvdata(dev, panel);
294
295 return 0;
296
297 free_ddc:
298 if (panel->ddc)
299 put_device(&panel->ddc->dev);
300 free_backlight:
301 if (panel->backlight)
302 put_device(&panel->backlight->dev);
303
304 return err;
305 }
306
panel_simple_remove(struct device * dev)307 static int panel_simple_remove(struct device *dev)
308 {
309 struct panel_simple *panel = dev_get_drvdata(dev);
310
311 drm_panel_detach(&panel->base);
312 drm_panel_remove(&panel->base);
313
314 panel_simple_disable(&panel->base);
315 panel_simple_unprepare(&panel->base);
316
317 if (panel->ddc)
318 put_device(&panel->ddc->dev);
319
320 if (panel->backlight)
321 put_device(&panel->backlight->dev);
322
323 return 0;
324 }
325
panel_simple_shutdown(struct device * dev)326 static void panel_simple_shutdown(struct device *dev)
327 {
328 struct panel_simple *panel = dev_get_drvdata(dev);
329
330 panel_simple_disable(&panel->base);
331 panel_simple_unprepare(&panel->base);
332 }
333
334 static const struct drm_display_mode auo_b101aw03_mode = {
335 .clock = 51450,
336 .hdisplay = 1024,
337 .hsync_start = 1024 + 156,
338 .hsync_end = 1024 + 156 + 8,
339 .htotal = 1024 + 156 + 8 + 156,
340 .vdisplay = 600,
341 .vsync_start = 600 + 16,
342 .vsync_end = 600 + 16 + 6,
343 .vtotal = 600 + 16 + 6 + 16,
344 .vrefresh = 60,
345 };
346
347 static const struct panel_desc auo_b101aw03 = {
348 .modes = &auo_b101aw03_mode,
349 .num_modes = 1,
350 .bpc = 6,
351 .size = {
352 .width = 223,
353 .height = 125,
354 },
355 };
356
357 static const struct drm_display_mode auo_b101xtn01_mode = {
358 .clock = 72000,
359 .hdisplay = 1366,
360 .hsync_start = 1366 + 20,
361 .hsync_end = 1366 + 20 + 70,
362 .htotal = 1366 + 20 + 70,
363 .vdisplay = 768,
364 .vsync_start = 768 + 14,
365 .vsync_end = 768 + 14 + 42,
366 .vtotal = 768 + 14 + 42,
367 .vrefresh = 60,
368 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
369 };
370
371 static const struct panel_desc auo_b101xtn01 = {
372 .modes = &auo_b101xtn01_mode,
373 .num_modes = 1,
374 .bpc = 6,
375 .size = {
376 .width = 223,
377 .height = 125,
378 },
379 };
380
381 static const struct drm_display_mode auo_b133xtn01_mode = {
382 .clock = 69500,
383 .hdisplay = 1366,
384 .hsync_start = 1366 + 48,
385 .hsync_end = 1366 + 48 + 32,
386 .htotal = 1366 + 48 + 32 + 20,
387 .vdisplay = 768,
388 .vsync_start = 768 + 3,
389 .vsync_end = 768 + 3 + 6,
390 .vtotal = 768 + 3 + 6 + 13,
391 .vrefresh = 60,
392 };
393
394 static const struct panel_desc auo_b133xtn01 = {
395 .modes = &auo_b133xtn01_mode,
396 .num_modes = 1,
397 .bpc = 6,
398 .size = {
399 .width = 293,
400 .height = 165,
401 },
402 };
403
404 static const struct drm_display_mode auo_b133htn01_mode = {
405 .clock = 150660,
406 .hdisplay = 1920,
407 .hsync_start = 1920 + 172,
408 .hsync_end = 1920 + 172 + 80,
409 .htotal = 1920 + 172 + 80 + 60,
410 .vdisplay = 1080,
411 .vsync_start = 1080 + 25,
412 .vsync_end = 1080 + 25 + 10,
413 .vtotal = 1080 + 25 + 10 + 10,
414 .vrefresh = 60,
415 };
416
417 static const struct panel_desc auo_b133htn01 = {
418 .modes = &auo_b133htn01_mode,
419 .num_modes = 1,
420 .size = {
421 .width = 293,
422 .height = 165,
423 },
424 .delay = {
425 .prepare = 105,
426 .enable = 20,
427 .unprepare = 50,
428 },
429 };
430
431 static const struct drm_display_mode chunghwa_claa101wa01a_mode = {
432 .clock = 72070,
433 .hdisplay = 1366,
434 .hsync_start = 1366 + 58,
435 .hsync_end = 1366 + 58 + 58,
436 .htotal = 1366 + 58 + 58 + 58,
437 .vdisplay = 768,
438 .vsync_start = 768 + 4,
439 .vsync_end = 768 + 4 + 4,
440 .vtotal = 768 + 4 + 4 + 4,
441 .vrefresh = 60,
442 };
443
444 static const struct panel_desc chunghwa_claa101wa01a = {
445 .modes = &chunghwa_claa101wa01a_mode,
446 .num_modes = 1,
447 .bpc = 6,
448 .size = {
449 .width = 220,
450 .height = 120,
451 },
452 };
453
454 static const struct drm_display_mode chunghwa_claa101wb01_mode = {
455 .clock = 69300,
456 .hdisplay = 1366,
457 .hsync_start = 1366 + 48,
458 .hsync_end = 1366 + 48 + 32,
459 .htotal = 1366 + 48 + 32 + 20,
460 .vdisplay = 768,
461 .vsync_start = 768 + 16,
462 .vsync_end = 768 + 16 + 8,
463 .vtotal = 768 + 16 + 8 + 16,
464 .vrefresh = 60,
465 };
466
467 static const struct panel_desc chunghwa_claa101wb01 = {
468 .modes = &chunghwa_claa101wb01_mode,
469 .num_modes = 1,
470 .bpc = 6,
471 .size = {
472 .width = 223,
473 .height = 125,
474 },
475 };
476
477 static const struct drm_display_mode edt_et057090dhu_mode = {
478 .clock = 25175,
479 .hdisplay = 640,
480 .hsync_start = 640 + 16,
481 .hsync_end = 640 + 16 + 30,
482 .htotal = 640 + 16 + 30 + 114,
483 .vdisplay = 480,
484 .vsync_start = 480 + 10,
485 .vsync_end = 480 + 10 + 3,
486 .vtotal = 480 + 10 + 3 + 32,
487 .vrefresh = 60,
488 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
489 };
490
491 static const struct panel_desc edt_et057090dhu = {
492 .modes = &edt_et057090dhu_mode,
493 .num_modes = 1,
494 .bpc = 6,
495 .size = {
496 .width = 115,
497 .height = 86,
498 },
499 };
500
501 static const struct drm_display_mode edt_etm0700g0dh6_mode = {
502 .clock = 33260,
503 .hdisplay = 800,
504 .hsync_start = 800 + 40,
505 .hsync_end = 800 + 40 + 128,
506 .htotal = 800 + 40 + 128 + 88,
507 .vdisplay = 480,
508 .vsync_start = 480 + 10,
509 .vsync_end = 480 + 10 + 2,
510 .vtotal = 480 + 10 + 2 + 33,
511 .vrefresh = 60,
512 .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
513 };
514
515 static const struct panel_desc edt_etm0700g0dh6 = {
516 .modes = &edt_etm0700g0dh6_mode,
517 .num_modes = 1,
518 .bpc = 6,
519 .size = {
520 .width = 152,
521 .height = 91,
522 },
523 };
524
525 static const struct drm_display_mode foxlink_fl500wvr00_a0t_mode = {
526 .clock = 32260,
527 .hdisplay = 800,
528 .hsync_start = 800 + 168,
529 .hsync_end = 800 + 168 + 64,
530 .htotal = 800 + 168 + 64 + 88,
531 .vdisplay = 480,
532 .vsync_start = 480 + 37,
533 .vsync_end = 480 + 37 + 2,
534 .vtotal = 480 + 37 + 2 + 8,
535 .vrefresh = 60,
536 };
537
538 static const struct panel_desc foxlink_fl500wvr00_a0t = {
539 .modes = &foxlink_fl500wvr00_a0t_mode,
540 .num_modes = 1,
541 .size = {
542 .width = 108,
543 .height = 65,
544 },
545 };
546
547 static const struct drm_display_mode innolux_n116bge_mode = {
548 .clock = 71000,
549 .hdisplay = 1366,
550 .hsync_start = 1366 + 64,
551 .hsync_end = 1366 + 64 + 6,
552 .htotal = 1366 + 64 + 6 + 64,
553 .vdisplay = 768,
554 .vsync_start = 768 + 8,
555 .vsync_end = 768 + 8 + 4,
556 .vtotal = 768 + 8 + 4 + 8,
557 .vrefresh = 60,
558 .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
559 };
560
561 static const struct panel_desc innolux_n116bge = {
562 .modes = &innolux_n116bge_mode,
563 .num_modes = 1,
564 .bpc = 6,
565 .size = {
566 .width = 256,
567 .height = 144,
568 },
569 };
570
571 static const struct drm_display_mode innolux_n156bge_l21_mode = {
572 .clock = 69300,
573 .hdisplay = 1366,
574 .hsync_start = 1366 + 16,
575 .hsync_end = 1366 + 16 + 34,
576 .htotal = 1366 + 16 + 34 + 50,
577 .vdisplay = 768,
578 .vsync_start = 768 + 2,
579 .vsync_end = 768 + 2 + 6,
580 .vtotal = 768 + 2 + 6 + 12,
581 .vrefresh = 60,
582 };
583
584 static const struct panel_desc innolux_n156bge_l21 = {
585 .modes = &innolux_n156bge_l21_mode,
586 .num_modes = 1,
587 .bpc = 6,
588 .size = {
589 .width = 344,
590 .height = 193,
591 },
592 };
593
594 static const struct drm_display_mode lg_lp129qe_mode = {
595 .clock = 285250,
596 .hdisplay = 2560,
597 .hsync_start = 2560 + 48,
598 .hsync_end = 2560 + 48 + 32,
599 .htotal = 2560 + 48 + 32 + 80,
600 .vdisplay = 1700,
601 .vsync_start = 1700 + 3,
602 .vsync_end = 1700 + 3 + 10,
603 .vtotal = 1700 + 3 + 10 + 36,
604 .vrefresh = 60,
605 };
606
607 static const struct panel_desc lg_lp129qe = {
608 .modes = &lg_lp129qe_mode,
609 .num_modes = 1,
610 .bpc = 8,
611 .size = {
612 .width = 272,
613 .height = 181,
614 },
615 };
616
617 static const struct drm_display_mode samsung_ltn101nt05_mode = {
618 .clock = 54030,
619 .hdisplay = 1024,
620 .hsync_start = 1024 + 24,
621 .hsync_end = 1024 + 24 + 136,
622 .htotal = 1024 + 24 + 136 + 160,
623 .vdisplay = 600,
624 .vsync_start = 600 + 3,
625 .vsync_end = 600 + 3 + 6,
626 .vtotal = 600 + 3 + 6 + 61,
627 .vrefresh = 60,
628 };
629
630 static const struct panel_desc samsung_ltn101nt05 = {
631 .modes = &samsung_ltn101nt05_mode,
632 .num_modes = 1,
633 .bpc = 6,
634 .size = {
635 .width = 1024,
636 .height = 600,
637 },
638 };
639
640 static const struct of_device_id platform_of_match[] = {
641 {
642 .compatible = "auo,b101aw03",
643 .data = &auo_b101aw03,
644 }, {
645 .compatible = "auo,b101xtn01",
646 .data = &auo_b101xtn01,
647 }, {
648 .compatible = "auo,b133htn01",
649 .data = &auo_b133htn01,
650 }, {
651 .compatible = "auo,b133xtn01",
652 .data = &auo_b133xtn01,
653 }, {
654 .compatible = "chunghwa,claa101wa01a",
655 .data = &chunghwa_claa101wa01a
656 }, {
657 .compatible = "chunghwa,claa101wb01",
658 .data = &chunghwa_claa101wb01
659 }, {
660 .compatible = "edt,et057090dhu",
661 .data = &edt_et057090dhu,
662 }, {
663 .compatible = "edt,et070080dh6",
664 .data = &edt_etm0700g0dh6,
665 }, {
666 .compatible = "edt,etm0700g0dh6",
667 .data = &edt_etm0700g0dh6,
668 }, {
669 .compatible = "foxlink,fl500wvr00-a0t",
670 .data = &foxlink_fl500wvr00_a0t,
671 }, {
672 .compatible = "innolux,n116bge",
673 .data = &innolux_n116bge,
674 }, {
675 .compatible = "innolux,n156bge-l21",
676 .data = &innolux_n156bge_l21,
677 }, {
678 .compatible = "lg,lp129qe",
679 .data = &lg_lp129qe,
680 }, {
681 .compatible = "samsung,ltn101nt05",
682 .data = &samsung_ltn101nt05,
683 }, {
684 /* sentinel */
685 }
686 };
687 MODULE_DEVICE_TABLE(of, platform_of_match);
688
panel_simple_platform_probe(struct platform_device * pdev)689 static int panel_simple_platform_probe(struct platform_device *pdev)
690 {
691 const struct of_device_id *id;
692
693 id = of_match_node(platform_of_match, pdev->dev.of_node);
694 if (!id)
695 return -ENODEV;
696
697 return panel_simple_probe(&pdev->dev, id->data);
698 }
699
panel_simple_platform_remove(struct platform_device * pdev)700 static int panel_simple_platform_remove(struct platform_device *pdev)
701 {
702 return panel_simple_remove(&pdev->dev);
703 }
704
panel_simple_platform_shutdown(struct platform_device * pdev)705 static void panel_simple_platform_shutdown(struct platform_device *pdev)
706 {
707 panel_simple_shutdown(&pdev->dev);
708 }
709
710 static struct platform_driver panel_simple_platform_driver = {
711 .driver = {
712 .name = "panel-simple",
713 .owner = THIS_MODULE,
714 .of_match_table = platform_of_match,
715 },
716 .probe = panel_simple_platform_probe,
717 .remove = panel_simple_platform_remove,
718 .shutdown = panel_simple_platform_shutdown,
719 };
720
721 struct panel_desc_dsi {
722 struct panel_desc desc;
723
724 unsigned long flags;
725 enum mipi_dsi_pixel_format format;
726 unsigned int lanes;
727 };
728
729 static const struct drm_display_mode lg_ld070wx3_sl01_mode = {
730 .clock = 71000,
731 .hdisplay = 800,
732 .hsync_start = 800 + 32,
733 .hsync_end = 800 + 32 + 1,
734 .htotal = 800 + 32 + 1 + 57,
735 .vdisplay = 1280,
736 .vsync_start = 1280 + 28,
737 .vsync_end = 1280 + 28 + 1,
738 .vtotal = 1280 + 28 + 1 + 14,
739 .vrefresh = 60,
740 };
741
742 static const struct panel_desc_dsi lg_ld070wx3_sl01 = {
743 .desc = {
744 .modes = &lg_ld070wx3_sl01_mode,
745 .num_modes = 1,
746 .size = {
747 .width = 94,
748 .height = 151,
749 },
750 },
751 .flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_CLOCK_NON_CONTINUOUS,
752 .format = MIPI_DSI_FMT_RGB888,
753 .lanes = 4,
754 };
755
756 static const struct drm_display_mode lg_lh500wx1_sd03_mode = {
757 .clock = 67000,
758 .hdisplay = 720,
759 .hsync_start = 720 + 12,
760 .hsync_end = 720 + 12 + 4,
761 .htotal = 720 + 12 + 4 + 112,
762 .vdisplay = 1280,
763 .vsync_start = 1280 + 8,
764 .vsync_end = 1280 + 8 + 4,
765 .vtotal = 1280 + 8 + 4 + 12,
766 .vrefresh = 60,
767 };
768
769 static const struct panel_desc_dsi lg_lh500wx1_sd03 = {
770 .desc = {
771 .modes = &lg_lh500wx1_sd03_mode,
772 .num_modes = 1,
773 .size = {
774 .width = 62,
775 .height = 110,
776 },
777 },
778 .flags = MIPI_DSI_MODE_VIDEO,
779 .format = MIPI_DSI_FMT_RGB888,
780 .lanes = 4,
781 };
782
783 static const struct drm_display_mode panasonic_vvx10f004b00_mode = {
784 .clock = 157200,
785 .hdisplay = 1920,
786 .hsync_start = 1920 + 154,
787 .hsync_end = 1920 + 154 + 16,
788 .htotal = 1920 + 154 + 16 + 32,
789 .vdisplay = 1200,
790 .vsync_start = 1200 + 17,
791 .vsync_end = 1200 + 17 + 2,
792 .vtotal = 1200 + 17 + 2 + 16,
793 .vrefresh = 60,
794 };
795
796 static const struct panel_desc_dsi panasonic_vvx10f004b00 = {
797 .desc = {
798 .modes = &panasonic_vvx10f004b00_mode,
799 .num_modes = 1,
800 .size = {
801 .width = 217,
802 .height = 136,
803 },
804 },
805 .flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE |
806 MIPI_DSI_CLOCK_NON_CONTINUOUS,
807 .format = MIPI_DSI_FMT_RGB888,
808 .lanes = 4,
809 };
810
811 static const struct of_device_id dsi_of_match[] = {
812 {
813 .compatible = "lg,ld070wx3-sl01",
814 .data = &lg_ld070wx3_sl01
815 }, {
816 .compatible = "lg,lh500wx1-sd03",
817 .data = &lg_lh500wx1_sd03
818 }, {
819 .compatible = "panasonic,vvx10f004b00",
820 .data = &panasonic_vvx10f004b00
821 }, {
822 /* sentinel */
823 }
824 };
825 MODULE_DEVICE_TABLE(of, dsi_of_match);
826
panel_simple_dsi_probe(struct mipi_dsi_device * dsi)827 static int panel_simple_dsi_probe(struct mipi_dsi_device *dsi)
828 {
829 const struct panel_desc_dsi *desc;
830 const struct of_device_id *id;
831 int err;
832
833 id = of_match_node(dsi_of_match, dsi->dev.of_node);
834 if (!id)
835 return -ENODEV;
836
837 desc = id->data;
838
839 err = panel_simple_probe(&dsi->dev, &desc->desc);
840 if (err < 0)
841 return err;
842
843 dsi->mode_flags = desc->flags;
844 dsi->format = desc->format;
845 dsi->lanes = desc->lanes;
846
847 return mipi_dsi_attach(dsi);
848 }
849
panel_simple_dsi_remove(struct mipi_dsi_device * dsi)850 static int panel_simple_dsi_remove(struct mipi_dsi_device *dsi)
851 {
852 int err;
853
854 err = mipi_dsi_detach(dsi);
855 if (err < 0)
856 dev_err(&dsi->dev, "failed to detach from DSI host: %d\n", err);
857
858 return panel_simple_remove(&dsi->dev);
859 }
860
panel_simple_dsi_shutdown(struct mipi_dsi_device * dsi)861 static void panel_simple_dsi_shutdown(struct mipi_dsi_device *dsi)
862 {
863 panel_simple_shutdown(&dsi->dev);
864 }
865
866 static struct mipi_dsi_driver panel_simple_dsi_driver = {
867 .driver = {
868 .name = "panel-simple-dsi",
869 .owner = THIS_MODULE,
870 .of_match_table = dsi_of_match,
871 },
872 .probe = panel_simple_dsi_probe,
873 .remove = panel_simple_dsi_remove,
874 .shutdown = panel_simple_dsi_shutdown,
875 };
876
panel_simple_init(void)877 static int __init panel_simple_init(void)
878 {
879 int err;
880
881 err = platform_driver_register(&panel_simple_platform_driver);
882 if (err < 0)
883 return err;
884
885 if (IS_ENABLED(CONFIG_DRM_MIPI_DSI)) {
886 err = mipi_dsi_driver_register(&panel_simple_dsi_driver);
887 if (err < 0)
888 return err;
889 }
890
891 return 0;
892 }
893 module_init(panel_simple_init);
894
panel_simple_exit(void)895 static void __exit panel_simple_exit(void)
896 {
897 if (IS_ENABLED(CONFIG_DRM_MIPI_DSI))
898 mipi_dsi_driver_unregister(&panel_simple_dsi_driver);
899
900 platform_driver_unregister(&panel_simple_platform_driver);
901 }
902 module_exit(panel_simple_exit);
903
904 MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
905 MODULE_DESCRIPTION("DRM Driver for Simple Panels");
906 MODULE_LICENSE("GPL and additional rights");
907