blob: 389b02cdcba2c75a81b9a6cacd23fa66900dd075 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass801ab9e2015-07-02 18:16:08 -06002/*
3 * Copyright (C) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glass801ab9e2015-07-02 18:16:08 -06005 */
6
7#include <common.h>
8#include <dm.h>
9#include <errno.h>
Vasily Khoruzhickfdb55252017-09-20 23:29:07 -070010#include <edid.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060011#include <log.h>
Simon Glass801ab9e2015-07-02 18:16:08 -060012#include <video_bridge.h>
Simon Glassc05ed002020-05-10 11:40:11 -060013#include <linux/delay.h>
Simon Glass801ab9e2015-07-02 18:16:08 -060014
15int video_bridge_set_backlight(struct udevice *dev, int percent)
16{
17 struct video_bridge_ops *ops = video_bridge_get_ops(dev);
18
19 if (!ops->set_backlight)
20 return -ENOSYS;
21
22 return ops->set_backlight(dev, percent);
23}
24
25int video_bridge_attach(struct udevice *dev)
26{
27 struct video_bridge_ops *ops = video_bridge_get_ops(dev);
28
29 if (!ops->attach)
30 return -ENOSYS;
31
32 return ops->attach(dev);
33}
34
35int video_bridge_check_attached(struct udevice *dev)
36{
37 struct video_bridge_priv *uc_priv = dev_get_uclass_priv(dev);
38 struct video_bridge_ops *ops = video_bridge_get_ops(dev);
39 int ret;
40
41 if (!ops->check_attached) {
42 ret = dm_gpio_get_value(&uc_priv->hotplug);
43
44 return ret > 0 ? 0 : ret == 0 ? -ENOTCONN : ret;
45 }
46
47 return ops->check_attached(dev);
48}
49
Vasily Khoruzhickfdb55252017-09-20 23:29:07 -070050int video_bridge_read_edid(struct udevice *dev, u8 *buf, int buf_size)
51{
52 struct video_bridge_ops *ops = video_bridge_get_ops(dev);
53
54 if (!ops || !ops->read_edid)
55 return -ENOSYS;
56 return ops->read_edid(dev, buf, buf_size);
57}
58
Simon Glass801ab9e2015-07-02 18:16:08 -060059static int video_bridge_pre_probe(struct udevice *dev)
60{
61 struct video_bridge_priv *uc_priv = dev_get_uclass_priv(dev);
62 int ret;
63
64 debug("%s\n", __func__);
65 ret = gpio_request_by_name(dev, "sleep-gpios", 0,
66 &uc_priv->sleep, GPIOD_IS_OUT);
67 if (ret) {
68 debug("%s: Could not decode sleep-gpios (%d)\n", __func__, ret);
Simon Glassd4bf91a2016-01-21 19:44:53 -070069 if (ret != -ENOENT)
70 return ret;
Simon Glass801ab9e2015-07-02 18:16:08 -060071 }
Simon Glass5eaeada2015-08-03 08:19:20 -060072 /*
73 * Drop this for now as we do not have driver model pinctrl support
74 *
75 * ret = dm_gpio_set_pull(&uc_priv->sleep, GPIO_PULL_NONE);
76 * if (ret) {
77 * debug("%s: Could not set sleep pull value\n", __func__);
78 * return ret;
79 * }
80 */
Simon Glass801ab9e2015-07-02 18:16:08 -060081 ret = gpio_request_by_name(dev, "reset-gpios", 0, &uc_priv->reset,
82 GPIOD_IS_OUT);
83 if (ret) {
84 debug("%s: Could not decode reset-gpios (%d)\n", __func__, ret);
Simon Glassd4bf91a2016-01-21 19:44:53 -070085 if (ret != -ENOENT)
86 return ret;
Simon Glass801ab9e2015-07-02 18:16:08 -060087 }
Simon Glass5eaeada2015-08-03 08:19:20 -060088 /*
89 * Drop this for now as we do not have driver model pinctrl support
90 *
91 * ret = dm_gpio_set_pull(&uc_priv->reset, GPIO_PULL_NONE);
92 * if (ret) {
93 * debug("%s: Could not set reset pull value\n", __func__);
94 * return ret;
95 * }
96 */
Simon Glass801ab9e2015-07-02 18:16:08 -060097 ret = gpio_request_by_name(dev, "hotplug-gpios", 0, &uc_priv->hotplug,
98 GPIOD_IS_IN);
Simon Glassd4bf91a2016-01-21 19:44:53 -070099 if (ret) {
Simon Glass801ab9e2015-07-02 18:16:08 -0600100 debug("%s: Could not decode hotplug (%d)\n", __func__, ret);
Simon Glassd4bf91a2016-01-21 19:44:53 -0700101 if (ret != -ENOENT)
102 return ret;
Simon Glass801ab9e2015-07-02 18:16:08 -0600103 }
104
105 return 0;
106}
107
108int video_bridge_set_active(struct udevice *dev, bool active)
109{
110 struct video_bridge_priv *uc_priv = dev_get_uclass_priv(dev);
Vasily Khoruzhick8336a432018-11-05 20:24:29 -0800111 int ret = 0;
Simon Glass801ab9e2015-07-02 18:16:08 -0600112
113 debug("%s: %d\n", __func__, active);
Vasily Khoruzhick8336a432018-11-05 20:24:29 -0800114 if (uc_priv->sleep.dev) {
115 ret = dm_gpio_set_value(&uc_priv->sleep, !active);
116 if (ret)
117 return ret;
118 }
119
120 if (!active)
121 return 0;
122
123 if (uc_priv->reset.dev) {
Simon Glass801ab9e2015-07-02 18:16:08 -0600124 ret = dm_gpio_set_value(&uc_priv->reset, true);
125 if (ret)
126 return ret;
127 udelay(10);
128 ret = dm_gpio_set_value(&uc_priv->reset, false);
129 }
130
131 return ret;
132}
133
134UCLASS_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,
139};