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 <linux/module.h>
32 #include <sound/core.h>
33 #include <sound/jack.h>
34 #include <sound/tlv.h>
35 #include "hda_codec.h"
36 #include "hda_local.h"
37 #include "hda_auto_parser.h"
40 #include "hda_generic.h"
44 * snd_hda_gen_spec_init - initialize hda_gen_spec struct
45 * @spec: hda_gen_spec object to initialize
47 * Initialize the given hda_gen_spec object.
49 int snd_hda_gen_spec_init(struct hda_gen_spec
*spec
)
51 snd_array_init(&spec
->kctls
, sizeof(struct snd_kcontrol_new
), 32);
52 snd_array_init(&spec
->paths
, sizeof(struct nid_path
), 8);
53 snd_array_init(&spec
->loopback_list
, sizeof(struct hda_amp_list
), 8);
54 mutex_init(&spec
->pcm_mutex
);
57 EXPORT_SYMBOL_GPL(snd_hda_gen_spec_init
);
60 * snd_hda_gen_add_kctl - Add a new kctl_new struct from the template
61 * @spec: hda_gen_spec object
62 * @name: name string to override the template, NULL if unchanged
63 * @temp: template for the new kctl
65 * Add a new kctl (actually snd_kcontrol_new to be instantiated later)
66 * element based on the given snd_kcontrol_new template @temp and the
67 * name string @name to the list in @spec.
68 * Returns the newly created object or NULL as error.
70 struct snd_kcontrol_new
*
71 snd_hda_gen_add_kctl(struct hda_gen_spec
*spec
, const char *name
,
72 const struct snd_kcontrol_new
*temp
)
74 struct snd_kcontrol_new
*knew
= snd_array_new(&spec
->kctls
);
79 knew
->name
= kstrdup(name
, GFP_KERNEL
);
81 knew
->name
= kstrdup(knew
->name
, GFP_KERNEL
);
86 EXPORT_SYMBOL_GPL(snd_hda_gen_add_kctl
);
88 static void free_kctls(struct hda_gen_spec
*spec
)
90 if (spec
->kctls
.list
) {
91 struct snd_kcontrol_new
*kctl
= spec
->kctls
.list
;
93 for (i
= 0; i
< spec
->kctls
.used
; i
++)
96 snd_array_free(&spec
->kctls
);
99 static void snd_hda_gen_spec_free(struct hda_gen_spec
*spec
)
104 snd_array_free(&spec
->paths
);
105 snd_array_free(&spec
->loopback_list
);
111 static void parse_user_hints(struct hda_codec
*codec
)
113 struct hda_gen_spec
*spec
= codec
->spec
;
116 val
= snd_hda_get_bool_hint(codec
, "jack_detect");
118 codec
->no_jack_detect
= !val
;
119 val
= snd_hda_get_bool_hint(codec
, "inv_jack_detect");
121 codec
->inv_jack_detect
= !!val
;
122 val
= snd_hda_get_bool_hint(codec
, "trigger_sense");
124 codec
->no_trigger_sense
= !val
;
125 val
= snd_hda_get_bool_hint(codec
, "inv_eapd");
127 codec
->inv_eapd
= !!val
;
128 val
= snd_hda_get_bool_hint(codec
, "pcm_format_first");
130 codec
->pcm_format_first
= !!val
;
131 val
= snd_hda_get_bool_hint(codec
, "sticky_stream");
133 codec
->no_sticky_stream
= !val
;
134 val
= snd_hda_get_bool_hint(codec
, "spdif_status_reset");
136 codec
->spdif_status_reset
= !!val
;
137 val
= snd_hda_get_bool_hint(codec
, "pin_amp_workaround");
139 codec
->pin_amp_workaround
= !!val
;
140 val
= snd_hda_get_bool_hint(codec
, "single_adc_amp");
142 codec
->single_adc_amp
= !!val
;
143 val
= snd_hda_get_bool_hint(codec
, "power_save_node");
145 codec
->power_save_node
= !!val
;
147 val
= snd_hda_get_bool_hint(codec
, "auto_mute");
149 spec
->suppress_auto_mute
= !val
;
150 val
= snd_hda_get_bool_hint(codec
, "auto_mic");
152 spec
->suppress_auto_mic
= !val
;
153 val
= snd_hda_get_bool_hint(codec
, "line_in_auto_switch");
155 spec
->line_in_auto_switch
= !!val
;
156 val
= snd_hda_get_bool_hint(codec
, "auto_mute_via_amp");
158 spec
->auto_mute_via_amp
= !!val
;
159 val
= snd_hda_get_bool_hint(codec
, "need_dac_fix");
161 spec
->need_dac_fix
= !!val
;
162 val
= snd_hda_get_bool_hint(codec
, "primary_hp");
164 spec
->no_primary_hp
= !val
;
165 val
= snd_hda_get_bool_hint(codec
, "multi_io");
167 spec
->no_multi_io
= !val
;
168 val
= snd_hda_get_bool_hint(codec
, "multi_cap_vol");
170 spec
->multi_cap_vol
= !!val
;
171 val
= snd_hda_get_bool_hint(codec
, "inv_dmic_split");
173 spec
->inv_dmic_split
= !!val
;
174 val
= snd_hda_get_bool_hint(codec
, "indep_hp");
176 spec
->indep_hp
= !!val
;
177 val
= snd_hda_get_bool_hint(codec
, "add_stereo_mix_input");
179 spec
->add_stereo_mix_input
= !!val
;
180 /* the following two are just for compatibility */
181 val
= snd_hda_get_bool_hint(codec
, "add_out_jack_modes");
183 spec
->add_jack_modes
= !!val
;
184 val
= snd_hda_get_bool_hint(codec
, "add_in_jack_modes");
186 spec
->add_jack_modes
= !!val
;
187 val
= snd_hda_get_bool_hint(codec
, "add_jack_modes");
189 spec
->add_jack_modes
= !!val
;
190 val
= snd_hda_get_bool_hint(codec
, "power_down_unused");
192 spec
->power_down_unused
= !!val
;
193 val
= snd_hda_get_bool_hint(codec
, "add_hp_mic");
195 spec
->hp_mic
= !!val
;
196 val
= snd_hda_get_bool_hint(codec
, "hp_mic_detect");
198 spec
->suppress_hp_mic_detect
= !val
;
200 if (!snd_hda_get_int_hint(codec
, "mixer_nid", &val
))
201 spec
->mixer_nid
= val
;
205 * pin control value accesses
208 #define update_pin_ctl(codec, pin, val) \
209 snd_hda_codec_update_cache(codec, pin, 0, \
210 AC_VERB_SET_PIN_WIDGET_CONTROL, val)
212 /* restore the pinctl based on the cached value */
213 static inline void restore_pin_ctl(struct hda_codec
*codec
, hda_nid_t pin
)
215 update_pin_ctl(codec
, pin
, snd_hda_codec_get_pin_target(codec
, pin
));
218 /* set the pinctl target value and write it if requested */
219 static void set_pin_target(struct hda_codec
*codec
, hda_nid_t pin
,
220 unsigned int val
, bool do_write
)
224 val
= snd_hda_correct_pin_ctl(codec
, pin
, val
);
225 snd_hda_codec_set_pin_target(codec
, pin
, val
);
227 update_pin_ctl(codec
, pin
, val
);
230 /* set pinctl target values for all given pins */
231 static void set_pin_targets(struct hda_codec
*codec
, int num_pins
,
232 hda_nid_t
*pins
, unsigned int val
)
235 for (i
= 0; i
< num_pins
; i
++)
236 set_pin_target(codec
, pins
[i
], val
, false);
243 /* return the position of NID in the list, or -1 if not found */
244 static int find_idx_in_nid_list(hda_nid_t nid
, const hda_nid_t
*list
, int nums
)
247 for (i
= 0; i
< nums
; i
++)
253 /* return true if the given NID is contained in the path */
254 static bool is_nid_contained(struct nid_path
*path
, hda_nid_t nid
)
256 return find_idx_in_nid_list(nid
, path
->path
, path
->depth
) >= 0;
259 static struct nid_path
*get_nid_path(struct hda_codec
*codec
,
260 hda_nid_t from_nid
, hda_nid_t to_nid
,
263 struct hda_gen_spec
*spec
= codec
->spec
;
266 for (i
= 0; i
< spec
->paths
.used
; i
++) {
267 struct nid_path
*path
= snd_array_elem(&spec
->paths
, i
);
268 if (path
->depth
<= 0)
270 if ((!from_nid
|| path
->path
[0] == from_nid
) &&
271 (!to_nid
|| path
->path
[path
->depth
- 1] == to_nid
)) {
273 (anchor_nid
> 0 && is_nid_contained(path
, anchor_nid
)) ||
274 (anchor_nid
< 0 && !is_nid_contained(path
, anchor_nid
)))
282 * snd_hda_get_nid_path - get the path between the given NIDs
283 * @codec: the HDA codec
284 * @from_nid: the NID where the path start from
285 * @to_nid: the NID where the path ends at
287 * Return the found nid_path object or NULL for error.
288 * Passing 0 to either @from_nid or @to_nid behaves as a wildcard.
290 struct nid_path
*snd_hda_get_nid_path(struct hda_codec
*codec
,
291 hda_nid_t from_nid
, hda_nid_t to_nid
)
293 return get_nid_path(codec
, from_nid
, to_nid
, 0);
295 EXPORT_SYMBOL_GPL(snd_hda_get_nid_path
);
298 * snd_hda_get_path_idx - get the index number corresponding to the path
300 * @codec: the HDA codec
301 * @path: nid_path object
303 * The returned index starts from 1, i.e. the actual array index with offset 1,
304 * and zero is handled as an invalid path
306 int snd_hda_get_path_idx(struct hda_codec
*codec
, struct nid_path
*path
)
308 struct hda_gen_spec
*spec
= codec
->spec
;
309 struct nid_path
*array
= spec
->paths
.list
;
312 if (!spec
->paths
.used
)
315 if (idx
< 0 || idx
>= spec
->paths
.used
)
319 EXPORT_SYMBOL_GPL(snd_hda_get_path_idx
);
322 * snd_hda_get_path_from_idx - get the path instance corresponding to the
324 * @codec: the HDA codec
325 * @idx: the path index
327 struct nid_path
*snd_hda_get_path_from_idx(struct hda_codec
*codec
, int idx
)
329 struct hda_gen_spec
*spec
= codec
->spec
;
331 if (idx
<= 0 || idx
> spec
->paths
.used
)
333 return snd_array_elem(&spec
->paths
, idx
- 1);
335 EXPORT_SYMBOL_GPL(snd_hda_get_path_from_idx
);
337 /* check whether the given DAC is already found in any existing paths */
338 static bool is_dac_already_used(struct hda_codec
*codec
, hda_nid_t nid
)
340 struct hda_gen_spec
*spec
= codec
->spec
;
343 for (i
= 0; i
< spec
->paths
.used
; i
++) {
344 struct nid_path
*path
= snd_array_elem(&spec
->paths
, i
);
345 if (path
->path
[0] == nid
)
351 /* check whether the given two widgets can be connected */
352 static bool is_reachable_path(struct hda_codec
*codec
,
353 hda_nid_t from_nid
, hda_nid_t to_nid
)
355 if (!from_nid
|| !to_nid
)
357 return snd_hda_get_conn_index(codec
, to_nid
, from_nid
, true) >= 0;
360 /* nid, dir and idx */
361 #define AMP_VAL_COMPARE_MASK (0xffff | (1U << 18) | (0x0f << 19))
363 /* check whether the given ctl is already assigned in any path elements */
364 static bool is_ctl_used(struct hda_codec
*codec
, unsigned int val
, int type
)
366 struct hda_gen_spec
*spec
= codec
->spec
;
369 val
&= AMP_VAL_COMPARE_MASK
;
370 for (i
= 0; i
< spec
->paths
.used
; i
++) {
371 struct nid_path
*path
= snd_array_elem(&spec
->paths
, i
);
372 if ((path
->ctls
[type
] & AMP_VAL_COMPARE_MASK
) == val
)
378 /* check whether a control with the given (nid, dir, idx) was assigned */
379 static bool is_ctl_associated(struct hda_codec
*codec
, hda_nid_t nid
,
380 int dir
, int idx
, int type
)
382 unsigned int val
= HDA_COMPOSE_AMP_VAL(nid
, 3, idx
, dir
);
383 return is_ctl_used(codec
, val
, type
);
386 static void print_nid_path(struct hda_codec
*codec
,
387 const char *pfx
, struct nid_path
*path
)
394 for (i
= 0; i
< path
->depth
; i
++)
395 pos
+= scnprintf(pos
, sizeof(buf
) - (pos
- buf
), "%s%02x",
396 pos
!= buf
? ":" : "",
399 codec_dbg(codec
, "%s path: depth=%d '%s'\n", pfx
, path
->depth
, buf
);
402 /* called recursively */
403 static bool __parse_nid_path(struct hda_codec
*codec
,
404 hda_nid_t from_nid
, hda_nid_t to_nid
,
405 int anchor_nid
, struct nid_path
*path
,
408 const hda_nid_t
*conn
;
411 if (to_nid
== anchor_nid
)
412 anchor_nid
= 0; /* anchor passed */
413 else if (to_nid
== (hda_nid_t
)(-anchor_nid
))
414 return false; /* hit the exclusive nid */
416 nums
= snd_hda_get_conn_list(codec
, to_nid
, &conn
);
417 for (i
= 0; i
< nums
; i
++) {
418 if (conn
[i
] != from_nid
) {
419 /* special case: when from_nid is 0,
420 * try to find an empty DAC
423 get_wcaps_type(get_wcaps(codec
, conn
[i
])) != AC_WID_AUD_OUT
||
424 is_dac_already_used(codec
, conn
[i
]))
427 /* anchor is not requested or already passed? */
431 if (depth
>= MAX_NID_PATH_DEPTH
)
433 for (i
= 0; i
< nums
; i
++) {
435 type
= get_wcaps_type(get_wcaps(codec
, conn
[i
]));
436 if (type
== AC_WID_AUD_OUT
|| type
== AC_WID_AUD_IN
||
439 if (__parse_nid_path(codec
, from_nid
, conn
[i
],
440 anchor_nid
, path
, depth
+ 1))
446 path
->path
[path
->depth
] = conn
[i
];
447 path
->idx
[path
->depth
+ 1] = i
;
448 if (nums
> 1 && get_wcaps_type(get_wcaps(codec
, to_nid
)) != AC_WID_AUD_MIX
)
449 path
->multi
[path
->depth
+ 1] = 1;
455 * snd_hda_parse_nid_path - parse the widget path from the given nid to
457 * @codec: the HDA codec
458 * @from_nid: the NID where the path start from
459 * @to_nid: the NID where the path ends at
460 * @anchor_nid: the anchor indication
461 * @path: the path object to store the result
463 * Returns true if a matching path is found.
465 * The parsing behavior depends on parameters:
466 * when @from_nid is 0, try to find an empty DAC;
467 * when @anchor_nid is set to a positive value, only paths through the widget
468 * with the given value are evaluated.
469 * when @anchor_nid is set to a negative value, paths through the widget
470 * with the negative of given value are excluded, only other paths are chosen.
471 * when @anchor_nid is zero, no special handling about path selection.
473 bool snd_hda_parse_nid_path(struct hda_codec
*codec
, hda_nid_t from_nid
,
474 hda_nid_t to_nid
, int anchor_nid
,
475 struct nid_path
*path
)
477 if (__parse_nid_path(codec
, from_nid
, to_nid
, anchor_nid
, path
, 1)) {
478 path
->path
[path
->depth
] = to_nid
;
484 EXPORT_SYMBOL_GPL(snd_hda_parse_nid_path
);
487 * snd_hda_add_new_path - parse the path between the given NIDs and
488 * add to the path list
489 * @codec: the HDA codec
490 * @from_nid: the NID where the path start from
491 * @to_nid: the NID where the path ends at
492 * @anchor_nid: the anchor indication, see snd_hda_parse_nid_path()
494 * If no valid path is found, returns NULL.
497 snd_hda_add_new_path(struct hda_codec
*codec
, hda_nid_t from_nid
,
498 hda_nid_t to_nid
, int anchor_nid
)
500 struct hda_gen_spec
*spec
= codec
->spec
;
501 struct nid_path
*path
;
503 if (from_nid
&& to_nid
&& !is_reachable_path(codec
, from_nid
, to_nid
))
506 /* check whether the path has been already added */
507 path
= get_nid_path(codec
, from_nid
, to_nid
, anchor_nid
);
511 path
= snd_array_new(&spec
->paths
);
514 memset(path
, 0, sizeof(*path
));
515 if (snd_hda_parse_nid_path(codec
, from_nid
, to_nid
, anchor_nid
, path
))
521 EXPORT_SYMBOL_GPL(snd_hda_add_new_path
);
523 /* clear the given path as invalid so that it won't be picked up later */
524 static void invalidate_nid_path(struct hda_codec
*codec
, int idx
)
526 struct nid_path
*path
= snd_hda_get_path_from_idx(codec
, idx
);
529 memset(path
, 0, sizeof(*path
));
532 /* return a DAC if paired to the given pin by codec driver */
533 static hda_nid_t
get_preferred_dac(struct hda_codec
*codec
, hda_nid_t pin
)
535 struct hda_gen_spec
*spec
= codec
->spec
;
536 const hda_nid_t
*list
= spec
->preferred_dacs
;
540 for (; *list
; list
+= 2)
546 /* look for an empty DAC slot */
547 static hda_nid_t
look_for_dac(struct hda_codec
*codec
, hda_nid_t pin
,
550 struct hda_gen_spec
*spec
= codec
->spec
;
554 for (i
= 0; i
< spec
->num_all_dacs
; i
++) {
555 hda_nid_t nid
= spec
->all_dacs
[i
];
556 if (!nid
|| is_dac_already_used(codec
, nid
))
558 cap_digital
= !!(get_wcaps(codec
, nid
) & AC_WCAP_DIGITAL
);
559 if (is_digital
!= cap_digital
)
561 if (is_reachable_path(codec
, nid
, pin
))
567 /* replace the channels in the composed amp value with the given number */
568 static unsigned int amp_val_replace_channels(unsigned int val
, unsigned int chs
)
570 val
&= ~(0x3U
<< 16);
575 static bool same_amp_caps(struct hda_codec
*codec
, hda_nid_t nid1
,
576 hda_nid_t nid2
, int dir
)
578 if (!(get_wcaps(codec
, nid1
) & (1 << (dir
+ 1))))
579 return !(get_wcaps(codec
, nid2
) & (1 << (dir
+ 1)));
580 return (query_amp_caps(codec
, nid1
, dir
) ==
581 query_amp_caps(codec
, nid2
, dir
));
584 /* look for a widget suitable for assigning a mute switch in the path */
585 static hda_nid_t
look_for_out_mute_nid(struct hda_codec
*codec
,
586 struct nid_path
*path
)
590 for (i
= path
->depth
- 1; i
>= 0; i
--) {
591 if (nid_has_mute(codec
, path
->path
[i
], HDA_OUTPUT
))
592 return path
->path
[i
];
593 if (i
!= path
->depth
- 1 && i
!= 0 &&
594 nid_has_mute(codec
, path
->path
[i
], HDA_INPUT
))
595 return path
->path
[i
];
600 /* look for a widget suitable for assigning a volume ctl in the path */
601 static hda_nid_t
look_for_out_vol_nid(struct hda_codec
*codec
,
602 struct nid_path
*path
)
604 struct hda_gen_spec
*spec
= codec
->spec
;
607 for (i
= path
->depth
- 1; i
>= 0; i
--) {
608 hda_nid_t nid
= path
->path
[i
];
609 if ((spec
->out_vol_mask
>> nid
) & 1)
611 if (nid_has_volume(codec
, nid
, HDA_OUTPUT
))
618 * path activation / deactivation
621 /* can have the amp-in capability? */
622 static bool has_amp_in(struct hda_codec
*codec
, struct nid_path
*path
, int idx
)
624 hda_nid_t nid
= path
->path
[idx
];
625 unsigned int caps
= get_wcaps(codec
, nid
);
626 unsigned int type
= get_wcaps_type(caps
);
628 if (!(caps
& AC_WCAP_IN_AMP
))
630 if (type
== AC_WID_PIN
&& idx
> 0) /* only for input pins */
635 /* can have the amp-out capability? */
636 static bool has_amp_out(struct hda_codec
*codec
, struct nid_path
*path
, int idx
)
638 hda_nid_t nid
= path
->path
[idx
];
639 unsigned int caps
= get_wcaps(codec
, nid
);
640 unsigned int type
= get_wcaps_type(caps
);
642 if (!(caps
& AC_WCAP_OUT_AMP
))
644 if (type
== AC_WID_PIN
&& !idx
) /* only for output pins */
649 /* check whether the given (nid,dir,idx) is active */
650 static bool is_active_nid(struct hda_codec
*codec
, hda_nid_t nid
,
651 unsigned int dir
, unsigned int idx
)
653 struct hda_gen_spec
*spec
= codec
->spec
;
654 int type
= get_wcaps_type(get_wcaps(codec
, nid
));
657 if (nid
== codec
->core
.afg
)
660 for (n
= 0; n
< spec
->paths
.used
; n
++) {
661 struct nid_path
*path
= snd_array_elem(&spec
->paths
, n
);
664 if (codec
->power_save_node
) {
665 if (!path
->stream_enabled
)
667 /* ignore unplugged paths except for DAC/ADC */
668 if (!(path
->pin_enabled
|| path
->pin_fixed
) &&
669 type
!= AC_WID_AUD_OUT
&& type
!= AC_WID_AUD_IN
)
672 for (i
= 0; i
< path
->depth
; i
++) {
673 if (path
->path
[i
] == nid
) {
674 if (dir
== HDA_OUTPUT
|| idx
== -1 ||
684 /* check whether the NID is referred by any active paths */
685 #define is_active_nid_for_any(codec, nid) \
686 is_active_nid(codec, nid, HDA_OUTPUT, -1)
688 /* get the default amp value for the target state */
689 static int get_amp_val_to_activate(struct hda_codec
*codec
, hda_nid_t nid
,
690 int dir
, unsigned int caps
, bool enable
)
692 unsigned int val
= 0;
694 if (caps
& AC_AMPCAP_NUM_STEPS
) {
697 val
= (caps
& AC_AMPCAP_OFFSET
) >> AC_AMPCAP_OFFSET_SHIFT
;
699 if (caps
& (AC_AMPCAP_MUTE
| AC_AMPCAP_MIN_MUTE
)) {
706 /* is this a stereo widget or a stereo-to-mono mix? */
707 static bool is_stereo_amps(struct hda_codec
*codec
, hda_nid_t nid
, int dir
)
709 unsigned int wcaps
= get_wcaps(codec
, nid
);
712 if (wcaps
& AC_WCAP_STEREO
)
714 if (dir
!= HDA_INPUT
|| get_wcaps_type(wcaps
) != AC_WID_AUD_MIX
)
716 if (snd_hda_get_num_conns(codec
, nid
) != 1)
718 if (snd_hda_get_connections(codec
, nid
, &conn
, 1) < 0)
720 return !!(get_wcaps(codec
, conn
) & AC_WCAP_STEREO
);
723 /* initialize the amp value (only at the first time) */
724 static void init_amp(struct hda_codec
*codec
, hda_nid_t nid
, int dir
, int idx
)
726 unsigned int caps
= query_amp_caps(codec
, nid
, dir
);
727 int val
= get_amp_val_to_activate(codec
, nid
, dir
, caps
, false);
729 if (is_stereo_amps(codec
, nid
, dir
))
730 snd_hda_codec_amp_init_stereo(codec
, nid
, dir
, idx
, 0xff, val
);
732 snd_hda_codec_amp_init(codec
, nid
, 0, dir
, idx
, 0xff, val
);
735 /* update the amp, doing in stereo or mono depending on NID */
736 static int update_amp(struct hda_codec
*codec
, hda_nid_t nid
, int dir
, int idx
,
737 unsigned int mask
, unsigned int val
)
739 if (is_stereo_amps(codec
, nid
, dir
))
740 return snd_hda_codec_amp_stereo(codec
, nid
, dir
, idx
,
743 return snd_hda_codec_amp_update(codec
, nid
, 0, dir
, idx
,
747 /* calculate amp value mask we can modify;
748 * if the given amp is controlled by mixers, don't touch it
750 static unsigned int get_amp_mask_to_modify(struct hda_codec
*codec
,
751 hda_nid_t nid
, int dir
, int idx
,
754 unsigned int mask
= 0xff;
756 if (caps
& (AC_AMPCAP_MUTE
| AC_AMPCAP_MIN_MUTE
)) {
757 if (is_ctl_associated(codec
, nid
, dir
, idx
, NID_PATH_MUTE_CTL
))
760 if (caps
& AC_AMPCAP_NUM_STEPS
) {
761 if (is_ctl_associated(codec
, nid
, dir
, idx
, NID_PATH_VOL_CTL
) ||
762 is_ctl_associated(codec
, nid
, dir
, idx
, NID_PATH_BOOST_CTL
))
768 static void activate_amp(struct hda_codec
*codec
, hda_nid_t nid
, int dir
,
769 int idx
, int idx_to_check
, bool enable
)
772 unsigned int mask
, val
;
774 if (!enable
&& is_active_nid(codec
, nid
, dir
, idx_to_check
))
777 caps
= query_amp_caps(codec
, nid
, dir
);
778 val
= get_amp_val_to_activate(codec
, nid
, dir
, caps
, enable
);
779 mask
= get_amp_mask_to_modify(codec
, nid
, dir
, idx_to_check
, caps
);
784 update_amp(codec
, nid
, dir
, idx
, mask
, val
);
787 static void activate_amp_out(struct hda_codec
*codec
, struct nid_path
*path
,
790 hda_nid_t nid
= path
->path
[i
];
791 init_amp(codec
, nid
, HDA_OUTPUT
, 0);
792 activate_amp(codec
, nid
, HDA_OUTPUT
, 0, 0, enable
);
795 static void activate_amp_in(struct hda_codec
*codec
, struct nid_path
*path
,
796 int i
, bool enable
, bool add_aamix
)
798 struct hda_gen_spec
*spec
= codec
->spec
;
799 const hda_nid_t
*conn
;
802 hda_nid_t nid
= path
->path
[i
];
804 nums
= snd_hda_get_conn_list(codec
, nid
, &conn
);
805 type
= get_wcaps_type(get_wcaps(codec
, nid
));
806 if (type
== AC_WID_PIN
||
807 (type
== AC_WID_AUD_IN
&& codec
->single_adc_amp
)) {
813 for (n
= 0; n
< nums
; n
++)
814 init_amp(codec
, nid
, HDA_INPUT
, n
);
816 /* here is a little bit tricky in comparison with activate_amp_out();
817 * when aa-mixer is available, we need to enable the path as well
819 for (n
= 0; n
< nums
; n
++) {
820 if (n
!= idx
&& (!add_aamix
|| conn
[n
] != spec
->mixer_merge_nid
))
822 activate_amp(codec
, nid
, HDA_INPUT
, n
, idx
, enable
);
826 /* sync power of each widget in the the given path */
827 static hda_nid_t
path_power_update(struct hda_codec
*codec
,
828 struct nid_path
*path
,
829 bool allow_powerdown
)
831 hda_nid_t nid
, changed
= 0;
834 for (i
= 0; i
< path
->depth
; i
++) {
836 if (!(get_wcaps(codec
, nid
) & AC_WCAP_POWER
))
838 if (nid
== codec
->core
.afg
)
840 if (!allow_powerdown
|| is_active_nid_for_any(codec
, nid
))
844 if (!snd_hda_check_power_state(codec
, nid
, state
)) {
845 snd_hda_codec_write(codec
, nid
, 0,
846 AC_VERB_SET_POWER_STATE
, state
);
848 /* all known codecs seem to be capable to handl
849 * widgets state even in D3, so far.
850 * if any new codecs need to restore the widget
851 * states after D0 transition, call the function
855 if (state
== AC_PWRST_D0
)
856 snd_hdac_regmap_sync_node(&codec
->core
, nid
);
863 /* do sync with the last power state change */
864 static void sync_power_state_change(struct hda_codec
*codec
, hda_nid_t nid
)
868 snd_hda_codec_read(codec
, nid
, 0, AC_VERB_GET_POWER_STATE
, 0);
873 * snd_hda_activate_path - activate or deactivate the given path
874 * @codec: the HDA codec
875 * @path: the path to activate/deactivate
876 * @enable: flag to activate or not
877 * @add_aamix: enable the input from aamix NID
879 * If @add_aamix is set, enable the input from aa-mix NID as well (if any).
881 void snd_hda_activate_path(struct hda_codec
*codec
, struct nid_path
*path
,
882 bool enable
, bool add_aamix
)
884 struct hda_gen_spec
*spec
= codec
->spec
;
887 path
->active
= enable
;
889 /* make sure the widget is powered up */
890 if (enable
&& (spec
->power_down_unused
|| codec
->power_save_node
))
891 path_power_update(codec
, path
, codec
->power_save_node
);
893 for (i
= path
->depth
- 1; i
>= 0; i
--) {
894 hda_nid_t nid
= path
->path
[i
];
896 if (enable
&& path
->multi
[i
])
897 snd_hda_codec_update_cache(codec
, nid
, 0,
898 AC_VERB_SET_CONNECT_SEL
,
900 if (has_amp_in(codec
, path
, i
))
901 activate_amp_in(codec
, path
, i
, enable
, add_aamix
);
902 if (has_amp_out(codec
, path
, i
))
903 activate_amp_out(codec
, path
, i
, enable
);
906 EXPORT_SYMBOL_GPL(snd_hda_activate_path
);
908 /* if the given path is inactive, put widgets into D3 (only if suitable) */
909 static void path_power_down_sync(struct hda_codec
*codec
, struct nid_path
*path
)
911 struct hda_gen_spec
*spec
= codec
->spec
;
913 if (!(spec
->power_down_unused
|| codec
->power_save_node
) || path
->active
)
915 sync_power_state_change(codec
, path_power_update(codec
, path
, true));
918 /* turn on/off EAPD on the given pin */
919 static void set_pin_eapd(struct hda_codec
*codec
, hda_nid_t pin
, bool enable
)
921 struct hda_gen_spec
*spec
= codec
->spec
;
922 if (spec
->own_eapd_ctl
||
923 !(snd_hda_query_pin_caps(codec
, pin
) & AC_PINCAP_EAPD
))
925 if (spec
->keep_eapd_on
&& !enable
)
929 snd_hda_codec_update_cache(codec
, pin
, 0,
930 AC_VERB_SET_EAPD_BTLENABLE
,
931 enable
? 0x02 : 0x00);
934 /* re-initialize the path specified by the given path index */
935 static void resume_path_from_idx(struct hda_codec
*codec
, int path_idx
)
937 struct nid_path
*path
= snd_hda_get_path_from_idx(codec
, path_idx
);
939 snd_hda_activate_path(codec
, path
, path
->active
, false);
944 * Helper functions for creating mixer ctl elements
947 static int hda_gen_mixer_mute_put(struct snd_kcontrol
*kcontrol
,
948 struct snd_ctl_elem_value
*ucontrol
);
949 static int hda_gen_bind_mute_put(struct snd_kcontrol
*kcontrol
,
950 struct snd_ctl_elem_value
*ucontrol
);
957 static const struct snd_kcontrol_new control_templates
[] = {
958 HDA_CODEC_VOLUME(NULL
, 0, 0, 0),
959 /* only the put callback is replaced for handling the special mute */
961 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
962 .subdevice
= HDA_SUBDEV_AMP_FLAG
,
963 .info
= snd_hda_mixer_amp_switch_info
,
964 .get
= snd_hda_mixer_amp_switch_get
,
965 .put
= hda_gen_mixer_mute_put
, /* replaced */
966 .private_value
= HDA_COMPOSE_AMP_VAL(0, 3, 0, 0),
969 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
970 .info
= snd_hda_mixer_amp_switch_info
,
971 .get
= snd_hda_mixer_bind_switch_get
,
972 .put
= hda_gen_bind_mute_put
, /* replaced */
973 .private_value
= HDA_COMPOSE_AMP_VAL(0, 3, 0, 0),
977 /* add dynamic controls from template */
978 static struct snd_kcontrol_new
*
979 add_control(struct hda_gen_spec
*spec
, int type
, const char *name
,
980 int cidx
, unsigned long val
)
982 struct snd_kcontrol_new
*knew
;
984 knew
= snd_hda_gen_add_kctl(spec
, name
, &control_templates
[type
]);
988 if (get_amp_nid_(val
))
989 knew
->subdevice
= HDA_SUBDEV_AMP_FLAG
;
990 knew
->private_value
= val
;
994 static int add_control_with_pfx(struct hda_gen_spec
*spec
, int type
,
995 const char *pfx
, const char *dir
,
996 const char *sfx
, int cidx
, unsigned long val
)
998 char name
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
999 snprintf(name
, sizeof(name
), "%s %s %s", pfx
, dir
, sfx
);
1000 if (!add_control(spec
, type
, name
, cidx
, val
))
1005 #define add_pb_vol_ctrl(spec, type, pfx, val) \
1006 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
1007 #define add_pb_sw_ctrl(spec, type, pfx, val) \
1008 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
1009 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
1010 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
1011 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
1012 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
1014 static int add_vol_ctl(struct hda_codec
*codec
, const char *pfx
, int cidx
,
1015 unsigned int chs
, struct nid_path
*path
)
1020 val
= path
->ctls
[NID_PATH_VOL_CTL
];
1023 val
= amp_val_replace_channels(val
, chs
);
1024 return __add_pb_vol_ctrl(codec
->spec
, HDA_CTL_WIDGET_VOL
, pfx
, cidx
, val
);
1027 /* return the channel bits suitable for the given path->ctls[] */
1028 static int get_default_ch_nums(struct hda_codec
*codec
, struct nid_path
*path
,
1031 int chs
= 1; /* mono (left only) */
1033 hda_nid_t nid
= get_amp_nid_(path
->ctls
[type
]);
1034 if (nid
&& (get_wcaps(codec
, nid
) & AC_WCAP_STEREO
))
1035 chs
= 3; /* stereo */
1040 static int add_stereo_vol(struct hda_codec
*codec
, const char *pfx
, int cidx
,
1041 struct nid_path
*path
)
1043 int chs
= get_default_ch_nums(codec
, path
, NID_PATH_VOL_CTL
);
1044 return add_vol_ctl(codec
, pfx
, cidx
, chs
, path
);
1047 /* create a mute-switch for the given mixer widget;
1048 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
1050 static int add_sw_ctl(struct hda_codec
*codec
, const char *pfx
, int cidx
,
1051 unsigned int chs
, struct nid_path
*path
)
1054 int type
= HDA_CTL_WIDGET_MUTE
;
1058 val
= path
->ctls
[NID_PATH_MUTE_CTL
];
1061 val
= amp_val_replace_channels(val
, chs
);
1062 if (get_amp_direction_(val
) == HDA_INPUT
) {
1063 hda_nid_t nid
= get_amp_nid_(val
);
1064 int nums
= snd_hda_get_num_conns(codec
, nid
);
1066 type
= HDA_CTL_BIND_MUTE
;
1070 return __add_pb_sw_ctrl(codec
->spec
, type
, pfx
, cidx
, val
);
1073 static int add_stereo_sw(struct hda_codec
*codec
, const char *pfx
,
1074 int cidx
, struct nid_path
*path
)
1076 int chs
= get_default_ch_nums(codec
, path
, NID_PATH_MUTE_CTL
);
1077 return add_sw_ctl(codec
, pfx
, cidx
, chs
, path
);
1080 /* playback mute control with the software mute bit check */
1081 static void sync_auto_mute_bits(struct snd_kcontrol
*kcontrol
,
1082 struct snd_ctl_elem_value
*ucontrol
)
1084 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
1085 struct hda_gen_spec
*spec
= codec
->spec
;
1087 if (spec
->auto_mute_via_amp
) {
1088 hda_nid_t nid
= get_amp_nid(kcontrol
);
1089 bool enabled
= !((spec
->mute_bits
>> nid
) & 1);
1090 ucontrol
->value
.integer
.value
[0] &= enabled
;
1091 ucontrol
->value
.integer
.value
[1] &= enabled
;
1095 static int hda_gen_mixer_mute_put(struct snd_kcontrol
*kcontrol
,
1096 struct snd_ctl_elem_value
*ucontrol
)
1098 sync_auto_mute_bits(kcontrol
, ucontrol
);
1099 return snd_hda_mixer_amp_switch_put(kcontrol
, ucontrol
);
1102 static int hda_gen_bind_mute_put(struct snd_kcontrol
*kcontrol
,
1103 struct snd_ctl_elem_value
*ucontrol
)
1105 sync_auto_mute_bits(kcontrol
, ucontrol
);
1106 return snd_hda_mixer_bind_switch_put(kcontrol
, ucontrol
);
1109 /* any ctl assigned to the path with the given index? */
1110 static bool path_has_mixer(struct hda_codec
*codec
, int path_idx
, int ctl_type
)
1112 struct nid_path
*path
= snd_hda_get_path_from_idx(codec
, path_idx
);
1113 return path
&& path
->ctls
[ctl_type
];
1116 static const char * const channel_name
[4] = {
1117 "Front", "Surround", "CLFE", "Side"
1120 /* give some appropriate ctl name prefix for the given line out channel */
1121 static const char *get_line_out_pfx(struct hda_codec
*codec
, int ch
,
1122 int *index
, int ctl_type
)
1124 struct hda_gen_spec
*spec
= codec
->spec
;
1125 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1128 if (cfg
->line_outs
== 1 && !spec
->multi_ios
&&
1129 !cfg
->hp_outs
&& !cfg
->speaker_outs
)
1130 return spec
->vmaster_mute
.hook
? "PCM" : "Master";
1132 /* if there is really a single DAC used in the whole output paths,
1133 * use it master (or "PCM" if a vmaster hook is present)
1135 if (spec
->multiout
.num_dacs
== 1 && !spec
->mixer_nid
&&
1136 !spec
->multiout
.hp_out_nid
[0] && !spec
->multiout
.extra_out_nid
[0])
1137 return spec
->vmaster_mute
.hook
? "PCM" : "Master";
1139 /* multi-io channels */
1140 if (ch
>= cfg
->line_outs
)
1141 return channel_name
[ch
];
1143 switch (cfg
->line_out_type
) {
1144 case AUTO_PIN_SPEAKER_OUT
:
1145 /* if the primary channel vol/mute is shared with HP volume,
1146 * don't name it as Speaker
1148 if (!ch
&& cfg
->hp_outs
&&
1149 !path_has_mixer(codec
, spec
->hp_paths
[0], ctl_type
))
1151 if (cfg
->line_outs
== 1)
1153 if (cfg
->line_outs
== 2)
1154 return ch
? "Bass Speaker" : "Speaker";
1156 case AUTO_PIN_HP_OUT
:
1157 /* if the primary channel vol/mute is shared with spk volume,
1158 * don't name it as Headphone
1160 if (!ch
&& cfg
->speaker_outs
&&
1161 !path_has_mixer(codec
, spec
->speaker_paths
[0], ctl_type
))
1163 /* for multi-io case, only the primary out */
1164 if (ch
&& spec
->multi_ios
)
1168 case AUTO_PIN_LINE_OUT
:
1169 /* This deals with the case where we have two DACs and
1170 * one LO, one HP and one Speaker */
1171 if (!ch
&& cfg
->speaker_outs
&& cfg
->hp_outs
) {
1172 bool hp_lo_shared
= !path_has_mixer(codec
, spec
->hp_paths
[0], ctl_type
);
1173 bool spk_lo_shared
= !path_has_mixer(codec
, spec
->speaker_paths
[0], ctl_type
);
1174 if (hp_lo_shared
&& spk_lo_shared
)
1175 return spec
->vmaster_mute
.hook
? "PCM" : "Master";
1177 return "Headphone+LO";
1179 return "Speaker+LO";
1183 /* for a single channel output, we don't have to name the channel */
1184 if (cfg
->line_outs
== 1 && !spec
->multi_ios
)
1187 if (ch
>= ARRAY_SIZE(channel_name
)) {
1192 return channel_name
[ch
];
1196 * Parse output paths
1199 /* badness definition */
1201 /* No primary DAC is found for the main output */
1202 BAD_NO_PRIMARY_DAC
= 0x10000,
1203 /* No DAC is found for the extra output */
1204 BAD_NO_DAC
= 0x4000,
1205 /* No possible multi-ios */
1206 BAD_MULTI_IO
= 0x120,
1207 /* No individual DAC for extra output */
1208 BAD_NO_EXTRA_DAC
= 0x102,
1209 /* No individual DAC for extra surrounds */
1210 BAD_NO_EXTRA_SURR_DAC
= 0x101,
1211 /* Primary DAC shared with main surrounds */
1212 BAD_SHARED_SURROUND
= 0x100,
1213 /* No independent HP possible */
1214 BAD_NO_INDEP_HP
= 0x10,
1215 /* Primary DAC shared with main CLFE */
1216 BAD_SHARED_CLFE
= 0x10,
1217 /* Primary DAC shared with extra surrounds */
1218 BAD_SHARED_EXTRA_SURROUND
= 0x10,
1219 /* Volume widget is shared */
1220 BAD_SHARED_VOL
= 0x10,
1223 /* look for widgets in the given path which are appropriate for
1224 * volume and mute controls, and assign the values to ctls[].
1226 * When no appropriate widget is found in the path, the badness value
1227 * is incremented depending on the situation. The function returns the
1228 * total badness for both volume and mute controls.
1230 static int assign_out_path_ctls(struct hda_codec
*codec
, struct nid_path
*path
)
1232 struct hda_gen_spec
*spec
= codec
->spec
;
1238 return BAD_SHARED_VOL
* 2;
1240 if (path
->ctls
[NID_PATH_VOL_CTL
] ||
1241 path
->ctls
[NID_PATH_MUTE_CTL
])
1242 return 0; /* already evaluated */
1244 nid
= look_for_out_vol_nid(codec
, path
);
1246 val
= HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_OUTPUT
);
1247 if (spec
->dac_min_mute
)
1248 val
|= HDA_AMP_VAL_MIN_MUTE
;
1249 if (is_ctl_used(codec
, val
, NID_PATH_VOL_CTL
))
1250 badness
+= BAD_SHARED_VOL
;
1252 path
->ctls
[NID_PATH_VOL_CTL
] = val
;
1254 badness
+= BAD_SHARED_VOL
;
1255 nid
= look_for_out_mute_nid(codec
, path
);
1257 unsigned int wid_type
= get_wcaps_type(get_wcaps(codec
, nid
));
1258 if (wid_type
== AC_WID_PIN
|| wid_type
== AC_WID_AUD_OUT
||
1259 nid_has_mute(codec
, nid
, HDA_OUTPUT
))
1260 val
= HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_OUTPUT
);
1262 val
= HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_INPUT
);
1263 if (is_ctl_used(codec
, val
, NID_PATH_MUTE_CTL
))
1264 badness
+= BAD_SHARED_VOL
;
1266 path
->ctls
[NID_PATH_MUTE_CTL
] = val
;
1268 badness
+= BAD_SHARED_VOL
;
1272 const struct badness_table hda_main_out_badness
= {
1273 .no_primary_dac
= BAD_NO_PRIMARY_DAC
,
1274 .no_dac
= BAD_NO_DAC
,
1275 .shared_primary
= BAD_NO_PRIMARY_DAC
,
1276 .shared_surr
= BAD_SHARED_SURROUND
,
1277 .shared_clfe
= BAD_SHARED_CLFE
,
1278 .shared_surr_main
= BAD_SHARED_SURROUND
,
1280 EXPORT_SYMBOL_GPL(hda_main_out_badness
);
1282 const struct badness_table hda_extra_out_badness
= {
1283 .no_primary_dac
= BAD_NO_DAC
,
1284 .no_dac
= BAD_NO_DAC
,
1285 .shared_primary
= BAD_NO_EXTRA_DAC
,
1286 .shared_surr
= BAD_SHARED_EXTRA_SURROUND
,
1287 .shared_clfe
= BAD_SHARED_EXTRA_SURROUND
,
1288 .shared_surr_main
= BAD_NO_EXTRA_SURR_DAC
,
1290 EXPORT_SYMBOL_GPL(hda_extra_out_badness
);
1292 /* get the DAC of the primary output corresponding to the given array index */
1293 static hda_nid_t
get_primary_out(struct hda_codec
*codec
, int idx
)
1295 struct hda_gen_spec
*spec
= codec
->spec
;
1296 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1298 if (cfg
->line_outs
> idx
)
1299 return spec
->private_dac_nids
[idx
];
1300 idx
-= cfg
->line_outs
;
1301 if (spec
->multi_ios
> idx
)
1302 return spec
->multi_io
[idx
].dac
;
1306 /* return the DAC if it's reachable, otherwise zero */
1307 static inline hda_nid_t
try_dac(struct hda_codec
*codec
,
1308 hda_nid_t dac
, hda_nid_t pin
)
1310 return is_reachable_path(codec
, dac
, pin
) ? dac
: 0;
1313 /* try to assign DACs to pins and return the resultant badness */
1314 static int try_assign_dacs(struct hda_codec
*codec
, int num_outs
,
1315 const hda_nid_t
*pins
, hda_nid_t
*dacs
,
1317 const struct badness_table
*bad
)
1319 struct hda_gen_spec
*spec
= codec
->spec
;
1327 for (i
= 0; i
< num_outs
; i
++) {
1328 struct nid_path
*path
;
1329 hda_nid_t pin
= pins
[i
];
1331 path
= snd_hda_get_path_from_idx(codec
, path_idx
[i
]);
1333 badness
+= assign_out_path_ctls(codec
, path
);
1337 dacs
[i
] = get_preferred_dac(codec
, pin
);
1339 if (is_dac_already_used(codec
, dacs
[i
]))
1340 badness
+= bad
->shared_primary
;
1344 dacs
[i
] = look_for_dac(codec
, pin
, false);
1345 if (!dacs
[i
] && !i
) {
1346 /* try to steal the DAC of surrounds for the front */
1347 for (j
= 1; j
< num_outs
; j
++) {
1348 if (is_reachable_path(codec
, dacs
[j
], pin
)) {
1351 invalidate_nid_path(codec
, path_idx
[j
]);
1360 dac
= try_dac(codec
, get_primary_out(codec
, i
), pin
);
1362 dac
= try_dac(codec
, dacs
[0], pin
);
1364 dac
= try_dac(codec
, get_primary_out(codec
, i
), pin
);
1367 badness
+= bad
->shared_primary
;
1369 badness
+= bad
->shared_surr
;
1371 badness
+= bad
->shared_clfe
;
1372 } else if (is_reachable_path(codec
, spec
->private_dac_nids
[0], pin
)) {
1373 dac
= spec
->private_dac_nids
[0];
1374 badness
+= bad
->shared_surr_main
;
1376 badness
+= bad
->no_primary_dac
;
1378 badness
+= bad
->no_dac
;
1382 path
= snd_hda_add_new_path(codec
, dac
, pin
, -spec
->mixer_nid
);
1383 if (!path
&& !i
&& spec
->mixer_nid
) {
1384 /* try with aamix */
1385 path
= snd_hda_add_new_path(codec
, dac
, pin
, 0);
1389 badness
+= bad
->no_dac
;
1391 /* print_nid_path(codec, "output", path); */
1392 path
->active
= true;
1393 path_idx
[i
] = snd_hda_get_path_idx(codec
, path
);
1394 badness
+= assign_out_path_ctls(codec
, path
);
1401 /* return NID if the given pin has only a single connection to a certain DAC */
1402 static hda_nid_t
get_dac_if_single(struct hda_codec
*codec
, hda_nid_t pin
)
1404 struct hda_gen_spec
*spec
= codec
->spec
;
1406 hda_nid_t nid_found
= 0;
1408 for (i
= 0; i
< spec
->num_all_dacs
; i
++) {
1409 hda_nid_t nid
= spec
->all_dacs
[i
];
1410 if (!nid
|| is_dac_already_used(codec
, nid
))
1412 if (is_reachable_path(codec
, nid
, pin
)) {
1421 /* check whether the given pin can be a multi-io pin */
1422 static bool can_be_multiio_pin(struct hda_codec
*codec
,
1423 unsigned int location
, hda_nid_t nid
)
1425 unsigned int defcfg
, caps
;
1427 defcfg
= snd_hda_codec_get_pincfg(codec
, nid
);
1428 if (get_defcfg_connect(defcfg
) != AC_JACK_PORT_COMPLEX
)
1430 if (location
&& get_defcfg_location(defcfg
) != location
)
1432 caps
= snd_hda_query_pin_caps(codec
, nid
);
1433 if (!(caps
& AC_PINCAP_OUT
))
1438 /* count the number of input pins that are capable to be multi-io */
1439 static int count_multiio_pins(struct hda_codec
*codec
, hda_nid_t reference_pin
)
1441 struct hda_gen_spec
*spec
= codec
->spec
;
1442 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1443 unsigned int defcfg
= snd_hda_codec_get_pincfg(codec
, reference_pin
);
1444 unsigned int location
= get_defcfg_location(defcfg
);
1448 for (type
= AUTO_PIN_LINE_IN
; type
>= AUTO_PIN_MIC
; type
--) {
1449 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
1450 if (cfg
->inputs
[i
].type
!= type
)
1452 if (can_be_multiio_pin(codec
, location
,
1453 cfg
->inputs
[i
].pin
))
1463 * When hardwired is set, try to fill ony hardwired pins, and returns
1464 * zero if any pins are filled, non-zero if nothing found.
1465 * When hardwired is off, try to fill possible input pins, and returns
1466 * the badness value.
1468 static int fill_multi_ios(struct hda_codec
*codec
,
1469 hda_nid_t reference_pin
,
1472 struct hda_gen_spec
*spec
= codec
->spec
;
1473 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1474 int type
, i
, j
, num_pins
, old_pins
;
1475 unsigned int defcfg
= snd_hda_codec_get_pincfg(codec
, reference_pin
);
1476 unsigned int location
= get_defcfg_location(defcfg
);
1478 struct nid_path
*path
;
1480 old_pins
= spec
->multi_ios
;
1484 num_pins
= count_multiio_pins(codec
, reference_pin
);
1488 for (type
= AUTO_PIN_LINE_IN
; type
>= AUTO_PIN_MIC
; type
--) {
1489 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
1490 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
1493 if (cfg
->inputs
[i
].type
!= type
)
1495 if (!can_be_multiio_pin(codec
, location
, nid
))
1497 for (j
= 0; j
< spec
->multi_ios
; j
++) {
1498 if (nid
== spec
->multi_io
[j
].pin
)
1501 if (j
< spec
->multi_ios
)
1505 dac
= get_dac_if_single(codec
, nid
);
1507 dac
= look_for_dac(codec
, nid
, false);
1512 path
= snd_hda_add_new_path(codec
, dac
, nid
,
1518 /* print_nid_path(codec, "multiio", path); */
1519 spec
->multi_io
[spec
->multi_ios
].pin
= nid
;
1520 spec
->multi_io
[spec
->multi_ios
].dac
= dac
;
1521 spec
->out_paths
[cfg
->line_outs
+ spec
->multi_ios
] =
1522 snd_hda_get_path_idx(codec
, path
);
1524 if (spec
->multi_ios
>= 2)
1530 badness
= BAD_MULTI_IO
;
1531 if (old_pins
== spec
->multi_ios
) {
1533 return 1; /* nothing found */
1535 return badness
; /* no badness if nothing found */
1537 if (!hardwired
&& spec
->multi_ios
< 2) {
1538 /* cancel newly assigned paths */
1539 spec
->paths
.used
-= spec
->multi_ios
- old_pins
;
1540 spec
->multi_ios
= old_pins
;
1544 /* assign volume and mute controls */
1545 for (i
= old_pins
; i
< spec
->multi_ios
; i
++) {
1546 path
= snd_hda_get_path_from_idx(codec
, spec
->out_paths
[cfg
->line_outs
+ i
]);
1547 badness
+= assign_out_path_ctls(codec
, path
);
1553 /* map DACs for all pins in the list if they are single connections */
1554 static bool map_singles(struct hda_codec
*codec
, int outs
,
1555 const hda_nid_t
*pins
, hda_nid_t
*dacs
, int *path_idx
)
1557 struct hda_gen_spec
*spec
= codec
->spec
;
1560 for (i
= 0; i
< outs
; i
++) {
1561 struct nid_path
*path
;
1565 dac
= get_dac_if_single(codec
, pins
[i
]);
1568 path
= snd_hda_add_new_path(codec
, dac
, pins
[i
],
1570 if (!path
&& !i
&& spec
->mixer_nid
)
1571 path
= snd_hda_add_new_path(codec
, dac
, pins
[i
], 0);
1575 /* print_nid_path(codec, "output", path); */
1576 path
->active
= true;
1577 path_idx
[i
] = snd_hda_get_path_idx(codec
, path
);
1583 /* create a new path including aamix if available, and return its index */
1584 static int check_aamix_out_path(struct hda_codec
*codec
, int path_idx
)
1586 struct hda_gen_spec
*spec
= codec
->spec
;
1587 struct nid_path
*path
;
1588 hda_nid_t path_dac
, dac
, pin
;
1590 path
= snd_hda_get_path_from_idx(codec
, path_idx
);
1591 if (!path
|| !path
->depth
||
1592 is_nid_contained(path
, spec
->mixer_nid
))
1594 path_dac
= path
->path
[0];
1595 dac
= spec
->private_dac_nids
[0];
1596 pin
= path
->path
[path
->depth
- 1];
1597 path
= snd_hda_add_new_path(codec
, dac
, pin
, spec
->mixer_nid
);
1599 if (dac
!= path_dac
)
1601 else if (spec
->multiout
.hp_out_nid
[0])
1602 dac
= spec
->multiout
.hp_out_nid
[0];
1603 else if (spec
->multiout
.extra_out_nid
[0])
1604 dac
= spec
->multiout
.extra_out_nid
[0];
1608 path
= snd_hda_add_new_path(codec
, dac
, pin
,
1613 /* print_nid_path(codec, "output-aamix", path); */
1614 path
->active
= false; /* unused as default */
1615 path
->pin_fixed
= true; /* static route */
1616 return snd_hda_get_path_idx(codec
, path
);
1619 /* check whether the independent HP is available with the current config */
1620 static bool indep_hp_possible(struct hda_codec
*codec
)
1622 struct hda_gen_spec
*spec
= codec
->spec
;
1623 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1624 struct nid_path
*path
;
1627 if (cfg
->line_out_type
== AUTO_PIN_HP_OUT
)
1628 idx
= spec
->out_paths
[0];
1630 idx
= spec
->hp_paths
[0];
1631 path
= snd_hda_get_path_from_idx(codec
, idx
);
1635 /* assume no path conflicts unless aamix is involved */
1636 if (!spec
->mixer_nid
|| !is_nid_contained(path
, spec
->mixer_nid
))
1639 /* check whether output paths contain aamix */
1640 for (i
= 0; i
< cfg
->line_outs
; i
++) {
1641 if (spec
->out_paths
[i
] == idx
)
1643 path
= snd_hda_get_path_from_idx(codec
, spec
->out_paths
[i
]);
1644 if (path
&& is_nid_contained(path
, spec
->mixer_nid
))
1647 for (i
= 0; i
< cfg
->speaker_outs
; i
++) {
1648 path
= snd_hda_get_path_from_idx(codec
, spec
->speaker_paths
[i
]);
1649 if (path
&& is_nid_contained(path
, spec
->mixer_nid
))
1656 /* fill the empty entries in the dac array for speaker/hp with the
1657 * shared dac pointed by the paths
1659 static void refill_shared_dacs(struct hda_codec
*codec
, int num_outs
,
1660 hda_nid_t
*dacs
, int *path_idx
)
1662 struct nid_path
*path
;
1665 for (i
= 0; i
< num_outs
; i
++) {
1668 path
= snd_hda_get_path_from_idx(codec
, path_idx
[i
]);
1671 dacs
[i
] = path
->path
[0];
1675 /* fill in the dac_nids table from the parsed pin configuration */
1676 static int fill_and_eval_dacs(struct hda_codec
*codec
,
1677 bool fill_hardwired
,
1678 bool fill_mio_first
)
1680 struct hda_gen_spec
*spec
= codec
->spec
;
1681 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1682 int i
, err
, badness
;
1684 /* set num_dacs once to full for look_for_dac() */
1685 spec
->multiout
.num_dacs
= cfg
->line_outs
;
1686 spec
->multiout
.dac_nids
= spec
->private_dac_nids
;
1687 memset(spec
->private_dac_nids
, 0, sizeof(spec
->private_dac_nids
));
1688 memset(spec
->multiout
.hp_out_nid
, 0, sizeof(spec
->multiout
.hp_out_nid
));
1689 memset(spec
->multiout
.extra_out_nid
, 0, sizeof(spec
->multiout
.extra_out_nid
));
1690 spec
->multi_ios
= 0;
1691 snd_array_free(&spec
->paths
);
1693 /* clear path indices */
1694 memset(spec
->out_paths
, 0, sizeof(spec
->out_paths
));
1695 memset(spec
->hp_paths
, 0, sizeof(spec
->hp_paths
));
1696 memset(spec
->speaker_paths
, 0, sizeof(spec
->speaker_paths
));
1697 memset(spec
->aamix_out_paths
, 0, sizeof(spec
->aamix_out_paths
));
1698 memset(spec
->digout_paths
, 0, sizeof(spec
->digout_paths
));
1699 memset(spec
->input_paths
, 0, sizeof(spec
->input_paths
));
1700 memset(spec
->loopback_paths
, 0, sizeof(spec
->loopback_paths
));
1701 memset(&spec
->digin_path
, 0, sizeof(spec
->digin_path
));
1705 /* fill hard-wired DACs first */
1706 if (fill_hardwired
) {
1709 mapped
= map_singles(codec
, cfg
->line_outs
,
1711 spec
->private_dac_nids
,
1713 mapped
|= map_singles(codec
, cfg
->hp_outs
,
1715 spec
->multiout
.hp_out_nid
,
1717 mapped
|= map_singles(codec
, cfg
->speaker_outs
,
1719 spec
->multiout
.extra_out_nid
,
1720 spec
->speaker_paths
);
1721 if (!spec
->no_multi_io
&&
1722 fill_mio_first
&& cfg
->line_outs
== 1 &&
1723 cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
) {
1724 err
= fill_multi_ios(codec
, cfg
->line_out_pins
[0], true);
1731 badness
+= try_assign_dacs(codec
, cfg
->line_outs
, cfg
->line_out_pins
,
1732 spec
->private_dac_nids
, spec
->out_paths
,
1733 spec
->main_out_badness
);
1735 if (!spec
->no_multi_io
&& fill_mio_first
&&
1736 cfg
->line_outs
== 1 && cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
) {
1737 /* try to fill multi-io first */
1738 err
= fill_multi_ios(codec
, cfg
->line_out_pins
[0], false);
1741 /* we don't count badness at this stage yet */
1744 if (cfg
->line_out_type
!= AUTO_PIN_HP_OUT
) {
1745 err
= try_assign_dacs(codec
, cfg
->hp_outs
, cfg
->hp_pins
,
1746 spec
->multiout
.hp_out_nid
,
1748 spec
->extra_out_badness
);
1753 if (cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
) {
1754 err
= try_assign_dacs(codec
, cfg
->speaker_outs
,
1756 spec
->multiout
.extra_out_nid
,
1757 spec
->speaker_paths
,
1758 spec
->extra_out_badness
);
1763 if (!spec
->no_multi_io
&&
1764 cfg
->line_outs
== 1 && cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
) {
1765 err
= fill_multi_ios(codec
, cfg
->line_out_pins
[0], false);
1771 if (spec
->mixer_nid
) {
1772 spec
->aamix_out_paths
[0] =
1773 check_aamix_out_path(codec
, spec
->out_paths
[0]);
1774 if (cfg
->line_out_type
!= AUTO_PIN_HP_OUT
)
1775 spec
->aamix_out_paths
[1] =
1776 check_aamix_out_path(codec
, spec
->hp_paths
[0]);
1777 if (cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
)
1778 spec
->aamix_out_paths
[2] =
1779 check_aamix_out_path(codec
, spec
->speaker_paths
[0]);
1782 if (!spec
->no_multi_io
&&
1783 cfg
->hp_outs
&& cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
)
1784 if (count_multiio_pins(codec
, cfg
->hp_pins
[0]) >= 2)
1785 spec
->multi_ios
= 1; /* give badness */
1787 /* re-count num_dacs and squash invalid entries */
1788 spec
->multiout
.num_dacs
= 0;
1789 for (i
= 0; i
< cfg
->line_outs
; i
++) {
1790 if (spec
->private_dac_nids
[i
])
1791 spec
->multiout
.num_dacs
++;
1793 memmove(spec
->private_dac_nids
+ i
,
1794 spec
->private_dac_nids
+ i
+ 1,
1795 sizeof(hda_nid_t
) * (cfg
->line_outs
- i
- 1));
1796 spec
->private_dac_nids
[cfg
->line_outs
- 1] = 0;
1800 spec
->ext_channel_count
= spec
->min_channel_count
=
1801 spec
->multiout
.num_dacs
* 2;
1803 if (spec
->multi_ios
== 2) {
1804 for (i
= 0; i
< 2; i
++)
1805 spec
->private_dac_nids
[spec
->multiout
.num_dacs
++] =
1806 spec
->multi_io
[i
].dac
;
1807 } else if (spec
->multi_ios
) {
1808 spec
->multi_ios
= 0;
1809 badness
+= BAD_MULTI_IO
;
1812 if (spec
->indep_hp
&& !indep_hp_possible(codec
))
1813 badness
+= BAD_NO_INDEP_HP
;
1815 /* re-fill the shared DAC for speaker / headphone */
1816 if (cfg
->line_out_type
!= AUTO_PIN_HP_OUT
)
1817 refill_shared_dacs(codec
, cfg
->hp_outs
,
1818 spec
->multiout
.hp_out_nid
,
1820 if (cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
)
1821 refill_shared_dacs(codec
, cfg
->speaker_outs
,
1822 spec
->multiout
.extra_out_nid
,
1823 spec
->speaker_paths
);
1828 #define DEBUG_BADNESS
1830 #ifdef DEBUG_BADNESS
1831 #define debug_badness(fmt, ...) \
1832 codec_dbg(codec, fmt, ##__VA_ARGS__)
1834 #define debug_badness(fmt, ...) \
1835 do { if (0) codec_dbg(codec, fmt, ##__VA_ARGS__); } while (0)
1838 #ifdef DEBUG_BADNESS
1839 static inline void print_nid_path_idx(struct hda_codec
*codec
,
1840 const char *pfx
, int idx
)
1842 struct nid_path
*path
;
1844 path
= snd_hda_get_path_from_idx(codec
, idx
);
1846 print_nid_path(codec
, pfx
, path
);
1849 static void debug_show_configs(struct hda_codec
*codec
,
1850 struct auto_pin_cfg
*cfg
)
1852 struct hda_gen_spec
*spec
= codec
->spec
;
1853 static const char * const lo_type
[3] = { "LO", "SP", "HP" };
1856 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x (type %s)\n",
1857 cfg
->line_out_pins
[0], cfg
->line_out_pins
[1],
1858 cfg
->line_out_pins
[2], cfg
->line_out_pins
[3],
1859 spec
->multiout
.dac_nids
[0],
1860 spec
->multiout
.dac_nids
[1],
1861 spec
->multiout
.dac_nids
[2],
1862 spec
->multiout
.dac_nids
[3],
1863 lo_type
[cfg
->line_out_type
]);
1864 for (i
= 0; i
< cfg
->line_outs
; i
++)
1865 print_nid_path_idx(codec
, " out", spec
->out_paths
[i
]);
1866 if (spec
->multi_ios
> 0)
1867 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
1869 spec
->multi_io
[0].pin
, spec
->multi_io
[1].pin
,
1870 spec
->multi_io
[0].dac
, spec
->multi_io
[1].dac
);
1871 for (i
= 0; i
< spec
->multi_ios
; i
++)
1872 print_nid_path_idx(codec
, " mio",
1873 spec
->out_paths
[cfg
->line_outs
+ i
]);
1875 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
1876 cfg
->hp_pins
[0], cfg
->hp_pins
[1],
1877 cfg
->hp_pins
[2], cfg
->hp_pins
[3],
1878 spec
->multiout
.hp_out_nid
[0],
1879 spec
->multiout
.hp_out_nid
[1],
1880 spec
->multiout
.hp_out_nid
[2],
1881 spec
->multiout
.hp_out_nid
[3]);
1882 for (i
= 0; i
< cfg
->hp_outs
; i
++)
1883 print_nid_path_idx(codec
, " hp ", spec
->hp_paths
[i
]);
1884 if (cfg
->speaker_outs
)
1885 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
1886 cfg
->speaker_pins
[0], cfg
->speaker_pins
[1],
1887 cfg
->speaker_pins
[2], cfg
->speaker_pins
[3],
1888 spec
->multiout
.extra_out_nid
[0],
1889 spec
->multiout
.extra_out_nid
[1],
1890 spec
->multiout
.extra_out_nid
[2],
1891 spec
->multiout
.extra_out_nid
[3]);
1892 for (i
= 0; i
< cfg
->speaker_outs
; i
++)
1893 print_nid_path_idx(codec
, " spk", spec
->speaker_paths
[i
]);
1894 for (i
= 0; i
< 3; i
++)
1895 print_nid_path_idx(codec
, " mix", spec
->aamix_out_paths
[i
]);
1898 #define debug_show_configs(codec, cfg) /* NOP */
1901 /* find all available DACs of the codec */
1902 static void fill_all_dac_nids(struct hda_codec
*codec
)
1904 struct hda_gen_spec
*spec
= codec
->spec
;
1907 spec
->num_all_dacs
= 0;
1908 memset(spec
->all_dacs
, 0, sizeof(spec
->all_dacs
));
1909 for_each_hda_codec_node(nid
, codec
) {
1910 if (get_wcaps_type(get_wcaps(codec
, nid
)) != AC_WID_AUD_OUT
)
1912 if (spec
->num_all_dacs
>= ARRAY_SIZE(spec
->all_dacs
)) {
1913 codec_err(codec
, "Too many DACs!\n");
1916 spec
->all_dacs
[spec
->num_all_dacs
++] = nid
;
1920 static int parse_output_paths(struct hda_codec
*codec
)
1922 struct hda_gen_spec
*spec
= codec
->spec
;
1923 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
1924 struct auto_pin_cfg
*best_cfg
;
1926 int best_badness
= INT_MAX
;
1928 bool fill_hardwired
= true, fill_mio_first
= true;
1929 bool best_wired
= true, best_mio
= true;
1930 bool hp_spk_swapped
= false;
1932 best_cfg
= kmalloc(sizeof(*best_cfg
), GFP_KERNEL
);
1938 badness
= fill_and_eval_dacs(codec
, fill_hardwired
,
1944 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
1945 cfg
->line_out_type
, fill_hardwired
, fill_mio_first
,
1947 debug_show_configs(codec
, cfg
);
1948 if (badness
< best_badness
) {
1949 best_badness
= badness
;
1951 best_wired
= fill_hardwired
;
1952 best_mio
= fill_mio_first
;
1956 fill_mio_first
= !fill_mio_first
;
1957 if (!fill_mio_first
)
1959 fill_hardwired
= !fill_hardwired
;
1960 if (!fill_hardwired
)
1964 hp_spk_swapped
= true;
1965 if (cfg
->speaker_outs
> 0 &&
1966 cfg
->line_out_type
== AUTO_PIN_HP_OUT
) {
1967 cfg
->hp_outs
= cfg
->line_outs
;
1968 memcpy(cfg
->hp_pins
, cfg
->line_out_pins
,
1969 sizeof(cfg
->hp_pins
));
1970 cfg
->line_outs
= cfg
->speaker_outs
;
1971 memcpy(cfg
->line_out_pins
, cfg
->speaker_pins
,
1972 sizeof(cfg
->speaker_pins
));
1973 cfg
->speaker_outs
= 0;
1974 memset(cfg
->speaker_pins
, 0, sizeof(cfg
->speaker_pins
));
1975 cfg
->line_out_type
= AUTO_PIN_SPEAKER_OUT
;
1976 fill_hardwired
= true;
1979 if (cfg
->hp_outs
> 0 &&
1980 cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
) {
1981 cfg
->speaker_outs
= cfg
->line_outs
;
1982 memcpy(cfg
->speaker_pins
, cfg
->line_out_pins
,
1983 sizeof(cfg
->speaker_pins
));
1984 cfg
->line_outs
= cfg
->hp_outs
;
1985 memcpy(cfg
->line_out_pins
, cfg
->hp_pins
,
1986 sizeof(cfg
->hp_pins
));
1988 memset(cfg
->hp_pins
, 0, sizeof(cfg
->hp_pins
));
1989 cfg
->line_out_type
= AUTO_PIN_HP_OUT
;
1990 fill_hardwired
= true;
1997 debug_badness("==> restoring best_cfg\n");
1999 fill_and_eval_dacs(codec
, best_wired
, best_mio
);
2001 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
2002 cfg
->line_out_type
, best_wired
, best_mio
);
2003 debug_show_configs(codec
, cfg
);
2005 if (cfg
->line_out_pins
[0]) {
2006 struct nid_path
*path
;
2007 path
= snd_hda_get_path_from_idx(codec
, spec
->out_paths
[0]);
2009 spec
->vmaster_nid
= look_for_out_vol_nid(codec
, path
);
2010 if (spec
->vmaster_nid
) {
2011 snd_hda_set_vmaster_tlv(codec
, spec
->vmaster_nid
,
2012 HDA_OUTPUT
, spec
->vmaster_tlv
);
2013 if (spec
->dac_min_mute
)
2014 spec
->vmaster_tlv
[3] |= TLV_DB_SCALE_MUTE
;
2018 /* set initial pinctl targets */
2019 if (spec
->prefer_hp_amp
|| cfg
->line_out_type
== AUTO_PIN_HP_OUT
)
2023 set_pin_targets(codec
, cfg
->line_outs
, cfg
->line_out_pins
, val
);
2024 if (cfg
->line_out_type
!= AUTO_PIN_HP_OUT
)
2025 set_pin_targets(codec
, cfg
->hp_outs
, cfg
->hp_pins
, PIN_HP
);
2026 if (cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
) {
2027 val
= spec
->prefer_hp_amp
? PIN_HP
: PIN_OUT
;
2028 set_pin_targets(codec
, cfg
->speaker_outs
,
2029 cfg
->speaker_pins
, val
);
2032 /* clear indep_hp flag if not available */
2033 if (spec
->indep_hp
&& !indep_hp_possible(codec
))
2040 /* add playback controls from the parsed DAC table */
2041 static int create_multi_out_ctls(struct hda_codec
*codec
,
2042 const struct auto_pin_cfg
*cfg
)
2044 struct hda_gen_spec
*spec
= codec
->spec
;
2045 int i
, err
, noutputs
;
2047 noutputs
= cfg
->line_outs
;
2048 if (spec
->multi_ios
> 0 && cfg
->line_outs
< 3)
2049 noutputs
+= spec
->multi_ios
;
2051 for (i
= 0; i
< noutputs
; i
++) {
2054 struct nid_path
*path
;
2056 path
= snd_hda_get_path_from_idx(codec
, spec
->out_paths
[i
]);
2060 name
= get_line_out_pfx(codec
, i
, &index
, NID_PATH_VOL_CTL
);
2061 if (!name
|| !strcmp(name
, "CLFE")) {
2063 err
= add_vol_ctl(codec
, "Center", 0, 1, path
);
2066 err
= add_vol_ctl(codec
, "LFE", 0, 2, path
);
2070 err
= add_stereo_vol(codec
, name
, index
, path
);
2075 name
= get_line_out_pfx(codec
, i
, &index
, NID_PATH_MUTE_CTL
);
2076 if (!name
|| !strcmp(name
, "CLFE")) {
2077 err
= add_sw_ctl(codec
, "Center", 0, 1, path
);
2080 err
= add_sw_ctl(codec
, "LFE", 0, 2, path
);
2084 err
= add_stereo_sw(codec
, name
, index
, path
);
2092 static int create_extra_out(struct hda_codec
*codec
, int path_idx
,
2093 const char *pfx
, int cidx
)
2095 struct nid_path
*path
;
2098 path
= snd_hda_get_path_from_idx(codec
, path_idx
);
2101 err
= add_stereo_vol(codec
, pfx
, cidx
, path
);
2104 err
= add_stereo_sw(codec
, pfx
, cidx
, path
);
2110 /* add playback controls for speaker and HP outputs */
2111 static int create_extra_outs(struct hda_codec
*codec
, int num_pins
,
2112 const int *paths
, const char *pfx
)
2116 for (i
= 0; i
< num_pins
; i
++) {
2118 char tmp
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
2121 if (num_pins
== 2 && i
== 1 && !strcmp(pfx
, "Speaker"))
2122 name
= "Bass Speaker";
2123 else if (num_pins
>= 3) {
2124 snprintf(tmp
, sizeof(tmp
), "%s %s",
2125 pfx
, channel_name
[i
]);
2131 err
= create_extra_out(codec
, paths
[i
], name
, idx
);
2138 static int create_hp_out_ctls(struct hda_codec
*codec
)
2140 struct hda_gen_spec
*spec
= codec
->spec
;
2141 return create_extra_outs(codec
, spec
->autocfg
.hp_outs
,
2146 static int create_speaker_out_ctls(struct hda_codec
*codec
)
2148 struct hda_gen_spec
*spec
= codec
->spec
;
2149 return create_extra_outs(codec
, spec
->autocfg
.speaker_outs
,
2150 spec
->speaker_paths
,
2155 * independent HP controls
2158 static void call_hp_automute(struct hda_codec
*codec
,
2159 struct hda_jack_callback
*jack
);
2160 static int indep_hp_info(struct snd_kcontrol
*kcontrol
,
2161 struct snd_ctl_elem_info
*uinfo
)
2163 return snd_hda_enum_bool_helper_info(kcontrol
, uinfo
);
2166 static int indep_hp_get(struct snd_kcontrol
*kcontrol
,
2167 struct snd_ctl_elem_value
*ucontrol
)
2169 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2170 struct hda_gen_spec
*spec
= codec
->spec
;
2171 ucontrol
->value
.enumerated
.item
[0] = spec
->indep_hp_enabled
;
2175 static void update_aamix_paths(struct hda_codec
*codec
, bool do_mix
,
2176 int nomix_path_idx
, int mix_path_idx
,
2179 static int indep_hp_put(struct snd_kcontrol
*kcontrol
,
2180 struct snd_ctl_elem_value
*ucontrol
)
2182 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2183 struct hda_gen_spec
*spec
= codec
->spec
;
2184 unsigned int select
= ucontrol
->value
.enumerated
.item
[0];
2187 mutex_lock(&spec
->pcm_mutex
);
2188 if (spec
->active_streams
) {
2193 if (spec
->indep_hp_enabled
!= select
) {
2195 if (spec
->autocfg
.line_out_type
== AUTO_PIN_HP_OUT
)
2196 dacp
= &spec
->private_dac_nids
[0];
2198 dacp
= &spec
->multiout
.hp_out_nid
[0];
2200 /* update HP aamix paths in case it conflicts with indep HP */
2201 if (spec
->have_aamix_ctl
) {
2202 if (spec
->autocfg
.line_out_type
== AUTO_PIN_HP_OUT
)
2203 update_aamix_paths(codec
, spec
->aamix_mode
,
2205 spec
->aamix_out_paths
[0],
2206 spec
->autocfg
.line_out_type
);
2208 update_aamix_paths(codec
, spec
->aamix_mode
,
2210 spec
->aamix_out_paths
[1],
2214 spec
->indep_hp_enabled
= select
;
2215 if (spec
->indep_hp_enabled
)
2218 *dacp
= spec
->alt_dac_nid
;
2220 call_hp_automute(codec
, NULL
);
2224 mutex_unlock(&spec
->pcm_mutex
);
2228 static const struct snd_kcontrol_new indep_hp_ctl
= {
2229 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2230 .name
= "Independent HP",
2231 .info
= indep_hp_info
,
2232 .get
= indep_hp_get
,
2233 .put
= indep_hp_put
,
2237 static int create_indep_hp_ctls(struct hda_codec
*codec
)
2239 struct hda_gen_spec
*spec
= codec
->spec
;
2242 if (!spec
->indep_hp
)
2244 if (spec
->autocfg
.line_out_type
== AUTO_PIN_HP_OUT
)
2245 dac
= spec
->multiout
.dac_nids
[0];
2247 dac
= spec
->multiout
.hp_out_nid
[0];
2253 spec
->indep_hp_enabled
= false;
2254 spec
->alt_dac_nid
= dac
;
2255 if (!snd_hda_gen_add_kctl(spec
, NULL
, &indep_hp_ctl
))
2261 * channel mode enum control
2264 static int ch_mode_info(struct snd_kcontrol
*kcontrol
,
2265 struct snd_ctl_elem_info
*uinfo
)
2267 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2268 struct hda_gen_spec
*spec
= codec
->spec
;
2271 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2273 uinfo
->value
.enumerated
.items
= spec
->multi_ios
+ 1;
2274 if (uinfo
->value
.enumerated
.item
> spec
->multi_ios
)
2275 uinfo
->value
.enumerated
.item
= spec
->multi_ios
;
2276 chs
= uinfo
->value
.enumerated
.item
* 2 + spec
->min_channel_count
;
2277 sprintf(uinfo
->value
.enumerated
.name
, "%dch", chs
);
2281 static int ch_mode_get(struct snd_kcontrol
*kcontrol
,
2282 struct snd_ctl_elem_value
*ucontrol
)
2284 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2285 struct hda_gen_spec
*spec
= codec
->spec
;
2286 ucontrol
->value
.enumerated
.item
[0] =
2287 (spec
->ext_channel_count
- spec
->min_channel_count
) / 2;
2291 static inline struct nid_path
*
2292 get_multiio_path(struct hda_codec
*codec
, int idx
)
2294 struct hda_gen_spec
*spec
= codec
->spec
;
2295 return snd_hda_get_path_from_idx(codec
,
2296 spec
->out_paths
[spec
->autocfg
.line_outs
+ idx
]);
2299 static void update_automute_all(struct hda_codec
*codec
);
2301 /* Default value to be passed as aamix argument for snd_hda_activate_path();
2302 * used for output paths
2304 static bool aamix_default(struct hda_gen_spec
*spec
)
2306 return !spec
->have_aamix_ctl
|| spec
->aamix_mode
;
2309 static int set_multi_io(struct hda_codec
*codec
, int idx
, bool output
)
2311 struct hda_gen_spec
*spec
= codec
->spec
;
2312 hda_nid_t nid
= spec
->multi_io
[idx
].pin
;
2313 struct nid_path
*path
;
2315 path
= get_multiio_path(codec
, idx
);
2319 if (path
->active
== output
)
2323 set_pin_target(codec
, nid
, PIN_OUT
, true);
2324 snd_hda_activate_path(codec
, path
, true, aamix_default(spec
));
2325 set_pin_eapd(codec
, nid
, true);
2327 set_pin_eapd(codec
, nid
, false);
2328 snd_hda_activate_path(codec
, path
, false, aamix_default(spec
));
2329 set_pin_target(codec
, nid
, spec
->multi_io
[idx
].ctl_in
, true);
2330 path_power_down_sync(codec
, path
);
2333 /* update jack retasking in case it modifies any of them */
2334 update_automute_all(codec
);
2339 static int ch_mode_put(struct snd_kcontrol
*kcontrol
,
2340 struct snd_ctl_elem_value
*ucontrol
)
2342 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2343 struct hda_gen_spec
*spec
= codec
->spec
;
2346 ch
= ucontrol
->value
.enumerated
.item
[0];
2347 if (ch
< 0 || ch
> spec
->multi_ios
)
2349 if (ch
== (spec
->ext_channel_count
- spec
->min_channel_count
) / 2)
2351 spec
->ext_channel_count
= ch
* 2 + spec
->min_channel_count
;
2352 for (i
= 0; i
< spec
->multi_ios
; i
++)
2353 set_multi_io(codec
, i
, i
< ch
);
2354 spec
->multiout
.max_channels
= max(spec
->ext_channel_count
,
2355 spec
->const_channel_count
);
2356 if (spec
->need_dac_fix
)
2357 spec
->multiout
.num_dacs
= spec
->multiout
.max_channels
/ 2;
2361 static const struct snd_kcontrol_new channel_mode_enum
= {
2362 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2363 .name
= "Channel Mode",
2364 .info
= ch_mode_info
,
2369 static int create_multi_channel_mode(struct hda_codec
*codec
)
2371 struct hda_gen_spec
*spec
= codec
->spec
;
2373 if (spec
->multi_ios
> 0) {
2374 if (!snd_hda_gen_add_kctl(spec
, NULL
, &channel_mode_enum
))
2381 * aamix loopback enable/disable switch
2384 #define loopback_mixing_info indep_hp_info
2386 static int loopback_mixing_get(struct snd_kcontrol
*kcontrol
,
2387 struct snd_ctl_elem_value
*ucontrol
)
2389 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2390 struct hda_gen_spec
*spec
= codec
->spec
;
2391 ucontrol
->value
.enumerated
.item
[0] = spec
->aamix_mode
;
2395 static void update_aamix_paths(struct hda_codec
*codec
, bool do_mix
,
2396 int nomix_path_idx
, int mix_path_idx
,
2399 struct hda_gen_spec
*spec
= codec
->spec
;
2400 struct nid_path
*nomix_path
, *mix_path
;
2402 nomix_path
= snd_hda_get_path_from_idx(codec
, nomix_path_idx
);
2403 mix_path
= snd_hda_get_path_from_idx(codec
, mix_path_idx
);
2404 if (!nomix_path
|| !mix_path
)
2407 /* if HP aamix path is driven from a different DAC and the
2408 * independent HP mode is ON, can't turn on aamix path
2410 if (out_type
== AUTO_PIN_HP_OUT
&& spec
->indep_hp_enabled
&&
2411 mix_path
->path
[0] != spec
->alt_dac_nid
)
2415 snd_hda_activate_path(codec
, nomix_path
, false, true);
2416 snd_hda_activate_path(codec
, mix_path
, true, true);
2417 path_power_down_sync(codec
, nomix_path
);
2419 snd_hda_activate_path(codec
, mix_path
, false, false);
2420 snd_hda_activate_path(codec
, nomix_path
, true, false);
2421 path_power_down_sync(codec
, mix_path
);
2425 static int loopback_mixing_put(struct snd_kcontrol
*kcontrol
,
2426 struct snd_ctl_elem_value
*ucontrol
)
2428 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2429 struct hda_gen_spec
*spec
= codec
->spec
;
2430 unsigned int val
= ucontrol
->value
.enumerated
.item
[0];
2432 if (val
== spec
->aamix_mode
)
2434 spec
->aamix_mode
= val
;
2435 update_aamix_paths(codec
, val
, spec
->out_paths
[0],
2436 spec
->aamix_out_paths
[0],
2437 spec
->autocfg
.line_out_type
);
2438 update_aamix_paths(codec
, val
, spec
->hp_paths
[0],
2439 spec
->aamix_out_paths
[1],
2441 update_aamix_paths(codec
, val
, spec
->speaker_paths
[0],
2442 spec
->aamix_out_paths
[2],
2443 AUTO_PIN_SPEAKER_OUT
);
2447 static const struct snd_kcontrol_new loopback_mixing_enum
= {
2448 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2449 .name
= "Loopback Mixing",
2450 .info
= loopback_mixing_info
,
2451 .get
= loopback_mixing_get
,
2452 .put
= loopback_mixing_put
,
2455 static int create_loopback_mixing_ctl(struct hda_codec
*codec
)
2457 struct hda_gen_spec
*spec
= codec
->spec
;
2459 if (!spec
->mixer_nid
)
2461 if (!(spec
->aamix_out_paths
[0] || spec
->aamix_out_paths
[1] ||
2462 spec
->aamix_out_paths
[2]))
2464 if (!snd_hda_gen_add_kctl(spec
, NULL
, &loopback_mixing_enum
))
2466 spec
->have_aamix_ctl
= 1;
2471 * shared headphone/mic handling
2474 static void call_update_outputs(struct hda_codec
*codec
);
2476 /* for shared I/O, change the pin-control accordingly */
2477 static void update_hp_mic(struct hda_codec
*codec
, int adc_mux
, bool force
)
2479 struct hda_gen_spec
*spec
= codec
->spec
;
2484 pin
= spec
->hp_mic_pin
;
2485 as_mic
= spec
->cur_mux
[adc_mux
] == spec
->hp_mic_mux_idx
;
2488 val
= snd_hda_codec_get_pin_target(codec
, pin
);
2498 val
= snd_hda_get_default_vref(codec
, pin
);
2499 /* if the HP pin doesn't support VREF and the codec driver gives an
2500 * alternative pin, set up the VREF on that pin instead
2502 if (val
== AC_PINCTL_VREF_HIZ
&& spec
->shared_mic_vref_pin
) {
2503 const hda_nid_t vref_pin
= spec
->shared_mic_vref_pin
;
2504 unsigned int vref_val
= snd_hda_get_default_vref(codec
, vref_pin
);
2505 if (vref_val
!= AC_PINCTL_VREF_HIZ
)
2506 snd_hda_set_pin_ctl_cache(codec
, vref_pin
,
2507 PIN_IN
| (as_mic
? vref_val
: 0));
2510 if (!spec
->hp_mic_jack_modes
) {
2515 set_pin_target(codec
, pin
, val
, true);
2516 call_hp_automute(codec
, NULL
);
2520 /* create a shared input with the headphone out */
2521 static int create_hp_mic(struct hda_codec
*codec
)
2523 struct hda_gen_spec
*spec
= codec
->spec
;
2524 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
2525 unsigned int defcfg
;
2528 if (!spec
->hp_mic
) {
2529 if (spec
->suppress_hp_mic_detect
)
2531 /* automatic detection: only if no input or a single internal
2532 * input pin is found, try to detect the shared hp/mic
2534 if (cfg
->num_inputs
> 1)
2536 else if (cfg
->num_inputs
== 1) {
2537 defcfg
= snd_hda_codec_get_pincfg(codec
, cfg
->inputs
[0].pin
);
2538 if (snd_hda_get_input_pin_attr(defcfg
) != INPUT_PIN_ATTR_INT
)
2543 spec
->hp_mic
= 0; /* clear once */
2544 if (cfg
->num_inputs
>= AUTO_CFG_MAX_INS
)
2548 if (cfg
->line_out_type
== AUTO_PIN_HP_OUT
&& cfg
->line_outs
> 0)
2549 nid
= cfg
->line_out_pins
[0];
2550 else if (cfg
->hp_outs
> 0)
2551 nid
= cfg
->hp_pins
[0];
2555 if (!(snd_hda_query_pin_caps(codec
, nid
) & AC_PINCAP_IN
))
2556 return 0; /* no input */
2558 cfg
->inputs
[cfg
->num_inputs
].pin
= nid
;
2559 cfg
->inputs
[cfg
->num_inputs
].type
= AUTO_PIN_MIC
;
2560 cfg
->inputs
[cfg
->num_inputs
].is_headphone_mic
= 1;
2563 spec
->hp_mic_pin
= nid
;
2564 /* we can't handle auto-mic together with HP-mic */
2565 spec
->suppress_auto_mic
= 1;
2566 codec_dbg(codec
, "Enable shared I/O jack on NID 0x%x\n", nid
);
2574 static int create_hp_mic_jack_mode(struct hda_codec
*codec
, hda_nid_t pin
);
2576 static const char * const out_jack_texts
[] = {
2577 "Line Out", "Headphone Out",
2580 static int out_jack_mode_info(struct snd_kcontrol
*kcontrol
,
2581 struct snd_ctl_elem_info
*uinfo
)
2583 return snd_hda_enum_helper_info(kcontrol
, uinfo
, 2, out_jack_texts
);
2586 static int out_jack_mode_get(struct snd_kcontrol
*kcontrol
,
2587 struct snd_ctl_elem_value
*ucontrol
)
2589 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2590 hda_nid_t nid
= kcontrol
->private_value
;
2591 if (snd_hda_codec_get_pin_target(codec
, nid
) == PIN_HP
)
2592 ucontrol
->value
.enumerated
.item
[0] = 1;
2594 ucontrol
->value
.enumerated
.item
[0] = 0;
2598 static int out_jack_mode_put(struct snd_kcontrol
*kcontrol
,
2599 struct snd_ctl_elem_value
*ucontrol
)
2601 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2602 hda_nid_t nid
= kcontrol
->private_value
;
2605 val
= ucontrol
->value
.enumerated
.item
[0] ? PIN_HP
: PIN_OUT
;
2606 if (snd_hda_codec_get_pin_target(codec
, nid
) == val
)
2608 snd_hda_set_pin_ctl_cache(codec
, nid
, val
);
2612 static const struct snd_kcontrol_new out_jack_mode_enum
= {
2613 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2614 .info
= out_jack_mode_info
,
2615 .get
= out_jack_mode_get
,
2616 .put
= out_jack_mode_put
,
2619 static bool find_kctl_name(struct hda_codec
*codec
, const char *name
, int idx
)
2621 struct hda_gen_spec
*spec
= codec
->spec
;
2624 for (i
= 0; i
< spec
->kctls
.used
; i
++) {
2625 struct snd_kcontrol_new
*kctl
= snd_array_elem(&spec
->kctls
, i
);
2626 if (!strcmp(kctl
->name
, name
) && kctl
->index
== idx
)
2632 static void get_jack_mode_name(struct hda_codec
*codec
, hda_nid_t pin
,
2633 char *name
, size_t name_len
)
2635 struct hda_gen_spec
*spec
= codec
->spec
;
2638 snd_hda_get_pin_label(codec
, pin
, &spec
->autocfg
, name
, name_len
, &idx
);
2639 strlcat(name
, " Jack Mode", name_len
);
2641 for (; find_kctl_name(codec
, name
, idx
); idx
++)
2645 static int get_out_jack_num_items(struct hda_codec
*codec
, hda_nid_t pin
)
2647 struct hda_gen_spec
*spec
= codec
->spec
;
2648 if (spec
->add_jack_modes
) {
2649 unsigned int pincap
= snd_hda_query_pin_caps(codec
, pin
);
2650 if ((pincap
& AC_PINCAP_OUT
) && (pincap
& AC_PINCAP_HP_DRV
))
2656 static int create_out_jack_modes(struct hda_codec
*codec
, int num_pins
,
2659 struct hda_gen_spec
*spec
= codec
->spec
;
2662 for (i
= 0; i
< num_pins
; i
++) {
2663 hda_nid_t pin
= pins
[i
];
2664 if (pin
== spec
->hp_mic_pin
)
2666 if (get_out_jack_num_items(codec
, pin
) > 1) {
2667 struct snd_kcontrol_new
*knew
;
2668 char name
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
2669 get_jack_mode_name(codec
, pin
, name
, sizeof(name
));
2670 knew
= snd_hda_gen_add_kctl(spec
, name
,
2671 &out_jack_mode_enum
);
2674 knew
->private_value
= pin
;
2685 /* from AC_PINCTL_VREF_HIZ to AC_PINCTL_VREF_100 */
2688 static const char * const vref_texts
[NUM_VREFS
] = {
2689 "Line In", "Mic 50pc Bias", "Mic 0V Bias",
2690 "", "Mic 80pc Bias", "Mic 100pc Bias"
2693 static unsigned int get_vref_caps(struct hda_codec
*codec
, hda_nid_t pin
)
2695 unsigned int pincap
;
2697 pincap
= snd_hda_query_pin_caps(codec
, pin
);
2698 pincap
= (pincap
& AC_PINCAP_VREF
) >> AC_PINCAP_VREF_SHIFT
;
2699 /* filter out unusual vrefs */
2700 pincap
&= ~(AC_PINCAP_VREF_GRD
| AC_PINCAP_VREF_100
);
2704 /* convert from the enum item index to the vref ctl index (0=HIZ, 1=50%...) */
2705 static int get_vref_idx(unsigned int vref_caps
, unsigned int item_idx
)
2707 unsigned int i
, n
= 0;
2709 for (i
= 0; i
< NUM_VREFS
; i
++) {
2710 if (vref_caps
& (1 << i
)) {
2719 /* convert back from the vref ctl index to the enum item index */
2720 static int cvt_from_vref_idx(unsigned int vref_caps
, unsigned int idx
)
2722 unsigned int i
, n
= 0;
2724 for (i
= 0; i
< NUM_VREFS
; i
++) {
2727 if (vref_caps
& (1 << i
))
2733 static int in_jack_mode_info(struct snd_kcontrol
*kcontrol
,
2734 struct snd_ctl_elem_info
*uinfo
)
2736 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2737 hda_nid_t nid
= kcontrol
->private_value
;
2738 unsigned int vref_caps
= get_vref_caps(codec
, nid
);
2740 snd_hda_enum_helper_info(kcontrol
, uinfo
, hweight32(vref_caps
),
2742 /* set the right text */
2743 strcpy(uinfo
->value
.enumerated
.name
,
2744 vref_texts
[get_vref_idx(vref_caps
, uinfo
->value
.enumerated
.item
)]);
2748 static int in_jack_mode_get(struct snd_kcontrol
*kcontrol
,
2749 struct snd_ctl_elem_value
*ucontrol
)
2751 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2752 hda_nid_t nid
= kcontrol
->private_value
;
2753 unsigned int vref_caps
= get_vref_caps(codec
, nid
);
2756 idx
= snd_hda_codec_get_pin_target(codec
, nid
) & AC_PINCTL_VREFEN
;
2757 ucontrol
->value
.enumerated
.item
[0] = cvt_from_vref_idx(vref_caps
, idx
);
2761 static int in_jack_mode_put(struct snd_kcontrol
*kcontrol
,
2762 struct snd_ctl_elem_value
*ucontrol
)
2764 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2765 hda_nid_t nid
= kcontrol
->private_value
;
2766 unsigned int vref_caps
= get_vref_caps(codec
, nid
);
2767 unsigned int val
, idx
;
2769 val
= snd_hda_codec_get_pin_target(codec
, nid
);
2770 idx
= cvt_from_vref_idx(vref_caps
, val
& AC_PINCTL_VREFEN
);
2771 if (idx
== ucontrol
->value
.enumerated
.item
[0])
2774 val
&= ~AC_PINCTL_VREFEN
;
2775 val
|= get_vref_idx(vref_caps
, ucontrol
->value
.enumerated
.item
[0]);
2776 snd_hda_set_pin_ctl_cache(codec
, nid
, val
);
2780 static const struct snd_kcontrol_new in_jack_mode_enum
= {
2781 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2782 .info
= in_jack_mode_info
,
2783 .get
= in_jack_mode_get
,
2784 .put
= in_jack_mode_put
,
2787 static int get_in_jack_num_items(struct hda_codec
*codec
, hda_nid_t pin
)
2789 struct hda_gen_spec
*spec
= codec
->spec
;
2791 if (spec
->add_jack_modes
)
2792 nitems
= hweight32(get_vref_caps(codec
, pin
));
2793 return nitems
? nitems
: 1;
2796 static int create_in_jack_mode(struct hda_codec
*codec
, hda_nid_t pin
)
2798 struct hda_gen_spec
*spec
= codec
->spec
;
2799 struct snd_kcontrol_new
*knew
;
2800 char name
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
2801 unsigned int defcfg
;
2803 if (pin
== spec
->hp_mic_pin
)
2804 return 0; /* already done in create_out_jack_mode() */
2806 /* no jack mode for fixed pins */
2807 defcfg
= snd_hda_codec_get_pincfg(codec
, pin
);
2808 if (snd_hda_get_input_pin_attr(defcfg
) == INPUT_PIN_ATTR_INT
)
2811 /* no multiple vref caps? */
2812 if (get_in_jack_num_items(codec
, pin
) <= 1)
2815 get_jack_mode_name(codec
, pin
, name
, sizeof(name
));
2816 knew
= snd_hda_gen_add_kctl(spec
, name
, &in_jack_mode_enum
);
2819 knew
->private_value
= pin
;
2824 * HP/mic shared jack mode
2826 static int hp_mic_jack_mode_info(struct snd_kcontrol
*kcontrol
,
2827 struct snd_ctl_elem_info
*uinfo
)
2829 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2830 hda_nid_t nid
= kcontrol
->private_value
;
2831 int out_jacks
= get_out_jack_num_items(codec
, nid
);
2832 int in_jacks
= get_in_jack_num_items(codec
, nid
);
2833 const char *text
= NULL
;
2836 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2838 uinfo
->value
.enumerated
.items
= out_jacks
+ in_jacks
;
2839 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
2840 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
2841 idx
= uinfo
->value
.enumerated
.item
;
2842 if (idx
< out_jacks
) {
2844 text
= out_jack_texts
[idx
];
2846 text
= "Headphone Out";
2850 unsigned int vref_caps
= get_vref_caps(codec
, nid
);
2851 text
= vref_texts
[get_vref_idx(vref_caps
, idx
)];
2856 strcpy(uinfo
->value
.enumerated
.name
, text
);
2860 static int get_cur_hp_mic_jack_mode(struct hda_codec
*codec
, hda_nid_t nid
)
2862 int out_jacks
= get_out_jack_num_items(codec
, nid
);
2863 int in_jacks
= get_in_jack_num_items(codec
, nid
);
2864 unsigned int val
= snd_hda_codec_get_pin_target(codec
, nid
);
2867 if (val
& PIN_OUT
) {
2868 if (out_jacks
> 1 && val
== PIN_HP
)
2870 } else if (val
& PIN_IN
) {
2873 unsigned int vref_caps
= get_vref_caps(codec
, nid
);
2874 val
&= AC_PINCTL_VREFEN
;
2875 idx
+= cvt_from_vref_idx(vref_caps
, val
);
2881 static int hp_mic_jack_mode_get(struct snd_kcontrol
*kcontrol
,
2882 struct snd_ctl_elem_value
*ucontrol
)
2884 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2885 hda_nid_t nid
= kcontrol
->private_value
;
2886 ucontrol
->value
.enumerated
.item
[0] =
2887 get_cur_hp_mic_jack_mode(codec
, nid
);
2891 static int hp_mic_jack_mode_put(struct snd_kcontrol
*kcontrol
,
2892 struct snd_ctl_elem_value
*ucontrol
)
2894 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
2895 hda_nid_t nid
= kcontrol
->private_value
;
2896 int out_jacks
= get_out_jack_num_items(codec
, nid
);
2897 int in_jacks
= get_in_jack_num_items(codec
, nid
);
2898 unsigned int val
, oldval
, idx
;
2900 oldval
= get_cur_hp_mic_jack_mode(codec
, nid
);
2901 idx
= ucontrol
->value
.enumerated
.item
[0];
2905 if (idx
< out_jacks
) {
2907 val
= idx
? PIN_HP
: PIN_OUT
;
2913 unsigned int vref_caps
= get_vref_caps(codec
, nid
);
2914 val
= snd_hda_codec_get_pin_target(codec
, nid
);
2915 val
&= ~(AC_PINCTL_VREFEN
| PIN_HP
);
2916 val
|= get_vref_idx(vref_caps
, idx
) | PIN_IN
;
2918 val
= snd_hda_get_default_vref(codec
, nid
) | PIN_IN
;
2920 snd_hda_set_pin_ctl_cache(codec
, nid
, val
);
2921 call_hp_automute(codec
, NULL
);
2926 static const struct snd_kcontrol_new hp_mic_jack_mode_enum
= {
2927 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2928 .info
= hp_mic_jack_mode_info
,
2929 .get
= hp_mic_jack_mode_get
,
2930 .put
= hp_mic_jack_mode_put
,
2933 static int create_hp_mic_jack_mode(struct hda_codec
*codec
, hda_nid_t pin
)
2935 struct hda_gen_spec
*spec
= codec
->spec
;
2936 struct snd_kcontrol_new
*knew
;
2938 knew
= snd_hda_gen_add_kctl(spec
, "Headphone Mic Jack Mode",
2939 &hp_mic_jack_mode_enum
);
2942 knew
->private_value
= pin
;
2943 spec
->hp_mic_jack_modes
= 1;
2951 /* add the powersave loopback-list entry */
2952 static int add_loopback_list(struct hda_gen_spec
*spec
, hda_nid_t mix
, int idx
)
2954 struct hda_amp_list
*list
;
2956 list
= snd_array_new(&spec
->loopback_list
);
2960 list
->dir
= HDA_INPUT
;
2962 spec
->loopback
.amplist
= spec
->loopback_list
.list
;
2966 /* return true if either a volume or a mute amp is found for the given
2967 * aamix path; the amp has to be either in the mixer node or its direct leaf
2969 static bool look_for_mix_leaf_ctls(struct hda_codec
*codec
, hda_nid_t mix_nid
,
2970 hda_nid_t pin
, unsigned int *mix_val
,
2971 unsigned int *mute_val
)
2974 const hda_nid_t
*list
;
2977 idx
= snd_hda_get_conn_index(codec
, mix_nid
, pin
, true);
2981 *mix_val
= *mute_val
= 0;
2982 if (nid_has_volume(codec
, mix_nid
, HDA_INPUT
))
2983 *mix_val
= HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
);
2984 if (nid_has_mute(codec
, mix_nid
, HDA_INPUT
))
2985 *mute_val
= HDA_COMPOSE_AMP_VAL(mix_nid
, 3, idx
, HDA_INPUT
);
2986 if (*mix_val
&& *mute_val
)
2989 /* check leaf node */
2990 num_conns
= snd_hda_get_conn_list(codec
, mix_nid
, &list
);
2991 if (num_conns
< idx
)
2994 if (!*mix_val
&& nid_has_volume(codec
, nid
, HDA_OUTPUT
) &&
2995 !is_ctl_associated(codec
, nid
, HDA_OUTPUT
, 0, NID_PATH_VOL_CTL
))
2996 *mix_val
= HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_OUTPUT
);
2997 if (!*mute_val
&& nid_has_mute(codec
, nid
, HDA_OUTPUT
) &&
2998 !is_ctl_associated(codec
, nid
, HDA_OUTPUT
, 0, NID_PATH_MUTE_CTL
))
2999 *mute_val
= HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_OUTPUT
);
3001 return *mix_val
|| *mute_val
;
3004 /* create input playback/capture controls for the given pin */
3005 static int new_analog_input(struct hda_codec
*codec
, int input_idx
,
3006 hda_nid_t pin
, const char *ctlname
, int ctlidx
,
3009 struct hda_gen_spec
*spec
= codec
->spec
;
3010 struct nid_path
*path
;
3011 unsigned int mix_val
, mute_val
;
3014 if (!look_for_mix_leaf_ctls(codec
, mix_nid
, pin
, &mix_val
, &mute_val
))
3017 path
= snd_hda_add_new_path(codec
, pin
, mix_nid
, 0);
3020 print_nid_path(codec
, "loopback", path
);
3021 spec
->loopback_paths
[input_idx
] = snd_hda_get_path_idx(codec
, path
);
3023 idx
= path
->idx
[path
->depth
- 1];
3025 err
= __add_pb_vol_ctrl(spec
, HDA_CTL_WIDGET_VOL
, ctlname
, ctlidx
, mix_val
);
3028 path
->ctls
[NID_PATH_VOL_CTL
] = mix_val
;
3032 err
= __add_pb_sw_ctrl(spec
, HDA_CTL_WIDGET_MUTE
, ctlname
, ctlidx
, mute_val
);
3035 path
->ctls
[NID_PATH_MUTE_CTL
] = mute_val
;
3038 path
->active
= true;
3039 path
->stream_enabled
= true; /* no DAC/ADC involved */
3040 err
= add_loopback_list(spec
, mix_nid
, idx
);
3044 if (spec
->mixer_nid
!= spec
->mixer_merge_nid
&&
3045 !spec
->loopback_merge_path
) {
3046 path
= snd_hda_add_new_path(codec
, spec
->mixer_nid
,
3047 spec
->mixer_merge_nid
, 0);
3049 print_nid_path(codec
, "loopback-merge", path
);
3050 path
->active
= true;
3051 path
->pin_fixed
= true; /* static route */
3052 path
->stream_enabled
= true; /* no DAC/ADC involved */
3053 spec
->loopback_merge_path
=
3054 snd_hda_get_path_idx(codec
, path
);
3061 static int is_input_pin(struct hda_codec
*codec
, hda_nid_t nid
)
3063 unsigned int pincap
= snd_hda_query_pin_caps(codec
, nid
);
3064 return (pincap
& AC_PINCAP_IN
) != 0;
3067 /* Parse the codec tree and retrieve ADCs */
3068 static int fill_adc_nids(struct hda_codec
*codec
)
3070 struct hda_gen_spec
*spec
= codec
->spec
;
3072 hda_nid_t
*adc_nids
= spec
->adc_nids
;
3073 int max_nums
= ARRAY_SIZE(spec
->adc_nids
);
3076 for_each_hda_codec_node(nid
, codec
) {
3077 unsigned int caps
= get_wcaps(codec
, nid
);
3078 int type
= get_wcaps_type(caps
);
3080 if (type
!= AC_WID_AUD_IN
|| (caps
& AC_WCAP_DIGITAL
))
3082 adc_nids
[nums
] = nid
;
3083 if (++nums
>= max_nums
)
3086 spec
->num_adc_nids
= nums
;
3088 /* copy the detected ADCs to all_adcs[] */
3089 spec
->num_all_adcs
= nums
;
3090 memcpy(spec
->all_adcs
, spec
->adc_nids
, nums
* sizeof(hda_nid_t
));
3095 /* filter out invalid adc_nids that don't give all active input pins;
3096 * if needed, check whether dynamic ADC-switching is available
3098 static int check_dyn_adc_switch(struct hda_codec
*codec
)
3100 struct hda_gen_spec
*spec
= codec
->spec
;
3101 struct hda_input_mux
*imux
= &spec
->input_mux
;
3102 unsigned int ok_bits
;
3107 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
3108 for (i
= 0; i
< imux
->num_items
; i
++) {
3109 if (!spec
->input_paths
[i
][n
])
3112 if (i
>= imux
->num_items
) {
3113 ok_bits
|= (1 << n
);
3119 /* check whether ADC-switch is possible */
3120 for (i
= 0; i
< imux
->num_items
; i
++) {
3121 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
3122 if (spec
->input_paths
[i
][n
]) {
3123 spec
->dyn_adc_idx
[i
] = n
;
3129 codec_dbg(codec
, "enabling ADC switching\n");
3130 spec
->dyn_adc_switch
= 1;
3131 } else if (nums
!= spec
->num_adc_nids
) {
3132 /* shrink the invalid adcs and input paths */
3134 for (n
= 0; n
< spec
->num_adc_nids
; n
++) {
3135 if (!(ok_bits
& (1 << n
)))
3138 spec
->adc_nids
[nums
] = spec
->adc_nids
[n
];
3139 for (i
= 0; i
< imux
->num_items
; i
++) {
3140 invalidate_nid_path(codec
,
3141 spec
->input_paths
[i
][nums
]);
3142 spec
->input_paths
[i
][nums
] =
3143 spec
->input_paths
[i
][n
];
3148 spec
->num_adc_nids
= nums
;
3151 if (imux
->num_items
== 1 ||
3152 (imux
->num_items
== 2 && spec
->hp_mic
)) {
3153 codec_dbg(codec
, "reducing to a single ADC\n");
3154 spec
->num_adc_nids
= 1; /* reduce to a single ADC */
3157 /* single index for individual volumes ctls */
3158 if (!spec
->dyn_adc_switch
&& spec
->multi_cap_vol
)
3159 spec
->num_adc_nids
= 1;
3164 /* parse capture source paths from the given pin and create imux items */
3165 static int parse_capture_source(struct hda_codec
*codec
, hda_nid_t pin
,
3166 int cfg_idx
, int num_adcs
,
3167 const char *label
, int anchor
)
3169 struct hda_gen_spec
*spec
= codec
->spec
;
3170 struct hda_input_mux
*imux
= &spec
->input_mux
;
3171 int imux_idx
= imux
->num_items
;
3172 bool imux_added
= false;
3175 for (c
= 0; c
< num_adcs
; c
++) {
3176 struct nid_path
*path
;
3177 hda_nid_t adc
= spec
->adc_nids
[c
];
3179 if (!is_reachable_path(codec
, pin
, adc
))
3181 path
= snd_hda_add_new_path(codec
, pin
, adc
, anchor
);
3184 print_nid_path(codec
, "input", path
);
3185 spec
->input_paths
[imux_idx
][c
] =
3186 snd_hda_get_path_idx(codec
, path
);
3189 if (spec
->hp_mic_pin
== pin
)
3190 spec
->hp_mic_mux_idx
= imux
->num_items
;
3191 spec
->imux_pins
[imux
->num_items
] = pin
;
3192 snd_hda_add_imux_item(codec
, imux
, label
, cfg_idx
, NULL
);
3194 if (spec
->dyn_adc_switch
)
3195 spec
->dyn_adc_idx
[imux_idx
] = c
;
3203 * create playback/capture controls for input pins
3206 /* fill the label for each input at first */
3207 static int fill_input_pin_labels(struct hda_codec
*codec
)
3209 struct hda_gen_spec
*spec
= codec
->spec
;
3210 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3213 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
3214 hda_nid_t pin
= cfg
->inputs
[i
].pin
;
3218 if (!is_input_pin(codec
, pin
))
3221 label
= hda_get_autocfg_input_label(codec
, cfg
, i
);
3223 for (j
= i
- 1; j
>= 0; j
--) {
3224 if (spec
->input_labels
[j
] &&
3225 !strcmp(spec
->input_labels
[j
], label
)) {
3226 idx
= spec
->input_label_idxs
[j
] + 1;
3231 spec
->input_labels
[i
] = label
;
3232 spec
->input_label_idxs
[i
] = idx
;
3238 #define CFG_IDX_MIX 99 /* a dummy cfg->input idx for stereo mix */
3240 static int create_input_ctls(struct hda_codec
*codec
)
3242 struct hda_gen_spec
*spec
= codec
->spec
;
3243 const struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3244 hda_nid_t mixer
= spec
->mixer_nid
;
3249 num_adcs
= fill_adc_nids(codec
);
3253 err
= fill_input_pin_labels(codec
);
3257 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
3260 pin
= cfg
->inputs
[i
].pin
;
3261 if (!is_input_pin(codec
, pin
))
3265 if (cfg
->inputs
[i
].type
== AUTO_PIN_MIC
)
3266 val
|= snd_hda_get_default_vref(codec
, pin
);
3267 if (pin
!= spec
->hp_mic_pin
&&
3268 !snd_hda_codec_get_pin_target(codec
, pin
))
3269 set_pin_target(codec
, pin
, val
, false);
3272 if (is_reachable_path(codec
, pin
, mixer
)) {
3273 err
= new_analog_input(codec
, i
, pin
,
3274 spec
->input_labels
[i
],
3275 spec
->input_label_idxs
[i
],
3282 err
= parse_capture_source(codec
, pin
, i
, num_adcs
,
3283 spec
->input_labels
[i
], -mixer
);
3287 if (spec
->add_jack_modes
) {
3288 err
= create_in_jack_mode(codec
, pin
);
3294 /* add stereo mix when explicitly enabled via hint */
3295 if (mixer
&& spec
->add_stereo_mix_input
== HDA_HINT_STEREO_MIX_ENABLE
) {
3296 err
= parse_capture_source(codec
, mixer
, CFG_IDX_MIX
, num_adcs
,
3301 spec
->suppress_auto_mic
= 1;
3312 /* get the input path specified by the given adc and imux indices */
3313 static struct nid_path
*get_input_path(struct hda_codec
*codec
, int adc_idx
, int imux_idx
)
3315 struct hda_gen_spec
*spec
= codec
->spec
;
3316 if (imux_idx
< 0 || imux_idx
>= HDA_MAX_NUM_INPUTS
) {
3320 if (spec
->dyn_adc_switch
)
3321 adc_idx
= spec
->dyn_adc_idx
[imux_idx
];
3322 if (adc_idx
< 0 || adc_idx
>= AUTO_CFG_MAX_INS
) {
3326 return snd_hda_get_path_from_idx(codec
, spec
->input_paths
[imux_idx
][adc_idx
]);
3329 static int mux_select(struct hda_codec
*codec
, unsigned int adc_idx
,
3332 static int mux_enum_info(struct snd_kcontrol
*kcontrol
,
3333 struct snd_ctl_elem_info
*uinfo
)
3335 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3336 struct hda_gen_spec
*spec
= codec
->spec
;
3337 return snd_hda_input_mux_info(&spec
->input_mux
, uinfo
);
3340 static int mux_enum_get(struct snd_kcontrol
*kcontrol
,
3341 struct snd_ctl_elem_value
*ucontrol
)
3343 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3344 struct hda_gen_spec
*spec
= codec
->spec
;
3345 /* the ctls are created at once with multiple counts */
3346 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
3348 ucontrol
->value
.enumerated
.item
[0] = spec
->cur_mux
[adc_idx
];
3352 static int mux_enum_put(struct snd_kcontrol
*kcontrol
,
3353 struct snd_ctl_elem_value
*ucontrol
)
3355 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3356 unsigned int adc_idx
= snd_ctl_get_ioffidx(kcontrol
, &ucontrol
->id
);
3357 return mux_select(codec
, adc_idx
,
3358 ucontrol
->value
.enumerated
.item
[0]);
3361 static const struct snd_kcontrol_new cap_src_temp
= {
3362 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3363 .name
= "Input Source",
3364 .info
= mux_enum_info
,
3365 .get
= mux_enum_get
,
3366 .put
= mux_enum_put
,
3370 * capture volume and capture switch ctls
3373 typedef int (*put_call_t
)(struct snd_kcontrol
*kcontrol
,
3374 struct snd_ctl_elem_value
*ucontrol
);
3376 /* call the given amp update function for all amps in the imux list at once */
3377 static int cap_put_caller(struct snd_kcontrol
*kcontrol
,
3378 struct snd_ctl_elem_value
*ucontrol
,
3379 put_call_t func
, int type
)
3381 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3382 struct hda_gen_spec
*spec
= codec
->spec
;
3383 const struct hda_input_mux
*imux
;
3384 struct nid_path
*path
;
3385 int i
, adc_idx
, err
= 0;
3387 imux
= &spec
->input_mux
;
3388 adc_idx
= kcontrol
->id
.index
;
3389 mutex_lock(&codec
->control_mutex
);
3390 for (i
= 0; i
< imux
->num_items
; i
++) {
3391 path
= get_input_path(codec
, adc_idx
, i
);
3392 if (!path
|| !path
->ctls
[type
])
3394 kcontrol
->private_value
= path
->ctls
[type
];
3395 err
= func(kcontrol
, ucontrol
);
3399 mutex_unlock(&codec
->control_mutex
);
3400 if (err
>= 0 && spec
->cap_sync_hook
)
3401 spec
->cap_sync_hook(codec
, kcontrol
, ucontrol
);
3405 /* capture volume ctl callbacks */
3406 #define cap_vol_info snd_hda_mixer_amp_volume_info
3407 #define cap_vol_get snd_hda_mixer_amp_volume_get
3408 #define cap_vol_tlv snd_hda_mixer_amp_tlv
3410 static int cap_vol_put(struct snd_kcontrol
*kcontrol
,
3411 struct snd_ctl_elem_value
*ucontrol
)
3413 return cap_put_caller(kcontrol
, ucontrol
,
3414 snd_hda_mixer_amp_volume_put
,
3418 static const struct snd_kcontrol_new cap_vol_temp
= {
3419 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3420 .name
= "Capture Volume",
3421 .access
= (SNDRV_CTL_ELEM_ACCESS_READWRITE
|
3422 SNDRV_CTL_ELEM_ACCESS_TLV_READ
|
3423 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK
),
3424 .info
= cap_vol_info
,
3427 .tlv
= { .c
= cap_vol_tlv
},
3430 /* capture switch ctl callbacks */
3431 #define cap_sw_info snd_ctl_boolean_stereo_info
3432 #define cap_sw_get snd_hda_mixer_amp_switch_get
3434 static int cap_sw_put(struct snd_kcontrol
*kcontrol
,
3435 struct snd_ctl_elem_value
*ucontrol
)
3437 return cap_put_caller(kcontrol
, ucontrol
,
3438 snd_hda_mixer_amp_switch_put
,
3442 static const struct snd_kcontrol_new cap_sw_temp
= {
3443 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3444 .name
= "Capture Switch",
3445 .info
= cap_sw_info
,
3450 static int parse_capvol_in_path(struct hda_codec
*codec
, struct nid_path
*path
)
3455 path
->ctls
[NID_PATH_VOL_CTL
] = path
->ctls
[NID_PATH_MUTE_CTL
] = 0;
3456 for (depth
= 0; depth
< 3; depth
++) {
3457 if (depth
>= path
->depth
)
3459 i
= path
->depth
- depth
- 1;
3460 nid
= path
->path
[i
];
3461 if (!path
->ctls
[NID_PATH_VOL_CTL
]) {
3462 if (nid_has_volume(codec
, nid
, HDA_OUTPUT
))
3463 path
->ctls
[NID_PATH_VOL_CTL
] =
3464 HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_OUTPUT
);
3465 else if (nid_has_volume(codec
, nid
, HDA_INPUT
)) {
3466 int idx
= path
->idx
[i
];
3467 if (!depth
&& codec
->single_adc_amp
)
3469 path
->ctls
[NID_PATH_VOL_CTL
] =
3470 HDA_COMPOSE_AMP_VAL(nid
, 3, idx
, HDA_INPUT
);
3473 if (!path
->ctls
[NID_PATH_MUTE_CTL
]) {
3474 if (nid_has_mute(codec
, nid
, HDA_OUTPUT
))
3475 path
->ctls
[NID_PATH_MUTE_CTL
] =
3476 HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_OUTPUT
);
3477 else if (nid_has_mute(codec
, nid
, HDA_INPUT
)) {
3478 int idx
= path
->idx
[i
];
3479 if (!depth
&& codec
->single_adc_amp
)
3481 path
->ctls
[NID_PATH_MUTE_CTL
] =
3482 HDA_COMPOSE_AMP_VAL(nid
, 3, idx
, HDA_INPUT
);
3489 static bool is_inv_dmic_pin(struct hda_codec
*codec
, hda_nid_t nid
)
3491 struct hda_gen_spec
*spec
= codec
->spec
;
3492 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3496 if (!spec
->inv_dmic_split
)
3498 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
3499 if (cfg
->inputs
[i
].pin
!= nid
)
3501 if (cfg
->inputs
[i
].type
!= AUTO_PIN_MIC
)
3503 val
= snd_hda_codec_get_pincfg(codec
, nid
);
3504 return snd_hda_get_input_pin_attr(val
) == INPUT_PIN_ATTR_INT
;
3509 /* capture switch put callback for a single control with hook call */
3510 static int cap_single_sw_put(struct snd_kcontrol
*kcontrol
,
3511 struct snd_ctl_elem_value
*ucontrol
)
3513 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
3514 struct hda_gen_spec
*spec
= codec
->spec
;
3517 ret
= snd_hda_mixer_amp_switch_put(kcontrol
, ucontrol
);
3521 if (spec
->cap_sync_hook
)
3522 spec
->cap_sync_hook(codec
, kcontrol
, ucontrol
);
3527 static int add_single_cap_ctl(struct hda_codec
*codec
, const char *label
,
3528 int idx
, bool is_switch
, unsigned int ctl
,
3531 struct hda_gen_spec
*spec
= codec
->spec
;
3532 char tmpname
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
3533 int type
= is_switch
? HDA_CTL_WIDGET_MUTE
: HDA_CTL_WIDGET_VOL
;
3534 const char *sfx
= is_switch
? "Switch" : "Volume";
3535 unsigned int chs
= inv_dmic
? 1 : 3;
3536 struct snd_kcontrol_new
*knew
;
3542 snprintf(tmpname
, sizeof(tmpname
),
3543 "%s Capture %s", label
, sfx
);
3545 snprintf(tmpname
, sizeof(tmpname
),
3547 knew
= add_control(spec
, type
, tmpname
, idx
,
3548 amp_val_replace_channels(ctl
, chs
));
3552 knew
->put
= cap_single_sw_put
;
3556 /* Make independent right kcontrol */
3558 snprintf(tmpname
, sizeof(tmpname
),
3559 "Inverted %s Capture %s", label
, sfx
);
3561 snprintf(tmpname
, sizeof(tmpname
),
3562 "Inverted Capture %s", sfx
);
3563 knew
= add_control(spec
, type
, tmpname
, idx
,
3564 amp_val_replace_channels(ctl
, 2));
3568 knew
->put
= cap_single_sw_put
;
3572 /* create single (and simple) capture volume and switch controls */
3573 static int create_single_cap_vol_ctl(struct hda_codec
*codec
, int idx
,
3574 unsigned int vol_ctl
, unsigned int sw_ctl
,
3578 err
= add_single_cap_ctl(codec
, NULL
, idx
, false, vol_ctl
, inv_dmic
);
3581 err
= add_single_cap_ctl(codec
, NULL
, idx
, true, sw_ctl
, inv_dmic
);
3587 /* create bound capture volume and switch controls */
3588 static int create_bind_cap_vol_ctl(struct hda_codec
*codec
, int idx
,
3589 unsigned int vol_ctl
, unsigned int sw_ctl
)
3591 struct hda_gen_spec
*spec
= codec
->spec
;
3592 struct snd_kcontrol_new
*knew
;
3595 knew
= snd_hda_gen_add_kctl(spec
, NULL
, &cap_vol_temp
);
3599 knew
->private_value
= vol_ctl
;
3600 knew
->subdevice
= HDA_SUBDEV_AMP_FLAG
;
3603 knew
= snd_hda_gen_add_kctl(spec
, NULL
, &cap_sw_temp
);
3607 knew
->private_value
= sw_ctl
;
3608 knew
->subdevice
= HDA_SUBDEV_AMP_FLAG
;
3613 /* return the vol ctl when used first in the imux list */
3614 static unsigned int get_first_cap_ctl(struct hda_codec
*codec
, int idx
, int type
)
3616 struct nid_path
*path
;
3620 path
= get_input_path(codec
, 0, idx
);
3623 ctl
= path
->ctls
[type
];
3626 for (i
= 0; i
< idx
- 1; i
++) {
3627 path
= get_input_path(codec
, 0, i
);
3628 if (path
&& path
->ctls
[type
] == ctl
)
3634 /* create individual capture volume and switch controls per input */
3635 static int create_multi_cap_vol_ctl(struct hda_codec
*codec
)
3637 struct hda_gen_spec
*spec
= codec
->spec
;
3638 struct hda_input_mux
*imux
= &spec
->input_mux
;
3641 for (i
= 0; i
< imux
->num_items
; i
++) {
3645 idx
= imux
->items
[i
].index
;
3646 if (idx
>= spec
->autocfg
.num_inputs
)
3648 inv_dmic
= is_inv_dmic_pin(codec
, spec
->imux_pins
[i
]);
3650 for (type
= 0; type
< 2; type
++) {
3651 err
= add_single_cap_ctl(codec
,
3652 spec
->input_labels
[idx
],
3653 spec
->input_label_idxs
[idx
],
3655 get_first_cap_ctl(codec
, i
, type
),
3664 static int create_capture_mixers(struct hda_codec
*codec
)
3666 struct hda_gen_spec
*spec
= codec
->spec
;
3667 struct hda_input_mux
*imux
= &spec
->input_mux
;
3668 int i
, n
, nums
, err
;
3670 if (spec
->dyn_adc_switch
)
3673 nums
= spec
->num_adc_nids
;
3675 if (!spec
->auto_mic
&& imux
->num_items
> 1) {
3676 struct snd_kcontrol_new
*knew
;
3678 name
= nums
> 1 ? "Input Source" : "Capture Source";
3679 knew
= snd_hda_gen_add_kctl(spec
, name
, &cap_src_temp
);
3685 for (n
= 0; n
< nums
; n
++) {
3687 bool multi_cap_vol
= spec
->multi_cap_vol
;
3688 bool inv_dmic
= false;
3692 for (i
= 0; i
< imux
->num_items
; i
++) {
3693 struct nid_path
*path
;
3694 path
= get_input_path(codec
, n
, i
);
3697 parse_capvol_in_path(codec
, path
);
3699 vol
= path
->ctls
[NID_PATH_VOL_CTL
];
3700 else if (vol
!= path
->ctls
[NID_PATH_VOL_CTL
]) {
3702 if (!same_amp_caps(codec
, vol
,
3703 path
->ctls
[NID_PATH_VOL_CTL
], HDA_INPUT
))
3704 multi_cap_vol
= true;
3707 sw
= path
->ctls
[NID_PATH_MUTE_CTL
];
3708 else if (sw
!= path
->ctls
[NID_PATH_MUTE_CTL
]) {
3710 if (!same_amp_caps(codec
, sw
,
3711 path
->ctls
[NID_PATH_MUTE_CTL
], HDA_INPUT
))
3712 multi_cap_vol
= true;
3714 if (is_inv_dmic_pin(codec
, spec
->imux_pins
[i
]))
3719 err
= create_single_cap_vol_ctl(codec
, n
, vol
, sw
,
3721 else if (!multi_cap_vol
&& !inv_dmic
)
3722 err
= create_bind_cap_vol_ctl(codec
, n
, vol
, sw
);
3724 err
= create_multi_cap_vol_ctl(codec
);
3733 * add mic boosts if needed
3736 /* check whether the given amp is feasible as a boost volume */
3737 static bool check_boost_vol(struct hda_codec
*codec
, hda_nid_t nid
,
3742 if (!nid_has_volume(codec
, nid
, dir
) ||
3743 is_ctl_associated(codec
, nid
, dir
, idx
, NID_PATH_VOL_CTL
) ||
3744 is_ctl_associated(codec
, nid
, dir
, idx
, NID_PATH_BOOST_CTL
))
3747 step
= (query_amp_caps(codec
, nid
, dir
) & AC_AMPCAP_STEP_SIZE
)
3748 >> AC_AMPCAP_STEP_SIZE_SHIFT
;
3754 /* look for a boost amp in a widget close to the pin */
3755 static unsigned int look_for_boost_amp(struct hda_codec
*codec
,
3756 struct nid_path
*path
)
3758 unsigned int val
= 0;
3762 for (depth
= 0; depth
< 3; depth
++) {
3763 if (depth
>= path
->depth
- 1)
3765 nid
= path
->path
[depth
];
3766 if (depth
&& check_boost_vol(codec
, nid
, HDA_OUTPUT
, 0)) {
3767 val
= HDA_COMPOSE_AMP_VAL(nid
, 3, 0, HDA_OUTPUT
);
3769 } else if (check_boost_vol(codec
, nid
, HDA_INPUT
,
3770 path
->idx
[depth
])) {
3771 val
= HDA_COMPOSE_AMP_VAL(nid
, 3, path
->idx
[depth
],
3780 static int parse_mic_boost(struct hda_codec
*codec
)
3782 struct hda_gen_spec
*spec
= codec
->spec
;
3783 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
3784 struct hda_input_mux
*imux
= &spec
->input_mux
;
3787 if (!spec
->num_adc_nids
)
3790 for (i
= 0; i
< imux
->num_items
; i
++) {
3791 struct nid_path
*path
;
3794 char boost_label
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
3796 idx
= imux
->items
[i
].index
;
3797 if (idx
>= imux
->num_items
)
3800 /* check only line-in and mic pins */
3801 if (cfg
->inputs
[idx
].type
> AUTO_PIN_LINE_IN
)
3804 path
= get_input_path(codec
, 0, i
);
3808 val
= look_for_boost_amp(codec
, path
);
3812 /* create a boost control */
3813 snprintf(boost_label
, sizeof(boost_label
),
3814 "%s Boost Volume", spec
->input_labels
[idx
]);
3815 if (!add_control(spec
, HDA_CTL_WIDGET_VOL
, boost_label
,
3816 spec
->input_label_idxs
[idx
], val
))
3819 path
->ctls
[NID_PATH_BOOST_CTL
] = val
;
3825 * parse digital I/Os and set up NIDs in BIOS auto-parse mode
3827 static void parse_digital(struct hda_codec
*codec
)
3829 struct hda_gen_spec
*spec
= codec
->spec
;
3830 struct nid_path
*path
;
3832 hda_nid_t dig_nid
, pin
;
3834 /* support multiple SPDIFs; the secondary is set up as a slave */
3836 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++) {
3837 pin
= spec
->autocfg
.dig_out_pins
[i
];
3838 dig_nid
= look_for_dac(codec
, pin
, true);
3841 path
= snd_hda_add_new_path(codec
, dig_nid
, pin
, 0);
3844 print_nid_path(codec
, "digout", path
);
3845 path
->active
= true;
3846 path
->pin_fixed
= true; /* no jack detection */
3847 spec
->digout_paths
[i
] = snd_hda_get_path_idx(codec
, path
);
3848 set_pin_target(codec
, pin
, PIN_OUT
, false);
3850 spec
->multiout
.dig_out_nid
= dig_nid
;
3851 spec
->dig_out_type
= spec
->autocfg
.dig_out_type
[0];
3853 spec
->multiout
.slave_dig_outs
= spec
->slave_dig_outs
;
3854 if (nums
>= ARRAY_SIZE(spec
->slave_dig_outs
) - 1)
3856 spec
->slave_dig_outs
[nums
- 1] = dig_nid
;
3861 if (spec
->autocfg
.dig_in_pin
) {
3862 pin
= spec
->autocfg
.dig_in_pin
;
3863 for_each_hda_codec_node(dig_nid
, codec
) {
3864 unsigned int wcaps
= get_wcaps(codec
, dig_nid
);
3865 if (get_wcaps_type(wcaps
) != AC_WID_AUD_IN
)
3867 if (!(wcaps
& AC_WCAP_DIGITAL
))
3869 path
= snd_hda_add_new_path(codec
, pin
, dig_nid
, 0);
3871 print_nid_path(codec
, "digin", path
);
3872 path
->active
= true;
3873 path
->pin_fixed
= true; /* no jack */
3874 spec
->dig_in_nid
= dig_nid
;
3875 spec
->digin_path
= snd_hda_get_path_idx(codec
, path
);
3876 set_pin_target(codec
, pin
, PIN_IN
, false);
3885 * input MUX handling
3888 static bool dyn_adc_pcm_resetup(struct hda_codec
*codec
, int cur
);
3890 /* select the given imux item; either unmute exclusively or select the route */
3891 static int mux_select(struct hda_codec
*codec
, unsigned int adc_idx
,
3894 struct hda_gen_spec
*spec
= codec
->spec
;
3895 const struct hda_input_mux
*imux
;
3896 struct nid_path
*old_path
, *path
;
3898 imux
= &spec
->input_mux
;
3899 if (!imux
->num_items
)
3902 if (idx
>= imux
->num_items
)
3903 idx
= imux
->num_items
- 1;
3904 if (spec
->cur_mux
[adc_idx
] == idx
)
3907 old_path
= get_input_path(codec
, adc_idx
, spec
->cur_mux
[adc_idx
]);
3910 if (old_path
->active
)
3911 snd_hda_activate_path(codec
, old_path
, false, false);
3913 spec
->cur_mux
[adc_idx
] = idx
;
3916 update_hp_mic(codec
, adc_idx
, false);
3918 if (spec
->dyn_adc_switch
)
3919 dyn_adc_pcm_resetup(codec
, idx
);
3921 path
= get_input_path(codec
, adc_idx
, idx
);
3926 snd_hda_activate_path(codec
, path
, true, false);
3927 if (spec
->cap_sync_hook
)
3928 spec
->cap_sync_hook(codec
, NULL
, NULL
);
3929 path_power_down_sync(codec
, old_path
);
3933 /* power up/down widgets in the all paths that match with the given NID
3934 * as terminals (either start- or endpoint)
3936 * returns the last changed NID, or zero if unchanged.
3938 static hda_nid_t
set_path_power(struct hda_codec
*codec
, hda_nid_t nid
,
3939 int pin_state
, int stream_state
)
3941 struct hda_gen_spec
*spec
= codec
->spec
;
3942 hda_nid_t last
, changed
= 0;
3943 struct nid_path
*path
;
3946 for (n
= 0; n
< spec
->paths
.used
; n
++) {
3947 path
= snd_array_elem(&spec
->paths
, n
);
3948 if (path
->path
[0] == nid
||
3949 path
->path
[path
->depth
- 1] == nid
) {
3950 bool pin_old
= path
->pin_enabled
;
3951 bool stream_old
= path
->stream_enabled
;
3954 path
->pin_enabled
= pin_state
;
3955 if (stream_state
>= 0)
3956 path
->stream_enabled
= stream_state
;
3957 if ((!path
->pin_fixed
&& path
->pin_enabled
!= pin_old
)
3958 || path
->stream_enabled
!= stream_old
) {
3959 last
= path_power_update(codec
, path
, true);
3968 /* check the jack status for power control */
3969 static bool detect_pin_state(struct hda_codec
*codec
, hda_nid_t pin
)
3971 if (!is_jack_detectable(codec
, pin
))
3973 return snd_hda_jack_detect_state(codec
, pin
) != HDA_JACK_NOT_PRESENT
;
3976 /* power up/down the paths of the given pin according to the jack state;
3977 * power = 0/1 : only power up/down if it matches with the jack state,
3978 * < 0 : force power up/down to follow the jack sate
3980 * returns the last changed NID, or zero if unchanged.
3982 static hda_nid_t
set_pin_power_jack(struct hda_codec
*codec
, hda_nid_t pin
,
3987 if (!codec
->power_save_node
)
3990 on
= detect_pin_state(codec
, pin
);
3992 if (power
>= 0 && on
!= power
)
3994 return set_path_power(codec
, pin
, on
, -1);
3997 static void pin_power_callback(struct hda_codec
*codec
,
3998 struct hda_jack_callback
*jack
,
4001 if (jack
&& jack
->tbl
->nid
)
4002 sync_power_state_change(codec
,
4003 set_pin_power_jack(codec
, jack
->tbl
->nid
, on
));
4006 /* callback only doing power up -- called at first */
4007 static void pin_power_up_callback(struct hda_codec
*codec
,
4008 struct hda_jack_callback
*jack
)
4010 pin_power_callback(codec
, jack
, true);
4013 /* callback only doing power down -- called at last */
4014 static void pin_power_down_callback(struct hda_codec
*codec
,
4015 struct hda_jack_callback
*jack
)
4017 pin_power_callback(codec
, jack
, false);
4020 /* set up the power up/down callbacks */
4021 static void add_pin_power_ctls(struct hda_codec
*codec
, int num_pins
,
4022 const hda_nid_t
*pins
, bool on
)
4025 hda_jack_callback_fn cb
=
4026 on
? pin_power_up_callback
: pin_power_down_callback
;
4028 for (i
= 0; i
< num_pins
&& pins
[i
]; i
++) {
4029 if (is_jack_detectable(codec
, pins
[i
]))
4030 snd_hda_jack_detect_enable_callback(codec
, pins
[i
], cb
);
4032 set_path_power(codec
, pins
[i
], true, -1);
4036 /* enabled power callback to each available I/O pin with jack detections;
4037 * the digital I/O pins are excluded because of the unreliable detectsion
4039 static void add_all_pin_power_ctls(struct hda_codec
*codec
, bool on
)
4041 struct hda_gen_spec
*spec
= codec
->spec
;
4042 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
4045 if (!codec
->power_save_node
)
4047 add_pin_power_ctls(codec
, cfg
->line_outs
, cfg
->line_out_pins
, on
);
4048 if (cfg
->line_out_type
!= AUTO_PIN_HP_OUT
)
4049 add_pin_power_ctls(codec
, cfg
->hp_outs
, cfg
->hp_pins
, on
);
4050 if (cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
)
4051 add_pin_power_ctls(codec
, cfg
->speaker_outs
, cfg
->speaker_pins
, on
);
4052 for (i
= 0; i
< cfg
->num_inputs
; i
++)
4053 add_pin_power_ctls(codec
, 1, &cfg
->inputs
[i
].pin
, on
);
4056 /* sync path power up/down with the jack states of given pins */
4057 static void sync_pin_power_ctls(struct hda_codec
*codec
, int num_pins
,
4058 const hda_nid_t
*pins
)
4062 for (i
= 0; i
< num_pins
&& pins
[i
]; i
++)
4063 if (is_jack_detectable(codec
, pins
[i
]))
4064 set_pin_power_jack(codec
, pins
[i
], -1);
4067 /* sync path power up/down with pins; called at init and resume */
4068 static void sync_all_pin_power_ctls(struct hda_codec
*codec
)
4070 struct hda_gen_spec
*spec
= codec
->spec
;
4071 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
4074 if (!codec
->power_save_node
)
4076 sync_pin_power_ctls(codec
, cfg
->line_outs
, cfg
->line_out_pins
);
4077 if (cfg
->line_out_type
!= AUTO_PIN_HP_OUT
)
4078 sync_pin_power_ctls(codec
, cfg
->hp_outs
, cfg
->hp_pins
);
4079 if (cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
)
4080 sync_pin_power_ctls(codec
, cfg
->speaker_outs
, cfg
->speaker_pins
);
4081 for (i
= 0; i
< cfg
->num_inputs
; i
++)
4082 sync_pin_power_ctls(codec
, 1, &cfg
->inputs
[i
].pin
);
4085 /* add fake paths if not present yet */
4086 static int add_fake_paths(struct hda_codec
*codec
, hda_nid_t nid
,
4087 int num_pins
, const hda_nid_t
*pins
)
4089 struct hda_gen_spec
*spec
= codec
->spec
;
4090 struct nid_path
*path
;
4093 for (i
= 0; i
< num_pins
; i
++) {
4096 if (get_nid_path(codec
, nid
, pins
[i
], 0))
4098 path
= snd_array_new(&spec
->paths
);
4101 memset(path
, 0, sizeof(*path
));
4103 path
->path
[0] = nid
;
4104 path
->path
[1] = pins
[i
];
4105 path
->active
= true;
4110 /* create fake paths to all outputs from beep */
4111 static int add_fake_beep_paths(struct hda_codec
*codec
)
4113 struct hda_gen_spec
*spec
= codec
->spec
;
4114 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
4115 hda_nid_t nid
= spec
->beep_nid
;
4118 if (!codec
->power_save_node
|| !nid
)
4120 err
= add_fake_paths(codec
, nid
, cfg
->line_outs
, cfg
->line_out_pins
);
4123 if (cfg
->line_out_type
!= AUTO_PIN_HP_OUT
) {
4124 err
= add_fake_paths(codec
, nid
, cfg
->hp_outs
, cfg
->hp_pins
);
4128 if (cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
) {
4129 err
= add_fake_paths(codec
, nid
, cfg
->speaker_outs
,
4137 /* power up/down beep widget and its output paths */
4138 static void beep_power_hook(struct hda_beep
*beep
, bool on
)
4140 set_path_power(beep
->codec
, beep
->nid
, -1, on
);
4144 * snd_hda_gen_fix_pin_power - Fix the power of the given pin widget to D0
4145 * @codec: the HDA codec
4146 * @pin: NID of pin to fix
4148 int snd_hda_gen_fix_pin_power(struct hda_codec
*codec
, hda_nid_t pin
)
4150 struct hda_gen_spec
*spec
= codec
->spec
;
4151 struct nid_path
*path
;
4153 path
= snd_array_new(&spec
->paths
);
4156 memset(path
, 0, sizeof(*path
));
4158 path
->path
[0] = pin
;
4159 path
->active
= true;
4160 path
->pin_fixed
= true;
4161 path
->stream_enabled
= true;
4164 EXPORT_SYMBOL_GPL(snd_hda_gen_fix_pin_power
);
4167 * Jack detections for HP auto-mute and mic-switch
4170 /* check each pin in the given array; returns true if any of them is plugged */
4171 static bool detect_jacks(struct hda_codec
*codec
, int num_pins
, hda_nid_t
*pins
)
4174 bool present
= false;
4176 for (i
= 0; i
< num_pins
; i
++) {
4177 hda_nid_t nid
= pins
[i
];
4180 /* don't detect pins retasked as inputs */
4181 if (snd_hda_codec_get_pin_target(codec
, nid
) & AC_PINCTL_IN_EN
)
4183 if (snd_hda_jack_detect_state(codec
, nid
) == HDA_JACK_PRESENT
)
4189 /* standard HP/line-out auto-mute helper */
4190 static void do_automute(struct hda_codec
*codec
, int num_pins
, hda_nid_t
*pins
,
4191 int *paths
, bool mute
)
4193 struct hda_gen_spec
*spec
= codec
->spec
;
4196 for (i
= 0; i
< num_pins
; i
++) {
4197 hda_nid_t nid
= pins
[i
];
4198 unsigned int val
, oldval
;
4202 oldval
= snd_hda_codec_get_pin_target(codec
, nid
);
4203 if (oldval
& PIN_IN
)
4204 continue; /* no mute for inputs */
4206 if (spec
->auto_mute_via_amp
) {
4207 struct nid_path
*path
;
4210 path
= snd_hda_get_path_from_idx(codec
, paths
[i
]);
4213 mute_nid
= get_amp_nid_(path
->ctls
[NID_PATH_MUTE_CTL
]);
4217 spec
->mute_bits
|= (1ULL << mute_nid
);
4219 spec
->mute_bits
&= ~(1ULL << mute_nid
);
4222 /* don't reset VREF value in case it's controlling
4223 * the amp (see alc861_fixup_asus_amp_vref_0f())
4225 if (spec
->keep_vref_in_automute
)
4226 val
= oldval
& ~PIN_HP
;
4231 /* here we call update_pin_ctl() so that the pinctl is
4232 * changed without changing the pinctl target value;
4233 * the original target value will be still referred at
4234 * the init / resume again
4236 update_pin_ctl(codec
, nid
, val
);
4239 set_pin_eapd(codec
, nid
, !mute
);
4240 if (codec
->power_save_node
) {
4243 on
= detect_pin_state(codec
, nid
);
4244 set_path_power(codec
, nid
, on
, -1);
4250 * snd_hda_gen_update_outputs - Toggle outputs muting
4251 * @codec: the HDA codec
4253 * Update the mute status of all outputs based on the current jack states.
4255 void snd_hda_gen_update_outputs(struct hda_codec
*codec
)
4257 struct hda_gen_spec
*spec
= codec
->spec
;
4261 /* Control HP pins/amps depending on master_mute state;
4262 * in general, HP pins/amps control should be enabled in all cases,
4263 * but currently set only for master_mute, just to be safe
4265 if (spec
->autocfg
.line_out_type
== AUTO_PIN_HP_OUT
)
4266 paths
= spec
->out_paths
;
4268 paths
= spec
->hp_paths
;
4269 do_automute(codec
, ARRAY_SIZE(spec
->autocfg
.hp_pins
),
4270 spec
->autocfg
.hp_pins
, paths
, spec
->master_mute
);
4272 if (!spec
->automute_speaker
)
4275 on
= spec
->hp_jack_present
| spec
->line_jack_present
;
4276 on
|= spec
->master_mute
;
4277 spec
->speaker_muted
= on
;
4278 if (spec
->autocfg
.line_out_type
== AUTO_PIN_SPEAKER_OUT
)
4279 paths
= spec
->out_paths
;
4281 paths
= spec
->speaker_paths
;
4282 do_automute(codec
, ARRAY_SIZE(spec
->autocfg
.speaker_pins
),
4283 spec
->autocfg
.speaker_pins
, paths
, on
);
4285 /* toggle line-out mutes if needed, too */
4286 /* if LO is a copy of either HP or Speaker, don't need to handle it */
4287 if (spec
->autocfg
.line_out_pins
[0] == spec
->autocfg
.hp_pins
[0] ||
4288 spec
->autocfg
.line_out_pins
[0] == spec
->autocfg
.speaker_pins
[0])
4290 if (!spec
->automute_lo
)
4293 on
= spec
->hp_jack_present
;
4294 on
|= spec
->master_mute
;
4295 spec
->line_out_muted
= on
;
4296 paths
= spec
->out_paths
;
4297 do_automute(codec
, ARRAY_SIZE(spec
->autocfg
.line_out_pins
),
4298 spec
->autocfg
.line_out_pins
, paths
, on
);
4300 EXPORT_SYMBOL_GPL(snd_hda_gen_update_outputs
);
4302 static void call_update_outputs(struct hda_codec
*codec
)
4304 struct hda_gen_spec
*spec
= codec
->spec
;
4305 if (spec
->automute_hook
)
4306 spec
->automute_hook(codec
);
4308 snd_hda_gen_update_outputs(codec
);
4310 /* sync the whole vmaster slaves to reflect the new auto-mute status */
4311 if (spec
->auto_mute_via_amp
&& !codec
->bus
->shutdown
)
4312 snd_ctl_sync_vmaster(spec
->vmaster_mute
.sw_kctl
, false);
4316 * snd_hda_gen_hp_automute - standard HP-automute helper
4317 * @codec: the HDA codec
4318 * @jack: jack object, NULL for the whole
4320 void snd_hda_gen_hp_automute(struct hda_codec
*codec
,
4321 struct hda_jack_callback
*jack
)
4323 struct hda_gen_spec
*spec
= codec
->spec
;
4324 hda_nid_t
*pins
= spec
->autocfg
.hp_pins
;
4325 int num_pins
= ARRAY_SIZE(spec
->autocfg
.hp_pins
);
4327 /* No detection for the first HP jack during indep-HP mode */
4328 if (spec
->indep_hp_enabled
) {
4333 spec
->hp_jack_present
= detect_jacks(codec
, num_pins
, pins
);
4334 if (!spec
->detect_hp
|| (!spec
->automute_speaker
&& !spec
->automute_lo
))
4336 call_update_outputs(codec
);
4338 EXPORT_SYMBOL_GPL(snd_hda_gen_hp_automute
);
4341 * snd_hda_gen_line_automute - standard line-out-automute helper
4342 * @codec: the HDA codec
4343 * @jack: jack object, NULL for the whole
4345 void snd_hda_gen_line_automute(struct hda_codec
*codec
,
4346 struct hda_jack_callback
*jack
)
4348 struct hda_gen_spec
*spec
= codec
->spec
;
4350 if (spec
->autocfg
.line_out_type
== AUTO_PIN_SPEAKER_OUT
)
4352 /* check LO jack only when it's different from HP */
4353 if (spec
->autocfg
.line_out_pins
[0] == spec
->autocfg
.hp_pins
[0])
4356 spec
->line_jack_present
=
4357 detect_jacks(codec
, ARRAY_SIZE(spec
->autocfg
.line_out_pins
),
4358 spec
->autocfg
.line_out_pins
);
4359 if (!spec
->automute_speaker
|| !spec
->detect_lo
)
4361 call_update_outputs(codec
);
4363 EXPORT_SYMBOL_GPL(snd_hda_gen_line_automute
);
4366 * snd_hda_gen_mic_autoswitch - standard mic auto-switch helper
4367 * @codec: the HDA codec
4368 * @jack: jack object, NULL for the whole
4370 void snd_hda_gen_mic_autoswitch(struct hda_codec
*codec
,
4371 struct hda_jack_callback
*jack
)
4373 struct hda_gen_spec
*spec
= codec
->spec
;
4376 if (!spec
->auto_mic
)
4379 for (i
= spec
->am_num_entries
- 1; i
> 0; i
--) {
4380 hda_nid_t pin
= spec
->am_entry
[i
].pin
;
4381 /* don't detect pins retasked as outputs */
4382 if (snd_hda_codec_get_pin_target(codec
, pin
) & AC_PINCTL_OUT_EN
)
4384 if (snd_hda_jack_detect_state(codec
, pin
) == HDA_JACK_PRESENT
) {
4385 mux_select(codec
, 0, spec
->am_entry
[i
].idx
);
4389 mux_select(codec
, 0, spec
->am_entry
[0].idx
);
4391 EXPORT_SYMBOL_GPL(snd_hda_gen_mic_autoswitch
);
4393 /* call appropriate hooks */
4394 static void call_hp_automute(struct hda_codec
*codec
,
4395 struct hda_jack_callback
*jack
)
4397 struct hda_gen_spec
*spec
= codec
->spec
;
4398 if (spec
->hp_automute_hook
)
4399 spec
->hp_automute_hook(codec
, jack
);
4401 snd_hda_gen_hp_automute(codec
, jack
);
4404 static void call_line_automute(struct hda_codec
*codec
,
4405 struct hda_jack_callback
*jack
)
4407 struct hda_gen_spec
*spec
= codec
->spec
;
4408 if (spec
->line_automute_hook
)
4409 spec
->line_automute_hook(codec
, jack
);
4411 snd_hda_gen_line_automute(codec
, jack
);
4414 static void call_mic_autoswitch(struct hda_codec
*codec
,
4415 struct hda_jack_callback
*jack
)
4417 struct hda_gen_spec
*spec
= codec
->spec
;
4418 if (spec
->mic_autoswitch_hook
)
4419 spec
->mic_autoswitch_hook(codec
, jack
);
4421 snd_hda_gen_mic_autoswitch(codec
, jack
);
4424 /* update jack retasking */
4425 static void update_automute_all(struct hda_codec
*codec
)
4427 call_hp_automute(codec
, NULL
);
4428 call_line_automute(codec
, NULL
);
4429 call_mic_autoswitch(codec
, NULL
);
4433 * Auto-Mute mode mixer enum support
4435 static int automute_mode_info(struct snd_kcontrol
*kcontrol
,
4436 struct snd_ctl_elem_info
*uinfo
)
4438 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
4439 struct hda_gen_spec
*spec
= codec
->spec
;
4440 static const char * const texts3
[] = {
4441 "Disabled", "Speaker Only", "Line Out+Speaker"
4444 if (spec
->automute_speaker_possible
&& spec
->automute_lo_possible
)
4445 return snd_hda_enum_helper_info(kcontrol
, uinfo
, 3, texts3
);
4446 return snd_hda_enum_bool_helper_info(kcontrol
, uinfo
);
4449 static int automute_mode_get(struct snd_kcontrol
*kcontrol
,
4450 struct snd_ctl_elem_value
*ucontrol
)
4452 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
4453 struct hda_gen_spec
*spec
= codec
->spec
;
4454 unsigned int val
= 0;
4455 if (spec
->automute_speaker
)
4457 if (spec
->automute_lo
)
4460 ucontrol
->value
.enumerated
.item
[0] = val
;
4464 static int automute_mode_put(struct snd_kcontrol
*kcontrol
,
4465 struct snd_ctl_elem_value
*ucontrol
)
4467 struct hda_codec
*codec
= snd_kcontrol_chip(kcontrol
);
4468 struct hda_gen_spec
*spec
= codec
->spec
;
4470 switch (ucontrol
->value
.enumerated
.item
[0]) {
4472 if (!spec
->automute_speaker
&& !spec
->automute_lo
)
4474 spec
->automute_speaker
= 0;
4475 spec
->automute_lo
= 0;
4478 if (spec
->automute_speaker_possible
) {
4479 if (!spec
->automute_lo
&& spec
->automute_speaker
)
4481 spec
->automute_speaker
= 1;
4482 spec
->automute_lo
= 0;
4483 } else if (spec
->automute_lo_possible
) {
4484 if (spec
->automute_lo
)
4486 spec
->automute_lo
= 1;
4491 if (!spec
->automute_lo_possible
|| !spec
->automute_speaker_possible
)
4493 if (spec
->automute_speaker
&& spec
->automute_lo
)
4495 spec
->automute_speaker
= 1;
4496 spec
->automute_lo
= 1;
4501 call_update_outputs(codec
);
4505 static const struct snd_kcontrol_new automute_mode_enum
= {
4506 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
4507 .name
= "Auto-Mute Mode",
4508 .info
= automute_mode_info
,
4509 .get
= automute_mode_get
,
4510 .put
= automute_mode_put
,
4513 static int add_automute_mode_enum(struct hda_codec
*codec
)
4515 struct hda_gen_spec
*spec
= codec
->spec
;
4517 if (!snd_hda_gen_add_kctl(spec
, NULL
, &automute_mode_enum
))
4523 * Check the availability of HP/line-out auto-mute;
4524 * Set up appropriately if really supported
4526 static int check_auto_mute_availability(struct hda_codec
*codec
)
4528 struct hda_gen_spec
*spec
= codec
->spec
;
4529 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
4533 if (spec
->suppress_auto_mute
)
4536 if (cfg
->hp_pins
[0])
4538 if (cfg
->line_out_pins
[0])
4540 if (cfg
->speaker_pins
[0])
4542 if (present
< 2) /* need two different output types */
4545 if (!cfg
->speaker_pins
[0] &&
4546 cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
) {
4547 memcpy(cfg
->speaker_pins
, cfg
->line_out_pins
,
4548 sizeof(cfg
->speaker_pins
));
4549 cfg
->speaker_outs
= cfg
->line_outs
;
4552 if (!cfg
->hp_pins
[0] &&
4553 cfg
->line_out_type
== AUTO_PIN_HP_OUT
) {
4554 memcpy(cfg
->hp_pins
, cfg
->line_out_pins
,
4555 sizeof(cfg
->hp_pins
));
4556 cfg
->hp_outs
= cfg
->line_outs
;
4559 for (i
= 0; i
< cfg
->hp_outs
; i
++) {
4560 hda_nid_t nid
= cfg
->hp_pins
[i
];
4561 if (!is_jack_detectable(codec
, nid
))
4563 codec_dbg(codec
, "Enable HP auto-muting on NID 0x%x\n", nid
);
4564 snd_hda_jack_detect_enable_callback(codec
, nid
,
4566 spec
->detect_hp
= 1;
4569 if (cfg
->line_out_type
== AUTO_PIN_LINE_OUT
&& cfg
->line_outs
) {
4570 if (cfg
->speaker_outs
)
4571 for (i
= 0; i
< cfg
->line_outs
; i
++) {
4572 hda_nid_t nid
= cfg
->line_out_pins
[i
];
4573 if (!is_jack_detectable(codec
, nid
))
4575 codec_dbg(codec
, "Enable Line-Out auto-muting on NID 0x%x\n", nid
);
4576 snd_hda_jack_detect_enable_callback(codec
, nid
,
4577 call_line_automute
);
4578 spec
->detect_lo
= 1;
4580 spec
->automute_lo_possible
= spec
->detect_hp
;
4583 spec
->automute_speaker_possible
= cfg
->speaker_outs
&&
4584 (spec
->detect_hp
|| spec
->detect_lo
);
4586 spec
->automute_lo
= spec
->automute_lo_possible
;
4587 spec
->automute_speaker
= spec
->automute_speaker_possible
;
4589 if (spec
->automute_speaker_possible
|| spec
->automute_lo_possible
) {
4590 /* create a control for automute mode */
4591 err
= add_automute_mode_enum(codec
);
4598 /* check whether all auto-mic pins are valid; setup indices if OK */
4599 static bool auto_mic_check_imux(struct hda_codec
*codec
)
4601 struct hda_gen_spec
*spec
= codec
->spec
;
4602 const struct hda_input_mux
*imux
;
4605 imux
= &spec
->input_mux
;
4606 for (i
= 0; i
< spec
->am_num_entries
; i
++) {
4607 spec
->am_entry
[i
].idx
=
4608 find_idx_in_nid_list(spec
->am_entry
[i
].pin
,
4609 spec
->imux_pins
, imux
->num_items
);
4610 if (spec
->am_entry
[i
].idx
< 0)
4611 return false; /* no corresponding imux */
4614 /* we don't need the jack detection for the first pin */
4615 for (i
= 1; i
< spec
->am_num_entries
; i
++)
4616 snd_hda_jack_detect_enable_callback(codec
,
4617 spec
->am_entry
[i
].pin
,
4618 call_mic_autoswitch
);
4622 static int compare_attr(const void *ap
, const void *bp
)
4624 const struct automic_entry
*a
= ap
;
4625 const struct automic_entry
*b
= bp
;
4626 return (int)(a
->attr
- b
->attr
);
4630 * Check the availability of auto-mic switch;
4631 * Set up if really supported
4633 static int check_auto_mic_availability(struct hda_codec
*codec
)
4635 struct hda_gen_spec
*spec
= codec
->spec
;
4636 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
4640 if (spec
->suppress_auto_mic
)
4645 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
4646 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
4648 attr
= snd_hda_codec_get_pincfg(codec
, nid
);
4649 attr
= snd_hda_get_input_pin_attr(attr
);
4650 if (types
& (1 << attr
))
4651 return 0; /* already occupied */
4653 case INPUT_PIN_ATTR_INT
:
4654 if (cfg
->inputs
[i
].type
!= AUTO_PIN_MIC
)
4655 return 0; /* invalid type */
4657 case INPUT_PIN_ATTR_UNUSED
:
4658 return 0; /* invalid entry */
4660 if (cfg
->inputs
[i
].type
> AUTO_PIN_LINE_IN
)
4661 return 0; /* invalid type */
4662 if (!spec
->line_in_auto_switch
&&
4663 cfg
->inputs
[i
].type
!= AUTO_PIN_MIC
)
4664 return 0; /* only mic is allowed */
4665 if (!is_jack_detectable(codec
, nid
))
4666 return 0; /* no unsol support */
4669 if (num_pins
>= MAX_AUTO_MIC_PINS
)
4671 types
|= (1 << attr
);
4672 spec
->am_entry
[num_pins
].pin
= nid
;
4673 spec
->am_entry
[num_pins
].attr
= attr
;
4680 spec
->am_num_entries
= num_pins
;
4681 /* sort the am_entry in the order of attr so that the pin with a
4682 * higher attr will be selected when the jack is plugged.
4684 sort(spec
->am_entry
, num_pins
, sizeof(spec
->am_entry
[0]),
4685 compare_attr
, NULL
);
4687 if (!auto_mic_check_imux(codec
))
4691 spec
->num_adc_nids
= 1;
4692 spec
->cur_mux
[0] = spec
->am_entry
[0].idx
;
4693 codec_dbg(codec
, "Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
4694 spec
->am_entry
[0].pin
,
4695 spec
->am_entry
[1].pin
,
4696 spec
->am_entry
[2].pin
);
4702 * snd_hda_gen_path_power_filter - power_filter hook to make inactive widgets
4704 * @codec: the HDA codec
4705 * @nid: NID to evalute
4706 * @power_state: target power state
4708 unsigned int snd_hda_gen_path_power_filter(struct hda_codec
*codec
,
4710 unsigned int power_state
)
4712 struct hda_gen_spec
*spec
= codec
->spec
;
4714 if (!spec
->power_down_unused
&& !codec
->power_save_node
)
4716 if (power_state
!= AC_PWRST_D0
|| nid
== codec
->core
.afg
)
4718 if (get_wcaps_type(get_wcaps(codec
, nid
)) >= AC_WID_POWER
)
4720 if (is_active_nid_for_any(codec
, nid
))
4724 EXPORT_SYMBOL_GPL(snd_hda_gen_path_power_filter
);
4726 /* mute all aamix inputs initially; parse up to the first leaves */
4727 static void mute_all_mixer_nid(struct hda_codec
*codec
, hda_nid_t mix
)
4730 const hda_nid_t
*conn
;
4733 nums
= snd_hda_get_conn_list(codec
, mix
, &conn
);
4734 has_amp
= nid_has_mute(codec
, mix
, HDA_INPUT
);
4735 for (i
= 0; i
< nums
; i
++) {
4737 update_amp(codec
, mix
, HDA_INPUT
, i
,
4738 0xff, HDA_AMP_MUTE
);
4739 else if (nid_has_volume(codec
, conn
[i
], HDA_OUTPUT
))
4740 update_amp(codec
, conn
[i
], HDA_OUTPUT
, 0,
4741 0xff, HDA_AMP_MUTE
);
4746 * snd_hda_gen_stream_pm - Stream power management callback
4747 * @codec: the HDA codec
4748 * @nid: audio widget
4749 * @on: power on/off flag
4751 * Set this in patch_ops.stream_pm. Only valid with power_save_node flag.
4753 void snd_hda_gen_stream_pm(struct hda_codec
*codec
, hda_nid_t nid
, bool on
)
4755 if (codec
->power_save_node
)
4756 set_path_power(codec
, nid
, -1, on
);
4758 EXPORT_SYMBOL_GPL(snd_hda_gen_stream_pm
);
4761 * snd_hda_gen_parse_auto_config - Parse the given BIOS configuration and
4762 * set up the hda_gen_spec
4763 * @codec: the HDA codec
4764 * @cfg: Parsed pin configuration
4766 * return 1 if successful, 0 if the proper config is not found,
4767 * or a negative error code
4769 int snd_hda_gen_parse_auto_config(struct hda_codec
*codec
,
4770 struct auto_pin_cfg
*cfg
)
4772 struct hda_gen_spec
*spec
= codec
->spec
;
4775 parse_user_hints(codec
);
4777 if (spec
->mixer_nid
&& !spec
->mixer_merge_nid
)
4778 spec
->mixer_merge_nid
= spec
->mixer_nid
;
4780 if (cfg
!= &spec
->autocfg
) {
4781 spec
->autocfg
= *cfg
;
4782 cfg
= &spec
->autocfg
;
4785 if (!spec
->main_out_badness
)
4786 spec
->main_out_badness
= &hda_main_out_badness
;
4787 if (!spec
->extra_out_badness
)
4788 spec
->extra_out_badness
= &hda_extra_out_badness
;
4790 fill_all_dac_nids(codec
);
4792 if (!cfg
->line_outs
) {
4793 if (cfg
->dig_outs
|| cfg
->dig_in_pin
) {
4794 spec
->multiout
.max_channels
= 2;
4795 spec
->no_analog
= 1;
4798 if (!cfg
->num_inputs
&& !cfg
->dig_in_pin
)
4799 return 0; /* can't find valid BIOS pin config */
4802 if (!spec
->no_primary_hp
&&
4803 cfg
->line_out_type
== AUTO_PIN_SPEAKER_OUT
&&
4804 cfg
->line_outs
<= cfg
->hp_outs
) {
4805 /* use HP as primary out */
4806 cfg
->speaker_outs
= cfg
->line_outs
;
4807 memcpy(cfg
->speaker_pins
, cfg
->line_out_pins
,
4808 sizeof(cfg
->speaker_pins
));
4809 cfg
->line_outs
= cfg
->hp_outs
;
4810 memcpy(cfg
->line_out_pins
, cfg
->hp_pins
, sizeof(cfg
->hp_pins
));
4812 memset(cfg
->hp_pins
, 0, sizeof(cfg
->hp_pins
));
4813 cfg
->line_out_type
= AUTO_PIN_HP_OUT
;
4816 err
= parse_output_paths(codec
);
4819 err
= create_multi_channel_mode(codec
);
4822 err
= create_multi_out_ctls(codec
, cfg
);
4825 err
= create_hp_out_ctls(codec
);
4828 err
= create_speaker_out_ctls(codec
);
4831 err
= create_indep_hp_ctls(codec
);
4834 err
= create_loopback_mixing_ctl(codec
);
4837 err
= create_hp_mic(codec
);
4840 err
= create_input_ctls(codec
);
4844 /* add power-down pin callbacks at first */
4845 add_all_pin_power_ctls(codec
, false);
4847 spec
->const_channel_count
= spec
->ext_channel_count
;
4848 /* check the multiple speaker and headphone pins */
4849 if (cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
)
4850 spec
->const_channel_count
= max(spec
->const_channel_count
,
4851 cfg
->speaker_outs
* 2);
4852 if (cfg
->line_out_type
!= AUTO_PIN_HP_OUT
)
4853 spec
->const_channel_count
= max(spec
->const_channel_count
,
4855 spec
->multiout
.max_channels
= max(spec
->ext_channel_count
,
4856 spec
->const_channel_count
);
4858 err
= check_auto_mute_availability(codec
);
4862 err
= check_dyn_adc_switch(codec
);
4866 err
= check_auto_mic_availability(codec
);
4870 /* add stereo mix if available and not enabled yet */
4871 if (!spec
->auto_mic
&& spec
->mixer_nid
&&
4872 spec
->add_stereo_mix_input
== HDA_HINT_STEREO_MIX_AUTO
&&
4873 spec
->input_mux
.num_items
> 1) {
4874 err
= parse_capture_source(codec
, spec
->mixer_nid
,
4875 CFG_IDX_MIX
, spec
->num_all_adcs
,
4882 err
= create_capture_mixers(codec
);
4886 err
= parse_mic_boost(codec
);
4890 /* create "Headphone Mic Jack Mode" if no input selection is
4891 * available (or user specifies add_jack_modes hint)
4893 if (spec
->hp_mic_pin
&&
4894 (spec
->auto_mic
|| spec
->input_mux
.num_items
== 1 ||
4895 spec
->add_jack_modes
)) {
4896 err
= create_hp_mic_jack_mode(codec
, spec
->hp_mic_pin
);
4901 if (spec
->add_jack_modes
) {
4902 if (cfg
->line_out_type
!= AUTO_PIN_SPEAKER_OUT
) {
4903 err
= create_out_jack_modes(codec
, cfg
->line_outs
,
4904 cfg
->line_out_pins
);
4908 if (cfg
->line_out_type
!= AUTO_PIN_HP_OUT
) {
4909 err
= create_out_jack_modes(codec
, cfg
->hp_outs
,
4916 /* add power-up pin callbacks at last */
4917 add_all_pin_power_ctls(codec
, true);
4919 /* mute all aamix input initially */
4920 if (spec
->mixer_nid
)
4921 mute_all_mixer_nid(codec
, spec
->mixer_nid
);
4924 parse_digital(codec
);
4926 if (spec
->power_down_unused
|| codec
->power_save_node
) {
4927 if (!codec
->power_filter
)
4928 codec
->power_filter
= snd_hda_gen_path_power_filter
;
4929 if (!codec
->patch_ops
.stream_pm
)
4930 codec
->patch_ops
.stream_pm
= snd_hda_gen_stream_pm
;
4933 if (!spec
->no_analog
&& spec
->beep_nid
) {
4934 err
= snd_hda_attach_beep_device(codec
, spec
->beep_nid
);
4937 if (codec
->beep
&& codec
->power_save_node
) {
4938 err
= add_fake_beep_paths(codec
);
4941 codec
->beep
->power_hook
= beep_power_hook
;
4947 EXPORT_SYMBOL_GPL(snd_hda_gen_parse_auto_config
);
4951 * Build control elements
4954 /* slave controls for virtual master */
4955 static const char * const slave_pfxs
[] = {
4956 "Front", "Surround", "Center", "LFE", "Side",
4957 "Headphone", "Speaker", "Mono", "Line Out",
4958 "CLFE", "Bass Speaker", "PCM",
4959 "Speaker Front", "Speaker Surround", "Speaker CLFE", "Speaker Side",
4960 "Headphone Front", "Headphone Surround", "Headphone CLFE",
4961 "Headphone Side", "Headphone+LO", "Speaker+LO",
4966 * snd_hda_gen_build_controls - Build controls from the parsed results
4967 * @codec: the HDA codec
4969 * Pass this to build_controls patch_ops.
4971 int snd_hda_gen_build_controls(struct hda_codec
*codec
)
4973 struct hda_gen_spec
*spec
= codec
->spec
;
4976 if (spec
->kctls
.used
) {
4977 err
= snd_hda_add_new_ctls(codec
, spec
->kctls
.list
);
4982 if (spec
->multiout
.dig_out_nid
) {
4983 err
= snd_hda_create_dig_out_ctls(codec
,
4984 spec
->multiout
.dig_out_nid
,
4985 spec
->multiout
.dig_out_nid
,
4986 spec
->pcm_rec
[1]->pcm_type
);
4989 if (!spec
->no_analog
) {
4990 err
= snd_hda_create_spdif_share_sw(codec
,
4994 spec
->multiout
.share_spdif
= 1;
4997 if (spec
->dig_in_nid
) {
4998 err
= snd_hda_create_spdif_in_ctls(codec
, spec
->dig_in_nid
);
5003 /* if we have no master control, let's create it */
5004 if (!spec
->no_analog
&&
5005 !snd_hda_find_mixer_ctl(codec
, "Master Playback Volume")) {
5006 err
= snd_hda_add_vmaster(codec
, "Master Playback Volume",
5007 spec
->vmaster_tlv
, slave_pfxs
,
5012 if (!spec
->no_analog
&&
5013 !snd_hda_find_mixer_ctl(codec
, "Master Playback Switch")) {
5014 err
= __snd_hda_add_vmaster(codec
, "Master Playback Switch",
5017 true, &spec
->vmaster_mute
.sw_kctl
);
5020 if (spec
->vmaster_mute
.hook
) {
5021 snd_hda_add_vmaster_hook(codec
, &spec
->vmaster_mute
,
5022 spec
->vmaster_mute_enum
);
5023 snd_hda_sync_vmaster_hook(&spec
->vmaster_mute
);
5027 free_kctls(spec
); /* no longer needed */
5029 err
= snd_hda_jack_add_kctls(codec
, &spec
->autocfg
);
5035 EXPORT_SYMBOL_GPL(snd_hda_gen_build_controls
);
5042 static void call_pcm_playback_hook(struct hda_pcm_stream
*hinfo
,
5043 struct hda_codec
*codec
,
5044 struct snd_pcm_substream
*substream
,
5047 struct hda_gen_spec
*spec
= codec
->spec
;
5048 if (spec
->pcm_playback_hook
)
5049 spec
->pcm_playback_hook(hinfo
, codec
, substream
, action
);
5052 static void call_pcm_capture_hook(struct hda_pcm_stream
*hinfo
,
5053 struct hda_codec
*codec
,
5054 struct snd_pcm_substream
*substream
,
5057 struct hda_gen_spec
*spec
= codec
->spec
;
5058 if (spec
->pcm_capture_hook
)
5059 spec
->pcm_capture_hook(hinfo
, codec
, substream
, action
);
5063 * Analog playback callbacks
5065 static int playback_pcm_open(struct hda_pcm_stream
*hinfo
,
5066 struct hda_codec
*codec
,
5067 struct snd_pcm_substream
*substream
)
5069 struct hda_gen_spec
*spec
= codec
->spec
;
5072 mutex_lock(&spec
->pcm_mutex
);
5073 err
= snd_hda_multi_out_analog_open(codec
,
5074 &spec
->multiout
, substream
,
5077 spec
->active_streams
|= 1 << STREAM_MULTI_OUT
;
5078 call_pcm_playback_hook(hinfo
, codec
, substream
,
5079 HDA_GEN_PCM_ACT_OPEN
);
5081 mutex_unlock(&spec
->pcm_mutex
);
5085 static int playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
5086 struct hda_codec
*codec
,
5087 unsigned int stream_tag
,
5088 unsigned int format
,
5089 struct snd_pcm_substream
*substream
)
5091 struct hda_gen_spec
*spec
= codec
->spec
;
5094 err
= snd_hda_multi_out_analog_prepare(codec
, &spec
->multiout
,
5095 stream_tag
, format
, substream
);
5097 call_pcm_playback_hook(hinfo
, codec
, substream
,
5098 HDA_GEN_PCM_ACT_PREPARE
);
5102 static int playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
5103 struct hda_codec
*codec
,
5104 struct snd_pcm_substream
*substream
)
5106 struct hda_gen_spec
*spec
= codec
->spec
;
5109 err
= snd_hda_multi_out_analog_cleanup(codec
, &spec
->multiout
);
5111 call_pcm_playback_hook(hinfo
, codec
, substream
,
5112 HDA_GEN_PCM_ACT_CLEANUP
);
5116 static int playback_pcm_close(struct hda_pcm_stream
*hinfo
,
5117 struct hda_codec
*codec
,
5118 struct snd_pcm_substream
*substream
)
5120 struct hda_gen_spec
*spec
= codec
->spec
;
5121 mutex_lock(&spec
->pcm_mutex
);
5122 spec
->active_streams
&= ~(1 << STREAM_MULTI_OUT
);
5123 call_pcm_playback_hook(hinfo
, codec
, substream
,
5124 HDA_GEN_PCM_ACT_CLOSE
);
5125 mutex_unlock(&spec
->pcm_mutex
);
5129 static int capture_pcm_open(struct hda_pcm_stream
*hinfo
,
5130 struct hda_codec
*codec
,
5131 struct snd_pcm_substream
*substream
)
5133 call_pcm_capture_hook(hinfo
, codec
, substream
, HDA_GEN_PCM_ACT_OPEN
);
5137 static int capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
5138 struct hda_codec
*codec
,
5139 unsigned int stream_tag
,
5140 unsigned int format
,
5141 struct snd_pcm_substream
*substream
)
5143 snd_hda_codec_setup_stream(codec
, hinfo
->nid
, stream_tag
, 0, format
);
5144 call_pcm_capture_hook(hinfo
, codec
, substream
,
5145 HDA_GEN_PCM_ACT_PREPARE
);
5149 static int capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
5150 struct hda_codec
*codec
,
5151 struct snd_pcm_substream
*substream
)
5153 snd_hda_codec_cleanup_stream(codec
, hinfo
->nid
);
5154 call_pcm_capture_hook(hinfo
, codec
, substream
,
5155 HDA_GEN_PCM_ACT_CLEANUP
);
5159 static int capture_pcm_close(struct hda_pcm_stream
*hinfo
,
5160 struct hda_codec
*codec
,
5161 struct snd_pcm_substream
*substream
)
5163 call_pcm_capture_hook(hinfo
, codec
, substream
, HDA_GEN_PCM_ACT_CLOSE
);
5167 static int alt_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
5168 struct hda_codec
*codec
,
5169 struct snd_pcm_substream
*substream
)
5171 struct hda_gen_spec
*spec
= codec
->spec
;
5174 mutex_lock(&spec
->pcm_mutex
);
5175 if (spec
->indep_hp
&& !spec
->indep_hp_enabled
)
5178 spec
->active_streams
|= 1 << STREAM_INDEP_HP
;
5179 call_pcm_playback_hook(hinfo
, codec
, substream
,
5180 HDA_GEN_PCM_ACT_OPEN
);
5181 mutex_unlock(&spec
->pcm_mutex
);
5185 static int alt_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
5186 struct hda_codec
*codec
,
5187 struct snd_pcm_substream
*substream
)
5189 struct hda_gen_spec
*spec
= codec
->spec
;
5190 mutex_lock(&spec
->pcm_mutex
);
5191 spec
->active_streams
&= ~(1 << STREAM_INDEP_HP
);
5192 call_pcm_playback_hook(hinfo
, codec
, substream
,
5193 HDA_GEN_PCM_ACT_CLOSE
);
5194 mutex_unlock(&spec
->pcm_mutex
);
5198 static int alt_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
5199 struct hda_codec
*codec
,
5200 unsigned int stream_tag
,
5201 unsigned int format
,
5202 struct snd_pcm_substream
*substream
)
5204 snd_hda_codec_setup_stream(codec
, hinfo
->nid
, stream_tag
, 0, format
);
5205 call_pcm_playback_hook(hinfo
, codec
, substream
,
5206 HDA_GEN_PCM_ACT_PREPARE
);
5210 static int alt_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
5211 struct hda_codec
*codec
,
5212 struct snd_pcm_substream
*substream
)
5214 snd_hda_codec_cleanup_stream(codec
, hinfo
->nid
);
5215 call_pcm_playback_hook(hinfo
, codec
, substream
,
5216 HDA_GEN_PCM_ACT_CLEANUP
);
5223 static int dig_playback_pcm_open(struct hda_pcm_stream
*hinfo
,
5224 struct hda_codec
*codec
,
5225 struct snd_pcm_substream
*substream
)
5227 struct hda_gen_spec
*spec
= codec
->spec
;
5228 return snd_hda_multi_out_dig_open(codec
, &spec
->multiout
);
5231 static int dig_playback_pcm_prepare(struct hda_pcm_stream
*hinfo
,
5232 struct hda_codec
*codec
,
5233 unsigned int stream_tag
,
5234 unsigned int format
,
5235 struct snd_pcm_substream
*substream
)
5237 struct hda_gen_spec
*spec
= codec
->spec
;
5238 return snd_hda_multi_out_dig_prepare(codec
, &spec
->multiout
,
5239 stream_tag
, format
, substream
);
5242 static int dig_playback_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
5243 struct hda_codec
*codec
,
5244 struct snd_pcm_substream
*substream
)
5246 struct hda_gen_spec
*spec
= codec
->spec
;
5247 return snd_hda_multi_out_dig_cleanup(codec
, &spec
->multiout
);
5250 static int dig_playback_pcm_close(struct hda_pcm_stream
*hinfo
,
5251 struct hda_codec
*codec
,
5252 struct snd_pcm_substream
*substream
)
5254 struct hda_gen_spec
*spec
= codec
->spec
;
5255 return snd_hda_multi_out_dig_close(codec
, &spec
->multiout
);
5261 #define alt_capture_pcm_open capture_pcm_open
5262 #define alt_capture_pcm_close capture_pcm_close
5264 static int alt_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
5265 struct hda_codec
*codec
,
5266 unsigned int stream_tag
,
5267 unsigned int format
,
5268 struct snd_pcm_substream
*substream
)
5270 struct hda_gen_spec
*spec
= codec
->spec
;
5272 snd_hda_codec_setup_stream(codec
, spec
->adc_nids
[substream
->number
+ 1],
5273 stream_tag
, 0, format
);
5274 call_pcm_capture_hook(hinfo
, codec
, substream
,
5275 HDA_GEN_PCM_ACT_PREPARE
);
5279 static int alt_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
5280 struct hda_codec
*codec
,
5281 struct snd_pcm_substream
*substream
)
5283 struct hda_gen_spec
*spec
= codec
->spec
;
5285 snd_hda_codec_cleanup_stream(codec
,
5286 spec
->adc_nids
[substream
->number
+ 1]);
5287 call_pcm_capture_hook(hinfo
, codec
, substream
,
5288 HDA_GEN_PCM_ACT_CLEANUP
);
5294 static const struct hda_pcm_stream pcm_analog_playback
= {
5298 /* NID is set in build_pcms */
5300 .open
= playback_pcm_open
,
5301 .close
= playback_pcm_close
,
5302 .prepare
= playback_pcm_prepare
,
5303 .cleanup
= playback_pcm_cleanup
5307 static const struct hda_pcm_stream pcm_analog_capture
= {
5311 /* NID is set in build_pcms */
5313 .open
= capture_pcm_open
,
5314 .close
= capture_pcm_close
,
5315 .prepare
= capture_pcm_prepare
,
5316 .cleanup
= capture_pcm_cleanup
5320 static const struct hda_pcm_stream pcm_analog_alt_playback
= {
5324 /* NID is set in build_pcms */
5326 .open
= alt_playback_pcm_open
,
5327 .close
= alt_playback_pcm_close
,
5328 .prepare
= alt_playback_pcm_prepare
,
5329 .cleanup
= alt_playback_pcm_cleanup
5333 static const struct hda_pcm_stream pcm_analog_alt_capture
= {
5334 .substreams
= 2, /* can be overridden */
5337 /* NID is set in build_pcms */
5339 .open
= alt_capture_pcm_open
,
5340 .close
= alt_capture_pcm_close
,
5341 .prepare
= alt_capture_pcm_prepare
,
5342 .cleanup
= alt_capture_pcm_cleanup
5346 static const struct hda_pcm_stream pcm_digital_playback
= {
5350 /* NID is set in build_pcms */
5352 .open
= dig_playback_pcm_open
,
5353 .close
= dig_playback_pcm_close
,
5354 .prepare
= dig_playback_pcm_prepare
,
5355 .cleanup
= dig_playback_pcm_cleanup
5359 static const struct hda_pcm_stream pcm_digital_capture
= {
5363 /* NID is set in build_pcms */
5366 /* Used by build_pcms to flag that a PCM has no playback stream */
5367 static const struct hda_pcm_stream pcm_null_stream
= {
5374 * dynamic changing ADC PCM streams
5376 static bool dyn_adc_pcm_resetup(struct hda_codec
*codec
, int cur
)
5378 struct hda_gen_spec
*spec
= codec
->spec
;
5379 hda_nid_t new_adc
= spec
->adc_nids
[spec
->dyn_adc_idx
[cur
]];
5381 if (spec
->cur_adc
&& spec
->cur_adc
!= new_adc
) {
5382 /* stream is running, let's swap the current ADC */
5383 __snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
, 1);
5384 spec
->cur_adc
= new_adc
;
5385 snd_hda_codec_setup_stream(codec
, new_adc
,
5386 spec
->cur_adc_stream_tag
, 0,
5387 spec
->cur_adc_format
);
5393 /* analog capture with dynamic dual-adc changes */
5394 static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream
*hinfo
,
5395 struct hda_codec
*codec
,
5396 unsigned int stream_tag
,
5397 unsigned int format
,
5398 struct snd_pcm_substream
*substream
)
5400 struct hda_gen_spec
*spec
= codec
->spec
;
5401 spec
->cur_adc
= spec
->adc_nids
[spec
->dyn_adc_idx
[spec
->cur_mux
[0]]];
5402 spec
->cur_adc_stream_tag
= stream_tag
;
5403 spec
->cur_adc_format
= format
;
5404 snd_hda_codec_setup_stream(codec
, spec
->cur_adc
, stream_tag
, 0, format
);
5408 static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream
*hinfo
,
5409 struct hda_codec
*codec
,
5410 struct snd_pcm_substream
*substream
)
5412 struct hda_gen_spec
*spec
= codec
->spec
;
5413 snd_hda_codec_cleanup_stream(codec
, spec
->cur_adc
);
5418 static const struct hda_pcm_stream dyn_adc_pcm_analog_capture
= {
5422 .nid
= 0, /* fill later */
5424 .prepare
= dyn_adc_capture_pcm_prepare
,
5425 .cleanup
= dyn_adc_capture_pcm_cleanup
5429 static void fill_pcm_stream_name(char *str
, size_t len
, const char *sfx
,
5430 const char *chip_name
)
5436 strlcpy(str
, chip_name
, len
);
5438 /* drop non-alnum chars after a space */
5439 for (p
= strchr(str
, ' '); p
; p
= strchr(p
+ 1, ' ')) {
5440 if (!isalnum(p
[1])) {
5445 strlcat(str
, sfx
, len
);
5448 /* copy PCM stream info from @default_str, and override non-NULL entries
5449 * from @spec_str and @nid
5451 static void setup_pcm_stream(struct hda_pcm_stream
*str
,
5452 const struct hda_pcm_stream
*default_str
,
5453 const struct hda_pcm_stream
*spec_str
,
5456 *str
= *default_str
;
5460 if (spec_str
->substreams
)
5461 str
->substreams
= spec_str
->substreams
;
5462 if (spec_str
->channels_min
)
5463 str
->channels_min
= spec_str
->channels_min
;
5464 if (spec_str
->channels_max
)
5465 str
->channels_max
= spec_str
->channels_max
;
5466 if (spec_str
->rates
)
5467 str
->rates
= spec_str
->rates
;
5468 if (spec_str
->formats
)
5469 str
->formats
= spec_str
->formats
;
5470 if (spec_str
->maxbps
)
5471 str
->maxbps
= spec_str
->maxbps
;
5476 * snd_hda_gen_build_pcms - build PCM streams based on the parsed results
5477 * @codec: the HDA codec
5479 * Pass this to build_pcms patch_ops.
5481 int snd_hda_gen_build_pcms(struct hda_codec
*codec
)
5483 struct hda_gen_spec
*spec
= codec
->spec
;
5484 struct hda_pcm
*info
;
5485 bool have_multi_adcs
;
5487 if (spec
->no_analog
)
5490 fill_pcm_stream_name(spec
->stream_name_analog
,
5491 sizeof(spec
->stream_name_analog
),
5492 " Analog", codec
->core
.chip_name
);
5493 info
= snd_hda_codec_pcm_new(codec
, "%s", spec
->stream_name_analog
);
5496 spec
->pcm_rec
[0] = info
;
5498 if (spec
->multiout
.num_dacs
> 0) {
5499 setup_pcm_stream(&info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
],
5500 &pcm_analog_playback
,
5501 spec
->stream_analog_playback
,
5502 spec
->multiout
.dac_nids
[0]);
5503 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].channels_max
=
5504 spec
->multiout
.max_channels
;
5505 if (spec
->autocfg
.line_out_type
== AUTO_PIN_SPEAKER_OUT
&&
5506 spec
->autocfg
.line_outs
== 2)
5507 info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
].chmap
=
5510 if (spec
->num_adc_nids
) {
5511 setup_pcm_stream(&info
->stream
[SNDRV_PCM_STREAM_CAPTURE
],
5512 (spec
->dyn_adc_switch
?
5513 &dyn_adc_pcm_analog_capture
: &pcm_analog_capture
),
5514 spec
->stream_analog_capture
,
5519 /* SPDIF for stream index #1 */
5520 if (spec
->multiout
.dig_out_nid
|| spec
->dig_in_nid
) {
5521 fill_pcm_stream_name(spec
->stream_name_digital
,
5522 sizeof(spec
->stream_name_digital
),
5523 " Digital", codec
->core
.chip_name
);
5524 info
= snd_hda_codec_pcm_new(codec
, "%s",
5525 spec
->stream_name_digital
);
5528 codec
->slave_dig_outs
= spec
->multiout
.slave_dig_outs
;
5529 spec
->pcm_rec
[1] = info
;
5530 if (spec
->dig_out_type
)
5531 info
->pcm_type
= spec
->dig_out_type
;
5533 info
->pcm_type
= HDA_PCM_TYPE_SPDIF
;
5534 if (spec
->multiout
.dig_out_nid
)
5535 setup_pcm_stream(&info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
],
5536 &pcm_digital_playback
,
5537 spec
->stream_digital_playback
,
5538 spec
->multiout
.dig_out_nid
);
5539 if (spec
->dig_in_nid
)
5540 setup_pcm_stream(&info
->stream
[SNDRV_PCM_STREAM_CAPTURE
],
5541 &pcm_digital_capture
,
5542 spec
->stream_digital_capture
,
5546 if (spec
->no_analog
)
5549 /* If the use of more than one ADC is requested for the current
5550 * model, configure a second analog capture-only PCM.
5552 have_multi_adcs
= (spec
->num_adc_nids
> 1) &&
5553 !spec
->dyn_adc_switch
&& !spec
->auto_mic
;
5554 /* Additional Analaog capture for index #2 */
5555 if (spec
->alt_dac_nid
|| have_multi_adcs
) {
5556 fill_pcm_stream_name(spec
->stream_name_alt_analog
,
5557 sizeof(spec
->stream_name_alt_analog
),
5558 " Alt Analog", codec
->core
.chip_name
);
5559 info
= snd_hda_codec_pcm_new(codec
, "%s",
5560 spec
->stream_name_alt_analog
);
5563 spec
->pcm_rec
[2] = info
;
5564 if (spec
->alt_dac_nid
)
5565 setup_pcm_stream(&info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
],
5566 &pcm_analog_alt_playback
,
5567 spec
->stream_analog_alt_playback
,
5570 setup_pcm_stream(&info
->stream
[SNDRV_PCM_STREAM_PLAYBACK
],
5571 &pcm_null_stream
, NULL
, 0);
5572 if (have_multi_adcs
) {
5573 setup_pcm_stream(&info
->stream
[SNDRV_PCM_STREAM_CAPTURE
],
5574 &pcm_analog_alt_capture
,
5575 spec
->stream_analog_alt_capture
,
5577 info
->stream
[SNDRV_PCM_STREAM_CAPTURE
].substreams
=
5578 spec
->num_adc_nids
- 1;
5580 setup_pcm_stream(&info
->stream
[SNDRV_PCM_STREAM_CAPTURE
],
5581 &pcm_null_stream
, NULL
, 0);
5587 EXPORT_SYMBOL_GPL(snd_hda_gen_build_pcms
);
5591 * Standard auto-parser initializations
5594 /* configure the given path as a proper output */
5595 static void set_output_and_unmute(struct hda_codec
*codec
, int path_idx
)
5597 struct nid_path
*path
;
5600 path
= snd_hda_get_path_from_idx(codec
, path_idx
);
5601 if (!path
|| !path
->depth
)
5603 pin
= path
->path
[path
->depth
- 1];
5604 restore_pin_ctl(codec
, pin
);
5605 snd_hda_activate_path(codec
, path
, path
->active
,
5606 aamix_default(codec
->spec
));
5607 set_pin_eapd(codec
, pin
, path
->active
);
5610 /* initialize primary output paths */
5611 static void init_multi_out(struct hda_codec
*codec
)
5613 struct hda_gen_spec
*spec
= codec
->spec
;
5616 for (i
= 0; i
< spec
->autocfg
.line_outs
; i
++)
5617 set_output_and_unmute(codec
, spec
->out_paths
[i
]);
5621 static void __init_extra_out(struct hda_codec
*codec
, int num_outs
, int *paths
)
5625 for (i
= 0; i
< num_outs
; i
++)
5626 set_output_and_unmute(codec
, paths
[i
]);
5629 /* initialize hp and speaker paths */
5630 static void init_extra_out(struct hda_codec
*codec
)
5632 struct hda_gen_spec
*spec
= codec
->spec
;
5634 if (spec
->autocfg
.line_out_type
!= AUTO_PIN_HP_OUT
)
5635 __init_extra_out(codec
, spec
->autocfg
.hp_outs
, spec
->hp_paths
);
5636 if (spec
->autocfg
.line_out_type
!= AUTO_PIN_SPEAKER_OUT
)
5637 __init_extra_out(codec
, spec
->autocfg
.speaker_outs
,
5638 spec
->speaker_paths
);
5641 /* initialize multi-io paths */
5642 static void init_multi_io(struct hda_codec
*codec
)
5644 struct hda_gen_spec
*spec
= codec
->spec
;
5647 for (i
= 0; i
< spec
->multi_ios
; i
++) {
5648 hda_nid_t pin
= spec
->multi_io
[i
].pin
;
5649 struct nid_path
*path
;
5650 path
= get_multiio_path(codec
, i
);
5653 if (!spec
->multi_io
[i
].ctl_in
)
5654 spec
->multi_io
[i
].ctl_in
=
5655 snd_hda_codec_get_pin_target(codec
, pin
);
5656 snd_hda_activate_path(codec
, path
, path
->active
,
5657 aamix_default(spec
));
5661 static void init_aamix_paths(struct hda_codec
*codec
)
5663 struct hda_gen_spec
*spec
= codec
->spec
;
5665 if (!spec
->have_aamix_ctl
)
5667 update_aamix_paths(codec
, spec
->aamix_mode
, spec
->out_paths
[0],
5668 spec
->aamix_out_paths
[0],
5669 spec
->autocfg
.line_out_type
);
5670 update_aamix_paths(codec
, spec
->aamix_mode
, spec
->hp_paths
[0],
5671 spec
->aamix_out_paths
[1],
5673 update_aamix_paths(codec
, spec
->aamix_mode
, spec
->speaker_paths
[0],
5674 spec
->aamix_out_paths
[2],
5675 AUTO_PIN_SPEAKER_OUT
);
5678 /* set up input pins and loopback paths */
5679 static void init_analog_input(struct hda_codec
*codec
)
5681 struct hda_gen_spec
*spec
= codec
->spec
;
5682 struct auto_pin_cfg
*cfg
= &spec
->autocfg
;
5685 for (i
= 0; i
< cfg
->num_inputs
; i
++) {
5686 hda_nid_t nid
= cfg
->inputs
[i
].pin
;
5687 if (is_input_pin(codec
, nid
))
5688 restore_pin_ctl(codec
, nid
);
5690 /* init loopback inputs */
5691 if (spec
->mixer_nid
) {
5692 resume_path_from_idx(codec
, spec
->loopback_paths
[i
]);
5693 resume_path_from_idx(codec
, spec
->loopback_merge_path
);
5698 /* initialize ADC paths */
5699 static void init_input_src(struct hda_codec
*codec
)
5701 struct hda_gen_spec
*spec
= codec
->spec
;
5702 struct hda_input_mux
*imux
= &spec
->input_mux
;
5703 struct nid_path
*path
;
5706 if (spec
->dyn_adc_switch
)
5709 nums
= spec
->num_adc_nids
;
5711 for (c
= 0; c
< nums
; c
++) {
5712 for (i
= 0; i
< imux
->num_items
; i
++) {
5713 path
= get_input_path(codec
, c
, i
);
5715 bool active
= path
->active
;
5716 if (i
== spec
->cur_mux
[c
])
5718 snd_hda_activate_path(codec
, path
, active
, false);
5722 update_hp_mic(codec
, c
, true);
5725 if (spec
->cap_sync_hook
)
5726 spec
->cap_sync_hook(codec
, NULL
, NULL
);
5729 /* set right pin controls for digital I/O */
5730 static void init_digital(struct hda_codec
*codec
)
5732 struct hda_gen_spec
*spec
= codec
->spec
;
5736 for (i
= 0; i
< spec
->autocfg
.dig_outs
; i
++)
5737 set_output_and_unmute(codec
, spec
->digout_paths
[i
]);
5738 pin
= spec
->autocfg
.dig_in_pin
;
5740 restore_pin_ctl(codec
, pin
);
5741 resume_path_from_idx(codec
, spec
->digin_path
);
5745 /* clear unsol-event tags on unused pins; Conexant codecs seem to leave
5746 * invalid unsol tags by some reason
5748 static void clear_unsol_on_unused_pins(struct hda_codec
*codec
)
5752 for (i
= 0; i
< codec
->init_pins
.used
; i
++) {
5753 struct hda_pincfg
*pin
= snd_array_elem(&codec
->init_pins
, i
);
5754 hda_nid_t nid
= pin
->nid
;
5755 if (is_jack_detectable(codec
, nid
) &&
5756 !snd_hda_jack_tbl_get(codec
, nid
))
5757 snd_hda_codec_update_cache(codec
, nid
, 0,
5758 AC_VERB_SET_UNSOLICITED_ENABLE
, 0);
5763 * snd_hda_gen_init - initialize the generic spec
5764 * @codec: the HDA codec
5766 * This can be put as patch_ops init function.
5768 int snd_hda_gen_init(struct hda_codec
*codec
)
5770 struct hda_gen_spec
*spec
= codec
->spec
;
5772 if (spec
->init_hook
)
5773 spec
->init_hook(codec
);
5775 snd_hda_apply_verbs(codec
);
5777 init_multi_out(codec
);
5778 init_extra_out(codec
);
5779 init_multi_io(codec
);
5780 init_aamix_paths(codec
);
5781 init_analog_input(codec
);
5782 init_input_src(codec
);
5783 init_digital(codec
);
5785 clear_unsol_on_unused_pins(codec
);
5787 sync_all_pin_power_ctls(codec
);
5789 /* call init functions of standard auto-mute helpers */
5790 update_automute_all(codec
);
5792 regcache_sync(codec
->core
.regmap
);
5794 if (spec
->vmaster_mute
.sw_kctl
&& spec
->vmaster_mute
.hook
)
5795 snd_hda_sync_vmaster_hook(&spec
->vmaster_mute
);
5797 hda_call_check_power_status(codec
, 0x01);
5800 EXPORT_SYMBOL_GPL(snd_hda_gen_init
);
5803 * snd_hda_gen_free - free the generic spec
5804 * @codec: the HDA codec
5806 * This can be put as patch_ops free function.
5808 void snd_hda_gen_free(struct hda_codec
*codec
)
5810 snd_hda_apply_fixup(codec
, HDA_FIXUP_ACT_FREE
);
5811 snd_hda_gen_spec_free(codec
->spec
);
5815 EXPORT_SYMBOL_GPL(snd_hda_gen_free
);
5819 * snd_hda_gen_check_power_status - check the loopback power save state
5820 * @codec: the HDA codec
5821 * @nid: NID to inspect
5823 * This can be put as patch_ops check_power_status function.
5825 int snd_hda_gen_check_power_status(struct hda_codec
*codec
, hda_nid_t nid
)
5827 struct hda_gen_spec
*spec
= codec
->spec
;
5828 return snd_hda_check_amp_list_power(codec
, &spec
->loopback
, nid
);
5830 EXPORT_SYMBOL_GPL(snd_hda_gen_check_power_status
);
5835 * the generic codec support
5838 static const struct hda_codec_ops generic_patch_ops
= {
5839 .build_controls
= snd_hda_gen_build_controls
,
5840 .build_pcms
= snd_hda_gen_build_pcms
,
5841 .init
= snd_hda_gen_init
,
5842 .free
= snd_hda_gen_free
,
5843 .unsol_event
= snd_hda_jack_unsol_event
,
5845 .check_power_status
= snd_hda_gen_check_power_status
,
5850 * snd_hda_parse_generic_codec - Generic codec parser
5851 * @codec: the HDA codec
5853 static int snd_hda_parse_generic_codec(struct hda_codec
*codec
)
5855 struct hda_gen_spec
*spec
;
5858 spec
= kzalloc(sizeof(*spec
), GFP_KERNEL
);
5861 snd_hda_gen_spec_init(spec
);
5864 err
= snd_hda_parse_pin_defcfg(codec
, &spec
->autocfg
, NULL
, 0);
5868 err
= snd_hda_gen_parse_auto_config(codec
, &spec
->autocfg
);
5872 codec
->patch_ops
= generic_patch_ops
;
5876 snd_hda_gen_free(codec
);
5880 static const struct hda_device_id snd_hda_id_generic
[] = {
5881 HDA_CODEC_ENTRY(HDA_CODEC_ID_GENERIC
, "Generic", snd_hda_parse_generic_codec
),
5884 MODULE_DEVICE_TABLE(hdaudio
, snd_hda_id_generic
);
5886 static struct hda_codec_driver generic_driver
= {
5887 .id
= snd_hda_id_generic
,
5890 module_hda_codec_driver(generic_driver
);
5892 MODULE_LICENSE("GPL");
5893 MODULE_DESCRIPTION("Generic HD-audio codec parser");