Commit 9322ca54 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: hda - Add suffix argument to snd_hda_add_vmaster()

In most cases, the slave strings for vmaster are identical between
volumes and switches except for "xxx Volume" and "xxx Switch" suffix.
Now snd_hda_add_vmaster() takes the optional suffix argument so that
each string can be composed with the given suffix, and we can share the
slave name strings in both volume and switch calls nicely.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 1299d330
...@@ -2300,7 +2300,7 @@ typedef int (*map_slave_func_t)(void *, struct snd_kcontrol *); ...@@ -2300,7 +2300,7 @@ typedef int (*map_slave_func_t)(void *, struct snd_kcontrol *);
/* apply the function to all matching slave ctls in the mixer list */ /* apply the function to all matching slave ctls in the mixer list */
static int map_slaves(struct hda_codec *codec, const char * const *slaves, static int map_slaves(struct hda_codec *codec, const char * const *slaves,
map_slave_func_t func, void *data) const char *suffix, map_slave_func_t func, void *data)
{ {
struct hda_nid_item *items; struct hda_nid_item *items;
const char * const *s; const char * const *s;
...@@ -2313,7 +2313,15 @@ static int map_slaves(struct hda_codec *codec, const char * const *slaves, ...@@ -2313,7 +2313,15 @@ static int map_slaves(struct hda_codec *codec, const char * const *slaves,
sctl->id.iface != SNDRV_CTL_ELEM_IFACE_MIXER) sctl->id.iface != SNDRV_CTL_ELEM_IFACE_MIXER)
continue; continue;
for (s = slaves; *s; s++) { for (s = slaves; *s; s++) {
if (!strcmp(sctl->id.name, *s)) { char tmpname[sizeof(sctl->id.name)];
const char *name = *s;
if (suffix) {
snprintf(tmpname, sizeof(tmpname), "%s %s",
name, suffix);
name = tmpname;
}
printk("XXX comparing %s vs %s\n", sctl->id.name, name);
if (!strcmp(sctl->id.name, name)) {
err = func(data, sctl); err = func(data, sctl);
if (err) if (err)
return err; return err;
...@@ -2335,6 +2343,7 @@ static int check_slave_present(void *data, struct snd_kcontrol *sctl) ...@@ -2335,6 +2343,7 @@ static int check_slave_present(void *data, struct snd_kcontrol *sctl)
* @name: vmaster control name * @name: vmaster control name
* @tlv: TLV data (optional) * @tlv: TLV data (optional)
* @slaves: slave control names (optional) * @slaves: slave control names (optional)
* @suffix: suffix string to each slave name (optional)
* *
* Create a virtual master control with the given name. The TLV data * Create a virtual master control with the given name. The TLV data
* must be either NULL or a valid data. * must be either NULL or a valid data.
...@@ -2346,12 +2355,13 @@ static int check_slave_present(void *data, struct snd_kcontrol *sctl) ...@@ -2346,12 +2355,13 @@ static int check_slave_present(void *data, struct snd_kcontrol *sctl)
* This function returns zero if successful or a negative error code. * This function returns zero if successful or a negative error code.
*/ */
int snd_hda_add_vmaster(struct hda_codec *codec, char *name, int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
unsigned int *tlv, const char * const *slaves) unsigned int *tlv, const char * const *slaves,
const char *suffix)
{ {
struct snd_kcontrol *kctl; struct snd_kcontrol *kctl;
int err; int err;
err = map_slaves(codec, slaves, check_slave_present, NULL); err = map_slaves(codec, slaves, suffix, check_slave_present, NULL);
if (err != 1) { if (err != 1) {
snd_printdd("No slave found for %s\n", name); snd_printdd("No slave found for %s\n", name);
return 0; return 0;
...@@ -2363,8 +2373,8 @@ int snd_hda_add_vmaster(struct hda_codec *codec, char *name, ...@@ -2363,8 +2373,8 @@ int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
if (err < 0) if (err < 0)
return err; return err;
err = map_slaves(codec, slaves, (map_slave_func_t)snd_ctl_add_slave, err = map_slaves(codec, slaves, suffix,
kctl); (map_slave_func_t)snd_ctl_add_slave, kctl);
if (err < 0) if (err < 0)
return err; return err;
return 0; return 0;
......
...@@ -140,7 +140,8 @@ void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir, ...@@ -140,7 +140,8 @@ void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec, struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
const char *name); const char *name);
int snd_hda_add_vmaster(struct hda_codec *codec, char *name, int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
unsigned int *tlv, const char * const *slaves); unsigned int *tlv, const char * const *slaves,
const char *suffix);
int snd_hda_codec_reset(struct hda_codec *codec); int snd_hda_codec_reset(struct hda_codec *codec);
/* amp value bits */ /* amp value bits */
......
...@@ -137,51 +137,17 @@ static int ad198x_init(struct hda_codec *codec) ...@@ -137,51 +137,17 @@ static int ad198x_init(struct hda_codec *codec)
return 0; return 0;
} }
static const char * const ad_slave_vols[] = { static const char * const ad_slave_pfxs[] = {
"Front Playback Volume", "Front", "Surround", "Center", "LFE", "Side",
"Surround Playback Volume", "Headphone", "Mono", "Speaker", "IEC958",
"Center Playback Volume",
"LFE Playback Volume",
"Side Playback Volume",
"Headphone Playback Volume",
"Mono Playback Volume",
"Speaker Playback Volume",
"IEC958 Playback Volume",
NULL NULL
}; };
static const char * const ad_slave_sws[] = { static const char * const ad1988_6stack_fp_slave_pfxs[] = {
"Front Playback Switch", "Front", "Surround", "Center", "LFE", "Side", "IEC958",
"Surround Playback Switch",
"Center Playback Switch",
"LFE Playback Switch",
"Side Playback Switch",
"Headphone Playback Switch",
"Mono Playback Switch",
"Speaker Playback Switch",
"IEC958 Playback Switch",
NULL NULL
}; };
static const char * const ad1988_6stack_fp_slave_vols[] = {
"Front Playback Volume",
"Surround Playback Volume",
"Center Playback Volume",
"LFE Playback Volume",
"Side Playback Volume",
"IEC958 Playback Volume",
NULL
};
static const char * const ad1988_6stack_fp_slave_sws[] = {
"Front Playback Switch",
"Surround Playback Switch",
"Center Playback Switch",
"LFE Playback Switch",
"Side Playback Switch",
"IEC958 Playback Switch",
NULL
};
static void ad198x_free_kctls(struct hda_codec *codec); static void ad198x_free_kctls(struct hda_codec *codec);
#ifdef CONFIG_SND_HDA_INPUT_BEEP #ifdef CONFIG_SND_HDA_INPUT_BEEP
...@@ -260,7 +226,8 @@ static int ad198x_build_controls(struct hda_codec *codec) ...@@ -260,7 +226,8 @@ static int ad198x_build_controls(struct hda_codec *codec)
err = snd_hda_add_vmaster(codec, "Master Playback Volume", err = snd_hda_add_vmaster(codec, "Master Playback Volume",
vmaster_tlv, vmaster_tlv,
(spec->slave_vols ? (spec->slave_vols ?
spec->slave_vols : ad_slave_vols)); spec->slave_vols : ad_slave_pfxs),
"Playback Volume");
if (err < 0) if (err < 0)
return err; return err;
} }
...@@ -268,7 +235,8 @@ static int ad198x_build_controls(struct hda_codec *codec) ...@@ -268,7 +235,8 @@ static int ad198x_build_controls(struct hda_codec *codec)
err = snd_hda_add_vmaster(codec, "Master Playback Switch", err = snd_hda_add_vmaster(codec, "Master Playback Switch",
NULL, NULL,
(spec->slave_sws ? (spec->slave_sws ?
spec->slave_sws : ad_slave_sws)); spec->slave_sws : ad_slave_pfxs),
"Playback Switch");
if (err < 0) if (err < 0)
return err; return err;
} }
...@@ -3385,8 +3353,8 @@ static int patch_ad1988(struct hda_codec *codec) ...@@ -3385,8 +3353,8 @@ static int patch_ad1988(struct hda_codec *codec)
if (spec->autocfg.hp_pins[0]) { if (spec->autocfg.hp_pins[0]) {
spec->mixers[spec->num_mixers++] = ad1988_hp_mixers; spec->mixers[spec->num_mixers++] = ad1988_hp_mixers;
spec->slave_vols = ad1988_6stack_fp_slave_vols; spec->slave_vols = ad1988_6stack_fp_slave_pfxs;
spec->slave_sws = ad1988_6stack_fp_slave_sws; spec->slave_sws = ad1988_6stack_fp_slave_pfxs;
spec->alt_dac_nid = ad1988_alt_dac_nid; spec->alt_dac_nid = ad1988_alt_dac_nid;
spec->stream_analog_alt_playback = spec->stream_analog_alt_playback =
&ad198x_pcm_analog_alt_playback; &ad198x_pcm_analog_alt_playback;
...@@ -3594,16 +3562,8 @@ static const struct hda_amp_list ad1884_loopbacks[] = { ...@@ -3594,16 +3562,8 @@ static const struct hda_amp_list ad1884_loopbacks[] = {
#endif #endif
static const char * const ad1884_slave_vols[] = { static const char * const ad1884_slave_vols[] = {
"PCM Playback Volume", "PCM", "Mic", "Mono", "Front Mic", "Mic", "CD",
"Mic Playback Volume", "Internal Mic", "Docking Mic", /* "Beep", */ "IEC958",
"Mono Playback Volume",
"Front Mic Playback Volume",
"Mic Playback Volume",
"CD Playback Volume",
"Internal Mic Playback Volume",
"Docking Mic Playback Volume",
/* "Beep Playback Volume", */
"IEC958 Playback Volume",
NULL NULL
}; };
......
...@@ -465,21 +465,8 @@ static const struct snd_kcontrol_new cxt_beep_mixer[] = { ...@@ -465,21 +465,8 @@ static const struct snd_kcontrol_new cxt_beep_mixer[] = {
}; };
#endif #endif
static const char * const slave_vols[] = { static const char * const slave_pfxs[] = {
"Headphone Playback Volume", "Headphone", "Speaker", "Front", "Surround", "CLFE",
"Speaker Playback Volume",
"Front Playback Volume",
"Surround Playback Volume",
"CLFE Playback Volume",
NULL
};
static const char * const slave_sws[] = {
"Headphone Playback Switch",
"Speaker Playback Switch",
"Front Playback Switch",
"Surround Playback Switch",
"CLFE Playback Switch",
NULL NULL
}; };
...@@ -519,14 +506,16 @@ static int conexant_build_controls(struct hda_codec *codec) ...@@ -519,14 +506,16 @@ static int conexant_build_controls(struct hda_codec *codec)
snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
HDA_OUTPUT, vmaster_tlv); HDA_OUTPUT, vmaster_tlv);
err = snd_hda_add_vmaster(codec, "Master Playback Volume", err = snd_hda_add_vmaster(codec, "Master Playback Volume",
vmaster_tlv, slave_vols); vmaster_tlv, slave_pfxs,
"Playback Volume");
if (err < 0) if (err < 0)
return err; return err;
} }
if (spec->vmaster_nid && if (spec->vmaster_nid &&
!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
err = snd_hda_add_vmaster(codec, "Master Playback Switch", err = snd_hda_add_vmaster(codec, "Master Playback Switch",
NULL, slave_sws); NULL, slave_pfxs,
"Playback Switch");
if (err < 0) if (err < 0)
return err; return err;
} }
......
...@@ -1845,36 +1845,10 @@ DEFINE_CAPMIX_NOSRC(3); ...@@ -1845,36 +1845,10 @@ DEFINE_CAPMIX_NOSRC(3);
/* /*
* slave controls for virtual master * slave controls for virtual master
*/ */
static const char * const alc_slave_vols[] = { static const char * const alc_slave_pfxs[] = {
"Front Playback Volume", "Front", "Surround", "Center", "LFE", "Side",
"Surround Playback Volume", "Headphone", "Speaker", "Mono", "Line-Out",
"Center Playback Volume", "CLFE", "Bass Speaker", "PCM",
"LFE Playback Volume",
"Side Playback Volume",
"Headphone Playback Volume",
"Speaker Playback Volume",
"Mono Playback Volume",
"Line-Out Playback Volume",
"CLFE Playback Volume",
"Bass Speaker Playback Volume",
"PCM Playback Volume",
NULL,
};
static const char * const alc_slave_sws[] = {
"Front Playback Switch",
"Surround Playback Switch",
"Center Playback Switch",
"LFE Playback Switch",
"Side Playback Switch",
"Headphone Playback Switch",
"Speaker Playback Switch",
"Mono Playback Switch",
"IEC958 Playback Switch",
"Line-Out Playback Switch",
"CLFE Playback Switch",
"Bass Speaker Playback Switch",
"PCM Playback Switch",
NULL, NULL,
}; };
...@@ -1965,14 +1939,16 @@ static int __alc_build_controls(struct hda_codec *codec) ...@@ -1965,14 +1939,16 @@ static int __alc_build_controls(struct hda_codec *codec)
snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
HDA_OUTPUT, vmaster_tlv); HDA_OUTPUT, vmaster_tlv);
err = snd_hda_add_vmaster(codec, "Master Playback Volume", err = snd_hda_add_vmaster(codec, "Master Playback Volume",
vmaster_tlv, alc_slave_vols); vmaster_tlv, alc_slave_pfxs,
"Playback Volume");
if (err < 0) if (err < 0)
return err; return err;
} }
if (!spec->no_analog && if (!spec->no_analog &&
!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
err = snd_hda_add_vmaster(codec, "Master Playback Switch", err = snd_hda_add_vmaster(codec, "Master Playback Switch",
NULL, alc_slave_sws); NULL, alc_slave_pfxs,
"Playback Switch");
if (err < 0) if (err < 0)
return err; return err;
} }
......
...@@ -1060,26 +1060,9 @@ static struct snd_kcontrol_new stac_smux_mixer = { ...@@ -1060,26 +1060,9 @@ static struct snd_kcontrol_new stac_smux_mixer = {
.put = stac92xx_smux_enum_put, .put = stac92xx_smux_enum_put,
}; };
static const char * const slave_vols[] = { static const char * const slave_pfxs[] = {
"Front Playback Volume", "Front", "Surround", "Center", "LFE", "Side",
"Surround Playback Volume", "Headphone", "Speaker", "IEC958",
"Center Playback Volume",
"LFE Playback Volume",
"Side Playback Volume",
"Headphone Playback Volume",
"Speaker Playback Volume",
NULL
};
static const char * const slave_sws[] = {
"Front Playback Switch",
"Surround Playback Switch",
"Center Playback Switch",
"LFE Playback Switch",
"Side Playback Switch",
"Headphone Playback Switch",
"Speaker Playback Switch",
"IEC958 Playback Switch",
NULL NULL
}; };
...@@ -1153,13 +1136,15 @@ static int stac92xx_build_controls(struct hda_codec *codec) ...@@ -1153,13 +1136,15 @@ static int stac92xx_build_controls(struct hda_codec *codec)
/* minimum value is actually mute */ /* minimum value is actually mute */
vmaster_tlv[3] |= TLV_DB_SCALE_MUTE; vmaster_tlv[3] |= TLV_DB_SCALE_MUTE;
err = snd_hda_add_vmaster(codec, "Master Playback Volume", err = snd_hda_add_vmaster(codec, "Master Playback Volume",
vmaster_tlv, slave_vols); vmaster_tlv, slave_pfxs,
"Playback Volume");
if (err < 0) if (err < 0)
return err; return err;
} }
if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
err = snd_hda_add_vmaster(codec, "Master Playback Switch", err = snd_hda_add_vmaster(codec, "Master Playback Switch",
NULL, slave_sws); NULL, slave_pfxs,
"Playback Switch");
if (err < 0) if (err < 0)
return err; return err;
} }
......
...@@ -1442,25 +1442,9 @@ static const struct hda_pcm_stream via_pcm_digital_capture = { ...@@ -1442,25 +1442,9 @@ static const struct hda_pcm_stream via_pcm_digital_capture = {
/* /*
* slave controls for virtual master * slave controls for virtual master
*/ */
static const char * const via_slave_vols[] = { static const char * const via_slave_pfxs[] = {
"Front Playback Volume", "Front", "Surround", "Center", "LFE", "Side",
"Surround Playback Volume", "Headphone", "Speaker",
"Center Playback Volume",
"LFE Playback Volume",
"Side Playback Volume",
"Headphone Playback Volume",
"Speaker Playback Volume",
NULL,
};
static const char * const via_slave_sws[] = {
"Front Playback Switch",
"Surround Playback Switch",
"Center Playback Switch",
"LFE Playback Switch",
"Side Playback Switch",
"Headphone Playback Switch",
"Speaker Playback Switch",
NULL, NULL,
}; };
...@@ -1505,13 +1489,15 @@ static int via_build_controls(struct hda_codec *codec) ...@@ -1505,13 +1489,15 @@ static int via_build_controls(struct hda_codec *codec)
snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0], snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
HDA_OUTPUT, vmaster_tlv); HDA_OUTPUT, vmaster_tlv);
err = snd_hda_add_vmaster(codec, "Master Playback Volume", err = snd_hda_add_vmaster(codec, "Master Playback Volume",
vmaster_tlv, via_slave_vols); vmaster_tlv, via_slave_pfxs,
"Playback Volume");
if (err < 0) if (err < 0)
return err; return err;
} }
if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
err = snd_hda_add_vmaster(codec, "Master Playback Switch", err = snd_hda_add_vmaster(codec, "Master Playback Switch",
NULL, via_slave_sws); NULL, via_slave_pfxs,
"Playback Switch");
if (err < 0) if (err < 0)
return err; return err;
} }
......
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