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;
47 struct drm_panel base;
50 const struct panel_desc *desc;
52 struct backlight_device *backlight;
53 struct regulator *supply;
54 struct i2c_adapter *ddc;
56 struct gpio_desc *enable_gpio;
59 static inline struct panel_simple *to_panel_simple(struct drm_panel *panel)
61 return container_of(panel, struct panel_simple, base);
64 static int panel_simple_get_fixed_modes(struct panel_simple *panel)
66 struct drm_connector *connector = panel->base.connector;
67 struct drm_device *drm = panel->base.drm;
68 struct drm_display_mode *mode;
69 unsigned int i, num = 0;
74 for (i = 0; i < panel->desc->num_modes; i++) {
75 const struct drm_display_mode *m = &panel->desc->modes[i];
77 mode = drm_mode_duplicate(drm, m);
79 dev_err(drm->dev, "failed to add mode %ux%u@%u\n",
80 m->hdisplay, m->vdisplay, m->vrefresh);
84 drm_mode_set_name(mode);
86 drm_mode_probed_add(connector, mode);
90 connector->display_info.width_mm = panel->desc->size.width;
91 connector->display_info.height_mm = panel->desc->size.height;
96 static int panel_simple_disable(struct drm_panel *panel)
98 struct panel_simple *p = to_panel_simple(panel);
104 p->backlight->props.power = FB_BLANK_POWERDOWN;
105 backlight_update_status(p->backlight);
109 gpiod_set_value_cansleep(p->enable_gpio, 0);
111 regulator_disable(p->supply);
117 static int panel_simple_enable(struct drm_panel *panel)
119 struct panel_simple *p = to_panel_simple(panel);
125 err = regulator_enable(p->supply);
127 dev_err(panel->dev, "failed to enable supply: %d\n", err);
132 gpiod_set_value_cansleep(p->enable_gpio, 1);
135 p->backlight->props.power = FB_BLANK_UNBLANK;
136 backlight_update_status(p->backlight);
144 static int panel_simple_get_modes(struct drm_panel *panel)
146 struct panel_simple *p = to_panel_simple(panel);
149 /* probe EDID if a DDC bus is available */
151 struct edid *edid = drm_get_edid(panel->connector, p->ddc);
152 drm_mode_connector_update_edid_property(panel->connector, edid);
154 num += drm_add_edid_modes(panel->connector, edid);
159 /* add hard-coded panel modes */
160 num += panel_simple_get_fixed_modes(p);
165 static const struct drm_panel_funcs panel_simple_funcs = {
166 .disable = panel_simple_disable,
167 .enable = panel_simple_enable,
168 .get_modes = panel_simple_get_modes,
171 static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
173 struct device_node *backlight, *ddc;
174 struct panel_simple *panel;
177 panel = devm_kzalloc(dev, sizeof(*panel), GFP_KERNEL);
181 panel->enabled = false;
184 panel->supply = devm_regulator_get(dev, "power");
185 if (IS_ERR(panel->supply))
186 return PTR_ERR(panel->supply);
188 panel->enable_gpio = devm_gpiod_get(dev, "enable");
189 if (IS_ERR(panel->enable_gpio)) {
190 err = PTR_ERR(panel->enable_gpio);
191 if (err != -ENOENT) {
192 dev_err(dev, "failed to request GPIO: %d\n", err);
196 panel->enable_gpio = NULL;
198 err = gpiod_direction_output(panel->enable_gpio, 0);
200 dev_err(dev, "failed to setup GPIO: %d\n", err);
205 backlight = of_parse_phandle(dev->of_node, "backlight", 0);
207 panel->backlight = of_find_backlight_by_node(backlight);
208 of_node_put(backlight);
210 if (!panel->backlight)
211 return -EPROBE_DEFER;
214 ddc = of_parse_phandle(dev->of_node, "ddc-i2c-bus", 0);
216 panel->ddc = of_find_i2c_adapter_by_node(ddc);
225 drm_panel_init(&panel->base);
226 panel->base.dev = dev;
227 panel->base.funcs = &panel_simple_funcs;
229 err = drm_panel_add(&panel->base);
233 dev_set_drvdata(dev, panel);
239 put_device(&panel->ddc->dev);
241 if (panel->backlight)
242 put_device(&panel->backlight->dev);
247 static int panel_simple_remove(struct device *dev)
249 struct panel_simple *panel = dev_get_drvdata(dev);
251 drm_panel_detach(&panel->base);
252 drm_panel_remove(&panel->base);
254 panel_simple_disable(&panel->base);
257 put_device(&panel->ddc->dev);
259 if (panel->backlight)
260 put_device(&panel->backlight->dev);
265 static void panel_simple_shutdown(struct device *dev)
267 struct panel_simple *panel = dev_get_drvdata(dev);
269 panel_simple_disable(&panel->base);
272 static const struct drm_display_mode auo_b101aw03_mode = {
275 .hsync_start = 1024 + 156,
276 .hsync_end = 1024 + 156 + 8,
277 .htotal = 1024 + 156 + 8 + 156,
279 .vsync_start = 600 + 16,
280 .vsync_end = 600 + 16 + 6,
281 .vtotal = 600 + 16 + 6 + 16,
285 static const struct panel_desc auo_b101aw03 = {
286 .modes = &auo_b101aw03_mode,
294 static const struct drm_display_mode auo_b133xtn01_mode = {
297 .hsync_start = 1366 + 48,
298 .hsync_end = 1366 + 48 + 32,
299 .htotal = 1366 + 48 + 32 + 20,
301 .vsync_start = 768 + 3,
302 .vsync_end = 768 + 3 + 6,
303 .vtotal = 768 + 3 + 6 + 13,
307 static const struct panel_desc auo_b133xtn01 = {
308 .modes = &auo_b133xtn01_mode,
316 static const struct drm_display_mode chunghwa_claa101wa01a_mode = {
319 .hsync_start = 1366 + 58,
320 .hsync_end = 1366 + 58 + 58,
321 .htotal = 1366 + 58 + 58 + 58,
323 .vsync_start = 768 + 4,
324 .vsync_end = 768 + 4 + 4,
325 .vtotal = 768 + 4 + 4 + 4,
329 static const struct panel_desc chunghwa_claa101wa01a = {
330 .modes = &chunghwa_claa101wa01a_mode,
338 static const struct drm_display_mode chunghwa_claa101wb01_mode = {
341 .hsync_start = 1366 + 48,
342 .hsync_end = 1366 + 48 + 32,
343 .htotal = 1366 + 48 + 32 + 20,
345 .vsync_start = 768 + 16,
346 .vsync_end = 768 + 16 + 8,
347 .vtotal = 768 + 16 + 8 + 16,
351 static const struct panel_desc chunghwa_claa101wb01 = {
352 .modes = &chunghwa_claa101wb01_mode,
360 static const struct drm_display_mode edt_et057090dhu_mode = {
363 .hsync_start = 640 + 16,
364 .hsync_end = 640 + 16 + 30,
365 .htotal = 640 + 16 + 30 + 114,
367 .vsync_start = 480 + 10,
368 .vsync_end = 480 + 10 + 3,
369 .vtotal = 480 + 10 + 3 + 32,
371 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
374 static const struct panel_desc edt_et057090dhu = {
375 .modes = &edt_et057090dhu_mode,
383 static const struct drm_display_mode edt_etm0700g0dh6_mode = {
386 .hsync_start = 800 + 40,
387 .hsync_end = 800 + 40 + 128,
388 .htotal = 800 + 40 + 128 + 88,
390 .vsync_start = 480 + 10,
391 .vsync_end = 480 + 10 + 2,
392 .vtotal = 480 + 10 + 2 + 33,
394 .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
397 static const struct panel_desc edt_etm0700g0dh6 = {
398 .modes = &edt_etm0700g0dh6_mode,
406 static const struct drm_display_mode lg_lp129qe_mode = {
409 .hsync_start = 2560 + 48,
410 .hsync_end = 2560 + 48 + 32,
411 .htotal = 2560 + 48 + 32 + 80,
413 .vsync_start = 1700 + 3,
414 .vsync_end = 1700 + 3 + 10,
415 .vtotal = 1700 + 3 + 10 + 36,
419 static const struct panel_desc lg_lp129qe = {
420 .modes = &lg_lp129qe_mode,
428 static const struct drm_display_mode samsung_ltn101nt05_mode = {
431 .hsync_start = 1024 + 24,
432 .hsync_end = 1024 + 24 + 136,
433 .htotal = 1024 + 24 + 136 + 160,
435 .vsync_start = 600 + 3,
436 .vsync_end = 600 + 3 + 6,
437 .vtotal = 600 + 3 + 6 + 61,
441 static const struct panel_desc samsung_ltn101nt05 = {
442 .modes = &samsung_ltn101nt05_mode,
450 static const struct of_device_id platform_of_match[] = {
452 .compatible = "auo,b101aw03",
453 .data = &auo_b101aw03,
455 .compatible = "auo,b133xtn01",
456 .data = &auo_b133xtn01,
458 .compatible = "chunghwa,claa101wa01a",
459 .data = &chunghwa_claa101wa01a
461 .compatible = "chunghwa,claa101wb01",
462 .data = &chunghwa_claa101wb01
464 .compatible = "edt,et057090dhu",
465 .data = &edt_et057090dhu,
467 .compatible = "edt,et070080dh6",
468 .data = &edt_etm0700g0dh6,
470 .compatible = "edt,etm0700g0dh6",
471 .data = &edt_etm0700g0dh6,
473 .compatible = "lg,lp129qe",
476 .compatible = "samsung,ltn101nt05",
477 .data = &samsung_ltn101nt05,
479 .compatible = "simple-panel",
484 MODULE_DEVICE_TABLE(of, platform_of_match);
486 static int panel_simple_platform_probe(struct platform_device *pdev)
488 const struct of_device_id *id;
490 id = of_match_node(platform_of_match, pdev->dev.of_node);
494 return panel_simple_probe(&pdev->dev, id->data);
497 static int panel_simple_platform_remove(struct platform_device *pdev)
499 return panel_simple_remove(&pdev->dev);
502 static void panel_simple_platform_shutdown(struct platform_device *pdev)
504 panel_simple_shutdown(&pdev->dev);
507 static struct platform_driver panel_simple_platform_driver = {
509 .name = "panel-simple",
510 .owner = THIS_MODULE,
511 .of_match_table = platform_of_match,
513 .probe = panel_simple_platform_probe,
514 .remove = panel_simple_platform_remove,
515 .shutdown = panel_simple_platform_shutdown,
518 struct panel_desc_dsi {
519 struct panel_desc desc;
522 enum mipi_dsi_pixel_format format;
526 static const struct drm_display_mode lg_ld070wx3_sl01_mode = {
529 .hsync_start = 800 + 32,
530 .hsync_end = 800 + 32 + 1,
531 .htotal = 800 + 32 + 1 + 57,
533 .vsync_start = 1280 + 28,
534 .vsync_end = 1280 + 28 + 1,
535 .vtotal = 1280 + 28 + 1 + 14,
539 static const struct panel_desc_dsi lg_ld070wx3_sl01 = {
541 .modes = &lg_ld070wx3_sl01_mode,
548 .flags = MIPI_DSI_MODE_VIDEO,
549 .format = MIPI_DSI_FMT_RGB888,
553 static const struct drm_display_mode lg_lh500wx1_sd03_mode = {
556 .hsync_start = 720 + 12,
557 .hsync_end = 720 + 12 + 4,
558 .htotal = 720 + 12 + 4 + 112,
560 .vsync_start = 1280 + 8,
561 .vsync_end = 1280 + 8 + 4,
562 .vtotal = 1280 + 8 + 4 + 12,
566 static const struct panel_desc_dsi lg_lh500wx1_sd03 = {
568 .modes = &lg_lh500wx1_sd03_mode,
575 .flags = MIPI_DSI_MODE_VIDEO,
576 .format = MIPI_DSI_FMT_RGB888,
580 static const struct drm_display_mode panasonic_vvx10f004b00_mode = {
583 .hsync_start = 1920 + 154,
584 .hsync_end = 1920 + 154 + 16,
585 .htotal = 1920 + 154 + 16 + 32,
587 .vsync_start = 1200 + 17,
588 .vsync_end = 1200 + 17 + 2,
589 .vtotal = 1200 + 17 + 2 + 16,
593 static const struct panel_desc_dsi panasonic_vvx10f004b00 = {
595 .modes = &panasonic_vvx10f004b00_mode,
602 .flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE,
603 .format = MIPI_DSI_FMT_RGB888,
607 static const struct of_device_id dsi_of_match[] = {
609 .compatible = "lg,ld070wx3-sl01",
610 .data = &lg_ld070wx3_sl01
612 .compatible = "lg,lh500wx1-sd03",
613 .data = &lg_lh500wx1_sd03
615 .compatible = "panasonic,vvx10f004b00",
616 .data = &panasonic_vvx10f004b00
621 MODULE_DEVICE_TABLE(of, dsi_of_match);
623 static int panel_simple_dsi_probe(struct mipi_dsi_device *dsi)
625 const struct panel_desc_dsi *desc;
626 const struct of_device_id *id;
629 id = of_match_node(dsi_of_match, dsi->dev.of_node);
635 err = panel_simple_probe(&dsi->dev, &desc->desc);
639 dsi->mode_flags = desc->flags;
640 dsi->format = desc->format;
641 dsi->lanes = desc->lanes;
643 return mipi_dsi_attach(dsi);
646 static int panel_simple_dsi_remove(struct mipi_dsi_device *dsi)
650 err = mipi_dsi_detach(dsi);
652 dev_err(&dsi->dev, "failed to detach from DSI host: %d\n", err);
654 return panel_simple_remove(&dsi->dev);
657 static void panel_simple_dsi_shutdown(struct mipi_dsi_device *dsi)
659 panel_simple_shutdown(&dsi->dev);
662 static struct mipi_dsi_driver panel_simple_dsi_driver = {
664 .name = "panel-simple-dsi",
665 .owner = THIS_MODULE,
666 .of_match_table = dsi_of_match,
668 .probe = panel_simple_dsi_probe,
669 .remove = panel_simple_dsi_remove,
670 .shutdown = panel_simple_dsi_shutdown,
673 static int __init panel_simple_init(void)
677 err = platform_driver_register(&panel_simple_platform_driver);
681 if (IS_ENABLED(CONFIG_DRM_MIPI_DSI)) {
682 err = mipi_dsi_driver_register(&panel_simple_dsi_driver);
689 module_init(panel_simple_init);
691 static void __exit panel_simple_exit(void)
693 if (IS_ENABLED(CONFIG_DRM_MIPI_DSI))
694 mipi_dsi_driver_unregister(&panel_simple_dsi_driver);
696 platform_driver_unregister(&panel_simple_platform_driver);
698 module_exit(panel_simple_exit);
700 MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
701 MODULE_DESCRIPTION("DRM Driver for Simple Panels");
702 MODULE_LICENSE("GPL and additional rights");