1 #ifndef __DRM_OF_H__
2 #define __DRM_OF_H__
3
4 #include <linux/of_graph.h>
5 #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE)
6 #include <drm/drm_bridge.h>
7 #endif
8
9 struct component_master_ops;
10 struct component_match;
11 struct device;
12 struct drm_device;
13 struct drm_encoder;
14 struct drm_panel;
15 struct drm_bridge;
16 struct device_node;
17
18 #ifdef CONFIG_OF
19 uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
20 struct device_node *port);
21 void drm_of_component_match_add(struct device *master,
22 struct component_match **matchptr,
23 int (*compare)(struct device *, void *),
24 struct device_node *node);
25 int drm_of_component_probe(struct device *dev,
26 int (*compare_of)(struct device *, void *),
27 const struct component_master_ops *m_ops);
28 int drm_of_encoder_active_endpoint(struct device_node *node,
29 struct drm_encoder *encoder,
30 struct of_endpoint *endpoint);
31 int drm_of_find_panel_or_bridge(const struct device_node *np,
32 int port, int endpoint,
33 struct drm_panel **panel,
34 struct drm_bridge **bridge);
35 #else
drm_of_find_possible_crtcs(struct drm_device * dev,struct device_node * port)36 static inline uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
37 struct device_node *port)
38 {
39 return 0;
40 }
41
42 static inline void
drm_of_component_match_add(struct device * master,struct component_match ** matchptr,int (* compare)(struct device *,void *),struct device_node * node)43 drm_of_component_match_add(struct device *master,
44 struct component_match **matchptr,
45 int (*compare)(struct device *, void *),
46 struct device_node *node)
47 {
48 }
49
50 static inline int
drm_of_component_probe(struct device * dev,int (* compare_of)(struct device *,void *),const struct component_master_ops * m_ops)51 drm_of_component_probe(struct device *dev,
52 int (*compare_of)(struct device *, void *),
53 const struct component_master_ops *m_ops)
54 {
55 return -EINVAL;
56 }
57
drm_of_encoder_active_endpoint(struct device_node * node,struct drm_encoder * encoder,struct of_endpoint * endpoint)58 static inline int drm_of_encoder_active_endpoint(struct device_node *node,
59 struct drm_encoder *encoder,
60 struct of_endpoint *endpoint)
61 {
62 return -EINVAL;
63 }
drm_of_find_panel_or_bridge(const struct device_node * np,int port,int endpoint,struct drm_panel ** panel,struct drm_bridge ** bridge)64 static inline int drm_of_find_panel_or_bridge(const struct device_node *np,
65 int port, int endpoint,
66 struct drm_panel **panel,
67 struct drm_bridge **bridge)
68 {
69 return -EINVAL;
70 }
71 #endif
72
73 /*
74 * drm_of_panel_bridge_remove - remove panel bridge
75 * @np: device tree node containing panel bridge output ports
76 *
77 * Remove the panel bridge of a given DT node's port and endpoint number
78 *
79 * Returns zero if successful, or one of the standard error codes if it fails.
80 */
drm_of_panel_bridge_remove(const struct device_node * np,int port,int endpoint)81 static inline int drm_of_panel_bridge_remove(const struct device_node *np,
82 int port, int endpoint)
83 {
84 #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE)
85 struct drm_bridge *bridge;
86 struct device_node *remote;
87
88 remote = of_graph_get_remote_node(np, port, endpoint);
89 if (!remote)
90 return -ENODEV;
91
92 bridge = of_drm_find_bridge(remote);
93 drm_panel_bridge_remove(bridge);
94
95 return 0;
96 #else
97 return -EINVAL;
98 #endif
99 }
100
drm_of_encoder_active_endpoint_id(struct device_node * node,struct drm_encoder * encoder)101 static inline int drm_of_encoder_active_endpoint_id(struct device_node *node,
102 struct drm_encoder *encoder)
103 {
104 struct of_endpoint endpoint;
105 int ret = drm_of_encoder_active_endpoint(node, encoder,
106 &endpoint);
107
108 return ret ?: endpoint.id;
109 }
110
drm_of_encoder_active_port_id(struct device_node * node,struct drm_encoder * encoder)111 static inline int drm_of_encoder_active_port_id(struct device_node *node,
112 struct drm_encoder *encoder)
113 {
114 struct of_endpoint endpoint;
115 int ret = drm_of_encoder_active_endpoint(node, encoder,
116 &endpoint);
117
118 return ret ?: endpoint.port;
119 }
120
121 #endif /* __DRM_OF_H__ */
122