blob: 66eb0baab0e9948cb4beeb88a1bac60e71c19821 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * bt878.c: part of the driver for the Pinnacle PCTV Sat DVB PCI card
3 *
Johannes Stezenbacha8d995c2005-09-09 13:02:19 -07004 * Copyright (C) 2002 Peter Hettkamp <peter.hettkamp@htp-tel.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * large parts based on the bttv driver
Johannes Stezenbach50b215a2005-05-16 21:54:41 -07007 * Copyright (C) 1996,97,98 Ralph Metzler (rjkm@metzlerbros.de)
8 * & Marcus Metzler (mocm@metzlerbros.de)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * (c) 1999,2000 Gerd Knorr <kraxel@goldbach.in-berlin.de>
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
Johannes Stezenbach43f1a8f2005-05-16 21:54:49 -070015 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
Johannes Stezenbach43f1a8f2005-05-16 21:54:49 -070021 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
Johannes Stezenbach43f1a8f2005-05-16 21:54:49 -070027 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 */
29
30#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/kernel.h>
32#include <linux/pci.h>
33#include <asm/io.h>
34#include <linux/ioport.h>
35#include <asm/pgtable.h>
36#include <asm/page.h>
37#include <linux/types.h>
38#include <linux/interrupt.h>
39#include <linux/kmod.h>
40#include <linux/vmalloc.h>
41#include <linux/init.h>
42
43#include "dmxdev.h"
44#include "dvbdev.h"
45#include "bt878.h"
46#include "dst_priv.h"
47
48
49/**************************************/
50/* Miscellaneous utility definitions */
51/**************************************/
52
53static unsigned int bt878_verbose = 1;
54static unsigned int bt878_debug;
55
56module_param_named(verbose, bt878_verbose, int, 0444);
57MODULE_PARM_DESC(verbose,
58 "verbose startup messages, default is 1 (yes)");
59module_param_named(debug, bt878_debug, int, 0644);
Johannes Stezenbach43f1a8f2005-05-16 21:54:49 -070060MODULE_PARM_DESC(debug, "Turn on/off debugging, default is 0 (off).");
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62int bt878_num;
63struct bt878 bt878[BT878_MAX];
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065EXPORT_SYMBOL(bt878_num);
66EXPORT_SYMBOL(bt878);
67
68#define btwrite(dat,adr) bmtwrite((dat), (bt->bt878_mem+(adr)))
69#define btread(adr) bmtread(bt->bt878_mem+(adr))
70
71#define btand(dat,adr) btwrite((dat) & btread(adr), adr)
72#define btor(dat,adr) btwrite((dat) | btread(adr), adr)
73#define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
74
75#if defined(dprintk)
76#undef dprintk
77#endif
Akinobu Mita46c9fc82008-01-19 05:38:59 -030078#define dprintk(fmt, arg...) \
79 do { \
80 if (bt878_debug) \
81 printk(KERN_DEBUG fmt, ##arg); \
82 } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84static void bt878_mem_free(struct bt878 *bt)
85{
86 if (bt->buf_cpu) {
87 pci_free_consistent(bt->dev, bt->buf_size, bt->buf_cpu,
88 bt->buf_dma);
89 bt->buf_cpu = NULL;
90 }
91
92 if (bt->risc_cpu) {
93 pci_free_consistent(bt->dev, bt->risc_size, bt->risc_cpu,
94 bt->risc_dma);
95 bt->risc_cpu = NULL;
96 }
97}
98
99static int bt878_mem_alloc(struct bt878 *bt)
100{
101 if (!bt->buf_cpu) {
102 bt->buf_size = 128 * 1024;
103
104 bt->buf_cpu =
105 pci_alloc_consistent(bt->dev, bt->buf_size,
106 &bt->buf_dma);
107
108 if (!bt->buf_cpu)
109 return -ENOMEM;
110
111 memset(bt->buf_cpu, 0, bt->buf_size);
112 }
113
114 if (!bt->risc_cpu) {
115 bt->risc_size = PAGE_SIZE;
116 bt->risc_cpu =
117 pci_alloc_consistent(bt->dev, bt->risc_size,
118 &bt->risc_dma);
119
120 if (!bt->risc_cpu) {
121 bt878_mem_free(bt);
122 return -ENOMEM;
123 }
124
125 memset(bt->risc_cpu, 0, bt->risc_size);
126 }
127
128 return 0;
129}
130
131/* RISC instructions */
Johannes Stezenbach43f1a8f2005-05-16 21:54:49 -0700132#define RISC_WRITE (0x01 << 28)
133#define RISC_JUMP (0x07 << 28)
134#define RISC_SYNC (0x08 << 28)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136/* RISC bits */
Johannes Stezenbach43f1a8f2005-05-16 21:54:49 -0700137#define RISC_WR_SOL (1 << 27)
138#define RISC_WR_EOL (1 << 26)
139#define RISC_IRQ (1 << 24)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140#define RISC_STATUS(status) ((((~status) & 0x0F) << 20) | ((status & 0x0F) << 16))
Johannes Stezenbach43f1a8f2005-05-16 21:54:49 -0700141#define RISC_SYNC_RESYNC (1 << 15)
142#define RISC_SYNC_FM1 0x06
143#define RISC_SYNC_VRO 0x0C
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145#define RISC_FLUSH() bt->risc_pos = 0
Johannes Stezenbach43f1a8f2005-05-16 21:54:49 -0700146#define RISC_INSTR(instr) bt->risc_cpu[bt->risc_pos++] = cpu_to_le32(instr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148static int bt878_make_risc(struct bt878 *bt)
149{
150 bt->block_bytes = bt->buf_size >> 4;
151 bt->block_count = 1 << 4;
152 bt->line_bytes = bt->block_bytes;
153 bt->line_count = bt->block_count;
154
155 while (bt->line_bytes > 4095) {
156 bt->line_bytes >>= 1;
157 bt->line_count <<= 1;
158 }
159
160 if (bt->line_count > 255) {
Akinobu Mita46c9fc82008-01-19 05:38:59 -0300161 printk(KERN_ERR "bt878: buffer size error!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 return -EINVAL;
163 }
164 return 0;
165}
166
167
168static void bt878_risc_program(struct bt878 *bt, u32 op_sync_orin)
169{
170 u32 buf_pos = 0;
171 u32 line;
172
173 RISC_FLUSH();
174 RISC_INSTR(RISC_SYNC | RISC_SYNC_FM1 | op_sync_orin);
175 RISC_INSTR(0);
176
Johannes Stezenbach43f1a8f2005-05-16 21:54:49 -0700177 dprintk("bt878: risc len lines %u, bytes per line %u\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 bt->line_count, bt->line_bytes);
179 for (line = 0; line < bt->line_count; line++) {
180 // At the beginning of every block we issue an IRQ with previous (finished) block number set
181 if (!(buf_pos % bt->block_bytes))
182 RISC_INSTR(RISC_WRITE | RISC_WR_SOL | RISC_WR_EOL |
183 RISC_IRQ |
184 RISC_STATUS(((buf_pos /
185 bt->block_bytes) +
186 (bt->block_count -
187 1)) %
188 bt->block_count) | bt->
189 line_bytes);
190 else
191 RISC_INSTR(RISC_WRITE | RISC_WR_SOL | RISC_WR_EOL |
192 bt->line_bytes);
193 RISC_INSTR(bt->buf_dma + buf_pos);
194 buf_pos += bt->line_bytes;
195 }
196
197 RISC_INSTR(RISC_SYNC | op_sync_orin | RISC_SYNC_VRO);
198 RISC_INSTR(0);
199
200 RISC_INSTR(RISC_JUMP);
201 RISC_INSTR(bt->risc_dma);
202
203 btwrite((bt->line_count << 16) | bt->line_bytes, BT878_APACK_LEN);
204}
205
206/*****************************/
207/* Start/Stop grabbing funcs */
208/*****************************/
209
210void bt878_start(struct bt878 *bt, u32 controlreg, u32 op_sync_orin,
211 u32 irq_err_ignore)
212{
213 u32 int_mask;
214
215 dprintk("bt878 debug: bt878_start (ctl=%8.8x)\n", controlreg);
216 /* complete the writing of the risc dma program now we have
217 * the card specifics
218 */
219 bt878_risc_program(bt, op_sync_orin);
220 controlreg &= ~0x1f;
221 controlreg |= 0x1b;
222
Johannes Stezenbach466d7252005-09-09 13:02:53 -0700223 btwrite(bt->risc_dma, BT878_ARISC_START);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
225 /* original int mask had :
226 * 6 2 8 4 0
227 * 1111 1111 1000 0000 0000
228 * SCERR|OCERR|PABORT|RIPERR|FDSR|FTRGT|FBUS|RISCI
229 * Hacked for DST to:
230 * SCERR | OCERR | FDSR | FTRGT | FBUS | RISCI
231 */
Johannes Stezenbach43f1a8f2005-05-16 21:54:49 -0700232 int_mask = BT878_ASCERR | BT878_AOCERR | BT878_APABORT |
233 BT878_ARIPERR | BT878_APPERR | BT878_AFDSR | BT878_AFTRGT |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 BT878_AFBUS | BT878_ARISCI;
235
236
237 /* ignore pesky bits */
238 int_mask &= ~irq_err_ignore;
Johannes Stezenbach43f1a8f2005-05-16 21:54:49 -0700239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 btwrite(int_mask, BT878_AINT_MASK);
241 btwrite(controlreg, BT878_AGPIO_DMA_CTL);
242}
243
244void bt878_stop(struct bt878 *bt)
245{
246 u32 stat;
247 int i = 0;
248
249 dprintk("bt878 debug: bt878_stop\n");
250
251 btwrite(0, BT878_AINT_MASK);
252 btand(~0x13, BT878_AGPIO_DMA_CTL);
253
254 do {
255 stat = btread(BT878_AINT_STAT);
256 if (!(stat & BT878_ARISC_EN))
257 break;
258 i++;
259 } while (i < 500);
260
261 dprintk("bt878(%d) debug: bt878_stop, i=%d, stat=0x%8.8x\n",
262 bt->nr, i, stat);
263}
264
265EXPORT_SYMBOL(bt878_start);
266EXPORT_SYMBOL(bt878_stop);
267
268/*****************************/
269/* Interrupt service routine */
270/*****************************/
271
David Howells7d12e782006-10-05 14:55:46 +0100272static irqreturn_t bt878_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273{
274 u32 stat, astat, mask;
275 int count;
276 struct bt878 *bt;
277
278 bt = (struct bt878 *) dev_id;
279
280 count = 0;
281 while (1) {
282 stat = btread(BT878_AINT_STAT);
283 mask = btread(BT878_AINT_MASK);
284 if (!(astat = (stat & mask)))
285 return IRQ_NONE; /* this interrupt is not for me */
286/* dprintk("bt878(%d) debug: irq count %d, stat 0x%8.8x, mask 0x%8.8x\n",bt->nr,count,stat,mask); */
Robert P. J. Day3a4fa0a2007-10-19 23:10:43 +0200287 btwrite(astat, BT878_AINT_STAT); /* try to clear interrupt condition */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
289
290 if (astat & (BT878_ASCERR | BT878_AOCERR)) {
291 if (bt878_verbose) {
Akinobu Mita46c9fc82008-01-19 05:38:59 -0300292 printk(KERN_INFO
293 "bt878(%d): irq%s%s risc_pc=%08x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 bt->nr,
295 (astat & BT878_ASCERR) ? " SCERR" :
296 "",
297 (astat & BT878_AOCERR) ? " OCERR" :
298 "", btread(BT878_ARISC_PC));
299 }
300 }
301 if (astat & (BT878_APABORT | BT878_ARIPERR | BT878_APPERR)) {
302 if (bt878_verbose) {
Akinobu Mita46c9fc82008-01-19 05:38:59 -0300303 printk(KERN_INFO
304 "bt878(%d): irq%s%s%s risc_pc=%08x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 bt->nr,
306 (astat & BT878_APABORT) ? " PABORT" :
307 "",
308 (astat & BT878_ARIPERR) ? " RIPERR" :
309 "",
310 (astat & BT878_APPERR) ? " PPERR" :
311 "", btread(BT878_ARISC_PC));
312 }
313 }
314 if (astat & (BT878_AFDSR | BT878_AFTRGT | BT878_AFBUS)) {
315 if (bt878_verbose) {
Akinobu Mita46c9fc82008-01-19 05:38:59 -0300316 printk(KERN_INFO
317 "bt878(%d): irq%s%s%s risc_pc=%08x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 bt->nr,
319 (astat & BT878_AFDSR) ? " FDSR" : "",
320 (astat & BT878_AFTRGT) ? " FTRGT" :
321 "",
322 (astat & BT878_AFBUS) ? " FBUS" : "",
323 btread(BT878_ARISC_PC));
324 }
325 }
326 if (astat & BT878_ARISCI) {
327 bt->finished_block = (stat & BT878_ARISCS) >> 28;
328 tasklet_schedule(&bt->tasklet);
329 break;
330 }
331 count++;
332 if (count > 20) {
333 btwrite(0, BT878_AINT_MASK);
334 printk(KERN_ERR
335 "bt878(%d): IRQ lockup, cleared int mask\n",
336 bt->nr);
337 break;
338 }
339 }
340 return IRQ_HANDLED;
341}
342
343int
344bt878_device_control(struct bt878 *bt, unsigned int cmd, union dst_gpio_packet *mp)
345{
346 int retval;
347
348 retval = 0;
Ingo Molnar3593cab2006-02-07 06:49:14 -0200349 if (mutex_lock_interruptible(&bt->gpio_lock))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 return -ERESTARTSYS;
351 /* special gpio signal */
352 switch (cmd) {
353 case DST_IG_ENABLE:
354 // dprintk("dvb_bt8xx: dst enable mask 0x%02x enb 0x%02x \n", mp->dstg.enb.mask, mp->dstg.enb.enable);
355 retval = bttv_gpio_enable(bt->bttv_nr,
356 mp->enb.mask,
357 mp->enb.enable);
358 break;
359 case DST_IG_WRITE:
360 // dprintk("dvb_bt8xx: dst write gpio mask 0x%02x out 0x%02x\n", mp->dstg.outp.mask, mp->dstg.outp.highvals);
361 retval = bttv_write_gpio(bt->bttv_nr,
362 mp->outp.mask,
363 mp->outp.highvals);
364
365 break;
366 case DST_IG_READ:
367 /* read */
368 retval = bttv_read_gpio(bt->bttv_nr, &mp->rd.value);
369 // dprintk("dvb_bt8xx: dst read gpio 0x%02x\n", (unsigned)mp->dstg.rd.value);
370 break;
371 case DST_IG_TS:
372 /* Set packet size */
373 bt->TS_Size = mp->psize;
374 break;
375
376 default:
377 retval = -EINVAL;
378 break;
379 }
Ingo Molnar3593cab2006-02-07 06:49:14 -0200380 mutex_unlock(&bt->gpio_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 return retval;
382}
383
384EXPORT_SYMBOL(bt878_device_control);
385
Akinobu Mita38690072008-01-21 12:15:19 -0300386#define BROOKTREE_878_DEVICE(vend, dev, name) \
387 { \
388 .vendor = PCI_VENDOR_ID_BROOKTREE, \
389 .device = PCI_DEVICE_ID_BROOKTREE_878, \
390 .subvendor = (vend), .subdevice = (dev), \
391 .driver_data = (unsigned long) name \
392 }
Manu Abraham6a5b28f2006-02-07 06:45:30 -0200393
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -0800394static struct pci_device_id bt878_pci_tbl[] = {
Akinobu Mita38690072008-01-21 12:15:19 -0300395 BROOKTREE_878_DEVICE(0x0071, 0x0101, "Nebula Electronics DigiTV"),
396 BROOKTREE_878_DEVICE(0x1461, 0x0761, "AverMedia AverTV DVB-T 761"),
397 BROOKTREE_878_DEVICE(0x11bd, 0x001c, "Pinnacle PCTV Sat"),
398 BROOKTREE_878_DEVICE(0x11bd, 0x0026, "Pinnacle PCTV SAT CI"),
399 BROOKTREE_878_DEVICE(0x1822, 0x0001, "Twinhan VisionPlus DVB"),
400 BROOKTREE_878_DEVICE(0x270f, 0xfc00,
401 "ChainTech digitop DST-1000 DVB-S"),
402 BROOKTREE_878_DEVICE(0x1461, 0x0771, "AVermedia AverTV DVB-T 771"),
403 BROOKTREE_878_DEVICE(0x18ac, 0xdb10, "DViCO FusionHDTV DVB-T Lite"),
404 BROOKTREE_878_DEVICE(0x18ac, 0xdb11, "Ultraview DVB-T Lite"),
405 BROOKTREE_878_DEVICE(0x18ac, 0xd500, "DViCO FusionHDTV 5 Lite"),
406 BROOKTREE_878_DEVICE(0x7063, 0x2000, "pcHDTV HD-2000 TV"),
407 BROOKTREE_878_DEVICE(0x1822, 0x0026, "DNTV Live! Mini"),
408 { }
Manu Abraham6a5b28f2006-02-07 06:45:30 -0200409};
410
Akinobu Mita38690072008-01-21 12:15:19 -0300411MODULE_DEVICE_TABLE(pci, bt878_pci_tbl);
412
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -0800413static const char * card_name(const struct pci_device_id *id)
Akinobu Mita38690072008-01-21 12:15:19 -0300414{
415 return id->driver_data ? (const char *)id->driver_data : "Unknown";
416}
Manu Abraham6a5b28f2006-02-07 06:45:30 -0200417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418/***********************/
419/* PCI device handling */
420/***********************/
421
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -0800422static int bt878_probe(struct pci_dev *dev, const struct pci_device_id *pci_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423{
Akinobu Mita38690072008-01-21 12:15:19 -0300424 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 unsigned char lat;
426 struct bt878 *bt;
427#if defined(__powerpc__)
428 unsigned int cmd;
429#endif
Manu Abraham6a5b28f2006-02-07 06:45:30 -0200430 unsigned int cardid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
432 printk(KERN_INFO "bt878: Bt878 AUDIO function found (%d).\n",
433 bt878_num);
Sigmund Augdal Helberg77e0be12006-06-21 10:35:48 -0300434 if (bt878_num >= BT878_MAX) {
435 printk(KERN_ERR "bt878: Too many devices inserted\n");
436 result = -ENOMEM;
437 goto fail0;
438 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 if (pci_enable_device(dev))
440 return -EIO;
441
Akinobu Mita38690072008-01-21 12:15:19 -0300442 cardid = dev->subsystem_device << 16;
443 cardid |= dev->subsystem_vendor;
Manu Abraham6a5b28f2006-02-07 06:45:30 -0200444
Akinobu Mita38690072008-01-21 12:15:19 -0300445 printk(KERN_INFO "%s: card id=[0x%x],[ %s ] has DVB functions.\n",
446 __func__, cardid, card_name(pci_id));
Manu Abraham6a5b28f2006-02-07 06:45:30 -0200447
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 bt = &bt878[bt878_num];
449 bt->dev = dev;
450 bt->nr = bt878_num;
451 bt->shutdown = 0;
452
453 bt->id = dev->device;
454 bt->irq = dev->irq;
455 bt->bt878_adr = pci_resource_start(dev, 0);
456 if (!request_mem_region(pci_resource_start(dev, 0),
457 pci_resource_len(dev, 0), "bt878")) {
458 result = -EBUSY;
459 goto fail0;
460 }
461
Bjørn Morkabd34d82011-03-21 11:35:56 -0300462 bt->revision = dev->revision;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat);
Manu Abraham6a5b28f2006-02-07 06:45:30 -0200464
465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 printk(KERN_INFO "bt878(%d): Bt%x (rev %d) at %02x:%02x.%x, ",
467 bt878_num, bt->id, bt->revision, dev->bus->number,
468 PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
469 printk("irq: %d, latency: %d, memory: 0x%lx\n",
470 bt->irq, lat, bt->bt878_adr);
471
472
473#if defined(__powerpc__)
474 /* on OpenFirmware machines (PowerMac at least), PCI memory cycle */
475 /* response on cards with no firmware is not enabled by OF */
476 pci_read_config_dword(dev, PCI_COMMAND, &cmd);
477 cmd = (cmd | PCI_COMMAND_MEMORY);
478 pci_write_config_dword(dev, PCI_COMMAND, cmd);
479#endif
480
481#ifdef __sparc__
482 bt->bt878_mem = (unsigned char *) bt->bt878_adr;
483#else
484 bt->bt878_mem = ioremap(bt->bt878_adr, 0x1000);
485#endif
486
487 /* clear interrupt mask */
488 btwrite(0, BT848_INT_MASK);
489
490 result = request_irq(bt->irq, bt878_irq,
Thomas Gleixner8076fe32006-07-01 19:29:37 -0700491 IRQF_SHARED | IRQF_DISABLED, "bt878",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 (void *) bt);
493 if (result == -EINVAL) {
494 printk(KERN_ERR "bt878(%d): Bad irq number or handler\n",
495 bt878_num);
496 goto fail1;
497 }
498 if (result == -EBUSY) {
499 printk(KERN_ERR
500 "bt878(%d): IRQ %d busy, change your PnP config in BIOS\n",
501 bt878_num, bt->irq);
502 goto fail1;
503 }
504 if (result < 0)
505 goto fail1;
506
507 pci_set_master(dev);
508 pci_set_drvdata(dev, bt);
509
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 if ((result = bt878_mem_alloc(bt))) {
Akinobu Mita46c9fc82008-01-19 05:38:59 -0300511 printk(KERN_ERR "bt878: failed to allocate memory!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 goto fail2;
513 }
514
515 bt878_make_risc(bt);
516 btwrite(0, BT878_AINT_MASK);
517 bt878_num++;
518
519 return 0;
520
521 fail2:
522 free_irq(bt->irq, bt);
523 fail1:
524 release_mem_region(pci_resource_start(bt->dev, 0),
525 pci_resource_len(bt->dev, 0));
526 fail0:
527 pci_disable_device(dev);
528 return result;
529}
530
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -0800531static void bt878_remove(struct pci_dev *pci_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532{
533 u8 command;
534 struct bt878 *bt = pci_get_drvdata(pci_dev);
535
536 if (bt878_verbose)
Akinobu Mita46c9fc82008-01-19 05:38:59 -0300537 printk(KERN_INFO "bt878(%d): unloading\n", bt->nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
539 /* turn off all capturing, DMA and IRQs */
540 btand(~0x13, BT878_AGPIO_DMA_CTL);
541
542 /* first disable interrupts before unmapping the memory! */
543 btwrite(0, BT878_AINT_MASK);
544 btwrite(~0U, BT878_AINT_STAT);
545
546 /* disable PCI bus-mastering */
547 pci_read_config_byte(bt->dev, PCI_COMMAND, &command);
548 /* Should this be &=~ ?? */
549 command &= ~PCI_COMMAND_MASTER;
550 pci_write_config_byte(bt->dev, PCI_COMMAND, command);
551
552 free_irq(bt->irq, bt);
553 printk(KERN_DEBUG "bt878_mem: 0x%p.\n", bt->bt878_mem);
554 if (bt->bt878_mem)
555 iounmap(bt->bt878_mem);
556
557 release_mem_region(pci_resource_start(bt->dev, 0),
558 pci_resource_len(bt->dev, 0));
559 /* wake up any waiting processes
560 because shutdown flag is set, no new processes (in this queue)
561 are expected
562 */
563 bt->shutdown = 1;
564 bt878_mem_free(bt);
565
566 pci_set_drvdata(pci_dev, NULL);
567 pci_disable_device(pci_dev);
568 return;
569}
570
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571static struct pci_driver bt878_pci_driver = {
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700572 .name = "bt878",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 .id_table = bt878_pci_tbl,
Johannes Stezenbach50b215a2005-05-16 21:54:41 -0700574 .probe = bt878_probe,
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -0800575 .remove = bt878_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576};
577
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578/*******************************/
579/* Module management functions */
580/*******************************/
581
Peter Huewe310b2622009-12-22 05:38:14 -0300582static int __init bt878_init_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583{
584 bt878_num = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
586 printk(KERN_INFO "bt878: AUDIO driver version %d.%d.%d loaded\n",
587 (BT878_VERSION_CODE >> 16) & 0xff,
588 (BT878_VERSION_CODE >> 8) & 0xff,
589 BT878_VERSION_CODE & 0xff);
Jean Delvare2abf6dd2010-01-26 16:46:58 -0300590
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 return pci_register_driver(&bt878_pci_driver);
592}
593
Peter Huewe310b2622009-12-22 05:38:14 -0300594static void __exit bt878_cleanup_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595{
Jean Delvare2abf6dd2010-01-26 16:46:58 -0300596 pci_unregister_driver(&bt878_pci_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597}
598
599module_init(bt878_init_module);
600module_exit(bt878_cleanup_module);
601
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602MODULE_LICENSE("GPL");
603
604/*
605 * Local variables:
606 * c-basic-offset: 8
607 * End:
608 */