simple_panel.c 3.0 KB

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