r128_irq.c revision 1.1.1.2.28.1 1 /* $NetBSD: r128_irq.c,v 1.1.1.2.28.1 2018/09/06 06:56:31 pgoyette 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.1.1.2.28.1 2018/09/06 06:56:31 pgoyette Exp $");
37
38 #include <drm/drmP.h>
39 #include <drm/r128_drm.h>
40 #include "r128_drv.h"
41
42 u32 r128_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
43 {
44 const drm_r128_private_t *dev_priv = dev->dev_private;
45
46 if (pipe != 0)
47 return 0;
48
49 return atomic_read(&dev_priv->vbl_received);
50 }
51
52 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
53 {
54 struct drm_device *dev = (struct drm_device *) arg;
55 drm_r128_private_t *dev_priv = (drm_r128_private_t *) dev->dev_private;
56 int status;
57
58 status = R128_READ(R128_GEN_INT_STATUS);
59
60 /* VBLANK interrupt */
61 if (status & R128_CRTC_VBLANK_INT) {
62 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
63 atomic_inc(&dev_priv->vbl_received);
64 drm_handle_vblank(dev, 0);
65 return IRQ_HANDLED;
66 }
67 return IRQ_NONE;
68 }
69
70 int r128_enable_vblank(struct drm_device *dev, unsigned int pipe)
71 {
72 drm_r128_private_t *dev_priv = dev->dev_private;
73
74 if (pipe != 0) {
75 DRM_ERROR("%s: bad crtc %u\n", __func__, pipe);
76 return -EINVAL;
77 }
78
79 R128_WRITE(R128_GEN_INT_CNTL, R128_CRTC_VBLANK_INT_EN);
80 return 0;
81 }
82
83 void r128_disable_vblank(struct drm_device *dev, unsigned int pipe)
84 {
85 if (pipe != 0)
86 DRM_ERROR("%s: bad crtc %u\n", __func__, pipe);
87
88 /*
89 * FIXME: implement proper interrupt disable by using the vblank
90 * counter register (if available)
91 *
92 * R128_WRITE(R128_GEN_INT_CNTL,
93 * R128_READ(R128_GEN_INT_CNTL) & ~R128_CRTC_VBLANK_INT_EN);
94 */
95 }
96
97 void r128_driver_irq_preinstall(struct drm_device *dev)
98 {
99 drm_r128_private_t *dev_priv = (drm_r128_private_t *) dev->dev_private;
100
101 /* Disable *all* interrupts */
102 R128_WRITE(R128_GEN_INT_CNTL, 0);
103 /* Clear vblank bit if it's already high */
104 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
105 }
106
107 int r128_driver_irq_postinstall(struct drm_device *dev)
108 {
109 return 0;
110 }
111
112 void r128_driver_irq_uninstall(struct drm_device *dev)
113 {
114 drm_r128_private_t *dev_priv = (drm_r128_private_t *) dev->dev_private;
115 if (!dev_priv)
116 return;
117
118 /* Disable *all* interrupts */
119 R128_WRITE(R128_GEN_INT_CNTL, 0);
120 }
121