]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - drivers/gpu/drm/omapdrm/displays/panel-nec-nl8048hl11.c
bf53676263ada2ee29d40f7b97071c343a9b31a0
[mirror_ubuntu-hirsute-kernel.git] / drivers / gpu / drm / omapdrm / displays / panel-nec-nl8048hl11.c
1 /*
2 * NEC NL8048HL11 Panel driver
3 *
4 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
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>
17 #include <linux/gpio/consumer.h>
18 #include <linux/of_gpio.h>
19
20 #include "../dss/omapdss.h"
21
22 struct panel_drv_data {
23 struct omap_dss_device dssdev;
24 struct omap_dss_device *in;
25
26 struct videomode vm;
27
28 int res_gpio;
29 int qvga_gpio;
30
31 struct spi_device *spi;
32 };
33
34 #define LCD_XRES 800
35 #define LCD_YRES 480
36 /*
37 * NEC PIX Clock Ratings
38 * MIN:21.8MHz TYP:23.8MHz MAX:25.7MHz
39 */
40 #define LCD_PIXEL_CLOCK 23800000
41
42 static const struct {
43 unsigned char addr;
44 unsigned char dat;
45 } nec_8048_init_seq[] = {
46 { 3, 0x01 }, { 0, 0x00 }, { 1, 0x01 }, { 4, 0x00 }, { 5, 0x14 },
47 { 6, 0x24 }, { 16, 0xD7 }, { 17, 0x00 }, { 18, 0x00 }, { 19, 0x55 },
48 { 20, 0x01 }, { 21, 0x70 }, { 22, 0x1E }, { 23, 0x25 }, { 24, 0x25 },
49 { 25, 0x02 }, { 26, 0x02 }, { 27, 0xA0 }, { 32, 0x2F }, { 33, 0x0F },
50 { 34, 0x0F }, { 35, 0x0F }, { 36, 0x0F }, { 37, 0x0F }, { 38, 0x0F },
51 { 39, 0x00 }, { 40, 0x02 }, { 41, 0x02 }, { 42, 0x02 }, { 43, 0x0F },
52 { 44, 0x0F }, { 45, 0x0F }, { 46, 0x0F }, { 47, 0x0F }, { 48, 0x0F },
53 { 49, 0x0F }, { 50, 0x00 }, { 51, 0x02 }, { 52, 0x02 }, { 53, 0x02 },
54 { 80, 0x0C }, { 83, 0x42 }, { 84, 0x42 }, { 85, 0x41 }, { 86, 0x14 },
55 { 89, 0x88 }, { 90, 0x01 }, { 91, 0x00 }, { 92, 0x02 }, { 93, 0x0C },
56 { 94, 0x1C }, { 95, 0x27 }, { 98, 0x49 }, { 99, 0x27 }, { 102, 0x76 },
57 { 103, 0x27 }, { 112, 0x01 }, { 113, 0x0E }, { 114, 0x02 },
58 { 115, 0x0C }, { 118, 0x0C }, { 121, 0x30 }, { 130, 0x00 },
59 { 131, 0x00 }, { 132, 0xFC }, { 134, 0x00 }, { 136, 0x00 },
60 { 138, 0x00 }, { 139, 0x00 }, { 140, 0x00 }, { 141, 0xFC },
61 { 143, 0x00 }, { 145, 0x00 }, { 147, 0x00 }, { 148, 0x00 },
62 { 149, 0x00 }, { 150, 0xFC }, { 152, 0x00 }, { 154, 0x00 },
63 { 156, 0x00 }, { 157, 0x00 }, { 2, 0x00 },
64 };
65
66 static const struct videomode nec_8048_panel_vm = {
67 .hactive = LCD_XRES,
68 .vactive = LCD_YRES,
69 .pixelclock = LCD_PIXEL_CLOCK,
70 .hfront_porch = 6,
71 .hsync_len = 1,
72 .hback_porch = 4,
73 .vfront_porch = 3,
74 .vsync_len = 1,
75 .vback_porch = 4,
76
77 .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW |
78 DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_SYNC_POSEDGE |
79 DISPLAY_FLAGS_PIXDATA_POSEDGE,
80 };
81
82 #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
83
84 static int nec_8048_spi_send(struct spi_device *spi, unsigned char reg_addr,
85 unsigned char reg_data)
86 {
87 int ret = 0;
88 unsigned int cmd = 0, data = 0;
89
90 cmd = 0x0000 | reg_addr; /* register address write */
91 data = 0x0100 | reg_data; /* register data write */
92 data = (cmd << 16) | data;
93
94 ret = spi_write(spi, (unsigned char *)&data, 4);
95 if (ret)
96 pr_err("error in spi_write %x\n", data);
97
98 return ret;
99 }
100
101 static int init_nec_8048_wvga_lcd(struct spi_device *spi)
102 {
103 unsigned int i;
104 /* Initialization Sequence */
105 /* nec_8048_spi_send(spi, REG, VAL) */
106 for (i = 0; i < (ARRAY_SIZE(nec_8048_init_seq) - 1); i++)
107 nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
108 nec_8048_init_seq[i].dat);
109 udelay(20);
110 nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
111 nec_8048_init_seq[i].dat);
112 return 0;
113 }
114
115 static int nec_8048_connect(struct omap_dss_device *dssdev)
116 {
117 struct panel_drv_data *ddata = to_panel_data(dssdev);
118 struct omap_dss_device *in = ddata->in;
119 int r;
120
121 if (omapdss_device_is_connected(dssdev))
122 return 0;
123
124 r = in->ops.dpi->connect(in, dssdev);
125 if (r)
126 return r;
127
128 return 0;
129 }
130
131 static void nec_8048_disconnect(struct omap_dss_device *dssdev)
132 {
133 struct panel_drv_data *ddata = to_panel_data(dssdev);
134 struct omap_dss_device *in = ddata->in;
135
136 if (!omapdss_device_is_connected(dssdev))
137 return;
138
139 in->ops.dpi->disconnect(in, dssdev);
140 }
141
142 static int nec_8048_enable(struct omap_dss_device *dssdev)
143 {
144 struct panel_drv_data *ddata = to_panel_data(dssdev);
145 struct omap_dss_device *in = ddata->in;
146 int r;
147
148 if (!omapdss_device_is_connected(dssdev))
149 return -ENODEV;
150
151 if (omapdss_device_is_enabled(dssdev))
152 return 0;
153
154 in->ops.dpi->set_timings(in, &ddata->vm);
155
156 r = in->ops.dpi->enable(in);
157 if (r)
158 return r;
159
160 if (gpio_is_valid(ddata->res_gpio))
161 gpio_set_value_cansleep(ddata->res_gpio, 1);
162
163 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
164
165 return 0;
166 }
167
168 static void nec_8048_disable(struct omap_dss_device *dssdev)
169 {
170 struct panel_drv_data *ddata = to_panel_data(dssdev);
171 struct omap_dss_device *in = ddata->in;
172
173 if (!omapdss_device_is_enabled(dssdev))
174 return;
175
176 if (gpio_is_valid(ddata->res_gpio))
177 gpio_set_value_cansleep(ddata->res_gpio, 0);
178
179 in->ops.dpi->disable(in);
180
181 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
182 }
183
184 static void nec_8048_set_timings(struct omap_dss_device *dssdev,
185 struct videomode *vm)
186 {
187 struct panel_drv_data *ddata = to_panel_data(dssdev);
188 struct omap_dss_device *in = ddata->in;
189
190 ddata->vm = *vm;
191 dssdev->panel.vm = *vm;
192
193 in->ops.dpi->set_timings(in, vm);
194 }
195
196 static void nec_8048_get_timings(struct omap_dss_device *dssdev,
197 struct videomode *vm)
198 {
199 struct panel_drv_data *ddata = to_panel_data(dssdev);
200
201 *vm = ddata->vm;
202 }
203
204 static int nec_8048_check_timings(struct omap_dss_device *dssdev,
205 struct videomode *vm)
206 {
207 struct panel_drv_data *ddata = to_panel_data(dssdev);
208 struct omap_dss_device *in = ddata->in;
209
210 return in->ops.dpi->check_timings(in, vm);
211 }
212
213 static struct omap_dss_driver nec_8048_ops = {
214 .connect = nec_8048_connect,
215 .disconnect = nec_8048_disconnect,
216
217 .enable = nec_8048_enable,
218 .disable = nec_8048_disable,
219
220 .set_timings = nec_8048_set_timings,
221 .get_timings = nec_8048_get_timings,
222 .check_timings = nec_8048_check_timings,
223 };
224
225 static int nec_8048_probe_of(struct spi_device *spi)
226 {
227 struct device_node *node = spi->dev.of_node;
228 struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
229 struct omap_dss_device *in;
230 int gpio;
231
232 gpio = of_get_named_gpio(node, "reset-gpios", 0);
233 if (!gpio_is_valid(gpio)) {
234 dev_err(&spi->dev, "failed to parse enable gpio\n");
235 return gpio;
236 }
237 ddata->res_gpio = gpio;
238
239 /* XXX the panel spec doesn't mention any QVGA pin?? */
240 ddata->qvga_gpio = -ENOENT;
241
242 in = omapdss_of_find_source_for_first_ep(node);
243 if (IS_ERR(in)) {
244 dev_err(&spi->dev, "failed to find video source\n");
245 return PTR_ERR(in);
246 }
247
248 ddata->in = in;
249
250 return 0;
251 }
252
253 static int nec_8048_probe(struct spi_device *spi)
254 {
255 struct panel_drv_data *ddata;
256 struct omap_dss_device *dssdev;
257 int r;
258
259 dev_dbg(&spi->dev, "%s\n", __func__);
260
261 spi->mode = SPI_MODE_0;
262 spi->bits_per_word = 32;
263
264 r = spi_setup(spi);
265 if (r < 0) {
266 dev_err(&spi->dev, "spi_setup failed: %d\n", r);
267 return r;
268 }
269
270 init_nec_8048_wvga_lcd(spi);
271
272 ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL);
273 if (ddata == NULL)
274 return -ENOMEM;
275
276 dev_set_drvdata(&spi->dev, ddata);
277
278 ddata->spi = spi;
279
280 if (!spi->dev.of_node)
281 return -ENODEV;
282
283 r = nec_8048_probe_of(spi);
284 if (r)
285 return r;
286
287 if (gpio_is_valid(ddata->qvga_gpio)) {
288 r = devm_gpio_request_one(&spi->dev, ddata->qvga_gpio,
289 GPIOF_OUT_INIT_HIGH, "lcd QVGA");
290 if (r)
291 goto err_gpio;
292 }
293
294 if (gpio_is_valid(ddata->res_gpio)) {
295 r = devm_gpio_request_one(&spi->dev, ddata->res_gpio,
296 GPIOF_OUT_INIT_LOW, "lcd RES");
297 if (r)
298 goto err_gpio;
299 }
300
301 ddata->vm = nec_8048_panel_vm;
302
303 dssdev = &ddata->dssdev;
304 dssdev->dev = &spi->dev;
305 dssdev->driver = &nec_8048_ops;
306 dssdev->type = OMAP_DISPLAY_TYPE_DPI;
307 dssdev->owner = THIS_MODULE;
308 dssdev->panel.vm = ddata->vm;
309
310 r = omapdss_register_display(dssdev);
311 if (r) {
312 dev_err(&spi->dev, "Failed to register panel\n");
313 goto err_reg;
314 }
315
316 return 0;
317
318 err_reg:
319 err_gpio:
320 omap_dss_put_device(ddata->in);
321 return r;
322 }
323
324 static int nec_8048_remove(struct spi_device *spi)
325 {
326 struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
327 struct omap_dss_device *dssdev = &ddata->dssdev;
328 struct omap_dss_device *in = ddata->in;
329
330 dev_dbg(&ddata->spi->dev, "%s\n", __func__);
331
332 omapdss_unregister_display(dssdev);
333
334 nec_8048_disable(dssdev);
335 nec_8048_disconnect(dssdev);
336
337 omap_dss_put_device(in);
338
339 return 0;
340 }
341
342 #ifdef CONFIG_PM_SLEEP
343 static int nec_8048_suspend(struct device *dev)
344 {
345 struct spi_device *spi = to_spi_device(dev);
346
347 nec_8048_spi_send(spi, 2, 0x01);
348 mdelay(40);
349
350 return 0;
351 }
352
353 static int nec_8048_resume(struct device *dev)
354 {
355 struct spi_device *spi = to_spi_device(dev);
356
357 /* reinitialize the panel */
358 spi_setup(spi);
359 nec_8048_spi_send(spi, 2, 0x00);
360 init_nec_8048_wvga_lcd(spi);
361
362 return 0;
363 }
364 static SIMPLE_DEV_PM_OPS(nec_8048_pm_ops, nec_8048_suspend,
365 nec_8048_resume);
366 #define NEC_8048_PM_OPS (&nec_8048_pm_ops)
367 #else
368 #define NEC_8048_PM_OPS NULL
369 #endif
370
371 static const struct of_device_id nec_8048_of_match[] = {
372 { .compatible = "omapdss,nec,nl8048hl11", },
373 {},
374 };
375
376 MODULE_DEVICE_TABLE(of, nec_8048_of_match);
377
378 static struct spi_driver nec_8048_driver = {
379 .driver = {
380 .name = "panel-nec-nl8048hl11",
381 .pm = NEC_8048_PM_OPS,
382 .of_match_table = nec_8048_of_match,
383 .suppress_bind_attrs = true,
384 },
385 .probe = nec_8048_probe,
386 .remove = nec_8048_remove,
387 };
388
389 module_spi_driver(nec_8048_driver);
390
391 MODULE_ALIAS("spi:nec,nl8048hl11");
392 MODULE_AUTHOR("Erik Gilling <konkers@android.com>");
393 MODULE_DESCRIPTION("NEC-NL8048HL11 Driver");
394 MODULE_LICENSE("GPL");