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