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