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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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/fb.h>
  22. #include <linux/gpio.h>
  23. #include <video/omapdss.h>
  24. #include <video/omap-panel-data.h>
  25. #define LCD_XRES 800
  26. #define LCD_YRES 480
  27. /*
  28. * NEC PIX Clock Ratings
  29. * MIN:21.8MHz TYP:23.8MHz MAX:25.7MHz
  30. */
  31. #define LCD_PIXEL_CLOCK 23800
  32. static const struct {
  33. unsigned char addr;
  34. unsigned char dat;
  35. } nec_8048_init_seq[] = {
  36. { 3, 0x01 }, { 0, 0x00 }, { 1, 0x01 }, { 4, 0x00 }, { 5, 0x14 },
  37. { 6, 0x24 }, { 16, 0xD7 }, { 17, 0x00 }, { 18, 0x00 }, { 19, 0x55 },
  38. { 20, 0x01 }, { 21, 0x70 }, { 22, 0x1E }, { 23, 0x25 }, { 24, 0x25 },
  39. { 25, 0x02 }, { 26, 0x02 }, { 27, 0xA0 }, { 32, 0x2F }, { 33, 0x0F },
  40. { 34, 0x0F }, { 35, 0x0F }, { 36, 0x0F }, { 37, 0x0F }, { 38, 0x0F },
  41. { 39, 0x00 }, { 40, 0x02 }, { 41, 0x02 }, { 42, 0x02 }, { 43, 0x0F },
  42. { 44, 0x0F }, { 45, 0x0F }, { 46, 0x0F }, { 47, 0x0F }, { 48, 0x0F },
  43. { 49, 0x0F }, { 50, 0x00 }, { 51, 0x02 }, { 52, 0x02 }, { 53, 0x02 },
  44. { 80, 0x0C }, { 83, 0x42 }, { 84, 0x42 }, { 85, 0x41 }, { 86, 0x14 },
  45. { 89, 0x88 }, { 90, 0x01 }, { 91, 0x00 }, { 92, 0x02 }, { 93, 0x0C },
  46. { 94, 0x1C }, { 95, 0x27 }, { 98, 0x49 }, { 99, 0x27 }, { 102, 0x76 },
  47. { 103, 0x27 }, { 112, 0x01 }, { 113, 0x0E }, { 114, 0x02 },
  48. { 115, 0x0C }, { 118, 0x0C }, { 121, 0x30 }, { 130, 0x00 },
  49. { 131, 0x00 }, { 132, 0xFC }, { 134, 0x00 }, { 136, 0x00 },
  50. { 138, 0x00 }, { 139, 0x00 }, { 140, 0x00 }, { 141, 0xFC },
  51. { 143, 0x00 }, { 145, 0x00 }, { 147, 0x00 }, { 148, 0x00 },
  52. { 149, 0x00 }, { 150, 0xFC }, { 152, 0x00 }, { 154, 0x00 },
  53. { 156, 0x00 }, { 157, 0x00 }, { 2, 0x00 },
  54. };
  55. /*
  56. * NEC NL8048HL11-01B Manual
  57. * defines HFB, HSW, HBP, VFP, VSW, VBP as shown below
  58. */
  59. static struct omap_video_timings nec_8048_panel_timings = {
  60. /* 800 x 480 @ 60 Hz Reduced blanking VESA CVT 0.31M3-R */
  61. .x_res = LCD_XRES,
  62. .y_res = LCD_YRES,
  63. .pixel_clock = LCD_PIXEL_CLOCK,
  64. .hfp = 6,
  65. .hsw = 1,
  66. .hbp = 4,
  67. .vfp = 3,
  68. .vsw = 1,
  69. .vbp = 4,
  70. .vsync_level = OMAPDSS_SIG_ACTIVE_LOW,
  71. .hsync_level = OMAPDSS_SIG_ACTIVE_LOW,
  72. .data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE,
  73. .de_level = OMAPDSS_SIG_ACTIVE_HIGH,
  74. .sync_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE,
  75. };
  76. static inline struct panel_nec_nl8048_data
  77. *get_panel_data(const struct omap_dss_device *dssdev)
  78. {
  79. return (struct panel_nec_nl8048_data *) dssdev->data;
  80. }
  81. static int nec_8048_panel_probe(struct omap_dss_device *dssdev)
  82. {
  83. struct panel_nec_nl8048_data *pd = get_panel_data(dssdev);
  84. int r;
  85. if (!pd)
  86. return -EINVAL;
  87. dssdev->panel.timings = nec_8048_panel_timings;
  88. if (gpio_is_valid(pd->qvga_gpio)) {
  89. r = devm_gpio_request_one(dssdev->dev, pd->qvga_gpio,
  90. GPIOF_OUT_INIT_HIGH, "lcd QVGA");
  91. if (r)
  92. return r;
  93. }
  94. if (gpio_is_valid(pd->res_gpio)) {
  95. r = devm_gpio_request_one(dssdev->dev, pd->res_gpio,
  96. GPIOF_OUT_INIT_LOW, "lcd RES");
  97. if (r)
  98. return r;
  99. }
  100. return 0;
  101. }
  102. static void nec_8048_panel_remove(struct omap_dss_device *dssdev)
  103. {
  104. }
  105. static int nec_8048_panel_power_on(struct omap_dss_device *dssdev)
  106. {
  107. struct panel_nec_nl8048_data *pd = get_panel_data(dssdev);
  108. int r;
  109. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  110. return 0;
  111. omapdss_dpi_set_timings(dssdev, &dssdev->panel.timings);
  112. omapdss_dpi_set_data_lines(dssdev, dssdev->phy.dpi.data_lines);
  113. r = omapdss_dpi_display_enable(dssdev);
  114. if (r)
  115. goto err0;
  116. if (gpio_is_valid(pd->res_gpio))
  117. gpio_set_value_cansleep(pd->res_gpio, 1);
  118. return 0;
  119. err0:
  120. return r;
  121. }
  122. static void nec_8048_panel_power_off(struct omap_dss_device *dssdev)
  123. {
  124. struct panel_nec_nl8048_data *pd = get_panel_data(dssdev);
  125. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
  126. return;
  127. if (gpio_is_valid(pd->res_gpio))
  128. gpio_set_value_cansleep(pd->res_gpio, 0);
  129. omapdss_dpi_display_disable(dssdev);
  130. }
  131. static int nec_8048_panel_enable(struct omap_dss_device *dssdev)
  132. {
  133. int r;
  134. r = nec_8048_panel_power_on(dssdev);
  135. if (r)
  136. return r;
  137. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  138. return 0;
  139. }
  140. static void nec_8048_panel_disable(struct omap_dss_device *dssdev)
  141. {
  142. nec_8048_panel_power_off(dssdev);
  143. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  144. }
  145. static int nec_8048_recommended_bpp(struct omap_dss_device *dssdev)
  146. {
  147. return 16;
  148. }
  149. static struct omap_dss_driver nec_8048_driver = {
  150. .probe = nec_8048_panel_probe,
  151. .remove = nec_8048_panel_remove,
  152. .enable = nec_8048_panel_enable,
  153. .disable = nec_8048_panel_disable,
  154. .get_recommended_bpp = nec_8048_recommended_bpp,
  155. .driver = {
  156. .name = "NEC_8048_panel",
  157. .owner = THIS_MODULE,
  158. },
  159. };
  160. static int nec_8048_spi_send(struct spi_device *spi, unsigned char reg_addr,
  161. unsigned char reg_data)
  162. {
  163. int ret = 0;
  164. unsigned int cmd = 0, data = 0;
  165. cmd = 0x0000 | reg_addr; /* register address write */
  166. data = 0x0100 | reg_data ; /* register data write */
  167. data = (cmd << 16) | data;
  168. ret = spi_write(spi, (unsigned char *)&data, 4);
  169. if (ret)
  170. pr_err("error in spi_write %x\n", data);
  171. return ret;
  172. }
  173. static int init_nec_8048_wvga_lcd(struct spi_device *spi)
  174. {
  175. unsigned int i;
  176. /* Initialization Sequence */
  177. /* nec_8048_spi_send(spi, REG, VAL) */
  178. for (i = 0; i < (ARRAY_SIZE(nec_8048_init_seq) - 1); i++)
  179. nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
  180. nec_8048_init_seq[i].dat);
  181. udelay(20);
  182. nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
  183. nec_8048_init_seq[i].dat);
  184. return 0;
  185. }
  186. static int nec_8048_spi_probe(struct spi_device *spi)
  187. {
  188. spi->mode = SPI_MODE_0;
  189. spi->bits_per_word = 32;
  190. spi_setup(spi);
  191. init_nec_8048_wvga_lcd(spi);
  192. return omap_dss_register_driver(&nec_8048_driver);
  193. }
  194. static int nec_8048_spi_remove(struct spi_device *spi)
  195. {
  196. omap_dss_unregister_driver(&nec_8048_driver);
  197. return 0;
  198. }
  199. #ifdef CONFIG_PM_SLEEP
  200. static int nec_8048_spi_suspend(struct device *dev)
  201. {
  202. struct spi_device *spi = to_spi_device(dev);
  203. nec_8048_spi_send(spi, 2, 0x01);
  204. mdelay(40);
  205. return 0;
  206. }
  207. static int nec_8048_spi_resume(struct device *dev)
  208. {
  209. struct spi_device *spi = to_spi_device(dev);
  210. /* reinitialize the panel */
  211. spi_setup(spi);
  212. nec_8048_spi_send(spi, 2, 0x00);
  213. init_nec_8048_wvga_lcd(spi);
  214. return 0;
  215. }
  216. static SIMPLE_DEV_PM_OPS(nec_8048_spi_pm_ops, nec_8048_spi_suspend,
  217. nec_8048_spi_resume);
  218. #define NEC_8048_SPI_PM_OPS (&nec_8048_spi_pm_ops)
  219. #else
  220. #define NEC_8048_SPI_PM_OPS NULL
  221. #endif
  222. static struct spi_driver nec_8048_spi_driver = {
  223. .probe = nec_8048_spi_probe,
  224. .remove = nec_8048_spi_remove,
  225. .driver = {
  226. .name = "nec_8048_spi",
  227. .owner = THIS_MODULE,
  228. .pm = NEC_8048_SPI_PM_OPS,
  229. },
  230. };
  231. module_spi_driver(nec_8048_spi_driver);
  232. MODULE_AUTHOR("Erik Gilling <konkers@android.com>");
  233. MODULE_DESCRIPTION("NEC-nl8048hl11-01b Driver");
  234. MODULE_LICENSE("GPL");