aboutsummaryrefslogtreecommitdiffstats
path: root/sound/isa/es1688/es1688.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/isa/es1688/es1688.c')
-rw-r--r--sound/isa/es1688/es1688.c251
1 files changed, 111 insertions, 140 deletions
diff --git a/sound/isa/es1688/es1688.c b/sound/isa/es1688/es1688.c
index 65f97ff4eef..edc398712e8 100644
--- a/sound/isa/es1688/es1688.c
+++ b/sound/isa/es1688/es1688.c
@@ -22,7 +22,7 @@
22#include <sound/driver.h> 22#include <sound/driver.h>
23#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/err.h> 24#include <linux/err.h>
25#include <linux/platform_device.h> 25#include <linux/isa.h>
26#include <linux/time.h> 26#include <linux/time.h>
27#include <linux/wait.h> 27#include <linux/wait.h>
28#include <linux/moduleparam.h> 28#include <linux/moduleparam.h>
@@ -35,8 +35,11 @@
35#define SNDRV_LEGACY_FIND_FREE_DMA 35#define SNDRV_LEGACY_FIND_FREE_DMA
36#include <sound/initval.h> 36#include <sound/initval.h>
37 37
38#define CRD_NAME "Generic ESS ES1688/ES688 AudioDrive"
39#define DEV_NAME "es1688"
40
41MODULE_DESCRIPTION(CRD_NAME);
38MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); 42MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
39MODULE_DESCRIPTION("ESS ESx688 AudioDrive");
40MODULE_LICENSE("GPL"); 43MODULE_LICENSE("GPL");
41MODULE_SUPPORTED_DEVICE("{{ESS,ES688 PnP AudioDrive,pnp:ESS0100}," 44MODULE_SUPPORTED_DEVICE("{{ESS,ES688 PnP AudioDrive,pnp:ESS0100},"
42 "{ESS,ES1688 PnP AudioDrive,pnp:ESS0102}," 45 "{ESS,ES1688 PnP AudioDrive,pnp:ESS0102},"
@@ -53,189 +56,157 @@ static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
53static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */ 56static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */
54 57
55module_param_array(index, int, NULL, 0444); 58module_param_array(index, int, NULL, 0444);
56MODULE_PARM_DESC(index, "Index value for ESx688 soundcard."); 59MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
57module_param_array(id, charp, NULL, 0444); 60module_param_array(id, charp, NULL, 0444);
58MODULE_PARM_DESC(id, "ID string for ESx688 soundcard."); 61MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
59module_param_array(enable, bool, NULL, 0444); 62module_param_array(enable, bool, NULL, 0444);
60MODULE_PARM_DESC(enable, "Enable ESx688 soundcard."); 63MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
61module_param_array(port, long, NULL, 0444); 64module_param_array(port, long, NULL, 0444);
62MODULE_PARM_DESC(port, "Port # for ESx688 driver."); 65MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
63module_param_array(mpu_port, long, NULL, 0444); 66module_param_array(mpu_port, long, NULL, 0444);
64MODULE_PARM_DESC(mpu_port, "MPU-401 port # for ESx688 driver."); 67MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " CRD_NAME " driver.");
65module_param_array(irq, int, NULL, 0444); 68module_param_array(irq, int, NULL, 0444);
66MODULE_PARM_DESC(irq, "IRQ # for ESx688 driver."); 69MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver.");
67module_param_array(mpu_irq, int, NULL, 0444); 70module_param_array(mpu_irq, int, NULL, 0444);
68MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for ESx688 driver."); 71MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " CRD_NAME " driver.");
69module_param_array(dma8, int, NULL, 0444); 72module_param_array(dma8, int, NULL, 0444);
70MODULE_PARM_DESC(dma8, "8-bit DMA # for ESx688 driver."); 73MODULE_PARM_DESC(dma8, "8-bit DMA # for " CRD_NAME " driver.");
71
72static struct platform_device *devices[SNDRV_CARDS];
73 74
74#define PFX "es1688: " 75static int __devinit snd_es1688_match(struct device *dev, unsigned int n)
76{
77 return enable[n];
78}
75 79
76static int __devinit snd_es1688_probe(struct platform_device *pdev) 80static int __devinit snd_es1688_legacy_create(struct snd_card *card,
81 struct device *dev, unsigned int n, struct snd_es1688 **rchip)
77{ 82{
78 int dev = pdev->id; 83 static long possible_ports[] = {0x220, 0x240, 0x260};
79 static int possible_irqs[] = {5, 9, 10, 7, -1}; 84 static int possible_irqs[] = {5, 9, 10, 7, -1};
80 static int possible_dmas[] = {1, 3, 0, -1}; 85 static int possible_dmas[] = {1, 3, 0, -1};
81 int xirq, xdma, xmpu_irq; 86
82 struct snd_card *card; 87 int i, error;
83 struct snd_es1688 *chip; 88
84 struct snd_opl3 *opl3; 89 if (irq[n] == SNDRV_AUTO_IRQ) {
85 struct snd_pcm *pcm; 90 irq[n] = snd_legacy_find_free_irq(possible_irqs);
86 int err; 91 if (irq[n] < 0) {
87 92 snd_printk(KERN_ERR "%s: unable to find a free IRQ\n",
88 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 93 dev->bus_id);
89 if (card == NULL) 94 return -EBUSY;
90 return -ENOMEM;
91
92 xirq = irq[dev];
93 if (xirq == SNDRV_AUTO_IRQ) {
94 if ((xirq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
95 snd_printk(KERN_ERR PFX "unable to find a free IRQ\n");
96 err = -EBUSY;
97 goto _err;
98 } 95 }
99 } 96 }
100 xmpu_irq = mpu_irq[dev]; 97 if (dma8[n] == SNDRV_AUTO_DMA) {
101 xdma = dma8[dev]; 98 dma8[n] = snd_legacy_find_free_dma(possible_dmas);
102 if (xdma == SNDRV_AUTO_DMA) { 99 if (dma8[n] < 0) {
103 if ((xdma = snd_legacy_find_free_dma(possible_dmas)) < 0) { 100 snd_printk(KERN_ERR "%s: unable to find a free DMA\n",
104 snd_printk(KERN_ERR PFX "unable to find a free DMA\n"); 101 dev->bus_id);
105 err = -EBUSY; 102 return -EBUSY;
106 goto _err;
107 } 103 }
108 } 104 }
109 105
110 if (port[dev] != SNDRV_AUTO_PORT) { 106 if (port[n] != SNDRV_AUTO_PORT)
111 if ((err = snd_es1688_create(card, port[dev], mpu_port[dev], 107 return snd_es1688_create(card, port[n], mpu_port[n], irq[n],
112 xirq, xmpu_irq, xdma, 108 mpu_irq[n], dma8[n], ES1688_HW_AUTO, rchip);
113 ES1688_HW_AUTO, &chip)) < 0) 109
114 goto _err; 110 i = 0;
115 } else { 111 do {
116 /* auto-probe legacy ports */ 112 port[n] = possible_ports[i];
117 static unsigned long possible_ports[] = { 113 error = snd_es1688_create(card, port[n], mpu_port[n], irq[n],
118 0x220, 0x240, 0x260, 114 mpu_irq[n], dma8[n], ES1688_HW_AUTO, rchip);
119 }; 115 } while (error < 0 && ++i < ARRAY_SIZE(possible_ports));
120 int i; 116
121 for (i = 0; i < ARRAY_SIZE(possible_ports); i++) { 117 return error;
122 err = snd_es1688_create(card, possible_ports[i], 118}
123 mpu_port[dev], 119
124 xirq, xmpu_irq, xdma, 120static int __devinit snd_es1688_probe(struct device *dev, unsigned int n)
125 ES1688_HW_AUTO, &chip); 121{
126 if (err >= 0) { 122 struct snd_card *card;
127 port[dev] = possible_ports[i]; 123 struct snd_es1688 *chip;
128 break; 124 struct snd_opl3 *opl3;
129 } 125 struct snd_pcm *pcm;
130 } 126 int error;
131 if (i >= ARRAY_SIZE(possible_ports)) 127
132 goto _err; 128 card = snd_card_new(index[n], id[n], THIS_MODULE, 0);
133 } 129 if (!card)
130 return -EINVAL;
131
132 error = snd_es1688_legacy_create(card, dev, n, &chip);
133 if (error < 0)
134 goto out;
134 135
135 if ((err = snd_es1688_pcm(chip, 0, &pcm)) < 0) 136 error = snd_es1688_pcm(chip, 0, &pcm);
136 goto _err; 137 if (error < 0)
138 goto out;
137 139
138 if ((err = snd_es1688_mixer(chip)) < 0) 140 error = snd_es1688_mixer(chip);
139 goto _err; 141 if (error < 0)
142 goto out;
140 143
141 strcpy(card->driver, "ES1688"); 144 strcpy(card->driver, "ES1688");
142 strcpy(card->shortname, pcm->name); 145 strcpy(card->shortname, pcm->name);
143 sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i", pcm->name, chip->port, xirq, xdma); 146 sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i", pcm->name,
144 147 chip->port, chip->irq, chip->dma8);
145 if ((snd_opl3_create(card, chip->port, chip->port + 2, OPL3_HW_OPL3, 0, &opl3)) < 0) { 148
146 printk(KERN_WARNING PFX "opl3 not detected at 0x%lx\n", chip->port); 149 if (snd_opl3_create(card, chip->port, chip->port + 2,
147 } else { 150 OPL3_HW_OPL3, 0, &opl3) < 0)
148 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) 151 printk(KERN_WARNING "%s: opl3 not detected at 0x%lx\n",
149 goto _err; 152 dev->bus_id, chip->port);
153 else {
154 error = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
155 if (error < 0)
156 goto out;
150 } 157 }
151 158
152 if (xmpu_irq >= 0 && xmpu_irq != SNDRV_AUTO_IRQ && chip->mpu_port > 0) { 159 if (mpu_irq[n] >= 0 && mpu_irq[n] != SNDRV_AUTO_IRQ &&
153 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688, 160 chip->mpu_port > 0) {
154 chip->mpu_port, 0, 161 error = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688,
155 xmpu_irq, 162 chip->mpu_port, 0,
156 IRQF_DISABLED, 163 mpu_irq[n], IRQF_DISABLED, NULL);
157 NULL)) < 0) 164 if (error < 0)
158 goto _err; 165 goto out;
159 } 166 }
160 167
161 snd_card_set_dev(card, &pdev->dev); 168 snd_card_set_dev(card, dev);
162 169
163 if ((err = snd_card_register(card)) < 0) 170 error = snd_card_register(card);
164 goto _err; 171 if (error < 0)
172 goto out;
165 173
166 platform_set_drvdata(pdev, card); 174 dev_set_drvdata(dev, card);
167 return 0; 175 return 0;
168 176
169 _err: 177out: snd_card_free(card);
170 snd_card_free(card); 178 return error;
171 return err;
172} 179}
173 180
174static int __devexit snd_es1688_remove(struct platform_device *devptr) 181static int __devexit snd_es1688_remove(struct device *dev, unsigned int n)
175{ 182{
176 snd_card_free(platform_get_drvdata(devptr)); 183 snd_card_free(dev_get_drvdata(dev));
177 platform_set_drvdata(devptr, NULL); 184 dev_set_drvdata(dev, NULL);
178 return 0; 185 return 0;
179} 186}
180 187
181#define ES1688_DRIVER "snd_es1688" 188static struct isa_driver snd_es1688_driver = {
182 189 .match = snd_es1688_match,
183static struct platform_driver snd_es1688_driver = {
184 .probe = snd_es1688_probe, 190 .probe = snd_es1688_probe,
185 .remove = __devexit_p(snd_es1688_remove), 191 .remove = snd_es1688_remove,
186 /* FIXME: suspend/resume */ 192#if 0 /* FIXME */
193 .suspend = snd_es1688_suspend,
194 .resume = snd_es1688_resume,
195#endif
187 .driver = { 196 .driver = {
188 .name = ES1688_DRIVER 197 .name = DEV_NAME
189 }, 198 }
190}; 199};
191 200
192static void __init_or_module snd_es1688_unregister_all(void)
193{
194 int i;
195
196 for (i = 0; i < ARRAY_SIZE(devices); ++i)
197 platform_device_unregister(devices[i]);
198 platform_driver_unregister(&snd_es1688_driver);
199}
200
201static int __init alsa_card_es1688_init(void) 201static int __init alsa_card_es1688_init(void)
202{ 202{
203 int i, cards, err; 203 return isa_register_driver(&snd_es1688_driver, SNDRV_CARDS);
204
205 err = platform_driver_register(&snd_es1688_driver);
206 if (err < 0)
207 return err;
208
209 cards = 0;
210 for (i = 0; i < SNDRV_CARDS; i++) {
211 struct platform_device *device;
212 if (! enable[i])
213 continue;
214 device = platform_device_register_simple(ES1688_DRIVER,
215 i, NULL, 0);
216 if (IS_ERR(device))
217 continue;
218 if (!platform_get_drvdata(device)) {
219 platform_device_unregister(device);
220 continue;
221 }
222 devices[i] = device;
223 cards++;
224 }
225 if (!cards) {
226#ifdef MODULE
227 printk(KERN_ERR "ESS AudioDrive ES1688 soundcard not found or device busy\n");
228#endif
229 snd_es1688_unregister_all();
230 return -ENODEV;
231 }
232 return 0;
233} 204}
234 205
235static void __exit alsa_card_es1688_exit(void) 206static void __exit alsa_card_es1688_exit(void)
236{ 207{
237 snd_es1688_unregister_all(); 208 isa_unregister_driver(&snd_es1688_driver);
238} 209}
239 210
240module_init(alsa_card_es1688_init) 211module_init(alsa_card_es1688_init);
241module_exit(alsa_card_es1688_exit) 212module_exit(alsa_card_es1688_exit);