Alsa-Devel Archive on lore.kernel.org
 help / color / Atom feed
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: clemens@ladisch.de, tiwai@suse.de, perex@perex.cz
Cc: alsa-devel@alsa-project.org, ffado-devel@lists.sf.net
Subject: [PATCH 17/39] firewire-lib: Add quirks for Fireworks
Date: Wed,  5 Mar 2014 19:48:05 +0900
Message-ID: <1394016507-15761-18-git-send-email-o-takashi@sakamocchi.jp> (raw)
In-Reply-To: <1394016507-15761-1-git-send-email-o-takashi@sakamocchi.jp>

This commit adds three modifications for Echo Audio's Fireworks quirks.

1.Making this module to support both TAG0 and TAG1
In IEC 61883-1, each common isochronous packet (CIP) has 'tag' field in its
packet header. The value is generally 0x01 (CIP header is included = TAG1).
But Fireworks in 'IEC 61883 compliant' mode transmits 'no data' packet with
0x00 (No CIP header is included = TAG0) but the packet includes CIP structure.
To process 'presentation timestamp' for duplex streams synchronization
correctly, this packets needs to be handled.

2.Making this module to calculate data block size and not to check continuity
One of Fireworks device, AudioFirePre8, always reports 8 data block size in
in-packets and the data block counter is incremented by 8. But actual value is
different.

3.Making this module to have the numebr of first data blocks for MIDI messages
in out-packet
Fireworks can pick up MIDI messages in first 8 data blocks and ignore in other
data blocks.

I confirm these quirks in firmware version between 4.8 and 5.8 with Windows.
I didn't investigate for the other versions. But according to contact person
in Echo Audio, there is no differences between firmwares installed by Windows
or OS X.
---
 sound/firewire/amdtp.c | 50 +++++++++++++++++++++++++-------------------------
 sound/firewire/amdtp.h |  2 ++
 2 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
index 402b8e4..f961d26 100644
--- a/sound/firewire/amdtp.c
+++ b/sound/firewire/amdtp.c
@@ -88,6 +88,8 @@ int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit,
 	s->sort_table = NULL;
 	s->left_packets = NULL;
 
+	s->blocks_for_midi = UINT_MAX;
+
 	return 0;
 }
 EXPORT_SYMBOL(amdtp_stream_init);
@@ -556,8 +558,14 @@ static void amdtp_fill_midi(struct amdtp_stream *s,
 		buffer[s->midi_position] = 0x00;
 		b = (u8 *)&buffer[s->midi_position];
 
+		/*
+		 * NOTE:
+		 * Fireworks ignores midi messages in more than first 8
+		 * data blocks of an packet.
+		 */
 		port = (s->data_block_counter + f) % 8;
-		if ((s->midi[port] == NULL) ||
+		if ((f >= s->blocks_for_midi) ||
+		    (s->midi[port] == NULL) ||
 		    (snd_rawmidi_transmit(s->midi[port], b + 1, 1) <= 0)) {
 			b[0] = 0x80;
 			b[1] = 0x00;	/* confirm to be zero */
@@ -710,7 +718,7 @@ static void handle_in_packet(struct amdtp_stream *s,
 			     __be32 *buffer)
 {
 	u32 cip_header[2];
-	unsigned int data_block_quadlets, data_blocks, data_block_counter;
+	unsigned int data_blocks;
 	struct snd_pcm_substream *pcm;
 
 	cip_header[0] = be32_to_cpu(buffer[0]);
@@ -735,27 +743,16 @@ static void handle_in_packet(struct amdtp_stream *s,
 							AMDTP_FDF_NO_DATA))
 		return;
 
-	data_block_quadlets =
-			(cip_header[1] & AMDTP_DBS_MASK) >> AMDTP_DBS_SHIFT;
-	/* avoid division by zero */
-	if (data_block_quadlets == 0) {
-		dev_info_ratelimited(&s->unit->device,
-				 "Detect invalid value in dbs field: %08X\n",
-				 data_block_quadlets);
-		return;
-	}
-
-	data_blocks = (payload_quadlets - 2) / data_block_quadlets;
-	data_block_counter = cip_header[1] & AMDTP_DBC_MASK;
-
-	/* check packet continuity */
-	s->data_block_counter = (s->data_block_counter + data_blocks) & 0xff;
-	if (s->data_block_counter != data_block_counter) {
-		dev_info_ratelimited(&s->unit->device,
-				     "Detect uncontinuity of CIP packets\n");
-		s->data_block_counter = data_block_counter;
-		return;
-	}
+	/*
+	 * This module don't use the value of dbs and dbc beceause Echo
+	 * AudioFirePre8 reports inappropriate value.
+	 *
+	 * This model always reports a fixed value "8" as data block size at
+	 * any sampling rates but actually data block size is different.
+	 * Additionally the value of data block count always incremented by
+	 * "8" at any sampling rates but actually it's different.
+	 */
+	data_blocks = (payload_quadlets - 2) / s->data_block_quadlets;
 
 	buffer += 2;
 
@@ -1033,11 +1030,14 @@ int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed)
 			goto err_context;
 	} while (s->packet_index > 0);
 
-	/* NOTE: TAG1 matches CIP. This just affects in stream */
+	/*
+	 * NOTE: TAG1 matches CIP. This just affects in stream.
+	 * Fireworks transmits NODATA packets with TAG0.
+	 */
 	s->data_block_counter = 0;
 	s->callbacked = false;
 	err = fw_iso_context_start(s->context, -1, 0,
-				   FW_ISO_CONTEXT_MATCH_TAG1);
+			FW_ISO_CONTEXT_MATCH_TAG0 | FW_ISO_CONTEXT_MATCH_TAG1);
 	if (err < 0)
 		goto err_context;
 
diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
index 861f509..dce3903 100644
--- a/sound/firewire/amdtp.h
+++ b/sound/firewire/amdtp.h
@@ -113,6 +113,8 @@ struct amdtp_stream {
 	bool pointer_flush;
 
 	struct snd_rawmidi_substream *midi[AMDTP_MAX_CHANNELS_FOR_MIDI * 8];
+	/* quirk: the first count of data blocks in an AMDTP packet for MIDI */
+	unsigned int blocks_for_midi;
 
 	bool callbacked;
 	wait_queue_head_t callback_wait;
-- 
1.8.3.2

  parent reply index

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <5316963F.1000206@sakamocchi.jp>
2014-03-05  6:14 ` [GIT PULL v2] Enhancement of support for Firewire devices Takashi Iwai
2014-03-05 11:00   ` Takashi Sakamoto
2014-03-05 11:09     ` Takashi Iwai
2014-03-05 11:23       ` Takashi Sakamoto
2014-03-05 10:47 ` [GIT PULL][PATCH 00/39 " Takashi Sakamoto
2014-03-05 10:47   ` [PATCH 01/39] firewire-lib: Rename functions, structure, member for AMDTP Takashi Sakamoto
2014-03-05 10:47   ` [PATCH 02/39] firewire-lib: Add macros instead of fixed value " Takashi Sakamoto
2014-03-05 10:47   ` [PATCH 03/39] firewire-lib: Add 'direction' member to 'amdtp_stream' structure Takashi Sakamoto
2014-03-05 10:47   ` [PATCH 04/39] firewire-lib: Split some codes into functions to reuse for both streams Takashi Sakamoto
2014-03-05 10:47   ` [PATCH 05/39] firewire-lib: Add support for AMDTP in-stream and PCM capture Takashi Sakamoto
2014-03-09 20:37     ` Clemens Ladisch
2014-03-10  3:55       ` Takashi Sakamoto
2014-03-12  2:00       ` Takashi Sakamoto
2014-03-14 13:50       ` Takashi Sakamoto
2014-03-05 10:47   ` [PATCH 06/39] firewire-lib: Add support for MIDI capture/playback Takashi Sakamoto
2014-03-09 20:48     ` Clemens Ladisch
2014-03-10  4:13       ` Takashi Sakamoto
2014-03-05 10:47   ` [PATCH 07/39] firewire-lib: Give syt value as parameter to handle_out_packet() Takashi Sakamoto
2014-03-05 10:47   ` [PATCH 08/39] firewire-lib: Add support for duplex streams synchronization in blocking mode Takashi Sakamoto
2014-03-09 20:55     ` Clemens Ladisch
2014-03-10 12:21       ` Takashi Sakamoto
2014-03-05 10:47   ` [PATCH 09/39] firewire-lib: Add sort function for transmitted packet Takashi Sakamoto
2014-03-09 21:07     ` Clemens Ladisch
2014-03-10 13:29       ` Takashi Sakamoto
2014-03-11  8:11         ` Clemens Ladisch
2014-03-12  1:23           ` Takashi Sakamoto
2014-03-12  7:21             ` Takashi Iwai
2014-03-05 10:47   ` [PATCH 10/39] firewire-lib: Add transfer delay to synchronized duplex streams Takashi Sakamoto
2014-03-09 21:13     ` Clemens Ladisch
2014-03-10 13:43       ` Takashi Sakamoto
2014-03-11  8:13         ` Clemens Ladisch
2014-03-05 10:47   ` [PATCH 11/39] firewire-lib: Add support for channel mapping Takashi Sakamoto
2014-03-09 21:20     ` Clemens Ladisch
2014-03-10 12:28       ` Takashi Sakamoto
2014-03-10 12:58         ` Takashi Sakamoto
2014-03-11  8:23         ` Clemens Ladisch
2014-03-11 16:03           ` Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 12/39] firewire-lib: Rename macros, variables and functions for CMP Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 13/39] firewire-lib: Add 'direction' member to 'cmp_connection' structure Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 14/39] firewire-lib: Add handling output connection by CMP Takashi Sakamoto
2014-03-09 21:27     ` Clemens Ladisch
2014-03-10 12:30       ` Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 15/39] firewire-lib: Add a new function to check others' connection Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 16/39] firewire-lib: Add some AV/C general commands Takashi Sakamoto
2014-03-09 21:32     ` Clemens Ladisch
2014-03-10 12:46       ` Takashi Sakamoto
2014-03-14 14:10       ` Takashi Sakamoto
2014-03-14 22:18         ` Clemens Ladisch
2014-03-05 10:48   ` Takashi Sakamoto [this message]
2014-03-09 21:39     ` [PATCH 17/39] firewire-lib: Add quirks for Fireworks Clemens Ladisch
2014-03-10 12:40       ` Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 18/39] firewire-lib: Add a fallback at RCODE_CANCELLED Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 19/39] fireworks: Add skelton for Fireworks based devices Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 20/39] fireworks: Add transaction and some commands Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 21/39] fireworks: Add connection and stream management Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 22/39] fireworks: Add proc interface for debugging purpose Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 23/39] fireworks: Add MIDI interface Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 24/39] fireworks: Add PCM interface Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 25/39] fireworks: Add hwdep interface Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 26/39] fireworks: Add command/response functionality into " Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 27/39] bebob: Add skelton for BeBoB based devices Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 28/39] bebob: Add commands and connections/streams management Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 29/39] bebob: Add proc interface for debugging purpose Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 30/39] bebob: Add MIDI interface Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 31/39] bebob: Add PCM interface Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 32/39] bebob: Add hwdep interface Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 33/39] bebob: Prepare for device specific operations Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 34/39] bebob: Add support for Terratec PHASE, EWS series and Aureon Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 35/39] bebob: Add support for Yamaha GO series Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 36/39] bebob: Add support for Focusrite Saffire/SaffirePro series Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 37/39] bebob: Add support for M-Audio usual Firewire series Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 38/39] bebob: Add support for M-Audio special " Takashi Sakamoto
2014-03-05 10:48   ` [PATCH 39/39] bebob: Send a cue to load firmware for M-Audio " Takashi Sakamoto
2014-03-07 11:44 ` [GIT PULL v2] Enhancement of support for Firewire devices Takashi Iwai
2014-03-07 14:46   ` Clemens Ladisch
2014-02-28  3:27 [GIT PULL][PATCH 00/39] " Takashi Sakamoto
2014-02-28  3:27 ` [PATCH 17/39] firewire-lib: Add quirks for Fireworks Takashi Sakamoto

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=1394016507-15761-18-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=perex@perex.cz \
    --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

Alsa-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/alsa-devel/0 alsa-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 alsa-devel alsa-devel/ https://lore.kernel.org/alsa-devel \
		alsa-devel@alsa-project.org
	public-inbox-index alsa-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.alsa-project.alsa-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git