24 #include <linux/slab.h>
25 #include <linux/export.h>
49 #define MAX_PCM_VOLS 2
74 #define MAX_LOOPBACK_AMPS 7
77 struct hda_amp_list loopback_list[MAX_LOOPBACK_AMPS + 1];
84 #define defcfg_type(node) (((node)->def_cfg & AC_DEFCFG_DEVICE) >> \
85 AC_DEFCFG_DEVICE_SHIFT)
86 #define defcfg_location(node) (((node)->def_cfg & AC_DEFCFG_LOCATION) >> \
87 AC_DEFCFG_LOCATION_SHIFT)
88 #define defcfg_port_conn(node) (((node)->def_cfg & AC_DEFCFG_PORT_CONN) >> \
89 AC_DEFCFG_PORT_CONN_SHIFT)
124 node->
wid_caps = get_wcaps(codec, nid);
175 static int build_afg_tree(
struct hda_codec *codec)
188 if (! nid || nodes < 0) {
194 for (i = 0; i < nodes; i++, nid++) {
195 if ((err = add_new_node(codec, spec, nid)) < 0)
212 if (node->
nid == nid)
223 unsigned int val, ofs;
238 unsigned int val, ofs;
262 static void clear_check_flags(
struct hda_gspec *spec)
294 return node == spec->
dac_node[dac_idx];
306 for (i = 0; i < node->
nconns; i++) {
307 child = hda_get_node(spec, node->
conn_list[i]);
310 err = parse_output_path(codec, spec, child, dac_idx);
318 select_input_connection(codec, node, i);
319 unmute_input(codec, node, i);
320 unmute_output(codec, node);
323 !(spec->
dac_node[dac_idx]->wid_caps &
326 (node->
wid_caps & AC_WCAP_OUT_AMP)) {
360 if (jack_type >= 0) {
370 clear_check_flags(spec);
371 err = parse_output_path(codec, spec, node, 0);
375 err = parse_output_path(codec, spec, node, 1);
381 unmute_output(codec, node);
398 static int parse_output(
struct hda_codec *codec)
429 spec->
out_pin_node[0] = parse_output_jack(codec, spec, -1);
431 snd_printd(
"hda_generic: no proper output path found\n");
469 static const char *get_input_type(
struct hda_gnode *node,
unsigned int *pinctl)
520 for (i = 0; i < node->
nconns; i++) {
522 child = hda_get_node(spec, node->
conn_list[i]);
525 err = parse_adc_sub_nodes(codec, spec, child, idx);
533 select_input_connection(codec, node, i);
534 unmute_input(codec, node, i);
535 unmute_output(codec, node);
559 type = get_input_type(node, &pinctl);
569 unmute_input(codec, node, 0);
587 clear_check_flags(spec);
590 unmute_input(codec, adc_node, 0);
598 for (i = 0; i < adc_node->
nconns; i++) {
599 node = hda_get_node(spec, adc_node->
conn_list[i]);
601 err = parse_adc_sub_nodes(codec, spec, node, i);
607 for (i = 0; i < adc_node->
nconns; i++) {
608 node = hda_get_node(spec, adc_node->
conn_list[i]);
610 err = parse_adc_sub_nodes(codec, spec, node, i);
620 for (i = 0; i < spec->
input_mux.num_items; i++)
631 static int parse_input(
struct hda_codec *codec)
646 err = parse_input_path(codec, node);
653 snd_printd(
"hda_generic: no proper input path found\n");
664 if (spec->num_loopbacks >= MAX_LOOPBACK_AMPS) {
668 p = &spec->loopback_list[spec->num_loopbacks++];
672 spec->loopback.amplist = spec->loopback_list;
675 #define add_input_loopback(codec,nid,dir,idx)
682 unsigned int index,
const char *type,
683 const char *dir_sfx,
int is_loopback)
691 sprintf(name,
"%s %s Switch", type, dir_sfx);
693 sprintf(name,
"%s Switch", dir_sfx);
696 knew = (
struct snd_kcontrol_new)HDA_CODEC_MUTE(name, node->nid, index, HDA_INPUT);
699 snd_printdd(
"[%s] NID=0x%x, DIR=IN, IDX=0x%x\n", name, node->nid, index);
707 knew = (
struct snd_kcontrol_new)HDA_CODEC_MUTE(name, node->nid, 0, HDA_OUTPUT);
710 snd_printdd(
"[%s] NID=0x%x, DIR=OUT\n", name, node->nid);
719 sprintf(name,
"%s %s Volume", type, dir_sfx);
721 sprintf(name,
"%s Volume", dir_sfx);
724 knew = (
struct snd_kcontrol_new)HDA_CODEC_VOLUME(name, node->nid, index, HDA_INPUT);
725 snd_printdd(
"[%s] NID=0x%x, DIR=IN, IDX=0x%x\n", name, node->nid, index);
733 knew = (
struct snd_kcontrol_new)HDA_CODEC_VOLUME(name, node->nid, 0, HDA_OUTPUT);
734 snd_printdd(
"[%s] NID=0x%x, DIR=OUT\n", name, node->nid);
748 static int check_existing_control(
struct hda_codec *codec,
const char *type,
const char *dir)
751 memset(&
id, 0,
sizeof(
id));
766 static int create_output_mixers(
struct hda_codec *codec,
767 const char *
const *names)
773 err = create_mixer(codec, spec->
pcm_vol[i].node,
775 names[i],
"Playback", 0);
782 static int build_output_controls(
struct hda_codec *codec)
785 static const char *
const types_speaker[] = {
"Speaker",
"Headphone" };
786 static const char *
const types_line[] = {
"Front",
"Headphone" };
790 return create_mixer(codec, spec->
pcm_vol[0].node,
792 "Master",
"Playback", 0);
795 return create_output_mixers(codec, types_speaker);
797 return create_output_mixers(codec, types_line);
803 static int build_input_controls(
struct hda_codec *codec)
810 .name =
"Capture Source",
811 .info = capture_source_info,
812 .get = capture_source_get,
813 .put = capture_source_put,
816 if (! adc_node || ! spec->
input_mux.num_items)
820 select_input_connection(codec, adc_node,
826 err = create_mixer(codec, adc_node,
845 for (i = 0; i < spec->
input_mux.num_items; i++) {
848 sprintf(name,
"%s Capture Volume",
852 spec->input_mux.
items[i].index,
882 if (node == dest_node) {
887 for (i = 0; i < node->
nconns; i++) {
891 err = parse_loopback_path(codec, spec, child, dest_node, type);
896 err = create_mixer(codec, node, i, type,
907 select_input_connection(codec, node, i);
908 unmute_input(codec, node, i);
909 unmute_output(codec, node);
919 static int build_loopback_controls(
struct hda_codec *codec)
935 type = get_input_type(node,
NULL);
937 if (check_existing_control(codec, type,
"Playback"))
939 clear_check_flags(spec);
940 err = parse_loopback_path(codec, spec,
955 static int build_generic_controls(
struct hda_codec *codec)
959 if ((err = build_input_controls(codec)) < 0 ||
960 (err = build_output_controls(codec)) < 0 ||
961 (err = build_loopback_controls(codec)) < 0)
978 unsigned int stream_tag,
986 stream_tag, 0, format);
1001 static int build_generic_pcms(
struct hda_codec *codec)
1014 info->
name =
"HDA Generic";
1016 info->
stream[0] = generic_pcm_playback;
1019 info->
stream[0].ops.prepare = generic_pcm2_prepare;
1020 info->
stream[0].ops.cleanup = generic_pcm2_cleanup;
1024 info->
stream[1] = generic_pcm_playback;
1043 .build_controls = build_generic_controls,
1044 .build_pcms = build_generic_pcms,
1045 .free = snd_hda_generic_free,
1047 .check_power_status = generic_check_power_status,
1070 if ((err = build_afg_tree(codec)) < 0)
1073 if ((err = parse_input(codec)) < 0 ||
1074 (err = parse_output(codec)) < 0)
1082 snd_hda_generic_free(codec);