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