Skip to content

Commit 9600732

Browse files
cladischtiwai
authored andcommitted
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>
1 parent b532d6b commit 9600732

8 files changed

Lines changed: 46 additions & 104 deletions

File tree

‎include/sound/control.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,14 @@ static inline struct snd_ctl_elem_id *snd_ctl_build_ioff(struct snd_ctl_elem_id
160160
}
161161

162162
/*
163-
* Frequently used control callbacks
163+
* Frequently used control callbacks/helpers
164164
*/
165165
int snd_ctl_boolean_mono_info(struct snd_kcontrol *kcontrol,
166166
struct snd_ctl_elem_info *uinfo);
167167
int snd_ctl_boolean_stereo_info(struct snd_kcontrol *kcontrol,
168168
struct snd_ctl_elem_info *uinfo);
169+
int snd_ctl_enum_info(struct snd_ctl_elem_info *info, unsigned int channels,
170+
unsigned int items, const char *const names[]);
169171

170172
/*
171173
* virtual master control

‎sound/core/control.c‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,7 @@ int snd_ctl_create(struct snd_card *card)
14881488
}
14891489

14901490
/*
1491-
* Frequently used control callbacks
1491+
* Frequently used control callbacks/helpers
14921492
*/
14931493
int snd_ctl_boolean_mono_info(struct snd_kcontrol *kcontrol,
14941494
struct snd_ctl_elem_info *uinfo)
@@ -1513,3 +1513,29 @@ int snd_ctl_boolean_stereo_info(struct snd_kcontrol *kcontrol,
15131513
}
15141514

15151515
EXPORT_SYMBOL(snd_ctl_boolean_stereo_info);
1516+
1517+
/**
1518+
* snd_ctl_enum_info - fills the info structure for an enumerated control
1519+
* @info: the structure to be filled
1520+
* @channels: the number of the control's channels; often one
1521+
* @items: the number of control values; also the size of @names
1522+
* @names: an array containing the names of all control values
1523+
*
1524+
* Sets all required fields in @info to their appropriate values.
1525+
* If the control's accessibility is not the default (readable and writable),
1526+
* the caller has to fill @info->access.
1527+
*/
1528+
int snd_ctl_enum_info(struct snd_ctl_elem_info *info, unsigned int channels,
1529+
unsigned int items, const char *const names[])
1530+
{
1531+
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1532+
info->count = channels;
1533+
info->value.enumerated.items = items;
1534+
if (info->value.enumerated.item >= items)
1535+
info->value.enumerated.item = items - 1;
1536+
strlcpy(info->value.enumerated.name,
1537+
names[info->value.enumerated.item],
1538+
sizeof(info->value.enumerated.name));
1539+
return 0;
1540+
}
1541+
EXPORT_SYMBOL(snd_ctl_enum_info);

‎sound/pci/oxygen/oxygen.c‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,7 @@ static int rolloff_info(struct snd_kcontrol *ctl,
415415
"Sharp Roll-off", "Slow Roll-off"
416416
};
417417

418-
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
419-
info->count = 1;
420-
info->value.enumerated.items = 2;
421-
if (info->value.enumerated.item >= 2)
422-
info->value.enumerated.item = 1;
423-
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
424-
return 0;
418+
return snd_ctl_enum_info(info, 1, 2, names);
425419
}
426420

427421
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)
473467
"None", "High-pass Filter"
474468
};
475469

476-
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
477-
info->count = 1;
478-
info->value.enumerated.items = 2;
479-
if (info->value.enumerated.item >= 2)
480-
info->value.enumerated.item = 1;
481-
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
482-
return 0;
470+
return snd_ctl_enum_info(info, 1, 2, names);
483471
}
484472

485473
static int hpf_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)

‎sound/pci/oxygen/oxygen_mixer.c‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,7 @@ static int upmix_info(struct snd_kcontrol *ctl, struct snd_ctl_elem_info *info)
119119
struct oxygen *chip = ctl->private_data;
120120
unsigned int count = upmix_item_count(chip);
121121

122-
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
123-
info->count = 1;
124-
info->value.enumerated.items = count;
125-
if (info->value.enumerated.item >= count)
126-
info->value.enumerated.item = count - 1;
127-
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
128-
return 0;
122+
return snd_ctl_enum_info(info, 1, count, names);
129123
}
130124

131125
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,
659653
{
660654
static const char *const names[] = { "Mic Jack", "Front Panel" };
661655

662-
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
663-
info->count = 1;
664-
info->value.enumerated.items = 2;
665-
info->value.enumerated.item &= 1;
666-
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
667-
return 0;
656+
return snd_ctl_enum_info(info, 1, 2, names);
668657
}
669658

670659
static int mic_fmic_source_get(struct snd_kcontrol *ctl,

‎sound/pci/oxygen/xonar_cs43xx.c‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,7 @@ static int rolloff_info(struct snd_kcontrol *ctl,
298298
"Fast Roll-off", "Slow Roll-off"
299299
};
300300

301-
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
302-
info->count = 1;
303-
info->value.enumerated.items = 2;
304-
if (info->value.enumerated.item >= 2)
305-
info->value.enumerated.item = 1;
306-
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
307-
return 0;
301+
return snd_ctl_enum_info(info, 1, 2, names);
308302
}
309303

310304
static int rolloff_get(struct snd_kcontrol *ctl,

‎sound/pci/oxygen/xonar_dg.c‎

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,7 @@ static int output_switch_info(struct snd_kcontrol *ctl,
213213
"Speakers", "Headphones", "FP Headphones"
214214
};
215215

216-
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
217-
info->count = 1;
218-
info->value.enumerated.items = 3;
219-
if (info->value.enumerated.item >= 3)
220-
info->value.enumerated.item = 2;
221-
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
222-
return 0;
216+
return snd_ctl_enum_info(info, 1, 3, names);
223217
}
224218

225219
static int output_switch_get(struct snd_kcontrol *ctl,
@@ -276,13 +270,7 @@ static int hp_volume_offset_info(struct snd_kcontrol *ctl,
276270
"< 64 ohms", "64-150 ohms", "150-300 ohms"
277271
};
278272

279-
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
280-
info->count = 1;
281-
info->value.enumerated.items = 3;
282-
if (info->value.enumerated.item >= 3)
283-
info->value.enumerated.item = 2;
284-
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
285-
return 0;
273+
return snd_ctl_enum_info(info, 1, 3, names);
286274
}
287275

288276
static int hp_volume_offset_get(struct snd_kcontrol *ctl,
@@ -390,12 +378,7 @@ static int input_sel_info(struct snd_kcontrol *ctl,
390378
"Mic", "Aux", "Front Mic", "Line"
391379
};
392380

393-
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
394-
info->count = 1;
395-
info->value.enumerated.items = 4;
396-
info->value.enumerated.item &= 3;
397-
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
398-
return 0;
381+
return snd_ctl_enum_info(info, 1, 4, names);
399382
}
400383

401384
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)
453436
{
454437
static const char *const names[2] = { "Active", "Frozen" };
455438

456-
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
457-
info->count = 1;
458-
info->value.enumerated.items = 2;
459-
info->value.enumerated.item &= 1;
460-
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
461-
return 0;
439+
return snd_ctl_enum_info(info, 1, 2, names);
462440
}
463441

464442
static int hpf_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)

‎sound/pci/oxygen/xonar_pcm179x.c‎

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -678,13 +678,7 @@ static int rolloff_info(struct snd_kcontrol *ctl,
678678
"Sharp Roll-off", "Slow Roll-off"
679679
};
680680

681-
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
682-
info->count = 1;
683-
info->value.enumerated.items = 2;
684-
if (info->value.enumerated.item >= 2)
685-
info->value.enumerated.item = 1;
686-
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
687-
return 0;
681+
return snd_ctl_enum_info(info, 1, 2, names);
688682
}
689683

690684
static int rolloff_get(struct snd_kcontrol *ctl,
@@ -748,13 +742,7 @@ static int st_output_switch_info(struct snd_kcontrol *ctl,
748742
"Speakers", "Headphones", "FP Headphones"
749743
};
750744

751-
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
752-
info->count = 1;
753-
info->value.enumerated.items = 3;
754-
if (info->value.enumerated.item >= 3)
755-
info->value.enumerated.item = 2;
756-
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
757-
return 0;
745+
return snd_ctl_enum_info(info, 1, 3, names);
758746
}
759747

760748
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,
809797
"< 64 ohms", "64-300 ohms", "300-600 ohms"
810798
};
811799

812-
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
813-
info->count = 1;
814-
info->value.enumerated.items = 3;
815-
if (info->value.enumerated.item > 2)
816-
info->value.enumerated.item = 2;
817-
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
818-
return 0;
800+
return snd_ctl_enum_info(info, 1, 3, names);
819801
}
820802

821803
static int st_hp_volume_offset_get(struct snd_kcontrol *ctl,

‎sound/pci/oxygen/xonar_wm87x6.c‎

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,6 @@ static int wm8776_field_enum_info(struct snd_kcontrol *ctl,
577577
const char *const *names;
578578

579579
max = (ctl->private_value >> 12) & 0xf;
580-
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
581-
info->count = 1;
582-
info->value.enumerated.items = max + 1;
583-
if (info->value.enumerated.item > max)
584-
info->value.enumerated.item = max;
585580
switch ((ctl->private_value >> 24) & 0x1f) {
586581
case WM8776_ALCCTRL2:
587582
names = hld;
@@ -605,8 +600,7 @@ static int wm8776_field_enum_info(struct snd_kcontrol *ctl,
605600
default:
606601
return -ENXIO;
607602
}
608-
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
609-
return 0;
603+
return snd_ctl_enum_info(info, 1, max + 1, names);
610604
}
611605

612606
static int wm8776_field_volume_info(struct snd_kcontrol *ctl,
@@ -863,13 +857,8 @@ static int wm8776_level_control_info(struct snd_kcontrol *ctl,
863857
static const char *const names[3] = {
864858
"None", "Peak Limiter", "Automatic Level Control"
865859
};
866-
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
867-
info->count = 1;
868-
info->value.enumerated.items = 3;
869-
if (info->value.enumerated.item >= 3)
870-
info->value.enumerated.item = 2;
871-
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
872-
return 0;
860+
861+
return snd_ctl_enum_info(info, 1, 3, names);
873862
}
874863

875864
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)
955944
"None", "High-pass Filter"
956945
};
957946

958-
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
959-
info->count = 1;
960-
info->value.enumerated.items = 2;
961-
if (info->value.enumerated.item >= 2)
962-
info->value.enumerated.item = 1;
963-
strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
964-
return 0;
947+
return snd_ctl_enum_info(info, 1, 2, names);
965948
}
966949

967950
static int hpf_get(struct snd_kcontrol *ctl, struct snd_ctl_elem_value *value)

0 commit comments

Comments
 (0)