panel-panasonic-vvx10f034n00.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. bool prepared;
  29. bool enabled;
  30. ktime_t earliest_wake;
  31. const struct drm_display_mode *mode;
  32. };
  33. static inline struct wuxga_nt_panel *to_wuxga_nt_panel(struct drm_panel *panel)
  34. {
  35. return container_of(panel, struct wuxga_nt_panel, base);
  36. }
  37. static int wuxga_nt_panel_on(struct wuxga_nt_panel *wuxga_nt)
  38. {
  39. return mipi_dsi_turn_on_peripheral(wuxga_nt->dsi);
  40. }
  41. static int wuxga_nt_panel_disable(struct drm_panel *panel)
  42. {
  43. struct wuxga_nt_panel *wuxga_nt = to_wuxga_nt_panel(panel);
  44. int mipi_ret, bl_ret = 0;
  45. if (!wuxga_nt->enabled)
  46. return 0;
  47. mipi_ret = mipi_dsi_shutdown_peripheral(wuxga_nt->dsi);
  48. wuxga_nt->enabled = false;
  49. return mipi_ret ? mipi_ret : bl_ret;
  50. }
  51. static int wuxga_nt_panel_unprepare(struct drm_panel *panel)
  52. {
  53. struct wuxga_nt_panel *wuxga_nt = to_wuxga_nt_panel(panel);
  54. if (!wuxga_nt->prepared)
  55. return 0;
  56. regulator_disable(wuxga_nt->supply);
  57. wuxga_nt->earliest_wake = ktime_add_ms(ktime_get_real(), MIN_POFF_MS);
  58. wuxga_nt->prepared = false;
  59. return 0;
  60. }
  61. static int wuxga_nt_panel_prepare(struct drm_panel *panel)
  62. {
  63. struct wuxga_nt_panel *wuxga_nt = to_wuxga_nt_panel(panel);
  64. int ret;
  65. s64 enablewait;
  66. if (wuxga_nt->prepared)
  67. return 0;
  68. /*
  69. * If the user re-enabled the panel before the required off-time then
  70. * we need to wait the remaining period before re-enabling regulator
  71. */
  72. enablewait = ktime_ms_delta(wuxga_nt->earliest_wake, ktime_get_real());
  73. /* Sanity check, this should never happen */
  74. if (enablewait > MIN_POFF_MS)
  75. enablewait = MIN_POFF_MS;
  76. if (enablewait > 0)
  77. msleep(enablewait);
  78. ret = regulator_enable(wuxga_nt->supply);
  79. if (ret < 0)
  80. return ret;
  81. /*
  82. * A minimum delay of 250ms is required after power-up until commands
  83. * can be sent
  84. */
  85. msleep(250);
  86. ret = wuxga_nt_panel_on(wuxga_nt);
  87. if (ret < 0) {
  88. dev_err(panel->dev, "failed to set panel on: %d\n", ret);
  89. goto poweroff;
  90. }
  91. wuxga_nt->prepared = true;
  92. return 0;
  93. poweroff:
  94. regulator_disable(wuxga_nt->supply);
  95. return ret;
  96. }
  97. static int wuxga_nt_panel_enable(struct drm_panel *panel)
  98. {
  99. struct wuxga_nt_panel *wuxga_nt = to_wuxga_nt_panel(panel);
  100. if (wuxga_nt->enabled)
  101. return 0;
  102. wuxga_nt->enabled = true;
  103. return 0;
  104. }
  105. static const struct drm_display_mode default_mode = {
  106. .clock = 164402,
  107. .hdisplay = 1920,
  108. .hsync_start = 1920 + 152,
  109. .hsync_end = 1920 + 152 + 52,
  110. .htotal = 1920 + 152 + 52 + 20,
  111. .vdisplay = 1200,
  112. .vsync_start = 1200 + 24,
  113. .vsync_end = 1200 + 24 + 6,
  114. .vtotal = 1200 + 24 + 6 + 48,
  115. };
  116. static int wuxga_nt_panel_get_modes(struct drm_panel *panel,
  117. struct drm_connector *connector)
  118. {
  119. struct drm_display_mode *mode;
  120. mode = drm_mode_duplicate(connector->dev, &default_mode);
  121. if (!mode) {
  122. dev_err(panel->dev, "failed to add mode %ux%u@%u\n",
  123. default_mode.hdisplay, default_mode.vdisplay,
  124. drm_mode_vrefresh(&default_mode));
  125. return -ENOMEM;
  126. }
  127. drm_mode_set_name(mode);
  128. drm_mode_probed_add(connector, mode);
  129. connector->display_info.width_mm = 217;
  130. connector->display_info.height_mm = 136;
  131. return 1;
  132. }
  133. static const struct drm_panel_funcs wuxga_nt_panel_funcs = {
  134. .disable = wuxga_nt_panel_disable,
  135. .unprepare = wuxga_nt_panel_unprepare,
  136. .prepare = wuxga_nt_panel_prepare,
  137. .enable = wuxga_nt_panel_enable,
  138. .get_modes = wuxga_nt_panel_get_modes,
  139. };
  140. static const struct of_device_id wuxga_nt_of_match[] = {
  141. { .compatible = "panasonic,vvx10f034n00", },
  142. { }
  143. };
  144. MODULE_DEVICE_TABLE(of, wuxga_nt_of_match);
  145. static int wuxga_nt_panel_add(struct wuxga_nt_panel *wuxga_nt)
  146. {
  147. struct device *dev = &wuxga_nt->dsi->dev;
  148. int ret;
  149. wuxga_nt->mode = &default_mode;
  150. wuxga_nt->supply = devm_regulator_get(dev, "power");
  151. if (IS_ERR(wuxga_nt->supply))
  152. return PTR_ERR(wuxga_nt->supply);
  153. drm_panel_init(&wuxga_nt->base, &wuxga_nt->dsi->dev,
  154. &wuxga_nt_panel_funcs, DRM_MODE_CONNECTOR_DSI);
  155. ret = drm_panel_of_backlight(&wuxga_nt->base);
  156. if (ret)
  157. return ret;
  158. drm_panel_add(&wuxga_nt->base);
  159. return 0;
  160. }
  161. static void wuxga_nt_panel_del(struct wuxga_nt_panel *wuxga_nt)
  162. {
  163. if (wuxga_nt->base.dev)
  164. drm_panel_remove(&wuxga_nt->base);
  165. }
  166. static int wuxga_nt_panel_probe(struct mipi_dsi_device *dsi)
  167. {
  168. struct wuxga_nt_panel *wuxga_nt;
  169. int ret;
  170. dsi->lanes = 4;
  171. dsi->format = MIPI_DSI_FMT_RGB888;
  172. dsi->mode_flags = MIPI_DSI_MODE_VIDEO |
  173. MIPI_DSI_MODE_VIDEO_HSE |
  174. MIPI_DSI_CLOCK_NON_CONTINUOUS |
  175. MIPI_DSI_MODE_LPM;
  176. wuxga_nt = devm_kzalloc(&dsi->dev, sizeof(*wuxga_nt), GFP_KERNEL);
  177. if (!wuxga_nt)
  178. return -ENOMEM;
  179. mipi_dsi_set_drvdata(dsi, wuxga_nt);
  180. wuxga_nt->dsi = dsi;
  181. ret = wuxga_nt_panel_add(wuxga_nt);
  182. if (ret < 0)
  183. return ret;
  184. return mipi_dsi_attach(dsi);
  185. }
  186. static int wuxga_nt_panel_remove(struct mipi_dsi_device *dsi)
  187. {
  188. struct wuxga_nt_panel *wuxga_nt = mipi_dsi_get_drvdata(dsi);
  189. int ret;
  190. ret = drm_panel_disable(&wuxga_nt->base);
  191. if (ret < 0)
  192. dev_err(&dsi->dev, "failed to disable panel: %d\n", ret);
  193. ret = mipi_dsi_detach(dsi);
  194. if (ret < 0)
  195. dev_err(&dsi->dev, "failed to detach from DSI host: %d\n", ret);
  196. wuxga_nt_panel_del(wuxga_nt);
  197. return 0;
  198. }
  199. static void wuxga_nt_panel_shutdown(struct mipi_dsi_device *dsi)
  200. {
  201. struct wuxga_nt_panel *wuxga_nt = mipi_dsi_get_drvdata(dsi);
  202. drm_panel_disable(&wuxga_nt->base);
  203. }
  204. static struct mipi_dsi_driver wuxga_nt_panel_driver = {
  205. .driver = {
  206. .name = "panel-panasonic-vvx10f034n00",
  207. .of_match_table = wuxga_nt_of_match,
  208. },
  209. .probe = wuxga_nt_panel_probe,
  210. .remove = wuxga_nt_panel_remove,
  211. .shutdown = wuxga_nt_panel_shutdown,
  212. };
  213. module_mipi_dsi_driver(wuxga_nt_panel_driver);
  214. MODULE_AUTHOR("Werner Johansson <werner.johansson@sonymobile.com>");
  215. MODULE_DESCRIPTION("Panasonic VVX10F034N00 Novatek NT1397-based WUXGA (1920x1200) video mode panel driver");
  216. MODULE_LICENSE("GPL v2");