diff options
Diffstat (limited to 'sound/isa/es1688/es1688.c')
-rw-r--r-- | sound/isa/es1688/es1688.c | 225 |
1 files changed, 190 insertions, 35 deletions
diff --git a/sound/isa/es1688/es1688.c b/sound/isa/es1688/es1688.c index 07df201ed8fa..0cde8131a575 100644 --- a/sound/isa/es1688/es1688.c +++ b/sound/isa/es1688/es1688.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/init.h> | 22 | #include <linux/init.h> |
23 | #include <linux/err.h> | 23 | #include <linux/err.h> |
24 | #include <linux/isa.h> | 24 | #include <linux/isa.h> |
25 | #include <linux/isapnp.h> | ||
25 | #include <linux/time.h> | 26 | #include <linux/time.h> |
26 | #include <linux/wait.h> | 27 | #include <linux/wait.h> |
27 | #include <linux/moduleparam.h> | 28 | #include <linux/moduleparam.h> |
@@ -45,8 +46,13 @@ MODULE_SUPPORTED_DEVICE("{{ESS,ES688 PnP AudioDrive,pnp:ESS0100}," | |||
45 | "{ESS,ES688 AudioDrive,pnp:ESS6881}," | 46 | "{ESS,ES688 AudioDrive,pnp:ESS6881}," |
46 | "{ESS,ES1688 AudioDrive,pnp:ESS1681}}"); | 47 | "{ESS,ES1688 AudioDrive,pnp:ESS1681}}"); |
47 | 48 | ||
49 | MODULE_ALIAS("snd_es968"); | ||
50 | |||
48 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ | 51 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
49 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ | 52 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
53 | #ifdef CONFIG_PNP | ||
54 | static int isapnp[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; | ||
55 | #endif | ||
50 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */ | 56 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */ |
51 | static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260 */ | 57 | static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260 */ |
52 | static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* Usually 0x388 */ | 58 | static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* Usually 0x388 */ |
@@ -60,6 +66,10 @@ MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard."); | |||
60 | module_param_array(id, charp, NULL, 0444); | 66 | module_param_array(id, charp, NULL, 0444); |
61 | MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard."); | 67 | MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard."); |
62 | module_param_array(enable, bool, NULL, 0444); | 68 | module_param_array(enable, bool, NULL, 0444); |
69 | #ifdef CONFIG_PNP | ||
70 | module_param_array(isapnp, bool, NULL, 0444); | ||
71 | MODULE_PARM_DESC(isapnp, "PnP detection for specified soundcard."); | ||
72 | #endif | ||
63 | MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard."); | 73 | MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard."); |
64 | module_param_array(port, long, NULL, 0444); | 74 | module_param_array(port, long, NULL, 0444); |
65 | MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver."); | 75 | MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver."); |
@@ -74,14 +84,21 @@ MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " CRD_NAME " driver."); | |||
74 | module_param_array(dma8, int, NULL, 0444); | 84 | module_param_array(dma8, int, NULL, 0444); |
75 | MODULE_PARM_DESC(dma8, "8-bit DMA # for " CRD_NAME " driver."); | 85 | MODULE_PARM_DESC(dma8, "8-bit DMA # for " CRD_NAME " driver."); |
76 | 86 | ||
87 | #ifdef CONFIG_PNP | ||
88 | #define is_isapnp_selected(dev) isapnp[dev] | ||
89 | #else | ||
90 | #define is_isapnp_selected(dev) 0 | ||
91 | #endif | ||
92 | |||
77 | static int __devinit snd_es1688_match(struct device *dev, unsigned int n) | 93 | static int __devinit snd_es1688_match(struct device *dev, unsigned int n) |
78 | { | 94 | { |
79 | return enable[n]; | 95 | return enable[n] && !is_isapnp_selected(n); |
80 | } | 96 | } |
81 | 97 | ||
82 | static int __devinit snd_es1688_legacy_create(struct snd_card *card, | 98 | static int __devinit snd_es1688_legacy_create(struct snd_card *card, |
83 | struct device *dev, unsigned int n, struct snd_es1688 **rchip) | 99 | struct device *dev, unsigned int n) |
84 | { | 100 | { |
101 | struct snd_es1688 *chip = card->private_data; | ||
85 | static long possible_ports[] = {0x220, 0x240, 0x260}; | 102 | static long possible_ports[] = {0x220, 0x240, 0x260}; |
86 | static int possible_irqs[] = {5, 9, 10, 7, -1}; | 103 | static int possible_irqs[] = {5, 9, 10, 7, -1}; |
87 | static int possible_dmas[] = {1, 3, 0, -1}; | 104 | static int possible_dmas[] = {1, 3, 0, -1}; |
@@ -104,47 +121,39 @@ static int __devinit snd_es1688_legacy_create(struct snd_card *card, | |||
104 | } | 121 | } |
105 | 122 | ||
106 | if (port[n] != SNDRV_AUTO_PORT) | 123 | if (port[n] != SNDRV_AUTO_PORT) |
107 | return snd_es1688_create(card, port[n], mpu_port[n], irq[n], | 124 | return snd_es1688_create(card, chip, port[n], mpu_port[n], |
108 | mpu_irq[n], dma8[n], ES1688_HW_AUTO, rchip); | 125 | irq[n], mpu_irq[n], dma8[n], ES1688_HW_AUTO); |
109 | 126 | ||
110 | i = 0; | 127 | i = 0; |
111 | do { | 128 | do { |
112 | port[n] = possible_ports[i]; | 129 | port[n] = possible_ports[i]; |
113 | error = snd_es1688_create(card, port[n], mpu_port[n], irq[n], | 130 | error = snd_es1688_create(card, chip, port[n], mpu_port[n], |
114 | mpu_irq[n], dma8[n], ES1688_HW_AUTO, rchip); | 131 | irq[n], mpu_irq[n], dma8[n], ES1688_HW_AUTO); |
115 | } while (error < 0 && ++i < ARRAY_SIZE(possible_ports)); | 132 | } while (error < 0 && ++i < ARRAY_SIZE(possible_ports)); |
116 | 133 | ||
117 | return error; | 134 | return error; |
118 | } | 135 | } |
119 | 136 | ||
120 | static int __devinit snd_es1688_probe(struct device *dev, unsigned int n) | 137 | static int __devinit snd_es1688_probe(struct snd_card *card, unsigned int n) |
121 | { | 138 | { |
122 | struct snd_card *card; | 139 | struct snd_es1688 *chip = card->private_data; |
123 | struct snd_es1688 *chip; | ||
124 | struct snd_opl3 *opl3; | 140 | struct snd_opl3 *opl3; |
125 | struct snd_pcm *pcm; | 141 | struct snd_pcm *pcm; |
126 | int error; | 142 | int error; |
127 | 143 | ||
128 | error = snd_card_create(index[n], id[n], THIS_MODULE, 0, &card); | 144 | error = snd_es1688_pcm(card, chip, 0, &pcm); |
129 | if (error < 0) | 145 | if (error < 0) |
130 | return error; | 146 | return error; |
131 | 147 | ||
132 | error = snd_es1688_legacy_create(card, dev, n, &chip); | 148 | error = snd_es1688_mixer(card, chip); |
133 | if (error < 0) | ||
134 | goto out; | ||
135 | |||
136 | error = snd_es1688_pcm(chip, 0, &pcm); | ||
137 | if (error < 0) | 149 | if (error < 0) |
138 | goto out; | 150 | return error; |
139 | |||
140 | error = snd_es1688_mixer(chip); | ||
141 | if (error < 0) | ||
142 | goto out; | ||
143 | 151 | ||
144 | strcpy(card->driver, "ES1688"); | 152 | strlcpy(card->driver, "ES1688", sizeof(card->driver)); |
145 | strcpy(card->shortname, pcm->name); | 153 | strlcpy(card->shortname, pcm->name, sizeof(card->shortname)); |
146 | sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i", pcm->name, | 154 | snprintf(card->longname, sizeof(card->longname), |
147 | chip->port, chip->irq, chip->dma8); | 155 | "%s at 0x%lx, irq %i, dma %i", pcm->name, chip->port, |
156 | chip->irq, chip->dma8); | ||
148 | 157 | ||
149 | if (fm_port[n] == SNDRV_AUTO_PORT) | 158 | if (fm_port[n] == SNDRV_AUTO_PORT) |
150 | fm_port[n] = port[n]; /* share the same port */ | 159 | fm_port[n] = port[n]; /* share the same port */ |
@@ -152,12 +161,12 @@ static int __devinit snd_es1688_probe(struct device *dev, unsigned int n) | |||
152 | if (fm_port[n] > 0) { | 161 | if (fm_port[n] > 0) { |
153 | if (snd_opl3_create(card, fm_port[n], fm_port[n] + 2, | 162 | if (snd_opl3_create(card, fm_port[n], fm_port[n] + 2, |
154 | OPL3_HW_OPL3, 0, &opl3) < 0) | 163 | OPL3_HW_OPL3, 0, &opl3) < 0) |
155 | dev_warn(dev, | 164 | dev_warn(card->dev, |
156 | "opl3 not detected at 0x%lx\n", fm_port[n]); | 165 | "opl3 not detected at 0x%lx\n", fm_port[n]); |
157 | else { | 166 | else { |
158 | error = snd_opl3_hwdep_new(opl3, 0, 1, NULL); | 167 | error = snd_opl3_hwdep_new(opl3, 0, 1, NULL); |
159 | if (error < 0) | 168 | if (error < 0) |
160 | goto out; | 169 | return error; |
161 | } | 170 | } |
162 | } | 171 | } |
163 | 172 | ||
@@ -167,23 +176,41 @@ static int __devinit snd_es1688_probe(struct device *dev, unsigned int n) | |||
167 | chip->mpu_port, 0, | 176 | chip->mpu_port, 0, |
168 | mpu_irq[n], IRQF_DISABLED, NULL); | 177 | mpu_irq[n], IRQF_DISABLED, NULL); |
169 | if (error < 0) | 178 | if (error < 0) |
170 | goto out; | 179 | return error; |
171 | } | 180 | } |
172 | 181 | ||
182 | return snd_card_register(card); | ||
183 | } | ||
184 | |||
185 | static int __devinit snd_es1688_isa_probe(struct device *dev, unsigned int n) | ||
186 | { | ||
187 | struct snd_card *card; | ||
188 | int error; | ||
189 | |||
190 | error = snd_card_create(index[n], id[n], THIS_MODULE, | ||
191 | sizeof(struct snd_es1688), &card); | ||
192 | if (error < 0) | ||
193 | return error; | ||
194 | |||
195 | error = snd_es1688_legacy_create(card, dev, n); | ||
196 | if (error < 0) | ||
197 | goto out; | ||
198 | |||
173 | snd_card_set_dev(card, dev); | 199 | snd_card_set_dev(card, dev); |
174 | 200 | ||
175 | error = snd_card_register(card); | 201 | error = snd_es1688_probe(card, n); |
176 | if (error < 0) | 202 | if (error < 0) |
177 | goto out; | 203 | goto out; |
178 | 204 | ||
179 | dev_set_drvdata(dev, card); | 205 | dev_set_drvdata(dev, card); |
180 | return 0; | ||
181 | 206 | ||
182 | out: snd_card_free(card); | 207 | return 0; |
208 | out: | ||
209 | snd_card_free(card); | ||
183 | return error; | 210 | return error; |
184 | } | 211 | } |
185 | 212 | ||
186 | static int __devexit snd_es1688_remove(struct device *dev, unsigned int n) | 213 | static int __devexit snd_es1688_isa_remove(struct device *dev, unsigned int n) |
187 | { | 214 | { |
188 | snd_card_free(dev_get_drvdata(dev)); | 215 | snd_card_free(dev_get_drvdata(dev)); |
189 | dev_set_drvdata(dev, NULL); | 216 | dev_set_drvdata(dev, NULL); |
@@ -192,8 +219,8 @@ static int __devexit snd_es1688_remove(struct device *dev, unsigned int n) | |||
192 | 219 | ||
193 | static struct isa_driver snd_es1688_driver = { | 220 | static struct isa_driver snd_es1688_driver = { |
194 | .match = snd_es1688_match, | 221 | .match = snd_es1688_match, |
195 | .probe = snd_es1688_probe, | 222 | .probe = snd_es1688_isa_probe, |
196 | .remove = __devexit_p(snd_es1688_remove), | 223 | .remove = __devexit_p(snd_es1688_isa_remove), |
197 | #if 0 /* FIXME */ | 224 | #if 0 /* FIXME */ |
198 | .suspend = snd_es1688_suspend, | 225 | .suspend = snd_es1688_suspend, |
199 | .resume = snd_es1688_resume, | 226 | .resume = snd_es1688_resume, |
@@ -203,14 +230,142 @@ static struct isa_driver snd_es1688_driver = { | |||
203 | } | 230 | } |
204 | }; | 231 | }; |
205 | 232 | ||
233 | static int snd_es968_pnp_is_probed; | ||
234 | |||
235 | #ifdef CONFIG_PNP | ||
236 | static int __devinit snd_card_es968_pnp(struct snd_card *card, unsigned int n, | ||
237 | struct pnp_card_link *pcard, | ||
238 | const struct pnp_card_device_id *pid) | ||
239 | { | ||
240 | struct snd_es1688 *chip = card->private_data; | ||
241 | struct pnp_dev *pdev; | ||
242 | int error; | ||
243 | |||
244 | pdev = pnp_request_card_device(pcard, pid->devs[0].id, NULL); | ||
245 | if (pdev == NULL) | ||
246 | return -ENODEV; | ||
247 | |||
248 | error = pnp_activate_dev(pdev); | ||
249 | if (error < 0) { | ||
250 | snd_printk(KERN_ERR "ES968 pnp configure failure\n"); | ||
251 | return error; | ||
252 | } | ||
253 | port[n] = pnp_port_start(pdev, 0); | ||
254 | dma8[n] = pnp_dma(pdev, 0); | ||
255 | irq[n] = pnp_irq(pdev, 0); | ||
256 | |||
257 | return snd_es1688_create(card, chip, port[n], mpu_port[n], irq[n], | ||
258 | mpu_irq[n], dma8[n], ES1688_HW_AUTO); | ||
259 | } | ||
260 | |||
261 | static int __devinit snd_es968_pnp_detect(struct pnp_card_link *pcard, | ||
262 | const struct pnp_card_device_id *pid) | ||
263 | { | ||
264 | struct snd_card *card; | ||
265 | static unsigned int dev; | ||
266 | int error; | ||
267 | struct snd_es1688 *chip; | ||
268 | |||
269 | if (snd_es968_pnp_is_probed) | ||
270 | return -EBUSY; | ||
271 | for ( ; dev < SNDRV_CARDS; dev++) { | ||
272 | if (enable[dev] && isapnp[dev]) | ||
273 | break; | ||
274 | } | ||
275 | if (dev == SNDRV_CARDS) | ||
276 | return -ENODEV; | ||
277 | |||
278 | error = snd_card_create(index[dev], id[dev], THIS_MODULE, | ||
279 | sizeof(struct snd_es1688), &card); | ||
280 | if (error < 0) | ||
281 | return error; | ||
282 | chip = card->private_data; | ||
283 | |||
284 | error = snd_card_es968_pnp(card, dev, pcard, pid); | ||
285 | if (error < 0) { | ||
286 | snd_card_free(card); | ||
287 | return error; | ||
288 | } | ||
289 | snd_card_set_dev(card, &pcard->card->dev); | ||
290 | error = snd_es1688_probe(card, dev); | ||
291 | if (error < 0) | ||
292 | return error; | ||
293 | pnp_set_card_drvdata(pcard, card); | ||
294 | snd_es968_pnp_is_probed = 1; | ||
295 | return 0; | ||
296 | } | ||
297 | |||
298 | static void __devexit snd_es968_pnp_remove(struct pnp_card_link * pcard) | ||
299 | { | ||
300 | snd_card_free(pnp_get_card_drvdata(pcard)); | ||
301 | pnp_set_card_drvdata(pcard, NULL); | ||
302 | snd_es968_pnp_is_probed = 0; | ||
303 | } | ||
304 | |||
305 | #ifdef CONFIG_PM | ||
306 | static int snd_es968_pnp_suspend(struct pnp_card_link *pcard, | ||
307 | pm_message_t state) | ||
308 | { | ||
309 | struct snd_card *card = pnp_get_card_drvdata(pcard); | ||
310 | struct snd_es1688 *chip = card->private_data; | ||
311 | |||
312 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); | ||
313 | snd_pcm_suspend_all(chip->pcm); | ||
314 | return 0; | ||
315 | } | ||
316 | |||
317 | static int snd_es968_pnp_resume(struct pnp_card_link *pcard) | ||
318 | { | ||
319 | struct snd_card *card = pnp_get_card_drvdata(pcard); | ||
320 | struct snd_es1688 *chip = card->private_data; | ||
321 | |||
322 | snd_es1688_reset(chip); | ||
323 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); | ||
324 | return 0; | ||
325 | } | ||
326 | #endif | ||
327 | |||
328 | static struct pnp_card_device_id snd_es968_pnpids[] = { | ||
329 | { .id = "ESS0968", .devs = { { "@@@0968" }, } }, | ||
330 | { .id = "ESS0968", .devs = { { "ESS0968" }, } }, | ||
331 | { .id = "", } /* end */ | ||
332 | }; | ||
333 | |||
334 | MODULE_DEVICE_TABLE(pnp_card, snd_es968_pnpids); | ||
335 | |||
336 | static struct pnp_card_driver es968_pnpc_driver = { | ||
337 | .flags = PNP_DRIVER_RES_DISABLE, | ||
338 | .name = DEV_NAME " PnP", | ||
339 | .id_table = snd_es968_pnpids, | ||
340 | .probe = snd_es968_pnp_detect, | ||
341 | .remove = __devexit_p(snd_es968_pnp_remove), | ||
342 | #ifdef CONFIG_PM | ||
343 | .suspend = snd_es968_pnp_suspend, | ||
344 | .resume = snd_es968_pnp_resume, | ||
345 | #endif | ||
346 | }; | ||
347 | #endif | ||
348 | |||
206 | static int __init alsa_card_es1688_init(void) | 349 | static int __init alsa_card_es1688_init(void) |
207 | { | 350 | { |
351 | #ifdef CONFIG_PNP | ||
352 | pnp_register_card_driver(&es968_pnpc_driver); | ||
353 | if (snd_es968_pnp_is_probed) | ||
354 | return 0; | ||
355 | pnp_unregister_card_driver(&es968_pnpc_driver); | ||
356 | #endif | ||
208 | return isa_register_driver(&snd_es1688_driver, SNDRV_CARDS); | 357 | return isa_register_driver(&snd_es1688_driver, SNDRV_CARDS); |
209 | } | 358 | } |
210 | 359 | ||
211 | static void __exit alsa_card_es1688_exit(void) | 360 | static void __exit alsa_card_es1688_exit(void) |
212 | { | 361 | { |
213 | isa_unregister_driver(&snd_es1688_driver); | 362 | if (!snd_es968_pnp_is_probed) { |
363 | isa_unregister_driver(&snd_es1688_driver); | ||
364 | return; | ||
365 | } | ||
366 | #ifdef CONFIG_PNP | ||
367 | pnp_unregister_card_driver(&es968_pnpc_driver); | ||
368 | #endif | ||
214 | } | 369 | } |
215 | 370 | ||
216 | module_init(alsa_card_es1688_init); | 371 | module_init(alsa_card_es1688_init); |