2 * LCD panel driver for Sharp LS037V7DW01
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/delay.h>
13 #include <linux/gpio.h>
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
16 #include <linux/slab.h>
18 #include <video/omapdss.h>
19 #include <video/omap-panel-data.h>
21 struct panel_drv_data
{
22 struct omap_dss_device dssdev
;
23 struct omap_dss_device
*in
;
27 struct omap_video_timings videomode
;
36 static const struct omap_video_timings sharp_ls_timings
= {
50 .vsync_level
= OMAPDSS_SIG_ACTIVE_LOW
,
51 .hsync_level
= OMAPDSS_SIG_ACTIVE_LOW
,
52 .data_pclk_edge
= OMAPDSS_DRIVE_SIG_RISING_EDGE
,
53 .de_level
= OMAPDSS_SIG_ACTIVE_HIGH
,
54 .sync_pclk_edge
= OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES
,
57 #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
59 static int sharp_ls_connect(struct omap_dss_device
*dssdev
)
61 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
62 struct omap_dss_device
*in
= ddata
->in
;
65 if (omapdss_device_is_connected(dssdev
))
68 r
= in
->ops
.dpi
->connect(in
, dssdev
);
75 static void sharp_ls_disconnect(struct omap_dss_device
*dssdev
)
77 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
78 struct omap_dss_device
*in
= ddata
->in
;
80 if (!omapdss_device_is_connected(dssdev
))
83 in
->ops
.dpi
->disconnect(in
, dssdev
);
86 static int sharp_ls_enable(struct omap_dss_device
*dssdev
)
88 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
89 struct omap_dss_device
*in
= ddata
->in
;
92 if (!omapdss_device_is_connected(dssdev
))
95 if (omapdss_device_is_enabled(dssdev
))
98 in
->ops
.dpi
->set_data_lines(in
, ddata
->data_lines
);
99 in
->ops
.dpi
->set_timings(in
, &ddata
->videomode
);
101 r
= in
->ops
.dpi
->enable(in
);
105 /* wait couple of vsyncs until enabling the LCD */
108 if (gpio_is_valid(ddata
->resb_gpio
))
109 gpio_set_value_cansleep(ddata
->resb_gpio
, 1);
111 if (gpio_is_valid(ddata
->ini_gpio
))
112 gpio_set_value_cansleep(ddata
->ini_gpio
, 1);
114 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
119 static void sharp_ls_disable(struct omap_dss_device
*dssdev
)
121 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
122 struct omap_dss_device
*in
= ddata
->in
;
124 if (!omapdss_device_is_enabled(dssdev
))
127 if (gpio_is_valid(ddata
->ini_gpio
))
128 gpio_set_value_cansleep(ddata
->ini_gpio
, 0);
130 if (gpio_is_valid(ddata
->resb_gpio
))
131 gpio_set_value_cansleep(ddata
->resb_gpio
, 0);
133 /* wait at least 5 vsyncs after disabling the LCD */
137 in
->ops
.dpi
->disable(in
);
139 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
142 static void sharp_ls_set_timings(struct omap_dss_device
*dssdev
,
143 struct omap_video_timings
*timings
)
145 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
146 struct omap_dss_device
*in
= ddata
->in
;
148 ddata
->videomode
= *timings
;
149 dssdev
->panel
.timings
= *timings
;
151 in
->ops
.dpi
->set_timings(in
, timings
);
154 static void sharp_ls_get_timings(struct omap_dss_device
*dssdev
,
155 struct omap_video_timings
*timings
)
157 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
159 *timings
= ddata
->videomode
;
162 static int sharp_ls_check_timings(struct omap_dss_device
*dssdev
,
163 struct omap_video_timings
*timings
)
165 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
166 struct omap_dss_device
*in
= ddata
->in
;
168 return in
->ops
.dpi
->check_timings(in
, timings
);
171 static struct omap_dss_driver sharp_ls_ops
= {
172 .connect
= sharp_ls_connect
,
173 .disconnect
= sharp_ls_disconnect
,
175 .enable
= sharp_ls_enable
,
176 .disable
= sharp_ls_disable
,
178 .set_timings
= sharp_ls_set_timings
,
179 .get_timings
= sharp_ls_get_timings
,
180 .check_timings
= sharp_ls_check_timings
,
182 .get_resolution
= omapdss_default_get_resolution
,
185 static int sharp_ls_probe_pdata(struct platform_device
*pdev
)
187 const struct panel_sharp_ls037v7dw01_platform_data
*pdata
;
188 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
189 struct omap_dss_device
*dssdev
, *in
;
191 pdata
= dev_get_platdata(&pdev
->dev
);
193 in
= omap_dss_find_output(pdata
->source
);
195 dev_err(&pdev
->dev
, "failed to find video source '%s'\n",
197 return -EPROBE_DEFER
;
202 ddata
->data_lines
= pdata
->data_lines
;
204 dssdev
= &ddata
->dssdev
;
205 dssdev
->name
= pdata
->name
;
207 ddata
->resb_gpio
= pdata
->resb_gpio
;
208 ddata
->ini_gpio
= pdata
->ini_gpio
;
209 ddata
->mo_gpio
= pdata
->mo_gpio
;
210 ddata
->lr_gpio
= pdata
->lr_gpio
;
211 ddata
->ud_gpio
= pdata
->ud_gpio
;
216 static int sharp_ls_probe(struct platform_device
*pdev
)
218 struct panel_drv_data
*ddata
;
219 struct omap_dss_device
*dssdev
;
222 ddata
= devm_kzalloc(&pdev
->dev
, sizeof(*ddata
), GFP_KERNEL
);
226 platform_set_drvdata(pdev
, ddata
);
228 if (dev_get_platdata(&pdev
->dev
)) {
229 r
= sharp_ls_probe_pdata(pdev
);
236 if (gpio_is_valid(ddata
->mo_gpio
)) {
237 r
= devm_gpio_request_one(&pdev
->dev
, ddata
->mo_gpio
,
238 GPIOF_OUT_INIT_LOW
, "lcd MO");
243 if (gpio_is_valid(ddata
->lr_gpio
)) {
244 r
= devm_gpio_request_one(&pdev
->dev
, ddata
->lr_gpio
,
245 GPIOF_OUT_INIT_HIGH
, "lcd LR");
250 if (gpio_is_valid(ddata
->ud_gpio
)) {
251 r
= devm_gpio_request_one(&pdev
->dev
, ddata
->ud_gpio
,
252 GPIOF_OUT_INIT_HIGH
, "lcd UD");
257 if (gpio_is_valid(ddata
->resb_gpio
)) {
258 r
= devm_gpio_request_one(&pdev
->dev
, ddata
->resb_gpio
,
259 GPIOF_OUT_INIT_LOW
, "lcd RESB");
264 if (gpio_is_valid(ddata
->ini_gpio
)) {
265 r
= devm_gpio_request_one(&pdev
->dev
, ddata
->ini_gpio
,
266 GPIOF_OUT_INIT_LOW
, "lcd INI");
271 ddata
->videomode
= sharp_ls_timings
;
273 dssdev
= &ddata
->dssdev
;
274 dssdev
->dev
= &pdev
->dev
;
275 dssdev
->driver
= &sharp_ls_ops
;
276 dssdev
->type
= OMAP_DISPLAY_TYPE_DPI
;
277 dssdev
->owner
= THIS_MODULE
;
278 dssdev
->panel
.timings
= ddata
->videomode
;
279 dssdev
->phy
.dpi
.data_lines
= ddata
->data_lines
;
281 r
= omapdss_register_display(dssdev
);
283 dev_err(&pdev
->dev
, "Failed to register panel\n");
291 omap_dss_put_device(ddata
->in
);
295 static int __exit
sharp_ls_remove(struct platform_device
*pdev
)
297 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
298 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
299 struct omap_dss_device
*in
= ddata
->in
;
301 omapdss_unregister_display(dssdev
);
303 sharp_ls_disable(dssdev
);
304 sharp_ls_disconnect(dssdev
);
306 omap_dss_put_device(in
);
311 static struct platform_driver sharp_ls_driver
= {
312 .probe
= sharp_ls_probe
,
313 .remove
= __exit_p(sharp_ls_remove
),
315 .name
= "panel-sharp-ls037v7dw01",
316 .owner
= THIS_MODULE
,
320 module_platform_driver(sharp_ls_driver
);
322 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
323 MODULE_DESCRIPTION("Sharp LS037V7DW01 Panel Driver");
324 MODULE_LICENSE("GPL");