blob: 9eab0dda2f3395b2d55ce38af9707eebe7d1d21e [file] [log] [blame]
Erik Gilling2d2afa42010-10-26 05:12:36 +02001/*
2 * Support for NEC-nl8048hl11-01b panel driver
3 *
4 * Copyright (C) 2010 Texas Instruments Inc.
5 * Author: Erik Gilling <konkers@android.com>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <linux/module.h>
20#include <linux/delay.h>
21#include <linux/spi/spi.h>
22#include <linux/backlight.h>
23#include <linux/fb.h>
24
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030025#include <video/omapdss.h>
Erik Gilling2d2afa42010-10-26 05:12:36 +020026
27#define LCD_XRES 800
28#define LCD_YRES 480
29/*
30 * NEC PIX Clock Ratings
31 * MIN:21.8MHz TYP:23.8MHz MAX:25.7MHz
32 */
33#define LCD_PIXEL_CLOCK 23800
34
35struct nec_8048_data {
36 struct backlight_device *bl;
37};
38
39static const struct {
40 unsigned char addr;
41 unsigned char dat;
42} nec_8048_init_seq[] = {
43 { 3, 0x01 }, { 0, 0x00 }, { 1, 0x01 }, { 4, 0x00 }, { 5, 0x14 },
44 { 6, 0x24 }, { 16, 0xD7 }, { 17, 0x00 }, { 18, 0x00 }, { 19, 0x55 },
45 { 20, 0x01 }, { 21, 0x70 }, { 22, 0x1E }, { 23, 0x25 }, { 24, 0x25 },
46 { 25, 0x02 }, { 26, 0x02 }, { 27, 0xA0 }, { 32, 0x2F }, { 33, 0x0F },
47 { 34, 0x0F }, { 35, 0x0F }, { 36, 0x0F }, { 37, 0x0F }, { 38, 0x0F },
48 { 39, 0x00 }, { 40, 0x02 }, { 41, 0x02 }, { 42, 0x02 }, { 43, 0x0F },
49 { 44, 0x0F }, { 45, 0x0F }, { 46, 0x0F }, { 47, 0x0F }, { 48, 0x0F },
50 { 49, 0x0F }, { 50, 0x00 }, { 51, 0x02 }, { 52, 0x02 }, { 53, 0x02 },
51 { 80, 0x0C }, { 83, 0x42 }, { 84, 0x42 }, { 85, 0x41 }, { 86, 0x14 },
52 { 89, 0x88 }, { 90, 0x01 }, { 91, 0x00 }, { 92, 0x02 }, { 93, 0x0C },
53 { 94, 0x1C }, { 95, 0x27 }, { 98, 0x49 }, { 99, 0x27 }, { 102, 0x76 },
54 { 103, 0x27 }, { 112, 0x01 }, { 113, 0x0E }, { 114, 0x02 },
55 { 115, 0x0C }, { 118, 0x0C }, { 121, 0x30 }, { 130, 0x00 },
56 { 131, 0x00 }, { 132, 0xFC }, { 134, 0x00 }, { 136, 0x00 },
57 { 138, 0x00 }, { 139, 0x00 }, { 140, 0x00 }, { 141, 0xFC },
58 { 143, 0x00 }, { 145, 0x00 }, { 147, 0x00 }, { 148, 0x00 },
59 { 149, 0x00 }, { 150, 0xFC }, { 152, 0x00 }, { 154, 0x00 },
60 { 156, 0x00 }, { 157, 0x00 }, { 2, 0x00 },
61};
62
63/*
64 * NEC NL8048HL11-01B Manual
65 * defines HFB, HSW, HBP, VFP, VSW, VBP as shown below
66 */
67
68static struct omap_video_timings nec_8048_panel_timings = {
69 /* 800 x 480 @ 60 Hz Reduced blanking VESA CVT 0.31M3-R */
70 .x_res = LCD_XRES,
71 .y_res = LCD_YRES,
72 .pixel_clock = LCD_PIXEL_CLOCK,
73 .hfp = 6,
74 .hsw = 1,
75 .hbp = 4,
76 .vfp = 3,
77 .vsw = 1,
78 .vbp = 4,
Archit Tanejaa8d5e412012-06-25 12:26:38 +053079
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,
Erik Gilling2d2afa42010-10-26 05:12:36 +020085};
86
87static int nec_8048_bl_update_status(struct backlight_device *bl)
88{
89 struct omap_dss_device *dssdev = dev_get_drvdata(&bl->dev);
90 int level;
91
92 if (!dssdev->set_backlight)
93 return -EINVAL;
94
95 if (bl->props.fb_blank == FB_BLANK_UNBLANK &&
96 bl->props.power == FB_BLANK_UNBLANK)
97 level = bl->props.brightness;
98 else
99 level = 0;
100
101 return dssdev->set_backlight(dssdev, level);
102}
103
104static int nec_8048_bl_get_brightness(struct backlight_device *bl)
105{
106 if (bl->props.fb_blank == FB_BLANK_UNBLANK &&
107 bl->props.power == FB_BLANK_UNBLANK)
108 return bl->props.brightness;
109
110 return 0;
111}
112
113static const struct backlight_ops nec_8048_bl_ops = {
114 .get_brightness = nec_8048_bl_get_brightness,
115 .update_status = nec_8048_bl_update_status,
116};
117
118static int nec_8048_panel_probe(struct omap_dss_device *dssdev)
119{
120 struct backlight_device *bl;
121 struct nec_8048_data *necd;
122 struct backlight_properties props;
123 int r;
124
Archit Taneja5ae9eaa2012-06-21 09:41:10 +0530125 dssdev->panel.config = OMAP_DSS_LCD_IVS | OMAP_DSS_LCD_IHS |
126 OMAP_DSS_LCD_RF | OMAP_DSS_LCD_ONOFF;
Erik Gilling2d2afa42010-10-26 05:12:36 +0200127 dssdev->panel.timings = nec_8048_panel_timings;
128
129 necd = kzalloc(sizeof(*necd), GFP_KERNEL);
130 if (!necd)
131 return -ENOMEM;
132
133 dev_set_drvdata(&dssdev->dev, necd);
134
135 memset(&props, 0, sizeof(struct backlight_properties));
136 props.max_brightness = 255;
137
138 bl = backlight_device_register("nec-8048", &dssdev->dev, dssdev,
139 &nec_8048_bl_ops, &props);
140 if (IS_ERR(bl)) {
141 r = PTR_ERR(bl);
142 kfree(necd);
143 return r;
144 }
145 necd->bl = bl;
146
147 bl->props.fb_blank = FB_BLANK_UNBLANK;
148 bl->props.power = FB_BLANK_UNBLANK;
149 bl->props.max_brightness = dssdev->max_backlight_level;
150 bl->props.brightness = dssdev->max_backlight_level;
151
152 r = nec_8048_bl_update_status(bl);
153 if (r < 0)
154 dev_err(&dssdev->dev, "failed to set lcd brightness\n");
155
156 return 0;
157}
158
159static void nec_8048_panel_remove(struct omap_dss_device *dssdev)
160{
161 struct nec_8048_data *necd = dev_get_drvdata(&dssdev->dev);
162 struct backlight_device *bl = necd->bl;
163
164 bl->props.power = FB_BLANK_POWERDOWN;
165 nec_8048_bl_update_status(bl);
166 backlight_device_unregister(bl);
167
168 kfree(necd);
169}
170
Archit Tanejad95c03f2011-12-12 11:47:42 +0530171static int nec_8048_panel_power_on(struct omap_dss_device *dssdev)
Erik Gilling2d2afa42010-10-26 05:12:36 +0200172{
Archit Tanejad95c03f2011-12-12 11:47:42 +0530173 int r;
Erik Gilling2d2afa42010-10-26 05:12:36 +0200174 struct nec_8048_data *necd = dev_get_drvdata(&dssdev->dev);
175 struct backlight_device *bl = necd->bl;
176
Archit Tanejad95c03f2011-12-12 11:47:42 +0530177 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
178 return 0;
179
180 r = omapdss_dpi_display_enable(dssdev);
181 if (r)
182 goto err0;
183
Erik Gilling2d2afa42010-10-26 05:12:36 +0200184 if (dssdev->platform_enable) {
185 r = dssdev->platform_enable(dssdev);
186 if (r)
Archit Tanejad95c03f2011-12-12 11:47:42 +0530187 goto err1;
Erik Gilling2d2afa42010-10-26 05:12:36 +0200188 }
189
190 r = nec_8048_bl_update_status(bl);
191 if (r < 0)
192 dev_err(&dssdev->dev, "failed to set lcd brightness\n");
193
Archit Tanejad95c03f2011-12-12 11:47:42 +0530194 return 0;
195err1:
196 omapdss_dpi_display_disable(dssdev);
197err0:
Erik Gilling2d2afa42010-10-26 05:12:36 +0200198 return r;
199}
200
Archit Tanejad95c03f2011-12-12 11:47:42 +0530201static void nec_8048_panel_power_off(struct omap_dss_device *dssdev)
Erik Gilling2d2afa42010-10-26 05:12:36 +0200202{
203 struct nec_8048_data *necd = dev_get_drvdata(&dssdev->dev);
204 struct backlight_device *bl = necd->bl;
205
Archit Tanejad95c03f2011-12-12 11:47:42 +0530206 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
207 return;
Erik Gilling2d2afa42010-10-26 05:12:36 +0200208
209 bl->props.brightness = 0;
210 nec_8048_bl_update_status(bl);
211
212 if (dssdev->platform_disable)
213 dssdev->platform_disable(dssdev);
Archit Tanejad95c03f2011-12-12 11:47:42 +0530214
215 omapdss_dpi_display_disable(dssdev);
216}
217
218static int nec_8048_panel_enable(struct omap_dss_device *dssdev)
219{
220 int r;
221
222 r = nec_8048_panel_power_on(dssdev);
223 if (r)
224 return r;
225
226 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
227
228 return 0;
229}
230
231static void nec_8048_panel_disable(struct omap_dss_device *dssdev)
232{
233 nec_8048_panel_power_off(dssdev);
234
235 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
Erik Gilling2d2afa42010-10-26 05:12:36 +0200236}
237
238static int nec_8048_panel_suspend(struct omap_dss_device *dssdev)
239{
Archit Tanejad95c03f2011-12-12 11:47:42 +0530240 nec_8048_panel_power_off(dssdev);
241
242 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
243
Erik Gilling2d2afa42010-10-26 05:12:36 +0200244 return 0;
245}
246
247static int nec_8048_panel_resume(struct omap_dss_device *dssdev)
248{
Archit Tanejad95c03f2011-12-12 11:47:42 +0530249 int r;
250
251 r = nec_8048_panel_power_on(dssdev);
252 if (r)
253 return r;
254
255 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
256
257 return 0;
Erik Gilling2d2afa42010-10-26 05:12:36 +0200258}
259
260static int nec_8048_recommended_bpp(struct omap_dss_device *dssdev)
261{
262 return 16;
263}
264
265static struct omap_dss_driver nec_8048_driver = {
266 .probe = nec_8048_panel_probe,
267 .remove = nec_8048_panel_remove,
268 .enable = nec_8048_panel_enable,
269 .disable = nec_8048_panel_disable,
270 .suspend = nec_8048_panel_suspend,
271 .resume = nec_8048_panel_resume,
272 .get_recommended_bpp = nec_8048_recommended_bpp,
273
274 .driver = {
275 .name = "NEC_8048_panel",
276 .owner = THIS_MODULE,
277 },
278};
279
280static int nec_8048_spi_send(struct spi_device *spi, unsigned char reg_addr,
281 unsigned char reg_data)
282{
283 int ret = 0;
284 unsigned int cmd = 0, data = 0;
285
286 cmd = 0x0000 | reg_addr; /* register address write */
287 data = 0x0100 | reg_data ; /* register data write */
288 data = (cmd << 16) | data;
289
290 ret = spi_write(spi, (unsigned char *)&data, 4);
291 if (ret)
292 pr_err("error in spi_write %x\n", data);
293
294 return ret;
295}
296
297static int init_nec_8048_wvga_lcd(struct spi_device *spi)
298{
299 unsigned int i;
300 /* Initialization Sequence */
301 /* nec_8048_spi_send(spi, REG, VAL) */
302 for (i = 0; i < (ARRAY_SIZE(nec_8048_init_seq) - 1); i++)
303 nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
304 nec_8048_init_seq[i].dat);
305 udelay(20);
306 nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
307 nec_8048_init_seq[i].dat);
308 return 0;
309}
310
311static int nec_8048_spi_probe(struct spi_device *spi)
312{
313 spi->mode = SPI_MODE_0;
314 spi->bits_per_word = 32;
315 spi_setup(spi);
316
317 init_nec_8048_wvga_lcd(spi);
318
319 return omap_dss_register_driver(&nec_8048_driver);
320}
321
322static int nec_8048_spi_remove(struct spi_device *spi)
323{
324 omap_dss_unregister_driver(&nec_8048_driver);
325
326 return 0;
327}
328
329static int nec_8048_spi_suspend(struct spi_device *spi, pm_message_t mesg)
330{
331 nec_8048_spi_send(spi, 2, 0x01);
332 mdelay(40);
333
334 return 0;
335}
336
337static int nec_8048_spi_resume(struct spi_device *spi)
338{
339 /* reinitialize the panel */
340 spi_setup(spi);
341 nec_8048_spi_send(spi, 2, 0x00);
342 init_nec_8048_wvga_lcd(spi);
343
344 return 0;
345}
346
347static struct spi_driver nec_8048_spi_driver = {
348 .probe = nec_8048_spi_probe,
349 .remove = __devexit_p(nec_8048_spi_remove),
350 .suspend = nec_8048_spi_suspend,
351 .resume = nec_8048_spi_resume,
352 .driver = {
353 .name = "nec_8048_spi",
Erik Gilling2d2afa42010-10-26 05:12:36 +0200354 .owner = THIS_MODULE,
355 },
356};
357
Axel Linc6d242a2012-01-27 16:02:54 +0800358module_spi_driver(nec_8048_spi_driver);
Erik Gilling2d2afa42010-10-26 05:12:36 +0200359
Erik Gilling2d2afa42010-10-26 05:12:36 +0200360MODULE_AUTHOR("Erik Gilling <konkers@android.com>");
361MODULE_DESCRIPTION("NEC-nl8048hl11-01b Driver");
362MODULE_LICENSE("GPL");