From patchwork Tue Aug 7 06:17:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 143558 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4112399ljj; Mon, 6 Aug 2018 23:18:31 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdiAa4QHS0SB7M/JdCMm2jXEAduCklp50jgOmnB9odoKwn24dzRPQafUlPZCQ9iFZtSGgYB X-Received: by 2002:a63:da04:: with SMTP id c4-v6mr16610212pgh.398.1533622711094; Mon, 06 Aug 2018 23:18:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533622711; cv=none; d=google.com; s=arc-20160816; b=Z9VS0I3Jdu4unL3grTadF4w3F0eGSOoQ9WQKa41cnF2Kb/VaYl662oQpqbzGYW2IzH wwjALrYzJT1TolaztN0+mVIGXOiErtRvNTaY7ZtzLL2zSZnLTAip/SbivtbfDlroqsMa FLJ0OgQZzivoHxZxYjUVrkH4rFcI+MaW/ewsE5icxXCHMiEBGKTBEKtFrAXhmZ49wyJ4 Eeet8gobu+nWcWRP5Dbwi7CYH6aTTfVbWhI0RHR3WoB4wp/DGLOONNHYfsJrz9ePGbPl OgjWnFo2sERQsexhb2tGI12toxI2Cws6dID4ypNUkvTkgWN4qJKvYDSBwIjQfc030GYt p/Pw== 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:dkim-filter :arc-authentication-results; bh=jX9An6BiMQI7QUXnSHAcO1fNcQi5ghfzqRL6lIcpxes=; b=KKh6TYMNCwtHI2CULpTwRL/ylTyxOEpvSg2e7H+j10udWM2zL6lY8zgzwXC1qAdbtC HR9nwtyK/rAH9aEBwodmZ2g0JpZTbVouGOMI30mTqvvBNHoz09dD4c+2U0jwk/Efl8JR ibhClfsD2cS4A83PlgmfnUCFNo29ZgLMsrD4srWGbeHbOyGfFwBW4X6pMig3DmfLuGaR WFS98PA6QoVE2Kh+D//RQgUTHhCUItx7DG1i6lOzSiefRvzMHS37Po8qrg8ah9GnbYch 2slfq+NXra0V7unHcJVvlWnpPpHybaH2BesdSHYpReaxW6hLYlBMsnC6RudYMdtO1PeE dCyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=Iyq18C3o; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z4-v6si563038pgf.193.2018.08.06.23.18.30; Mon, 06 Aug 2018 23:18:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=Iyq18C3o; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388594AbeHGIbO (ORCPT + 5 others); Tue, 7 Aug 2018 04:31:14 -0400 Received: from conuserg-08.nifty.com ([210.131.2.75]:39265 "EHLO conuserg-08.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733061AbeHGIa6 (ORCPT ); Tue, 7 Aug 2018 04:30:58 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-08.nifty.com with ESMTP id w776HYgj009463; Tue, 7 Aug 2018 15:17:40 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com w776HYgj009463 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1533622661; bh=93n/hdv/fu8dAdRrLAHfmbU88lUWS0mHHs+i79buDAA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Iyq18C3o8zluJ9xaZYliAQo9dwvl8LJpz/YLeIT37PFoUCTXMDe0W2DkPz4HDqJ8f pljeYYEypCSbrTh+fV4TpiyVclrtUJfeubpumuGlS2nsAWSETJICW7BrAncHvtc+uV lmNC2zSUQoHUaC4ufAE3uhnudrzAHCg4oGwdmRL588mnPffC+50PXb1wgjtVorGR+F 2B0LEvhgBPiXDHiqcYh6CGCSRfAQZCGXX8I6l+R68n4wNkZt4mYomb3hvolIgvWIoP TbiVpWul0QwLir9Dy7EjxJSDKYXlv1lFQ+9zkfS8e3ENcftVq4BctmiJegx85esiCm H8/kUdtW43ZIA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: Wolfram Sang , linux-mmc@vger.kernel.org Cc: Ulf Hansson , linux-renesas-soc@vger.kernel.org, Masami Hiramatsu , Jassi Brar , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [v0.1 PATCH 7/7] mmc: tmio: refactor CLK_CTL bit calculation Date: Tue, 7 Aug 2018 15:17:22 +0900 Message-Id: <1533622642-13989-8-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1533622642-13989-1-git-send-email-yamada.masahiro@socionext.com> References: <1533622642-13989-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org for (clk = 0x80000080; new_clock >= (clock << 1); clk >>= 1) clock <<= 1; ... is too tricky, hence I replaced with roundup_pow_of_two(divisor) >> 2 '(clk >> 22) & 0x1' is the bit test for the 1/1 divisor, but it is not clear. 'divisor <= 1' is easier to understand. Signed-off-by: Masahiro Yamada --- drivers/mmc/host/tmio_mmc.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/mmc/host/tmio_mmc.c b/drivers/mmc/host/tmio_mmc.c index b031a77..e04c322 100644 --- a/drivers/mmc/host/tmio_mmc.c +++ b/drivers/mmc/host/tmio_mmc.c @@ -48,19 +48,27 @@ static void tmio_mmc_clk_stop(struct tmio_mmc_host *host) static void tmio_mmc_set_clock(struct tmio_mmc_host *host, unsigned int new_clock) { - u32 clk = 0, clock; + unsigned int clock, divisor; + u32 clk = 0; + int clk_sel; if (new_clock == 0) { tmio_mmc_clk_stop(host); return; } - clock = host->mmc->f_min; + divisor = host->pdata->hclk / new_clock; - for (clk = 0x80000080; new_clock >= (clock << 1); clk >>= 1) - clock <<= 1; + if (divisor <= 1) { + clk_sel = 1; + clk = 0; + } else { + clk_sel = 0; + /* bit7 set: 1/512, ... bit0 set:1/4, all bits clear: 1/2 */ + clk = roundup_pow_of_two(divisor) >> 2; + } - host->pdata->set_clk_div(host->pdev, (clk >> 22) & 1); + host->pdata->set_clk_div(host->pdev, clk_sel); sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN & sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));