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