Import 2.1.118
[davej-history.git] / drivers / sound / lowlevel / aedsp16.c
blob48ef93f19552929ae99489aea6c797b60da6a326
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_AEDSP16_BASE)
38 # undef CONFIG_AEDSP16
39 #else
40 # if defined(MODULE) && defined(CONFIG_AEDSP16_MODULE)
41 # define CONFIG_AEDSP16 1
42 # endif
43 #endif
46 #if defined(CONFIG_AEDSP16)
48 #if defined(CONFIG_AEDSP16_SBPRO) && defined(CONFIG_AEDSP16_MSS)
49 #error You have to enable only one of the MSS and SBPRO emulations.
50 #endif
54 READ THIS
56 This module started to configure the Audio Excel DSP 16 Sound Card.
57 Now works with the SC-6000 (old aedsp16) and new SC-6600 based cards.
59 NOTE: I have NO idea about Audio Excel DSP 16 III. If someone owns this
60 audio card and want to see the kernel support for it, please contact me.
62 Audio Excel DSP 16 is an SB pro II, Microsoft Sound System and MPU-401
63 compatible card.
64 It is software-only configurable (no jumpers to hard-set irq/dma/mpu-irq),
65 so before this module, the only way to configure the DSP under linux was
66 boot the MS-DOS loading the sound.sys device driver (this driver soft-
67 configure the sound board hardware by massaging someone of its registers),
68 and then ctrl-alt-del to boot linux with the DSP configured by the DOS
69 driver.
71 This module works configuring your Audio Excel DSP 16's irq, dma and
72 mpu-401-irq. The OSS Lite routines rely on the fact that if the
73 hardware is there, they can detect it. The problem with AEDSP16 is
74 that no hardware can be found by the probe routines if the sound card
75 is not configured properly. Sometimes the kernel probe routines can find
76 an SBPRO even when the card is not configured (this is the standard setup
77 of the card), but the SBPRO emulation don't work well if the card is not
78 properly initialized. For this reason
80 aedsp16_init_board()
82 routine is called before the OSS Lite probe routines try to detect the
83 hardware.
85 NOTE (READ THE NOTE TOO, IT CONTAIN USEFUL INFORMATIONS)
87 NOTE: Now it works with SC-6000 and SC-6600 based audio cards. The new cards
88 have no jumper switch at all. No more WSS or MPU-401 I/O port switches. They
89 have to be configured by software.
91 NOTE: The driver is merged with the new OSS Lite sound driver. It works
92 as a lowlevel driver.
94 The Audio Excel DSP 16 Sound Card emulates both SBPRO and MSS;
95 the OSS Lite sound driver can be configured for SBPRO and MSS cards
96 at the same time, but the aedsp16 can't be two cards!!
97 When we configure it, we have to choose the SBPRO or the MSS emulation
98 for AEDSP16. We also can install a *REAL* card of the other type (see [1]).
100 NOTE: If someone can test the combination AEDSP16+MSS or AEDSP16+SBPRO
101 please let me know if it works.
103 The MPU-401 support can be compiled in together with one of the other
104 two operating modes.
106 NOTE: This is something like plug-and-play: we have only to plug
107 the AEDSP16 board in the socket, and then configure and compile
108 a kernel that uses the AEDSP16 software configuration capability.
109 No jumper setting is needed!
111 For example, if you want AEDSP16 to be an SBPro, on irq 10, dma 3
112 you have just to make config the OSS Lite package, configuring
113 the AEDSP16 sound card, then activating the SBPro emulation mode
114 and at last configuring IRQ and DMA.
115 Compile the kernel and run it.
117 NOTE: This means for SC-6000 cards that you can choose irq and dma,
118 but not the I/O addresses. To change I/O addresses you have to set
119 them with jumpers. For SC-6600 cards you have no jumpers so you have
120 to set up your full card configuration in the make config.
122 You can change the irq/dma/mirq settings WITHOUT THE NEED to open
123 your computer and massage the jumpers (there are no irq/dma/mirq
124 jumpers to be configured anyway, only I/O BASE values have to be
125 configured with jumpers)
127 For some ununderstandable reason, the card default of irq 7, dma 1,
128 don't work for me. Seems to be an IRQ or DMA conflict. Under heavy
129 HDD work, the kernel start to erupt out a lot of messages like:
131 'Sound: DMA timed out - IRQ/DRQ config error?'
133 For what I can say, I have NOT any conflict at irq 7 (under linux I'm
134 using the lp polling driver), and dma line 1 is unused as stated by
135 /proc/dma. I can suppose this is a bug of AEDSP16. I know my hardware so
136 I'm pretty sure I have not any conflict, but may be I'm wrong. Who knows!
137 Anyway a setting of irq 10, dma 3 works really fine.
139 NOTE: if someone can use AEDSP16 with irq 7, dma 1, please let me know
140 the emulation mode, all the installed hardware and the hardware
141 configuration (irq and dma settings of all the hardware).
143 This init module should work with SBPRO+MSS, when one of the two is
144 the AEDSP16 emulation and the other the real card. (see [1])
145 For example:
147 AEDSP16 (0x220) in SBPRO emu (0x220) + real MSS + other
148 AEDSP16 (0x220) in MSS emu + real SBPRO (0x240) + other
150 MPU401 should work. (see [2])
154 Date: Mon, 29 Jul 1997 08:35:40 +0100
155 From: Mr S J Greenaway <sjg95@unixfe.rl.ac.uk>
157 [...]
158 Just to let you know got my Audio Excel (emulating a MSS) working
159 with my original SB16, thanks for the driver!
160 [...]
163 [2] Not tested by me for lack of hardware.
165 TODO, WISHES AND TECH
167 - About I/O ports allocation -
169 Request the 2x0h region (port base) in any case if we are using this card.
171 NOTE: the "aedsp16 (base)" string with which we are requesting the aedsp16
172 port base region (see code) does not mean necessarily that we are emulating
173 sbpro. Even if this region is the sbpro I/O ports region, we use this
174 region to access the control registers of the card, and if emulating
175 sbpro, I/O sbpro registers too. If we are emulating MSS, the sbpro
176 registers are not used, in no way, to emulate an sbpro: they are
177 used only for configuration purposes.
179 Started Fri Mar 17 16:13:18 MET 1995
181 v0.1 (ALPHA, was an user-level program called AudioExcelDSP16.c)
182 - Initial code.
183 v0.2 (ALPHA)
184 - Cleanups.
185 - Integrated with Linux voxware v 2.90-2 kernel sound driver.
186 - SoundBlaster Pro mode configuration.
187 - Microsoft Sound System mode configuration.
188 - MPU-401 mode configuration.
189 v0.3 (ALPHA)
190 - Cleanups.
191 - Rearranged the code to let aedsp16_init_board be more general.
192 - Erased the REALLY_SLOW_IO. We don't need it. Erased the linux/io.h
193 inclusion too. We rely on os.h
194 - Used the to get a variable
195 len string (we are not sure about the len of Copyright string).
196 This works with any SB and compatible.
197 - Added the code to request_region at device init (should go in
198 the main body of voxware).
199 v0.4 (BETA)
200 - Better configure.c patch for aedsp16 configuration (better
201 logic of inclusion of AEDSP16 support)
202 - Modified the conditional compilation to better support more than
203 one sound card of the emulated type (read the NOTES above)
204 - Moved the sb init routine from the attach to the very first
205 probe in sb_card.c
206 - Rearrangements and cleanups
207 - Wiped out some unnecessary code and variables: this is kernel
208 code so it is better save some TEXT and DATA
209 - Fixed the request_region code. We must allocate the aedsp16 (sbpro)
210 I/O ports in any case because they are used to access the DSP
211 configuration registers and we can not allow anyone to get them.
212 v0.5
213 - cleanups on comments
214 - prep for diffs against v3.0-proto-950402
215 v0.6
216 - removed the request_region()s when compiling the MODULE sound.o
217 because we are not allowed (by the actual voxware structure) to
218 release_region()
219 v0.7 (pre ALPHA, not distributed)
220 - started porting this module to kernel 1.3.84. Dummy probe/attach
221 routines.
222 v0.8 (ALPHA)
223 - attached all the init routines.
224 v0.9 (BETA)
225 - Integrated with linux-pre2.0.7
226 - Integrated with configuration scripts.
227 - Cleaned up and beautyfied the code.
228 v0.9.9 (BETA)
229 - Thanks to Piercarlo Grandi: corrected the conditonal compilation code.
230 Now only the code configured is compiled in, with some memory saving.
231 v0.9.10
232 - Integration into the sound/lowlevel/ section of the sound driver.
233 - Re-organized the code.
234 v0.9.11 (not distributed)
235 - Rewritten the init interface-routines to initialize the AEDSP16 in
236 one shot.
237 - More cosmetics.
238 - SC-6600 support.
239 - More soft/hard configuration.
240 v0.9.12
241 - Refined the v0.9.11 code with conditional compilation to distinguish
242 between SC-6000 and SC-6600 code.
243 v1.0.0
244 - Prep for merging with OSS Lite and Linux kernel 2.1.13
245 - Corrected a bug in request/check/release region calls (thanks to the
246 new kernel exception handling).
247 v1.1
248 - Revamped for integration with new modularized sound drivers: to enhance
249 the flexibility of modular version, I have removed all the conditional
250 compilation for SBPRO, MPU and MSS code. Now it is all managed with
251 the ae_config structure.
252 v1.2
253 - Module informations added.
254 - Removed aedsp16_delay_10msec(), now using mdelay(10)
255 - All data and funcs moved to .*.init section.
257 Known Problems:
258 - Audio Excel DSP 16 III don't work with this driver.
260 Credits:
261 Many thanks to Gerald Britton <gbritton@CapAccess.org>. He helped me a
262 lot in testing the 0.9.11 and 0.9.12 versions of this driver.
267 #define VERSION "1.2" /* Version of Audio Excel DSP 16 driver */
269 #undef AEDSP16_DEBUG 1 /* Define this to enable debug code */
270 #undef AEDSP16_DEBUG_MORE 1 /* Define this to enable more debug */
271 #undef AEDSP16_INFO 1 /* Define this to enable info code */
273 #if defined(AEDSP16_DEBUG)
274 # define DBG(x) printk x
275 # if defined(AEDSP16_DEBUG_MORE)
276 # define DBG1(x) printk x
277 # else
278 # define DBG1(x)
279 # endif
280 #else
281 # define DBG(x)
282 # define DBG1(x)
283 #endif
286 * Misc definitions
288 #define TRUE 1
289 #define FALSE 0
292 * Region Size for request/check/release region.
294 #define IOBASE_REGION_SIZE 0x10
297 * Hardware related defaults
299 #define DEF_AEDSP16_IOB 0x220 /* 0x220(default) 0x240 */
300 #define DEF_AEDSP16_IRQ 7 /* 5 7(default) 9 10 11 */
301 #define DEF_AEDSP16_MRQ 0 /* 5 7 9 10 0(default), 0 means disable */
302 #define DEF_AEDSP16_DMA 1 /* 0 1(default) 3 */
305 * Commands of AEDSP16's DSP (SBPRO+special).
306 * Some of them are COMMAND_xx, in the future they may change.
308 #define WRITE_MDIRQ_CFG 0x50 /* Set M&I&DRQ mask (the real config) */
309 #define COMMAND_52 0x52 /* */
310 #define READ_HARD_CFG 0x58 /* Read Hardware Config (I/O base etc) */
311 #define COMMAND_5C 0x5c /* */
312 #define COMMAND_60 0x60 /* */
313 #define COMMAND_66 0x66 /* */
314 #define COMMAND_6C 0x6c /* */
315 #define COMMAND_6E 0x6e /* */
316 #define COMMAND_88 0x88 /* */
317 #define DSP_INIT_MSS 0x8c /* Enable Microsoft Sound System mode */
318 #define COMMAND_C5 0xc5 /* */
319 #define GET_DSP_VERSION 0xe1 /* Get DSP Version */
320 #define GET_DSP_COPYRIGHT 0xe3 /* Get DSP Copyright */
323 * Offsets of AEDSP16 DSP I/O ports. The offset is added to base I/O port
324 * to have the actual I/O port.
325 * Register permissions are:
326 * (wo) == Write Only
327 * (ro) == Read Only
328 * (w-) == Write
329 * (r-) == Read
331 #define DSP_RESET 0x06 /* offset of DSP RESET (wo) */
332 #define DSP_READ 0x0a /* offset of DSP READ (ro) */
333 #define DSP_WRITE 0x0c /* offset of DSP WRITE (w-) */
334 #define DSP_COMMAND 0x0c /* offset of DSP COMMAND (w-) */
335 #define DSP_STATUS 0x0c /* offset of DSP STATUS (r-) */
336 #define DSP_DATAVAIL 0x0e /* offset of DSP DATA AVAILABLE (ro) */
339 #define RETRY 10 /* Various retry values on I/O opera- */
340 #define STATUSRETRY 1000 /* tions. Sometimes we have to */
341 #define HARDRETRY 500000 /* wait for previous cmd to complete */
344 * Size of character arrays that store name and version of sound card
346 #define CARDNAMELEN 15 /* Size of the card's name in chars */
347 #define CARDVERLEN 2 /* Size of the card's version in chars */
349 #if defined(CONFIG_SC6600)
351 * Bitmapped flags of hard configuration
354 * Decode macros (xl == low byte, xh = high byte)
356 #define IOBASE(xl) ((xl & 0x01)?0x240:0x220)
357 #define JOY(xl) (xl & 0x02)
358 #define MPUADDR(xl) ( \
359 (xl & 0x0C)?0x330: \
360 (xl & 0x08)?0x320: \
361 (xl & 0x04)?0x310: \
362 0x300)
363 #define WSSADDR(xl) ((xl & 0x10)?0xE80:0x530)
364 #define CDROM(xh) (xh & 0x20)
365 #define CDROMADDR(xh) (((xh & 0x1F) << 4) + 0x200)
367 * Encode macros
369 #define BLDIOBASE(xl, val) { \
370 xl &= ~0x01; \
371 if (val == 0x240) \
372 xl |= 0x01; \
374 #define BLDJOY(xl, val) { \
375 xl &= ~0x02; \
376 if (val == 1) \
377 xl |= 0x02; \
379 #define BLDMPUADDR(xl, val) { \
380 xl &= ~0x0C; \
381 switch (val) { \
382 case 0x330: \
383 xl |= 0x0C; \
384 break; \
385 case 0x320: \
386 xl |= 0x08; \
387 break; \
388 case 0x310: \
389 xl |= 0x04; \
390 break; \
391 case 0x300: \
392 xl |= 0x00; \
393 break; \
394 default: \
395 xl |= 0x00; \
396 break; \
399 #define BLDWSSADDR(xl, val) { \
400 xl &= ~0x10; \
401 if (val == 0xE80) \
402 xl |= 0x10; \
404 #define BLDCDROM(xh, val) { \
405 xh &= ~0x20; \
406 if (val == 1) \
407 xh |= 0x20; \
409 #define BLDCDROMADDR(xh, val) { \
410 int tmp = val; \
411 tmp -= 0x200; \
412 tmp >>= 4; \
413 tmp &= 0x1F; \
414 xh |= tmp; \
415 xh &= 0x7F; \
416 xh |= 0x40; \
418 #endif /* CONFIG_SC6600 */
421 * Bit mapped flags for calling aedsp16_init_board(), and saving the current
422 * emulation mode.
424 #define INIT_NONE (0 )
425 #define INIT_SBPRO (1<<0)
426 #define INIT_MSS (1<<1)
427 #define INIT_MPU401 (1<<2)
429 static int soft_cfg __initdata = 0; /* bitmapped config */
430 static int soft_cfg_mss __initdata = 0; /* bitmapped mss config */
431 static int ver[CARDVERLEN] __initdata = {0, 0}; /* DSP Ver:
432 hi->ver[0] lo->ver[1] */
434 #if defined(CONFIG_SC6600)
435 static int hard_cfg[2] /* lo<-hard_cfg[0] hi<-hard_cfg[1] */
436 __initdata = { 0, 0};
437 #endif /* CONFIG_SC6600 */
439 #if defined(CONFIG_SC6600)
440 /* Decoded hard configuration */
441 struct d_hcfg {
442 int iobase;
443 int joystick;
444 int mpubase;
445 int wssbase;
446 int cdrom;
447 int cdrombase;
450 struct d_hcfg decoded_hcfg __initdata = {0, };
452 #endif /* CONFIG_SC6600 */
454 /* orVals contain the values to be or'ed */
455 struct orVals {
456 int val; /* irq|mirq|dma */
457 int or; /* soft_cfg |= TheStruct.or */
460 /* aedsp16_info contain the audio card configuration */
461 struct aedsp16_info {
462 int base_io; /* base I/O address for accessing card */
463 int irq; /* irq value for DSP I/O */
464 int mpu_irq; /* irq for mpu401 interface I/O */
465 int dma; /* dma value for DSP I/O */
466 int mss_base; /* base I/O for Microsoft Sound System */
467 int mpu_base; /* base I/O for MPU-401 emulation */
468 int init; /* Initialization status of the card */
472 * Magic values that the DSP will eat when configuring irq/mirq/dma
474 /* DSP IRQ conversion array */
475 static struct orVals orIRQ[] __initdata = {
476 {0x05, 0x28},
477 {0x07, 0x08},
478 {0x09, 0x10},
479 {0x0a, 0x18},
480 {0x0b, 0x20},
481 {0x00, 0x00}
484 /* MPU-401 IRQ conversion array */
485 static struct orVals orMIRQ[] __initdata = {
486 {0x05, 0x04},
487 {0x07, 0x44},
488 {0x09, 0x84},
489 {0x0a, 0xc4},
490 {0x00, 0x00}
493 /* DMA Channels conversion array */
494 static struct orVals orDMA[] __initdata = {
495 {0x00, 0x01},
496 {0x01, 0x02},
497 {0x03, 0x03},
498 {0x00, 0x00}
501 static struct aedsp16_info ae_config __initdata = {
502 DEF_AEDSP16_IOB,
503 DEF_AEDSP16_IRQ,
504 DEF_AEDSP16_MRQ,
505 DEF_AEDSP16_DMA,
508 INIT_NONE
512 * Buffers to store audio card informations
514 static char DSPCopyright[CARDNAMELEN + 1] __initdata = {0, };
515 static char DSPVersion[CARDVERLEN + 1] __initdata = {0, };
517 static int __init aedsp16_wait_data(int port)
519 int loop = STATUSRETRY;
520 unsigned char ret = 0;
522 DBG1(("aedsp16_wait_data (0x%x): ", port));
524 do {
525 ret = inb(port + DSP_DATAVAIL);
527 * Wait for data available (bit 7 of ret == 1)
529 } while (!(ret & 0x80) && loop--);
531 if (ret & 0x80) {
532 DBG1(("success.\n"));
533 return TRUE;
536 DBG1(("failure.\n"));
537 return FALSE;
540 static int __init aedsp16_read(int port)
542 int inbyte;
544 DBG((" Read DSP Byte (0x%x): ", port));
546 if (aedsp16_wait_data(port) == FALSE) {
547 DBG(("failure.\n"));
548 return -1;
551 inbyte = inb(port + DSP_READ);
553 DBG(("read [0x%x]/{%c}.\n", inbyte, inbyte));
555 return inbyte;
558 static int __init aedsp16_test_dsp(int port)
560 return ((aedsp16_read(port) == 0xaa) ? TRUE : FALSE);
563 static int __init aedsp16_dsp_reset(int port)
566 * Reset DSP
569 DBG(("Reset DSP:\n"));
571 outb(1, (port + DSP_RESET));
572 udelay(10);
573 outb(0, (port + DSP_RESET));
574 udelay(10);
575 udelay(10);
576 if (aedsp16_test_dsp(port) == TRUE) {
577 DBG(("success.\n"));
578 return TRUE;
579 } else
580 DBG(("failure.\n"));
581 return FALSE;
584 static int __init aedsp16_write(int port, int cmd)
586 unsigned char ret;
587 int loop = HARDRETRY;
589 DBG((" Write DSP Byte (0x%x) [0x%x]: ", port, cmd));
591 do {
592 ret = inb(port + DSP_STATUS);
594 * DSP ready to receive data if bit 7 of ret == 0
596 if (!(ret & 0x80)) {
597 outb(cmd, port + DSP_COMMAND);
598 DBG(("success.\n"));
599 return 0;
601 } while (loop--);
603 DBG(("timeout.\n"));
604 printk("[AEDSP16] DSP Command (0x%x) timeout.\n", cmd);
606 return -1;
609 #if defined(CONFIG_SC6600)
611 #if defined(AEDSP16_INFO) || defined(AEDSP16_DEBUG)
612 void __init aedsp16_pinfo(void) {
613 DBG(("\n Base address: %x\n", decoded_hcfg.iobase));
614 DBG((" Joystick : %s present\n", decoded_hcfg.joystick?"":" not"));
615 DBG((" WSS addr : %x\n", decoded_hcfg.wssbase));
616 DBG((" MPU-401 addr: %x\n", decoded_hcfg.mpubase));
617 DBG((" CDROM : %s present\n", (decoded_hcfg.cdrom!=4)?"":" not"));
618 DBG((" CDROMADDR : %x\n\n", decoded_hcfg.cdrombase));
620 #endif
622 void __init aedsp16_hard_decode(void) {
624 DBG((" aedsp16_hard_decode: 0x%x, 0x%x\n", hard_cfg[0], hard_cfg[1]));
627 * Decode Cfg Bytes.
629 decoded_hcfg.iobase = IOBASE(hard_cfg[0]);
630 decoded_hcfg.joystick = JOY(hard_cfg[0]);
631 decoded_hcfg.wssbase = WSSADDR(hard_cfg[0]);
632 decoded_hcfg.mpubase = MPUADDR(hard_cfg[0]);
633 decoded_hcfg.cdrom = CDROM(hard_cfg[1]);
634 decoded_hcfg.cdrombase = CDROMADDR(hard_cfg[1]);
636 #if defined(AEDSP16_INFO) || defined(AEDSP16_DEBUG)
637 printk(" Original sound card configuration:\n");
638 aedsp16_pinfo();
639 #endif
642 * Now set up the real kernel configuration.
644 decoded_hcfg.iobase = ae_config.base_io;
645 decoded_hcfg.wssbase = ae_config.mss_base;
646 decoded_hcfg.mpubase = ae_config.mpu_base;
648 #if defined(CONFIG_SC6600_JOY)
649 decoded_hcfg.joystick = CONFIG_SC6600_JOY; /* Enable */
650 #endif
651 #if defined(CONFIG_SC6600_CDROM)
652 decoded_hcfg.cdrom = CONFIG_SC6600_CDROM; /* 4:N-3:I-2:G-1:P-0:S */
653 #endif
654 #if defined(CONFIG_SC6600_CDROMBASE)
655 decoded_hcfg.cdrombase = CONFIG_SC6600_CDROMBASE; /* 0 Disable */
656 #endif
658 #if defined(AEDSP16_DEBUG)
659 DBG((" New Values:\n"));
660 aedsp16_pinfo();
661 #endif
663 DBG(("success.\n"));
666 void __init aedsp16_hard_encode(void) {
668 DBG((" aedsp16_hard_encode: 0x%x, 0x%x\n", hard_cfg[0], hard_cfg[1]));
670 hard_cfg[0] = 0;
671 hard_cfg[1] = 0;
673 hard_cfg[0] |= 0x20;
675 BLDIOBASE (hard_cfg[0], decoded_hcfg.iobase);
676 BLDWSSADDR(hard_cfg[0], decoded_hcfg.wssbase);
677 BLDMPUADDR(hard_cfg[0], decoded_hcfg.mpubase);
678 BLDJOY(hard_cfg[0], decoded_hcfg.joystick);
679 BLDCDROM(hard_cfg[1], decoded_hcfg.cdrom);
680 BLDCDROMADDR(hard_cfg[1], decoded_hcfg.cdrombase);
682 #if defined(AEDSP16_DEBUG)
683 aedsp16_pinfo();
684 #endif
686 DBG((" aedsp16_hard_encode: 0x%x, 0x%x\n", hard_cfg[0], hard_cfg[1]));
687 DBG(("success.\n"));
691 static int __init aedsp16_hard_write(int port) {
693 DBG(("aedsp16_hard_write:\n"));
695 if (aedsp16_write(port, COMMAND_6C)) {
696 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_6C);
697 DBG(("failure.\n"));
698 return FALSE;
700 if (aedsp16_write(port, COMMAND_5C)) {
701 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_5C);
702 DBG(("failure.\n"));
703 return FALSE;
705 if (aedsp16_write(port, hard_cfg[0])) {
706 printk("[AEDSP16] DATA 0x%x: failed!\n", hard_cfg[0]);
707 DBG(("failure.\n"));
708 return FALSE;
710 if (aedsp16_write(port, hard_cfg[1])) {
711 printk("[AEDSP16] DATA 0x%x: failed!\n", hard_cfg[1]);
712 DBG(("failure.\n"));
713 return FALSE;
715 if (aedsp16_write(port, COMMAND_C5)) {
716 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_C5);
717 DBG(("failure.\n"));
718 return FALSE;
721 DBG(("success.\n"));
723 return TRUE;
726 static int __init aedsp16_hard_read(int port) {
728 DBG(("aedsp16_hard_read:\n"));
730 if (aedsp16_write(port, READ_HARD_CFG)) {
731 printk("[AEDSP16] CMD 0x%x: failed!\n", READ_HARD_CFG);
732 DBG(("failure.\n"));
733 return FALSE;
736 if ((hard_cfg[0] = aedsp16_read(port)) == -1) {
737 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n",
738 READ_HARD_CFG);
739 DBG(("failure.\n"));
740 return FALSE;
742 if ((hard_cfg[1] = aedsp16_read(port)) == -1) {
743 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n",
744 READ_HARD_CFG);
745 DBG(("failure.\n"));
746 return FALSE;
748 if (aedsp16_read(port) == -1) {
749 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n",
750 READ_HARD_CFG);
751 DBG(("failure.\n"));
752 return FALSE;
755 DBG(("success.\n"));
757 return TRUE;
760 static int __init aedsp16_ext_cfg_write(int port) {
762 int extcfg, val;
764 if (aedsp16_write(port, COMMAND_66)) {
765 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_66);
766 return FALSE;
769 extcfg = 7;
770 if (decoded_hcfg.cdrom != 2)
771 extcfg = 0x0F;
772 if ((decoded_hcfg.cdrom == 4) ||
773 (decoded_hcfg.cdrom == 3))
774 extcfg &= ~2;
775 if (decoded_hcfg.cdrombase == 0)
776 extcfg &= ~2;
777 if (decoded_hcfg.mpubase == 0)
778 extcfg &= ~1;
780 if (aedsp16_write(port, extcfg)) {
781 printk("[AEDSP16] Write extcfg: failed!\n");
782 return FALSE;
784 if (aedsp16_write(port, 0)) {
785 printk("[AEDSP16] Write extcfg: failed!\n");
786 return FALSE;
788 if (decoded_hcfg.cdrom == 3) {
789 if (aedsp16_write(port, COMMAND_52)) {
790 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_52);
791 return FALSE;
793 if ((val = aedsp16_read(port)) == -1) {
794 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n"
795 , COMMAND_52);
796 return FALSE;
798 val &= 0x7F;
799 if (aedsp16_write(port, COMMAND_60)) {
800 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_60);
801 return FALSE;
803 if (aedsp16_write(port, val)) {
804 printk("[AEDSP16] Write val: failed!\n");
805 return FALSE;
809 return TRUE;
812 #endif /* CONFIG_SC6600 */
814 static int __init aedsp16_cfg_write(int port) {
815 if (aedsp16_write(port, WRITE_MDIRQ_CFG)) {
816 printk("[AEDSP16] CMD 0x%x: failed!\n", WRITE_MDIRQ_CFG);
817 return FALSE;
819 if (aedsp16_write(port, soft_cfg)) {
820 printk("[AEDSP16] Initialization of (M)IRQ and DMA: failed!\n");
821 return FALSE;
823 return TRUE;
826 static int __init aedsp16_init_mss(int port)
828 DBG(("aedsp16_init_mss:\n"));
830 mdelay(10);
832 if (aedsp16_write(port, DSP_INIT_MSS)) {
833 printk("[AEDSP16] aedsp16_init_mss [0x%x]: failed!\n",
834 DSP_INIT_MSS);
835 DBG(("failure.\n"));
836 return FALSE;
839 mdelay(10);
841 if (aedsp16_cfg_write(port) == FALSE)
842 return FALSE;
844 outb(soft_cfg_mss, ae_config.mss_base);
846 DBG(("success.\n"));
848 return TRUE;
851 static int __init aedsp16_setup_board(int port) {
852 int loop = RETRY;
854 #if defined(CONFIG_SC6600)
855 int val = 0;
857 if (aedsp16_hard_read(port) == FALSE) {
858 printk("[AEDSP16] aedsp16_hard_read: failed!\n");
859 return FALSE;
862 if (aedsp16_write(port, COMMAND_52)) {
863 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_52);
864 return FALSE;
867 if ((val = aedsp16_read(port)) == -1) {
868 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n",
869 COMMAND_52);
870 return FALSE;
872 #endif
874 do {
875 if (aedsp16_write(port, COMMAND_88)) {
876 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_88);
877 return FALSE;
879 mdelay(10);
880 } while ((aedsp16_wait_data(port) == FALSE) && loop--);
882 if (aedsp16_read(port) == -1) {
883 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n",
884 COMMAND_88);
885 return FALSE;
888 #if !defined(CONFIG_SC6600)
889 if (aedsp16_write(port, COMMAND_5C)) {
890 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_5C);
891 return FALSE;
893 #endif
895 if (aedsp16_cfg_write(port) == FALSE)
896 return FALSE;
898 #if defined(CONFIG_SC6600)
899 if (aedsp16_write(port, COMMAND_60)) {
900 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_60);
901 return FALSE;
903 if (aedsp16_write(port, val)) {
904 printk("[AEDSP16] DATA 0x%x: failed!\n", val);
905 return FALSE;
907 if (aedsp16_write(port, COMMAND_6E)) {
908 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_6E);
909 return FALSE;
911 if (aedsp16_write(port, ver[0])) {
912 printk("[AEDSP16] DATA 0x%x: failed!\n", ver[0]);
913 return FALSE;
915 if (aedsp16_write(port, ver[1])) {
916 printk("[AEDSP16] DATA 0x%x: failed!\n", ver[1]);
917 return FALSE;
920 if (aedsp16_hard_write(port) == FALSE) {
921 printk("[AEDSP16] aedsp16_hard_write: failed!\n");
922 return FALSE;
925 if (aedsp16_write(port, COMMAND_5C)) {
926 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_5C);
927 return FALSE;
930 #if defined(THIS_IS_A_THING_I_HAVE_NOT_TESTED_YET)
931 if (aedsp16_cfg_write(port) == FALSE)
932 return FALSE;
933 #endif
935 #endif
937 return TRUE;
940 static int __init aedsp16_stdcfg(int port) {
941 if (aedsp16_write(port, WRITE_MDIRQ_CFG)) {
942 printk("[AEDSP16] CMD 0x%x: failed!\n", WRITE_MDIRQ_CFG);
943 return FALSE;
946 * 0x0A == (IRQ 7, DMA 1, MIRQ 0)
948 if (aedsp16_write(port, 0x0A)) {
949 printk("[AEDSP16] aedsp16_stdcfg: failed!\n");
950 return FALSE;
952 return TRUE;
955 static int __init aedsp16_dsp_version(int port)
957 int len = 0;
958 int ret;
960 DBG(("Get DSP Version:\n"));
962 if (aedsp16_write(ae_config.base_io, GET_DSP_VERSION)) {
963 printk("[AEDSP16] CMD 0x%x: failed!\n", GET_DSP_VERSION);
964 DBG(("failed.\n"));
965 return FALSE;
968 do {
969 if ((ret = aedsp16_read(port)) == -1) {
970 DBG(("failed.\n"));
971 return FALSE;
974 * We already know how many int are stored (2), so we know when the
975 * string is finished.
977 ver[len++] = ret;
978 } while (len < CARDVERLEN);
979 sprintf(DSPVersion, "%d.%d", ver[0], ver[1]);
981 DBG(("success.\n"));
983 return TRUE;
986 static int __init aedsp16_dsp_copyright(int port)
988 int len = 0;
989 int ret;
991 DBG(("Get DSP Copyright:\n"));
993 if (aedsp16_write(ae_config.base_io, GET_DSP_COPYRIGHT)) {
994 printk("[AEDSP16] CMD 0x%x: failed!\n", GET_DSP_COPYRIGHT);
995 DBG(("failed.\n"));
996 return FALSE;
999 do {
1000 if ((ret = aedsp16_read(port)) == -1) {
1002 * If no more data available, return to the caller, no error if len>0.
1003 * We have no other way to know when the string is finished.
1005 if (len)
1006 break;
1007 else {
1008 DBG(("failed.\n"));
1009 return FALSE;
1013 DSPCopyright[len++] = ret;
1015 } while (len < CARDNAMELEN);
1017 DBG(("success.\n"));
1019 return TRUE;
1022 static void __init aedsp16_init_tables(void)
1024 int i = 0;
1026 memset(DSPCopyright, 0, CARDNAMELEN + 1);
1027 memset(DSPVersion, 0, CARDVERLEN + 1);
1029 for (i = 0; orIRQ[i].or; i++)
1030 if (orIRQ[i].val == ae_config.irq) {
1031 soft_cfg |= orIRQ[i].or;
1032 soft_cfg_mss |= orIRQ[i].or;
1035 for (i = 0; orMIRQ[i].or; i++)
1036 if (orMIRQ[i].or == ae_config.mpu_irq)
1037 soft_cfg |= orMIRQ[i].or;
1039 for (i = 0; orDMA[i].or; i++)
1040 if (orDMA[i].val == ae_config.dma) {
1041 soft_cfg |= orDMA[i].or;
1042 soft_cfg_mss |= orDMA[i].or;
1046 static int __init aedsp16_init_board(void)
1048 aedsp16_init_tables();
1050 if (aedsp16_dsp_reset(ae_config.base_io) == FALSE) {
1051 printk("[AEDSP16] aedsp16_dsp_reset: failed!\n");
1052 return FALSE;
1054 if (aedsp16_dsp_copyright(ae_config.base_io) == FALSE) {
1055 printk("[AEDSP16] aedsp16_dsp_copyright: failed!\n");
1056 return FALSE;
1060 * My AEDSP16 card return SC-6000 in DSPCopyright, so
1061 * if we have something different, we have to be warned.
1063 if (strcmp("SC-6000", DSPCopyright))
1064 printk("[AEDSP16] Warning: non SC-6000 audio card!\n");
1066 if (aedsp16_dsp_version(ae_config.base_io) == FALSE) {
1067 printk("[AEDSP16] aedsp16_dsp_version: failed!\n");
1068 return FALSE;
1071 if (aedsp16_stdcfg(ae_config.base_io) == FALSE) {
1072 printk("[AEDSP16] aedsp16_stdcfg: failed!\n");
1073 return FALSE;
1076 #if defined(CONFIG_SC6600)
1077 if (aedsp16_hard_read(ae_config.base_io) == FALSE) {
1078 printk("[AEDSP16] aedsp16_hard_read: failed!\n");
1079 return FALSE;
1082 aedsp16_hard_decode();
1084 aedsp16_hard_encode();
1086 if (aedsp16_hard_write(ae_config.base_io) == FALSE) {
1087 printk("[AEDSP16] aedsp16_hard_write: failed!\n");
1088 return FALSE;
1091 if (aedsp16_ext_cfg_write(ae_config.base_io) == FALSE) {
1092 printk("[AEDSP16] aedsp16_ext_cfg_write: failed!\n");
1093 return FALSE;
1095 #endif /* CONFIG_SC6600 */
1097 if (aedsp16_setup_board(ae_config.base_io) == FALSE) {
1098 printk("[AEDSP16] aedsp16_setup_board: failed!\n");
1099 return FALSE;
1102 if (ae_config.mss_base != -1) {
1103 if (ae_config.init & INIT_MSS) {
1104 if (aedsp16_init_mss(ae_config.base_io) == FALSE) {
1105 printk("[AEDSP16] Can not initialize"
1106 "Microsoft Sound System mode.\n");
1107 return FALSE;
1112 #if !defined(MODULE) || defined(AEDSP16_INFO) || defined(AEDSP16_DEBUG)
1114 printk("Audio Excel DSP 16 init v%s (%s %s) [",
1115 VERSION, DSPCopyright,
1116 DSPVersion);
1118 if (ae_config.mpu_base != -1) {
1119 if (ae_config.init & INIT_MPU401) {
1120 printk("MPU401");
1121 if ((ae_config.init & INIT_MSS) ||
1122 (ae_config.init & INIT_SBPRO))
1123 printk(" ");
1127 if (ae_config.mss_base == -1) {
1128 if (ae_config.init & INIT_SBPRO) {
1129 printk("SBPro");
1130 if (ae_config.init & INIT_MSS)
1131 printk(" ");
1135 if (ae_config.mss_base != -1)
1136 if (ae_config.init & INIT_MSS)
1137 printk("MSS");
1139 printk("]\n");
1140 #endif /* MODULE || AEDSP16_INFO || AEDSP16_DEBUG */
1142 mdelay(10);
1144 return TRUE;
1147 static int __init init_aedsp16_sb(void)
1149 DBG(("init_aedsp16_sb: "));
1152 * If the card is already init'ed MSS, we can not init it to SBPRO too
1153 * because the board can not emulate simultaneously MSS and SBPRO.
1155 if (ae_config.init & INIT_MSS)
1156 return FALSE;
1157 if (ae_config.init & INIT_SBPRO)
1158 return FALSE;
1160 ae_config.init |= INIT_SBPRO;
1162 DBG(("done.\n"));
1164 return TRUE;
1167 static void __init uninit_aedsp16_sb(void)
1169 DBG(("uninit_aedsp16_sb: "));
1171 ae_config.init &= ~INIT_SBPRO;
1173 DBG(("done.\n"));
1176 static int __init init_aedsp16_mss(void)
1178 DBG(("init_aedsp16_mss: "));
1181 * If the card is already init'ed SBPRO, we can not init it to MSS too
1182 * because the board can not emulate simultaneously MSS and SBPRO.
1184 if (ae_config.init & INIT_SBPRO)
1185 return FALSE;
1186 if (ae_config.init & INIT_MSS)
1187 return FALSE;
1189 * We must check the CONFIG_AEDSP16_BASE region too because these are the I/O
1190 * ports to access card's control registers.
1192 if (!(ae_config.init & INIT_MPU401)) {
1193 if (check_region(ae_config.base_io, IOBASE_REGION_SIZE)) {
1194 printk(
1195 "AEDSP16 BASE I/O port region is already in use.\n");
1196 return FALSE;
1201 * We must allocate the CONFIG_AEDSP16_BASE region too because these are the
1202 * I/O ports to access card's control registers.
1204 if (!(ae_config.init & INIT_MPU401))
1205 request_region(ae_config.base_io, IOBASE_REGION_SIZE,
1206 "aedsp16 (base)");
1208 ae_config.init |= INIT_MSS;
1210 DBG(("done.\n"));
1212 return TRUE;
1215 static void __init uninit_aedsp16_mss(void)
1217 DBG(("uninit_aedsp16_mss: "));
1219 if ((!(ae_config.init & INIT_MPU401)) &&
1220 (ae_config.init & INIT_MSS)) {
1221 release_region(ae_config.base_io, IOBASE_REGION_SIZE);
1222 DBG(("AEDSP16 base region released.\n"));
1225 ae_config.init &= ~INIT_MSS;
1226 DBG(("done.\n"));
1229 static int __init init_aedsp16_mpu(void)
1231 DBG(("init_aedsp16_mpu: "));
1233 if (ae_config.init & INIT_MPU401)
1234 return FALSE;
1237 * We must check the CONFIG_AEDSP16_BASE region too because these are the I/O
1238 * ports to access card's control registers.
1240 if (!(ae_config.init & (INIT_MSS | INIT_SBPRO))) {
1241 if (check_region(ae_config.base_io, IOBASE_REGION_SIZE)) {
1242 printk(
1243 "AEDSP16 BASE I/O port region is already in use.\n");
1244 return FALSE;
1248 if (!(ae_config.init & (INIT_MSS | INIT_SBPRO)))
1249 request_region(ae_config.base_io, IOBASE_REGION_SIZE,
1250 "aedsp16 (base)");
1252 ae_config.init |= INIT_MPU401;
1254 DBG(("done.\n"));
1256 return TRUE;
1259 static void __init uninit_aedsp16_mpu(void)
1261 DBG(("uninit_aedsp16_mpu: "));
1263 if ((!(ae_config.init & (INIT_MSS | INIT_SBPRO))) &&
1264 (ae_config.init & INIT_MPU401)) {
1265 release_region(ae_config.base_io, IOBASE_REGION_SIZE);
1266 DBG(("AEDSP16 base region released.\n"));
1269 ae_config.init &= ~INIT_MPU401;
1271 DBG(("done.\n"));
1274 int __init init_aedsp16(void)
1276 int initialized = FALSE;
1278 #if !defined(MODULE)
1279 ae_config.base_io = CONFIG_AEDSP16_BASE;
1280 #if defined(CONFIG_AEDSP16_SBPRO)
1281 ae_config.irq = CONFIG_AEDSP16_SB_IRQ;
1282 ae_config.dma = CONFIG_AEDSP16_SB_DMA;
1283 #endif
1284 #if defined(CONFIG_AEDSP16_MSS)
1285 ae_config.mss_base = CONFIG_MSS_BASE;
1286 ae_config.irq = CONFIG_AEDSP16_MSS_IRQ;
1287 ae_config.dma = CONFIG_AEDSP16_MSS_DMA;
1288 #endif
1289 #if defined(CONFIG_AEDSP16_MPU401)
1290 ae_config.mpu_base = CONFIG_MPU_BASE;
1291 ae_config.mpu_irq = CONFIG_AEDSP16_MPU_IRQ;
1292 #endif
1293 #endif /* !MODULE */
1294 DBG(("Initializing BASE[0x%x] IRQ[%d] DMA[%d] MIRQ[%d]\n",
1295 ae_config.base_io,ae_config.irq,ae_config.dma,ae_config.mpu_irq));
1297 if (ae_config.mss_base == -1) {
1298 if (init_aedsp16_sb() == FALSE) {
1299 uninit_aedsp16_sb();
1300 } else {
1301 initialized = TRUE;
1305 if (ae_config.mpu_base != -1) {
1306 if (init_aedsp16_mpu() == FALSE) {
1307 uninit_aedsp16_mpu();
1308 } else {
1309 initialized = TRUE;
1314 * In the sequence of init routines, the MSS init MUST be the last!
1315 * This because of the special register programming the MSS mode needs.
1316 * A board reset would disable the MSS mode restoring the default SBPRO
1317 * mode.
1319 if (ae_config.mss_base != -1) {
1320 if (init_aedsp16_mss() == FALSE) {
1321 uninit_aedsp16_mss();
1322 } else {
1323 initialized = TRUE;
1327 if (initialized)
1328 initialized = aedsp16_init_board();
1329 return initialized;
1332 void __init uninit_aedsp16(void)
1334 if (ae_config.mss_base != -1)
1335 uninit_aedsp16_mss();
1336 else
1337 uninit_aedsp16_sb();
1338 if (ae_config.mpu_base != -1)
1339 uninit_aedsp16_mpu();
1342 #if defined(MODULE)
1344 int io = -1;
1345 int irq = -1;
1346 int dma = -1;
1347 int mpu_irq = -1;
1348 int mss_base = -1;
1349 int mpu_base = -1;
1352 MODULE_PARM(io, "i");
1353 MODULE_PARM_DESC(io, "I/O base address (0x220 0x240)");
1354 MODULE_PARM(irq, "i");
1355 MODULE_PARM_DESC(irq, "IRQ line (5 7 9 10 11)");
1356 MODULE_PARM(dma, "i");
1357 MODULE_PARM_DESC(dma, "dma line (0 1 3)");
1358 MODULE_PARM(mpu_irq, "i");
1359 MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ line (5 7 9 10 0)");
1360 MODULE_PARM(mss_base, "i");
1361 MODULE_PARM_DESC(mss_base, "MSS emulation I/O base address (0x530 0xE80)");
1362 MODULE_PARM(mpu_base, "i");
1363 MODULE_PARM_DESC(mpu_base,"MPU-401 I/O base address (0x300 0x310 0x320 0x330)");
1364 MODULE_AUTHOR("Riccardo Facchetti <fizban@tin.it>");
1365 MODULE_DESCRIPTION("Audio Excel DSP 16 Driver Version " VERSION);
1367 int init_module(void) {
1368 printk("Audio Excel DSP 16 init driver Copyright (C) Riccardo Facchetti 1995-98\n");
1369 if (io == -1 || dma == -1 || irq == -1) {
1370 printk(KERN_INFO "aedsp16: I/O, IRQ and DMA are mandatory\n");
1371 return -EINVAL;
1374 ae_config.base_io = io;
1375 ae_config.irq = irq;
1376 ae_config.dma = dma;
1378 ae_config.mss_base = mss_base;
1379 ae_config.mpu_base = mpu_base;
1380 ae_config.mpu_irq = mpu_irq;
1382 if (init_aedsp16() == FALSE) {
1383 printk(KERN_ERR "aedsp16: initialization failed\n");
1385 * XXX
1386 * What error should we return here ?
1388 return -EINVAL;
1390 SOUND_LOCK;
1391 return 0;
1394 void cleanup_module(void) {
1395 uninit_aedsp16();
1396 SOUND_LOCK_END;
1398 #endif /* MODULE */
1400 #endif /* CONFIG_AEDSP16 */