panel-nec-nl8048hl11.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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. #include <video/omap-panel-data.h>
  21. struct panel_drv_data {
  22. struct omap_dss_device dssdev;
  23. struct omap_dss_device *in;
  24. struct omap_video_timings videomode;
  25. int data_lines;
  26. int res_gpio;
  27. int qvga_gpio;
  28. struct spi_device *spi;
  29. };
  30. #define LCD_XRES 800
  31. #define LCD_YRES 480
  32. /*
  33. * NEC PIX Clock Ratings
  34. * MIN:21.8MHz TYP:23.8MHz MAX:25.7MHz
  35. */
  36. #define LCD_PIXEL_CLOCK 23800000
  37. static const struct {
  38. unsigned char addr;
  39. unsigned char dat;
  40. } nec_8048_init_seq[] = {
  41. { 3, 0x01 }, { 0, 0x00 }, { 1, 0x01 }, { 4, 0x00 }, { 5, 0x14 },
  42. { 6, 0x24 }, { 16, 0xD7 }, { 17, 0x00 }, { 18, 0x00 }, { 19, 0x55 },
  43. { 20, 0x01 }, { 21, 0x70 }, { 22, 0x1E }, { 23, 0x25 }, { 24, 0x25 },
  44. { 25, 0x02 }, { 26, 0x02 }, { 27, 0xA0 }, { 32, 0x2F }, { 33, 0x0F },
  45. { 34, 0x0F }, { 35, 0x0F }, { 36, 0x0F }, { 37, 0x0F }, { 38, 0x0F },
  46. { 39, 0x00 }, { 40, 0x02 }, { 41, 0x02 }, { 42, 0x02 }, { 43, 0x0F },
  47. { 44, 0x0F }, { 45, 0x0F }, { 46, 0x0F }, { 47, 0x0F }, { 48, 0x0F },
  48. { 49, 0x0F }, { 50, 0x00 }, { 51, 0x02 }, { 52, 0x02 }, { 53, 0x02 },
  49. { 80, 0x0C }, { 83, 0x42 }, { 84, 0x42 }, { 85, 0x41 }, { 86, 0x14 },
  50. { 89, 0x88 }, { 90, 0x01 }, { 91, 0x00 }, { 92, 0x02 }, { 93, 0x0C },
  51. { 94, 0x1C }, { 95, 0x27 }, { 98, 0x49 }, { 99, 0x27 }, { 102, 0x76 },
  52. { 103, 0x27 }, { 112, 0x01 }, { 113, 0x0E }, { 114, 0x02 },
  53. { 115, 0x0C }, { 118, 0x0C }, { 121, 0x30 }, { 130, 0x00 },
  54. { 131, 0x00 }, { 132, 0xFC }, { 134, 0x00 }, { 136, 0x00 },
  55. { 138, 0x00 }, { 139, 0x00 }, { 140, 0x00 }, { 141, 0xFC },
  56. { 143, 0x00 }, { 145, 0x00 }, { 147, 0x00 }, { 148, 0x00 },
  57. { 149, 0x00 }, { 150, 0xFC }, { 152, 0x00 }, { 154, 0x00 },
  58. { 156, 0x00 }, { 157, 0x00 }, { 2, 0x00 },
  59. };
  60. static const struct omap_video_timings nec_8048_panel_timings = {
  61. .x_res = LCD_XRES,
  62. .y_res = LCD_YRES,
  63. .pixelclock = 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. #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
  77. static int nec_8048_spi_send(struct spi_device *spi, unsigned char reg_addr,
  78. unsigned char reg_data)
  79. {
  80. int ret = 0;
  81. unsigned int cmd = 0, data = 0;
  82. cmd = 0x0000 | reg_addr; /* register address write */
  83. data = 0x0100 | reg_data; /* register data write */
  84. data = (cmd << 16) | data;
  85. ret = spi_write(spi, (unsigned char *)&data, 4);
  86. if (ret)
  87. pr_err("error in spi_write %x\n", data);
  88. return ret;
  89. }
  90. static int init_nec_8048_wvga_lcd(struct spi_device *spi)
  91. {
  92. unsigned int i;
  93. /* Initialization Sequence */
  94. /* nec_8048_spi_send(spi, REG, VAL) */
  95. for (i = 0; i < (ARRAY_SIZE(nec_8048_init_seq) - 1); i++)
  96. nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
  97. nec_8048_init_seq[i].dat);
  98. udelay(20);
  99. nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
  100. nec_8048_init_seq[i].dat);
  101. return 0;
  102. }
  103. static int nec_8048_connect(struct omap_dss_device *dssdev)
  104. {
  105. struct panel_drv_data *ddata = to_panel_data(dssdev);
  106. struct omap_dss_device *in = ddata->in;
  107. int r;
  108. if (omapdss_device_is_connected(dssdev))
  109. return 0;
  110. r = in->ops.dpi->connect(in, dssdev);
  111. if (r)
  112. return r;
  113. return 0;
  114. }
  115. static void nec_8048_disconnect(struct omap_dss_device *dssdev)
  116. {
  117. struct panel_drv_data *ddata = to_panel_data(dssdev);
  118. struct omap_dss_device *in = ddata->in;
  119. if (!omapdss_device_is_connected(dssdev))
  120. return;
  121. in->ops.dpi->disconnect(in, dssdev);
  122. }
  123. static int nec_8048_enable(struct omap_dss_device *dssdev)
  124. {
  125. struct panel_drv_data *ddata = to_panel_data(dssdev);
  126. struct omap_dss_device *in = ddata->in;
  127. int r;
  128. if (!omapdss_device_is_connected(dssdev))
  129. return -ENODEV;
  130. if (omapdss_device_is_enabled(dssdev))
  131. return 0;
  132. if (ddata->data_lines)
  133. in->ops.dpi->set_data_lines(in, ddata->data_lines);
  134. in->ops.dpi->set_timings(in, &ddata->videomode);
  135. r = in->ops.dpi->enable(in);
  136. if (r)
  137. return r;
  138. if (gpio_is_valid(ddata->res_gpio))
  139. gpio_set_value_cansleep(ddata->res_gpio, 1);
  140. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  141. return 0;
  142. }
  143. static void nec_8048_disable(struct omap_dss_device *dssdev)
  144. {
  145. struct panel_drv_data *ddata = to_panel_data(dssdev);
  146. struct omap_dss_device *in = ddata->in;
  147. if (!omapdss_device_is_enabled(dssdev))
  148. return;
  149. if (gpio_is_valid(ddata->res_gpio))
  150. gpio_set_value_cansleep(ddata->res_gpio, 0);
  151. in->ops.dpi->disable(in);
  152. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  153. }
  154. static void nec_8048_set_timings(struct omap_dss_device *dssdev,
  155. struct omap_video_timings *timings)
  156. {
  157. struct panel_drv_data *ddata = to_panel_data(dssdev);
  158. struct omap_dss_device *in = ddata->in;
  159. ddata->videomode = *timings;
  160. dssdev->panel.timings = *timings;
  161. in->ops.dpi->set_timings(in, timings);
  162. }
  163. static void nec_8048_get_timings(struct omap_dss_device *dssdev,
  164. struct omap_video_timings *timings)
  165. {
  166. struct panel_drv_data *ddata = to_panel_data(dssdev);
  167. *timings = ddata->videomode;
  168. }
  169. static int nec_8048_check_timings(struct omap_dss_device *dssdev,
  170. struct omap_video_timings *timings)
  171. {
  172. struct panel_drv_data *ddata = to_panel_data(dssdev);
  173. struct omap_dss_device *in = ddata->in;
  174. return in->ops.dpi->check_timings(in, timings);
  175. }
  176. static struct omap_dss_driver nec_8048_ops = {
  177. .connect = nec_8048_connect,
  178. .disconnect = nec_8048_disconnect,
  179. .enable = nec_8048_enable,
  180. .disable = nec_8048_disable,
  181. .set_timings = nec_8048_set_timings,
  182. .get_timings = nec_8048_get_timings,
  183. .check_timings = nec_8048_check_timings,
  184. .get_resolution = omapdss_default_get_resolution,
  185. };
  186. static int nec_8048_probe_pdata(struct spi_device *spi)
  187. {
  188. const struct panel_nec_nl8048hl11_platform_data *pdata;
  189. struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
  190. struct omap_dss_device *dssdev, *in;
  191. pdata = dev_get_platdata(&spi->dev);
  192. ddata->qvga_gpio = pdata->qvga_gpio;
  193. ddata->res_gpio = pdata->res_gpio;
  194. in = omap_dss_find_output(pdata->source);
  195. if (in == NULL) {
  196. dev_err(&spi->dev, "failed to find video source '%s'\n",
  197. pdata->source);
  198. return -EPROBE_DEFER;
  199. }
  200. ddata->in = in;
  201. ddata->data_lines = pdata->data_lines;
  202. dssdev = &ddata->dssdev;
  203. dssdev->name = pdata->name;
  204. return 0;
  205. }
  206. static int nec_8048_probe_of(struct spi_device *spi)
  207. {
  208. struct device_node *node = spi->dev.of_node;
  209. struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
  210. struct omap_dss_device *in;
  211. int gpio;
  212. gpio = of_get_named_gpio(node, "reset-gpios", 0);
  213. if (!gpio_is_valid(gpio)) {
  214. dev_err(&spi->dev, "failed to parse enable gpio\n");
  215. return gpio;
  216. }
  217. ddata->res_gpio = gpio;
  218. /* XXX the panel spec doesn't mention any QVGA pin?? */
  219. ddata->qvga_gpio = -ENOENT;
  220. in = omapdss_of_find_source_for_first_ep(node);
  221. if (IS_ERR(in)) {
  222. dev_err(&spi->dev, "failed to find video source\n");
  223. return PTR_ERR(in);
  224. }
  225. ddata->in = in;
  226. return 0;
  227. }
  228. static int nec_8048_probe(struct spi_device *spi)
  229. {
  230. struct panel_drv_data *ddata;
  231. struct omap_dss_device *dssdev;
  232. int r;
  233. dev_dbg(&spi->dev, "%s\n", __func__);
  234. spi->mode = SPI_MODE_0;
  235. spi->bits_per_word = 32;
  236. r = spi_setup(spi);
  237. if (r < 0) {
  238. dev_err(&spi->dev, "spi_setup failed: %d\n", r);
  239. return r;
  240. }
  241. init_nec_8048_wvga_lcd(spi);
  242. ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL);
  243. if (ddata == NULL)
  244. return -ENOMEM;
  245. dev_set_drvdata(&spi->dev, ddata);
  246. ddata->spi = spi;
  247. if (dev_get_platdata(&spi->dev)) {
  248. r = nec_8048_probe_pdata(spi);
  249. if (r)
  250. return r;
  251. } else if (spi->dev.of_node) {
  252. r = nec_8048_probe_of(spi);
  253. if (r)
  254. return r;
  255. } else {
  256. return -ENODEV;
  257. }
  258. if (gpio_is_valid(ddata->qvga_gpio)) {
  259. r = devm_gpio_request_one(&spi->dev, ddata->qvga_gpio,
  260. GPIOF_OUT_INIT_HIGH, "lcd QVGA");
  261. if (r)
  262. goto err_gpio;
  263. }
  264. if (gpio_is_valid(ddata->res_gpio)) {
  265. r = devm_gpio_request_one(&spi->dev, ddata->res_gpio,
  266. GPIOF_OUT_INIT_LOW, "lcd RES");
  267. if (r)
  268. goto err_gpio;
  269. }
  270. ddata->videomode = nec_8048_panel_timings;
  271. dssdev = &ddata->dssdev;
  272. dssdev->dev = &spi->dev;
  273. dssdev->driver = &nec_8048_ops;
  274. dssdev->type = OMAP_DISPLAY_TYPE_DPI;
  275. dssdev->owner = THIS_MODULE;
  276. dssdev->panel.timings = ddata->videomode;
  277. r = omapdss_register_display(dssdev);
  278. if (r) {
  279. dev_err(&spi->dev, "Failed to register panel\n");
  280. goto err_reg;
  281. }
  282. return 0;
  283. err_reg:
  284. err_gpio:
  285. omap_dss_put_device(ddata->in);
  286. return r;
  287. }
  288. static int nec_8048_remove(struct spi_device *spi)
  289. {
  290. struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
  291. struct omap_dss_device *dssdev = &ddata->dssdev;
  292. struct omap_dss_device *in = ddata->in;
  293. dev_dbg(&ddata->spi->dev, "%s\n", __func__);
  294. omapdss_unregister_display(dssdev);
  295. nec_8048_disable(dssdev);
  296. nec_8048_disconnect(dssdev);
  297. omap_dss_put_device(in);
  298. return 0;
  299. }
  300. #ifdef CONFIG_PM_SLEEP
  301. static int nec_8048_suspend(struct device *dev)
  302. {
  303. struct spi_device *spi = to_spi_device(dev);
  304. nec_8048_spi_send(spi, 2, 0x01);
  305. mdelay(40);
  306. return 0;
  307. }
  308. static int nec_8048_resume(struct device *dev)
  309. {
  310. struct spi_device *spi = to_spi_device(dev);
  311. /* reinitialize the panel */
  312. spi_setup(spi);
  313. nec_8048_spi_send(spi, 2, 0x00);
  314. init_nec_8048_wvga_lcd(spi);
  315. return 0;
  316. }
  317. static SIMPLE_DEV_PM_OPS(nec_8048_pm_ops, nec_8048_suspend,
  318. nec_8048_resume);
  319. #define NEC_8048_PM_OPS (&nec_8048_pm_ops)
  320. #else
  321. #define NEC_8048_PM_OPS NULL
  322. #endif
  323. static const struct of_device_id nec_8048_of_match[] = {
  324. { .compatible = "omapdss,nec,nl8048hl11", },
  325. {},
  326. };
  327. MODULE_DEVICE_TABLE(of, nec_8048_of_match);
  328. static struct spi_driver nec_8048_driver = {
  329. .driver = {
  330. .name = "panel-nec-nl8048hl11",
  331. .owner = THIS_MODULE,
  332. .pm = NEC_8048_PM_OPS,
  333. .of_match_table = nec_8048_of_match,
  334. .suppress_bind_attrs = true,
  335. },
  336. .probe = nec_8048_probe,
  337. .remove = nec_8048_remove,
  338. };
  339. module_spi_driver(nec_8048_driver);
  340. MODULE_ALIAS("spi:nec,nl8048hl11");
  341. MODULE_AUTHOR("Erik Gilling <konkers@android.com>");
  342. MODULE_DESCRIPTION("NEC-NL8048HL11 Driver");
  343. MODULE_LICENSE("GPL");