panel-ronbo-rb070d30.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2018-2019, Bridge Systems BV
  4. * Copyright (C) 2018-2019, Bootlin
  5. * Copyright (C) 2017, Free Electrons
  6. *
  7. * This file based on panel-ilitek-ili9881c.c
  8. */
  9. #include <linux/delay.h>
  10. #include <linux/device.h>
  11. #include <linux/err.h>
  12. #include <linux/errno.h>
  13. #include <linux/fb.h>
  14. #include <linux/kernel.h>
  15. #include <linux/media-bus-format.h>
  16. #include <linux/module.h>
  17. #include <linux/gpio/consumer.h>
  18. #include <linux/regulator/consumer.h>
  19. #include <drm/drm_connector.h>
  20. #include <drm/drm_mipi_dsi.h>
  21. #include <drm/drm_modes.h>
  22. #include <drm/drm_panel.h>
  23. struct rb070d30_panel {
  24. struct drm_panel panel;
  25. struct mipi_dsi_device *dsi;
  26. struct regulator *supply;
  27. struct {
  28. struct gpio_desc *power;
  29. struct gpio_desc *reset;
  30. struct gpio_desc *updn;
  31. struct gpio_desc *shlr;
  32. } gpios;
  33. };
  34. static inline struct rb070d30_panel *panel_to_rb070d30_panel(struct drm_panel *panel)
  35. {
  36. return container_of(panel, struct rb070d30_panel, panel);
  37. }
  38. static int rb070d30_panel_prepare(struct drm_panel *panel)
  39. {
  40. struct rb070d30_panel *ctx = panel_to_rb070d30_panel(panel);
  41. int ret;
  42. ret = regulator_enable(ctx->supply);
  43. if (ret < 0) {
  44. dev_err(&ctx->dsi->dev, "Failed to enable supply: %d\n", ret);
  45. return ret;
  46. }
  47. msleep(20);
  48. gpiod_set_value(ctx->gpios.power, 1);
  49. msleep(20);
  50. gpiod_set_value(ctx->gpios.reset, 1);
  51. msleep(20);
  52. return 0;
  53. }
  54. static int rb070d30_panel_unprepare(struct drm_panel *panel)
  55. {
  56. struct rb070d30_panel *ctx = panel_to_rb070d30_panel(panel);
  57. gpiod_set_value(ctx->gpios.reset, 0);
  58. gpiod_set_value(ctx->gpios.power, 0);
  59. regulator_disable(ctx->supply);
  60. return 0;
  61. }
  62. static int rb070d30_panel_enable(struct drm_panel *panel)
  63. {
  64. struct rb070d30_panel *ctx = panel_to_rb070d30_panel(panel);
  65. return mipi_dsi_dcs_exit_sleep_mode(ctx->dsi);
  66. }
  67. static int rb070d30_panel_disable(struct drm_panel *panel)
  68. {
  69. struct rb070d30_panel *ctx = panel_to_rb070d30_panel(panel);
  70. return mipi_dsi_dcs_enter_sleep_mode(ctx->dsi);
  71. }
  72. /* Default timings */
  73. static const struct drm_display_mode default_mode = {
  74. .clock = 51206,
  75. .hdisplay = 1024,
  76. .hsync_start = 1024 + 160,
  77. .hsync_end = 1024 + 160 + 80,
  78. .htotal = 1024 + 160 + 80 + 80,
  79. .vdisplay = 600,
  80. .vsync_start = 600 + 12,
  81. .vsync_end = 600 + 12 + 10,
  82. .vtotal = 600 + 12 + 10 + 13,
  83. .width_mm = 154,
  84. .height_mm = 85,
  85. };
  86. static int rb070d30_panel_get_modes(struct drm_panel *panel,
  87. struct drm_connector *connector)
  88. {
  89. struct rb070d30_panel *ctx = panel_to_rb070d30_panel(panel);
  90. struct drm_display_mode *mode;
  91. static const u32 bus_format = MEDIA_BUS_FMT_RGB888_1X24;
  92. mode = drm_mode_duplicate(connector->dev, &default_mode);
  93. if (!mode) {
  94. dev_err(&ctx->dsi->dev, "Failed to add mode " DRM_MODE_FMT "\n",
  95. DRM_MODE_ARG(&default_mode));
  96. return -EINVAL;
  97. }
  98. drm_mode_set_name(mode);
  99. mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
  100. drm_mode_probed_add(connector, mode);
  101. connector->display_info.bpc = 8;
  102. connector->display_info.width_mm = mode->width_mm;
  103. connector->display_info.height_mm = mode->height_mm;
  104. drm_display_info_set_bus_formats(&connector->display_info,
  105. &bus_format, 1);
  106. return 1;
  107. }
  108. static const struct drm_panel_funcs rb070d30_panel_funcs = {
  109. .get_modes = rb070d30_panel_get_modes,
  110. .prepare = rb070d30_panel_prepare,
  111. .enable = rb070d30_panel_enable,
  112. .disable = rb070d30_panel_disable,
  113. .unprepare = rb070d30_panel_unprepare,
  114. };
  115. static int rb070d30_panel_dsi_probe(struct mipi_dsi_device *dsi)
  116. {
  117. struct rb070d30_panel *ctx;
  118. int ret;
  119. ctx = devm_kzalloc(&dsi->dev, sizeof(*ctx), GFP_KERNEL);
  120. if (!ctx)
  121. return -ENOMEM;
  122. ctx->supply = devm_regulator_get(&dsi->dev, "vcc-lcd");
  123. if (IS_ERR(ctx->supply))
  124. return PTR_ERR(ctx->supply);
  125. mipi_dsi_set_drvdata(dsi, ctx);
  126. ctx->dsi = dsi;
  127. drm_panel_init(&ctx->panel, &dsi->dev, &rb070d30_panel_funcs,
  128. DRM_MODE_CONNECTOR_DSI);
  129. ctx->gpios.reset = devm_gpiod_get(&dsi->dev, "reset", GPIOD_OUT_LOW);
  130. if (IS_ERR(ctx->gpios.reset)) {
  131. dev_err(&dsi->dev, "Couldn't get our reset GPIO\n");
  132. return PTR_ERR(ctx->gpios.reset);
  133. }
  134. ctx->gpios.power = devm_gpiod_get(&dsi->dev, "power", GPIOD_OUT_LOW);
  135. if (IS_ERR(ctx->gpios.power)) {
  136. dev_err(&dsi->dev, "Couldn't get our power GPIO\n");
  137. return PTR_ERR(ctx->gpios.power);
  138. }
  139. /*
  140. * We don't change the state of that GPIO later on but we need
  141. * to force it into a low state.
  142. */
  143. ctx->gpios.updn = devm_gpiod_get(&dsi->dev, "updn", GPIOD_OUT_LOW);
  144. if (IS_ERR(ctx->gpios.updn)) {
  145. dev_err(&dsi->dev, "Couldn't get our updn GPIO\n");
  146. return PTR_ERR(ctx->gpios.updn);
  147. }
  148. /*
  149. * We don't change the state of that GPIO later on but we need
  150. * to force it into a low state.
  151. */
  152. ctx->gpios.shlr = devm_gpiod_get(&dsi->dev, "shlr", GPIOD_OUT_LOW);
  153. if (IS_ERR(ctx->gpios.shlr)) {
  154. dev_err(&dsi->dev, "Couldn't get our shlr GPIO\n");
  155. return PTR_ERR(ctx->gpios.shlr);
  156. }
  157. ret = drm_panel_of_backlight(&ctx->panel);
  158. if (ret)
  159. return ret;
  160. drm_panel_add(&ctx->panel);
  161. dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST | MIPI_DSI_MODE_LPM;
  162. dsi->format = MIPI_DSI_FMT_RGB888;
  163. dsi->lanes = 4;
  164. ret = mipi_dsi_attach(dsi);
  165. if (ret < 0) {
  166. drm_panel_remove(&ctx->panel);
  167. return ret;
  168. }
  169. return 0;
  170. }
  171. static void rb070d30_panel_dsi_remove(struct mipi_dsi_device *dsi)
  172. {
  173. struct rb070d30_panel *ctx = mipi_dsi_get_drvdata(dsi);
  174. mipi_dsi_detach(dsi);
  175. drm_panel_remove(&ctx->panel);
  176. }
  177. static const struct of_device_id rb070d30_panel_of_match[] = {
  178. { .compatible = "ronbo,rb070d30" },
  179. { /* sentinel */ },
  180. };
  181. MODULE_DEVICE_TABLE(of, rb070d30_panel_of_match);
  182. static struct mipi_dsi_driver rb070d30_panel_driver = {
  183. .probe = rb070d30_panel_dsi_probe,
  184. .remove = rb070d30_panel_dsi_remove,
  185. .driver = {
  186. .name = "panel-ronbo-rb070d30",
  187. .of_match_table = rb070d30_panel_of_match,
  188. },
  189. };
  190. module_mipi_dsi_driver(rb070d30_panel_driver);
  191. MODULE_AUTHOR("Boris Brezillon <[email protected]>");
  192. MODULE_AUTHOR("Konstantin Sudakov <[email protected]>");
  193. MODULE_DESCRIPTION("Ronbo RB070D30 Panel Driver");
  194. MODULE_LICENSE("GPL");