summaryrefslogtreecommitdiff
path: root/drivers/mmc
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2018-08-23 07:44:20 +0300
committerUlf Hansson <ulf.hansson@linaro.org>2018-10-08 12:40:43 +0300
commitdb4cea918e11d1cd1cb870049b2af17fe99d7b94 (patch)
treed67c3b45621792fcd0a7e3c8a8680d49867d4f73 /drivers/mmc
parent68f83127fe750c8b270361f4353cc9d76b0286d6 (diff)
downloadlinux-db4cea918e11d1cd1cb870049b2af17fe99d7b94.tar.xz
mmc: tmio: refactor CLK_CTL bit calculation
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> Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Tested-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Diffstat (limited to 'drivers/mmc')
-rw-r--r--drivers/mmc/host/tmio_mmc.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/drivers/mmc/host/tmio_mmc.c b/drivers/mmc/host/tmio_mmc.c
index 09bb104e3fff..0ae9ba1ee01b 100644
--- a/drivers/mmc/host/tmio_mmc.c
+++ b/drivers/mmc/host/tmio_mmc.c
@@ -45,19 +45,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));