Import 2.3.18pre1
[davej-history.git] / drivers / sound / pas2_card.c
blob488e77a63f723347113ec4f5fab21efbe10e5b91
1 /*
2 * sound/pas2_card.c
4 * Detection routine for the Pro Audio Spectrum cards.
5 */
7 #include <linux/config.h>
8 #include <linux/module.h>
9 #include "sound_config.h"
10 #include "soundmodule.h"
12 #ifdef CONFIG_PAS
14 static unsigned char dma_bits[] = {
15 4, 1, 2, 3, 0, 5, 6, 7
18 static unsigned char irq_bits[] = {
19 0, 0, 1, 2, 3, 4, 5, 6, 0, 1, 7, 8, 9, 0, 10, 11
22 static unsigned char sb_irq_bits[] = {
23 0x00, 0x00, 0x08, 0x10, 0x00, 0x18, 0x00, 0x20,
24 0x00, 0x08, 0x28, 0x30, 0x38, 0, 0
27 static unsigned char sb_dma_bits[] = {
28 0x00, 0x40, 0x80, 0xC0, 0, 0, 0, 0
32 * The Address Translation code is used to convert I/O register addresses to
33 * be relative to the given base -register
36 int translate_code = 0;
37 static int pas_intr_mask = 0;
38 static int pas_irq = 0;
39 static int pas_sb_base = 0;
40 #ifndef CONFIG_PAS_JOYSTICK
41 static int joystick = 0;
42 #else
43 static int joystick = 1;
44 #endif
45 #ifdef SYMPHONY_PAS
46 static int symphony = 1;
47 #else
48 static int symphony = 0;
49 #endif
50 #ifdef BROKEN_BUS_CLOCK
51 static int broken_bus_clock = 1;
52 #else
53 static int broken_bus_clock = 0;
54 #endif
57 char pas_model = 0;
58 static char *pas_model_names[] = {
59 "",
60 "Pro AudioSpectrum+",
61 "CDPC",
62 "Pro AudioSpectrum 16",
63 "Pro AudioSpectrum 16D"
67 * pas_read() and pas_write() are equivalents of inb and outb
68 * These routines perform the I/O address translation required
69 * to support other than the default base address
72 extern void mix_write(unsigned char data, int ioaddr);
74 unsigned char pas_read(int ioaddr)
76 return inb(ioaddr + translate_code);
79 void pas_write(unsigned char data, int ioaddr)
81 outb((data), ioaddr + translate_code);
84 /******************* Begin of the Interrupt Handler ********************/
86 static void pasintr(int irq, void *dev_id, struct pt_regs *dummy)
88 int status;
90 status = pas_read(0x0B89);
91 pas_write(status, 0x0B89); /* Clear interrupt */
93 if (status & 0x08)
95 #ifdef CONFIG_AUDIO
96 pas_pcm_interrupt(status, 1);
97 #endif
98 status &= ~0x08;
100 if (status & 0x10)
102 #ifdef CONFIG_MIDI
103 pas_midi_interrupt();
104 #endif
105 status &= ~0x10;
109 int pas_set_intr(int mask)
111 if (!mask)
112 return 0;
114 pas_intr_mask |= mask;
116 pas_write(pas_intr_mask, 0x0B8B);
117 return 0;
120 int pas_remove_intr(int mask)
122 if (!mask)
123 return 0;
125 pas_intr_mask &= ~mask;
126 pas_write(pas_intr_mask, 0x0B8B);
128 return 0;
131 /******************* End of the Interrupt handler **********************/
133 /******************* Begin of the Initialization Code ******************/
135 extern struct address_info sbhw_config;
137 static int config_pas_hw(struct address_info *hw_config)
139 char ok = 1;
140 unsigned int_ptrs; /* scsi/sound interrupt pointers */
142 pas_irq = hw_config->irq;
144 pas_write(0x00, 0x0B8B);
145 pas_write(0x36, 0x138B);
146 pas_write(0x36, 0x1388);
147 pas_write(0, 0x1388);
148 pas_write(0x74, 0x138B);
149 pas_write(0x74, 0x1389);
150 pas_write(0, 0x1389);
152 pas_write(0x80 | 0x40 | 0x20 | 1, 0x0B8A);
153 pas_write(0x80 | 0x20 | 0x10 | 0x08 | 0x01, 0xF8A);
154 pas_write(0x01 | 0x02 | 0x04 | 0x10 /*
156 * 0x80
157 */ , 0xB88);
159 pas_write(0x80
160 | joystick?0x40:0
161 ,0xF388);
163 if (pas_irq < 0 || pas_irq > 15)
165 printk(KERN_ERR "PAS16: Invalid IRQ %d", pas_irq);
166 hw_config->irq=-1;
167 ok = 0;
169 else
171 int_ptrs = pas_read(0xF38A);
172 int_ptrs = (int_ptrs & 0xf0) | irq_bits[pas_irq];
173 pas_write(int_ptrs, 0xF38A);
174 if (!irq_bits[pas_irq])
176 printk(KERN_ERR "PAS16: Invalid IRQ %d", pas_irq);
177 hw_config->irq=-1;
178 ok = 0;
180 else
182 if (request_irq(pas_irq, pasintr, 0, "PAS16",hw_config) < 0) {
183 printk(KERN_ERR "PAS16: Cannot allocate IRQ %d\n",pas_irq);
184 hw_config->irq=-1;
185 ok = 0;
190 if (hw_config->dma < 0 || hw_config->dma > 7)
192 printk(KERN_ERR "PAS16: Invalid DMA selection %d", hw_config->dma);
193 hw_config->dma=-1;
194 ok = 0;
196 else
198 pas_write(dma_bits[hw_config->dma], 0xF389);
199 if (!dma_bits[hw_config->dma])
201 printk(KERN_ERR "PAS16: Invalid DMA selection %d", hw_config->dma);
202 hw_config->dma=-1;
203 ok = 0;
205 else
207 if (sound_alloc_dma(hw_config->dma, "PAS16"))
209 printk(KERN_ERR "pas2_card.c: Can't allocate DMA channel\n");
210 hw_config->dma=-1;
211 ok = 0;
217 * This fixes the timing problems of the PAS due to the Symphony chipset
218 * as per Media Vision. Only define this if your PAS doesn't work correctly.
221 if(symphony)
223 outb((0x05), 0xa8);
224 outb((0x60), 0xa9);
227 if(broken_bus_clock)
228 pas_write(0x01 | 0x10 | 0x20 | 0x04, 0x8388);
229 else
231 * pas_write(0x01, 0x8388);
233 pas_write(0x01 | 0x10 | 0x20, 0x8388);
235 pas_write(0x18, 0x838A); /* ??? */
236 pas_write(0x20 | 0x01, 0x0B8A); /* Mute off, filter = 17.897 kHz */
237 pas_write(8, 0xBF8A);
239 mix_write(0x80 | 5, 0x078B);
240 mix_write(5, 0x078B);
242 #if !defined(DISABLE_SB_EMULATION) && defined(CONFIG_SB)
245 struct address_info *sb_config;
247 #ifndef MODULE
248 if ((sb_config = sound_getconf(SNDCARD_SB)))
249 #else
250 sb_config = &sbhw_config;
251 if (sb_config->io_base)
252 #endif
254 unsigned char irq_dma;
257 * Turn on Sound Blaster compatibility
258 * bit 1 = SB emulation
259 * bit 0 = MPU401 emulation (CDPC only :-( )
262 pas_write(0x02, 0xF788);
265 * "Emulation address"
268 pas_write((sb_config->io_base >> 4) & 0x0f, 0xF789);
269 pas_sb_base = sb_config->io_base;
271 if (!sb_dma_bits[sb_config->dma])
272 printk(KERN_ERR "PAS16 Warning: Invalid SB DMA %d\n\n", sb_config->dma);
274 if (!sb_irq_bits[sb_config->irq])
275 printk(KERN_ERR "PAS16 Warning: Invalid SB IRQ %d\n\n", sb_config->irq);
277 irq_dma = sb_dma_bits[sb_config->dma] |
278 sb_irq_bits[sb_config->irq];
280 pas_write(irq_dma, 0xFB8A);
282 else
283 pas_write(0x00, 0xF788);
285 #else
286 pas_write(0x00, 0xF788);
287 #endif
289 if (!ok)
290 printk(KERN_WARNING "PAS16: Driver not enabled\n");
292 return ok;
295 static int detect_pas_hw(struct address_info *hw_config)
297 unsigned char board_id, foo;
300 * WARNING: Setting an option like W:1 or so that disables warm boot reset
301 * of the card will screw up this detect code something fierce. Adding code
302 * to handle this means possibly interfering with other cards on the bus if
303 * you have something on base port 0x388. SO be forewarned.
306 outb((0xBC), 0x9A01); /* Activate first board */
307 outb((hw_config->io_base >> 2), 0x9A01); /* Set base address */
308 translate_code = hw_config->io_base - 0x388;
309 pas_write(1, 0xBF88); /* Select one wait states */
311 board_id = pas_read(0x0B8B);
313 if (board_id == 0xff)
314 return 0;
317 * We probably have a PAS-series board, now check for a PAS16-series board
318 * by trying to change the board revision bits. PAS16-series hardware won't
319 * let you do this - the bits are read-only.
322 foo = board_id ^ 0xe0;
324 pas_write(foo, 0x0B8B);
325 foo = pas_read(0x0B8B);
326 pas_write(board_id, 0x0B8B);
328 if (board_id != foo)
329 return 0;
331 pas_model = pas_read(0xFF88);
333 return pas_model;
336 void attach_pas_card(struct address_info *hw_config)
338 pas_irq = hw_config->irq;
340 if (detect_pas_hw(hw_config))
343 if ((pas_model = pas_read(0xFF88)))
345 char temp[100];
347 sprintf(temp,
348 "%s rev %d", pas_model_names[(int) pas_model],
349 pas_read(0x2789));
350 conf_printf(temp, hw_config);
352 if (config_pas_hw(hw_config))
354 #ifdef CONFIG_AUDIO
355 pas_pcm_init(hw_config);
356 #endif
358 #if !defined(MODULE) && !defined(DISABLE_SB_EMULATION) && defined(CONFIG_SB)
360 sb_dsp_disable_midi(pas_sb_base); /* No MIDI capability */
361 #endif
363 #ifdef CONFIG_MIDI
364 pas_midi_init();
365 #endif
366 pas_init_mixer();
371 int probe_pas(struct address_info *hw_config)
373 return detect_pas_hw(hw_config);
376 void unload_pas(struct address_info *hw_config)
378 extern int pas_audiodev;
379 extern int pas2_mididev;
381 if (hw_config->dma>0)
382 sound_free_dma(hw_config->dma);
383 if (hw_config->irq>0)
384 free_irq(hw_config->irq, hw_config);
386 if(pas_audiodev!=-1)
387 sound_unload_mixerdev(audio_devs[pas_audiodev]->mixer_dev);
388 if(pas2_mididev!=-1)
389 sound_unload_mididev(pas2_mididev);
390 if(pas_audiodev!=-1)
391 sound_unload_audiodev(pas_audiodev);
394 #ifdef MODULE
396 int io = -1;
397 int irq = -1;
398 int dma = -1;
399 int dma16 = -1; /* Set this for modules that need it */
401 int sb_io = 0;
402 int sb_irq = -1;
403 int sb_dma = -1;
404 int sb_dma16 = -1;
406 MODULE_PARM(io,"i");
407 MODULE_PARM(irq,"i");
408 MODULE_PARM(dma,"i");
409 MODULE_PARM(dma16,"i");
411 MODULE_PARM(sb_io,"i");
412 MODULE_PARM(sb_irq,"i");
413 MODULE_PARM(sb_dma,"i");
414 MODULE_PARM(sb_dma16,"i");
416 MODULE_PARM(joystick,"i");
417 MODULE_PARM(symphony,"i");
418 MODULE_PARM(broken_bus_clock,"i");
420 struct address_info config;
421 struct address_info sbhw_config;
423 int init_module(void)
425 printk(KERN_INFO "Pro Audio Spectrum driver Copyright (C) by Hannu Savolainen 1993-1996\n");
427 if (io == -1 || dma == -1 || irq == -1)
429 printk(KERN_INFO "I/O, IRQ, DMA and type are mandatory\n");
430 return -EINVAL;
432 config.io_base = io;
433 config.irq = irq;
434 config.dma = dma;
435 config.dma2 = dma16;
437 sbhw_config.io_base = sb_io;
438 sbhw_config.irq = sb_irq;
439 sbhw_config.dma = sb_dma;
440 sbhw_config.dma2 = sb_dma16;
442 if (!probe_pas(&config))
443 return -ENODEV;
444 attach_pas_card(&config);
445 SOUND_LOCK;
446 return 0;
449 void cleanup_module(void)
451 unload_pas(&config);
452 SOUND_LOCK_END;
456 #endif
457 #endif