Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / sys / dev / sound / isa / i386 / css / cs4232.c
1 /*
2  * sound/cs4232.c
3  * 
4  * The low level driver for Crystal CS4232 based cards. The CS4232 is a PnP
5  * compatible chip which contains a CS4231A codec, SB emulation, a MPU401
6  * compatible MIDI port, joystick and synthesizer and IDE CD-ROM interfaces.
7  * This is just a temporary driver until full PnP support gets inplemented.
8  * Just the WSS codec, FM synth and the MIDI ports are supported. Other
9  * interfaces are left uninitialized.
10  * 
11  * Copyright by Hannu Savolainen 1995
12  * 
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions are
15  * met: 1. Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer. 2.
17  * Redistributions in binary form must reproduce the above copyright notice,
18  * this list of conditions and the following disclaimer in the documentation
19  * and/or other materials provided with the distribution.
20  * 
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
22  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
25  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  * 
33  * $FreeBSD: src/sys/i386/isa/sound/cs4232.c,v 1.6 2000/01/24 08:16:15 bde Exp $
34  * $DragonFly: src/sys/dev/sound/isa/i386/css/Attic/cs4232.c,v 1.2 2003/06/17 04:28:38 dillon Exp $
35  */
36
37 #include <i386/isa/sound/sound_config.h>
38
39 #if defined(CONFIG_CS4232)
40
41 #define KEY_PORT        0x279   /* Same as LPT1 status port */
42 #define CSN_NUM         0x99    /* Just a random number */
43
44 #define CS_OUT(a)               outb( KEY_PORT,  a)
45 #define CS_OUT2(a, b)           {CS_OUT(a);CS_OUT(b);}
46 #define CS_OUT3(a, b, c)        {CS_OUT(a);CS_OUT(b);CS_OUT(c);}
47
48 static int      mpu_base = 0, mpu_irq = 0;
49
50 int
51 probe_cs4232_mpu(struct address_info * hw_config)
52 {
53     /*
54      * Just write down the config values.
55      */
56
57     mpu_base = hw_config->io_base;
58     mpu_irq = hw_config->irq;
59     return 0;
60 }
61
62 void
63 attach_cs4232_mpu(struct address_info * hw_config)
64 {
65 }
66
67 static unsigned char crystal_key[] =    /* A 32 byte magic key sequence */
68 {
69     0x96, 0x35, 0x9a, 0xcd, 0xe6, 0xf3, 0x79, 0xbc,
70     0x5e, 0xaf, 0x57, 0x2b, 0x15, 0x8a, 0xc5, 0xe2,
71     0xf1, 0xf8, 0x7c, 0x3e, 0x9f, 0x4f, 0x27, 0x13,
72     0x09, 0x84, 0x42, 0xa1, 0xd0, 0x68, 0x34, 0x1a
73 };
74
75 int
76 probe_cs4232(struct address_info * hw_config)
77 {
78     int             i;
79     int             base = hw_config->io_base, irq = hw_config->irq;
80     int             dma1 = hw_config->dma, dma2 = hw_config->dma2;
81
82     /*
83      * Verify that the I/O port range is free.
84      */
85
86     if (0) {
87         printf("cs4232.c: I/O port 0x%03x not free\n", base);
88         return 0;
89     }
90     /*
91      * This version of the driver doesn't use the PnP method when
92      * configuring the card but a simplified method defined by Crystal.
93      * This means that just one CS4232 compatible device can exist on the
94      * system. Also this method conflicts with possible PnP support in
95      * the OS. For this reason driver is just a temporary kludge.
96      */
97
98     /*
99      * Wake up the card by sending a 32 byte Crystal key to the key port.
100      */
101     for (i = 0; i < 32; i++)
102         CS_OUT(crystal_key[i]);
103
104     /*
105      * Now set the CSN (Card Select Number).
106      */
107
108     CS_OUT2(0x06, CSN_NUM);
109
110     /*
111      * Ensure that there is no other codec using the same address.
112      */
113
114     CS_OUT2(0x15, 0x00);        /* Select logical device 0 (WSS/SB/FM) */
115     CS_OUT2(0x33, 0x00);        /* Inactivate logical dev 0 */
116
117     /*
118      * Then set some config bytes. First logical device 0
119      */
120
121     CS_OUT2(0x15, 0x00);        /* Select logical device 0 (WSS/SB/FM) */
122     CS_OUT3(0x47, (base >> 8) & 0xff, base & 0xff);     /* WSSbase */
123
124     if (0)                      /* Not free */
125         CS_OUT3(0x48, 0x00, 0x00)       /* FMbase off */
126     else
127         CS_OUT3(0x48, 0x03, 0x88);      /* FMbase 0x388 */
128
129     CS_OUT3(0x42, 0x00, 0x00);  /* SBbase off */
130     CS_OUT2(0x22, irq); /* SB+WSS IRQ */
131     CS_OUT2(0x2a, dma1);        /* SB+WSS DMA */
132
133     if (dma2 != -1)
134         CS_OUT2(0x25, dma2)     /* WSS DMA2 */
135     else
136         CS_OUT2(0x25, 4);       /* No WSS DMA2 */
137
138     CS_OUT2(0x33, 0x01);        /* Activate logical dev 0 */
139
140     /*
141      * Initialize logical device 3 (MPU)
142      */
143
144 #if (defined(CONFIG_MPU401) || defined(CONFIG_MPU_EMU)) && defined(CONFIG_MIDI)
145     if (mpu_base != 0 && mpu_irq != 0) {
146         CS_OUT2(0x15, 0x03);    /* Select logical device 3 (MPU) */
147         CS_OUT3(0x47, (mpu_base >> 8) & 0xff, mpu_base & 0xff); /* MPUbase */
148         CS_OUT2(0x22, mpu_irq); /* MPU IRQ */
149         CS_OUT2(0x33, 0x01);    /* Activate logical dev 3 */
150     }
151 #endif
152
153     /*
154      * Finally activate the chip
155      */
156     CS_OUT(0x79);
157
158     /*
159      * Then try to detect the codec part of the chip
160      */
161
162     return ad1848_detect(hw_config->io_base, NULL, hw_config->osp);
163 }
164
165 void
166 attach_cs4232(struct address_info * hw_config)
167 {
168     int             base = hw_config->io_base, irq = hw_config->irq;
169     int             dma1 = hw_config->dma, dma2 = hw_config->dma2;
170
171     if (dma2 == -1)
172         dma2 = dma1;
173
174     ad1848_init("CS4232", base,
175         irq,
176         dma1,   /* Playback DMA */
177         dma2,   /* Capture DMA */
178         0,
179         hw_config->osp);
180
181 #if (defined(CONFIG_MPU401) || defined(CONFIG_MPU_EMU)) && defined(CONFIG_MIDI)
182     if (mpu_base != 0 && mpu_irq != 0) {
183         static struct address_info hw_config2 =
184         {0};            /* Ensure it's initialized */
185
186         hw_config2.io_base = mpu_base;
187         hw_config2.irq = mpu_irq;
188         hw_config2.dma = -1;
189         hw_config2.dma2 = -1;
190         hw_config2.always_detect = 0;
191         hw_config2.name = NULL;
192         hw_config2.card_subtype = 0;
193         hw_config2.osp = hw_config->osp;
194
195         if (probe_mpu401(&hw_config2))
196             attach_mpu401(&hw_config2);
197         else
198             mpu_base = mpu_irq = 0;
199     }
200 #endif
201 }
202
203 #endif