LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Olivier Moysan <olivier.moysan@st.com>
To: <lgirdwood@gmail.com>, <broonie@kernel.org>, <perex@perex.cz>,
	<tiwai@suse.com>, <mcoquelin.stm32@gmail.com>,
	<alexandre.torgue@st.com>, <alsa-devel@alsa-project.org>,
	<robh@kernel.org>, <mark.rutland@arm.com>,
	<devicetree@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>, <kernel@stlinux.com>,
	<linux-kernel@vger.kernel.org>, <olivier.moysan@st.com>
Cc: <arnaud.pouliquen@st.com>, <benjamin.gaignard@st.com>,
	<rmk@arm.linux.org.uk>, <jsarha@ti.com>
Subject: [PATCH 1/3] ALSA: pcm: add IEC958 channel status control helper
Date: Tue, 13 Mar 2018 17:27:06 +0100	[thread overview]
Message-ID: <1520958428-10930-2-git-send-email-olivier.moysan@st.com> (raw)
In-Reply-To: <1520958428-10930-1-git-send-email-olivier.moysan@st.com>

From: Arnaud Pouliquen <arnaud.pouliquen@st.com>

Add IEC958 channel status helper that creates control to handle the
IEC60958 status bits.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@st.com>
Signed-off-by: Olivier Moysan <olivier.moysan@st.com>
---
 include/sound/pcm_iec958.h |  19 ++++++++
 sound/core/pcm_iec958.c    | 113 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 132 insertions(+)

diff --git a/include/sound/pcm_iec958.h b/include/sound/pcm_iec958.h
index 0939aa45e2fe..3c9701a9b1b0 100644
--- a/include/sound/pcm_iec958.h
+++ b/include/sound/pcm_iec958.h
@@ -4,9 +4,28 @@
 
 #include <linux/types.h>
 
+/**
+ * struct snd_pcm_iec958_params: IEC 60958 controls parameters
+ * @ctrl_set: control set callback
+ * This callback is optional and shall be used to set associated driver
+ * configuration.
+ * @iec: Mandatory pointer to iec958 structure.
+ * @cs: Mandatory pointer to AES/IEC958  channel status bits.
+ * @cs_len: size in byte of the AES/IEC958  channel status bits.
+ * @private_data: Optional private pointer to driver context.
+ */
+struct snd_pcm_iec958_params {
+	int (*ctrl_set)(struct snd_pcm_iec958_params *iec_param);
+	unsigned char *cs;
+	unsigned char cs_len;
+	void *private_data;
+};
+
 int snd_pcm_create_iec958_consumer(struct snd_pcm_runtime *runtime, u8 *cs,
 	size_t len);
 
 int snd_pcm_create_iec958_consumer_hw_params(struct snd_pcm_hw_params *params,
 					     u8 *cs, size_t len);
+int snd_pcm_add_iec958_ctl(struct snd_pcm *pcm, int subdevice, int stream,
+			   struct snd_pcm_iec958_params *params);
 #endif
diff --git a/sound/core/pcm_iec958.c b/sound/core/pcm_iec958.c
index 5e6aed64f451..aba1f522e98a 100644
--- a/sound/core/pcm_iec958.c
+++ b/sound/core/pcm_iec958.c
@@ -7,11 +7,88 @@
  */
 #include <linux/export.h>
 #include <linux/types.h>
+#include <linux/wait.h>
 #include <sound/asoundef.h>
+#include <sound/control.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
 #include <sound/pcm_iec958.h>
 
+static int snd_pcm_iec958_info(struct snd_kcontrol *kcontrol,
+			       struct snd_ctl_elem_info *uinfo)
+{
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
+	uinfo->count = 1;
+	return 0;
+}
+
+/*
+ * IEC958 channel status default controls callbacks
+ */
+static int snd_pcm_iec958_get(struct snd_kcontrol *kcontrol,
+			      struct snd_ctl_elem_value *uctl)
+{
+	struct snd_pcm_iec958_params *params = snd_kcontrol_chip(kcontrol);
+	int i;
+
+	for (i = 0; i < params->cs_len; i++)
+		uctl->value.iec958.status[i] = params->cs[i];
+
+	return 0;
+}
+
+static int snd_pcm_iec958_put(struct snd_kcontrol *kcontrol,
+			      struct snd_ctl_elem_value *uctl)
+{
+	struct snd_pcm_iec958_params *params = snd_kcontrol_chip(kcontrol);
+	int err = 0;
+	unsigned int i, updated = 0;
+	unsigned char old_status[5];
+
+	for (i = 0; i < params->cs_len; i++) {
+		if (params->cs[i] != uctl->value.iec958.status[i])
+			updated = 1;
+	}
+
+	if (!updated)
+		return 0;
+
+	/* Store current status to restore them in error case */
+	for (i = 0; i < params->cs_len; i++) {
+		old_status[i] = params->cs[i];
+		params->cs[i] = uctl->value.iec958.status[i];
+	}
+
+	if (params->ctrl_set)
+		err = params->ctrl_set(params);
+	if (err < 0) {
+		for (i = 0; i < params->cs_len; i++)
+			params->cs[i] = old_status[i];
+	}
+
+	return err;
+}
+
+static const struct snd_kcontrol_new iec958_ctls[] = {
+	{
+		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
+			   SNDRV_CTL_ELEM_ACCESS_VOLATILE),
+		.iface = SNDRV_CTL_ELEM_IFACE_PCM,
+		.name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
+		.info = snd_pcm_iec958_info,
+		.get = snd_pcm_iec958_get,
+		.put = snd_pcm_iec958_put,
+	},
+	{
+		.access = (SNDRV_CTL_ELEM_ACCESS_READ |
+			   SNDRV_CTL_ELEM_ACCESS_VOLATILE),
+		.iface = SNDRV_CTL_ELEM_IFACE_PCM,
+		.name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT),
+		.info = snd_pcm_iec958_info,
+		.get = snd_pcm_iec958_get,
+	},
+};
+
 static int create_iec958_consumer(uint rate, uint sample_width,
 				  u8 *cs, size_t len)
 {
@@ -21,6 +98,9 @@ static int create_iec958_consumer(uint rate, uint sample_width,
 		return -EINVAL;
 
 	switch (rate) {
+	case 0:
+		fs = IEC958_AES3_CON_FS_NOTID;
+		break;
 	case 32000:
 		fs = IEC958_AES3_CON_FS_32000;
 		break;
@@ -48,6 +128,9 @@ static int create_iec958_consumer(uint rate, uint sample_width,
 
 	if (len > 4) {
 		switch (sample_width) {
+		case 0:
+			ws = IEC958_AES4_CON_WORDLEN_NOTID;
+			break;
 		case 16:
 			ws = IEC958_AES4_CON_WORDLEN_20_16;
 			break;
@@ -124,3 +207,33 @@ int snd_pcm_create_iec958_consumer_hw_params(struct snd_pcm_hw_params *params,
 				      cs, len);
 }
 EXPORT_SYMBOL(snd_pcm_create_iec958_consumer_hw_params);
+
+/**
+ * snd_pcm_add_iec958_ctl - Add a IEC958 control associated to the pcm device
+ * @pcm: pcm device to associate to the control.
+ * @subdevice: subdevice index.Must be set to 0 if unused
+ * @iec958: snd_pcm_iec958_params structure that contains callbacks
+ *          and channel status buffer.
+ * @stream: stream type SNDRV_PCM_STREAM_PLAYBACK or SNDRV_PCM_STREAM_CATURE.
+ * Returns:  negative error code if something failed.
+ */
+int snd_pcm_add_iec958_ctl(struct snd_pcm *pcm, int subdevice, int stream,
+			   struct snd_pcm_iec958_params *params)
+{
+	struct snd_kcontrol_new knew;
+
+	if (stream > SNDRV_PCM_STREAM_LAST)
+		return -EINVAL;
+	if (!params->cs)
+		return -EINVAL;
+	if (params->cs_len < 4)
+		return -EINVAL;
+
+	create_iec958_consumer(0, 0, params->cs, params->cs_len);
+	knew = iec958_ctls[stream];
+	knew.device = pcm->device;
+	knew.subdevice = subdevice;
+
+	return snd_ctl_add(pcm->card, snd_ctl_new1(&knew, params));
+}
+EXPORT_SYMBOL(snd_pcm_add_iec958_ctl);
-- 
1.9.1

  reply	other threads:[~2018-03-13 16:30 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-13 16:27 [PATCH 0/3] ASoC: stm32: sai: add support of iec958 controls Olivier Moysan
2018-03-13 16:27 ` Olivier Moysan [this message]
2018-03-13 16:27 ` [PATCH 2/3] ASoC: stm32: sai: add iec958 controls support Olivier Moysan
2018-06-05 15:52   ` Arnaud Pouliquen
2018-03-13 16:27 ` [PATCH 3/3] ASoC: dmaengine_pcm: document process callback Olivier Moysan
2018-03-13 16:47   ` Applied "ASoC: dmaengine_pcm: document process callback" to the asoc tree Mark Brown
2018-04-17  8:29 ` [PATCH 0/3] ASoC: stm32: sai: add support of iec958 controls Olivier MOYSAN
2018-04-17 11:17   ` Mark Brown
2018-05-17 13:03     ` Olivier MOYSAN
2018-06-05 15:50     ` [alsa-devel] " Arnaud Pouliquen
2018-06-05 18:29       ` Takashi Iwai
2018-06-06  9:31         ` Arnaud Pouliquen
2018-06-06  9:47           ` Takashi Iwai
2018-06-07 16:02             ` Arnaud Pouliquen

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=1520958428-10930-2-git-send-email-olivier.moysan@st.com \
    --to=olivier.moysan@st.com \
    --cc=alexandre.torgue@st.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=arnaud.pouliquen@st.com \
    --cc=benjamin.gaignard@st.com \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jsarha@ti.com \
    --cc=kernel@stlinux.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=perex@perex.cz \
    --cc=rmk@arm.linux.org.uk \
    --cc=robh@kernel.org \
    --cc=tiwai@suse.com \
    --subject='Re: [PATCH 1/3] ALSA: pcm: add IEC958 channel status control helper' \
    /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

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).