diff options
Diffstat (limited to 'sound/isa/es1688/es1688.c')
-rw-r--r-- | sound/isa/es1688/es1688.c | 251 |
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 | |||
41 | MODULE_DESCRIPTION(CRD_NAME); | ||
38 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); | 42 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); |
39 | MODULE_DESCRIPTION("ESS ESx688 AudioDrive"); | ||
40 | MODULE_LICENSE("GPL"); | 43 | MODULE_LICENSE("GPL"); |
41 | MODULE_SUPPORTED_DEVICE("{{ESS,ES688 PnP AudioDrive,pnp:ESS0100}," | 44 | MODULE_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 */ | |||
53 | static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */ | 56 | static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */ |
54 | 57 | ||
55 | module_param_array(index, int, NULL, 0444); | 58 | module_param_array(index, int, NULL, 0444); |
56 | MODULE_PARM_DESC(index, "Index value for ESx688 soundcard."); | 59 | MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard."); |
57 | module_param_array(id, charp, NULL, 0444); | 60 | module_param_array(id, charp, NULL, 0444); |
58 | MODULE_PARM_DESC(id, "ID string for ESx688 soundcard."); | 61 | MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard."); |
59 | module_param_array(enable, bool, NULL, 0444); | 62 | module_param_array(enable, bool, NULL, 0444); |
60 | MODULE_PARM_DESC(enable, "Enable ESx688 soundcard."); | 63 | MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard."); |
61 | module_param_array(port, long, NULL, 0444); | 64 | module_param_array(port, long, NULL, 0444); |
62 | MODULE_PARM_DESC(port, "Port # for ESx688 driver."); | 65 | MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver."); |
63 | module_param_array(mpu_port, long, NULL, 0444); | 66 | module_param_array(mpu_port, long, NULL, 0444); |
64 | MODULE_PARM_DESC(mpu_port, "MPU-401 port # for ESx688 driver."); | 67 | MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " CRD_NAME " driver."); |
65 | module_param_array(irq, int, NULL, 0444); | 68 | module_param_array(irq, int, NULL, 0444); |
66 | MODULE_PARM_DESC(irq, "IRQ # for ESx688 driver."); | 69 | MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver."); |
67 | module_param_array(mpu_irq, int, NULL, 0444); | 70 | module_param_array(mpu_irq, int, NULL, 0444); |
68 | MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for ESx688 driver."); | 71 | MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " CRD_NAME " driver."); |
69 | module_param_array(dma8, int, NULL, 0444); | 72 | module_param_array(dma8, int, NULL, 0444); |
70 | MODULE_PARM_DESC(dma8, "8-bit DMA # for ESx688 driver."); | 73 | MODULE_PARM_DESC(dma8, "8-bit DMA # for " CRD_NAME " driver."); |
71 | |||
72 | static struct platform_device *devices[SNDRV_CARDS]; | ||
73 | 74 | ||
74 | #define PFX "es1688: " | 75 | static int __devinit snd_es1688_match(struct device *dev, unsigned int n) |
76 | { | ||
77 | return enable[n]; | ||
78 | } | ||
75 | 79 | ||
76 | static int __devinit snd_es1688_probe(struct platform_device *pdev) | 80 | static 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, | 120 | static 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: | 177 | out: snd_card_free(card); |
170 | snd_card_free(card); | 178 | return error; |
171 | return err; | ||
172 | } | 179 | } |
173 | 180 | ||
174 | static int __devexit snd_es1688_remove(struct platform_device *devptr) | 181 | static 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" | 188 | static struct isa_driver snd_es1688_driver = { |
182 | 189 | .match = snd_es1688_match, | |
183 | static 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 | ||
192 | static 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 | |||
201 | static int __init alsa_card_es1688_init(void) | 201 | static 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 | ||
235 | static void __exit alsa_card_es1688_exit(void) | 206 | static 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 | ||
240 | module_init(alsa_card_es1688_init) | 211 | module_init(alsa_card_es1688_init); |
241 | module_exit(alsa_card_es1688_exit) | 212 | module_exit(alsa_card_es1688_exit); |