V4L/DVB (13779): [Mantis] Missing wakeup for write queue
[linux-2.6/btrfs-unstable.git] / drivers / media / dvb / mantis / mantis_pci.c
bloba068ffb32534dbd37662a48a3120758544621ea0
1 /*
2 Mantis PCI bridge driver
4 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
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.
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.
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.
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"
31 #include <asm/irq.h>
32 #include <linux/signal.h>
33 #include <linux/sched.h>
34 #include <linux/interrupt.h>
36 unsigned int verbose = 1;
37 module_param(verbose, int, 0644);
38 MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)");
40 unsigned int devs;
42 #define PCI_VENDOR_ID_MANTIS 0x1822
43 #define PCI_DEVICE_ID_MANTIS_R11 0x4e35
44 #define DRIVER_NAME "Mantis"
46 static struct pci_device_id mantis_pci_table[] = {
47 { PCI_DEVICE(PCI_VENDOR_ID_MANTIS, PCI_DEVICE_ID_MANTIS_R11) },
48 { 0 },
51 MODULE_DEVICE_TABLE(pci, mantis_pci_table);
53 static irqreturn_t mantis_pci_irq(int irq, void *dev_id)
55 u32 stat = 0, mask = 0, lstat = 0, mstat = 0;
56 u32 rst_stat = 0, rst_mask = 0;
58 struct mantis_pci *mantis;
59 struct mantis_ca *ca;
61 mantis = (struct mantis_pci *) dev_id;
62 if (unlikely(mantis == NULL)) {
63 dprintk(verbose, MANTIS_ERROR, 1, "Mantis == NULL");
64 return IRQ_NONE;
66 ca = mantis->mantis_ca;
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;
74 rst_mask = MANTIS_GPIF_WRACK |
75 MANTIS_GPIF_OTHERR |
76 MANTIS_SBUF_WSTO |
77 MANTIS_GPIF_EXTIRQ;
79 rst_stat = mmread(MANTIS_GPIF_STATUS);
80 rst_stat &= rst_mask;
81 mmwrite(rst_stat, MANTIS_GPIF_STATUS);
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 *");
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);
95 if (stat & MANTIS_INT_IRQ1) {
96 dprintk(verbose, MANTIS_DEBUG, 0, "* INT IRQ-1 *");
98 if (stat & MANTIS_INT_OCERR) {
99 dprintk(verbose, MANTIS_DEBUG, 0, "* INT OCERR *");
101 if (stat & MANTIS_INT_PABORT) {
102 dprintk(verbose, MANTIS_DEBUG, 0, "* INT PABRT *");
104 if (stat & MANTIS_INT_RIPERR) {
105 dprintk(verbose, MANTIS_DEBUG, 0, "* INT RIPRR *");
107 if (stat & MANTIS_INT_PPERR) {
108 dprintk(verbose, MANTIS_DEBUG, 0, "* INT PPERR *");
110 if (stat & MANTIS_INT_FTRGT) {
111 dprintk(verbose, MANTIS_DEBUG, 0, "* INT FTRGT *");
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);
118 if (stat & MANTIS_INT_I2CDONE) {
119 dprintk(verbose, MANTIS_DEBUG, 0, "* I2C DONE *");
120 wake_up(&mantis->i2c_wq);
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);
134 if (stat)
135 dprintk(verbose, MANTIS_DEBUG, 0, "* Unknown [%04x] *", stat);
137 dprintk(verbose, MANTIS_DEBUG, 0, "] ===\n");
139 return IRQ_HANDLED;
143 static int __devinit mantis_pci_probe(struct pci_dev *pdev,
144 const struct pci_device_id *mantis_pci_table)
146 u8 revision, latency;
147 struct mantis_pci *mantis;
148 int ret = 0;
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;
156 memset(mantis, 0, sizeof (struct mantis_pci));
157 mantis->num = devs;
158 devs++;
160 if (pci_enable_device(pdev)) {
161 dprintk(verbose, MANTIS_ERROR, 1, "Mantis PCI enable failed");
162 ret = -ENODEV;
163 goto err;
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;
172 if ((mantis->mantis_mmio = ioremap(mantis->mantis_addr, 0x1000)) == NULL) {
173 dprintk(verbose, MANTIS_ERROR, 1, "IO remap failed");
174 ret = -ENODEV;
175 goto err1;
178 // Clear and disable all interrupts at startup
179 // to avoid lockup situations
180 mmwrite(0x00, MANTIS_INT_MASK);
181 if (request_irq(pdev->irq, mantis_pci_irq, IRQF_SHARED | IRQF_DISABLED,
182 DRIVER_NAME, mantis) < 0) {
184 dprintk(verbose, MANTIS_ERROR, 1, "Mantis IRQ reg failed");
185 ret = -ENODEV;
186 goto err2;
188 pci_set_master(pdev);
189 pci_set_drvdata(pdev, mantis);
190 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency);
191 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
192 mantis->latency = latency;
193 mantis->revision = revision;
194 mantis->pdev = pdev;
195 mantis->subsystem_vendor = pdev->subsystem_vendor;
196 mantis->subsystem_device = pdev->subsystem_device;
197 init_waitqueue_head(&mantis->i2c_wq);
199 mantis_set_direction(mantis, 0); /* CAM bypass */
201 if (!latency)
202 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 32);
204 dprintk(verbose, MANTIS_ERROR, 0,
205 "irq: %d, latency: %d\n memory: 0x%lx, mmio: 0x%p\n",
206 pdev->irq, mantis->latency,
207 mantis->mantis_addr, mantis->mantis_mmio);
209 // No more PCI specific stuff !
210 if (mantis_core_init(mantis) < 0) {
211 dprintk(verbose, MANTIS_ERROR, 1, "Mantis core init failed");
212 ret = -ENODEV;
213 goto err2;
216 return 0;
218 // Error conditions ..
219 err2:
220 dprintk(verbose, MANTIS_DEBUG, 1, "Err: IO Unmap");
221 if (mantis->mantis_mmio)
222 iounmap(mantis->mantis_mmio);
223 err1:
224 dprintk(verbose, MANTIS_DEBUG, 1, "Err: Release regions");
225 release_mem_region(pci_resource_start(pdev, 0),
226 pci_resource_len(pdev, 0));
227 pci_disable_device(pdev);
228 err0:
229 dprintk(verbose, MANTIS_DEBUG, 1, "Err: Free");
230 kfree(mantis);
231 err:
232 dprintk(verbose, MANTIS_DEBUG, 1, "Err:");
233 return ret;
236 static void __devexit mantis_pci_remove(struct pci_dev *pdev)
238 struct mantis_pci *mantis = pci_get_drvdata(pdev);
240 if (mantis == NULL) {
241 dprintk(verbose, MANTIS_ERROR, 1, "Aeio, Mantis NULL ptr");
242 return;
244 mantis_core_exit(mantis);
245 dprintk(verbose, MANTIS_ERROR, 1, "Removing -->Mantis irq: %d, latency: %d\n memory: 0x%lx, mmio: 0x%p",
246 pdev->irq, mantis->latency, mantis->mantis_addr,
247 mantis->mantis_mmio);
249 free_irq(pdev->irq, mantis);
250 pci_release_regions(pdev);
251 if (mantis_dma_exit(mantis) < 0)
252 dprintk(verbose, MANTIS_ERROR, 1, "DMA exit failed");
254 pci_set_drvdata(pdev, NULL);
255 pci_disable_device(pdev);
256 kfree(mantis);
259 static struct pci_driver mantis_pci_driver = {
260 .name = DRIVER_NAME,
261 .id_table = mantis_pci_table,
262 .probe = mantis_pci_probe,
263 .remove = mantis_pci_remove,
266 static int __devinit mantis_pci_init(void)
268 return pci_register_driver(&mantis_pci_driver);
271 static void __devexit mantis_pci_exit(void)
273 pci_unregister_driver(&mantis_pci_driver);
276 module_init(mantis_pci_init);
277 module_exit(mantis_pci_exit);
279 MODULE_DESCRIPTION("Mantis PCI DTV bridge driver");
280 MODULE_AUTHOR("Manu Abraham");
281 MODULE_LICENSE("GPL");