simple_panel.c 2.5 KB

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