18c2ecf20Sopenharmony_ci/* r128_irq.c -- IRQ handling for radeon -*- linux-c -*- */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * The Weather Channel (TM) funded Tungsten Graphics to develop the 68c2ecf20Sopenharmony_ci * initial release of the Radeon 8500 driver under the XFree86 license. 78c2ecf20Sopenharmony_ci * This notice must be preserved. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 108c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 118c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation 128c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 138c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 148c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the next 178c2ecf20Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 188c2ecf20Sopenharmony_ci * Software. 198c2ecf20Sopenharmony_ci * 208c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 218c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 228c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 238c2ecf20Sopenharmony_ci * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 248c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 258c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 268c2ecf20Sopenharmony_ci * DEALINGS IN THE SOFTWARE. 278c2ecf20Sopenharmony_ci * 288c2ecf20Sopenharmony_ci * Authors: 298c2ecf20Sopenharmony_ci * Keith Whitwell <keith@tungstengraphics.com> 308c2ecf20Sopenharmony_ci * Eric Anholt <anholt@FreeBSD.org> 318c2ecf20Sopenharmony_ci */ 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#include <drm/drm_device.h> 348c2ecf20Sopenharmony_ci#include <drm/drm_print.h> 358c2ecf20Sopenharmony_ci#include <drm/drm_vblank.h> 368c2ecf20Sopenharmony_ci#include <drm/r128_drm.h> 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#include "r128_drv.h" 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ciu32 r128_get_vblank_counter(struct drm_device *dev, unsigned int pipe) 418c2ecf20Sopenharmony_ci{ 428c2ecf20Sopenharmony_ci const drm_r128_private_t *dev_priv = dev->dev_private; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci if (pipe != 0) 458c2ecf20Sopenharmony_ci return 0; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci return atomic_read(&dev_priv->vbl_received); 488c2ecf20Sopenharmony_ci} 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ciirqreturn_t r128_driver_irq_handler(int irq, void *arg) 518c2ecf20Sopenharmony_ci{ 528c2ecf20Sopenharmony_ci struct drm_device *dev = (struct drm_device *) arg; 538c2ecf20Sopenharmony_ci drm_r128_private_t *dev_priv = (drm_r128_private_t *) dev->dev_private; 548c2ecf20Sopenharmony_ci int status; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci status = R128_READ(R128_GEN_INT_STATUS); 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci /* VBLANK interrupt */ 598c2ecf20Sopenharmony_ci if (status & R128_CRTC_VBLANK_INT) { 608c2ecf20Sopenharmony_ci R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK); 618c2ecf20Sopenharmony_ci atomic_inc(&dev_priv->vbl_received); 628c2ecf20Sopenharmony_ci drm_handle_vblank(dev, 0); 638c2ecf20Sopenharmony_ci return IRQ_HANDLED; 648c2ecf20Sopenharmony_ci } 658c2ecf20Sopenharmony_ci return IRQ_NONE; 668c2ecf20Sopenharmony_ci} 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ciint r128_enable_vblank(struct drm_device *dev, unsigned int pipe) 698c2ecf20Sopenharmony_ci{ 708c2ecf20Sopenharmony_ci drm_r128_private_t *dev_priv = dev->dev_private; 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci if (pipe != 0) { 738c2ecf20Sopenharmony_ci DRM_ERROR("%s: bad crtc %u\n", __func__, pipe); 748c2ecf20Sopenharmony_ci return -EINVAL; 758c2ecf20Sopenharmony_ci } 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci R128_WRITE(R128_GEN_INT_CNTL, R128_CRTC_VBLANK_INT_EN); 788c2ecf20Sopenharmony_ci return 0; 798c2ecf20Sopenharmony_ci} 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_civoid r128_disable_vblank(struct drm_device *dev, unsigned int pipe) 828c2ecf20Sopenharmony_ci{ 838c2ecf20Sopenharmony_ci if (pipe != 0) 848c2ecf20Sopenharmony_ci DRM_ERROR("%s: bad crtc %u\n", __func__, pipe); 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci /* 878c2ecf20Sopenharmony_ci * FIXME: implement proper interrupt disable by using the vblank 888c2ecf20Sopenharmony_ci * counter register (if available) 898c2ecf20Sopenharmony_ci * 908c2ecf20Sopenharmony_ci * R128_WRITE(R128_GEN_INT_CNTL, 918c2ecf20Sopenharmony_ci * R128_READ(R128_GEN_INT_CNTL) & ~R128_CRTC_VBLANK_INT_EN); 928c2ecf20Sopenharmony_ci */ 938c2ecf20Sopenharmony_ci} 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_civoid r128_driver_irq_preinstall(struct drm_device *dev) 968c2ecf20Sopenharmony_ci{ 978c2ecf20Sopenharmony_ci drm_r128_private_t *dev_priv = (drm_r128_private_t *) dev->dev_private; 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci /* Disable *all* interrupts */ 1008c2ecf20Sopenharmony_ci R128_WRITE(R128_GEN_INT_CNTL, 0); 1018c2ecf20Sopenharmony_ci /* Clear vblank bit if it's already high */ 1028c2ecf20Sopenharmony_ci R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK); 1038c2ecf20Sopenharmony_ci} 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ciint r128_driver_irq_postinstall(struct drm_device *dev) 1068c2ecf20Sopenharmony_ci{ 1078c2ecf20Sopenharmony_ci return 0; 1088c2ecf20Sopenharmony_ci} 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_civoid r128_driver_irq_uninstall(struct drm_device *dev) 1118c2ecf20Sopenharmony_ci{ 1128c2ecf20Sopenharmony_ci drm_r128_private_t *dev_priv = (drm_r128_private_t *) dev->dev_private; 1138c2ecf20Sopenharmony_ci if (!dev_priv) 1148c2ecf20Sopenharmony_ci return; 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci /* Disable *all* interrupts */ 1178c2ecf20Sopenharmony_ci R128_WRITE(R128_GEN_INT_CNTL, 0); 1188c2ecf20Sopenharmony_ci} 119