ALSA: ice1724: Use snd_ctl_enum_info()
authorTakashi Iwai <tiwai@suse.de>
Mon, 20 Oct 2014 16:18:50 +0000 (18:18 +0200)
committerTakashi Iwai <tiwai@suse.de>
Tue, 21 Oct 2014 07:02:50 +0000 (09:02 +0200)
... and reduce the open codes.  Also add missing const to text arrays.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/pci/ice1712/aureon.c
sound/pci/ice1712/ice1724.c
sound/pci/ice1712/maya44.c
sound/pci/ice1712/phase.c
sound/pci/ice1712/pontis.c
sound/pci/ice1712/prodigy192.c
sound/pci/ice1712/prodigy_hifi.c
sound/pci/ice1712/quartet.c
sound/pci/ice1712/se.c

index 3b3cf4ac9060ac41b9876e52c94a4151e61cdce5..c9411dfff5a4deee94bad34e6da4b0b9d7ca1479 100644 (file)
@@ -205,13 +205,7 @@ static int aureon_universe_inmux_info(struct snd_kcontrol *kcontrol,
        static const char * const texts[3] =
                {"Internal Aux", "Wavetable", "Rear Line-In"};
 
-       uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
-       uinfo->count = 1;
-       uinfo->value.enumerated.items = 3;
-       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;
+       return snd_ctl_enum_info(uinfo, 1, 3, texts);
 }
 
 static int aureon_universe_inmux_get(struct snd_kcontrol *kcontrol,
@@ -1106,20 +1100,10 @@ static int wm_adc_mux_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_in
        };
        struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
 
-       uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
-       uinfo->count = 2;
-       if (ice->eeprom.subvendor == VT1724_SUBDEVICE_AUREON71_UNIVERSE) {
-               uinfo->value.enumerated.items = 8;
-               if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
-                       uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
-               strcpy(uinfo->value.enumerated.name, universe_texts[uinfo->value.enumerated.item]);
-       } else {
-               uinfo->value.enumerated.items = 5;
-               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;
+       if (ice->eeprom.subvendor == VT1724_SUBDEVICE_AUREON71_UNIVERSE)
+               return snd_ctl_enum_info(uinfo, 2, 8, universe_texts);
+       else
+               return snd_ctl_enum_info(uinfo, 2, 5, texts);
 }
 
 static int wm_adc_mux_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -1167,16 +1151,10 @@ static int aureon_cs8415_mux_info(struct snd_kcontrol *kcontrol, struct snd_ctl_
                "CD",
                "Coax"
        };
-       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;
        if (ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71)
-               strcpy(uinfo->value.enumerated.name, prodigy_texts[uinfo->value.enumerated.item]);
+               return snd_ctl_enum_info(uinfo, 1, 2, prodigy_texts);
        else
-               strcpy(uinfo->value.enumerated.name, aureon_texts[uinfo->value.enumerated.item]);
-       return 0;
+               return snd_ctl_enum_info(uinfo, 1, 2, aureon_texts);
 }
 
 static int aureon_cs8415_mux_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -1392,15 +1370,7 @@ static int aureon_oversampling_info(struct snd_kcontrol *k, struct snd_ctl_elem_
 {
        static const char * const texts[2] = { "128x", "64x"    };
 
-       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;
+       return snd_ctl_enum_info(uinfo, 1, 2, texts);
 }
 
 static int aureon_oversampling_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
index 08cb08ac85e6848b448231db3a5ec397c7525c69..f633e3bb4c432da3f6b7470da6809fbac3fab269 100644 (file)
@@ -2049,13 +2049,7 @@ static int snd_vt1724_pro_route_info(struct snd_kcontrol *kcontrol,
                "IEC958 In L", "IEC958 In R", /* 3-4 */
        };
 
-       uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
-       uinfo->count = 1;
-       uinfo->value.enumerated.items = 5;
-       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;
+       return snd_ctl_enum_info(uinfo, 1, 5, texts);
 }
 
 static inline int analog_route_shift(int idx)
index 63aa39f06f02be728081d77c8b5c7d7a32ccdbd4..7de25c4807fdad069d12c89b7a8900b6f1e393ed 100644 (file)
@@ -359,15 +359,7 @@ static int maya_rec_src_info(struct snd_kcontrol *kcontrol,
 {
        static const char * const texts[] = { "Line", "Mic" };
 
-       uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
-       uinfo->count = 1;
-       uinfo->value.enumerated.items = ARRAY_SIZE(texts);
-       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;
+       return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
 }
 
 static int maya_rec_src_get(struct snd_kcontrol *kcontrol,
@@ -411,15 +403,7 @@ static int maya_pb_route_info(struct snd_kcontrol *kcontrol,
                "Input 1", "Input 2", "Input 3", "Input 4"
        };
 
-       uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
-       uinfo->count = 1;
-       uinfo->value.enumerated.items = ARRAY_SIZE(texts);
-       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;
+       return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
 }
 
 static int maya_pb_route_shift(int idx)
index 0011e04f36a23bc08dbeb8fbc2af4ead158ed69d..e9ca89c9174bbe7124ccd7dbaeb76301ebb11cfc 100644 (file)
@@ -723,17 +723,7 @@ static int phase28_oversampling_info(struct snd_kcontrol *k,
 {
        static const char * const texts[2] = { "128x", "64x"    };
 
-       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;
+       return snd_ctl_enum_info(uinfo, 1, 2, texts);
 }
 
 static int phase28_oversampling_get(struct snd_kcontrol *kcontrol,
index 5555eb4b2400696e640422aba6a231f0a47e43a0..5101f40f6fbdd099ec6c96c709e7b5d0195d4695 100644 (file)
@@ -417,13 +417,7 @@ static int cs_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_inf
                "Optical",      /* RXP1 */
                "CD",           /* RXP2 */
        };
-       uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
-       uinfo->count = 1;
-       uinfo->value.enumerated.items = 3;
-       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;
+       return snd_ctl_enum_info(uinfo, 1, 3, texts);
 }
 
 static int cs_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
index f3b491aa3e223ce8fc8825e921ebe9e49067afac..1eb151aaa9659060a9e50c4037f2bcfba31cb3cb 100644 (file)
@@ -284,15 +284,7 @@ static int stac9460_mic_sw_info(struct snd_kcontrol *kcontrol,
 {
        static const char * const texts[2] = { "Line In", "Mic" };
 
-       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;
+       return snd_ctl_enum_info(uinfo, 1, 2, texts);
 }
 
 
@@ -563,13 +555,7 @@ static int ak4114_input_sw_info(struct snd_kcontrol *kcontrol,
 {
        static const char * const texts[2] = { "Toslink", "Coax" };
 
-       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;
+       return snd_ctl_enum_info(uinfo, 1, 2, texts);
 }
 
 
index 2261d1e4915004281d3fcce7b29e243faff41689..2697402b5195799243e115fef1996c7293eb773d 100644 (file)
@@ -537,7 +537,7 @@ static int wm_master_vol_put(struct snd_kcontrol *kcontrol,
 static int wm_adc_mux_enum_info(struct snd_kcontrol *kcontrol,
                                struct snd_ctl_elem_info *uinfo)
 {
-       static char* texts[32] = {
+       static const char * const texts[32] = {
                "NULL", WM_AIN1, WM_AIN2, WM_AIN1 "+" WM_AIN2,
                WM_AIN3, WM_AIN1 "+" WM_AIN3, WM_AIN2 "+" WM_AIN3,
                WM_AIN1 "+" WM_AIN2 "+" WM_AIN3,
@@ -560,14 +560,7 @@ static int wm_adc_mux_enum_info(struct snd_kcontrol *kcontrol,
                WM_AIN1 "+" WM_AIN2 "+" WM_AIN3 "+" WM_AIN4 "+" WM_AIN5
        };
 
-       uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
-       uinfo->count = 1;
-       uinfo->value.enumerated.items = 32;
-       if (uinfo->value.enumerated.item > 31)
-               uinfo->value.enumerated.item = 31;
-       strcpy(uinfo->value.enumerated.name,
-              texts[uinfo->value.enumerated.item]);
-       return 0;
+       return snd_ctl_enum_info(uinfo, 1, 32, texts);
 }
 
 static int wm_adc_mux_enum_get(struct snd_kcontrol *kcontrol,
index 2c2df4b74e01420966853324fbeebae6c66b53fa..d4caf9d059225d3b6bbdd0b6ef1c26c20ab39f32 100644 (file)
@@ -46,7 +46,7 @@ struct qtet_kcontrol_private {
        unsigned int bit;
        void (*set_register)(struct snd_ice1712 *ice, unsigned int val);
        unsigned int (*get_register)(struct snd_ice1712 *ice);
-       unsigned char * const texts[2];
+       const char * const texts[2];
 };
 
 enum {
@@ -554,17 +554,7 @@ static int qtet_ain12_enum_info(struct snd_kcontrol *kcontrol,
 {
        static const char * const texts[3] =
                {"Line In 1/2", "Mic", "Mic + Low-cut"};
-       uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
-       uinfo->count = 1;
-       uinfo->value.enumerated.items = ARRAY_SIZE(texts);
-
-       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;
+       return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
 }
 
 static int qtet_ain12_sw_get(struct snd_kcontrol *kcontrol,
@@ -706,17 +696,8 @@ static int qtet_enum_info(struct snd_kcontrol *kcontrol,
 {
        struct qtet_kcontrol_private private =
                qtet_privates[kcontrol->private_value];
-       uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
-       uinfo->count = 1;
-       uinfo->value.enumerated.items = ARRAY_SIZE(private.texts);
-
-       if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
-               uinfo->value.enumerated.item =
-                       uinfo->value.enumerated.items - 1;
-       strcpy(uinfo->value.enumerated.name,
-                       private.texts[uinfo->value.enumerated.item]);
-
-       return 0;
+       return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(private.texts),
+                                private.texts);
 }
 
 static int qtet_sw_get(struct snd_kcontrol *kcontrol,
index ffd894bb4507b2ea919b18f980c09007f6a8f8bf..1c5d5b22c7a0d2ee4ccccf7e1bf6760f42ab6cca 100644 (file)
@@ -452,14 +452,7 @@ static int se200pci_cont_enum_info(struct snd_kcontrol *kc,
        c = se200pci_get_enum_count(n);
        if (!c)
                return -EINVAL;
-       uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
-       uinfo->count = 1;
-       uinfo->value.enumerated.items = c;
-       if (uinfo->value.enumerated.item >= c)
-               uinfo->value.enumerated.item = c - 1;
-       strcpy(uinfo->value.enumerated.name,
-              se200pci_cont[n].member[uinfo->value.enumerated.item]);
-       return 0;
+       return snd_ctl_enum_info(uinfo, 1, c, se200pci_cont[n].member);
 }
 
 static int se200pci_cont_volume_get(struct snd_kcontrol *kc,