blob: 56bb34d043326c084956a6eb2008504da0276ead [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001// SPDX-License-Identifier: GPL-2.0-only
2/**************************************************************************
3 * Copyright (c) 2007, Intel Corporation.
4 * All Rights Reserved.
5 *
6 * Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
7 * develop this driver.
8 *
9 **************************************************************************/
10
11#include <drm/drm_vblank.h>
12
13#include "mdfld_output.h"
14#include "power.h"
15#include "psb_drv.h"
16#include "psb_intel_reg.h"
17#include "psb_irq.h"
18#include "psb_reg.h"
19
20/*
21 * inline functions
22 */
23
24static inline u32
25psb_pipestat(int pipe)
26{
27 if (pipe == 0)
28 return PIPEASTAT;
29 if (pipe == 1)
30 return PIPEBSTAT;
31 if (pipe == 2)
32 return PIPECSTAT;
33 BUG();
34}
35
36static inline u32
37mid_pipe_event(int pipe)
38{
39 if (pipe == 0)
40 return _PSB_PIPEA_EVENT_FLAG;
41 if (pipe == 1)
42 return _MDFLD_PIPEB_EVENT_FLAG;
43 if (pipe == 2)
44 return _MDFLD_PIPEC_EVENT_FLAG;
45 BUG();
46}
47
48static inline u32
49mid_pipe_vsync(int pipe)
50{
51 if (pipe == 0)
52 return _PSB_VSYNC_PIPEA_FLAG;
53 if (pipe == 1)
54 return _PSB_VSYNC_PIPEB_FLAG;
55 if (pipe == 2)
56 return _MDFLD_PIPEC_VBLANK_FLAG;
57 BUG();
58}
59
60static inline u32
61mid_pipeconf(int pipe)
62{
63 if (pipe == 0)
64 return PIPEACONF;
65 if (pipe == 1)
66 return PIPEBCONF;
67 if (pipe == 2)
68 return PIPECCONF;
69 BUG();
70}
71
72void
73psb_enable_pipestat(struct drm_psb_private *dev_priv, int pipe, u32 mask)
74{
75 if ((dev_priv->pipestat[pipe] & mask) != mask) {
76 u32 reg = psb_pipestat(pipe);
77 dev_priv->pipestat[pipe] |= mask;
78 /* Enable the interrupt, clear any pending status */
79 if (gma_power_begin(dev_priv->dev, false)) {
80 u32 writeVal = PSB_RVDC32(reg);
81 writeVal |= (mask | (mask >> 16));
82 PSB_WVDC32(writeVal, reg);
83 (void) PSB_RVDC32(reg);
84 gma_power_end(dev_priv->dev);
85 }
86 }
87}
88
89void
90psb_disable_pipestat(struct drm_psb_private *dev_priv, int pipe, u32 mask)
91{
92 if ((dev_priv->pipestat[pipe] & mask) != 0) {
93 u32 reg = psb_pipestat(pipe);
94 dev_priv->pipestat[pipe] &= ~mask;
95 if (gma_power_begin(dev_priv->dev, false)) {
96 u32 writeVal = PSB_RVDC32(reg);
97 writeVal &= ~mask;
98 PSB_WVDC32(writeVal, reg);
99 (void) PSB_RVDC32(reg);
100 gma_power_end(dev_priv->dev);
101 }
102 }
103}
104
105static void mid_enable_pipe_event(struct drm_psb_private *dev_priv, int pipe)
106{
107 if (gma_power_begin(dev_priv->dev, false)) {
108 u32 pipe_event = mid_pipe_event(pipe);
109 dev_priv->vdc_irq_mask |= pipe_event;
110 PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R);
111 PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R);
112 gma_power_end(dev_priv->dev);
113 }
114}
115
116static void mid_disable_pipe_event(struct drm_psb_private *dev_priv, int pipe)
117{
118 if (dev_priv->pipestat[pipe] == 0) {
119 if (gma_power_begin(dev_priv->dev, false)) {
120 u32 pipe_event = mid_pipe_event(pipe);
121 dev_priv->vdc_irq_mask &= ~pipe_event;
122 PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R);
123 PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R);
124 gma_power_end(dev_priv->dev);
125 }
126 }
127}
128
129/**
130 * Display controller interrupt handler for pipe event.
131 *
132 */
133static void mid_pipe_event_handler(struct drm_device *dev, int pipe)
134{
135 struct drm_psb_private *dev_priv =
136 (struct drm_psb_private *) dev->dev_private;
137
138 uint32_t pipe_stat_val = 0;
139 uint32_t pipe_stat_reg = psb_pipestat(pipe);
140 uint32_t pipe_enable = dev_priv->pipestat[pipe];
141 uint32_t pipe_status = dev_priv->pipestat[pipe] >> 16;
142 uint32_t pipe_clear;
143 uint32_t i = 0;
144
145 spin_lock(&dev_priv->irqmask_lock);
146
147 pipe_stat_val = PSB_RVDC32(pipe_stat_reg);
148 pipe_stat_val &= pipe_enable | pipe_status;
149 pipe_stat_val &= pipe_stat_val >> 16;
150
151 spin_unlock(&dev_priv->irqmask_lock);
152
153 /* Clear the 2nd level interrupt status bits
154 * Sometimes the bits are very sticky so we repeat until they unstick */
155 for (i = 0; i < 0xffff; i++) {
156 PSB_WVDC32(PSB_RVDC32(pipe_stat_reg), pipe_stat_reg);
157 pipe_clear = PSB_RVDC32(pipe_stat_reg) & pipe_status;
158
159 if (pipe_clear == 0)
160 break;
161 }
162
163 if (pipe_clear)
164 dev_err(dev->dev,
165 "%s, can't clear status bits for pipe %d, its value = 0x%x.\n",
166 __func__, pipe, PSB_RVDC32(pipe_stat_reg));
167
168 if (pipe_stat_val & PIPE_VBLANK_STATUS)
169 drm_handle_vblank(dev, pipe);
170
171 if (pipe_stat_val & PIPE_TE_STATUS)
172 drm_handle_vblank(dev, pipe);
173}
174
175/*
176 * Display controller interrupt handler.
177 */
178static void psb_vdc_interrupt(struct drm_device *dev, uint32_t vdc_stat)
179{
180 if (vdc_stat & _PSB_IRQ_ASLE)
181 psb_intel_opregion_asle_intr(dev);
182
183 if (vdc_stat & _PSB_VSYNC_PIPEA_FLAG)
184 mid_pipe_event_handler(dev, 0);
185
186 if (vdc_stat & _PSB_VSYNC_PIPEB_FLAG)
187 mid_pipe_event_handler(dev, 1);
188}
189
190/*
191 * SGX interrupt handler
192 */
193static void psb_sgx_interrupt(struct drm_device *dev, u32 stat_1, u32 stat_2)
194{
195 struct drm_psb_private *dev_priv = dev->dev_private;
196 u32 val, addr;
197 int error = false;
198
199 if (stat_1 & _PSB_CE_TWOD_COMPLETE)
200 val = PSB_RSGX32(PSB_CR_2D_BLIT_STATUS);
201
202 if (stat_2 & _PSB_CE2_BIF_REQUESTER_FAULT) {
203 val = PSB_RSGX32(PSB_CR_BIF_INT_STAT);
204 addr = PSB_RSGX32(PSB_CR_BIF_FAULT);
205 if (val) {
206 if (val & _PSB_CBI_STAT_PF_N_RW)
207 DRM_ERROR("SGX MMU page fault:");
208 else
209 DRM_ERROR("SGX MMU read / write protection fault:");
210
211 if (val & _PSB_CBI_STAT_FAULT_CACHE)
212 DRM_ERROR("\tCache requestor");
213 if (val & _PSB_CBI_STAT_FAULT_TA)
214 DRM_ERROR("\tTA requestor");
215 if (val & _PSB_CBI_STAT_FAULT_VDM)
216 DRM_ERROR("\tVDM requestor");
217 if (val & _PSB_CBI_STAT_FAULT_2D)
218 DRM_ERROR("\t2D requestor");
219 if (val & _PSB_CBI_STAT_FAULT_PBE)
220 DRM_ERROR("\tPBE requestor");
221 if (val & _PSB_CBI_STAT_FAULT_TSP)
222 DRM_ERROR("\tTSP requestor");
223 if (val & _PSB_CBI_STAT_FAULT_ISP)
224 DRM_ERROR("\tISP requestor");
225 if (val & _PSB_CBI_STAT_FAULT_USSEPDS)
226 DRM_ERROR("\tUSSEPDS requestor");
227 if (val & _PSB_CBI_STAT_FAULT_HOST)
228 DRM_ERROR("\tHost requestor");
229
230 DRM_ERROR("\tMMU failing address is 0x%08x.\n",
231 (unsigned int)addr);
232 error = true;
233 }
234 }
235
236 /* Clear bits */
237 PSB_WSGX32(stat_1, PSB_CR_EVENT_HOST_CLEAR);
238 PSB_WSGX32(stat_2, PSB_CR_EVENT_HOST_CLEAR2);
239 PSB_RSGX32(PSB_CR_EVENT_HOST_CLEAR2);
240}
241
242irqreturn_t psb_irq_handler(int irq, void *arg)
243{
244 struct drm_device *dev = arg;
245 struct drm_psb_private *dev_priv = dev->dev_private;
246 uint32_t vdc_stat, dsp_int = 0, sgx_int = 0, hotplug_int = 0;
247 u32 sgx_stat_1, sgx_stat_2;
248 int handled = 0;
249
250 spin_lock(&dev_priv->irqmask_lock);
251
252 vdc_stat = PSB_RVDC32(PSB_INT_IDENTITY_R);
253
254 if (vdc_stat & (_PSB_PIPE_EVENT_FLAG|_PSB_IRQ_ASLE))
255 dsp_int = 1;
256
257 /* FIXME: Handle Medfield
258 if (vdc_stat & _MDFLD_DISP_ALL_IRQ_FLAG)
259 dsp_int = 1;
260 */
261
262 if (vdc_stat & _PSB_IRQ_SGX_FLAG)
263 sgx_int = 1;
264 if (vdc_stat & _PSB_IRQ_DISP_HOTSYNC)
265 hotplug_int = 1;
266
267 vdc_stat &= dev_priv->vdc_irq_mask;
268 spin_unlock(&dev_priv->irqmask_lock);
269
270 if (dsp_int && gma_power_is_on(dev)) {
271 psb_vdc_interrupt(dev, vdc_stat);
272 handled = 1;
273 }
274
275 if (sgx_int) {
276 sgx_stat_1 = PSB_RSGX32(PSB_CR_EVENT_STATUS);
277 sgx_stat_2 = PSB_RSGX32(PSB_CR_EVENT_STATUS2);
278 psb_sgx_interrupt(dev, sgx_stat_1, sgx_stat_2);
279 handled = 1;
280 }
281
282 /* Note: this bit has other meanings on some devices, so we will
283 need to address that later if it ever matters */
284 if (hotplug_int && dev_priv->ops->hotplug) {
285 handled = dev_priv->ops->hotplug(dev);
286 REG_WRITE(PORT_HOTPLUG_STAT, REG_READ(PORT_HOTPLUG_STAT));
287 }
288
289 PSB_WVDC32(vdc_stat, PSB_INT_IDENTITY_R);
290 (void) PSB_RVDC32(PSB_INT_IDENTITY_R);
291 rmb();
292
293 if (!handled)
294 return IRQ_NONE;
295
296 return IRQ_HANDLED;
297}
298
299void psb_irq_preinstall(struct drm_device *dev)
300{
301 struct drm_psb_private *dev_priv =
302 (struct drm_psb_private *) dev->dev_private;
303 unsigned long irqflags;
304
305 spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
306
307 if (gma_power_is_on(dev)) {
308 PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM);
309 PSB_WVDC32(0x00000000, PSB_INT_MASK_R);
310 PSB_WVDC32(0x00000000, PSB_INT_ENABLE_R);
311 PSB_WSGX32(0x00000000, PSB_CR_EVENT_HOST_ENABLE);
312 PSB_RSGX32(PSB_CR_EVENT_HOST_ENABLE);
313 }
314 if (dev->vblank[0].enabled)
315 dev_priv->vdc_irq_mask |= _PSB_VSYNC_PIPEA_FLAG;
316 if (dev->vblank[1].enabled)
317 dev_priv->vdc_irq_mask |= _PSB_VSYNC_PIPEB_FLAG;
318
319 /* FIXME: Handle Medfield irq mask
320 if (dev->vblank[1].enabled)
321 dev_priv->vdc_irq_mask |= _MDFLD_PIPEB_EVENT_FLAG;
322 if (dev->vblank[2].enabled)
323 dev_priv->vdc_irq_mask |= _MDFLD_PIPEC_EVENT_FLAG;
324 */
325
326 /* Revisit this area - want per device masks ? */
327 if (dev_priv->ops->hotplug)
328 dev_priv->vdc_irq_mask |= _PSB_IRQ_DISP_HOTSYNC;
329 dev_priv->vdc_irq_mask |= _PSB_IRQ_ASLE | _PSB_IRQ_SGX_FLAG;
330
331 /* This register is safe even if display island is off */
332 PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R);
333 spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
334}
335
336int psb_irq_postinstall(struct drm_device *dev)
337{
338 struct drm_psb_private *dev_priv = dev->dev_private;
339 unsigned long irqflags;
340 unsigned int i;
341
342 spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
343
344 /* Enable 2D and MMU fault interrupts */
345 PSB_WSGX32(_PSB_CE2_BIF_REQUESTER_FAULT, PSB_CR_EVENT_HOST_ENABLE2);
346 PSB_WSGX32(_PSB_CE_TWOD_COMPLETE, PSB_CR_EVENT_HOST_ENABLE);
347 PSB_RSGX32(PSB_CR_EVENT_HOST_ENABLE); /* Post */
348
349 /* This register is safe even if display island is off */
350 PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R);
351 PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM);
352
353 for (i = 0; i < dev->num_crtcs; ++i) {
354 if (dev->vblank[i].enabled)
355 psb_enable_pipestat(dev_priv, i, PIPE_VBLANK_INTERRUPT_ENABLE);
356 else
357 psb_disable_pipestat(dev_priv, i, PIPE_VBLANK_INTERRUPT_ENABLE);
358 }
359
360 if (dev_priv->ops->hotplug_enable)
361 dev_priv->ops->hotplug_enable(dev, true);
362
363 spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
364 return 0;
365}
366
367void psb_irq_uninstall(struct drm_device *dev)
368{
369 struct drm_psb_private *dev_priv = dev->dev_private;
370 unsigned long irqflags;
371 unsigned int i;
372
373 spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
374
375 if (dev_priv->ops->hotplug_enable)
376 dev_priv->ops->hotplug_enable(dev, false);
377
378 PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM);
379
380 for (i = 0; i < dev->num_crtcs; ++i) {
381 if (dev->vblank[i].enabled)
382 psb_disable_pipestat(dev_priv, i, PIPE_VBLANK_INTERRUPT_ENABLE);
383 }
384
385 dev_priv->vdc_irq_mask &= _PSB_IRQ_SGX_FLAG |
386 _PSB_IRQ_MSVDX_FLAG |
387 _LNC_IRQ_TOPAZ_FLAG;
388
389 /* These two registers are safe even if display island is off */
390 PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R);
391 PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R);
392
393 wmb();
394
395 /* This register is safe even if display island is off */
396 PSB_WVDC32(PSB_RVDC32(PSB_INT_IDENTITY_R), PSB_INT_IDENTITY_R);
397 spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
398}
399
400void psb_irq_turn_on_dpst(struct drm_device *dev)
401{
402 struct drm_psb_private *dev_priv =
403 (struct drm_psb_private *) dev->dev_private;
404 u32 hist_reg;
405 u32 pwm_reg;
406
407 if (gma_power_begin(dev, false)) {
408 PSB_WVDC32(1 << 31, HISTOGRAM_LOGIC_CONTROL);
409 hist_reg = PSB_RVDC32(HISTOGRAM_LOGIC_CONTROL);
410 PSB_WVDC32(1 << 31, HISTOGRAM_INT_CONTROL);
411 hist_reg = PSB_RVDC32(HISTOGRAM_INT_CONTROL);
412
413 PSB_WVDC32(0x80010100, PWM_CONTROL_LOGIC);
414 pwm_reg = PSB_RVDC32(PWM_CONTROL_LOGIC);
415 PSB_WVDC32(pwm_reg | PWM_PHASEIN_ENABLE
416 | PWM_PHASEIN_INT_ENABLE,
417 PWM_CONTROL_LOGIC);
418 pwm_reg = PSB_RVDC32(PWM_CONTROL_LOGIC);
419
420 psb_enable_pipestat(dev_priv, 0, PIPE_DPST_EVENT_ENABLE);
421
422 hist_reg = PSB_RVDC32(HISTOGRAM_INT_CONTROL);
423 PSB_WVDC32(hist_reg | HISTOGRAM_INT_CTRL_CLEAR,
424 HISTOGRAM_INT_CONTROL);
425 pwm_reg = PSB_RVDC32(PWM_CONTROL_LOGIC);
426 PSB_WVDC32(pwm_reg | 0x80010100 | PWM_PHASEIN_ENABLE,
427 PWM_CONTROL_LOGIC);
428
429 gma_power_end(dev);
430 }
431}
432
433int psb_irq_enable_dpst(struct drm_device *dev)
434{
435 struct drm_psb_private *dev_priv =
436 (struct drm_psb_private *) dev->dev_private;
437 unsigned long irqflags;
438
439 spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
440
441 /* enable DPST */
442 mid_enable_pipe_event(dev_priv, 0);
443 psb_irq_turn_on_dpst(dev);
444
445 spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
446 return 0;
447}
448
449void psb_irq_turn_off_dpst(struct drm_device *dev)
450{
451 struct drm_psb_private *dev_priv =
452 (struct drm_psb_private *) dev->dev_private;
453 u32 hist_reg;
454 u32 pwm_reg;
455
456 if (gma_power_begin(dev, false)) {
457 PSB_WVDC32(0x00000000, HISTOGRAM_INT_CONTROL);
458 hist_reg = PSB_RVDC32(HISTOGRAM_INT_CONTROL);
459
460 psb_disable_pipestat(dev_priv, 0, PIPE_DPST_EVENT_ENABLE);
461
462 pwm_reg = PSB_RVDC32(PWM_CONTROL_LOGIC);
463 PSB_WVDC32(pwm_reg & ~PWM_PHASEIN_INT_ENABLE,
464 PWM_CONTROL_LOGIC);
465 pwm_reg = PSB_RVDC32(PWM_CONTROL_LOGIC);
466
467 gma_power_end(dev);
468 }
469}
470
471int psb_irq_disable_dpst(struct drm_device *dev)
472{
473 struct drm_psb_private *dev_priv =
474 (struct drm_psb_private *) dev->dev_private;
475 unsigned long irqflags;
476
477 spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
478
479 mid_disable_pipe_event(dev_priv, 0);
480 psb_irq_turn_off_dpst(dev);
481
482 spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
483
484 return 0;
485}
486
487/*
488 * It is used to enable VBLANK interrupt
489 */
490int psb_enable_vblank(struct drm_device *dev, unsigned int pipe)
491{
492 struct drm_psb_private *dev_priv = dev->dev_private;
493 unsigned long irqflags;
494 uint32_t reg_val = 0;
495 uint32_t pipeconf_reg = mid_pipeconf(pipe);
496
497 /* Medfield is different - we should perhaps extract out vblank
498 and blacklight etc ops */
499 if (IS_MFLD(dev))
500 return mdfld_enable_te(dev, pipe);
501
502 if (gma_power_begin(dev, false)) {
503 reg_val = REG_READ(pipeconf_reg);
504 gma_power_end(dev);
505 }
506
507 if (!(reg_val & PIPEACONF_ENABLE))
508 return -EINVAL;
509
510 spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
511
512 if (pipe == 0)
513 dev_priv->vdc_irq_mask |= _PSB_VSYNC_PIPEA_FLAG;
514 else if (pipe == 1)
515 dev_priv->vdc_irq_mask |= _PSB_VSYNC_PIPEB_FLAG;
516
517 PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R);
518 PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R);
519 psb_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_ENABLE);
520
521 spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
522
523 return 0;
524}
525
526/*
527 * It is used to disable VBLANK interrupt
528 */
529void psb_disable_vblank(struct drm_device *dev, unsigned int pipe)
530{
531 struct drm_psb_private *dev_priv = dev->dev_private;
532 unsigned long irqflags;
533
534 if (IS_MFLD(dev))
535 mdfld_disable_te(dev, pipe);
536 spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
537
538 if (pipe == 0)
539 dev_priv->vdc_irq_mask &= ~_PSB_VSYNC_PIPEA_FLAG;
540 else if (pipe == 1)
541 dev_priv->vdc_irq_mask &= ~_PSB_VSYNC_PIPEB_FLAG;
542
543 PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R);
544 PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R);
545 psb_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_ENABLE);
546
547 spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
548}
549
550/*
551 * It is used to enable TE interrupt
552 */
553int mdfld_enable_te(struct drm_device *dev, int pipe)
554{
555 struct drm_psb_private *dev_priv =
556 (struct drm_psb_private *) dev->dev_private;
557 unsigned long irqflags;
558 uint32_t reg_val = 0;
559 uint32_t pipeconf_reg = mid_pipeconf(pipe);
560
561 if (gma_power_begin(dev, false)) {
562 reg_val = REG_READ(pipeconf_reg);
563 gma_power_end(dev);
564 }
565
566 if (!(reg_val & PIPEACONF_ENABLE))
567 return -EINVAL;
568
569 spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
570
571 mid_enable_pipe_event(dev_priv, pipe);
572 psb_enable_pipestat(dev_priv, pipe, PIPE_TE_ENABLE);
573
574 spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
575
576 return 0;
577}
578
579/*
580 * It is used to disable TE interrupt
581 */
582void mdfld_disable_te(struct drm_device *dev, int pipe)
583{
584 struct drm_psb_private *dev_priv =
585 (struct drm_psb_private *) dev->dev_private;
586 unsigned long irqflags;
587
588 if (!dev_priv->dsr_enable)
589 return;
590
591 spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
592
593 mid_disable_pipe_event(dev_priv, pipe);
594 psb_disable_pipestat(dev_priv, pipe, PIPE_TE_ENABLE);
595
596 spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
597}
598
599/* Called from drm generic code, passed a 'crtc', which
600 * we use as a pipe index
601 */
602u32 psb_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
603{
604 uint32_t high_frame = PIPEAFRAMEHIGH;
605 uint32_t low_frame = PIPEAFRAMEPIXEL;
606 uint32_t pipeconf_reg = PIPEACONF;
607 uint32_t reg_val = 0;
608 uint32_t high1 = 0, high2 = 0, low = 0, count = 0;
609
610 switch (pipe) {
611 case 0:
612 break;
613 case 1:
614 high_frame = PIPEBFRAMEHIGH;
615 low_frame = PIPEBFRAMEPIXEL;
616 pipeconf_reg = PIPEBCONF;
617 break;
618 case 2:
619 high_frame = PIPECFRAMEHIGH;
620 low_frame = PIPECFRAMEPIXEL;
621 pipeconf_reg = PIPECCONF;
622 break;
623 default:
624 dev_err(dev->dev, "%s, invalid pipe.\n", __func__);
625 return 0;
626 }
627
628 if (!gma_power_begin(dev, false))
629 return 0;
630
631 reg_val = REG_READ(pipeconf_reg);
632
633 if (!(reg_val & PIPEACONF_ENABLE)) {
634 dev_err(dev->dev, "trying to get vblank count for disabled pipe %u\n",
635 pipe);
636 goto psb_get_vblank_counter_exit;
637 }
638
639 /*
640 * High & low register fields aren't synchronized, so make sure
641 * we get a low value that's stable across two reads of the high
642 * register.
643 */
644 do {
645 high1 = ((REG_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >>
646 PIPE_FRAME_HIGH_SHIFT);
647 low = ((REG_READ(low_frame) & PIPE_FRAME_LOW_MASK) >>
648 PIPE_FRAME_LOW_SHIFT);
649 high2 = ((REG_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >>
650 PIPE_FRAME_HIGH_SHIFT);
651 } while (high1 != high2);
652
653 count = (high1 << 8) | low;
654
655psb_get_vblank_counter_exit:
656
657 gma_power_end(dev);
658
659 return count;
660}
661