/* r128_irq.c -- IRQ handling for radeon -*- linux-c -*- */1/*2* Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.3*4* The Weather Channel (TM) funded Tungsten Graphics to develop the5* initial release of the Radeon 8500 driver under the XFree86 license.6* This notice must be preserved.7*8* Permission is hereby granted, free of charge, to any person obtaining a9* copy of this software and associated documentation files (the "Software"),10* to deal in the Software without restriction, including without limitation11* the rights to use, copy, modify, merge, publish, distribute, sublicense,12* and/or sell copies of the Software, and to permit persons to whom the13* Software is furnished to do so, subject to the following conditions:14*15* The above copyright notice and this permission notice (including the next16* paragraph) shall be included in all copies or substantial portions of the17* Software.18*19* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR20* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,21* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL22* PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR23* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,24* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER25* DEALINGS IN THE SOFTWARE.26*27* Authors:28* Keith Whitwell <[email protected]>29* Eric Anholt <[email protected]>30*/3132#include "drmP.h"33#include "drm.h"34#include "r128_drm.h"35#include "r128_drv.h"3637u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)38{39const drm_r128_private_t *dev_priv = dev->dev_private;4041if (crtc != 0)42return 0;4344return atomic_read(&dev_priv->vbl_received);45}4647irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)48{49struct drm_device *dev = (struct drm_device *) arg;50drm_r128_private_t *dev_priv = (drm_r128_private_t *) dev->dev_private;51int status;5253status = R128_READ(R128_GEN_INT_STATUS);5455/* VBLANK interrupt */56if (status & R128_CRTC_VBLANK_INT) {57R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);58atomic_inc(&dev_priv->vbl_received);59drm_handle_vblank(dev, 0);60return IRQ_HANDLED;61}62return IRQ_NONE;63}6465int r128_enable_vblank(struct drm_device *dev, int crtc)66{67drm_r128_private_t *dev_priv = dev->dev_private;6869if (crtc != 0) {70DRM_ERROR("%s: bad crtc %d\n", __func__, crtc);71return -EINVAL;72}7374R128_WRITE(R128_GEN_INT_CNTL, R128_CRTC_VBLANK_INT_EN);75return 0;76}7778void r128_disable_vblank(struct drm_device *dev, int crtc)79{80if (crtc != 0)81DRM_ERROR("%s: bad crtc %d\n", __func__, crtc);8283/*84* FIXME: implement proper interrupt disable by using the vblank85* counter register (if available)86*87* R128_WRITE(R128_GEN_INT_CNTL,88* R128_READ(R128_GEN_INT_CNTL) & ~R128_CRTC_VBLANK_INT_EN);89*/90}9192void r128_driver_irq_preinstall(struct drm_device *dev)93{94drm_r128_private_t *dev_priv = (drm_r128_private_t *) dev->dev_private;9596/* Disable *all* interrupts */97R128_WRITE(R128_GEN_INT_CNTL, 0);98/* Clear vblank bit if it's already high */99R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);100}101102int r128_driver_irq_postinstall(struct drm_device *dev)103{104return 0;105}106107void r128_driver_irq_uninstall(struct drm_device *dev)108{109drm_r128_private_t *dev_priv = (drm_r128_private_t *) dev->dev_private;110if (!dev_priv)111return;112113/* Disable *all* interrupts */114R128_WRITE(R128_GEN_INT_CNTL, 0);115}116117118