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