1 | /*
|
---|
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>
|
---|
6 | *
|
---|
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.
|
---|
11 | *
|
---|
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.
|
---|
16 | *
|
---|
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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
20 | *
|
---|
21 | */
|
---|
22 |
|
---|
23 | #define SNDRV_MAIN_OBJECT_FILE
|
---|
24 | #include <sound/driver.h>
|
---|
25 | #include <sound/cs4231.h>
|
---|
26 | #include <sound/mpu401.h>
|
---|
27 | #define SNDRV_GET_ID
|
---|
28 | #include <sound/initval.h>
|
---|
29 |
|
---|
30 | #define chip_t cs4231_t
|
---|
31 |
|
---|
32 | EXPORT_NO_SYMBOLS;
|
---|
33 | MODULE_DESCRIPTION("Generic CS4231");
|
---|
34 | MODULE_CLASSES("{sound}");
|
---|
35 | MODULE_DEVICES("{{Crystal Semiconductors,CS4231}}");
|
---|
36 |
|
---|
37 | static int snd_index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
|
---|
38 | static char *snd_id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
|
---|
39 | static int snd_enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
|
---|
40 | static long snd_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
|
---|
41 | static long snd_mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
|
---|
42 | static int snd_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,11,12,15 */
|
---|
43 | static int snd_mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 9,11,12,15 */
|
---|
44 | static int snd_dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
|
---|
45 | static int snd_dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
|
---|
46 |
|
---|
47 | MODULE_PARM(snd_index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
---|
48 | MODULE_PARM_DESC(snd_index, "Index value for CS4231 soundcard.");
|
---|
49 | MODULE_PARM_SYNTAX(snd_index, SNDRV_INDEX_DESC);
|
---|
50 | MODULE_PARM(snd_id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
|
---|
51 | MODULE_PARM_DESC(snd_id, "ID string for CS4231 soundcard.");
|
---|
52 | MODULE_PARM_SYNTAX(snd_id, SNDRV_ID_DESC);
|
---|
53 | MODULE_PARM(snd_enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
---|
54 | MODULE_PARM_DESC(snd_enable, "Enable CS4231 soundcard.");
|
---|
55 | MODULE_PARM_SYNTAX(snd_enable, SNDRV_ENABLE_DESC);
|
---|
56 | MODULE_PARM(snd_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
|
---|
57 | MODULE_PARM_DESC(snd_port, "Port # for CS4231 driver.");
|
---|
58 | MODULE_PARM_SYNTAX(snd_port, SNDRV_PORT12_DESC);
|
---|
59 | MODULE_PARM(snd_mpu_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
|
---|
60 | MODULE_PARM_DESC(snd_mpu_port, "MPU-401 port # for CS4231 driver.");
|
---|
61 | MODULE_PARM_SYNTAX(snd_mpu_port, SNDRV_PORT12_DESC);
|
---|
62 | MODULE_PARM(snd_irq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
---|
63 | MODULE_PARM_DESC(snd_irq, "IRQ # for CS4231 driver.");
|
---|
64 | MODULE_PARM_SYNTAX(snd_irq, SNDRV_IRQ_DESC);
|
---|
65 | MODULE_PARM(snd_mpu_irq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
---|
66 | MODULE_PARM_DESC(snd_mpu_irq, "MPU-401 IRQ # for CS4231 driver.");
|
---|
67 | MODULE_PARM_SYNTAX(snd_mpu_irq, SNDRV_IRQ_DESC);
|
---|
68 | MODULE_PARM(snd_dma1, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
---|
69 | MODULE_PARM_DESC(snd_dma1, "DMA1 # for CS4231 driver.");
|
---|
70 | MODULE_PARM_SYNTAX(snd_dma1, SNDRV_DMA_DESC);
|
---|
71 | MODULE_PARM(snd_dma2, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
---|
72 | MODULE_PARM_DESC(snd_dma2, "DMA2 # for CS4231 driver.");
|
---|
73 | MODULE_PARM_SYNTAX(snd_dma2, SNDRV_DMA_DESC);
|
---|
74 |
|
---|
75 | static snd_card_t *snd_cs4231_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
|
---|
76 |
|
---|
77 |
|
---|
78 | static int __init snd_card_cs4231_probe(int dev)
|
---|
79 | {
|
---|
80 | snd_card_t *card;
|
---|
81 | struct snd_card_cs4231 *acard;
|
---|
82 | snd_pcm_t *pcm = NULL;
|
---|
83 | cs4231_t *chip;
|
---|
84 | int err;
|
---|
85 |
|
---|
86 | if (snd_port[dev] == SNDRV_AUTO_PORT) {
|
---|
87 | snd_printk("specify snd_port\n");
|
---|
88 | return -EINVAL;
|
---|
89 | }
|
---|
90 | if (snd_irq[dev] == SNDRV_AUTO_IRQ) {
|
---|
91 | snd_printk("specify snd_irq\n");
|
---|
92 | return -EINVAL;
|
---|
93 | }
|
---|
94 | if (snd_dma1[dev] == SNDRV_AUTO_DMA) {
|
---|
95 | snd_printk("specify snd_dma1\n");
|
---|
96 | return -EINVAL;
|
---|
97 | }
|
---|
98 | card = snd_card_new(snd_index[dev], snd_id[dev], THIS_MODULE, 0);
|
---|
99 | if (card == NULL)
|
---|
100 | return -ENOMEM;
|
---|
101 | acard = (struct snd_card_cs4231 *)card->private_data;
|
---|
102 | if (snd_mpu_port[dev] < 0)
|
---|
103 | snd_mpu_port[dev] = SNDRV_AUTO_PORT;
|
---|
104 | if ((err = snd_cs4231_create(card, snd_port[dev], -1,
|
---|
105 | snd_irq[dev],
|
---|
106 | snd_dma1[dev],
|
---|
107 | snd_dma2[dev],
|
---|
108 | CS4231_HW_DETECT,
|
---|
109 | 0, &chip)) < 0) {
|
---|
110 | snd_card_free(card);
|
---|
111 | return err;
|
---|
112 | }
|
---|
113 |
|
---|
114 | if ((err = snd_cs4231_pcm(chip, 0, &pcm)) < 0) {
|
---|
115 | snd_card_free(card);
|
---|
116 | return err;
|
---|
117 | }
|
---|
118 | if ((err = snd_cs4231_mixer(chip)) < 0) {
|
---|
119 | snd_card_free(card);
|
---|
120 | return err;
|
---|
121 | }
|
---|
122 | if ((err = snd_cs4231_timer(chip, 0, NULL)) < 0) {
|
---|
123 | snd_card_free(card);
|
---|
124 | return err;
|
---|
125 | }
|
---|
126 |
|
---|
127 | if (snd_mpu_irq[dev] >= 0 && snd_mpu_irq[dev] != SNDRV_AUTO_IRQ) {
|
---|
128 | if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232,
|
---|
129 | snd_mpu_port[dev], 0,
|
---|
130 | snd_mpu_irq[dev], SA_INTERRUPT,
|
---|
131 | NULL) < 0)
|
---|
132 | snd_printk("MPU401 not detected\n");
|
---|
133 | }
|
---|
134 | strcpy(card->driver, "CS4231");
|
---|
135 | strcpy(card->shortname, pcm->name);
|
---|
136 | sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
|
---|
137 | pcm->name, chip->port, snd_irq[dev], snd_dma1[dev]);
|
---|
138 | if (snd_dma2[dev] >= 0)
|
---|
139 | sprintf(card->longname + strlen(card->longname), "&%d", snd_dma2[dev]);
|
---|
140 | if ((err = snd_card_register(card)) < 0) {
|
---|
141 | snd_card_free(card);
|
---|
142 | return err;
|
---|
143 | }
|
---|
144 | snd_cs4231_cards[dev] = card;
|
---|
145 | return 0;
|
---|
146 | }
|
---|
147 |
|
---|
148 | static int __init alsa_card_cs4231_init(void)
|
---|
149 | {
|
---|
150 | int dev, cards;
|
---|
151 |
|
---|
152 | for (dev = cards = 0; dev < SNDRV_CARDS && snd_enable[dev]; dev++) {
|
---|
153 | if (snd_card_cs4231_probe(dev) >= 0)
|
---|
154 | cards++;
|
---|
155 | }
|
---|
156 | if (!cards) {
|
---|
157 | #ifdef MODULE
|
---|
158 | snd_printk("CS4231 soundcard not found or device busy\n");
|
---|
159 | #endif
|
---|
160 | return -ENODEV;
|
---|
161 | }
|
---|
162 | return 0;
|
---|
163 | }
|
---|
164 |
|
---|
165 | static void __exit alsa_card_cs4231_exit(void)
|
---|
166 | {
|
---|
167 | int idx;
|
---|
168 |
|
---|
169 | for (idx = 0; idx < SNDRV_CARDS; idx++)
|
---|
170 | snd_card_free(snd_cs4231_cards[idx]);
|
---|
171 | }
|
---|
172 |
|
---|
173 | module_init(alsa_card_cs4231_init)
|
---|
174 | module_exit(alsa_card_cs4231_exit)
|
---|
175 |
|
---|
176 | #ifndef MODULE
|
---|
177 |
|
---|
178 | /* format is: snd-card-cs4231=snd_enable,snd_index,snd_id,
|
---|
179 | snd_port,snd_mpu_port,snd_irq,snd_mpu_irq,
|
---|
180 | snd_dma1,snd_dma2 */
|
---|
181 |
|
---|
182 | static int __init alsa_card_cs4231_setup(char *str)
|
---|
183 | {
|
---|
184 | static unsigned __initdata nr_dev = 0;
|
---|
185 | int __attribute__ ((__unused__)) pnp = INT_MAX;
|
---|
186 |
|
---|
187 | if (nr_dev >= SNDRV_CARDS)
|
---|
188 | return 0;
|
---|
189 | (void)(get_option(&str,&snd_enable[nr_dev]) == 2 &&
|
---|
190 | get_option(&str,&snd_index[nr_dev]) == 2 &&
|
---|
191 | get_id(&str,&snd_id[nr_dev]) == 2 &&
|
---|
192 | get_option(&str,&pnp) == 2 &&
|
---|
193 | get_option(&str,(int *)&snd_port[nr_dev]) == 2 &&
|
---|
194 | get_option(&str,(int *)&snd_mpu_port[nr_dev]) == 2 &&
|
---|
195 | get_option(&str,&snd_irq[nr_dev]) == 2 &&
|
---|
196 | get_option(&str,&snd_mpu_irq[nr_dev]) == 2 &&
|
---|
197 | get_option(&str,&snd_dma1[nr_dev]) == 2 &&
|
---|
198 | get_option(&str,&snd_dma2[nr_dev]) == 2);
|
---|
199 | nr_dev++;
|
---|
200 | return 1;
|
---|
201 | }
|
---|
202 |
|
---|
203 | __setup("snd-card-cs4231=", alsa_card_cs4231_setup);
|
---|
204 |
|
---|
205 | #endif /* ifndef MODULE */
|
---|