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
5 * Copyright (C) The Weather Channel, Inc. 2002.
6 * Copyright 2003 Leif Delgass
9 * The Weather Channel (TM) funded Tungsten Graphics to develop the
10 * initial release of the Radeon 8500 driver under the XFree86 license.
11 * This notice must be preserved.
13 * Permission is hereby granted, free of charge, to any person obtaining a
14 * copy of this software and associated documentation files (the "Software"),
15 * to deal in the Software without restriction, including without limitation
16 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 * and/or sell copies of the Software, and to permit persons to whom the
18 * Software is furnished to do so, subject to the following conditions:
20 * The above copyright notice and this permission notice (including the next
21 * paragraph) shall be included in all copies or substantial portions of the
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 * THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
28 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
29 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 * DEALINGS IN THE SOFTWARE.
33 * Keith Whitwell <keith@tungstengraphics.com>
34 * Eric Anholt <anholt@FreeBSD.org>
35 * Leif Delgass <ldelgass@retinalburn.net>
38 #include <sys/cdefs.h>
39 __FBSDID("$FreeBSD$");
41 #include "dev/drm/drmP.h"
42 #include "dev/drm/drm.h"
43 #include "dev/drm/mach64_drm.h"
44 #include "dev/drm/mach64_drv.h"
46 irqreturn_t mach64_driver_irq_handler(DRM_IRQ_ARGS)
48 struct drm_device *dev = arg;
49 drm_mach64_private_t *dev_priv = dev->dev_private;
52 status = MACH64_READ(MACH64_CRTC_INT_CNTL);
54 /* VBLANK interrupt */
55 if (status & MACH64_CRTC_VBLANK_INT) {
56 /* Mask off all interrupt ack bits before setting the ack bit, since
57 * there may be other handlers outside the DRM.
59 * NOTE: On mach64, you need to keep the enable bits set when doing
60 * the ack, despite what the docs say about not acking and enabling
63 MACH64_WRITE(MACH64_CRTC_INT_CNTL,
64 (status & ~MACH64_CRTC_INT_ACKS)
65 | MACH64_CRTC_VBLANK_INT);
67 atomic_inc(&dev_priv->vbl_received);
68 drm_handle_vblank(dev, 0);
74 u32 mach64_get_vblank_counter(struct drm_device * dev, int crtc)
76 const drm_mach64_private_t *const dev_priv = dev->dev_private;
81 return atomic_read(&dev_priv->vbl_received);
84 int mach64_enable_vblank(struct drm_device * dev, int crtc)
86 drm_mach64_private_t *dev_priv = dev->dev_private;
87 u32 status = MACH64_READ(MACH64_CRTC_INT_CNTL);
90 DRM_ERROR("tried to enable vblank on non-existent crtc %d\n",
95 DRM_DEBUG("before enable vblank CRTC_INT_CTNL: 0x%08x\n", status);
97 /* Turn on VBLANK interrupt */
98 MACH64_WRITE(MACH64_CRTC_INT_CNTL, MACH64_READ(MACH64_CRTC_INT_CNTL)
99 | MACH64_CRTC_VBLANK_INT_EN);
104 void mach64_disable_vblank(struct drm_device * dev, int crtc)
107 DRM_ERROR("tried to disable vblank on non-existent crtc %d\n",
113 * FIXME: implement proper interrupt disable by using the vblank
114 * counter register (if available).
118 static void mach64_disable_vblank_local(struct drm_device * dev, int crtc)
120 drm_mach64_private_t *dev_priv = dev->dev_private;
121 u32 status = MACH64_READ(MACH64_CRTC_INT_CNTL);
124 DRM_ERROR("tried to disable vblank on non-existent crtc %d\n",
129 DRM_DEBUG("before disable vblank CRTC_INT_CTNL: 0x%08x\n", status);
131 /* Disable and clear VBLANK interrupt */
132 MACH64_WRITE(MACH64_CRTC_INT_CNTL, (status & ~MACH64_CRTC_VBLANK_INT_EN)
133 | MACH64_CRTC_VBLANK_INT);
136 void mach64_driver_irq_preinstall(struct drm_device * dev)
138 drm_mach64_private_t *dev_priv = dev->dev_private;
140 u32 status = MACH64_READ(MACH64_CRTC_INT_CNTL);
142 DRM_DEBUG("before install CRTC_INT_CTNL: 0x%08x\n", status);
144 mach64_disable_vblank_local(dev, 0);
147 int mach64_driver_irq_postinstall(struct drm_device * dev)
149 return drm_vblank_init(dev, 1);
152 void mach64_driver_irq_uninstall(struct drm_device * dev)
154 drm_mach64_private_t *dev_priv = dev->dev_private;
158 mach64_disable_vblank_local(dev, 0);
160 DRM_DEBUG("after uninstall CRTC_INT_CTNL: 0x%08x\n",
161 MACH64_READ(MACH64_CRTC_INT_CNTL));