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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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 <plat/display.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_enable(struct omap_dss_device *dssdev)
  140. {
  141. int r = 0;
  142. struct nec_8048_data *necd = dev_get_drvdata(&dssdev->dev);
  143. struct backlight_device *bl = necd->bl;
  144. if (dssdev->platform_enable) {
  145. r = dssdev->platform_enable(dssdev);
  146. if (r)
  147. return r;
  148. }
  149. r = nec_8048_bl_update_status(bl);
  150. if (r < 0)
  151. dev_err(&dssdev->dev, "failed to set lcd brightness\n");
  152. r = omapdss_dpi_display_enable(dssdev);
  153. return r;
  154. }
  155. static void nec_8048_panel_disable(struct omap_dss_device *dssdev)
  156. {
  157. struct nec_8048_data *necd = dev_get_drvdata(&dssdev->dev);
  158. struct backlight_device *bl = necd->bl;
  159. omapdss_dpi_display_disable(dssdev);
  160. bl->props.brightness = 0;
  161. nec_8048_bl_update_status(bl);
  162. if (dssdev->platform_disable)
  163. dssdev->platform_disable(dssdev);
  164. }
  165. static int nec_8048_panel_suspend(struct omap_dss_device *dssdev)
  166. {
  167. nec_8048_panel_disable(dssdev);
  168. return 0;
  169. }
  170. static int nec_8048_panel_resume(struct omap_dss_device *dssdev)
  171. {
  172. return nec_8048_panel_enable(dssdev);
  173. }
  174. static int nec_8048_recommended_bpp(struct omap_dss_device *dssdev)
  175. {
  176. return 16;
  177. }
  178. static struct omap_dss_driver nec_8048_driver = {
  179. .probe = nec_8048_panel_probe,
  180. .remove = nec_8048_panel_remove,
  181. .enable = nec_8048_panel_enable,
  182. .disable = nec_8048_panel_disable,
  183. .suspend = nec_8048_panel_suspend,
  184. .resume = nec_8048_panel_resume,
  185. .get_recommended_bpp = nec_8048_recommended_bpp,
  186. .driver = {
  187. .name = "NEC_8048_panel",
  188. .owner = THIS_MODULE,
  189. },
  190. };
  191. static int nec_8048_spi_send(struct spi_device *spi, unsigned char reg_addr,
  192. unsigned char reg_data)
  193. {
  194. int ret = 0;
  195. unsigned int cmd = 0, data = 0;
  196. cmd = 0x0000 | reg_addr; /* register address write */
  197. data = 0x0100 | reg_data ; /* register data write */
  198. data = (cmd << 16) | data;
  199. ret = spi_write(spi, (unsigned char *)&data, 4);
  200. if (ret)
  201. pr_err("error in spi_write %x\n", data);
  202. return ret;
  203. }
  204. static int init_nec_8048_wvga_lcd(struct spi_device *spi)
  205. {
  206. unsigned int i;
  207. /* Initialization Sequence */
  208. /* nec_8048_spi_send(spi, REG, VAL) */
  209. for (i = 0; i < (ARRAY_SIZE(nec_8048_init_seq) - 1); i++)
  210. nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
  211. nec_8048_init_seq[i].dat);
  212. udelay(20);
  213. nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
  214. nec_8048_init_seq[i].dat);
  215. return 0;
  216. }
  217. static int nec_8048_spi_probe(struct spi_device *spi)
  218. {
  219. spi->mode = SPI_MODE_0;
  220. spi->bits_per_word = 32;
  221. spi_setup(spi);
  222. init_nec_8048_wvga_lcd(spi);
  223. return omap_dss_register_driver(&nec_8048_driver);
  224. }
  225. static int nec_8048_spi_remove(struct spi_device *spi)
  226. {
  227. omap_dss_unregister_driver(&nec_8048_driver);
  228. return 0;
  229. }
  230. static int nec_8048_spi_suspend(struct spi_device *spi, pm_message_t mesg)
  231. {
  232. nec_8048_spi_send(spi, 2, 0x01);
  233. mdelay(40);
  234. return 0;
  235. }
  236. static int nec_8048_spi_resume(struct spi_device *spi)
  237. {
  238. /* reinitialize the panel */
  239. spi_setup(spi);
  240. nec_8048_spi_send(spi, 2, 0x00);
  241. init_nec_8048_wvga_lcd(spi);
  242. return 0;
  243. }
  244. static struct spi_driver nec_8048_spi_driver = {
  245. .probe = nec_8048_spi_probe,
  246. .remove = __devexit_p(nec_8048_spi_remove),
  247. .suspend = nec_8048_spi_suspend,
  248. .resume = nec_8048_spi_resume,
  249. .driver = {
  250. .name = "nec_8048_spi",
  251. .bus = &spi_bus_type,
  252. .owner = THIS_MODULE,
  253. },
  254. };
  255. static int __init nec_8048_lcd_init(void)
  256. {
  257. return spi_register_driver(&nec_8048_spi_driver);
  258. }
  259. static void __exit nec_8048_lcd_exit(void)
  260. {
  261. return spi_unregister_driver(&nec_8048_spi_driver);
  262. }
  263. module_init(nec_8048_lcd_init);
  264. module_exit(nec_8048_lcd_exit);
  265. MODULE_AUTHOR("Erik Gilling <konkers@android.com>");
  266. MODULE_DESCRIPTION("NEC-nl8048hl11-01b Driver");
  267. MODULE_LICENSE("GPL");