/*1* Copyright (c) 2014 Samsung Electronics Co., Ltd2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sub license,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the11* next paragraph) shall be included in all copies or substantial portions12* of the Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER20* DEALINGS IN THE SOFTWARE.21*/2223#include <linux/debugfs.h>24#include <linux/err.h>25#include <linux/export.h>26#include <linux/media-bus-format.h>27#include <linux/module.h>28#include <linux/mutex.h>2930#include <drm/drm_atomic_state_helper.h>31#include <drm/drm_bridge.h>32#include <drm/drm_debugfs.h>33#include <drm/drm_edid.h>34#include <drm/drm_encoder.h>35#include <drm/drm_file.h>36#include <drm/drm_of.h>37#include <drm/drm_print.h>3839#include "drm_crtc_internal.h"4041/**42* DOC: overview43*44* &struct drm_bridge represents a device that hangs on to an encoder. These are45* handy when a regular &drm_encoder entity isn't enough to represent the entire46* encoder chain.47*48* A bridge is always attached to a single &drm_encoder at a time, but can be49* either connected to it directly, or through a chain of bridges::50*51* [ CRTC ---> ] Encoder ---> Bridge A ---> Bridge B52*53* Here, the output of the encoder feeds to bridge A, and that furthers feeds to54* bridge B. Bridge chains can be arbitrarily long, and shall be fully linear:55* Chaining multiple bridges to the output of a bridge, or the same bridge to56* the output of different bridges, is not supported.57*58* &drm_bridge, like &drm_panel, aren't &drm_mode_object entities like planes,59* CRTCs, encoders or connectors and hence are not visible to userspace. They60* just provide additional hooks to get the desired output at the end of the61* encoder chain.62*/6364/**65* DOC: display driver integration66*67* Display drivers are responsible for linking encoders with the first bridge68* in the chains. This is done by acquiring the appropriate bridge with69* devm_drm_of_get_bridge(). Once acquired, the bridge shall be attached to the70* encoder with a call to drm_bridge_attach().71*72* Bridges are responsible for linking themselves with the next bridge in the73* chain, if any. This is done the same way as for encoders, with the call to74* drm_bridge_attach() occurring in the &drm_bridge_funcs.attach operation.75*76* Once these links are created, the bridges can participate along with encoder77* functions to perform mode validation and fixup (through78* drm_bridge_chain_mode_valid() and drm_atomic_bridge_chain_check()), mode79* setting (through drm_bridge_chain_mode_set()), enable (through80* drm_atomic_bridge_chain_pre_enable() and drm_atomic_bridge_chain_enable())81* and disable (through drm_atomic_bridge_chain_disable() and82* drm_atomic_bridge_chain_post_disable()). Those functions call the83* corresponding operations provided in &drm_bridge_funcs in sequence for all84* bridges in the chain.85*86* For display drivers that use the atomic helpers87* drm_atomic_helper_check_modeset(),88* drm_atomic_helper_commit_modeset_enables() and89* drm_atomic_helper_commit_modeset_disables() (either directly in hand-rolled90* commit check and commit tail handlers, or through the higher-level91* drm_atomic_helper_check() and drm_atomic_helper_commit_tail() or92* drm_atomic_helper_commit_tail_rpm() helpers), this is done transparently and93* requires no intervention from the driver. For other drivers, the relevant94* DRM bridge chain functions shall be called manually.95*96* Bridges also participate in implementing the &drm_connector at the end of97* the bridge chain. Display drivers may use the drm_bridge_connector_init()98* helper to create the &drm_connector, or implement it manually on top of the99* connector-related operations exposed by the bridge (see the overview100* documentation of bridge operations for more details).101*/102103/**104* DOC: special care dsi105*106* The interaction between the bridges and other frameworks involved in107* the probing of the upstream driver and the bridge driver can be108* challenging. Indeed, there's multiple cases that needs to be109* considered:110*111* - The upstream driver doesn't use the component framework and isn't a112* MIPI-DSI host. In this case, the bridge driver will probe at some113* point and the upstream driver should try to probe again by returning114* EPROBE_DEFER as long as the bridge driver hasn't probed.115*116* - The upstream driver doesn't use the component framework, but is a117* MIPI-DSI host. The bridge device uses the MIPI-DCS commands to be118* controlled. In this case, the bridge device is a child of the119* display device and when it will probe it's assured that the display120* device (and MIPI-DSI host) is present. The upstream driver will be121* assured that the bridge driver is connected between the122* &mipi_dsi_host_ops.attach and &mipi_dsi_host_ops.detach operations.123* Therefore, it must run mipi_dsi_host_register() in its probe124* function, and then run drm_bridge_attach() in its125* &mipi_dsi_host_ops.attach hook.126*127* - The upstream driver uses the component framework and is a MIPI-DSI128* host. The bridge device uses the MIPI-DCS commands to be129* controlled. This is the same situation than above, and can run130* mipi_dsi_host_register() in either its probe or bind hooks.131*132* - The upstream driver uses the component framework and is a MIPI-DSI133* host. The bridge device uses a separate bus (such as I2C) to be134* controlled. In this case, there's no correlation between the probe135* of the bridge and upstream drivers, so care must be taken to avoid136* an endless EPROBE_DEFER loop, with each driver waiting for the137* other to probe.138*139* The ideal pattern to cover the last item (and all the others in the140* MIPI-DSI host driver case) is to split the operations like this:141*142* - The MIPI-DSI host driver must run mipi_dsi_host_register() in its143* probe hook. It will make sure that the MIPI-DSI host sticks around,144* and that the driver's bind can be called.145*146* - In its probe hook, the bridge driver must try to find its MIPI-DSI147* host, register as a MIPI-DSI device and attach the MIPI-DSI device148* to its host. The bridge driver is now functional.149*150* - In its &struct mipi_dsi_host_ops.attach hook, the MIPI-DSI host can151* now add its component. Its bind hook will now be called and since152* the bridge driver is attached and registered, we can now look for153* and attach it.154*155* At this point, we're now certain that both the upstream driver and156* the bridge driver are functional and we can't have a deadlock-like157* situation when probing.158*/159160/**161* DOC: dsi bridge operations162*163* DSI host interfaces are expected to be implemented as bridges rather than164* encoders, however there are a few aspects of their operation that need to165* be defined in order to provide a consistent interface.166*167* A DSI host should keep the PHY powered down until the pre_enable operation is168* called. All lanes are in an undefined idle state up to this point, and it169* must not be assumed that it is LP-11.170* pre_enable should initialise the PHY, set the data lanes to LP-11, and the171* clock lane to either LP-11 or HS depending on the mode_flag172* %MIPI_DSI_CLOCK_NON_CONTINUOUS.173*174* Ordinarily the downstream bridge DSI peripheral pre_enable will have been175* called before the DSI host. If the DSI peripheral requires LP-11 and/or176* the clock lane to be in HS mode prior to pre_enable, then it can set the177* &pre_enable_prev_first flag to request the pre_enable (and178* post_disable) order to be altered to enable the DSI host first.179*180* Either the CRTC being enabled, or the DSI host enable operation should switch181* the host to actively transmitting video on the data lanes.182*183* The reverse also applies. The DSI host disable operation or stopping the CRTC184* should stop transmitting video, and the data lanes should return to the LP-11185* state. The DSI host &post_disable operation should disable the PHY.186* If the &pre_enable_prev_first flag is set, then the DSI peripheral's187* bridge &post_disable will be called before the DSI host's post_disable.188*189* Whilst it is valid to call &host_transfer prior to pre_enable or after190* post_disable, the exact state of the lanes is undefined at this point. The191* DSI host should initialise the interface, transmit the data, and then disable192* the interface again.193*194* Ultra Low Power State (ULPS) is not explicitly supported by DRM. If195* implemented, it therefore needs to be handled entirely within the DSI Host196* driver.197*/198199static DEFINE_MUTEX(bridge_lock);200static LIST_HEAD(bridge_list);201202static void __drm_bridge_free(struct kref *kref)203{204struct drm_bridge *bridge = container_of(kref, struct drm_bridge, refcount);205206if (bridge->funcs->destroy)207bridge->funcs->destroy(bridge);208kfree(bridge->container);209}210211/**212* drm_bridge_get - Acquire a bridge reference213* @bridge: DRM bridge214*215* This function increments the bridge's refcount.216*217* Returns:218* Pointer to @bridge.219*/220struct drm_bridge *drm_bridge_get(struct drm_bridge *bridge)221{222if (bridge)223kref_get(&bridge->refcount);224225return bridge;226}227EXPORT_SYMBOL(drm_bridge_get);228229/**230* drm_bridge_put - Release a bridge reference231* @bridge: DRM bridge232*233* This function decrements the bridge's reference count and frees the234* object if the reference count drops to zero.235*/236void drm_bridge_put(struct drm_bridge *bridge)237{238if (bridge)239kref_put(&bridge->refcount, __drm_bridge_free);240}241EXPORT_SYMBOL(drm_bridge_put);242243/**244* drm_bridge_put_void - wrapper to drm_bridge_put() taking a void pointer245*246* @data: pointer to @struct drm_bridge, cast to a void pointer247*248* Wrapper of drm_bridge_put() to be used when a function taking a void249* pointer is needed, for example as a devm action.250*/251static void drm_bridge_put_void(void *data)252{253struct drm_bridge *bridge = (struct drm_bridge *)data;254255drm_bridge_put(bridge);256}257258void *__devm_drm_bridge_alloc(struct device *dev, size_t size, size_t offset,259const struct drm_bridge_funcs *funcs)260{261void *container;262struct drm_bridge *bridge;263int err;264265if (!funcs) {266dev_warn(dev, "Missing funcs pointer\n");267return ERR_PTR(-EINVAL);268}269270container = kzalloc(size, GFP_KERNEL);271if (!container)272return ERR_PTR(-ENOMEM);273274bridge = container + offset;275bridge->container = container;276bridge->funcs = funcs;277kref_init(&bridge->refcount);278279err = devm_add_action_or_reset(dev, drm_bridge_put_void, bridge);280if (err)281return ERR_PTR(err);282283return container;284}285EXPORT_SYMBOL(__devm_drm_bridge_alloc);286287/**288* drm_bridge_add - add the given bridge to the global bridge list289*290* @bridge: bridge control structure291*292* The bridge to be added must have been allocated by293* devm_drm_bridge_alloc().294*/295void drm_bridge_add(struct drm_bridge *bridge)296{297if (!bridge->container)298DRM_WARN("DRM bridge corrupted or not allocated by devm_drm_bridge_alloc()\n");299300drm_bridge_get(bridge);301302mutex_init(&bridge->hpd_mutex);303304if (bridge->ops & DRM_BRIDGE_OP_HDMI)305bridge->ycbcr_420_allowed = !!(bridge->supported_formats &306BIT(HDMI_COLORSPACE_YUV420));307308mutex_lock(&bridge_lock);309list_add_tail(&bridge->list, &bridge_list);310mutex_unlock(&bridge_lock);311}312EXPORT_SYMBOL(drm_bridge_add);313314static void drm_bridge_remove_void(void *bridge)315{316drm_bridge_remove(bridge);317}318319/**320* devm_drm_bridge_add - devm managed version of drm_bridge_add()321*322* @dev: device to tie the bridge lifetime to323* @bridge: bridge control structure324*325* This is the managed version of drm_bridge_add() which automatically326* calls drm_bridge_remove() when @dev is unbound.327*328* Return: 0 if no error or negative error code.329*/330int devm_drm_bridge_add(struct device *dev, struct drm_bridge *bridge)331{332drm_bridge_add(bridge);333return devm_add_action_or_reset(dev, drm_bridge_remove_void, bridge);334}335EXPORT_SYMBOL(devm_drm_bridge_add);336337/**338* drm_bridge_remove - remove the given bridge from the global bridge list339*340* @bridge: bridge control structure341*/342void drm_bridge_remove(struct drm_bridge *bridge)343{344mutex_lock(&bridge_lock);345list_del_init(&bridge->list);346mutex_unlock(&bridge_lock);347348mutex_destroy(&bridge->hpd_mutex);349350drm_bridge_put(bridge);351}352EXPORT_SYMBOL(drm_bridge_remove);353354static struct drm_private_state *355drm_bridge_atomic_duplicate_priv_state(struct drm_private_obj *obj)356{357struct drm_bridge *bridge = drm_priv_to_bridge(obj);358struct drm_bridge_state *state;359360state = bridge->funcs->atomic_duplicate_state(bridge);361return state ? &state->base : NULL;362}363364static void365drm_bridge_atomic_destroy_priv_state(struct drm_private_obj *obj,366struct drm_private_state *s)367{368struct drm_bridge_state *state = drm_priv_to_bridge_state(s);369struct drm_bridge *bridge = drm_priv_to_bridge(obj);370371bridge->funcs->atomic_destroy_state(bridge, state);372}373374static const struct drm_private_state_funcs drm_bridge_priv_state_funcs = {375.atomic_duplicate_state = drm_bridge_atomic_duplicate_priv_state,376.atomic_destroy_state = drm_bridge_atomic_destroy_priv_state,377};378379static bool drm_bridge_is_atomic(struct drm_bridge *bridge)380{381return bridge->funcs->atomic_reset != NULL;382}383384/**385* drm_bridge_attach - attach the bridge to an encoder's chain386*387* @encoder: DRM encoder388* @bridge: bridge to attach389* @previous: previous bridge in the chain (optional)390* @flags: DRM_BRIDGE_ATTACH_* flags391*392* Called by a kms driver to link the bridge to an encoder's chain. The previous393* argument specifies the previous bridge in the chain. If NULL, the bridge is394* linked directly at the encoder's output. Otherwise it is linked at the395* previous bridge's output.396*397* If non-NULL the previous bridge must be already attached by a call to this398* function.399*400* Note that bridges attached to encoders are auto-detached during encoder401* cleanup in drm_encoder_cleanup(), so drm_bridge_attach() should generally402* *not* be balanced with a drm_bridge_detach() in driver code.403*404* RETURNS:405* Zero on success, error code on failure406*/407int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,408struct drm_bridge *previous,409enum drm_bridge_attach_flags flags)410{411int ret;412413if (!encoder || !bridge)414return -EINVAL;415416drm_bridge_get(bridge);417418if (previous && (!previous->dev || previous->encoder != encoder)) {419ret = -EINVAL;420goto err_put_bridge;421}422423if (bridge->dev) {424ret = -EBUSY;425goto err_put_bridge;426}427428bridge->dev = encoder->dev;429bridge->encoder = encoder;430431if (previous)432list_add(&bridge->chain_node, &previous->chain_node);433else434list_add(&bridge->chain_node, &encoder->bridge_chain);435436if (bridge->funcs->attach) {437ret = bridge->funcs->attach(bridge, encoder, flags);438if (ret < 0)439goto err_reset_bridge;440}441442if (drm_bridge_is_atomic(bridge)) {443struct drm_bridge_state *state;444445state = bridge->funcs->atomic_reset(bridge);446if (IS_ERR(state)) {447ret = PTR_ERR(state);448goto err_detach_bridge;449}450451drm_atomic_private_obj_init(bridge->dev, &bridge->base,452&state->base,453&drm_bridge_priv_state_funcs);454}455456return 0;457458err_detach_bridge:459if (bridge->funcs->detach)460bridge->funcs->detach(bridge);461462err_reset_bridge:463bridge->dev = NULL;464bridge->encoder = NULL;465list_del(&bridge->chain_node);466467if (ret != -EPROBE_DEFER)468DRM_ERROR("failed to attach bridge %pOF to encoder %s: %d\n",469bridge->of_node, encoder->name, ret);470else471dev_err_probe(encoder->dev->dev, -EPROBE_DEFER,472"failed to attach bridge %pOF to encoder %s\n",473bridge->of_node, encoder->name);474475err_put_bridge:476drm_bridge_put(bridge);477return ret;478}479EXPORT_SYMBOL(drm_bridge_attach);480481void drm_bridge_detach(struct drm_bridge *bridge)482{483if (WARN_ON(!bridge))484return;485486if (WARN_ON(!bridge->dev))487return;488489if (drm_bridge_is_atomic(bridge))490drm_atomic_private_obj_fini(&bridge->base);491492if (bridge->funcs->detach)493bridge->funcs->detach(bridge);494495list_del(&bridge->chain_node);496bridge->dev = NULL;497drm_bridge_put(bridge);498}499500/**501* DOC: bridge operations502*503* Bridge drivers expose operations through the &drm_bridge_funcs structure.504* The DRM internals (atomic and CRTC helpers) use the helpers defined in505* drm_bridge.c to call bridge operations. Those operations are divided in506* three big categories to support different parts of the bridge usage.507*508* - The encoder-related operations support control of the bridges in the509* chain, and are roughly counterparts to the &drm_encoder_helper_funcs510* operations. They are used by the legacy CRTC and the atomic modeset511* helpers to perform mode validation, fixup and setting, and enable and512* disable the bridge automatically.513*514* The enable and disable operations are split in515* &drm_bridge_funcs.pre_enable, &drm_bridge_funcs.enable,516* &drm_bridge_funcs.disable and &drm_bridge_funcs.post_disable to provide517* finer-grained control.518*519* Bridge drivers may implement the legacy version of those operations, or520* the atomic version (prefixed with atomic\_), in which case they shall also521* implement the atomic state bookkeeping operations522* (&drm_bridge_funcs.atomic_duplicate_state,523* &drm_bridge_funcs.atomic_destroy_state and &drm_bridge_funcs.reset).524* Mixing atomic and non-atomic versions of the operations is not supported.525*526* - The bus format negotiation operations527* &drm_bridge_funcs.atomic_get_output_bus_fmts and528* &drm_bridge_funcs.atomic_get_input_bus_fmts allow bridge drivers to529* negotiate the formats transmitted between bridges in the chain when530* multiple formats are supported. Negotiation for formats is performed531* transparently for display drivers by the atomic modeset helpers. Only532* atomic versions of those operations exist, bridge drivers that need to533* implement them shall thus also implement the atomic version of the534* encoder-related operations. This feature is not supported by the legacy535* CRTC helpers.536*537* - The connector-related operations support implementing a &drm_connector538* based on a chain of bridges. DRM bridges traditionally create a539* &drm_connector for bridges meant to be used at the end of the chain. This540* puts additional burden on bridge drivers, especially for bridges that may541* be used in the middle of a chain or at the end of it. Furthermore, it542* requires all operations of the &drm_connector to be handled by a single543* bridge, which doesn't always match the hardware architecture.544*545* To simplify bridge drivers and make the connector implementation more546* flexible, a new model allows bridges to unconditionally skip creation of547* &drm_connector and instead expose &drm_bridge_funcs operations to support548* an externally-implemented &drm_connector. Those operations are549* &drm_bridge_funcs.detect, &drm_bridge_funcs.get_modes,550* &drm_bridge_funcs.get_edid, &drm_bridge_funcs.hpd_notify,551* &drm_bridge_funcs.hpd_enable and &drm_bridge_funcs.hpd_disable. When552* implemented, display drivers shall create a &drm_connector instance for553* each chain of bridges, and implement those connector instances based on554* the bridge connector operations.555*556* Bridge drivers shall implement the connector-related operations for all557* the features that the bridge hardware support. For instance, if a bridge558* supports reading EDID, the &drm_bridge_funcs.get_edid shall be559* implemented. This however doesn't mean that the DDC lines are wired to the560* bridge on a particular platform, as they could also be connected to an I2C561* controller of the SoC. Support for the connector-related operations on the562* running platform is reported through the &drm_bridge.ops flags. Bridge563* drivers shall detect which operations they can support on the platform564* (usually this information is provided by ACPI or DT), and set the565* &drm_bridge.ops flags for all supported operations. A flag shall only be566* set if the corresponding &drm_bridge_funcs operation is implemented, but567* an implemented operation doesn't necessarily imply that the corresponding568* flag will be set. Display drivers shall use the &drm_bridge.ops flags to569* decide which bridge to delegate a connector operation to. This mechanism570* allows providing a single static const &drm_bridge_funcs instance in571* bridge drivers, improving security by storing function pointers in572* read-only memory.573*574* In order to ease transition, bridge drivers may support both the old and575* new models by making connector creation optional and implementing the576* connected-related bridge operations. Connector creation is then controlled577* by the flags argument to the drm_bridge_attach() function. Display drivers578* that support the new model and create connectors themselves shall set the579* %DRM_BRIDGE_ATTACH_NO_CONNECTOR flag, and bridge drivers shall then skip580* connector creation. For intermediate bridges in the chain, the flag shall581* be passed to the drm_bridge_attach() call for the downstream bridge.582* Bridge drivers that implement the new model only shall return an error583* from their &drm_bridge_funcs.attach handler when the584* %DRM_BRIDGE_ATTACH_NO_CONNECTOR flag is not set. New display drivers585* should use the new model, and convert the bridge drivers they use if586* needed, in order to gradually transition to the new model.587*/588589/**590* drm_bridge_chain_mode_valid - validate the mode against all bridges in the591* encoder chain.592* @bridge: bridge control structure593* @info: display info against which the mode shall be validated594* @mode: desired mode to be validated595*596* Calls &drm_bridge_funcs.mode_valid for all the bridges in the encoder597* chain, starting from the first bridge to the last. If at least one bridge598* does not accept the mode the function returns the error code.599*600* Note: the bridge passed should be the one closest to the encoder.601*602* RETURNS:603* MODE_OK on success, drm_mode_status Enum error code on failure604*/605enum drm_mode_status606drm_bridge_chain_mode_valid(struct drm_bridge *bridge,607const struct drm_display_info *info,608const struct drm_display_mode *mode)609{610struct drm_encoder *encoder;611612if (!bridge)613return MODE_OK;614615encoder = bridge->encoder;616list_for_each_entry_from(bridge, &encoder->bridge_chain, chain_node) {617enum drm_mode_status ret;618619if (!bridge->funcs->mode_valid)620continue;621622ret = bridge->funcs->mode_valid(bridge, info, mode);623if (ret != MODE_OK)624return ret;625}626627return MODE_OK;628}629EXPORT_SYMBOL(drm_bridge_chain_mode_valid);630631/**632* drm_bridge_chain_mode_set - set proposed mode for all bridges in the633* encoder chain634* @bridge: bridge control structure635* @mode: desired mode to be set for the encoder chain636* @adjusted_mode: updated mode that works for this encoder chain637*638* Calls &drm_bridge_funcs.mode_set op for all the bridges in the639* encoder chain, starting from the first bridge to the last.640*641* Note: the bridge passed should be the one closest to the encoder642*/643void drm_bridge_chain_mode_set(struct drm_bridge *bridge,644const struct drm_display_mode *mode,645const struct drm_display_mode *adjusted_mode)646{647struct drm_encoder *encoder;648649if (!bridge)650return;651652encoder = bridge->encoder;653list_for_each_entry_from(bridge, &encoder->bridge_chain, chain_node) {654if (bridge->funcs->mode_set)655bridge->funcs->mode_set(bridge, mode, adjusted_mode);656}657}658EXPORT_SYMBOL(drm_bridge_chain_mode_set);659660/**661* drm_atomic_bridge_chain_disable - disables all bridges in the encoder chain662* @bridge: bridge control structure663* @state: atomic state being committed664*665* Calls &drm_bridge_funcs.atomic_disable (falls back on666* &drm_bridge_funcs.disable) op for all the bridges in the encoder chain,667* starting from the last bridge to the first. These are called before calling668* &drm_encoder_helper_funcs.atomic_disable669*670* Note: the bridge passed should be the one closest to the encoder671*/672void drm_atomic_bridge_chain_disable(struct drm_bridge *bridge,673struct drm_atomic_state *state)674{675struct drm_encoder *encoder;676struct drm_bridge *iter;677678if (!bridge)679return;680681encoder = bridge->encoder;682list_for_each_entry_reverse(iter, &encoder->bridge_chain, chain_node) {683if (iter->funcs->atomic_disable) {684iter->funcs->atomic_disable(iter, state);685} else if (iter->funcs->disable) {686iter->funcs->disable(iter);687}688689if (iter == bridge)690break;691}692}693EXPORT_SYMBOL(drm_atomic_bridge_chain_disable);694695static void drm_atomic_bridge_call_post_disable(struct drm_bridge *bridge,696struct drm_atomic_state *state)697{698if (state && bridge->funcs->atomic_post_disable)699bridge->funcs->atomic_post_disable(bridge, state);700else if (bridge->funcs->post_disable)701bridge->funcs->post_disable(bridge);702}703704/**705* drm_atomic_bridge_chain_post_disable - cleans up after disabling all bridges706* in the encoder chain707* @bridge: bridge control structure708* @state: atomic state being committed709*710* Calls &drm_bridge_funcs.atomic_post_disable (falls back on711* &drm_bridge_funcs.post_disable) op for all the bridges in the encoder chain,712* starting from the first bridge to the last. These are called after completing713* &drm_encoder_helper_funcs.atomic_disable714*715* If a bridge sets @pre_enable_prev_first, then the @post_disable for that716* bridge will be called before the previous one to reverse the @pre_enable717* calling direction.718*719* Example:720* Bridge A ---> Bridge B ---> Bridge C ---> Bridge D ---> Bridge E721*722* With pre_enable_prev_first flag enable in Bridge B, D, E then the resulting723* @post_disable order would be,724* Bridge B, Bridge A, Bridge E, Bridge D, Bridge C.725*726* Note: the bridge passed should be the one closest to the encoder727*/728void drm_atomic_bridge_chain_post_disable(struct drm_bridge *bridge,729struct drm_atomic_state *state)730{731struct drm_encoder *encoder;732struct drm_bridge *next, *limit;733734if (!bridge)735return;736737encoder = bridge->encoder;738739list_for_each_entry_from(bridge, &encoder->bridge_chain, chain_node) {740limit = NULL;741742if (!list_is_last(&bridge->chain_node, &encoder->bridge_chain)) {743next = list_next_entry(bridge, chain_node);744745if (next->pre_enable_prev_first) {746/* next bridge had requested that prev747* was enabled first, so disabled last748*/749limit = next;750751/* Find the next bridge that has NOT requested752* prev to be enabled first / disabled last753*/754list_for_each_entry_from(next, &encoder->bridge_chain,755chain_node) {756if (!next->pre_enable_prev_first) {757next = list_prev_entry(next, chain_node);758limit = next;759break;760}761762if (list_is_last(&next->chain_node,763&encoder->bridge_chain)) {764limit = next;765break;766}767}768769/* Call these bridges in reverse order */770list_for_each_entry_from_reverse(next, &encoder->bridge_chain,771chain_node) {772if (next == bridge)773break;774775drm_atomic_bridge_call_post_disable(next,776state);777}778}779}780781drm_atomic_bridge_call_post_disable(bridge, state);782783if (limit)784/* Jump all bridges that we have already post_disabled */785bridge = limit;786}787}788EXPORT_SYMBOL(drm_atomic_bridge_chain_post_disable);789790static void drm_atomic_bridge_call_pre_enable(struct drm_bridge *bridge,791struct drm_atomic_state *state)792{793if (state && bridge->funcs->atomic_pre_enable)794bridge->funcs->atomic_pre_enable(bridge, state);795else if (bridge->funcs->pre_enable)796bridge->funcs->pre_enable(bridge);797}798799/**800* drm_atomic_bridge_chain_pre_enable - prepares for enabling all bridges in801* the encoder chain802* @bridge: bridge control structure803* @state: atomic state being committed804*805* Calls &drm_bridge_funcs.atomic_pre_enable (falls back on806* &drm_bridge_funcs.pre_enable) op for all the bridges in the encoder chain,807* starting from the last bridge to the first. These are called before calling808* &drm_encoder_helper_funcs.atomic_enable809*810* If a bridge sets @pre_enable_prev_first, then the pre_enable for the811* prev bridge will be called before pre_enable of this bridge.812*813* Example:814* Bridge A ---> Bridge B ---> Bridge C ---> Bridge D ---> Bridge E815*816* With pre_enable_prev_first flag enable in Bridge B, D, E then the resulting817* @pre_enable order would be,818* Bridge C, Bridge D, Bridge E, Bridge A, Bridge B.819*820* Note: the bridge passed should be the one closest to the encoder821*/822void drm_atomic_bridge_chain_pre_enable(struct drm_bridge *bridge,823struct drm_atomic_state *state)824{825struct drm_encoder *encoder;826struct drm_bridge *iter, *next, *limit;827828if (!bridge)829return;830831encoder = bridge->encoder;832833list_for_each_entry_reverse(iter, &encoder->bridge_chain, chain_node) {834if (iter->pre_enable_prev_first) {835next = iter;836limit = bridge;837list_for_each_entry_from_reverse(next,838&encoder->bridge_chain,839chain_node) {840if (next == bridge)841break;842843if (!next->pre_enable_prev_first) {844/* Found first bridge that does NOT845* request prev to be enabled first846*/847limit = next;848break;849}850}851852list_for_each_entry_from(next, &encoder->bridge_chain, chain_node) {853/* Call requested prev bridge pre_enable854* in order.855*/856if (next == iter)857/* At the first bridge to request prev858* bridges called first.859*/860break;861862drm_atomic_bridge_call_pre_enable(next, state);863}864}865866drm_atomic_bridge_call_pre_enable(iter, state);867868if (iter->pre_enable_prev_first)869/* Jump all bridges that we have already pre_enabled */870iter = limit;871872if (iter == bridge)873break;874}875}876EXPORT_SYMBOL(drm_atomic_bridge_chain_pre_enable);877878/**879* drm_atomic_bridge_chain_enable - enables all bridges in the encoder chain880* @bridge: bridge control structure881* @state: atomic state being committed882*883* Calls &drm_bridge_funcs.atomic_enable (falls back on884* &drm_bridge_funcs.enable) op for all the bridges in the encoder chain,885* starting from the first bridge to the last. These are called after completing886* &drm_encoder_helper_funcs.atomic_enable887*888* Note: the bridge passed should be the one closest to the encoder889*/890void drm_atomic_bridge_chain_enable(struct drm_bridge *bridge,891struct drm_atomic_state *state)892{893struct drm_encoder *encoder;894895if (!bridge)896return;897898encoder = bridge->encoder;899list_for_each_entry_from(bridge, &encoder->bridge_chain, chain_node) {900if (bridge->funcs->atomic_enable) {901bridge->funcs->atomic_enable(bridge, state);902} else if (bridge->funcs->enable) {903bridge->funcs->enable(bridge);904}905}906}907EXPORT_SYMBOL(drm_atomic_bridge_chain_enable);908909static int drm_atomic_bridge_check(struct drm_bridge *bridge,910struct drm_crtc_state *crtc_state,911struct drm_connector_state *conn_state)912{913if (bridge->funcs->atomic_check) {914struct drm_bridge_state *bridge_state;915int ret;916917bridge_state = drm_atomic_get_new_bridge_state(crtc_state->state,918bridge);919if (WARN_ON(!bridge_state))920return -EINVAL;921922ret = bridge->funcs->atomic_check(bridge, bridge_state,923crtc_state, conn_state);924if (ret)925return ret;926} else if (bridge->funcs->mode_fixup) {927if (!bridge->funcs->mode_fixup(bridge, &crtc_state->mode,928&crtc_state->adjusted_mode))929return -EINVAL;930}931932return 0;933}934935static int select_bus_fmt_recursive(struct drm_bridge *first_bridge,936struct drm_bridge *cur_bridge,937struct drm_crtc_state *crtc_state,938struct drm_connector_state *conn_state,939u32 out_bus_fmt)940{941unsigned int i, num_in_bus_fmts = 0;942struct drm_bridge_state *cur_state;943struct drm_bridge *prev_bridge;944u32 *in_bus_fmts;945int ret;946947prev_bridge = drm_bridge_get_prev_bridge(cur_bridge);948cur_state = drm_atomic_get_new_bridge_state(crtc_state->state,949cur_bridge);950951/*952* If bus format negotiation is not supported by this bridge, let's953* pass MEDIA_BUS_FMT_FIXED to the previous bridge in the chain and954* hope that it can handle this situation gracefully (by providing955* appropriate default values).956*/957if (!cur_bridge->funcs->atomic_get_input_bus_fmts) {958if (cur_bridge != first_bridge) {959ret = select_bus_fmt_recursive(first_bridge,960prev_bridge, crtc_state,961conn_state,962MEDIA_BUS_FMT_FIXED);963if (ret)964return ret;965}966967/*968* Driver does not implement the atomic state hooks, but that's969* fine, as long as it does not access the bridge state.970*/971if (cur_state) {972cur_state->input_bus_cfg.format = MEDIA_BUS_FMT_FIXED;973cur_state->output_bus_cfg.format = out_bus_fmt;974}975976return 0;977}978979/*980* If the driver implements ->atomic_get_input_bus_fmts() it981* should also implement the atomic state hooks.982*/983if (WARN_ON(!cur_state))984return -EINVAL;985986in_bus_fmts = cur_bridge->funcs->atomic_get_input_bus_fmts(cur_bridge,987cur_state,988crtc_state,989conn_state,990out_bus_fmt,991&num_in_bus_fmts);992if (!num_in_bus_fmts)993return -ENOTSUPP;994else if (!in_bus_fmts)995return -ENOMEM;996997if (first_bridge == cur_bridge) {998cur_state->input_bus_cfg.format = in_bus_fmts[0];999cur_state->output_bus_cfg.format = out_bus_fmt;1000kfree(in_bus_fmts);1001return 0;1002}10031004for (i = 0; i < num_in_bus_fmts; i++) {1005ret = select_bus_fmt_recursive(first_bridge, prev_bridge,1006crtc_state, conn_state,1007in_bus_fmts[i]);1008if (ret != -ENOTSUPP)1009break;1010}10111012if (!ret) {1013cur_state->input_bus_cfg.format = in_bus_fmts[i];1014cur_state->output_bus_cfg.format = out_bus_fmt;1015}10161017kfree(in_bus_fmts);1018return ret;1019}10201021/*1022* This function is called by &drm_atomic_bridge_chain_check() just before1023* calling &drm_bridge_funcs.atomic_check() on all elements of the chain.1024* It performs bus format negotiation between bridge elements. The negotiation1025* happens in reverse order, starting from the last element in the chain up to1026* @bridge.1027*1028* Negotiation starts by retrieving supported output bus formats on the last1029* bridge element and testing them one by one. The test is recursive, meaning1030* that for each tested output format, the whole chain will be walked backward,1031* and each element will have to choose an input bus format that can be1032* transcoded to the requested output format. When a bridge element does not1033* support transcoding into a specific output format -ENOTSUPP is returned and1034* the next bridge element will have to try a different format. If none of the1035* combinations worked, -ENOTSUPP is returned and the atomic modeset will fail.1036*1037* This implementation is relying on1038* &drm_bridge_funcs.atomic_get_output_bus_fmts() and1039* &drm_bridge_funcs.atomic_get_input_bus_fmts() to gather supported1040* input/output formats.1041*1042* When &drm_bridge_funcs.atomic_get_output_bus_fmts() is not implemented by1043* the last element of the chain, &drm_atomic_bridge_chain_select_bus_fmts()1044* tries a single format: &drm_connector.display_info.bus_formats[0] if1045* available, MEDIA_BUS_FMT_FIXED otherwise.1046*1047* When &drm_bridge_funcs.atomic_get_input_bus_fmts() is not implemented,1048* &drm_atomic_bridge_chain_select_bus_fmts() skips the negotiation on the1049* bridge element that lacks this hook and asks the previous element in the1050* chain to try MEDIA_BUS_FMT_FIXED. It's up to bridge drivers to decide what1051* to do in that case (fail if they want to enforce bus format negotiation, or1052* provide a reasonable default if they need to support pipelines where not1053* all elements support bus format negotiation).1054*/1055static int1056drm_atomic_bridge_chain_select_bus_fmts(struct drm_bridge *bridge,1057struct drm_crtc_state *crtc_state,1058struct drm_connector_state *conn_state)1059{1060struct drm_connector *conn = conn_state->connector;1061struct drm_encoder *encoder = bridge->encoder;1062struct drm_bridge_state *last_bridge_state;1063unsigned int i, num_out_bus_fmts = 0;1064struct drm_bridge *last_bridge;1065u32 *out_bus_fmts;1066int ret = 0;10671068last_bridge = list_last_entry(&encoder->bridge_chain,1069struct drm_bridge, chain_node);1070last_bridge_state = drm_atomic_get_new_bridge_state(crtc_state->state,1071last_bridge);10721073if (last_bridge->funcs->atomic_get_output_bus_fmts) {1074const struct drm_bridge_funcs *funcs = last_bridge->funcs;10751076/*1077* If the driver implements ->atomic_get_output_bus_fmts() it1078* should also implement the atomic state hooks.1079*/1080if (WARN_ON(!last_bridge_state))1081return -EINVAL;10821083out_bus_fmts = funcs->atomic_get_output_bus_fmts(last_bridge,1084last_bridge_state,1085crtc_state,1086conn_state,1087&num_out_bus_fmts);1088if (!num_out_bus_fmts)1089return -ENOTSUPP;1090else if (!out_bus_fmts)1091return -ENOMEM;1092} else {1093num_out_bus_fmts = 1;1094out_bus_fmts = kmalloc(sizeof(*out_bus_fmts), GFP_KERNEL);1095if (!out_bus_fmts)1096return -ENOMEM;10971098if (conn->display_info.num_bus_formats &&1099conn->display_info.bus_formats)1100out_bus_fmts[0] = conn->display_info.bus_formats[0];1101else1102out_bus_fmts[0] = MEDIA_BUS_FMT_FIXED;1103}11041105for (i = 0; i < num_out_bus_fmts; i++) {1106ret = select_bus_fmt_recursive(bridge, last_bridge, crtc_state,1107conn_state, out_bus_fmts[i]);1108if (ret != -ENOTSUPP)1109break;1110}11111112kfree(out_bus_fmts);11131114return ret;1115}11161117static void1118drm_atomic_bridge_propagate_bus_flags(struct drm_bridge *bridge,1119struct drm_connector *conn,1120struct drm_atomic_state *state)1121{1122struct drm_bridge_state *bridge_state, *next_bridge_state;1123struct drm_bridge *next_bridge;1124u32 output_flags = 0;11251126bridge_state = drm_atomic_get_new_bridge_state(state, bridge);11271128/* No bridge state attached to this bridge => nothing to propagate. */1129if (!bridge_state)1130return;11311132next_bridge = drm_bridge_get_next_bridge(bridge);11331134/*1135* Let's try to apply the most common case here, that is, propagate1136* display_info flags for the last bridge, and propagate the input1137* flags of the next bridge element to the output end of the current1138* bridge when the bridge is not the last one.1139* There are exceptions to this rule, like when signal inversion is1140* happening at the board level, but that's something drivers can deal1141* with from their &drm_bridge_funcs.atomic_check() implementation by1142* simply overriding the flags value we've set here.1143*/1144if (!next_bridge) {1145output_flags = conn->display_info.bus_flags;1146} else {1147next_bridge_state = drm_atomic_get_new_bridge_state(state,1148next_bridge);1149/*1150* No bridge state attached to the next bridge, just leave the1151* flags to 0.1152*/1153if (next_bridge_state)1154output_flags = next_bridge_state->input_bus_cfg.flags;1155}11561157bridge_state->output_bus_cfg.flags = output_flags;11581159/*1160* Propagate the output flags to the input end of the bridge. Again, it's1161* not necessarily what all bridges want, but that's what most of them1162* do, and by doing that by default we avoid forcing drivers to1163* duplicate the "dummy propagation" logic.1164*/1165bridge_state->input_bus_cfg.flags = output_flags;1166}11671168/**1169* drm_atomic_bridge_chain_check() - Do an atomic check on the bridge chain1170* @bridge: bridge control structure1171* @crtc_state: new CRTC state1172* @conn_state: new connector state1173*1174* First trigger a bus format negotiation before calling1175* &drm_bridge_funcs.atomic_check() (falls back on1176* &drm_bridge_funcs.mode_fixup()) op for all the bridges in the encoder chain,1177* starting from the last bridge to the first. These are called before calling1178* &drm_encoder_helper_funcs.atomic_check()1179*1180* RETURNS:1181* 0 on success, a negative error code on failure1182*/1183int drm_atomic_bridge_chain_check(struct drm_bridge *bridge,1184struct drm_crtc_state *crtc_state,1185struct drm_connector_state *conn_state)1186{1187struct drm_connector *conn = conn_state->connector;1188struct drm_encoder *encoder;1189struct drm_bridge *iter;1190int ret;11911192if (!bridge)1193return 0;11941195ret = drm_atomic_bridge_chain_select_bus_fmts(bridge, crtc_state,1196conn_state);1197if (ret)1198return ret;11991200encoder = bridge->encoder;1201list_for_each_entry_reverse(iter, &encoder->bridge_chain, chain_node) {1202int ret;12031204/*1205* Bus flags are propagated by default. If a bridge needs to1206* tweak the input bus flags for any reason, it should happen1207* in its &drm_bridge_funcs.atomic_check() implementation such1208* that preceding bridges in the chain can propagate the new1209* bus flags.1210*/1211drm_atomic_bridge_propagate_bus_flags(iter, conn,1212crtc_state->state);12131214ret = drm_atomic_bridge_check(iter, crtc_state, conn_state);1215if (ret)1216return ret;12171218if (iter == bridge)1219break;1220}12211222return 0;1223}1224EXPORT_SYMBOL(drm_atomic_bridge_chain_check);12251226/**1227* drm_bridge_detect - check if anything is attached to the bridge output1228* @bridge: bridge control structure1229* @connector: attached connector1230*1231* If the bridge supports output detection, as reported by the1232* DRM_BRIDGE_OP_DETECT bridge ops flag, call &drm_bridge_funcs.detect for the1233* bridge and return the connection status. Otherwise return1234* connector_status_unknown.1235*1236* RETURNS:1237* The detection status on success, or connector_status_unknown if the bridge1238* doesn't support output detection.1239*/1240enum drm_connector_status1241drm_bridge_detect(struct drm_bridge *bridge, struct drm_connector *connector)1242{1243if (!(bridge->ops & DRM_BRIDGE_OP_DETECT))1244return connector_status_unknown;12451246return bridge->funcs->detect(bridge, connector);1247}1248EXPORT_SYMBOL_GPL(drm_bridge_detect);12491250/**1251* drm_bridge_get_modes - fill all modes currently valid for the sink into the1252* @connector1253* @bridge: bridge control structure1254* @connector: the connector to fill with modes1255*1256* If the bridge supports output modes retrieval, as reported by the1257* DRM_BRIDGE_OP_MODES bridge ops flag, call &drm_bridge_funcs.get_modes to1258* fill the connector with all valid modes and return the number of modes1259* added. Otherwise return 0.1260*1261* RETURNS:1262* The number of modes added to the connector.1263*/1264int drm_bridge_get_modes(struct drm_bridge *bridge,1265struct drm_connector *connector)1266{1267if (!(bridge->ops & DRM_BRIDGE_OP_MODES))1268return 0;12691270return bridge->funcs->get_modes(bridge, connector);1271}1272EXPORT_SYMBOL_GPL(drm_bridge_get_modes);12731274/**1275* drm_bridge_edid_read - read the EDID data of the connected display1276* @bridge: bridge control structure1277* @connector: the connector to read EDID for1278*1279* If the bridge supports output EDID retrieval, as reported by the1280* DRM_BRIDGE_OP_EDID bridge ops flag, call &drm_bridge_funcs.edid_read to get1281* the EDID and return it. Otherwise return NULL.1282*1283* RETURNS:1284* The retrieved EDID on success, or NULL otherwise.1285*/1286const struct drm_edid *drm_bridge_edid_read(struct drm_bridge *bridge,1287struct drm_connector *connector)1288{1289if (!(bridge->ops & DRM_BRIDGE_OP_EDID))1290return NULL;12911292return bridge->funcs->edid_read(bridge, connector);1293}1294EXPORT_SYMBOL_GPL(drm_bridge_edid_read);12951296/**1297* drm_bridge_hpd_enable - enable hot plug detection for the bridge1298* @bridge: bridge control structure1299* @cb: hot-plug detection callback1300* @data: data to be passed to the hot-plug detection callback1301*1302* Call &drm_bridge_funcs.hpd_enable if implemented and register the given @cb1303* and @data as hot plug notification callback. From now on the @cb will be1304* called with @data when an output status change is detected by the bridge,1305* until hot plug notification gets disabled with drm_bridge_hpd_disable().1306*1307* Hot plug detection is supported only if the DRM_BRIDGE_OP_HPD flag is set in1308* bridge->ops. This function shall not be called when the flag is not set.1309*1310* Only one hot plug detection callback can be registered at a time, it is an1311* error to call this function when hot plug detection is already enabled for1312* the bridge.1313*/1314void drm_bridge_hpd_enable(struct drm_bridge *bridge,1315void (*cb)(void *data,1316enum drm_connector_status status),1317void *data)1318{1319if (!(bridge->ops & DRM_BRIDGE_OP_HPD))1320return;13211322mutex_lock(&bridge->hpd_mutex);13231324if (WARN(bridge->hpd_cb, "Hot plug detection already enabled\n"))1325goto unlock;13261327bridge->hpd_cb = cb;1328bridge->hpd_data = data;13291330if (bridge->funcs->hpd_enable)1331bridge->funcs->hpd_enable(bridge);13321333unlock:1334mutex_unlock(&bridge->hpd_mutex);1335}1336EXPORT_SYMBOL_GPL(drm_bridge_hpd_enable);13371338/**1339* drm_bridge_hpd_disable - disable hot plug detection for the bridge1340* @bridge: bridge control structure1341*1342* Call &drm_bridge_funcs.hpd_disable if implemented and unregister the hot1343* plug detection callback previously registered with drm_bridge_hpd_enable().1344* Once this function returns the callback will not be called by the bridge1345* when an output status change occurs.1346*1347* Hot plug detection is supported only if the DRM_BRIDGE_OP_HPD flag is set in1348* bridge->ops. This function shall not be called when the flag is not set.1349*/1350void drm_bridge_hpd_disable(struct drm_bridge *bridge)1351{1352if (!(bridge->ops & DRM_BRIDGE_OP_HPD))1353return;13541355mutex_lock(&bridge->hpd_mutex);1356if (bridge->funcs->hpd_disable)1357bridge->funcs->hpd_disable(bridge);13581359bridge->hpd_cb = NULL;1360bridge->hpd_data = NULL;1361mutex_unlock(&bridge->hpd_mutex);1362}1363EXPORT_SYMBOL_GPL(drm_bridge_hpd_disable);13641365/**1366* drm_bridge_hpd_notify - notify hot plug detection events1367* @bridge: bridge control structure1368* @status: output connection status1369*1370* Bridge drivers shall call this function to report hot plug events when they1371* detect a change in the output status, when hot plug detection has been1372* enabled by drm_bridge_hpd_enable().1373*1374* This function shall be called in a context that can sleep.1375*/1376void drm_bridge_hpd_notify(struct drm_bridge *bridge,1377enum drm_connector_status status)1378{1379mutex_lock(&bridge->hpd_mutex);1380if (bridge->hpd_cb)1381bridge->hpd_cb(bridge->hpd_data, status);1382mutex_unlock(&bridge->hpd_mutex);1383}1384EXPORT_SYMBOL_GPL(drm_bridge_hpd_notify);13851386#ifdef CONFIG_OF1387/**1388* of_drm_find_bridge - find the bridge corresponding to the device node in1389* the global bridge list1390*1391* @np: device node1392*1393* RETURNS:1394* drm_bridge control struct on success, NULL on failure1395*/1396struct drm_bridge *of_drm_find_bridge(struct device_node *np)1397{1398struct drm_bridge *bridge;13991400mutex_lock(&bridge_lock);14011402list_for_each_entry(bridge, &bridge_list, list) {1403if (bridge->of_node == np) {1404mutex_unlock(&bridge_lock);1405return bridge;1406}1407}14081409mutex_unlock(&bridge_lock);1410return NULL;1411}1412EXPORT_SYMBOL(of_drm_find_bridge);1413#endif14141415/**1416* devm_drm_put_bridge - Release a bridge reference obtained via devm1417* @dev: device that got the bridge via devm1418* @bridge: pointer to a struct drm_bridge obtained via devm1419*1420* Same as drm_bridge_put() for bridge pointers obtained via devm functions1421* such as devm_drm_bridge_alloc().1422*1423* This function is a temporary workaround and MUST NOT be used. Manual1424* handling of bridge lifetime is inherently unsafe.1425*/1426void devm_drm_put_bridge(struct device *dev, struct drm_bridge *bridge)1427{1428devm_release_action(dev, drm_bridge_put_void, bridge);1429}1430EXPORT_SYMBOL(devm_drm_put_bridge);14311432static void drm_bridge_debugfs_show_bridge(struct drm_printer *p,1433struct drm_bridge *bridge,1434unsigned int idx)1435{1436drm_printf(p, "bridge[%u]: %ps\n", idx, bridge->funcs);1437drm_printf(p, "\ttype: [%d] %s\n",1438bridge->type,1439drm_get_connector_type_name(bridge->type));14401441if (bridge->of_node)1442drm_printf(p, "\tOF: %pOFfc\n", bridge->of_node);14431444drm_printf(p, "\tops: [0x%x]", bridge->ops);1445if (bridge->ops & DRM_BRIDGE_OP_DETECT)1446drm_puts(p, " detect");1447if (bridge->ops & DRM_BRIDGE_OP_EDID)1448drm_puts(p, " edid");1449if (bridge->ops & DRM_BRIDGE_OP_HPD)1450drm_puts(p, " hpd");1451if (bridge->ops & DRM_BRIDGE_OP_MODES)1452drm_puts(p, " modes");1453if (bridge->ops & DRM_BRIDGE_OP_HDMI)1454drm_puts(p, " hdmi");1455drm_puts(p, "\n");1456}14571458static int allbridges_show(struct seq_file *m, void *data)1459{1460struct drm_printer p = drm_seq_file_printer(m);1461struct drm_bridge *bridge;1462unsigned int idx = 0;14631464mutex_lock(&bridge_lock);14651466list_for_each_entry(bridge, &bridge_list, list)1467drm_bridge_debugfs_show_bridge(&p, bridge, idx++);14681469mutex_unlock(&bridge_lock);14701471return 0;1472}1473DEFINE_SHOW_ATTRIBUTE(allbridges);14741475static int encoder_bridges_show(struct seq_file *m, void *data)1476{1477struct drm_encoder *encoder = m->private;1478struct drm_printer p = drm_seq_file_printer(m);1479struct drm_bridge *bridge;1480unsigned int idx = 0;14811482drm_for_each_bridge_in_chain(encoder, bridge)1483drm_bridge_debugfs_show_bridge(&p, bridge, idx++);14841485return 0;1486}1487DEFINE_SHOW_ATTRIBUTE(encoder_bridges);14881489void drm_bridge_debugfs_params(struct dentry *root)1490{1491debugfs_create_file("bridges", 0444, root, NULL, &allbridges_fops);1492}14931494void drm_bridge_debugfs_encoder_params(struct dentry *root,1495struct drm_encoder *encoder)1496{1497/* bridges list */1498debugfs_create_file("bridges", 0444, root, encoder, &encoder_bridges_fops);1499}15001501MODULE_AUTHOR("Ajay Kumar <[email protected]>");1502MODULE_DESCRIPTION("DRM bridge infrastructure");1503MODULE_LICENSE("GPL and additional rights");150415051506