Merge branch 'fix/soundcore' into for-linus
[pandora-kernel.git] / drivers / gpu / drm / radeon / radeon_irq_kms.c
1 /*
2  * Copyright 2008 Advanced Micro Devices, Inc.
3  * Copyright 2008 Red Hat Inc.
4  * Copyright 2009 Jerome Glisse.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * Authors: Dave Airlie
25  *          Alex Deucher
26  *          Jerome Glisse
27  */
28 #include "drmP.h"
29 #include "radeon_drm.h"
30 #include "radeon_reg.h"
31 #include "radeon_microcode.h"
32 #include "radeon.h"
33 #include "atom.h"
34
35 static inline uint32_t r100_irq_ack(struct radeon_device *rdev)
36 {
37         uint32_t irqs = RREG32(RADEON_GEN_INT_STATUS);
38         uint32_t irq_mask = RADEON_SW_INT_TEST;
39
40         if (irqs) {
41                 WREG32(RADEON_GEN_INT_STATUS, irqs);
42         }
43         return irqs & irq_mask;
44 }
45
46 int r100_irq_set(struct radeon_device *rdev)
47 {
48         uint32_t tmp = 0;
49
50         if (rdev->irq.sw_int) {
51                 tmp |= RADEON_SW_INT_ENABLE;
52         }
53         /* Todo go through CRTC and enable vblank int or not */
54         WREG32(RADEON_GEN_INT_CNTL, tmp);
55         return 0;
56 }
57
58 int r100_irq_process(struct radeon_device *rdev)
59 {
60         uint32_t status;
61
62         status = r100_irq_ack(rdev);
63         if (!status) {
64                 return IRQ_NONE;
65         }
66         while (status) {
67                 /* SW interrupt */
68                 if (status & RADEON_SW_INT_TEST) {
69                         radeon_fence_process(rdev);
70                 }
71                 status = r100_irq_ack(rdev);
72         }
73         return IRQ_HANDLED;
74 }
75
76 int rs600_irq_set(struct radeon_device *rdev)
77 {
78         uint32_t tmp = 0;
79
80         if (rdev->irq.sw_int) {
81                 tmp |= RADEON_SW_INT_ENABLE;
82         }
83         WREG32(RADEON_GEN_INT_CNTL, tmp);
84         /* Todo go through CRTC and enable vblank int or not */
85         WREG32(R500_DxMODE_INT_MASK, 0);
86         return 0;
87 }
88
89 irqreturn_t radeon_driver_irq_handler_kms(DRM_IRQ_ARGS)
90 {
91         struct drm_device *dev = (struct drm_device *) arg;
92         struct radeon_device *rdev = dev->dev_private;
93
94         return radeon_irq_process(rdev);
95 }
96
97 void radeon_driver_irq_preinstall_kms(struct drm_device *dev)
98 {
99         struct radeon_device *rdev = dev->dev_private;
100         unsigned i;
101
102         /* Disable *all* interrupts */
103         rdev->irq.sw_int = false;
104         for (i = 0; i < 2; i++) {
105                 rdev->irq.crtc_vblank_int[i] = false;
106         }
107         radeon_irq_set(rdev);
108         /* Clear bits */
109         radeon_irq_process(rdev);
110 }
111
112 int radeon_driver_irq_postinstall_kms(struct drm_device *dev)
113 {
114         struct radeon_device *rdev = dev->dev_private;
115
116         dev->max_vblank_count = 0x001fffff;
117         rdev->irq.sw_int = true;
118         radeon_irq_set(rdev);
119         return 0;
120 }
121
122 void radeon_driver_irq_uninstall_kms(struct drm_device *dev)
123 {
124         struct radeon_device *rdev = dev->dev_private;
125         unsigned i;
126
127         if (rdev == NULL) {
128                 return;
129         }
130         /* Disable *all* interrupts */
131         rdev->irq.sw_int = false;
132         for (i = 0; i < 2; i++) {
133                 rdev->irq.crtc_vblank_int[i] = false;
134         }
135         radeon_irq_set(rdev);
136 }
137
138 int radeon_irq_kms_init(struct radeon_device *rdev)
139 {
140         int r = 0;
141
142         r = drm_vblank_init(rdev->ddev, 2);
143         if (r) {
144                 return r;
145         }
146         drm_irq_install(rdev->ddev);
147         rdev->irq.installed = true;
148         DRM_INFO("radeon: irq initialized.\n");
149         return 0;
150 }
151
152 void radeon_irq_kms_fini(struct radeon_device *rdev)
153 {
154         if (rdev->irq.installed) {
155                 rdev->irq.installed = false;
156                 drm_irq_uninstall(rdev->ddev);
157         }
158 }