]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/gpu/drm/drm_bridge.c
Revert "drm/bridge: Add the necessary bits to support bus format negotiation"
[linux.git] / drivers / gpu / drm / drm_bridge.c
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 #include <linux/mutex.h>
27
28 #include <drm/drm_atomic_state_helper.h>
29 #include <drm/drm_bridge.h>
30 #include <drm/drm_encoder.h>
31
32 #include "drm_crtc_internal.h"
33
34 /**
35  * DOC: overview
36  *
37  * &struct drm_bridge represents a device that hangs on to an encoder. These are
38  * handy when a regular &drm_encoder entity isn't enough to represent the entire
39  * encoder chain.
40  *
41  * A bridge is always attached to a single &drm_encoder at a time, but can be
42  * either connected to it directly, or through an intermediate bridge::
43  *
44  *     encoder ---> bridge B ---> bridge A
45  *
46  * Here, the output of the encoder feeds to bridge B, and that furthers feeds to
47  * bridge A.
48  *
49  * The driver using the bridge is responsible to make the associations between
50  * the encoder and bridges. Once these links are made, the bridges will
51  * participate along with encoder functions to perform mode_set/enable/disable
52  * through the ops provided in &drm_bridge_funcs.
53  *
54  * drm_bridge, like drm_panel, aren't drm_mode_object entities like planes,
55  * CRTCs, encoders or connectors and hence are not visible to userspace. They
56  * just provide additional hooks to get the desired output at the end of the
57  * encoder chain.
58  *
59  * Bridges can also be chained up using the &drm_bridge.chain_node field.
60  *
61  * Both legacy CRTC helpers and the new atomic modeset helpers support bridges.
62  */
63
64 static DEFINE_MUTEX(bridge_lock);
65 static LIST_HEAD(bridge_list);
66
67 /**
68  * drm_bridge_add - add the given bridge to the global bridge list
69  *
70  * @bridge: bridge control structure
71  */
72 void drm_bridge_add(struct drm_bridge *bridge)
73 {
74         mutex_lock(&bridge_lock);
75         list_add_tail(&bridge->list, &bridge_list);
76         mutex_unlock(&bridge_lock);
77 }
78 EXPORT_SYMBOL(drm_bridge_add);
79
80 /**
81  * drm_bridge_remove - remove the given bridge from the global bridge list
82  *
83  * @bridge: bridge control structure
84  */
85 void drm_bridge_remove(struct drm_bridge *bridge)
86 {
87         mutex_lock(&bridge_lock);
88         list_del_init(&bridge->list);
89         mutex_unlock(&bridge_lock);
90 }
91 EXPORT_SYMBOL(drm_bridge_remove);
92
93 static struct drm_bridge_state *
94 drm_atomic_default_bridge_duplicate_state(struct drm_bridge *bridge)
95 {
96         struct drm_bridge_state *new;
97
98         if (WARN_ON(!bridge->base.state))
99                 return NULL;
100
101         new = kzalloc(sizeof(*new), GFP_KERNEL);
102         if (new)
103                 __drm_atomic_helper_bridge_duplicate_state(bridge, new);
104
105         return new;
106 }
107
108 static struct drm_private_state *
109 drm_bridge_atomic_duplicate_priv_state(struct drm_private_obj *obj)
110 {
111         struct drm_bridge *bridge = drm_priv_to_bridge(obj);
112         struct drm_bridge_state *state;
113
114         if (bridge->funcs->atomic_duplicate_state)
115                 state = bridge->funcs->atomic_duplicate_state(bridge);
116         else
117                 state = drm_atomic_default_bridge_duplicate_state(bridge);
118
119         return state ? &state->base : NULL;
120 }
121
122 static void
123 drm_atomic_default_bridge_destroy_state(struct drm_bridge *bridge,
124                                         struct drm_bridge_state *state)
125 {
126         /* Just a simple kfree() for now */
127         kfree(state);
128 }
129
130 static void
131 drm_bridge_atomic_destroy_priv_state(struct drm_private_obj *obj,
132                                      struct drm_private_state *s)
133 {
134         struct drm_bridge_state *state = drm_priv_to_bridge_state(s);
135         struct drm_bridge *bridge = drm_priv_to_bridge(obj);
136
137         if (bridge->funcs->atomic_destroy_state)
138                 bridge->funcs->atomic_destroy_state(bridge, state);
139         else
140                 drm_atomic_default_bridge_destroy_state(bridge, state);
141 }
142
143 static const struct drm_private_state_funcs drm_bridge_priv_state_funcs = {
144         .atomic_duplicate_state = drm_bridge_atomic_duplicate_priv_state,
145         .atomic_destroy_state = drm_bridge_atomic_destroy_priv_state,
146 };
147
148 static struct drm_bridge_state *
149 drm_atomic_default_bridge_reset(struct drm_bridge *bridge)
150 {
151         struct drm_bridge_state *bridge_state;
152
153         bridge_state = kzalloc(sizeof(*bridge_state), GFP_KERNEL);
154         if (!bridge_state)
155                 return ERR_PTR(-ENOMEM);
156
157         __drm_atomic_helper_bridge_reset(bridge, bridge_state);
158         return bridge_state;
159 }
160
161 /**
162  * drm_bridge_attach - attach the bridge to an encoder's chain
163  *
164  * @encoder: DRM encoder
165  * @bridge: bridge to attach
166  * @previous: previous bridge in the chain (optional)
167  *
168  * Called by a kms driver to link the bridge to an encoder's chain. The previous
169  * argument specifies the previous bridge in the chain. If NULL, the bridge is
170  * linked directly at the encoder's output. Otherwise it is linked at the
171  * previous bridge's output.
172  *
173  * If non-NULL the previous bridge must be already attached by a call to this
174  * function.
175  *
176  * Note that bridges attached to encoders are auto-detached during encoder
177  * cleanup in drm_encoder_cleanup(), so drm_bridge_attach() should generally
178  * *not* be balanced with a drm_bridge_detach() in driver code.
179  *
180  * RETURNS:
181  * Zero on success, error code on failure
182  */
183 int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
184                       struct drm_bridge *previous)
185 {
186         struct drm_bridge_state *state;
187         int ret;
188
189         if (!encoder || !bridge)
190                 return -EINVAL;
191
192         if (previous && (!previous->dev || previous->encoder != encoder))
193                 return -EINVAL;
194
195         if (bridge->dev)
196                 return -EBUSY;
197
198         bridge->dev = encoder->dev;
199         bridge->encoder = encoder;
200
201         if (previous)
202                 list_add(&bridge->chain_node, &previous->chain_node);
203         else
204                 list_add(&bridge->chain_node, &encoder->bridge_chain);
205
206         if (bridge->funcs->attach) {
207                 ret = bridge->funcs->attach(bridge);
208                 if (ret < 0)
209                         goto err_reset_bridge;
210         }
211
212         if (bridge->funcs->atomic_reset)
213                 state = bridge->funcs->atomic_reset(bridge);
214         else
215                 state = drm_atomic_default_bridge_reset(bridge);
216
217         if (IS_ERR(state)) {
218                 ret = PTR_ERR(state);
219                 goto err_detach_bridge;
220         }
221
222         drm_atomic_private_obj_init(bridge->dev, &bridge->base,
223                                     &state->base,
224                                     &drm_bridge_priv_state_funcs);
225
226         return 0;
227
228 err_detach_bridge:
229         if (bridge->funcs->detach)
230                 bridge->funcs->detach(bridge);
231
232 err_reset_bridge:
233         bridge->dev = NULL;
234         bridge->encoder = NULL;
235         list_del(&bridge->chain_node);
236         return ret;
237 }
238 EXPORT_SYMBOL(drm_bridge_attach);
239
240 void drm_bridge_detach(struct drm_bridge *bridge)
241 {
242         if (WARN_ON(!bridge))
243                 return;
244
245         if (WARN_ON(!bridge->dev))
246                 return;
247
248         drm_atomic_private_obj_fini(&bridge->base);
249
250         if (bridge->funcs->detach)
251                 bridge->funcs->detach(bridge);
252
253         list_del(&bridge->chain_node);
254         bridge->dev = NULL;
255 }
256
257 /**
258  * DOC: bridge callbacks
259  *
260  * The &drm_bridge_funcs ops are populated by the bridge driver. The DRM
261  * internals (atomic and CRTC helpers) use the helpers defined in drm_bridge.c
262  * These helpers call a specific &drm_bridge_funcs op for all the bridges
263  * during encoder configuration.
264  *
265  * For detailed specification of the bridge callbacks see &drm_bridge_funcs.
266  */
267
268 /**
269  * drm_bridge_chain_mode_fixup - fixup proposed mode for all bridges in the
270  *                               encoder chain
271  * @bridge: bridge control structure
272  * @mode: desired mode to be set for the bridge
273  * @adjusted_mode: updated mode that works for this bridge
274  *
275  * Calls &drm_bridge_funcs.mode_fixup for all the bridges in the
276  * encoder chain, starting from the first bridge to the last.
277  *
278  * Note: the bridge passed should be the one closest to the encoder
279  *
280  * RETURNS:
281  * true on success, false on failure
282  */
283 bool drm_bridge_chain_mode_fixup(struct drm_bridge *bridge,
284                                  const struct drm_display_mode *mode,
285                                  struct drm_display_mode *adjusted_mode)
286 {
287         struct drm_encoder *encoder;
288
289         if (!bridge)
290                 return true;
291
292         encoder = bridge->encoder;
293         list_for_each_entry_from(bridge, &encoder->bridge_chain, chain_node) {
294                 if (!bridge->funcs->mode_fixup)
295                         continue;
296
297                 if (!bridge->funcs->mode_fixup(bridge, mode, adjusted_mode))
298                         return false;
299         }
300
301         return true;
302 }
303 EXPORT_SYMBOL(drm_bridge_chain_mode_fixup);
304
305 /**
306  * drm_bridge_chain_mode_valid - validate the mode against all bridges in the
307  *                               encoder chain.
308  * @bridge: bridge control structure
309  * @mode: desired mode to be validated
310  *
311  * Calls &drm_bridge_funcs.mode_valid for all the bridges in the encoder
312  * chain, starting from the first bridge to the last. If at least one bridge
313  * does not accept the mode the function returns the error code.
314  *
315  * Note: the bridge passed should be the one closest to the encoder.
316  *
317  * RETURNS:
318  * MODE_OK on success, drm_mode_status Enum error code on failure
319  */
320 enum drm_mode_status
321 drm_bridge_chain_mode_valid(struct drm_bridge *bridge,
322                             const struct drm_display_mode *mode)
323 {
324         struct drm_encoder *encoder;
325
326         if (!bridge)
327                 return MODE_OK;
328
329         encoder = bridge->encoder;
330         list_for_each_entry_from(bridge, &encoder->bridge_chain, chain_node) {
331                 enum drm_mode_status ret;
332
333                 if (!bridge->funcs->mode_valid)
334                         continue;
335
336                 ret = bridge->funcs->mode_valid(bridge, mode);
337                 if (ret != MODE_OK)
338                         return ret;
339         }
340
341         return MODE_OK;
342 }
343 EXPORT_SYMBOL(drm_bridge_chain_mode_valid);
344
345 /**
346  * drm_bridge_chain_disable - disables all bridges in the encoder chain
347  * @bridge: bridge control structure
348  *
349  * Calls &drm_bridge_funcs.disable op for all the bridges in the encoder
350  * chain, starting from the last bridge to the first. These are called before
351  * calling the encoder's prepare op.
352  *
353  * Note: the bridge passed should be the one closest to the encoder
354  */
355 void drm_bridge_chain_disable(struct drm_bridge *bridge)
356 {
357         struct drm_encoder *encoder;
358         struct drm_bridge *iter;
359
360         if (!bridge)
361                 return;
362
363         encoder = bridge->encoder;
364         list_for_each_entry_reverse(iter, &encoder->bridge_chain, chain_node) {
365                 if (iter->funcs->disable)
366                         iter->funcs->disable(iter);
367
368                 if (iter == bridge)
369                         break;
370         }
371 }
372 EXPORT_SYMBOL(drm_bridge_chain_disable);
373
374 /**
375  * drm_bridge_chain_post_disable - cleans up after disabling all bridges in the
376  *                                 encoder chain
377  * @bridge: bridge control structure
378  *
379  * Calls &drm_bridge_funcs.post_disable op for all the bridges in the
380  * encoder chain, starting from the first bridge to the last. These are called
381  * after completing the encoder's prepare op.
382  *
383  * Note: the bridge passed should be the one closest to the encoder
384  */
385 void drm_bridge_chain_post_disable(struct drm_bridge *bridge)
386 {
387         struct drm_encoder *encoder;
388
389         if (!bridge)
390                 return;
391
392         encoder = bridge->encoder;
393         list_for_each_entry_from(bridge, &encoder->bridge_chain, chain_node) {
394                 if (bridge->funcs->post_disable)
395                         bridge->funcs->post_disable(bridge);
396         }
397 }
398 EXPORT_SYMBOL(drm_bridge_chain_post_disable);
399
400 /**
401  * drm_bridge_chain_mode_set - set proposed mode for all bridges in the
402  *                             encoder chain
403  * @bridge: bridge control structure
404  * @mode: desired mode to be set for the encoder chain
405  * @adjusted_mode: updated mode that works for this encoder chain
406  *
407  * Calls &drm_bridge_funcs.mode_set op for all the bridges in the
408  * encoder chain, starting from the first bridge to the last.
409  *
410  * Note: the bridge passed should be the one closest to the encoder
411  */
412 void drm_bridge_chain_mode_set(struct drm_bridge *bridge,
413                                const struct drm_display_mode *mode,
414                                const struct drm_display_mode *adjusted_mode)
415 {
416         struct drm_encoder *encoder;
417
418         if (!bridge)
419                 return;
420
421         encoder = bridge->encoder;
422         list_for_each_entry_from(bridge, &encoder->bridge_chain, chain_node) {
423                 if (bridge->funcs->mode_set)
424                         bridge->funcs->mode_set(bridge, mode, adjusted_mode);
425         }
426 }
427 EXPORT_SYMBOL(drm_bridge_chain_mode_set);
428
429 /**
430  * drm_bridge_chain_pre_enable - prepares for enabling all bridges in the
431  *                               encoder chain
432  * @bridge: bridge control structure
433  *
434  * Calls &drm_bridge_funcs.pre_enable op for all the bridges in the encoder
435  * chain, starting from the last bridge to the first. These are called
436  * before calling the encoder's commit op.
437  *
438  * Note: the bridge passed should be the one closest to the encoder
439  */
440 void drm_bridge_chain_pre_enable(struct drm_bridge *bridge)
441 {
442         struct drm_encoder *encoder;
443         struct drm_bridge *iter;
444
445         if (!bridge)
446                 return;
447
448         encoder = bridge->encoder;
449         list_for_each_entry_reverse(iter, &encoder->bridge_chain, chain_node) {
450                 if (iter->funcs->pre_enable)
451                         iter->funcs->pre_enable(iter);
452         }
453 }
454 EXPORT_SYMBOL(drm_bridge_chain_pre_enable);
455
456 /**
457  * drm_bridge_chain_enable - enables all bridges in the encoder chain
458  * @bridge: bridge control structure
459  *
460  * Calls &drm_bridge_funcs.enable op for all the bridges in the encoder
461  * chain, starting from the first bridge to the last. These are called
462  * after completing the encoder's commit op.
463  *
464  * Note that the bridge passed should be the one closest to the encoder
465  */
466 void drm_bridge_chain_enable(struct drm_bridge *bridge)
467 {
468         struct drm_encoder *encoder;
469
470         if (!bridge)
471                 return;
472
473         encoder = bridge->encoder;
474         list_for_each_entry_from(bridge, &encoder->bridge_chain, chain_node) {
475                 if (bridge->funcs->enable)
476                         bridge->funcs->enable(bridge);
477         }
478 }
479 EXPORT_SYMBOL(drm_bridge_chain_enable);
480
481 /**
482  * drm_atomic_bridge_chain_disable - disables all bridges in the encoder chain
483  * @bridge: bridge control structure
484  * @old_state: old atomic state
485  *
486  * Calls &drm_bridge_funcs.atomic_disable (falls back on
487  * &drm_bridge_funcs.disable) op for all the bridges in the encoder chain,
488  * starting from the last bridge to the first. These are called before calling
489  * &drm_encoder_helper_funcs.atomic_disable
490  *
491  * Note: the bridge passed should be the one closest to the encoder
492  */
493 void drm_atomic_bridge_chain_disable(struct drm_bridge *bridge,
494                                      struct drm_atomic_state *old_state)
495 {
496         struct drm_encoder *encoder;
497         struct drm_bridge *iter;
498
499         if (!bridge)
500                 return;
501
502         encoder = bridge->encoder;
503         list_for_each_entry_reverse(iter, &encoder->bridge_chain, chain_node) {
504                 if (iter->funcs->atomic_disable) {
505                         struct drm_bridge_state *old_bridge_state;
506
507                         old_bridge_state =
508                                 drm_atomic_get_old_bridge_state(old_state,
509                                                                 iter);
510                         if (WARN_ON(!old_bridge_state))
511                                 return;
512
513                         iter->funcs->atomic_disable(iter, old_bridge_state);
514                 } else if (iter->funcs->disable) {
515                         iter->funcs->disable(iter);
516                 }
517
518                 if (iter == bridge)
519                         break;
520         }
521 }
522 EXPORT_SYMBOL(drm_atomic_bridge_chain_disable);
523
524 /**
525  * drm_atomic_bridge_chain_post_disable - cleans up after disabling all bridges
526  *                                        in the encoder chain
527  * @bridge: bridge control structure
528  * @old_state: old atomic state
529  *
530  * Calls &drm_bridge_funcs.atomic_post_disable (falls back on
531  * &drm_bridge_funcs.post_disable) op for all the bridges in the encoder chain,
532  * starting from the first bridge to the last. These are called after completing
533  * &drm_encoder_helper_funcs.atomic_disable
534  *
535  * Note: the bridge passed should be the one closest to the encoder
536  */
537 void drm_atomic_bridge_chain_post_disable(struct drm_bridge *bridge,
538                                           struct drm_atomic_state *old_state)
539 {
540         struct drm_encoder *encoder;
541
542         if (!bridge)
543                 return;
544
545         encoder = bridge->encoder;
546         list_for_each_entry_from(bridge, &encoder->bridge_chain, chain_node) {
547                 if (bridge->funcs->atomic_post_disable) {
548                         struct drm_bridge_state *old_bridge_state;
549
550                         old_bridge_state =
551                                 drm_atomic_get_old_bridge_state(old_state,
552                                                                 bridge);
553                         if (WARN_ON(!old_bridge_state))
554                                 return;
555
556                         bridge->funcs->atomic_post_disable(bridge,
557                                                            old_bridge_state);
558                 } else if (bridge->funcs->post_disable) {
559                         bridge->funcs->post_disable(bridge);
560                 }
561         }
562 }
563 EXPORT_SYMBOL(drm_atomic_bridge_chain_post_disable);
564
565 /**
566  * drm_atomic_bridge_chain_pre_enable - prepares for enabling all bridges in
567  *                                      the encoder chain
568  * @bridge: bridge control structure
569  * @old_state: old atomic state
570  *
571  * Calls &drm_bridge_funcs.atomic_pre_enable (falls back on
572  * &drm_bridge_funcs.pre_enable) op for all the bridges in the encoder chain,
573  * starting from the last bridge to the first. These are called before calling
574  * &drm_encoder_helper_funcs.atomic_enable
575  *
576  * Note: the bridge passed should be the one closest to the encoder
577  */
578 void drm_atomic_bridge_chain_pre_enable(struct drm_bridge *bridge,
579                                         struct drm_atomic_state *old_state)
580 {
581         struct drm_encoder *encoder;
582         struct drm_bridge *iter;
583
584         if (!bridge)
585                 return;
586
587         encoder = bridge->encoder;
588         list_for_each_entry_reverse(iter, &encoder->bridge_chain, chain_node) {
589                 if (iter->funcs->atomic_pre_enable) {
590                         struct drm_bridge_state *old_bridge_state;
591
592                         old_bridge_state =
593                                 drm_atomic_get_old_bridge_state(old_state,
594                                                                 iter);
595                         if (WARN_ON(!old_bridge_state))
596                                 return;
597
598                         iter->funcs->atomic_pre_enable(iter, old_bridge_state);
599                 } else if (iter->funcs->pre_enable) {
600                         iter->funcs->pre_enable(iter);
601                 }
602
603                 if (iter == bridge)
604                         break;
605         }
606 }
607 EXPORT_SYMBOL(drm_atomic_bridge_chain_pre_enable);
608
609 /**
610  * drm_atomic_bridge_chain_enable - enables all bridges in the encoder chain
611  * @bridge: bridge control structure
612  * @old_state: old atomic state
613  *
614  * Calls &drm_bridge_funcs.atomic_enable (falls back on
615  * &drm_bridge_funcs.enable) op for all the bridges in the encoder chain,
616  * starting from the first bridge to the last. These are called after completing
617  * &drm_encoder_helper_funcs.atomic_enable
618  *
619  * Note: the bridge passed should be the one closest to the encoder
620  */
621 void drm_atomic_bridge_chain_enable(struct drm_bridge *bridge,
622                                     struct drm_atomic_state *old_state)
623 {
624         struct drm_encoder *encoder;
625
626         if (!bridge)
627                 return;
628
629         encoder = bridge->encoder;
630         list_for_each_entry_from(bridge, &encoder->bridge_chain, chain_node) {
631                 if (bridge->funcs->atomic_enable) {
632                         struct drm_bridge_state *old_bridge_state;
633
634                         old_bridge_state =
635                                 drm_atomic_get_old_bridge_state(old_state,
636                                                                 bridge);
637                         if (WARN_ON(!old_bridge_state))
638                                 return;
639
640                         bridge->funcs->atomic_enable(bridge, old_bridge_state);
641                 } else if (bridge->funcs->enable) {
642                         bridge->funcs->enable(bridge);
643                 }
644         }
645 }
646 EXPORT_SYMBOL(drm_atomic_bridge_chain_enable);
647
648 static int drm_atomic_bridge_check(struct drm_bridge *bridge,
649                                    struct drm_crtc_state *crtc_state,
650                                    struct drm_connector_state *conn_state)
651 {
652         if (bridge->funcs->atomic_check) {
653                 struct drm_bridge_state *bridge_state;
654                 int ret;
655
656                 bridge_state = drm_atomic_get_new_bridge_state(crtc_state->state,
657                                                                bridge);
658                 if (WARN_ON(!bridge_state))
659                         return -EINVAL;
660
661                 ret = bridge->funcs->atomic_check(bridge, bridge_state,
662                                                   crtc_state, conn_state);
663                 if (ret)
664                         return ret;
665         } else if (bridge->funcs->mode_fixup) {
666                 if (!bridge->funcs->mode_fixup(bridge, &crtc_state->mode,
667                                                &crtc_state->adjusted_mode))
668                         return -EINVAL;
669         }
670
671         return 0;
672 }
673
674 /**
675  * drm_atomic_bridge_chain_check() - Do an atomic check on the bridge chain
676  * @bridge: bridge control structure
677  * @crtc_state: new CRTC state
678  * @conn_state: new connector state
679  *
680  * Calls &drm_bridge_funcs.atomic_check() (falls back on
681  * &drm_bridge_funcs.mode_fixup()) op for all the bridges in the encoder chain,
682  * starting from the last bridge to the first. These are called before calling
683  * &drm_encoder_helper_funcs.atomic_check()
684  *
685  * RETURNS:
686  * 0 on success, a negative error code on failure
687  */
688 int drm_atomic_bridge_chain_check(struct drm_bridge *bridge,
689                                   struct drm_crtc_state *crtc_state,
690                                   struct drm_connector_state *conn_state)
691 {
692         struct drm_encoder *encoder = bridge->encoder;
693         struct drm_bridge *iter;
694
695         list_for_each_entry_reverse(iter, &encoder->bridge_chain, chain_node) {
696                 int ret;
697
698                 ret = drm_atomic_bridge_check(iter, crtc_state, conn_state);
699                 if (ret)
700                         return ret;
701
702                 if (iter == bridge)
703                         break;
704         }
705
706         return 0;
707 }
708 EXPORT_SYMBOL(drm_atomic_bridge_chain_check);
709
710 /**
711  * __drm_atomic_helper_bridge_reset() - Initialize a bridge state to its
712  *                                      default
713  * @bridge: the bridge this state is refers to
714  * @state: bridge state to initialize
715  *
716  * Initialize the bridge state to default values. This is meant to be* called
717  * by the bridge &drm_plane_funcs.reset hook for bridges that subclass the
718  * bridge state.
719  */
720 void __drm_atomic_helper_bridge_reset(struct drm_bridge *bridge,
721                                       struct drm_bridge_state *state)
722 {
723         memset(state, 0, sizeof(*state));
724         state->bridge = bridge;
725 }
726 EXPORT_SYMBOL(__drm_atomic_helper_bridge_reset);
727
728 /**
729  * __drm_atomic_helper_bridge_duplicate_state() - Copy atomic bridge state
730  * @bridge: bridge object
731  * @state: atomic bridge state
732  *
733  * Copies atomic state from a bridge's current state and resets inferred values.
734  * This is useful for drivers that subclass the bridge state.
735  */
736 void __drm_atomic_helper_bridge_duplicate_state(struct drm_bridge *bridge,
737                                                 struct drm_bridge_state *state)
738 {
739         __drm_atomic_helper_private_obj_duplicate_state(&bridge->base,
740                                                         &state->base);
741         state->bridge = bridge;
742 }
743 EXPORT_SYMBOL(__drm_atomic_helper_bridge_duplicate_state);
744
745 #ifdef CONFIG_OF
746 /**
747  * of_drm_find_bridge - find the bridge corresponding to the device node in
748  *                      the global bridge list
749  *
750  * @np: device node
751  *
752  * RETURNS:
753  * drm_bridge control struct on success, NULL on failure
754  */
755 struct drm_bridge *of_drm_find_bridge(struct device_node *np)
756 {
757         struct drm_bridge *bridge;
758
759         mutex_lock(&bridge_lock);
760
761         list_for_each_entry(bridge, &bridge_list, list) {
762                 if (bridge->of_node == np) {
763                         mutex_unlock(&bridge_lock);
764                         return bridge;
765                 }
766         }
767
768         mutex_unlock(&bridge_lock);
769         return NULL;
770 }
771 EXPORT_SYMBOL(of_drm_find_bridge);
772 #endif
773
774 MODULE_AUTHOR("Ajay Kumar <ajaykumar.rs@samsung.com>");
775 MODULE_DESCRIPTION("DRM bridge infrastructure");
776 MODULE_LICENSE("GPL and additional rights");