Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
panel-nec-nl8048hl11-01b.c
Go to the documentation of this file.
1 /*
2  * Support for NEC-nl8048hl11-01b panel driver
3  *
4  * Copyright (C) 2010 Texas Instruments Inc.
5  * Author: Erik Gilling <[email protected]>
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 
25 #include <video/omapdss.h>
26 
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 
35 struct nec_8048_data {
37 };
38 
39 static 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 
68 static 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,
79 
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,
85 };
86 
87 static 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 
104 static 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 
113 static 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 
118 static 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 
125  dssdev->panel.timings = nec_8048_panel_timings;
126 
127  necd = kzalloc(sizeof(*necd), GFP_KERNEL);
128  if (!necd)
129  return -ENOMEM;
130 
131  dev_set_drvdata(&dssdev->dev, necd);
132 
133  memset(&props, 0, sizeof(struct backlight_properties));
134  props.max_brightness = 255;
135 
136  bl = backlight_device_register("nec-8048", &dssdev->dev, dssdev,
137  &nec_8048_bl_ops, &props);
138  if (IS_ERR(bl)) {
139  r = PTR_ERR(bl);
140  kfree(necd);
141  return r;
142  }
143  necd->bl = bl;
144 
145  bl->props.fb_blank = FB_BLANK_UNBLANK;
146  bl->props.power = FB_BLANK_UNBLANK;
147  bl->props.max_brightness = dssdev->max_backlight_level;
148  bl->props.brightness = dssdev->max_backlight_level;
149 
150  r = nec_8048_bl_update_status(bl);
151  if (r < 0)
152  dev_err(&dssdev->dev, "failed to set lcd brightness\n");
153 
154  return 0;
155 }
156 
157 static void nec_8048_panel_remove(struct omap_dss_device *dssdev)
158 {
159  struct nec_8048_data *necd = dev_get_drvdata(&dssdev->dev);
160  struct backlight_device *bl = necd->bl;
161 
162  bl->props.power = FB_BLANK_POWERDOWN;
163  nec_8048_bl_update_status(bl);
165 
166  kfree(necd);
167 }
168 
169 static int nec_8048_panel_power_on(struct omap_dss_device *dssdev)
170 {
171  int r;
172  struct nec_8048_data *necd = dev_get_drvdata(&dssdev->dev);
173  struct backlight_device *bl = necd->bl;
174 
175  if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
176  return 0;
177 
178  omapdss_dpi_set_timings(dssdev, &dssdev->panel.timings);
179  omapdss_dpi_set_data_lines(dssdev, dssdev->phy.dpi.data_lines);
180 
181  r = omapdss_dpi_display_enable(dssdev);
182  if (r)
183  goto err0;
184 
185  if (dssdev->platform_enable) {
186  r = dssdev->platform_enable(dssdev);
187  if (r)
188  goto err1;
189  }
190 
191  r = nec_8048_bl_update_status(bl);
192  if (r < 0)
193  dev_err(&dssdev->dev, "failed to set lcd brightness\n");
194 
195  return 0;
196 err1:
198 err0:
199  return r;
200 }
201 
202 static void nec_8048_panel_power_off(struct omap_dss_device *dssdev)
203 {
204  struct nec_8048_data *necd = dev_get_drvdata(&dssdev->dev);
205  struct backlight_device *bl = necd->bl;
206 
207  if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
208  return;
209 
210  bl->props.brightness = 0;
211  nec_8048_bl_update_status(bl);
212 
213  if (dssdev->platform_disable)
214  dssdev->platform_disable(dssdev);
215 
217 }
218 
219 static int nec_8048_panel_enable(struct omap_dss_device *dssdev)
220 {
221  int r;
222 
223  r = nec_8048_panel_power_on(dssdev);
224  if (r)
225  return r;
226 
227  dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
228 
229  return 0;
230 }
231 
232 static void nec_8048_panel_disable(struct omap_dss_device *dssdev)
233 {
234  nec_8048_panel_power_off(dssdev);
235 
237 }
238 
239 static int nec_8048_panel_suspend(struct omap_dss_device *dssdev)
240 {
241  nec_8048_panel_power_off(dssdev);
242 
244 
245  return 0;
246 }
247 
248 static int nec_8048_panel_resume(struct omap_dss_device *dssdev)
249 {
250  int r;
251 
252  r = nec_8048_panel_power_on(dssdev);
253  if (r)
254  return r;
255 
256  dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
257 
258  return 0;
259 }
260 
261 static int nec_8048_recommended_bpp(struct omap_dss_device *dssdev)
262 {
263  return 16;
264 }
265 
266 static struct omap_dss_driver nec_8048_driver = {
267  .probe = nec_8048_panel_probe,
268  .remove = nec_8048_panel_remove,
269  .enable = nec_8048_panel_enable,
270  .disable = nec_8048_panel_disable,
271  .suspend = nec_8048_panel_suspend,
272  .resume = nec_8048_panel_resume,
273  .get_recommended_bpp = nec_8048_recommended_bpp,
274 
275  .driver = {
276  .name = "NEC_8048_panel",
277  .owner = THIS_MODULE,
278  },
279 };
280 
281 static int nec_8048_spi_send(struct spi_device *spi, unsigned char reg_addr,
282  unsigned char reg_data)
283 {
284  int ret = 0;
285  unsigned int cmd = 0, data = 0;
286 
287  cmd = 0x0000 | reg_addr; /* register address write */
288  data = 0x0100 | reg_data ; /* register data write */
289  data = (cmd << 16) | data;
290 
291  ret = spi_write(spi, (unsigned char *)&data, 4);
292  if (ret)
293  pr_err("error in spi_write %x\n", data);
294 
295  return ret;
296 }
297 
298 static int init_nec_8048_wvga_lcd(struct spi_device *spi)
299 {
300  unsigned int i;
301  /* Initialization Sequence */
302  /* nec_8048_spi_send(spi, REG, VAL) */
303  for (i = 0; i < (ARRAY_SIZE(nec_8048_init_seq) - 1); i++)
304  nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
305  nec_8048_init_seq[i].dat);
306  udelay(20);
307  nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
308  nec_8048_init_seq[i].dat);
309  return 0;
310 }
311 
312 static int nec_8048_spi_probe(struct spi_device *spi)
313 {
314  spi->mode = SPI_MODE_0;
315  spi->bits_per_word = 32;
316  spi_setup(spi);
317 
318  init_nec_8048_wvga_lcd(spi);
319 
320  return omap_dss_register_driver(&nec_8048_driver);
321 }
322 
323 static int nec_8048_spi_remove(struct spi_device *spi)
324 {
325  omap_dss_unregister_driver(&nec_8048_driver);
326 
327  return 0;
328 }
329 
330 static int nec_8048_spi_suspend(struct spi_device *spi, pm_message_t mesg)
331 {
332  nec_8048_spi_send(spi, 2, 0x01);
333  mdelay(40);
334 
335  return 0;
336 }
337 
338 static int nec_8048_spi_resume(struct spi_device *spi)
339 {
340  /* reinitialize the panel */
341  spi_setup(spi);
342  nec_8048_spi_send(spi, 2, 0x00);
343  init_nec_8048_wvga_lcd(spi);
344 
345  return 0;
346 }
347 
348 static struct spi_driver nec_8048_spi_driver = {
349  .probe = nec_8048_spi_probe,
350  .remove = __devexit_p(nec_8048_spi_remove),
351  .suspend = nec_8048_spi_suspend,
352  .resume = nec_8048_spi_resume,
353  .driver = {
354  .name = "nec_8048_spi",
355  .owner = THIS_MODULE,
356  },
357 };
358 
359 module_spi_driver(nec_8048_spi_driver);
360 
361 MODULE_AUTHOR("Erik Gilling <[email protected]>");
362 MODULE_DESCRIPTION("NEC-nl8048hl11-01b Driver");
363 MODULE_LICENSE("GPL");