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