1 |
|
---|
2 | /*
|
---|
3 | card-es968.c - driver for ESS AudioDrive ES968 based soundcards.
|
---|
4 | Copyright (C) 1999 by Massimo Piccioni <dafastidio@libero.it>
|
---|
5 |
|
---|
6 | Thanks to Pierfrancesco 'qM2' Passerini.
|
---|
7 |
|
---|
8 | This program is free software; you can redistribute it and/or modify
|
---|
9 | it under the terms of the GNU General Public License as published by
|
---|
10 | the Free Software Foundation; either version 2 of the License, or
|
---|
11 | (at your option) any later version.
|
---|
12 |
|
---|
13 | This program is distributed in the hope that it will be useful,
|
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | GNU General Public License for more details.
|
---|
17 |
|
---|
18 | You should have received a copy of the GNU General Public License
|
---|
19 | along with this program; if not, write to the Free Software
|
---|
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
21 | */
|
---|
22 |
|
---|
23 | #define SNDRV_MAIN_OBJECT_FILE
|
---|
24 | #include <sound/driver.h>
|
---|
25 | #define SNDRV_GET_ID
|
---|
26 | #include <sound/initval.h>
|
---|
27 | #include <sound/sb.h>
|
---|
28 |
|
---|
29 | EXPORT_NO_SYMBOLS;
|
---|
30 | MODULE_DESCRIPTION("ESS AudioDrive ES968");
|
---|
31 | MODULE_CLASSES("{sound}");
|
---|
32 | MODULE_DEVICES("{{ESS,AudioDrive ES968}}");
|
---|
33 |
|
---|
34 | static int snd_index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
|
---|
35 | static char *snd_id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
|
---|
36 | static int snd_enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
|
---|
37 | static long snd_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
|
---|
38 | static int snd_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */
|
---|
39 | static int snd_dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
|
---|
40 |
|
---|
41 | MODULE_PARM(snd_index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
---|
42 | MODULE_PARM_DESC(snd_index, "Index value for es968 based soundcard.");
|
---|
43 | MODULE_PARM_SYNTAX(snd_index, SNDRV_INDEX_DESC);
|
---|
44 | MODULE_PARM(snd_id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
|
---|
45 | MODULE_PARM_DESC(snd_id, "ID string for es968 based soundcard.");
|
---|
46 | MODULE_PARM_SYNTAX(snd_id, SNDRV_ID_DESC);
|
---|
47 | MODULE_PARM(snd_enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
---|
48 | MODULE_PARM_DESC(snd_enable, "Enable es968 based soundcard.");
|
---|
49 | MODULE_PARM_SYNTAX(snd_enable, SNDRV_ENABLE_DESC);
|
---|
50 | MODULE_PARM(snd_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
|
---|
51 | MODULE_PARM_DESC(snd_port, "Port # for es968 driver.");
|
---|
52 | MODULE_PARM_SYNTAX(snd_port, SNDRV_PORT12_DESC);
|
---|
53 | MODULE_PARM(snd_irq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
---|
54 | MODULE_PARM_DESC(snd_irq, "IRQ # for es968 driver.");
|
---|
55 | MODULE_PARM_SYNTAX(snd_irq, SNDRV_IRQ_DESC);
|
---|
56 | MODULE_PARM(snd_dma8, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
---|
57 | MODULE_PARM_DESC(snd_dma8, "8-bit DMA # for es968 driver.");
|
---|
58 | MODULE_PARM_SYNTAX(snd_dma8, SNDRV_DMA8_DESC);
|
---|
59 |
|
---|
60 | struct snd_card_es968 {
|
---|
61 | #ifdef __ISAPNP__
|
---|
62 | struct isapnp_dev *dev;
|
---|
63 | #endif /* __ISAPNP__ */
|
---|
64 | };
|
---|
65 |
|
---|
66 | static snd_card_t *snd_es968_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
|
---|
67 |
|
---|
68 | #ifdef __ISAPNP__
|
---|
69 | static struct isapnp_card *snd_es968_isapnp_cards[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
|
---|
70 | static const struct isapnp_card_id *snd_es968_isapnp_id[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
|
---|
71 |
|
---|
72 | static struct isapnp_card_id snd_es968_pnpids[] __devinitdata = {
|
---|
73 | {
|
---|
74 | #ifdef TARGET_OS2
|
---|
75 | 0, ISAPNP_CARD_ID('E','S','S',0x0968),
|
---|
76 | { ISAPNP_DEVICE_ID('E','S','S',0x0968), }
|
---|
77 | #else
|
---|
78 | ISAPNP_CARD_ID('E','S','S',0x0968),
|
---|
79 | devs: { ISAPNP_DEVICE_ID('E','S','S',0x0968), }
|
---|
80 | #endif
|
---|
81 | },
|
---|
82 | { ISAPNP_CARD_END, }
|
---|
83 | };
|
---|
84 |
|
---|
85 | ISAPNP_CARD_TABLE(snd_es968_pnpids);
|
---|
86 |
|
---|
87 | #endif /* __ISAPNP__ */
|
---|
88 |
|
---|
89 | #define DRIVER_NAME "snd-card-es968"
|
---|
90 |
|
---|
91 |
|
---|
92 | static void snd_card_es968_interrupt(int irq, void *dev_id,
|
---|
93 | struct pt_regs *regs)
|
---|
94 | {
|
---|
95 | sb_t *chip = dev_id;
|
---|
96 |
|
---|
97 | if (chip->open & SB_OPEN_PCM) {
|
---|
98 | snd_sb8dsp_interrupt(chip);
|
---|
99 | } else {
|
---|
100 | snd_sb8dsp_midi_interrupt(chip);
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
104 | #ifdef __ISAPNP__
|
---|
105 | static int __init snd_card_es968_isapnp(int dev, struct snd_card_es968 *acard)
|
---|
106 | {
|
---|
107 | const struct isapnp_card_id *id = snd_es968_isapnp_id[dev];
|
---|
108 | struct isapnp_card *card = snd_es968_isapnp_cards[dev];
|
---|
109 | struct isapnp_dev *pdev;
|
---|
110 |
|
---|
111 | acard->dev = isapnp_find_dev(card, id->devs[0].vendor, id->devs[0].function, NULL);
|
---|
112 | if (acard->dev->active) {
|
---|
113 | acard->dev = NULL;
|
---|
114 | return -EBUSY;
|
---|
115 | }
|
---|
116 |
|
---|
117 | pdev = acard->dev;
|
---|
118 | if (pdev->prepare(pdev)<0)
|
---|
119 | return -EAGAIN;
|
---|
120 |
|
---|
121 | if (snd_port[dev] != SNDRV_AUTO_PORT)
|
---|
122 | isapnp_resource_change(&pdev->resource[0], snd_port[dev], 16);
|
---|
123 | if (snd_dma8[dev] != SNDRV_AUTO_DMA)
|
---|
124 | isapnp_resource_change(&pdev->dma_resource[0], snd_dma8[dev],
|
---|
125 | 1);
|
---|
126 | if (snd_irq[dev] != SNDRV_AUTO_IRQ)
|
---|
127 | isapnp_resource_change(&pdev->irq_resource[0], snd_irq[dev], 1);
|
---|
128 |
|
---|
129 | if (pdev->activate(pdev)<0) {
|
---|
130 | snd_printk("AUDIO isapnp configure failure\n");
|
---|
131 | return -EBUSY;
|
---|
132 | }
|
---|
133 |
|
---|
134 | snd_port[dev] = pdev->resource[0].start;
|
---|
135 | snd_dma8[dev] = pdev->dma_resource[0].start;
|
---|
136 | snd_irq[dev] = pdev->irq_resource[0].start;
|
---|
137 |
|
---|
138 | return 0;
|
---|
139 | }
|
---|
140 |
|
---|
141 | static void snd_card_es968_deactivate(struct snd_card_es968 *acard)
|
---|
142 | {
|
---|
143 | if (acard->dev) {
|
---|
144 | acard->dev->deactivate(acard->dev);
|
---|
145 | acard->dev = NULL;
|
---|
146 | }
|
---|
147 | }
|
---|
148 | #endif /* __ISAPNP__ */
|
---|
149 |
|
---|
150 | static void __exit snd_card_es968_free(snd_card_t *card)
|
---|
151 | {
|
---|
152 | struct snd_card_es968 *acard = (struct snd_card_es968 *)card->private_data;
|
---|
153 |
|
---|
154 | if (acard) {
|
---|
155 | #ifdef __ISAPNP__
|
---|
156 | snd_card_es968_deactivate(acard);
|
---|
157 | #endif /* __ISAPNP__ */
|
---|
158 | }
|
---|
159 | }
|
---|
160 |
|
---|
161 | static int __init snd_card_es968_probe(int dev)
|
---|
162 | {
|
---|
163 | int error;
|
---|
164 | sb_t *chip;
|
---|
165 | snd_card_t *card;
|
---|
166 | struct snd_card_es968 *acard;
|
---|
167 |
|
---|
168 | if ((card = snd_card_new(snd_index[dev], snd_id[dev], THIS_MODULE,
|
---|
169 | sizeof(struct snd_card_es968))) == NULL)
|
---|
170 | return -ENOMEM;
|
---|
171 | acard = (struct snd_card_es968 *)card->private_data;
|
---|
172 | card->private_free = snd_card_es968_free;
|
---|
173 |
|
---|
174 | #ifdef __ISAPNP__
|
---|
175 | if ((error = snd_card_es968_isapnp(dev, acard))) {
|
---|
176 | snd_card_free(card);
|
---|
177 | return error;
|
---|
178 | }
|
---|
179 | #else
|
---|
180 | snd_printk("you have to enable PnP support ...\n");
|
---|
181 | snd_card_free(card);
|
---|
182 | return -ENOSYS;
|
---|
183 | #endif /* __ISAPNP__ */
|
---|
184 |
|
---|
185 | if ((error = snd_sbdsp_create(card, snd_port[dev],
|
---|
186 | snd_irq[dev],
|
---|
187 | snd_card_es968_interrupt,
|
---|
188 | snd_dma8[dev],
|
---|
189 | -1,
|
---|
190 | SB_HW_AUTO, &chip)) < 0) {
|
---|
191 | snd_card_free(card);
|
---|
192 | return error;
|
---|
193 | }
|
---|
194 |
|
---|
195 | if ((error = snd_sb8dsp_pcm(chip, 0, NULL)) < 0) {
|
---|
196 | snd_card_free(card);
|
---|
197 | return error;
|
---|
198 | }
|
---|
199 |
|
---|
200 | if ((error = snd_sbmixer_new(chip)) < 0) {
|
---|
201 | snd_card_free(card);
|
---|
202 | return error;
|
---|
203 | }
|
---|
204 |
|
---|
205 | if ((error = snd_sb8dsp_midi(chip, 0, NULL)) < 0) {
|
---|
206 | snd_card_free(card);
|
---|
207 | return error;
|
---|
208 | }
|
---|
209 |
|
---|
210 | strcpy(card->driver, "ES968");
|
---|
211 | strcpy(card->shortname, "ESS ES968");
|
---|
212 | sprintf(card->longname, "%s soundcard, %s at 0x%lx, irq %d, dma %d",
|
---|
213 | card->shortname, chip->name, chip->port, snd_irq[dev], snd_dma8[dev]);
|
---|
214 |
|
---|
215 | if ((error = snd_card_register(card)) < 0) {
|
---|
216 | snd_card_free(card);
|
---|
217 | return error;
|
---|
218 | }
|
---|
219 | snd_es968_cards[dev] = card;
|
---|
220 | return 0;
|
---|
221 | }
|
---|
222 |
|
---|
223 | #ifdef __ISAPNP__
|
---|
224 | static int __init snd_es968_isapnp_detect(struct isapnp_card *card,
|
---|
225 | const struct isapnp_card_id *id)
|
---|
226 | {
|
---|
227 | static int dev = 0;
|
---|
228 | int res;
|
---|
229 |
|
---|
230 | for ( ; dev < SNDRV_CARDS; dev++) {
|
---|
231 | if (!snd_enable[dev])
|
---|
232 | continue;
|
---|
233 | snd_es968_isapnp_cards[dev] = card;
|
---|
234 | snd_es968_isapnp_id[dev] = id;
|
---|
235 | res = snd_card_es968_probe(dev);
|
---|
236 | if (res < 0)
|
---|
237 | return res;
|
---|
238 | dev++;
|
---|
239 | return 0;
|
---|
240 | }
|
---|
241 | return -ENODEV;
|
---|
242 | }
|
---|
243 | #endif /* __ISAPNP__ */
|
---|
244 |
|
---|
245 | static int __init alsa_card_es968_init(void)
|
---|
246 | {
|
---|
247 | int cards = 0;
|
---|
248 |
|
---|
249 | #ifdef __ISAPNP__
|
---|
250 | cards += isapnp_probe_cards(snd_es968_pnpids, snd_es968_isapnp_detect);
|
---|
251 | #else
|
---|
252 | snd_printk("you have to enable ISA PnP support.\n");
|
---|
253 | #endif
|
---|
254 | #ifdef MODULE
|
---|
255 | if (!cards)
|
---|
256 | snd_printk("no ES968 based soundcards found\n");
|
---|
257 | #endif
|
---|
258 | return cards ? 0 : -ENODEV;
|
---|
259 | }
|
---|
260 |
|
---|
261 | static void __exit alsa_card_es968_exit(void)
|
---|
262 | {
|
---|
263 | int dev;
|
---|
264 |
|
---|
265 | for (dev = 0; dev < SNDRV_CARDS; dev++)
|
---|
266 | snd_card_free(snd_es968_cards[dev]);
|
---|
267 | }
|
---|
268 |
|
---|
269 | module_init(alsa_card_es968_init)
|
---|
270 | module_exit(alsa_card_es968_exit)
|
---|
271 |
|
---|
272 | #ifndef MODULE
|
---|
273 |
|
---|
274 | /* format is: snd-card-es968=snd_enable,snd_index,snd_id,
|
---|
275 | snd_port,snd_irq,snd_dma1 */
|
---|
276 |
|
---|
277 | static int __init alsa_card_es968_setup(char *str)
|
---|
278 | {
|
---|
279 | static unsigned __initdata nr_dev = 0;
|
---|
280 |
|
---|
281 | if (nr_dev >= SNDRV_CARDS)
|
---|
282 | return 0;
|
---|
283 | (void)(get_option(&str,&snd_enable[nr_dev]) == 2 &&
|
---|
284 | get_option(&str,&snd_index[nr_dev]) == 2 &&
|
---|
285 | get_id(&str,&snd_id[nr_dev]) == 2 &&
|
---|
286 | get_option(&str,(int *)&snd_port[nr_dev]) == 2 &&
|
---|
287 | get_option(&str,&snd_irq[nr_dev]) == 2 &&
|
---|
288 | get_option(&str,&snd_dma8[nr_dev]) == 2);
|
---|
289 | nr_dev++;
|
---|
290 | return 1;
|
---|
291 | }
|
---|
292 |
|
---|
293 | __setup("snd-card-es968=", alsa_card_es968_setup);
|
---|
294 |
|
---|
295 | #endif /* ifndef MODULE */
|
---|