blob: 281679493fb4aa26b8fdc1de4e26416177fb39c2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Driver for generic ESS AudioDrive ESx688 soundcards
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02003 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/init.h>
Takashi Iwai2a571ed2005-11-17 17:13:30 +010023#include <linux/err.h>
Rene Hermanae596182007-02-14 13:26:17 +010024#include <linux/isa.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/time.h>
26#include <linux/wait.h>
27#include <linux/moduleparam.h>
Takashi Iwai2a571ed2005-11-17 17:13:30 +010028#include <asm/dma.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <sound/core.h>
30#include <sound/es1688.h>
31#include <sound/mpu401.h>
32#include <sound/opl3.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#define SNDRV_LEGACY_FIND_FREE_IRQ
34#define SNDRV_LEGACY_FIND_FREE_DMA
35#include <sound/initval.h>
36
Rene Hermanae596182007-02-14 13:26:17 +010037#define CRD_NAME "Generic ESS ES1688/ES688 AudioDrive"
38#define DEV_NAME "es1688"
39
40MODULE_DESCRIPTION(CRD_NAME);
Jaroslav Kyselac1017a42007-10-15 09:50:19 +020041MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
Linus Torvalds1da177e2005-04-16 15:20:36 -070042MODULE_LICENSE("GPL");
43MODULE_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}}");
47
48static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
49static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
50static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
51static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260 */
Krzysztof Helt880abd42009-01-30 19:20:29 +010052static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* Usually 0x388 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070053static 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);
Rene Hermanae596182007-02-14 13:26:17 +010059MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070060module_param_array(id, charp, NULL, 0444);
Rene Hermanae596182007-02-14 13:26:17 +010061MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070062module_param_array(enable, bool, NULL, 0444);
Rene Hermanae596182007-02-14 13:26:17 +010063MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070064module_param_array(port, long, NULL, 0444);
Rene Hermanae596182007-02-14 13:26:17 +010065MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070066module_param_array(mpu_port, long, NULL, 0444);
Rene Hermanae596182007-02-14 13:26:17 +010067MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " CRD_NAME " driver.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070068module_param_array(irq, int, NULL, 0444);
Krzysztof Helt880abd42009-01-30 19:20:29 +010069module_param_array(fm_port, long, NULL, 0444);
70MODULE_PARM_DESC(fm_port, "FM port # for ES1688 driver.");
Rene Hermanae596182007-02-14 13:26:17 +010071MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070072module_param_array(mpu_irq, int, NULL, 0444);
Rene Hermanae596182007-02-14 13:26:17 +010073MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " CRD_NAME " driver.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070074module_param_array(dma8, int, NULL, 0444);
Rene Hermanae596182007-02-14 13:26:17 +010075MODULE_PARM_DESC(dma8, "8-bit DMA # for " CRD_NAME " driver.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Rene Hermanae596182007-02-14 13:26:17 +010077static int __devinit snd_es1688_match(struct device *dev, unsigned int n)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078{
Rene Hermanae596182007-02-14 13:26:17 +010079 return enable[n];
80}
81
Krzysztof Helt396fa822010-05-09 20:35:44 +020082static int __devinit snd_es1688_legacy_create(struct snd_card *card,
83 struct snd_es1688 *chip, struct device *dev, unsigned int n)
Rene Hermanae596182007-02-14 13:26:17 +010084{
Rene Herman019608b2007-02-19 13:01:45 +010085 static long possible_ports[] = {0x220, 0x240, 0x260};
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 static int possible_irqs[] = {5, 9, 10, 7, -1};
87 static int possible_dmas[] = {1, 3, 0, -1};
Rene Hermanae596182007-02-14 13:26:17 +010088
Rene Herman019608b2007-02-19 13:01:45 +010089 int i, error;
90
91 if (irq[n] == SNDRV_AUTO_IRQ) {
92 irq[n] = snd_legacy_find_free_irq(possible_irqs);
93 if (irq[n] < 0) {
Takashi Iwai0418ff02008-11-03 08:51:33 +010094 dev_err(dev, "unable to find a free IRQ\n");
Rene Herman019608b2007-02-19 13:01:45 +010095 return -EBUSY;
96 }
97 }
98 if (dma8[n] == SNDRV_AUTO_DMA) {
99 dma8[n] = snd_legacy_find_free_dma(possible_dmas);
100 if (dma8[n] < 0) {
Takashi Iwai0418ff02008-11-03 08:51:33 +0100101 dev_err(dev, "unable to find a free DMA\n");
Rene Herman019608b2007-02-19 13:01:45 +0100102 return -EBUSY;
103 }
104 }
105
106 if (port[n] != SNDRV_AUTO_PORT)
Krzysztof Helt396fa822010-05-09 20:35:44 +0200107 return snd_es1688_create(card, chip, port[n], mpu_port[n],
108 irq[n], mpu_irq[n], dma8[n], ES1688_HW_AUTO);
Rene Herman019608b2007-02-19 13:01:45 +0100109
110 i = 0;
111 do {
112 port[n] = possible_ports[i];
Krzysztof Helt396fa822010-05-09 20:35:44 +0200113 error = snd_es1688_create(card, chip, port[n], mpu_port[n],
114 irq[n], mpu_irq[n], dma8[n], ES1688_HW_AUTO);
Rene Herman019608b2007-02-19 13:01:45 +0100115 } 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{
Takashi Iwaid3a7e472005-11-17 14:31:42 +0100122 struct snd_card *card;
123 struct snd_es1688 *chip;
124 struct snd_opl3 *opl3;
125 struct snd_pcm *pcm;
Rene Hermanae596182007-02-14 13:26:17 +0100126 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Krzysztof Helt396fa822010-05-09 20:35:44 +0200128 error = snd_card_create(index[n], id[n], THIS_MODULE,
129 sizeof(struct snd_es1688), &card);
Takashi Iwaic95eadd2008-12-28 16:43:35 +0100130 if (error < 0)
131 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Krzysztof Helt396fa822010-05-09 20:35:44 +0200133 chip = card->private_data;
134
135 error = snd_es1688_legacy_create(card, chip, dev, n);
Rene Hermanae596182007-02-14 13:26:17 +0100136 if (error < 0)
137 goto out;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200138
Krzysztof Helt396fa822010-05-09 20:35:44 +0200139 error = snd_es1688_pcm(card, chip, 0, &pcm);
Rene Hermanae596182007-02-14 13:26:17 +0100140 if (error < 0)
141 goto out;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200142
Krzysztof Helt396fa822010-05-09 20:35:44 +0200143 error = snd_es1688_mixer(card, chip);
Rene Hermanae596182007-02-14 13:26:17 +0100144 if (error < 0)
145 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
147 strcpy(card->driver, "ES1688");
148 strcpy(card->shortname, pcm->name);
Rene Herman019608b2007-02-19 13:01:45 +0100149 sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i", pcm->name,
150 chip->port, chip->irq, chip->dma8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Krzysztof Helt880abd42009-01-30 19:20:29 +0100152 if (fm_port[n] == SNDRV_AUTO_PORT)
153 fm_port[n] = port[n]; /* share the same port */
154
155 if (fm_port[n] > 0) {
156 if (snd_opl3_create(card, fm_port[n], fm_port[n] + 2,
157 OPL3_HW_OPL3, 0, &opl3) < 0)
158 dev_warn(dev,
159 "opl3 not detected at 0x%lx\n", fm_port[n]);
160 else {
161 error = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
162 if (error < 0)
163 goto out;
164 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 }
166
Rene Herman019608b2007-02-19 13:01:45 +0100167 if (mpu_irq[n] >= 0 && mpu_irq[n] != SNDRV_AUTO_IRQ &&
168 chip->mpu_port > 0) {
169 error = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688,
170 chip->mpu_port, 0,
171 mpu_irq[n], IRQF_DISABLED, NULL);
Rene Hermanae596182007-02-14 13:26:17 +0100172 if (error < 0)
173 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 }
Takashi Iwai43bcd972005-09-05 17:19:20 +0200175
Rene Hermanae596182007-02-14 13:26:17 +0100176 snd_card_set_dev(card, dev);
Takashi Iwai43bcd972005-09-05 17:19:20 +0200177
Rene Hermanae596182007-02-14 13:26:17 +0100178 error = snd_card_register(card);
179 if (error < 0)
180 goto out;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200181
Rene Hermanae596182007-02-14 13:26:17 +0100182 dev_set_drvdata(dev, card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 return 0;
184
Rene Hermanae596182007-02-14 13:26:17 +0100185out: snd_card_free(card);
186 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187}
188
Rene Hermanae596182007-02-14 13:26:17 +0100189static int __devexit snd_es1688_remove(struct device *dev, unsigned int n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190{
Rene Hermanae596182007-02-14 13:26:17 +0100191 snd_card_free(dev_get_drvdata(dev));
192 dev_set_drvdata(dev, NULL);
Takashi Iwai2a571ed2005-11-17 17:13:30 +0100193 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194}
195
Rene Hermanae596182007-02-14 13:26:17 +0100196static struct isa_driver snd_es1688_driver = {
197 .match = snd_es1688_match,
Takashi Iwai2a571ed2005-11-17 17:13:30 +0100198 .probe = snd_es1688_probe,
Jean Delvare82ced6f2009-06-04 10:46:43 +0200199 .remove = __devexit_p(snd_es1688_remove),
Rene Hermanae596182007-02-14 13:26:17 +0100200#if 0 /* FIXME */
201 .suspend = snd_es1688_suspend,
202 .resume = snd_es1688_resume,
203#endif
Takashi Iwai2a571ed2005-11-17 17:13:30 +0100204 .driver = {
Rene Hermanae596182007-02-14 13:26:17 +0100205 .name = DEV_NAME
206 }
Takashi Iwai2a571ed2005-11-17 17:13:30 +0100207};
208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209static int __init alsa_card_es1688_init(void)
210{
Rene Hermanae596182007-02-14 13:26:17 +0100211 return isa_register_driver(&snd_es1688_driver, SNDRV_CARDS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212}
213
214static void __exit alsa_card_es1688_exit(void)
215{
Rene Hermanae596182007-02-14 13:26:17 +0100216 isa_unregister_driver(&snd_es1688_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217}
218
Rene Hermanae596182007-02-14 13:26:17 +0100219module_init(alsa_card_es1688_init);
220module_exit(alsa_card_es1688_exit);