panel-nec-nl8048hl11.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. /*
  2. * NEC NL8048HL11 Panel driver
  3. *
  4. * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
  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/gpio/consumer.h>
  17. #include <linux/of_gpio.h>
  18. #include "../dss/omapdss.h"
  19. struct panel_drv_data {
  20. struct omap_dss_device dssdev;
  21. struct omap_dss_device *in;
  22. struct videomode vm;
  23. int res_gpio;
  24. int qvga_gpio;
  25. struct spi_device *spi;
  26. };
  27. #define LCD_XRES 800
  28. #define LCD_YRES 480
  29. /*
  30. * NEC PIX Clock Ratings
  31. * MIN:21.8MHz TYP:23.8MHz MAX:25.7MHz
  32. */
  33. #define LCD_PIXEL_CLOCK 23800000
  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. static const struct videomode nec_8048_panel_vm = {
  58. .hactive = LCD_XRES,
  59. .vactive = LCD_YRES,
  60. .pixelclock = LCD_PIXEL_CLOCK,
  61. .hfront_porch = 6,
  62. .hsync_len = 1,
  63. .hback_porch = 4,
  64. .vfront_porch = 3,
  65. .vsync_len = 1,
  66. .vback_porch = 4,
  67. .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW |
  68. DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_SYNC_POSEDGE |
  69. DISPLAY_FLAGS_PIXDATA_POSEDGE,
  70. };
  71. #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
  72. static int nec_8048_spi_send(struct spi_device *spi, unsigned char reg_addr,
  73. unsigned char reg_data)
  74. {
  75. int ret = 0;
  76. unsigned int cmd = 0, data = 0;
  77. cmd = 0x0000 | reg_addr; /* register address write */
  78. data = 0x0100 | reg_data; /* register data write */
  79. data = (cmd << 16) | data;
  80. ret = spi_write(spi, (unsigned char *)&data, 4);
  81. if (ret)
  82. pr_err("error in spi_write %x\n", data);
  83. return ret;
  84. }
  85. static int init_nec_8048_wvga_lcd(struct spi_device *spi)
  86. {
  87. unsigned int i;
  88. /* Initialization Sequence */
  89. /* nec_8048_spi_send(spi, REG, VAL) */
  90. for (i = 0; i < (ARRAY_SIZE(nec_8048_init_seq) - 1); i++)
  91. nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
  92. nec_8048_init_seq[i].dat);
  93. udelay(20);
  94. nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
  95. nec_8048_init_seq[i].dat);
  96. return 0;
  97. }
  98. static int nec_8048_connect(struct omap_dss_device *dssdev)
  99. {
  100. struct panel_drv_data *ddata = to_panel_data(dssdev);
  101. struct omap_dss_device *in;
  102. int r;
  103. if (omapdss_device_is_connected(dssdev))
  104. return 0;
  105. in = omapdss_of_find_source_for_first_ep(dssdev->dev->of_node);
  106. if (IS_ERR(in)) {
  107. dev_err(dssdev->dev, "failed to find video source\n");
  108. return PTR_ERR(in);
  109. }
  110. r = in->ops.dpi->connect(in, dssdev);
  111. if (r) {
  112. omap_dss_put_device(in);
  113. return r;
  114. }
  115. ddata->in = in;
  116. return 0;
  117. }
  118. static void nec_8048_disconnect(struct omap_dss_device *dssdev)
  119. {
  120. struct panel_drv_data *ddata = to_panel_data(dssdev);
  121. struct omap_dss_device *in = ddata->in;
  122. if (!omapdss_device_is_connected(dssdev))
  123. return;
  124. in->ops.dpi->disconnect(in, dssdev);
  125. omap_dss_put_device(in);
  126. ddata->in = NULL;
  127. }
  128. static int nec_8048_enable(struct omap_dss_device *dssdev)
  129. {
  130. struct panel_drv_data *ddata = to_panel_data(dssdev);
  131. struct omap_dss_device *in = ddata->in;
  132. int r;
  133. if (!omapdss_device_is_connected(dssdev))
  134. return -ENODEV;
  135. if (omapdss_device_is_enabled(dssdev))
  136. return 0;
  137. in->ops.dpi->set_timings(in, &ddata->vm);
  138. r = in->ops.dpi->enable(in);
  139. if (r)
  140. return r;
  141. if (gpio_is_valid(ddata->res_gpio))
  142. gpio_set_value_cansleep(ddata->res_gpio, 1);
  143. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  144. return 0;
  145. }
  146. static void nec_8048_disable(struct omap_dss_device *dssdev)
  147. {
  148. struct panel_drv_data *ddata = to_panel_data(dssdev);
  149. struct omap_dss_device *in = ddata->in;
  150. if (!omapdss_device_is_enabled(dssdev))
  151. return;
  152. if (gpio_is_valid(ddata->res_gpio))
  153. gpio_set_value_cansleep(ddata->res_gpio, 0);
  154. in->ops.dpi->disable(in);
  155. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  156. }
  157. static void nec_8048_set_timings(struct omap_dss_device *dssdev,
  158. struct videomode *vm)
  159. {
  160. struct panel_drv_data *ddata = to_panel_data(dssdev);
  161. struct omap_dss_device *in = ddata->in;
  162. ddata->vm = *vm;
  163. dssdev->panel.vm = *vm;
  164. in->ops.dpi->set_timings(in, vm);
  165. }
  166. static void nec_8048_get_timings(struct omap_dss_device *dssdev,
  167. struct videomode *vm)
  168. {
  169. struct panel_drv_data *ddata = to_panel_data(dssdev);
  170. *vm = ddata->vm;
  171. }
  172. static int nec_8048_check_timings(struct omap_dss_device *dssdev,
  173. struct videomode *vm)
  174. {
  175. struct panel_drv_data *ddata = to_panel_data(dssdev);
  176. struct omap_dss_device *in = ddata->in;
  177. return in->ops.dpi->check_timings(in, vm);
  178. }
  179. static struct omap_dss_driver nec_8048_ops = {
  180. .connect = nec_8048_connect,
  181. .disconnect = nec_8048_disconnect,
  182. .enable = nec_8048_enable,
  183. .disable = nec_8048_disable,
  184. .set_timings = nec_8048_set_timings,
  185. .get_timings = nec_8048_get_timings,
  186. .check_timings = nec_8048_check_timings,
  187. };
  188. static int nec_8048_probe_of(struct spi_device *spi)
  189. {
  190. struct device_node *node = spi->dev.of_node;
  191. struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
  192. int gpio;
  193. gpio = of_get_named_gpio(node, "reset-gpios", 0);
  194. if (!gpio_is_valid(gpio)) {
  195. dev_err(&spi->dev, "failed to parse enable gpio\n");
  196. return gpio;
  197. }
  198. ddata->res_gpio = gpio;
  199. /* XXX the panel spec doesn't mention any QVGA pin?? */
  200. ddata->qvga_gpio = -ENOENT;
  201. return 0;
  202. }
  203. static int nec_8048_probe(struct spi_device *spi)
  204. {
  205. struct panel_drv_data *ddata;
  206. struct omap_dss_device *dssdev;
  207. int r;
  208. dev_dbg(&spi->dev, "%s\n", __func__);
  209. spi->mode = SPI_MODE_0;
  210. spi->bits_per_word = 32;
  211. r = spi_setup(spi);
  212. if (r < 0) {
  213. dev_err(&spi->dev, "spi_setup failed: %d\n", r);
  214. return r;
  215. }
  216. init_nec_8048_wvga_lcd(spi);
  217. ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL);
  218. if (ddata == NULL)
  219. return -ENOMEM;
  220. dev_set_drvdata(&spi->dev, ddata);
  221. ddata->spi = spi;
  222. r = nec_8048_probe_of(spi);
  223. if (r)
  224. return r;
  225. if (gpio_is_valid(ddata->qvga_gpio)) {
  226. r = devm_gpio_request_one(&spi->dev, ddata->qvga_gpio,
  227. GPIOF_OUT_INIT_HIGH, "lcd QVGA");
  228. if (r)
  229. return r;
  230. }
  231. if (gpio_is_valid(ddata->res_gpio)) {
  232. r = devm_gpio_request_one(&spi->dev, ddata->res_gpio,
  233. GPIOF_OUT_INIT_LOW, "lcd RES");
  234. if (r)
  235. return r;
  236. }
  237. ddata->vm = nec_8048_panel_vm;
  238. dssdev = &ddata->dssdev;
  239. dssdev->dev = &spi->dev;
  240. dssdev->driver = &nec_8048_ops;
  241. dssdev->type = OMAP_DISPLAY_TYPE_DPI;
  242. dssdev->owner = THIS_MODULE;
  243. dssdev->panel.vm = ddata->vm;
  244. r = omapdss_register_display(dssdev);
  245. if (r) {
  246. dev_err(&spi->dev, "Failed to register panel\n");
  247. return r;
  248. }
  249. return 0;
  250. }
  251. static int nec_8048_remove(struct spi_device *spi)
  252. {
  253. struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
  254. struct omap_dss_device *dssdev = &ddata->dssdev;
  255. dev_dbg(&ddata->spi->dev, "%s\n", __func__);
  256. omapdss_unregister_display(dssdev);
  257. nec_8048_disable(dssdev);
  258. nec_8048_disconnect(dssdev);
  259. return 0;
  260. }
  261. #ifdef CONFIG_PM_SLEEP
  262. static int nec_8048_suspend(struct device *dev)
  263. {
  264. struct spi_device *spi = to_spi_device(dev);
  265. nec_8048_spi_send(spi, 2, 0x01);
  266. mdelay(40);
  267. return 0;
  268. }
  269. static int nec_8048_resume(struct device *dev)
  270. {
  271. struct spi_device *spi = to_spi_device(dev);
  272. /* reinitialize the panel */
  273. spi_setup(spi);
  274. nec_8048_spi_send(spi, 2, 0x00);
  275. init_nec_8048_wvga_lcd(spi);
  276. return 0;
  277. }
  278. static SIMPLE_DEV_PM_OPS(nec_8048_pm_ops, nec_8048_suspend,
  279. nec_8048_resume);
  280. #define NEC_8048_PM_OPS (&nec_8048_pm_ops)
  281. #else
  282. #define NEC_8048_PM_OPS NULL
  283. #endif
  284. static const struct of_device_id nec_8048_of_match[] = {
  285. { .compatible = "omapdss,nec,nl8048hl11", },
  286. {},
  287. };
  288. MODULE_DEVICE_TABLE(of, nec_8048_of_match);
  289. static struct spi_driver nec_8048_driver = {
  290. .driver = {
  291. .name = "panel-nec-nl8048hl11",
  292. .pm = NEC_8048_PM_OPS,
  293. .of_match_table = nec_8048_of_match,
  294. .suppress_bind_attrs = true,
  295. },
  296. .probe = nec_8048_probe,
  297. .remove = nec_8048_remove,
  298. };
  299. module_spi_driver(nec_8048_driver);
  300. MODULE_ALIAS("spi:nec,nl8048hl11");
  301. MODULE_AUTHOR("Erik Gilling <konkers@android.com>");
  302. MODULE_DESCRIPTION("NEC-NL8048HL11 Driver");
  303. MODULE_LICENSE("GPL");