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