diff options
author | Takashi Iwai <tiwai@suse.de> | 2011-06-22 09:23:25 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2011-06-22 09:23:25 -0400 |
commit | a86a88eaf6db7bcc3900d0b7d4755474cc73201f (patch) | |
tree | d18d1d9c3bc36b964145d69715584c62f784602e /sound/pci/hda/patch_via.c | |
parent | f2b1c9f031d6b7604f861223f9e7024e6597b201 (diff) |
ALSA: hda - Implement dynamic-ADC switching for VIA codecs
Some VIA codecs like VT1702 provide the input-route only to specific
ADCs such as digital-mic inputs. These routes aren't covered by the
normal primary ADC, and for now, user had to open the capture stream
assigned to that special ADC manually for using such inputs.
This patch implements a way to switch the current ADC dynamically per
the input-source selection in such a case. When this workaround is
activated, the driver provides only one capture stream and one input-
source control but with the full possible inputs. The driver switches
the ADC to be used (or being used) according to the input-source on the
fly.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci/hda/patch_via.c')
-rw-r--r-- | sound/pci/hda/patch_via.c | 516 |
1 files changed, 391 insertions, 125 deletions
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index af47b9aca974..fb5468b4c55a 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c | |||
@@ -99,6 +99,14 @@ struct nid_path { | |||
99 | unsigned int mute_ctl; | 99 | unsigned int mute_ctl; |
100 | }; | 100 | }; |
101 | 101 | ||
102 | /* input-path */ | ||
103 | struct via_input { | ||
104 | hda_nid_t pin; /* input-pin or aa-mix */ | ||
105 | int adc_idx; /* ADC index to be used */ | ||
106 | int mux_idx; /* MUX index (if any) */ | ||
107 | const char *label; /* input-source label */ | ||
108 | }; | ||
109 | |||
102 | struct via_spec { | 110 | struct via_spec { |
103 | /* codec parameterization */ | 111 | /* codec parameterization */ |
104 | const struct snd_kcontrol_new *mixers[6]; | 112 | const struct snd_kcontrol_new *mixers[6]; |
@@ -135,16 +143,22 @@ struct via_spec { | |||
135 | hda_nid_t dig_in_nid; | 143 | hda_nid_t dig_in_nid; |
136 | 144 | ||
137 | /* capture source */ | 145 | /* capture source */ |
138 | const struct hda_input_mux *input_mux; | 146 | bool dyn_adc_switch; |
147 | int num_inputs; | ||
148 | struct via_input inputs[AUTO_CFG_MAX_INS + 1]; | ||
139 | unsigned int cur_mux[3]; | 149 | unsigned int cur_mux[3]; |
140 | 150 | ||
151 | /* dynamic ADC switching */ | ||
152 | hda_nid_t cur_adc; | ||
153 | unsigned int cur_adc_stream_tag; | ||
154 | unsigned int cur_adc_format; | ||
155 | |||
141 | /* PCM information */ | 156 | /* PCM information */ |
142 | struct hda_pcm pcm_rec[3]; | 157 | struct hda_pcm pcm_rec[3]; |
143 | 158 | ||
144 | /* dynamic controls, init_verbs and input_mux */ | 159 | /* dynamic controls, init_verbs and input_mux */ |
145 | struct auto_pin_cfg autocfg; | 160 | struct auto_pin_cfg autocfg; |
146 | struct snd_array kctls; | 161 | struct snd_array kctls; |
147 | struct hda_input_mux private_imux[2]; | ||
148 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; | 162 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; |
149 | 163 | ||
150 | /* HP mode source */ | 164 | /* HP mode source */ |
@@ -171,6 +185,10 @@ struct via_spec { | |||
171 | struct hda_loopback_check loopback; | 185 | struct hda_loopback_check loopback; |
172 | int num_loopbacks; | 186 | int num_loopbacks; |
173 | struct hda_amp_list loopback_list[8]; | 187 | struct hda_amp_list loopback_list[8]; |
188 | |||
189 | /* bind capture-volume */ | ||
190 | struct hda_bind_ctls *bind_cap_vol; | ||
191 | struct hda_bind_ctls *bind_cap_sw; | ||
174 | }; | 192 | }; |
175 | 193 | ||
176 | static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec); | 194 | static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec); |
@@ -586,12 +604,15 @@ static void via_auto_init_analog_input(struct hda_codec *codec) | |||
586 | 604 | ||
587 | /* init input-src */ | 605 | /* init input-src */ |
588 | for (i = 0; i < spec->num_adc_nids; i++) { | 606 | for (i = 0; i < spec->num_adc_nids; i++) { |
589 | const struct hda_input_mux *imux = spec->input_mux; | 607 | int adc_idx = spec->inputs[spec->cur_mux[i]].adc_idx; |
590 | if (!imux || !spec->mux_nids[i]) | 608 | if (spec->mux_nids[adc_idx]) { |
591 | continue; | 609 | int mux_idx = spec->inputs[spec->cur_mux[i]].mux_idx; |
592 | snd_hda_codec_write(codec, spec->mux_nids[i], 0, | 610 | snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0, |
593 | AC_VERB_SET_CONNECT_SEL, | 611 | AC_VERB_SET_CONNECT_SEL, |
594 | imux->items[spec->cur_mux[i]].index); | 612 | mux_idx); |
613 | } | ||
614 | if (spec->dyn_adc_switch) | ||
615 | break; /* only one input-src */ | ||
595 | } | 616 | } |
596 | 617 | ||
597 | /* init aa-mixer */ | 618 | /* init aa-mixer */ |
@@ -682,53 +703,6 @@ static const struct snd_kcontrol_new via_pin_power_ctl_enum = { | |||
682 | }; | 703 | }; |
683 | 704 | ||
684 | 705 | ||
685 | /* | ||
686 | * input MUX handling | ||
687 | */ | ||
688 | static int via_mux_enum_info(struct snd_kcontrol *kcontrol, | ||
689 | struct snd_ctl_elem_info *uinfo) | ||
690 | { | ||
691 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
692 | struct via_spec *spec = codec->spec; | ||
693 | return snd_hda_input_mux_info(spec->input_mux, uinfo); | ||
694 | } | ||
695 | |||
696 | static int via_mux_enum_get(struct snd_kcontrol *kcontrol, | ||
697 | struct snd_ctl_elem_value *ucontrol) | ||
698 | { | ||
699 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
700 | struct via_spec *spec = codec->spec; | ||
701 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | ||
702 | |||
703 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; | ||
704 | return 0; | ||
705 | } | ||
706 | |||
707 | static int via_mux_enum_put(struct snd_kcontrol *kcontrol, | ||
708 | struct snd_ctl_elem_value *ucontrol) | ||
709 | { | ||
710 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
711 | struct via_spec *spec = codec->spec; | ||
712 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | ||
713 | int ret; | ||
714 | |||
715 | if (!spec->mux_nids[adc_idx]) | ||
716 | return -EINVAL; | ||
717 | /* switch to D0 beofre change index */ | ||
718 | if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0, | ||
719 | AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0) | ||
720 | snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0, | ||
721 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | ||
722 | |||
723 | ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, | ||
724 | spec->mux_nids[adc_idx], | ||
725 | &spec->cur_mux[adc_idx]); | ||
726 | /* update jack power state */ | ||
727 | set_widgets_power_state(codec); | ||
728 | |||
729 | return ret; | ||
730 | } | ||
731 | |||
732 | static int via_independent_hp_info(struct snd_kcontrol *kcontrol, | 706 | static int via_independent_hp_info(struct snd_kcontrol *kcontrol, |
733 | struct snd_ctl_elem_info *uinfo) | 707 | struct snd_ctl_elem_info *uinfo) |
734 | { | 708 | { |
@@ -1149,6 +1123,53 @@ static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, | |||
1149 | return 0; | 1123 | return 0; |
1150 | } | 1124 | } |
1151 | 1125 | ||
1126 | /* analog capture with dynamic ADC switching */ | ||
1127 | static int via_dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo, | ||
1128 | struct hda_codec *codec, | ||
1129 | unsigned int stream_tag, | ||
1130 | unsigned int format, | ||
1131 | struct snd_pcm_substream *substream) | ||
1132 | { | ||
1133 | struct via_spec *spec = codec->spec; | ||
1134 | int adc_idx = spec->inputs[spec->cur_mux[0]].adc_idx; | ||
1135 | |||
1136 | spec->cur_adc = spec->adc_nids[adc_idx]; | ||
1137 | spec->cur_adc_stream_tag = stream_tag; | ||
1138 | spec->cur_adc_format = format; | ||
1139 | snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); | ||
1140 | return 0; | ||
1141 | } | ||
1142 | |||
1143 | static int via_dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, | ||
1144 | struct hda_codec *codec, | ||
1145 | struct snd_pcm_substream *substream) | ||
1146 | { | ||
1147 | struct via_spec *spec = codec->spec; | ||
1148 | |||
1149 | snd_hda_codec_cleanup_stream(codec, spec->cur_adc); | ||
1150 | spec->cur_adc = 0; | ||
1151 | return 0; | ||
1152 | } | ||
1153 | |||
1154 | /* re-setup the stream if running; called from input-src put */ | ||
1155 | static bool via_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur) | ||
1156 | { | ||
1157 | struct via_spec *spec = codec->spec; | ||
1158 | int adc_idx = spec->inputs[cur].adc_idx; | ||
1159 | hda_nid_t adc = spec->adc_nids[adc_idx]; | ||
1160 | |||
1161 | if (spec->cur_adc && spec->cur_adc != adc) { | ||
1162 | /* stream is running, let's swap the current ADC */ | ||
1163 | __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); | ||
1164 | spec->cur_adc = adc; | ||
1165 | snd_hda_codec_setup_stream(codec, adc, | ||
1166 | spec->cur_adc_stream_tag, 0, | ||
1167 | spec->cur_adc_format); | ||
1168 | return true; | ||
1169 | } | ||
1170 | return false; | ||
1171 | } | ||
1172 | |||
1152 | static const struct hda_pcm_stream via_pcm_analog_playback = { | 1173 | static const struct hda_pcm_stream via_pcm_analog_playback = { |
1153 | .substreams = 1, | 1174 | .substreams = 1, |
1154 | .channels_min = 2, | 1175 | .channels_min = 2, |
@@ -1204,6 +1225,17 @@ static const struct hda_pcm_stream via_pcm_analog_capture = { | |||
1204 | }, | 1225 | }, |
1205 | }; | 1226 | }; |
1206 | 1227 | ||
1228 | static const struct hda_pcm_stream via_pcm_dyn_adc_analog_capture = { | ||
1229 | .substreams = 1, | ||
1230 | .channels_min = 2, | ||
1231 | .channels_max = 2, | ||
1232 | /* NID is set in via_build_pcms */ | ||
1233 | .ops = { | ||
1234 | .prepare = via_dyn_adc_capture_pcm_prepare, | ||
1235 | .cleanup = via_dyn_adc_capture_pcm_cleanup, | ||
1236 | }, | ||
1237 | }; | ||
1238 | |||
1207 | static const struct hda_pcm_stream via_pcm_digital_playback = { | 1239 | static const struct hda_pcm_stream via_pcm_digital_playback = { |
1208 | .substreams = 1, | 1240 | .substreams = 1, |
1209 | .channels_min = 2, | 1241 | .channels_min = 2, |
@@ -1336,13 +1368,19 @@ static int via_build_pcms(struct hda_codec *codec) | |||
1336 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = | 1368 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = |
1337 | spec->multiout.max_channels; | 1369 | spec->multiout.max_channels; |
1338 | 1370 | ||
1339 | if (!spec->stream_analog_capture) | 1371 | if (!spec->stream_analog_capture) { |
1340 | spec->stream_analog_capture = &via_pcm_analog_capture; | 1372 | if (spec->dyn_adc_switch) |
1373 | spec->stream_analog_capture = | ||
1374 | &via_pcm_dyn_adc_analog_capture; | ||
1375 | else | ||
1376 | spec->stream_analog_capture = &via_pcm_analog_capture; | ||
1377 | } | ||
1341 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = | 1378 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
1342 | *spec->stream_analog_capture; | 1379 | *spec->stream_analog_capture; |
1343 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; | 1380 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; |
1344 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = | 1381 | if (!spec->dyn_adc_switch) |
1345 | spec->num_adc_nids; | 1382 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = |
1383 | spec->num_adc_nids; | ||
1346 | 1384 | ||
1347 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { | 1385 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { |
1348 | codec->num_pcms++; | 1386 | codec->num_pcms++; |
@@ -1394,7 +1432,9 @@ static void via_free(struct hda_codec *codec) | |||
1394 | 1432 | ||
1395 | via_free_kctls(codec); | 1433 | via_free_kctls(codec); |
1396 | vt1708_stop_hp_work(spec); | 1434 | vt1708_stop_hp_work(spec); |
1397 | kfree(codec->spec); | 1435 | kfree(spec->bind_cap_vol); |
1436 | kfree(spec->bind_cap_sw); | ||
1437 | kfree(spec); | ||
1398 | } | 1438 | } |
1399 | 1439 | ||
1400 | /* mute/unmute outputs */ | 1440 | /* mute/unmute outputs */ |
@@ -1860,7 +1900,74 @@ static int via_fill_adcs(struct hda_codec *codec) | |||
1860 | return 0; | 1900 | return 0; |
1861 | } | 1901 | } |
1862 | 1902 | ||
1863 | static int get_mux_nids(struct hda_codec *codec); | 1903 | /* input-src control */ |
1904 | static int via_mux_enum_info(struct snd_kcontrol *kcontrol, | ||
1905 | struct snd_ctl_elem_info *uinfo) | ||
1906 | { | ||
1907 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
1908 | struct via_spec *spec = codec->spec; | ||
1909 | |||
1910 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | ||
1911 | uinfo->count = 1; | ||
1912 | uinfo->value.enumerated.items = spec->num_inputs; | ||
1913 | if (uinfo->value.enumerated.item >= spec->num_inputs) | ||
1914 | uinfo->value.enumerated.item = spec->num_inputs - 1; | ||
1915 | strcpy(uinfo->value.enumerated.name, | ||
1916 | spec->inputs[uinfo->value.enumerated.item].label); | ||
1917 | return 0; | ||
1918 | } | ||
1919 | |||
1920 | static int via_mux_enum_get(struct snd_kcontrol *kcontrol, | ||
1921 | struct snd_ctl_elem_value *ucontrol) | ||
1922 | { | ||
1923 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
1924 | struct via_spec *spec = codec->spec; | ||
1925 | unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | ||
1926 | |||
1927 | ucontrol->value.enumerated.item[0] = spec->cur_mux[idx]; | ||
1928 | return 0; | ||
1929 | } | ||
1930 | |||
1931 | static int via_mux_enum_put(struct snd_kcontrol *kcontrol, | ||
1932 | struct snd_ctl_elem_value *ucontrol) | ||
1933 | { | ||
1934 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
1935 | struct via_spec *spec = codec->spec; | ||
1936 | unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | ||
1937 | hda_nid_t mux; | ||
1938 | int cur; | ||
1939 | |||
1940 | cur = ucontrol->value.enumerated.item[0]; | ||
1941 | if (cur < 0 || cur >= spec->num_inputs) | ||
1942 | return -EINVAL; | ||
1943 | if (spec->cur_mux[idx] == cur) | ||
1944 | return 0; | ||
1945 | spec->cur_mux[idx] = cur; | ||
1946 | if (spec->dyn_adc_switch) { | ||
1947 | int adc_idx = spec->inputs[cur].adc_idx; | ||
1948 | mux = spec->mux_nids[adc_idx]; | ||
1949 | via_dyn_adc_pcm_resetup(codec, cur); | ||
1950 | } else { | ||
1951 | mux = spec->mux_nids[idx]; | ||
1952 | if (snd_BUG_ON(!mux)) | ||
1953 | return -EINVAL; | ||
1954 | } | ||
1955 | |||
1956 | if (mux) { | ||
1957 | /* switch to D0 beofre change index */ | ||
1958 | if (snd_hda_codec_read(codec, mux, 0, | ||
1959 | AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0) | ||
1960 | snd_hda_codec_write(codec, mux, 0, | ||
1961 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | ||
1962 | snd_hda_codec_write(codec, mux, 0, | ||
1963 | AC_VERB_SET_CONNECT_SEL, | ||
1964 | spec->inputs[cur].mux_idx); | ||
1965 | } | ||
1966 | |||
1967 | /* update jack power state */ | ||
1968 | set_widgets_power_state(codec); | ||
1969 | return 0; | ||
1970 | } | ||
1864 | 1971 | ||
1865 | static const struct snd_kcontrol_new via_input_src_ctl = { | 1972 | static const struct snd_kcontrol_new via_input_src_ctl = { |
1866 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 1973 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
@@ -1874,6 +1981,22 @@ static const struct snd_kcontrol_new via_input_src_ctl = { | |||
1874 | .put = via_mux_enum_put, | 1981 | .put = via_mux_enum_put, |
1875 | }; | 1982 | }; |
1876 | 1983 | ||
1984 | static int create_input_src_ctls(struct hda_codec *codec, int count) | ||
1985 | { | ||
1986 | struct via_spec *spec = codec->spec; | ||
1987 | struct snd_kcontrol_new *knew; | ||
1988 | |||
1989 | if (spec->num_inputs <= 1 || !count) | ||
1990 | return 0; /* no need for single src */ | ||
1991 | |||
1992 | knew = via_clone_control(spec, &via_input_src_ctl); | ||
1993 | if (!knew) | ||
1994 | return -ENOMEM; | ||
1995 | knew->count = count; | ||
1996 | return 0; | ||
1997 | } | ||
1998 | |||
1999 | /* add the powersave loopback-list entry */ | ||
1877 | static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx) | 2000 | static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx) |
1878 | { | 2001 | { |
1879 | struct hda_amp_list *list; | 2002 | struct hda_amp_list *list; |
@@ -1888,17 +2011,65 @@ static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx) | |||
1888 | spec->loopback.amplist = spec->loopback_list; | 2011 | spec->loopback.amplist = spec->loopback_list; |
1889 | } | 2012 | } |
1890 | 2013 | ||
1891 | /* create playback/capture controls for input pins */ | 2014 | /* check whether the path from src to dst is reachable */ |
1892 | static int via_auto_create_analog_input_ctls(struct hda_codec *codec, | 2015 | static bool is_reachable_nid(struct hda_codec *codec, hda_nid_t src, |
1893 | const struct auto_pin_cfg *cfg) | 2016 | hda_nid_t dst, int depth) |
2017 | { | ||
2018 | hda_nid_t conn[8]; | ||
2019 | int i, nums; | ||
2020 | |||
2021 | nums = snd_hda_get_connections(codec, src, conn, ARRAY_SIZE(conn)); | ||
2022 | for (i = 0; i < nums; i++) | ||
2023 | if (conn[i] == dst) | ||
2024 | return true; | ||
2025 | if (++depth > MAX_NID_PATH_DEPTH) | ||
2026 | return false; | ||
2027 | for (i = 0; i < nums; i++) | ||
2028 | if (is_reachable_nid(codec, conn[i], dst, depth)) | ||
2029 | return true; | ||
2030 | return false; | ||
2031 | } | ||
2032 | |||
2033 | /* add the input-route to the given pin */ | ||
2034 | static bool add_input_route(struct hda_codec *codec, hda_nid_t pin) | ||
1894 | { | 2035 | { |
1895 | struct via_spec *spec = codec->spec; | 2036 | struct via_spec *spec = codec->spec; |
1896 | struct hda_input_mux *imux = &spec->private_imux[0]; | 2037 | int c, idx; |
1897 | int i, j, err, idx, idx2, type, type_idx = 0; | 2038 | |
1898 | const char *prev_label = NULL; | 2039 | spec->inputs[spec->num_inputs].adc_idx = -1; |
1899 | hda_nid_t cap_nid; | 2040 | spec->inputs[spec->num_inputs].pin = pin; |
1900 | hda_nid_t pin_idxs[8]; | 2041 | for (c = 0; c < spec->num_adc_nids; c++) { |
1901 | int num_idxs; | 2042 | if (spec->mux_nids[c]) { |
2043 | idx = get_connection_index(codec, spec->mux_nids[c], | ||
2044 | pin); | ||
2045 | if (idx < 0) | ||
2046 | continue; | ||
2047 | spec->inputs[spec->num_inputs].mux_idx = idx; | ||
2048 | } else { | ||
2049 | if (!is_reachable_nid(codec, spec->adc_nids[c], pin, 0)) | ||
2050 | continue; | ||
2051 | } | ||
2052 | spec->inputs[spec->num_inputs].adc_idx = c; | ||
2053 | /* Can primary ADC satisfy all inputs? */ | ||
2054 | if (!spec->dyn_adc_switch && | ||
2055 | spec->num_inputs > 0 && spec->inputs[0].adc_idx != c) { | ||
2056 | snd_printd(KERN_INFO | ||
2057 | "via: dynamic ADC switching enabled\n"); | ||
2058 | spec->dyn_adc_switch = 1; | ||
2059 | } | ||
2060 | return true; | ||
2061 | } | ||
2062 | return false; | ||
2063 | } | ||
2064 | |||
2065 | static int get_mux_nids(struct hda_codec *codec); | ||
2066 | |||
2067 | /* parse input-routes; fill ADCs, MUXs and input-src entries */ | ||
2068 | static int parse_analog_inputs(struct hda_codec *codec) | ||
2069 | { | ||
2070 | struct via_spec *spec = codec->spec; | ||
2071 | const struct auto_pin_cfg *cfg = &spec->autocfg; | ||
2072 | int i, err; | ||
1902 | 2073 | ||
1903 | err = via_fill_adcs(codec); | 2074 | err = via_fill_adcs(codec); |
1904 | if (err < 0) | 2075 | if (err < 0) |
@@ -1906,55 +2077,97 @@ static int via_auto_create_analog_input_ctls(struct hda_codec *codec, | |||
1906 | err = get_mux_nids(codec); | 2077 | err = get_mux_nids(codec); |
1907 | if (err < 0) | 2078 | if (err < 0) |
1908 | return err; | 2079 | return err; |
1909 | cap_nid = spec->mux_nids[0]; | ||
1910 | 2080 | ||
1911 | num_idxs = snd_hda_get_connections(codec, cap_nid, pin_idxs, | 2081 | /* fill all input-routes */ |
1912 | ARRAY_SIZE(pin_idxs)); | 2082 | for (i = 0; i < cfg->num_inputs; i++) { |
1913 | if (num_idxs <= 0) | 2083 | if (add_input_route(codec, cfg->inputs[i].pin)) |
1914 | return 0; | 2084 | spec->inputs[spec->num_inputs++].label = |
1915 | 2085 | hda_get_autocfg_input_label(codec, cfg, i); | |
1916 | /* for internal loopback recording select */ | ||
1917 | for (idx = 0; idx < num_idxs; idx++) { | ||
1918 | if (pin_idxs[idx] == spec->aa_mix_nid) { | ||
1919 | snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL); | ||
1920 | break; | ||
1921 | } | ||
1922 | } | 2086 | } |
1923 | 2087 | ||
2088 | /* check for internal loopback recording */ | ||
2089 | if (spec->aa_mix_nid && | ||
2090 | add_input_route(codec, spec->aa_mix_nid)) | ||
2091 | spec->inputs[spec->num_inputs++].label = "Stereo Mixer"; | ||
2092 | |||
2093 | return 0; | ||
2094 | } | ||
2095 | |||
2096 | /* create analog-loopback volume/switch controls */ | ||
2097 | static int create_loopback_ctls(struct hda_codec *codec) | ||
2098 | { | ||
2099 | struct via_spec *spec = codec->spec; | ||
2100 | const struct auto_pin_cfg *cfg = &spec->autocfg; | ||
2101 | const char *prev_label = NULL; | ||
2102 | int type_idx = 0; | ||
2103 | int i, j, err, idx; | ||
2104 | |||
2105 | if (!spec->aa_mix_nid) | ||
2106 | return 0; | ||
2107 | |||
1924 | for (i = 0; i < cfg->num_inputs; i++) { | 2108 | for (i = 0; i < cfg->num_inputs; i++) { |
1925 | const char *label; | 2109 | hda_nid_t pin = cfg->inputs[i].pin; |
1926 | type = cfg->inputs[i].type; | 2110 | const char *label = hda_get_autocfg_input_label(codec, cfg, i); |
1927 | for (idx = 0; idx < num_idxs; idx++) | 2111 | |
1928 | if (pin_idxs[idx] == cfg->inputs[i].pin) | ||
1929 | break; | ||
1930 | if (idx >= num_idxs) | ||
1931 | continue; | ||
1932 | label = hda_get_autocfg_input_label(codec, cfg, i); | ||
1933 | if (prev_label && !strcmp(label, prev_label)) | 2112 | if (prev_label && !strcmp(label, prev_label)) |
1934 | type_idx++; | 2113 | type_idx++; |
1935 | else | 2114 | else |
1936 | type_idx = 0; | 2115 | type_idx = 0; |
1937 | prev_label = label; | 2116 | prev_label = label; |
1938 | idx2 = get_connection_index(codec, spec->aa_mix_nid, | 2117 | idx = get_connection_index(codec, spec->aa_mix_nid, pin); |
1939 | pin_idxs[idx]); | 2118 | if (idx >= 0) { |
1940 | if (idx2 >= 0) { | ||
1941 | err = via_new_analog_input(spec, label, type_idx, | 2119 | err = via_new_analog_input(spec, label, type_idx, |
1942 | idx2, spec->aa_mix_nid); | 2120 | idx, spec->aa_mix_nid); |
1943 | if (err < 0) | 2121 | if (err < 0) |
1944 | return err; | 2122 | return err; |
1945 | add_loopback_list(spec, spec->aa_mix_nid, idx2); | 2123 | add_loopback_list(spec, spec->aa_mix_nid, idx); |
1946 | } | 2124 | } |
1947 | snd_hda_add_imux_item(imux, label, idx, NULL); | ||
1948 | 2125 | ||
1949 | /* remember the label for smart51 control */ | 2126 | /* remember the label for smart51 control */ |
1950 | for (j = 0; j < spec->smart51_nums; j++) { | 2127 | for (j = 0; j < spec->smart51_nums; j++) { |
1951 | if (spec->smart51_pins[j] == cfg->inputs[i].pin) { | 2128 | if (spec->smart51_pins[j] == pin) { |
1952 | spec->smart51_idxs[j] = idx; | 2129 | spec->smart51_idxs[j] = idx; |
1953 | spec->smart51_labels[j] = label; | 2130 | spec->smart51_labels[j] = label; |
1954 | break; | 2131 | break; |
1955 | } | 2132 | } |
1956 | } | 2133 | } |
1957 | } | 2134 | } |
2135 | return 0; | ||
2136 | } | ||
2137 | |||
2138 | /* create mic-boost controls (if present) */ | ||
2139 | static int create_mic_boost_ctls(struct hda_codec *codec) | ||
2140 | { | ||
2141 | struct via_spec *spec = codec->spec; | ||
2142 | const struct auto_pin_cfg *cfg = &spec->autocfg; | ||
2143 | int i, err; | ||
2144 | |||
2145 | for (i = 0; i < cfg->num_inputs; i++) { | ||
2146 | hda_nid_t pin = cfg->inputs[i].pin; | ||
2147 | unsigned int caps; | ||
2148 | const char *label; | ||
2149 | char name[32]; | ||
2150 | |||
2151 | if (cfg->inputs[i].type != AUTO_PIN_MIC) | ||
2152 | continue; | ||
2153 | caps = query_amp_caps(codec, pin, HDA_INPUT); | ||
2154 | if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS)) | ||
2155 | continue; | ||
2156 | label = hda_get_autocfg_input_label(codec, cfg, i); | ||
2157 | snprintf(name, sizeof(name), "%s Boost Volume", label); | ||
2158 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | ||
2159 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT)); | ||
2160 | if (err < 0) | ||
2161 | return err; | ||
2162 | } | ||
2163 | return 0; | ||
2164 | } | ||
2165 | |||
2166 | /* create capture and input-src controls for multiple streams */ | ||
2167 | static int create_multi_adc_ctls(struct hda_codec *codec) | ||
2168 | { | ||
2169 | struct via_spec *spec = codec->spec; | ||
2170 | int i, err; | ||
1958 | 2171 | ||
1959 | /* create capture mixer elements */ | 2172 | /* create capture mixer elements */ |
1960 | for (i = 0; i < spec->num_adc_nids; i++) { | 2173 | for (i = 0; i < spec->num_adc_nids; i++) { |
@@ -1977,34 +2190,89 @@ static int via_auto_create_analog_input_ctls(struct hda_codec *codec, | |||
1977 | for (i = 0; i < spec->num_adc_nids; i++) | 2190 | for (i = 0; i < spec->num_adc_nids; i++) |
1978 | if (!spec->mux_nids[i]) | 2191 | if (!spec->mux_nids[i]) |
1979 | break; | 2192 | break; |
1980 | if (i) { | 2193 | err = create_input_src_ctls(codec, i); |
1981 | struct snd_kcontrol_new *knew; | 2194 | if (err < 0) |
1982 | knew = via_clone_control(spec, &via_input_src_ctl); | 2195 | return err; |
1983 | if (!knew) | 2196 | return 0; |
1984 | return -ENOMEM; | 2197 | } |
1985 | knew->count = i; | ||
1986 | } | ||
1987 | 2198 | ||
1988 | /* mic-boosts */ | 2199 | /* bind capture volume/switch */ |
1989 | for (i = 0; i < cfg->num_inputs; i++) { | 2200 | static struct snd_kcontrol_new via_bind_cap_vol_ctl = |
1990 | hda_nid_t pin = cfg->inputs[i].pin; | 2201 | HDA_BIND_VOL("Capture Volume", 0); |
1991 | unsigned int caps; | 2202 | static struct snd_kcontrol_new via_bind_cap_sw_ctl = |
1992 | const char *label; | 2203 | HDA_BIND_SW("Capture Switch", 0); |
1993 | char name[32]; | ||
1994 | 2204 | ||
1995 | if (cfg->inputs[i].type != AUTO_PIN_MIC) | 2205 | static int init_bind_ctl(struct via_spec *spec, struct hda_bind_ctls **ctl_ret, |
1996 | continue; | 2206 | struct hda_ctl_ops *ops) |
1997 | caps = query_amp_caps(codec, pin, HDA_INPUT); | 2207 | { |
1998 | if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS)) | 2208 | struct hda_bind_ctls *ctl; |
1999 | continue; | 2209 | int i; |
2000 | label = hda_get_autocfg_input_label(codec, cfg, i); | 2210 | |
2001 | snprintf(name, sizeof(name), "%s Boost Volume", label); | 2211 | ctl = kzalloc(sizeof(*ctl) + sizeof(long) * 4, GFP_KERNEL); |
2002 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | 2212 | if (!ctl) |
2003 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT)); | 2213 | return -ENOMEM; |
2004 | if (err < 0) | 2214 | ctl->ops = ops; |
2005 | return err; | 2215 | for (i = 0; i < spec->num_adc_nids; i++) |
2006 | } | 2216 | ctl->values[i] = |
2217 | HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], 3, 0, HDA_INPUT); | ||
2218 | *ctl_ret = ctl; | ||
2219 | return 0; | ||
2220 | } | ||
2221 | |||
2222 | /* create capture and input-src controls for dynamic ADC-switch case */ | ||
2223 | static int create_dyn_adc_ctls(struct hda_codec *codec) | ||
2224 | { | ||
2225 | struct via_spec *spec = codec->spec; | ||
2226 | struct snd_kcontrol_new *knew; | ||
2227 | int err; | ||
2228 | |||
2229 | /* set up the bind capture ctls */ | ||
2230 | err = init_bind_ctl(spec, &spec->bind_cap_vol, &snd_hda_bind_vol); | ||
2231 | if (err < 0) | ||
2232 | return err; | ||
2233 | err = init_bind_ctl(spec, &spec->bind_cap_sw, &snd_hda_bind_sw); | ||
2234 | if (err < 0) | ||
2235 | return err; | ||
2236 | |||
2237 | /* create capture mixer elements */ | ||
2238 | knew = via_clone_control(spec, &via_bind_cap_vol_ctl); | ||
2239 | if (!knew) | ||
2240 | return -ENOMEM; | ||
2241 | knew->private_value = (long)spec->bind_cap_vol; | ||
2242 | |||
2243 | knew = via_clone_control(spec, &via_bind_cap_sw_ctl); | ||
2244 | if (!knew) | ||
2245 | return -ENOMEM; | ||
2246 | knew->private_value = (long)spec->bind_cap_sw; | ||
2247 | |||
2248 | /* input-source control */ | ||
2249 | err = create_input_src_ctls(codec, 1); | ||
2250 | if (err < 0) | ||
2251 | return err; | ||
2252 | return 0; | ||
2253 | } | ||
2007 | 2254 | ||
2255 | /* parse and create capture-related stuff */ | ||
2256 | static int via_auto_create_analog_input_ctls(struct hda_codec *codec) | ||
2257 | { | ||
2258 | struct via_spec *spec = codec->spec; | ||
2259 | int err; | ||
2260 | |||
2261 | err = parse_analog_inputs(codec); | ||
2262 | if (err < 0) | ||
2263 | return err; | ||
2264 | if (spec->dyn_adc_switch) | ||
2265 | err = create_dyn_adc_ctls(codec); | ||
2266 | else | ||
2267 | err = create_multi_adc_ctls(codec); | ||
2268 | if (err < 0) | ||
2269 | return err; | ||
2270 | err = create_loopback_ctls(codec); | ||
2271 | if (err < 0) | ||
2272 | return err; | ||
2273 | err = create_mic_boost_ctls(codec); | ||
2274 | if (err < 0) | ||
2275 | return err; | ||
2008 | return 0; | 2276 | return 0; |
2009 | } | 2277 | } |
2010 | 2278 | ||
@@ -2090,7 +2358,7 @@ static int via_parse_auto_config(struct hda_codec *codec) | |||
2090 | err = via_auto_create_speaker_ctls(codec); | 2358 | err = via_auto_create_speaker_ctls(codec); |
2091 | if (err < 0) | 2359 | if (err < 0) |
2092 | return err; | 2360 | return err; |
2093 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); | 2361 | err = via_auto_create_analog_input_ctls(codec); |
2094 | if (err < 0) | 2362 | if (err < 0) |
2095 | return err; | 2363 | return err; |
2096 | 2364 | ||
@@ -2104,8 +2372,6 @@ static int via_parse_auto_config(struct hda_codec *codec) | |||
2104 | 2372 | ||
2105 | spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs; | 2373 | spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs; |
2106 | 2374 | ||
2107 | spec->input_mux = &spec->private_imux[0]; | ||
2108 | |||
2109 | if (spec->hp_dac_nid && spec->hp_dep_path.depth) { | 2375 | if (spec->hp_dac_nid && spec->hp_dep_path.depth) { |
2110 | err = via_hp_build(codec); | 2376 | err = via_hp_build(codec); |
2111 | if (err < 0) | 2377 | if (err < 0) |