From patchwork Tue Apr 24 23:42:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 10361271 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E9F3260209 for ; Tue, 24 Apr 2018 23:44:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D86A528DCC for ; Tue, 24 Apr 2018 23:44:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD09128E8F; Tue, 24 Apr 2018 23:44:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00EE028DCC for ; Tue, 24 Apr 2018 23:44:00 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id BA33F26772C; Wed, 25 Apr 2018 01:43:26 +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 7074E267704; Wed, 25 Apr 2018 01:43:24 +0200 (CEST) Received: from mail-pf0-f193.google.com (mail-pf0-f193.google.com [209.85.192.193]) by alsa0.perex.cz (Postfix) with ESMTP id 4E769267714 for ; Wed, 25 Apr 2018 01:43:20 +0200 (CEST) Received: by mail-pf0-f193.google.com with SMTP id l27so13561577pfk.12 for ; Tue, 24 Apr 2018 16:43:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tc2c0lljTXMJaDWg/lzRpYnb9n8+/fkoZWO6RzVlWyg=; b=GUNVn/EaMfXpnF3HP4W7fq9boVx4ihVJChyb++GtxeowkEG1uFMCg+L6pdEbPQsAeI gtCPb0ruZVyTnxpTxZSmZoxuGuvsZsglbkEjijqfgk2YzWXj2qT+0vj7dXUXeIYymn1F 79PMgq5eAsawhv79Es8CjzpKcZ/ZybQguFP5Xvbu3TEAVrfvol8esnDgRW7lFFLUFfgc 7Q33B1ZMUJ5/3ZJ3/WWf/WzXQhx/UnIZHG+9PjJZ105IN6ToREirCyftkZvQHy/7VZEE mOx1CHzWqJxkcStl0wiOjZa/aazevR8CMVWI/HgH/G9wQUVSjl9Y52WnR3LAMka9r+xY rpwg== X-Gm-Message-State: ALQs6tDHn6AGsq8n/hVC5nx7cETwJUP1s0pTCL17+cbVhxGxuVO3tM73 NVBG2h07bpes89XLQz41V7g= X-Google-Smtp-Source: AIpwx4+3J0UPdmQTuQ33rTzI2jhdY+NN4/USFOY+E+3Ew8tPw8GuMDrqki5ErmRiCjy6pD7N3Qg8/g== X-Received: by 2002:a17:902:69c5:: with SMTP id m5-v6mr26472873pln.358.1524613399645; Tue, 24 Apr 2018 16:43:19 -0700 (PDT) Received: from localhost.localdomain (i196238.dynamic.ppp.asahi-net.or.jp. [61.125.196.238]) by smtp.gmail.com with ESMTPSA id o4sm5339792pfg.129.2018.04.24.16.43.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Apr 2018 16:43:18 -0700 (PDT) From: Takashi Sakamoto To: clemens@ladisch.de, tiwai@suse.de Date: Wed, 25 Apr 2018 08:42:28 +0900 Message-Id: <20180424234234.6063-6-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180424234234.6063-1-o-takashi@sakamocchi.jp> References: <20180424234234.6063-1-o-takashi@sakamocchi.jp> Cc: alsa-devel@alsa-project.org, ffado-devel@lists.sourceforge.net Subject: [alsa-devel] [PATCH 05/11] ALSA: dice: enable to change current sampling transmission frequency 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 is a preparation for userspace applications to change current sampling transmission frequency via ALSA PCM interface. Signed-off-by: Takashi Sakamoto --- sound/firewire/dice/dice-stream.c | 44 +++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/sound/firewire/dice/dice-stream.c b/sound/firewire/dice/dice-stream.c index e22896aaf346..92f3c345fa59 100644 --- a/sound/firewire/dice/dice-stream.c +++ b/sound/firewire/dice/dice-stream.c @@ -52,19 +52,32 @@ int snd_dice_stream_get_rate_mode(struct snd_dice *dice, unsigned int rate, * This operation has an effect to synchronize GLOBAL_STATUS/GLOBAL_SAMPLE_RATE * to GLOBAL_STATUS. Especially, just after powering on, these are different. */ -static int ensure_phase_lock(struct snd_dice *dice) +static int ensure_phase_lock(struct snd_dice *dice, unsigned int rate) { __be32 reg, nominal; + u32 data; + int i; int err; err = snd_dice_transaction_read_global(dice, GLOBAL_CLOCK_SELECT, ®, sizeof(reg)); if (err < 0) return err; + data = be32_to_cpu(reg); + + data &= ~CLOCK_RATE_MASK; + for (i = 0; i < ARRAY_SIZE(snd_dice_rates); ++i) { + if (snd_dice_rates[i] == rate) + break; + } + if (i == ARRAY_SIZE(snd_dice_rates)) + return -EINVAL; + data |= i << CLOCK_RATE_SHIFT; if (completion_done(&dice->clock_accepted)) reinit_completion(&dice->clock_accepted); + reg = cpu_to_be32(data); err = snd_dice_transaction_write_global(dice, GLOBAL_CLOCK_SELECT, ®, sizeof(reg)); if (err < 0) @@ -210,6 +223,7 @@ static int start_streams(struct snd_dice *dice, enum amdtp_stream_direction dir, unsigned int rate, struct reg_params *params) { __be32 reg[2]; + unsigned int mode; unsigned int i, pcm_chs, midi_ports; struct amdtp_stream *streams; struct fw_iso_resources *resources; @@ -224,12 +238,23 @@ static int start_streams(struct snd_dice *dice, enum amdtp_stream_direction dir, resources = dice->rx_resources; } + err = snd_dice_stream_get_rate_mode(dice, rate, &mode); + if (err < 0) + return err; + for (i = 0; i < params->count; i++) { + unsigned int pcm_cache; + unsigned int midi_cache; + if (dir == AMDTP_IN_STREAM) { + pcm_cache = dice->tx_channels[i][mode]; + midi_cache = dice->tx_midi_ports[i]; err = snd_dice_transaction_read_tx(dice, params->size * i + TX_NUMBER_AUDIO, reg, sizeof(reg)); } else { + pcm_cache = dice->rx_channels[i][mode]; + midi_cache = dice->rx_midi_ports[i]; err = snd_dice_transaction_read_rx(dice, params->size * i + RX_NUMBER_AUDIO, reg, sizeof(reg)); @@ -239,6 +264,14 @@ static int start_streams(struct snd_dice *dice, enum amdtp_stream_direction dir, pcm_chs = be32_to_cpu(reg[0]); midi_ports = be32_to_cpu(reg[1]); + /* These are important for developer of this driver. */ + if (pcm_chs != pcm_cache || midi_ports != midi_cache) { + dev_info(&dice->unit->device, + "cache mismatch: pcm: %u:%u, midi: %u:%u\n", + pcm_chs, pcm_cache, midi_ports, midi_cache); + return -EPROTO; + } + err = keep_resources(dice, dir, i, rate, pcm_chs, midi_ports); if (err < 0) return err; @@ -300,10 +333,9 @@ int snd_dice_stream_start_duplex(struct snd_dice *dice, unsigned int rate) "fail to get sampling rate\n"); return err; } - if (rate == 0) + + if (rate != 0) rate = curr_rate; - if (rate != curr_rate) - return -EINVAL; /* Judge to need to restart streams. */ for (i = 0; i < MAX_STREAMS; i++) { @@ -318,7 +350,7 @@ int snd_dice_stream_start_duplex(struct snd_dice *dice, unsigned int rate) break; } } - need_to_start = (i < MAX_STREAMS); + need_to_start = (rate != curr_rate || i < MAX_STREAMS); if (need_to_start) { /* Stop transmission. */ @@ -327,7 +359,7 @@ int snd_dice_stream_start_duplex(struct snd_dice *dice, unsigned int rate) stop_streams(dice, AMDTP_OUT_STREAM, &rx_params); release_resources(dice); - err = ensure_phase_lock(dice); + err = ensure_phase_lock(dice, rate); if (err < 0) { dev_err(&dice->unit->device, "fail to ensure phase lock\n");