blob: 2fcdffdc906313836dc700b3ed6bcdc9620f277a [file] [log] [blame]
Alan Cox5c49fd32011-11-03 18:22:04 +00001/**************************************************************************
2 * Copyright (c) 2007, Intel Corporation.
3 * All Rights Reserved.
4 *
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.
8 *
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
12 * more details.
13 *
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.
17 *
18 * Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
19 * develop this driver.
20 *
21 **************************************************************************/
22/*
23 */
24
25#include <drm/drmP.h>
26#include "psb_drv.h"
27#include "psb_reg.h"
28#include "psb_intel_reg.h"
29#include "power.h"
Kirill A. Shutemov026abc32012-03-08 16:02:20 +000030#include "psb_irq.h"
31#include "mdfld_output.h"
Alan Cox5c49fd32011-11-03 18:22:04 +000032
33/*
34 * inline functions
35 */
36
37static inline u32
38psb_pipestat(int pipe)
39{
40 if (pipe == 0)
41 return PIPEASTAT;
42 if (pipe == 1)
43 return PIPEBSTAT;
44 if (pipe == 2)
45 return PIPECSTAT;
46 BUG();
47}
48
49static inline u32
50mid_pipe_event(int pipe)
51{
52 if (pipe == 0)
53 return _PSB_PIPEA_EVENT_FLAG;
54 if (pipe == 1)
55 return _MDFLD_PIPEB_EVENT_FLAG;
56 if (pipe == 2)
57 return _MDFLD_PIPEC_EVENT_FLAG;
58 BUG();
59}
60
61static inline u32
62mid_pipe_vsync(int pipe)
63{
64 if (pipe == 0)
65 return _PSB_VSYNC_PIPEA_FLAG;
66 if (pipe == 1)
67 return _PSB_VSYNC_PIPEB_FLAG;
68 if (pipe == 2)
69 return _MDFLD_PIPEC_VBLANK_FLAG;
70 BUG();
71}
72
73static inline u32
74mid_pipeconf(int pipe)
75{
76 if (pipe == 0)
77 return PIPEACONF;
78 if (pipe == 1)
79 return PIPEBCONF;
80 if (pipe == 2)
81 return PIPECCONF;
82 BUG();
83}
84
85void
86psb_enable_pipestat(struct drm_psb_private *dev_priv, int pipe, u32 mask)
87{
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);
98 }
99 }
100}
101
102void
103psb_disable_pipestat(struct drm_psb_private *dev_priv, int pipe, u32 mask)
104{
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);
110 writeVal &= ~mask;
111 PSB_WVDC32(writeVal, reg);
112 (void) PSB_RVDC32(reg);
113 gma_power_end(dev_priv->dev);
114 }
115 }
116}
117
Kirill A. Shutemov8e18db82012-03-08 16:15:47 +0000118static void mid_enable_pipe_event(struct drm_psb_private *dev_priv, int pipe)
Alan Cox5c49fd32011-11-03 18:22:04 +0000119{
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);
126 }
127}
128
Kirill A. Shutemov8e18db82012-03-08 16:15:47 +0000129static void mid_disable_pipe_event(struct drm_psb_private *dev_priv, int pipe)
Alan Cox5c49fd32011-11-03 18:22:04 +0000130{
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);
138 }
139 }
140}
141
142/**
Alan Cox5c49fd32011-11-03 18:22:04 +0000143 * Display controller interrupt handler for pipe event.
144 *
145 */
Patrik Jakobsson700e59f2011-11-29 22:20:34 +0000146static void mid_pipe_event_handler(struct drm_device *dev, int pipe)
Alan Cox5c49fd32011-11-03 18:22:04 +0000147{
148 struct drm_psb_private *dev_priv =
149 (struct drm_psb_private *) dev->dev_private;
150
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;
Patrik Jakobsson700e59f2011-11-29 22:20:34 +0000155 uint32_t pipe_clear;
Alan Cox5c49fd32011-11-03 18:22:04 +0000156 uint32_t i = 0;
157
158 spin_lock(&dev_priv->irqmask_lock);
159
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;
163
164 spin_unlock(&dev_priv->irqmask_lock);
165
Patrik Jakobsson700e59f2011-11-29 22:20:34 +0000166 /* 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++) {
Alan Cox5c49fd32011-11-03 18:22:04 +0000169 PSB_WVDC32(PSB_RVDC32(pipe_stat_reg), pipe_stat_reg);
Patrik Jakobsson700e59f2011-11-29 22:20:34 +0000170 pipe_clear = PSB_RVDC32(pipe_stat_reg) & pipe_status;
Alan Cox5c49fd32011-11-03 18:22:04 +0000171
Patrik Jakobsson700e59f2011-11-29 22:20:34 +0000172 if (pipe_clear == 0)
Alan Cox5c49fd32011-11-03 18:22:04 +0000173 break;
174 }
175
Patrik Jakobsson700e59f2011-11-29 22:20:34 +0000176 if (pipe_clear)
Alan Cox5c49fd32011-11-03 18:22:04 +0000177 dev_err(dev->dev,
Patrik Jakobsson700e59f2011-11-29 22:20:34 +0000178 "%s, can't clear status bits for pipe %d, its value = 0x%x.\n",
179 __func__, pipe, PSB_RVDC32(pipe_stat_reg));
Alan Cox5c49fd32011-11-03 18:22:04 +0000180
181 if (pipe_stat_val & PIPE_VBLANK_STATUS)
Patrik Jakobsson700e59f2011-11-29 22:20:34 +0000182 drm_handle_vblank(dev, pipe);
Alan Cox5c49fd32011-11-03 18:22:04 +0000183
184 if (pipe_stat_val & PIPE_TE_STATUS)
185 drm_handle_vblank(dev, pipe);
186}
187
188/*
189 * Display controller interrupt handler.
190 */
191static void psb_vdc_interrupt(struct drm_device *dev, uint32_t vdc_stat)
192{
Patrik Jakobsson700e59f2011-11-29 22:20:34 +0000193 if (vdc_stat & _PSB_VSYNC_PIPEA_FLAG)
Alan Cox5c49fd32011-11-03 18:22:04 +0000194 mid_pipe_event_handler(dev, 0);
Patrik Jakobsson700e59f2011-11-29 22:20:34 +0000195
196 if (vdc_stat & _PSB_VSYNC_PIPEB_FLAG)
197 mid_pipe_event_handler(dev, 1);
Alan Cox5c49fd32011-11-03 18:22:04 +0000198}
199
200irqreturn_t psb_irq_handler(DRM_IRQ_ARGS)
201{
Alan Cox68cb6382012-04-25 14:38:20 +0100202 struct drm_device *dev = arg;
203 struct drm_psb_private *dev_priv = dev->dev_private;
204 uint32_t vdc_stat, dsp_int = 0, sgx_int = 0, hotplug_int = 0;
Alan Cox5c49fd32011-11-03 18:22:04 +0000205 int handled = 0;
206
207 spin_lock(&dev_priv->irqmask_lock);
208
209 vdc_stat = PSB_RVDC32(PSB_INT_IDENTITY_R);
210
Patrik Jakobsson700e59f2011-11-29 22:20:34 +0000211 if (vdc_stat & _PSB_PIPE_EVENT_FLAG)
212 dsp_int = 1;
213
214 /* FIXME: Handle Medfield
Alan Cox5c49fd32011-11-03 18:22:04 +0000215 if (vdc_stat & _MDFLD_DISP_ALL_IRQ_FLAG)
216 dsp_int = 1;
Patrik Jakobsson700e59f2011-11-29 22:20:34 +0000217 */
Alan Cox5c49fd32011-11-03 18:22:04 +0000218
219 if (vdc_stat & _PSB_IRQ_SGX_FLAG)
220 sgx_int = 1;
Alan Cox68cb6382012-04-25 14:38:20 +0100221 if (vdc_stat & _PSB_IRQ_DISP_HOTSYNC)
222 hotplug_int = 1;
Alan Cox5c49fd32011-11-03 18:22:04 +0000223
224 vdc_stat &= dev_priv->vdc_irq_mask;
225 spin_unlock(&dev_priv->irqmask_lock);
226
227 if (dsp_int && gma_power_is_on(dev)) {
228 psb_vdc_interrupt(dev, vdc_stat);
229 handled = 1;
230 }
231
232 if (sgx_int) {
233 /* Not expected - we have it masked, shut it up */
234 u32 s, s2;
235 s = PSB_RSGX32(PSB_CR_EVENT_STATUS);
236 s2 = PSB_RSGX32(PSB_CR_EVENT_STATUS2);
237 PSB_WSGX32(s, PSB_CR_EVENT_HOST_CLEAR);
238 PSB_WSGX32(s2, PSB_CR_EVENT_HOST_CLEAR2);
239 /* if s & _PSB_CE_TWOD_COMPLETE we have 2D done but
240 we may as well poll even if we add that ! */
241 handled = 1;
242 }
243
Alan Cox68cb6382012-04-25 14:38:20 +0100244 /* Note: this bit has other meanings on some devices, so we will
245 need to address that later if it ever matters */
246 if (hotplug_int && dev_priv->ops->hotplug) {
247 handled = dev_priv->ops->hotplug(dev);
248 REG_WRITE(PORT_HOTPLUG_STAT, REG_READ(PORT_HOTPLUG_STAT));
249 }
250
Alan Cox5c49fd32011-11-03 18:22:04 +0000251 PSB_WVDC32(vdc_stat, PSB_INT_IDENTITY_R);
252 (void) PSB_RVDC32(PSB_INT_IDENTITY_R);
253 DRM_READMEMORYBARRIER();
254
255 if (!handled)
256 return IRQ_NONE;
257
258 return IRQ_HANDLED;
259}
260
261void psb_irq_preinstall(struct drm_device *dev)
262{
263 struct drm_psb_private *dev_priv =
264 (struct drm_psb_private *) dev->dev_private;
265 unsigned long irqflags;
266
267 spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
268
269 if (gma_power_is_on(dev))
270 PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM);
271 if (dev->vblank_enabled[0])
Patrik Jakobsson700e59f2011-11-29 22:20:34 +0000272 dev_priv->vdc_irq_mask |= _PSB_VSYNC_PIPEA_FLAG;
273 if (dev->vblank_enabled[1])
274 dev_priv->vdc_irq_mask |= _PSB_VSYNC_PIPEB_FLAG;
275
276 /* FIXME: Handle Medfield irq mask
Alan Cox5c49fd32011-11-03 18:22:04 +0000277 if (dev->vblank_enabled[1])
278 dev_priv->vdc_irq_mask |= _MDFLD_PIPEB_EVENT_FLAG;
279 if (dev->vblank_enabled[2])
280 dev_priv->vdc_irq_mask |= _MDFLD_PIPEC_EVENT_FLAG;
Patrik Jakobsson700e59f2011-11-29 22:20:34 +0000281 */
Alan Cox5c49fd32011-11-03 18:22:04 +0000282
Alan Cox68cb6382012-04-25 14:38:20 +0100283 /* Revisit this area - want per device masks ? */
284 if (dev_priv->ops->hotplug)
285 dev_priv->vdc_irq_mask |= _PSB_IRQ_DISP_HOTSYNC;
286
Patrik Jakobsson700e59f2011-11-29 22:20:34 +0000287 /* This register is safe even if display island is off */
Alan Cox5c49fd32011-11-03 18:22:04 +0000288 PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R);
289 spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
290}
291
292int psb_irq_postinstall(struct drm_device *dev)
293{
294 struct drm_psb_private *dev_priv =
295 (struct drm_psb_private *) dev->dev_private;
296 unsigned long irqflags;
297
298 spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
299
300 /* This register is safe even if display island is off */
301 PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R);
302 PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM);
303
304 if (dev->vblank_enabled[0])
305 psb_enable_pipestat(dev_priv, 0, PIPE_VBLANK_INTERRUPT_ENABLE);
306 else
307 psb_disable_pipestat(dev_priv, 0, PIPE_VBLANK_INTERRUPT_ENABLE);
308
309 if (dev->vblank_enabled[1])
310 psb_enable_pipestat(dev_priv, 1, PIPE_VBLANK_INTERRUPT_ENABLE);
311 else
312 psb_disable_pipestat(dev_priv, 1, PIPE_VBLANK_INTERRUPT_ENABLE);
313
314 if (dev->vblank_enabled[2])
315 psb_enable_pipestat(dev_priv, 2, PIPE_VBLANK_INTERRUPT_ENABLE);
316 else
317 psb_disable_pipestat(dev_priv, 2, PIPE_VBLANK_INTERRUPT_ENABLE);
318
Alan Cox68cb6382012-04-25 14:38:20 +0100319 if (dev_priv->ops->hotplug_enable)
320 dev_priv->ops->hotplug_enable(dev, true);
321
Alan Cox5c49fd32011-11-03 18:22:04 +0000322 spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
323 return 0;
324}
325
326void psb_irq_uninstall(struct drm_device *dev)
327{
Alan Cox68cb6382012-04-25 14:38:20 +0100328 struct drm_psb_private *dev_priv = dev->dev_private;
Alan Cox5c49fd32011-11-03 18:22:04 +0000329 unsigned long irqflags;
330
331 spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
332
Alan Cox68cb6382012-04-25 14:38:20 +0100333 if (dev_priv->ops->hotplug_enable)
334 dev_priv->ops->hotplug_enable(dev, false);
335
Alan Cox5c49fd32011-11-03 18:22:04 +0000336 PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM);
337
338 if (dev->vblank_enabled[0])
339 psb_disable_pipestat(dev_priv, 0, PIPE_VBLANK_INTERRUPT_ENABLE);
340
341 if (dev->vblank_enabled[1])
342 psb_disable_pipestat(dev_priv, 1, PIPE_VBLANK_INTERRUPT_ENABLE);
343
344 if (dev->vblank_enabled[2])
345 psb_disable_pipestat(dev_priv, 2, PIPE_VBLANK_INTERRUPT_ENABLE);
346
347 dev_priv->vdc_irq_mask &= _PSB_IRQ_SGX_FLAG |
348 _PSB_IRQ_MSVDX_FLAG |
349 _LNC_IRQ_TOPAZ_FLAG;
350
351 /* These two registers are safe even if display island is off */
352 PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R);
353 PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R);
354
355 wmb();
356
357 /* This register is safe even if display island is off */
358 PSB_WVDC32(PSB_RVDC32(PSB_INT_IDENTITY_R), PSB_INT_IDENTITY_R);
359 spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
360}
361
362void psb_irq_turn_on_dpst(struct drm_device *dev)
363{
364 struct drm_psb_private *dev_priv =
365 (struct drm_psb_private *) dev->dev_private;
366 u32 hist_reg;
367 u32 pwm_reg;
368
369 if (gma_power_begin(dev, false)) {
370 PSB_WVDC32(1 << 31, HISTOGRAM_LOGIC_CONTROL);
371 hist_reg = PSB_RVDC32(HISTOGRAM_LOGIC_CONTROL);
372 PSB_WVDC32(1 << 31, HISTOGRAM_INT_CONTROL);
373 hist_reg = PSB_RVDC32(HISTOGRAM_INT_CONTROL);
374
375 PSB_WVDC32(0x80010100, PWM_CONTROL_LOGIC);
376 pwm_reg = PSB_RVDC32(PWM_CONTROL_LOGIC);
377 PSB_WVDC32(pwm_reg | PWM_PHASEIN_ENABLE
378 | PWM_PHASEIN_INT_ENABLE,
379 PWM_CONTROL_LOGIC);
380 pwm_reg = PSB_RVDC32(PWM_CONTROL_LOGIC);
381
382 psb_enable_pipestat(dev_priv, 0, PIPE_DPST_EVENT_ENABLE);
383
384 hist_reg = PSB_RVDC32(HISTOGRAM_INT_CONTROL);
385 PSB_WVDC32(hist_reg | HISTOGRAM_INT_CTRL_CLEAR,
386 HISTOGRAM_INT_CONTROL);
387 pwm_reg = PSB_RVDC32(PWM_CONTROL_LOGIC);
388 PSB_WVDC32(pwm_reg | 0x80010100 | PWM_PHASEIN_ENABLE,
389 PWM_CONTROL_LOGIC);
390
391 gma_power_end(dev);
392 }
393}
394
395int psb_irq_enable_dpst(struct drm_device *dev)
396{
397 struct drm_psb_private *dev_priv =
398 (struct drm_psb_private *) dev->dev_private;
399 unsigned long irqflags;
400
401 spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
402
403 /* enable DPST */
404 mid_enable_pipe_event(dev_priv, 0);
405 psb_irq_turn_on_dpst(dev);
406
407 spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
408 return 0;
409}
410
411void psb_irq_turn_off_dpst(struct drm_device *dev)
412{
413 struct drm_psb_private *dev_priv =
414 (struct drm_psb_private *) dev->dev_private;
415 u32 hist_reg;
416 u32 pwm_reg;
417
418 if (gma_power_begin(dev, false)) {
419 PSB_WVDC32(0x00000000, HISTOGRAM_INT_CONTROL);
420 hist_reg = PSB_RVDC32(HISTOGRAM_INT_CONTROL);
421
422 psb_disable_pipestat(dev_priv, 0, PIPE_DPST_EVENT_ENABLE);
423
424 pwm_reg = PSB_RVDC32(PWM_CONTROL_LOGIC);
425 PSB_WVDC32(pwm_reg & !(PWM_PHASEIN_INT_ENABLE),
426 PWM_CONTROL_LOGIC);
427 pwm_reg = PSB_RVDC32(PWM_CONTROL_LOGIC);
428
429 gma_power_end(dev);
430 }
431}
432
433int psb_irq_disable_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 mid_disable_pipe_event(dev_priv, 0);
442 psb_irq_turn_off_dpst(dev);
443
444 spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
445
446 return 0;
447}
448
449#ifdef PSB_FIXME
450static int psb_vblank_do_wait(struct drm_device *dev,
451 unsigned int *sequence, atomic_t *counter)
452{
453 unsigned int cur_vblank;
454 int ret = 0;
455 DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ,
456 (((cur_vblank = atomic_read(counter))
457 - *sequence) <= (1 << 23)));
458 *sequence = cur_vblank;
459
460 return ret;
461}
462#endif
463
464/*
465 * It is used to enable VBLANK interrupt
466 */
467int psb_enable_vblank(struct drm_device *dev, int pipe)
468{
469 struct drm_psb_private *dev_priv = dev->dev_private;
470 unsigned long irqflags;
471 uint32_t reg_val = 0;
472 uint32_t pipeconf_reg = mid_pipeconf(pipe);
473
Kirill A. Shutemov026abc32012-03-08 16:02:20 +0000474 /* Medfield is different - we should perhaps extract out vblank
475 and blacklight etc ops */
476 if (IS_MFLD(dev))
477 return mdfld_enable_te(dev, pipe);
478
Alan Cox5c49fd32011-11-03 18:22:04 +0000479 if (gma_power_begin(dev, false)) {
480 reg_val = REG_READ(pipeconf_reg);
481 gma_power_end(dev);
482 }
483
484 if (!(reg_val & PIPEACONF_ENABLE))
485 return -EINVAL;
486
487 spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
488
Patrik Jakobsson700e59f2011-11-29 22:20:34 +0000489 if (pipe == 0)
490 dev_priv->vdc_irq_mask |= _PSB_VSYNC_PIPEA_FLAG;
491 else if (pipe == 1)
492 dev_priv->vdc_irq_mask |= _PSB_VSYNC_PIPEB_FLAG;
493
494 PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R);
495 PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R);
Alan Cox5c49fd32011-11-03 18:22:04 +0000496 psb_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_ENABLE);
497
498 spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
499
500 return 0;
501}
502
503/*
504 * It is used to disable VBLANK interrupt
505 */
506void psb_disable_vblank(struct drm_device *dev, int pipe)
507{
508 struct drm_psb_private *dev_priv = dev->dev_private;
509 unsigned long irqflags;
510
Kirill A. Shutemov026abc32012-03-08 16:02:20 +0000511 if (IS_MFLD(dev))
512 mdfld_disable_te(dev, pipe);
Alan Cox5c49fd32011-11-03 18:22:04 +0000513 spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
514
Patrik Jakobsson700e59f2011-11-29 22:20:34 +0000515 if (pipe == 0)
516 dev_priv->vdc_irq_mask &= ~_PSB_VSYNC_PIPEA_FLAG;
517 else if (pipe == 1)
518 dev_priv->vdc_irq_mask &= ~_PSB_VSYNC_PIPEB_FLAG;
519
520 PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R);
521 PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R);
Alan Cox5c49fd32011-11-03 18:22:04 +0000522 psb_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_ENABLE);
523
524 spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
525}
526
Kirill A. Shutemov026abc32012-03-08 16:02:20 +0000527/*
528 * It is used to enable TE interrupt
529 */
530int mdfld_enable_te(struct drm_device *dev, int pipe)
531{
532 struct drm_psb_private *dev_priv =
533 (struct drm_psb_private *) dev->dev_private;
534 unsigned long irqflags;
535 uint32_t reg_val = 0;
536 uint32_t pipeconf_reg = mid_pipeconf(pipe);
537
538 if (gma_power_begin(dev, false)) {
539 reg_val = REG_READ(pipeconf_reg);
540 gma_power_end(dev);
541 }
542
543 if (!(reg_val & PIPEACONF_ENABLE))
544 return -EINVAL;
545
546 spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
547
548 mid_enable_pipe_event(dev_priv, pipe);
549 psb_enable_pipestat(dev_priv, pipe, PIPE_TE_ENABLE);
550
551 spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
552
553 return 0;
554}
555
556/*
557 * It is used to disable TE interrupt
558 */
559void mdfld_disable_te(struct drm_device *dev, int pipe)
560{
561 struct drm_psb_private *dev_priv =
562 (struct drm_psb_private *) dev->dev_private;
563 unsigned long irqflags;
564
565 if (!dev_priv->dsr_enable)
566 return;
567
568 spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
569
570 mid_disable_pipe_event(dev_priv, pipe);
571 psb_disable_pipestat(dev_priv, pipe, PIPE_TE_ENABLE);
572
573 spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
574}
575
Alan Cox5c49fd32011-11-03 18:22:04 +0000576/* Called from drm generic code, passed a 'crtc', which
577 * we use as a pipe index
578 */
579u32 psb_get_vblank_counter(struct drm_device *dev, int pipe)
580{
581 uint32_t high_frame = PIPEAFRAMEHIGH;
582 uint32_t low_frame = PIPEAFRAMEPIXEL;
583 uint32_t pipeconf_reg = PIPEACONF;
584 uint32_t reg_val = 0;
585 uint32_t high1 = 0, high2 = 0, low = 0, count = 0;
586
587 switch (pipe) {
588 case 0:
589 break;
590 case 1:
591 high_frame = PIPEBFRAMEHIGH;
592 low_frame = PIPEBFRAMEPIXEL;
593 pipeconf_reg = PIPEBCONF;
594 break;
595 case 2:
596 high_frame = PIPECFRAMEHIGH;
597 low_frame = PIPECFRAMEPIXEL;
598 pipeconf_reg = PIPECCONF;
599 break;
600 default:
601 dev_err(dev->dev, "%s, invalid pipe.\n", __func__);
602 return 0;
603 }
604
605 if (!gma_power_begin(dev, false))
606 return 0;
607
608 reg_val = REG_READ(pipeconf_reg);
609
610 if (!(reg_val & PIPEACONF_ENABLE)) {
611 dev_err(dev->dev, "trying to get vblank count for disabled pipe %d\n",
612 pipe);
613 goto psb_get_vblank_counter_exit;
614 }
615
616 /*
617 * High & low register fields aren't synchronized, so make sure
618 * we get a low value that's stable across two reads of the high
619 * register.
620 */
621 do {
622 high1 = ((REG_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >>
623 PIPE_FRAME_HIGH_SHIFT);
624 low = ((REG_READ(low_frame) & PIPE_FRAME_LOW_MASK) >>
625 PIPE_FRAME_LOW_SHIFT);
626 high2 = ((REG_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >>
627 PIPE_FRAME_HIGH_SHIFT);
628 } while (high1 != high2);
629
630 count = (high1 << 8) | low;
631
632psb_get_vblank_counter_exit:
633
634 gma_power_end(dev);
635
636 return count;
637}
638