panel-sharp-ls060t1sx01.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* Copyright (c) 2021 Linaro Ltd.
  3. * Generated with linux-mdss-dsi-panel-driver-generator from vendor device tree:
  4. * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
  5. */
  6. #include <linux/delay.h>
  7. #include <linux/gpio/consumer.h>
  8. #include <linux/module.h>
  9. #include <linux/of.h>
  10. #include <linux/regulator/consumer.h>
  11. #include <video/mipi_display.h>
  12. #include <drm/drm_mipi_dsi.h>
  13. #include <drm/drm_modes.h>
  14. #include <drm/drm_panel.h>
  15. struct sharp_ls060 {
  16. struct drm_panel panel;
  17. struct mipi_dsi_device *dsi;
  18. struct regulator *vddi_supply;
  19. struct regulator *vddh_supply;
  20. struct regulator *avdd_supply;
  21. struct regulator *avee_supply;
  22. struct gpio_desc *reset_gpio;
  23. };
  24. static inline struct sharp_ls060 *to_sharp_ls060(struct drm_panel *panel)
  25. {
  26. return container_of(panel, struct sharp_ls060, panel);
  27. }
  28. static void sharp_ls060_reset(struct sharp_ls060 *ctx)
  29. {
  30. gpiod_set_value_cansleep(ctx->reset_gpio, 0);
  31. usleep_range(10000, 11000);
  32. gpiod_set_value_cansleep(ctx->reset_gpio, 1);
  33. usleep_range(10000, 11000);
  34. gpiod_set_value_cansleep(ctx->reset_gpio, 0);
  35. usleep_range(10000, 11000);
  36. }
  37. static int sharp_ls060_on(struct sharp_ls060 *ctx)
  38. {
  39. struct mipi_dsi_device *dsi = ctx->dsi;
  40. struct device *dev = &dsi->dev;
  41. int ret;
  42. dsi->mode_flags |= MIPI_DSI_MODE_LPM;
  43. mipi_dsi_dcs_write_seq(dsi, 0xbb, 0x13);
  44. mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_WRITE_MEMORY_START);
  45. ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
  46. if (ret < 0) {
  47. dev_err(dev, "Failed to exit sleep mode: %d\n", ret);
  48. return ret;
  49. }
  50. msleep(120);
  51. ret = mipi_dsi_dcs_set_display_on(dsi);
  52. if (ret < 0) {
  53. dev_err(dev, "Failed to set display on: %d\n", ret);
  54. return ret;
  55. }
  56. msleep(50);
  57. return 0;
  58. }
  59. static int sharp_ls060_off(struct sharp_ls060 *ctx)
  60. {
  61. struct mipi_dsi_device *dsi = ctx->dsi;
  62. struct device *dev = &dsi->dev;
  63. int ret;
  64. dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
  65. ret = mipi_dsi_dcs_set_display_off(dsi);
  66. if (ret < 0) {
  67. dev_err(dev, "Failed to set display off: %d\n", ret);
  68. return ret;
  69. }
  70. usleep_range(2000, 3000);
  71. ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
  72. if (ret < 0) {
  73. dev_err(dev, "Failed to enter sleep mode: %d\n", ret);
  74. return ret;
  75. }
  76. msleep(121);
  77. return 0;
  78. }
  79. static int sharp_ls060_prepare(struct drm_panel *panel)
  80. {
  81. struct sharp_ls060 *ctx = to_sharp_ls060(panel);
  82. struct device *dev = &ctx->dsi->dev;
  83. int ret;
  84. ret = regulator_enable(ctx->vddi_supply);
  85. if (ret < 0)
  86. return ret;
  87. ret = regulator_enable(ctx->avdd_supply);
  88. if (ret < 0)
  89. goto err_avdd;
  90. usleep_range(1000, 2000);
  91. ret = regulator_enable(ctx->avee_supply);
  92. if (ret < 0)
  93. goto err_avee;
  94. usleep_range(10000, 11000);
  95. ret = regulator_enable(ctx->vddh_supply);
  96. if (ret < 0)
  97. goto err_vddh;
  98. usleep_range(10000, 11000);
  99. sharp_ls060_reset(ctx);
  100. ret = sharp_ls060_on(ctx);
  101. if (ret < 0) {
  102. dev_err(dev, "Failed to initialize panel: %d\n", ret);
  103. goto err_on;
  104. }
  105. return 0;
  106. err_on:
  107. regulator_disable(ctx->vddh_supply);
  108. usleep_range(10000, 11000);
  109. err_vddh:
  110. regulator_disable(ctx->avee_supply);
  111. err_avee:
  112. regulator_disable(ctx->avdd_supply);
  113. gpiod_set_value_cansleep(ctx->reset_gpio, 1);
  114. err_avdd:
  115. regulator_disable(ctx->vddi_supply);
  116. return ret;
  117. }
  118. static int sharp_ls060_unprepare(struct drm_panel *panel)
  119. {
  120. struct sharp_ls060 *ctx = to_sharp_ls060(panel);
  121. struct device *dev = &ctx->dsi->dev;
  122. int ret;
  123. ret = sharp_ls060_off(ctx);
  124. if (ret < 0)
  125. dev_err(dev, "Failed to un-initialize panel: %d\n", ret);
  126. regulator_disable(ctx->vddh_supply);
  127. usleep_range(10000, 11000);
  128. regulator_disable(ctx->avee_supply);
  129. regulator_disable(ctx->avdd_supply);
  130. gpiod_set_value_cansleep(ctx->reset_gpio, 1);
  131. regulator_disable(ctx->vddi_supply);
  132. return 0;
  133. }
  134. static const struct drm_display_mode sharp_ls060_mode = {
  135. .clock = (1080 + 96 + 16 + 64) * (1920 + 4 + 1 + 16) * 60 / 1000,
  136. .hdisplay = 1080,
  137. .hsync_start = 1080 + 96,
  138. .hsync_end = 1080 + 96 + 16,
  139. .htotal = 1080 + 96 + 16 + 64,
  140. .vdisplay = 1920,
  141. .vsync_start = 1920 + 4,
  142. .vsync_end = 1920 + 4 + 1,
  143. .vtotal = 1920 + 4 + 1 + 16,
  144. .width_mm = 75,
  145. .height_mm = 132,
  146. };
  147. static int sharp_ls060_get_modes(struct drm_panel *panel,
  148. struct drm_connector *connector)
  149. {
  150. struct drm_display_mode *mode;
  151. mode = drm_mode_duplicate(connector->dev, &sharp_ls060_mode);
  152. if (!mode)
  153. return -ENOMEM;
  154. drm_mode_set_name(mode);
  155. mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
  156. connector->display_info.width_mm = mode->width_mm;
  157. connector->display_info.height_mm = mode->height_mm;
  158. drm_mode_probed_add(connector, mode);
  159. return 1;
  160. }
  161. static const struct drm_panel_funcs sharp_ls060_panel_funcs = {
  162. .prepare = sharp_ls060_prepare,
  163. .unprepare = sharp_ls060_unprepare,
  164. .get_modes = sharp_ls060_get_modes,
  165. };
  166. static int sharp_ls060_probe(struct mipi_dsi_device *dsi)
  167. {
  168. struct device *dev = &dsi->dev;
  169. struct sharp_ls060 *ctx;
  170. int ret;
  171. ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
  172. if (!ctx)
  173. return -ENOMEM;
  174. ctx->vddi_supply = devm_regulator_get(dev, "vddi");
  175. if (IS_ERR(ctx->vddi_supply))
  176. return PTR_ERR(ctx->vddi_supply);
  177. ctx->vddh_supply = devm_regulator_get(dev, "vddh");
  178. if (IS_ERR(ctx->vddh_supply))
  179. return PTR_ERR(ctx->vddh_supply);
  180. ctx->avdd_supply = devm_regulator_get(dev, "avdd");
  181. if (IS_ERR(ctx->avdd_supply))
  182. return PTR_ERR(ctx->avdd_supply);
  183. ctx->avee_supply = devm_regulator_get(dev, "avee");
  184. if (IS_ERR(ctx->avee_supply))
  185. return PTR_ERR(ctx->avee_supply);
  186. ctx->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
  187. if (IS_ERR(ctx->reset_gpio))
  188. return dev_err_probe(dev, PTR_ERR(ctx->reset_gpio),
  189. "Failed to get reset-gpios\n");
  190. ctx->dsi = dsi;
  191. mipi_dsi_set_drvdata(dsi, ctx);
  192. dsi->lanes = 4;
  193. dsi->format = MIPI_DSI_FMT_RGB888;
  194. dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST |
  195. MIPI_DSI_MODE_NO_EOT_PACKET |
  196. MIPI_DSI_CLOCK_NON_CONTINUOUS;
  197. drm_panel_init(&ctx->panel, dev, &sharp_ls060_panel_funcs,
  198. DRM_MODE_CONNECTOR_DSI);
  199. ret = drm_panel_of_backlight(&ctx->panel);
  200. if (ret)
  201. return dev_err_probe(dev, ret, "Failed to get backlight\n");
  202. drm_panel_add(&ctx->panel);
  203. ret = mipi_dsi_attach(dsi);
  204. if (ret < 0) {
  205. dev_err(dev, "Failed to attach to DSI host: %d\n", ret);
  206. drm_panel_remove(&ctx->panel);
  207. return ret;
  208. }
  209. return 0;
  210. }
  211. static void sharp_ls060_remove(struct mipi_dsi_device *dsi)
  212. {
  213. struct sharp_ls060 *ctx = mipi_dsi_get_drvdata(dsi);
  214. int ret;
  215. ret = mipi_dsi_detach(dsi);
  216. if (ret < 0)
  217. dev_err(&dsi->dev, "Failed to detach from DSI host: %d\n", ret);
  218. drm_panel_remove(&ctx->panel);
  219. }
  220. static const struct of_device_id sharp_ls060t1sx01_of_match[] = {
  221. { .compatible = "sharp,ls060t1sx01" },
  222. { /* sentinel */ }
  223. };
  224. MODULE_DEVICE_TABLE(of, sharp_ls060t1sx01_of_match);
  225. static struct mipi_dsi_driver sharp_ls060_driver = {
  226. .probe = sharp_ls060_probe,
  227. .remove = sharp_ls060_remove,
  228. .driver = {
  229. .name = "panel-sharp-ls060t1sx01",
  230. .of_match_table = sharp_ls060t1sx01_of_match,
  231. },
  232. };
  233. module_mipi_dsi_driver(sharp_ls060_driver);
  234. MODULE_AUTHOR("Dmitry Baryshkov <dmitry.baryshkov@linaro.org>");
  235. MODULE_DESCRIPTION("DRM driver for Sharp LS060T1SX01 1080p video mode dsi panel");
  236. MODULE_LICENSE("GPL v2");