📄 opti92x-ad1848.c
字号:
int err; unsigned int idx; snd_assert(chip != NULL && chip->card != NULL, return -EINVAL); card = chip->card; strcpy(card->mixername, snd_opti93x_chip_id(chip)); for (idx = 0; idx < ARRAY_SIZE(snd_opti93x_controls); idx++) { knew = snd_opti93x_controls[idx]; if (chip->hardware == OPTi9XX_HW_82C930) { if (strstr(knew.name, "FM")) /* skip FM controls */ continue; else if (strcmp(knew.name, "Mic Playback Volume")) OPTi93X_DOUBLE_INVERT_INVERT(knew); else if (strstr(knew.name, "Aux")) OPTi93X_DOUBLE_CHANGE_REGS(knew, OPTi930_AUX_LEFT_INPUT, OPTi930_AUX_RIGHT_INPUT); else if (strcmp(knew.name, "PCM Playback Volume")) OPTi93X_DOUBLE_INVERT_INVERT(knew); else if (strcmp(knew.name, "Master Playback Volume")) OPTi93X_DOUBLE_INVERT_INVERT(knew); } if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_opti93x_controls[idx], chip))) < 0) return err; } return 0;}#endif /* OPTi93X */static int __init snd_card_opti9xx_detect(struct snd_card *card, struct snd_opti9xx *chip){ int i, err;#ifndef OPTi93X for (i = OPTi9XX_HW_82C928; i < OPTi9XX_HW_82C930; i++) { unsigned char value; if ((err = snd_opti9xx_init(chip, i)) < 0) return err; if ((chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL) continue; value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(1)); if ((value != 0xff) && (value != inb(chip->mc_base + 1))) if (value == snd_opti9xx_read(chip, OPTi9XX_MC_REG(1))) return 1; release_and_free_resource(chip->res_mc_base); chip->res_mc_base = NULL; }#else /* OPTi93X */ for (i = OPTi9XX_HW_82C931; i >= OPTi9XX_HW_82C930; i--) { unsigned long flags; unsigned char value; if ((err = snd_opti9xx_init(chip, i)) < 0) return err; if ((chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL) continue; spin_lock_irqsave(&chip->lock, flags); outb(chip->password, chip->mc_base + chip->pwd_reg); outb(((chip->mc_indir_index & (1 << 8)) >> 4) | ((chip->mc_indir_index & 0xf0) >> 4), chip->mc_base); spin_unlock_irqrestore(&chip->lock, flags); value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(7)); snd_opti9xx_write(chip, OPTi9XX_MC_REG(7), 0xff - value); if (snd_opti9xx_read(chip, OPTi9XX_MC_REG(7)) == 0xff - value) return 1; release_and_free_resource(chip->res_mc_base); chip->res_mc_base = NULL; }#endif /* OPTi93X */ return -ENODEV;}#ifdef CONFIG_PNPstatic int __init snd_card_opti9xx_pnp(struct snd_opti9xx *chip, struct pnp_card_link *card, const struct pnp_card_device_id *pid){ struct pnp_dev *pdev; struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL); int err; chip->dev = pnp_request_card_device(card, pid->devs[0].id, NULL); if (chip->dev == NULL) { kfree(cfg); return -EBUSY; } chip->devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL); pdev = chip->dev; pnp_init_resource_table(cfg);#ifdef OPTi93X if (port != SNDRV_AUTO_PORT) pnp_resource_change(&cfg->port_resource[0], port + 4, 4);#else if (pid->driver_data != 0x0924 && port != SNDRV_AUTO_PORT) pnp_resource_change(&cfg->port_resource[1], port, 4);#endif /* OPTi93X */ if (irq != SNDRV_AUTO_IRQ) pnp_resource_change(&cfg->irq_resource[0], irq, 1); if (dma1 != SNDRV_AUTO_DMA) pnp_resource_change(&cfg->dma_resource[0], dma1, 1);#if defined(CS4231) || defined(OPTi93X) if (dma2 != SNDRV_AUTO_DMA) pnp_resource_change(&cfg->dma_resource[1], dma2, 1);#else#ifdef snd_opti9xx_fixup_dma2 snd_opti9xx_fixup_dma2(pdev);#endif#endif /* CS4231 || OPTi93X */#ifdef OPTi93X if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT) pnp_resource_change(&cfg->port_resource[1], fm_port, 4);#else if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT) pnp_resource_change(&cfg->port_resource[2], fm_port, 4);#endif if (pnp_manual_config_dev(pdev, cfg, 0) < 0) snd_printk(KERN_ERR "AUDIO the requested resources are invalid, using auto config\n"); err = pnp_activate_dev(pdev); if (err < 0) { snd_printk(KERN_ERR "AUDIO pnp configure failure: %d\n", err); kfree(cfg); return err; }#ifdef OPTi93X port = pnp_port_start(pdev, 0) - 4; fm_port = pnp_port_start(pdev, 1);#else if (pid->driver_data != 0x0924) port = pnp_port_start(pdev, 1); fm_port = pnp_port_start(pdev, 2);#endif /* OPTi93X */ irq = pnp_irq(pdev, 0); dma1 = pnp_dma(pdev, 0);#if defined(CS4231) || defined(OPTi93X) dma2 = pnp_dma(pdev, 1);#endif /* CS4231 || OPTi93X */ pdev = chip->devmpu; if (pdev && mpu_port > 0) { pnp_init_resource_table(cfg); if (mpu_port != SNDRV_AUTO_PORT) pnp_resource_change(&cfg->port_resource[0], mpu_port, 2); if (mpu_irq != SNDRV_AUTO_IRQ) pnp_resource_change(&cfg->irq_resource[0], mpu_irq, 1); if (pnp_manual_config_dev(pdev, cfg, 0) < 0) snd_printk(KERN_ERR "AUDIO the requested resources are invalid, using auto config\n"); err = pnp_activate_dev(pdev); if (err < 0) { snd_printk(KERN_ERR "AUDIO pnp configure failure\n"); mpu_port = -1; chip->devmpu = NULL; } else { mpu_port = pnp_port_start(pdev, 0); mpu_irq = pnp_irq(pdev, 0); } } kfree(cfg); return pid->driver_data;}#endif /* CONFIG_PNP */static void snd_card_opti9xx_free(struct snd_card *card){ struct snd_opti9xx *chip = card->private_data; if (chip) release_and_free_resource(chip->res_mc_base);}static int __init snd_opti9xx_probe(struct snd_card *card){ static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1}; int error; struct snd_opti9xx *chip = card->private_data;#if defined(OPTi93X) struct snd_opti93x *codec;#elif defined(CS4231) struct snd_cs4231 *codec; struct snd_timer *timer;#else struct snd_ad1848 *codec;#endif struct snd_pcm *pcm; struct snd_rawmidi *rmidi; struct snd_hwdep *synth; if (! chip->res_mc_base && (chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL) return -ENOMEM; chip->wss_base = port; chip->fm_port = fm_port; chip->mpu_port = mpu_port; chip->irq = irq; chip->mpu_irq = mpu_irq; chip->dma1 = dma1;#if defined(CS4231) || defined(OPTi93X) chip->dma2 = dma2;#endif if (chip->wss_base == SNDRV_AUTO_PORT) { if ((chip->wss_base = snd_legacy_find_free_ioport(possible_ports, 4)) < 0) { snd_printk("unable to find a free WSS port\n"); return -EBUSY; } } if ((error = snd_opti9xx_configure(chip))) return error;#if defined(OPTi93X) if ((error = snd_opti93x_create(card, chip, chip->dma1, chip->dma2, &codec))) return error; if ((error = snd_opti93x_pcm(codec, 0, &pcm)) < 0) return error; if ((error = snd_opti93x_mixer(codec)) < 0) return error;#elif defined(CS4231) if ((error = snd_cs4231_create(card, chip->wss_base + 4, -1, chip->irq, chip->dma1, chip->dma2, CS4231_HW_DETECT, 0, &codec)) < 0) return error; if ((error = snd_cs4231_pcm(codec, 0, &pcm)) < 0) return error; if ((error = snd_cs4231_mixer(codec)) < 0) return error; if ((error = snd_cs4231_timer(codec, 0, &timer)) < 0) return error;#else if ((error = snd_ad1848_create(card, chip->wss_base + 4, chip->irq, chip->dma1, AD1848_HW_DETECT, &codec)) < 0) return error; if ((error = snd_ad1848_pcm(codec, 0, &pcm)) < 0) return error; if ((error = snd_ad1848_mixer(codec)) < 0) return error;#endif strcpy(card->driver, chip->name); sprintf(card->shortname, "OPTi %s", card->driver);#if defined(CS4231) || defined(OPTi93X) sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d", card->shortname, pcm->name, chip->wss_base + 4, chip->irq, chip->dma1, chip->dma2);#else sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d", card->shortname, pcm->name, chip->wss_base + 4, chip->irq, chip->dma1);#endif /* CS4231 || OPTi93X */ if (chip->mpu_port <= 0 || chip->mpu_port == SNDRV_AUTO_PORT) rmidi = NULL; else if ((error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, chip->mpu_port, 0, chip->mpu_irq, SA_INTERRUPT, &rmidi))) snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n", chip->mpu_port); if (chip->fm_port > 0 && chip->fm_port != SNDRV_AUTO_PORT) { struct snd_opl3 *opl3 = NULL;#ifndef OPTi93X if (chip->hardware == OPTi9XX_HW_82C928 || chip->hardware == OPTi9XX_HW_82C929 || chip->hardware == OPTi9XX_HW_82C924) { struct snd_opl4 *opl4; /* assume we have an OPL4 */ snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x20, 0x20); if (snd_opl4_create(card, chip->fm_port, chip->fm_port - 8, 2, &opl3, &opl4) < 0) { /* no luck, use OPL3 instead */ snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20); } }#endif /* !OPTi93X */ if (!opl3 && snd_opl3_create(card, chip->fm_port, chip->fm_port + 2, OPL3_HW_AUTO, 0, &opl3) < 0) { snd_printk(KERN_WARNING "no OPL device at 0x%lx-0x%lx\n", chip->fm_port, chip->fm_port + 4 - 1); } if (opl3) {#ifdef CS4231 const int t1dev = 1;#else const int t1dev = 0;#endif if ((error = snd_opl3_timer_new(opl3, t1dev, t1dev+1)) < 0) return error; if ((error = snd_opl3_hwdep_new(opl3, 0, 1, &synth)) < 0) return error; } } return snd_card_register(card);}static struct snd_card *snd_opti9xx_card_new(void){ struct snd_card *card; card = snd_card_new(index, id, THIS_MODULE, sizeof(struct snd_opti9xx)); if (! card) return NULL; card->private_free = snd_card_opti9xx_free; return card;}static int __init snd_opti9xx_nonpnp_probe(struct platform_device *devptr){ struct snd_card *card; int error; static long possible_mpu_ports[] = {0x300, 0x310, 0x320, 0x330, -1};#ifdef OPTi93X static int possible_irqs[] = {5, 9, 10, 11, 7, -1};#else static int possible_irqs[] = {9, 10, 11, 7, -1};#endif /* OPTi93X */ static int possible_mpu_irqs[] = {5, 9, 10, 7, -1}; static int possible_dma1s[] = {3, 1, 0, -1};#if defined(CS4231) || defined(OPTi93X) static int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}};#endif /* CS4231 || OPTi93X */ if (snd_opti9xx_pnp_is_probed) return -EBUSY; if (mpu_port == SNDRV_AUTO_PORT) { if ((mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2)) < 0) { snd_printk(KERN_ERR "unable to find a free MPU401 port\n"); return -EBUSY; } } if (irq == SNDRV_AUTO_IRQ) { if ((irq = snd_legacy_find_free_irq(possible_irqs)) < 0) { snd_printk(KERN_ERR "unable to find a free IRQ\n"); return -EBUSY; } } if (mpu_irq == SNDRV_AUTO_IRQ) { if ((mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs)) < 0) { snd_printk(KERN_ERR "unable to find a free MPU401 IRQ\n"); return -EBUSY; } } if (dma1 == SNDRV_AUTO_DMA) { if ((dma1 = snd_legacy_find_free_dma(possible_dma1s)) < 0) { snd_printk(KERN_ERR "unable to find a free DMA1\n"); return -EBUSY; } }#if defined(CS4231) || defined(OPTi93X) if (dma2 == SNDRV_AUTO_DMA) { if ((dma2 = snd_legacy_find_free_dma(possible_dma2s[dma1 % 4])) < 0) { snd_printk("unable to find a free DMA2\n"); return -EBUSY; } }#endif card = snd_opti9xx_card_new(); if (! card) return -ENOMEM; if ((error = snd_card_opti9xx_detect(card, card->private_data)) < 0) { snd_card_free(card); return error; } snd_card_set_dev(card, &devptr->dev); if ((error = snd_opti9xx_probe(card)) < 0) { snd_card_free(card); return error; } platform_set_drvdata(devptr, card); return 0;}static int __devexit snd_opti9xx_nonpnp_remove(struct platform_device *devptr){ snd_card_free(platform_get_drvdata(devptr)); platform_set_drvdata(devptr, NULL); return 0;}static struct platform_driver snd_opti9xx_driver = { .probe = snd_opti9xx_nonpnp_probe, .remove = __devexit_p(snd_opti9xx_nonpnp_remove), /* FIXME: suspend/resume */ .driver = { .name = DRIVER_NAME },};#ifdef CONFIG_PNPstatic int __init snd_opti9xx_pnp_probe(struct pnp_card_link *pcard, const struct pnp_card_device_id *pid){ struct snd_card *card; int error, hw; struct snd_opti9xx *chip; if (snd_opti9xx_pnp_is_probed) return -EBUSY; if (! isapnp) return -ENODEV; card = snd_opti9xx_card_new(); if (! card) return -ENOMEM; chip = card->private_data; hw = snd_card_opti9xx_pnp(chip, pcard, pid); switch (hw) { case 0x0924: hw = OPTi9XX_HW_82C924; break; case 0x0925: hw = OPTi9XX_HW_82C925; break; case 0x0931: hw = OPTi9XX_HW_82C931; break; default: snd_card_free(card); return -ENODEV; } if ((error = snd_opti9xx_init(chip, hw))) { snd_card_free(card); return error; } if (hw <= OPTi9XX_HW_82C930) chip->mc_base -= 0x80; snd_card_set_dev(card, &pcard->card->dev); if ((error = snd_opti9xx_probe(card)) < 0) { snd_card_free(card); return error; } pnp_set_card_drvdata(pcard, card); snd_opti9xx_pnp_is_probed = 1; return 0;}static void __devexit snd_opti9xx_pnp_remove(struct pnp_card_link * pcard){ snd_card_free(pnp_get_card_drvdata(pcard)); pnp_set_card_drvdata(pcard, NULL); snd_opti9xx_pnp_is_probed = 0;}static struct pnp_card_driver opti9xx_pnpc_driver = { .flags = PNP_DRIVER_RES_DISABLE, .name = "opti9xx", .id_table = snd_opti9xx_pnpids, .probe = snd_opti9xx_pnp_probe, .remove = __devexit_p(snd_opti9xx_pnp_remove),};#endif#ifdef CONFIG_PNP#define is_isapnp_selected() isapnp#else#define is_isapnp_selected() 0#endif#ifdef OPTi93X#define CHIP_NAME "82C93x"#else#define CHIP_NAME "82C92x"#endifstatic int __init alsa_card_opti9xx_init(void){ int error; struct platform_device *device; pnp_register_card_driver(&opti9xx_pnpc_driver); if (snd_opti9xx_pnp_is_probed) return 0; if (! is_isapnp_selected()) { error = platform_driver_register(&snd_opti9xx_driver); if (error < 0) return error; device = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0); if (!IS_ERR(device)) { snd_opti9xx_platform_device = device; return 0; } platform_driver_unregister(&snd_opti9xx_driver); } pnp_unregister_card_driver(&opti9xx_pnpc_driver);#ifdef MODULE printk(KERN_ERR "no OPTi " CHIP_NAME " soundcard found\n");#endif return -ENODEV;}static void __exit alsa_card_opti9xx_exit(void){ if (!snd_opti9xx_pnp_is_probed) { platform_device_unregister(snd_opti9xx_platform_device); platform_driver_unregister(&snd_opti9xx_driver); } pnp_unregister_card_driver(&opti9xx_pnpc_driver);}module_init(alsa_card_opti9xx_init)module_exit(alsa_card_opti9xx_exit)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -