panel-nec-nl8048hl11.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. /*
  2. * NEC NL8048HL11 Panel driver
  3. *
  4. * Copyright (C) 2010 Texas Instruments Inc.
  5. * Author: Erik Gilling <konkers@android.com>
  6. * Converted to new DSS device model: Tomi Valkeinen <tomi.valkeinen@ti.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/delay.h>
  15. #include <linux/spi/spi.h>
  16. #include <linux/fb.h>
  17. #include <linux/gpio.h>
  18. #include <video/omapdss.h>
  19. #include <video/omap-panel-data.h>
  20. struct panel_drv_data {
  21. struct omap_dss_device dssdev;
  22. struct omap_dss_device *in;
  23. struct omap_video_timings videomode;
  24. int data_lines;
  25. int res_gpio;
  26. int qvga_gpio;
  27. struct spi_device *spi;
  28. };
  29. #define LCD_XRES 800
  30. #define LCD_YRES 480
  31. /*
  32. * NEC PIX Clock Ratings
  33. * MIN:21.8MHz TYP:23.8MHz MAX:25.7MHz
  34. */
  35. #define LCD_PIXEL_CLOCK 23800
  36. static const struct {
  37. unsigned char addr;
  38. unsigned char dat;
  39. } nec_8048_init_seq[] = {
  40. { 3, 0x01 }, { 0, 0x00 }, { 1, 0x01 }, { 4, 0x00 }, { 5, 0x14 },
  41. { 6, 0x24 }, { 16, 0xD7 }, { 17, 0x00 }, { 18, 0x00 }, { 19, 0x55 },
  42. { 20, 0x01 }, { 21, 0x70 }, { 22, 0x1E }, { 23, 0x25 }, { 24, 0x25 },
  43. { 25, 0x02 }, { 26, 0x02 }, { 27, 0xA0 }, { 32, 0x2F }, { 33, 0x0F },
  44. { 34, 0x0F }, { 35, 0x0F }, { 36, 0x0F }, { 37, 0x0F }, { 38, 0x0F },
  45. { 39, 0x00 }, { 40, 0x02 }, { 41, 0x02 }, { 42, 0x02 }, { 43, 0x0F },
  46. { 44, 0x0F }, { 45, 0x0F }, { 46, 0x0F }, { 47, 0x0F }, { 48, 0x0F },
  47. { 49, 0x0F }, { 50, 0x00 }, { 51, 0x02 }, { 52, 0x02 }, { 53, 0x02 },
  48. { 80, 0x0C }, { 83, 0x42 }, { 84, 0x42 }, { 85, 0x41 }, { 86, 0x14 },
  49. { 89, 0x88 }, { 90, 0x01 }, { 91, 0x00 }, { 92, 0x02 }, { 93, 0x0C },
  50. { 94, 0x1C }, { 95, 0x27 }, { 98, 0x49 }, { 99, 0x27 }, { 102, 0x76 },
  51. { 103, 0x27 }, { 112, 0x01 }, { 113, 0x0E }, { 114, 0x02 },
  52. { 115, 0x0C }, { 118, 0x0C }, { 121, 0x30 }, { 130, 0x00 },
  53. { 131, 0x00 }, { 132, 0xFC }, { 134, 0x00 }, { 136, 0x00 },
  54. { 138, 0x00 }, { 139, 0x00 }, { 140, 0x00 }, { 141, 0xFC },
  55. { 143, 0x00 }, { 145, 0x00 }, { 147, 0x00 }, { 148, 0x00 },
  56. { 149, 0x00 }, { 150, 0xFC }, { 152, 0x00 }, { 154, 0x00 },
  57. { 156, 0x00 }, { 157, 0x00 }, { 2, 0x00 },
  58. };
  59. static const struct omap_video_timings nec_8048_panel_timings = {
  60. .x_res = LCD_XRES,
  61. .y_res = LCD_YRES,
  62. .pixel_clock = LCD_PIXEL_CLOCK,
  63. .hfp = 6,
  64. .hsw = 1,
  65. .hbp = 4,
  66. .vfp = 3,
  67. .vsw = 1,
  68. .vbp = 4,
  69. .vsync_level = OMAPDSS_SIG_ACTIVE_LOW,
  70. .hsync_level = OMAPDSS_SIG_ACTIVE_LOW,
  71. .data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE,
  72. .de_level = OMAPDSS_SIG_ACTIVE_HIGH,
  73. .sync_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE,
  74. };
  75. #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
  76. static int nec_8048_spi_send(struct spi_device *spi, unsigned char reg_addr,
  77. unsigned char reg_data)
  78. {
  79. int ret = 0;
  80. unsigned int cmd = 0, data = 0;
  81. cmd = 0x0000 | reg_addr; /* register address write */
  82. data = 0x0100 | reg_data; /* register data write */
  83. data = (cmd << 16) | data;
  84. ret = spi_write(spi, (unsigned char *)&data, 4);
  85. if (ret)
  86. pr_err("error in spi_write %x\n", data);
  87. return ret;
  88. }
  89. static int init_nec_8048_wvga_lcd(struct spi_device *spi)
  90. {
  91. unsigned int i;
  92. /* Initialization Sequence */
  93. /* nec_8048_spi_send(spi, REG, VAL) */
  94. for (i = 0; i < (ARRAY_SIZE(nec_8048_init_seq) - 1); i++)
  95. nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
  96. nec_8048_init_seq[i].dat);
  97. udelay(20);
  98. nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
  99. nec_8048_init_seq[i].dat);
  100. return 0;
  101. }
  102. static int nec_8048_connect(struct omap_dss_device *dssdev)
  103. {
  104. struct panel_drv_data *ddata = to_panel_data(dssdev);
  105. struct omap_dss_device *in = ddata->in;
  106. int r;
  107. if (omapdss_device_is_connected(dssdev))
  108. return 0;
  109. r = in->ops.dpi->connect(in, dssdev);
  110. if (r)
  111. return r;
  112. return 0;
  113. }
  114. static void nec_8048_disconnect(struct omap_dss_device *dssdev)
  115. {
  116. struct panel_drv_data *ddata = to_panel_data(dssdev);
  117. struct omap_dss_device *in = ddata->in;
  118. if (!omapdss_device_is_connected(dssdev))
  119. return;
  120. in->ops.dpi->disconnect(in, dssdev);
  121. }
  122. static int nec_8048_enable(struct omap_dss_device *dssdev)
  123. {
  124. struct panel_drv_data *ddata = to_panel_data(dssdev);
  125. struct omap_dss_device *in = ddata->in;
  126. int r;
  127. if (!omapdss_device_is_connected(dssdev))
  128. return -ENODEV;
  129. if (omapdss_device_is_enabled(dssdev))
  130. return 0;
  131. in->ops.dpi->set_data_lines(in, ddata->data_lines);
  132. in->ops.dpi->set_timings(in, &ddata->videomode);
  133. r = in->ops.dpi->enable(in);
  134. if (r)
  135. return r;
  136. if (gpio_is_valid(ddata->res_gpio))
  137. gpio_set_value_cansleep(ddata->res_gpio, 1);
  138. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  139. return 0;
  140. }
  141. static void nec_8048_disable(struct omap_dss_device *dssdev)
  142. {
  143. struct panel_drv_data *ddata = to_panel_data(dssdev);
  144. struct omap_dss_device *in = ddata->in;
  145. if (!omapdss_device_is_enabled(dssdev))
  146. return;
  147. if (gpio_is_valid(ddata->res_gpio))
  148. gpio_set_value_cansleep(ddata->res_gpio, 0);
  149. in->ops.dpi->disable(in);
  150. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  151. }
  152. static void nec_8048_set_timings(struct omap_dss_device *dssdev,
  153. struct omap_video_timings *timings)
  154. {
  155. struct panel_drv_data *ddata = to_panel_data(dssdev);
  156. struct omap_dss_device *in = ddata->in;
  157. ddata->videomode = *timings;
  158. dssdev->panel.timings = *timings;
  159. in->ops.dpi->set_timings(in, timings);
  160. }
  161. static void nec_8048_get_timings(struct omap_dss_device *dssdev,
  162. struct omap_video_timings *timings)
  163. {
  164. struct panel_drv_data *ddata = to_panel_data(dssdev);
  165. *timings = ddata->videomode;
  166. }
  167. static int nec_8048_check_timings(struct omap_dss_device *dssdev,
  168. struct omap_video_timings *timings)
  169. {
  170. struct panel_drv_data *ddata = to_panel_data(dssdev);
  171. struct omap_dss_device *in = ddata->in;
  172. return in->ops.dpi->check_timings(in, timings);
  173. }
  174. static struct omap_dss_driver nec_8048_ops = {
  175. .connect = nec_8048_connect,
  176. .disconnect = nec_8048_disconnect,
  177. .enable = nec_8048_enable,
  178. .disable = nec_8048_disable,
  179. .set_timings = nec_8048_set_timings,
  180. .get_timings = nec_8048_get_timings,
  181. .check_timings = nec_8048_check_timings,
  182. .get_resolution = omapdss_default_get_resolution,
  183. };
  184. static int nec_8048_probe_pdata(struct spi_device *spi)
  185. {
  186. const struct panel_nec_nl8048hl11_platform_data *pdata;
  187. struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
  188. struct omap_dss_device *dssdev, *in;
  189. pdata = dev_get_platdata(&spi->dev);
  190. ddata->qvga_gpio = pdata->qvga_gpio;
  191. ddata->res_gpio = pdata->res_gpio;
  192. in = omap_dss_find_output(pdata->source);
  193. if (in == NULL) {
  194. dev_err(&spi->dev, "failed to find video source '%s'\n",
  195. pdata->source);
  196. return -EPROBE_DEFER;
  197. }
  198. ddata->in = in;
  199. ddata->data_lines = pdata->data_lines;
  200. dssdev = &ddata->dssdev;
  201. dssdev->name = pdata->name;
  202. return 0;
  203. }
  204. static int nec_8048_probe(struct spi_device *spi)
  205. {
  206. struct panel_drv_data *ddata;
  207. struct omap_dss_device *dssdev;
  208. int r;
  209. dev_dbg(&spi->dev, "%s\n", __func__);
  210. spi->mode = SPI_MODE_0;
  211. spi->bits_per_word = 32;
  212. r = spi_setup(spi);
  213. if (r < 0) {
  214. dev_err(&spi->dev, "spi_setup failed: %d\n", r);
  215. return r;
  216. }
  217. init_nec_8048_wvga_lcd(spi);
  218. ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL);
  219. if (ddata == NULL)
  220. return -ENOMEM;
  221. dev_set_drvdata(&spi->dev, ddata);
  222. ddata->spi = spi;
  223. if (dev_get_platdata(&spi->dev)) {
  224. r = nec_8048_probe_pdata(spi);
  225. if (r)
  226. return r;
  227. } else {
  228. return -ENODEV;
  229. }
  230. if (gpio_is_valid(ddata->qvga_gpio)) {
  231. r = devm_gpio_request_one(&spi->dev, ddata->qvga_gpio,
  232. GPIOF_OUT_INIT_HIGH, "lcd QVGA");
  233. if (r)
  234. goto err_gpio;
  235. }
  236. if (gpio_is_valid(ddata->res_gpio)) {
  237. r = devm_gpio_request_one(&spi->dev, ddata->res_gpio,
  238. GPIOF_OUT_INIT_LOW, "lcd RES");
  239. if (r)
  240. goto err_gpio;
  241. }
  242. ddata->videomode = nec_8048_panel_timings;
  243. dssdev = &ddata->dssdev;
  244. dssdev->dev = &spi->dev;
  245. dssdev->driver = &nec_8048_ops;
  246. dssdev->type = OMAP_DISPLAY_TYPE_DPI;
  247. dssdev->owner = THIS_MODULE;
  248. dssdev->panel.timings = ddata->videomode;
  249. r = omapdss_register_display(dssdev);
  250. if (r) {
  251. dev_err(&spi->dev, "Failed to register panel\n");
  252. goto err_reg;
  253. }
  254. return 0;
  255. err_reg:
  256. err_gpio:
  257. omap_dss_put_device(ddata->in);
  258. return r;
  259. }
  260. static int nec_8048_remove(struct spi_device *spi)
  261. {
  262. struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
  263. struct omap_dss_device *dssdev = &ddata->dssdev;
  264. struct omap_dss_device *in = ddata->in;
  265. dev_dbg(&ddata->spi->dev, "%s\n", __func__);
  266. omapdss_unregister_display(dssdev);
  267. nec_8048_disable(dssdev);
  268. nec_8048_disconnect(dssdev);
  269. omap_dss_put_device(in);
  270. return 0;
  271. }
  272. #ifdef CONFIG_PM_SLEEP
  273. static int nec_8048_suspend(struct device *dev)
  274. {
  275. struct spi_device *spi = to_spi_device(dev);
  276. nec_8048_spi_send(spi, 2, 0x01);
  277. mdelay(40);
  278. return 0;
  279. }
  280. static int nec_8048_resume(struct device *dev)
  281. {
  282. struct spi_device *spi = to_spi_device(dev);
  283. /* reinitialize the panel */
  284. spi_setup(spi);
  285. nec_8048_spi_send(spi, 2, 0x00);
  286. init_nec_8048_wvga_lcd(spi);
  287. return 0;
  288. }
  289. static SIMPLE_DEV_PM_OPS(nec_8048_pm_ops, nec_8048_suspend,
  290. nec_8048_resume);
  291. #define NEC_8048_PM_OPS (&nec_8048_pm_ops)
  292. #else
  293. #define NEC_8048_PM_OPS NULL
  294. #endif
  295. static struct spi_driver nec_8048_driver = {
  296. .driver = {
  297. .name = "panel-nec-nl8048hl11",
  298. .owner = THIS_MODULE,
  299. .pm = NEC_8048_PM_OPS,
  300. },
  301. .probe = nec_8048_probe,
  302. .remove = nec_8048_remove,
  303. };
  304. module_spi_driver(nec_8048_driver);
  305. MODULE_AUTHOR("Erik Gilling <konkers@android.com>");
  306. MODULE_DESCRIPTION("NEC-NL8048HL11 Driver");
  307. MODULE_LICENSE("GPL");