From patchwork Sun Jun 2 07:12:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 10971635 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2E79815E6 for ; Sun, 2 Jun 2019 07:21:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1116F28C13 for ; Sun, 2 Jun 2019 07:21:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 00C1B28C1A; Sun, 2 Jun 2019 07:21:48 +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,DKIM_SIGNED, DKIM_VALID,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]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2544628C13 for ; Sun, 2 Jun 2019 07:21:48 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 6B7B316B0; Sun, 2 Jun 2019 09:20:56 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 6B7B316B0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1559460106; bh=ANqMK8+SyO/CSP34TSXc6IwgyYyGveLBAmLRzeXj4Qs=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=LmwsbnN0SD7WHUfRJdVdNhvrv+KJf8oNYo77hDxedx0KeuIDz2b8sZD3jg88X9Mqe Iej5XKw+X9HUDIDNS63URN3+sfnDUdudE6DEES4j2QAOKRDqWgwxZXDYrrH870EEOf QgkLjNIWsa8UXUDgvgfeCPKHLeQYrRdZeCmSPbps= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 2F866F89766; Sun, 2 Jun 2019 09:13:34 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 0C320F89747; Sun, 2 Jun 2019 09:13:26 +0200 (CEST) Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 9DAE0F89741 for ; Sun, 2 Jun 2019 09:13:22 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 9DAE0F89741 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="XQp7Y2aX"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="2M9azKIa" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id CFC2A20F20; Sun, 2 Jun 2019 03:13:21 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Sun, 02 Jun 2019 03:13:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=Xbb1CG0Jn8goX byP+1GxDWb5KC8a0RvlIjE/hZHan+w=; b=XQp7Y2aXXd8FFcXhPwVZq6rvD6US8 KeyshCY1BNqNBYDy/zuVBRfDyBr9/7J3v9S4s9lsJ8ca28gm1QoWZJVwYEZyHOfQ 8fbKxtZuqCD+HLQhoUFp821z/MlNPqm21hcHtBRaJ9Lpy0c6NyjKwOeZKx68Lqv1 s15S+ETHr3eWin8p1MQXWX4cQXt7OHW9S3cVGLu+ynNmnYCalWuneMxBumZXhhGT 7a+tZwV3EtDgpVh0OrMvQcKMvM5+YXunF92tbYtPlH6BG0FNcvwYPhBYYAlJ6LP4 ieTfocbObuGrJ4l34+u3wazDHHtsCsLu2ju8kWMq+eGxZO2jpmqkJZvpg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=Xbb1CG0Jn8goXbyP+1GxDWb5KC8a0RvlIjE/hZHan+w=; b=2M9azKIa EKZkm7GaoQkYRSJvSO6qPMPvsmfIfw/NDosJ7W7ytk3yzkbjTaQL3IQc6sBqWvk/ aFA8v2eQNk4qQ7mA1haoSDwYTuRyEhTFxJf8mhs8f7G+bWNQR8uShorIM5kMz2Vs Jr5jj/1Hz9yJyojBfHEun8EHpM64c9jAg48zb/CuRmON3vDUVEx9LQhJeEAIo9Ch XBPcn4OJYc3esVmMmYGgGpYOOABqJSgz49iNWUhWgbb6CL/sF8ip++vfcvZNWS9A hY5wzzV25TVeVvMPnrBcvKU3WxYiZ8Ya+M5mjNoQRCTfDP5D2BKFTa4/183dEtZ7 lZjOFOVi/BCrOQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddrudefgedguddvtdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpefvrghkrghshhhiucfurghkrghmohhtohcuoehoqdhtrghk rghshhhisehsrghkrghmohgttghhihdrjhhpqeenucfkphepudegrdefrdejhedrudekud enucfrrghrrghmpehmrghilhhfrhhomhepohdqthgrkhgrshhhihesshgrkhgrmhhotggt hhhirdhjphenucevlhhushhtvghrufhiiigvpeef X-ME-Proxy: Received: from workstation.flets-east.jp (ae075181.dynamic.ppp.asahi-net.or.jp [14.3.75.181]) by mail.messagingengine.com (Postfix) with ESMTPA id 654DB80059; Sun, 2 Jun 2019 03:13:20 -0400 (EDT) From: Takashi Sakamoto To: clemens@ladisch.de, tiwai@suse.de Date: Sun, 2 Jun 2019 16:12:55 +0900 Message-Id: <20190602071259.21622-12-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190602071259.21622-1-o-takashi@sakamocchi.jp> References: <20190602071259.21622-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH 11/15] ALSA: fireface: support allocate_resources operation in latter protocol X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" X-Virus-Scanned: ClamAV using ClamSMTP This commit is a part of preparation to perform allocation/release of isochronous channels in pcm.hw_params/hw_free callbacks. This commit implements allocate_resources callback for the protocol specific to latter models. The encoded values of constant table is split into several condition statements to separate the operation to configure sampling transfer frequency from the operation to configure the number of data channels in rx packet. Signed-off-by: Takashi Sakamoto --- sound/firewire/fireface/ff-protocol-latter.c | 113 +++++++++---------- 1 file changed, 56 insertions(+), 57 deletions(-) diff --git a/sound/firewire/fireface/ff-protocol-latter.c b/sound/firewire/fireface/ff-protocol-latter.c index c8236ff89b7f..3d12ba5b2a9b 100644 --- a/sound/firewire/fireface/ff-protocol-latter.c +++ b/sound/firewire/fireface/ff-protocol-latter.c @@ -97,25 +97,64 @@ static int latter_switch_fetching_mode(struct snd_ff *ff, bool enable) LATTER_FETCH_MODE, ®, sizeof(reg), 0); } -static int keep_resources(struct snd_ff *ff, unsigned int rate) +static int latter_allocate_resources(struct snd_ff *ff, unsigned int rate) { enum snd_ff_stream_mode mode; + unsigned int code; + __le32 reg; + unsigned int count; int i; int err; - // Check whether the given value is supported or not. - for (i = 0; i < CIP_SFC_COUNT; i++) { - if (amdtp_rate_table[i] == rate) + // Set the number of data blocks transferred in a second. + if (rate % 32000 == 0) + code = 0x00; + else if (rate % 44100 == 0) + code = 0x02; + else if (rate % 48000 == 0) + code = 0x04; + else + return -EINVAL; + + if (rate >= 64000 && rate < 128000) + code |= 0x08; + else if (rate >= 128000 && rate < 192000) + code |= 0x10; + + reg = cpu_to_le32(code); + err = snd_fw_transaction(ff->unit, TCODE_WRITE_QUADLET_REQUEST, + LATTER_STF, ®, sizeof(reg), 0); + if (err < 0) + return err; + + // Confirm to shift transmission clock. + count = 0; + while (count++ < 10) { + unsigned int curr_rate; + enum snd_ff_clock_src src; + + err = latter_get_clock(ff, &curr_rate, &src); + if (err < 0) + return err; + + if (curr_rate == rate) break; } - if (i >= CIP_SFC_COUNT) + if (count == 10) + return -ETIMEDOUT; + + for (i = 0; i < ARRAY_SIZE(amdtp_rate_table); ++i) { + if (rate == amdtp_rate_table[i]) + break; + } + if (i == ARRAY_SIZE(amdtp_rate_table)) return -EINVAL; err = snd_ff_stream_get_multiplier_mode(i, &mode); if (err < 0) return err; - /* Keep resources for in-stream. */ + // Keep resources for in-stream. ff->tx_resources.channels_mask = 0x00000000000000ffuLL; err = fw_iso_resources_allocate(&ff->tx_resources, amdtp_stream_get_max_payload(&ff->tx_stream), @@ -123,7 +162,7 @@ static int keep_resources(struct snd_ff *ff, unsigned int rate) if (err < 0) return err; - /* Keep resources for out-stream. */ + // Keep resources for out-stream. ff->rx_resources.channels_mask = 0x00000000000000ffuLL; err = fw_iso_resources_allocate(&ff->rx_resources, amdtp_stream_get_max_payload(&ff->rx_stream), @@ -136,61 +175,20 @@ static int keep_resources(struct snd_ff *ff, unsigned int rate) static int latter_begin_session(struct snd_ff *ff, unsigned int rate) { - static const struct { - unsigned int stf; - unsigned int code; - unsigned int flag; - } *entry, rate_table[] = { - { 32000, 0x00, 0x92, }, - { 44100, 0x02, 0x92, }, - { 48000, 0x04, 0x92, }, - { 64000, 0x08, 0x8e, }, - { 88200, 0x0a, 0x8e, }, - { 96000, 0x0c, 0x8e, }, - { 128000, 0x10, 0x8c, }, - { 176400, 0x12, 0x8c, }, - { 192000, 0x14, 0x8c, }, - }; + unsigned int flag; u32 data; __le32 reg; - unsigned int count; - int i; int err; - for (i = 0; i < ARRAY_SIZE(rate_table); ++i) { - entry = rate_table + i; - if (entry->stf == rate) - break; - } - if (i == ARRAY_SIZE(rate_table)) + if (rate >= 32000 && rate <= 48000) + flag = 0x92; + else if (rate >= 64000 && rate <= 96000) + flag = 0x8e; + else if (rate >= 128000 && rate <= 192000) + flag = 0x8c; + else return -EINVAL; - reg = cpu_to_le32(entry->code); - err = snd_fw_transaction(ff->unit, TCODE_WRITE_QUADLET_REQUEST, - LATTER_STF, ®, sizeof(reg), 0); - if (err < 0) - return err; - - // Confirm to shift transmission clock. - count = 0; - while (count++ < 10) { - unsigned int curr_rate; - enum snd_ff_clock_src src; - - err = latter_get_clock(ff, &curr_rate, &src); - if (err < 0) - return err; - - if (curr_rate == rate) - break; - } - if (count == 10) - return -ETIMEDOUT; - - err = keep_resources(ff, rate); - if (err < 0) - return err; - data = (ff->tx_resources.channel << 8) | ff->rx_resources.channel; reg = cpu_to_le32(data); err = snd_fw_transaction(ff->unit, TCODE_WRITE_QUADLET_REQUEST, @@ -200,7 +198,7 @@ static int latter_begin_session(struct snd_ff *ff, unsigned int rate) // Always use the maximum number of data channels in data block of // packet. - reg = cpu_to_le32(entry->flag); + reg = cpu_to_le32(flag); return snd_fw_transaction(ff->unit, TCODE_WRITE_QUADLET_REQUEST, LATTER_ISOC_START, ®, sizeof(reg), 0); } @@ -424,6 +422,7 @@ const struct snd_ff_protocol snd_ff_protocol_latter = { .fill_midi_msg = latter_fill_midi_msg, .get_clock = latter_get_clock, .switch_fetching_mode = latter_switch_fetching_mode, + .allocate_resources = latter_allocate_resources, .begin_session = latter_begin_session, .finish_session = latter_finish_session, .dump_status = latter_dump_status,