2 * Generic MIPI DPI Panel Driver
4 * Copyright (C) 2013 Texas Instruments
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.h>
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
15 #include <linux/slab.h>
17 #include <video/omapdss.h>
18 #include <video/omap-panel-data.h>
20 struct panel_drv_data
{
21 struct omap_dss_device dssdev
;
22 struct omap_dss_device
*in
;
26 struct omap_video_timings videomode
;
32 #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
34 static int panel_dpi_connect(struct omap_dss_device
*dssdev
)
36 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
37 struct omap_dss_device
*in
= ddata
->in
;
40 if (omapdss_device_is_connected(dssdev
))
43 r
= in
->ops
.dpi
->connect(in
, dssdev
);
50 static void panel_dpi_disconnect(struct omap_dss_device
*dssdev
)
52 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
53 struct omap_dss_device
*in
= ddata
->in
;
55 if (!omapdss_device_is_connected(dssdev
))
58 in
->ops
.dpi
->disconnect(in
, dssdev
);
61 static int panel_dpi_enable(struct omap_dss_device
*dssdev
)
63 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
64 struct omap_dss_device
*in
= ddata
->in
;
67 if (!omapdss_device_is_connected(dssdev
))
70 if (omapdss_device_is_enabled(dssdev
))
73 in
->ops
.dpi
->set_data_lines(in
, ddata
->data_lines
);
74 in
->ops
.dpi
->set_timings(in
, &ddata
->videomode
);
76 r
= in
->ops
.dpi
->enable(in
);
80 if (gpio_is_valid(ddata
->enable_gpio
))
81 gpio_set_value_cansleep(ddata
->enable_gpio
, 1);
83 if (gpio_is_valid(ddata
->backlight_gpio
))
84 gpio_set_value_cansleep(ddata
->backlight_gpio
, 1);
86 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
91 static void panel_dpi_disable(struct omap_dss_device
*dssdev
)
93 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
94 struct omap_dss_device
*in
= ddata
->in
;
96 if (!omapdss_device_is_enabled(dssdev
))
99 if (gpio_is_valid(ddata
->enable_gpio
))
100 gpio_set_value_cansleep(ddata
->enable_gpio
, 0);
102 if (gpio_is_valid(ddata
->backlight_gpio
))
103 gpio_set_value_cansleep(ddata
->backlight_gpio
, 0);
105 in
->ops
.dpi
->disable(in
);
107 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
110 static void panel_dpi_set_timings(struct omap_dss_device
*dssdev
,
111 struct omap_video_timings
*timings
)
113 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
114 struct omap_dss_device
*in
= ddata
->in
;
116 ddata
->videomode
= *timings
;
117 dssdev
->panel
.timings
= *timings
;
119 in
->ops
.dpi
->set_timings(in
, timings
);
122 static void panel_dpi_get_timings(struct omap_dss_device
*dssdev
,
123 struct omap_video_timings
*timings
)
125 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
127 *timings
= ddata
->videomode
;
130 static int panel_dpi_check_timings(struct omap_dss_device
*dssdev
,
131 struct omap_video_timings
*timings
)
133 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
134 struct omap_dss_device
*in
= ddata
->in
;
136 return in
->ops
.dpi
->check_timings(in
, timings
);
139 static struct omap_dss_driver panel_dpi_ops
= {
140 .connect
= panel_dpi_connect
,
141 .disconnect
= panel_dpi_disconnect
,
143 .enable
= panel_dpi_enable
,
144 .disable
= panel_dpi_disable
,
146 .set_timings
= panel_dpi_set_timings
,
147 .get_timings
= panel_dpi_get_timings
,
148 .check_timings
= panel_dpi_check_timings
,
150 .get_resolution
= omapdss_default_get_resolution
,
153 static int panel_dpi_probe_pdata(struct platform_device
*pdev
)
155 const struct panel_dpi_platform_data
*pdata
;
156 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
157 struct omap_dss_device
*dssdev
, *in
;
160 pdata
= dev_get_platdata(&pdev
->dev
);
162 in
= omap_dss_find_output(pdata
->source
);
164 dev_err(&pdev
->dev
, "failed to find video source '%s'\n",
166 return -EPROBE_DEFER
;
171 ddata
->data_lines
= pdata
->data_lines
;
173 videomode_from_timing(pdata
->display_timing
, &vm
);
174 videomode_to_omap_video_timings(&vm
, &ddata
->videomode
);
176 dssdev
= &ddata
->dssdev
;
177 dssdev
->name
= pdata
->name
;
179 ddata
->enable_gpio
= pdata
->enable_gpio
;
180 ddata
->backlight_gpio
= pdata
->backlight_gpio
;
185 static int panel_dpi_probe(struct platform_device
*pdev
)
187 struct panel_drv_data
*ddata
;
188 struct omap_dss_device
*dssdev
;
191 ddata
= devm_kzalloc(&pdev
->dev
, sizeof(*ddata
), GFP_KERNEL
);
195 platform_set_drvdata(pdev
, ddata
);
197 if (dev_get_platdata(&pdev
->dev
)) {
198 r
= panel_dpi_probe_pdata(pdev
);
205 if (gpio_is_valid(ddata
->enable_gpio
)) {
206 r
= devm_gpio_request_one(&pdev
->dev
, ddata
->enable_gpio
,
207 GPIOF_OUT_INIT_LOW
, "panel enable");
212 if (gpio_is_valid(ddata
->backlight_gpio
)) {
213 r
= devm_gpio_request_one(&pdev
->dev
, ddata
->backlight_gpio
,
214 GPIOF_OUT_INIT_LOW
, "panel backlight");
219 dssdev
= &ddata
->dssdev
;
220 dssdev
->dev
= &pdev
->dev
;
221 dssdev
->driver
= &panel_dpi_ops
;
222 dssdev
->type
= OMAP_DISPLAY_TYPE_DPI
;
223 dssdev
->owner
= THIS_MODULE
;
224 dssdev
->panel
.timings
= ddata
->videomode
;
225 dssdev
->phy
.dpi
.data_lines
= ddata
->data_lines
;
227 r
= omapdss_register_display(dssdev
);
229 dev_err(&pdev
->dev
, "Failed to register panel\n");
237 omap_dss_put_device(ddata
->in
);
241 static int __exit
panel_dpi_remove(struct platform_device
*pdev
)
243 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
244 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
245 struct omap_dss_device
*in
= ddata
->in
;
247 omapdss_unregister_display(dssdev
);
249 panel_dpi_disable(dssdev
);
250 panel_dpi_disconnect(dssdev
);
252 omap_dss_put_device(in
);
257 static struct platform_driver panel_dpi_driver
= {
258 .probe
= panel_dpi_probe
,
259 .remove
= __exit_p(panel_dpi_remove
),
262 .owner
= THIS_MODULE
,
266 module_platform_driver(panel_dpi_driver
);
268 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
269 MODULE_DESCRIPTION("Generic MIPI DPI Panel Driver");
270 MODULE_LICENSE("GPL");