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 | |
Fabrizio Castro | 6529007 | 2019-12-17 13:45:56 +0000 | [diff] [blame] | 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 | */ |
| 26 | enum 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 King | 7e435aa | 2014-06-15 11:07:12 +0100 | [diff] [blame] | 31 | #ifdef CONFIG_OF |
Jernej Skrabec | 8b5f7a6 | 2018-06-25 14:03:01 +0200 | [diff] [blame] | 32 | uint32_t drm_of_crtc_port_mask(struct drm_device *dev, |
| 33 | struct device_node *port); |
Daniel Vetter | 91faa04 | 2017-03-22 09:36:02 +0100 | [diff] [blame] | 34 | uint32_t drm_of_find_possible_crtcs(struct drm_device *dev, |
| 35 | struct device_node *port); |
| 36 | void drm_of_component_match_add(struct device *master, |
| 37 | struct component_match **matchptr, |
| 38 | int (*compare)(struct device *, void *), |
| 39 | struct device_node *node); |
| 40 | int drm_of_component_probe(struct device *dev, |
| 41 | int (*compare_of)(struct device *, void *), |
| 42 | const struct component_master_ops *m_ops); |
| 43 | int drm_of_encoder_active_endpoint(struct device_node *node, |
| 44 | struct drm_encoder *encoder, |
| 45 | struct of_endpoint *endpoint); |
Rob Herring | 1f2db30 | 2017-03-22 08:26:05 -0500 | [diff] [blame] | 46 | int 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 Castro | 6529007 | 2019-12-17 13:45:56 +0000 | [diff] [blame] | 50 | int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1, |
| 51 | const struct device_node *port2); |
Marek Vasut | 7c4dd0a | 2021-10-13 00:42:52 +0200 | [diff] [blame] | 52 | int drm_of_lvds_get_data_mapping(const struct device_node *port); |
Russell King | 7e435aa | 2014-06-15 11:07:12 +0100 | [diff] [blame] | 53 | #else |
Jernej Skrabec | 8b5f7a6 | 2018-06-25 14:03:01 +0200 | [diff] [blame] | 54 | static inline uint32_t drm_of_crtc_port_mask(struct drm_device *dev, |
| 55 | struct device_node *port) |
| 56 | { |
| 57 | return 0; |
| 58 | } |
| 59 | |
Russell King | 7e435aa | 2014-06-15 11:07:12 +0100 | [diff] [blame] | 60 | static inline uint32_t drm_of_find_possible_crtcs(struct drm_device *dev, |
| 61 | struct device_node *port) |
| 62 | { |
| 63 | return 0; |
| 64 | } |
Liviu Dudau | df785aa | 2015-10-20 10:23:12 +0100 | [diff] [blame] | 65 | |
Arnd Bergmann | 329f4c8 | 2016-10-26 10:57:47 +0200 | [diff] [blame] | 66 | static inline void |
| 67 | drm_of_component_match_add(struct device *master, |
| 68 | struct component_match **matchptr, |
| 69 | int (*compare)(struct device *, void *), |
| 70 | struct device_node *node) |
Russell King | 97ac0e4 | 2016-10-19 11:28:27 +0100 | [diff] [blame] | 71 | { |
| 72 | } |
| 73 | |
Liviu Dudau | df785aa | 2015-10-20 10:23:12 +0100 | [diff] [blame] | 74 | static inline int |
| 75 | drm_of_component_probe(struct device *dev, |
| 76 | int (*compare_of)(struct device *, void *), |
| 77 | const struct component_master_ops *m_ops) |
| 78 | { |
| 79 | return -EINVAL; |
| 80 | } |
Philipp Zabel | 4cacf91 | 2015-02-24 11:34:01 +0100 | [diff] [blame] | 81 | |
| 82 | static inline int drm_of_encoder_active_endpoint(struct device_node *node, |
| 83 | struct drm_encoder *encoder, |
| 84 | struct of_endpoint *endpoint) |
| 85 | { |
| 86 | return -EINVAL; |
| 87 | } |
Rob Herring | 1f2db30 | 2017-03-22 08:26:05 -0500 | [diff] [blame] | 88 | static inline int drm_of_find_panel_or_bridge(const struct device_node *np, |
| 89 | int port, int endpoint, |
| 90 | struct drm_panel **panel, |
| 91 | struct drm_bridge **bridge) |
| 92 | { |
| 93 | return -EINVAL; |
| 94 | } |
Fabrizio Castro | 6529007 | 2019-12-17 13:45:56 +0000 | [diff] [blame] | 95 | |
Laurent Pinchart | 528d06d | 2019-12-19 12:37:03 +0200 | [diff] [blame] | 96 | static inline int |
| 97 | drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1, |
| 98 | const struct device_node *port2) |
Fabrizio Castro | 6529007 | 2019-12-17 13:45:56 +0000 | [diff] [blame] | 99 | { |
| 100 | return -EINVAL; |
| 101 | } |
Marek Vasut | 7c4dd0a | 2021-10-13 00:42:52 +0200 | [diff] [blame] | 102 | |
| 103 | static inline int |
| 104 | drm_of_lvds_get_data_mapping(const struct device_node *port) |
| 105 | { |
| 106 | return -EINVAL; |
| 107 | } |
Russell King | 7e435aa | 2014-06-15 11:07:12 +0100 | [diff] [blame] | 108 | #endif |
| 109 | |
Maarten Lankhorst | 512721a | 2017-10-13 16:08:53 +0200 | [diff] [blame] | 110 | /* |
| 111 | * drm_of_panel_bridge_remove - remove panel bridge |
| 112 | * @np: device tree node containing panel bridge output ports |
| 113 | * |
| 114 | * Remove the panel bridge of a given DT node's port and endpoint number |
| 115 | * |
| 116 | * Returns zero if successful, or one of the standard error codes if it fails. |
| 117 | */ |
benjamin.gaignard@linaro.org | c70087e | 2017-10-02 11:34:45 +0200 | [diff] [blame] | 118 | static inline int drm_of_panel_bridge_remove(const struct device_node *np, |
| 119 | int port, int endpoint) |
| 120 | { |
Maarten Lankhorst | 512721a | 2017-10-13 16:08:53 +0200 | [diff] [blame] | 121 | #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE) |
| 122 | struct drm_bridge *bridge; |
| 123 | struct device_node *remote; |
| 124 | |
| 125 | remote = of_graph_get_remote_node(np, port, endpoint); |
| 126 | if (!remote) |
| 127 | return -ENODEV; |
| 128 | |
| 129 | bridge = of_drm_find_bridge(remote); |
| 130 | drm_panel_bridge_remove(bridge); |
| 131 | |
| 132 | return 0; |
| 133 | #else |
benjamin.gaignard@linaro.org | c70087e | 2017-10-02 11:34:45 +0200 | [diff] [blame] | 134 | return -EINVAL; |
Russell King | 7e435aa | 2014-06-15 11:07:12 +0100 | [diff] [blame] | 135 | #endif |
Maarten Lankhorst | 512721a | 2017-10-13 16:08:53 +0200 | [diff] [blame] | 136 | } |
Russell King | 7e435aa | 2014-06-15 11:07:12 +0100 | [diff] [blame] | 137 | |
Philipp Zabel | 4cacf91 | 2015-02-24 11:34:01 +0100 | [diff] [blame] | 138 | static inline int drm_of_encoder_active_endpoint_id(struct device_node *node, |
| 139 | struct drm_encoder *encoder) |
| 140 | { |
| 141 | struct of_endpoint endpoint; |
| 142 | int ret = drm_of_encoder_active_endpoint(node, encoder, |
| 143 | &endpoint); |
| 144 | |
| 145 | return ret ?: endpoint.id; |
| 146 | } |
| 147 | |
| 148 | static inline int drm_of_encoder_active_port_id(struct device_node *node, |
| 149 | struct drm_encoder *encoder) |
| 150 | { |
| 151 | struct of_endpoint endpoint; |
| 152 | int ret = drm_of_encoder_active_endpoint(node, encoder, |
| 153 | &endpoint); |
| 154 | |
| 155 | return ret ?: endpoint.port; |
| 156 | } |
| 157 | |
Russell King | 7e435aa | 2014-06-15 11:07:12 +0100 | [diff] [blame] | 158 | #endif /* __DRM_OF_H__ */ |