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

📄 prodigy192.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *   ALSA driver for ICEnsemble VT1724 (Envy24HT) * *   Lowlevel functions for AudioTrak Prodigy 192 cards *   Supported IEC958 input from optional MI/ODI/O add-on card. * *   Specifics (SW, HW): *   ------------------- *   	* 49.5MHz crystal *   	* SPDIF-OUT on the card: *  	  - coax (through isolation transformer)/toslink supplied by *          74HC04 gates - 3 in parallel *   	  - output switched between on-board CD drive dig-out connector *          and ice1724 SPDTX pin, using 74HC02 NOR gates, controlled *          by GPIO20 (0 = CD dig-out, 1 = SPDTX) *   	* SPDTX goes straight to MI/ODI/O card's SPDIF-OUT coax * *   	* MI/ODI/O card: AK4114 based, used for iec958 input only *   		- toslink input -> RX0 *   		- coax input -> RX1 *   		- 4wire protocol: *   			AK4114		ICE1724 *   			------------------------------ * 			CDTO (pin 32) -- GPIO11 pin 86 * 			CDTI (pin 33) -- GPIO10 pin 77 * 			CCLK (pin 34) -- GPIO9 pin 76 * 			CSN  (pin 35) -- GPIO8 pin 75 *   		- output data Mode 7 (24bit, I2S, slave) *		- both MCKO1 and MCKO2 of ak4114 are fed to FPGA, which *		  outputs master clock to SPMCLKIN of ice1724. *		  Experimentally I found out that only a combination of *		  OCKS0=1, OCKS1=1 (128fs, 64fs output) and ice1724 - *		  VT1724_MT_I2S_MCLK_128X=0 (256fs input) yields correct *		  sampling rate. That means the the FPGA doubles the *		  MCK01 rate. * *	Copyright (c) 2003 Takashi Iwai <tiwai@suse.de> *      Copyright (c) 2003 Dimitromanolakis Apostolos <apostol@cs.utoronto.ca> *      Copyright (c) 2004 Kouichi ONO <co2b@ceres.dti.ne.jp> * *   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 * */      #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 <sound/core.h>#include "ice1712.h"#include "envy24ht.h"#include "prodigy192.h"#include "stac946x.h"#include <sound/tlv.h>static inline void stac9460_put(struct snd_ice1712 *ice, int reg, unsigned char val){	snd_vt1724_write_i2c(ice, PRODIGY192_STAC9460_ADDR, reg, val);}static inline unsigned char stac9460_get(struct snd_ice1712 *ice, int reg){	return snd_vt1724_read_i2c(ice, PRODIGY192_STAC9460_ADDR, reg);}/* * DAC mute control */#define stac9460_dac_mute_info		snd_ctl_boolean_mono_infostatic int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);	unsigned char val;	int idx;	if (kcontrol->private_value)		idx = STAC946X_MASTER_VOLUME;	else		idx  = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + STAC946X_LF_VOLUME;	val = stac9460_get(ice, idx);	ucontrol->value.integer.value[0] = (~val >> 7) & 0x1;	return 0;}static int stac9460_dac_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);	unsigned char new, old;	int idx;	int change;	if (kcontrol->private_value)		idx = STAC946X_MASTER_VOLUME;	else		idx  = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + STAC946X_LF_VOLUME;	old = stac9460_get(ice, idx);	new = (~ucontrol->value.integer.value[0]<< 7 & 0x80) | (old & ~0x80);	change = (new != old);	if (change)		stac9460_put(ice, idx, new);	return change;}/* * DAC volume attenuation mixer control */static int stac9460_dac_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;	uinfo->count = 1;	uinfo->value.integer.min = 0;			/* mute */	uinfo->value.integer.max = 0x7f;		/* 0dB */	return 0;}static int stac9460_dac_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);	int idx;	unsigned char vol;	if (kcontrol->private_value)		idx = STAC946X_MASTER_VOLUME;	else		idx  = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + STAC946X_LF_VOLUME;	vol = stac9460_get(ice, idx) & 0x7f;	ucontrol->value.integer.value[0] = 0x7f - vol;	return 0;}static int stac9460_dac_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);	int idx;	unsigned char tmp, ovol, nvol;	int change;	if (kcontrol->private_value)		idx = STAC946X_MASTER_VOLUME;	else		idx  = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + STAC946X_LF_VOLUME;	nvol = ucontrol->value.integer.value[0];	tmp = stac9460_get(ice, idx);	ovol = 0x7f - (tmp & 0x7f);	change = (ovol != nvol);	if (change) {		stac9460_put(ice, idx, (0x7f - nvol) | (tmp & 0x80));	}	return change;}/* * ADC mute control */#define stac9460_adc_mute_info		snd_ctl_boolean_stereo_infostatic int stac9460_adc_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);	unsigned char val;	int i;	for (i = 0; i < 2; ++i) {		val = stac9460_get(ice, STAC946X_MIC_L_VOLUME + i);		ucontrol->value.integer.value[i] = ~val>>7 & 0x1;	}	return 0;}static int stac9460_adc_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);	unsigned char new, old;	int i, reg;	int change;	for (i = 0; i < 2; ++i) {		reg = STAC946X_MIC_L_VOLUME + i;		old = stac9460_get(ice, reg);		new = (~ucontrol->value.integer.value[i]<<7&0x80) | (old&~0x80);		change = (new != old);		if (change)			stac9460_put(ice, reg, new);	}	return change;}/* * ADC gain mixer control */static int stac9460_adc_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;	uinfo->count = 2;	uinfo->value.integer.min = 0;		/* 0dB */	uinfo->value.integer.max = 0x0f;	/* 22.5dB */	return 0;}static int stac9460_adc_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);	int i, reg;	unsigned char vol;	for (i = 0; i < 2; ++i) {		reg = STAC946X_MIC_L_VOLUME + i;		vol = stac9460_get(ice, reg) & 0x0f;		ucontrol->value.integer.value[i] = 0x0f - vol;	}	return 0;}static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);	int i, reg;	unsigned char ovol, nvol;	int change;	for (i = 0; i < 2; ++i) {		reg = STAC946X_MIC_L_VOLUME + i;		nvol = ucontrol->value.integer.value[i];		ovol = 0x0f - stac9460_get(ice, reg);		change = ((ovol & 0x0f)  != nvol);		if (change)			stac9460_put(ice, reg, (0x0f - nvol) | (ovol & ~0x0f));	}	return change;}#if 0/* * Headphone Amplifier */static int aureon_set_headphone_amp(struct snd_ice1712 *ice, int enable){	unsigned int tmp, tmp2;	tmp2 = tmp = snd_ice1712_gpio_read(ice);	if (enable)		tmp |= AUREON_HP_SEL;	else		tmp &= ~ AUREON_HP_SEL;	if (tmp != tmp2) {		snd_ice1712_gpio_write(ice, tmp);		return 1;	}	return 0;}static int aureon_get_headphone_amp(struct snd_ice1712 *ice){	unsigned int tmp = snd_ice1712_gpio_read(ice);	return ( tmp & AUREON_HP_SEL )!= 0;}#define aureon_bool_info	snd_ctl_boolean_mono_infostatic int aureon_hpamp_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);	ucontrol->value.integer.value[0] = aureon_get_headphone_amp(ice);	return 0;}static int aureon_hpamp_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);	return aureon_set_headphone_amp(ice,ucontrol->value.integer.value[0]);}/* * Deemphasis */static int aureon_deemp_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);	ucontrol->value.integer.value[0] = (wm_get(ice, WM_DAC_CTRL2) & 0xf) == 0xf;	return 0;}static int aureon_deemp_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);	int temp, temp2;	temp2 = temp = wm_get(ice, WM_DAC_CTRL2);	if (ucontrol->value.integer.value[0])		temp |= 0xf;	else		temp &= ~0xf;	if (temp != temp2) {		wm_put(ice, WM_DAC_CTRL2, temp);		return 1;	}	return 0;}/* * ADC Oversampling */static int aureon_oversampling_info(struct snd_kcontrol *k, struct snd_ctl_elem_info *uinfo){	static char *texts[2] = { "128x", "64x"	};	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;	uinfo->count = 1;	uinfo->value.enumerated.items = 2;	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_oversampling_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);	ucontrol->value.enumerated.item[0] = (wm_get(ice, WM_MASTER) & 0x8) == 0x8;	return 0;}static int aureon_oversampling_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){	int temp, temp2;	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);	temp2 = temp = wm_get(ice, WM_MASTER);	if (ucontrol->value.enumerated.item[0])		temp |= 0x8;	else		temp &= ~0x8;	if (temp != temp2) {		wm_put(ice, WM_MASTER, temp);		return 1;	}	return 0;}#endifstatic int stac9460_mic_sw_info(struct snd_kcontrol *kcontrol,	       			struct snd_ctl_elem_info *uinfo){	static char *texts[2] = { "Line In", "Mic" };	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;	uinfo->count = 1;	uinfo->value.enumerated.items = 2;	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 stac9460_mic_sw_get(struct snd_kcontrol *kcontrol,	       		struct snd_ctl_elem_value *ucontrol){	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);	unsigned char val;			val = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);	ucontrol->value.enumerated.item[0] = (val >> 7) & 0x1;	return 0;}static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol,	       		struct snd_ctl_elem_value *ucontrol){	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);	unsigned char new, old;	int change;	old = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);	new = (ucontrol->value.enumerated.item[0] << 7 & 0x80) | (old & ~0x80);	change = (new != old);	if (change)		stac9460_put(ice, STAC946X_GENERAL_PURPOSE, new);	return change;}static const DECLARE_TLV_DB_SCALE(db_scale_dac, -19125, 75, 0);static const DECLARE_TLV_DB_SCALE(db_scale_adc, 0, 150, 0);/* * mixers */static struct snd_kcontrol_new stac_controls[] __devinitdata = {	{		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,		.name = "Master Playback Switch",		.info = stac9460_dac_mute_info,		.get = stac9460_dac_mute_get,		.put = stac9460_dac_mute_put,		.private_value = 1,		.tlv = { .p = db_scale_dac }	},	{		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |

⌨️ 快捷键说明

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