V4L/DVB (13805): Fix: Unregister the frontend before detaching
[deliverable/linux.git] / drivers / media / dvb / mantis / mantis_cards.c
CommitLineData
b3b96144
MA
1#include <linux/module.h>
2#include <linux/moduleparam.h>
3#include <linux/kernel.h>
4#include <linux/pci.h>
5#include <asm/irq.h>
6#include <linux/interrupt.h>
7
8#include "dmxdev.h"
9#include "dvbdev.h"
10#include "dvb_demux.h"
11#include "dvb_frontend.h"
12#include "dvb_net.h"
13
14#include "mantis_common.h"
15
16#include "mantis_vp1033.h"
17#include "mantis_vp1034.h"
18#include "mantis_vp1041.h"
19#include "mantis_vp2033.h"
20#include "mantis_vp2040.h"
21#include "mantis_vp3030.h"
22
23#include "mantis_dma.h"
24#include "mantis_ca.h"
25#include "mantis_dvb.h"
26#include "mantis_uart.h"
27#include "mantis_ioc.h"
28#include "mantis_pci.h"
29#include "mantis_i2c.h"
30#include "mantis_reg.h"
31
32static unsigned int verbose;
33module_param(verbose, int, 0644);
34MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)");
35
36static int devs;
37
38#define DRIVER_NAME "Mantis"
39
40static char *label[10] = {
41 "DMA",
42 "IRQ-0",
43 "IRQ-1",
44 "OCERR",
45 "PABRT",
46 "RIPRR",
47 "PPERR",
48 "FTRGT",
49 "RISCI",
50 "RACK"
51};
52
b3b96144
MA
53static irqreturn_t mantis_irq_handler(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(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(MANTIS_DEBUG, 0, "\n-- Stat=<%02x> Mask=<%02x> --", stat, mask);
86 if (stat & MANTIS_INT_RISCEN) {
87 dprintk(MANTIS_DEBUG, 0, "<%s>", label[0]);
88 }
89 if (stat & MANTIS_INT_IRQ0) {
90 dprintk(MANTIS_DEBUG, 0, "<%s>", label[1]);
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(MANTIS_DEBUG, 0, "<%s>", label[2]);
97 schedule_work(&mantis->uart_work);
98 }
99 if (stat & MANTIS_INT_OCERR) {
100 dprintk(MANTIS_DEBUG, 0, "<%s>", label[3]);
101 }
102 if (stat & MANTIS_INT_PABORT) {
103 dprintk(MANTIS_DEBUG, 0, "<%s>", label[4]);
104 }
105 if (stat & MANTIS_INT_RIPERR) {
106 dprintk(MANTIS_DEBUG, 0, "<%s>", label[5]);
107 }
108 if (stat & MANTIS_INT_PPERR) {
109 dprintk(MANTIS_DEBUG, 0, "<%s>", label[6]);
110 }
111 if (stat & MANTIS_INT_FTRGT) {
112 dprintk(MANTIS_DEBUG, 0, "<%s>", label[7]);
113 }
114 if (stat & MANTIS_INT_RISCI) {
115 dprintk(MANTIS_DEBUG, 0, "<%s>", label[8]);
116 mantis->finished_block = (stat & MANTIS_INT_RISCSTAT) >> 28;
117 tasklet_schedule(&mantis->tasklet);
118 }
119 if (stat & MANTIS_INT_I2CDONE) {
120 dprintk(MANTIS_DEBUG, 0, "<%s>", label[9]);
121 wake_up(&mantis->i2c_wq);
122 }
123 mmwrite(stat, MANTIS_INT_STAT);
124 stat &= ~(MANTIS_INT_RISCEN | MANTIS_INT_I2CDONE |
125 MANTIS_INT_I2CRACK | MANTIS_INT_PCMCIA7 |
126 MANTIS_INT_PCMCIA6 | MANTIS_INT_PCMCIA5 |
127 MANTIS_INT_PCMCIA4 | MANTIS_INT_PCMCIA3 |
128 MANTIS_INT_PCMCIA2 | MANTIS_INT_PCMCIA1 |
129 MANTIS_INT_PCMCIA0 | MANTIS_INT_IRQ1 |
130 MANTIS_INT_IRQ0 | MANTIS_INT_OCERR |
131 MANTIS_INT_PABORT | MANTIS_INT_RIPERR |
132 MANTIS_INT_PPERR | MANTIS_INT_FTRGT |
133 MANTIS_INT_RISCI);
134
135 if (stat)
136 dprintk(MANTIS_DEBUG, 0, "<Unknown> Stat=<%02x> Mask=<%02x>", stat, mask);
137
138 dprintk(MANTIS_DEBUG, 0, "\n");
139 return IRQ_HANDLED;
140}
141
142static int __devinit mantis_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id)
143{
144 struct mantis_pci *mantis;
145 struct mantis_hwconfig *config;
146 int err = 0;
147
148 mantis = kzalloc(sizeof (struct mantis_pci), GFP_KERNEL);
149 if (mantis == NULL) {
150 printk(KERN_ERR "%s ERROR: Out of memory\n", __func__);
151 err = -ENOMEM;
152 goto fail0;
153 }
154
155 mantis->num = devs;
156 mantis->verbose = verbose;
157 mantis->pdev = pdev;
158 config = (struct mantis_hwconfig *) pci_id->driver_data;
159 config->irq_handler = &mantis_irq_handler;
160 mantis->hwconfig = config;
161
162 err = mantis_pci_init(mantis);
163 if (err) {
164 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI initialization failed <%d>", err);
165 goto fail1;
166 }
167
168 err = mantis_stream_control(mantis, STREAM_TO_HIF);
169 if (err < 0) {
170 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis stream control failed <%d>", err);
171 goto fail1;
172 }
173
174 err = mantis_i2c_init(mantis);
175 if (err < 0) {
176 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C initialization failed <%d>", err);
177 goto fail2;
178 }
179
180 err = mantis_get_mac(mantis);
181 if (err < 0) {
182 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis MAC address read failed <%d>", err);
183 goto fail2;
184 }
185
186 err = mantis_dma_init(mantis);
187 if (err < 0) {
188 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA initialization failed <%d>", err);
189 goto fail3;
190 }
191
192 err = mantis_dvb_init(mantis);
193 if (err < 0) {
194 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err);
195 goto fail4;
196 }
197 devs++;
198
199 return err;
b3b96144
MA
200fail4:
201 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA exit! <%d>", err);
202 mantis_dma_exit(mantis);
203
204fail3:
205 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C exit! <%d>", err);
206 mantis_i2c_exit(mantis);
207
208fail2:
209 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI exit! <%d>", err);
210 mantis_pci_exit(mantis);
211
212fail1:
213 dprintk(MANTIS_ERROR, 1, "ERROR: Mantis free! <%d>", err);
214 kfree(mantis);
215
216fail0:
217 return err;
218}
219
220static void __devexit mantis_pci_remove(struct pci_dev *pdev)
221{
222 struct mantis_pci *mantis = pci_get_drvdata(pdev);
223
224 if (mantis) {
b3b96144
MA
225 mantis_dvb_exit(mantis);
226 mantis_dma_exit(mantis);
227 mantis_i2c_exit(mantis);
228 mantis_pci_exit(mantis);
229 kfree(mantis);
230 }
231 return;
232}
233
234static struct pci_device_id mantis_pci_table[] = {
235 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1033_DVB_S, &vp1033_config),
236 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1034_DVB_S, &vp1034_config),
237 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1041_DVB_S2, &vp1041_config),
238 MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_10, &vp1041_config),
239 MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_20, &vp1041_config),
240 MAKE_ENTRY(TERRATEC, CINERGY_S2_PCI_HD, &vp1041_config),
241 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2033_DVB_C, &vp2033_config),
242 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2040_DVB_C, &vp2040_config),
243 MAKE_ENTRY(TECHNISAT, CABLESTAR_HD2, &vp2040_config),
244 MAKE_ENTRY(TERRATEC, CINERGY_C, &vp2033_config),
245 MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_3030_DVB_T, &vp3030_config),
246 { }
247};
248
249static struct pci_driver mantis_pci_driver = {
250 .name = DRIVER_NAME,
251 .id_table = mantis_pci_table,
252 .probe = mantis_pci_probe,
253 .remove = mantis_pci_remove,
254};
255
256static int __devinit mantis_init(void)
257{
258 return pci_register_driver(&mantis_pci_driver);
259}
260
261static void __devexit mantis_exit(void)
262{
263 return pci_unregister_driver(&mantis_pci_driver);
264}
265
266module_init(mantis_init);
267module_exit(mantis_exit);
268
269MODULE_DESCRIPTION("MANTIS driver");
270MODULE_AUTHOR("Manu Abraham");
271MODULE_LICENSE("GPL");
This page took 0.032878 seconds and 5 git commands to generate.