Skip to content

Commit 781c7b9

Browse files
committed
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: Takashi Iwai <tiwai@suse.de>
1 parent 96d2bd6 commit 781c7b9

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

sound/pci/hda/hda_codec.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,11 +2148,10 @@ EXPORT_SYMBOL_GPL(snd_hda_codec_amp_read);
21482148

21492149
static int codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
21502150
int direction, int idx, int mask, int val,
2151-
bool init_only)
2151+
bool init_only, bool cache_only)
21522152
{
21532153
struct hda_amp_info *info;
21542154
unsigned int caps;
2155-
unsigned int cache_only;
21562155

21572156
if (snd_BUG_ON(mask & ~0xff))
21582157
mask &= 0xff;
@@ -2170,7 +2169,7 @@ static int codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
21702169
return 0;
21712170
}
21722171
info->vol[ch] = val;
2173-
cache_only = info->head.dirty = codec->cached_write;
2172+
info->head.dirty |= cache_only;
21742173
caps = info->amp_caps;
21752174
mutex_unlock(&codec->hash_mutex);
21762175
if (!cache_only)
@@ -2194,7 +2193,8 @@ static int codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
21942193
int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
21952194
int direction, int idx, int mask, int val)
21962195
{
2197-
return codec_amp_update(codec, nid, ch, direction, idx, mask, val, false);
2196+
return codec_amp_update(codec, nid, ch, direction, idx, mask, val,
2197+
false, codec->cached_write);
21982198
}
21992199
EXPORT_SYMBOL_GPL(snd_hda_codec_amp_update);
22002200

@@ -2241,7 +2241,8 @@ EXPORT_SYMBOL_GPL(snd_hda_codec_amp_stereo);
22412241
int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch,
22422242
int dir, int idx, int mask, int val)
22432243
{
2244-
return codec_amp_update(codec, nid, ch, dir, idx, mask, val, true);
2244+
return codec_amp_update(codec, nid, ch, dir, idx, mask, val, true,
2245+
codec->cached_write);
22452246
}
22462247
EXPORT_SYMBOL_GPL(snd_hda_codec_amp_init);
22472248

@@ -2383,8 +2384,8 @@ update_amp_value(struct hda_codec *codec, hda_nid_t nid,
23832384
maxval = get_amp_max_value(codec, nid, dir, 0);
23842385
if (val > maxval)
23852386
val = maxval;
2386-
return snd_hda_codec_amp_update(codec, nid, ch, dir, idx,
2387-
HDA_AMP_VOLMASK, val);
2387+
return codec_amp_update(codec, nid, ch, dir, idx, HDA_AMP_VOLMASK, val,
2388+
false, !hda_codec_is_power_on(codec));
23882389
}
23892390

23902391
/**
@@ -2434,14 +2435,12 @@ int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
24342435
long *valp = ucontrol->value.integer.value;
24352436
int change = 0;
24362437

2437-
snd_hda_power_up(codec);
24382438
if (chs & 1) {
24392439
change = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp);
24402440
valp++;
24412441
}
24422442
if (chs & 2)
24432443
change |= update_amp_value(codec, nid, 1, dir, idx, ofs, *valp);
2444-
snd_hda_power_down(codec);
24452444
return change;
24462445
}
24472446
EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_volume_put);
@@ -3109,19 +3108,19 @@ int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
31093108
long *valp = ucontrol->value.integer.value;
31103109
int change = 0;
31113110

3112-
snd_hda_power_up(codec);
31133111
if (chs & 1) {
3114-
change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx,
3115-
HDA_AMP_MUTE,
3116-
*valp ? 0 : HDA_AMP_MUTE);
3112+
change = codec_amp_update(codec, nid, 0, dir, idx,
3113+
HDA_AMP_MUTE,
3114+
*valp ? 0 : HDA_AMP_MUTE, false,
3115+
!hda_codec_is_power_on(codec));
31173116
valp++;
31183117
}
31193118
if (chs & 2)
3120-
change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx,
3121-
HDA_AMP_MUTE,
3122-
*valp ? 0 : HDA_AMP_MUTE);
3119+
change |= codec_amp_update(codec, nid, 1, dir, idx,
3120+
HDA_AMP_MUTE,
3121+
*valp ? 0 : HDA_AMP_MUTE, false,
3122+
!hda_codec_is_power_on(codec));
31233123
hda_call_check_power_status(codec, nid);
3124-
snd_hda_power_down(codec);
31253124
return change;
31263125
}
31273126
EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_switch_put);

0 commit comments

Comments
 (0)