]> bbs.cooldavid.org Git - net-next-2.6.git/blame - sound/isa/es1688/es1688.c
[ALSA] Changed Jaroslav Kysela's e-mail from perex@suse.cz to perex@perex.cz
[net-next-2.6.git] / sound / isa / es1688 / es1688.c
CommitLineData
1da177e4
LT
1/*
2 * Driver for generic ESS AudioDrive ESx688 soundcards
c1017a4c 3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
1da177e4
LT
4 *
5 *
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.
10 *
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.
15 *
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
19 *
20 */
21
22#include <sound/driver.h>
1da177e4 23#include <linux/init.h>
2a571ed1 24#include <linux/err.h>
ae596186 25#include <linux/isa.h>
1da177e4
LT
26#include <linux/time.h>
27#include <linux/wait.h>
28#include <linux/moduleparam.h>
2a571ed1 29#include <asm/dma.h>
1da177e4
LT
30#include <sound/core.h>
31#include <sound/es1688.h>
32#include <sound/mpu401.h>
33#include <sound/opl3.h>
1da177e4
LT
34#define SNDRV_LEGACY_FIND_FREE_IRQ
35#define SNDRV_LEGACY_FIND_FREE_DMA
36#include <sound/initval.h>
37
ae596186
RH
38#define CRD_NAME "Generic ESS ES1688/ES688 AudioDrive"
39#define DEV_NAME "es1688"
40
41MODULE_DESCRIPTION(CRD_NAME);
c1017a4c 42MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
1da177e4
LT
43MODULE_LICENSE("GPL");
44MODULE_SUPPORTED_DEVICE("{{ESS,ES688 PnP AudioDrive,pnp:ESS0100},"
45 "{ESS,ES1688 PnP AudioDrive,pnp:ESS0102},"
46 "{ESS,ES688 AudioDrive,pnp:ESS6881},"
47 "{ESS,ES1688 AudioDrive,pnp:ESS1681}}");
48
49static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
50static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
51static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
52static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260 */
53static long mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1};
54static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
55static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
56static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */
57
58module_param_array(index, int, NULL, 0444);
ae596186 59MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
1da177e4 60module_param_array(id, charp, NULL, 0444);
ae596186 61MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
1da177e4 62module_param_array(enable, bool, NULL, 0444);
ae596186 63MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
1da177e4 64module_param_array(port, long, NULL, 0444);
ae596186 65MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
1da177e4 66module_param_array(mpu_port, long, NULL, 0444);
ae596186 67MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " CRD_NAME " driver.");
1da177e4 68module_param_array(irq, int, NULL, 0444);
ae596186 69MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver.");
1da177e4 70module_param_array(mpu_irq, int, NULL, 0444);
ae596186 71MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " CRD_NAME " driver.");
1da177e4 72module_param_array(dma8, int, NULL, 0444);
ae596186 73MODULE_PARM_DESC(dma8, "8-bit DMA # for " CRD_NAME " driver.");
f7a9275d 74
ae596186
RH
75static int __devinit snd_es1688_match(struct device *dev, unsigned int n)
76{
77 return enable[n];
78}
1da177e4 79
019608b6
RH
80static int __devinit snd_es1688_legacy_create(struct snd_card *card,
81 struct device *dev, unsigned int n, struct snd_es1688 **rchip)
1da177e4 82{
019608b6 83 static long possible_ports[] = {0x220, 0x240, 0x260};
1da177e4
LT
84 static int possible_irqs[] = {5, 9, 10, 7, -1};
85 static int possible_dmas[] = {1, 3, 0, -1};
ae596186 86
019608b6
RH
87 int i, error;
88
89 if (irq[n] == SNDRV_AUTO_IRQ) {
90 irq[n] = snd_legacy_find_free_irq(possible_irqs);
91 if (irq[n] < 0) {
92 snd_printk(KERN_ERR "%s: unable to find a free IRQ\n",
93 dev->bus_id);
94 return -EBUSY;
95 }
96 }
97 if (dma8[n] == SNDRV_AUTO_DMA) {
98 dma8[n] = snd_legacy_find_free_dma(possible_dmas);
99 if (dma8[n] < 0) {
100 snd_printk(KERN_ERR "%s: unable to find a free DMA\n",
101 dev->bus_id);
102 return -EBUSY;
103 }
104 }
105
106 if (port[n] != SNDRV_AUTO_PORT)
107 return snd_es1688_create(card, port[n], mpu_port[n], irq[n],
108 mpu_irq[n], dma8[n], ES1688_HW_AUTO, rchip);
109
110 i = 0;
111 do {
112 port[n] = possible_ports[i];
113 error = snd_es1688_create(card, port[n], mpu_port[n], irq[n],
114 mpu_irq[n], dma8[n], ES1688_HW_AUTO, rchip);
115 } while (error < 0 && ++i < ARRAY_SIZE(possible_ports));
116
117 return error;
118}
119
120static int __devinit snd_es1688_probe(struct device *dev, unsigned int n)
121{
d3a7e476
TI
122 struct snd_card *card;
123 struct snd_es1688 *chip;
124 struct snd_opl3 *opl3;
125 struct snd_pcm *pcm;
ae596186
RH
126 int error;
127
128 card = snd_card_new(index[n], id[n], THIS_MODULE, 0);
129 if (!card)
130 return -EINVAL;
1da177e4 131
019608b6 132 error = snd_es1688_legacy_create(card, dev, n, &chip);
ae596186
RH
133 if (error < 0)
134 goto out;
43bcd973 135
ae596186
RH
136 error = snd_es1688_pcm(chip, 0, &pcm);
137 if (error < 0)
138 goto out;
43bcd973 139
ae596186
RH
140 error = snd_es1688_mixer(chip);
141 if (error < 0)
142 goto out;
1da177e4
LT
143
144 strcpy(card->driver, "ES1688");
145 strcpy(card->shortname, pcm->name);
019608b6
RH
146 sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i", pcm->name,
147 chip->port, chip->irq, chip->dma8);
1da177e4 148
019608b6
RH
149 if (snd_opl3_create(card, chip->port, chip->port + 2,
150 OPL3_HW_OPL3, 0, &opl3) < 0)
151 printk(KERN_WARNING "%s: opl3 not detected at 0x%lx\n",
152 dev->bus_id, chip->port);
ae596186
RH
153 else {
154 error = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
155 if (error < 0)
156 goto out;
1da177e4
LT
157 }
158
019608b6
RH
159 if (mpu_irq[n] >= 0 && mpu_irq[n] != SNDRV_AUTO_IRQ &&
160 chip->mpu_port > 0) {
161 error = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688,
162 chip->mpu_port, 0,
163 mpu_irq[n], IRQF_DISABLED, NULL);
ae596186
RH
164 if (error < 0)
165 goto out;
1da177e4 166 }
43bcd973 167
ae596186 168 snd_card_set_dev(card, dev);
43bcd973 169
ae596186
RH
170 error = snd_card_register(card);
171 if (error < 0)
172 goto out;
43bcd973 173
ae596186 174 dev_set_drvdata(dev, card);
1da177e4
LT
175 return 0;
176
ae596186
RH
177out: snd_card_free(card);
178 return error;
1da177e4
LT
179}
180
ae596186 181static int __devexit snd_es1688_remove(struct device *dev, unsigned int n)
1da177e4 182{
ae596186
RH
183 snd_card_free(dev_get_drvdata(dev));
184 dev_set_drvdata(dev, NULL);
2a571ed1 185 return 0;
1da177e4
LT
186}
187
ae596186
RH
188static struct isa_driver snd_es1688_driver = {
189 .match = snd_es1688_match,
2a571ed1 190 .probe = snd_es1688_probe,
ae596186
RH
191 .remove = snd_es1688_remove,
192#if 0 /* FIXME */
193 .suspend = snd_es1688_suspend,
194 .resume = snd_es1688_resume,
195#endif
2a571ed1 196 .driver = {
ae596186
RH
197 .name = DEV_NAME
198 }
2a571ed1
TI
199};
200
1da177e4
LT
201static int __init alsa_card_es1688_init(void)
202{
ae596186 203 return isa_register_driver(&snd_es1688_driver, SNDRV_CARDS);
1da177e4
LT
204}
205
206static void __exit alsa_card_es1688_exit(void)
207{
ae596186 208 isa_unregister_driver(&snd_es1688_driver);
1da177e4
LT
209}
210
ae596186
RH
211module_init(alsa_card_es1688_init);
212module_exit(alsa_card_es1688_exit);