Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 230326
b: refs/heads/master
c: dd31b31
h: refs/heads/master
v: v3
  • Loading branch information
Mark Brown committed Dec 2, 2010
1 parent 3ada12a commit 45f7a2a
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 6 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 59f7297014b7e96779493f132eed04a3d44565df
refs/heads/master: dd31b310b9104327fb6bf7d2fe3b0f0f6fde4dd7
76 changes: 71 additions & 5 deletions trunk/sound/soc/codecs/wm8731.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ struct wm8731_priv {
u16 reg_cache[WM8731_CACHEREGNUM];
unsigned int sysclk;
int sysclk_type;
int playback_fs;
bool deemph;
};


Expand All @@ -65,14 +67,73 @@ static const u16 wm8731_reg[WM8731_CACHEREGNUM] = {

static const char *wm8731_input_select[] = {"Line In", "Mic"};

static const char *wm8731_deemph[] = {"None", "32Khz", "44.1Khz", "48Khz"};

static const struct soc_enum wm8731_insel_enum =
SOC_ENUM_SINGLE(WM8731_APANA, 2, 2, wm8731_input_select);

static const struct soc_enum wm8731_deemph_enum =
SOC_ENUM_SINGLE(WM8731_APDIGI, 1, 4, wm8731_deemph);
static int wm8731_deemph[] = { 0, 32000, 44100, 48000 };

static int wm8731_set_deemph(struct snd_soc_codec *codec)
{
struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
int val, i, best;

/* If we're using deemphasis select the nearest available sample
* rate.
*/
if (wm8731->deemph) {
best = 1;
for (i = 2; i < ARRAY_SIZE(wm8731_deemph); i++) {
if (abs(wm8731_deemph[i] - wm8731->playback_fs) <
abs(wm8731_deemph[best] - wm8731->playback_fs))
best = i;
}

val = best << 1;
} else {
best = 0;
val = 0;
}

dev_dbg(codec->dev, "Set deemphasis %d (%dHz)\n",
best, wm8731_deemph[best]);

return snd_soc_update_bits(codec, WM8731_APDIGI, 0x6, val);
}

static int wm8731_get_deemph(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);

ucontrol->value.enumerated.item[0] = wm8731->deemph;

return 0;
}

static int wm8731_put_deemph(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
int deemph = ucontrol->value.enumerated.item[0];
int ret = 0;

if (deemph > 1)
return -EINVAL;

mutex_lock(&codec->mutex);
if (wm8731->deemph != deemph) {
wm8731->deemph = deemph;

wm8731_set_deemph(codec);

ret = 1;
}
mutex_unlock(&codec->mutex);

return ret;
}

static const DECLARE_TLV_DB_SCALE(in_tlv, -3450, 150, 0);
static const DECLARE_TLV_DB_SCALE(sidetone_tlv, -1500, 300, 0);
Expand All @@ -99,7 +160,8 @@ SOC_SINGLE_TLV("Sidetone Playback Volume", WM8731_APANA, 6, 3, 1,
SOC_SINGLE("ADC High Pass Filter Switch", WM8731_APDIGI, 0, 1, 1),
SOC_SINGLE("Store DC Offset Switch", WM8731_APDIGI, 4, 1, 0),

SOC_ENUM("Playback De-emphasis", wm8731_deemph_enum),
SOC_SINGLE_BOOL_EXT("Playback Deemphasis Switch", 0,
wm8731_get_deemph, wm8731_put_deemph),
};

/* Output Mixer */
Expand Down Expand Up @@ -243,6 +305,8 @@ static int wm8731_hw_params(struct snd_pcm_substream *substream,
u16 srate = (coeff_div[i].sr << 2) |
(coeff_div[i].bosr << 1) | coeff_div[i].usb;

wm8731->playback_fs = params_rate(params);

snd_soc_write(codec, WM8731_SRATE, srate);

/* bit size */
Expand All @@ -257,6 +321,8 @@ static int wm8731_hw_params(struct snd_pcm_substream *substream,
break;
}

wm8731_set_deemph(codec);

snd_soc_write(codec, WM8731_IFACE, iface);
return 0;
}
Expand Down

0 comments on commit 45f7a2a

Please sign in to comment.