]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - drivers/mmc/mmc.c
mmc: Drop unnecessary case for mmc_probe()
[people/ms/u-boot.git] / drivers / mmc / mmc.c
index 5255c0dccfc24ace69592d4014fe7c2e8d6d33db..31f65f6e242f6eb57d2ffddbd3146e42e014d6e0 100644 (file)
 #include <div64.h>
 #include "mmc_private.h"
 
-static const unsigned int sd_au_size[] = {
-       0,              SZ_16K / 512,           SZ_32K / 512,
-       SZ_64K / 512,   SZ_128K / 512,          SZ_256K / 512,
-       SZ_512K / 512,  SZ_1M / 512,            SZ_2M / 512,
-       SZ_4M / 512,    SZ_8M / 512,            (SZ_8M + SZ_4M) / 512,
-       SZ_16M / 512,   (SZ_16M + SZ_8M) / 512, SZ_32M / 512,   SZ_64M / 512,
-};
-
 static int mmc_set_signal_voltage(struct mmc *mmc, uint signal_voltage);
 static int mmc_power_cycle(struct mmc *mmc);
 static int mmc_select_mode_and_width(struct mmc *mmc, uint card_caps);
@@ -189,23 +181,18 @@ const char *mmc_mode_name(enum bus_mode mode)
 static uint mmc_mode2freq(struct mmc *mmc, enum bus_mode mode)
 {
        static const int freqs[] = {
+             [MMC_LEGACY]      = 25000000,
              [SD_LEGACY]       = 25000000,
              [MMC_HS]          = 26000000,
              [SD_HS]           = 50000000,
-#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
+             [MMC_HS_52]       = 52000000,
+             [MMC_DDR_52]      = 52000000,
              [UHS_SDR12]       = 25000000,
              [UHS_SDR25]       = 50000000,
              [UHS_SDR50]       = 100000000,
              [UHS_DDR50]       = 50000000,
-#ifdef MMC_SUPPORTS_TUNING
              [UHS_SDR104]      = 208000000,
-#endif
-#endif
-             [MMC_HS_52]       = 52000000,
-             [MMC_DDR_52]      = 52000000,
-#if CONFIG_IS_ENABLED(MMC_HS200_SUPPORT)
              [MMC_HS_200]      = 200000000,
-#endif
        };
 
        if (mode == MMC_LEGACY)
@@ -221,8 +208,8 @@ static int mmc_select_mode(struct mmc *mmc, enum bus_mode mode)
        mmc->selected_mode = mode;
        mmc->tran_speed = mmc_mode2freq(mmc, mode);
        mmc->ddr_mode = mmc_is_mode_ddr(mode);
-       debug("selecting mode %s (freq : %d MHz)\n", mmc_mode_name(mode),
-             mmc->tran_speed / 1000000);
+       pr_debug("selecting mode %s (freq : %d MHz)\n", mmc_mode_name(mode),
+                mmc->tran_speed / 1000000);
        return 0;
 }
 
@@ -465,7 +452,7 @@ ulong mmc_bread(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt,
        }
 
        if (mmc_set_blocklen(mmc, mmc->read_bl_len)) {
-               debug("%s: Failed to set blocklen\n", __func__);
+               pr_debug("%s: Failed to set blocklen\n", __func__);
                return 0;
        }
 
@@ -473,7 +460,7 @@ ulong mmc_bread(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt,
                cur = (blocks_todo > mmc->cfg->b_max) ?
                        mmc->cfg->b_max : blocks_todo;
                if (mmc_read_blocks(mmc, dst, start, cur) != cur) {
-                       debug("%s: Failed to read blocks\n", __func__);
+                       pr_debug("%s: Failed to read blocks\n", __func__);
                        return 0;
                }
                blocks_todo -= cur;
@@ -908,11 +895,11 @@ static int mmc_boot_part_access_chk(struct mmc *mmc, unsigned int part_num)
                forbidden = MMC_CAP(MMC_HS_200);
 
        if (MMC_CAP(mmc->selected_mode) & forbidden) {
-               debug("selected mode (%s) is forbidden for part %d\n",
-                     mmc_mode_name(mmc->selected_mode), part_num);
+               pr_debug("selected mode (%s) is forbidden for part %d\n",
+                        mmc_mode_name(mmc->selected_mode), part_num);
                change = true;
        } else if (mmc->selected_mode != mmc->best_mode) {
-               debug("selected mode is not optimal\n");
+               pr_debug("selected mode is not optimal\n");
                change = true;
        }
 
@@ -1341,7 +1328,7 @@ static int sd_set_card_speed(struct mmc *mmc, enum bus_mode mode)
        if (err)
                return err;
 
-       if ((__be32_to_cpu(switch_status[4]) >> 24) != speed)
+       if (((__be32_to_cpu(switch_status[4]) >> 24) & 0xF) != speed)
                return -ENOTSUPP;
 
        return 0;
@@ -1376,8 +1363,17 @@ int sd_select_bus_width(struct mmc *mmc, int w)
        return 0;
 }
 
+#if CONFIG_IS_ENABLED(MMC_WRITE)
 static int sd_read_ssr(struct mmc *mmc)
 {
+       static const unsigned int sd_au_size[] = {
+               0,              SZ_16K / 512,           SZ_32K / 512,
+               SZ_64K / 512,   SZ_128K / 512,          SZ_256K / 512,
+               SZ_512K / 512,  SZ_1M / 512,            SZ_2M / 512,
+               SZ_4M / 512,    SZ_8M / 512,            (SZ_8M + SZ_4M) / 512,
+               SZ_16M / 512,   (SZ_16M + SZ_8M) / 512, SZ_32M / 512,
+               SZ_64M / 512,
+       };
        int err, i;
        struct mmc_cmd cmd;
        ALLOC_CACHE_ALIGN_BUFFER(uint, ssr, 16);
@@ -1426,12 +1422,12 @@ retry_ssr:
                        mmc->ssr.erase_offset = eo * 1000;
                }
        } else {
-               debug("Invalid Allocation Unit Size.\n");
+               pr_debug("Invalid Allocation Unit Size.\n");
        }
 
        return 0;
 }
-
+#endif
 /* frequency bases */
 /* divided by 10 to be nice to platforms without floating point */
 static const int fbase[] = {
@@ -1500,11 +1496,13 @@ static int mmc_set_ios(struct mmc *mmc)
 
 int mmc_set_clock(struct mmc *mmc, uint clock, bool disable)
 {
-       if (clock > mmc->cfg->f_max)
-               clock = mmc->cfg->f_max;
+       if (!disable) {
+               if (clock > mmc->cfg->f_max)
+                       clock = mmc->cfg->f_max;
 
-       if (clock < mmc->cfg->f_min)
-               clock = mmc->cfg->f_min;
+               if (clock < mmc->cfg->f_min)
+                       clock = mmc->cfg->f_min;
+       }
 
        mmc->clock = clock;
        mmc->clk_disable = disable;
@@ -1529,18 +1527,18 @@ void mmc_dump_capabilities(const char *text, uint caps)
 {
        enum bus_mode mode;
 
-       printf("%s: widths [", text);
+       pr_debug("%s: widths [", text);
        if (caps & MMC_MODE_8BIT)
-               printf("8, ");
+               pr_debug("8, ");
        if (caps & MMC_MODE_4BIT)
-               printf("4, ");
+               pr_debug("4, ");
        if (caps & MMC_MODE_1BIT)
-               printf("1, ");
-       printf("\b\b] modes [");
+               pr_debug("1, ");
+       pr_debug("\b\b] modes [");
        for (mode = MMC_LEGACY; mode < MMC_MODES_END; mode++)
                if (MMC_CAP(mode) & caps)
-                       printf("%s, ", mmc_mode_name(mode));
-       printf("\b\b]\n");
+                       pr_debug("%s, ", mmc_mode_name(mode));
+       pr_debug("\b\b]\n");
 }
 #endif
 
@@ -1574,7 +1572,7 @@ static int mmc_set_signal_voltage(struct mmc *mmc, uint signal_voltage)
        mmc->signal_voltage = signal_voltage;
        err = mmc_set_ios(mmc);
        if (err)
-               debug("unable to set voltage (err %d)\n", err);
+               pr_debug("unable to set voltage (err %d)\n", err);
 
        return err;
 }
@@ -1657,10 +1655,10 @@ static int sd_select_mode_and_width(struct mmc *mmc, uint card_caps)
 
                for (w = widths; w < widths + ARRAY_SIZE(widths); w++) {
                        if (*w & caps & mwt->widths) {
-                               debug("trying mode %s width %d (at %d MHz)\n",
-                                     mmc_mode_name(mwt->mode),
-                                     bus_width(*w),
-                                     mmc_mode2freq(mmc, mwt->mode) / 1000000);
+                               pr_debug("trying mode %s width %d (at %d MHz)\n",
+                                        mmc_mode_name(mwt->mode),
+                                        bus_width(*w),
+                                        mmc_mode2freq(mmc, mwt->mode) / 1000000);
 
                                /* configure the bus width (card + host) */
                                err = sd_select_bus_width(mmc, bus_width(*w));
@@ -1683,18 +1681,20 @@ static int sd_select_mode_and_width(struct mmc *mmc, uint card_caps)
                                        err = mmc_execute_tuning(mmc,
                                                                 mwt->tuning);
                                        if (err) {
-                                               debug("tuning failed\n");
+                                               pr_debug("tuning failed\n");
                                                goto error;
                                        }
                                }
 #endif
 
+#if CONFIG_IS_ENABLED(MMC_WRITE)
                                err = sd_read_ssr(mmc);
+                               if (!err)
+                                       pr_warn("unable to read ssr\n");
+#endif
                                if (!err)
                                        return 0;
 
-                               pr_warn("bad ssr\n");
-
 error:
                                /* revert to a safer bus speed */
                                mmc_select_mode(mmc, SD_LEGACY);
@@ -1703,7 +1703,7 @@ error:
                }
        }
 
-       printf("unable to select a mode\n");
+       pr_err("unable to select a mode\n");
        return -ENOTSUPP;
 }
 
@@ -1855,7 +1855,7 @@ static int mmc_select_mode_and_width(struct mmc *mmc, uint card_caps)
                return 0;
 
        if (!mmc->ext_csd) {
-               debug("No ext_csd found!\n"); /* this should enver happen */
+               pr_debug("No ext_csd found!\n"); /* this should enver happen */
                return -ENOTSUPP;
        }
 
@@ -1865,10 +1865,10 @@ static int mmc_select_mode_and_width(struct mmc *mmc, uint card_caps)
                for_each_supported_width(card_caps & mwt->widths,
                                         mmc_is_mode_ddr(mwt->mode), ecbw) {
                        enum mmc_voltage old_voltage;
-                       debug("trying mode %s width %d (at %d MHz)\n",
-                             mmc_mode_name(mwt->mode),
-                             bus_width(ecbw->cap),
-                             mmc_mode2freq(mmc, mwt->mode) / 1000000);
+                       pr_debug("trying mode %s width %d (at %d MHz)\n",
+                                mmc_mode_name(mwt->mode),
+                                bus_width(ecbw->cap),
+                                mmc_mode2freq(mmc, mwt->mode) / 1000000);
                        old_voltage = mmc->signal_voltage;
                        err = mmc_set_lowest_voltage(mmc, mwt->mode,
                                                     MMC_ALL_SIGNAL_VOLTAGE);
@@ -1909,7 +1909,7 @@ static int mmc_select_mode_and_width(struct mmc *mmc, uint card_caps)
                        if (mwt->tuning) {
                                err = mmc_execute_tuning(mmc, mwt->tuning);
                                if (err) {
-                                       debug("tuning failed\n");
+                                       pr_debug("tuning failed\n");
                                        goto error;
                                }
                        }
@@ -1945,6 +1945,7 @@ static int mmc_startup_v4(struct mmc *mmc)
                MMC_VERSION_4_1,
                MMC_VERSION_4_2,
                MMC_VERSION_4_3,
+               MMC_VERSION_4_4,
                MMC_VERSION_4_41,
                MMC_VERSION_4_5,
                MMC_VERSION_5_0,
@@ -2025,6 +2026,7 @@ static int mmc_startup_v4(struct mmc *mmc)
                mmc->capacity_gp[i] <<= 19;
        }
 
+#ifndef CONFIG_SPL_BUILD
        if (part_completed) {
                mmc->enh_user_size =
                        (ext_csd[EXT_CSD_ENH_SIZE_MULT + 2] << 16) +
@@ -2041,6 +2043,7 @@ static int mmc_startup_v4(struct mmc *mmc)
                if (mmc->high_capacity)
                        mmc->enh_user_start <<= 9;
        }
+#endif
 
        /*
         * Host needs to enable ERASE_GRP_DEF bit if device is
@@ -2063,9 +2066,11 @@ static int mmc_startup_v4(struct mmc *mmc)
        }
 
        if (ext_csd[EXT_CSD_ERASE_GROUP_DEF] & 0x01) {
+#if CONFIG_IS_ENABLED(MMC_WRITE)
                /* Read out group size from ext_csd */
                mmc->erase_grp_size =
                        ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] * 1024;
+#endif
                /*
                 * if high capacity and partition setting completed
                 * SEC_COUNT is valid even if it is smaller than 2 GiB
@@ -2079,7 +2084,9 @@ static int mmc_startup_v4(struct mmc *mmc)
                        capacity *= MMC_MAX_BLOCK_LEN;
                        mmc->capacity_user = capacity;
                }
-       } else {
+       }
+#if CONFIG_IS_ENABLED(MMC_WRITE)
+       else {
                /* Calculate the group size from the csd value. */
                int erase_gsz, erase_gmul;
 
@@ -2088,10 +2095,12 @@ static int mmc_startup_v4(struct mmc *mmc)
                mmc->erase_grp_size = (erase_gsz + 1)
                        * (erase_gmul + 1);
        }
-
+#endif
+#if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING)
        mmc->hc_wp_grp_size = 1024
                * ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]
                * ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
+#endif
 
        mmc->wr_rel_set = ext_csd[EXT_CSD_WR_REL_SET];
 
@@ -2219,11 +2228,13 @@ static int mmc_startup(struct mmc *mmc)
 
        mmc->dsr_imp = ((cmd.response[1] >> 12) & 0x1);
        mmc->read_bl_len = 1 << ((cmd.response[1] >> 16) & 0xf);
+#if CONFIG_IS_ENABLED(MMC_WRITE)
 
        if (IS_SD(mmc))
                mmc->write_bl_len = mmc->read_bl_len;
        else
                mmc->write_bl_len = 1 << ((cmd.response[3] >> 22) & 0xf);
+#endif
 
        if (mmc->high_capacity) {
                csize = (mmc->csd[1] & 0x3f) << 16
@@ -2245,8 +2256,10 @@ static int mmc_startup(struct mmc *mmc)
        if (mmc->read_bl_len > MMC_MAX_BLOCK_LEN)
                mmc->read_bl_len = MMC_MAX_BLOCK_LEN;
 
+#if CONFIG_IS_ENABLED(MMC_WRITE)
        if (mmc->write_bl_len > MMC_MAX_BLOCK_LEN)
                mmc->write_bl_len = MMC_MAX_BLOCK_LEN;
+#endif
 
        if ((mmc->dsr_imp) && (0xffffffff != mmc->dsr)) {
                cmd.cmdidx = MMC_CMD_SET_DSR;
@@ -2270,7 +2283,9 @@ static int mmc_startup(struct mmc *mmc)
        /*
         * For SD, its erase group is always one sector
         */
+#if CONFIG_IS_ENABLED(MMC_WRITE)
        mmc->erase_grp_size = 1;
+#endif
        mmc->part_config = MMCPART_NOAVAILABLE;
 
        err = mmc_startup_v4(mmc);
@@ -2301,7 +2316,9 @@ static int mmc_startup(struct mmc *mmc)
        /* Fix the block length for DDR mode */
        if (mmc->ddr_mode) {
                mmc->read_bl_len = MMC_MAX_BLOCK_LEN;
+#if CONFIG_IS_ENABLED(MMC_WRITE)
                mmc->write_bl_len = MMC_MAX_BLOCK_LEN;
+#endif
        }
 
        /* fill in device description */
@@ -2375,12 +2392,12 @@ static int mmc_power_init(struct mmc *mmc)
        ret = device_get_supply_regulator(mmc->dev, "vmmc-supply",
                                          &mmc->vmmc_supply);
        if (ret)
-               debug("%s: No vmmc supply\n", mmc->dev->name);
+               pr_debug("%s: No vmmc supply\n", mmc->dev->name);
 
        ret = device_get_supply_regulator(mmc->dev, "vqmmc-supply",
                                          &mmc->vqmmc_supply);
        if (ret)
-               debug("%s: No vqmmc supply\n", mmc->dev->name);
+               pr_debug("%s: No vqmmc supply\n", mmc->dev->name);
 #endif
 #else /* !CONFIG_DM_MMC */
        /*
@@ -2430,13 +2447,13 @@ static int mmc_power_on(struct mmc *mmc)
 
 static int mmc_power_off(struct mmc *mmc)
 {
-       mmc_set_clock(mmc, 1, true);
+       mmc_set_clock(mmc, 0, true);
 #if CONFIG_IS_ENABLED(DM_MMC) && CONFIG_IS_ENABLED(DM_REGULATOR)
        if (mmc->vmmc_supply) {
                int ret = regulator_set_enable(mmc->vmmc_supply, false);
 
                if (ret) {
-                       debug("Error disabling VMMC supply\n");
+                       pr_debug("Error disabling VMMC supply\n");
                        return ret;
                }
        }
@@ -2472,15 +2489,19 @@ int mmc_start_init(struct mmc *mmc)
        mmc->host_caps = mmc->cfg->host_caps | MMC_CAP(SD_LEGACY) |
                         MMC_CAP(MMC_LEGACY) | MMC_MODE_1BIT;
 
+#if !defined(CONFIG_MMC_BROKEN_CD)
        /* we pretend there's no card when init is NULL */
        no_card = mmc_getcd(mmc) == 0;
+#else
+       no_card = 0;
+#endif
 #if !CONFIG_IS_ENABLED(DM_MMC)
        no_card = no_card || (mmc->cfg->ops->init == NULL);
 #endif
        if (no_card) {
                mmc->has_init = 0;
 #if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
-               printf("MMC: no card present\n");
+               pr_err("MMC: no card present\n");
 #endif
                return -ENOMEDIUM;
        }
@@ -2507,7 +2528,7 @@ int mmc_start_init(struct mmc *mmc)
                 * to use the UHS modes, because we wouldn't be able to
                 * recover from an error during the UHS initialization.
                 */
-               debug("Unable to do a full power cycle. Disabling the UHS modes for safety\n");
+               pr_debug("Unable to do a full power cycle. Disabling the UHS modes for safety\n");
                uhs_en = false;
                mmc->host_caps &= ~UHS_CAPS;
                err = mmc_power_on(mmc);
@@ -2604,7 +2625,7 @@ int mmc_init(struct mmc *mmc)
        if (!err)
                err = mmc_complete_init(mmc);
        if (err)
-               printf("%s: %d, time %lu\n", __func__, err, get_timer(start));
+               pr_info("%s: %d, time %lu\n", __func__, err, get_timer(start));
 
        return err;
 }
@@ -2632,12 +2653,7 @@ void mmc_set_preinit(struct mmc *mmc, int preinit)
        mmc->preinit = preinit;
 }
 
-#if CONFIG_IS_ENABLED(DM_MMC) && defined(CONFIG_SPL_BUILD)
-static int mmc_probe(bd_t *bis)
-{
-       return 0;
-}
-#elif CONFIG_IS_ENABLED(DM_MMC)
+#if CONFIG_IS_ENABLED(DM_MMC)
 static int mmc_probe(bd_t *bis)
 {
        int ret, i;