2 * Copyright (C) by Hannu Savolainen 1993-1997
6 * The low level driver for Crystal CS4232 based cards. The CS4232 is
7 * a PnP compatible chip which contains a CS4231A codec, SB emulation,
8 * a MPU401 compatible MIDI port, joystick and synthesizer and IDE CD-ROM
9 * interfaces. This is just a temporary driver until full PnP support
10 * gets implemented. Just the WSS codec, FM synth and the MIDI ports are
11 * supported. Other interfaces are left uninitialized.
13 * ifdef ...WAVEFRONT...
15 * Support is provided for initializing the WaveFront synth
16 * interface as well, which is logical device #4. Note that if
17 * you have a Tropez+ card, you probably don't need to setup
18 * the CS4232-supported MIDI interface, since it corresponds to
19 * the internal 26-pin header that's hard to access. Using this
20 * requires an additional IRQ, a resource none too plentiful in
21 * this environment. Just don't set module parameters mpuio and
22 * mpuirq, and the MIDI port will be left uninitialized. You can
23 * still use the ICS2115 hosted MIDI interface which corresponds
24 * to the 9-pin D connector on the back of the card.
26 * endif ...WAVEFRONT...
28 * Supported chips are:
33 * Note: You will need a PnP config setup to initialise some CS4232 boards
37 * Alan Cox Modularisation, Basic cleanups.
38 * Paul Barton-Davis Separated MPU configuration, added
39 * Tropez+ (WaveFront) support
40 * Christoph Hellwig Adapted to module_init/module_exit,
44 #include <linux/config.h>
45 #include <linux/module.h>
46 #include <linux/init.h>
48 #include "sound_config.h"
49 #include "soundmodule.h"
55 #define KEY_PORT 0x279 /* Same as LPT1 status port */
56 #define CSN_NUM 0x99 /* Just a random number */
58 static void CS_OUT(unsigned char a
)
63 #define CS_OUT2(a, b) {CS_OUT(a);CS_OUT(b);}
64 #define CS_OUT3(a, b, c) {CS_OUT(a);CS_OUT(b);CS_OUT(c);}
66 static int mpu_base
= 0, mpu_irq
= 0;
67 static int synth_base
= 0, synth_irq
= 0;
68 static int mpu_detected
= 0;
70 int probe_cs4232_mpu(struct address_info
*hw_config
)
73 * Just write down the config values.
76 mpu_base
= hw_config
->io_base
;
77 mpu_irq
= hw_config
->irq
;
82 static unsigned char crystal_key
[] = /* A 32 byte magic key sequence */
84 0x96, 0x35, 0x9a, 0xcd, 0xe6, 0xf3, 0x79, 0xbc,
85 0x5e, 0xaf, 0x57, 0x2b, 0x15, 0x8a, 0xc5, 0xe2,
86 0xf1, 0xf8, 0x7c, 0x3e, 0x9f, 0x4f, 0x27, 0x13,
87 0x09, 0x84, 0x42, 0xa1, 0xd0, 0x68, 0x34, 0x1a
90 static void sleep(unsigned howlong
)
92 current
->state
= TASK_INTERRUPTIBLE
;
93 schedule_timeout(howlong
);
96 int probe_cs4232(struct address_info
*hw_config
)
99 int base
= hw_config
->io_base
, irq
= hw_config
->irq
;
100 int dma1
= hw_config
->dma
, dma2
= hw_config
->dma2
;
103 * Verify that the I/O port range is free.
106 if (check_region(base
, 4))
108 printk(KERN_ERR
"cs4232.c: I/O port 0x%03x not free\n", base
);
111 if (ad1848_detect(hw_config
->io_base
, NULL
, hw_config
->osp
))
112 return 1; /* The card is already active */
115 * This version of the driver doesn't use the PnP method when configuring
116 * the card but a simplified method defined by Crystal. This means that
117 * just one CS4232 compatible device can exist on the system. Also this
118 * method conflicts with possible PnP support in the OS. For this reason
119 * driver is just a temporary kludge.
121 * Also the Cirrus/Crystal method doesnt always work. Try ISA PnP first ;)
125 * Repeat initialization few times since it doesn't always succeed in
129 for (n
= 0; n
< 4; n
++)
132 * Wake up the card by sending a 32 byte Crystal key to the key port.
135 for (i
= 0; i
< 32; i
++)
136 CS_OUT(crystal_key
[i
]);
141 * Now set the CSN (Card Select Number).
144 CS_OUT2(0x06, CSN_NUM
);
147 * Then set some config bytes. First logical device 0
150 CS_OUT2(0x15, 0x00); /* Select logical device 0 (WSS/SB/FM) */
151 CS_OUT3(0x47, (base
>> 8) & 0xff, base
& 0xff); /* WSS base */
153 if (check_region(0x388, 4)) /* Not free */
154 CS_OUT3(0x48, 0x00, 0x00) /* FM base off */
156 CS_OUT3(0x48, 0x03, 0x88); /* FM base 0x388 */
158 CS_OUT3(0x42, 0x00, 0x00); /* SB base off */
159 CS_OUT2(0x22, irq
); /* SB+WSS IRQ */
160 CS_OUT2(0x2a, dma1
); /* SB+WSS DMA */
163 CS_OUT2(0x25, dma2
) /* WSS DMA2 */
165 CS_OUT2(0x25, 4); /* No WSS DMA2 */
167 CS_OUT2(0x33, 0x01); /* Activate logical dev 0 */
172 * Initialize logical device 3 (MPU)
175 if (mpu_base
!= 0 && mpu_irq
!= 0)
177 CS_OUT2(0x15, 0x03); /* Select logical device 3 (MPU) */
178 CS_OUT3(0x47, (mpu_base
>> 8) & 0xff, mpu_base
& 0xff); /* MPU base */
179 CS_OUT2(0x22, mpu_irq
); /* MPU IRQ */
180 CS_OUT2(0x33, 0x01); /* Activate logical dev 3 */
185 CS_OUT2 (0x15, 0x04); /* logical device 4 (WaveFront) */
186 CS_OUT3 (0x47, (synth_base
>> 8) & 0xff,
187 synth_base
& 0xff); /* base */
188 CS_OUT2 (0x22, synth_irq
); /* IRQ */
189 CS_OUT2 (0x33, 0x01); /* Activate logical dev 4 */
193 * Finally activate the chip
201 * Then try to detect the codec part of the chip
204 if (ad1848_detect(hw_config
->io_base
, NULL
, hw_config
->osp
))
212 void attach_cs4232(struct address_info
*hw_config
)
214 int base
= hw_config
->io_base
,
215 irq
= hw_config
->irq
,
216 dma1
= hw_config
->dma
,
217 dma2
= hw_config
->dma2
;
219 if (base
== -1 || irq
== -1 || dma1
== -1) {
220 printk(KERN_ERR
"cs4232: dma, irq and io must be set.\n");
227 hw_config
->slots
[0] = ad1848_init("Crystal audio controller", base
,
229 dma1
, /* Playback DMA */
230 dma2
, /* Capture DMA */
234 if (hw_config
->slots
[0] != -1 &&
235 audio_devs
[hw_config
->slots
[0]]->mixer_dev
!=-1)
237 /* Assume the mixer map is as suggested in the CS4232 databook */
238 AD1848_REROUTE(SOUND_MIXER_LINE1
, SOUND_MIXER_LINE
);
239 AD1848_REROUTE(SOUND_MIXER_LINE2
, SOUND_MIXER_CD
);
240 AD1848_REROUTE(SOUND_MIXER_LINE3
, SOUND_MIXER_SYNTH
); /* FM synth */
242 if (mpu_base
!= 0 && mpu_irq
!= 0)
244 static struct address_info hw_config2
= {
246 }; /* Ensure it's initialized */
248 hw_config2
.io_base
= mpu_base
;
249 hw_config2
.irq
= mpu_irq
;
251 hw_config2
.dma2
= -1;
252 hw_config2
.always_detect
= 0;
253 hw_config2
.name
= NULL
;
254 hw_config2
.driver_use_1
= 0;
255 hw_config2
.driver_use_2
= 0;
256 hw_config2
.card_subtype
= 0;
258 if (probe_uart401(&hw_config2
))
261 attach_uart401(&hw_config2
);
265 mpu_base
= mpu_irq
= 0;
267 hw_config
->slots
[1] = hw_config2
.slots
[1];
272 void unload_cs4232(struct address_info
*hw_config
)
274 int base
= hw_config
->io_base
, irq
= hw_config
->irq
;
275 int dma1
= hw_config
->dma
, dma2
= hw_config
->dma2
;
282 dma1
, /* Playback DMA */
283 dma2
, /* Capture DMA */
286 sound_unload_audiodev(hw_config
->slots
[0]);
287 if (mpu_base
!= 0 && mpu_irq
!= 0 && mpu_detected
)
289 static struct address_info hw_config2
=
292 }; /* Ensure it's initialized */
294 hw_config2
.io_base
= mpu_base
;
295 hw_config2
.irq
= mpu_irq
;
297 hw_config2
.dma2
= -1;
298 hw_config2
.always_detect
= 0;
299 hw_config2
.name
= NULL
;
300 hw_config2
.driver_use_1
= 0;
301 hw_config2
.driver_use_2
= 0;
302 hw_config2
.card_subtype
= 0;
303 hw_config2
.slots
[1] = hw_config
->slots
[1];
305 unload_uart401(&hw_config2
);
309 static struct address_info cfg
;
310 static struct address_info cfg_mpu
;
312 static int __initdata io
= -1;
313 static int __initdata irq
= -1;
314 static int __initdata dma
= -1;
315 static int __initdata dma2
= -1;
316 static int __initdata mpuio
= -1;
317 static int __initdata mpuirq
= -1;
318 static int __initdata synthio
= -1;
319 static int __initdata synthirq
= -1;
323 MODULE_PARM(irq
,"i");
324 MODULE_PARM(dma
,"i");
325 MODULE_PARM(dma2
,"i");
326 MODULE_PARM(mpuio
,"i");
327 MODULE_PARM(mpuirq
,"i");
328 MODULE_PARM(synthio
,"i");
329 MODULE_PARM(synthirq
,"i");
332 * Install a CS4232 based card. Need to have ad1848 and mpu401
336 static int __init
init_cs4232(void)
338 #ifdef CONFIG_SOUND_WAVEFRONT_MODULE
340 printk(KERN_WARNING
"cs4232: set synthio and synthirq to use the wavefront facilities.\n");
342 synth_base
= synthio
;
343 synth_irq
= synthirq
;
347 printk(KERN_WARNING
"cs4232: wavefront support not enabled in this driver.\n");
349 if(io
==-1||irq
==-1||dma
==-1)
351 printk(KERN_ERR
"cs4232: Must set io, irq and dma.\n");
360 cfg_mpu
.io_base
= -1;
363 if (mpuio
!= -1 && mpuirq
!= -1) {
364 cfg_mpu
.io_base
= mpuio
;
365 cfg_mpu
.irq
= mpuirq
;
366 probe_cs4232_mpu(&cfg_mpu
); /* Bug always returns 0 not OK -- AC */
369 if (probe_cs4232(&cfg
) == 0)
376 static void __exit
cleanup_cs4232(void)
378 unload_cs4232(&cfg
); /* unloads MPU as well, if needed */
382 module_init(init_cs4232
);
383 module_exit(cleanup_cs4232
);
386 static int __init
setup_cs4232(char *str
)
388 /* io, irq, dma, dma2 mpuio, mpuirq*/
391 str
= get_options(str
, ARRAY_SIZE(ints
), ints
);
403 __setup("cs4232=", setup_cs4232
);