All of lore.kernel.org
 help / color / mirror / Atom feed
From: Clemens Ladisch <clemens@ladisch.de>
To: Takashi Iwai <tiwai@suse.de>
Cc: alsa-devel@alsa-project.org, linux1394-devel@lists.sourceforge.net
Subject: [PATCH] [05/29] ALSA: dice, firewire-lib: add blocking mode
Date: Mon, 21 Oct 2013 21:23:48 +0200	[thread overview]
Message-ID: <52657F44.7070203@ladisch.de> (raw)
In-Reply-To: <52657E3B.7040205@ladisch.de>

Allow AMDTP output streams to use blocking mode.

Use it for DICE devices, because the old DICE-II chip will in some cases
not be able to lock to non-blocking streams (erratum E7).

Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
---
 sound/firewire/amdtp.c |   54 ++++++++++++++++++++++++++----------------------
 sound/firewire/amdtp.h |    7 +++++-
 sound/firewire/dice.c  |    2 +-
 3 files changed, 36 insertions(+), 27 deletions(-)

diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
index ea995af..efb2e29 100644
--- a/sound/firewire/amdtp.c
+++ b/sound/firewire/amdtp.c
@@ -42,9 +42,6 @@ static void pcm_period_tasklet(unsigned long data);
 int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit,
 			  enum cip_out_flags flags)
 {
-	if (flags != CIP_NONBLOCKING)
-		return -EINVAL;
-
 	s->unit = fw_unit_get(unit);
 	s->flags = flags;
 	s->context = ERR_PTR(-1);
@@ -96,12 +93,20 @@ void amdtp_out_stream_set_rate(struct amdtp_out_stream *s, unsigned int rate)
 		return;

 	for (sfc = 0; sfc < ARRAY_SIZE(rate_info); ++sfc)
-		if (rate_info[sfc].rate == rate) {
-			s->sfc = sfc;
-			s->syt_interval = rate_info[sfc].syt_interval;
-			return;
-		}
+		if (rate_info[sfc].rate == rate)
+			goto sfc_found;
 	WARN_ON(1);
+	return;
+
+sfc_found:
+	s->sfc = sfc;
+	s->syt_interval = rate_info[sfc].syt_interval;
+
+	/* default buffering in the device */
+	s->transfer_delay = TRANSFER_DELAY_TICKS - TICKS_PER_CYCLE;
+	if (s->flags & CIP_BLOCKING)
+		/* additional buffering needed to adjust for no-data packets */
+		s->transfer_delay += TICKS_PER_SECOND * s->syt_interval / rate;
 }
 EXPORT_SYMBOL(amdtp_out_stream_set_rate);

@@ -110,25 +115,15 @@ EXPORT_SYMBOL(amdtp_out_stream_set_rate);
  * @s: the AMDTP output stream
  *
  * This function must not be called before the stream has been configured
- * with amdtp_out_stream_set_hw_params(), amdtp_out_stream_set_pcm(), and
+ * with amdtp_out_stream_set_rate(), amdtp_out_stream_set_pcm(), and
  * amdtp_out_stream_set_midi().
  */
 unsigned int amdtp_out_stream_get_max_payload(struct amdtp_out_stream *s)
 {
-	static const unsigned int max_data_blocks[] = {
-		[CIP_SFC_32000]  =  4,
-		[CIP_SFC_44100]  =  6,
-		[CIP_SFC_48000]  =  6,
-		[CIP_SFC_88200]  = 12,
-		[CIP_SFC_96000]  = 12,
-		[CIP_SFC_176400] = 23,
-		[CIP_SFC_192000] = 24,
-	};
-
 	s->data_block_quadlets = s->pcm_channels;
 	s->data_block_quadlets += DIV_ROUND_UP(s->midi_ports, 8);

-	return 8 + max_data_blocks[s->sfc] * 4 * s->data_block_quadlets;
+	return 8 + s->syt_interval * s->data_block_quadlets * 4;
 }
 EXPORT_SYMBOL(amdtp_out_stream_get_max_payload);

@@ -248,7 +243,7 @@ static unsigned int calculate_syt(struct amdtp_out_stream *s,
 	s->last_syt_offset = syt_offset;

 	if (syt_offset < TICKS_PER_CYCLE) {
-		syt_offset += TRANSFER_DELAY_TICKS - TICKS_PER_CYCLE;
+		syt_offset += s->transfer_delay;
 		syt = (cycle + syt_offset / TICKS_PER_CYCLE) << 12;
 		syt += syt_offset % TICKS_PER_CYCLE;

@@ -344,8 +339,17 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
 		return;
 	index = s->packet_index;

-	data_blocks = calculate_data_blocks(s);
 	syt = calculate_syt(s, cycle);
+	if (!(s->flags & CIP_BLOCKING)) {
+		data_blocks = calculate_data_blocks(s);
+	} else {
+		if (syt != 0xffff) {
+			data_blocks = s->syt_interval;
+		} else {
+			data_blocks = 0;
+			syt = 0xffffff;
+		}
+	}

 	buffer = s->buffer.packets[index].buffer;
 	buffer[0] = cpu_to_be32(ACCESS_ONCE(s->source_node_id_field) |
@@ -455,9 +459,9 @@ static int queue_initial_skip_packets(struct amdtp_out_stream *s)
  * @speed: firewire speed code
  *
  * The stream cannot be started until it has been configured with
- * amdtp_out_stream_set_hw_params(), amdtp_out_stream_set_pcm(), and
- * amdtp_out_stream_set_midi(); and it must be started before any
- * PCM or MIDI device can be started.
+ * amdtp_out_stream_set_rate(), amdtp_out_stream_set_pcm(),
+ * amdtp_out_stream_set_midi(), and amdtp_out_stream_set_format();
+ * and it must be started before any PCM or MIDI device can be started.
  */
 int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed)
 {
diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
index f6103d6..fd4ce30 100644
--- a/sound/firewire/amdtp.h
+++ b/sound/firewire/amdtp.h
@@ -11,9 +11,13 @@
  *	sample_rate/8000 samples, with rounding up or down to adjust
  *	for clock skew and left-over fractional samples.  This should
  *	be used if supported by the device.
+ * @CIP_BLOCKING: In blocking mode, each packet contains either zero or
+ *	SYT_INTERVAL samples, with these two types alternating so that
+ *	the overall sample rate comes out right.
  */
 enum cip_out_flags {
-	CIP_NONBLOCKING = 0,
+	CIP_NONBLOCKING	= 0x00,
+	CIP_BLOCKING	= 0x01,
 };

 /**
@@ -51,6 +55,7 @@ struct amdtp_out_stream {
 				 __be32 *buffer, unsigned int frames);

 	unsigned int syt_interval;
+	unsigned int transfer_delay;
 	unsigned int source_node_id_field;
 	struct iso_packets_buffer buffer;

diff --git a/sound/firewire/dice.c b/sound/firewire/dice.c
index 02c7b5a..63446f8 100644
--- a/sound/firewire/dice.c
+++ b/sound/firewire/dice.c
@@ -942,7 +942,7 @@ static int dice_probe(struct fw_unit *unit, const struct ieee1394_device_id *id)
 		goto err_notification_handler;
 	dice->resources.channels_mask = 0x00000000ffffffffuLL;

-	err = amdtp_out_stream_init(&dice->stream, unit, CIP_NONBLOCKING);
+	err = amdtp_out_stream_init(&dice->stream, unit, CIP_BLOCKING);
 	if (err < 0)
 		goto err_resources;


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk

  parent reply	other threads:[~2013-10-21 19:23 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-21 19:19 [GIT PULL] [00/29] playback-only DICE driver Clemens Ladisch
2013-10-21 19:21 ` [PATCH] [01/29] ALSA: add " Clemens Ladisch
2013-10-21 19:21 ` [PATCH] [02/29] ALSA: dice: optimize bus reset handling Clemens Ladisch
2013-10-21 19:22 ` [PATCH] [03/29] ALSA: dice: allow all sample rates Clemens Ladisch
2013-10-21 19:23 ` [PATCH] [04/29] ALSA: dice: reduce noisy logging Clemens Ladisch
2013-10-21 19:23 ` Clemens Ladisch [this message]
2013-10-21 19:24 ` [PATCH] [06/29] ALSA: dice: fix hang when unplugging a running device Clemens Ladisch
2013-10-21 19:24 ` [PATCH] [07/29] ALSA: dice: implement hwdep device Clemens Ladisch
2013-10-21 19:25 ` [PATCH] [08/29] ALSA: dice: clear device lock when closing " Clemens Ladisch
2013-10-21 19:25 ` [PATCH] [09/29] ALSA: firewire: introduce amdtp_out_stream_running() Clemens Ladisch
2013-10-21 19:26 ` [PATCH] [10/29] ALSA: dice: reorganize interface definitions Clemens Ladisch
2013-10-21 19:26 ` [PATCH] [11/29] ALSA: dice: fix device detection for other vendors Clemens Ladisch
2013-10-21 19:27 ` [PATCH] [12/29] ALSA: dice: support dual-wire stream format at 192 kHz Clemens Ladisch
2013-10-21 19:27 ` [PATCH] [13/29] ALSA: dice: optimize reading of consecutive registers Clemens Ladisch
2013-10-21 19:28 ` [PATCH] [14/29] ALSA: firewire: extend snd_fw_transaction() Clemens Ladisch
2013-10-21 19:29 ` [PATCH] [15/29] ALSA: dice: avoid superflous write at bus reset Clemens Ladisch
2013-10-21 19:29 ` [PATCH] [16/29] ALSA: dice: remove 10s period length limit Clemens Ladisch
2013-10-21 19:30 ` [PATCH] [17/29] ALSA: dice: remove superfluous field Clemens Ladisch
2013-10-21 19:31 ` [PATCH] [18/29] ALSA: dice: fix locking Clemens Ladisch
2013-10-21 19:31 ` [PATCH] [19/29] ALSA: dice: make amdtp_rates[] const Clemens Ladisch
2013-10-21 19:32 ` [PATCH] [20/29] ALSA: dice: get clock capabilities Clemens Ladisch
2013-10-21 19:32 ` [PATCH] [21/29] ALSA: dice: allow notifications during initialization Clemens Ladisch
2013-10-21 19:33 ` [PATCH] [22/29] ALSA: dice: get rate-dependent parameters Clemens Ladisch
2013-10-21 19:34 ` [PATCH] [23/29] ALSA: dice: dynamic sample rate selection Clemens Ladisch
2013-10-21 19:34 ` [PATCH] [24/29] ALSA: dice: check clock change timeout Clemens Ladisch
2013-10-21 19:34 ` [PATCH] [25/29] ALSA: dice: add a proc file to show device information Clemens Ladisch
2013-10-21 19:35 ` [PATCH] [26/29] ALSA: dice: document quadlet alignment Clemens Ladisch
2013-10-21 19:40 ` [PATCH] [27/29] ALSA: dice: dice_proc_read: remove wrong typecast Clemens Ladisch
2013-10-21 19:41 ` [PATCH] [28/29] ALSA: dice: fix detection of Weiss devices Clemens Ladisch
2013-10-21 19:42 ` [PATCH] [29/29] ALSA: dice: restrict the driver to playback-only devices Clemens Ladisch
2013-10-24  9:39 ` [GIT PULL] [00/29] playback-only DICE driver 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=52657F44.7070203@ladisch.de \
    --to=clemens@ladisch.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=linux1394-devel@lists.sourceforge.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.