From patchwork Fri Apr 26 12:59:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Thomson X-Patchwork-Id: 10919133 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 59F6914D5 for ; Fri, 26 Apr 2019 13:18:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 40F3928B10 for ; Fri, 26 Apr 2019 13:18:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3188728D48; Fri, 26 Apr 2019 13:18:25 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FROM_WORDY,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 2CDF628B10 for ; Fri, 26 Apr 2019 13:18:24 +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 54D1983A; Fri, 26 Apr 2019 14:59:34 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 54D1983A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1556283624; bh=fquBRWxTMnC+JHMlXEBGkvH6NpXKQPe0ernWzs0ss0c=; h=From:Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=OVOx/e9O7zAQsqhEk6CQspepyhmieh0OYgw69ymwj+6e29Gl/y0DxlI/hpqu//q1t oSorDUPRRtFducENs7I5FTljsQ+JOElpgWU+71T9h5m22O5WL588cjSv1T9loW3+h/ xRwNjbcUmFUpzKm4psB1ivUREgo7T10hxUB+gJ0I= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id B13FEF896CC; Fri, 26 Apr 2019 14:59:33 +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 B1399F896DF; Fri, 26 Apr 2019 14:59:31 +0200 (CEST) Received: from mail1.bemta26.messagelabs.com (mail1.bemta26.messagelabs.com [85.158.142.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 12DE7F80C0D for ; Fri, 26 Apr 2019 14:59:27 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 12DE7F80C0D Received: from [85.158.142.194] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-6.bemta.az-b.eu-central-1.aws.symcld.net id 65/D7-19007-EA003CC5; Fri, 26 Apr 2019 12:59:26 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrKIsWRWlGSWpSXmKPExsVy8IPnUd11DId jDH5cFLQ41bKH3eLKxUNMFlMfPmGz+Halg8ni8q45bBadu/pZLTZ8X8vowO6x4XMTm0frpb9s Hjtn3WX32LSqk81j39tlbB7rt1xl8fi8SS6APYo1My8pvyKBNePL1S+MBV/FKnq7j7M1ML4R6 mLk4hASWM8o8eLwRNYuRk4gp0Kid+4BFhCbTcBCYvKJB2wgNouAqsSOPecZQWxhgWCJue1dYD UiAl2MEuePeoMMYhaYzyixbeFVsEG8Ag4Sa64dZYawBSVOznwC1sAsICFx8MULZohlBhKnFzS CxSUE7CWmv78KFOcAsvUlGo/FQoQNJb7P+gZVYi6xb38T2wRG/llIps5CMnUBI9MqRoukosz0 jJLcxMwcXUMDA11DQ2NdE10LS73EKt0kvdRS3eTUvJKiRKCkXmJ5sV5xZW5yTopeXmrJJkZgF KQUskTuYLy0NP0QoyQHk5Iob/2nQzFCfEn5KZUZicUZ8UWlOanFhxhlODiUJHhL/gPlBItS01 Mr0jJzgPEIk5bg4FES4X0CkuYtLkjMLc5Mh0idYtTleNj6eS6zEEtefl6qlDjvApAiAZCijNI 8uBGw1HCJUVZKmJeRgYFBiKcgtSg3swRV/hWjOAejkjDvBpApPJl5JXCbXgEdwQR0RMpKsCNK EhFSUg2MXi/0mU44fV2WvjD4bvPvyQ8+BYQn5Yevesv9sqW34cNODTVRnY6tszx/GdnU+2WzN a4tkNm9vrzo0/2UB/urcrdOO/AjTCPaZ0nuTL50+x77n71fDjFnzOsMEd+5s0495eRNhdXytx xDox1CVkb8vfzFo7C2rf23elR3YL6WEN/+lzZPF/1QYinOSDTUYi4qTgQA3S+hnAgDAAA= X-Env-Sender: Adam.Thomson.Opensource@diasemi.com X-Msg-Ref: server-14.tower-239.messagelabs.com!1556283565!4816085!1 X-Originating-IP: [193.240.73.197] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.31.5; banners=-,-,- X-VirusChecked: Checked Received: (qmail 3143 invoked from network); 26 Apr 2019 12:59:26 -0000 Received: from unknown (HELO sw-ex-cashub01.diasemi.com) (193.240.73.197) by server-14.tower-239.messagelabs.com with AES128-SHA256 encrypted SMTP; 26 Apr 2019 12:59:26 -0000 Received: from swsrvapps-01.diasemi.com (10.20.28.141) by SW-EX-CASHUB01.diasemi.com (10.20.16.140) with Microsoft SMTP Server id 14.3.408.0; Fri, 26 Apr 2019 13:59:25 +0100 Received: by swsrvapps-01.diasemi.com (Postfix, from userid 22379) id 04F3F3FB4A; Fri, 26 Apr 2019 13:59:25 +0100 (BST) From: Adam Thomson Date: Fri, 26 Apr 2019 13:59:24 +0100 To: Mark Brown , Liam Girdwood , Takashi Iwai , Jaroslav Kysela Message-ID: <20190426125925.04F3F3FB4A@swsrvapps-01.diasemi.com> MIME-Version: 1.0 X-KSE-AttachmentFiltering-Interceptor-Info: protection disabled X-KSE-ServerInfo: sw-ex-cashub01.diasemi.com, 9 X-KSE-Antivirus-Interceptor-Info: scan successful X-KSE-Antivirus-Info: Clean, bases: 26/04/2019 09:14:00 Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Support Opensource , Akshu Agrawal Subject: [alsa-devel] [PATCH] ASoC: da7219: Use clk_round_rate to handle enabled bclk/wclk case 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 For some platforms where DA7219 is the DAI clock master, BCLK/WCLK will be set and enabled prior to the codec's hw_params() function being called. It is possible the platform requires a different BCLK/WCLK configuration than would be chosen by hw_params(), for example S16_LE format needed with a 64-bit frame to satisfy certain devices using the clocks. To handle those kinds of scenarios, the use of clk_round_rate() is now employed as part of hw_params(). If BCLK/WCLk are already enabled then this function will just return the currently set rates, so the subsequent calls to clk_set_rate() will succeed and nothing changes with regards to clocking. In addition the specific recalc_rate() implementations needed updating to always give back a real value, as those functions are called as part of the clk init code and a real value is needed for the clk_round_rate() calls to work as expected. Signed-off-by: Adam Thomson --- sound/soc/codecs/da7219.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/sound/soc/codecs/da7219.c b/sound/soc/codecs/da7219.c index 5f5fa34..72268f5 100644 --- a/sound/soc/codecs/da7219.c +++ b/sound/soc/codecs/da7219.c @@ -1593,6 +1593,13 @@ static int da7219_hw_params(struct snd_pcm_substream *substream, sr = params_rate(params); if (da7219->master && wclk) { + /* + * Rounding the rate here avoids failure trying to set a new + * rate on an already enabled wclk. In that instance this will + * just set the same rate as is currently in use, and so should + * continue without problem. + */ + sr = clk_round_rate(wclk, sr); ret = clk_set_rate(wclk, sr); if (ret) { dev_err(component->dev, @@ -1621,6 +1628,14 @@ static int da7219_hw_params(struct snd_pcm_substream *substream, if (bclk) { bclk_rate = frame_size * sr; + /* + * Rounding the rate here avoids failure trying to set a + * new rate on an already enabled bclk. In that + * instance this will just set the same rate as is + * currently in use, and so should continue without + * problem. + */ + bclk_rate = clk_round_rate(bclk, bclk_rate); ret = clk_set_rate(bclk, bclk_rate); if (ret) { dev_err(component->dev, @@ -1927,9 +1942,6 @@ static unsigned long da7219_wclk_recalc_rate(struct clk_hw *hw, struct snd_soc_component *component = da7219->component; u8 fs = snd_soc_component_read32(component, DA7219_SR); - if (!da7219->master) - return 0; - switch (fs & DA7219_SR_MASK) { case DA7219_SR_8000: return 8000; @@ -2016,9 +2028,6 @@ static unsigned long da7219_bclk_recalc_rate(struct clk_hw *hw, u8 bclks_per_wclk = snd_soc_component_read32(component, DA7219_DAI_CLK_MODE); - if (!da7219->master) - return 0; - switch (bclks_per_wclk & DA7219_DAI_BCLKS_PER_WCLK_MASK) { case DA7219_DAI_BCLKS_PER_WCLK_32: return parent_rate * 32;