panel-boe-tv101wum-ll2.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. // Generated with linux-mdss-dsi-panel-driver-generator from vendor device tree:
  3. // Copyright (c) 2013, The Linux Foundation. All rights reserved.
  4. // Copyright (c) 2024, Neil Armstrong <neil.armstrong@linaro.org>
  5. #include <linux/delay.h>
  6. #include <linux/gpio/consumer.h>
  7. #include <linux/module.h>
  8. #include <linux/of.h>
  9. #include <linux/regulator/consumer.h>
  10. #include <drm/drm_mipi_dsi.h>
  11. #include <drm/drm_modes.h>
  12. #include <drm/drm_panel.h>
  13. #include <drm/drm_probe_helper.h>
  14. struct boe_tv101wum_ll2 {
  15. struct drm_panel panel;
  16. struct mipi_dsi_device *dsi;
  17. struct gpio_desc *reset_gpio;
  18. struct regulator_bulk_data *supplies;
  19. };
  20. static const struct regulator_bulk_data boe_tv101wum_ll2_supplies[] = {
  21. { .supply = "vsp" },
  22. { .supply = "vsn" },
  23. };
  24. static inline struct boe_tv101wum_ll2 *to_boe_tv101wum_ll2(struct drm_panel *panel)
  25. {
  26. return container_of(panel, struct boe_tv101wum_ll2, panel);
  27. }
  28. static void boe_tv101wum_ll2_reset(struct boe_tv101wum_ll2 *ctx)
  29. {
  30. gpiod_set_value_cansleep(ctx->reset_gpio, 0);
  31. usleep_range(5000, 6000);
  32. gpiod_set_value_cansleep(ctx->reset_gpio, 1);
  33. usleep_range(5000, 6000);
  34. gpiod_set_value_cansleep(ctx->reset_gpio, 0);
  35. msleep(120);
  36. }
  37. static int boe_tv101wum_ll2_on(struct boe_tv101wum_ll2 *ctx)
  38. {
  39. struct mipi_dsi_device *dsi = ctx->dsi;
  40. struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi };
  41. dsi->mode_flags |= MIPI_DSI_MODE_LPM;
  42. mipi_dsi_dcs_exit_sleep_mode_multi(&dsi_ctx);
  43. mipi_dsi_msleep(&dsi_ctx, 120);
  44. mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x50, 0x5a, 0x0e);
  45. mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x80, 0xff, 0x81, 0x68, 0x6c, 0x22,
  46. 0x6d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00);
  47. mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x50, 0x5a, 0x23);
  48. mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x90, 0x00, 0x00);
  49. mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x94, 0x2c, 0x00);
  50. mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x50, 0x5a, 0x19);
  51. mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xa2, 0x38);
  52. mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x50, 0x5a, 0x0c);
  53. mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x80, 0xfd);
  54. mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0x50, 0x00);
  55. mipi_dsi_dcs_set_display_on_multi(&dsi_ctx);
  56. mipi_dsi_msleep(&dsi_ctx, 20);
  57. return dsi_ctx.accum_err;
  58. }
  59. static void boe_tv101wum_ll2_off(struct boe_tv101wum_ll2 *ctx)
  60. {
  61. struct mipi_dsi_device *dsi = ctx->dsi;
  62. struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi };
  63. dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
  64. mipi_dsi_dcs_set_display_off_multi(&dsi_ctx);
  65. mipi_dsi_msleep(&dsi_ctx, 70);
  66. mipi_dsi_dcs_enter_sleep_mode_multi(&dsi_ctx);
  67. mipi_dsi_msleep(&dsi_ctx, 20);
  68. mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x04, 0x5a);
  69. mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x05, 0x5a);
  70. mipi_dsi_msleep(&dsi_ctx, 150);
  71. }
  72. static int boe_tv101wum_ll2_prepare(struct drm_panel *panel)
  73. {
  74. struct boe_tv101wum_ll2 *ctx = to_boe_tv101wum_ll2(panel);
  75. int ret;
  76. ret = regulator_bulk_enable(ARRAY_SIZE(boe_tv101wum_ll2_supplies),
  77. ctx->supplies);
  78. if (ret < 0)
  79. return ret;
  80. boe_tv101wum_ll2_reset(ctx);
  81. ret = boe_tv101wum_ll2_on(ctx);
  82. if (ret < 0) {
  83. gpiod_set_value_cansleep(ctx->reset_gpio, 1);
  84. regulator_bulk_disable(ARRAY_SIZE(boe_tv101wum_ll2_supplies),
  85. ctx->supplies);
  86. return ret;
  87. }
  88. return 0;
  89. }
  90. static int boe_tv101wum_ll2_unprepare(struct drm_panel *panel)
  91. {
  92. struct boe_tv101wum_ll2 *ctx = to_boe_tv101wum_ll2(panel);
  93. /* Ignore errors on failure, in any case set gpio and disable regulators */
  94. boe_tv101wum_ll2_off(ctx);
  95. gpiod_set_value_cansleep(ctx->reset_gpio, 1);
  96. regulator_bulk_disable(ARRAY_SIZE(boe_tv101wum_ll2_supplies),
  97. ctx->supplies);
  98. return 0;
  99. }
  100. static const struct drm_display_mode boe_tv101wum_ll2_mode = {
  101. .clock = (1200 + 27 + 8 + 12) * (1920 + 155 + 8 + 32) * 60 / 1000,
  102. .hdisplay = 1200,
  103. .hsync_start = 1200 + 27,
  104. .hsync_end = 1200 + 27 + 8,
  105. .htotal = 1200 + 27 + 8 + 12,
  106. .vdisplay = 1920,
  107. .vsync_start = 1920 + 155,
  108. .vsync_end = 1920 + 155 + 8,
  109. .vtotal = 1920 + 155 + 8 + 32,
  110. .width_mm = 136,
  111. .height_mm = 217,
  112. .type = DRM_MODE_TYPE_DRIVER,
  113. };
  114. static int boe_tv101wum_ll2_get_modes(struct drm_panel *panel,
  115. struct drm_connector *connector)
  116. {
  117. /* We do not set display_info.bpc since unset value is bpc=8 by default */
  118. return drm_connector_helper_get_modes_fixed(connector, &boe_tv101wum_ll2_mode);
  119. }
  120. static const struct drm_panel_funcs boe_tv101wum_ll2_panel_funcs = {
  121. .prepare = boe_tv101wum_ll2_prepare,
  122. .unprepare = boe_tv101wum_ll2_unprepare,
  123. .get_modes = boe_tv101wum_ll2_get_modes,
  124. };
  125. static int boe_tv101wum_ll2_probe(struct mipi_dsi_device *dsi)
  126. {
  127. struct device *dev = &dsi->dev;
  128. struct boe_tv101wum_ll2 *ctx;
  129. int ret;
  130. ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
  131. if (!ctx)
  132. return -ENOMEM;
  133. ret = devm_regulator_bulk_get_const(&dsi->dev,
  134. ARRAY_SIZE(boe_tv101wum_ll2_supplies),
  135. boe_tv101wum_ll2_supplies,
  136. &ctx->supplies);
  137. if (ret < 0)
  138. return ret;
  139. ctx->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
  140. if (IS_ERR(ctx->reset_gpio))
  141. return dev_err_probe(dev, PTR_ERR(ctx->reset_gpio),
  142. "Failed to get reset-gpios\n");
  143. ctx->dsi = dsi;
  144. mipi_dsi_set_drvdata(dsi, ctx);
  145. dsi->lanes = 4;
  146. dsi->format = MIPI_DSI_FMT_RGB888;
  147. dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST |
  148. MIPI_DSI_MODE_VIDEO_HSE;
  149. drm_panel_init(&ctx->panel, dev, &boe_tv101wum_ll2_panel_funcs,
  150. DRM_MODE_CONNECTOR_DSI);
  151. ctx->panel.prepare_prev_first = true;
  152. ret = drm_panel_of_backlight(&ctx->panel);
  153. if (ret)
  154. return dev_err_probe(dev, ret, "Failed to get backlight\n");
  155. drm_panel_add(&ctx->panel);
  156. ret = mipi_dsi_attach(dsi);
  157. if (ret < 0) {
  158. drm_panel_remove(&ctx->panel);
  159. return dev_err_probe(dev, ret, "Failed to attach to DSI host\n");
  160. }
  161. return 0;
  162. }
  163. static void boe_tv101wum_ll2_remove(struct mipi_dsi_device *dsi)
  164. {
  165. struct boe_tv101wum_ll2 *ctx = mipi_dsi_get_drvdata(dsi);
  166. int ret;
  167. ret = mipi_dsi_detach(dsi);
  168. if (ret < 0)
  169. dev_err(&dsi->dev, "Failed to detach from DSI host: %d\n", ret);
  170. drm_panel_remove(&ctx->panel);
  171. }
  172. static const struct of_device_id boe_tv101wum_ll2_of_match[] = {
  173. { .compatible = "boe,tv101wum-ll2" },
  174. { /* sentinel */ }
  175. };
  176. MODULE_DEVICE_TABLE(of, boe_tv101wum_ll2_of_match);
  177. static struct mipi_dsi_driver boe_tv101wum_ll2_driver = {
  178. .probe = boe_tv101wum_ll2_probe,
  179. .remove = boe_tv101wum_ll2_remove,
  180. .driver = {
  181. .name = "panel-boe-tv101wum_ll2",
  182. .of_match_table = boe_tv101wum_ll2_of_match,
  183. },
  184. };
  185. module_mipi_dsi_driver(boe_tv101wum_ll2_driver);
  186. MODULE_DESCRIPTION("DRM driver for BOE TV101WUM-LL2 Panel");
  187. MODULE_LICENSE("GPL");