2 * Generic driver for CS4231 chips
3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
4 * Originally the CS4232/CS4232A driver, modified for use on CS4231 by
5 * Tugrul Galatali <galatalt@stuy.edu>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <sound/driver.h>
24 #include <linux/init.h>
25 #include <linux/time.h>
26 #include <linux/wait.h>
27 #include <sound/core.h>
28 #include <sound/cs4231.h>
29 #include <sound/mpu401.h>
31 #include <sound/initval.h>
33 #define chip_t cs4231_t
35 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
36 MODULE_DESCRIPTION("Generic CS4231");
37 MODULE_LICENSE("GPL");
38 MODULE_CLASSES("{sound}");
39 MODULE_DEVICES("{{Crystal Semiconductors,CS4231}}");
41 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
42 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
43 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
44 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
45 static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
46 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,11,12,15 */
47 static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 9,11,12,15 */
48 static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
49 static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
51 MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
52 MODULE_PARM_DESC(index, "Index value for CS4231 soundcard.");
53 MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
54 MODULE_PARM(id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
55 MODULE_PARM_DESC(id, "ID string for CS4231 soundcard.");
56 MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
57 MODULE_PARM(enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
58 MODULE_PARM_DESC(enable, "Enable CS4231 soundcard.");
59 MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
60 MODULE_PARM(port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
61 MODULE_PARM_DESC(port, "Port # for CS4231 driver.");
62 MODULE_PARM_SYNTAX(port, SNDRV_PORT12_DESC);
63 MODULE_PARM(mpu_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
64 MODULE_PARM_DESC(mpu_port, "MPU-401 port # for CS4231 driver.");
65 MODULE_PARM_SYNTAX(mpu_port, SNDRV_PORT12_DESC);
66 MODULE_PARM(irq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
67 MODULE_PARM_DESC(irq, "IRQ # for CS4231 driver.");
68 MODULE_PARM_SYNTAX(irq, SNDRV_IRQ_DESC);
69 MODULE_PARM(mpu_irq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
70 MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for CS4231 driver.");
71 MODULE_PARM_SYNTAX(mpu_irq, SNDRV_IRQ_DESC);
72 MODULE_PARM(dma1, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
73 MODULE_PARM_DESC(dma1, "DMA1 # for CS4231 driver.");
74 MODULE_PARM_SYNTAX(dma1, SNDRV_DMA_DESC);
75 MODULE_PARM(dma2, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
76 MODULE_PARM_DESC(dma2, "DMA2 # for CS4231 driver.");
77 MODULE_PARM_SYNTAX(dma2, SNDRV_DMA_DESC);
79 static snd_card_t *snd_cs4231_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
82 static int __init snd_card_cs4231_probe(int dev)
85 struct snd_card_cs4231 *acard;
86 snd_pcm_t *pcm = NULL;
90 if (port[dev] == SNDRV_AUTO_PORT) {
91 snd_printk("specify port\n");
94 if (irq[dev] == SNDRV_AUTO_IRQ) {
95 snd_printk("specify irq\n");
98 if (dma1[dev] == SNDRV_AUTO_DMA) {
99 snd_printk("specify dma1\n");
102 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
105 acard = (struct snd_card_cs4231 *)card->private_data;
106 if ((err = snd_cs4231_create(card, port[dev], -1,
116 if ((err = snd_cs4231_pcm(chip, 0, &pcm)) < 0) {
121 strcpy(card->driver, "CS4231");
122 strcpy(card->shortname, pcm->name);
123 sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
124 pcm->name, chip->port, irq[dev], dma1[dev]);
126 sprintf(card->longname + strlen(card->longname), "&%d", dma2[dev]);
128 if ((err = snd_cs4231_mixer(chip)) < 0) {
132 if ((err = snd_cs4231_timer(chip, 0, NULL)) < 0) {
137 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
138 if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
140 if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232,
143 mpu_irq[dev] >= 0 ? SA_INTERRUPT : 0,
145 printk(KERN_ERR "cs4231: MPU401 not detected\n");
147 if ((err = snd_card_register(card)) < 0) {
151 snd_cs4231_cards[dev] = card;
155 static int __init alsa_card_cs4231_init(void)
159 for (dev = cards = 0; dev < SNDRV_CARDS && enable[dev]; dev++) {
160 if (snd_card_cs4231_probe(dev) >= 0)
165 printk(KERN_ERR "CS4231 soundcard not found or device busy\n");
172 static void __exit alsa_card_cs4231_exit(void)
176 for (idx = 0; idx < SNDRV_CARDS; idx++)
177 snd_card_free(snd_cs4231_cards[idx]);
180 module_init(alsa_card_cs4231_init)
181 module_exit(alsa_card_cs4231_exit)
185 /* format is: snd-cs4231=enable,index,id,
186 port,mpu_port,irq,mpu_irq,
189 static int __init alsa_card_cs4231_setup(char *str)
191 static unsigned __initdata nr_dev = 0;
192 int __attribute__ ((__unused__)) pnp = INT_MAX;
194 if (nr_dev >= SNDRV_CARDS)
196 (void)(get_option(&str,&enable[nr_dev]) == 2 &&
197 get_option(&str,&index[nr_dev]) == 2 &&
198 get_id(&str,&id[nr_dev]) == 2 &&
199 get_option(&str,&pnp) == 2 &&
200 get_option_long(&str,&port[nr_dev]) == 2 &&
201 get_option_long(&str,&mpu_port[nr_dev]) == 2 &&
202 get_option(&str,&irq[nr_dev]) == 2 &&
203 get_option(&str,&mpu_irq[nr_dev]) == 2 &&
204 get_option(&str,&dma1[nr_dev]) == 2 &&
205 get_option(&str,&dma2[nr_dev]) == 2);
210 __setup("snd-cs4231=", alsa_card_cs4231_setup);
212 #endif /* ifndef MODULE */