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 1965290075SFabrizio Castro /** 2065290075SFabrizio Castro * enum drm_lvds_dual_link_pixels - Pixel order of an LVDS dual-link connection 2165290075SFabrizio Castro * @DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS: Even pixels are expected to be generated 2265290075SFabrizio Castro * from the first port, odd pixels from the second port 2365290075SFabrizio Castro * @DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS: Odd pixels are expected to be generated 2465290075SFabrizio Castro * from the first port, even pixels from the second port 2565290075SFabrizio Castro */ 2665290075SFabrizio Castro enum drm_lvds_dual_link_pixels { 2765290075SFabrizio Castro DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS = 0, 2865290075SFabrizio Castro DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS = 1, 2965290075SFabrizio Castro }; 3065290075SFabrizio 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); 5065290075SFabrizio Castro int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1, 5165290075SFabrizio Castro const struct device_node *port2); 527c4dd0a2SMarek Vasut int drm_of_lvds_get_data_mapping(const struct device_node *port); 53fc801750SMarek Vasut int drm_of_get_data_lanes_count(const struct device_node *endpoint, 54fc801750SMarek Vasut const unsigned int min, const unsigned int max); 55fc801750SMarek Vasut int drm_of_get_data_lanes_count_ep(const struct device_node *port, 56fc801750SMarek Vasut int port_reg, int reg, 57fc801750SMarek Vasut const unsigned int min, 58fc801750SMarek Vasut const unsigned int max); 597e435aadSRussell King #else 608b5f7a62SJernej Skrabec static inline uint32_t drm_of_crtc_port_mask(struct drm_device *dev, 618b5f7a62SJernej Skrabec struct device_node *port) 628b5f7a62SJernej Skrabec { 638b5f7a62SJernej Skrabec return 0; 648b5f7a62SJernej Skrabec } 658b5f7a62SJernej Skrabec 667e435aadSRussell King static inline uint32_t drm_of_find_possible_crtcs(struct drm_device *dev, 677e435aadSRussell King struct device_node *port) 687e435aadSRussell King { 697e435aadSRussell King return 0; 707e435aadSRussell King } 71df785aa8SLiviu Dudau 72329f4c81SArnd Bergmann static inline void 73329f4c81SArnd Bergmann drm_of_component_match_add(struct device *master, 7497ac0e47SRussell King struct component_match **matchptr, 7597ac0e47SRussell King int (*compare)(struct device *, void *), 7697ac0e47SRussell King struct device_node *node) 7797ac0e47SRussell King { 7897ac0e47SRussell King } 7997ac0e47SRussell King 80df785aa8SLiviu Dudau static inline int 81df785aa8SLiviu Dudau drm_of_component_probe(struct device *dev, 82df785aa8SLiviu Dudau int (*compare_of)(struct device *, void *), 83df785aa8SLiviu Dudau const struct component_master_ops *m_ops) 84df785aa8SLiviu Dudau { 85df785aa8SLiviu Dudau return -EINVAL; 86df785aa8SLiviu Dudau } 874cacf91fSPhilipp Zabel 884cacf91fSPhilipp Zabel static inline int drm_of_encoder_active_endpoint(struct device_node *node, 894cacf91fSPhilipp Zabel struct drm_encoder *encoder, 904cacf91fSPhilipp Zabel struct of_endpoint *endpoint) 914cacf91fSPhilipp Zabel { 924cacf91fSPhilipp Zabel return -EINVAL; 934cacf91fSPhilipp Zabel } 941f2db303SRob Herring static inline int drm_of_find_panel_or_bridge(const struct device_node *np, 951f2db303SRob Herring int port, int endpoint, 961f2db303SRob Herring struct drm_panel **panel, 971f2db303SRob Herring struct drm_bridge **bridge) 981f2db303SRob Herring { 991f2db303SRob Herring return -EINVAL; 1001f2db303SRob Herring } 10165290075SFabrizio Castro 102528d06d4SLaurent Pinchart static inline int 103528d06d4SLaurent Pinchart drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1, 10465290075SFabrizio Castro const struct device_node *port2) 10565290075SFabrizio Castro { 10665290075SFabrizio Castro return -EINVAL; 10765290075SFabrizio Castro } 1087c4dd0a2SMarek Vasut 1097c4dd0a2SMarek Vasut static inline int 1107c4dd0a2SMarek Vasut drm_of_lvds_get_data_mapping(const struct device_node *port) 1117c4dd0a2SMarek Vasut { 1127c4dd0a2SMarek Vasut return -EINVAL; 1137c4dd0a2SMarek Vasut } 114fc801750SMarek Vasut 115*eb6b94dbSMarek Vasut static inline int 116*eb6b94dbSMarek Vasut drm_of_get_data_lanes_count(const struct device_node *endpoint, 117fc801750SMarek Vasut const unsigned int min, const unsigned int max) 118fc801750SMarek Vasut { 119fc801750SMarek Vasut return -EINVAL; 120fc801750SMarek Vasut } 121fc801750SMarek Vasut 122*eb6b94dbSMarek Vasut static inline int 123*eb6b94dbSMarek Vasut drm_of_get_data_lanes_count_ep(const struct device_node *port, 124*eb6b94dbSMarek Vasut int port_reg, int reg, 125fc801750SMarek Vasut const unsigned int min, 126fc801750SMarek Vasut const unsigned int max) 127fc801750SMarek Vasut { 128fc801750SMarek Vasut return -EINVAL; 129fc801750SMarek Vasut } 1307e435aadSRussell King #endif 1317e435aadSRussell King 132512721a1SMaarten Lankhorst /* 133512721a1SMaarten Lankhorst * drm_of_panel_bridge_remove - remove panel bridge 134512721a1SMaarten Lankhorst * @np: device tree node containing panel bridge output ports 135512721a1SMaarten Lankhorst * 136512721a1SMaarten Lankhorst * Remove the panel bridge of a given DT node's port and endpoint number 137512721a1SMaarten Lankhorst * 138512721a1SMaarten Lankhorst * Returns zero if successful, or one of the standard error codes if it fails. 139512721a1SMaarten Lankhorst */ 140c70087e8Sbenjamin.gaignard@linaro.org static inline int drm_of_panel_bridge_remove(const struct device_node *np, 141c70087e8Sbenjamin.gaignard@linaro.org int port, int endpoint) 142c70087e8Sbenjamin.gaignard@linaro.org { 143512721a1SMaarten Lankhorst #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE) 144512721a1SMaarten Lankhorst struct drm_bridge *bridge; 145512721a1SMaarten Lankhorst struct device_node *remote; 146512721a1SMaarten Lankhorst 147512721a1SMaarten Lankhorst remote = of_graph_get_remote_node(np, port, endpoint); 148512721a1SMaarten Lankhorst if (!remote) 149512721a1SMaarten Lankhorst return -ENODEV; 150512721a1SMaarten Lankhorst 151512721a1SMaarten Lankhorst bridge = of_drm_find_bridge(remote); 152512721a1SMaarten Lankhorst drm_panel_bridge_remove(bridge); 153512721a1SMaarten Lankhorst 154512721a1SMaarten Lankhorst return 0; 155512721a1SMaarten Lankhorst #else 156c70087e8Sbenjamin.gaignard@linaro.org return -EINVAL; 1577e435aadSRussell King #endif 158512721a1SMaarten Lankhorst } 1597e435aadSRussell King 1604cacf91fSPhilipp Zabel static inline int drm_of_encoder_active_endpoint_id(struct device_node *node, 1614cacf91fSPhilipp Zabel struct drm_encoder *encoder) 1624cacf91fSPhilipp Zabel { 1634cacf91fSPhilipp Zabel struct of_endpoint endpoint; 1644cacf91fSPhilipp Zabel int ret = drm_of_encoder_active_endpoint(node, encoder, 1654cacf91fSPhilipp Zabel &endpoint); 1664cacf91fSPhilipp Zabel 1674cacf91fSPhilipp Zabel return ret ?: endpoint.id; 1684cacf91fSPhilipp Zabel } 1694cacf91fSPhilipp Zabel 1704cacf91fSPhilipp Zabel static inline int drm_of_encoder_active_port_id(struct device_node *node, 1714cacf91fSPhilipp Zabel struct drm_encoder *encoder) 1724cacf91fSPhilipp Zabel { 1734cacf91fSPhilipp Zabel struct of_endpoint endpoint; 1744cacf91fSPhilipp Zabel int ret = drm_of_encoder_active_endpoint(node, encoder, 1754cacf91fSPhilipp Zabel &endpoint); 1764cacf91fSPhilipp Zabel 1774cacf91fSPhilipp Zabel return ret ?: endpoint.port; 1784cacf91fSPhilipp Zabel } 1794cacf91fSPhilipp Zabel 1807e435aadSRussell King #endif /* __DRM_OF_H__ */ 181