Input: xpad - add support for Xbox1 PDP Camo series gamepad
[linux/fpc-iii.git] / drivers / gpu / drm / omapdrm / displays / panel-lgphilips-lb035q02.c
blob6dfb96cea293e2c1cdc0deeff32096b9057710e4
1 /*
2 * LG.Philips LB035Q02 LCD Panel driver
4 * Copyright (C) 2013 Texas Instruments
5 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
6 * Based on a driver by: Steve Sakoman <steve@sakoman.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published by
10 * the Free Software Foundation.
13 #include <linux/module.h>
14 #include <linux/delay.h>
15 #include <linux/spi/spi.h>
16 #include <linux/mutex.h>
17 #include <linux/gpio.h>
18 #include <linux/gpio/consumer.h>
20 #include "../dss/omapdss.h"
22 static struct omap_video_timings lb035q02_timings = {
23 .x_res = 320,
24 .y_res = 240,
26 .pixelclock = 6500000,
28 .hsw = 2,
29 .hfp = 20,
30 .hbp = 68,
32 .vsw = 2,
33 .vfp = 4,
34 .vbp = 18,
36 .vsync_level = OMAPDSS_SIG_ACTIVE_LOW,
37 .hsync_level = OMAPDSS_SIG_ACTIVE_LOW,
38 .data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE,
39 .de_level = OMAPDSS_SIG_ACTIVE_HIGH,
40 .sync_pclk_edge = OMAPDSS_DRIVE_SIG_FALLING_EDGE,
43 struct panel_drv_data {
44 struct omap_dss_device dssdev;
45 struct omap_dss_device *in;
47 struct spi_device *spi;
49 int data_lines;
51 struct omap_video_timings videomode;
53 struct gpio_desc *enable_gpio;
56 #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
58 static int lb035q02_write_reg(struct spi_device *spi, u8 reg, u16 val)
60 struct spi_message msg;
61 struct spi_transfer index_xfer = {
62 .len = 3,
63 .cs_change = 1,
65 struct spi_transfer value_xfer = {
66 .len = 3,
68 u8 buffer[16];
70 spi_message_init(&msg);
72 /* register index */
73 buffer[0] = 0x70;
74 buffer[1] = 0x00;
75 buffer[2] = reg & 0x7f;
76 index_xfer.tx_buf = buffer;
77 spi_message_add_tail(&index_xfer, &msg);
79 /* register value */
80 buffer[4] = 0x72;
81 buffer[5] = val >> 8;
82 buffer[6] = val;
83 value_xfer.tx_buf = buffer + 4;
84 spi_message_add_tail(&value_xfer, &msg);
86 return spi_sync(spi, &msg);
89 static void init_lb035q02_panel(struct spi_device *spi)
91 /* Init sequence from page 28 of the lb035q02 spec */
92 lb035q02_write_reg(spi, 0x01, 0x6300);
93 lb035q02_write_reg(spi, 0x02, 0x0200);
94 lb035q02_write_reg(spi, 0x03, 0x0177);
95 lb035q02_write_reg(spi, 0x04, 0x04c7);
96 lb035q02_write_reg(spi, 0x05, 0xffc0);
97 lb035q02_write_reg(spi, 0x06, 0xe806);
98 lb035q02_write_reg(spi, 0x0a, 0x4008);
99 lb035q02_write_reg(spi, 0x0b, 0x0000);
100 lb035q02_write_reg(spi, 0x0d, 0x0030);
101 lb035q02_write_reg(spi, 0x0e, 0x2800);
102 lb035q02_write_reg(spi, 0x0f, 0x0000);
103 lb035q02_write_reg(spi, 0x16, 0x9f80);
104 lb035q02_write_reg(spi, 0x17, 0x0a0f);
105 lb035q02_write_reg(spi, 0x1e, 0x00c1);
106 lb035q02_write_reg(spi, 0x30, 0x0300);
107 lb035q02_write_reg(spi, 0x31, 0x0007);
108 lb035q02_write_reg(spi, 0x32, 0x0000);
109 lb035q02_write_reg(spi, 0x33, 0x0000);
110 lb035q02_write_reg(spi, 0x34, 0x0707);
111 lb035q02_write_reg(spi, 0x35, 0x0004);
112 lb035q02_write_reg(spi, 0x36, 0x0302);
113 lb035q02_write_reg(spi, 0x37, 0x0202);
114 lb035q02_write_reg(spi, 0x3a, 0x0a0d);
115 lb035q02_write_reg(spi, 0x3b, 0x0806);
118 static int lb035q02_connect(struct omap_dss_device *dssdev)
120 struct panel_drv_data *ddata = to_panel_data(dssdev);
121 struct omap_dss_device *in = ddata->in;
122 int r;
124 if (omapdss_device_is_connected(dssdev))
125 return 0;
127 r = in->ops.dpi->connect(in, dssdev);
128 if (r)
129 return r;
131 init_lb035q02_panel(ddata->spi);
133 return 0;
136 static void lb035q02_disconnect(struct omap_dss_device *dssdev)
138 struct panel_drv_data *ddata = to_panel_data(dssdev);
139 struct omap_dss_device *in = ddata->in;
141 if (!omapdss_device_is_connected(dssdev))
142 return;
144 in->ops.dpi->disconnect(in, dssdev);
147 static int lb035q02_enable(struct omap_dss_device *dssdev)
149 struct panel_drv_data *ddata = to_panel_data(dssdev);
150 struct omap_dss_device *in = ddata->in;
151 int r;
153 if (!omapdss_device_is_connected(dssdev))
154 return -ENODEV;
156 if (omapdss_device_is_enabled(dssdev))
157 return 0;
159 if (ddata->data_lines)
160 in->ops.dpi->set_data_lines(in, ddata->data_lines);
161 in->ops.dpi->set_timings(in, &ddata->videomode);
163 r = in->ops.dpi->enable(in);
164 if (r)
165 return r;
167 if (ddata->enable_gpio)
168 gpiod_set_value_cansleep(ddata->enable_gpio, 1);
170 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
172 return 0;
175 static void lb035q02_disable(struct omap_dss_device *dssdev)
177 struct panel_drv_data *ddata = to_panel_data(dssdev);
178 struct omap_dss_device *in = ddata->in;
180 if (!omapdss_device_is_enabled(dssdev))
181 return;
183 if (ddata->enable_gpio)
184 gpiod_set_value_cansleep(ddata->enable_gpio, 0);
186 in->ops.dpi->disable(in);
188 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
191 static void lb035q02_set_timings(struct omap_dss_device *dssdev,
192 struct omap_video_timings *timings)
194 struct panel_drv_data *ddata = to_panel_data(dssdev);
195 struct omap_dss_device *in = ddata->in;
197 ddata->videomode = *timings;
198 dssdev->panel.timings = *timings;
200 in->ops.dpi->set_timings(in, timings);
203 static void lb035q02_get_timings(struct omap_dss_device *dssdev,
204 struct omap_video_timings *timings)
206 struct panel_drv_data *ddata = to_panel_data(dssdev);
208 *timings = ddata->videomode;
211 static int lb035q02_check_timings(struct omap_dss_device *dssdev,
212 struct omap_video_timings *timings)
214 struct panel_drv_data *ddata = to_panel_data(dssdev);
215 struct omap_dss_device *in = ddata->in;
217 return in->ops.dpi->check_timings(in, timings);
220 static struct omap_dss_driver lb035q02_ops = {
221 .connect = lb035q02_connect,
222 .disconnect = lb035q02_disconnect,
224 .enable = lb035q02_enable,
225 .disable = lb035q02_disable,
227 .set_timings = lb035q02_set_timings,
228 .get_timings = lb035q02_get_timings,
229 .check_timings = lb035q02_check_timings,
231 .get_resolution = omapdss_default_get_resolution,
234 static int lb035q02_probe_of(struct spi_device *spi)
236 struct device_node *node = spi->dev.of_node;
237 struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
238 struct omap_dss_device *in;
239 struct gpio_desc *gpio;
241 gpio = devm_gpiod_get(&spi->dev, "enable", GPIOD_OUT_LOW);
242 if (IS_ERR(gpio)) {
243 dev_err(&spi->dev, "failed to parse enable gpio\n");
244 return PTR_ERR(gpio);
247 ddata->enable_gpio = gpio;
249 in = omapdss_of_find_source_for_first_ep(node);
250 if (IS_ERR(in)) {
251 dev_err(&spi->dev, "failed to find video source\n");
252 return PTR_ERR(in);
255 ddata->in = in;
257 return 0;
260 static int lb035q02_panel_spi_probe(struct spi_device *spi)
262 struct panel_drv_data *ddata;
263 struct omap_dss_device *dssdev;
264 int r;
266 ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL);
267 if (ddata == NULL)
268 return -ENOMEM;
270 dev_set_drvdata(&spi->dev, ddata);
272 ddata->spi = spi;
274 if (!spi->dev.of_node)
275 return -ENODEV;
277 r = lb035q02_probe_of(spi);
278 if (r)
279 return r;
281 ddata->videomode = lb035q02_timings;
283 dssdev = &ddata->dssdev;
284 dssdev->dev = &spi->dev;
285 dssdev->driver = &lb035q02_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);
292 if (r) {
293 dev_err(&spi->dev, "Failed to register panel\n");
294 goto err_reg;
297 return 0;
299 err_reg:
300 omap_dss_put_device(ddata->in);
301 return r;
304 static int lb035q02_panel_spi_remove(struct spi_device *spi)
306 struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
307 struct omap_dss_device *dssdev = &ddata->dssdev;
308 struct omap_dss_device *in = ddata->in;
310 omapdss_unregister_display(dssdev);
312 lb035q02_disable(dssdev);
313 lb035q02_disconnect(dssdev);
315 omap_dss_put_device(in);
317 return 0;
320 static const struct of_device_id lb035q02_of_match[] = {
321 { .compatible = "omapdss,lgphilips,lb035q02", },
325 MODULE_DEVICE_TABLE(of, lb035q02_of_match);
327 static struct spi_driver lb035q02_spi_driver = {
328 .probe = lb035q02_panel_spi_probe,
329 .remove = lb035q02_panel_spi_remove,
330 .driver = {
331 .name = "panel_lgphilips_lb035q02",
332 .of_match_table = lb035q02_of_match,
333 .suppress_bind_attrs = true,
337 module_spi_driver(lb035q02_spi_driver);
339 MODULE_ALIAS("spi:lgphilips,lb035q02");
340 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
341 MODULE_DESCRIPTION("LG.Philips LB035Q02 LCD Panel driver");
342 MODULE_LICENSE("GPL");