From: Masahiro Yamada <yamada.masahiro@socionext.com>
To: Wolfram Sang <wsa+renesas@sang-engineering.com>,
linux-mmc@vger.kernel.org
Cc: Ulf Hansson <ulf.hansson@linaro.org>,
linux-renesas-soc@vger.kernel.org,
Masami Hiramatsu <mhiramat@kernel.org>,
Jassi Brar <jaswinder.singh@linaro.org>,
Masahiro Yamada <yamada.masahiro@socionext.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH v3 6/6] mmc: tmio: refactor CLK_CTL bit calculation
Date: Thu, 23 Aug 2018 13:44:20 +0900 [thread overview]
Message-ID: <1534999460-15111-7-git-send-email-yamada.masahiro@socionext.com> (raw)
In-Reply-To: <1534999460-15111-1-git-send-email-yamada.masahiro@socionext.com>
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 <yamada.masahiro@socionext.com>
---
Changes in v3: None
Changes in v2: None
drivers/mmc/host/tmio_mmc.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
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));
--
2.7.4
next prev parent reply other threads:[~2018-08-23 4:45 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-23 4:44 [PATCH v3 0/6] mmc: tmio: refactor TMIO core a bit and add UniPhier SD/eMMC controller support Masahiro Yamada
2018-08-23 4:44 ` [PATCH v3 1/6] mmc: tmio: replace tmio_mmc_clk_stop() calls with tmio_mmc_set_clock() Masahiro Yamada
2018-08-23 4:44 ` [PATCH v3 2/6] mmc: tmio: move tmio_mmc_set_clock() to platform hook Masahiro Yamada
2018-08-23 4:44 ` [PATCH v3 3/6] dt-bindings: mmc: add DT binding for UniPhier SD/eMMC controller Masahiro Yamada
2018-08-23 4:44 ` [PATCH v3 4/6] mmc: uniphier-sd: add UniPhier SD/eMMC controller driver Masahiro Yamada
2018-08-23 10:43 ` Ulf Hansson
2018-08-24 1:50 ` Masahiro Yamada
2018-08-24 6:32 ` Ulf Hansson
2018-08-23 4:44 ` [PATCH v3 5/6] mmc: renesas_sdhi: merge clk_{start,stop} functions to set_clock Masahiro Yamada
2018-08-29 8:40 ` Wolfram Sang
2018-08-30 12:30 ` Ulf Hansson
2018-08-23 4:44 ` Masahiro Yamada [this message]
2018-08-29 8:49 ` [PATCH v3 6/6] mmc: tmio: refactor CLK_CTL bit calculation Wolfram Sang
2018-08-30 11:51 ` Ulf Hansson
2018-08-30 12:03 ` Wolfram Sang
2018-08-30 12:30 ` Ulf Hansson
2018-08-23 10:43 ` [PATCH v3 0/6] mmc: tmio: refactor TMIO core a bit and add UniPhier SD/eMMC controller support Ulf Hansson
2018-08-29 8:27 ` Wolfram Sang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1534999460-15111-7-git-send-email-yamada.masahiro@socionext.com \
--to=yamada.masahiro@socionext.com \
--cc=jaswinder.singh@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=ulf.hansson@linaro.org \
--cc=wsa+renesas@sang-engineering.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).