2 * Universal Interface for Intel High Definition Audio Codec
4 * Generic widget tree parser
6 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
8 * This driver is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This driver is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/init.h>
24 #include <linux/slab.h>
25 #include <linux/export.h>
26 #include <linux/sort.h>
27 #include <linux/delay.h>
28 #include <linux/ctype.h>
29 #include <linux/string.h>
30 #include <linux/bitops.h>
31 #include <sound/core.h>
32 #include <sound/jack.h>
33 #include "hda_codec.h"
34 #include "hda_local.h"
35 #include "hda_auto_parser.h"
38 #include "hda_generic.h"
41 /* initialize hda_gen_spec struct */
42 int snd_hda_gen_spec_init(struct hda_gen_spec
*spec
)
44 snd_array_init(&spec
->kctls
, sizeof(struct snd_kcontrol_new
), 32);
45 snd_array_init(&spec
->paths
, sizeof(struct nid_path
), 8);
46 snd_array_init(&spec
->loopback_list
, sizeof(struct hda_amp_list
), 8);
47 mutex_init(&spec
->pcm_mutex
);
50 EXPORT_SYMBOL_HDA(snd_hda_gen_spec_init
);
52 struct snd_kcontrol_new
*
53 snd_hda_gen_add_kctl(struct hda_gen_spec
*spec
, const char *name
,
54 const struct snd_kcontrol_new
*temp
)
56 struct snd_kcontrol_new
*knew
= snd_array_new(&spec
->kctls
);
61 knew
->name
= kstrdup(name
, GFP_KERNEL
);
63 knew
->name
= kstrdup(knew
->name
, GFP_KERNEL
);
68 EXPORT_SYMBOL_HDA(snd_hda_gen_add_kctl
);
70 static void free_kctls(struct hda_gen_spec
*spec
)
72 if (spec
->kctls
.list
) {
73 struct snd_kcontrol_new
*kctl
= spec
->kctls
.list
;
75 for (i
= 0; i
< spec
->kctls
.used
; i
++)
78 snd_array_free(&spec
->kctls
);
81 void snd_hda_gen_spec_free(struct hda_gen_spec
*spec
)
86 snd_array_free(&spec
->paths
);
87 snd_array_free(&spec
->loopback_list
);
89 EXPORT_SYMBOL_HDA(snd_hda_gen_spec_free
);
94 static void parse_user_hints(struct hda_codec
*codec
)
96 struct hda_gen_spec
*spec
= codec
->spec
;
99 val
= snd_hda_get_bool_hint(codec
, "jack_detect");
101 codec
->no_jack_detect
= !val
;
102 val
= snd_hda_get_bool_hint(codec
, "inv_jack_detect");
104 codec
->inv_jack_detect
= !!val
;
105 val
= snd_hda_get_bool_hint(codec
, "trigger_sense");
107 codec
->no_trigger_sense
= !val
;
108 val
= snd_hda_get_bool_hint(codec
, "inv_eapd");
110 codec
->inv_eapd
= !!val
;
111 val
= snd_hda_get_bool_hint(codec
, "pcm_format_first");
113 codec
->pcm_format_first
= !!val
;
114 val
= snd_hda_get_bool_hint(codec
, "sticky_stream");
116 codec
->no_sticky_stream
= !val
;
117 val
= snd_hda_get_bool_hint(codec
, "spdif_status_reset");
119 codec
->spdif_status_reset
= !!val
;
120 val
= snd_hda_get_bool_hint(codec
, "pin_amp_workaround");
122 codec
->pin_amp_workaround
= !!val
;
123 val
= snd_hda_get_bool_hint(codec
, "single_adc_amp");
125 codec
->single_adc_amp
= !!val
;
127 val
= snd_hda_get_bool_hint(codec
, "auto_mute");
129 spec
->suppress_auto_mute
= !val
;
130 val
= snd_hda_get_bool_hint(codec
, "auto_mic");
132 spec
->suppress_auto_mic
= !val
;
133 val
= snd_hda_get_bool_hint(codec
, "line_in_auto_switch");
135 spec
->line_in_auto_switch
= !!val
;
136 val
= snd_hda_get_bool_hint(codec
, "auto_mute_via_amp");
138 spec
->auto_mute_via_amp
= !!val
;
139 val
= snd_hda_get_bool_hint(codec
, "need_dac_fix");
141 spec
->need_dac_fix
= !!val
;
142 val
= snd_hda_get_bool_hint(codec
, "primary_hp");
144 spec
->no_primary_hp
= !val
;
145 val
= snd_hda_get_bool_hint(codec
, "multi_io");
147 spec
->no_multi_io
= !val
;
148 val
= snd_hda_get_bool_hint(codec
, "multi_cap_vol");
150 spec
->multi_cap_vol
= !!val
;
151 val
= snd_hda_get_bool_hint(codec
, "inv_dmic_split");
153 spec
->inv_dmic_split
= !!val
;
154 val
= snd_hda_get_bool_hint(codec
, "indep_hp");
156 spec
->indep_hp
= !!val
;
157 val
= snd_hda_get_bool_hint(codec
, "add_stereo_mix_input");
159 spec
->add_stereo_mix_input
= !!val
;
160 /* the following two are just for compatibility */
161 val
= snd_hda_get_bool_hint(codec
, "add_out_jack_modes");
163 spec
->add_jack_modes
= !!val
;
164 val
= snd_hda_get_bool_hint(codec
, "add_in_jack_modes");
166 spec
->add_jack_modes
= !!val
;
167 val
= snd_hda_get_bool_hint(codec
, "add_jack_modes");
169 spec
->add_jack_modes
= !!val
;
170 val
= snd_hda_get_bool_hint(codec
, "power_down_unused");
172 spec
->power_down_unused
= !!val
;
173 val
= snd_hda_get_bool_hint(codec
, "add_hp_mic");
175 spec
->hp_mic
= !!val
;
176 val
= snd_hda_get_bool_hint(codec
, "hp_mic_detect");
178 spec
->suppress_hp_mic_detect
= !val
;
180 if (!snd_hda_get_int_hint(codec
, "mixer_nid", &val
))
181 spec
->mixer_nid
= val
;
185 * pin control value accesses
188 #define update_pin_ctl(codec, pin, val) \
189 snd_hda_codec_update_cache(codec, pin, 0, \
190 AC_VERB_SET_PIN_WIDGET_CONTROL, val)
192 /* restore the pinctl based on the cached value */
193 static inline void restore_pin_ctl(struct hda_codec
*codec
, hda_nid_t pin
)
195 update_pin_ctl(codec
, pin
, snd_hda_codec_get_pin_target(codec
, pin
));
198 /* set the pinctl target value and write it if requested */
199 static void set_pin_target(struct hda_codec
*codec
, hda_nid_t pin
,
200 unsigned int val
, bool do_write
)
204 val
= snd_hda_correct_pin_ctl(codec
, pin
, val
);
205 snd_hda_codec_set_pin_target(codec
, pin
, val
);
207 update_pin_ctl(codec
, pin
, val
);
210 /* set pinctl target values for all given pins */
211 static void set_pin_targets(struct hda_codec
*codec
, int num_pins
,
212 hda_nid_t
*pins
, unsigned int val
)
215 for (i
= 0; i
< num_pins
; i
++)
216 set_pin_target(codec
, pins
[i
], val
, false);
223 /* return the position of NID in the list, or -1 if not found */
224 static int find_idx_in_nid_list(hda_nid_t nid
, const hda_nid_t
*list
, int nums
)
227 for (i
= 0; i
< nums
; i
++)
233 /* return true if the given NID is contained in the path */
234 static bool is_nid_contained(struct nid_path
*path
, hda_nid_t nid
)
236 return find_idx_in_nid_list(nid
, path
->path
, path
->depth
) >= 0;
239 static struct nid_path
*get_nid_path(struct hda_codec
*codec
,
240 hda_nid_t from_nid
, hda_nid_t to_nid
,
243 struct hda_gen_spec
*spec
= codec
->spec
;
246 for (i
= 0; i
< spec
->paths
.used
; i
++) {
247 struct nid_path
*path
= snd_array_elem(&spec
->paths
, i
);
248 if (path
->depth
<= 0)
250 if ((!from_nid
|| path
->path
[0] == from_nid
) &&
251 (!to_nid
|| path
->path
[path
->depth
- 1] == to_nid
)) {
253 (anchor_nid
> 0 && is_nid_contained(path
, anchor_nid
)) ||
254 (anchor_nid
< 0 && !is_nid_contained(path
, anchor_nid
)))
261 /* get the path between the given NIDs;
262 * passing 0 to either @pin or @dac behaves as a wildcard
264 struct nid_path
*snd_hda_get_nid_path(struct hda_codec
*codec
,
265 hda_nid_t from_nid
, hda_nid_t to_nid
)
267 return get_nid_path(codec
, from_nid
, to_nid
, 0);
269 EXPORT_SYMBOL_HDA(snd_hda_get_nid_path
);
271 /* get the index number corresponding to the path instance;
272 * the index starts from 1, for easier checking the invalid value
274 int snd_hda_get_path_idx(struct hda_codec
*codec
, struct nid_path
*path
)
276 struct hda_gen_spec
*spec
= codec
->spec
;
277 struct nid_path
*array
= spec
->paths
.list
;
280 if (!spec
->paths
.used
)
283 if (idx
< 0 || idx
>= spec
->paths
.used
)
287 EXPORT_SYMBOL_HDA(snd_hda_get_path_idx
);
289 /* get the path instance corresponding to the given index number */
290 struct nid_path
*snd_hda_get_path_from_idx(struct hda_codec
*codec
, int idx
)
292 struct hda_gen_spec
*spec
= codec
->spec
;
294 if (idx
<= 0 || idx
> spec
->paths
.used
)
296 return snd_array_elem(&spec
->paths
, idx
- 1);
298 EXPORT_SYMBOL_HDA(snd_hda_get_path_from_idx
);
300 /* check whether the given DAC is already found in any existing paths */
301 static bool is_dac_already_used(struct hda_codec
*codec
, hda_nid_t nid
)
303 struct hda_gen_spec
*spec
= codec
->spec
;
306 for (i
= 0; i
< spec
->paths
.used
; i
++) {
307 struct nid_path
*path
= snd_array_elem(&spec
->paths
, i
);
308 if (path
->path
[0] == nid
)
314 /* check whether the given two widgets can be connected */
315 static bool is_reachable_path(struct hda_codec
*codec
,
316 hda_nid_t from_nid
, hda_nid_t to_nid
)
318 if (!from_nid
|| !to_nid
)
320 return snd_hda_get_conn_index(codec
, to_nid
, from_nid
, true) >= 0;
323 /* nid, dir and idx */
324 #define AMP_VAL_COMPARE_MASK (0xffff | (1U << 18) | (0x0f << 19))
326 /* check whether the given ctl is already assigned in any path elements */
327 static bool is_ctl_used(struct hda_codec
*codec
, unsigned int val
, int type
)
329 struct hda_gen_spec
*spec
= codec
->spec
;
332 val
&= AMP_VAL_COMPARE_MASK
;
333 for (i
= 0; i
< spec
->paths
.used
; i
++) {
334 struct nid_path
*path
= snd_array_elem(&spec
->paths
, i
);
335 if ((path
->ctls
[type
] & AMP_VAL_COMPARE_MASK
) == val
)
341 /* check whether a control with the given (nid, dir, idx) was assigned */
342 static bool is_ctl_associated(struct hda_codec
*codec
, hda_nid_t nid
,
343 int dir
, int idx
, int type
)
345 unsigned int val
= HDA_COMPOSE_AMP_VAL(nid
, 3, idx
, dir
);
346 return is_ctl_used(codec
, val
, type
);
349 static void print_nid_path(const char *pfx
, struct nid_path
*path
)
356 for (i
= 0; i
< path
->depth
; i
++) {
358 sprintf(tmp
, ":%02x", path
->path
[i
]);
359 strlcat(buf
, tmp
, sizeof(buf
));
361 snd_printdd("%s path: depth=%d %s\n", pfx
, path
->depth
, buf
);
364 /* called recursively */
365 static bool __parse_nid_path(struct hda_codec
*codec
,
366 hda_nid_t from_nid
, hda_nid_t to_nid
,
367 int anchor_nid
, struct nid_path
*path
,
370 const hda_nid_t
*conn
;
373 if (to_nid
== anchor_nid
)
374 anchor_nid
= 0; /* anchor passed */
375 else if (to_nid
== (hda_nid_t
)(-anchor_nid
))
376 return false; /* hit the exclusive nid */
378 nums
= snd_hda_get_conn_list(codec
, to_nid
, &conn
);
379 for (i
= 0; i
< nums
; i
++) {
380 if (conn
[i
] != from_nid
) {
381 /* special case: when from_nid is 0,
382 * try to find an empty DAC
385 get_wcaps_type(get_wcaps(codec
, conn
[i
])) != AC_WID_AUD_OUT
||
386 is_dac_already_used(codec
, conn
[i
]))
389 /* anchor is not requested or already passed? */
393 if (depth
>= MAX_NID_PATH_DEPTH
)
395 for (i
= 0; i
< nums
; i
++) {
397 type
= get_wcaps_type(get_wcaps(codec
, conn
[i
]));
398 if (type
== AC_WID_AUD_OUT
|| type
== AC_WID_AUD_IN
||
401 if (__parse_nid_path(codec
, from_nid
, conn
[i
],
402 anchor_nid
, path
, depth
+ 1))
408 path
->path
[path
->depth
] = conn
[i
];
409 path
->idx
[path
->depth
+ 1] = i
;
410 if (nums
> 1 && get_wcaps_type(get_wcaps(codec
, to_nid
)) != AC_WID_AUD_MIX
)
411 path
->multi
[path
->depth
+ 1] = 1;
416 /* parse the widget path from the given nid to the target nid;
417 * when @from_nid is 0, try to find an empty DAC;
418 * when @anchor_nid is set to a positive value, only paths through the widget
419 * with the given value are evaluated.
420 * when @anchor_nid is set to a negative value, paths through the widget
421 * with the negative of given value are excluded, only other paths are chosen.
422 * when @anchor_nid is zero, no special handling about path selection.
424 bool snd_hda_parse_nid_path(struct hda_codec
*codec
, hda_nid_t from_nid
,
425 hda_nid_t to_nid
, int anchor_nid
,
426 struct nid_path
*path
)
428 if (__parse_nid_path(codec
, from_nid
, to_nid
, anchor_nid
, path
, 1)) {
429 path
->path
[path
->depth
] = to_nid
;
435 EXPORT_SYMBOL_HDA(snd_hda_parse_nid_path
);
438 * parse the path between the given NIDs and add to the path list.
439 * if no valid path is found, return NULL
442 snd_hda_add_new_path(struct hda_codec
*codec
, hda_nid_t from_nid
,
443 hda_nid_t to_nid
, int anchor_nid
)
445 struct hda_gen_spec
*spec
= codec
->spec
;
446 struct nid_path
*path
;
448 if (from_nid
&& to_nid
&& !is_reachable_path(codec
, from_nid
, to_nid
))
451 /* check whether the path has been already added */
452 path
= get_nid_path(codec
, from_nid
, to_nid
, anchor_nid
);
456 path
= snd_array_new(&spec
->paths
);
459 memset(path
, 0, sizeof(*path
));
460 if (snd_hda_parse_nid_path(codec
, from_nid
, to_nid
, anchor_nid
, path
))
466 EXPORT_SYMBOL_HDA(snd_hda_add_new_path
);
468 /* clear the given path as invalid so that it won't be picked up later */
469 static void invalidate_nid_path(struct hda_codec
*codec
, int idx
)
471 struct nid_path
*path
= snd_hda_get_path_from_idx(codec
, idx
);
474 memset(path
, 0, sizeof(*path
));
477 /* return a DAC if paired to the given pin by codec driver */
478 static hda_nid_t
get_preferred_dac(struct hda_codec
*codec
, hda_nid_t pin
)
480 struct hda_gen_spec
*spec
= codec
->spec
;
481 const hda_nid_t
*list
= spec
->preferred_dacs
;
485 for (; *list
; list
+= 2)
491 /* look for an empty DAC slot */
492 static hda_nid_t
look_for_dac(struct hda_codec
*codec
, hda_nid_t pin
,
495 struct hda_gen_spec
*spec
= codec
->spec
;
499 for (i
= 0; i
< spec
->num_all_dacs
; i
++) {
500 hda_nid_t nid
= spec
->all_dacs
[i
];
501 if (!nid
|| is_dac_already_used(codec
, nid
))
503 cap_digital
= !!(get_wcaps(codec
, nid
) & AC_WCAP_DIGITAL
);
504 if (is_digital
!= cap_digital
)
506 if (is_reachable_path(codec
, nid
, pin
))
512 /* replace the channels in the composed amp value with the given number */
513 static unsigned int amp_val_replace_channels(unsigned int val
, unsigned int chs
)
515 val
&= ~(0x3U
<< 16);
520 /* check whether the widget has the given amp capability for the direction */
521 static bool check_amp_caps(struct hda_codec
*codec
, hda_nid_t nid
,
522 int dir
, unsigned int bits
)
526 if (get_wcaps(codec
, nid
) & (1 << (dir
+ 1)))
527 if (query_amp_caps(codec
, nid
, dir
) & bits
)
532 static bool same_amp_caps(struct hda_codec
*codec
, hda_nid_t nid1
,
533 hda_nid_t nid2
, int dir
)
535 if (!(get_wcaps(codec
, nid1
) & (1 << (dir
+ 1))))
536 return !(get_wcaps(codec
, nid2
) & (1 << (dir
+ 1)));
537 return (query_amp_caps(codec
, nid1
, dir
) ==
538 query_amp_caps(codec
, nid2
, dir
));
541 #define nid_has_mute(codec, nid, dir) \
542 check_amp_caps(codec, nid, dir, (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE))
543 #define nid_has_volume(codec, nid, dir) \
544 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
546 /* look for a widget suitable for assigning a mute switch in the path */
547 static hda_nid_t
look_for_out_mute_nid(struct hda_codec
*codec
,
548 struct nid_path
*path
)
552 for (i
= path
->depth
- 1; i
>= 0; i
--) {
553 if (nid_has_mute(codec
, path
->path
[i
], HDA_OUTPUT
))
554 return path
->path
[i
];
555 if (i
!= path
->depth
- 1 && i
!= 0 &&
556 nid_has_mute(codec
, path
->path
[i
], HDA_INPUT
))
557 return path
->path
[i
];
562 /* look for a widget suitable for assigning a volume ctl in the path */
563 static hda_nid_t
look_for_out_vol_nid(struct hda_codec
*codec
,
564 struct nid_path
*path
)
566 struct hda_gen_spec
*spec
= codec
->spec
;
569 for (i
= path
->depth
- 1; i
>= 0; i
--) {
570 hda_nid_t nid
= path
->path
[i
];
571 if ((spec
->out_vol_mask
>> nid
) & 1)
573 if (nid_has_volume(codec
, nid
, HDA_OUTPUT
))
580 * path activation / deactivation
583 /* can have the amp-in capability? */
584 static bool has_amp_in(struct hda_codec
*codec
, struct nid_path
*path
, int idx
)
586 hda_nid_t nid
= path
->path
[idx
];
587 unsigned int caps
= get_wcaps(codec
, nid
);
588 unsigned int type
= get_wcaps_type(caps
);
590 if (!(caps
& AC_WCAP_IN_AMP
))
592 if (type
== AC_WID_PIN
&& idx
> 0) /* only for input pins */
597 /* can have the amp-out capability? */
598 static bool has_amp_out(struct hda_codec
*codec
, struct nid_path
*path
, int idx
)
600 hda_nid_t nid
= path
->path
[idx
];
601 unsigned int caps
= get_wcaps(codec
, nid
);
602 unsigned int type
= get_wcaps_type(caps
);
604 if (!(caps
& AC_WCAP_OUT_AMP
))
606 if (type
== AC_WID_PIN
&& !idx
) /* only for output pins */
611 /* check whether the given (nid,dir,idx) is active */
612 static bool is_active_nid(struct hda_codec
*codec
, hda_nid_t nid
,
613 unsigned int dir
, unsigned int idx
)
615 struct hda_gen_spec
*spec
= codec
->spec
;
618 for (n
= 0; n
< spec
->paths
.used
; n
++) {
619 struct nid_path
*path
= snd_array_elem(&spec
->paths
, n
);
622 for (i
= 0; i
< path
->depth
; i
++) {
623 if (path
->path
[i
] == nid
) {
624 if (dir
== HDA_OUTPUT
|| path
->idx
[i
] == idx
)
633 /* check whether the NID is referred by any active paths */
634 #define is_active_nid_for_any(codec, nid) \
635 is_active_nid(codec, nid, HDA_OUTPUT, 0)
637 /* get the default amp value for the target state */
638 static int get_amp_val_to_activate(struct hda_codec
*codec
, hda_nid_t nid
,
639 int dir
, unsigned int caps
, bool enable
)
641 unsigned int val
= 0;
643 if (caps
& AC_AMPCAP_NUM_STEPS
) {
646 val
= (caps
& AC_AMPCAP_OFFSET
) >> AC_AMPCAP_OFFSET_SHIFT
;
648 if (caps
& (AC_AMPCAP_MUTE
| AC_AMPCAP_MIN_MUTE
)) {
655 /* initialize the amp value (only at the first time) */
656 static void init_amp(struct hda_codec
*codec
, hda_nid_t nid
, int dir
, int idx
)
658 unsigned int caps
= query_amp_caps(codec
, nid
, dir
);
659 int val
= get_amp_val_to_activate(codec
, nid
, dir
, caps
, false);
660 snd_hda_codec_amp_init_stereo(codec
, nid
, dir
, idx
, 0xff, val
);
663 /* calculate amp value mask we can modify;
664 * if the given amp is controlled by mixers, don't touch it
666 static unsigned int get_amp_mask_to_modify(struct hda_codec
*codec
,
667 hda_nid_t nid
, int dir
, int idx
,
670 unsigned int mask
= 0xff;
672 if (caps
& (AC_AMPCAP_MUTE
| AC_AMPCAP_MIN_MUTE
)) {
673 if (is_ctl_associated(codec
, nid
, dir
, idx
, NID_PATH_MUTE_CTL
))
676 if (caps
& AC_AMPCAP_NUM_STEPS
) {
677 if (is_ctl_associated(codec
, nid
, dir
, idx
, NID_PATH_VOL_CTL
) ||
678 is_ctl_associated(codec
, nid
, dir
, idx
, NID_PATH_BOOST_CTL
))
684 static void activate_amp(struct hda_codec
*codec
, hda_nid_t nid
, int dir
,
685 int idx
, int idx_to_check
, bool enable
)
688 unsigned int mask
, val
;
690 if (!enable
&& is_active_nid(codec
, nid
, dir
, idx_to_check
))
693 caps
= query_amp_caps(codec
, nid
, dir
);
694 val
= get_amp_val_to_activate(codec
, nid
, dir
, caps
, enable
);
695 mask
= get_amp_mask_to_modify(codec
, nid
, dir
, idx_to_check
, caps
);
700 snd_hda_codec_amp_stereo(codec
, nid
, dir
, idx
, mask
, val
);
703 static void activate_amp_out(struct hda_codec
*codec
, struct nid_path
*path
,
706 hda_nid_t nid
= path
->path
[i
];
707 init_amp(codec
, nid
, HDA_OUTPUT
, 0);
708 activate_amp(codec
, nid
, HDA_OUTPUT
, 0, 0, enable
);
711 static void activate_amp_in(struct hda_codec
*codec
, struct nid_path
*path
,
712 int i
, bool enable
, bool add_aamix
)
714 struct hda_gen_spec
*spec
= codec
->spec
;
715 const hda_nid_t
*conn
;
718 hda_nid_t nid
= path
->path
[i
];
720 nums
= snd_hda_get_conn_list(codec
, nid
, &conn
);
721 type
= get_wcaps_type(get_wcaps(codec
, nid
));
722 if (type
== AC_WID_PIN
||
723 (type
== AC_WID_AUD_IN
&& codec
->single_adc_amp
)) {
729 for (n
= 0; n
< nums
; n
++)
730 init_amp(codec
, nid
, HDA_INPUT
, n
);
732 /* here is a little bit tricky in comparison with activate_amp_out();
733 * when aa-mixer is available, we need to enable the path as well
735 for (n
= 0; n
< nums
; n
++) {
736 if (n
!= idx
&& (!add_aamix
|| conn
[n
] != spec
->mixer_merge_nid
))
738 activate_amp(codec
, nid
, HDA_INPUT
, n
, idx
, enable
);
742 /* activate or deactivate the given path
743 * if @add_aamix is set, enable the input from aa-mix NID as well (if any)
745 void snd_hda_activate_path(struct hda_codec
*codec
, struct nid_path
*path
,
746 bool enable
, bool add_aamix
)
748 struct hda_gen_spec
*spec
= codec
->spec
;
752 path
->active
= false;
754 for (i
= path
->depth
- 1; i
>= 0; i
--) {
755 hda_nid_t nid
= path
->path
[i
];
756 if (enable
&& spec
->power_down_unused
) {
757 /* make sure the widget is powered up */
758 if (!snd_hda_check_power_state(codec
, nid
, AC_PWRST_D0
))
759 snd_hda_codec_write(codec
, nid
, 0,
760 AC_VERB_SET_POWER_STATE
,
763 if (enable
&& path
->multi
[i
])
764 snd_hda_codec_write_cache(codec
, nid
, 0,
765 AC_VERB_SET_CONNECT_SEL
,
767 if (has_amp_in(codec
, path
, i
))
768 activate_amp_in(codec
, path
, i
, enable
, add_aamix
);
769 if (has_amp_out(codec
, path
, i
))
770 activate_amp_out(codec
, path
, i
, enable
);
776 EXPORT_SYMBOL_HDA(snd_hda_activate_path
);
778 /* if the given path is inactive, put widgets into D3 (only if suitable) */
779 static void path_power_down_sync(struct hda_codec
*codec
, struct nid_path
*path
)
781 struct hda_gen_spec
*spec
= codec
->spec
;
782 bool changed
= false;
785 if (!spec
->power_down_unused
|| path
->active
)
788 for (i
= 0; i
< path
->depth
; i
++) {
789 hda_nid_t nid
= path
->path
[i
];
790 if (!snd_hda_check_power_state(codec
, nid
, AC_PWRST_D3
) &&
791 !is_active_nid_for_any(codec
, nid
)) {
792 snd_hda_codec_write(codec
, nid
, 0,
793 AC_VERB_SET_POWER_STATE
,
801 snd_hda_codec_read(codec
, path
->path
[0], 0,
802 AC_VERB_GET_POWER_STATE
, 0);
806 /* turn on/off EAPD on the given pin */
807 static void set_pin_eapd(struct hda_codec
*codec
, hda_nid_t pin
, bool enable
)
809 struct hda_gen_spec
*spec
= codec
->spec
;
810 if (spec
->own_eapd_ctl
||
811 !(snd_hda_query_pin_caps(codec
, pin
) & AC_PINCAP_EAPD
))
813 if (spec
->keep_eapd_on
&& !enable
)
817 snd_hda_codec_update_cache(codec
, pin
, 0,
818 AC_VERB_SET_EAPD_BTLENABLE
,
819 enable
? 0x02 : 0x00);
822 /* re-initialize the path specified by the given path index */
823 static void resume_path_from_idx(struct hda_codec
*codec
, int path_idx
)
825 struct nid_path
*path
= snd_hda_get_path_from_idx(codec
, path_idx
);
827 snd_hda_activate_path(codec
, path
, path
->active
, false);
832 * Helper functions for creating mixer ctl elements
835 static int hda_gen_mixer_mute_put(struct snd_kcontrol
*kcontrol
,
836 struct snd_ctl_elem_value
*ucontrol
);
837 static int hda_gen_bind_mute_put(struct snd_kcontrol
*kcontrol
,
838 struct snd_ctl_elem_value
*ucontrol
);
845 static const struct snd_kcontrol_new control_templates
[] = {
846 HDA_CODEC_VOLUME(NULL
, 0, 0, 0),
847 /* only the put callback is replaced for handling the special mute */
849 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
850 .subdevice
= HDA_SUBDEV_AMP_FLAG
,
851 .info
= snd_hda_mixer_amp_switch_info
,
852 .get
= snd_hda_mixer_amp_switch_get
,
853 .put
= hda_gen_mixer_mute_put
, /* replaced */
854 .private_value
= HDA_COMPOSE_AMP_VAL(0, 3, 0, 0),
857 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
858 .info
= snd_hda_mixer_amp_switch_info
,
859 .get
= snd_hda_mixer_bind_switch_get
,
860 .put
= hda_gen_bind_mute_put
, /* replaced */
861 .private_value
= HDA_COMPOSE_AMP_VAL(0, 3, 0, 0),
865 /* add dynamic controls from template */
866 static struct snd_kcontrol_new
*
867 add_control(struct hda_gen_spec
*spec
, int type
, const char *name
,
868 int cidx
, unsigned long val
)
870 struct snd_kcontrol_new
*knew
;
872 knew
= snd_hda_gen_add_kctl(spec
, name
, &control_templates
[type
]);
876 if (get_amp_nid_(val
))
877 knew
->subdevice
= HDA_SUBDEV_AMP_FLAG
;
878 knew
->private_value
= val
;
882 static int add_control_with_pfx(struct hda_gen_spec
*spec
, int type
,
883 const char *pfx
, const char *dir
,
884 const char *sfx
, int cidx
, unsigned long val
)
886 char name
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
887 snprintf(name
, sizeof(name
), "%s %s %s", pfx
, dir
, sfx
);
888 if (!add_control(spec
, type
, name
, cidx
, val
))
893 #define add_pb_vol_ctrl(spec, type, pfx, val) \
894 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
895 #define add_pb_sw_ctrl(spec, type, pfx, val) \
896 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
897 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
898 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
899 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
900 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
902 static int add_vol_ctl(struct hda_codec
*codec
, const char *pfx
, int cidx
,
903 unsigned int chs
, struct nid_path
*path
)
908 val
= path
->ctls
[NID_PATH_VOL_CTL
];
911 val
= amp_val_replace_channels(val
, chs
);
912 return __add_pb_vol_ctrl(codec
->spec
, HDA_CTL_WIDGET_VOL
, pfx
, cidx
, val
);
915 /* return the channel bits suitable for the given path->ctls[] */
916 static int get_default_ch_nums(struct hda_codec
*codec
, struct nid_path
*path
,
919 int chs
= 1; /* mono (left only) */
921 hda_nid_t nid
= get_amp_nid_(path
->ctls
[type
]);
922 if (nid
&& (get_wcaps(codec
, nid
) & AC_WCAP_STEREO
))
923 chs
= 3; /* stereo */
928 static int add_stereo_vol(struct hda_codec
*codec
, const char *pfx
, int cidx
,
929 struct nid_path
*path
)
931 int chs
= get_default_ch_nums(codec
, path
, NID_PATH_VOL_CTL
);
932 return add_vol_ctl(codec
, pfx
, cidx
, chs
, path
);
935 /* create a mute-switch for the given mixer widget;
936 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
938 static int add_sw_ctl(struct hda_codec
*codec
, const char *pfx
, int cidx
,
939 unsigned int chs
, struct nid_path
*path
)
942 int type
= HDA_CTL_WIDGET_MUTE
;
946 val
= path
->ctls
[NID_PATH_MUTE_CTL
];
949 val
= amp_val_replace_channels(val
, chs
);
950 if (get_amp_direction_(val
) == HDA_INPUT
) {
951 hda_nid_t nid
= get_amp_nid_(val
);
952 int nums
= snd_hda_get_num_conns(codec
, nid
);
954 type
= HDA_CTL_BIND_MUTE
;
958 return __add_pb_sw_ctrl(codec
->spec
, type
, pfx
, cidx
, val
);
961 static int add_stereo_sw(struct hda_codec
*codec
, const char *pfx
,
962 int cidx
, struct nid_path
*path
)
964 int chs
= get_default_ch_nums(codec
, path
, NID_PATH_MUTE_CTL
);
965 return add_sw_ctl(codec
, pfx
, cidx
, chs
, path
);
968 /* playback mute control with the software mute bit check */
969 static void sync_auto_mute_bits(struct snd_kcontrol
*kcontrol
,
970 struct snd_ctl_elem_value
*ucontrol
)
972 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
973 struct hda_gen_spec
*spec
= codec
->spec
;
975 if (spec
->auto_mute_via_amp
) {
976 hda_nid_t nid
= get_amp_nid(kcontrol
);
977 bool enabled
= !((spec
->mute_bits
>> nid
) & 1);
978 ucontrol
->value
.integer
.value
[0] &= enabled
;
979 ucontrol
->value
.integer
.value
[1] &= enabled
;
983 static int hda_gen_mixer_mute_put(struct snd_kcontrol
*kcontrol
,
984 struct snd_ctl_elem_value
*ucontrol
)
986 sync_auto_mute_bits(kcontrol
, ucontrol
);
987 return snd_hda_mixer_amp_switch_put(kcontrol
, ucontrol
);
990 static int hda_gen_bind_mute_put(struct snd_kcontrol
*kcontrol
,
991 struct snd_ctl_elem_value
*ucontrol
)
993 sync_auto_mute_bits(kcontrol
, ucontrol
);
994 return snd_hda_mixer_bind_switch_put(kcontrol
, ucontrol
);
997 /* any ctl assigned to the path with the given index? */
998 static bool path_has_mixer(struct hda_codec
*codec
, int path_idx
, int ctl_type
)
1000 struct nid_path
*path
= snd_hda_get_path_from_idx(codec
, path_idx
);
1001 return path
&& path
->ctls
[ctl_type
];
1004 static const char * const channel_name
[4] = {
1005 "Front", "Surround", "CLFE", "Side"
1008 /* give some appropriate ctl name prefix for the given line out channel */
1009 static const char *get_line_out_pfx(struct hda_codec
*codec
, int ch
,
1010 int *index
, int ctl_type
)
1012 struct hda_gen_spec
*spec
= codec
->spec
;
1013 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1016 if (cfg
->line_outs
== 1 && !spec
->multi_ios
&&
1017 !cfg
->hp_outs
&& !cfg
->speaker_outs
)
1018 return spec
->vmaster_mute
.hook
? "PCM" : "Master";
1020 /* if there is really a single DAC used in the whole output paths,
1021 * use it master (or "PCM" if a vmaster hook is present)
1023 if (spec
->multiout
.num_dacs
== 1 && !spec
->mixer_nid
&&
1024 !spec
->multiout
.hp_out_nid
[0] && !spec
->multiout
.extra_out_nid
[0])
1025 return spec
->vmaster_mute
.hook
? "PCM" : "Master";
1027 /* multi-io channels */
1028 if (ch
>= cfg
->line_outs
)
1029 return channel_name
[ch
];
1031 switch (cfg
->line_out_type
) {
1032 case AUTO_PIN_SPEAKER_OUT
:
1033 /* if the primary channel vol/mute is shared with HP volume,
1034 * don't name it as Speaker
1036 if (!ch
&& cfg
->hp_outs
&&
1037 !path_has_mixer(codec
, spec
->hp_paths
[0], ctl_type
))
1039 if (cfg
->line_outs
== 1)
1041 if (cfg
->line_outs
== 2)
1042 return ch
? "Bass Speaker" : "Speaker";
1044 case AUTO_PIN_HP_OUT
:
1045 /* if the primary channel vol/mute is shared with spk volume,
1046 * don't name it as Headphone
1048 if (!ch
&& cfg
->speaker_outs
&&
1049 !path_has_mixer(codec
, spec
->speaker_paths
[0], ctl_type
))
1051 /* for multi-io case, only the primary out */
1052 if (ch
&& spec
->multi_ios
)
1058 /* for a single channel output, we don't have to name the channel */
1059 if (cfg
->line_outs
== 1 && !spec
->multi_ios
)
1062 if (ch
>= ARRAY_SIZE(channel_name
)) {
1067 return channel_name
[ch
];
1071 * Parse output paths
1074 /* badness definition */
1076 /* No primary DAC is found for the main output */
1077 BAD_NO_PRIMARY_DAC
= 0x10000,
1078 /* No DAC is found for the extra output */
1079 BAD_NO_DAC
= 0x4000,
1080 /* No possible multi-ios */
1081 BAD_MULTI_IO
= 0x120,
1082 /* No individual DAC for extra output */
1083 BAD_NO_EXTRA_DAC
= 0x102,
1084 /* No individual DAC for extra surrounds */
1085 BAD_NO_EXTRA_SURR_DAC
= 0x101,
1086 /* Primary DAC shared with main surrounds */
1087 BAD_SHARED_SURROUND
= 0x100,
1088 /* No independent HP possible */
1089 BAD_NO_INDEP_HP
= 0x10,
1090 /* Primary DAC shared with main CLFE */
1091 BAD_SHARED_CLFE
= 0x10,
1092 /* Primary DAC shared with extra surrounds */
1093 BAD_SHARED_EXTRA_SURROUND
= 0x10,
1094 /* Volume widget is shared */
1095 BAD_SHARED_VOL
= 0x10,
1098 /* look for widgets in the given path which are appropriate for
1099 * volume and mute controls, and assign the values to ctls[].
1101 * When no appropriate widget is found in the path, the badness value
1102 * is incremented depending on the situation. The function returns the
1103 * total badness for both volume and mute controls.
1105 static int assign_out_path_ctls(struct hda_codec
*codec
, struct nid_path
*path
)
1112 return BAD_SHARED_VOL
* 2;
1114 if (path
->ctls
[NID_PATH_VOL_CTL
] ||
1115 path
->ctls
[NID_PATH_MUTE_CTL
])
1116 return 0; /* already evaluated */
1118 nid
= look_for_out_vol_nid(codec
, path
);
1120 val
= HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_OUTPUT
);
1121 if (is_ctl_used(codec
, val
, NID_PATH_VOL_CTL
))
1122 badness
+= BAD_SHARED_VOL
;
1124 path
->ctls
[NID_PATH_VOL_CTL
] = val
;
1126 badness
+= BAD_SHARED_VOL
;
1127 nid
= look_for_out_mute_nid(codec
, path
);
1129 unsigned int wid_type
= get_wcaps_type(get_wcaps(codec
, nid
));
1130 if (wid_type
== AC_WID_PIN
|| wid_type
== AC_WID_AUD_OUT
||
1131 nid_has_mute(codec
, nid
, HDA_OUTPUT
))
1132 val
= HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_OUTPUT
);
1134 val
= HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_INPUT
);
1135 if (is_ctl_used(codec
, val
, NID_PATH_MUTE_CTL
))
1136 badness
+= BAD_SHARED_VOL
;
1138 path
->ctls
[NID_PATH_MUTE_CTL
] = val
;
1140 badness
+= BAD_SHARED_VOL
;
1144 const struct badness_table hda_main_out_badness
= {
1145 .no_primary_dac
= BAD_NO_PRIMARY_DAC
,
1146 .no_dac
= BAD_NO_DAC
,
1147 .shared_primary
= BAD_NO_PRIMARY_DAC
,
1148 .shared_surr
= BAD_SHARED_SURROUND
,
1149 .shared_clfe
= BAD_SHARED_CLFE
,
1150 .shared_surr_main
= BAD_SHARED_SURROUND
,
1152 EXPORT_SYMBOL_HDA(hda_main_out_badness
);
1154 const struct badness_table hda_extra_out_badness
= {
1155 .no_primary_dac
= BAD_NO_DAC
,
1156 .no_dac
= BAD_NO_DAC
,
1157 .shared_primary
= BAD_NO_EXTRA_DAC
,
1158 .shared_surr
= BAD_SHARED_EXTRA_SURROUND
,
1159 .shared_clfe
= BAD_SHARED_EXTRA_SURROUND
,
1160 .shared_surr_main
= BAD_NO_EXTRA_SURR_DAC
,
1162 EXPORT_SYMBOL_HDA(hda_extra_out_badness
);
1164 /* get the DAC of the primary output corresponding to the given array index */
1165 static hda_nid_t
get_primary_out(struct hda_codec
*codec
, int idx
)
1167 struct hda_gen_spec
*spec
= codec
->spec
;
1168 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1170 if (cfg
->line_outs
> idx
)
1171 return spec
->private_dac_nids
[idx
];
1172 idx
-= cfg
->line_outs
;
1173 if (spec
->multi_ios
> idx
)
1174 return spec
->multi_io
[idx
].dac
;
1178 /* return the DAC if it's reachable, otherwise zero */
1179 static inline hda_nid_t
try_dac(struct hda_codec
*codec
,
1180 hda_nid_t dac
, hda_nid_t pin
)
1182 return is_reachable_path(codec
, dac
, pin
) ? dac
: 0;
1185 /* try to assign DACs to pins and return the resultant badness */
1186 static int try_assign_dacs(struct hda_codec
*codec
, int num_outs
,
1187 const hda_nid_t
*pins
, hda_nid_t
*dacs
,
1189 const struct badness_table
*bad
)
1191 struct hda_gen_spec
*spec
= codec
->spec
;
1199 for (i
= 0; i
< num_outs
; i
++) {
1200 struct nid_path
*path
;
1201 hda_nid_t pin
= pins
[i
];
1203 path
= snd_hda_get_path_from_idx(codec
, path_idx
[i
]);
1205 badness
+= assign_out_path_ctls(codec
, path
);
1209 dacs
[i
] = get_preferred_dac(codec
, pin
);
1211 if (is_dac_already_used(codec
, dacs
[i
]))
1212 badness
+= bad
->shared_primary
;
1216 dacs
[i
] = look_for_dac(codec
, pin
, false);
1217 if (!dacs
[i
] && !i
) {
1218 /* try to steal the DAC of surrounds for the front */
1219 for (j
= 1; j
< num_outs
; j
++) {
1220 if (is_reachable_path(codec
, dacs
[j
], pin
)) {
1223 invalidate_nid_path(codec
, path_idx
[j
]);
1232 dac
= try_dac(codec
, get_primary_out(codec
, i
), pin
);
1234 dac
= try_dac(codec
, dacs
[0], pin
);
1236 dac
= try_dac(codec
, get_primary_out(codec
, i
), pin
);
1239 badness
+= bad
->shared_primary
;
1241 badness
+= bad
->shared_surr
;
1243 badness
+= bad
->shared_clfe
;
1244 } else if (is_reachable_path(codec
, spec
->private_dac_nids
[0], pin
)) {
1245 dac
= spec
->private_dac_nids
[0];
1246 badness
+= bad
->shared_surr_main
;
1248 badness
+= bad
->no_primary_dac
;
1250 badness
+= bad
->no_dac
;
1254 path
= snd_hda_add_new_path(codec
, dac
, pin
, -spec
->mixer_nid
);
1255 if (!path
&& !i
&& spec
->mixer_nid
) {
1256 /* try with aamix */
1257 path
= snd_hda_add_new_path(codec
, dac
, pin
, 0);
1261 badness
+= bad
->no_dac
;
1263 /* print_nid_path("output", path); */
1264 path
->active
= true;
1265 path_idx
[i
] = snd_hda_get_path_idx(codec
, path
);
1266 badness
+= assign_out_path_ctls(codec
, path
);
1273 /* return NID if the given pin has only a single connection to a certain DAC */
1274 static hda_nid_t
get_dac_if_single(struct hda_codec
*codec
, hda_nid_t pin
)
1276 struct hda_gen_spec
*spec
= codec
->spec
;
1278 hda_nid_t nid_found
= 0;
1280 for (i
= 0; i
< spec
->num_all_dacs
; i
++) {
1281 hda_nid_t nid
= spec
->all_dacs
[i
];
1282 if (!nid
|| is_dac_already_used(codec
, nid
))
1284 if (is_reachable_path(codec
, nid
, pin
)) {
1293 /* check whether the given pin can be a multi-io pin */
1294 static bool can_be_multiio_pin(struct hda_codec
*codec
,
1295 unsigned int location
, hda_nid_t nid
)
1297 unsigned int defcfg
, caps
;
1299 defcfg
= snd_hda_codec_get_pincfg(codec
, nid
);
1300 if (get_defcfg_connect(defcfg
) != AC_JACK_PORT_COMPLEX
)
1302 if (location
&& get_defcfg_location(defcfg
) != location
)
1304 caps
= snd_hda_query_pin_caps(codec
, nid
);
1305 if (!(caps
& AC_PINCAP_OUT
))
1310 /* count the number of input pins that are capable to be multi-io */
1311 static int count_multiio_pins(struct hda_codec
*codec
, hda_nid_t reference_pin
)
1313 struct hda_gen_spec
*spec
= codec
->spec
;
1314 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1315 unsigned int defcfg
= snd_hda_codec_get_pincfg(codec
, reference_pin
);
1316 unsigned int location
= get_defcfg_location(defcfg
);
1320 for (type
= AUTO_PIN_LINE_IN
; type
>= AUTO_PIN_MIC
; type
--) {
1321 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
1322 if (cfg
->inputs
[i
].type
!= type
)
1324 if (can_be_multiio_pin(codec
, location
,
1325 cfg
->inputs
[i
].pin
))
1335 * When hardwired is set, try to fill ony hardwired pins, and returns
1336 * zero if any pins are filled, non-zero if nothing found.
1337 * When hardwired is off, try to fill possible input pins, and returns
1338 * the badness value.
1340 static int fill_multi_ios(struct hda_codec
*codec
,
1341 hda_nid_t reference_pin
,
1344 struct hda_gen_spec
*spec
= codec
->spec
;
1345 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1346 int type
, i
, j
, num_pins
, old_pins
;
1347 unsigned int defcfg
= snd_hda_codec_get_pincfg(codec
, reference_pin
);
1348 unsigned int location
= get_defcfg_location(defcfg
);
1350 struct nid_path
*path
;
1352 old_pins
= spec
->multi_ios
;
1356 num_pins
= count_multiio_pins(codec
, reference_pin
);
1360 for (type
= AUTO_PIN_LINE_IN
; type
>= AUTO_PIN_MIC
; type
--) {
1361 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
1362 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
1365 if (cfg
->inputs
[i
].type
!= type
)
1367 if (!can_be_multiio_pin(codec
, location
, nid
))
1369 for (j
= 0; j
< spec
->multi_ios
; j
++) {
1370 if (nid
== spec
->multi_io
[j
].pin
)
1373 if (j
< spec
->multi_ios
)
1377 dac
= get_dac_if_single(codec
, nid
);
1379 dac
= look_for_dac(codec
, nid
, false);
1384 path
= snd_hda_add_new_path(codec
, dac
, nid
,
1390 /* print_nid_path("multiio", path); */
1391 spec
->multi_io
[spec
->multi_ios
].pin
= nid
;
1392 spec
->multi_io
[spec
->multi_ios
].dac
= dac
;
1393 spec
->out_paths
[cfg
->line_outs
+ spec
->multi_ios
] =
1394 snd_hda_get_path_idx(codec
, path
);
1396 if (spec
->multi_ios
>= 2)
1402 badness
= BAD_MULTI_IO
;
1403 if (old_pins
== spec
->multi_ios
) {
1405 return 1; /* nothing found */
1407 return badness
; /* no badness if nothing found */
1409 if (!hardwired
&& spec
->multi_ios
< 2) {
1410 /* cancel newly assigned paths */
1411 spec
->paths
.used
-= spec
->multi_ios
- old_pins
;
1412 spec
->multi_ios
= old_pins
;
1416 /* assign volume and mute controls */
1417 for (i
= old_pins
; i
< spec
->multi_ios
; i
++) {
1418 path
= snd_hda_get_path_from_idx(codec
, spec
->out_paths
[cfg
->line_outs
+ i
]);
1419 badness
+= assign_out_path_ctls(codec
, path
);
1425 /* map DACs for all pins in the list if they are single connections */
1426 static bool map_singles(struct hda_codec
*codec
, int outs
,
1427 const hda_nid_t
*pins
, hda_nid_t
*dacs
, int *path_idx
)
1429 struct hda_gen_spec
*spec
= codec
->spec
;
1432 for (i
= 0; i
< outs
; i
++) {
1433 struct nid_path
*path
;
1437 dac
= get_dac_if_single(codec
, pins
[i
]);
1440 path
= snd_hda_add_new_path(codec
, dac
, pins
[i
],
1442 if (!path
&& !i
&& spec
->mixer_nid
)
1443 path
= snd_hda_add_new_path(codec
, dac
, pins
[i
], 0);
1447 /* print_nid_path("output", path); */
1448 path
->active
= true;
1449 path_idx
[i
] = snd_hda_get_path_idx(codec
, path
);
1455 /* create a new path including aamix if available, and return its index */
1456 static int check_aamix_out_path(struct hda_codec
*codec
, int path_idx
)
1458 struct hda_gen_spec
*spec
= codec
->spec
;
1459 struct nid_path
*path
;
1460 hda_nid_t path_dac
, dac
, pin
;
1462 path
= snd_hda_get_path_from_idx(codec
, path_idx
);
1463 if (!path
|| !path
->depth
||
1464 is_nid_contained(path
, spec
->mixer_nid
))
1466 path_dac
= path
->path
[0];
1467 dac
= spec
->private_dac_nids
[0];
1468 pin
= path
->path
[path
->depth
- 1];
1469 path
= snd_hda_add_new_path(codec
, dac
, pin
, spec
->mixer_nid
);
1471 if (dac
!= path_dac
)
1473 else if (spec
->multiout
.hp_out_nid
[0])
1474 dac
= spec
->multiout
.hp_out_nid
[0];
1475 else if (spec
->multiout
.extra_out_nid
[0])
1476 dac
= spec
->multiout
.extra_out_nid
[0];
1480 path
= snd_hda_add_new_path(codec
, dac
, pin
,
1485 /* print_nid_path("output-aamix", path); */
1486 path
->active
= false; /* unused as default */
1487 return snd_hda_get_path_idx(codec
, path
);
1490 /* check whether the independent HP is available with the current config */
1491 static bool indep_hp_possible(struct hda_codec
*codec
)
1493 struct hda_gen_spec
*spec
= codec
->spec
;
1494 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1495 struct nid_path
*path
;
1498 if (cfg
->line_out_type
== AUTO_PIN_HP_OUT
)
1499 idx
= spec
->out_paths
[0];
1501 idx
= spec
->hp_paths
[0];
1502 path
= snd_hda_get_path_from_idx(codec
, idx
);
1506 /* assume no path conflicts unless aamix is involved */
1507 if (!spec
->mixer_nid
|| !is_nid_contained(path
, spec
->mixer_nid
))
1510 /* check whether output paths contain aamix */
1511 for (i
= 0; i
< cfg
->line_outs
; i
++) {
1512 if (spec
->out_paths
[i
] == idx
)
1514 path
= snd_hda_get_path_from_idx(codec
, spec
->out_paths
[i
]);
1515 if (path
&& is_nid_contained(path
, spec
->mixer_nid
))
1518 for (i
= 0; i
< cfg
->speaker_outs
; i
++) {
1519 path
= snd_hda_get_path_from_idx(codec
, spec
->speaker_paths
[i
]);
1520 if (path
&& is_nid_contained(path
, spec
->mixer_nid
))
1527 /* fill the empty entries in the dac array for speaker/hp with the
1528 * shared dac pointed by the paths
1530 static void refill_shared_dacs(struct hda_codec
*codec
, int num_outs
,
1531 hda_nid_t
*dacs
, int *path_idx
)
1533 struct nid_path
*path
;
1536 for (i
= 0; i
< num_outs
; i
++) {
1539 path
= snd_hda_get_path_from_idx(codec
, path_idx
[i
]);
1542 dacs
[i
] = path
->path
[0];
1546 /* fill in the dac_nids table from the parsed pin configuration */
1547 static int fill_and_eval_dacs(struct hda_codec
*codec
,
1548 bool fill_hardwired
,
1549 bool fill_mio_first
)
1551 struct hda_gen_spec
*spec
= codec
->spec
;
1552 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1553 int i
, err
, badness
;
1555 /* set num_dacs once to full for look_for_dac() */
1556 spec
->multiout
.num_dacs
= cfg
->line_outs
;
1557 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
1558 memset(spec
->private_dac_nids
, 0, sizeof(spec
->private_dac_nids
));
1559 memset(spec
->multiout
.hp_out_nid
, 0, sizeof(spec
->multiout
.hp_out_nid
));
1560 memset(spec
->multiout
.extra_out_nid
, 0, sizeof(spec
->multiout
.extra_out_nid
));
1561 spec
->multi_ios
= 0;
1562 snd_array_free(&spec
->paths
);
1564 /* clear path indices */
1565 memset(spec
->out_paths
, 0, sizeof(spec
->out_paths
));
1566 memset(spec
->hp_paths
, 0, sizeof(spec
->hp_paths
));
1567 memset(spec
->speaker_paths
, 0, sizeof(spec
->speaker_paths
));
1568 memset(spec
->aamix_out_paths
, 0, sizeof(spec
->aamix_out_paths
));
1569 memset(spec
->digout_paths
, 0, sizeof(spec
->digout_paths
));
1570 memset(spec
->input_paths
, 0, sizeof(spec
->input_paths
));
1571 memset(spec
->loopback_paths
, 0, sizeof(spec
->loopback_paths
));
1572 memset(&spec
->digin_path
, 0, sizeof(spec
->digin_path
));
1576 /* fill hard-wired DACs first */
1577 if (fill_hardwired
) {
1580 mapped
= map_singles(codec
, cfg
->line_outs
,
1582 spec
->private_dac_nids
,
1584 mapped
|= map_singles(codec
, cfg
->hp_outs
,
1586 spec
->multiout
.hp_out_nid
,
1588 mapped
|= map_singles(codec
, cfg
->speaker_outs
,
1590 spec
->multiout
.extra_out_nid
,
1591 spec
->speaker_paths
);
1592 if (!spec
->no_multi_io
&&
1593 fill_mio_first
&& cfg
->line_outs
== 1 &&
1594 cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
) {
1595 err
= fill_multi_ios(codec
, cfg
->line_out_pins
[0], true);
1602 badness
+= try_assign_dacs(codec
, cfg
->line_outs
, cfg
->line_out_pins
,
1603 spec
->private_dac_nids
, spec
->out_paths
,
1604 spec
->main_out_badness
);
1606 if (!spec
->no_multi_io
&& fill_mio_first
&&
1607 cfg
->line_outs
== 1 && cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
) {
1608 /* try to fill multi-io first */
1609 err
= fill_multi_ios(codec
, cfg
->line_out_pins
[0], false);
1612 /* we don't count badness at this stage yet */
1615 if (cfg
->line_out_type
!= AUTO_PIN_HP_OUT
) {
1616 err
= try_assign_dacs(codec
, cfg
->hp_outs
, cfg
->hp_pins
,
1617 spec
->multiout
.hp_out_nid
,
1619 spec
->extra_out_badness
);
1624 if (cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
) {
1625 err
= try_assign_dacs(codec
, cfg
->speaker_outs
,
1627 spec
->multiout
.extra_out_nid
,
1628 spec
->speaker_paths
,
1629 spec
->extra_out_badness
);
1634 if (!spec
->no_multi_io
&&
1635 cfg
->line_outs
== 1 && cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
) {
1636 err
= fill_multi_ios(codec
, cfg
->line_out_pins
[0], false);
1642 if (spec
->mixer_nid
) {
1643 spec
->aamix_out_paths
[0] =
1644 check_aamix_out_path(codec
, spec
->out_paths
[0]);
1645 if (cfg
->line_out_type
!= AUTO_PIN_HP_OUT
)
1646 spec
->aamix_out_paths
[1] =
1647 check_aamix_out_path(codec
, spec
->hp_paths
[0]);
1648 if (cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
)
1649 spec
->aamix_out_paths
[2] =
1650 check_aamix_out_path(codec
, spec
->speaker_paths
[0]);
1653 if (!spec
->no_multi_io
&&
1654 cfg
->hp_outs
&& cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
)
1655 if (count_multiio_pins(codec
, cfg
->hp_pins
[0]) >= 2)
1656 spec
->multi_ios
= 1; /* give badness */
1658 /* re-count num_dacs and squash invalid entries */
1659 spec
->multiout
.num_dacs
= 0;
1660 for (i
= 0; i
< cfg
->line_outs
; i
++) {
1661 if (spec
->private_dac_nids
[i
])
1662 spec
->multiout
.num_dacs
++;
1664 memmove(spec
->private_dac_nids
+ i
,
1665 spec
->private_dac_nids
+ i
+ 1,
1666 sizeof(hda_nid_t
) * (cfg
->line_outs
- i
- 1));
1667 spec
->private_dac_nids
[cfg
->line_outs
- 1] = 0;
1671 spec
->ext_channel_count
= spec
->min_channel_count
=
1672 spec
->multiout
.num_dacs
* 2;
1674 if (spec
->multi_ios
== 2) {
1675 for (i
= 0; i
< 2; i
++)
1676 spec
->private_dac_nids
[spec
->multiout
.num_dacs
++] =
1677 spec
->multi_io
[i
].dac
;
1678 } else if (spec
->multi_ios
) {
1679 spec
->multi_ios
= 0;
1680 badness
+= BAD_MULTI_IO
;
1683 if (spec
->indep_hp
&& !indep_hp_possible(codec
))
1684 badness
+= BAD_NO_INDEP_HP
;
1686 /* re-fill the shared DAC for speaker / headphone */
1687 if (cfg
->line_out_type
!= AUTO_PIN_HP_OUT
)
1688 refill_shared_dacs(codec
, cfg
->hp_outs
,
1689 spec
->multiout
.hp_out_nid
,
1691 if (cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
)
1692 refill_shared_dacs(codec
, cfg
->speaker_outs
,
1693 spec
->multiout
.extra_out_nid
,
1694 spec
->speaker_paths
);
1699 #define DEBUG_BADNESS
1701 #ifdef DEBUG_BADNESS
1702 #define debug_badness snd_printdd
1704 #define debug_badness(...)
1707 #ifdef DEBUG_BADNESS
1708 static inline void print_nid_path_idx(struct hda_codec
*codec
,
1709 const char *pfx
, int idx
)
1711 struct nid_path
*path
;
1713 path
= snd_hda_get_path_from_idx(codec
, idx
);
1715 print_nid_path(pfx
, path
);
1718 static void debug_show_configs(struct hda_codec
*codec
,
1719 struct auto_pin_cfg
*cfg
)
1721 struct hda_gen_spec
*spec
= codec
->spec
;
1722 static const char * const lo_type
[3] = { "LO", "SP", "HP" };
1725 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x (type %s)\n",
1726 cfg
->line_out_pins
[0], cfg
->line_out_pins
[1],
1727 cfg
->line_out_pins
[2], cfg
->line_out_pins
[3],
1728 spec
->multiout
.dac_nids
[0],
1729 spec
->multiout
.dac_nids
[1],
1730 spec
->multiout
.dac_nids
[2],
1731 spec
->multiout
.dac_nids
[3],
1732 lo_type
[cfg
->line_out_type
]);
1733 for (i
= 0; i
< cfg
->line_outs
; i
++)
1734 print_nid_path_idx(codec
, " out", spec
->out_paths
[i
]);
1735 if (spec
->multi_ios
> 0)
1736 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
1738 spec
->multi_io
[0].pin
, spec
->multi_io
[1].pin
,
1739 spec
->multi_io
[0].dac
, spec
->multi_io
[1].dac
);
1740 for (i
= 0; i
< spec
->multi_ios
; i
++)
1741 print_nid_path_idx(codec
, " mio",
1742 spec
->out_paths
[cfg
->line_outs
+ i
]);
1744 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
1745 cfg
->hp_pins
[0], cfg
->hp_pins
[1],
1746 cfg
->hp_pins
[2], cfg
->hp_pins
[3],
1747 spec
->multiout
.hp_out_nid
[0],
1748 spec
->multiout
.hp_out_nid
[1],
1749 spec
->multiout
.hp_out_nid
[2],
1750 spec
->multiout
.hp_out_nid
[3]);
1751 for (i
= 0; i
< cfg
->hp_outs
; i
++)
1752 print_nid_path_idx(codec
, " hp ", spec
->hp_paths
[i
]);
1753 if (cfg
->speaker_outs
)
1754 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
1755 cfg
->speaker_pins
[0], cfg
->speaker_pins
[1],
1756 cfg
->speaker_pins
[2], cfg
->speaker_pins
[3],
1757 spec
->multiout
.extra_out_nid
[0],
1758 spec
->multiout
.extra_out_nid
[1],
1759 spec
->multiout
.extra_out_nid
[2],
1760 spec
->multiout
.extra_out_nid
[3]);
1761 for (i
= 0; i
< cfg
->speaker_outs
; i
++)
1762 print_nid_path_idx(codec
, " spk", spec
->speaker_paths
[i
]);
1763 for (i
= 0; i
< 3; i
++)
1764 print_nid_path_idx(codec
, " mix", spec
->aamix_out_paths
[i
]);
1767 #define debug_show_configs(codec, cfg) /* NOP */
1770 /* find all available DACs of the codec */
1771 static void fill_all_dac_nids(struct hda_codec
*codec
)
1773 struct hda_gen_spec
*spec
= codec
->spec
;
1775 hda_nid_t nid
= codec
->start_nid
;
1777 spec
->num_all_dacs
= 0;
1778 memset(spec
->all_dacs
, 0, sizeof(spec
->all_dacs
));
1779 for (i
= 0; i
< codec
->num_nodes
; i
++, nid
++) {
1780 if (get_wcaps_type(get_wcaps(codec
, nid
)) != AC_WID_AUD_OUT
)
1782 if (spec
->num_all_dacs
>= ARRAY_SIZE(spec
->all_dacs
)) {
1783 snd_printk(KERN_ERR
"hda: Too many DACs!\n");
1786 spec
->all_dacs
[spec
->num_all_dacs
++] = nid
;
1790 static int parse_output_paths(struct hda_codec
*codec
)
1792 struct hda_gen_spec
*spec
= codec
->spec
;
1793 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1794 struct auto_pin_cfg
*best_cfg
;
1796 int best_badness
= INT_MAX
;
1798 bool fill_hardwired
= true, fill_mio_first
= true;
1799 bool best_wired
= true, best_mio
= true;
1800 bool hp_spk_swapped
= false;
1802 best_cfg
= kmalloc(sizeof(*best_cfg
), GFP_KERNEL
);
1808 badness
= fill_and_eval_dacs(codec
, fill_hardwired
,
1814 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
1815 cfg
->line_out_type
, fill_hardwired
, fill_mio_first
,
1817 debug_show_configs(codec
, cfg
);
1818 if (badness
< best_badness
) {
1819 best_badness
= badness
;
1821 best_wired
= fill_hardwired
;
1822 best_mio
= fill_mio_first
;
1826 fill_mio_first
= !fill_mio_first
;
1827 if (!fill_mio_first
)
1829 fill_hardwired
= !fill_hardwired
;
1830 if (!fill_hardwired
)
1834 hp_spk_swapped
= true;
1835 if (cfg
->speaker_outs
> 0 &&
1836 cfg
->line_out_type
== AUTO_PIN_HP_OUT
) {
1837 cfg
->hp_outs
= cfg
->line_outs
;
1838 memcpy(cfg
->hp_pins
, cfg
->line_out_pins
,
1839 sizeof(cfg
->hp_pins
));
1840 cfg
->line_outs
= cfg
->speaker_outs
;
1841 memcpy(cfg
->line_out_pins
, cfg
->speaker_pins
,
1842 sizeof(cfg
->speaker_pins
));
1843 cfg
->speaker_outs
= 0;
1844 memset(cfg
->speaker_pins
, 0, sizeof(cfg
->speaker_pins
));
1845 cfg
->line_out_type
= AUTO_PIN_SPEAKER_OUT
;
1846 fill_hardwired
= true;
1849 if (cfg
->hp_outs
> 0 &&
1850 cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
) {
1851 cfg
->speaker_outs
= cfg
->line_outs
;
1852 memcpy(cfg
->speaker_pins
, cfg
->line_out_pins
,
1853 sizeof(cfg
->speaker_pins
));
1854 cfg
->line_outs
= cfg
->hp_outs
;
1855 memcpy(cfg
->line_out_pins
, cfg
->hp_pins
,
1856 sizeof(cfg
->hp_pins
));
1858 memset(cfg
->hp_pins
, 0, sizeof(cfg
->hp_pins
));
1859 cfg
->line_out_type
= AUTO_PIN_HP_OUT
;
1860 fill_hardwired
= true;
1867 debug_badness("==> restoring best_cfg\n");
1869 fill_and_eval_dacs(codec
, best_wired
, best_mio
);
1871 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
1872 cfg
->line_out_type
, best_wired
, best_mio
);
1873 debug_show_configs(codec
, cfg
);
1875 if (cfg
->line_out_pins
[0]) {
1876 struct nid_path
*path
;
1877 path
= snd_hda_get_path_from_idx(codec
, spec
->out_paths
[0]);
1879 spec
->vmaster_nid
= look_for_out_vol_nid(codec
, path
);
1880 if (spec
->vmaster_nid
)
1881 snd_hda_set_vmaster_tlv(codec
, spec
->vmaster_nid
,
1882 HDA_OUTPUT
, spec
->vmaster_tlv
);
1885 /* set initial pinctl targets */
1886 if (spec
->prefer_hp_amp
|| cfg
->line_out_type
== AUTO_PIN_HP_OUT
)
1890 set_pin_targets(codec
, cfg
->line_outs
, cfg
->line_out_pins
, val
);
1891 if (cfg
->line_out_type
!= AUTO_PIN_HP_OUT
)
1892 set_pin_targets(codec
, cfg
->hp_outs
, cfg
->hp_pins
, PIN_HP
);
1893 if (cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
) {
1894 val
= spec
->prefer_hp_amp
? PIN_HP
: PIN_OUT
;
1895 set_pin_targets(codec
, cfg
->speaker_outs
,
1896 cfg
->speaker_pins
, val
);
1899 /* clear indep_hp flag if not available */
1900 if (spec
->indep_hp
&& !indep_hp_possible(codec
))
1907 /* add playback controls from the parsed DAC table */
1908 static int create_multi_out_ctls(struct hda_codec
*codec
,
1909 const struct auto_pin_cfg
*cfg
)
1911 struct hda_gen_spec
*spec
= codec
->spec
;
1912 int i
, err
, noutputs
;
1914 noutputs
= cfg
->line_outs
;
1915 if (spec
->multi_ios
> 0 && cfg
->line_outs
< 3)
1916 noutputs
+= spec
->multi_ios
;
1918 for (i
= 0; i
< noutputs
; i
++) {
1921 struct nid_path
*path
;
1923 path
= snd_hda_get_path_from_idx(codec
, spec
->out_paths
[i
]);
1927 name
= get_line_out_pfx(codec
, i
, &index
, NID_PATH_VOL_CTL
);
1928 if (!name
|| !strcmp(name
, "CLFE")) {
1930 err
= add_vol_ctl(codec
, "Center", 0, 1, path
);
1933 err
= add_vol_ctl(codec
, "LFE", 0, 2, path
);
1937 err
= add_stereo_vol(codec
, name
, index
, path
);
1942 name
= get_line_out_pfx(codec
, i
, &index
, NID_PATH_MUTE_CTL
);
1943 if (!name
|| !strcmp(name
, "CLFE")) {
1944 err
= add_sw_ctl(codec
, "Center", 0, 1, path
);
1947 err
= add_sw_ctl(codec
, "LFE", 0, 2, path
);
1951 err
= add_stereo_sw(codec
, name
, index
, path
);
1959 static int create_extra_out(struct hda_codec
*codec
, int path_idx
,
1960 const char *pfx
, int cidx
)
1962 struct nid_path
*path
;
1965 path
= snd_hda_get_path_from_idx(codec
, path_idx
);
1968 err
= add_stereo_vol(codec
, pfx
, cidx
, path
);
1971 err
= add_stereo_sw(codec
, pfx
, cidx
, path
);
1977 /* add playback controls for speaker and HP outputs */
1978 static int create_extra_outs(struct hda_codec
*codec
, int num_pins
,
1979 const int *paths
, const char *pfx
)
1983 for (i
= 0; i
< num_pins
; i
++) {
1985 char tmp
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
1988 if (num_pins
== 2 && i
== 1 && !strcmp(pfx
, "Speaker"))
1989 name
= "Bass Speaker";
1990 else if (num_pins
>= 3) {
1991 snprintf(tmp
, sizeof(tmp
), "%s %s",
1992 pfx
, channel_name
[i
]);
1998 err
= create_extra_out(codec
, paths
[i
], name
, idx
);
2005 static int create_hp_out_ctls(struct hda_codec
*codec
)
2007 struct hda_gen_spec
*spec
= codec
->spec
;
2008 return create_extra_outs(codec
, spec
->autocfg
.hp_outs
,
2013 static int create_speaker_out_ctls(struct hda_codec
*codec
)
2015 struct hda_gen_spec
*spec
= codec
->spec
;
2016 return create_extra_outs(codec
, spec
->autocfg
.speaker_outs
,
2017 spec
->speaker_paths
,
2022 * independent HP controls
2025 static void call_hp_automute(struct hda_codec
*codec
, struct hda_jack_tbl
*jack
);
2026 static int indep_hp_info(struct snd_kcontrol
*kcontrol
,
2027 struct snd_ctl_elem_info
*uinfo
)
2029 return snd_hda_enum_bool_helper_info(kcontrol
, uinfo
);
2032 static int indep_hp_get(struct snd_kcontrol
*kcontrol
,
2033 struct snd_ctl_elem_value
*ucontrol
)
2035 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2036 struct hda_gen_spec
*spec
= codec
->spec
;
2037 ucontrol
->value
.enumerated
.item
[0] = spec
->indep_hp_enabled
;
2041 static void update_aamix_paths(struct hda_codec
*codec
, bool do_mix
,
2042 int nomix_path_idx
, int mix_path_idx
,
2045 static int indep_hp_put(struct snd_kcontrol
*kcontrol
,
2046 struct snd_ctl_elem_value
*ucontrol
)
2048 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2049 struct hda_gen_spec
*spec
= codec
->spec
;
2050 unsigned int select
= ucontrol
->value
.enumerated
.item
[0];
2053 mutex_lock(&spec
->pcm_mutex
);
2054 if (spec
->active_streams
) {
2059 if (spec
->indep_hp_enabled
!= select
) {
2061 if (spec
->autocfg
.line_out_type
== AUTO_PIN_HP_OUT
)
2062 dacp
= &spec
->private_dac_nids
[0];
2064 dacp
= &spec
->multiout
.hp_out_nid
[0];
2066 /* update HP aamix paths in case it conflicts with indep HP */
2067 if (spec
->have_aamix_ctl
) {
2068 if (spec
->autocfg
.line_out_type
== AUTO_PIN_HP_OUT
)
2069 update_aamix_paths(codec
, spec
->aamix_mode
,
2071 spec
->aamix_out_paths
[0],
2072 spec
->autocfg
.line_out_type
);
2074 update_aamix_paths(codec
, spec
->aamix_mode
,
2076 spec
->aamix_out_paths
[1],
2080 spec
->indep_hp_enabled
= select
;
2081 if (spec
->indep_hp_enabled
)
2084 *dacp
= spec
->alt_dac_nid
;
2086 call_hp_automute(codec
, NULL
);
2090 mutex_unlock(&spec
->pcm_mutex
);
2094 static const struct snd_kcontrol_new indep_hp_ctl
= {
2095 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2096 .name
= "Independent HP",
2097 .info
= indep_hp_info
,
2098 .get
= indep_hp_get
,
2099 .put
= indep_hp_put
,
2103 static int create_indep_hp_ctls(struct hda_codec
*codec
)
2105 struct hda_gen_spec
*spec
= codec
->spec
;
2108 if (!spec
->indep_hp
)
2110 if (spec
->autocfg
.line_out_type
== AUTO_PIN_HP_OUT
)
2111 dac
= spec
->multiout
.dac_nids
[0];
2113 dac
= spec
->multiout
.hp_out_nid
[0];
2119 spec
->indep_hp_enabled
= false;
2120 spec
->alt_dac_nid
= dac
;
2121 if (!snd_hda_gen_add_kctl(spec
, NULL
, &indep_hp_ctl
))
2127 * channel mode enum control
2130 static int ch_mode_info(struct snd_kcontrol
*kcontrol
,
2131 struct snd_ctl_elem_info
*uinfo
)
2133 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2134 struct hda_gen_spec
*spec
= codec
->spec
;
2137 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2139 uinfo
->value
.enumerated
.items
= spec
->multi_ios
+ 1;
2140 if (uinfo
->value
.enumerated
.item
> spec
->multi_ios
)
2141 uinfo
->value
.enumerated
.item
= spec
->multi_ios
;
2142 chs
= uinfo
->value
.enumerated
.item
* 2 + spec
->min_channel_count
;
2143 sprintf(uinfo
->value
.enumerated
.name
, "%dch", chs
);
2147 static int ch_mode_get(struct snd_kcontrol
*kcontrol
,
2148 struct snd_ctl_elem_value
*ucontrol
)
2150 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2151 struct hda_gen_spec
*spec
= codec
->spec
;
2152 ucontrol
->value
.enumerated
.item
[0] =
2153 (spec
->ext_channel_count
- spec
->min_channel_count
) / 2;
2157 static inline struct nid_path
*
2158 get_multiio_path(struct hda_codec
*codec
, int idx
)
2160 struct hda_gen_spec
*spec
= codec
->spec
;
2161 return snd_hda_get_path_from_idx(codec
,
2162 spec
->out_paths
[spec
->autocfg
.line_outs
+ idx
]);
2165 static void update_automute_all(struct hda_codec
*codec
);
2167 /* Default value to be passed as aamix argument for snd_hda_activate_path();
2168 * used for output paths
2170 static bool aamix_default(struct hda_gen_spec
*spec
)
2172 return !spec
->have_aamix_ctl
|| spec
->aamix_mode
;
2175 static int set_multi_io(struct hda_codec
*codec
, int idx
, bool output
)
2177 struct hda_gen_spec
*spec
= codec
->spec
;
2178 hda_nid_t nid
= spec
->multi_io
[idx
].pin
;
2179 struct nid_path
*path
;
2181 path
= get_multiio_path(codec
, idx
);
2185 if (path
->active
== output
)
2189 set_pin_target(codec
, nid
, PIN_OUT
, true);
2190 snd_hda_activate_path(codec
, path
, true, aamix_default(spec
));
2191 set_pin_eapd(codec
, nid
, true);
2193 set_pin_eapd(codec
, nid
, false);
2194 snd_hda_activate_path(codec
, path
, false, aamix_default(spec
));
2195 set_pin_target(codec
, nid
, spec
->multi_io
[idx
].ctl_in
, true);
2196 path_power_down_sync(codec
, path
);
2199 /* update jack retasking in case it modifies any of them */
2200 update_automute_all(codec
);
2205 static int ch_mode_put(struct snd_kcontrol
*kcontrol
,
2206 struct snd_ctl_elem_value
*ucontrol
)
2208 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2209 struct hda_gen_spec
*spec
= codec
->spec
;
2212 ch
= ucontrol
->value
.enumerated
.item
[0];
2213 if (ch
< 0 || ch
> spec
->multi_ios
)
2215 if (ch
== (spec
->ext_channel_count
- spec
->min_channel_count
) / 2)
2217 spec
->ext_channel_count
= ch
* 2 + spec
->min_channel_count
;
2218 for (i
= 0; i
< spec
->multi_ios
; i
++)
2219 set_multi_io(codec
, i
, i
< ch
);
2220 spec
->multiout
.max_channels
= max(spec
->ext_channel_count
,
2221 spec
->const_channel_count
);
2222 if (spec
->need_dac_fix
)
2223 spec
->multiout
.num_dacs
= spec
->multiout
.max_channels
/ 2;
2227 static const struct snd_kcontrol_new channel_mode_enum
= {
2228 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2229 .name
= "Channel Mode",
2230 .info
= ch_mode_info
,
2235 static int create_multi_channel_mode(struct hda_codec
*codec
)
2237 struct hda_gen_spec
*spec
= codec
->spec
;
2239 if (spec
->multi_ios
> 0) {
2240 if (!snd_hda_gen_add_kctl(spec
, NULL
, &channel_mode_enum
))
2247 * aamix loopback enable/disable switch
2250 #define loopback_mixing_info indep_hp_info
2252 static int loopback_mixing_get(struct snd_kcontrol
*kcontrol
,
2253 struct snd_ctl_elem_value
*ucontrol
)
2255 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2256 struct hda_gen_spec
*spec
= codec
->spec
;
2257 ucontrol
->value
.enumerated
.item
[0] = spec
->aamix_mode
;
2261 static void update_aamix_paths(struct hda_codec
*codec
, bool do_mix
,
2262 int nomix_path_idx
, int mix_path_idx
,
2265 struct hda_gen_spec
*spec
= codec
->spec
;
2266 struct nid_path
*nomix_path
, *mix_path
;
2268 nomix_path
= snd_hda_get_path_from_idx(codec
, nomix_path_idx
);
2269 mix_path
= snd_hda_get_path_from_idx(codec
, mix_path_idx
);
2270 if (!nomix_path
|| !mix_path
)
2273 /* if HP aamix path is driven from a different DAC and the
2274 * independent HP mode is ON, can't turn on aamix path
2276 if (out_type
== AUTO_PIN_HP_OUT
&& spec
->indep_hp_enabled
&&
2277 mix_path
->path
[0] != spec
->alt_dac_nid
)
2281 snd_hda_activate_path(codec
, nomix_path
, false, true);
2282 snd_hda_activate_path(codec
, mix_path
, true, true);
2283 path_power_down_sync(codec
, nomix_path
);
2285 snd_hda_activate_path(codec
, mix_path
, false, false);
2286 snd_hda_activate_path(codec
, nomix_path
, true, false);
2287 path_power_down_sync(codec
, mix_path
);
2291 static int loopback_mixing_put(struct snd_kcontrol
*kcontrol
,
2292 struct snd_ctl_elem_value
*ucontrol
)
2294 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2295 struct hda_gen_spec
*spec
= codec
->spec
;
2296 unsigned int val
= ucontrol
->value
.enumerated
.item
[0];
2298 if (val
== spec
->aamix_mode
)
2300 spec
->aamix_mode
= val
;
2301 update_aamix_paths(codec
, val
, spec
->out_paths
[0],
2302 spec
->aamix_out_paths
[0],
2303 spec
->autocfg
.line_out_type
);
2304 update_aamix_paths(codec
, val
, spec
->hp_paths
[0],
2305 spec
->aamix_out_paths
[1],
2307 update_aamix_paths(codec
, val
, spec
->speaker_paths
[0],
2308 spec
->aamix_out_paths
[2],
2309 AUTO_PIN_SPEAKER_OUT
);
2313 static const struct snd_kcontrol_new loopback_mixing_enum
= {
2314 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2315 .name
= "Loopback Mixing",
2316 .info
= loopback_mixing_info
,
2317 .get
= loopback_mixing_get
,
2318 .put
= loopback_mixing_put
,
2321 static int create_loopback_mixing_ctl(struct hda_codec
*codec
)
2323 struct hda_gen_spec
*spec
= codec
->spec
;
2325 if (!spec
->mixer_nid
)
2327 if (!(spec
->aamix_out_paths
[0] || spec
->aamix_out_paths
[1] ||
2328 spec
->aamix_out_paths
[2]))
2330 if (!snd_hda_gen_add_kctl(spec
, NULL
, &loopback_mixing_enum
))
2332 spec
->have_aamix_ctl
= 1;
2337 * shared headphone/mic handling
2340 static void call_update_outputs(struct hda_codec
*codec
);
2342 /* for shared I/O, change the pin-control accordingly */
2343 static void update_hp_mic(struct hda_codec
*codec
, int adc_mux
, bool force
)
2345 struct hda_gen_spec
*spec
= codec
->spec
;
2350 pin
= spec
->hp_mic_pin
;
2351 as_mic
= spec
->cur_mux
[adc_mux
] == spec
->hp_mic_mux_idx
;
2354 val
= snd_hda_codec_get_pin_target(codec
, pin
);
2364 val
= snd_hda_get_default_vref(codec
, pin
);
2365 /* if the HP pin doesn't support VREF and the codec driver gives an
2366 * alternative pin, set up the VREF on that pin instead
2368 if (val
== AC_PINCTL_VREF_HIZ
&& spec
->shared_mic_vref_pin
) {
2369 const hda_nid_t vref_pin
= spec
->shared_mic_vref_pin
;
2370 unsigned int vref_val
= snd_hda_get_default_vref(codec
, vref_pin
);
2371 if (vref_val
!= AC_PINCTL_VREF_HIZ
)
2372 snd_hda_set_pin_ctl_cache(codec
, vref_pin
,
2373 PIN_IN
| (as_mic
? vref_val
: 0));
2376 if (!spec
->hp_mic_jack_modes
) {
2381 set_pin_target(codec
, pin
, val
, true);
2382 call_hp_automute(codec
, NULL
);
2386 /* create a shared input with the headphone out */
2387 static int create_hp_mic(struct hda_codec
*codec
)
2389 struct hda_gen_spec
*spec
= codec
->spec
;
2390 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2391 unsigned int defcfg
;
2394 if (!spec
->hp_mic
) {
2395 if (spec
->suppress_hp_mic_detect
)
2397 /* automatic detection: only if no input or a single internal
2398 * input pin is found, try to detect the shared hp/mic
2400 if (cfg
->num_inputs
> 1)
2402 else if (cfg
->num_inputs
== 1) {
2403 defcfg
= snd_hda_codec_get_pincfg(codec
, cfg
->inputs
[0].pin
);
2404 if (snd_hda_get_input_pin_attr(defcfg
) != INPUT_PIN_ATTR_INT
)
2409 spec
->hp_mic
= 0; /* clear once */
2410 if (cfg
->num_inputs
>= AUTO_CFG_MAX_INS
)
2414 if (cfg
->line_out_type
== AUTO_PIN_HP_OUT
&& cfg
->line_outs
> 0)
2415 nid
= cfg
->line_out_pins
[0];
2416 else if (cfg
->hp_outs
> 0)
2417 nid
= cfg
->hp_pins
[0];
2421 if (!(snd_hda_query_pin_caps(codec
, nid
) & AC_PINCAP_IN
))
2422 return 0; /* no input */
2424 cfg
->inputs
[cfg
->num_inputs
].pin
= nid
;
2425 cfg
->inputs
[cfg
->num_inputs
].type
= AUTO_PIN_MIC
;
2426 cfg
->inputs
[cfg
->num_inputs
].is_headphone_mic
= 1;
2429 spec
->hp_mic_pin
= nid
;
2430 /* we can't handle auto-mic together with HP-mic */
2431 spec
->suppress_auto_mic
= 1;
2432 snd_printdd("hda-codec: Enable shared I/O jack on NID 0x%x\n", nid
);
2440 static int create_hp_mic_jack_mode(struct hda_codec
*codec
, hda_nid_t pin
);
2442 static const char * const out_jack_texts
[] = {
2443 "Line Out", "Headphone Out",
2446 static int out_jack_mode_info(struct snd_kcontrol
*kcontrol
,
2447 struct snd_ctl_elem_info
*uinfo
)
2449 return snd_hda_enum_helper_info(kcontrol
, uinfo
, 2, out_jack_texts
);
2452 static int out_jack_mode_get(struct snd_kcontrol
*kcontrol
,
2453 struct snd_ctl_elem_value
*ucontrol
)
2455 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2456 hda_nid_t nid
= kcontrol
->private_value
;
2457 if (snd_hda_codec_get_pin_target(codec
, nid
) == PIN_HP
)
2458 ucontrol
->value
.enumerated
.item
[0] = 1;
2460 ucontrol
->value
.enumerated
.item
[0] = 0;
2464 static int out_jack_mode_put(struct snd_kcontrol
*kcontrol
,
2465 struct snd_ctl_elem_value
*ucontrol
)
2467 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2468 hda_nid_t nid
= kcontrol
->private_value
;
2471 val
= ucontrol
->value
.enumerated
.item
[0] ? PIN_HP
: PIN_OUT
;
2472 if (snd_hda_codec_get_pin_target(codec
, nid
) == val
)
2474 snd_hda_set_pin_ctl_cache(codec
, nid
, val
);
2478 static const struct snd_kcontrol_new out_jack_mode_enum
= {
2479 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2480 .info
= out_jack_mode_info
,
2481 .get
= out_jack_mode_get
,
2482 .put
= out_jack_mode_put
,
2485 static bool find_kctl_name(struct hda_codec
*codec
, const char *name
, int idx
)
2487 struct hda_gen_spec
*spec
= codec
->spec
;
2490 for (i
= 0; i
< spec
->kctls
.used
; i
++) {
2491 struct snd_kcontrol_new
*kctl
= snd_array_elem(&spec
->kctls
, i
);
2492 if (!strcmp(kctl
->name
, name
) && kctl
->index
== idx
)
2498 static void get_jack_mode_name(struct hda_codec
*codec
, hda_nid_t pin
,
2499 char *name
, size_t name_len
)
2501 struct hda_gen_spec
*spec
= codec
->spec
;
2504 snd_hda_get_pin_label(codec
, pin
, &spec
->autocfg
, name
, name_len
, &idx
);
2505 strlcat(name
, " Jack Mode", name_len
);
2507 for (; find_kctl_name(codec
, name
, idx
); idx
++)
2511 static int get_out_jack_num_items(struct hda_codec
*codec
, hda_nid_t pin
)
2513 struct hda_gen_spec
*spec
= codec
->spec
;
2514 if (spec
->add_jack_modes
) {
2515 unsigned int pincap
= snd_hda_query_pin_caps(codec
, pin
);
2516 if ((pincap
& AC_PINCAP_OUT
) && (pincap
& AC_PINCAP_HP_DRV
))
2522 static int create_out_jack_modes(struct hda_codec
*codec
, int num_pins
,
2525 struct hda_gen_spec
*spec
= codec
->spec
;
2528 for (i
= 0; i
< num_pins
; i
++) {
2529 hda_nid_t pin
= pins
[i
];
2530 if (pin
== spec
->hp_mic_pin
)
2532 if (get_out_jack_num_items(codec
, pin
) > 1) {
2533 struct snd_kcontrol_new
*knew
;
2534 char name
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
2535 get_jack_mode_name(codec
, pin
, name
, sizeof(name
));
2536 knew
= snd_hda_gen_add_kctl(spec
, name
,
2537 &out_jack_mode_enum
);
2540 knew
->private_value
= pin
;
2551 /* from AC_PINCTL_VREF_HIZ to AC_PINCTL_VREF_100 */
2554 static const char * const vref_texts
[NUM_VREFS
] = {
2555 "Line In", "Mic 50pc Bias", "Mic 0V Bias",
2556 "", "Mic 80pc Bias", "Mic 100pc Bias"
2559 static unsigned int get_vref_caps(struct hda_codec
*codec
, hda_nid_t pin
)
2561 unsigned int pincap
;
2563 pincap
= snd_hda_query_pin_caps(codec
, pin
);
2564 pincap
= (pincap
& AC_PINCAP_VREF
) >> AC_PINCAP_VREF_SHIFT
;
2565 /* filter out unusual vrefs */
2566 pincap
&= ~(AC_PINCAP_VREF_GRD
| AC_PINCAP_VREF_100
);
2570 /* convert from the enum item index to the vref ctl index (0=HIZ, 1=50%...) */
2571 static int get_vref_idx(unsigned int vref_caps
, unsigned int item_idx
)
2573 unsigned int i
, n
= 0;
2575 for (i
= 0; i
< NUM_VREFS
; i
++) {
2576 if (vref_caps
& (1 << i
)) {
2585 /* convert back from the vref ctl index to the enum item index */
2586 static int cvt_from_vref_idx(unsigned int vref_caps
, unsigned int idx
)
2588 unsigned int i
, n
= 0;
2590 for (i
= 0; i
< NUM_VREFS
; i
++) {
2593 if (vref_caps
& (1 << i
))
2599 static int in_jack_mode_info(struct snd_kcontrol
*kcontrol
,
2600 struct snd_ctl_elem_info
*uinfo
)
2602 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2603 hda_nid_t nid
= kcontrol
->private_value
;
2604 unsigned int vref_caps
= get_vref_caps(codec
, nid
);
2606 snd_hda_enum_helper_info(kcontrol
, uinfo
, hweight32(vref_caps
),
2608 /* set the right text */
2609 strcpy(uinfo
->value
.enumerated
.name
,
2610 vref_texts
[get_vref_idx(vref_caps
, uinfo
->value
.enumerated
.item
)]);
2614 static int in_jack_mode_get(struct snd_kcontrol
*kcontrol
,
2615 struct snd_ctl_elem_value
*ucontrol
)
2617 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2618 hda_nid_t nid
= kcontrol
->private_value
;
2619 unsigned int vref_caps
= get_vref_caps(codec
, nid
);
2622 idx
= snd_hda_codec_get_pin_target(codec
, nid
) & AC_PINCTL_VREFEN
;
2623 ucontrol
->value
.enumerated
.item
[0] = cvt_from_vref_idx(vref_caps
, idx
);
2627 static int in_jack_mode_put(struct snd_kcontrol
*kcontrol
,
2628 struct snd_ctl_elem_value
*ucontrol
)
2630 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2631 hda_nid_t nid
= kcontrol
->private_value
;
2632 unsigned int vref_caps
= get_vref_caps(codec
, nid
);
2633 unsigned int val
, idx
;
2635 val
= snd_hda_codec_get_pin_target(codec
, nid
);
2636 idx
= cvt_from_vref_idx(vref_caps
, val
& AC_PINCTL_VREFEN
);
2637 if (idx
== ucontrol
->value
.enumerated
.item
[0])
2640 val
&= ~AC_PINCTL_VREFEN
;
2641 val
|= get_vref_idx(vref_caps
, ucontrol
->value
.enumerated
.item
[0]);
2642 snd_hda_set_pin_ctl_cache(codec
, nid
, val
);
2646 static const struct snd_kcontrol_new in_jack_mode_enum
= {
2647 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2648 .info
= in_jack_mode_info
,
2649 .get
= in_jack_mode_get
,
2650 .put
= in_jack_mode_put
,
2653 static int get_in_jack_num_items(struct hda_codec
*codec
, hda_nid_t pin
)
2655 struct hda_gen_spec
*spec
= codec
->spec
;
2657 if (spec
->add_jack_modes
)
2658 nitems
= hweight32(get_vref_caps(codec
, pin
));
2659 return nitems
? nitems
: 1;
2662 static int create_in_jack_mode(struct hda_codec
*codec
, hda_nid_t pin
)
2664 struct hda_gen_spec
*spec
= codec
->spec
;
2665 struct snd_kcontrol_new
*knew
;
2666 char name
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
2667 unsigned int defcfg
;
2669 if (pin
== spec
->hp_mic_pin
)
2670 return 0; /* already done in create_out_jack_mode() */
2672 /* no jack mode for fixed pins */
2673 defcfg
= snd_hda_codec_get_pincfg(codec
, pin
);
2674 if (snd_hda_get_input_pin_attr(defcfg
) == INPUT_PIN_ATTR_INT
)
2677 /* no multiple vref caps? */
2678 if (get_in_jack_num_items(codec
, pin
) <= 1)
2681 get_jack_mode_name(codec
, pin
, name
, sizeof(name
));
2682 knew
= snd_hda_gen_add_kctl(spec
, name
, &in_jack_mode_enum
);
2685 knew
->private_value
= pin
;
2690 * HP/mic shared jack mode
2692 static int hp_mic_jack_mode_info(struct snd_kcontrol
*kcontrol
,
2693 struct snd_ctl_elem_info
*uinfo
)
2695 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2696 hda_nid_t nid
= kcontrol
->private_value
;
2697 int out_jacks
= get_out_jack_num_items(codec
, nid
);
2698 int in_jacks
= get_in_jack_num_items(codec
, nid
);
2699 const char *text
= NULL
;
2702 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2704 uinfo
->value
.enumerated
.items
= out_jacks
+ in_jacks
;
2705 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
2706 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
2707 idx
= uinfo
->value
.enumerated
.item
;
2708 if (idx
< out_jacks
) {
2710 text
= out_jack_texts
[idx
];
2712 text
= "Headphone Out";
2716 unsigned int vref_caps
= get_vref_caps(codec
, nid
);
2717 text
= vref_texts
[get_vref_idx(vref_caps
, idx
)];
2722 strcpy(uinfo
->value
.enumerated
.name
, text
);
2726 static int get_cur_hp_mic_jack_mode(struct hda_codec
*codec
, hda_nid_t nid
)
2728 int out_jacks
= get_out_jack_num_items(codec
, nid
);
2729 int in_jacks
= get_in_jack_num_items(codec
, nid
);
2730 unsigned int val
= snd_hda_codec_get_pin_target(codec
, nid
);
2733 if (val
& PIN_OUT
) {
2734 if (out_jacks
> 1 && val
== PIN_HP
)
2736 } else if (val
& PIN_IN
) {
2739 unsigned int vref_caps
= get_vref_caps(codec
, nid
);
2740 val
&= AC_PINCTL_VREFEN
;
2741 idx
+= cvt_from_vref_idx(vref_caps
, val
);
2747 static int hp_mic_jack_mode_get(struct snd_kcontrol
*kcontrol
,
2748 struct snd_ctl_elem_value
*ucontrol
)
2750 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2751 hda_nid_t nid
= kcontrol
->private_value
;
2752 ucontrol
->value
.enumerated
.item
[0] =
2753 get_cur_hp_mic_jack_mode(codec
, nid
);
2757 static int hp_mic_jack_mode_put(struct snd_kcontrol
*kcontrol
,
2758 struct snd_ctl_elem_value
*ucontrol
)
2760 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2761 hda_nid_t nid
= kcontrol
->private_value
;
2762 int out_jacks
= get_out_jack_num_items(codec
, nid
);
2763 int in_jacks
= get_in_jack_num_items(codec
, nid
);
2764 unsigned int val
, oldval
, idx
;
2766 oldval
= get_cur_hp_mic_jack_mode(codec
, nid
);
2767 idx
= ucontrol
->value
.enumerated
.item
[0];
2771 if (idx
< out_jacks
) {
2773 val
= idx
? PIN_HP
: PIN_OUT
;
2779 unsigned int vref_caps
= get_vref_caps(codec
, nid
);
2780 val
= snd_hda_codec_get_pin_target(codec
, nid
);
2781 val
&= ~(AC_PINCTL_VREFEN
| PIN_HP
);
2782 val
|= get_vref_idx(vref_caps
, idx
) | PIN_IN
;
2784 val
= snd_hda_get_default_vref(codec
, nid
) | PIN_IN
;
2786 snd_hda_set_pin_ctl_cache(codec
, nid
, val
);
2787 call_hp_automute(codec
, NULL
);
2792 static const struct snd_kcontrol_new hp_mic_jack_mode_enum
= {
2793 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2794 .info
= hp_mic_jack_mode_info
,
2795 .get
= hp_mic_jack_mode_get
,
2796 .put
= hp_mic_jack_mode_put
,
2799 static int create_hp_mic_jack_mode(struct hda_codec
*codec
, hda_nid_t pin
)
2801 struct hda_gen_spec
*spec
= codec
->spec
;
2802 struct snd_kcontrol_new
*knew
;
2804 knew
= snd_hda_gen_add_kctl(spec
, "Headphone Mic Jack Mode",
2805 &hp_mic_jack_mode_enum
);
2808 knew
->private_value
= pin
;
2809 spec
->hp_mic_jack_modes
= 1;
2817 /* add the powersave loopback-list entry */
2818 static int add_loopback_list(struct hda_gen_spec
*spec
, hda_nid_t mix
, int idx
)
2820 struct hda_amp_list
*list
;
2822 list
= snd_array_new(&spec
->loopback_list
);
2826 list
->dir
= HDA_INPUT
;
2828 spec
->loopback
.amplist
= spec
->loopback_list
.list
;
2832 /* return true if either a volume or a mute amp is found for the given
2833 * aamix path; the amp has to be either in the mixer node or its direct leaf
2835 static bool look_for_mix_leaf_ctls(struct hda_codec
*codec
, hda_nid_t mix_nid
,
2836 hda_nid_t pin
, unsigned int *mix_val
,
2837 unsigned int *mute_val
)
2840 const hda_nid_t
*list
;
2843 idx
= snd_hda_get_conn_index(codec
, mix_nid
, pin
, true);
2847 *mix_val
= *mute_val
= 0;
2848 if (nid_has_volume(codec
, mix_nid
, HDA_INPUT
))
2849 *mix_val
= HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
);
2850 if (nid_has_mute(codec
, mix_nid
, HDA_INPUT
))
2851 *mute_val
= HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
);
2852 if (*mix_val
&& *mute_val
)
2855 /* check leaf node */
2856 num_conns
= snd_hda_get_conn_list(codec
, mix_nid
, &list
);
2857 if (num_conns
< idx
)
2860 if (!*mix_val
&& nid_has_volume(codec
, nid
, HDA_OUTPUT
) &&
2861 !is_ctl_associated(codec
, nid
, HDA_OUTPUT
, 0, NID_PATH_VOL_CTL
))
2862 *mix_val
= HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_OUTPUT
);
2863 if (!*mute_val
&& nid_has_mute(codec
, nid
, HDA_OUTPUT
) &&
2864 !is_ctl_associated(codec
, nid
, HDA_OUTPUT
, 0, NID_PATH_MUTE_CTL
))
2865 *mute_val
= HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_OUTPUT
);
2867 return *mix_val
|| *mute_val
;
2870 /* create input playback/capture controls for the given pin */
2871 static int new_analog_input(struct hda_codec
*codec
, int input_idx
,
2872 hda_nid_t pin
, const char *ctlname
, int ctlidx
,
2875 struct hda_gen_spec
*spec
= codec
->spec
;
2876 struct nid_path
*path
;
2877 unsigned int mix_val
, mute_val
;
2880 if (!look_for_mix_leaf_ctls(codec
, mix_nid
, pin
, &mix_val
, &mute_val
))
2883 path
= snd_hda_add_new_path(codec
, pin
, mix_nid
, 0);
2886 print_nid_path("loopback", path
);
2887 spec
->loopback_paths
[input_idx
] = snd_hda_get_path_idx(codec
, path
);
2889 idx
= path
->idx
[path
->depth
- 1];
2891 err
= __add_pb_vol_ctrl(spec
, HDA_CTL_WIDGET_VOL
, ctlname
, ctlidx
, mix_val
);
2894 path
->ctls
[NID_PATH_VOL_CTL
] = mix_val
;
2898 err
= __add_pb_sw_ctrl(spec
, HDA_CTL_WIDGET_MUTE
, ctlname
, ctlidx
, mute_val
);
2901 path
->ctls
[NID_PATH_MUTE_CTL
] = mute_val
;
2904 path
->active
= true;
2905 err
= add_loopback_list(spec
, mix_nid
, idx
);
2909 if (spec
->mixer_nid
!= spec
->mixer_merge_nid
&&
2910 !spec
->loopback_merge_path
) {
2911 path
= snd_hda_add_new_path(codec
, spec
->mixer_nid
,
2912 spec
->mixer_merge_nid
, 0);
2914 print_nid_path("loopback-merge", path
);
2915 path
->active
= true;
2916 spec
->loopback_merge_path
=
2917 snd_hda_get_path_idx(codec
, path
);
2924 static int is_input_pin(struct hda_codec
*codec
, hda_nid_t nid
)
2926 unsigned int pincap
= snd_hda_query_pin_caps(codec
, nid
);
2927 return (pincap
& AC_PINCAP_IN
) != 0;
2930 /* Parse the codec tree and retrieve ADCs */
2931 static int fill_adc_nids(struct hda_codec
*codec
)
2933 struct hda_gen_spec
*spec
= codec
->spec
;
2935 hda_nid_t
*adc_nids
= spec
->adc_nids
;
2936 int max_nums
= ARRAY_SIZE(spec
->adc_nids
);
2939 nid
= codec
->start_nid
;
2940 for (i
= 0; i
< codec
->num_nodes
; i
++, nid
++) {
2941 unsigned int caps
= get_wcaps(codec
, nid
);
2942 int type
= get_wcaps_type(caps
);
2944 if (type
!= AC_WID_AUD_IN
|| (caps
& AC_WCAP_DIGITAL
))
2946 adc_nids
[nums
] = nid
;
2947 if (++nums
>= max_nums
)
2950 spec
->num_adc_nids
= nums
;
2952 /* copy the detected ADCs to all_adcs[] */
2953 spec
->num_all_adcs
= nums
;
2954 memcpy(spec
->all_adcs
, spec
->adc_nids
, nums
* sizeof(hda_nid_t
));
2959 /* filter out invalid adc_nids that don't give all active input pins;
2960 * if needed, check whether dynamic ADC-switching is available
2962 static int check_dyn_adc_switch(struct hda_codec
*codec
)
2964 struct hda_gen_spec
*spec
= codec
->spec
;
2965 struct hda_input_mux
*imux
= &spec
->input_mux
;
2966 unsigned int ok_bits
;
2971 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
2972 for (i
= 0; i
< imux
->num_items
; i
++) {
2973 if (!spec
->input_paths
[i
][n
])
2976 if (i
>= imux
->num_items
) {
2977 ok_bits
|= (1 << n
);
2983 /* check whether ADC-switch is possible */
2984 for (i
= 0; i
< imux
->num_items
; i
++) {
2985 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
2986 if (spec
->input_paths
[i
][n
]) {
2987 spec
->dyn_adc_idx
[i
] = n
;
2993 snd_printdd("hda-codec: enabling ADC switching\n");
2994 spec
->dyn_adc_switch
= 1;
2995 } else if (nums
!= spec
->num_adc_nids
) {
2996 /* shrink the invalid adcs and input paths */
2998 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
2999 if (!(ok_bits
& (1 << n
)))
3002 spec
->adc_nids
[nums
] = spec
->adc_nids
[n
];
3003 for (i
= 0; i
< imux
->num_items
; i
++) {
3004 invalidate_nid_path(codec
,
3005 spec
->input_paths
[i
][nums
]);
3006 spec
->input_paths
[i
][nums
] =
3007 spec
->input_paths
[i
][n
];
3012 spec
->num_adc_nids
= nums
;
3015 if (imux
->num_items
== 1 ||
3016 (imux
->num_items
== 2 && spec
->hp_mic
)) {
3017 snd_printdd("hda-codec: reducing to a single ADC\n");
3018 spec
->num_adc_nids
= 1; /* reduce to a single ADC */
3021 /* single index for individual volumes ctls */
3022 if (!spec
->dyn_adc_switch
&& spec
->multi_cap_vol
)
3023 spec
->num_adc_nids
= 1;
3028 /* parse capture source paths from the given pin and create imux items */
3029 static int parse_capture_source(struct hda_codec
*codec
, hda_nid_t pin
,
3030 int cfg_idx
, int num_adcs
,
3031 const char *label
, int anchor
)
3033 struct hda_gen_spec
*spec
= codec
->spec
;
3034 struct hda_input_mux
*imux
= &spec
->input_mux
;
3035 int imux_idx
= imux
->num_items
;
3036 bool imux_added
= false;
3039 for (c
= 0; c
< num_adcs
; c
++) {
3040 struct nid_path
*path
;
3041 hda_nid_t adc
= spec
->adc_nids
[c
];
3043 if (!is_reachable_path(codec
, pin
, adc
))
3045 path
= snd_hda_add_new_path(codec
, pin
, adc
, anchor
);
3048 print_nid_path("input", path
);
3049 spec
->input_paths
[imux_idx
][c
] =
3050 snd_hda_get_path_idx(codec
, path
);
3053 if (spec
->hp_mic_pin
== pin
)
3054 spec
->hp_mic_mux_idx
= imux
->num_items
;
3055 spec
->imux_pins
[imux
->num_items
] = pin
;
3056 snd_hda_add_imux_item(imux
, label
, cfg_idx
, NULL
);
3065 * create playback/capture controls for input pins
3068 /* fill the label for each input at first */
3069 static int fill_input_pin_labels(struct hda_codec
*codec
)
3071 struct hda_gen_spec
*spec
= codec
->spec
;
3072 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3075 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
3076 hda_nid_t pin
= cfg
->inputs
[i
].pin
;
3080 if (!is_input_pin(codec
, pin
))
3083 label
= hda_get_autocfg_input_label(codec
, cfg
, i
);
3085 for (j
= i
- 1; j
>= 0; j
--) {
3086 if (spec
->input_labels
[j
] &&
3087 !strcmp(spec
->input_labels
[j
], label
)) {
3088 idx
= spec
->input_label_idxs
[j
] + 1;
3093 spec
->input_labels
[i
] = label
;
3094 spec
->input_label_idxs
[i
] = idx
;
3100 #define CFG_IDX_MIX 99 /* a dummy cfg->input idx for stereo mix */
3102 static int create_input_ctls(struct hda_codec
*codec
)
3104 struct hda_gen_spec
*spec
= codec
->spec
;
3105 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3106 hda_nid_t mixer
= spec
->mixer_nid
;
3111 num_adcs
= fill_adc_nids(codec
);
3115 err
= fill_input_pin_labels(codec
);
3119 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
3122 pin
= cfg
->inputs
[i
].pin
;
3123 if (!is_input_pin(codec
, pin
))
3127 if (cfg
->inputs
[i
].type
== AUTO_PIN_MIC
)
3128 val
|= snd_hda_get_default_vref(codec
, pin
);
3129 if (pin
!= spec
->hp_mic_pin
)
3130 set_pin_target(codec
, pin
, val
, false);
3133 if (is_reachable_path(codec
, pin
, mixer
)) {
3134 err
= new_analog_input(codec
, i
, pin
,
3135 spec
->input_labels
[i
],
3136 spec
->input_label_idxs
[i
],
3143 err
= parse_capture_source(codec
, pin
, i
, num_adcs
,
3144 spec
->input_labels
[i
], -mixer
);
3148 if (spec
->add_jack_modes
) {
3149 err
= create_in_jack_mode(codec
, pin
);
3155 if (mixer
&& spec
->add_stereo_mix_input
) {
3156 err
= parse_capture_source(codec
, mixer
, CFG_IDX_MIX
, num_adcs
,
3170 /* get the input path specified by the given adc and imux indices */
3171 static struct nid_path
*get_input_path(struct hda_codec
*codec
, int adc_idx
, int imux_idx
)
3173 struct hda_gen_spec
*spec
= codec
->spec
;
3174 if (imux_idx
< 0 || imux_idx
>= HDA_MAX_NUM_INPUTS
) {
3178 if (spec
->dyn_adc_switch
)
3179 adc_idx
= spec
->dyn_adc_idx
[imux_idx
];
3180 if (adc_idx
< 0 || adc_idx
>= AUTO_CFG_MAX_INS
) {
3184 return snd_hda_get_path_from_idx(codec
, spec
->input_paths
[imux_idx
][adc_idx
]);
3187 static int mux_select(struct hda_codec
*codec
, unsigned int adc_idx
,
3190 static int mux_enum_info(struct snd_kcontrol
*kcontrol
,
3191 struct snd_ctl_elem_info
*uinfo
)
3193 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3194 struct hda_gen_spec
*spec
= codec
->spec
;
3195 return snd_hda_input_mux_info(&spec
->input_mux
, uinfo
);
3198 static int mux_enum_get(struct snd_kcontrol
*kcontrol
,
3199 struct snd_ctl_elem_value
*ucontrol
)
3201 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3202 struct hda_gen_spec
*spec
= codec
->spec
;
3203 /* the ctls are created at once with multiple counts */
3204 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
3206 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_mux
[adc_idx
];
3210 static int mux_enum_put(struct snd_kcontrol
*kcontrol
,
3211 struct snd_ctl_elem_value
*ucontrol
)
3213 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3214 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
3215 return mux_select(codec
, adc_idx
,
3216 ucontrol
->value
.enumerated
.item
[0]);
3219 static const struct snd_kcontrol_new cap_src_temp
= {
3220 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3221 .name
= "Input Source",
3222 .info
= mux_enum_info
,
3223 .get
= mux_enum_get
,
3224 .put
= mux_enum_put
,
3228 * capture volume and capture switch ctls
3231 typedef int (*put_call_t
)(struct snd_kcontrol
*kcontrol
,
3232 struct snd_ctl_elem_value
*ucontrol
);
3234 /* call the given amp update function for all amps in the imux list at once */
3235 static int cap_put_caller(struct snd_kcontrol
*kcontrol
,
3236 struct snd_ctl_elem_value
*ucontrol
,
3237 put_call_t func
, int type
)
3239 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3240 struct hda_gen_spec
*spec
= codec
->spec
;
3241 const struct hda_input_mux
*imux
;
3242 struct nid_path
*path
;
3243 int i
, adc_idx
, err
= 0;
3245 imux
= &spec
->input_mux
;
3246 adc_idx
= kcontrol
->id
.index
;
3247 mutex_lock(&codec
->control_mutex
);
3248 /* we use the cache-only update at first since multiple input paths
3249 * may shared the same amp; by updating only caches, the redundant
3250 * writes to hardware can be reduced.
3252 codec
->cached_write
= 1;
3253 for (i
= 0; i
< imux
->num_items
; i
++) {
3254 path
= get_input_path(codec
, adc_idx
, i
);
3255 if (!path
|| !path
->ctls
[type
])
3257 kcontrol
->private_value
= path
->ctls
[type
];
3258 err
= func(kcontrol
, ucontrol
);
3263 codec
->cached_write
= 0;
3264 mutex_unlock(&codec
->control_mutex
);
3265 snd_hda_codec_flush_cache(codec
); /* flush the updates */
3266 if (err
>= 0 && spec
->cap_sync_hook
)
3267 spec
->cap_sync_hook(codec
, kcontrol
, ucontrol
);
3271 /* capture volume ctl callbacks */
3272 #define cap_vol_info snd_hda_mixer_amp_volume_info
3273 #define cap_vol_get snd_hda_mixer_amp_volume_get
3274 #define cap_vol_tlv snd_hda_mixer_amp_tlv
3276 static int cap_vol_put(struct snd_kcontrol
*kcontrol
,
3277 struct snd_ctl_elem_value
*ucontrol
)
3279 return cap_put_caller(kcontrol
, ucontrol
,
3280 snd_hda_mixer_amp_volume_put
,
3284 static const struct snd_kcontrol_new cap_vol_temp
= {
3285 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3286 .name
= "Capture Volume",
3287 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
3288 SNDRV_CTL_ELEM_ACCESS_TLV_READ
|
3289 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK
),
3290 .info
= cap_vol_info
,
3293 .tlv
= { .c
= cap_vol_tlv
},
3296 /* capture switch ctl callbacks */
3297 #define cap_sw_info snd_ctl_boolean_stereo_info
3298 #define cap_sw_get snd_hda_mixer_amp_switch_get
3300 static int cap_sw_put(struct snd_kcontrol
*kcontrol
,
3301 struct snd_ctl_elem_value
*ucontrol
)
3303 return cap_put_caller(kcontrol
, ucontrol
,
3304 snd_hda_mixer_amp_switch_put
,
3308 static const struct snd_kcontrol_new cap_sw_temp
= {
3309 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3310 .name
= "Capture Switch",
3311 .info
= cap_sw_info
,
3316 static int parse_capvol_in_path(struct hda_codec
*codec
, struct nid_path
*path
)
3321 path
->ctls
[NID_PATH_VOL_CTL
] = path
->ctls
[NID_PATH_MUTE_CTL
] = 0;
3322 for (depth
= 0; depth
< 3; depth
++) {
3323 if (depth
>= path
->depth
)
3325 i
= path
->depth
- depth
- 1;
3326 nid
= path
->path
[i
];
3327 if (!path
->ctls
[NID_PATH_VOL_CTL
]) {
3328 if (nid_has_volume(codec
, nid
, HDA_OUTPUT
))
3329 path
->ctls
[NID_PATH_VOL_CTL
] =
3330 HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_OUTPUT
);
3331 else if (nid_has_volume(codec
, nid
, HDA_INPUT
)) {
3332 int idx
= path
->idx
[i
];
3333 if (!depth
&& codec
->single_adc_amp
)
3335 path
->ctls
[NID_PATH_VOL_CTL
] =
3336 HDA_COMPOSE_AMP_VAL(nid
, 3, idx
, HDA_INPUT
);
3339 if (!path
->ctls
[NID_PATH_MUTE_CTL
]) {
3340 if (nid_has_mute(codec
, nid
, HDA_OUTPUT
))
3341 path
->ctls
[NID_PATH_MUTE_CTL
] =
3342 HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_OUTPUT
);
3343 else if (nid_has_mute(codec
, nid
, HDA_INPUT
)) {
3344 int idx
= path
->idx
[i
];
3345 if (!depth
&& codec
->single_adc_amp
)
3347 path
->ctls
[NID_PATH_MUTE_CTL
] =
3348 HDA_COMPOSE_AMP_VAL(nid
, 3, idx
, HDA_INPUT
);
3355 static bool is_inv_dmic_pin(struct hda_codec
*codec
, hda_nid_t nid
)
3357 struct hda_gen_spec
*spec
= codec
->spec
;
3358 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3362 if (!spec
->inv_dmic_split
)
3364 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
3365 if (cfg
->inputs
[i
].pin
!= nid
)
3367 if (cfg
->inputs
[i
].type
!= AUTO_PIN_MIC
)
3369 val
= snd_hda_codec_get_pincfg(codec
, nid
);
3370 return snd_hda_get_input_pin_attr(val
) == INPUT_PIN_ATTR_INT
;
3375 /* capture switch put callback for a single control with hook call */
3376 static int cap_single_sw_put(struct snd_kcontrol
*kcontrol
,
3377 struct snd_ctl_elem_value
*ucontrol
)
3379 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3380 struct hda_gen_spec
*spec
= codec
->spec
;
3383 ret
= snd_hda_mixer_amp_switch_put(kcontrol
, ucontrol
);
3387 if (spec
->cap_sync_hook
)
3388 spec
->cap_sync_hook(codec
, kcontrol
, ucontrol
);
3393 static int add_single_cap_ctl(struct hda_codec
*codec
, const char *label
,
3394 int idx
, bool is_switch
, unsigned int ctl
,
3397 struct hda_gen_spec
*spec
= codec
->spec
;
3398 char tmpname
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
3399 int type
= is_switch
? HDA_CTL_WIDGET_MUTE
: HDA_CTL_WIDGET_VOL
;
3400 const char *sfx
= is_switch
? "Switch" : "Volume";
3401 unsigned int chs
= inv_dmic
? 1 : 3;
3402 struct snd_kcontrol_new
*knew
;
3408 snprintf(tmpname
, sizeof(tmpname
),
3409 "%s Capture %s", label
, sfx
);
3411 snprintf(tmpname
, sizeof(tmpname
),
3413 knew
= add_control(spec
, type
, tmpname
, idx
,
3414 amp_val_replace_channels(ctl
, chs
));
3418 knew
->put
= cap_single_sw_put
;
3422 /* Make independent right kcontrol */
3424 snprintf(tmpname
, sizeof(tmpname
),
3425 "Inverted %s Capture %s", label
, sfx
);
3427 snprintf(tmpname
, sizeof(tmpname
),
3428 "Inverted Capture %s", sfx
);
3429 knew
= add_control(spec
, type
, tmpname
, idx
,
3430 amp_val_replace_channels(ctl
, 2));
3434 knew
->put
= cap_single_sw_put
;
3438 /* create single (and simple) capture volume and switch controls */
3439 static int create_single_cap_vol_ctl(struct hda_codec
*codec
, int idx
,
3440 unsigned int vol_ctl
, unsigned int sw_ctl
,
3444 err
= add_single_cap_ctl(codec
, NULL
, idx
, false, vol_ctl
, inv_dmic
);
3447 err
= add_single_cap_ctl(codec
, NULL
, idx
, true, sw_ctl
, inv_dmic
);
3453 /* create bound capture volume and switch controls */
3454 static int create_bind_cap_vol_ctl(struct hda_codec
*codec
, int idx
,
3455 unsigned int vol_ctl
, unsigned int sw_ctl
)
3457 struct hda_gen_spec
*spec
= codec
->spec
;
3458 struct snd_kcontrol_new
*knew
;
3461 knew
= snd_hda_gen_add_kctl(spec
, NULL
, &cap_vol_temp
);
3465 knew
->private_value
= vol_ctl
;
3466 knew
->subdevice
= HDA_SUBDEV_AMP_FLAG
;
3469 knew
= snd_hda_gen_add_kctl(spec
, NULL
, &cap_sw_temp
);
3473 knew
->private_value
= sw_ctl
;
3474 knew
->subdevice
= HDA_SUBDEV_AMP_FLAG
;
3479 /* return the vol ctl when used first in the imux list */
3480 static unsigned int get_first_cap_ctl(struct hda_codec
*codec
, int idx
, int type
)
3482 struct nid_path
*path
;
3486 path
= get_input_path(codec
, 0, idx
);
3489 ctl
= path
->ctls
[type
];
3492 for (i
= 0; i
< idx
- 1; i
++) {
3493 path
= get_input_path(codec
, 0, i
);
3494 if (path
&& path
->ctls
[type
] == ctl
)
3500 /* create individual capture volume and switch controls per input */
3501 static int create_multi_cap_vol_ctl(struct hda_codec
*codec
)
3503 struct hda_gen_spec
*spec
= codec
->spec
;
3504 struct hda_input_mux
*imux
= &spec
->input_mux
;
3507 for (i
= 0; i
< imux
->num_items
; i
++) {
3511 idx
= imux
->items
[i
].index
;
3512 if (idx
>= spec
->autocfg
.num_inputs
)
3514 inv_dmic
= is_inv_dmic_pin(codec
, spec
->imux_pins
[i
]);
3516 for (type
= 0; type
< 2; type
++) {
3517 err
= add_single_cap_ctl(codec
,
3518 spec
->input_labels
[idx
],
3519 spec
->input_label_idxs
[idx
],
3521 get_first_cap_ctl(codec
, i
, type
),
3530 static int create_capture_mixers(struct hda_codec
*codec
)
3532 struct hda_gen_spec
*spec
= codec
->spec
;
3533 struct hda_input_mux
*imux
= &spec
->input_mux
;
3534 int i
, n
, nums
, err
;
3536 if (spec
->dyn_adc_switch
)
3539 nums
= spec
->num_adc_nids
;
3541 if (!spec
->auto_mic
&& imux
->num_items
> 1) {
3542 struct snd_kcontrol_new
*knew
;
3544 name
= nums
> 1 ? "Input Source" : "Capture Source";
3545 knew
= snd_hda_gen_add_kctl(spec
, name
, &cap_src_temp
);
3551 for (n
= 0; n
< nums
; n
++) {
3553 bool multi_cap_vol
= spec
->multi_cap_vol
;
3554 bool inv_dmic
= false;
3558 for (i
= 0; i
< imux
->num_items
; i
++) {
3559 struct nid_path
*path
;
3560 path
= get_input_path(codec
, n
, i
);
3563 parse_capvol_in_path(codec
, path
);
3565 vol
= path
->ctls
[NID_PATH_VOL_CTL
];
3566 else if (vol
!= path
->ctls
[NID_PATH_VOL_CTL
]) {
3568 if (!same_amp_caps(codec
, vol
,
3569 path
->ctls
[NID_PATH_VOL_CTL
], HDA_INPUT
))
3570 multi_cap_vol
= true;
3573 sw
= path
->ctls
[NID_PATH_MUTE_CTL
];
3574 else if (sw
!= path
->ctls
[NID_PATH_MUTE_CTL
]) {
3576 if (!same_amp_caps(codec
, sw
,
3577 path
->ctls
[NID_PATH_MUTE_CTL
], HDA_INPUT
))
3578 multi_cap_vol
= true;
3580 if (is_inv_dmic_pin(codec
, spec
->imux_pins
[i
]))
3585 err
= create_single_cap_vol_ctl(codec
, n
, vol
, sw
,
3587 else if (!multi_cap_vol
&& !inv_dmic
)
3588 err
= create_bind_cap_vol_ctl(codec
, n
, vol
, sw
);
3590 err
= create_multi_cap_vol_ctl(codec
);
3599 * add mic boosts if needed
3602 /* check whether the given amp is feasible as a boost volume */
3603 static bool check_boost_vol(struct hda_codec
*codec
, hda_nid_t nid
,
3608 if (!nid_has_volume(codec
, nid
, dir
) ||
3609 is_ctl_associated(codec
, nid
, dir
, idx
, NID_PATH_VOL_CTL
) ||
3610 is_ctl_associated(codec
, nid
, dir
, idx
, NID_PATH_BOOST_CTL
))
3613 step
= (query_amp_caps(codec
, nid
, dir
) & AC_AMPCAP_STEP_SIZE
)
3614 >> AC_AMPCAP_STEP_SIZE_SHIFT
;
3620 /* look for a boost amp in a widget close to the pin */
3621 static unsigned int look_for_boost_amp(struct hda_codec
*codec
,
3622 struct nid_path
*path
)
3624 unsigned int val
= 0;
3628 for (depth
= 0; depth
< 3; depth
++) {
3629 if (depth
>= path
->depth
- 1)
3631 nid
= path
->path
[depth
];
3632 if (depth
&& check_boost_vol(codec
, nid
, HDA_OUTPUT
, 0)) {
3633 val
= HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_OUTPUT
);
3635 } else if (check_boost_vol(codec
, nid
, HDA_INPUT
,
3636 path
->idx
[depth
])) {
3637 val
= HDA_COMPOSE_AMP_VAL(nid
, 3, path
->idx
[depth
],
3646 static int parse_mic_boost(struct hda_codec
*codec
)
3648 struct hda_gen_spec
*spec
= codec
->spec
;
3649 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3650 struct hda_input_mux
*imux
= &spec
->input_mux
;
3653 if (!spec
->num_adc_nids
)
3656 for (i
= 0; i
< imux
->num_items
; i
++) {
3657 struct nid_path
*path
;
3660 char boost_label
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
3662 idx
= imux
->items
[i
].index
;
3663 if (idx
>= imux
->num_items
)
3666 /* check only line-in and mic pins */
3667 if (cfg
->inputs
[idx
].type
> AUTO_PIN_LINE_IN
)
3670 path
= get_input_path(codec
, 0, i
);
3674 val
= look_for_boost_amp(codec
, path
);
3678 /* create a boost control */
3679 snprintf(boost_label
, sizeof(boost_label
),
3680 "%s Boost Volume", spec
->input_labels
[idx
]);
3681 if (!add_control(spec
, HDA_CTL_WIDGET_VOL
, boost_label
,
3682 spec
->input_label_idxs
[idx
], val
))
3685 path
->ctls
[NID_PATH_BOOST_CTL
] = val
;
3691 * parse digital I/Os and set up NIDs in BIOS auto-parse mode
3693 static void parse_digital(struct hda_codec
*codec
)
3695 struct hda_gen_spec
*spec
= codec
->spec
;
3696 struct nid_path
*path
;
3698 hda_nid_t dig_nid
, pin
;
3700 /* support multiple SPDIFs; the secondary is set up as a slave */
3702 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
3703 pin
= spec
->autocfg
.dig_out_pins
[i
];
3704 dig_nid
= look_for_dac(codec
, pin
, true);
3707 path
= snd_hda_add_new_path(codec
, dig_nid
, pin
, 0);
3710 print_nid_path("digout", path
);
3711 path
->active
= true;
3712 spec
->digout_paths
[i
] = snd_hda_get_path_idx(codec
, path
);
3713 set_pin_target(codec
, pin
, PIN_OUT
, false);
3715 spec
->multiout
.dig_out_nid
= dig_nid
;
3716 spec
->dig_out_type
= spec
->autocfg
.dig_out_type
[0];
3718 spec
->multiout
.slave_dig_outs
= spec
->slave_dig_outs
;
3719 if (nums
>= ARRAY_SIZE(spec
->slave_dig_outs
) - 1)
3721 spec
->slave_dig_outs
[nums
- 1] = dig_nid
;
3726 if (spec
->autocfg
.dig_in_pin
) {
3727 pin
= spec
->autocfg
.dig_in_pin
;
3728 dig_nid
= codec
->start_nid
;
3729 for (i
= 0; i
< codec
->num_nodes
; i
++, dig_nid
++) {
3730 unsigned int wcaps
= get_wcaps(codec
, dig_nid
);
3731 if (get_wcaps_type(wcaps
) != AC_WID_AUD_IN
)
3733 if (!(wcaps
& AC_WCAP_DIGITAL
))
3735 path
= snd_hda_add_new_path(codec
, pin
, dig_nid
, 0);
3737 print_nid_path("digin", path
);
3738 path
->active
= true;
3739 spec
->dig_in_nid
= dig_nid
;
3740 spec
->digin_path
= snd_hda_get_path_idx(codec
, path
);
3741 set_pin_target(codec
, pin
, PIN_IN
, false);
3750 * input MUX handling
3753 static bool dyn_adc_pcm_resetup(struct hda_codec
*codec
, int cur
);
3755 /* select the given imux item; either unmute exclusively or select the route */
3756 static int mux_select(struct hda_codec
*codec
, unsigned int adc_idx
,
3759 struct hda_gen_spec
*spec
= codec
->spec
;
3760 const struct hda_input_mux
*imux
;
3761 struct nid_path
*old_path
, *path
;
3763 imux
= &spec
->input_mux
;
3764 if (!imux
->num_items
)
3767 if (idx
>= imux
->num_items
)
3768 idx
= imux
->num_items
- 1;
3769 if (spec
->cur_mux
[adc_idx
] == idx
)
3772 old_path
= get_input_path(codec
, adc_idx
, spec
->cur_mux
[adc_idx
]);
3775 if (old_path
->active
)
3776 snd_hda_activate_path(codec
, old_path
, false, false);
3778 spec
->cur_mux
[adc_idx
] = idx
;
3781 update_hp_mic(codec
, adc_idx
, false);
3783 if (spec
->dyn_adc_switch
)
3784 dyn_adc_pcm_resetup(codec
, idx
);
3786 path
= get_input_path(codec
, adc_idx
, idx
);
3791 snd_hda_activate_path(codec
, path
, true, false);
3792 if (spec
->cap_sync_hook
)
3793 spec
->cap_sync_hook(codec
, NULL
, NULL
);
3794 path_power_down_sync(codec
, old_path
);
3800 * Jack detections for HP auto-mute and mic-switch
3803 /* check each pin in the given array; returns true if any of them is plugged */
3804 static bool detect_jacks(struct hda_codec
*codec
, int num_pins
, hda_nid_t
*pins
)
3807 bool present
= false;
3809 for (i
= 0; i
< num_pins
; i
++) {
3810 hda_nid_t nid
= pins
[i
];
3813 /* don't detect pins retasked as inputs */
3814 if (snd_hda_codec_get_pin_target(codec
, nid
) & AC_PINCTL_IN_EN
)
3816 if (snd_hda_jack_detect_state(codec
, nid
) == HDA_JACK_PRESENT
)
3822 /* standard HP/line-out auto-mute helper */
3823 static void do_automute(struct hda_codec
*codec
, int num_pins
, hda_nid_t
*pins
,
3824 int *paths
, bool mute
)
3826 struct hda_gen_spec
*spec
= codec
->spec
;
3829 for (i
= 0; i
< num_pins
; i
++) {
3830 hda_nid_t nid
= pins
[i
];
3831 unsigned int val
, oldval
;
3835 if (spec
->auto_mute_via_amp
) {
3836 struct nid_path
*path
;
3839 path
= snd_hda_get_path_from_idx(codec
, paths
[i
]);
3842 mute_nid
= get_amp_nid_(path
->ctls
[NID_PATH_MUTE_CTL
]);
3846 spec
->mute_bits
|= (1ULL << mute_nid
);
3848 spec
->mute_bits
&= ~(1ULL << mute_nid
);
3849 set_pin_eapd(codec
, nid
, !mute
);
3853 oldval
= snd_hda_codec_get_pin_target(codec
, nid
);
3854 if (oldval
& PIN_IN
)
3855 continue; /* no mute for inputs */
3856 /* don't reset VREF value in case it's controlling
3857 * the amp (see alc861_fixup_asus_amp_vref_0f())
3859 if (spec
->keep_vref_in_automute
)
3860 val
= oldval
& ~PIN_HP
;
3865 /* here we call update_pin_ctl() so that the pinctl is changed
3866 * without changing the pinctl target value;
3867 * the original target value will be still referred at the
3868 * init / resume again
3870 update_pin_ctl(codec
, nid
, val
);
3871 set_pin_eapd(codec
, nid
, !mute
);
3875 /* Toggle outputs muting */
3876 void snd_hda_gen_update_outputs(struct hda_codec
*codec
)
3878 struct hda_gen_spec
*spec
= codec
->spec
;
3882 /* Control HP pins/amps depending on master_mute state;
3883 * in general, HP pins/amps control should be enabled in all cases,
3884 * but currently set only for master_mute, just to be safe
3886 if (spec
->autocfg
.line_out_type
== AUTO_PIN_HP_OUT
)
3887 paths
= spec
->out_paths
;
3889 paths
= spec
->hp_paths
;
3890 do_automute(codec
, ARRAY_SIZE(spec
->autocfg
.hp_pins
),
3891 spec
->autocfg
.hp_pins
, paths
, spec
->master_mute
);
3893 if (!spec
->automute_speaker
)
3896 on
= spec
->hp_jack_present
| spec
->line_jack_present
;
3897 on
|= spec
->master_mute
;
3898 spec
->speaker_muted
= on
;
3899 if (spec
->autocfg
.line_out_type
== AUTO_PIN_SPEAKER_OUT
)
3900 paths
= spec
->out_paths
;
3902 paths
= spec
->speaker_paths
;
3903 do_automute(codec
, ARRAY_SIZE(spec
->autocfg
.speaker_pins
),
3904 spec
->autocfg
.speaker_pins
, paths
, on
);
3906 /* toggle line-out mutes if needed, too */
3907 /* if LO is a copy of either HP or Speaker, don't need to handle it */
3908 if (spec
->autocfg
.line_out_pins
[0] == spec
->autocfg
.hp_pins
[0] ||
3909 spec
->autocfg
.line_out_pins
[0] == spec
->autocfg
.speaker_pins
[0])
3911 if (!spec
->automute_lo
)
3914 on
= spec
->hp_jack_present
;
3915 on
|= spec
->master_mute
;
3916 spec
->line_out_muted
= on
;
3917 paths
= spec
->out_paths
;
3918 do_automute(codec
, ARRAY_SIZE(spec
->autocfg
.line_out_pins
),
3919 spec
->autocfg
.line_out_pins
, paths
, on
);
3921 EXPORT_SYMBOL_HDA(snd_hda_gen_update_outputs
);
3923 static void call_update_outputs(struct hda_codec
*codec
)
3925 struct hda_gen_spec
*spec
= codec
->spec
;
3926 if (spec
->automute_hook
)
3927 spec
->automute_hook(codec
);
3929 snd_hda_gen_update_outputs(codec
);
3931 /* sync the whole vmaster slaves to reflect the new auto-mute status */
3932 if (spec
->auto_mute_via_amp
&& !codec
->bus
->shutdown
)
3933 snd_ctl_sync_vmaster(spec
->vmaster_mute
.sw_kctl
, false);
3936 /* standard HP-automute helper */
3937 void snd_hda_gen_hp_automute(struct hda_codec
*codec
, struct hda_jack_tbl
*jack
)
3939 struct hda_gen_spec
*spec
= codec
->spec
;
3940 hda_nid_t
*pins
= spec
->autocfg
.hp_pins
;
3941 int num_pins
= ARRAY_SIZE(spec
->autocfg
.hp_pins
);
3943 /* No detection for the first HP jack during indep-HP mode */
3944 if (spec
->indep_hp_enabled
) {
3949 spec
->hp_jack_present
= detect_jacks(codec
, num_pins
, pins
);
3950 if (!spec
->detect_hp
|| (!spec
->automute_speaker
&& !spec
->automute_lo
))
3952 call_update_outputs(codec
);
3954 EXPORT_SYMBOL_HDA(snd_hda_gen_hp_automute
);
3956 /* standard line-out-automute helper */
3957 void snd_hda_gen_line_automute(struct hda_codec
*codec
, struct hda_jack_tbl
*jack
)
3959 struct hda_gen_spec
*spec
= codec
->spec
;
3961 if (spec
->autocfg
.line_out_type
== AUTO_PIN_SPEAKER_OUT
)
3963 /* check LO jack only when it's different from HP */
3964 if (spec
->autocfg
.line_out_pins
[0] == spec
->autocfg
.hp_pins
[0])
3967 spec
->line_jack_present
=
3968 detect_jacks(codec
, ARRAY_SIZE(spec
->autocfg
.line_out_pins
),
3969 spec
->autocfg
.line_out_pins
);
3970 if (!spec
->automute_speaker
|| !spec
->detect_lo
)
3972 call_update_outputs(codec
);
3974 EXPORT_SYMBOL_HDA(snd_hda_gen_line_automute
);
3976 /* standard mic auto-switch helper */
3977 void snd_hda_gen_mic_autoswitch(struct hda_codec
*codec
, struct hda_jack_tbl
*jack
)
3979 struct hda_gen_spec
*spec
= codec
->spec
;
3982 if (!spec
->auto_mic
)
3985 for (i
= spec
->am_num_entries
- 1; i
> 0; i
--) {
3986 hda_nid_t pin
= spec
->am_entry
[i
].pin
;
3987 /* don't detect pins retasked as outputs */
3988 if (snd_hda_codec_get_pin_target(codec
, pin
) & AC_PINCTL_OUT_EN
)
3990 if (snd_hda_jack_detect_state(codec
, pin
) == HDA_JACK_PRESENT
) {
3991 mux_select(codec
, 0, spec
->am_entry
[i
].idx
);
3995 mux_select(codec
, 0, spec
->am_entry
[0].idx
);
3997 EXPORT_SYMBOL_HDA(snd_hda_gen_mic_autoswitch
);
3999 /* call appropriate hooks */
4000 static void call_hp_automute(struct hda_codec
*codec
, struct hda_jack_tbl
*jack
)
4002 struct hda_gen_spec
*spec
= codec
->spec
;
4003 if (spec
->hp_automute_hook
)
4004 spec
->hp_automute_hook(codec
, jack
);
4006 snd_hda_gen_hp_automute(codec
, jack
);
4009 static void call_line_automute(struct hda_codec
*codec
,
4010 struct hda_jack_tbl
*jack
)
4012 struct hda_gen_spec
*spec
= codec
->spec
;
4013 if (spec
->line_automute_hook
)
4014 spec
->line_automute_hook(codec
, jack
);
4016 snd_hda_gen_line_automute(codec
, jack
);
4019 static void call_mic_autoswitch(struct hda_codec
*codec
,
4020 struct hda_jack_tbl
*jack
)
4022 struct hda_gen_spec
*spec
= codec
->spec
;
4023 if (spec
->mic_autoswitch_hook
)
4024 spec
->mic_autoswitch_hook(codec
, jack
);
4026 snd_hda_gen_mic_autoswitch(codec
, jack
);
4029 /* update jack retasking */
4030 static void update_automute_all(struct hda_codec
*codec
)
4032 call_hp_automute(codec
, NULL
);
4033 call_line_automute(codec
, NULL
);
4034 call_mic_autoswitch(codec
, NULL
);
4038 * Auto-Mute mode mixer enum support
4040 static int automute_mode_info(struct snd_kcontrol
*kcontrol
,
4041 struct snd_ctl_elem_info
*uinfo
)
4043 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
4044 struct hda_gen_spec
*spec
= codec
->spec
;
4045 static const char * const texts3
[] = {
4046 "Disabled", "Speaker Only", "Line Out+Speaker"
4049 if (spec
->automute_speaker_possible
&& spec
->automute_lo_possible
)
4050 return snd_hda_enum_helper_info(kcontrol
, uinfo
, 3, texts3
);
4051 return snd_hda_enum_bool_helper_info(kcontrol
, uinfo
);
4054 static int automute_mode_get(struct snd_kcontrol
*kcontrol
,
4055 struct snd_ctl_elem_value
*ucontrol
)
4057 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
4058 struct hda_gen_spec
*spec
= codec
->spec
;
4059 unsigned int val
= 0;
4060 if (spec
->automute_speaker
)
4062 if (spec
->automute_lo
)
4065 ucontrol
->value
.enumerated
.item
[0] = val
;
4069 static int automute_mode_put(struct snd_kcontrol
*kcontrol
,
4070 struct snd_ctl_elem_value
*ucontrol
)
4072 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
4073 struct hda_gen_spec
*spec
= codec
->spec
;
4075 switch (ucontrol
->value
.enumerated
.item
[0]) {
4077 if (!spec
->automute_speaker
&& !spec
->automute_lo
)
4079 spec
->automute_speaker
= 0;
4080 spec
->automute_lo
= 0;
4083 if (spec
->automute_speaker_possible
) {
4084 if (!spec
->automute_lo
&& spec
->automute_speaker
)
4086 spec
->automute_speaker
= 1;
4087 spec
->automute_lo
= 0;
4088 } else if (spec
->automute_lo_possible
) {
4089 if (spec
->automute_lo
)
4091 spec
->automute_lo
= 1;
4096 if (!spec
->automute_lo_possible
|| !spec
->automute_speaker_possible
)
4098 if (spec
->automute_speaker
&& spec
->automute_lo
)
4100 spec
->automute_speaker
= 1;
4101 spec
->automute_lo
= 1;
4106 call_update_outputs(codec
);
4110 static const struct snd_kcontrol_new automute_mode_enum
= {
4111 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
4112 .name
= "Auto-Mute Mode",
4113 .info
= automute_mode_info
,
4114 .get
= automute_mode_get
,
4115 .put
= automute_mode_put
,
4118 static int add_automute_mode_enum(struct hda_codec
*codec
)
4120 struct hda_gen_spec
*spec
= codec
->spec
;
4122 if (!snd_hda_gen_add_kctl(spec
, NULL
, &automute_mode_enum
))
4128 * Check the availability of HP/line-out auto-mute;
4129 * Set up appropriately if really supported
4131 static int check_auto_mute_availability(struct hda_codec
*codec
)
4133 struct hda_gen_spec
*spec
= codec
->spec
;
4134 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
4138 if (spec
->suppress_auto_mute
)
4141 if (cfg
->hp_pins
[0])
4143 if (cfg
->line_out_pins
[0])
4145 if (cfg
->speaker_pins
[0])
4147 if (present
< 2) /* need two different output types */
4150 if (!cfg
->speaker_pins
[0] &&
4151 cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
) {
4152 memcpy(cfg
->speaker_pins
, cfg
->line_out_pins
,
4153 sizeof(cfg
->speaker_pins
));
4154 cfg
->speaker_outs
= cfg
->line_outs
;
4157 if (!cfg
->hp_pins
[0] &&
4158 cfg
->line_out_type
== AUTO_PIN_HP_OUT
) {
4159 memcpy(cfg
->hp_pins
, cfg
->line_out_pins
,
4160 sizeof(cfg
->hp_pins
));
4161 cfg
->hp_outs
= cfg
->line_outs
;
4164 for (i
= 0; i
< cfg
->hp_outs
; i
++) {
4165 hda_nid_t nid
= cfg
->hp_pins
[i
];
4166 if (!is_jack_detectable(codec
, nid
))
4168 snd_printdd("hda-codec: Enable HP auto-muting on NID 0x%x\n",
4170 snd_hda_jack_detect_enable_callback(codec
, nid
, HDA_GEN_HP_EVENT
,
4172 spec
->detect_hp
= 1;
4175 if (cfg
->line_out_type
== AUTO_PIN_LINE_OUT
&& cfg
->line_outs
) {
4176 if (cfg
->speaker_outs
)
4177 for (i
= 0; i
< cfg
->line_outs
; i
++) {
4178 hda_nid_t nid
= cfg
->line_out_pins
[i
];
4179 if (!is_jack_detectable(codec
, nid
))
4181 snd_printdd("hda-codec: Enable Line-Out auto-muting on NID 0x%x\n", nid
);
4182 snd_hda_jack_detect_enable_callback(codec
, nid
,
4183 HDA_GEN_FRONT_EVENT
,
4184 call_line_automute
);
4185 spec
->detect_lo
= 1;
4187 spec
->automute_lo_possible
= spec
->detect_hp
;
4190 spec
->automute_speaker_possible
= cfg
->speaker_outs
&&
4191 (spec
->detect_hp
|| spec
->detect_lo
);
4193 spec
->automute_lo
= spec
->automute_lo_possible
;
4194 spec
->automute_speaker
= spec
->automute_speaker_possible
;
4196 if (spec
->automute_speaker_possible
|| spec
->automute_lo_possible
) {
4197 /* create a control for automute mode */
4198 err
= add_automute_mode_enum(codec
);
4205 /* check whether all auto-mic pins are valid; setup indices if OK */
4206 static bool auto_mic_check_imux(struct hda_codec
*codec
)
4208 struct hda_gen_spec
*spec
= codec
->spec
;
4209 const struct hda_input_mux
*imux
;
4212 imux
= &spec
->input_mux
;
4213 for (i
= 0; i
< spec
->am_num_entries
; i
++) {
4214 spec
->am_entry
[i
].idx
=
4215 find_idx_in_nid_list(spec
->am_entry
[i
].pin
,
4216 spec
->imux_pins
, imux
->num_items
);
4217 if (spec
->am_entry
[i
].idx
< 0)
4218 return false; /* no corresponding imux */
4221 /* we don't need the jack detection for the first pin */
4222 for (i
= 1; i
< spec
->am_num_entries
; i
++)
4223 snd_hda_jack_detect_enable_callback(codec
,
4224 spec
->am_entry
[i
].pin
,
4226 call_mic_autoswitch
);
4230 static int compare_attr(const void *ap
, const void *bp
)
4232 const struct automic_entry
*a
= ap
;
4233 const struct automic_entry
*b
= bp
;
4234 return (int)(a
->attr
- b
->attr
);
4238 * Check the availability of auto-mic switch;
4239 * Set up if really supported
4241 static int check_auto_mic_availability(struct hda_codec
*codec
)
4243 struct hda_gen_spec
*spec
= codec
->spec
;
4244 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
4248 if (spec
->suppress_auto_mic
)
4253 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
4254 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
4256 attr
= snd_hda_codec_get_pincfg(codec
, nid
);
4257 attr
= snd_hda_get_input_pin_attr(attr
);
4258 if (types
& (1 << attr
))
4259 return 0; /* already occupied */
4261 case INPUT_PIN_ATTR_INT
:
4262 if (cfg
->inputs
[i
].type
!= AUTO_PIN_MIC
)
4263 return 0; /* invalid type */
4265 case INPUT_PIN_ATTR_UNUSED
:
4266 return 0; /* invalid entry */
4268 if (cfg
->inputs
[i
].type
> AUTO_PIN_LINE_IN
)
4269 return 0; /* invalid type */
4270 if (!spec
->line_in_auto_switch
&&
4271 cfg
->inputs
[i
].type
!= AUTO_PIN_MIC
)
4272 return 0; /* only mic is allowed */
4273 if (!is_jack_detectable(codec
, nid
))
4274 return 0; /* no unsol support */
4277 if (num_pins
>= MAX_AUTO_MIC_PINS
)
4279 types
|= (1 << attr
);
4280 spec
->am_entry
[num_pins
].pin
= nid
;
4281 spec
->am_entry
[num_pins
].attr
= attr
;
4288 spec
->am_num_entries
= num_pins
;
4289 /* sort the am_entry in the order of attr so that the pin with a
4290 * higher attr will be selected when the jack is plugged.
4292 sort(spec
->am_entry
, num_pins
, sizeof(spec
->am_entry
[0]),
4293 compare_attr
, NULL
);
4295 if (!auto_mic_check_imux(codec
))
4299 spec
->num_adc_nids
= 1;
4300 spec
->cur_mux
[0] = spec
->am_entry
[0].idx
;
4301 snd_printdd("hda-codec: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
4302 spec
->am_entry
[0].pin
,
4303 spec
->am_entry
[1].pin
,
4304 spec
->am_entry
[2].pin
);
4309 /* power_filter hook; make inactive widgets into power down */
4310 static unsigned int snd_hda_gen_path_power_filter(struct hda_codec
*codec
,
4312 unsigned int power_state
)
4314 if (power_state
!= AC_PWRST_D0
)
4316 if (get_wcaps_type(get_wcaps(codec
, nid
)) >= AC_WID_POWER
)
4318 if (is_active_nid_for_any(codec
, nid
))
4323 /* mute all aamix inputs initially; parse up to the first leaves */
4324 static void mute_all_mixer_nid(struct hda_codec
*codec
, hda_nid_t mix
)
4327 const hda_nid_t
*conn
;
4330 nums
= snd_hda_get_conn_list(codec
, mix
, &conn
);
4331 has_amp
= nid_has_mute(codec
, mix
, HDA_INPUT
);
4332 for (i
= 0; i
< nums
; i
++) {
4334 snd_hda_codec_amp_stereo(codec
, mix
,
4336 0xff, HDA_AMP_MUTE
);
4337 else if (nid_has_volume(codec
, conn
[i
], HDA_OUTPUT
))
4338 snd_hda_codec_amp_stereo(codec
, conn
[i
],
4340 0xff, HDA_AMP_MUTE
);
4345 * Parse the given BIOS configuration and set up the hda_gen_spec
4347 * return 1 if successful, 0 if the proper config is not found,
4348 * or a negative error code
4350 int snd_hda_gen_parse_auto_config(struct hda_codec
*codec
,
4351 struct auto_pin_cfg
*cfg
)
4353 struct hda_gen_spec
*spec
= codec
->spec
;
4356 parse_user_hints(codec
);
4358 if (spec
->mixer_nid
&& !spec
->mixer_merge_nid
)
4359 spec
->mixer_merge_nid
= spec
->mixer_nid
;
4361 if (cfg
!= &spec
->autocfg
) {
4362 spec
->autocfg
= *cfg
;
4363 cfg
= &spec
->autocfg
;
4366 if (!spec
->main_out_badness
)
4367 spec
->main_out_badness
= &hda_main_out_badness
;
4368 if (!spec
->extra_out_badness
)
4369 spec
->extra_out_badness
= &hda_extra_out_badness
;
4371 fill_all_dac_nids(codec
);
4373 if (!cfg
->line_outs
) {
4374 if (cfg
->dig_outs
|| cfg
->dig_in_pin
) {
4375 spec
->multiout
.max_channels
= 2;
4376 spec
->no_analog
= 1;
4379 return 0; /* can't find valid BIOS pin config */
4382 if (!spec
->no_primary_hp
&&
4383 cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
&&
4384 cfg
->line_outs
<= cfg
->hp_outs
) {
4385 /* use HP as primary out */
4386 cfg
->speaker_outs
= cfg
->line_outs
;
4387 memcpy(cfg
->speaker_pins
, cfg
->line_out_pins
,
4388 sizeof(cfg
->speaker_pins
));
4389 cfg
->line_outs
= cfg
->hp_outs
;
4390 memcpy(cfg
->line_out_pins
, cfg
->hp_pins
, sizeof(cfg
->hp_pins
));
4392 memset(cfg
->hp_pins
, 0, sizeof(cfg
->hp_pins
));
4393 cfg
->line_out_type
= AUTO_PIN_HP_OUT
;
4396 err
= parse_output_paths(codec
);
4399 err
= create_multi_channel_mode(codec
);
4402 err
= create_multi_out_ctls(codec
, cfg
);
4405 err
= create_hp_out_ctls(codec
);
4408 err
= create_speaker_out_ctls(codec
);
4411 err
= create_indep_hp_ctls(codec
);
4414 err
= create_loopback_mixing_ctl(codec
);
4417 err
= create_hp_mic(codec
);
4420 err
= create_input_ctls(codec
);
4424 spec
->const_channel_count
= spec
->ext_channel_count
;
4425 /* check the multiple speaker and headphone pins */
4426 if (cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
)
4427 spec
->const_channel_count
= max(spec
->const_channel_count
,
4428 cfg
->speaker_outs
* 2);
4429 if (cfg
->line_out_type
!= AUTO_PIN_HP_OUT
)
4430 spec
->const_channel_count
= max(spec
->const_channel_count
,
4432 spec
->multiout
.max_channels
= max(spec
->ext_channel_count
,
4433 spec
->const_channel_count
);
4435 err
= check_auto_mute_availability(codec
);
4439 err
= check_dyn_adc_switch(codec
);
4443 err
= check_auto_mic_availability(codec
);
4447 err
= create_capture_mixers(codec
);
4451 err
= parse_mic_boost(codec
);
4455 /* create "Headphone Mic Jack Mode" if no input selection is
4456 * available (or user specifies add_jack_modes hint)
4458 if (spec
->hp_mic_pin
&&
4459 (spec
->auto_mic
|| spec
->input_mux
.num_items
== 1 ||
4460 spec
->add_jack_modes
)) {
4461 err
= create_hp_mic_jack_mode(codec
, spec
->hp_mic_pin
);
4466 if (spec
->add_jack_modes
) {
4467 if (cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
) {
4468 err
= create_out_jack_modes(codec
, cfg
->line_outs
,
4469 cfg
->line_out_pins
);
4473 if (cfg
->line_out_type
!= AUTO_PIN_HP_OUT
) {
4474 err
= create_out_jack_modes(codec
, cfg
->hp_outs
,
4481 /* mute all aamix input initially */
4482 if (spec
->mixer_nid
)
4483 mute_all_mixer_nid(codec
, spec
->mixer_nid
);
4486 parse_digital(codec
);
4488 if (spec
->power_down_unused
)
4489 codec
->power_filter
= snd_hda_gen_path_power_filter
;
4491 if (!spec
->no_analog
&& spec
->beep_nid
) {
4492 err
= snd_hda_attach_beep_device(codec
, spec
->beep_nid
);
4499 EXPORT_SYMBOL_HDA(snd_hda_gen_parse_auto_config
);
4503 * Build control elements
4506 /* slave controls for virtual master */
4507 static const char * const slave_pfxs
[] = {
4508 "Front", "Surround", "Center", "LFE", "Side",
4509 "Headphone", "Speaker", "Mono", "Line Out",
4510 "CLFE", "Bass Speaker", "PCM",
4511 "Speaker Front", "Speaker Surround", "Speaker CLFE", "Speaker Side",
4512 "Headphone Front", "Headphone Surround", "Headphone CLFE",
4517 int snd_hda_gen_build_controls(struct hda_codec
*codec
)
4519 struct hda_gen_spec
*spec
= codec
->spec
;
4522 if (spec
->kctls
.used
) {
4523 err
= snd_hda_add_new_ctls(codec
, spec
->kctls
.list
);
4528 if (spec
->multiout
.dig_out_nid
) {
4529 err
= snd_hda_create_dig_out_ctls(codec
,
4530 spec
->multiout
.dig_out_nid
,
4531 spec
->multiout
.dig_out_nid
,
4532 spec
->pcm_rec
[1].pcm_type
);
4535 if (!spec
->no_analog
) {
4536 err
= snd_hda_create_spdif_share_sw(codec
,
4540 spec
->multiout
.share_spdif
= 1;
4543 if (spec
->dig_in_nid
) {
4544 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in_nid
);
4549 /* if we have no master control, let's create it */
4550 if (!spec
->no_analog
&&
4551 !snd_hda_find_mixer_ctl(codec
, "Master Playback Volume")) {
4552 err
= snd_hda_add_vmaster(codec
, "Master Playback Volume",
4553 spec
->vmaster_tlv
, slave_pfxs
,
4558 if (!spec
->no_analog
&&
4559 !snd_hda_find_mixer_ctl(codec
, "Master Playback Switch")) {
4560 err
= __snd_hda_add_vmaster(codec
, "Master Playback Switch",
4563 true, &spec
->vmaster_mute
.sw_kctl
);
4566 if (spec
->vmaster_mute
.hook
) {
4567 snd_hda_add_vmaster_hook(codec
, &spec
->vmaster_mute
,
4568 spec
->vmaster_mute_enum
);
4569 snd_hda_sync_vmaster_hook(&spec
->vmaster_mute
);
4573 free_kctls(spec
); /* no longer needed */
4575 err
= snd_hda_jack_add_kctls(codec
, &spec
->autocfg
);
4581 EXPORT_SYMBOL_HDA(snd_hda_gen_build_controls
);
4588 static void call_pcm_playback_hook(struct hda_pcm_stream
*hinfo
,
4589 struct hda_codec
*codec
,
4590 struct snd_pcm_substream
*substream
,
4593 struct hda_gen_spec
*spec
= codec
->spec
;
4594 if (spec
->pcm_playback_hook
)
4595 spec
->pcm_playback_hook(hinfo
, codec
, substream
, action
);
4598 static void call_pcm_capture_hook(struct hda_pcm_stream
*hinfo
,
4599 struct hda_codec
*codec
,
4600 struct snd_pcm_substream
*substream
,
4603 struct hda_gen_spec
*spec
= codec
->spec
;
4604 if (spec
->pcm_capture_hook
)
4605 spec
->pcm_capture_hook(hinfo
, codec
, substream
, action
);
4609 * Analog playback callbacks
4611 static int playback_pcm_open(struct hda_pcm_stream
*hinfo
,
4612 struct hda_codec
*codec
,
4613 struct snd_pcm_substream
*substream
)
4615 struct hda_gen_spec
*spec
= codec
->spec
;
4618 mutex_lock(&spec
->pcm_mutex
);
4619 err
= snd_hda_multi_out_analog_open(codec
,
4620 &spec
->multiout
, substream
,
4623 spec
->active_streams
|= 1 << STREAM_MULTI_OUT
;
4624 call_pcm_playback_hook(hinfo
, codec
, substream
,
4625 HDA_GEN_PCM_ACT_OPEN
);
4627 mutex_unlock(&spec
->pcm_mutex
);
4631 static int playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
4632 struct hda_codec
*codec
,
4633 unsigned int stream_tag
,
4634 unsigned int format
,
4635 struct snd_pcm_substream
*substream
)
4637 struct hda_gen_spec
*spec
= codec
->spec
;
4640 err
= snd_hda_multi_out_analog_prepare(codec
, &spec
->multiout
,
4641 stream_tag
, format
, substream
);
4643 call_pcm_playback_hook(hinfo
, codec
, substream
,
4644 HDA_GEN_PCM_ACT_PREPARE
);
4648 static int playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
4649 struct hda_codec
*codec
,
4650 struct snd_pcm_substream
*substream
)
4652 struct hda_gen_spec
*spec
= codec
->spec
;
4655 err
= snd_hda_multi_out_analog_cleanup(codec
, &spec
->multiout
);
4657 call_pcm_playback_hook(hinfo
, codec
, substream
,
4658 HDA_GEN_PCM_ACT_CLEANUP
);
4662 static int playback_pcm_close(struct hda_pcm_stream
*hinfo
,
4663 struct hda_codec
*codec
,
4664 struct snd_pcm_substream
*substream
)
4666 struct hda_gen_spec
*spec
= codec
->spec
;
4667 mutex_lock(&spec
->pcm_mutex
);
4668 spec
->active_streams
&= ~(1 << STREAM_MULTI_OUT
);
4669 call_pcm_playback_hook(hinfo
, codec
, substream
,
4670 HDA_GEN_PCM_ACT_CLOSE
);
4671 mutex_unlock(&spec
->pcm_mutex
);
4675 static int capture_pcm_open(struct hda_pcm_stream
*hinfo
,
4676 struct hda_codec
*codec
,
4677 struct snd_pcm_substream
*substream
)
4679 call_pcm_capture_hook(hinfo
, codec
, substream
, HDA_GEN_PCM_ACT_OPEN
);
4683 static int capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
4684 struct hda_codec
*codec
,
4685 unsigned int stream_tag
,
4686 unsigned int format
,
4687 struct snd_pcm_substream
*substream
)
4689 snd_hda_codec_setup_stream(codec
, hinfo
->nid
, stream_tag
, 0, format
);
4690 call_pcm_capture_hook(hinfo
, codec
, substream
,
4691 HDA_GEN_PCM_ACT_PREPARE
);
4695 static int capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
4696 struct hda_codec
*codec
,
4697 struct snd_pcm_substream
*substream
)
4699 snd_hda_codec_cleanup_stream(codec
, hinfo
->nid
);
4700 call_pcm_capture_hook(hinfo
, codec
, substream
,
4701 HDA_GEN_PCM_ACT_CLEANUP
);
4705 static int capture_pcm_close(struct hda_pcm_stream
*hinfo
,
4706 struct hda_codec
*codec
,
4707 struct snd_pcm_substream
*substream
)
4709 call_pcm_capture_hook(hinfo
, codec
, substream
, HDA_GEN_PCM_ACT_CLOSE
);
4713 static int alt_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
4714 struct hda_codec
*codec
,
4715 struct snd_pcm_substream
*substream
)
4717 struct hda_gen_spec
*spec
= codec
->spec
;
4720 mutex_lock(&spec
->pcm_mutex
);
4721 if (!spec
->indep_hp_enabled
)
4724 spec
->active_streams
|= 1 << STREAM_INDEP_HP
;
4725 call_pcm_playback_hook(hinfo
, codec
, substream
,
4726 HDA_GEN_PCM_ACT_OPEN
);
4727 mutex_unlock(&spec
->pcm_mutex
);
4731 static int alt_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
4732 struct hda_codec
*codec
,
4733 struct snd_pcm_substream
*substream
)
4735 struct hda_gen_spec
*spec
= codec
->spec
;
4736 mutex_lock(&spec
->pcm_mutex
);
4737 spec
->active_streams
&= ~(1 << STREAM_INDEP_HP
);
4738 call_pcm_playback_hook(hinfo
, codec
, substream
,
4739 HDA_GEN_PCM_ACT_CLOSE
);
4740 mutex_unlock(&spec
->pcm_mutex
);
4744 static int alt_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
4745 struct hda_codec
*codec
,
4746 unsigned int stream_tag
,
4747 unsigned int format
,
4748 struct snd_pcm_substream
*substream
)
4750 snd_hda_codec_setup_stream(codec
, hinfo
->nid
, stream_tag
, 0, format
);
4751 call_pcm_playback_hook(hinfo
, codec
, substream
,
4752 HDA_GEN_PCM_ACT_PREPARE
);
4756 static int alt_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
4757 struct hda_codec
*codec
,
4758 struct snd_pcm_substream
*substream
)
4760 snd_hda_codec_cleanup_stream(codec
, hinfo
->nid
);
4761 call_pcm_playback_hook(hinfo
, codec
, substream
,
4762 HDA_GEN_PCM_ACT_CLEANUP
);
4769 static int dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
4770 struct hda_codec
*codec
,
4771 struct snd_pcm_substream
*substream
)
4773 struct hda_gen_spec
*spec
= codec
->spec
;
4774 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
4777 static int dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
4778 struct hda_codec
*codec
,
4779 unsigned int stream_tag
,
4780 unsigned int format
,
4781 struct snd_pcm_substream
*substream
)
4783 struct hda_gen_spec
*spec
= codec
->spec
;
4784 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
4785 stream_tag
, format
, substream
);
4788 static int dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
4789 struct hda_codec
*codec
,
4790 struct snd_pcm_substream
*substream
)
4792 struct hda_gen_spec
*spec
= codec
->spec
;
4793 return snd_hda_multi_out_dig_cleanup(codec
, &spec
->multiout
);
4796 static int dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
4797 struct hda_codec
*codec
,
4798 struct snd_pcm_substream
*substream
)
4800 struct hda_gen_spec
*spec
= codec
->spec
;
4801 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
4807 #define alt_capture_pcm_open capture_pcm_open
4808 #define alt_capture_pcm_close capture_pcm_close
4810 static int alt_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
4811 struct hda_codec
*codec
,
4812 unsigned int stream_tag
,
4813 unsigned int format
,
4814 struct snd_pcm_substream
*substream
)
4816 struct hda_gen_spec
*spec
= codec
->spec
;
4818 snd_hda_codec_setup_stream(codec
, spec
->adc_nids
[substream
->number
+ 1],
4819 stream_tag
, 0, format
);
4820 call_pcm_capture_hook(hinfo
, codec
, substream
,
4821 HDA_GEN_PCM_ACT_PREPARE
);
4825 static int alt_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
4826 struct hda_codec
*codec
,
4827 struct snd_pcm_substream
*substream
)
4829 struct hda_gen_spec
*spec
= codec
->spec
;
4831 snd_hda_codec_cleanup_stream(codec
,
4832 spec
->adc_nids
[substream
->number
+ 1]);
4833 call_pcm_capture_hook(hinfo
, codec
, substream
,
4834 HDA_GEN_PCM_ACT_CLEANUP
);
4840 static const struct hda_pcm_stream pcm_analog_playback
= {
4844 /* NID is set in build_pcms */
4846 .open
= playback_pcm_open
,
4847 .close
= playback_pcm_close
,
4848 .prepare
= playback_pcm_prepare
,
4849 .cleanup
= playback_pcm_cleanup
4853 static const struct hda_pcm_stream pcm_analog_capture
= {
4857 /* NID is set in build_pcms */
4859 .open
= capture_pcm_open
,
4860 .close
= capture_pcm_close
,
4861 .prepare
= capture_pcm_prepare
,
4862 .cleanup
= capture_pcm_cleanup
4866 static const struct hda_pcm_stream pcm_analog_alt_playback
= {
4870 /* NID is set in build_pcms */
4872 .open
= alt_playback_pcm_open
,
4873 .close
= alt_playback_pcm_close
,
4874 .prepare
= alt_playback_pcm_prepare
,
4875 .cleanup
= alt_playback_pcm_cleanup
4879 static const struct hda_pcm_stream pcm_analog_alt_capture
= {
4880 .substreams
= 2, /* can be overridden */
4883 /* NID is set in build_pcms */
4885 .open
= alt_capture_pcm_open
,
4886 .close
= alt_capture_pcm_close
,
4887 .prepare
= alt_capture_pcm_prepare
,
4888 .cleanup
= alt_capture_pcm_cleanup
4892 static const struct hda_pcm_stream pcm_digital_playback
= {
4896 /* NID is set in build_pcms */
4898 .open
= dig_playback_pcm_open
,
4899 .close
= dig_playback_pcm_close
,
4900 .prepare
= dig_playback_pcm_prepare
,
4901 .cleanup
= dig_playback_pcm_cleanup
4905 static const struct hda_pcm_stream pcm_digital_capture
= {
4909 /* NID is set in build_pcms */
4912 /* Used by build_pcms to flag that a PCM has no playback stream */
4913 static const struct hda_pcm_stream pcm_null_stream
= {
4920 * dynamic changing ADC PCM streams
4922 static bool dyn_adc_pcm_resetup(struct hda_codec
*codec
, int cur
)
4924 struct hda_gen_spec
*spec
= codec
->spec
;
4925 hda_nid_t new_adc
= spec
->adc_nids
[spec
->dyn_adc_idx
[cur
]];
4927 if (spec
->cur_adc
&& spec
->cur_adc
!= new_adc
) {
4928 /* stream is running, let's swap the current ADC */
4929 __snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
, 1);
4930 spec
->cur_adc
= new_adc
;
4931 snd_hda_codec_setup_stream(codec
, new_adc
,
4932 spec
->cur_adc_stream_tag
, 0,
4933 spec
->cur_adc_format
);
4939 /* analog capture with dynamic dual-adc changes */
4940 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
4941 struct hda_codec
*codec
,
4942 unsigned int stream_tag
,
4943 unsigned int format
,
4944 struct snd_pcm_substream
*substream
)
4946 struct hda_gen_spec
*spec
= codec
->spec
;
4947 spec
->cur_adc
= spec
->adc_nids
[spec
->dyn_adc_idx
[spec
->cur_mux
[0]]];
4948 spec
->cur_adc_stream_tag
= stream_tag
;
4949 spec
->cur_adc_format
= format
;
4950 snd_hda_codec_setup_stream(codec
, spec
->cur_adc
, stream_tag
, 0, format
);
4954 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
4955 struct hda_codec
*codec
,
4956 struct snd_pcm_substream
*substream
)
4958 struct hda_gen_spec
*spec
= codec
->spec
;
4959 snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
);
4964 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture
= {
4968 .nid
= 0, /* fill later */
4970 .prepare
= dyn_adc_capture_pcm_prepare
,
4971 .cleanup
= dyn_adc_capture_pcm_cleanup
4975 static void fill_pcm_stream_name(char *str
, size_t len
, const char *sfx
,
4976 const char *chip_name
)
4982 strlcpy(str
, chip_name
, len
);
4984 /* drop non-alnum chars after a space */
4985 for (p
= strchr(str
, ' '); p
; p
= strchr(p
+ 1, ' ')) {
4986 if (!isalnum(p
[1])) {
4991 strlcat(str
, sfx
, len
);
4994 /* build PCM streams based on the parsed results */
4995 int snd_hda_gen_build_pcms(struct hda_codec
*codec
)
4997 struct hda_gen_spec
*spec
= codec
->spec
;
4998 struct hda_pcm
*info
= spec
->pcm_rec
;
4999 const struct hda_pcm_stream
*p
;
5000 bool have_multi_adcs
;
5002 codec
->num_pcms
= 1;
5003 codec
->pcm_info
= info
;
5005 if (spec
->no_analog
)
5008 fill_pcm_stream_name(spec
->stream_name_analog
,
5009 sizeof(spec
->stream_name_analog
),
5010 " Analog", codec
->chip_name
);
5011 info
->name
= spec
->stream_name_analog
;
5013 if (spec
->multiout
.num_dacs
> 0) {
5014 p
= spec
->stream_analog_playback
;
5016 p
= &pcm_analog_playback
;
5017 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
5018 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dac_nids
[0];
5019 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
=
5020 spec
->multiout
.max_channels
;
5021 if (spec
->autocfg
.line_out_type
== AUTO_PIN_SPEAKER_OUT
&&
5022 spec
->autocfg
.line_outs
== 2)
5023 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].chmap
=
5026 if (spec
->num_adc_nids
) {
5027 p
= spec
->stream_analog_capture
;
5029 if (spec
->dyn_adc_switch
)
5030 p
= &dyn_adc_pcm_analog_capture
;
5032 p
= &pcm_analog_capture
;
5034 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
5035 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->adc_nids
[0];
5039 /* SPDIF for stream index #1 */
5040 if (spec
->multiout
.dig_out_nid
|| spec
->dig_in_nid
) {
5041 fill_pcm_stream_name(spec
->stream_name_digital
,
5042 sizeof(spec
->stream_name_digital
),
5043 " Digital", codec
->chip_name
);
5044 codec
->num_pcms
= 2;
5045 codec
->slave_dig_outs
= spec
->multiout
.slave_dig_outs
;
5046 info
= spec
->pcm_rec
+ 1;
5047 info
->name
= spec
->stream_name_digital
;
5048 if (spec
->dig_out_type
)
5049 info
->pcm_type
= spec
->dig_out_type
;
5051 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
5052 if (spec
->multiout
.dig_out_nid
) {
5053 p
= spec
->stream_digital_playback
;
5055 p
= &pcm_digital_playback
;
5056 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
5057 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= spec
->multiout
.dig_out_nid
;
5059 if (spec
->dig_in_nid
) {
5060 p
= spec
->stream_digital_capture
;
5062 p
= &pcm_digital_capture
;
5063 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
5064 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= spec
->dig_in_nid
;
5068 if (spec
->no_analog
)
5071 /* If the use of more than one ADC is requested for the current
5072 * model, configure a second analog capture-only PCM.
5074 have_multi_adcs
= (spec
->num_adc_nids
> 1) &&
5075 !spec
->dyn_adc_switch
&& !spec
->auto_mic
;
5076 /* Additional Analaog capture for index #2 */
5077 if (spec
->alt_dac_nid
|| have_multi_adcs
) {
5078 fill_pcm_stream_name(spec
->stream_name_alt_analog
,
5079 sizeof(spec
->stream_name_alt_analog
),
5080 " Alt Analog", codec
->chip_name
);
5081 codec
->num_pcms
= 3;
5082 info
= spec
->pcm_rec
+ 2;
5083 info
->name
= spec
->stream_name_alt_analog
;
5084 if (spec
->alt_dac_nid
) {
5085 p
= spec
->stream_analog_alt_playback
;
5087 p
= &pcm_analog_alt_playback
;
5088 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] = *p
;
5089 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
=
5092 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
] =
5094 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].nid
= 0;
5096 if (have_multi_adcs
) {
5097 p
= spec
->stream_analog_alt_capture
;
5099 p
= &pcm_analog_alt_capture
;
5100 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] = *p
;
5101 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
=
5103 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].substreams
=
5104 spec
->num_adc_nids
- 1;
5106 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
] =
5108 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].nid
= 0;
5114 EXPORT_SYMBOL_HDA(snd_hda_gen_build_pcms
);
5118 * Standard auto-parser initializations
5121 /* configure the given path as a proper output */
5122 static void set_output_and_unmute(struct hda_codec
*codec
, int path_idx
)
5124 struct nid_path
*path
;
5127 path
= snd_hda_get_path_from_idx(codec
, path_idx
);
5128 if (!path
|| !path
->depth
)
5130 pin
= path
->path
[path
->depth
- 1];
5131 restore_pin_ctl(codec
, pin
);
5132 snd_hda_activate_path(codec
, path
, path
->active
,
5133 aamix_default(codec
->spec
));
5134 set_pin_eapd(codec
, pin
, path
->active
);
5137 /* initialize primary output paths */
5138 static void init_multi_out(struct hda_codec
*codec
)
5140 struct hda_gen_spec
*spec
= codec
->spec
;
5143 for (i
= 0; i
< spec
->autocfg
.line_outs
; i
++)
5144 set_output_and_unmute(codec
, spec
->out_paths
[i
]);
5148 static void __init_extra_out(struct hda_codec
*codec
, int num_outs
, int *paths
)
5152 for (i
= 0; i
< num_outs
; i
++)
5153 set_output_and_unmute(codec
, paths
[i
]);
5156 /* initialize hp and speaker paths */
5157 static void init_extra_out(struct hda_codec
*codec
)
5159 struct hda_gen_spec
*spec
= codec
->spec
;
5161 if (spec
->autocfg
.line_out_type
!= AUTO_PIN_HP_OUT
)
5162 __init_extra_out(codec
, spec
->autocfg
.hp_outs
, spec
->hp_paths
);
5163 if (spec
->autocfg
.line_out_type
!= AUTO_PIN_SPEAKER_OUT
)
5164 __init_extra_out(codec
, spec
->autocfg
.speaker_outs
,
5165 spec
->speaker_paths
);
5168 /* initialize multi-io paths */
5169 static void init_multi_io(struct hda_codec
*codec
)
5171 struct hda_gen_spec
*spec
= codec
->spec
;
5174 for (i
= 0; i
< spec
->multi_ios
; i
++) {
5175 hda_nid_t pin
= spec
->multi_io
[i
].pin
;
5176 struct nid_path
*path
;
5177 path
= get_multiio_path(codec
, i
);
5180 if (!spec
->multi_io
[i
].ctl_in
)
5181 spec
->multi_io
[i
].ctl_in
=
5182 snd_hda_codec_get_pin_target(codec
, pin
);
5183 snd_hda_activate_path(codec
, path
, path
->active
,
5184 aamix_default(spec
));
5188 /* set up input pins and loopback paths */
5189 static void init_analog_input(struct hda_codec
*codec
)
5191 struct hda_gen_spec
*spec
= codec
->spec
;
5192 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
5195 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
5196 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
5197 if (is_input_pin(codec
, nid
))
5198 restore_pin_ctl(codec
, nid
);
5200 /* init loopback inputs */
5201 if (spec
->mixer_nid
) {
5202 resume_path_from_idx(codec
, spec
->loopback_paths
[i
]);
5203 resume_path_from_idx(codec
, spec
->loopback_merge_path
);
5208 /* initialize ADC paths */
5209 static void init_input_src(struct hda_codec
*codec
)
5211 struct hda_gen_spec
*spec
= codec
->spec
;
5212 struct hda_input_mux
*imux
= &spec
->input_mux
;
5213 struct nid_path
*path
;
5216 if (spec
->dyn_adc_switch
)
5219 nums
= spec
->num_adc_nids
;
5221 for (c
= 0; c
< nums
; c
++) {
5222 for (i
= 0; i
< imux
->num_items
; i
++) {
5223 path
= get_input_path(codec
, c
, i
);
5225 bool active
= path
->active
;
5226 if (i
== spec
->cur_mux
[c
])
5228 snd_hda_activate_path(codec
, path
, active
, false);
5232 update_hp_mic(codec
, c
, true);
5235 if (spec
->cap_sync_hook
)
5236 spec
->cap_sync_hook(codec
, NULL
, NULL
);
5239 /* set right pin controls for digital I/O */
5240 static void init_digital(struct hda_codec
*codec
)
5242 struct hda_gen_spec
*spec
= codec
->spec
;
5246 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++)
5247 set_output_and_unmute(codec
, spec
->digout_paths
[i
]);
5248 pin
= spec
->autocfg
.dig_in_pin
;
5250 restore_pin_ctl(codec
, pin
);
5251 resume_path_from_idx(codec
, spec
->digin_path
);
5255 /* clear unsol-event tags on unused pins; Conexant codecs seem to leave
5256 * invalid unsol tags by some reason
5258 static void clear_unsol_on_unused_pins(struct hda_codec
*codec
)
5262 for (i
= 0; i
< codec
->init_pins
.used
; i
++) {
5263 struct hda_pincfg
*pin
= snd_array_elem(&codec
->init_pins
, i
);
5264 hda_nid_t nid
= pin
->nid
;
5265 if (is_jack_detectable(codec
, nid
) &&
5266 !snd_hda_jack_tbl_get(codec
, nid
))
5267 snd_hda_codec_update_cache(codec
, nid
, 0,
5268 AC_VERB_SET_UNSOLICITED_ENABLE
, 0);
5273 * initialize the generic spec;
5274 * this can be put as patch_ops.init function
5276 int snd_hda_gen_init(struct hda_codec
*codec
)
5278 struct hda_gen_spec
*spec
= codec
->spec
;
5280 if (spec
->init_hook
)
5281 spec
->init_hook(codec
);
5283 snd_hda_apply_verbs(codec
);
5285 codec
->cached_write
= 1;
5287 init_multi_out(codec
);
5288 init_extra_out(codec
);
5289 init_multi_io(codec
);
5290 init_analog_input(codec
);
5291 init_input_src(codec
);
5292 init_digital(codec
);
5294 clear_unsol_on_unused_pins(codec
);
5296 /* call init functions of standard auto-mute helpers */
5297 update_automute_all(codec
);
5299 snd_hda_codec_flush_cache(codec
);
5301 if (spec
->vmaster_mute
.sw_kctl
&& spec
->vmaster_mute
.hook
)
5302 snd_hda_sync_vmaster_hook(&spec
->vmaster_mute
);
5304 hda_call_check_power_status(codec
, 0x01);
5307 EXPORT_SYMBOL_HDA(snd_hda_gen_init
);
5310 * free the generic spec;
5311 * this can be put as patch_ops.free function
5313 void snd_hda_gen_free(struct hda_codec
*codec
)
5315 snd_hda_detach_beep_device(codec
);
5316 snd_hda_gen_spec_free(codec
->spec
);
5320 EXPORT_SYMBOL_HDA(snd_hda_gen_free
);
5324 * check the loopback power save state;
5325 * this can be put as patch_ops.check_power_status function
5327 int snd_hda_gen_check_power_status(struct hda_codec
*codec
, hda_nid_t nid
)
5329 struct hda_gen_spec
*spec
= codec
->spec
;
5330 return snd_hda_check_amp_list_power(codec
, &spec
->loopback
, nid
);
5332 EXPORT_SYMBOL_HDA(snd_hda_gen_check_power_status
);
5337 * the generic codec support
5340 static const struct hda_codec_ops generic_patch_ops
= {
5341 .build_controls
= snd_hda_gen_build_controls
,
5342 .build_pcms
= snd_hda_gen_build_pcms
,
5343 .init
= snd_hda_gen_init
,
5344 .free
= snd_hda_gen_free
,
5345 .unsol_event
= snd_hda_jack_unsol_event
,
5347 .check_power_status
= snd_hda_gen_check_power_status
,
5351 int snd_hda_parse_generic_codec(struct hda_codec
*codec
)
5353 struct hda_gen_spec
*spec
;
5356 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
5359 snd_hda_gen_spec_init(spec
);
5362 err
= snd_hda_parse_pin_defcfg(codec
, &spec
->autocfg
, NULL
, 0);
5366 err
= snd_hda_gen_parse_auto_config(codec
, &spec
->autocfg
);
5370 codec
->patch_ops
= generic_patch_ops
;
5374 snd_hda_gen_free(codec
);
5377 EXPORT_SYMBOL_HDA(snd_hda_parse_generic_codec
);