Input: xpad - add support for Xbox1 PDP Camo series gamepad
[linux/fpc-iii.git] / drivers / gpu / drm / omapdrm / displays / panel-nec-nl8048hl11.c
blob9f3d6f48f3e16658722065d9afeb3ff8cda6f179
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/gpio/consumer.h>
18 #include <linux/of_gpio.h>
20 #include "../dss/omapdss.h"
22 struct panel_drv_data {
23 struct omap_dss_device dssdev;
24 struct omap_dss_device *in;
26 struct omap_video_timings videomode;
28 int data_lines;
30 int res_gpio;
31 int qvga_gpio;
33 struct spi_device *spi;
36 #define LCD_XRES 800
37 #define LCD_YRES 480
39 * NEC PIX Clock Ratings
40 * MIN:21.8MHz TYP:23.8MHz MAX:25.7MHz
42 #define LCD_PIXEL_CLOCK 23800000
44 static 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 },
68 static const struct omap_video_timings nec_8048_panel_timings = {
69 .x_res = LCD_XRES,
70 .y_res = LCD_YRES,
71 .pixelclock = LCD_PIXEL_CLOCK,
72 .hfp = 6,
73 .hsw = 1,
74 .hbp = 4,
75 .vfp = 3,
76 .vsw = 1,
77 .vbp = 4,
79 .vsync_level = OMAPDSS_SIG_ACTIVE_LOW,
80 .hsync_level = OMAPDSS_SIG_ACTIVE_LOW,
81 .data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE,
82 .de_level = OMAPDSS_SIG_ACTIVE_HIGH,
83 .sync_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE,
86 #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
88 static int nec_8048_spi_send(struct spi_device *spi, unsigned char reg_addr,
89 unsigned char reg_data)
91 int ret = 0;
92 unsigned int cmd = 0, data = 0;
94 cmd = 0x0000 | reg_addr; /* register address write */
95 data = 0x0100 | reg_data; /* register data write */
96 data = (cmd << 16) | data;
98 ret = spi_write(spi, (unsigned char *)&data, 4);
99 if (ret)
100 pr_err("error in spi_write %x\n", data);
102 return ret;
105 static int init_nec_8048_wvga_lcd(struct spi_device *spi)
107 unsigned int i;
108 /* Initialization Sequence */
109 /* nec_8048_spi_send(spi, REG, VAL) */
110 for (i = 0; i < (ARRAY_SIZE(nec_8048_init_seq) - 1); i++)
111 nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
112 nec_8048_init_seq[i].dat);
113 udelay(20);
114 nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
115 nec_8048_init_seq[i].dat);
116 return 0;
119 static int nec_8048_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 return 0;
135 static void nec_8048_disconnect(struct omap_dss_device *dssdev)
137 struct panel_drv_data *ddata = to_panel_data(dssdev);
138 struct omap_dss_device *in = ddata->in;
140 if (!omapdss_device_is_connected(dssdev))
141 return;
143 in->ops.dpi->disconnect(in, dssdev);
146 static int nec_8048_enable(struct omap_dss_device *dssdev)
148 struct panel_drv_data *ddata = to_panel_data(dssdev);
149 struct omap_dss_device *in = ddata->in;
150 int r;
152 if (!omapdss_device_is_connected(dssdev))
153 return -ENODEV;
155 if (omapdss_device_is_enabled(dssdev))
156 return 0;
158 if (ddata->data_lines)
159 in->ops.dpi->set_data_lines(in, ddata->data_lines);
160 in->ops.dpi->set_timings(in, &ddata->videomode);
162 r = in->ops.dpi->enable(in);
163 if (r)
164 return r;
166 if (gpio_is_valid(ddata->res_gpio))
167 gpio_set_value_cansleep(ddata->res_gpio, 1);
169 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
171 return 0;
174 static void nec_8048_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 (gpio_is_valid(ddata->res_gpio))
183 gpio_set_value_cansleep(ddata->res_gpio, 0);
185 in->ops.dpi->disable(in);
187 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
190 static void nec_8048_set_timings(struct omap_dss_device *dssdev,
191 struct omap_video_timings *timings)
193 struct panel_drv_data *ddata = to_panel_data(dssdev);
194 struct omap_dss_device *in = ddata->in;
196 ddata->videomode = *timings;
197 dssdev->panel.timings = *timings;
199 in->ops.dpi->set_timings(in, timings);
202 static void nec_8048_get_timings(struct omap_dss_device *dssdev,
203 struct omap_video_timings *timings)
205 struct panel_drv_data *ddata = to_panel_data(dssdev);
207 *timings = ddata->videomode;
210 static int nec_8048_check_timings(struct omap_dss_device *dssdev,
211 struct omap_video_timings *timings)
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, timings);
219 static struct omap_dss_driver nec_8048_ops = {
220 .connect = nec_8048_connect,
221 .disconnect = nec_8048_disconnect,
223 .enable = nec_8048_enable,
224 .disable = nec_8048_disable,
226 .set_timings = nec_8048_set_timings,
227 .get_timings = nec_8048_get_timings,
228 .check_timings = nec_8048_check_timings,
230 .get_resolution = omapdss_default_get_resolution,
233 static int nec_8048_probe_of(struct spi_device *spi)
235 struct device_node *node = spi->dev.of_node;
236 struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
237 struct omap_dss_device *in;
238 int gpio;
240 gpio = of_get_named_gpio(node, "reset-gpios", 0);
241 if (!gpio_is_valid(gpio)) {
242 dev_err(&spi->dev, "failed to parse enable gpio\n");
243 return gpio;
245 ddata->res_gpio = gpio;
247 /* XXX the panel spec doesn't mention any QVGA pin?? */
248 ddata->qvga_gpio = -ENOENT;
250 in = omapdss_of_find_source_for_first_ep(node);
251 if (IS_ERR(in)) {
252 dev_err(&spi->dev, "failed to find video source\n");
253 return PTR_ERR(in);
256 ddata->in = in;
258 return 0;
261 static int nec_8048_probe(struct spi_device *spi)
263 struct panel_drv_data *ddata;
264 struct omap_dss_device *dssdev;
265 int r;
267 dev_dbg(&spi->dev, "%s\n", __func__);
269 spi->mode = SPI_MODE_0;
270 spi->bits_per_word = 32;
272 r = spi_setup(spi);
273 if (r < 0) {
274 dev_err(&spi->dev, "spi_setup failed: %d\n", r);
275 return r;
278 init_nec_8048_wvga_lcd(spi);
280 ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL);
281 if (ddata == NULL)
282 return -ENOMEM;
284 dev_set_drvdata(&spi->dev, ddata);
286 ddata->spi = spi;
288 if (!spi->dev.of_node)
289 return -ENODEV;
291 r = nec_8048_probe_of(spi);
292 if (r)
293 return r;
295 if (gpio_is_valid(ddata->qvga_gpio)) {
296 r = devm_gpio_request_one(&spi->dev, ddata->qvga_gpio,
297 GPIOF_OUT_INIT_HIGH, "lcd QVGA");
298 if (r)
299 goto err_gpio;
302 if (gpio_is_valid(ddata->res_gpio)) {
303 r = devm_gpio_request_one(&spi->dev, ddata->res_gpio,
304 GPIOF_OUT_INIT_LOW, "lcd RES");
305 if (r)
306 goto err_gpio;
309 ddata->videomode = nec_8048_panel_timings;
311 dssdev = &ddata->dssdev;
312 dssdev->dev = &spi->dev;
313 dssdev->driver = &nec_8048_ops;
314 dssdev->type = OMAP_DISPLAY_TYPE_DPI;
315 dssdev->owner = THIS_MODULE;
316 dssdev->panel.timings = ddata->videomode;
318 r = omapdss_register_display(dssdev);
319 if (r) {
320 dev_err(&spi->dev, "Failed to register panel\n");
321 goto err_reg;
324 return 0;
326 err_reg:
327 err_gpio:
328 omap_dss_put_device(ddata->in);
329 return r;
332 static int nec_8048_remove(struct spi_device *spi)
334 struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
335 struct omap_dss_device *dssdev = &ddata->dssdev;
336 struct omap_dss_device *in = ddata->in;
338 dev_dbg(&ddata->spi->dev, "%s\n", __func__);
340 omapdss_unregister_display(dssdev);
342 nec_8048_disable(dssdev);
343 nec_8048_disconnect(dssdev);
345 omap_dss_put_device(in);
347 return 0;
350 #ifdef CONFIG_PM_SLEEP
351 static int nec_8048_suspend(struct device *dev)
353 struct spi_device *spi = to_spi_device(dev);
355 nec_8048_spi_send(spi, 2, 0x01);
356 mdelay(40);
358 return 0;
361 static int nec_8048_resume(struct device *dev)
363 struct spi_device *spi = to_spi_device(dev);
365 /* reinitialize the panel */
366 spi_setup(spi);
367 nec_8048_spi_send(spi, 2, 0x00);
368 init_nec_8048_wvga_lcd(spi);
370 return 0;
372 static SIMPLE_DEV_PM_OPS(nec_8048_pm_ops, nec_8048_suspend,
373 nec_8048_resume);
374 #define NEC_8048_PM_OPS (&nec_8048_pm_ops)
375 #else
376 #define NEC_8048_PM_OPS NULL
377 #endif
379 static const struct of_device_id nec_8048_of_match[] = {
380 { .compatible = "omapdss,nec,nl8048hl11", },
384 MODULE_DEVICE_TABLE(of, nec_8048_of_match);
386 static struct spi_driver nec_8048_driver = {
387 .driver = {
388 .name = "panel-nec-nl8048hl11",
389 .pm = NEC_8048_PM_OPS,
390 .of_match_table = nec_8048_of_match,
391 .suppress_bind_attrs = true,
393 .probe = nec_8048_probe,
394 .remove = nec_8048_remove,
397 module_spi_driver(nec_8048_driver);
399 MODULE_ALIAS("spi:nec,nl8048hl11");
400 MODULE_AUTHOR("Erik Gilling <konkers@android.com>");
401 MODULE_DESCRIPTION("NEC-NL8048HL11 Driver");
402 MODULE_LICENSE("GPL");