panel-ebbg-ft8719.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2022 Joel Selvaraj <[email protected]>
  4. * Generated with linux-mdss-dsi-panel-driver-generator from vendor device tree:
  5. * Copyright (c) 2013, The Linux Foundation. All rights reserved.
  6. */
  7. #include <linux/delay.h>
  8. #include <linux/gpio/consumer.h>
  9. #include <linux/regulator/consumer.h>
  10. #include <linux/module.h>
  11. #include <linux/of.h>
  12. #include <video/mipi_display.h>
  13. #include <drm/drm_mipi_dsi.h>
  14. #include <drm/drm_modes.h>
  15. #include <drm/drm_panel.h>
  16. static const char * const regulator_names[] = {
  17. "vddio",
  18. "vddpos",
  19. "vddneg",
  20. };
  21. static const unsigned long regulator_enable_loads[] = {
  22. 62000,
  23. 100000,
  24. 100000
  25. };
  26. struct ebbg_ft8719 {
  27. struct drm_panel panel;
  28. struct mipi_dsi_device *dsi;
  29. struct regulator_bulk_data supplies[ARRAY_SIZE(regulator_names)];
  30. struct gpio_desc *reset_gpio;
  31. };
  32. static inline
  33. struct ebbg_ft8719 *to_ebbg_ft8719(struct drm_panel *panel)
  34. {
  35. return container_of(panel, struct ebbg_ft8719, panel);
  36. }
  37. static void ebbg_ft8719_reset(struct ebbg_ft8719 *ctx)
  38. {
  39. gpiod_set_value_cansleep(ctx->reset_gpio, 0);
  40. usleep_range(4000, 5000);
  41. gpiod_set_value_cansleep(ctx->reset_gpio, 1);
  42. usleep_range(1000, 2000);
  43. gpiod_set_value_cansleep(ctx->reset_gpio, 0);
  44. usleep_range(15000, 16000);
  45. }
  46. static int ebbg_ft8719_on(struct ebbg_ft8719 *ctx)
  47. {
  48. struct mipi_dsi_device *dsi = ctx->dsi;
  49. struct device *dev = &dsi->dev;
  50. int ret;
  51. dsi->mode_flags |= MIPI_DSI_MODE_LPM;
  52. ret = mipi_dsi_dcs_set_display_brightness(dsi, 0x00ff);
  53. if (ret < 0) {
  54. dev_err(dev, "Failed to set display brightness: %d\n", ret);
  55. return ret;
  56. }
  57. mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_WRITE_CONTROL_DISPLAY, 0x24);
  58. mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_WRITE_POWER_SAVE, 0x00);
  59. ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
  60. if (ret < 0) {
  61. dev_err(dev, "Failed to exit sleep mode: %d\n", ret);
  62. return ret;
  63. }
  64. msleep(90);
  65. ret = mipi_dsi_dcs_set_display_on(dsi);
  66. if (ret < 0) {
  67. dev_err(dev, "Failed to set display on: %d\n", ret);
  68. return ret;
  69. }
  70. return 0;
  71. }
  72. static int ebbg_ft8719_off(struct ebbg_ft8719 *ctx)
  73. {
  74. struct mipi_dsi_device *dsi = ctx->dsi;
  75. struct device *dev = &dsi->dev;
  76. int ret;
  77. dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
  78. ret = mipi_dsi_dcs_set_display_off(dsi);
  79. if (ret < 0) {
  80. dev_err(dev, "Failed to set display off: %d\n", ret);
  81. return ret;
  82. }
  83. usleep_range(10000, 11000);
  84. ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
  85. if (ret < 0) {
  86. dev_err(dev, "Failed to enter sleep mode: %d\n", ret);
  87. return ret;
  88. }
  89. msleep(90);
  90. return 0;
  91. }
  92. static int ebbg_ft8719_prepare(struct drm_panel *panel)
  93. {
  94. struct ebbg_ft8719 *ctx = to_ebbg_ft8719(panel);
  95. struct device *dev = &ctx->dsi->dev;
  96. int ret;
  97. ret = regulator_bulk_enable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
  98. if (ret < 0)
  99. return ret;
  100. ebbg_ft8719_reset(ctx);
  101. ret = ebbg_ft8719_on(ctx);
  102. if (ret < 0) {
  103. dev_err(dev, "Failed to initialize panel: %d\n", ret);
  104. gpiod_set_value_cansleep(ctx->reset_gpio, 1);
  105. return ret;
  106. }
  107. return 0;
  108. }
  109. static int ebbg_ft8719_unprepare(struct drm_panel *panel)
  110. {
  111. struct ebbg_ft8719 *ctx = to_ebbg_ft8719(panel);
  112. struct device *dev = &ctx->dsi->dev;
  113. int ret;
  114. ret = ebbg_ft8719_off(ctx);
  115. if (ret < 0)
  116. dev_err(dev, "Failed to un-initialize panel: %d\n", ret);
  117. gpiod_set_value_cansleep(ctx->reset_gpio, 1);
  118. ret = regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
  119. if (ret)
  120. dev_err(panel->dev, "Failed to disable regulators: %d\n", ret);
  121. return 0;
  122. }
  123. static const struct drm_display_mode ebbg_ft8719_mode = {
  124. .clock = (1080 + 28 + 4 + 16) * (2246 + 120 + 4 + 12) * 60 / 1000,
  125. .hdisplay = 1080,
  126. .hsync_start = 1080 + 28,
  127. .hsync_end = 1080 + 28 + 4,
  128. .htotal = 1080 + 28 + 4 + 16,
  129. .vdisplay = 2246,
  130. .vsync_start = 2246 + 120,
  131. .vsync_end = 2246 + 120 + 4,
  132. .vtotal = 2246 + 120 + 4 + 12,
  133. .width_mm = 68,
  134. .height_mm = 141,
  135. };
  136. static int ebbg_ft8719_get_modes(struct drm_panel *panel,
  137. struct drm_connector *connector)
  138. {
  139. struct drm_display_mode *mode;
  140. mode = drm_mode_duplicate(connector->dev, &ebbg_ft8719_mode);
  141. if (!mode)
  142. return -ENOMEM;
  143. drm_mode_set_name(mode);
  144. mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
  145. connector->display_info.width_mm = mode->width_mm;
  146. connector->display_info.height_mm = mode->height_mm;
  147. drm_mode_probed_add(connector, mode);
  148. return 1;
  149. }
  150. static const struct drm_panel_funcs ebbg_ft8719_panel_funcs = {
  151. .prepare = ebbg_ft8719_prepare,
  152. .unprepare = ebbg_ft8719_unprepare,
  153. .get_modes = ebbg_ft8719_get_modes,
  154. };
  155. static int ebbg_ft8719_probe(struct mipi_dsi_device *dsi)
  156. {
  157. struct device *dev = &dsi->dev;
  158. struct ebbg_ft8719 *ctx;
  159. int i, ret;
  160. ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
  161. if (!ctx)
  162. return -ENOMEM;
  163. for (i = 0; i < ARRAY_SIZE(ctx->supplies); i++)
  164. ctx->supplies[i].supply = regulator_names[i];
  165. ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ctx->supplies),
  166. ctx->supplies);
  167. if (ret < 0)
  168. return dev_err_probe(dev, ret, "Failed to get regulators\n");
  169. for (i = 0; i < ARRAY_SIZE(ctx->supplies); i++) {
  170. ret = regulator_set_load(ctx->supplies[i].consumer,
  171. regulator_enable_loads[i]);
  172. if (ret)
  173. return dev_err_probe(dev, ret,
  174. "Failed to set regulator load\n");
  175. }
  176. ctx->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
  177. if (IS_ERR(ctx->reset_gpio))
  178. return dev_err_probe(dev, PTR_ERR(ctx->reset_gpio),
  179. "Failed to get reset-gpios\n");
  180. ctx->dsi = dsi;
  181. mipi_dsi_set_drvdata(dsi, ctx);
  182. dsi->lanes = 4;
  183. dsi->format = MIPI_DSI_FMT_RGB888;
  184. dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST |
  185. MIPI_DSI_CLOCK_NON_CONTINUOUS;
  186. drm_panel_init(&ctx->panel, dev, &ebbg_ft8719_panel_funcs,
  187. DRM_MODE_CONNECTOR_DSI);
  188. ret = drm_panel_of_backlight(&ctx->panel);
  189. if (ret)
  190. return dev_err_probe(dev, ret, "Failed to get backlight\n");
  191. drm_panel_add(&ctx->panel);
  192. ret = mipi_dsi_attach(dsi);
  193. if (ret < 0) {
  194. dev_err(dev, "Failed to attach to DSI host: %d\n", ret);
  195. drm_panel_remove(&ctx->panel);
  196. return ret;
  197. }
  198. return 0;
  199. }
  200. static void ebbg_ft8719_remove(struct mipi_dsi_device *dsi)
  201. {
  202. struct ebbg_ft8719 *ctx = mipi_dsi_get_drvdata(dsi);
  203. int ret;
  204. ret = mipi_dsi_detach(dsi);
  205. if (ret < 0)
  206. dev_err(&dsi->dev, "Failed to detach from DSI host: %d\n", ret);
  207. drm_panel_remove(&ctx->panel);
  208. }
  209. static const struct of_device_id ebbg_ft8719_of_match[] = {
  210. { .compatible = "ebbg,ft8719" },
  211. { /* sentinel */ }
  212. };
  213. MODULE_DEVICE_TABLE(of, ebbg_ft8719_of_match);
  214. static struct mipi_dsi_driver ebbg_ft8719_driver = {
  215. .probe = ebbg_ft8719_probe,
  216. .remove = ebbg_ft8719_remove,
  217. .driver = {
  218. .name = "panel-ebbg-ft8719",
  219. .of_match_table = ebbg_ft8719_of_match,
  220. },
  221. };
  222. module_mipi_dsi_driver(ebbg_ft8719_driver);
  223. MODULE_AUTHOR("Joel Selvaraj <[email protected]>");
  224. MODULE_DESCRIPTION("DRM driver for EBBG FT8719 video dsi panel");
  225. MODULE_LICENSE("GPL v2");