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

📄 aureon.c

📁 LINUX 2.6.17.4的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
/* *   ALSA driver for ICEnsemble VT1724 (Envy24HT) * *   Lowlevel functions for Terratec Aureon cards * *	Copyright (c) 2003 Takashi Iwai <tiwai@suse.de> * *   This program is free software; you can redistribute it and/or modify *   it under the terms of the GNU General Public License as published by *   the Free Software Foundation; either version 2 of the License, or *   (at your option) any later version. * *   This program is distributed in the hope that it will be useful, *   but WITHOUT ANY WARRANTY; without even the implied warranty of *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *   GNU General Public License for more details. * *   You should have received a copy of the GNU General Public License *   along with this program; if not, write to the Free Software *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA * * * NOTES: * * - we reuse the struct snd_akm4xxx record for storing the wm8770 codec data. *   both wm and akm codecs are pretty similar, so we can integrate *   both controls in the future, once if wm codecs are reused in *   many boards. * * - DAC digital volumes are not implemented in the mixer. *   if they show better response than DAC analog volumes, we can use them *   instead. * *   Lowlevel functions for AudioTrak Prodigy 7.1 (and possibly 192) cards *      Copyright (c) 2003 Dimitromanolakis Apostolos <apostol@cs.utoronto.ca> * *   version 0.82: Stable / not all features work yet (no communication with AC97 secondary) *       added 64x/128x oversampling switch (should be 64x only for 96khz) *       fixed some recording labels (still need to check the rest) *       recording is working probably thanks to correct wm8770 initialization * *   version 0.5: Initial release: *           working: analog output, mixer, headphone amplifier switch *       not working: prety much everything else, at least i could verify that *                    we have no digital output, no capture, pretty bad clicks and poops *                    on mixer switch and other coll stuff. * */      #include <sound/driver.h>#include <asm/io.h>#include <linux/delay.h>#include <linux/interrupt.h>#include <linux/init.h>#include <linux/slab.h>#include <linux/mutex.h>#include <sound/core.h>#include "ice1712.h"#include "envy24ht.h"#include "aureon.h"/* WM8770 registers */#define WM_DAC_ATTEN		0x00	/* DAC1-8 analog attenuation */#define WM_DAC_MASTER_ATTEN	0x08	/* DAC master analog attenuation */#define WM_DAC_DIG_ATTEN	0x09	/* DAC1-8 digital attenuation */#define WM_DAC_DIG_MASTER_ATTEN	0x11	/* DAC master digital attenuation */#define WM_PHASE_SWAP		0x12	/* DAC phase */#define WM_DAC_CTRL1		0x13	/* DAC control bits */#define WM_MUTE			0x14	/* mute controls */#define WM_DAC_CTRL2		0x15	/* de-emphasis and zefo-flag */#define WM_INT_CTRL		0x16	/* interface control */#define WM_MASTER		0x17	/* master clock and mode */#define WM_POWERDOWN		0x18	/* power-down controls */#define WM_ADC_GAIN		0x19	/* ADC gain L(19)/R(1a) */#define WM_ADC_MUX		0x1b	/* input MUX */#define WM_OUT_MUX1		0x1c	/* output MUX */#define WM_OUT_MUX2		0x1e	/* output MUX */#define WM_RESET		0x1f	/* software reset *//* CS8415A registers */#define CS8415_CTRL1	0x01#define CS8415_CTRL2	0x02#define CS8415_QSUB		0x14#define CS8415_RATIO	0x1E#define CS8415_C_BUFFER	0x20#define CS8415_ID		0x7F/* PCA9554 registers */#define PCA9554_DEV     0x40            /* I2C device address */#define PCA9554_IN      0x00            /* input port */#define PCA9554_OUT     0x01            /* output port */#define PCA9554_INVERT  0x02            /* input invert */#define PCA9554_DIR     0x03            /* port directions *//* * Aureon Universe additional controls using PCA9554 *//* * Send data to pca9554 */static void aureon_pca9554_write(struct snd_ice1712 *ice, unsigned char reg,				 unsigned char data){	unsigned int tmp;	int i, j;	unsigned char dev = PCA9554_DEV;  /* ID 0100000, write */	unsigned char val = 0;	tmp = snd_ice1712_gpio_read(ice);	snd_ice1712_gpio_set_mask(ice, ~(AUREON_SPI_MOSI|AUREON_SPI_CLK|					 AUREON_WM_RW|AUREON_WM_CS|					 AUREON_CS8415_CS));	tmp |= AUREON_WM_RW;	tmp |= AUREON_CS8415_CS | AUREON_WM_CS; /* disable SPI devices */	tmp &= ~AUREON_SPI_MOSI;	tmp &= ~AUREON_SPI_CLK;	snd_ice1712_gpio_write(ice, tmp);	udelay(50);	/* 	 * send i2c stop condition and start condition	 * to obtain sane state	 */	tmp |= AUREON_SPI_CLK;	snd_ice1712_gpio_write(ice, tmp);	udelay(50);	tmp |= AUREON_SPI_MOSI;	snd_ice1712_gpio_write(ice, tmp);	udelay(100);	tmp &= ~AUREON_SPI_MOSI;	snd_ice1712_gpio_write(ice, tmp);	udelay(50);	tmp &= ~AUREON_SPI_CLK;	snd_ice1712_gpio_write(ice, tmp);	udelay(100);	/*	 * send device address, command and value,	 * skipping ack cycles inbetween	 */	for (j = 0; j < 3; j++) {		switch(j) {		case 0: val = dev; break;		case 1: val = reg; break;		case 2: val = data; break;		}		for (i = 7; i >= 0; i--) {			tmp &= ~AUREON_SPI_CLK;			snd_ice1712_gpio_write(ice, tmp);			udelay(40);			if (val & (1 << i))				tmp |= AUREON_SPI_MOSI;			else				tmp &= ~AUREON_SPI_MOSI;			snd_ice1712_gpio_write(ice, tmp);			udelay(40);			tmp |= AUREON_SPI_CLK;			snd_ice1712_gpio_write(ice, tmp);			udelay(40);		}                tmp &= ~AUREON_SPI_CLK;		snd_ice1712_gpio_write(ice, tmp);		udelay(40);		tmp |= AUREON_SPI_CLK;		snd_ice1712_gpio_write(ice, tmp);		udelay(40);		tmp &= ~AUREON_SPI_CLK;		snd_ice1712_gpio_write(ice, tmp);		udelay(40);	}	tmp &= ~AUREON_SPI_CLK;	snd_ice1712_gpio_write(ice, tmp);	udelay(40);	tmp &= ~AUREON_SPI_MOSI;	snd_ice1712_gpio_write(ice, tmp);	udelay(40);	tmp |= AUREON_SPI_CLK;	snd_ice1712_gpio_write(ice, tmp);	udelay(50);	tmp |= AUREON_SPI_MOSI;	snd_ice1712_gpio_write(ice, tmp);	udelay(100);}static int aureon_universe_inmux_info(struct snd_kcontrol *kcontrol,				      struct snd_ctl_elem_info *uinfo){	char *texts[3] = {"Internal Aux", "Wavetable", "Rear Line-In"};	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;	uinfo->count = 1;	uinfo->value.enumerated.items = 3;	if(uinfo->value.enumerated.item >= uinfo->value.enumerated.items)		uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);	return 0;}static int aureon_universe_inmux_get(struct snd_kcontrol *kcontrol,				     struct snd_ctl_elem_value *ucontrol){	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);	ucontrol->value.integer.value[0] = ice->spec.aureon.pca9554_out;	return 0;}static int aureon_universe_inmux_put(struct snd_kcontrol *kcontrol,				     struct snd_ctl_elem_value *ucontrol){	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);	unsigned char oval, nval;	int change;	snd_ice1712_save_gpio_status(ice);		oval = ice->spec.aureon.pca9554_out;	nval = ucontrol->value.integer.value[0];	if ((change = (oval != nval))) {		aureon_pca9554_write(ice, PCA9554_OUT, nval);		ice->spec.aureon.pca9554_out = nval;	}	snd_ice1712_restore_gpio_status(ice);		return change;}static void aureon_ac97_write(struct snd_ice1712 *ice, unsigned short reg,			      unsigned short val){	unsigned int tmp;	/* Send address to XILINX chip */	tmp = (snd_ice1712_gpio_read(ice) & ~0xFF) | (reg & 0x7F);	snd_ice1712_gpio_write(ice, tmp);	udelay(10);	tmp |= AUREON_AC97_ADDR;	snd_ice1712_gpio_write(ice, tmp);	udelay(10);	tmp &= ~AUREON_AC97_ADDR;	snd_ice1712_gpio_write(ice, tmp);	udelay(10);		/* Send low-order byte to XILINX chip */	tmp &= ~AUREON_AC97_DATA_MASK;	tmp |= val & AUREON_AC97_DATA_MASK;	snd_ice1712_gpio_write(ice, tmp);	udelay(10);	tmp |= AUREON_AC97_DATA_LOW;	snd_ice1712_gpio_write(ice, tmp);	udelay(10);	tmp &= ~AUREON_AC97_DATA_LOW;	snd_ice1712_gpio_write(ice, tmp);	udelay(10);		/* Send high-order byte to XILINX chip */	tmp &= ~AUREON_AC97_DATA_MASK;	tmp |= (val >> 8) & AUREON_AC97_DATA_MASK;	snd_ice1712_gpio_write(ice, tmp);	udelay(10);	tmp |= AUREON_AC97_DATA_HIGH;	snd_ice1712_gpio_write(ice, tmp);	udelay(10);	tmp &= ~AUREON_AC97_DATA_HIGH;	snd_ice1712_gpio_write(ice, tmp);	udelay(10);		/* Instruct XILINX chip to parse the data to the STAC9744 chip */	tmp |= AUREON_AC97_COMMIT;	snd_ice1712_gpio_write(ice, tmp);	udelay(10);	tmp &= ~AUREON_AC97_COMMIT;	snd_ice1712_gpio_write(ice, tmp);	udelay(10);		/* Store the data in out private buffer */	ice->spec.aureon.stac9744[(reg & 0x7F) >> 1] = val;}static unsigned short aureon_ac97_read(struct snd_ice1712 *ice, unsigned short reg){       return ice->spec.aureon.stac9744[(reg & 0x7F) >> 1];}/* * Initialize STAC9744 chip */static int aureon_ac97_init (struct snd_ice1712 *ice){	int i;	static unsigned short ac97_defaults[] = {		0x00, 0x9640,		0x02, 0x8000,		0x04, 0x8000,		0x06, 0x8000,		0x0C, 0x8008,		0x0E, 0x8008,		0x10, 0x8808,		0x12, 0x8808,		0x14, 0x8808,		0x16, 0x8808,		0x18, 0x8808,		0x1C, 0x8000,		0x26, 0x000F,		0x28, 0x0201,		0x2C, 0xBB80,		0x32, 0xBB80,		0x7C, 0x8384,		0x7E, 0x7644,		(unsigned short)-1	};	unsigned int tmp;	/* Cold reset */	tmp = (snd_ice1712_gpio_read(ice) | AUREON_AC97_RESET) & ~AUREON_AC97_DATA_MASK;	snd_ice1712_gpio_write(ice, tmp);	udelay(3);		tmp &= ~AUREON_AC97_RESET;	snd_ice1712_gpio_write(ice, tmp);	udelay(3);		tmp |= AUREON_AC97_RESET;	snd_ice1712_gpio_write(ice, tmp);	udelay(3);		memset(&ice->spec.aureon.stac9744, 0, sizeof(ice->spec.aureon.stac9744));	for (i=0; ac97_defaults[i] != (unsigned short)-1; i+=2)		ice->spec.aureon.stac9744[(ac97_defaults[i]) >> 1] = ac97_defaults[i+1];			aureon_ac97_write(ice, AC97_MASTER, 0x0000); // Unmute AC'97 master volume permanently - muting is done by WM8770	return 0;}#define AUREON_AC97_STEREO	0x80/* * AC'97 volume controls */static int aureon_ac97_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;	uinfo->count = kcontrol->private_value & AUREON_AC97_STEREO ? 2 : 1;	uinfo->value.integer.min = 0;	uinfo->value.integer.max = 31;	return 0;}static int aureon_ac97_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);	unsigned short vol;	mutex_lock(&ice->gpio_mutex);	vol = aureon_ac97_read(ice, kcontrol->private_value & 0x7F);	ucontrol->value.integer.value[0] = 0x1F - (vol & 0x1F);	if (kcontrol->private_value & AUREON_AC97_STEREO)		ucontrol->value.integer.value[1] = 0x1F - ((vol >> 8) & 0x1F);	mutex_unlock(&ice->gpio_mutex);	return 0;}static int aureon_ac97_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);	unsigned short ovol, nvol;	int change;		snd_ice1712_save_gpio_status(ice);	ovol = aureon_ac97_read(ice, kcontrol->private_value & 0x7F);	nvol = (0x1F - ucontrol->value.integer.value[0]) & 0x001F;	if (kcontrol->private_value & AUREON_AC97_STEREO)		nvol |= ((0x1F - ucontrol->value.integer.value[1]) << 8) & 0x1F00;	nvol |= ovol & ~0x1F1F;		if ((change = (ovol != nvol)))		aureon_ac97_write(ice, kcontrol->private_value & 0x7F, nvol);	snd_ice1712_restore_gpio_status(ice);	return change;		}/* * AC'97 mute controls */#define aureon_ac97_mute_info	aureon_mono_bool_infostatic int aureon_ac97_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);	mutex_lock(&ice->gpio_mutex);	ucontrol->value.integer.value[0] = aureon_ac97_read(ice, kcontrol->private_value & 0x7F) & 0x8000 ? 0 : 1;	mutex_unlock(&ice->gpio_mutex);	return 0;}static int aureon_ac97_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);	unsigned short ovol, nvol;	int change;	snd_ice1712_save_gpio_status(ice);		ovol = aureon_ac97_read(ice, kcontrol->private_value & 0x7F);	nvol = (ucontrol->value.integer.value[0] ? 0x0000 : 0x8000) | (ovol & ~	0x8000);		if ((change = (ovol != nvol)))		aureon_ac97_write(ice, kcontrol->private_value & 0x7F, nvol);			snd_ice1712_restore_gpio_status(ice);	return change;}/* * AC'97 mute controls */#define aureon_ac97_micboost_info	aureon_mono_bool_infostatic int aureon_ac97_micboost_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);	mutex_lock(&ice->gpio_mutex);	ucontrol->value.integer.value[0] = aureon_ac97_read(ice, AC97_MIC) & 0x0020 ? 0 : 1;	mutex_unlock(&ice->gpio_mutex);	return 0;}static int aureon_ac97_micboost_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);	unsigned short ovol, nvol;	int change;	snd_ice1712_save_gpio_status(ice);		ovol = aureon_ac97_read(ice, AC97_MIC);	nvol = (ucontrol->value.integer.value[0] ? 0x0000 : 0x0020) | (ovol & ~0x0020);		if ((change = (ovol != nvol)))		aureon_ac97_write(ice, AC97_MIC, nvol);			snd_ice1712_restore_gpio_status(ice);	return change;}/* * write data in the SPI mode */static void aureon_spi_write(struct snd_ice1712 *ice, unsigned int cs, unsigned int data, int bits){	unsigned int tmp;	int i;	unsigned int mosi, clk;	tmp = snd_ice1712_gpio_read(ice);	if (ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71LT) {		snd_ice1712_gpio_set_mask(ice, ~(PRODIGY_SPI_MOSI|PRODIGY_SPI_CLK|PRODIGY_WM_CS));		mosi = PRODIGY_SPI_MOSI;		clk = PRODIGY_SPI_CLK;	}	else {		snd_ice1712_gpio_set_mask(ice, ~(AUREON_WM_RW|AUREON_SPI_MOSI|AUREON_SPI_CLK|						 AUREON_WM_CS|AUREON_CS8415_CS));		mosi = AUREON_SPI_MOSI;		clk = AUREON_SPI_CLK;				tmp |= AUREON_WM_RW;	}		tmp &= ~cs;	snd_ice1712_gpio_write(ice, tmp);	udelay(1);	for (i = bits - 1; i >= 0; i--) {		tmp &= ~clk;		snd_ice1712_gpio_write(ice, tmp);		udelay(1);		if (data & (1 << i))			tmp |= mosi;		else			tmp &= ~mosi;		snd_ice1712_gpio_write(ice, tmp);		udelay(1);		tmp |= clk;		snd_ice1712_gpio_write(ice, tmp);		udelay(1);	}	tmp &= ~clk;	tmp |= cs;	snd_ice1712_gpio_write(ice, tmp);	udelay(1);	tmp |= clk;	snd_ice1712_gpio_write(ice, tmp);	udelay(1);}/* * Read data in SPI mode */static void aureon_spi_read(struct snd_ice1712 *ice, unsigned int cs, unsigned int data, int bits, unsigned char *buffer, int size) {	int i, j;	unsigned int tmp;	tmp = (snd_ice1712_gpio_read(ice) & ~AUREON_SPI_CLK) | AUREON_CS8415_CS|AUREON_WM_CS;	snd_ice1712_gpio_write(ice, tmp);	tmp &= ~cs;	snd_ice1712_gpio_write(ice, tmp);	udelay(1);	for (i=bits-1; i>=0; i--) {		if (data & (1 << i))			tmp |= AUREON_SPI_MOSI;		else			tmp &= ~AUREON_SPI_MOSI;		snd_ice1712_gpio_write(ice, tmp);		udelay(1);

⌨️ 快捷键说明

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