blob: b9b093add92e792555778084472c536ffd897367 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Russell King7e435aa2014-06-15 11:07:12 +01002#ifndef __DRM_OF_H__
3#define __DRM_OF_H__
4
Philipp Zabel4cacf912015-02-24 11:34:01 +01005#include <linux/of_graph.h>
Maarten Lankhorst512721a2017-10-13 16:08:53 +02006#if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE)
7#include <drm/drm_bridge.h>
8#endif
Philipp Zabel4cacf912015-02-24 11:34:01 +01009
Liviu Dudaudf785aa2015-10-20 10:23:12 +010010struct component_master_ops;
Russell King97ac0e42016-10-19 11:28:27 +010011struct component_match;
Liviu Dudaudf785aa2015-10-20 10:23:12 +010012struct device;
Russell King7e435aa2014-06-15 11:07:12 +010013struct drm_device;
Philipp Zabel4cacf912015-02-24 11:34:01 +010014struct drm_encoder;
Rob Herring1f2db302017-03-22 08:26:05 -050015struct drm_panel;
16struct drm_bridge;
Russell King7e435aa2014-06-15 11:07:12 +010017struct device_node;
18
Fabrizio Castro65290072019-12-17 13:45:56 +000019/**
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
Russell King7e435aa2014-06-15 11:07:12 +010031#ifdef CONFIG_OF
Jernej Skrabec8b5f7a62018-06-25 14:03:01 +020032uint32_t drm_of_crtc_port_mask(struct drm_device *dev,
33 struct device_node *port);
Daniel Vetter91faa042017-03-22 09:36:02 +010034uint32_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);
Rob Herring1f2db302017-03-22 08:26:05 -050046int 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);
Fabrizio Castro65290072019-12-17 13:45:56 +000050int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
51 const struct device_node *port2);
Russell King7e435aa2014-06-15 11:07:12 +010052#else
Jernej Skrabec8b5f7a62018-06-25 14:03:01 +020053static inline uint32_t drm_of_crtc_port_mask(struct drm_device *dev,
54 struct device_node *port)
55{
56 return 0;
57}
58
Russell King7e435aa2014-06-15 11:07:12 +010059static inline uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
60 struct device_node *port)
61{
62 return 0;
63}
Liviu Dudaudf785aa2015-10-20 10:23:12 +010064
Arnd Bergmann329f4c82016-10-26 10:57:47 +020065static 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)
Russell King97ac0e42016-10-19 11:28:27 +010070{
71}
72
Liviu Dudaudf785aa2015-10-20 10:23:12 +010073static 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}
Philipp Zabel4cacf912015-02-24 11:34:01 +010080
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}
Rob Herring1f2db302017-03-22 08:26:05 -050087static 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}
Fabrizio Castro65290072019-12-17 13:45:56 +000094
Laurent Pinchart528d06d2019-12-19 12:37:03 +020095static inline int
96drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
97 const struct device_node *port2)
Fabrizio Castro65290072019-12-17 13:45:56 +000098{
99 return -EINVAL;
100}
Russell King7e435aa2014-06-15 11:07:12 +0100101#endif
102
Maarten Lankhorst512721a2017-10-13 16:08:53 +0200103/*
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 */
benjamin.gaignard@linaro.orgc70087e2017-10-02 11:34:45 +0200111static inline int drm_of_panel_bridge_remove(const struct device_node *np,
112 int port, int endpoint)
113{
Maarten Lankhorst512721a2017-10-13 16:08:53 +0200114#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
benjamin.gaignard@linaro.orgc70087e2017-10-02 11:34:45 +0200127 return -EINVAL;
Russell King7e435aa2014-06-15 11:07:12 +0100128#endif
Maarten Lankhorst512721a2017-10-13 16:08:53 +0200129}
Russell King7e435aa2014-06-15 11:07:12 +0100130
Philipp Zabel4cacf912015-02-24 11:34:01 +0100131static 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
Russell King7e435aa2014-06-15 11:07:12 +0100151#endif /* __DRM_OF_H__ */