From: "Felipe F. Tonello" <eu@felipetonello.com>
To: alsa-devel@alsa-project.org
Cc: "Felipe F. Tonello" <eu@felipetonello.com>,
linux-kernel@vger.kernel.org, Takashi Iwai <tiwai@suse.de>,
Mark Brown <broonie@kernel.org>,
David Henningsson <david.henningsson@canonical.com>,
Wang Xingchao <xingchao.wang@linux.intel.com>,
Jaroslav Kysela <perex@perex.cz>
Subject: [PATCH v2 1/3] ALSA: Added jack detection kcontrol support
Date: Fri, 26 Jul 2013 15:45:11 -0700 [thread overview]
Message-ID: <1374878713-11922-2-git-send-email-eu@felipetonello.com> (raw)
In-Reply-To: <1374878713-11922-1-git-send-email-eu@felipetonello.com>
In-Reply-To: <1374863133-6745-1-git-send-email-eu@felipetonello.com>
From: "Felipe F. Tonello" <eu@felipetonello.com>
This patch adds jack support for alsa kcontrol.
This support is necessary since the new kcontrol is used by user-space
daemons, such as PulseAudio(>=2.0), to do jack detection.)
Signed-off-by: Felipe F. Tonello <eu@felipetonello.com>
---
include/sound/jack.h | 6 ++++--
sound/core/Kconfig | 1 +
sound/core/ctljack.c | 3 ++-
sound/core/jack.c | 29 +++++++++++++++++++++++++++--
4 files changed, 34 insertions(+), 5 deletions(-)
diff --git a/include/sound/jack.h b/include/sound/jack.h
index 5891657..dc62b74 100644
--- a/include/sound/jack.h
+++ b/include/sound/jack.h
@@ -26,6 +26,7 @@
#include <sound/core.h>
struct input_dev;
+struct snd_kcontrol;
/**
* Jack types which can be reported. These values are used as a
@@ -58,6 +59,7 @@ enum snd_jack_types {
struct snd_jack {
struct input_dev *input_dev;
+ struct snd_kcontrol *kctl;
int registered;
int type;
const char *id;
@@ -70,7 +72,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);
+ int idx, struct snd_jack **jack);
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,
int keytype);
@@ -80,7 +82,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)
+ int idx, struct snd_jack **jack)
{
return 0;
}
diff --git a/sound/core/Kconfig b/sound/core/Kconfig
index c0c2f57..8167615 100644
--- a/sound/core/Kconfig
+++ b/sound/core/Kconfig
@@ -20,6 +20,7 @@ config SND_COMPRESS_OFFLOAD
# to avoid having to force INPUT on.
config SND_JACK
bool
+ select SND_KCTL_JACK
config SND_SEQUENCER
tristate "Sequencer support"
diff --git a/sound/core/ctljack.c b/sound/core/ctljack.c
index e4b38fb..59aa6d0 100644
--- a/sound/core/ctljack.c
+++ b/sound/core/ctljack.c
@@ -38,7 +38,8 @@ snd_kctl_jack_new(const char *name, int idx, void *private_data)
kctl = snd_ctl_new1(&jack_detect_kctl, private_data);
if (!kctl)
return NULL;
- snprintf(kctl->id.name, sizeof(kctl->id.name), "%s Jack", name);
+
+ strlcpy(kctl->id.name, name, sizeof(kctl->id.name));
kctl->id.index = idx;
kctl->private_value = 0;
return kctl;
diff --git a/sound/core/jack.c b/sound/core/jack.c
index b35fe73..b2757b1 100644
--- a/sound/core/jack.c
+++ b/sound/core/jack.c
@@ -24,6 +24,7 @@
#include <linux/module.h>
#include <sound/jack.h>
#include <sound/core.h>
+#include <sound/control.h>
static int jack_switch_types[SND_JACK_SWITCH_TYPES] = {
SW_HEADPHONE_INSERT,
@@ -48,6 +49,7 @@ static int snd_jack_dev_free(struct snd_device *device)
else
input_free_device(jack->input_dev);
+ snd_ctl_remove(device->card, jack->kctl);
kfree(jack->id);
kfree(jack);
@@ -85,26 +87,36 @@ static int snd_jack_dev_register(struct snd_device *device)
if (err == 0)
jack->registered = 1;
+ /* We don't need to free the control, it's freed by snd_ctl_add itself
+ if an error occur */
+ err = snd_ctl_add(card, jack->kctl);
+
return err;
}
/**
* snd_jack_new - Create a new jack
* @card: the card instance
- * @id: an identifying string for this jack
+ * @id: an identifying string for this jack, " Jack" is appended to the
+ * string
* @type: a bitmask of enum snd_jack_type values that can be detected by
* this jack
+ * @idx: index of this control item
* @jjack: Used to provide the allocated jack object to the caller.
*
* Creates a new jack object.
*
+ * This function creates a Jack Kcontrol, which is exported to user space via
+ * ALSA Controls.
+ *
* Return: Zero if successful, or a negative error code on failure.
* On success @jjack will be initialised.
*/
int snd_jack_new(struct snd_card *card, const char *id, int type,
- struct snd_jack **jjack)
+ int idx, struct snd_jack **jjack)
{
struct snd_jack *jack;
+ struct snd_kcontrol *kctl;
int err;
int i;
static struct snd_device_ops ops = {
@@ -117,6 +129,7 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
return -ENOMEM;
jack->id = kstrdup(id, GFP_KERNEL);
+ sprintf((char *)jack->id, "%s Jack", jack->id);
jack->input_dev = input_allocate_device();
if (jack->input_dev == NULL) {
@@ -137,6 +150,15 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
if (err < 0)
goto fail_input;
+ /* card is the private_data */
+ kctl = snd_kctl_jack_new(jack->id, idx, card);
+ if (!kctl) {
+ err = -ENOMEM;
+ goto fail_input;
+ }
+
+ jack->kctl = kctl;
+
*jjack = jack;
return 0;
@@ -239,6 +261,9 @@ void snd_jack_report(struct snd_jack *jack, int status)
}
input_sync(jack->input_dev);
+
+ /* Update ALSA KControl interface */
+ snd_kctl_jack_report((struct snd_card *)jack->kctl->private_data, jack->kctl, !!status);
}
EXPORT_SYMBOL(snd_jack_report);
--
1.8.1.4
next prev parent reply other threads:[~2013-07-26 22:46 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-26 18:25 [PATCH 0/4] ALSA: Implement core jack support for kcontrol Felipe F. Tonello
2013-07-26 18:25 ` [PATCH 1/4] ALSA: Added jack detection kcontrol support Felipe F. Tonello
2013-07-26 18:46 ` Mark Brown
2013-07-26 19:04 ` Felipe Tonello
2013-07-26 18:54 ` Mark Brown
2013-07-26 19:10 ` Felipe Tonello
2013-07-26 22:48 ` Mark Brown
2013-07-26 23:13 ` Felipe Tonello
2013-07-27 12:25 ` Mark Brown
2013-07-29 12:05 ` Takashi Iwai
2013-08-01 3:49 ` Felipe Ferreri Tonello
2013-08-01 3:48 ` Felipe Ferreri Tonello
2013-08-01 8:24 ` Mark Brown
2013-07-26 18:25 ` [PATCH 2/4] ALSA: HDA: Updating jack implementation according new ALSA Jacks Felipe F. Tonello
2013-07-26 18:25 ` [PATCH 3/4] ALSA: SoC: " Felipe F. Tonello
2013-07-26 18:50 ` Mark Brown
2013-07-26 19:11 ` Felipe Tonello
2013-07-26 18:25 ` [PATCH 4/4] ALSA: oxygen: " Felipe F. Tonello
2013-07-26 18:56 ` Mark Brown
2013-07-26 19:02 ` Felipe Tonello
2013-07-26 22:45 ` Mark Brown
2013-07-26 22:48 ` Felipe Tonello
2013-07-29 12:10 ` Takashi Iwai
2013-08-01 3:51 ` Felipe Ferreri Tonello
2013-07-26 22:45 ` [PATCH v2 0/3] ALSA: Implement core jack support for kcontrol Felipe F. Tonello
2013-07-26 22:45 ` Felipe F. Tonello [this message]
2013-07-29 14:19 ` [PATCH v2 1/3] ALSA: Added jack detection kcontrol support Takashi Iwai
2013-08-01 3:52 ` Felipe Ferreri Tonello
2013-07-26 22:45 ` [PATCH v2 2/3] ALSA: pci: HDA/oxygen: Updating jack implementation according new ALSA Jacks Felipe F. Tonello
2013-07-26 22:45 ` [PATCH v2 3/3] ALSA: SoC: " Felipe F. Tonello
2013-07-29 15:03 ` Stephen Warren
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=1374878713-11922-2-git-send-email-eu@felipetonello.com \
--to=eu@felipetonello.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=david.henningsson@canonical.com \
--cc=linux-kernel@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.de \
--cc=xingchao.wang@linux.intel.com \
/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;
as well as URLs for NNTP newsgroup(s).