4 * Detection routine for the Pro Audio Spectrum cards.
7 #include <linux/config.h>
8 #include <linux/init.h>
9 #include <linux/interrupt.h>
10 #include <linux/module.h>
11 #include <linux/spinlock.h>
12 #include "sound_config.h"
17 static unsigned char dma_bits
[] = {
18 4, 1, 2, 3, 0, 5, 6, 7
21 static unsigned char irq_bits
[] = {
22 0, 0, 1, 2, 3, 4, 5, 6, 0, 1, 7, 8, 9, 0, 10, 11
25 static unsigned char sb_irq_bits
[] = {
26 0x00, 0x00, 0x08, 0x10, 0x00, 0x18, 0x00, 0x20,
27 0x00, 0x08, 0x28, 0x30, 0x38, 0, 0
30 static unsigned char sb_dma_bits
[] = {
31 0x00, 0x40, 0x80, 0xC0, 0, 0, 0, 0
35 * The Address Translation code is used to convert I/O register addresses to
36 * be relative to the given base -register
39 int pas_translate_code
= 0;
40 static int pas_intr_mask
;
42 static int pas_sb_base
;
43 DEFINE_SPINLOCK(pas_lock
);
44 #ifndef CONFIG_PAS_JOYSTICK
47 static int joystick
= 1;
50 static int symphony
= 1;
54 #ifdef BROKEN_BUS_CLOCK
55 static int broken_bus_clock
= 1;
57 static int broken_bus_clock
;
60 static struct address_info cfg
;
61 static struct address_info cfg2
;
64 static char *pas_model_names
[] = {
68 "Pro AudioSpectrum 16",
69 "Pro AudioSpectrum 16D"
73 * pas_read() and pas_write() are equivalents of inb and outb
74 * These routines perform the I/O address translation required
75 * to support other than the default base address
78 extern void mix_write(unsigned char data
, int ioaddr
);
80 unsigned char pas_read(int ioaddr
)
82 return inb(ioaddr
+ pas_translate_code
);
85 void pas_write(unsigned char data
, int ioaddr
)
87 outb((data
), ioaddr
+ pas_translate_code
);
90 /******************* Begin of the Interrupt Handler ********************/
92 static irqreturn_t
pasintr(int irq
, void *dev_id
, struct pt_regs
*dummy
)
96 status
= pas_read(0x0B89);
97 pas_write(status
, 0x0B89); /* Clear interrupt */
101 pas_pcm_interrupt(status
, 1);
106 pas_midi_interrupt();
112 int pas_set_intr(int mask
)
117 pas_intr_mask
|= mask
;
119 pas_write(pas_intr_mask
, 0x0B8B);
123 int pas_remove_intr(int mask
)
128 pas_intr_mask
&= ~mask
;
129 pas_write(pas_intr_mask
, 0x0B8B);
134 /******************* End of the Interrupt handler **********************/
136 /******************* Begin of the Initialization Code ******************/
138 static int __init
config_pas_hw(struct address_info
*hw_config
)
141 unsigned int_ptrs
; /* scsi/sound interrupt pointers */
143 pas_irq
= hw_config
->irq
;
145 pas_write(0x00, 0x0B8B);
146 pas_write(0x36, 0x138B);
147 pas_write(0x36, 0x1388);
148 pas_write(0, 0x1388);
149 pas_write(0x74, 0x138B);
150 pas_write(0x74, 0x1389);
151 pas_write(0, 0x1389);
153 pas_write(0x80 | 0x40 | 0x20 | 1, 0x0B8A);
154 pas_write(0x80 | 0x20 | 0x10 | 0x08 | 0x01, 0xF8A);
155 pas_write(0x01 | 0x02 | 0x04 | 0x10 /*
164 if (pas_irq
< 0 || pas_irq
> 15)
166 printk(KERN_ERR
"PAS16: Invalid IRQ %d", pas_irq
);
172 int_ptrs
= pas_read(0xF38A);
173 int_ptrs
= (int_ptrs
& 0xf0) | irq_bits
[pas_irq
];
174 pas_write(int_ptrs
, 0xF38A);
175 if (!irq_bits
[pas_irq
])
177 printk(KERN_ERR
"PAS16: Invalid IRQ %d", pas_irq
);
183 if (request_irq(pas_irq
, pasintr
, 0, "PAS16",hw_config
) < 0) {
184 printk(KERN_ERR
"PAS16: Cannot allocate IRQ %d\n",pas_irq
);
191 if (hw_config
->dma
< 0 || hw_config
->dma
> 7)
193 printk(KERN_ERR
"PAS16: Invalid DMA selection %d", hw_config
->dma
);
199 pas_write(dma_bits
[hw_config
->dma
], 0xF389);
200 if (!dma_bits
[hw_config
->dma
])
202 printk(KERN_ERR
"PAS16: Invalid DMA selection %d", hw_config
->dma
);
208 if (sound_alloc_dma(hw_config
->dma
, "PAS16"))
210 printk(KERN_ERR
"pas2_card.c: Can't allocate DMA channel\n");
218 * This fixes the timing problems of the PAS due to the Symphony chipset
219 * as per Media Vision. Only define this if your PAS doesn't work correctly.
229 pas_write(0x01 | 0x10 | 0x20 | 0x04, 0x8388);
232 * pas_write(0x01, 0x8388);
234 pas_write(0x01 | 0x10 | 0x20, 0x8388);
236 pas_write(0x18, 0x838A); /* ??? */
237 pas_write(0x20 | 0x01, 0x0B8A); /* Mute off, filter = 17.897 kHz */
238 pas_write(8, 0xBF8A);
240 mix_write(0x80 | 5, 0x078B);
241 mix_write(5, 0x078B);
244 struct address_info
*sb_config
;
247 if (sb_config
->io_base
)
249 unsigned char irq_dma
;
252 * Turn on Sound Blaster compatibility
253 * bit 1 = SB emulation
254 * bit 0 = MPU401 emulation (CDPC only :-( )
257 pas_write(0x02, 0xF788);
260 * "Emulation address"
263 pas_write((sb_config
->io_base
>> 4) & 0x0f, 0xF789);
264 pas_sb_base
= sb_config
->io_base
;
266 if (!sb_dma_bits
[sb_config
->dma
])
267 printk(KERN_ERR
"PAS16 Warning: Invalid SB DMA %d\n\n", sb_config
->dma
);
269 if (!sb_irq_bits
[sb_config
->irq
])
270 printk(KERN_ERR
"PAS16 Warning: Invalid SB IRQ %d\n\n", sb_config
->irq
);
272 irq_dma
= sb_dma_bits
[sb_config
->dma
] |
273 sb_irq_bits
[sb_config
->irq
];
275 pas_write(irq_dma
, 0xFB8A);
278 pas_write(0x00, 0xF788);
282 printk(KERN_WARNING
"PAS16: Driver not enabled\n");
287 static int __init
detect_pas_hw(struct address_info
*hw_config
)
289 unsigned char board_id
, foo
;
292 * WARNING: Setting an option like W:1 or so that disables warm boot reset
293 * of the card will screw up this detect code something fierce. Adding code
294 * to handle this means possibly interfering with other cards on the bus if
295 * you have something on base port 0x388. SO be forewarned.
298 outb((0xBC), 0x9A01); /* Activate first board */
299 outb((hw_config
->io_base
>> 2), 0x9A01); /* Set base address */
300 pas_translate_code
= hw_config
->io_base
- 0x388;
301 pas_write(1, 0xBF88); /* Select one wait states */
303 board_id
= pas_read(0x0B8B);
305 if (board_id
== 0xff)
309 * We probably have a PAS-series board, now check for a PAS16-series board
310 * by trying to change the board revision bits. PAS16-series hardware won't
311 * let you do this - the bits are read-only.
314 foo
= board_id
^ 0xe0;
316 pas_write(foo
, 0x0B8B);
317 foo
= pas_read(0x0B8B);
318 pas_write(board_id
, 0x0B8B);
323 pas_model
= pas_read(0xFF88);
328 static void __init
attach_pas_card(struct address_info
*hw_config
)
330 pas_irq
= hw_config
->irq
;
332 if (detect_pas_hw(hw_config
))
335 if ((pas_model
= pas_read(0xFF88)))
340 "%s rev %d", pas_model_names
[(int) pas_model
],
342 conf_printf(temp
, hw_config
);
344 if (config_pas_hw(hw_config
))
346 pas_pcm_init(hw_config
);
353 static inline int __init
probe_pas(struct address_info
*hw_config
)
355 return detect_pas_hw(hw_config
);
358 static void __exit
unload_pas(struct address_info
*hw_config
)
360 extern int pas_audiodev
;
361 extern int pas2_mididev
;
363 if (hw_config
->dma
>0)
364 sound_free_dma(hw_config
->dma
);
365 if (hw_config
->irq
>0)
366 free_irq(hw_config
->irq
, hw_config
);
369 sound_unload_mixerdev(audio_devs
[pas_audiodev
]->mixer_dev
);
371 sound_unload_mididev(pas2_mididev
);
373 sound_unload_audiodev(pas_audiodev
);
376 static int __initdata io
= -1;
377 static int __initdata irq
= -1;
378 static int __initdata dma
= -1;
379 static int __initdata dma16
= -1; /* Set this for modules that need it */
381 static int __initdata sb_io
= 0;
382 static int __initdata sb_irq
= -1;
383 static int __initdata sb_dma
= -1;
384 static int __initdata sb_dma16
= -1;
386 module_param(io
, int, 0);
387 module_param(irq
, int, 0);
388 module_param(dma
, int, 0);
389 module_param(dma16
, int, 0);
391 module_param(sb_io
, int, 0);
392 module_param(sb_irq
, int, 0);
393 module_param(sb_dma
, int, 0);
394 module_param(sb_dma16
, int, 0);
396 module_param(joystick
, bool, 0);
397 module_param(symphony
, bool, 0);
398 module_param(broken_bus_clock
, bool, 0);
400 MODULE_LICENSE("GPL");
402 static int __init
init_pas2(void)
404 printk(KERN_INFO
"Pro Audio Spectrum driver Copyright (C) by Hannu Savolainen 1993-1996\n");
411 cfg2
.io_base
= sb_io
;
414 cfg2
.dma2
= sb_dma16
;
416 if (cfg
.io_base
== -1 || cfg
.dma
== -1 || cfg
.irq
== -1) {
417 printk(KERN_INFO
"I/O, IRQ, DMA and type are mandatory\n");
421 if (!probe_pas(&cfg
))
423 attach_pas_card(&cfg
);
428 static void __exit
cleanup_pas2(void)
433 module_init(init_pas2
);
434 module_exit(cleanup_pas2
);
437 static int __init
setup_pas2(char *str
)
439 /* io, irq, dma, dma2, sb_io, sb_irq, sb_dma, sb_dma2 */
442 str
= get_options(str
, ARRAY_SIZE(ints
), ints
);
457 __setup("pas2=", setup_pas2
);