]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/media/dvb/mantis/mantis_pci.c
V4L/DVB (13708): [Mantis] Remove some dead code
[karo-tx-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         struct mantis_pci *mantis;
57
58         mantis = (struct mantis_pci *) dev_id;
59         if (unlikely(mantis == NULL)) {
60                 dprintk(verbose, MANTIS_ERROR, 1, "Mantis == NULL");
61                 return IRQ_NONE;
62         }
63         stat = mmread(MANTIS_INT_STAT);
64         mask = mmread(MANTIS_INT_MASK);
65         mstat = lstat = stat & ~MANTIS_INT_RISCSTAT;
66         if (!(stat & mask))
67                 return IRQ_NONE;
68
69         mantis->mantis_int_stat = stat;
70         mantis->mantis_int_mask = mask;
71         dprintk(verbose, MANTIS_DEBUG, 0, "=== Interrupts[%04x/%04x]= [", stat, mask);
72         if (stat & MANTIS_INT_RISCEN) {
73                 dprintk(verbose, MANTIS_DEBUG, 0, "* DMA enabl *");
74         }
75         if (stat & MANTIS_INT_I2CRACK) {
76                 dprintk(verbose, MANTIS_DEBUG, 0, "* I2C R-ACK *");
77         }
78         if (stat & MANTIS_INT_PCMCIA7) {
79                 dprintk(verbose, MANTIS_DEBUG, 0, "* PCMCIA-07 *");
80         }
81         if (stat & MANTIS_INT_IRQ0) {
82                 dprintk(verbose, MANTIS_DEBUG, 0, "* INT IRQ-0 *");
83         }
84         if (stat & MANTIS_INT_IRQ1) {
85                 dprintk(verbose, MANTIS_DEBUG, 0, "* INT IRQ-1 *");
86         }
87         if (stat & MANTIS_INT_OCERR) {
88                 dprintk(verbose, MANTIS_DEBUG, 0, "* INT OCERR *");
89         }
90         if (stat & MANTIS_INT_PABORT) {
91                 dprintk(verbose, MANTIS_DEBUG, 0, "* INT PABRT *");
92         }
93         if (stat & MANTIS_INT_RIPERR) {
94                 dprintk(verbose, MANTIS_DEBUG, 0, "* INT RIPRR *");
95         }
96         if (stat & MANTIS_INT_PPERR) {
97                 dprintk(verbose, MANTIS_DEBUG, 0, "* INT PPERR *");
98         }
99         if (stat & MANTIS_INT_FTRGT) {
100                 dprintk(verbose, MANTIS_DEBUG, 0, "* INT FTRGT *");
101         }
102         if (stat & MANTIS_INT_RISCI) {
103                 dprintk(verbose, MANTIS_DEBUG, 0, "* INT RISCI *");
104                 mantis->finished_block = (stat & MANTIS_INT_RISCSTAT) >> 28;
105                 tasklet_schedule(&mantis->tasklet);
106         }
107         if (stat & MANTIS_INT_I2CDONE) {
108                 dprintk(verbose, MANTIS_DEBUG, 0, "* I2C DONE  *");
109                 wake_up(&mantis->i2c_wq);
110         }
111         mmwrite(stat, MANTIS_INT_STAT);
112         stat &= ~(MANTIS_INT_RISCEN   | MANTIS_INT_I2CDONE |
113                   MANTIS_INT_I2CRACK  | MANTIS_INT_PCMCIA7 |
114                   MANTIS_INT_PCMCIA6  | MANTIS_INT_PCMCIA5 |
115                   MANTIS_INT_PCMCIA4  | MANTIS_INT_PCMCIA3 |
116                   MANTIS_INT_PCMCIA2  | MANTIS_INT_PCMCIA1 |
117                   MANTIS_INT_PCMCIA0  | MANTIS_INT_IRQ1    |
118                   MANTIS_INT_IRQ0     | MANTIS_INT_OCERR   |
119                   MANTIS_INT_PABORT   | MANTIS_INT_RIPERR  |
120                   MANTIS_INT_PPERR    | MANTIS_INT_FTRGT   |
121                   MANTIS_INT_RISCI);
122
123         if (stat)
124                 dprintk(verbose, MANTIS_DEBUG, 0, "* Unknown [%04x] *", stat);
125
126         dprintk(verbose, MANTIS_DEBUG, 0, "] ===\n");
127
128         return IRQ_HANDLED;
129 }
130
131
132 static int __devinit mantis_pci_probe(struct pci_dev *pdev,
133                                       const struct pci_device_id *mantis_pci_table)
134 {
135         u8 revision, latency;
136         struct mantis_pci *mantis;
137         int ret = 0;
138
139         mantis = kmalloc(sizeof (struct mantis_pci), GFP_KERNEL);
140         if (mantis == NULL) {
141                 printk("%s: Out of memory\n", __func__);
142                 ret = -ENOMEM;
143                 goto err;
144         }
145         memset(mantis, 0, sizeof (struct mantis_pci));
146         mantis->num = devs;
147         devs++;
148
149         if (pci_enable_device(pdev)) {
150                 dprintk(verbose, MANTIS_ERROR, 1, "Mantis PCI enable failed");
151                 ret = -ENODEV;
152                 goto err;
153         }
154         mantis->mantis_addr = pci_resource_start(pdev, 0);
155         if (!request_mem_region(pci_resource_start(pdev, 0),
156                         pci_resource_len(pdev, 0), DRIVER_NAME)) {
157                 ret = -ENODEV;
158                 goto err0;
159         }
160
161         if ((mantis->mantis_mmio = ioremap(mantis->mantis_addr, 0x1000)) == NULL) {
162                 dprintk(verbose, MANTIS_ERROR, 1, "IO remap failed");
163                 ret = -ENODEV;
164                 goto err1;
165         }
166
167         // Clear and disable all interrupts at startup
168         // to avoid lockup situations
169         mmwrite(0x00, MANTIS_INT_MASK);
170         if (request_irq(pdev->irq, mantis_pci_irq, IRQF_SHARED | IRQF_DISABLED,
171                                                 DRIVER_NAME, mantis) < 0) {
172
173                 dprintk(verbose, MANTIS_ERROR, 1, "Mantis IRQ reg failed");
174                 ret = -ENODEV;
175                 goto err2;
176         }
177         pci_set_master(pdev);
178         pci_set_drvdata(pdev, mantis);
179         pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency);
180         pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
181         mantis->latency = latency;
182         mantis->revision = revision;
183         mantis->pdev = pdev;
184         mantis->subsystem_vendor = pdev->subsystem_vendor;
185         mantis->subsystem_device = pdev->subsystem_device;
186         init_waitqueue_head(&mantis->i2c_wq);
187
188         // CAM bypass
189         //mmwrite(mmread(MANTIS_INT_MASK) | MANTIS_INT_IRQ1, MANTIS_INT_MASK);
190         dprintk(verbose, MANTIS_INFO, 0, "\ngpif status: %04x  irqcfg: %04x\n", mmread(0x9c), mmread(0x98));
191         if ((mmread(0x9c) & 0x200) != 0) { //CAM inserted
192                 msleep_interruptible(1);
193                 if ((mmread(0x9c) & 0x200) != 0)
194                         mmwrite(((mmread(0x98) | 0x01) & ~0x02), 0x98);
195                 else
196                         mmwrite(((mmread(0x98) | 0x02) & ~0x01), 0x98);
197
198         } else {
199                 mmwrite(((mmread(0x98) | 0x02) & ~0x01), 0x98);
200         }
201         mantis_set_direction(mantis, 0);
202
203         if (!latency)
204                 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 32);
205
206         dprintk(verbose, MANTIS_ERROR, 0,
207                 "irq: %d, latency: %d\n memory: 0x%lx, mmio: 0x%p\n",
208                 pdev->irq, mantis->latency,
209                 mantis->mantis_addr, mantis->mantis_mmio);
210
211         // No more PCI specific stuff !
212         if (mantis_core_init(mantis) < 0) {
213                 dprintk(verbose, MANTIS_ERROR, 1, "Mantis core init failed");
214                 ret = -ENODEV;
215                 goto err2;
216         }
217
218         return 0;
219
220         // Error conditions ..
221 err2:
222         dprintk(verbose, MANTIS_DEBUG, 1, "Err: IO Unmap");
223         if (mantis->mantis_mmio)
224                 iounmap(mantis->mantis_mmio);
225 err1:
226         dprintk(verbose, MANTIS_DEBUG, 1, "Err: Release regions");
227         release_mem_region(pci_resource_start(pdev, 0),
228                                 pci_resource_len(pdev, 0));
229         pci_disable_device(pdev);
230 err0:
231         dprintk(verbose, MANTIS_DEBUG, 1, "Err: Free");
232         kfree(mantis);
233 err:
234         dprintk(verbose, MANTIS_DEBUG, 1, "Err:");
235         return ret;
236 }
237
238 static void __devexit mantis_pci_remove(struct pci_dev *pdev)
239 {
240         struct mantis_pci *mantis = pci_get_drvdata(pdev);
241
242         if (mantis == NULL) {
243                 dprintk(verbose, MANTIS_ERROR, 1, "Aeio, Mantis NULL ptr");
244                 return;
245         }
246         mantis_core_exit(mantis);
247         dprintk(verbose, MANTIS_ERROR, 1, "Removing -->Mantis irq: %d, latency: %d\n memory: 0x%lx, mmio: 0x%p",
248                 pdev->irq, mantis->latency, mantis->mantis_addr,
249                 mantis->mantis_mmio);
250
251         free_irq(pdev->irq, mantis);
252         pci_release_regions(pdev);
253         if (mantis_dma_exit(mantis) < 0)
254                 dprintk(verbose, MANTIS_ERROR, 1, "DMA exit failed");
255
256         pci_set_drvdata(pdev, NULL);
257         pci_disable_device(pdev);
258         kfree(mantis);
259 }
260
261 static struct pci_driver mantis_pci_driver = {
262         .name = DRIVER_NAME,
263         .id_table = mantis_pci_table,
264         .probe = mantis_pci_probe,
265         .remove = mantis_pci_remove,
266 };
267
268 static int __devinit mantis_pci_init(void)
269 {
270         return pci_register_driver(&mantis_pci_driver);
271 }
272
273 static void __devexit mantis_pci_exit(void)
274 {
275         pci_unregister_driver(&mantis_pci_driver);
276 }
277
278 module_init(mantis_pci_init);
279 module_exit(mantis_pci_exit);
280
281 MODULE_DESCRIPTION("Mantis PCI DTV bridge driver");
282 MODULE_AUTHOR("Manu Abraham");
283 MODULE_LICENSE("GPL");