1a1b63119SJosé Roberto de Souza // SPDX-License-Identifier: MIT
2a1b63119SJosé Roberto de Souza /*
3a1b63119SJosé Roberto de Souza * Copyright © 2021 Intel Corporation
4a1b63119SJosé Roberto de Souza */
5a1b63119SJosé Roberto de Souza
6a1b63119SJosé Roberto de Souza #include "i915_drv.h"
7801543b2SJani Nikula #include "i915_reg.h"
8a1b63119SJosé Roberto de Souza #include "intel_atomic.h"
9a1b63119SJosé Roberto de Souza #include "intel_de.h"
10a1b63119SJosé Roberto de Souza #include "intel_display_types.h"
11a1b63119SJosé Roberto de Souza #include "intel_drrs.h"
12a1b63119SJosé Roberto de Souza #include "intel_panel.h"
13a1b63119SJosé Roberto de Souza
14a1b63119SJosé Roberto de Souza /**
15a1b63119SJosé Roberto de Souza * DOC: Display Refresh Rate Switching (DRRS)
16a1b63119SJosé Roberto de Souza *
17a1b63119SJosé Roberto de Souza * Display Refresh Rate Switching (DRRS) is a power conservation feature
18a1b63119SJosé Roberto de Souza * which enables swtching between low and high refresh rates,
19a1b63119SJosé Roberto de Souza * dynamically, based on the usage scenario. This feature is applicable
20a1b63119SJosé Roberto de Souza * for internal panels.
21a1b63119SJosé Roberto de Souza *
22a1b63119SJosé Roberto de Souza * Indication that the panel supports DRRS is given by the panel EDID, which
23a1b63119SJosé Roberto de Souza * would list multiple refresh rates for one resolution.
24a1b63119SJosé Roberto de Souza *
25a1b63119SJosé Roberto de Souza * DRRS is of 2 types - static and seamless.
26a1b63119SJosé Roberto de Souza * Static DRRS involves changing refresh rate (RR) by doing a full modeset
27a1b63119SJosé Roberto de Souza * (may appear as a blink on screen) and is used in dock-undock scenario.
28a1b63119SJosé Roberto de Souza * Seamless DRRS involves changing RR without any visual effect to the user
29a1b63119SJosé Roberto de Souza * and can be used during normal system usage. This is done by programming
30a1b63119SJosé Roberto de Souza * certain registers.
31a1b63119SJosé Roberto de Souza *
32a1b63119SJosé Roberto de Souza * Support for static/seamless DRRS may be indicated in the VBT based on
33a1b63119SJosé Roberto de Souza * inputs from the panel spec.
34a1b63119SJosé Roberto de Souza *
35a1b63119SJosé Roberto de Souza * DRRS saves power by switching to low RR based on usage scenarios.
36a1b63119SJosé Roberto de Souza *
37a1b63119SJosé Roberto de Souza * The implementation is based on frontbuffer tracking implementation. When
38a1b63119SJosé Roberto de Souza * there is a disturbance on the screen triggered by user activity or a periodic
39a1b63119SJosé Roberto de Souza * system activity, DRRS is disabled (RR is changed to high RR). When there is
40a1b63119SJosé Roberto de Souza * no movement on screen, after a timeout of 1 second, a switch to low RR is
41a1b63119SJosé Roberto de Souza * made.
42a1b63119SJosé Roberto de Souza *
433a3dd534SJosé Roberto de Souza * For integration with frontbuffer tracking code, intel_drrs_invalidate()
443a3dd534SJosé Roberto de Souza * and intel_drrs_flush() are called.
45a1b63119SJosé Roberto de Souza *
46a1b63119SJosé Roberto de Souza * DRRS can be further extended to support other internal panels and also
47a1b63119SJosé Roberto de Souza * the scenario of video playback wherein RR is set based on the rate
48a1b63119SJosé Roberto de Souza * requested by userspace.
49a1b63119SJosé Roberto de Souza */
50a1b63119SJosé Roberto de Souza
intel_drrs_type_str(enum drrs_type drrs_type)51a1b952d4SVille Syrjälä const char *intel_drrs_type_str(enum drrs_type drrs_type)
52a1b952d4SVille Syrjälä {
53a1b952d4SVille Syrjälä static const char * const str[] = {
54a1b952d4SVille Syrjälä [DRRS_TYPE_NONE] = "none",
55a1b952d4SVille Syrjälä [DRRS_TYPE_STATIC] = "static",
56a1b952d4SVille Syrjälä [DRRS_TYPE_SEAMLESS] = "seamless",
57a1b952d4SVille Syrjälä };
58a1b952d4SVille Syrjälä
59a1b952d4SVille Syrjälä if (drrs_type >= ARRAY_SIZE(str))
60a1b952d4SVille Syrjälä return "<invalid>";
61a1b952d4SVille Syrjälä
62a1b952d4SVille Syrjälä return str[drrs_type];
63a1b952d4SVille Syrjälä }
64a1b952d4SVille Syrjälä
6514683babSVille Syrjälä static void
intel_drrs_set_refresh_rate_pipeconf(struct intel_crtc * crtc,enum drrs_refresh_rate refresh_rate)66851f15feSVille Syrjälä intel_drrs_set_refresh_rate_pipeconf(struct intel_crtc *crtc,
675a220c53SVille Syrjälä enum drrs_refresh_rate refresh_rate)
6814683babSVille Syrjälä {
6914683babSVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
70851f15feSVille Syrjälä enum transcoder cpu_transcoder = crtc->drrs.cpu_transcoder;
7159ea2887SAndrzej Hajda u32 bit;
7214683babSVille Syrjälä
7314683babSVille Syrjälä if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
74*3eb08ea5SVille Syrjälä bit = TRANSCONF_REFRESH_RATE_ALT_VLV;
7514683babSVille Syrjälä else
76*3eb08ea5SVille Syrjälä bit = TRANSCONF_REFRESH_RATE_ALT_ILK;
7714683babSVille Syrjälä
78*3eb08ea5SVille Syrjälä intel_de_rmw(dev_priv, TRANSCONF(cpu_transcoder),
7959ea2887SAndrzej Hajda bit, refresh_rate == DRRS_REFRESH_RATE_LOW ? bit : 0);
8014683babSVille Syrjälä }
8114683babSVille Syrjälä
8214683babSVille Syrjälä static void
intel_drrs_set_refresh_rate_m_n(struct intel_crtc * crtc,enum drrs_refresh_rate refresh_rate)83851f15feSVille Syrjälä intel_drrs_set_refresh_rate_m_n(struct intel_crtc *crtc,
845a220c53SVille Syrjälä enum drrs_refresh_rate refresh_rate)
8514683babSVille Syrjälä {
86851f15feSVille Syrjälä intel_cpu_transcoder_set_m1_n1(crtc, crtc->drrs.cpu_transcoder,
875a220c53SVille Syrjälä refresh_rate == DRRS_REFRESH_RATE_LOW ?
88851f15feSVille Syrjälä &crtc->drrs.m2_n2 : &crtc->drrs.m_n);
8914683babSVille Syrjälä }
9014683babSVille Syrjälä
intel_drrs_is_active(struct intel_crtc * crtc)9154903c7aSVille Syrjälä bool intel_drrs_is_active(struct intel_crtc *crtc)
92a1b63119SJosé Roberto de Souza {
93851f15feSVille Syrjälä return crtc->drrs.cpu_transcoder != INVALID_TRANSCODER;
94a1b63119SJosé Roberto de Souza }
95a1b63119SJosé Roberto de Souza
intel_drrs_set_state(struct intel_crtc * crtc,enum drrs_refresh_rate refresh_rate)96851f15feSVille Syrjälä static void intel_drrs_set_state(struct intel_crtc *crtc,
97851f15feSVille Syrjälä enum drrs_refresh_rate refresh_rate)
98a1b63119SJosé Roberto de Souza {
99ba770ce3SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
100a1b63119SJosé Roberto de Souza
101851f15feSVille Syrjälä if (refresh_rate == crtc->drrs.refresh_rate)
102851f15feSVille Syrjälä return;
103851f15feSVille Syrjälä
104c2f12155SVille Syrjälä if (intel_cpu_transcoder_has_m2_n2(dev_priv, crtc->drrs.cpu_transcoder))
105851f15feSVille Syrjälä intel_drrs_set_refresh_rate_pipeconf(crtc, refresh_rate);
106c2f12155SVille Syrjälä else
107c2f12155SVille Syrjälä intel_drrs_set_refresh_rate_m_n(crtc, refresh_rate);
108851f15feSVille Syrjälä
109851f15feSVille Syrjälä crtc->drrs.refresh_rate = refresh_rate;
110a1b63119SJosé Roberto de Souza }
111a1b63119SJosé Roberto de Souza
intel_drrs_schedule_work(struct intel_crtc * crtc)1121c004047SVille Syrjälä static void intel_drrs_schedule_work(struct intel_crtc *crtc)
1131c004047SVille Syrjälä {
1141c004047SVille Syrjälä struct drm_i915_private *i915 = to_i915(crtc->base.dev);
1151c004047SVille Syrjälä
1161c004047SVille Syrjälä mod_delayed_work(i915->unordered_wq, &crtc->drrs.work, msecs_to_jiffies(1000));
11770e10a2bSVille Syrjälä }
11870e10a2bSVille Syrjälä
intel_drrs_frontbuffer_bits(const struct intel_crtc_state * crtc_state)11970e10a2bSVille Syrjälä static unsigned int intel_drrs_frontbuffer_bits(const struct intel_crtc_state *crtc_state)
120579899c7SVille Syrjälä {
121579899c7SVille Syrjälä struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
12270e10a2bSVille Syrjälä struct drm_i915_private *i915 = to_i915(crtc->base.dev);
123579899c7SVille Syrjälä unsigned int frontbuffer_bits;
124579899c7SVille Syrjälä
125579899c7SVille Syrjälä frontbuffer_bits = INTEL_FRONTBUFFER_ALL_MASK(crtc->pipe);
126579899c7SVille Syrjälä
127579899c7SVille Syrjälä for_each_intel_crtc_in_pipe_mask(&i915->drm, crtc,
128579899c7SVille Syrjälä crtc_state->bigjoiner_pipes)
129579899c7SVille Syrjälä frontbuffer_bits |= INTEL_FRONTBUFFER_ALL_MASK(crtc->pipe);
13070e10a2bSVille Syrjälä
13170e10a2bSVille Syrjälä return frontbuffer_bits;
132a1b63119SJosé Roberto de Souza }
13354903c7aSVille Syrjälä
13454903c7aSVille Syrjälä /**
135a1b63119SJosé Roberto de Souza * intel_drrs_activate - activate DRRS
13654903c7aSVille Syrjälä * @crtc_state: the crtc state
137a1b63119SJosé Roberto de Souza *
13854903c7aSVille Syrjälä * Activates DRRS on the crtc.
139a1b63119SJosé Roberto de Souza */
intel_drrs_activate(const struct intel_crtc_state * crtc_state)140ba770ce3SVille Syrjälä void intel_drrs_activate(const struct intel_crtc_state *crtc_state)
141a1b63119SJosé Roberto de Souza {
142a1b63119SJosé Roberto de Souza struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
143a1b63119SJosé Roberto de Souza
144a1b63119SJosé Roberto de Souza if (!crtc_state->has_drrs)
1451b333c67SVille Syrjälä return;
1461b333c67SVille Syrjälä
147a1b63119SJosé Roberto de Souza if (!crtc_state->hw.active)
148579899c7SVille Syrjälä return;
149579899c7SVille Syrjälä
150579899c7SVille Syrjälä if (intel_crtc_is_bigjoiner_slave(crtc_state))
151851f15feSVille Syrjälä return;
152a1b63119SJosé Roberto de Souza
153851f15feSVille Syrjälä mutex_lock(&crtc->drrs.mutex);
154851f15feSVille Syrjälä
155851f15feSVille Syrjälä crtc->drrs.cpu_transcoder = crtc_state->cpu_transcoder;
15670e10a2bSVille Syrjälä crtc->drrs.m_n = crtc_state->dp_m_n;
157851f15feSVille Syrjälä crtc->drrs.m2_n2 = crtc_state->dp_m2_n2;
158a1b63119SJosé Roberto de Souza crtc->drrs.frontbuffer_bits = intel_drrs_frontbuffer_bits(crtc_state);
1591c004047SVille Syrjälä crtc->drrs.busy_frontbuffer_bits = 0;
1601c004047SVille Syrjälä
161851f15feSVille Syrjälä intel_drrs_schedule_work(crtc);
162a1b63119SJosé Roberto de Souza
163a1b63119SJosé Roberto de Souza mutex_unlock(&crtc->drrs.mutex);
164a1b63119SJosé Roberto de Souza }
16554903c7aSVille Syrjälä
16654903c7aSVille Syrjälä /**
16754903c7aSVille Syrjälä * intel_drrs_deactivate - deactivate DRRS
16854903c7aSVille Syrjälä * @old_crtc_state: the old crtc state
169a1b63119SJosé Roberto de Souza *
17054903c7aSVille Syrjälä * Deactivates DRRS on the crtc.
171a1b63119SJosé Roberto de Souza */
intel_drrs_deactivate(const struct intel_crtc_state * old_crtc_state)172ba770ce3SVille Syrjälä void intel_drrs_deactivate(const struct intel_crtc_state *old_crtc_state)
173a1b63119SJosé Roberto de Souza {
174a1b63119SJosé Roberto de Souza struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
175a1b63119SJosé Roberto de Souza
176a1b63119SJosé Roberto de Souza if (!old_crtc_state->has_drrs)
1771b333c67SVille Syrjälä return;
1781b333c67SVille Syrjälä
179a1b63119SJosé Roberto de Souza if (!old_crtc_state->hw.active)
180579899c7SVille Syrjälä return;
181579899c7SVille Syrjälä
182579899c7SVille Syrjälä if (intel_crtc_is_bigjoiner_slave(old_crtc_state))
183851f15feSVille Syrjälä return;
184a1b63119SJosé Roberto de Souza
18554903c7aSVille Syrjälä mutex_lock(&crtc->drrs.mutex);
186851f15feSVille Syrjälä
187851f15feSVille Syrjälä if (intel_drrs_is_active(crtc))
188851f15feSVille Syrjälä intel_drrs_set_state(crtc, DRRS_REFRESH_RATE_HIGH);
18970e10a2bSVille Syrjälä
190851f15feSVille Syrjälä crtc->drrs.cpu_transcoder = INVALID_TRANSCODER;
191851f15feSVille Syrjälä crtc->drrs.frontbuffer_bits = 0;
192851f15feSVille Syrjälä crtc->drrs.busy_frontbuffer_bits = 0;
193851f15feSVille Syrjälä
194851f15feSVille Syrjälä mutex_unlock(&crtc->drrs.mutex);
195a1b63119SJosé Roberto de Souza
196a1b63119SJosé Roberto de Souza cancel_delayed_work_sync(&crtc->drrs.work);
1973a3dd534SJosé Roberto de Souza }
198a1b63119SJosé Roberto de Souza
intel_drrs_downclock_work(struct work_struct * work)199851f15feSVille Syrjälä static void intel_drrs_downclock_work(struct work_struct *work)
200a1b63119SJosé Roberto de Souza {
201851f15feSVille Syrjälä struct intel_crtc *crtc = container_of(work, typeof(*crtc), drrs.work.work);
202a1b63119SJosé Roberto de Souza
20354903c7aSVille Syrjälä mutex_lock(&crtc->drrs.mutex);
204851f15feSVille Syrjälä
205a1b63119SJosé Roberto de Souza if (intel_drrs_is_active(crtc) && !crtc->drrs.busy_frontbuffer_bits)
206851f15feSVille Syrjälä intel_drrs_set_state(crtc, DRRS_REFRESH_RATE_LOW);
207a1b63119SJosé Roberto de Souza
208a1b63119SJosé Roberto de Souza mutex_unlock(&crtc->drrs.mutex);
2096bd58b70SJosé Roberto de Souza }
21018f23b92SVille Syrjälä
intel_drrs_frontbuffer_update(struct drm_i915_private * dev_priv,unsigned int all_frontbuffer_bits,bool invalidate)2116bd58b70SJosé Roberto de Souza static void intel_drrs_frontbuffer_update(struct drm_i915_private *dev_priv,
212a1b63119SJosé Roberto de Souza unsigned int all_frontbuffer_bits,
213ba770ce3SVille Syrjälä bool invalidate)
214a1b63119SJosé Roberto de Souza {
215851f15feSVille Syrjälä struct intel_crtc *crtc;
21618f23b92SVille Syrjälä
21718f23b92SVille Syrjälä for_each_intel_crtc(&dev_priv->drm, crtc) {
218851f15feSVille Syrjälä unsigned int frontbuffer_bits;
219a1b63119SJosé Roberto de Souza
220fb4ae6e6SVille Syrjälä mutex_lock(&crtc->drrs.mutex);
221fb4ae6e6SVille Syrjälä
222851f15feSVille Syrjälä frontbuffer_bits = all_frontbuffer_bits & crtc->drrs.frontbuffer_bits;
223851f15feSVille Syrjälä if (!frontbuffer_bits) {
224a1b63119SJosé Roberto de Souza mutex_unlock(&crtc->drrs.mutex);
225a1b63119SJosé Roberto de Souza continue;
2266bd58b70SJosé Roberto de Souza }
227851f15feSVille Syrjälä
2286bd58b70SJosé Roberto de Souza if (invalidate)
229851f15feSVille Syrjälä crtc->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
230a1b63119SJosé Roberto de Souza else
2316bd58b70SJosé Roberto de Souza crtc->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
232851f15feSVille Syrjälä
233a1b63119SJosé Roberto de Souza /* flush/invalidate means busy screen hence upclock */
2346bd58b70SJosé Roberto de Souza intel_drrs_set_state(crtc, DRRS_REFRESH_RATE_HIGH);
2356bd58b70SJosé Roberto de Souza
2366bd58b70SJosé Roberto de Souza /*
2376bd58b70SJosé Roberto de Souza * flush also means no more activity hence schedule downclock, if all
238fb4ae6e6SVille Syrjälä * other fbs are quiescent too
2391c004047SVille Syrjälä */
240fb4ae6e6SVille Syrjälä if (!crtc->drrs.busy_frontbuffer_bits)
241fb4ae6e6SVille Syrjälä intel_drrs_schedule_work(crtc);
242851f15feSVille Syrjälä else
243851f15feSVille Syrjälä cancel_delayed_work(&crtc->drrs.work);
244851f15feSVille Syrjälä
245a1b63119SJosé Roberto de Souza mutex_unlock(&crtc->drrs.mutex);
246a1b63119SJosé Roberto de Souza }
247a1b63119SJosé Roberto de Souza }
2486bd58b70SJosé Roberto de Souza
2496bd58b70SJosé Roberto de Souza /**
2506bd58b70SJosé Roberto de Souza * intel_drrs_invalidate - Disable Idleness DRRS
2516bd58b70SJosé Roberto de Souza * @dev_priv: i915 device
2526bd58b70SJosé Roberto de Souza * @frontbuffer_bits: frontbuffer plane tracking bits
2536bd58b70SJosé Roberto de Souza *
2546bd58b70SJosé Roberto de Souza * This function gets called everytime rendering on the given planes start.
2556bd58b70SJosé Roberto de Souza * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
2566bd58b70SJosé Roberto de Souza *
2576bd58b70SJosé Roberto de Souza * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
2586bd58b70SJosé Roberto de Souza */
intel_drrs_invalidate(struct drm_i915_private * dev_priv,unsigned int frontbuffer_bits)2596bd58b70SJosé Roberto de Souza void intel_drrs_invalidate(struct drm_i915_private *dev_priv,
2606bd58b70SJosé Roberto de Souza unsigned int frontbuffer_bits)
2616bd58b70SJosé Roberto de Souza {
2626bd58b70SJosé Roberto de Souza intel_drrs_frontbuffer_update(dev_priv, frontbuffer_bits, true);
2636bd58b70SJosé Roberto de Souza }
2643a3dd534SJosé Roberto de Souza
265a1b63119SJosé Roberto de Souza /**
266a1b63119SJosé Roberto de Souza * intel_drrs_flush - Restart Idleness DRRS
267a1b63119SJosé Roberto de Souza * @dev_priv: i915 device
268a1b63119SJosé Roberto de Souza * @frontbuffer_bits: frontbuffer plane tracking bits
269a1b63119SJosé Roberto de Souza *
270a1b63119SJosé Roberto de Souza * This function gets called every time rendering on the given planes has
271a1b63119SJosé Roberto de Souza * completed or flip on a crtc is completed. So DRRS should be upclocked
272a1b63119SJosé Roberto de Souza * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
273a1b63119SJosé Roberto de Souza * if no other planes are dirty.
274a1b63119SJosé Roberto de Souza *
2753a3dd534SJosé Roberto de Souza * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
276a1b63119SJosé Roberto de Souza */
intel_drrs_flush(struct drm_i915_private * dev_priv,unsigned int frontbuffer_bits)277a1b63119SJosé Roberto de Souza void intel_drrs_flush(struct drm_i915_private *dev_priv,
2786bd58b70SJosé Roberto de Souza unsigned int frontbuffer_bits)
279a1b63119SJosé Roberto de Souza {
280a1b63119SJosé Roberto de Souza intel_drrs_frontbuffer_update(dev_priv, frontbuffer_bits, false);
281a1b63119SJosé Roberto de Souza }
282a2b1d9ecSVille Syrjälä
283851f15feSVille Syrjälä /**
284a1b63119SJosé Roberto de Souza * intel_drrs_crtc_init - Init DRRS for CRTC
285a1b63119SJosé Roberto de Souza * @crtc: crtc
286a1b63119SJosé Roberto de Souza *
287a1b63119SJosé Roberto de Souza * This function is called only once at driver load to initialize basic
288851f15feSVille Syrjälä * DRRS stuff.
289a2b1d9ecSVille Syrjälä *
290851f15feSVille Syrjälä */
intel_drrs_crtc_init(struct intel_crtc * crtc)291851f15feSVille Syrjälä void intel_drrs_crtc_init(struct intel_crtc *crtc)
292851f15feSVille Syrjälä {
293851f15feSVille Syrjälä INIT_DELAYED_WORK(&crtc->drrs.work, intel_drrs_downclock_work);
294851f15feSVille Syrjälä mutex_init(&crtc->drrs.mutex);
29561564e6cSVille Syrjälä crtc->drrs.cpu_transcoder = INVALID_TRANSCODER;
29661564e6cSVille Syrjälä }
29761564e6cSVille Syrjälä
intel_drrs_debugfs_status_show(struct seq_file * m,void * unused)298adc831bfSVille Syrjälä static int intel_drrs_debugfs_status_show(struct seq_file *m, void *unused)
2999519c865SVille Syrjälä {
3009519c865SVille Syrjälä struct intel_crtc *crtc = m->private;
3019519c865SVille Syrjälä const struct intel_crtc_state *crtc_state;
3029519c865SVille Syrjälä int ret;
3039519c865SVille Syrjälä
3049519c865SVille Syrjälä ret = drm_modeset_lock_single_interruptible(&crtc->base.mutex);
3059519c865SVille Syrjälä if (ret)
3069519c865SVille Syrjälä return ret;
30761564e6cSVille Syrjälä
30861564e6cSVille Syrjälä crtc_state = to_intel_crtc_state(crtc->base.state);
30961564e6cSVille Syrjälä
310adc831bfSVille Syrjälä mutex_lock(&crtc->drrs.mutex);
31161564e6cSVille Syrjälä
31261564e6cSVille Syrjälä seq_printf(m, "DRRS enabled: %s\n",
313adc831bfSVille Syrjälä str_yes_no(crtc_state->has_drrs));
31461564e6cSVille Syrjälä
31561564e6cSVille Syrjälä seq_printf(m, "DRRS active: %s\n",
316adc831bfSVille Syrjälä str_yes_no(intel_drrs_is_active(crtc)));
31761564e6cSVille Syrjälä
31861564e6cSVille Syrjälä seq_printf(m, "DRRS refresh rate: %s\n",
31961564e6cSVille Syrjälä crtc->drrs.refresh_rate == DRRS_REFRESH_RATE_LOW ?
320adc831bfSVille Syrjälä "low" : "high");
3212e25c1fbSVille Syrjälä
3222e25c1fbSVille Syrjälä seq_printf(m, "DRRS busy frontbuffer bits: 0x%x\n",
32361564e6cSVille Syrjälä crtc->drrs.busy_frontbuffer_bits);
32461564e6cSVille Syrjälä
3259519c865SVille Syrjälä mutex_unlock(&crtc->drrs.mutex);
3269519c865SVille Syrjälä
32761564e6cSVille Syrjälä drm_modeset_unlock(&crtc->base.mutex);
32861564e6cSVille Syrjälä
32961564e6cSVille Syrjälä return 0;
33061564e6cSVille Syrjälä }
33161564e6cSVille Syrjälä
33261564e6cSVille Syrjälä DEFINE_SHOW_ATTRIBUTE(intel_drrs_debugfs_status);
33361564e6cSVille Syrjälä
intel_drrs_debugfs_ctl_set(void * data,u64 val)334adc831bfSVille Syrjälä static int intel_drrs_debugfs_ctl_set(void *data, u64 val)
335adc831bfSVille Syrjälä {
33661564e6cSVille Syrjälä struct intel_crtc *crtc = data;
33761564e6cSVille Syrjälä struct drm_i915_private *i915 = to_i915(crtc->base.dev);
33861564e6cSVille Syrjälä struct intel_crtc_state *crtc_state;
33961564e6cSVille Syrjälä struct drm_crtc_commit *commit;
34061564e6cSVille Syrjälä int ret;
34161564e6cSVille Syrjälä
34261564e6cSVille Syrjälä ret = drm_modeset_lock_single_interruptible(&crtc->base.mutex);
34361564e6cSVille Syrjälä if (ret)
34461564e6cSVille Syrjälä return ret;
34561564e6cSVille Syrjälä
34661564e6cSVille Syrjälä crtc_state = to_intel_crtc_state(crtc->base.state);
34761564e6cSVille Syrjälä
34861564e6cSVille Syrjälä if (!crtc_state->hw.active ||
34961564e6cSVille Syrjälä !crtc_state->has_drrs)
35061564e6cSVille Syrjälä goto out;
35161564e6cSVille Syrjälä
35261564e6cSVille Syrjälä commit = crtc_state->uapi.commit;
35361564e6cSVille Syrjälä if (commit) {
35461564e6cSVille Syrjälä ret = wait_for_completion_interruptible(&commit->hw_done);
35561564e6cSVille Syrjälä if (ret)
35661564e6cSVille Syrjälä goto out;
35761564e6cSVille Syrjälä }
35861564e6cSVille Syrjälä
35961564e6cSVille Syrjälä drm_dbg(&i915->drm,
36061564e6cSVille Syrjälä "Manually %sactivating DRRS\n", val ? "" : "de");
36161564e6cSVille Syrjälä
36261564e6cSVille Syrjälä if (val)
36361564e6cSVille Syrjälä intel_drrs_activate(crtc_state);
36461564e6cSVille Syrjälä else
36561564e6cSVille Syrjälä intel_drrs_deactivate(crtc_state);
36661564e6cSVille Syrjälä
36761564e6cSVille Syrjälä out:
368adc831bfSVille Syrjälä drm_modeset_unlock(&crtc->base.mutex);
36961564e6cSVille Syrjälä
37061564e6cSVille Syrjälä return ret;
37140a7463cSDeepak R Varma }
37261564e6cSVille Syrjälä
37361564e6cSVille Syrjälä DEFINE_DEBUGFS_ATTRIBUTE(intel_drrs_debugfs_ctl_fops,
374adc831bfSVille Syrjälä NULL, intel_drrs_debugfs_ctl_set, "%llu\n");
37561564e6cSVille Syrjälä
intel_drrs_crtc_debugfs_add(struct intel_crtc * crtc)376adc831bfSVille Syrjälä void intel_drrs_crtc_debugfs_add(struct intel_crtc *crtc)
377adc831bfSVille Syrjälä {
37861564e6cSVille Syrjälä debugfs_create_file("i915_drrs_status", 0444, crtc->base.debugfs_entry,
37940a7463cSDeepak R Varma crtc, &intel_drrs_debugfs_status_fops);
380adc831bfSVille Syrjälä
381adc831bfSVille Syrjälä debugfs_create_file_unsafe("i915_drrs_ctl", 0644, crtc->base.debugfs_entry,
38261564e6cSVille Syrjälä crtc, &intel_drrs_debugfs_ctl_fops);
383adc831bfSVille Syrjälä }
384adc831bfSVille Syrjälä
intel_drrs_debugfs_type_show(struct seq_file * m,void * unused)385adc831bfSVille Syrjälä static int intel_drrs_debugfs_type_show(struct seq_file *m, void *unused)
386adc831bfSVille Syrjälä {
387adc831bfSVille Syrjälä struct intel_connector *connector = m->private;
388adc831bfSVille Syrjälä
389adc831bfSVille Syrjälä seq_printf(m, "DRRS type: %s\n",
390adc831bfSVille Syrjälä intel_drrs_type_str(intel_panel_drrs_type(connector)));
391adc831bfSVille Syrjälä
392adc831bfSVille Syrjälä return 0;
393adc831bfSVille Syrjälä }
394adc831bfSVille Syrjälä
395adc831bfSVille Syrjälä DEFINE_SHOW_ATTRIBUTE(intel_drrs_debugfs_type);
396adc831bfSVille Syrjälä
intel_drrs_connector_debugfs_add(struct intel_connector * connector)397adc831bfSVille Syrjälä void intel_drrs_connector_debugfs_add(struct intel_connector *connector)
398adc831bfSVille Syrjälä {
399adc831bfSVille Syrjälä if (intel_panel_drrs_type(connector) == DRRS_TYPE_NONE)
400adc831bfSVille Syrjälä return;
401adc831bfSVille Syrjälä
40261564e6cSVille Syrjälä debugfs_create_file("i915_drrs_type", 0444, connector->base.debugfs_entry,
403 connector, &intel_drrs_debugfs_type_fops);
404 }
405