Commit e5b7b1fe authored by Adrian Knoth's avatar Adrian Knoth Committed by Takashi Iwai

ALSA: hdspm - Remove duplicate code from ALSA controls

Considerably shorten the code by using a macro. Though this won't lower
the binary size, it makes the source more readable.
Signed-off-by: default avatarAdrian Knoth <adi@drcomp.erfurt.thur.de>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 696be0fb
...@@ -2175,6 +2175,16 @@ static int hdspm_get_s1_sample_rate(struct hdspm *hdspm, unsigned int idx) ...@@ -2175,6 +2175,16 @@ static int hdspm_get_s1_sample_rate(struct hdspm *hdspm, unsigned int idx)
return (status >> (idx*4)) & 0xF; return (status >> (idx*4)) & 0xF;
} }
#define ENUMERATED_CTL_INFO(info, texts) \
{ \
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]); \
}
#define HDSPM_AUTOSYNC_SAMPLE_RATE(xname, xindex) \ #define HDSPM_AUTOSYNC_SAMPLE_RATE(xname, xindex) \
...@@ -2190,14 +2200,7 @@ static int hdspm_get_s1_sample_rate(struct hdspm *hdspm, unsigned int idx) ...@@ -2190,14 +2200,7 @@ static int hdspm_get_s1_sample_rate(struct hdspm *hdspm, unsigned int idx)
static int snd_hdspm_info_autosync_sample_rate(struct snd_kcontrol *kcontrol, static int snd_hdspm_info_autosync_sample_rate(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo) struct snd_ctl_elem_info *uinfo)
{ {
uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; ENUMERATED_CTL_INFO(uinfo, texts_freq);
uinfo->count = 1;
uinfo->value.enumerated.items = 10;
if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
strcpy(uinfo->value.enumerated.name,
texts_freq[uinfo->value.enumerated.item]);
return 0; return 0;
} }
...@@ -2363,15 +2366,7 @@ static int snd_hdspm_info_system_clock_mode(struct snd_kcontrol *kcontrol, ...@@ -2363,15 +2366,7 @@ static int snd_hdspm_info_system_clock_mode(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo) struct snd_ctl_elem_info *uinfo)
{ {
static char *texts[] = { "Master", "AutoSync" }; static char *texts[] = { "Master", "AutoSync" };
ENUMERATED_CTL_INFO(uinfo, texts);
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 0;
} }
...@@ -3021,17 +3016,7 @@ static int snd_hdspm_info_input_select(struct snd_kcontrol *kcontrol, ...@@ -3021,17 +3016,7 @@ static int snd_hdspm_info_input_select(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo) struct snd_ctl_elem_info *uinfo)
{ {
static char *texts[] = { "optical", "coaxial" }; static char *texts[] = { "optical", "coaxial" };
ENUMERATED_CTL_INFO(uinfo, texts);
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 0;
} }
...@@ -3093,17 +3078,7 @@ static int snd_hdspm_info_ds_wire(struct snd_kcontrol *kcontrol, ...@@ -3093,17 +3078,7 @@ static int snd_hdspm_info_ds_wire(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo) struct snd_ctl_elem_info *uinfo)
{ {
static char *texts[] = { "Single", "Double" }; static char *texts[] = { "Single", "Double" };
ENUMERATED_CTL_INFO(uinfo, texts);
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 0;
} }
...@@ -3176,17 +3151,7 @@ static int snd_hdspm_info_qs_wire(struct snd_kcontrol *kcontrol, ...@@ -3176,17 +3151,7 @@ static int snd_hdspm_info_qs_wire(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo) struct snd_ctl_elem_info *uinfo)
{ {
static char *texts[] = { "Single", "Double", "Quad" }; static char *texts[] = { "Single", "Double", "Quad" };
ENUMERATED_CTL_INFO(uinfo, texts);
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 0;
} }
...@@ -3262,17 +3227,7 @@ static int snd_hdspm_info_madi_speedmode(struct snd_kcontrol *kcontrol, ...@@ -3262,17 +3227,7 @@ static int snd_hdspm_info_madi_speedmode(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo) struct snd_ctl_elem_info *uinfo)
{ {
static char *texts[] = { "Single", "Double", "Quad" }; static char *texts[] = { "Single", "Double", "Quad" };
ENUMERATED_CTL_INFO(uinfo, texts);
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 0;
} }
...@@ -3497,14 +3452,7 @@ static int snd_hdspm_info_sync_check(struct snd_kcontrol *kcontrol, ...@@ -3497,14 +3452,7 @@ static int snd_hdspm_info_sync_check(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo) struct snd_ctl_elem_info *uinfo)
{ {
static char *texts[] = { "No Lock", "Lock", "Sync", "N/A" }; static char *texts[] = { "No Lock", "Lock", "Sync", "N/A" };
uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; ENUMERATED_CTL_INFO(uinfo, texts);
uinfo->count = 1;
uinfo->value.enumerated.items = 4;
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 0;
} }
...@@ -3860,17 +3808,7 @@ static int snd_hdspm_info_tco_sample_rate(struct snd_kcontrol *kcontrol, ...@@ -3860,17 +3808,7 @@ static int snd_hdspm_info_tco_sample_rate(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo) struct snd_ctl_elem_info *uinfo)
{ {
static char *texts[] = { "44.1 kHz", "48 kHz" }; static char *texts[] = { "44.1 kHz", "48 kHz" };
uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; ENUMERATED_CTL_INFO(uinfo, texts);
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 0;
} }
...@@ -3916,17 +3854,7 @@ static int snd_hdspm_info_tco_pull(struct snd_kcontrol *kcontrol, ...@@ -3916,17 +3854,7 @@ static int snd_hdspm_info_tco_pull(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo) struct snd_ctl_elem_info *uinfo)
{ {
static char *texts[] = { "0", "+ 0.1 %", "- 0.1 %", "+ 4 %", "- 4 %" }; static char *texts[] = { "0", "+ 0.1 %", "- 0.1 %", "+ 4 %", "- 4 %" };
uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; ENUMERATED_CTL_INFO(uinfo, texts);
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 0;
} }
...@@ -3971,17 +3899,7 @@ static int snd_hdspm_info_tco_wck_conversion(struct snd_kcontrol *kcontrol, ...@@ -3971,17 +3899,7 @@ static int snd_hdspm_info_tco_wck_conversion(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo) struct snd_ctl_elem_info *uinfo)
{ {
static char *texts[] = { "1:1", "44.1 -> 48", "48 -> 44.1" }; static char *texts[] = { "1:1", "44.1 -> 48", "48 -> 44.1" };
uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; ENUMERATED_CTL_INFO(uinfo, texts);
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 0;
} }
...@@ -4028,17 +3946,7 @@ static int snd_hdspm_info_tco_frame_rate(struct snd_kcontrol *kcontrol, ...@@ -4028,17 +3946,7 @@ static int snd_hdspm_info_tco_frame_rate(struct snd_kcontrol *kcontrol,
{ {
static char *texts[] = { "24 fps", "25 fps", "29.97fps", static char *texts[] = { "24 fps", "25 fps", "29.97fps",
"29.97 dfps", "30 fps", "30 dfps" }; "29.97 dfps", "30 fps", "30 dfps" };
uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; ENUMERATED_CTL_INFO(uinfo, texts);
uinfo->count = 1;
uinfo->value.enumerated.items = 6;
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 0;
} }
...@@ -4084,17 +3992,7 @@ static int snd_hdspm_info_tco_sync_source(struct snd_kcontrol *kcontrol, ...@@ -4084,17 +3992,7 @@ static int snd_hdspm_info_tco_sync_source(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_info *uinfo) struct snd_ctl_elem_info *uinfo)
{ {
static char *texts[] = { "LTC", "Video", "WCK" }; static char *texts[] = { "LTC", "Video", "WCK" };
uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; ENUMERATED_CTL_INFO(uinfo, texts);
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 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment