diff options
author | Takashi Iwai <tiwai@suse.de> | 2014-10-20 12:15:50 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2014-10-21 02:52:13 -0400 |
commit | 30d0ae425ab1c9bb0003c3798de78fbf30ddebdc (patch) | |
tree | a352a4284c43b3a230702c095f16d34704c3002f | |
parent | 1bc10bb68d348078af0eb8b64292ec542dcd7634 (diff) |
ALSA: asihpi: Use snd_ctl_enum_info()
... and reduce the open codes.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r-- | sound/pci/asihpi/asihpi.c | 46 |
1 files changed, 5 insertions, 41 deletions
diff --git a/sound/pci/asihpi/asihpi.c b/sound/pci/asihpi/asihpi.c index 5017176bfaa1..ac66b3228a34 100644 --- a/sound/pci/asihpi/asihpi.c +++ b/sound/pci/asihpi/asihpi.c | |||
@@ -1625,18 +1625,7 @@ static const char * const asihpi_aesebu_format_names[] = { | |||
1625 | static int snd_asihpi_aesebu_format_info(struct snd_kcontrol *kcontrol, | 1625 | static int snd_asihpi_aesebu_format_info(struct snd_kcontrol *kcontrol, |
1626 | struct snd_ctl_elem_info *uinfo) | 1626 | struct snd_ctl_elem_info *uinfo) |
1627 | { | 1627 | { |
1628 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | 1628 | return snd_ctl_enum_info(uinfo, 1, 3, asihpi_aesebu_format_names); |
1629 | uinfo->count = 1; | ||
1630 | uinfo->value.enumerated.items = 3; | ||
1631 | |||
1632 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) | ||
1633 | uinfo->value.enumerated.item = | ||
1634 | uinfo->value.enumerated.items - 1; | ||
1635 | |||
1636 | strcpy(uinfo->value.enumerated.name, | ||
1637 | asihpi_aesebu_format_names[uinfo->value.enumerated.item]); | ||
1638 | |||
1639 | return 0; | ||
1640 | } | 1629 | } |
1641 | 1630 | ||
1642 | static int snd_asihpi_aesebu_format_get(struct snd_kcontrol *kcontrol, | 1631 | static int snd_asihpi_aesebu_format_get(struct snd_kcontrol *kcontrol, |
@@ -1863,22 +1852,7 @@ static int snd_asihpi_tuner_band_info(struct snd_kcontrol *kcontrol, | |||
1863 | if (num_bands < 0) | 1852 | if (num_bands < 0) |
1864 | return num_bands; | 1853 | return num_bands; |
1865 | 1854 | ||
1866 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | 1855 | return snd_ctl_enum_info(uinfo, 1, num_bands, asihpi_tuner_band_names); |
1867 | uinfo->count = 1; | ||
1868 | uinfo->value.enumerated.items = num_bands; | ||
1869 | |||
1870 | if (num_bands > 0) { | ||
1871 | if (uinfo->value.enumerated.item >= | ||
1872 | uinfo->value.enumerated.items) | ||
1873 | uinfo->value.enumerated.item = | ||
1874 | uinfo->value.enumerated.items - 1; | ||
1875 | |||
1876 | strcpy(uinfo->value.enumerated.name, | ||
1877 | asihpi_tuner_band_names[ | ||
1878 | tuner_bands[uinfo->value.enumerated.item]]); | ||
1879 | |||
1880 | } | ||
1881 | return 0; | ||
1882 | } | 1856 | } |
1883 | 1857 | ||
1884 | static int snd_asihpi_tuner_band_get(struct snd_kcontrol *kcontrol, | 1858 | static int snd_asihpi_tuner_band_get(struct snd_kcontrol *kcontrol, |
@@ -2253,7 +2227,7 @@ static int snd_asihpi_cmode_info(struct snd_kcontrol *kcontrol, | |||
2253 | u32 h_control = kcontrol->private_value; | 2227 | u32 h_control = kcontrol->private_value; |
2254 | u16 mode; | 2228 | u16 mode; |
2255 | int i; | 2229 | int i; |
2256 | u16 mode_map[6]; | 2230 | const char *mapped_names[6]; |
2257 | int valid_modes = 0; | 2231 | int valid_modes = 0; |
2258 | 2232 | ||
2259 | /* HPI channel mode values can be from 1 to 6 | 2233 | /* HPI channel mode values can be from 1 to 6 |
@@ -2262,24 +2236,14 @@ static int snd_asihpi_cmode_info(struct snd_kcontrol *kcontrol, | |||
2262 | for (i = 0; i < HPI_CHANNEL_MODE_LAST; i++) | 2236 | for (i = 0; i < HPI_CHANNEL_MODE_LAST; i++) |
2263 | if (!hpi_channel_mode_query_mode( | 2237 | if (!hpi_channel_mode_query_mode( |
2264 | h_control, i, &mode)) { | 2238 | h_control, i, &mode)) { |
2265 | mode_map[valid_modes] = mode; | 2239 | mapped_names[valid_modes] = mode_names[mode]; |
2266 | valid_modes++; | 2240 | valid_modes++; |
2267 | } | 2241 | } |
2268 | 2242 | ||
2269 | if (!valid_modes) | 2243 | if (!valid_modes) |
2270 | return -EINVAL; | 2244 | return -EINVAL; |
2271 | 2245 | ||
2272 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | 2246 | return snd_ctl_enum_info(uinfo, 1, valid_modes, mapped_names); |
2273 | uinfo->count = 1; | ||
2274 | uinfo->value.enumerated.items = valid_modes; | ||
2275 | |||
2276 | if (uinfo->value.enumerated.item >= valid_modes) | ||
2277 | uinfo->value.enumerated.item = valid_modes - 1; | ||
2278 | |||
2279 | strcpy(uinfo->value.enumerated.name, | ||
2280 | mode_names[mode_map[uinfo->value.enumerated.item]]); | ||
2281 | |||
2282 | return 0; | ||
2283 | } | 2247 | } |
2284 | 2248 | ||
2285 | static int snd_asihpi_cmode_get(struct snd_kcontrol *kcontrol, | 2249 | static int snd_asihpi_cmode_get(struct snd_kcontrol *kcontrol, |