Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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