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 #ifndef __VIDEO_BRIDGE
8 #define __VIDEO_BRIDGE
9
10 #include <asm/gpio.h>
11
12 /**
13 * struct video_bridge_priv - uclass information for video bridges
14 *
15 * @sleep: GPIO to assert to power down the bridge
16 * @reset: GPIO to assert to reset the bridge
17 * @hotplug: Optional GPIO to check if bridge is connected
18 */
19 struct video_bridge_priv {
20 struct gpio_desc sleep;
21 struct gpio_desc reset;
22 struct gpio_desc hotplug;
23 };
24
25 /**
26 * Operations for video bridges
27 */
28 struct video_bridge_ops {
29 /**
30 * attach() - attach a video bridge
31 *
32 * @return 0 if OK, -ve on error
33 */
34 int (*attach)(struct udevice *dev);
35
36 /**
37 * check_attached() - check if a bridge is correctly attached
38 *
39 * This method is optional - if not provided then the hotplug GPIO
40 * will be checked instead.
41 *
42 * @dev: Device to check
43 * @return 0 if attached, -EENOTCONN if not, or other -ve error
44 */
45 int (*check_attached)(struct udevice *dev);
46
47 /**
48 * set_backlight() - Set the backlight brightness
49 *
50 * @dev: device to adjust
51 * @percent: brightness percentage (0=off, 100=full brightness)
52 * @return 0 if OK, -ve on error
53 */
54 int (*set_backlight)(struct udevice *dev, int percent);
55
56 /**
57 * get_display_timing() - Get display timings from bridge.
58 *
59 * @dev: Bridge device containing the linked display timings
60 * @tim: Place to put timings
61 * @return 0 if OK, -ve on error
62 *
63 * This call it totally optional and useful mainly for integrated
64 * bridges with fixed output device.
65 */
66 int (*get_display_timing)(struct udevice *dev,
67 struct display_timing *timing);
68
69 /**
70 * read_edid() - Read information from EDID
71 *
72 * @dev: Device to read from
73 * @buf: Buffer to read into
74 * @buf_size: Buffer size
75 * @return number of bytes read, <=0 for error
76 */
77 int (*read_edid)(struct udevice *dev, u8 *buf, int buf_size);
78 };
79
80 #define video_bridge_get_ops(dev) \
81 ((struct video_bridge_ops *)(dev)->driver->ops)
82
83 #if CONFIG_IS_ENABLED(VIDEO_BRIDGE)
84 /**
85 * video_bridge_attach() - attach a video bridge
86 *
87 * Return: 0 if OK, -ve on error
88 */
89 int video_bridge_attach(struct udevice *dev);
90
91 /**
92 * video_bridge_set_backlight() - Set the backlight brightness
93 *
94 * @percent: brightness percentage (0=off, 100=full brightness)
95 * Return: 0 if OK, -ve on error
96 */
97 int video_bridge_set_backlight(struct udevice *dev, int percent);
98
99 /**
100 * video_bridge_set_active() - take the bridge in/out of reset/powerdown
101 *
102 * @dev: Device to adjust
103 * @active: true to power up and reset, false to power down
104 */
105 int video_bridge_set_active(struct udevice *dev, bool active);
106
107 /**
108 * check_attached() - check if a bridge is correctly attached
109 *
110 * @dev: Device to check
111 * Return: 0 if attached, -EENOTCONN if not, or other -ve error
112 */
113 int video_bridge_check_attached(struct udevice *dev);
114
115 /**
116 * video_bridge_get_display_timing() - Get display timings from bridge.
117 *
118 * @dev: Bridge device containing the linked display timings
119 * Return: 0 if OK, -ve on error
120 */
121 int video_bridge_get_display_timing(struct udevice *dev,
122 struct display_timing *timing);
123 /**
124 * video_bridge_read_edid() - Read information from EDID
125 *
126 * @dev: Device to read from
127 * @buf: Buffer to read into
128 * @buf_size: Buffer size
129 * Return: number of bytes read, <=0 for error
130 */
131 int video_bridge_read_edid(struct udevice *dev, u8 *buf, int buf_size);
132 #else
video_bridge_attach(struct udevice * dev)133 static inline int video_bridge_attach(struct udevice *dev)
134 {
135 return -ENOSYS;
136 }
137
video_bridge_set_backlight(struct udevice * dev,int percent)138 static inline int video_bridge_set_backlight(struct udevice *dev, int percent)
139 {
140 return -ENOSYS;
141 }
142
video_bridge_set_active(struct udevice * dev,bool active)143 static inline int video_bridge_set_active(struct udevice *dev, bool active)
144 {
145 return -ENOSYS;
146 }
147
video_bridge_check_attached(struct udevice * dev)148 static inline int video_bridge_check_attached(struct udevice *dev)
149 {
150 return -ENOSYS;
151 }
152
video_bridge_get_display_timing(struct udevice * dev,struct display_timing * timing)153 static inline int video_bridge_get_display_timing(struct udevice *dev,
154 struct display_timing *timing)
155 {
156 return -ENOSYS;
157 }
158
video_bridge_read_edid(struct udevice * dev,u8 * buf,int buf_size)159 static inline int video_bridge_read_edid(struct udevice *dev, u8 *buf, int buf_size)
160 {
161 return -ENOSYS;
162 }
163 #endif /* CONFIG_VIDEO_BRIDGE */
164
165 #endif
166