📄 aureon.c
字号:
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 ? 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;}/* */static int aureon_mono_bool_info(struct snd_kcontrol *k, struct snd_ctl_elem_info *uinfo){ uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = 1; uinfo->value.integer.min = 0; uinfo->value.integer.max = 1; return 0;}/* * AC'97 master playback mute controls (Mute on WM8770 chip) */#define aureon_ac97_mmute_info aureon_mono_bool_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;}/* * Logarithmic volume values for WM8770 * Computed as 20 * Log10(255 / x) */static 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 aureon_mono_bool_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 */static int wm_master_mute_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = 2; uinfo->value.integer.min = 0; uinfo->value.integer.max = 1; return 0;}static int wm_master_mute_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.master[0] & WM_VOL_MUTE) ? 0 : 1; ucontrol->value.integer.value[1] = (ice->spec.aureon.master[1] & WM_VOL_MUTE) ? 0 : 1; return 0;}static int wm_master_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); int change = 0, i; snd_ice1712_save_gpio_status(ice); for (i = 0; i < 2; i++) { int val = (ice->spec.aureon.master[i] & WM_VOL_MUTE) ? 0 : 1; if (ucontrol->value.integer.value[i] != val) { int dac; ice->spec.aureon.master[i] &= ~WM_VOL_MUTE; ice->spec.aureon.master[i] |= ucontrol->value.integer.value[i] ? 0 : WM_VOL_MUTE; for (dac = 0; dac < ice->num_total_dacs; dac += 2) wm_set_vol(ice, WM_DAC_ATTEN + dac + i, ice->spec.aureon.vol[dac + i], ice->spec.aureon.master[i]); change = 1; } } snd_ice1712_restore_gpio_status(ice); return change;}/* digital master volume */#define PCM_0dB 0xff#define PCM_RES 128 /* -64dB */#define PCM_MIN (PCM_0dB - PCM_RES)static int wm_pcm_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 (-64dB) */ uinfo->value.integer.max = PCM_RES; /* 0dB */ return 0;}static int wm_pcm_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); unsigned short val; mutex_lock(&ice->gpio_mutex); val = wm_get(ice, WM_DAC_DIG_MASTER_ATTEN) & 0xff; val = val > PCM_MIN ? (val - PCM_MIN) : 0; ucontrol->value.integer.value[0] = val; mutex_unlock(&ice->gpio_mutex); return 0;}static int wm_pcm_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 = 0; snd_ice1712_save_gpio_status(ice); nvol = ucontrol->value.integer.value[0]; nvol = (nvol ? (nvol + PCM_MIN) : 0) & 0xff; ovol = wm_get(ice, WM_DAC_DIG_MASTER_ATTEN) & 0xff; if (ovol != nvol) { wm_put(ice, WM_DAC_DIG_MASTER_ATTEN, nvol); /* prelatch */ wm_put_nocache(ice, WM_DAC_DIG_MASTER_ATTEN, nvol | 0x100); /* update */ change = 1; } snd_ice1712_restore_gpio_status(ice); return change;}/* * ADC mute control */static int wm_adc_mute_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){ uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = 2; uinfo->value.integer.min = 0; uinfo->value.integer.max = 1; return 0;}static int wm_adc_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); unsigned short val; int i; mutex_lock(&ice->gpio_mutex); for (i = 0; i < 2; i++) { val = wm_get(ice, WM_ADC_GAIN + i); ucontrol->value.integer.value[i] = ~val>>5 & 0x1; } mutex_unlock(&ice->gpio_mutex); return 0;}static int wm_adc_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); unsigned short new, old; int i, change = 0; snd_ice1712_save_gpio_status(ice); for (i = 0; i < 2; i++) { old = wm_get(ice, WM_ADC_GAIN + i); new = (~ucontrol->value.integer.value[i]<<5&0x20) | (old&~0x20); if (new != old) { wm_put(ice, WM_ADC_GAIN + i, new); change = 1; } } snd_ice1712_restore_gpio_status(ice); return change;}/* * ADC gain mixer control */static int wm_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; /* -12dB */ uinfo->value.integer.max = 0x1f; /* 19dB */ return 0;}static int wm_adc_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); int i, idx; unsigned short vol; mutex_lock(&ice->gpio_mutex); for (i = 0; i < 2; i++) { idx = WM_ADC_GAIN + i; vol = wm_get(ice, idx) & 0x1f; ucontrol->value.integer.value[i] = vol; } mutex_unlock(&ice->gpio_mutex); return 0;}static int wm_adc_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); int i, idx; unsigned short ovol, nvol; int change = 0; snd_ice1712_save_gpio_status(ice); for (i = 0; i < 2; i++) { idx = WM_ADC_GAIN + i; nvol = ucontrol->value.integer.value[i]; ovol = wm_get(ice, idx); if ((ovol & 0x1f) != nvol) { wm_put(ice, idx, nvol | (ovol & ~0x1f)); change = 1; } } snd_ice1712_restore_gpio_status(ice); return change;}/* * ADC input mux mixer control */static int wm_adc_mux_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){ static char *texts[] = { "CD", //AIN1 "Aux", //AIN2 "Line", //AIN3 "Mic", //AIN4 "AC97" //AIN5 }; static char *universe_texts[] = { "Aux1", //AIN1 "CD", //AIN2 "Phono", //AIN3 "Line", //AIN4 "Aux2", //AIN5 "Mic", //AIN6 "Aux3", //AIN7 "AC97" //AIN8 };
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -