ALSA: core, oxygen, virtuoso: add an enum control info helper
Introduce the helper function snd_ctl_enum_info() to fill out the elem_info fields for an enumerated control. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
b532d6b8d3
commit
9600732b6c
8 changed files with 46 additions and 104 deletions
|
@ -160,12 +160,14 @@ static inline struct snd_ctl_elem_id *snd_ctl_build_ioff(struct snd_ctl_elem_id
|
|||
}
|
||||
|
||||
/*
|
||||
* Frequently used control callbacks
|
||||
* Frequently used control callbacks/helpers
|
||||
*/
|
||||
int snd_ctl_boolean_mono_info(struct snd_kcontrol *kcontrol,
|
||||
struct snd_ctl_elem_info *uinfo);
|
||||
int snd_ctl_boolean_stereo_info(struct snd_kcontrol *kcontrol,
|
||||
struct snd_ctl_elem_info *uinfo);
|
||||
int snd_ctl_enum_info(struct snd_ctl_elem_info *info, unsigned int channels,
|
||||
unsigned int items, const char *const names[]);
|
||||
|
||||
/*
|
||||
* virtual master control
|
||||
|
|
|
@ -1488,7 +1488,7 @@ int snd_ctl_create(struct snd_card *card)
|
|||
}
|
||||
|
||||
/*
|
||||
* Frequently used control callbacks
|
||||
* Frequently used control callbacks/helpers
|
||||
*/
|
||||
int snd_ctl_boolean_mono_info(struct snd_kcontrol *kcontrol,
|
||||
struct snd_ctl_elem_info *uinfo)
|
||||
|
@ -1513,3 +1513,29 @@ int snd_ctl_boolean_stereo_info(struct snd_kcontrol *kcontrol,
|
|||
}
|
||||
|
||||
EXPORT_SYMBOL(snd_ctl_boolean_stereo_info);
|
||||
|
||||
/**
|
||||
* snd_ctl_enum_info - fills the info structure for an enumerated control
|
||||
* @info: the structure to be filled
|
||||
* @channels: the number of the control's channels; often one
|
||||
* @items: the number of control values; also the size of @names
|
||||
* @names: an array containing the names of all control values
|
||||
*
|
||||
* Sets all required fields in @info to their appropriate values.
|
||||
* If the control's accessibility is not the default (readable and writable),
|
||||
* the caller has to fill @info->access.
|
||||
*/
|
||||
int snd_ctl_enum_info(struct snd_ctl_elem_info *info, unsigned int channels,
|
||||
unsigned int items, const char *const names[])
|
||||
{
|
||||
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
|
||||
info->count = channels;
|
||||
info->value.enumerated.items = items;
|
||||
if (info->value.enumerated.item >= items)
|
||||
info->value.enumerated.item = items - 1;
|
||||
strlcpy(info->value.enumerated.name,
|
||||
names[info->value.enumerated.item],
|
||||
sizeof(info->value.enumerated.name));
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(snd_ctl_enum_info);
|
||||
|
|
|
@ -415,13 +415,7 @@ static int rolloff_info(struct snd_kcontrol *ctl,
|
|||
"Sharp Roll-off", "Slow Roll-off"
|
||||
};
|
||||
|
||||
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
|
||||
info->count = 1;
|
||||
info->value.enumerated.items = 2;
|
||||
if (info->value.enumerated.item >= 2)
|
||||
info->value.enumerated.item = 1;
|
||||
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
|
||||
return 0;
|
||||
return snd_ctl_enum_info(info, 1, 2, names);
|
||||
}
|
||||
|
||||
static int rolloff_get(struct snd_kcontrol *ctl,
|
||||
|
@ -473,13 +467,7 @@ static int hpf_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
|
|||
"None", "High-pass Filter"
|
||||
};
|
||||
|
||||
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
|
||||
info->count = 1;
|
||||
info->value.enumerated.items = 2;
|
||||
if (info->value.enumerated.item >= 2)
|
||||
info->value.enumerated.item = 1;
|
||||
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
|
||||
return 0;
|
||||
return snd_ctl_enum_info(info, 1, 2, names);
|
||||
}
|
||||
|
||||
static int hpf_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
|
||||
|
|
|
@ -119,13 +119,7 @@ static int upmix_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
|
|||
struct oxygen *chip = ctl->private_data;
|
||||
unsigned int count = upmix_item_count(chip);
|
||||
|
||||
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
|
||||
info->count = 1;
|
||||
info->value.enumerated.items = count;
|
||||
if (info->value.enumerated.item >= count)
|
||||
info->value.enumerated.item = count - 1;
|
||||
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
|
||||
return 0;
|
||||
return snd_ctl_enum_info(info, 1, count, names);
|
||||
}
|
||||
|
||||
static int upmix_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
|
||||
|
@ -659,12 +653,7 @@ static int mic_fmic_source_info(struct snd_kcontrol *ctl,
|
|||
{
|
||||
static const char *const names[] = { "Mic Jack", "Front Panel" };
|
||||
|
||||
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
|
||||
info->count = 1;
|
||||
info->value.enumerated.items = 2;
|
||||
info->value.enumerated.item &= 1;
|
||||
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
|
||||
return 0;
|
||||
return snd_ctl_enum_info(info, 1, 2, names);
|
||||
}
|
||||
|
||||
static int mic_fmic_source_get(struct snd_kcontrol *ctl,
|
||||
|
|
|
@ -298,13 +298,7 @@ static int rolloff_info(struct snd_kcontrol *ctl,
|
|||
"Fast Roll-off", "Slow Roll-off"
|
||||
};
|
||||
|
||||
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
|
||||
info->count = 1;
|
||||
info->value.enumerated.items = 2;
|
||||
if (info->value.enumerated.item >= 2)
|
||||
info->value.enumerated.item = 1;
|
||||
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
|
||||
return 0;
|
||||
return snd_ctl_enum_info(info, 1, 2, names);
|
||||
}
|
||||
|
||||
static int rolloff_get(struct snd_kcontrol *ctl,
|
||||
|
|
|
@ -213,13 +213,7 @@ static int output_switch_info(struct snd_kcontrol *ctl,
|
|||
"Speakers", "Headphones", "FP Headphones"
|
||||
};
|
||||
|
||||
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
|
||||
info->count = 1;
|
||||
info->value.enumerated.items = 3;
|
||||
if (info->value.enumerated.item >= 3)
|
||||
info->value.enumerated.item = 2;
|
||||
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
|
||||
return 0;
|
||||
return snd_ctl_enum_info(info, 1, 3, names);
|
||||
}
|
||||
|
||||
static int output_switch_get(struct snd_kcontrol *ctl,
|
||||
|
@ -276,13 +270,7 @@ static int hp_volume_offset_info(struct snd_kcontrol *ctl,
|
|||
"< 64 ohms", "64-150 ohms", "150-300 ohms"
|
||||
};
|
||||
|
||||
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
|
||||
info->count = 1;
|
||||
info->value.enumerated.items = 3;
|
||||
if (info->value.enumerated.item >= 3)
|
||||
info->value.enumerated.item = 2;
|
||||
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
|
||||
return 0;
|
||||
return snd_ctl_enum_info(info, 1, 3, names);
|
||||
}
|
||||
|
||||
static int hp_volume_offset_get(struct snd_kcontrol *ctl,
|
||||
|
@ -390,12 +378,7 @@ static int input_sel_info(struct snd_kcontrol *ctl,
|
|||
"Mic", "Aux", "Front Mic", "Line"
|
||||
};
|
||||
|
||||
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
|
||||
info->count = 1;
|
||||
info->value.enumerated.items = 4;
|
||||
info->value.enumerated.item &= 3;
|
||||
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
|
||||
return 0;
|
||||
return snd_ctl_enum_info(info, 1, 4, names);
|
||||
}
|
||||
|
||||
static int input_sel_get(struct snd_kcontrol *ctl,
|
||||
|
@ -453,12 +436,7 @@ static int hpf_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
|
|||
{
|
||||
static const char *const names[2] = { "Active", "Frozen" };
|
||||
|
||||
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
|
||||
info->count = 1;
|
||||
info->value.enumerated.items = 2;
|
||||
info->value.enumerated.item &= 1;
|
||||
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
|
||||
return 0;
|
||||
return snd_ctl_enum_info(info, 1, 2, names);
|
||||
}
|
||||
|
||||
static int hpf_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
|
||||
|
|
|
@ -678,13 +678,7 @@ static int rolloff_info(struct snd_kcontrol *ctl,
|
|||
"Sharp Roll-off", "Slow Roll-off"
|
||||
};
|
||||
|
||||
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
|
||||
info->count = 1;
|
||||
info->value.enumerated.items = 2;
|
||||
if (info->value.enumerated.item >= 2)
|
||||
info->value.enumerated.item = 1;
|
||||
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
|
||||
return 0;
|
||||
return snd_ctl_enum_info(info, 1, 2, names);
|
||||
}
|
||||
|
||||
static int rolloff_get(struct snd_kcontrol *ctl,
|
||||
|
@ -748,13 +742,7 @@ static int st_output_switch_info(struct snd_kcontrol *ctl,
|
|||
"Speakers", "Headphones", "FP Headphones"
|
||||
};
|
||||
|
||||
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
|
||||
info->count = 1;
|
||||
info->value.enumerated.items = 3;
|
||||
if (info->value.enumerated.item >= 3)
|
||||
info->value.enumerated.item = 2;
|
||||
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
|
||||
return 0;
|
||||
return snd_ctl_enum_info(info, 1, 3, names);
|
||||
}
|
||||
|
||||
static int st_output_switch_get(struct snd_kcontrol *ctl,
|
||||
|
@ -809,13 +797,7 @@ static int st_hp_volume_offset_info(struct snd_kcontrol *ctl,
|
|||
"< 64 ohms", "64-300 ohms", "300-600 ohms"
|
||||
};
|
||||
|
||||
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
|
||||
info->count = 1;
|
||||
info->value.enumerated.items = 3;
|
||||
if (info->value.enumerated.item > 2)
|
||||
info->value.enumerated.item = 2;
|
||||
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
|
||||
return 0;
|
||||
return snd_ctl_enum_info(info, 1, 3, names);
|
||||
}
|
||||
|
||||
static int st_hp_volume_offset_get(struct snd_kcontrol *ctl,
|
||||
|
|
|
@ -577,11 +577,6 @@ static int wm8776_field_enum_info(struct snd_kcontrol *ctl,
|
|||
const char *const *names;
|
||||
|
||||
max = (ctl->private_value >> 12) & 0xf;
|
||||
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
|
||||
info->count = 1;
|
||||
info->value.enumerated.items = max + 1;
|
||||
if (info->value.enumerated.item > max)
|
||||
info->value.enumerated.item = max;
|
||||
switch ((ctl->private_value >> 24) & 0x1f) {
|
||||
case WM8776_ALCCTRL2:
|
||||
names = hld;
|
||||
|
@ -605,8 +600,7 @@ static int wm8776_field_enum_info(struct snd_kcontrol *ctl,
|
|||
default:
|
||||
return -ENXIO;
|
||||
}
|
||||
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
|
||||
return 0;
|
||||
return snd_ctl_enum_info(info, 1, max + 1, names);
|
||||
}
|
||||
|
||||
static int wm8776_field_volume_info(struct snd_kcontrol *ctl,
|
||||
|
@ -863,13 +857,8 @@ static int wm8776_level_control_info(struct snd_kcontrol *ctl,
|
|||
static const char *const names[3] = {
|
||||
"None", "Peak Limiter", "Automatic Level Control"
|
||||
};
|
||||
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
|
||||
info->count = 1;
|
||||
info->value.enumerated.items = 3;
|
||||
if (info->value.enumerated.item >= 3)
|
||||
info->value.enumerated.item = 2;
|
||||
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
|
||||
return 0;
|
||||
|
||||
return snd_ctl_enum_info(info, 1, 3, names);
|
||||
}
|
||||
|
||||
static int wm8776_level_control_get(struct snd_kcontrol *ctl,
|
||||
|
@ -955,13 +944,7 @@ static int hpf_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
|
|||
"None", "High-pass Filter"
|
||||
};
|
||||
|
||||
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
|
||||
info->count = 1;
|
||||
info->value.enumerated.items = 2;
|
||||
if (info->value.enumerated.item >= 2)
|
||||
info->value.enumerated.item = 1;
|
||||
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
|
||||
return 0;
|
||||
return snd_ctl_enum_info(info, 1, 2, names);
|
||||
}
|
||||
|
||||
static int hpf_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)
|
||||
|
|
Loading…
Reference in a new issue