source: GPL/branches/alsa-resync1/alsa-kernel/isa/sb/es968.c@ 212

Last change on this file since 212 was 212, checked in by Brendan Oakley, 18 years ago

Merged to Alsa 0.9.0rc5

File size: 8.8 KB
Line 
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#include <sound/driver.h>
24#include <linux/init.h>
25#include <linux/time.h>
26#ifndef LINUX_ISAPNP_H
27#include <linux/isapnp.h>
28#define isapnp_card pci_bus
29#define isapnp_dev pci_dev
30#endif
31#include <sound/core.h>
32#define SNDRV_GET_ID
33#include <sound/initval.h>
34#include <sound/sb.h>
35
36#define chip_t sb_t
37
38MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
39MODULE_DESCRIPTION("ESS AudioDrive ES968");
40MODULE_LICENSE("GPL");
41MODULE_CLASSES("{sound}");
42MODULE_DEVICES("{{ESS,AudioDrive ES968}}");
43
44static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
45static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
46static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
47static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
48static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */
49static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
50
51MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
52MODULE_PARM_DESC(index, "Index value for es968 based soundcard.");
53MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
54MODULE_PARM(id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
55MODULE_PARM_DESC(id, "ID string for es968 based soundcard.");
56MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
57MODULE_PARM(enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
58MODULE_PARM_DESC(enable, "Enable es968 based soundcard.");
59MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
60MODULE_PARM(port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
61MODULE_PARM_DESC(port, "Port # for es968 driver.");
62MODULE_PARM_SYNTAX(port, SNDRV_PORT12_DESC);
63MODULE_PARM(irq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
64MODULE_PARM_DESC(irq, "IRQ # for es968 driver.");
65MODULE_PARM_SYNTAX(irq, SNDRV_IRQ_DESC);
66MODULE_PARM(dma8, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
67MODULE_PARM_DESC(dma8, "8-bit DMA # for es968 driver.");
68MODULE_PARM_SYNTAX(dma8, SNDRV_DMA8_DESC);
69
70struct snd_card_es968 {
71#ifdef __ISAPNP__
72 struct isapnp_dev *dev;
73#endif /* __ISAPNP__ */
74};
75
76static snd_card_t *snd_es968_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
77
78#ifdef __ISAPNP__
79static struct isapnp_card *snd_es968_isapnp_cards[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
80static const struct isapnp_card_id *snd_es968_isapnp_id[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
81
82static struct isapnp_card_id snd_es968_pnpids[] __devinitdata = {
83 {
84 ISAPNP_CARD_ID('E','S','S',0x0968),
85 .devs = { ISAPNP_DEVICE_ID('E','S','S',0x0968), }
86 },
87 { ISAPNP_CARD_END, }
88};
89
90ISAPNP_CARD_TABLE(snd_es968_pnpids);
91
92#endif /* __ISAPNP__ */
93
94#define DRIVER_NAME "snd-card-es968"
95
96
97static void snd_card_es968_interrupt(int irq, void *dev_id,
98 struct pt_regs *regs)
99{
100 sb_t *chip = snd_magic_cast(sb_t, dev_id, return);
101
102 if (chip->open & SB_OPEN_PCM) {
103 snd_sb8dsp_interrupt(chip);
104 } else {
105 snd_sb8dsp_midi_interrupt(chip);
106 }
107}
108
109#ifdef __ISAPNP__
110static int __init snd_card_es968_isapnp(int dev, struct snd_card_es968 *acard)
111{
112 const struct isapnp_card_id *id = snd_es968_isapnp_id[dev];
113 struct isapnp_card *card = snd_es968_isapnp_cards[dev];
114 struct isapnp_dev *pdev;
115
116 acard->dev = isapnp_find_dev(card, id->devs[0].vendor, id->devs[0].function, NULL);
117 if (acard->dev->active) {
118 acard->dev = NULL;
119 return -EBUSY;
120 }
121
122 pdev = acard->dev;
123 if (pdev->prepare(pdev)<0)
124 return -EAGAIN;
125
126 if (port[dev] != SNDRV_AUTO_PORT)
127 isapnp_resource_change(&pdev->resource[0], port[dev], 16);
128 if (dma8[dev] != SNDRV_AUTO_DMA)
129 isapnp_resource_change(&pdev->dma_resource[0], dma8[dev],
130 1);
131 if (irq[dev] != SNDRV_AUTO_IRQ)
132 isapnp_resource_change(&pdev->irq_resource[0], irq[dev], 1);
133
134 if (pdev->activate(pdev)<0) {
135 snd_printk("AUDIO isapnp configure failure\n");
136 return -EBUSY;
137 }
138
139 port[dev] = pdev->resource[0].start;
140 dma8[dev] = pdev->dma_resource[0].start;
141 irq[dev] = pdev->irq_resource[0].start;
142
143 return 0;
144}
145
146static void snd_card_es968_deactivate(struct snd_card_es968 *acard)
147{
148 if (acard->dev) {
149 acard->dev->deactivate(acard->dev);
150 acard->dev = NULL;
151 }
152}
153#endif /* __ISAPNP__ */
154
155static void snd_card_es968_free(snd_card_t *card)
156{
157 struct snd_card_es968 *acard = (struct snd_card_es968 *)card->private_data;
158
159 if (acard) {
160#ifdef __ISAPNP__
161 snd_card_es968_deactivate(acard);
162#endif /* __ISAPNP__ */
163 }
164}
165
166static int __init snd_card_es968_probe(int dev)
167{
168 int error;
169 sb_t *chip;
170 snd_card_t *card;
171 struct snd_card_es968 *acard;
172
173 if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
174 sizeof(struct snd_card_es968))) == NULL)
175 return -ENOMEM;
176 acard = (struct snd_card_es968 *)card->private_data;
177 card->private_free = snd_card_es968_free;
178
179#ifdef __ISAPNP__
180 if ((error = snd_card_es968_isapnp(dev, acard))) {
181 snd_card_free(card);
182 return error;
183 }
184#else
185 snd_printk("you have to enable PnP support ...\n");
186 snd_card_free(card);
187 return -ENOSYS;
188#endif /* __ISAPNP__ */
189
190 if ((error = snd_sbdsp_create(card, port[dev],
191 irq[dev],
192 snd_card_es968_interrupt,
193 dma8[dev],
194 -1,
195 SB_HW_AUTO, &chip)) < 0) {
196 snd_card_free(card);
197 return error;
198 }
199
200 if ((error = snd_sb8dsp_pcm(chip, 0, NULL)) < 0) {
201 snd_card_free(card);
202 return error;
203 }
204
205 if ((error = snd_sbmixer_new(chip)) < 0) {
206 snd_card_free(card);
207 return error;
208 }
209
210 if ((error = snd_sb8dsp_midi(chip, 0, NULL)) < 0) {
211 snd_card_free(card);
212 return error;
213 }
214
215 strcpy(card->driver, "ES968");
216 strcpy(card->shortname, "ESS ES968");
217 sprintf(card->longname, "%s soundcard, %s at 0x%lx, irq %d, dma %d",
218 card->shortname, chip->name, chip->port, irq[dev], dma8[dev]);
219
220 if ((error = snd_card_register(card)) < 0) {
221 snd_card_free(card);
222 return error;
223 }
224 snd_es968_cards[dev] = card;
225 return 0;
226}
227
228#ifdef __ISAPNP__
229static int __init snd_es968_isapnp_detect(struct isapnp_card *card,
230 const struct isapnp_card_id *id)
231{
232 static int dev;
233 int res;
234
235 for ( ; dev < SNDRV_CARDS; dev++) {
236 if (!enable[dev])
237 continue;
238 snd_es968_isapnp_cards[dev] = card;
239 snd_es968_isapnp_id[dev] = id;
240 res = snd_card_es968_probe(dev);
241 if (res < 0)
242 return res;
243 dev++;
244 return 0;
245 }
246 return -ENODEV;
247}
248#endif /* __ISAPNP__ */
249
250static int __init alsa_card_es968_init(void)
251{
252 int cards = 0;
253
254#ifdef __ISAPNP__
255 cards += isapnp_probe_cards(snd_es968_pnpids, snd_es968_isapnp_detect);
256#else
257 snd_printk("you have to enable ISA PnP support.\n");
258#endif
259#ifdef MODULE
260 if (!cards)
261 snd_printk("no ES968 based soundcards found\n");
262#endif
263 return cards ? 0 : -ENODEV;
264}
265
266static void __exit alsa_card_es968_exit(void)
267{
268 int dev;
269
270 for (dev = 0; dev < SNDRV_CARDS; dev++)
271 snd_card_free(snd_es968_cards[dev]);
272}
273
274module_init(alsa_card_es968_init)
275module_exit(alsa_card_es968_exit)
276
277#ifndef MODULE
278
279/* format is: snd-es968=enable,index,id,
280 port,irq,snd_dma1 */
281
282static int __init alsa_card_es968_setup(char *str)
283{
284 static unsigned __initdata nr_dev = 0;
285
286 if (nr_dev >= SNDRV_CARDS)
287 return 0;
288 (void)(get_option(&str,&enable[nr_dev]) == 2 &&
289 get_option(&str,&index[nr_dev]) == 2 &&
290 get_id(&str,&id[nr_dev]) == 2 &&
291 get_option(&str,(int *)&port[nr_dev]) == 2 &&
292 get_option(&str,&irq[nr_dev]) == 2 &&
293 get_option(&str,&dma8[nr_dev]) == 2);
294 nr_dev++;
295 return 1;
296}
297
298__setup("snd-es968=", alsa_card_es968_setup);
299
300#endif /* ifndef MODULE */
Note: See TracBrowser for help on using the repository browser.