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,
	tanu.kaskinen@linux.intel.com, liam.r.girdwood@intel.com
Subject: [PATCH v9 3/7] ALSA: jack: extend snd_jack_new to support phantom jack
Date: Thu, 23 Apr 2015 10:32:42 +0800	[thread overview]
Message-ID: <1429756366-22520-4-git-send-email-yang.jie@intel.com> (raw)
In-Reply-To: <1429756366-22520-1-git-send-email-yang.jie@intel.com>

For phantom jack, we won't create input device, but jack kctl
may be needed.

Here, we extend snd_jack_new() to support phantom jack creating:
pass in a bool param for [non-]phantom flag, and a bool param
initial_jack to indicate that if we need create kctl at this
jack creating stage.

We can also add kctl to a jack after the jack is created.

This make the integrating the existing HDA jack kctl and soc jack
kctl possible.

Signed-off-by: Jie Yang <yang.jie@intel.com>
---
 include/sound/jack.h            |  4 ++--
 sound/core/jack.c               | 42 +++++++++++++++++++++++++++++------------
 sound/pci/hda/hda_jack.c        |  2 +-
 sound/pci/oxygen/xonar_wm87x6.c |  2 +-
 sound/soc/soc-jack.c            |  2 +-
 5 files changed, 35 insertions(+), 17 deletions(-)

diff --git a/include/sound/jack.h b/include/sound/jack.h
index 433b13b..23bede1 100644
--- a/include/sound/jack.h
+++ b/include/sound/jack.h
@@ -87,7 +87,7 @@ struct snd_jack {
 #ifdef CONFIG_SND_JACK
 
 int snd_jack_new(struct snd_card *card, const char *id, int type,
-		 struct snd_jack **jack);
+		 struct snd_jack **jack, bool initial_kctl, bool phantom_jack);
 int snd_jack_add_new_kctl(struct snd_jack *jack, const char * name, int mask);
 void snd_jack_set_parent(struct snd_jack *jack, struct device *parent);
 int snd_jack_set_key(struct snd_jack *jack, enum snd_jack_types type,
@@ -97,7 +97,7 @@ void snd_jack_report(struct snd_jack *jack, int status);
 
 #else
 static inline int snd_jack_new(struct snd_card *card, const char *id, int type,
-			       struct snd_jack **jack)
+			       struct snd_jack **jack, bool initial_kctl, bool phantom_jack)
 {
 	return 0;
 }
diff --git a/sound/core/jack.c b/sound/core/jack.c
index 0ccd3b0..d84850c 100644
--- a/sound/core/jack.c
+++ b/sound/core/jack.c
@@ -204,6 +204,10 @@ EXPORT_SYMBOL(snd_jack_add_new_kctl);
  * @type:  a bitmask of enum snd_jack_type values that can be detected by
  *         this jack
  * @jjack: Used to provide the allocated jack object to the caller.
+ * @initial_kctl: create kctl if true, also add it to the non-phantom jack
+ *         kctl list
+ * @phantom_jack: for phantom jack, only create needed kctl, won't create
+ *         input device
  *
  * Creates a new jack object.
  *
@@ -211,9 +215,10 @@ EXPORT_SYMBOL(snd_jack_add_new_kctl);
  * On success @jjack will be initialised.
  */
 int snd_jack_new(struct snd_card *card, const char *id, int type,
-		 struct snd_jack **jjack)
+		 struct snd_jack **jjack, bool initial_kctl, bool phantom_jack)
 {
 	struct snd_jack *jack;
+	struct snd_jack_kctl *jack_kctl = NULL;
 	int err;
 	int i;
 	static struct snd_device_ops ops = {
@@ -222,26 +227,36 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
 		.dev_disconnect = snd_jack_dev_disconnect,
 	};
 
+	if (initial_kctl) {
+		jack_kctl = snd_jack_kctl_new(card, id, type);
+		if (!jack_kctl)
+			return -ENOMEM;
+	}
+
 	jack = kzalloc(sizeof(struct snd_jack), GFP_KERNEL);
 	if (jack == NULL)
 		return -ENOMEM;
 
 	jack->id = kstrdup(id, GFP_KERNEL);
 
-	jack->input_dev = input_allocate_device();
-	if (jack->input_dev == NULL) {
-		err = -ENOMEM;
-		goto fail_input;
-	}
+	/* don't creat input device for phantom jack */
+	if (!phantom_jack) {
+		jack->input_dev = input_allocate_device();
+		if (jack->input_dev == NULL) {
+			err = -ENOMEM;
+			goto fail_input;
+		}
+
+		jack->input_dev->phys = "ALSA";
 
-	jack->input_dev->phys = "ALSA";
+		jack->type = type;
 
-	jack->type = type;
+		for (i = 0; i < SND_JACK_SWITCH_TYPES; i++)
+			if (type & (1 << i))
+				input_set_capability(jack->input_dev, EV_SW,
+						     jack_switch_types[i]);
 
-	for (i = 0; i < SND_JACK_SWITCH_TYPES; i++)
-		if (type & (1 << i))
-			input_set_capability(jack->input_dev, EV_SW,
-					     jack_switch_types[i]);
+	}
 
 	err = snd_device_new(card, SNDRV_DEV_JACK, jack, &ops);
 	if (err < 0)
@@ -250,6 +265,9 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
 	jack->card = card;
 	INIT_LIST_HEAD(&jack->kctl_list);
 
+	if (initial_kctl)
+		snd_jack_kctl_add(jack, jack_kctl);
+
 	*jjack = jack;
 
 	return 0;
diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c
index 6bf1cde..f648229 100644
--- a/sound/pci/hda/hda_jack.c
+++ b/sound/pci/hda/hda_jack.c
@@ -417,7 +417,7 @@ static int __snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,
 	if (!phantom_jack) {
 		jack->type = get_input_jack_type(codec, nid);
 		err = snd_jack_new(codec->bus->card, name, jack->type,
-				   &jack->jack);
+				   &jack->jack, false, false);
 		if (err < 0)
 			return err;
 		jack->jack->private_data = jack;
diff --git a/sound/pci/oxygen/xonar_wm87x6.c b/sound/pci/oxygen/xonar_wm87x6.c
index 6ce6860..90ac479 100644
--- a/sound/pci/oxygen/xonar_wm87x6.c
+++ b/sound/pci/oxygen/xonar_wm87x6.c
@@ -286,7 +286,7 @@ static void xonar_ds_init(struct oxygen *chip)
 	xonar_enable_output(chip);
 
 	snd_jack_new(chip->card, "Headphone",
-		     SND_JACK_HEADPHONE, &data->hp_jack);
+		     SND_JACK_HEADPHONE, &data->hp_jack, false, false);
 	xonar_ds_handle_hp_jack(chip);
 
 	snd_component_add(chip->card, "WM8776");
diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c
index 9f60c25..70a9bdd 100644
--- a/sound/soc/soc-jack.c
+++ b/sound/soc/soc-jack.c
@@ -48,7 +48,7 @@ int snd_soc_card_jack_new(struct snd_soc_card *card, const char *id, int type,
 	INIT_LIST_HEAD(&jack->jack_zones);
 	BLOCKING_INIT_NOTIFIER_HEAD(&jack->notifier);
 
-	ret = snd_jack_new(card->snd_card, id, type, &jack->jack);
+	ret = snd_jack_new(card->snd_card, id, type, &jack->jack, false, false);
 	if (ret)
 		return ret;
 
-- 
1.9.1

  parent reply	other threads:[~2015-04-23  2:29 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-23  2:32 [PATCH v9 0/7] ALSA: jack: Refactoring for jack kctls Jie Yang
2015-04-23  2:32 ` [PATCH v9 1/7] ALSA: jack: implement kctl creating for jack device Jie Yang
2015-04-23  2:32 ` [PATCH v9 2/7] ALSA: Jack: handle jack embedded kcontrol creating within ctljack Jie Yang
2015-04-23  2:32 ` Jie Yang [this message]
2015-04-23  2:32 ` [PATCH v9 4/7] ALSA: hda - Update to use the new jack kctls method Jie Yang
2015-04-23  2:32 ` [PATCH v9 5/7] ASoC: jack: create kctls according to jack pins info Jie Yang
2015-04-27 19:33   ` Mark Brown
2015-04-23  2:32 ` [PATCH v9 6/7] ALSA: jack: remove exporting ctljack functions Jie Yang
2015-04-23  2:32 ` [PATCH v9 7/7] ALSA: Docs: Add documentation for Jack kcontrols Jie Yang
2015-04-23 12:47 ` [PATCH v9 0/7] ALSA: jack: Refactoring for jack kctls Takashi Iwai
2015-04-23 13:45   ` Jie, Yang
2015-04-23 15:00     ` Takashi Iwai
2015-04-23 15:20       ` Liam Girdwood
2015-04-24  4:27         ` Jie, Yang
2015-04-23 18:18     ` Mark Brown
2015-04-24  4:37       ` 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=1429756366-22520-4-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=tanu.kaskinen@linux.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