All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Ranostay <mranostay@embeddedalley.com>
To: alsa-devel@alsa-project.org
Cc: Takashi Iwai <tiwai@suse.de>
Subject: [PATCH] hda: add support for jack detection on IDT/Sigmatel
Date: Wed, 15 Oct 2008 10:43:28 -0400	[thread overview]
Message-ID: <48F60190.5060601@embeddedalley.com> (raw)

Added support for jack detection reporting to userspace for
IDT/Sigmatel codecs.

Signed-off-by: Matthew Ranostay <mranostay@embeddedalley.com>
---

diff --git a/core/jack.c b/core/jack.c
index 8133a2b..7a5b07b 100644
--- a/core/jack.c
+++ b/core/jack.c
@@ -95,7 +95,7 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
 		goto fail_input;
 	}

-	jack->input_dev->phys = "ALSA";
+	jack->input_dev->phys = "ALSA Jack Detection";

 	jack->type = type;

diff --git a/pci/Kconfig b/pci/Kconfig
index 7003711..7e40890 100644
--- a/pci/Kconfig
+++ b/pci/Kconfig
@@ -501,6 +501,7 @@ config SND_HDA_INTEL
 	tristate "Intel HD Audio"
 	select SND_PCM
 	select SND_VMASTER
+	select SND_JACK if INPUT=y || INPUT=SND
 	help
 	  Say Y here to include support for Intel "High Definition
 	  Audio" (Azalia) motherboard devices.
diff --git a/pci/hda/hda_codec.h b/pci/hda/hda_codec.h
index 60468f5..93dc961 100644
--- a/pci/hda/hda_codec.h
+++ b/pci/hda/hda_codec.h
@@ -729,6 +729,9 @@ struct hda_codec {

 	struct snd_hwdep *hwdep;	/* assigned hwdep device */

+	/* jack detection */
+	struct snd_jack *jack;
+
 	/* misc flags */
 	unsigned int spdif_status_reset :1; /* needs to toggle SPDIF for each
 					     * status change
diff --git a/pci/hda/hda_proc.c b/pci/hda/hda_proc.c
index 743d779..e07652a 100644
--- a/pci/hda/hda_proc.c
+++ b/pci/hda/hda_proc.c
@@ -425,6 +425,22 @@ static void print_unsol_cap(struct snd_info_buffer *buffer,
 		    (unsol & AC_UNSOL_ENABLED) ? 1 : 0);
 }

+static void print_presence_cap(struct snd_info_buffer *buffer,
+			      struct hda_codec *codec, hda_nid_t nid)
+{
+	int presence = snd_hda_codec_read(codec, nid, 0,
+			AC_VERB_GET_PIN_SENSE, 0);
+	int def_conf = snd_hda_codec_read(codec, nid, 0,
+			AC_VERB_GET_CONFIG_DEFAULT, 0x00);
+	def_conf = get_defcfg_connect(def_conf);
+	if (def_conf && def_conf != AC_JACK_PORT_FIXED)
+		return;
+	snd_iprintf(buffer,
+			"  Jack Presence: %s\n",
+			(presence & AC_PINSENSE_PRESENCE)
+				? "Plugged in" : "Unplugged");
+}
+
 static void print_proc_caps(struct snd_info_buffer *buffer,
 			    struct hda_codec *codec, hda_nid_t nid)
 {
@@ -552,6 +568,9 @@ static void print_codec_info(struct snd_info_entry *entry,
 					   AC_PAR_AUDIO_WIDGET_CAP);
 		unsigned int wid_type =
 			(wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
+		unsigned int pincap = snd_hda_param_read(codec, nid,
+					 AC_PAR_PIN_CAP);
+
 		hda_nid_t conn[HDA_MAX_CONNECTIONS];
 		int conn_len = 0;

@@ -632,6 +651,9 @@ static void print_codec_info(struct snd_info_entry *entry,
 		if (wid_caps & AC_WCAP_UNSOL_CAP)
 			print_unsol_cap(buffer, codec, nid);

+		if (pincap & AC_PINCAP_PRES_DETECT)
+			print_presence_cap(buffer, codec, nid);
+
 		if (wid_caps & AC_WCAP_POWER)
 			print_power_state(buffer, codec, nid);

diff --git a/pci/hda/patch_sigmatel.c b/pci/hda/patch_sigmatel.c
index a2ac720..a406fa7 100644
--- a/pci/hda/patch_sigmatel.c
+++ b/pci/hda/patch_sigmatel.c
@@ -30,6 +30,7 @@
 #include <linux/pci.h>
 #include <sound/core.h>
 #include <sound/asoundef.h>
+#include <sound/jack.h>
 #include "hda_codec.h"
 #include "hda_local.h"
 #include "hda_patch.h"
@@ -3617,7 +3618,7 @@ static int stac92xx_init(struct hda_codec *codec)
 {
 	struct sigmatel_spec *spec = codec->spec;
 	struct auto_pin_cfg *cfg = &spec->autocfg;
-	int i;
+	int i, err;

 	snd_hda_sequence_write(codec, spec->init);

@@ -3639,6 +3640,12 @@ static int stac92xx_init(struct hda_codec *codec)
 		stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
 					 AC_PINCTL_OUT_EN);
 		stac92xx_auto_init_hp_out(codec);
+		/* jack detection */
+		err = snd_jack_new(codec->bus->card,
+			"Headphone Jack Detection",
+			SND_JACK_HEADPHONE, &codec->jack);
+		if (err < 0)
+			return err;
 		/* fake event to set up pins */
 		codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
 	} else {
@@ -3797,6 +3804,10 @@ static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
 		presence = get_hp_pin_presence(codec, cfg->hp_pins[i]);
 	}

+	if (codec->jack)
+		snd_jack_report(codec->jack,
+			presence ? SND_JACK_HEADPHONE : 0);
+
 	if (presence) {
 		/* disable lineouts, enable hp */
 		if (spec->hp_switch)

             reply	other threads:[~2008-10-15 14:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-15 14:43 Matthew Ranostay [this message]
2008-10-15 15:02 ` [PATCH] hda: add support for jack detection on IDT/Sigmatel Takashi Iwai
2008-10-15 15:19   ` Matthew Ranostay
2008-10-15 15:35     ` Takashi Iwai
2008-10-15 15:32   ` Mark Brown
2008-10-15 15:44 ` Mark Brown
2008-10-15 15:45   ` Matthew Ranostay
2008-10-15 15:47   ` Takashi Iwai
  -- strict thread matches above, loose matches on Subject: below --
2008-10-15 18:45 Matthew Ranostay
2008-10-16  6:54 ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48F60190.5060601@embeddedalley.com \
    --to=mranostay@embeddedalley.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.