Import 2.3.18pre1
[davej-history.git] / drivers / sound / cs4232.c
blob11feddcccb0bc3bd9c425c35d4cc28bfa267bbcb
1 /*
2 * sound/cs4232.c
4 * The low level driver for Crystal CS4232 based cards. The CS4232 is
5 * a PnP compatible chip which contains a CS4231A codec, SB emulation,
6 * a MPU401 compatible MIDI port, joystick and synthesizer and IDE CD-ROM
7 * interfaces. This is just a temporary driver until full PnP support
8 * gets implemented. Just the WSS codec, FM synth and the MIDI ports are
9 * supported. Other interfaces are left uninitialized.
11 * ifdef ...WAVEFRONT...
13 * Support is provided for initializing the WaveFront synth
14 * interface as well, which is logical device #4. Note that if
15 * you have a Tropez+ card, you probably don't need to setup
16 * the CS4232-supported MIDI interface, since it corresponds to
17 * the internal 26-pin header that's hard to access. Using this
18 * requires an additional IRQ, a resource none too plentiful in
19 * this environment. Just don't set module parameters mpuio and
20 * mpuirq, and the MIDI port will be left uninitialized. You can
21 * still use the ICS2115 hosted MIDI interface which corresponds
22 * to the 9-pin D connector on the back of the card.
24 * endif ...WAVEFRONT...
26 * Supported chips are:
27 * CS4232
28 * CS4236
29 * CS4236B
31 * Note: You will need a PnP config setup to initialise some CS4232 boards
32 * anyway.
34 * Changes
35 * Alan Cox Modularisation, Basic cleanups.
36 * Paul Barton-Davis Separated MPU configuration, added
37 * Tropez+ (WaveFront) support
41 * Copyright (C) by Hannu Savolainen 1993-1997
43 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
44 * Version 2 (June 1991). See the "COPYING" file distributed with this software
45 * for more info.
48 #include <linux/config.h>
49 #include <linux/module.h>
51 #include "sound_config.h"
52 #include "soundmodule.h"
54 #define KEY_PORT 0x279 /* Same as LPT1 status port */
55 #define CSN_NUM 0x99 /* Just a random number */
57 static void CS_OUT(unsigned char a)
59 outb(a, KEY_PORT);
62 #define CS_OUT2(a, b) {CS_OUT(a);CS_OUT(b);}
63 #define CS_OUT3(a, b, c) {CS_OUT(a);CS_OUT(b);CS_OUT(c);}
65 static int mpu_base = 0, mpu_irq = 0;
66 static int synth_base = 0, synth_irq = 0;
67 static int mpu_detected = 0;
69 int probe_cs4232_mpu(struct address_info *hw_config)
72 * Just write down the config values.
75 mpu_base = hw_config->io_base;
76 mpu_irq = hw_config->irq;
78 return 1;
81 void attach_cs4232_mpu(struct address_info *hw_config)
83 /* Nothing needs doing */
86 static unsigned char crystal_key[] = /* A 32 byte magic key sequence */
88 0x96, 0x35, 0x9a, 0xcd, 0xe6, 0xf3, 0x79, 0xbc,
89 0x5e, 0xaf, 0x57, 0x2b, 0x15, 0x8a, 0xc5, 0xe2,
90 0xf1, 0xf8, 0x7c, 0x3e, 0x9f, 0x4f, 0x27, 0x13,
91 0x09, 0x84, 0x42, 0xa1, 0xd0, 0x68, 0x34, 0x1a
94 static void sleep(unsigned howlong)
96 current->state = TASK_INTERRUPTIBLE;
97 schedule_timeout(howlong);
100 int probe_cs4232(struct address_info *hw_config)
102 int i, n;
103 int base = hw_config->io_base, irq = hw_config->irq;
104 int dma1 = hw_config->dma, dma2 = hw_config->dma2;
107 * Verify that the I/O port range is free.
110 if (check_region(base, 4))
112 printk(KERN_ERR "cs4232.c: I/O port 0x%03x not free\n", base);
113 return 0;
115 if (ad1848_detect(hw_config->io_base, NULL, hw_config->osp))
116 return 1; /* The card is already active */
119 * This version of the driver doesn't use the PnP method when configuring
120 * the card but a simplified method defined by Crystal. This means that
121 * just one CS4232 compatible device can exist on the system. Also this
122 * method conflicts with possible PnP support in the OS. For this reason
123 * driver is just a temporary kludge.
125 * Also the Cirrus/Crystal method doesnt always work. Try ISA PnP first ;)
129 * Repeat initialization few times since it doesn't always succeed in
130 * first time.
133 for (n = 0; n < 4; n++)
136 * Wake up the card by sending a 32 byte Crystal key to the key port.
139 for (i = 0; i < 32; i++)
140 CS_OUT(crystal_key[i]);
142 sleep(HZ / 10);
145 * Now set the CSN (Card Select Number).
148 CS_OUT2(0x06, CSN_NUM);
151 * Then set some config bytes. First logical device 0
154 CS_OUT2(0x15, 0x00); /* Select logical device 0 (WSS/SB/FM) */
155 CS_OUT3(0x47, (base >> 8) & 0xff, base & 0xff); /* WSS base */
157 if (check_region(0x388, 4)) /* Not free */
158 CS_OUT3(0x48, 0x00, 0x00) /* FM base off */
159 else
160 CS_OUT3(0x48, 0x03, 0x88); /* FM base 0x388 */
162 CS_OUT3(0x42, 0x00, 0x00); /* SB base off */
163 CS_OUT2(0x22, irq); /* SB+WSS IRQ */
164 CS_OUT2(0x2a, dma1); /* SB+WSS DMA */
166 if (dma2 != -1)
167 CS_OUT2(0x25, dma2) /* WSS DMA2 */
168 else
169 CS_OUT2(0x25, 4); /* No WSS DMA2 */
171 CS_OUT2(0x33, 0x01); /* Activate logical dev 0 */
173 sleep(HZ / 10);
176 * Initialize logical device 3 (MPU)
179 #if defined(CONFIG_UART401) && defined(CONFIG_MIDI)
180 if (mpu_base != 0 && mpu_irq != 0)
182 CS_OUT2(0x15, 0x03); /* Select logical device 3 (MPU) */
183 CS_OUT3(0x47, (mpu_base >> 8) & 0xff, mpu_base & 0xff); /* MPU base */
184 CS_OUT2(0x22, mpu_irq); /* MPU IRQ */
185 CS_OUT2(0x33, 0x01); /* Activate logical dev 3 */
187 #endif
189 if(synth_base != 0)
191 CS_OUT2 (0x15, 0x04); /* logical device 4 (WaveFront) */
192 CS_OUT3 (0x47, (synth_base >> 8) & 0xff,
193 synth_base & 0xff); /* base */
194 CS_OUT2 (0x22, synth_irq); /* IRQ */
195 CS_OUT2 (0x33, 0x01); /* Activate logical dev 4 */
199 * Finally activate the chip
202 CS_OUT(0x79);
204 sleep(HZ / 5);
207 * Then try to detect the codec part of the chip
210 if (ad1848_detect(hw_config->io_base, NULL, hw_config->osp))
211 return 1;
213 sleep(HZ);
215 return 0;
218 void attach_cs4232(struct address_info *hw_config)
220 int base = hw_config->io_base, irq = hw_config->irq;
221 int dma1 = hw_config->dma, dma2 = hw_config->dma2;
223 if (dma2 == -1)
224 dma2 = dma1;
226 hw_config->slots[0] = ad1848_init("Crystal audio controller", base,
227 irq,
228 dma1, /* Playback DMA */
229 dma2, /* Capture DMA */
231 hw_config->osp);
233 if (hw_config->slots[0] != -1 &&
234 audio_devs[hw_config->slots[0]]->mixer_dev!=-1)
236 /* Assume the mixer map is as suggested in the CS4232 databook */
237 AD1848_REROUTE(SOUND_MIXER_LINE1, SOUND_MIXER_LINE);
238 AD1848_REROUTE(SOUND_MIXER_LINE2, SOUND_MIXER_CD);
239 AD1848_REROUTE(SOUND_MIXER_LINE3, SOUND_MIXER_SYNTH); /* FM synth */
241 #if defined(CONFIG_UART401) && defined(CONFIG_MIDI)
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;
250 hw_config2.dma = -1;
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))
260 mpu_detected = 1;
261 attach_uart401(&hw_config2);
263 else
265 mpu_base = mpu_irq = 0;
267 hw_config->slots[1] = hw_config2.slots[1];
269 #endif
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;
277 if (dma2 == -1)
278 dma2 = dma1;
280 ad1848_unload(base,
281 irq,
282 dma1, /* Playback DMA */
283 dma2, /* Capture DMA */
286 sound_unload_audiodev(hw_config->slots[0]);
287 #if defined(CONFIG_UART401) && defined(CONFIG_MIDI)
288 if (mpu_base != 0 && mpu_irq != 0 && mpu_detected)
290 static struct address_info hw_config2 =
293 }; /* Ensure it's initialized */
295 hw_config2.io_base = mpu_base;
296 hw_config2.irq = mpu_irq;
297 hw_config2.dma = -1;
298 hw_config2.dma2 = -1;
299 hw_config2.always_detect = 0;
300 hw_config2.name = NULL;
301 hw_config2.driver_use_1 = 0;
302 hw_config2.driver_use_2 = 0;
303 hw_config2.card_subtype = 0;
304 hw_config2.slots[1] = hw_config->slots[1];
306 unload_uart401(&hw_config2);
308 #endif
311 void unload_cs4232_mpu(struct address_info *hw_config)
313 /* Not required. Handled by cs4232_unload */
316 #ifdef MODULE
318 int io = -1;
319 int irq = -1;
320 int dma = -1;
321 int dma2 = -1;
322 int mpuio = -1;
323 int mpuirq = -1;
325 MODULE_PARM(io,"i");
326 MODULE_PARM(irq,"i");
327 MODULE_PARM(dma,"i");
328 MODULE_PARM(dma2,"i");
329 MODULE_PARM(mpuio,"i");
330 MODULE_PARM(mpuirq,"i");
332 int synthio = -1;
333 int synthirq = -1;
334 MODULE_PARM(synthio,"i");
335 MODULE_PARM(synthirq,"i");
337 EXPORT_NO_SYMBOLS;
339 struct address_info cfg;
340 struct address_info mpu_cfg;
343 * Install a CS4232 based card. Need to have ad1848 and mpu401
344 * loaded ready.
347 int init_module(void)
349 if (io == -1 || irq == -1 || dma == -1 || dma2 == -1)
351 printk(KERN_ERR "cs4232: dma, dma2, irq and io must be set.\n");
352 return -EINVAL;
354 #ifdef CONFIG_SOUND_WAVEFRONT_MODULE
355 if(synthio == -1)
356 printk(KERN_WARNING "cs4232: set synthio and synthirq to use the wavefront facilities.\n");
357 else
359 synth_base = synthio;
360 synth_irq = synthirq;
362 #else
363 if(synthio != -1)
364 printk(KERN_WARNING "cs4232: wavefront support not enabled in this driver.\n");
365 #endif
367 cfg.io_base = io;
368 cfg.irq = irq;
369 cfg.dma = dma;
370 cfg.dma2 = dma2;
372 mpu_cfg.io_base = -1;
373 mpu_cfg.irq = -1;
375 if (mpuio != -1 && mpuirq != -1) {
376 mpu_cfg.io_base = mpuio;
377 mpu_cfg.irq = mpuirq;
378 probe_cs4232_mpu(&mpu_cfg); /* Bug always returns 0 not OK -- AC */
381 if (probe_cs4232(&cfg) == 0)
382 return -ENODEV;
384 attach_cs4232(&cfg);
386 if (mpuio != -1 && mpuirq != -1) {
387 attach_cs4232_mpu(&mpu_cfg);
390 SOUND_LOCK;
391 return 0;
394 void cleanup_module(void)
396 unload_cs4232(&cfg); /* unloads MPU as well, if needed */
397 SOUND_LOCK_END;
400 #endif