Skip to content

Commit

Permalink
mmc: mediatek: Fixed bug where clock frequency could be set wrong
Browse files Browse the repository at this point in the history
This patch can fix two issues:

Issue 1:
In previous code, div may be overflow when setting clock frequency
as f_min. We can use DIV_ROUND_UP to fix this boundary related
issue.

Issue 2:
In previous code, we can not set the correct clock frequency when
div equals 0xff.

Signed-off-by: Yong Mao <[email protected]>
Signed-off-by: Chaotian Jing <[email protected]>
Reviewed-by: Daniel Kurtz <[email protected]>
Signed-off-by: Ulf Hansson <[email protected]>
  • Loading branch information
yong mao authored and storulf committed Mar 16, 2017
1 parent 8ecc344 commit 40ceda0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/mmc/host/mtk-sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ static void msdc_set_mclk(struct msdc_host *host, unsigned char timing, u32 hz)
}
}
sdr_set_field(host->base + MSDC_CFG, MSDC_CFG_CKMOD | MSDC_CFG_CKDIV,
(mode << 8) | (div % 0xff));
(mode << 8) | div);
sdr_set_bits(host->base + MSDC_CFG, MSDC_CFG_CKPDN);
while (!(readl(host->base + MSDC_CFG) & MSDC_CFG_CKSTB))
cpu_relax();
Expand Down Expand Up @@ -1559,7 +1559,7 @@ static int msdc_drv_probe(struct platform_device *pdev)
host->src_clk_freq = clk_get_rate(host->src_clk);
/* Set host parameters to mmc */
mmc->ops = &mt_msdc_ops;
mmc->f_min = host->src_clk_freq / (4 * 255);
mmc->f_min = DIV_ROUND_UP(host->src_clk_freq, 4 * 255);

mmc->caps |= MMC_CAP_ERASE | MMC_CAP_CMD23;
/* MMC core transfer sizes tunable parameters */
Expand Down

0 comments on commit 40ceda0

Please sign in to comment.