Merge with 2.4.0-test3-pre4.
[linux-2.6/linux-mips.git] / drivers / sound / aedsp16.c
blob6ea812a385ca05076516a20c44146616091a5a06
1 /*
2 drivers/sound/lowlevel/aedsp16.c
4 Audio Excel DSP 16 software configuration routines
5 Copyright (C) 1995,1996,1997,1998 Riccardo Facchetti (fizban@tin.it)
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * Include the main OSS Lite header file. It include all the os, OSS Lite, etc
24 * headers needed by this source.
26 #include <linux/config.h>
27 #include <linux/delay.h>
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include "sound_config.h"
31 #include "soundmodule.h"
34 * Sanity checks
37 #if defined(CONFIG_SOUND_AEDSP16_SBPRO) && defined(CONFIG_SOUND_AEDSP16_MSS)
38 #error You have to enable only one of the MSS and SBPRO emulations.
39 #endif
43 READ THIS
45 This module started to configure the Audio Excel DSP 16 Sound Card.
46 Now works with the SC-6000 (old aedsp16) and new SC-6600 based cards.
48 NOTE: I have NO idea about Audio Excel DSP 16 III. If someone owns this
49 audio card and want to see the kernel support for it, please contact me.
51 Audio Excel DSP 16 is an SB pro II, Microsoft Sound System and MPU-401
52 compatible card.
53 It is software-only configurable (no jumpers to hard-set irq/dma/mpu-irq),
54 so before this module, the only way to configure the DSP under linux was
55 boot the MS-DOS loading the sound.sys device driver (this driver soft-
56 configure the sound board hardware by massaging someone of its registers),
57 and then ctrl-alt-del to boot linux with the DSP configured by the DOS
58 driver.
60 This module works configuring your Audio Excel DSP 16's irq, dma and
61 mpu-401-irq. The OSS Lite routines rely on the fact that if the
62 hardware is there, they can detect it. The problem with AEDSP16 is
63 that no hardware can be found by the probe routines if the sound card
64 is not configured properly. Sometimes the kernel probe routines can find
65 an SBPRO even when the card is not configured (this is the standard setup
66 of the card), but the SBPRO emulation don't work well if the card is not
67 properly initialized. For this reason
69 aedsp16_init_board()
71 routine is called before the OSS Lite probe routines try to detect the
72 hardware.
74 NOTE (READ THE NOTE TOO, IT CONTAIN USEFUL INFORMATIONS)
76 NOTE: Now it works with SC-6000 and SC-6600 based audio cards. The new cards
77 have no jumper switch at all. No more WSS or MPU-401 I/O port switches. They
78 have to be configured by software.
80 NOTE: The driver is merged with the new OSS Lite sound driver. It works
81 as a lowlevel driver.
83 The Audio Excel DSP 16 Sound Card emulates both SBPRO and MSS;
84 the OSS Lite sound driver can be configured for SBPRO and MSS cards
85 at the same time, but the aedsp16 can't be two cards!!
86 When we configure it, we have to choose the SBPRO or the MSS emulation
87 for AEDSP16. We also can install a *REAL* card of the other type (see [1]).
89 NOTE: If someone can test the combination AEDSP16+MSS or AEDSP16+SBPRO
90 please let me know if it works.
92 The MPU-401 support can be compiled in together with one of the other
93 two operating modes.
95 NOTE: This is something like plug-and-play: we have only to plug
96 the AEDSP16 board in the socket, and then configure and compile
97 a kernel that uses the AEDSP16 software configuration capability.
98 No jumper setting is needed!
100 For example, if you want AEDSP16 to be an SBPro, on irq 10, dma 3
101 you have just to make config the OSS Lite package, configuring
102 the AEDSP16 sound card, then activating the SBPro emulation mode
103 and at last configuring IRQ and DMA.
104 Compile the kernel and run it.
106 NOTE: This means for SC-6000 cards that you can choose irq and dma,
107 but not the I/O addresses. To change I/O addresses you have to set
108 them with jumpers. For SC-6600 cards you have no jumpers so you have
109 to set up your full card configuration in the make config.
111 You can change the irq/dma/mirq settings WITHOUT THE NEED to open
112 your computer and massage the jumpers (there are no irq/dma/mirq
113 jumpers to be configured anyway, only I/O BASE values have to be
114 configured with jumpers)
116 For some ununderstandable reason, the card default of irq 7, dma 1,
117 don't work for me. Seems to be an IRQ or DMA conflict. Under heavy
118 HDD work, the kernel start to erupt out a lot of messages like:
120 'Sound: DMA timed out - IRQ/DRQ config error?'
122 For what I can say, I have NOT any conflict at irq 7 (under linux I'm
123 using the lp polling driver), and dma line 1 is unused as stated by
124 /proc/dma. I can suppose this is a bug of AEDSP16. I know my hardware so
125 I'm pretty sure I have not any conflict, but may be I'm wrong. Who knows!
126 Anyway a setting of irq 10, dma 3 works really fine.
128 NOTE: if someone can use AEDSP16 with irq 7, dma 1, please let me know
129 the emulation mode, all the installed hardware and the hardware
130 configuration (irq and dma settings of all the hardware).
132 This init module should work with SBPRO+MSS, when one of the two is
133 the AEDSP16 emulation and the other the real card. (see [1])
134 For example:
136 AEDSP16 (0x220) in SBPRO emu (0x220) + real MSS + other
137 AEDSP16 (0x220) in MSS emu + real SBPRO (0x240) + other
139 MPU401 should work. (see [2])
143 Date: Mon, 29 Jul 1997 08:35:40 +0100
144 From: Mr S J Greenaway <sjg95@unixfe.rl.ac.uk>
146 [...]
147 Just to let you know got my Audio Excel (emulating a MSS) working
148 with my original SB16, thanks for the driver!
149 [...]
152 [2] Not tested by me for lack of hardware.
154 TODO, WISHES AND TECH
156 - About I/O ports allocation -
158 Request the 2x0h region (port base) in any case if we are using this card.
160 NOTE: the "aedsp16 (base)" string with which we are requesting the aedsp16
161 port base region (see code) does not mean necessarily that we are emulating
162 sbpro. Even if this region is the sbpro I/O ports region, we use this
163 region to access the control registers of the card, and if emulating
164 sbpro, I/O sbpro registers too. If we are emulating MSS, the sbpro
165 registers are not used, in no way, to emulate an sbpro: they are
166 used only for configuration purposes.
168 Started Fri Mar 17 16:13:18 MET 1995
170 v0.1 (ALPHA, was an user-level program called AudioExcelDSP16.c)
171 - Initial code.
172 v0.2 (ALPHA)
173 - Cleanups.
174 - Integrated with Linux voxware v 2.90-2 kernel sound driver.
175 - SoundBlaster Pro mode configuration.
176 - Microsoft Sound System mode configuration.
177 - MPU-401 mode configuration.
178 v0.3 (ALPHA)
179 - Cleanups.
180 - Rearranged the code to let aedsp16_init_board be more general.
181 - Erased the REALLY_SLOW_IO. We don't need it. Erased the linux/io.h
182 inclusion too. We rely on os.h
183 - Used the to get a variable
184 len string (we are not sure about the len of Copyright string).
185 This works with any SB and compatible.
186 - Added the code to request_region at device init (should go in
187 the main body of voxware).
188 v0.4 (BETA)
189 - Better configure.c patch for aedsp16 configuration (better
190 logic of inclusion of AEDSP16 support)
191 - Modified the conditional compilation to better support more than
192 one sound card of the emulated type (read the NOTES above)
193 - Moved the sb init routine from the attach to the very first
194 probe in sb_card.c
195 - Rearrangements and cleanups
196 - Wiped out some unnecessary code and variables: this is kernel
197 code so it is better save some TEXT and DATA
198 - Fixed the request_region code. We must allocate the aedsp16 (sbpro)
199 I/O ports in any case because they are used to access the DSP
200 configuration registers and we can not allow anyone to get them.
201 v0.5
202 - cleanups on comments
203 - prep for diffs against v3.0-proto-950402
204 v0.6
205 - removed the request_region()s when compiling the MODULE sound.o
206 because we are not allowed (by the actual voxware structure) to
207 release_region()
208 v0.7 (pre ALPHA, not distributed)
209 - started porting this module to kernel 1.3.84. Dummy probe/attach
210 routines.
211 v0.8 (ALPHA)
212 - attached all the init routines.
213 v0.9 (BETA)
214 - Integrated with linux-pre2.0.7
215 - Integrated with configuration scripts.
216 - Cleaned up and beautyfied the code.
217 v0.9.9 (BETA)
218 - Thanks to Piercarlo Grandi: corrected the conditonal compilation code.
219 Now only the code configured is compiled in, with some memory saving.
220 v0.9.10
221 - Integration into the sound/lowlevel/ section of the sound driver.
222 - Re-organized the code.
223 v0.9.11 (not distributed)
224 - Rewritten the init interface-routines to initialize the AEDSP16 in
225 one shot.
226 - More cosmetics.
227 - SC-6600 support.
228 - More soft/hard configuration.
229 v0.9.12
230 - Refined the v0.9.11 code with conditional compilation to distinguish
231 between SC-6000 and SC-6600 code.
232 v1.0.0
233 - Prep for merging with OSS Lite and Linux kernel 2.1.13
234 - Corrected a bug in request/check/release region calls (thanks to the
235 new kernel exception handling).
236 v1.1
237 - Revamped for integration with new modularized sound drivers: to enhance
238 the flexibility of modular version, I have removed all the conditional
239 compilation for SBPRO, MPU and MSS code. Now it is all managed with
240 the ae_config structure.
241 v1.2
242 - Module informations added.
243 - Removed aedsp16_delay_10msec(), now using mdelay(10)
244 - All data and funcs moved to .*.init section.
246 Known Problems:
247 - Audio Excel DSP 16 III don't work with this driver.
249 Credits:
250 Many thanks to Gerald Britton <gbritton@CapAccess.org>. He helped me a
251 lot in testing the 0.9.11 and 0.9.12 versions of this driver.
256 #define VERSION "1.2" /* Version of Audio Excel DSP 16 driver */
258 #undef AEDSP16_DEBUG 1 /* Define this to enable debug code */
259 #undef AEDSP16_DEBUG_MORE 1 /* Define this to enable more debug */
260 #undef AEDSP16_INFO 1 /* Define this to enable info code */
262 #if defined(AEDSP16_DEBUG)
263 # define DBG(x) printk x
264 # if defined(AEDSP16_DEBUG_MORE)
265 # define DBG1(x) printk x
266 # else
267 # define DBG1(x)
268 # endif
269 #else
270 # define DBG(x)
271 # define DBG1(x)
272 #endif
275 * Misc definitions
277 #define TRUE 1
278 #define FALSE 0
281 * Region Size for request/check/release region.
283 #define IOBASE_REGION_SIZE 0x10
286 * Hardware related defaults
288 #define DEF_AEDSP16_IOB 0x220 /* 0x220(default) 0x240 */
289 #define DEF_AEDSP16_IRQ 7 /* 5 7(default) 9 10 11 */
290 #define DEF_AEDSP16_MRQ 0 /* 5 7 9 10 0(default), 0 means disable */
291 #define DEF_AEDSP16_DMA 1 /* 0 1(default) 3 */
294 * Commands of AEDSP16's DSP (SBPRO+special).
295 * Some of them are COMMAND_xx, in the future they may change.
297 #define WRITE_MDIRQ_CFG 0x50 /* Set M&I&DRQ mask (the real config) */
298 #define COMMAND_52 0x52 /* */
299 #define READ_HARD_CFG 0x58 /* Read Hardware Config (I/O base etc) */
300 #define COMMAND_5C 0x5c /* */
301 #define COMMAND_60 0x60 /* */
302 #define COMMAND_66 0x66 /* */
303 #define COMMAND_6C 0x6c /* */
304 #define COMMAND_6E 0x6e /* */
305 #define COMMAND_88 0x88 /* */
306 #define DSP_INIT_MSS 0x8c /* Enable Microsoft Sound System mode */
307 #define COMMAND_C5 0xc5 /* */
308 #define GET_DSP_VERSION 0xe1 /* Get DSP Version */
309 #define GET_DSP_COPYRIGHT 0xe3 /* Get DSP Copyright */
312 * Offsets of AEDSP16 DSP I/O ports. The offset is added to base I/O port
313 * to have the actual I/O port.
314 * Register permissions are:
315 * (wo) == Write Only
316 * (ro) == Read Only
317 * (w-) == Write
318 * (r-) == Read
320 #define DSP_RESET 0x06 /* offset of DSP RESET (wo) */
321 #define DSP_READ 0x0a /* offset of DSP READ (ro) */
322 #define DSP_WRITE 0x0c /* offset of DSP WRITE (w-) */
323 #define DSP_COMMAND 0x0c /* offset of DSP COMMAND (w-) */
324 #define DSP_STATUS 0x0c /* offset of DSP STATUS (r-) */
325 #define DSP_DATAVAIL 0x0e /* offset of DSP DATA AVAILABLE (ro) */
328 #define RETRY 10 /* Various retry values on I/O opera- */
329 #define STATUSRETRY 1000 /* tions. Sometimes we have to */
330 #define HARDRETRY 500000 /* wait for previous cmd to complete */
333 * Size of character arrays that store name and version of sound card
335 #define CARDNAMELEN 15 /* Size of the card's name in chars */
336 #define CARDVERLEN 2 /* Size of the card's version in chars */
338 #if defined(CONFIG_SC6600)
340 * Bitmapped flags of hard configuration
343 * Decode macros (xl == low byte, xh = high byte)
345 #define IOBASE(xl) ((xl & 0x01)?0x240:0x220)
346 #define JOY(xl) (xl & 0x02)
347 #define MPUADDR(xl) ( \
348 (xl & 0x0C)?0x330: \
349 (xl & 0x08)?0x320: \
350 (xl & 0x04)?0x310: \
351 0x300)
352 #define WSSADDR(xl) ((xl & 0x10)?0xE80:0x530)
353 #define CDROM(xh) (xh & 0x20)
354 #define CDROMADDR(xh) (((xh & 0x1F) << 4) + 0x200)
356 * Encode macros
358 #define BLDIOBASE(xl, val) { \
359 xl &= ~0x01; \
360 if (val == 0x240) \
361 xl |= 0x01; \
363 #define BLDJOY(xl, val) { \
364 xl &= ~0x02; \
365 if (val == 1) \
366 xl |= 0x02; \
368 #define BLDMPUADDR(xl, val) { \
369 xl &= ~0x0C; \
370 switch (val) { \
371 case 0x330: \
372 xl |= 0x0C; \
373 break; \
374 case 0x320: \
375 xl |= 0x08; \
376 break; \
377 case 0x310: \
378 xl |= 0x04; \
379 break; \
380 case 0x300: \
381 xl |= 0x00; \
382 break; \
383 default: \
384 xl |= 0x00; \
385 break; \
388 #define BLDWSSADDR(xl, val) { \
389 xl &= ~0x10; \
390 if (val == 0xE80) \
391 xl |= 0x10; \
393 #define BLDCDROM(xh, val) { \
394 xh &= ~0x20; \
395 if (val == 1) \
396 xh |= 0x20; \
398 #define BLDCDROMADDR(xh, val) { \
399 int tmp = val; \
400 tmp -= 0x200; \
401 tmp >>= 4; \
402 tmp &= 0x1F; \
403 xh |= tmp; \
404 xh &= 0x7F; \
405 xh |= 0x40; \
407 #endif /* CONFIG_SC6600 */
410 * Bit mapped flags for calling aedsp16_init_board(), and saving the current
411 * emulation mode.
413 #define INIT_NONE (0 )
414 #define INIT_SBPRO (1<<0)
415 #define INIT_MSS (1<<1)
416 #define INIT_MPU401 (1<<2)
418 static int soft_cfg __initdata = 0; /* bitmapped config */
419 static int soft_cfg_mss __initdata = 0; /* bitmapped mss config */
420 static int ver[CARDVERLEN] __initdata = {0, 0}; /* DSP Ver:
421 hi->ver[0] lo->ver[1] */
423 #if defined(CONFIG_SC6600)
424 static int hard_cfg[2] /* lo<-hard_cfg[0] hi<-hard_cfg[1] */
425 __initdata = { 0, 0};
426 #endif /* CONFIG_SC6600 */
428 #if defined(CONFIG_SC6600)
429 /* Decoded hard configuration */
430 struct d_hcfg {
431 int iobase;
432 int joystick;
433 int mpubase;
434 int wssbase;
435 int cdrom;
436 int cdrombase;
439 struct d_hcfg decoded_hcfg __initdata = {0, };
441 #endif /* CONFIG_SC6600 */
443 /* orVals contain the values to be or'ed */
444 struct orVals {
445 int val; /* irq|mirq|dma */
446 int or; /* soft_cfg |= TheStruct.or */
449 /* aedsp16_info contain the audio card configuration */
450 struct aedsp16_info {
451 int base_io; /* base I/O address for accessing card */
452 int irq; /* irq value for DSP I/O */
453 int mpu_irq; /* irq for mpu401 interface I/O */
454 int dma; /* dma value for DSP I/O */
455 int mss_base; /* base I/O for Microsoft Sound System */
456 int mpu_base; /* base I/O for MPU-401 emulation */
457 int init; /* Initialization status of the card */
461 * Magic values that the DSP will eat when configuring irq/mirq/dma
463 /* DSP IRQ conversion array */
464 static struct orVals orIRQ[] __initdata = {
465 {0x05, 0x28},
466 {0x07, 0x08},
467 {0x09, 0x10},
468 {0x0a, 0x18},
469 {0x0b, 0x20},
470 {0x00, 0x00}
473 /* MPU-401 IRQ conversion array */
474 static struct orVals orMIRQ[] __initdata = {
475 {0x05, 0x04},
476 {0x07, 0x44},
477 {0x09, 0x84},
478 {0x0a, 0xc4},
479 {0x00, 0x00}
482 /* DMA Channels conversion array */
483 static struct orVals orDMA[] __initdata = {
484 {0x00, 0x01},
485 {0x01, 0x02},
486 {0x03, 0x03},
487 {0x00, 0x00}
490 static struct aedsp16_info ae_config __initdata = {
491 DEF_AEDSP16_IOB,
492 DEF_AEDSP16_IRQ,
493 DEF_AEDSP16_MRQ,
494 DEF_AEDSP16_DMA,
497 INIT_NONE
501 * Buffers to store audio card informations
503 static char DSPCopyright[CARDNAMELEN + 1] __initdata = {0, };
504 static char DSPVersion[CARDVERLEN + 1] __initdata = {0, };
506 static int __init aedsp16_wait_data(int port)
508 int loop = STATUSRETRY;
509 unsigned char ret = 0;
511 DBG1(("aedsp16_wait_data (0x%x): ", port));
513 do {
514 ret = inb(port + DSP_DATAVAIL);
516 * Wait for data available (bit 7 of ret == 1)
518 } while (!(ret & 0x80) && loop--);
520 if (ret & 0x80) {
521 DBG1(("success.\n"));
522 return TRUE;
525 DBG1(("failure.\n"));
526 return FALSE;
529 static int __init aedsp16_read(int port)
531 int inbyte;
533 DBG((" Read DSP Byte (0x%x): ", port));
535 if (aedsp16_wait_data(port) == FALSE) {
536 DBG(("failure.\n"));
537 return -1;
540 inbyte = inb(port + DSP_READ);
542 DBG(("read [0x%x]/{%c}.\n", inbyte, inbyte));
544 return inbyte;
547 static int __init aedsp16_test_dsp(int port)
549 return ((aedsp16_read(port) == 0xaa) ? TRUE : FALSE);
552 static int __init aedsp16_dsp_reset(int port)
555 * Reset DSP
558 DBG(("Reset DSP:\n"));
560 outb(1, (port + DSP_RESET));
561 udelay(10);
562 outb(0, (port + DSP_RESET));
563 udelay(10);
564 udelay(10);
565 if (aedsp16_test_dsp(port) == TRUE) {
566 DBG(("success.\n"));
567 return TRUE;
568 } else
569 DBG(("failure.\n"));
570 return FALSE;
573 static int __init aedsp16_write(int port, int cmd)
575 unsigned char ret;
576 int loop = HARDRETRY;
578 DBG((" Write DSP Byte (0x%x) [0x%x]: ", port, cmd));
580 do {
581 ret = inb(port + DSP_STATUS);
583 * DSP ready to receive data if bit 7 of ret == 0
585 if (!(ret & 0x80)) {
586 outb(cmd, port + DSP_COMMAND);
587 DBG(("success.\n"));
588 return 0;
590 } while (loop--);
592 DBG(("timeout.\n"));
593 printk("[AEDSP16] DSP Command (0x%x) timeout.\n", cmd);
595 return -1;
598 #if defined(CONFIG_SC6600)
600 #if defined(AEDSP16_INFO) || defined(AEDSP16_DEBUG)
601 void __init aedsp16_pinfo(void) {
602 DBG(("\n Base address: %x\n", decoded_hcfg.iobase));
603 DBG((" Joystick : %s present\n", decoded_hcfg.joystick?"":" not"));
604 DBG((" WSS addr : %x\n", decoded_hcfg.wssbase));
605 DBG((" MPU-401 addr: %x\n", decoded_hcfg.mpubase));
606 DBG((" CDROM : %s present\n", (decoded_hcfg.cdrom!=4)?"":" not"));
607 DBG((" CDROMADDR : %x\n\n", decoded_hcfg.cdrombase));
609 #endif
611 void __init aedsp16_hard_decode(void) {
613 DBG((" aedsp16_hard_decode: 0x%x, 0x%x\n", hard_cfg[0], hard_cfg[1]));
616 * Decode Cfg Bytes.
618 decoded_hcfg.iobase = IOBASE(hard_cfg[0]);
619 decoded_hcfg.joystick = JOY(hard_cfg[0]);
620 decoded_hcfg.wssbase = WSSADDR(hard_cfg[0]);
621 decoded_hcfg.mpubase = MPUADDR(hard_cfg[0]);
622 decoded_hcfg.cdrom = CDROM(hard_cfg[1]);
623 decoded_hcfg.cdrombase = CDROMADDR(hard_cfg[1]);
625 #if defined(AEDSP16_INFO) || defined(AEDSP16_DEBUG)
626 printk(" Original sound card configuration:\n");
627 aedsp16_pinfo();
628 #endif
631 * Now set up the real kernel configuration.
633 decoded_hcfg.iobase = ae_config.base_io;
634 decoded_hcfg.wssbase = ae_config.mss_base;
635 decoded_hcfg.mpubase = ae_config.mpu_base;
637 #if defined(CONFIG_SC6600_JOY)
638 decoded_hcfg.joystick = CONFIG_SC6600_JOY; /* Enable */
639 #endif
640 #if defined(CONFIG_SC6600_CDROM)
641 decoded_hcfg.cdrom = CONFIG_SC6600_CDROM; /* 4:N-3:I-2:G-1:P-0:S */
642 #endif
643 #if defined(CONFIG_SC6600_CDROMBASE)
644 decoded_hcfg.cdrombase = CONFIG_SC6600_CDROMBASE; /* 0 Disable */
645 #endif
647 #if defined(AEDSP16_DEBUG)
648 DBG((" New Values:\n"));
649 aedsp16_pinfo();
650 #endif
652 DBG(("success.\n"));
655 void __init aedsp16_hard_encode(void) {
657 DBG((" aedsp16_hard_encode: 0x%x, 0x%x\n", hard_cfg[0], hard_cfg[1]));
659 hard_cfg[0] = 0;
660 hard_cfg[1] = 0;
662 hard_cfg[0] |= 0x20;
664 BLDIOBASE (hard_cfg[0], decoded_hcfg.iobase);
665 BLDWSSADDR(hard_cfg[0], decoded_hcfg.wssbase);
666 BLDMPUADDR(hard_cfg[0], decoded_hcfg.mpubase);
667 BLDJOY(hard_cfg[0], decoded_hcfg.joystick);
668 BLDCDROM(hard_cfg[1], decoded_hcfg.cdrom);
669 BLDCDROMADDR(hard_cfg[1], decoded_hcfg.cdrombase);
671 #if defined(AEDSP16_DEBUG)
672 aedsp16_pinfo();
673 #endif
675 DBG((" aedsp16_hard_encode: 0x%x, 0x%x\n", hard_cfg[0], hard_cfg[1]));
676 DBG(("success.\n"));
680 static int __init aedsp16_hard_write(int port) {
682 DBG(("aedsp16_hard_write:\n"));
684 if (aedsp16_write(port, COMMAND_6C)) {
685 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_6C);
686 DBG(("failure.\n"));
687 return FALSE;
689 if (aedsp16_write(port, COMMAND_5C)) {
690 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_5C);
691 DBG(("failure.\n"));
692 return FALSE;
694 if (aedsp16_write(port, hard_cfg[0])) {
695 printk("[AEDSP16] DATA 0x%x: failed!\n", hard_cfg[0]);
696 DBG(("failure.\n"));
697 return FALSE;
699 if (aedsp16_write(port, hard_cfg[1])) {
700 printk("[AEDSP16] DATA 0x%x: failed!\n", hard_cfg[1]);
701 DBG(("failure.\n"));
702 return FALSE;
704 if (aedsp16_write(port, COMMAND_C5)) {
705 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_C5);
706 DBG(("failure.\n"));
707 return FALSE;
710 DBG(("success.\n"));
712 return TRUE;
715 static int __init aedsp16_hard_read(int port) {
717 DBG(("aedsp16_hard_read:\n"));
719 if (aedsp16_write(port, READ_HARD_CFG)) {
720 printk("[AEDSP16] CMD 0x%x: failed!\n", READ_HARD_CFG);
721 DBG(("failure.\n"));
722 return FALSE;
725 if ((hard_cfg[0] = aedsp16_read(port)) == -1) {
726 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n",
727 READ_HARD_CFG);
728 DBG(("failure.\n"));
729 return FALSE;
731 if ((hard_cfg[1] = aedsp16_read(port)) == -1) {
732 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n",
733 READ_HARD_CFG);
734 DBG(("failure.\n"));
735 return FALSE;
737 if (aedsp16_read(port) == -1) {
738 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n",
739 READ_HARD_CFG);
740 DBG(("failure.\n"));
741 return FALSE;
744 DBG(("success.\n"));
746 return TRUE;
749 static int __init aedsp16_ext_cfg_write(int port) {
751 int extcfg, val;
753 if (aedsp16_write(port, COMMAND_66)) {
754 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_66);
755 return FALSE;
758 extcfg = 7;
759 if (decoded_hcfg.cdrom != 2)
760 extcfg = 0x0F;
761 if ((decoded_hcfg.cdrom == 4) ||
762 (decoded_hcfg.cdrom == 3))
763 extcfg &= ~2;
764 if (decoded_hcfg.cdrombase == 0)
765 extcfg &= ~2;
766 if (decoded_hcfg.mpubase == 0)
767 extcfg &= ~1;
769 if (aedsp16_write(port, extcfg)) {
770 printk("[AEDSP16] Write extcfg: failed!\n");
771 return FALSE;
773 if (aedsp16_write(port, 0)) {
774 printk("[AEDSP16] Write extcfg: failed!\n");
775 return FALSE;
777 if (decoded_hcfg.cdrom == 3) {
778 if (aedsp16_write(port, COMMAND_52)) {
779 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_52);
780 return FALSE;
782 if ((val = aedsp16_read(port)) == -1) {
783 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n"
784 , COMMAND_52);
785 return FALSE;
787 val &= 0x7F;
788 if (aedsp16_write(port, COMMAND_60)) {
789 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_60);
790 return FALSE;
792 if (aedsp16_write(port, val)) {
793 printk("[AEDSP16] Write val: failed!\n");
794 return FALSE;
798 return TRUE;
801 #endif /* CONFIG_SC6600 */
803 static int __init aedsp16_cfg_write(int port) {
804 if (aedsp16_write(port, WRITE_MDIRQ_CFG)) {
805 printk("[AEDSP16] CMD 0x%x: failed!\n", WRITE_MDIRQ_CFG);
806 return FALSE;
808 if (aedsp16_write(port, soft_cfg)) {
809 printk("[AEDSP16] Initialization of (M)IRQ and DMA: failed!\n");
810 return FALSE;
812 return TRUE;
815 static int __init aedsp16_init_mss(int port)
817 DBG(("aedsp16_init_mss:\n"));
819 mdelay(10);
821 if (aedsp16_write(port, DSP_INIT_MSS)) {
822 printk("[AEDSP16] aedsp16_init_mss [0x%x]: failed!\n",
823 DSP_INIT_MSS);
824 DBG(("failure.\n"));
825 return FALSE;
828 mdelay(10);
830 if (aedsp16_cfg_write(port) == FALSE)
831 return FALSE;
833 outb(soft_cfg_mss, ae_config.mss_base);
835 DBG(("success.\n"));
837 return TRUE;
840 static int __init aedsp16_setup_board(int port) {
841 int loop = RETRY;
843 #if defined(CONFIG_SC6600)
844 int val = 0;
846 if (aedsp16_hard_read(port) == FALSE) {
847 printk("[AEDSP16] aedsp16_hard_read: failed!\n");
848 return FALSE;
851 if (aedsp16_write(port, COMMAND_52)) {
852 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_52);
853 return FALSE;
856 if ((val = aedsp16_read(port)) == -1) {
857 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n",
858 COMMAND_52);
859 return FALSE;
861 #endif
863 do {
864 if (aedsp16_write(port, COMMAND_88)) {
865 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_88);
866 return FALSE;
868 mdelay(10);
869 } while ((aedsp16_wait_data(port) == FALSE) && loop--);
871 if (aedsp16_read(port) == -1) {
872 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n",
873 COMMAND_88);
874 return FALSE;
877 #if !defined(CONFIG_SC6600)
878 if (aedsp16_write(port, COMMAND_5C)) {
879 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_5C);
880 return FALSE;
882 #endif
884 if (aedsp16_cfg_write(port) == FALSE)
885 return FALSE;
887 #if defined(CONFIG_SC6600)
888 if (aedsp16_write(port, COMMAND_60)) {
889 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_60);
890 return FALSE;
892 if (aedsp16_write(port, val)) {
893 printk("[AEDSP16] DATA 0x%x: failed!\n", val);
894 return FALSE;
896 if (aedsp16_write(port, COMMAND_6E)) {
897 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_6E);
898 return FALSE;
900 if (aedsp16_write(port, ver[0])) {
901 printk("[AEDSP16] DATA 0x%x: failed!\n", ver[0]);
902 return FALSE;
904 if (aedsp16_write(port, ver[1])) {
905 printk("[AEDSP16] DATA 0x%x: failed!\n", ver[1]);
906 return FALSE;
909 if (aedsp16_hard_write(port) == FALSE) {
910 printk("[AEDSP16] aedsp16_hard_write: failed!\n");
911 return FALSE;
914 if (aedsp16_write(port, COMMAND_5C)) {
915 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_5C);
916 return FALSE;
919 #if defined(THIS_IS_A_THING_I_HAVE_NOT_TESTED_YET)
920 if (aedsp16_cfg_write(port) == FALSE)
921 return FALSE;
922 #endif
924 #endif
926 return TRUE;
929 static int __init aedsp16_stdcfg(int port) {
930 if (aedsp16_write(port, WRITE_MDIRQ_CFG)) {
931 printk("[AEDSP16] CMD 0x%x: failed!\n", WRITE_MDIRQ_CFG);
932 return FALSE;
935 * 0x0A == (IRQ 7, DMA 1, MIRQ 0)
937 if (aedsp16_write(port, 0x0A)) {
938 printk("[AEDSP16] aedsp16_stdcfg: failed!\n");
939 return FALSE;
941 return TRUE;
944 static int __init aedsp16_dsp_version(int port)
946 int len = 0;
947 int ret;
949 DBG(("Get DSP Version:\n"));
951 if (aedsp16_write(ae_config.base_io, GET_DSP_VERSION)) {
952 printk("[AEDSP16] CMD 0x%x: failed!\n", GET_DSP_VERSION);
953 DBG(("failed.\n"));
954 return FALSE;
957 do {
958 if ((ret = aedsp16_read(port)) == -1) {
959 DBG(("failed.\n"));
960 return FALSE;
963 * We already know how many int are stored (2), so we know when the
964 * string is finished.
966 ver[len++] = ret;
967 } while (len < CARDVERLEN);
968 sprintf(DSPVersion, "%d.%d", ver[0], ver[1]);
970 DBG(("success.\n"));
972 return TRUE;
975 static int __init aedsp16_dsp_copyright(int port)
977 int len = 0;
978 int ret;
980 DBG(("Get DSP Copyright:\n"));
982 if (aedsp16_write(ae_config.base_io, GET_DSP_COPYRIGHT)) {
983 printk("[AEDSP16] CMD 0x%x: failed!\n", GET_DSP_COPYRIGHT);
984 DBG(("failed.\n"));
985 return FALSE;
988 do {
989 if ((ret = aedsp16_read(port)) == -1) {
991 * If no more data available, return to the caller, no error if len>0.
992 * We have no other way to know when the string is finished.
994 if (len)
995 break;
996 else {
997 DBG(("failed.\n"));
998 return FALSE;
1002 DSPCopyright[len++] = ret;
1004 } while (len < CARDNAMELEN);
1006 DBG(("success.\n"));
1008 return TRUE;
1011 static void __init aedsp16_init_tables(void)
1013 int i = 0;
1015 memset(DSPCopyright, 0, CARDNAMELEN + 1);
1016 memset(DSPVersion, 0, CARDVERLEN + 1);
1018 for (i = 0; orIRQ[i].or; i++)
1019 if (orIRQ[i].val == ae_config.irq) {
1020 soft_cfg |= orIRQ[i].or;
1021 soft_cfg_mss |= orIRQ[i].or;
1024 for (i = 0; orMIRQ[i].or; i++)
1025 if (orMIRQ[i].or == ae_config.mpu_irq)
1026 soft_cfg |= orMIRQ[i].or;
1028 for (i = 0; orDMA[i].or; i++)
1029 if (orDMA[i].val == ae_config.dma) {
1030 soft_cfg |= orDMA[i].or;
1031 soft_cfg_mss |= orDMA[i].or;
1035 static int __init aedsp16_init_board(void)
1037 aedsp16_init_tables();
1039 if (aedsp16_dsp_reset(ae_config.base_io) == FALSE) {
1040 printk("[AEDSP16] aedsp16_dsp_reset: failed!\n");
1041 return FALSE;
1043 if (aedsp16_dsp_copyright(ae_config.base_io) == FALSE) {
1044 printk("[AEDSP16] aedsp16_dsp_copyright: failed!\n");
1045 return FALSE;
1049 * My AEDSP16 card return SC-6000 in DSPCopyright, so
1050 * if we have something different, we have to be warned.
1052 if (strcmp("SC-6000", DSPCopyright))
1053 printk("[AEDSP16] Warning: non SC-6000 audio card!\n");
1055 if (aedsp16_dsp_version(ae_config.base_io) == FALSE) {
1056 printk("[AEDSP16] aedsp16_dsp_version: failed!\n");
1057 return FALSE;
1060 if (aedsp16_stdcfg(ae_config.base_io) == FALSE) {
1061 printk("[AEDSP16] aedsp16_stdcfg: failed!\n");
1062 return FALSE;
1065 #if defined(CONFIG_SC6600)
1066 if (aedsp16_hard_read(ae_config.base_io) == FALSE) {
1067 printk("[AEDSP16] aedsp16_hard_read: failed!\n");
1068 return FALSE;
1071 aedsp16_hard_decode();
1073 aedsp16_hard_encode();
1075 if (aedsp16_hard_write(ae_config.base_io) == FALSE) {
1076 printk("[AEDSP16] aedsp16_hard_write: failed!\n");
1077 return FALSE;
1080 if (aedsp16_ext_cfg_write(ae_config.base_io) == FALSE) {
1081 printk("[AEDSP16] aedsp16_ext_cfg_write: failed!\n");
1082 return FALSE;
1084 #endif /* CONFIG_SC6600 */
1086 if (aedsp16_setup_board(ae_config.base_io) == FALSE) {
1087 printk("[AEDSP16] aedsp16_setup_board: failed!\n");
1088 return FALSE;
1091 if (ae_config.mss_base != -1) {
1092 if (ae_config.init & INIT_MSS) {
1093 if (aedsp16_init_mss(ae_config.base_io) == FALSE) {
1094 printk("[AEDSP16] Can not initialize"
1095 "Microsoft Sound System mode.\n");
1096 return FALSE;
1101 #if !defined(MODULE) || defined(AEDSP16_INFO) || defined(AEDSP16_DEBUG)
1103 printk("Audio Excel DSP 16 init v%s (%s %s) [",
1104 VERSION, DSPCopyright,
1105 DSPVersion);
1107 if (ae_config.mpu_base != -1) {
1108 if (ae_config.init & INIT_MPU401) {
1109 printk("MPU401");
1110 if ((ae_config.init & INIT_MSS) ||
1111 (ae_config.init & INIT_SBPRO))
1112 printk(" ");
1116 if (ae_config.mss_base == -1) {
1117 if (ae_config.init & INIT_SBPRO) {
1118 printk("SBPro");
1119 if (ae_config.init & INIT_MSS)
1120 printk(" ");
1124 if (ae_config.mss_base != -1)
1125 if (ae_config.init & INIT_MSS)
1126 printk("MSS");
1128 printk("]\n");
1129 #endif /* MODULE || AEDSP16_INFO || AEDSP16_DEBUG */
1131 mdelay(10);
1133 return TRUE;
1136 static int __init init_aedsp16_sb(void)
1138 DBG(("init_aedsp16_sb: "));
1141 * If the card is already init'ed MSS, we can not init it to SBPRO too
1142 * because the board can not emulate simultaneously MSS and SBPRO.
1144 if (ae_config.init & INIT_MSS)
1145 return FALSE;
1146 if (ae_config.init & INIT_SBPRO)
1147 return FALSE;
1149 ae_config.init |= INIT_SBPRO;
1151 DBG(("done.\n"));
1153 return TRUE;
1156 static void __init uninit_aedsp16_sb(void)
1158 DBG(("uninit_aedsp16_sb: "));
1160 ae_config.init &= ~INIT_SBPRO;
1162 DBG(("done.\n"));
1165 static int __init init_aedsp16_mss(void)
1167 DBG(("init_aedsp16_mss: "));
1170 * If the card is already init'ed SBPRO, we can not init it to MSS too
1171 * because the board can not emulate simultaneously MSS and SBPRO.
1173 if (ae_config.init & INIT_SBPRO)
1174 return FALSE;
1175 if (ae_config.init & INIT_MSS)
1176 return FALSE;
1178 * We must check the CONFIG_AEDSP16_BASE region too because these are the I/O
1179 * ports to access card's control registers.
1181 if (!(ae_config.init & INIT_MPU401)) {
1182 if (check_region(ae_config.base_io, IOBASE_REGION_SIZE)) {
1183 printk(
1184 "AEDSP16 BASE I/O port region is already in use.\n");
1185 return FALSE;
1190 * We must allocate the CONFIG_AEDSP16_BASE region too because these are the
1191 * I/O ports to access card's control registers.
1193 if (!(ae_config.init & INIT_MPU401))
1194 request_region(ae_config.base_io, IOBASE_REGION_SIZE,
1195 "aedsp16 (base)");
1197 ae_config.init |= INIT_MSS;
1199 DBG(("done.\n"));
1201 return TRUE;
1204 static void __init uninit_aedsp16_mss(void)
1206 DBG(("uninit_aedsp16_mss: "));
1208 if ((!(ae_config.init & INIT_MPU401)) &&
1209 (ae_config.init & INIT_MSS)) {
1210 release_region(ae_config.base_io, IOBASE_REGION_SIZE);
1211 DBG(("AEDSP16 base region released.\n"));
1214 ae_config.init &= ~INIT_MSS;
1215 DBG(("done.\n"));
1218 static int __init init_aedsp16_mpu(void)
1220 DBG(("init_aedsp16_mpu: "));
1222 if (ae_config.init & INIT_MPU401)
1223 return FALSE;
1226 * We must check the CONFIG_AEDSP16_BASE region too because these are the I/O
1227 * ports to access card's control registers.
1229 if (!(ae_config.init & (INIT_MSS | INIT_SBPRO))) {
1230 if (check_region(ae_config.base_io, IOBASE_REGION_SIZE)) {
1231 printk(
1232 "AEDSP16 BASE I/O port region is already in use.\n");
1233 return FALSE;
1237 if (!(ae_config.init & (INIT_MSS | INIT_SBPRO)))
1238 request_region(ae_config.base_io, IOBASE_REGION_SIZE,
1239 "aedsp16 (base)");
1241 ae_config.init |= INIT_MPU401;
1243 DBG(("done.\n"));
1245 return TRUE;
1248 static void __init uninit_aedsp16_mpu(void)
1250 DBG(("uninit_aedsp16_mpu: "));
1252 if ((!(ae_config.init & (INIT_MSS | INIT_SBPRO))) &&
1253 (ae_config.init & INIT_MPU401)) {
1254 release_region(ae_config.base_io, IOBASE_REGION_SIZE);
1255 DBG(("AEDSP16 base region released.\n"));
1258 ae_config.init &= ~INIT_MPU401;
1260 DBG(("done.\n"));
1263 int __init init_aedsp16(void)
1265 int initialized = FALSE;
1267 DBG(("Initializing BASE[0x%x] IRQ[%d] DMA[%d] MIRQ[%d]\n",
1268 ae_config.base_io,ae_config.irq,ae_config.dma,ae_config.mpu_irq));
1270 if (ae_config.mss_base == -1) {
1271 if (init_aedsp16_sb() == FALSE) {
1272 uninit_aedsp16_sb();
1273 } else {
1274 initialized = TRUE;
1278 if (ae_config.mpu_base != -1) {
1279 if (init_aedsp16_mpu() == FALSE) {
1280 uninit_aedsp16_mpu();
1281 } else {
1282 initialized = TRUE;
1287 * In the sequence of init routines, the MSS init MUST be the last!
1288 * This because of the special register programming the MSS mode needs.
1289 * A board reset would disable the MSS mode restoring the default SBPRO
1290 * mode.
1292 if (ae_config.mss_base != -1) {
1293 if (init_aedsp16_mss() == FALSE) {
1294 uninit_aedsp16_mss();
1295 } else {
1296 initialized = TRUE;
1300 if (initialized)
1301 initialized = aedsp16_init_board();
1302 return initialized;
1305 void __init uninit_aedsp16(void)
1307 if (ae_config.mss_base != -1)
1308 uninit_aedsp16_mss();
1309 else
1310 uninit_aedsp16_sb();
1311 if (ae_config.mpu_base != -1)
1312 uninit_aedsp16_mpu();
1315 static int __initdata io = -1;
1316 static int __initdata irq = -1;
1317 static int __initdata dma = -1;
1318 static int __initdata mpu_irq = -1;
1319 static int __initdata mss_base = -1;
1320 static int __initdata mpu_base = -1;
1322 MODULE_PARM(io, "i");
1323 MODULE_PARM_DESC(io, "I/O base address (0x220 0x240)");
1324 MODULE_PARM(irq, "i");
1325 MODULE_PARM_DESC(irq, "IRQ line (5 7 9 10 11)");
1326 MODULE_PARM(dma, "i");
1327 MODULE_PARM_DESC(dma, "dma line (0 1 3)");
1328 MODULE_PARM(mpu_irq, "i");
1329 MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ line (5 7 9 10 0)");
1330 MODULE_PARM(mss_base, "i");
1331 MODULE_PARM_DESC(mss_base, "MSS emulation I/O base address (0x530 0xE80)");
1332 MODULE_PARM(mpu_base, "i");
1333 MODULE_PARM_DESC(mpu_base,"MPU-401 I/O base address (0x300 0x310 0x320 0x330)");
1334 MODULE_AUTHOR("Riccardo Facchetti <fizban@tin.it>");
1335 MODULE_DESCRIPTION("Audio Excel DSP 16 Driver Version " VERSION);
1337 static int __init do_init_aedsp16(void) {
1338 printk("Audio Excel DSP 16 init driver Copyright (C) Riccardo Facchetti 1995-98\n");
1339 if (io == -1 || dma == -1 || irq == -1) {
1340 printk(KERN_INFO "aedsp16: I/O, IRQ and DMA are mandatory\n");
1341 return -EINVAL;
1344 ae_config.base_io = io;
1345 ae_config.irq = irq;
1346 ae_config.dma = dma;
1348 ae_config.mss_base = mss_base;
1349 ae_config.mpu_base = mpu_base;
1350 ae_config.mpu_irq = mpu_irq;
1352 if (init_aedsp16() == FALSE) {
1353 printk(KERN_ERR "aedsp16: initialization failed\n");
1355 * XXX
1356 * What error should we return here ?
1358 return -EINVAL;
1360 SOUND_LOCK;
1361 return 0;
1364 static void __exit cleanup_aedsp16(void) {
1365 uninit_aedsp16();
1366 SOUND_LOCK_END;
1369 module_init(do_init_aedsp16);
1370 module_exit(cleanup_aedsp16);
1372 #ifndef MODULE
1373 static int __init setup_aedsp16(char *str)
1375 /* io, irq, dma, mss_io, mpu_io, mpu_irq */
1376 int ints[7];
1378 str = get_options(str, ARRAY_SIZE(ints), ints);
1380 io = ints[1];
1381 irq = ints[2];
1382 dma = ints[3];
1383 mss_base = ints[4];
1384 mpu_base = ints[5];
1385 mpu_irq = ints[6];
1386 return 1;
1389 __setup("aedsp16=", setup_aedsp16);
1390 #endif