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"
31 #include "mdfld_output.h"
38 psb_pipestat(int pipe
)
50 mid_pipe_event(int pipe
)
53 return _PSB_PIPEA_EVENT_FLAG
;
55 return _MDFLD_PIPEB_EVENT_FLAG
;
57 return _MDFLD_PIPEC_EVENT_FLAG
;
62 mid_pipe_vsync(int pipe
)
65 return _PSB_VSYNC_PIPEA_FLAG
;
67 return _PSB_VSYNC_PIPEB_FLAG
;
69 return _MDFLD_PIPEC_VBLANK_FLAG
;
74 mid_pipeconf(int pipe
)
86 psb_enable_pipestat(struct drm_psb_private
*dev_priv
, int pipe
, u32 mask
)
88 if ((dev_priv
->pipestat
[pipe
] & mask
) != mask
) {
89 u32 reg
= psb_pipestat(pipe
);
90 dev_priv
->pipestat
[pipe
] |= mask
;
91 /* Enable the interrupt, clear any pending status */
92 if (gma_power_begin(dev_priv
->dev
, false)) {
93 u32 writeVal
= PSB_RVDC32(reg
);
94 writeVal
|= (mask
| (mask
>> 16));
95 PSB_WVDC32(writeVal
, reg
);
96 (void) PSB_RVDC32(reg
);
97 gma_power_end(dev_priv
->dev
);
103 psb_disable_pipestat(struct drm_psb_private
*dev_priv
, int pipe
, u32 mask
)
105 if ((dev_priv
->pipestat
[pipe
] & mask
) != 0) {
106 u32 reg
= psb_pipestat(pipe
);
107 dev_priv
->pipestat
[pipe
] &= ~mask
;
108 if (gma_power_begin(dev_priv
->dev
, false)) {
109 u32 writeVal
= PSB_RVDC32(reg
);
111 PSB_WVDC32(writeVal
, reg
);
112 (void) PSB_RVDC32(reg
);
113 gma_power_end(dev_priv
->dev
);
118 static void mid_enable_pipe_event(struct drm_psb_private
*dev_priv
, int pipe
)
120 if (gma_power_begin(dev_priv
->dev
, false)) {
121 u32 pipe_event
= mid_pipe_event(pipe
);
122 dev_priv
->vdc_irq_mask
|= pipe_event
;
123 PSB_WVDC32(~dev_priv
->vdc_irq_mask
, PSB_INT_MASK_R
);
124 PSB_WVDC32(dev_priv
->vdc_irq_mask
, PSB_INT_ENABLE_R
);
125 gma_power_end(dev_priv
->dev
);
129 static void mid_disable_pipe_event(struct drm_psb_private
*dev_priv
, int pipe
)
131 if (dev_priv
->pipestat
[pipe
] == 0) {
132 if (gma_power_begin(dev_priv
->dev
, false)) {
133 u32 pipe_event
= mid_pipe_event(pipe
);
134 dev_priv
->vdc_irq_mask
&= ~pipe_event
;
135 PSB_WVDC32(~dev_priv
->vdc_irq_mask
, PSB_INT_MASK_R
);
136 PSB_WVDC32(dev_priv
->vdc_irq_mask
, PSB_INT_ENABLE_R
);
137 gma_power_end(dev_priv
->dev
);
143 * Display controller interrupt handler for pipe event.
146 static void mid_pipe_event_handler(struct drm_device
*dev
, int pipe
)
148 struct drm_psb_private
*dev_priv
=
149 (struct drm_psb_private
*) dev
->dev_private
;
151 uint32_t pipe_stat_val
= 0;
152 uint32_t pipe_stat_reg
= psb_pipestat(pipe
);
153 uint32_t pipe_enable
= dev_priv
->pipestat
[pipe
];
154 uint32_t pipe_status
= dev_priv
->pipestat
[pipe
] >> 16;
158 spin_lock(&dev_priv
->irqmask_lock
);
160 pipe_stat_val
= PSB_RVDC32(pipe_stat_reg
);
161 pipe_stat_val
&= pipe_enable
| pipe_status
;
162 pipe_stat_val
&= pipe_stat_val
>> 16;
164 spin_unlock(&dev_priv
->irqmask_lock
);
166 /* Clear the 2nd level interrupt status bits
167 * Sometimes the bits are very sticky so we repeat until they unstick */
168 for (i
= 0; i
< 0xffff; i
++) {
169 PSB_WVDC32(PSB_RVDC32(pipe_stat_reg
), pipe_stat_reg
);
170 pipe_clear
= PSB_RVDC32(pipe_stat_reg
) & pipe_status
;
178 "%s, can't clear status bits for pipe %d, its value = 0x%x.\n",
179 __func__
, pipe
, PSB_RVDC32(pipe_stat_reg
));
181 if (pipe_stat_val
& PIPE_VBLANK_STATUS
)
182 drm_handle_vblank(dev
, pipe
);
184 if (pipe_stat_val
& PIPE_TE_STATUS
)
185 drm_handle_vblank(dev
, pipe
);
189 * Display controller interrupt handler.
191 static void psb_vdc_interrupt(struct drm_device
*dev
, uint32_t vdc_stat
)
193 if (vdc_stat
& _PSB_IRQ_ASLE
)
194 psb_intel_opregion_asle_intr(dev
);
196 if (vdc_stat
& _PSB_VSYNC_PIPEA_FLAG
)
197 mid_pipe_event_handler(dev
, 0);
199 if (vdc_stat
& _PSB_VSYNC_PIPEB_FLAG
)
200 mid_pipe_event_handler(dev
, 1);
203 irqreturn_t
psb_irq_handler(int irq
, void *arg
)
205 struct drm_device
*dev
= arg
;
206 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
207 uint32_t vdc_stat
, dsp_int
= 0, sgx_int
= 0, hotplug_int
= 0;
210 spin_lock(&dev_priv
->irqmask_lock
);
212 vdc_stat
= PSB_RVDC32(PSB_INT_IDENTITY_R
);
214 if (vdc_stat
& (_PSB_PIPE_EVENT_FLAG
|_PSB_IRQ_ASLE
))
217 /* FIXME: Handle Medfield
218 if (vdc_stat & _MDFLD_DISP_ALL_IRQ_FLAG)
222 if (vdc_stat
& _PSB_IRQ_SGX_FLAG
)
224 if (vdc_stat
& _PSB_IRQ_DISP_HOTSYNC
)
227 vdc_stat
&= dev_priv
->vdc_irq_mask
;
228 spin_unlock(&dev_priv
->irqmask_lock
);
230 if (dsp_int
&& gma_power_is_on(dev
)) {
231 psb_vdc_interrupt(dev
, vdc_stat
);
236 /* Not expected - we have it masked, shut it up */
238 s
= PSB_RSGX32(PSB_CR_EVENT_STATUS
);
239 s2
= PSB_RSGX32(PSB_CR_EVENT_STATUS2
);
240 PSB_WSGX32(s
, PSB_CR_EVENT_HOST_CLEAR
);
241 PSB_WSGX32(s2
, PSB_CR_EVENT_HOST_CLEAR2
);
242 /* if s & _PSB_CE_TWOD_COMPLETE we have 2D done but
243 we may as well poll even if we add that ! */
247 /* Note: this bit has other meanings on some devices, so we will
248 need to address that later if it ever matters */
249 if (hotplug_int
&& dev_priv
->ops
->hotplug
) {
250 handled
= dev_priv
->ops
->hotplug(dev
);
251 REG_WRITE(PORT_HOTPLUG_STAT
, REG_READ(PORT_HOTPLUG_STAT
));
254 PSB_WVDC32(vdc_stat
, PSB_INT_IDENTITY_R
);
255 (void) PSB_RVDC32(PSB_INT_IDENTITY_R
);
264 void psb_irq_preinstall(struct drm_device
*dev
)
266 struct drm_psb_private
*dev_priv
=
267 (struct drm_psb_private
*) dev
->dev_private
;
268 unsigned long irqflags
;
270 spin_lock_irqsave(&dev_priv
->irqmask_lock
, irqflags
);
272 if (gma_power_is_on(dev
))
273 PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM
);
274 if (dev
->vblank
[0].enabled
)
275 dev_priv
->vdc_irq_mask
|= _PSB_VSYNC_PIPEA_FLAG
;
276 if (dev
->vblank
[1].enabled
)
277 dev_priv
->vdc_irq_mask
|= _PSB_VSYNC_PIPEB_FLAG
;
279 /* FIXME: Handle Medfield irq mask
280 if (dev->vblank[1].enabled)
281 dev_priv->vdc_irq_mask |= _MDFLD_PIPEB_EVENT_FLAG;
282 if (dev->vblank[2].enabled)
283 dev_priv->vdc_irq_mask |= _MDFLD_PIPEC_EVENT_FLAG;
286 /* Revisit this area - want per device masks ? */
287 if (dev_priv
->ops
->hotplug
)
288 dev_priv
->vdc_irq_mask
|= _PSB_IRQ_DISP_HOTSYNC
;
289 dev_priv
->vdc_irq_mask
|= _PSB_IRQ_ASLE
;
291 /* This register is safe even if display island is off */
292 PSB_WVDC32(~dev_priv
->vdc_irq_mask
, PSB_INT_MASK_R
);
293 spin_unlock_irqrestore(&dev_priv
->irqmask_lock
, irqflags
);
296 int psb_irq_postinstall(struct drm_device
*dev
)
298 struct drm_psb_private
*dev_priv
=
299 (struct drm_psb_private
*) dev
->dev_private
;
300 unsigned long irqflags
;
302 spin_lock_irqsave(&dev_priv
->irqmask_lock
, irqflags
);
304 /* This register is safe even if display island is off */
305 PSB_WVDC32(dev_priv
->vdc_irq_mask
, PSB_INT_ENABLE_R
);
306 PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM
);
308 if (dev
->vblank
[0].enabled
)
309 psb_enable_pipestat(dev_priv
, 0, PIPE_VBLANK_INTERRUPT_ENABLE
);
311 psb_disable_pipestat(dev_priv
, 0, PIPE_VBLANK_INTERRUPT_ENABLE
);
313 if (dev
->vblank
[1].enabled
)
314 psb_enable_pipestat(dev_priv
, 1, PIPE_VBLANK_INTERRUPT_ENABLE
);
316 psb_disable_pipestat(dev_priv
, 1, PIPE_VBLANK_INTERRUPT_ENABLE
);
318 if (dev
->vblank
[2].enabled
)
319 psb_enable_pipestat(dev_priv
, 2, PIPE_VBLANK_INTERRUPT_ENABLE
);
321 psb_disable_pipestat(dev_priv
, 2, PIPE_VBLANK_INTERRUPT_ENABLE
);
323 if (dev_priv
->ops
->hotplug_enable
)
324 dev_priv
->ops
->hotplug_enable(dev
, true);
326 spin_unlock_irqrestore(&dev_priv
->irqmask_lock
, irqflags
);
330 void psb_irq_uninstall(struct drm_device
*dev
)
332 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
333 unsigned long irqflags
;
335 spin_lock_irqsave(&dev_priv
->irqmask_lock
, irqflags
);
337 if (dev_priv
->ops
->hotplug_enable
)
338 dev_priv
->ops
->hotplug_enable(dev
, false);
340 PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM
);
342 if (dev
->vblank
[0].enabled
)
343 psb_disable_pipestat(dev_priv
, 0, PIPE_VBLANK_INTERRUPT_ENABLE
);
345 if (dev
->vblank
[1].enabled
)
346 psb_disable_pipestat(dev_priv
, 1, PIPE_VBLANK_INTERRUPT_ENABLE
);
348 if (dev
->vblank
[2].enabled
)
349 psb_disable_pipestat(dev_priv
, 2, PIPE_VBLANK_INTERRUPT_ENABLE
);
351 dev_priv
->vdc_irq_mask
&= _PSB_IRQ_SGX_FLAG
|
352 _PSB_IRQ_MSVDX_FLAG
|
355 /* These two registers are safe even if display island is off */
356 PSB_WVDC32(~dev_priv
->vdc_irq_mask
, PSB_INT_MASK_R
);
357 PSB_WVDC32(dev_priv
->vdc_irq_mask
, PSB_INT_ENABLE_R
);
361 /* This register is safe even if display island is off */
362 PSB_WVDC32(PSB_RVDC32(PSB_INT_IDENTITY_R
), PSB_INT_IDENTITY_R
);
363 spin_unlock_irqrestore(&dev_priv
->irqmask_lock
, irqflags
);
366 void psb_irq_turn_on_dpst(struct drm_device
*dev
)
368 struct drm_psb_private
*dev_priv
=
369 (struct drm_psb_private
*) dev
->dev_private
;
373 if (gma_power_begin(dev
, false)) {
374 PSB_WVDC32(1 << 31, HISTOGRAM_LOGIC_CONTROL
);
375 hist_reg
= PSB_RVDC32(HISTOGRAM_LOGIC_CONTROL
);
376 PSB_WVDC32(1 << 31, HISTOGRAM_INT_CONTROL
);
377 hist_reg
= PSB_RVDC32(HISTOGRAM_INT_CONTROL
);
379 PSB_WVDC32(0x80010100, PWM_CONTROL_LOGIC
);
380 pwm_reg
= PSB_RVDC32(PWM_CONTROL_LOGIC
);
381 PSB_WVDC32(pwm_reg
| PWM_PHASEIN_ENABLE
382 | PWM_PHASEIN_INT_ENABLE
,
384 pwm_reg
= PSB_RVDC32(PWM_CONTROL_LOGIC
);
386 psb_enable_pipestat(dev_priv
, 0, PIPE_DPST_EVENT_ENABLE
);
388 hist_reg
= PSB_RVDC32(HISTOGRAM_INT_CONTROL
);
389 PSB_WVDC32(hist_reg
| HISTOGRAM_INT_CTRL_CLEAR
,
390 HISTOGRAM_INT_CONTROL
);
391 pwm_reg
= PSB_RVDC32(PWM_CONTROL_LOGIC
);
392 PSB_WVDC32(pwm_reg
| 0x80010100 | PWM_PHASEIN_ENABLE
,
399 int psb_irq_enable_dpst(struct drm_device
*dev
)
401 struct drm_psb_private
*dev_priv
=
402 (struct drm_psb_private
*) dev
->dev_private
;
403 unsigned long irqflags
;
405 spin_lock_irqsave(&dev_priv
->irqmask_lock
, irqflags
);
408 mid_enable_pipe_event(dev_priv
, 0);
409 psb_irq_turn_on_dpst(dev
);
411 spin_unlock_irqrestore(&dev_priv
->irqmask_lock
, irqflags
);
415 void psb_irq_turn_off_dpst(struct drm_device
*dev
)
417 struct drm_psb_private
*dev_priv
=
418 (struct drm_psb_private
*) dev
->dev_private
;
422 if (gma_power_begin(dev
, false)) {
423 PSB_WVDC32(0x00000000, HISTOGRAM_INT_CONTROL
);
424 hist_reg
= PSB_RVDC32(HISTOGRAM_INT_CONTROL
);
426 psb_disable_pipestat(dev_priv
, 0, PIPE_DPST_EVENT_ENABLE
);
428 pwm_reg
= PSB_RVDC32(PWM_CONTROL_LOGIC
);
429 PSB_WVDC32(pwm_reg
& ~PWM_PHASEIN_INT_ENABLE
,
431 pwm_reg
= PSB_RVDC32(PWM_CONTROL_LOGIC
);
437 int psb_irq_disable_dpst(struct drm_device
*dev
)
439 struct drm_psb_private
*dev_priv
=
440 (struct drm_psb_private
*) dev
->dev_private
;
441 unsigned long irqflags
;
443 spin_lock_irqsave(&dev_priv
->irqmask_lock
, irqflags
);
445 mid_disable_pipe_event(dev_priv
, 0);
446 psb_irq_turn_off_dpst(dev
);
448 spin_unlock_irqrestore(&dev_priv
->irqmask_lock
, irqflags
);
454 * It is used to enable VBLANK interrupt
456 int psb_enable_vblank(struct drm_device
*dev
, int pipe
)
458 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
459 unsigned long irqflags
;
460 uint32_t reg_val
= 0;
461 uint32_t pipeconf_reg
= mid_pipeconf(pipe
);
463 /* Medfield is different - we should perhaps extract out vblank
464 and blacklight etc ops */
466 return mdfld_enable_te(dev
, pipe
);
468 if (gma_power_begin(dev
, false)) {
469 reg_val
= REG_READ(pipeconf_reg
);
473 if (!(reg_val
& PIPEACONF_ENABLE
))
476 spin_lock_irqsave(&dev_priv
->irqmask_lock
, irqflags
);
479 dev_priv
->vdc_irq_mask
|= _PSB_VSYNC_PIPEA_FLAG
;
481 dev_priv
->vdc_irq_mask
|= _PSB_VSYNC_PIPEB_FLAG
;
483 PSB_WVDC32(~dev_priv
->vdc_irq_mask
, PSB_INT_MASK_R
);
484 PSB_WVDC32(dev_priv
->vdc_irq_mask
, PSB_INT_ENABLE_R
);
485 psb_enable_pipestat(dev_priv
, pipe
, PIPE_VBLANK_INTERRUPT_ENABLE
);
487 spin_unlock_irqrestore(&dev_priv
->irqmask_lock
, irqflags
);
493 * It is used to disable VBLANK interrupt
495 void psb_disable_vblank(struct drm_device
*dev
, int pipe
)
497 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
498 unsigned long irqflags
;
501 mdfld_disable_te(dev
, pipe
);
502 spin_lock_irqsave(&dev_priv
->irqmask_lock
, irqflags
);
505 dev_priv
->vdc_irq_mask
&= ~_PSB_VSYNC_PIPEA_FLAG
;
507 dev_priv
->vdc_irq_mask
&= ~_PSB_VSYNC_PIPEB_FLAG
;
509 PSB_WVDC32(~dev_priv
->vdc_irq_mask
, PSB_INT_MASK_R
);
510 PSB_WVDC32(dev_priv
->vdc_irq_mask
, PSB_INT_ENABLE_R
);
511 psb_disable_pipestat(dev_priv
, pipe
, PIPE_VBLANK_INTERRUPT_ENABLE
);
513 spin_unlock_irqrestore(&dev_priv
->irqmask_lock
, irqflags
);
517 * It is used to enable TE interrupt
519 int mdfld_enable_te(struct drm_device
*dev
, int pipe
)
521 struct drm_psb_private
*dev_priv
=
522 (struct drm_psb_private
*) dev
->dev_private
;
523 unsigned long irqflags
;
524 uint32_t reg_val
= 0;
525 uint32_t pipeconf_reg
= mid_pipeconf(pipe
);
527 if (gma_power_begin(dev
, false)) {
528 reg_val
= REG_READ(pipeconf_reg
);
532 if (!(reg_val
& PIPEACONF_ENABLE
))
535 spin_lock_irqsave(&dev_priv
->irqmask_lock
, irqflags
);
537 mid_enable_pipe_event(dev_priv
, pipe
);
538 psb_enable_pipestat(dev_priv
, pipe
, PIPE_TE_ENABLE
);
540 spin_unlock_irqrestore(&dev_priv
->irqmask_lock
, irqflags
);
546 * It is used to disable TE interrupt
548 void mdfld_disable_te(struct drm_device
*dev
, int pipe
)
550 struct drm_psb_private
*dev_priv
=
551 (struct drm_psb_private
*) dev
->dev_private
;
552 unsigned long irqflags
;
554 if (!dev_priv
->dsr_enable
)
557 spin_lock_irqsave(&dev_priv
->irqmask_lock
, irqflags
);
559 mid_disable_pipe_event(dev_priv
, pipe
);
560 psb_disable_pipestat(dev_priv
, pipe
, PIPE_TE_ENABLE
);
562 spin_unlock_irqrestore(&dev_priv
->irqmask_lock
, irqflags
);
565 /* Called from drm generic code, passed a 'crtc', which
566 * we use as a pipe index
568 u32
psb_get_vblank_counter(struct drm_device
*dev
, int pipe
)
570 uint32_t high_frame
= PIPEAFRAMEHIGH
;
571 uint32_t low_frame
= PIPEAFRAMEPIXEL
;
572 uint32_t pipeconf_reg
= PIPEACONF
;
573 uint32_t reg_val
= 0;
574 uint32_t high1
= 0, high2
= 0, low
= 0, count
= 0;
580 high_frame
= PIPEBFRAMEHIGH
;
581 low_frame
= PIPEBFRAMEPIXEL
;
582 pipeconf_reg
= PIPEBCONF
;
585 high_frame
= PIPECFRAMEHIGH
;
586 low_frame
= PIPECFRAMEPIXEL
;
587 pipeconf_reg
= PIPECCONF
;
590 dev_err(dev
->dev
, "%s, invalid pipe.\n", __func__
);
594 if (!gma_power_begin(dev
, false))
597 reg_val
= REG_READ(pipeconf_reg
);
599 if (!(reg_val
& PIPEACONF_ENABLE
)) {
600 dev_err(dev
->dev
, "trying to get vblank count for disabled pipe %d\n",
602 goto psb_get_vblank_counter_exit
;
606 * High & low register fields aren't synchronized, so make sure
607 * we get a low value that's stable across two reads of the high
611 high1
= ((REG_READ(high_frame
) & PIPE_FRAME_HIGH_MASK
) >>
612 PIPE_FRAME_HIGH_SHIFT
);
613 low
= ((REG_READ(low_frame
) & PIPE_FRAME_LOW_MASK
) >>
614 PIPE_FRAME_LOW_SHIFT
);
615 high2
= ((REG_READ(high_frame
) & PIPE_FRAME_HIGH_MASK
) >>
616 PIPE_FRAME_HIGH_SHIFT
);
617 } while (high1
!= high2
);
619 count
= (high1
<< 8) | low
;
621 psb_get_vblank_counter_exit
: