Loading...
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;
18
19#ifdef CONFIG_OF
20uint32_t drm_of_crtc_port_mask(struct drm_device *dev,
21 struct device_node *port);
22uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
23 struct device_node *port);
24void drm_of_component_match_add(struct device *master,
25 struct component_match **matchptr,
26 int (*compare)(struct device *, void *),
27 struct device_node *node);
28int drm_of_component_probe(struct device *dev,
29 int (*compare_of)(struct device *, void *),
30 const struct component_master_ops *m_ops);
31int drm_of_encoder_active_endpoint(struct device_node *node,
32 struct drm_encoder *encoder,
33 struct of_endpoint *endpoint);
34int drm_of_find_panel_or_bridge(const struct device_node *np,
35 int port, int endpoint,
36 struct drm_panel **panel,
37 struct drm_bridge **bridge);
38#else
39static inline uint32_t drm_of_crtc_port_mask(struct drm_device *dev,
40 struct device_node *port)
41{
42 return 0;
43}
44
45static inline uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
46 struct device_node *port)
47{
48 return 0;
49}
50
51static inline void
52drm_of_component_match_add(struct device *master,
53 struct component_match **matchptr,
54 int (*compare)(struct device *, void *),
55 struct device_node *node)
56{
57}
58
59static inline int
60drm_of_component_probe(struct device *dev,
61 int (*compare_of)(struct device *, void *),
62 const struct component_master_ops *m_ops)
63{
64 return -EINVAL;
65}
66
67static inline int drm_of_encoder_active_endpoint(struct device_node *node,
68 struct drm_encoder *encoder,
69 struct of_endpoint *endpoint)
70{
71 return -EINVAL;
72}
73static inline int drm_of_find_panel_or_bridge(const struct device_node *np,
74 int port, int endpoint,
75 struct drm_panel **panel,
76 struct drm_bridge **bridge)
77{
78 return -EINVAL;
79}
80#endif
81
82/*
83 * drm_of_panel_bridge_remove - remove panel bridge
84 * @np: device tree node containing panel bridge output ports
85 *
86 * Remove the panel bridge of a given DT node's port and endpoint number
87 *
88 * Returns zero if successful, or one of the standard error codes if it fails.
89 */
90static inline int drm_of_panel_bridge_remove(const struct device_node *np,
91 int port, int endpoint)
92{
93#if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE)
94 struct drm_bridge *bridge;
95 struct device_node *remote;
96
97 remote = of_graph_get_remote_node(np, port, endpoint);
98 if (!remote)
99 return -ENODEV;
100
101 bridge = of_drm_find_bridge(remote);
102 drm_panel_bridge_remove(bridge);
103
104 return 0;
105#else
106 return -EINVAL;
107#endif
108}
109
110static inline int drm_of_encoder_active_endpoint_id(struct device_node *node,
111 struct drm_encoder *encoder)
112{
113 struct of_endpoint endpoint;
114 int ret = drm_of_encoder_active_endpoint(node, encoder,
115 &endpoint);
116
117 return ret ?: endpoint.id;
118}
119
120static inline int drm_of_encoder_active_port_id(struct device_node *node,
121 struct drm_encoder *encoder)
122{
123 struct of_endpoint endpoint;
124 int ret = drm_of_encoder_active_endpoint(node, encoder,
125 &endpoint);
126
127 return ret ?: endpoint.port;
128}
129
130#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;
18
19/**
20 * enum drm_lvds_dual_link_pixels - Pixel order of an LVDS dual-link connection
21 * @DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS: Even pixels are expected to be generated
22 * from the first port, odd pixels from the second port
23 * @DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS: Odd pixels are expected to be generated
24 * from the first port, even pixels from the second port
25 */
26enum drm_lvds_dual_link_pixels {
27 DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS = 0,
28 DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS = 1,
29};
30
31#ifdef CONFIG_OF
32uint32_t drm_of_crtc_port_mask(struct drm_device *dev,
33 struct device_node *port);
34uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
35 struct device_node *port);
36void drm_of_component_match_add(struct device *master,
37 struct component_match **matchptr,
38 int (*compare)(struct device *, void *),
39 struct device_node *node);
40int drm_of_component_probe(struct device *dev,
41 int (*compare_of)(struct device *, void *),
42 const struct component_master_ops *m_ops);
43int drm_of_encoder_active_endpoint(struct device_node *node,
44 struct drm_encoder *encoder,
45 struct of_endpoint *endpoint);
46int drm_of_find_panel_or_bridge(const struct device_node *np,
47 int port, int endpoint,
48 struct drm_panel **panel,
49 struct drm_bridge **bridge);
50int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
51 const struct device_node *port2);
52#else
53static inline uint32_t drm_of_crtc_port_mask(struct drm_device *dev,
54 struct device_node *port)
55{
56 return 0;
57}
58
59static inline uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
60 struct device_node *port)
61{
62 return 0;
63}
64
65static inline void
66drm_of_component_match_add(struct device *master,
67 struct component_match **matchptr,
68 int (*compare)(struct device *, void *),
69 struct device_node *node)
70{
71}
72
73static inline int
74drm_of_component_probe(struct device *dev,
75 int (*compare_of)(struct device *, void *),
76 const struct component_master_ops *m_ops)
77{
78 return -EINVAL;
79}
80
81static inline int drm_of_encoder_active_endpoint(struct device_node *node,
82 struct drm_encoder *encoder,
83 struct of_endpoint *endpoint)
84{
85 return -EINVAL;
86}
87static inline int drm_of_find_panel_or_bridge(const struct device_node *np,
88 int port, int endpoint,
89 struct drm_panel **panel,
90 struct drm_bridge **bridge)
91{
92 return -EINVAL;
93}
94
95static inline int
96drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
97 const struct device_node *port2)
98{
99 return -EINVAL;
100}
101#endif
102
103/*
104 * drm_of_panel_bridge_remove - remove panel bridge
105 * @np: device tree node containing panel bridge output ports
106 *
107 * Remove the panel bridge of a given DT node's port and endpoint number
108 *
109 * Returns zero if successful, or one of the standard error codes if it fails.
110 */
111static inline int drm_of_panel_bridge_remove(const struct device_node *np,
112 int port, int endpoint)
113{
114#if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE)
115 struct drm_bridge *bridge;
116 struct device_node *remote;
117
118 remote = of_graph_get_remote_node(np, port, endpoint);
119 if (!remote)
120 return -ENODEV;
121
122 bridge = of_drm_find_bridge(remote);
123 drm_panel_bridge_remove(bridge);
124
125 return 0;
126#else
127 return -EINVAL;
128#endif
129}
130
131static inline int drm_of_encoder_active_endpoint_id(struct device_node *node,
132 struct drm_encoder *encoder)
133{
134 struct of_endpoint endpoint;
135 int ret = drm_of_encoder_active_endpoint(node, encoder,
136 &endpoint);
137
138 return ret ?: endpoint.id;
139}
140
141static inline int drm_of_encoder_active_port_id(struct device_node *node,
142 struct drm_encoder *encoder)
143{
144 struct of_endpoint endpoint;
145 int ret = drm_of_encoder_active_endpoint(node, encoder,
146 &endpoint);
147
148 return ret ?: endpoint.port;
149}
150
151#endif /* __DRM_OF_H__ */