panel-sharp-ls037v7dw01.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Sharp LS037V7DW01 LCD Panel Driver
  4. *
  5. * Copyright (C) 2019 Texas Instruments Incorporated
  6. *
  7. * Based on the omapdrm-specific panel-sharp-ls037v7dw01 driver
  8. *
  9. * Copyright (C) 2013 Texas Instruments Incorporated
  10. * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
  11. */
  12. #include <linux/delay.h>
  13. #include <linux/gpio/consumer.h>
  14. #include <linux/module.h>
  15. #include <linux/of.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/regulator/consumer.h>
  18. #include <drm/drm_connector.h>
  19. #include <drm/drm_modes.h>
  20. #include <drm/drm_panel.h>
  21. struct ls037v7dw01_panel {
  22. struct drm_panel panel;
  23. struct platform_device *pdev;
  24. struct regulator *vdd;
  25. struct gpio_desc *resb_gpio; /* low = reset active min 20 us */
  26. struct gpio_desc *ini_gpio; /* high = power on */
  27. struct gpio_desc *mo_gpio; /* low = 480x640, high = 240x320 */
  28. struct gpio_desc *lr_gpio; /* high = conventional horizontal scanning */
  29. struct gpio_desc *ud_gpio; /* high = conventional vertical scanning */
  30. };
  31. #define to_ls037v7dw01_device(p) \
  32. container_of(p, struct ls037v7dw01_panel, panel)
  33. static int ls037v7dw01_disable(struct drm_panel *panel)
  34. {
  35. struct ls037v7dw01_panel *lcd = to_ls037v7dw01_device(panel);
  36. gpiod_set_value_cansleep(lcd->ini_gpio, 0);
  37. gpiod_set_value_cansleep(lcd->resb_gpio, 0);
  38. /* Wait at least 5 vsyncs after disabling the LCD. */
  39. msleep(100);
  40. return 0;
  41. }
  42. static int ls037v7dw01_unprepare(struct drm_panel *panel)
  43. {
  44. struct ls037v7dw01_panel *lcd = to_ls037v7dw01_device(panel);
  45. regulator_disable(lcd->vdd);
  46. return 0;
  47. }
  48. static int ls037v7dw01_prepare(struct drm_panel *panel)
  49. {
  50. struct ls037v7dw01_panel *lcd = to_ls037v7dw01_device(panel);
  51. int ret;
  52. ret = regulator_enable(lcd->vdd);
  53. if (ret < 0)
  54. dev_err(&lcd->pdev->dev, "%s: failed to enable regulator\n",
  55. __func__);
  56. return ret;
  57. }
  58. static int ls037v7dw01_enable(struct drm_panel *panel)
  59. {
  60. struct ls037v7dw01_panel *lcd = to_ls037v7dw01_device(panel);
  61. /* Wait couple of vsyncs before enabling the LCD. */
  62. msleep(50);
  63. gpiod_set_value_cansleep(lcd->resb_gpio, 1);
  64. gpiod_set_value_cansleep(lcd->ini_gpio, 1);
  65. return 0;
  66. }
  67. static const struct drm_display_mode ls037v7dw01_mode = {
  68. .clock = 19200,
  69. .hdisplay = 480,
  70. .hsync_start = 480 + 1,
  71. .hsync_end = 480 + 1 + 2,
  72. .htotal = 480 + 1 + 2 + 28,
  73. .vdisplay = 640,
  74. .vsync_start = 640 + 1,
  75. .vsync_end = 640 + 1 + 1,
  76. .vtotal = 640 + 1 + 1 + 1,
  77. .type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED,
  78. .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
  79. .width_mm = 56,
  80. .height_mm = 75,
  81. };
  82. static int ls037v7dw01_get_modes(struct drm_panel *panel,
  83. struct drm_connector *connector)
  84. {
  85. struct drm_display_mode *mode;
  86. mode = drm_mode_duplicate(connector->dev, &ls037v7dw01_mode);
  87. if (!mode)
  88. return -ENOMEM;
  89. drm_mode_set_name(mode);
  90. drm_mode_probed_add(connector, mode);
  91. connector->display_info.width_mm = ls037v7dw01_mode.width_mm;
  92. connector->display_info.height_mm = ls037v7dw01_mode.height_mm;
  93. /*
  94. * FIXME: According to the datasheet pixel data is sampled on the
  95. * rising edge of the clock, but the code running on the SDP3430
  96. * indicates sampling on the negative edge. This should be tested on a
  97. * real device.
  98. */
  99. connector->display_info.bus_flags = DRM_BUS_FLAG_DE_HIGH
  100. | DRM_BUS_FLAG_SYNC_SAMPLE_POSEDGE
  101. | DRM_BUS_FLAG_PIXDATA_SAMPLE_NEGEDGE;
  102. return 1;
  103. }
  104. static const struct drm_panel_funcs ls037v7dw01_funcs = {
  105. .disable = ls037v7dw01_disable,
  106. .unprepare = ls037v7dw01_unprepare,
  107. .prepare = ls037v7dw01_prepare,
  108. .enable = ls037v7dw01_enable,
  109. .get_modes = ls037v7dw01_get_modes,
  110. };
  111. static int ls037v7dw01_probe(struct platform_device *pdev)
  112. {
  113. struct ls037v7dw01_panel *lcd;
  114. lcd = devm_kzalloc(&pdev->dev, sizeof(*lcd), GFP_KERNEL);
  115. if (!lcd)
  116. return -ENOMEM;
  117. platform_set_drvdata(pdev, lcd);
  118. lcd->pdev = pdev;
  119. lcd->vdd = devm_regulator_get(&pdev->dev, "envdd");
  120. if (IS_ERR(lcd->vdd)) {
  121. dev_err(&pdev->dev, "failed to get regulator\n");
  122. return PTR_ERR(lcd->vdd);
  123. }
  124. lcd->ini_gpio = devm_gpiod_get(&pdev->dev, "enable", GPIOD_OUT_LOW);
  125. if (IS_ERR(lcd->ini_gpio)) {
  126. dev_err(&pdev->dev, "failed to get enable gpio\n");
  127. return PTR_ERR(lcd->ini_gpio);
  128. }
  129. lcd->resb_gpio = devm_gpiod_get(&pdev->dev, "reset", GPIOD_OUT_LOW);
  130. if (IS_ERR(lcd->resb_gpio)) {
  131. dev_err(&pdev->dev, "failed to get reset gpio\n");
  132. return PTR_ERR(lcd->resb_gpio);
  133. }
  134. lcd->mo_gpio = devm_gpiod_get_index(&pdev->dev, "mode", 0,
  135. GPIOD_OUT_LOW);
  136. if (IS_ERR(lcd->mo_gpio)) {
  137. dev_err(&pdev->dev, "failed to get mode[0] gpio\n");
  138. return PTR_ERR(lcd->mo_gpio);
  139. }
  140. lcd->lr_gpio = devm_gpiod_get_index(&pdev->dev, "mode", 1,
  141. GPIOD_OUT_LOW);
  142. if (IS_ERR(lcd->lr_gpio)) {
  143. dev_err(&pdev->dev, "failed to get mode[1] gpio\n");
  144. return PTR_ERR(lcd->lr_gpio);
  145. }
  146. lcd->ud_gpio = devm_gpiod_get_index(&pdev->dev, "mode", 2,
  147. GPIOD_OUT_LOW);
  148. if (IS_ERR(lcd->ud_gpio)) {
  149. dev_err(&pdev->dev, "failed to get mode[2] gpio\n");
  150. return PTR_ERR(lcd->ud_gpio);
  151. }
  152. drm_panel_init(&lcd->panel, &pdev->dev, &ls037v7dw01_funcs,
  153. DRM_MODE_CONNECTOR_DPI);
  154. drm_panel_add(&lcd->panel);
  155. return 0;
  156. }
  157. static int ls037v7dw01_remove(struct platform_device *pdev)
  158. {
  159. struct ls037v7dw01_panel *lcd = platform_get_drvdata(pdev);
  160. drm_panel_remove(&lcd->panel);
  161. drm_panel_disable(&lcd->panel);
  162. drm_panel_unprepare(&lcd->panel);
  163. return 0;
  164. }
  165. static const struct of_device_id ls037v7dw01_of_match[] = {
  166. { .compatible = "sharp,ls037v7dw01", },
  167. { /* sentinel */ },
  168. };
  169. MODULE_DEVICE_TABLE(of, ls037v7dw01_of_match);
  170. static struct platform_driver ls037v7dw01_driver = {
  171. .probe = ls037v7dw01_probe,
  172. .remove = ls037v7dw01_remove,
  173. .driver = {
  174. .name = "panel-sharp-ls037v7dw01",
  175. .of_match_table = ls037v7dw01_of_match,
  176. },
  177. };
  178. module_platform_driver(ls037v7dw01_driver);
  179. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
  180. MODULE_DESCRIPTION("Sharp LS037V7DW01 Panel Driver");
  181. MODULE_LICENSE("GPL");