📄 cmi8330.c
字号:
* 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(struct snd_pcm_substream *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(struct snd_pcm_substream *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 int __devinit snd_cmi8330_pcm(struct snd_card *card, struct snd_cmi8330 *chip){ struct snd_pcm *pcm; const struct snd_pcm_ops *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; /* 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;}#ifdef CONFIG_PMstatic int snd_cmi8330_suspend(struct snd_card *card){ struct snd_cmi8330 *acard = card->private_data; snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); snd_pcm_suspend_all(acard->pcm); acard->wss->suspend(acard->wss); snd_sbmixer_suspend(acard->sb); return 0;}static int snd_cmi8330_resume(struct snd_card *card){ struct snd_cmi8330 *acard = card->private_data; snd_sbdsp_reset(acard->sb); snd_sbmixer_suspend(acard->sb); acard->wss->resume(acard->wss); snd_power_change_state(card, SNDRV_CTL_POWER_D0); return 0;}#endif/* */#ifdef CONFIG_PNP#define is_isapnp_selected(dev) isapnp[dev]#else#define is_isapnp_selected(dev) 0#endif#define PFX "cmi8330: "static struct snd_card *snd_cmi8330_card_new(int dev){ struct snd_card *card; struct snd_cmi8330 *acard; card = snd_card_new(index[dev], id[dev], THIS_MODULE, sizeof(struct snd_cmi8330)); if (card == NULL) { snd_printk(KERN_ERR PFX "could not get a new card\n"); return NULL; } acard = card->private_data; acard->card = card; return card;}static int __devinit snd_cmi8330_probe(struct snd_card *card, int dev){ struct snd_cmi8330 *acard; int i, err; acard = card->private_data; if ((err = snd_ad1848_create(card, wssport[dev] + 4, wssirq[dev], wssdma[dev], AD1848_HW_DETECT, &acard->wss)) < 0) { snd_printk(KERN_ERR PFX "(AD1848) device busy??\n"); return err; } if (acard->wss->hardware != AD1848_HW_CMI8330) { snd_printk(KERN_ERR PFX "(AD1848) not found during probe\n"); 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(KERN_ERR PFX "(SB16) device busy??\n"); return err; } if (acard->sb->hardware != SB_HW_16) { snd_printk(KERN_ERR PFX "(SB16) not found during probe\n"); return err; } 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]); if ((err = snd_cmi8330_mixer(card, acard)) < 0) { snd_printk(KERN_ERR PFX "failed to create mixers\n"); return err; } if ((err = snd_cmi8330_pcm(card, acard)) < 0) { snd_printk(KERN_ERR PFX "failed to create pcms\n"); 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]); return snd_card_register(card);}static int __devinit snd_cmi8330_isa_match(struct device *pdev, unsigned int dev){ if (!enable[dev] || is_isapnp_selected(dev)) return 0; if (wssport[dev] == SNDRV_AUTO_PORT) { snd_printk(KERN_ERR PFX "specify wssport\n"); return 0; } if (sbport[dev] == SNDRV_AUTO_PORT) { snd_printk(KERN_ERR PFX "specify sbport\n"); return 0; } return 1;}static int __devinit snd_cmi8330_isa_probe(struct device *pdev, unsigned int dev){ struct snd_card *card; int err; card = snd_cmi8330_card_new(dev); if (! card) return -ENOMEM; snd_card_set_dev(card, pdev); if ((err = snd_cmi8330_probe(card, dev)) < 0) { snd_card_free(card); return err; } dev_set_drvdata(pdev, card); return 0;}static int __devexit snd_cmi8330_isa_remove(struct device *devptr, unsigned int dev){ snd_card_free(dev_get_drvdata(devptr)); dev_set_drvdata(devptr, NULL); return 0;}#ifdef CONFIG_PMstatic int snd_cmi8330_isa_suspend(struct device *dev, unsigned int n, pm_message_t state){ return snd_cmi8330_suspend(dev_get_drvdata(dev));}static int snd_cmi8330_isa_resume(struct device *dev, unsigned int n){ return snd_cmi8330_resume(dev_get_drvdata(dev));}#endif#define DEV_NAME "cmi8330"static struct isa_driver snd_cmi8330_driver = { .match = snd_cmi8330_isa_match, .probe = snd_cmi8330_isa_probe, .remove = __devexit_p(snd_cmi8330_isa_remove),#ifdef CONFIG_PM .suspend = snd_cmi8330_isa_suspend, .resume = snd_cmi8330_isa_resume,#endif .driver = { .name = DEV_NAME },};#ifdef CONFIG_PNPstatic int __devinit snd_cmi8330_pnp_detect(struct pnp_card_link *pcard, const struct pnp_card_device_id *pid){ static int dev; struct snd_card *card; int res; for ( ; dev < SNDRV_CARDS; dev++) { if (enable[dev] && isapnp[dev]) break; } if (dev >= SNDRV_CARDS) return -ENODEV; card = snd_cmi8330_card_new(dev); if (! card) return -ENOMEM; if ((res = snd_cmi8330_pnp(dev, card->private_data, pcard, pid)) < 0) { snd_printk(KERN_ERR PFX "PnP detection failed\n"); snd_card_free(card); return res; } snd_card_set_dev(card, &pcard->card->dev); if ((res = snd_cmi8330_probe(card, dev)) < 0) { snd_card_free(card); return res; } pnp_set_card_drvdata(pcard, card); dev++; return 0;}static void __devexit snd_cmi8330_pnp_remove(struct pnp_card_link * pcard){ snd_card_free(pnp_get_card_drvdata(pcard)); pnp_set_card_drvdata(pcard, NULL);}#ifdef CONFIG_PMstatic int snd_cmi8330_pnp_suspend(struct pnp_card_link *pcard, pm_message_t state){ return snd_cmi8330_suspend(pnp_get_card_drvdata(pcard));}static int snd_cmi8330_pnp_resume(struct pnp_card_link *pcard){ return snd_cmi8330_resume(pnp_get_card_drvdata(pcard));}#endifstatic 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),#ifdef CONFIG_PM .suspend = snd_cmi8330_pnp_suspend, .resume = snd_cmi8330_pnp_resume,#endif};#endif /* CONFIG_PNP */static int __init alsa_card_cmi8330_init(void){ int err; err = isa_register_driver(&snd_cmi8330_driver, SNDRV_CARDS);#ifdef CONFIG_PNP if (!err) isa_registered = 1; err = pnp_register_card_driver(&cmi8330_pnpc_driver); if (!err) pnp_registered = 1; if (isa_registered) err = 0;#endif return err;}static void __exit alsa_card_cmi8330_exit(void){#ifdef CONFIG_PNP if (pnp_registered) pnp_unregister_card_driver(&cmi8330_pnpc_driver); if (isa_registered)#endif isa_unregister_driver(&snd_cmi8330_driver);}module_init(alsa_card_cmi8330_init)module_exit(alsa_card_cmi8330_exit)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -