Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
7e435aad RK |
2 | #ifndef __DRM_OF_H__ |
3 | #define __DRM_OF_H__ | |
4 | ||
4cacf91f | 5 | #include <linux/of_graph.h> |
512721a1 ML |
6 | #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE) |
7 | #include <drm/drm_bridge.h> | |
8 | #endif | |
4cacf91f | 9 | |
df785aa8 | 10 | struct component_master_ops; |
97ac0e47 | 11 | struct component_match; |
df785aa8 | 12 | struct device; |
7e435aad | 13 | struct drm_device; |
4cacf91f | 14 | struct drm_encoder; |
1f2db303 RH |
15 | struct drm_panel; |
16 | struct drm_bridge; | |
7e435aad | 17 | struct device_node; |
19ff997f CM |
18 | struct mipi_dsi_device_info; |
19 | struct mipi_dsi_host; | |
7e435aad | 20 | |
65290075 FC |
21 | /** |
22 | * enum drm_lvds_dual_link_pixels - Pixel order of an LVDS dual-link connection | |
23 | * @DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS: Even pixels are expected to be generated | |
24 | * from the first port, odd pixels from the second port | |
25 | * @DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS: Odd pixels are expected to be generated | |
26 | * from the first port, even pixels from the second port | |
27 | */ | |
28 | enum drm_lvds_dual_link_pixels { | |
29 | DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS = 0, | |
30 | DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS = 1, | |
31 | }; | |
32 | ||
7e435aad | 33 | #ifdef CONFIG_OF |
8b5f7a62 JS |
34 | uint32_t drm_of_crtc_port_mask(struct drm_device *dev, |
35 | struct device_node *port); | |
91faa047 DV |
36 | uint32_t drm_of_find_possible_crtcs(struct drm_device *dev, |
37 | struct device_node *port); | |
38 | void drm_of_component_match_add(struct device *master, | |
39 | struct component_match **matchptr, | |
40 | int (*compare)(struct device *, void *), | |
41 | struct device_node *node); | |
42 | int drm_of_component_probe(struct device *dev, | |
43 | int (*compare_of)(struct device *, void *), | |
44 | const struct component_master_ops *m_ops); | |
45 | int drm_of_encoder_active_endpoint(struct device_node *node, | |
46 | struct drm_encoder *encoder, | |
47 | struct of_endpoint *endpoint); | |
1f2db303 RH |
48 | int drm_of_find_panel_or_bridge(const struct device_node *np, |
49 | int port, int endpoint, | |
50 | struct drm_panel **panel, | |
51 | struct drm_bridge **bridge); | |
65290075 FC |
52 | int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1, |
53 | const struct device_node *port2); | |
7c4dd0a2 | 54 | int drm_of_lvds_get_data_mapping(const struct device_node *port); |
fc801750 MV |
55 | int drm_of_get_data_lanes_count(const struct device_node *endpoint, |
56 | const unsigned int min, const unsigned int max); | |
57 | int drm_of_get_data_lanes_count_ep(const struct device_node *port, | |
58 | int port_reg, int reg, | |
59 | const unsigned int min, | |
60 | const unsigned int max); | |
7e435aad | 61 | #else |
8b5f7a62 JS |
62 | static inline uint32_t drm_of_crtc_port_mask(struct drm_device *dev, |
63 | struct device_node *port) | |
64 | { | |
65 | return 0; | |
66 | } | |
67 | ||
7e435aad RK |
68 | static inline uint32_t drm_of_find_possible_crtcs(struct drm_device *dev, |
69 | struct device_node *port) | |
70 | { | |
71 | return 0; | |
72 | } | |
df785aa8 | 73 | |
329f4c81 AB |
74 | static inline void |
75 | drm_of_component_match_add(struct device *master, | |
76 | struct component_match **matchptr, | |
77 | int (*compare)(struct device *, void *), | |
78 | struct device_node *node) | |
97ac0e47 RK |
79 | { |
80 | } | |
81 | ||
df785aa8 LD |
82 | static inline int |
83 | drm_of_component_probe(struct device *dev, | |
84 | int (*compare_of)(struct device *, void *), | |
85 | const struct component_master_ops *m_ops) | |
86 | { | |
87 | return -EINVAL; | |
88 | } | |
4cacf91f PZ |
89 | |
90 | static inline int drm_of_encoder_active_endpoint(struct device_node *node, | |
91 | struct drm_encoder *encoder, | |
92 | struct of_endpoint *endpoint) | |
93 | { | |
94 | return -EINVAL; | |
95 | } | |
1f2db303 RH |
96 | static inline int drm_of_find_panel_or_bridge(const struct device_node *np, |
97 | int port, int endpoint, | |
98 | struct drm_panel **panel, | |
99 | struct drm_bridge **bridge) | |
100 | { | |
101 | return -EINVAL; | |
102 | } | |
65290075 | 103 | |
528d06d4 LP |
104 | static inline int |
105 | drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1, | |
106 | const struct device_node *port2) | |
65290075 FC |
107 | { |
108 | return -EINVAL; | |
109 | } | |
7c4dd0a2 MV |
110 | |
111 | static inline int | |
112 | drm_of_lvds_get_data_mapping(const struct device_node *port) | |
113 | { | |
114 | return -EINVAL; | |
115 | } | |
fc801750 | 116 | |
eb6b94db MV |
117 | static inline int |
118 | drm_of_get_data_lanes_count(const struct device_node *endpoint, | |
119 | const unsigned int min, const unsigned int max) | |
fc801750 MV |
120 | { |
121 | return -EINVAL; | |
122 | } | |
123 | ||
eb6b94db MV |
124 | static inline int |
125 | drm_of_get_data_lanes_count_ep(const struct device_node *port, | |
126 | int port_reg, int reg, | |
127 | const unsigned int min, | |
128 | const unsigned int max) | |
fc801750 MV |
129 | { |
130 | return -EINVAL; | |
131 | } | |
7e435aad RK |
132 | #endif |
133 | ||
19ff997f CM |
134 | #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_MIPI_DSI) |
135 | struct mipi_dsi_host *drm_of_get_dsi_bus(struct device *dev); | |
136 | #else | |
137 | static inline struct | |
138 | mipi_dsi_host *drm_of_get_dsi_bus(struct device *dev) | |
139 | { | |
140 | return ERR_PTR(-EINVAL); | |
141 | } | |
142 | #endif /* CONFIG_OF && CONFIG_DRM_MIPI_DSI */ | |
143 | ||
512721a1 ML |
144 | /* |
145 | * drm_of_panel_bridge_remove - remove panel bridge | |
146 | * @np: device tree node containing panel bridge output ports | |
147 | * | |
148 | * Remove the panel bridge of a given DT node's port and endpoint number | |
149 | * | |
150 | * Returns zero if successful, or one of the standard error codes if it fails. | |
151 | */ | |
c70087e8 | 152 | static inline int drm_of_panel_bridge_remove(const struct device_node *np, |
153 | int port, int endpoint) | |
154 | { | |
512721a1 ML |
155 | #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE) |
156 | struct drm_bridge *bridge; | |
157 | struct device_node *remote; | |
158 | ||
159 | remote = of_graph_get_remote_node(np, port, endpoint); | |
160 | if (!remote) | |
161 | return -ENODEV; | |
162 | ||
163 | bridge = of_drm_find_bridge(remote); | |
164 | drm_panel_bridge_remove(bridge); | |
165 | ||
166 | return 0; | |
167 | #else | |
c70087e8 | 168 | return -EINVAL; |
7e435aad | 169 | #endif |
512721a1 | 170 | } |
7e435aad | 171 | |
4cacf91f PZ |
172 | static inline int drm_of_encoder_active_endpoint_id(struct device_node *node, |
173 | struct drm_encoder *encoder) | |
174 | { | |
175 | struct of_endpoint endpoint; | |
176 | int ret = drm_of_encoder_active_endpoint(node, encoder, | |
177 | &endpoint); | |
178 | ||
179 | return ret ?: endpoint.id; | |
180 | } | |
181 | ||
182 | static inline int drm_of_encoder_active_port_id(struct device_node *node, | |
183 | struct drm_encoder *encoder) | |
184 | { | |
185 | struct of_endpoint endpoint; | |
186 | int ret = drm_of_encoder_active_endpoint(node, encoder, | |
187 | &endpoint); | |
188 | ||
189 | return ret ?: endpoint.port; | |
190 | } | |
191 | ||
7e435aad | 192 | #endif /* __DRM_OF_H__ */ |