aboutsummaryrefslogtreecommitdiffstats
path: root/sound/isa
diff options
context:
space:
mode:
Diffstat (limited to 'sound/isa')
-rw-r--r--sound/isa/es1688/es1688.c217
1 files changed, 87 insertions, 130 deletions
diff --git a/sound/isa/es1688/es1688.c b/sound/isa/es1688/es1688.c
index 65f97ff4eef1..f7d0c5fab5d9 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,143 @@ 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_probe(struct device *dev, unsigned int n)
77{ 81{
78 int dev = pdev->id; 82 static unsigned long possible_ports[] = {0x220, 0x240, 0x260};
79 static int possible_irqs[] = {5, 9, 10, 7, -1}; 83 static int possible_irqs[] = {5, 9, 10, 7, -1};
80 static int possible_dmas[] = {1, 3, 0, -1}; 84 static int possible_dmas[] = {1, 3, 0, -1};
81 int xirq, xdma, xmpu_irq; 85 int i, xirq, xdma;
86
82 struct snd_card *card; 87 struct snd_card *card;
83 struct snd_es1688 *chip; 88 struct snd_es1688 *chip;
84 struct snd_opl3 *opl3; 89 struct snd_opl3 *opl3;
85 struct snd_pcm *pcm; 90 struct snd_pcm *pcm;
86 int err; 91 int error;
92
93 card = snd_card_new(index[n], id[n], THIS_MODULE, 0);
94 if (!card)
95 return -EINVAL;
87 96
88 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 97 error = -EBUSY;
89 if (card == NULL)
90 return -ENOMEM;
91 98
92 xirq = irq[dev]; 99 xirq = irq[n];
93 if (xirq == SNDRV_AUTO_IRQ) { 100 if (xirq == SNDRV_AUTO_IRQ) {
94 if ((xirq = snd_legacy_find_free_irq(possible_irqs)) < 0) { 101 xirq = snd_legacy_find_free_irq(possible_irqs);
95 snd_printk(KERN_ERR PFX "unable to find a free IRQ\n"); 102 if (xirq < 0) {
96 err = -EBUSY; 103 snd_printk(KERN_ERR "%s: unable to find a free IRQ\n", dev->bus_id);
97 goto _err; 104 goto out;
98 } 105 }
99 } 106 }
100 xmpu_irq = mpu_irq[dev]; 107
101 xdma = dma8[dev]; 108 xdma = dma8[n];
102 if (xdma == SNDRV_AUTO_DMA) { 109 if (xdma == SNDRV_AUTO_DMA) {
103 if ((xdma = snd_legacy_find_free_dma(possible_dmas)) < 0) { 110 xdma = snd_legacy_find_free_dma(possible_dmas);
104 snd_printk(KERN_ERR PFX "unable to find a free DMA\n"); 111 if (xdma < 0) {
105 err = -EBUSY; 112 snd_printk(KERN_ERR "%s: unable to find a free DMA\n", dev->bus_id);
106 goto _err; 113 goto out;
107 } 114 }
108 } 115 }
109 116
110 if (port[dev] != SNDRV_AUTO_PORT) { 117 if (port[n] == SNDRV_AUTO_PORT)
111 if ((err = snd_es1688_create(card, port[dev], mpu_port[dev], 118 for (i = 0; i < ARRAY_SIZE(possible_ports) && error < 0; i++)
112 xirq, xmpu_irq, xdma, 119 error = snd_es1688_create(card, possible_ports[i], mpu_port[n],
113 ES1688_HW_AUTO, &chip)) < 0) 120 xirq, mpu_irq[n], xdma, ES1688_HW_AUTO, &chip);
114 goto _err; 121 else
115 } else { 122 error = snd_es1688_create(card, port[n], mpu_port[n],
116 /* auto-probe legacy ports */ 123 xirq, mpu_irq[n], xdma, ES1688_HW_AUTO, &chip);
117 static unsigned long possible_ports[] = { 124 if (error < 0)
118 0x220, 0x240, 0x260, 125 goto out;
119 };
120 int i;
121 for (i = 0; i < ARRAY_SIZE(possible_ports); i++) {
122 err = snd_es1688_create(card, possible_ports[i],
123 mpu_port[dev],
124 xirq, xmpu_irq, xdma,
125 ES1688_HW_AUTO, &chip);
126 if (err >= 0) {
127 port[dev] = possible_ports[i];
128 break;
129 }
130 }
131 if (i >= ARRAY_SIZE(possible_ports))
132 goto _err;
133 }
134 126
135 if ((err = snd_es1688_pcm(chip, 0, &pcm)) < 0) 127 error = snd_es1688_pcm(chip, 0, &pcm);
136 goto _err; 128 if (error < 0)
129 goto out;
137 130
138 if ((err = snd_es1688_mixer(chip)) < 0) 131 error = snd_es1688_mixer(chip);
139 goto _err; 132 if (error < 0)
133 goto out;
140 134
141 strcpy(card->driver, "ES1688"); 135 strcpy(card->driver, "ES1688");
142 strcpy(card->shortname, pcm->name); 136 strcpy(card->shortname, pcm->name);
143 sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i", pcm->name, chip->port, xirq, xdma); 137 sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i", pcm->name, chip->port, xirq, xdma);
144 138
145 if ((snd_opl3_create(card, chip->port, chip->port + 2, OPL3_HW_OPL3, 0, &opl3)) < 0) { 139 if (snd_opl3_create(card, chip->port, chip->port + 2, OPL3_HW_OPL3, 0, &opl3) < 0)
146 printk(KERN_WARNING PFX "opl3 not detected at 0x%lx\n", chip->port); 140 printk(KERN_WARNING "%s: opl3 not detected at 0x%lx\n", dev->bus_id, chip->port);
147 } else { 141 else {
148 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) 142 error = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
149 goto _err; 143 if (error < 0)
144 goto out;
150 } 145 }
151 146
152 if (xmpu_irq >= 0 && xmpu_irq != SNDRV_AUTO_IRQ && chip->mpu_port > 0) { 147 if (mpu_irq[n] >= 0 && mpu_irq[n] != SNDRV_AUTO_IRQ && chip->mpu_port > 0) {
153 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688, 148 error = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688, chip->mpu_port,
154 chip->mpu_port, 0, 149 0, mpu_irq[n], IRQF_DISABLED, NULL);
155 xmpu_irq, 150 if (error < 0)
156 IRQF_DISABLED, 151 goto out;
157 NULL)) < 0)
158 goto _err;
159 } 152 }
160 153
161 snd_card_set_dev(card, &pdev->dev); 154 snd_card_set_dev(card, dev);
162 155
163 if ((err = snd_card_register(card)) < 0) 156 error = snd_card_register(card);
164 goto _err; 157 if (error < 0)
158 goto out;
165 159
166 platform_set_drvdata(pdev, card); 160 dev_set_drvdata(dev, card);
167 return 0; 161 return 0;
168 162
169 _err: 163out: snd_card_free(card);
170 snd_card_free(card); 164 return error;
171 return err;
172} 165}
173 166
174static int __devexit snd_es1688_remove(struct platform_device *devptr) 167static int __devexit snd_es1688_remove(struct device *dev, unsigned int n)
175{ 168{
176 snd_card_free(platform_get_drvdata(devptr)); 169 snd_card_free(dev_get_drvdata(dev));
177 platform_set_drvdata(devptr, NULL); 170 dev_set_drvdata(dev, NULL);
178 return 0; 171 return 0;
179} 172}
180 173
181#define ES1688_DRIVER "snd_es1688" 174static struct isa_driver snd_es1688_driver = {
182 175 .match = snd_es1688_match,
183static struct platform_driver snd_es1688_driver = {
184 .probe = snd_es1688_probe, 176 .probe = snd_es1688_probe,
185 .remove = __devexit_p(snd_es1688_remove), 177 .remove = snd_es1688_remove,
186 /* FIXME: suspend/resume */ 178#if 0 /* FIXME */
179 .suspend = snd_es1688_suspend,
180 .resume = snd_es1688_resume,
181#endif
187 .driver = { 182 .driver = {
188 .name = ES1688_DRIVER 183 .name = DEV_NAME
189 }, 184 }
190}; 185};
191 186
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) 187static int __init alsa_card_es1688_init(void)
202{ 188{
203 int i, cards, err; 189 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} 190}
234 191
235static void __exit alsa_card_es1688_exit(void) 192static void __exit alsa_card_es1688_exit(void)
236{ 193{
237 snd_es1688_unregister_all(); 194 isa_unregister_driver(&snd_es1688_driver);
238} 195}
239 196
240module_init(alsa_card_es1688_init) 197module_init(alsa_card_es1688_init);
241module_exit(alsa_card_es1688_exit) 198module_exit(alsa_card_es1688_exit);