blob: b93c239afb608e04f2d06149833488cd66db4d88 [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
19#ifdef CONFIG_OF
Daniel Vetter91faa042017-03-22 09:36:02 +010020uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
21 struct device_node *port);
22void drm_of_component_match_add(struct device *master,
23 struct component_match **matchptr,
24 int (*compare)(struct device *, void *),
25 struct device_node *node);
26int drm_of_component_probe(struct device *dev,
27 int (*compare_of)(struct device *, void *),
28 const struct component_master_ops *m_ops);
29int drm_of_encoder_active_endpoint(struct device_node *node,
30 struct drm_encoder *encoder,
31 struct of_endpoint *endpoint);
Rob Herring1f2db302017-03-22 08:26:05 -050032int drm_of_find_panel_or_bridge(const struct device_node *np,
33 int port, int endpoint,
34 struct drm_panel **panel,
35 struct drm_bridge **bridge);
Russell King7e435aa2014-06-15 11:07:12 +010036#else
37static inline uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
38 struct device_node *port)
39{
40 return 0;
41}
Liviu Dudaudf785aa2015-10-20 10:23:12 +010042
Arnd Bergmann329f4c82016-10-26 10:57:47 +020043static inline void
44drm_of_component_match_add(struct device *master,
45 struct component_match **matchptr,
46 int (*compare)(struct device *, void *),
47 struct device_node *node)
Russell King97ac0e42016-10-19 11:28:27 +010048{
49}
50
Liviu Dudaudf785aa2015-10-20 10:23:12 +010051static inline int
52drm_of_component_probe(struct device *dev,
53 int (*compare_of)(struct device *, void *),
54 const struct component_master_ops *m_ops)
55{
56 return -EINVAL;
57}
Philipp Zabel4cacf912015-02-24 11:34:01 +010058
59static inline int drm_of_encoder_active_endpoint(struct device_node *node,
60 struct drm_encoder *encoder,
61 struct of_endpoint *endpoint)
62{
63 return -EINVAL;
64}
Rob Herring1f2db302017-03-22 08:26:05 -050065static inline int drm_of_find_panel_or_bridge(const struct device_node *np,
66 int port, int endpoint,
67 struct drm_panel **panel,
68 struct drm_bridge **bridge)
69{
70 return -EINVAL;
71}
Russell King7e435aa2014-06-15 11:07:12 +010072#endif
73
Maarten Lankhorst512721a2017-10-13 16:08:53 +020074/*
75 * drm_of_panel_bridge_remove - remove panel bridge
76 * @np: device tree node containing panel bridge output ports
77 *
78 * Remove the panel bridge of a given DT node's port and endpoint number
79 *
80 * Returns zero if successful, or one of the standard error codes if it fails.
81 */
benjamin.gaignard@linaro.orgc70087e2017-10-02 11:34:45 +020082static inline int drm_of_panel_bridge_remove(const struct device_node *np,
83 int port, int endpoint)
84{
Maarten Lankhorst512721a2017-10-13 16:08:53 +020085#if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE)
86 struct drm_bridge *bridge;
87 struct device_node *remote;
88
89 remote = of_graph_get_remote_node(np, port, endpoint);
90 if (!remote)
91 return -ENODEV;
92
93 bridge = of_drm_find_bridge(remote);
94 drm_panel_bridge_remove(bridge);
95
96 return 0;
97#else
benjamin.gaignard@linaro.orgc70087e2017-10-02 11:34:45 +020098 return -EINVAL;
Russell King7e435aa2014-06-15 11:07:12 +010099#endif
Maarten Lankhorst512721a2017-10-13 16:08:53 +0200100}
Russell King7e435aa2014-06-15 11:07:12 +0100101
Philipp Zabel4cacf912015-02-24 11:34:01 +0100102static inline int drm_of_encoder_active_endpoint_id(struct device_node *node,
103 struct drm_encoder *encoder)
104{
105 struct of_endpoint endpoint;
106 int ret = drm_of_encoder_active_endpoint(node, encoder,
107 &endpoint);
108
109 return ret ?: endpoint.id;
110}
111
112static inline int drm_of_encoder_active_port_id(struct device_node *node,
113 struct drm_encoder *encoder)
114{
115 struct of_endpoint endpoint;
116 int ret = drm_of_encoder_active_endpoint(node, encoder,
117 &endpoint);
118
119 return ret ?: endpoint.port;
120}
121
Russell King7e435aa2014-06-15 11:07:12 +0100122#endif /* __DRM_OF_H__ */