From patchwork Sat Oct 4 11:27:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 5032341 X-Patchwork-Delegate: tiwai@suse.de Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A58FBC11AB for ; Sat, 4 Oct 2014 11:33:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A758D201F5 for ; Sat, 4 Oct 2014 11:33:46 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id DF5592017E for ; Sat, 4 Oct 2014 11:33:43 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id C399B261B02; Sat, 4 Oct 2014 13:33:42 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id BF8682605C6; Sat, 4 Oct 2014 13:28:22 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 2FB9D2605B7; Sat, 4 Oct 2014 13:28:21 +0200 (CEST) Received: from smtp310.phy.lolipop.jp (smtp310.phy.lolipop.jp [210.157.22.78]) by alsa0.perex.cz (Postfix) with ESMTP id 07B83260568 for ; Sat, 4 Oct 2014 13:27:47 +0200 (CEST) Received: from smtp310.phy.lolipop.lan (HELO smtp310.phy.lolipop.jp) (172.17.1.10) (smtp-auth username m12129643-o-takashi, mechanism plain) by smtp310.phy.lolipop.jp (qpsmtpd/0.82) with ESMTPA; Sat, 04 Oct 2014 20:27:45 +0900 Received: from 127.0.0.1 (127.0.0.1) by smtp310.phy.lolipop.jp (LOLIPOP-Fsecure); Sat, 04 Oct 2014 20:27:25 +0900 (JST) X-Virus-Status: clean(LOLIPOP-Fsecure) From: Takashi Sakamoto To: clemens@ladisch.de Date: Sat, 4 Oct 2014 20:27:21 +0900 Message-Id: <1412422044-15133-12-git-send-email-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1412422044-15133-1-git-send-email-o-takashi@sakamocchi.jp> References: <1412422044-15133-1-git-send-email-o-takashi@sakamocchi.jp> Cc: alsa-devel@alsa-project.org, ffado-devel@lists.sourceforge.net Subject: [alsa-devel] [PATCH 11/14] ALSA: dice: Support for non SYT-Match sampling clock source mode X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP This commit allows another mode. 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. Signed-off-by: Takashi Sakamoto --- sound/firewire/dice/dice-pcm.c | 37 ++++++++++++++++++++++++++++++++++ sound/firewire/dice/dice-stream.c | 35 +++++++++++++++++++++----------- sound/firewire/dice/dice-transaction.c | 5 ----- sound/firewire/dice/dice.h | 2 -- 4 files changed, 60 insertions(+), 19 deletions(-) diff --git a/sound/firewire/dice/dice-pcm.c b/sound/firewire/dice/dice-pcm.c index 78b5408..a0dbe0c 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,41 @@ 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 or any PCM streams are running, + * available sampling rate is limited at current sampling rate. + */ + if (!internal || + amdtp_stream_pcm_running(&dice->tx_stream) || + amdtp_stream_pcm_running(&dice->rx_stream)) { + 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 2ca62ce..c95709e 100644 --- a/sound/firewire/dice/dice-stream.c +++ b/sound/firewire/dice/dice-stream.c @@ -160,9 +160,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) @@ -316,15 +336,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 0f4b52a..01d25bf 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 a868485..8ea5cb4 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);