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 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW |
53 DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_SYNC_NEGEDGE |
54 DISPLAY_FLAGS_PIXDATA_POSEDGE,
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 if (ddata->data_lines)
99 in->ops.dpi->set_data_lines(in, ddata->data_lines);
100 in->ops.dpi->set_timings(in, &ddata->videomode);
103 r = regulator_enable(ddata->vcc);
108 r = in->ops.dpi->enable(in);
110 regulator_disable(ddata->vcc);
114 /* wait couple of vsyncs until enabling the LCD */
117 if (ddata->resb_gpio)
118 gpiod_set_value_cansleep(ddata->resb_gpio, 1);
121 gpiod_set_value_cansleep(ddata->ini_gpio, 1);
123 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
128 static void sharp_ls_disable(struct omap_dss_device *dssdev)
130 struct panel_drv_data *ddata = to_panel_data(dssdev);
131 struct omap_dss_device *in = ddata->in;
133 if (!omapdss_device_is_enabled(dssdev))
137 gpiod_set_value_cansleep(ddata->ini_gpio, 0);
139 if (ddata->resb_gpio)
140 gpiod_set_value_cansleep(ddata->resb_gpio, 0);
142 /* wait at least 5 vsyncs after disabling the LCD */
146 in->ops.dpi->disable(in);
149 regulator_disable(ddata->vcc);
151 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
154 static void sharp_ls_set_timings(struct omap_dss_device *dssdev,
155 struct omap_video_timings *timings)
157 struct panel_drv_data *ddata = to_panel_data(dssdev);
158 struct omap_dss_device *in = ddata->in;
160 ddata->videomode = *timings;
161 dssdev->panel.timings = *timings;
163 in->ops.dpi->set_timings(in, timings);
166 static void sharp_ls_get_timings(struct omap_dss_device *dssdev,
167 struct omap_video_timings *timings)
169 struct panel_drv_data *ddata = to_panel_data(dssdev);
171 *timings = ddata->videomode;
174 static int sharp_ls_check_timings(struct omap_dss_device *dssdev,
175 struct omap_video_timings *timings)
177 struct panel_drv_data *ddata = to_panel_data(dssdev);
178 struct omap_dss_device *in = ddata->in;
180 return in->ops.dpi->check_timings(in, timings);
183 static struct omap_dss_driver sharp_ls_ops = {
184 .connect = sharp_ls_connect,
185 .disconnect = sharp_ls_disconnect,
187 .enable = sharp_ls_enable,
188 .disable = sharp_ls_disable,
190 .set_timings = sharp_ls_set_timings,
191 .get_timings = sharp_ls_get_timings,
192 .check_timings = sharp_ls_check_timings,
194 .get_resolution = omapdss_default_get_resolution,
197 static int sharp_ls_get_gpio_of(struct device *dev, int index, int val,
198 const char *desc, struct gpio_desc **gpiod)
200 struct gpio_desc *gd;
204 gd = devm_gpiod_get_index(dev, desc, index, GPIOD_OUT_LOW);
212 static int sharp_ls_probe_of(struct platform_device *pdev)
214 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
215 struct device_node *node = pdev->dev.of_node;
216 struct omap_dss_device *in;
219 ddata->vcc = devm_regulator_get(&pdev->dev, "envdd");
220 if (IS_ERR(ddata->vcc)) {
221 dev_err(&pdev->dev, "failed to get regulator\n");
222 return PTR_ERR(ddata->vcc);
226 r = sharp_ls_get_gpio_of(&pdev->dev, 0, 0, "enable", &ddata->ini_gpio);
231 r = sharp_ls_get_gpio_of(&pdev->dev, 0, 0, "reset", &ddata->resb_gpio);
236 r = sharp_ls_get_gpio_of(&pdev->dev, 0, 0, "mode", &ddata->mo_gpio);
241 r = sharp_ls_get_gpio_of(&pdev->dev, 1, 1, "mode", &ddata->lr_gpio);
246 r = sharp_ls_get_gpio_of(&pdev->dev, 2, 1, "mode", &ddata->ud_gpio);
250 in = omapdss_of_find_source_for_first_ep(node);
252 dev_err(&pdev->dev, "failed to find video source\n");
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 if (!pdev->dev.of_node)
276 r = sharp_ls_probe_of(pdev);
280 ddata->videomode = sharp_ls_timings;
282 dssdev = &ddata->dssdev;
283 dssdev->dev = &pdev->dev;
284 dssdev->driver = &sharp_ls_ops;
285 dssdev->type = OMAP_DISPLAY_TYPE_DPI;
286 dssdev->owner = THIS_MODULE;
287 dssdev->panel.timings = ddata->videomode;
288 dssdev->phy.dpi.data_lines = ddata->data_lines;
290 r = omapdss_register_display(dssdev);
292 dev_err(&pdev->dev, "Failed to register panel\n");
299 omap_dss_put_device(ddata->in);
303 static int __exit sharp_ls_remove(struct platform_device *pdev)
305 struct panel_drv_data *ddata = platform_get_drvdata(pdev);
306 struct omap_dss_device *dssdev = &ddata->dssdev;
307 struct omap_dss_device *in = ddata->in;
309 omapdss_unregister_display(dssdev);
311 sharp_ls_disable(dssdev);
312 sharp_ls_disconnect(dssdev);
314 omap_dss_put_device(in);
319 static const struct of_device_id sharp_ls_of_match[] = {
320 { .compatible = "omapdss,sharp,ls037v7dw01", },
324 MODULE_DEVICE_TABLE(of, sharp_ls_of_match);
326 static struct platform_driver sharp_ls_driver = {
327 .probe = sharp_ls_probe,
328 .remove = __exit_p(sharp_ls_remove),
330 .name = "panel-sharp-ls037v7dw01",
331 .of_match_table = sharp_ls_of_match,
332 .suppress_bind_attrs = true,
336 module_platform_driver(sharp_ls_driver);
338 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
339 MODULE_DESCRIPTION("Sharp LS037V7DW01 Panel Driver");
340 MODULE_LICENSE("GPL");