📄 cmi8330.c
字号:
wssdma[dev] = pnp_dma(pdev, 0); wssirq[dev] = pnp_irq(pdev, 0); /* allocate SB16 resources */ pdev = acard->play; pnp_init_resource_table(cfg); if (sbport[dev] != SNDRV_AUTO_PORT) pnp_resource_change(&cfg->port_resource[0], sbport[dev], 16); if (sbdma8[dev] != SNDRV_AUTO_DMA) pnp_resource_change(&cfg->dma_resource[0], sbdma8[dev], 1); if (sbdma16[dev] != SNDRV_AUTO_DMA) pnp_resource_change(&cfg->dma_resource[1], sbdma16[dev], 1); if (sbirq[dev] != SNDRV_AUTO_IRQ) pnp_resource_change(&cfg->irq_resource[0], sbirq[dev], 1); err = pnp_manual_config_dev(pdev, cfg, 0); if (err < 0) snd_printk(KERN_ERR "CMI8330/C3D (SB16) PnP manual resources are invalid, using auto config\n"); err = pnp_activate_dev(pdev); if (err < 0) { snd_printk(KERN_ERR "CMI8330/C3D (SB16) PnP configure failure\n"); kfree(cfg); return -EBUSY; } sbport[dev] = pnp_port_start(pdev, 0); sbdma8[dev] = pnp_dma(pdev, 0); sbdma16[dev] = pnp_dma(pdev, 1); sbirq[dev] = pnp_irq(pdev, 0); kfree(cfg); return 0;}#endif/* * PCM interface * * since we call the different chip interfaces for playback and capture * directions, we need a trick. * * - copy the ops for each direction into a local record. * - replace the open callback with the new one, which replaces the * substream->private_data with the corresponding chip instance * and calls again the original open callback of the chip. * */#ifdef PLAYBACK_ON_SB#define CMI_SB_STREAM SNDRV_PCM_STREAM_PLAYBACK#define CMI_AD_STREAM SNDRV_PCM_STREAM_CAPTURE#else#define CMI_SB_STREAM SNDRV_PCM_STREAM_CAPTURE#define CMI_AD_STREAM SNDRV_PCM_STREAM_PLAYBACK#endifstatic int snd_cmi8330_playback_open(snd_pcm_substream_t * substream){ struct snd_cmi8330 *chip = snd_pcm_substream_chip(substream); /* replace the private_data and call the original open callback */ substream->private_data = chip->streams[SNDRV_PCM_STREAM_PLAYBACK].private_data; return chip->streams[SNDRV_PCM_STREAM_PLAYBACK].open(substream);}static int snd_cmi8330_capture_open(snd_pcm_substream_t * substream){ struct snd_cmi8330 *chip = snd_pcm_substream_chip(substream); /* replace the private_data and call the original open callback */ substream->private_data = chip->streams[SNDRV_PCM_STREAM_CAPTURE].private_data; return chip->streams[SNDRV_PCM_STREAM_CAPTURE].open(substream);}static void snd_cmi8330_pcm_free(snd_pcm_t *pcm){ snd_pcm_lib_preallocate_free_for_all(pcm);}static int __devinit snd_cmi8330_pcm(snd_card_t *card, struct snd_cmi8330 *chip){ snd_pcm_t *pcm; const snd_pcm_ops_t *ops; int err; static snd_pcm_open_callback_t cmi_open_callbacks[2] = { snd_cmi8330_playback_open, snd_cmi8330_capture_open }; if ((err = snd_pcm_new(card, "CMI8330", 0, 1, 1, &pcm)) < 0) return err; strcpy(pcm->name, "CMI8330"); pcm->private_data = chip; pcm->private_free = snd_cmi8330_pcm_free; /* SB16 */ ops = snd_sb16dsp_get_pcm_ops(CMI_SB_STREAM); chip->streams[CMI_SB_STREAM].ops = *ops; chip->streams[CMI_SB_STREAM].open = ops->open; chip->streams[CMI_SB_STREAM].ops.open = cmi_open_callbacks[CMI_SB_STREAM]; chip->streams[CMI_SB_STREAM].private_data = chip->sb; /* AD1848 */ ops = snd_ad1848_get_pcm_ops(CMI_AD_STREAM); chip->streams[CMI_AD_STREAM].ops = *ops; chip->streams[CMI_AD_STREAM].open = ops->open; chip->streams[CMI_AD_STREAM].ops.open = cmi_open_callbacks[CMI_AD_STREAM]; chip->streams[CMI_AD_STREAM].private_data = chip->wss; snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &chip->streams[SNDRV_PCM_STREAM_PLAYBACK].ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &chip->streams[SNDRV_PCM_STREAM_CAPTURE].ops); snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_isa_data(), 64*1024, 128*1024); chip->pcm = pcm; return 0;}/* */static int __devinit snd_cmi8330_probe(int dev, struct pnp_card_link *pcard, const struct pnp_card_device_id *pid){ snd_card_t *card; struct snd_cmi8330 *acard; unsigned long flags; int i, err;#ifdef CONFIG_PNP if (!isapnp[dev]) {#endif if (wssport[dev] == SNDRV_AUTO_PORT) { snd_printk("specify wssport\n"); return -EINVAL; } if (sbport[dev] == SNDRV_AUTO_PORT) { snd_printk("specify sbport\n"); return -EINVAL; }#ifdef CONFIG_PNP }#endif card = snd_card_new(index[dev], id[dev], THIS_MODULE, sizeof(struct snd_cmi8330)); if (card == NULL) { snd_printk("could not get a new card\n"); return -ENOMEM; } acard = (struct snd_cmi8330 *)card->private_data; acard->card = card;#ifdef CONFIG_PNP if (isapnp[dev]) { if ((err = snd_cmi8330_pnp(dev, acard, pcard, pid)) < 0) { snd_printk("PnP detection failed\n"); snd_card_free(card); return err; } snd_card_set_dev(card, &pcard->card->dev); }#endif if ((err = snd_ad1848_create(card, wssport[dev] + 4, wssirq[dev], wssdma[dev], AD1848_HW_DETECT, &acard->wss)) < 0) { snd_printk("(AD1848) device busy??\n"); snd_card_free(card); return err; } if (acard->wss->hardware != AD1848_HW_CMI8330) { snd_printk("(AD1848) not found during probe\n"); snd_card_free(card); return -ENODEV; } if ((err = snd_sbdsp_create(card, sbport[dev], sbirq[dev], snd_sb16dsp_interrupt, sbdma8[dev], sbdma16[dev], SB_HW_AUTO, &acard->sb)) < 0) { snd_printk("(SB16) device busy??\n"); snd_card_free(card); return err; } if (acard->sb->hardware != SB_HW_16) { snd_printk("(SB16) not found during probe\n"); snd_card_free(card); return -ENODEV; } spin_lock_irqsave(&acard->wss->reg_lock, flags); snd_ad1848_out(acard->wss, AD1848_MISC_INFO, 0x40); /* switch on MODE2 */ for (i = CMI8330_RMUX3D; i <= CMI8330_CDINGAIN; i++) snd_ad1848_out(acard->wss, i, snd_cmi8330_image[i - CMI8330_RMUX3D]); spin_unlock_irqrestore(&acard->wss->reg_lock, flags); if ((err = snd_cmi8330_mixer(card, acard)) < 0) { snd_printk("failed to create mixers\n"); snd_card_free(card); return err; } if ((err = snd_cmi8330_pcm(card, acard)) < 0) { snd_printk("failed to create pcms\n"); snd_card_free(card); return err; } strcpy(card->driver, "CMI8330/C3D"); strcpy(card->shortname, "C-Media CMI8330/C3D"); sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d", card->shortname, acard->wss->port, wssirq[dev], wssdma[dev]); if ((err = snd_card_register(card)) < 0) { snd_card_free(card); return err; } if (pcard) pnp_set_card_drvdata(pcard, card); else snd_cmi8330_legacy[dev] = card; return 0;}#ifdef CONFIG_PNPstatic int __devinit snd_cmi8330_pnp_detect(struct pnp_card_link *card, const struct pnp_card_device_id *id){ static int dev; int res; for ( ; dev < SNDRV_CARDS; dev++) { if (!enable[dev] || !isapnp[dev]) continue; res = snd_cmi8330_probe(dev, card, id); if (res < 0) return res; dev++; return 0; } return -ENODEV;}static void __devexit snd_cmi8330_pnp_remove(struct pnp_card_link * pcard){ snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard); snd_card_disconnect(card); snd_card_free_in_thread(card);}static struct pnp_card_driver cmi8330_pnpc_driver = { .flags = PNP_DRIVER_RES_DISABLE, .name = "cmi8330", .id_table = snd_cmi8330_pnpids, .probe = snd_cmi8330_pnp_detect, .remove = __devexit_p(snd_cmi8330_pnp_remove),};#endif /* CONFIG_PNP */static int __init alsa_card_cmi8330_init(void){ int dev, cards = 0; for (dev = 0; dev < SNDRV_CARDS; dev++) { if (!enable[dev]) continue;#ifdef CONFIG_PNP if (isapnp[dev]) continue;#endif if (snd_cmi8330_probe(dev, NULL, NULL) >= 0) cards++; }#ifdef CONFIG_PNP cards += pnp_register_card_driver(&cmi8330_pnpc_driver);#endif if (!cards) {#ifdef CONFIG_PNP pnp_unregister_card_driver(&cmi8330_pnpc_driver);#endif#ifdef MODULE snd_printk(KERN_ERR "CMI8330 not found or device busy\n");#endif return -ENODEV; } return 0;}static void __exit alsa_card_cmi8330_exit(void){ int i;#ifdef CONFIG_PNP /* PnP cards first */ pnp_unregister_card_driver(&cmi8330_pnpc_driver);#endif for (i = 0; i < SNDRV_CARDS; i++) snd_card_free(snd_cmi8330_legacy[i]);}module_init(alsa_card_cmi8330_init)module_exit(alsa_card_cmi8330_exit)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -