Commit | Line | Data |
---|---|---|
8825a097 MA |
1 | /* |
2 | Mantis PCI bridge driver | |
3 | ||
4 | Copyright (C) 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 | ||
b3b96144 MA |
21 | #include <linux/module.h> |
22 | #include <linux/moduleparam.h> | |
23 | #include <linux/kernel.h> | |
24 | #include <linux/pci.h> | |
25 | #include <asm/irq.h> | |
26 | #include <linux/interrupt.h> | |
27 | ||
28 | #include "dmxdev.h" | |
29 | #include "dvbdev.h" | |
30 | #include "dvb_demux.h" | |
31 | #include "dvb_frontend.h" | |
32 | #include "dvb_net.h" | |
33 | ||
34 | #include "mantis_common.h" | |
35 | ||
36 | #include "mantis_vp1033.h" | |
37 | #include "mantis_vp1034.h" | |
38 | #include "mantis_vp1041.h" | |
39 | #include "mantis_vp2033.h" | |
40 | #include "mantis_vp2040.h" | |
41 | #include "mantis_vp3030.h" | |
42 | ||
43 | #include "mantis_dma.h" | |
44 | #include "mantis_ca.h" | |
45 | #include "mantis_dvb.h" | |
46 | #include "mantis_uart.h" | |
47 | #include "mantis_ioc.h" | |
48 | #include "mantis_pci.h" | |
49 | #include "mantis_i2c.h" | |
50 | #include "mantis_reg.h" | |
51 | ||
52 | static unsigned int verbose; | |
53 | module_param(verbose, int, 0644); | |
54 | MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)"); | |
55 | ||
56 | static int devs; | |
57 | ||
58 | #define DRIVER_NAME "Mantis" | |
59 | ||
60 | static char *label[10] = { | |
61 | "DMA", | |
62 | "IRQ-0", | |
63 | "IRQ-1", | |
64 | "OCERR", | |
65 | "PABRT", | |
66 | "RIPRR", | |
67 | "PPERR", | |
68 | "FTRGT", | |
69 | "RISCI", | |
70 | "RACK" | |
71 | }; | |
72 | ||
b3b96144 MA |
73 | static irqreturn_t mantis_irq_handler(int irq, void *dev_id) |
74 | { | |
75 | u32 stat = 0, mask = 0, lstat = 0, mstat = 0; | |
76 | u32 rst_stat = 0, rst_mask = 0; | |
77 | ||
78 | struct mantis_pci *mantis; | |
79 | struct mantis_ca *ca; | |
80 | ||
81 | mantis = (struct mantis_pci *) dev_id; | |
82 | if (unlikely(mantis == NULL)) { | |
83 | dprintk(MANTIS_ERROR, 1, "Mantis == NULL"); | |
84 | return IRQ_NONE; | |
85 | } | |
86 | ca = mantis->mantis_ca; | |
87 | ||
88 | stat = mmread(MANTIS_INT_STAT); | |
89 | mask = mmread(MANTIS_INT_MASK); | |
90 | mstat = lstat = stat & ~MANTIS_INT_RISCSTAT; | |
91 | if (!(stat & mask)) | |
92 | return IRQ_NONE; | |
93 | ||
94 | rst_mask = MANTIS_GPIF_WRACK | | |
95 | MANTIS_GPIF_OTHERR | | |
96 | MANTIS_SBUF_WSTO | | |
97 | MANTIS_GPIF_EXTIRQ; | |
98 | ||
99 | rst_stat = mmread(MANTIS_GPIF_STATUS); | |
100 | rst_stat &= rst_mask; | |
101 | mmwrite(rst_stat, MANTIS_GPIF_STATUS); | |
102 | ||
103 | mantis->mantis_int_stat = stat; | |
104 | mantis->mantis_int_mask = mask; | |
105 | dprintk(MANTIS_DEBUG, 0, "\n-- Stat=<%02x> Mask=<%02x> --", stat, mask); | |
106 | if (stat & MANTIS_INT_RISCEN) { | |
107 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[0]); | |
108 | } | |
109 | if (stat & MANTIS_INT_IRQ0) { | |
110 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[1]); | |
111 | mantis->gpif_status = rst_stat; | |
112 | wake_up(&ca->hif_write_wq); | |
113 | schedule_work(&ca->hif_evm_work); | |
114 | } | |
115 | if (stat & MANTIS_INT_IRQ1) { | |
116 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[2]); | |
117 | schedule_work(&mantis->uart_work); | |
118 | } | |
119 | if (stat & MANTIS_INT_OCERR) { | |
120 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[3]); | |
121 | } | |
122 | if (stat & MANTIS_INT_PABORT) { | |
123 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[4]); | |
124 | } | |
125 | if (stat & MANTIS_INT_RIPERR) { | |
126 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[5]); | |
127 | } | |
128 | if (stat & MANTIS_INT_PPERR) { | |
129 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[6]); | |
130 | } | |
131 | if (stat & MANTIS_INT_FTRGT) { | |
132 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[7]); | |
133 | } | |
134 | if (stat & MANTIS_INT_RISCI) { | |
135 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[8]); | |
136 | mantis->finished_block = (stat & MANTIS_INT_RISCSTAT) >> 28; | |
137 | tasklet_schedule(&mantis->tasklet); | |
138 | } | |
139 | if (stat & MANTIS_INT_I2CDONE) { | |
140 | dprintk(MANTIS_DEBUG, 0, "<%s>", label[9]); | |
141 | wake_up(&mantis->i2c_wq); | |
142 | } | |
143 | mmwrite(stat, MANTIS_INT_STAT); | |
144 | stat &= ~(MANTIS_INT_RISCEN | MANTIS_INT_I2CDONE | | |
145 | MANTIS_INT_I2CRACK | MANTIS_INT_PCMCIA7 | | |
146 | MANTIS_INT_PCMCIA6 | MANTIS_INT_PCMCIA5 | | |
147 | MANTIS_INT_PCMCIA4 | MANTIS_INT_PCMCIA3 | | |
148 | MANTIS_INT_PCMCIA2 | MANTIS_INT_PCMCIA1 | | |
149 | MANTIS_INT_PCMCIA0 | MANTIS_INT_IRQ1 | | |
150 | MANTIS_INT_IRQ0 | MANTIS_INT_OCERR | | |
151 | MANTIS_INT_PABORT | MANTIS_INT_RIPERR | | |
152 | MANTIS_INT_PPERR | MANTIS_INT_FTRGT | | |
153 | MANTIS_INT_RISCI); | |
154 | ||
155 | if (stat) | |
156 | dprintk(MANTIS_DEBUG, 0, "<Unknown> Stat=<%02x> Mask=<%02x>", stat, mask); | |
157 | ||
158 | dprintk(MANTIS_DEBUG, 0, "\n"); | |
159 | return IRQ_HANDLED; | |
160 | } | |
161 | ||
162 | static int __devinit mantis_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id) | |
163 | { | |
164 | struct mantis_pci *mantis; | |
165 | struct mantis_hwconfig *config; | |
166 | int err = 0; | |
167 | ||
f5ae4f6f | 168 | mantis = kzalloc(sizeof(struct mantis_pci), GFP_KERNEL); |
b3b96144 MA |
169 | if (mantis == NULL) { |
170 | printk(KERN_ERR "%s ERROR: Out of memory\n", __func__); | |
171 | err = -ENOMEM; | |
172 | goto fail0; | |
173 | } | |
174 | ||
175 | mantis->num = devs; | |
176 | mantis->verbose = verbose; | |
177 | mantis->pdev = pdev; | |
178 | config = (struct mantis_hwconfig *) pci_id->driver_data; | |
179 | config->irq_handler = &mantis_irq_handler; | |
180 | mantis->hwconfig = config; | |
181 | ||
182 | err = mantis_pci_init(mantis); | |
183 | if (err) { | |
184 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI initialization failed <%d>", err); | |
185 | goto fail1; | |
186 | } | |
187 | ||
188 | err = mantis_stream_control(mantis, STREAM_TO_HIF); | |
189 | if (err < 0) { | |
190 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis stream control failed <%d>", err); | |
191 | goto fail1; | |
192 | } | |
193 | ||
194 | err = mantis_i2c_init(mantis); | |
195 | if (err < 0) { | |
196 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C initialization failed <%d>", err); | |
197 | goto fail2; | |
198 | } | |
199 | ||
200 | err = mantis_get_mac(mantis); | |
201 | if (err < 0) { | |
202 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis MAC address read failed <%d>", err); | |
203 | goto fail2; | |
204 | } | |
205 | ||
206 | err = mantis_dma_init(mantis); | |
207 | if (err < 0) { | |
208 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA initialization failed <%d>", err); | |
209 | goto fail3; | |
210 | } | |
211 | ||
212 | err = mantis_dvb_init(mantis); | |
213 | if (err < 0) { | |
214 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DVB initialization failed <%d>", err); | |
215 | goto fail4; | |
216 | } | |
a1497357 MA |
217 | err = mantis_uart_init(mantis); |
218 | if (err < 0) { | |
219 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART initialization failed <%d>", err); | |
220 | goto fail6; | |
221 | } | |
222 | ||
b3b96144 MA |
223 | devs++; |
224 | ||
225 | return err; | |
a1497357 MA |
226 | |
227 | ||
228 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis UART exit! <%d>", err); | |
229 | mantis_uart_exit(mantis); | |
230 | ||
231 | fail6: | |
b3b96144 MA |
232 | fail4: |
233 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis DMA exit! <%d>", err); | |
234 | mantis_dma_exit(mantis); | |
235 | ||
236 | fail3: | |
237 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis I2C exit! <%d>", err); | |
238 | mantis_i2c_exit(mantis); | |
239 | ||
240 | fail2: | |
241 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis PCI exit! <%d>", err); | |
242 | mantis_pci_exit(mantis); | |
243 | ||
244 | fail1: | |
245 | dprintk(MANTIS_ERROR, 1, "ERROR: Mantis free! <%d>", err); | |
246 | kfree(mantis); | |
247 | ||
248 | fail0: | |
249 | return err; | |
250 | } | |
251 | ||
252 | static void __devexit mantis_pci_remove(struct pci_dev *pdev) | |
253 | { | |
254 | struct mantis_pci *mantis = pci_get_drvdata(pdev); | |
255 | ||
256 | if (mantis) { | |
a1497357 MA |
257 | |
258 | mantis_uart_exit(mantis); | |
b3b96144 MA |
259 | mantis_dvb_exit(mantis); |
260 | mantis_dma_exit(mantis); | |
261 | mantis_i2c_exit(mantis); | |
262 | mantis_pci_exit(mantis); | |
263 | kfree(mantis); | |
264 | } | |
265 | return; | |
266 | } | |
267 | ||
268 | static struct pci_device_id mantis_pci_table[] = { | |
269 | MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1033_DVB_S, &vp1033_config), | |
270 | MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1034_DVB_S, &vp1034_config), | |
271 | MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_1041_DVB_S2, &vp1041_config), | |
272 | MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_10, &vp1041_config), | |
273 | MAKE_ENTRY(TECHNISAT, SKYSTAR_HD2_20, &vp1041_config), | |
274 | MAKE_ENTRY(TERRATEC, CINERGY_S2_PCI_HD, &vp1041_config), | |
275 | MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2033_DVB_C, &vp2033_config), | |
276 | MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_2040_DVB_C, &vp2040_config), | |
277 | MAKE_ENTRY(TECHNISAT, CABLESTAR_HD2, &vp2040_config), | |
278 | MAKE_ENTRY(TERRATEC, CINERGY_C, &vp2033_config), | |
279 | MAKE_ENTRY(TWINHAN_TECHNOLOGIES, MANTIS_VP_3030_DVB_T, &vp3030_config), | |
280 | { } | |
281 | }; | |
282 | ||
283 | static struct pci_driver mantis_pci_driver = { | |
284 | .name = DRIVER_NAME, | |
285 | .id_table = mantis_pci_table, | |
286 | .probe = mantis_pci_probe, | |
287 | .remove = mantis_pci_remove, | |
288 | }; | |
289 | ||
290 | static int __devinit mantis_init(void) | |
291 | { | |
292 | return pci_register_driver(&mantis_pci_driver); | |
293 | } | |
294 | ||
295 | static void __devexit mantis_exit(void) | |
296 | { | |
297 | return pci_unregister_driver(&mantis_pci_driver); | |
298 | } | |
299 | ||
300 | module_init(mantis_init); | |
301 | module_exit(mantis_exit); | |
302 | ||
303 | MODULE_DESCRIPTION("MANTIS driver"); | |
304 | MODULE_AUTHOR("Manu Abraham"); | |
305 | MODULE_LICENSE("GPL"); |