/src/u-boot/drivers/video/bridge/video-bridge-uclass.c
Line | Count | Source |
1 | | // SPDX-License-Identifier: GPL-2.0+ |
2 | | /* |
3 | | * Copyright (C) 2015 Google, Inc |
4 | | * Written by Simon Glass <sjg@chromium.org> |
5 | | */ |
6 | | |
7 | | #define LOG_CATEGORY UCLASS_VIDEO_BRIDGE |
8 | | |
9 | | #include <dm.h> |
10 | | #include <errno.h> |
11 | | #include <edid.h> |
12 | | #include <log.h> |
13 | | #include <video_bridge.h> |
14 | | #include <linux/delay.h> |
15 | | |
16 | | int video_bridge_set_backlight(struct udevice *dev, int percent) |
17 | 0 | { |
18 | 0 | struct video_bridge_ops *ops = video_bridge_get_ops(dev); |
19 | |
|
20 | 0 | if (!ops->set_backlight) |
21 | 0 | return -ENOSYS; |
22 | | |
23 | 0 | return ops->set_backlight(dev, percent); |
24 | 0 | } |
25 | | |
26 | | int video_bridge_attach(struct udevice *dev) |
27 | 0 | { |
28 | 0 | struct video_bridge_ops *ops = video_bridge_get_ops(dev); |
29 | |
|
30 | 0 | if (!ops->attach) |
31 | 0 | return -ENOSYS; |
32 | | |
33 | 0 | return ops->attach(dev); |
34 | 0 | } |
35 | | |
36 | | int video_bridge_get_display_timing(struct udevice *dev, |
37 | | struct display_timing *timings) |
38 | 0 | { |
39 | 0 | struct video_bridge_ops *ops = video_bridge_get_ops(dev); |
40 | |
|
41 | 0 | if (!ops->get_display_timing) |
42 | 0 | return -ENOSYS; |
43 | | |
44 | 0 | return ops->get_display_timing(dev, timings); |
45 | 0 | } |
46 | | |
47 | | int video_bridge_check_attached(struct udevice *dev) |
48 | 0 | { |
49 | 0 | struct video_bridge_priv *uc_priv = dev_get_uclass_priv(dev); |
50 | 0 | struct video_bridge_ops *ops = video_bridge_get_ops(dev); |
51 | 0 | int ret; |
52 | |
|
53 | 0 | if (!ops->check_attached) { |
54 | 0 | ret = dm_gpio_get_value(&uc_priv->hotplug); |
55 | |
|
56 | 0 | return ret > 0 ? 0 : ret == 0 ? -ENOTCONN : ret; |
57 | 0 | } |
58 | | |
59 | 0 | return ops->check_attached(dev); |
60 | 0 | } |
61 | | |
62 | | int video_bridge_read_edid(struct udevice *dev, u8 *buf, int buf_size) |
63 | 0 | { |
64 | 0 | struct video_bridge_ops *ops = video_bridge_get_ops(dev); |
65 | |
|
66 | 0 | if (!ops || !ops->read_edid) |
67 | 0 | return -ENOSYS; |
68 | 0 | return ops->read_edid(dev, buf, buf_size); |
69 | 0 | } |
70 | | |
71 | | static int video_bridge_pre_probe(struct udevice *dev) |
72 | 0 | { |
73 | 0 | struct video_bridge_priv *uc_priv = dev_get_uclass_priv(dev); |
74 | 0 | int ret; |
75 | |
|
76 | 0 | debug("%s\n", __func__); |
77 | 0 | ret = gpio_request_by_name(dev, "sleep-gpios", 0, |
78 | 0 | &uc_priv->sleep, GPIOD_IS_OUT); |
79 | 0 | if (ret) { |
80 | 0 | debug("%s: Could not decode sleep-gpios (%d)\n", __func__, ret); |
81 | 0 | if (ret != -ENOENT) |
82 | 0 | return ret; |
83 | 0 | } |
84 | | /* |
85 | | * Drop this for now as we do not have driver model pinctrl support |
86 | | * |
87 | | * ret = dm_gpio_set_pull(&uc_priv->sleep, GPIO_PULL_NONE); |
88 | | * if (ret) { |
89 | | * debug("%s: Could not set sleep pull value\n", __func__); |
90 | | * return ret; |
91 | | * } |
92 | | */ |
93 | 0 | ret = gpio_request_by_name(dev, "reset-gpios", 0, &uc_priv->reset, |
94 | 0 | GPIOD_IS_OUT); |
95 | 0 | if (ret) { |
96 | 0 | debug("%s: Could not decode reset-gpios (%d)\n", __func__, ret); |
97 | 0 | if (ret != -ENOENT) |
98 | 0 | return ret; |
99 | 0 | } |
100 | | /* |
101 | | * Drop this for now as we do not have driver model pinctrl support |
102 | | * |
103 | | * ret = dm_gpio_set_pull(&uc_priv->reset, GPIO_PULL_NONE); |
104 | | * if (ret) { |
105 | | * debug("%s: Could not set reset pull value\n", __func__); |
106 | | * return ret; |
107 | | * } |
108 | | */ |
109 | 0 | ret = gpio_request_by_name(dev, "hotplug-gpios", 0, &uc_priv->hotplug, |
110 | 0 | GPIOD_IS_IN); |
111 | 0 | if (ret) { |
112 | 0 | debug("%s: Could not decode hotplug (%d)\n", __func__, ret); |
113 | 0 | if (ret != -ENOENT) |
114 | 0 | return ret; |
115 | 0 | } |
116 | | |
117 | 0 | return 0; |
118 | 0 | } |
119 | | |
120 | | int video_bridge_set_active(struct udevice *dev, bool active) |
121 | 0 | { |
122 | 0 | struct video_bridge_priv *uc_priv = dev_get_uclass_priv(dev); |
123 | 0 | int ret = 0; |
124 | |
|
125 | 0 | debug("%s: %d\n", __func__, active); |
126 | 0 | if (uc_priv->sleep.dev) { |
127 | 0 | ret = dm_gpio_set_value(&uc_priv->sleep, !active); |
128 | 0 | if (ret) |
129 | 0 | return ret; |
130 | 0 | } |
131 | | |
132 | 0 | if (!active) |
133 | 0 | return 0; |
134 | | |
135 | 0 | if (uc_priv->reset.dev) { |
136 | 0 | ret = dm_gpio_set_value(&uc_priv->reset, true); |
137 | 0 | if (ret) |
138 | 0 | return ret; |
139 | 0 | udelay(10); |
140 | 0 | ret = dm_gpio_set_value(&uc_priv->reset, false); |
141 | 0 | } |
142 | | |
143 | 0 | return ret; |
144 | 0 | } |
145 | | |
146 | | UCLASS_DRIVER(video_bridge) = { |
147 | | .id = UCLASS_VIDEO_BRIDGE, |
148 | | .name = "video_bridge", |
149 | | .per_device_auto = sizeof(struct video_bridge_priv), |
150 | | .pre_probe = video_bridge_pre_probe, |
151 | | }; |