1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
12 #include <video_bridge.h>
13 #include <linux/delay.h>
15 int video_bridge_set_backlight(struct udevice *dev, int percent)
17 struct video_bridge_ops *ops = video_bridge_get_ops(dev);
19 if (!ops->set_backlight)
22 return ops->set_backlight(dev, percent);
25 int video_bridge_attach(struct udevice *dev)
27 struct video_bridge_ops *ops = video_bridge_get_ops(dev);
32 return ops->attach(dev);
35 int video_bridge_check_attached(struct udevice *dev)
37 struct video_bridge_priv *uc_priv = dev_get_uclass_priv(dev);
38 struct video_bridge_ops *ops = video_bridge_get_ops(dev);
41 if (!ops->check_attached) {
42 ret = dm_gpio_get_value(&uc_priv->hotplug);
44 return ret > 0 ? 0 : ret == 0 ? -ENOTCONN : ret;
47 return ops->check_attached(dev);
50 int video_bridge_read_edid(struct udevice *dev, u8 *buf, int buf_size)
52 struct video_bridge_ops *ops = video_bridge_get_ops(dev);
54 if (!ops || !ops->read_edid)
56 return ops->read_edid(dev, buf, buf_size);
59 static int video_bridge_pre_probe(struct udevice *dev)
61 struct video_bridge_priv *uc_priv = dev_get_uclass_priv(dev);
64 debug("%s\n", __func__);
65 ret = gpio_request_by_name(dev, "sleep-gpios", 0,
66 &uc_priv->sleep, GPIOD_IS_OUT);
68 debug("%s: Could not decode sleep-gpios (%d)\n", __func__, ret);
73 * Drop this for now as we do not have driver model pinctrl support
75 * ret = dm_gpio_set_pull(&uc_priv->sleep, GPIO_PULL_NONE);
77 * debug("%s: Could not set sleep pull value\n", __func__);
81 ret = gpio_request_by_name(dev, "reset-gpios", 0, &uc_priv->reset,
84 debug("%s: Could not decode reset-gpios (%d)\n", __func__, ret);
89 * Drop this for now as we do not have driver model pinctrl support
91 * ret = dm_gpio_set_pull(&uc_priv->reset, GPIO_PULL_NONE);
93 * debug("%s: Could not set reset pull value\n", __func__);
97 ret = gpio_request_by_name(dev, "hotplug-gpios", 0, &uc_priv->hotplug,
100 debug("%s: Could not decode hotplug (%d)\n", __func__, ret);
108 int video_bridge_set_active(struct udevice *dev, bool active)
110 struct video_bridge_priv *uc_priv = dev_get_uclass_priv(dev);
113 debug("%s: %d\n", __func__, active);
114 if (uc_priv->sleep.dev) {
115 ret = dm_gpio_set_value(&uc_priv->sleep, !active);
123 if (uc_priv->reset.dev) {
124 ret = dm_gpio_set_value(&uc_priv->reset, true);
128 ret = dm_gpio_set_value(&uc_priv->reset, false);
134 UCLASS_DRIVER(video_bridge) = {
135 .id = UCLASS_VIDEO_BRIDGE,
136 .name = "video_bridge",
137 .per_device_auto_alloc_size = sizeof(struct video_bridge_priv),
138 .pre_probe = video_bridge_pre_probe,