projects/linux·blob master · refs

230 lines · 6.2 KiB

1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __DRM_OF_H__
3#define __DRM_OF_H__
4
5#include <linux/err.h>
6#include <linux/of_graph.h>
7#if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE)
8#include <linux/of.h>
9#include <drm/drm_bridge.h>
10#endif
11
12struct component_master_ops;
13struct component_match;
14struct device;
15struct drm_device;
16struct drm_encoder;
17struct drm_panel;
18struct drm_bridge;
19struct device_node;
20struct mipi_dsi_device_info;
21struct mipi_dsi_host;
22
23enum drm_panel_orientation;
24
25/**
26 * enum drm_lvds_dual_link_pixels - Pixel order of an LVDS dual-link connection
27 * @DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS: Even pixels are expected to be generated
28 * from the first port, odd pixels from the second port
29 * @DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS: Odd pixels are expected to be generated
30 * from the first port, even pixels from the second port
31 */
32enum drm_lvds_dual_link_pixels {
33 DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS = 0,
34 DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS = 1,
35};
36
37#ifdef CONFIG_OF
38uint32_t drm_of_crtc_port_mask(struct drm_device *dev,
39 struct device_node *port);
40uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
41 struct device_node *port);
42void drm_of_component_match_add(struct device *master,
43 struct component_match **matchptr,
44 int (*compare)(struct device *, void *),
45 struct device_node *node);
46int drm_of_component_probe(struct device *dev,
47 int (*compare_of)(struct device *, void *),
48 const struct component_master_ops *m_ops);
49int drm_of_encoder_active_endpoint(struct device_node *node,
50 struct drm_encoder *encoder,
51 struct of_endpoint *endpoint);
52int drm_of_get_panel_orientation(const struct device_node *np,
53 enum drm_panel_orientation *orientation);
54int drm_of_find_panel_or_bridge(const struct device_node *np,
55 int port, int endpoint,
56 struct drm_panel **panel,
57 struct drm_bridge **bridge);
58int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
59 const struct device_node *port2);
60int drm_of_lvds_get_dual_link_pixel_order_sink(struct device_node *port1,
61 struct device_node *port2);
62int drm_of_lvds_get_data_mapping(const struct device_node *port);
63int drm_of_get_data_lanes_count(const struct device_node *endpoint,
64 const unsigned int min, const unsigned int max);
65int drm_of_get_data_lanes_count_ep(const struct device_node *port,
66 int port_reg, int reg,
67 const unsigned int min,
68 const unsigned int max);
69int drm_of_get_data_lanes_count_remote(const struct device_node *port,
70 int port_reg, int reg,
71 const unsigned int min,
72 const unsigned int max);
73#else
74static inline uint32_t drm_of_crtc_port_mask(struct drm_device *dev,
75 struct device_node *port)
76{
77 return 0;
78}
79
80static inline uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
81 struct device_node *port)
82{
83 return 0;
84}
85
86static inline void
87drm_of_component_match_add(struct device *master,
88 struct component_match **matchptr,
89 int (*compare)(struct device *, void *),
90 struct device_node *node)
91{
92}
93
94static inline int
95drm_of_component_probe(struct device *dev,
96 int (*compare_of)(struct device *, void *),
97 const struct component_master_ops *m_ops)
98{
99 return -EINVAL;
100}
101
102static inline int drm_of_encoder_active_endpoint(struct device_node *node,
103 struct drm_encoder *encoder,
104 struct of_endpoint *endpoint)
105{
106 return -EINVAL;
107}
108
109static inline int drm_of_get_panel_orientation(const struct device_node *np,
110 enum drm_panel_orientation *orientation)
111{
112 return -EINVAL;
113}
114
115static inline int drm_of_find_panel_or_bridge(const struct device_node *np,
116 int port, int endpoint,
117 struct drm_panel **panel,
118 struct drm_bridge **bridge)
119{
120 return -EINVAL;
121}
122
123static inline int
124drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
125 const struct device_node *port2)
126{
127 return -EINVAL;
128}
129
130static inline int
131drm_of_lvds_get_dual_link_pixel_order_sink(struct device_node *port1,
132 struct device_node *port2)
133{
134 return -EINVAL;
135}
136
137static inline int
138drm_of_lvds_get_data_mapping(const struct device_node *port)
139{
140 return -EINVAL;
141}
142
143static inline int
144drm_of_get_data_lanes_count(const struct device_node *endpoint,
145 const unsigned int min, const unsigned int max)
146{
147 return -EINVAL;
148}
149
150static inline int
151drm_of_get_data_lanes_count_ep(const struct device_node *port,
152 int port_reg, int reg,
153 const unsigned int min,
154 const unsigned int max)
155{
156 return -EINVAL;
157}
158
159static inline int
160drm_of_get_data_lanes_count_remote(const struct device_node *port,
161 int port_reg, int reg,
162 const unsigned int min,
163 const unsigned int max)
164{
165 return -EINVAL;
166}
167#endif
168
169#if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_MIPI_DSI)
170struct mipi_dsi_host *drm_of_get_dsi_bus(struct device *dev);
171#else
172static inline struct
173mipi_dsi_host *drm_of_get_dsi_bus(struct device *dev)
174{
175 return ERR_PTR(-EINVAL);
176}
177#endif /* CONFIG_OF && CONFIG_DRM_MIPI_DSI */
178
179/*
180 * drm_of_panel_bridge_remove - remove panel bridge
181 * @np: device tree node containing panel bridge output ports
182 *
183 * Remove the panel bridge of a given DT node's port and endpoint number
184 *
185 * Returns zero if successful, or one of the standard error codes if it fails.
186 */
187static inline int drm_of_panel_bridge_remove(const struct device_node *np,
188 int port, int endpoint)
189{
190#if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE)
191 struct drm_bridge *bridge;
192 struct device_node *remote;
193
194 remote = of_graph_get_remote_node(np, port, endpoint);
195 if (!remote)
196 return -ENODEV;
197
198 bridge = of_drm_find_and_get_bridge(remote);
199 drm_panel_bridge_remove(bridge);
200
201 drm_bridge_put(bridge);
202 of_node_put(remote);
203
204 return 0;
205#else
206 return -EINVAL;
207#endif
208}
209
210static inline int drm_of_encoder_active_endpoint_id(struct device_node *node,
211 struct drm_encoder *encoder)
212{
213 struct of_endpoint endpoint;
214 int ret = drm_of_encoder_active_endpoint(node, encoder,
215 &endpoint);
216
217 return ret ?: endpoint.id;
218}
219
220static inline int drm_of_encoder_active_port_id(struct device_node *node,
221 struct drm_encoder *encoder)
222{
223 struct of_endpoint endpoint;
224 int ret = drm_of_encoder_active_endpoint(node, encoder,
225 &endpoint);
226
227 return ret ?: endpoint.port;
228}
229
230#endif /* __DRM_OF_H__ */