diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1999-03-04 08:57:35 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1999-03-04 08:57:35 +0000 |
commit | 8cdf1684b0abda316c7352be3b1a6c5e96a0f24c (patch) | |
tree | 3f0d0217d2caf917b9b3d2081629e6c30c637f0e /sys | |
parent | 799ffd7275d2c8f9e1ccd1eee324be9d411a5d78 (diff) |
cs4232 hack
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/isa/cs4232.c | 179 | ||||
-rw-r--r-- | sys/dev/isa/cs4232.h | 5 | ||||
-rw-r--r-- | sys/dev/isa/files.isapnp | 3 | ||||
-rw-r--r-- | sys/dev/isa/isapnp.c | 41 |
4 files changed, 226 insertions, 2 deletions
diff --git a/sys/dev/isa/cs4232.c b/sys/dev/isa/cs4232.c new file mode 100644 index 00000000000..b1419747888 --- /dev/null +++ b/sys/dev/isa/cs4232.c @@ -0,0 +1,179 @@ +/* + * ISA PnP bus autoconfiguration. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/device.h> +#include <sys/malloc.h> + +#include <machine/bus.h> + + +#include <dev/isa/isavar.h> +#include <dev/isa/isadmavar.h> + +#include "cs4232.h" + +#ifdef CONFIG_CS4232 +int probe_cs4232 __P((void)); + +/* a note about the CS4232 stuff. its really pretty bad. if you dont have a + * CS4232 or compatible then you should really (really) turn off CONFIG_CS4232. + * i dont THINK that this will do any damage, but who knows? its really a + * bad fix. (also note, in order for it to work it assumes that you have a + * io port 534-537 clear as well as irq 5 and dma 0,1 all free. + * this is all really lousy also. if it crashes your machine, sorry. + */ + +/* + * sound/cs4232.c + * + * The low level driver for Crystal CS4232 based cards. The CS4232 is a PnP + * compatible chip which contains a CS4231A codec, SB emulation, a MPU401 + * compatible MIDI port, joystick and synthesizer and IDE CD-ROM interfaces. + * This is just a temporary driver until full PnP support gets inplemented. + * Just the WSS codec, FM synth and the MIDI ports are supported. Other + * interfaces are left uninitialized. + * + * Copyright by Hannu Savolainen 1995 + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. 2. + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + + + +#define KEY_PORT 0x279 /* Same as LPT1 status port */ +#define CSN_NUM 0x01 /* Just a random number */ + +#define CS_OUT(a) outb( KEY_PORT, a) +#define CS_OUT2(a, b) {CS_OUT(a);CS_OUT(b);} +#define CS_OUT3(a, b, c) {CS_OUT(a);CS_OUT(b);CS_OUT(c);} + + + +static unsigned char crystal_key[] = /* A 32 byte magic key sequence */ +{ + 0x96, 0x35, 0x9a, 0xcd, 0xe6, 0xf3, 0x79, 0xbc, + 0x5e, 0xaf, 0x57, 0x2b, 0x15, 0x8a, 0xc5, 0xe2, + 0xf1, 0xf8, 0x7c, 0x3e, 0x9f, 0x4f, 0x27, 0x13, + 0x09, 0x84, 0x42, 0xa1, 0xd0, 0x68, 0x34, 0x1a +}; + +int +probe_cs4232(void) +{ + int i; + + /* + * Verify that the I/O port range is free. + */ + + if (0) { + printf("cs4232.c: I/O port 0x534 not free\n"); + return 0; + } + /* + * This version of the driver doesn't use the PnP method when + * configuring the card but a simplified method defined by Crystal. + * This means that just one CS4232 compatible device can exist on the + * system. Also this method conflicts with possible PnP support in + * the OS. For this reason driver is just a temporary kludge. + */ + + /* + * Wake up the card by sending a 32 byte Crystal key to the key port. + */ + for (i = 0; i < 32; i++) + CS_OUT(crystal_key[i]); + + /* + * Now set the CSN (Card Select Number). + */ + +/* CS_OUT2(0x06, 0x01); */ + + /* + * Ensure that there is no other codec using the same address. + */ + + CS_OUT2(0x15, 0x00); /* Select logical device 0 (WSS/SB/FM) */ + + /* + * Then set some config bytes. First logical device 0 + */ + + CS_OUT3(0x47, 0x05, 0x34); /* WSSbase */ + + if (0) /* Not free */ + CS_OUT3(0x48, 0x03, 0x88) /* FMbase off */ + else + CS_OUT3(0x48, 0x03, 0x88); /* FMbase 0x388 */ + + CS_OUT3(0x42, 0x02, 0x20); /* SBbase off */ + CS_OUT2(0x22, 0x05); /* SB+WSS IRQ */ + CS_OUT2(0x2a, 0x01); /* SB+WSS DMA */ + + if (0) + CS_OUT2(0x25, 0x00) /* WSS DMA2 */ + else + CS_OUT2(0x25, 0x00); /* No WSS DMA2 */ + + CS_OUT2(0x33, 0x01); /* Activate logical dev 0 */ + +/* + * init logical device 2... + * + */ + CS_OUT2(0x15,0x02); + CS_OUT3(0x47,0x01,0x20); + CS_OUT2(0x33,0x01); + + +/* +* Initialize logical device 3 (MPU) +*/ + +#if (defined(CONFIG_MPU401) || defined(CONFIG_MPU_EMU)) && defined(CONFIG_MIDI) + if (mpu_base != 0 && mpu_irq != 0) { + CS_OUT2(0x15, 0x03); /* Select logical device 3 (MPU) */ + CS_OUT3(0x47, (mpu_base >> 8) & 0xff, mpu_base & 0xff); /* MPUbase */ + CS_OUT2(0x22, mpu_irq); /* MPU IRQ */ + CS_OUT2(0x33, 0x01); /* Activate logical dev 3 */ +} +#endif + +/* +* Finally activate the chip +*/ + CS_OUT(0x79); + +/* +* Then try to detect the codec part of the chip +*/ + delay(15000); + + outb(0x534,0x40); /* this seems to be needed... */ + return 1; +} + +#endif diff --git a/sys/dev/isa/cs4232.h b/sys/dev/isa/cs4232.h new file mode 100644 index 00000000000..8180eef23c9 --- /dev/null +++ b/sys/dev/isa/cs4232.h @@ -0,0 +1,5 @@ +/* $OpenBSD: cs4232.h,v 1.1 1999/03/04 08:57:34 deraadt Exp $ */ + +#ifdef CONFIG_CS4232 +int probe_cs4232 __P((void)); +#endif diff --git a/sys/dev/isa/files.isapnp b/sys/dev/isa/files.isapnp index 0387427240a..5da8da7a42e 100644 --- a/sys/dev/isa/files.isapnp +++ b/sys/dev/isa/files.isapnp @@ -1,4 +1,4 @@ -# $OpenBSD: files.isapnp,v 1.12 1999/03/02 08:12:45 deraadt Exp $ +# $OpenBSD: files.isapnp,v 1.13 1999/03/04 08:57:34 deraadt Exp $ # $NetBSD: files.isapnp,v 1.7 1997/10/16 17:16:36 matt Exp $ # # Config file and device description for machine-independent ISAPnP code. @@ -28,6 +28,7 @@ file dev/isa/sb_isapnp.c sb & (sb_isa | sb_isapnp) needs-flag attach wss at isapnp with wss_isapnp file dev/isa/wss_isapnp.c wss & (wss_isa | wss_isapnp) needs-flag +file dev/isa/cs4232.c wss_isapnp attach le at isapnp with le_isapnp file dev/isa/if_le_isapnp.c le_isapnp diff --git a/sys/dev/isa/isapnp.c b/sys/dev/isa/isapnp.c index e9b8dabaee9..79bc15688a7 100644 --- a/sys/dev/isa/isapnp.c +++ b/sys/dev/isa/isapnp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: isapnp.c,v 1.23 1999/01/11 01:57:53 millert Exp $ */ +/* $OpenBSD: isapnp.c,v 1.24 1999/03/04 08:57:34 deraadt Exp $ */ /* $NetBSD: isapnp.c,v 1.9.4.3 1997/10/29 00:40:43 thorpej Exp $ */ /* @@ -48,6 +48,10 @@ #include <dev/isa/pnpdevs.h> +#ifdef CONFIG_CS4232 +#include <dev/isa/cs4232.h> +#endif + void isapnp_init __P((struct isapnp_softc *)); static __inline u_char isapnp_shift_bit __P((struct isapnp_softc *)); int isapnp_findcard __P((struct isapnp_softc *)); @@ -813,6 +817,38 @@ isapnp_isa_attach_hook(isa_sc) if (isapnp_map(&sc)) return; +#ifdef CONFIG_CS4232 + /* + * XXX XXX + * This a totally disgusting hack, but I can't figure out another way. + * It seems that many CS audio chips have a bug (as far as I can + * understand). The reset below does not really reset the chip, it + * remains in a catatonic state and will not respond when probed. + * The chip can be used both as a WSS and as a SB device, and a + * single read at the WSS address (0x534) takes it out of this + * non-responsive state. + * The read has to happen at this point in time (or earlier) so + * it cannot be moved to the wss_isapnp.c driver. + * (BTW, We're not alone in having problems with these chips: + * Windoze 98 couldn't detect the sound chip on a Dell when I tried.) + * + * Lennart Augustsson <augustss@netbsd.org> + * + * (Implementation from John Kohl <jtk@kolvir.arlington.ma.us>) + */ + { + bus_space_handle_t ioh; + int rv; + + if ((rv = bus_space_map(sc.sc_iot, 0x534, 1, 0, &ioh)) == 0) { + DPRINTF(("wss probe kludge\n")); + (void)bus_space_read_1(sc.sc_iot, ioh, 0); + bus_space_unmap(sc.sc_iot, ioh, 1); + } else { + DPRINTF(("wss probe kludge failed to map: %d\n", rv)); + } + } +#endif isapnp_init(&sc); isapnp_write_reg(&sc, ISAPNP_CONFIG_CONTROL, ISAPNP_CC_RESET_DRV); @@ -838,6 +874,9 @@ isapnp_match(parent, match, aux) sc.sc_ncards = 0; (void) strcpy(sc.sc_dev.dv_xname, "(isapnp probe)"); +#ifdef CONFIG_CS4232 + probe_cs4232(); +#endif if (isapnp_map(&sc)) return 0; |