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");
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);
257 if (panel->enable_gpio) {
258 err = gpiod_direction_output(panel->enable_gpio, 0);
260 dev_err(dev, "failed to setup GPIO: %d\n", err);
265 backlight = of_parse_phandle(dev->of_node, "backlight", 0);
267 panel->backlight = of_find_backlight_by_node(backlight);
268 of_node_put(backlight);
270 if (!panel->backlight)
271 return -EPROBE_DEFER;
274 ddc = of_parse_phandle(dev->of_node, "ddc-i2c-bus", 0);
276 panel->ddc = of_find_i2c_adapter_by_node(ddc);
285 drm_panel_init(&panel->base);
286 panel->base.dev = dev;
287 panel->base.funcs = &panel_simple_funcs;
289 err = drm_panel_add(&panel->base);
293 dev_set_drvdata(dev, panel);
299 put_device(&panel->ddc->dev);
301 if (panel->backlight)
302 put_device(&panel->backlight->dev);
307 static int panel_simple_remove(struct device *dev)
309 struct panel_simple *panel = dev_get_drvdata(dev);
311 drm_panel_detach(&panel->base);
312 drm_panel_remove(&panel->base);
314 panel_simple_disable(&panel->base);
317 put_device(&panel->ddc->dev);
319 if (panel->backlight)
320 put_device(&panel->backlight->dev);
325 static void panel_simple_shutdown(struct device *dev)
327 struct panel_simple *panel = dev_get_drvdata(dev);
329 panel_simple_disable(&panel->base);
332 static const struct drm_display_mode auo_b101aw03_mode = {
335 .hsync_start = 1024 + 156,
336 .hsync_end = 1024 + 156 + 8,
337 .htotal = 1024 + 156 + 8 + 156,
339 .vsync_start = 600 + 16,
340 .vsync_end = 600 + 16 + 6,
341 .vtotal = 600 + 16 + 6 + 16,
345 static const struct panel_desc auo_b101aw03 = {
346 .modes = &auo_b101aw03_mode,
355 static const struct drm_display_mode auo_b101xtn01_mode = {
358 .hsync_start = 1366 + 20,
359 .hsync_end = 1366 + 20 + 70,
360 .htotal = 1366 + 20 + 70,
362 .vsync_start = 768 + 14,
363 .vsync_end = 768 + 14 + 42,
364 .vtotal = 768 + 14 + 42,
366 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
369 static const struct panel_desc auo_b101xtn01 = {
370 .modes = &auo_b101xtn01_mode,
379 static const struct drm_display_mode auo_b133xtn01_mode = {
382 .hsync_start = 1366 + 48,
383 .hsync_end = 1366 + 48 + 32,
384 .htotal = 1366 + 48 + 32 + 20,
386 .vsync_start = 768 + 3,
387 .vsync_end = 768 + 3 + 6,
388 .vtotal = 768 + 3 + 6 + 13,
392 static const struct panel_desc auo_b133xtn01 = {
393 .modes = &auo_b133xtn01_mode,
402 static const struct drm_display_mode auo_b133htn01_mode = {
405 .hsync_start = 1920 + 172,
406 .hsync_end = 1920 + 172 + 80,
407 .htotal = 1920 + 172 + 80 + 60,
409 .vsync_start = 1080 + 25,
410 .vsync_end = 1080 + 25 + 10,
411 .vtotal = 1080 + 25 + 10 + 10,
415 static const struct panel_desc auo_b133htn01 = {
416 .modes = &auo_b133htn01_mode,
429 static const struct drm_display_mode chunghwa_claa101wa01a_mode = {
432 .hsync_start = 1366 + 58,
433 .hsync_end = 1366 + 58 + 58,
434 .htotal = 1366 + 58 + 58 + 58,
436 .vsync_start = 768 + 4,
437 .vsync_end = 768 + 4 + 4,
438 .vtotal = 768 + 4 + 4 + 4,
442 static const struct panel_desc chunghwa_claa101wa01a = {
443 .modes = &chunghwa_claa101wa01a_mode,
452 static const struct drm_display_mode chunghwa_claa101wb01_mode = {
455 .hsync_start = 1366 + 48,
456 .hsync_end = 1366 + 48 + 32,
457 .htotal = 1366 + 48 + 32 + 20,
459 .vsync_start = 768 + 16,
460 .vsync_end = 768 + 16 + 8,
461 .vtotal = 768 + 16 + 8 + 16,
465 static const struct panel_desc chunghwa_claa101wb01 = {
466 .modes = &chunghwa_claa101wb01_mode,
475 static const struct drm_display_mode edt_et057090dhu_mode = {
478 .hsync_start = 640 + 16,
479 .hsync_end = 640 + 16 + 30,
480 .htotal = 640 + 16 + 30 + 114,
482 .vsync_start = 480 + 10,
483 .vsync_end = 480 + 10 + 3,
484 .vtotal = 480 + 10 + 3 + 32,
486 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
489 static const struct panel_desc edt_et057090dhu = {
490 .modes = &edt_et057090dhu_mode,
499 static const struct drm_display_mode edt_etm0700g0dh6_mode = {
502 .hsync_start = 800 + 40,
503 .hsync_end = 800 + 40 + 128,
504 .htotal = 800 + 40 + 128 + 88,
506 .vsync_start = 480 + 10,
507 .vsync_end = 480 + 10 + 2,
508 .vtotal = 480 + 10 + 2 + 33,
510 .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
513 static const struct panel_desc edt_etm0700g0dh6 = {
514 .modes = &edt_etm0700g0dh6_mode,
523 static const struct drm_display_mode foxlink_fl500wvr00_a0t_mode = {
526 .hsync_start = 800 + 168,
527 .hsync_end = 800 + 168 + 64,
528 .htotal = 800 + 168 + 64 + 88,
530 .vsync_start = 480 + 37,
531 .vsync_end = 480 + 37 + 2,
532 .vtotal = 480 + 37 + 2 + 8,
536 static const struct panel_desc foxlink_fl500wvr00_a0t = {
537 .modes = &foxlink_fl500wvr00_a0t_mode,
545 static const struct drm_display_mode innolux_n116bge_mode = {
548 .hsync_start = 1366 + 64,
549 .hsync_end = 1366 + 64 + 6,
550 .htotal = 1366 + 64 + 6 + 64,
552 .vsync_start = 768 + 8,
553 .vsync_end = 768 + 8 + 4,
554 .vtotal = 768 + 8 + 4 + 8,
556 .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
559 static const struct panel_desc innolux_n116bge = {
560 .modes = &innolux_n116bge_mode,
569 static const struct drm_display_mode innolux_n156bge_l21_mode = {
572 .hsync_start = 1366 + 16,
573 .hsync_end = 1366 + 16 + 34,
574 .htotal = 1366 + 16 + 34 + 50,
576 .vsync_start = 768 + 2,
577 .vsync_end = 768 + 2 + 6,
578 .vtotal = 768 + 2 + 6 + 12,
582 static const struct panel_desc innolux_n156bge_l21 = {
583 .modes = &innolux_n156bge_l21_mode,
592 static const struct drm_display_mode lg_lp129qe_mode = {
595 .hsync_start = 2560 + 48,
596 .hsync_end = 2560 + 48 + 32,
597 .htotal = 2560 + 48 + 32 + 80,
599 .vsync_start = 1700 + 3,
600 .vsync_end = 1700 + 3 + 10,
601 .vtotal = 1700 + 3 + 10 + 36,
605 static const struct panel_desc lg_lp129qe = {
606 .modes = &lg_lp129qe_mode,
615 static const struct drm_display_mode samsung_ltn101nt05_mode = {
618 .hsync_start = 1024 + 24,
619 .hsync_end = 1024 + 24 + 136,
620 .htotal = 1024 + 24 + 136 + 160,
622 .vsync_start = 600 + 3,
623 .vsync_end = 600 + 3 + 6,
624 .vtotal = 600 + 3 + 6 + 61,
628 static const struct panel_desc samsung_ltn101nt05 = {
629 .modes = &samsung_ltn101nt05_mode,
638 static const struct of_device_id platform_of_match[] = {
640 .compatible = "auo,b101aw03",
641 .data = &auo_b101aw03,
643 .compatible = "auo,b101xtn01",
644 .data = &auo_b101xtn01,
646 .compatible = "auo,b133htn01",
647 .data = &auo_b133htn01,
649 .compatible = "auo,b133xtn01",
650 .data = &auo_b133xtn01,
652 .compatible = "chunghwa,claa101wa01a",
653 .data = &chunghwa_claa101wa01a
655 .compatible = "chunghwa,claa101wb01",
656 .data = &chunghwa_claa101wb01
658 .compatible = "edt,et057090dhu",
659 .data = &edt_et057090dhu,
661 .compatible = "edt,et070080dh6",
662 .data = &edt_etm0700g0dh6,
664 .compatible = "edt,etm0700g0dh6",
665 .data = &edt_etm0700g0dh6,
667 .compatible = "foxlink,fl500wvr00-a0t",
668 .data = &foxlink_fl500wvr00_a0t,
670 .compatible = "innolux,n116bge",
671 .data = &innolux_n116bge,
673 .compatible = "innolux,n156bge-l21",
674 .data = &innolux_n156bge_l21,
676 .compatible = "lg,lp129qe",
679 .compatible = "samsung,ltn101nt05",
680 .data = &samsung_ltn101nt05,
685 MODULE_DEVICE_TABLE(of, platform_of_match);
687 static int panel_simple_platform_probe(struct platform_device *pdev)
689 const struct of_device_id *id;
691 id = of_match_node(platform_of_match, pdev->dev.of_node);
695 return panel_simple_probe(&pdev->dev, id->data);
698 static int panel_simple_platform_remove(struct platform_device *pdev)
700 return panel_simple_remove(&pdev->dev);
703 static void panel_simple_platform_shutdown(struct platform_device *pdev)
705 panel_simple_shutdown(&pdev->dev);
708 static struct platform_driver panel_simple_platform_driver = {
710 .name = "panel-simple",
711 .owner = THIS_MODULE,
712 .of_match_table = platform_of_match,
714 .probe = panel_simple_platform_probe,
715 .remove = panel_simple_platform_remove,
716 .shutdown = panel_simple_platform_shutdown,
719 struct panel_desc_dsi {
720 struct panel_desc desc;
723 enum mipi_dsi_pixel_format format;
727 static const struct drm_display_mode lg_ld070wx3_sl01_mode = {
730 .hsync_start = 800 + 32,
731 .hsync_end = 800 + 32 + 1,
732 .htotal = 800 + 32 + 1 + 57,
734 .vsync_start = 1280 + 28,
735 .vsync_end = 1280 + 28 + 1,
736 .vtotal = 1280 + 28 + 1 + 14,
740 static const struct panel_desc_dsi lg_ld070wx3_sl01 = {
742 .modes = &lg_ld070wx3_sl01_mode,
749 .flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_CLOCK_NON_CONTINUOUS,
750 .format = MIPI_DSI_FMT_RGB888,
754 static const struct drm_display_mode lg_lh500wx1_sd03_mode = {
757 .hsync_start = 720 + 12,
758 .hsync_end = 720 + 12 + 4,
759 .htotal = 720 + 12 + 4 + 112,
761 .vsync_start = 1280 + 8,
762 .vsync_end = 1280 + 8 + 4,
763 .vtotal = 1280 + 8 + 4 + 12,
767 static const struct panel_desc_dsi lg_lh500wx1_sd03 = {
769 .modes = &lg_lh500wx1_sd03_mode,
776 .flags = MIPI_DSI_MODE_VIDEO,
777 .format = MIPI_DSI_FMT_RGB888,
781 static const struct drm_display_mode panasonic_vvx10f004b00_mode = {
784 .hsync_start = 1920 + 154,
785 .hsync_end = 1920 + 154 + 16,
786 .htotal = 1920 + 154 + 16 + 32,
788 .vsync_start = 1200 + 17,
789 .vsync_end = 1200 + 17 + 2,
790 .vtotal = 1200 + 17 + 2 + 16,
794 static const struct panel_desc_dsi panasonic_vvx10f004b00 = {
796 .modes = &panasonic_vvx10f004b00_mode,
803 .flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE |
804 MIPI_DSI_CLOCK_NON_CONTINUOUS,
805 .format = MIPI_DSI_FMT_RGB888,
809 static const struct of_device_id dsi_of_match[] = {
811 .compatible = "lg,ld070wx3-sl01",
812 .data = &lg_ld070wx3_sl01
814 .compatible = "lg,lh500wx1-sd03",
815 .data = &lg_lh500wx1_sd03
817 .compatible = "panasonic,vvx10f004b00",
818 .data = &panasonic_vvx10f004b00
823 MODULE_DEVICE_TABLE(of, dsi_of_match);
825 static int panel_simple_dsi_probe(struct mipi_dsi_device *dsi)
827 const struct panel_desc_dsi *desc;
828 const struct of_device_id *id;
831 id = of_match_node(dsi_of_match, dsi->dev.of_node);
837 err = panel_simple_probe(&dsi->dev, &desc->desc);
841 dsi->mode_flags = desc->flags;
842 dsi->format = desc->format;
843 dsi->lanes = desc->lanes;
845 return mipi_dsi_attach(dsi);
848 static int panel_simple_dsi_remove(struct mipi_dsi_device *dsi)
852 err = mipi_dsi_detach(dsi);
854 dev_err(&dsi->dev, "failed to detach from DSI host: %d\n", err);
856 return panel_simple_remove(&dsi->dev);
859 static void panel_simple_dsi_shutdown(struct mipi_dsi_device *dsi)
861 panel_simple_shutdown(&dsi->dev);
864 static struct mipi_dsi_driver panel_simple_dsi_driver = {
866 .name = "panel-simple-dsi",
867 .owner = THIS_MODULE,
868 .of_match_table = dsi_of_match,
870 .probe = panel_simple_dsi_probe,
871 .remove = panel_simple_dsi_remove,
872 .shutdown = panel_simple_dsi_shutdown,
875 static int __init panel_simple_init(void)
879 err = platform_driver_register(&panel_simple_platform_driver);
883 if (IS_ENABLED(CONFIG_DRM_MIPI_DSI)) {
884 err = mipi_dsi_driver_register(&panel_simple_dsi_driver);
891 module_init(panel_simple_init);
893 static void __exit panel_simple_exit(void)
895 if (IS_ENABLED(CONFIG_DRM_MIPI_DSI))
896 mipi_dsi_driver_unregister(&panel_simple_dsi_driver);
898 platform_driver_unregister(&panel_simple_platform_driver);
900 module_exit(panel_simple_exit);
902 MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
903 MODULE_DESCRIPTION("DRM Driver for Simple Panels");
904 MODULE_LICENSE("GPL and additional rights");