Received: by 10.223.176.46 with SMTP id f43csp801615wra; Wed, 24 Jan 2018 06:13:02 -0800 (PST) X-Google-Smtp-Source: AH8x225lwIPFNqg1RrMG/RUqwyLIl3XdVrZz/nbbRZwBO/Hb3vlPVxrw+EmRcr0TyUCOPERZ+2/o X-Received: by 10.98.86.19 with SMTP id k19mr13047253pfb.71.1516803182000; Wed, 24 Jan 2018 06:13:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516803181; cv=none; d=google.com; s=arc-20160816; b=ehN9Gyv+nlXDiHSeIkM+07Mr/84MiWxAWsAlK4nODzzQktwDWZUDWUUEiLgcvp6M9m +rS85nWWO5kdIVx/Wzph5XpNZcVHWuDuRY8rYyxBol7VIGSseynftCZcyNaBt4bnxGRb t1I4WwpJ31wdf8LtY1vbMMe7Mbo3HIZoQnmfIMClDcQAy78/jq9R3NdDXt3E+bcbWV7r iIZ+mAR7GtWq3D1YdGBcgX7zDf32aQFmEjRVK8LSf6LzAnKFLnsw57+5TKIx8hEscBZe 3Ra61BiOflFtqHfGIthuolkGVTRjGKGIz4fkBuSgUaAxYHA0VYvJF46WrwyKkUnvboKx Xa5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=f1ceExQKWOC8n0a+sSO2Q5+NeaU83gQTST1JtBT+8+M=; b=0d3lzX8UgtWbBZCBuwC6Qse0QLhsaHkBnIg79/L0ooG3G/7cDL8mwD+FCT0AMoNtLe MGyl5fA751RFptnikkyf+ydKeKAd2NXoT+Qi+vQ8VsluGqaGuJkRHWIeGY3iKDvdT2bh lcALCzirdfudI0gAUAFCiqz9Ju9cphazN9dHVnu7hbgOUBFJgdB4LeVrVNOBxSgmN3Jz cLsmdmyfz46AUSkyD6gOvLwpw7w5mggwyGR5g1zBDhrVtvKErFePb0XelfUV1OU9oRAt eFO6y8cx79y9TSJ07+QnFtE42wNVsvnudxIpXIgNnY5zEUdxy1MIGYudUFYI1iHM6w1q oUJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=A+2Km8JG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 8-v6si271029pla.105.2018.01.24.06.12.48; Wed, 24 Jan 2018 06:13:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=A+2Km8JG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934001AbeAXOLg (ORCPT + 99 others); Wed, 24 Jan 2018 09:11:36 -0500 Received: from mail-lf0-f65.google.com ([209.85.215.65]:41641 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933648AbeAXOLH (ORCPT ); Wed, 24 Jan 2018 09:11:07 -0500 Received: by mail-lf0-f65.google.com with SMTP id f136so5396834lff.8 for ; Wed, 24 Jan 2018 06:11:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=f1ceExQKWOC8n0a+sSO2Q5+NeaU83gQTST1JtBT+8+M=; b=A+2Km8JGVuXrZQNTTvQrUTjkVcG9cT2BkW00d7v0vH521wThRppKxaMLBU94M0gfsU gV0t8hqh2sQoOgCulPgkSkrny6G55Hmc0rdSCHIOnOUEeNI89/7RO2TMlQuiGXh1C/3E Bprq0Ro3gb9i0uE/u9eJoompkYPK9RLjXWUVXpEMmuOH6r3oq6YyXSHMvcttla3hS8Xu n7ThkyWKD6424ZT56BzeK44ah9ooUTGYPxy2bIaKKQi/VcG3wR59VFzJ1Y9WsVL45fqQ B6MNYPC+V5cG9PxcoBvNnJhKKc+/CffqtbE0qBuuZ71puOLSg6//BBdf3oMU7fG45K5g 7G6w== 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=f1ceExQKWOC8n0a+sSO2Q5+NeaU83gQTST1JtBT+8+M=; b=jOVOlxKbV2fKkG9pY8ELHZnSaLutpG9jOUcIj/L4xzDwmRS1ScdUFgv9V20Gk1TR3m KTyYhshWLQn2ViPEOXZqdOfbv9DLCpGRc3kPIJbt/eVdmG1eCn7naNy7JIxtVPYNTaMx AJYNtQbd3HFg18JlftJLLXWj8dCmspnOHp/RsPYtjMS5I5HSinnOqQFKOJXqp5V85atV dgMxASRmX2I2jC7loePc3ChH1cLoIjpucDvSkdgIDtuVsxYoEim4w0Vy8RKSb0ZV5r4/ FF+dS+8Mo1e+XyxEO9YhFvypVwLA3xZEbm7x1XmEAAbEgmn3X/h/Qn2n+enNU7QMdQqi nUSg== X-Gm-Message-State: AKwxyten1HYcAPOt14VUGkARMMeHv4v+OfGadBGaeFEc1Zc1P1MF+Kaj RCjK82qVVOFGeDNas5Hpz9k= X-Received: by 10.46.68.133 with SMTP id b5mr3873665ljf.62.1516803065956; Wed, 24 Jan 2018 06:11:05 -0800 (PST) Received: from localhost.localdomain (c80-217-9-219.bredband.comhem.se. [80.217.9.219]) by smtp.gmail.com with ESMTPSA id r84sm579227lff.72.2018.01.24.06.11.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Jan 2018 06:11:05 -0800 (PST) From: codekipper@gmail.com To: maxime.ripard@free-electrons.com Cc: linux-arm-kernel@lists.infradead.org, linux-sunxi@googlegroups.com, lgirdwood@gmail.com, broonie@kernel.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, be17068@iperbole.bo.it, Marcus Cooper Subject: [PATCH 2/3] ASoC: sun4i-i2s: Do not divide clocks when slave Date: Wed, 24 Jan 2018 15:11:00 +0100 Message-Id: <20180124141101.12867-3-codekipper@gmail.com> X-Mailer: git-send-email 2.16.0 In-Reply-To: <20180124141101.12867-1-codekipper@gmail.com> References: <20180124141101.12867-1-codekipper@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marcus Cooper There is no need to set the clock and calculate the division of the audio pll for the bclk and sync signals when they are not required. Signed-off-by: Marcus Cooper --- sound/soc/sunxi/sun4i-i2s.c | 116 ++++++++++++++++++++++++-------------------- 1 file changed, 64 insertions(+), 52 deletions(-) diff --git a/sound/soc/sunxi/sun4i-i2s.c b/sound/soc/sunxi/sun4i-i2s.c index d7a9141514cf..626679057d0f 100644 --- a/sound/soc/sunxi/sun4i-i2s.c +++ b/sound/soc/sunxi/sun4i-i2s.c @@ -195,6 +195,8 @@ struct sun4i_i2s { const struct sun4i_i2s_quirks *variant; + bool bit_clk_master; + unsigned int tdm_slots; unsigned int slot_width; }; @@ -282,67 +284,73 @@ static int sun4i_i2s_set_clk_rate(struct snd_soc_dai *dai, int bclk_div, mclk_div; int ret; - switch (rate) { - case 176400: - case 88200: - case 44100: - case 22050: - case 11025: - clk_rate = 22579200; - break; + if (i2s->bit_clk_master) { + switch (rate) { + case 176400: + case 88200: + case 44100: + case 22050: + case 11025: + clk_rate = 22579200; + break; - case 192000: - case 128000: - case 96000: - case 64000: - case 48000: - case 32000: - case 24000: - case 16000: - case 12000: - case 8000: - clk_rate = 24576000; - break; + case 192000: + case 128000: + case 96000: + case 64000: + case 48000: + case 32000: + case 24000: + case 16000: + case 12000: + case 8000: + clk_rate = 24576000; + break; - default: - dev_err(dai->dev, "Unsupported sample rate: %u\n", rate); - return -EINVAL; - } + default: + dev_err(dai->dev, "Unsupported sample rate: %u\n", rate); + return -EINVAL; + } - ret = clk_set_rate(i2s->mod_clk, clk_rate); - if (ret) - return ret; + ret = clk_set_rate(i2s->mod_clk, clk_rate); + if (ret) { + dev_err(dai->dev, "Unable to set clock\n"); + return ret; + } - oversample_rate = i2s->mclk_freq / rate; - if (!sun4i_i2s_oversample_is_valid(oversample_rate)) { - dev_err(dai->dev, "Unsupported oversample rate: %d\n", - oversample_rate); - return -EINVAL; - } + oversample_rate = i2s->mclk_freq / rate; + if (!sun4i_i2s_oversample_is_valid(oversample_rate)) { + dev_err(dai->dev, "Unsupported oversample rate: %d\n", + oversample_rate); + return -EINVAL; + } - bclk_div = sun4i_i2s_get_bclk_div(i2s, oversample_rate, - word_size); - if (bclk_div < 0) { - dev_err(dai->dev, "Unsupported BCLK divider: %d\n", bclk_div); - return -EINVAL; - } + bclk_div = sun4i_i2s_get_bclk_div(i2s, oversample_rate, + word_size); + if (bclk_div < 0) { + dev_err(dai->dev, "Unsupported BCLK divider: %d\n", + bclk_div); + return -EINVAL; + } - mclk_div = sun4i_i2s_get_mclk_div(i2s, oversample_rate, - clk_rate, rate); - if (mclk_div < 0) { - dev_err(dai->dev, "Unsupported MCLK divider: %d\n", mclk_div); - return -EINVAL; - } + mclk_div = sun4i_i2s_get_mclk_div(i2s, oversample_rate, + clk_rate, rate); + if (mclk_div < 0) { + dev_err(dai->dev, "Unsupported MCLK divider: %d\n", + mclk_div); + return -EINVAL; + } - /* Adjust the clock division values if needed */ - bclk_div += i2s->variant->bclk_offset; - mclk_div += i2s->variant->mclk_offset; + /* Adjust the clock division values if needed */ + bclk_div += i2s->variant->bclk_offset; + mclk_div += i2s->variant->mclk_offset; - regmap_write(i2s->regmap, SUN4I_I2S_CLK_DIV_REG, - SUN4I_I2S_CLK_DIV_BCLK(bclk_div) | - SUN4I_I2S_CLK_DIV_MCLK(mclk_div)); + regmap_write(i2s->regmap, SUN4I_I2S_CLK_DIV_REG, + SUN4I_I2S_CLK_DIV_BCLK(bclk_div) | + SUN4I_I2S_CLK_DIV_MCLK(mclk_div)); - regmap_field_write(i2s->field_clkdiv_mclk_en, 1); + regmap_field_write(i2s->field_clkdiv_mclk_en, 1); + } /* Set sync period */ if (i2s->variant->has_fmt_set_lrck_period) @@ -501,10 +509,12 @@ static int sun4i_i2s_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) case SND_SOC_DAIFMT_CBS_CFS: /* BCLK and LRCLK master */ val = SUN4I_I2S_CTRL_MODE_MASTER; + i2s->bit_clk_master = true; break; case SND_SOC_DAIFMT_CBM_CFM: /* BCLK and LRCLK slave */ val = SUN4I_I2S_CTRL_MODE_SLAVE; + i2s->bit_clk_master = false; break; default: dev_err(dai->dev, "Unsupported slave setting: %d\n", @@ -525,10 +535,12 @@ static int sun4i_i2s_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) /* BCLK and LRCLK master */ val = SUN8I_I2S_CTRL_BCLK_OUT | SUN8I_I2S_CTRL_LRCK_OUT; + i2s->bit_clk_master = true; break; case SND_SOC_DAIFMT_CBM_CFM: /* BCLK and LRCLK slave */ val = 0; + i2s->bit_clk_master = false; break; default: dev_err(dai->dev, "Unsupported slave setting: %d\n", -- 2.16.0