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); 52*7c4dd0a2SMarek Vasut int drm_of_lvds_get_data_mapping(const struct device_node *port); 537e435aadSRussell King #else 548b5f7a62SJernej Skrabec static inline uint32_t drm_of_crtc_port_mask(struct drm_device *dev, 558b5f7a62SJernej Skrabec struct device_node *port) 568b5f7a62SJernej Skrabec { 578b5f7a62SJernej Skrabec return 0; 588b5f7a62SJernej Skrabec } 598b5f7a62SJernej Skrabec 607e435aadSRussell King static inline uint32_t drm_of_find_possible_crtcs(struct drm_device *dev, 617e435aadSRussell King struct device_node *port) 627e435aadSRussell King { 637e435aadSRussell King return 0; 647e435aadSRussell King } 65df785aa8SLiviu Dudau 66329f4c81SArnd Bergmann static inline void 67329f4c81SArnd Bergmann drm_of_component_match_add(struct device *master, 6897ac0e47SRussell King struct component_match **matchptr, 6997ac0e47SRussell King int (*compare)(struct device *, void *), 7097ac0e47SRussell King struct device_node *node) 7197ac0e47SRussell King { 7297ac0e47SRussell King } 7397ac0e47SRussell King 74df785aa8SLiviu Dudau static inline int 75df785aa8SLiviu Dudau drm_of_component_probe(struct device *dev, 76df785aa8SLiviu Dudau int (*compare_of)(struct device *, void *), 77df785aa8SLiviu Dudau const struct component_master_ops *m_ops) 78df785aa8SLiviu Dudau { 79df785aa8SLiviu Dudau return -EINVAL; 80df785aa8SLiviu Dudau } 814cacf91fSPhilipp Zabel 824cacf91fSPhilipp Zabel static inline int drm_of_encoder_active_endpoint(struct device_node *node, 834cacf91fSPhilipp Zabel struct drm_encoder *encoder, 844cacf91fSPhilipp Zabel struct of_endpoint *endpoint) 854cacf91fSPhilipp Zabel { 864cacf91fSPhilipp Zabel return -EINVAL; 874cacf91fSPhilipp Zabel } 881f2db303SRob Herring static inline int drm_of_find_panel_or_bridge(const struct device_node *np, 891f2db303SRob Herring int port, int endpoint, 901f2db303SRob Herring struct drm_panel **panel, 911f2db303SRob Herring struct drm_bridge **bridge) 921f2db303SRob Herring { 931f2db303SRob Herring return -EINVAL; 941f2db303SRob Herring } 9565290075SFabrizio Castro 96528d06d4SLaurent Pinchart static inline int 97528d06d4SLaurent Pinchart drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1, 9865290075SFabrizio Castro const struct device_node *port2) 9965290075SFabrizio Castro { 10065290075SFabrizio Castro return -EINVAL; 10165290075SFabrizio Castro } 102*7c4dd0a2SMarek Vasut 103*7c4dd0a2SMarek Vasut static inline int 104*7c4dd0a2SMarek Vasut drm_of_lvds_get_data_mapping(const struct device_node *port) 105*7c4dd0a2SMarek Vasut { 106*7c4dd0a2SMarek Vasut return -EINVAL; 107*7c4dd0a2SMarek Vasut } 1087e435aadSRussell King #endif 1097e435aadSRussell King 110512721a1SMaarten Lankhorst /* 111512721a1SMaarten Lankhorst * drm_of_panel_bridge_remove - remove panel bridge 112512721a1SMaarten Lankhorst * @np: device tree node containing panel bridge output ports 113512721a1SMaarten Lankhorst * 114512721a1SMaarten Lankhorst * Remove the panel bridge of a given DT node's port and endpoint number 115512721a1SMaarten Lankhorst * 116512721a1SMaarten Lankhorst * Returns zero if successful, or one of the standard error codes if it fails. 117512721a1SMaarten Lankhorst */ 118c70087e8Sbenjamin.gaignard@linaro.org static inline int drm_of_panel_bridge_remove(const struct device_node *np, 119c70087e8Sbenjamin.gaignard@linaro.org int port, int endpoint) 120c70087e8Sbenjamin.gaignard@linaro.org { 121512721a1SMaarten Lankhorst #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE) 122512721a1SMaarten Lankhorst struct drm_bridge *bridge; 123512721a1SMaarten Lankhorst struct device_node *remote; 124512721a1SMaarten Lankhorst 125512721a1SMaarten Lankhorst remote = of_graph_get_remote_node(np, port, endpoint); 126512721a1SMaarten Lankhorst if (!remote) 127512721a1SMaarten Lankhorst return -ENODEV; 128512721a1SMaarten Lankhorst 129512721a1SMaarten Lankhorst bridge = of_drm_find_bridge(remote); 130512721a1SMaarten Lankhorst drm_panel_bridge_remove(bridge); 131512721a1SMaarten Lankhorst 132512721a1SMaarten Lankhorst return 0; 133512721a1SMaarten Lankhorst #else 134c70087e8Sbenjamin.gaignard@linaro.org return -EINVAL; 1357e435aadSRussell King #endif 136512721a1SMaarten Lankhorst } 1377e435aadSRussell King 1384cacf91fSPhilipp Zabel static inline int drm_of_encoder_active_endpoint_id(struct device_node *node, 1394cacf91fSPhilipp Zabel struct drm_encoder *encoder) 1404cacf91fSPhilipp Zabel { 1414cacf91fSPhilipp Zabel struct of_endpoint endpoint; 1424cacf91fSPhilipp Zabel int ret = drm_of_encoder_active_endpoint(node, encoder, 1434cacf91fSPhilipp Zabel &endpoint); 1444cacf91fSPhilipp Zabel 1454cacf91fSPhilipp Zabel return ret ?: endpoint.id; 1464cacf91fSPhilipp Zabel } 1474cacf91fSPhilipp Zabel 1484cacf91fSPhilipp Zabel static inline int drm_of_encoder_active_port_id(struct device_node *node, 1494cacf91fSPhilipp Zabel struct drm_encoder *encoder) 1504cacf91fSPhilipp Zabel { 1514cacf91fSPhilipp Zabel struct of_endpoint endpoint; 1524cacf91fSPhilipp Zabel int ret = drm_of_encoder_active_endpoint(node, encoder, 1534cacf91fSPhilipp Zabel &endpoint); 1544cacf91fSPhilipp Zabel 1554cacf91fSPhilipp Zabel return ret ?: endpoint.port; 1564cacf91fSPhilipp Zabel } 1574cacf91fSPhilipp Zabel 1587e435aadSRussell King #endif /* __DRM_OF_H__ */ 159