From patchwork Tue Aug 7 06:17:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 143557 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4112220ljj; Mon, 6 Aug 2018 23:18:21 -0700 (PDT) X-Google-Smtp-Source: AAOMgpecNuc4xpQgMHhFXEqi51Rm63i9ghpMnRRslYbuXXsKJZsJKc/Z/YQOjAwRSLW0ucv9c/ca X-Received: by 2002:a63:90c8:: with SMTP id a191-v6mr17453128pge.173.1533622701525; Mon, 06 Aug 2018 23:18:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533622701; cv=none; d=google.com; s=arc-20160816; b=GQO4zGyhXT9SCkNkXQUkVJ43D2D6r1aI2qSOqnr5zK/hc+xpQgM6vU3R1LPHYo9NMP S5lQkOMgPQp4HtIn8dggMFZTVgUpjuCeDhB8ChOE667dDX4VqpspsDMXS3LhMLtE3aqY DZ5fsNAZfRwQDNaXrar+YnHQO7ca7J3/zi+P5IgQAZT0B6Z58rqY5J1KV7n/UBamrjWJ 8YQ/QQhEScEz3O4N/un/r9+nOtr4JzmoE/Ih3pPvmNlp4vX+q8fagGdfYS/y1KYtqBvs V6o/svFSCoJ1M1H5ZNpCTIe1wChLOtsbQEITupv2L47gxrRxB00t8a9nL/bzmbEXjKSa nnhA== 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=qIOmIprJkVi21IP1uiV+8Gl0nf5/lZ12zXJKRFzTnGQ=; b=icMfmtqEYhoq5JrhQ+Iui+cCaFLW/4bbsqZRRzqkiqGbedCyNefLtLpevlU1VrpRbp VImWoNJdYkrPrN5+fmcjz0JN2B1I22LAmCMfYs1wASIDyaX27Q8XJG17mN9yBxCqcj/n mKv40EgKsVem+gqdQHRj9+K6KREXN4Ofji1eVSRqAKdVp3kmsjZ2iKYvFSnudry9PVNv 5adKJNcaTnhmjFeMoew5Obl/SBkxqUATq7MruTqrV6bU8wZV5tymBjyl+E5tvjpnzc1a yvMRkHllxOExeDS/MzToL5cXromEdEbCIy2mkVqdqNEVmtvR2TYQOuJVpqNeyQoz3pre 5FKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=bvOcbINp; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f2-v6si564105pgg.552.2018.08.06.23.18.21; Mon, 06 Aug 2018 23:18:21 -0700 (PDT) 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=@nifty.com header.s=dec2015msa header.b=bvOcbINp; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388468AbeHGIa6 (ORCPT + 31 others); Tue, 7 Aug 2018 04:30:58 -0400 Received: from conuserg-08.nifty.com ([210.131.2.75]:39262 "EHLO conuserg-08.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727360AbeHGIa5 (ORCPT ); Tue, 7 Aug 2018 04:30:57 -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 w776HYgi009463; Tue, 7 Aug 2018 15:17:39 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com w776HYgi009463 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1533622660; bh=qIOmIprJkVi21IP1uiV+8Gl0nf5/lZ12zXJKRFzTnGQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bvOcbINp7Do8Jv0JSmQkdtyqT4eT8Hj3WTQkqVa/fn3G9Pr9H3rC2ZlZD1vZRs9iR J9Z2VoY1xWLBemgUAitUi1Cc02LbLMWb7gNYFvceeEnXoF6ywpQnSgrcmjTs8XsXo5 xO3nLJqUAM+XmfIr7wJ8bgsUVr6i7PrtCONx9pc2EdrpGY3W2GqWTGbNBf7w3AnIH+ CnSLgfAY9O6EU076+YG0ssEHdizLusjDmqOU6tb5edAd5fYUXEgiNusiLJwb0iJsVz /1Sm5BrluZMDJZrNVX1EzlyZPvhW2p352Qlupx5zsnZYwVISrUf4jU3cwU/D+zOQzA aGv1IwmDezXPQ== 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 6/7] mmc: renesas_sdhi: refactor CLK_CTL bit calculation Date: Tue, 7 Aug 2018 15:17:21 +0900 Message-Id: <1533622642-13989-7-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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/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))