forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/gpu/drm/drm_bridge.c
....@@ -25,6 +25,7 @@
2525 #include <linux/module.h>
2626 #include <linux/mutex.h>
2727
28
+#include <drm/drm_atomic_state_helper.h>
2829 #include <drm/drm_bridge.h>
2930 #include <drm/drm_encoder.h>
3031
....@@ -38,26 +39,56 @@
3839 * encoder chain.
3940 *
4041 * A bridge is always attached to a single &drm_encoder at a time, but can be
41
- * either connected to it directly, or through an intermediate bridge::
42
+ * either connected to it directly, or through a chain of bridges::
4243 *
43
- * encoder ---> bridge B ---> bridge A
44
+ * [ CRTC ---> ] Encoder ---> Bridge A ---> Bridge B
4445 *
45
- * Here, the output of the encoder feeds to bridge B, and that furthers feeds to
46
- * bridge A.
46
+ * Here, the output of the encoder feeds to bridge A, and that furthers feeds to
47
+ * bridge B. Bridge chains can be arbitrarily long, and shall be fully linear:
48
+ * Chaining multiple bridges to the output of a bridge, or the same bridge to
49
+ * the output of different bridges, is not supported.
4750 *
48
- * The driver using the bridge is responsible to make the associations between
49
- * the encoder and bridges. Once these links are made, the bridges will
50
- * participate along with encoder functions to perform mode_set/enable/disable
51
- * through the ops provided in &drm_bridge_funcs.
51
+ * Display drivers are responsible for linking encoders with the first bridge
52
+ * in the chains. This is done by acquiring the appropriate bridge with
53
+ * of_drm_find_bridge() or drm_of_find_panel_or_bridge(), or creating it for a
54
+ * panel with drm_panel_bridge_add_typed() (or the managed version
55
+ * devm_drm_panel_bridge_add_typed()). Once acquired, the bridge shall be
56
+ * attached to the encoder with a call to drm_bridge_attach().
5257 *
53
- * drm_bridge, like drm_panel, aren't drm_mode_object entities like planes,
58
+ * Bridges are responsible for linking themselves with the next bridge in the
59
+ * chain, if any. This is done the same way as for encoders, with the call to
60
+ * drm_bridge_attach() occurring in the &drm_bridge_funcs.attach operation.
61
+ *
62
+ * Once these links are created, the bridges can participate along with encoder
63
+ * functions to perform mode validation and fixup (through
64
+ * drm_bridge_chain_mode_valid() and drm_atomic_bridge_chain_check()), mode
65
+ * setting (through drm_bridge_chain_mode_set()), enable (through
66
+ * drm_atomic_bridge_chain_pre_enable() and drm_atomic_bridge_chain_enable())
67
+ * and disable (through drm_atomic_bridge_chain_disable() and
68
+ * drm_atomic_bridge_chain_post_disable()). Those functions call the
69
+ * corresponding operations provided in &drm_bridge_funcs in sequence for all
70
+ * bridges in the chain.
71
+ *
72
+ * For display drivers that use the atomic helpers
73
+ * drm_atomic_helper_check_modeset(),
74
+ * drm_atomic_helper_commit_modeset_enables() and
75
+ * drm_atomic_helper_commit_modeset_disables() (either directly in hand-rolled
76
+ * commit check and commit tail handlers, or through the higher-level
77
+ * drm_atomic_helper_check() and drm_atomic_helper_commit_tail() or
78
+ * drm_atomic_helper_commit_tail_rpm() helpers), this is done transparently and
79
+ * requires no intervention from the driver. For other drivers, the relevant
80
+ * DRM bridge chain functions shall be called manually.
81
+ *
82
+ * Bridges also participate in implementing the &drm_connector at the end of
83
+ * the bridge chain. Display drivers may use the drm_bridge_connector_init()
84
+ * helper to create the &drm_connector, or implement it manually on top of the
85
+ * connector-related operations exposed by the bridge (see the overview
86
+ * documentation of bridge operations for more details).
87
+ *
88
+ * &drm_bridge, like &drm_panel, aren't &drm_mode_object entities like planes,
5489 * CRTCs, encoders or connectors and hence are not visible to userspace. They
5590 * just provide additional hooks to get the desired output at the end of the
5691 * encoder chain.
57
- *
58
- * Bridges can also be chained up using the &drm_bridge.next pointer.
59
- *
60
- * Both legacy CRTC helpers and the new atomic modeset helpers support bridges.
6192 */
6293
6394 static DEFINE_MUTEX(bridge_lock);
....@@ -70,6 +101,8 @@
70101 */
71102 void drm_bridge_add(struct drm_bridge *bridge)
72103 {
104
+ mutex_init(&bridge->hpd_mutex);
105
+
73106 mutex_lock(&bridge_lock);
74107 list_add_tail(&bridge->list, &bridge_list);
75108 mutex_unlock(&bridge_lock);
....@@ -86,8 +119,35 @@
86119 mutex_lock(&bridge_lock);
87120 list_del_init(&bridge->list);
88121 mutex_unlock(&bridge_lock);
122
+
123
+ mutex_destroy(&bridge->hpd_mutex);
89124 }
90125 EXPORT_SYMBOL(drm_bridge_remove);
126
+
127
+static struct drm_private_state *
128
+drm_bridge_atomic_duplicate_priv_state(struct drm_private_obj *obj)
129
+{
130
+ struct drm_bridge *bridge = drm_priv_to_bridge(obj);
131
+ struct drm_bridge_state *state;
132
+
133
+ state = bridge->funcs->atomic_duplicate_state(bridge);
134
+ return state ? &state->base : NULL;
135
+}
136
+
137
+static void
138
+drm_bridge_atomic_destroy_priv_state(struct drm_private_obj *obj,
139
+ struct drm_private_state *s)
140
+{
141
+ struct drm_bridge_state *state = drm_priv_to_bridge_state(s);
142
+ struct drm_bridge *bridge = drm_priv_to_bridge(obj);
143
+
144
+ bridge->funcs->atomic_destroy_state(bridge, state);
145
+}
146
+
147
+static const struct drm_private_state_funcs drm_bridge_priv_state_funcs = {
148
+ .atomic_duplicate_state = drm_bridge_atomic_duplicate_priv_state,
149
+ .atomic_destroy_state = drm_bridge_atomic_destroy_priv_state,
150
+};
91151
92152 /**
93153 * drm_bridge_attach - attach the bridge to an encoder's chain
....@@ -95,6 +155,7 @@
95155 * @encoder: DRM encoder
96156 * @bridge: bridge to attach
97157 * @previous: previous bridge in the chain (optional)
158
+ * @flags: DRM_BRIDGE_ATTACH_* flags
98159 *
99160 * Called by a kms driver to link the bridge to an encoder's chain. The previous
100161 * argument specifies the previous bridge in the chain. If NULL, the bridge is
....@@ -104,11 +165,16 @@
104165 * If non-NULL the previous bridge must be already attached by a call to this
105166 * function.
106167 *
168
+ * Note that bridges attached to encoders are auto-detached during encoder
169
+ * cleanup in drm_encoder_cleanup(), so drm_bridge_attach() should generally
170
+ * *not* be balanced with a drm_bridge_detach() in driver code.
171
+ *
107172 * RETURNS:
108173 * Zero on success, error code on failure
109174 */
110175 int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
111
- struct drm_bridge *previous)
176
+ struct drm_bridge *previous,
177
+ enum drm_bridge_attach_flags flags)
112178 {
113179 int ret;
114180
....@@ -124,21 +190,42 @@
124190 bridge->dev = encoder->dev;
125191 bridge->encoder = encoder;
126192
193
+ if (previous)
194
+ list_add(&bridge->chain_node, &previous->chain_node);
195
+ else
196
+ list_add(&bridge->chain_node, &encoder->bridge_chain);
197
+
127198 if (bridge->funcs->attach) {
128
- ret = bridge->funcs->attach(bridge);
129
- if (ret < 0) {
130
- bridge->dev = NULL;
131
- bridge->encoder = NULL;
132
- return ret;
133
- }
199
+ ret = bridge->funcs->attach(bridge, flags);
200
+ if (ret < 0)
201
+ goto err_reset_bridge;
134202 }
135203
136
- if (previous)
137
- previous->next = bridge;
138
- else
139
- encoder->bridge = bridge;
204
+ if (bridge->funcs->atomic_reset) {
205
+ struct drm_bridge_state *state;
206
+
207
+ state = bridge->funcs->atomic_reset(bridge);
208
+ if (IS_ERR(state)) {
209
+ ret = PTR_ERR(state);
210
+ goto err_detach_bridge;
211
+ }
212
+
213
+ drm_atomic_private_obj_init(bridge->dev, &bridge->base,
214
+ &state->base,
215
+ &drm_bridge_priv_state_funcs);
216
+ }
140217
141218 return 0;
219
+
220
+err_detach_bridge:
221
+ if (bridge->funcs->detach)
222
+ bridge->funcs->detach(bridge);
223
+
224
+err_reset_bridge:
225
+ bridge->dev = NULL;
226
+ bridge->encoder = NULL;
227
+ list_del(&bridge->chain_node);
228
+ return ret;
142229 }
143230 EXPORT_SYMBOL(drm_bridge_attach);
144231
....@@ -150,26 +237,108 @@
150237 if (WARN_ON(!bridge->dev))
151238 return;
152239
240
+ if (bridge->funcs->atomic_reset)
241
+ drm_atomic_private_obj_fini(&bridge->base);
242
+
153243 if (bridge->funcs->detach)
154244 bridge->funcs->detach(bridge);
155245
246
+ list_del(&bridge->chain_node);
156247 bridge->dev = NULL;
157248 }
158249
159250 /**
160
- * DOC: bridge callbacks
251
+ * DOC: bridge operations
161252 *
162
- * The &drm_bridge_funcs ops are populated by the bridge driver. The DRM
163
- * internals (atomic and CRTC helpers) use the helpers defined in drm_bridge.c
164
- * These helpers call a specific &drm_bridge_funcs op for all the bridges
165
- * during encoder configuration.
253
+ * Bridge drivers expose operations through the &drm_bridge_funcs structure.
254
+ * The DRM internals (atomic and CRTC helpers) use the helpers defined in
255
+ * drm_bridge.c to call bridge operations. Those operations are divided in
256
+ * three big categories to support different parts of the bridge usage.
166257 *
167
- * For detailed specification of the bridge callbacks see &drm_bridge_funcs.
258
+ * - The encoder-related operations support control of the bridges in the
259
+ * chain, and are roughly counterparts to the &drm_encoder_helper_funcs
260
+ * operations. They are used by the legacy CRTC and the atomic modeset
261
+ * helpers to perform mode validation, fixup and setting, and enable and
262
+ * disable the bridge automatically.
263
+ *
264
+ * The enable and disable operations are split in
265
+ * &drm_bridge_funcs.pre_enable, &drm_bridge_funcs.enable,
266
+ * &drm_bridge_funcs.disable and &drm_bridge_funcs.post_disable to provide
267
+ * finer-grained control.
268
+ *
269
+ * Bridge drivers may implement the legacy version of those operations, or
270
+ * the atomic version (prefixed with atomic\_), in which case they shall also
271
+ * implement the atomic state bookkeeping operations
272
+ * (&drm_bridge_funcs.atomic_duplicate_state,
273
+ * &drm_bridge_funcs.atomic_destroy_state and &drm_bridge_funcs.reset).
274
+ * Mixing atomic and non-atomic versions of the operations is not supported.
275
+ *
276
+ * - The bus format negotiation operations
277
+ * &drm_bridge_funcs.atomic_get_output_bus_fmts and
278
+ * &drm_bridge_funcs.atomic_get_input_bus_fmts allow bridge drivers to
279
+ * negotiate the formats transmitted between bridges in the chain when
280
+ * multiple formats are supported. Negotiation for formats is performed
281
+ * transparently for display drivers by the atomic modeset helpers. Only
282
+ * atomic versions of those operations exist, bridge drivers that need to
283
+ * implement them shall thus also implement the atomic version of the
284
+ * encoder-related operations. This feature is not supported by the legacy
285
+ * CRTC helpers.
286
+ *
287
+ * - The connector-related operations support implementing a &drm_connector
288
+ * based on a chain of bridges. DRM bridges traditionally create a
289
+ * &drm_connector for bridges meant to be used at the end of the chain. This
290
+ * puts additional burden on bridge drivers, especially for bridges that may
291
+ * be used in the middle of a chain or at the end of it. Furthermore, it
292
+ * requires all operations of the &drm_connector to be handled by a single
293
+ * bridge, which doesn't always match the hardware architecture.
294
+ *
295
+ * To simplify bridge drivers and make the connector implementation more
296
+ * flexible, a new model allows bridges to unconditionally skip creation of
297
+ * &drm_connector and instead expose &drm_bridge_funcs operations to support
298
+ * an externally-implemented &drm_connector. Those operations are
299
+ * &drm_bridge_funcs.detect, &drm_bridge_funcs.get_modes,
300
+ * &drm_bridge_funcs.get_edid, &drm_bridge_funcs.hpd_notify,
301
+ * &drm_bridge_funcs.hpd_enable and &drm_bridge_funcs.hpd_disable. When
302
+ * implemented, display drivers shall create a &drm_connector instance for
303
+ * each chain of bridges, and implement those connector instances based on
304
+ * the bridge connector operations.
305
+ *
306
+ * Bridge drivers shall implement the connector-related operations for all
307
+ * the features that the bridge hardware support. For instance, if a bridge
308
+ * supports reading EDID, the &drm_bridge_funcs.get_edid shall be
309
+ * implemented. This however doesn't mean that the DDC lines are wired to the
310
+ * bridge on a particular platform, as they could also be connected to an I2C
311
+ * controller of the SoC. Support for the connector-related operations on the
312
+ * running platform is reported through the &drm_bridge.ops flags. Bridge
313
+ * drivers shall detect which operations they can support on the platform
314
+ * (usually this information is provided by ACPI or DT), and set the
315
+ * &drm_bridge.ops flags for all supported operations. A flag shall only be
316
+ * set if the corresponding &drm_bridge_funcs operation is implemented, but
317
+ * an implemented operation doesn't necessarily imply that the corresponding
318
+ * flag will be set. Display drivers shall use the &drm_bridge.ops flags to
319
+ * decide which bridge to delegate a connector operation to. This mechanism
320
+ * allows providing a single static const &drm_bridge_funcs instance in
321
+ * bridge drivers, improving security by storing function pointers in
322
+ * read-only memory.
323
+ *
324
+ * In order to ease transition, bridge drivers may support both the old and
325
+ * new models by making connector creation optional and implementing the
326
+ * connected-related bridge operations. Connector creation is then controlled
327
+ * by the flags argument to the drm_bridge_attach() function. Display drivers
328
+ * that support the new model and create connectors themselves shall set the
329
+ * %DRM_BRIDGE_ATTACH_NO_CONNECTOR flag, and bridge drivers shall then skip
330
+ * connector creation. For intermediate bridges in the chain, the flag shall
331
+ * be passed to the drm_bridge_attach() call for the downstream bridge.
332
+ * Bridge drivers that implement the new model only shall return an error
333
+ * from their &drm_bridge_funcs.attach handler when the
334
+ * %DRM_BRIDGE_ATTACH_NO_CONNECTOR flag is not set. New display drivers
335
+ * should use the new model, and convert the bridge drivers they use if
336
+ * needed, in order to gradually transition to the new model.
168337 */
169338
170339 /**
171
- * drm_bridge_mode_fixup - fixup proposed mode for all bridges in the
172
- * encoder chain
340
+ * drm_bridge_chain_mode_fixup - fixup proposed mode for all bridges in the
341
+ * encoder chain
173342 * @bridge: bridge control structure
174343 * @mode: desired mode to be set for the bridge
175344 * @adjusted_mode: updated mode that works for this bridge
....@@ -182,28 +351,33 @@
182351 * RETURNS:
183352 * true on success, false on failure
184353 */
185
-bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
186
- const struct drm_display_mode *mode,
187
- struct drm_display_mode *adjusted_mode)
354
+bool drm_bridge_chain_mode_fixup(struct drm_bridge *bridge,
355
+ const struct drm_display_mode *mode,
356
+ struct drm_display_mode *adjusted_mode)
188357 {
189
- bool ret = true;
358
+ struct drm_encoder *encoder;
190359
191360 if (!bridge)
192361 return true;
193362
194
- if (bridge->funcs->mode_fixup)
195
- ret = bridge->funcs->mode_fixup(bridge, mode, adjusted_mode);
363
+ encoder = bridge->encoder;
364
+ list_for_each_entry_from(bridge, &encoder->bridge_chain, chain_node) {
365
+ if (!bridge->funcs->mode_fixup)
366
+ continue;
196367
197
- ret = ret && drm_bridge_mode_fixup(bridge->next, mode, adjusted_mode);
368
+ if (!bridge->funcs->mode_fixup(bridge, mode, adjusted_mode))
369
+ return false;
370
+ }
198371
199
- return ret;
372
+ return true;
200373 }
201
-EXPORT_SYMBOL(drm_bridge_mode_fixup);
374
+EXPORT_SYMBOL(drm_bridge_chain_mode_fixup);
202375
203376 /**
204
- * drm_bridge_mode_valid - validate the mode against all bridges in the
205
- * encoder chain.
377
+ * drm_bridge_chain_mode_valid - validate the mode against all bridges in the
378
+ * encoder chain.
206379 * @bridge: bridge control structure
380
+ * @info: display info against which the mode shall be validated
207381 * @mode: desired mode to be validated
208382 *
209383 * Calls &drm_bridge_funcs.mode_valid for all the bridges in the encoder
....@@ -215,26 +389,34 @@
215389 * RETURNS:
216390 * MODE_OK on success, drm_mode_status Enum error code on failure
217391 */
218
-enum drm_mode_status drm_bridge_mode_valid(struct drm_bridge *bridge,
219
- const struct drm_display_mode *mode)
392
+enum drm_mode_status
393
+drm_bridge_chain_mode_valid(struct drm_bridge *bridge,
394
+ const struct drm_display_info *info,
395
+ const struct drm_display_mode *mode)
220396 {
221
- enum drm_mode_status ret = MODE_OK;
397
+ struct drm_encoder *encoder;
222398
223399 if (!bridge)
224
- return ret;
400
+ return MODE_OK;
225401
226
- if (bridge->funcs->mode_valid)
227
- ret = bridge->funcs->mode_valid(bridge, mode);
402
+ encoder = bridge->encoder;
403
+ list_for_each_entry_from(bridge, &encoder->bridge_chain, chain_node) {
404
+ enum drm_mode_status ret;
228405
229
- if (ret != MODE_OK)
230
- return ret;
406
+ if (!bridge->funcs->mode_valid)
407
+ continue;
231408
232
- return drm_bridge_mode_valid(bridge->next, mode);
409
+ ret = bridge->funcs->mode_valid(bridge, info, mode);
410
+ if (ret != MODE_OK)
411
+ return ret;
412
+ }
413
+
414
+ return MODE_OK;
233415 }
234
-EXPORT_SYMBOL(drm_bridge_mode_valid);
416
+EXPORT_SYMBOL(drm_bridge_chain_mode_valid);
235417
236418 /**
237
- * drm_bridge_disable - disables all bridges in the encoder chain
419
+ * drm_bridge_chain_disable - disables all bridges in the encoder chain
238420 * @bridge: bridge control structure
239421 *
240422 * Calls &drm_bridge_funcs.disable op for all the bridges in the encoder
....@@ -243,20 +425,28 @@
243425 *
244426 * Note: the bridge passed should be the one closest to the encoder
245427 */
246
-void drm_bridge_disable(struct drm_bridge *bridge)
428
+void drm_bridge_chain_disable(struct drm_bridge *bridge)
247429 {
430
+ struct drm_encoder *encoder;
431
+ struct drm_bridge *iter;
432
+
248433 if (!bridge)
249434 return;
250435
251
- drm_bridge_disable(bridge->next);
436
+ encoder = bridge->encoder;
437
+ list_for_each_entry_reverse(iter, &encoder->bridge_chain, chain_node) {
438
+ if (iter->funcs->disable)
439
+ iter->funcs->disable(iter);
252440
253
- if (bridge->funcs->disable)
254
- bridge->funcs->disable(bridge);
441
+ if (iter == bridge)
442
+ break;
443
+ }
255444 }
256
-EXPORT_SYMBOL(drm_bridge_disable);
445
+EXPORT_SYMBOL(drm_bridge_chain_disable);
257446
258447 /**
259
- * drm_bridge_post_disable - cleans up after disabling all bridges in the encoder chain
448
+ * drm_bridge_chain_post_disable - cleans up after disabling all bridges in the
449
+ * encoder chain
260450 * @bridge: bridge control structure
261451 *
262452 * Calls &drm_bridge_funcs.post_disable op for all the bridges in the
....@@ -265,47 +455,53 @@
265455 *
266456 * Note: the bridge passed should be the one closest to the encoder
267457 */
268
-void drm_bridge_post_disable(struct drm_bridge *bridge)
458
+void drm_bridge_chain_post_disable(struct drm_bridge *bridge)
269459 {
460
+ struct drm_encoder *encoder;
461
+
270462 if (!bridge)
271463 return;
272464
273
- if (bridge->funcs->post_disable)
274
- bridge->funcs->post_disable(bridge);
275
-
276
- drm_bridge_post_disable(bridge->next);
465
+ encoder = bridge->encoder;
466
+ list_for_each_entry_from(bridge, &encoder->bridge_chain, chain_node) {
467
+ if (bridge->funcs->post_disable)
468
+ bridge->funcs->post_disable(bridge);
469
+ }
277470 }
278
-EXPORT_SYMBOL(drm_bridge_post_disable);
471
+EXPORT_SYMBOL(drm_bridge_chain_post_disable);
279472
280473 /**
281
- * drm_bridge_mode_set - set proposed mode for all bridges in the
282
- * encoder chain
474
+ * drm_bridge_chain_mode_set - set proposed mode for all bridges in the
475
+ * encoder chain
283476 * @bridge: bridge control structure
284
- * @mode: desired mode to be set for the bridge
285
- * @adjusted_mode: updated mode that works for this bridge
477
+ * @mode: desired mode to be set for the encoder chain
478
+ * @adjusted_mode: updated mode that works for this encoder chain
286479 *
287480 * Calls &drm_bridge_funcs.mode_set op for all the bridges in the
288481 * encoder chain, starting from the first bridge to the last.
289482 *
290483 * Note: the bridge passed should be the one closest to the encoder
291484 */
292
-void drm_bridge_mode_set(struct drm_bridge *bridge,
293
- struct drm_display_mode *mode,
294
- struct drm_display_mode *adjusted_mode)
485
+void drm_bridge_chain_mode_set(struct drm_bridge *bridge,
486
+ const struct drm_display_mode *mode,
487
+ const struct drm_display_mode *adjusted_mode)
295488 {
489
+ struct drm_encoder *encoder;
490
+
296491 if (!bridge)
297492 return;
298493
299
- if (bridge->funcs->mode_set)
300
- bridge->funcs->mode_set(bridge, mode, adjusted_mode);
301
-
302
- drm_bridge_mode_set(bridge->next, mode, adjusted_mode);
494
+ encoder = bridge->encoder;
495
+ list_for_each_entry_from(bridge, &encoder->bridge_chain, chain_node) {
496
+ if (bridge->funcs->mode_set)
497
+ bridge->funcs->mode_set(bridge, mode, adjusted_mode);
498
+ }
303499 }
304
-EXPORT_SYMBOL(drm_bridge_mode_set);
500
+EXPORT_SYMBOL(drm_bridge_chain_mode_set);
305501
306502 /**
307
- * drm_bridge_pre_enable - prepares for enabling all
308
- * bridges in the encoder chain
503
+ * drm_bridge_chain_pre_enable - prepares for enabling all bridges in the
504
+ * encoder chain
309505 * @bridge: bridge control structure
310506 *
311507 * Calls &drm_bridge_funcs.pre_enable op for all the bridges in the encoder
....@@ -314,20 +510,27 @@
314510 *
315511 * Note: the bridge passed should be the one closest to the encoder
316512 */
317
-void drm_bridge_pre_enable(struct drm_bridge *bridge)
513
+void drm_bridge_chain_pre_enable(struct drm_bridge *bridge)
318514 {
515
+ struct drm_encoder *encoder;
516
+ struct drm_bridge *iter;
517
+
319518 if (!bridge)
320519 return;
321520
322
- drm_bridge_pre_enable(bridge->next);
521
+ encoder = bridge->encoder;
522
+ list_for_each_entry_reverse(iter, &encoder->bridge_chain, chain_node) {
523
+ if (iter->funcs->pre_enable)
524
+ iter->funcs->pre_enable(iter);
323525
324
- if (bridge->funcs->pre_enable)
325
- bridge->funcs->pre_enable(bridge);
526
+ if (iter == bridge)
527
+ break;
528
+ }
326529 }
327
-EXPORT_SYMBOL(drm_bridge_pre_enable);
530
+EXPORT_SYMBOL(drm_bridge_chain_pre_enable);
328531
329532 /**
330
- * drm_bridge_enable - enables all bridges in the encoder chain
533
+ * drm_bridge_chain_enable - enables all bridges in the encoder chain
331534 * @bridge: bridge control structure
332535 *
333536 * Calls &drm_bridge_funcs.enable op for all the bridges in the encoder
....@@ -336,17 +539,662 @@
336539 *
337540 * Note that the bridge passed should be the one closest to the encoder
338541 */
339
-void drm_bridge_enable(struct drm_bridge *bridge)
542
+void drm_bridge_chain_enable(struct drm_bridge *bridge)
340543 {
544
+ struct drm_encoder *encoder;
545
+
341546 if (!bridge)
342547 return;
343548
344
- if (bridge->funcs->enable)
345
- bridge->funcs->enable(bridge);
346
-
347
- drm_bridge_enable(bridge->next);
549
+ encoder = bridge->encoder;
550
+ list_for_each_entry_from(bridge, &encoder->bridge_chain, chain_node) {
551
+ if (bridge->funcs->enable)
552
+ bridge->funcs->enable(bridge);
553
+ }
348554 }
349
-EXPORT_SYMBOL(drm_bridge_enable);
555
+EXPORT_SYMBOL(drm_bridge_chain_enable);
556
+
557
+/**
558
+ * drm_atomic_bridge_chain_disable - disables all bridges in the encoder chain
559
+ * @bridge: bridge control structure
560
+ * @old_state: old atomic state
561
+ *
562
+ * Calls &drm_bridge_funcs.atomic_disable (falls back on
563
+ * &drm_bridge_funcs.disable) op for all the bridges in the encoder chain,
564
+ * starting from the last bridge to the first. These are called before calling
565
+ * &drm_encoder_helper_funcs.atomic_disable
566
+ *
567
+ * Note: the bridge passed should be the one closest to the encoder
568
+ */
569
+void drm_atomic_bridge_chain_disable(struct drm_bridge *bridge,
570
+ struct drm_atomic_state *old_state)
571
+{
572
+ struct drm_encoder *encoder;
573
+ struct drm_bridge *iter;
574
+
575
+ if (!bridge)
576
+ return;
577
+
578
+ encoder = bridge->encoder;
579
+ list_for_each_entry_reverse(iter, &encoder->bridge_chain, chain_node) {
580
+ if (iter->funcs->atomic_disable) {
581
+ struct drm_bridge_state *old_bridge_state;
582
+
583
+ old_bridge_state =
584
+ drm_atomic_get_old_bridge_state(old_state,
585
+ iter);
586
+ if (WARN_ON(!old_bridge_state))
587
+ return;
588
+
589
+ iter->funcs->atomic_disable(iter, old_bridge_state);
590
+ } else if (iter->funcs->disable) {
591
+ iter->funcs->disable(iter);
592
+ }
593
+
594
+ if (iter == bridge)
595
+ break;
596
+ }
597
+}
598
+EXPORT_SYMBOL(drm_atomic_bridge_chain_disable);
599
+
600
+/**
601
+ * drm_atomic_bridge_chain_post_disable - cleans up after disabling all bridges
602
+ * in the encoder chain
603
+ * @bridge: bridge control structure
604
+ * @old_state: old atomic state
605
+ *
606
+ * Calls &drm_bridge_funcs.atomic_post_disable (falls back on
607
+ * &drm_bridge_funcs.post_disable) op for all the bridges in the encoder chain,
608
+ * starting from the first bridge to the last. These are called after completing
609
+ * &drm_encoder_helper_funcs.atomic_disable
610
+ *
611
+ * Note: the bridge passed should be the one closest to the encoder
612
+ */
613
+void drm_atomic_bridge_chain_post_disable(struct drm_bridge *bridge,
614
+ struct drm_atomic_state *old_state)
615
+{
616
+ struct drm_encoder *encoder;
617
+
618
+ if (!bridge)
619
+ return;
620
+
621
+ encoder = bridge->encoder;
622
+ list_for_each_entry_from(bridge, &encoder->bridge_chain, chain_node) {
623
+ if (bridge->funcs->atomic_post_disable) {
624
+ struct drm_bridge_state *old_bridge_state;
625
+
626
+ old_bridge_state =
627
+ drm_atomic_get_old_bridge_state(old_state,
628
+ bridge);
629
+ if (WARN_ON(!old_bridge_state))
630
+ return;
631
+
632
+ bridge->funcs->atomic_post_disable(bridge,
633
+ old_bridge_state);
634
+ } else if (bridge->funcs->post_disable) {
635
+ bridge->funcs->post_disable(bridge);
636
+ }
637
+ }
638
+}
639
+EXPORT_SYMBOL(drm_atomic_bridge_chain_post_disable);
640
+
641
+/**
642
+ * drm_atomic_bridge_chain_pre_enable - prepares for enabling all bridges in
643
+ * the encoder chain
644
+ * @bridge: bridge control structure
645
+ * @old_state: old atomic state
646
+ *
647
+ * Calls &drm_bridge_funcs.atomic_pre_enable (falls back on
648
+ * &drm_bridge_funcs.pre_enable) op for all the bridges in the encoder chain,
649
+ * starting from the last bridge to the first. These are called before calling
650
+ * &drm_encoder_helper_funcs.atomic_enable
651
+ *
652
+ * Note: the bridge passed should be the one closest to the encoder
653
+ */
654
+void drm_atomic_bridge_chain_pre_enable(struct drm_bridge *bridge,
655
+ struct drm_atomic_state *old_state)
656
+{
657
+ struct drm_encoder *encoder;
658
+ struct drm_bridge *iter;
659
+
660
+ if (!bridge)
661
+ return;
662
+
663
+ encoder = bridge->encoder;
664
+ list_for_each_entry_reverse(iter, &encoder->bridge_chain, chain_node) {
665
+ if (iter->funcs->atomic_pre_enable) {
666
+ struct drm_bridge_state *old_bridge_state;
667
+
668
+ old_bridge_state =
669
+ drm_atomic_get_old_bridge_state(old_state,
670
+ iter);
671
+ if (WARN_ON(!old_bridge_state))
672
+ return;
673
+
674
+ iter->funcs->atomic_pre_enable(iter, old_bridge_state);
675
+ } else if (iter->funcs->pre_enable) {
676
+ iter->funcs->pre_enable(iter);
677
+ }
678
+
679
+ if (iter == bridge)
680
+ break;
681
+ }
682
+}
683
+EXPORT_SYMBOL(drm_atomic_bridge_chain_pre_enable);
684
+
685
+/**
686
+ * drm_atomic_bridge_chain_enable - enables all bridges in the encoder chain
687
+ * @bridge: bridge control structure
688
+ * @old_state: old atomic state
689
+ *
690
+ * Calls &drm_bridge_funcs.atomic_enable (falls back on
691
+ * &drm_bridge_funcs.enable) op for all the bridges in the encoder chain,
692
+ * starting from the first bridge to the last. These are called after completing
693
+ * &drm_encoder_helper_funcs.atomic_enable
694
+ *
695
+ * Note: the bridge passed should be the one closest to the encoder
696
+ */
697
+void drm_atomic_bridge_chain_enable(struct drm_bridge *bridge,
698
+ struct drm_atomic_state *old_state)
699
+{
700
+ struct drm_encoder *encoder;
701
+
702
+ if (!bridge)
703
+ return;
704
+
705
+ encoder = bridge->encoder;
706
+ list_for_each_entry_from(bridge, &encoder->bridge_chain, chain_node) {
707
+ if (bridge->funcs->atomic_enable) {
708
+ struct drm_bridge_state *old_bridge_state;
709
+
710
+ old_bridge_state =
711
+ drm_atomic_get_old_bridge_state(old_state,
712
+ bridge);
713
+ if (WARN_ON(!old_bridge_state))
714
+ return;
715
+
716
+ bridge->funcs->atomic_enable(bridge, old_bridge_state);
717
+ } else if (bridge->funcs->enable) {
718
+ bridge->funcs->enable(bridge);
719
+ }
720
+ }
721
+}
722
+EXPORT_SYMBOL(drm_atomic_bridge_chain_enable);
723
+
724
+static int drm_atomic_bridge_check(struct drm_bridge *bridge,
725
+ struct drm_crtc_state *crtc_state,
726
+ struct drm_connector_state *conn_state)
727
+{
728
+ if (bridge->funcs->atomic_check) {
729
+ struct drm_bridge_state *bridge_state;
730
+ int ret;
731
+
732
+ bridge_state = drm_atomic_get_new_bridge_state(crtc_state->state,
733
+ bridge);
734
+ if (WARN_ON(!bridge_state))
735
+ return -EINVAL;
736
+
737
+ ret = bridge->funcs->atomic_check(bridge, bridge_state,
738
+ crtc_state, conn_state);
739
+ if (ret)
740
+ return ret;
741
+ } else if (bridge->funcs->mode_fixup) {
742
+ if (!bridge->funcs->mode_fixup(bridge, &crtc_state->mode,
743
+ &crtc_state->adjusted_mode))
744
+ return -EINVAL;
745
+ }
746
+
747
+ return 0;
748
+}
749
+
750
+static int select_bus_fmt_recursive(struct drm_bridge *first_bridge,
751
+ struct drm_bridge *cur_bridge,
752
+ struct drm_crtc_state *crtc_state,
753
+ struct drm_connector_state *conn_state,
754
+ u32 out_bus_fmt)
755
+{
756
+ unsigned int i, num_in_bus_fmts = 0;
757
+ struct drm_bridge_state *cur_state;
758
+ struct drm_bridge *prev_bridge;
759
+ u32 *in_bus_fmts;
760
+ int ret;
761
+
762
+ prev_bridge = drm_bridge_get_prev_bridge(cur_bridge);
763
+ cur_state = drm_atomic_get_new_bridge_state(crtc_state->state,
764
+ cur_bridge);
765
+
766
+ /*
767
+ * If bus format negotiation is not supported by this bridge, let's
768
+ * pass MEDIA_BUS_FMT_FIXED to the previous bridge in the chain and
769
+ * hope that it can handle this situation gracefully (by providing
770
+ * appropriate default values).
771
+ */
772
+ if (!cur_bridge->funcs->atomic_get_input_bus_fmts) {
773
+ if (cur_bridge != first_bridge) {
774
+ ret = select_bus_fmt_recursive(first_bridge,
775
+ prev_bridge, crtc_state,
776
+ conn_state,
777
+ MEDIA_BUS_FMT_FIXED);
778
+ if (ret)
779
+ return ret;
780
+ }
781
+
782
+ /*
783
+ * Driver does not implement the atomic state hooks, but that's
784
+ * fine, as long as it does not access the bridge state.
785
+ */
786
+ if (cur_state) {
787
+ cur_state->input_bus_cfg.format = MEDIA_BUS_FMT_FIXED;
788
+ cur_state->output_bus_cfg.format = out_bus_fmt;
789
+ }
790
+
791
+ return 0;
792
+ }
793
+
794
+ /*
795
+ * If the driver implements ->atomic_get_input_bus_fmts() it
796
+ * should also implement the atomic state hooks.
797
+ */
798
+ if (WARN_ON(!cur_state))
799
+ return -EINVAL;
800
+
801
+ in_bus_fmts = cur_bridge->funcs->atomic_get_input_bus_fmts(cur_bridge,
802
+ cur_state,
803
+ crtc_state,
804
+ conn_state,
805
+ out_bus_fmt,
806
+ &num_in_bus_fmts);
807
+ if (!num_in_bus_fmts)
808
+ return -ENOTSUPP;
809
+ else if (!in_bus_fmts)
810
+ return -ENOMEM;
811
+
812
+ if (first_bridge == cur_bridge) {
813
+ cur_state->input_bus_cfg.format = in_bus_fmts[0];
814
+ cur_state->output_bus_cfg.format = out_bus_fmt;
815
+ kfree(in_bus_fmts);
816
+ return 0;
817
+ }
818
+
819
+ for (i = 0; i < num_in_bus_fmts; i++) {
820
+ ret = select_bus_fmt_recursive(first_bridge, prev_bridge,
821
+ crtc_state, conn_state,
822
+ in_bus_fmts[i]);
823
+ if (ret != -ENOTSUPP)
824
+ break;
825
+ }
826
+
827
+ if (!ret) {
828
+ cur_state->input_bus_cfg.format = in_bus_fmts[i];
829
+ cur_state->output_bus_cfg.format = out_bus_fmt;
830
+ }
831
+
832
+ kfree(in_bus_fmts);
833
+ return ret;
834
+}
835
+
836
+/*
837
+ * This function is called by &drm_atomic_bridge_chain_check() just before
838
+ * calling &drm_bridge_funcs.atomic_check() on all elements of the chain.
839
+ * It performs bus format negotiation between bridge elements. The negotiation
840
+ * happens in reverse order, starting from the last element in the chain up to
841
+ * @bridge.
842
+ *
843
+ * Negotiation starts by retrieving supported output bus formats on the last
844
+ * bridge element and testing them one by one. The test is recursive, meaning
845
+ * that for each tested output format, the whole chain will be walked backward,
846
+ * and each element will have to choose an input bus format that can be
847
+ * transcoded to the requested output format. When a bridge element does not
848
+ * support transcoding into a specific output format -ENOTSUPP is returned and
849
+ * the next bridge element will have to try a different format. If none of the
850
+ * combinations worked, -ENOTSUPP is returned and the atomic modeset will fail.
851
+ *
852
+ * This implementation is relying on
853
+ * &drm_bridge_funcs.atomic_get_output_bus_fmts() and
854
+ * &drm_bridge_funcs.atomic_get_input_bus_fmts() to gather supported
855
+ * input/output formats.
856
+ *
857
+ * When &drm_bridge_funcs.atomic_get_output_bus_fmts() is not implemented by
858
+ * the last element of the chain, &drm_atomic_bridge_chain_select_bus_fmts()
859
+ * tries a single format: &drm_connector.display_info.bus_formats[0] if
860
+ * available, MEDIA_BUS_FMT_FIXED otherwise.
861
+ *
862
+ * When &drm_bridge_funcs.atomic_get_input_bus_fmts() is not implemented,
863
+ * &drm_atomic_bridge_chain_select_bus_fmts() skips the negotiation on the
864
+ * bridge element that lacks this hook and asks the previous element in the
865
+ * chain to try MEDIA_BUS_FMT_FIXED. It's up to bridge drivers to decide what
866
+ * to do in that case (fail if they want to enforce bus format negotiation, or
867
+ * provide a reasonable default if they need to support pipelines where not
868
+ * all elements support bus format negotiation).
869
+ */
870
+static int
871
+drm_atomic_bridge_chain_select_bus_fmts(struct drm_bridge *bridge,
872
+ struct drm_crtc_state *crtc_state,
873
+ struct drm_connector_state *conn_state)
874
+{
875
+ struct drm_connector *conn = conn_state->connector;
876
+ struct drm_encoder *encoder = bridge->encoder;
877
+ struct drm_bridge_state *last_bridge_state;
878
+ unsigned int i, num_out_bus_fmts = 0;
879
+ struct drm_bridge *last_bridge;
880
+ u32 *out_bus_fmts;
881
+ int ret = 0;
882
+
883
+ last_bridge = list_last_entry(&encoder->bridge_chain,
884
+ struct drm_bridge, chain_node);
885
+ last_bridge_state = drm_atomic_get_new_bridge_state(crtc_state->state,
886
+ last_bridge);
887
+
888
+ if (last_bridge->funcs->atomic_get_output_bus_fmts) {
889
+ const struct drm_bridge_funcs *funcs = last_bridge->funcs;
890
+
891
+ /*
892
+ * If the driver implements ->atomic_get_output_bus_fmts() it
893
+ * should also implement the atomic state hooks.
894
+ */
895
+ if (WARN_ON(!last_bridge_state))
896
+ return -EINVAL;
897
+
898
+ out_bus_fmts = funcs->atomic_get_output_bus_fmts(last_bridge,
899
+ last_bridge_state,
900
+ crtc_state,
901
+ conn_state,
902
+ &num_out_bus_fmts);
903
+ if (!num_out_bus_fmts)
904
+ return -ENOTSUPP;
905
+ else if (!out_bus_fmts)
906
+ return -ENOMEM;
907
+ } else {
908
+ num_out_bus_fmts = 1;
909
+ out_bus_fmts = kmalloc(sizeof(*out_bus_fmts), GFP_KERNEL);
910
+ if (!out_bus_fmts)
911
+ return -ENOMEM;
912
+
913
+ if (conn->display_info.num_bus_formats &&
914
+ conn->display_info.bus_formats)
915
+ out_bus_fmts[0] = conn->display_info.bus_formats[0];
916
+ else
917
+ out_bus_fmts[0] = MEDIA_BUS_FMT_FIXED;
918
+ }
919
+
920
+ for (i = 0; i < num_out_bus_fmts; i++) {
921
+ ret = select_bus_fmt_recursive(bridge, last_bridge, crtc_state,
922
+ conn_state, out_bus_fmts[i]);
923
+ if (ret != -ENOTSUPP)
924
+ break;
925
+ }
926
+
927
+ kfree(out_bus_fmts);
928
+
929
+ return ret;
930
+}
931
+
932
+static void
933
+drm_atomic_bridge_propagate_bus_flags(struct drm_bridge *bridge,
934
+ struct drm_connector *conn,
935
+ struct drm_atomic_state *state)
936
+{
937
+ struct drm_bridge_state *bridge_state, *next_bridge_state;
938
+ struct drm_bridge *next_bridge;
939
+ u32 output_flags = 0;
940
+
941
+ bridge_state = drm_atomic_get_new_bridge_state(state, bridge);
942
+
943
+ /* No bridge state attached to this bridge => nothing to propagate. */
944
+ if (!bridge_state)
945
+ return;
946
+
947
+ next_bridge = drm_bridge_get_next_bridge(bridge);
948
+
949
+ /*
950
+ * Let's try to apply the most common case here, that is, propagate
951
+ * display_info flags for the last bridge, and propagate the input
952
+ * flags of the next bridge element to the output end of the current
953
+ * bridge when the bridge is not the last one.
954
+ * There are exceptions to this rule, like when signal inversion is
955
+ * happening at the board level, but that's something drivers can deal
956
+ * with from their &drm_bridge_funcs.atomic_check() implementation by
957
+ * simply overriding the flags value we've set here.
958
+ */
959
+ if (!next_bridge) {
960
+ output_flags = conn->display_info.bus_flags;
961
+ } else {
962
+ next_bridge_state = drm_atomic_get_new_bridge_state(state,
963
+ next_bridge);
964
+ /*
965
+ * No bridge state attached to the next bridge, just leave the
966
+ * flags to 0.
967
+ */
968
+ if (next_bridge_state)
969
+ output_flags = next_bridge_state->input_bus_cfg.flags;
970
+ }
971
+
972
+ bridge_state->output_bus_cfg.flags = output_flags;
973
+
974
+ /*
975
+ * Propage the output flags to the input end of the bridge. Again, it's
976
+ * not necessarily what all bridges want, but that's what most of them
977
+ * do, and by doing that by default we avoid forcing drivers to
978
+ * duplicate the "dummy propagation" logic.
979
+ */
980
+ bridge_state->input_bus_cfg.flags = output_flags;
981
+}
982
+
983
+/**
984
+ * drm_atomic_bridge_chain_check() - Do an atomic check on the bridge chain
985
+ * @bridge: bridge control structure
986
+ * @crtc_state: new CRTC state
987
+ * @conn_state: new connector state
988
+ *
989
+ * First trigger a bus format negotiation before calling
990
+ * &drm_bridge_funcs.atomic_check() (falls back on
991
+ * &drm_bridge_funcs.mode_fixup()) op for all the bridges in the encoder chain,
992
+ * starting from the last bridge to the first. These are called before calling
993
+ * &drm_encoder_helper_funcs.atomic_check()
994
+ *
995
+ * RETURNS:
996
+ * 0 on success, a negative error code on failure
997
+ */
998
+int drm_atomic_bridge_chain_check(struct drm_bridge *bridge,
999
+ struct drm_crtc_state *crtc_state,
1000
+ struct drm_connector_state *conn_state)
1001
+{
1002
+ struct drm_connector *conn = conn_state->connector;
1003
+ struct drm_encoder *encoder;
1004
+ struct drm_bridge *iter;
1005
+ int ret;
1006
+
1007
+ if (!bridge)
1008
+ return 0;
1009
+
1010
+ ret = drm_atomic_bridge_chain_select_bus_fmts(bridge, crtc_state,
1011
+ conn_state);
1012
+ if (ret)
1013
+ return ret;
1014
+
1015
+ encoder = bridge->encoder;
1016
+ list_for_each_entry_reverse(iter, &encoder->bridge_chain, chain_node) {
1017
+ int ret;
1018
+
1019
+ /*
1020
+ * Bus flags are propagated by default. If a bridge needs to
1021
+ * tweak the input bus flags for any reason, it should happen
1022
+ * in its &drm_bridge_funcs.atomic_check() implementation such
1023
+ * that preceding bridges in the chain can propagate the new
1024
+ * bus flags.
1025
+ */
1026
+ drm_atomic_bridge_propagate_bus_flags(iter, conn,
1027
+ crtc_state->state);
1028
+
1029
+ ret = drm_atomic_bridge_check(iter, crtc_state, conn_state);
1030
+ if (ret)
1031
+ return ret;
1032
+
1033
+ if (iter == bridge)
1034
+ break;
1035
+ }
1036
+
1037
+ return 0;
1038
+}
1039
+EXPORT_SYMBOL(drm_atomic_bridge_chain_check);
1040
+
1041
+/**
1042
+ * drm_bridge_detect - check if anything is attached to the bridge output
1043
+ * @bridge: bridge control structure
1044
+ *
1045
+ * If the bridge supports output detection, as reported by the
1046
+ * DRM_BRIDGE_OP_DETECT bridge ops flag, call &drm_bridge_funcs.detect for the
1047
+ * bridge and return the connection status. Otherwise return
1048
+ * connector_status_unknown.
1049
+ *
1050
+ * RETURNS:
1051
+ * The detection status on success, or connector_status_unknown if the bridge
1052
+ * doesn't support output detection.
1053
+ */
1054
+enum drm_connector_status drm_bridge_detect(struct drm_bridge *bridge)
1055
+{
1056
+ if (!(bridge->ops & DRM_BRIDGE_OP_DETECT))
1057
+ return connector_status_unknown;
1058
+
1059
+ return bridge->funcs->detect(bridge);
1060
+}
1061
+EXPORT_SYMBOL_GPL(drm_bridge_detect);
1062
+
1063
+/**
1064
+ * drm_bridge_get_modes - fill all modes currently valid for the sink into the
1065
+ * @connector
1066
+ * @bridge: bridge control structure
1067
+ * @connector: the connector to fill with modes
1068
+ *
1069
+ * If the bridge supports output modes retrieval, as reported by the
1070
+ * DRM_BRIDGE_OP_MODES bridge ops flag, call &drm_bridge_funcs.get_modes to
1071
+ * fill the connector with all valid modes and return the number of modes
1072
+ * added. Otherwise return 0.
1073
+ *
1074
+ * RETURNS:
1075
+ * The number of modes added to the connector.
1076
+ */
1077
+int drm_bridge_get_modes(struct drm_bridge *bridge,
1078
+ struct drm_connector *connector)
1079
+{
1080
+ if (!(bridge->ops & DRM_BRIDGE_OP_MODES))
1081
+ return 0;
1082
+
1083
+ return bridge->funcs->get_modes(bridge, connector);
1084
+}
1085
+EXPORT_SYMBOL_GPL(drm_bridge_get_modes);
1086
+
1087
+/**
1088
+ * drm_bridge_get_edid - get the EDID data of the connected display
1089
+ * @bridge: bridge control structure
1090
+ * @connector: the connector to read EDID for
1091
+ *
1092
+ * If the bridge supports output EDID retrieval, as reported by the
1093
+ * DRM_BRIDGE_OP_EDID bridge ops flag, call &drm_bridge_funcs.get_edid to
1094
+ * get the EDID and return it. Otherwise return NULL.
1095
+ *
1096
+ * RETURNS:
1097
+ * The retrieved EDID on success, or NULL otherwise.
1098
+ */
1099
+struct edid *drm_bridge_get_edid(struct drm_bridge *bridge,
1100
+ struct drm_connector *connector)
1101
+{
1102
+ if (!(bridge->ops & DRM_BRIDGE_OP_EDID))
1103
+ return NULL;
1104
+
1105
+ return bridge->funcs->get_edid(bridge, connector);
1106
+}
1107
+EXPORT_SYMBOL_GPL(drm_bridge_get_edid);
1108
+
1109
+/**
1110
+ * drm_bridge_hpd_enable - enable hot plug detection for the bridge
1111
+ * @bridge: bridge control structure
1112
+ * @cb: hot-plug detection callback
1113
+ * @data: data to be passed to the hot-plug detection callback
1114
+ *
1115
+ * Call &drm_bridge_funcs.hpd_enable if implemented and register the given @cb
1116
+ * and @data as hot plug notification callback. From now on the @cb will be
1117
+ * called with @data when an output status change is detected by the bridge,
1118
+ * until hot plug notification gets disabled with drm_bridge_hpd_disable().
1119
+ *
1120
+ * Hot plug detection is supported only if the DRM_BRIDGE_OP_HPD flag is set in
1121
+ * bridge->ops. This function shall not be called when the flag is not set.
1122
+ *
1123
+ * Only one hot plug detection callback can be registered at a time, it is an
1124
+ * error to call this function when hot plug detection is already enabled for
1125
+ * the bridge.
1126
+ */
1127
+void drm_bridge_hpd_enable(struct drm_bridge *bridge,
1128
+ void (*cb)(void *data,
1129
+ enum drm_connector_status status),
1130
+ void *data)
1131
+{
1132
+ if (!(bridge->ops & DRM_BRIDGE_OP_HPD))
1133
+ return;
1134
+
1135
+ mutex_lock(&bridge->hpd_mutex);
1136
+
1137
+ if (WARN(bridge->hpd_cb, "Hot plug detection already enabled\n"))
1138
+ goto unlock;
1139
+
1140
+ bridge->hpd_cb = cb;
1141
+ bridge->hpd_data = data;
1142
+
1143
+ if (bridge->funcs->hpd_enable)
1144
+ bridge->funcs->hpd_enable(bridge);
1145
+
1146
+unlock:
1147
+ mutex_unlock(&bridge->hpd_mutex);
1148
+}
1149
+EXPORT_SYMBOL_GPL(drm_bridge_hpd_enable);
1150
+
1151
+/**
1152
+ * drm_bridge_hpd_disable - disable hot plug detection for the bridge
1153
+ * @bridge: bridge control structure
1154
+ *
1155
+ * Call &drm_bridge_funcs.hpd_disable if implemented and unregister the hot
1156
+ * plug detection callback previously registered with drm_bridge_hpd_enable().
1157
+ * Once this function returns the callback will not be called by the bridge
1158
+ * when an output status change occurs.
1159
+ *
1160
+ * Hot plug detection is supported only if the DRM_BRIDGE_OP_HPD flag is set in
1161
+ * bridge->ops. This function shall not be called when the flag is not set.
1162
+ */
1163
+void drm_bridge_hpd_disable(struct drm_bridge *bridge)
1164
+{
1165
+ if (!(bridge->ops & DRM_BRIDGE_OP_HPD))
1166
+ return;
1167
+
1168
+ mutex_lock(&bridge->hpd_mutex);
1169
+ if (bridge->funcs->hpd_disable)
1170
+ bridge->funcs->hpd_disable(bridge);
1171
+
1172
+ bridge->hpd_cb = NULL;
1173
+ bridge->hpd_data = NULL;
1174
+ mutex_unlock(&bridge->hpd_mutex);
1175
+}
1176
+EXPORT_SYMBOL_GPL(drm_bridge_hpd_disable);
1177
+
1178
+/**
1179
+ * drm_bridge_hpd_notify - notify hot plug detection events
1180
+ * @bridge: bridge control structure
1181
+ * @status: output connection status
1182
+ *
1183
+ * Bridge drivers shall call this function to report hot plug events when they
1184
+ * detect a change in the output status, when hot plug detection has been
1185
+ * enabled by drm_bridge_hpd_enable().
1186
+ *
1187
+ * This function shall be called in a context that can sleep.
1188
+ */
1189
+void drm_bridge_hpd_notify(struct drm_bridge *bridge,
1190
+ enum drm_connector_status status)
1191
+{
1192
+ mutex_lock(&bridge->hpd_mutex);
1193
+ if (bridge->hpd_cb)
1194
+ bridge->hpd_cb(bridge->hpd_data, status);
1195
+ mutex_unlock(&bridge->hpd_mutex);
1196
+}
1197
+EXPORT_SYMBOL_GPL(drm_bridge_hpd_notify);
3501198
3511199 #ifdef CONFIG_OF
3521200 /**