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

📄 emu10k1_main.c

📁 鼎力推荐!本程序是基于嵌入式LUNUX系统开发的源程序代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* In A1 Silicon, these bits are in the HC register */#define HOOKN_BIT		(1L << 12)#define HANDN_BIT		(1L << 11)#define PULSEN_BIT		(1L << 10)#define EC_GDI1			(1 << 13)#define EC_GDI0			(1 << 14)#define EC_NUM_CONTROL_BITS	20#define EC_AC3_DATA_SELN	0x0001L#define EC_EE_DATA_SEL		0x0002L#define EC_EE_CNTRL_SELN	0x0004L#define EC_EECLK		0x0008L#define EC_EECS			0x0010L#define EC_EESDO		0x0020L#define EC_TRIM_CSN		0x0040L#define EC_TRIM_SCLK		0x0080L#define EC_TRIM_SDATA		0x0100L#define EC_TRIM_MUTEN		0x0200L#define EC_ADCCAL		0x0400L#define EC_ADCRSTN		0x0800L#define EC_DACCAL		0x1000L#define EC_DACMUTEN		0x2000L#define EC_LEDN			0x4000L#define EC_SPDIF0_SEL_SHIFT	15#define EC_SPDIF1_SEL_SHIFT	17#define EC_SPDIF0_SEL_MASK	(0x3L << EC_SPDIF0_SEL_SHIFT)#define EC_SPDIF1_SEL_MASK	(0x7L << EC_SPDIF1_SEL_SHIFT)#define EC_SPDIF0_SELECT(_x)	(((_x) << EC_SPDIF0_SEL_SHIFT) & EC_SPDIF0_SEL_MASK)#define EC_SPDIF1_SELECT(_x)	(((_x) << EC_SPDIF1_SEL_SHIFT) & EC_SPDIF1_SEL_MASK)#define EC_CURRENT_PROM_VERSION 0x01	/* Self-explanatory.  This should					 * be incremented any time the EEPROM's					 * format is changed.  */#define EC_EEPROM_SIZE		0x40	/* ECARD EEPROM has 64 16-bit words *//* Addresses for special values stored in to EEPROM */#define EC_PROM_VERSION_ADDR	0x20	/* Address of the current prom version */#define EC_BOARDREV0_ADDR	0x21	/* LSW of board rev */#define EC_BOARDREV1_ADDR	0x22	/* MSW of board rev */#define EC_LAST_PROMFILE_ADDR	0x2f#define EC_SERIALNUM_ADDR	0x30	/* First word of serial number.  The 					 * can be up to 30 characters in length					 * and is stored as a NULL-terminated					 * ASCII string.  Any unused bytes must be					 * filled with zeros */#define EC_CHECKSUM_ADDR	0x3f	/* Location at which checksum is stored *//* Most of this stuff is pretty self-evident.  According to the hardware  * dudes, we need to leave the ADCCAL bit low in order to avoid a DC  * offset problem.  Weird. */#define EC_RAW_RUN_MODE		(EC_DACMUTEN | EC_ADCRSTN | EC_TRIM_MUTEN | \				 EC_TRIM_CSN)#define EC_DEFAULT_ADC_GAIN	0xC4C4#define EC_DEFAULT_SPDIF0_SEL	0x0#define EC_DEFAULT_SPDIF1_SEL	0x4/************************************************************************** * @func Clock bits into the Ecard's control latch.  The Ecard uses a *  control latch will is loaded bit-serially by toggling the Modem control *  lines from function 2 on the E8010.  This function hides these details *  and presents the illusion that we are actually writing to a distinct *  register. */static void snd_emu10k1_ecard_write(emu10k1_t * emu, unsigned int value){	unsigned short count;	unsigned int data;	unsigned long hc_port;	unsigned int hc_value;	hc_port = emu->port + HCFG;	hc_value = inl(hc_port) & ~(HOOKN_BIT | HANDN_BIT | PULSEN_BIT);	outl(hc_value, hc_port);	for (count = 0; count < EC_NUM_CONTROL_BITS; count++) {		/* Set up the value */		data = ((value & 0x1) ? PULSEN_BIT : 0);		value >>= 1;		outl(hc_value | data, hc_port);		/* Clock the shift register */		outl(hc_value | data | HANDN_BIT, hc_port);		outl(hc_value | data, hc_port);	}	/* Latch the bits */	outl(hc_value | HOOKN_BIT, hc_port);	outl(hc_value, hc_port);}/************************************************************************** * @func Set the gain of the ECARD's CS3310 Trim/gain controller.  The * trim value consists of a 16bit value which is composed of two * 8 bit gain/trim values, one for the left channel and one for the * right channel.  The following table maps from the Gain/Attenuation * value in decibels into the corresponding bit pattern for a single * channel. */static void snd_emu10k1_ecard_setadcgain(emu10k1_t * emu,					 unsigned short gain){	unsigned int bit;	/* Enable writing to the TRIM registers */	snd_emu10k1_ecard_write(emu, emu->ecard_ctrl & ~EC_TRIM_CSN);	/* Do it again to insure that we meet hold time requirements */	snd_emu10k1_ecard_write(emu, emu->ecard_ctrl & ~EC_TRIM_CSN);	for (bit = (1 << 15); bit; bit >>= 1) {		unsigned int value;				value = emu->ecard_ctrl & ~(EC_TRIM_CSN | EC_TRIM_SDATA);		if (gain & bit)			value |= EC_TRIM_SDATA;		/* Clock the bit */		snd_emu10k1_ecard_write(emu, value);		snd_emu10k1_ecard_write(emu, value | EC_TRIM_SCLK);		snd_emu10k1_ecard_write(emu, value);	}	snd_emu10k1_ecard_write(emu, emu->ecard_ctrl);}static int __devinit snd_emu10k1_ecard_init(emu10k1_t * emu){	unsigned int hc_value;	/* Set up the initial settings */	emu->ecard_ctrl = EC_RAW_RUN_MODE |			  EC_SPDIF0_SELECT(EC_DEFAULT_SPDIF0_SEL) |			  EC_SPDIF1_SELECT(EC_DEFAULT_SPDIF1_SEL);	/* Step 0: Set the codec type in the hardware control register 	 * and enable audio output */	hc_value = inl(emu->port + HCFG);	outl(hc_value | HCFG_AUDIOENABLE | HCFG_CODECFORMAT_I2S, emu->port + HCFG);	inl(emu->port + HCFG);	/* Step 1: Turn off the led and deassert TRIM_CS */	snd_emu10k1_ecard_write(emu, EC_ADCCAL | EC_LEDN | EC_TRIM_CSN);	/* Step 2: Calibrate the ADC and DAC */	snd_emu10k1_ecard_write(emu, EC_DACCAL | EC_LEDN | EC_TRIM_CSN);	/* Step 3: Wait for awhile;   XXX We can't get away with this	 * under a real operating system; we'll need to block and wait that	 * way. */	snd_emu10k1_wait(emu, 48000);	/* Step 4: Switch off the DAC and ADC calibration.  Note	 * That ADC_CAL is actually an inverted signal, so we assert	 * it here to stop calibration.  */	snd_emu10k1_ecard_write(emu, EC_ADCCAL | EC_LEDN | EC_TRIM_CSN);	/* Step 4: Switch into run mode */	snd_emu10k1_ecard_write(emu, emu->ecard_ctrl);	/* Step 5: Set the analog input gain */	snd_emu10k1_ecard_setadcgain(emu, EC_DEFAULT_ADC_GAIN);	return 0;}/* *  Create the EMU10K1 instance */static int snd_emu10k1_free(emu10k1_t *emu){	if (emu->port) {	/* avoid access to already used hardware */	       	snd_emu10k1_fx8010_tram_setup(emu, 0);		snd_emu10k1_done(emu);       	}	if (emu->memhdr)		snd_util_memhdr_free(emu->memhdr);	if (emu->silent_page.area)		snd_dma_free_pages(&emu->silent_page);	if (emu->ptb_pages.area)		snd_dma_free_pages(&emu->ptb_pages);	vfree(emu->page_ptr_table);	vfree(emu->page_addr_table);	if (emu->irq >= 0)		free_irq(emu->irq, (void *)emu);	if (emu->port)		pci_release_regions(emu->pci);	pci_disable_device(emu->pci);	kfree(emu);	return 0;}static int snd_emu10k1_dev_free(snd_device_t *device){	emu10k1_t *emu = device->device_data;	return snd_emu10k1_free(emu);}int __devinit snd_emu10k1_create(snd_card_t * card,		       struct pci_dev * pci,		       unsigned short extin_mask,		       unsigned short extout_mask,		       long max_cache_bytes,		       int enable_ir,		       emu10k1_t ** remu){	emu10k1_t *emu;	int err;	int is_audigy;	static snd_device_ops_t ops = {		.dev_free =	snd_emu10k1_dev_free,	};		*remu = NULL;	// is_audigy = (int)pci->driver_data;	is_audigy = (pci->device == 0x0004) || ( (pci->device == 0x0008) );	/* enable PCI device */	if ((err = pci_enable_device(pci)) < 0)		return err;	emu = kcalloc(1, sizeof(*emu), GFP_KERNEL);	if (emu == NULL) {		pci_disable_device(pci);		return -ENOMEM;	}	/* set the DMA transfer mask */	emu->dma_mask = is_audigy ? AUDIGY_DMA_MASK : EMU10K1_DMA_MASK;	if (pci_set_dma_mask(pci, emu->dma_mask) < 0 ||	    pci_set_consistent_dma_mask(pci, emu->dma_mask) < 0) {		snd_printk(KERN_ERR "architecture does not support PCI busmaster DMA with mask 0x%lx\n", emu->dma_mask);		kfree(emu);		pci_disable_device(pci);		return -ENXIO;	}	emu->card = card;	spin_lock_init(&emu->reg_lock);	spin_lock_init(&emu->emu_lock);	spin_lock_init(&emu->voice_lock);	spin_lock_init(&emu->synth_lock);	spin_lock_init(&emu->memblk_lock);	init_MUTEX(&emu->ptb_lock);	init_MUTEX(&emu->fx8010.lock);	INIT_LIST_HEAD(&emu->mapped_link_head);	INIT_LIST_HEAD(&emu->mapped_order_link_head);	emu->pci = pci;	emu->irq = -1;	emu->synth = NULL;	emu->get_synth_voice = NULL;	emu->audigy = is_audigy;	if (is_audigy)		emu->gpr_base = A_FXGPREGBASE;	else		emu->gpr_base = FXGPREGBASE;	if ((err = pci_request_regions(pci, "EMU10K1")) < 0) {		kfree(emu);		pci_disable_device(pci);		return err;	}	emu->port = pci_resource_start(pci, 0);	if (request_irq(pci->irq, snd_emu10k1_interrupt, SA_INTERRUPT|SA_SHIRQ, "EMU10K1", (void *)emu)) {		snd_emu10k1_free(emu);		return -EBUSY;	}	emu->irq = pci->irq;	emu->max_cache_pages = max_cache_bytes >> PAGE_SHIFT;	if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),				32 * 1024, &emu->ptb_pages) < 0) {		snd_emu10k1_free(emu);		return -ENOMEM;	}	emu->page_ptr_table = (void **)vmalloc(emu->max_cache_pages * sizeof(void*));	emu->page_addr_table = (unsigned long*)vmalloc(emu->max_cache_pages * sizeof(unsigned long));	if (emu->page_ptr_table == NULL || emu->page_addr_table == NULL) {		snd_emu10k1_free(emu);		return -ENOMEM;	}	if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),				EMUPAGESIZE, &emu->silent_page) < 0) {		snd_emu10k1_free(emu);		return -ENOMEM;	}	emu->memhdr = snd_util_memhdr_new(emu->max_cache_pages * PAGE_SIZE);	if (emu->memhdr == NULL) {		snd_emu10k1_free(emu);		return -ENOMEM;	}	emu->memhdr->block_extra_size = sizeof(emu10k1_memblk_t) - sizeof(snd_util_memblk_t);	pci_set_master(pci);	/* read revision & serial */	pci_read_config_byte(pci, PCI_REVISION_ID, (char *)&emu->revision);	pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &emu->serial);	pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &emu->model);	emu->card_type = EMU10K1_CARD_CREATIVE;	if (emu->serial == 0x40011102) {		emu->card_type = EMU10K1_CARD_EMUAPS;		emu->APS = 1;		emu->no_ac97 = 1; /* APS has no AC97 chip */	}	else if (emu->revision == 4 && emu->serial == 0x10051102) {		/* Audigy 2 EX has apparently no effective AC97 controls		 * (for both input and output), so we skip the AC97 detections		 */		snd_printdd(KERN_INFO "Audigy2 EX is detected. skipping ac97.\n");		emu->no_ac97 = 1;		}		if (emu->revision == 4 && (emu->model == 0x2001 || emu->model == 0x2002)) {		/* Audigy 2 ZS */		snd_printdd(KERN_INFO "Audigy2 ZS is detected. setting 7.1 mode.\n");		emu->spk71 = 1;	}			emu->fx8010.fxbus_mask = 0x303f;	if (extin_mask == 0)		extin_mask = 0x3fcf;	if (extout_mask == 0)		extout_mask = 0x7fff;	emu->fx8010.extin_mask = extin_mask;	emu->fx8010.extout_mask = extout_mask;	if (emu->APS) {		if ((err = snd_emu10k1_ecard_init(emu)) < 0) {			snd_emu10k1_free(emu);			return err;		}	} else {		/* 5.1: Enable the additional AC97 Slots. If the emu10k1 version			does not support this, it shouldn't do any harm */		snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE);	}	if ((err = snd_emu10k1_init(emu, enable_ir)) < 0) {		snd_emu10k1_free(emu);		return err;	}	if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, emu, &ops)) < 0) {		snd_emu10k1_free(emu);		return err;	}	snd_emu10k1_proc_init(emu);	snd_card_set_dev(card, &pci->dev);	*remu = emu;	return 0;}/* memory.c */EXPORT_SYMBOL(snd_emu10k1_synth_alloc);EXPORT_SYMBOL(snd_emu10k1_synth_free);EXPORT_SYMBOL(snd_emu10k1_synth_bzero);EXPORT_SYMBOL(snd_emu10k1_synth_copy_from_user);EXPORT_SYMBOL(snd_emu10k1_memblk_map);/* voice.c */EXPORT_SYMBOL(snd_emu10k1_voice_alloc);EXPORT_SYMBOL(snd_emu10k1_voice_free);/* io.c */EXPORT_SYMBOL(snd_emu10k1_ptr_read);EXPORT_SYMBOL(snd_emu10k1_ptr_write);

⌨️ 快捷键说明

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