2 * Copyright (C) 2013, NVIDIA Corporation. All rights reserved.
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:
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
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.
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>
32 #include <drm/drm_crtc.h>
33 #include <drm/drm_mipi_dsi.h>
34 #include <drm/drm_panel.h>
37 const struct drm_display_mode *modes;
38 unsigned int num_modes;
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
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
62 unsigned int unprepare;
67 struct drm_panel base;
71 const struct panel_desc *desc;
73 struct backlight_device *backlight;
74 struct regulator *supply;
75 struct i2c_adapter *ddc;
77 struct gpio_desc *enable_gpio;
80 static inline struct panel_simple *to_panel_simple(struct drm_panel *panel)
82 return container_of(panel, struct panel_simple, base);
85 static int panel_simple_get_fixed_modes(struct panel_simple *panel)
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;
95 for (i = 0; i < panel->desc->num_modes; i++) {
96 const struct drm_display_mode *m = &panel->desc->modes[i];
98 mode = drm_mode_duplicate(drm, m);
100 dev_err(drm->dev, "failed to add mode %ux%u@%u\n",
101 m->hdisplay, m->vdisplay, m->vrefresh);
105 drm_mode_set_name(mode);
107 drm_mode_probed_add(connector, mode);
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;
118 static int panel_simple_disable(struct drm_panel *panel)
120 struct panel_simple *p = to_panel_simple(panel);
126 p->backlight->props.power = FB_BLANK_POWERDOWN;
127 backlight_update_status(p->backlight);
130 if (p->desc->delay.disable)
131 msleep(p->desc->delay.disable);
138 static int panel_simple_unprepare(struct drm_panel *panel)
140 struct panel_simple *p = to_panel_simple(panel);
146 gpiod_set_value_cansleep(p->enable_gpio, 0);
148 regulator_disable(p->supply);
150 if (p->desc->delay.unprepare)
151 msleep(p->desc->delay.unprepare);
158 static int panel_simple_prepare(struct drm_panel *panel)
160 struct panel_simple *p = to_panel_simple(panel);
166 err = regulator_enable(p->supply);
168 dev_err(panel->dev, "failed to enable supply: %d\n", err);
173 gpiod_set_value_cansleep(p->enable_gpio, 1);
175 if (p->desc->delay.prepare)
176 msleep(p->desc->delay.prepare);
183 static int panel_simple_enable(struct drm_panel *panel)
185 struct panel_simple *p = to_panel_simple(panel);
190 if (p->desc->delay.enable)
191 msleep(p->desc->delay.enable);
194 p->backlight->props.power = FB_BLANK_UNBLANK;
195 backlight_update_status(p->backlight);
203 static int panel_simple_get_modes(struct drm_panel *panel)
205 struct panel_simple *p = to_panel_simple(panel);
208 /* probe EDID if a DDC bus is available */
210 struct edid *edid = drm_get_edid(panel->connector, p->ddc);
211 drm_mode_connector_update_edid_property(panel->connector, edid);
213 num += drm_add_edid_modes(panel->connector, edid);
218 /* add hard-coded panel modes */
219 num += panel_simple_get_fixed_modes(p);
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,
232 static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
234 struct device_node *backlight, *ddc;
235 struct panel_simple *panel;
238 panel = devm_kzalloc(dev, sizeof(*panel), GFP_KERNEL);
242 panel->enabled = false;
243 panel->prepared = false;
246 panel->supply = devm_regulator_get(dev, "power");
247 if (IS_ERR(panel->supply))
248 return PTR_ERR(panel->supply);
250 panel->enable_gpio = devm_gpiod_get_optional(dev, "enable",
252 if (IS_ERR(panel->enable_gpio)) {
253 err = PTR_ERR(panel->enable_gpio);
254 dev_err(dev, "failed to request GPIO: %d\n", err);
258 backlight = of_parse_phandle(dev->of_node, "backlight", 0);
260 panel->backlight = of_find_backlight_by_node(backlight);
261 of_node_put(backlight);
263 if (!panel->backlight)
264 return -EPROBE_DEFER;
267 ddc = of_parse_phandle(dev->of_node, "ddc-i2c-bus", 0);
269 panel->ddc = of_find_i2c_adapter_by_node(ddc);
278 drm_panel_init(&panel->base);
279 panel->base.dev = dev;
280 panel->base.funcs = &panel_simple_funcs;
282 err = drm_panel_add(&panel->base);
286 dev_set_drvdata(dev, panel);
292 put_device(&panel->ddc->dev);
294 if (panel->backlight)
295 put_device(&panel->backlight->dev);
300 static int panel_simple_remove(struct device *dev)
302 struct panel_simple *panel = dev_get_drvdata(dev);
304 drm_panel_detach(&panel->base);
305 drm_panel_remove(&panel->base);
307 panel_simple_disable(&panel->base);
310 put_device(&panel->ddc->dev);
312 if (panel->backlight)
313 put_device(&panel->backlight->dev);
318 static void panel_simple_shutdown(struct device *dev)
320 struct panel_simple *panel = dev_get_drvdata(dev);
322 panel_simple_disable(&panel->base);
325 static const struct drm_display_mode auo_b101aw03_mode = {
328 .hsync_start = 1024 + 156,
329 .hsync_end = 1024 + 156 + 8,
330 .htotal = 1024 + 156 + 8 + 156,
332 .vsync_start = 600 + 16,
333 .vsync_end = 600 + 16 + 6,
334 .vtotal = 600 + 16 + 6 + 16,
338 static const struct panel_desc auo_b101aw03 = {
339 .modes = &auo_b101aw03_mode,
348 static const struct drm_display_mode auo_b101xtn01_mode = {
351 .hsync_start = 1366 + 20,
352 .hsync_end = 1366 + 20 + 70,
353 .htotal = 1366 + 20 + 70,
355 .vsync_start = 768 + 14,
356 .vsync_end = 768 + 14 + 42,
357 .vtotal = 768 + 14 + 42,
359 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
362 static const struct panel_desc auo_b101xtn01 = {
363 .modes = &auo_b101xtn01_mode,
372 static const struct drm_display_mode auo_b116xw03_mode = {
375 .hsync_start = 1366 + 40,
376 .hsync_end = 1366 + 40 + 40,
377 .htotal = 1366 + 40 + 40 + 32,
379 .vsync_start = 768 + 10,
380 .vsync_end = 768 + 10 + 12,
381 .vtotal = 768 + 10 + 12 + 6,
385 static const struct panel_desc auo_b116xw03 = {
386 .modes = &auo_b116xw03_mode,
395 static const struct drm_display_mode auo_b133xtn01_mode = {
398 .hsync_start = 1366 + 48,
399 .hsync_end = 1366 + 48 + 32,
400 .htotal = 1366 + 48 + 32 + 20,
402 .vsync_start = 768 + 3,
403 .vsync_end = 768 + 3 + 6,
404 .vtotal = 768 + 3 + 6 + 13,
408 static const struct panel_desc auo_b133xtn01 = {
409 .modes = &auo_b133xtn01_mode,
418 static const struct drm_display_mode auo_b133htn01_mode = {
421 .hsync_start = 1920 + 172,
422 .hsync_end = 1920 + 172 + 80,
423 .htotal = 1920 + 172 + 80 + 60,
425 .vsync_start = 1080 + 25,
426 .vsync_end = 1080 + 25 + 10,
427 .vtotal = 1080 + 25 + 10 + 10,
431 static const struct panel_desc auo_b133htn01 = {
432 .modes = &auo_b133htn01_mode,
446 static const struct drm_display_mode chunghwa_claa101wa01a_mode = {
449 .hsync_start = 1366 + 58,
450 .hsync_end = 1366 + 58 + 58,
451 .htotal = 1366 + 58 + 58 + 58,
453 .vsync_start = 768 + 4,
454 .vsync_end = 768 + 4 + 4,
455 .vtotal = 768 + 4 + 4 + 4,
459 static const struct panel_desc chunghwa_claa101wa01a = {
460 .modes = &chunghwa_claa101wa01a_mode,
469 static const struct drm_display_mode chunghwa_claa101wb01_mode = {
472 .hsync_start = 1366 + 48,
473 .hsync_end = 1366 + 48 + 32,
474 .htotal = 1366 + 48 + 32 + 20,
476 .vsync_start = 768 + 16,
477 .vsync_end = 768 + 16 + 8,
478 .vtotal = 768 + 16 + 8 + 16,
482 static const struct panel_desc chunghwa_claa101wb01 = {
483 .modes = &chunghwa_claa101wb01_mode,
492 static const struct drm_display_mode edt_et057090dhu_mode = {
495 .hsync_start = 640 + 16,
496 .hsync_end = 640 + 16 + 30,
497 .htotal = 640 + 16 + 30 + 114,
499 .vsync_start = 480 + 10,
500 .vsync_end = 480 + 10 + 3,
501 .vtotal = 480 + 10 + 3 + 32,
503 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
506 static const struct panel_desc edt_et057090dhu = {
507 .modes = &edt_et057090dhu_mode,
516 static const struct drm_display_mode edt_etm0700g0dh6_mode = {
519 .hsync_start = 800 + 40,
520 .hsync_end = 800 + 40 + 128,
521 .htotal = 800 + 40 + 128 + 88,
523 .vsync_start = 480 + 10,
524 .vsync_end = 480 + 10 + 2,
525 .vtotal = 480 + 10 + 2 + 33,
527 .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
530 static const struct panel_desc edt_etm0700g0dh6 = {
531 .modes = &edt_etm0700g0dh6_mode,
540 static const struct drm_display_mode foxlink_fl500wvr00_a0t_mode = {
543 .hsync_start = 800 + 168,
544 .hsync_end = 800 + 168 + 64,
545 .htotal = 800 + 168 + 64 + 88,
547 .vsync_start = 480 + 37,
548 .vsync_end = 480 + 37 + 2,
549 .vtotal = 480 + 37 + 2 + 8,
553 static const struct panel_desc foxlink_fl500wvr00_a0t = {
554 .modes = &foxlink_fl500wvr00_a0t_mode,
563 static const struct drm_display_mode hannstar_hsd070pww1_mode = {
566 .hsync_start = 1280 + 1,
567 .hsync_end = 1280 + 1 + 158,
568 .htotal = 1280 + 1 + 158 + 1,
570 .vsync_start = 800 + 1,
571 .vsync_end = 800 + 1 + 21,
572 .vtotal = 800 + 1 + 21 + 1,
576 static const struct panel_desc hannstar_hsd070pww1 = {
577 .modes = &hannstar_hsd070pww1_mode,
586 static const struct drm_display_mode hitachi_tx23d38vm0caa_mode = {
589 .hsync_start = 800 + 85,
590 .hsync_end = 800 + 85 + 86,
591 .htotal = 800 + 85 + 86 + 85,
593 .vsync_start = 480 + 16,
594 .vsync_end = 480 + 16 + 13,
595 .vtotal = 480 + 16 + 13 + 16,
599 static const struct panel_desc hitachi_tx23d38vm0caa = {
600 .modes = &hitachi_tx23d38vm0caa_mode,
609 static const struct drm_display_mode innolux_g121i1_l01_mode = {
612 .hsync_start = 1280 + 64,
613 .hsync_end = 1280 + 64 + 32,
614 .htotal = 1280 + 64 + 32 + 64,
616 .vsync_start = 800 + 9,
617 .vsync_end = 800 + 9 + 6,
618 .vtotal = 800 + 9 + 6 + 9,
622 static const struct panel_desc innolux_g121i1_l01 = {
623 .modes = &innolux_g121i1_l01_mode,
632 static const struct drm_display_mode innolux_n116bge_mode = {
635 .hsync_start = 1366 + 136,
636 .hsync_end = 1366 + 136 + 30,
637 .htotal = 1366 + 136 + 30 + 60,
639 .vsync_start = 768 + 8,
640 .vsync_end = 768 + 8 + 12,
641 .vtotal = 768 + 8 + 12 + 12,
643 .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
646 static const struct panel_desc innolux_n116bge = {
647 .modes = &innolux_n116bge_mode,
656 static const struct drm_display_mode innolux_n156bge_l21_mode = {
659 .hsync_start = 1366 + 16,
660 .hsync_end = 1366 + 16 + 34,
661 .htotal = 1366 + 16 + 34 + 50,
663 .vsync_start = 768 + 2,
664 .vsync_end = 768 + 2 + 6,
665 .vtotal = 768 + 2 + 6 + 12,
669 static const struct panel_desc innolux_n156bge_l21 = {
670 .modes = &innolux_n156bge_l21_mode,
679 static const struct drm_display_mode lg_lp129qe_mode = {
682 .hsync_start = 2560 + 48,
683 .hsync_end = 2560 + 48 + 32,
684 .htotal = 2560 + 48 + 32 + 80,
686 .vsync_start = 1700 + 3,
687 .vsync_end = 1700 + 3 + 10,
688 .vtotal = 1700 + 3 + 10 + 36,
692 static const struct panel_desc lg_lp129qe = {
693 .modes = &lg_lp129qe_mode,
702 static const struct drm_display_mode samsung_ltn101nt05_mode = {
705 .hsync_start = 1024 + 24,
706 .hsync_end = 1024 + 24 + 136,
707 .htotal = 1024 + 24 + 136 + 160,
709 .vsync_start = 600 + 3,
710 .vsync_end = 600 + 3 + 6,
711 .vtotal = 600 + 3 + 6 + 61,
715 static const struct panel_desc samsung_ltn101nt05 = {
716 .modes = &samsung_ltn101nt05_mode,
725 static const struct of_device_id platform_of_match[] = {
727 .compatible = "auo,b101aw03",
728 .data = &auo_b101aw03,
730 .compatible = "auo,b101xtn01",
731 .data = &auo_b101xtn01,
733 .compatible = "auo,b116xw03",
734 .data = &auo_b116xw03,
736 .compatible = "auo,b133htn01",
737 .data = &auo_b133htn01,
739 .compatible = "auo,b133xtn01",
740 .data = &auo_b133xtn01,
742 .compatible = "chunghwa,claa101wa01a",
743 .data = &chunghwa_claa101wa01a
745 .compatible = "chunghwa,claa101wb01",
746 .data = &chunghwa_claa101wb01
748 .compatible = "edt,et057090dhu",
749 .data = &edt_et057090dhu,
751 .compatible = "edt,et070080dh6",
752 .data = &edt_etm0700g0dh6,
754 .compatible = "edt,etm0700g0dh6",
755 .data = &edt_etm0700g0dh6,
757 .compatible = "foxlink,fl500wvr00-a0t",
758 .data = &foxlink_fl500wvr00_a0t,
760 .compatible = "hannstar,hsd070pww1",
761 .data = &hannstar_hsd070pww1,
763 .compatible = "hit,tx23d38vm0caa",
764 .data = &hitachi_tx23d38vm0caa
766 .compatible ="innolux,g121i1-l01",
767 .data = &innolux_g121i1_l01
769 .compatible = "innolux,n116bge",
770 .data = &innolux_n116bge,
772 .compatible = "innolux,n156bge-l21",
773 .data = &innolux_n156bge_l21,
775 .compatible = "lg,lp129qe",
778 .compatible = "samsung,ltn101nt05",
779 .data = &samsung_ltn101nt05,
784 MODULE_DEVICE_TABLE(of, platform_of_match);
786 static int panel_simple_platform_probe(struct platform_device *pdev)
788 const struct of_device_id *id;
790 id = of_match_node(platform_of_match, pdev->dev.of_node);
794 return panel_simple_probe(&pdev->dev, id->data);
797 static int panel_simple_platform_remove(struct platform_device *pdev)
799 return panel_simple_remove(&pdev->dev);
802 static void panel_simple_platform_shutdown(struct platform_device *pdev)
804 panel_simple_shutdown(&pdev->dev);
807 static struct platform_driver panel_simple_platform_driver = {
809 .name = "panel-simple",
810 .owner = THIS_MODULE,
811 .of_match_table = platform_of_match,
813 .probe = panel_simple_platform_probe,
814 .remove = panel_simple_platform_remove,
815 .shutdown = panel_simple_platform_shutdown,
818 struct panel_desc_dsi {
819 struct panel_desc desc;
822 enum mipi_dsi_pixel_format format;
826 static const struct drm_display_mode lg_ld070wx3_sl01_mode = {
829 .hsync_start = 800 + 32,
830 .hsync_end = 800 + 32 + 1,
831 .htotal = 800 + 32 + 1 + 57,
833 .vsync_start = 1280 + 28,
834 .vsync_end = 1280 + 28 + 1,
835 .vtotal = 1280 + 28 + 1 + 14,
839 static const struct panel_desc_dsi lg_ld070wx3_sl01 = {
841 .modes = &lg_ld070wx3_sl01_mode,
849 .flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_CLOCK_NON_CONTINUOUS,
850 .format = MIPI_DSI_FMT_RGB888,
854 static const struct drm_display_mode lg_lh500wx1_sd03_mode = {
857 .hsync_start = 720 + 12,
858 .hsync_end = 720 + 12 + 4,
859 .htotal = 720 + 12 + 4 + 112,
861 .vsync_start = 1280 + 8,
862 .vsync_end = 1280 + 8 + 4,
863 .vtotal = 1280 + 8 + 4 + 12,
867 static const struct panel_desc_dsi lg_lh500wx1_sd03 = {
869 .modes = &lg_lh500wx1_sd03_mode,
877 .flags = MIPI_DSI_MODE_VIDEO,
878 .format = MIPI_DSI_FMT_RGB888,
882 static const struct drm_display_mode panasonic_vvx10f004b00_mode = {
885 .hsync_start = 1920 + 154,
886 .hsync_end = 1920 + 154 + 16,
887 .htotal = 1920 + 154 + 16 + 32,
889 .vsync_start = 1200 + 17,
890 .vsync_end = 1200 + 17 + 2,
891 .vtotal = 1200 + 17 + 2 + 16,
895 static const struct panel_desc_dsi panasonic_vvx10f004b00 = {
897 .modes = &panasonic_vvx10f004b00_mode,
905 .flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE |
906 MIPI_DSI_CLOCK_NON_CONTINUOUS,
907 .format = MIPI_DSI_FMT_RGB888,
911 static const struct of_device_id dsi_of_match[] = {
913 .compatible = "lg,ld070wx3-sl01",
914 .data = &lg_ld070wx3_sl01
916 .compatible = "lg,lh500wx1-sd03",
917 .data = &lg_lh500wx1_sd03
919 .compatible = "panasonic,vvx10f004b00",
920 .data = &panasonic_vvx10f004b00
925 MODULE_DEVICE_TABLE(of, dsi_of_match);
927 static int panel_simple_dsi_probe(struct mipi_dsi_device *dsi)
929 const struct panel_desc_dsi *desc;
930 const struct of_device_id *id;
933 id = of_match_node(dsi_of_match, dsi->dev.of_node);
939 err = panel_simple_probe(&dsi->dev, &desc->desc);
943 dsi->mode_flags = desc->flags;
944 dsi->format = desc->format;
945 dsi->lanes = desc->lanes;
947 return mipi_dsi_attach(dsi);
950 static int panel_simple_dsi_remove(struct mipi_dsi_device *dsi)
954 err = mipi_dsi_detach(dsi);
956 dev_err(&dsi->dev, "failed to detach from DSI host: %d\n", err);
958 return panel_simple_remove(&dsi->dev);
961 static void panel_simple_dsi_shutdown(struct mipi_dsi_device *dsi)
963 panel_simple_shutdown(&dsi->dev);
966 static struct mipi_dsi_driver panel_simple_dsi_driver = {
968 .name = "panel-simple-dsi",
969 .of_match_table = dsi_of_match,
971 .probe = panel_simple_dsi_probe,
972 .remove = panel_simple_dsi_remove,
973 .shutdown = panel_simple_dsi_shutdown,
976 static int __init panel_simple_init(void)
980 err = platform_driver_register(&panel_simple_platform_driver);
984 if (IS_ENABLED(CONFIG_DRM_MIPI_DSI)) {
985 err = mipi_dsi_driver_register(&panel_simple_dsi_driver);
992 module_init(panel_simple_init);
994 static void __exit panel_simple_exit(void)
996 if (IS_ENABLED(CONFIG_DRM_MIPI_DSI))
997 mipi_dsi_driver_unregister(&panel_simple_dsi_driver);
999 platform_driver_unregister(&panel_simple_platform_driver);
1001 module_exit(panel_simple_exit);
1003 MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
1004 MODULE_DESCRIPTION("DRM Driver for Simple Panels");
1005 MODULE_LICENSE("GPL and additional rights");