[U-Boot] [PATCH 07/22] mmc: use mmc modes to select the correct bus speed

Simon Glass sjg at chromium.org
Mon May 15 03:28:05 UTC 2017


On 12 May 2017 at 12:16, Jean-Jacques Hiblot <jjhiblot at ti.com> wrote:

Please add commit message which what is happening and motivation.

> Signed-off-by: Jean-Jacques Hiblot <jjhiblot at ti.com>
> ---
>  drivers/mmc/mmc.c | 40 +++++++++++++++++++++++++++++-----------
>  1 file changed, 29 insertions(+), 11 deletions(-)

Reviewed-by: Simon Glass <sjg at chromium.org>

>
> diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
> index 5d418c5..dc7985f 100644
> --- a/drivers/mmc/mmc.c
> +++ b/drivers/mmc/mmc.c
> @@ -171,9 +171,35 @@ const char *mmc_mode_name(enum bus_mode mode)
>         else
>                 return names[mode];
>  }
> +
> +static uint mmc_mode2freq(struct mmc *mmc, enum bus_mode mode)
> +{
> +       static const int freqs[] = {
> +             [SD_LEGACY]       = 25000000,
> +             [MMC_HS]          = 26000000,
> +             [SD_HS]           = 50000000,
> +             [UHS_SDR12]       = 25000000,
> +             [UHS_SDR25]       = 50000000,
> +             [UHS_SDR50]       = 100000000,
> +             [UHS_SDR104]      = 208000000,
> +             [UHS_DDR50]       = 50000000,
> +             [MMC_HS_52]       = 52000000,
> +             [MMC_DDR_52]      = 52000000,
> +             [MMC_HS_200]      = 200000000,
> +       };
> +
> +       if (mode == MMC_LEGACY)
> +               return mmc->legacy_speed;
> +       else if (mode >= MMC_MODES_END)
> +               return 0;
> +       else
> +               return freqs[mode];
> +}
> +
>  static int mmc_select_mode(struct mmc *mmc, enum bus_mode mode)
>  {
>         mmc->selected_mode = mode;
> +       mmc->tran_speed = mmc_mode2freq(mmc, mode);
>         debug("selecting mode %s (freq : %d MHz)\n", mmc_mode_name(mode),
>               mmc->tran_speed / 1000000);
>         return 0;
> @@ -1185,13 +1211,10 @@ static int sd_select_bus_freq_width(struct mmc *mmc)
>         if (err)
>                 return err;
>
> -       if (mmc->card_caps & MMC_MODE_HS) {
> +       if (mmc->card_caps & MMC_MODE_HS)
>                 mmc_select_mode(mmc, SD_HS);
> -               mmc->tran_speed = 50000000;
> -       } else {
> +       else
>                 mmc_select_mode(mmc, SD_LEGACY);
> -               mmc->tran_speed = 25000000;
> -       }
>
>         return 0;
>  }
> @@ -1310,11 +1333,8 @@ static int mmc_select_bus_freq_width(struct mmc *mmc)
>                         mmc_select_mode(mmc, MMC_DDR_52);
>                 else
>                         mmc_select_mode(mmc, MMC_HS_52);
> -               mmc->tran_speed = 52000000;
> -       } else if (mmc->card_caps & MMC_MODE_HS) {
> +       } else if (mmc->card_caps & MMC_MODE_HS)
>                 mmc_select_mode(mmc, MMC_HS);
> -               mmc->tran_speed = 26000000;
> -       }
>
>         return err;
>  }
> @@ -1584,7 +1604,6 @@ static int mmc_startup(struct mmc *mmc)
>         mult = multipliers[((cmd.response[0] >> 3) & 0xf)];
>
>         mmc->legacy_speed = freq * mult;
> -       mmc->tran_speed = mmc->legacy_speed;
>         mmc_select_mode(mmc, MMC_LEGACY);
>
>         mmc->dsr_imp = ((cmd.response[1] >> 12) & 0x1);
> @@ -1659,7 +1678,6 @@ static int mmc_startup(struct mmc *mmc)
>         if (err)
>                 return err;
>
> -       mmc_set_clock(mmc, mmc->tran_speed);
>
>         /* Fix the block length for DDR mode */
>         if (mmc->ddr_mode) {
> --
> 1.9.1
>


More information about the U-Boot mailing list