panel-nec-nl8048hl11-01b.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. /*
  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. #include <linux/module.h>
  19. #include <linux/delay.h>
  20. #include <linux/spi/spi.h>
  21. #include <linux/backlight.h>
  22. #include <linux/fb.h>
  23. #include <video/omapdss.h>
  24. #define LCD_XRES 800
  25. #define LCD_YRES 480
  26. /*
  27. * NEC PIX Clock Ratings
  28. * MIN:21.8MHz TYP:23.8MHz MAX:25.7MHz
  29. */
  30. #define LCD_PIXEL_CLOCK 23800
  31. struct nec_8048_data {
  32. struct backlight_device *bl;
  33. };
  34. static const struct {
  35. unsigned char addr;
  36. unsigned char dat;
  37. } nec_8048_init_seq[] = {
  38. { 3, 0x01 }, { 0, 0x00 }, { 1, 0x01 }, { 4, 0x00 }, { 5, 0x14 },
  39. { 6, 0x24 }, { 16, 0xD7 }, { 17, 0x00 }, { 18, 0x00 }, { 19, 0x55 },
  40. { 20, 0x01 }, { 21, 0x70 }, { 22, 0x1E }, { 23, 0x25 }, { 24, 0x25 },
  41. { 25, 0x02 }, { 26, 0x02 }, { 27, 0xA0 }, { 32, 0x2F }, { 33, 0x0F },
  42. { 34, 0x0F }, { 35, 0x0F }, { 36, 0x0F }, { 37, 0x0F }, { 38, 0x0F },
  43. { 39, 0x00 }, { 40, 0x02 }, { 41, 0x02 }, { 42, 0x02 }, { 43, 0x0F },
  44. { 44, 0x0F }, { 45, 0x0F }, { 46, 0x0F }, { 47, 0x0F }, { 48, 0x0F },
  45. { 49, 0x0F }, { 50, 0x00 }, { 51, 0x02 }, { 52, 0x02 }, { 53, 0x02 },
  46. { 80, 0x0C }, { 83, 0x42 }, { 84, 0x42 }, { 85, 0x41 }, { 86, 0x14 },
  47. { 89, 0x88 }, { 90, 0x01 }, { 91, 0x00 }, { 92, 0x02 }, { 93, 0x0C },
  48. { 94, 0x1C }, { 95, 0x27 }, { 98, 0x49 }, { 99, 0x27 }, { 102, 0x76 },
  49. { 103, 0x27 }, { 112, 0x01 }, { 113, 0x0E }, { 114, 0x02 },
  50. { 115, 0x0C }, { 118, 0x0C }, { 121, 0x30 }, { 130, 0x00 },
  51. { 131, 0x00 }, { 132, 0xFC }, { 134, 0x00 }, { 136, 0x00 },
  52. { 138, 0x00 }, { 139, 0x00 }, { 140, 0x00 }, { 141, 0xFC },
  53. { 143, 0x00 }, { 145, 0x00 }, { 147, 0x00 }, { 148, 0x00 },
  54. { 149, 0x00 }, { 150, 0xFC }, { 152, 0x00 }, { 154, 0x00 },
  55. { 156, 0x00 }, { 157, 0x00 }, { 2, 0x00 },
  56. };
  57. /*
  58. * NEC NL8048HL11-01B Manual
  59. * defines HFB, HSW, HBP, VFP, VSW, VBP as shown below
  60. */
  61. static struct omap_video_timings nec_8048_panel_timings = {
  62. /* 800 x 480 @ 60 Hz Reduced blanking VESA CVT 0.31M3-R */
  63. .x_res = LCD_XRES,
  64. .y_res = LCD_YRES,
  65. .pixel_clock = LCD_PIXEL_CLOCK,
  66. .hfp = 6,
  67. .hsw = 1,
  68. .hbp = 4,
  69. .vfp = 3,
  70. .vsw = 1,
  71. .vbp = 4,
  72. };
  73. static int nec_8048_bl_update_status(struct backlight_device *bl)
  74. {
  75. struct omap_dss_device *dssdev = dev_get_drvdata(&bl->dev);
  76. int level;
  77. if (!dssdev->set_backlight)
  78. return -EINVAL;
  79. if (bl->props.fb_blank == FB_BLANK_UNBLANK &&
  80. bl->props.power == FB_BLANK_UNBLANK)
  81. level = bl->props.brightness;
  82. else
  83. level = 0;
  84. return dssdev->set_backlight(dssdev, level);
  85. }
  86. static int nec_8048_bl_get_brightness(struct backlight_device *bl)
  87. {
  88. if (bl->props.fb_blank == FB_BLANK_UNBLANK &&
  89. bl->props.power == FB_BLANK_UNBLANK)
  90. return bl->props.brightness;
  91. return 0;
  92. }
  93. static const struct backlight_ops nec_8048_bl_ops = {
  94. .get_brightness = nec_8048_bl_get_brightness,
  95. .update_status = nec_8048_bl_update_status,
  96. };
  97. static int nec_8048_panel_probe(struct omap_dss_device *dssdev)
  98. {
  99. struct backlight_device *bl;
  100. struct nec_8048_data *necd;
  101. struct backlight_properties props;
  102. int r;
  103. dssdev->panel.config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
  104. OMAP_DSS_LCD_IHS | OMAP_DSS_LCD_RF |
  105. OMAP_DSS_LCD_ONOFF;
  106. dssdev->panel.timings = nec_8048_panel_timings;
  107. necd = kzalloc(sizeof(*necd), GFP_KERNEL);
  108. if (!necd)
  109. return -ENOMEM;
  110. dev_set_drvdata(&dssdev->dev, necd);
  111. memset(&props, 0, sizeof(struct backlight_properties));
  112. props.max_brightness = 255;
  113. bl = backlight_device_register("nec-8048", &dssdev->dev, dssdev,
  114. &nec_8048_bl_ops, &props);
  115. if (IS_ERR(bl)) {
  116. r = PTR_ERR(bl);
  117. kfree(necd);
  118. return r;
  119. }
  120. necd->bl = bl;
  121. bl->props.fb_blank = FB_BLANK_UNBLANK;
  122. bl->props.power = FB_BLANK_UNBLANK;
  123. bl->props.max_brightness = dssdev->max_backlight_level;
  124. bl->props.brightness = dssdev->max_backlight_level;
  125. r = nec_8048_bl_update_status(bl);
  126. if (r < 0)
  127. dev_err(&dssdev->dev, "failed to set lcd brightness\n");
  128. return 0;
  129. }
  130. static void nec_8048_panel_remove(struct omap_dss_device *dssdev)
  131. {
  132. struct nec_8048_data *necd = dev_get_drvdata(&dssdev->dev);
  133. struct backlight_device *bl = necd->bl;
  134. bl->props.power = FB_BLANK_POWERDOWN;
  135. nec_8048_bl_update_status(bl);
  136. backlight_device_unregister(bl);
  137. kfree(necd);
  138. }
  139. static int nec_8048_panel_power_on(struct omap_dss_device *dssdev)
  140. {
  141. int r;
  142. struct nec_8048_data *necd = dev_get_drvdata(&dssdev->dev);
  143. struct backlight_device *bl = necd->bl;
  144. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  145. return 0;
  146. r = omapdss_dpi_display_enable(dssdev);
  147. if (r)
  148. goto err0;
  149. if (dssdev->platform_enable) {
  150. r = dssdev->platform_enable(dssdev);
  151. if (r)
  152. goto err1;
  153. }
  154. r = nec_8048_bl_update_status(bl);
  155. if (r < 0)
  156. dev_err(&dssdev->dev, "failed to set lcd brightness\n");
  157. return 0;
  158. err1:
  159. omapdss_dpi_display_disable(dssdev);
  160. err0:
  161. return r;
  162. }
  163. static void nec_8048_panel_power_off(struct omap_dss_device *dssdev)
  164. {
  165. struct nec_8048_data *necd = dev_get_drvdata(&dssdev->dev);
  166. struct backlight_device *bl = necd->bl;
  167. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
  168. return;
  169. bl->props.brightness = 0;
  170. nec_8048_bl_update_status(bl);
  171. if (dssdev->platform_disable)
  172. dssdev->platform_disable(dssdev);
  173. omapdss_dpi_display_disable(dssdev);
  174. }
  175. static int nec_8048_panel_enable(struct omap_dss_device *dssdev)
  176. {
  177. int r;
  178. r = nec_8048_panel_power_on(dssdev);
  179. if (r)
  180. return r;
  181. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  182. return 0;
  183. }
  184. static void nec_8048_panel_disable(struct omap_dss_device *dssdev)
  185. {
  186. nec_8048_panel_power_off(dssdev);
  187. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  188. }
  189. static int nec_8048_panel_suspend(struct omap_dss_device *dssdev)
  190. {
  191. nec_8048_panel_power_off(dssdev);
  192. dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
  193. return 0;
  194. }
  195. static int nec_8048_panel_resume(struct omap_dss_device *dssdev)
  196. {
  197. int r;
  198. r = nec_8048_panel_power_on(dssdev);
  199. if (r)
  200. return r;
  201. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  202. return 0;
  203. }
  204. static int nec_8048_recommended_bpp(struct omap_dss_device *dssdev)
  205. {
  206. return 16;
  207. }
  208. static struct omap_dss_driver nec_8048_driver = {
  209. .probe = nec_8048_panel_probe,
  210. .remove = nec_8048_panel_remove,
  211. .enable = nec_8048_panel_enable,
  212. .disable = nec_8048_panel_disable,
  213. .suspend = nec_8048_panel_suspend,
  214. .resume = nec_8048_panel_resume,
  215. .get_recommended_bpp = nec_8048_recommended_bpp,
  216. .driver = {
  217. .name = "NEC_8048_panel",
  218. .owner = THIS_MODULE,
  219. },
  220. };
  221. static int nec_8048_spi_send(struct spi_device *spi, unsigned char reg_addr,
  222. unsigned char reg_data)
  223. {
  224. int ret = 0;
  225. unsigned int cmd = 0, data = 0;
  226. cmd = 0x0000 | reg_addr; /* register address write */
  227. data = 0x0100 | reg_data ; /* register data write */
  228. data = (cmd << 16) | data;
  229. ret = spi_write(spi, (unsigned char *)&data, 4);
  230. if (ret)
  231. pr_err("error in spi_write %x\n", data);
  232. return ret;
  233. }
  234. static int init_nec_8048_wvga_lcd(struct spi_device *spi)
  235. {
  236. unsigned int i;
  237. /* Initialization Sequence */
  238. /* nec_8048_spi_send(spi, REG, VAL) */
  239. for (i = 0; i < (ARRAY_SIZE(nec_8048_init_seq) - 1); i++)
  240. nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
  241. nec_8048_init_seq[i].dat);
  242. udelay(20);
  243. nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
  244. nec_8048_init_seq[i].dat);
  245. return 0;
  246. }
  247. static int nec_8048_spi_probe(struct spi_device *spi)
  248. {
  249. spi->mode = SPI_MODE_0;
  250. spi->bits_per_word = 32;
  251. spi_setup(spi);
  252. init_nec_8048_wvga_lcd(spi);
  253. return omap_dss_register_driver(&nec_8048_driver);
  254. }
  255. static int nec_8048_spi_remove(struct spi_device *spi)
  256. {
  257. omap_dss_unregister_driver(&nec_8048_driver);
  258. return 0;
  259. }
  260. static int nec_8048_spi_suspend(struct spi_device *spi, pm_message_t mesg)
  261. {
  262. nec_8048_spi_send(spi, 2, 0x01);
  263. mdelay(40);
  264. return 0;
  265. }
  266. static int nec_8048_spi_resume(struct spi_device *spi)
  267. {
  268. /* reinitialize the panel */
  269. spi_setup(spi);
  270. nec_8048_spi_send(spi, 2, 0x00);
  271. init_nec_8048_wvga_lcd(spi);
  272. return 0;
  273. }
  274. static struct spi_driver nec_8048_spi_driver = {
  275. .probe = nec_8048_spi_probe,
  276. .remove = __devexit_p(nec_8048_spi_remove),
  277. .suspend = nec_8048_spi_suspend,
  278. .resume = nec_8048_spi_resume,
  279. .driver = {
  280. .name = "nec_8048_spi",
  281. .owner = THIS_MODULE,
  282. },
  283. };
  284. module_spi_driver(nec_8048_spi_driver);
  285. MODULE_AUTHOR("Erik Gilling <konkers@android.com>");
  286. MODULE_DESCRIPTION("NEC-nl8048hl11-01b Driver");
  287. MODULE_LICENSE("GPL");