mac80211: rx.c use new helpers
[linux-2.6/linux-2.6-openrd.git] / sound / isa / es1688 / es1688.c
blobf88639ea64b214ddd976ef6577eab8100f2741f4
1 /*
2 * Driver for generic ESS AudioDrive ESx688 soundcards
3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <linux/init.h>
23 #include <linux/err.h>
24 #include <linux/isa.h>
25 #include <linux/time.h>
26 #include <linux/wait.h>
27 #include <linux/moduleparam.h>
28 #include <asm/dma.h>
29 #include <sound/core.h>
30 #include <sound/es1688.h>
31 #include <sound/mpu401.h>
32 #include <sound/opl3.h>
33 #define SNDRV_LEGACY_FIND_FREE_IRQ
34 #define SNDRV_LEGACY_FIND_FREE_DMA
35 #include <sound/initval.h>
37 #define CRD_NAME "Generic ESS ES1688/ES688 AudioDrive"
38 #define DEV_NAME "es1688"
40 MODULE_DESCRIPTION(CRD_NAME);
41 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
42 MODULE_LICENSE("GPL");
43 MODULE_SUPPORTED_DEVICE("{{ESS,ES688 PnP AudioDrive,pnp:ESS0100},"
44 "{ESS,ES1688 PnP AudioDrive,pnp:ESS0102},"
45 "{ESS,ES688 AudioDrive,pnp:ESS6881},"
46 "{ESS,ES1688 AudioDrive,pnp:ESS1681}}");
48 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
49 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
50 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
51 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260 */
52 static long mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1};
53 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
54 static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
55 static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */
57 module_param_array(index, int, NULL, 0444);
58 MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
59 module_param_array(id, charp, NULL, 0444);
60 MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
61 module_param_array(enable, bool, NULL, 0444);
62 MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
63 module_param_array(port, long, NULL, 0444);
64 MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
65 module_param_array(mpu_port, long, NULL, 0444);
66 MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " CRD_NAME " driver.");
67 module_param_array(irq, int, NULL, 0444);
68 MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver.");
69 module_param_array(mpu_irq, int, NULL, 0444);
70 MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " CRD_NAME " driver.");
71 module_param_array(dma8, int, NULL, 0444);
72 MODULE_PARM_DESC(dma8, "8-bit DMA # for " CRD_NAME " driver.");
74 static int __devinit snd_es1688_match(struct device *dev, unsigned int n)
76 return enable[n];
79 static int __devinit snd_es1688_legacy_create(struct snd_card *card,
80 struct device *dev, unsigned int n, struct snd_es1688 **rchip)
82 static long possible_ports[] = {0x220, 0x240, 0x260};
83 static int possible_irqs[] = {5, 9, 10, 7, -1};
84 static int possible_dmas[] = {1, 3, 0, -1};
86 int i, error;
88 if (irq[n] == SNDRV_AUTO_IRQ) {
89 irq[n] = snd_legacy_find_free_irq(possible_irqs);
90 if (irq[n] < 0) {
91 snd_printk(KERN_ERR "%s: unable to find a free IRQ\n",
92 dev->bus_id);
93 return -EBUSY;
96 if (dma8[n] == SNDRV_AUTO_DMA) {
97 dma8[n] = snd_legacy_find_free_dma(possible_dmas);
98 if (dma8[n] < 0) {
99 snd_printk(KERN_ERR "%s: unable to find a free DMA\n",
100 dev->bus_id);
101 return -EBUSY;
105 if (port[n] != SNDRV_AUTO_PORT)
106 return snd_es1688_create(card, port[n], mpu_port[n], irq[n],
107 mpu_irq[n], dma8[n], ES1688_HW_AUTO, rchip);
109 i = 0;
110 do {
111 port[n] = possible_ports[i];
112 error = snd_es1688_create(card, port[n], mpu_port[n], irq[n],
113 mpu_irq[n], dma8[n], ES1688_HW_AUTO, rchip);
114 } while (error < 0 && ++i < ARRAY_SIZE(possible_ports));
116 return error;
119 static int __devinit snd_es1688_probe(struct device *dev, unsigned int n)
121 struct snd_card *card;
122 struct snd_es1688 *chip;
123 struct snd_opl3 *opl3;
124 struct snd_pcm *pcm;
125 int error;
127 card = snd_card_new(index[n], id[n], THIS_MODULE, 0);
128 if (!card)
129 return -EINVAL;
131 error = snd_es1688_legacy_create(card, dev, n, &chip);
132 if (error < 0)
133 goto out;
135 error = snd_es1688_pcm(chip, 0, &pcm);
136 if (error < 0)
137 goto out;
139 error = snd_es1688_mixer(chip);
140 if (error < 0)
141 goto out;
143 strcpy(card->driver, "ES1688");
144 strcpy(card->shortname, pcm->name);
145 sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i", pcm->name,
146 chip->port, chip->irq, chip->dma8);
148 if (snd_opl3_create(card, chip->port, chip->port + 2,
149 OPL3_HW_OPL3, 0, &opl3) < 0)
150 printk(KERN_WARNING "%s: opl3 not detected at 0x%lx\n",
151 dev->bus_id, chip->port);
152 else {
153 error = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
154 if (error < 0)
155 goto out;
158 if (mpu_irq[n] >= 0 && mpu_irq[n] != SNDRV_AUTO_IRQ &&
159 chip->mpu_port > 0) {
160 error = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688,
161 chip->mpu_port, 0,
162 mpu_irq[n], IRQF_DISABLED, NULL);
163 if (error < 0)
164 goto out;
167 snd_card_set_dev(card, dev);
169 error = snd_card_register(card);
170 if (error < 0)
171 goto out;
173 dev_set_drvdata(dev, card);
174 return 0;
176 out: snd_card_free(card);
177 return error;
180 static int __devexit snd_es1688_remove(struct device *dev, unsigned int n)
182 snd_card_free(dev_get_drvdata(dev));
183 dev_set_drvdata(dev, NULL);
184 return 0;
187 static struct isa_driver snd_es1688_driver = {
188 .match = snd_es1688_match,
189 .probe = snd_es1688_probe,
190 .remove = snd_es1688_remove,
191 #if 0 /* FIXME */
192 .suspend = snd_es1688_suspend,
193 .resume = snd_es1688_resume,
194 #endif
195 .driver = {
196 .name = DEV_NAME
200 static int __init alsa_card_es1688_init(void)
202 return isa_register_driver(&snd_es1688_driver, SNDRV_CARDS);
205 static void __exit alsa_card_es1688_exit(void)
207 isa_unregister_driver(&snd_es1688_driver);
210 module_init(alsa_card_es1688_init);
211 module_exit(alsa_card_es1688_exit);