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/consumer.h>
14 #include <linux/module.h>
16 #include <linux/platform_device.h>
17 #include <linux/slab.h>
18 #include <linux/regulator/consumer.h>
20 #include "../dss/omapdss.h"
22 struct panel_drv_data
{
23 struct omap_dss_device dssdev
;
24 struct omap_dss_device
*in
;
25 struct regulator
*vcc
;
29 struct omap_video_timings videomode
;
31 struct gpio_desc
*resb_gpio
; /* low = reset active min 20 us */
32 struct gpio_desc
*ini_gpio
; /* high = power on */
33 struct gpio_desc
*mo_gpio
; /* low = 480x640, high = 240x320 */
34 struct gpio_desc
*lr_gpio
; /* high = conventional horizontal scanning */
35 struct gpio_desc
*ud_gpio
; /* high = conventional vertical scanning */
38 static const struct omap_video_timings sharp_ls_timings
= {
42 .pixelclock
= 19200000,
52 .sync_pclk_edge
= OMAPDSS_DRIVE_SIG_FALLING_EDGE
,
54 .flags
= DISPLAY_FLAGS_HSYNC_LOW
| DISPLAY_FLAGS_VSYNC_LOW
|
55 DISPLAY_FLAGS_DE_HIGH
| DISPLAY_FLAGS_PIXDATA_POSEDGE
,
58 #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
60 static int sharp_ls_connect(struct omap_dss_device
*dssdev
)
62 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
63 struct omap_dss_device
*in
= ddata
->in
;
66 if (omapdss_device_is_connected(dssdev
))
69 r
= in
->ops
.dpi
->connect(in
, dssdev
);
76 static void sharp_ls_disconnect(struct omap_dss_device
*dssdev
)
78 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
79 struct omap_dss_device
*in
= ddata
->in
;
81 if (!omapdss_device_is_connected(dssdev
))
84 in
->ops
.dpi
->disconnect(in
, dssdev
);
87 static int sharp_ls_enable(struct omap_dss_device
*dssdev
)
89 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
90 struct omap_dss_device
*in
= ddata
->in
;
93 if (!omapdss_device_is_connected(dssdev
))
96 if (omapdss_device_is_enabled(dssdev
))
99 if (ddata
->data_lines
)
100 in
->ops
.dpi
->set_data_lines(in
, ddata
->data_lines
);
101 in
->ops
.dpi
->set_timings(in
, &ddata
->videomode
);
104 r
= regulator_enable(ddata
->vcc
);
109 r
= in
->ops
.dpi
->enable(in
);
111 regulator_disable(ddata
->vcc
);
115 /* wait couple of vsyncs until enabling the LCD */
118 if (ddata
->resb_gpio
)
119 gpiod_set_value_cansleep(ddata
->resb_gpio
, 1);
122 gpiod_set_value_cansleep(ddata
->ini_gpio
, 1);
124 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
129 static void sharp_ls_disable(struct omap_dss_device
*dssdev
)
131 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
132 struct omap_dss_device
*in
= ddata
->in
;
134 if (!omapdss_device_is_enabled(dssdev
))
138 gpiod_set_value_cansleep(ddata
->ini_gpio
, 0);
140 if (ddata
->resb_gpio
)
141 gpiod_set_value_cansleep(ddata
->resb_gpio
, 0);
143 /* wait at least 5 vsyncs after disabling the LCD */
147 in
->ops
.dpi
->disable(in
);
150 regulator_disable(ddata
->vcc
);
152 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
155 static void sharp_ls_set_timings(struct omap_dss_device
*dssdev
,
156 struct omap_video_timings
*timings
)
158 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
159 struct omap_dss_device
*in
= ddata
->in
;
161 ddata
->videomode
= *timings
;
162 dssdev
->panel
.timings
= *timings
;
164 in
->ops
.dpi
->set_timings(in
, timings
);
167 static void sharp_ls_get_timings(struct omap_dss_device
*dssdev
,
168 struct omap_video_timings
*timings
)
170 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
172 *timings
= ddata
->videomode
;
175 static int sharp_ls_check_timings(struct omap_dss_device
*dssdev
,
176 struct omap_video_timings
*timings
)
178 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
179 struct omap_dss_device
*in
= ddata
->in
;
181 return in
->ops
.dpi
->check_timings(in
, timings
);
184 static struct omap_dss_driver sharp_ls_ops
= {
185 .connect
= sharp_ls_connect
,
186 .disconnect
= sharp_ls_disconnect
,
188 .enable
= sharp_ls_enable
,
189 .disable
= sharp_ls_disable
,
191 .set_timings
= sharp_ls_set_timings
,
192 .get_timings
= sharp_ls_get_timings
,
193 .check_timings
= sharp_ls_check_timings
,
195 .get_resolution
= omapdss_default_get_resolution
,
198 static int sharp_ls_get_gpio_of(struct device
*dev
, int index
, int val
,
199 const char *desc
, struct gpio_desc
**gpiod
)
201 struct gpio_desc
*gd
;
205 gd
= devm_gpiod_get_index(dev
, desc
, index
, GPIOD_OUT_LOW
);
213 static int sharp_ls_probe_of(struct platform_device
*pdev
)
215 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
216 struct device_node
*node
= pdev
->dev
.of_node
;
217 struct omap_dss_device
*in
;
220 ddata
->vcc
= devm_regulator_get(&pdev
->dev
, "envdd");
221 if (IS_ERR(ddata
->vcc
)) {
222 dev_err(&pdev
->dev
, "failed to get regulator\n");
223 return PTR_ERR(ddata
->vcc
);
227 r
= sharp_ls_get_gpio_of(&pdev
->dev
, 0, 0, "enable", &ddata
->ini_gpio
);
232 r
= sharp_ls_get_gpio_of(&pdev
->dev
, 0, 0, "reset", &ddata
->resb_gpio
);
237 r
= sharp_ls_get_gpio_of(&pdev
->dev
, 0, 0, "mode", &ddata
->mo_gpio
);
242 r
= sharp_ls_get_gpio_of(&pdev
->dev
, 1, 1, "mode", &ddata
->lr_gpio
);
247 r
= sharp_ls_get_gpio_of(&pdev
->dev
, 2, 1, "mode", &ddata
->ud_gpio
);
251 in
= omapdss_of_find_source_for_first_ep(node
);
253 dev_err(&pdev
->dev
, "failed to find video source\n");
262 static int sharp_ls_probe(struct platform_device
*pdev
)
264 struct panel_drv_data
*ddata
;
265 struct omap_dss_device
*dssdev
;
268 ddata
= devm_kzalloc(&pdev
->dev
, sizeof(*ddata
), GFP_KERNEL
);
272 platform_set_drvdata(pdev
, ddata
);
274 if (!pdev
->dev
.of_node
)
277 r
= sharp_ls_probe_of(pdev
);
281 ddata
->videomode
= sharp_ls_timings
;
283 dssdev
= &ddata
->dssdev
;
284 dssdev
->dev
= &pdev
->dev
;
285 dssdev
->driver
= &sharp_ls_ops
;
286 dssdev
->type
= OMAP_DISPLAY_TYPE_DPI
;
287 dssdev
->owner
= THIS_MODULE
;
288 dssdev
->panel
.timings
= ddata
->videomode
;
289 dssdev
->phy
.dpi
.data_lines
= ddata
->data_lines
;
291 r
= omapdss_register_display(dssdev
);
293 dev_err(&pdev
->dev
, "Failed to register panel\n");
300 omap_dss_put_device(ddata
->in
);
304 static int __exit
sharp_ls_remove(struct platform_device
*pdev
)
306 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
307 struct omap_dss_device
*dssdev
= &ddata
->dssdev
;
308 struct omap_dss_device
*in
= ddata
->in
;
310 omapdss_unregister_display(dssdev
);
312 sharp_ls_disable(dssdev
);
313 sharp_ls_disconnect(dssdev
);
315 omap_dss_put_device(in
);
320 static const struct of_device_id sharp_ls_of_match
[] = {
321 { .compatible
= "omapdss,sharp,ls037v7dw01", },
325 MODULE_DEVICE_TABLE(of
, sharp_ls_of_match
);
327 static struct platform_driver sharp_ls_driver
= {
328 .probe
= sharp_ls_probe
,
329 .remove
= __exit_p(sharp_ls_remove
),
331 .name
= "panel-sharp-ls037v7dw01",
332 .of_match_table
= sharp_ls_of_match
,
333 .suppress_bind_attrs
= true,
337 module_platform_driver(sharp_ls_driver
);
339 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
340 MODULE_DESCRIPTION("Sharp LS037V7DW01 Panel Driver");
341 MODULE_LICENSE("GPL");