xref: /openbmc/linux/sound/pci/hda/hda_auto_parser.h (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
162810dbdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
223d30f28STakashi Iwai /*
323d30f28STakashi Iwai  * BIOS auto-parser helper functions for HD-audio
423d30f28STakashi Iwai  *
523d30f28STakashi Iwai  * Copyright (c) 2012 Takashi Iwai <tiwai@suse.de>
623d30f28STakashi Iwai  */
723d30f28STakashi Iwai 
823d30f28STakashi Iwai #ifndef __SOUND_HDA_AUTO_PARSER_H
923d30f28STakashi Iwai #define __SOUND_HDA_AUTO_PARSER_H
1023d30f28STakashi Iwai 
11*64e05321SRichard Fitzgerald #include "hda_local.h"
12*64e05321SRichard Fitzgerald 
13128bc4baSTakashi Iwai /*
14128bc4baSTakashi Iwai  * Helper for automatic pin configuration
15128bc4baSTakashi Iwai  */
16128bc4baSTakashi Iwai 
17128bc4baSTakashi Iwai enum {
18128bc4baSTakashi Iwai 	AUTO_PIN_MIC,
19128bc4baSTakashi Iwai 	AUTO_PIN_LINE_IN,
20128bc4baSTakashi Iwai 	AUTO_PIN_CD,
21128bc4baSTakashi Iwai 	AUTO_PIN_AUX,
22128bc4baSTakashi Iwai 	AUTO_PIN_LAST
23128bc4baSTakashi Iwai };
24128bc4baSTakashi Iwai 
25128bc4baSTakashi Iwai enum {
26128bc4baSTakashi Iwai 	AUTO_PIN_LINE_OUT,
27128bc4baSTakashi Iwai 	AUTO_PIN_SPEAKER_OUT,
28128bc4baSTakashi Iwai 	AUTO_PIN_HP_OUT
29128bc4baSTakashi Iwai };
30128bc4baSTakashi Iwai 
31128bc4baSTakashi Iwai #define AUTO_CFG_MAX_OUTS	HDA_MAX_OUTS
32b95a913cSVitaly Rodionov #define AUTO_CFG_MAX_INS	18
33128bc4baSTakashi Iwai 
34128bc4baSTakashi Iwai struct auto_pin_cfg_item {
35128bc4baSTakashi Iwai 	hda_nid_t pin;
36128bc4baSTakashi Iwai 	int type;
37a385d97bSDavid Henningsson 	unsigned int is_headset_mic:1;
38cb420b11SDavid Henningsson 	unsigned int is_headphone_mic:1; /* Mic-only in headphone jack */
3995f72cf2SDavid Henningsson 	unsigned int has_boost_on_pin:1;
40128bc4baSTakashi Iwai };
41128bc4baSTakashi Iwai 
42128bc4baSTakashi Iwai struct auto_pin_cfg;
43128bc4baSTakashi Iwai const char *hda_get_autocfg_input_label(struct hda_codec *codec,
44128bc4baSTakashi Iwai 					const struct auto_pin_cfg *cfg,
45128bc4baSTakashi Iwai 					int input);
46128bc4baSTakashi Iwai int snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid,
47128bc4baSTakashi Iwai 			  const struct auto_pin_cfg *cfg,
48128bc4baSTakashi Iwai 			  char *label, int maxlen, int *indexp);
49128bc4baSTakashi Iwai 
50128bc4baSTakashi Iwai enum {
51128bc4baSTakashi Iwai 	INPUT_PIN_ATTR_UNUSED,	/* pin not connected */
52128bc4baSTakashi Iwai 	INPUT_PIN_ATTR_INT,	/* internal mic/line-in */
53128bc4baSTakashi Iwai 	INPUT_PIN_ATTR_DOCK,	/* docking mic/line-in */
54128bc4baSTakashi Iwai 	INPUT_PIN_ATTR_NORMAL,	/* mic/line-in jack */
55128bc4baSTakashi Iwai 	INPUT_PIN_ATTR_REAR,	/* mic/line-in jack in rear */
565ec16d12STakashi Iwai 	INPUT_PIN_ATTR_FRONT,	/* mic/line-in jack in front */
575ec16d12STakashi Iwai 	INPUT_PIN_ATTR_LAST = INPUT_PIN_ATTR_FRONT,
58128bc4baSTakashi Iwai };
59128bc4baSTakashi Iwai 
60128bc4baSTakashi Iwai int snd_hda_get_input_pin_attr(unsigned int def_conf);
61128bc4baSTakashi Iwai 
62128bc4baSTakashi Iwai struct auto_pin_cfg {
63128bc4baSTakashi Iwai 	int line_outs;
64128bc4baSTakashi Iwai 	/* sorted in the order of Front/Surr/CLFE/Side */
65128bc4baSTakashi Iwai 	hda_nid_t line_out_pins[AUTO_CFG_MAX_OUTS];
66128bc4baSTakashi Iwai 	int speaker_outs;
67128bc4baSTakashi Iwai 	hda_nid_t speaker_pins[AUTO_CFG_MAX_OUTS];
68128bc4baSTakashi Iwai 	int hp_outs;
69128bc4baSTakashi Iwai 	int line_out_type;	/* AUTO_PIN_XXX_OUT */
70128bc4baSTakashi Iwai 	hda_nid_t hp_pins[AUTO_CFG_MAX_OUTS];
71128bc4baSTakashi Iwai 	int num_inputs;
72128bc4baSTakashi Iwai 	struct auto_pin_cfg_item inputs[AUTO_CFG_MAX_INS];
73128bc4baSTakashi Iwai 	int dig_outs;
74128bc4baSTakashi Iwai 	hda_nid_t dig_out_pins[2];
75128bc4baSTakashi Iwai 	hda_nid_t dig_in_pin;
76128bc4baSTakashi Iwai 	hda_nid_t mono_out_pin;
77128bc4baSTakashi Iwai 	int dig_out_type[2]; /* HDA_PCM_TYPE_XXX */
78128bc4baSTakashi Iwai 	int dig_in_type; /* HDA_PCM_TYPE_XXX */
79128bc4baSTakashi Iwai };
80128bc4baSTakashi Iwai 
81128bc4baSTakashi Iwai /* bit-flags for snd_hda_parse_pin_def_config() behavior */
82128bc4baSTakashi Iwai #define HDA_PINCFG_NO_HP_FIXUP   (1 << 0) /* no HP-split */
83128bc4baSTakashi Iwai #define HDA_PINCFG_NO_LO_FIXUP   (1 << 1) /* don't take other outs as LO */
84cb420b11SDavid Henningsson #define HDA_PINCFG_HEADSET_MIC   (1 << 2) /* Try to find headset mic; mark seq number as 0xc to trigger */
85cb420b11SDavid Henningsson #define HDA_PINCFG_HEADPHONE_MIC (1 << 3) /* Try to find headphone mic; mark seq number as 0xd to trigger */
86128bc4baSTakashi Iwai 
87128bc4baSTakashi Iwai int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
88128bc4baSTakashi Iwai 			     struct auto_pin_cfg *cfg,
89128bc4baSTakashi Iwai 			     const hda_nid_t *ignore_nids,
90128bc4baSTakashi Iwai 			     unsigned int cond_flags);
91128bc4baSTakashi Iwai 
92128bc4baSTakashi Iwai /* older function */
93128bc4baSTakashi Iwai #define snd_hda_parse_pin_def_config(codec, cfg, ignore) \
94128bc4baSTakashi Iwai 	snd_hda_parse_pin_defcfg(codec, cfg, ignore, 0)
95128bc4baSTakashi Iwai 
auto_cfg_hp_outs(const struct auto_pin_cfg * cfg)963cdbe11aSDavid Henningsson static inline int auto_cfg_hp_outs(const struct auto_pin_cfg *cfg)
973cdbe11aSDavid Henningsson {
983cdbe11aSDavid Henningsson 	return (cfg->line_out_type == AUTO_PIN_HP_OUT) ?
993cdbe11aSDavid Henningsson 	       cfg->line_outs : cfg->hp_outs;
1003cdbe11aSDavid Henningsson }
auto_cfg_hp_pins(const struct auto_pin_cfg * cfg)1013cdbe11aSDavid Henningsson static inline const hda_nid_t *auto_cfg_hp_pins(const struct auto_pin_cfg *cfg)
1023cdbe11aSDavid Henningsson {
1033cdbe11aSDavid Henningsson 	return (cfg->line_out_type == AUTO_PIN_HP_OUT) ?
1043cdbe11aSDavid Henningsson 	       cfg->line_out_pins : cfg->hp_pins;
1053cdbe11aSDavid Henningsson }
auto_cfg_speaker_outs(const struct auto_pin_cfg * cfg)1063cdbe11aSDavid Henningsson static inline int auto_cfg_speaker_outs(const struct auto_pin_cfg *cfg)
1073cdbe11aSDavid Henningsson {
1083cdbe11aSDavid Henningsson 	return (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) ?
1093cdbe11aSDavid Henningsson 	       cfg->line_outs : cfg->speaker_outs;
1103cdbe11aSDavid Henningsson }
auto_cfg_speaker_pins(const struct auto_pin_cfg * cfg)1113cdbe11aSDavid Henningsson static inline const hda_nid_t *auto_cfg_speaker_pins(const struct auto_pin_cfg *cfg)
1123cdbe11aSDavid Henningsson {
1133cdbe11aSDavid Henningsson 	return (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) ?
1143cdbe11aSDavid Henningsson 	       cfg->line_out_pins : cfg->speaker_pins;
1153cdbe11aSDavid Henningsson }
1163cdbe11aSDavid Henningsson 
11723d30f28STakashi Iwai #endif /* __SOUND_HDA_AUTO_PARSER_H */
118