Ajay Kumar | 3d3f8b1 | 2015-01-20 22:08:44 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 Samsung Electronics Co., Ltd |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sub license, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the |
| 12 | * next paragraph) shall be included in all copies or substantial portions |
| 13 | * of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
| 22 | */ |
| 23 | |
| 24 | #include <linux/err.h> |
| 25 | #include <linux/module.h> |
Daniel Vetter | 199e4e9 | 2016-08-31 18:09:05 +0200 | [diff] [blame] | 26 | #include <linux/mutex.h> |
Ajay Kumar | 3d3f8b1 | 2015-01-20 22:08:44 +0530 | [diff] [blame] | 27 | |
Daniel Vetter | 199e4e9 | 2016-08-31 18:09:05 +0200 | [diff] [blame] | 28 | #include <drm/drm_bridge.h> |
Laurent Pinchart | 3bb80f2 | 2016-11-28 17:59:08 +0200 | [diff] [blame] | 29 | #include <drm/drm_encoder.h> |
Ajay Kumar | 3d3f8b1 | 2015-01-20 22:08:44 +0530 | [diff] [blame] | 30 | |
Laurent Pinchart | 4a878c0 | 2016-11-28 18:32:05 +0200 | [diff] [blame] | 31 | #include "drm_crtc_internal.h" |
| 32 | |
Archit Taneja | 2331b4e | 2015-05-21 11:03:17 +0530 | [diff] [blame] | 33 | /** |
| 34 | * DOC: overview |
| 35 | * |
Daniel Vetter | ea0dd85 | 2016-12-29 21:48:26 +0100 | [diff] [blame] | 36 | * &struct drm_bridge represents a device that hangs on to an encoder. These are |
Daniel Vetter | da024fe | 2015-12-04 09:45:47 +0100 | [diff] [blame] | 37 | * handy when a regular &drm_encoder entity isn't enough to represent the entire |
Archit Taneja | 2331b4e | 2015-05-21 11:03:17 +0530 | [diff] [blame] | 38 | * encoder chain. |
| 39 | * |
Daniel Vetter | da024fe | 2015-12-04 09:45:47 +0100 | [diff] [blame] | 40 | * A bridge is always attached to a single &drm_encoder at a time, but can be |
Daniel Vetter | da5335b | 2016-05-31 22:55:13 +0200 | [diff] [blame] | 41 | * either connected to it directly, or through an intermediate bridge:: |
Archit Taneja | 2331b4e | 2015-05-21 11:03:17 +0530 | [diff] [blame] | 42 | * |
Daniel Vetter | da024fe | 2015-12-04 09:45:47 +0100 | [diff] [blame] | 43 | * encoder ---> bridge B ---> bridge A |
Archit Taneja | 2331b4e | 2015-05-21 11:03:17 +0530 | [diff] [blame] | 44 | * |
| 45 | * Here, the output of the encoder feeds to bridge B, and that furthers feeds to |
| 46 | * bridge A. |
| 47 | * |
| 48 | * The driver using the bridge is responsible to make the associations between |
| 49 | * the encoder and bridges. Once these links are made, the bridges will |
| 50 | * participate along with encoder functions to perform mode_set/enable/disable |
Daniel Vetter | da024fe | 2015-12-04 09:45:47 +0100 | [diff] [blame] | 51 | * through the ops provided in &drm_bridge_funcs. |
Archit Taneja | 2331b4e | 2015-05-21 11:03:17 +0530 | [diff] [blame] | 52 | * |
| 53 | * drm_bridge, like drm_panel, aren't drm_mode_object entities like planes, |
Daniel Vetter | da024fe | 2015-12-04 09:45:47 +0100 | [diff] [blame] | 54 | * CRTCs, encoders or connectors and hence are not visible to userspace. They |
| 55 | * just provide additional hooks to get the desired output at the end of the |
| 56 | * encoder chain. |
| 57 | * |
Daniel Vetter | 4541d31 | 2017-01-02 09:17:26 +0100 | [diff] [blame] | 58 | * Bridges can also be chained up using the &drm_bridge.next pointer. |
Daniel Vetter | da024fe | 2015-12-04 09:45:47 +0100 | [diff] [blame] | 59 | * |
| 60 | * Both legacy CRTC helpers and the new atomic modeset helpers support bridges. |
Archit Taneja | 2331b4e | 2015-05-21 11:03:17 +0530 | [diff] [blame] | 61 | */ |
| 62 | |
Ajay Kumar | 3d3f8b1 | 2015-01-20 22:08:44 +0530 | [diff] [blame] | 63 | static DEFINE_MUTEX(bridge_lock); |
| 64 | static LIST_HEAD(bridge_list); |
| 65 | |
Archit Taneja | 2331b4e | 2015-05-21 11:03:17 +0530 | [diff] [blame] | 66 | /** |
| 67 | * drm_bridge_add - add the given bridge to the global bridge list |
| 68 | * |
| 69 | * @bridge: bridge control structure |
Archit Taneja | 2331b4e | 2015-05-21 11:03:17 +0530 | [diff] [blame] | 70 | */ |
Inki Dae | 99286884 | 2017-07-03 17:42:17 +0900 | [diff] [blame] | 71 | void drm_bridge_add(struct drm_bridge *bridge) |
Ajay Kumar | 3d3f8b1 | 2015-01-20 22:08:44 +0530 | [diff] [blame] | 72 | { |
| 73 | mutex_lock(&bridge_lock); |
| 74 | list_add_tail(&bridge->list, &bridge_list); |
| 75 | mutex_unlock(&bridge_lock); |
Ajay Kumar | 3d3f8b1 | 2015-01-20 22:08:44 +0530 | [diff] [blame] | 76 | } |
| 77 | EXPORT_SYMBOL(drm_bridge_add); |
| 78 | |
Archit Taneja | 2331b4e | 2015-05-21 11:03:17 +0530 | [diff] [blame] | 79 | /** |
| 80 | * drm_bridge_remove - remove the given bridge from the global bridge list |
| 81 | * |
| 82 | * @bridge: bridge control structure |
| 83 | */ |
Ajay Kumar | 3d3f8b1 | 2015-01-20 22:08:44 +0530 | [diff] [blame] | 84 | void drm_bridge_remove(struct drm_bridge *bridge) |
| 85 | { |
| 86 | mutex_lock(&bridge_lock); |
| 87 | list_del_init(&bridge->list); |
| 88 | mutex_unlock(&bridge_lock); |
| 89 | } |
| 90 | EXPORT_SYMBOL(drm_bridge_remove); |
| 91 | |
Archit Taneja | 2331b4e | 2015-05-21 11:03:17 +0530 | [diff] [blame] | 92 | /** |
Laurent Pinchart | 3bb80f2 | 2016-11-28 17:59:08 +0200 | [diff] [blame] | 93 | * drm_bridge_attach - attach the bridge to an encoder's chain |
Archit Taneja | 2331b4e | 2015-05-21 11:03:17 +0530 | [diff] [blame] | 94 | * |
Laurent Pinchart | 3bb80f2 | 2016-11-28 17:59:08 +0200 | [diff] [blame] | 95 | * @encoder: DRM encoder |
| 96 | * @bridge: bridge to attach |
| 97 | * @previous: previous bridge in the chain (optional) |
Archit Taneja | 2331b4e | 2015-05-21 11:03:17 +0530 | [diff] [blame] | 98 | * |
Laurent Pinchart | 3bb80f2 | 2016-11-28 17:59:08 +0200 | [diff] [blame] | 99 | * Called by a kms driver to link the bridge to an encoder's chain. The previous |
| 100 | * argument specifies the previous bridge in the chain. If NULL, the bridge is |
| 101 | * linked directly at the encoder's output. Otherwise it is linked at the |
| 102 | * previous bridge's output. |
Archit Taneja | 2331b4e | 2015-05-21 11:03:17 +0530 | [diff] [blame] | 103 | * |
Laurent Pinchart | 3bb80f2 | 2016-11-28 17:59:08 +0200 | [diff] [blame] | 104 | * If non-NULL the previous bridge must be already attached by a call to this |
| 105 | * function. |
Archit Taneja | 2331b4e | 2015-05-21 11:03:17 +0530 | [diff] [blame] | 106 | * |
Peter Rosin | 169cc4c | 2018-08-06 08:19:10 +0200 | [diff] [blame] | 107 | * Note that bridges attached to encoders are auto-detached during encoder |
| 108 | * cleanup in drm_encoder_cleanup(), so drm_bridge_attach() should generally |
| 109 | * *not* be balanced with a drm_bridge_detach() in driver code. |
| 110 | * |
Archit Taneja | 2331b4e | 2015-05-21 11:03:17 +0530 | [diff] [blame] | 111 | * RETURNS: |
| 112 | * Zero on success, error code on failure |
| 113 | */ |
Laurent Pinchart | 3bb80f2 | 2016-11-28 17:59:08 +0200 | [diff] [blame] | 114 | int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge, |
| 115 | struct drm_bridge *previous) |
Ajay Kumar | 3d3f8b1 | 2015-01-20 22:08:44 +0530 | [diff] [blame] | 116 | { |
Laurent Pinchart | 3bb80f2 | 2016-11-28 17:59:08 +0200 | [diff] [blame] | 117 | int ret; |
| 118 | |
| 119 | if (!encoder || !bridge) |
| 120 | return -EINVAL; |
| 121 | |
| 122 | if (previous && (!previous->dev || previous->encoder != encoder)) |
Ajay Kumar | 3d3f8b1 | 2015-01-20 22:08:44 +0530 | [diff] [blame] | 123 | return -EINVAL; |
| 124 | |
| 125 | if (bridge->dev) |
| 126 | return -EBUSY; |
| 127 | |
Laurent Pinchart | 3bb80f2 | 2016-11-28 17:59:08 +0200 | [diff] [blame] | 128 | bridge->dev = encoder->dev; |
| 129 | bridge->encoder = encoder; |
Ajay Kumar | 3d3f8b1 | 2015-01-20 22:08:44 +0530 | [diff] [blame] | 130 | |
Laurent Pinchart | 3bb80f2 | 2016-11-28 17:59:08 +0200 | [diff] [blame] | 131 | if (bridge->funcs->attach) { |
| 132 | ret = bridge->funcs->attach(bridge); |
| 133 | if (ret < 0) { |
| 134 | bridge->dev = NULL; |
| 135 | bridge->encoder = NULL; |
| 136 | return ret; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | if (previous) |
| 141 | previous->next = bridge; |
| 142 | else |
| 143 | encoder->bridge = bridge; |
Ajay Kumar | 3d3f8b1 | 2015-01-20 22:08:44 +0530 | [diff] [blame] | 144 | |
| 145 | return 0; |
| 146 | } |
| 147 | EXPORT_SYMBOL(drm_bridge_attach); |
| 148 | |
Andrea Merello | cf3bef9 | 2016-08-25 11:04:32 +0200 | [diff] [blame] | 149 | void drm_bridge_detach(struct drm_bridge *bridge) |
| 150 | { |
| 151 | if (WARN_ON(!bridge)) |
| 152 | return; |
| 153 | |
| 154 | if (WARN_ON(!bridge->dev)) |
| 155 | return; |
| 156 | |
| 157 | if (bridge->funcs->detach) |
| 158 | bridge->funcs->detach(bridge); |
| 159 | |
| 160 | bridge->dev = NULL; |
| 161 | } |
Andrea Merello | cf3bef9 | 2016-08-25 11:04:32 +0200 | [diff] [blame] | 162 | |
| 163 | /** |
Archit Taneja | 2331b4e | 2015-05-21 11:03:17 +0530 | [diff] [blame] | 164 | * DOC: bridge callbacks |
| 165 | * |
Daniel Vetter | da024fe | 2015-12-04 09:45:47 +0100 | [diff] [blame] | 166 | * The &drm_bridge_funcs ops are populated by the bridge driver. The DRM |
| 167 | * internals (atomic and CRTC helpers) use the helpers defined in drm_bridge.c |
| 168 | * These helpers call a specific &drm_bridge_funcs op for all the bridges |
Archit Taneja | 2331b4e | 2015-05-21 11:03:17 +0530 | [diff] [blame] | 169 | * during encoder configuration. |
| 170 | * |
Daniel Vetter | da024fe | 2015-12-04 09:45:47 +0100 | [diff] [blame] | 171 | * For detailed specification of the bridge callbacks see &drm_bridge_funcs. |
Archit Taneja | 2331b4e | 2015-05-21 11:03:17 +0530 | [diff] [blame] | 172 | */ |
| 173 | |
| 174 | /** |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 175 | * drm_bridge_mode_fixup - fixup proposed mode for all bridges in the |
| 176 | * encoder chain |
| 177 | * @bridge: bridge control structure |
| 178 | * @mode: desired mode to be set for the bridge |
| 179 | * @adjusted_mode: updated mode that works for this bridge |
| 180 | * |
Daniel Vetter | 4541d31 | 2017-01-02 09:17:26 +0100 | [diff] [blame] | 181 | * Calls &drm_bridge_funcs.mode_fixup for all the bridges in the |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 182 | * encoder chain, starting from the first bridge to the last. |
| 183 | * |
| 184 | * Note: the bridge passed should be the one closest to the encoder |
| 185 | * |
| 186 | * RETURNS: |
| 187 | * true on success, false on failure |
| 188 | */ |
| 189 | bool drm_bridge_mode_fixup(struct drm_bridge *bridge, |
| 190 | const struct drm_display_mode *mode, |
| 191 | struct drm_display_mode *adjusted_mode) |
| 192 | { |
| 193 | bool ret = true; |
| 194 | |
| 195 | if (!bridge) |
| 196 | return true; |
| 197 | |
| 198 | if (bridge->funcs->mode_fixup) |
| 199 | ret = bridge->funcs->mode_fixup(bridge, mode, adjusted_mode); |
| 200 | |
| 201 | ret = ret && drm_bridge_mode_fixup(bridge->next, mode, adjusted_mode); |
| 202 | |
| 203 | return ret; |
| 204 | } |
| 205 | EXPORT_SYMBOL(drm_bridge_mode_fixup); |
| 206 | |
| 207 | /** |
Jose Abreu | b1240f8 | 2017-05-25 15:19:14 +0100 | [diff] [blame] | 208 | * drm_bridge_mode_valid - validate the mode against all bridges in the |
| 209 | * encoder chain. |
| 210 | * @bridge: bridge control structure |
| 211 | * @mode: desired mode to be validated |
| 212 | * |
| 213 | * Calls &drm_bridge_funcs.mode_valid for all the bridges in the encoder |
| 214 | * chain, starting from the first bridge to the last. If at least one bridge |
| 215 | * does not accept the mode the function returns the error code. |
| 216 | * |
| 217 | * Note: the bridge passed should be the one closest to the encoder. |
| 218 | * |
| 219 | * RETURNS: |
| 220 | * MODE_OK on success, drm_mode_status Enum error code on failure |
| 221 | */ |
| 222 | enum drm_mode_status drm_bridge_mode_valid(struct drm_bridge *bridge, |
| 223 | const struct drm_display_mode *mode) |
| 224 | { |
| 225 | enum drm_mode_status ret = MODE_OK; |
| 226 | |
| 227 | if (!bridge) |
| 228 | return ret; |
| 229 | |
| 230 | if (bridge->funcs->mode_valid) |
| 231 | ret = bridge->funcs->mode_valid(bridge, mode); |
| 232 | |
| 233 | if (ret != MODE_OK) |
| 234 | return ret; |
| 235 | |
| 236 | return drm_bridge_mode_valid(bridge->next, mode); |
| 237 | } |
| 238 | EXPORT_SYMBOL(drm_bridge_mode_valid); |
| 239 | |
| 240 | /** |
Daniel Vetter | 4541d31 | 2017-01-02 09:17:26 +0100 | [diff] [blame] | 241 | * drm_bridge_disable - disables all bridges in the encoder chain |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 242 | * @bridge: bridge control structure |
| 243 | * |
Daniel Vetter | 4541d31 | 2017-01-02 09:17:26 +0100 | [diff] [blame] | 244 | * Calls &drm_bridge_funcs.disable op for all the bridges in the encoder |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 245 | * chain, starting from the last bridge to the first. These are called before |
| 246 | * calling the encoder's prepare op. |
| 247 | * |
| 248 | * Note: the bridge passed should be the one closest to the encoder |
| 249 | */ |
| 250 | void drm_bridge_disable(struct drm_bridge *bridge) |
| 251 | { |
| 252 | if (!bridge) |
| 253 | return; |
| 254 | |
| 255 | drm_bridge_disable(bridge->next); |
| 256 | |
Laurent Pinchart | c8a3b2a | 2016-02-26 11:51:06 +0200 | [diff] [blame] | 257 | if (bridge->funcs->disable) |
| 258 | bridge->funcs->disable(bridge); |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 259 | } |
| 260 | EXPORT_SYMBOL(drm_bridge_disable); |
| 261 | |
| 262 | /** |
Daniel Vetter | 4541d31 | 2017-01-02 09:17:26 +0100 | [diff] [blame] | 263 | * drm_bridge_post_disable - cleans up after disabling all bridges in the encoder chain |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 264 | * @bridge: bridge control structure |
| 265 | * |
Daniel Vetter | 4541d31 | 2017-01-02 09:17:26 +0100 | [diff] [blame] | 266 | * Calls &drm_bridge_funcs.post_disable op for all the bridges in the |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 267 | * encoder chain, starting from the first bridge to the last. These are called |
| 268 | * after completing the encoder's prepare op. |
| 269 | * |
| 270 | * Note: the bridge passed should be the one closest to the encoder |
| 271 | */ |
| 272 | void drm_bridge_post_disable(struct drm_bridge *bridge) |
| 273 | { |
| 274 | if (!bridge) |
| 275 | return; |
| 276 | |
Laurent Pinchart | c8a3b2a | 2016-02-26 11:51:06 +0200 | [diff] [blame] | 277 | if (bridge->funcs->post_disable) |
| 278 | bridge->funcs->post_disable(bridge); |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 279 | |
| 280 | drm_bridge_post_disable(bridge->next); |
| 281 | } |
| 282 | EXPORT_SYMBOL(drm_bridge_post_disable); |
| 283 | |
| 284 | /** |
| 285 | * drm_bridge_mode_set - set proposed mode for all bridges in the |
| 286 | * encoder chain |
| 287 | * @bridge: bridge control structure |
| 288 | * @mode: desired mode to be set for the bridge |
| 289 | * @adjusted_mode: updated mode that works for this bridge |
| 290 | * |
Daniel Vetter | 4541d31 | 2017-01-02 09:17:26 +0100 | [diff] [blame] | 291 | * Calls &drm_bridge_funcs.mode_set op for all the bridges in the |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 292 | * encoder chain, starting from the first bridge to the last. |
| 293 | * |
| 294 | * Note: the bridge passed should be the one closest to the encoder |
| 295 | */ |
| 296 | void drm_bridge_mode_set(struct drm_bridge *bridge, |
Laurent Pinchart | 63f8f3b | 2018-04-06 17:39:01 +0300 | [diff] [blame] | 297 | const struct drm_display_mode *mode, |
| 298 | const struct drm_display_mode *adjusted_mode) |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 299 | { |
| 300 | if (!bridge) |
| 301 | return; |
| 302 | |
| 303 | if (bridge->funcs->mode_set) |
| 304 | bridge->funcs->mode_set(bridge, mode, adjusted_mode); |
| 305 | |
| 306 | drm_bridge_mode_set(bridge->next, mode, adjusted_mode); |
| 307 | } |
| 308 | EXPORT_SYMBOL(drm_bridge_mode_set); |
| 309 | |
| 310 | /** |
Daniel Vetter | 4541d31 | 2017-01-02 09:17:26 +0100 | [diff] [blame] | 311 | * drm_bridge_pre_enable - prepares for enabling all |
| 312 | * bridges in the encoder chain |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 313 | * @bridge: bridge control structure |
| 314 | * |
Daniel Vetter | 4541d31 | 2017-01-02 09:17:26 +0100 | [diff] [blame] | 315 | * Calls &drm_bridge_funcs.pre_enable op for all the bridges in the encoder |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 316 | * chain, starting from the last bridge to the first. These are called |
| 317 | * before calling the encoder's commit op. |
| 318 | * |
| 319 | * Note: the bridge passed should be the one closest to the encoder |
| 320 | */ |
| 321 | void drm_bridge_pre_enable(struct drm_bridge *bridge) |
| 322 | { |
| 323 | if (!bridge) |
| 324 | return; |
| 325 | |
| 326 | drm_bridge_pre_enable(bridge->next); |
| 327 | |
Laurent Pinchart | c8a3b2a | 2016-02-26 11:51:06 +0200 | [diff] [blame] | 328 | if (bridge->funcs->pre_enable) |
| 329 | bridge->funcs->pre_enable(bridge); |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 330 | } |
| 331 | EXPORT_SYMBOL(drm_bridge_pre_enable); |
| 332 | |
| 333 | /** |
Daniel Vetter | 4541d31 | 2017-01-02 09:17:26 +0100 | [diff] [blame] | 334 | * drm_bridge_enable - enables all bridges in the encoder chain |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 335 | * @bridge: bridge control structure |
| 336 | * |
Daniel Vetter | 4541d31 | 2017-01-02 09:17:26 +0100 | [diff] [blame] | 337 | * Calls &drm_bridge_funcs.enable op for all the bridges in the encoder |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 338 | * chain, starting from the first bridge to the last. These are called |
| 339 | * after completing the encoder's commit op. |
| 340 | * |
| 341 | * Note that the bridge passed should be the one closest to the encoder |
| 342 | */ |
| 343 | void drm_bridge_enable(struct drm_bridge *bridge) |
| 344 | { |
| 345 | if (!bridge) |
| 346 | return; |
| 347 | |
Laurent Pinchart | c8a3b2a | 2016-02-26 11:51:06 +0200 | [diff] [blame] | 348 | if (bridge->funcs->enable) |
| 349 | bridge->funcs->enable(bridge); |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 350 | |
| 351 | drm_bridge_enable(bridge->next); |
| 352 | } |
| 353 | EXPORT_SYMBOL(drm_bridge_enable); |
| 354 | |
Sean Paul | 5ade071 | 2019-06-11 12:08:17 -0400 | [diff] [blame^] | 355 | /** |
| 356 | * drm_atomic_bridge_disable - disables all bridges in the encoder chain |
| 357 | * @bridge: bridge control structure |
| 358 | * @state: atomic state being committed |
| 359 | * |
| 360 | * Calls &drm_bridge_funcs.atomic_disable (falls back on |
| 361 | * &drm_bridge_funcs.disable) op for all the bridges in the encoder chain, |
| 362 | * starting from the last bridge to the first. These are called before calling |
| 363 | * &drm_encoder_helper_funcs.atomic_disable |
| 364 | * |
| 365 | * Note: the bridge passed should be the one closest to the encoder |
| 366 | */ |
| 367 | void drm_atomic_bridge_disable(struct drm_bridge *bridge, |
| 368 | struct drm_atomic_state *state) |
| 369 | { |
| 370 | if (!bridge) |
| 371 | return; |
| 372 | |
| 373 | drm_atomic_bridge_disable(bridge->next, state); |
| 374 | |
| 375 | if (bridge->funcs->atomic_disable) |
| 376 | bridge->funcs->atomic_disable(bridge, state); |
| 377 | else if (bridge->funcs->disable) |
| 378 | bridge->funcs->disable(bridge); |
| 379 | } |
| 380 | EXPORT_SYMBOL(drm_atomic_bridge_disable); |
| 381 | |
| 382 | /** |
| 383 | * drm_atomic_bridge_post_disable - cleans up after disabling all bridges in the |
| 384 | * encoder chain |
| 385 | * @bridge: bridge control structure |
| 386 | * @state: atomic state being committed |
| 387 | * |
| 388 | * Calls &drm_bridge_funcs.atomic_post_disable (falls back on |
| 389 | * &drm_bridge_funcs.post_disable) op for all the bridges in the encoder chain, |
| 390 | * starting from the first bridge to the last. These are called after completing |
| 391 | * &drm_encoder_helper_funcs.atomic_disable |
| 392 | * |
| 393 | * Note: the bridge passed should be the one closest to the encoder |
| 394 | */ |
| 395 | void drm_atomic_bridge_post_disable(struct drm_bridge *bridge, |
| 396 | struct drm_atomic_state *state) |
| 397 | { |
| 398 | if (!bridge) |
| 399 | return; |
| 400 | |
| 401 | if (bridge->funcs->atomic_post_disable) |
| 402 | bridge->funcs->atomic_post_disable(bridge, state); |
| 403 | else if (bridge->funcs->post_disable) |
| 404 | bridge->funcs->post_disable(bridge); |
| 405 | |
| 406 | drm_atomic_bridge_post_disable(bridge->next, state); |
| 407 | } |
| 408 | EXPORT_SYMBOL(drm_atomic_bridge_post_disable); |
| 409 | |
| 410 | /** |
| 411 | * drm_atomic_bridge_pre_enable - prepares for enabling all bridges in the |
| 412 | * encoder chain |
| 413 | * @bridge: bridge control structure |
| 414 | * @state: atomic state being committed |
| 415 | * |
| 416 | * Calls &drm_bridge_funcs.atomic_pre_enable (falls back on |
| 417 | * &drm_bridge_funcs.pre_enable) op for all the bridges in the encoder chain, |
| 418 | * starting from the last bridge to the first. These are called before calling |
| 419 | * &drm_encoder_helper_funcs.atomic_enable |
| 420 | * |
| 421 | * Note: the bridge passed should be the one closest to the encoder |
| 422 | */ |
| 423 | void drm_atomic_bridge_pre_enable(struct drm_bridge *bridge, |
| 424 | struct drm_atomic_state *state) |
| 425 | { |
| 426 | if (!bridge) |
| 427 | return; |
| 428 | |
| 429 | drm_atomic_bridge_pre_enable(bridge->next, state); |
| 430 | |
| 431 | if (bridge->funcs->atomic_pre_enable) |
| 432 | bridge->funcs->atomic_pre_enable(bridge, state); |
| 433 | else if (bridge->funcs->pre_enable) |
| 434 | bridge->funcs->pre_enable(bridge); |
| 435 | } |
| 436 | EXPORT_SYMBOL(drm_atomic_bridge_pre_enable); |
| 437 | |
| 438 | /** |
| 439 | * drm_atomic_bridge_enable - enables all bridges in the encoder chain |
| 440 | * @bridge: bridge control structure |
| 441 | * @state: atomic state being committed |
| 442 | * |
| 443 | * Calls &drm_bridge_funcs.atomic_enable (falls back on |
| 444 | * &drm_bridge_funcs.enable) op for all the bridges in the encoder chain, |
| 445 | * starting from the first bridge to the last. These are called after completing |
| 446 | * &drm_encoder_helper_funcs.atomic_enable |
| 447 | * |
| 448 | * Note: the bridge passed should be the one closest to the encoder |
| 449 | */ |
| 450 | void drm_atomic_bridge_enable(struct drm_bridge *bridge, |
| 451 | struct drm_atomic_state *state) |
| 452 | { |
| 453 | if (!bridge) |
| 454 | return; |
| 455 | |
| 456 | if (bridge->funcs->atomic_enable) |
| 457 | bridge->funcs->atomic_enable(bridge, state); |
| 458 | else if (bridge->funcs->enable) |
| 459 | bridge->funcs->enable(bridge); |
| 460 | |
| 461 | drm_atomic_bridge_enable(bridge->next, state); |
| 462 | } |
| 463 | EXPORT_SYMBOL(drm_atomic_bridge_enable); |
| 464 | |
Ajay Kumar | 3d3f8b1 | 2015-01-20 22:08:44 +0530 | [diff] [blame] | 465 | #ifdef CONFIG_OF |
Archit Taneja | 2331b4e | 2015-05-21 11:03:17 +0530 | [diff] [blame] | 466 | /** |
| 467 | * of_drm_find_bridge - find the bridge corresponding to the device node in |
| 468 | * the global bridge list |
| 469 | * |
| 470 | * @np: device node |
| 471 | * |
| 472 | * RETURNS: |
| 473 | * drm_bridge control struct on success, NULL on failure |
| 474 | */ |
Ajay Kumar | 3d3f8b1 | 2015-01-20 22:08:44 +0530 | [diff] [blame] | 475 | struct drm_bridge *of_drm_find_bridge(struct device_node *np) |
| 476 | { |
| 477 | struct drm_bridge *bridge; |
| 478 | |
| 479 | mutex_lock(&bridge_lock); |
| 480 | |
| 481 | list_for_each_entry(bridge, &bridge_list, list) { |
| 482 | if (bridge->of_node == np) { |
| 483 | mutex_unlock(&bridge_lock); |
| 484 | return bridge; |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | mutex_unlock(&bridge_lock); |
| 489 | return NULL; |
| 490 | } |
| 491 | EXPORT_SYMBOL(of_drm_find_bridge); |
| 492 | #endif |
| 493 | |
| 494 | MODULE_AUTHOR("Ajay Kumar <ajaykumar.rs@samsung.com>"); |
| 495 | MODULE_DESCRIPTION("DRM bridge infrastructure"); |
| 496 | MODULE_LICENSE("GPL and additional rights"); |