17e435aadSRussell King #ifndef __DRM_OF_H__ 27e435aadSRussell King #define __DRM_OF_H__ 37e435aadSRussell King 44cacf91fSPhilipp Zabel #include <linux/of_graph.h> 5*512721a1SMaarten Lankhorst #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE) 6*512721a1SMaarten Lankhorst #include <drm/drm_bridge.h> 7*512721a1SMaarten Lankhorst #endif 84cacf91fSPhilipp Zabel 9df785aa8SLiviu Dudau struct component_master_ops; 1097ac0e47SRussell King struct component_match; 11df785aa8SLiviu Dudau struct device; 127e435aadSRussell King struct drm_device; 134cacf91fSPhilipp Zabel struct drm_encoder; 141f2db303SRob Herring struct drm_panel; 151f2db303SRob Herring struct drm_bridge; 167e435aadSRussell King struct device_node; 177e435aadSRussell King 187e435aadSRussell King #ifdef CONFIG_OF 1991faa047SDaniel Vetter uint32_t drm_of_find_possible_crtcs(struct drm_device *dev, 207e435aadSRussell King struct device_node *port); 2191faa047SDaniel Vetter void drm_of_component_match_add(struct device *master, 2297ac0e47SRussell King struct component_match **matchptr, 2397ac0e47SRussell King int (*compare)(struct device *, void *), 2497ac0e47SRussell King struct device_node *node); 2591faa047SDaniel Vetter int drm_of_component_probe(struct device *dev, 26df785aa8SLiviu Dudau int (*compare_of)(struct device *, void *), 27df785aa8SLiviu Dudau const struct component_master_ops *m_ops); 2891faa047SDaniel Vetter int drm_of_encoder_active_endpoint(struct device_node *node, 294cacf91fSPhilipp Zabel struct drm_encoder *encoder, 304cacf91fSPhilipp Zabel struct of_endpoint *endpoint); 311f2db303SRob Herring int drm_of_find_panel_or_bridge(const struct device_node *np, 321f2db303SRob Herring int port, int endpoint, 331f2db303SRob Herring struct drm_panel **panel, 341f2db303SRob Herring struct drm_bridge **bridge); 357e435aadSRussell King #else 367e435aadSRussell King static inline uint32_t drm_of_find_possible_crtcs(struct drm_device *dev, 377e435aadSRussell King struct device_node *port) 387e435aadSRussell King { 397e435aadSRussell King return 0; 407e435aadSRussell King } 41df785aa8SLiviu Dudau 42329f4c81SArnd Bergmann static inline void 43329f4c81SArnd Bergmann drm_of_component_match_add(struct device *master, 4497ac0e47SRussell King struct component_match **matchptr, 4597ac0e47SRussell King int (*compare)(struct device *, void *), 4697ac0e47SRussell King struct device_node *node) 4797ac0e47SRussell King { 4897ac0e47SRussell King } 4997ac0e47SRussell King 50df785aa8SLiviu Dudau static inline int 51df785aa8SLiviu Dudau drm_of_component_probe(struct device *dev, 52df785aa8SLiviu Dudau int (*compare_of)(struct device *, void *), 53df785aa8SLiviu Dudau const struct component_master_ops *m_ops) 54df785aa8SLiviu Dudau { 55df785aa8SLiviu Dudau return -EINVAL; 56df785aa8SLiviu Dudau } 574cacf91fSPhilipp Zabel 584cacf91fSPhilipp Zabel static inline int drm_of_encoder_active_endpoint(struct device_node *node, 594cacf91fSPhilipp Zabel struct drm_encoder *encoder, 604cacf91fSPhilipp Zabel struct of_endpoint *endpoint) 614cacf91fSPhilipp Zabel { 624cacf91fSPhilipp Zabel return -EINVAL; 634cacf91fSPhilipp Zabel } 641f2db303SRob Herring static inline int drm_of_find_panel_or_bridge(const struct device_node *np, 651f2db303SRob Herring int port, int endpoint, 661f2db303SRob Herring struct drm_panel **panel, 671f2db303SRob Herring struct drm_bridge **bridge) 681f2db303SRob Herring { 691f2db303SRob Herring return -EINVAL; 701f2db303SRob Herring } 71*512721a1SMaarten Lankhorst #endif 72c70087e8Sbenjamin.gaignard@linaro.org 73*512721a1SMaarten Lankhorst /* 74*512721a1SMaarten Lankhorst * drm_of_panel_bridge_remove - remove panel bridge 75*512721a1SMaarten Lankhorst * @np: device tree node containing panel bridge output ports 76*512721a1SMaarten Lankhorst * 77*512721a1SMaarten Lankhorst * Remove the panel bridge of a given DT node's port and endpoint number 78*512721a1SMaarten Lankhorst * 79*512721a1SMaarten Lankhorst * Returns zero if successful, or one of the standard error codes if it fails. 80*512721a1SMaarten Lankhorst */ 81c70087e8Sbenjamin.gaignard@linaro.org static inline int drm_of_panel_bridge_remove(const struct device_node *np, 82c70087e8Sbenjamin.gaignard@linaro.org int port, int endpoint) 83c70087e8Sbenjamin.gaignard@linaro.org { 84*512721a1SMaarten Lankhorst #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE) 85*512721a1SMaarten Lankhorst struct drm_bridge *bridge; 86*512721a1SMaarten Lankhorst struct device_node *remote; 87*512721a1SMaarten Lankhorst 88*512721a1SMaarten Lankhorst remote = of_graph_get_remote_node(np, port, endpoint); 89*512721a1SMaarten Lankhorst if (!remote) 90*512721a1SMaarten Lankhorst return -ENODEV; 91*512721a1SMaarten Lankhorst 92*512721a1SMaarten Lankhorst bridge = of_drm_find_bridge(remote); 93*512721a1SMaarten Lankhorst drm_panel_bridge_remove(bridge); 94*512721a1SMaarten Lankhorst 95*512721a1SMaarten Lankhorst return 0; 96*512721a1SMaarten Lankhorst #else 97c70087e8Sbenjamin.gaignard@linaro.org return -EINVAL; 987e435aadSRussell King #endif 99*512721a1SMaarten Lankhorst } 1007e435aadSRussell King 1014cacf91fSPhilipp Zabel static inline int drm_of_encoder_active_endpoint_id(struct device_node *node, 1024cacf91fSPhilipp Zabel struct drm_encoder *encoder) 1034cacf91fSPhilipp Zabel { 1044cacf91fSPhilipp Zabel struct of_endpoint endpoint; 1054cacf91fSPhilipp Zabel int ret = drm_of_encoder_active_endpoint(node, encoder, 1064cacf91fSPhilipp Zabel &endpoint); 1074cacf91fSPhilipp Zabel 1084cacf91fSPhilipp Zabel return ret ?: endpoint.id; 1094cacf91fSPhilipp Zabel } 1104cacf91fSPhilipp Zabel 1114cacf91fSPhilipp Zabel static inline int drm_of_encoder_active_port_id(struct device_node *node, 1124cacf91fSPhilipp Zabel struct drm_encoder *encoder) 1134cacf91fSPhilipp Zabel { 1144cacf91fSPhilipp Zabel struct of_endpoint endpoint; 1154cacf91fSPhilipp Zabel int ret = drm_of_encoder_active_endpoint(node, encoder, 1164cacf91fSPhilipp Zabel &endpoint); 1174cacf91fSPhilipp Zabel 1184cacf91fSPhilipp Zabel return ret ?: endpoint.port; 1194cacf91fSPhilipp Zabel } 1204cacf91fSPhilipp Zabel 1217e435aadSRussell King #endif /* __DRM_OF_H__ */ 122