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