simple_panel.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. dm_gpio_set_value(&priv->enable, 1);
  24. ret = backlight_enable(priv->backlight);
  25. if (ret)
  26. return ret;
  27. return 0;
  28. }
  29. static int simple_panel_ofdata_to_platdata(struct udevice *dev)
  30. {
  31. struct simple_panel_priv *priv = dev_get_priv(dev);
  32. int ret;
  33. if (IS_ENABLED(CONFIG_DM_REGULATOR)) {
  34. ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev,
  35. "power-supply", &priv->reg);
  36. if (ret) {
  37. debug("%s: Warning: cannot get power supply: ret=%d\n",
  38. __func__, ret);
  39. if (ret != -ENOENT)
  40. return ret;
  41. }
  42. }
  43. ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev,
  44. "backlight", &priv->backlight);
  45. if (ret) {
  46. debug("%s: Cannot get backlight: ret=%d\n", __func__, ret);
  47. return ret;
  48. }
  49. ret = gpio_request_by_name(dev, "enable-gpios", 0, &priv->enable,
  50. GPIOD_IS_OUT);
  51. if (ret) {
  52. debug("%s: Warning: cannot get enable GPIO: ret=%d\n",
  53. __func__, ret);
  54. if (ret != -ENOENT)
  55. return ret;
  56. }
  57. return 0;
  58. }
  59. static int simple_panel_probe(struct udevice *dev)
  60. {
  61. struct simple_panel_priv *priv = dev_get_priv(dev);
  62. int ret;
  63. if (IS_ENABLED(CONFIG_DM_REGULATOR) && priv->reg) {
  64. debug("%s: Enable regulator '%s'\n", __func__, priv->reg->name);
  65. ret = regulator_set_enable(priv->reg, true);
  66. if (ret)
  67. return ret;
  68. }
  69. return 0;
  70. }
  71. static const struct panel_ops simple_panel_ops = {
  72. .enable_backlight = simple_panel_enable_backlight,
  73. };
  74. static const struct udevice_id simple_panel_ids[] = {
  75. { .compatible = "simple-panel" },
  76. { .compatible = "auo,b133xtn01" },
  77. { .compatible = "auo,b116xw03" },
  78. { .compatible = "auo,b133htn01" },
  79. { }
  80. };
  81. U_BOOT_DRIVER(simple_panel) = {
  82. .name = "simple_panel",
  83. .id = UCLASS_PANEL,
  84. .of_match = simple_panel_ids,
  85. .ops = &simple_panel_ops,
  86. .ofdata_to_platdata = simple_panel_ofdata_to_platdata,
  87. .probe = simple_panel_probe,
  88. .priv_auto_alloc_size = sizeof(struct simple_panel_priv),
  89. };