Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jie Yang <yang.jie@intel.com>
To: tiwai@suse.de
Cc: alsa-devel@alsa-project.org, broonie@kernel.org,
	liam.r.girdwood@intel.com
Subject: [PATCH v7 4/7] ALSA: hda - Update to use the new jack kctls method
Date: Tue, 21 Apr 2015 16:05:42 +0800	[thread overview]
Message-ID: <1429603545-21063-5-git-send-email-yang.jie@intel.com> (raw)
In-Reply-To: <1429603545-21063-1-git-send-email-yang.jie@intel.com>

In the new jack kctls design, snd_kcontrol can be created
during snd_jack_new(), or calling snd_jack_add_new_kctls()
to create and attach to the created jack later.

Here we create jack kctls at the jack creating stage, for
both phantom/non-phantom jack.

Signed-off-by: Jie Yang <yang.jie@intel.com>
---
 sound/pci/hda/hda_jack.c | 53 +++++++++++++++++-------------------------------
 sound/pci/hda/hda_jack.h |  4 +---
 2 files changed, 20 insertions(+), 37 deletions(-)

diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c
index f45c488..3447853 100644
--- a/sound/pci/hda/hda_jack.c
+++ b/sound/pci/hda/hda_jack.c
@@ -132,11 +132,11 @@ void snd_hda_jack_tbl_clear(struct hda_codec *codec)
 
 	for (i = 0; i < codec->jacktbl.used; i++, jack++) {
 		struct hda_jack_callback *cb, *next;
-#ifdef CONFIG_SND_HDA_INPUT_JACK
+
 		/* free jack instances manually when clearing/reconfiguring */
 		if (!codec->bus->shutdown && jack->jack)
 			snd_device_free(codec->bus->card, jack->jack);
-#endif
+
 		for (cb = jack->callback; cb; cb = next) {
 			next = cb->next;
 			kfree(cb);
@@ -337,20 +337,16 @@ void snd_hda_jack_report_sync(struct hda_codec *codec)
 	jack = codec->jacktbl.list;
 	for (i = 0; i < codec->jacktbl.used; i++, jack++)
 		if (jack->nid) {
-			if (!jack->kctl || jack->block_report)
+			if (!jack->jack_kctl || jack->block_report)
 				continue;
 			state = get_jack_plug_state(jack->pin_sense);
-			snd_kctl_jack_report(codec->bus->card, jack->kctl, state);
-#ifdef CONFIG_SND_HDA_INPUT_JACK
 			if (jack->jack)
 				snd_jack_report(jack->jack,
 						state ? jack->type : 0);
-#endif
 		}
 }
 EXPORT_SYMBOL_GPL(snd_hda_jack_report_sync);
 
-#ifdef CONFIG_SND_HDA_INPUT_JACK
 /* guess the jack type from the pin-config */
 static int get_input_jack_type(struct hda_codec *codec, hda_nid_t nid)
 {
@@ -377,7 +373,6 @@ static void hda_free_jack_priv(struct snd_jack *jack)
 	jacks->nid = 0;
 	jacks->jack = NULL;
 }
-#endif
 
 /**
  * snd_hda_jack_add_kctl - Add a kctl for the given pin
@@ -394,37 +389,27 @@ static int __snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,
 			  const char *name, int idx, bool phantom_jack)
 {
 	struct hda_jack_tbl *jack;
-	struct snd_kcontrol *kctl;
-	int err, state;
+	int err, state, type;
 
 	jack = snd_hda_jack_tbl_new(codec, nid);
 	if (!jack)
 		return 0;
-	if (jack->kctl)
+	if (jack->jack_kctl)
 		return 0; /* already created */
-	kctl = snd_kctl_jack_new(name, codec);
-	if (!kctl)
-		return -ENOMEM;
-	err = snd_hda_ctl_add(codec, nid, kctl);
+
+	type = get_input_jack_type(codec, nid);
+	err = snd_jack_new(codec->bus->card, name, type,
+			   &jack->jack, phantom_jack, &jack->jack_kctl);
 	if (err < 0)
 		return err;
-	jack->kctl = kctl;
-	jack->phantom_jack = !!phantom_jack;
 
+	jack->phantom_jack = !!phantom_jack;
+	jack->type = type;
+	jack->jack->private_data = jack;
+	jack->jack->private_free = hda_free_jack_priv;
 	state = snd_hda_jack_detect(codec, nid);
-	snd_kctl_jack_report(codec->bus->card, kctl, state);
-#ifdef CONFIG_SND_HDA_INPUT_JACK
-	if (!phantom_jack) {
-		jack->type = get_input_jack_type(codec, nid);
-		err = snd_jack_new(codec->bus->card, name, jack->type,
-				   &jack->jack, false, NULL);
-		if (err < 0)
-			return err;
-		jack->jack->private_data = jack;
-		jack->jack->private_free = hda_free_jack_priv;
-		snd_jack_report(jack->jack, state ? jack->type : 0);
-	}
-#endif
+	snd_jack_report(jack->jack, state ? jack->type : 0);
+
 	return 0;
 }
 
@@ -453,10 +438,10 @@ static int get_unique_index(struct hda_codec *codec, const char *name, int idx)
 	jack = codec->jacktbl.list;
 	for (i = 0; i < codec->jacktbl.used; i++, jack++) {
 		/* jack->kctl.id contains "XXX Jack" name string with index */
-		if (jack->kctl &&
-		    !strncmp(name, jack->kctl->id.name, len) &&
-		    !strcmp(" Jack", jack->kctl->id.name + len) &&
-		    jack->kctl->id.index == idx) {
+		if (jack->jack_kctl &&
+		    !strncmp(name, jack->jack_kctl->kctl->id.name, len) &&
+		    !strcmp(" Jack", jack->jack_kctl->kctl->id.name + len) &&
+		    jack->jack_kctl->kctl->id.index == idx) {
 			idx++;
 			goto again;
 		}
diff --git a/sound/pci/hda/hda_jack.h b/sound/pci/hda/hda_jack.h
index b279e32..346a639 100644
--- a/sound/pci/hda/hda_jack.h
+++ b/sound/pci/hda/hda_jack.h
@@ -39,11 +39,9 @@ struct hda_jack_tbl {
 	unsigned int block_report:1;    /* in a transitional state - do not report to userspace */
 	hda_nid_t gating_jack;		/* valid when gating jack plugged */
 	hda_nid_t gated_jack;		/* gated is dependent on this jack */
-	struct snd_kcontrol *kctl;	/* assigned kctl for jack-detection */
-#ifdef CONFIG_SND_HDA_INPUT_JACK
 	int type;
+	struct snd_jack_kctl *jack_kctl;
 	struct snd_jack *jack;
-#endif
 };
 
 struct hda_jack_tbl *
-- 
1.9.1

  parent reply	other threads:[~2015-04-21  8:02 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-21  8:05 [PATCH v7 0/7] ALSA: jack: Refactoring for jack kctls Jie Yang
2015-04-21  8:05 ` [PATCH v7 1/7] ALSA: jack: implement kctl creating for jack device Jie Yang
2015-04-21  8:05 ` [PATCH v7 2/7] ALSA: Jack: refactoring snd_kctl_jack_new to support embedded kctl Jie Yang
2015-04-21  9:53   ` Takashi Iwai
2015-04-22  0:51     ` Jie, Yang
2015-04-22  5:32       ` Takashi Iwai
2015-04-22  5:33         ` Jie, Yang
2015-04-21  8:05 ` [PATCH v7 3/7] ALSA: jack: extend snd_jack_new to support phantom jack Jie Yang
2015-04-21  9:57   ` Takashi Iwai
2015-04-22  2:06     ` Jie, Yang
2015-04-22  2:51     ` Jie, Yang
2015-04-21  8:05 ` Jie Yang [this message]
2015-04-21  9:58   ` [PATCH v7 4/7] ALSA: hda - Update to use the new jack kctls method Takashi Iwai
2015-04-22  4:56     ` Jie, Yang
2015-04-21  8:05 ` [PATCH v7 5/7] ASoC: jack: create kctls according to jack pins info Jie Yang
2015-04-21  8:05 ` [PATCH v7 6/7] ALSA: jack: remove exporting ctljack functions Jie Yang
2015-04-21  8:05 ` [PATCH v7 7/7] ALSA: Docs: Add documentation for Jack kcontrols Jie Yang

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=1429603545-21063-5-git-send-email-yang.jie@intel.com \
    --to=yang.jie@intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=liam.r.girdwood@intel.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox