From patchwork Thu Aug 16 07:16:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 144321 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1729514ljj; Thu, 16 Aug 2018 00:17:50 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyp0Npb5ujsho9h9hV/Sx6sljiL3MGkZ/dpoiM+ZFmW+C6kRjfEwUCrFAK/WWU/C5VdAHSd X-Received: by 2002:a63:d20e:: with SMTP id a14-v6mr27898523pgg.226.1534403869975; Thu, 16 Aug 2018 00:17:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534403869; cv=none; d=google.com; s=arc-20160816; b=U3UwaYWxdskEMpczdY/X6C+u9GA5nyS1iAIpyq+Rzf1SAhqTWrx5NJRNW/whvipEoI GAkWfjyyhjClDZ6fkR/Heh/Kq+htrzbwAp/Uuew5bysB9OGFPyvFQTjvDygSM+j3DZYp 3npTp/xlsMyQfdx4Jn+8gAXlqaLEhsNY24wJC3PWfF+OPbQjZjUaljuf1rwTY333F7av mQ19W9RoRBuclPdqavrasJQMBaqq6+3v+I3nB7q9ocKQ8d7JdkkWrMpzzCXLy6qSYE7u Xi9nAIXDMlRbkCgv7ySXE3uk3rd6twfILWbv4SpUwdmj81fLZPkTCGw+TvfGP0AGJKBF oBmg== 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=dZTlH7sBCcuqFoGzvHUAD435gAWPXVV9fA5VEQ/IoJk=; b=du5X/Ny9IV8cqyWQZGZ1K2EyuCoTLVpmWNiP2NgBR9VCwDojJMN9jEdHVFOwKMATqT 2C3KXn9QMkGGK1YQPpKYO1nidltzVZP1hCR9MaCg1k4XMiO3xVCt/zBVw+X5yDJEDpxX PgI3JgMEacVY30ZHk31pwR9UG7glPg1QdR4cRiUFtRQ7w/aOkhoe95f191hejtU475Su BHcmZ//iwT6BbuYSStBW92CTL5OGR2onSxNBwKTQ4NXOJlcLAzl3Omt3Pd2Zej4fmGPc B24FIV2Y35fwiCbbytOURpXdGE+wbXwW9dJJHc8cUpw89E/6PhZfceLEO2pnIXNItmLt 5vjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=2GYSYrXx; 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 f12-v6si24878828pgm.601.2018.08.16.00.17.49; Thu, 16 Aug 2018 00:17:49 -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=pass header.i=@nifty.com header.s=dec2015msa header.b=2GYSYrXx; 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 S2389278AbeHPKOP (ORCPT + 5 others); Thu, 16 Aug 2018 06:14:15 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:17394 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389265AbeHPKOP (ORCPT ); Thu, 16 Aug 2018 06:14:15 -0400 Received: from grover.tkatk1.zaq.ne.jp (zaqdadce369.zaq.ne.jp [218.220.227.105]) (authenticated) by conuserg-09.nifty.com with ESMTP id w7G7Gu2M008336; Thu, 16 Aug 2018 16:17:01 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w7G7Gu2M008336 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1534403822; bh=dZTlH7sBCcuqFoGzvHUAD435gAWPXVV9fA5VEQ/IoJk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2GYSYrXxDR3t0Mhfe3/pmvL7WJTfFkRJU4+suVIUESv0pqyxKqVNRHT+IjE64dpja 1dYxj88/Niso07iWIbMiZ98WmalcpbM39S3l02oF7UIk/PDD/uki3yrH9FtrE7REai eEiRt96Psv53nw8pFxOMGZzGlKpgiGewLHXnQNHmeOmXdm1nNQIE3X68jIf/lYapsX VnPoSjD3xDSi/PxfM/Ia5gOQ2qcBftSzjlGCeN0uu/g94hfkkG4tj2CNzRsX4gsnaC GOMoy+Ob3CdHjblhwHb3IKI90tdvxcc8W9W1Zl5eby4FBKXFLrFYGxwSqyB7wD7k8S HzbwAHj/vshIg== X-Nifty-SrcIP: [218.220.227.105] From: Masahiro Yamada To: linux-mmc@vger.kernel.org, Wolfram Sang Cc: Masami Hiramatsu , Jassi Brar , Ulf Hansson , linux-renesas-soc@vger.kernel.org, Masahiro Yamada Subject: [PATCH v2 6/7] mmc: renesas_sdhi: refactor CLK_CTL bit calculation Date: Thu, 16 Aug 2018 16:16:38 +0900 Message-Id: <1534403799-10594-7-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534403799-10594-1-git-send-email-yamada.masahiro@socionext.com> References: <1534403799-10594-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 --- Changes in v2: None drivers/mmc/host/renesas_sdhi_core.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) -- 2.7.4 diff --git a/drivers/mmc/host/renesas_sdhi_core.c b/drivers/mmc/host/renesas_sdhi_core.c index a15fb2e..98391e9 100644 --- a/drivers/mmc/host/renesas_sdhi_core.c +++ b/drivers/mmc/host/renesas_sdhi_core.c @@ -158,7 +158,8 @@ static unsigned int renesas_sdhi_clk_update(struct tmio_mmc_host *host, static void renesas_sdhi_set_clock(struct tmio_mmc_host *host, unsigned int new_clock) { - u32 clk = 0, clock; + unsigned int clock, divisor; + u32 clk = 0; sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN & sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL)); @@ -166,14 +167,18 @@ static void renesas_sdhi_set_clock(struct tmio_mmc_host *host, if (new_clock == 0) goto out; - clock = renesas_sdhi_clk_update(host, new_clock) / 512; + clock = renesas_sdhi_clk_update(host, new_clock); - for (clk = 0x80000080; new_clock >= (clock << 1); clk >>= 1) - clock <<= 1; + divisor = clock / new_clock; - /* 1/1 clock is option */ - if ((host->pdata->flags & TMIO_MMC_CLK_ACTUAL) && ((clk >> 22) & 0x1)) - clk |= 0xff; + /* + * bit7 set: 1/512, ... bit0 set:1/4, all bits clear: 1/2 + * all bits set: 1/1 (Renesas-specific extension?) + */ + if ((host->pdata->flags & TMIO_MMC_CLK_ACTUAL) && divisor <= 1) + clk = 0xff; + else + clk = roundup_pow_of_two(divisor) >> 2; sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, clk & CLK_CTL_DIV_MASK); if (!(host->pdata->flags & TMIO_MMC_MIN_RCAR2))