tdo-tl070wsh30.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2020 BayLibre, SAS
  4. * Author: Neil Armstrong <narmstrong@baylibre.com>
  5. */
  6. #include <common.h>
  7. #include <backlight.h>
  8. #include <dm.h>
  9. #include <mipi_dsi.h>
  10. #include <panel.h>
  11. #include <asm/gpio.h>
  12. #include <dm/device_compat.h>
  13. #include <linux/delay.h>
  14. #include <power/regulator.h>
  15. struct tl070wsh30_panel_priv {
  16. struct udevice *reg;
  17. struct udevice *backlight;
  18. struct gpio_desc reset;
  19. };
  20. static const struct display_timing default_timing = {
  21. .pixelclock.typ = 47250000,
  22. .hactive.typ = 1024,
  23. .hfront_porch.typ = 46,
  24. .hback_porch.typ = 100,
  25. .hsync_len.typ = 80,
  26. .vactive.typ = 600,
  27. .vfront_porch.typ = 5,
  28. .vback_porch.typ = 20,
  29. .vsync_len.typ = 5,
  30. .flags = DISPLAY_FLAGS_HSYNC_HIGH | DISPLAY_FLAGS_VSYNC_HIGH,
  31. };
  32. static int tl070wsh30_panel_enable_backlight(struct udevice *dev)
  33. {
  34. struct mipi_dsi_panel_plat *plat = dev_get_plat(dev);
  35. struct mipi_dsi_device *device = plat->device;
  36. struct tl070wsh30_panel_priv *priv = dev_get_priv(dev);
  37. int ret;
  38. ret = mipi_dsi_attach(device);
  39. if (ret < 0)
  40. return ret;
  41. ret = mipi_dsi_dcs_exit_sleep_mode(device);
  42. if (ret)
  43. return ret;
  44. mdelay(200);
  45. ret = mipi_dsi_dcs_set_display_on(device);
  46. if (ret)
  47. return ret;
  48. mdelay(20);
  49. ret = backlight_enable(priv->backlight);
  50. if (ret)
  51. return ret;
  52. return 0;
  53. }
  54. static int tl070wsh30_panel_get_display_timing(struct udevice *dev,
  55. struct display_timing *timings)
  56. {
  57. memcpy(timings, &default_timing, sizeof(*timings));
  58. return 0;
  59. }
  60. static int tl070wsh30_panel_of_to_plat(struct udevice *dev)
  61. {
  62. struct tl070wsh30_panel_priv *priv = dev_get_priv(dev);
  63. int ret;
  64. if (IS_ENABLED(CONFIG_DM_REGULATOR)) {
  65. ret = device_get_supply_regulator(dev, "power-supply",
  66. &priv->reg);
  67. if (ret && ret != -ENOENT) {
  68. dev_err(dev, "Warning: cannot get power supply\n");
  69. return ret;
  70. }
  71. }
  72. ret = gpio_request_by_name(dev, "reset-gpios", 0, &priv->reset,
  73. GPIOD_IS_OUT);
  74. if (ret) {
  75. dev_err(dev, "Warning: cannot get reset GPIO\n");
  76. if (ret != -ENOENT)
  77. return ret;
  78. }
  79. ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev,
  80. "backlight", &priv->backlight);
  81. if (ret) {
  82. dev_err(dev, "Cannot get backlight: ret=%d\n", ret);
  83. return ret;
  84. }
  85. return 0;
  86. }
  87. static int tl070wsh30_panel_probe(struct udevice *dev)
  88. {
  89. struct tl070wsh30_panel_priv *priv = dev_get_priv(dev);
  90. struct mipi_dsi_panel_plat *plat = dev_get_plat(dev);
  91. int ret;
  92. if (IS_ENABLED(CONFIG_DM_REGULATOR) && priv->reg) {
  93. ret = regulator_set_enable(priv->reg, true);
  94. if (ret)
  95. return ret;
  96. }
  97. mdelay(10);
  98. /* reset panel */
  99. dm_gpio_set_value(&priv->reset, true);
  100. mdelay(10);
  101. dm_gpio_set_value(&priv->reset, false);
  102. /* fill characteristics of DSI data link */
  103. plat->lanes = 4;
  104. plat->format = MIPI_DSI_FMT_RGB888;
  105. plat->mode_flags = MIPI_DSI_MODE_VIDEO |
  106. MIPI_DSI_MODE_VIDEO_BURST |
  107. MIPI_DSI_MODE_LPM;
  108. return 0;
  109. }
  110. static const struct panel_ops tl070wsh30_panel_ops = {
  111. .enable_backlight = tl070wsh30_panel_enable_backlight,
  112. .get_display_timing = tl070wsh30_panel_get_display_timing,
  113. };
  114. static const struct udevice_id tl070wsh30_panel_ids[] = {
  115. { .compatible = "tdo,tl070wsh30" },
  116. { }
  117. };
  118. U_BOOT_DRIVER(tl070wsh30_panel) = {
  119. .name = "tl070wsh30_panel",
  120. .id = UCLASS_PANEL,
  121. .of_match = tl070wsh30_panel_ids,
  122. .ops = &tl070wsh30_panel_ops,
  123. .of_to_plat = tl070wsh30_panel_of_to_plat,
  124. .probe = tl070wsh30_panel_probe,
  125. .plat_auto = sizeof(struct mipi_dsi_panel_plat),
  126. .priv_auto = sizeof(struct tl070wsh30_panel_priv),
  127. };