panel-panasonic-vvx10f034n00.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2015 Red Hat
  4. * Copyright (C) 2015 Sony Mobile Communications Inc.
  5. * Author: Werner Johansson <werner.johansson@sonymobile.com>
  6. *
  7. * Based on AUO panel driver by Rob Clark <robdclark@gmail.com>
  8. */
  9. #include <linux/delay.h>
  10. #include <linux/module.h>
  11. #include <linux/of.h>
  12. #include <linux/regulator/consumer.h>
  13. #include <video/mipi_display.h>
  14. #include <drm/drm_crtc.h>
  15. #include <drm/drm_device.h>
  16. #include <drm/drm_mipi_dsi.h>
  17. #include <drm/drm_panel.h>
  18. /*
  19. * When power is turned off to this panel a minimum off time of 500ms has to be
  20. * observed before powering back on as there's no external reset pin. Keep
  21. * track of earliest wakeup time and delay subsequent prepare call accordingly
  22. */
  23. #define MIN_POFF_MS (500)
  24. struct wuxga_nt_panel {
  25. struct drm_panel base;
  26. struct mipi_dsi_device *dsi;
  27. struct regulator *supply;
  28. ktime_t earliest_wake;
  29. const struct drm_display_mode *mode;
  30. };
  31. static inline struct wuxga_nt_panel *to_wuxga_nt_panel(struct drm_panel *panel)
  32. {
  33. return container_of(panel, struct wuxga_nt_panel, base);
  34. }
  35. static int wuxga_nt_panel_on(struct wuxga_nt_panel *wuxga_nt)
  36. {
  37. return mipi_dsi_turn_on_peripheral(wuxga_nt->dsi);
  38. }
  39. static int wuxga_nt_panel_disable(struct drm_panel *panel)
  40. {
  41. struct wuxga_nt_panel *wuxga_nt = to_wuxga_nt_panel(panel);
  42. return mipi_dsi_shutdown_peripheral(wuxga_nt->dsi);
  43. }
  44. static int wuxga_nt_panel_unprepare(struct drm_panel *panel)
  45. {
  46. struct wuxga_nt_panel *wuxga_nt = to_wuxga_nt_panel(panel);
  47. regulator_disable(wuxga_nt->supply);
  48. wuxga_nt->earliest_wake = ktime_add_ms(ktime_get_real(), MIN_POFF_MS);
  49. return 0;
  50. }
  51. static int wuxga_nt_panel_prepare(struct drm_panel *panel)
  52. {
  53. struct wuxga_nt_panel *wuxga_nt = to_wuxga_nt_panel(panel);
  54. int ret;
  55. s64 enablewait;
  56. /*
  57. * If the user re-enabled the panel before the required off-time then
  58. * we need to wait the remaining period before re-enabling regulator
  59. */
  60. enablewait = ktime_ms_delta(wuxga_nt->earliest_wake, ktime_get_real());
  61. /* Sanity check, this should never happen */
  62. if (enablewait > MIN_POFF_MS)
  63. enablewait = MIN_POFF_MS;
  64. if (enablewait > 0)
  65. msleep(enablewait);
  66. ret = regulator_enable(wuxga_nt->supply);
  67. if (ret < 0)
  68. return ret;
  69. /*
  70. * A minimum delay of 250ms is required after power-up until commands
  71. * can be sent
  72. */
  73. msleep(250);
  74. ret = wuxga_nt_panel_on(wuxga_nt);
  75. if (ret < 0) {
  76. dev_err(panel->dev, "failed to set panel on: %d\n", ret);
  77. goto poweroff;
  78. }
  79. return 0;
  80. poweroff:
  81. regulator_disable(wuxga_nt->supply);
  82. return ret;
  83. }
  84. static const struct drm_display_mode default_mode = {
  85. .clock = 164402,
  86. .hdisplay = 1920,
  87. .hsync_start = 1920 + 152,
  88. .hsync_end = 1920 + 152 + 52,
  89. .htotal = 1920 + 152 + 52 + 20,
  90. .vdisplay = 1200,
  91. .vsync_start = 1200 + 24,
  92. .vsync_end = 1200 + 24 + 6,
  93. .vtotal = 1200 + 24 + 6 + 48,
  94. };
  95. static int wuxga_nt_panel_get_modes(struct drm_panel *panel,
  96. struct drm_connector *connector)
  97. {
  98. struct drm_display_mode *mode;
  99. mode = drm_mode_duplicate(connector->dev, &default_mode);
  100. if (!mode) {
  101. dev_err(panel->dev, "failed to add mode %ux%u@%u\n",
  102. default_mode.hdisplay, default_mode.vdisplay,
  103. drm_mode_vrefresh(&default_mode));
  104. return -ENOMEM;
  105. }
  106. drm_mode_set_name(mode);
  107. drm_mode_probed_add(connector, mode);
  108. connector->display_info.width_mm = 217;
  109. connector->display_info.height_mm = 136;
  110. return 1;
  111. }
  112. static const struct drm_panel_funcs wuxga_nt_panel_funcs = {
  113. .disable = wuxga_nt_panel_disable,
  114. .unprepare = wuxga_nt_panel_unprepare,
  115. .prepare = wuxga_nt_panel_prepare,
  116. .get_modes = wuxga_nt_panel_get_modes,
  117. };
  118. static const struct of_device_id wuxga_nt_of_match[] = {
  119. { .compatible = "panasonic,vvx10f034n00", },
  120. { }
  121. };
  122. MODULE_DEVICE_TABLE(of, wuxga_nt_of_match);
  123. static int wuxga_nt_panel_add(struct wuxga_nt_panel *wuxga_nt)
  124. {
  125. struct device *dev = &wuxga_nt->dsi->dev;
  126. int ret;
  127. wuxga_nt->mode = &default_mode;
  128. wuxga_nt->supply = devm_regulator_get(dev, "power");
  129. if (IS_ERR(wuxga_nt->supply))
  130. return PTR_ERR(wuxga_nt->supply);
  131. drm_panel_init(&wuxga_nt->base, &wuxga_nt->dsi->dev,
  132. &wuxga_nt_panel_funcs, DRM_MODE_CONNECTOR_DSI);
  133. ret = drm_panel_of_backlight(&wuxga_nt->base);
  134. if (ret)
  135. return ret;
  136. drm_panel_add(&wuxga_nt->base);
  137. return 0;
  138. }
  139. static void wuxga_nt_panel_del(struct wuxga_nt_panel *wuxga_nt)
  140. {
  141. if (wuxga_nt->base.dev)
  142. drm_panel_remove(&wuxga_nt->base);
  143. }
  144. static int wuxga_nt_panel_probe(struct mipi_dsi_device *dsi)
  145. {
  146. struct wuxga_nt_panel *wuxga_nt;
  147. int ret;
  148. dsi->lanes = 4;
  149. dsi->format = MIPI_DSI_FMT_RGB888;
  150. dsi->mode_flags = MIPI_DSI_MODE_VIDEO |
  151. MIPI_DSI_MODE_VIDEO_HSE |
  152. MIPI_DSI_CLOCK_NON_CONTINUOUS |
  153. MIPI_DSI_MODE_LPM;
  154. wuxga_nt = devm_kzalloc(&dsi->dev, sizeof(*wuxga_nt), GFP_KERNEL);
  155. if (!wuxga_nt)
  156. return -ENOMEM;
  157. mipi_dsi_set_drvdata(dsi, wuxga_nt);
  158. wuxga_nt->dsi = dsi;
  159. ret = wuxga_nt_panel_add(wuxga_nt);
  160. if (ret < 0)
  161. return ret;
  162. ret = mipi_dsi_attach(dsi);
  163. if (ret < 0) {
  164. wuxga_nt_panel_del(wuxga_nt);
  165. return ret;
  166. }
  167. return 0;
  168. }
  169. static void wuxga_nt_panel_remove(struct mipi_dsi_device *dsi)
  170. {
  171. struct wuxga_nt_panel *wuxga_nt = mipi_dsi_get_drvdata(dsi);
  172. int ret;
  173. ret = mipi_dsi_detach(dsi);
  174. if (ret < 0)
  175. dev_err(&dsi->dev, "failed to detach from DSI host: %d\n", ret);
  176. wuxga_nt_panel_del(wuxga_nt);
  177. }
  178. static struct mipi_dsi_driver wuxga_nt_panel_driver = {
  179. .driver = {
  180. .name = "panel-panasonic-vvx10f034n00",
  181. .of_match_table = wuxga_nt_of_match,
  182. },
  183. .probe = wuxga_nt_panel_probe,
  184. .remove = wuxga_nt_panel_remove,
  185. };
  186. module_mipi_dsi_driver(wuxga_nt_panel_driver);
  187. MODULE_AUTHOR("Werner Johansson <werner.johansson@sonymobile.com>");
  188. MODULE_DESCRIPTION("Panasonic VVX10F034N00 Novatek NT1397-based WUXGA (1920x1200) video mode panel driver");
  189. MODULE_LICENSE("GPL v2");