simple_panel.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2016 Google, Inc
  4. * Written by Simon Glass <sjg@chromium.org>
  5. */
  6. #include <common.h>
  7. #include <backlight.h>
  8. #include <dm.h>
  9. #include <log.h>
  10. #include <panel.h>
  11. #include <asm/gpio.h>
  12. #include <power/regulator.h>
  13. struct simple_panel_priv {
  14. struct udevice *reg;
  15. struct udevice *backlight;
  16. struct gpio_desc enable;
  17. };
  18. static int simple_panel_enable_backlight(struct udevice *dev)
  19. {
  20. struct simple_panel_priv *priv = dev_get_priv(dev);
  21. int ret;
  22. debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name);
  23. dm_gpio_set_value(&priv->enable, 1);
  24. ret = backlight_enable(priv->backlight);
  25. debug("%s: done, ret = %d\n", __func__, ret);
  26. if (ret)
  27. return ret;
  28. return 0;
  29. }
  30. static int simple_panel_set_backlight(struct udevice *dev, int percent)
  31. {
  32. struct simple_panel_priv *priv = dev_get_priv(dev);
  33. int ret;
  34. debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name);
  35. dm_gpio_set_value(&priv->enable, 1);
  36. ret = backlight_set_brightness(priv->backlight, percent);
  37. debug("%s: done, ret = %d\n", __func__, ret);
  38. if (ret)
  39. return ret;
  40. return 0;
  41. }
  42. static int simple_panel_ofdata_to_platdata(struct udevice *dev)
  43. {
  44. struct simple_panel_priv *priv = dev_get_priv(dev);
  45. int ret;
  46. if (IS_ENABLED(CONFIG_DM_REGULATOR)) {
  47. ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev,
  48. "power-supply", &priv->reg);
  49. if (ret) {
  50. debug("%s: Warning: cannot get power supply: ret=%d\n",
  51. __func__, ret);
  52. if (ret != -ENOENT)
  53. return ret;
  54. }
  55. }
  56. ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev,
  57. "backlight", &priv->backlight);
  58. if (ret) {
  59. debug("%s: Cannot get backlight: ret=%d\n", __func__, ret);
  60. return log_ret(ret);
  61. }
  62. ret = gpio_request_by_name(dev, "enable-gpios", 0, &priv->enable,
  63. GPIOD_IS_OUT);
  64. if (ret) {
  65. debug("%s: Warning: cannot get enable GPIO: ret=%d\n",
  66. __func__, ret);
  67. if (ret != -ENOENT)
  68. return log_ret(ret);
  69. }
  70. return 0;
  71. }
  72. static int simple_panel_probe(struct udevice *dev)
  73. {
  74. struct simple_panel_priv *priv = dev_get_priv(dev);
  75. int ret;
  76. if (IS_ENABLED(CONFIG_DM_REGULATOR) && priv->reg) {
  77. debug("%s: Enable regulator '%s'\n", __func__, priv->reg->name);
  78. ret = regulator_set_enable(priv->reg, true);
  79. if (ret)
  80. return ret;
  81. }
  82. return 0;
  83. }
  84. static const struct panel_ops simple_panel_ops = {
  85. .enable_backlight = simple_panel_enable_backlight,
  86. .set_backlight = simple_panel_set_backlight,
  87. };
  88. static const struct udevice_id simple_panel_ids[] = {
  89. { .compatible = "simple-panel" },
  90. { .compatible = "auo,b133xtn01" },
  91. { .compatible = "auo,b116xw03" },
  92. { .compatible = "auo,b133htn01" },
  93. { .compatible = "boe,nv140fhmn49" },
  94. { .compatible = "lg,lb070wv8" },
  95. { }
  96. };
  97. U_BOOT_DRIVER(simple_panel) = {
  98. .name = "simple_panel",
  99. .id = UCLASS_PANEL,
  100. .of_match = simple_panel_ids,
  101. .ops = &simple_panel_ops,
  102. .ofdata_to_platdata = simple_panel_ofdata_to_platdata,
  103. .probe = simple_panel_probe,
  104. .priv_auto_alloc_size = sizeof(struct simple_panel_priv),
  105. };