Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 206583
b: refs/heads/master
c: afd6d36
h: refs/heads/master
i:
  206581: 0443c9e
  206579: 05d0bba
  206575: edeaf62
v: v3
  • Loading branch information
Mark Brown committed Jul 5, 2010
1 parent b2f6d19 commit a0f4f31
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 4faaa8d968df08bf2e75a481f99e7c5c1d0142ab
refs/heads/master: afd6d36a0ded1691c6710ebddabae06e5bb9583b
64 changes: 64 additions & 0 deletions trunk/sound/soc/codecs/wm8960.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ struct wm8960_priv {
struct snd_soc_dapm_widget *lout1;
struct snd_soc_dapm_widget *rout1;
struct snd_soc_dapm_widget *out3;
bool deemph;
int playback_fs;
};

#define wm8960_reset(c) snd_soc_write(c, WM8960_RESET, 0)
Expand All @@ -100,6 +102,59 @@ static const struct soc_enum wm8960_enum[] = {
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(dac_tlv, -12700, 50, 1);
static const DECLARE_TLV_DB_SCALE(bypass_tlv, -2100, 300, 0);
Expand Down Expand Up @@ -133,6 +188,8 @@ SOC_ENUM("ADC Polarity", wm8960_enum[0]),
SOC_SINGLE("ADC High Pass Filter Switch", WM8960_DACCTL1, 0, 1, 0),

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 Lower Cut-Off", wm8960_enum[3]),
Expand Down Expand Up @@ -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_device *socdev = rtd->socdev;
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;

/* bit size */
Expand All @@ -451,6 +509,12 @@ static int wm8960_hw_params(struct snd_pcm_substream *substream,
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 */
snd_soc_write(codec, WM8960_IFACE1, iface);
return 0;
Expand Down

0 comments on commit a0f4f31

Please sign in to comment.