]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - drivers/gpu/drm/drm_bridge.c
2 * Copyright (c) 2014 Samsung Electronics Co., Ltd
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:
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
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.
24 #include <linux/err.h>
25 #include <linux/module.h>
27 #include <drm/drm_crtc.h>
31 static DEFINE_MUTEX(bridge_lock
);
32 static LIST_HEAD(bridge_list
);
34 int drm_bridge_add(struct drm_bridge
*bridge
)
36 mutex_lock(&bridge_lock
);
37 list_add_tail(&bridge
->list
, &bridge_list
);
38 mutex_unlock(&bridge_lock
);
42 EXPORT_SYMBOL(drm_bridge_add
);
44 void drm_bridge_remove(struct drm_bridge
*bridge
)
46 mutex_lock(&bridge_lock
);
47 list_del_init(&bridge
->list
);
48 mutex_unlock(&bridge_lock
);
50 EXPORT_SYMBOL(drm_bridge_remove
);
52 int drm_bridge_attach(struct drm_device
*dev
, struct drm_bridge
*bridge
)
62 if (bridge
->funcs
->attach
)
63 return bridge
->funcs
->attach(bridge
);
67 EXPORT_SYMBOL(drm_bridge_attach
);
70 * drm_bridge_mode_fixup - fixup proposed mode for all bridges in the
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
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.
79 * Note: the bridge passed should be the one closest to the encoder
82 * true on success, false on failure
84 bool drm_bridge_mode_fixup(struct drm_bridge
*bridge
,
85 const struct drm_display_mode
*mode
,
86 struct drm_display_mode
*adjusted_mode
)
93 if (bridge
->funcs
->mode_fixup
)
94 ret
= bridge
->funcs
->mode_fixup(bridge
, mode
, adjusted_mode
);
96 ret
= ret
&& drm_bridge_mode_fixup(bridge
->next
, mode
, adjusted_mode
);
100 EXPORT_SYMBOL(drm_bridge_mode_fixup
);
103 * drm_bridge_disable - calls 'disable' drm_bridge_funcs op for all
104 * bridges in the encoder chain.
105 * @bridge: bridge control structure
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.
111 * Note: the bridge passed should be the one closest to the encoder
113 void drm_bridge_disable(struct drm_bridge
*bridge
)
118 drm_bridge_disable(bridge
->next
);
120 bridge
->funcs
->disable(bridge
);
122 EXPORT_SYMBOL(drm_bridge_disable
);
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
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.
133 * Note: the bridge passed should be the one closest to the encoder
135 void drm_bridge_post_disable(struct drm_bridge
*bridge
)
140 bridge
->funcs
->post_disable(bridge
);
142 drm_bridge_post_disable(bridge
->next
);
144 EXPORT_SYMBOL(drm_bridge_post_disable
);
147 * drm_bridge_mode_set - set proposed mode for all bridges in the
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
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.
156 * Note: the bridge passed should be the one closest to the encoder
158 void drm_bridge_mode_set(struct drm_bridge
*bridge
,
159 struct drm_display_mode
*mode
,
160 struct drm_display_mode
*adjusted_mode
)
165 if (bridge
->funcs
->mode_set
)
166 bridge
->funcs
->mode_set(bridge
, mode
, adjusted_mode
);
168 drm_bridge_mode_set(bridge
->next
, mode
, adjusted_mode
);
170 EXPORT_SYMBOL(drm_bridge_mode_set
);
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
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.
181 * Note: the bridge passed should be the one closest to the encoder
183 void drm_bridge_pre_enable(struct drm_bridge
*bridge
)
188 drm_bridge_pre_enable(bridge
->next
);
190 bridge
->funcs
->pre_enable(bridge
);
192 EXPORT_SYMBOL(drm_bridge_pre_enable
);
195 * drm_bridge_enable - calls 'enable' drm_bridge_funcs op for all bridges
196 * in the encoder chain.
197 * @bridge: bridge control structure
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.
203 * Note that the bridge passed should be the one closest to the encoder
205 void drm_bridge_enable(struct drm_bridge
*bridge
)
210 bridge
->funcs
->enable(bridge
);
212 drm_bridge_enable(bridge
->next
);
214 EXPORT_SYMBOL(drm_bridge_enable
);
217 struct drm_bridge
*of_drm_find_bridge(struct device_node
*np
)
219 struct drm_bridge
*bridge
;
221 mutex_lock(&bridge_lock
);
223 list_for_each_entry(bridge
, &bridge_list
, list
) {
224 if (bridge
->of_node
== np
) {
225 mutex_unlock(&bridge_lock
);
230 mutex_unlock(&bridge_lock
);
233 EXPORT_SYMBOL(of_drm_find_bridge
);
236 MODULE_AUTHOR("Ajay Kumar <ajaykumar.rs@samsung.com>");
237 MODULE_DESCRIPTION("DRM bridge infrastructure");
238 MODULE_LICENSE("GPL and additional rights");