1 /* mach64_irq.c -- IRQ handling for ATI Mach64 -*- linux-c -*-
2 * Created: Tue Feb 25, 2003 by Leif Delgass, based on radeon_irq.c/r128_irq.c
4 * Copyright (C) The Weather Channel, Inc. 2002.
5 * Copyright 2003 Leif Delgass
8 * The Weather Channel (TM) funded Tungsten Graphics to develop the
9 * initial release of the Radeon 8500 driver under the XFree86 license.
10 * This notice must be preserved.
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the "Software"),
14 * to deal in the Software without restriction, including without limitation
15 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 * and/or sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following conditions:
19 * The above copyright notice and this permission notice (including the next
20 * paragraph) shall be included in all copies or substantial portions of the
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 * THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
27 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
28 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 * DEALINGS IN THE SOFTWARE.
32 * Keith Whitwell <keith@tungstengraphics.com>
33 * Eric Anholt <anholt@FreeBSD.org>
34 * Leif Delgass <ldelgass@retinalburn.net>
39 #include "dev/drm/drmP.h"
40 #include "dev/drm/drm.h"
41 #include "dev/drm/mach64_drm.h"
42 #include "dev/drm/mach64_drv.h"
44 irqreturn_t mach64_driver_irq_handler(DRM_IRQ_ARGS)
46 drm_device_t *dev = (drm_device_t *) arg;
47 drm_mach64_private_t *dev_priv =
48 (drm_mach64_private_t *) dev->dev_private;
51 status = MACH64_READ(MACH64_CRTC_INT_CNTL);
53 /* VBLANK interrupt */
54 if (status & MACH64_CRTC_VBLANK_INT) {
55 /* Mask off all interrupt ack bits before setting the ack bit, since
56 * there may be other handlers outside the DRM.
58 * NOTE: On mach64, you need to keep the enable bits set when doing
59 * the ack, despite what the docs say about not acking and enabling
62 MACH64_WRITE(MACH64_CRTC_INT_CNTL,
63 (status & ~MACH64_CRTC_INT_ACKS)
64 | MACH64_CRTC_VBLANK_INT);
66 atomic_inc(&dev->vbl_received);
67 DRM_WAKEUP(&dev->vbl_queue);
68 drm_vbl_send_signals(dev);
74 int mach64_driver_vblank_wait(drm_device_t * dev, unsigned int *sequence)
76 unsigned int cur_vblank;
79 /* Assume that the user has missed the current sequence number
80 * by about a day rather than she wants to wait for years
81 * using vertical blanks...
83 DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ,
84 (((cur_vblank = atomic_read(&dev->vbl_received))
85 - *sequence) <= (1 << 23)));
87 *sequence = cur_vblank;
94 void mach64_driver_irq_preinstall(drm_device_t * dev)
96 drm_mach64_private_t *dev_priv =
97 (drm_mach64_private_t *) dev->dev_private;
99 u32 status = MACH64_READ(MACH64_CRTC_INT_CNTL);
101 DRM_DEBUG("before install CRTC_INT_CTNL: 0x%08x\n", status);
103 /* Disable and clear VBLANK interrupt */
104 MACH64_WRITE(MACH64_CRTC_INT_CNTL, (status & ~MACH64_CRTC_VBLANK_INT_EN)
105 | MACH64_CRTC_VBLANK_INT);
108 void mach64_driver_irq_postinstall(drm_device_t * dev)
110 drm_mach64_private_t *dev_priv =
111 (drm_mach64_private_t *) dev->dev_private;
113 /* Turn on VBLANK interrupt */
114 MACH64_WRITE(MACH64_CRTC_INT_CNTL, MACH64_READ(MACH64_CRTC_INT_CNTL)
115 | MACH64_CRTC_VBLANK_INT_EN);
117 DRM_DEBUG("after install CRTC_INT_CTNL: 0x%08x\n",
118 MACH64_READ(MACH64_CRTC_INT_CNTL));
122 void mach64_driver_irq_uninstall(drm_device_t * dev)
124 drm_mach64_private_t *dev_priv =
125 (drm_mach64_private_t *) dev->dev_private;
129 /* Disable and clear VBLANK interrupt */
130 MACH64_WRITE(MACH64_CRTC_INT_CNTL,
131 (MACH64_READ(MACH64_CRTC_INT_CNTL) &
132 ~MACH64_CRTC_VBLANK_INT_EN)
133 | MACH64_CRTC_VBLANK_INT);
135 DRM_DEBUG("after uninstall CRTC_INT_CTNL: 0x%08x\n",
136 MACH64_READ(MACH64_CRTC_INT_CNTL));