Skip to contentSkip to conversation

mmc: Cleanup time for mmc_struct

PATCH New Pantelis Antoniou 3 participants 10 messages Mar 12, 2014 – Mar 14, 2014

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover mmc: Cleanup time for mmc_struct

Struct mmc has picked up a lot of cruft over the years.

It is time for it to be split in 3 parts; the original mmc struct containing the state, the mmc_config struct containing the board setup configuration and the mmc_ops struct contains the method pointers.

Using the new config structures the mmc device creation now gets much more easier by using the new mmc_create() call

Pantelis Antoniou (3):
mmc: Remove ops from struct mmc and put in mmc_ops
mmc: Convert mmc struct's name array to a pointer
mmc: Split mmc struct, rework mmc initialization

 arch/arm/include/asm/arch-davinci/sdmmc_defs.h |   1 +
 arch/arm/include/asm/arch-tegra/tegra_mmc.h    |   4 +
 common/cmd_mmc.c                               |   2 +-
 common/cmd_mmc_spi.c                           |   2 +-
 drivers/mmc/arm_pl180_mmci.c                   |  50 +++++----
 drivers/mmc/arm_pl180_mmci.h                   |   4 +
 drivers/mmc/bfin_sdh.c                         |  40 +++----
 drivers/mmc/davinci_mmc.c                      |  41 ++++---
 drivers/mmc/dw_mmc.c                           |  58 +++++-----
 drivers/mmc/fsl_esdhc.c                        |  65 +++++------
 drivers/mmc/ftsdc010_mci.c                     |  63 +++++------
 drivers/mmc/gen_atmel_mci.c                    |  53 +++++----
 drivers/mmc/mmc.c                              |  88 +++++++++------
 drivers/mmc/mmc_spi.c                          |  50 +++++----
 drivers/mmc/mmc_write.c                        |   3 +-
 drivers/mmc/mxcmmc.c                           |  45 ++++----
 drivers/mmc/mxsmmc.c                           |  48 ++++-----
 drivers/mmc/omap_hsmmc.c                       | 142 +++++++++++++++----------
 drivers/mmc/pxa_mmc_gen.c                      |  70 ++++++------
 drivers/mmc/sdhci.c                            |  84 ++++++++-------
 drivers/mmc/sh_mmcif.c                         |  52 ++++-----
 drivers/mmc/tegra_mmc.c                        |  53 ++++-----
 include/dwmmc.h                                |   2 +
 include/fsl_esdhc.h                            |   4 +
 include/mmc.h                                  |  48 ++++++---
 include/sdhci.h                                |   2 +
 26 files changed, 590 insertions(+), 484 deletions(-)
Signature · 1 line
1.7.12
#1 lore raw

PATCH 1/3 mmc: Remove ops from struct mmc and put in mmc_ops

Remove the in-structure ops and put them in mmc_ops with a constant pointer to it.

This makes the mmc structure smaller as well as conserving code space (in theory).

All in-tree drivers are converted as well; this is done in a single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was not set.

---
 drivers/mmc/arm_pl180_mmci.c | 12 +++---
 drivers/mmc/bfin_sdh.c       | 11 +++---
 drivers/mmc/davinci_mmc.c    | 13 ++++---
 drivers/mmc/dw_mmc.c         | 10 +++--
 drivers/mmc/fsl_esdhc.c      | 14 ++++---
 drivers/mmc/ftsdc010_mci.c   | 11 ++++--
 drivers/mmc/gen_atmel_mci.c  | 12 +++---
 drivers/mmc/mmc.c            | 21 ++++++-----
 drivers/mmc/mmc_spi.c        | 12 +++---
 drivers/mmc/mxcmmc.c         | 12 +++---
 drivers/mmc/mxsmmc.c         | 12 +++---
 drivers/mmc/omap_hsmmc.c     | 89 ++++++++++++++++++++++++++++----------------
 drivers/mmc/pxa_mmc_gen.c    | 11 ++++--
 drivers/mmc/sdhci.c          | 13 ++++---
 drivers/mmc/sh_mmcif.c       | 12 +++---
 drivers/mmc/tegra_mmc.c      | 19 ++++++----
 include/mmc.h                | 19 +++++++---
 17 files changed, 184 insertions(+), 119 deletions(-)
drivers/mmc/arm_pl180_mmci.c +7 -5
index 5a55fe7..4490e97 100644
@@ -335,6 +335,12 @@ static void host_set_ios(struct mmc *dev)
 	udelay(CLK_CHANGE_DELAY);
 }
 
+static const struct mmc_ops arm_pl180_mmci_ops = {
+	.send_cmd = host_request,
+	.set_ios = host_set_ios,
+	.init = mmc_host_reset,
+};
+
 /*
  * mmc_host_init - initialize the mmc controller.
  * Set initial clock and power for mmc slot.
@@ -360,11 +366,7 @@ int arm_pl180_mmci_init(struct pl180_mmc_host *host)
 	sdi_u32 = readl(&host->base->mask0) & ~SDI_MASK0_MASK;
 	writel(sdi_u32, &host->base->mask0);
 	strncpy(dev->name, host->name, sizeof(dev->name));
-	dev->send_cmd = host_request;
-	dev->set_ios = host_set_ios;
-	dev->init = mmc_host_reset;
-	dev->getcd = NULL;
-	dev->getwp = NULL;
+	dev->ops = &arm_pl180_mmci_ops;
 	dev->host_caps = host->caps;
 	dev->voltages = host->voltages;
 	dev->f_min = host->clock_min;
drivers/mmc/bfin_sdh.c +6 -5
index bd9b641..f0871ec 100644
@@ -274,6 +274,11 @@ static int bfin_sdh_init(struct mmc *mmc)
 	return 0;
 }
 
+static const struct mmc_ops bfin_mmc_ops = {
+	.send_cmd	= bfin_sdh_request,
+	.set_ios	= bfin_sdh_set_ios,
+	.init		= bfin_sdh_init,
+};
 
 int bfin_mmc_init(bd_t *bis)
 {
@@ -284,11 +289,7 @@ int bfin_mmc_init(bd_t *bis)
 	if (!mmc)
 		return -ENOMEM;
 	sprintf(mmc->name, "Blackfin SDH");
-	mmc->send_cmd = bfin_sdh_request;
-	mmc->set_ios = bfin_sdh_set_ios;
-	mmc->init = bfin_sdh_init;
-	mmc->getcd = NULL;
-	mmc->getwp = NULL;
+	mmc->ops = &bfin_mmc_ops;
 	mmc->host_caps = MMC_MODE_4BIT;
 
 	mmc->voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
drivers/mmc/davinci_mmc.c +7 -6
index b380961..29ca4a6 100644
@@ -363,6 +363,12 @@ static void dmmc_set_ios(struct mmc *mmc)
 		dmmc_set_clock(mmc, mmc->clock);
 }
 
+static const struct mmc_ops dmmc_ops = {
+	.send_cmd	= dmmc_send_cmd,
+	.set_ios	= dmmc_set_ios,
+	.init		= dmmc_init,
+};
+
 /* Called from board_mmc_init during startup. Can be called multiple times
  * depending on the number of slots available on board and controller
  */
@@ -375,12 +381,7 @@ int davinci_mmc_init(bd_t *bis, struct davinci_mmc *host)
 
 	sprintf(mmc->name, "davinci");
 	mmc->priv = host;
-	mmc->send_cmd = dmmc_send_cmd;
-	mmc->set_ios = dmmc_set_ios;
-	mmc->init = dmmc_init;
-	mmc->getcd = NULL;
-	mmc->getwp = NULL;
-
+	mmc->ops = &dmmc_ops;
 	mmc->f_min = 200000;
 	mmc->f_max = 25000000;
 	mmc->voltages = host->voltages;
drivers/mmc/dw_mmc.c +7 -3
index d45c15c..2e6576e 100644
@@ -343,6 +343,12 @@ static int dwmci_init(struct mmc *mmc)
 	return 0;
 }
 
+static const struct mmc_ops dwmci_ops = {
+	.send_cmd	= dwmci_send_cmd,
+	.set_ios	= dwmci_set_ios,
+	.init		= dwmci_init,
+};
+
 int add_dwmci(struct dwmci_host *host, u32 max_clk, u32 min_clk)
 {
 	struct mmc *mmc;
@@ -358,9 +364,7 @@ int add_dwmci(struct dwmci_host *host, u32 max_clk, u32 min_clk)
 	host->mmc = mmc;
 
 	sprintf(mmc->name, "%s", host->name);
-	mmc->send_cmd = dwmci_send_cmd;
-	mmc->set_ios = dwmci_set_ios;
-	mmc->init = dwmci_init;
+	mmc->ops = &dwmci_ops;
 	mmc->f_min = min_clk;
 	mmc->f_max = max_clk;
 
drivers/mmc/fsl_esdhc.c +8 -6
index 7b146a3..861f536 100644
@@ -524,6 +524,13 @@ static void esdhc_reset(struct fsl_esdhc *regs)
 		printf("MMC/SD: Reset never completed.\n");
 }
 
+static const struct mmc_ops esdhc_ops = {
+	.send_cmd	= esdhc_send_cmd,
+	.set_ios	= esdhc_set_ios,
+	.init		= esdhc_init,
+	.getcd		= esdhc_getcd,
+};
+
 int fsl_esdhc_initialize(bd_t *bis, struct fsl_esdhc_cfg *cfg)
 {
 	struct fsl_esdhc *regs;
@@ -548,12 +555,7 @@ int fsl_esdhc_initialize(bd_t *bis, struct fsl_esdhc_cfg *cfg)
 				| SYSCTL_IPGEN | SYSCTL_CKEN);
 
 	mmc->priv = cfg;
-	mmc->send_cmd = esdhc_send_cmd;
-	mmc->set_ios = esdhc_set_ios;
-	mmc->init = esdhc_init;
-	mmc->getcd = esdhc_getcd;
-	mmc->getwp = NULL;
-
+	mmc->ops = &esdhc_ops;
 	voltage_caps = 0;
 	caps = regs->hostcapblt;
 
drivers/mmc/ftsdc010_mci.c +7 -4
index 7600d5c..ce43ae1 100644
@@ -316,6 +316,12 @@ static int ftsdc010_init(struct mmc *mmc)
 	return 0;
 }
 
+static const struct mmc_ops ftsdc010_ops = {
+	.send_cmd	= ftsdc010_request,
+	.set_ios	= ftsdc010_set_ios,
+	.init		= ftsdc010_init,
+};
+
 int ftsdc010_mmc_init(int devid)
 {
 	struct mmc *mmc;
@@ -347,10 +353,7 @@ int ftsdc010_mmc_init(int devid)
 	mmc->priv  = chip;
 
 	sprintf(mmc->name, "ftsdc010");
-	mmc->send_cmd  = ftsdc010_request;
-	mmc->set_ios   = ftsdc010_set_ios;
-	mmc->init      = ftsdc010_init;
-
+	mmc->ops = &ftsdc010_ops;
 	mmc->host_caps = MMC_MODE_HS | MMC_MODE_HS_52MHz;
 	switch (readl(&regs->bwr) & FTSDC010_BWR_CAPS_MASK) {
 	case FTSDC010_BWR_CAPS_4BIT:
drivers/mmc/gen_atmel_mci.c +7 -5
index c11dcd0..456f8bf 100644
@@ -344,6 +344,12 @@ static int mci_init(struct mmc *mmc)
 	return 0;
 }
 
+static const struct mmc_ops atmel_mci_ops = {
+	.send_cmd	= mci_send_cmd,
+	.set_ios	= mci_set_ios,
+	.init		= mci_init,
+};
+
 /*
  * This is the only exported function
  *
@@ -360,11 +366,7 @@ int atmel_mci_init(void *regs)
 
 	strcpy(mmc->name, "mci");
 	mmc->priv = regs;
-	mmc->send_cmd = mci_send_cmd;
-	mmc->set_ios = mci_set_ios;
-	mmc->init = mci_init;
-	mmc->getcd = NULL;
-	mmc->getwp = NULL;
+	mmc->ops = &atmel_mci_ops;
 
 	/* need to be able to pass these in on a board by board basis */
 	mmc->voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
drivers/mmc/mmc.c +12 -9
index 8ab0bc9..ac07bb9 100644
@@ -37,8 +37,8 @@ int mmc_getwp(struct mmc *mmc)
 	wp = board_mmc_getwp(mmc);
 
 	if (wp < 0) {
-		if (mmc->getwp)
-			wp = mmc->getwp(mmc);
+		if (mmc->ops->getwp)
+			wp = mmc->ops->getwp(mmc);
 		else
 			wp = 0;
 	}
@@ -63,7 +63,7 @@ int mmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
 
 	printf("CMD_SEND:%d\n", cmd->cmdidx);
 	printf("\t\tARG\t\t\t 0x%08X\n", cmd->cmdarg);
-	ret = mmc->send_cmd(mmc, cmd, data);
+	ret = mmc->ops->send_cmd(mmc, cmd, data);
 	switch (cmd->resp_type) {
 		case MMC_RSP_NONE:
 			printf("\t\tMMC_RSP_NONE\n");
@@ -106,7 +106,7 @@ int mmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
 			break;
 	}
 #else
-	ret = mmc->send_cmd(mmc, cmd, data);
+	ret = mmc->ops->send_cmd(mmc, cmd, data);
 #endif
 	return ret;
 }
@@ -578,8 +578,8 @@ int mmc_getcd(struct mmc *mmc)
 	cd = board_mmc_getcd(mmc);
 
 	if (cd < 0) {
-		if (mmc->getcd)
-			cd = mmc->getcd(mmc);
+		if (mmc->ops->getcd)
+			cd = mmc->ops->getcd(mmc);
 		else
 			cd = 1;
 	}
@@ -751,7 +751,8 @@ static const int multipliers[] = {
 
 static void mmc_set_ios(struct mmc *mmc)
 {
-	mmc->set_ios(mmc);
+	if (mmc->ops->set_ios)
+		mmc->ops->set_ios(mmc);
 }
 
 void mmc_set_clock(struct mmc *mmc, uint clock)
@@ -1207,7 +1208,8 @@ int mmc_start_init(struct mmc *mmc)
 {
 	int err;
 
-	if (mmc_getcd(mmc) == 0) {
+	/* we pretend there's no card when init is NULL */
+	if (mmc_getcd(mmc) == 0 || mmc->ops->init == NULL) {
 		mmc->has_init = 0;
 #if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
 		printf("MMC: no card present\n");
@@ -1218,7 +1220,8 @@ int mmc_start_init(struct mmc *mmc)
 	if (mmc->has_init)
 		return 0;
 
-	err = mmc->init(mmc);
+	/* made sure it's not NULL earlier */
+	err = mmc->ops->init(mmc);
 
 	if (err)
 		return err;
drivers/mmc/mmc_spi.c +7 -5
index fe6a5a1..0a0f894 100644
@@ -255,6 +255,12 @@ static int mmc_spi_init_p(struct mmc *mmc)
 	return 0;
 }
 
+static const struct mmc_ops mmc_spi_ops = {
+	.send_cmd	= mmc_spi_request,
+	.set_ios	= mmc_spi_set_ios,
+	.init		= mmc_spi_init_p,
+};
+
 struct mmc *mmc_spi_init(uint bus, uint cs, uint speed, uint mode)
 {
 	struct mmc *mmc;
@@ -269,11 +275,7 @@ struct mmc *mmc_spi_init(uint bus, uint cs, uint speed, uint mode)
 		return NULL;
 	}
 	sprintf(mmc->name, "MMC_SPI");
-	mmc->send_cmd = mmc_spi_request;
-	mmc->set_ios = mmc_spi_set_ios;
-	mmc->init = mmc_spi_init_p;
-	mmc->getcd = NULL;
-	mmc->getwp = NULL;
+	mmc->ops = &mmc_spi_ops;
 	mmc->host_caps = MMC_MODE_SPI;
 
 	mmc->voltages = MMC_SPI_VOLTAGE;
drivers/mmc/mxcmmc.c +7 -5
index 4f99617..f3e1eed 100644
@@ -485,6 +485,12 @@ static int mxcmci_init(struct mmc *mmc)
 	return 0;
 }
 
+static const struct mmc_ops mxcmci_ops = {
+	.send_cmd	= mxcmci_request,
+	.set_ios	= mxcmci_set_ios,
+	.init		= mxcmci_init,
+};
+
 static int mxcmci_initialize(bd_t *bis)
 {
 	struct mmc *mmc = NULL;
@@ -495,11 +501,7 @@ static int mxcmci_initialize(bd_t *bis)
 		return -ENOMEM;
 
 	sprintf(mmc->name, "MXC MCI");
-	mmc->send_cmd = mxcmci_request;
-	mmc->set_ios = mxcmci_set_ios;
-	mmc->init = mxcmci_init;
-	mmc->getcd = NULL;
-	mmc->getwp = NULL;
+	mmc->ops = &mxcmci_ops;
 	mmc->host_caps = MMC_MODE_4BIT;
 
 	host->base = (struct mxcmci_regs *)CONFIG_MXC_MCI_REGS_BASE;
drivers/mmc/mxsmmc.c +7 -5
index 245f9d0..97c9ee8 100644
@@ -363,6 +363,12 @@ static int mxsmmc_init(struct mmc *mmc)
 	return 0;
 }
 
+static const struct mmc_ops mxsmmc_ops = {
+	.send_cmd	= mxsmmc_send_cmd,
+	.set_ios	= mxsmmc_set_ios,
+	.init		= mxsmmc_init,
+};
+
 int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int), int (*cd)(int))
 {
 	struct mmc *mmc = NULL;
@@ -400,11 +406,7 @@ int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int), int (*cd)(int))
 	priv->regs = mxs_ssp_regs_by_bus(id);
 
 	sprintf(mmc->name, "MXS MMC");
-	mmc->send_cmd = mxsmmc_send_cmd;
-	mmc->set_ios = mxsmmc_set_ios;
-	mmc->init = mxsmmc_init;
-	mmc->getcd = NULL;
-	mmc->getwp = NULL;
+	mmc->ops = &mxsmmc_ops;
 	mmc->priv = priv;
 
 	mmc->voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
drivers/mmc/omap_hsmmc.c +56 -33

153 lines not on this page · raw message

drivers/mmc/pxa_mmc_gen.c +7 -4
index 29f3eaf..4694c8f 100644
@@ -366,6 +366,12 @@ static int pxa_mmc_init(struct mmc *mmc)
 	return 0;
 }
 
+static const struct mmc_ops pxa_mmc_ops = {
+	.send_cmd	= pxa_mmc_request,
+	.set_ios	= pxa_mmc_set_ios,
+	.init		= pxa_mmc_init,
+};
+
 int pxa_mmc_register(int card_index)
 {
 	struct mmc *mmc;
@@ -397,10 +403,7 @@ int pxa_mmc_register(int card_index)
 	mmc->priv = priv;
 
 	sprintf(mmc->name, "PXA MMC");
-	mmc->send_cmd	= pxa_mmc_request;
-	mmc->set_ios	= pxa_mmc_set_ios;
-	mmc->init	= pxa_mmc_init;
-	mmc->getcd	= NULL;
+	mmc->ops = &pxa_mmc_ops;
 
 	mmc->voltages	= MMC_VDD_32_33 | MMC_VDD_33_34;
 	mmc->f_max	= PXAMMC_MAX_SPEED;
drivers/mmc/sdhci.c +8 -5
index 1e86b92..c3425a6 100644
@@ -430,6 +430,13 @@ int sdhci_init(struct mmc *mmc)
 	return 0;
 }
 
+
+static const struct mmc_ops sdhci_ops = {
+	.send_cmd	= sdhci_send_command,
+	.set_ios	= sdhci_set_ios,
+	.init		= sdhci_init,
+};
+
 int add_sdhci(struct sdhci_host *host, u32 max_clk, u32 min_clk)
 {
 	struct mmc *mmc;
@@ -445,11 +452,7 @@ int add_sdhci(struct sdhci_host *host, u32 max_clk, u32 min_clk)
 	host->mmc = mmc;
 
 	sprintf(mmc->name, "%s", host->name);
-	mmc->send_cmd = sdhci_send_command;
-	mmc->set_ios = sdhci_set_ios;
-	mmc->init = sdhci_init;
-	mmc->getcd = NULL;
-	mmc->getwp = NULL;
+	mmc->ops = &sdhci_ops;
 
 	caps = sdhci_readl(host, SDHCI_CAPABILITIES);
 #ifdef CONFIG_MMC_SDMA
drivers/mmc/sh_mmcif.c +7 -5
index 011d4f3..6a4860b 100644
@@ -574,6 +574,12 @@ static int sh_mmcif_init(struct mmc *mmc)
 	return 0;
 }
 
+static const struct mmc_ops sh_mmcif_ops = {
+	.send_cmd	= sh_mmcif_request,
+	.set_ios	= sh_mmcif_set_ios,
+	.init		= sh_mmcif_init,
+};
+
 int mmcif_mmc_init(void)
 {
 	int ret = 0;
@@ -595,11 +601,7 @@ int mmcif_mmc_init(void)
 	mmc->host_caps = MMC_MODE_HS | MMC_MODE_HS_52MHz | MMC_MODE_4BIT |
 			 MMC_MODE_8BIT | MMC_MODE_HC;
 	memcpy(mmc->name, DRIVER_NAME, sizeof(DRIVER_NAME));
-	mmc->send_cmd = sh_mmcif_request;
-	mmc->set_ios = sh_mmcif_set_ios;
-	mmc->init = sh_mmcif_init;
-	mmc->getcd = NULL;
-	mmc->getwp = NULL;
+	mmc->ops = &sh_mmcif_ops;
 	host->regs = (struct sh_mmcif_regs *)CONFIG_SH_MMCIF_ADDR;
 	host->clk = CONFIG_SH_MMCIF_CLK;
 	mmc->priv = host;
drivers/mmc/tegra_mmc.c +11 -8
index 3d1ce12..5f7b590 100644
@@ -314,7 +314,7 @@ static int mmc_send_cmd_bounced(struct mmc *mmc, struct mmc_cmd *cmd,
 	return 0;
 }
 
-static int mmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
+static int tegra_mmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
 			struct mmc_data *data)
 {
 	void *buf;
@@ -396,7 +396,7 @@ out:
 	host->clock = clock;
 }
 
-static void mmc_set_ios(struct mmc *mmc)
+static void tegra_mmc_set_ios(struct mmc *mmc)
 {
 	struct mmc_host *host = mmc->priv;
 	unsigned char ctrl;
@@ -464,7 +464,7 @@ static void mmc_reset(struct mmc_host *host, struct mmc *mmc)
 	pad_init_mmc(host);
 }
 
-static int mmc_core_init(struct mmc *mmc)
+static int tegra_mmc_core_init(struct mmc *mmc)
 {
 	struct mmc_host *host = (struct mmc_host *)mmc->priv;
 	unsigned int mask;
@@ -521,6 +521,13 @@ int tegra_mmc_getcd(struct mmc *mmc)
 	return 1;
 }
 
+static const struct mmc_ops tegra_mmc_ops = {
+	.send_cmd	= tegra_mmc_send_cmd,
+	.set_ios	= tegra_mmc_set_ios,
+	.init		= tegra_mmc_core_init,
+	.getcd		= tegra_mmc_getcd,
+};
+
 static int do_mmc_init(int dev_index)
 {
 	struct mmc_host *host;
@@ -558,11 +565,7 @@ static int do_mmc_init(int dev_index)
 
 	sprintf(mmc->name, "Tegra SD/MMC");
 	mmc->priv = host;
-	mmc->send_cmd = mmc_send_cmd;
-	mmc->set_ios = mmc_set_ios;
-	mmc->init = mmc_core_init;
-	mmc->getcd = tegra_mmc_getcd;
-	mmc->getwp = NULL;
+	mmc->ops = &tegra_mmc_ops;
 
 	mmc->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195;
 	mmc->host_caps = 0;
include/mmc.h +13 -6
index e95a237..3d53ce1 100644
@@ -250,6 +250,18 @@ struct mmc_data {
 	uint blocksize;
 };
 
+/* forward decl. */
+struct mmc;
+
+struct mmc_ops {
+	int (*send_cmd)(struct mmc *mmc,
+			struct mmc_cmd *cmd, struct mmc_data *data);
+	void (*set_ios)(struct mmc *mmc);
+	int (*init)(struct mmc *mmc);
+	int (*getcd)(struct mmc *mmc);
+	int (*getwp)(struct mmc *mmc);
+};
+
 struct mmc {
 	struct list_head link;
 	char name[32];
@@ -283,12 +295,7 @@ struct mmc {
 	u64 capacity_rpmb;
 	u64 capacity_gp[4];
 	block_dev_desc_t block_dev;
-	int (*send_cmd)(struct mmc *mmc,
-			struct mmc_cmd *cmd, struct mmc_data *data);
-	void (*set_ios)(struct mmc *mmc);
-	int (*init)(struct mmc *mmc);
-	int (*getcd)(struct mmc *mmc);
-	int (*getwp)(struct mmc *mmc);
+	const struct mmc_ops *ops;
 	uint b_max;
 	char op_cond_pending;	/* 1 if we are waiting on an op_cond command */
 	char init_in_progress;	/* 1 if we have done mmc_start_init() */
Signature · 1 line
1.7.12
#2 lore raw

PATCH 1/3 mmc: Remove ops from struct mmc and put in mmc_ops

Hi,

Quoted 5 lines · Pantelis Antoniou

Remove the in-structure ops and put them in mmc_ops with a constant pointer to it.

This makes the mmc structure smaller as well as conserving code space (in theory).

You might be able to run buildman (and use -S) to check this.

These changes look good to me, and will make it easier to move to driver model I suspect.

Regards,
Simon

Quoted 9 lines

All in-tree drivers are converted as well; this is done in a single patch in order to not break git bisect.

Changes since V1:
Fix compilation b0rked issue on omap platforms where OMAP_GPIO was not set.

#3 lore raw

PATCH 1/3 mmc: Remove ops from struct mmc and put in mmc_ops

Quoted 3 lines · Simon Glass

Hi,

On 12 March 2014 04:24, Pantelis Antoniou <[email protected]>

Quoted 10 lines · wrote:
Quoted 5 lines

Remove the in-structure ops and put them in mmc_ops with a constant pointer to it.

This makes the mmc structure smaller as well as conserving code space (in theory).

You might be able to run buildman (and use -S) to check this.

These changes look good to me, and will make it easier to move to driver model I suspect.

Full ack on the driver model part.

Best regards,
Marek Vasut

#4 lore raw

PATCH 2/3 mmc: Convert mmc struct's name array to a pointer

In reply to Pantelis Antoniou

Using an array is pointless; even more pointless (and scary) is using sprintf to fill it without a format string.

---
 drivers/mmc/arm_pl180_mmci.c | 2 +-
 drivers/mmc/bfin_sdh.c       | 2 +-
 drivers/mmc/davinci_mmc.c    | 2 +-
 drivers/mmc/dw_mmc.c         | 2 +-
 drivers/mmc/fsl_esdhc.c      | 2 +-
 drivers/mmc/ftsdc010_mci.c   | 2 +-
 drivers/mmc/gen_atmel_mci.c  | 2 +-
 drivers/mmc/mmc_spi.c        | 2 +-
 drivers/mmc/mxcmmc.c         | 2 +-
 drivers/mmc/mxsmmc.c         | 2 +-
 drivers/mmc/omap_hsmmc.c     | 2 +-
 drivers/mmc/pxa_mmc_gen.c    | 2 +-
 drivers/mmc/sdhci.c          | 2 +-
 drivers/mmc/sh_mmcif.c       | 2 +-
 drivers/mmc/tegra_mmc.c      | 2 +-
 include/mmc.h                | 2 +-
 16 files changed, 16 insertions(+), 16 deletions(-)
drivers/mmc/arm_pl180_mmci.c +1 -1
index 4490e97..5a30590 100644
@@ -365,7 +365,7 @@ int arm_pl180_mmci_init(struct pl180_mmc_host *host)
 	/* Disable mmc interrupts */
 	sdi_u32 = readl(&host->base->mask0) & ~SDI_MASK0_MASK;
 	writel(sdi_u32, &host->base->mask0);
-	strncpy(dev->name, host->name, sizeof(dev->name));
+	dev->name = host->name;
 	dev->ops = &arm_pl180_mmci_ops;
 	dev->host_caps = host->caps;
 	dev->voltages = host->voltages;
drivers/mmc/bfin_sdh.c +1 -1
index f0871ec..5f6145b 100644
@@ -288,7 +288,7 @@ int bfin_mmc_init(bd_t *bis)
 
 	if (!mmc)
 		return -ENOMEM;
-	sprintf(mmc->name, "Blackfin SDH");
+	mmc->name = "Blackfin SDH";
 	mmc->ops = &bfin_mmc_ops;
 	mmc->host_caps = MMC_MODE_4BIT;
 
drivers/mmc/davinci_mmc.c +1 -1
index 29ca4a6..cae972a 100644
@@ -379,7 +379,7 @@ int davinci_mmc_init(bd_t *bis, struct davinci_mmc *host)
 	mmc = malloc(sizeof(struct mmc));
 	memset(mmc, 0, sizeof(struct mmc));
 
-	sprintf(mmc->name, "davinci");
+	mmc->name = "davinci";
 	mmc->priv = host;
 	mmc->ops = &dmmc_ops;
 	mmc->f_min = 200000;
drivers/mmc/dw_mmc.c +1 -1
index 2e6576e..011efb1 100644
@@ -363,7 +363,7 @@ int add_dwmci(struct dwmci_host *host, u32 max_clk, u32 min_clk)
 	mmc->priv = host;
 	host->mmc = mmc;
 
-	sprintf(mmc->name, "%s", host->name);
+	mmc->name = host->name;
 	mmc->ops = &dwmci_ops;
 	mmc->f_min = min_clk;
 	mmc->f_max = max_clk;
drivers/mmc/fsl_esdhc.c +1 -1
index 861f536..f66513e 100644
@@ -545,7 +545,7 @@ int fsl_esdhc_initialize(bd_t *bis, struct fsl_esdhc_cfg *cfg)
 		return -ENOMEM;
 
 	memset(mmc, 0, sizeof(struct mmc));
-	sprintf(mmc->name, "FSL_SDHC");
+	mmc->name = "FSL_SDHC";
 	regs = (struct fsl_esdhc *)cfg->esdhc_base;
 
 	/* First reset the eSDHC controller */
drivers/mmc/ftsdc010_mci.c +1 -1
index ce43ae1..b1673fc 100644
@@ -352,7 +352,7 @@ int ftsdc010_mmc_init(int devid)
 	chip->regs = regs;
 	mmc->priv  = chip;
 
-	sprintf(mmc->name, "ftsdc010");
+	mmc->name = "ftsdc010";
 	mmc->ops = &ftsdc010_ops;
 	mmc->host_caps = MMC_MODE_HS | MMC_MODE_HS_52MHz;
 	switch (readl(&regs->bwr) & FTSDC010_BWR_CAPS_MASK) {
drivers/mmc/gen_atmel_mci.c +1 -1
index 456f8bf..ce799f3 100644
@@ -364,7 +364,7 @@ int atmel_mci_init(void *regs)
 	if (!mmc)
 		return -1;
 
-	strcpy(mmc->name, "mci");
+	mmc->name = "mci";
 	mmc->priv = regs;
 	mmc->ops = &atmel_mci_ops;
 
drivers/mmc/mmc_spi.c +1 -1
index 0a0f894..e94de37 100644
@@ -274,7 +274,7 @@ struct mmc *mmc_spi_init(uint bus, uint cs, uint speed, uint mode)
 		free(mmc);
 		return NULL;
 	}
-	sprintf(mmc->name, "MMC_SPI");
+	mmc->name = "MMC_SPI";
 	mmc->ops = &mmc_spi_ops;
 	mmc->host_caps = MMC_MODE_SPI;
 
drivers/mmc/mxcmmc.c +1 -1
index f3e1eed..3357559 100644
@@ -500,7 +500,7 @@ static int mxcmci_initialize(bd_t *bis)
 	if (!mmc)
 		return -ENOMEM;
 
-	sprintf(mmc->name, "MXC MCI");
+	mmc->name = "MXC MCI";
 	mmc->ops = &mxcmci_ops;
 	mmc->host_caps = MMC_MODE_4BIT;
 
drivers/mmc/mxsmmc.c +1 -1
index 97c9ee8..3512a99 100644
@@ -405,7 +405,7 @@ int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int), int (*cd)(int))
 	priv->id = id;
 	priv->regs = mxs_ssp_regs_by_bus(id);
 
-	sprintf(mmc->name, "MXS MMC");
+	mmc->name = "MXS MMC";
 	mmc->ops = &mxsmmc_ops;
 	mmc->priv = priv;
 
drivers/mmc/omap_hsmmc.c +1 -1
index 6bf602f..fecac56 100644
@@ -641,7 +641,7 @@ int omap_mmc_init(int dev_index, uint host_caps_mask, uint f_max, int cd_gpio,
 	uint host_caps_val = MMC_MODE_4BIT | MMC_MODE_HS_52MHz | MMC_MODE_HS |
 			     MMC_MODE_HC;
 
-	sprintf(mmc->name, "OMAP SD/MMC");
+	mmc->name = "OMAP SD/MMC";
 	mmc->ops = &omap_hsmmc_ops;
 	mmc->priv = priv_data;
 
drivers/mmc/pxa_mmc_gen.c +1 -1
index 4694c8f..188e1d4 100644
@@ -402,7 +402,7 @@ int pxa_mmc_register(int card_index)
 
 	mmc->priv = priv;
 
-	sprintf(mmc->name, "PXA MMC");
+	mmc->name = "PXA MMC";
 	mmc->ops = &pxa_mmc_ops;
 
 	mmc->voltages	= MMC_VDD_32_33 | MMC_VDD_33_34;
drivers/mmc/sdhci.c +1 -1
index c3425a6..dc6f4e4 100644
@@ -451,7 +451,7 @@ int add_sdhci(struct sdhci_host *host, u32 max_clk, u32 min_clk)
 	mmc->priv = host;
 	host->mmc = mmc;
 
-	sprintf(mmc->name, "%s", host->name);
+	mmc->name = host->name;
 	mmc->ops = &sdhci_ops;
 
 	caps = sdhci_readl(host, SDHCI_CAPABILITIES);
drivers/mmc/sh_mmcif.c +1 -1
index 6a4860b..008617d 100644
@@ -600,7 +600,7 @@ int mmcif_mmc_init(void)
 	mmc->voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
 	mmc->host_caps = MMC_MODE_HS | MMC_MODE_HS_52MHz | MMC_MODE_4BIT |
 			 MMC_MODE_8BIT | MMC_MODE_HC;
-	memcpy(mmc->name, DRIVER_NAME, sizeof(DRIVER_NAME));
+	mmc->name = DRIVER_NAME;
 	mmc->ops = &sh_mmcif_ops;
 	host->regs = (struct sh_mmcif_regs *)CONFIG_SH_MMCIF_ADDR;
 	host->clk = CONFIG_SH_MMCIF_CLK;
drivers/mmc/tegra_mmc.c +1 -1
index 5f7b590..e8fbb63 100644
@@ -563,7 +563,7 @@ static int do_mmc_init(int dev_index)
 
 	mmc = &mmc_dev[dev_index];
 
-	sprintf(mmc->name, "Tegra SD/MMC");
+	mmc->name = "Tegra SD/MMC";
 	mmc->priv = host;
 	mmc->ops = &tegra_mmc_ops;
 
include/mmc.h +1 -1
index 3d53ce1..6b08c62 100644
@@ -264,7 +264,7 @@ struct mmc_ops {
 
 struct mmc {
 	struct list_head link;
-	char name[32];
+	const char *name;	/* no need for this to be an array */
 	void *priv;
 	uint voltages;
 	uint version;
Signature · 1 line
1.7.12
#5 lore raw

PATCH 2/3 mmc: Convert mmc struct's name array to a pointer

Hi,

Quoted 2 lines · Pantelis Antoniou

Using an array is pointless; even more pointless (and scary) is using sprintf to fill it without a format string.

This is certainly better, but how about an mmc structure init function which sets this up?

Regards,
Simon

#6 lore raw

PATCH 2/3 mmc: Convert mmc struct's name array to a pointer

Quoted 3 lines · Simon Glass

Hi,

On 12 March 2014 04:24, Pantelis Antoniou <[email protected]>

Quoted 5 lines · wrote:
Quoted 2 lines

Using an array is pointless; even more pointless (and scary) is using sprintf to fill it without a format string.

This is certainly better, but how about an mmc structure init function which sets this up?

You mean DM's .probe() ? :-)

Best regards,
Marek Vasut

#7 lore raw

PATCH 3/3 mmc: Split mmc struct, rework mmc initialization

In reply to Pantelis Antoniou

The way that struct mmc was implemented was a bit of a mess; configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

	struct mmc *mmc = malloc(sizeof(struct mmc));
	memset(mmc, 0, sizeof(struct mmc);
	/* fill in fields of mmc struct */
	/* store private data pointer */
	mmc_register(mmc);

By using the new mmc_create call one just passes an mmc config struct and an optional private data pointer like this:

	struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect mmc_register to go away before long.

---
 arch/arm/include/asm/arch-davinci/sdmmc_defs.h |  1 +
 arch/arm/include/asm/arch-tegra/tegra_mmc.h    |  4 ++
 common/cmd_mmc.c                               |  2 +-
 common/cmd_mmc_spi.c                           |  2 +-
 drivers/mmc/arm_pl180_mmci.c                   | 40 ++++++------
 drivers/mmc/arm_pl180_mmci.h                   |  4 ++
 drivers/mmc/bfin_sdh.c                         | 31 +++++----
 drivers/mmc/davinci_mmc.c                      | 30 ++++-----
 drivers/mmc/dw_mmc.c                           | 50 +++++++--------
 drivers/mmc/fsl_esdhc.c                        | 55 ++++++++--------
 drivers/mmc/ftsdc010_mci.c                     | 54 +++++++---------
 drivers/mmc/gen_atmel_mci.c                    | 43 ++++++++-----
 drivers/mmc/mmc.c                              | 87 +++++++++++++++++---------
 drivers/mmc/mmc_spi.c                          | 40 ++++++------
 drivers/mmc/mmc_write.c                        |  3 +-
 drivers/mmc/mxcmmc.c                           | 35 +++++------
 drivers/mmc/mxsmmc.c                           | 38 ++++++-----
 drivers/mmc/omap_hsmmc.c                       | 55 +++++++++-------
 drivers/mmc/pxa_mmc_gen.c                      | 61 +++++++++---------
 drivers/mmc/sdhci.c                            | 73 +++++++++++----------
 drivers/mmc/sh_mmcif.c                         | 42 ++++++-------
 drivers/mmc/tegra_mmc.c                        | 36 ++++++-----
 include/dwmmc.h                                |  2 +
 include/fsl_esdhc.h                            |  4 ++
 include/mmc.h                                  | 31 ++++++---
 include/sdhci.h                                |  2 +
 26 files changed, 433 insertions(+), 392 deletions(-)
arch/arm/include/asm/arch-davinci/sdmmc_defs.h +1 -0
index 3e9e606..9aa3f4a 100644
@@ -151,6 +151,7 @@ struct davinci_mmc {
 	uint host_caps;		/* Host capabilities */
 	uint voltages;		/* Host supported voltages */
 	uint version;		/* MMC Controller version */
+	struct mmc_config cfg;
 };
 
 enum {
arch/arm/include/asm/arch-tegra/tegra_mmc.h +4 -0
index b6896af..310bbd7 100644
@@ -11,6 +11,9 @@
 
 #include <fdtdec.h>
 
+/* for mmc_config definition */
+#include <mmc.h>
+
 #define MAX_HOSTS		4	/* Max number of 'hosts'/controllers */
 
 #ifndef __ASSEMBLY__
@@ -138,6 +141,7 @@ struct mmc_host {
 	struct fdt_gpio_state wp_gpio;		/* Write Protect GPIO */
 	unsigned int version;	/* SDHCI spec. version */
 	unsigned int clock;	/* Current clock (MHz) */
+	struct mmc_config cfg;	/* mmc configuration */
 };
 
 void pad_init_mmc(struct mmc_host *host);
common/cmd_mmc.c +1 -1
index 2d51927..bd1edc8 100644
@@ -79,7 +79,7 @@ enum mmc_state {
 };
 static void print_mmcinfo(struct mmc *mmc)
 {
-	printf("Device: %s\n", mmc->name);
+	printf("Device: %s\n", mmc->cfg->name);
 	printf("Manufacturer ID: %x\n", mmc->cid[0] >> 24);
 	printf("OEM: %x\n", (mmc->cid[0] >> 8) & 0xffff);
 	printf("Name: %c%c%c%c%c \n", mmc->cid[0] & 0xff,
common/cmd_mmc_spi.c +1 -1
index 98cd788..a2138b8 100644
@@ -72,7 +72,7 @@ static int do_mmc_spi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		printf("Failed to create MMC Device\n");
 		return 1;
 	}
-	printf("%s: %d at %u:%u hz %u mode %u\n", mmc->name, mmc->block_dev.dev,
+	printf("%s: %d at %u:%u hz %u mode %u\n", mmc->cfg->name, mmc->block_dev.dev,
 	       bus, cs, speed, mode);
 	mmc_init(mmc);
 	return 0;
drivers/mmc/arm_pl180_mmci.c +21 -19
index 5a30590..5ef7ff7 100644
@@ -287,9 +287,9 @@ static void host_set_ios(struct mmc *dev)
 		u32 clkdiv = 0;
 		u32 tmp_clock;
 
-		if (dev->clock >= dev->f_max) {
+		if (dev->clock >= dev->cfg->f_max) {
 			clkdiv = 0;
-			dev->clock = dev->f_max;
+			dev->clock = dev->cfg->f_max;
 		} else {
 			clkdiv = (host->clock_in / dev->clock) - 2;
 		}
@@ -348,16 +348,9 @@ static const struct mmc_ops arm_pl180_mmci_ops = {
  */
 int arm_pl180_mmci_init(struct pl180_mmc_host *host)
 {
-	struct mmc *dev;
+	struct mmc *mmc;
 	u32 sdi_u32;
 
-	dev = malloc(sizeof(struct mmc));
-	if (!dev)
-		return -ENOMEM;
-
-	memset(dev, 0, sizeof(struct mmc));
-	dev->priv = host;
-
 	writel(host->pwr_init, &host->base->power);
 	writel(host->clkdiv_init, &host->base->clock);
 	udelay(CLK_CHANGE_DELAY);
@@ -365,15 +358,24 @@ int arm_pl180_mmci_init(struct pl180_mmc_host *host)
 	/* Disable mmc interrupts */
 	sdi_u32 = readl(&host->base->mask0) & ~SDI_MASK0_MASK;
 	writel(sdi_u32, &host->base->mask0);
-	dev->name = host->name;
-	dev->ops = &arm_pl180_mmci_ops;
-	dev->host_caps = host->caps;
-	dev->voltages = host->voltages;
-	dev->f_min = host->clock_min;
-	dev->f_max = host->clock_max;
-	dev->b_max = host->b_max;
-	mmc_register(dev);
-	debug("registered mmc interface number is:%d\n", dev->block_dev.dev);
+
+	host->cfg.name = host->name;
+	host->cfg.ops = &arm_pl180_mmci_ops;
+	/* TODO remove the duplicates */
+	host->cfg.host_caps = host->caps;
+	host->cfg.voltages = host->voltages;
+	host->cfg.f_min = host->clock_min;
+	host->cfg.f_max = host->clock_max;
+	if (host->b_max != 0)
+		host->cfg.b_max = host->b_max;
+	else
+		host->cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
+
+	mmc = mmc_create(&host->cfg, host);
+	if (mmc == NULL)
+		return -1;
+
+	debug("registered mmc interface number is:%d\n", mmc->block_dev.dev);
 
 	return 0;
 }
drivers/mmc/arm_pl180_mmci.h +4 -0
index 7234449..f23bd39 100644
@@ -13,6 +13,9 @@
 #ifndef __ARM_PL180_MMCI_H__
 #define __ARM_PL180_MMCI_H__
 
+/* need definition of struct mmc_config */
+#include <mmc.h>
+
 #define COMMAND_REG_DELAY	300
 #define DATA_REG_DELAY		1000
 #define CLK_CHANGE_DELAY	2000
@@ -184,6 +187,7 @@ struct pl180_mmc_host {
 	unsigned int clkdiv_init;
 	unsigned int pwr_init;
 	int version2;
+	struct mmc_config cfg;
 };
 
 int arm_pl180_mmci_init(struct pl180_mmc_host *);
drivers/mmc/bfin_sdh.c +15 -16
index 5f6145b..7b35d8e 100644
@@ -238,7 +238,7 @@ static void bfin_sdh_set_ios(struct mmc *mmc)
 	u16 cfg = 0;
 	u16 clk_ctl = 0;
 
-	if (mmc->bus_width == 4) {
+	if (mmc_bus_width(mmc) == 4) {
 		cfg = bfin_read_SDH_CFG();
 #ifndef RSI_BLKSZ
 		cfg &= ~PD_SDDAT3;
@@ -280,25 +280,24 @@ static const struct mmc_ops bfin_mmc_ops = {
 	.init		= bfin_sdh_init,
 };
 
+static struct mmc_config bfin_mmc_cfg = {
+	.name		= "Blackfin SDH",
+	.ops		= &bfin_mmc_ops,
+	.host_caps	= MMC_MODE_4BIT,
+	.voltages	= MMC_VDD_32_33 | MMC_VDD_33_34,
+	.b_max		= CONFIG_SYS_MMC_MAX_BLK_COUNT,
+};
+
 int bfin_mmc_init(bd_t *bis)
 {
-	struct mmc *mmc = NULL;
-
-	mmc = malloc(sizeof(struct mmc));
-
-	if (!mmc)
-		return -ENOMEM;
-	mmc->name = "Blackfin SDH";
-	mmc->ops = &bfin_mmc_ops;
-	mmc->host_caps = MMC_MODE_4BIT;
-
-	mmc->voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
-	mmc->f_max = get_sclk();
-	mmc->f_min = mmc->f_max >> 9;
+	struct mmc *mmc;
 
-	mmc->b_max = 0;
+	bfin_mmc_cfg.f_max = get_sclk();
+	bfin_mmc_cfg.f_min = bfin_mmc_cfg.f_max >> 9;
 
-	mmc_register(mmc);
+	mmc = mmc_create(&bfin_mmc_cfg, NULL);
+	if (mmc == NULL)
+		return -1;
 
 	return 0;
 }
drivers/mmc/davinci_mmc.c +12 -18
index cae972a..aae00e9 100644
@@ -30,10 +30,10 @@ static void dmmc_set_clock(struct mmc *mmc, uint clock)
 	struct davinci_mmc_regs *regs = host->reg_base;
 	uint clkrt, sysclk2, act_clock;
 
-	if (clock < mmc->f_min)
-		clock = mmc->f_min;
-	if (clock > mmc->f_max)
-		clock = mmc->f_max;
+	if (clock < mmc->cfg->f_min)
+		clock = mmc->cfg->f_min;
+	if (clock > mmc->cfg->f_max)
+		clock = mmc->cfg->f_max;
 
 	set_val(&regs->mmcclk, 0);
 	sysclk2 = host->input_clk;
@@ -374,22 +374,16 @@ static const struct mmc_ops dmmc_ops = {
  */
 int davinci_mmc_init(bd_t *bis, struct davinci_mmc *host)
 {
-	struct mmc *mmc;
+	host->cfg.name = "davinci";
+	host->cfg.ops = &dmmc_ops;
+	host->cfg.f_min = 200000;
+	host->cfg.f_max = 25000000;
+	host->cfg.voltages = host->voltages;
+	host->cfg.host_caps = host->host_caps;
 
-	mmc = malloc(sizeof(struct mmc));
-	memset(mmc, 0, sizeof(struct mmc));
+	host->cfg.b_max = DAVINCI_MAX_BLOCKS;
 
-	mmc->name = "davinci";
-	mmc->priv = host;
-	mmc->ops = &dmmc_ops;
-	mmc->f_min = 200000;
-	mmc->f_max = 25000000;
-	mmc->voltages = host->voltages;
-	mmc->host_caps = host->host_caps;
-
-	mmc->b_max = DAVINCI_MAX_BLOCKS;
-
-	mmc_register(mmc);
+	mmc_create(&host->cfg, host);
 
 	return 0;
 }
drivers/mmc/dw_mmc.c +21 -29

86 lines not on this page · raw message

drivers/mmc/fsl_esdhc.c +27 -28

133 lines not on this page · raw message

drivers/mmc/ftsdc010_mci.c +22 -32

89 lines not on this page · raw message

drivers/mmc/gen_atmel_mci.c +26 -17

90 lines not on this page · raw message

drivers/mmc/mmc.c +56 -31

203 lines not on this page · raw message

drivers/mmc/mmc_spi.c +21 -19
index e94de37..5b5b33a 100644
@@ -92,7 +92,7 @@ static uint mmc_spi_readdata(struct mmc *mmc, void *xbuf,
 			spi_xfer(spi, 2 * 8, NULL, &crc, 0);
 #ifdef CONFIG_MMC_SPI_CRC_ON
 			if (swab16(cyg_crc16(buf, bsize)) != crc) {
-				debug("%s: CRC error\n", mmc->name);
+				debug("%s: CRC error\n", mmc->cfg->name);
 				r1 = R1_SPI_COM_CRC;
 				break;
 			}
@@ -238,6 +238,7 @@ done:
 static void mmc_spi_set_ios(struct mmc *mmc)
 {
 	struct spi_slave *spi = mmc->priv;
+
 	debug("%s: clock %u\n", __func__, mmc->clock);
 	if (mmc->clock)
 		spi_set_speed(spi, mmc->clock);
@@ -246,7 +247,6 @@ static void mmc_spi_set_ios(struct mmc *mmc)
 static int mmc_spi_init_p(struct mmc *mmc)
 {
 	struct spi_slave *spi = mmc->priv;
-	mmc->clock = 0;
 	spi_set_speed(spi, MMC_SPI_MIN_CLOCK);
 	spi_claim_bus(spi);
 	/* cs deactivated for 100+ clock */
@@ -261,29 +261,31 @@ static const struct mmc_ops mmc_spi_ops = {
 	.init		= mmc_spi_init_p,
 };
 
+static struct mmc_config mmc_spi_cfg = {
+	.name		= "MMC_SPI",
+	.ops		= &mmc_spi_ops,
+	.host_caps	= MMC_MODE_SPI,
+	.voltages	= MMC_SPI_VOLTAGE,
+	.f_min		= MMC_SPI_MIN_CLOCK,
+	.part_type	= PART_TYPE_DOS,
+	.b_max		= CONFIG_SYS_MMC_MAX_BLK_COUNT,
+};
+
 struct mmc *mmc_spi_init(uint bus, uint cs, uint speed, uint mode)
 {
 	struct mmc *mmc;
+	struct spi_slave *spi;
 
-	mmc = malloc(sizeof(*mmc));
-	if (!mmc)
-		return NULL;
-	memset(mmc, 0, sizeof(*mmc));
-	mmc->priv = spi_setup_slave(bus, cs, speed, mode);
-	if (!mmc->priv) {
-		free(mmc);
+	spi = spi_setup_slave(bus, cs, speed, mode);
+	if (spi == NULL)
 		return NULL;
-	}
-	mmc->name = "MMC_SPI";
-	mmc->ops = &mmc_spi_ops;
-	mmc->host_caps = MMC_MODE_SPI;
-
-	mmc->voltages = MMC_SPI_VOLTAGE;
-	mmc->f_max = speed;
-	mmc->f_min = MMC_SPI_MIN_CLOCK;
-	mmc->block_dev.part_type = PART_TYPE_DOS;
 
-	mmc_register(mmc);
+	mmc_spi_cfg.f_max = speed;
 
+	mmc = mmc_create(&mmc_spi_cfg, spi);
+	if (mmc == NULL) {
+		spi_free_slave(spi);
+		return NULL;
+	}
 	return mmc;
 }
drivers/mmc/mmc_write.c +2 -1
index aa2fdef..3db9669 100644
@@ -167,7 +167,8 @@ ulong mmc_bwrite(int dev_num, lbaint_t start, lbaint_t blkcnt, const void *src)
 		return 0;
 
 	do {
-		cur = (blocks_todo > mmc->b_max) ?  mmc->b_max : blocks_todo;
+		cur = (blocks_todo > mmc->cfg->b_max) ?
+			mmc->cfg->b_max : blocks_todo;
 		if (mmc_write_blocks(mmc, start, cur, src) != cur)
 			return 0;
 		blocks_todo -= cur;
drivers/mmc/mxcmmc.c +15 -20
index 3357559..561b204 100644
@@ -122,6 +122,8 @@ struct mxcmci_host {
 };
 
 static struct mxcmci_host mxcmci_host;
+
+/* maintainer note: do we really want to have a global host pointer? */
 static struct mxcmci_host *host = &mxcmci_host;
 
 static inline int mxcmci_use_dma(struct mxcmci_host *host)
@@ -491,31 +493,24 @@ static const struct mmc_ops mxcmci_ops = {
 	.init		= mxcmci_init,
 };
 
+static struct mmc_config mxcmci_cfg = {
+	.name		= "MXC MCI",
+	.ops		= &mxcmci_ops,
+	.host_caps	= MMC_MODE_4BIT,
+	.voltages	= MMC_VDD_32_33 | MMC_VDD_33_34,
+	.b_max		= CONFIG_SYS_MMC_MAX_BLK_COUNT,
+};
+
 static int mxcmci_initialize(bd_t *bis)
 {
-	struct mmc *mmc = NULL;
-
-	mmc = malloc(sizeof(struct mmc));
-
-	if (!mmc)
-		return -ENOMEM;
-
-	mmc->name = "MXC MCI";
-	mmc->ops = &mxcmci_ops;
-	mmc->host_caps = MMC_MODE_4BIT;
-
 	host->base = (struct mxcmci_regs *)CONFIG_MXC_MCI_REGS_BASE;
-	mmc->priv = host;
-	host->mmc = mmc;
-
-	mmc->voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
-
-	mmc->f_min = mxc_get_clock(MXC_ESDHC_CLK) >> 7;
-	mmc->f_max = mxc_get_clock(MXC_ESDHC_CLK) >> 1;
 
-	mmc->b_max = 0;
+	mxcmci_cfg.f_min = mxc_get_clock(MXC_ESDHC_CLK) >> 7;
+	mxcmci_cfg.f_max = mxc_get_clock(MXC_ESDHC_CLK) >> 1;
 
-	mmc_register(mmc);
+	host->mmc = mmc_create(&mxcmci_cfg, host);
+	if (host->mmc == NULL)
+		return -1;
 
 	return 0;
 }
drivers/mmc/mxsmmc.c +18 -20
index 3512a99..2fa4eee 100644
@@ -35,6 +35,7 @@ struct mxsmmc_priv {
 	int			(*mmc_is_wp)(int);
 	int			(*mmc_cd)(int);
 	struct mxs_dma_desc	*desc;
+	struct mmc_config	cfg;	/* mmc configuration */
 };
 
 #define	MXSMMC_MAX_TIMEOUT	10000
@@ -134,7 +135,7 @@ static int mxsmmc_send_cmd_dma(struct mxsmmc_priv *priv, struct mmc_data *data)
 static int
 mxsmmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
 {
-	struct mxsmmc_priv *priv = (struct mxsmmc_priv *)mmc->priv;
+	struct mxsmmc_priv *priv = mmc->priv;
 	struct mxs_ssp_regs *ssp_regs = priv->regs;
 	uint32_t reg;
 	int timeout;
@@ -305,7 +306,7 @@ mxsmmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
 
 static void mxsmmc_set_ios(struct mmc *mmc)
 {
-	struct mxsmmc_priv *priv = (struct mxsmmc_priv *)mmc->priv;
+	struct mxsmmc_priv *priv = mmc->priv;
 	struct mxs_ssp_regs *ssp_regs = priv->regs;
 
 	/* Set the clock speed */
@@ -334,7 +335,7 @@ static void mxsmmc_set_ios(struct mmc *mmc)
 
 static int mxsmmc_init(struct mmc *mmc)
 {
-	struct mxsmmc_priv *priv = (struct mxsmmc_priv *)mmc->priv;
+	struct mxsmmc_priv *priv = mmc->priv;
 	struct mxs_ssp_regs *ssp_regs = priv->regs;
 
 	/* Reset SSP */
@@ -379,20 +380,13 @@ int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int), int (*cd)(int))
 	if (!mxs_ssp_bus_id_valid(id))
 		return -ENODEV;
 
-	mmc = malloc(sizeof(struct mmc));
-	if (!mmc)
-		return -ENOMEM;
-
 	priv = malloc(sizeof(struct mxsmmc_priv));
-	if (!priv) {
-		free(mmc);
+	if (!priv)
 		return -ENOMEM;
-	}
 
 	priv->desc = mxs_dma_desc_alloc();
 	if (!priv->desc) {
 		free(priv);
-		free(mmc);
 		return -ENOMEM;
 	}
 
@@ -405,13 +399,12 @@ int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int), int (*cd)(int))
 	priv->id = id;
 	priv->regs = mxs_ssp_regs_by_bus(id);
 
-	mmc->name = "MXS MMC";
-	mmc->ops = &mxsmmc_ops;
-	mmc->priv = priv;
+	priv->cfg.name = "MXS MMC";
+	priv->cfg.ops = &mxsmmc_ops;
 
-	mmc->voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
+	priv->cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
 
-	mmc->host_caps = MMC_MODE_4BIT | MMC_MODE_8BIT |
+	priv->cfg.host_caps = MMC_MODE_4BIT | MMC_MODE_8BIT |
 			 MMC_MODE_HS_52MHz | MMC_MODE_HS |
 			 MMC_MODE_HC;
 
@@ -421,10 +414,15 @@ int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int), int (*cd)(int))
 	 * CLOCK_DIVIDE has to be an even value from 2 to 254, and
 	 * CLOCK_RATE could be any integer from 0 to 255.
 	 */
-	mmc->f_min = 400000;
-	mmc->f_max = mxc_get_clock(MXC_SSP0_CLK + mxsmmc_clk_id) * 1000 / 2;
-	mmc->b_max = 0x20;
+	priv->cfg.f_min = 400000;
+	priv->cfg.f_max = mxc_get_clock(MXC_SSP0_CLK + mxsmmc_clk_id) * 1000 / 2;
+	priv->cfg.b_max = 0x20;
 
-	mmc_register(mmc);
+	mmc = mmc_create(&priv->cfg, priv);
+	if (mmc == NULL) {
+		mxs_dma_desc_free(priv->desc);
+		free(priv);
+		return -ENOMEM;
+	}
 	return 0;
 }
drivers/mmc/omap_hsmmc.c +32 -23

107 lines not on this page · raw message

drivers/mmc/pxa_mmc_gen.c +29 -32

155 lines not on this page · raw message

drivers/mmc/sdhci.c +36 -37

160 lines not on this page · raw message

drivers/mmc/sh_mmcif.c +20 -22

85 lines not on this page · raw message

drivers/mmc/tegra_mmc.c +19 -17
index e8fbb63..ed67eec 100644
@@ -18,7 +18,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-struct mmc mmc_dev[MAX_HOSTS];
 struct mmc_host mmc_host[MAX_HOSTS];
 
 #ifndef CONFIG_OF_CONTROL
@@ -145,7 +144,7 @@ static int mmc_wait_inhibit(struct mmc_host *host,
 static int mmc_send_cmd_bounced(struct mmc *mmc, struct mmc_cmd *cmd,
 			struct mmc_data *data, struct bounce_buffer *bbstate)
 {
-	struct mmc_host *host = (struct mmc_host *)mmc->priv;
+	struct mmc_host *host = mmc->priv;
 	int flags, i;
 	int result;
 	unsigned int mask = 0;
@@ -456,7 +455,7 @@ static void mmc_reset(struct mmc_host *host, struct mmc *mmc)
 	}
 
 	/* Set SD bus voltage & enable bus power */
-	mmc_set_power(host, fls(mmc->voltages) - 1);
+	mmc_set_power(host, fls(mmc->cfg->voltages) - 1);
 	debug("%s: power control = %02X, host control = %02X\n", __func__,
 		readb(&host->reg->pwrcon), readb(&host->reg->hostctl));
 
@@ -466,7 +465,7 @@ static void mmc_reset(struct mmc_host *host, struct mmc *mmc)
 
 static int tegra_mmc_core_init(struct mmc *mmc)
 {
-	struct mmc_host *host = (struct mmc_host *)mmc->priv;
+	struct mmc_host *host = mmc->priv;
 	unsigned int mask;
 	debug(" mmc_core_init called\n");
 
@@ -511,7 +510,7 @@ static int tegra_mmc_core_init(struct mmc *mmc)
 
 int tegra_mmc_getcd(struct mmc *mmc)
 {
-	struct mmc_host *host = (struct mmc_host *)mmc->priv;
+	struct mmc_host *host = mmc->priv;
 
 	debug("tegra_mmc_getcd called\n");
 
@@ -561,19 +560,18 @@ static int do_mmc_init(int dev_index)
 		debug(" CD GPIO name = %s\n", host->cd_gpio.name);
 	}
 
-	mmc = &mmc_dev[dev_index];
+	memset(&host->cfg, 0, sizeof(host->cfg));
 
-	mmc->name = "Tegra SD/MMC";
-	mmc->priv = host;
-	mmc->ops = &tegra_mmc_ops;
+	host->cfg.name = "Tegra SD/MMC";
+	host->cfg.ops = &tegra_mmc_ops;
 
-	mmc->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195;
-	mmc->host_caps = 0;
+	host->cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195;
+	host->cfg.host_caps = 0;
 	if (host->width == 8)
-		mmc->host_caps |= MMC_MODE_8BIT;
+		host->cfg.host_caps |= MMC_MODE_8BIT;
 	if (host->width >= 4)
-		mmc->host_caps |= MMC_MODE_4BIT;
-	mmc->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_HC;
+		host->cfg.host_caps |= MMC_MODE_4BIT;
+	host->cfg.host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_HC;
 
 	/*
 	 * min freq is for card identification, and is the highest
@@ -581,10 +579,14 @@ static int do_mmc_init(int dev_index)
 	 * max freq is highest HS eMMC clock as per the SD/MMC spec
 	 *  (actually 52MHz)
 	 */
-	mmc->f_min = 375000;
-	mmc->f_max = 48000000;
+	host->cfg.f_min = 375000;
+	host->cfg.f_max = 48000000;
 
-	mmc_register(mmc);
+	host->cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
+
+	mmc = mmc_create(&host->cfg, host);
+	if (mmc == NULL)
+		return -1;
 
 	return 0;
 }
include/dwmmc.h +2 -0
index b641558..c9bdf51 100644
@@ -143,6 +143,8 @@ struct dwmci_host {
 	void (*clksel)(struct dwmci_host *host);
 	void (*board_init)(struct dwmci_host *host);
 	unsigned int (*get_mmc_clk)(struct dwmci_host *host);
+
+	struct mmc_config cfg;
 };
 
 struct dwmci_idmac {
include/fsl_esdhc.h +4 -0
index 89bcbd1..a6e3a5d 100644
@@ -13,6 +13,9 @@
 #include <asm/errno.h>
 #include <asm/byteorder.h>
 
+/* needed for the mmc_cfg definition */
+#include <mmc.h>
+
 /* FSL eSDHC-specific constants */
 #define SYSCTL			0x0002e02c
 #define SYSCTL_INITA		0x08000000
@@ -155,6 +158,7 @@ struct fsl_esdhc_cfg {
 	u32	esdhc_base;
 	u32	sdhc_clk;
 	u8	max_bus_width;
+	struct mmc_config cfg;
 };
 
 /* Select the correct accessors depending on endianess */
include/mmc.h +22 -9
index 6b08c62..0172979 100644
@@ -262,20 +262,28 @@ struct mmc_ops {
 	int (*getwp)(struct mmc *mmc);
 };
 
+struct mmc_config {
+	const char *name;
+	const struct mmc_ops *ops;
+	uint host_caps;
+	uint voltages;
+	uint f_min;
+	uint f_max;
+	uint b_max;
+	unsigned char part_type;
+};
+
+/* TODO struct mmc should be in mmc_private but it's hard to fix right now */
 struct mmc {
 	struct list_head link;
-	const char *name;	/* no need for this to be an array */
-	void *priv;
-	uint voltages;
+	const struct mmc_config *cfg;	/* provided configuration */
 	uint version;
+	void *priv;
 	uint has_init;
-	uint f_min;
-	uint f_max;
 	int high_capacity;
 	uint bus_width;
 	uint clock;
 	uint card_caps;
-	uint host_caps;
 	uint ocr;
 	uint dsr;
 	uint dsr_imp;
@@ -295,8 +303,6 @@ struct mmc {
 	u64 capacity_rpmb;
 	u64 capacity_gp[4];
 	block_dev_desc_t block_dev;
-	const struct mmc_ops *ops;
-	uint b_max;
 	char op_cond_pending;	/* 1 if we are waiting on an op_cond command */
 	char init_in_progress;	/* 1 if we have done mmc_start_init() */
 	char preinit;		/* start init as early as possible */
@@ -304,6 +310,8 @@ struct mmc {
 };
 
 int mmc_register(struct mmc *mmc);
+struct mmc *mmc_create(const struct mmc_config *cfg, void *priv);
+void mmc_destroy(struct mmc *mmc);
 int mmc_initialize(bd_t *bis);
 int mmc_init(struct mmc *mmc);
 int mmc_read(struct mmc *mmc, u64 src, uchar *dst, int size);
@@ -352,7 +360,7 @@ void mmc_set_preinit(struct mmc *mmc, int preinit);
 
 #ifdef CONFIG_GENERIC_MMC
 #ifdef CONFIG_MMC_SPI
-#define mmc_host_is_spi(mmc)	((mmc)->host_caps & MMC_MODE_SPI)
+#define mmc_host_is_spi(mmc)	((mmc)->cfg.host_caps & MMC_MODE_SPI)
 #else
 #define mmc_host_is_spi(mmc)	0
 #endif
@@ -361,4 +369,9 @@ struct mmc *mmc_spi_init(uint bus, uint cs, uint speed, uint mode);
 int mmc_legacy_init(int verbose);
 #endif
 
+/* Set block count limit because of 16 bit register limit on some hardware*/
+#ifndef CONFIG_SYS_MMC_MAX_BLK_COUNT
+#define CONFIG_SYS_MMC_MAX_BLK_COUNT 65535
+#endif
+
 #endif /* _MMC_H_ */
include/sdhci.h +2 -0
index 74d06ae..2c480d0 100644
@@ -247,6 +247,8 @@ struct sdhci_host {
 	void (*set_control_reg)(struct sdhci_host *host);
 	void (*set_clock)(int dev_index, unsigned int div);
 	uint	voltages;
+
+	struct mmc_config cfg;
 };
 
 #ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
Signature · 1 line
1.7.12
#8 lore raw

PATCH 3/3 mmc: Split mmc struct, rework mmc initialization

Quoted 14 lines · Pantelis Antoniou

The way that struct mmc was implemented was a bit of a mess; configuration and internal state all jumbled up in a single structure.

On top of that the way initialization is done with mmc_register leads to a lot of duplicated code in drivers.

Typically the initialization got something like this in every driver.

        struct mmc *mmc = malloc(sizeof(struct mmc));
        memset(mmc, 0, sizeof(struct mmc);
        /* fill in fields of mmc struct */
        /* store private data pointer */
        mmc_register(mmc);
Quoted 7 lines

By using the new mmc_create call one just passes an mmc config struct and an optional private data pointer like this:

        struct mmc = mmc_create(&cfg, priv);

All in tree drivers have been updated to the new form, and expect mmc_register to go away before long.

Looks like a big improvement!

Quoted 2 lines
#9 lore raw

cover mmc: Cleanup time for mmc_struct

In reply to Pantelis Antoniou
Quoted 9 lines · Pantelis Antoniou

Struct mmc has picked up a lot of cruft over the years.

It is time for it to be split in 3 parts; the original mmc struct containing the state, the mmc_config struct containing the board setup configuration and the mmc_ops struct contains the method pointers.

Using the new config structures the mmc device creation now gets much more easier by using the new mmc_create() call

Is this a V2? I don't see a changelog or anything ...

Best regards,
Marek Vasut