Commit 781c7b96 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: hda - Avoid unnecessary power-up at mixer amp changes

When the mixer amp is touched by control elements, we don't have to
power up always; if the codec was suspended at the time, we can just
update the amp cache and it's reflected to the hardware upon resume.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 96d2bd6e
...@@ -2148,11 +2148,10 @@ EXPORT_SYMBOL_GPL(snd_hda_codec_amp_read); ...@@ -2148,11 +2148,10 @@ EXPORT_SYMBOL_GPL(snd_hda_codec_amp_read);
static int codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, static int codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
int direction, int idx, int mask, int val, int direction, int idx, int mask, int val,
bool init_only) bool init_only, bool cache_only)
{ {
struct hda_amp_info *info; struct hda_amp_info *info;
unsigned int caps; unsigned int caps;
unsigned int cache_only;
if (snd_BUG_ON(mask & ~0xff)) if (snd_BUG_ON(mask & ~0xff))
mask &= 0xff; mask &= 0xff;
...@@ -2170,7 +2169,7 @@ static int codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, ...@@ -2170,7 +2169,7 @@ static int codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
return 0; return 0;
} }
info->vol[ch] = val; info->vol[ch] = val;
cache_only = info->head.dirty = codec->cached_write; info->head.dirty |= cache_only;
caps = info->amp_caps; caps = info->amp_caps;
mutex_unlock(&codec->hash_mutex); mutex_unlock(&codec->hash_mutex);
if (!cache_only) if (!cache_only)
...@@ -2194,7 +2193,8 @@ static int codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, ...@@ -2194,7 +2193,8 @@ static int codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch, int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
int direction, int idx, int mask, int val) int direction, int idx, int mask, int val)
{ {
return codec_amp_update(codec, nid, ch, direction, idx, mask, val, false); return codec_amp_update(codec, nid, ch, direction, idx, mask, val,
false, codec->cached_write);
} }
EXPORT_SYMBOL_GPL(snd_hda_codec_amp_update); EXPORT_SYMBOL_GPL(snd_hda_codec_amp_update);
...@@ -2241,7 +2241,8 @@ EXPORT_SYMBOL_GPL(snd_hda_codec_amp_stereo); ...@@ -2241,7 +2241,8 @@ EXPORT_SYMBOL_GPL(snd_hda_codec_amp_stereo);
int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch, int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch,
int dir, int idx, int mask, int val) int dir, int idx, int mask, int val)
{ {
return codec_amp_update(codec, nid, ch, dir, idx, mask, val, true); return codec_amp_update(codec, nid, ch, dir, idx, mask, val, true,
codec->cached_write);
} }
EXPORT_SYMBOL_GPL(snd_hda_codec_amp_init); EXPORT_SYMBOL_GPL(snd_hda_codec_amp_init);
...@@ -2383,8 +2384,8 @@ update_amp_value(struct hda_codec *codec, hda_nid_t nid, ...@@ -2383,8 +2384,8 @@ update_amp_value(struct hda_codec *codec, hda_nid_t nid,
maxval = get_amp_max_value(codec, nid, dir, 0); maxval = get_amp_max_value(codec, nid, dir, 0);
if (val > maxval) if (val > maxval)
val = maxval; val = maxval;
return snd_hda_codec_amp_update(codec, nid, ch, dir, idx, return codec_amp_update(codec, nid, ch, dir, idx, HDA_AMP_VOLMASK, val,
HDA_AMP_VOLMASK, val); false, !hda_codec_is_power_on(codec));
} }
/** /**
...@@ -2434,14 +2435,12 @@ int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol, ...@@ -2434,14 +2435,12 @@ int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
long *valp = ucontrol->value.integer.value; long *valp = ucontrol->value.integer.value;
int change = 0; int change = 0;
snd_hda_power_up(codec);
if (chs & 1) { if (chs & 1) {
change = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp); change = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp);
valp++; valp++;
} }
if (chs & 2) if (chs & 2)
change |= update_amp_value(codec, nid, 1, dir, idx, ofs, *valp); change |= update_amp_value(codec, nid, 1, dir, idx, ofs, *valp);
snd_hda_power_down(codec);
return change; return change;
} }
EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_volume_put); EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_volume_put);
...@@ -3109,19 +3108,19 @@ int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol, ...@@ -3109,19 +3108,19 @@ int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
long *valp = ucontrol->value.integer.value; long *valp = ucontrol->value.integer.value;
int change = 0; int change = 0;
snd_hda_power_up(codec);
if (chs & 1) { if (chs & 1) {
change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx, change = codec_amp_update(codec, nid, 0, dir, idx,
HDA_AMP_MUTE, HDA_AMP_MUTE,
*valp ? 0 : HDA_AMP_MUTE); *valp ? 0 : HDA_AMP_MUTE, false,
!hda_codec_is_power_on(codec));
valp++; valp++;
} }
if (chs & 2) if (chs & 2)
change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx, change |= codec_amp_update(codec, nid, 1, dir, idx,
HDA_AMP_MUTE, HDA_AMP_MUTE,
*valp ? 0 : HDA_AMP_MUTE); *valp ? 0 : HDA_AMP_MUTE, false,
!hda_codec_is_power_on(codec));
hda_call_check_power_status(codec, nid); hda_call_check_power_status(codec, nid);
snd_hda_power_down(codec);
return change; return change;
} }
EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_switch_put); EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_switch_put);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment