2 * LCD panel driver for Sharp LS037V7DW01
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/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 gpio_desc
*resb_gpio
; /* low = reset active min 20 us */
30 struct gpio_desc
*ini_gpio
; /* high = power on */
31 struct gpio_desc
*mo_gpio
; /* low = 480x640, high = 240x320 */
32 struct gpio_desc
*lr_gpio
; /* high = conventional horizontal scanning */
33 struct gpio_desc
*ud_gpio
; /* high = conventional vertical scanning */
36 static const struct videomode sharp_ls_vm
= {
40 .pixelclock
= 19200000,
50 .flags
= DISPLAY_FLAGS_HSYNC_LOW
| DISPLAY_FLAGS_VSYNC_LOW
|
51 DISPLAY_FLAGS_DE_HIGH
| DISPLAY_FLAGS_SYNC_NEGEDGE
|
52 DISPLAY_FLAGS_PIXDATA_POSEDGE
,
54 * Note: According to the panel documentation:
55 * DATA needs to be driven on the FALLING edge
59 #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
61 static int sharp_ls_connect(struct omap_dss_device
*dssdev
)
63 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
64 struct omap_dss_device
*in
;
67 if (omapdss_device_is_connected(dssdev
))
70 in
= omapdss_of_find_source_for_first_ep(dssdev
->dev
->of_node
);
72 dev_err(dssdev
->dev
, "failed to find video source\n");
76 r
= in
->ops
.dpi
->connect(in
, dssdev
);
78 omap_dss_put_device(in
);
86 static void sharp_ls_disconnect(struct omap_dss_device
*dssdev
)
88 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
89 struct omap_dss_device
*in
= ddata
->in
;
91 if (!omapdss_device_is_connected(dssdev
))
94 in
->ops
.dpi
->disconnect(in
, dssdev
);
96 omap_dss_put_device(in
);
100 static int sharp_ls_enable(struct omap_dss_device
*dssdev
)
102 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
103 struct omap_dss_device
*in
= ddata
->in
;
106 if (!omapdss_device_is_connected(dssdev
))
109 if (omapdss_device_is_enabled(dssdev
))
112 in
->ops
.dpi
->set_timings(in
, &ddata
->vm
);
115 r
= regulator_enable(ddata
->vcc
);
120 r
= in
->ops
.dpi
->enable(in
);
122 regulator_disable(ddata
->vcc
);
126 /* wait couple of vsyncs until enabling the LCD */
129 if (ddata
->resb_gpio
)
130 gpiod_set_value_cansleep(ddata
->resb_gpio
, 1);
133 gpiod_set_value_cansleep(ddata
->ini_gpio
, 1);
135 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
140 static void sharp_ls_disable(struct omap_dss_device
*dssdev
)
142 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
143 struct omap_dss_device
*in
= ddata
->in
;
145 if (!omapdss_device_is_enabled(dssdev
))
149 gpiod_set_value_cansleep(ddata
->ini_gpio
, 0);
151 if (ddata
->resb_gpio
)
152 gpiod_set_value_cansleep(ddata
->resb_gpio
, 0);
154 /* wait at least 5 vsyncs after disabling the LCD */
158 in
->ops
.dpi
->disable(in
);
161 regulator_disable(ddata
->vcc
);
163 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
166 static void sharp_ls_set_timings(struct omap_dss_device
*dssdev
,
167 struct videomode
*vm
)
169 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
170 struct omap_dss_device
*in
= ddata
->in
;
173 dssdev
->panel
.vm
= *vm
;
175 in
->ops
.dpi
->set_timings(in
, vm
);
178 static void sharp_ls_get_timings(struct omap_dss_device
*dssdev
,
179 struct videomode
*vm
)
181 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
186 static int sharp_ls_check_timings(struct omap_dss_device
*dssdev
,
187 struct videomode
*vm
)
189 struct panel_drv_data
*ddata
= to_panel_data(dssdev
);
190 struct omap_dss_device
*in
= ddata
->in
;
192 return in
->ops
.dpi
->check_timings(in
, vm
);
195 static struct omap_dss_driver sharp_ls_ops
= {
196 .connect
= sharp_ls_connect
,
197 .disconnect
= sharp_ls_disconnect
,
199 .enable
= sharp_ls_enable
,
200 .disable
= sharp_ls_disable
,
202 .set_timings
= sharp_ls_set_timings
,
203 .get_timings
= sharp_ls_get_timings
,
204 .check_timings
= sharp_ls_check_timings
,
207 static int sharp_ls_get_gpio_of(struct device
*dev
, int index
, int val
,
208 const char *desc
, struct gpio_desc
**gpiod
)
210 struct gpio_desc
*gd
;
214 gd
= devm_gpiod_get_index(dev
, desc
, index
, GPIOD_OUT_LOW
);
222 static int sharp_ls_probe_of(struct platform_device
*pdev
)
224 struct panel_drv_data
*ddata
= platform_get_drvdata(pdev
);
227 ddata
->vcc
= devm_regulator_get(&pdev
->dev
, "envdd");
228 if (IS_ERR(ddata
->vcc
)) {
229 dev_err(&pdev
->dev
, "failed to get regulator\n");
230 return PTR_ERR(ddata
->vcc
);
234 r
= sharp_ls_get_gpio_of(&pdev
->dev
, 0, 0, "enable", &ddata
->ini_gpio
);
239 r
= sharp_ls_get_gpio_of(&pdev
->dev
, 0, 0, "reset", &ddata
->resb_gpio
);
244 r
= sharp_ls_get_gpio_of(&pdev
->dev
, 0, 0, "mode", &ddata
->mo_gpio
);
249 r
= sharp_ls_get_gpio_of(&pdev
->dev
, 1, 1, "mode", &ddata
->lr_gpio
);
254 r
= sharp_ls_get_gpio_of(&pdev
->dev
, 2, 1, "mode", &ddata
->ud_gpio
);
261 static int sharp_ls_probe(struct platform_device
*pdev
)
263 struct panel_drv_data
*ddata
;
264 struct omap_dss_device
*dssdev
;
267 ddata
= devm_kzalloc(&pdev
->dev
, sizeof(*ddata
), GFP_KERNEL
);
271 platform_set_drvdata(pdev
, ddata
);
273 r
= sharp_ls_probe_of(pdev
);
277 ddata
->vm
= sharp_ls_vm
;
279 dssdev
= &ddata
->dssdev
;
280 dssdev
->dev
= &pdev
->dev
;
281 dssdev
->driver
= &sharp_ls_ops
;
282 dssdev
->type
= OMAP_DISPLAY_TYPE_DPI
;
283 dssdev
->owner
= THIS_MODULE
;
284 dssdev
->panel
.vm
= ddata
->vm
;
286 r
= omapdss_register_display(dssdev
);
288 dev_err(&pdev
->dev
, "Failed to register panel\n");
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
;
300 omapdss_unregister_display(dssdev
);
302 sharp_ls_disable(dssdev
);
303 sharp_ls_disconnect(dssdev
);
308 static const struct of_device_id sharp_ls_of_match
[] = {
309 { .compatible
= "omapdss,sharp,ls037v7dw01", },
313 MODULE_DEVICE_TABLE(of
, sharp_ls_of_match
);
315 static struct platform_driver sharp_ls_driver
= {
316 .probe
= sharp_ls_probe
,
317 .remove
= __exit_p(sharp_ls_remove
),
319 .name
= "panel-sharp-ls037v7dw01",
320 .of_match_table
= sharp_ls_of_match
,
321 .suppress_bind_attrs
= true,
325 module_platform_driver(sharp_ls_driver
);
327 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
328 MODULE_DESCRIPTION("Sharp LS037V7DW01 Panel Driver");
329 MODULE_LICENSE("GPL");