Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[cris-mirror.git] / drivers / gpu / drm / omapdrm / displays / panel-lgphilips-lb035q02.c
blob57af22ce87c5f108b12219062d912d90b3362837
1 /*
2 * LG.Philips LB035Q02 LCD Panel driver
4 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
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 const struct videomode lb035q02_vm = {
23 .hactive = 320,
24 .vactive = 240,
26 .pixelclock = 6500000,
28 .hsync_len = 2,
29 .hfront_porch = 20,
30 .hback_porch = 68,
32 .vsync_len = 2,
33 .vfront_porch = 4,
34 .vback_porch = 18,
36 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW |
37 DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_SYNC_NEGEDGE |
38 DISPLAY_FLAGS_PIXDATA_POSEDGE,
40 * Note: According to the panel documentation:
41 * DE is active LOW
42 * DATA needs to be driven on the FALLING edge
46 struct panel_drv_data {
47 struct omap_dss_device dssdev;
48 struct omap_dss_device *in;
50 struct spi_device *spi;
52 struct videomode vm;
54 struct gpio_desc *enable_gpio;
57 #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
59 static int lb035q02_write_reg(struct spi_device *spi, u8 reg, u16 val)
61 struct spi_message msg;
62 struct spi_transfer index_xfer = {
63 .len = 3,
64 .cs_change = 1,
66 struct spi_transfer value_xfer = {
67 .len = 3,
69 u8 buffer[16];
71 spi_message_init(&msg);
73 /* register index */
74 buffer[0] = 0x70;
75 buffer[1] = 0x00;
76 buffer[2] = reg & 0x7f;
77 index_xfer.tx_buf = buffer;
78 spi_message_add_tail(&index_xfer, &msg);
80 /* register value */
81 buffer[4] = 0x72;
82 buffer[5] = val >> 8;
83 buffer[6] = val;
84 value_xfer.tx_buf = buffer + 4;
85 spi_message_add_tail(&value_xfer, &msg);
87 return spi_sync(spi, &msg);
90 static void init_lb035q02_panel(struct spi_device *spi)
92 /* Init sequence from page 28 of the lb035q02 spec */
93 lb035q02_write_reg(spi, 0x01, 0x6300);
94 lb035q02_write_reg(spi, 0x02, 0x0200);
95 lb035q02_write_reg(spi, 0x03, 0x0177);
96 lb035q02_write_reg(spi, 0x04, 0x04c7);
97 lb035q02_write_reg(spi, 0x05, 0xffc0);
98 lb035q02_write_reg(spi, 0x06, 0xe806);
99 lb035q02_write_reg(spi, 0x0a, 0x4008);
100 lb035q02_write_reg(spi, 0x0b, 0x0000);
101 lb035q02_write_reg(spi, 0x0d, 0x0030);
102 lb035q02_write_reg(spi, 0x0e, 0x2800);
103 lb035q02_write_reg(spi, 0x0f, 0x0000);
104 lb035q02_write_reg(spi, 0x16, 0x9f80);
105 lb035q02_write_reg(spi, 0x17, 0x0a0f);
106 lb035q02_write_reg(spi, 0x1e, 0x00c1);
107 lb035q02_write_reg(spi, 0x30, 0x0300);
108 lb035q02_write_reg(spi, 0x31, 0x0007);
109 lb035q02_write_reg(spi, 0x32, 0x0000);
110 lb035q02_write_reg(spi, 0x33, 0x0000);
111 lb035q02_write_reg(spi, 0x34, 0x0707);
112 lb035q02_write_reg(spi, 0x35, 0x0004);
113 lb035q02_write_reg(spi, 0x36, 0x0302);
114 lb035q02_write_reg(spi, 0x37, 0x0202);
115 lb035q02_write_reg(spi, 0x3a, 0x0a0d);
116 lb035q02_write_reg(spi, 0x3b, 0x0806);
119 static int lb035q02_connect(struct omap_dss_device *dssdev)
121 struct panel_drv_data *ddata = to_panel_data(dssdev);
122 struct omap_dss_device *in = ddata->in;
123 int r;
125 if (omapdss_device_is_connected(dssdev))
126 return 0;
128 r = in->ops.dpi->connect(in, dssdev);
129 if (r)
130 return r;
132 init_lb035q02_panel(ddata->spi);
134 return 0;
137 static void lb035q02_disconnect(struct omap_dss_device *dssdev)
139 struct panel_drv_data *ddata = to_panel_data(dssdev);
140 struct omap_dss_device *in = ddata->in;
142 if (!omapdss_device_is_connected(dssdev))
143 return;
145 in->ops.dpi->disconnect(in, dssdev);
148 static int lb035q02_enable(struct omap_dss_device *dssdev)
150 struct panel_drv_data *ddata = to_panel_data(dssdev);
151 struct omap_dss_device *in = ddata->in;
152 int r;
154 if (!omapdss_device_is_connected(dssdev))
155 return -ENODEV;
157 if (omapdss_device_is_enabled(dssdev))
158 return 0;
160 in->ops.dpi->set_timings(in, &ddata->vm);
162 r = in->ops.dpi->enable(in);
163 if (r)
164 return r;
166 if (ddata->enable_gpio)
167 gpiod_set_value_cansleep(ddata->enable_gpio, 1);
169 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
171 return 0;
174 static void lb035q02_disable(struct omap_dss_device *dssdev)
176 struct panel_drv_data *ddata = to_panel_data(dssdev);
177 struct omap_dss_device *in = ddata->in;
179 if (!omapdss_device_is_enabled(dssdev))
180 return;
182 if (ddata->enable_gpio)
183 gpiod_set_value_cansleep(ddata->enable_gpio, 0);
185 in->ops.dpi->disable(in);
187 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
190 static void lb035q02_set_timings(struct omap_dss_device *dssdev,
191 struct videomode *vm)
193 struct panel_drv_data *ddata = to_panel_data(dssdev);
194 struct omap_dss_device *in = ddata->in;
196 ddata->vm = *vm;
197 dssdev->panel.vm = *vm;
199 in->ops.dpi->set_timings(in, vm);
202 static void lb035q02_get_timings(struct omap_dss_device *dssdev,
203 struct videomode *vm)
205 struct panel_drv_data *ddata = to_panel_data(dssdev);
207 *vm = ddata->vm;
210 static int lb035q02_check_timings(struct omap_dss_device *dssdev,
211 struct videomode *vm)
213 struct panel_drv_data *ddata = to_panel_data(dssdev);
214 struct omap_dss_device *in = ddata->in;
216 return in->ops.dpi->check_timings(in, vm);
219 static struct omap_dss_driver lb035q02_ops = {
220 .connect = lb035q02_connect,
221 .disconnect = lb035q02_disconnect,
223 .enable = lb035q02_enable,
224 .disable = lb035q02_disable,
226 .set_timings = lb035q02_set_timings,
227 .get_timings = lb035q02_get_timings,
228 .check_timings = lb035q02_check_timings,
231 static int lb035q02_probe_of(struct spi_device *spi)
233 struct device_node *node = spi->dev.of_node;
234 struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
235 struct omap_dss_device *in;
236 struct gpio_desc *gpio;
238 gpio = devm_gpiod_get(&spi->dev, "enable", GPIOD_OUT_LOW);
239 if (IS_ERR(gpio)) {
240 dev_err(&spi->dev, "failed to parse enable gpio\n");
241 return PTR_ERR(gpio);
244 ddata->enable_gpio = gpio;
246 in = omapdss_of_find_source_for_first_ep(node);
247 if (IS_ERR(in)) {
248 dev_err(&spi->dev, "failed to find video source\n");
249 return PTR_ERR(in);
252 ddata->in = in;
254 return 0;
257 static int lb035q02_panel_spi_probe(struct spi_device *spi)
259 struct panel_drv_data *ddata;
260 struct omap_dss_device *dssdev;
261 int r;
263 ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL);
264 if (ddata == NULL)
265 return -ENOMEM;
267 dev_set_drvdata(&spi->dev, ddata);
269 ddata->spi = spi;
271 if (!spi->dev.of_node)
272 return -ENODEV;
274 r = lb035q02_probe_of(spi);
275 if (r)
276 return r;
278 ddata->vm = lb035q02_vm;
280 dssdev = &ddata->dssdev;
281 dssdev->dev = &spi->dev;
282 dssdev->driver = &lb035q02_ops;
283 dssdev->type = OMAP_DISPLAY_TYPE_DPI;
284 dssdev->owner = THIS_MODULE;
285 dssdev->panel.vm = ddata->vm;
287 r = omapdss_register_display(dssdev);
288 if (r) {
289 dev_err(&spi->dev, "Failed to register panel\n");
290 goto err_reg;
293 return 0;
295 err_reg:
296 omap_dss_put_device(ddata->in);
297 return r;
300 static int lb035q02_panel_spi_remove(struct spi_device *spi)
302 struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
303 struct omap_dss_device *dssdev = &ddata->dssdev;
304 struct omap_dss_device *in = ddata->in;
306 omapdss_unregister_display(dssdev);
308 lb035q02_disable(dssdev);
309 lb035q02_disconnect(dssdev);
311 omap_dss_put_device(in);
313 return 0;
316 static const struct of_device_id lb035q02_of_match[] = {
317 { .compatible = "omapdss,lgphilips,lb035q02", },
321 MODULE_DEVICE_TABLE(of, lb035q02_of_match);
323 static struct spi_driver lb035q02_spi_driver = {
324 .probe = lb035q02_panel_spi_probe,
325 .remove = lb035q02_panel_spi_remove,
326 .driver = {
327 .name = "panel_lgphilips_lb035q02",
328 .of_match_table = lb035q02_of_match,
329 .suppress_bind_attrs = true,
333 module_spi_driver(lb035q02_spi_driver);
335 MODULE_ALIAS("spi:lgphilips,lb035q02");
336 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
337 MODULE_DESCRIPTION("LG.Philips LB035Q02 LCD Panel driver");
338 MODULE_LICENSE("GPL");