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

Linux Cross Reference
Linux/drivers/sound/sb_common.c

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

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

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.