1 1.2 riastrad /* $NetBSD: r128_irq.c,v 1.3 2021/12/18 23:45:42 riastradh Exp $ */ 2 1.2 riastrad 3 1.1 riastrad /* r128_irq.c -- IRQ handling for radeon -*- linux-c -*- */ 4 1.1 riastrad /* 5 1.1 riastrad * Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved. 6 1.1 riastrad * 7 1.1 riastrad * The Weather Channel (TM) funded Tungsten Graphics to develop the 8 1.1 riastrad * initial release of the Radeon 8500 driver under the XFree86 license. 9 1.1 riastrad * This notice must be preserved. 10 1.1 riastrad * 11 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining a 12 1.1 riastrad * copy of this software and associated documentation files (the "Software"), 13 1.1 riastrad * to deal in the Software without restriction, including without limitation 14 1.1 riastrad * the rights to use, copy, modify, merge, publish, distribute, sublicense, 15 1.1 riastrad * and/or sell copies of the Software, and to permit persons to whom the 16 1.1 riastrad * Software is furnished to do so, subject to the following conditions: 17 1.1 riastrad * 18 1.1 riastrad * The above copyright notice and this permission notice (including the next 19 1.1 riastrad * paragraph) shall be included in all copies or substantial portions of the 20 1.1 riastrad * Software. 21 1.1 riastrad * 22 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 1.1 riastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 1.1 riastrad * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 25 1.1 riastrad * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 26 1.1 riastrad * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 27 1.1 riastrad * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 28 1.1 riastrad * DEALINGS IN THE SOFTWARE. 29 1.1 riastrad * 30 1.1 riastrad * Authors: 31 1.1 riastrad * Keith Whitwell <keith (at) tungstengraphics.com> 32 1.1 riastrad * Eric Anholt <anholt (at) FreeBSD.org> 33 1.1 riastrad */ 34 1.1 riastrad 35 1.2 riastrad #include <sys/cdefs.h> 36 1.2 riastrad __KERNEL_RCSID(0, "$NetBSD: r128_irq.c,v 1.3 2021/12/18 23:45:42 riastradh Exp $"); 37 1.2 riastrad 38 1.3 riastrad #include <drm/drm_device.h> 39 1.3 riastrad #include <drm/drm_print.h> 40 1.3 riastrad #include <drm/drm_vblank.h> 41 1.1 riastrad #include <drm/r128_drm.h> 42 1.3 riastrad 43 1.1 riastrad #include "r128_drv.h" 44 1.1 riastrad 45 1.2 riastrad u32 r128_get_vblank_counter(struct drm_device *dev, unsigned int pipe) 46 1.1 riastrad { 47 1.1 riastrad const drm_r128_private_t *dev_priv = dev->dev_private; 48 1.1 riastrad 49 1.2 riastrad if (pipe != 0) 50 1.1 riastrad return 0; 51 1.1 riastrad 52 1.1 riastrad return atomic_read(&dev_priv->vbl_received); 53 1.1 riastrad } 54 1.1 riastrad 55 1.2 riastrad irqreturn_t r128_driver_irq_handler(int irq, void *arg) 56 1.1 riastrad { 57 1.1 riastrad struct drm_device *dev = (struct drm_device *) arg; 58 1.1 riastrad drm_r128_private_t *dev_priv = (drm_r128_private_t *) dev->dev_private; 59 1.1 riastrad int status; 60 1.1 riastrad 61 1.1 riastrad status = R128_READ(R128_GEN_INT_STATUS); 62 1.1 riastrad 63 1.1 riastrad /* VBLANK interrupt */ 64 1.1 riastrad if (status & R128_CRTC_VBLANK_INT) { 65 1.1 riastrad R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK); 66 1.1 riastrad atomic_inc(&dev_priv->vbl_received); 67 1.1 riastrad drm_handle_vblank(dev, 0); 68 1.1 riastrad return IRQ_HANDLED; 69 1.1 riastrad } 70 1.1 riastrad return IRQ_NONE; 71 1.1 riastrad } 72 1.1 riastrad 73 1.2 riastrad int r128_enable_vblank(struct drm_device *dev, unsigned int pipe) 74 1.1 riastrad { 75 1.1 riastrad drm_r128_private_t *dev_priv = dev->dev_private; 76 1.1 riastrad 77 1.2 riastrad if (pipe != 0) { 78 1.2 riastrad DRM_ERROR("%s: bad crtc %u\n", __func__, pipe); 79 1.1 riastrad return -EINVAL; 80 1.1 riastrad } 81 1.1 riastrad 82 1.1 riastrad R128_WRITE(R128_GEN_INT_CNTL, R128_CRTC_VBLANK_INT_EN); 83 1.1 riastrad return 0; 84 1.1 riastrad } 85 1.1 riastrad 86 1.2 riastrad void r128_disable_vblank(struct drm_device *dev, unsigned int pipe) 87 1.1 riastrad { 88 1.2 riastrad if (pipe != 0) 89 1.2 riastrad DRM_ERROR("%s: bad crtc %u\n", __func__, pipe); 90 1.1 riastrad 91 1.1 riastrad /* 92 1.1 riastrad * FIXME: implement proper interrupt disable by using the vblank 93 1.1 riastrad * counter register (if available) 94 1.1 riastrad * 95 1.1 riastrad * R128_WRITE(R128_GEN_INT_CNTL, 96 1.1 riastrad * R128_READ(R128_GEN_INT_CNTL) & ~R128_CRTC_VBLANK_INT_EN); 97 1.1 riastrad */ 98 1.1 riastrad } 99 1.1 riastrad 100 1.1 riastrad void r128_driver_irq_preinstall(struct drm_device *dev) 101 1.1 riastrad { 102 1.1 riastrad drm_r128_private_t *dev_priv = (drm_r128_private_t *) dev->dev_private; 103 1.1 riastrad 104 1.1 riastrad /* Disable *all* interrupts */ 105 1.1 riastrad R128_WRITE(R128_GEN_INT_CNTL, 0); 106 1.1 riastrad /* Clear vblank bit if it's already high */ 107 1.1 riastrad R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK); 108 1.1 riastrad } 109 1.1 riastrad 110 1.1 riastrad int r128_driver_irq_postinstall(struct drm_device *dev) 111 1.1 riastrad { 112 1.1 riastrad return 0; 113 1.1 riastrad } 114 1.1 riastrad 115 1.1 riastrad void r128_driver_irq_uninstall(struct drm_device *dev) 116 1.1 riastrad { 117 1.1 riastrad drm_r128_private_t *dev_priv = (drm_r128_private_t *) dev->dev_private; 118 1.1 riastrad if (!dev_priv) 119 1.1 riastrad return; 120 1.1 riastrad 121 1.1 riastrad /* Disable *all* interrupts */ 122 1.1 riastrad R128_WRITE(R128_GEN_INT_CNTL, 0); 123 1.1 riastrad } 124