xref: /OK3568_Linux_fs/kernel/sound/pci/hda/hda_auto_parser.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * BIOS auto-parser helper functions for HD-audio
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (c) 2012 Takashi Iwai <tiwai@suse.de>
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #ifndef __SOUND_HDA_AUTO_PARSER_H
9*4882a593Smuzhiyun #define __SOUND_HDA_AUTO_PARSER_H
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun /*
12*4882a593Smuzhiyun  * Helper for automatic pin configuration
13*4882a593Smuzhiyun  */
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun enum {
16*4882a593Smuzhiyun 	AUTO_PIN_MIC,
17*4882a593Smuzhiyun 	AUTO_PIN_LINE_IN,
18*4882a593Smuzhiyun 	AUTO_PIN_CD,
19*4882a593Smuzhiyun 	AUTO_PIN_AUX,
20*4882a593Smuzhiyun 	AUTO_PIN_LAST
21*4882a593Smuzhiyun };
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun enum {
24*4882a593Smuzhiyun 	AUTO_PIN_LINE_OUT,
25*4882a593Smuzhiyun 	AUTO_PIN_SPEAKER_OUT,
26*4882a593Smuzhiyun 	AUTO_PIN_HP_OUT
27*4882a593Smuzhiyun };
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun #define AUTO_CFG_MAX_OUTS	HDA_MAX_OUTS
30*4882a593Smuzhiyun #define AUTO_CFG_MAX_INS	8
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun struct auto_pin_cfg_item {
33*4882a593Smuzhiyun 	hda_nid_t pin;
34*4882a593Smuzhiyun 	int type;
35*4882a593Smuzhiyun 	unsigned int is_headset_mic:1;
36*4882a593Smuzhiyun 	unsigned int is_headphone_mic:1; /* Mic-only in headphone jack */
37*4882a593Smuzhiyun 	unsigned int has_boost_on_pin:1;
38*4882a593Smuzhiyun };
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun struct auto_pin_cfg;
41*4882a593Smuzhiyun const char *hda_get_autocfg_input_label(struct hda_codec *codec,
42*4882a593Smuzhiyun 					const struct auto_pin_cfg *cfg,
43*4882a593Smuzhiyun 					int input);
44*4882a593Smuzhiyun int snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid,
45*4882a593Smuzhiyun 			  const struct auto_pin_cfg *cfg,
46*4882a593Smuzhiyun 			  char *label, int maxlen, int *indexp);
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun enum {
49*4882a593Smuzhiyun 	INPUT_PIN_ATTR_UNUSED,	/* pin not connected */
50*4882a593Smuzhiyun 	INPUT_PIN_ATTR_INT,	/* internal mic/line-in */
51*4882a593Smuzhiyun 	INPUT_PIN_ATTR_DOCK,	/* docking mic/line-in */
52*4882a593Smuzhiyun 	INPUT_PIN_ATTR_NORMAL,	/* mic/line-in jack */
53*4882a593Smuzhiyun 	INPUT_PIN_ATTR_REAR,	/* mic/line-in jack in rear */
54*4882a593Smuzhiyun 	INPUT_PIN_ATTR_FRONT,	/* mic/line-in jack in front */
55*4882a593Smuzhiyun 	INPUT_PIN_ATTR_LAST = INPUT_PIN_ATTR_FRONT,
56*4882a593Smuzhiyun };
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun int snd_hda_get_input_pin_attr(unsigned int def_conf);
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun struct auto_pin_cfg {
61*4882a593Smuzhiyun 	int line_outs;
62*4882a593Smuzhiyun 	/* sorted in the order of Front/Surr/CLFE/Side */
63*4882a593Smuzhiyun 	hda_nid_t line_out_pins[AUTO_CFG_MAX_OUTS];
64*4882a593Smuzhiyun 	int speaker_outs;
65*4882a593Smuzhiyun 	hda_nid_t speaker_pins[AUTO_CFG_MAX_OUTS];
66*4882a593Smuzhiyun 	int hp_outs;
67*4882a593Smuzhiyun 	int line_out_type;	/* AUTO_PIN_XXX_OUT */
68*4882a593Smuzhiyun 	hda_nid_t hp_pins[AUTO_CFG_MAX_OUTS];
69*4882a593Smuzhiyun 	int num_inputs;
70*4882a593Smuzhiyun 	struct auto_pin_cfg_item inputs[AUTO_CFG_MAX_INS];
71*4882a593Smuzhiyun 	int dig_outs;
72*4882a593Smuzhiyun 	hda_nid_t dig_out_pins[2];
73*4882a593Smuzhiyun 	hda_nid_t dig_in_pin;
74*4882a593Smuzhiyun 	hda_nid_t mono_out_pin;
75*4882a593Smuzhiyun 	int dig_out_type[2]; /* HDA_PCM_TYPE_XXX */
76*4882a593Smuzhiyun 	int dig_in_type; /* HDA_PCM_TYPE_XXX */
77*4882a593Smuzhiyun };
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun /* bit-flags for snd_hda_parse_pin_def_config() behavior */
80*4882a593Smuzhiyun #define HDA_PINCFG_NO_HP_FIXUP   (1 << 0) /* no HP-split */
81*4882a593Smuzhiyun #define HDA_PINCFG_NO_LO_FIXUP   (1 << 1) /* don't take other outs as LO */
82*4882a593Smuzhiyun #define HDA_PINCFG_HEADSET_MIC   (1 << 2) /* Try to find headset mic; mark seq number as 0xc to trigger */
83*4882a593Smuzhiyun #define HDA_PINCFG_HEADPHONE_MIC (1 << 3) /* Try to find headphone mic; mark seq number as 0xd to trigger */
84*4882a593Smuzhiyun 
85*4882a593Smuzhiyun int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
86*4882a593Smuzhiyun 			     struct auto_pin_cfg *cfg,
87*4882a593Smuzhiyun 			     const hda_nid_t *ignore_nids,
88*4882a593Smuzhiyun 			     unsigned int cond_flags);
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun /* older function */
91*4882a593Smuzhiyun #define snd_hda_parse_pin_def_config(codec, cfg, ignore) \
92*4882a593Smuzhiyun 	snd_hda_parse_pin_defcfg(codec, cfg, ignore, 0)
93*4882a593Smuzhiyun 
auto_cfg_hp_outs(const struct auto_pin_cfg * cfg)94*4882a593Smuzhiyun static inline int auto_cfg_hp_outs(const struct auto_pin_cfg *cfg)
95*4882a593Smuzhiyun {
96*4882a593Smuzhiyun 	return (cfg->line_out_type == AUTO_PIN_HP_OUT) ?
97*4882a593Smuzhiyun 	       cfg->line_outs : cfg->hp_outs;
98*4882a593Smuzhiyun }
auto_cfg_hp_pins(const struct auto_pin_cfg * cfg)99*4882a593Smuzhiyun static inline const hda_nid_t *auto_cfg_hp_pins(const struct auto_pin_cfg *cfg)
100*4882a593Smuzhiyun {
101*4882a593Smuzhiyun 	return (cfg->line_out_type == AUTO_PIN_HP_OUT) ?
102*4882a593Smuzhiyun 	       cfg->line_out_pins : cfg->hp_pins;
103*4882a593Smuzhiyun }
auto_cfg_speaker_outs(const struct auto_pin_cfg * cfg)104*4882a593Smuzhiyun static inline int auto_cfg_speaker_outs(const struct auto_pin_cfg *cfg)
105*4882a593Smuzhiyun {
106*4882a593Smuzhiyun 	return (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) ?
107*4882a593Smuzhiyun 	       cfg->line_outs : cfg->speaker_outs;
108*4882a593Smuzhiyun }
auto_cfg_speaker_pins(const struct auto_pin_cfg * cfg)109*4882a593Smuzhiyun static inline const hda_nid_t *auto_cfg_speaker_pins(const struct auto_pin_cfg *cfg)
110*4882a593Smuzhiyun {
111*4882a593Smuzhiyun 	return (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) ?
112*4882a593Smuzhiyun 	       cfg->line_out_pins : cfg->speaker_pins;
113*4882a593Smuzhiyun }
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun #endif /* __SOUND_HDA_AUTO_PARSER_H */
116