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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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. .vsync_level = OMAPDSS_SIG_ACTIVE_LOW,
  73. .hsync_level = OMAPDSS_SIG_ACTIVE_LOW,
  74. .data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE,
  75. .de_level = OMAPDSS_SIG_ACTIVE_HIGH,
  76. .sync_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE,
  77. };
  78. static int nec_8048_bl_update_status(struct backlight_device *bl)
  79. {
  80. struct omap_dss_device *dssdev = dev_get_drvdata(&bl->dev);
  81. int level;
  82. if (!dssdev->set_backlight)
  83. return -EINVAL;
  84. if (bl->props.fb_blank == FB_BLANK_UNBLANK &&
  85. bl->props.power == FB_BLANK_UNBLANK)
  86. level = bl->props.brightness;
  87. else
  88. level = 0;
  89. return dssdev->set_backlight(dssdev, level);
  90. }
  91. static int nec_8048_bl_get_brightness(struct backlight_device *bl)
  92. {
  93. if (bl->props.fb_blank == FB_BLANK_UNBLANK &&
  94. bl->props.power == FB_BLANK_UNBLANK)
  95. return bl->props.brightness;
  96. return 0;
  97. }
  98. static const struct backlight_ops nec_8048_bl_ops = {
  99. .get_brightness = nec_8048_bl_get_brightness,
  100. .update_status = nec_8048_bl_update_status,
  101. };
  102. static int nec_8048_panel_probe(struct omap_dss_device *dssdev)
  103. {
  104. struct backlight_device *bl;
  105. struct nec_8048_data *necd;
  106. struct backlight_properties props;
  107. int r;
  108. dssdev->panel.timings = nec_8048_panel_timings;
  109. necd = kzalloc(sizeof(*necd), GFP_KERNEL);
  110. if (!necd)
  111. return -ENOMEM;
  112. dev_set_drvdata(&dssdev->dev, necd);
  113. memset(&props, 0, sizeof(struct backlight_properties));
  114. props.max_brightness = 255;
  115. bl = backlight_device_register("nec-8048", &dssdev->dev, dssdev,
  116. &nec_8048_bl_ops, &props);
  117. if (IS_ERR(bl)) {
  118. r = PTR_ERR(bl);
  119. kfree(necd);
  120. return r;
  121. }
  122. necd->bl = bl;
  123. bl->props.fb_blank = FB_BLANK_UNBLANK;
  124. bl->props.power = FB_BLANK_UNBLANK;
  125. bl->props.max_brightness = dssdev->max_backlight_level;
  126. bl->props.brightness = dssdev->max_backlight_level;
  127. r = nec_8048_bl_update_status(bl);
  128. if (r < 0)
  129. dev_err(&dssdev->dev, "failed to set lcd brightness\n");
  130. return 0;
  131. }
  132. static void nec_8048_panel_remove(struct omap_dss_device *dssdev)
  133. {
  134. struct nec_8048_data *necd = dev_get_drvdata(&dssdev->dev);
  135. struct backlight_device *bl = necd->bl;
  136. bl->props.power = FB_BLANK_POWERDOWN;
  137. nec_8048_bl_update_status(bl);
  138. backlight_device_unregister(bl);
  139. kfree(necd);
  140. }
  141. static int nec_8048_panel_power_on(struct omap_dss_device *dssdev)
  142. {
  143. int r;
  144. struct nec_8048_data *necd = dev_get_drvdata(&dssdev->dev);
  145. struct backlight_device *bl = necd->bl;
  146. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  147. return 0;
  148. omapdss_dpi_set_timings(dssdev, &dssdev->panel.timings);
  149. omapdss_dpi_set_data_lines(dssdev, dssdev->phy.dpi.data_lines);
  150. r = omapdss_dpi_display_enable(dssdev);
  151. if (r)
  152. goto err0;
  153. if (dssdev->platform_enable) {
  154. r = dssdev->platform_enable(dssdev);
  155. if (r)
  156. goto err1;
  157. }
  158. r = nec_8048_bl_update_status(bl);
  159. if (r < 0)
  160. dev_err(&dssdev->dev, "failed to set lcd brightness\n");
  161. return 0;
  162. err1:
  163. omapdss_dpi_display_disable(dssdev);
  164. err0:
  165. return r;
  166. }
  167. static void nec_8048_panel_power_off(struct omap_dss_device *dssdev)
  168. {
  169. struct nec_8048_data *necd = dev_get_drvdata(&dssdev->dev);
  170. struct backlight_device *bl = necd->bl;
  171. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
  172. return;
  173. bl->props.brightness = 0;
  174. nec_8048_bl_update_status(bl);
  175. if (dssdev->platform_disable)
  176. dssdev->platform_disable(dssdev);
  177. omapdss_dpi_display_disable(dssdev);
  178. }
  179. static int nec_8048_panel_enable(struct omap_dss_device *dssdev)
  180. {
  181. int r;
  182. r = nec_8048_panel_power_on(dssdev);
  183. if (r)
  184. return r;
  185. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  186. return 0;
  187. }
  188. static void nec_8048_panel_disable(struct omap_dss_device *dssdev)
  189. {
  190. nec_8048_panel_power_off(dssdev);
  191. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  192. }
  193. static int nec_8048_recommended_bpp(struct omap_dss_device *dssdev)
  194. {
  195. return 16;
  196. }
  197. static struct omap_dss_driver nec_8048_driver = {
  198. .probe = nec_8048_panel_probe,
  199. .remove = nec_8048_panel_remove,
  200. .enable = nec_8048_panel_enable,
  201. .disable = nec_8048_panel_disable,
  202. .get_recommended_bpp = nec_8048_recommended_bpp,
  203. .driver = {
  204. .name = "NEC_8048_panel",
  205. .owner = THIS_MODULE,
  206. },
  207. };
  208. static int nec_8048_spi_send(struct spi_device *spi, unsigned char reg_addr,
  209. unsigned char reg_data)
  210. {
  211. int ret = 0;
  212. unsigned int cmd = 0, data = 0;
  213. cmd = 0x0000 | reg_addr; /* register address write */
  214. data = 0x0100 | reg_data ; /* register data write */
  215. data = (cmd << 16) | data;
  216. ret = spi_write(spi, (unsigned char *)&data, 4);
  217. if (ret)
  218. pr_err("error in spi_write %x\n", data);
  219. return ret;
  220. }
  221. static int init_nec_8048_wvga_lcd(struct spi_device *spi)
  222. {
  223. unsigned int i;
  224. /* Initialization Sequence */
  225. /* nec_8048_spi_send(spi, REG, VAL) */
  226. for (i = 0; i < (ARRAY_SIZE(nec_8048_init_seq) - 1); i++)
  227. nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
  228. nec_8048_init_seq[i].dat);
  229. udelay(20);
  230. nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
  231. nec_8048_init_seq[i].dat);
  232. return 0;
  233. }
  234. static int nec_8048_spi_probe(struct spi_device *spi)
  235. {
  236. spi->mode = SPI_MODE_0;
  237. spi->bits_per_word = 32;
  238. spi_setup(spi);
  239. init_nec_8048_wvga_lcd(spi);
  240. return omap_dss_register_driver(&nec_8048_driver);
  241. }
  242. static int nec_8048_spi_remove(struct spi_device *spi)
  243. {
  244. omap_dss_unregister_driver(&nec_8048_driver);
  245. return 0;
  246. }
  247. static int nec_8048_spi_suspend(struct spi_device *spi, pm_message_t mesg)
  248. {
  249. nec_8048_spi_send(spi, 2, 0x01);
  250. mdelay(40);
  251. return 0;
  252. }
  253. static int nec_8048_spi_resume(struct spi_device *spi)
  254. {
  255. /* reinitialize the panel */
  256. spi_setup(spi);
  257. nec_8048_spi_send(spi, 2, 0x00);
  258. init_nec_8048_wvga_lcd(spi);
  259. return 0;
  260. }
  261. static struct spi_driver nec_8048_spi_driver = {
  262. .probe = nec_8048_spi_probe,
  263. .remove = nec_8048_spi_remove,
  264. .suspend = nec_8048_spi_suspend,
  265. .resume = nec_8048_spi_resume,
  266. .driver = {
  267. .name = "nec_8048_spi",
  268. .owner = THIS_MODULE,
  269. },
  270. };
  271. module_spi_driver(nec_8048_spi_driver);
  272. MODULE_AUTHOR("Erik Gilling <konkers@android.com>");
  273. MODULE_DESCRIPTION("NEC-nl8048hl11-01b Driver");
  274. MODULE_LICENSE("GPL");