File Index
Files and directories
Sign in
FILE

drm_bridge.h

File preview with syntax highlighting.

linux-6.19.14/include/drm/drm_bridge.h C
   1/*
   2 * Copyright (c) 2016 Intel Corporation
   3 *
   4 * Permission to use, copy, modify, distribute, and sell this software and its
   5 * documentation for any purpose is hereby granted without fee, provided that
   6 * the above copyright notice appear in all copies and that both that copyright
   7 * notice and this permission notice appear in supporting documentation, and
   8 * that the name of the copyright holders not be used in advertising or
   9 * publicity pertaining to distribution of the software without specific,
  10 * written prior permission.  The copyright holders make no representations
  11 * about the suitability of this software for any purpose.  It is provided "as
  12 * is" without express or implied warranty.
  13 *
  14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  20 * OF THIS SOFTWARE.
  21 */
  22
  23#ifndef __DRM_BRIDGE_H__
  24#define __DRM_BRIDGE_H__
  25
  26#include <linux/cleanup.h>
  27#include <linux/ctype.h>
  28#include <linux/list.h>
  29#include <linux/mutex.h>
  30
  31#include <drm/drm_atomic.h>
  32#include <drm/drm_encoder.h>
  33#include <drm/drm_mode_object.h>
  34#include <drm/drm_modes.h>
  35
  36struct cec_msg;
  37struct device_node;
  38
  39struct drm_bridge;
  40struct drm_bridge_timings;
  41struct drm_connector;
  42struct drm_display_info;
  43struct drm_minor;
  44struct drm_panel;
  45struct edid;
  46struct hdmi_codec_daifmt;
  47struct hdmi_codec_params;
  48struct i2c_adapter;
  49
  50/**
  51 * enum drm_bridge_attach_flags - Flags for &drm_bridge_funcs.attach
  52 */
  53enum drm_bridge_attach_flags {
  54	/**
  55	 * @DRM_BRIDGE_ATTACH_NO_CONNECTOR: When this flag is set the bridge
  56	 * shall not create a drm_connector.
  57	 */
  58	DRM_BRIDGE_ATTACH_NO_CONNECTOR = BIT(0),
  59};
  60
  61/**
  62 * struct drm_bridge_funcs - drm_bridge control functions
  63 */
  64struct drm_bridge_funcs {
  65	/**
  66	 * @attach:
  67	 *
  68	 * This callback is invoked whenever our bridge is being attached to a
  69	 * &drm_encoder. The flags argument tunes the behaviour of the attach
  70	 * operation (see DRM_BRIDGE_ATTACH_*).
  71	 *
  72	 * The @attach callback is optional.
  73	 *
  74	 * RETURNS:
  75	 *
  76	 * Zero on success, error code on failure.
  77	 */
  78	int (*attach)(struct drm_bridge *bridge, struct drm_encoder *encoder,
  79		      enum drm_bridge_attach_flags flags);
  80
  81	/**
  82	 * @destroy:
  83	 *
  84	 * This callback is invoked when the bridge is about to be
  85	 * deallocated.
  86	 *
  87	 * The @destroy callback is optional.
  88	 */
  89	void (*destroy)(struct drm_bridge *bridge);
  90
  91	/**
  92	 * @detach:
  93	 *
  94	 * This callback is invoked whenever our bridge is being detached from a
  95	 * &drm_encoder.
  96	 *
  97	 * The @detach callback is optional.
  98	 */
  99	void (*detach)(struct drm_bridge *bridge);
 100
 101	/**
 102	 * @mode_valid:
 103	 *
 104	 * This callback is used to check if a specific mode is valid in this
 105	 * bridge. This should be implemented if the bridge has some sort of
 106	 * restriction in the modes it can display. For example, a given bridge
 107	 * may be responsible to set a clock value. If the clock can not
 108	 * produce all the values for the available modes then this callback
 109	 * can be used to restrict the number of modes to only the ones that
 110	 * can be displayed.
 111	 *
 112	 * This hook is used by the probe helpers to filter the mode list in
 113	 * drm_helper_probe_single_connector_modes(), and it is used by the
 114	 * atomic helpers to validate modes supplied by userspace in
 115	 * drm_atomic_helper_check_modeset().
 116	 *
 117	 * The @mode_valid callback is optional.
 118	 *
 119	 * NOTE:
 120	 *
 121	 * Since this function is both called from the check phase of an atomic
 122	 * commit, and the mode validation in the probe paths it is not allowed
 123	 * to look at anything else but the passed-in mode, and validate it
 124	 * against configuration-invariant hardware constraints. Any further
 125	 * limits which depend upon the configuration can only be checked in
 126	 * @mode_fixup.
 127	 *
 128	 * RETURNS:
 129	 *
 130	 * drm_mode_status Enum
 131	 */
 132	enum drm_mode_status (*mode_valid)(struct drm_bridge *bridge,
 133					   const struct drm_display_info *info,
 134					   const struct drm_display_mode *mode);
 135
 136	/**
 137	 * @mode_fixup:
 138	 *
 139	 * This callback is used to validate and adjust a mode. The parameter
 140	 * mode is the display mode that should be fed to the next element in
 141	 * the display chain, either the final &drm_connector or the next
 142	 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
 143	 * requires. It can be modified by this callback and does not need to
 144	 * match mode. See also &drm_crtc_state.adjusted_mode for more details.
 145	 *
 146	 * This is the only hook that allows a bridge to reject a modeset. If
 147	 * this function passes all other callbacks must succeed for this
 148	 * configuration.
 149	 *
 150	 * The mode_fixup callback is optional. &drm_bridge_funcs.mode_fixup()
 151	 * is not called when &drm_bridge_funcs.atomic_check() is implemented,
 152	 * so only one of them should be provided.
 153	 *
 154	 * NOTE:
 155	 *
 156	 * This function is called in the check phase of atomic modesets, which
 157	 * can be aborted for any reason (including on userspace's request to
 158	 * just check whether a configuration would be possible). Drivers MUST
 159	 * NOT touch any persistent state (hardware or software) or data
 160	 * structures except the passed in @state parameter.
 161	 *
 162	 * Also beware that userspace can request its own custom modes, neither
 163	 * core nor helpers filter modes to the list of probe modes reported by
 164	 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
 165	 * that modes are filtered consistently put any bridge constraints and
 166	 * limits checks into @mode_valid.
 167	 *
 168	 * RETURNS:
 169	 *
 170	 * True if an acceptable configuration is possible, false if the modeset
 171	 * operation should be rejected.
 172	 */
 173	bool (*mode_fixup)(struct drm_bridge *bridge,
 174			   const struct drm_display_mode *mode,
 175			   struct drm_display_mode *adjusted_mode);
 176	/**
 177	 * @disable:
 178	 *
 179	 * This callback should disable the bridge. It is called right before
 180	 * the preceding element in the display pipe is disabled. If the
 181	 * preceding element is a bridge this means it's called before that
 182	 * bridge's @disable vfunc. If the preceding element is a &drm_encoder
 183	 * it's called right before the &drm_encoder_helper_funcs.disable,
 184	 * &drm_encoder_helper_funcs.prepare or &drm_encoder_helper_funcs.dpms
 185	 * hook.
 186	 *
 187	 * The bridge can assume that the display pipe (i.e. clocks and timing
 188	 * signals) feeding it is still running when this callback is called.
 189	 *
 190	 * The @disable callback is optional.
 191	 *
 192	 * NOTE:
 193	 *
 194	 * This is deprecated, do not use!
 195	 * New drivers shall use &drm_bridge_funcs.atomic_disable.
 196	 */
 197	void (*disable)(struct drm_bridge *bridge);
 198
 199	/**
 200	 * @post_disable:
 201	 *
 202	 * This callback should disable the bridge. It is called right after the
 203	 * preceding element in the display pipe is disabled. If the preceding
 204	 * element is a bridge this means it's called after that bridge's
 205	 * @post_disable function. If the preceding element is a &drm_encoder
 206	 * it's called right after the encoder's
 207	 * &drm_encoder_helper_funcs.disable, &drm_encoder_helper_funcs.prepare
 208	 * or &drm_encoder_helper_funcs.dpms hook.
 209	 *
 210	 * The bridge must assume that the display pipe (i.e. clocks and timing
 211	 * signals) feeding it is no longer running when this callback is
 212	 * called.
 213	 *
 214	 * The @post_disable callback is optional.
 215	 *
 216	 * NOTE:
 217	 *
 218	 * This is deprecated, do not use!
 219	 * New drivers shall use &drm_bridge_funcs.atomic_post_disable.
 220	 */
 221	void (*post_disable)(struct drm_bridge *bridge);
 222
 223	/**
 224	 * @mode_set:
 225	 *
 226	 * This callback should set the given mode on the bridge. It is called
 227	 * after the @mode_set callback for the preceding element in the display
 228	 * pipeline has been called already. If the bridge is the first element
 229	 * then this would be &drm_encoder_helper_funcs.mode_set. The display
 230	 * pipe (i.e.  clocks and timing signals) is off when this function is
 231	 * called.
 232	 *
 233	 * The adjusted_mode parameter is the mode output by the CRTC for the
 234	 * first bridge in the chain. It can be different from the mode
 235	 * parameter that contains the desired mode for the connector at the end
 236	 * of the bridges chain, for instance when the first bridge in the chain
 237	 * performs scaling. The adjusted mode is mostly useful for the first
 238	 * bridge in the chain and is likely irrelevant for the other bridges.
 239	 *
 240	 * For atomic drivers the adjusted_mode is the mode stored in
 241	 * &drm_crtc_state.adjusted_mode.
 242	 *
 243	 * NOTE:
 244	 *
 245	 * This is deprecated, do not use!
 246	 * New drivers shall set their mode in the
 247	 * &drm_bridge_funcs.atomic_enable operation.
 248	 */
 249	void (*mode_set)(struct drm_bridge *bridge,
 250			 const struct drm_display_mode *mode,
 251			 const struct drm_display_mode *adjusted_mode);
 252	/**
 253	 * @pre_enable:
 254	 *
 255	 * This callback should enable the bridge. It is called right before
 256	 * the preceding element in the display pipe is enabled. If the
 257	 * preceding element is a bridge this means it's called before that
 258	 * bridge's @pre_enable function. If the preceding element is a
 259	 * &drm_encoder it's called right before the encoder's
 260	 * &drm_encoder_helper_funcs.enable, &drm_encoder_helper_funcs.commit or
 261	 * &drm_encoder_helper_funcs.dpms hook.
 262	 *
 263	 * The display pipe (i.e. clocks and timing signals) feeding this bridge
 264	 * will not yet be running when this callback is called. The bridge must
 265	 * not enable the display link feeding the next bridge in the chain (if
 266	 * there is one) when this callback is called.
 267	 *
 268	 * The @pre_enable callback is optional.
 269	 *
 270	 * NOTE:
 271	 *
 272	 * This is deprecated, do not use!
 273	 * New drivers shall use &drm_bridge_funcs.atomic_pre_enable.
 274	 */
 275	void (*pre_enable)(struct drm_bridge *bridge);
 276
 277	/**
 278	 * @enable:
 279	 *
 280	 * This callback should enable the bridge. It is called right after
 281	 * the preceding element in the display pipe is enabled. If the
 282	 * preceding element is a bridge this means it's called after that
 283	 * bridge's @enable function. If the preceding element is a
 284	 * &drm_encoder it's called right after the encoder's
 285	 * &drm_encoder_helper_funcs.enable, &drm_encoder_helper_funcs.commit or
 286	 * &drm_encoder_helper_funcs.dpms hook.
 287	 *
 288	 * The bridge can assume that the display pipe (i.e. clocks and timing
 289	 * signals) feeding it is running when this callback is called. This
 290	 * callback must enable the display link feeding the next bridge in the
 291	 * chain if there is one.
 292	 *
 293	 * The @enable callback is optional.
 294	 *
 295	 * NOTE:
 296	 *
 297	 * This is deprecated, do not use!
 298	 * New drivers shall use &drm_bridge_funcs.atomic_enable.
 299	 */
 300	void (*enable)(struct drm_bridge *bridge);
 301
 302	/**
 303	 * @atomic_pre_enable:
 304	 *
 305	 * This callback should enable the bridge. It is called right before
 306	 * the preceding element in the display pipe is enabled. If the
 307	 * preceding element is a bridge this means it's called before that
 308	 * bridge's @atomic_pre_enable or @pre_enable function. If the preceding
 309	 * element is a &drm_encoder it's called right before the encoder's
 310	 * &drm_encoder_helper_funcs.atomic_enable hook.
 311	 *
 312	 * The display pipe (i.e. clocks and timing signals) feeding this bridge
 313	 * will not yet be running when this callback is called. The bridge must
 314	 * not enable the display link feeding the next bridge in the chain (if
 315	 * there is one) when this callback is called.
 316	 *
 317	 * The @atomic_pre_enable callback is optional.
 318	 */
 319	void (*atomic_pre_enable)(struct drm_bridge *bridge,
 320				  struct drm_atomic_state *state);
 321
 322	/**
 323	 * @atomic_enable:
 324	 *
 325	 * This callback should enable the bridge. It is called right after
 326	 * the preceding element in the display pipe is enabled. If the
 327	 * preceding element is a bridge this means it's called after that
 328	 * bridge's @atomic_enable or @enable function. If the preceding element
 329	 * is a &drm_encoder it's called right after the encoder's
 330	 * &drm_encoder_helper_funcs.atomic_enable hook.
 331	 *
 332	 * The bridge can assume that the display pipe (i.e. clocks and timing
 333	 * signals) feeding it is running when this callback is called. This
 334	 * callback must enable the display link feeding the next bridge in the
 335	 * chain if there is one.
 336	 *
 337	 * The @atomic_enable callback is optional.
 338	 */
 339	void (*atomic_enable)(struct drm_bridge *bridge,
 340			      struct drm_atomic_state *state);
 341	/**
 342	 * @atomic_disable:
 343	 *
 344	 * This callback should disable the bridge. It is called right before
 345	 * the preceding element in the display pipe is disabled. If the
 346	 * preceding element is a bridge this means it's called before that
 347	 * bridge's @atomic_disable or @disable vfunc. If the preceding element
 348	 * is a &drm_encoder it's called right before the
 349	 * &drm_encoder_helper_funcs.atomic_disable hook.
 350	 *
 351	 * The bridge can assume that the display pipe (i.e. clocks and timing
 352	 * signals) feeding it is still running when this callback is called.
 353	 *
 354	 * The @atomic_disable callback is optional.
 355	 */
 356	void (*atomic_disable)(struct drm_bridge *bridge,
 357			       struct drm_atomic_state *state);
 358
 359	/**
 360	 * @atomic_post_disable:
 361	 *
 362	 * This callback should disable the bridge. It is called right after the
 363	 * preceding element in the display pipe is disabled. If the preceding
 364	 * element is a bridge this means it's called after that bridge's
 365	 * @atomic_post_disable or @post_disable function. If the preceding
 366	 * element is a &drm_encoder it's called right after the encoder's
 367	 * &drm_encoder_helper_funcs.atomic_disable hook.
 368	 *
 369	 * The bridge must assume that the display pipe (i.e. clocks and timing
 370	 * signals) feeding it is no longer running when this callback is
 371	 * called.
 372	 *
 373	 * The @atomic_post_disable callback is optional.
 374	 */
 375	void (*atomic_post_disable)(struct drm_bridge *bridge,
 376				    struct drm_atomic_state *state);
 377
 378	/**
 379	 * @atomic_duplicate_state:
 380	 *
 381	 * Duplicate the current bridge state object (which is guaranteed to be
 382	 * non-NULL).
 383	 *
 384	 * The atomic_duplicate_state hook is mandatory if the bridge
 385	 * implements any of the atomic hooks, and should be left unassigned
 386	 * otherwise. For bridges that don't subclass &drm_bridge_state, the
 387	 * drm_atomic_helper_bridge_duplicate_state() helper function shall be
 388	 * used to implement this hook.
 389	 *
 390	 * RETURNS:
 391	 * A valid drm_bridge_state object or NULL if the allocation fails.
 392	 */
 393	struct drm_bridge_state *(*atomic_duplicate_state)(struct drm_bridge *bridge);
 394
 395	/**
 396	 * @atomic_destroy_state:
 397	 *
 398	 * Destroy a bridge state object previously allocated by
 399	 * &drm_bridge_funcs.atomic_duplicate_state().
 400	 *
 401	 * The atomic_destroy_state hook is mandatory if the bridge implements
 402	 * any of the atomic hooks, and should be left unassigned otherwise.
 403	 * For bridges that don't subclass &drm_bridge_state, the
 404	 * drm_atomic_helper_bridge_destroy_state() helper function shall be
 405	 * used to implement this hook.
 406	 */
 407	void (*atomic_destroy_state)(struct drm_bridge *bridge,
 408				     struct drm_bridge_state *state);
 409
 410	/**
 411	 * @atomic_get_output_bus_fmts:
 412	 *
 413	 * Return the supported bus formats on the output end of a bridge.
 414	 * The returned array must be allocated with kmalloc() and will be
 415	 * freed by the caller. If the allocation fails, NULL should be
 416	 * returned. num_output_fmts must be set to the returned array size.
 417	 * Formats listed in the returned array should be listed in decreasing
 418	 * preference order (the core will try all formats until it finds one
 419	 * that works).
 420	 *
 421	 * This method is only called on the last element of the bridge chain
 422	 * as part of the bus format negotiation process that happens in
 423	 * &drm_atomic_bridge_chain_select_bus_fmts().
 424	 * This method is optional. When not implemented, the core will
 425	 * fall back to &drm_connector.display_info.bus_formats[0] if
 426	 * &drm_connector.display_info.num_bus_formats > 0,
 427	 * or to MEDIA_BUS_FMT_FIXED otherwise.
 428	 */
 429	u32 *(*atomic_get_output_bus_fmts)(struct drm_bridge *bridge,
 430					   struct drm_bridge_state *bridge_state,
 431					   struct drm_crtc_state *crtc_state,
 432					   struct drm_connector_state *conn_state,
 433					   unsigned int *num_output_fmts);
 434
 435	/**
 436	 * @atomic_get_input_bus_fmts:
 437	 *
 438	 * Return the supported bus formats on the input end of a bridge for
 439	 * a specific output bus format.
 440	 *
 441	 * The returned array must be allocated with kmalloc() and will be
 442	 * freed by the caller. If the allocation fails, NULL should be
 443	 * returned. num_input_fmts must be set to the returned array size.
 444	 * Formats listed in the returned array should be listed in decreasing
 445	 * preference order (the core will try all formats until it finds one
 446	 * that works). When the format is not supported NULL should be
 447	 * returned and num_input_fmts should be set to 0.
 448	 *
 449	 * This method is called on all elements of the bridge chain as part of
 450	 * the bus format negotiation process that happens in
 451	 * drm_atomic_bridge_chain_select_bus_fmts().
 452	 * This method is optional. When not implemented, the core will bypass
 453	 * bus format negotiation on this element of the bridge without
 454	 * failing, and the previous element in the chain will be passed
 455	 * MEDIA_BUS_FMT_FIXED as its output bus format.
 456	 *
 457	 * Bridge drivers that need to support being linked to bridges that are
 458	 * not supporting bus format negotiation should handle the
 459	 * output_fmt == MEDIA_BUS_FMT_FIXED case appropriately, by selecting a
 460	 * sensible default value or extracting this information from somewhere
 461	 * else (FW property, &drm_display_mode, &drm_display_info, ...)
 462	 *
 463	 * Note: Even if input format selection on the first bridge has no
 464	 * impact on the negotiation process (bus format negotiation stops once
 465	 * we reach the first element of the chain), drivers are expected to
 466	 * return accurate input formats as the input format may be used to
 467	 * configure the CRTC output appropriately.
 468	 */
 469	u32 *(*atomic_get_input_bus_fmts)(struct drm_bridge *bridge,
 470					  struct drm_bridge_state *bridge_state,
 471					  struct drm_crtc_state *crtc_state,
 472					  struct drm_connector_state *conn_state,
 473					  u32 output_fmt,
 474					  unsigned int *num_input_fmts);
 475
 476	/**
 477	 * @atomic_check:
 478	 *
 479	 * This method is responsible for checking bridge state correctness.
 480	 * It can also check the state of the surrounding components in chain
 481	 * to make sure the whole pipeline can work properly.
 482	 *
 483	 * &drm_bridge_funcs.atomic_check() hooks are called in reverse
 484	 * order (from the last to the first bridge).
 485	 *
 486	 * This method is optional. &drm_bridge_funcs.mode_fixup() is not
 487	 * called when &drm_bridge_funcs.atomic_check() is implemented, so only
 488	 * one of them should be provided.
 489	 *
 490	 * If drivers need to tweak &drm_bridge_state.input_bus_cfg.flags or
 491	 * &drm_bridge_state.output_bus_cfg.flags it should happen in
 492	 * this function. By default the &drm_bridge_state.output_bus_cfg.flags
 493	 * field is set to the next bridge
 494	 * &drm_bridge_state.input_bus_cfg.flags value or
 495	 * &drm_connector.display_info.bus_flags if the bridge is the last
 496	 * element in the chain.
 497	 *
 498	 * RETURNS:
 499	 * zero if the check passed, a negative error code otherwise.
 500	 */
 501	int (*atomic_check)(struct drm_bridge *bridge,
 502			    struct drm_bridge_state *bridge_state,
 503			    struct drm_crtc_state *crtc_state,
 504			    struct drm_connector_state *conn_state);
 505
 506	/**
 507	 * @atomic_reset:
 508	 *
 509	 * Reset the bridge to a predefined state (or retrieve its current
 510	 * state) and return a &drm_bridge_state object matching this state.
 511	 * This function is called at attach time.
 512	 *
 513	 * The atomic_reset hook is mandatory if the bridge implements any of
 514	 * the atomic hooks, and should be left unassigned otherwise. For
 515	 * bridges that don't subclass &drm_bridge_state, the
 516	 * drm_atomic_helper_bridge_reset() helper function shall be used to
 517	 * implement this hook.
 518	 *
 519	 * Note that the atomic_reset() semantics is not exactly matching the
 520	 * reset() semantics found on other components (connector, plane, ...).
 521	 *
 522	 * 1. The reset operation happens when the bridge is attached, not when
 523	 *    drm_mode_config_reset() is called
 524	 * 2. It's meant to be used exclusively on bridges that have been
 525	 *    converted to the ATOMIC API
 526	 *
 527	 * RETURNS:
 528	 * A valid drm_bridge_state object in case of success, an ERR_PTR()
 529	 * giving the reason of the failure otherwise.
 530	 */
 531	struct drm_bridge_state *(*atomic_reset)(struct drm_bridge *bridge);
 532
 533	/**
 534	 * @detect:
 535	 *
 536	 * Check if anything is attached to the bridge output.
 537	 *
 538	 * This callback is optional, if not implemented the bridge will be
 539	 * considered as always having a component attached to its output.
 540	 * Bridges that implement this callback shall set the
 541	 * DRM_BRIDGE_OP_DETECT flag in their &drm_bridge->ops.
 542	 *
 543	 * RETURNS:
 544	 *
 545	 * drm_connector_status indicating the bridge output status.
 546	 */
 547	enum drm_connector_status (*detect)(struct drm_bridge *bridge,
 548					    struct drm_connector *connector);
 549
 550	/**
 551	 * @get_modes:
 552	 *
 553	 * Fill all modes currently valid for the sink into the &drm_connector
 554	 * with drm_mode_probed_add().
 555	 *
 556	 * The @get_modes callback is mostly intended to support non-probeable
 557	 * displays such as many fixed panels. Bridges that support reading
 558	 * EDID shall leave @get_modes unimplemented and implement the
 559	 * &drm_bridge_funcs->edid_read callback instead.
 560	 *
 561	 * This callback is optional. Bridges that implement it shall set the
 562	 * DRM_BRIDGE_OP_MODES flag in their &drm_bridge->ops.
 563	 *
 564	 * The connector parameter shall be used for the sole purpose of
 565	 * filling modes, and shall not be stored internally by bridge drivers
 566	 * for future usage.
 567	 *
 568	 * RETURNS:
 569	 *
 570	 * The number of modes added by calling drm_mode_probed_add().
 571	 */
 572	int (*get_modes)(struct drm_bridge *bridge,
 573			 struct drm_connector *connector);
 574
 575	/**
 576	 * @edid_read:
 577	 *
 578	 * Read the EDID data of the connected display.
 579	 *
 580	 * The @edid_read callback is the preferred way of reporting mode
 581	 * information for a display connected to the bridge output. Bridges
 582	 * that support reading EDID shall implement this callback and leave
 583	 * the @get_modes callback unimplemented.
 584	 *
 585	 * The caller of this operation shall first verify the output
 586	 * connection status and refrain from reading EDID from a disconnected
 587	 * output.
 588	 *
 589	 * This callback is optional. Bridges that implement it shall set the
 590	 * DRM_BRIDGE_OP_EDID flag in their &drm_bridge->ops.
 591	 *
 592	 * The connector parameter shall be used for the sole purpose of EDID
 593	 * retrieval, and shall not be stored internally by bridge drivers for
 594	 * future usage.
 595	 *
 596	 * RETURNS:
 597	 *
 598	 * An edid structure newly allocated with drm_edid_alloc() or returned
 599	 * from drm_edid_read() family of functions on success, or NULL
 600	 * otherwise. The caller is responsible for freeing the returned edid
 601	 * structure with drm_edid_free().
 602	 */
 603	const struct drm_edid *(*edid_read)(struct drm_bridge *bridge,
 604					    struct drm_connector *connector);
 605
 606	/**
 607	 * @hpd_notify:
 608	 *
 609	 * Notify the bridge of hot plug detection.
 610	 *
 611	 * This callback is optional, it may be implemented by bridges that
 612	 * need to be notified of display connection or disconnection for
 613	 * internal reasons. One use case is to reset the internal state of CEC
 614	 * controllers for HDMI bridges.
 615	 */
 616	void (*hpd_notify)(struct drm_bridge *bridge,
 617			   enum drm_connector_status status);
 618
 619	/**
 620	 * @hpd_enable:
 621	 *
 622	 * Enable hot plug detection. From now on the bridge shall call
 623	 * drm_bridge_hpd_notify() each time a change is detected in the output
 624	 * connection status, until hot plug detection gets disabled with
 625	 * @hpd_disable.
 626	 *
 627	 * This callback is optional and shall only be implemented by bridges
 628	 * that support hot-plug notification without polling. Bridges that
 629	 * implement it shall also implement the @hpd_disable callback and set
 630	 * the DRM_BRIDGE_OP_HPD flag in their &drm_bridge->ops.
 631	 */
 632	void (*hpd_enable)(struct drm_bridge *bridge);
 633
 634	/**
 635	 * @hpd_disable:
 636	 *
 637	 * Disable hot plug detection. Once this function returns the bridge
 638	 * shall not call drm_bridge_hpd_notify() when a change in the output
 639	 * connection status occurs.
 640	 *
 641	 * This callback is optional and shall only be implemented by bridges
 642	 * that support hot-plug notification without polling. Bridges that
 643	 * implement it shall also implement the @hpd_enable callback and set
 644	 * the DRM_BRIDGE_OP_HPD flag in their &drm_bridge->ops.
 645	 */
 646	void (*hpd_disable)(struct drm_bridge *bridge);
 647
 648	/**
 649	 * @hdmi_tmds_char_rate_valid:
 650	 *
 651	 * Check whether a particular TMDS character rate is supported by the
 652	 * driver.
 653	 *
 654	 * This callback is optional and should only be implemented by the
 655	 * bridges that take part in the HDMI connector implementation. Bridges
 656	 * that implement it shall set the DRM_BRIDGE_OP_HDMI flag in their
 657	 * &drm_bridge->ops.
 658	 *
 659	 * Returns:
 660	 *
 661	 * Either &drm_mode_status.MODE_OK or one of the failure reasons
 662	 * in &enum drm_mode_status.
 663	 */
 664	enum drm_mode_status
 665	(*hdmi_tmds_char_rate_valid)(const struct drm_bridge *bridge,
 666				     const struct drm_display_mode *mode,
 667				     unsigned long long tmds_rate);
 668
 669	/**
 670	 * @hdmi_clear_infoframe:
 671	 *
 672	 * This callback clears the infoframes in the hardware during commit.
 673	 * It will be called multiple times, once for every disabled infoframe
 674	 * type.
 675	 *
 676	 * This callback is optional but it must be implemented by bridges that
 677	 * set the DRM_BRIDGE_OP_HDMI flag in their &drm_bridge->ops.
 678	 */
 679	int (*hdmi_clear_infoframe)(struct drm_bridge *bridge,
 680				    enum hdmi_infoframe_type type);
 681	/**
 682	 * @hdmi_write_infoframe:
 683	 *
 684	 * Program the infoframe into the hardware. It will be called multiple
 685	 * times, once for every updated infoframe type.
 686	 *
 687	 * This callback is optional but it must be implemented by bridges that
 688	 * set the DRM_BRIDGE_OP_HDMI flag in their &drm_bridge->ops.
 689	 */
 690	int (*hdmi_write_infoframe)(struct drm_bridge *bridge,
 691				    enum hdmi_infoframe_type type,
 692				    const u8 *buffer, size_t len);
 693
 694	/**
 695	 * @hdmi_audio_startup:
 696	 *
 697	 * Called when ASoC starts an audio stream setup.
 698	 *
 699	 * This callback is optional, it can be implemented by bridges that
 700	 * set the @DRM_BRIDGE_OP_HDMI_AUDIO flag in their &drm_bridge->ops.
 701	 *
 702	 * Returns:
 703	 * 0 on success, a negative error code otherwise
 704	 */
 705	int (*hdmi_audio_startup)(struct drm_bridge *bridge,
 706				  struct drm_connector *connector);
 707
 708	/**
 709	 * @hdmi_audio_prepare:
 710	 * Configures HDMI-encoder for audio stream. Can be called multiple
 711	 * times for each setup.
 712	 *
 713	 * This callback is optional but it must be implemented by bridges that
 714	 * set the @DRM_BRIDGE_OP_HDMI_AUDIO flag in their &drm_bridge->ops.
 715	 *
 716	 * Returns:
 717	 * 0 on success, a negative error code otherwise
 718	 */
 719	int (*hdmi_audio_prepare)(struct drm_bridge *bridge,
 720				  struct drm_connector *connector,
 721				  struct hdmi_codec_daifmt *fmt,
 722				  struct hdmi_codec_params *hparms);
 723
 724	/**
 725	 * @hdmi_audio_shutdown:
 726	 *
 727	 * Shut down the audio stream.
 728	 *
 729	 * This callback is optional but it must be implemented by bridges that
 730	 * set the @DRM_BRIDGE_OP_HDMI_AUDIO flag in their &drm_bridge->ops.
 731	 *
 732	 * Returns:
 733	 * 0 on success, a negative error code otherwise
 734	 */
 735	void (*hdmi_audio_shutdown)(struct drm_bridge *bridge,
 736				    struct drm_connector *connector);
 737
 738	/**
 739	 * @hdmi_audio_mute_stream:
 740	 *
 741	 * Mute/unmute HDMI audio stream.
 742	 *
 743	 * This callback is optional, it can be implemented by bridges that
 744	 * set the @DRM_BRIDGE_OP_HDMI_AUDIO flag in their &drm_bridge->ops.
 745	 *
 746	 * Returns:
 747	 * 0 on success, a negative error code otherwise
 748	 */
 749	int (*hdmi_audio_mute_stream)(struct drm_bridge *bridge,
 750				      struct drm_connector *connector,
 751				      bool enable, int direction);
 752
 753	/**
 754	 * @hdmi_cec_init:
 755	 *
 756	 * Initialize CEC part of the bridge.
 757	 *
 758	 * This callback is optional, it can be implemented by bridges that
 759	 * set the @DRM_BRIDGE_OP_HDMI_CEC_ADAPTER flag in their
 760	 * &drm_bridge->ops.
 761	 *
 762	 * Returns:
 763	 * 0 on success, a negative error code otherwise
 764	 */
 765	int (*hdmi_cec_init)(struct drm_bridge *bridge,
 766			     struct drm_connector *connector);
 767
 768	/**
 769	 * @hdmi_cec_enable:
 770	 *
 771	 * Enable or disable the CEC adapter inside the bridge.
 772	 *
 773	 * This callback is optional, it can be implemented by bridges that
 774	 * set the @DRM_BRIDGE_OP_HDMI_CEC_ADAPTER flag in their
 775	 * &drm_bridge->ops.
 776	 *
 777	 * Returns:
 778	 * 0 on success, a negative error code otherwise
 779	 */
 780	int (*hdmi_cec_enable)(struct drm_bridge *bridge, bool enable);
 781
 782	/**
 783	 * @hdmi_cec_log_addr:
 784	 *
 785	 * Set the logical address of the CEC adapter inside the bridge.
 786	 *
 787	 * This callback is optional, it can be implemented by bridges that
 788	 * set the @DRM_BRIDGE_OP_HDMI_CEC_ADAPTER flag in their
 789	 * &drm_bridge->ops.
 790	 *
 791	 * Returns:
 792	 * 0 on success, a negative error code otherwise
 793	 */
 794	int (*hdmi_cec_log_addr)(struct drm_bridge *bridge, u8 logical_addr);
 795
 796	/**
 797	 * @hdmi_cec_transmit:
 798	 *
 799	 * Transmit the message using the CEC adapter inside the bridge.
 800	 *
 801	 * This callback is optional, it can be implemented by bridges that
 802	 * set the @DRM_BRIDGE_OP_HDMI_CEC_ADAPTER flag in their
 803	 * &drm_bridge->ops.
 804	 *
 805	 * Returns:
 806	 * 0 on success, a negative error code otherwise
 807	 */
 808	int (*hdmi_cec_transmit)(struct drm_bridge *bridge, u8 attempts,
 809				 u32 signal_free_time, struct cec_msg *msg);
 810
 811	/**
 812	 * @dp_audio_startup:
 813	 *
 814	 * Called when ASoC starts a DisplayPort audio stream setup.
 815	 *
 816	 * This callback is optional, it can be implemented by bridges that
 817	 * set the @DRM_BRIDGE_OP_DP_AUDIO flag in their &drm_bridge->ops.
 818	 *
 819	 * Returns:
 820	 * 0 on success, a negative error code otherwise
 821	 */
 822	int (*dp_audio_startup)(struct drm_bridge *bridge,
 823				struct drm_connector *connector);
 824
 825	/**
 826	 * @dp_audio_prepare:
 827	 * Configures DisplayPort audio stream. Can be called multiple
 828	 * times for each setup.
 829	 *
 830	 * This callback is optional but it must be implemented by bridges that
 831	 * set the @DRM_BRIDGE_OP_DP_AUDIO flag in their &drm_bridge->ops.
 832	 *
 833	 * Returns:
 834	 * 0 on success, a negative error code otherwise
 835	 */
 836	int (*dp_audio_prepare)(struct drm_bridge *bridge,
 837				struct drm_connector *connector,
 838				struct hdmi_codec_daifmt *fmt,
 839				struct hdmi_codec_params *hparms);
 840
 841	/**
 842	 * @dp_audio_shutdown:
 843	 *
 844	 * Shut down the DisplayPort audio stream.
 845	 *
 846	 * This callback is optional but it must be implemented by bridges that
 847	 * set the @DRM_BRIDGE_OP_DP_AUDIO flag in their &drm_bridge->ops.
 848	 *
 849	 * Returns:
 850	 * 0 on success, a negative error code otherwise
 851	 */
 852	void (*dp_audio_shutdown)(struct drm_bridge *bridge,
 853				  struct drm_connector *connector);
 854
 855	/**
 856	 * @dp_audio_mute_stream:
 857	 *
 858	 * Mute/unmute DisplayPort audio stream.
 859	 *
 860	 * This callback is optional, it can be implemented by bridges that
 861	 * set the @DRM_BRIDGE_OP_DP_AUDIO flag in their &drm_bridge->ops.
 862	 *
 863	 * Returns:
 864	 * 0 on success, a negative error code otherwise
 865	 */
 866	int (*dp_audio_mute_stream)(struct drm_bridge *bridge,
 867				    struct drm_connector *connector,
 868				    bool enable, int direction);
 869
 870	/**
 871	 * @debugfs_init:
 872	 *
 873	 * Allows bridges to create bridge-specific debugfs files.
 874	 */
 875	void (*debugfs_init)(struct drm_bridge *bridge, struct dentry *root);
 876};
 877
 878/**
 879 * struct drm_bridge_timings - timing information for the bridge
 880 */
 881struct drm_bridge_timings {
 882	/**
 883	 * @input_bus_flags:
 884	 *
 885	 * Tells what additional settings for the pixel data on the bus
 886	 * this bridge requires (like pixel signal polarity). See also
 887	 * &drm_display_info->bus_flags.
 888	 */
 889	u32 input_bus_flags;
 890	/**
 891	 * @setup_time_ps:
 892	 *
 893	 * Defines the time in picoseconds the input data lines must be
 894	 * stable before the clock edge.
 895	 */
 896	u32 setup_time_ps;
 897	/**
 898	 * @hold_time_ps:
 899	 *
 900	 * Defines the time in picoseconds taken for the bridge to sample the
 901	 * input signal after the clock edge.
 902	 */
 903	u32 hold_time_ps;
 904	/**
 905	 * @dual_link:
 906	 *
 907	 * True if the bus operates in dual-link mode. The exact meaning is
 908	 * dependent on the bus type. For LVDS buses, this indicates that even-
 909	 * and odd-numbered pixels are received on separate links.
 910	 */
 911	bool dual_link;
 912};
 913
 914/**
 915 * enum drm_bridge_ops - Bitmask of operations supported by the bridge
 916 */
 917enum drm_bridge_ops {
 918	/**
 919	 * @DRM_BRIDGE_OP_DETECT: The bridge can detect displays connected to
 920	 * its output. Bridges that set this flag shall implement the
 921	 * &drm_bridge_funcs->detect callback.
 922	 */
 923	DRM_BRIDGE_OP_DETECT = BIT(0),
 924	/**
 925	 * @DRM_BRIDGE_OP_EDID: The bridge can retrieve the EDID of the display
 926	 * connected to its output. Bridges that set this flag shall implement
 927	 * the &drm_bridge_funcs->edid_read callback.
 928	 */
 929	DRM_BRIDGE_OP_EDID = BIT(1),
 930	/**
 931	 * @DRM_BRIDGE_OP_HPD: The bridge can detect hot-plug and hot-unplug
 932	 * without requiring polling. Bridges that set this flag shall
 933	 * implement the &drm_bridge_funcs->hpd_enable and
 934	 * &drm_bridge_funcs->hpd_disable callbacks if they support enabling
 935	 * and disabling hot-plug detection dynamically.
 936	 */
 937	DRM_BRIDGE_OP_HPD = BIT(2),
 938	/**
 939	 * @DRM_BRIDGE_OP_MODES: The bridge can retrieve the modes supported
 940	 * by the display at its output. This does not include reading EDID
 941	 * which is separately covered by @DRM_BRIDGE_OP_EDID. Bridges that set
 942	 * this flag shall implement the &drm_bridge_funcs->get_modes callback.
 943	 */
 944	DRM_BRIDGE_OP_MODES = BIT(3),
 945	/**
 946	 * @DRM_BRIDGE_OP_HDMI: The bridge provides HDMI connector operations,
 947	 * including infoframes support. Bridges that set this flag must
 948	 * implement the &drm_bridge_funcs->write_infoframe callback.
 949	 *
 950	 * Note: currently there can be at most one bridge in a chain that sets
 951	 * this bit. This is to simplify corresponding glue code in connector
 952	 * drivers.
 953	 */
 954	DRM_BRIDGE_OP_HDMI = BIT(4),
 955	/**
 956	 * @DRM_BRIDGE_OP_HDMI_AUDIO: The bridge provides HDMI audio operations.
 957	 * Bridges that set this flag must implement the
 958	 * &drm_bridge_funcs->hdmi_audio_prepare and
 959	 * &drm_bridge_funcs->hdmi_audio_shutdown callbacks.
 960	 *
 961	 * Note: currently there can be at most one bridge in a chain that sets
 962	 * this bit. This is to simplify corresponding glue code in connector
 963	 * drivers. Also it is not possible to have a bridge in the chain that
 964	 * sets @DRM_BRIDGE_OP_DP_AUDIO if there is a bridge that sets this
 965	 * flag.
 966	 */
 967	DRM_BRIDGE_OP_HDMI_AUDIO = BIT(5),
 968	/**
 969	 * @DRM_BRIDGE_OP_DP_AUDIO: The bridge provides DisplayPort audio operations.
 970	 * Bridges that set this flag must implement the
 971	 * &drm_bridge_funcs->dp_audio_prepare and
 972	 * &drm_bridge_funcs->dp_audio_shutdown callbacks.
 973	 *
 974	 * Note: currently there can be at most one bridge in a chain that sets
 975	 * this bit. This is to simplify corresponding glue code in connector
 976	 * drivers. Also it is not possible to have a bridge in the chain that
 977	 * sets @DRM_BRIDGE_OP_HDMI_AUDIO if there is a bridge that sets this
 978	 * flag.
 979	 */
 980	DRM_BRIDGE_OP_DP_AUDIO = BIT(6),
 981	/**
 982	 * @DRM_BRIDGE_OP_HDMI_CEC_NOTIFIER: The bridge requires CEC notifier
 983	 * to be present.
 984	 */
 985	DRM_BRIDGE_OP_HDMI_CEC_NOTIFIER = BIT(7),
 986	/**
 987	 * @DRM_BRIDGE_OP_HDMI_CEC_ADAPTER: The bridge requires CEC adapter
 988	 * to be present.
 989	 */
 990	DRM_BRIDGE_OP_HDMI_CEC_ADAPTER = BIT(8),
 991};
 992
 993/**
 994 * struct drm_bridge - central DRM bridge control structure
 995 */
 996struct drm_bridge {
 997	/** @base: inherit from &drm_private_object */
 998	struct drm_private_obj base;
 999	/** @dev: DRM device this bridge belongs to */
1000	struct drm_device *dev;
1001	/** @encoder: encoder to which this bridge is connected */
1002	struct drm_encoder *encoder;
1003	/** @chain_node: used to form a bridge chain */
1004	struct list_head chain_node;
1005	/** @of_node: device node pointer to the bridge */
1006	struct device_node *of_node;
1007	/** @list: to keep track of all added bridges */
1008	struct list_head list;
1009	/**
1010	 * @timings:
1011	 *
1012	 * the timing specification for the bridge, if any (may be NULL)
1013	 */
1014	const struct drm_bridge_timings *timings;
1015	/** @funcs: control functions */
1016	const struct drm_bridge_funcs *funcs;
1017
1018	/**
1019	 * @container: Pointer to the private driver struct embedding this
1020	 * @struct drm_bridge.
1021	 */
1022	void *container;
1023
1024	/**
1025	 * @refcount: reference count of users referencing this bridge.
1026	 */
1027	struct kref refcount;
1028
1029	/** @driver_private: pointer to the bridge driver's internal context */
1030	void *driver_private;
1031	/** @ops: bitmask of operations supported by the bridge */
1032	enum drm_bridge_ops ops;
1033	/**
1034	 * @type: Type of the connection at the bridge output
1035	 * (DRM_MODE_CONNECTOR_*). For bridges at the end of this chain this
1036	 * identifies the type of connected display.
1037	 */
1038	int type;
1039	/**
1040	 * @interlace_allowed: Indicate that the bridge can handle interlaced
1041	 * modes.
1042	 */
1043	bool interlace_allowed;
1044	/**
1045	 * @ycbcr_420_allowed: Indicate that the bridge can handle YCbCr 420
1046	 * output.
1047	 */
1048	bool ycbcr_420_allowed;
1049	/**
1050	 * @pre_enable_prev_first: The bridge requires that the prev
1051	 * bridge @pre_enable function is called before its @pre_enable,
1052	 * and conversely for post_disable. This is most frequently a
1053	 * requirement for DSI devices which need the host to be initialised
1054	 * before the peripheral.
1055	 */
1056	bool pre_enable_prev_first;
1057	/**
1058	 * @support_hdcp: Indicate that the bridge supports HDCP.
1059	 */
1060	bool support_hdcp;
1061	/**
1062	 * @ddc: Associated I2C adapter for DDC access, if any.
1063	 */
1064	struct i2c_adapter *ddc;
1065
1066	/**
1067	 * @vendor: Vendor of the product to be used for the SPD InfoFrame
1068	 * generation. This is required if @DRM_BRIDGE_OP_HDMI is set.
1069	 */
1070	const char *vendor;
1071
1072	/**
1073	 * @product: Name of the product to be used for the SPD InfoFrame
1074	 * generation. This is required if @DRM_BRIDGE_OP_HDMI is set.
1075	 */
1076	const char *product;
1077
1078	/**
1079	 * @supported_formats: Bitmask of @hdmi_colorspace listing supported
1080	 * output formats. This is only relevant if @DRM_BRIDGE_OP_HDMI is set.
1081	 */
1082	unsigned int supported_formats;
1083
1084	/**
1085	 * @max_bpc: Maximum bits per char the HDMI bridge supports. Allowed
1086	 * values are 8, 10 and 12. This is only relevant if
1087	 * @DRM_BRIDGE_OP_HDMI is set.
1088	 */
1089	unsigned int max_bpc;
1090
1091	/**
1092	 * @hdmi_cec_dev: device to be used as a containing device for CEC
1093	 * functions.
1094	 */
1095	struct device *hdmi_cec_dev;
1096
1097	/**
1098	 * @hdmi_audio_dev: device to be used as a parent for the HDMI Codec if
1099	 * either of @DRM_BRIDGE_OP_HDMI_AUDIO or @DRM_BRIDGE_OP_DP_AUDIO is set.
1100	 */
1101	struct device *hdmi_audio_dev;
1102
1103	/**
1104	 * @hdmi_audio_max_i2s_playback_channels: maximum number of playback
1105	 * I2S channels for the @DRM_BRIDGE_OP_HDMI_AUDIO or
1106	 * @DRM_BRIDGE_OP_DP_AUDIO.
1107	 */
1108	int hdmi_audio_max_i2s_playback_channels;
1109
1110	/**
1111	 * @hdmi_audio_i2s_formats: supported I2S formats, optional. The
1112	 * default is to allow all formats supported by the corresponding I2S
1113	 * bus driver. This is only used for bridges setting
1114	 * @DRM_BRIDGE_OP_HDMI_AUDIO or @DRM_BRIDGE_OP_DP_AUDIO.
1115	 */
1116	u64 hdmi_audio_i2s_formats;
1117
1118	/**
1119	 * @hdmi_audio_spdif_playback: set if this bridge has S/PDIF playback
1120	 * port for @DRM_BRIDGE_OP_HDMI_AUDIO or @DRM_BRIDGE_OP_DP_AUDIO.
1121	 */
1122	unsigned int hdmi_audio_spdif_playback : 1;
1123
1124	/**
1125	 * @hdmi_audio_dai_port: sound DAI port for either of
1126	 * @DRM_BRIDGE_OP_HDMI_AUDIO and @DRM_BRIDGE_OP_DP_AUDIO, -1 if it is
1127	 * not used.
1128	 */
1129	int hdmi_audio_dai_port;
1130
1131	/**
1132	 * @hdmi_cec_adapter_name: the name of the adapter to register
1133	 */
1134	const char *hdmi_cec_adapter_name;
1135
1136	/**
1137	 * @hdmi_cec_available_las: number of logical addresses, CEC_MAX_LOG_ADDRS if unset
1138	 */
1139	u8 hdmi_cec_available_las;
1140
1141	/** private: */
1142	/**
1143	 * @hpd_mutex: Protects the @hpd_cb and @hpd_data fields.
1144	 */
1145	struct mutex hpd_mutex;
1146	/**
1147	 * @hpd_cb: Hot plug detection callback, registered with
1148	 * drm_bridge_hpd_enable().
1149	 */
1150	void (*hpd_cb)(void *data, enum drm_connector_status status);
1151	/**
1152	 * @hpd_data: Private data passed to the Hot plug detection callback
1153	 * @hpd_cb.
1154	 */
1155	void *hpd_data;
1156};
1157
1158static inline struct drm_bridge *
1159drm_priv_to_bridge(struct drm_private_obj *priv)
1160{
1161	return container_of(priv, struct drm_bridge, base);
1162}
1163
1164struct drm_bridge *drm_bridge_get(struct drm_bridge *bridge);
1165void drm_bridge_put(struct drm_bridge *bridge);
1166
1167/* Cleanup action for use with __free() */
1168DEFINE_FREE(drm_bridge_put, struct drm_bridge *, if (_T) drm_bridge_put(_T))
1169
1170void *__devm_drm_bridge_alloc(struct device *dev, size_t size, size_t offset,
1171			      const struct drm_bridge_funcs *funcs);
1172
1173/**
1174 * devm_drm_bridge_alloc - Allocate and initialize a bridge
1175 * @dev: struct device of the bridge device
1176 * @type: the type of the struct which contains struct &drm_bridge
1177 * @member: the name of the &drm_bridge within @type
1178 * @funcs: callbacks for this bridge
1179 *
1180 * The reference count of the returned bridge is initialized to 1. This
1181 * reference will be automatically dropped via devm (by calling
1182 * drm_bridge_put()) when @dev is removed.
1183 *
1184 * Returns:
1185 * Pointer to new bridge, or ERR_PTR on failure.
1186 */
1187#define devm_drm_bridge_alloc(dev, type, member, funcs) \
1188	((type *)__devm_drm_bridge_alloc(dev, sizeof(type), \
1189					 offsetof(type, member), funcs))
1190
1191void drm_bridge_add(struct drm_bridge *bridge);
1192int devm_drm_bridge_add(struct device *dev, struct drm_bridge *bridge);
1193void drm_bridge_remove(struct drm_bridge *bridge);
1194int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
1195		      struct drm_bridge *previous,
1196		      enum drm_bridge_attach_flags flags);
1197
1198#ifdef CONFIG_OF
1199struct drm_bridge *of_drm_find_bridge(struct device_node *np);
1200#else
1201static inline struct drm_bridge *of_drm_find_bridge(struct device_node *np)
1202{
1203	return NULL;
1204}
1205#endif
1206
1207static inline bool drm_bridge_is_last(struct drm_bridge *bridge)
1208{
1209	return list_is_last(&bridge->chain_node, &bridge->encoder->bridge_chain);
1210}
1211
1212/**
1213 * drm_bridge_get_current_state() - Get the current bridge state
1214 * @bridge: bridge object
1215 *
1216 * This function must be called with the modeset lock held.
1217 *
1218 * RETURNS:
1219 *
1220 * The current bridge state, or NULL if there is none.
1221 */
1222static inline struct drm_bridge_state *
1223drm_bridge_get_current_state(struct drm_bridge *bridge)
1224{
1225	if (!bridge)
1226		return NULL;
1227
1228	/*
1229	 * Only atomic bridges will have bridge->base initialized by
1230	 * drm_atomic_private_obj_init(), so we need to make sure we're
1231	 * working with one before we try to use the lock.
1232	 */
1233	if (!bridge->funcs || !bridge->funcs->atomic_reset)
1234		return NULL;
1235
1236	drm_modeset_lock_assert_held(&bridge->base.lock);
1237
1238	if (!bridge->base.state)
1239		return NULL;
1240
1241	return drm_priv_to_bridge_state(bridge->base.state);
1242}
1243
1244/**
1245 * drm_bridge_get_next_bridge() - Get the next bridge in the chain
1246 * @bridge: bridge object
1247 *
1248 * The caller is responsible of having a reference to @bridge via
1249 * drm_bridge_get() or equivalent. This function leaves the refcount of
1250 * @bridge unmodified.
1251 *
1252 * The refcount of the returned bridge is incremented. Use drm_bridge_put()
1253 * when done with it.
1254 *
1255 * RETURNS:
1256 * the next bridge in the chain after @bridge, or NULL if @bridge is the last.
1257 */
1258static inline struct drm_bridge *
1259drm_bridge_get_next_bridge(struct drm_bridge *bridge)
1260{
1261	if (list_is_last(&bridge->chain_node, &bridge->encoder->bridge_chain))
1262		return NULL;
1263
1264	return drm_bridge_get(list_next_entry(bridge, chain_node));
1265}
1266
1267/**
1268 * drm_bridge_get_prev_bridge() - Get the previous bridge in the chain
1269 * @bridge: bridge object
1270 *
1271 * The caller is responsible of having a reference to @bridge via
1272 * drm_bridge_get() or equivalent. This function leaves the refcount of
1273 * @bridge unmodified.
1274 *
1275 * The refcount of the returned bridge is incremented. Use drm_bridge_put()
1276 * when done with it.
1277 *
1278 * RETURNS:
1279 * the previous bridge in the chain, or NULL if @bridge is the first.
1280 */
1281static inline struct drm_bridge *
1282drm_bridge_get_prev_bridge(struct drm_bridge *bridge)
1283{
1284	if (list_is_first(&bridge->chain_node, &bridge->encoder->bridge_chain))
1285		return NULL;
1286
1287	return drm_bridge_get(list_prev_entry(bridge, chain_node));
1288}
1289
1290/**
1291 * drm_bridge_chain_get_first_bridge() - Get the first bridge in the chain
1292 * @encoder: encoder object
1293 *
1294 * The refcount of the returned bridge is incremented. Use drm_bridge_put()
1295 * when done with it.
1296 *
1297 * RETURNS:
1298 * the first bridge in the chain, or NULL if @encoder has no bridge attached
1299 * to it.
1300 */
1301static inline struct drm_bridge *
1302drm_bridge_chain_get_first_bridge(struct drm_encoder *encoder)
1303{
1304	return drm_bridge_get(list_first_entry_or_null(&encoder->bridge_chain,
1305						       struct drm_bridge, chain_node));
1306}
1307
1308/**
1309 * drm_bridge_chain_get_last_bridge() - Get the last bridge in the chain
1310 * @encoder: encoder object
1311 *
1312 * The refcount of the returned bridge is incremented. Use drm_bridge_put()
1313 * when done with it.
1314 *
1315 * RETURNS:
1316 * the last bridge in the chain, or NULL if @encoder has no bridge attached
1317 * to it.
1318 */
1319static inline struct drm_bridge *
1320drm_bridge_chain_get_last_bridge(struct drm_encoder *encoder)
1321{
1322	return drm_bridge_get(list_last_entry_or_null(&encoder->bridge_chain,
1323						      struct drm_bridge, chain_node));
1324}
1325
1326/**
1327 * drm_bridge_get_next_bridge_and_put - Get the next bridge in the chain
1328 *                                      and put the previous
1329 * @bridge: bridge object
1330 *
1331 * Same as drm_bridge_get_next_bridge() but additionally puts the @bridge.
1332 *
1333 * RETURNS:
1334 * the next bridge in the chain after @bridge, or NULL if @bridge is the last.
1335 */
1336static inline struct drm_bridge *
1337drm_bridge_get_next_bridge_and_put(struct drm_bridge *bridge)
1338{
1339	struct drm_bridge *next = drm_bridge_get_next_bridge(bridge);
1340
1341	drm_bridge_put(bridge);
1342
1343	return next;
1344}
1345
1346/**
1347 * drm_for_each_bridge_in_chain_scoped - iterate over all bridges attached
1348 *                                       to an encoder
1349 * @encoder: the encoder to iterate bridges on
1350 * @bridge: a bridge pointer updated to point to the current bridge at each
1351 *	    iteration
1352 *
1353 * Iterate over all bridges present in the bridge chain attached to @encoder.
1354 *
1355 * Automatically gets/puts the bridge reference while iterating, and puts
1356 * the reference even if returning or breaking in the middle of the loop.
1357 */
1358#define drm_for_each_bridge_in_chain_scoped(encoder, bridge)		\
1359	for (struct drm_bridge *bridge __free(drm_bridge_put) =		\
1360	     drm_bridge_chain_get_first_bridge(encoder);		\
1361	     bridge;							\
1362	     bridge = drm_bridge_get_next_bridge_and_put(bridge))
1363
1364/**
1365 * drm_for_each_bridge_in_chain_from - iterate over all bridges starting
1366 *                                     from the given bridge
1367 * @first_bridge: the bridge to start from
1368 * @bridge: a bridge pointer updated to point to the current bridge at each
1369 *	    iteration
1370 *
1371 * Iterate over all bridges in the encoder chain starting from
1372 * @first_bridge, included.
1373 *
1374 * Automatically gets/puts the bridge reference while iterating, and puts
1375 * the reference even if returning or breaking in the middle of the loop.
1376 */
1377#define drm_for_each_bridge_in_chain_from(first_bridge, bridge)		\
1378	for (struct drm_bridge *bridge __free(drm_bridge_put) =		\
1379		     drm_bridge_get(first_bridge);			\
1380	     bridge;							\
1381	     bridge = drm_bridge_get_next_bridge_and_put(bridge))
1382
1383enum drm_mode_status
1384drm_bridge_chain_mode_valid(struct drm_bridge *bridge,
1385			    const struct drm_display_info *info,
1386			    const struct drm_display_mode *mode);
1387void drm_bridge_chain_mode_set(struct drm_bridge *bridge,
1388			       const struct drm_display_mode *mode,
1389			       const struct drm_display_mode *adjusted_mode);
1390
1391int drm_atomic_bridge_chain_check(struct drm_bridge *bridge,
1392				  struct drm_crtc_state *crtc_state,
1393				  struct drm_connector_state *conn_state);
1394void drm_atomic_bridge_chain_disable(struct drm_bridge *bridge,
1395				     struct drm_atomic_state *state);
1396void drm_atomic_bridge_chain_post_disable(struct drm_bridge *bridge,
1397					  struct drm_atomic_state *state);
1398void drm_atomic_bridge_chain_pre_enable(struct drm_bridge *bridge,
1399					struct drm_atomic_state *state);
1400void drm_atomic_bridge_chain_enable(struct drm_bridge *bridge,
1401				    struct drm_atomic_state *state);
1402
1403u32 *
1404drm_atomic_helper_bridge_propagate_bus_fmt(struct drm_bridge *bridge,
1405					struct drm_bridge_state *bridge_state,
1406					struct drm_crtc_state *crtc_state,
1407					struct drm_connector_state *conn_state,
1408					u32 output_fmt,
1409					unsigned int *num_input_fmts);
1410
1411enum drm_connector_status
1412drm_bridge_detect(struct drm_bridge *bridge, struct drm_connector *connector);
1413int drm_bridge_get_modes(struct drm_bridge *bridge,
1414			 struct drm_connector *connector);
1415const struct drm_edid *drm_bridge_edid_read(struct drm_bridge *bridge,
1416					    struct drm_connector *connector);
1417void drm_bridge_hpd_enable(struct drm_bridge *bridge,
1418			   void (*cb)(void *data,
1419				      enum drm_connector_status status),
1420			   void *data);
1421void drm_bridge_hpd_disable(struct drm_bridge *bridge);
1422void drm_bridge_hpd_notify(struct drm_bridge *bridge,
1423			   enum drm_connector_status status);
1424
1425#ifdef CONFIG_DRM_PANEL_BRIDGE
1426bool drm_bridge_is_panel(const struct drm_bridge *bridge);
1427struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel);
1428struct drm_bridge *drm_panel_bridge_add_typed(struct drm_panel *panel,
1429					      u32 connector_type);
1430void drm_panel_bridge_remove(struct drm_bridge *bridge);
1431int drm_panel_bridge_set_orientation(struct drm_connector *connector,
1432				     struct drm_bridge *bridge);
1433struct drm_bridge *devm_drm_panel_bridge_add(struct device *dev,
1434					     struct drm_panel *panel);
1435struct drm_bridge *devm_drm_panel_bridge_add_typed(struct device *dev,
1436						   struct drm_panel *panel,
1437						   u32 connector_type);
1438struct drm_bridge *drmm_panel_bridge_add(struct drm_device *drm,
1439					     struct drm_panel *panel);
1440struct drm_connector *drm_panel_bridge_connector(struct drm_bridge *bridge);
1441#else
1442static inline bool drm_bridge_is_panel(const struct drm_bridge *bridge)
1443{
1444	return false;
1445}
1446
1447static inline int drm_panel_bridge_set_orientation(struct drm_connector *connector,
1448						   struct drm_bridge *bridge)
1449{
1450	return -EINVAL;
1451}
1452#endif
1453
1454#if defined(CONFIG_OF) && defined(CONFIG_DRM_PANEL_BRIDGE)
1455struct drm_bridge *devm_drm_of_get_bridge(struct device *dev, struct device_node *node,
1456					  u32 port, u32 endpoint);
1457struct drm_bridge *drmm_of_get_bridge(struct drm_device *drm, struct device_node *node,
1458					  u32 port, u32 endpoint);
1459#else
1460static inline struct drm_bridge *devm_drm_of_get_bridge(struct device *dev,
1461							struct device_node *node,
1462							u32 port,
1463							u32 endpoint)
1464{
1465	return ERR_PTR(-ENODEV);
1466}
1467
1468static inline struct drm_bridge *drmm_of_get_bridge(struct drm_device *drm,
1469						     struct device_node *node,
1470						     u32 port,
1471						     u32 endpoint)
1472{
1473	return ERR_PTR(-ENODEV);
1474}
1475#endif
1476
1477void devm_drm_put_bridge(struct device *dev, struct drm_bridge *bridge);
1478
1479void drm_bridge_debugfs_params(struct dentry *root);
1480void drm_bridge_debugfs_encoder_params(struct dentry *root, struct drm_encoder *encoder);
1481
1482#endif
~/ Read-only file preview.