panel-nec-nl8048hl11.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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 <linux/of_gpio.h>
  19. #include <video/omapdss.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 23800000
  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. .pixelclock = 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. if (ddata->data_lines)
  132. in->ops.dpi->set_data_lines(in, ddata->data_lines);
  133. in->ops.dpi->set_timings(in, &ddata->videomode);
  134. r = in->ops.dpi->enable(in);
  135. if (r)
  136. return r;
  137. if (gpio_is_valid(ddata->res_gpio))
  138. gpio_set_value_cansleep(ddata->res_gpio, 1);
  139. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  140. return 0;
  141. }
  142. static void nec_8048_disable(struct omap_dss_device *dssdev)
  143. {
  144. struct panel_drv_data *ddata = to_panel_data(dssdev);
  145. struct omap_dss_device *in = ddata->in;
  146. if (!omapdss_device_is_enabled(dssdev))
  147. return;
  148. if (gpio_is_valid(ddata->res_gpio))
  149. gpio_set_value_cansleep(ddata->res_gpio, 0);
  150. in->ops.dpi->disable(in);
  151. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  152. }
  153. static void nec_8048_set_timings(struct omap_dss_device *dssdev,
  154. struct omap_video_timings *timings)
  155. {
  156. struct panel_drv_data *ddata = to_panel_data(dssdev);
  157. struct omap_dss_device *in = ddata->in;
  158. ddata->videomode = *timings;
  159. dssdev->panel.timings = *timings;
  160. in->ops.dpi->set_timings(in, timings);
  161. }
  162. static void nec_8048_get_timings(struct omap_dss_device *dssdev,
  163. struct omap_video_timings *timings)
  164. {
  165. struct panel_drv_data *ddata = to_panel_data(dssdev);
  166. *timings = ddata->videomode;
  167. }
  168. static int nec_8048_check_timings(struct omap_dss_device *dssdev,
  169. struct omap_video_timings *timings)
  170. {
  171. struct panel_drv_data *ddata = to_panel_data(dssdev);
  172. struct omap_dss_device *in = ddata->in;
  173. return in->ops.dpi->check_timings(in, timings);
  174. }
  175. static struct omap_dss_driver nec_8048_ops = {
  176. .connect = nec_8048_connect,
  177. .disconnect = nec_8048_disconnect,
  178. .enable = nec_8048_enable,
  179. .disable = nec_8048_disable,
  180. .set_timings = nec_8048_set_timings,
  181. .get_timings = nec_8048_get_timings,
  182. .check_timings = nec_8048_check_timings,
  183. .get_resolution = omapdss_default_get_resolution,
  184. };
  185. static int nec_8048_probe_of(struct spi_device *spi)
  186. {
  187. struct device_node *node = spi->dev.of_node;
  188. struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
  189. struct omap_dss_device *in;
  190. int gpio;
  191. gpio = of_get_named_gpio(node, "reset-gpios", 0);
  192. if (!gpio_is_valid(gpio)) {
  193. dev_err(&spi->dev, "failed to parse enable gpio\n");
  194. return gpio;
  195. }
  196. ddata->res_gpio = gpio;
  197. /* XXX the panel spec doesn't mention any QVGA pin?? */
  198. ddata->qvga_gpio = -ENOENT;
  199. in = omapdss_of_find_source_for_first_ep(node);
  200. if (IS_ERR(in)) {
  201. dev_err(&spi->dev, "failed to find video source\n");
  202. return PTR_ERR(in);
  203. }
  204. ddata->in = in;
  205. return 0;
  206. }
  207. static int nec_8048_probe(struct spi_device *spi)
  208. {
  209. struct panel_drv_data *ddata;
  210. struct omap_dss_device *dssdev;
  211. int r;
  212. dev_dbg(&spi->dev, "%s\n", __func__);
  213. spi->mode = SPI_MODE_0;
  214. spi->bits_per_word = 32;
  215. r = spi_setup(spi);
  216. if (r < 0) {
  217. dev_err(&spi->dev, "spi_setup failed: %d\n", r);
  218. return r;
  219. }
  220. init_nec_8048_wvga_lcd(spi);
  221. ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL);
  222. if (ddata == NULL)
  223. return -ENOMEM;
  224. dev_set_drvdata(&spi->dev, ddata);
  225. ddata->spi = spi;
  226. if (!spi->dev.of_node)
  227. return -ENODEV;
  228. r = nec_8048_probe_of(spi);
  229. if (r)
  230. return r;
  231. if (gpio_is_valid(ddata->qvga_gpio)) {
  232. r = devm_gpio_request_one(&spi->dev, ddata->qvga_gpio,
  233. GPIOF_OUT_INIT_HIGH, "lcd QVGA");
  234. if (r)
  235. goto err_gpio;
  236. }
  237. if (gpio_is_valid(ddata->res_gpio)) {
  238. r = devm_gpio_request_one(&spi->dev, ddata->res_gpio,
  239. GPIOF_OUT_INIT_LOW, "lcd RES");
  240. if (r)
  241. goto err_gpio;
  242. }
  243. ddata->videomode = nec_8048_panel_timings;
  244. dssdev = &ddata->dssdev;
  245. dssdev->dev = &spi->dev;
  246. dssdev->driver = &nec_8048_ops;
  247. dssdev->type = OMAP_DISPLAY_TYPE_DPI;
  248. dssdev->owner = THIS_MODULE;
  249. dssdev->panel.timings = ddata->videomode;
  250. r = omapdss_register_display(dssdev);
  251. if (r) {
  252. dev_err(&spi->dev, "Failed to register panel\n");
  253. goto err_reg;
  254. }
  255. return 0;
  256. err_reg:
  257. err_gpio:
  258. omap_dss_put_device(ddata->in);
  259. return r;
  260. }
  261. static int nec_8048_remove(struct spi_device *spi)
  262. {
  263. struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
  264. struct omap_dss_device *dssdev = &ddata->dssdev;
  265. struct omap_dss_device *in = ddata->in;
  266. dev_dbg(&ddata->spi->dev, "%s\n", __func__);
  267. omapdss_unregister_display(dssdev);
  268. nec_8048_disable(dssdev);
  269. nec_8048_disconnect(dssdev);
  270. omap_dss_put_device(in);
  271. return 0;
  272. }
  273. #ifdef CONFIG_PM_SLEEP
  274. static int nec_8048_suspend(struct device *dev)
  275. {
  276. struct spi_device *spi = to_spi_device(dev);
  277. nec_8048_spi_send(spi, 2, 0x01);
  278. mdelay(40);
  279. return 0;
  280. }
  281. static int nec_8048_resume(struct device *dev)
  282. {
  283. struct spi_device *spi = to_spi_device(dev);
  284. /* reinitialize the panel */
  285. spi_setup(spi);
  286. nec_8048_spi_send(spi, 2, 0x00);
  287. init_nec_8048_wvga_lcd(spi);
  288. return 0;
  289. }
  290. static SIMPLE_DEV_PM_OPS(nec_8048_pm_ops, nec_8048_suspend,
  291. nec_8048_resume);
  292. #define NEC_8048_PM_OPS (&nec_8048_pm_ops)
  293. #else
  294. #define NEC_8048_PM_OPS NULL
  295. #endif
  296. static const struct of_device_id nec_8048_of_match[] = {
  297. { .compatible = "omapdss,nec,nl8048hl11", },
  298. {},
  299. };
  300. MODULE_DEVICE_TABLE(of, nec_8048_of_match);
  301. static struct spi_driver nec_8048_driver = {
  302. .driver = {
  303. .name = "panel-nec-nl8048hl11",
  304. .pm = NEC_8048_PM_OPS,
  305. .of_match_table = nec_8048_of_match,
  306. .suppress_bind_attrs = true,
  307. },
  308. .probe = nec_8048_probe,
  309. .remove = nec_8048_remove,
  310. };
  311. module_spi_driver(nec_8048_driver);
  312. MODULE_ALIAS("spi:nec,nl8048hl11");
  313. MODULE_AUTHOR("Erik Gilling <konkers@android.com>");
  314. MODULE_DESCRIPTION("NEC-NL8048HL11 Driver");
  315. MODULE_LICENSE("GPL");