xref: /openbmc/linux/sound/pci/hda/hda_jack.c (revision a9c74173f4be2a536ef8d8c88642e41527f2d8b4)
11835a0f9STakashi Iwai /*
21835a0f9STakashi Iwai  * Jack-detection handling for HD-audio
31835a0f9STakashi Iwai  *
41835a0f9STakashi Iwai  * Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
51835a0f9STakashi Iwai  *
61835a0f9STakashi Iwai  * This driver is free software; you can redistribute it and/or modify
71835a0f9STakashi Iwai  * it under the terms of the GNU General Public License as published by
81835a0f9STakashi Iwai  * the Free Software Foundation; either version 2 of the License, or
91835a0f9STakashi Iwai  * (at your option) any later version.
101835a0f9STakashi Iwai  */
111835a0f9STakashi Iwai 
121835a0f9STakashi Iwai #include <linux/init.h>
131835a0f9STakashi Iwai #include <linux/slab.h>
14bf815bf0STakashi Iwai #include <linux/export.h>
151835a0f9STakashi Iwai #include <sound/core.h>
1601a61e12STakashi Iwai #include <sound/control.h>
17aad37dbdSTakashi Iwai #include <sound/jack.h>
181835a0f9STakashi Iwai #include "hda_codec.h"
191835a0f9STakashi Iwai #include "hda_local.h"
201835a0f9STakashi Iwai #include "hda_jack.h"
211835a0f9STakashi Iwai 
22*a9c74173STakashi Iwai bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid)
23*a9c74173STakashi Iwai {
24*a9c74173STakashi Iwai 	if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_PRES_DETECT))
25*a9c74173STakashi Iwai 		return false;
26*a9c74173STakashi Iwai 	if (!codec->ignore_misc_bit &&
27*a9c74173STakashi Iwai 	    (get_defcfg_misc(snd_hda_codec_get_pincfg(codec, nid)) &
28*a9c74173STakashi Iwai 	     AC_DEFCFG_MISC_NO_PRESENCE))
29*a9c74173STakashi Iwai 		return false;
30*a9c74173STakashi Iwai 	if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
31*a9c74173STakashi Iwai 		return false;
32*a9c74173STakashi Iwai 	return true;
33*a9c74173STakashi Iwai }
34*a9c74173STakashi Iwai EXPORT_SYMBOL_HDA(is_jack_detectable);
35*a9c74173STakashi Iwai 
361835a0f9STakashi Iwai /* execute pin sense measurement */
371835a0f9STakashi Iwai static u32 read_pin_sense(struct hda_codec *codec, hda_nid_t nid)
381835a0f9STakashi Iwai {
391835a0f9STakashi Iwai 	u32 pincap;
401835a0f9STakashi Iwai 
411835a0f9STakashi Iwai 	if (!codec->no_trigger_sense) {
421835a0f9STakashi Iwai 		pincap = snd_hda_query_pin_caps(codec, nid);
431835a0f9STakashi Iwai 		if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
441835a0f9STakashi Iwai 			snd_hda_codec_read(codec, nid, 0,
451835a0f9STakashi Iwai 					AC_VERB_SET_PIN_SENSE, 0);
461835a0f9STakashi Iwai 	}
471835a0f9STakashi Iwai 	return snd_hda_codec_read(codec, nid, 0,
481835a0f9STakashi Iwai 				  AC_VERB_GET_PIN_SENSE, 0);
491835a0f9STakashi Iwai }
501835a0f9STakashi Iwai 
511835a0f9STakashi Iwai /**
521835a0f9STakashi Iwai  * snd_hda_jack_tbl_get - query the jack-table entry for the given NID
531835a0f9STakashi Iwai  */
541835a0f9STakashi Iwai struct hda_jack_tbl *
551835a0f9STakashi Iwai snd_hda_jack_tbl_get(struct hda_codec *codec, hda_nid_t nid)
561835a0f9STakashi Iwai {
571835a0f9STakashi Iwai 	struct hda_jack_tbl *jack = codec->jacktbl.list;
581835a0f9STakashi Iwai 	int i;
591835a0f9STakashi Iwai 
601835a0f9STakashi Iwai 	if (!nid || !jack)
611835a0f9STakashi Iwai 		return NULL;
621835a0f9STakashi Iwai 	for (i = 0; i < codec->jacktbl.used; i++, jack++)
631835a0f9STakashi Iwai 		if (jack->nid == nid)
641835a0f9STakashi Iwai 			return jack;
651835a0f9STakashi Iwai 	return NULL;
661835a0f9STakashi Iwai }
671835a0f9STakashi Iwai EXPORT_SYMBOL_HDA(snd_hda_jack_tbl_get);
681835a0f9STakashi Iwai 
691835a0f9STakashi Iwai /**
703a93897eSTakashi Iwai  * snd_hda_jack_tbl_get_from_tag - query the jack-table entry for the given tag
713a93897eSTakashi Iwai  */
723a93897eSTakashi Iwai struct hda_jack_tbl *
733a93897eSTakashi Iwai snd_hda_jack_tbl_get_from_tag(struct hda_codec *codec, unsigned char tag)
743a93897eSTakashi Iwai {
753a93897eSTakashi Iwai 	struct hda_jack_tbl *jack = codec->jacktbl.list;
763a93897eSTakashi Iwai 	int i;
773a93897eSTakashi Iwai 
783a93897eSTakashi Iwai 	if (!tag || !jack)
793a93897eSTakashi Iwai 		return NULL;
803a93897eSTakashi Iwai 	for (i = 0; i < codec->jacktbl.used; i++, jack++)
813a93897eSTakashi Iwai 		if (jack->tag == tag)
823a93897eSTakashi Iwai 			return jack;
833a93897eSTakashi Iwai 	return NULL;
843a93897eSTakashi Iwai }
853a93897eSTakashi Iwai EXPORT_SYMBOL_HDA(snd_hda_jack_tbl_get_from_tag);
863a93897eSTakashi Iwai 
873a93897eSTakashi Iwai /**
881835a0f9STakashi Iwai  * snd_hda_jack_tbl_new - create a jack-table entry for the given NID
891835a0f9STakashi Iwai  */
901835a0f9STakashi Iwai struct hda_jack_tbl *
911835a0f9STakashi Iwai snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid)
921835a0f9STakashi Iwai {
931835a0f9STakashi Iwai 	struct hda_jack_tbl *jack = snd_hda_jack_tbl_get(codec, nid);
941835a0f9STakashi Iwai 	if (jack)
951835a0f9STakashi Iwai 		return jack;
961835a0f9STakashi Iwai 	snd_array_init(&codec->jacktbl, sizeof(*jack), 16);
971835a0f9STakashi Iwai 	jack = snd_array_new(&codec->jacktbl);
981835a0f9STakashi Iwai 	if (!jack)
991835a0f9STakashi Iwai 		return NULL;
1001835a0f9STakashi Iwai 	jack->nid = nid;
1011835a0f9STakashi Iwai 	jack->jack_dirty = 1;
1023a93897eSTakashi Iwai 	jack->tag = codec->jacktbl.used;
1031835a0f9STakashi Iwai 	return jack;
1041835a0f9STakashi Iwai }
105d1cb6200SDavid Henningsson EXPORT_SYMBOL_HDA(snd_hda_jack_tbl_new);
1061835a0f9STakashi Iwai 
1071835a0f9STakashi Iwai void snd_hda_jack_tbl_clear(struct hda_codec *codec)
1081835a0f9STakashi Iwai {
10931ef2257STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK
11031ef2257STakashi Iwai 	/* free jack instances manually when clearing/reconfiguring */
11131ef2257STakashi Iwai 	if (!codec->bus->shutdown && codec->jacktbl.list) {
11231ef2257STakashi Iwai 		struct hda_jack_tbl *jack = codec->jacktbl.list;
11331ef2257STakashi Iwai 		int i;
11431ef2257STakashi Iwai 		for (i = 0; i < codec->jacktbl.used; i++, jack++) {
11531ef2257STakashi Iwai 			if (jack->jack)
11631ef2257STakashi Iwai 				snd_device_free(codec->bus->card, jack->jack);
11731ef2257STakashi Iwai 		}
11831ef2257STakashi Iwai 	}
11931ef2257STakashi Iwai #endif
1201835a0f9STakashi Iwai 	snd_array_free(&codec->jacktbl);
1211835a0f9STakashi Iwai }
1221835a0f9STakashi Iwai 
1231835a0f9STakashi Iwai /* update the cached value and notification flag if needed */
1241835a0f9STakashi Iwai static void jack_detect_update(struct hda_codec *codec,
1251835a0f9STakashi Iwai 			       struct hda_jack_tbl *jack)
1261835a0f9STakashi Iwai {
1273a93897eSTakashi Iwai 	if (jack->jack_dirty || !jack->jack_detect) {
12835be544aSTakashi Iwai 		jack->pin_sense = read_pin_sense(codec, jack->nid);
1291835a0f9STakashi Iwai 		jack->jack_dirty = 0;
1301835a0f9STakashi Iwai 	}
1311835a0f9STakashi Iwai }
1321835a0f9STakashi Iwai 
1331835a0f9STakashi Iwai /**
1341835a0f9STakashi Iwai  * snd_hda_set_dirty_all - Mark all the cached as dirty
1351835a0f9STakashi Iwai  *
1361835a0f9STakashi Iwai  * This function sets the dirty flag to all entries of jack table.
1371835a0f9STakashi Iwai  * It's called from the resume path in hda_codec.c.
1381835a0f9STakashi Iwai  */
1391835a0f9STakashi Iwai void snd_hda_jack_set_dirty_all(struct hda_codec *codec)
1401835a0f9STakashi Iwai {
1411835a0f9STakashi Iwai 	struct hda_jack_tbl *jack = codec->jacktbl.list;
1421835a0f9STakashi Iwai 	int i;
1431835a0f9STakashi Iwai 
1441835a0f9STakashi Iwai 	for (i = 0; i < codec->jacktbl.used; i++, jack++)
1451835a0f9STakashi Iwai 		if (jack->nid)
1461835a0f9STakashi Iwai 			jack->jack_dirty = 1;
1471835a0f9STakashi Iwai }
1481835a0f9STakashi Iwai EXPORT_SYMBOL_HDA(snd_hda_jack_set_dirty_all);
1491835a0f9STakashi Iwai 
1501835a0f9STakashi Iwai /**
1511835a0f9STakashi Iwai  * snd_hda_pin_sense - execute pin sense measurement
1521835a0f9STakashi Iwai  * @codec: the CODEC to sense
1531835a0f9STakashi Iwai  * @nid: the pin NID to sense
1541835a0f9STakashi Iwai  *
1551835a0f9STakashi Iwai  * Execute necessary pin sense measurement and return its Presence Detect,
1561835a0f9STakashi Iwai  * Impedance, ELD Valid etc. status bits.
1571835a0f9STakashi Iwai  */
1581835a0f9STakashi Iwai u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid)
1591835a0f9STakashi Iwai {
1601835a0f9STakashi Iwai 	struct hda_jack_tbl *jack = snd_hda_jack_tbl_get(codec, nid);
1611835a0f9STakashi Iwai 	if (jack) {
1621835a0f9STakashi Iwai 		jack_detect_update(codec, jack);
1631835a0f9STakashi Iwai 		return jack->pin_sense;
1641835a0f9STakashi Iwai 	}
1651835a0f9STakashi Iwai 	return read_pin_sense(codec, nid);
1661835a0f9STakashi Iwai }
1671835a0f9STakashi Iwai EXPORT_SYMBOL_HDA(snd_hda_pin_sense);
1681835a0f9STakashi Iwai 
16935be544aSTakashi Iwai #define get_jack_plug_state(sense) !!(sense & AC_PINSENSE_PRESENCE)
17035be544aSTakashi Iwai 
1711835a0f9STakashi Iwai /**
1721835a0f9STakashi Iwai  * snd_hda_jack_detect - query pin Presence Detect status
1731835a0f9STakashi Iwai  * @codec: the CODEC to sense
1741835a0f9STakashi Iwai  * @nid: the pin NID to sense
1751835a0f9STakashi Iwai  *
1761835a0f9STakashi Iwai  * Query and return the pin's Presence Detect status.
1771835a0f9STakashi Iwai  */
1781835a0f9STakashi Iwai int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid)
1791835a0f9STakashi Iwai {
1801835a0f9STakashi Iwai 	u32 sense = snd_hda_pin_sense(codec, nid);
18135be544aSTakashi Iwai 	return get_jack_plug_state(sense);
1821835a0f9STakashi Iwai }
1831835a0f9STakashi Iwai EXPORT_SYMBOL_HDA(snd_hda_jack_detect);
1841835a0f9STakashi Iwai 
1851835a0f9STakashi Iwai /**
1861835a0f9STakashi Iwai  * snd_hda_jack_detect_enable - enable the jack-detection
1871835a0f9STakashi Iwai  */
1881835a0f9STakashi Iwai int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid,
1893a93897eSTakashi Iwai 			       unsigned char action)
1901835a0f9STakashi Iwai {
1911835a0f9STakashi Iwai 	struct hda_jack_tbl *jack = snd_hda_jack_tbl_new(codec, nid);
1921835a0f9STakashi Iwai 	if (!jack)
1931835a0f9STakashi Iwai 		return -ENOMEM;
1943a93897eSTakashi Iwai 	if (jack->jack_detect)
19501a61e12STakashi Iwai 		return 0; /* already registered */
1963a93897eSTakashi Iwai 	jack->jack_detect = 1;
1973a93897eSTakashi Iwai 	if (action)
1983a93897eSTakashi Iwai 		jack->action = action;
1991835a0f9STakashi Iwai 	return snd_hda_codec_write_cache(codec, nid, 0,
2001835a0f9STakashi Iwai 					 AC_VERB_SET_UNSOLICITED_ENABLE,
2013a93897eSTakashi Iwai 					 AC_USRSP_EN | jack->tag);
2021835a0f9STakashi Iwai }
2031835a0f9STakashi Iwai EXPORT_SYMBOL_HDA(snd_hda_jack_detect_enable);
20401a61e12STakashi Iwai 
20501a61e12STakashi Iwai /**
20601a61e12STakashi Iwai  * snd_hda_jack_report_sync - sync the states of all jacks and report if changed
20701a61e12STakashi Iwai  */
20801a61e12STakashi Iwai void snd_hda_jack_report_sync(struct hda_codec *codec)
20901a61e12STakashi Iwai {
21001a61e12STakashi Iwai 	struct hda_jack_tbl *jack = codec->jacktbl.list;
21135be544aSTakashi Iwai 	int i, state;
21201a61e12STakashi Iwai 
21301a61e12STakashi Iwai 	for (i = 0; i < codec->jacktbl.used; i++, jack++)
21401a61e12STakashi Iwai 		if (jack->nid) {
21501a61e12STakashi Iwai 			jack_detect_update(codec, jack);
216cfc7c9d3STakashi Iwai 			if (!jack->kctl)
217cfc7c9d3STakashi Iwai 				continue;
21835be544aSTakashi Iwai 			state = get_jack_plug_state(jack->pin_sense);
219aad37dbdSTakashi Iwai 			snd_kctl_jack_report(codec->bus->card, jack->kctl, state);
22031ef2257STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK
22131ef2257STakashi Iwai 			if (jack->jack)
22231ef2257STakashi Iwai 				snd_jack_report(jack->jack,
22331ef2257STakashi Iwai 						state ? jack->type : 0);
22431ef2257STakashi Iwai #endif
22501a61e12STakashi Iwai 		}
22601a61e12STakashi Iwai }
22701a61e12STakashi Iwai EXPORT_SYMBOL_HDA(snd_hda_jack_report_sync);
22801a61e12STakashi Iwai 
22931ef2257STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK
23031ef2257STakashi Iwai /* guess the jack type from the pin-config */
23131ef2257STakashi Iwai static int get_input_jack_type(struct hda_codec *codec, hda_nid_t nid)
23231ef2257STakashi Iwai {
23331ef2257STakashi Iwai 	unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
23431ef2257STakashi Iwai 	switch (get_defcfg_device(def_conf)) {
23531ef2257STakashi Iwai 	case AC_JACK_LINE_OUT:
23631ef2257STakashi Iwai 	case AC_JACK_SPEAKER:
23731ef2257STakashi Iwai 		return SND_JACK_LINEOUT;
23831ef2257STakashi Iwai 	case AC_JACK_HP_OUT:
23931ef2257STakashi Iwai 		return SND_JACK_HEADPHONE;
24031ef2257STakashi Iwai 	case AC_JACK_SPDIF_OUT:
24131ef2257STakashi Iwai 	case AC_JACK_DIG_OTHER_OUT:
24231ef2257STakashi Iwai 		return SND_JACK_AVOUT;
24331ef2257STakashi Iwai 	case AC_JACK_MIC_IN:
24431ef2257STakashi Iwai 		return SND_JACK_MICROPHONE;
24531ef2257STakashi Iwai 	default:
24631ef2257STakashi Iwai 		return SND_JACK_LINEIN;
24731ef2257STakashi Iwai 	}
24831ef2257STakashi Iwai }
24931ef2257STakashi Iwai 
25031ef2257STakashi Iwai static void hda_free_jack_priv(struct snd_jack *jack)
25131ef2257STakashi Iwai {
25231ef2257STakashi Iwai 	struct hda_jack_tbl *jacks = jack->private_data;
25331ef2257STakashi Iwai 	jacks->nid = 0;
25431ef2257STakashi Iwai 	jacks->jack = NULL;
25531ef2257STakashi Iwai }
25631ef2257STakashi Iwai #endif
25731ef2257STakashi Iwai 
25801a61e12STakashi Iwai /**
25901a61e12STakashi Iwai  * snd_hda_jack_add_kctl - Add a kctl for the given pin
26001a61e12STakashi Iwai  *
26101a61e12STakashi Iwai  * This assigns a jack-detection kctl to the given pin.  The kcontrol
26201a61e12STakashi Iwai  * will have the given name and index.
26301a61e12STakashi Iwai  */
26401a61e12STakashi Iwai int snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,
26501a61e12STakashi Iwai 			  const char *name, int idx)
26601a61e12STakashi Iwai {
26701a61e12STakashi Iwai 	struct hda_jack_tbl *jack;
26801a61e12STakashi Iwai 	struct snd_kcontrol *kctl;
26931ef2257STakashi Iwai 	int err, state;
27001a61e12STakashi Iwai 
2713a93897eSTakashi Iwai 	jack = snd_hda_jack_tbl_new(codec, nid);
27201a61e12STakashi Iwai 	if (!jack)
27301a61e12STakashi Iwai 		return 0;
27401a61e12STakashi Iwai 	if (jack->kctl)
27501a61e12STakashi Iwai 		return 0; /* already created */
27635be544aSTakashi Iwai 	kctl = snd_kctl_jack_new(name, idx, codec);
27701a61e12STakashi Iwai 	if (!kctl)
27801a61e12STakashi Iwai 		return -ENOMEM;
27931ef2257STakashi Iwai 	err = snd_hda_ctl_add(codec, nid, kctl);
28031ef2257STakashi Iwai 	if (err < 0)
28131ef2257STakashi Iwai 		return err;
28201a61e12STakashi Iwai 	jack->kctl = kctl;
28331ef2257STakashi Iwai 	state = snd_hda_jack_detect(codec, nid);
28431ef2257STakashi Iwai 	snd_kctl_jack_report(codec->bus->card, kctl, state);
28531ef2257STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK
28631ef2257STakashi Iwai 	jack->type = get_input_jack_type(codec, nid);
28731ef2257STakashi Iwai 	err = snd_jack_new(codec->bus->card, name, jack->type, &jack->jack);
28831ef2257STakashi Iwai 	if (err < 0)
28931ef2257STakashi Iwai 		return err;
29031ef2257STakashi Iwai 	jack->jack->private_data = jack;
29131ef2257STakashi Iwai 	jack->jack->private_free = hda_free_jack_priv;
29231ef2257STakashi Iwai 	snd_jack_report(jack->jack, state ? jack->type : 0);
29331ef2257STakashi Iwai #endif
29401a61e12STakashi Iwai 	return 0;
29501a61e12STakashi Iwai }
296d1cb6200SDavid Henningsson EXPORT_SYMBOL_HDA(snd_hda_jack_add_kctl);
29701a61e12STakashi Iwai 
298201e06ffSTakashi Iwai static int add_jack_kctl(struct hda_codec *codec, hda_nid_t nid,
29905c3b36eSDavid Henningsson 			 const struct auto_pin_cfg *cfg,
30005c3b36eSDavid Henningsson 			 char *lastname, int *lastidx)
30101a61e12STakashi Iwai {
3023a93897eSTakashi Iwai 	unsigned int def_conf, conn;
303201e06ffSTakashi Iwai 	char name[44];
304201e06ffSTakashi Iwai 	int idx, err;
3053a93897eSTakashi Iwai 
30601a61e12STakashi Iwai 	if (!nid)
30701a61e12STakashi Iwai 		return 0;
30801a61e12STakashi Iwai 	if (!is_jack_detectable(codec, nid))
30901a61e12STakashi Iwai 		return 0;
3103a93897eSTakashi Iwai 	def_conf = snd_hda_codec_get_pincfg(codec, nid);
3113a93897eSTakashi Iwai 	conn = get_defcfg_connect(def_conf);
3123a93897eSTakashi Iwai 	if (conn != AC_JACK_PORT_COMPLEX)
3133a93897eSTakashi Iwai 		return 0;
3143a93897eSTakashi Iwai 
315201e06ffSTakashi Iwai 	snd_hda_get_pin_label(codec, nid, cfg, name, sizeof(name), &idx);
31605c3b36eSDavid Henningsson 	if (!strcmp(name, lastname) && idx == *lastidx)
31705c3b36eSDavid Henningsson 		idx++;
31805c3b36eSDavid Henningsson 	strncpy(lastname, name, 44);
31905c3b36eSDavid Henningsson 	*lastidx = idx;
320201e06ffSTakashi Iwai 	err = snd_hda_jack_add_kctl(codec, nid, name, idx);
3213a93897eSTakashi Iwai 	if (err < 0)
3223a93897eSTakashi Iwai 		return err;
3233a93897eSTakashi Iwai 	return snd_hda_jack_detect_enable(codec, nid, 0);
32401a61e12STakashi Iwai }
32501a61e12STakashi Iwai 
32601a61e12STakashi Iwai /**
32701a61e12STakashi Iwai  * snd_hda_jack_add_kctls - Add kctls for all pins included in the given pincfg
32801a61e12STakashi Iwai  */
32901a61e12STakashi Iwai int snd_hda_jack_add_kctls(struct hda_codec *codec,
33001a61e12STakashi Iwai 			   const struct auto_pin_cfg *cfg)
33101a61e12STakashi Iwai {
33201a61e12STakashi Iwai 	const hda_nid_t *p;
33305c3b36eSDavid Henningsson 	int i, err, lastidx = 0;
33405c3b36eSDavid Henningsson 	char lastname[44] = "";
33501a61e12STakashi Iwai 
33601a61e12STakashi Iwai 	for (i = 0, p = cfg->line_out_pins; i < cfg->line_outs; i++, p++) {
33705c3b36eSDavid Henningsson 		err = add_jack_kctl(codec, *p, cfg, lastname, &lastidx);
33801a61e12STakashi Iwai 		if (err < 0)
33901a61e12STakashi Iwai 			return err;
34001a61e12STakashi Iwai 	}
34101a61e12STakashi Iwai 	for (i = 0, p = cfg->hp_pins; i < cfg->hp_outs; i++, p++) {
34201a61e12STakashi Iwai 		if (*p == *cfg->line_out_pins) /* might be duplicated */
34301a61e12STakashi Iwai 			break;
34405c3b36eSDavid Henningsson 		err = add_jack_kctl(codec, *p, cfg, lastname, &lastidx);
34501a61e12STakashi Iwai 		if (err < 0)
34601a61e12STakashi Iwai 			return err;
34701a61e12STakashi Iwai 	}
34801a61e12STakashi Iwai 	for (i = 0, p = cfg->speaker_pins; i < cfg->speaker_outs; i++, p++) {
34901a61e12STakashi Iwai 		if (*p == *cfg->line_out_pins) /* might be duplicated */
35001a61e12STakashi Iwai 			break;
35105c3b36eSDavid Henningsson 		err = add_jack_kctl(codec, *p, cfg, lastname, &lastidx);
35201a61e12STakashi Iwai 		if (err < 0)
35301a61e12STakashi Iwai 			return err;
35401a61e12STakashi Iwai 	}
35501a61e12STakashi Iwai 	for (i = 0; i < cfg->num_inputs; i++) {
35605c3b36eSDavid Henningsson 		err = add_jack_kctl(codec, cfg->inputs[i].pin, cfg, lastname, &lastidx);
35701a61e12STakashi Iwai 		if (err < 0)
35801a61e12STakashi Iwai 			return err;
35901a61e12STakashi Iwai 	}
36001a61e12STakashi Iwai 	for (i = 0, p = cfg->dig_out_pins; i < cfg->dig_outs; i++, p++) {
36105c3b36eSDavid Henningsson 		err = add_jack_kctl(codec, *p, cfg, lastname, &lastidx);
36201a61e12STakashi Iwai 		if (err < 0)
36301a61e12STakashi Iwai 			return err;
36401a61e12STakashi Iwai 	}
36505c3b36eSDavid Henningsson 	err = add_jack_kctl(codec, cfg->dig_in_pin, cfg, lastname, &lastidx);
36601a61e12STakashi Iwai 	if (err < 0)
36701a61e12STakashi Iwai 		return err;
36805c3b36eSDavid Henningsson 	err = add_jack_kctl(codec, cfg->mono_out_pin, cfg, lastname, &lastidx);
36901a61e12STakashi Iwai 	if (err < 0)
37001a61e12STakashi Iwai 		return err;
37101a61e12STakashi Iwai 	return 0;
37201a61e12STakashi Iwai }
37301a61e12STakashi Iwai EXPORT_SYMBOL_HDA(snd_hda_jack_add_kctls);
374