Linux 4.19.133
[linux/fpc-iii.git] / drivers / video / fbdev / omap2 / omapfb / displays / panel-nec-nl8048hl11.c
bloba2cbadd3eca301fbadf3a9e3e90b466e3c4bc741
1 /*
2 * NEC NL8048HL11 Panel driver
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>
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.
14 #include <linux/module.h>
15 #include <linux/delay.h>
16 #include <linux/spi/spi.h>
17 #include <linux/fb.h>
18 #include <linux/gpio.h>
19 #include <linux/of_gpio.h>
21 #include <video/omapfb_dss.h>
23 struct panel_drv_data {
24 struct omap_dss_device dssdev;
25 struct omap_dss_device *in;
27 struct omap_video_timings videomode;
29 int data_lines;
31 int res_gpio;
32 int qvga_gpio;
34 struct spi_device *spi;
37 #define LCD_XRES 800
38 #define LCD_YRES 480
40 * NEC PIX Clock Ratings
41 * MIN:21.8MHz TYP:23.8MHz MAX:25.7MHz
43 #define LCD_PIXEL_CLOCK 23800000
45 static const struct {
46 unsigned char addr;
47 unsigned char dat;
48 } nec_8048_init_seq[] = {
49 { 3, 0x01 }, { 0, 0x00 }, { 1, 0x01 }, { 4, 0x00 }, { 5, 0x14 },
50 { 6, 0x24 }, { 16, 0xD7 }, { 17, 0x00 }, { 18, 0x00 }, { 19, 0x55 },
51 { 20, 0x01 }, { 21, 0x70 }, { 22, 0x1E }, { 23, 0x25 }, { 24, 0x25 },
52 { 25, 0x02 }, { 26, 0x02 }, { 27, 0xA0 }, { 32, 0x2F }, { 33, 0x0F },
53 { 34, 0x0F }, { 35, 0x0F }, { 36, 0x0F }, { 37, 0x0F }, { 38, 0x0F },
54 { 39, 0x00 }, { 40, 0x02 }, { 41, 0x02 }, { 42, 0x02 }, { 43, 0x0F },
55 { 44, 0x0F }, { 45, 0x0F }, { 46, 0x0F }, { 47, 0x0F }, { 48, 0x0F },
56 { 49, 0x0F }, { 50, 0x00 }, { 51, 0x02 }, { 52, 0x02 }, { 53, 0x02 },
57 { 80, 0x0C }, { 83, 0x42 }, { 84, 0x42 }, { 85, 0x41 }, { 86, 0x14 },
58 { 89, 0x88 }, { 90, 0x01 }, { 91, 0x00 }, { 92, 0x02 }, { 93, 0x0C },
59 { 94, 0x1C }, { 95, 0x27 }, { 98, 0x49 }, { 99, 0x27 }, { 102, 0x76 },
60 { 103, 0x27 }, { 112, 0x01 }, { 113, 0x0E }, { 114, 0x02 },
61 { 115, 0x0C }, { 118, 0x0C }, { 121, 0x30 }, { 130, 0x00 },
62 { 131, 0x00 }, { 132, 0xFC }, { 134, 0x00 }, { 136, 0x00 },
63 { 138, 0x00 }, { 139, 0x00 }, { 140, 0x00 }, { 141, 0xFC },
64 { 143, 0x00 }, { 145, 0x00 }, { 147, 0x00 }, { 148, 0x00 },
65 { 149, 0x00 }, { 150, 0xFC }, { 152, 0x00 }, { 154, 0x00 },
66 { 156, 0x00 }, { 157, 0x00 }, { 2, 0x00 },
69 static const struct omap_video_timings nec_8048_panel_timings = {
70 .x_res = LCD_XRES,
71 .y_res = LCD_YRES,
72 .pixelclock = LCD_PIXEL_CLOCK,
73 .hfp = 6,
74 .hsw = 1,
75 .hbp = 4,
76 .vfp = 3,
77 .vsw = 1,
78 .vbp = 4,
80 .vsync_level = OMAPDSS_SIG_ACTIVE_LOW,
81 .hsync_level = OMAPDSS_SIG_ACTIVE_LOW,
82 .data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE,
83 .de_level = OMAPDSS_SIG_ACTIVE_HIGH,
84 .sync_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE,
87 #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
89 static int nec_8048_spi_send(struct spi_device *spi, unsigned char reg_addr,
90 unsigned char reg_data)
92 int ret = 0;
93 unsigned int cmd = 0, data = 0;
95 cmd = 0x0000 | reg_addr; /* register address write */
96 data = 0x0100 | reg_data; /* register data write */
97 data = (cmd << 16) | data;
99 ret = spi_write(spi, (unsigned char *)&data, 4);
100 if (ret)
101 pr_err("error in spi_write %x\n", data);
103 return ret;
106 static int init_nec_8048_wvga_lcd(struct spi_device *spi)
108 unsigned int i;
109 /* Initialization Sequence */
110 /* nec_8048_spi_send(spi, REG, VAL) */
111 for (i = 0; i < (ARRAY_SIZE(nec_8048_init_seq) - 1); i++)
112 nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
113 nec_8048_init_seq[i].dat);
114 udelay(20);
115 nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
116 nec_8048_init_seq[i].dat);
117 return 0;
120 static int nec_8048_connect(struct omap_dss_device *dssdev)
122 struct panel_drv_data *ddata = to_panel_data(dssdev);
123 struct omap_dss_device *in = ddata->in;
124 int r;
126 if (omapdss_device_is_connected(dssdev))
127 return 0;
129 r = in->ops.dpi->connect(in, dssdev);
130 if (r)
131 return r;
133 return 0;
136 static void nec_8048_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 nec_8048_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 (gpio_is_valid(ddata->res_gpio))
168 gpio_set_value_cansleep(ddata->res_gpio, 1);
170 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
172 return 0;
175 static void nec_8048_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 (gpio_is_valid(ddata->res_gpio))
184 gpio_set_value_cansleep(ddata->res_gpio, 0);
186 in->ops.dpi->disable(in);
188 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
191 static void nec_8048_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 nec_8048_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 nec_8048_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 nec_8048_ops = {
221 .connect = nec_8048_connect,
222 .disconnect = nec_8048_disconnect,
224 .enable = nec_8048_enable,
225 .disable = nec_8048_disable,
227 .set_timings = nec_8048_set_timings,
228 .get_timings = nec_8048_get_timings,
229 .check_timings = nec_8048_check_timings,
231 .get_resolution = omapdss_default_get_resolution,
235 static int nec_8048_probe_of(struct spi_device *spi)
237 struct device_node *node = spi->dev.of_node;
238 struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
239 struct omap_dss_device *in;
240 int gpio;
242 gpio = of_get_named_gpio(node, "reset-gpios", 0);
243 if (!gpio_is_valid(gpio)) {
244 dev_err(&spi->dev, "failed to parse enable gpio\n");
245 return gpio;
247 ddata->res_gpio = gpio;
249 /* XXX the panel spec doesn't mention any QVGA pin?? */
250 ddata->qvga_gpio = -ENOENT;
252 in = omapdss_of_find_source_for_first_ep(node);
253 if (IS_ERR(in)) {
254 dev_err(&spi->dev, "failed to find video source\n");
255 return PTR_ERR(in);
258 ddata->in = in;
260 return 0;
263 static int nec_8048_probe(struct spi_device *spi)
265 struct panel_drv_data *ddata;
266 struct omap_dss_device *dssdev;
267 int r;
269 dev_dbg(&spi->dev, "%s\n", __func__);
271 if (!spi->dev.of_node)
272 return -ENODEV;
274 spi->mode = SPI_MODE_0;
275 spi->bits_per_word = 32;
277 r = spi_setup(spi);
278 if (r < 0) {
279 dev_err(&spi->dev, "spi_setup failed: %d\n", r);
280 return r;
283 init_nec_8048_wvga_lcd(spi);
285 ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL);
286 if (ddata == NULL)
287 return -ENOMEM;
289 dev_set_drvdata(&spi->dev, ddata);
291 ddata->spi = spi;
293 r = nec_8048_probe_of(spi);
294 if (r)
295 return r;
297 if (gpio_is_valid(ddata->qvga_gpio)) {
298 r = devm_gpio_request_one(&spi->dev, ddata->qvga_gpio,
299 GPIOF_OUT_INIT_HIGH, "lcd QVGA");
300 if (r)
301 goto err_gpio;
304 if (gpio_is_valid(ddata->res_gpio)) {
305 r = devm_gpio_request_one(&spi->dev, ddata->res_gpio,
306 GPIOF_OUT_INIT_LOW, "lcd RES");
307 if (r)
308 goto err_gpio;
311 ddata->videomode = nec_8048_panel_timings;
313 dssdev = &ddata->dssdev;
314 dssdev->dev = &spi->dev;
315 dssdev->driver = &nec_8048_ops;
316 dssdev->type = OMAP_DISPLAY_TYPE_DPI;
317 dssdev->owner = THIS_MODULE;
318 dssdev->panel.timings = ddata->videomode;
320 r = omapdss_register_display(dssdev);
321 if (r) {
322 dev_err(&spi->dev, "Failed to register panel\n");
323 goto err_reg;
326 return 0;
328 err_reg:
329 err_gpio:
330 omap_dss_put_device(ddata->in);
331 return r;
334 static int nec_8048_remove(struct spi_device *spi)
336 struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
337 struct omap_dss_device *dssdev = &ddata->dssdev;
338 struct omap_dss_device *in = ddata->in;
340 dev_dbg(&ddata->spi->dev, "%s\n", __func__);
342 omapdss_unregister_display(dssdev);
344 nec_8048_disable(dssdev);
345 nec_8048_disconnect(dssdev);
347 omap_dss_put_device(in);
349 return 0;
352 #ifdef CONFIG_PM_SLEEP
353 static int nec_8048_suspend(struct device *dev)
355 struct spi_device *spi = to_spi_device(dev);
357 nec_8048_spi_send(spi, 2, 0x01);
358 mdelay(40);
360 return 0;
363 static int nec_8048_resume(struct device *dev)
365 struct spi_device *spi = to_spi_device(dev);
367 /* reinitialize the panel */
368 spi_setup(spi);
369 nec_8048_spi_send(spi, 2, 0x00);
370 init_nec_8048_wvga_lcd(spi);
372 return 0;
374 static SIMPLE_DEV_PM_OPS(nec_8048_pm_ops, nec_8048_suspend,
375 nec_8048_resume);
376 #define NEC_8048_PM_OPS (&nec_8048_pm_ops)
377 #else
378 #define NEC_8048_PM_OPS NULL
379 #endif
381 static const struct of_device_id nec_8048_of_match[] = {
382 { .compatible = "omapdss,nec,nl8048hl11", },
386 MODULE_DEVICE_TABLE(of, nec_8048_of_match);
388 static struct spi_driver nec_8048_driver = {
389 .driver = {
390 .name = "panel-nec-nl8048hl11",
391 .pm = NEC_8048_PM_OPS,
392 .of_match_table = nec_8048_of_match,
393 .suppress_bind_attrs = true,
395 .probe = nec_8048_probe,
396 .remove = nec_8048_remove,
399 module_spi_driver(nec_8048_driver);
401 MODULE_ALIAS("spi:nec,nl8048hl11");
402 MODULE_AUTHOR("Erik Gilling <konkers@android.com>");
403 MODULE_DESCRIPTION("NEC-NL8048HL11 Driver");
404 MODULE_LICENSE("GPL");