From patchwork Mon May 9 11:24:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Keeping X-Patchwork-Id: 9045161 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 357079F30C for ; Mon, 9 May 2016 11:25:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 552A420123 for ; Mon, 9 May 2016 11:25:16 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 1AE6520114 for ; Mon, 9 May 2016 11:25:15 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 2915B265928; Mon, 9 May 2016 13:25:14 +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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 06842265593; Mon, 9 May 2016 13:24:55 +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 41D6826578F; Mon, 9 May 2016 13:24:54 +0200 (CEST) Received: from metanate.com (dougal.metanate.com [90.155.101.14]) by alsa0.perex.cz (Postfix) with ESMTP id B232A2606F5 for ; Mon, 9 May 2016 13:24:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=simple/simple; d=metanate.com; s=stronger; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=WbDLMgKz+0L+WWD4u8+G6GhaPrURaqLuCznVyyAZvrQ=; b=LBoQpvzOjFPWOW/H/ODs9faBTrcuS/Ul4Teerh07oZ3wuYP0GR8fQkWRNZNq3c1QhNfwVxPR6b3bxlFjne3Y1vhgc7eZ0sEYsYmvetJ9aDulgIAngSqoxOTnoSP+Xu6jYpH1ilo5tZXTg9vC0Rgl8jbcUaP5OtIfTFaTMWdeLfaAvlUcPk1PekFSOYaF5hLtpTAggUQ4pum8vqgI4pDPH0nkjIfnxIpccoNSg1PGsnJdkaSvEkFWBZuBy/JpPyXXC6/OWZ0ieSpWkbeXtQ+tJYr9tS1sdNQCOj4HuUhC5l6O6e5RhqJxZ7mJRIVH5vwu8Be0T3xXJ9BQlqjLO3I/ZQ==; Received: from brian ([192.168.88.1] helo=leela.metanate.com) by shrek.metanate.com with esmtpsa (TLSv1.2:AES128-SHA256:128) (Exim 4.83_RC2) (envelope-from ) id 1azjIr-0004xp-Kc; Mon, 09 May 2016 12:24:45 +0100 From: John Keeping To: alsa-devel@alsa-project.org Date: Mon, 9 May 2016 12:24:29 +0100 Message-Id: <20160509112437.8924-2-john@metanate.com> X-Mailer: git-send-email 2.8.2.565.gdb84f68.dirty In-Reply-To: <20160509112437.8924-1-john@metanate.com> References: <20160509112437.8924-1-john@metanate.com> Cc: Liam Girdwood , linux-kernel@vger.kernel.org, Takashi Iwai , Mark Brown , John Keeping Subject: [alsa-devel] [PATCH 1/9] ASoC: es8328: Move clock setup to hw_params 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 ensures that the clock is setup after its frequency has been set; the existing code in set_dai_fmt may be called before the clock rate has been set resulting in an incorrect configuration. Signed-off-by: John Keeping --- sound/soc/codecs/es8328.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/sound/soc/codecs/es8328.c b/sound/soc/codecs/es8328.c index afa6c5db9dcc..3ca89ae32889 100644 --- a/sound/soc/codecs/es8328.c +++ b/sound/soc/codecs/es8328.c @@ -445,9 +445,10 @@ static int es8328_hw_params(struct snd_pcm_substream *substream, { struct snd_soc_codec *codec = dai->codec; struct es8328_priv *es8328 = snd_soc_codec_get_drvdata(codec); - int clk_rate; + int clk_rate = clk_get_rate(es8328->clk); int i; int reg; + int val; u8 ratio; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) @@ -455,16 +456,24 @@ static int es8328_hw_params(struct snd_pcm_substream *substream, else reg = ES8328_ADCCONTROL5; - clk_rate = clk_get_rate(es8328->clk); - - if ((clk_rate != ES8328_SYSCLK_RATE_1X) && - (clk_rate != ES8328_SYSCLK_RATE_2X)) { + switch (clk_rate) { + case ES8328_SYSCLK_RATE_1X: + val = 0; + break; + case ES8328_SYSCLK_RATE_2X: + val = ES8328_MASTERMODE_MCLKDIV2; + break; + default: dev_err(codec->dev, "%s: clock is running at %d Hz, not %d or %d Hz\n", __func__, clk_rate, ES8328_SYSCLK_RATE_1X, ES8328_SYSCLK_RATE_2X); return -EINVAL; } + ret = snd_soc_update_bits(codec, ES8328_MASTERMODE, + ES8328_MASTERMODE_MCLKDIV2, val); + if (ret < 0) + return ret; /* find master mode MCLK to sampling frequency ratio */ ratio = mclk_ratios[0].rate; @@ -484,8 +493,6 @@ static int es8328_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) { struct snd_soc_codec *codec = codec_dai->codec; - struct es8328_priv *es8328 = snd_soc_codec_get_drvdata(codec); - int clk_rate; u8 mode = ES8328_DACCONTROL1_DACWL_16; /* set master/slave audio interface */ @@ -515,14 +522,8 @@ static int es8328_set_dai_fmt(struct snd_soc_dai *codec_dai, snd_soc_write(codec, ES8328_ADCCONTROL4, mode); /* Master serial port mode, with BCLK generated automatically */ - clk_rate = clk_get_rate(es8328->clk); - if (clk_rate == ES8328_SYSCLK_RATE_1X) - snd_soc_write(codec, ES8328_MASTERMODE, - ES8328_MASTERMODE_MSC); - else - snd_soc_write(codec, ES8328_MASTERMODE, - ES8328_MASTERMODE_MCLKDIV2 | - ES8328_MASTERMODE_MSC); + snd_soc_update_bits(codec, ES8328_MASTERMODE, + ES8328_MASTERMODE_MSC, ES8328_MASTERMODE_MSC); return 0; }