]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - drivers/mmc/sh_mmcif.c
mmc: omap_hsmmc: Reduce the max timeout for reset controller fsm
[people/ms/u-boot.git] / drivers / mmc / sh_mmcif.c
index 64b5b472616b828ccf2d3743d42666337ec6585d..1ff59f06d576b77dbfe1fc92ba7f44f5a9d0e006 100644 (file)
@@ -3,9 +3,7 @@
  *
  * Copyright (C)  2011 Renesas Solutions Corp.
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License.
+ * SPDX-License-Identifier:    GPL-2.0
  */
 
 #include <config.h>
@@ -14,7 +12,7 @@
 #include <command.h>
 #include <mmc.h>
 #include <malloc.h>
-#include <asm/errno.h>
+#include <linux/errno.h>
 #include <asm/io.h>
 #include "sh_mmcif.h"
 
@@ -103,20 +101,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);
 }
 
@@ -172,7 +168,7 @@ static int sh_mmcif_error_manage(struct sh_mmcif_host *host)
        if (state2 & STS2_CRC_ERR)
                ret = -EILSEQ;
        else if (state2 & STS2_TIMEOUT_ERR)
-               ret = TIMEOUT;
+               ret = -ETIMEDOUT;
        else
                ret = -EILSEQ;
        return ret;
@@ -487,7 +483,7 @@ static int sh_mmcif_start_cmd(struct sh_mmcif_host *host,
                case MMC_CMD_ALL_SEND_CID:
                case MMC_CMD_SELECT_CARD:
                case MMC_CMD_APP_CMD:
-                       ret = TIMEOUT;
+                       ret = -ETIMEDOUT;
                        break;
                default:
                        printf(DRIVER_NAME": Cmd(d'%d) err\n", cmd->cmdidx);
@@ -524,14 +520,14 @@ static int sh_mmcif_request(struct mmc *mmc, struct mmc_cmd *cmd,
 
        switch (cmd->cmdidx) {
        case MMC_CMD_APP_CMD:
-               return TIMEOUT;
+               return -ETIMEDOUT;
        case MMC_CMD_SEND_EXT_CSD: /* = SD_SEND_IF_COND (8) */
                if (data)
                        /* ext_csd */
                        break;
                else
                        /* send_if_cond cmd (not support) */
-                       return TIMEOUT;
+                       return -ETIMEDOUT;
        default:
                break;
        }
@@ -543,7 +539,7 @@ static int sh_mmcif_request(struct mmc *mmc, struct mmc_cmd *cmd,
        return ret;
 }
 
-static void sh_mmcif_set_ios(struct mmc *mmc)
+static int sh_mmcif_set_ios(struct mmc *mmc)
 {
        struct sh_mmcif_host *host = mmc->priv;
 
@@ -558,6 +554,8 @@ static void sh_mmcif_set_ios(struct mmc *mmc)
                host->bus_width = MMC_BUS_WIDTH_1;
 
        debug("clock = %d, buswidth = %d\n", mmc->clock, mmc->bus_width);
+
+       return 0;
 }
 
 static int sh_mmcif_init(struct mmc *mmc)
@@ -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);