2 * Generic MIPI DPI Panel Driver
4 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
5 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
12 #include <linux/gpio/consumer.h>
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
15 #include <linux/slab.h>
17 #include <linux/regulator/consumer.h>
18 #include <linux/backlight.h>
20 #include <video/of_display_timing.h>
22 #include "../dss/omapdss.h"
24 struct panel_drv_data {
25 struct omap_dss_device dssdev;
29 struct backlight_device *backlight;
31 struct gpio_desc *enable_gpio;
32 struct regulator *vcc_supply;
35 #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
37 static int panel_dpi_connect(struct omap_dss_device *src,
38 struct omap_dss_device *dst)
43 static void panel_dpi_disconnect(struct omap_dss_device *src,
44 struct omap_dss_device *dst)
48 static void panel_dpi_enable(struct omap_dss_device *dssdev)
50 struct panel_drv_data *ddata = to_panel_data(dssdev);
53 r = regulator_enable(ddata->vcc_supply);
57 gpiod_set_value_cansleep(ddata->enable_gpio, 1);
58 backlight_enable(ddata->backlight);
61 static void panel_dpi_disable(struct omap_dss_device *dssdev)
63 struct panel_drv_data *ddata = to_panel_data(dssdev);
65 backlight_disable(ddata->backlight);
67 gpiod_set_value_cansleep(ddata->enable_gpio, 0);
68 regulator_disable(ddata->vcc_supply);
71 static int panel_dpi_get_modes(struct omap_dss_device *dssdev,
72 struct drm_connector *connector)
74 struct panel_drv_data *ddata = to_panel_data(dssdev);
76 return omapdss_display_get_modes(connector, &ddata->vm);
79 static const struct omap_dss_device_ops panel_dpi_ops = {
80 .connect = panel_dpi_connect,
81 .disconnect = panel_dpi_disconnect,
83 .enable = panel_dpi_enable,
84 .disable = panel_dpi_disable,
86 .get_modes = panel_dpi_get_modes,
89 static int panel_dpi_probe_of(struct platform_device *pdev)
91 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
92 struct device_node *node = pdev->dev.of_node;
94 struct display_timing timing;
95 struct gpio_desc *gpio;
97 gpio = devm_gpiod_get_optional(&pdev->dev, "enable", GPIOD_OUT_LOW);
101 ddata->enable_gpio = gpio;
104 * Many different panels are supported by this driver and there are
105 * probably very different needs for their reset pins in regards to
106 * timing and order relative to the enable gpio. So for now it's just
107 * ensured that the reset line isn't active.
109 gpio = devm_gpiod_get_optional(&pdev->dev, "reset", GPIOD_OUT_LOW);
111 return PTR_ERR(gpio);
113 ddata->vcc_supply = devm_regulator_get(&pdev->dev, "vcc");
114 if (IS_ERR(ddata->vcc_supply))
115 return PTR_ERR(ddata->vcc_supply);
117 ddata->backlight = devm_of_find_backlight(&pdev->dev);
119 if (IS_ERR(ddata->backlight))
120 return PTR_ERR(ddata->backlight);
122 r = of_get_display_timing(node, "panel-timing", &timing);
124 dev_err(&pdev->dev, "failed to get video timing\n");
128 videomode_from_timing(&timing, &ddata->vm);
133 static int panel_dpi_probe(struct platform_device *pdev)
135 struct panel_drv_data *ddata;
136 struct omap_dss_device *dssdev;
139 ddata = devm_kzalloc(&pdev->dev, sizeof(*ddata), GFP_KERNEL);
143 platform_set_drvdata(pdev, ddata);
145 r = panel_dpi_probe_of(pdev);
149 dssdev = &ddata->dssdev;
150 dssdev->dev = &pdev->dev;
151 dssdev->ops = &panel_dpi_ops;
152 dssdev->type = OMAP_DISPLAY_TYPE_DPI;
153 dssdev->display = true;
154 dssdev->owner = THIS_MODULE;
155 dssdev->of_ports = BIT(0);
156 dssdev->ops_flags = OMAP_DSS_DEVICE_OP_MODES;
157 drm_bus_flags_from_videomode(&ddata->vm, &dssdev->bus_flags);
159 omapdss_display_init(dssdev);
160 omapdss_device_register(dssdev);
165 static int __exit panel_dpi_remove(struct platform_device *pdev)
167 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
168 struct omap_dss_device *dssdev = &ddata->dssdev;
170 omapdss_device_unregister(dssdev);
172 if (omapdss_device_is_enabled(dssdev))
173 panel_dpi_disable(dssdev);
178 static const struct of_device_id panel_dpi_of_match[] = {
179 { .compatible = "omapdss,panel-dpi", },
183 MODULE_DEVICE_TABLE(of, panel_dpi_of_match);
185 static struct platform_driver panel_dpi_driver = {
186 .probe = panel_dpi_probe,
187 .remove = __exit_p(panel_dpi_remove),
190 .of_match_table = panel_dpi_of_match,
191 .suppress_bind_attrs = true,
195 module_platform_driver(panel_dpi_driver);
197 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
198 MODULE_DESCRIPTION("Generic MIPI DPI Panel Driver");
199 MODULE_LICENSE("GPL");