⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 opti92x-ad1848.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 5 页
字号:
	return pid->driver_data;}#endif	/* CONFIG_PNP */#if 0static int __devinit snd_card_opti9xx_resources(struct snd_card_opti9xx *chip,						snd_card_t *card){	int error, i, pnp = 0;#ifdef CONFIG_PNP	pnp = chip->dev != NULL;#endif	/* CONFIG_PNP */#ifndef OPTi93X	if (chip->chip->hardware == OPTi9XX_HW_82C928)		mpu_port = -1;#endif	/* OPTi93X */	error = 0;	if (!pnp && (mpu_port == SNDRV_DEFAULT_PORT1)) {		for (i = 0; possible_mpu_ports[i] != -1; i++)			if (!snd_register_ioport(card, possible_mpu_ports[i], 2,					DRIVER_NAME" - MPU-401", NULL)) {				mpu_port = possible_mpu_ports[i];				break;			}		if (mpu_port == SNDRV_DEFAULT_PORT1)			error = -EBUSY;	}	else		error = (mpu_port == -1) ? -ENODEV :			snd_register_ioport(card, mpu_port, 2,			DRIVER_NAME" - MPU-401", NULL);	if (error)		chip->chip->mpu_port = -1;	else if (pnp && (irq == mpu_irq))		chip->chip->mpu_irq = mpu_irq;	else if (!snd_register_interrupt(card,			DRIVER_NAME" - MPU-401",			mpu_irq, SNDRV_IRQ_TYPE_ISA,			snd_card_opti9xx_mpu_interrupt, chip,			pnp ? no_alternatives : possible_mpu_irqs,			&chip->mpuirqptr)) {		chip->chip->mpu_port = mpu_port;		chip->chip->mpu_irq = chip->mpuirqptr->irq;	}	else		chip->chip->mpu_port = -1;	if (!pnp && (port == SNDRV_DEFAULT_PORT1)) {		for (i = 0; possible_ports[i] != -1; i++)			if (!snd_register_ioport(card, possible_ports[i], 8,					DRIVER_NAME" - WSS", NULL)) {				port = possible_ports[i];				break;			}		if (port == SNDRV_DEFAULT_PORT1)			return -EBUSY;	}	else if ((error = snd_register_ioport(card, port, 8,			DRIVER_NAME" - WSS", NULL)) < 0)		return error;	chip->chip->wss_base = port;	if ((error = snd_register_interrupt(card, DRIVER_NAME" - WSS",			irq, SNDRV_IRQ_TYPE_ISA,			snd_card_opti9xx_interrupt, chip,			pnp ? no_alternatives : possible_irqs,			&chip->irqptr)) < 0)		return error;	chip->chip->irq = chip->irqptr->irq;	if ((error = snd_register_dma_channel(card,#if defined(CS4231) || defined(OPTi93X)			DRIVER_NAME" - WSS playback",#else			DRIVER_NAME" - WSS",#endif	/* CS4231 || OPTi93X */			dma1, SNDRV_DMA_TYPE_ISA, dma1_size,			pnp ? no_alternatives : possible_dma1s,			&chip->dma1ptr)) < 0)		return error;	chip->chip->dma1 = chip->dma1ptr->dma;#if defined(CS4231) || defined(OPTi93X)	if ((error = snd_register_dma_channel(card, DRIVER_NAME" - WSS capture",			dma2, SNDRV_DMA_TYPE_ISA, dma2_size,			pnp ? no_alternatives :				possible_dma2s[chip->dma1ptr->dma],			&chip->dma2ptr)) < 0)		return error;	chip->chip->dma2 = chip->dma2ptr->dma;#endif	/* CS4231 || OPTi93X */	if (snd_register_ioport(card,			pnp ? fm_port : fm_port = 0x388, 4,			DRIVER_NAME" - OPL", NULL) < 0)		fm_port = -1;	chip->chip->fm_port = fm_port;	return 0;}#endifstatic void snd_card_opti9xx_free(snd_card_t *card){	opti9xx_t *chip = (opti9xx_t *)card->private_data;        	if (chip)		release_and_free_resource(chip->res_mc_base);}static int snd_card_opti9xx_probe(struct pnp_card_link *pcard,				  const struct pnp_card_device_id *pid){	static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};	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 */	int error;	opti9xx_t *chip;#if defined(OPTi93X)	opti93x_t *codec;#elif defined(CS4231)	cs4231_t *codec;	snd_timer_t *timer;#else	ad1848_t *codec;#endif	snd_card_t *card;	snd_pcm_t *pcm;	snd_rawmidi_t *rmidi;	snd_hwdep_t *synth;#ifdef CONFIG_PNP	int hw;#endif	/* CONFIG_PNP */	if (pcard && !snd_opti9xx_first_hit)		return -EBUSY;	if (!(card = snd_card_new(index, id, THIS_MODULE,				  sizeof(opti9xx_t))))		return -ENOMEM;	card->private_free = snd_card_opti9xx_free;	chip = (opti9xx_t *)card->private_data;#ifdef CONFIG_PNP	if (isapnp && pcard && (hw = snd_card_opti9xx_pnp(chip, pcard, pid)) > 0) {		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);	} else {#endif	/* CONFIG_PNP */		if ((error = snd_card_opti9xx_detect(card, chip)) < 0) {			snd_card_free(card);			return error;		}		if ((error = snd_card_set_generic_dev(card)) < 0) {			snd_card_free(card);			return error;		}#ifdef CONFIG_PNP	}#endif	/* CONFIG_PNP */	if (! chip->res_mc_base &&	    (chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL) {		snd_card_free(card);		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_card_free(card);			snd_printk("unable to find a free WSS port\n");			return -EBUSY;		}	}#ifdef CONFIG_PNP	if (!isapnp) {#endif	if (chip->mpu_port == SNDRV_AUTO_PORT) {		if ((chip->mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2)) < 0) {			snd_card_free(card);			snd_printk("unable to find a free MPU401 port\n");			return -EBUSY;		}	}	if (chip->irq == SNDRV_AUTO_IRQ) {		if ((chip->irq = snd_legacy_find_free_irq(possible_irqs)) < 0) {			snd_card_free(card);			snd_printk("unable to find a free IRQ\n");			return -EBUSY;		}	}	if (chip->mpu_irq == SNDRV_AUTO_IRQ) {		if ((chip->mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs)) < 0) {			snd_card_free(card);			snd_printk("unable to find a free MPU401 IRQ\n");			return -EBUSY;		}	}	if (chip->dma1 == SNDRV_AUTO_DMA) {                if ((chip->dma1 = snd_legacy_find_free_dma(possible_dma1s)) < 0) {                        snd_card_free(card);			snd_printk("unable to find a free DMA1\n");			return -EBUSY;		}        }#if defined(CS4231) || defined(OPTi93X)	if (chip->dma2 == SNDRV_AUTO_DMA) {                if ((chip->dma2 = snd_legacy_find_free_dma(possible_dma2s[chip->dma1 % 4])) < 0) {                        snd_card_free(card);			snd_printk("unable to find a free DMA2\n");			return -EBUSY;		}        }#endif#ifdef CONFIG_PNP	}#endif	if ((error = snd_opti9xx_configure(chip))) {		snd_card_free(card);		return error;	}#if defined(OPTi93X)	if ((error = snd_opti93x_create(card, chip, chip->dma1, chip->dma2, &codec))) {		snd_card_free(card);		return error;	}	if ((error = snd_opti93x_pcm(codec, 0, &pcm)) < 0) {		snd_card_free(card);		return error;	}	if ((error = snd_opti93x_mixer(codec)) < 0) {		snd_card_free(card);		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) {		snd_card_free(card);		return error;	}	if ((error = snd_cs4231_pcm(codec, 0, &pcm)) < 0) {		snd_card_free(card);		return error;	}	if ((error = snd_cs4231_mixer(codec)) < 0) {		snd_card_free(card);		return error;	}	if ((error = snd_cs4231_timer(codec, 0, &timer)) < 0) {		snd_card_free(card);		return error;	}#else	if ((error = snd_ad1848_create(card, chip->wss_base + 4,				       chip->irq, chip->dma1,				       AD1848_HW_DETECT, &codec)) < 0) {		snd_card_free(card);		return error;	}	if ((error = snd_ad1848_pcm(codec, 0, &pcm)) < 0) {		snd_card_free(card);		return error;	}	if ((error = snd_ad1848_mixer(codec)) < 0) {		snd_card_free(card);		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("no MPU-401 device at 0x%lx?\n", chip->mpu_port);	if (chip->fm_port > 0 && chip->fm_port != SNDRV_AUTO_PORT) {		opl3_t *opl3 = NULL;#ifndef OPTi93X		if (chip->hardware == OPTi9XX_HW_82C928 ||		    chip->hardware == OPTi9XX_HW_82C929 ||		    chip->hardware == OPTi9XX_HW_82C924) {			opl4_t *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("no OPL device at 0x%lx-0x%lx\n",				   chip->fm_port, chip->fm_port + 4 - 1);		}		if (opl3) {			if ((error = snd_opl3_timer_new(opl3,#ifdef CS4231							1, 2)) < 0) {#else							0, 1)) < 0) {#endif	/* CS4231 */				snd_card_free(card);				return error;			}			if ((error = snd_opl3_hwdep_new(opl3, 0, 1, &synth)) < 0) {				snd_card_free(card);				return error;			}		}	}	if ((error = snd_card_register(card))) {		snd_card_free(card);		return error;	}	snd_opti9xx_first_hit = 0;	if (pcard)		pnp_set_card_drvdata(pcard, card);	else		snd_opti9xx_legacy = card;	return 0;}#ifdef CONFIG_PNPstatic void __devexit snd_opti9xx_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);	snd_opti9xx_first_hit = 0;}static struct pnp_card_driver opti9xx_pnpc_driver = {	.flags		= PNP_DRIVER_RES_DISABLE,	.name		= "opti9xx",	.id_table	= snd_opti9xx_pnpids,	.probe		= snd_card_opti9xx_probe,	.remove		= __devexit_p(snd_opti9xx_pnp_remove),};#endifstatic int __init alsa_card_opti9xx_init(void){	int cards, error;#ifdef CONFIG_PNP	cards = pnp_register_card_driver(&opti9xx_pnpc_driver);#else	cards = 0;#endif	if (cards == 0 && (error = snd_card_opti9xx_probe(NULL, NULL)) < 0) {#ifdef CONFIG_PNP		pnp_unregister_card_driver(&opti9xx_pnpc_driver);#endif#ifdef MODULE#ifdef OPTi93X		printk(KERN_ERR "no OPTi 82C93x soundcard found\n");#else		printk(KERN_ERR "no OPTi 82C92x soundcard found\n");#endif	/* OPTi93X */#endif		return error;	}	return 0;}static void __exit alsa_card_opti9xx_exit(void){#ifdef CONFIG_PNP	pnp_unregister_card_driver(&opti9xx_pnpc_driver);#endif	if (snd_opti9xx_legacy)		snd_card_free(snd_opti9xx_legacy);}module_init(alsa_card_opti9xx_init)module_exit(alsa_card_opti9xx_exit)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -