Skip to content

Commit

Permalink
ALSA: hda - Consolidate cap_sync_hook and capture_switch_hook
Browse files Browse the repository at this point in the history
Two hooks in hda_gen_spec, cap_sync_hook and capture_switch_hook, play
very similar roles.  The only differences are that the former is
called more often (e.g. at init or switching capsrc) while the latter
can take an on/off argument.

As a more generic implementation, consolidate these two hooks, and
pass snd_ctl_elem_value pointer as the second argument.  If the
secondary argument is non-NULL, it can take the on/off value, so the
caller handles it like the former capture_switch_hook.  If it's NULL,
it's called in the init or capsrc switch case.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
Takashi Iwai committed Jan 18, 2013
1 parent a35bd1e commit a90229e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 33 deletions.
34 changes: 9 additions & 25 deletions sound/pci/hda/hda_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -2738,7 +2738,7 @@ static int cap_put_caller(struct snd_kcontrol *kcontrol,
mutex_unlock(&codec->control_mutex);
snd_hda_codec_flush_amp_cache(codec); /* flush the updates */
if (err >= 0 && spec->cap_sync_hook)
spec->cap_sync_hook(codec);
spec->cap_sync_hook(codec, ucontrol);
return err;
}

Expand Down Expand Up @@ -2774,23 +2774,9 @@ static const struct snd_kcontrol_new cap_vol_temp = {
static int cap_sw_put(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
struct hda_gen_spec *spec = codec->spec;
int ret;

ret = cap_put_caller(kcontrol, ucontrol,
return cap_put_caller(kcontrol, ucontrol,
snd_hda_mixer_amp_switch_put,
NID_PATH_MUTE_CTL);
if (ret < 0)
return ret;

if (spec->capture_switch_hook) {
bool enable = (ucontrol->value.integer.value[0] ||
ucontrol->value.integer.value[1]);
spec->capture_switch_hook(codec, enable);
}

return ret;
}

static const struct snd_kcontrol_new cap_sw_temp = {
Expand Down Expand Up @@ -2860,6 +2846,7 @@ static bool is_inv_dmic_pin(struct hda_codec *codec, hda_nid_t nid)
return false;
}

/* capture switch put callback for a single control with hook call */
static int cap_single_sw_put(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
Expand All @@ -2871,11 +2858,8 @@ static int cap_single_sw_put(struct snd_kcontrol *kcontrol,
if (ret < 0)
return ret;

if (spec->capture_switch_hook) {
bool enable = (ucontrol->value.integer.value[0] ||
ucontrol->value.integer.value[1]);
spec->capture_switch_hook(codec, enable);
}
if (spec->cap_sync_hook)
spec->cap_sync_hook(codec, ucontrol);

return ret;
}
Expand Down Expand Up @@ -2904,7 +2888,7 @@ static int add_single_cap_ctl(struct hda_codec *codec, const char *label,
amp_val_replace_channels(ctl, chs));
if (!knew)
return -ENOMEM;
if (is_switch && spec->capture_switch_hook)
if (is_switch)
knew->put = cap_single_sw_put;
if (!inv_dmic)
return 0;
Expand All @@ -2920,7 +2904,7 @@ static int add_single_cap_ctl(struct hda_codec *codec, const char *label,
amp_val_replace_channels(ctl, 2));
if (!knew)
return -ENOMEM;
if (is_switch && spec->capture_switch_hook)
if (is_switch)
knew->put = cap_single_sw_put;
return 0;
}
Expand Down Expand Up @@ -3280,7 +3264,7 @@ static int mux_select(struct hda_codec *codec, unsigned int adc_idx,
return 0;
snd_hda_activate_path(codec, path, true, false);
if (spec->cap_sync_hook)
spec->cap_sync_hook(codec);
spec->cap_sync_hook(codec, NULL);
return 1;
}

Expand Down Expand Up @@ -4610,7 +4594,7 @@ static void init_input_src(struct hda_codec *codec)
update_shared_mic_hp(codec, spec->cur_mux[0]);

if (spec->cap_sync_hook)
spec->cap_sync_hook(codec);
spec->cap_sync_hook(codec, NULL);
}

/* set right pin controls for digital I/O */
Expand Down
6 changes: 2 additions & 4 deletions sound/pci/hda/hda_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ struct hda_gen_spec {
/* hooks */
void (*init_hook)(struct hda_codec *codec);
void (*automute_hook)(struct hda_codec *codec);
void (*cap_sync_hook)(struct hda_codec *codec);
void (*cap_sync_hook)(struct hda_codec *codec,
struct snd_ctl_elem_value *ucontrol);

/* PCM hooks */
void (*pcm_playback_hook)(struct hda_pcm_stream *hinfo,
Expand All @@ -252,9 +253,6 @@ struct hda_gen_spec {
struct hda_jack_tbl *tbl);
void (*mic_autoswitch_hook)(struct hda_codec *codec,
struct hda_jack_tbl *tbl);

/* capture switch hook (for mic-mute LED) */
void (*capture_switch_hook)(struct hda_codec *codec, bool enable);
};

int snd_hda_gen_spec_init(struct hda_gen_spec *spec);
Expand Down
3 changes: 2 additions & 1 deletion sound/pci/hda/patch_realtek.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,8 @@ static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
}
}

static void alc_inv_dmic_hook(struct hda_codec *codec)
static void alc_inv_dmic_hook(struct hda_codec *codec,
struct snd_ctl_elem_value *ucontrol)
{
alc_inv_dmic_sync(codec, false);
}
Expand Down
12 changes: 9 additions & 3 deletions sound/pci/hda/patch_sigmatel.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,17 @@ static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
}

/* hook for controlling mic-mute LED GPIO */
static void stac_capture_led_hook(struct hda_codec *codec, bool enable)
static void stac_capture_led_hook(struct hda_codec *codec,
struct snd_ctl_elem_value *ucontrol)
{
struct sigmatel_spec *spec = codec->spec;
bool mute = !enable;
bool mute;

if (!ucontrol)
return;

mute = !(ucontrol->value.integer.value[0] ||
ucontrol->value.integer.value[1]);
if (spec->mic_mute_led_on != mute) {
spec->mic_mute_led_on = mute;
if (mute)
Expand Down Expand Up @@ -3806,7 +3812,7 @@ static void stac_setup_gpio(struct hda_codec *codec)
spec->mic_mute_led_on = true;
spec->gpio_data |= spec->mic_mute_led_gpio;

spec->gen.capture_switch_hook = stac_capture_led_hook;
spec->gen.cap_sync_hook = stac_capture_led_hook;
}
}

Expand Down

0 comments on commit a90229e

Please sign in to comment.