blob: 64f6f42dbe92e78132e64fb7615bf509d67c84c3 [file] [log] [blame]
Tomi Valkeinen6077ce82013-05-31 13:39:31 +03001/*
2 * NEC NL8048HL11 Panel driver
3 *
4 * Copyright (C) 2010 Texas Instruments Inc.
5 * Author: Erik Gilling <konkers@android.com>
6 * Converted to new DSS device model: Tomi Valkeinen <tomi.valkeinen@ti.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14#include <linux/module.h>
15#include <linux/delay.h>
16#include <linux/spi/spi.h>
Arnd Bergmannd0196c82016-05-11 18:05:39 +020017#include <linux/gpio/consumer.h>
Tomi Valkeinenb36250d2014-05-16 12:39:29 +030018#include <linux/of_gpio.h>
Tomi Valkeinen6077ce82013-05-31 13:39:31 +030019
Peter Ujfalusi32043da2016-05-27 14:40:49 +030020#include "../dss/omapdss.h"
Tomi Valkeinen6077ce82013-05-31 13:39:31 +030021
22struct panel_drv_data {
23 struct omap_dss_device dssdev;
24 struct omap_dss_device *in;
25
26 struct omap_video_timings videomode;
27
28 int data_lines;
29
30 int res_gpio;
31 int qvga_gpio;
32
33 struct spi_device *spi;
34};
35
36#define LCD_XRES 800
37#define LCD_YRES 480
38/*
39 * NEC PIX Clock Ratings
40 * MIN:21.8MHz TYP:23.8MHz MAX:25.7MHz
41 */
Tomi Valkeinend8d789412013-04-10 14:12:14 +030042#define LCD_PIXEL_CLOCK 23800000
Tomi Valkeinen6077ce82013-05-31 13:39:31 +030043
44static const struct {
45 unsigned char addr;
46 unsigned char dat;
47} nec_8048_init_seq[] = {
48 { 3, 0x01 }, { 0, 0x00 }, { 1, 0x01 }, { 4, 0x00 }, { 5, 0x14 },
49 { 6, 0x24 }, { 16, 0xD7 }, { 17, 0x00 }, { 18, 0x00 }, { 19, 0x55 },
50 { 20, 0x01 }, { 21, 0x70 }, { 22, 0x1E }, { 23, 0x25 }, { 24, 0x25 },
51 { 25, 0x02 }, { 26, 0x02 }, { 27, 0xA0 }, { 32, 0x2F }, { 33, 0x0F },
52 { 34, 0x0F }, { 35, 0x0F }, { 36, 0x0F }, { 37, 0x0F }, { 38, 0x0F },
53 { 39, 0x00 }, { 40, 0x02 }, { 41, 0x02 }, { 42, 0x02 }, { 43, 0x0F },
54 { 44, 0x0F }, { 45, 0x0F }, { 46, 0x0F }, { 47, 0x0F }, { 48, 0x0F },
55 { 49, 0x0F }, { 50, 0x00 }, { 51, 0x02 }, { 52, 0x02 }, { 53, 0x02 },
56 { 80, 0x0C }, { 83, 0x42 }, { 84, 0x42 }, { 85, 0x41 }, { 86, 0x14 },
57 { 89, 0x88 }, { 90, 0x01 }, { 91, 0x00 }, { 92, 0x02 }, { 93, 0x0C },
58 { 94, 0x1C }, { 95, 0x27 }, { 98, 0x49 }, { 99, 0x27 }, { 102, 0x76 },
59 { 103, 0x27 }, { 112, 0x01 }, { 113, 0x0E }, { 114, 0x02 },
60 { 115, 0x0C }, { 118, 0x0C }, { 121, 0x30 }, { 130, 0x00 },
61 { 131, 0x00 }, { 132, 0xFC }, { 134, 0x00 }, { 136, 0x00 },
62 { 138, 0x00 }, { 139, 0x00 }, { 140, 0x00 }, { 141, 0xFC },
63 { 143, 0x00 }, { 145, 0x00 }, { 147, 0x00 }, { 148, 0x00 },
64 { 149, 0x00 }, { 150, 0xFC }, { 152, 0x00 }, { 154, 0x00 },
65 { 156, 0x00 }, { 157, 0x00 }, { 2, 0x00 },
66};
67
68static const struct omap_video_timings nec_8048_panel_timings = {
Peter Ujfalusi81899062016-09-22 14:06:46 +030069 .hactive = LCD_XRES,
Peter Ujfalusifb7f3c42016-09-22 14:06:47 +030070 .vactive = LCD_YRES,
Tomi Valkeinend8d789412013-04-10 14:12:14 +030071 .pixelclock = LCD_PIXEL_CLOCK,
Peter Ujfalusi0a30e152016-09-22 14:06:49 +030072 .hfront_porch = 6,
Peter Ujfalusi4dc22502016-09-22 14:06:48 +030073 .hsync_len = 1,
Peter Ujfalusia85f4a82016-09-22 14:06:50 +030074 .hback_porch = 4,
Peter Ujfalusi0996c682016-09-22 14:06:52 +030075 .vfront_porch = 3,
Peter Ujfalusid5bcf0a2016-09-22 14:06:51 +030076 .vsync_len = 1,
Peter Ujfalusi458540c2016-09-22 14:06:53 +030077 .vback_porch = 4,
Tomi Valkeinen6077ce82013-05-31 13:39:31 +030078
Tomi Valkeinen6077ce82013-05-31 13:39:31 +030079 .sync_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE,
Peter Ujfalusi6b44cd22016-09-22 14:06:57 +030080
Peter Ujfalusi3fa3ab42016-09-22 14:06:58 +030081 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW |
Peter Ujfalusif149e172016-09-22 14:07:00 +030082 DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_PIXDATA_POSEDGE,
Tomi Valkeinen6077ce82013-05-31 13:39:31 +030083};
84
85#define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
86
87static int nec_8048_spi_send(struct spi_device *spi, unsigned char reg_addr,
88 unsigned char reg_data)
89{
90 int ret = 0;
91 unsigned int cmd = 0, data = 0;
92
93 cmd = 0x0000 | reg_addr; /* register address write */
94 data = 0x0100 | reg_data; /* register data write */
95 data = (cmd << 16) | data;
96
97 ret = spi_write(spi, (unsigned char *)&data, 4);
98 if (ret)
99 pr_err("error in spi_write %x\n", data);
100
101 return ret;
102}
103
104static int init_nec_8048_wvga_lcd(struct spi_device *spi)
105{
106 unsigned int i;
107 /* Initialization Sequence */
108 /* nec_8048_spi_send(spi, REG, VAL) */
109 for (i = 0; i < (ARRAY_SIZE(nec_8048_init_seq) - 1); i++)
110 nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
111 nec_8048_init_seq[i].dat);
112 udelay(20);
113 nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
114 nec_8048_init_seq[i].dat);
115 return 0;
116}
117
118static int nec_8048_connect(struct omap_dss_device *dssdev)
119{
120 struct panel_drv_data *ddata = to_panel_data(dssdev);
121 struct omap_dss_device *in = ddata->in;
122 int r;
123
124 if (omapdss_device_is_connected(dssdev))
125 return 0;
126
127 r = in->ops.dpi->connect(in, dssdev);
128 if (r)
129 return r;
130
131 return 0;
132}
133
134static void nec_8048_disconnect(struct omap_dss_device *dssdev)
135{
136 struct panel_drv_data *ddata = to_panel_data(dssdev);
137 struct omap_dss_device *in = ddata->in;
138
139 if (!omapdss_device_is_connected(dssdev))
140 return;
141
142 in->ops.dpi->disconnect(in, dssdev);
143}
144
145static int nec_8048_enable(struct omap_dss_device *dssdev)
146{
147 struct panel_drv_data *ddata = to_panel_data(dssdev);
148 struct omap_dss_device *in = ddata->in;
149 int r;
150
151 if (!omapdss_device_is_connected(dssdev))
152 return -ENODEV;
153
154 if (omapdss_device_is_enabled(dssdev))
155 return 0;
156
Tomi Valkeinenb36250d2014-05-16 12:39:29 +0300157 if (ddata->data_lines)
158 in->ops.dpi->set_data_lines(in, ddata->data_lines);
Tomi Valkeinen6077ce82013-05-31 13:39:31 +0300159 in->ops.dpi->set_timings(in, &ddata->videomode);
160
161 r = in->ops.dpi->enable(in);
162 if (r)
163 return r;
164
165 if (gpio_is_valid(ddata->res_gpio))
166 gpio_set_value_cansleep(ddata->res_gpio, 1);
167
168 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
169
170 return 0;
171}
172
173static void nec_8048_disable(struct omap_dss_device *dssdev)
174{
175 struct panel_drv_data *ddata = to_panel_data(dssdev);
176 struct omap_dss_device *in = ddata->in;
177
178 if (!omapdss_device_is_enabled(dssdev))
179 return;
180
181 if (gpio_is_valid(ddata->res_gpio))
182 gpio_set_value_cansleep(ddata->res_gpio, 0);
183
184 in->ops.dpi->disable(in);
185
186 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
187}
188
189static void nec_8048_set_timings(struct omap_dss_device *dssdev,
190 struct omap_video_timings *timings)
191{
192 struct panel_drv_data *ddata = to_panel_data(dssdev);
193 struct omap_dss_device *in = ddata->in;
194
195 ddata->videomode = *timings;
196 dssdev->panel.timings = *timings;
197
198 in->ops.dpi->set_timings(in, timings);
199}
200
201static void nec_8048_get_timings(struct omap_dss_device *dssdev,
202 struct omap_video_timings *timings)
203{
204 struct panel_drv_data *ddata = to_panel_data(dssdev);
205
206 *timings = ddata->videomode;
207}
208
209static int nec_8048_check_timings(struct omap_dss_device *dssdev,
210 struct omap_video_timings *timings)
211{
212 struct panel_drv_data *ddata = to_panel_data(dssdev);
213 struct omap_dss_device *in = ddata->in;
214
215 return in->ops.dpi->check_timings(in, timings);
216}
217
218static struct omap_dss_driver nec_8048_ops = {
219 .connect = nec_8048_connect,
220 .disconnect = nec_8048_disconnect,
221
222 .enable = nec_8048_enable,
223 .disable = nec_8048_disable,
224
225 .set_timings = nec_8048_set_timings,
226 .get_timings = nec_8048_get_timings,
227 .check_timings = nec_8048_check_timings,
228
229 .get_resolution = omapdss_default_get_resolution,
230};
231
Tomi Valkeinenb36250d2014-05-16 12:39:29 +0300232static int nec_8048_probe_of(struct spi_device *spi)
233{
234 struct device_node *node = spi->dev.of_node;
235 struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
236 struct omap_dss_device *in;
237 int gpio;
238
239 gpio = of_get_named_gpio(node, "reset-gpios", 0);
240 if (!gpio_is_valid(gpio)) {
241 dev_err(&spi->dev, "failed to parse enable gpio\n");
242 return gpio;
243 }
244 ddata->res_gpio = gpio;
245
246 /* XXX the panel spec doesn't mention any QVGA pin?? */
247 ddata->qvga_gpio = -ENOENT;
248
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);
253 }
254
255 ddata->in = in;
256
257 return 0;
258}
259
Tomi Valkeinen6077ce82013-05-31 13:39:31 +0300260static int nec_8048_probe(struct spi_device *spi)
261{
262 struct panel_drv_data *ddata;
263 struct omap_dss_device *dssdev;
264 int r;
265
266 dev_dbg(&spi->dev, "%s\n", __func__);
267
268 spi->mode = SPI_MODE_0;
269 spi->bits_per_word = 32;
270
271 r = spi_setup(spi);
272 if (r < 0) {
273 dev_err(&spi->dev, "spi_setup failed: %d\n", r);
274 return r;
275 }
276
277 init_nec_8048_wvga_lcd(spi);
278
279 ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL);
280 if (ddata == NULL)
281 return -ENOMEM;
282
283 dev_set_drvdata(&spi->dev, ddata);
284
285 ddata->spi = spi;
286
Tomi Valkeinen367aa942016-02-18 17:27:55 +0200287 if (!spi->dev.of_node)
Tomi Valkeinen6077ce82013-05-31 13:39:31 +0300288 return -ENODEV;
Tomi Valkeinen367aa942016-02-18 17:27:55 +0200289
290 r = nec_8048_probe_of(spi);
291 if (r)
292 return r;
Tomi Valkeinen6077ce82013-05-31 13:39:31 +0300293
294 if (gpio_is_valid(ddata->qvga_gpio)) {
295 r = devm_gpio_request_one(&spi->dev, ddata->qvga_gpio,
296 GPIOF_OUT_INIT_HIGH, "lcd QVGA");
297 if (r)
298 goto err_gpio;
299 }
300
301 if (gpio_is_valid(ddata->res_gpio)) {
302 r = devm_gpio_request_one(&spi->dev, ddata->res_gpio,
303 GPIOF_OUT_INIT_LOW, "lcd RES");
304 if (r)
305 goto err_gpio;
306 }
307
308 ddata->videomode = nec_8048_panel_timings;
309
310 dssdev = &ddata->dssdev;
311 dssdev->dev = &spi->dev;
312 dssdev->driver = &nec_8048_ops;
313 dssdev->type = OMAP_DISPLAY_TYPE_DPI;
314 dssdev->owner = THIS_MODULE;
315 dssdev->panel.timings = ddata->videomode;
316
317 r = omapdss_register_display(dssdev);
318 if (r) {
319 dev_err(&spi->dev, "Failed to register panel\n");
320 goto err_reg;
321 }
322
323 return 0;
324
325err_reg:
326err_gpio:
327 omap_dss_put_device(ddata->in);
328 return r;
329}
330
331static int nec_8048_remove(struct spi_device *spi)
332{
333 struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
334 struct omap_dss_device *dssdev = &ddata->dssdev;
335 struct omap_dss_device *in = ddata->in;
336
337 dev_dbg(&ddata->spi->dev, "%s\n", __func__);
338
339 omapdss_unregister_display(dssdev);
340
341 nec_8048_disable(dssdev);
342 nec_8048_disconnect(dssdev);
343
344 omap_dss_put_device(in);
345
346 return 0;
347}
348
349#ifdef CONFIG_PM_SLEEP
350static int nec_8048_suspend(struct device *dev)
351{
352 struct spi_device *spi = to_spi_device(dev);
353
354 nec_8048_spi_send(spi, 2, 0x01);
355 mdelay(40);
356
357 return 0;
358}
359
360static int nec_8048_resume(struct device *dev)
361{
362 struct spi_device *spi = to_spi_device(dev);
363
364 /* reinitialize the panel */
365 spi_setup(spi);
366 nec_8048_spi_send(spi, 2, 0x00);
367 init_nec_8048_wvga_lcd(spi);
368
369 return 0;
370}
371static SIMPLE_DEV_PM_OPS(nec_8048_pm_ops, nec_8048_suspend,
372 nec_8048_resume);
373#define NEC_8048_PM_OPS (&nec_8048_pm_ops)
374#else
375#define NEC_8048_PM_OPS NULL
376#endif
377
Tomi Valkeinenb36250d2014-05-16 12:39:29 +0300378static const struct of_device_id nec_8048_of_match[] = {
379 { .compatible = "omapdss,nec,nl8048hl11", },
380 {},
381};
382
383MODULE_DEVICE_TABLE(of, nec_8048_of_match);
384
Tomi Valkeinen6077ce82013-05-31 13:39:31 +0300385static struct spi_driver nec_8048_driver = {
386 .driver = {
387 .name = "panel-nec-nl8048hl11",
Tomi Valkeinen6077ce82013-05-31 13:39:31 +0300388 .pm = NEC_8048_PM_OPS,
Tomi Valkeinenb36250d2014-05-16 12:39:29 +0300389 .of_match_table = nec_8048_of_match,
Tomi Valkeinen422ccbd2014-10-16 09:54:25 +0300390 .suppress_bind_attrs = true,
Tomi Valkeinen6077ce82013-05-31 13:39:31 +0300391 },
392 .probe = nec_8048_probe,
393 .remove = nec_8048_remove,
394};
395
396module_spi_driver(nec_8048_driver);
397
Tomi Valkeinenb36250d2014-05-16 12:39:29 +0300398MODULE_ALIAS("spi:nec,nl8048hl11");
Tomi Valkeinen6077ce82013-05-31 13:39:31 +0300399MODULE_AUTHOR("Erik Gilling <konkers@android.com>");
400MODULE_DESCRIPTION("NEC-NL8048HL11 Driver");
401MODULE_LICENSE("GPL");