panel-nec-nl8048hl11.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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/delay.h>
  14. #include <linux/gpio/consumer.h>
  15. #include <linux/module.h>
  16. #include <linux/spi/spi.h>
  17. #include "../dss/omapdss.h"
  18. struct panel_drv_data {
  19. struct omap_dss_device dssdev;
  20. struct videomode vm;
  21. struct gpio_desc *res_gpio;
  22. struct spi_device *spi;
  23. };
  24. #define LCD_XRES 800
  25. #define LCD_YRES 480
  26. /*
  27. * NEC PIX Clock Ratings
  28. * MIN:21.8MHz TYP:23.8MHz MAX:25.7MHz
  29. */
  30. #define LCD_PIXEL_CLOCK 23800000
  31. static const struct {
  32. unsigned char addr;
  33. unsigned char dat;
  34. } nec_8048_init_seq[] = {
  35. { 3, 0x01 }, { 0, 0x00 }, { 1, 0x01 }, { 4, 0x00 }, { 5, 0x14 },
  36. { 6, 0x24 }, { 16, 0xD7 }, { 17, 0x00 }, { 18, 0x00 }, { 19, 0x55 },
  37. { 20, 0x01 }, { 21, 0x70 }, { 22, 0x1E }, { 23, 0x25 }, { 24, 0x25 },
  38. { 25, 0x02 }, { 26, 0x02 }, { 27, 0xA0 }, { 32, 0x2F }, { 33, 0x0F },
  39. { 34, 0x0F }, { 35, 0x0F }, { 36, 0x0F }, { 37, 0x0F }, { 38, 0x0F },
  40. { 39, 0x00 }, { 40, 0x02 }, { 41, 0x02 }, { 42, 0x02 }, { 43, 0x0F },
  41. { 44, 0x0F }, { 45, 0x0F }, { 46, 0x0F }, { 47, 0x0F }, { 48, 0x0F },
  42. { 49, 0x0F }, { 50, 0x00 }, { 51, 0x02 }, { 52, 0x02 }, { 53, 0x02 },
  43. { 80, 0x0C }, { 83, 0x42 }, { 84, 0x42 }, { 85, 0x41 }, { 86, 0x14 },
  44. { 89, 0x88 }, { 90, 0x01 }, { 91, 0x00 }, { 92, 0x02 }, { 93, 0x0C },
  45. { 94, 0x1C }, { 95, 0x27 }, { 98, 0x49 }, { 99, 0x27 }, { 102, 0x76 },
  46. { 103, 0x27 }, { 112, 0x01 }, { 113, 0x0E }, { 114, 0x02 },
  47. { 115, 0x0C }, { 118, 0x0C }, { 121, 0x30 }, { 130, 0x00 },
  48. { 131, 0x00 }, { 132, 0xFC }, { 134, 0x00 }, { 136, 0x00 },
  49. { 138, 0x00 }, { 139, 0x00 }, { 140, 0x00 }, { 141, 0xFC },
  50. { 143, 0x00 }, { 145, 0x00 }, { 147, 0x00 }, { 148, 0x00 },
  51. { 149, 0x00 }, { 150, 0xFC }, { 152, 0x00 }, { 154, 0x00 },
  52. { 156, 0x00 }, { 157, 0x00 }, { 2, 0x00 },
  53. };
  54. static const struct videomode nec_8048_panel_vm = {
  55. .hactive = LCD_XRES,
  56. .vactive = LCD_YRES,
  57. .pixelclock = LCD_PIXEL_CLOCK,
  58. .hfront_porch = 6,
  59. .hsync_len = 1,
  60. .hback_porch = 4,
  61. .vfront_porch = 3,
  62. .vsync_len = 1,
  63. .vback_porch = 4,
  64. .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW,
  65. };
  66. #define to_panel_data(p) container_of(p, struct panel_drv_data, dssdev)
  67. static int nec_8048_spi_send(struct spi_device *spi, unsigned char reg_addr,
  68. unsigned char reg_data)
  69. {
  70. int ret = 0;
  71. unsigned int cmd = 0, data = 0;
  72. cmd = 0x0000 | reg_addr; /* register address write */
  73. data = 0x0100 | reg_data; /* register data write */
  74. data = (cmd << 16) | data;
  75. ret = spi_write(spi, (unsigned char *)&data, 4);
  76. if (ret)
  77. pr_err("error in spi_write %x\n", data);
  78. return ret;
  79. }
  80. static int init_nec_8048_wvga_lcd(struct spi_device *spi)
  81. {
  82. unsigned int i;
  83. /* Initialization Sequence */
  84. /* nec_8048_spi_send(spi, REG, VAL) */
  85. for (i = 0; i < (ARRAY_SIZE(nec_8048_init_seq) - 1); i++)
  86. nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
  87. nec_8048_init_seq[i].dat);
  88. udelay(20);
  89. nec_8048_spi_send(spi, nec_8048_init_seq[i].addr,
  90. nec_8048_init_seq[i].dat);
  91. return 0;
  92. }
  93. static int nec_8048_connect(struct omap_dss_device *src,
  94. struct omap_dss_device *dst)
  95. {
  96. return 0;
  97. }
  98. static void nec_8048_disconnect(struct omap_dss_device *src,
  99. struct omap_dss_device *dst)
  100. {
  101. }
  102. static int nec_8048_enable(struct omap_dss_device *dssdev)
  103. {
  104. struct panel_drv_data *ddata = to_panel_data(dssdev);
  105. struct omap_dss_device *src = dssdev->src;
  106. int r;
  107. if (!omapdss_device_is_connected(dssdev))
  108. return -ENODEV;
  109. if (omapdss_device_is_enabled(dssdev))
  110. return 0;
  111. r = src->ops->enable(src);
  112. if (r)
  113. return r;
  114. gpiod_set_value_cansleep(ddata->res_gpio, 1);
  115. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  116. return 0;
  117. }
  118. static void nec_8048_disable(struct omap_dss_device *dssdev)
  119. {
  120. struct panel_drv_data *ddata = to_panel_data(dssdev);
  121. struct omap_dss_device *src = dssdev->src;
  122. if (!omapdss_device_is_enabled(dssdev))
  123. return;
  124. gpiod_set_value_cansleep(ddata->res_gpio, 0);
  125. src->ops->disable(src);
  126. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  127. }
  128. static void nec_8048_get_timings(struct omap_dss_device *dssdev,
  129. struct videomode *vm)
  130. {
  131. struct panel_drv_data *ddata = to_panel_data(dssdev);
  132. *vm = ddata->vm;
  133. }
  134. static const struct omap_dss_device_ops nec_8048_ops = {
  135. .connect = nec_8048_connect,
  136. .disconnect = nec_8048_disconnect,
  137. .enable = nec_8048_enable,
  138. .disable = nec_8048_disable,
  139. .get_timings = nec_8048_get_timings,
  140. };
  141. static int nec_8048_probe(struct spi_device *spi)
  142. {
  143. struct panel_drv_data *ddata;
  144. struct omap_dss_device *dssdev;
  145. struct gpio_desc *gpio;
  146. int r;
  147. dev_dbg(&spi->dev, "%s\n", __func__);
  148. spi->mode = SPI_MODE_0;
  149. spi->bits_per_word = 32;
  150. r = spi_setup(spi);
  151. if (r < 0) {
  152. dev_err(&spi->dev, "spi_setup failed: %d\n", r);
  153. return r;
  154. }
  155. init_nec_8048_wvga_lcd(spi);
  156. ddata = devm_kzalloc(&spi->dev, sizeof(*ddata), GFP_KERNEL);
  157. if (ddata == NULL)
  158. return -ENOMEM;
  159. dev_set_drvdata(&spi->dev, ddata);
  160. ddata->spi = spi;
  161. gpio = devm_gpiod_get(&spi->dev, "reset", GPIOD_OUT_LOW);
  162. if (IS_ERR(gpio)) {
  163. dev_err(&spi->dev, "failed to get reset gpio\n");
  164. return PTR_ERR(gpio);
  165. }
  166. ddata->res_gpio = gpio;
  167. ddata->vm = nec_8048_panel_vm;
  168. dssdev = &ddata->dssdev;
  169. dssdev->dev = &spi->dev;
  170. dssdev->ops = &nec_8048_ops;
  171. dssdev->type = OMAP_DISPLAY_TYPE_DPI;
  172. dssdev->owner = THIS_MODULE;
  173. dssdev->of_ports = BIT(0);
  174. dssdev->bus_flags = DRM_BUS_FLAG_DE_HIGH | DRM_BUS_FLAG_SYNC_POSEDGE
  175. | DRM_BUS_FLAG_PIXDATA_POSEDGE;
  176. omapdss_display_init(dssdev);
  177. omapdss_device_register(dssdev);
  178. return 0;
  179. }
  180. static int nec_8048_remove(struct spi_device *spi)
  181. {
  182. struct panel_drv_data *ddata = dev_get_drvdata(&spi->dev);
  183. struct omap_dss_device *dssdev = &ddata->dssdev;
  184. dev_dbg(&ddata->spi->dev, "%s\n", __func__);
  185. omapdss_device_unregister(dssdev);
  186. nec_8048_disable(dssdev);
  187. return 0;
  188. }
  189. #ifdef CONFIG_PM_SLEEP
  190. static int nec_8048_suspend(struct device *dev)
  191. {
  192. struct spi_device *spi = to_spi_device(dev);
  193. nec_8048_spi_send(spi, 2, 0x01);
  194. mdelay(40);
  195. return 0;
  196. }
  197. static int nec_8048_resume(struct device *dev)
  198. {
  199. struct spi_device *spi = to_spi_device(dev);
  200. /* reinitialize the panel */
  201. spi_setup(spi);
  202. nec_8048_spi_send(spi, 2, 0x00);
  203. init_nec_8048_wvga_lcd(spi);
  204. return 0;
  205. }
  206. static SIMPLE_DEV_PM_OPS(nec_8048_pm_ops, nec_8048_suspend,
  207. nec_8048_resume);
  208. #define NEC_8048_PM_OPS (&nec_8048_pm_ops)
  209. #else
  210. #define NEC_8048_PM_OPS NULL
  211. #endif
  212. static const struct of_device_id nec_8048_of_match[] = {
  213. { .compatible = "omapdss,nec,nl8048hl11", },
  214. {},
  215. };
  216. MODULE_DEVICE_TABLE(of, nec_8048_of_match);
  217. static struct spi_driver nec_8048_driver = {
  218. .driver = {
  219. .name = "panel-nec-nl8048hl11",
  220. .pm = NEC_8048_PM_OPS,
  221. .of_match_table = nec_8048_of_match,
  222. .suppress_bind_attrs = true,
  223. },
  224. .probe = nec_8048_probe,
  225. .remove = nec_8048_remove,
  226. };
  227. module_spi_driver(nec_8048_driver);
  228. MODULE_ALIAS("spi:nec,nl8048hl11");
  229. MODULE_AUTHOR("Erik Gilling <konkers@android.com>");
  230. MODULE_DESCRIPTION("NEC-NL8048HL11 Driver");
  231. MODULE_LICENSE("GPL");