forked from Minki/linux
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: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
1299d33020
commit
9322ca5497
@ -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 */
|
||||
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;
|
||||
const char * const *s;
|
||||
@ -2313,7 +2313,15 @@ static int map_slaves(struct hda_codec *codec, const char * const *slaves,
|
||||
sctl->id.iface != SNDRV_CTL_ELEM_IFACE_MIXER)
|
||||
continue;
|
||||
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);
|
||||
if (err)
|
||||
return err;
|
||||
@ -2335,6 +2343,7 @@ static int check_slave_present(void *data, struct snd_kcontrol *sctl)
|
||||
* @name: vmaster control name
|
||||
* @tlv: TLV data (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
|
||||
* must be either NULL or a valid data.
|
||||
@ -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.
|
||||
*/
|
||||
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;
|
||||
int err;
|
||||
|
||||
err = map_slaves(codec, slaves, check_slave_present, NULL);
|
||||
err = map_slaves(codec, slaves, suffix, check_slave_present, NULL);
|
||||
if (err != 1) {
|
||||
snd_printdd("No slave found for %s\n", name);
|
||||
return 0;
|
||||
@ -2363,8 +2373,8 @@ int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
err = map_slaves(codec, slaves, (map_slave_func_t)snd_ctl_add_slave,
|
||||
kctl);
|
||||
err = map_slaves(codec, slaves, suffix,
|
||||
(map_slave_func_t)snd_ctl_add_slave, kctl);
|
||||
if (err < 0)
|
||||
return err;
|
||||
return 0;
|
||||
|
@ -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,
|
||||
const 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);
|
||||
|
||||
/* amp value bits */
|
||||
|
@ -137,51 +137,17 @@ static int ad198x_init(struct hda_codec *codec)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char * const ad_slave_vols[] = {
|
||||
"Front Playback Volume",
|
||||
"Surround Playback Volume",
|
||||
"Center Playback Volume",
|
||||
"LFE Playback Volume",
|
||||
"Side Playback Volume",
|
||||
"Headphone Playback Volume",
|
||||
"Mono Playback Volume",
|
||||
"Speaker Playback Volume",
|
||||
"IEC958 Playback Volume",
|
||||
static const char * const ad_slave_pfxs[] = {
|
||||
"Front", "Surround", "Center", "LFE", "Side",
|
||||
"Headphone", "Mono", "Speaker", "IEC958",
|
||||
NULL
|
||||
};
|
||||
|
||||
static const char * const ad_slave_sws[] = {
|
||||
"Front Playback Switch",
|
||||
"Surround Playback Switch",
|
||||
"Center Playback Switch",
|
||||
"LFE Playback Switch",
|
||||
"Side Playback Switch",
|
||||
"Headphone Playback Switch",
|
||||
"Mono Playback Switch",
|
||||
"Speaker Playback Switch",
|
||||
"IEC958 Playback Switch",
|
||||
static const char * const ad1988_6stack_fp_slave_pfxs[] = {
|
||||
"Front", "Surround", "Center", "LFE", "Side", "IEC958",
|
||||
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);
|
||||
|
||||
#ifdef CONFIG_SND_HDA_INPUT_BEEP
|
||||
@ -260,7 +226,8 @@ static int ad198x_build_controls(struct hda_codec *codec)
|
||||
err = snd_hda_add_vmaster(codec, "Master Playback Volume",
|
||||
vmaster_tlv,
|
||||
(spec->slave_vols ?
|
||||
spec->slave_vols : ad_slave_vols));
|
||||
spec->slave_vols : ad_slave_pfxs),
|
||||
"Playback Volume");
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
@ -268,7 +235,8 @@ static int ad198x_build_controls(struct hda_codec *codec)
|
||||
err = snd_hda_add_vmaster(codec, "Master Playback Switch",
|
||||
NULL,
|
||||
(spec->slave_sws ?
|
||||
spec->slave_sws : ad_slave_sws));
|
||||
spec->slave_sws : ad_slave_pfxs),
|
||||
"Playback Switch");
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
@ -3385,8 +3353,8 @@ static int patch_ad1988(struct hda_codec *codec)
|
||||
|
||||
if (spec->autocfg.hp_pins[0]) {
|
||||
spec->mixers[spec->num_mixers++] = ad1988_hp_mixers;
|
||||
spec->slave_vols = ad1988_6stack_fp_slave_vols;
|
||||
spec->slave_sws = ad1988_6stack_fp_slave_sws;
|
||||
spec->slave_vols = ad1988_6stack_fp_slave_pfxs;
|
||||
spec->slave_sws = ad1988_6stack_fp_slave_pfxs;
|
||||
spec->alt_dac_nid = ad1988_alt_dac_nid;
|
||||
spec->stream_analog_alt_playback =
|
||||
&ad198x_pcm_analog_alt_playback;
|
||||
@ -3594,16 +3562,8 @@ static const struct hda_amp_list ad1884_loopbacks[] = {
|
||||
#endif
|
||||
|
||||
static const char * const ad1884_slave_vols[] = {
|
||||
"PCM Playback Volume",
|
||||
"Mic Playback Volume",
|
||||
"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",
|
||||
"PCM", "Mic", "Mono", "Front Mic", "Mic", "CD",
|
||||
"Internal Mic", "Docking Mic", /* "Beep", */ "IEC958",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
@ -465,21 +465,8 @@ static const struct snd_kcontrol_new cxt_beep_mixer[] = {
|
||||
};
|
||||
#endif
|
||||
|
||||
static const char * const slave_vols[] = {
|
||||
"Headphone Playback Volume",
|
||||
"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",
|
||||
static const char * const slave_pfxs[] = {
|
||||
"Headphone", "Speaker", "Front", "Surround", "CLFE",
|
||||
NULL
|
||||
};
|
||||
|
||||
@ -519,14 +506,16 @@ static int conexant_build_controls(struct hda_codec *codec)
|
||||
snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
|
||||
HDA_OUTPUT, vmaster_tlv);
|
||||
err = snd_hda_add_vmaster(codec, "Master Playback Volume",
|
||||
vmaster_tlv, slave_vols);
|
||||
vmaster_tlv, slave_pfxs,
|
||||
"Playback Volume");
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
if (spec->vmaster_nid &&
|
||||
!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
|
||||
err = snd_hda_add_vmaster(codec, "Master Playback Switch",
|
||||
NULL, slave_sws);
|
||||
NULL, slave_pfxs,
|
||||
"Playback Switch");
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
|
@ -1845,36 +1845,10 @@ DEFINE_CAPMIX_NOSRC(3);
|
||||
/*
|
||||
* slave controls for virtual master
|
||||
*/
|
||||
static const char * const alc_slave_vols[] = {
|
||||
"Front Playback Volume",
|
||||
"Surround Playback Volume",
|
||||
"Center Playback Volume",
|
||||
"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",
|
||||
static const char * const alc_slave_pfxs[] = {
|
||||
"Front", "Surround", "Center", "LFE", "Side",
|
||||
"Headphone", "Speaker", "Mono", "Line-Out",
|
||||
"CLFE", "Bass Speaker", "PCM",
|
||||
NULL,
|
||||
};
|
||||
|
||||
@ -1965,14 +1939,16 @@ static int __alc_build_controls(struct hda_codec *codec)
|
||||
snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
|
||||
HDA_OUTPUT, vmaster_tlv);
|
||||
err = snd_hda_add_vmaster(codec, "Master Playback Volume",
|
||||
vmaster_tlv, alc_slave_vols);
|
||||
vmaster_tlv, alc_slave_pfxs,
|
||||
"Playback Volume");
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
if (!spec->no_analog &&
|
||||
!snd_hda_find_mixer_ctl(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)
|
||||
return err;
|
||||
}
|
||||
|
@ -1060,26 +1060,9 @@ static struct snd_kcontrol_new stac_smux_mixer = {
|
||||
.put = stac92xx_smux_enum_put,
|
||||
};
|
||||
|
||||
static const char * const slave_vols[] = {
|
||||
"Front Playback Volume",
|
||||
"Surround Playback Volume",
|
||||
"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",
|
||||
static const char * const slave_pfxs[] = {
|
||||
"Front", "Surround", "Center", "LFE", "Side",
|
||||
"Headphone", "Speaker", "IEC958",
|
||||
NULL
|
||||
};
|
||||
|
||||
@ -1153,13 +1136,15 @@ static int stac92xx_build_controls(struct hda_codec *codec)
|
||||
/* minimum value is actually mute */
|
||||
vmaster_tlv[3] |= TLV_DB_SCALE_MUTE;
|
||||
err = snd_hda_add_vmaster(codec, "Master Playback Volume",
|
||||
vmaster_tlv, slave_vols);
|
||||
vmaster_tlv, slave_pfxs,
|
||||
"Playback Volume");
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
|
||||
err = snd_hda_add_vmaster(codec, "Master Playback Switch",
|
||||
NULL, slave_sws);
|
||||
NULL, slave_pfxs,
|
||||
"Playback Switch");
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
|
@ -1442,25 +1442,9 @@ static const struct hda_pcm_stream via_pcm_digital_capture = {
|
||||
/*
|
||||
* slave controls for virtual master
|
||||
*/
|
||||
static const char * const via_slave_vols[] = {
|
||||
"Front Playback Volume",
|
||||
"Surround Playback Volume",
|
||||
"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",
|
||||
static const char * const via_slave_pfxs[] = {
|
||||
"Front", "Surround", "Center", "LFE", "Side",
|
||||
"Headphone", "Speaker",
|
||||
NULL,
|
||||
};
|
||||
|
||||
@ -1505,13 +1489,15 @@ static int via_build_controls(struct hda_codec *codec)
|
||||
snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
|
||||
HDA_OUTPUT, vmaster_tlv);
|
||||
err = snd_hda_add_vmaster(codec, "Master Playback Volume",
|
||||
vmaster_tlv, via_slave_vols);
|
||||
vmaster_tlv, via_slave_pfxs,
|
||||
"Playback Volume");
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
if (!snd_hda_find_mixer_ctl(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)
|
||||
return err;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user