blob: f389bc6b14753613f14e41e5a06adbc3242d4767 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass7cf17572015-07-02 18:16:08 -06002/*
3 * Copyright (C) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glass7cf17572015-07-02 18:16:08 -06005 */
6
Patrick Delaunay81313352021-04-27 11:02:19 +02007#define LOG_CATEGORY UCLASS_VIDEO_BRIDGE
8
Simon Glass7cf17572015-07-02 18:16:08 -06009#include <common.h>
10#include <dm.h>
11#include <errno.h>
Vasily Khoruzhick82e9a5a2017-09-20 23:29:07 -070012#include <edid.h>
Simon Glass0f2af882020-05-10 11:40:05 -060013#include <log.h>
Simon Glass7cf17572015-07-02 18:16:08 -060014#include <video_bridge.h>
Simon Glassdbd79542020-05-10 11:40:11 -060015#include <linux/delay.h>
Simon Glass7cf17572015-07-02 18:16:08 -060016
17int video_bridge_set_backlight(struct udevice *dev, int percent)
18{
19 struct video_bridge_ops *ops = video_bridge_get_ops(dev);
20
21 if (!ops->set_backlight)
22 return -ENOSYS;
23
24 return ops->set_backlight(dev, percent);
25}
26
27int video_bridge_attach(struct udevice *dev)
28{
29 struct video_bridge_ops *ops = video_bridge_get_ops(dev);
30
31 if (!ops->attach)
32 return -ENOSYS;
33
34 return ops->attach(dev);
35}
36
37int video_bridge_check_attached(struct udevice *dev)
38{
39 struct video_bridge_priv *uc_priv = dev_get_uclass_priv(dev);
40 struct video_bridge_ops *ops = video_bridge_get_ops(dev);
41 int ret;
42
43 if (!ops->check_attached) {
44 ret = dm_gpio_get_value(&uc_priv->hotplug);
45
46 return ret > 0 ? 0 : ret == 0 ? -ENOTCONN : ret;
47 }
48
49 return ops->check_attached(dev);
50}
51
Vasily Khoruzhick82e9a5a2017-09-20 23:29:07 -070052int video_bridge_read_edid(struct udevice *dev, u8 *buf, int buf_size)
53{
54 struct video_bridge_ops *ops = video_bridge_get_ops(dev);
55
56 if (!ops || !ops->read_edid)
57 return -ENOSYS;
58 return ops->read_edid(dev, buf, buf_size);
59}
60
Simon Glass7cf17572015-07-02 18:16:08 -060061static int video_bridge_pre_probe(struct udevice *dev)
62{
63 struct video_bridge_priv *uc_priv = dev_get_uclass_priv(dev);
64 int ret;
65
66 debug("%s\n", __func__);
67 ret = gpio_request_by_name(dev, "sleep-gpios", 0,
68 &uc_priv->sleep, GPIOD_IS_OUT);
69 if (ret) {
70 debug("%s: Could not decode sleep-gpios (%d)\n", __func__, ret);
Simon Glass661d5de2016-01-21 19:44:53 -070071 if (ret != -ENOENT)
72 return ret;
Simon Glass7cf17572015-07-02 18:16:08 -060073 }
Simon Glassbe72e332015-08-03 08:19:20 -060074 /*
75 * Drop this for now as we do not have driver model pinctrl support
76 *
77 * ret = dm_gpio_set_pull(&uc_priv->sleep, GPIO_PULL_NONE);
78 * if (ret) {
79 * debug("%s: Could not set sleep pull value\n", __func__);
80 * return ret;
81 * }
82 */
Simon Glass7cf17572015-07-02 18:16:08 -060083 ret = gpio_request_by_name(dev, "reset-gpios", 0, &uc_priv->reset,
84 GPIOD_IS_OUT);
85 if (ret) {
86 debug("%s: Could not decode reset-gpios (%d)\n", __func__, ret);
Simon Glass661d5de2016-01-21 19:44:53 -070087 if (ret != -ENOENT)
88 return ret;
Simon Glass7cf17572015-07-02 18:16:08 -060089 }
Simon Glassbe72e332015-08-03 08:19:20 -060090 /*
91 * Drop this for now as we do not have driver model pinctrl support
92 *
93 * ret = dm_gpio_set_pull(&uc_priv->reset, GPIO_PULL_NONE);
94 * if (ret) {
95 * debug("%s: Could not set reset pull value\n", __func__);
96 * return ret;
97 * }
98 */
Simon Glass7cf17572015-07-02 18:16:08 -060099 ret = gpio_request_by_name(dev, "hotplug-gpios", 0, &uc_priv->hotplug,
100 GPIOD_IS_IN);
Simon Glass661d5de2016-01-21 19:44:53 -0700101 if (ret) {
Simon Glass7cf17572015-07-02 18:16:08 -0600102 debug("%s: Could not decode hotplug (%d)\n", __func__, ret);
Simon Glass661d5de2016-01-21 19:44:53 -0700103 if (ret != -ENOENT)
104 return ret;
Simon Glass7cf17572015-07-02 18:16:08 -0600105 }
106
107 return 0;
108}
109
110int video_bridge_set_active(struct udevice *dev, bool active)
111{
112 struct video_bridge_priv *uc_priv = dev_get_uclass_priv(dev);
Vasily Khoruzhicke0b22602018-11-05 20:24:29 -0800113 int ret = 0;
Simon Glass7cf17572015-07-02 18:16:08 -0600114
115 debug("%s: %d\n", __func__, active);
Vasily Khoruzhicke0b22602018-11-05 20:24:29 -0800116 if (uc_priv->sleep.dev) {
117 ret = dm_gpio_set_value(&uc_priv->sleep, !active);
118 if (ret)
119 return ret;
120 }
121
122 if (!active)
123 return 0;
124
125 if (uc_priv->reset.dev) {
Simon Glass7cf17572015-07-02 18:16:08 -0600126 ret = dm_gpio_set_value(&uc_priv->reset, true);
127 if (ret)
128 return ret;
129 udelay(10);
130 ret = dm_gpio_set_value(&uc_priv->reset, false);
131 }
132
133 return ret;
134}
135
136UCLASS_DRIVER(video_bridge) = {
137 .id = UCLASS_VIDEO_BRIDGE,
138 .name = "video_bridge",
Simon Glass8a2b47f2020-12-03 16:55:17 -0700139 .per_device_auto = sizeof(struct video_bridge_priv),
Simon Glass7cf17572015-07-02 18:16:08 -0600140 .pre_probe = video_bridge_pre_probe,
141};