ALSA: hda - Add a helper function for simple enum kcontrols
The same type of code is being used in multiple places in various codec drivers, so put it as a core library. Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
@@ -4791,6 +4791,34 @@ int snd_hda_input_mux_put(struct hda_codec *codec,
|
|||||||
EXPORT_SYMBOL_HDA(snd_hda_input_mux_put);
|
EXPORT_SYMBOL_HDA(snd_hda_input_mux_put);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* process kcontrol info callback of a simple string enum array
|
||||||
|
* when @num_items is 0 or @texts is NULL, assume a boolean enum array
|
||||||
|
*/
|
||||||
|
int snd_hda_enum_helper_info(struct snd_kcontrol *kcontrol,
|
||||||
|
struct snd_ctl_elem_info *uinfo,
|
||||||
|
int num_items, const char * const *texts)
|
||||||
|
{
|
||||||
|
static const char * const texts_default[] = {
|
||||||
|
"Disabled", "Enabled"
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!texts || !num_items) {
|
||||||
|
num_items = 2;
|
||||||
|
texts = texts_default;
|
||||||
|
}
|
||||||
|
|
||||||
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
|
||||||
|
uinfo->count = 1;
|
||||||
|
uinfo->value.enumerated.items = num_items;
|
||||||
|
if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
|
||||||
|
uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
|
||||||
|
strcpy(uinfo->value.enumerated.name,
|
||||||
|
texts[uinfo->value.enumerated.item]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_HDA(snd_hda_enum_helper_info);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Multi-channel / digital-out PCM helper functions
|
* Multi-channel / digital-out PCM helper functions
|
||||||
*/
|
*/
|
||||||
|
@@ -600,6 +600,15 @@ int snd_hda_check_amp_list_power(struct hda_codec *codec,
|
|||||||
#define get_amp_offset(kc) (((kc)->private_value >> 23) & 0x3f)
|
#define get_amp_offset(kc) (((kc)->private_value >> 23) & 0x3f)
|
||||||
#define get_amp_min_mute(kc) (((kc)->private_value >> 29) & 0x1)
|
#define get_amp_min_mute(kc) (((kc)->private_value >> 29) & 0x1)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* enum control helper
|
||||||
|
*/
|
||||||
|
int snd_hda_enum_helper_info(struct snd_kcontrol *kcontrol,
|
||||||
|
struct snd_ctl_elem_info *uinfo,
|
||||||
|
int num_entries, const char * const *texts);
|
||||||
|
#define snd_hda_enum_bool_helper_info(kcontrol, uinfo) \
|
||||||
|
snd_hda_enum_helper_info(kcontrol, uinfo, 0, NULL)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CEA Short Audio Descriptor data
|
* CEA Short Audio Descriptor data
|
||||||
*/
|
*/
|
||||||
|
@@ -3435,28 +3435,13 @@ static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
|
|||||||
{
|
{
|
||||||
struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
|
struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
|
||||||
struct conexant_spec *spec = codec->spec;
|
struct conexant_spec *spec = codec->spec;
|
||||||
static const char * const texts2[] = {
|
|
||||||
"Disabled", "Enabled"
|
|
||||||
};
|
|
||||||
static const char * const texts3[] = {
|
static const char * const texts3[] = {
|
||||||
"Disabled", "Speaker Only", "Line Out+Speaker"
|
"Disabled", "Speaker Only", "Line Out+Speaker"
|
||||||
};
|
};
|
||||||
const char * const *texts;
|
|
||||||
|
|
||||||
uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
|
if (spec->automute_hp_lo)
|
||||||
uinfo->count = 1;
|
return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
|
||||||
if (spec->automute_hp_lo) {
|
return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
|
||||||
uinfo->value.enumerated.items = 3;
|
|
||||||
texts = texts3;
|
|
||||||
} else {
|
|
||||||
uinfo->value.enumerated.items = 2;
|
|
||||||
texts = texts2;
|
|
||||||
}
|
|
||||||
if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
|
|
||||||
uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
|
|
||||||
strcpy(uinfo->value.enumerated.name,
|
|
||||||
texts[uinfo->value.enumerated.item]);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
|
static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
|
||||||
|
@@ -815,28 +815,13 @@ static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
|
|||||||
{
|
{
|
||||||
struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
|
struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
|
||||||
struct alc_spec *spec = codec->spec;
|
struct alc_spec *spec = codec->spec;
|
||||||
static const char * const texts2[] = {
|
|
||||||
"Disabled", "Enabled"
|
|
||||||
};
|
|
||||||
static const char * const texts3[] = {
|
static const char * const texts3[] = {
|
||||||
"Disabled", "Speaker Only", "Line Out+Speaker"
|
"Disabled", "Speaker Only", "Line Out+Speaker"
|
||||||
};
|
};
|
||||||
const char * const *texts;
|
|
||||||
|
|
||||||
uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
|
if (spec->automute_speaker_possible && spec->automute_lo_possible)
|
||||||
uinfo->count = 1;
|
return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
|
||||||
if (spec->automute_speaker_possible && spec->automute_lo_possible) {
|
return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
|
||||||
uinfo->value.enumerated.items = 3;
|
|
||||||
texts = texts3;
|
|
||||||
} else {
|
|
||||||
uinfo->value.enumerated.items = 2;
|
|
||||||
texts = texts2;
|
|
||||||
}
|
|
||||||
if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
|
|
||||||
uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
|
|
||||||
strcpy(uinfo->value.enumerated.name,
|
|
||||||
texts[uinfo->value.enumerated.item]);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
|
static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
|
||||||
|
@@ -739,18 +739,7 @@ static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
|
|||||||
static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
|
static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
|
||||||
struct snd_ctl_elem_info *uinfo)
|
struct snd_ctl_elem_info *uinfo)
|
||||||
{
|
{
|
||||||
static const char * const texts[] = {
|
return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
|
||||||
"Disabled", "Enabled"
|
|
||||||
};
|
|
||||||
|
|
||||||
uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
|
|
||||||
uinfo->count = 1;
|
|
||||||
uinfo->value.enumerated.items = 2;
|
|
||||||
if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
|
|
||||||
uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
|
|
||||||
strcpy(uinfo->value.enumerated.name,
|
|
||||||
texts[uinfo->value.enumerated.item]);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
|
static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
|
||||||
|
Reference in New Issue
Block a user