@@ -91,9 +91,6 @@ struct via_spec {
91
91
struct hda_gen_spec gen ;
92
92
93
93
/* codec parameterization */
94
- const struct snd_kcontrol_new * mixers [6 ];
95
- unsigned int num_mixers ;
96
-
97
94
const struct hda_verb * init_verbs [5 ];
98
95
unsigned int num_iverbs ;
99
96
@@ -107,8 +104,6 @@ struct via_spec {
107
104
/* work to check hp jack state */
108
105
int hp_work_active ;
109
106
int vt1708_jack_detect ;
110
-
111
- unsigned int beep_amp ;
112
107
};
113
108
114
109
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,
262
257
return 1 ;
263
258
}
264
259
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 = {
267
261
.iface = SNDRV_CTL_ELEM_IFACE_MIXER ,
268
262
.name = "Dynamic Power-Control" ,
269
263
.info = via_pin_power_ctl_info ,
270
264
.get = via_pin_power_ctl_get ,
271
265
.put = via_pin_power_ctl_put ,
272
- },
273
- {} /* terminator */
274
266
};
275
267
276
268
#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
-
284
269
/* 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 [] = {
286
271
HDA_CODEC_VOLUME_MONO ("Beep Playback Volume" , 0 , 1 , 0 , HDA_OUTPUT ),
287
272
HDA_CODEC_MUTE_BEEP_MONO ("Beep Playback Switch" , 0 , 1 , 0 , HDA_OUTPUT ),
288
- { } /* end */
289
273
};
290
274
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 )
293
277
{
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 ;
296
281
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 ;
309
289
}
310
290
return 0 ;
311
291
}
312
292
313
- static void auto_parse_beep (struct hda_codec * codec )
293
+ static int auto_parse_beep (struct hda_codec * codec )
314
294
{
315
295
struct via_spec * spec = codec -> spec ;
316
296
hda_nid_t nid ;
317
297
318
298
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 ;
323
302
}
324
303
#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
328
305
#endif
329
306
330
307
/* check AA path's mute status */
@@ -403,30 +380,6 @@ static void analog_low_current_mode(struct hda_codec *codec)
403
380
return __analog_low_current_mode (codec , false);
404
381
}
405
382
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
-
430
383
static void via_playback_pcm_hook (struct hda_pcm_stream * hinfo ,
431
384
struct hda_codec * codec ,
432
385
struct snd_pcm_substream * substream ,
@@ -481,7 +434,7 @@ static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
481
434
static int via_init (struct hda_codec * codec );
482
435
483
436
static const struct hda_codec_ops via_patch_ops = {
484
- .build_controls = via_build_controls ,
437
+ .build_controls = snd_hda_gen_build_controls ,
485
438
.build_pcms = snd_hda_gen_build_pcms ,
486
439
.init = via_init ,
487
440
.free = via_free ,
@@ -545,16 +498,13 @@ static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
545
498
return 1 ;
546
499
}
547
500
548
- static const struct snd_kcontrol_new vt1708_jack_detect_ctl [] = {
549
- {
501
+ static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
550
502
.iface = SNDRV_CTL_ELEM_IFACE_MIXER ,
551
503
.name = "Jack Detect" ,
552
504
.count = 1 ,
553
505
.info = snd_ctl_boolean_mono_info ,
554
506
.get = vt1708_jack_detect_get ,
555
507
.put = vt1708_jack_detect_put ,
556
- },
557
- {} /* terminator */
558
508
};
559
509
560
510
static const struct badness_table via_main_out_badness = {
@@ -586,12 +536,17 @@ static int via_parse_auto_config(struct hda_codec *codec)
586
536
if (err < 0 )
587
537
return err ;
588
538
589
- auto_parse_beep (codec );
590
-
591
539
err = snd_hda_gen_parse_auto_config (codec , & spec -> gen .autocfg );
592
540
if (err < 0 )
593
541
return err ;
594
542
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
+
595
550
/* disable widget PM at start for compatibility */
596
551
codec -> power_save_node = 0 ;
597
552
spec -> gen .power_down_unused = 0 ;
@@ -623,7 +578,7 @@ static int vt1708_build_controls(struct hda_codec *codec)
623
578
int err ;
624
579
int old_interval = codec -> jackpoll_interval ;
625
580
codec -> jackpoll_interval = msecs_to_jiffies (100 );
626
- err = via_build_controls (codec );
581
+ err = snd_hda_gen_build_controls (codec );
627
582
codec -> jackpoll_interval = old_interval ;
628
583
return err ;
629
584
}
@@ -690,7 +645,10 @@ static int patch_vt1708(struct hda_codec *codec)
690
645
goto error ;
691
646
692
647
/* 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
+ }
694
652
695
653
spec -> init_verbs [spec -> num_iverbs ++ ] = vt1708_init_verbs ;
696
654
@@ -967,26 +925,22 @@ static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
967
925
return 1 ;
968
926
}
969
927
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 = {
973
931
.iface = SNDRV_CTL_ELEM_IFACE_MIXER ,
974
932
.name = "Digital Mic Capture Switch" ,
975
933
.subdevice = HDA_SUBDEV_NID_FLAG | 0x26 ,
976
934
.count = 1 ,
977
935
.info = vt1716s_dmic_info ,
978
936
.get = vt1716s_dmic_get ,
979
937
.put = vt1716s_dmic_put ,
980
- },
981
- {} /* end */
982
938
};
983
939
984
940
985
941
/* 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 );
990
944
991
945
static const struct hda_verb vt1716S_init_verbs [] = {
992
946
/* Enable Boost Volume backdoor */
@@ -1019,8 +973,12 @@ static int patch_vt1716S(struct hda_codec *codec)
1019
973
1020
974
spec -> init_verbs [spec -> num_iverbs ++ ] = vt1716S_init_verbs ;
1021
975
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
+ }
1024
982
1025
983
return 0 ;
1026
984
0 commit comments