aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2011-12-20 09:42:57 -0500
committerTakashi Iwai <tiwai@suse.de>2011-12-20 09:42:57 -0500
commit78c058df6a120044455b5635daefdc515bf9d899 (patch)
treed349e70e384404a9a2d9860feb0219e9f8acb212 /sound
parentdb9c6f842fa957b41984cd8ceea1f07c53fb3fbf (diff)
parent31ef22579302ac42054bebecb528710f46580925 (diff)
Merge branch 'test/hda-jack' into topic/hda
Conflicts: sound/pci/hda/patch_hdmi.c sound/pci/hda/patch_via.c
Diffstat (limited to 'sound')
-rw-r--r--sound/core/Kconfig3
-rw-r--r--sound/core/Makefile1
-rw-r--r--sound/core/ctljack.c56
-rw-r--r--sound/pci/hda/Kconfig1
-rw-r--r--sound/pci/hda/Makefile2
-rw-r--r--sound/pci/hda/hda_codec.c296
-rw-r--r--sound/pci/hda/hda_codec.h3
-rw-r--r--sound/pci/hda/hda_jack.c353
-rw-r--r--sound/pci/hda/hda_jack.h86
-rw-r--r--sound/pci/hda/hda_local.h44
-rw-r--r--sound/pci/hda/patch_analog.c1
-rw-r--r--sound/pci/hda/patch_ca0110.c6
-rw-r--r--sound/pci/hda/patch_cirrus.c50
-rw-r--r--sound/pci/hda/patch_conexant.c77
-rw-r--r--sound/pci/hda/patch_hdmi.c37
-rw-r--r--sound/pci/hda/patch_realtek.c84
-rw-r--r--sound/pci/hda/patch_sigmatel.c196
-rw-r--r--sound/pci/hda/patch_via.c25
18 files changed, 826 insertions, 495 deletions
diff --git a/sound/core/Kconfig b/sound/core/Kconfig
index 475455c76610..66f287f2f759 100644
--- a/sound/core/Kconfig
+++ b/sound/core/Kconfig
@@ -207,6 +207,9 @@ config SND_PCM_XRUN_DEBUG
207config SND_VMASTER 207config SND_VMASTER
208 bool 208 bool
209 209
210config SND_KCTL_JACK
211 bool
212
210config SND_DMA_SGBUF 213config SND_DMA_SGBUF
211 def_bool y 214 def_bool y
212 depends on X86 215 depends on X86
diff --git a/sound/core/Makefile b/sound/core/Makefile
index 350a08d277f4..b4637c3e776e 100644
--- a/sound/core/Makefile
+++ b/sound/core/Makefile
@@ -7,6 +7,7 @@ snd-y := sound.o init.o memory.o info.o control.o misc.o device.o
7snd-$(CONFIG_ISA_DMA_API) += isadma.o 7snd-$(CONFIG_ISA_DMA_API) += isadma.o
8snd-$(CONFIG_SND_OSSEMUL) += sound_oss.o info_oss.o 8snd-$(CONFIG_SND_OSSEMUL) += sound_oss.o info_oss.o
9snd-$(CONFIG_SND_VMASTER) += vmaster.o 9snd-$(CONFIG_SND_VMASTER) += vmaster.o
10snd-$(CONFIG_SND_KCTL_JACK) += ctljack.o
10snd-$(CONFIG_SND_JACK) += jack.o 11snd-$(CONFIG_SND_JACK) += jack.o
11 12
12snd-pcm-objs := pcm.o pcm_native.o pcm_lib.o pcm_timer.o pcm_misc.o \ 13snd-pcm-objs := pcm.o pcm_native.o pcm_lib.o pcm_timer.o pcm_misc.o \
diff --git a/sound/core/ctljack.c b/sound/core/ctljack.c
new file mode 100644
index 000000000000..e4b38fbe51da
--- /dev/null
+++ b/sound/core/ctljack.c
@@ -0,0 +1,56 @@
1/*
2 * Helper functions for jack-detection kcontrols
3 *
4 * Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 */
11
12#include <linux/kernel.h>
13#include <linux/export.h>
14#include <sound/core.h>
15#include <sound/control.h>
16
17#define jack_detect_kctl_info snd_ctl_boolean_mono_info
18
19static int jack_detect_kctl_get(struct snd_kcontrol *kcontrol,
20 struct snd_ctl_elem_value *ucontrol)
21{
22 ucontrol->value.integer.value[0] = kcontrol->private_value;
23 return 0;
24}
25
26static struct snd_kcontrol_new jack_detect_kctl = {
27 /* name is filled later */
28 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
29 .access = SNDRV_CTL_ELEM_ACCESS_READ,
30 .info = jack_detect_kctl_info,
31 .get = jack_detect_kctl_get,
32};
33
34struct snd_kcontrol *
35snd_kctl_jack_new(const char *name, int idx, void *private_data)
36{
37 struct snd_kcontrol *kctl;
38 kctl = snd_ctl_new1(&jack_detect_kctl, private_data);
39 if (!kctl)
40 return NULL;
41 snprintf(kctl->id.name, sizeof(kctl->id.name), "%s Jack", name);
42 kctl->id.index = idx;
43 kctl->private_value = 0;
44 return kctl;
45}
46EXPORT_SYMBOL_GPL(snd_kctl_jack_new);
47
48void snd_kctl_jack_report(struct snd_card *card,
49 struct snd_kcontrol *kctl, bool status)
50{
51 if (kctl->private_value == status)
52 return;
53 kctl->private_value = status;
54 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
55}
56EXPORT_SYMBOL_GPL(snd_kctl_jack_report);
diff --git a/sound/pci/hda/Kconfig b/sound/pci/hda/Kconfig
index bb7e102d6726..163b6b5de3eb 100644
--- a/sound/pci/hda/Kconfig
+++ b/sound/pci/hda/Kconfig
@@ -2,6 +2,7 @@ menuconfig SND_HDA_INTEL
2 tristate "Intel HD Audio" 2 tristate "Intel HD Audio"
3 select SND_PCM 3 select SND_PCM
4 select SND_VMASTER 4 select SND_VMASTER
5 select SND_KCTL_JACK
5 help 6 help
6 Say Y here to include support for Intel "High Definition 7 Say Y here to include support for Intel "High Definition
7 Audio" (Azalia) and its compatible devices. 8 Audio" (Azalia) and its compatible devices.
diff --git a/sound/pci/hda/Makefile b/sound/pci/hda/Makefile
index f928d6634723..ace157cc3d15 100644
--- a/sound/pci/hda/Makefile
+++ b/sound/pci/hda/Makefile
@@ -1,6 +1,6 @@
1snd-hda-intel-objs := hda_intel.o 1snd-hda-intel-objs := hda_intel.o
2 2
3snd-hda-codec-y := hda_codec.o 3snd-hda-codec-y := hda_codec.o hda_jack.o
4snd-hda-codec-$(CONFIG_SND_HDA_GENERIC) += hda_generic.o 4snd-hda-codec-$(CONFIG_SND_HDA_GENERIC) += hda_generic.o
5snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o 5snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o
6snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o 6snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 4463f9a9619a..4df72c0e8c37 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -33,6 +33,7 @@
33#include <sound/jack.h> 33#include <sound/jack.h>
34#include "hda_local.h" 34#include "hda_local.h"
35#include "hda_beep.h" 35#include "hda_beep.h"
36#include "hda_jack.h"
36#include <sound/hda_hwdep.h> 37#include <sound/hda_hwdep.h>
37 38
38#define CREATE_TRACE_POINTS 39#define CREATE_TRACE_POINTS
@@ -1723,43 +1724,6 @@ int snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid,
1723} 1724}
1724EXPORT_SYMBOL_HDA(snd_hda_override_pin_caps); 1725EXPORT_SYMBOL_HDA(snd_hda_override_pin_caps);
1725 1726
1726/**
1727 * snd_hda_pin_sense - execute pin sense measurement
1728 * @codec: the CODEC to sense
1729 * @nid: the pin NID to sense
1730 *
1731 * Execute necessary pin sense measurement and return its Presence Detect,
1732 * Impedance, ELD Valid etc. status bits.
1733 */
1734u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid)
1735{
1736 u32 pincap;
1737
1738 if (!codec->no_trigger_sense) {
1739 pincap = snd_hda_query_pin_caps(codec, nid);
1740 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
1741 snd_hda_codec_read(codec, nid, 0,
1742 AC_VERB_SET_PIN_SENSE, 0);
1743 }
1744 return snd_hda_codec_read(codec, nid, 0,
1745 AC_VERB_GET_PIN_SENSE, 0);
1746}
1747EXPORT_SYMBOL_HDA(snd_hda_pin_sense);
1748
1749/**
1750 * snd_hda_jack_detect - query pin Presence Detect status
1751 * @codec: the CODEC to sense
1752 * @nid: the pin NID to sense
1753 *
1754 * Query and return the pin's Presence Detect status.
1755 */
1756int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid)
1757{
1758 u32 sense = snd_hda_pin_sense(codec, nid);
1759 return !!(sense & AC_PINSENSE_PRESENCE);
1760}
1761EXPORT_SYMBOL_HDA(snd_hda_jack_detect);
1762
1763/* 1727/*
1764 * read the current volume to info 1728 * read the current volume to info
1765 * if the cache exists, read the cache value. 1729 * if the cache exists, read the cache value.
@@ -2308,6 +2272,7 @@ int snd_hda_codec_reset(struct hda_codec *codec)
2308 } 2272 }
2309 if (codec->patch_ops.free) 2273 if (codec->patch_ops.free)
2310 codec->patch_ops.free(codec); 2274 codec->patch_ops.free(codec);
2275 snd_hda_jack_tbl_clear(codec);
2311 codec->proc_widget_hook = NULL; 2276 codec->proc_widget_hook = NULL;
2312 codec->spec = NULL; 2277 codec->spec = NULL;
2313 free_hda_cache(&codec->amp_cache); 2278 free_hda_cache(&codec->amp_cache);
@@ -3364,6 +3329,7 @@ static void hda_call_codec_resume(struct hda_codec *codec)
3364 restore_pincfgs(codec); /* restore all current pin configs */ 3329 restore_pincfgs(codec); /* restore all current pin configs */
3365 restore_shutup_pins(codec); 3330 restore_shutup_pins(codec);
3366 hda_exec_init_verbs(codec); 3331 hda_exec_init_verbs(codec);
3332 snd_hda_jack_set_dirty_all(codec);
3367 if (codec->patch_ops.resume) 3333 if (codec->patch_ops.resume)
3368 codec->patch_ops.resume(codec); 3334 codec->patch_ops.resume(codec);
3369 else { 3335 else {
@@ -5010,8 +4976,8 @@ EXPORT_SYMBOL_HDA(snd_hda_get_input_pin_attr);
5010 * "Rear", "Internal". 4976 * "Rear", "Internal".
5011 */ 4977 */
5012 4978
5013const char *hda_get_input_pin_label(struct hda_codec *codec, hda_nid_t pin, 4979static const char *hda_get_input_pin_label(struct hda_codec *codec,
5014 int check_location) 4980 hda_nid_t pin, bool check_location)
5015{ 4981{
5016 unsigned int def_conf; 4982 unsigned int def_conf;
5017 static const char * const mic_names[] = { 4983 static const char * const mic_names[] = {
@@ -5050,7 +5016,6 @@ const char *hda_get_input_pin_label(struct hda_codec *codec, hda_nid_t pin,
5050 return "Misc"; 5016 return "Misc";
5051 } 5017 }
5052} 5018}
5053EXPORT_SYMBOL_HDA(hda_get_input_pin_label);
5054 5019
5055/* Check whether the location prefix needs to be added to the label. 5020/* Check whether the location prefix needs to be added to the label.
5056 * If all mic-jacks are in the same location (e.g. rear panel), we don't 5021 * If all mic-jacks are in the same location (e.g. rear panel), we don't
@@ -5107,6 +5072,149 @@ const char *hda_get_autocfg_input_label(struct hda_codec *codec,
5107} 5072}
5108EXPORT_SYMBOL_HDA(hda_get_autocfg_input_label); 5073EXPORT_SYMBOL_HDA(hda_get_autocfg_input_label);
5109 5074
5075/* return the position of NID in the list, or -1 if not found */
5076static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
5077{
5078 int i;
5079 for (i = 0; i < nums; i++)
5080 if (list[i] == nid)
5081 return i;
5082 return -1;
5083}
5084
5085/* get a unique suffix or an index number */
5086static const char *check_output_sfx(hda_nid_t nid, const hda_nid_t *pins,
5087 int num_pins, int *indexp)
5088{
5089 static const char * const channel_sfx[] = {
5090 " Front", " Surround", " CLFE", " Side"
5091 };
5092 int i;
5093
5094 i = find_idx_in_nid_list(nid, pins, num_pins);
5095 if (i < 0)
5096 return NULL;
5097 if (num_pins == 1)
5098 return "";
5099 if (num_pins > ARRAY_SIZE(channel_sfx)) {
5100 if (indexp)
5101 *indexp = i;
5102 return "";
5103 }
5104 return channel_sfx[i];
5105}
5106
5107static int fill_audio_out_name(struct hda_codec *codec, hda_nid_t nid,
5108 const struct auto_pin_cfg *cfg,
5109 const char *name, char *label, int maxlen,
5110 int *indexp)
5111{
5112 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
5113 int attr = snd_hda_get_input_pin_attr(def_conf);
5114 const char *pfx = "", *sfx = "";
5115
5116 /* handle as a speaker if it's a fixed line-out */
5117 if (!strcmp(name, "Line-Out") && attr == INPUT_PIN_ATTR_INT)
5118 name = "Speaker";
5119 /* check the location */
5120 switch (attr) {
5121 case INPUT_PIN_ATTR_DOCK:
5122 pfx = "Dock ";
5123 break;
5124 case INPUT_PIN_ATTR_FRONT:
5125 pfx = "Front ";
5126 break;
5127 }
5128 if (cfg) {
5129 /* try to give a unique suffix if needed */
5130 sfx = check_output_sfx(nid, cfg->line_out_pins, cfg->line_outs,
5131 indexp);
5132 if (!sfx)
5133 sfx = check_output_sfx(nid, cfg->speaker_pins, cfg->speaker_outs,
5134 indexp);
5135 if (!sfx) {
5136 /* don't add channel suffix for Headphone controls */
5137 int idx = find_idx_in_nid_list(nid, cfg->hp_pins,
5138 cfg->hp_outs);
5139 if (idx >= 0)
5140 *indexp = idx;
5141 sfx = "";
5142 }
5143 }
5144 snprintf(label, maxlen, "%s%s%s", pfx, name, sfx);
5145 return 1;
5146}
5147
5148/**
5149 * snd_hda_get_pin_label - Get a label for the given I/O pin
5150 *
5151 * Get a label for the given pin. This function works for both input and
5152 * output pins. When @cfg is given as non-NULL, the function tries to get
5153 * an optimized label using hda_get_autocfg_input_label().
5154 *
5155 * This function tries to give a unique label string for the pin as much as
5156 * possible. For example, when the multiple line-outs are present, it adds
5157 * the channel suffix like "Front", "Surround", etc (only when @cfg is given).
5158 * If no unique name with a suffix is available and @indexp is non-NULL, the
5159 * index number is stored in the pointer.
5160 */
5161int snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid,
5162 const struct auto_pin_cfg *cfg,
5163 char *label, int maxlen, int *indexp)
5164{
5165 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
5166 const char *name = NULL;
5167 int i;
5168
5169 if (indexp)
5170 *indexp = 0;
5171 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
5172 return 0;
5173
5174 switch (get_defcfg_device(def_conf)) {
5175 case AC_JACK_LINE_OUT:
5176 return fill_audio_out_name(codec, nid, cfg, "Line-Out",
5177 label, maxlen, indexp);
5178 case AC_JACK_SPEAKER:
5179 return fill_audio_out_name(codec, nid, cfg, "Speaker",
5180 label, maxlen, indexp);
5181 case AC_JACK_HP_OUT:
5182 return fill_audio_out_name(codec, nid, cfg, "Headphone",
5183 label, maxlen, indexp);
5184 case AC_JACK_SPDIF_OUT:
5185 case AC_JACK_DIG_OTHER_OUT:
5186 if (get_defcfg_location(def_conf) == AC_JACK_LOC_HDMI)
5187 name = "HDMI";
5188 else
5189 name = "SPDIF";
5190 if (cfg && indexp) {
5191 i = find_idx_in_nid_list(nid, cfg->dig_out_pins,
5192 cfg->dig_outs);
5193 if (i >= 0)
5194 *indexp = i;
5195 }
5196 break;
5197 default:
5198 if (cfg) {
5199 for (i = 0; i < cfg->num_inputs; i++) {
5200 if (cfg->inputs[i].pin != nid)
5201 continue;
5202 name = hda_get_autocfg_input_label(codec, cfg, i);
5203 if (name)
5204 break;
5205 }
5206 }
5207 if (!name)
5208 name = hda_get_input_pin_label(codec, nid, true);
5209 break;
5210 }
5211 if (!name)
5212 return 0;
5213 strlcpy(label, name, maxlen);
5214 return 1;
5215}
5216EXPORT_SYMBOL_HDA(snd_hda_get_pin_label);
5217
5110/** 5218/**
5111 * snd_hda_add_imux_item - Add an item to input_mux 5219 * snd_hda_add_imux_item - Add an item to input_mux
5112 * 5220 *
@@ -5258,113 +5366,5 @@ void snd_print_pcm_bits(int pcm, char *buf, int buflen)
5258} 5366}
5259EXPORT_SYMBOL_HDA(snd_print_pcm_bits); 5367EXPORT_SYMBOL_HDA(snd_print_pcm_bits);
5260 5368
5261#ifdef CONFIG_SND_HDA_INPUT_JACK
5262/*
5263 * Input-jack notification support
5264 */
5265struct hda_jack_item {
5266 hda_nid_t nid;
5267 int type;
5268 struct snd_jack *jack;
5269};
5270
5271static const char *get_jack_default_name(struct hda_codec *codec, hda_nid_t nid,
5272 int type)
5273{
5274 switch (type) {
5275 case SND_JACK_HEADPHONE:
5276 return "Headphone";
5277 case SND_JACK_MICROPHONE:
5278 return "Mic";
5279 case SND_JACK_LINEOUT:
5280 return "Line-out";
5281 case SND_JACK_LINEIN:
5282 return "Line-in";
5283 case SND_JACK_HEADSET:
5284 return "Headset";
5285 case SND_JACK_VIDEOOUT:
5286 return "HDMI/DP";
5287 default:
5288 return "Misc";
5289 }
5290}
5291
5292static void hda_free_jack_priv(struct snd_jack *jack)
5293{
5294 struct hda_jack_item *jacks = jack->private_data;
5295 jacks->nid = 0;
5296 jacks->jack = NULL;
5297}
5298
5299int snd_hda_input_jack_add(struct hda_codec *codec, hda_nid_t nid, int type,
5300 const char *name)
5301{
5302 struct hda_jack_item *jack;
5303 int err;
5304
5305 snd_array_init(&codec->jacks, sizeof(*jack), 32);
5306 jack = snd_array_new(&codec->jacks);
5307 if (!jack)
5308 return -ENOMEM;
5309
5310 jack->nid = nid;
5311 jack->type = type;
5312 if (!name)
5313 name = get_jack_default_name(codec, nid, type);
5314 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
5315 if (err < 0) {
5316 jack->nid = 0;
5317 return err;
5318 }
5319 jack->jack->private_data = jack;
5320 jack->jack->private_free = hda_free_jack_priv;
5321 return 0;
5322}
5323EXPORT_SYMBOL_HDA(snd_hda_input_jack_add);
5324
5325void snd_hda_input_jack_report(struct hda_codec *codec, hda_nid_t nid)
5326{
5327 struct hda_jack_item *jacks = codec->jacks.list;
5328 int i;
5329
5330 if (!jacks)
5331 return;
5332
5333 for (i = 0; i < codec->jacks.used; i++, jacks++) {
5334 unsigned int pin_ctl;
5335 unsigned int present;
5336 int type;
5337
5338 if (jacks->nid != nid)
5339 continue;
5340 present = snd_hda_jack_detect(codec, nid);
5341 type = jacks->type;
5342 if (type == (SND_JACK_HEADPHONE | SND_JACK_LINEOUT)) {
5343 pin_ctl = snd_hda_codec_read(codec, nid, 0,
5344 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5345 type = (pin_ctl & AC_PINCTL_HP_EN) ?
5346 SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
5347 }
5348 snd_jack_report(jacks->jack, present ? type : 0);
5349 }
5350}
5351EXPORT_SYMBOL_HDA(snd_hda_input_jack_report);
5352
5353/* free jack instances manually when clearing/reconfiguring */
5354void snd_hda_input_jack_free(struct hda_codec *codec)
5355{
5356 if (!codec->bus->shutdown && codec->jacks.list) {
5357 struct hda_jack_item *jacks = codec->jacks.list;
5358 int i;
5359 for (i = 0; i < codec->jacks.used; i++, jacks++) {
5360 if (jacks->jack)
5361 snd_device_free(codec->bus->card, jacks->jack);
5362 }
5363 }
5364 snd_array_free(&codec->jacks);
5365}
5366EXPORT_SYMBOL_HDA(snd_hda_input_jack_free);
5367#endif /* CONFIG_SND_HDA_INPUT_JACK */
5368
5369MODULE_DESCRIPTION("HDA codec core"); 5369MODULE_DESCRIPTION("HDA codec core");
5370MODULE_LICENSE("GPL"); 5370MODULE_LICENSE("GPL");
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index 17cee4ee8e65..e9f71dc0d464 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -866,6 +866,9 @@ struct hda_codec {
866 void (*proc_widget_hook)(struct snd_info_buffer *buffer, 866 void (*proc_widget_hook)(struct snd_info_buffer *buffer,
867 struct hda_codec *codec, hda_nid_t nid); 867 struct hda_codec *codec, hda_nid_t nid);
868 868
869 /* jack detection */
870 struct snd_array jacktbl;
871
869#ifdef CONFIG_SND_HDA_INPUT_JACK 872#ifdef CONFIG_SND_HDA_INPUT_JACK
870 /* jack detection */ 873 /* jack detection */
871 struct snd_array jacks; 874 struct snd_array jacks;
diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c
new file mode 100644
index 000000000000..d8a35da0803f
--- /dev/null
+++ b/sound/pci/hda/hda_jack.c
@@ -0,0 +1,353 @@
1/*
2 * Jack-detection handling for HD-audio
3 *
4 * Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
5 *
6 * This driver is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#include <linux/init.h>
13#include <linux/slab.h>
14#include <linux/export.h>
15#include <sound/core.h>
16#include <sound/control.h>
17#include <sound/jack.h>
18#include "hda_codec.h"
19#include "hda_local.h"
20#include "hda_jack.h"
21
22/* execute pin sense measurement */
23static u32 read_pin_sense(struct hda_codec *codec, hda_nid_t nid)
24{
25 u32 pincap;
26
27 if (!codec->no_trigger_sense) {
28 pincap = snd_hda_query_pin_caps(codec, nid);
29 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
30 snd_hda_codec_read(codec, nid, 0,
31 AC_VERB_SET_PIN_SENSE, 0);
32 }
33 return snd_hda_codec_read(codec, nid, 0,
34 AC_VERB_GET_PIN_SENSE, 0);
35}
36
37/**
38 * snd_hda_jack_tbl_get - query the jack-table entry for the given NID
39 */
40struct hda_jack_tbl *
41snd_hda_jack_tbl_get(struct hda_codec *codec, hda_nid_t nid)
42{
43 struct hda_jack_tbl *jack = codec->jacktbl.list;
44 int i;
45
46 if (!nid || !jack)
47 return NULL;
48 for (i = 0; i < codec->jacktbl.used; i++, jack++)
49 if (jack->nid == nid)
50 return jack;
51 return NULL;
52}
53EXPORT_SYMBOL_HDA(snd_hda_jack_tbl_get);
54
55/**
56 * snd_hda_jack_tbl_get_from_tag - query the jack-table entry for the given tag
57 */
58struct hda_jack_tbl *
59snd_hda_jack_tbl_get_from_tag(struct hda_codec *codec, unsigned char tag)
60{
61 struct hda_jack_tbl *jack = codec->jacktbl.list;
62 int i;
63
64 if (!tag || !jack)
65 return NULL;
66 for (i = 0; i < codec->jacktbl.used; i++, jack++)
67 if (jack->tag == tag)
68 return jack;
69 return NULL;
70}
71EXPORT_SYMBOL_HDA(snd_hda_jack_tbl_get_from_tag);
72
73/**
74 * snd_hda_jack_tbl_new - create a jack-table entry for the given NID
75 */
76struct hda_jack_tbl *
77snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid)
78{
79 struct hda_jack_tbl *jack = snd_hda_jack_tbl_get(codec, nid);
80 if (jack)
81 return jack;
82 snd_array_init(&codec->jacktbl, sizeof(*jack), 16);
83 jack = snd_array_new(&codec->jacktbl);
84 if (!jack)
85 return NULL;
86 jack->nid = nid;
87 jack->jack_dirty = 1;
88 jack->tag = codec->jacktbl.used;
89 return jack;
90}
91EXPORT_SYMBOL_HDA(snd_hda_jack_tbl_new);
92
93void snd_hda_jack_tbl_clear(struct hda_codec *codec)
94{
95#ifdef CONFIG_SND_HDA_INPUT_JACK
96 /* free jack instances manually when clearing/reconfiguring */
97 if (!codec->bus->shutdown && codec->jacktbl.list) {
98 struct hda_jack_tbl *jack = codec->jacktbl.list;
99 int i;
100 for (i = 0; i < codec->jacktbl.used; i++, jack++) {
101 if (jack->jack)
102 snd_device_free(codec->bus->card, jack->jack);
103 }
104 }
105#endif
106 snd_array_free(&codec->jacktbl);
107}
108
109/* update the cached value and notification flag if needed */
110static void jack_detect_update(struct hda_codec *codec,
111 struct hda_jack_tbl *jack)
112{
113 if (jack->jack_dirty || !jack->jack_detect) {
114 jack->pin_sense = read_pin_sense(codec, jack->nid);
115 jack->jack_dirty = 0;
116 }
117}
118
119/**
120 * snd_hda_set_dirty_all - Mark all the cached as dirty
121 *
122 * This function sets the dirty flag to all entries of jack table.
123 * It's called from the resume path in hda_codec.c.
124 */
125void snd_hda_jack_set_dirty_all(struct hda_codec *codec)
126{
127 struct hda_jack_tbl *jack = codec->jacktbl.list;
128 int i;
129
130 for (i = 0; i < codec->jacktbl.used; i++, jack++)
131 if (jack->nid)
132 jack->jack_dirty = 1;
133}
134EXPORT_SYMBOL_HDA(snd_hda_jack_set_dirty_all);
135
136/**
137 * snd_hda_pin_sense - execute pin sense measurement
138 * @codec: the CODEC to sense
139 * @nid: the pin NID to sense
140 *
141 * Execute necessary pin sense measurement and return its Presence Detect,
142 * Impedance, ELD Valid etc. status bits.
143 */
144u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid)
145{
146 struct hda_jack_tbl *jack = snd_hda_jack_tbl_get(codec, nid);
147 if (jack) {
148 jack_detect_update(codec, jack);
149 return jack->pin_sense;
150 }
151 return read_pin_sense(codec, nid);
152}
153EXPORT_SYMBOL_HDA(snd_hda_pin_sense);
154
155#define get_jack_plug_state(sense) !!(sense & AC_PINSENSE_PRESENCE)
156
157/**
158 * snd_hda_jack_detect - query pin Presence Detect status
159 * @codec: the CODEC to sense
160 * @nid: the pin NID to sense
161 *
162 * Query and return the pin's Presence Detect status.
163 */
164int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid)
165{
166 u32 sense = snd_hda_pin_sense(codec, nid);
167 return get_jack_plug_state(sense);
168}
169EXPORT_SYMBOL_HDA(snd_hda_jack_detect);
170
171/**
172 * snd_hda_jack_detect_enable - enable the jack-detection
173 */
174int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid,
175 unsigned char action)
176{
177 struct hda_jack_tbl *jack = snd_hda_jack_tbl_new(codec, nid);
178 if (!jack)
179 return -ENOMEM;
180 if (jack->jack_detect)
181 return 0; /* already registered */
182 jack->jack_detect = 1;
183 if (action)
184 jack->action = action;
185 return snd_hda_codec_write_cache(codec, nid, 0,
186 AC_VERB_SET_UNSOLICITED_ENABLE,
187 AC_USRSP_EN | jack->tag);
188}
189EXPORT_SYMBOL_HDA(snd_hda_jack_detect_enable);
190
191/**
192 * snd_hda_jack_report_sync - sync the states of all jacks and report if changed
193 */
194void snd_hda_jack_report_sync(struct hda_codec *codec)
195{
196 struct hda_jack_tbl *jack = codec->jacktbl.list;
197 int i, state;
198
199 for (i = 0; i < codec->jacktbl.used; i++, jack++)
200 if (jack->nid) {
201 jack_detect_update(codec, jack);
202 if (!jack->kctl)
203 continue;
204 state = get_jack_plug_state(jack->pin_sense);
205 snd_kctl_jack_report(codec->bus->card, jack->kctl, state);
206#ifdef CONFIG_SND_HDA_INPUT_JACK
207 if (jack->jack)
208 snd_jack_report(jack->jack,
209 state ? jack->type : 0);
210#endif
211 }
212}
213EXPORT_SYMBOL_HDA(snd_hda_jack_report_sync);
214
215#ifdef CONFIG_SND_HDA_INPUT_JACK
216/* guess the jack type from the pin-config */
217static int get_input_jack_type(struct hda_codec *codec, hda_nid_t nid)
218{
219 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
220 switch (get_defcfg_device(def_conf)) {
221 case AC_JACK_LINE_OUT:
222 case AC_JACK_SPEAKER:
223 return SND_JACK_LINEOUT;
224 case AC_JACK_HP_OUT:
225 return SND_JACK_HEADPHONE;
226 case AC_JACK_SPDIF_OUT:
227 case AC_JACK_DIG_OTHER_OUT:
228 return SND_JACK_AVOUT;
229 case AC_JACK_MIC_IN:
230 return SND_JACK_MICROPHONE;
231 default:
232 return SND_JACK_LINEIN;
233 }
234}
235
236static void hda_free_jack_priv(struct snd_jack *jack)
237{
238 struct hda_jack_tbl *jacks = jack->private_data;
239 jacks->nid = 0;
240 jacks->jack = NULL;
241}
242#endif
243
244/**
245 * snd_hda_jack_add_kctl - Add a kctl for the given pin
246 *
247 * This assigns a jack-detection kctl to the given pin. The kcontrol
248 * will have the given name and index.
249 */
250int snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,
251 const char *name, int idx)
252{
253 struct hda_jack_tbl *jack;
254 struct snd_kcontrol *kctl;
255 int err, state;
256
257 jack = snd_hda_jack_tbl_new(codec, nid);
258 if (!jack)
259 return 0;
260 if (jack->kctl)
261 return 0; /* already created */
262 kctl = snd_kctl_jack_new(name, idx, codec);
263 if (!kctl)
264 return -ENOMEM;
265 err = snd_hda_ctl_add(codec, nid, kctl);
266 if (err < 0)
267 return err;
268 jack->kctl = kctl;
269 state = snd_hda_jack_detect(codec, nid);
270 snd_kctl_jack_report(codec->bus->card, kctl, state);
271#ifdef CONFIG_SND_HDA_INPUT_JACK
272 jack->type = get_input_jack_type(codec, nid);
273 err = snd_jack_new(codec->bus->card, name, jack->type, &jack->jack);
274 if (err < 0)
275 return err;
276 jack->jack->private_data = jack;
277 jack->jack->private_free = hda_free_jack_priv;
278 snd_jack_report(jack->jack, state ? jack->type : 0);
279#endif
280 return 0;
281}
282EXPORT_SYMBOL_HDA(snd_hda_jack_add_kctl);
283
284static int add_jack_kctl(struct hda_codec *codec, hda_nid_t nid,
285 const struct auto_pin_cfg *cfg)
286{
287 unsigned int def_conf, conn;
288 char name[44];
289 int idx, err;
290
291 if (!nid)
292 return 0;
293 if (!is_jack_detectable(codec, nid))
294 return 0;
295 def_conf = snd_hda_codec_get_pincfg(codec, nid);
296 conn = get_defcfg_connect(def_conf);
297 if (conn != AC_JACK_PORT_COMPLEX)
298 return 0;
299
300 snd_hda_get_pin_label(codec, nid, cfg, name, sizeof(name), &idx);
301 err = snd_hda_jack_add_kctl(codec, nid, name, idx);
302 if (err < 0)
303 return err;
304 return snd_hda_jack_detect_enable(codec, nid, 0);
305}
306
307/**
308 * snd_hda_jack_add_kctls - Add kctls for all pins included in the given pincfg
309 */
310int snd_hda_jack_add_kctls(struct hda_codec *codec,
311 const struct auto_pin_cfg *cfg)
312{
313 const hda_nid_t *p;
314 int i, err;
315
316 for (i = 0, p = cfg->line_out_pins; i < cfg->line_outs; i++, p++) {
317 err = add_jack_kctl(codec, *p, cfg);
318 if (err < 0)
319 return err;
320 }
321 for (i = 0, p = cfg->hp_pins; i < cfg->hp_outs; i++, p++) {
322 if (*p == *cfg->line_out_pins) /* might be duplicated */
323 break;
324 err = add_jack_kctl(codec, *p, cfg);
325 if (err < 0)
326 return err;
327 }
328 for (i = 0, p = cfg->speaker_pins; i < cfg->speaker_outs; i++, p++) {
329 if (*p == *cfg->line_out_pins) /* might be duplicated */
330 break;
331 err = add_jack_kctl(codec, *p, cfg);
332 if (err < 0)
333 return err;
334 }
335 for (i = 0; i < cfg->num_inputs; i++) {
336 err = add_jack_kctl(codec, cfg->inputs[i].pin, cfg);
337 if (err < 0)
338 return err;
339 }
340 for (i = 0, p = cfg->dig_out_pins; i < cfg->dig_outs; i++, p++) {
341 err = add_jack_kctl(codec, *p, cfg);
342 if (err < 0)
343 return err;
344 }
345 err = add_jack_kctl(codec, cfg->dig_in_pin, cfg);
346 if (err < 0)
347 return err;
348 err = add_jack_kctl(codec, cfg->mono_out_pin, cfg);
349 if (err < 0)
350 return err;
351 return 0;
352}
353EXPORT_SYMBOL_HDA(snd_hda_jack_add_kctls);
diff --git a/sound/pci/hda/hda_jack.h b/sound/pci/hda/hda_jack.h
new file mode 100644
index 000000000000..f8f97c71c9c1
--- /dev/null
+++ b/sound/pci/hda/hda_jack.h
@@ -0,0 +1,86 @@
1/*
2 * Jack-detection handling for HD-audio
3 *
4 * Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
5 *
6 * This driver is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#ifndef __SOUND_HDA_JACK_H
13#define __SOUND_HDA_JACK_H
14
15struct hda_jack_tbl {
16 hda_nid_t nid;
17 unsigned char action; /* event action (0 = none) */
18 unsigned char tag; /* unsol event tag */
19 unsigned int private_data; /* arbitrary data */
20 /* jack-detection stuff */
21 unsigned int pin_sense; /* cached pin-sense value */
22 unsigned int jack_detect:1; /* capable of jack-detection? */
23 unsigned int jack_dirty:1; /* needs to update? */
24 struct snd_kcontrol *kctl; /* assigned kctl for jack-detection */
25#ifdef CONFIG_SND_HDA_INPUT_JACK
26 int type;
27 struct snd_jack *jack;
28#endif
29};
30
31struct hda_jack_tbl *
32snd_hda_jack_tbl_get(struct hda_codec *codec, hda_nid_t nid);
33struct hda_jack_tbl *
34snd_hda_jack_tbl_get_from_tag(struct hda_codec *codec, unsigned char tag);
35
36struct hda_jack_tbl *
37snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid);
38void snd_hda_jack_tbl_clear(struct hda_codec *codec);
39
40/**
41 * snd_hda_jack_get_action - get jack-tbl entry for the tag
42 *
43 * Call this from the unsol event handler to get the assigned action for the
44 * event. This will mark the dirty flag for the later reporting, too.
45 */
46static inline unsigned char
47snd_hda_jack_get_action(struct hda_codec *codec, unsigned int tag)
48{
49 struct hda_jack_tbl *jack = snd_hda_jack_tbl_get_from_tag(codec, tag);
50 if (jack) {
51 jack->jack_dirty = 1;
52 return jack->action;
53 }
54 return 0;
55}
56
57void snd_hda_jack_set_dirty_all(struct hda_codec *codec);
58
59int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid,
60 unsigned char action);
61
62u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid);
63int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid);
64
65static inline bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid)
66{
67 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_PRES_DETECT))
68 return false;
69 if (!codec->ignore_misc_bit &&
70 (get_defcfg_misc(snd_hda_codec_get_pincfg(codec, nid)) &
71 AC_DEFCFG_MISC_NO_PRESENCE))
72 return false;
73 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
74 return false;
75 return true;
76}
77
78int snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,
79 const char *name, int idx);
80int snd_hda_jack_add_kctls(struct hda_codec *codec,
81 const struct auto_pin_cfg *cfg);
82
83void snd_hda_jack_report_sync(struct hda_codec *codec);
84
85
86#endif /* __SOUND_HDA_JACK_H */
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index 618ddad17236..e1abc07f7436 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -394,11 +394,12 @@ struct auto_pin_cfg_item {
394}; 394};
395 395
396struct auto_pin_cfg; 396struct auto_pin_cfg;
397const char *hda_get_input_pin_label(struct hda_codec *codec, hda_nid_t pin,
398 int check_location);
399const char *hda_get_autocfg_input_label(struct hda_codec *codec, 397const char *hda_get_autocfg_input_label(struct hda_codec *codec,
400 const struct auto_pin_cfg *cfg, 398 const struct auto_pin_cfg *cfg,
401 int input); 399 int input);
400int snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid,
401 const struct auto_pin_cfg *cfg,
402 char *label, int maxlen, int *indexp);
402int snd_hda_add_imux_item(struct hda_input_mux *imux, const char *label, 403int snd_hda_add_imux_item(struct hda_input_mux *imux, const char *label,
403 int index, int *type_index_ret); 404 int index, int *type_index_ret);
404 405
@@ -505,21 +506,6 @@ int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
505u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid); 506u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid);
506int snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid, 507int snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid,
507 unsigned int caps); 508 unsigned int caps);
508u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid);
509int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid);
510
511static inline bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid)
512{
513 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_PRES_DETECT))
514 return false;
515 if (!codec->ignore_misc_bit &&
516 (get_defcfg_misc(snd_hda_codec_get_pincfg(codec, nid)) &
517 AC_DEFCFG_MISC_NO_PRESENCE))
518 return false;
519 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
520 return false;
521 return true;
522}
523 509
524/* flags for hda_nid_item */ 510/* flags for hda_nid_item */
525#define HDA_NID_ITEM_AMP (1<<0) 511#define HDA_NID_ITEM_AMP (1<<0)
@@ -688,28 +674,4 @@ static inline void snd_hda_eld_proc_free(struct hda_codec *codec,
688#define SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE 80 674#define SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE 80
689void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen); 675void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen);
690 676
691/*
692 * Input-jack notification support
693 */
694#ifdef CONFIG_SND_HDA_INPUT_JACK
695int snd_hda_input_jack_add(struct hda_codec *codec, hda_nid_t nid, int type,
696 const char *name);
697void snd_hda_input_jack_report(struct hda_codec *codec, hda_nid_t nid);
698void snd_hda_input_jack_free(struct hda_codec *codec);
699#else /* CONFIG_SND_HDA_INPUT_JACK */
700static inline int snd_hda_input_jack_add(struct hda_codec *codec,
701 hda_nid_t nid, int type,
702 const char *name)
703{
704 return 0;
705}
706static inline void snd_hda_input_jack_report(struct hda_codec *codec,
707 hda_nid_t nid)
708{
709}
710static inline void snd_hda_input_jack_free(struct hda_codec *codec)
711{
712}
713#endif /* CONFIG_SND_HDA_INPUT_JACK */
714
715#endif /* __SOUND_HDA_LOCAL_H */ 677#endif /* __SOUND_HDA_LOCAL_H */
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index bcb3310c394f..9cb14b42dfff 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -29,6 +29,7 @@
29#include "hda_codec.h" 29#include "hda_codec.h"
30#include "hda_local.h" 30#include "hda_local.h"
31#include "hda_beep.h" 31#include "hda_beep.h"
32#include "hda_jack.h"
32 33
33struct ad198x_spec { 34struct ad198x_spec {
34 const struct snd_kcontrol_new *mixers[6]; 35 const struct snd_kcontrol_new *mixers[6];
diff --git a/sound/pci/hda/patch_ca0110.c b/sound/pci/hda/patch_ca0110.c
index 993757b65736..09ccfabb4a17 100644
--- a/sound/pci/hda/patch_ca0110.c
+++ b/sound/pci/hda/patch_ca0110.c
@@ -41,7 +41,7 @@ struct ca0110_spec {
41 hda_nid_t dig_out; 41 hda_nid_t dig_out;
42 hda_nid_t dig_in; 42 hda_nid_t dig_in;
43 unsigned int num_inputs; 43 unsigned int num_inputs;
44 const char *input_labels[AUTO_PIN_LAST]; 44 char input_labels[AUTO_PIN_LAST][32];
45 struct hda_pcm pcm_rec[2]; /* PCM information */ 45 struct hda_pcm pcm_rec[2]; /* PCM information */
46}; 46};
47 47
@@ -476,7 +476,9 @@ static void parse_input(struct hda_codec *codec)
476 if (j >= cfg->num_inputs) 476 if (j >= cfg->num_inputs)
477 continue; 477 continue;
478 spec->input_pins[n] = pin; 478 spec->input_pins[n] = pin;
479 spec->input_labels[n] = hda_get_input_pin_label(codec, pin, 1); 479 snd_hda_get_pin_label(codec, pin, cfg,
480 spec->input_labels[n],
481 sizeof(spec->input_labels[n]), NULL);
480 spec->adcs[n] = nid; 482 spec->adcs[n] = nid;
481 n++; 483 n++;
482 } 484 }
diff --git a/sound/pci/hda/patch_cirrus.c b/sound/pci/hda/patch_cirrus.c
index 70a7abda7e22..acfb64534bf0 100644
--- a/sound/pci/hda/patch_cirrus.c
+++ b/sound/pci/hda/patch_cirrus.c
@@ -26,6 +26,7 @@
26#include <sound/core.h> 26#include <sound/core.h>
27#include "hda_codec.h" 27#include "hda_codec.h"
28#include "hda_local.h" 28#include "hda_local.h"
29#include "hda_jack.h"
29#include <sound/tlv.h> 30#include <sound/tlv.h>
30 31
31/* 32/*
@@ -721,8 +722,9 @@ static int cs_capture_source_info(struct snd_kcontrol *kcontrol,
721 if (uinfo->value.enumerated.item >= spec->num_inputs) 722 if (uinfo->value.enumerated.item >= spec->num_inputs)
722 uinfo->value.enumerated.item = spec->num_inputs - 1; 723 uinfo->value.enumerated.item = spec->num_inputs - 1;
723 idx = spec->input_idx[uinfo->value.enumerated.item]; 724 idx = spec->input_idx[uinfo->value.enumerated.item];
724 strcpy(uinfo->value.enumerated.name, 725 snd_hda_get_pin_label(codec, cfg->inputs[idx].pin, cfg,
725 hda_get_input_pin_label(codec, cfg->inputs[idx].pin, 1)); 726 uinfo->value.enumerated.name,
727 sizeof(uinfo->value.enumerated.name), NULL);
726 return 0; 728 return 0;
727} 729}
728 730
@@ -1027,9 +1029,7 @@ static void init_output(struct hda_codec *codec)
1027 if (!cfg->speaker_outs) 1029 if (!cfg->speaker_outs)
1028 continue; 1030 continue;
1029 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) { 1031 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) {
1030 snd_hda_codec_write(codec, nid, 0, 1032 snd_hda_jack_detect_enable(codec, nid, HP_EVENT);
1031 AC_VERB_SET_UNSOLICITED_ENABLE,
1032 AC_USRSP_EN | HP_EVENT);
1033 spec->hp_detect = 1; 1033 spec->hp_detect = 1;
1034 } 1034 }
1035 } 1035 }
@@ -1070,9 +1070,7 @@ static void init_input(struct hda_codec *codec)
1070 AC_VERB_SET_AMP_GAIN_MUTE, 1070 AC_VERB_SET_AMP_GAIN_MUTE,
1071 AMP_IN_MUTE(spec->adc_idx[i])); 1071 AMP_IN_MUTE(spec->adc_idx[i]));
1072 if (spec->mic_detect && spec->automic_idx == i) 1072 if (spec->mic_detect && spec->automic_idx == i)
1073 snd_hda_codec_write(codec, pin, 0, 1073 snd_hda_jack_detect_enable(codec, pin, MIC_EVENT);
1074 AC_VERB_SET_UNSOLICITED_ENABLE,
1075 AC_USRSP_EN | MIC_EVENT);
1076 } 1074 }
1077 /* specific to CS421x */ 1075 /* specific to CS421x */
1078 if (spec->vendor_nid == CS421X_VENDOR_NID) { 1076 if (spec->vendor_nid == CS421X_VENDOR_NID) {
@@ -1200,11 +1198,14 @@ static int cs_init(struct hda_codec *codec)
1200 init_output(codec); 1198 init_output(codec);
1201 init_input(codec); 1199 init_input(codec);
1202 init_digital(codec); 1200 init_digital(codec);
1201 snd_hda_jack_report_sync(codec);
1202
1203 return 0; 1203 return 0;
1204} 1204}
1205 1205
1206static int cs_build_controls(struct hda_codec *codec) 1206static int cs_build_controls(struct hda_codec *codec)
1207{ 1207{
1208 struct cs_spec *spec = codec->spec;
1208 int err; 1209 int err;
1209 1210
1210 err = build_output(codec); 1211 err = build_output(codec);
@@ -1219,7 +1220,15 @@ static int cs_build_controls(struct hda_codec *codec)
1219 err = build_digital_input(codec); 1220 err = build_digital_input(codec);
1220 if (err < 0) 1221 if (err < 0)
1221 return err; 1222 return err;
1222 return cs_init(codec); 1223 err = cs_init(codec);
1224 if (err < 0)
1225 return err;
1226
1227 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
1228 if (err < 0)
1229 return err;
1230
1231 return 0;
1223} 1232}
1224 1233
1225static void cs_free(struct hda_codec *codec) 1234static void cs_free(struct hda_codec *codec)
@@ -1232,7 +1241,7 @@ static void cs_free(struct hda_codec *codec)
1232 1241
1233static void cs_unsol_event(struct hda_codec *codec, unsigned int res) 1242static void cs_unsol_event(struct hda_codec *codec, unsigned int res)
1234{ 1243{
1235 switch ((res >> 26) & 0x7f) { 1244 switch (snd_hda_jack_get_action(codec, res >> 26)) {
1236 case HP_EVENT: 1245 case HP_EVENT:
1237 cs_automute(codec); 1246 cs_automute(codec);
1238 break; 1247 break;
@@ -1240,6 +1249,7 @@ static void cs_unsol_event(struct hda_codec *codec, unsigned int res)
1240 cs_automic(codec); 1249 cs_automic(codec);
1241 break; 1250 break;
1242 } 1251 }
1252 snd_hda_jack_report_sync(codec);
1243} 1253}
1244 1254
1245static const struct hda_codec_ops cs_patch_ops = { 1255static const struct hda_codec_ops cs_patch_ops = {
@@ -1602,10 +1612,7 @@ static void init_cs421x_digital(struct hda_codec *codec)
1602 if (!cfg->speaker_outs) 1612 if (!cfg->speaker_outs)
1603 continue; 1613 continue;
1604 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) { 1614 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) {
1605 1615 snd_hda_jack_detect_enable(codec, nid, SPDIF_EVENT);
1606 snd_hda_codec_write(codec, nid, 0,
1607 AC_VERB_SET_UNSOLICITED_ENABLE,
1608 AC_USRSP_EN | SPDIF_EVENT);
1609 spec->spdif_detect = 1; 1616 spec->spdif_detect = 1;
1610 } 1617 }
1611 } 1618 }
@@ -1632,6 +1639,7 @@ static int cs421x_init(struct hda_codec *codec)
1632 init_output(codec); 1639 init_output(codec);
1633 init_input(codec); 1640 init_input(codec);
1634 init_cs421x_digital(codec); 1641 init_cs421x_digital(codec);
1642 snd_hda_jack_report_sync(codec);
1635 1643
1636 return 0; 1644 return 0;
1637} 1645}
@@ -1807,6 +1815,7 @@ static int build_cs421x_output(struct hda_codec *codec)
1807 1815
1808static int cs421x_build_controls(struct hda_codec *codec) 1816static int cs421x_build_controls(struct hda_codec *codec)
1809{ 1817{
1818 struct cs_spec *spec = codec->spec;
1810 int err; 1819 int err;
1811 1820
1812 err = build_cs421x_output(codec); 1821 err = build_cs421x_output(codec);
@@ -1818,12 +1827,20 @@ static int cs421x_build_controls(struct hda_codec *codec)
1818 err = build_digital_output(codec); 1827 err = build_digital_output(codec);
1819 if (err < 0) 1828 if (err < 0)
1820 return err; 1829 return err;
1821 return cs421x_init(codec); 1830 err = cs421x_init(codec);
1831 if (err < 0)
1832 return err;
1833
1834 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
1835 if (err < 0)
1836 return err;
1837
1838 return 0;
1822} 1839}
1823 1840
1824static void cs421x_unsol_event(struct hda_codec *codec, unsigned int res) 1841static void cs421x_unsol_event(struct hda_codec *codec, unsigned int res)
1825{ 1842{
1826 switch ((res >> 26) & 0x3f) { 1843 switch (snd_hda_jack_get_action(codec, res >> 26)) {
1827 case HP_EVENT: 1844 case HP_EVENT:
1828 case SPDIF_EVENT: 1845 case SPDIF_EVENT:
1829 cs_automute(codec); 1846 cs_automute(codec);
@@ -1833,6 +1850,7 @@ static void cs421x_unsol_event(struct hda_codec *codec, unsigned int res)
1833 cs_automic(codec); 1850 cs_automic(codec);
1834 break; 1851 break;
1835 } 1852 }
1853 snd_hda_jack_report_sync(codec);
1836} 1854}
1837 1855
1838static int parse_cs421x_input(struct hda_codec *codec) 1856static int parse_cs421x_input(struct hda_codec *codec)
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index 0de21193a2b0..bf14a0a0ce1c 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -31,6 +31,7 @@
31#include "hda_codec.h" 31#include "hda_codec.h"
32#include "hda_local.h" 32#include "hda_local.h"
33#include "hda_beep.h" 33#include "hda_beep.h"
34#include "hda_jack.h"
34 35
35#define CXT_PIN_DIR_IN 0x00 36#define CXT_PIN_DIR_IN 0x00
36#define CXT_PIN_DIR_OUT 0x01 37#define CXT_PIN_DIR_OUT 0x01
@@ -415,40 +416,6 @@ static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
415 &spec->cur_mux[adc_idx]); 416 &spec->cur_mux[adc_idx]);
416} 417}
417 418
418static int conexant_init_jacks(struct hda_codec *codec)
419{
420#ifdef CONFIG_SND_HDA_INPUT_JACK
421 struct conexant_spec *spec = codec->spec;
422 int i;
423
424 for (i = 0; i < spec->num_init_verbs; i++) {
425 const struct hda_verb *hv;
426
427 hv = spec->init_verbs[i];
428 while (hv->nid) {
429 int err = 0;
430 switch (hv->param ^ AC_USRSP_EN) {
431 case CONEXANT_HP_EVENT:
432 err = snd_hda_input_jack_add(codec, hv->nid,
433 SND_JACK_HEADPHONE, NULL);
434 snd_hda_input_jack_report(codec, hv->nid);
435 break;
436 case CXT5051_PORTC_EVENT:
437 case CONEXANT_MIC_EVENT:
438 err = snd_hda_input_jack_add(codec, hv->nid,
439 SND_JACK_MICROPHONE, NULL);
440 snd_hda_input_jack_report(codec, hv->nid);
441 break;
442 }
443 if (err < 0)
444 return err;
445 ++hv;
446 }
447 }
448#endif /* CONFIG_SND_HDA_INPUT_JACK */
449 return 0;
450}
451
452static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg, 419static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
453 unsigned int power_state) 420 unsigned int power_state)
454{ 421{
@@ -474,7 +441,6 @@ static int conexant_init(struct hda_codec *codec)
474 441
475static void conexant_free(struct hda_codec *codec) 442static void conexant_free(struct hda_codec *codec)
476{ 443{
477 snd_hda_input_jack_free(codec);
478 snd_hda_detach_beep_device(codec); 444 snd_hda_detach_beep_device(codec);
479 kfree(codec->spec); 445 kfree(codec->spec);
480} 446}
@@ -1750,7 +1716,6 @@ static void cxt5051_hp_automute(struct hda_codec *codec)
1750static void cxt5051_hp_unsol_event(struct hda_codec *codec, 1716static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1751 unsigned int res) 1717 unsigned int res)
1752{ 1718{
1753 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1754 switch (res >> 26) { 1719 switch (res >> 26) {
1755 case CONEXANT_HP_EVENT: 1720 case CONEXANT_HP_EVENT:
1756 cxt5051_hp_automute(codec); 1721 cxt5051_hp_automute(codec);
@@ -1762,7 +1727,6 @@ static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1762 cxt5051_portc_automic(codec); 1727 cxt5051_portc_automic(codec);
1763 break; 1728 break;
1764 } 1729 }
1765 snd_hda_input_jack_report(codec, nid);
1766} 1730}
1767 1731
1768static const struct snd_kcontrol_new cxt5051_playback_mixers[] = { 1732static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
@@ -1901,8 +1865,6 @@ static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
1901 snd_hda_codec_write(codec, nid, 0, 1865 snd_hda_codec_write(codec, nid, 0,
1902 AC_VERB_SET_UNSOLICITED_ENABLE, 1866 AC_VERB_SET_UNSOLICITED_ENABLE,
1903 AC_USRSP_EN | event); 1867 AC_USRSP_EN | event);
1904 snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
1905 snd_hda_input_jack_report(codec, nid);
1906} 1868}
1907 1869
1908static const struct hda_verb cxt5051_ideapad_init_verbs[] = { 1870static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
@@ -1918,7 +1880,6 @@ static int cxt5051_init(struct hda_codec *codec)
1918 struct conexant_spec *spec = codec->spec; 1880 struct conexant_spec *spec = codec->spec;
1919 1881
1920 conexant_init(codec); 1882 conexant_init(codec);
1921 conexant_init_jacks(codec);
1922 1883
1923 if (spec->auto_mic & AUTO_MIC_PORTB) 1884 if (spec->auto_mic & AUTO_MIC_PORTB)
1924 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT); 1885 cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
@@ -3450,7 +3411,6 @@ static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
3450 hda_nid_t nid = pins[i]; 3411 hda_nid_t nid = pins[i];
3451 if (!nid || !is_jack_detectable(codec, nid)) 3412 if (!nid || !is_jack_detectable(codec, nid))
3452 break; 3413 break;
3453 snd_hda_input_jack_report(codec, nid);
3454 present |= snd_hda_jack_detect(codec, nid); 3414 present |= snd_hda_jack_detect(codec, nid);
3455 } 3415 }
3456 return present; 3416 return present;
@@ -3755,8 +3715,7 @@ static void cx_auto_automic(struct hda_codec *codec)
3755 3715
3756static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res) 3716static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3757{ 3717{
3758 int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20; 3718 switch (snd_hda_jack_get_action(codec, res >> 26)) {
3759 switch (res >> 26) {
3760 case CONEXANT_HP_EVENT: 3719 case CONEXANT_HP_EVENT:
3761 cx_auto_hp_automute(codec); 3720 cx_auto_hp_automute(codec);
3762 break; 3721 break;
@@ -3765,9 +3724,9 @@ static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3765 break; 3724 break;
3766 case CONEXANT_MIC_EVENT: 3725 case CONEXANT_MIC_EVENT:
3767 cx_auto_automic(codec); 3726 cx_auto_automic(codec);
3768 snd_hda_input_jack_report(codec, nid);
3769 break; 3727 break;
3770 } 3728 }
3729 snd_hda_jack_report_sync(codec);
3771} 3730}
3772 3731
3773/* check whether the pin config is suitable for auto-mic switching; 3732/* check whether the pin config is suitable for auto-mic switching;
@@ -3979,13 +3938,11 @@ static void mute_outputs(struct hda_codec *codec, int num_nids,
3979} 3938}
3980 3939
3981static void enable_unsol_pins(struct hda_codec *codec, int num_pins, 3940static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
3982 hda_nid_t *pins, unsigned int tag) 3941 hda_nid_t *pins, unsigned int action)
3983{ 3942{
3984 int i; 3943 int i;
3985 for (i = 0; i < num_pins; i++) 3944 for (i = 0; i < num_pins; i++)
3986 snd_hda_codec_write(codec, pins[i], 0, 3945 snd_hda_jack_detect_enable(codec, pins[i], action);
3987 AC_VERB_SET_UNSOLICITED_ENABLE,
3988 AC_USRSP_EN | tag);
3989} 3946}
3990 3947
3991static void cx_auto_init_output(struct hda_codec *codec) 3948static void cx_auto_init_output(struct hda_codec *codec)
@@ -4060,16 +4017,14 @@ static void cx_auto_init_input(struct hda_codec *codec)
4060 4017
4061 if (spec->auto_mic) { 4018 if (spec->auto_mic) {
4062 if (spec->auto_mic_ext >= 0) { 4019 if (spec->auto_mic_ext >= 0) {
4063 snd_hda_codec_write(codec, 4020 snd_hda_jack_detect_enable(codec,
4064 cfg->inputs[spec->auto_mic_ext].pin, 0, 4021 cfg->inputs[spec->auto_mic_ext].pin,
4065 AC_VERB_SET_UNSOLICITED_ENABLE, 4022 CONEXANT_MIC_EVENT);
4066 AC_USRSP_EN | CONEXANT_MIC_EVENT);
4067 } 4023 }
4068 if (spec->auto_mic_dock >= 0) { 4024 if (spec->auto_mic_dock >= 0) {
4069 snd_hda_codec_write(codec, 4025 snd_hda_jack_detect_enable(codec,
4070 cfg->inputs[spec->auto_mic_dock].pin, 0, 4026 cfg->inputs[spec->auto_mic_dock].pin,
4071 AC_VERB_SET_UNSOLICITED_ENABLE, 4027 CONEXANT_MIC_EVENT);
4072 AC_USRSP_EN | CONEXANT_MIC_EVENT);
4073 } 4028 }
4074 cx_auto_automic(codec); 4029 cx_auto_automic(codec);
4075 } else { 4030 } else {
@@ -4097,6 +4052,7 @@ static int cx_auto_init(struct hda_codec *codec)
4097 cx_auto_init_output(codec); 4052 cx_auto_init_output(codec);
4098 cx_auto_init_input(codec); 4053 cx_auto_init_input(codec);
4099 cx_auto_init_digital(codec); 4054 cx_auto_init_digital(codec);
4055 snd_hda_jack_report_sync(codec);
4100 return 0; 4056 return 0;
4101} 4057}
4102 4058
@@ -4326,6 +4282,7 @@ static int cx_auto_build_input_controls(struct hda_codec *codec)
4326 4282
4327static int cx_auto_build_controls(struct hda_codec *codec) 4283static int cx_auto_build_controls(struct hda_codec *codec)
4328{ 4284{
4285 struct conexant_spec *spec = codec->spec;
4329 int err; 4286 int err;
4330 4287
4331 err = cx_auto_build_output_controls(codec); 4288 err = cx_auto_build_output_controls(codec);
@@ -4334,7 +4291,13 @@ static int cx_auto_build_controls(struct hda_codec *codec)
4334 err = cx_auto_build_input_controls(codec); 4291 err = cx_auto_build_input_controls(codec);
4335 if (err < 0) 4292 if (err < 0)
4336 return err; 4293 return err;
4337 return conexant_build_controls(codec); 4294 err = conexant_build_controls(codec);
4295 if (err < 0)
4296 return err;
4297 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
4298 if (err < 0)
4299 return err;
4300 return 0;
4338} 4301}
4339 4302
4340static int cx_auto_search_adcs(struct hda_codec *codec) 4303static int cx_auto_search_adcs(struct hda_codec *codec)
diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
index 6e0756febb2e..3f42cc965b46 100644
--- a/sound/pci/hda/patch_hdmi.c
+++ b/sound/pci/hda/patch_hdmi.c
@@ -36,6 +36,7 @@
36#include <sound/jack.h> 36#include <sound/jack.h>
37#include "hda_codec.h" 37#include "hda_codec.h"
38#include "hda_local.h" 38#include "hda_local.h"
39#include "hda_jack.h"
39 40
40static bool static_hdmi_pcm; 41static bool static_hdmi_pcm;
41module_param(static_hdmi_pcm, bool, 0644); 42module_param(static_hdmi_pcm, bool, 0644);
@@ -754,10 +755,18 @@ static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll);
754static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res) 755static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
755{ 756{
756 struct hdmi_spec *spec = codec->spec; 757 struct hdmi_spec *spec = codec->spec;
757 int pin_nid = res >> AC_UNSOL_RES_TAG_SHIFT; 758 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
759 int pin_nid;
758 int pd = !!(res & AC_UNSOL_RES_PD); 760 int pd = !!(res & AC_UNSOL_RES_PD);
759 int eldv = !!(res & AC_UNSOL_RES_ELDV); 761 int eldv = !!(res & AC_UNSOL_RES_ELDV);
760 int pin_idx; 762 int pin_idx;
763 struct hda_jack_tbl *jack;
764
765 jack = snd_hda_jack_tbl_get_from_tag(codec, tag);
766 if (!jack)
767 return;
768 pin_nid = jack->nid;
769 jack->jack_dirty = 1;
761 770
762 printk(KERN_INFO 771 printk(KERN_INFO
763 "HDMI hot plug event: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n", 772 "HDMI hot plug event: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
@@ -768,6 +777,7 @@ static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
768 return; 777 return;
769 778
770 hdmi_present_sense(&spec->pins[pin_idx], 1); 779 hdmi_present_sense(&spec->pins[pin_idx], 1);
780 snd_hda_jack_report_sync(codec);
771} 781}
772 782
773static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res) 783static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
@@ -799,7 +809,7 @@ static void hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
799 int tag = res >> AC_UNSOL_RES_TAG_SHIFT; 809 int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
800 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT; 810 int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
801 811
802 if (pin_nid_to_pin_index(spec, tag) < 0) { 812 if (!snd_hda_jack_tbl_get_from_tag(codec, tag)) {
803 snd_printd(KERN_INFO "Unexpected HDMI event tag 0x%x\n", tag); 813 snd_printd(KERN_INFO "Unexpected HDMI event tag 0x%x\n", tag);
804 return; 814 return;
805 } 815 }
@@ -996,8 +1006,6 @@ static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
996 msecs_to_jiffies(300)); 1006 msecs_to_jiffies(300));
997 } 1007 }
998 } 1008 }
999
1000 snd_hda_input_jack_report(codec, pin_nid);
1001} 1009}
1002 1010
1003static void hdmi_repoll_eld(struct work_struct *work) 1011static void hdmi_repoll_eld(struct work_struct *work)
@@ -1226,21 +1234,16 @@ static int generic_hdmi_build_pcms(struct hda_codec *codec)
1226 1234
1227static int generic_hdmi_build_jack(struct hda_codec *codec, int pin_idx) 1235static int generic_hdmi_build_jack(struct hda_codec *codec, int pin_idx)
1228{ 1236{
1229 int err; 1237 char hdmi_str[32] = "HDMI/DP";
1230 char hdmi_str[32];
1231 struct hdmi_spec *spec = codec->spec; 1238 struct hdmi_spec *spec = codec->spec;
1232 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx]; 1239 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
1233 int pcmdev = spec->pcm_rec[pin_idx].device; 1240 int pcmdev = spec->pcm_rec[pin_idx].device;
1234 1241
1235 snprintf(hdmi_str, sizeof(hdmi_str), "HDMI/DP,pcm=%d", pcmdev); 1242 if (pcmdev > 0)
1236 1243 sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev);
1237 err = snd_hda_input_jack_add(codec, per_pin->pin_nid,
1238 SND_JACK_VIDEOOUT, pcmdev > 0 ? hdmi_str : NULL);
1239 if (err < 0)
1240 return err;
1241 1244
1242 hdmi_present_sense(per_pin, 0); 1245 hdmi_present_sense(per_pin, 0);
1243 return 0; 1246 return snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str, 0);
1244} 1247}
1245 1248
1246static int generic_hdmi_build_controls(struct hda_codec *codec) 1249static int generic_hdmi_build_controls(struct hda_codec *codec)
@@ -1270,6 +1273,8 @@ static int generic_hdmi_build_controls(struct hda_codec *codec)
1270 1273
1271 if (err < 0) 1274 if (err < 0)
1272 return err; 1275 return err;
1276
1277 hdmi_present_sense(per_pin, false);
1273 } 1278 }
1274 1279
1275 return 0; 1280 return 0;
@@ -1286,14 +1291,13 @@ static int generic_hdmi_init(struct hda_codec *codec)
1286 struct hdmi_eld *eld = &per_pin->sink_eld; 1291 struct hdmi_eld *eld = &per_pin->sink_eld;
1287 1292
1288 hdmi_init_pin(codec, pin_nid); 1293 hdmi_init_pin(codec, pin_nid);
1289 snd_hda_codec_write(codec, pin_nid, 0, 1294 snd_hda_jack_detect_enable(codec, pin_nid, pin_nid);
1290 AC_VERB_SET_UNSOLICITED_ENABLE,
1291 AC_USRSP_EN | pin_nid);
1292 1295
1293 per_pin->codec = codec; 1296 per_pin->codec = codec;
1294 INIT_DELAYED_WORK(&per_pin->work, hdmi_repoll_eld); 1297 INIT_DELAYED_WORK(&per_pin->work, hdmi_repoll_eld);
1295 snd_hda_eld_proc_new(codec, eld, pin_idx); 1298 snd_hda_eld_proc_new(codec, eld, pin_idx);
1296 } 1299 }
1300 snd_hda_jack_report_sync(codec);
1297 return 0; 1301 return 0;
1298} 1302}
1299 1303
@@ -1309,7 +1313,6 @@ static void generic_hdmi_free(struct hda_codec *codec)
1309 cancel_delayed_work(&per_pin->work); 1313 cancel_delayed_work(&per_pin->work);
1310 snd_hda_eld_proc_free(codec, eld); 1314 snd_hda_eld_proc_free(codec, eld);
1311 } 1315 }
1312 snd_hda_input_jack_free(codec);
1313 1316
1314 flush_workqueue(codec->bus->workq); 1317 flush_workqueue(codec->bus->workq);
1315 kfree(spec); 1318 kfree(spec);
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 690f2a2a4595..d24adbd023ee 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -33,6 +33,7 @@
33#include "hda_codec.h" 33#include "hda_codec.h"
34#include "hda_local.h" 34#include "hda_local.h"
35#include "hda_beep.h" 35#include "hda_beep.h"
36#include "hda_jack.h"
36 37
37/* unsol event tags */ 38/* unsol event tags */
38#define ALC_FRONT_EVENT 0x01 39#define ALC_FRONT_EVENT 0x01
@@ -184,6 +185,7 @@ struct alc_spec {
184 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */ 185 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
185 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */ 186 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
186 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */ 187 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
188 unsigned int use_jack_tbl:1; /* 1 for model=auto */
187 189
188 /* auto-mute control */ 190 /* auto-mute control */
189 int automute_mode; 191 int automute_mode;
@@ -466,46 +468,6 @@ static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
466} 468}
467 469
468/* 470/*
469 * Jack-reporting via input-jack layer
470 */
471
472/* initialization of jacks; currently checks only a few known pins */
473static int alc_init_jacks(struct hda_codec *codec)
474{
475#ifdef CONFIG_SND_HDA_INPUT_JACK
476 struct alc_spec *spec = codec->spec;
477 int err;
478 unsigned int hp_nid = spec->autocfg.hp_pins[0];
479 unsigned int mic_nid = spec->ext_mic_pin;
480 unsigned int dock_nid = spec->dock_mic_pin;
481
482 if (hp_nid) {
483 err = snd_hda_input_jack_add(codec, hp_nid,
484 SND_JACK_HEADPHONE, NULL);
485 if (err < 0)
486 return err;
487 snd_hda_input_jack_report(codec, hp_nid);
488 }
489
490 if (mic_nid) {
491 err = snd_hda_input_jack_add(codec, mic_nid,
492 SND_JACK_MICROPHONE, NULL);
493 if (err < 0)
494 return err;
495 snd_hda_input_jack_report(codec, mic_nid);
496 }
497 if (dock_nid) {
498 err = snd_hda_input_jack_add(codec, dock_nid,
499 SND_JACK_MICROPHONE, NULL);
500 if (err < 0)
501 return err;
502 snd_hda_input_jack_report(codec, dock_nid);
503 }
504#endif /* CONFIG_SND_HDA_INPUT_JACK */
505 return 0;
506}
507
508/*
509 * Jack detections for HP auto-mute and mic-switch 471 * Jack detections for HP auto-mute and mic-switch
510 */ 472 */
511 473
@@ -518,7 +480,6 @@ static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
518 hda_nid_t nid = pins[i]; 480 hda_nid_t nid = pins[i];
519 if (!nid) 481 if (!nid)
520 break; 482 break;
521 snd_hda_input_jack_report(codec, nid);
522 present |= snd_hda_jack_detect(codec, nid); 483 present |= snd_hda_jack_detect(codec, nid);
523 } 484 }
524 return present; 485 return present;
@@ -658,19 +619,18 @@ static void alc_mic_automute(struct hda_codec *codec)
658 alc_mux_select(codec, 0, spec->dock_mic_idx, false); 619 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
659 else 620 else
660 alc_mux_select(codec, 0, spec->int_mic_idx, false); 621 alc_mux_select(codec, 0, spec->int_mic_idx, false);
661
662 snd_hda_input_jack_report(codec, pins[spec->ext_mic_idx]);
663 if (spec->dock_mic_idx >= 0)
664 snd_hda_input_jack_report(codec, pins[spec->dock_mic_idx]);
665} 622}
666 623
667/* unsolicited event for HP jack sensing */ 624/* unsolicited event for HP jack sensing */
668static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res) 625static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
669{ 626{
627 struct alc_spec *spec = codec->spec;
670 if (codec->vendor_id == 0x10ec0880) 628 if (codec->vendor_id == 0x10ec0880)
671 res >>= 28; 629 res >>= 28;
672 else 630 else
673 res >>= 26; 631 res >>= 26;
632 if (spec->use_jack_tbl)
633 res = snd_hda_jack_get_action(codec, res);
674 switch (res) { 634 switch (res) {
675 case ALC_HP_EVENT: 635 case ALC_HP_EVENT:
676 alc_hp_automute(codec); 636 alc_hp_automute(codec);
@@ -682,6 +642,7 @@ static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
682 alc_mic_automute(codec); 642 alc_mic_automute(codec);
683 break; 643 break;
684 } 644 }
645 snd_hda_jack_report_sync(codec);
685} 646}
686 647
687/* call init functions of standard auto-mute helpers */ 648/* call init functions of standard auto-mute helpers */
@@ -971,9 +932,7 @@ static void alc_init_automute(struct hda_codec *codec)
971 continue; 932 continue;
972 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n", 933 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
973 nid); 934 nid);
974 snd_hda_codec_write_cache(codec, nid, 0, 935 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
975 AC_VERB_SET_UNSOLICITED_ENABLE,
976 AC_USRSP_EN | ALC_HP_EVENT);
977 spec->detect_hp = 1; 936 spec->detect_hp = 1;
978 } 937 }
979 938
@@ -985,9 +944,8 @@ static void alc_init_automute(struct hda_codec *codec)
985 continue; 944 continue;
986 snd_printdd("realtek: Enable Line-Out " 945 snd_printdd("realtek: Enable Line-Out "
987 "auto-muting on NID 0x%x\n", nid); 946 "auto-muting on NID 0x%x\n", nid);
988 snd_hda_codec_write_cache(codec, nid, 0, 947 snd_hda_jack_detect_enable(codec, nid,
989 AC_VERB_SET_UNSOLICITED_ENABLE, 948 ALC_FRONT_EVENT);
990 AC_USRSP_EN | ALC_FRONT_EVENT);
991 spec->detect_lo = 1; 949 spec->detect_lo = 1;
992 } 950 }
993 spec->automute_lo_possible = spec->detect_hp; 951 spec->automute_lo_possible = spec->detect_hp;
@@ -1126,13 +1084,10 @@ static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1126 return false; /* no corresponding imux */ 1084 return false; /* no corresponding imux */
1127 } 1085 }
1128 1086
1129 snd_hda_codec_write_cache(codec, spec->ext_mic_pin, 0, 1087 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
1130 AC_VERB_SET_UNSOLICITED_ENABLE,
1131 AC_USRSP_EN | ALC_MIC_EVENT);
1132 if (spec->dock_mic_pin) 1088 if (spec->dock_mic_pin)
1133 snd_hda_codec_write_cache(codec, spec->dock_mic_pin, 0, 1089 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1134 AC_VERB_SET_UNSOLICITED_ENABLE, 1090 ALC_MIC_EVENT);
1135 AC_USRSP_EN | ALC_MIC_EVENT);
1136 1091
1137 spec->auto_mic_valid_imux = 1; 1092 spec->auto_mic_valid_imux = 1;
1138 spec->auto_mic = 1; 1093 spec->auto_mic = 1;
@@ -2074,6 +2029,10 @@ static int alc_build_controls(struct hda_codec *codec)
2074 2029
2075 alc_free_kctls(codec); /* no longer needed */ 2030 alc_free_kctls(codec); /* no longer needed */
2076 2031
2032 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
2033 if (err < 0)
2034 return err;
2035
2077 return 0; 2036 return 0;
2078} 2037}
2079 2038
@@ -2101,6 +2060,8 @@ static int alc_init(struct hda_codec *codec)
2101 2060
2102 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT); 2061 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2103 2062
2063 snd_hda_jack_report_sync(codec);
2064
2104 hda_call_check_power_status(codec, 0x01); 2065 hda_call_check_power_status(codec, 0x01);
2105 return 0; 2066 return 0;
2106} 2067}
@@ -2484,7 +2445,6 @@ static void alc_free(struct hda_codec *codec)
2484 return; 2445 return;
2485 2446
2486 alc_shutup(codec); 2447 alc_shutup(codec);
2487 snd_hda_input_jack_free(codec);
2488 alc_free_kctls(codec); 2448 alc_free_kctls(codec);
2489 alc_free_bind_ctls(codec); 2449 alc_free_bind_ctls(codec);
2490 kfree(spec); 2450 kfree(spec);
@@ -3944,6 +3904,7 @@ static void set_capture_mixer(struct hda_codec *codec)
3944static void alc_auto_init_std(struct hda_codec *codec) 3904static void alc_auto_init_std(struct hda_codec *codec)
3945{ 3905{
3946 struct alc_spec *spec = codec->spec; 3906 struct alc_spec *spec = codec->spec;
3907 spec->use_jack_tbl = 1;
3947 alc_auto_init_multi_out(codec); 3908 alc_auto_init_multi_out(codec);
3948 alc_auto_init_extra_out(codec); 3909 alc_auto_init_extra_out(codec);
3949 alc_auto_init_analog_input(codec); 3910 alc_auto_init_analog_input(codec);
@@ -4731,7 +4692,6 @@ static int patch_alc882(struct hda_codec *codec)
4731 if (board_config == ALC_MODEL_AUTO) 4692 if (board_config == ALC_MODEL_AUTO)
4732 spec->init_hook = alc_auto_init_std; 4693 spec->init_hook = alc_auto_init_std;
4733 4694
4734 alc_init_jacks(codec);
4735#ifdef CONFIG_SND_HDA_POWER_SAVE 4695#ifdef CONFIG_SND_HDA_POWER_SAVE
4736 if (!spec->loopback.amplist) 4696 if (!spec->loopback.amplist)
4737 spec->loopback.amplist = alc882_loopbacks; 4697 spec->loopback.amplist = alc882_loopbacks;
@@ -4909,7 +4869,6 @@ static int patch_alc262(struct hda_codec *codec)
4909 spec->init_hook = alc_auto_init_std; 4869 spec->init_hook = alc_auto_init_std;
4910 spec->shutup = alc_eapd_shutup; 4870 spec->shutup = alc_eapd_shutup;
4911 4871
4912 alc_init_jacks(codec);
4913#ifdef CONFIG_SND_HDA_POWER_SAVE 4872#ifdef CONFIG_SND_HDA_POWER_SAVE
4914 if (!spec->loopback.amplist) 4873 if (!spec->loopback.amplist)
4915 spec->loopback.amplist = alc262_loopbacks; 4874 spec->loopback.amplist = alc262_loopbacks;
@@ -5020,8 +4979,6 @@ static int patch_alc268(struct hda_codec *codec)
5020 spec->init_hook = alc_auto_init_std; 4979 spec->init_hook = alc_auto_init_std;
5021 spec->shutup = alc_eapd_shutup; 4980 spec->shutup = alc_eapd_shutup;
5022 4981
5023 alc_init_jacks(codec);
5024
5025 return 0; 4982 return 0;
5026 4983
5027 error: 4984 error:
@@ -5577,7 +5534,6 @@ static int patch_alc269(struct hda_codec *codec)
5577 spec->init_hook = alc_auto_init_std; 5534 spec->init_hook = alc_auto_init_std;
5578 spec->shutup = alc269_shutup; 5535 spec->shutup = alc269_shutup;
5579 5536
5580 alc_init_jacks(codec);
5581#ifdef CONFIG_SND_HDA_POWER_SAVE 5537#ifdef CONFIG_SND_HDA_POWER_SAVE
5582 if (!spec->loopback.amplist) 5538 if (!spec->loopback.amplist)
5583 spec->loopback.amplist = alc269_loopbacks; 5539 spec->loopback.amplist = alc269_loopbacks;
@@ -6187,8 +6143,6 @@ static int patch_alc662(struct hda_codec *codec)
6187 spec->init_hook = alc_auto_init_std; 6143 spec->init_hook = alc_auto_init_std;
6188 spec->shutup = alc_eapd_shutup; 6144 spec->shutup = alc_eapd_shutup;
6189 6145
6190 alc_init_jacks(codec);
6191
6192#ifdef CONFIG_SND_HDA_POWER_SAVE 6146#ifdef CONFIG_SND_HDA_POWER_SAVE
6193 if (!spec->loopback.amplist) 6147 if (!spec->loopback.amplist)
6194 spec->loopback.amplist = alc662_loopbacks; 6148 spec->loopback.amplist = alc662_loopbacks;
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index aaed004eacc5..03145aec65f1 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -37,6 +37,7 @@
37#include "hda_codec.h" 37#include "hda_codec.h"
38#include "hda_local.h" 38#include "hda_local.h"
39#include "hda_beep.h" 39#include "hda_beep.h"
40#include "hda_jack.h"
40 41
41enum { 42enum {
42 STAC_VREF_EVENT = 1, 43 STAC_VREF_EVENT = 1,
@@ -175,13 +176,6 @@ enum {
175 STAC_9872_MODELS 176 STAC_9872_MODELS
176}; 177};
177 178
178struct sigmatel_event {
179 hda_nid_t nid;
180 unsigned char type;
181 unsigned char tag;
182 int data;
183};
184
185struct sigmatel_mic_route { 179struct sigmatel_mic_route {
186 hda_nid_t pin; 180 hda_nid_t pin;
187 signed char mux_idx; 181 signed char mux_idx;
@@ -230,9 +224,6 @@ struct sigmatel_spec {
230 const hda_nid_t *pwr_nids; 224 const hda_nid_t *pwr_nids;
231 const hda_nid_t *dac_list; 225 const hda_nid_t *dac_list;
232 226
233 /* events */
234 struct snd_array events;
235
236 /* playback */ 227 /* playback */
237 struct hda_input_mux *mono_mux; 228 struct hda_input_mux *mono_mux;
238 unsigned int cur_mmux; 229 unsigned int cur_mmux;
@@ -1093,13 +1084,10 @@ static const char * const slave_sws[] = {
1093}; 1084};
1094 1085
1095static void stac92xx_free_kctls(struct hda_codec *codec); 1086static void stac92xx_free_kctls(struct hda_codec *codec);
1096static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
1097 1087
1098static int stac92xx_build_controls(struct hda_codec *codec) 1088static int stac92xx_build_controls(struct hda_codec *codec)
1099{ 1089{
1100 struct sigmatel_spec *spec = codec->spec; 1090 struct sigmatel_spec *spec = codec->spec;
1101 struct auto_pin_cfg *cfg = &spec->autocfg;
1102 hda_nid_t nid;
1103 int err; 1091 int err;
1104 int i; 1092 int i;
1105 1093
@@ -1185,31 +1173,9 @@ static int stac92xx_build_controls(struct hda_codec *codec)
1185 1173
1186 stac92xx_free_kctls(codec); /* no longer needed */ 1174 stac92xx_free_kctls(codec); /* no longer needed */
1187 1175
1188 /* create jack input elements */ 1176 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
1189 if (spec->hp_detect) { 1177 if (err < 0)
1190 for (i = 0; i < cfg->hp_outs; i++) { 1178 return err;
1191 int type = SND_JACK_HEADPHONE;
1192 nid = cfg->hp_pins[i];
1193 /* jack detection */
1194 if (cfg->hp_outs == i)
1195 type |= SND_JACK_LINEOUT;
1196 err = stac92xx_add_jack(codec, nid, type);
1197 if (err < 0)
1198 return err;
1199 }
1200 }
1201 for (i = 0; i < cfg->line_outs; i++) {
1202 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1203 SND_JACK_LINEOUT);
1204 if (err < 0)
1205 return err;
1206 }
1207 for (i = 0; i < cfg->num_inputs; i++) {
1208 nid = cfg->inputs[i].pin;
1209 err = stac92xx_add_jack(codec, nid, SND_JACK_MICROPHONE);
1210 if (err < 0)
1211 return err;
1212 }
1213 1179
1214 return 0; 1180 return 0;
1215} 1181}
@@ -2871,7 +2837,8 @@ static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2871 } 2837 }
2872 2838
2873 if (control) { 2839 if (control) {
2874 strcpy(name, hda_get_input_pin_label(codec, nid, 1)); 2840 snd_hda_get_pin_label(codec, nid, &spec->autocfg,
2841 name, sizeof(name), NULL);
2875 return stac92xx_add_control(codec->spec, control, 2842 return stac92xx_add_control(codec->spec, control,
2876 strcat(name, " Jack Mode"), nid); 2843 strcat(name, " Jack Mode"), nid);
2877 } 2844 }
@@ -3549,7 +3516,7 @@ static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3549 for (i = 0; i < spec->num_dmics; i++) { 3516 for (i = 0; i < spec->num_dmics; i++) {
3550 hda_nid_t nid; 3517 hda_nid_t nid;
3551 int index, type_idx; 3518 int index, type_idx;
3552 const char *label; 3519 char label[32];
3553 3520
3554 nid = spec->dmic_nids[i]; 3521 nid = spec->dmic_nids[i];
3555 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN) 3522 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
@@ -3562,7 +3529,8 @@ static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3562 if (index < 0) 3529 if (index < 0)
3563 continue; 3530 continue;
3564 3531
3565 label = hda_get_input_pin_label(codec, nid, 1); 3532 snd_hda_get_pin_label(codec, nid, &spec->autocfg,
3533 label, sizeof(label), NULL);
3566 snd_hda_add_imux_item(dimux, label, index, &type_idx); 3534 snd_hda_add_imux_item(dimux, label, index, &type_idx);
3567 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1) 3535 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1)
3568 snd_hda_add_imux_item(imux, label, index, &type_idx); 3536 snd_hda_add_imux_item(imux, label, index, &type_idx);
@@ -4160,65 +4128,18 @@ static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
4160 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */ 4128 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
4161} 4129}
4162 4130
4163static int stac92xx_add_jack(struct hda_codec *codec, 4131static int stac_add_event(struct hda_codec *codec, hda_nid_t nid,
4164 hda_nid_t nid, int type)
4165{
4166#ifdef CONFIG_SND_HDA_INPUT_JACK
4167 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
4168 int connectivity = get_defcfg_connect(def_conf);
4169
4170 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
4171 return 0;
4172
4173 return snd_hda_input_jack_add(codec, nid, type, NULL);
4174#else
4175 return 0;
4176#endif /* CONFIG_SND_HDA_INPUT_JACK */
4177}
4178
4179static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4180 unsigned char type, int data) 4132 unsigned char type, int data)
4181{ 4133{
4182 struct sigmatel_event *event; 4134 struct hda_jack_tbl *event;
4183 4135
4184 snd_array_init(&spec->events, sizeof(*event), 32); 4136 event = snd_hda_jack_tbl_new(codec, nid);
4185 event = snd_array_new(&spec->events);
4186 if (!event) 4137 if (!event)
4187 return -ENOMEM; 4138 return -ENOMEM;
4188 event->nid = nid; 4139 event->action = type;
4189 event->type = type; 4140 event->private_data = data;
4190 event->tag = spec->events.used;
4191 event->data = data;
4192
4193 return event->tag;
4194}
4195
4196static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
4197 hda_nid_t nid)
4198{
4199 struct sigmatel_spec *spec = codec->spec;
4200 struct sigmatel_event *event = spec->events.list;
4201 int i;
4202
4203 for (i = 0; i < spec->events.used; i++, event++) {
4204 if (event->nid == nid)
4205 return event;
4206 }
4207 return NULL;
4208}
4209
4210static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4211 unsigned char tag)
4212{
4213 struct sigmatel_spec *spec = codec->spec;
4214 struct sigmatel_event *event = spec->events.list;
4215 int i;
4216 4141
4217 for (i = 0; i < spec->events.used; i++, event++) { 4142 return 0;
4218 if (event->tag == tag)
4219 return event;
4220 }
4221 return NULL;
4222} 4143}
4223 4144
4224/* check if given nid is a valid pin and no other events are assigned 4145/* check if given nid is a valid pin and no other events are assigned
@@ -4228,24 +4149,17 @@ static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4228static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid, 4149static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4229 unsigned int type) 4150 unsigned int type)
4230{ 4151{
4231 struct sigmatel_event *event; 4152 struct hda_jack_tbl *event;
4232 int tag;
4233 4153
4234 if (!is_jack_detectable(codec, nid)) 4154 if (!is_jack_detectable(codec, nid))
4235 return 0; 4155 return 0;
4236 event = stac_get_event(codec, nid); 4156 event = snd_hda_jack_tbl_new(codec, nid);
4237 if (event) { 4157 if (!event)
4238 if (event->type != type) 4158 return -ENOMEM;
4239 return 0; 4159 if (event->action && event->action != type)
4240 tag = event->tag; 4160 return 0;
4241 } else { 4161 event->action = type;
4242 tag = stac_add_event(codec->spec, nid, type, 0); 4162 snd_hda_jack_detect_enable(codec, nid, 0);
4243 if (tag < 0)
4244 return 0;
4245 }
4246 snd_hda_codec_write_cache(codec, nid, 0,
4247 AC_VERB_SET_UNSOLICITED_ENABLE,
4248 AC_USRSP_EN | tag);
4249 return 1; 4163 return 1;
4250} 4164}
4251 4165
@@ -4473,6 +4387,8 @@ static int stac92xx_init(struct hda_codec *codec)
4473 stac_toggle_power_map(codec, nid, 0); 4387 stac_toggle_power_map(codec, nid, 0);
4474 } 4388 }
4475 4389
4390 snd_hda_jack_report_sync(codec);
4391
4476 /* sync mute LED */ 4392 /* sync mute LED */
4477 if (spec->gpio_led) 4393 if (spec->gpio_led)
4478 hda_call_check_power_status(codec, 0x01); 4394 hda_call_check_power_status(codec, 0x01);
@@ -4529,8 +4445,6 @@ static void stac92xx_free(struct hda_codec *codec)
4529 return; 4445 return;
4530 4446
4531 stac92xx_shutup(codec); 4447 stac92xx_shutup(codec);
4532 snd_hda_input_jack_free(codec);
4533 snd_array_free(&spec->events);
4534 4448
4535 kfree(spec); 4449 kfree(spec);
4536 snd_hda_detach_beep_device(codec); 4450 snd_hda_detach_beep_device(codec);
@@ -4794,26 +4708,13 @@ static void stac92xx_mic_detect(struct hda_codec *codec)
4794 mic->mux_idx); 4708 mic->mux_idx);
4795} 4709}
4796 4710
4797static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid) 4711static void handle_unsol_event(struct hda_codec *codec,
4798{ 4712 struct hda_jack_tbl *event)
4799 struct sigmatel_event *event = stac_get_event(codec, nid);
4800 if (!event)
4801 return;
4802 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4803}
4804
4805static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4806{ 4713{
4807 struct sigmatel_spec *spec = codec->spec; 4714 struct sigmatel_spec *spec = codec->spec;
4808 struct sigmatel_event *event; 4715 int data;
4809 int tag, data;
4810
4811 tag = (res >> 26) & 0x7f;
4812 event = stac_get_event_from_tag(codec, tag);
4813 if (!event)
4814 return;
4815 4716
4816 switch (event->type) { 4717 switch (event->action) {
4817 case STAC_HP_EVENT: 4718 case STAC_HP_EVENT:
4818 case STAC_LO_EVENT: 4719 case STAC_LO_EVENT:
4819 stac92xx_hp_detect(codec); 4720 stac92xx_hp_detect(codec);
@@ -4823,7 +4724,7 @@ static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4823 break; 4724 break;
4824 } 4725 }
4825 4726
4826 switch (event->type) { 4727 switch (event->action) {
4827 case STAC_HP_EVENT: 4728 case STAC_HP_EVENT:
4828 case STAC_LO_EVENT: 4729 case STAC_LO_EVENT:
4829 case STAC_MIC_EVENT: 4730 case STAC_MIC_EVENT:
@@ -4831,7 +4732,6 @@ static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4831 case STAC_PWR_EVENT: 4732 case STAC_PWR_EVENT:
4832 if (spec->num_pwrs > 0) 4733 if (spec->num_pwrs > 0)
4833 stac92xx_pin_sense(codec, event->nid); 4734 stac92xx_pin_sense(codec, event->nid);
4834 snd_hda_input_jack_report(codec, event->nid);
4835 4735
4836 switch (codec->subsystem_id) { 4736 switch (codec->subsystem_id) {
4837 case 0x103c308f: 4737 case 0x103c308f:
@@ -4856,11 +4756,33 @@ static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4856 AC_VERB_GET_GPIO_DATA, 0); 4756 AC_VERB_GET_GPIO_DATA, 0);
4857 /* toggle VREF state based on GPIOx status */ 4757 /* toggle VREF state based on GPIOx status */
4858 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0, 4758 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
4859 !!(data & (1 << event->data))); 4759 !!(data & (1 << event->private_data)));
4860 break; 4760 break;
4861 } 4761 }
4862} 4762}
4863 4763
4764static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
4765{
4766 struct hda_jack_tbl *event = snd_hda_jack_tbl_get(codec, nid);
4767 if (!event)
4768 return;
4769 handle_unsol_event(codec, event);
4770}
4771
4772static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4773{
4774 struct hda_jack_tbl *event;
4775 int tag;
4776
4777 tag = (res >> 26) & 0x7f;
4778 event = snd_hda_jack_tbl_get_from_tag(codec, tag);
4779 if (!event)
4780 return;
4781 event->jack_dirty = 1;
4782 handle_unsol_event(codec, event);
4783 snd_hda_jack_report_sync(codec);
4784}
4785
4864static int hp_blike_system(u32 subsystem_id); 4786static int hp_blike_system(u32 subsystem_id);
4865 4787
4866static void set_hp_led_gpio(struct hda_codec *codec) 4788static void set_hp_led_gpio(struct hda_codec *codec)
@@ -5837,15 +5759,13 @@ again:
5837 switch (spec->board_config) { 5759 switch (spec->board_config) {
5838 case STAC_HP_M4: 5760 case STAC_HP_M4:
5839 /* Enable VREF power saving on GPIO1 detect */ 5761 /* Enable VREF power saving on GPIO1 detect */
5840 err = stac_add_event(spec, codec->afg, 5762 err = stac_add_event(codec, codec->afg,
5841 STAC_VREF_EVENT, 0x02); 5763 STAC_VREF_EVENT, 0x02);
5842 if (err < 0) 5764 if (err < 0)
5843 return err; 5765 return err;
5844 snd_hda_codec_write_cache(codec, codec->afg, 0, 5766 snd_hda_codec_write_cache(codec, codec->afg, 0,
5845 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02); 5767 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5846 snd_hda_codec_write_cache(codec, codec->afg, 0, 5768 snd_hda_jack_detect_enable(codec, codec->afg, 0);
5847 AC_VERB_SET_UNSOLICITED_ENABLE,
5848 AC_USRSP_EN | err);
5849 spec->gpio_mask |= 0x02; 5769 spec->gpio_mask |= 0x02;
5850 break; 5770 break;
5851 } 5771 }
@@ -6316,14 +6236,12 @@ static int patch_stac9205(struct hda_codec *codec)
6316 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030); 6236 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
6317 6237
6318 /* Enable unsol response for GPIO4/Dock HP connection */ 6238 /* Enable unsol response for GPIO4/Dock HP connection */
6319 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01); 6239 err = stac_add_event(codec, codec->afg, STAC_VREF_EVENT, 0x01);
6320 if (err < 0) 6240 if (err < 0)
6321 return err; 6241 return err;
6322 snd_hda_codec_write_cache(codec, codec->afg, 0, 6242 snd_hda_codec_write_cache(codec, codec->afg, 0,
6323 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10); 6243 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
6324 snd_hda_codec_write_cache(codec, codec->afg, 0, 6244 snd_hda_jack_detect_enable(codec, codec->afg, 0);
6325 AC_VERB_SET_UNSOLICITED_ENABLE,
6326 AC_USRSP_EN | err);
6327 6245
6328 spec->gpio_dir = 0x0b; 6246 spec->gpio_dir = 0x0b;
6329 spec->eapd_mask = 0x01; 6247 spec->eapd_mask = 0x01;
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
index b5137629f8e9..ab56866cc94e 100644
--- a/sound/pci/hda/patch_via.c
+++ b/sound/pci/hda/patch_via.c
@@ -54,6 +54,7 @@
54#include <sound/asoundef.h> 54#include <sound/asoundef.h>
55#include "hda_codec.h" 55#include "hda_codec.h"
56#include "hda_local.h" 56#include "hda_local.h"
57#include "hda_jack.h"
57 58
58/* Pin Widget NID */ 59/* Pin Widget NID */
59#define VT1708_HP_PIN_NID 0x20 60#define VT1708_HP_PIN_NID 0x20
@@ -1503,6 +1504,11 @@ static int via_build_controls(struct hda_codec *codec)
1503 analog_low_current_mode(codec); 1504 analog_low_current_mode(codec);
1504 1505
1505 via_free_kctls(codec); /* no longer needed */ 1506 via_free_kctls(codec); /* no longer needed */
1507
1508 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
1509 if (err < 0)
1510 return err;
1511
1506 return 0; 1512 return 0;
1507} 1513}
1508 1514
@@ -1714,6 +1720,7 @@ static void via_unsol_event(struct hda_codec *codec,
1714 unsigned int res) 1720 unsigned int res)
1715{ 1721{
1716 res >>= 26; 1722 res >>= 26;
1723 res = snd_hda_jack_get_action(codec, res);
1717 1724
1718 if (res & VIA_JACK_EVENT) 1725 if (res & VIA_JACK_EVENT)
1719 set_widgets_power_state(codec); 1726 set_widgets_power_state(codec);
@@ -1724,6 +1731,7 @@ static void via_unsol_event(struct hda_codec *codec,
1724 via_hp_automute(codec); 1731 via_hp_automute(codec);
1725 else if (res == VIA_GPIO_EVENT) 1732 else if (res == VIA_GPIO_EVENT)
1726 via_gpio_control(codec); 1733 via_gpio_control(codec);
1734 snd_hda_jack_report_sync(codec);
1727} 1735}
1728 1736
1729#ifdef CONFIG_PM 1737#ifdef CONFIG_PM
@@ -2736,9 +2744,8 @@ static void via_auto_init_unsol_event(struct hda_codec *codec)
2736 int i; 2744 int i;
2737 2745
2738 if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0])) 2746 if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
2739 snd_hda_codec_write(codec, cfg->hp_pins[0], 0, 2747 snd_hda_jack_detect_enable(codec, cfg->hp_pins[0],
2740 AC_VERB_SET_UNSOLICITED_ENABLE, 2748 VIA_HP_EVENT | VIA_JACK_EVENT);
2741 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT);
2742 2749
2743 if (cfg->speaker_pins[0]) 2750 if (cfg->speaker_pins[0])
2744 ev = VIA_LINE_EVENT; 2751 ev = VIA_LINE_EVENT;
@@ -2747,16 +2754,14 @@ static void via_auto_init_unsol_event(struct hda_codec *codec)
2747 for (i = 0; i < cfg->line_outs; i++) { 2754 for (i = 0; i < cfg->line_outs; i++) {
2748 if (cfg->line_out_pins[i] && 2755 if (cfg->line_out_pins[i] &&
2749 is_jack_detectable(codec, cfg->line_out_pins[i])) 2756 is_jack_detectable(codec, cfg->line_out_pins[i]))
2750 snd_hda_codec_write(codec, cfg->line_out_pins[i], 0, 2757 snd_hda_jack_detect_enable(codec, cfg->line_out_pins[i],
2751 AC_VERB_SET_UNSOLICITED_ENABLE, 2758 ev | VIA_JACK_EVENT);
2752 AC_USRSP_EN | ev | VIA_JACK_EVENT);
2753 } 2759 }
2754 2760
2755 for (i = 0; i < cfg->num_inputs; i++) { 2761 for (i = 0; i < cfg->num_inputs; i++) {
2756 if (is_jack_detectable(codec, cfg->inputs[i].pin)) 2762 if (is_jack_detectable(codec, cfg->inputs[i].pin))
2757 snd_hda_codec_write(codec, cfg->inputs[i].pin, 0, 2763 snd_hda_jack_detect_enable(codec, cfg->inputs[i].pin,
2758 AC_VERB_SET_UNSOLICITED_ENABLE, 2764 VIA_JACK_EVENT);
2759 AC_USRSP_EN | VIA_JACK_EVENT);
2760 } 2765 }
2761} 2766}
2762 2767
@@ -2779,6 +2784,7 @@ static int via_init(struct hda_codec *codec)
2779 2784
2780 via_hp_automute(codec); 2785 via_hp_automute(codec);
2781 vt1708_update_hp_work(spec); 2786 vt1708_update_hp_work(spec);
2787 snd_hda_jack_report_sync(codec);
2782 2788
2783 return 0; 2789 return 0;
2784} 2790}
@@ -2789,6 +2795,7 @@ static void vt1708_update_hp_jack_state(struct work_struct *work)
2789 vt1708_hp_work.work); 2795 vt1708_hp_work.work);
2790 if (spec->codec_type != VT1708) 2796 if (spec->codec_type != VT1708)
2791 return; 2797 return;
2798 snd_hda_jack_set_dirty_all(spec->codec);
2792 /* if jack state toggled */ 2799 /* if jack state toggled */
2793 if (spec->vt1708_hp_present 2800 if (spec->vt1708_hp_present
2794 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) { 2801 != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {