162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * BIOS auto-parser helper functions for HD-audio
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (c) 2012 Takashi Iwai <tiwai@suse.de>
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#ifndef __SOUND_HDA_AUTO_PARSER_H
962306a36Sopenharmony_ci#define __SOUND_HDA_AUTO_PARSER_H
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include "hda_local.h"
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci/*
1462306a36Sopenharmony_ci * Helper for automatic pin configuration
1562306a36Sopenharmony_ci */
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_cienum {
1862306a36Sopenharmony_ci	AUTO_PIN_MIC,
1962306a36Sopenharmony_ci	AUTO_PIN_LINE_IN,
2062306a36Sopenharmony_ci	AUTO_PIN_CD,
2162306a36Sopenharmony_ci	AUTO_PIN_AUX,
2262306a36Sopenharmony_ci	AUTO_PIN_LAST
2362306a36Sopenharmony_ci};
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_cienum {
2662306a36Sopenharmony_ci	AUTO_PIN_LINE_OUT,
2762306a36Sopenharmony_ci	AUTO_PIN_SPEAKER_OUT,
2862306a36Sopenharmony_ci	AUTO_PIN_HP_OUT
2962306a36Sopenharmony_ci};
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci#define AUTO_CFG_MAX_OUTS	HDA_MAX_OUTS
3262306a36Sopenharmony_ci#define AUTO_CFG_MAX_INS	18
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_cistruct auto_pin_cfg_item {
3562306a36Sopenharmony_ci	hda_nid_t pin;
3662306a36Sopenharmony_ci	int type;
3762306a36Sopenharmony_ci	unsigned int is_headset_mic:1;
3862306a36Sopenharmony_ci	unsigned int is_headphone_mic:1; /* Mic-only in headphone jack */
3962306a36Sopenharmony_ci	unsigned int has_boost_on_pin:1;
4062306a36Sopenharmony_ci};
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_cistruct auto_pin_cfg;
4362306a36Sopenharmony_ciconst char *hda_get_autocfg_input_label(struct hda_codec *codec,
4462306a36Sopenharmony_ci					const struct auto_pin_cfg *cfg,
4562306a36Sopenharmony_ci					int input);
4662306a36Sopenharmony_ciint snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid,
4762306a36Sopenharmony_ci			  const struct auto_pin_cfg *cfg,
4862306a36Sopenharmony_ci			  char *label, int maxlen, int *indexp);
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_cienum {
5162306a36Sopenharmony_ci	INPUT_PIN_ATTR_UNUSED,	/* pin not connected */
5262306a36Sopenharmony_ci	INPUT_PIN_ATTR_INT,	/* internal mic/line-in */
5362306a36Sopenharmony_ci	INPUT_PIN_ATTR_DOCK,	/* docking mic/line-in */
5462306a36Sopenharmony_ci	INPUT_PIN_ATTR_NORMAL,	/* mic/line-in jack */
5562306a36Sopenharmony_ci	INPUT_PIN_ATTR_REAR,	/* mic/line-in jack in rear */
5662306a36Sopenharmony_ci	INPUT_PIN_ATTR_FRONT,	/* mic/line-in jack in front */
5762306a36Sopenharmony_ci	INPUT_PIN_ATTR_LAST = INPUT_PIN_ATTR_FRONT,
5862306a36Sopenharmony_ci};
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ciint snd_hda_get_input_pin_attr(unsigned int def_conf);
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_cistruct auto_pin_cfg {
6362306a36Sopenharmony_ci	int line_outs;
6462306a36Sopenharmony_ci	/* sorted in the order of Front/Surr/CLFE/Side */
6562306a36Sopenharmony_ci	hda_nid_t line_out_pins[AUTO_CFG_MAX_OUTS];
6662306a36Sopenharmony_ci	int speaker_outs;
6762306a36Sopenharmony_ci	hda_nid_t speaker_pins[AUTO_CFG_MAX_OUTS];
6862306a36Sopenharmony_ci	int hp_outs;
6962306a36Sopenharmony_ci	int line_out_type;	/* AUTO_PIN_XXX_OUT */
7062306a36Sopenharmony_ci	hda_nid_t hp_pins[AUTO_CFG_MAX_OUTS];
7162306a36Sopenharmony_ci	int num_inputs;
7262306a36Sopenharmony_ci	struct auto_pin_cfg_item inputs[AUTO_CFG_MAX_INS];
7362306a36Sopenharmony_ci	int dig_outs;
7462306a36Sopenharmony_ci	hda_nid_t dig_out_pins[2];
7562306a36Sopenharmony_ci	hda_nid_t dig_in_pin;
7662306a36Sopenharmony_ci	hda_nid_t mono_out_pin;
7762306a36Sopenharmony_ci	int dig_out_type[2]; /* HDA_PCM_TYPE_XXX */
7862306a36Sopenharmony_ci	int dig_in_type; /* HDA_PCM_TYPE_XXX */
7962306a36Sopenharmony_ci};
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci/* bit-flags for snd_hda_parse_pin_def_config() behavior */
8262306a36Sopenharmony_ci#define HDA_PINCFG_NO_HP_FIXUP   (1 << 0) /* no HP-split */
8362306a36Sopenharmony_ci#define HDA_PINCFG_NO_LO_FIXUP   (1 << 1) /* don't take other outs as LO */
8462306a36Sopenharmony_ci#define HDA_PINCFG_HEADSET_MIC   (1 << 2) /* Try to find headset mic; mark seq number as 0xc to trigger */
8562306a36Sopenharmony_ci#define HDA_PINCFG_HEADPHONE_MIC (1 << 3) /* Try to find headphone mic; mark seq number as 0xd to trigger */
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ciint snd_hda_parse_pin_defcfg(struct hda_codec *codec,
8862306a36Sopenharmony_ci			     struct auto_pin_cfg *cfg,
8962306a36Sopenharmony_ci			     const hda_nid_t *ignore_nids,
9062306a36Sopenharmony_ci			     unsigned int cond_flags);
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci/* older function */
9362306a36Sopenharmony_ci#define snd_hda_parse_pin_def_config(codec, cfg, ignore) \
9462306a36Sopenharmony_ci	snd_hda_parse_pin_defcfg(codec, cfg, ignore, 0)
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_cistatic inline int auto_cfg_hp_outs(const struct auto_pin_cfg *cfg)
9762306a36Sopenharmony_ci{
9862306a36Sopenharmony_ci	return (cfg->line_out_type == AUTO_PIN_HP_OUT) ?
9962306a36Sopenharmony_ci	       cfg->line_outs : cfg->hp_outs;
10062306a36Sopenharmony_ci}
10162306a36Sopenharmony_cistatic inline const hda_nid_t *auto_cfg_hp_pins(const struct auto_pin_cfg *cfg)
10262306a36Sopenharmony_ci{
10362306a36Sopenharmony_ci	return (cfg->line_out_type == AUTO_PIN_HP_OUT) ?
10462306a36Sopenharmony_ci	       cfg->line_out_pins : cfg->hp_pins;
10562306a36Sopenharmony_ci}
10662306a36Sopenharmony_cistatic inline int auto_cfg_speaker_outs(const struct auto_pin_cfg *cfg)
10762306a36Sopenharmony_ci{
10862306a36Sopenharmony_ci	return (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) ?
10962306a36Sopenharmony_ci	       cfg->line_outs : cfg->speaker_outs;
11062306a36Sopenharmony_ci}
11162306a36Sopenharmony_cistatic inline const hda_nid_t *auto_cfg_speaker_pins(const struct auto_pin_cfg *cfg)
11262306a36Sopenharmony_ci{
11362306a36Sopenharmony_ci	return (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) ?
11462306a36Sopenharmony_ci	       cfg->line_out_pins : cfg->speaker_pins;
11562306a36Sopenharmony_ci}
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci#endif /* __SOUND_HDA_AUTO_PARSER_H */
118