source: GPL/branches/alsa-resync1/alsa-kernel/isa/es1688/es1688.c@ 207

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

Merged to Alsa 0.9.0rc2.

File size: 7.7 KB
Line 
1/*
2 * Driver for generic ESS AudioDrive ESx688 soundcards
3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
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>
23#include <asm/dma.h>
24#include <linux/init.h>
25#include <linux/time.h>
26#include <linux/wait.h>
27#include <sound/core.h>
28#include <sound/es1688.h>
29#include <sound/mpu401.h>
30#include <sound/opl3.h>
31#define SNDRV_LEGACY_AUTO_PROBE
32#define SNDRV_LEGACY_FIND_FREE_IRQ
33#define SNDRV_LEGACY_FIND_FREE_DMA
34#define SNDRV_GET_ID
35#include <sound/initval.h>
36
37#define chip_t es1688_t
38
39MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
40MODULE_DESCRIPTION("ESS ESx688 AudioDrive");
41MODULE_LICENSE("GPL");
42MODULE_CLASSES("{sound}");
43MODULE_DEVICES("{{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}}");
47
48static int snd_index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
49static char *snd_id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
50static int snd_enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
51static long snd_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260 */
52#ifdef TARGET_OS2
53static long snd_mpu_port[SNDRV_CARDS] = {-1,-1,-1,-1,-1,-1,-1,-1};
54#else
55static long snd_mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1};
56#endif
57static int snd_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
58static int snd_mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
59static int snd_dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */
60
61MODULE_PARM(snd_index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
62MODULE_PARM_DESC(snd_index, "Index value for ESx688 soundcard.");
63MODULE_PARM_SYNTAX(snd_index, SNDRV_INDEX_DESC);
64MODULE_PARM(snd_id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
65MODULE_PARM_DESC(snd_id, "ID string for ESx688 soundcard.");
66MODULE_PARM_SYNTAX(snd_id, SNDRV_ID_DESC);
67MODULE_PARM(snd_enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
68MODULE_PARM_DESC(snd_enable, "Enable ESx688 soundcard.");
69MODULE_PARM_SYNTAX(snd_enable, SNDRV_ENABLE_DESC);
70MODULE_PARM(snd_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
71MODULE_PARM_DESC(snd_port, "Port # for ESx688 driver.");
72MODULE_PARM_SYNTAX(snd_port, SNDRV_PORT12_DESC);
73MODULE_PARM(snd_mpu_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
74MODULE_PARM_DESC(snd_mpu_port, "MPU-401 port # for ESx688 driver.");
75MODULE_PARM_SYNTAX(snd_mpu_port, SNDRV_PORT12_DESC);
76MODULE_PARM(snd_irq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
77MODULE_PARM_DESC(snd_irq, "IRQ # for ESx688 driver.");
78MODULE_PARM_SYNTAX(snd_irq, SNDRV_IRQ_DESC);
79MODULE_PARM(snd_mpu_irq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
80MODULE_PARM_DESC(snd_mpu_irq, "MPU-401 IRQ # for ESx688 driver.");
81MODULE_PARM_SYNTAX(snd_mpu_irq, SNDRV_IRQ_DESC);
82MODULE_PARM(snd_dma8, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
83MODULE_PARM_DESC(snd_dma8, "8-bit DMA # for ESx688 driver.");
84MODULE_PARM_SYNTAX(snd_dma8, SNDRV_DMA8_DESC);
85
86static snd_card_t *snd_audiodrive_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
87
88
89static int __init snd_audiodrive_probe(int dev)
90{
91 static int possible_irqs[] = {5, 9, 10, 7, -1};
92 static int possible_dmas[] = {1, 3, 0, -1};
93 int irq, dma, mpu_irq;
94 snd_card_t *card;
95 es1688_t *chip;
96 opl3_t *opl3;
97 snd_pcm_t *pcm;
98 int err;
99
100 card = snd_card_new(snd_index[dev], snd_id[dev], THIS_MODULE, 0);
101 if (card == NULL)
102 return -ENOMEM;
103
104 irq = snd_irq[dev];
105 if (irq == SNDRV_AUTO_IRQ) {
106 if ((irq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
107 snd_card_free(card);
108 snd_printk("unable to find a free IRQ\n");
109 return -EBUSY;
110 }
111 }
112 mpu_irq = snd_mpu_irq[dev];
113 dma = snd_dma8[dev];
114 if (dma == SNDRV_AUTO_DMA) {
115 if ((dma = snd_legacy_find_free_dma(possible_dmas)) < 0) {
116 snd_card_free(card);
117 snd_printk("unable to find a free DMA\n");
118 return -EBUSY;
119 }
120 }
121
122 if ((err = snd_es1688_create(card, snd_port[dev], snd_mpu_port[dev],
123 irq, mpu_irq, dma,
124 ES1688_HW_AUTO, &chip)) < 0) {
125 snd_card_free(card);
126 return err;
127 }
128 if ((err = snd_es1688_pcm(chip, 0, &pcm)) < 0) {
129 snd_card_free(card);
130 return err;
131 }
132 if ((err = snd_es1688_mixer(chip)) < 0) {
133 snd_card_free(card);
134 return err;
135 }
136
137 if ((snd_opl3_create(card, chip->port, chip->port + 2, OPL3_HW_OPL3, 0, &opl3)) < 0) {
138 printk(KERN_ERR "es1688: opl3 not detected at 0x%lx\n", chip->port);
139 } else {
140 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
141 snd_card_free(card);
142 return err;
143 }
144 }
145
146 if (mpu_irq >= 0) {
147 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688,
148 chip->mpu_port, 0,
149 mpu_irq,
150 SA_INTERRUPT,
151 NULL)) < 0) {
152 snd_card_free(card);
153 return err;
154 }
155 }
156 strcpy(card->driver, "ES1688");
157 strcpy(card->shortname, pcm->name);
158 sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i", pcm->name, chip->port, irq, dma);
159 if ((err = snd_card_register(card)) < 0) {
160 snd_card_free(card);
161 return err;
162 }
163 snd_audiodrive_cards[dev] = card;
164 return 0;
165
166}
167
168static int __init snd_audiodrive_legacy_auto_probe(unsigned long port)
169{
170 static int dev;
171 int res;
172
173 for ( ; dev < SNDRV_CARDS; dev++) {
174 if (!snd_enable[dev] || snd_port[dev] != SNDRV_AUTO_PORT)
175 continue;
176 snd_port[dev] = port;
177 res = snd_audiodrive_probe(dev);
178 if (res < 0)
179 snd_port[dev] = SNDRV_AUTO_PORT;
180 return res;
181 }
182 return -ENODEV;
183}
184
185static int __init alsa_card_es1688_init(void)
186{
187 static unsigned long possible_ports[] = {0x220, 0x240, 0x260, -1};
188 int dev, cards = 0;
189
190 for (dev = cards = 0; dev < SNDRV_CARDS && snd_enable[dev]; dev++) {
191 if (snd_port[dev] == SNDRV_AUTO_PORT)
192 continue;
193 if (snd_audiodrive_probe(dev) >= 0)
194 cards++;
195 }
196 cards += snd_legacy_auto_probe(possible_ports, snd_audiodrive_legacy_auto_probe);
197 if (!cards) {
198#ifdef MODULE
199 snd_printk("ESS AudioDrive ES1688 soundcard not found or device busy\n");
200#endif
201 return -ENODEV;
202 }
203 return 0;
204}
205
206static void __exit alsa_card_es1688_exit(void)
207{
208 int idx;
209
210 for (idx = 0; idx < SNDRV_CARDS; idx++)
211 snd_card_free(snd_audiodrive_cards[idx]);
212}
213
214module_init(alsa_card_es1688_init)
215module_exit(alsa_card_es1688_exit)
216
217#ifndef MODULE
218
219/* format is: snd-es1688=snd_enable,snd_index,snd_id,
220 snd_port,snd_mpu_port,
221 snd_irq,snd_mpu_irq,
222 snd_dma8 */
223
224static int __init alsa_card_es1688_setup(char *str)
225{
226 static unsigned __initdata nr_dev = 0;
227
228 if (nr_dev >= SNDRV_CARDS)
229 return 0;
230 (void)(get_option(&str,&snd_enable[nr_dev]) == 2 &&
231 get_option(&str,&snd_index[nr_dev]) == 2 &&
232 get_id(&str,&snd_id[nr_dev]) == 2 &&
233 get_option(&str,(int *)&snd_port[nr_dev]) == 2 &&
234 get_option(&str,(int *)&snd_mpu_port[nr_dev]) == 2 &&
235 get_option(&str,&snd_irq[nr_dev]) == 2 &&
236 get_option(&str,&snd_mpu_irq[nr_dev]) == 2 &&
237 get_option(&str,&snd_dma8[nr_dev]) == 2);
238 nr_dev++;
239 return 1;
240}
241
242__setup("snd-es1688=", alsa_card_es1688_setup);
243
244#endif /* ifndef MODULE */
Note: See TracBrowser for help on using the repository browser.