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

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

Version: ~ [ linux-5.10-rc1 ] ~ [ linux-5.9.1 ] ~ [ linux-5.8.16 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.72 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.152 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.202 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.240 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.240 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ 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-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/sb_common.c
  3  *
  4  * Common routines for Sound Blaster compatible cards.
  5  *
  6  *
  7  * Copyright (C) by Hannu Savolainen 1993-1997
  8  *
  9  * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
 10  * Version 2 (June 1991). See the "COPYING" file distributed with this software
 11  * for more info.
 12  *
 13  *
 14  * Daniel J. Rodriksson: Modified sbintr to handle 8 and 16 bit interrupts
 15  *                       for full duplex support ( only sb16 by now )
 16  * Rolf Fokkens:         Added (BETA?) support for ES1887 chips.
 17  * (fokkensr@vertis.nl)  Which means: You can adjust the recording levels.
 18  *
 19  * 2000/01/18 - separated sb_card and sb_common -
 20  * Jeff Garzik <jgarzik@pobox.com>
 21  *
 22  * 2000/09/18 - got rid of attach_uart401
 23  * Arnaldo Carvalho de Melo <acme@conectiva.com.br>
 24  *
 25  * 2001/01/26 - replaced CLI/STI with spinlocks
 26  * Chris Rankin <rankinc@zipworld.com.au>
 27  */
 28 
 29 #include <linux/config.h>
 30 #include <linux/init.h>
 31 #include <linux/interrupt.h>
 32 #include <linux/module.h>
 33 #include <linux/delay.h>
 34 #include <linux/spinlock.h>
 35 
 36 #include "sound_config.h"
 37 #include "sound_firmware.h"
 38 
 39 #include "mpu401.h"
 40 
 41 #include "sb_mixer.h"
 42 #include "sb.h"
 43 #include "sb_ess.h"
 44 
 45 /*
 46  * global module flag
 47  */
 48 
 49 int sb_be_quiet;
 50 
 51 static sb_devc *detected_devc;  /* For communication from probe to init */
 52 static sb_devc *last_devc;      /* For MPU401 initialization */
 53 
 54 static unsigned char jazz_irq_bits[] = {
 55         0, 0, 2, 3, 0, 1, 0, 4, 0, 2, 5, 0, 0, 0, 0, 6
 56 };
 57 
 58 static unsigned char jazz_dma_bits[] = {
 59         0, 1, 0, 2, 0, 3, 0, 4
 60 };
 61 
 62 void *smw_free;
 63 
 64 /*
 65  * Jazz16 chipset specific control variables
 66  */
 67 
 68 static int jazz16_base;                 /* Not detected */
 69 static unsigned char jazz16_bits;       /* I/O relocation bits */
 70 static spinlock_t jazz16_lock = SPIN_LOCK_UNLOCKED;
 71 
 72 /*
 73  * Logitech Soundman Wave specific initialization code
 74  */
 75 
 76 #ifdef SMW_MIDI0001_INCLUDED
 77 #include "smw-midi0001.h"
 78 #else
 79 static unsigned char *smw_ucode;
 80 static int      smw_ucodeLen;
 81 
 82 #endif
 83 
 84 sb_devc *last_sb;               /* Last sb loaded */
 85 
 86 int sb_dsp_command(sb_devc * devc, unsigned char val)
 87 {
 88         int i;
 89         unsigned long limit;
 90 
 91         limit = jiffies + HZ / 10;      /* Timeout */
 92         
 93         /*
 94          * Note! the i<500000 is an emergency exit. The sb_dsp_command() is sometimes
 95          * called while interrupts are disabled. This means that the timer is
 96          * disabled also. However the timeout situation is a abnormal condition.
 97          * Normally the DSP should be ready to accept commands after just couple of
 98          * loops.
 99          */
100 
101         for (i = 0; i < 500000 && (limit-jiffies)>0; i++)
102         {
103                 if ((inb(DSP_STATUS) & 0x80) == 0)
104                 {
105                         outb((val), DSP_COMMAND);
106                         return 1;
107                 }
108         }
109         printk(KERN_WARNING "Sound Blaster:  DSP command(%x) timeout.\n", val);
110         return 0;
111 }
112 
113 int sb_dsp_get_byte(sb_devc * devc)
114 {
115         int i;
116 
117         for (i = 1000; i; i--)
118         {
119                 if (inb(DSP_DATA_AVAIL) & 0x80)
120                         return inb(DSP_READ);
121         }
122         return 0xffff;
123 }
124 
125 static void sb_intr (sb_devc *devc)
126 {
127         int status;
128         unsigned char   src = 0xff;
129 
130         if (devc->model == MDL_SB16)
131         {
132                 src = sb_getmixer(devc, IRQ_STAT);      /* Interrupt source register */
133 
134                 if (src & 4)                                            /* MPU401 interrupt */
135                         if(devc->midi_irq_cookie)
136                                 uart401intr(devc->irq, devc->midi_irq_cookie, NULL);
137 
138                 if (!(src & 3))
139                         return; /* Not a DSP interrupt */
140         }
141         if (devc->intr_active && (!devc->fullduplex || (src & 0x01)))
142         {
143                 switch (devc->irq_mode)
144                 {
145                         case IMODE_OUTPUT:
146                                 DMAbuf_outputintr(devc->dev, 1);
147                                 break;
148 
149                         case IMODE_INPUT:
150                                 DMAbuf_inputintr(devc->dev);
151                                 break;
152 
153                         case IMODE_INIT:
154                                 break;
155 
156                         case IMODE_MIDI:
157                                 sb_midi_interrupt(devc);
158                                 break;
159 
160                         default:
161                                 /* printk(KERN_WARN "Sound Blaster: Unexpected interrupt\n"); */
162                                 ;
163                 }
164         }
165         else if (devc->intr_active_16 && (src & 0x02))
166         {
167                 switch (devc->irq_mode_16)
168                 {
169                         case IMODE_OUTPUT:
170                                 DMAbuf_outputintr(devc->dev, 1);
171                                 break;
172 
173                         case IMODE_INPUT:
174                                 DMAbuf_inputintr(devc->dev);
175                                 break;
176 
177                         case IMODE_INIT:
178                                 break;
179 
180                         default:
181                                 /* printk(KERN_WARN "Sound Blaster: Unexpected interrupt\n"); */
182                                 ;
183                 }
184         }
185         /*
186          * Acknowledge interrupts 
187          */
188 
189         if (src & 0x01)
190                 status = inb(DSP_DATA_AVAIL);
191 
192         if (devc->model == MDL_SB16 && src & 0x02)
193                 status = inb(DSP_DATA_AVL16);
194 }
195 
196 static void pci_intr(sb_devc *devc)
197 {
198         int src = inb(devc->pcibase+0x1A);
199         src&=3;
200         if(src)
201                 sb_intr(devc);
202 }
203 
204 static irqreturn_t sbintr(int irq, void *dev_id, struct pt_regs *dummy)
205 {
206         sb_devc *devc = dev_id;
207 
208         devc->irq_ok = 1;
209 
210         switch (devc->model) {
211         case MDL_ESSPCI:
212                 pci_intr (devc);
213                 break;
214                 
215         case MDL_ESS:
216                 ess_intr (devc);
217                 break;
218         default:
219                 sb_intr (devc);
220                 break;
221         }
222         return IRQ_HANDLED;
223 }
224 
225 int sb_dsp_reset(sb_devc * devc)
226 {
227         int loopc;
228 
229         DEB(printk("Entered sb_dsp_reset()\n"));
230 
231         if (devc->model == MDL_ESS) return ess_dsp_reset (devc);
232 
233         /* This is only for non-ESS chips */
234 
235         outb(1, DSP_RESET);
236 
237         udelay(10);
238         outb(0, DSP_RESET);
239         udelay(30);
240 
241         for (loopc = 0; loopc < 1000 && !(inb(DSP_DATA_AVAIL) & 0x80); loopc++);
242 
243         if (inb(DSP_READ) != 0xAA)
244         {
245                 DDB(printk("sb: No response to RESET\n"));
246                 return 0;       /* Sorry */
247         }
248 
249         DEB(printk("sb_dsp_reset() OK\n"));
250 
251         return 1;
252 }
253 
254 static void dsp_get_vers(sb_devc * devc)
255 {
256         int i;
257 
258         unsigned long   flags;
259 
260         DDB(printk("Entered dsp_get_vers()\n"));
261         spin_lock_irqsave(&devc->lock, flags);
262         devc->major = devc->minor = 0;
263         sb_dsp_command(devc, 0xe1);     /* Get version */
264 
265         for (i = 100000; i; i--)
266         {
267                 if (inb(DSP_DATA_AVAIL) & 0x80)
268                 {
269                         if (devc->major == 0)
270                                 devc->major = inb(DSP_READ);
271                         else
272                         {
273                                 devc->minor = inb(DSP_READ);
274                                 break;
275                         }
276                 }
277         }
278         spin_unlock_irqrestore(&devc->lock, flags);
279         DDB(printk("DSP version %d.%02d\n", devc->major, devc->minor));
280 }
281 
282 static int sb16_set_dma_hw(sb_devc * devc)
283 {
284         int bits;
285 
286         if (devc->dma8 != 0 && devc->dma8 != 1 && devc->dma8 != 3)
287         {
288                 printk(KERN_ERR "SB16: Invalid 8 bit DMA (%d)\n", devc->dma8);
289                 return 0;
290         }
291         bits = (1 << devc->dma8);
292 
293         if (devc->dma16 >= 5 && devc->dma16 <= 7)
294                 bits |= (1 << devc->dma16);
295 
296         sb_setmixer(devc, DMA_NR, bits);
297         return 1;
298 }
299 
300 static void sb16_set_mpu_port(sb_devc * devc, struct address_info *hw_config)
301 {
302         /*
303          * This routine initializes new MIDI port setup register of SB Vibra (CT2502).
304          */
305         unsigned char   bits = sb_getmixer(devc, 0x84) & ~0x06;
306 
307         switch (hw_config->io_base)
308         {
309                 case 0x300:
310                         sb_setmixer(devc, 0x84, bits | 0x04);
311                         break;
312 
313                 case 0x330:
314                         sb_setmixer(devc, 0x84, bits | 0x00);
315                         break;
316 
317                 default:
318                         sb_setmixer(devc, 0x84, bits | 0x02);           /* Disable MPU */
319                         printk(KERN_ERR "SB16: Invalid MIDI I/O port %x\n", hw_config->io_base);
320         }
321 }
322 
323 static int sb16_set_irq_hw(sb_devc * devc, int level)
324 {
325         int ival;
326 
327         switch (level)
328         {
329                 case 5:
330                         ival = 2;
331                         break;
332                 case 7:
333                         ival = 4;
334                         break;
335                 case 9:
336                         ival = 1;
337                         break;
338                 case 10:
339                         ival = 8;
340                         break;
341                 default:
342                         printk(KERN_ERR "SB16: Invalid IRQ%d\n", level);
343                         return 0;
344         }
345         sb_setmixer(devc, IRQ_NR, ival);
346         return 1;
347 }
348 
349 static void relocate_Jazz16(sb_devc * devc, struct address_info *hw_config)
350 {
351         unsigned char bits = 0;
352         unsigned long flags;
353 
354         if (jazz16_base != 0 && jazz16_base != hw_config->io_base)
355                 return;
356 
357         switch (hw_config->io_base)
358         {
359                 case 0x220:
360                         bits = 1;
361                         break;
362                 case 0x240:
363                         bits = 2;
364                         break;
365                 case 0x260:
366                         bits = 3;
367                         break;
368                 default:
369                         return;
370         }
371         bits = jazz16_bits = bits << 5;
372         jazz16_base = hw_config->io_base;
373 
374         /*
375          *      Magic wake up sequence by writing to 0x201 (aka Joystick port)
376          */
377         spin_lock_irqsave(&jazz16_lock, flags);
378         outb((0xAF), 0x201);
379         outb((0x50), 0x201);
380         outb((bits), 0x201);
381         spin_unlock_irqrestore(&jazz16_lock, flags);
382 }
383 
384 static int init_Jazz16(sb_devc * devc, struct address_info *hw_config)
385 {
386         char name[100];
387         /*
388          * First try to check that the card has Jazz16 chip. It identifies itself
389          * by returning 0x12 as response to DSP command 0xfa.
390          */
391 
392         if (!sb_dsp_command(devc, 0xfa))
393                 return 0;
394 
395         if (sb_dsp_get_byte(devc) != 0x12)
396                 return 0;
397 
398         /*
399          * OK so far. Now configure the IRQ and DMA channel used by the card.
400          */
401         if (hw_config->irq < 1 || hw_config->irq > 15 || jazz_irq_bits[hw_config->irq] == 0)
402         {
403                 printk(KERN_ERR "Jazz16: Invalid interrupt (IRQ%d)\n", hw_config->irq);
404                 return 0;
405         }
406         if (hw_config->dma < 0 || hw_config->dma > 3 || jazz_dma_bits[hw_config->dma] == 0)
407         {
408                   printk(KERN_ERR "Jazz16: Invalid 8 bit DMA (DMA%d)\n", hw_config->dma);
409                   return 0;
410         }
411         if (hw_config->dma2 < 0)
412         {
413                 printk(KERN_ERR "Jazz16: No 16 bit DMA channel defined\n");
414                 return 0;
415         }
416         if (hw_config->dma2 < 5 || hw_config->dma2 > 7 || jazz_dma_bits[hw_config->dma2] == 0)
417         {
418                 printk(KERN_ERR "Jazz16: Invalid 16 bit DMA (DMA%d)\n", hw_config->dma2);
419                 return 0;
420         }
421         devc->dma16 = hw_config->dma2;
422 
423         if (!sb_dsp_command(devc, 0xfb))
424                 return 0;
425 
426         if (!sb_dsp_command(devc, jazz_dma_bits[hw_config->dma] |
427                         (jazz_dma_bits[hw_config->dma2] << 4)))
428                 return 0;
429 
430         if (!sb_dsp_command(devc, jazz_irq_bits[hw_config->irq]))
431                 return 0;
432 
433         /*
434          * Now we have configured a standard Jazz16 device. 
435          */
436         devc->model = MDL_JAZZ;
437         strcpy(name, "Jazz16");
438 
439         hw_config->name = "Jazz16";
440         devc->caps |= SB_NO_MIDI;
441         return 1;
442 }
443 
444 static void relocate_ess1688(sb_devc * devc)
445 {
446         unsigned char bits;
447 
448         switch (devc->base)
449         {
450                 case 0x220:
451                         bits = 0x04;
452                         break;
453                 case 0x230:
454                         bits = 0x05;
455                         break;
456                 case 0x240:
457                         bits = 0x06;
458                         break;
459                 case 0x250:
460                         bits = 0x07;
461                         break;
462                 default:
463                         return; /* Wrong port */
464         }
465 
466         DDB(printk("Doing ESS1688 address selection\n"));
467         
468         /*
469          * ES1688 supports two alternative ways for software address config.
470          * First try the so called Read-Sequence-Key method.
471          */
472 
473         /* Reset the sequence logic */
474         inb(0x229);
475         inb(0x229);
476         inb(0x229);
477 
478         /* Perform the read sequence */
479         inb(0x22b);
480         inb(0x229);
481         inb(0x22b);
482         inb(0x229);
483         inb(0x229);
484         inb(0x22b);
485         inb(0x229);
486 
487         /* Select the base address by reading from it. Then probe using the port. */
488         inb(devc->base);
489         if (sb_dsp_reset(devc)) /* Bingo */
490                 return;
491 
492 #if 0                           /* This causes system lockups (Nokia 386/25 at least) */
493         /*
494          * The last resort is the system control register method.
495          */
496 
497         outb((0x00), 0xfb);     /* 0xFB is the unlock register */
498         outb((0x00), 0xe0);     /* Select index 0 */
499         outb((bits), 0xe1);     /* Write the config bits */
500         outb((0x00), 0xf9);     /* 0xFB is the lock register */
501 #endif
502 }
503 
504 int sb_dsp_detect(struct address_info *hw_config, int pci, int pciio, struct sb_module_options *sbmo)
505 {
506         sb_devc sb_info;
507         sb_devc *devc = &sb_info;
508 
509         memset((char *) &sb_info, 0, sizeof(sb_info));  /* Zero everything */
510 
511         /* Copy module options in place */
512         if(sbmo) memcpy(&devc->sbmo, sbmo, sizeof(struct sb_module_options));
513 
514         sb_info.my_mididev = -1;
515         sb_info.my_mixerdev = -1;
516         sb_info.dev = -1;
517 
518         /*
519          * Initialize variables 
520          */
521         
522         DDB(printk("sb_dsp_detect(%x) entered\n", hw_config->io_base));
523         if (check_region(hw_config->io_base, 16))
524         {
525 #ifdef MODULE
526                 printk(KERN_INFO "sb: I/O region in use.\n");
527 #endif
528                 return 0;
529         }
530 
531         devc->lock = SPIN_LOCK_UNLOCKED;
532         devc->type = hw_config->card_subtype;
533 
534         devc->base = hw_config->io_base;
535         devc->irq = hw_config->irq;
536         devc->dma8 = hw_config->dma;
537 
538         devc->dma16 = -1;
539         devc->pcibase = pciio;
540         
541         if(pci == SB_PCI_ESSMAESTRO)
542         {
543                 devc->model = MDL_ESSPCI;
544                 devc->caps |= SB_PCI_IRQ;
545                 hw_config->driver_use_1 |= SB_PCI_IRQ;
546                 hw_config->card_subtype = MDL_ESSPCI;
547         }
548         
549         if(pci == SB_PCI_YAMAHA)
550         {
551                 devc->model = MDL_YMPCI;
552                 devc->caps |= SB_PCI_IRQ;
553                 hw_config->driver_use_1 |= SB_PCI_IRQ;
554                 hw_config->card_subtype = MDL_YMPCI;
555                 
556                 printk("Yamaha PCI mode.\n");
557         }
558         
559         if (devc->sbmo.acer)
560         {
561                 unsigned long flags;
562 
563                 spin_lock_irqsave(&devc->lock, flags);
564                 inb(devc->base + 0x09);
565                 inb(devc->base + 0x09);
566                 inb(devc->base + 0x09);
567                 inb(devc->base + 0x0b);
568                 inb(devc->base + 0x09);
569                 inb(devc->base + 0x0b);
570                 inb(devc->base + 0x09);
571                 inb(devc->base + 0x09);
572                 inb(devc->base + 0x0b);
573                 inb(devc->base + 0x09);
574                 inb(devc->base + 0x00);
575                 spin_unlock_irqrestore(&devc->lock, flags);
576         }
577         /*
578          * Detect the device
579          */
580 
581         if (sb_dsp_reset(devc))
582                 dsp_get_vers(devc);
583         else
584                 devc->major = 0;
585 
586         if (devc->type == 0 || devc->type == MDL_JAZZ || devc->type == MDL_SMW)
587                 if (devc->major == 0 || (devc->major == 3 && devc->minor == 1))
588                         relocate_Jazz16(devc, hw_config);
589 
590         if (devc->major == 0 && (devc->type == MDL_ESS || devc->type == 0))
591                 relocate_ess1688(devc);
592 
593         if (!sb_dsp_reset(devc))
594         {
595                 DDB(printk("SB reset failed\n"));
596 #ifdef MODULE
597                 printk(KERN_INFO "sb: dsp reset failed.\n");
598 #endif
599                 return 0;
600         }
601         if (devc->major == 0)
602                 dsp_get_vers(devc);
603 
604         if (devc->major == 3 && devc->minor == 1)
605         {
606                 if (devc->type == MDL_AZTECH)           /* SG Washington? */
607                 {
608                         if (sb_dsp_command(devc, 0x09))
609                                 if (sb_dsp_command(devc, 0x00)) /* Enter WSS mode */
610                                 {
611                                         int i;
612 
613                                         /* Have some delay */
614                                         for (i = 0; i < 10000; i++)
615                                                 inb(DSP_DATA_AVAIL);
616                                         devc->caps = SB_NO_AUDIO | SB_NO_MIDI;  /* Mixer only */
617                                         devc->model = MDL_AZTECH;
618                                 }
619                 }
620         }
621         
622         if(devc->type == MDL_ESSPCI)
623                 devc->model = MDL_ESSPCI;
624                 
625         if(devc->type == MDL_YMPCI)
626         {
627                 printk("YMPCI selected\n");
628                 devc->model = MDL_YMPCI;
629         }
630                 
631         /*
632          * Save device information for sb_dsp_init()
633          */
634 
635 
636         detected_devc = (sb_devc *)kmalloc(sizeof(sb_devc), GFP_KERNEL);
637         if (detected_devc == NULL)
638         {
639                 printk(KERN_ERR "sb: Can't allocate memory for device information\n");
640                 return 0;
641         }
642         memcpy(detected_devc, devc, sizeof(sb_devc));
643         MDB(printk(KERN_INFO "SB %d.%02d detected OK (%x)\n", devc->major, devc->minor, hw_config->io_base));
644         return 1;
645 }
646 
647 int sb_dsp_init(struct address_info *hw_config, struct module *owner)
648 {
649         sb_devc *devc;
650         char name[100];
651         extern int sb_be_quiet;
652         int     mixer22, mixer30;
653         
654 /*
655  * Check if we had detected a SB device earlier
656  */
657         DDB(printk("sb_dsp_init(%x) entered\n", hw_config->io_base));
658         name[0] = 0;
659 
660         if (detected_devc == NULL)
661         {
662                 MDB(printk("No detected device\n"));
663                 return 0;
664         }
665         devc = detected_devc;
666         detected_devc = NULL;
667 
668         if (devc->base != hw_config->io_base)
669         {
670                 DDB(printk("I/O port mismatch\n"));
671                 return 0;
672         }
673         /*
674          * Now continue initialization of the device
675          */
676 
677         devc->caps = hw_config->driver_use_1;
678 
679         if (!((devc->caps & SB_NO_AUDIO) && (devc->caps & SB_NO_MIDI)) && hw_config->irq > 0)
680         {                       /* IRQ setup */
681                 
682                 /*
683                  *      ESS PCI cards do shared PCI IRQ stuff. Since they
684                  *      will get shared PCI irq lines we must cope.
685                  */
686                  
687                 int i=(devc->caps&SB_PCI_IRQ)?SA_SHIRQ:0;
688                 
689                 if (request_irq(hw_config->irq, sbintr, i, "soundblaster", devc) < 0)
690                 {
691                         printk(KERN_ERR "SB: Can't allocate IRQ%d\n", hw_config->irq);
692                         return 0;
693                 }
694                 devc->irq_ok = 0;
695 
696                 if (devc->major == 4)
697                         if (!sb16_set_irq_hw(devc, devc->irq))  /* Unsupported IRQ */
698                         {
699                                 free_irq(devc->irq, devc);
700                                 return 0;
701                         }
702                 if ((devc->type == 0 || devc->type == MDL_ESS) &&
703                         devc->major == 3 && devc->minor == 1)
704                 {               /* Handle various chipsets which claim they are SB Pro compatible */
705                         if ((devc->type != 0 && devc->type != MDL_ESS) ||
706                                 !ess_init(devc, hw_config))
707                         {
708                                 if ((devc->type != 0 && devc->type != MDL_JAZZ &&
709                                          devc->type != MDL_SMW) || !init_Jazz16(devc, hw_config))
710                                 {
711                                         DDB(printk("This is a genuine SB Pro\n"));
712                                 }
713                         }
714                 }
715                 if (devc->major == 4 && devc->minor <= 11 )     /* Won't work */
716                         devc->irq_ok = 1;
717                 else
718                 {
719                         int n;
720 
721                         for (n = 0; n < 3 && devc->irq_ok == 0; n++)
722                         {
723                                 if (sb_dsp_command(devc, 0xf2)) /* Cause interrupt immediately */
724                                 {
725                                         int i;
726 
727                                         for (i = 0; !devc->irq_ok && i < 10000; i++);
728                                 }
729                         }
730                         if (!devc->irq_ok)
731                                 printk(KERN_WARNING "sb: Interrupt test on IRQ%d failed - Probable IRQ conflict\n", devc->irq);
732                         else
733                         {
734                                 DDB(printk("IRQ test OK (IRQ%d)\n", devc->irq));
735                         }
736                 }
737         }                       /* IRQ setup */
738         request_region(hw_config->io_base, 16, "soundblaster");
739 
740         last_sb = devc;
741         
742         switch (devc->major)
743         {
744                 case 1:         /* SB 1.0 or 1.5 */
745                         devc->model = hw_config->card_subtype = MDL_SB1;
746                         break;
747 
748                 case 2:         /* SB 2.x */
749                         if (devc->minor == 0)
750                                 devc->model = hw_config->card_subtype = MDL_SB2;
751                         else
752                                 devc->model = hw_config->card_subtype = MDL_SB201;
753                         break;
754 
755                 case 3:         /* SB Pro and most clones */
756                         switch (devc->model) {
757                         case 0:
758                                 devc->model = hw_config->card_subtype = MDL_SBPRO;
759                                 if (hw_config->name == NULL)
760                                         hw_config->name = "Sound Blaster Pro (8 BIT ONLY)";
761                                 break;
762                         case MDL_ESS:
763                                 ess_dsp_init(devc, hw_config);
764                                 break;
765                         }
766                         break;
767 
768                 case 4:
769                         devc->model = hw_config->card_subtype = MDL_SB16;
770                         /* 
771                          * ALS007 and ALS100 return DSP version 4.2 and have 2 post-reset !=0
772                          * registers at 0x3c and 0x4c (output ctrl registers on ALS007) whereas
773                          * a "standard" SB16 doesn't have a register at 0x4c.  ALS100 actively
774                          * updates register 0x22 whenever 0x30 changes, as per the SB16 spec.
775                          * Since ALS007 doesn't, this can be used to differentiate the 2 cards.
776                          */
777                         if ((devc->minor == 2) && sb_getmixer(devc,0x3c) && sb_getmixer(devc,0x4c)) 
778                         {
779                                 mixer30 = sb_getmixer(devc,0x30);
780                                 sb_setmixer(devc,0x22,(mixer22=sb_getmixer(devc,0x22)) & 0x0f);
781                                 sb_setmixer(devc,0x30,0xff);
782                                 /* ALS100 will force 0x30 to 0xf8 like SB16; ALS007 will allow 0xff. */
783                                 /* Register 0x22 & 0xf0 on ALS100 == 0xf0; on ALS007 it == 0x10.     */
784                                 if ((sb_getmixer(devc,0x30) != 0xff) || ((sb_getmixer(devc,0x22) & 0xf0) != 0x10)) 
785                                 {
786                                         devc->submodel = SUBMDL_ALS100;
787                                         if (hw_config->name == NULL)
788                                                 hw_config->name = "Sound Blaster 16 (ALS-100)";
789                                 }
790                                 else
791                                 {
792                                         sb_setmixer(devc,0x3c,0x1f);    /* Enable all inputs */
793                                         sb_setmixer(devc,0x4c,0x1f);
794                                         sb_setmixer(devc,0x22,mixer22); /* Restore 0x22 to original value */
795                                         devc->submodel = SUBMDL_ALS007;
796                                         if (hw_config->name == NULL)
797                                                 hw_config->name = "Sound Blaster 16 (ALS-007)";
798                                 }
799                                 sb_setmixer(devc,0x30,mixer30);
800                         }
801                         else if (hw_config->name == NULL)
802                                 hw_config->name = "Sound Blaster 16";
803 
804                         if (hw_config->dma2 == -1)
805                                 devc->dma16 = devc->dma8;
806                         else if (hw_config->dma2 < 5 || hw_config->dma2 > 7)
807                         {
808                                 printk(KERN_WARNING  "SB16: Bad or missing 16 bit DMA channel\n");
809                                 devc->dma16 = devc->dma8;
810                         }
811                         else
812                                 devc->dma16 = hw_config->dma2;
813 
814                         if(!sb16_set_dma_hw(devc)) {
815                                 free_irq(devc->irq, devc);
816                                 release_region(hw_config->io_base, 16);
817                                 return 0;
818                         }
819 
820                         devc->caps |= SB_NO_MIDI;
821         }
822 
823         if (!(devc->caps & SB_NO_MIXER))
824                 if (devc->major == 3 || devc->major == 4)
825                         sb_mixer_init(devc, owner);
826 
827         if (!(devc->caps & SB_NO_MIDI))
828                 sb_dsp_midi_init(devc, owner);
829 
830         if (hw_config->name == NULL)
831                 hw_config->name = "Sound Blaster (8 BIT/MONO ONLY)";
832 
833         sprintf(name, "%s (%d.%02d)", hw_config->name, devc->major, devc->minor);
834         conf_printf(name, hw_config);
835 
836         /*
837          * Assuming that a sound card is Sound Blaster (compatible) is the most common
838          * configuration error and the mother of all problems. Usually sound cards
839          * emulate SB Pro but in addition they have a 16 bit native mode which should be
840          * used in Unix. See Readme.cards for more information about configuring OSS/Free
841          * properly.
842          */
843         if (devc->model <= MDL_SBPRO)
844         {
845                 if (devc->major == 3 && devc->minor != 1)       /* "True" SB Pro should have v3.1 (rare ones may have 3.2). */
846                 {
847                         printk(KERN_INFO "This sound card may not be fully Sound Blaster Pro compatible.\n");
848                         printk(KERN_INFO "In many cases there is another way to configure OSS so that\n");
849                         printk(KERN_INFO "it works properly with OSS (for example in 16 bit mode).\n");
850                         printk(KERN_INFO "Please ignore this message if you _really_ have a SB Pro.\n");
851                 }
852                 else if (!sb_be_quiet && devc->model == MDL_SBPRO)
853                 {
854                         printk(KERN_INFO "SB DSP version is just %d.%02d which means that your card is\n", devc->major, devc->minor);
855                         printk(KERN_INFO "several years old (8 bit only device) or alternatively the sound driver\n");
856                         printk(KERN_INFO "is incorrectly configured.\n");
857                 }
858         }
859         hw_config->card_subtype = devc->model;
860         hw_config->slots[0]=devc->dev;
861         last_devc = devc;       /* For SB MPU detection */
862 
863         if (!(devc->caps & SB_NO_AUDIO) && devc->dma8 >= 0)
864         {
865                 if (sound_alloc_dma(devc->dma8, "SoundBlaster8"))
866                 {
867                         printk(KERN_WARNING "Sound Blaster: Can't allocate 8 bit DMA channel %d\n", devc->dma8);
868                 }
869                 if (devc->dma16 >= 0 && devc->dma16 != devc->dma8)
870                 {
871                         if (sound_alloc_dma(devc->dma16, "SoundBlaster16"))
872                                 printk(KERN_WARNING "Sound Blaster:  can't allocate 16 bit DMA channel %d.\n", devc->dma16);
873                 }
874                 sb_audio_init(devc, name, owner);
875                 hw_config->slots[0]=devc->dev;
876         }
877         else
878         {
879                 MDB(printk("Sound Blaster:  no audio devices found.\n"));
880         }
881         return 1;
882 }
883 
884 void sb_dsp_disable_midi(int io_base)
885 {
886 }
887 
888 void sb_dsp_disable_recording(int io_base)
889 {
890 }
891 
892 /* if (sbmpu) below we allow mpu401 to manage the midi devs
893    otherwise we have to unload them. (Andrzej Krzysztofowicz) */
894    
895 void sb_dsp_unload(struct address_info *hw_config, int sbmpu)
896 {
897         sb_devc *devc;
898 
899         devc = audio_devs[hw_config->slots[0]]->devc;
900 
901         if (devc && devc->base == hw_config->io_base)
902         {
903                 if ((devc->model & MDL_ESS) && devc->pcibase)
904                         release_region(devc->pcibase, 8);
905 
906                 release_region(devc->base, 16);
907 
908                 if (!(devc->caps & SB_NO_AUDIO))
909                 {
910                         sound_free_dma(devc->dma8);
911                         if (devc->dma16 >= 0)
912                                 sound_free_dma(devc->dma16);
913                 }
914                 if (!(devc->caps & SB_NO_AUDIO && devc->caps & SB_NO_MIDI))
915                 {
916                         if (devc->irq > 0)
917                                 free_irq(devc->irq, devc);
918 
919                         sb_mixer_unload(devc);
920                         /* We don't have to do this bit any more the UART401 is its own
921                                 master  -- Krzysztof Halasa */
922                         /* But we have to do it, if UART401 is not detected */
923                         if (!sbmpu)
924                                 sound_unload_mididev(devc->my_mididev);
925                         sound_unload_audiodev(devc->dev);
926                 }
927                 kfree(devc);
928         }
929         else
930                 release_region(hw_config->io_base, 16);
931         if(detected_devc)
932                 kfree(detected_devc);
933 }
934 
935 /*
936  *      Mixer access routines
937  *
938  *      ES1887 modifications: some mixer registers reside in the
939  *      range above 0xa0. These must be accessed in another way.
940  */
941 
942 void sb_setmixer(sb_devc * devc, unsigned int port, unsigned int value)
943 {
944         unsigned long flags;
945 
946         if (devc->model == MDL_ESS) return ess_setmixer (devc, port, value);
947 
948         spin_lock_irqsave(&devc->lock, flags);
949 
950         outb(((unsigned char) (port & 0xff)), MIXER_ADDR);
951         udelay(20);
952         outb(((unsigned char) (value & 0xff)), MIXER_DATA);
953         udelay(20);
954 
955         spin_unlock_irqrestore(&devc->lock, flags);
956 }
957 
958 unsigned int sb_getmixer(sb_devc * devc, unsigned int port)
959 {
960         unsigned int val;
961         unsigned long flags;
962 
963         if (devc->model == MDL_ESS) return ess_getmixer (devc, port);
964 
965         spin_lock_irqsave(&devc->lock, flags);
966 
967         outb(((unsigned char) (port & 0xff)), MIXER_ADDR);
968         udelay(20);
969         val = inb(MIXER_DATA);
970         udelay(20);
971 
972         spin_unlock_irqrestore(&devc->lock, flags);
973 
974         return val;
975 }
976 
977 void sb_chgmixer
978         (sb_devc * devc, unsigned int reg, unsigned int mask, unsigned int val)
979 {
980         int value;
981 
982         value = sb_getmixer(devc, reg);
983         value = (value & ~mask) | (val & mask);
984         sb_setmixer(devc, reg, value);
985 }
986 
987 /*
988  *      MPU401 MIDI initialization.
989  */
990 
991 static void smw_putmem(sb_devc * devc, int base, int addr, unsigned char val)
992 {
993         unsigned long flags;
994 
995         spin_lock_irqsave(&jazz16_lock, flags);  /* NOT the SB card? */
996 
997         outb((addr & 0xff), base + 1);  /* Low address bits */
998         outb((addr >> 8), base + 2);    /* High address bits */
999         outb((val), base);      /* Data */
1000 
1001         spin_unlock_irqrestore(&jazz16_lock, flags);
1002 }
1003 
1004 static unsigned char smw_getmem(sb_devc * devc, int base, int addr)
1005 {
1006         unsigned long flags;
1007         unsigned char val;
1008 
1009         spin_lock_irqsave(&jazz16_lock, flags);  /* NOT the SB card? */
1010 
1011         outb((addr & 0xff), base + 1);  /* Low address bits */
1012         outb((addr >> 8), base + 2);    /* High address bits */
1013         val = inb(base);        /* Data */
1014 
1015         spin_unlock_irqrestore(&jazz16_lock, flags);
1016         return val;
1017 }
1018 
1019 static int smw_midi_init(sb_devc * devc, struct address_info *hw_config)
1020 {
1021         int mpu_base = hw_config->io_base;
1022         int mp_base = mpu_base + 4;             /* Microcontroller base */
1023         int i;
1024         unsigned char control;
1025 
1026 
1027         /*
1028          *  Reset the microcontroller so that the RAM can be accessed
1029          */
1030 
1031         control = inb(mpu_base + 7);
1032         outb((control | 3), mpu_base + 7);      /* Set last two bits to 1 (?) */
1033         outb(((control & 0xfe) | 2), mpu_base + 7);     /* xxxxxxx0 resets the mc */
1034 
1035         mdelay(3);      /* Wait at least 1ms */
1036 
1037         outb((control & 0xfc), mpu_base + 7);   /* xxxxxx00 enables RAM */
1038 
1039         /*
1040          *  Detect microcontroller by probing the 8k RAM area
1041          */
1042         smw_putmem(devc, mp_base, 0, 0x00);
1043         smw_putmem(devc, mp_base, 1, 0xff);
1044         udelay(10);
1045 
1046         if (smw_getmem(devc, mp_base, 0) != 0x00 || smw_getmem(devc, mp_base, 1) != 0xff)
1047         {
1048                 DDB(printk("SM Wave: No microcontroller RAM detected (%02x, %02x)\n", smw_getmem(devc, mp_base, 0), smw_getmem(devc, mp_base, 1)));
1049                 return 0;       /* No RAM */
1050         }
1051         /*
1052          *  There is RAM so assume it's really a SM Wave
1053          */
1054 
1055         devc->model = MDL_SMW;
1056         smw_mixer_init(devc);
1057 
1058 #ifdef MODULE
1059         if (!smw_ucode)
1060         {
1061                 smw_ucodeLen = mod_firmware_load("/etc/sound/midi0001.bin", (void *) &smw_ucode);
1062                 smw_free = smw_ucode;
1063         }
1064 #endif
1065         if (smw_ucodeLen > 0)
1066         {
1067                 if (smw_ucodeLen != 8192)
1068                 {
1069                         printk(KERN_ERR "SM Wave: Invalid microcode (MIDI0001.BIN) length\n");
1070                         return 1;
1071                 }
1072                 /*
1073                  *  Download microcode
1074                  */
1075 
1076                 for (i = 0; i < 8192; i++)
1077                         smw_putmem(devc, mp_base, i, smw_ucode[i]);
1078 
1079                 /*
1080                  *  Verify microcode
1081                  */
1082 
1083                 for (i = 0; i < 8192; i++)
1084                         if (smw_getmem(devc, mp_base, i) != smw_ucode[i])
1085                         {
1086                                 printk(KERN_ERR "SM Wave: Microcode verification failed\n");
1087                                 return 0;
1088                         }
1089         }
1090         control = 0;
1091 #ifdef SMW_SCSI_IRQ
1092         /*
1093          * Set the SCSI interrupt (IRQ2/9, IRQ3 or IRQ10). The SCSI interrupt
1094          * is disabled by default.
1095          *
1096          * FIXME - make this a module option
1097          *
1098          * BTW the Zilog 5380 SCSI controller is located at MPU base + 0x10.
1099          */
1100         {
1101                 static unsigned char scsi_irq_bits[] = {
1102                         0, 0, 3, 1, 0, 0, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0
1103                 };
1104                 control |= scsi_irq_bits[SMW_SCSI_IRQ] << 6;
1105         }
1106 #endif
1107 
1108 #ifdef SMW_OPL4_ENABLE
1109         /*
1110          *  Make the OPL4 chip visible on the PC bus at 0x380.
1111          *
1112          *  There is no need to enable this feature since this driver
1113          *  doesn't support OPL4 yet. Also there is no RAM in SM Wave so
1114          *  enabling OPL4 is pretty useless.
1115          */
1116         control |= 0x10;        /* Uses IRQ12 if bit 0x20 == 0 */
1117         /* control |= 0x20;      Uncomment this if you want to use IRQ7 */
1118 #endif
1119         outb((control | 0x03), mpu_base + 7);   /* xxxxxx11 restarts */
1120         hw_config->name = "SoundMan Wave";
1121         return 1;
1122 }
1123 
1124 static int init_Jazz16_midi(sb_devc * devc, struct address_info *hw_config)
1125 {
1126         int mpu_base = hw_config->io_base;
1127         int sb_base = devc->base;
1128         int irq = hw_config->irq;
1129 
1130         unsigned char bits = 0;
1131         unsigned long flags;
1132 
1133         if (irq < 0)
1134                 irq *= -1;
1135 
1136         if (irq < 1 || irq > 15 ||
1137             jazz_irq_bits[irq] == 0)
1138         {
1139                 printk(KERN_ERR "Jazz16: Invalid MIDI interrupt (IRQ%d)\n", irq);
1140                 return 0;
1141         }
1142         switch (sb_base)
1143         {
1144                 case 0x220:
1145                         bits = 1;
1146                         break;
1147                 case 0x240:
1148                         bits = 2;
1149                         break;
1150                 case 0x260:
1151                         bits = 3;
1152                         break;
1153                 default:
1154                         return 0;
1155         }
1156         bits = jazz16_bits = bits << 5;
1157         switch (mpu_base)
1158         {
1159                 case 0x310:
1160                         bits |= 1;
1161                         break;
1162                 case 0x320:
1163                         bits |= 2;
1164                         break;
1165                 case 0x330:
1166                         bits |= 3;
1167                         break;
1168                 default:
1169                         printk(KERN_ERR "Jazz16: Invalid MIDI I/O port %x\n", mpu_base);
1170                         return 0;
1171         }
1172         /*
1173          *      Magic wake up sequence by writing to 0x201 (aka Joystick port)
1174          */
1175         spin_lock_irqsave(&jazz16_lock, flags);
1176         outb(0xAF, 0x201);
1177         outb(0x50, 0x201);
1178         outb(bits, 0x201);
1179         spin_unlock_irqrestore(&jazz16_lock, flags);
1180 
1181         hw_config->name = "Jazz16";
1182         smw_midi_init(devc, hw_config);
1183 
1184         if (!sb_dsp_command(devc, 0xfb))
1185                 return 0;
1186 
1187         if (!sb_dsp_command(devc, jazz_dma_bits[devc->dma8] |
1188                             (jazz_dma_bits[devc->dma16] << 4)))
1189                 return 0;
1190 
1191         if (!sb_dsp_command(devc, jazz_irq_bits[devc->irq] |
1192                             (jazz_irq_bits[irq] << 4)))
1193                 return 0;
1194 
1195         return 1;
1196 }
1197 
1198 int probe_sbmpu(struct address_info *hw_config, struct module *owner)
1199 {
1200         sb_devc *devc = last_devc;
1201         int ret;
1202 
1203         if (last_devc == NULL)
1204                 return 0;
1205 
1206         last_devc = 0;
1207 
1208         if (hw_config->io_base <= 0)
1209         {
1210                 /* The real vibra16 is fine about this, but we have to go
1211                    wipe up after Cyrix again */
1212                            
1213                 if(devc->model == MDL_SB16 && devc->minor >= 12)
1214                 {
1215                         unsigned char   bits = sb_getmixer(devc, 0x84) & ~0x06;
1216                         sb_setmixer(devc, 0x84, bits | 0x02);           /* Disable MPU */
1217                 }
1218                 return 0;
1219         }
1220 
1221 #if defined(CONFIG_SOUND_MPU401)
1222         if (devc->model == MDL_ESS)
1223         {
1224                 if (check_region(hw_config->io_base, 2))
1225                 {
1226                         printk(KERN_ERR "sbmpu: I/O port conflict (%x)\n", hw_config->io_base);
1227                         return 0;
1228                 }
1229                 if (!ess_midi_init(devc, hw_config))
1230                         return 0;
1231                 hw_config->name = "ESS1xxx MPU";
1232                 devc->midi_irq_cookie = NULL;
1233                 if (!probe_mpu401(hw_config))
1234                         return 0;
1235                 attach_mpu401(hw_config, owner);
1236                 if (last_sb->irq == -hw_config->irq)
1237                         last_sb->midi_irq_cookie=(void *)hw_config->slots[1];
1238                 return 1;
1239         }
1240 #endif
1241 
1242         switch (devc->model)
1243         {
1244                 case MDL_SB16:
1245                         if (hw_config->io_base != 0x300 && hw_config->io_base != 0x330)
1246                         {
1247                                 printk(KERN_ERR "SB16: Invalid MIDI port %x\n", hw_config->io_base);
1248                                 return 0;
1249                         }
1250                         hw_config->name = "Sound Blaster 16";
1251                         if (hw_config->irq < 3 || hw_config->irq == devc->irq)
1252                                 hw_config->irq = -devc->irq;
1253                         if (devc->minor > 12)           /* What is Vibra's version??? */
1254                                 sb16_set_mpu_port(devc, hw_config);
1255                         break;
1256 
1257                 case MDL_JAZZ:
1258                         if (hw_config->irq < 3 || hw_config->irq == devc->irq)
1259                                 hw_config->irq = -devc->irq;
1260                         if (!init_Jazz16_midi(devc, hw_config))
1261                                 return 0;
1262                         break;
1263 
1264                 case MDL_YMPCI:
1265                         hw_config->name = "Yamaha PCI Legacy";
1266                         printk("Yamaha PCI legacy UART401 check.\n");
1267                         break;
1268                 default:
1269                         return 0;
1270         }
1271         
1272         ret = probe_uart401(hw_config, owner);
1273         if (ret)
1274                 last_sb->midi_irq_cookie=midi_devs[hw_config->slots[4]]->devc;
1275         return ret;
1276 }
1277 
1278 void unload_sbmpu(struct address_info *hw_config)
1279 {
1280 #if defined(CONFIG_SOUND_MPU401)
1281         if (!strcmp (hw_config->name, "ESS1xxx MPU")) {
1282                 unload_mpu401(hw_config);
1283                 return;
1284         }
1285 #endif
1286         unload_uart401(hw_config);
1287 }
1288 
1289 EXPORT_SYMBOL(sb_dsp_init);
1290 EXPORT_SYMBOL(sb_dsp_detect);
1291 EXPORT_SYMBOL(sb_dsp_unload);
1292 EXPORT_SYMBOL(sb_dsp_disable_midi);
1293 EXPORT_SYMBOL(sb_be_quiet);
1294 EXPORT_SYMBOL(probe_sbmpu);
1295 EXPORT_SYMBOL(unload_sbmpu);
1296 EXPORT_SYMBOL(smw_free);
1297 MODULE_LICENSE("GPL");
1298 

~ [ 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