Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Russell King | 7e435aa | 2014-06-15 11:07:12 +0100 | [diff] [blame] | 2 | #ifndef __DRM_OF_H__ |
| 3 | #define __DRM_OF_H__ |
| 4 | |
Philipp Zabel | 4cacf91 | 2015-02-24 11:34:01 +0100 | [diff] [blame] | 5 | #include <linux/of_graph.h> |
Maarten Lankhorst | 512721a | 2017-10-13 16:08:53 +0200 | [diff] [blame] | 6 | #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE) |
| 7 | #include <drm/drm_bridge.h> |
| 8 | #endif |
Philipp Zabel | 4cacf91 | 2015-02-24 11:34:01 +0100 | [diff] [blame] | 9 | |
Liviu Dudau | df785aa | 2015-10-20 10:23:12 +0100 | [diff] [blame] | 10 | struct component_master_ops; |
Russell King | 97ac0e4 | 2016-10-19 11:28:27 +0100 | [diff] [blame] | 11 | struct component_match; |
Liviu Dudau | df785aa | 2015-10-20 10:23:12 +0100 | [diff] [blame] | 12 | struct device; |
Russell King | 7e435aa | 2014-06-15 11:07:12 +0100 | [diff] [blame] | 13 | struct drm_device; |
Philipp Zabel | 4cacf91 | 2015-02-24 11:34:01 +0100 | [diff] [blame] | 14 | struct drm_encoder; |
Rob Herring | 1f2db30 | 2017-03-22 08:26:05 -0500 | [diff] [blame] | 15 | struct drm_panel; |
| 16 | struct drm_bridge; |
Russell King | 7e435aa | 2014-06-15 11:07:12 +0100 | [diff] [blame] | 17 | struct device_node; |
| 18 | |
| 19 | #ifdef CONFIG_OF |
Jernej Skrabec | 8b5f7a6 | 2018-06-25 14:03:01 +0200 | [diff] [blame] | 20 | uint32_t drm_of_crtc_port_mask(struct drm_device *dev, |
| 21 | struct device_node *port); |
Daniel Vetter | 91faa04 | 2017-03-22 09:36:02 +0100 | [diff] [blame] | 22 | uint32_t drm_of_find_possible_crtcs(struct drm_device *dev, |
| 23 | struct device_node *port); |
| 24 | void drm_of_component_match_add(struct device *master, |
| 25 | struct component_match **matchptr, |
| 26 | int (*compare)(struct device *, void *), |
| 27 | struct device_node *node); |
| 28 | int drm_of_component_probe(struct device *dev, |
| 29 | int (*compare_of)(struct device *, void *), |
| 30 | const struct component_master_ops *m_ops); |
| 31 | int drm_of_encoder_active_endpoint(struct device_node *node, |
| 32 | struct drm_encoder *encoder, |
| 33 | struct of_endpoint *endpoint); |
Rob Herring | 1f2db30 | 2017-03-22 08:26:05 -0500 | [diff] [blame] | 34 | int 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); |
Russell King | 7e435aa | 2014-06-15 11:07:12 +0100 | [diff] [blame] | 38 | #else |
Jernej Skrabec | 8b5f7a6 | 2018-06-25 14:03:01 +0200 | [diff] [blame] | 39 | static inline uint32_t drm_of_crtc_port_mask(struct drm_device *dev, |
| 40 | struct device_node *port) |
| 41 | { |
| 42 | return 0; |
| 43 | } |
| 44 | |
Russell King | 7e435aa | 2014-06-15 11:07:12 +0100 | [diff] [blame] | 45 | static inline uint32_t drm_of_find_possible_crtcs(struct drm_device *dev, |
| 46 | struct device_node *port) |
| 47 | { |
| 48 | return 0; |
| 49 | } |
Liviu Dudau | df785aa | 2015-10-20 10:23:12 +0100 | [diff] [blame] | 50 | |
Arnd Bergmann | 329f4c8 | 2016-10-26 10:57:47 +0200 | [diff] [blame] | 51 | static inline void |
| 52 | drm_of_component_match_add(struct device *master, |
| 53 | struct component_match **matchptr, |
| 54 | int (*compare)(struct device *, void *), |
| 55 | struct device_node *node) |
Russell King | 97ac0e4 | 2016-10-19 11:28:27 +0100 | [diff] [blame] | 56 | { |
| 57 | } |
| 58 | |
Liviu Dudau | df785aa | 2015-10-20 10:23:12 +0100 | [diff] [blame] | 59 | static inline int |
| 60 | drm_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 | } |
Philipp Zabel | 4cacf91 | 2015-02-24 11:34:01 +0100 | [diff] [blame] | 66 | |
| 67 | static 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 | } |
Rob Herring | 1f2db30 | 2017-03-22 08:26:05 -0500 | [diff] [blame] | 73 | static 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 | } |
Russell King | 7e435aa | 2014-06-15 11:07:12 +0100 | [diff] [blame] | 80 | #endif |
| 81 | |
Maarten Lankhorst | 512721a | 2017-10-13 16:08:53 +0200 | [diff] [blame] | 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 | */ |
benjamin.gaignard@linaro.org | c70087e | 2017-10-02 11:34:45 +0200 | [diff] [blame] | 90 | static inline int drm_of_panel_bridge_remove(const struct device_node *np, |
| 91 | int port, int endpoint) |
| 92 | { |
Maarten Lankhorst | 512721a | 2017-10-13 16:08:53 +0200 | [diff] [blame] | 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 |
benjamin.gaignard@linaro.org | c70087e | 2017-10-02 11:34:45 +0200 | [diff] [blame] | 106 | return -EINVAL; |
Russell King | 7e435aa | 2014-06-15 11:07:12 +0100 | [diff] [blame] | 107 | #endif |
Maarten Lankhorst | 512721a | 2017-10-13 16:08:53 +0200 | [diff] [blame] | 108 | } |
Russell King | 7e435aa | 2014-06-15 11:07:12 +0100 | [diff] [blame] | 109 | |
Philipp Zabel | 4cacf91 | 2015-02-24 11:34:01 +0100 | [diff] [blame] | 110 | static 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 | |
| 120 | static 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 | |
Russell King | 7e435aa | 2014-06-15 11:07:12 +0100 | [diff] [blame] | 130 | #endif /* __DRM_OF_H__ */ |