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> |
| 26 | |
| 27 | #include <drm/drm_crtc.h> |
| 28 | |
| 29 | #include "drm/drmP.h" |
| 30 | |
| 31 | static DEFINE_MUTEX(bridge_lock); |
| 32 | static LIST_HEAD(bridge_list); |
| 33 | |
| 34 | int drm_bridge_add(struct drm_bridge *bridge) |
| 35 | { |
| 36 | mutex_lock(&bridge_lock); |
| 37 | list_add_tail(&bridge->list, &bridge_list); |
| 38 | mutex_unlock(&bridge_lock); |
| 39 | |
| 40 | return 0; |
| 41 | } |
| 42 | EXPORT_SYMBOL(drm_bridge_add); |
| 43 | |
| 44 | void drm_bridge_remove(struct drm_bridge *bridge) |
| 45 | { |
| 46 | mutex_lock(&bridge_lock); |
| 47 | list_del_init(&bridge->list); |
| 48 | mutex_unlock(&bridge_lock); |
| 49 | } |
| 50 | EXPORT_SYMBOL(drm_bridge_remove); |
| 51 | |
Ville Syrjälä | 43fc884 | 2015-03-13 14:51:25 +0200 | [diff] [blame] | 52 | int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge) |
Ajay Kumar | 3d3f8b1 | 2015-01-20 22:08:44 +0530 | [diff] [blame] | 53 | { |
| 54 | if (!dev || !bridge) |
| 55 | return -EINVAL; |
| 56 | |
| 57 | if (bridge->dev) |
| 58 | return -EBUSY; |
| 59 | |
| 60 | bridge->dev = dev; |
| 61 | |
| 62 | if (bridge->funcs->attach) |
| 63 | return bridge->funcs->attach(bridge); |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | EXPORT_SYMBOL(drm_bridge_attach); |
| 68 | |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame^] | 69 | /** |
| 70 | * drm_bridge_mode_fixup - fixup proposed mode for all bridges in the |
| 71 | * encoder chain |
| 72 | * @bridge: bridge control structure |
| 73 | * @mode: desired mode to be set for the bridge |
| 74 | * @adjusted_mode: updated mode that works for this bridge |
| 75 | * |
| 76 | * Calls 'mode_fixup' drm_bridge_funcs op for all the bridges in the |
| 77 | * encoder chain, starting from the first bridge to the last. |
| 78 | * |
| 79 | * Note: the bridge passed should be the one closest to the encoder |
| 80 | * |
| 81 | * RETURNS: |
| 82 | * true on success, false on failure |
| 83 | */ |
| 84 | bool drm_bridge_mode_fixup(struct drm_bridge *bridge, |
| 85 | const struct drm_display_mode *mode, |
| 86 | struct drm_display_mode *adjusted_mode) |
| 87 | { |
| 88 | bool ret = true; |
| 89 | |
| 90 | if (!bridge) |
| 91 | return true; |
| 92 | |
| 93 | if (bridge->funcs->mode_fixup) |
| 94 | ret = bridge->funcs->mode_fixup(bridge, mode, adjusted_mode); |
| 95 | |
| 96 | ret = ret && drm_bridge_mode_fixup(bridge->next, mode, adjusted_mode); |
| 97 | |
| 98 | return ret; |
| 99 | } |
| 100 | EXPORT_SYMBOL(drm_bridge_mode_fixup); |
| 101 | |
| 102 | /** |
| 103 | * drm_bridge_disable - calls 'disable' drm_bridge_funcs op for all |
| 104 | * bridges in the encoder chain. |
| 105 | * @bridge: bridge control structure |
| 106 | * |
| 107 | * Calls 'disable' drm_bridge_funcs op for all the bridges in the encoder |
| 108 | * chain, starting from the last bridge to the first. These are called before |
| 109 | * calling the encoder's prepare op. |
| 110 | * |
| 111 | * Note: the bridge passed should be the one closest to the encoder |
| 112 | */ |
| 113 | void drm_bridge_disable(struct drm_bridge *bridge) |
| 114 | { |
| 115 | if (!bridge) |
| 116 | return; |
| 117 | |
| 118 | drm_bridge_disable(bridge->next); |
| 119 | |
| 120 | bridge->funcs->disable(bridge); |
| 121 | } |
| 122 | EXPORT_SYMBOL(drm_bridge_disable); |
| 123 | |
| 124 | /** |
| 125 | * drm_bridge_post_disable - calls 'post_disable' drm_bridge_funcs op for |
| 126 | * all bridges in the encoder chain. |
| 127 | * @bridge: bridge control structure |
| 128 | * |
| 129 | * Calls 'post_disable' drm_bridge_funcs op for all the bridges in the |
| 130 | * encoder chain, starting from the first bridge to the last. These are called |
| 131 | * after completing the encoder's prepare op. |
| 132 | * |
| 133 | * Note: the bridge passed should be the one closest to the encoder |
| 134 | */ |
| 135 | void drm_bridge_post_disable(struct drm_bridge *bridge) |
| 136 | { |
| 137 | if (!bridge) |
| 138 | return; |
| 139 | |
| 140 | bridge->funcs->post_disable(bridge); |
| 141 | |
| 142 | drm_bridge_post_disable(bridge->next); |
| 143 | } |
| 144 | EXPORT_SYMBOL(drm_bridge_post_disable); |
| 145 | |
| 146 | /** |
| 147 | * drm_bridge_mode_set - set proposed mode for all bridges in the |
| 148 | * encoder chain |
| 149 | * @bridge: bridge control structure |
| 150 | * @mode: desired mode to be set for the bridge |
| 151 | * @adjusted_mode: updated mode that works for this bridge |
| 152 | * |
| 153 | * Calls 'mode_set' drm_bridge_funcs op for all the bridges in the |
| 154 | * encoder chain, starting from the first bridge to the last. |
| 155 | * |
| 156 | * Note: the bridge passed should be the one closest to the encoder |
| 157 | */ |
| 158 | void drm_bridge_mode_set(struct drm_bridge *bridge, |
| 159 | struct drm_display_mode *mode, |
| 160 | struct drm_display_mode *adjusted_mode) |
| 161 | { |
| 162 | if (!bridge) |
| 163 | return; |
| 164 | |
| 165 | if (bridge->funcs->mode_set) |
| 166 | bridge->funcs->mode_set(bridge, mode, adjusted_mode); |
| 167 | |
| 168 | drm_bridge_mode_set(bridge->next, mode, adjusted_mode); |
| 169 | } |
| 170 | EXPORT_SYMBOL(drm_bridge_mode_set); |
| 171 | |
| 172 | /** |
| 173 | * drm_bridge_pre_enable - calls 'pre_enable' drm_bridge_funcs op for all |
| 174 | * bridges in the encoder chain. |
| 175 | * @bridge: bridge control structure |
| 176 | * |
| 177 | * Calls 'pre_enable' drm_bridge_funcs op for all the bridges in the encoder |
| 178 | * chain, starting from the last bridge to the first. These are called |
| 179 | * before calling the encoder's commit op. |
| 180 | * |
| 181 | * Note: the bridge passed should be the one closest to the encoder |
| 182 | */ |
| 183 | void drm_bridge_pre_enable(struct drm_bridge *bridge) |
| 184 | { |
| 185 | if (!bridge) |
| 186 | return; |
| 187 | |
| 188 | drm_bridge_pre_enable(bridge->next); |
| 189 | |
| 190 | bridge->funcs->pre_enable(bridge); |
| 191 | } |
| 192 | EXPORT_SYMBOL(drm_bridge_pre_enable); |
| 193 | |
| 194 | /** |
| 195 | * drm_bridge_enable - calls 'enable' drm_bridge_funcs op for all bridges |
| 196 | * in the encoder chain. |
| 197 | * @bridge: bridge control structure |
| 198 | * |
| 199 | * Calls 'enable' drm_bridge_funcs op for all the bridges in the encoder |
| 200 | * chain, starting from the first bridge to the last. These are called |
| 201 | * after completing the encoder's commit op. |
| 202 | * |
| 203 | * Note that the bridge passed should be the one closest to the encoder |
| 204 | */ |
| 205 | void drm_bridge_enable(struct drm_bridge *bridge) |
| 206 | { |
| 207 | if (!bridge) |
| 208 | return; |
| 209 | |
| 210 | bridge->funcs->enable(bridge); |
| 211 | |
| 212 | drm_bridge_enable(bridge->next); |
| 213 | } |
| 214 | EXPORT_SYMBOL(drm_bridge_enable); |
| 215 | |
Ajay Kumar | 3d3f8b1 | 2015-01-20 22:08:44 +0530 | [diff] [blame] | 216 | #ifdef CONFIG_OF |
| 217 | struct drm_bridge *of_drm_find_bridge(struct device_node *np) |
| 218 | { |
| 219 | struct drm_bridge *bridge; |
| 220 | |
| 221 | mutex_lock(&bridge_lock); |
| 222 | |
| 223 | list_for_each_entry(bridge, &bridge_list, list) { |
| 224 | if (bridge->of_node == np) { |
| 225 | mutex_unlock(&bridge_lock); |
| 226 | return bridge; |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | mutex_unlock(&bridge_lock); |
| 231 | return NULL; |
| 232 | } |
| 233 | EXPORT_SYMBOL(of_drm_find_bridge); |
| 234 | #endif |
| 235 | |
| 236 | MODULE_AUTHOR("Ajay Kumar <ajaykumar.rs@samsung.com>"); |
| 237 | MODULE_DESCRIPTION("DRM bridge infrastructure"); |
| 238 | MODULE_LICENSE("GPL and additional rights"); |