📄 aureon.c
字号:
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 || ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71XT) { 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); tmp |= AUREON_SPI_CLK; snd_ice1712_gpio_write(ice, tmp); udelay(1); tmp &= ~AUREON_SPI_CLK; snd_ice1712_gpio_write(ice, tmp); udelay(1); } for (j=0; j<size; j++) { unsigned char outdata = 0; for (i=7; i>=0; i--) { tmp = snd_ice1712_gpio_read(ice); outdata <<= 1; outdata |= (tmp & AUREON_SPI_MISO) ? 1 : 0; udelay(1); tmp |= AUREON_SPI_CLK; snd_ice1712_gpio_write(ice, tmp); udelay(1); tmp &= ~AUREON_SPI_CLK; snd_ice1712_gpio_write(ice, tmp); udelay(1); } buffer[j] = outdata; } tmp |= cs; snd_ice1712_gpio_write(ice, tmp);}static unsigned char aureon_cs8415_get(struct snd_ice1712 *ice, int reg) { unsigned char val; aureon_spi_write(ice, AUREON_CS8415_CS, 0x2000 | reg, 16); aureon_spi_read(ice, AUREON_CS8415_CS, 0x21, 8, &val, 1); return val;}static void aureon_cs8415_read(struct snd_ice1712 *ice, int reg, unsigned char *buffer, int size) { aureon_spi_write(ice, AUREON_CS8415_CS, 0x2000 | reg, 16); aureon_spi_read(ice, AUREON_CS8415_CS, 0x21, 8, buffer, size);}static void aureon_cs8415_put(struct snd_ice1712 *ice, int reg, unsigned char val) { aureon_spi_write(ice, AUREON_CS8415_CS, 0x200000 | (reg << 8) | val, 24);}/* * get the current register value of WM codec */static unsigned short wm_get(struct snd_ice1712 *ice, int reg){ reg <<= 1; return ((unsigned short)ice->akm[0].images[reg] << 8) | ice->akm[0].images[reg + 1];}/* * set the register value of WM codec */static void wm_put_nocache(struct snd_ice1712 *ice, int reg, unsigned short val){ aureon_spi_write(ice, ((ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71LT || ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71XT) ? PRODIGY_WM_CS : AUREON_WM_CS), (reg << 9) | (val & 0x1ff), 16);}/* * set the register value of WM codec and remember it */static void wm_put(struct snd_ice1712 *ice, int reg, unsigned short val){ wm_put_nocache(ice, reg, val); reg <<= 1; ice->akm[0].images[reg] = val >> 8; ice->akm[0].images[reg + 1] = val;}/* */#define aureon_mono_bool_info snd_ctl_boolean_mono_info/* * AC'97 master playback mute controls (Mute on WM8770 chip) */#define aureon_ac97_mmute_info snd_ctl_boolean_mono_infostatic int aureon_ac97_mmute_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] = (wm_get(ice, WM_OUT_MUX1) >> 1) & 0x01; mutex_unlock(&ice->gpio_mutex); return 0;}static int aureon_ac97_mmute_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 = wm_get(ice, WM_OUT_MUX1); nvol = (ovol & ~0x02) | (ucontrol->value.integer.value[0] ? 0x02 : 0x00); if ((change = (ovol != nvol))) wm_put(ice, WM_OUT_MUX1, nvol); snd_ice1712_restore_gpio_status(ice); return change;}static const DECLARE_TLV_DB_SCALE(db_scale_wm_dac, -12700, 100, 1);static const DECLARE_TLV_DB_SCALE(db_scale_wm_pcm, -6400, 50, 1);static const DECLARE_TLV_DB_SCALE(db_scale_wm_adc, -1200, 100, 0);static const DECLARE_TLV_DB_SCALE(db_scale_ac97_master, -4650, 150, 0);static const DECLARE_TLV_DB_SCALE(db_scale_ac97_gain, -3450, 150, 0);/* * Logarithmic volume values for WM8770 * Computed as 20 * Log10(255 / x) */static const unsigned char wm_vol[256] = { 127, 48, 42, 39, 36, 34, 33, 31, 30, 29, 28, 27, 27, 26, 25, 25, 24, 24, 23, 23, 22, 22, 21, 21, 21, 20, 20, 20, 19, 19, 19, 18, 18, 18, 18, 17, 17, 17, 17, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};#define WM_VOL_MAX (sizeof(wm_vol) - 1)#define WM_VOL_MUTE 0x8000static void wm_set_vol(struct snd_ice1712 *ice, unsigned int index, unsigned short vol, unsigned short master){ unsigned char nvol; if ((master & WM_VOL_MUTE) || (vol & WM_VOL_MUTE)) nvol = 0; else nvol = 127 - wm_vol[(((vol & ~WM_VOL_MUTE) * (master & ~WM_VOL_MUTE)) / 127) & WM_VOL_MAX]; wm_put(ice, index, nvol); wm_put_nocache(ice, index, 0x180 | nvol);}/* * DAC mute control */#define wm_pcm_mute_info snd_ctl_boolean_mono_infostatic int wm_pcm_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] = (wm_get(ice, WM_MUTE) & 0x10) ? 0 : 1; mutex_unlock(&ice->gpio_mutex); return 0;}static int wm_pcm_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); unsigned short nval, oval; int change; snd_ice1712_save_gpio_status(ice); oval = wm_get(ice, WM_MUTE); nval = (oval & ~0x10) | (ucontrol->value.integer.value[0] ? 0 : 0x10); if ((change = (nval != oval))) wm_put(ice, WM_MUTE, nval); snd_ice1712_restore_gpio_status(ice); return change;}/* * Master volume attenuation mixer control */static int wm_master_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; uinfo->value.integer.max = WM_VOL_MAX; return 0;}static int wm_master_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); int i; for (i=0; i<2; i++) ucontrol->value.integer.value[i] = ice->spec.aureon.master[i] & ~WM_VOL_MUTE; return 0;}static int wm_master_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); int ch, change = 0; snd_ice1712_save_gpio_status(ice); for (ch = 0; ch < 2; ch++) { if (ucontrol->value.integer.value[ch] != ice->spec.aureon.master[ch]) { int dac; ice->spec.aureon.master[ch] &= WM_VOL_MUTE; ice->spec.aureon.master[ch] |= ucontrol->value.integer.value[ch]; for (dac = 0; dac < ice->num_total_dacs; dac += 2) wm_set_vol(ice, WM_DAC_ATTEN + dac + ch, ice->spec.aureon.vol[dac + ch], ice->spec.aureon.master[ch]); change = 1; } } snd_ice1712_restore_gpio_status(ice); return change;}/* * DAC volume attenuation mixer control */static int wm_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){ int voices = kcontrol->private_value >> 8; uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = voices; uinfo->value.integer.min = 0; /* mute (-101dB) */ uinfo->value.integer.max = 0x7F; /* 0dB */ return 0;}static int wm_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); int i, ofs, voices; voices = kcontrol->private_value >> 8; ofs = kcontrol->private_value & 0xff; for (i = 0; i < voices; i++) ucontrol->value.integer.value[i] = ice->spec.aureon.vol[ofs+i] & ~WM_VOL_MUTE; return 0;}static int wm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); int i, idx, ofs, voices; int change = 0; voices = kcontrol->private_value >> 8; ofs = kcontrol->private_value & 0xff; snd_ice1712_save_gpio_status(ice); for (i = 0; i < voices; i++) { idx = WM_DAC_ATTEN + ofs + i; if (ucontrol->value.integer.value[i] != ice->spec.aureon.vol[ofs+i]) { ice->spec.aureon.vol[ofs+i] &= WM_VOL_MUTE; ice->spec.aureon.vol[ofs+i] |= ucontrol->value.integer.value[i]; wm_set_vol(ice, idx, ice->spec.aureon.vol[ofs+i], ice->spec.aureon.master[i]); change = 1; } } snd_ice1712_restore_gpio_status(ice); return change;}/* * WM8770 mute control */static int wm_mute_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = kcontrol->private_value >> 8; uinfo->value.integer.min = 0; uinfo->value.integer.max = 1; return 0;}static int wm_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); int voices, ofs, i; voices = kcontrol->private_value >> 8; ofs = kcontrol->private_value & 0xFF; for (i = 0; i < voices; i++) ucontrol->value.integer.value[i] = (ice->spec.aureon.vol[ofs+i] & WM_VOL_MUTE) ? 0 : 1; return 0;}static int wm_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); int change = 0, voices, ofs, i; voices = kcontrol->private_value >> 8; ofs = kcontrol->private_value & 0xFF; snd_ice1712_save_gpio_status(ice); for (i = 0; i < voices; i++) { int val = (ice->spec.aureon.vol[ofs + i] & WM_VOL_MUTE) ? 0 : 1; if (ucontrol->value.integer.value[i] != val) { ice->spec.aureon.vol[ofs + i] &= ~WM_VOL_MUTE; ice->spec.aureon.vol[ofs + i] |= ucontrol->value.integer.value[i] ? 0 : WM_VOL_MUTE; wm_set_vol(ice, ofs + i, ice->spec.aureon.vol[ofs + i], ice->spec.aureon.master[i]); change = 1; } } snd_ice1712_restore_gpio_status(ice); return change;}/* * WM8770 master mute control */#define wm_master_mute_info snd_ctl_boolean_stereo_infostatic int wm_master_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -