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.sourceforge.net
Subject: [PATCH 12/30] ALSA: dice: Support for non SYT-Match sampling clock source mode
Date: Sat, 29 Nov 2014 00:59:21 +0900	[thread overview]
Message-ID: <1417190379-4172-13-git-send-email-o-takashi@sakamocchi.jp> (raw)
In-Reply-To: <1417190379-4172-1-git-send-email-o-takashi@sakamocchi.jp>

This commit allows this driver to handle devices with non SYT-Match
sampling clock source.

When sampling clock source is SYT-Match mode, devices handle
'presentation timestamp' in received packets and generates sampling clock
according to the information. In this case, driver is synchronization master
and must transfer correct value in SYT field of each packets in outgoing
stream, then the outgoing stream is a master stream.

On the other hand, non SYT-Match mode, devices do this. So drivers must pick
up the value in SYT field of incoming packets and use the value for outgoing
stream. Currently firewire-lib module achieve this work.

Furthermore, without SYT-Match and internal clock source, the sampling rate
should be fixed for the other devices connected to the handled device. This
commit add a restriction of sampling rate at this situation.

With these implementations, this driver has no need to set clock source.
This commit remove set function.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 sound/firewire/dice/dice-pcm.c         | 35 ++++++++++++++++++++++++++++++++++
 sound/firewire/dice/dice-stream.c      | 35 ++++++++++++++++++++++------------
 sound/firewire/dice/dice-transaction.c |  5 -----
 sound/firewire/dice/dice.h             |  2 --
 4 files changed, 58 insertions(+), 19 deletions(-)

diff --git a/sound/firewire/dice/dice-pcm.c b/sound/firewire/dice/dice-pcm.c
index b9ce026..062b7a3 100644
--- a/sound/firewire/dice/dice-pcm.c
+++ b/sound/firewire/dice/dice-pcm.c
@@ -140,6 +140,8 @@ end:
 static int pcm_open(struct snd_pcm_substream *substream)
 {
 	struct snd_dice *dice = substream->private_data;
+	unsigned int source, rate;
+	bool internal;
 	int err;
 
 	err = snd_dice_stream_lock_try(dice);
@@ -149,6 +151,39 @@ static int pcm_open(struct snd_pcm_substream *substream)
 	err = init_hw_info(dice, substream);
 	if (err < 0)
 		goto err_locked;
+
+	err = snd_dice_transaction_get_clock_source(dice, &source);
+	if (err < 0)
+		goto err_locked;
+	switch (source) {
+	case CLOCK_SOURCE_AES1:
+	case CLOCK_SOURCE_AES2:
+	case CLOCK_SOURCE_AES3:
+	case CLOCK_SOURCE_AES4:
+	case CLOCK_SOURCE_AES_ANY:
+	case CLOCK_SOURCE_ADAT:
+	case CLOCK_SOURCE_TDIF:
+	case CLOCK_SOURCE_WC:
+		internal = false;
+		break;
+	default:
+		internal = true;
+		break;
+	}
+
+	/*
+	 * When source of clock is not internal, available sampling rate is
+	 * limited at current sampling rate.
+	 */
+	if (!internal) {
+		err = snd_dice_transaction_get_rate(dice, &rate);
+		if (err < 0)
+			goto err_locked;
+		substream->runtime->hw.rate_min = rate;
+		substream->runtime->hw.rate_max = rate;
+	}
+
+	snd_pcm_set_sync(substream);
 end:
 	return err;
 err_locked:
diff --git a/sound/firewire/dice/dice-stream.c b/sound/firewire/dice/dice-stream.c
index e60b84d..20765a0 100644
--- a/sound/firewire/dice/dice-stream.c
+++ b/sound/firewire/dice/dice-stream.c
@@ -161,9 +161,29 @@ end:
 
 static int get_sync_mode(struct snd_dice *dice, enum cip_flags *sync_mode)
 {
-	/* Currently, clock source is fixed at SYT-Match mode. */
-	*sync_mode = 0;
-	return 0;
+	u32 source;
+	int err;
+
+	err = snd_dice_transaction_get_clock_source(dice, &source);
+	if (err < 0)
+		goto end;
+
+	switch (source) {
+	/* So-called 'SYT Match' modes, sync_to_syt value of packets received */
+	case CLOCK_SOURCE_ARX4:	/* in 4th stream */
+	case CLOCK_SOURCE_ARX3:	/* in 3rd stream */
+	case CLOCK_SOURCE_ARX2:	/* in 2nd stream */
+		err = -ENOSYS;
+		break;
+	case CLOCK_SOURCE_ARX1:	/* in 1st stream, which this driver uses */
+		*sync_mode = 0;
+		break;
+	default:
+		*sync_mode = CIP_SYNC_TO_DEVICE;
+		break;
+	}
+end:
+	return err;
 }
 
 int snd_dice_stream_start_duplex(struct snd_dice *dice, unsigned int rate)
@@ -310,15 +330,6 @@ int snd_dice_stream_init_duplex(struct snd_dice *dice)
 		goto end;
 
 	err = init_stream(dice, &dice->rx_stream);
-	if (err < 0)
-		goto end;
-
-	/* Currently, clock source is fixed at SYT-Match mode. */
-	err = snd_dice_transaction_set_clock_source(dice, CLOCK_SOURCE_ARX1);
-	if (err < 0) {
-		destroy_stream(dice, &dice->rx_stream);
-		destroy_stream(dice, &dice->tx_stream);
-	}
 end:
 	return err;
 }
diff --git a/sound/firewire/dice/dice-transaction.c b/sound/firewire/dice/dice-transaction.c
index a9b98e0..b128ee3 100644
--- a/sound/firewire/dice/dice-transaction.c
+++ b/sound/firewire/dice/dice-transaction.c
@@ -137,11 +137,6 @@ int snd_dice_transaction_get_clock_source(struct snd_dice *dice,
 
 	return err;
 }
-int snd_dice_transaction_set_clock_source(struct snd_dice *dice,
-					  unsigned int source)
-{
-	return set_clock_info(dice, UINT_MAX, source);
-}
 
 int snd_dice_transaction_get_rate(struct snd_dice *dice, unsigned int *rate)
 {
diff --git a/sound/firewire/dice/dice.h b/sound/firewire/dice/dice.h
index a62ee22..f30326e 100644
--- a/sound/firewire/dice/dice.h
+++ b/sound/firewire/dice/dice.h
@@ -152,8 +152,6 @@ static inline int snd_dice_transaction_read_sync(struct snd_dice *dice,
 					 buf, len);
 }
 
-int snd_dice_transaction_set_clock_source(struct snd_dice *dice,
-					  unsigned int source);
 int snd_dice_transaction_get_clock_source(struct snd_dice *dice,
 					  unsigned int *source);
 int snd_dice_transaction_set_rate(struct snd_dice *dice, unsigned int rate);
-- 
2.1.0

  parent reply	other threads:[~2014-11-28 15:59 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-28 15:59 [PATCH 00/30 v3] ALSA: Enhancement for existed FireWire drivers Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 01/30] ALSA: dice: suppress checkpatch.pl warnings Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 02/30] ALSA: dice: Rename structure and its members Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 03/30] ALSA: dice: Move file to its own directory Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 04/30] ALSA: dice: Split transaction functionality into a file Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 05/30] ALSA: dice: Split stream " Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 06/30] ALSA: dice: Split PCM " Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 07/30] ALSA: dice: Split hwdep " Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 08/30] ALSA: dice: Split proc interface " Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 09/30] ALSA: dice: Add new functions for constraints of PCM parameters Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 10/30] ALSA: dice: Change the way to start stream Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 11/30] ALSA: dice: Add support for duplex streams with synchronization Takashi Sakamoto
2014-11-28 15:59 ` Takashi Sakamoto [this message]
2014-11-28 15:59 ` [PATCH 13/30] ALSA: dice: Add support for capturing PCM samples Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 14/30] ALSA: dice: Add support for MIDI capture/playback Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 15/30] ALSA: dice: remove experimental state Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 16/30] ALSA: speakers: Rename to oxfw and rename some members Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 17/30] ALSA: oxfw: Move to its own directory Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 18/30] ALSA: oxfw: Split stream functionality to a new file and add a header file Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 19/30] ALSA: oxfw: Split PCM functionality to a new file Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 20/30] ALSA: oxfw: Split control " Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 21/30] ALSA: oxfw: Change the way to name card Takashi Sakamoto
2014-11-29 19:37   ` Takashi Iwai
2014-11-30  4:33     ` Takashi Sakamoto
2014-11-30  8:31       ` Takashi Iwai
2014-11-30 23:19         ` Takashi Sakamoto
2014-12-01  8:41           ` Takashi Iwai
2014-12-01 11:21             ` Clemens Ladisch
2014-12-01 15:05               ` Takashi Sakamoto
2014-12-01 15:21                 ` Takashi Iwai
2014-12-02  6:17                   ` Takashi Sakamoto
2014-12-02  6:41                     ` Takashi Iwai
2014-12-03 14:19                       ` Takashi Sakamoto
2014-12-01 14:58             ` Takashi Sakamoto
2014-12-01 15:22               ` Takashi Iwai
2014-11-28 15:59 ` [PATCH 22/30] ALSA: oxfw: Add support for AV/C stream format command to get/set supported stream formation Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 23/30] ALSA: oxfw: Change the way to make PCM rules/constraints Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 24/30] ALSA: oxfw: Add proc interface for debugging purpose Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 25/30] ALSA: oxfw: Change the way to start stream Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 26/30] ALSA: oxfw: Add support for Behringer/Mackie devices Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 27/30] ALSA: oxfw: Add support AMDTP in-stream Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 28/30] ALSA: oxfw: add support for capturing PCM samples Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 29/30] ALSA: oxfw: Add support for capture/playback MIDI messages Takashi Sakamoto
2014-11-28 15:59 ` [PATCH 30/30] ALSA: oxfw: Add hwdep interface Takashi Sakamoto
2014-11-28 16:03 ` [PATCH alsa-lib] hwdep: add OXFW driver support Takashi Sakamoto
2014-11-29 19:35 ` [PATCH 00/30 v3] ALSA: Enhancement for existed FireWire drivers Takashi Iwai
2014-11-30  3:21   ` Takashi Sakamoto
2014-11-30  8:35     ` 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=1417190379-4172-13-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.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.