1 /**************************************************************************
2 * Copyright (c) 2007, Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18 * Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
19 * develop this driver.
21 **************************************************************************/
28 #include "psb_intel_reg.h"
36 psb_pipestat(int pipe
)
48 mid_pipe_event(int pipe
)
51 return _PSB_PIPEA_EVENT_FLAG
;
53 return _MDFLD_PIPEB_EVENT_FLAG
;
55 return _MDFLD_PIPEC_EVENT_FLAG
;
60 mid_pipe_vsync(int pipe
)
63 return _PSB_VSYNC_PIPEA_FLAG
;
65 return _PSB_VSYNC_PIPEB_FLAG
;
67 return _MDFLD_PIPEC_VBLANK_FLAG
;
72 mid_pipeconf(int pipe
)
84 psb_enable_pipestat(struct drm_psb_private
*dev_priv
, int pipe
, u32 mask
)
86 if ((dev_priv
->pipestat
[pipe
] & mask
) != mask
) {
87 u32 reg
= psb_pipestat(pipe
);
88 dev_priv
->pipestat
[pipe
] |= mask
;
89 /* Enable the interrupt, clear any pending status */
90 if (gma_power_begin(dev_priv
->dev
, false)) {
91 u32 writeVal
= PSB_RVDC32(reg
);
92 writeVal
|= (mask
| (mask
>> 16));
93 PSB_WVDC32(writeVal
, reg
);
94 (void) PSB_RVDC32(reg
);
95 gma_power_end(dev_priv
->dev
);
101 psb_disable_pipestat(struct drm_psb_private
*dev_priv
, int pipe
, u32 mask
)
103 if ((dev_priv
->pipestat
[pipe
] & mask
) != 0) {
104 u32 reg
= psb_pipestat(pipe
);
105 dev_priv
->pipestat
[pipe
] &= ~mask
;
106 if (gma_power_begin(dev_priv
->dev
, false)) {
107 u32 writeVal
= PSB_RVDC32(reg
);
109 PSB_WVDC32(writeVal
, reg
);
110 (void) PSB_RVDC32(reg
);
111 gma_power_end(dev_priv
->dev
);
116 void mid_enable_pipe_event(struct drm_psb_private
*dev_priv
, int pipe
)
118 if (gma_power_begin(dev_priv
->dev
, false)) {
119 u32 pipe_event
= mid_pipe_event(pipe
);
120 dev_priv
->vdc_irq_mask
|= pipe_event
;
121 PSB_WVDC32(~dev_priv
->vdc_irq_mask
, PSB_INT_MASK_R
);
122 PSB_WVDC32(dev_priv
->vdc_irq_mask
, PSB_INT_ENABLE_R
);
123 gma_power_end(dev_priv
->dev
);
127 void mid_disable_pipe_event(struct drm_psb_private
*dev_priv
, int pipe
)
129 if (dev_priv
->pipestat
[pipe
] == 0) {
130 if (gma_power_begin(dev_priv
->dev
, false)) {
131 u32 pipe_event
= mid_pipe_event(pipe
);
132 dev_priv
->vdc_irq_mask
&= ~pipe_event
;
133 PSB_WVDC32(~dev_priv
->vdc_irq_mask
, PSB_INT_MASK_R
);
134 PSB_WVDC32(dev_priv
->vdc_irq_mask
, PSB_INT_ENABLE_R
);
135 gma_power_end(dev_priv
->dev
);
141 * Display controller interrupt handler for pipe event.
144 static void mid_pipe_event_handler(struct drm_device
*dev
, int pipe
)
146 struct drm_psb_private
*dev_priv
=
147 (struct drm_psb_private
*) dev
->dev_private
;
149 uint32_t pipe_stat_val
= 0;
150 uint32_t pipe_stat_reg
= psb_pipestat(pipe
);
151 uint32_t pipe_enable
= dev_priv
->pipestat
[pipe
];
152 uint32_t pipe_status
= dev_priv
->pipestat
[pipe
] >> 16;
156 spin_lock(&dev_priv
->irqmask_lock
);
158 pipe_stat_val
= PSB_RVDC32(pipe_stat_reg
);
159 pipe_stat_val
&= pipe_enable
| pipe_status
;
160 pipe_stat_val
&= pipe_stat_val
>> 16;
162 spin_unlock(&dev_priv
->irqmask_lock
);
164 /* Clear the 2nd level interrupt status bits
165 * Sometimes the bits are very sticky so we repeat until they unstick */
166 for (i
= 0; i
< 0xffff; i
++) {
167 PSB_WVDC32(PSB_RVDC32(pipe_stat_reg
), pipe_stat_reg
);
168 pipe_clear
= PSB_RVDC32(pipe_stat_reg
) & pipe_status
;
176 "%s, can't clear status bits for pipe %d, its value = 0x%x.\n",
177 __func__
, pipe
, PSB_RVDC32(pipe_stat_reg
));
179 if (pipe_stat_val
& PIPE_VBLANK_STATUS
)
180 drm_handle_vblank(dev
, pipe
);
182 if (pipe_stat_val
& PIPE_TE_STATUS
)
183 drm_handle_vblank(dev
, pipe
);
187 * Display controller interrupt handler.
189 static void psb_vdc_interrupt(struct drm_device
*dev
, uint32_t vdc_stat
)
191 if (vdc_stat
& _PSB_VSYNC_PIPEA_FLAG
)
192 mid_pipe_event_handler(dev
, 0);
194 if (vdc_stat
& _PSB_VSYNC_PIPEB_FLAG
)
195 mid_pipe_event_handler(dev
, 1);
198 irqreturn_t
psb_irq_handler(DRM_IRQ_ARGS
)
200 struct drm_device
*dev
= (struct drm_device
*) arg
;
201 struct drm_psb_private
*dev_priv
=
202 (struct drm_psb_private
*) dev
->dev_private
;
204 uint32_t vdc_stat
, dsp_int
= 0, sgx_int
= 0;
207 spin_lock(&dev_priv
->irqmask_lock
);
209 vdc_stat
= PSB_RVDC32(PSB_INT_IDENTITY_R
);
211 if (vdc_stat
& _PSB_PIPE_EVENT_FLAG
)
214 /* FIXME: Handle Medfield
215 if (vdc_stat & _MDFLD_DISP_ALL_IRQ_FLAG)
219 if (vdc_stat
& _PSB_IRQ_SGX_FLAG
)
222 vdc_stat
&= dev_priv
->vdc_irq_mask
;
223 spin_unlock(&dev_priv
->irqmask_lock
);
225 if (dsp_int
&& gma_power_is_on(dev
)) {
226 psb_vdc_interrupt(dev
, vdc_stat
);
231 /* Not expected - we have it masked, shut it up */
233 s
= PSB_RSGX32(PSB_CR_EVENT_STATUS
);
234 s2
= PSB_RSGX32(PSB_CR_EVENT_STATUS2
);
235 PSB_WSGX32(s
, PSB_CR_EVENT_HOST_CLEAR
);
236 PSB_WSGX32(s2
, PSB_CR_EVENT_HOST_CLEAR2
);
237 /* if s & _PSB_CE_TWOD_COMPLETE we have 2D done but
238 we may as well poll even if we add that ! */
242 PSB_WVDC32(vdc_stat
, PSB_INT_IDENTITY_R
);
243 (void) PSB_RVDC32(PSB_INT_IDENTITY_R
);
244 DRM_READMEMORYBARRIER();
252 void psb_irq_preinstall(struct drm_device
*dev
)
254 struct drm_psb_private
*dev_priv
=
255 (struct drm_psb_private
*) dev
->dev_private
;
256 unsigned long irqflags
;
258 spin_lock_irqsave(&dev_priv
->irqmask_lock
, irqflags
);
260 if (gma_power_is_on(dev
))
261 PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM
);
262 if (dev
->vblank_enabled
[0])
263 dev_priv
->vdc_irq_mask
|= _PSB_VSYNC_PIPEA_FLAG
;
264 if (dev
->vblank_enabled
[1])
265 dev_priv
->vdc_irq_mask
|= _PSB_VSYNC_PIPEB_FLAG
;
267 /* FIXME: Handle Medfield irq mask
268 if (dev->vblank_enabled[1])
269 dev_priv->vdc_irq_mask |= _MDFLD_PIPEB_EVENT_FLAG;
270 if (dev->vblank_enabled[2])
271 dev_priv->vdc_irq_mask |= _MDFLD_PIPEC_EVENT_FLAG;
274 /* This register is safe even if display island is off */
275 PSB_WVDC32(~dev_priv
->vdc_irq_mask
, PSB_INT_MASK_R
);
276 spin_unlock_irqrestore(&dev_priv
->irqmask_lock
, irqflags
);
279 int psb_irq_postinstall(struct drm_device
*dev
)
281 struct drm_psb_private
*dev_priv
=
282 (struct drm_psb_private
*) dev
->dev_private
;
283 unsigned long irqflags
;
285 spin_lock_irqsave(&dev_priv
->irqmask_lock
, irqflags
);
287 /* This register is safe even if display island is off */
288 PSB_WVDC32(dev_priv
->vdc_irq_mask
, PSB_INT_ENABLE_R
);
289 PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM
);
291 if (dev
->vblank_enabled
[0])
292 psb_enable_pipestat(dev_priv
, 0, PIPE_VBLANK_INTERRUPT_ENABLE
);
294 psb_disable_pipestat(dev_priv
, 0, PIPE_VBLANK_INTERRUPT_ENABLE
);
296 if (dev
->vblank_enabled
[1])
297 psb_enable_pipestat(dev_priv
, 1, PIPE_VBLANK_INTERRUPT_ENABLE
);
299 psb_disable_pipestat(dev_priv
, 1, PIPE_VBLANK_INTERRUPT_ENABLE
);
301 if (dev
->vblank_enabled
[2])
302 psb_enable_pipestat(dev_priv
, 2, PIPE_VBLANK_INTERRUPT_ENABLE
);
304 psb_disable_pipestat(dev_priv
, 2, PIPE_VBLANK_INTERRUPT_ENABLE
);
306 spin_unlock_irqrestore(&dev_priv
->irqmask_lock
, irqflags
);
310 void psb_irq_uninstall(struct drm_device
*dev
)
312 struct drm_psb_private
*dev_priv
=
313 (struct drm_psb_private
*) dev
->dev_private
;
314 unsigned long irqflags
;
316 spin_lock_irqsave(&dev_priv
->irqmask_lock
, irqflags
);
318 PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM
);
320 if (dev
->vblank_enabled
[0])
321 psb_disable_pipestat(dev_priv
, 0, PIPE_VBLANK_INTERRUPT_ENABLE
);
323 if (dev
->vblank_enabled
[1])
324 psb_disable_pipestat(dev_priv
, 1, PIPE_VBLANK_INTERRUPT_ENABLE
);
326 if (dev
->vblank_enabled
[2])
327 psb_disable_pipestat(dev_priv
, 2, PIPE_VBLANK_INTERRUPT_ENABLE
);
329 dev_priv
->vdc_irq_mask
&= _PSB_IRQ_SGX_FLAG
|
330 _PSB_IRQ_MSVDX_FLAG
|
333 /* These two registers are safe even if display island is off */
334 PSB_WVDC32(~dev_priv
->vdc_irq_mask
, PSB_INT_MASK_R
);
335 PSB_WVDC32(dev_priv
->vdc_irq_mask
, PSB_INT_ENABLE_R
);
339 /* This register is safe even if display island is off */
340 PSB_WVDC32(PSB_RVDC32(PSB_INT_IDENTITY_R
), PSB_INT_IDENTITY_R
);
341 spin_unlock_irqrestore(&dev_priv
->irqmask_lock
, irqflags
);
344 void psb_irq_turn_on_dpst(struct drm_device
*dev
)
346 struct drm_psb_private
*dev_priv
=
347 (struct drm_psb_private
*) dev
->dev_private
;
351 if (gma_power_begin(dev
, false)) {
352 PSB_WVDC32(1 << 31, HISTOGRAM_LOGIC_CONTROL
);
353 hist_reg
= PSB_RVDC32(HISTOGRAM_LOGIC_CONTROL
);
354 PSB_WVDC32(1 << 31, HISTOGRAM_INT_CONTROL
);
355 hist_reg
= PSB_RVDC32(HISTOGRAM_INT_CONTROL
);
357 PSB_WVDC32(0x80010100, PWM_CONTROL_LOGIC
);
358 pwm_reg
= PSB_RVDC32(PWM_CONTROL_LOGIC
);
359 PSB_WVDC32(pwm_reg
| PWM_PHASEIN_ENABLE
360 | PWM_PHASEIN_INT_ENABLE
,
362 pwm_reg
= PSB_RVDC32(PWM_CONTROL_LOGIC
);
364 psb_enable_pipestat(dev_priv
, 0, PIPE_DPST_EVENT_ENABLE
);
366 hist_reg
= PSB_RVDC32(HISTOGRAM_INT_CONTROL
);
367 PSB_WVDC32(hist_reg
| HISTOGRAM_INT_CTRL_CLEAR
,
368 HISTOGRAM_INT_CONTROL
);
369 pwm_reg
= PSB_RVDC32(PWM_CONTROL_LOGIC
);
370 PSB_WVDC32(pwm_reg
| 0x80010100 | PWM_PHASEIN_ENABLE
,
377 int psb_irq_enable_dpst(struct drm_device
*dev
)
379 struct drm_psb_private
*dev_priv
=
380 (struct drm_psb_private
*) dev
->dev_private
;
381 unsigned long irqflags
;
383 spin_lock_irqsave(&dev_priv
->irqmask_lock
, irqflags
);
386 mid_enable_pipe_event(dev_priv
, 0);
387 psb_irq_turn_on_dpst(dev
);
389 spin_unlock_irqrestore(&dev_priv
->irqmask_lock
, irqflags
);
393 void psb_irq_turn_off_dpst(struct drm_device
*dev
)
395 struct drm_psb_private
*dev_priv
=
396 (struct drm_psb_private
*) dev
->dev_private
;
400 if (gma_power_begin(dev
, false)) {
401 PSB_WVDC32(0x00000000, HISTOGRAM_INT_CONTROL
);
402 hist_reg
= PSB_RVDC32(HISTOGRAM_INT_CONTROL
);
404 psb_disable_pipestat(dev_priv
, 0, PIPE_DPST_EVENT_ENABLE
);
406 pwm_reg
= PSB_RVDC32(PWM_CONTROL_LOGIC
);
407 PSB_WVDC32(pwm_reg
& !(PWM_PHASEIN_INT_ENABLE
),
409 pwm_reg
= PSB_RVDC32(PWM_CONTROL_LOGIC
);
415 int psb_irq_disable_dpst(struct drm_device
*dev
)
417 struct drm_psb_private
*dev_priv
=
418 (struct drm_psb_private
*) dev
->dev_private
;
419 unsigned long irqflags
;
421 spin_lock_irqsave(&dev_priv
->irqmask_lock
, irqflags
);
423 mid_disable_pipe_event(dev_priv
, 0);
424 psb_irq_turn_off_dpst(dev
);
426 spin_unlock_irqrestore(&dev_priv
->irqmask_lock
, irqflags
);
432 static int psb_vblank_do_wait(struct drm_device
*dev
,
433 unsigned int *sequence
, atomic_t
*counter
)
435 unsigned int cur_vblank
;
437 DRM_WAIT_ON(ret
, dev
->vbl_queue
, 3 * DRM_HZ
,
438 (((cur_vblank
= atomic_read(counter
))
439 - *sequence
) <= (1 << 23)));
440 *sequence
= cur_vblank
;
447 * It is used to enable VBLANK interrupt
449 int psb_enable_vblank(struct drm_device
*dev
, int pipe
)
451 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
452 unsigned long irqflags
;
453 uint32_t reg_val
= 0;
454 uint32_t pipeconf_reg
= mid_pipeconf(pipe
);
456 if (gma_power_begin(dev
, false)) {
457 reg_val
= REG_READ(pipeconf_reg
);
461 if (!(reg_val
& PIPEACONF_ENABLE
))
464 spin_lock_irqsave(&dev_priv
->irqmask_lock
, irqflags
);
467 dev_priv
->vdc_irq_mask
|= _PSB_VSYNC_PIPEA_FLAG
;
469 dev_priv
->vdc_irq_mask
|= _PSB_VSYNC_PIPEB_FLAG
;
471 PSB_WVDC32(~dev_priv
->vdc_irq_mask
, PSB_INT_MASK_R
);
472 PSB_WVDC32(dev_priv
->vdc_irq_mask
, PSB_INT_ENABLE_R
);
473 psb_enable_pipestat(dev_priv
, pipe
, PIPE_VBLANK_INTERRUPT_ENABLE
);
475 spin_unlock_irqrestore(&dev_priv
->irqmask_lock
, irqflags
);
481 * It is used to disable VBLANK interrupt
483 void psb_disable_vblank(struct drm_device
*dev
, int pipe
)
485 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
486 unsigned long irqflags
;
488 spin_lock_irqsave(&dev_priv
->irqmask_lock
, irqflags
);
491 dev_priv
->vdc_irq_mask
&= ~_PSB_VSYNC_PIPEA_FLAG
;
493 dev_priv
->vdc_irq_mask
&= ~_PSB_VSYNC_PIPEB_FLAG
;
495 PSB_WVDC32(~dev_priv
->vdc_irq_mask
, PSB_INT_MASK_R
);
496 PSB_WVDC32(dev_priv
->vdc_irq_mask
, PSB_INT_ENABLE_R
);
497 psb_disable_pipestat(dev_priv
, pipe
, PIPE_VBLANK_INTERRUPT_ENABLE
);
499 spin_unlock_irqrestore(&dev_priv
->irqmask_lock
, irqflags
);
502 /* Called from drm generic code, passed a 'crtc', which
503 * we use as a pipe index
505 u32
psb_get_vblank_counter(struct drm_device
*dev
, int pipe
)
507 uint32_t high_frame
= PIPEAFRAMEHIGH
;
508 uint32_t low_frame
= PIPEAFRAMEPIXEL
;
509 uint32_t pipeconf_reg
= PIPEACONF
;
510 uint32_t reg_val
= 0;
511 uint32_t high1
= 0, high2
= 0, low
= 0, count
= 0;
517 high_frame
= PIPEBFRAMEHIGH
;
518 low_frame
= PIPEBFRAMEPIXEL
;
519 pipeconf_reg
= PIPEBCONF
;
522 high_frame
= PIPECFRAMEHIGH
;
523 low_frame
= PIPECFRAMEPIXEL
;
524 pipeconf_reg
= PIPECCONF
;
527 dev_err(dev
->dev
, "%s, invalid pipe.\n", __func__
);
531 if (!gma_power_begin(dev
, false))
534 reg_val
= REG_READ(pipeconf_reg
);
536 if (!(reg_val
& PIPEACONF_ENABLE
)) {
537 dev_err(dev
->dev
, "trying to get vblank count for disabled pipe %d\n",
539 goto psb_get_vblank_counter_exit
;
543 * High & low register fields aren't synchronized, so make sure
544 * we get a low value that's stable across two reads of the high
548 high1
= ((REG_READ(high_frame
) & PIPE_FRAME_HIGH_MASK
) >>
549 PIPE_FRAME_HIGH_SHIFT
);
550 low
= ((REG_READ(low_frame
) & PIPE_FRAME_LOW_MASK
) >>
551 PIPE_FRAME_LOW_SHIFT
);
552 high2
= ((REG_READ(high_frame
) & PIPE_FRAME_HIGH_MASK
) >>
553 PIPE_FRAME_HIGH_SHIFT
);
554 } while (high1
!= high2
);
556 count
= (high1
<< 8) | low
;
558 psb_get_vblank_counter_exit
: