All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: clemens@ladisch.de, tiwai@suse.de
Cc: alsa-devel@alsa-project.org, ffado-devel@lists.sf.net
Subject: [PATCH 06/15] ALSA: firewire-lib: add support arbitrary value for fmt/fdf fields in CIP header
Date: Sat, 19 Sep 2015 11:21:53 +0900	[thread overview]
Message-ID: <1442629322-15457-7-git-send-email-o-takashi@sakamocchi.jp> (raw)
In-Reply-To: <1442629322-15457-1-git-send-email-o-takashi@sakamocchi.jp>

Some vendor specific protocol uses its own value for fmt/fdf fields in
CIP header.

This commit support to set arbitrary values for the fields.

In IEC 61883-6, NO-DATA code is defined for FDF field. A packet with this
code includes no data even if it includes some data blocks. This commit
still leaves a condition to handle this special packet.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 sound/firewire/amdtp.c | 31 +++++++++++++++++++++++--------
 sound/firewire/amdtp.h |  2 ++
 2 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
index 5a3a452..b251f4b 100644
--- a/sound/firewire/amdtp.c
+++ b/sound/firewire/amdtp.c
@@ -59,8 +59,8 @@
  * Audio and Music transfer protocol specific parameters
  * only "Clock-based rate control mode" is supported
  */
-#define CIP_FMT_AM		(0x10 << CIP_FMT_SHIFT)
-#define AMDTP_FDF_AM824		(0 << (CIP_FDF_SHIFT + 3))
+#define CIP_FMT_AM		0x10
+#define AMDTP_FDF_AM824		0x00
 #define AMDTP_FDF_NO_DATA	0xff
 
 /* TODO: make these configurable */
@@ -94,6 +94,8 @@ int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit,
 	s->callbacked = false;
 	s->sync_slave = NULL;
 
+	s->fmt = CIP_FMT_AM;
+
 	return 0;
 }
 EXPORT_SYMBOL(amdtp_stream_init);
@@ -225,6 +227,8 @@ int amdtp_stream_set_parameters(struct amdtp_stream *s,
 	s->data_block_quadlets = s->pcm_channels + midi_channels;
 	s->midi_ports = midi_ports;
 
+	s->fdf = AMDTP_FDF_AM824 | s->sfc;
+
 	/*
 	 * In IEC 61883-6, one data block represents one event. In ALSA, one
 	 * event equals to one PCM frame. But Dice has a quirk at higher
@@ -691,8 +695,10 @@ static int handle_out_packet(struct amdtp_stream *s, unsigned int data_blocks,
 	buffer[0] = cpu_to_be32(ACCESS_ONCE(s->source_node_id_field) |
 				(s->data_block_quadlets << CIP_DBS_SHIFT) |
 				s->data_block_counter);
-	buffer[1] = cpu_to_be32(CIP_EOH | CIP_FMT_AM | AMDTP_FDF_AM824 |
-				(s->sfc << CIP_FDF_SHIFT) | syt);
+	buffer[1] = cpu_to_be32(CIP_EOH |
+				((s->fmt << CIP_FMT_SHIFT) & CIP_FMT_MASK) |
+				((s->fdf << CIP_FDF_SHIFT) & CIP_FDF_MASK) |
+				(syt & CIP_SYT_MASK));
 
 	s->data_block_counter = (s->data_block_counter + data_blocks) & 0xff;
 
@@ -732,6 +738,7 @@ static int handle_in_packet(struct amdtp_stream *s,
 			    unsigned int *data_blocks, unsigned int syt)
 {
 	u32 cip_header[2];
+	unsigned int fmt, fdf;
 	unsigned int data_block_quadlets, data_block_counter, dbc_interval;
 	struct snd_pcm_substream *pcm;
 	unsigned int pcm_frames;
@@ -745,8 +752,7 @@ static int handle_in_packet(struct amdtp_stream *s,
 	 * For convenience, also check FMT field is AM824 or not.
 	 */
 	if (((cip_header[0] & CIP_EOH_MASK) == CIP_EOH) ||
-	    ((cip_header[1] & CIP_EOH_MASK) != CIP_EOH) ||
-	    ((cip_header[1] & CIP_FMT_MASK) != CIP_FMT_AM)) {
+	    ((cip_header[1] & CIP_EOH_MASK) != CIP_EOH)) {
 		dev_info_ratelimited(&s->unit->device,
 				"Invalid CIP header for AMDTP: %08X:%08X\n",
 				cip_header[0], cip_header[1]);
@@ -755,10 +761,19 @@ static int handle_in_packet(struct amdtp_stream *s,
 		goto end;
 	}
 
+	/* Check valid protocol or not. */
+	fmt = (cip_header[1] & CIP_FMT_MASK) >> CIP_FMT_SHIFT;
+	if (fmt != s->fmt) {
+		dev_err(&s->unit->device,
+			"Detect unexpected protocol: %08x %08x\n",
+			cip_header[0], cip_header[1]);
+		return -EIO;
+	}
+
 	/* Calculate data blocks */
+	fdf = (cip_header[1] & CIP_FDF_MASK) >> CIP_FDF_SHIFT;
 	if (payload_quadlets < 3 ||
-	    ((cip_header[1] & CIP_FDF_MASK) ==
-				(AMDTP_FDF_NO_DATA << CIP_FDF_SHIFT))) {
+	    (fmt == CIP_FMT_AM && fdf == AMDTP_FDF_NO_DATA)) {
 		*data_blocks = 0;
 	} else {
 		data_block_quadlets =
diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
index 6522925..883bb1a 100644
--- a/sound/firewire/amdtp.h
+++ b/sound/firewire/amdtp.h
@@ -128,6 +128,8 @@ struct amdtp_stream {
 	unsigned int source_node_id_field;
 	unsigned int data_block_quadlets;
 	unsigned int data_block_counter;
+	unsigned int fmt;
+	unsigned int fdf;
 	/* quirk: fixed interval of dbc between previos/current packets. */
 	unsigned int tx_dbc_interval;
 	/* quirk: indicate the value of dbc field in a first packet. */
-- 
2.1.4

  parent reply	other threads:[~2015-09-19  2:22 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-19  2:21 [PATCH 00/15 v3] ALSA: firewire-lib: separate to packet streaming layer and data block processing layer Takashi Sakamoto
2015-09-19  2:21 ` [PATCH 01/15] ALSA: firewire-lib: arrange structure for AMDTP stream Takashi Sakamoto
2015-09-19  2:21 ` [PATCH 02/15] ALSA: firewire-lib: return error code when amdtp_stream_set_parameters() detects error Takashi Sakamoto
2015-09-19  2:21 ` [PATCH 03/15] ALSA: firewire-lib: add an argument for Dice's dual wire mode Takashi Sakamoto
2015-09-19  2:21 ` [PATCH 04/15] ALSA: firewire-lib: add a member of frame_multiplier instead of double_pcm_frames Takashi Sakamoto
2015-09-19  2:21 ` [PATCH 05/15] ALSA: firewire-lib: add helper functions as interfaces between packet streaming layer and data block processing layer Takashi Sakamoto
2015-09-19  2:21 ` Takashi Sakamoto [this message]
2015-09-19  2:21 ` [PATCH 07/15] ALSA: firewire-lib: rename 'amdtp' to 'amdtp-stream' to prepare for functional separation Takashi Sakamoto
2015-09-19  2:21 ` [PATCH 08/15] ALSA: firewire-lib: add data block processing layer for AM824 format Takashi Sakamoto
2015-09-19  2:21 ` [PATCH 09/15] ALSA: firewire-lib: rename parameter setting function for AM824 with FDF field Takashi Sakamoto
2015-09-19  2:21 ` [PATCH 10/15] ALSA: firewire-lib: move PCM substream constraint to AM824 layer Takashi Sakamoto
2015-09-19  2:21 ` [PATCH 11/15] ALSA: firewire-lib: add helper functions to set positions of data channels Takashi Sakamoto
2015-09-19  2:21 ` [PATCH 12/15] ALSA: firewire-lib: move MIDI trigger helper function to AM824 layer Takashi Sakamoto
2015-09-19  2:22 ` [PATCH 13/15] ALSA: firewire-lib: rename PCM format helper function Takashi Sakamoto
2015-09-19  2:22 ` [PATCH 14/15] ALSA: firewire-lib: rename macros with AM824 prefix Takashi Sakamoto
2015-09-19  2:22 ` [PATCH 15/15] ALSA: firewire-lib: complete AM824 data block processing layer Takashi Sakamoto
2015-09-19 16:46 ` [PATCH 00/15 v3] ALSA: firewire-lib: separate to packet streaming layer and " Takashi Iwai
2015-09-29 10:55   ` Takashi Iwai
2015-09-29 12:45     ` Takashi Sakamoto
2015-09-29 12:57       ` 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=1442629322-15457-7-git-send-email-o-takashi@sakamocchi.jp \
    --to=o-takashi@sakamocchi.jp \
    --cc=alsa-devel@alsa-project.org \
    --cc=clemens@ladisch.de \
    --cc=ffado-devel@lists.sf.net \
    --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.