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 197e435aadSRussell King #ifdef CONFIG_OF 20*8b5f7a62SJernej Skrabec uint32_t drm_of_crtc_port_mask(struct drm_device *dev, 21*8b5f7a62SJernej Skrabec struct device_node *port); 2291faa047SDaniel Vetter uint32_t drm_of_find_possible_crtcs(struct drm_device *dev, 237e435aadSRussell King struct device_node *port); 2491faa047SDaniel Vetter void drm_of_component_match_add(struct device *master, 2597ac0e47SRussell King struct component_match **matchptr, 2697ac0e47SRussell King int (*compare)(struct device *, void *), 2797ac0e47SRussell King struct device_node *node); 2891faa047SDaniel Vetter int drm_of_component_probe(struct device *dev, 29df785aa8SLiviu Dudau int (*compare_of)(struct device *, void *), 30df785aa8SLiviu Dudau const struct component_master_ops *m_ops); 3191faa047SDaniel Vetter int drm_of_encoder_active_endpoint(struct device_node *node, 324cacf91fSPhilipp Zabel struct drm_encoder *encoder, 334cacf91fSPhilipp Zabel struct of_endpoint *endpoint); 341f2db303SRob Herring int drm_of_find_panel_or_bridge(const struct device_node *np, 351f2db303SRob Herring int port, int endpoint, 361f2db303SRob Herring struct drm_panel **panel, 371f2db303SRob Herring struct drm_bridge **bridge); 387e435aadSRussell King #else 39*8b5f7a62SJernej Skrabec static inline uint32_t drm_of_crtc_port_mask(struct drm_device *dev, 40*8b5f7a62SJernej Skrabec struct device_node *port) 41*8b5f7a62SJernej Skrabec { 42*8b5f7a62SJernej Skrabec return 0; 43*8b5f7a62SJernej Skrabec } 44*8b5f7a62SJernej Skrabec 457e435aadSRussell King static inline uint32_t drm_of_find_possible_crtcs(struct drm_device *dev, 467e435aadSRussell King struct device_node *port) 477e435aadSRussell King { 487e435aadSRussell King return 0; 497e435aadSRussell King } 50df785aa8SLiviu Dudau 51329f4c81SArnd Bergmann static inline void 52329f4c81SArnd Bergmann drm_of_component_match_add(struct device *master, 5397ac0e47SRussell King struct component_match **matchptr, 5497ac0e47SRussell King int (*compare)(struct device *, void *), 5597ac0e47SRussell King struct device_node *node) 5697ac0e47SRussell King { 5797ac0e47SRussell King } 5897ac0e47SRussell King 59df785aa8SLiviu Dudau static inline int 60df785aa8SLiviu Dudau drm_of_component_probe(struct device *dev, 61df785aa8SLiviu Dudau int (*compare_of)(struct device *, void *), 62df785aa8SLiviu Dudau const struct component_master_ops *m_ops) 63df785aa8SLiviu Dudau { 64df785aa8SLiviu Dudau return -EINVAL; 65df785aa8SLiviu Dudau } 664cacf91fSPhilipp Zabel 674cacf91fSPhilipp Zabel static inline int drm_of_encoder_active_endpoint(struct device_node *node, 684cacf91fSPhilipp Zabel struct drm_encoder *encoder, 694cacf91fSPhilipp Zabel struct of_endpoint *endpoint) 704cacf91fSPhilipp Zabel { 714cacf91fSPhilipp Zabel return -EINVAL; 724cacf91fSPhilipp Zabel } 731f2db303SRob Herring static inline int drm_of_find_panel_or_bridge(const struct device_node *np, 741f2db303SRob Herring int port, int endpoint, 751f2db303SRob Herring struct drm_panel **panel, 761f2db303SRob Herring struct drm_bridge **bridge) 771f2db303SRob Herring { 781f2db303SRob Herring return -EINVAL; 791f2db303SRob Herring } 807e435aadSRussell King #endif 817e435aadSRussell King 82512721a1SMaarten Lankhorst /* 83512721a1SMaarten Lankhorst * drm_of_panel_bridge_remove - remove panel bridge 84512721a1SMaarten Lankhorst * @np: device tree node containing panel bridge output ports 85512721a1SMaarten Lankhorst * 86512721a1SMaarten Lankhorst * Remove the panel bridge of a given DT node's port and endpoint number 87512721a1SMaarten Lankhorst * 88512721a1SMaarten Lankhorst * Returns zero if successful, or one of the standard error codes if it fails. 89512721a1SMaarten Lankhorst */ 90c70087e8Sbenjamin.gaignard@linaro.org static inline int drm_of_panel_bridge_remove(const struct device_node *np, 91c70087e8Sbenjamin.gaignard@linaro.org int port, int endpoint) 92c70087e8Sbenjamin.gaignard@linaro.org { 93512721a1SMaarten Lankhorst #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE) 94512721a1SMaarten Lankhorst struct drm_bridge *bridge; 95512721a1SMaarten Lankhorst struct device_node *remote; 96512721a1SMaarten Lankhorst 97512721a1SMaarten Lankhorst remote = of_graph_get_remote_node(np, port, endpoint); 98512721a1SMaarten Lankhorst if (!remote) 99512721a1SMaarten Lankhorst return -ENODEV; 100512721a1SMaarten Lankhorst 101512721a1SMaarten Lankhorst bridge = of_drm_find_bridge(remote); 102512721a1SMaarten Lankhorst drm_panel_bridge_remove(bridge); 103512721a1SMaarten Lankhorst 104512721a1SMaarten Lankhorst return 0; 105512721a1SMaarten Lankhorst #else 106c70087e8Sbenjamin.gaignard@linaro.org return -EINVAL; 1077e435aadSRussell King #endif 108512721a1SMaarten Lankhorst } 1097e435aadSRussell King 1104cacf91fSPhilipp Zabel static inline int drm_of_encoder_active_endpoint_id(struct device_node *node, 1114cacf91fSPhilipp Zabel struct drm_encoder *encoder) 1124cacf91fSPhilipp Zabel { 1134cacf91fSPhilipp Zabel struct of_endpoint endpoint; 1144cacf91fSPhilipp Zabel int ret = drm_of_encoder_active_endpoint(node, encoder, 1154cacf91fSPhilipp Zabel &endpoint); 1164cacf91fSPhilipp Zabel 1174cacf91fSPhilipp Zabel return ret ?: endpoint.id; 1184cacf91fSPhilipp Zabel } 1194cacf91fSPhilipp Zabel 1204cacf91fSPhilipp Zabel static inline int drm_of_encoder_active_port_id(struct device_node *node, 1214cacf91fSPhilipp Zabel struct drm_encoder *encoder) 1224cacf91fSPhilipp Zabel { 1234cacf91fSPhilipp Zabel struct of_endpoint endpoint; 1244cacf91fSPhilipp Zabel int ret = drm_of_encoder_active_endpoint(node, encoder, 1254cacf91fSPhilipp Zabel &endpoint); 1264cacf91fSPhilipp Zabel 1274cacf91fSPhilipp Zabel return ret ?: endpoint.port; 1284cacf91fSPhilipp Zabel } 1294cacf91fSPhilipp Zabel 1307e435aadSRussell King #endif /* __DRM_OF_H__ */ 131