panel-nec-nl8048hl11.c 9.4 KB

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