From 1b313aa3e33de09db7b48de5d325fd22e73e1f47 Mon Sep 17 00:00:00 2001 From: Jaehoon Chung Date: Tue, 30 Jan 2018 14:10:16 +0900 Subject: [PATCH 1/7] mmc: synchronize the sequence with enum bus_mode in mmc.h If some configs are disabled, number of freqs array will not assigned to correct value with bus_mode. Synchornize the ordering with enum bus_mode in mmc.h. Signed-off-by: Jaehoon Chung --- drivers/mmc/mmc.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index fb303dc21e..5d9b54149a 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -181,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) From 8a856db238072dbee370cb0f01648fe0462fe677 Mon Sep 17 00:00:00 2001 From: Faiz Abbas Date: Mon, 12 Feb 2018 19:35:24 +0530 Subject: [PATCH 2/7] mmc: Drop unnecessary case for mmc_probe() Drop the unnecessary empty function case for mmc_probe(). Signed-off-by: Faiz Abbas --- drivers/mmc/mmc.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 5d9b54149a..31f65f6e24 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -2653,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; From 76584e33988fc9f6c80199e04ca6e249baf7289a Mon Sep 17 00:00:00 2001 From: Alexander Kochetkov Date: Tue, 20 Feb 2018 14:35:55 +0300 Subject: [PATCH 3/7] mmc: fix off-by-one bug in mmc_startup_v4() MMC card with EXT_CSD_REV value 9 will trigger off-by-one bug while accessing mmc_versions array. The patch fix that. Signed-off-by: Alexander Kochetkov --- drivers/mmc/mmc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 31f65f6e24..c930893300 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -1969,7 +1969,7 @@ static int mmc_startup_v4(struct mmc *mmc) return -ENOMEM; memcpy(mmc->ext_csd, ext_csd, MMC_MAX_BLOCK_LEN); - if (ext_csd[EXT_CSD_REV] > ARRAY_SIZE(mmc_versions)) + if (ext_csd[EXT_CSD_REV] >= ARRAY_SIZE(mmc_versions)) return -EINVAL; mmc->version = mmc_versions[ext_csd[EXT_CSD_REV]]; From 45530e3943445f2787dc254cc12c58810b9e840f Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Fri, 23 Feb 2018 10:40:16 +0100 Subject: [PATCH 4/7] mmc: omap_hsmmc: do not embed struct mmc in struct omap_hsmmc_plat The area for struct mmc can be allocated dynamically. It greatly reduces the size of struct omap_hsmmc_plat. This is useful in cases where the board level code declares one or two struct omap_hsmmc_plat because it doesn't use the Driver Model. This saves around 740 bytes for the am335x_evm SPL. Signed-off-by: Jean-Jacques Hiblot Tested-by: Adam Ford Reviewed-by: Tom Rini --- arch/arm/include/asm/omap_mmc.h | 2 +- drivers/mmc/omap_hsmmc.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/arm/include/asm/omap_mmc.h b/arch/arm/include/asm/omap_mmc.h index 3d70148882..42ce8dcd6d 100644 --- a/arch/arm/include/asm/omap_mmc.h +++ b/arch/arm/include/asm/omap_mmc.h @@ -67,7 +67,7 @@ struct hsmmc { struct omap_hsmmc_plat { struct mmc_config cfg; struct hsmmc *base_addr; - struct mmc mmc; + struct mmc *mmc; bool cd_inverted; u32 controller_flags; const char *hw_rev; diff --git a/drivers/mmc/omap_hsmmc.c b/drivers/mmc/omap_hsmmc.c index 02970f29b2..e0b679aa2c 100644 --- a/drivers/mmc/omap_hsmmc.c +++ b/drivers/mmc/omap_hsmmc.c @@ -1858,8 +1858,8 @@ static int omap_hsmmc_ofdata_to_platdata(struct udevice *dev) static int omap_hsmmc_bind(struct udevice *dev) { struct omap_hsmmc_plat *plat = dev_get_platdata(dev); - - return mmc_bind(dev, &plat->mmc, &plat->cfg); + plat->mmc = calloc(1, sizeof(struct mmc)); + return mmc_bind(dev, plat->mmc, &plat->cfg); } #endif static int omap_hsmmc_probe(struct udevice *dev) @@ -1882,7 +1882,7 @@ static int omap_hsmmc_probe(struct udevice *dev) #endif #ifdef CONFIG_BLK - mmc = &plat->mmc; + mmc = plat->mmc; #else mmc = mmc_create(cfg, priv); if (mmc == NULL) From c7d08d80c3e792bfbd239b5aafccd5134e91251d Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Fri, 23 Feb 2018 10:40:17 +0100 Subject: [PATCH 5/7] mmc: omap_hsmmc: compile out write support if not needed This reduces the size of the binary by about 196 bytes. Signed-off-by: Jean-Jacques Hiblot Tested-by: Adam Ford Reviewed-by: Tom Rini --- drivers/mmc/omap_hsmmc.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/omap_hsmmc.c b/drivers/mmc/omap_hsmmc.c index e0b679aa2c..8b57edc14a 100644 --- a/drivers/mmc/omap_hsmmc.c +++ b/drivers/mmc/omap_hsmmc.c @@ -1181,8 +1181,9 @@ static int mmc_read_data(struct hsmmc *mmc_base, char *buf, unsigned int size) return 0; } +#if CONFIG_IS_ENABLED(MMC_WRITE) static int mmc_write_data(struct hsmmc *mmc_base, const char *buf, - unsigned int size) + unsigned int size) { unsigned int *input_buf = (unsigned int *)buf; unsigned int mmc_stat; @@ -1235,7 +1236,13 @@ static int mmc_write_data(struct hsmmc *mmc_base, const char *buf, } return 0; } - +#else +static int mmc_write_data(struct hsmmc *mmc_base, const char *buf, + unsigned int size) +{ + return -ENOTSUPP; +} +#endif static void omap_hsmmc_stop_clock(struct hsmmc *mmc_base) { writel(readl(&mmc_base->sysctl) & ~CEN_ENABLE, &mmc_base->sysctl); From 27a4b3bc4c165695cac65e92a5cb2537367a2392 Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Fri, 23 Feb 2018 10:40:18 +0100 Subject: [PATCH 6/7] mmc: omap_hsmmc: make it possible to compile out ADMA support Some platforms don't have ADMA controllers. For those platforms, compiling it out reduces the size of the binary by about 600 bytes. Leaving the support in doesn't break things as the driver checks at runtime if the ADMA2 controller is present. Signed-off-by: Jean-Jacques Hiblot Tested-by: Adam Ford Reviewed-by: Tom Rini --- drivers/mmc/Kconfig | 9 +++++++++ drivers/mmc/omap_hsmmc.c | 12 ++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig index f2d8256582..88a13591ad 100644 --- a/drivers/mmc/Kconfig +++ b/drivers/mmc/Kconfig @@ -239,6 +239,15 @@ config MMC_OMAP_HS If unsure, say N. +config MMC_OMAP_HS_ADMA + bool "ADMA support for OMAP HS MMC" + depends on MMC_OMAP_HS && !OMAP34XX + default y if !AM33XX + help + This enables support for the ADMA2 controller (SDA3.00 Part A2 DMA + controller). If supported by the hardware, selecting this option will + increase performances. + config MMC_OMAP36XX_PINS bool "Enable MMC1 on OMAP36xx/37xx" depends on OMAP34XX && MMC_OMAP_HS diff --git a/drivers/mmc/omap_hsmmc.c b/drivers/mmc/omap_hsmmc.c index 8b57edc14a..3d2836d9da 100644 --- a/drivers/mmc/omap_hsmmc.c +++ b/drivers/mmc/omap_hsmmc.c @@ -93,7 +93,7 @@ struct omap_hsmmc_data { enum bus_mode mode; #endif u8 controller_flags; -#ifndef CONFIG_OMAP34XX +#ifdef CONFIG_MMC_OMAP_HS_ADMA struct omap_hsmmc_adma_desc *adma_desc_table; uint desc_slot; #endif @@ -117,7 +117,7 @@ struct omap_mmc_of_data { u8 controller_flags; }; -#ifndef CONFIG_OMAP34XX +#ifdef CONFIG_MMC_OMAP_HS_ADMA struct omap_hsmmc_adma_desc { u8 attr; u8 reserved; @@ -741,7 +741,7 @@ static int omap_hsmmc_init_setup(struct mmc *mmc) return -ETIMEDOUT; } } -#ifndef CONFIG_OMAP34XX +#ifdef CONFIG_MMC_OMAP_HS_ADMA reg_val = readl(&mmc_base->hl_hwinfo); if (reg_val & MADMA_EN) priv->controller_flags |= OMAP_HSMMC_USE_ADMA; @@ -834,7 +834,7 @@ static void mmc_reset_controller_fsm(struct hsmmc *mmc_base, u32 bit) } } -#ifndef CONFIG_OMAP34XX +#ifdef CONFIG_MMC_OMAP_HS_ADMA static void omap_hsmmc_adma_desc(struct mmc *mmc, char *buf, u16 len, bool end) { struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc); @@ -1037,7 +1037,7 @@ static int omap_hsmmc_send_cmd(struct udevice *dev, struct mmc_cmd *cmd, else flags |= (DP_DATA | DDIR_WRITE); -#ifndef CONFIG_OMAP34XX +#ifdef CONFIG_MMC_OMAP_HS_ADMA if ((priv->controller_flags & OMAP_HSMMC_USE_ADMA) && !mmc_is_tuning_cmd(cmd->cmdidx)) { omap_hsmmc_prepare_data(mmc, data); @@ -1082,7 +1082,7 @@ static int omap_hsmmc_send_cmd(struct udevice *dev, struct mmc_cmd *cmd, } } -#ifndef CONFIG_OMAP34XX +#ifdef CONFIG_MMC_OMAP_HS_ADMA if ((priv->controller_flags & OMAP_HSMMC_USE_ADMA) && data && !mmc_is_tuning_cmd(cmd->cmdidx)) { u32 sz_mb, timeout; From beac7d33d9131d22ffbdbfbf2786858062b63786 Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Fri, 23 Feb 2018 10:40:19 +0100 Subject: [PATCH 7/7] mmc: omap_hsmmc: use a default 52MHz max clock rate if none is specified mmc_of_parse() doesn't set a default value if none is available in DT. In that case, use a default 52MHz clock rate. Signed-off-by: Alex Kiernan Signed-off-by: Jean-Jacques Hiblot Tested-by: Adam Ford Reviewed-by: Tom Rini --- drivers/mmc/omap_hsmmc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/mmc/omap_hsmmc.c b/drivers/mmc/omap_hsmmc.c index 3d2836d9da..caaa914604 100644 --- a/drivers/mmc/omap_hsmmc.c +++ b/drivers/mmc/omap_hsmmc.c @@ -1832,6 +1832,8 @@ static int omap_hsmmc_ofdata_to_platdata(struct udevice *dev) if (ret < 0) return ret; + if (!cfg->f_max) + cfg->f_max = 52000000; cfg->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS; cfg->f_min = 400000; cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195;