ALSA: opti92x: use PnP data to select Master Control port

The Master Control port (MC) is available as the last
PnP resource (OPT005). Use this value instead fo guessing.

Also, add some comments to the code.

Signed-off-by: Krzysztof Helt <krzysztof.h1@wp.pl>
Signed-off-by: Takashi Iwai <tiwai@suse.de>

authored by Krzysztof Helt and committed by Takashi Iwai fd8d4735 864c1108

+79 -43
+1 -1
sound/isa/opti9xx/miro.c
··· 1558 1558 1559 1559 err = pnp_activate_dev(devmc); 1560 1560 if (err < 0) { 1561 - snd_printk(KERN_ERR "OPL syntg pnp configure failure: %d\n", 1561 + snd_printk(KERN_ERR "MC pnp configure failure: %d\n", 1562 1562 err); 1563 1563 return err; 1564 1564 }
+78 -42
sound/isa/opti9xx/opti92x-ad1848.c
··· 144 144 145 145 spinlock_t lock; 146 146 147 + long wss_base; 147 148 int irq; 148 - 149 - #ifdef CONFIG_PNP 150 - struct pnp_dev *dev; 151 - struct pnp_dev *devmpu; 152 - #endif /* CONFIG_PNP */ 153 149 }; 154 150 155 151 static int snd_opti9xx_pnp_is_probed; ··· 155 159 static struct pnp_card_device_id snd_opti9xx_pnpids[] = { 156 160 #ifndef OPTi93X 157 161 /* OPTi 82C924 */ 158 - { .id = "OPT0924", .devs = { { "OPT0000" }, { "OPT0002" } }, .driver_data = 0x0924 }, 162 + { .id = "OPT0924", 163 + .devs = { { "OPT0000" }, { "OPT0002" }, { "OPT0005" } }, 164 + .driver_data = 0x0924 }, 159 165 /* OPTi 82C925 */ 160 - { .id = "OPT0925", .devs = { { "OPT9250" }, { "OPT0002" } }, .driver_data = 0x0925 }, 166 + { .id = "OPT0925", 167 + .devs = { { "OPT9250" }, { "OPT0002" }, { "OPT0005" } }, 168 + .driver_data = 0x0925 }, 161 169 #else 162 170 /* OPTi 82C931/3 */ 163 - { .id = "OPT0931", .devs = { { "OPT9310" }, { "OPT0002" } }, .driver_data = 0x0931 }, 171 + { .id = "OPT0931", .devs = { { "OPT9310" }, { "OPT0002" } }, 172 + .driver_data = 0x0931 }, 164 173 #endif /* OPTi93X */ 165 174 { .id = "" } 166 175 }; ··· 208 207 chip->hardware = hardware; 209 208 strcpy(chip->name, snd_opti9xx_names[hardware]); 210 209 211 - chip->mc_base_size = opti9xx_mc_size[hardware]; 212 - 213 210 spin_lock_init(&chip->lock); 214 211 215 212 chip->irq = -1; 213 + 214 + #ifndef OPTi93X 215 + #ifdef CONFIG_PNP 216 + if (isapnp && chip->mc_base) 217 + /* PnP resource gives the least 10 bits */ 218 + chip->mc_base |= 0xc00; 219 + #endif /* CONFIG_PNP */ 220 + else { 221 + chip->mc_base = 0xf8c; 222 + chip->mc_base_size = opti9xx_mc_size[hardware]; 223 + } 224 + #else 225 + chip->mc_base_size = opti9xx_mc_size[hardware]; 226 + #endif 216 227 217 228 switch (hardware) { 218 229 #ifndef OPTi93X 219 230 case OPTi9XX_HW_82C928: 220 231 case OPTi9XX_HW_82C929: 221 - chip->mc_base = 0xf8c; 222 232 chip->password = (hardware == OPTi9XX_HW_82C928) ? 0xe2 : 0xe3; 223 233 chip->pwd_reg = 3; 224 234 break; 225 235 226 236 case OPTi9XX_HW_82C924: 227 237 case OPTi9XX_HW_82C925: 228 - chip->mc_base = 0xf8c; 229 238 chip->password = 0xe5; 230 239 chip->pwd_reg = 3; 231 240 break; ··· 303 292 spin_unlock_irqrestore(&chip->lock, flags); 304 293 return retval; 305 294 } 306 - 295 + 307 296 static void snd_opti9xx_write(struct snd_opti9xx *chip, unsigned char reg, 308 297 unsigned char value) 309 298 { ··· 352 341 353 342 354 343 static int __devinit snd_opti9xx_configure(struct snd_opti9xx *chip, 355 - long wss_base, 344 + long port, 356 345 int irq, int dma1, int dma2, 357 346 long mpu_port, int mpu_irq) 358 347 { ··· 365 354 switch (chip->hardware) { 366 355 #ifndef OPTi93X 367 356 case OPTi9XX_HW_82C924: 357 + /* opti 929 mode (?), OPL3 clock output, audio enable */ 368 358 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0xf0, 0xfc); 359 + /* enable wave audio */ 369 360 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02); 370 361 371 362 case OPTi9XX_HW_82C925: 363 + /* enable WSS mode */ 372 364 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80); 365 + /* OPL3 FM synthesis */ 373 366 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20); 367 + /* disable Sound Blaster IRQ and DMA */ 374 368 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff); 375 369 #ifdef CS4231 370 + /* cs4231/4248 fix enabled */ 376 371 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02); 377 372 #else 373 + /* cs4231/4248 fix disabled */ 378 374 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02); 379 375 #endif /* CS4231 */ 380 376 break; ··· 429 411 return -EINVAL; 430 412 } 431 413 432 - switch (wss_base) { 433 - case 0x530: 414 + /* PnP resource says it decodes only 10 bits of address */ 415 + switch (port & 0x3ff) { 416 + case 0x130: 417 + chip->wss_base = 0x530; 434 418 wss_base_bits = 0x00; 435 419 break; 436 - case 0x604: 420 + case 0x204: 421 + chip->wss_base = 0x604; 437 422 wss_base_bits = 0x03; 438 423 break; 439 - case 0xe80: 424 + case 0x280: 425 + chip->wss_base = 0xe80; 440 426 wss_base_bits = 0x01; 441 427 break; 442 - case 0xf40: 428 + case 0x340: 429 + chip->wss_base = 0xf40; 443 430 wss_base_bits = 0x02; 444 431 break; 445 432 default: 446 - snd_printk(KERN_WARNING "WSS port 0x%lx not valid\n", wss_base); 433 + snd_printk(KERN_WARNING "WSS port 0x%lx not valid\n", port); 447 434 goto __skip_base; 448 435 } 449 436 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30); ··· 510 487 #endif /* CS4231 || OPTi93X */ 511 488 512 489 #ifndef OPTi93X 513 - outb(irq_bits << 3 | dma_bits, wss_base); 490 + outb(irq_bits << 3 | dma_bits, chip->wss_base); 514 491 #else /* OPTi93X */ 515 492 snd_opti9xx_write(chip, OPTi9XX_MC_REG(3), (irq_bits << 3 | dma_bits)); 516 493 #endif /* OPTi93X */ ··· 752 729 { 753 730 struct pnp_dev *pdev; 754 731 int err; 732 + struct pnp_dev *devmpu; 733 + #ifndef OPTi93X 734 + struct pnp_dev *devmc; 735 + #endif 755 736 756 - chip->dev = pnp_request_card_device(card, pid->devs[0].id, NULL); 757 - if (chip->dev == NULL) 737 + pdev = pnp_request_card_device(card, pid->devs[0].id, NULL); 738 + if (pdev == NULL) 758 739 return -EBUSY; 759 - 760 - chip->devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL); 761 - 762 - pdev = chip->dev; 763 740 764 741 err = pnp_activate_dev(pdev); 765 742 if (err < 0) { ··· 773 750 chip->mc_indir_index = pnp_port_start(pdev, 3) + 2; 774 751 chip->mc_indir_size = pnp_port_len(pdev, 3) - 2; 775 752 #else 776 - if (pid->driver_data != 0x0924) 777 - port = pnp_port_start(pdev, 1); 753 + devmc = pnp_request_card_device(card, pid->devs[2].id, NULL); 754 + if (devmc == NULL) 755 + return -EBUSY; 756 + 757 + err = pnp_activate_dev(devmc); 758 + if (err < 0) { 759 + snd_printk(KERN_ERR "MC pnp configure failure: %d\n", err); 760 + return err; 761 + } 762 + 763 + port = pnp_port_start(pdev, 1); 778 764 fm_port = pnp_port_start(pdev, 2) + 8; 765 + /* 766 + * The MC(0) is never accessed and card does not 767 + * include it in the PnP resource range. OPTI93x include it. 768 + */ 769 + chip->mc_base = pnp_port_start(devmc, 0) - 1; 770 + chip->mc_base_size = pnp_port_len(devmc, 0) + 1; 779 771 #endif /* OPTi93X */ 780 772 irq = pnp_irq(pdev, 0); 781 773 dma1 = pnp_dma(pdev, 0); ··· 798 760 dma2 = pnp_dma(pdev, 1); 799 761 #endif /* CS4231 || OPTi93X */ 800 762 801 - pdev = chip->devmpu; 802 - if (pdev && mpu_port > 0) { 803 - err = pnp_activate_dev(pdev); 763 + devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL); 764 + 765 + if (devmpu && mpu_port > 0) { 766 + err = pnp_activate_dev(devmpu); 804 767 if (err < 0) { 805 - snd_printk(KERN_ERR "AUDIO pnp configure failure\n"); 768 + snd_printk(KERN_ERR "MPU401 pnp configure failure\n"); 806 769 mpu_port = -1; 807 - chip->devmpu = NULL; 808 770 } else { 809 - mpu_port = pnp_port_start(pdev, 0); 810 - mpu_irq = pnp_irq(pdev, 0); 771 + mpu_port = pnp_port_start(devmpu, 0); 772 + mpu_irq = pnp_irq(devmpu, 0); 811 773 } 812 774 } 813 775 return pid->driver_data; ··· 862 824 if (error) 863 825 return error; 864 826 865 - error = snd_wss_create(card, port + 4, -1, irq, dma1, xdma2, 827 + error = snd_wss_create(card, chip->wss_base + 4, -1, irq, dma1, xdma2, 866 828 #ifdef OPTi93X 867 829 WSS_HW_OPTI93X, WSS_HWSHARE_IRQ, 868 830 #else ··· 903 865 sprintf(card->shortname, "OPTi %s", card->driver); 904 866 #if defined(CS4231) || defined(OPTi93X) 905 867 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d", 906 - card->shortname, pcm->name, port + 4, irq, dma1, xdma2); 868 + card->shortname, pcm->name, 869 + chip->wss_base + 4, irq, dma1, xdma2); 907 870 #else 908 871 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d", 909 - card->shortname, pcm->name, port + 4, irq, dma1); 872 + card->shortname, pcm->name, chip->wss_base + 4, irq, dma1); 910 873 #endif /* CS4231 || OPTi93X */ 911 874 912 875 if (mpu_port <= 0 || mpu_port == SNDRV_AUTO_PORT) ··· 1101 1062 snd_card_free(card); 1102 1063 return error; 1103 1064 } 1104 - if (hw <= OPTi9XX_HW_82C930) 1105 - chip->mc_base -= 0x80; 1106 - 1107 1065 error = snd_opti9xx_read_check(chip); 1108 1066 if (error) { 1109 1067 snd_printk(KERN_ERR "OPTI chip not found\n");