xref: /openbmc/linux/include/drm/drm_of.h (revision 6529007522ded00b8912c079250620fa7a732166)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
27e435aadSRussell King #ifndef __DRM_OF_H__
37e435aadSRussell King #define __DRM_OF_H__
47e435aadSRussell King 
54cacf91fSPhilipp Zabel #include <linux/of_graph.h>
6512721a1SMaarten Lankhorst #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE)
7512721a1SMaarten Lankhorst #include <drm/drm_bridge.h>
8512721a1SMaarten Lankhorst #endif
94cacf91fSPhilipp Zabel 
10df785aa8SLiviu Dudau struct component_master_ops;
1197ac0e47SRussell King struct component_match;
12df785aa8SLiviu Dudau struct device;
137e435aadSRussell King struct drm_device;
144cacf91fSPhilipp Zabel struct drm_encoder;
151f2db303SRob Herring struct drm_panel;
161f2db303SRob Herring struct drm_bridge;
177e435aadSRussell King struct device_node;
187e435aadSRussell King 
19*65290075SFabrizio Castro /**
20*65290075SFabrizio Castro  * enum drm_lvds_dual_link_pixels - Pixel order of an LVDS dual-link connection
21*65290075SFabrizio Castro  * @DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS: Even pixels are expected to be generated
22*65290075SFabrizio Castro  *    from the first port, odd pixels from the second port
23*65290075SFabrizio Castro  * @DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS: Odd pixels are expected to be generated
24*65290075SFabrizio Castro  *    from the first port, even pixels from the second port
25*65290075SFabrizio Castro  */
26*65290075SFabrizio Castro enum drm_lvds_dual_link_pixels {
27*65290075SFabrizio Castro 	DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS = 0,
28*65290075SFabrizio Castro 	DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS = 1,
29*65290075SFabrizio Castro };
30*65290075SFabrizio Castro 
317e435aadSRussell King #ifdef CONFIG_OF
328b5f7a62SJernej Skrabec uint32_t drm_of_crtc_port_mask(struct drm_device *dev,
338b5f7a62SJernej Skrabec 			    struct device_node *port);
3491faa047SDaniel Vetter uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
357e435aadSRussell King 				    struct device_node *port);
3691faa047SDaniel Vetter void drm_of_component_match_add(struct device *master,
3797ac0e47SRussell King 				struct component_match **matchptr,
3897ac0e47SRussell King 				int (*compare)(struct device *, void *),
3997ac0e47SRussell King 				struct device_node *node);
4091faa047SDaniel Vetter int drm_of_component_probe(struct device *dev,
41df785aa8SLiviu Dudau 			   int (*compare_of)(struct device *, void *),
42df785aa8SLiviu Dudau 			   const struct component_master_ops *m_ops);
4391faa047SDaniel Vetter int drm_of_encoder_active_endpoint(struct device_node *node,
444cacf91fSPhilipp Zabel 				   struct drm_encoder *encoder,
454cacf91fSPhilipp Zabel 				   struct of_endpoint *endpoint);
461f2db303SRob Herring int drm_of_find_panel_or_bridge(const struct device_node *np,
471f2db303SRob Herring 				int port, int endpoint,
481f2db303SRob Herring 				struct drm_panel **panel,
491f2db303SRob Herring 				struct drm_bridge **bridge);
50*65290075SFabrizio Castro int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
51*65290075SFabrizio Castro 					  const struct device_node *port2);
527e435aadSRussell King #else
538b5f7a62SJernej Skrabec static inline uint32_t drm_of_crtc_port_mask(struct drm_device *dev,
548b5f7a62SJernej Skrabec 					  struct device_node *port)
558b5f7a62SJernej Skrabec {
568b5f7a62SJernej Skrabec 	return 0;
578b5f7a62SJernej Skrabec }
588b5f7a62SJernej Skrabec 
597e435aadSRussell King static inline uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
607e435aadSRussell King 						  struct device_node *port)
617e435aadSRussell King {
627e435aadSRussell King 	return 0;
637e435aadSRussell King }
64df785aa8SLiviu Dudau 
65329f4c81SArnd Bergmann static inline void
66329f4c81SArnd Bergmann drm_of_component_match_add(struct device *master,
6797ac0e47SRussell King 			   struct component_match **matchptr,
6897ac0e47SRussell King 			   int (*compare)(struct device *, void *),
6997ac0e47SRussell King 			   struct device_node *node)
7097ac0e47SRussell King {
7197ac0e47SRussell King }
7297ac0e47SRussell King 
73df785aa8SLiviu Dudau static inline int
74df785aa8SLiviu Dudau drm_of_component_probe(struct device *dev,
75df785aa8SLiviu Dudau 		       int (*compare_of)(struct device *, void *),
76df785aa8SLiviu Dudau 		       const struct component_master_ops *m_ops)
77df785aa8SLiviu Dudau {
78df785aa8SLiviu Dudau 	return -EINVAL;
79df785aa8SLiviu Dudau }
804cacf91fSPhilipp Zabel 
814cacf91fSPhilipp Zabel static inline int drm_of_encoder_active_endpoint(struct device_node *node,
824cacf91fSPhilipp Zabel 						 struct drm_encoder *encoder,
834cacf91fSPhilipp Zabel 						 struct of_endpoint *endpoint)
844cacf91fSPhilipp Zabel {
854cacf91fSPhilipp Zabel 	return -EINVAL;
864cacf91fSPhilipp Zabel }
871f2db303SRob Herring static inline int drm_of_find_panel_or_bridge(const struct device_node *np,
881f2db303SRob Herring 					      int port, int endpoint,
891f2db303SRob Herring 					      struct drm_panel **panel,
901f2db303SRob Herring 					      struct drm_bridge **bridge)
911f2db303SRob Herring {
921f2db303SRob Herring 	return -EINVAL;
931f2db303SRob Herring }
94*65290075SFabrizio Castro 
95*65290075SFabrizio Castro int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
96*65290075SFabrizio Castro 					  const struct device_node *port2)
97*65290075SFabrizio Castro {
98*65290075SFabrizio Castro 	return -EINVAL;
99*65290075SFabrizio Castro }
1007e435aadSRussell King #endif
1017e435aadSRussell King 
102512721a1SMaarten Lankhorst /*
103512721a1SMaarten Lankhorst  * drm_of_panel_bridge_remove - remove panel bridge
104512721a1SMaarten Lankhorst  * @np: device tree node containing panel bridge output ports
105512721a1SMaarten Lankhorst  *
106512721a1SMaarten Lankhorst  * Remove the panel bridge of a given DT node's port and endpoint number
107512721a1SMaarten Lankhorst  *
108512721a1SMaarten Lankhorst  * Returns zero if successful, or one of the standard error codes if it fails.
109512721a1SMaarten Lankhorst  */
110c70087e8Sbenjamin.gaignard@linaro.org static inline int drm_of_panel_bridge_remove(const struct device_node *np,
111c70087e8Sbenjamin.gaignard@linaro.org 					     int port, int endpoint)
112c70087e8Sbenjamin.gaignard@linaro.org {
113512721a1SMaarten Lankhorst #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE)
114512721a1SMaarten Lankhorst 	struct drm_bridge *bridge;
115512721a1SMaarten Lankhorst 	struct device_node *remote;
116512721a1SMaarten Lankhorst 
117512721a1SMaarten Lankhorst 	remote = of_graph_get_remote_node(np, port, endpoint);
118512721a1SMaarten Lankhorst 	if (!remote)
119512721a1SMaarten Lankhorst 		return -ENODEV;
120512721a1SMaarten Lankhorst 
121512721a1SMaarten Lankhorst 	bridge = of_drm_find_bridge(remote);
122512721a1SMaarten Lankhorst 	drm_panel_bridge_remove(bridge);
123512721a1SMaarten Lankhorst 
124512721a1SMaarten Lankhorst 	return 0;
125512721a1SMaarten Lankhorst #else
126c70087e8Sbenjamin.gaignard@linaro.org 	return -EINVAL;
1277e435aadSRussell King #endif
128512721a1SMaarten Lankhorst }
1297e435aadSRussell King 
1304cacf91fSPhilipp Zabel static inline int drm_of_encoder_active_endpoint_id(struct device_node *node,
1314cacf91fSPhilipp Zabel 						    struct drm_encoder *encoder)
1324cacf91fSPhilipp Zabel {
1334cacf91fSPhilipp Zabel 	struct of_endpoint endpoint;
1344cacf91fSPhilipp Zabel 	int ret = drm_of_encoder_active_endpoint(node, encoder,
1354cacf91fSPhilipp Zabel 						 &endpoint);
1364cacf91fSPhilipp Zabel 
1374cacf91fSPhilipp Zabel 	return ret ?: endpoint.id;
1384cacf91fSPhilipp Zabel }
1394cacf91fSPhilipp Zabel 
1404cacf91fSPhilipp Zabel static inline int drm_of_encoder_active_port_id(struct device_node *node,
1414cacf91fSPhilipp Zabel 						struct drm_encoder *encoder)
1424cacf91fSPhilipp Zabel {
1434cacf91fSPhilipp Zabel 	struct of_endpoint endpoint;
1444cacf91fSPhilipp Zabel 	int ret = drm_of_encoder_active_endpoint(node, encoder,
1454cacf91fSPhilipp Zabel 						 &endpoint);
1464cacf91fSPhilipp Zabel 
1474cacf91fSPhilipp Zabel 	return ret ?: endpoint.port;
1484cacf91fSPhilipp Zabel }
1494cacf91fSPhilipp Zabel 
1507e435aadSRussell King #endif /* __DRM_OF_H__ */
151