~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/oss/pas2_card.c

Version: ~ [ linux-5.2-rc1 ] ~ [ linux-5.1.2 ] ~ [ linux-5.0.16 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.43 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.119 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.176 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.179 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.139 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.67 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * sound/pas2_card.c
  3  *
  4  * Detection routine for the Pro Audio Spectrum cards.
  5  */
  6 
  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"
 13 
 14 #include "pas2.h"
 15 #include "sb.h"
 16 
 17 static unsigned char dma_bits[] = {
 18         4, 1, 2, 3, 0, 5, 6, 7
 19 };
 20 
 21 static unsigned char irq_bits[] = {
 22         0, 0, 1, 2, 3, 4, 5, 6, 0, 1, 7, 8, 9, 0, 10, 11
 23 };
 24 
 25 static unsigned char sb_irq_bits[] = {
 26         0x00, 0x00, 0x08, 0x10, 0x00, 0x18, 0x00, 0x20, 
 27         0x00, 0x08, 0x28, 0x30, 0x38, 0, 0
 28 };
 29 
 30 static unsigned char sb_dma_bits[] = {
 31         0x00, 0x40, 0x80, 0xC0, 0, 0, 0, 0
 32 };
 33 
 34 /*
 35  * The Address Translation code is used to convert I/O register addresses to
 36  * be relative to the given base -register
 37  */
 38 
 39 int             pas_translate_code = 0;
 40 static int      pas_intr_mask;
 41 static int      pas_irq;
 42 static int      pas_sb_base;
 43 spinlock_t      pas_lock=SPIN_LOCK_UNLOCKED;
 44 #ifndef CONFIG_PAS_JOYSTICK
 45 static int      joystick;
 46 #else
 47 static int      joystick = 1;
 48 #endif
 49 #ifdef SYMPHONY_PAS
 50 static int      symphony = 1;
 51 #else
 52 static int      symphony;
 53 #endif
 54 #ifdef BROKEN_BUS_CLOCK
 55 static int      broken_bus_clock = 1;
 56 #else
 57 static int      broken_bus_clock;
 58 #endif
 59 
 60 static struct address_info cfg;
 61 static struct address_info cfg2;
 62 
 63 char            pas_model = 0;
 64 static char    *pas_model_names[] = {
 65         "", 
 66         "Pro AudioSpectrum+", 
 67         "CDPC", 
 68         "Pro AudioSpectrum 16", 
 69         "Pro AudioSpectrum 16D"
 70 };
 71 
 72 /*
 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
 76  */
 77 
 78 extern void     mix_write(unsigned char data, int ioaddr);
 79 
 80 unsigned char pas_read(int ioaddr)
 81 {
 82         return inb(ioaddr + pas_translate_code);
 83 }
 84 
 85 void pas_write(unsigned char data, int ioaddr)
 86 {
 87         outb((data), ioaddr + pas_translate_code);
 88 }
 89 
 90 /******************* Begin of the Interrupt Handler ********************/
 91 
 92 static irqreturn_t pasintr(int irq, void *dev_id, struct pt_regs *dummy)
 93 {
 94         int             status;
 95 
 96         status = pas_read(0x0B89);
 97         pas_write(status, 0x0B89);      /* Clear interrupt */
 98 
 99         if (status & 0x08)
100         {
101                   pas_pcm_interrupt(status, 1);
102                   status &= ~0x08;
103         }
104         if (status & 0x10)
105         {
106                   pas_midi_interrupt();
107                   status &= ~0x10;
108         }
109         return IRQ_HANDLED;
110 }
111 
112 int pas_set_intr(int mask)
113 {
114         if (!mask)
115                 return 0;
116 
117         pas_intr_mask |= mask;
118 
119         pas_write(pas_intr_mask, 0x0B8B);
120         return 0;
121 }
122 
123 int pas_remove_intr(int mask)
124 {
125         if (!mask)
126                 return 0;
127 
128         pas_intr_mask &= ~mask;
129         pas_write(pas_intr_mask, 0x0B8B);
130 
131         return 0;
132 }
133 
134 /******************* End of the Interrupt handler **********************/
135 
136 /******************* Begin of the Initialization Code ******************/
137 
138 static int __init config_pas_hw(struct address_info *hw_config)
139 {
140         char            ok = 1;
141         unsigned        int_ptrs;       /* scsi/sound interrupt pointers */
142 
143         pas_irq = hw_config->irq;
144 
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);
152 
153         pas_write(0x80 | 0x40 | 0x20 | 1, 0x0B8A);
154         pas_write(0x80 | 0x20 | 0x10 | 0x08 | 0x01, 0xF8A);
155         pas_write(0x01 | 0x02 | 0x04 | 0x10     /*
156                                                  * |
157                                                  * 0x80
158                                                  */ , 0xB88);
159 
160         pas_write(0x80
161                   | joystick?0x40:0
162                   ,0xF388);
163 
164         if (pas_irq < 0 || pas_irq > 15)
165         {
166                 printk(KERN_ERR "PAS16: Invalid IRQ %d", pas_irq);
167                 hw_config->irq=-1;
168                 ok = 0;
169         }
170         else
171         {
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])
176                 {
177                         printk(KERN_ERR "PAS16: Invalid IRQ %d", pas_irq);
178                         hw_config->irq=-1;
179                         ok = 0;
180                 }
181                 else
182                 {
183                         if (request_irq(pas_irq, pasintr, 0, "PAS16",hw_config) < 0) {
184                                 printk(KERN_ERR "PAS16: Cannot allocate IRQ %d\n",pas_irq);
185                                 hw_config->irq=-1;
186                                 ok = 0;
187                         }
188                 }
189         }
190 
191         if (hw_config->dma < 0 || hw_config->dma > 7)
192         {
193                 printk(KERN_ERR "PAS16: Invalid DMA selection %d", hw_config->dma);
194                 hw_config->dma=-1;
195                 ok = 0;
196         }
197         else
198         {
199                 pas_write(dma_bits[hw_config->dma], 0xF389);
200                 if (!dma_bits[hw_config->dma])
201                 {
202                         printk(KERN_ERR "PAS16: Invalid DMA selection %d", hw_config->dma);
203                         hw_config->dma=-1;
204                         ok = 0;
205                 }
206                 else
207                 {
208                         if (sound_alloc_dma(hw_config->dma, "PAS16"))
209                         {
210                                 printk(KERN_ERR "pas2_card.c: Can't allocate DMA channel\n");
211                                 hw_config->dma=-1;
212                                 ok = 0;
213                         }
214                 }
215         }
216 
217         /*
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.
220          */
221 
222         if(symphony)
223         {
224                 outb((0x05), 0xa8);
225                 outb((0x60), 0xa9);
226         }
227 
228         if(broken_bus_clock)
229                 pas_write(0x01 | 0x10 | 0x20 | 0x04, 0x8388);
230         else
231                 /*
232                  * pas_write(0x01, 0x8388);
233                  */
234                 pas_write(0x01 | 0x10 | 0x20, 0x8388);
235 
236         pas_write(0x18, 0x838A);        /* ??? */
237         pas_write(0x20 | 0x01, 0x0B8A);         /* Mute off, filter = 17.897 kHz */
238         pas_write(8, 0xBF8A);
239 
240         mix_write(0x80 | 5, 0x078B);
241         mix_write(5, 0x078B);
242 
243 #if !defined(DISABLE_SB_EMULATION)
244 
245         {
246                 struct address_info *sb_config;
247 
248                 sb_config = &cfg2;
249                 if (sb_config->io_base)
250                 {
251                         unsigned char   irq_dma;
252 
253                         /*
254                          * Turn on Sound Blaster compatibility
255                          * bit 1 = SB emulation
256                          * bit 0 = MPU401 emulation (CDPC only :-( )
257                          */
258                         
259                         pas_write(0x02, 0xF788);
260 
261                         /*
262                          * "Emulation address"
263                          */
264                         
265                         pas_write((sb_config->io_base >> 4) & 0x0f, 0xF789);
266                         pas_sb_base = sb_config->io_base;
267 
268                         if (!sb_dma_bits[sb_config->dma])
269                                 printk(KERN_ERR "PAS16 Warning: Invalid SB DMA %d\n\n", sb_config->dma);
270 
271                         if (!sb_irq_bits[sb_config->irq])
272                                 printk(KERN_ERR "PAS16 Warning: Invalid SB IRQ %d\n\n", sb_config->irq);
273 
274                         irq_dma = sb_dma_bits[sb_config->dma] |
275                                 sb_irq_bits[sb_config->irq];
276 
277                         pas_write(irq_dma, 0xFB8A);
278                 }
279                 else
280                         pas_write(0x00, 0xF788);
281         }
282 #else
283         pas_write(0x00, 0xF788);
284 #endif
285 
286         if (!ok)
287                 printk(KERN_WARNING "PAS16: Driver not enabled\n");
288 
289         return ok;
290 }
291 
292 static int __init detect_pas_hw(struct address_info *hw_config)
293 {
294         unsigned char   board_id, foo;
295 
296         /*
297          * WARNING: Setting an option like W:1 or so that disables warm boot reset
298          * of the card will screw up this detect code something fierce. Adding code
299          * to handle this means possibly interfering with other cards on the bus if
300          * you have something on base port 0x388. SO be forewarned.
301          */
302 
303         outb((0xBC), 0x9A01);   /* Activate first board */
304         outb((hw_config->io_base >> 2), 0x9A01);        /* Set base address */
305         pas_translate_code = hw_config->io_base - 0x388;
306         pas_write(1, 0xBF88);   /* Select one wait states */
307 
308         board_id = pas_read(0x0B8B);
309 
310         if (board_id == 0xff)
311                 return 0;
312 
313         /*
314          * We probably have a PAS-series board, now check for a PAS16-series board
315          * by trying to change the board revision bits. PAS16-series hardware won't
316          * let you do this - the bits are read-only.
317          */
318 
319         foo = board_id ^ 0xe0;
320 
321         pas_write(foo, 0x0B8B);
322         foo = pas_read(0x0B8B);
323         pas_write(board_id, 0x0B8B);
324 
325         if (board_id != foo)
326                 return 0;
327 
328         pas_model = pas_read(0xFF88);
329 
330         return pas_model;
331 }
332 
333 static void __init attach_pas_card(struct address_info *hw_config)
334 {
335         pas_irq = hw_config->irq;
336 
337         if (detect_pas_hw(hw_config))
338         {
339 
340                 if ((pas_model = pas_read(0xFF88)))
341                 {
342                         char            temp[100];
343 
344                         sprintf(temp,
345                             "%s rev %d", pas_model_names[(int) pas_model],
346                                     pas_read(0x2789));
347                         conf_printf(temp, hw_config);
348                 }
349                 if (config_pas_hw(hw_config))
350                 {
351                         pas_pcm_init(hw_config);
352 
353 #if !defined(MODULE) && !defined(DISABLE_SB_EMULATION)
354                         sb_dsp_disable_midi(pas_sb_base);       /* No MIDI capability */
355 #endif
356 
357                         pas_midi_init();
358                         pas_init_mixer();
359                 }
360         }
361 }
362 
363 static inline int __init probe_pas(struct address_info *hw_config)
364 {
365         return detect_pas_hw(hw_config);
366 }
367 
368 static void __exit unload_pas(struct address_info *hw_config)
369 {
370         extern int pas_audiodev;
371         extern int pas2_mididev;
372 
373         if (hw_config->dma>0)
374                 sound_free_dma(hw_config->dma);
375         if (hw_config->irq>0)
376                 free_irq(hw_config->irq, hw_config);
377 
378         if(pas_audiodev!=-1)
379                 sound_unload_mixerdev(audio_devs[pas_audiodev]->mixer_dev);
380         if(pas2_mididev!=-1)
381                 sound_unload_mididev(pas2_mididev);
382         if(pas_audiodev!=-1)
383                 sound_unload_audiodev(pas_audiodev);
384 }
385 
386 static int __initdata io        = -1;
387 static int __initdata irq       = -1;
388 static int __initdata dma       = -1;
389 static int __initdata dma16     = -1;   /* Set this for modules that need it */
390 
391 static int __initdata sb_io     = 0;
392 static int __initdata sb_irq    = -1;
393 static int __initdata sb_dma    = -1;
394 static int __initdata sb_dma16  = -1;
395 
396 MODULE_PARM(io,"i");
397 MODULE_PARM(irq,"i");
398 MODULE_PARM(dma,"i");
399 MODULE_PARM(dma16,"i");
400 
401 MODULE_PARM(sb_io,"i");
402 MODULE_PARM(sb_irq,"i");
403 MODULE_PARM(sb_dma,"i");
404 MODULE_PARM(sb_dma16,"i");
405 
406 MODULE_PARM(joystick,"i");
407 MODULE_PARM(symphony,"i");
408 MODULE_PARM(broken_bus_clock,"i");
409 
410 MODULE_LICENSE("GPL");
411 
412 static int __init init_pas2(void)
413 {
414         printk(KERN_INFO "Pro Audio Spectrum driver Copyright (C) by Hannu Savolainen 1993-1996\n");
415 
416         cfg.io_base = io;
417         cfg.irq = irq;
418         cfg.dma = dma;
419         cfg.dma2 = dma16;
420 
421         cfg2.io_base = sb_io;
422         cfg2.irq = sb_irq;
423         cfg2.dma = sb_dma;
424         cfg2.dma2 = sb_dma16;
425 
426         if (cfg.io_base == -1 || cfg.dma == -1 || cfg.irq == -1) {
427                 printk(KERN_INFO "I/O, IRQ, DMA and type are mandatory\n");
428                 return -EINVAL;
429         }
430 
431         if (!probe_pas(&cfg))
432                 return -ENODEV;
433         attach_pas_card(&cfg);
434 
435         return 0;
436 }
437 
438 static void __exit cleanup_pas2(void)
439 {
440         unload_pas(&cfg);
441 }
442 
443 module_init(init_pas2);
444 module_exit(cleanup_pas2);
445 
446 #ifndef MODULE
447 static int __init setup_pas2(char *str)
448 {
449         /* io, irq, dma, dma2, sb_io, sb_irq, sb_dma, sb_dma2 */
450         int ints[9];
451         
452         str = get_options(str, ARRAY_SIZE(ints), ints);
453 
454         io      = ints[1];
455         irq     = ints[2];
456         dma     = ints[3];
457         dma16   = ints[4];
458 
459         sb_io   = ints[5];
460         sb_irq  = ints[6];
461         sb_dma  = ints[7];
462         sb_dma16 = ints[8];
463 
464         return 1;
465 }
466 
467 __setup("pas2=", setup_pas2);
468 #endif
469 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp