Merge branch 'master' of git://git.denx.de/u-boot-net
[oweals/u-boot.git] / drivers / mmc / sh_mmcif.c
index 64b5b472616b828ccf2d3743d42666337ec6585d..f92cf00cf4477f6cd275cffbc411efd9fe41efe9 100644 (file)
@@ -103,20 +103,18 @@ static int mmcif_wait_interrupt_flag(struct sh_mmcif_host *host)
 
 static void sh_mmcif_clock_control(struct sh_mmcif_host *host, unsigned int clk)
 {
-       int i;
-
        sh_mmcif_bitclr(CLK_ENABLE, &host->regs->ce_clk_ctrl);
        sh_mmcif_bitclr(CLK_CLEAR, &host->regs->ce_clk_ctrl);
 
        if (!clk)
                return;
-       if (clk == CLKDEV_EMMC_DATA) {
+
+       if (clk == CLKDEV_EMMC_DATA)
                sh_mmcif_bitset(CLK_PCLK, &host->regs->ce_clk_ctrl);
-       } else {
-               for (i = 1; (unsigned int)host->clk / (1 << i) >= clk; i++)
-                       ;
-               sh_mmcif_bitset((i - 1) << 16, &host->regs->ce_clk_ctrl);
-       }
+       else
+               sh_mmcif_bitset((fls(DIV_ROUND_UP(host->clk,
+                                                 clk) - 1) - 1) << 16,
+                               &host->regs->ce_clk_ctrl);
        sh_mmcif_bitset(CLK_ENABLE, &host->regs->ce_clk_ctrl);
 }
 
@@ -579,27 +577,27 @@ static struct mmc_config sh_mmcif_cfg = {
        .name           = DRIVER_NAME,
        .ops            = &sh_mmcif_ops,
        .host_caps      = MMC_MODE_HS | MMC_MODE_HS_52MHz | MMC_MODE_4BIT |
-                         MMC_MODE_8BIT | MMC_MODE_HC,
-       .voltages       = MMC_VDD_32_33 | MMC_VDD_33_34;
-       .f_min          = CLKDEV_MMC_INIT,
-       .f_max          = CLKDEV_EMMC_DATA,
+                         MMC_MODE_8BIT,
+       .voltages       = MMC_VDD_32_33 | MMC_VDD_33_34,
        .b_max          = CONFIG_SYS_MMC_MAX_BLK_COUNT,
 };
 
 int mmcif_mmc_init(void)
 {
-       int ret = 0;
        struct mmc *mmc;
        struct sh_mmcif_host *host = NULL;
 
        host = malloc(sizeof(struct sh_mmcif_host));
        if (!host)
-               ret = -ENOMEM;
+               return -ENOMEM;
        memset(host, 0, sizeof(*host));
 
        host->regs = (struct sh_mmcif_regs *)CONFIG_SH_MMCIF_ADDR;
        host->clk = CONFIG_SH_MMCIF_CLK;
 
+       sh_mmcif_cfg.f_min = MMC_CLK_DIV_MIN(host->clk);
+       sh_mmcif_cfg.f_max = MMC_CLK_DIV_MAX(host->clk);
+
        mmc = mmc_create(&sh_mmcif_cfg, host);
        if (mmc == NULL) {
                free(host);