ASoC: Automatically manage DAC deemphasis rate for WM8960
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
This commit is contained in:
parent
4faaa8d968
commit
afd6d36a0d
1 changed files with 64 additions and 0 deletions
|
@ -79,6 +79,8 @@ struct wm8960_priv {
|
||||||
struct snd_soc_dapm_widget *lout1;
|
struct snd_soc_dapm_widget *lout1;
|
||||||
struct snd_soc_dapm_widget *rout1;
|
struct snd_soc_dapm_widget *rout1;
|
||||||
struct snd_soc_dapm_widget *out3;
|
struct snd_soc_dapm_widget *out3;
|
||||||
|
bool deemph;
|
||||||
|
int playback_fs;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define wm8960_reset(c) snd_soc_write(c, WM8960_RESET, 0)
|
#define wm8960_reset(c) snd_soc_write(c, WM8960_RESET, 0)
|
||||||
|
@ -100,6 +102,59 @@ static const struct soc_enum wm8960_enum[] = {
|
||||||
SOC_ENUM_SINGLE(WM8960_ALC3, 8, 2, wm8960_alcmode),
|
SOC_ENUM_SINGLE(WM8960_ALC3, 8, 2, wm8960_alcmode),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const int deemph_settings[] = { 0, 32000, 44100, 48000 };
|
||||||
|
|
||||||
|
static int wm8960_set_deemph(struct snd_soc_codec *codec)
|
||||||
|
{
|
||||||
|
struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
|
||||||
|
int val, i, best;
|
||||||
|
|
||||||
|
/* If we're using deemphasis select the nearest available sample
|
||||||
|
* rate.
|
||||||
|
*/
|
||||||
|
if (wm8960->deemph) {
|
||||||
|
best = 1;
|
||||||
|
for (i = 2; i < ARRAY_SIZE(deemph_settings); i++) {
|
||||||
|
if (abs(deemph_settings[i] - wm8960->playback_fs) <
|
||||||
|
abs(deemph_settings[best] - wm8960->playback_fs))
|
||||||
|
best = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
val = best << 1;
|
||||||
|
} else {
|
||||||
|
val = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
dev_dbg(codec->dev, "Set deemphasis %d\n", val);
|
||||||
|
|
||||||
|
return snd_soc_update_bits(codec, WM8960_DACCTL1,
|
||||||
|
0x6, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int wm8960_get_deemph(struct snd_kcontrol *kcontrol,
|
||||||
|
struct snd_ctl_elem_value *ucontrol)
|
||||||
|
{
|
||||||
|
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
|
||||||
|
struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
|
||||||
|
|
||||||
|
return wm8960->deemph;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int wm8960_put_deemph(struct snd_kcontrol *kcontrol,
|
||||||
|
struct snd_ctl_elem_value *ucontrol)
|
||||||
|
{
|
||||||
|
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
|
||||||
|
struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
|
||||||
|
int deemph = ucontrol->value.enumerated.item[0];
|
||||||
|
|
||||||
|
if (deemph > 1)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
wm8960->deemph = deemph;
|
||||||
|
|
||||||
|
return wm8960_set_deemph(codec);
|
||||||
|
}
|
||||||
|
|
||||||
static const DECLARE_TLV_DB_SCALE(adc_tlv, -9700, 50, 0);
|
static const DECLARE_TLV_DB_SCALE(adc_tlv, -9700, 50, 0);
|
||||||
static const DECLARE_TLV_DB_SCALE(dac_tlv, -12700, 50, 1);
|
static const DECLARE_TLV_DB_SCALE(dac_tlv, -12700, 50, 1);
|
||||||
static const DECLARE_TLV_DB_SCALE(bypass_tlv, -2100, 300, 0);
|
static const DECLARE_TLV_DB_SCALE(bypass_tlv, -2100, 300, 0);
|
||||||
|
@ -133,6 +188,8 @@ SOC_ENUM("ADC Polarity", wm8960_enum[0]),
|
||||||
SOC_SINGLE("ADC High Pass Filter Switch", WM8960_DACCTL1, 0, 1, 0),
|
SOC_SINGLE("ADC High Pass Filter Switch", WM8960_DACCTL1, 0, 1, 0),
|
||||||
|
|
||||||
SOC_ENUM("DAC Polarity", wm8960_enum[2]),
|
SOC_ENUM("DAC Polarity", wm8960_enum[2]),
|
||||||
|
SOC_SINGLE_BOOL_EXT("DAC Deemphasis Switch", 0,
|
||||||
|
wm8960_get_deemph, wm8960_put_deemph),
|
||||||
|
|
||||||
SOC_ENUM("3D Filter Upper Cut-Off", wm8960_enum[2]),
|
SOC_ENUM("3D Filter Upper Cut-Off", wm8960_enum[2]),
|
||||||
SOC_ENUM("3D Filter Lower Cut-Off", wm8960_enum[3]),
|
SOC_ENUM("3D Filter Lower Cut-Off", wm8960_enum[3]),
|
||||||
|
@ -437,6 +494,7 @@ static int wm8960_hw_params(struct snd_pcm_substream *substream,
|
||||||
struct snd_soc_pcm_runtime *rtd = substream->private_data;
|
struct snd_soc_pcm_runtime *rtd = substream->private_data;
|
||||||
struct snd_soc_device *socdev = rtd->socdev;
|
struct snd_soc_device *socdev = rtd->socdev;
|
||||||
struct snd_soc_codec *codec = socdev->card->codec;
|
struct snd_soc_codec *codec = socdev->card->codec;
|
||||||
|
struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
|
||||||
u16 iface = snd_soc_read(codec, WM8960_IFACE1) & 0xfff3;
|
u16 iface = snd_soc_read(codec, WM8960_IFACE1) & 0xfff3;
|
||||||
|
|
||||||
/* bit size */
|
/* bit size */
|
||||||
|
@ -451,6 +509,12 @@ static int wm8960_hw_params(struct snd_pcm_substream *substream,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Update filters for the new rate */
|
||||||
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
|
||||||
|
wm8960->playback_fs = params_rate(params);
|
||||||
|
wm8960_set_deemph(codec);
|
||||||
|
}
|
||||||
|
|
||||||
/* set iface */
|
/* set iface */
|
||||||
snd_soc_write(codec, WM8960_IFACE1, iface);
|
snd_soc_write(codec, WM8960_IFACE1, iface);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue