video-bridge-uclass.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2015 Google, Inc
  4. * Written by Simon Glass <sjg@chromium.org>
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <errno.h>
  9. #include <edid.h>
  10. #include <video_bridge.h>
  11. int video_bridge_set_backlight(struct udevice *dev, int percent)
  12. {
  13. struct video_bridge_ops *ops = video_bridge_get_ops(dev);
  14. if (!ops->set_backlight)
  15. return -ENOSYS;
  16. return ops->set_backlight(dev, percent);
  17. }
  18. int video_bridge_attach(struct udevice *dev)
  19. {
  20. struct video_bridge_ops *ops = video_bridge_get_ops(dev);
  21. if (!ops->attach)
  22. return -ENOSYS;
  23. return ops->attach(dev);
  24. }
  25. int video_bridge_check_attached(struct udevice *dev)
  26. {
  27. struct video_bridge_priv *uc_priv = dev_get_uclass_priv(dev);
  28. struct video_bridge_ops *ops = video_bridge_get_ops(dev);
  29. int ret;
  30. if (!ops->check_attached) {
  31. ret = dm_gpio_get_value(&uc_priv->hotplug);
  32. return ret > 0 ? 0 : ret == 0 ? -ENOTCONN : ret;
  33. }
  34. return ops->check_attached(dev);
  35. }
  36. int video_bridge_read_edid(struct udevice *dev, u8 *buf, int buf_size)
  37. {
  38. struct video_bridge_ops *ops = video_bridge_get_ops(dev);
  39. if (!ops || !ops->read_edid)
  40. return -ENOSYS;
  41. return ops->read_edid(dev, buf, buf_size);
  42. }
  43. static int video_bridge_pre_probe(struct udevice *dev)
  44. {
  45. struct video_bridge_priv *uc_priv = dev_get_uclass_priv(dev);
  46. int ret;
  47. debug("%s\n", __func__);
  48. ret = gpio_request_by_name(dev, "sleep-gpios", 0,
  49. &uc_priv->sleep, GPIOD_IS_OUT);
  50. if (ret) {
  51. debug("%s: Could not decode sleep-gpios (%d)\n", __func__, ret);
  52. if (ret != -ENOENT)
  53. return ret;
  54. }
  55. /*
  56. * Drop this for now as we do not have driver model pinctrl support
  57. *
  58. * ret = dm_gpio_set_pull(&uc_priv->sleep, GPIO_PULL_NONE);
  59. * if (ret) {
  60. * debug("%s: Could not set sleep pull value\n", __func__);
  61. * return ret;
  62. * }
  63. */
  64. ret = gpio_request_by_name(dev, "reset-gpios", 0, &uc_priv->reset,
  65. GPIOD_IS_OUT);
  66. if (ret) {
  67. debug("%s: Could not decode reset-gpios (%d)\n", __func__, ret);
  68. if (ret != -ENOENT)
  69. return ret;
  70. }
  71. /*
  72. * Drop this for now as we do not have driver model pinctrl support
  73. *
  74. * ret = dm_gpio_set_pull(&uc_priv->reset, GPIO_PULL_NONE);
  75. * if (ret) {
  76. * debug("%s: Could not set reset pull value\n", __func__);
  77. * return ret;
  78. * }
  79. */
  80. ret = gpio_request_by_name(dev, "hotplug-gpios", 0, &uc_priv->hotplug,
  81. GPIOD_IS_IN);
  82. if (ret) {
  83. debug("%s: Could not decode hotplug (%d)\n", __func__, ret);
  84. if (ret != -ENOENT)
  85. return ret;
  86. }
  87. return 0;
  88. }
  89. int video_bridge_set_active(struct udevice *dev, bool active)
  90. {
  91. struct video_bridge_priv *uc_priv = dev_get_uclass_priv(dev);
  92. int ret;
  93. debug("%s: %d\n", __func__, active);
  94. ret = dm_gpio_set_value(&uc_priv->sleep, !active);
  95. if (ret)
  96. return ret;
  97. if (active) {
  98. ret = dm_gpio_set_value(&uc_priv->reset, true);
  99. if (ret)
  100. return ret;
  101. udelay(10);
  102. ret = dm_gpio_set_value(&uc_priv->reset, false);
  103. }
  104. return ret;
  105. }
  106. UCLASS_DRIVER(video_bridge) = {
  107. .id = UCLASS_VIDEO_BRIDGE,
  108. .name = "video_bridge",
  109. .per_device_auto_alloc_size = sizeof(struct video_bridge_priv),
  110. .pre_probe = video_bridge_pre_probe,
  111. };