xref: /linux/drivers/gpu/drm/i915/display/intel_encoder.c (revision 4b132aacb0768ac1e652cf517097ea6f237214b9)
1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright © 2024 Intel Corporation
4  */
5 
6 #include <linux/workqueue.h>
7 
8 #include "i915_drv.h"
9 
10 #include "intel_display_types.h"
11 #include "intel_encoder.h"
12 
13 static void intel_encoder_link_check_work_fn(struct work_struct *work)
14 {
15 	struct intel_encoder *encoder =
16 		container_of(work, typeof(*encoder), link_check_work.work);
17 
18 	encoder->link_check(encoder);
19 }
20 
21 void intel_encoder_link_check_init(struct intel_encoder *encoder,
22 				   void (*callback)(struct intel_encoder *encoder))
23 {
24 	INIT_DELAYED_WORK(&encoder->link_check_work, intel_encoder_link_check_work_fn);
25 	encoder->link_check = callback;
26 }
27 
28 void intel_encoder_link_check_flush_work(struct intel_encoder *encoder)
29 {
30 	cancel_delayed_work_sync(&encoder->link_check_work);
31 }
32 
33 void intel_encoder_link_check_queue_work(struct intel_encoder *encoder, int delay_ms)
34 {
35 	struct drm_i915_private *i915 = to_i915(encoder->base.dev);
36 
37 	mod_delayed_work(i915->unordered_wq,
38 			 &encoder->link_check_work, msecs_to_jiffies(delay_ms));
39 }
40 
41 void intel_encoder_suspend_all(struct intel_display *display)
42 {
43 	struct intel_encoder *encoder;
44 
45 	if (!HAS_DISPLAY(display))
46 		return;
47 
48 	/*
49 	 * TODO: check and remove holding the modeset locks if none of
50 	 * the encoders depends on this.
51 	 */
52 	drm_modeset_lock_all(display->drm);
53 	for_each_intel_encoder(display->drm, encoder)
54 		if (encoder->suspend)
55 			encoder->suspend(encoder);
56 	drm_modeset_unlock_all(display->drm);
57 
58 	for_each_intel_encoder(display->drm, encoder)
59 		if (encoder->suspend_complete)
60 			encoder->suspend_complete(encoder);
61 }
62 
63 void intel_encoder_shutdown_all(struct intel_display *display)
64 {
65 	struct intel_encoder *encoder;
66 
67 	if (!HAS_DISPLAY(display))
68 		return;
69 
70 	/*
71 	 * TODO: check and remove holding the modeset locks if none of
72 	 * the encoders depends on this.
73 	 */
74 	drm_modeset_lock_all(display->drm);
75 	for_each_intel_encoder(display->drm, encoder)
76 		if (encoder->shutdown)
77 			encoder->shutdown(encoder);
78 	drm_modeset_unlock_all(display->drm);
79 
80 	for_each_intel_encoder(display->drm, encoder)
81 		if (encoder->shutdown_complete)
82 			encoder->shutdown_complete(encoder);
83 }
84