V4L/DVB (13785): [Mantis] Do not disable IRQ's while being invoked
[deliverable/linux.git] / drivers / media / dvb / mantis / mantis_pci.c
1 /*
2 Mantis PCI bridge driver
3
4 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include <asm/io.h>
22 #include <asm/pgtable.h>
23 #include <asm/page.h>
24 #include <linux/kmod.h>
25 #include <linux/vmalloc.h>
26 #include <linux/init.h>
27 #include <linux/device.h>
28 #include "mantis_common.h"
29 #include "mantis_core.h"
30
31 #include <asm/irq.h>
32 #include <linux/signal.h>
33 #include <linux/sched.h>
34 #include <linux/interrupt.h>
35
36 unsigned int verbose = 1;
37 module_param(verbose, int, 0644);
38 MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)");
39
40 unsigned int devs;
41
42 #define PCI_VENDOR_ID_MANTIS 0x1822
43 #define PCI_DEVICE_ID_MANTIS_R11 0x4e35
44 #define DRIVER_NAME "Mantis"
45
46 static struct pci_device_id mantis_pci_table[] = {
47 { PCI_DEVICE(PCI_VENDOR_ID_MANTIS, PCI_DEVICE_ID_MANTIS_R11) },
48 { 0 },
49 };
50
51 MODULE_DEVICE_TABLE(pci, mantis_pci_table);
52
53 static irqreturn_t mantis_pci_irq(int irq, void *dev_id)
54 {
55 u32 stat = 0, mask = 0, lstat = 0, mstat = 0;
56 u32 rst_stat = 0, rst_mask = 0;
57
58 struct mantis_pci *mantis;
59 struct mantis_ca *ca;
60
61 mantis = (struct mantis_pci *) dev_id;
62 if (unlikely(mantis == NULL)) {
63 dprintk(verbose, MANTIS_ERROR, 1, "Mantis == NULL");
64 return IRQ_NONE;
65 }
66 ca = mantis->mantis_ca;
67
68 stat = mmread(MANTIS_INT_STAT);
69 mask = mmread(MANTIS_INT_MASK);
70 mstat = lstat = stat & ~MANTIS_INT_RISCSTAT;
71 if (!(stat & mask))
72 return IRQ_NONE;
73
74 rst_mask = MANTIS_GPIF_WRACK |
75 MANTIS_GPIF_OTHERR |
76 MANTIS_SBUF_WSTO |
77 MANTIS_GPIF_EXTIRQ;
78
79 rst_stat = mmread(MANTIS_GPIF_STATUS);
80 rst_stat &= rst_mask;
81 mmwrite(rst_stat, MANTIS_GPIF_STATUS);
82
83 mantis->mantis_int_stat = stat;
84 mantis->mantis_int_mask = mask;
85 dprintk(verbose, MANTIS_DEBUG, 0, "=== Interrupts[%04x/%04x]= [", stat, mask);
86 if (stat & MANTIS_INT_RISCEN) {
87 dprintk(verbose, MANTIS_DEBUG, 0, "* DMA enabl *");
88 }
89 if (stat & MANTIS_INT_IRQ0) {
90 dprintk(verbose, MANTIS_DEBUG, 0, "* INT IRQ-0 *");
91 mantis->gpif_status = rst_stat;
92 wake_up(&ca->hif_write_wq);
93 schedule_work(&ca->hif_evm_work);
94 }
95 if (stat & MANTIS_INT_IRQ1) {
96 dprintk(verbose, MANTIS_DEBUG, 0, "* INT IRQ-1 *");
97 }
98 if (stat & MANTIS_INT_OCERR) {
99 dprintk(verbose, MANTIS_DEBUG, 0, "* INT OCERR *");
100 }
101 if (stat & MANTIS_INT_PABORT) {
102 dprintk(verbose, MANTIS_DEBUG, 0, "* INT PABRT *");
103 }
104 if (stat & MANTIS_INT_RIPERR) {
105 dprintk(verbose, MANTIS_DEBUG, 0, "* INT RIPRR *");
106 }
107 if (stat & MANTIS_INT_PPERR) {
108 dprintk(verbose, MANTIS_DEBUG, 0, "* INT PPERR *");
109 }
110 if (stat & MANTIS_INT_FTRGT) {
111 dprintk(verbose, MANTIS_DEBUG, 0, "* INT FTRGT *");
112 }
113 if (stat & MANTIS_INT_RISCI) {
114 dprintk(verbose, MANTIS_DEBUG, 0, "* INT RISCI *");
115 mantis->finished_block = (stat & MANTIS_INT_RISCSTAT) >> 28;
116 tasklet_schedule(&mantis->tasklet);
117 }
118 if (stat & MANTIS_INT_I2CDONE) {
119 dprintk(verbose, MANTIS_DEBUG, 0, "* I2C DONE *");
120 wake_up(&mantis->i2c_wq);
121 }
122 mmwrite(stat, MANTIS_INT_STAT);
123 stat &= ~(MANTIS_INT_RISCEN | MANTIS_INT_I2CDONE |
124 MANTIS_INT_I2CRACK | MANTIS_INT_PCMCIA7 |
125 MANTIS_INT_PCMCIA6 | MANTIS_INT_PCMCIA5 |
126 MANTIS_INT_PCMCIA4 | MANTIS_INT_PCMCIA3 |
127 MANTIS_INT_PCMCIA2 | MANTIS_INT_PCMCIA1 |
128 MANTIS_INT_PCMCIA0 | MANTIS_INT_IRQ1 |
129 MANTIS_INT_IRQ0 | MANTIS_INT_OCERR |
130 MANTIS_INT_PABORT | MANTIS_INT_RIPERR |
131 MANTIS_INT_PPERR | MANTIS_INT_FTRGT |
132 MANTIS_INT_RISCI);
133
134 if (stat)
135 dprintk(verbose, MANTIS_DEBUG, 0, "* Unknown [%04x] *", stat);
136
137 dprintk(verbose, MANTIS_DEBUG, 0, "] ===\n");
138
139 return IRQ_HANDLED;
140 }
141
142
143 static int __devinit mantis_pci_probe(struct pci_dev *pdev,
144 const struct pci_device_id *mantis_pci_table)
145 {
146 u8 revision, latency;
147 struct mantis_pci *mantis;
148 int ret = 0;
149
150 mantis = kmalloc(sizeof (struct mantis_pci), GFP_KERNEL);
151 if (mantis == NULL) {
152 printk("%s: Out of memory\n", __func__);
153 ret = -ENOMEM;
154 goto err;
155 }
156 memset(mantis, 0, sizeof (struct mantis_pci));
157 mantis->num = devs;
158 devs++;
159
160 if (pci_enable_device(pdev)) {
161 dprintk(verbose, MANTIS_ERROR, 1, "Mantis PCI enable failed");
162 ret = -ENODEV;
163 goto err;
164 }
165 mantis->mantis_addr = pci_resource_start(pdev, 0);
166 if (!request_mem_region(pci_resource_start(pdev, 0),
167 pci_resource_len(pdev, 0), DRIVER_NAME)) {
168 ret = -ENODEV;
169 goto err0;
170 }
171
172 mantis->mantis_mmio = ioremap(pci_resource_start(pdev, 0),
173 pci_resource_len(pdev, 0));
174
175 if (!mantis->mantis_mmio) {
176 dprintk(verbose, MANTIS_ERROR, 1, "IO remap failed");
177 ret = -ENODEV;
178 goto err1;
179 }
180
181 // Clear and disable all interrupts at startup
182 // to avoid lockup situations
183 mmwrite(0x00, MANTIS_INT_MASK);
184 if (request_irq(pdev->irq,
185 mantis_pci_irq,
186 IRQF_SHARED,
187 DRIVER_NAME,
188 mantis) < 0) {
189
190 dprintk(verbose, MANTIS_ERROR, 1, "Mantis IRQ reg failed");
191 ret = -ENODEV;
192 goto err2;
193 }
194 pci_set_master(pdev);
195 pci_set_drvdata(pdev, mantis);
196 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency);
197 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
198 mantis->latency = latency;
199 mantis->revision = revision;
200 mantis->pdev = pdev;
201 mantis->subsystem_vendor = pdev->subsystem_vendor;
202 mantis->subsystem_device = pdev->subsystem_device;
203 init_waitqueue_head(&mantis->i2c_wq);
204
205 mantis_set_direction(mantis, 0); /* CAM bypass */
206
207 if (!latency)
208 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 32);
209
210 dprintk(verbose, MANTIS_ERROR, 0,
211 "irq: %d, latency: %d\n memory: 0x%lx, mmio: 0x%p\n",
212 pdev->irq, mantis->latency,
213 mantis->mantis_addr, mantis->mantis_mmio);
214
215 // No more PCI specific stuff !
216 if (mantis_core_init(mantis) < 0) {
217 dprintk(verbose, MANTIS_ERROR, 1, "Mantis core init failed");
218 ret = -ENODEV;
219 goto err2;
220 }
221
222 return 0;
223
224 // Error conditions ..
225 err2:
226 dprintk(verbose, MANTIS_DEBUG, 1, "Err: IO Unmap");
227 if (mantis->mantis_mmio)
228 iounmap(mantis->mantis_mmio);
229 err1:
230 dprintk(verbose, MANTIS_DEBUG, 1, "Err: Release regions");
231 release_mem_region(pci_resource_start(pdev, 0),
232 pci_resource_len(pdev, 0));
233 pci_disable_device(pdev);
234 err0:
235 dprintk(verbose, MANTIS_DEBUG, 1, "Err: Free");
236 kfree(mantis);
237 err:
238 dprintk(verbose, MANTIS_DEBUG, 1, "Err:");
239 return ret;
240 }
241
242 static void __devexit mantis_pci_remove(struct pci_dev *pdev)
243 {
244 struct mantis_pci *mantis = pci_get_drvdata(pdev);
245
246 if (mantis == NULL) {
247 dprintk(verbose, MANTIS_ERROR, 1, "Aeio, Mantis NULL ptr");
248 return;
249 }
250 mantis_core_exit(mantis);
251 dprintk(verbose, MANTIS_ERROR, 1, "Removing -->Mantis irq: %d, latency: %d\n memory: 0x%lx, mmio: 0x%p",
252 pdev->irq, mantis->latency, mantis->mantis_addr,
253 mantis->mantis_mmio);
254
255 free_irq(pdev->irq, mantis);
256 pci_release_regions(pdev);
257 if (mantis_dma_exit(mantis) < 0)
258 dprintk(verbose, MANTIS_ERROR, 1, "DMA exit failed");
259
260 pci_set_drvdata(pdev, NULL);
261 pci_disable_device(pdev);
262 kfree(mantis);
263 }
264
265 static struct pci_driver mantis_pci_driver = {
266 .name = DRIVER_NAME,
267 .id_table = mantis_pci_table,
268 .probe = mantis_pci_probe,
269 .remove = mantis_pci_remove,
270 };
271
272 static int __devinit mantis_pci_init(void)
273 {
274 return pci_register_driver(&mantis_pci_driver);
275 }
276
277 static void __devexit mantis_pci_exit(void)
278 {
279 pci_unregister_driver(&mantis_pci_driver);
280 }
281
282 module_init(mantis_pci_init);
283 module_exit(mantis_pci_exit);
284
285 MODULE_DESCRIPTION("Mantis PCI DTV bridge driver");
286 MODULE_AUTHOR("Manu Abraham");
287 MODULE_LICENSE("GPL");
This page took 0.047871 seconds and 5 git commands to generate.