diff options
Diffstat (limited to 'sound/isa/opti9xx/miro.c')
-rw-r--r-- | sound/isa/opti9xx/miro.c | 786 |
1 files changed, 511 insertions, 275 deletions
diff --git a/sound/isa/opti9xx/miro.c b/sound/isa/opti9xx/miro.c index 02e30d7c6a93..8c24102d0d93 100644 --- a/sound/isa/opti9xx/miro.c +++ b/sound/isa/opti9xx/miro.c | |||
@@ -25,8 +25,8 @@ | |||
25 | #include <linux/init.h> | 25 | #include <linux/init.h> |
26 | #include <linux/err.h> | 26 | #include <linux/err.h> |
27 | #include <linux/isa.h> | 27 | #include <linux/isa.h> |
28 | #include <linux/pnp.h> | ||
28 | #include <linux/delay.h> | 29 | #include <linux/delay.h> |
29 | #include <linux/slab.h> | ||
30 | #include <linux/ioport.h> | 30 | #include <linux/ioport.h> |
31 | #include <linux/moduleparam.h> | 31 | #include <linux/moduleparam.h> |
32 | #include <asm/io.h> | 32 | #include <asm/io.h> |
@@ -40,7 +40,7 @@ | |||
40 | #define SNDRV_LEGACY_FIND_FREE_IRQ | 40 | #define SNDRV_LEGACY_FIND_FREE_IRQ |
41 | #define SNDRV_LEGACY_FIND_FREE_DMA | 41 | #define SNDRV_LEGACY_FIND_FREE_DMA |
42 | #include <sound/initval.h> | 42 | #include <sound/initval.h> |
43 | #include "miro.h" | 43 | #include <sound/aci.h> |
44 | 44 | ||
45 | MODULE_AUTHOR("Martin Langer <martin-langer@gmx.de>"); | 45 | MODULE_AUTHOR("Martin Langer <martin-langer@gmx.de>"); |
46 | MODULE_LICENSE("GPL"); | 46 | MODULE_LICENSE("GPL"); |
@@ -60,6 +60,9 @@ static int dma1 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */ | |||
60 | static int dma2 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */ | 60 | static int dma2 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */ |
61 | static int wss; | 61 | static int wss; |
62 | static int ide; | 62 | static int ide; |
63 | #ifdef CONFIG_PNP | ||
64 | static int isapnp = 1; /* Enable ISA PnP detection */ | ||
65 | #endif | ||
63 | 66 | ||
64 | module_param(index, int, 0444); | 67 | module_param(index, int, 0444); |
65 | MODULE_PARM_DESC(index, "Index value for miro soundcard."); | 68 | MODULE_PARM_DESC(index, "Index value for miro soundcard."); |
@@ -83,6 +86,10 @@ module_param(wss, int, 0444); | |||
83 | MODULE_PARM_DESC(wss, "wss mode"); | 86 | MODULE_PARM_DESC(wss, "wss mode"); |
84 | module_param(ide, int, 0444); | 87 | module_param(ide, int, 0444); |
85 | MODULE_PARM_DESC(ide, "enable ide port"); | 88 | MODULE_PARM_DESC(ide, "enable ide port"); |
89 | #ifdef CONFIG_PNP | ||
90 | module_param(isapnp, bool, 0444); | ||
91 | MODULE_PARM_DESC(isapnp, "Enable ISA PnP detection for specified soundcard."); | ||
92 | #endif | ||
86 | 93 | ||
87 | #define OPTi9XX_HW_DETECT 0 | 94 | #define OPTi9XX_HW_DETECT 0 |
88 | #define OPTi9XX_HW_82C928 1 | 95 | #define OPTi9XX_HW_82C928 1 |
@@ -96,7 +103,6 @@ MODULE_PARM_DESC(ide, "enable ide port"); | |||
96 | 103 | ||
97 | #define OPTi9XX_MC_REG(n) n | 104 | #define OPTi9XX_MC_REG(n) n |
98 | 105 | ||
99 | |||
100 | struct snd_miro { | 106 | struct snd_miro { |
101 | unsigned short hardware; | 107 | unsigned short hardware; |
102 | unsigned char password; | 108 | unsigned char password; |
@@ -110,7 +116,6 @@ struct snd_miro { | |||
110 | unsigned long pwd_reg; | 116 | unsigned long pwd_reg; |
111 | 117 | ||
112 | spinlock_t lock; | 118 | spinlock_t lock; |
113 | struct snd_card *card; | ||
114 | struct snd_pcm *pcm; | 119 | struct snd_pcm *pcm; |
115 | 120 | ||
116 | long wss_base; | 121 | long wss_base; |
@@ -118,42 +123,48 @@ struct snd_miro { | |||
118 | int dma1; | 123 | int dma1; |
119 | int dma2; | 124 | int dma2; |
120 | 125 | ||
121 | long fm_port; | ||
122 | |||
123 | long mpu_port; | 126 | long mpu_port; |
124 | int mpu_irq; | 127 | int mpu_irq; |
125 | 128 | ||
126 | unsigned long aci_port; | 129 | struct snd_miro_aci *aci; |
127 | int aci_vendor; | ||
128 | int aci_product; | ||
129 | int aci_version; | ||
130 | int aci_amp; | ||
131 | int aci_preamp; | ||
132 | int aci_solomode; | ||
133 | |||
134 | struct mutex aci_mutex; | ||
135 | }; | 130 | }; |
136 | 131 | ||
137 | static void snd_miro_proc_init(struct snd_miro * miro); | 132 | static struct snd_miro_aci aci_device; |
138 | 133 | ||
139 | static char * snd_opti9xx_names[] = { | 134 | static char * snd_opti9xx_names[] = { |
140 | "unkown", | 135 | "unknown", |
141 | "82C928", "82C929", | 136 | "82C928", "82C929", |
142 | "82C924", "82C925", | 137 | "82C924", "82C925", |
143 | "82C930", "82C931", "82C933" | 138 | "82C930", "82C931", "82C933" |
144 | }; | 139 | }; |
145 | 140 | ||
141 | static int snd_miro_pnp_is_probed; | ||
142 | |||
143 | #ifdef CONFIG_PNP | ||
144 | |||
145 | static struct pnp_card_device_id snd_miro_pnpids[] = { | ||
146 | /* PCM20 and PCM12 in PnP mode */ | ||
147 | { .id = "MIR0924", | ||
148 | .devs = { { "MIR0000" }, { "MIR0002" }, { "MIR0005" } }, }, | ||
149 | { .id = "" } | ||
150 | }; | ||
151 | |||
152 | MODULE_DEVICE_TABLE(pnp_card, snd_miro_pnpids); | ||
153 | |||
154 | #endif /* CONFIG_PNP */ | ||
155 | |||
146 | /* | 156 | /* |
147 | * ACI control | 157 | * ACI control |
148 | */ | 158 | */ |
149 | 159 | ||
150 | static int aci_busy_wait(struct snd_miro * miro) | 160 | static int aci_busy_wait(struct snd_miro_aci *aci) |
151 | { | 161 | { |
152 | long timeout; | 162 | long timeout; |
153 | unsigned char byte; | 163 | unsigned char byte; |
154 | 164 | ||
155 | for (timeout = 1; timeout <= ACI_MINTIME+30; timeout++) { | 165 | for (timeout = 1; timeout <= ACI_MINTIME + 30; timeout++) { |
156 | if (((byte=inb(miro->aci_port + ACI_REG_BUSY)) & 1) == 0) { | 166 | byte = inb(aci->aci_port + ACI_REG_BUSY); |
167 | if ((byte & 1) == 0) { | ||
157 | if (timeout >= ACI_MINTIME) | 168 | if (timeout >= ACI_MINTIME) |
158 | snd_printd("aci ready in round %ld.\n", | 169 | snd_printd("aci ready in round %ld.\n", |
159 | timeout-ACI_MINTIME); | 170 | timeout-ACI_MINTIME); |
@@ -179,10 +190,10 @@ static int aci_busy_wait(struct snd_miro * miro) | |||
179 | return -EBUSY; | 190 | return -EBUSY; |
180 | } | 191 | } |
181 | 192 | ||
182 | static inline int aci_write(struct snd_miro * miro, unsigned char byte) | 193 | static inline int aci_write(struct snd_miro_aci *aci, unsigned char byte) |
183 | { | 194 | { |
184 | if (aci_busy_wait(miro) >= 0) { | 195 | if (aci_busy_wait(aci) >= 0) { |
185 | outb(byte, miro->aci_port + ACI_REG_COMMAND); | 196 | outb(byte, aci->aci_port + ACI_REG_COMMAND); |
186 | return 0; | 197 | return 0; |
187 | } else { | 198 | } else { |
188 | snd_printk(KERN_ERR "aci busy, aci_write(0x%x) stopped.\n", byte); | 199 | snd_printk(KERN_ERR "aci busy, aci_write(0x%x) stopped.\n", byte); |
@@ -190,12 +201,12 @@ static inline int aci_write(struct snd_miro * miro, unsigned char byte) | |||
190 | } | 201 | } |
191 | } | 202 | } |
192 | 203 | ||
193 | static inline int aci_read(struct snd_miro * miro) | 204 | static inline int aci_read(struct snd_miro_aci *aci) |
194 | { | 205 | { |
195 | unsigned char byte; | 206 | unsigned char byte; |
196 | 207 | ||
197 | if (aci_busy_wait(miro) >= 0) { | 208 | if (aci_busy_wait(aci) >= 0) { |
198 | byte=inb(miro->aci_port + ACI_REG_STATUS); | 209 | byte = inb(aci->aci_port + ACI_REG_STATUS); |
199 | return byte; | 210 | return byte; |
200 | } else { | 211 | } else { |
201 | snd_printk(KERN_ERR "aci busy, aci_read() stopped.\n"); | 212 | snd_printk(KERN_ERR "aci busy, aci_read() stopped.\n"); |
@@ -203,39 +214,49 @@ static inline int aci_read(struct snd_miro * miro) | |||
203 | } | 214 | } |
204 | } | 215 | } |
205 | 216 | ||
206 | static int aci_cmd(struct snd_miro * miro, int write1, int write2, int write3) | 217 | int snd_aci_cmd(struct snd_miro_aci *aci, int write1, int write2, int write3) |
207 | { | 218 | { |
208 | int write[] = {write1, write2, write3}; | 219 | int write[] = {write1, write2, write3}; |
209 | int value, i; | 220 | int value, i; |
210 | 221 | ||
211 | if (mutex_lock_interruptible(&miro->aci_mutex)) | 222 | if (mutex_lock_interruptible(&aci->aci_mutex)) |
212 | return -EINTR; | 223 | return -EINTR; |
213 | 224 | ||
214 | for (i=0; i<3; i++) { | 225 | for (i=0; i<3; i++) { |
215 | if (write[i]< 0 || write[i] > 255) | 226 | if (write[i]< 0 || write[i] > 255) |
216 | break; | 227 | break; |
217 | else { | 228 | else { |
218 | value = aci_write(miro, write[i]); | 229 | value = aci_write(aci, write[i]); |
219 | if (value < 0) | 230 | if (value < 0) |
220 | goto out; | 231 | goto out; |
221 | } | 232 | } |
222 | } | 233 | } |
223 | 234 | ||
224 | value = aci_read(miro); | 235 | value = aci_read(aci); |
225 | 236 | ||
226 | out: mutex_unlock(&miro->aci_mutex); | 237 | out: mutex_unlock(&aci->aci_mutex); |
227 | return value; | 238 | return value; |
228 | } | 239 | } |
240 | EXPORT_SYMBOL(snd_aci_cmd); | ||
241 | |||
242 | static int aci_getvalue(struct snd_miro_aci *aci, unsigned char index) | ||
243 | { | ||
244 | return snd_aci_cmd(aci, ACI_STATUS, index, -1); | ||
245 | } | ||
229 | 246 | ||
230 | static int aci_getvalue(struct snd_miro * miro, unsigned char index) | 247 | static int aci_setvalue(struct snd_miro_aci *aci, unsigned char index, |
248 | int value) | ||
231 | { | 249 | { |
232 | return aci_cmd(miro, ACI_STATUS, index, -1); | 250 | return snd_aci_cmd(aci, index, value, -1); |
233 | } | 251 | } |
234 | 252 | ||
235 | static int aci_setvalue(struct snd_miro * miro, unsigned char index, int value) | 253 | struct snd_miro_aci *snd_aci_get_aci(void) |
236 | { | 254 | { |
237 | return aci_cmd(miro, index, value, -1); | 255 | if (aci_device.aci_port == 0) |
256 | return NULL; | ||
257 | return &aci_device; | ||
238 | } | 258 | } |
259 | EXPORT_SYMBOL(snd_aci_get_aci); | ||
239 | 260 | ||
240 | /* | 261 | /* |
241 | * MIXER part | 262 | * MIXER part |
@@ -249,8 +270,10 @@ static int snd_miro_get_capture(struct snd_kcontrol *kcontrol, | |||
249 | struct snd_miro *miro = snd_kcontrol_chip(kcontrol); | 270 | struct snd_miro *miro = snd_kcontrol_chip(kcontrol); |
250 | int value; | 271 | int value; |
251 | 272 | ||
252 | if ((value = aci_getvalue(miro, ACI_S_GENERAL)) < 0) { | 273 | value = aci_getvalue(miro->aci, ACI_S_GENERAL); |
253 | snd_printk(KERN_ERR "snd_miro_get_capture() failed: %d\n", value); | 274 | if (value < 0) { |
275 | snd_printk(KERN_ERR "snd_miro_get_capture() failed: %d\n", | ||
276 | value); | ||
254 | return value; | 277 | return value; |
255 | } | 278 | } |
256 | 279 | ||
@@ -267,13 +290,15 @@ static int snd_miro_put_capture(struct snd_kcontrol *kcontrol, | |||
267 | 290 | ||
268 | value = !(ucontrol->value.integer.value[0]); | 291 | value = !(ucontrol->value.integer.value[0]); |
269 | 292 | ||
270 | if ((error = aci_setvalue(miro, ACI_SET_SOLOMODE, value)) < 0) { | 293 | error = aci_setvalue(miro->aci, ACI_SET_SOLOMODE, value); |
271 | snd_printk(KERN_ERR "snd_miro_put_capture() failed: %d\n", error); | 294 | if (error < 0) { |
295 | snd_printk(KERN_ERR "snd_miro_put_capture() failed: %d\n", | ||
296 | error); | ||
272 | return error; | 297 | return error; |
273 | } | 298 | } |
274 | 299 | ||
275 | change = (value != miro->aci_solomode); | 300 | change = (value != miro->aci->aci_solomode); |
276 | miro->aci_solomode = value; | 301 | miro->aci->aci_solomode = value; |
277 | 302 | ||
278 | return change; | 303 | return change; |
279 | } | 304 | } |
@@ -295,7 +320,7 @@ static int snd_miro_get_preamp(struct snd_kcontrol *kcontrol, | |||
295 | struct snd_miro *miro = snd_kcontrol_chip(kcontrol); | 320 | struct snd_miro *miro = snd_kcontrol_chip(kcontrol); |
296 | int value; | 321 | int value; |
297 | 322 | ||
298 | if (miro->aci_version <= 176) { | 323 | if (miro->aci->aci_version <= 176) { |
299 | 324 | ||
300 | /* | 325 | /* |
301 | OSS says it's not readable with versions < 176. | 326 | OSS says it's not readable with versions < 176. |
@@ -303,12 +328,14 @@ static int snd_miro_get_preamp(struct snd_kcontrol *kcontrol, | |||
303 | which is a PCM12 with aci_version = 176. | 328 | which is a PCM12 with aci_version = 176. |
304 | */ | 329 | */ |
305 | 330 | ||
306 | ucontrol->value.integer.value[0] = miro->aci_preamp; | 331 | ucontrol->value.integer.value[0] = miro->aci->aci_preamp; |
307 | return 0; | 332 | return 0; |
308 | } | 333 | } |
309 | 334 | ||
310 | if ((value = aci_getvalue(miro, ACI_GET_PREAMP)) < 0) { | 335 | value = aci_getvalue(miro->aci, ACI_GET_PREAMP); |
311 | snd_printk(KERN_ERR "snd_miro_get_preamp() failed: %d\n", value); | 336 | if (value < 0) { |
337 | snd_printk(KERN_ERR "snd_miro_get_preamp() failed: %d\n", | ||
338 | value); | ||
312 | return value; | 339 | return value; |
313 | } | 340 | } |
314 | 341 | ||
@@ -325,13 +352,15 @@ static int snd_miro_put_preamp(struct snd_kcontrol *kcontrol, | |||
325 | 352 | ||
326 | value = ucontrol->value.integer.value[0]; | 353 | value = ucontrol->value.integer.value[0]; |
327 | 354 | ||
328 | if ((error = aci_setvalue(miro, ACI_SET_PREAMP, value)) < 0) { | 355 | error = aci_setvalue(miro->aci, ACI_SET_PREAMP, value); |
329 | snd_printk(KERN_ERR "snd_miro_put_preamp() failed: %d\n", error); | 356 | if (error < 0) { |
357 | snd_printk(KERN_ERR "snd_miro_put_preamp() failed: %d\n", | ||
358 | error); | ||
330 | return error; | 359 | return error; |
331 | } | 360 | } |
332 | 361 | ||
333 | change = (value != miro->aci_preamp); | 362 | change = (value != miro->aci->aci_preamp); |
334 | miro->aci_preamp = value; | 363 | miro->aci->aci_preamp = value; |
335 | 364 | ||
336 | return change; | 365 | return change; |
337 | } | 366 | } |
@@ -342,7 +371,7 @@ static int snd_miro_get_amp(struct snd_kcontrol *kcontrol, | |||
342 | struct snd_ctl_elem_value *ucontrol) | 371 | struct snd_ctl_elem_value *ucontrol) |
343 | { | 372 | { |
344 | struct snd_miro *miro = snd_kcontrol_chip(kcontrol); | 373 | struct snd_miro *miro = snd_kcontrol_chip(kcontrol); |
345 | ucontrol->value.integer.value[0] = miro->aci_amp; | 374 | ucontrol->value.integer.value[0] = miro->aci->aci_amp; |
346 | 375 | ||
347 | return 0; | 376 | return 0; |
348 | } | 377 | } |
@@ -355,13 +384,14 @@ static int snd_miro_put_amp(struct snd_kcontrol *kcontrol, | |||
355 | 384 | ||
356 | value = ucontrol->value.integer.value[0]; | 385 | value = ucontrol->value.integer.value[0]; |
357 | 386 | ||
358 | if ((error = aci_setvalue(miro, ACI_SET_POWERAMP, value)) < 0) { | 387 | error = aci_setvalue(miro->aci, ACI_SET_POWERAMP, value); |
388 | if (error < 0) { | ||
359 | snd_printk(KERN_ERR "snd_miro_put_amp() to %d failed: %d\n", value, error); | 389 | snd_printk(KERN_ERR "snd_miro_put_amp() to %d failed: %d\n", value, error); |
360 | return error; | 390 | return error; |
361 | } | 391 | } |
362 | 392 | ||
363 | change = (value != miro->aci_amp); | 393 | change = (value != miro->aci->aci_amp); |
364 | miro->aci_amp = value; | 394 | miro->aci->aci_amp = value; |
365 | 395 | ||
366 | return change; | 396 | return change; |
367 | } | 397 | } |
@@ -410,12 +440,14 @@ static int snd_miro_get_double(struct snd_kcontrol *kcontrol, | |||
410 | int right_reg = kcontrol->private_value & 0xff; | 440 | int right_reg = kcontrol->private_value & 0xff; |
411 | int left_reg = right_reg + 1; | 441 | int left_reg = right_reg + 1; |
412 | 442 | ||
413 | if ((right_val = aci_getvalue(miro, right_reg)) < 0) { | 443 | right_val = aci_getvalue(miro->aci, right_reg); |
444 | if (right_val < 0) { | ||
414 | snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", right_reg, right_val); | 445 | snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", right_reg, right_val); |
415 | return right_val; | 446 | return right_val; |
416 | } | 447 | } |
417 | 448 | ||
418 | if ((left_val = aci_getvalue(miro, left_reg)) < 0) { | 449 | left_val = aci_getvalue(miro->aci, left_reg); |
450 | if (left_val < 0) { | ||
419 | snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", left_reg, left_val); | 451 | snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", left_reg, left_val); |
420 | return left_val; | 452 | return left_val; |
421 | } | 453 | } |
@@ -451,6 +483,7 @@ static int snd_miro_put_double(struct snd_kcontrol *kcontrol, | |||
451 | struct snd_ctl_elem_value *ucontrol) | 483 | struct snd_ctl_elem_value *ucontrol) |
452 | { | 484 | { |
453 | struct snd_miro *miro = snd_kcontrol_chip(kcontrol); | 485 | struct snd_miro *miro = snd_kcontrol_chip(kcontrol); |
486 | struct snd_miro_aci *aci = miro->aci; | ||
454 | int left, right, left_old, right_old; | 487 | int left, right, left_old, right_old; |
455 | int setreg_left, setreg_right, getreg_left, getreg_right; | 488 | int setreg_left, setreg_right, getreg_left, getreg_right; |
456 | int change, error; | 489 | int change, error; |
@@ -459,21 +492,21 @@ static int snd_miro_put_double(struct snd_kcontrol *kcontrol, | |||
459 | right = ucontrol->value.integer.value[1]; | 492 | right = ucontrol->value.integer.value[1]; |
460 | 493 | ||
461 | setreg_right = (kcontrol->private_value >> 8) & 0xff; | 494 | setreg_right = (kcontrol->private_value >> 8) & 0xff; |
462 | if (setreg_right == ACI_SET_MASTER) { | 495 | setreg_left = setreg_right + 8; |
463 | setreg_left = setreg_right + 1; | 496 | if (setreg_right == ACI_SET_MASTER) |
464 | } else { | 497 | setreg_left -= 7; |
465 | setreg_left = setreg_right + 8; | ||
466 | } | ||
467 | 498 | ||
468 | getreg_right = kcontrol->private_value & 0xff; | 499 | getreg_right = kcontrol->private_value & 0xff; |
469 | getreg_left = getreg_right + 1; | 500 | getreg_left = getreg_right + 1; |
470 | 501 | ||
471 | if ((left_old = aci_getvalue(miro, getreg_left)) < 0) { | 502 | left_old = aci_getvalue(aci, getreg_left); |
503 | if (left_old < 0) { | ||
472 | snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", getreg_left, left_old); | 504 | snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", getreg_left, left_old); |
473 | return left_old; | 505 | return left_old; |
474 | } | 506 | } |
475 | 507 | ||
476 | if ((right_old = aci_getvalue(miro, getreg_right)) < 0) { | 508 | right_old = aci_getvalue(aci, getreg_right); |
509 | if (right_old < 0) { | ||
477 | snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", getreg_right, right_old); | 510 | snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", getreg_right, right_old); |
478 | return right_old; | 511 | return right_old; |
479 | } | 512 | } |
@@ -492,13 +525,15 @@ static int snd_miro_put_double(struct snd_kcontrol *kcontrol, | |||
492 | right_old = 0x80 - right_old; | 525 | right_old = 0x80 - right_old; |
493 | 526 | ||
494 | if (left >= 0) { | 527 | if (left >= 0) { |
495 | if ((error = aci_setvalue(miro, setreg_left, left)) < 0) { | 528 | error = aci_setvalue(aci, setreg_left, left); |
529 | if (error < 0) { | ||
496 | snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", | 530 | snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", |
497 | left, error); | 531 | left, error); |
498 | return error; | 532 | return error; |
499 | } | 533 | } |
500 | } else { | 534 | } else { |
501 | if ((error = aci_setvalue(miro, setreg_left, 0x80 - left)) < 0) { | 535 | error = aci_setvalue(aci, setreg_left, 0x80 - left); |
536 | if (error < 0) { | ||
502 | snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", | 537 | snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", |
503 | 0x80 - left, error); | 538 | 0x80 - left, error); |
504 | return error; | 539 | return error; |
@@ -506,13 +541,15 @@ static int snd_miro_put_double(struct snd_kcontrol *kcontrol, | |||
506 | } | 541 | } |
507 | 542 | ||
508 | if (right >= 0) { | 543 | if (right >= 0) { |
509 | if ((error = aci_setvalue(miro, setreg_right, right)) < 0) { | 544 | error = aci_setvalue(aci, setreg_right, right); |
545 | if (error < 0) { | ||
510 | snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", | 546 | snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", |
511 | right, error); | 547 | right, error); |
512 | return error; | 548 | return error; |
513 | } | 549 | } |
514 | } else { | 550 | } else { |
515 | if ((error = aci_setvalue(miro, setreg_right, 0x80 - right)) < 0) { | 551 | error = aci_setvalue(aci, setreg_right, 0x80 - right); |
552 | if (error < 0) { | ||
516 | snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", | 553 | snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", |
517 | 0x80 - right, error); | 554 | 0x80 - right, error); |
518 | return error; | 555 | return error; |
@@ -530,12 +567,14 @@ static int snd_miro_put_double(struct snd_kcontrol *kcontrol, | |||
530 | left_old = 0x20 - left_old; | 567 | left_old = 0x20 - left_old; |
531 | right_old = 0x20 - right_old; | 568 | right_old = 0x20 - right_old; |
532 | 569 | ||
533 | if ((error = aci_setvalue(miro, setreg_left, 0x20 - left)) < 0) { | 570 | error = aci_setvalue(aci, setreg_left, 0x20 - left); |
571 | if (error < 0) { | ||
534 | snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", | 572 | snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", |
535 | 0x20 - left, error); | 573 | 0x20 - left, error); |
536 | return error; | 574 | return error; |
537 | } | 575 | } |
538 | if ((error = aci_setvalue(miro, setreg_right, 0x20 - right)) < 0) { | 576 | error = aci_setvalue(aci, setreg_right, 0x20 - right); |
577 | if (error < 0) { | ||
539 | snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", | 578 | snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", |
540 | 0x20 - right, error); | 579 | 0x20 - right, error); |
541 | return error; | 580 | return error; |
@@ -633,11 +672,13 @@ static unsigned char aci_init_values[][2] __devinitdata = { | |||
633 | static int __devinit snd_set_aci_init_values(struct snd_miro *miro) | 672 | static int __devinit snd_set_aci_init_values(struct snd_miro *miro) |
634 | { | 673 | { |
635 | int idx, error; | 674 | int idx, error; |
675 | struct snd_miro_aci *aci = miro->aci; | ||
636 | 676 | ||
637 | /* enable WSS on PCM1 */ | 677 | /* enable WSS on PCM1 */ |
638 | 678 | ||
639 | if ((miro->aci_product == 'A') && wss) { | 679 | if ((aci->aci_product == 'A') && wss) { |
640 | if ((error = aci_setvalue(miro, ACI_SET_WSS, wss)) < 0) { | 680 | error = aci_setvalue(aci, ACI_SET_WSS, wss); |
681 | if (error < 0) { | ||
641 | snd_printk(KERN_ERR "enabling WSS mode failed\n"); | 682 | snd_printk(KERN_ERR "enabling WSS mode failed\n"); |
642 | return error; | 683 | return error; |
643 | } | 684 | } |
@@ -646,7 +687,8 @@ static int __devinit snd_set_aci_init_values(struct snd_miro *miro) | |||
646 | /* enable IDE port */ | 687 | /* enable IDE port */ |
647 | 688 | ||
648 | if (ide) { | 689 | if (ide) { |
649 | if ((error = aci_setvalue(miro, ACI_SET_IDE, ide)) < 0) { | 690 | error = aci_setvalue(aci, ACI_SET_IDE, ide); |
691 | if (error < 0) { | ||
650 | snd_printk(KERN_ERR "enabling IDE port failed\n"); | 692 | snd_printk(KERN_ERR "enabling IDE port failed\n"); |
651 | return error; | 693 | return error; |
652 | } | 694 | } |
@@ -654,32 +696,31 @@ static int __devinit snd_set_aci_init_values(struct snd_miro *miro) | |||
654 | 696 | ||
655 | /* set common aci values */ | 697 | /* set common aci values */ |
656 | 698 | ||
657 | for (idx = 0; idx < ARRAY_SIZE(aci_init_values); idx++) | 699 | for (idx = 0; idx < ARRAY_SIZE(aci_init_values); idx++) { |
658 | if ((error = aci_setvalue(miro, aci_init_values[idx][0], | 700 | error = aci_setvalue(aci, aci_init_values[idx][0], |
659 | aci_init_values[idx][1])) < 0) { | 701 | aci_init_values[idx][1]); |
702 | if (error < 0) { | ||
660 | snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", | 703 | snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n", |
661 | aci_init_values[idx][0], error); | 704 | aci_init_values[idx][0], error); |
662 | return error; | 705 | return error; |
663 | } | 706 | } |
664 | 707 | } | |
665 | miro->aci_amp = 0; | 708 | aci->aci_amp = 0; |
666 | miro->aci_preamp = 0; | 709 | aci->aci_preamp = 0; |
667 | miro->aci_solomode = 1; | 710 | aci->aci_solomode = 1; |
668 | 711 | ||
669 | return 0; | 712 | return 0; |
670 | } | 713 | } |
671 | 714 | ||
672 | static int __devinit snd_miro_mixer(struct snd_miro *miro) | 715 | static int __devinit snd_miro_mixer(struct snd_card *card, |
716 | struct snd_miro *miro) | ||
673 | { | 717 | { |
674 | struct snd_card *card; | ||
675 | unsigned int idx; | 718 | unsigned int idx; |
676 | int err; | 719 | int err; |
677 | 720 | ||
678 | if (snd_BUG_ON(!miro || !miro->card)) | 721 | if (snd_BUG_ON(!miro || !card)) |
679 | return -EINVAL; | 722 | return -EINVAL; |
680 | 723 | ||
681 | card = miro->card; | ||
682 | |||
683 | switch (miro->hardware) { | 724 | switch (miro->hardware) { |
684 | case OPTi9XX_HW_82C924: | 725 | case OPTi9XX_HW_82C924: |
685 | strcpy(card->mixername, "ACI & OPTi924"); | 726 | strcpy(card->mixername, "ACI & OPTi924"); |
@@ -697,7 +738,8 @@ static int __devinit snd_miro_mixer(struct snd_miro *miro) | |||
697 | return err; | 738 | return err; |
698 | } | 739 | } |
699 | 740 | ||
700 | if ((miro->aci_product == 'A') || (miro->aci_product == 'B')) { | 741 | if ((miro->aci->aci_product == 'A') || |
742 | (miro->aci->aci_product == 'B')) { | ||
701 | /* PCM1/PCM12 with power-amp and Line 2 */ | 743 | /* PCM1/PCM12 with power-amp and Line 2 */ |
702 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_line_control[0], miro))) < 0) | 744 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_line_control[0], miro))) < 0) |
703 | return err; | 745 | return err; |
@@ -705,16 +747,17 @@ static int __devinit snd_miro_mixer(struct snd_miro *miro) | |||
705 | return err; | 747 | return err; |
706 | } | 748 | } |
707 | 749 | ||
708 | if ((miro->aci_product == 'B') || (miro->aci_product == 'C')) { | 750 | if ((miro->aci->aci_product == 'B') || |
751 | (miro->aci->aci_product == 'C')) { | ||
709 | /* PCM12/PCM20 with mic-preamp */ | 752 | /* PCM12/PCM20 with mic-preamp */ |
710 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_preamp_control[0], miro))) < 0) | 753 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_preamp_control[0], miro))) < 0) |
711 | return err; | 754 | return err; |
712 | if (miro->aci_version >= 176) | 755 | if (miro->aci->aci_version >= 176) |
713 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_capture_control[0], miro))) < 0) | 756 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_capture_control[0], miro))) < 0) |
714 | return err; | 757 | return err; |
715 | } | 758 | } |
716 | 759 | ||
717 | if (miro->aci_product == 'C') { | 760 | if (miro->aci->aci_product == 'C') { |
718 | /* PCM20 with radio and 7 band equalizer */ | 761 | /* PCM20 with radio and 7 band equalizer */ |
719 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_radio_control[0], miro))) < 0) | 762 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_radio_control[0], miro))) < 0) |
720 | return err; | 763 | return err; |
@@ -757,21 +800,26 @@ static int __devinit snd_miro_init(struct snd_miro *chip, | |||
757 | chip->irq = -1; | 800 | chip->irq = -1; |
758 | chip->dma1 = -1; | 801 | chip->dma1 = -1; |
759 | chip->dma2 = -1; | 802 | chip->dma2 = -1; |
760 | chip->fm_port = -1; | ||
761 | chip->mpu_port = -1; | 803 | chip->mpu_port = -1; |
762 | chip->mpu_irq = -1; | 804 | chip->mpu_irq = -1; |
763 | 805 | ||
806 | chip->pwd_reg = 3; | ||
807 | |||
808 | #ifdef CONFIG_PNP | ||
809 | if (isapnp && chip->mc_base) | ||
810 | /* PnP resource gives the least 10 bits */ | ||
811 | chip->mc_base |= 0xc00; | ||
812 | else | ||
813 | #endif | ||
814 | chip->mc_base = 0xf8c; | ||
815 | |||
764 | switch (hardware) { | 816 | switch (hardware) { |
765 | case OPTi9XX_HW_82C929: | 817 | case OPTi9XX_HW_82C929: |
766 | chip->mc_base = 0xf8c; | ||
767 | chip->password = 0xe3; | 818 | chip->password = 0xe3; |
768 | chip->pwd_reg = 3; | ||
769 | break; | 819 | break; |
770 | 820 | ||
771 | case OPTi9XX_HW_82C924: | 821 | case OPTi9XX_HW_82C924: |
772 | chip->mc_base = 0xf8c; | ||
773 | chip->password = 0xe5; | 822 | chip->password = 0xe5; |
774 | chip->pwd_reg = 3; | ||
775 | break; | 823 | break; |
776 | 824 | ||
777 | default: | 825 | default: |
@@ -853,14 +901,15 @@ static void snd_miro_proc_read(struct snd_info_entry * entry, | |||
853 | struct snd_info_buffer *buffer) | 901 | struct snd_info_buffer *buffer) |
854 | { | 902 | { |
855 | struct snd_miro *miro = (struct snd_miro *) entry->private_data; | 903 | struct snd_miro *miro = (struct snd_miro *) entry->private_data; |
904 | struct snd_miro_aci *aci = miro->aci; | ||
856 | char* model = "unknown"; | 905 | char* model = "unknown"; |
857 | 906 | ||
858 | /* miroSOUND PCM1 pro, early PCM12 */ | 907 | /* miroSOUND PCM1 pro, early PCM12 */ |
859 | 908 | ||
860 | if ((miro->hardware == OPTi9XX_HW_82C929) && | 909 | if ((miro->hardware == OPTi9XX_HW_82C929) && |
861 | (miro->aci_vendor == 'm') && | 910 | (aci->aci_vendor == 'm') && |
862 | (miro->aci_product == 'A')) { | 911 | (aci->aci_product == 'A')) { |
863 | switch(miro->aci_version) { | 912 | switch (aci->aci_version) { |
864 | case 3: | 913 | case 3: |
865 | model = "miroSOUND PCM1 pro"; | 914 | model = "miroSOUND PCM1 pro"; |
866 | break; | 915 | break; |
@@ -873,9 +922,9 @@ static void snd_miro_proc_read(struct snd_info_entry * entry, | |||
873 | /* miroSOUND PCM12, PCM12 (Rev. E), PCM12 pnp */ | 922 | /* miroSOUND PCM12, PCM12 (Rev. E), PCM12 pnp */ |
874 | 923 | ||
875 | if ((miro->hardware == OPTi9XX_HW_82C924) && | 924 | if ((miro->hardware == OPTi9XX_HW_82C924) && |
876 | (miro->aci_vendor == 'm') && | 925 | (aci->aci_vendor == 'm') && |
877 | (miro->aci_product == 'B')) { | 926 | (aci->aci_product == 'B')) { |
878 | switch(miro->aci_version) { | 927 | switch (aci->aci_version) { |
879 | case 4: | 928 | case 4: |
880 | model = "miroSOUND PCM12"; | 929 | model = "miroSOUND PCM12"; |
881 | break; | 930 | break; |
@@ -891,9 +940,9 @@ static void snd_miro_proc_read(struct snd_info_entry * entry, | |||
891 | /* miroSOUND PCM20 radio */ | 940 | /* miroSOUND PCM20 radio */ |
892 | 941 | ||
893 | if ((miro->hardware == OPTi9XX_HW_82C924) && | 942 | if ((miro->hardware == OPTi9XX_HW_82C924) && |
894 | (miro->aci_vendor == 'm') && | 943 | (aci->aci_vendor == 'm') && |
895 | (miro->aci_product == 'C')) { | 944 | (aci->aci_product == 'C')) { |
896 | switch(miro->aci_version) { | 945 | switch (aci->aci_version) { |
897 | case 7: | 946 | case 7: |
898 | model = "miroSOUND PCM20 radio (Rev. E)"; | 947 | model = "miroSOUND PCM20 radio (Rev. E)"; |
899 | break; | 948 | break; |
@@ -917,17 +966,17 @@ static void snd_miro_proc_read(struct snd_info_entry * entry, | |||
917 | 966 | ||
918 | snd_iprintf(buffer, "ACI information:\n"); | 967 | snd_iprintf(buffer, "ACI information:\n"); |
919 | snd_iprintf(buffer, " vendor : "); | 968 | snd_iprintf(buffer, " vendor : "); |
920 | switch(miro->aci_vendor) { | 969 | switch (aci->aci_vendor) { |
921 | case 'm': | 970 | case 'm': |
922 | snd_iprintf(buffer, "Miro\n"); | 971 | snd_iprintf(buffer, "Miro\n"); |
923 | break; | 972 | break; |
924 | default: | 973 | default: |
925 | snd_iprintf(buffer, "unknown (0x%x)\n", miro->aci_vendor); | 974 | snd_iprintf(buffer, "unknown (0x%x)\n", aci->aci_vendor); |
926 | break; | 975 | break; |
927 | } | 976 | } |
928 | 977 | ||
929 | snd_iprintf(buffer, " product : "); | 978 | snd_iprintf(buffer, " product : "); |
930 | switch(miro->aci_product) { | 979 | switch (aci->aci_product) { |
931 | case 'A': | 980 | case 'A': |
932 | snd_iprintf(buffer, "miroSOUND PCM1 pro / (early) PCM12\n"); | 981 | snd_iprintf(buffer, "miroSOUND PCM1 pro / (early) PCM12\n"); |
933 | break; | 982 | break; |
@@ -938,26 +987,27 @@ static void snd_miro_proc_read(struct snd_info_entry * entry, | |||
938 | snd_iprintf(buffer, "miroSOUND PCM20 radio\n"); | 987 | snd_iprintf(buffer, "miroSOUND PCM20 radio\n"); |
939 | break; | 988 | break; |
940 | default: | 989 | default: |
941 | snd_iprintf(buffer, "unknown (0x%x)\n", miro->aci_product); | 990 | snd_iprintf(buffer, "unknown (0x%x)\n", aci->aci_product); |
942 | break; | 991 | break; |
943 | } | 992 | } |
944 | 993 | ||
945 | snd_iprintf(buffer, " firmware: %d (0x%x)\n", | 994 | snd_iprintf(buffer, " firmware: %d (0x%x)\n", |
946 | miro->aci_version, miro->aci_version); | 995 | aci->aci_version, aci->aci_version); |
947 | snd_iprintf(buffer, " port : 0x%lx-0x%lx\n", | 996 | snd_iprintf(buffer, " port : 0x%lx-0x%lx\n", |
948 | miro->aci_port, miro->aci_port+2); | 997 | aci->aci_port, aci->aci_port+2); |
949 | snd_iprintf(buffer, " wss : 0x%x\n", wss); | 998 | snd_iprintf(buffer, " wss : 0x%x\n", wss); |
950 | snd_iprintf(buffer, " ide : 0x%x\n", ide); | 999 | snd_iprintf(buffer, " ide : 0x%x\n", ide); |
951 | snd_iprintf(buffer, " solomode: 0x%x\n", miro->aci_solomode); | 1000 | snd_iprintf(buffer, " solomode: 0x%x\n", aci->aci_solomode); |
952 | snd_iprintf(buffer, " amp : 0x%x\n", miro->aci_amp); | 1001 | snd_iprintf(buffer, " amp : 0x%x\n", aci->aci_amp); |
953 | snd_iprintf(buffer, " preamp : 0x%x\n", miro->aci_preamp); | 1002 | snd_iprintf(buffer, " preamp : 0x%x\n", aci->aci_preamp); |
954 | } | 1003 | } |
955 | 1004 | ||
956 | static void __devinit snd_miro_proc_init(struct snd_miro * miro) | 1005 | static void __devinit snd_miro_proc_init(struct snd_card *card, |
1006 | struct snd_miro *miro) | ||
957 | { | 1007 | { |
958 | struct snd_info_entry *entry; | 1008 | struct snd_info_entry *entry; |
959 | 1009 | ||
960 | if (! snd_card_proc_new(miro->card, "miro", &entry)) | 1010 | if (!snd_card_proc_new(card, "miro", &entry)) |
961 | snd_info_set_text_ops(entry, miro, snd_miro_proc_read); | 1011 | snd_info_set_text_ops(entry, miro, snd_miro_proc_read); |
962 | } | 1012 | } |
963 | 1013 | ||
@@ -974,37 +1024,40 @@ static int __devinit snd_miro_configure(struct snd_miro *chip) | |||
974 | unsigned char mpu_irq_bits; | 1024 | unsigned char mpu_irq_bits; |
975 | unsigned long flags; | 1025 | unsigned long flags; |
976 | 1026 | ||
1027 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80); | ||
1028 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(2), 0x20, 0x20); /* OPL4 */ | ||
1029 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02); | ||
1030 | |||
977 | switch (chip->hardware) { | 1031 | switch (chip->hardware) { |
978 | case OPTi9XX_HW_82C924: | 1032 | case OPTi9XX_HW_82C924: |
979 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02); | 1033 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02); |
980 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80); | ||
981 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(2), 0x20, 0x20); /* OPL4 */ | ||
982 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff); | 1034 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff); |
983 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02); | ||
984 | break; | 1035 | break; |
985 | case OPTi9XX_HW_82C929: | 1036 | case OPTi9XX_HW_82C929: |
986 | /* untested init commands for OPTi929 */ | 1037 | /* untested init commands for OPTi929 */ |
987 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80); | ||
988 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(2), 0x20, 0x20); /* OPL4 */ | ||
989 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c); | 1038 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c); |
990 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02); | ||
991 | break; | 1039 | break; |
992 | default: | 1040 | default: |
993 | snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware); | 1041 | snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware); |
994 | return -EINVAL; | 1042 | return -EINVAL; |
995 | } | 1043 | } |
996 | 1044 | ||
997 | switch (chip->wss_base) { | 1045 | /* PnP resource says it decodes only 10 bits of address */ |
998 | case 0x530: | 1046 | switch (chip->wss_base & 0x3ff) { |
1047 | case 0x130: | ||
1048 | chip->wss_base = 0x530; | ||
999 | wss_base_bits = 0x00; | 1049 | wss_base_bits = 0x00; |
1000 | break; | 1050 | break; |
1001 | case 0x604: | 1051 | case 0x204: |
1052 | chip->wss_base = 0x604; | ||
1002 | wss_base_bits = 0x03; | 1053 | wss_base_bits = 0x03; |
1003 | break; | 1054 | break; |
1004 | case 0xe80: | 1055 | case 0x280: |
1056 | chip->wss_base = 0xe80; | ||
1005 | wss_base_bits = 0x01; | 1057 | wss_base_bits = 0x01; |
1006 | break; | 1058 | break; |
1007 | case 0xf40: | 1059 | case 0x340: |
1060 | chip->wss_base = 0xf40; | ||
1008 | wss_base_bits = 0x02; | 1061 | wss_base_bits = 0x02; |
1009 | break; | 1062 | break; |
1010 | default: | 1063 | default: |
@@ -1122,75 +1175,92 @@ __skip_mpu: | |||
1122 | return 0; | 1175 | return 0; |
1123 | } | 1176 | } |
1124 | 1177 | ||
1178 | static int __devinit snd_miro_opti_check(struct snd_miro *chip) | ||
1179 | { | ||
1180 | unsigned char value; | ||
1181 | |||
1182 | chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, | ||
1183 | "OPTi9xx MC"); | ||
1184 | if (chip->res_mc_base == NULL) | ||
1185 | return -ENOMEM; | ||
1186 | |||
1187 | value = snd_miro_read(chip, OPTi9XX_MC_REG(1)); | ||
1188 | if (value != 0xff && value != inb(chip->mc_base + OPTi9XX_MC_REG(1))) | ||
1189 | if (value == snd_miro_read(chip, OPTi9XX_MC_REG(1))) | ||
1190 | return 0; | ||
1191 | |||
1192 | release_and_free_resource(chip->res_mc_base); | ||
1193 | chip->res_mc_base = NULL; | ||
1194 | |||
1195 | return -ENODEV; | ||
1196 | } | ||
1197 | |||
1125 | static int __devinit snd_card_miro_detect(struct snd_card *card, | 1198 | static int __devinit snd_card_miro_detect(struct snd_card *card, |
1126 | struct snd_miro *chip) | 1199 | struct snd_miro *chip) |
1127 | { | 1200 | { |
1128 | int i, err; | 1201 | int i, err; |
1129 | unsigned char value; | ||
1130 | 1202 | ||
1131 | for (i = OPTi9XX_HW_82C929; i <= OPTi9XX_HW_82C924; i++) { | 1203 | for (i = OPTi9XX_HW_82C929; i <= OPTi9XX_HW_82C924; i++) { |
1132 | 1204 | ||
1133 | if ((err = snd_miro_init(chip, i)) < 0) | 1205 | if ((err = snd_miro_init(chip, i)) < 0) |
1134 | return err; | 1206 | return err; |
1135 | 1207 | ||
1136 | if ((chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL) | 1208 | err = snd_miro_opti_check(chip); |
1137 | continue; | 1209 | if (err == 0) |
1138 | 1210 | return 1; | |
1139 | value = snd_miro_read(chip, OPTi9XX_MC_REG(1)); | ||
1140 | if ((value != 0xff) && (value != inb(chip->mc_base + 1))) | ||
1141 | if (value == snd_miro_read(chip, OPTi9XX_MC_REG(1))) | ||
1142 | return 1; | ||
1143 | |||
1144 | release_and_free_resource(chip->res_mc_base); | ||
1145 | chip->res_mc_base = NULL; | ||
1146 | |||
1147 | } | 1211 | } |
1148 | 1212 | ||
1149 | return -ENODEV; | 1213 | return -ENODEV; |
1150 | } | 1214 | } |
1151 | 1215 | ||
1152 | static int __devinit snd_card_miro_aci_detect(struct snd_card *card, | 1216 | static int __devinit snd_card_miro_aci_detect(struct snd_card *card, |
1153 | struct snd_miro * miro) | 1217 | struct snd_miro *miro) |
1154 | { | 1218 | { |
1155 | unsigned char regval; | 1219 | unsigned char regval; |
1156 | int i; | 1220 | int i; |
1221 | struct snd_miro_aci *aci = &aci_device; | ||
1222 | |||
1223 | miro->aci = aci; | ||
1157 | 1224 | ||
1158 | mutex_init(&miro->aci_mutex); | 1225 | mutex_init(&aci->aci_mutex); |
1159 | 1226 | ||
1160 | /* get ACI port from OPTi9xx MC 4 */ | 1227 | /* get ACI port from OPTi9xx MC 4 */ |
1161 | 1228 | ||
1162 | miro->mc_base = 0xf8c; | ||
1163 | regval=inb(miro->mc_base + 4); | 1229 | regval=inb(miro->mc_base + 4); |
1164 | miro->aci_port = (regval & 0x10) ? 0x344: 0x354; | 1230 | aci->aci_port = (regval & 0x10) ? 0x344 : 0x354; |
1165 | 1231 | ||
1166 | if ((miro->res_aci_port = request_region(miro->aci_port, 3, "miro aci")) == NULL) { | 1232 | miro->res_aci_port = request_region(aci->aci_port, 3, "miro aci"); |
1233 | if (miro->res_aci_port == NULL) { | ||
1167 | snd_printk(KERN_ERR "aci i/o area 0x%lx-0x%lx already used.\n", | 1234 | snd_printk(KERN_ERR "aci i/o area 0x%lx-0x%lx already used.\n", |
1168 | miro->aci_port, miro->aci_port+2); | 1235 | aci->aci_port, aci->aci_port+2); |
1169 | return -ENOMEM; | 1236 | return -ENOMEM; |
1170 | } | 1237 | } |
1171 | 1238 | ||
1172 | /* force ACI into a known state */ | 1239 | /* force ACI into a known state */ |
1173 | for (i = 0; i < 3; i++) | 1240 | for (i = 0; i < 3; i++) |
1174 | if (aci_cmd(miro, ACI_ERROR_OP, -1, -1) < 0) { | 1241 | if (snd_aci_cmd(aci, ACI_ERROR_OP, -1, -1) < 0) { |
1175 | snd_printk(KERN_ERR "can't force aci into known state.\n"); | 1242 | snd_printk(KERN_ERR "can't force aci into known state.\n"); |
1176 | return -ENXIO; | 1243 | return -ENXIO; |
1177 | } | 1244 | } |
1178 | 1245 | ||
1179 | if ((miro->aci_vendor=aci_cmd(miro, ACI_READ_IDCODE, -1, -1)) < 0 || | 1246 | aci->aci_vendor = snd_aci_cmd(aci, ACI_READ_IDCODE, -1, -1); |
1180 | (miro->aci_product=aci_cmd(miro, ACI_READ_IDCODE, -1, -1)) < 0) { | 1247 | aci->aci_product = snd_aci_cmd(aci, ACI_READ_IDCODE, -1, -1); |
1181 | snd_printk(KERN_ERR "can't read aci id on 0x%lx.\n", miro->aci_port); | 1248 | if (aci->aci_vendor < 0 || aci->aci_product < 0) { |
1249 | snd_printk(KERN_ERR "can't read aci id on 0x%lx.\n", | ||
1250 | aci->aci_port); | ||
1182 | return -ENXIO; | 1251 | return -ENXIO; |
1183 | } | 1252 | } |
1184 | 1253 | ||
1185 | if ((miro->aci_version=aci_cmd(miro, ACI_READ_VERSION, -1, -1)) < 0) { | 1254 | aci->aci_version = snd_aci_cmd(aci, ACI_READ_VERSION, -1, -1); |
1255 | if (aci->aci_version < 0) { | ||
1186 | snd_printk(KERN_ERR "can't read aci version on 0x%lx.\n", | 1256 | snd_printk(KERN_ERR "can't read aci version on 0x%lx.\n", |
1187 | miro->aci_port); | 1257 | aci->aci_port); |
1188 | return -ENXIO; | 1258 | return -ENXIO; |
1189 | } | 1259 | } |
1190 | 1260 | ||
1191 | if (aci_cmd(miro, ACI_INIT, -1, -1) < 0 || | 1261 | if (snd_aci_cmd(aci, ACI_INIT, -1, -1) < 0 || |
1192 | aci_cmd(miro, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0 || | 1262 | snd_aci_cmd(aci, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0 || |
1193 | aci_cmd(miro, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0) { | 1263 | snd_aci_cmd(aci, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0) { |
1194 | snd_printk(KERN_ERR "can't initialize aci.\n"); | 1264 | snd_printk(KERN_ERR "can't initialize aci.\n"); |
1195 | return -ENXIO; | 1265 | return -ENXIO; |
1196 | } | 1266 | } |
@@ -1201,157 +1271,80 @@ static int __devinit snd_card_miro_aci_detect(struct snd_card *card, | |||
1201 | static void snd_card_miro_free(struct snd_card *card) | 1271 | static void snd_card_miro_free(struct snd_card *card) |
1202 | { | 1272 | { |
1203 | struct snd_miro *miro = card->private_data; | 1273 | struct snd_miro *miro = card->private_data; |
1204 | 1274 | ||
1205 | release_and_free_resource(miro->res_aci_port); | 1275 | release_and_free_resource(miro->res_aci_port); |
1276 | if (miro->aci) | ||
1277 | miro->aci->aci_port = 0; | ||
1206 | release_and_free_resource(miro->res_mc_base); | 1278 | release_and_free_resource(miro->res_mc_base); |
1207 | } | 1279 | } |
1208 | 1280 | ||
1209 | static int __devinit snd_miro_match(struct device *devptr, unsigned int n) | 1281 | static int __devinit snd_miro_probe(struct snd_card *card) |
1210 | { | ||
1211 | return 1; | ||
1212 | } | ||
1213 | |||
1214 | static int __devinit snd_miro_probe(struct device *devptr, unsigned int n) | ||
1215 | { | 1282 | { |
1216 | static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1}; | ||
1217 | static long possible_mpu_ports[] = {0x330, 0x300, 0x310, 0x320, -1}; | ||
1218 | static int possible_irqs[] = {11, 9, 10, 7, -1}; | ||
1219 | static int possible_mpu_irqs[] = {10, 5, 9, 7, -1}; | ||
1220 | static int possible_dma1s[] = {3, 1, 0, -1}; | ||
1221 | static int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}}; | ||
1222 | |||
1223 | int error; | 1283 | int error; |
1224 | struct snd_miro *miro; | 1284 | struct snd_miro *miro = card->private_data; |
1225 | struct snd_wss *codec; | 1285 | struct snd_wss *codec; |
1226 | struct snd_timer *timer; | 1286 | struct snd_timer *timer; |
1227 | struct snd_card *card; | ||
1228 | struct snd_pcm *pcm; | 1287 | struct snd_pcm *pcm; |
1229 | struct snd_rawmidi *rmidi; | 1288 | struct snd_rawmidi *rmidi; |
1230 | 1289 | ||
1231 | error = snd_card_create(index, id, THIS_MODULE, | 1290 | if (!miro->res_mc_base) { |
1232 | sizeof(struct snd_miro), &card); | 1291 | miro->res_mc_base = request_region(miro->mc_base, |
1233 | if (error < 0) | 1292 | miro->mc_base_size, |
1234 | return error; | 1293 | "miro (OPTi9xx MC)"); |
1235 | 1294 | if (miro->res_mc_base == NULL) { | |
1236 | card->private_free = snd_card_miro_free; | 1295 | snd_printk(KERN_ERR "request for OPTI9xx MC failed\n"); |
1237 | miro = card->private_data; | 1296 | return -ENOMEM; |
1238 | miro->card = card; | 1297 | } |
1239 | |||
1240 | if ((error = snd_card_miro_aci_detect(card, miro)) < 0) { | ||
1241 | snd_card_free(card); | ||
1242 | snd_printk(KERN_ERR "unable to detect aci chip\n"); | ||
1243 | return -ENODEV; | ||
1244 | } | 1298 | } |
1245 | 1299 | ||
1246 | /* init proc interface */ | 1300 | error = snd_card_miro_aci_detect(card, miro); |
1247 | snd_miro_proc_init(miro); | 1301 | if (error < 0) { |
1248 | |||
1249 | if ((error = snd_card_miro_detect(card, miro)) < 0) { | ||
1250 | snd_card_free(card); | 1302 | snd_card_free(card); |
1251 | snd_printk(KERN_ERR "unable to detect OPTi9xx chip\n"); | 1303 | snd_printk(KERN_ERR "unable to detect aci chip\n"); |
1252 | return -ENODEV; | 1304 | return -ENODEV; |
1253 | } | 1305 | } |
1254 | 1306 | ||
1255 | if (! miro->res_mc_base && | ||
1256 | (miro->res_mc_base = request_region(miro->mc_base, miro->mc_base_size, | ||
1257 | "miro (OPTi9xx MC)")) == NULL) { | ||
1258 | snd_card_free(card); | ||
1259 | snd_printk(KERN_ERR "request for OPTI9xx MC failed\n"); | ||
1260 | return -ENOMEM; | ||
1261 | } | ||
1262 | |||
1263 | miro->wss_base = port; | 1307 | miro->wss_base = port; |
1264 | miro->fm_port = fm_port; | ||
1265 | miro->mpu_port = mpu_port; | 1308 | miro->mpu_port = mpu_port; |
1266 | miro->irq = irq; | 1309 | miro->irq = irq; |
1267 | miro->mpu_irq = mpu_irq; | 1310 | miro->mpu_irq = mpu_irq; |
1268 | miro->dma1 = dma1; | 1311 | miro->dma1 = dma1; |
1269 | miro->dma2 = dma2; | 1312 | miro->dma2 = dma2; |
1270 | 1313 | ||
1271 | if (miro->wss_base == SNDRV_AUTO_PORT) { | 1314 | /* init proc interface */ |
1272 | if ((miro->wss_base = snd_legacy_find_free_ioport(possible_ports, 4)) < 0) { | 1315 | snd_miro_proc_init(card, miro); |
1273 | snd_card_free(card); | ||
1274 | snd_printk(KERN_ERR "unable to find a free WSS port\n"); | ||
1275 | return -EBUSY; | ||
1276 | } | ||
1277 | } | ||
1278 | |||
1279 | if (miro->mpu_port == SNDRV_AUTO_PORT) { | ||
1280 | if ((miro->mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2)) < 0) { | ||
1281 | snd_card_free(card); | ||
1282 | snd_printk(KERN_ERR "unable to find a free MPU401 port\n"); | ||
1283 | return -EBUSY; | ||
1284 | } | ||
1285 | } | ||
1286 | if (miro->irq == SNDRV_AUTO_IRQ) { | ||
1287 | if ((miro->irq = snd_legacy_find_free_irq(possible_irqs)) < 0) { | ||
1288 | snd_card_free(card); | ||
1289 | snd_printk(KERN_ERR "unable to find a free IRQ\n"); | ||
1290 | return -EBUSY; | ||
1291 | } | ||
1292 | } | ||
1293 | if (miro->mpu_irq == SNDRV_AUTO_IRQ) { | ||
1294 | if ((miro->mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs)) < 0) { | ||
1295 | snd_card_free(card); | ||
1296 | snd_printk(KERN_ERR "unable to find a free MPU401 IRQ\n"); | ||
1297 | return -EBUSY; | ||
1298 | } | ||
1299 | } | ||
1300 | if (miro->dma1 == SNDRV_AUTO_DMA) { | ||
1301 | if ((miro->dma1 = snd_legacy_find_free_dma(possible_dma1s)) < 0) { | ||
1302 | snd_card_free(card); | ||
1303 | snd_printk(KERN_ERR "unable to find a free DMA1\n"); | ||
1304 | return -EBUSY; | ||
1305 | } | ||
1306 | } | ||
1307 | if (miro->dma2 == SNDRV_AUTO_DMA) { | ||
1308 | if ((miro->dma2 = snd_legacy_find_free_dma(possible_dma2s[miro->dma1 % 4])) < 0) { | ||
1309 | snd_card_free(card); | ||
1310 | snd_printk(KERN_ERR "unable to find a free DMA2\n"); | ||
1311 | return -EBUSY; | ||
1312 | } | ||
1313 | } | ||
1314 | 1316 | ||
1315 | error = snd_miro_configure(miro); | 1317 | error = snd_miro_configure(miro); |
1316 | if (error) { | 1318 | if (error) |
1317 | snd_card_free(card); | ||
1318 | return error; | 1319 | return error; |
1319 | } | ||
1320 | 1320 | ||
1321 | error = snd_wss_create(card, miro->wss_base + 4, -1, | 1321 | error = snd_wss_create(card, miro->wss_base + 4, -1, |
1322 | miro->irq, miro->dma1, miro->dma2, | 1322 | miro->irq, miro->dma1, miro->dma2, |
1323 | WSS_HW_AD1845, 0, &codec); | 1323 | WSS_HW_DETECT, 0, &codec); |
1324 | if (error < 0) { | 1324 | if (error < 0) |
1325 | snd_card_free(card); | ||
1326 | return error; | 1325 | return error; |
1327 | } | ||
1328 | 1326 | ||
1329 | error = snd_wss_pcm(codec, 0, &pcm); | 1327 | error = snd_wss_pcm(codec, 0, &pcm); |
1330 | if (error < 0) { | 1328 | if (error < 0) |
1331 | snd_card_free(card); | ||
1332 | return error; | 1329 | return error; |
1333 | } | 1330 | |
1334 | error = snd_wss_mixer(codec); | 1331 | error = snd_wss_mixer(codec); |
1335 | if (error < 0) { | 1332 | if (error < 0) |
1336 | snd_card_free(card); | ||
1337 | return error; | 1333 | return error; |
1338 | } | 1334 | |
1339 | error = snd_wss_timer(codec, 0, &timer); | 1335 | error = snd_wss_timer(codec, 0, &timer); |
1340 | if (error < 0) { | 1336 | if (error < 0) |
1341 | snd_card_free(card); | ||
1342 | return error; | 1337 | return error; |
1343 | } | ||
1344 | 1338 | ||
1345 | miro->pcm = pcm; | 1339 | miro->pcm = pcm; |
1346 | 1340 | ||
1347 | if ((error = snd_miro_mixer(miro)) < 0) { | 1341 | error = snd_miro_mixer(card, miro); |
1348 | snd_card_free(card); | 1342 | if (error < 0) |
1349 | return error; | 1343 | return error; |
1350 | } | ||
1351 | 1344 | ||
1352 | if (miro->aci_vendor == 'm') { | 1345 | if (miro->aci->aci_vendor == 'm') { |
1353 | /* It looks like a miro sound card. */ | 1346 | /* It looks like a miro sound card. */ |
1354 | switch (miro->aci_product) { | 1347 | switch (miro->aci->aci_product) { |
1355 | case 'A': | 1348 | case 'A': |
1356 | sprintf(card->shortname, | 1349 | sprintf(card->shortname, |
1357 | "miroSOUND PCM1 pro / PCM12"); | 1350 | "miroSOUND PCM1 pro / PCM12"); |
@@ -1380,30 +1373,131 @@ static int __devinit snd_miro_probe(struct device *devptr, unsigned int n) | |||
1380 | card->shortname, miro->name, pcm->name, miro->wss_base + 4, | 1373 | card->shortname, miro->name, pcm->name, miro->wss_base + 4, |
1381 | miro->irq, miro->dma1, miro->dma2); | 1374 | miro->irq, miro->dma1, miro->dma2); |
1382 | 1375 | ||
1383 | if (miro->mpu_port <= 0 || miro->mpu_port == SNDRV_AUTO_PORT) | 1376 | if (mpu_port <= 0 || mpu_port == SNDRV_AUTO_PORT) |
1384 | rmidi = NULL; | 1377 | rmidi = NULL; |
1385 | else | 1378 | else { |
1386 | if ((error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, | 1379 | error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, |
1387 | miro->mpu_port, 0, miro->mpu_irq, IRQF_DISABLED, | 1380 | mpu_port, 0, miro->mpu_irq, IRQF_DISABLED, |
1388 | &rmidi))) | 1381 | &rmidi); |
1389 | snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n", miro->mpu_port); | 1382 | if (error < 0) |
1383 | snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n", | ||
1384 | mpu_port); | ||
1385 | } | ||
1390 | 1386 | ||
1391 | if (miro->fm_port > 0 && miro->fm_port != SNDRV_AUTO_PORT) { | 1387 | if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT) { |
1392 | struct snd_opl3 *opl3 = NULL; | 1388 | struct snd_opl3 *opl3 = NULL; |
1393 | struct snd_opl4 *opl4; | 1389 | struct snd_opl4 *opl4; |
1394 | if (snd_opl4_create(card, miro->fm_port, miro->fm_port - 8, | 1390 | |
1391 | if (snd_opl4_create(card, fm_port, fm_port - 8, | ||
1395 | 2, &opl3, &opl4) < 0) | 1392 | 2, &opl3, &opl4) < 0) |
1396 | snd_printk(KERN_WARNING "no OPL4 device at 0x%lx\n", miro->fm_port); | 1393 | snd_printk(KERN_WARNING "no OPL4 device at 0x%lx\n", |
1394 | fm_port); | ||
1397 | } | 1395 | } |
1398 | 1396 | ||
1399 | if ((error = snd_set_aci_init_values(miro)) < 0) { | 1397 | error = snd_set_aci_init_values(miro); |
1400 | snd_card_free(card); | 1398 | if (error < 0) |
1401 | return error; | 1399 | return error; |
1400 | |||
1401 | return snd_card_register(card); | ||
1402 | } | ||
1403 | |||
1404 | static int __devinit snd_miro_isa_match(struct device *devptr, unsigned int n) | ||
1405 | { | ||
1406 | #ifdef CONFIG_PNP | ||
1407 | if (snd_miro_pnp_is_probed) | ||
1408 | return 0; | ||
1409 | if (isapnp) | ||
1410 | return 0; | ||
1411 | #endif | ||
1412 | return 1; | ||
1413 | } | ||
1414 | |||
1415 | static int __devinit snd_miro_isa_probe(struct device *devptr, unsigned int n) | ||
1416 | { | ||
1417 | static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1}; | ||
1418 | static long possible_mpu_ports[] = {0x330, 0x300, 0x310, 0x320, -1}; | ||
1419 | static int possible_irqs[] = {11, 9, 10, 7, -1}; | ||
1420 | static int possible_mpu_irqs[] = {10, 5, 9, 7, -1}; | ||
1421 | static int possible_dma1s[] = {3, 1, 0, -1}; | ||
1422 | static int possible_dma2s[][2] = { {1, -1}, {0, -1}, {-1, -1}, | ||
1423 | {0, -1} }; | ||
1424 | |||
1425 | int error; | ||
1426 | struct snd_miro *miro; | ||
1427 | struct snd_card *card; | ||
1428 | |||
1429 | error = snd_card_create(index, id, THIS_MODULE, | ||
1430 | sizeof(struct snd_miro), &card); | ||
1431 | if (error < 0) | ||
1432 | return error; | ||
1433 | |||
1434 | card->private_free = snd_card_miro_free; | ||
1435 | miro = card->private_data; | ||
1436 | |||
1437 | error = snd_card_miro_detect(card, miro); | ||
1438 | if (error < 0) { | ||
1439 | snd_card_free(card); | ||
1440 | snd_printk(KERN_ERR "unable to detect OPTi9xx chip\n"); | ||
1441 | return -ENODEV; | ||
1442 | } | ||
1443 | |||
1444 | if (port == SNDRV_AUTO_PORT) { | ||
1445 | port = snd_legacy_find_free_ioport(possible_ports, 4); | ||
1446 | if (port < 0) { | ||
1447 | snd_card_free(card); | ||
1448 | snd_printk(KERN_ERR "unable to find a free WSS port\n"); | ||
1449 | return -EBUSY; | ||
1450 | } | ||
1451 | } | ||
1452 | |||
1453 | if (mpu_port == SNDRV_AUTO_PORT) { | ||
1454 | mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2); | ||
1455 | if (mpu_port < 0) { | ||
1456 | snd_card_free(card); | ||
1457 | snd_printk(KERN_ERR | ||
1458 | "unable to find a free MPU401 port\n"); | ||
1459 | return -EBUSY; | ||
1460 | } | ||
1461 | } | ||
1462 | |||
1463 | if (irq == SNDRV_AUTO_IRQ) { | ||
1464 | irq = snd_legacy_find_free_irq(possible_irqs); | ||
1465 | if (irq < 0) { | ||
1466 | snd_card_free(card); | ||
1467 | snd_printk(KERN_ERR "unable to find a free IRQ\n"); | ||
1468 | return -EBUSY; | ||
1469 | } | ||
1470 | } | ||
1471 | if (mpu_irq == SNDRV_AUTO_IRQ) { | ||
1472 | mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs); | ||
1473 | if (mpu_irq < 0) { | ||
1474 | snd_card_free(card); | ||
1475 | snd_printk(KERN_ERR | ||
1476 | "unable to find a free MPU401 IRQ\n"); | ||
1477 | return -EBUSY; | ||
1478 | } | ||
1479 | } | ||
1480 | if (dma1 == SNDRV_AUTO_DMA) { | ||
1481 | dma1 = snd_legacy_find_free_dma(possible_dma1s); | ||
1482 | if (dma1 < 0) { | ||
1483 | snd_card_free(card); | ||
1484 | snd_printk(KERN_ERR "unable to find a free DMA1\n"); | ||
1485 | return -EBUSY; | ||
1486 | } | ||
1487 | } | ||
1488 | if (dma2 == SNDRV_AUTO_DMA) { | ||
1489 | dma2 = snd_legacy_find_free_dma(possible_dma2s[dma1 % 4]); | ||
1490 | if (dma2 < 0) { | ||
1491 | snd_card_free(card); | ||
1492 | snd_printk(KERN_ERR "unable to find a free DMA2\n"); | ||
1493 | return -EBUSY; | ||
1494 | } | ||
1402 | } | 1495 | } |
1403 | 1496 | ||
1404 | snd_card_set_dev(card, devptr); | 1497 | snd_card_set_dev(card, devptr); |
1405 | 1498 | ||
1406 | if ((error = snd_card_register(card))) { | 1499 | error = snd_miro_probe(card); |
1500 | if (error < 0) { | ||
1407 | snd_card_free(card); | 1501 | snd_card_free(card); |
1408 | return error; | 1502 | return error; |
1409 | } | 1503 | } |
@@ -1412,7 +1506,8 @@ static int __devinit snd_miro_probe(struct device *devptr, unsigned int n) | |||
1412 | return 0; | 1506 | return 0; |
1413 | } | 1507 | } |
1414 | 1508 | ||
1415 | static int __devexit snd_miro_remove(struct device *devptr, unsigned int dev) | 1509 | static int __devexit snd_miro_isa_remove(struct device *devptr, |
1510 | unsigned int dev) | ||
1416 | { | 1511 | { |
1417 | snd_card_free(dev_get_drvdata(devptr)); | 1512 | snd_card_free(dev_get_drvdata(devptr)); |
1418 | dev_set_drvdata(devptr, NULL); | 1513 | dev_set_drvdata(devptr, NULL); |
@@ -1422,23 +1517,164 @@ static int __devexit snd_miro_remove(struct device *devptr, unsigned int dev) | |||
1422 | #define DEV_NAME "miro" | 1517 | #define DEV_NAME "miro" |
1423 | 1518 | ||
1424 | static struct isa_driver snd_miro_driver = { | 1519 | static struct isa_driver snd_miro_driver = { |
1425 | .match = snd_miro_match, | 1520 | .match = snd_miro_isa_match, |
1426 | .probe = snd_miro_probe, | 1521 | .probe = snd_miro_isa_probe, |
1427 | .remove = __devexit_p(snd_miro_remove), | 1522 | .remove = __devexit_p(snd_miro_isa_remove), |
1428 | /* FIXME: suspend/resume */ | 1523 | /* FIXME: suspend/resume */ |
1429 | .driver = { | 1524 | .driver = { |
1430 | .name = DEV_NAME | 1525 | .name = DEV_NAME |
1431 | }, | 1526 | }, |
1432 | }; | 1527 | }; |
1433 | 1528 | ||
1529 | #ifdef CONFIG_PNP | ||
1530 | |||
1531 | static int __devinit snd_card_miro_pnp(struct snd_miro *chip, | ||
1532 | struct pnp_card_link *card, | ||
1533 | const struct pnp_card_device_id *pid) | ||
1534 | { | ||
1535 | struct pnp_dev *pdev; | ||
1536 | int err; | ||
1537 | struct pnp_dev *devmpu; | ||
1538 | struct pnp_dev *devmc; | ||
1539 | |||
1540 | pdev = pnp_request_card_device(card, pid->devs[0].id, NULL); | ||
1541 | if (pdev == NULL) | ||
1542 | return -EBUSY; | ||
1543 | |||
1544 | devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL); | ||
1545 | if (devmpu == NULL) | ||
1546 | return -EBUSY; | ||
1547 | |||
1548 | devmc = pnp_request_card_device(card, pid->devs[2].id, NULL); | ||
1549 | if (devmc == NULL) | ||
1550 | return -EBUSY; | ||
1551 | |||
1552 | err = pnp_activate_dev(pdev); | ||
1553 | if (err < 0) { | ||
1554 | snd_printk(KERN_ERR "AUDIO pnp configure failure: %d\n", err); | ||
1555 | return err; | ||
1556 | } | ||
1557 | |||
1558 | err = pnp_activate_dev(devmc); | ||
1559 | if (err < 0) { | ||
1560 | snd_printk(KERN_ERR "MC pnp configure failure: %d\n", | ||
1561 | err); | ||
1562 | return err; | ||
1563 | } | ||
1564 | |||
1565 | port = pnp_port_start(pdev, 1); | ||
1566 | fm_port = pnp_port_start(pdev, 2) + 8; | ||
1567 | |||
1568 | /* | ||
1569 | * The MC(0) is never accessed and the miroSOUND PCM20 card does not | ||
1570 | * include it in the PnP resource range. OPTI93x include it. | ||
1571 | */ | ||
1572 | chip->mc_base = pnp_port_start(devmc, 0) - 1; | ||
1573 | chip->mc_base_size = pnp_port_len(devmc, 0) + 1; | ||
1574 | |||
1575 | irq = pnp_irq(pdev, 0); | ||
1576 | dma1 = pnp_dma(pdev, 0); | ||
1577 | dma2 = pnp_dma(pdev, 1); | ||
1578 | |||
1579 | if (mpu_port > 0) { | ||
1580 | err = pnp_activate_dev(devmpu); | ||
1581 | if (err < 0) { | ||
1582 | snd_printk(KERN_ERR "MPU401 pnp configure failure\n"); | ||
1583 | mpu_port = -1; | ||
1584 | return err; | ||
1585 | } | ||
1586 | mpu_port = pnp_port_start(devmpu, 0); | ||
1587 | mpu_irq = pnp_irq(devmpu, 0); | ||
1588 | } | ||
1589 | return 0; | ||
1590 | } | ||
1591 | |||
1592 | static int __devinit snd_miro_pnp_probe(struct pnp_card_link *pcard, | ||
1593 | const struct pnp_card_device_id *pid) | ||
1594 | { | ||
1595 | struct snd_card *card; | ||
1596 | int err; | ||
1597 | struct snd_miro *miro; | ||
1598 | |||
1599 | if (snd_miro_pnp_is_probed) | ||
1600 | return -EBUSY; | ||
1601 | if (!isapnp) | ||
1602 | return -ENODEV; | ||
1603 | err = snd_card_create(index, id, THIS_MODULE, | ||
1604 | sizeof(struct snd_miro), &card); | ||
1605 | if (err < 0) | ||
1606 | return err; | ||
1607 | |||
1608 | card->private_free = snd_card_miro_free; | ||
1609 | miro = card->private_data; | ||
1610 | |||
1611 | err = snd_card_miro_pnp(miro, pcard, pid); | ||
1612 | if (err) { | ||
1613 | snd_card_free(card); | ||
1614 | return err; | ||
1615 | } | ||
1616 | |||
1617 | /* only miroSOUND PCM20 and PCM12 == OPTi924 */ | ||
1618 | err = snd_miro_init(miro, OPTi9XX_HW_82C924); | ||
1619 | if (err) { | ||
1620 | snd_card_free(card); | ||
1621 | return err; | ||
1622 | } | ||
1623 | |||
1624 | err = snd_miro_opti_check(miro); | ||
1625 | if (err) { | ||
1626 | snd_printk(KERN_ERR "OPTI chip not found\n"); | ||
1627 | snd_card_free(card); | ||
1628 | return err; | ||
1629 | } | ||
1630 | |||
1631 | snd_card_set_dev(card, &pcard->card->dev); | ||
1632 | err = snd_miro_probe(card); | ||
1633 | if (err < 0) { | ||
1634 | snd_card_free(card); | ||
1635 | return err; | ||
1636 | } | ||
1637 | pnp_set_card_drvdata(pcard, card); | ||
1638 | snd_miro_pnp_is_probed = 1; | ||
1639 | return 0; | ||
1640 | } | ||
1641 | |||
1642 | static void __devexit snd_miro_pnp_remove(struct pnp_card_link * pcard) | ||
1643 | { | ||
1644 | snd_card_free(pnp_get_card_drvdata(pcard)); | ||
1645 | pnp_set_card_drvdata(pcard, NULL); | ||
1646 | snd_miro_pnp_is_probed = 0; | ||
1647 | } | ||
1648 | |||
1649 | static struct pnp_card_driver miro_pnpc_driver = { | ||
1650 | .flags = PNP_DRIVER_RES_DISABLE, | ||
1651 | .name = "miro", | ||
1652 | .id_table = snd_miro_pnpids, | ||
1653 | .probe = snd_miro_pnp_probe, | ||
1654 | .remove = __devexit_p(snd_miro_pnp_remove), | ||
1655 | }; | ||
1656 | #endif | ||
1657 | |||
1434 | static int __init alsa_card_miro_init(void) | 1658 | static int __init alsa_card_miro_init(void) |
1435 | { | 1659 | { |
1660 | #ifdef CONFIG_PNP | ||
1661 | pnp_register_card_driver(&miro_pnpc_driver); | ||
1662 | if (snd_miro_pnp_is_probed) | ||
1663 | return 0; | ||
1664 | pnp_unregister_card_driver(&miro_pnpc_driver); | ||
1665 | #endif | ||
1436 | return isa_register_driver(&snd_miro_driver, 1); | 1666 | return isa_register_driver(&snd_miro_driver, 1); |
1437 | } | 1667 | } |
1438 | 1668 | ||
1439 | static void __exit alsa_card_miro_exit(void) | 1669 | static void __exit alsa_card_miro_exit(void) |
1440 | { | 1670 | { |
1441 | isa_unregister_driver(&snd_miro_driver); | 1671 | if (!snd_miro_pnp_is_probed) { |
1672 | isa_unregister_driver(&snd_miro_driver); | ||
1673 | return; | ||
1674 | } | ||
1675 | #ifdef CONFIG_PNP | ||
1676 | pnp_unregister_card_driver(&miro_pnpc_driver); | ||
1677 | #endif | ||
1442 | } | 1678 | } |
1443 | 1679 | ||
1444 | module_init(alsa_card_miro_init) | 1680 | module_init(alsa_card_miro_init) |