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.h>
26 #include <linux/module.h>
27 #include <linux/of_gpio.h>
28 #include <linux/of_platform.h>
29 #include <linux/platform_device.h>
30 #include <linux/regulator/consumer.h>
33 #include <drm/drm_crtc.h>
34 #include <drm/drm_mipi_dsi.h>
35 #include <drm/drm_panel.h>
38 const struct drm_display_mode *modes;
39 unsigned int num_modes;
47 /* TODO: convert to gpiod_*() API once it's been merged */
48 #define GPIO_ACTIVE_LOW (1 << 0)
51 struct drm_panel base;
54 const struct panel_desc *desc;
56 struct backlight_device *backlight;
57 struct regulator *supply;
58 struct i2c_adapter *ddc;
60 unsigned long enable_gpio_flags;
64 static inline struct panel_simple *to_panel_simple(struct drm_panel *panel)
66 return container_of(panel, struct panel_simple, base);
69 static int panel_simple_get_fixed_modes(struct panel_simple *panel)
71 struct drm_connector *connector = panel->base.connector;
72 struct drm_device *drm = panel->base.drm;
73 struct drm_display_mode *mode;
74 unsigned int i, num = 0;
79 for (i = 0; i < panel->desc->num_modes; i++) {
80 const struct drm_display_mode *m = &panel->desc->modes[i];
82 mode = drm_mode_duplicate(drm, m);
84 dev_err(drm->dev, "failed to add mode %ux%u@%u\n",
85 m->hdisplay, m->vdisplay, m->vrefresh);
89 drm_mode_set_name(mode);
91 drm_mode_probed_add(connector, mode);
95 connector->display_info.width_mm = panel->desc->size.width;
96 connector->display_info.height_mm = panel->desc->size.height;
101 static int panel_simple_disable(struct drm_panel *panel)
103 struct panel_simple *p = to_panel_simple(panel);
109 p->backlight->props.power = FB_BLANK_POWERDOWN;
110 backlight_update_status(p->backlight);
113 if (gpio_is_valid(p->enable_gpio)) {
114 if (p->enable_gpio_flags & GPIO_ACTIVE_LOW)
115 gpio_set_value(p->enable_gpio, 1);
117 gpio_set_value(p->enable_gpio, 0);
120 regulator_disable(p->supply);
126 static int panel_simple_enable(struct drm_panel *panel)
128 struct panel_simple *p = to_panel_simple(panel);
134 err = regulator_enable(p->supply);
136 dev_err(panel->dev, "failed to enable supply: %d\n", err);
140 if (gpio_is_valid(p->enable_gpio)) {
141 if (p->enable_gpio_flags & GPIO_ACTIVE_LOW)
142 gpio_set_value(p->enable_gpio, 0);
144 gpio_set_value(p->enable_gpio, 1);
148 p->backlight->props.power = FB_BLANK_UNBLANK;
149 backlight_update_status(p->backlight);
157 static int panel_simple_get_modes(struct drm_panel *panel)
159 struct panel_simple *p = to_panel_simple(panel);
162 /* probe EDID if a DDC bus is available */
164 struct edid *edid = drm_get_edid(panel->connector, p->ddc);
165 drm_mode_connector_update_edid_property(panel->connector, edid);
167 num += drm_add_edid_modes(panel->connector, edid);
172 /* add hard-coded panel modes */
173 num += panel_simple_get_fixed_modes(p);
178 static const struct drm_panel_funcs panel_simple_funcs = {
179 .disable = panel_simple_disable,
180 .enable = panel_simple_enable,
181 .get_modes = panel_simple_get_modes,
184 static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
186 struct device_node *backlight, *ddc;
187 struct panel_simple *panel;
188 enum of_gpio_flags flags;
191 panel = devm_kzalloc(dev, sizeof(*panel), GFP_KERNEL);
195 panel->enabled = false;
198 panel->supply = devm_regulator_get(dev, "power");
199 if (IS_ERR(panel->supply))
200 return PTR_ERR(panel->supply);
202 panel->enable_gpio = of_get_named_gpio_flags(dev->of_node,
205 if (gpio_is_valid(panel->enable_gpio)) {
208 if (flags & OF_GPIO_ACTIVE_LOW)
209 panel->enable_gpio_flags |= GPIO_ACTIVE_LOW;
211 err = gpio_request(panel->enable_gpio, "enable");
213 dev_err(dev, "failed to request GPIO#%u: %d\n",
214 panel->enable_gpio, err);
218 value = (panel->enable_gpio_flags & GPIO_ACTIVE_LOW) != 0;
220 err = gpio_direction_output(panel->enable_gpio, value);
222 dev_err(dev, "failed to setup GPIO%u: %d\n",
223 panel->enable_gpio, err);
228 backlight = of_parse_phandle(dev->of_node, "backlight", 0);
230 panel->backlight = of_find_backlight_by_node(backlight);
231 of_node_put(backlight);
233 if (!panel->backlight) {
239 ddc = of_parse_phandle(dev->of_node, "ddc-i2c-bus", 0);
241 panel->ddc = of_find_i2c_adapter_by_node(ddc);
250 drm_panel_init(&panel->base);
251 panel->base.dev = dev;
252 panel->base.funcs = &panel_simple_funcs;
254 err = drm_panel_add(&panel->base);
258 dev_set_drvdata(dev, panel);
264 put_device(&panel->ddc->dev);
266 if (panel->backlight)
267 put_device(&panel->backlight->dev);
269 if (gpio_is_valid(panel->enable_gpio))
270 gpio_free(panel->enable_gpio);
275 static int panel_simple_remove(struct device *dev)
277 struct panel_simple *panel = dev_get_drvdata(dev);
279 drm_panel_detach(&panel->base);
280 drm_panel_remove(&panel->base);
282 panel_simple_disable(&panel->base);
285 put_device(&panel->ddc->dev);
287 if (panel->backlight)
288 put_device(&panel->backlight->dev);
290 if (gpio_is_valid(panel->enable_gpio))
291 gpio_free(panel->enable_gpio);
293 regulator_disable(panel->supply);
298 static const struct drm_display_mode auo_b101aw03_mode = {
301 .hsync_start = 1024 + 156,
302 .hsync_end = 1024 + 156 + 8,
303 .htotal = 1024 + 156 + 8 + 156,
305 .vsync_start = 600 + 16,
306 .vsync_end = 600 + 16 + 6,
307 .vtotal = 600 + 16 + 6 + 16,
311 static const struct panel_desc auo_b101aw03 = {
312 .modes = &auo_b101aw03_mode,
320 static const struct drm_display_mode chunghwa_claa101wa01a_mode = {
323 .hsync_start = 1366 + 58,
324 .hsync_end = 1366 + 58 + 58,
325 .htotal = 1366 + 58 + 58 + 58,
327 .vsync_start = 768 + 4,
328 .vsync_end = 768 + 4 + 4,
329 .vtotal = 768 + 4 + 4 + 4,
333 static const struct panel_desc chunghwa_claa101wa01a = {
334 .modes = &chunghwa_claa101wa01a_mode,
342 static const struct drm_display_mode chunghwa_claa101wb01_mode = {
345 .hsync_start = 1366 + 48,
346 .hsync_end = 1366 + 48 + 32,
347 .htotal = 1366 + 48 + 32 + 20,
349 .vsync_start = 768 + 16,
350 .vsync_end = 768 + 16 + 8,
351 .vtotal = 768 + 16 + 8 + 16,
355 static const struct panel_desc chunghwa_claa101wb01 = {
356 .modes = &chunghwa_claa101wb01_mode,
364 static const struct drm_display_mode samsung_ltn101nt05_mode = {
367 .hsync_start = 1024 + 24,
368 .hsync_end = 1024 + 24 + 136,
369 .htotal = 1024 + 24 + 136 + 160,
371 .vsync_start = 600 + 3,
372 .vsync_end = 600 + 3 + 6,
373 .vtotal = 600 + 3 + 6 + 61,
377 static const struct panel_desc samsung_ltn101nt05 = {
378 .modes = &samsung_ltn101nt05_mode,
386 static const struct of_device_id platform_of_match[] = {
388 .compatible = "auo,b101aw03",
389 .data = &auo_b101aw03,
391 .compatible = "chunghwa,claa101wa01a",
392 .data = &chunghwa_claa101wa01a
394 .compatible = "chunghwa,claa101wb01",
395 .data = &chunghwa_claa101wb01
397 .compatible = "samsung,ltn101nt05",
398 .data = &samsung_ltn101nt05,
400 .compatible = "simple-panel",
405 MODULE_DEVICE_TABLE(of, platform_of_match);
407 static int panel_simple_platform_probe(struct platform_device *pdev)
409 const struct of_device_id *id;
411 id = of_match_node(platform_of_match, pdev->dev.of_node);
415 return panel_simple_probe(&pdev->dev, id->data);
418 static int panel_simple_platform_remove(struct platform_device *pdev)
420 return panel_simple_remove(&pdev->dev);
423 static struct platform_driver panel_simple_platform_driver = {
425 .name = "panel-simple",
426 .owner = THIS_MODULE,
427 .of_match_table = platform_of_match,
429 .probe = panel_simple_platform_probe,
430 .remove = panel_simple_platform_remove,
433 struct panel_desc_dsi {
434 struct panel_desc desc;
436 enum mipi_dsi_pixel_format format;
440 static const struct drm_display_mode panasonic_vvx10f004b00_mode = {
443 .hsync_start = 1920 + 154,
444 .hsync_end = 1920 + 154 + 16,
445 .htotal = 1920 + 154 + 16 + 32,
447 .vsync_start = 1200 + 17,
448 .vsync_end = 1200 + 17 + 2,
449 .vtotal = 1200 + 17 + 2 + 16,
453 static const struct panel_desc_dsi panasonic_vvx10f004b00 = {
455 .modes = &panasonic_vvx10f004b00_mode,
462 .format = MIPI_DSI_FMT_RGB888,
466 static const struct of_device_id dsi_of_match[] = {
468 .compatible = "panasonic,vvx10f004b00",
469 .data = &panasonic_vvx10f004b00
474 MODULE_DEVICE_TABLE(of, dsi_of_match);
476 static int panel_simple_dsi_probe(struct mipi_dsi_device *dsi)
478 const struct panel_desc_dsi *desc;
479 const struct of_device_id *id;
482 id = of_match_node(dsi_of_match, dsi->dev.of_node);
488 err = panel_simple_probe(&dsi->dev, &desc->desc);
492 dsi->format = desc->format;
493 dsi->lanes = desc->lanes;
495 return mipi_dsi_attach(dsi);
498 static int panel_simple_dsi_remove(struct mipi_dsi_device *dsi)
502 err = mipi_dsi_detach(dsi);
504 dev_err(&dsi->dev, "failed to detach from DSI host: %d\n", err);
506 return panel_simple_remove(&dsi->dev);
509 static struct mipi_dsi_driver panel_simple_dsi_driver = {
511 .name = "panel-simple-dsi",
512 .owner = THIS_MODULE,
513 .of_match_table = dsi_of_match,
515 .probe = panel_simple_dsi_probe,
516 .remove = panel_simple_dsi_remove,
519 static int __init panel_simple_init(void)
523 err = platform_driver_register(&panel_simple_platform_driver);
527 if (IS_ENABLED(CONFIG_DRM_MIPI_DSI)) {
528 err = mipi_dsi_driver_register(&panel_simple_dsi_driver);
535 module_init(panel_simple_init);
537 static void __exit panel_simple_exit(void)
539 if (IS_ENABLED(CONFIG_DRM_MIPI_DSI))
540 mipi_dsi_driver_unregister(&panel_simple_dsi_driver);
542 platform_driver_unregister(&panel_simple_platform_driver);
544 module_exit(panel_simple_exit);
546 MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
547 MODULE_DESCRIPTION("DRM Driver for Simple Panels");
548 MODULE_LICENSE("GPL and additional rights");