diff options
Diffstat (limited to 'sound/isa')
-rw-r--r-- | sound/isa/gus/gusclassic.c | 292 |
1 files changed, 130 insertions, 162 deletions
diff --git a/sound/isa/gus/gusclassic.c b/sound/isa/gus/gusclassic.c index 0395e2e0dd03..8f23f433d491 100644 --- a/sound/isa/gus/gusclassic.c +++ b/sound/isa/gus/gusclassic.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/delay.h> | 26 | #include <linux/delay.h> |
27 | #include <linux/time.h> | 27 | #include <linux/time.h> |
28 | #include <linux/moduleparam.h> | 28 | #include <linux/moduleparam.h> |
@@ -33,8 +33,11 @@ | |||
33 | #define SNDRV_LEGACY_FIND_FREE_DMA | 33 | #define SNDRV_LEGACY_FIND_FREE_DMA |
34 | #include <sound/initval.h> | 34 | #include <sound/initval.h> |
35 | 35 | ||
36 | #define CRD_NAME "Gravis UltraSound Classic" | ||
37 | #define DEV_NAME "gusclassic" | ||
38 | |||
39 | MODULE_DESCRIPTION(CRD_NAME); | ||
36 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); | 40 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); |
37 | MODULE_DESCRIPTION("Gravis UltraSound Classic"); | ||
38 | MODULE_LICENSE("GPL"); | 41 | MODULE_LICENSE("GPL"); |
39 | MODULE_SUPPORTED_DEVICE("{{Gravis,UltraSound Classic}}"); | 42 | MODULE_SUPPORTED_DEVICE("{{Gravis,UltraSound Classic}}"); |
40 | 43 | ||
@@ -51,32 +54,80 @@ static int channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 24}; | |||
51 | static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2}; | 54 | static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2}; |
52 | 55 | ||
53 | module_param_array(index, int, NULL, 0444); | 56 | module_param_array(index, int, NULL, 0444); |
54 | MODULE_PARM_DESC(index, "Index value for GUS Classic soundcard."); | 57 | MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard."); |
55 | module_param_array(id, charp, NULL, 0444); | 58 | module_param_array(id, charp, NULL, 0444); |
56 | MODULE_PARM_DESC(id, "ID string for GUS Classic soundcard."); | 59 | MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard."); |
57 | module_param_array(enable, bool, NULL, 0444); | 60 | module_param_array(enable, bool, NULL, 0444); |
58 | MODULE_PARM_DESC(enable, "Enable GUS Classic soundcard."); | 61 | MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard."); |
59 | module_param_array(port, long, NULL, 0444); | 62 | module_param_array(port, long, NULL, 0444); |
60 | MODULE_PARM_DESC(port, "Port # for GUS Classic driver."); | 63 | MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver."); |
61 | module_param_array(irq, int, NULL, 0444); | 64 | module_param_array(irq, int, NULL, 0444); |
62 | MODULE_PARM_DESC(irq, "IRQ # for GUS Classic driver."); | 65 | MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver."); |
63 | module_param_array(dma1, int, NULL, 0444); | 66 | module_param_array(dma1, int, NULL, 0444); |
64 | MODULE_PARM_DESC(dma1, "DMA1 # for GUS Classic driver."); | 67 | MODULE_PARM_DESC(dma1, "DMA1 # for " CRD_NAME " driver."); |
65 | module_param_array(dma2, int, NULL, 0444); | 68 | module_param_array(dma2, int, NULL, 0444); |
66 | MODULE_PARM_DESC(dma2, "DMA2 # for GUS Classic driver."); | 69 | MODULE_PARM_DESC(dma2, "DMA2 # for " CRD_NAME " driver."); |
67 | module_param_array(joystick_dac, int, NULL, 0444); | 70 | module_param_array(joystick_dac, int, NULL, 0444); |
68 | MODULE_PARM_DESC(joystick_dac, "Joystick DAC level 0.59V-4.52V or 0.389V-2.98V for GUS Classic driver."); | 71 | MODULE_PARM_DESC(joystick_dac, "Joystick DAC level 0.59V-4.52V or 0.389V-2.98V for " CRD_NAME " driver."); |
69 | module_param_array(channels, int, NULL, 0444); | 72 | module_param_array(channels, int, NULL, 0444); |
70 | MODULE_PARM_DESC(channels, "GF1 channels for GUS Classic driver."); | 73 | MODULE_PARM_DESC(channels, "GF1 channels for " CRD_NAME " driver."); |
71 | module_param_array(pcm_channels, int, NULL, 0444); | 74 | module_param_array(pcm_channels, int, NULL, 0444); |
72 | MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for GUS Classic driver."); | 75 | MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for " CRD_NAME " driver."); |
76 | |||
77 | static int __devinit snd_gusclassic_match(struct device *dev, unsigned int n) | ||
78 | { | ||
79 | return enable[n]; | ||
80 | } | ||
81 | |||
82 | static int __devinit snd_gusclassic_create(struct snd_card *card, | ||
83 | struct device *dev, unsigned int n, struct snd_gus_card **rgus) | ||
84 | { | ||
85 | static long possible_ports[] = {0x220, 0x230, 0x240, 0x250, 0x260}; | ||
86 | static int possible_irqs[] = {5, 11, 12, 9, 7, 15, 3, 4, -1}; | ||
87 | static int possible_dmas[] = {5, 6, 7, 1, 3, -1}; | ||
88 | |||
89 | 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) { | ||
94 | snd_printk(KERN_ERR "%s: unable to find a free IRQ\n", | ||
95 | dev->bus_id); | ||
96 | return -EBUSY; | ||
97 | } | ||
98 | } | ||
99 | if (dma1[n] == SNDRV_AUTO_DMA) { | ||
100 | dma1[n] = snd_legacy_find_free_dma(possible_dmas); | ||
101 | if (dma1[n] < 0) { | ||
102 | snd_printk(KERN_ERR "%s: unable to find a free DMA1\n", | ||
103 | dev->bus_id); | ||
104 | return -EBUSY; | ||
105 | } | ||
106 | } | ||
107 | if (dma2[n] == SNDRV_AUTO_DMA) { | ||
108 | dma2[n] = snd_legacy_find_free_dma(possible_dmas); | ||
109 | if (dma2[n] < 0) { | ||
110 | snd_printk(KERN_ERR "%s: unable to find a free DMA2\n", | ||
111 | dev->bus_id); | ||
112 | return -EBUSY; | ||
113 | } | ||
114 | } | ||
73 | 115 | ||
74 | static struct platform_device *devices[SNDRV_CARDS]; | 116 | if (port[n] != SNDRV_AUTO_PORT) |
117 | return snd_gus_create(card, port[n], irq[n], dma1[n], dma2[n], | ||
118 | 0, channels[n], pcm_channels[n], 0, rgus); | ||
75 | 119 | ||
120 | i = 0; | ||
121 | do { | ||
122 | port[n] = possible_ports[i]; | ||
123 | error = snd_gus_create(card, port[n], irq[n], dma1[n], dma2[n], | ||
124 | 0, channels[n], pcm_channels[n], 0, rgus); | ||
125 | } while (error < 0 && ++i < ARRAY_SIZE(possible_ports)); | ||
76 | 126 | ||
77 | #define PFX "gusclassic: " | 127 | return error; |
128 | } | ||
78 | 129 | ||
79 | static int __devinit snd_gusclassic_detect(struct snd_gus_card * gus) | 130 | static int __devinit snd_gusclassic_detect(struct snd_gus_card *gus) |
80 | { | 131 | { |
81 | unsigned char d; | 132 | unsigned char d; |
82 | 133 | ||
@@ -95,187 +146,104 @@ static int __devinit snd_gusclassic_detect(struct snd_gus_card * gus) | |||
95 | return 0; | 146 | return 0; |
96 | } | 147 | } |
97 | 148 | ||
98 | static void __devinit snd_gusclassic_init(int dev, struct snd_gus_card * gus) | 149 | static int __devinit snd_gusclassic_probe(struct device *dev, unsigned int n) |
99 | { | ||
100 | gus->equal_irq = 0; | ||
101 | gus->codec_flag = 0; | ||
102 | gus->max_flag = 0; | ||
103 | gus->joystick_dac = joystick_dac[dev]; | ||
104 | } | ||
105 | |||
106 | static int __devinit snd_gusclassic_probe(struct platform_device *pdev) | ||
107 | { | 150 | { |
108 | int dev = pdev->id; | ||
109 | static int possible_irqs[] = {5, 11, 12, 9, 7, 15, 3, 4, -1}; | ||
110 | static int possible_dmas[] = {5, 6, 7, 1, 3, -1}; | ||
111 | int xirq, xdma1, xdma2; | ||
112 | struct snd_card *card; | 151 | struct snd_card *card; |
113 | struct snd_gus_card *gus = NULL; | 152 | struct snd_gus_card *gus; |
114 | int err; | 153 | int error; |
115 | |||
116 | card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); | ||
117 | if (card == NULL) | ||
118 | return -ENOMEM; | ||
119 | if (pcm_channels[dev] < 2) | ||
120 | pcm_channels[dev] = 2; | ||
121 | |||
122 | xirq = irq[dev]; | ||
123 | if (xirq == SNDRV_AUTO_IRQ) { | ||
124 | if ((xirq = snd_legacy_find_free_irq(possible_irqs)) < 0) { | ||
125 | snd_printk(KERN_ERR PFX "unable to find a free IRQ\n"); | ||
126 | err = -EBUSY; | ||
127 | goto _err; | ||
128 | } | ||
129 | } | ||
130 | xdma1 = dma1[dev]; | ||
131 | if (xdma1 == SNDRV_AUTO_DMA) { | ||
132 | if ((xdma1 = snd_legacy_find_free_dma(possible_dmas)) < 0) { | ||
133 | snd_printk(KERN_ERR PFX "unable to find a free DMA1\n"); | ||
134 | err = -EBUSY; | ||
135 | goto _err; | ||
136 | } | ||
137 | } | ||
138 | xdma2 = dma2[dev]; | ||
139 | if (xdma2 == SNDRV_AUTO_DMA) { | ||
140 | if ((xdma2 = snd_legacy_find_free_dma(possible_dmas)) < 0) { | ||
141 | snd_printk(KERN_ERR PFX "unable to find a free DMA2\n"); | ||
142 | err = -EBUSY; | ||
143 | goto _err; | ||
144 | } | ||
145 | } | ||
146 | 154 | ||
147 | if (port[dev] != SNDRV_AUTO_PORT) { | 155 | card = snd_card_new(index[n], id[n], THIS_MODULE, 0); |
148 | err = snd_gus_create(card, | 156 | if (!card) |
149 | port[dev], | 157 | return -EINVAL; |
150 | xirq, xdma1, xdma2, | ||
151 | 0, channels[dev], pcm_channels[dev], | ||
152 | 0, &gus); | ||
153 | } else { | ||
154 | /* auto-probe legacy ports */ | ||
155 | static unsigned long possible_ports[] = { | ||
156 | 0x220, 0x230, 0x240, 0x250, 0x260, | ||
157 | }; | ||
158 | int i; | ||
159 | for (i = 0; i < ARRAY_SIZE(possible_ports); i++) { | ||
160 | err = snd_gus_create(card, | ||
161 | possible_ports[i], | ||
162 | xirq, xdma1, xdma2, | ||
163 | 0, channels[dev], pcm_channels[dev], | ||
164 | 0, &gus); | ||
165 | if (err >= 0) { | ||
166 | port[dev] = possible_ports[i]; | ||
167 | break; | ||
168 | } | ||
169 | } | ||
170 | } | ||
171 | if (err < 0) | ||
172 | goto _err; | ||
173 | 158 | ||
174 | if ((err = snd_gusclassic_detect(gus)) < 0) | 159 | if (pcm_channels[n] < 2) |
175 | goto _err; | 160 | pcm_channels[n] = 2; |
176 | 161 | ||
177 | snd_gusclassic_init(dev, gus); | 162 | error = snd_gusclassic_create(card, dev, n, &gus); |
178 | if ((err = snd_gus_initialize(gus)) < 0) | 163 | if (error < 0) |
179 | goto _err; | 164 | goto out; |
180 | 165 | ||
166 | error = snd_gusclassic_detect(gus); | ||
167 | if (error < 0) | ||
168 | goto out; | ||
169 | |||
170 | gus->joystick_dac = joystick_dac[n]; | ||
171 | |||
172 | error = snd_gus_initialize(gus); | ||
173 | if (error < 0) | ||
174 | goto out; | ||
175 | |||
176 | error = -ENODEV; | ||
181 | if (gus->max_flag || gus->ess_flag) { | 177 | if (gus->max_flag || gus->ess_flag) { |
182 | snd_printk(KERN_ERR PFX "GUS Classic or ACE soundcard was not detected at 0x%lx\n", gus->gf1.port); | 178 | snd_printk(KERN_ERR "%s: GUS Classic or ACE soundcard was " |
183 | err = -ENODEV; | 179 | "not detected at 0x%lx\n", dev->bus_id, gus->gf1.port); |
184 | goto _err; | 180 | goto out; |
185 | } | 181 | } |
186 | 182 | ||
187 | if ((err = snd_gf1_new_mixer(gus)) < 0) | 183 | error = snd_gf1_new_mixer(gus); |
188 | goto _err; | 184 | if (error < 0) |
185 | goto out; | ||
189 | 186 | ||
190 | if ((err = snd_gf1_pcm_new(gus, 0, 0, NULL)) < 0) | 187 | error = snd_gf1_pcm_new(gus, 0, 0, NULL); |
191 | goto _err; | 188 | if (error < 0) |
189 | goto out; | ||
192 | 190 | ||
193 | if (!gus->ace_flag) { | 191 | if (!gus->ace_flag) { |
194 | if ((err = snd_gf1_rawmidi_new(gus, 0, NULL)) < 0) | 192 | error = snd_gf1_rawmidi_new(gus, 0, NULL); |
195 | goto _err; | 193 | if (error < 0) |
194 | goto out; | ||
196 | } | 195 | } |
197 | sprintf(card->longname + strlen(card->longname), " at 0x%lx, irq %d, dma %d", gus->gf1.port, xirq, xdma1); | ||
198 | if (xdma2 >= 0) | ||
199 | sprintf(card->longname + strlen(card->longname), "&%d", xdma2); | ||
200 | 196 | ||
201 | snd_card_set_dev(card, &pdev->dev); | 197 | sprintf(card->longname + strlen(card->longname), |
198 | " at 0x%lx, irq %d, dma %d", | ||
199 | gus->gf1.port, gus->gf1.irq, gus->gf1.dma1); | ||
202 | 200 | ||
203 | if ((err = snd_card_register(card)) < 0) | 201 | if (gus->gf1.dma2 >= 0) |
204 | goto _err; | 202 | sprintf(card->longname + strlen(card->longname), |
203 | "&%d", gus->gf1.dma2); | ||
205 | 204 | ||
206 | platform_set_drvdata(pdev, card); | 205 | snd_card_set_dev(card, dev); |
206 | |||
207 | error = snd_card_register(card); | ||
208 | if (error < 0) | ||
209 | goto out; | ||
210 | |||
211 | dev_set_drvdata(dev, card); | ||
207 | return 0; | 212 | return 0; |
208 | 213 | ||
209 | _err: | 214 | out: snd_card_free(card); |
210 | snd_card_free(card); | 215 | return error; |
211 | return err; | ||
212 | } | 216 | } |
213 | 217 | ||
214 | static int __devexit snd_gusclassic_remove(struct platform_device *devptr) | 218 | static int __devexit snd_gusclassic_remove(struct device *dev, unsigned int n) |
215 | { | 219 | { |
216 | snd_card_free(platform_get_drvdata(devptr)); | 220 | snd_card_free(dev_get_drvdata(dev)); |
217 | platform_set_drvdata(devptr, NULL); | 221 | dev_set_drvdata(dev, NULL); |
218 | return 0; | 222 | return 0; |
219 | } | 223 | } |
220 | 224 | ||
221 | #define GUSCLASSIC_DRIVER "snd_gusclassic" | 225 | static struct isa_driver snd_gusclassic_driver = { |
222 | 226 | .match = snd_gusclassic_match, | |
223 | static struct platform_driver snd_gusclassic_driver = { | ||
224 | .probe = snd_gusclassic_probe, | 227 | .probe = snd_gusclassic_probe, |
225 | .remove = __devexit_p(snd_gusclassic_remove), | 228 | .remove = __devexit_p(snd_gusclassic_remove), |
226 | /* FIXME: suspend/resume */ | 229 | #if 0 /* FIXME */ |
230 | .suspend = snd_gusclassic_suspend, | ||
231 | .remove = snd_gusclassic_remove, | ||
232 | #endif | ||
227 | .driver = { | 233 | .driver = { |
228 | .name = GUSCLASSIC_DRIVER | 234 | .name = DEV_NAME |
229 | }, | 235 | } |
230 | }; | 236 | }; |
231 | 237 | ||
232 | static void __init_or_module snd_gusclassic_unregister_all(void) | ||
233 | { | ||
234 | int i; | ||
235 | |||
236 | for (i = 0; i < ARRAY_SIZE(devices); ++i) | ||
237 | platform_device_unregister(devices[i]); | ||
238 | platform_driver_unregister(&snd_gusclassic_driver); | ||
239 | } | ||
240 | |||
241 | static int __init alsa_card_gusclassic_init(void) | 238 | static int __init alsa_card_gusclassic_init(void) |
242 | { | 239 | { |
243 | int i, cards, err; | 240 | return isa_register_driver(&snd_gusclassic_driver, SNDRV_CARDS); |
244 | |||
245 | err = platform_driver_register(&snd_gusclassic_driver); | ||
246 | if (err < 0) | ||
247 | return err; | ||
248 | |||
249 | cards = 0; | ||
250 | for (i = 0; i < SNDRV_CARDS; i++) { | ||
251 | struct platform_device *device; | ||
252 | if (! enable[i]) | ||
253 | continue; | ||
254 | device = platform_device_register_simple(GUSCLASSIC_DRIVER, | ||
255 | i, NULL, 0); | ||
256 | if (IS_ERR(device)) | ||
257 | continue; | ||
258 | if (!platform_get_drvdata(device)) { | ||
259 | platform_device_unregister(device); | ||
260 | continue; | ||
261 | } | ||
262 | devices[i] = device; | ||
263 | cards++; | ||
264 | } | ||
265 | if (!cards) { | ||
266 | #ifdef MODULE | ||
267 | printk(KERN_ERR "GUS Classic soundcard not found or device busy\n"); | ||
268 | #endif | ||
269 | snd_gusclassic_unregister_all(); | ||
270 | return -ENODEV; | ||
271 | } | ||
272 | return 0; | ||
273 | } | 241 | } |
274 | 242 | ||
275 | static void __exit alsa_card_gusclassic_exit(void) | 243 | static void __exit alsa_card_gusclassic_exit(void) |
276 | { | 244 | { |
277 | snd_gusclassic_unregister_all(); | 245 | isa_unregister_driver(&snd_gusclassic_driver); |
278 | } | 246 | } |
279 | 247 | ||
280 | module_init(alsa_card_gusclassic_init) | 248 | module_init(alsa_card_gusclassic_init); |
281 | module_exit(alsa_card_gusclassic_exit) | 249 | module_exit(alsa_card_gusclassic_exit); |