Skip to content

Commit 0e8f986

Browse files
committed
ALSA: hda/via - Simplify control management
This patch replaces the control element creations in VIA codec driver with the standard snd_hda_gen_add_kctl() calls as a cleanup. There are two major fields targeted by this patch: the beep controls and static init controls. The former is converted just like other codec drivers do. The spec->beep_amp field can be eliminated by this change as well. The latter, static init controls, are replaced simply with explicit snd_hda_gen_add_kctl() calls. After these conversions, via_build_controls() becomes superfluous and replaced with snd_hda_gen_build_controls(), too. Signed-off-by: Takashi Iwai <[email protected]>
1 parent fcbdcc1 commit 0e8f986

File tree

1 file changed

+44
-86
lines changed

1 file changed

+44
-86
lines changed

sound/pci/hda/patch_via.c

Lines changed: 44 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ struct via_spec {
9191
struct hda_gen_spec gen;
9292

9393
/* codec parameterization */
94-
const struct snd_kcontrol_new *mixers[6];
95-
unsigned int num_mixers;
96-
9794
const struct hda_verb *init_verbs[5];
9895
unsigned int num_iverbs;
9996

@@ -107,8 +104,6 @@ struct via_spec {
107104
/* work to check hp jack state */
108105
int hp_work_active;
109106
int vt1708_jack_detect;
110-
111-
unsigned int beep_amp;
112107
};
113108

114109
static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
@@ -262,69 +257,51 @@ static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
262257
return 1;
263258
}
264259

265-
static const struct snd_kcontrol_new via_pin_power_ctl_enum[] = {
266-
{
260+
static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
267261
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
268262
.name = "Dynamic Power-Control",
269263
.info = via_pin_power_ctl_info,
270264
.get = via_pin_power_ctl_get,
271265
.put = via_pin_power_ctl_put,
272-
},
273-
{} /* terminator */
274266
};
275267

276268
#ifdef CONFIG_SND_HDA_INPUT_BEEP
277-
static inline void set_beep_amp(struct via_spec *spec, hda_nid_t nid,
278-
int idx, int dir)
279-
{
280-
spec->gen.beep_nid = nid;
281-
spec->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir);
282-
}
283-
284269
/* additional beep mixers; the actual parameters are overwritten at build */
285-
static const struct snd_kcontrol_new cxt_beep_mixer[] = {
270+
static const struct snd_kcontrol_new via_beep_mixer[] = {
286271
HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
287272
HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
288-
{ } /* end */
289273
};
290274

291-
/* create beep controls if needed */
292-
static int add_beep_ctls(struct hda_codec *codec)
275+
static int set_beep_amp(struct via_spec *spec, hda_nid_t nid,
276+
int idx, int dir)
293277
{
294-
struct via_spec *spec = codec->spec;
295-
int err;
278+
struct snd_kcontrol_new *knew;
279+
unsigned int beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir);
280+
int i;
296281

297-
if (spec->beep_amp) {
298-
const struct snd_kcontrol_new *knew;
299-
for (knew = cxt_beep_mixer; knew->name; knew++) {
300-
struct snd_kcontrol *kctl;
301-
kctl = snd_ctl_new1(knew, codec);
302-
if (!kctl)
303-
return -ENOMEM;
304-
kctl->private_value = spec->beep_amp;
305-
err = snd_hda_ctl_add(codec, 0, kctl);
306-
if (err < 0)
307-
return err;
308-
}
282+
spec->gen.beep_nid = nid;
283+
for (i = 0; i < ARRAY_SIZE(via_beep_mixer); i++) {
284+
knew = snd_hda_gen_add_kctl(&spec->gen, NULL,
285+
&via_beep_mixer[i]);
286+
if (!knew)
287+
return -ENOMEM;
288+
knew->private_value = beep_amp;
309289
}
310290
return 0;
311291
}
312292

313-
static void auto_parse_beep(struct hda_codec *codec)
293+
static int auto_parse_beep(struct hda_codec *codec)
314294
{
315295
struct via_spec *spec = codec->spec;
316296
hda_nid_t nid;
317297

318298
for_each_hda_codec_node(nid, codec)
319-
if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
320-
set_beep_amp(spec, nid, 0, HDA_OUTPUT);
321-
break;
322-
}
299+
if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP)
300+
return set_beep_amp(spec, nid, 0, HDA_OUTPUT);
301+
return 0;
323302
}
324303
#else
325-
#define set_beep_amp(spec, nid, idx, dir) /* NOP */
326-
#define add_beep_ctls(codec) 0
327-
#define auto_parse_beep(codec)
304+
#define auto_parse_beep(codec) 0
328305
#endif
329306

330307
/* check AA path's mute status */
@@ -403,30 +380,6 @@ static void analog_low_current_mode(struct hda_codec *codec)
403380
return __analog_low_current_mode(codec, false);
404381
}
405382

406-
static int via_build_controls(struct hda_codec *codec)
407-
{
408-
struct via_spec *spec = codec->spec;
409-
int err, i;
410-
411-
err = snd_hda_gen_build_controls(codec);
412-
if (err < 0)
413-
return err;
414-
415-
err = add_beep_ctls(codec);
416-
if (err < 0)
417-
return err;
418-
419-
spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum;
420-
421-
for (i = 0; i < spec->num_mixers; i++) {
422-
err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
423-
if (err < 0)
424-
return err;
425-
}
426-
427-
return 0;
428-
}
429-
430383
static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo,
431384
struct hda_codec *codec,
432385
struct snd_pcm_substream *substream,
@@ -481,7 +434,7 @@ static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
481434
static int via_init(struct hda_codec *codec);
482435

483436
static const struct hda_codec_ops via_patch_ops = {
484-
.build_controls = via_build_controls,
437+
.build_controls = snd_hda_gen_build_controls,
485438
.build_pcms = snd_hda_gen_build_pcms,
486439
.init = via_init,
487440
.free = via_free,
@@ -545,16 +498,13 @@ static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
545498
return 1;
546499
}
547500

548-
static const struct snd_kcontrol_new vt1708_jack_detect_ctl[] = {
549-
{
501+
static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
550502
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
551503
.name = "Jack Detect",
552504
.count = 1,
553505
.info = snd_ctl_boolean_mono_info,
554506
.get = vt1708_jack_detect_get,
555507
.put = vt1708_jack_detect_put,
556-
},
557-
{} /* terminator */
558508
};
559509

560510
static const struct badness_table via_main_out_badness = {
@@ -586,12 +536,17 @@ static int via_parse_auto_config(struct hda_codec *codec)
586536
if (err < 0)
587537
return err;
588538

589-
auto_parse_beep(codec);
590-
591539
err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
592540
if (err < 0)
593541
return err;
594542

543+
err = auto_parse_beep(codec);
544+
if (err < 0)
545+
return err;
546+
547+
if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &via_pin_power_ctl_enum))
548+
return -ENOMEM;
549+
595550
/* disable widget PM at start for compatibility */
596551
codec->power_save_node = 0;
597552
spec->gen.power_down_unused = 0;
@@ -623,7 +578,7 @@ static int vt1708_build_controls(struct hda_codec *codec)
623578
int err;
624579
int old_interval = codec->jackpoll_interval;
625580
codec->jackpoll_interval = msecs_to_jiffies(100);
626-
err = via_build_controls(codec);
581+
err = snd_hda_gen_build_controls(codec);
627582
codec->jackpoll_interval = old_interval;
628583
return err;
629584
}
@@ -690,7 +645,10 @@ static int patch_vt1708(struct hda_codec *codec)
690645
goto error;
691646

692647
/* add jack detect on/off control */
693-
spec->mixers[spec->num_mixers++] = vt1708_jack_detect_ctl;
648+
if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &vt1708_jack_detect_ctl)) {
649+
err = -ENOMEM;
650+
goto error;
651+
}
694652

695653
spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
696654

@@ -967,26 +925,22 @@ static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
967925
return 1;
968926
}
969927

970-
static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
971-
HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
972-
{
928+
static const struct snd_kcontrol_new vt1716s_dmic_mixer_vol =
929+
HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT);
930+
static const struct snd_kcontrol_new vt1716s_dmic_mixer_sw = {
973931
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
974932
.name = "Digital Mic Capture Switch",
975933
.subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
976934
.count = 1,
977935
.info = vt1716s_dmic_info,
978936
.get = vt1716s_dmic_get,
979937
.put = vt1716s_dmic_put,
980-
},
981-
{} /* end */
982938
};
983939

984940

985941
/* mono-out mixer elements */
986-
static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
987-
HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
988-
{ } /* end */
989-
};
942+
static const struct snd_kcontrol_new vt1716S_mono_out_mixer =
943+
HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT);
990944

991945
static const struct hda_verb vt1716S_init_verbs[] = {
992946
/* Enable Boost Volume backdoor */
@@ -1019,8 +973,12 @@ static int patch_vt1716S(struct hda_codec *codec)
1019973

1020974
spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
1021975

1022-
spec->mixers[spec->num_mixers++] = vt1716s_dmic_mixer;
1023-
spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
976+
if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &vt1716s_dmic_mixer_vol) ||
977+
!snd_hda_gen_add_kctl(&spec->gen, NULL, &vt1716s_dmic_mixer_sw) ||
978+
!snd_hda_gen_add_kctl(&spec->gen, NULL, &vt1716S_mono_out_mixer)) {
979+
err = -ENOMEM;
980+
goto error;
981+
}
1024982

1025983
return 0;
1026984

0 commit comments

Comments
 (0)