drm/bridge: tfp410: Allow operation without drm_connector
[linux-block.git] / drivers / gpu / drm / drm_bridge.c
CommitLineData
3d3f8b1f
AK
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>
199e4e96 26#include <linux/mutex.h>
3d3f8b1f 27
75146591 28#include <drm/drm_atomic_state_helper.h>
199e4e96 29#include <drm/drm_bridge.h>
3bb80f24 30#include <drm/drm_encoder.h>
3d3f8b1f 31
4a878c03
LP
32#include "drm_crtc_internal.h"
33
2331b4e4
AT
34/**
35 * DOC: overview
36 *
ea0dd85a 37 * &struct drm_bridge represents a device that hangs on to an encoder. These are
da024fe5 38 * handy when a regular &drm_encoder entity isn't enough to represent the entire
2331b4e4
AT
39 * encoder chain.
40 *
da024fe5 41 * A bridge is always attached to a single &drm_encoder at a time, but can be
0451369b 42 * either connected to it directly, or through a chain of bridges::
2331b4e4 43 *
0451369b 44 * [ CRTC ---> ] Encoder ---> Bridge A ---> Bridge B
2331b4e4 45 *
0451369b
LP
46 * Here, the output of the encoder feeds to bridge A, and that furthers feeds to
47 * bridge B. Bridge chains can be arbitrarily long, and shall be fully linear:
48 * Chaining multiple bridges to the output of a bridge, or the same bridge to
49 * the output of different bridges, is not supported.
2331b4e4 50 *
0451369b
LP
51 * Display drivers are responsible for linking encoders with the first bridge
52 * in the chains. This is done by acquiring the appropriate bridge with
53 * of_drm_find_bridge() or drm_of_find_panel_or_bridge(), or creating it for a
54 * panel with drm_panel_bridge_add_typed() (or the managed version
55 * devm_drm_panel_bridge_add_typed()). Once acquired, the bridge shall be
56 * attached to the encoder with a call to drm_bridge_attach().
2331b4e4 57 *
0451369b
LP
58 * Bridges are responsible for linking themselves with the next bridge in the
59 * chain, if any. This is done the same way as for encoders, with the call to
60 * drm_bridge_attach() occurring in the &drm_bridge_funcs.attach operation.
61 *
62 * Once these links are created, the bridges can participate along with encoder
63 * functions to perform mode validation and fixup (through
64 * drm_bridge_chain_mode_valid() and drm_atomic_bridge_chain_check()), mode
65 * setting (through drm_bridge_chain_mode_set()), enable (through
66 * drm_atomic_bridge_chain_pre_enable() and drm_atomic_bridge_chain_enable())
67 * and disable (through drm_atomic_bridge_chain_disable() and
68 * drm_atomic_bridge_chain_post_disable()). Those functions call the
69 * corresponding operations provided in &drm_bridge_funcs in sequence for all
70 * bridges in the chain.
71 *
72 * For display drivers that use the atomic helpers
73 * drm_atomic_helper_check_modeset(),
74 * drm_atomic_helper_commit_modeset_enables() and
75 * drm_atomic_helper_commit_modeset_disables() (either directly in hand-rolled
76 * commit check and commit tail handlers, or through the higher-level
77 * drm_atomic_helper_check() and drm_atomic_helper_commit_tail() or
78 * drm_atomic_helper_commit_tail_rpm() helpers), this is done transparently and
79 * requires no intervention from the driver. For other drivers, the relevant
80 * DRM bridge chain functions shall be called manually.
81 *
82 * &drm_bridge, like &drm_panel, aren't &drm_mode_object entities like planes,
da024fe5
DV
83 * CRTCs, encoders or connectors and hence are not visible to userspace. They
84 * just provide additional hooks to get the desired output at the end of the
85 * encoder chain.
2331b4e4
AT
86 */
87
3d3f8b1f
AK
88static DEFINE_MUTEX(bridge_lock);
89static LIST_HEAD(bridge_list);
90
2331b4e4
AT
91/**
92 * drm_bridge_add - add the given bridge to the global bridge list
93 *
94 * @bridge: bridge control structure
2331b4e4 95 */
99286884 96void drm_bridge_add(struct drm_bridge *bridge)
3d3f8b1f 97{
11f6c4b1
LP
98 mutex_init(&bridge->hpd_mutex);
99
3d3f8b1f
AK
100 mutex_lock(&bridge_lock);
101 list_add_tail(&bridge->list, &bridge_list);
102 mutex_unlock(&bridge_lock);
3d3f8b1f
AK
103}
104EXPORT_SYMBOL(drm_bridge_add);
105
2331b4e4
AT
106/**
107 * drm_bridge_remove - remove the given bridge from the global bridge list
108 *
109 * @bridge: bridge control structure
110 */
3d3f8b1f
AK
111void drm_bridge_remove(struct drm_bridge *bridge)
112{
113 mutex_lock(&bridge_lock);
114 list_del_init(&bridge->list);
115 mutex_unlock(&bridge_lock);
11f6c4b1
LP
116
117 mutex_destroy(&bridge->hpd_mutex);
3d3f8b1f
AK
118}
119EXPORT_SYMBOL(drm_bridge_remove);
120
75146591
BB
121static struct drm_private_state *
122drm_bridge_atomic_duplicate_priv_state(struct drm_private_obj *obj)
123{
124 struct drm_bridge *bridge = drm_priv_to_bridge(obj);
125 struct drm_bridge_state *state;
126
127 state = bridge->funcs->atomic_duplicate_state(bridge);
128 return state ? &state->base : NULL;
129}
130
131static void
132drm_bridge_atomic_destroy_priv_state(struct drm_private_obj *obj,
133 struct drm_private_state *s)
134{
135 struct drm_bridge_state *state = drm_priv_to_bridge_state(s);
136 struct drm_bridge *bridge = drm_priv_to_bridge(obj);
137
138 bridge->funcs->atomic_destroy_state(bridge, state);
139}
140
141static const struct drm_private_state_funcs drm_bridge_priv_state_funcs = {
142 .atomic_duplicate_state = drm_bridge_atomic_duplicate_priv_state,
143 .atomic_destroy_state = drm_bridge_atomic_destroy_priv_state,
144};
145
2331b4e4 146/**
3bb80f24 147 * drm_bridge_attach - attach the bridge to an encoder's chain
2331b4e4 148 *
3bb80f24
LP
149 * @encoder: DRM encoder
150 * @bridge: bridge to attach
151 * @previous: previous bridge in the chain (optional)
a25b988f 152 * @flags: DRM_BRIDGE_ATTACH_* flags
2331b4e4 153 *
3bb80f24
LP
154 * Called by a kms driver to link the bridge to an encoder's chain. The previous
155 * argument specifies the previous bridge in the chain. If NULL, the bridge is
156 * linked directly at the encoder's output. Otherwise it is linked at the
157 * previous bridge's output.
2331b4e4 158 *
3bb80f24
LP
159 * If non-NULL the previous bridge must be already attached by a call to this
160 * function.
2331b4e4 161 *
169cc4c7
PR
162 * Note that bridges attached to encoders are auto-detached during encoder
163 * cleanup in drm_encoder_cleanup(), so drm_bridge_attach() should generally
164 * *not* be balanced with a drm_bridge_detach() in driver code.
165 *
2331b4e4
AT
166 * RETURNS:
167 * Zero on success, error code on failure
168 */
3bb80f24 169int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
a25b988f
LP
170 struct drm_bridge *previous,
171 enum drm_bridge_attach_flags flags)
3d3f8b1f 172{
3bb80f24
LP
173 int ret;
174
175 if (!encoder || !bridge)
176 return -EINVAL;
177
178 if (previous && (!previous->dev || previous->encoder != encoder))
3d3f8b1f
AK
179 return -EINVAL;
180
181 if (bridge->dev)
182 return -EBUSY;
183
3bb80f24
LP
184 bridge->dev = encoder->dev;
185 bridge->encoder = encoder;
186
05193dc3
BB
187 if (previous)
188 list_add(&bridge->chain_node, &previous->chain_node);
189 else
190 list_add(&bridge->chain_node, &encoder->bridge_chain);
191
3bb80f24 192 if (bridge->funcs->attach) {
a25b988f 193 ret = bridge->funcs->attach(bridge, flags);
75146591
BB
194 if (ret < 0)
195 goto err_reset_bridge;
196 }
197
198 if (bridge->funcs->atomic_reset) {
199 struct drm_bridge_state *state;
200
201 state = bridge->funcs->atomic_reset(bridge);
202 if (IS_ERR(state)) {
203 ret = PTR_ERR(state);
204 goto err_detach_bridge;
09912635 205 }
75146591
BB
206
207 drm_atomic_private_obj_init(bridge->dev, &bridge->base,
208 &state->base,
209 &drm_bridge_priv_state_funcs);
6ed7e962
BB
210 }
211
3d3f8b1f 212 return 0;
75146591
BB
213
214err_detach_bridge:
215 if (bridge->funcs->detach)
216 bridge->funcs->detach(bridge);
217
218err_reset_bridge:
219 bridge->dev = NULL;
220 bridge->encoder = NULL;
221 list_del(&bridge->chain_node);
222 return ret;
3d3f8b1f
AK
223}
224EXPORT_SYMBOL(drm_bridge_attach);
225
cf3bef95
AM
226void drm_bridge_detach(struct drm_bridge *bridge)
227{
228 if (WARN_ON(!bridge))
229 return;
230
231 if (WARN_ON(!bridge->dev))
232 return;
233
75146591
BB
234 if (bridge->funcs->atomic_reset)
235 drm_atomic_private_obj_fini(&bridge->base);
236
cf3bef95
AM
237 if (bridge->funcs->detach)
238 bridge->funcs->detach(bridge);
239
05193dc3 240 list_del(&bridge->chain_node);
cf3bef95
AM
241 bridge->dev = NULL;
242}
cf3bef95 243
2331b4e4 244/**
0451369b
LP
245 * DOC: bridge operations
246 *
247 * Bridge drivers expose operations through the &drm_bridge_funcs structure.
248 * The DRM internals (atomic and CRTC helpers) use the helpers defined in
249 * drm_bridge.c to call bridge operations. Those operations are divided in
11f6c4b1 250 * three big categories to support different parts of the bridge usage.
0451369b
LP
251 *
252 * - The encoder-related operations support control of the bridges in the
253 * chain, and are roughly counterparts to the &drm_encoder_helper_funcs
254 * operations. They are used by the legacy CRTC and the atomic modeset
255 * helpers to perform mode validation, fixup and setting, and enable and
256 * disable the bridge automatically.
257 *
258 * The enable and disable operations are split in
259 * &drm_bridge_funcs.pre_enable, &drm_bridge_funcs.enable,
260 * &drm_bridge_funcs.disable and &drm_bridge_funcs.post_disable to provide
261 * finer-grained control.
2331b4e4 262 *
0451369b
LP
263 * Bridge drivers may implement the legacy version of those operations, or
264 * the atomic version (prefixed with atomic\_), in which case they shall also
265 * implement the atomic state bookkeeping operations
266 * (&drm_bridge_funcs.atomic_duplicate_state,
267 * &drm_bridge_funcs.atomic_destroy_state and &drm_bridge_funcs.reset).
268 * Mixing atomic and non-atomic versions of the operations is not supported.
2331b4e4 269 *
0451369b
LP
270 * - The bus format negotiation operations
271 * &drm_bridge_funcs.atomic_get_output_bus_fmts and
272 * &drm_bridge_funcs.atomic_get_input_bus_fmts allow bridge drivers to
273 * negotiate the formats transmitted between bridges in the chain when
274 * multiple formats are supported. Negotiation for formats is performed
275 * transparently for display drivers by the atomic modeset helpers. Only
276 * atomic versions of those operations exist, bridge drivers that need to
277 * implement them shall thus also implement the atomic version of the
278 * encoder-related operations. This feature is not supported by the legacy
279 * CRTC helpers.
11f6c4b1
LP
280 *
281 * - The connector-related operations support implementing a &drm_connector
282 * based on a chain of bridges. DRM bridges traditionally create a
283 * &drm_connector for bridges meant to be used at the end of the chain. This
284 * puts additional burden on bridge drivers, especially for bridges that may
285 * be used in the middle of a chain or at the end of it. Furthermore, it
286 * requires all operations of the &drm_connector to be handled by a single
287 * bridge, which doesn't always match the hardware architecture.
288 *
289 * To simplify bridge drivers and make the connector implementation more
290 * flexible, a new model allows bridges to unconditionally skip creation of
291 * &drm_connector and instead expose &drm_bridge_funcs operations to support
292 * an externally-implemented &drm_connector. Those operations are
293 * &drm_bridge_funcs.detect, &drm_bridge_funcs.get_modes,
294 * &drm_bridge_funcs.get_edid, &drm_bridge_funcs.hpd_notify,
295 * &drm_bridge_funcs.hpd_enable and &drm_bridge_funcs.hpd_disable. When
296 * implemented, display drivers shall create a &drm_connector instance for
297 * each chain of bridges, and implement those connector instances based on
298 * the bridge connector operations.
299 *
300 * Bridge drivers shall implement the connector-related operations for all
301 * the features that the bridge hardware support. For instance, if a bridge
302 * supports reading EDID, the &drm_bridge_funcs.get_edid shall be
303 * implemented. This however doesn't mean that the DDC lines are wired to the
304 * bridge on a particular platform, as they could also be connected to an I2C
305 * controller of the SoC. Support for the connector-related operations on the
306 * running platform is reported through the &drm_bridge.ops flags. Bridge
307 * drivers shall detect which operations they can support on the platform
308 * (usually this information is provided by ACPI or DT), and set the
309 * &drm_bridge.ops flags for all supported operations. A flag shall only be
310 * set if the corresponding &drm_bridge_funcs operation is implemented, but
311 * an implemented operation doesn't necessarily imply that the corresponding
312 * flag will be set. Display drivers shall use the &drm_bridge.ops flags to
313 * decide which bridge to delegate a connector operation to. This mechanism
314 * allows providing a single static const &drm_bridge_funcs instance in
315 * bridge drivers, improving security by storing function pointers in
316 * read-only memory.
a25b988f
LP
317 *
318 * In order to ease transition, bridge drivers may support both the old and
319 * new models by making connector creation optional and implementing the
320 * connected-related bridge operations. Connector creation is then controlled
321 * by the flags argument to the drm_bridge_attach() function. Display drivers
322 * that support the new model and create connectors themselves shall set the
323 * %DRM_BRIDGE_ATTACH_NO_CONNECTOR flag, and bridge drivers shall then skip
324 * connector creation. For intermediate bridges in the chain, the flag shall
325 * be passed to the drm_bridge_attach() call for the downstream bridge.
326 * Bridge drivers that implement the new model only shall return an error
327 * from their &drm_bridge_funcs.attach handler when the
328 * %DRM_BRIDGE_ATTACH_NO_CONNECTOR flag is not set. New display drivers
329 * should use the new model, and convert the bridge drivers they use if
330 * needed, in order to gradually transition to the new model.
2331b4e4
AT
331 */
332
862e686c 333/**
ea099adf
BB
334 * drm_bridge_chain_mode_fixup - fixup proposed mode for all bridges in the
335 * encoder chain
862e686c
AT
336 * @bridge: bridge control structure
337 * @mode: desired mode to be set for the bridge
338 * @adjusted_mode: updated mode that works for this bridge
339 *
4541d31e 340 * Calls &drm_bridge_funcs.mode_fixup for all the bridges in the
862e686c
AT
341 * encoder chain, starting from the first bridge to the last.
342 *
343 * Note: the bridge passed should be the one closest to the encoder
344 *
345 * RETURNS:
346 * true on success, false on failure
347 */
ea099adf
BB
348bool drm_bridge_chain_mode_fixup(struct drm_bridge *bridge,
349 const struct drm_display_mode *mode,
350 struct drm_display_mode *adjusted_mode)
862e686c 351{
05193dc3 352 struct drm_encoder *encoder;
862e686c
AT
353
354 if (!bridge)
355 return true;
356
05193dc3
BB
357 encoder = bridge->encoder;
358 list_for_each_entry_from(bridge, &encoder->bridge_chain, chain_node) {
359 if (!bridge->funcs->mode_fixup)
360 continue;
862e686c 361
05193dc3
BB
362 if (!bridge->funcs->mode_fixup(bridge, mode, adjusted_mode))
363 return false;
364 }
862e686c 365
05193dc3 366 return true;
862e686c 367}
ea099adf 368EXPORT_SYMBOL(drm_bridge_chain_mode_fixup);
862e686c 369
b1240f81 370/**
ea099adf
BB
371 * drm_bridge_chain_mode_valid - validate the mode against all bridges in the
372 * encoder chain.
b1240f81
JA
373 * @bridge: bridge control structure
374 * @mode: desired mode to be validated
375 *
376 * Calls &drm_bridge_funcs.mode_valid for all the bridges in the encoder
377 * chain, starting from the first bridge to the last. If at least one bridge
378 * does not accept the mode the function returns the error code.
379 *
380 * Note: the bridge passed should be the one closest to the encoder.
381 *
382 * RETURNS:
383 * MODE_OK on success, drm_mode_status Enum error code on failure
384 */
ea099adf
BB
385enum drm_mode_status
386drm_bridge_chain_mode_valid(struct drm_bridge *bridge,
387 const struct drm_display_mode *mode)
b1240f81 388{
05193dc3 389 struct drm_encoder *encoder;
b1240f81
JA
390
391 if (!bridge)
05193dc3 392 return MODE_OK;
b1240f81 393
05193dc3
BB
394 encoder = bridge->encoder;
395 list_for_each_entry_from(bridge, &encoder->bridge_chain, chain_node) {
396 enum drm_mode_status ret;
397
398 if (!bridge->funcs->mode_valid)
399 continue;
b1240f81 400
05193dc3
BB
401 ret = bridge->funcs->mode_valid(bridge, mode);
402 if (ret != MODE_OK)
403 return ret;
404 }
b1240f81 405
05193dc3 406 return MODE_OK;
b1240f81 407}
ea099adf 408EXPORT_SYMBOL(drm_bridge_chain_mode_valid);
b1240f81 409
862e686c 410/**
ea099adf 411 * drm_bridge_chain_disable - disables all bridges in the encoder chain
862e686c
AT
412 * @bridge: bridge control structure
413 *
4541d31e 414 * Calls &drm_bridge_funcs.disable op for all the bridges in the encoder
862e686c
AT
415 * chain, starting from the last bridge to the first. These are called before
416 * calling the encoder's prepare op.
417 *
418 * Note: the bridge passed should be the one closest to the encoder
419 */
ea099adf 420void drm_bridge_chain_disable(struct drm_bridge *bridge)
862e686c 421{
05193dc3
BB
422 struct drm_encoder *encoder;
423 struct drm_bridge *iter;
424
862e686c
AT
425 if (!bridge)
426 return;
427
05193dc3
BB
428 encoder = bridge->encoder;
429 list_for_each_entry_reverse(iter, &encoder->bridge_chain, chain_node) {
430 if (iter->funcs->disable)
431 iter->funcs->disable(iter);
862e686c 432
05193dc3
BB
433 if (iter == bridge)
434 break;
435 }
862e686c 436}
ea099adf 437EXPORT_SYMBOL(drm_bridge_chain_disable);
862e686c
AT
438
439/**
ea099adf
BB
440 * drm_bridge_chain_post_disable - cleans up after disabling all bridges in the
441 * encoder chain
862e686c
AT
442 * @bridge: bridge control structure
443 *
4541d31e 444 * Calls &drm_bridge_funcs.post_disable op for all the bridges in the
862e686c
AT
445 * encoder chain, starting from the first bridge to the last. These are called
446 * after completing the encoder's prepare op.
447 *
448 * Note: the bridge passed should be the one closest to the encoder
449 */
ea099adf 450void drm_bridge_chain_post_disable(struct drm_bridge *bridge)
862e686c 451{
05193dc3
BB
452 struct drm_encoder *encoder;
453
862e686c
AT
454 if (!bridge)
455 return;
456
05193dc3
BB
457 encoder = bridge->encoder;
458 list_for_each_entry_from(bridge, &encoder->bridge_chain, chain_node) {
459 if (bridge->funcs->post_disable)
460 bridge->funcs->post_disable(bridge);
461 }
862e686c 462}
ea099adf 463EXPORT_SYMBOL(drm_bridge_chain_post_disable);
862e686c
AT
464
465/**
ea099adf
BB
466 * drm_bridge_chain_mode_set - set proposed mode for all bridges in the
467 * encoder chain
862e686c 468 * @bridge: bridge control structure
ea099adf
BB
469 * @mode: desired mode to be set for the encoder chain
470 * @adjusted_mode: updated mode that works for this encoder chain
862e686c 471 *
4541d31e 472 * Calls &drm_bridge_funcs.mode_set op for all the bridges in the
862e686c
AT
473 * encoder chain, starting from the first bridge to the last.
474 *
475 * Note: the bridge passed should be the one closest to the encoder
476 */
ea099adf
BB
477void drm_bridge_chain_mode_set(struct drm_bridge *bridge,
478 const struct drm_display_mode *mode,
479 const struct drm_display_mode *adjusted_mode)
862e686c 480{
05193dc3
BB
481 struct drm_encoder *encoder;
482
862e686c
AT
483 if (!bridge)
484 return;
485
05193dc3
BB
486 encoder = bridge->encoder;
487 list_for_each_entry_from(bridge, &encoder->bridge_chain, chain_node) {
488 if (bridge->funcs->mode_set)
489 bridge->funcs->mode_set(bridge, mode, adjusted_mode);
490 }
862e686c 491}
ea099adf 492EXPORT_SYMBOL(drm_bridge_chain_mode_set);
862e686c
AT
493
494/**
ea099adf
BB
495 * drm_bridge_chain_pre_enable - prepares for enabling all bridges in the
496 * encoder chain
862e686c
AT
497 * @bridge: bridge control structure
498 *
4541d31e 499 * Calls &drm_bridge_funcs.pre_enable op for all the bridges in the encoder
862e686c
AT
500 * chain, starting from the last bridge to the first. These are called
501 * before calling the encoder's commit op.
502 *
503 * Note: the bridge passed should be the one closest to the encoder
504 */
ea099adf 505void drm_bridge_chain_pre_enable(struct drm_bridge *bridge)
862e686c 506{
05193dc3
BB
507 struct drm_encoder *encoder;
508 struct drm_bridge *iter;
509
862e686c
AT
510 if (!bridge)
511 return;
512
05193dc3
BB
513 encoder = bridge->encoder;
514 list_for_each_entry_reverse(iter, &encoder->bridge_chain, chain_node) {
515 if (iter->funcs->pre_enable)
516 iter->funcs->pre_enable(iter);
517 }
862e686c 518}
ea099adf 519EXPORT_SYMBOL(drm_bridge_chain_pre_enable);
862e686c
AT
520
521/**
ea099adf 522 * drm_bridge_chain_enable - enables all bridges in the encoder chain
862e686c
AT
523 * @bridge: bridge control structure
524 *
4541d31e 525 * Calls &drm_bridge_funcs.enable op for all the bridges in the encoder
862e686c
AT
526 * chain, starting from the first bridge to the last. These are called
527 * after completing the encoder's commit op.
528 *
529 * Note that the bridge passed should be the one closest to the encoder
530 */
ea099adf 531void drm_bridge_chain_enable(struct drm_bridge *bridge)
862e686c 532{
05193dc3
BB
533 struct drm_encoder *encoder;
534
862e686c
AT
535 if (!bridge)
536 return;
537
05193dc3
BB
538 encoder = bridge->encoder;
539 list_for_each_entry_from(bridge, &encoder->bridge_chain, chain_node) {
540 if (bridge->funcs->enable)
541 bridge->funcs->enable(bridge);
542 }
862e686c 543}
ea099adf 544EXPORT_SYMBOL(drm_bridge_chain_enable);
862e686c 545
5ade071b 546/**
ea099adf 547 * drm_atomic_bridge_chain_disable - disables all bridges in the encoder chain
5ade071b 548 * @bridge: bridge control structure
f3fdbc72 549 * @old_state: old atomic state
5ade071b
SP
550 *
551 * Calls &drm_bridge_funcs.atomic_disable (falls back on
552 * &drm_bridge_funcs.disable) op for all the bridges in the encoder chain,
553 * starting from the last bridge to the first. These are called before calling
554 * &drm_encoder_helper_funcs.atomic_disable
555 *
556 * Note: the bridge passed should be the one closest to the encoder
557 */
ea099adf 558void drm_atomic_bridge_chain_disable(struct drm_bridge *bridge,
f3fdbc72 559 struct drm_atomic_state *old_state)
5ade071b 560{
05193dc3
BB
561 struct drm_encoder *encoder;
562 struct drm_bridge *iter;
563
5ade071b
SP
564 if (!bridge)
565 return;
566
05193dc3
BB
567 encoder = bridge->encoder;
568 list_for_each_entry_reverse(iter, &encoder->bridge_chain, chain_node) {
41cf5712
BB
569 if (iter->funcs->atomic_disable) {
570 struct drm_bridge_state *old_bridge_state;
571
572 old_bridge_state =
573 drm_atomic_get_old_bridge_state(old_state,
574 iter);
575 if (WARN_ON(!old_bridge_state))
576 return;
577
578 iter->funcs->atomic_disable(iter, old_bridge_state);
579 } else if (iter->funcs->disable) {
05193dc3 580 iter->funcs->disable(iter);
41cf5712 581 }
5ade071b 582
05193dc3
BB
583 if (iter == bridge)
584 break;
585 }
5ade071b 586}
ea099adf 587EXPORT_SYMBOL(drm_atomic_bridge_chain_disable);
5ade071b
SP
588
589/**
ea099adf
BB
590 * drm_atomic_bridge_chain_post_disable - cleans up after disabling all bridges
591 * in the encoder chain
5ade071b 592 * @bridge: bridge control structure
f3fdbc72 593 * @old_state: old atomic state
5ade071b
SP
594 *
595 * Calls &drm_bridge_funcs.atomic_post_disable (falls back on
596 * &drm_bridge_funcs.post_disable) op for all the bridges in the encoder chain,
597 * starting from the first bridge to the last. These are called after completing
598 * &drm_encoder_helper_funcs.atomic_disable
599 *
600 * Note: the bridge passed should be the one closest to the encoder
601 */
ea099adf 602void drm_atomic_bridge_chain_post_disable(struct drm_bridge *bridge,
f3fdbc72 603 struct drm_atomic_state *old_state)
5ade071b 604{
05193dc3
BB
605 struct drm_encoder *encoder;
606
5ade071b
SP
607 if (!bridge)
608 return;
609
05193dc3
BB
610 encoder = bridge->encoder;
611 list_for_each_entry_from(bridge, &encoder->bridge_chain, chain_node) {
41cf5712
BB
612 if (bridge->funcs->atomic_post_disable) {
613 struct drm_bridge_state *old_bridge_state;
614
615 old_bridge_state =
616 drm_atomic_get_old_bridge_state(old_state,
617 bridge);
618 if (WARN_ON(!old_bridge_state))
619 return;
620
621 bridge->funcs->atomic_post_disable(bridge,
622 old_bridge_state);
623 } else if (bridge->funcs->post_disable) {
05193dc3 624 bridge->funcs->post_disable(bridge);
41cf5712 625 }
05193dc3 626 }
5ade071b 627}
ea099adf 628EXPORT_SYMBOL(drm_atomic_bridge_chain_post_disable);
5ade071b
SP
629
630/**
ea099adf
BB
631 * drm_atomic_bridge_chain_pre_enable - prepares for enabling all bridges in
632 * the encoder chain
5ade071b 633 * @bridge: bridge control structure
f3fdbc72 634 * @old_state: old atomic state
5ade071b
SP
635 *
636 * Calls &drm_bridge_funcs.atomic_pre_enable (falls back on
637 * &drm_bridge_funcs.pre_enable) op for all the bridges in the encoder chain,
638 * starting from the last bridge to the first. These are called before calling
639 * &drm_encoder_helper_funcs.atomic_enable
640 *
641 * Note: the bridge passed should be the one closest to the encoder
642 */
ea099adf 643void drm_atomic_bridge_chain_pre_enable(struct drm_bridge *bridge,
f3fdbc72 644 struct drm_atomic_state *old_state)
5ade071b 645{
05193dc3
BB
646 struct drm_encoder *encoder;
647 struct drm_bridge *iter;
648
5ade071b
SP
649 if (!bridge)
650 return;
651
05193dc3
BB
652 encoder = bridge->encoder;
653 list_for_each_entry_reverse(iter, &encoder->bridge_chain, chain_node) {
41cf5712
BB
654 if (iter->funcs->atomic_pre_enable) {
655 struct drm_bridge_state *old_bridge_state;
656
657 old_bridge_state =
658 drm_atomic_get_old_bridge_state(old_state,
659 iter);
660 if (WARN_ON(!old_bridge_state))
661 return;
662
663 iter->funcs->atomic_pre_enable(iter, old_bridge_state);
664 } else if (iter->funcs->pre_enable) {
05193dc3 665 iter->funcs->pre_enable(iter);
41cf5712 666 }
5ade071b 667
05193dc3
BB
668 if (iter == bridge)
669 break;
670 }
5ade071b 671}
ea099adf 672EXPORT_SYMBOL(drm_atomic_bridge_chain_pre_enable);
5ade071b
SP
673
674/**
ea099adf 675 * drm_atomic_bridge_chain_enable - enables all bridges in the encoder chain
5ade071b 676 * @bridge: bridge control structure
f3fdbc72 677 * @old_state: old atomic state
5ade071b
SP
678 *
679 * Calls &drm_bridge_funcs.atomic_enable (falls back on
680 * &drm_bridge_funcs.enable) op for all the bridges in the encoder chain,
681 * starting from the first bridge to the last. These are called after completing
682 * &drm_encoder_helper_funcs.atomic_enable
683 *
684 * Note: the bridge passed should be the one closest to the encoder
685 */
ea099adf 686void drm_atomic_bridge_chain_enable(struct drm_bridge *bridge,
f3fdbc72 687 struct drm_atomic_state *old_state)
5ade071b 688{
05193dc3
BB
689 struct drm_encoder *encoder;
690
5ade071b
SP
691 if (!bridge)
692 return;
693
05193dc3
BB
694 encoder = bridge->encoder;
695 list_for_each_entry_from(bridge, &encoder->bridge_chain, chain_node) {
41cf5712
BB
696 if (bridge->funcs->atomic_enable) {
697 struct drm_bridge_state *old_bridge_state;
698
699 old_bridge_state =
700 drm_atomic_get_old_bridge_state(old_state,
701 bridge);
702 if (WARN_ON(!old_bridge_state))
703 return;
704
705 bridge->funcs->atomic_enable(bridge, old_bridge_state);
706 } else if (bridge->funcs->enable) {
05193dc3 707 bridge->funcs->enable(bridge);
41cf5712 708 }
05193dc3 709 }
5ade071b 710}
ea099adf 711EXPORT_SYMBOL(drm_atomic_bridge_chain_enable);
5ade071b 712
5061b8a9
BB
713static int drm_atomic_bridge_check(struct drm_bridge *bridge,
714 struct drm_crtc_state *crtc_state,
715 struct drm_connector_state *conn_state)
716{
717 if (bridge->funcs->atomic_check) {
718 struct drm_bridge_state *bridge_state;
719 int ret;
720
721 bridge_state = drm_atomic_get_new_bridge_state(crtc_state->state,
722 bridge);
723 if (WARN_ON(!bridge_state))
724 return -EINVAL;
725
726 ret = bridge->funcs->atomic_check(bridge, bridge_state,
727 crtc_state, conn_state);
728 if (ret)
729 return ret;
730 } else if (bridge->funcs->mode_fixup) {
731 if (!bridge->funcs->mode_fixup(bridge, &crtc_state->mode,
732 &crtc_state->adjusted_mode))
733 return -EINVAL;
734 }
735
736 return 0;
737}
738
f32df58a
BB
739static int select_bus_fmt_recursive(struct drm_bridge *first_bridge,
740 struct drm_bridge *cur_bridge,
741 struct drm_crtc_state *crtc_state,
742 struct drm_connector_state *conn_state,
743 u32 out_bus_fmt)
744{
745 struct drm_bridge_state *cur_state;
746 unsigned int num_in_bus_fmts, i;
747 struct drm_bridge *prev_bridge;
748 u32 *in_bus_fmts;
749 int ret;
750
751 prev_bridge = drm_bridge_get_prev_bridge(cur_bridge);
752 cur_state = drm_atomic_get_new_bridge_state(crtc_state->state,
753 cur_bridge);
754
755 /*
756 * If bus format negotiation is not supported by this bridge, let's
757 * pass MEDIA_BUS_FMT_FIXED to the previous bridge in the chain and
758 * hope that it can handle this situation gracefully (by providing
759 * appropriate default values).
760 */
761 if (!cur_bridge->funcs->atomic_get_input_bus_fmts) {
762 if (cur_bridge != first_bridge) {
763 ret = select_bus_fmt_recursive(first_bridge,
764 prev_bridge, crtc_state,
765 conn_state,
766 MEDIA_BUS_FMT_FIXED);
767 if (ret)
768 return ret;
769 }
770
771 /*
772 * Driver does not implement the atomic state hooks, but that's
773 * fine, as long as it does not access the bridge state.
774 */
775 if (cur_state) {
776 cur_state->input_bus_cfg.format = MEDIA_BUS_FMT_FIXED;
777 cur_state->output_bus_cfg.format = out_bus_fmt;
778 }
779
780 return 0;
781 }
782
783 /*
784 * If the driver implements ->atomic_get_input_bus_fmts() it
785 * should also implement the atomic state hooks.
786 */
787 if (WARN_ON(!cur_state))
788 return -EINVAL;
789
790 in_bus_fmts = cur_bridge->funcs->atomic_get_input_bus_fmts(cur_bridge,
791 cur_state,
792 crtc_state,
793 conn_state,
794 out_bus_fmt,
795 &num_in_bus_fmts);
796 if (!num_in_bus_fmts)
797 return -ENOTSUPP;
798 else if (!in_bus_fmts)
799 return -ENOMEM;
800
801 if (first_bridge == cur_bridge) {
802 cur_state->input_bus_cfg.format = in_bus_fmts[0];
803 cur_state->output_bus_cfg.format = out_bus_fmt;
804 kfree(in_bus_fmts);
805 return 0;
806 }
807
808 for (i = 0; i < num_in_bus_fmts; i++) {
809 ret = select_bus_fmt_recursive(first_bridge, prev_bridge,
810 crtc_state, conn_state,
811 in_bus_fmts[i]);
812 if (ret != -ENOTSUPP)
813 break;
814 }
815
816 if (!ret) {
817 cur_state->input_bus_cfg.format = in_bus_fmts[i];
818 cur_state->output_bus_cfg.format = out_bus_fmt;
819 }
820
821 kfree(in_bus_fmts);
822 return ret;
823}
824
825/*
826 * This function is called by &drm_atomic_bridge_chain_check() just before
827 * calling &drm_bridge_funcs.atomic_check() on all elements of the chain.
828 * It performs bus format negotiation between bridge elements. The negotiation
829 * happens in reverse order, starting from the last element in the chain up to
830 * @bridge.
831 *
832 * Negotiation starts by retrieving supported output bus formats on the last
833 * bridge element and testing them one by one. The test is recursive, meaning
834 * that for each tested output format, the whole chain will be walked backward,
835 * and each element will have to choose an input bus format that can be
836 * transcoded to the requested output format. When a bridge element does not
837 * support transcoding into a specific output format -ENOTSUPP is returned and
838 * the next bridge element will have to try a different format. If none of the
839 * combinations worked, -ENOTSUPP is returned and the atomic modeset will fail.
840 *
841 * This implementation is relying on
842 * &drm_bridge_funcs.atomic_get_output_bus_fmts() and
843 * &drm_bridge_funcs.atomic_get_input_bus_fmts() to gather supported
844 * input/output formats.
845 *
846 * When &drm_bridge_funcs.atomic_get_output_bus_fmts() is not implemented by
847 * the last element of the chain, &drm_atomic_bridge_chain_select_bus_fmts()
848 * tries a single format: &drm_connector.display_info.bus_formats[0] if
849 * available, MEDIA_BUS_FMT_FIXED otherwise.
850 *
851 * When &drm_bridge_funcs.atomic_get_input_bus_fmts() is not implemented,
852 * &drm_atomic_bridge_chain_select_bus_fmts() skips the negotiation on the
853 * bridge element that lacks this hook and asks the previous element in the
854 * chain to try MEDIA_BUS_FMT_FIXED. It's up to bridge drivers to decide what
855 * to do in that case (fail if they want to enforce bus format negotiation, or
856 * provide a reasonable default if they need to support pipelines where not
857 * all elements support bus format negotiation).
858 */
859static int
860drm_atomic_bridge_chain_select_bus_fmts(struct drm_bridge *bridge,
861 struct drm_crtc_state *crtc_state,
862 struct drm_connector_state *conn_state)
863{
864 struct drm_connector *conn = conn_state->connector;
865 struct drm_encoder *encoder = bridge->encoder;
866 struct drm_bridge_state *last_bridge_state;
867 unsigned int i, num_out_bus_fmts;
868 struct drm_bridge *last_bridge;
869 u32 *out_bus_fmts;
870 int ret = 0;
871
872 last_bridge = list_last_entry(&encoder->bridge_chain,
873 struct drm_bridge, chain_node);
874 last_bridge_state = drm_atomic_get_new_bridge_state(crtc_state->state,
875 last_bridge);
876
877 if (last_bridge->funcs->atomic_get_output_bus_fmts) {
878 const struct drm_bridge_funcs *funcs = last_bridge->funcs;
879
880 /*
881 * If the driver implements ->atomic_get_output_bus_fmts() it
882 * should also implement the atomic state hooks.
883 */
884 if (WARN_ON(!last_bridge_state))
885 return -EINVAL;
886
887 out_bus_fmts = funcs->atomic_get_output_bus_fmts(last_bridge,
888 last_bridge_state,
889 crtc_state,
890 conn_state,
891 &num_out_bus_fmts);
892 if (!num_out_bus_fmts)
893 return -ENOTSUPP;
894 else if (!out_bus_fmts)
895 return -ENOMEM;
896 } else {
897 num_out_bus_fmts = 1;
898 out_bus_fmts = kmalloc(sizeof(*out_bus_fmts), GFP_KERNEL);
899 if (!out_bus_fmts)
900 return -ENOMEM;
901
902 if (conn->display_info.num_bus_formats &&
903 conn->display_info.bus_formats)
904 out_bus_fmts[0] = conn->display_info.bus_formats[0];
905 else
906 out_bus_fmts[0] = MEDIA_BUS_FMT_FIXED;
907 }
908
909 for (i = 0; i < num_out_bus_fmts; i++) {
910 ret = select_bus_fmt_recursive(bridge, last_bridge, crtc_state,
911 conn_state, out_bus_fmts[i]);
912 if (ret != -ENOTSUPP)
913 break;
914 }
915
916 kfree(out_bus_fmts);
917
918 return ret;
919}
920
921static void
922drm_atomic_bridge_propagate_bus_flags(struct drm_bridge *bridge,
923 struct drm_connector *conn,
924 struct drm_atomic_state *state)
925{
926 struct drm_bridge_state *bridge_state, *next_bridge_state;
927 struct drm_bridge *next_bridge;
928 u32 output_flags = 0;
929
930 bridge_state = drm_atomic_get_new_bridge_state(state, bridge);
931
932 /* No bridge state attached to this bridge => nothing to propagate. */
933 if (!bridge_state)
934 return;
935
936 next_bridge = drm_bridge_get_next_bridge(bridge);
937
938 /*
939 * Let's try to apply the most common case here, that is, propagate
940 * display_info flags for the last bridge, and propagate the input
941 * flags of the next bridge element to the output end of the current
942 * bridge when the bridge is not the last one.
943 * There are exceptions to this rule, like when signal inversion is
944 * happening at the board level, but that's something drivers can deal
945 * with from their &drm_bridge_funcs.atomic_check() implementation by
946 * simply overriding the flags value we've set here.
947 */
948 if (!next_bridge) {
949 output_flags = conn->display_info.bus_flags;
950 } else {
951 next_bridge_state = drm_atomic_get_new_bridge_state(state,
952 next_bridge);
953 /*
954 * No bridge state attached to the next bridge, just leave the
955 * flags to 0.
956 */
957 if (next_bridge_state)
958 output_flags = next_bridge_state->input_bus_cfg.flags;
959 }
960
961 bridge_state->output_bus_cfg.flags = output_flags;
962
963 /*
964 * Propage the output flags to the input end of the bridge. Again, it's
965 * not necessarily what all bridges want, but that's what most of them
966 * do, and by doing that by default we avoid forcing drivers to
967 * duplicate the "dummy propagation" logic.
968 */
969 bridge_state->input_bus_cfg.flags = output_flags;
970}
971
5061b8a9
BB
972/**
973 * drm_atomic_bridge_chain_check() - Do an atomic check on the bridge chain
974 * @bridge: bridge control structure
975 * @crtc_state: new CRTC state
976 * @conn_state: new connector state
977 *
f32df58a
BB
978 * First trigger a bus format negotiation before calling
979 * &drm_bridge_funcs.atomic_check() (falls back on
5061b8a9
BB
980 * &drm_bridge_funcs.mode_fixup()) op for all the bridges in the encoder chain,
981 * starting from the last bridge to the first. These are called before calling
982 * &drm_encoder_helper_funcs.atomic_check()
983 *
984 * RETURNS:
985 * 0 on success, a negative error code on failure
986 */
987int drm_atomic_bridge_chain_check(struct drm_bridge *bridge,
988 struct drm_crtc_state *crtc_state,
989 struct drm_connector_state *conn_state)
990{
f32df58a 991 struct drm_connector *conn = conn_state->connector;
5061b8a9
BB
992 struct drm_encoder *encoder;
993 struct drm_bridge *iter;
f32df58a 994 int ret;
5061b8a9
BB
995
996 if (!bridge)
997 return 0;
998
f32df58a
BB
999 ret = drm_atomic_bridge_chain_select_bus_fmts(bridge, crtc_state,
1000 conn_state);
1001 if (ret)
1002 return ret;
1003
5061b8a9
BB
1004 encoder = bridge->encoder;
1005 list_for_each_entry_reverse(iter, &encoder->bridge_chain, chain_node) {
1006 int ret;
1007
f32df58a
BB
1008 /*
1009 * Bus flags are propagated by default. If a bridge needs to
1010 * tweak the input bus flags for any reason, it should happen
1011 * in its &drm_bridge_funcs.atomic_check() implementation such
1012 * that preceding bridges in the chain can propagate the new
1013 * bus flags.
1014 */
1015 drm_atomic_bridge_propagate_bus_flags(iter, conn,
1016 crtc_state->state);
1017
5061b8a9
BB
1018 ret = drm_atomic_bridge_check(iter, crtc_state, conn_state);
1019 if (ret)
1020 return ret;
1021
1022 if (iter == bridge)
1023 break;
1024 }
1025
1026 return 0;
1027}
1028EXPORT_SYMBOL(drm_atomic_bridge_chain_check);
1029
11f6c4b1
LP
1030/**
1031 * drm_bridge_detect - check if anything is attached to the bridge output
1032 * @bridge: bridge control structure
1033 *
1034 * If the bridge supports output detection, as reported by the
1035 * DRM_BRIDGE_OP_DETECT bridge ops flag, call &drm_bridge_funcs.detect for the
1036 * bridge and return the connection status. Otherwise return
1037 * connector_status_unknown.
1038 *
1039 * RETURNS:
1040 * The detection status on success, or connector_status_unknown if the bridge
1041 * doesn't support output detection.
1042 */
1043enum drm_connector_status drm_bridge_detect(struct drm_bridge *bridge)
1044{
1045 if (!(bridge->ops & DRM_BRIDGE_OP_DETECT))
1046 return connector_status_unknown;
1047
1048 return bridge->funcs->detect(bridge);
1049}
1050EXPORT_SYMBOL_GPL(drm_bridge_detect);
1051
1052/**
1053 * drm_bridge_get_modes - fill all modes currently valid for the sink into the
1054 * @connector
1055 * @bridge: bridge control structure
1056 * @connector: the connector to fill with modes
1057 *
1058 * If the bridge supports output modes retrieval, as reported by the
1059 * DRM_BRIDGE_OP_MODES bridge ops flag, call &drm_bridge_funcs.get_modes to
1060 * fill the connector with all valid modes and return the number of modes
1061 * added. Otherwise return 0.
1062 *
1063 * RETURNS:
1064 * The number of modes added to the connector.
1065 */
1066int drm_bridge_get_modes(struct drm_bridge *bridge,
1067 struct drm_connector *connector)
1068{
1069 if (!(bridge->ops & DRM_BRIDGE_OP_MODES))
1070 return 0;
1071
1072 return bridge->funcs->get_modes(bridge, connector);
1073}
1074EXPORT_SYMBOL_GPL(drm_bridge_get_modes);
1075
1076/**
1077 * drm_bridge_get_edid - get the EDID data of the connected display
1078 * @bridge: bridge control structure
1079 * @connector: the connector to read EDID for
1080 *
1081 * If the bridge supports output EDID retrieval, as reported by the
1082 * DRM_BRIDGE_OP_EDID bridge ops flag, call &drm_bridge_funcs.get_edid to
1083 * get the EDID and return it. Otherwise return ERR_PTR(-ENOTSUPP).
1084 *
1085 * RETURNS:
1086 * The retrieved EDID on success, or an error pointer otherwise.
1087 */
1088struct edid *drm_bridge_get_edid(struct drm_bridge *bridge,
1089 struct drm_connector *connector)
1090{
1091 if (!(bridge->ops & DRM_BRIDGE_OP_EDID))
1092 return ERR_PTR(-ENOTSUPP);
1093
1094 return bridge->funcs->get_edid(bridge, connector);
1095}
1096EXPORT_SYMBOL_GPL(drm_bridge_get_edid);
1097
1098/**
1099 * drm_bridge_hpd_enable - enable hot plug detection for the bridge
1100 * @bridge: bridge control structure
1101 * @cb: hot-plug detection callback
1102 * @data: data to be passed to the hot-plug detection callback
1103 *
1104 * Call &drm_bridge_funcs.hpd_enable if implemented and register the given @cb
1105 * and @data as hot plug notification callback. From now on the @cb will be
1106 * called with @data when an output status change is detected by the bridge,
1107 * until hot plug notification gets disabled with drm_bridge_hpd_disable().
1108 *
1109 * Hot plug detection is supported only if the DRM_BRIDGE_OP_HPD flag is set in
1110 * bridge->ops. This function shall not be called when the flag is not set.
1111 *
1112 * Only one hot plug detection callback can be registered at a time, it is an
1113 * error to call this function when hot plug detection is already enabled for
1114 * the bridge.
1115 */
1116void drm_bridge_hpd_enable(struct drm_bridge *bridge,
1117 void (*cb)(void *data,
1118 enum drm_connector_status status),
1119 void *data)
1120{
1121 if (!(bridge->ops & DRM_BRIDGE_OP_HPD))
1122 return;
1123
1124 mutex_lock(&bridge->hpd_mutex);
1125
1126 if (WARN(bridge->hpd_cb, "Hot plug detection already enabled\n"))
1127 goto unlock;
1128
1129 bridge->hpd_cb = cb;
1130 bridge->hpd_data = data;
1131
1132 if (bridge->funcs->hpd_enable)
1133 bridge->funcs->hpd_enable(bridge);
1134
1135unlock:
1136 mutex_unlock(&bridge->hpd_mutex);
1137}
1138EXPORT_SYMBOL_GPL(drm_bridge_hpd_enable);
1139
1140/**
1141 * drm_bridge_hpd_disable - disable hot plug detection for the bridge
1142 * @bridge: bridge control structure
1143 *
1144 * Call &drm_bridge_funcs.hpd_disable if implemented and unregister the hot
1145 * plug detection callback previously registered with drm_bridge_hpd_enable().
1146 * Once this function returns the callback will not be called by the bridge
1147 * when an output status change occurs.
1148 *
1149 * Hot plug detection is supported only if the DRM_BRIDGE_OP_HPD flag is set in
1150 * bridge->ops. This function shall not be called when the flag is not set.
1151 */
1152void drm_bridge_hpd_disable(struct drm_bridge *bridge)
1153{
1154 if (!(bridge->ops & DRM_BRIDGE_OP_HPD))
1155 return;
1156
1157 mutex_lock(&bridge->hpd_mutex);
1158 if (bridge->funcs->hpd_disable)
1159 bridge->funcs->hpd_disable(bridge);
1160
1161 bridge->hpd_cb = NULL;
1162 bridge->hpd_data = NULL;
1163 mutex_unlock(&bridge->hpd_mutex);
1164}
1165EXPORT_SYMBOL_GPL(drm_bridge_hpd_disable);
1166
1167/**
1168 * drm_bridge_hpd_notify - notify hot plug detection events
1169 * @bridge: bridge control structure
1170 * @status: output connection status
1171 *
1172 * Bridge drivers shall call this function to report hot plug events when they
1173 * detect a change in the output status, when hot plug detection has been
1174 * enabled by drm_bridge_hpd_enable().
1175 *
1176 * This function shall be called in a context that can sleep.
1177 */
1178void drm_bridge_hpd_notify(struct drm_bridge *bridge,
1179 enum drm_connector_status status)
1180{
1181 mutex_lock(&bridge->hpd_mutex);
1182 if (bridge->hpd_cb)
1183 bridge->hpd_cb(bridge->hpd_data, status);
1184 mutex_unlock(&bridge->hpd_mutex);
1185}
1186EXPORT_SYMBOL_GPL(drm_bridge_hpd_notify);
1187
3d3f8b1f 1188#ifdef CONFIG_OF
2331b4e4
AT
1189/**
1190 * of_drm_find_bridge - find the bridge corresponding to the device node in
1191 * the global bridge list
1192 *
1193 * @np: device node
1194 *
1195 * RETURNS:
1196 * drm_bridge control struct on success, NULL on failure
1197 */
3d3f8b1f
AK
1198struct drm_bridge *of_drm_find_bridge(struct device_node *np)
1199{
1200 struct drm_bridge *bridge;
1201
1202 mutex_lock(&bridge_lock);
1203
1204 list_for_each_entry(bridge, &bridge_list, list) {
1205 if (bridge->of_node == np) {
1206 mutex_unlock(&bridge_lock);
1207 return bridge;
1208 }
1209 }
1210
1211 mutex_unlock(&bridge_lock);
1212 return NULL;
1213}
1214EXPORT_SYMBOL(of_drm_find_bridge);
1215#endif
1216
1217MODULE_AUTHOR("Ajay Kumar <ajaykumar.rs@samsung.com>");
1218MODULE_DESCRIPTION("DRM bridge infrastructure");
1219MODULE_LICENSE("GPL and additional rights");