Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 99ae28be authored by Takashi Iwai's avatar Takashi Iwai
Browse files

ALSA: hda - Make snd_hda_get_input_pin_attr() helper



Make the helper function to give the input-pin attribute for jack
connectivity and location.  This simplifies checks of input-pin jacks
a bit in some places.

Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 5637edb2
Loading
Loading
Loading
Loading
+25 −37
Original line number Diff line number Diff line
@@ -4637,44 +4637,26 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
}
EXPORT_SYMBOL_HDA(snd_hda_parse_pin_def_config);

enum {
	MIC_ATTR_INT,
	MIC_ATTR_DOCK,
	MIC_ATTR_NORMAL,
	MIC_ATTR_FRONT,
	MIC_ATTR_REAR,
};

static int get_mic_pin_attr(unsigned int def_conf)
int snd_hda_get_input_pin_attr(unsigned int def_conf)
{
	unsigned int loc = get_defcfg_location(def_conf);
	unsigned int conn = get_defcfg_connect(def_conf);
	if (conn == AC_JACK_PORT_NONE)
		return INPUT_PIN_ATTR_UNUSED;
	/* Windows may claim the internal mic to be BOTH, too */
	if (conn == AC_JACK_PORT_FIXED || conn == AC_JACK_PORT_BOTH)
		return MIC_ATTR_INT;
		return INPUT_PIN_ATTR_INT;
	if ((loc & 0x30) == AC_JACK_LOC_INTERNAL)
		return MIC_ATTR_INT;
		return INPUT_PIN_ATTR_INT;
	if ((loc & 0x30) == AC_JACK_LOC_SEPARATE)
		return MIC_ATTR_DOCK;
		return INPUT_PIN_ATTR_DOCK;
	if (loc == AC_JACK_LOC_REAR)
		return MIC_ATTR_REAR;
		return INPUT_PIN_ATTR_REAR;
	if (loc == AC_JACK_LOC_FRONT)
		return MIC_ATTR_FRONT;
	return MIC_ATTR_NORMAL;
}

enum {
	LINE_ATTR_DOCK,
	LINE_ATTR_NORMAL,
};

static int get_line_pin_attr(unsigned int def_conf)
{
	unsigned int loc = get_defcfg_location(def_conf);
	if ((loc & 0xf0) == AC_JACK_LOC_SEPARATE)
		return LINE_ATTR_DOCK;
	return LINE_ATTR_NORMAL;
		return INPUT_PIN_ATTR_FRONT;
	return INPUT_PIN_ATTR_NORMAL;
}
EXPORT_SYMBOL_HDA(snd_hda_get_input_pin_attr);

/**
 * hda_get_input_pin_label - Give a label for the given input pin
@@ -4691,9 +4673,7 @@ const char *hda_get_input_pin_label(struct hda_codec *codec, hda_nid_t pin,
	static const char *mic_names[] = {
		"Internal Mic", "Dock Mic", "Mic", "Front Mic", "Rear Mic",
	};
	static const char *line_names[] = {
		"Dock Line", "Line",
	};
	int attr;

	def_conf = snd_hda_codec_get_pincfg(codec, pin);

@@ -4701,11 +4681,19 @@ const char *hda_get_input_pin_label(struct hda_codec *codec, hda_nid_t pin,
	case AC_JACK_MIC_IN:
		if (!check_location)
			return "Mic";
		return mic_names[get_mic_pin_attr(def_conf)];
		attr = snd_hda_get_input_pin_attr(def_conf);
		if (!attr)
			return "None";
		return mic_names[attr - 1];
	case AC_JACK_LINE_IN:
		if (!check_location)
			return "Line";
		return line_names[get_line_pin_attr(def_conf)];
		attr = snd_hda_get_input_pin_attr(def_conf);
		if (!attr)
			return "None";
		if (attr == INPUT_PIN_ATTR_DOCK)
			return "Dock Line";
		return "Line";
	case AC_JACK_AUX:
		return "Aux";
	case AC_JACK_CD:
@@ -4732,16 +4720,16 @@ static int check_mic_location_need(struct hda_codec *codec,
	int i, attr, attr2;

	defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[input].pin);
	attr = get_mic_pin_attr(defc);
	attr = snd_hda_get_input_pin_attr(defc);
	/* for internal or docking mics, we need locations */
	if (attr <= MIC_ATTR_NORMAL)
	if (attr <= INPUT_PIN_ATTR_NORMAL)
		return 1;

	attr = 0;
	for (i = 0; i < cfg->num_inputs; i++) {
		defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[i].pin);
		attr2 = get_mic_pin_attr(defc);
		if (attr2 >= MIC_ATTR_NORMAL) {
		attr2 = snd_hda_get_input_pin_attr(defc);
		if (attr2 >= INPUT_PIN_ATTR_NORMAL) {
			if (attr && attr != attr2)
				return 1; /* different locations found */
			attr = attr2;
+11 −0
Original line number Diff line number Diff line
@@ -395,6 +395,17 @@ const char *hda_get_autocfg_input_label(struct hda_codec *codec,
int snd_hda_add_imux_item(struct hda_input_mux *imux, const char *label,
			  int index, int *type_index_ret);

enum {
	INPUT_PIN_ATTR_UNUSED,	/* pin not connected */
	INPUT_PIN_ATTR_INT,	/* internal mic/line-in */
	INPUT_PIN_ATTR_DOCK,	/* docking mic/line-in */
	INPUT_PIN_ATTR_NORMAL,	/* mic/line-in jack */
	INPUT_PIN_ATTR_FRONT,	/* mic/line-in jack in front */
	INPUT_PIN_ATTR_REAR,	/* mic/line-in jack in rear */
};

int snd_hda_get_input_pin_attr(unsigned int def_conf);

struct auto_pin_cfg {
	int line_outs;
	/* sorted in the order of Front/Surr/CLFE/Side */
+1 −1
Original line number Diff line number Diff line
@@ -334,7 +334,7 @@ static int is_ext_mic(struct hda_codec *codec, unsigned int idx)
	if (!(val & AC_PINCAP_PRES_DETECT))
		return 0;
	val = snd_hda_codec_get_pincfg(codec, pin);
	return (get_defcfg_connect(val) == AC_JACK_PORT_COMPLEX);
	return (snd_hda_get_input_pin_attr(val) != INPUT_PIN_ATTR_INT);
}

static hda_nid_t get_adc(struct hda_codec *codec, hda_nid_t pin,
+2 −9
Original line number Diff line number Diff line
@@ -3462,19 +3462,12 @@ static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
	}
}

static int is_int_mic_conn(unsigned int def_conf)
{
	unsigned int loc = get_defcfg_location(def_conf);
	return get_defcfg_connect(def_conf) == AC_JACK_PORT_FIXED ||
		(loc & 0x30) == AC_JACK_LOC_INTERNAL;
}

/* return true if it's an internal-mic pin */
static int is_int_mic(struct hda_codec *codec, hda_nid_t pin)
{
	unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
	return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
		is_int_mic_conn(def_conf);
		snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT;
}

/* return true if it's an external-mic pin */
@@ -3482,7 +3475,7 @@ static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin)
{
	unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
	return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
		!is_int_mic_conn(def_conf);
		snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT;
}

/* check whether the pin config is suitable for auto-mic switching;
+5 −5
Original line number Diff line number Diff line
@@ -1403,19 +1403,19 @@ static void alc_init_auto_mic(struct hda_codec *codec)
		hda_nid_t nid = cfg->inputs[i].pin;
		unsigned int defcfg;
		defcfg = snd_hda_codec_get_pincfg(codec, nid);
		switch (get_defcfg_connect(defcfg)) {
		case AC_JACK_PORT_FIXED:
		switch (snd_hda_get_input_pin_attr(defcfg)) {
		case INPUT_PIN_ATTR_INT:
			if (fixed)
				return; /* already occupied */
			fixed = nid;
			break;
		case AC_JACK_PORT_COMPLEX:
		case INPUT_PIN_ATTR_UNUSED:
			return; /* invalid entry */
		default:
			if (ext)
				return; /* already occupied */
			ext = nid;
			break;
		default:
			return; /* invalid entry */
		}
	}
	if (!ext || !fixed)
Loading