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

Commit 8d087c76 authored by Takashi Iwai's avatar Takashi Iwai
Browse files

ALSA: hda - Create snd_hda_get_conn_index() helper function



Create snd_hda_get_conn_index() helper function for obtaining the
connection index of the widget.  Replaced the similar codes used in
several codec-drivers with this common helper.

Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 63f10d2c
Loading
Loading
Loading
Loading
+37 −5
Original line number Diff line number Diff line
@@ -411,11 +411,8 @@ static int _hda_get_connections(struct hda_codec *codec, hda_nid_t nid,

	wcaps = get_wcaps(codec, nid);
	if (!(wcaps & AC_WCAP_CONN_LIST) &&
	    get_wcaps_type(wcaps) != AC_WID_VOL_KNB) {
		snd_printk(KERN_WARNING "hda_codec: "
			   "connection list not available for 0x%x\n", nid);
		return -EINVAL;
	}
	    get_wcaps_type(wcaps) != AC_WID_VOL_KNB)
		return 0;

	parm = snd_hda_param_read(codec, nid, AC_PAR_CONNLIST_LEN);
	if (parm & AC_CLIST_LONG) {
@@ -505,6 +502,41 @@ static bool add_conn_list(struct snd_array *array, hda_nid_t nid)
	return true;
}

/**
 * snd_hda_get_conn_index - get the connection index of the given NID
 * @codec: the HDA codec
 * @mux: NID containing the list
 * @nid: NID to select
 * @recursive: 1 when searching NID recursively, otherwise 0
 *
 * Parses the connection list of the widget @mux and checks whether the
 * widget @nid is present.  If it is, return the connection index.
 * Otherwise it returns -1.
 */
int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux,
			   hda_nid_t nid, int recursive)
{
	hda_nid_t conn[HDA_MAX_NUM_INPUTS];
	int i, nums;

	nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
	for (i = 0; i < nums; i++)
		if (conn[i] == nid)
			return i;
	if (!recursive)
		return -1;
	if (recursive > 5) {
		snd_printd("hda_codec: too deep connection for 0x%x\n", nid);
		return -1;
	}
	recursive++;
	for (i = 0; i < nums; i++)
		if (snd_hda_get_conn_index(codec, conn[i], nid, recursive) >= 0)
			return i;
	return -1;
}
EXPORT_SYMBOL_HDA(snd_hda_get_conn_index);

/**
 * snd_hda_queue_unsol_event - add an unsolicited event to queue
 * @bus: the BUS
+2 −0
Original line number Diff line number Diff line
@@ -905,6 +905,8 @@ int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
			    hda_nid_t *conn_list, int max_conns);
int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid,
			  const hda_nid_t **listp);
int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux,
			   hda_nid_t nid, int recursive);
int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
				u32 *ratesp, u64 *formatsp, unsigned int *bpsp);

+5 −11
Original line number Diff line number Diff line
@@ -346,23 +346,17 @@ static hda_nid_t get_adc(struct hda_codec *codec, hda_nid_t pin,

	nid = codec->start_nid;
	for (i = 0; i < codec->num_nodes; i++, nid++) {
		hda_nid_t pins[2];
		unsigned int type;
		int j, nums;
		int idx;
		type = get_wcaps_type(get_wcaps(codec, nid));
		if (type != AC_WID_AUD_IN)
			continue;
		nums = snd_hda_get_connections(codec, nid, pins,
					       ARRAY_SIZE(pins));
		if (nums <= 0)
			continue;
		for (j = 0; j < nums; j++) {
			if (pins[j] == pin) {
				*idxp = j;
		idx = snd_hda_get_conn_index(codec, nid, pin, 0);
		if (idx >= 0) {
			*idxp = idx;
			return nid;
		}
	}
	}
	return 0;
}

+4 −7
Original line number Diff line number Diff line
@@ -403,7 +403,6 @@ static int cmi9880_fill_multi_init(struct hda_codec *codec, const struct auto_pi
	/* clear the table, only one c-media dac assumed here */
	memset(spec->multi_init, 0, sizeof(spec->multi_init));
	for (j = 0, i = 0; i < cfg->line_outs; i++) {
		hda_nid_t conn[4];
		nid = cfg->line_out_pins[i];
		/* set as output */
		spec->multi_init[j].nid = nid;
@@ -416,12 +415,10 @@ static int cmi9880_fill_multi_init(struct hda_codec *codec, const struct auto_pi
			spec->multi_init[j].verb = AC_VERB_SET_CONNECT_SEL;
			spec->multi_init[j].param = 0;
			/* find the index in connect list */
			len = snd_hda_get_connections(codec, nid, conn, 4);
			for (k = 0; k < len; k++)
				if (conn[k] == spec->dac_nids[i]) {
			k = snd_hda_get_conn_index(codec, nid,
						   spec->dac_nids[i], 0);
			if (k >= 0)
				spec->multi_init[j].param = k;
					break;
				}
			j++;
		}
	}
+2 −13
Original line number Diff line number Diff line
@@ -3308,19 +3308,8 @@ static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {

static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };

/* get the connection index of @nid in the widget @mux */
static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
				hda_nid_t nid)
{
	hda_nid_t conn[HDA_MAX_NUM_INPUTS];
	int i, nums;

	nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
	for (i = 0; i < nums; i++)
		if (conn[i] == nid)
			return i;
	return -1;
}
#define get_connection_index(codec, mux, nid)\
	snd_hda_get_conn_index(codec, mux, nid, 0)

/* get an unassigned DAC from the given list.
 * Return the nid if found and reduce the DAC list, or return zero if
Loading