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;
18*19ff997fSChris Morgan struct mipi_dsi_device_info;
19*19ff997fSChris Morgan struct mipi_dsi_host;
207e435aadSRussell King
2165290075SFabrizio Castro /**
2265290075SFabrizio Castro * enum drm_lvds_dual_link_pixels - Pixel order of an LVDS dual-link connection
2365290075SFabrizio Castro * @DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS: Even pixels are expected to be generated
2465290075SFabrizio Castro * from the first port, odd pixels from the second port
2565290075SFabrizio Castro * @DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS: Odd pixels are expected to be generated
2665290075SFabrizio Castro * from the first port, even pixels from the second port
2765290075SFabrizio Castro */
2865290075SFabrizio Castro enum drm_lvds_dual_link_pixels {
2965290075SFabrizio Castro DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS = 0,
3065290075SFabrizio Castro DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS = 1,
3165290075SFabrizio Castro };
3265290075SFabrizio Castro
337e435aadSRussell King #ifdef CONFIG_OF
348b5f7a62SJernej Skrabec uint32_t drm_of_crtc_port_mask(struct drm_device *dev,
358b5f7a62SJernej Skrabec struct device_node *port);
3691faa047SDaniel Vetter uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
377e435aadSRussell King struct device_node *port);
3891faa047SDaniel Vetter void drm_of_component_match_add(struct device *master,
3997ac0e47SRussell King struct component_match **matchptr,
4097ac0e47SRussell King int (*compare)(struct device *, void *),
4197ac0e47SRussell King struct device_node *node);
4291faa047SDaniel Vetter int drm_of_component_probe(struct device *dev,
43df785aa8SLiviu Dudau int (*compare_of)(struct device *, void *),
44df785aa8SLiviu Dudau const struct component_master_ops *m_ops);
4591faa047SDaniel Vetter int drm_of_encoder_active_endpoint(struct device_node *node,
464cacf91fSPhilipp Zabel struct drm_encoder *encoder,
474cacf91fSPhilipp Zabel struct of_endpoint *endpoint);
481f2db303SRob Herring int drm_of_find_panel_or_bridge(const struct device_node *np,
491f2db303SRob Herring int port, int endpoint,
501f2db303SRob Herring struct drm_panel **panel,
511f2db303SRob Herring struct drm_bridge **bridge);
5265290075SFabrizio Castro int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
5365290075SFabrizio Castro const struct device_node *port2);
547c4dd0a2SMarek Vasut int drm_of_lvds_get_data_mapping(const struct device_node *port);
55fc801750SMarek Vasut int drm_of_get_data_lanes_count(const struct device_node *endpoint,
56fc801750SMarek Vasut const unsigned int min, const unsigned int max);
57fc801750SMarek Vasut int drm_of_get_data_lanes_count_ep(const struct device_node *port,
58fc801750SMarek Vasut int port_reg, int reg,
59fc801750SMarek Vasut const unsigned int min,
60fc801750SMarek Vasut const unsigned int max);
617e435aadSRussell King #else
drm_of_crtc_port_mask(struct drm_device * dev,struct device_node * port)628b5f7a62SJernej Skrabec static inline uint32_t drm_of_crtc_port_mask(struct drm_device *dev,
638b5f7a62SJernej Skrabec struct device_node *port)
648b5f7a62SJernej Skrabec {
658b5f7a62SJernej Skrabec return 0;
668b5f7a62SJernej Skrabec }
678b5f7a62SJernej Skrabec
drm_of_find_possible_crtcs(struct drm_device * dev,struct device_node * port)687e435aadSRussell King static inline uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
697e435aadSRussell King struct device_node *port)
707e435aadSRussell King {
717e435aadSRussell King return 0;
727e435aadSRussell King }
73df785aa8SLiviu Dudau
74329f4c81SArnd Bergmann static inline void
drm_of_component_match_add(struct device * master,struct component_match ** matchptr,int (* compare)(struct device *,void *),struct device_node * node)75329f4c81SArnd Bergmann drm_of_component_match_add(struct device *master,
7697ac0e47SRussell King struct component_match **matchptr,
7797ac0e47SRussell King int (*compare)(struct device *, void *),
7897ac0e47SRussell King struct device_node *node)
7997ac0e47SRussell King {
8097ac0e47SRussell King }
8197ac0e47SRussell King
82df785aa8SLiviu Dudau static inline int
drm_of_component_probe(struct device * dev,int (* compare_of)(struct device *,void *),const struct component_master_ops * m_ops)83df785aa8SLiviu Dudau drm_of_component_probe(struct device *dev,
84df785aa8SLiviu Dudau int (*compare_of)(struct device *, void *),
85df785aa8SLiviu Dudau const struct component_master_ops *m_ops)
86df785aa8SLiviu Dudau {
87df785aa8SLiviu Dudau return -EINVAL;
88df785aa8SLiviu Dudau }
894cacf91fSPhilipp Zabel
drm_of_encoder_active_endpoint(struct device_node * node,struct drm_encoder * encoder,struct of_endpoint * endpoint)904cacf91fSPhilipp Zabel static inline int drm_of_encoder_active_endpoint(struct device_node *node,
914cacf91fSPhilipp Zabel struct drm_encoder *encoder,
924cacf91fSPhilipp Zabel struct of_endpoint *endpoint)
934cacf91fSPhilipp Zabel {
944cacf91fSPhilipp Zabel return -EINVAL;
954cacf91fSPhilipp Zabel }
drm_of_find_panel_or_bridge(const struct device_node * np,int port,int endpoint,struct drm_panel ** panel,struct drm_bridge ** bridge)961f2db303SRob Herring static inline int drm_of_find_panel_or_bridge(const struct device_node *np,
971f2db303SRob Herring int port, int endpoint,
981f2db303SRob Herring struct drm_panel **panel,
991f2db303SRob Herring struct drm_bridge **bridge)
1001f2db303SRob Herring {
1011f2db303SRob Herring return -EINVAL;
1021f2db303SRob Herring }
10365290075SFabrizio Castro
104528d06d4SLaurent Pinchart static inline int
drm_of_lvds_get_dual_link_pixel_order(const struct device_node * port1,const struct device_node * port2)105528d06d4SLaurent Pinchart drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
10665290075SFabrizio Castro const struct device_node *port2)
10765290075SFabrizio Castro {
10865290075SFabrizio Castro return -EINVAL;
10965290075SFabrizio Castro }
1107c4dd0a2SMarek Vasut
1117c4dd0a2SMarek Vasut static inline int
drm_of_lvds_get_data_mapping(const struct device_node * port)1127c4dd0a2SMarek Vasut drm_of_lvds_get_data_mapping(const struct device_node *port)
1137c4dd0a2SMarek Vasut {
1147c4dd0a2SMarek Vasut return -EINVAL;
1157c4dd0a2SMarek Vasut }
116fc801750SMarek Vasut
117eb6b94dbSMarek Vasut static inline int
drm_of_get_data_lanes_count(const struct device_node * endpoint,const unsigned int min,const unsigned int max)118eb6b94dbSMarek Vasut drm_of_get_data_lanes_count(const struct device_node *endpoint,
119fc801750SMarek Vasut const unsigned int min, const unsigned int max)
120fc801750SMarek Vasut {
121fc801750SMarek Vasut return -EINVAL;
122fc801750SMarek Vasut }
123fc801750SMarek Vasut
124eb6b94dbSMarek Vasut static inline int
drm_of_get_data_lanes_count_ep(const struct device_node * port,int port_reg,int reg,const unsigned int min,const unsigned int max)125eb6b94dbSMarek Vasut drm_of_get_data_lanes_count_ep(const struct device_node *port,
126eb6b94dbSMarek Vasut int port_reg, int reg,
127fc801750SMarek Vasut const unsigned int min,
128fc801750SMarek Vasut const unsigned int max)
129fc801750SMarek Vasut {
130fc801750SMarek Vasut return -EINVAL;
131fc801750SMarek Vasut }
1327e435aadSRussell King #endif
1337e435aadSRussell King
134*19ff997fSChris Morgan #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_MIPI_DSI)
135*19ff997fSChris Morgan struct mipi_dsi_host *drm_of_get_dsi_bus(struct device *dev);
136*19ff997fSChris Morgan #else
137*19ff997fSChris Morgan static inline struct
drm_of_get_dsi_bus(struct device * dev)138*19ff997fSChris Morgan mipi_dsi_host *drm_of_get_dsi_bus(struct device *dev)
139*19ff997fSChris Morgan {
140*19ff997fSChris Morgan return ERR_PTR(-EINVAL);
141*19ff997fSChris Morgan }
142*19ff997fSChris Morgan #endif /* CONFIG_OF && CONFIG_DRM_MIPI_DSI */
143*19ff997fSChris Morgan
144512721a1SMaarten Lankhorst /*
145512721a1SMaarten Lankhorst * drm_of_panel_bridge_remove - remove panel bridge
146512721a1SMaarten Lankhorst * @np: device tree node containing panel bridge output ports
147512721a1SMaarten Lankhorst *
148512721a1SMaarten Lankhorst * Remove the panel bridge of a given DT node's port and endpoint number
149512721a1SMaarten Lankhorst *
150512721a1SMaarten Lankhorst * Returns zero if successful, or one of the standard error codes if it fails.
151512721a1SMaarten Lankhorst */
drm_of_panel_bridge_remove(const struct device_node * np,int port,int endpoint)152c70087e8Sbenjamin.gaignard@linaro.org static inline int drm_of_panel_bridge_remove(const struct device_node *np,
153c70087e8Sbenjamin.gaignard@linaro.org int port, int endpoint)
154c70087e8Sbenjamin.gaignard@linaro.org {
155512721a1SMaarten Lankhorst #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE)
156512721a1SMaarten Lankhorst struct drm_bridge *bridge;
157512721a1SMaarten Lankhorst struct device_node *remote;
158512721a1SMaarten Lankhorst
159512721a1SMaarten Lankhorst remote = of_graph_get_remote_node(np, port, endpoint);
160512721a1SMaarten Lankhorst if (!remote)
161512721a1SMaarten Lankhorst return -ENODEV;
162512721a1SMaarten Lankhorst
163512721a1SMaarten Lankhorst bridge = of_drm_find_bridge(remote);
164512721a1SMaarten Lankhorst drm_panel_bridge_remove(bridge);
165512721a1SMaarten Lankhorst
166512721a1SMaarten Lankhorst return 0;
167512721a1SMaarten Lankhorst #else
168c70087e8Sbenjamin.gaignard@linaro.org return -EINVAL;
1697e435aadSRussell King #endif
170512721a1SMaarten Lankhorst }
1717e435aadSRussell King
drm_of_encoder_active_endpoint_id(struct device_node * node,struct drm_encoder * encoder)1724cacf91fSPhilipp Zabel static inline int drm_of_encoder_active_endpoint_id(struct device_node *node,
1734cacf91fSPhilipp Zabel struct drm_encoder *encoder)
1744cacf91fSPhilipp Zabel {
1754cacf91fSPhilipp Zabel struct of_endpoint endpoint;
1764cacf91fSPhilipp Zabel int ret = drm_of_encoder_active_endpoint(node, encoder,
1774cacf91fSPhilipp Zabel &endpoint);
1784cacf91fSPhilipp Zabel
1794cacf91fSPhilipp Zabel return ret ?: endpoint.id;
1804cacf91fSPhilipp Zabel }
1814cacf91fSPhilipp Zabel
drm_of_encoder_active_port_id(struct device_node * node,struct drm_encoder * encoder)1824cacf91fSPhilipp Zabel static inline int drm_of_encoder_active_port_id(struct device_node *node,
1834cacf91fSPhilipp Zabel struct drm_encoder *encoder)
1844cacf91fSPhilipp Zabel {
1854cacf91fSPhilipp Zabel struct of_endpoint endpoint;
1864cacf91fSPhilipp Zabel int ret = drm_of_encoder_active_endpoint(node, encoder,
1874cacf91fSPhilipp Zabel &endpoint);
1884cacf91fSPhilipp Zabel
1894cacf91fSPhilipp Zabel return ret ?: endpoint.port;
1904cacf91fSPhilipp Zabel }
1914cacf91fSPhilipp Zabel
1927e435aadSRussell King #endif /* __DRM_OF_H__ */
193