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