aboutsummaryrefslogtreecommitdiffstats
path: root/sound/isa
diff options
context:
space:
mode:
Diffstat (limited to 'sound/isa')
-rw-r--r--sound/isa/cs423x/cs4236.c15
-rw-r--r--sound/isa/cs423x/cs4236_lib.c241
-rw-r--r--sound/isa/es18xx.c91
-rw-r--r--sound/isa/opti9xx/miro.c785
-rw-r--r--sound/isa/opti9xx/miro.h73
-rw-r--r--sound/isa/opti9xx/opti92x-ad1848.c242
-rw-r--r--sound/isa/wss/wss_lib.c11
7 files changed, 837 insertions, 621 deletions
diff --git a/sound/isa/cs423x/cs4236.c b/sound/isa/cs423x/cs4236.c
index a076a6ce8071..cc15d1d65a22 100644
--- a/sound/isa/cs423x/cs4236.c
+++ b/sound/isa/cs423x/cs4236.c
@@ -177,7 +177,7 @@ static struct pnp_card_device_id snd_cs423x_pnpids[] = {
177 { .id = "CSC0437", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, 177 { .id = "CSC0437", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
178 /* Digital PC 5000 Onboard - CS4236B */ 178 /* Digital PC 5000 Onboard - CS4236B */
179 { .id = "CSC0735", .devs = { { "CSC0000" }, { "CSC0010" } } }, 179 { .id = "CSC0735", .devs = { { "CSC0000" }, { "CSC0010" } } },
180 /* some uknown CS4236B */ 180 /* some unknown CS4236B */
181 { .id = "CSC0b35", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, 181 { .id = "CSC0b35", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
182 /* Intel PR440FX Onboard sound */ 182 /* Intel PR440FX Onboard sound */
183 { .id = "CSC0b36", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, 183 { .id = "CSC0b36", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
@@ -394,21 +394,15 @@ static int __devinit snd_cs423x_probe(struct snd_card *card, int dev)
394 return -EBUSY; 394 return -EBUSY;
395 } 395 }
396 396
397 err = snd_wss_create(card, port[dev], cport[dev], 397 err = snd_cs4236_create(card, port[dev], cport[dev],
398 irq[dev], 398 irq[dev],
399 dma1[dev], dma2[dev], 399 dma1[dev], dma2[dev],
400 WSS_HW_DETECT3, 0, &chip); 400 WSS_HW_DETECT3, 0, &chip);
401 if (err < 0) 401 if (err < 0)
402 return err; 402 return err;
403
404 acard->chip = chip;
403 if (chip->hardware & WSS_HW_CS4236B_MASK) { 405 if (chip->hardware & WSS_HW_CS4236B_MASK) {
404 snd_wss_free(chip);
405 err = snd_cs4236_create(card,
406 port[dev], cport[dev],
407 irq[dev], dma1[dev], dma2[dev],
408 WSS_HW_DETECT, 0, &chip);
409 if (err < 0)
410 return err;
411 acard->chip = chip;
412 406
413 err = snd_cs4236_pcm(chip, 0, &pcm); 407 err = snd_cs4236_pcm(chip, 0, &pcm);
414 if (err < 0) 408 if (err < 0)
@@ -418,7 +412,6 @@ static int __devinit snd_cs423x_probe(struct snd_card *card, int dev)
418 if (err < 0) 412 if (err < 0)
419 return err; 413 return err;
420 } else { 414 } else {
421 acard->chip = chip;
422 err = snd_wss_pcm(chip, 0, &pcm); 415 err = snd_wss_pcm(chip, 0, &pcm);
423 if (err < 0) 416 if (err < 0)
424 return err; 417 return err;
diff --git a/sound/isa/cs423x/cs4236_lib.c b/sound/isa/cs423x/cs4236_lib.c
index 38835f31298b..c5adca300632 100644
--- a/sound/isa/cs423x/cs4236_lib.c
+++ b/sound/isa/cs423x/cs4236_lib.c
@@ -87,6 +87,8 @@
87#include <sound/core.h> 87#include <sound/core.h>
88#include <sound/wss.h> 88#include <sound/wss.h>
89#include <sound/asoundef.h> 89#include <sound/asoundef.h>
90#include <sound/initval.h>
91#include <sound/tlv.h>
90 92
91/* 93/*
92 * 94 *
@@ -264,7 +266,10 @@ static void snd_cs4236_resume(struct snd_wss *chip)
264} 266}
265 267
266#endif /* CONFIG_PM */ 268#endif /* CONFIG_PM */
267 269/*
270 * This function does no fail if the chip is not CS4236B or compatible.
271 * It just an equivalent to the snd_wss_create() then.
272 */
268int snd_cs4236_create(struct snd_card *card, 273int snd_cs4236_create(struct snd_card *card,
269 unsigned long port, 274 unsigned long port,
270 unsigned long cport, 275 unsigned long cport,
@@ -281,21 +286,17 @@ int snd_cs4236_create(struct snd_card *card,
281 *rchip = NULL; 286 *rchip = NULL;
282 if (hardware == WSS_HW_DETECT) 287 if (hardware == WSS_HW_DETECT)
283 hardware = WSS_HW_DETECT3; 288 hardware = WSS_HW_DETECT3;
284 if (cport < 0x100) { 289
285 snd_printk(KERN_ERR "please, specify control port "
286 "for CS4236+ chips\n");
287 return -ENODEV;
288 }
289 err = snd_wss_create(card, port, cport, 290 err = snd_wss_create(card, port, cport,
290 irq, dma1, dma2, hardware, hwshare, &chip); 291 irq, dma1, dma2, hardware, hwshare, &chip);
291 if (err < 0) 292 if (err < 0)
292 return err; 293 return err;
293 294
294 if (!(chip->hardware & WSS_HW_CS4236B_MASK)) { 295 if ((chip->hardware & WSS_HW_CS4236B_MASK) == 0) {
295 snd_printk(KERN_ERR "CS4236+: MODE3 and extended registers " 296 snd_printd("chip is not CS4236+, hardware=0x%x\n",
296 "not available, hardware=0x%x\n", chip->hardware); 297 chip->hardware);
297 snd_device_free(card, chip); 298 *rchip = chip;
298 return -ENODEV; 299 return 0;
299 } 300 }
300#if 0 301#if 0
301 { 302 {
@@ -308,9 +309,16 @@ int snd_cs4236_create(struct snd_card *card,
308 idx, snd_cs4236_ctrl_in(chip, idx)); 309 idx, snd_cs4236_ctrl_in(chip, idx));
309 } 310 }
310#endif 311#endif
312 if (cport < 0x100 || cport == SNDRV_AUTO_PORT) {
313 snd_printk(KERN_ERR "please, specify control port "
314 "for CS4236+ chips\n");
315 snd_device_free(card, chip);
316 return -ENODEV;
317 }
311 ver1 = snd_cs4236_ctrl_in(chip, 1); 318 ver1 = snd_cs4236_ctrl_in(chip, 1);
312 ver2 = snd_cs4236_ext_in(chip, CS4236_VERSION); 319 ver2 = snd_cs4236_ext_in(chip, CS4236_VERSION);
313 snd_printdd("CS4236: [0x%lx] C1 (version) = 0x%x, ext = 0x%x\n", cport, ver1, ver2); 320 snd_printdd("CS4236: [0x%lx] C1 (version) = 0x%x, ext = 0x%x\n",
321 cport, ver1, ver2);
314 if (ver1 != ver2) { 322 if (ver1 != ver2) {
315 snd_printk(KERN_ERR "CS4236+ chip detected, but " 323 snd_printk(KERN_ERR "CS4236+ chip detected, but "
316 "control port 0x%lx is not valid\n", cport); 324 "control port 0x%lx is not valid\n", cport);
@@ -321,13 +329,17 @@ int snd_cs4236_create(struct snd_card *card,
321 snd_cs4236_ctrl_out(chip, 2, 0xff); 329 snd_cs4236_ctrl_out(chip, 2, 0xff);
322 snd_cs4236_ctrl_out(chip, 3, 0x00); 330 snd_cs4236_ctrl_out(chip, 3, 0x00);
323 snd_cs4236_ctrl_out(chip, 4, 0x80); 331 snd_cs4236_ctrl_out(chip, 4, 0x80);
324 snd_cs4236_ctrl_out(chip, 5, ((IEC958_AES1_CON_PCM_CODER & 3) << 6) | IEC958_AES0_CON_EMPHASIS_NONE); 332 reg = ((IEC958_AES1_CON_PCM_CODER & 3) << 6) |
333 IEC958_AES0_CON_EMPHASIS_NONE;
334 snd_cs4236_ctrl_out(chip, 5, reg);
325 snd_cs4236_ctrl_out(chip, 6, IEC958_AES1_CON_PCM_CODER >> 2); 335 snd_cs4236_ctrl_out(chip, 6, IEC958_AES1_CON_PCM_CODER >> 2);
326 snd_cs4236_ctrl_out(chip, 7, 0x00); 336 snd_cs4236_ctrl_out(chip, 7, 0x00);
327 /* 0x8c for C8 is valid for Turtle Beach Malibu - the IEC-958 output */ 337 /*
328 /* is working with this setup, other hardware should have */ 338 * 0x8c for C8 is valid for Turtle Beach Malibu - the IEC-958
329 /* different signal paths and this value should be selectable */ 339 * output is working with this setup, other hardware should
330 /* in the future */ 340 * have different signal paths and this value should be
341 * selectable in the future
342 */
331 snd_cs4236_ctrl_out(chip, 8, 0x8c); 343 snd_cs4236_ctrl_out(chip, 8, 0x8c);
332 chip->rate_constraint = snd_cs4236_xrate; 344 chip->rate_constraint = snd_cs4236_xrate;
333 chip->set_playback_format = snd_cs4236_playback_format; 345 chip->set_playback_format = snd_cs4236_playback_format;
@@ -339,9 +351,10 @@ int snd_cs4236_create(struct snd_card *card,
339 351
340 /* initialize extended registers */ 352 /* initialize extended registers */
341 for (reg = 0; reg < sizeof(snd_cs4236_ext_map); reg++) 353 for (reg = 0; reg < sizeof(snd_cs4236_ext_map); reg++)
342 snd_cs4236_ext_out(chip, CS4236_I23VAL(reg), snd_cs4236_ext_map[reg]); 354 snd_cs4236_ext_out(chip, CS4236_I23VAL(reg),
355 snd_cs4236_ext_map[reg]);
343 356
344 /* initialize compatible but more featured registers */ 357 /* initialize compatible but more featured registers */
345 snd_wss_out(chip, CS4231_LEFT_INPUT, 0x40); 358 snd_wss_out(chip, CS4231_LEFT_INPUT, 0x40);
346 snd_wss_out(chip, CS4231_RIGHT_INPUT, 0x40); 359 snd_wss_out(chip, CS4231_RIGHT_INPUT, 0x40);
347 snd_wss_out(chip, CS4231_AUX1_LEFT_INPUT, 0xff); 360 snd_wss_out(chip, CS4231_AUX1_LEFT_INPUT, 0xff);
@@ -387,6 +400,14 @@ int snd_cs4236_pcm(struct snd_wss *chip, int device, struct snd_pcm **rpcm)
387 .get = snd_cs4236_get_single, .put = snd_cs4236_put_single, \ 400 .get = snd_cs4236_get_single, .put = snd_cs4236_put_single, \
388 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) } 401 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
389 402
403#define CS4236_SINGLE_TLV(xname, xindex, reg, shift, mask, invert, xtlv) \
404{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
405 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
406 .info = snd_cs4236_info_single, \
407 .get = snd_cs4236_get_single, .put = snd_cs4236_put_single, \
408 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24), \
409 .tlv = { .p = (xtlv) } }
410
390static int snd_cs4236_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 411static int snd_cs4236_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
391{ 412{
392 int mask = (kcontrol->private_value >> 16) & 0xff; 413 int mask = (kcontrol->private_value >> 16) & 0xff;
@@ -490,6 +511,16 @@ static int snd_cs4236_put_singlec(struct snd_kcontrol *kcontrol, struct snd_ctl_
490 .get = snd_cs4236_get_double, .put = snd_cs4236_put_double, \ 511 .get = snd_cs4236_get_double, .put = snd_cs4236_put_double, \
491 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) } 512 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
492 513
514#define CS4236_DOUBLE_TLV(xname, xindex, left_reg, right_reg, shift_left, \
515 shift_right, mask, invert, xtlv) \
516{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
517 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
518 .info = snd_cs4236_info_double, \
519 .get = snd_cs4236_get_double, .put = snd_cs4236_put_double, \
520 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | \
521 (shift_right << 19) | (mask << 24) | (invert << 22), \
522 .tlv = { .p = (xtlv) } }
523
493static int snd_cs4236_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 524static int snd_cs4236_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
494{ 525{
495 int mask = (kcontrol->private_value >> 24) & 0xff; 526 int mask = (kcontrol->private_value >> 24) & 0xff;
@@ -560,12 +591,23 @@ static int snd_cs4236_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_e
560 return change; 591 return change;
561} 592}
562 593
563#define CS4236_DOUBLE1(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \ 594#define CS4236_DOUBLE1(xname, xindex, left_reg, right_reg, shift_left, \
595 shift_right, mask, invert) \
564{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 596{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
565 .info = snd_cs4236_info_double, \ 597 .info = snd_cs4236_info_double, \
566 .get = snd_cs4236_get_double1, .put = snd_cs4236_put_double1, \ 598 .get = snd_cs4236_get_double1, .put = snd_cs4236_put_double1, \
567 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) } 599 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
568 600
601#define CS4236_DOUBLE1_TLV(xname, xindex, left_reg, right_reg, shift_left, \
602 shift_right, mask, invert, xtlv) \
603{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
604 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
605 .info = snd_cs4236_info_double, \
606 .get = snd_cs4236_get_double1, .put = snd_cs4236_put_double1, \
607 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | \
608 (shift_right << 19) | (mask << 24) | (invert << 22), \
609 .tlv = { .p = (xtlv) } }
610
569static int snd_cs4236_get_double1(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 611static int snd_cs4236_get_double1(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
570{ 612{
571 struct snd_wss *chip = snd_kcontrol_chip(kcontrol); 613 struct snd_wss *chip = snd_kcontrol_chip(kcontrol);
@@ -619,16 +661,18 @@ static int snd_cs4236_put_double1(struct snd_kcontrol *kcontrol, struct snd_ctl_
619 return change; 661 return change;
620} 662}
621 663
622#define CS4236_MASTER_DIGITAL(xname, xindex) \ 664#define CS4236_MASTER_DIGITAL(xname, xindex, xtlv) \
623{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 665{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
666 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
624 .info = snd_cs4236_info_double, \ 667 .info = snd_cs4236_info_double, \
625 .get = snd_cs4236_get_master_digital, .put = snd_cs4236_put_master_digital, \ 668 .get = snd_cs4236_get_master_digital, .put = snd_cs4236_put_master_digital, \
626 .private_value = 71 << 24 } 669 .private_value = 71 << 24, \
670 .tlv = { .p = (xtlv) } }
627 671
628static inline int snd_cs4236_mixer_master_digital_invert_volume(int vol) 672static inline int snd_cs4236_mixer_master_digital_invert_volume(int vol)
629{ 673{
630 return (vol < 64) ? 63 - vol : 64 + (71 - vol); 674 return (vol < 64) ? 63 - vol : 64 + (71 - vol);
631} 675}
632 676
633static int snd_cs4236_get_master_digital(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 677static int snd_cs4236_get_master_digital(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
634{ 678{
@@ -661,11 +705,13 @@ static int snd_cs4236_put_master_digital(struct snd_kcontrol *kcontrol, struct s
661 return change; 705 return change;
662} 706}
663 707
664#define CS4235_OUTPUT_ACCU(xname, xindex) \ 708#define CS4235_OUTPUT_ACCU(xname, xindex, xtlv) \
665{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 709{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
710 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
666 .info = snd_cs4236_info_double, \ 711 .info = snd_cs4236_info_double, \
667 .get = snd_cs4235_get_output_accu, .put = snd_cs4235_put_output_accu, \ 712 .get = snd_cs4235_get_output_accu, .put = snd_cs4235_put_output_accu, \
668 .private_value = 3 << 24 } 713 .private_value = 3 << 24, \
714 .tlv = { .p = (xtlv) } }
669 715
670static inline int snd_cs4235_mixer_output_accu_get_volume(int vol) 716static inline int snd_cs4235_mixer_output_accu_get_volume(int vol)
671{ 717{
@@ -720,41 +766,56 @@ static int snd_cs4235_put_output_accu(struct snd_kcontrol *kcontrol, struct snd_
720 return change; 766 return change;
721} 767}
722 768
769static const DECLARE_TLV_DB_SCALE(db_scale_7bit, -9450, 150, 0);
770static const DECLARE_TLV_DB_SCALE(db_scale_6bit, -9450, 150, 0);
771static const DECLARE_TLV_DB_SCALE(db_scale_6bit_12db_max, -8250, 150, 0);
772static const DECLARE_TLV_DB_SCALE(db_scale_5bit_12db_max, -3450, 150, 0);
773static const DECLARE_TLV_DB_SCALE(db_scale_5bit_22db_max, -2400, 150, 0);
774static const DECLARE_TLV_DB_SCALE(db_scale_4bit, -4500, 300, 0);
775static const DECLARE_TLV_DB_SCALE(db_scale_2bit, -1800, 600, 0);
776static const DECLARE_TLV_DB_SCALE(db_scale_rec_gain, 0, 150, 0);
777
723static struct snd_kcontrol_new snd_cs4236_controls[] = { 778static struct snd_kcontrol_new snd_cs4236_controls[] = {
724 779
725CS4236_DOUBLE("Master Digital Playback Switch", 0, 780CS4236_DOUBLE("Master Digital Playback Switch", 0,
726 CS4236_LEFT_MASTER, CS4236_RIGHT_MASTER, 7, 7, 1, 1), 781 CS4236_LEFT_MASTER, CS4236_RIGHT_MASTER, 7, 7, 1, 1),
727CS4236_DOUBLE("Master Digital Capture Switch", 0, 782CS4236_DOUBLE("Master Digital Capture Switch", 0,
728 CS4236_DAC_MUTE, CS4236_DAC_MUTE, 7, 6, 1, 1), 783 CS4236_DAC_MUTE, CS4236_DAC_MUTE, 7, 6, 1, 1),
729CS4236_MASTER_DIGITAL("Master Digital Volume", 0), 784CS4236_MASTER_DIGITAL("Master Digital Volume", 0, db_scale_7bit),
730 785
731CS4236_DOUBLE("Capture Boost Volume", 0, 786CS4236_DOUBLE_TLV("Capture Boost Volume", 0,
732 CS4236_LEFT_MIX_CTRL, CS4236_RIGHT_MIX_CTRL, 5, 5, 3, 1), 787 CS4236_LEFT_MIX_CTRL, CS4236_RIGHT_MIX_CTRL, 5, 5, 3, 1,
788 db_scale_2bit),
733 789
734WSS_DOUBLE("PCM Playback Switch", 0, 790WSS_DOUBLE("PCM Playback Switch", 0,
735 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1), 791 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
736WSS_DOUBLE("PCM Playback Volume", 0, 792WSS_DOUBLE_TLV("PCM Playback Volume", 0,
737 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1), 793 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1,
794 db_scale_6bit),
738 795
739CS4236_DOUBLE("DSP Playback Switch", 0, 796CS4236_DOUBLE("DSP Playback Switch", 0,
740 CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 7, 7, 1, 1), 797 CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 7, 7, 1, 1),
741CS4236_DOUBLE("DSP Playback Volume", 0, 798CS4236_DOUBLE_TLV("DSP Playback Volume", 0,
742 CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 0, 0, 63, 1), 799 CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 0, 0, 63, 1,
800 db_scale_6bit),
743 801
744CS4236_DOUBLE("FM Playback Switch", 0, 802CS4236_DOUBLE("FM Playback Switch", 0,
745 CS4236_LEFT_FM, CS4236_RIGHT_FM, 7, 7, 1, 1), 803 CS4236_LEFT_FM, CS4236_RIGHT_FM, 7, 7, 1, 1),
746CS4236_DOUBLE("FM Playback Volume", 0, 804CS4236_DOUBLE_TLV("FM Playback Volume", 0,
747 CS4236_LEFT_FM, CS4236_RIGHT_FM, 0, 0, 63, 1), 805 CS4236_LEFT_FM, CS4236_RIGHT_FM, 0, 0, 63, 1,
806 db_scale_6bit),
748 807
749CS4236_DOUBLE("Wavetable Playback Switch", 0, 808CS4236_DOUBLE("Wavetable Playback Switch", 0,
750 CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 7, 7, 1, 1), 809 CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 7, 7, 1, 1),
751CS4236_DOUBLE("Wavetable Playback Volume", 0, 810CS4236_DOUBLE_TLV("Wavetable Playback Volume", 0,
752 CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 0, 0, 63, 1), 811 CS4236_LEFT_WAVE, CS4236_RIGHT_WAVE, 0, 0, 63, 1,
812 db_scale_6bit_12db_max),
753 813
754WSS_DOUBLE("Synth Playback Switch", 0, 814WSS_DOUBLE("Synth Playback Switch", 0,
755 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1), 815 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
756WSS_DOUBLE("Synth Volume", 0, 816WSS_DOUBLE_TLV("Synth Volume", 0,
757 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1), 817 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1,
818 db_scale_5bit_12db_max),
758WSS_DOUBLE("Synth Capture Switch", 0, 819WSS_DOUBLE("Synth Capture Switch", 0,
759 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 6, 6, 1, 1), 820 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 6, 6, 1, 1),
760WSS_DOUBLE("Synth Capture Bypass", 0, 821WSS_DOUBLE("Synth Capture Bypass", 0,
@@ -764,14 +825,16 @@ CS4236_DOUBLE("Mic Playback Switch", 0,
764 CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 6, 6, 1, 1), 825 CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 6, 6, 1, 1),
765CS4236_DOUBLE("Mic Capture Switch", 0, 826CS4236_DOUBLE("Mic Capture Switch", 0,
766 CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 7, 7, 1, 1), 827 CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 7, 7, 1, 1),
767CS4236_DOUBLE("Mic Volume", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 0, 0, 31, 1), 828CS4236_DOUBLE_TLV("Mic Volume", 0, CS4236_LEFT_MIC, CS4236_RIGHT_MIC,
768CS4236_DOUBLE("Mic Playback Boost", 0, 829 0, 0, 31, 1, db_scale_5bit_22db_max),
830CS4236_DOUBLE("Mic Playback Boost (+20dB)", 0,
769 CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 5, 5, 1, 0), 831 CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 5, 5, 1, 0),
770 832
771WSS_DOUBLE("Line Playback Switch", 0, 833WSS_DOUBLE("Line Playback Switch", 0,
772 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1), 834 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
773WSS_DOUBLE("Line Volume", 0, 835WSS_DOUBLE_TLV("Line Volume", 0,
774 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1), 836 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1,
837 db_scale_5bit_12db_max),
775WSS_DOUBLE("Line Capture Switch", 0, 838WSS_DOUBLE("Line Capture Switch", 0,
776 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 6, 6, 1, 1), 839 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 6, 6, 1, 1),
777WSS_DOUBLE("Line Capture Bypass", 0, 840WSS_DOUBLE("Line Capture Bypass", 0,
@@ -779,57 +842,63 @@ WSS_DOUBLE("Line Capture Bypass", 0,
779 842
780WSS_DOUBLE("CD Playback Switch", 0, 843WSS_DOUBLE("CD Playback Switch", 0,
781 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1), 844 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
782WSS_DOUBLE("CD Volume", 0, 845WSS_DOUBLE_TLV("CD Volume", 0,
783 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1), 846 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1,
847 db_scale_5bit_12db_max),
784WSS_DOUBLE("CD Capture Switch", 0, 848WSS_DOUBLE("CD Capture Switch", 0,
785 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 6, 6, 1, 1), 849 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 6, 6, 1, 1),
786 850
787CS4236_DOUBLE1("Mono Output Playback Switch", 0, 851CS4236_DOUBLE1("Mono Output Playback Switch", 0,
788 CS4231_MONO_CTRL, CS4236_RIGHT_MIX_CTRL, 6, 7, 1, 1), 852 CS4231_MONO_CTRL, CS4236_RIGHT_MIX_CTRL, 6, 7, 1, 1),
789CS4236_DOUBLE1("Mono Playback Switch", 0, 853CS4236_DOUBLE1("Beep Playback Switch", 0,
790 CS4231_MONO_CTRL, CS4236_LEFT_MIX_CTRL, 7, 7, 1, 1), 854 CS4231_MONO_CTRL, CS4236_LEFT_MIX_CTRL, 7, 7, 1, 1),
791WSS_SINGLE("Mono Playback Volume", 0, CS4231_MONO_CTRL, 0, 15, 1), 855WSS_SINGLE_TLV("Beep Playback Volume", 0, CS4231_MONO_CTRL, 0, 15, 1,
792WSS_SINGLE("Mono Playback Bypass", 0, CS4231_MONO_CTRL, 5, 1, 0), 856 db_scale_4bit),
857WSS_SINGLE("Beep Bypass Playback Switch", 0, CS4231_MONO_CTRL, 5, 1, 0),
793 858
794WSS_DOUBLE("Capture Volume", 0, 859WSS_DOUBLE_TLV("Capture Volume", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT,
795 CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, 15, 0), 860 0, 0, 15, 0, db_scale_rec_gain),
796WSS_DOUBLE("Analog Loopback Capture Switch", 0, 861WSS_DOUBLE("Analog Loopback Capture Switch", 0,
797 CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 7, 7, 1, 0), 862 CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 7, 7, 1, 0),
798 863
799WSS_SINGLE("Digital Loopback Playback Switch", 0, CS4231_LOOPBACK, 0, 1, 0), 864WSS_SINGLE("Loopback Digital Playback Switch", 0, CS4231_LOOPBACK, 0, 1, 0),
800CS4236_DOUBLE1("Digital Loopback Playback Volume", 0, 865CS4236_DOUBLE1_TLV("Loopback Digital Playback Volume", 0,
801 CS4231_LOOPBACK, CS4236_RIGHT_LOOPBACK, 2, 0, 63, 1) 866 CS4231_LOOPBACK, CS4236_RIGHT_LOOPBACK, 2, 0, 63, 1,
867 db_scale_6bit),
802}; 868};
803 869
870static const DECLARE_TLV_DB_SCALE(db_scale_5bit_6db_max, -5600, 200, 0);
871static const DECLARE_TLV_DB_SCALE(db_scale_2bit_16db_max, -2400, 800, 0);
872
804static struct snd_kcontrol_new snd_cs4235_controls[] = { 873static struct snd_kcontrol_new snd_cs4235_controls[] = {
805 874
806WSS_DOUBLE("Master Switch", 0, 875WSS_DOUBLE("Master Playback Switch", 0,
807 CS4235_LEFT_MASTER, CS4235_RIGHT_MASTER, 7, 7, 1, 1), 876 CS4235_LEFT_MASTER, CS4235_RIGHT_MASTER, 7, 7, 1, 1),
808WSS_DOUBLE("Master Volume", 0, 877WSS_DOUBLE_TLV("Master Playback Volume", 0,
809 CS4235_LEFT_MASTER, CS4235_RIGHT_MASTER, 0, 0, 31, 1), 878 CS4235_LEFT_MASTER, CS4235_RIGHT_MASTER, 0, 0, 31, 1,
810 879 db_scale_5bit_6db_max),
811CS4235_OUTPUT_ACCU("Playback Volume", 0),
812 880
813CS4236_DOUBLE("Master Digital Playback Switch", 0, 881CS4235_OUTPUT_ACCU("Playback Volume", 0, db_scale_2bit_16db_max),
814 CS4236_LEFT_MASTER, CS4236_RIGHT_MASTER, 7, 7, 1, 1),
815CS4236_DOUBLE("Master Digital Capture Switch", 0,
816 CS4236_DAC_MUTE, CS4236_DAC_MUTE, 7, 6, 1, 1),
817CS4236_MASTER_DIGITAL("Master Digital Volume", 0),
818 882
819WSS_DOUBLE("Master Digital Playback Switch", 1, 883WSS_DOUBLE("Synth Playback Switch", 1,
820 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1), 884 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
821WSS_DOUBLE("Master Digital Capture Switch", 1, 885WSS_DOUBLE("Synth Capture Switch", 1,
822 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 6, 6, 1, 1), 886 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 6, 6, 1, 1),
823WSS_DOUBLE("Master Digital Volume", 1, 887WSS_DOUBLE_TLV("Synth Volume", 1,
824 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1), 888 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1,
889 db_scale_5bit_12db_max),
825 890
826CS4236_DOUBLE("Capture Volume", 0, 891CS4236_DOUBLE_TLV("Capture Volume", 0,
827 CS4236_LEFT_MIX_CTRL, CS4236_RIGHT_MIX_CTRL, 5, 5, 3, 1), 892 CS4236_LEFT_MIX_CTRL, CS4236_RIGHT_MIX_CTRL, 5, 5, 3, 1,
893 db_scale_2bit),
828 894
829WSS_DOUBLE("PCM Switch", 0, 895WSS_DOUBLE("PCM Playback Switch", 0,
830 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1), 896 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
831WSS_DOUBLE("PCM Volume", 0, 897WSS_DOUBLE("PCM Capture Switch", 0,
832 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1), 898 CS4236_DAC_MUTE, CS4236_DAC_MUTE, 7, 6, 1, 1),
899WSS_DOUBLE_TLV("PCM Volume", 0,
900 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1,
901 db_scale_6bit),
833 902
834CS4236_DOUBLE("DSP Switch", 0, CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 7, 7, 1, 1), 903CS4236_DOUBLE("DSP Switch", 0, CS4236_LEFT_DSP, CS4236_RIGHT_DSP, 7, 7, 1, 1),
835 904
@@ -842,29 +911,29 @@ CS4236_DOUBLE("Mic Capture Switch", 0,
842 CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 7, 7, 1, 1), 911 CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 7, 7, 1, 1),
843CS4236_DOUBLE("Mic Playback Switch", 0, 912CS4236_DOUBLE("Mic Playback Switch", 0,
844 CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 6, 6, 1, 1), 913 CS4236_LEFT_MIC, CS4236_RIGHT_MIC, 6, 6, 1, 1),
845CS4236_SINGLE("Mic Volume", 0, CS4236_LEFT_MIC, 0, 31, 1), 914CS4236_SINGLE_TLV("Mic Volume", 0, CS4236_LEFT_MIC, 0, 31, 1,
846CS4236_SINGLE("Mic Playback Boost", 0, CS4236_LEFT_MIC, 5, 1, 0), 915 db_scale_5bit_22db_max),
916CS4236_SINGLE("Mic Boost (+20dB)", 0, CS4236_LEFT_MIC, 5, 1, 0),
847 917
848WSS_DOUBLE("Aux Playback Switch", 0, 918WSS_DOUBLE("Line Playback Switch", 0,
849 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1), 919 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
850WSS_DOUBLE("Aux Capture Switch", 0, 920WSS_DOUBLE("Line Capture Switch", 0,
851 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 6, 6, 1, 1), 921 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 6, 6, 1, 1),
852WSS_DOUBLE("Aux Volume", 0, 922WSS_DOUBLE_TLV("Line Volume", 0,
853 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1), 923 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1,
924 db_scale_5bit_12db_max),
854 925
855WSS_DOUBLE("Aux Playback Switch", 1, 926WSS_DOUBLE("CD Playback Switch", 1,
856 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1), 927 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
857WSS_DOUBLE("Aux Capture Switch", 1, 928WSS_DOUBLE("CD Capture Switch", 1,
858 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 6, 6, 1, 1), 929 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 6, 6, 1, 1),
859WSS_DOUBLE("Aux Volume", 1, 930WSS_DOUBLE_TLV("CD Volume", 1,
860 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1), 931 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1,
861 932 db_scale_5bit_12db_max),
862CS4236_DOUBLE1("Master Mono Switch", 0,
863 CS4231_MONO_CTRL, CS4236_RIGHT_MIX_CTRL, 6, 7, 1, 1),
864 933
865CS4236_DOUBLE1("Mono Switch", 0, 934CS4236_DOUBLE1("Beep Playback Switch", 0,
866 CS4231_MONO_CTRL, CS4236_LEFT_MIX_CTRL, 7, 7, 1, 1), 935 CS4231_MONO_CTRL, CS4236_LEFT_MIX_CTRL, 7, 7, 1, 1),
867WSS_SINGLE("Mono Volume", 0, CS4231_MONO_CTRL, 0, 15, 1), 936WSS_SINGLE("Beep Playback Volume", 0, CS4231_MONO_CTRL, 0, 15, 1),
868 937
869WSS_DOUBLE("Analog Loopback Switch", 0, 938WSS_DOUBLE("Analog Loopback Switch", 0,
870 CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 7, 7, 1, 0), 939 CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 7, 7, 1, 0),
diff --git a/sound/isa/es18xx.c b/sound/isa/es18xx.c
index e5bf3355d2ca..9a43baae7250 100644
--- a/sound/isa/es18xx.c
+++ b/sound/isa/es18xx.c
@@ -102,8 +102,6 @@
102 102
103struct snd_es18xx { 103struct snd_es18xx {
104 unsigned long port; /* port of ESS chip */ 104 unsigned long port; /* port of ESS chip */
105 unsigned long mpu_port; /* MPU-401 port of ESS chip */
106 unsigned long fm_port; /* FM port */
107 unsigned long ctrl_port; /* Control port of ESS chip */ 105 unsigned long ctrl_port; /* Control port of ESS chip */
108 struct resource *res_port; 106 struct resource *res_port;
109 struct resource *res_mpu_port; 107 struct resource *res_mpu_port;
@@ -116,8 +114,6 @@ struct snd_es18xx {
116 unsigned short audio2_vol; /* volume level of audio2 */ 114 unsigned short audio2_vol; /* volume level of audio2 */
117 115
118 unsigned short active; /* active channel mask */ 116 unsigned short active; /* active channel mask */
119 unsigned int dma1_size;
120 unsigned int dma2_size;
121 unsigned int dma1_shift; 117 unsigned int dma1_shift;
122 unsigned int dma2_shift; 118 unsigned int dma2_shift;
123 119
@@ -135,7 +131,6 @@ struct snd_es18xx {
135 131
136 spinlock_t reg_lock; 132 spinlock_t reg_lock;
137 spinlock_t mixer_lock; 133 spinlock_t mixer_lock;
138 spinlock_t ctrl_lock;
139#ifdef CONFIG_PM 134#ifdef CONFIG_PM
140 unsigned char pm_reg; 135 unsigned char pm_reg;
141#endif 136#endif
@@ -354,7 +349,7 @@ static inline int snd_es18xx_mixer_writable(struct snd_es18xx *chip, unsigned ch
354} 349}
355 350
356 351
357static int snd_es18xx_reset(struct snd_es18xx *chip) 352static int __devinit snd_es18xx_reset(struct snd_es18xx *chip)
358{ 353{
359 int i; 354 int i;
360 outb(0x03, chip->port + 0x06); 355 outb(0x03, chip->port + 0x06);
@@ -490,8 +485,6 @@ static int snd_es18xx_playback1_prepare(struct snd_es18xx *chip,
490 unsigned int size = snd_pcm_lib_buffer_bytes(substream); 485 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
491 unsigned int count = snd_pcm_lib_period_bytes(substream); 486 unsigned int count = snd_pcm_lib_period_bytes(substream);
492 487
493 chip->dma2_size = size;
494
495 snd_es18xx_rate_set(chip, substream, DAC2); 488 snd_es18xx_rate_set(chip, substream, DAC2);
496 489
497 /* Transfer Count Reload */ 490 /* Transfer Count Reload */
@@ -591,8 +584,6 @@ static int snd_es18xx_capture_prepare(struct snd_pcm_substream *substream)
591 unsigned int size = snd_pcm_lib_buffer_bytes(substream); 584 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
592 unsigned int count = snd_pcm_lib_period_bytes(substream); 585 unsigned int count = snd_pcm_lib_period_bytes(substream);
593 586
594 chip->dma1_size = size;
595
596 snd_es18xx_reset_fifo(chip); 587 snd_es18xx_reset_fifo(chip);
597 588
598 /* Set stereo/mono */ 589 /* Set stereo/mono */
@@ -659,8 +650,6 @@ static int snd_es18xx_playback2_prepare(struct snd_es18xx *chip,
659 unsigned int size = snd_pcm_lib_buffer_bytes(substream); 650 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
660 unsigned int count = snd_pcm_lib_period_bytes(substream); 651 unsigned int count = snd_pcm_lib_period_bytes(substream);
661 652
662 chip->dma1_size = size;
663
664 snd_es18xx_reset_fifo(chip); 653 snd_es18xx_reset_fifo(chip);
665 654
666 /* Set stereo/mono */ 655 /* Set stereo/mono */
@@ -821,17 +810,18 @@ static irqreturn_t snd_es18xx_interrupt(int irq, void *dev_id)
821static snd_pcm_uframes_t snd_es18xx_playback_pointer(struct snd_pcm_substream *substream) 810static snd_pcm_uframes_t snd_es18xx_playback_pointer(struct snd_pcm_substream *substream)
822{ 811{
823 struct snd_es18xx *chip = snd_pcm_substream_chip(substream); 812 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
813 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
824 int pos; 814 int pos;
825 815
826 if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) { 816 if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) {
827 if (!(chip->active & DAC2)) 817 if (!(chip->active & DAC2))
828 return 0; 818 return 0;
829 pos = snd_dma_pointer(chip->dma2, chip->dma2_size); 819 pos = snd_dma_pointer(chip->dma2, size);
830 return pos >> chip->dma2_shift; 820 return pos >> chip->dma2_shift;
831 } else { 821 } else {
832 if (!(chip->active & DAC1)) 822 if (!(chip->active & DAC1))
833 return 0; 823 return 0;
834 pos = snd_dma_pointer(chip->dma1, chip->dma1_size); 824 pos = snd_dma_pointer(chip->dma1, size);
835 return pos >> chip->dma1_shift; 825 return pos >> chip->dma1_shift;
836 } 826 }
837} 827}
@@ -839,11 +829,12 @@ static snd_pcm_uframes_t snd_es18xx_playback_pointer(struct snd_pcm_substream *s
839static snd_pcm_uframes_t snd_es18xx_capture_pointer(struct snd_pcm_substream *substream) 829static snd_pcm_uframes_t snd_es18xx_capture_pointer(struct snd_pcm_substream *substream)
840{ 830{
841 struct snd_es18xx *chip = snd_pcm_substream_chip(substream); 831 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
832 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
842 int pos; 833 int pos;
843 834
844 if (!(chip->active & ADC1)) 835 if (!(chip->active & ADC1))
845 return 0; 836 return 0;
846 pos = snd_dma_pointer(chip->dma1, chip->dma1_size); 837 pos = snd_dma_pointer(chip->dma1, size);
847 return pos >> chip->dma1_shift; 838 return pos >> chip->dma1_shift;
848} 839}
849 840
@@ -974,9 +965,6 @@ static int snd_es18xx_capture_close(struct snd_pcm_substream *substream)
974 965
975static int snd_es18xx_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 966static int snd_es18xx_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
976{ 967{
977 static char *texts4Source[4] = {
978 "Mic", "CD", "Line", "Master"
979 };
980 static char *texts5Source[5] = { 968 static char *texts5Source[5] = {
981 "Mic", "CD", "Line", "Master", "Mix" 969 "Mic", "CD", "Line", "Master", "Mix"
982 }; 970 };
@@ -994,7 +982,8 @@ static int snd_es18xx_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_ele
994 uinfo->value.enumerated.items = 4; 982 uinfo->value.enumerated.items = 4;
995 if (uinfo->value.enumerated.item > 3) 983 if (uinfo->value.enumerated.item > 3)
996 uinfo->value.enumerated.item = 3; 984 uinfo->value.enumerated.item = 3;
997 strcpy(uinfo->value.enumerated.name, texts4Source[uinfo->value.enumerated.item]); 985 strcpy(uinfo->value.enumerated.name,
986 texts5Source[uinfo->value.enumerated.item]);
998 break; 987 break;
999 case 0x1887: 988 case 0x1887:
1000 case 0x1888: 989 case 0x1888:
@@ -1378,11 +1367,9 @@ ES18XX_SINGLE("Hardware Master Volume Split", 0, 0x64, 7, 1, 0),
1378static int __devinit snd_es18xx_config_read(struct snd_es18xx *chip, unsigned char reg) 1367static int __devinit snd_es18xx_config_read(struct snd_es18xx *chip, unsigned char reg)
1379{ 1368{
1380 int data; 1369 int data;
1381 unsigned long flags; 1370
1382 spin_lock_irqsave(&chip->ctrl_lock, flags);
1383 outb(reg, chip->ctrl_port); 1371 outb(reg, chip->ctrl_port);
1384 data = inb(chip->ctrl_port + 1); 1372 data = inb(chip->ctrl_port + 1);
1385 spin_unlock_irqrestore(&chip->ctrl_lock, flags);
1386 return data; 1373 return data;
1387} 1374}
1388 1375
@@ -1398,7 +1385,9 @@ static void __devinit snd_es18xx_config_write(struct snd_es18xx *chip,
1398#endif 1385#endif
1399} 1386}
1400 1387
1401static int __devinit snd_es18xx_initialize(struct snd_es18xx *chip) 1388static int __devinit snd_es18xx_initialize(struct snd_es18xx *chip,
1389 unsigned long mpu_port,
1390 unsigned long fm_port)
1402{ 1391{
1403 int mask = 0; 1392 int mask = 0;
1404 1393
@@ -1412,15 +1401,15 @@ static int __devinit snd_es18xx_initialize(struct snd_es18xx *chip)
1412 if (chip->caps & ES18XX_CONTROL) { 1401 if (chip->caps & ES18XX_CONTROL) {
1413 /* Hardware volume IRQ */ 1402 /* Hardware volume IRQ */
1414 snd_es18xx_config_write(chip, 0x27, chip->irq); 1403 snd_es18xx_config_write(chip, 0x27, chip->irq);
1415 if (chip->fm_port > 0 && chip->fm_port != SNDRV_AUTO_PORT) { 1404 if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT) {
1416 /* FM I/O */ 1405 /* FM I/O */
1417 snd_es18xx_config_write(chip, 0x62, chip->fm_port >> 8); 1406 snd_es18xx_config_write(chip, 0x62, fm_port >> 8);
1418 snd_es18xx_config_write(chip, 0x63, chip->fm_port & 0xff); 1407 snd_es18xx_config_write(chip, 0x63, fm_port & 0xff);
1419 } 1408 }
1420 if (chip->mpu_port > 0 && chip->mpu_port != SNDRV_AUTO_PORT) { 1409 if (mpu_port > 0 && mpu_port != SNDRV_AUTO_PORT) {
1421 /* MPU-401 I/O */ 1410 /* MPU-401 I/O */
1422 snd_es18xx_config_write(chip, 0x64, chip->mpu_port >> 8); 1411 snd_es18xx_config_write(chip, 0x64, mpu_port >> 8);
1423 snd_es18xx_config_write(chip, 0x65, chip->mpu_port & 0xff); 1412 snd_es18xx_config_write(chip, 0x65, mpu_port & 0xff);
1424 /* MPU-401 IRQ */ 1413 /* MPU-401 IRQ */
1425 snd_es18xx_config_write(chip, 0x28, chip->irq); 1414 snd_es18xx_config_write(chip, 0x28, chip->irq);
1426 } 1415 }
@@ -1507,11 +1496,12 @@ static int __devinit snd_es18xx_initialize(struct snd_es18xx *chip)
1507 snd_es18xx_mixer_write(chip, 0x7A, 0x68); 1496 snd_es18xx_mixer_write(chip, 0x7A, 0x68);
1508 /* Enable and set hardware volume interrupt */ 1497 /* Enable and set hardware volume interrupt */
1509 snd_es18xx_mixer_write(chip, 0x64, 0x06); 1498 snd_es18xx_mixer_write(chip, 0x64, 0x06);
1510 if (chip->mpu_port > 0 && chip->mpu_port != SNDRV_AUTO_PORT) { 1499 if (mpu_port > 0 && mpu_port != SNDRV_AUTO_PORT) {
1511 /* MPU401 share irq with audio 1500 /* MPU401 share irq with audio
1512 Joystick enabled 1501 Joystick enabled
1513 FM enabled */ 1502 FM enabled */
1514 snd_es18xx_mixer_write(chip, 0x40, 0x43 | (chip->mpu_port & 0xf0) >> 1); 1503 snd_es18xx_mixer_write(chip, 0x40,
1504 0x43 | (mpu_port & 0xf0) >> 1);
1515 } 1505 }
1516 snd_es18xx_mixer_write(chip, 0x7f, ((irqmask + 1) << 1) | 0x01); 1506 snd_es18xx_mixer_write(chip, 0x7f, ((irqmask + 1) << 1) | 0x01);
1517 } 1507 }
@@ -1629,7 +1619,9 @@ static int __devinit snd_es18xx_identify(struct snd_es18xx *chip)
1629 return 0; 1619 return 0;
1630} 1620}
1631 1621
1632static int __devinit snd_es18xx_probe(struct snd_es18xx *chip) 1622static int __devinit snd_es18xx_probe(struct snd_es18xx *chip,
1623 unsigned long mpu_port,
1624 unsigned long fm_port)
1633{ 1625{
1634 if (snd_es18xx_identify(chip) < 0) { 1626 if (snd_es18xx_identify(chip) < 0) {
1635 snd_printk(KERN_ERR PFX "[0x%lx] ESS chip not found\n", chip->port); 1627 snd_printk(KERN_ERR PFX "[0x%lx] ESS chip not found\n", chip->port);
@@ -1650,8 +1642,6 @@ static int __devinit snd_es18xx_probe(struct snd_es18xx *chip)
1650 chip->caps = ES18XX_PCM2 | ES18XX_SPATIALIZER | ES18XX_RECMIX | ES18XX_NEW_RATE | ES18XX_AUXB | ES18XX_I2S | ES18XX_CONTROL | ES18XX_HWV; 1642 chip->caps = ES18XX_PCM2 | ES18XX_SPATIALIZER | ES18XX_RECMIX | ES18XX_NEW_RATE | ES18XX_AUXB | ES18XX_I2S | ES18XX_CONTROL | ES18XX_HWV;
1651 break; 1643 break;
1652 case 0x1887: 1644 case 0x1887:
1653 chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME;
1654 break;
1655 case 0x1888: 1645 case 0x1888:
1656 chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME; 1646 chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME;
1657 break; 1647 break;
@@ -1666,7 +1656,7 @@ static int __devinit snd_es18xx_probe(struct snd_es18xx *chip)
1666 if (chip->dma1 == chip->dma2) 1656 if (chip->dma1 == chip->dma2)
1667 chip->caps &= ~(ES18XX_PCM2 | ES18XX_DUPLEX_SAME); 1657 chip->caps &= ~(ES18XX_PCM2 | ES18XX_DUPLEX_SAME);
1668 1658
1669 return snd_es18xx_initialize(chip); 1659 return snd_es18xx_initialize(chip, mpu_port, fm_port);
1670} 1660}
1671 1661
1672static struct snd_pcm_ops snd_es18xx_playback_ops = { 1662static struct snd_pcm_ops snd_es18xx_playback_ops = {
@@ -1802,10 +1792,7 @@ static int __devinit snd_es18xx_new_device(struct snd_card *card,
1802 1792
1803 spin_lock_init(&chip->reg_lock); 1793 spin_lock_init(&chip->reg_lock);
1804 spin_lock_init(&chip->mixer_lock); 1794 spin_lock_init(&chip->mixer_lock);
1805 spin_lock_init(&chip->ctrl_lock);
1806 chip->port = port; 1795 chip->port = port;
1807 chip->mpu_port = mpu_port;
1808 chip->fm_port = fm_port;
1809 chip->irq = -1; 1796 chip->irq = -1;
1810 chip->dma1 = -1; 1797 chip->dma1 = -1;
1811 chip->dma2 = -1; 1798 chip->dma2 = -1;
@@ -1841,11 +1828,11 @@ static int __devinit snd_es18xx_new_device(struct snd_card *card,
1841 } 1828 }
1842 chip->dma2 = dma2; 1829 chip->dma2 = dma2;
1843 1830
1844 if (snd_es18xx_probe(chip) < 0) { 1831 if (snd_es18xx_probe(chip, mpu_port, fm_port) < 0) {
1845 snd_es18xx_free(card); 1832 snd_es18xx_free(card);
1846 return -ENODEV; 1833 return -ENODEV;
1847 } 1834 }
1848 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, NULL, &ops); 1835 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
1849 if (err < 0) { 1836 if (err < 0) {
1850 snd_es18xx_free(card); 1837 snd_es18xx_free(card);
1851 return err; 1838 return err;
@@ -1980,7 +1967,7 @@ static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
1980static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 1967static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
1981static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */ 1968static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
1982#ifdef CONFIG_PNP 1969#ifdef CONFIG_PNP
1983static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; 1970static int isapnp[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP;
1984#endif 1971#endif
1985static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260,0x280 */ 1972static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260,0x280 */
1986#ifndef CONFIG_PNP 1973#ifndef CONFIG_PNP
@@ -2160,19 +2147,23 @@ static int __devinit snd_audiodrive_probe(struct snd_card *card, int dev)
2160 return err; 2147 return err;
2161 2148
2162 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) { 2149 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
2163 if (snd_opl3_create(card, chip->fm_port, chip->fm_port + 2, OPL3_HW_OPL3, 0, &opl3) < 0) { 2150 if (snd_opl3_create(card, fm_port[dev], fm_port[dev] + 2,
2164 snd_printk(KERN_WARNING PFX "opl3 not detected at 0x%lx\n", chip->fm_port); 2151 OPL3_HW_OPL3, 0, &opl3) < 0) {
2152 snd_printk(KERN_WARNING PFX
2153 "opl3 not detected at 0x%lx\n",
2154 fm_port[dev]);
2165 } else { 2155 } else {
2166 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) 2156 err = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
2157 if (err < 0)
2167 return err; 2158 return err;
2168 } 2159 }
2169 } 2160 }
2170 2161
2171 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) { 2162 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
2172 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES18XX, 2163 err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES18XX,
2173 chip->mpu_port, 0, 2164 mpu_port[dev], 0,
2174 irq[dev], 0, 2165 irq[dev], 0, &chip->rmidi);
2175 &chip->rmidi)) < 0) 2166 if (err < 0)
2176 return err; 2167 return err;
2177 } 2168 }
2178 2169
diff --git a/sound/isa/opti9xx/miro.c b/sound/isa/opti9xx/miro.c
index 02e30d7c6a93..b865e45a8f9b 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,42 +124,48 @@ 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 "unknown",
141 "82C928", "82C929", 137 "82C928", "82C929",
142 "82C924", "82C925", 138 "82C924", "82C925",
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)
diff --git a/sound/isa/opti9xx/miro.h b/sound/isa/opti9xx/miro.h
deleted file mode 100644
index 6e1385b8e07e..000000000000
--- a/sound/isa/opti9xx/miro.h
+++ /dev/null
@@ -1,73 +0,0 @@
1#ifndef _MIRO_H_
2#define _MIRO_H_
3
4#define ACI_REG_COMMAND 0 /* write register offset */
5#define ACI_REG_STATUS 1 /* read register offset */
6#define ACI_REG_BUSY 2 /* busy register offset */
7#define ACI_REG_RDS 2 /* PCM20: RDS register offset */
8#define ACI_MINTIME 500 /* ACI time out limit */
9
10#define ACI_SET_MUTE 0x0d
11#define ACI_SET_POWERAMP 0x0f
12#define ACI_SET_TUNERMUTE 0xa3
13#define ACI_SET_TUNERMONO 0xa4
14#define ACI_SET_IDE 0xd0
15#define ACI_SET_WSS 0xd1
16#define ACI_SET_SOLOMODE 0xd2
17#define ACI_SET_PREAMP 0x03
18#define ACI_GET_PREAMP 0x21
19#define ACI_WRITE_TUNE 0xa7
20#define ACI_READ_TUNERSTEREO 0xa8
21#define ACI_READ_TUNERSTATION 0xa9
22#define ACI_READ_VERSION 0xf1
23#define ACI_READ_IDCODE 0xf2
24#define ACI_INIT 0xff
25#define ACI_STATUS 0xf0
26#define ACI_S_GENERAL 0x00
27#define ACI_ERROR_OP 0xdf
28
29/* ACI Mixer */
30
31/* These are the values for the right channel GET registers.
32 Add an offset of 0x01 for the left channel register.
33 (left=right+0x01) */
34
35#define ACI_GET_MASTER 0x03
36#define ACI_GET_MIC 0x05
37#define ACI_GET_LINE 0x07
38#define ACI_GET_CD 0x09
39#define ACI_GET_SYNTH 0x0b
40#define ACI_GET_PCM 0x0d
41#define ACI_GET_LINE1 0x10 /* Radio on PCM20 */
42#define ACI_GET_LINE2 0x12
43
44#define ACI_GET_EQ1 0x22 /* from Bass ... */
45#define ACI_GET_EQ2 0x24
46#define ACI_GET_EQ3 0x26
47#define ACI_GET_EQ4 0x28
48#define ACI_GET_EQ5 0x2a
49#define ACI_GET_EQ6 0x2c
50#define ACI_GET_EQ7 0x2e /* ... to Treble */
51
52/* And these are the values for the right channel SET registers.
53 For left channel access you have to add an offset of 0x08.
54 MASTER is an exception, which needs an offset of 0x01 */
55
56#define ACI_SET_MASTER 0x00
57#define ACI_SET_MIC 0x30
58#define ACI_SET_LINE 0x31
59#define ACI_SET_CD 0x34
60#define ACI_SET_SYNTH 0x33
61#define ACI_SET_PCM 0x32
62#define ACI_SET_LINE1 0x35 /* Radio on PCM20 */
63#define ACI_SET_LINE2 0x36
64
65#define ACI_SET_EQ1 0x40 /* from Bass ... */
66#define ACI_SET_EQ2 0x41
67#define ACI_SET_EQ3 0x42
68#define ACI_SET_EQ4 0x43
69#define ACI_SET_EQ5 0x44
70#define ACI_SET_EQ6 0x45
71#define ACI_SET_EQ7 0x46 /* ... to Treble */
72
73#endif /* _MIRO_H_ */
diff --git a/sound/isa/opti9xx/opti92x-ad1848.c b/sound/isa/opti9xx/opti92x-ad1848.c
index 5cd555325b9d..c8a8da0d4036 100644
--- a/sound/isa/opti9xx/opti92x-ad1848.c
+++ b/sound/isa/opti9xx/opti92x-ad1848.c
@@ -135,21 +135,15 @@ struct snd_opti9xx {
135 unsigned long mc_base_size; 135 unsigned long mc_base_size;
136#ifdef OPTi93X 136#ifdef OPTi93X
137 unsigned long mc_indir_index; 137 unsigned long mc_indir_index;
138 unsigned long mc_indir_size;
139 struct resource *res_mc_indir;
138 struct snd_wss *codec; 140 struct snd_wss *codec;
139#endif /* OPTi93X */ 141#endif /* OPTi93X */
140 unsigned long pwd_reg; 142 unsigned long pwd_reg;
141 143
142 spinlock_t lock; 144 spinlock_t lock;
143 145
144 long wss_base;
145 int irq; 146 int irq;
146 int dma1;
147 int dma2;
148
149 long fm_port;
150
151 long mpu_port;
152 int mpu_irq;
153 147
154#ifdef CONFIG_PNP 148#ifdef CONFIG_PNP
155 struct pnp_dev *dev; 149 struct pnp_dev *dev;
@@ -185,7 +179,7 @@ MODULE_DEVICE_TABLE(pnp_card, snd_opti9xx_pnpids);
185#endif 179#endif
186 180
187static char * snd_opti9xx_names[] = { 181static char * snd_opti9xx_names[] = {
188 "unkown", 182 "unknown",
189 "82C928", "82C929", 183 "82C928", "82C929",
190 "82C924", "82C925", 184 "82C924", "82C925",
191 "82C930", "82C931", "82C933" 185 "82C930", "82C931", "82C933"
@@ -216,13 +210,7 @@ static int __devinit snd_opti9xx_init(struct snd_opti9xx *chip,
216 210
217 spin_lock_init(&chip->lock); 211 spin_lock_init(&chip->lock);
218 212
219 chip->wss_base = -1;
220 chip->irq = -1; 213 chip->irq = -1;
221 chip->dma1 = -1;
222 chip->dma2 = -1;
223 chip->fm_port = -1;
224 chip->mpu_port = -1;
225 chip->mpu_irq = -1;
226 214
227 switch (hardware) { 215 switch (hardware) {
228#ifndef OPTi93X 216#ifndef OPTi93X
@@ -245,7 +233,10 @@ static int __devinit snd_opti9xx_init(struct snd_opti9xx *chip,
245 case OPTi9XX_HW_82C931: 233 case OPTi9XX_HW_82C931:
246 case OPTi9XX_HW_82C933: 234 case OPTi9XX_HW_82C933:
247 chip->mc_base = (hardware == OPTi9XX_HW_82C930) ? 0xf8f : 0xf8d; 235 chip->mc_base = (hardware == OPTi9XX_HW_82C930) ? 0xf8f : 0xf8d;
248 chip->mc_indir_index = 0xe0e; 236 if (!chip->mc_indir_index) {
237 chip->mc_indir_index = 0xe0e;
238 chip->mc_indir_size = 2;
239 }
249 chip->password = 0xe4; 240 chip->password = 0xe4;
250 chip->pwd_reg = 0; 241 chip->pwd_reg = 0;
251 break; 242 break;
@@ -348,7 +339,10 @@ static void snd_opti9xx_write(struct snd_opti9xx *chip, unsigned char reg,
348 (snd_opti9xx_read(chip, reg) & ~(mask)) | ((value) & (mask))) 339 (snd_opti9xx_read(chip, reg) & ~(mask)) | ((value) & (mask)))
349 340
350 341
351static int __devinit snd_opti9xx_configure(struct snd_opti9xx *chip) 342static int __devinit snd_opti9xx_configure(struct snd_opti9xx *chip,
343 long wss_base,
344 int irq, int dma1, int dma2,
345 long mpu_port, int mpu_irq)
352{ 346{
353 unsigned char wss_base_bits; 347 unsigned char wss_base_bits;
354 unsigned char irq_bits; 348 unsigned char irq_bits;
@@ -416,7 +410,7 @@ static int __devinit snd_opti9xx_configure(struct snd_opti9xx *chip)
416 return -EINVAL; 410 return -EINVAL;
417 } 411 }
418 412
419 switch (chip->wss_base) { 413 switch (wss_base) {
420 case 0x530: 414 case 0x530:
421 wss_base_bits = 0x00; 415 wss_base_bits = 0x00;
422 break; 416 break;
@@ -430,14 +424,13 @@ static int __devinit snd_opti9xx_configure(struct snd_opti9xx *chip)
430 wss_base_bits = 0x02; 424 wss_base_bits = 0x02;
431 break; 425 break;
432 default: 426 default:
433 snd_printk(KERN_WARNING "WSS port 0x%lx not valid\n", 427 snd_printk(KERN_WARNING "WSS port 0x%lx not valid\n", wss_base);
434 chip->wss_base);
435 goto __skip_base; 428 goto __skip_base;
436 } 429 }
437 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30); 430 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30);
438 431
439__skip_base: 432__skip_base:
440 switch (chip->irq) { 433 switch (irq) {
441//#ifdef OPTi93X 434//#ifdef OPTi93X
442 case 5: 435 case 5:
443 irq_bits = 0x05; 436 irq_bits = 0x05;
@@ -456,11 +449,11 @@ __skip_base:
456 irq_bits = 0x04; 449 irq_bits = 0x04;
457 break; 450 break;
458 default: 451 default:
459 snd_printk(KERN_WARNING "WSS irq # %d not valid\n", chip->irq); 452 snd_printk(KERN_WARNING "WSS irq # %d not valid\n", irq);
460 goto __skip_resources; 453 goto __skip_resources;
461 } 454 }
462 455
463 switch (chip->dma1) { 456 switch (dma1) {
464 case 0: 457 case 0:
465 dma_bits = 0x01; 458 dma_bits = 0x01;
466 break; 459 break;
@@ -471,38 +464,36 @@ __skip_base:
471 dma_bits = 0x03; 464 dma_bits = 0x03;
472 break; 465 break;
473 default: 466 default:
474 snd_printk(KERN_WARNING "WSS dma1 # %d not valid\n", 467 snd_printk(KERN_WARNING "WSS dma1 # %d not valid\n", dma1);
475 chip->dma1);
476 goto __skip_resources; 468 goto __skip_resources;
477 } 469 }
478 470
479#if defined(CS4231) || defined(OPTi93X) 471#if defined(CS4231) || defined(OPTi93X)
480 if (chip->dma1 == chip->dma2) { 472 if (dma1 == dma2) {
481 snd_printk(KERN_ERR "don't want to share dmas\n"); 473 snd_printk(KERN_ERR "don't want to share dmas\n");
482 return -EBUSY; 474 return -EBUSY;
483 } 475 }
484 476
485 switch (chip->dma2) { 477 switch (dma2) {
486 case 0: 478 case 0:
487 case 1: 479 case 1:
488 break; 480 break;
489 default: 481 default:
490 snd_printk(KERN_WARNING "WSS dma2 # %d not valid\n", 482 snd_printk(KERN_WARNING "WSS dma2 # %d not valid\n", dma2);
491 chip->dma2);
492 goto __skip_resources; 483 goto __skip_resources;
493 } 484 }
494 dma_bits |= 0x04; 485 dma_bits |= 0x04;
495#endif /* CS4231 || OPTi93X */ 486#endif /* CS4231 || OPTi93X */
496 487
497#ifndef OPTi93X 488#ifndef OPTi93X
498 outb(irq_bits << 3 | dma_bits, chip->wss_base); 489 outb(irq_bits << 3 | dma_bits, wss_base);
499#else /* OPTi93X */ 490#else /* OPTi93X */
500 snd_opti9xx_write(chip, OPTi9XX_MC_REG(3), (irq_bits << 3 | dma_bits)); 491 snd_opti9xx_write(chip, OPTi9XX_MC_REG(3), (irq_bits << 3 | dma_bits));
501#endif /* OPTi93X */ 492#endif /* OPTi93X */
502 493
503__skip_resources: 494__skip_resources:
504 if (chip->hardware > OPTi9XX_HW_82C928) { 495 if (chip->hardware > OPTi9XX_HW_82C928) {
505 switch (chip->mpu_port) { 496 switch (mpu_port) {
506 case 0: 497 case 0:
507 case -1: 498 case -1:
508 break; 499 break;
@@ -520,12 +511,11 @@ __skip_resources:
520 break; 511 break;
521 default: 512 default:
522 snd_printk(KERN_WARNING 513 snd_printk(KERN_WARNING
523 "MPU-401 port 0x%lx not valid\n", 514 "MPU-401 port 0x%lx not valid\n", mpu_port);
524 chip->mpu_port);
525 goto __skip_mpu; 515 goto __skip_mpu;
526 } 516 }
527 517
528 switch (chip->mpu_irq) { 518 switch (mpu_irq) {
529 case 5: 519 case 5:
530 mpu_irq_bits = 0x02; 520 mpu_irq_bits = 0x02;
531 break; 521 break;
@@ -540,12 +530,12 @@ __skip_resources:
540 break; 530 break;
541 default: 531 default:
542 snd_printk(KERN_WARNING "MPU-401 irq # %d not valid\n", 532 snd_printk(KERN_WARNING "MPU-401 irq # %d not valid\n",
543 chip->mpu_irq); 533 mpu_irq);
544 goto __skip_mpu; 534 goto __skip_mpu;
545 } 535 }
546 536
547 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 537 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6),
548 (chip->mpu_port <= 0) ? 0x00 : 538 (mpu_port <= 0) ? 0x00 :
549 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3, 539 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3,
550 0xf8); 540 0xf8);
551 } 541 }
@@ -558,10 +548,13 @@ __skip_mpu:
558 548
559static irqreturn_t snd_opti93x_interrupt(int irq, void *dev_id) 549static irqreturn_t snd_opti93x_interrupt(int irq, void *dev_id)
560{ 550{
561 struct snd_wss *codec = dev_id; 551 struct snd_opti9xx *chip = dev_id;
562 struct snd_opti9xx *chip = codec->card->private_data; 552 struct snd_wss *codec = chip->codec;
563 unsigned char status; 553 unsigned char status;
564 554
555 if (!codec)
556 return IRQ_HANDLED;
557
565 status = snd_opti9xx_read(chip, OPTi9XX_MC_REG(11)); 558 status = snd_opti9xx_read(chip, OPTi9XX_MC_REG(11));
566 if ((status & OPTi93X_IRQ_PLAYBACK) && codec->playback_substream) 559 if ((status & OPTi93X_IRQ_PLAYBACK) && codec->playback_substream)
567 snd_pcm_period_elapsed(codec->playback_substream); 560 snd_pcm_period_elapsed(codec->playback_substream);
@@ -575,57 +568,69 @@ static irqreturn_t snd_opti93x_interrupt(int irq, void *dev_id)
575 568
576#endif /* OPTi93X */ 569#endif /* OPTi93X */
577 570
578static int __devinit snd_card_opti9xx_detect(struct snd_card *card, 571static int __devinit snd_opti9xx_read_check(struct snd_opti9xx *chip)
579 struct snd_opti9xx *chip)
580{ 572{
581 int i, err; 573 unsigned char value;
574#ifdef OPTi93X
575 unsigned long flags;
576#endif
582 577
578 chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size,
579 "OPTi9xx MC");
580 if (chip->res_mc_base == NULL)
581 return -EBUSY;
583#ifndef OPTi93X 582#ifndef OPTi93X
584 for (i = OPTi9XX_HW_82C928; i < OPTi9XX_HW_82C930; i++) { 583 value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(1));
585 unsigned char value; 584 if (value != 0xff && value != inb(chip->mc_base + OPTi9XX_MC_REG(1)))
585 if (value == snd_opti9xx_read(chip, OPTi9XX_MC_REG(1)))
586 return 0;
587#else /* OPTi93X */
588 chip->res_mc_indir = request_region(chip->mc_indir_index,
589 chip->mc_indir_size,
590 "OPTi93x MC");
591 if (chip->res_mc_indir == NULL)
592 return -EBUSY;
586 593
587 if ((err = snd_opti9xx_init(chip, i)) < 0) 594 spin_lock_irqsave(&chip->lock, flags);
588 return err; 595 outb(chip->password, chip->mc_base + chip->pwd_reg);
596 outb(((chip->mc_indir_index & 0x1f0) >> 4), chip->mc_base);
597 spin_unlock_irqrestore(&chip->lock, flags);
589 598
590 if ((chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL) 599 value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(7));
591 continue; 600 snd_opti9xx_write(chip, OPTi9XX_MC_REG(7), 0xff - value);
601 if (snd_opti9xx_read(chip, OPTi9XX_MC_REG(7)) == 0xff - value)
602 return 0;
592 603
593 value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(1)); 604 release_and_free_resource(chip->res_mc_indir);
594 if ((value != 0xff) && (value != inb(chip->mc_base + 1))) 605 chip->res_mc_indir = NULL;
595 if (value == snd_opti9xx_read(chip, OPTi9XX_MC_REG(1))) 606#endif /* OPTi93X */
596 return 1; 607 release_and_free_resource(chip->res_mc_base);
608 chip->res_mc_base = NULL;
597 609
598 release_and_free_resource(chip->res_mc_base); 610 return -ENODEV;
599 chip->res_mc_base = NULL; 611}
600 612
601 } 613static int __devinit snd_card_opti9xx_detect(struct snd_card *card,
602#else /* OPTi93X */ 614 struct snd_opti9xx *chip)
603 for (i = OPTi9XX_HW_82C931; i >= OPTi9XX_HW_82C930; i--) { 615{
604 unsigned long flags; 616 int i, err;
605 unsigned char value;
606 617
607 if ((err = snd_opti9xx_init(chip, i)) < 0) 618#ifndef OPTi93X
619 for (i = OPTi9XX_HW_82C928; i < OPTi9XX_HW_82C930; i++) {
620#else
621 for (i = OPTi9XX_HW_82C931; i >= OPTi9XX_HW_82C930; i--) {
622#endif
623 err = snd_opti9xx_init(chip, i);
624 if (err < 0)
608 return err; 625 return err;
609 626
610 if ((chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL) 627 err = snd_opti9xx_read_check(chip);
611 continue; 628 if (err == 0)
612
613 spin_lock_irqsave(&chip->lock, flags);
614 outb(chip->password, chip->mc_base + chip->pwd_reg);
615 outb(((chip->mc_indir_index & (1 << 8)) >> 4) |
616 ((chip->mc_indir_index & 0xf0) >> 4), chip->mc_base);
617 spin_unlock_irqrestore(&chip->lock, flags);
618
619 value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(7));
620 snd_opti9xx_write(chip, OPTi9XX_MC_REG(7), 0xff - value);
621 if (snd_opti9xx_read(chip, OPTi9XX_MC_REG(7)) == 0xff - value)
622 return 1; 629 return 1;
623 630#ifdef OPTi93X
624 release_and_free_resource(chip->res_mc_base); 631 chip->mc_indir_index = 0;
625 chip->res_mc_base = NULL; 632#endif
626 } 633 }
627#endif /* OPTi93X */
628
629 return -ENODEV; 634 return -ENODEV;
630} 635}
631 636
@@ -654,6 +659,8 @@ static int __devinit snd_card_opti9xx_pnp(struct snd_opti9xx *chip,
654#ifdef OPTi93X 659#ifdef OPTi93X
655 port = pnp_port_start(pdev, 0) - 4; 660 port = pnp_port_start(pdev, 0) - 4;
656 fm_port = pnp_port_start(pdev, 1) + 8; 661 fm_port = pnp_port_start(pdev, 1) + 8;
662 chip->mc_indir_index = pnp_port_start(pdev, 3) + 2;
663 chip->mc_indir_size = pnp_port_len(pdev, 3) - 2;
657#else 664#else
658 if (pid->driver_data != 0x0924) 665 if (pid->driver_data != 0x0924)
659 port = pnp_port_start(pdev, 1); 666 port = pnp_port_start(pdev, 1);
@@ -684,14 +691,14 @@ static int __devinit snd_card_opti9xx_pnp(struct snd_opti9xx *chip,
684static void snd_card_opti9xx_free(struct snd_card *card) 691static void snd_card_opti9xx_free(struct snd_card *card)
685{ 692{
686 struct snd_opti9xx *chip = card->private_data; 693 struct snd_opti9xx *chip = card->private_data;
687 694
688 if (chip) { 695 if (chip) {
689#ifdef OPTi93X 696#ifdef OPTi93X
690 struct snd_wss *codec = chip->codec; 697 if (chip->irq > 0) {
691 if (codec && codec->irq > 0) { 698 disable_irq(chip->irq);
692 disable_irq(codec->irq); 699 free_irq(chip->irq, chip);
693 free_irq(codec->irq, codec);
694 } 700 }
701 release_and_free_resource(chip->res_mc_indir);
695#endif 702#endif
696 release_and_free_resource(chip->res_mc_base); 703 release_and_free_resource(chip->res_mc_base);
697 } 704 }
@@ -701,6 +708,7 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
701{ 708{
702 static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1}; 709 static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
703 int error; 710 int error;
711 int xdma2;
704 struct snd_opti9xx *chip = card->private_data; 712 struct snd_opti9xx *chip = card->private_data;
705 struct snd_wss *codec; 713 struct snd_wss *codec;
706#ifdef CS4231 714#ifdef CS4231
@@ -710,36 +718,25 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
710 struct snd_rawmidi *rmidi; 718 struct snd_rawmidi *rmidi;
711 struct snd_hwdep *synth; 719 struct snd_hwdep *synth;
712 720
713 if (! chip->res_mc_base &&
714 (chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size,
715 "OPTi9xx MC")) == NULL)
716 return -ENOMEM;
717
718 chip->wss_base = port;
719 chip->fm_port = fm_port;
720 chip->mpu_port = mpu_port;
721 chip->irq = irq;
722 chip->mpu_irq = mpu_irq;
723 chip->dma1 = dma1;
724#if defined(CS4231) || defined(OPTi93X) 721#if defined(CS4231) || defined(OPTi93X)
725 chip->dma2 = dma2; 722 xdma2 = dma2;
726#else 723#else
727 chip->dma2 = -1; 724 xdma2 = -1;
728#endif 725#endif
729 726
730 if (chip->wss_base == SNDRV_AUTO_PORT) { 727 if (port == SNDRV_AUTO_PORT) {
731 chip->wss_base = snd_legacy_find_free_ioport(possible_ports, 4); 728 port = snd_legacy_find_free_ioport(possible_ports, 4);
732 if (chip->wss_base < 0) { 729 if (port < 0) {
733 snd_printk(KERN_ERR "unable to find a free WSS port\n"); 730 snd_printk(KERN_ERR "unable to find a free WSS port\n");
734 return -EBUSY; 731 return -EBUSY;
735 } 732 }
736 } 733 }
737 error = snd_opti9xx_configure(chip); 734 error = snd_opti9xx_configure(chip, port, irq, dma1, xdma2,
735 mpu_port, mpu_irq);
738 if (error) 736 if (error)
739 return error; 737 return error;
740 738
741 error = snd_wss_create(card, chip->wss_base + 4, -1, 739 error = snd_wss_create(card, port + 4, -1, irq, dma1, xdma2,
742 chip->irq, chip->dma1, chip->dma2,
743#ifdef OPTi93X 740#ifdef OPTi93X
744 WSS_HW_OPTI93X, WSS_HWSHARE_IRQ, 741 WSS_HW_OPTI93X, WSS_HWSHARE_IRQ,
745#else 742#else
@@ -763,35 +760,35 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
763 return error; 760 return error;
764#endif 761#endif
765#ifdef OPTi93X 762#ifdef OPTi93X
766 error = request_irq(chip->irq, snd_opti93x_interrupt, 763 error = request_irq(irq, snd_opti93x_interrupt,
767 IRQF_DISABLED, DEV_NAME" - WSS", codec); 764 IRQF_DISABLED, DEV_NAME" - WSS", chip);
768 if (error < 0) { 765 if (error < 0) {
769 snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", chip->irq); 766 snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", irq);
770 return error; 767 return error;
771 } 768 }
772#endif 769#endif
770 chip->irq = irq;
773 strcpy(card->driver, chip->name); 771 strcpy(card->driver, chip->name);
774 sprintf(card->shortname, "OPTi %s", card->driver); 772 sprintf(card->shortname, "OPTi %s", card->driver);
775#if defined(CS4231) || defined(OPTi93X) 773#if defined(CS4231) || defined(OPTi93X)
776 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d", 774 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d",
777 card->shortname, pcm->name, chip->wss_base + 4, 775 card->shortname, pcm->name, port + 4, irq, dma1, xdma2);
778 chip->irq, chip->dma1, chip->dma2);
779#else 776#else
780 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d", 777 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d",
781 card->shortname, pcm->name, chip->wss_base + 4, 778 card->shortname, pcm->name, port + 4, irq, dma1);
782 chip->irq, chip->dma1);
783#endif /* CS4231 || OPTi93X */ 779#endif /* CS4231 || OPTi93X */
784 780
785 if (chip->mpu_port <= 0 || chip->mpu_port == SNDRV_AUTO_PORT) 781 if (mpu_port <= 0 || mpu_port == SNDRV_AUTO_PORT)
786 rmidi = NULL; 782 rmidi = NULL;
787 else 783 else {
788 if ((error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, 784 error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
789 chip->mpu_port, 0, chip->mpu_irq, IRQF_DISABLED, 785 mpu_port, 0, mpu_irq, IRQF_DISABLED, &rmidi);
790 &rmidi))) 786 if (error)
791 snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n", 787 snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n",
792 chip->mpu_port); 788 mpu_port);
789 }
793 790
794 if (chip->fm_port > 0 && chip->fm_port != SNDRV_AUTO_PORT) { 791 if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT) {
795 struct snd_opl3 *opl3 = NULL; 792 struct snd_opl3 *opl3 = NULL;
796#ifndef OPTi93X 793#ifndef OPTi93X
797 if (chip->hardware == OPTi9XX_HW_82C928 || 794 if (chip->hardware == OPTi9XX_HW_82C928 ||
@@ -801,9 +798,7 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
801 /* assume we have an OPL4 */ 798 /* assume we have an OPL4 */
802 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 799 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
803 0x20, 0x20); 800 0x20, 0x20);
804 if (snd_opl4_create(card, 801 if (snd_opl4_create(card, fm_port, fm_port - 8,
805 chip->fm_port,
806 chip->fm_port - 8,
807 2, &opl3, &opl4) < 0) { 802 2, &opl3, &opl4) < 0) {
808 /* no luck, use OPL3 instead */ 803 /* no luck, use OPL3 instead */
809 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 804 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
@@ -811,12 +806,10 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
811 } 806 }
812 } 807 }
813#endif /* !OPTi93X */ 808#endif /* !OPTi93X */
814 if (!opl3 && snd_opl3_create(card, 809 if (!opl3 && snd_opl3_create(card, fm_port, fm_port + 2,
815 chip->fm_port,
816 chip->fm_port + 2,
817 OPL3_HW_AUTO, 0, &opl3) < 0) { 810 OPL3_HW_AUTO, 0, &opl3) < 0) {
818 snd_printk(KERN_WARNING "no OPL device at 0x%lx-0x%lx\n", 811 snd_printk(KERN_WARNING "no OPL device at 0x%lx-0x%lx\n",
819 chip->fm_port, chip->fm_port + 4 - 1); 812 fm_port, fm_port + 4 - 1);
820 } 813 }
821 if (opl3) { 814 if (opl3) {
822 error = snd_opl3_hwdep_new(opl3, 0, 1, &synth); 815 error = snd_opl3_hwdep_new(opl3, 0, 1, &synth);
@@ -978,6 +971,13 @@ static int __devinit snd_opti9xx_pnp_probe(struct pnp_card_link *pcard,
978 } 971 }
979 if (hw <= OPTi9XX_HW_82C930) 972 if (hw <= OPTi9XX_HW_82C930)
980 chip->mc_base -= 0x80; 973 chip->mc_base -= 0x80;
974
975 error = snd_opti9xx_read_check(chip);
976 if (error) {
977 snd_printk(KERN_ERR "OPTI chip not found\n");
978 snd_card_free(card);
979 return error;
980 }
981 snd_card_set_dev(card, &pcard->card->dev); 981 snd_card_set_dev(card, &pcard->card->dev);
982 if ((error = snd_opti9xx_probe(card)) < 0) { 982 if ((error = snd_opti9xx_probe(card)) < 0) {
983 snd_card_free(card); 983 snd_card_free(card);
diff --git a/sound/isa/wss/wss_lib.c b/sound/isa/wss/wss_lib.c
index 2ba18978b419..5b9d6c18bc45 100644
--- a/sound/isa/wss/wss_lib.c
+++ b/sound/isa/wss/wss_lib.c
@@ -1682,7 +1682,7 @@ static void snd_wss_resume(struct snd_wss *chip)
1682} 1682}
1683#endif /* CONFIG_PM */ 1683#endif /* CONFIG_PM */
1684 1684
1685int snd_wss_free(struct snd_wss *chip) 1685static int snd_wss_free(struct snd_wss *chip)
1686{ 1686{
1687 release_and_free_resource(chip->res_port); 1687 release_and_free_resource(chip->res_port);
1688 release_and_free_resource(chip->res_cport); 1688 release_and_free_resource(chip->res_cport);
@@ -1705,7 +1705,6 @@ int snd_wss_free(struct snd_wss *chip)
1705 kfree(chip); 1705 kfree(chip);
1706 return 0; 1706 return 0;
1707} 1707}
1708EXPORT_SYMBOL(snd_wss_free);
1709 1708
1710static int snd_wss_dev_free(struct snd_device *device) 1709static int snd_wss_dev_free(struct snd_device *device)
1711{ 1710{
@@ -2225,7 +2224,7 @@ WSS_DOUBLE_TLV("Capture Volume", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT,
2225 .get = snd_wss_get_mux, 2224 .get = snd_wss_get_mux,
2226 .put = snd_wss_put_mux, 2225 .put = snd_wss_put_mux,
2227}, 2226},
2228WSS_DOUBLE("Mic Boost", 0, 2227WSS_DOUBLE("Mic Boost (+20dB)", 0,
2229 CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 5, 5, 1, 0), 2228 CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 5, 5, 1, 0),
2230WSS_SINGLE("Loopback Capture Switch", 0, 2229WSS_SINGLE("Loopback Capture Switch", 0,
2231 CS4231_LOOPBACK, 0, 1, 0), 2230 CS4231_LOOPBACK, 0, 1, 0),
@@ -2236,14 +2235,14 @@ WSS_DOUBLE("Line Playback Switch", 0,
2236WSS_DOUBLE_TLV("Line Playback Volume", 0, 2235WSS_DOUBLE_TLV("Line Playback Volume", 0,
2237 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1, 2236 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1,
2238 db_scale_5bit_12db_max), 2237 db_scale_5bit_12db_max),
2239WSS_SINGLE("Mono Playback Switch", 0, 2238WSS_SINGLE("Beep Playback Switch", 0,
2240 CS4231_MONO_CTRL, 7, 1, 1), 2239 CS4231_MONO_CTRL, 7, 1, 1),
2241WSS_SINGLE_TLV("Mono Playback Volume", 0, 2240WSS_SINGLE_TLV("Beep Playback Volume", 0,
2242 CS4231_MONO_CTRL, 0, 15, 1, 2241 CS4231_MONO_CTRL, 0, 15, 1,
2243 db_scale_4bit), 2242 db_scale_4bit),
2244WSS_SINGLE("Mono Output Playback Switch", 0, 2243WSS_SINGLE("Mono Output Playback Switch", 0,
2245 CS4231_MONO_CTRL, 6, 1, 1), 2244 CS4231_MONO_CTRL, 6, 1, 1),
2246WSS_SINGLE("Mono Output Playback Bypass", 0, 2245WSS_SINGLE("Beep Bypass Playback Switch", 0,
2247 CS4231_MONO_CTRL, 5, 1, 0), 2246 CS4231_MONO_CTRL, 5, 1, 0),
2248}; 2247};
2249 2248