mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] mmc/sd patches
@ 2012-02-09 11:53 Sascha Hauer
  2012-02-09 11:53 ` [PATCH 01/15] mci: Add complete definitions for the card type Sascha Hauer
                   ` (14 more replies)
  0 siblings, 15 replies; 17+ messages in thread
From: Sascha Hauer @ 2012-02-09 11:53 UTC (permalink / raw)
  To: barebox

Here are several patches to clean up the sd/mmc layer.

Sascha Hauer (15):
      mci: Add complete definitions for the card type
      mci: use card type definitions
      mci: fix high capacity detection
      mci mxs: do not use external define for internal use
      mci core: replace discrete ios values with struct ios
      mci s3c: Do not mess with struct mci_host
      mci s3c: allocate host struct dynamically
      mci s3c: pass around the right pointer
      mci: remove unused device argument from set_ios
      mci core: fix mixup of max write/read block len
      mci: Use struct mci for internal argument passing
      mci: replace pr_debug with dev_dbg
      mci: factor out mci/sd specific startup functions
      mci: cdev_find_free_index won't fail, no need to check
      mci: Be more verbose on what device is associated to which disk

 drivers/mci/atmel_mci.c  |   19 +-
 drivers/mci/imx-esdhc.c  |   17 +-
 drivers/mci/imx.c        |   19 +-
 drivers/mci/mci-core.c   |  503 +++++++++++++++++++++++-----------------------
 drivers/mci/mci_spi.c    |    3 +-
 drivers/mci/mxs.c        |   17 +-
 drivers/mci/omap_hsmmc.c |   20 +-
 drivers/mci/pxamci.c     |   20 ++-
 drivers/mci/s3c.c        |  165 +++++++---------
 include/mci.h            |   52 ++++-
 10 files changed, 437 insertions(+), 398 deletions(-)

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 01/15] mci: Add complete definitions for the card type
  2012-02-09 11:53 [PATCH] mmc/sd patches Sascha Hauer
@ 2012-02-09 11:53 ` Sascha Hauer
  2012-02-09 11:53 ` [PATCH 02/15] mci: use card type definitions Sascha Hauer
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Sascha Hauer @ 2012-02-09 11:53 UTC (permalink / raw)
  To: barebox

Add the different DDR types and also a definition for the card
type mask.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/mci.h |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/include/mci.h b/include/mci.h
index d3b3082..87c7194 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -155,8 +155,16 @@
 #define EXT_CSD_CMD_SET_SECURE		(1<<1)
 #define EXT_CSD_CMD_SET_CPSECURE	(1<<2)
 
-#define EXT_CSD_CARD_TYPE_26	(1<<0)	/* Card can run at 26MHz */
-#define EXT_CSD_CARD_TYPE_52	(1<<1)	/* Card can run at 52MHz */
+#define EXT_CSD_CARD_TYPE_MASK		0x3f
+#define EXT_CSD_CARD_TYPE_26		(1<<0)	/* Card can run at 26MHz */
+#define EXT_CSD_CARD_TYPE_52		(1<<1)	/* Card can run at 52MHz */
+#define EXT_CSD_CARD_TYPE_DDR_1_8V	(1<<2)	/* Card can run at 52MHz */
+						/* DDR mode @1.8V or 3V I/O */
+#define EXT_CSD_CARD_TYPE_DDR_1_2V	(1<<3)	/* Card can run at 52MHz */
+						/* DDR mode @1.2V I/O */
+#define EXT_CSD_CARD_TYPE_SDR_1_8V	(1<<4)	/* Card can run at 200MHz */
+#define EXT_CSD_CARD_TYPE_SDR_1_2V	(1<<5)	/* Card can run at 200MHz */
+						/* SDR mode @1.2V I/O */
 
 #define EXT_CSD_BUS_WIDTH_1	0	/* Card is in 1 bit mode */
 #define EXT_CSD_BUS_WIDTH_4	1	/* Card is in 4 bit mode */
-- 
1.7.9


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 02/15] mci: use card type definitions
  2012-02-09 11:53 [PATCH] mmc/sd patches Sascha Hauer
  2012-02-09 11:53 ` [PATCH 01/15] mci: Add complete definitions for the card type Sascha Hauer
@ 2012-02-09 11:53 ` Sascha Hauer
  2012-02-09 11:53 ` [PATCH 03/15] mci: fix high capacity detection Sascha Hauer
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Sascha Hauer @ 2012-02-09 11:53 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/mci-core.c |    4 ++--
 include/mci.h          |    1 -
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index e9fe87c..db69b27 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -417,7 +417,7 @@ static int mmc_change_freq(struct device_d *mci_dev)
 	if (ext_csd[212] || ext_csd[213] || ext_csd[214] || ext_csd[215])
 		mci->high_capacity = 1;
 
-	cardtype = ext_csd[196] & 0xf;
+	cardtype = ext_csd[EXT_CSD_CARD_TYPE] & EXT_CSD_CARD_TYPE_MASK;
 
 	err = mci_switch(mci_dev, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, 1);
 
@@ -439,7 +439,7 @@ static int mmc_change_freq(struct device_d *mci_dev)
 		return 0;
 
 	/* High Speed is set, there are two types: 52MHz and 26MHz */
-	if (cardtype & MMC_HS_52MHZ)
+	if (cardtype & EXT_CSD_CARD_TYPE_52)
 		mci->card_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
 	else
 		mci->card_caps |= MMC_MODE_HS;
diff --git a/include/mci.h b/include/mci.h
index 87c7194..6d8468c 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -102,7 +102,6 @@
 #define SD_HIGHSPEED_SUPPORTED	0x00020000
 
 #define MMC_HS_TIMING		0x00000100
-#define MMC_HS_52MHZ		0x2
 
 #define OCR_BUSY		0x80000000
 /** card's response in its OCR if it is a high capacity card */
-- 
1.7.9


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 03/15] mci: fix high capacity detection
  2012-02-09 11:53 [PATCH] mmc/sd patches Sascha Hauer
  2012-02-09 11:53 ` [PATCH 01/15] mci: Add complete definitions for the card type Sascha Hauer
  2012-02-09 11:53 ` [PATCH 02/15] mci: use card type definitions Sascha Hauer
@ 2012-02-09 11:53 ` Sascha Hauer
  2012-02-09 11:53 ` [PATCH 04/15] mci mxs: do not use external define for internal use Sascha Hauer
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Sascha Hauer @ 2012-02-09 11:53 UTC (permalink / raw)
  To: barebox

Whether a card is high capacity is checked in
sd_send_op_cond/mmc_send_op_cond. Remove the wrong check in
mmc_change_freq which wrongly recognizes some eMMC flash
as high capacity.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/mci-core.c |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index db69b27..8951c07 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -414,9 +414,6 @@ static int mmc_change_freq(struct device_d *mci_dev)
 		return err;
 	}
 
-	if (ext_csd[212] || ext_csd[213] || ext_csd[214] || ext_csd[215])
-		mci->high_capacity = 1;
-
 	cardtype = ext_csd[EXT_CSD_CARD_TYPE] & EXT_CSD_CARD_TYPE_MASK;
 
 	err = mci_switch(mci_dev, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, 1);
-- 
1.7.9


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 04/15] mci mxs: do not use external define for internal use
  2012-02-09 11:53 [PATCH] mmc/sd patches Sascha Hauer
                   ` (2 preceding siblings ...)
  2012-02-09 11:53 ` [PATCH 03/15] mci: fix high capacity detection Sascha Hauer
@ 2012-02-09 11:53 ` Sascha Hauer
  2012-02-09 11:53 ` [PATCH 05/15] mci core: replace discrete ios values with struct ios Sascha Hauer
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Sascha Hauer @ 2012-02-09 11:53 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/mxs.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/mci/mxs.c b/drivers/mci/mxs.c
index 4b8bd75..a60e706 100644
--- a/drivers/mci/mxs.c
+++ b/drivers/mci/mxs.c
@@ -672,7 +672,7 @@ const unsigned char bus_width[3] = { 1, 4, 8 };
 
 static void mxs_mci_info(struct device_d *hw_dev)
 {
-	struct mxs_mci_host *mxs_mci = GET_HOST_DATA(hw_dev);
+	struct mxs_mci_host *mxs_mci = hw_dev->priv;
 
 	printf(" Interface\n");
 	printf("  Min. bus clock: %u Hz\n", mxs_mci->f_min);
-- 
1.7.9


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 05/15] mci core: replace discrete ios values with struct ios
  2012-02-09 11:53 [PATCH] mmc/sd patches Sascha Hauer
                   ` (3 preceding siblings ...)
  2012-02-09 11:53 ` [PATCH 04/15] mci mxs: do not use external define for internal use Sascha Hauer
@ 2012-02-09 11:53 ` Sascha Hauer
  2012-02-09 11:53 ` [PATCH 06/15] mci s3c: Do not mess with struct mci_host Sascha Hauer
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Sascha Hauer @ 2012-02-09 11:53 UTC (permalink / raw)
  To: barebox

As we'll need more arguments to set_ios over time put them
in a struct mci_ios like the kernel does.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/atmel_mci.c  |   18 ++++++++++--------
 drivers/mci/imx-esdhc.c  |   16 ++++++++++++----
 drivers/mci/imx.c        |   18 ++++++++++++------
 drivers/mci/mci-core.c   |   14 +++++++++-----
 drivers/mci/mci_spi.c    |    2 +-
 drivers/mci/mxs.c        |   14 ++++++++------
 drivers/mci/omap_hsmmc.c |   19 ++++++++++---------
 drivers/mci/pxamci.c     |   19 +++++++++++++------
 drivers/mci/s3c.c        |   15 ++++++++-------
 include/mci.h            |   32 +++++++++++++++++++++++++++++++-
 10 files changed, 114 insertions(+), 53 deletions(-)

diff --git a/drivers/mci/atmel_mci.c b/drivers/mci/atmel_mci.c
index 3c37747..e0272b9 100644
--- a/drivers/mci/atmel_mci.c
+++ b/drivers/mci/atmel_mci.c
@@ -352,29 +352,31 @@ static int mci_reset(struct mci_host *mci, struct device_d *mci_dev)
 
 /** change host interface settings */
 static void mci_set_ios(struct mci_host *mci, struct device_d *mci_dev,
-			unsigned bus_width, unsigned clock)
+			struct mci_ios *ios)
 {
 	struct atmel_mci_host *host = to_mci_host(mci);
 
 	dev_dbg(host->hw_dev, "atmel_mci_set_ios: bus_width=%d clk=%d\n",
-		bus_width, clock);
+		ios->bus_width, ios->clock);
 
-	switch (bus_width) {
-	case 4:
+	switch (ios->bus_width) {
+	case MMC_BUS_WIDTH_4:
 		atmel_mci_writel(host, AT91_MCI_SDCR, AT91_MCI_SDCBUS_4BIT);
 		break;
-	case 8:
+	case MMC_BUS_WIDTH_8:
 		atmel_mci_writel(host, AT91_MCI_SDCR, AT91_MCI_SDCBUS_8BIT);
 		break;
-	default:
+	case MMC_BUS_WIDTH_1:
 		atmel_mci_writel(host, AT91_MCI_SDCR, AT91_MCI_SDCBUS_1BIT);
 		break;
+	default:
+		return;
 	}
 	atmel_mci_writel(host, AT91_MCI_SDCR, atmel_mci_readl(host, AT91_MCI_SDCR)
 		| host->slot_b);
 
-	if (clock) {
-		atmel_set_clk_rate(host, clock);
+	if (ios->clock) {
+		atmel_set_clk_rate(host, ios->clock);
 		atmel_mci_writel(host, AT91_MCI_CR, AT91_MCI_MCIEN
 		);
 	} else {
diff --git a/drivers/mci/imx-esdhc.c b/drivers/mci/imx-esdhc.c
index fe55697..f1e876b 100644
--- a/drivers/mci/imx-esdhc.c
+++ b/drivers/mci/imx-esdhc.c
@@ -376,21 +376,29 @@ void set_sysctl(struct mci_host *mci, u32 clock)
 }
 
 static void esdhc_set_ios(struct mci_host *mci, struct device_d *dev,
-		unsigned bus_width, unsigned clock)
+		struct mci_ios *ios)
 {
 	struct fsl_esdhc_host *host = to_fsl_esdhc(mci);
 	struct fsl_esdhc *regs = host->regs;
 
 	/* Set the clock speed */
-	set_sysctl(mci, clock);
+	set_sysctl(mci, ios->clock);
 
 	/* Set the bus width */
 	esdhc_clrbits32(&regs->proctl, PROCTL_DTW_4 | PROCTL_DTW_8);
 
-	if (bus_width == 4)
+	switch (ios->bus_width) {
+	case MMC_BUS_WIDTH_4:
 		esdhc_setbits32(&regs->proctl, PROCTL_DTW_4);
-	else if (bus_width == 8)
+		break;
+	case MMC_BUS_WIDTH_8:
 		esdhc_setbits32(&regs->proctl, PROCTL_DTW_8);
+		break;
+	case MMC_BUS_WIDTH_1:
+		break;
+	default:
+		return;
+	}
 
 }
 
diff --git a/drivers/mci/imx.c b/drivers/mci/imx.c
index 50c98e1..2ce34bb 100644
--- a/drivers/mci/imx.c
+++ b/drivers/mci/imx.c
@@ -442,23 +442,29 @@ static void mxcmci_set_clk_rate(struct mxcmci_host *host, unsigned int clk_ios)
 }
 
 static void mxcmci_set_ios(struct mci_host *mci, struct device_d *dev,
-		unsigned bus_width, unsigned clock)
+		struct mci_ios *ios)
 {
 	struct mxcmci_host *host = to_mxcmci(mci);
 
-	if (bus_width == 4)
+	switch (ios->bus_width) {
+	case MMC_BUS_WIDTH_4:
 		host->cmdat |= CMD_DAT_CONT_BUS_WIDTH_4;
-	else
+		break;
+	case MMC_BUS_WIDTH_1:
 		host->cmdat &= ~CMD_DAT_CONT_BUS_WIDTH_4;
+		break;
+	default:
+		return;
+	}
 
-	if (clock) {
-		mxcmci_set_clk_rate(host, clock);
+	if (ios->clock) {
+		mxcmci_set_clk_rate(host, ios->clock);
 		writew(STR_STP_CLK_START_CLK, &host->base->str_stp_clk);
 	} else {
 		writew(STR_STP_CLK_STOP_CLK, &host->base->str_stp_clk);
 	}
 
-	host->clock = clock;
+	host->clock = ios->clock;
 }
 
 static int mxcmci_init(struct mci_host *mci, struct device_d *dev)
diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 8951c07..18ccc9c 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -591,8 +591,12 @@ retry_scr:
 static void mci_set_ios(struct device_d *mci_dev)
 {
 	struct mci_host *host = GET_MCI_PDATA(mci_dev);
+	struct mci_ios ios;
 
-	host->set_ios(host, mci_dev, host->bus_width, host->clock);
+	ios.bus_width = host->bus_width;
+	ios.clock = host->clock;
+
+	host->set_ios(host, mci_dev, &ios);
 }
 
 /**
@@ -907,7 +911,7 @@ static int mci_startup(struct device_d *mci_dev)
 				/* TODO continue with 1 bit? */
 				return err;
 			}
-			mci_set_bus_width(mci_dev, 4);
+			mci_set_bus_width(mci_dev, MMC_BUS_WIDTH_4);
 		}
 		/* if possible, speed up the transfer */
 		if (mci->card_caps & MMC_MODE_HS)
@@ -924,7 +928,7 @@ static int mci_startup(struct device_d *mci_dev)
 				pr_debug("Changing MMC bus width failed: %d\n", err);
 				return err;
 			}
-			mci_set_bus_width(mci_dev, 4);
+			mci_set_bus_width(mci_dev, MMC_BUS_WIDTH_4);
 		} else if (mci->card_caps & MMC_MODE_8BIT) {
 			pr_debug("Set MMC bus width to 8 bit\n");
 			/* Set the card to use 8 bit*/
@@ -934,7 +938,7 @@ static int mci_startup(struct device_d *mci_dev)
 				pr_debug("Changing MMC bus width failed: %d\n", err);
 				return err;
 			}
-			mci_set_bus_width(mci_dev, 8);
+			mci_set_bus_width(mci_dev, MMC_BUS_WIDTH_8);
 		}
 		/* if possible, speed up the transfer */
 		if (mci->card_caps & MMC_MODE_HS) {
@@ -1243,7 +1247,7 @@ static int mci_card_probe(struct device_d *mci_dev)
 		return rc;
 	}
 
-	mci_set_bus_width(mci_dev, 1);
+	mci_set_bus_width(mci_dev, MMC_BUS_WIDTH_1);
 	mci_set_clock(mci_dev, 1);	/* set the lowest available clock */
 
 	/* reset the card */
diff --git a/drivers/mci/mci_spi.c b/drivers/mci/mci_spi.c
index 54b2a91..0f94dab 100644
--- a/drivers/mci/mci_spi.c
+++ b/drivers/mci/mci_spi.c
@@ -330,7 +330,7 @@ return  0;
 }
 
 static void mmc_spi_set_ios(struct mci_host *mci, struct device_d *mci_dev,
-			unsigned bus_width, unsigned clock)
+			struct mci_ios *ios)
 {
 	struct mmc_spi_host	*host = to_spi_host(mci);
 
diff --git a/drivers/mci/mxs.c b/drivers/mci/mxs.c
index a60e706..4b944fd 100644
--- a/drivers/mci/mxs.c
+++ b/drivers/mci/mxs.c
@@ -641,26 +641,28 @@ static int mxs_mci_request(struct mci_host *host, struct mci_cmd *cmd,
  * Drivers currently realized values are stored in MCI's platformdata
  */
 static void mxs_mci_set_ios(struct mci_host *host, struct device_d *mci_dev,
-			unsigned bus_width, unsigned clock)
+			struct mci_ios *ios)
 {
 	struct mxs_mci_host *mxs_mci = to_mxs_mci(host);
 
-	switch (bus_width) {
-	case 8:
+	switch (ios->bus_width) {
+	case MMC_BUS_WIDTH_8:
 		mxs_mci->bus_width = 2;
 		host->bus_width = 8;	/* 8 bit is possible */
 		break;
-	case 4:
+	case MMC_BUS_WIDTH_4:
 		mxs_mci->bus_width = 1;
 		host->bus_width = 4;	/* 4 bit is possible */
 		break;
-	default:
+	case MMC_BUS_WIDTH_1:
 		mxs_mci->bus_width = 0;
 		host->bus_width = 1;	/* 1 bit is possible */
 		break;
+	default:
+		return;
 	}
 
-	mxs_mci->clock = mxs_mci_setup_clock_speed(mxs_mci, clock);
+	mxs_mci->clock = mxs_mci_setup_clock_speed(mxs_mci, ios->clock);
 	pr_debug("IO settings: bus width=%d, frequency=%u Hz\n", host->bus_width,
 			mxs_mci->clock);
 }
diff --git a/drivers/mci/omap_hsmmc.c b/drivers/mci/omap_hsmmc.c
index e671bbe..e629fba 100644
--- a/drivers/mci/omap_hsmmc.c
+++ b/drivers/mci/omap_hsmmc.c
@@ -511,7 +511,7 @@ static int mmc_send_cmd(struct mci_host *mci, struct mci_cmd *cmd,
 }
 
 static void mmc_set_ios(struct mci_host *mci, struct device_d *dev,
-		unsigned bus_width, unsigned clock)
+		struct mci_ios *ios)
 {
 	struct omap_hsmmc *hsmmc = to_hsmmc(mci);
 	struct hsmmc *mmc_base = hsmmc->base;
@@ -519,33 +519,34 @@ static void mmc_set_ios(struct mci_host *mci, struct device_d *dev,
 	uint64_t start;
 
 	/* configue bus width */
-	switch (bus_width) {
-	case 8:
+	switch (ios->bus_width) {
+	case MMC_BUS_WIDTH_8:
 		writel(readl(&mmc_base->con) | DTW_8_BITMODE,
 			&mmc_base->con);
 		break;
 
-	case 4:
+	case MMC_BUS_WIDTH_4:
 		writel(readl(&mmc_base->con) & ~DTW_8_BITMODE,
 			&mmc_base->con);
 		writel(readl(&mmc_base->hctl) | DTW_4_BITMODE,
 			&mmc_base->hctl);
 		break;
 
-	case 1:
-	default:
+	case MMC_BUS_WIDTH_1:
 		writel(readl(&mmc_base->con) & ~DTW_8_BITMODE,
 			&mmc_base->con);
 		writel(readl(&mmc_base->hctl) & ~DTW_4_BITMODE,
 			&mmc_base->hctl);
 		break;
+	default:
+		return;
 	}
 
 	/* configure clock with 96Mhz system clock.
 	 */
-	if (clock != 0) {
-		dsor = (MMC_CLOCK_REFERENCE * 1000000 / clock);
-		if ((MMC_CLOCK_REFERENCE * 1000000) / dsor > clock)
+	if (ios->clock != 0) {
+		dsor = (MMC_CLOCK_REFERENCE * 1000000 / ios->clock);
+		if ((MMC_CLOCK_REFERENCE * 1000000) / dsor > ios->clock)
 			dsor++;
 	}
 
diff --git a/drivers/mci/pxamci.c b/drivers/mci/pxamci.c
index 75b61f0..a22bdba 100644
--- a/drivers/mci/pxamci.c
+++ b/drivers/mci/pxamci.c
@@ -274,15 +274,15 @@ static int pxamci_request(struct mci_host *mci, struct mci_cmd *cmd,
 }
 
 static void pxamci_set_ios(struct mci_host *mci, struct device_d *dev,
-			   unsigned bus_width, unsigned clock)
+			   struct mci_ios *ios)
 {
 	struct pxamci_host *host = to_pxamci(mci);
 	unsigned int clk_in = pxa_get_mmcclk();
 	int fact;
 
-	mci_dbg("bus_width=%d, clock=%u\n", bus_width, clock);
-	if (clock)
-		fact = min_t(int, clk_in / clock, 1 << 6);
+	mci_dbg("bus_width=%d, clock=%u\n", ios->bus_width, ios->clock);
+	if (ios->clock)
+		fact = min_t(int, clk_in / ios->clock, 1 << 6);
 	else
 		fact = 1 << 6;
 	fact = max_t(int, fact, 1);
@@ -294,10 +294,17 @@ static void pxamci_set_ios(struct mci_host *mci, struct device_d *dev,
 	/* to handle (19.5MHz, 26MHz) */
 	host->clkrt = fls(fact) - 1;
 
-	if (bus_width == 4)
+	switch (ios->bus_width) {
+	case MMC_BUS_WIDTH_4:
 		host->cmdat |= CMDAT_SD_4DAT;
-	else
+		break;
+	case MMC_BUS_WIDTH_1:
 		host->cmdat &= ~CMDAT_SD_4DAT;
+		break;
+	default:
+		return;
+	}
+
 	host->cmdat |= CMDAT_INIT;
 
 	clk_enable();
diff --git a/drivers/mci/s3c.c b/drivers/mci/s3c.c
index 7babab4..9d46b09 100644
--- a/drivers/mci/s3c.c
+++ b/drivers/mci/s3c.c
@@ -687,29 +687,30 @@ static int mci_request(struct mci_host *mci_pdata, struct mci_cmd *cmd,
  * @param clock New clock in Hz (can be '0' to disable the clock)
  */
 static void mci_set_ios(struct mci_host *mci_pdata, struct device_d *mci_dev,
-			unsigned bus_width, unsigned clock)
+			struct mci_ios *ios)
 {
 	struct device_d *hw_dev = mci_pdata->hw_dev;
 	struct s3c_mci_host *host_data = GET_HOST_DATA(hw_dev);
 	struct mci_host *host = GET_MCI_PDATA(mci_dev);
 	uint32_t reg;
 
-	switch (bus_width) {
-	case 8:		/* no 8 bit support, fall back to 4 bit */
-	case 4:
+	switch (ios->bus_width) {
+	case MMC_BUS_WIDTH_4:
 		host_data->bus_width = 1;
 		host->bus_width = 4;	/* 4 bit is possible */
 		break;
-	default:
+	case MMC_BUS_WIDTH_1:
 		host_data->bus_width = 0;
 		host->bus_width = 1;	/* 1 bit is possible */
 		break;
+	default:
+		return;
 	}
 
 	reg = readl(host_data->base + SDICON);
-	if (clock) {
+	if (ios->clock) {
 		/* setup the IO clock frequency and enable it */
-		host->clock = host_data->clock = s3c_setup_clock_speed(hw_dev, clock);
+		host->clock = host_data->clock = s3c_setup_clock_speed(hw_dev, ios->clock);
 		reg |= SDICON_CLKEN;	/* enable the clock */
 	} else {
 		reg &= ~SDICON_CLKEN;	/* disable the clock */
diff --git a/include/mci.h b/include/mci.h
index 6d8468c..3473aaa 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -168,6 +168,8 @@
 #define EXT_CSD_BUS_WIDTH_1	0	/* Card is in 1 bit mode */
 #define EXT_CSD_BUS_WIDTH_4	1	/* Card is in 4 bit mode */
 #define EXT_CSD_BUS_WIDTH_8	2	/* Card is in 8 bit mode */
+#define EXT_CSD_DDR_BUS_WIDTH_4	5	/* Card is in 4 bit DDR mode */
+#define EXT_CSD_DDR_BUS_WIDTH_8	6	/* Card is in 8 bit DDR mode */
 
 #define R1_ILLEGAL_COMMAND		(1 << 22)
 #define R1_APP_CMD			(1 << 5)
@@ -217,6 +219,34 @@ struct mci_data {
 	unsigned blocksize;	/**< block size in bytes (mostly 512) */
 };
 
+struct mci_ios {
+	unsigned int	clock;			/* clock rate */
+
+	unsigned char	bus_width;		/* data bus width */
+
+#define MMC_BUS_WIDTH_1		0
+#define MMC_BUS_WIDTH_4		2
+#define MMC_BUS_WIDTH_8		3
+
+	unsigned char	timing;			/* timing specification used */
+
+#define MMC_TIMING_LEGACY	0
+#define MMC_TIMING_MMC_HS	1
+#define MMC_TIMING_SD_HS	2
+#define MMC_TIMING_UHS_SDR12	MMC_TIMING_LEGACY
+#define MMC_TIMING_UHS_SDR25	MMC_TIMING_SD_HS
+#define MMC_TIMING_UHS_SDR50	3
+#define MMC_TIMING_UHS_SDR104	4
+#define MMC_TIMING_UHS_DDR50	5
+#define MMC_TIMING_MMC_HS200	6
+
+#define MMC_SDR_MODE		0
+#define MMC_1_2V_DDR_MODE	1
+#define MMC_1_8V_DDR_MODE	2
+#define MMC_1_2V_SDR_MODE	3
+#define MMC_1_8V_SDR_MODE	4
+};
+
 /** host information */
 struct mci_host {
 	struct device_d *hw_dev;	/**< the host MCI hardware device */
@@ -230,7 +260,7 @@ struct mci_host {
 	/** init the host interface */
 	int (*init)(struct mci_host*, struct device_d*);
 	/** change host interface settings */
-	void (*set_ios)(struct mci_host*, struct device_d*, unsigned, unsigned);
+	void (*set_ios)(struct mci_host*, struct device_d*, struct mci_ios *);
 	/** handle a command */
 	int (*send_cmd)(struct mci_host*, struct mci_cmd*, struct mci_data*);
 };
-- 
1.7.9


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 06/15] mci s3c: Do not mess with struct mci_host
  2012-02-09 11:53 [PATCH] mmc/sd patches Sascha Hauer
                   ` (4 preceding siblings ...)
  2012-02-09 11:53 ` [PATCH 05/15] mci core: replace discrete ios values with struct ios Sascha Hauer
@ 2012-02-09 11:53 ` Sascha Hauer
  2012-02-09 11:53 ` [PATCH 07/15] mci s3c: allocate host struct dynamically Sascha Hauer
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Sascha Hauer @ 2012-02-09 11:53 UTC (permalink / raw)
  To: barebox

This structure is owned by the core, do not change its contents
in the driver.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/s3c.c |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/mci/s3c.c b/drivers/mci/s3c.c
index 9d46b09..a153b1c 100644
--- a/drivers/mci/s3c.c
+++ b/drivers/mci/s3c.c
@@ -691,17 +691,14 @@ static void mci_set_ios(struct mci_host *mci_pdata, struct device_d *mci_dev,
 {
 	struct device_d *hw_dev = mci_pdata->hw_dev;
 	struct s3c_mci_host *host_data = GET_HOST_DATA(hw_dev);
-	struct mci_host *host = GET_MCI_PDATA(mci_dev);
 	uint32_t reg;
 
 	switch (ios->bus_width) {
 	case MMC_BUS_WIDTH_4:
 		host_data->bus_width = 1;
-		host->bus_width = 4;	/* 4 bit is possible */
 		break;
 	case MMC_BUS_WIDTH_1:
 		host_data->bus_width = 0;
-		host->bus_width = 1;	/* 1 bit is possible */
 		break;
 	default:
 		return;
@@ -710,16 +707,16 @@ static void mci_set_ios(struct mci_host *mci_pdata, struct device_d *mci_dev,
 	reg = readl(host_data->base + SDICON);
 	if (ios->clock) {
 		/* setup the IO clock frequency and enable it */
-		host->clock = host_data->clock = s3c_setup_clock_speed(hw_dev, ios->clock);
+		host_data->clock = s3c_setup_clock_speed(hw_dev, ios->clock);
 		reg |= SDICON_CLKEN;	/* enable the clock */
 	} else {
 		reg &= ~SDICON_CLKEN;	/* disable the clock */
-		host->clock = host_data->clock = 0;
+		host_data->clock = 0;
 	}
 	writel(reg, host_data->base + SDICON);
 
 	pr_debug("IO settings: bus width=%d, frequency=%u Hz\n",
-		host->bus_width, host->clock);
+		host_data->bus_width, host_data->clock);
 }
 
 /* ----------------------------------------------------------------------- */
-- 
1.7.9


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 07/15] mci s3c: allocate host struct dynamically
  2012-02-09 11:53 [PATCH] mmc/sd patches Sascha Hauer
                   ` (5 preceding siblings ...)
  2012-02-09 11:53 ` [PATCH 06/15] mci s3c: Do not mess with struct mci_host Sascha Hauer
@ 2012-02-09 11:53 ` Sascha Hauer
  2012-02-09 11:53 ` [PATCH 08/15] mci s3c: pass around the right pointer Sascha Hauer
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Sascha Hauer @ 2012-02-09 11:53 UTC (permalink / raw)
  To: barebox

Yes, it does make sense. First there will always be the next
hardware which has multiple controllers. Also, we shouldn't
give bad examples to others.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/s3c.c |   43 +++++++++++++++++--------------------------
 1 files changed, 17 insertions(+), 26 deletions(-)

diff --git a/drivers/mci/s3c.c b/drivers/mci/s3c.c
index a153b1c..44c682e 100644
--- a/drivers/mci/s3c.c
+++ b/drivers/mci/s3c.c
@@ -153,18 +153,13 @@
 #define SDIDATA 0x40
 
 struct s3c_mci_host {
+	struct mci_host	host;
 	void __iomem	*base;
 	int		bus_width:2; /* 0 = 1 bit, 1 = 4 bit, 2 = 8 bit */
 	unsigned	clock;	/* current clock in Hz */
 	unsigned	data_size;	/* data transfer in bytes */
 };
 
-/*
- * There is only one host MCI hardware instance available.
- * It makes no sense to dynamically allocate this data
- */
-static struct s3c_mci_host host_data;
-
 /**
  * Finish a request
  * @param hw_dev Host interface instance
@@ -743,20 +738,16 @@ static void s3c_info(struct device_d *hw_dev)
 }
 #endif
 
-/*
- * There is only one host MCI hardware instance available.
- * It makes no sense to dynamically allocate this data
- */
-static struct mci_host mci_pdata = {
-	.send_cmd = mci_request,
-	.set_ios = mci_set_ios,
-	.init = mci_reset,
-};
-
 static int s3c_mci_probe(struct device_d *hw_dev)
 {
+	struct s3c_mci_host *s3c_host;
 	struct s3c_mci_platform_data *pd = hw_dev->platform_data;
 
+	s3c_host = xzalloc(sizeof(*s3c_host));
+	s3c_host->host.send_cmd = mci_request;
+	s3c_host->host.set_ios = mci_set_ios;
+	s3c_host->host.init = mci_reset;
+
 	/* TODO replace by the global func: enable the SDI unit clock */
 	writel(readl(S3C_CLOCK_POWER_BASE + 0x0c) | 0x200,
 		S3C_CLOCK_POWER_BASE + 0x0c);
@@ -766,23 +757,23 @@ static int s3c_mci_probe(struct device_d *hw_dev)
 		return -EINVAL;
 	}
 
-	hw_dev->priv = &host_data;
-	host_data.base = dev_request_mem_region(hw_dev, 0);
-	mci_pdata.hw_dev = hw_dev;
+	hw_dev->priv = s3c_host;
+	s3c_host->base = dev_request_mem_region(hw_dev, 0);
+	s3c_host->host.hw_dev = hw_dev;
 
 	/* feed forward the platform specific values */
-	mci_pdata.voltages = pd->voltages;
-	mci_pdata.host_caps = pd->caps;
-	mci_pdata.f_min = pd->f_min == 0 ? s3c_get_pclk() / 256 : pd->f_min;
-	mci_pdata.f_max = pd->f_max == 0 ? s3c_get_pclk() / 2 : pd->f_max;
+	s3c_host->host.voltages = pd->voltages;
+	s3c_host->host.host_caps = pd->caps;
+	s3c_host->host.f_min = pd->f_min == 0 ? s3c_get_pclk() / 256 : pd->f_min;
+	s3c_host->host.f_max = pd->f_max == 0 ? s3c_get_pclk() / 2 : pd->f_max;
 
 	/*
 	 * Start the clock to let the engine and the card finishes its startup
 	 */
-	host_data.clock = s3c_setup_clock_speed(hw_dev, mci_pdata.f_min);
-	writel(SDICON_FIFORESET | SDICON_MMCCLOCK, host_data.base + SDICON);
+	s3c_host->clock = s3c_setup_clock_speed(hw_dev, pd->f_min);
+	writel(SDICON_FIFORESET | SDICON_MMCCLOCK, s3c_host->base + SDICON);
 
-	return mci_register(&mci_pdata);
+	return mci_register(&s3c_host->host);
 }
 
 static struct driver_d s3c_mci_driver = {
-- 
1.7.9


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 08/15] mci s3c: pass around the right pointer
  2012-02-09 11:53 [PATCH] mmc/sd patches Sascha Hauer
                   ` (6 preceding siblings ...)
  2012-02-09 11:53 ` [PATCH 07/15] mci s3c: allocate host struct dynamically Sascha Hauer
@ 2012-02-09 11:53 ` Sascha Hauer
  2012-02-09 11:53 ` [PATCH 09/15] mci: remove unused device argument from set_ios Sascha Hauer
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Sascha Hauer @ 2012-02-09 11:53 UTC (permalink / raw)
  To: barebox

The s3c driver passes around a struct device_d * internally in which
it is never interested in. Instead pass around a struct s3c_mci_host
and get rid of all this ugly void * derefs.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/s3c.c |  103 +++++++++++++++++++++++------------------------------
 1 files changed, 45 insertions(+), 58 deletions(-)

diff --git a/drivers/mci/s3c.c b/drivers/mci/s3c.c
index 44c682e..6648d6f 100644
--- a/drivers/mci/s3c.c
+++ b/drivers/mci/s3c.c
@@ -160,13 +160,15 @@ struct s3c_mci_host {
 	unsigned	data_size;	/* data transfer in bytes */
 };
 
+#define to_s3c_host(h)	container_of(h, struct s3c_mci_host, host)
+
 /**
  * Finish a request
  * @param hw_dev Host interface instance
  *
  * Just a little bit paranoia.
  */
-static void s3c_finish_request(struct device_d *hw_dev)
+static void s3c_finish_request(struct s3c_mci_host *host_data)
 {
 	/* TODO ensure the engines are stopped */
 }
@@ -177,11 +179,10 @@ static void s3c_finish_request(struct device_d *hw_dev)
  * @param nc New clock value in Hz (can be 0)
  * @return New clock value (may differ from 'nc')
  */
-static unsigned s3c_setup_clock_speed(struct device_d *hw_dev, unsigned nc)
+static unsigned s3c_setup_clock_speed(struct s3c_mci_host *host_data, unsigned nc)
 {
 	unsigned clock;
 	uint32_t mci_psc;
-	struct s3c_mci_host *host_data = GET_HOST_DATA(hw_dev);
 
 	if (nc == 0)
 		return 0;
@@ -206,10 +207,8 @@ static unsigned s3c_setup_clock_speed(struct device_d *hw_dev, unsigned nc)
  *
  * This will reset everything in all registers of this unit!
  */
-static void s3c_mci_reset(struct device_d *hw_dev)
+static void s3c_mci_reset(struct s3c_mci_host *host_data)
 {
-	struct s3c_mci_host *host_data = GET_HOST_DATA(hw_dev);
-
 	/* reset the hardware */
 	writel(SDICON_SDRESET, host_data->base + SDICON);
 	/* wait until reset it finished */
@@ -222,14 +221,12 @@ static void s3c_mci_reset(struct device_d *hw_dev)
  * @param hw_dev Host interface instance
  * @param mci_dev MCI device instance (might be NULL)
  */
-static int s3c_mci_initialize(struct device_d *hw_dev, struct device_d *mci_dev)
+static int s3c_mci_initialize(struct s3c_mci_host *host_data, struct device_d *mci_dev)
 {
-	struct s3c_mci_host *host_data = GET_HOST_DATA(hw_dev);
-
-	s3c_mci_reset(hw_dev);
+	s3c_mci_reset(host_data);
 
 	/* restore last settings */
-	host_data->clock = s3c_setup_clock_speed(hw_dev, host_data->clock);
+	host_data->clock = s3c_setup_clock_speed(host_data, host_data->clock);
 	writel(0x007FFFFF, host_data->base + SDITIMER);
 	writel(SDICON_MMCCLOCK, host_data->base + SDICON);
 	writel(512, host_data->base + SDIBSIZE);
@@ -276,9 +273,8 @@ static uint32_t s3c_prepare_command_setup(unsigned cmd_flags, unsigned data_flag
  * @param data_flags MCI's data flags
  * @return Register bits for this transfer
  */
-static uint32_t s3c_prepare_data_setup(struct device_d *hw_dev, unsigned data_flags)
+static uint32_t s3c_prepare_data_setup(struct s3c_mci_host *host_data, unsigned data_flags)
 {
-	struct s3c_mci_host *host_data = (struct s3c_mci_host*)GET_HOST_DATA(hw_dev);
 	uint32_t reg = SDIDCON_BLOCKMODE;	/* block mode only is supported */
 
 	if (host_data->bus_width == 1)
@@ -305,16 +301,15 @@ static uint32_t s3c_prepare_data_setup(struct device_d *hw_dev, unsigned data_fl
  * Note: Try to stop a running transfer. This should not happen, as all
  * transfers must complete in this driver. But who knows... ;-)
  */
-static int s3c_terminate_transfer(struct device_d *hw_dev)
+static int s3c_terminate_transfer(struct s3c_mci_host *host_data)
 {
 	unsigned stoptries = 3;
-	struct s3c_mci_host *host_data = GET_HOST_DATA(hw_dev);
 
 	while (readl(host_data->base + SDIDSTA) & (SDIDSTA_TXDATAON | SDIDSTA_RXDATAON)) {
 		pr_debug("Transfer still in progress.\n");
 
 		writel(SDIDCON_STOP, host_data->base + SDIDCON);
-		s3c_mci_initialize(hw_dev, NULL);
+		s3c_mci_initialize(host_data, NULL);
 
 		if ((stoptries--) == 0) {
 			pr_warning("Cannot stop the engine!\n");
@@ -331,13 +326,12 @@ static int s3c_terminate_transfer(struct device_d *hw_dev)
  * @param data The data information (buffer, direction aso.)
  * @return 0 on success
  */
-static int s3c_prepare_data_transfer(struct device_d *hw_dev, struct mci_data *data)
+static int s3c_prepare_data_transfer(struct s3c_mci_host *host_data, struct mci_data *data)
 {
 	uint32_t reg;
-	struct s3c_mci_host *host_data = GET_HOST_DATA(hw_dev);
 
 	writel(data->blocksize, host_data->base + SDIBSIZE);
-	reg = s3c_prepare_data_setup(hw_dev, data->flags);
+	reg = s3c_prepare_data_setup(host_data, data->flags);
 	reg |= data->blocks & SDIDCON_BLKNUM;
 	writel(reg, host_data->base + SDIDCON);
 	writel(0x007FFFFF, host_data->base + SDITIMER);
@@ -352,12 +346,11 @@ static int s3c_prepare_data_transfer(struct device_d *hw_dev, struct mci_data *d
  * @param data The data information (buffer, direction aso.)
  * @return 0 on success
  */
-static int s3c_send_command(struct device_d *hw_dev, struct mci_cmd *cmd,
+static int s3c_send_command(struct s3c_mci_host *host_data, struct mci_cmd *cmd,
 				struct mci_data *data)
 {
 	uint32_t reg, t1;
 	int rc;
-	struct s3c_mci_host *host_data = GET_HOST_DATA(hw_dev);
 
 	writel(0x007FFFFF, host_data->base + SDITIMER);
 
@@ -416,12 +409,11 @@ static int s3c_send_command(struct device_d *hw_dev, struct mci_cmd *cmd,
  *
  * FIFO clear is only necessary on 2440, but doesn't hurt on 2410
  */
-static int s3c_prepare_engine(struct device_d *hw_dev)
+static int s3c_prepare_engine(struct s3c_mci_host *host_data)
 {
 	int rc;
-	struct s3c_mci_host *host_data = GET_HOST_DATA(hw_dev);
 
-	rc = s3c_terminate_transfer(hw_dev);
+	rc = s3c_terminate_transfer(host_data);
 	if (rc != 0)
 		return rc;
 
@@ -443,15 +435,15 @@ static int s3c_prepare_engine(struct device_d *hw_dev)
  * - "broadcast commands with response (BCR)"
  * - "addressed command (AC)" with response, but without data
  */
-static int s3c_mci_std_cmds(struct device_d *hw_dev, struct mci_cmd *cmd)
+static int s3c_mci_std_cmds(struct s3c_mci_host *host_data, struct mci_cmd *cmd)
 {
 	int rc;
 
-	rc = s3c_prepare_engine(hw_dev);
+	rc = s3c_prepare_engine(host_data);
 	if (rc != 0)
 		return 0;
 
-	return s3c_send_command(hw_dev, cmd, NULL);
+	return s3c_send_command(host_data, cmd, NULL);
 }
 
 /**
@@ -460,11 +452,10 @@ static int s3c_mci_std_cmds(struct device_d *hw_dev, struct mci_cmd *cmd)
  * @param data The data information (buffer, direction aso.)
  * @return 0 on success
  */
-static int s3c_mci_read_block(struct device_d *hw_dev, struct mci_data *data)
+static int s3c_mci_read_block(struct s3c_mci_host *host_data, struct mci_data *data)
 {
 	uint32_t *p;
 	unsigned cnt, data_size;
-	struct s3c_mci_host *host_data = GET_HOST_DATA(hw_dev);
 
 #define READ_REASON_TO_FAIL (SDIDSTA_CRCFAIL | SDIDSTA_RXCRCFAIL | SDIDSTA_DATATIMEOUT)
 
@@ -514,13 +505,12 @@ static int s3c_mci_read_block(struct device_d *hw_dev, struct mci_data *data)
  * We must ensure data in the FIFO when the command phase changes into the
  * data phase. To ensure this, the FIFO gets filled first, then the command.
  */
-static int s3c_mci_write_block(struct device_d *hw_dev, struct mci_cmd *cmd,
+static int s3c_mci_write_block(struct s3c_mci_host *host_data, struct mci_cmd *cmd,
 				struct mci_data *data)
 {
 	const uint32_t *p = (const uint32_t*)data->src;
 	unsigned cnt, data_size;
 	uint32_t reg;
-	struct s3c_mci_host *host_data = GET_HOST_DATA(hw_dev);
 
 #define WRITE_REASON_TO_FAIL (SDIDSTA_CRCFAIL | SDIDSTA_DATATIMEOUT)
 
@@ -543,7 +533,7 @@ static int s3c_mci_write_block(struct device_d *hw_dev, struct mci_cmd *cmd,
 	}
 
 	/* data is now in place and waits for transmitt. Start the command right now */
-	s3c_send_command(hw_dev, cmd, data);
+	s3c_send_command(host_data, cmd, data);
 
 	if ((reg = readl(host_data->base + SDIFSTA)) & SDIFSTA_FIFOFAIL) {
 		pr_err("Command fails immediatly due to FIFO underrun when writing %08X\n",
@@ -591,37 +581,36 @@ static int s3c_mci_write_block(struct device_d *hw_dev, struct mci_cmd *cmd,
  * @param data The data information (buffer, direction aso.)
  * @return 0 on success
 */
-static int s3c_mci_adtc(struct device_d *hw_dev, struct mci_cmd *cmd,
+static int s3c_mci_adtc(struct s3c_mci_host *host_data, struct mci_cmd *cmd,
 			struct mci_data *data)
 {
 	int rc;
-	struct s3c_mci_host *host_data = GET_HOST_DATA(hw_dev);
 
-	rc = s3c_prepare_engine(hw_dev);
+	rc = s3c_prepare_engine(host_data);
 	if (rc != 0)
 		return rc;
 
-	rc = s3c_prepare_data_transfer(hw_dev, data);
+	rc = s3c_prepare_data_transfer(host_data, data);
 	if (rc != 0)
 		return rc;
 
 	if (data->flags & MMC_DATA_READ) {
-		s3c_send_command(hw_dev, cmd, data);
-		rc = s3c_mci_read_block(hw_dev, data);
+		s3c_send_command(host_data, cmd, data);
+		rc = s3c_mci_read_block(host_data, data);
 		if (rc == 0) {
 			while (!(readl(host_data->base + SDIDSTA) & SDIDSTA_XFERFINISH))
 				;
 		} else
-			s3c_terminate_transfer(hw_dev);
+			s3c_terminate_transfer(host_data);
 	}
 
 	if (data->flags & MMC_DATA_WRITE) {
-		rc = s3c_mci_write_block(hw_dev, cmd, data);
+		rc = s3c_mci_write_block(host_data, cmd, data);
 		if (rc == 0) {
 			while (!(readl(host_data->base + SDIDSTA) & SDIDSTA_XFERFINISH))
 				;
 		} else
-			s3c_terminate_transfer(hw_dev);
+			s3c_terminate_transfer(host_data);
 	}
 	writel(0, host_data->base + SDIDCON);
 
@@ -632,29 +621,28 @@ static int s3c_mci_adtc(struct device_d *hw_dev, struct mci_cmd *cmd,
 
 /**
  * Keep the attached MMC/SD unit in a well know state
- * @param mci_pdata MCI platform data
+ * @param host MCI host
  * @param mci_dev MCI device instance
  * @return 0 on success, negative value else
  */
-static int mci_reset(struct mci_host *mci_pdata, struct device_d *mci_dev)
+static int mci_reset(struct mci_host *host, struct device_d *mci_dev)
 {
-	struct device_d *hw_dev = mci_pdata->hw_dev;
+	struct s3c_mci_host *host_data = to_s3c_host(host);
 
-	return s3c_mci_initialize(hw_dev, mci_dev);
+	return s3c_mci_initialize(host_data, mci_dev);
 }
 
 /**
  * Process one command to the MCI card
- * @param mci_pdata MCI platform data
+ * @param host MCI host
  * @param cmd The command to process
  * @param data The data to handle in the command (can be NULL)
  * @return 0 on success, negative value else
  */
-static int mci_request(struct mci_host *mci_pdata, struct mci_cmd *cmd,
+static int mci_request(struct mci_host *host, struct mci_cmd *cmd,
 			struct mci_data *data)
 {
-	struct device_d *hw_dev = mci_pdata->hw_dev;
-	struct s3c_mci_host *host_data = GET_HOST_DATA(hw_dev);
+	struct s3c_mci_host *host_data = to_s3c_host(host);
 	int rc;
 
 	/* enable clock */
@@ -662,11 +650,11 @@ static int mci_request(struct mci_host *mci_pdata, struct mci_cmd *cmd,
 		host_data->base + SDICON);
 
 	if ((cmd->resp_type == 0) || (data == NULL))
-		rc = s3c_mci_std_cmds(hw_dev, cmd);
+		rc = s3c_mci_std_cmds(host_data, cmd);
 	else
-		rc = s3c_mci_adtc(hw_dev, cmd, data);	/* with response and data */
+		rc = s3c_mci_adtc(host_data, cmd, data);	/* with response and data */
 
-	s3c_finish_request(hw_dev);
+	s3c_finish_request(host_data);
 
 	/* disable clock */
 	writel(readl(host_data->base + SDICON) & ~SDICON_CLKEN,
@@ -676,16 +664,15 @@ static int mci_request(struct mci_host *mci_pdata, struct mci_cmd *cmd,
 
 /**
  * Setup the bus width and IO speed
- * @param mci_pdata MCI platform data
+ * @param host MCI host
  * @param mci_dev MCI device instance
  * @param bus_width New bus width value (1, 4 or 8)
  * @param clock New clock in Hz (can be '0' to disable the clock)
  */
-static void mci_set_ios(struct mci_host *mci_pdata, struct device_d *mci_dev,
+static void mci_set_ios(struct mci_host *host, struct device_d *mci_dev,
 			struct mci_ios *ios)
 {
-	struct device_d *hw_dev = mci_pdata->hw_dev;
-	struct s3c_mci_host *host_data = GET_HOST_DATA(hw_dev);
+	struct s3c_mci_host *host_data = to_s3c_host(host);
 	uint32_t reg;
 
 	switch (ios->bus_width) {
@@ -702,7 +689,7 @@ static void mci_set_ios(struct mci_host *mci_pdata, struct device_d *mci_dev,
 	reg = readl(host_data->base + SDICON);
 	if (ios->clock) {
 		/* setup the IO clock frequency and enable it */
-		host_data->clock = s3c_setup_clock_speed(hw_dev, ios->clock);
+		host_data->clock = s3c_setup_clock_speed(host_data, ios->clock);
 		reg |= SDICON_CLKEN;	/* enable the clock */
 	} else {
 		reg &= ~SDICON_CLKEN;	/* disable the clock */
@@ -770,7 +757,7 @@ static int s3c_mci_probe(struct device_d *hw_dev)
 	/*
 	 * Start the clock to let the engine and the card finishes its startup
 	 */
-	s3c_host->clock = s3c_setup_clock_speed(hw_dev, pd->f_min);
+	s3c_host->clock = s3c_setup_clock_speed(s3c_host, pd->f_min);
 	writel(SDICON_FIFORESET | SDICON_MMCCLOCK, s3c_host->base + SDICON);
 
 	return mci_register(&s3c_host->host);
-- 
1.7.9


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 09/15] mci: remove unused device argument from set_ios
  2012-02-09 11:53 [PATCH] mmc/sd patches Sascha Hauer
                   ` (7 preceding siblings ...)
  2012-02-09 11:53 ` [PATCH 08/15] mci s3c: pass around the right pointer Sascha Hauer
@ 2012-02-09 11:53 ` Sascha Hauer
  2012-02-09 11:53 ` [PATCH 10/15] mci core: fix mixup of max write/read block len Sascha Hauer
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Sascha Hauer @ 2012-02-09 11:53 UTC (permalink / raw)
  To: barebox

This argmuent is unused in all drivers, so remove it.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/atmel_mci.c  |    3 +--
 drivers/mci/imx-esdhc.c  |    3 +--
 drivers/mci/imx.c        |    3 +--
 drivers/mci/mci-core.c   |    2 +-
 drivers/mci/mci_spi.c    |    3 +--
 drivers/mci/mxs.c        |    3 +--
 drivers/mci/omap_hsmmc.c |    3 +--
 drivers/mci/pxamci.c     |    3 +--
 drivers/mci/s3c.c        |    4 +---
 include/mci.h            |    2 +-
 10 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/drivers/mci/atmel_mci.c b/drivers/mci/atmel_mci.c
index e0272b9..6e74990 100644
--- a/drivers/mci/atmel_mci.c
+++ b/drivers/mci/atmel_mci.c
@@ -351,8 +351,7 @@ static int mci_reset(struct mci_host *mci, struct device_d *mci_dev)
 }
 
 /** change host interface settings */
-static void mci_set_ios(struct mci_host *mci, struct device_d *mci_dev,
-			struct mci_ios *ios)
+static void mci_set_ios(struct mci_host *mci, struct mci_ios *ios)
 {
 	struct atmel_mci_host *host = to_mci_host(mci);
 
diff --git a/drivers/mci/imx-esdhc.c b/drivers/mci/imx-esdhc.c
index f1e876b..2123a8b 100644
--- a/drivers/mci/imx-esdhc.c
+++ b/drivers/mci/imx-esdhc.c
@@ -375,8 +375,7 @@ void set_sysctl(struct mci_host *mci, u32 clock)
 	esdhc_setbits32(&regs->sysctl, clk);
 }
 
-static void esdhc_set_ios(struct mci_host *mci, struct device_d *dev,
-		struct mci_ios *ios)
+static void esdhc_set_ios(struct mci_host *mci, struct mci_ios *ios)
 {
 	struct fsl_esdhc_host *host = to_fsl_esdhc(mci);
 	struct fsl_esdhc *regs = host->regs;
diff --git a/drivers/mci/imx.c b/drivers/mci/imx.c
index 2ce34bb..0e4fa66 100644
--- a/drivers/mci/imx.c
+++ b/drivers/mci/imx.c
@@ -441,8 +441,7 @@ static void mxcmci_set_clk_rate(struct mxcmci_host *host, unsigned int clk_ios)
 	writew((prescaler << 4) | divider, &host->base->clk_rate);
 }
 
-static void mxcmci_set_ios(struct mci_host *mci, struct device_d *dev,
-		struct mci_ios *ios)
+static void mxcmci_set_ios(struct mci_host *mci, struct mci_ios *ios)
 {
 	struct mxcmci_host *host = to_mxcmci(mci);
 
diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 18ccc9c..e0e70dd 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -596,7 +596,7 @@ static void mci_set_ios(struct device_d *mci_dev)
 	ios.bus_width = host->bus_width;
 	ios.clock = host->clock;
 
-	host->set_ios(host, mci_dev, &ios);
+	host->set_ios(host, &ios);
 }
 
 /**
diff --git a/drivers/mci/mci_spi.c b/drivers/mci/mci_spi.c
index 0f94dab..a659ebb 100644
--- a/drivers/mci/mci_spi.c
+++ b/drivers/mci/mci_spi.c
@@ -329,8 +329,7 @@ return  0;
 
 }
 
-static void mmc_spi_set_ios(struct mci_host *mci, struct device_d *mci_dev,
-			struct mci_ios *ios)
+static void mmc_spi_set_ios(struct mci_host *mci, struct mci_ios *ios)
 {
 	struct mmc_spi_host	*host = to_spi_host(mci);
 
diff --git a/drivers/mci/mxs.c b/drivers/mci/mxs.c
index 4b944fd..eaef41b 100644
--- a/drivers/mci/mxs.c
+++ b/drivers/mci/mxs.c
@@ -640,8 +640,7 @@ static int mxs_mci_request(struct mci_host *host, struct mci_cmd *cmd,
  *
  * Drivers currently realized values are stored in MCI's platformdata
  */
-static void mxs_mci_set_ios(struct mci_host *host, struct device_d *mci_dev,
-			struct mci_ios *ios)
+static void mxs_mci_set_ios(struct mci_host *host, struct mci_ios *ios)
 {
 	struct mxs_mci_host *mxs_mci = to_mxs_mci(host);
 
diff --git a/drivers/mci/omap_hsmmc.c b/drivers/mci/omap_hsmmc.c
index e629fba..e0b245b 100644
--- a/drivers/mci/omap_hsmmc.c
+++ b/drivers/mci/omap_hsmmc.c
@@ -510,8 +510,7 @@ static int mmc_send_cmd(struct mci_host *mci, struct mci_cmd *cmd,
 	return 0;
 }
 
-static void mmc_set_ios(struct mci_host *mci, struct device_d *dev,
-		struct mci_ios *ios)
+static void mmc_set_ios(struct mci_host *mci, struct mci_ios *ios)
 {
 	struct omap_hsmmc *hsmmc = to_hsmmc(mci);
 	struct hsmmc *mmc_base = hsmmc->base;
diff --git a/drivers/mci/pxamci.c b/drivers/mci/pxamci.c
index a22bdba..239b46a 100644
--- a/drivers/mci/pxamci.c
+++ b/drivers/mci/pxamci.c
@@ -273,8 +273,7 @@ static int pxamci_request(struct mci_host *mci, struct mci_cmd *cmd,
 	return ret;
 }
 
-static void pxamci_set_ios(struct mci_host *mci, struct device_d *dev,
-			   struct mci_ios *ios)
+static void pxamci_set_ios(struct mci_host *mci, struct mci_ios *ios)
 {
 	struct pxamci_host *host = to_pxamci(mci);
 	unsigned int clk_in = pxa_get_mmcclk();
diff --git a/drivers/mci/s3c.c b/drivers/mci/s3c.c
index 6648d6f..e7646c9 100644
--- a/drivers/mci/s3c.c
+++ b/drivers/mci/s3c.c
@@ -665,12 +665,10 @@ static int mci_request(struct mci_host *host, struct mci_cmd *cmd,
 /**
  * Setup the bus width and IO speed
  * @param host MCI host
- * @param mci_dev MCI device instance
  * @param bus_width New bus width value (1, 4 or 8)
  * @param clock New clock in Hz (can be '0' to disable the clock)
  */
-static void mci_set_ios(struct mci_host *host, struct device_d *mci_dev,
-			struct mci_ios *ios)
+static void mci_set_ios(struct mci_host *host, struct mci_ios *ios)
 {
 	struct s3c_mci_host *host_data = to_s3c_host(host);
 	uint32_t reg;
diff --git a/include/mci.h b/include/mci.h
index 3473aaa..9215e39 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -260,7 +260,7 @@ struct mci_host {
 	/** init the host interface */
 	int (*init)(struct mci_host*, struct device_d*);
 	/** change host interface settings */
-	void (*set_ios)(struct mci_host*, struct device_d*, struct mci_ios *);
+	void (*set_ios)(struct mci_host*, struct mci_ios *);
 	/** handle a command */
 	int (*send_cmd)(struct mci_host*, struct mci_cmd*, struct mci_data*);
 };
-- 
1.7.9


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 10/15] mci core: fix mixup of max write/read block len
  2012-02-09 11:53 [PATCH] mmc/sd patches Sascha Hauer
                   ` (8 preceding siblings ...)
  2012-02-09 11:53 ` [PATCH 09/15] mci: remove unused device argument from set_ios Sascha Hauer
@ 2012-02-09 11:53 ` Sascha Hauer
  2012-02-09 11:53 ` [PATCH 11/15] mci: Use struct mci for internal argument passing Sascha Hauer
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Sascha Hauer @ 2012-02-09 11:53 UTC (permalink / raw)
  To: barebox

The argmument order in this pr_debug does not match
the string printed. Fix this.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/mci-core.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index e0e70dd..1c0e4e7 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -753,7 +753,7 @@ static void mci_extract_block_lengths_from_csd(struct device_d *mci_dev)
 		mci->write_bl_len = 1 << ((mci->csd[3] >> 22) & 0xf);
 
 	pr_debug("Max. block length are: Write=%u, Read=%u Bytes\n",
-		mci->read_bl_len, mci->write_bl_len);
+		mci->write_bl_len, mci->read_bl_len);
 }
 
 /**
-- 
1.7.9


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 11/15] mci: Use struct mci for internal argument passing
  2012-02-09 11:53 [PATCH] mmc/sd patches Sascha Hauer
                   ` (9 preceding siblings ...)
  2012-02-09 11:53 ` [PATCH 10/15] mci core: fix mixup of max write/read block len Sascha Hauer
@ 2012-02-09 11:53 ` Sascha Hauer
  2012-02-09 11:53 ` [PATCH 12/15] mci: replace pr_debug with dev_dbg Sascha Hauer
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Sascha Hauer @ 2012-02-09 11:53 UTC (permalink / raw)
  To: barebox

The mci layer currently passes around a struct device_d for
its internal use. Apart from being confusing this drops
typesafety for no good reason. Instead, pass around a struct
mci.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/mci-core.c |  271 +++++++++++++++++++++++-------------------------
 drivers/mci/s3c.c      |    3 +
 include/mci.h          |    7 +-
 3 files changed, 133 insertions(+), 148 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 1c0e4e7..49e1c42 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -57,16 +57,16 @@
 
 /**
  * Call the MMC/SD instance driver to run the command on the MMC/SD card
- * @param mci_dev MCI instance
+ * @param mci MCI instance
  * @param cmd The information about the command to run
  * @param data The data according to the command (can be NULL)
  * @return Driver's answer (0 on success)
  */
-static int mci_send_cmd(struct device_d *mci_dev, struct mci_cmd *cmd, struct mci_data *data)
+static int mci_send_cmd(struct mci *mci, struct mci_cmd *cmd, struct mci_data *data)
 {
-	struct mci_host *host = GET_MCI_PDATA(mci_dev);
+	struct mci_host *host = mci->host;
 
-	return host->send_cmd(host, cmd, data);
+	return host->send_cmd(mci->host, cmd, data);
 }
 
 /**
@@ -90,12 +90,12 @@ static void mci_setup_cmd(struct mci_cmd *p, unsigned cmd, unsigned arg, unsigne
  * @param len Blocklength in bytes
  * @return Transaction status (0 on success)
  */
-static int mci_set_blocklen(struct device_d *mci_dev, unsigned len)
+static int mci_set_blocklen(struct mci *mci, unsigned len)
 {
 	struct mci_cmd cmd;
 
 	mci_setup_cmd(&cmd, MMC_CMD_SET_BLOCKLEN, len, MMC_RSP_R1);
-	return mci_send_cmd(mci_dev, &cmd, NULL);
+	return mci_send_cmd(mci, &cmd, NULL);
 }
 
 static void *sector_buf;
@@ -108,10 +108,9 @@ static void *sector_buf;
  * @param blocks Block count to write
  * @return Transaction status (0 on success)
  */
-static int mci_block_write(struct device_d *mci_dev, const void *src, int blocknum,
+static int mci_block_write(struct mci *mci, const void *src, int blocknum,
 	int blocks)
 {
-	struct mci *mci = GET_MCI_DATA(mci_dev);
 	struct mci_cmd cmd;
 	struct mci_data data;
 	const void *buf;
@@ -140,7 +139,7 @@ static int mci_block_write(struct device_d *mci_dev, const void *src, int blockn
 	data.blocksize = mci->write_bl_len;
 	data.flags = MMC_DATA_WRITE;
 
-	ret = mci_send_cmd(mci_dev, &cmd, &data);
+	ret = mci_send_cmd(mci, &cmd, &data);
 	if (ret)
 		return ret;
 
@@ -148,7 +147,7 @@ static int mci_block_write(struct device_d *mci_dev, const void *src, int blockn
 		mci_setup_cmd(&cmd,
 			MMC_CMD_STOP_TRANSMISSION,
 			0, MMC_RSP_R1b);
-			ret = mci_send_cmd(mci_dev, &cmd, NULL);
+			ret = mci_send_cmd(mci, &cmd, NULL);
 			if (ret)
 				return ret;
         }
@@ -158,15 +157,14 @@ static int mci_block_write(struct device_d *mci_dev, const void *src, int blockn
 
 /**
  * Read one block of data from the card
- * @param mci_dev MCI instance
+ * @param mci MCI instance
  * @param dst Where to store the data read from the card
  * @param blocknum Block number to read
  * @param blocks number of blocks to read
  */
-static int mci_read_block(struct device_d *mci_dev, void *dst, int blocknum,
+static int mci_read_block(struct mci *mci, void *dst, int blocknum,
 		int blocks)
 {
-	struct mci *mci = GET_MCI_DATA(mci_dev);
 	struct mci_cmd cmd;
 	struct mci_data data;
 	int ret;
@@ -187,7 +185,7 @@ static int mci_read_block(struct device_d *mci_dev, void *dst, int blocknum,
 	data.blocksize = mci->read_bl_len;
 	data.flags = MMC_DATA_READ;
 
-	ret = mci_send_cmd(mci_dev, &cmd, &data);
+	ret = mci_send_cmd(mci, &cmd, &data);
 	if (ret)
 		return ret;
 
@@ -196,17 +194,17 @@ static int mci_read_block(struct device_d *mci_dev, void *dst, int blocknum,
 			MMC_CMD_STOP_TRANSMISSION,
 			0,
 			MMC_RSP_R1b);
-			ret = mci_send_cmd(mci_dev, &cmd, NULL);
+			ret = mci_send_cmd(mci, &cmd, NULL);
 	}
 	return ret;
 }
 
 /**
  * Reset the attached MMC/SD card
- * @param mci_dev MCI instance
+ * @param mci MCI instance
  * @return Transaction status (0 on success)
  */
-static int mci_go_idle(struct device_d *mci_dev)
+static int mci_go_idle(struct mci *mci)
 {
 	struct mci_cmd cmd;
 	int err;
@@ -214,7 +212,7 @@ static int mci_go_idle(struct device_d *mci_dev)
 	udelay(1000);
 
 	mci_setup_cmd(&cmd, MMC_CMD_GO_IDLE_STATE, 0, MMC_RSP_NONE);
-	err = mci_send_cmd(mci_dev, &cmd, NULL);
+	err = mci_send_cmd(mci, &cmd, NULL);
 
 	if (err) {
 		pr_debug("Activating IDLE state failed: %d\n", err);
@@ -228,13 +226,12 @@ static int mci_go_idle(struct device_d *mci_dev)
 
 /**
  * FIXME
- * @param mci_dev MCI instance
+ * @param mci MCI instance
  * @return Transaction status (0 on success)
  */
-static int sd_send_op_cond(struct device_d *mci_dev)
+static int sd_send_op_cond(struct mci *mci)
 {
-	struct mci *mci = GET_MCI_DATA(mci_dev);
-	struct mci_host *host = GET_MCI_PDATA(mci_dev);
+	struct mci_host *host = mci->host;
 	struct mci_cmd cmd;
 	int timeout = 1000;
 	int err;
@@ -252,7 +249,7 @@ static int sd_send_op_cond(struct device_d *mci_dev)
 
 	do {
 		mci_setup_cmd(&cmd, MMC_CMD_APP_CMD, 0, MMC_RSP_R1);
-		err = mci_send_cmd(mci_dev, &cmd, NULL);
+		err = mci_send_cmd(mci, &cmd, NULL);
 		if (err) {
 			pr_debug("Preparing SD for operating conditions failed: %d\n", err);
 			return err;
@@ -261,7 +258,7 @@ static int sd_send_op_cond(struct device_d *mci_dev)
 		mci_setup_cmd(&cmd, SD_CMD_APP_SEND_OP_COND,
 			mmc_host_is_spi(host) ? 0 : (voltages | (mci->version == SD_VERSION_2 ? OCR_HCS : 0)),
 			MMC_RSP_R3);
-		err = mci_send_cmd(mci_dev, &cmd, NULL);
+		err = mci_send_cmd(mci, &cmd, NULL);
 		if (err) {
 			pr_debug("SD operation condition set failed: %d\n", err);
 			return err;
@@ -285,7 +282,7 @@ static int sd_send_op_cond(struct device_d *mci_dev)
 
 	if (mmc_host_is_spi(host)) { /* read OCR for spi */
 		mci_setup_cmd(&cmd, MMC_CMD_SPI_READ_OCR, 0, MMC_RSP_R3);
-		err = mci_send_cmd(mci_dev, &cmd, NULL);
+		err = mci_send_cmd(mci, &cmd, NULL);
 		if (err)
 			return err;
 	}
@@ -300,24 +297,23 @@ static int sd_send_op_cond(struct device_d *mci_dev)
 
 /**
  * Setup the operation conditions to a MultiMediaCard
- * @param mci_dev MCI instance
+ * @param mci MCI instance
  * @return Transaction status (0 on success)
  */
-static int mmc_send_op_cond(struct device_d *mci_dev)
+static int mmc_send_op_cond(struct mci *mci)
 {
-	struct mci *mci = GET_MCI_DATA(mci_dev);
-	struct mci_host *host = GET_MCI_PDATA(mci_dev);
+	struct mci_host *host = mci->host;
 	struct mci_cmd cmd;
 	int timeout = 1000;
 	int err;
 
 	/* Some cards seem to need this */
-	mci_go_idle(mci_dev);
+	mci_go_idle(mci);
 
 	do {
 		mci_setup_cmd(&cmd, MMC_CMD_SEND_OP_COND, OCR_HCS |
 				host->voltages, MMC_RSP_R3);
-		err = mci_send_cmd(mci_dev, &cmd, NULL);
+		err = mci_send_cmd(mci, &cmd, NULL);
 
 		if (err) {
 			pr_debug("Preparing MMC for operating conditions failed: %d\n", err);
@@ -343,14 +339,14 @@ static int mmc_send_op_cond(struct device_d *mci_dev)
 
 /**
  * FIXME
- * @param mci_dev MCI instance
+ * @param mci MCI instance
  * @param ext_csd Buffer for a 512 byte sized extended CSD
  * @return Transaction status (0 on success)
  *
  * Note: Only cards newer than Version 1.1 (Physical Layer Spec) support
  * this command
  */
-static int mci_send_ext_csd(struct device_d *mci_dev, char *ext_csd)
+static int mci_send_ext_csd(struct mci *mci, char *ext_csd)
 {
 	struct mci_cmd cmd;
 	struct mci_data data;
@@ -363,18 +359,18 @@ static int mci_send_ext_csd(struct device_d *mci_dev, char *ext_csd)
 	data.blocksize = 512;
 	data.flags = MMC_DATA_READ;
 
-	return mci_send_cmd(mci_dev, &cmd, &data);
+	return mci_send_cmd(mci, &cmd, &data);
 }
 
 /**
  * FIXME
- * @param mci_dev MCI instance
+ * @param mci MCI instance
  * @param set FIXME
  * @param index FIXME
  * @param value FIXME
  * @return Transaction status (0 on success)
  */
-static int mci_switch(struct device_d *mci_dev, unsigned set, unsigned index,
+static int mci_switch(struct mci *mci, unsigned set, unsigned index,
 			unsigned value)
 {
 	struct mci_cmd cmd;
@@ -385,17 +381,16 @@ static int mci_switch(struct device_d *mci_dev, unsigned set, unsigned index,
 		(value << 8),
 		 MMC_RSP_R1b);
 
-	return mci_send_cmd(mci_dev, &cmd, NULL);
+	return mci_send_cmd(mci, &cmd, NULL);
 }
 
 /**
  * Change transfer frequency for an MMC card
- * @param mci_dev MCI instance
+ * @param mci MCI instance
  * @return Transaction status (0 on success)
  */
-static int mmc_change_freq(struct device_d *mci_dev)
+static int mmc_change_freq(struct mci *mci)
 {
-	struct mci *mci = GET_MCI_DATA(mci_dev);
 	char *ext_csd = sector_buf;
 	char cardtype;
 	int err;
@@ -408,7 +403,7 @@ static int mmc_change_freq(struct device_d *mci_dev)
 
 	mci->card_caps |= MMC_MODE_4BIT;
 
-	err = mci_send_ext_csd(mci_dev, ext_csd);
+	err = mci_send_ext_csd(mci, ext_csd);
 	if (err) {
 		pr_debug("Preparing for frequency setup failed: %d\n", err);
 		return err;
@@ -416,7 +411,7 @@ static int mmc_change_freq(struct device_d *mci_dev)
 
 	cardtype = ext_csd[EXT_CSD_CARD_TYPE] & EXT_CSD_CARD_TYPE_MASK;
 
-	err = mci_switch(mci_dev, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, 1);
+	err = mci_switch(mci, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, 1);
 
 	if (err) {
 		pr_debug("MMC frequency changing failed: %d\n", err);
@@ -424,7 +419,7 @@ static int mmc_change_freq(struct device_d *mci_dev)
 	}
 
 	/* Now check to see that it worked */
-	err = mci_send_ext_csd(mci_dev, ext_csd);
+	err = mci_send_ext_csd(mci, ext_csd);
 
 	if (err) {
 		pr_debug("Verifying frequency change failed: %d\n", err);
@@ -446,14 +441,14 @@ static int mmc_change_freq(struct device_d *mci_dev)
 
 /**
  * FIXME
- * @param mci_dev MCI instance
+ * @param mci MCI instance
  * @param mode FIXME
  * @param group FIXME
  * @param value FIXME
  * @param resp FIXME
  * @return Transaction status (0 on success)
  */
-static int sd_switch(struct device_d *mci_dev, unsigned mode, unsigned group,
+static int sd_switch(struct mci *mci, unsigned mode, unsigned group,
 			unsigned value, uint8_t *resp)
 {
 	struct mci_cmd cmd;
@@ -472,21 +467,20 @@ static int sd_switch(struct device_d *mci_dev, unsigned mode, unsigned group,
 	data.blocks = 1;
 	data.flags = MMC_DATA_READ;
 
-	return mci_send_cmd(mci_dev, &cmd, &data);
+	return mci_send_cmd(mci, &cmd, &data);
 }
 
 /**
  * Change transfer frequency for an SD card
- * @param mci_dev MCI instance
+ * @param mci MCI instance
  * @return Transaction status (0 on success)
  */
-static int sd_change_freq(struct device_d *mci_dev)
+static int sd_change_freq(struct mci *mci)
 {
-	struct mci *mci = GET_MCI_DATA(mci_dev);
 	struct mci_cmd cmd;
 	struct mci_data data;
 #ifdef CONFIG_MCI_SPI
-	struct mci_host *host = GET_MCI_PDATA(mci_dev);
+	struct mci_host *host = mci->host;
 #endif
 	uint32_t *switch_status = sector_buf;
 	uint32_t *scr = sector_buf;
@@ -501,7 +495,7 @@ static int sd_change_freq(struct device_d *mci_dev)
 
 	/* Read the SCR to find out if this card supports higher speeds */
 	mci_setup_cmd(&cmd, MMC_CMD_APP_CMD, mci->rca << 16, MMC_RSP_R1);
-	err = mci_send_cmd(mci_dev, &cmd, NULL);
+	err = mci_send_cmd(mci, &cmd, NULL);
 	if (err) {
 		pr_debug("Query SD card capabilities failed: %d\n", err);
 		return err;
@@ -518,7 +512,7 @@ retry_scr:
 	data.blocks = 1;
 	data.flags = MMC_DATA_READ;
 
-	err = mci_send_cmd(mci_dev, &cmd, &data);
+	err = mci_send_cmd(mci, &cmd, &data);
 	if (err) {
 		pr_debug(" Catch error (%d)", err);
 		if (timeout--) {
@@ -553,7 +547,7 @@ retry_scr:
 
 	timeout = 4;
 	while (timeout--) {
-		err = sd_switch(mci_dev, SD_SWITCH_CHECK, 0, 1,
+		err = sd_switch(mci, SD_SWITCH_CHECK, 0, 1,
 				(uint8_t*)switch_status);
 		if (err) {
 			pr_debug("Checking SD transfer switch frequency feature failed: %d\n", err);
@@ -572,7 +566,7 @@ retry_scr:
 	if (!(__be32_to_cpu(switch_status[3]) & SD_HIGHSPEED_SUPPORTED))
 		return 0;
 
-	err = sd_switch(mci_dev, SD_SWITCH_SWITCH, 0, 1, (uint8_t*)switch_status);
+	err = sd_switch(mci, SD_SWITCH_SWITCH, 0, 1, (uint8_t*)switch_status);
 	if (err) {
 		pr_debug("Switching SD transfer frequency failed: %d\n", err);
 		return err;
@@ -586,11 +580,11 @@ retry_scr:
 
 /**
  * Setup host's interface bus width and transfer frequency
- * @param mci_dev MCI instance
+ * @param mci MCI instance
  */
-static void mci_set_ios(struct device_d *mci_dev)
+static void mci_set_ios(struct mci *mci)
 {
-	struct mci_host *host = GET_MCI_PDATA(mci_dev);
+	struct mci_host *host = mci->host;
 	struct mci_ios ios;
 
 	ios.bus_width = host->bus_width;
@@ -601,12 +595,12 @@ static void mci_set_ios(struct device_d *mci_dev)
 
 /**
  * Setup host's interface transfer frequency
- * @param mci_dev MCI instance
+ * @param mci MCI instance
  * @param clock New clock in Hz to set
  */
-static void mci_set_clock(struct device_d *mci_dev, unsigned clock)
+static void mci_set_clock(struct mci *mci, unsigned clock)
 {
-	struct mci_host *host = GET_MCI_PDATA(mci_dev);
+	struct mci_host *host = mci->host;
 
 	/* check against any given limits */
 	if (clock > host->f_max)
@@ -616,30 +610,29 @@ static void mci_set_clock(struct device_d *mci_dev, unsigned clock)
 		clock = host->f_min;
 
 	host->clock = clock;	/* the new target frequency */
-	mci_set_ios(mci_dev);
+	mci_set_ios(mci);
 }
 
 /**
  * Setup host's interface bus width
- * @param mci_dev MCI instance
+ * @param mci MCI instance
  * @param width New interface bit width (1, 4 or 8)
  */
-static void mci_set_bus_width(struct device_d *mci_dev, unsigned width)
+static void mci_set_bus_width(struct mci *mci, unsigned width)
 {
-	struct mci_host *host = GET_MCI_PDATA(mci_dev);
+	struct mci_host *host = mci->host;
 
 	host->bus_width = width;	/* the new target bus width */
-	mci_set_ios(mci_dev);
+	mci_set_ios(mci);
 }
 
 /**
  * Extract card's version from its CSD
- * @param mci_dev MCI instance
+ * @param mci MCI instance
  * @return 0 on success
  */
-static void mci_detect_version_from_csd(struct device_d *mci_dev)
+static void mci_detect_version_from_csd(struct mci *mci)
 {
-	struct mci *mci = GET_MCI_DATA(mci_dev);
 	int version;
 	char *vstr;
 
@@ -714,13 +707,12 @@ static const unsigned char tran_speed_time[] = {
 
 /**
  * Extract max. transfer speed from the CSD
- * @param mci_dev MCI instance
+ * @param mci MCI instance
  *
  * Encoded in bit 103:96 (103: reserved, 102:99: time, 98:96 unit)
  */
-static void mci_extract_max_tran_speed_from_csd(struct device_d *mci_dev)
+static void mci_extract_max_tran_speed_from_csd(struct mci *mci)
 {
-	struct mci *mci = GET_MCI_DATA(mci_dev);
 	unsigned unit, time;
 
 	unit = tran_speed_unit[(mci->csd[0] & 0x7)];
@@ -737,14 +729,12 @@ static void mci_extract_max_tran_speed_from_csd(struct device_d *mci_dev)
 
 /**
  * Extract max read and write block length from the CSD
- * @param mci_dev MCI instance
+ * @param mci MCI instance
  *
  * Encoded in bit 83:80 (read) and 25:22 (write)
  */
-static void mci_extract_block_lengths_from_csd(struct device_d *mci_dev)
+static void mci_extract_block_lengths_from_csd(struct mci *mci)
 {
-	struct mci *mci = GET_MCI_DATA(mci_dev);
-
 	mci->read_bl_len = 1 << ((mci->csd[1] >> 16) & 0xf);
 
 	if (IS_SD(mci))
@@ -758,11 +748,10 @@ static void mci_extract_block_lengths_from_csd(struct device_d *mci_dev)
 
 /**
  * Extract card's capacitiy from the CSD
- * @param mci_dev MCI instance
+ * @param mci MCI instance
  */
-static void mci_extract_card_capacity_from_csd(struct device_d *mci_dev)
+static void mci_extract_card_capacity_from_csd(struct mci *mci)
 {
-	struct mci *mci = GET_MCI_DATA(mci_dev);
 	uint64_t csize, cmult;
 
 	if (mci->high_capacity) {
@@ -780,13 +769,12 @@ static void mci_extract_card_capacity_from_csd(struct device_d *mci_dev)
 
 /**
  * Scan the given host interfaces and detect connected MMC/SD cards
- * @param mci_dev MCI instance
+ * @param mci MCI instance
  * @return 0 on success, negative value else
  */
-static int mci_startup(struct device_d *mci_dev)
+static int mci_startup(struct mci *mci)
 {
-	struct mci *mci = GET_MCI_DATA(mci_dev);
-	struct mci_host *host = GET_MCI_PDATA(mci_dev);
+	struct mci_host *host = mci->host;
 	struct mci_cmd cmd;
 	int err;
 
@@ -794,7 +782,7 @@ static int mci_startup(struct device_d *mci_dev)
 	if (mmc_host_is_spi(host)) { /* enable CRC check for spi */
 
 		mci_setup_cmd(&cmd, MMC_CMD_SPI_CRC_ON_OFF, 1, MMC_RSP_R1);
-		err = mci_send_cmd(mci_dev, &cmd, NULL);
+		err = mci_send_cmd(mci, &cmd, NULL);
 
 		if (err) {
 			pr_debug("Can't enable CRC check : %d\n", err);
@@ -807,7 +795,7 @@ static int mci_startup(struct device_d *mci_dev)
 
 	/* Put the Card in Identify Mode */
 	mci_setup_cmd(&cmd, mmc_host_is_spi(host) ? MMC_CMD_SEND_CID : MMC_CMD_ALL_SEND_CID, 0, MMC_RSP_R2);
-	err = mci_send_cmd(mci_dev, &cmd, NULL);
+	err = mci_send_cmd(mci, &cmd, NULL);
 	if (err) {
 		pr_debug("Can't bring card into identify mode: %d\n", err);
 		return err;
@@ -826,7 +814,7 @@ static int mci_startup(struct device_d *mci_dev)
 	if (!mmc_host_is_spi(host)) { /* cmd not supported in spi */
 		pr_debug("Get/Set relative address\n");
 		mci_setup_cmd(&cmd, SD_CMD_SEND_RELATIVE_ADDR, mci->rca << 16, MMC_RSP_R6);
-		err = mci_send_cmd(mci_dev, &cmd, NULL);
+		err = mci_send_cmd(mci, &cmd, NULL);
 		if (err) {
 			pr_debug("Get/Set relative address failed: %d\n", err);
 			return err;
@@ -839,7 +827,7 @@ static int mci_startup(struct device_d *mci_dev)
 	pr_debug("Get card's specific data\n");
 	/* Get the Card-Specific Data */
 	mci_setup_cmd(&cmd, MMC_CMD_SEND_CSD, mci->rca << 16, MMC_RSP_R2);
-	err = mci_send_cmd(mci_dev, &cmd, NULL);
+	err = mci_send_cmd(mci, &cmd, NULL);
 	if (err) {
 		pr_debug("Getting card's specific data failed: %d\n", err);
 		return err;
@@ -851,10 +839,10 @@ static int mci_startup(struct device_d *mci_dev)
 	pr_debug("Card's specific data is: %08X-%08X-%08X-%08X\n",
 		mci->csd[0], mci->csd[1], mci->csd[2], mci->csd[3]);
 
-	mci_detect_version_from_csd(mci_dev);
-	mci_extract_max_tran_speed_from_csd(mci_dev);
-	mci_extract_block_lengths_from_csd(mci_dev);
-	mci_extract_card_capacity_from_csd(mci_dev);
+	mci_detect_version_from_csd(mci);
+	mci_extract_max_tran_speed_from_csd(mci);
+	mci_extract_block_lengths_from_csd(mci);
+	mci_extract_card_capacity_from_csd(mci);
 
 	/* sanitiy? */
 	if (mci->read_bl_len > SECTOR_SIZE) {
@@ -875,7 +863,7 @@ static int mci_startup(struct device_d *mci_dev)
 		pr_debug("Select the card, and put it into Transfer Mode\n");
 		/* Select the card, and put it into Transfer Mode */
 		mci_setup_cmd(&cmd, MMC_CMD_SELECT_CARD, mci->rca << 16, MMC_RSP_R1b);
-		err = mci_send_cmd(mci_dev, &cmd, NULL);
+		err = mci_send_cmd(mci, &cmd, NULL);
 		if (err) {
 			pr_debug("Putting in transfer mode failed: %d\n", err);
 			return err;
@@ -883,9 +871,9 @@ static int mci_startup(struct device_d *mci_dev)
 	}
 
 	if (IS_SD(mci))
-		err = sd_change_freq(mci_dev);
+		err = sd_change_freq(mci);
 	else
-		err = mmc_change_freq(mci_dev);
+		err = mmc_change_freq(mci);
 
 	if (err)
 		return err;
@@ -897,7 +885,7 @@ static int mci_startup(struct device_d *mci_dev)
 		if (mci->card_caps & MMC_MODE_4BIT) {
 			pr_debug("Prepare for bus width change\n");
 			mci_setup_cmd(&cmd, MMC_CMD_APP_CMD, mci->rca << 16, MMC_RSP_R1);
-			err = mci_send_cmd(mci_dev, &cmd, NULL);
+			err = mci_send_cmd(mci, &cmd, NULL);
 			if (err) {
 				pr_debug("Preparing SD for bus width change failed: %d\n", err);
 				return err;
@@ -905,60 +893,60 @@ static int mci_startup(struct device_d *mci_dev)
 
 			pr_debug("Set SD bus width to 4 bit\n");
 			mci_setup_cmd(&cmd, SD_CMD_APP_SET_BUS_WIDTH, 2, MMC_RSP_R1);
-			err = mci_send_cmd(mci_dev, &cmd, NULL);
+			err = mci_send_cmd(mci, &cmd, NULL);
 			if (err) {
 				pr_debug("Changing SD bus width failed: %d\n", err);
 				/* TODO continue with 1 bit? */
 				return err;
 			}
-			mci_set_bus_width(mci_dev, MMC_BUS_WIDTH_4);
+			mci_set_bus_width(mci, MMC_BUS_WIDTH_4);
 		}
 		/* if possible, speed up the transfer */
 		if (mci->card_caps & MMC_MODE_HS)
-			mci_set_clock(mci_dev, 50000000);
+			mci_set_clock(mci, 50000000);
 		else
-			mci_set_clock(mci_dev, 25000000);
+			mci_set_clock(mci, 25000000);
 	} else {
 		if (mci->card_caps & MMC_MODE_4BIT) {
 			pr_debug("Set MMC bus width to 4 bit\n");
 			/* Set the card to use 4 bit*/
-			err = mci_switch(mci_dev, EXT_CSD_CMD_SET_NORMAL,
+			err = mci_switch(mci, EXT_CSD_CMD_SET_NORMAL,
 					EXT_CSD_BUS_WIDTH, EXT_CSD_BUS_WIDTH_4);
 			if (err) {
 				pr_debug("Changing MMC bus width failed: %d\n", err);
 				return err;
 			}
-			mci_set_bus_width(mci_dev, MMC_BUS_WIDTH_4);
+			mci_set_bus_width(mci, MMC_BUS_WIDTH_4);
 		} else if (mci->card_caps & MMC_MODE_8BIT) {
 			pr_debug("Set MMC bus width to 8 bit\n");
 			/* Set the card to use 8 bit*/
-			err = mci_switch(mci_dev, EXT_CSD_CMD_SET_NORMAL,
+			err = mci_switch(mci, EXT_CSD_CMD_SET_NORMAL,
 					EXT_CSD_BUS_WIDTH, EXT_CSD_BUS_WIDTH_8);
 			if (err) {
 				pr_debug("Changing MMC bus width failed: %d\n", err);
 				return err;
 			}
-			mci_set_bus_width(mci_dev, MMC_BUS_WIDTH_8);
+			mci_set_bus_width(mci, MMC_BUS_WIDTH_8);
 		}
 		/* if possible, speed up the transfer */
 		if (mci->card_caps & MMC_MODE_HS) {
 			if (mci->card_caps & MMC_MODE_HS_52MHz)
-				mci_set_clock(mci_dev, 52000000);
+				mci_set_clock(mci, 52000000);
 			else
-				mci_set_clock(mci_dev, 26000000);
+				mci_set_clock(mci, 26000000);
 		} else
-			mci_set_clock(mci_dev, 20000000);
+			mci_set_clock(mci, 20000000);
 	}
 
 	/* we setup the blocklength only one times for all accesses to this media  */
-	err = mci_set_blocklen(mci_dev, mci->read_bl_len);
+	err = mci_set_blocklen(mci, mci->read_bl_len);
 
 	return err;
 }
 
 /**
  * Detect a SD 2.0 card and enable its features
- * @param mci_dev MCI instance
+ * @param mci MCI instance
  * @return Transfer status (0 on success)
  *
  * By issuing the CMD8 command SDHC/SDXC cards realize that the host supports
@@ -967,10 +955,9 @@ static int mci_startup(struct device_d *mci_dev)
  *
  * If this CMD8 command will end with a timeout it is a MultiMediaCard only.
  */
-static int sd_send_if_cond(struct device_d *mci_dev)
+static int sd_send_if_cond(struct mci *mci)
 {
-	struct mci *mci = GET_MCI_DATA(mci_dev);
-	struct mci_host *host = GET_MCI_PDATA(mci_dev);
+	struct mci_host *host = mci->host;
 	struct mci_cmd cmd;
 	int err;
 
@@ -978,7 +965,7 @@ static int sd_send_if_cond(struct device_d *mci_dev)
 	/* We set the bit if the host supports voltages between 2.7 and 3.6 V */
 		((host->voltages & 0x00ff8000) != 0) << 8 | 0xaa,
 		MMC_RSP_R7);
-	err = mci_send_cmd(mci_dev, &cmd, NULL);
+	err = mci_send_cmd(mci, &cmd, NULL);
 	if (err) {
 		pr_debug("Query interface conditions failed: %d\n", err);
 		return err;
@@ -1010,8 +997,7 @@ static int sd_send_if_cond(struct device_d *mci_dev)
 static int __maybe_unused mci_sd_write(struct block_device *blk,
 				const void *buffer, int block, int num_blocks)
 {
-	struct device_d *mci_dev = blk->dev;
-	struct mci *mci = GET_MCI_DATA(mci_dev);
+	struct mci *mci = container_of(blk, struct mci, blk);
 	int rc;
 
 	pr_debug("%s: Write %d block(s), starting at %d\n",
@@ -1029,7 +1015,7 @@ static int __maybe_unused mci_sd_write(struct block_device *blk,
 		return -EINVAL;
 	}
 
-	rc = mci_block_write(mci_dev, buffer, block, num_blocks);
+	rc = mci_block_write(mci, buffer, block, num_blocks);
 	if (rc != 0) {
 		pr_debug("Writing block %d failed with %d\n", block, rc);
 		return rc;
@@ -1051,8 +1037,7 @@ static int __maybe_unused mci_sd_write(struct block_device *blk,
 static int mci_sd_read(struct block_device *blk, void *buffer, int block,
 				int num_blocks)
 {
-	struct device_d *mci_dev = blk->dev;
-	struct mci *mci = GET_MCI_DATA(mci_dev);
+	struct mci *mci = container_of(blk, struct mci, blk);
 	int rc;
 
 	pr_debug("%s: Read %d block(s), starting at %d\n",
@@ -1069,7 +1054,7 @@ static int mci_sd_read(struct block_device *blk, void *buffer, int block,
 		return -EINVAL;
 	}
 
-	rc = mci_read_block(mci_dev, buffer, block, num_blocks);
+	rc = mci_read_block(mci, buffer, block, num_blocks);
 	if (rc != 0) {
 		pr_debug("Reading block %d failed with %d\n", block, rc);
 		return rc;
@@ -1150,11 +1135,11 @@ static unsigned extract_mtd_year(struct mci *mci)
 
 /**
  * Output some valuable information when the user runs 'devinfo' on an MCI device
- * @param mci_dev MCI device instance
+ * @param mci MCI device instance
  */
 static void mci_info(struct device_d *mci_dev)
 {
-	struct mci *mci = GET_MCI_DATA(mci_dev);
+	struct mci *mci = mci_dev->priv;
 
 	if (mci->ready_for_use == 0) {
 		printf(" No information available:\n  MCI card not probed yet\n");
@@ -1193,17 +1178,15 @@ static void mci_info(struct device_d *mci_dev)
 
 /**
  * Check if the MCI card is already probed
- * @param mci_dev MCI device instance
+ * @param mci MCI device instance
  * @return 0 when not probed yet, -EPERM if already probed
  *
  * @a barebox cannot really cope with hot plugging. So, probing an attached
  * MCI card is a one time only job. If its already done, there is no way to
  * return.
  */
-static int mci_check_if_already_initialized(struct device_d *mci_dev)
+static int mci_check_if_already_initialized(struct mci *mci)
 {
-	struct mci *mci = GET_MCI_DATA(mci_dev);
-
 	if (mci->ready_for_use != 0)
 		return -EPERM;
 
@@ -1231,45 +1214,44 @@ static struct block_device_ops mci_ops = {
 
 /**
  * Probe an MCI card at the given host interface
- * @param mci_dev MCI device instance
+ * @param mci MCI device instance
  * @return 0 on success, negative values else
  */
-static int mci_card_probe(struct device_d *mci_dev)
+static int mci_card_probe(struct mci *mci)
 {
-	struct mci *mci = GET_MCI_DATA(mci_dev);
-	struct mci_host *host = GET_MCI_PDATA(mci_dev);
+	struct mci_host *host = mci->host;
 	int rc;
 
 	/* start with a host interface reset */
-	rc = (host->init)(host, mci_dev);
+	rc = (host->init)(host, mci->mci_dev);
 	if (rc) {
 		pr_err("Cannot reset the SD/MMC interface\n");
 		return rc;
 	}
 
-	mci_set_bus_width(mci_dev, MMC_BUS_WIDTH_1);
-	mci_set_clock(mci_dev, 1);	/* set the lowest available clock */
+	mci_set_bus_width(mci, MMC_BUS_WIDTH_1);
+	mci_set_clock(mci, 1);	/* set the lowest available clock */
 
 	/* reset the card */
-	rc = mci_go_idle(mci_dev);
+	rc = mci_go_idle(mci);
 	if (rc) {
 		pr_warning("Cannot reset the SD/MMC card\n");
 		goto on_error;
 	}
 
 	/* Check if this card can handle the "SD Card Physical Layer Specification 2.0" */
-	rc = sd_send_if_cond(mci_dev);
-	rc = sd_send_op_cond(mci_dev);
+	rc = sd_send_if_cond(mci);
+	rc = sd_send_op_cond(mci);
 	if (rc && rc == -ETIMEDOUT) {
 		/* If the command timed out, we check for an MMC card */
 		pr_debug("Card seems to be a MultiMediaCard\n");
-		rc = mmc_send_op_cond(mci_dev);
+		rc = mmc_send_op_cond(mci);
 	}
 
 	if (rc)
 		goto on_error;
 
-	rc = mci_startup(mci_dev);
+	rc = mci_startup(mci);
 	if (rc) {
 		pr_debug("Card's startup fails with %d\n", rc);
 		goto on_error;
@@ -1282,7 +1264,7 @@ static int mci_card_probe(struct device_d *mci_dev)
 	 * An MMC/SD card acts like an ordinary disk.
 	 * So, re-use the disk driver to gain access to this media
 	 */
-	mci->blk.dev = mci_dev;
+	mci->blk.dev = mci->mci_dev;
 	mci->blk.ops = &mci_ops;
 
 	rc = cdev_find_free_index("disk");
@@ -1295,14 +1277,14 @@ static int mci_card_probe(struct device_d *mci_dev)
 
 	rc = blockdevice_register(&mci->blk);
 	if (rc != 0) {
-		dev_err(mci_dev, "Failed to register MCI/SD blockdevice\n");
+		dev_err(mci->mci_dev, "Failed to register MCI/SD blockdevice\n");
 		goto on_error;
 	}
 
 	/* create partitions on demand */
 	rc = parse_partition_table(&mci->blk);
 	if (rc != 0) {
-		dev_warn(mci_dev, "No partition table found\n");
+		dev_warn(mci->mci_dev, "No partition table found\n");
 		rc = 0; /* it's not a failure */
 	}
 
@@ -1311,7 +1293,7 @@ static int mci_card_probe(struct device_d *mci_dev)
 on_error:
 	if (rc != 0) {
 		host->clock = 0;	/* disable the MCI clock */
-		mci_set_ios(mci_dev);
+		mci_set_ios(mci);
 	}
 
 	return rc;
@@ -1327,15 +1309,16 @@ on_error:
 static int mci_set_probe(struct device_d *mci_dev, struct param_d *param,
 				const char *val)
 {
+	struct mci *mci = mci_dev->priv;
 	int rc, probe;
 
-	rc = mci_check_if_already_initialized(mci_dev);
+	rc = mci_check_if_already_initialized(mci);
 	if (rc != 0)
 		return rc;
 
 	probe = simple_strtoul(val, NULL, 0);
 	if (probe != 0) {
-		rc = mci_card_probe(mci_dev);
+		rc = mci_card_probe(mci);
 		if (rc != 0)
 			return rc;
 	}
@@ -1377,10 +1360,12 @@ static int mci_probe(struct device_d *mci_dev)
 
 	mci = xzalloc(sizeof(struct mci));
 	mci_dev->priv = mci;
+	mci->mci_dev = mci_dev;
+	mci->host = mci_dev->platform_data;
 
 #ifdef CONFIG_MCI_STARTUP
 	/* if enabled, probe the attached card immediately */
-	rc = mci_card_probe(mci_dev);
+	rc = mci_card_probe(mci);
 	if (rc) {
 		/*
 		 * If it fails, add the 'probe' parameter to give the user
@@ -1439,7 +1424,7 @@ int mci_register(struct mci_host *host)
 
 	mci_dev->id = -1;
 	strcpy(mci_dev->name, mci_driver.name);
-	mci_dev->platform_data = (void*)host;
+	mci_dev->platform_data = host;
 	dev_add_child(host->hw_dev, mci_dev);
 
 	return register_device(mci_dev);
diff --git a/drivers/mci/s3c.c b/drivers/mci/s3c.c
index e7646c9..c905c07 100644
--- a/drivers/mci/s3c.c
+++ b/drivers/mci/s3c.c
@@ -44,6 +44,9 @@
 #include <mach/s3c-generic.h>
 #include <mach/s3c-iomap.h>
 
+#define GET_HOST_DATA(x) (x->priv)
+#define GET_MCI_PDATA(x) (x->platform_data)
+
 #define SDICON 0x0
 # define SDICON_SDRESET (1 << 8)
 # define SDICON_MMCCLOCK (1 << 5) /* this is a clock type SD or MMC style WTF? */
diff --git a/include/mci.h b/include/mci.h
index 9215e39..d8a88da 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -267,7 +267,9 @@ struct mci_host {
 
 /** MMC/SD and interface instance information */
 struct mci {
+	struct mci_host *host;		/**< the host for this card */
 	struct block_device blk;	/**< the blockdevice for the card */
+	struct device_d *mci_dev;	/**< the device for our disk (mcix) */
 	unsigned version;
 	/** != 0 when a high capacity card is connected (OCR -> OCR_HCS) */
 	int high_capacity;
@@ -288,9 +290,4 @@ struct mci {
 
 int mci_register(struct mci_host*);
 
-#define GET_HOST_DATA(x) (x->priv)
-#define GET_HOST_PDATA(x) (x->platform_data)
-#define GET_MCI_DATA(x) (x->priv)
-#define GET_MCI_PDATA(x) (x->platform_data)
-
 #endif /* _MCI_H_ */
-- 
1.7.9


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 12/15] mci: replace pr_debug with dev_dbg
  2012-02-09 11:53 [PATCH] mmc/sd patches Sascha Hauer
                   ` (10 preceding siblings ...)
  2012-02-09 11:53 ` [PATCH 11/15] mci: Use struct mci for internal argument passing Sascha Hauer
@ 2012-02-09 11:53 ` Sascha Hauer
  2012-02-09 11:53 ` [PATCH 13/15] mci: factor out mci/sd specific startup functions Sascha Hauer
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Sascha Hauer @ 2012-02-09 11:53 UTC (permalink / raw)
  To: barebox

The mci layer uses pr_debug throughout. Use dev_dbg instead
which is very useful when multiple cards are involved.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/mci-core.c |  118 ++++++++++++++++++++++++------------------------
 1 files changed, 59 insertions(+), 59 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 49e1c42..799c5cb 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -215,7 +215,7 @@ static int mci_go_idle(struct mci *mci)
 	err = mci_send_cmd(mci, &cmd, NULL);
 
 	if (err) {
-		pr_debug("Activating IDLE state failed: %d\n", err);
+		dev_dbg(mci->mci_dev, "Activating IDLE state failed: %d\n", err);
 		return err;
 	}
 
@@ -251,7 +251,7 @@ static int sd_send_op_cond(struct mci *mci)
 		mci_setup_cmd(&cmd, MMC_CMD_APP_CMD, 0, MMC_RSP_R1);
 		err = mci_send_cmd(mci, &cmd, NULL);
 		if (err) {
-			pr_debug("Preparing SD for operating conditions failed: %d\n", err);
+			dev_dbg(mci->mci_dev, "Preparing SD for operating conditions failed: %d\n", err);
 			return err;
 		}
 
@@ -260,7 +260,7 @@ static int sd_send_op_cond(struct mci *mci)
 			MMC_RSP_R3);
 		err = mci_send_cmd(mci, &cmd, NULL);
 		if (err) {
-			pr_debug("SD operation condition set failed: %d\n", err);
+			dev_dbg(mci->mci_dev, "SD operation condition set failed: %d\n", err);
 			return err;
 		}
 		udelay(1000);
@@ -273,7 +273,7 @@ static int sd_send_op_cond(struct mci *mci)
 	} while (busy && timeout--);
 
 	if (timeout <= 0) {
-		pr_debug("SD operation condition set timed out\n");
+		dev_dbg(mci->mci_dev, "SD operation condition set timed out\n");
 		return -ENODEV;
 	}
 
@@ -316,7 +316,7 @@ static int mmc_send_op_cond(struct mci *mci)
 		err = mci_send_cmd(mci, &cmd, NULL);
 
 		if (err) {
-			pr_debug("Preparing MMC for operating conditions failed: %d\n", err);
+			dev_dbg(mci->mci_dev, "Preparing MMC for operating conditions failed: %d\n", err);
 			return err;
 		}
 
@@ -324,7 +324,7 @@ static int mmc_send_op_cond(struct mci *mci)
 	} while (!(cmd.response[0] & OCR_BUSY) && timeout--);
 
 	if (timeout <= 0) {
-		pr_debug("SD operation condition set timed out\n");
+		dev_dbg(mci->mci_dev, "SD operation condition set timed out\n");
 		return -ENODEV;
 	}
 
@@ -405,7 +405,7 @@ static int mmc_change_freq(struct mci *mci)
 
 	err = mci_send_ext_csd(mci, ext_csd);
 	if (err) {
-		pr_debug("Preparing for frequency setup failed: %d\n", err);
+		dev_dbg(mci->mci_dev, "Preparing for frequency setup failed: %d\n", err);
 		return err;
 	}
 
@@ -414,7 +414,7 @@ static int mmc_change_freq(struct mci *mci)
 	err = mci_switch(mci, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, 1);
 
 	if (err) {
-		pr_debug("MMC frequency changing failed: %d\n", err);
+		dev_dbg(mci->mci_dev, "MMC frequency changing failed: %d\n", err);
 		return err;
 	}
 
@@ -422,7 +422,7 @@ static int mmc_change_freq(struct mci *mci)
 	err = mci_send_ext_csd(mci, ext_csd);
 
 	if (err) {
-		pr_debug("Verifying frequency change failed: %d\n", err);
+		dev_dbg(mci->mci_dev, "Verifying frequency change failed: %d\n", err);
 		return err;
 	}
 
@@ -490,14 +490,14 @@ static int sd_change_freq(struct mci *mci)
 	if (mmc_host_is_spi(host))
 		return 0;
 
-	pr_debug("Changing transfer frequency\n");
+	dev_dbg(mci->mci_dev, "Changing transfer frequency\n");
 	mci->card_caps = 0;
 
 	/* Read the SCR to find out if this card supports higher speeds */
 	mci_setup_cmd(&cmd, MMC_CMD_APP_CMD, mci->rca << 16, MMC_RSP_R1);
 	err = mci_send_cmd(mci, &cmd, NULL);
 	if (err) {
-		pr_debug("Query SD card capabilities failed: %d\n", err);
+		dev_dbg(mci->mci_dev, "Query SD card capabilities failed: %d\n", err);
 		return err;
 	}
 
@@ -506,7 +506,7 @@ static int sd_change_freq(struct mci *mci)
 	timeout = 3;
 
 retry_scr:
-	pr_debug("Trying to read the SCR (try %d of %d)\n", 4 - timeout, 3);
+	dev_dbg(mci->mci_dev, "Trying to read the SCR (try %d of %d)\n", 4 - timeout, 3);
 	data.dest = (char *)scr;
 	data.blocksize = 8;
 	data.blocks = 1;
@@ -514,12 +514,12 @@ retry_scr:
 
 	err = mci_send_cmd(mci, &cmd, &data);
 	if (err) {
-		pr_debug(" Catch error (%d)", err);
+		dev_dbg(mci->mci_dev, " Catch error (%d)", err);
 		if (timeout--) {
-			pr_debug("-- retrying\n");
+			dev_dbg(mci->mci_dev, "-- retrying\n");
 			goto retry_scr;
 		}
-		pr_debug("-- giving up\n");
+		dev_dbg(mci->mci_dev, "-- giving up\n");
 		return err;
 	}
 
@@ -550,7 +550,7 @@ retry_scr:
 		err = sd_switch(mci, SD_SWITCH_CHECK, 0, 1,
 				(uint8_t*)switch_status);
 		if (err) {
-			pr_debug("Checking SD transfer switch frequency feature failed: %d\n", err);
+			dev_dbg(mci->mci_dev, "Checking SD transfer switch frequency feature failed: %d\n", err);
 			return err;
 		}
 
@@ -568,7 +568,7 @@ retry_scr:
 
 	err = sd_switch(mci, SD_SWITCH_SWITCH, 0, 1, (uint8_t*)switch_status);
 	if (err) {
-		pr_debug("Switching SD transfer frequency failed: %d\n", err);
+		dev_dbg(mci->mci_dev, "Switching SD transfer frequency failed: %d\n", err);
 		return err;
 	}
 
@@ -718,13 +718,13 @@ static void mci_extract_max_tran_speed_from_csd(struct mci *mci)
 	unit = tran_speed_unit[(mci->csd[0] & 0x7)];
 	time = tran_speed_time[((mci->csd[0] >> 3) & 0xf)];
 	if ((unit == 0) || (time == 0)) {
-		pr_debug("Unsupported 'TRAN_SPEED' unit/time value."
+		dev_dbg(mci->mci_dev, "Unsupported 'TRAN_SPEED' unit/time value."
 				" Can't calculate card's max. transfer speed\n");
 		return;
 	}
 
 	mci->tran_speed = time * unit;
-	pr_debug("Transfer speed: %u\n", mci->tran_speed);
+	dev_dbg(mci->mci_dev, "Transfer speed: %u\n", mci->tran_speed);
 }
 
 /**
@@ -742,7 +742,7 @@ static void mci_extract_block_lengths_from_csd(struct mci *mci)
 	else
 		mci->write_bl_len = 1 << ((mci->csd[3] >> 22) & 0xf);
 
-	pr_debug("Max. block length are: Write=%u, Read=%u Bytes\n",
+	dev_dbg(mci->mci_dev, "Max. block length are: Write=%u, Read=%u Bytes\n",
 		mci->write_bl_len, mci->read_bl_len);
 }
 
@@ -764,7 +764,7 @@ static void mci_extract_card_capacity_from_csd(struct mci *mci)
 
 	mci->capacity = (csize + 1) << (cmult + 2);
 	mci->capacity *= mci->read_bl_len;
-	pr_debug("Capacity: %u MiB\n", (unsigned)mci->capacity >> 20);
+	dev_dbg(mci->mci_dev, "Capacity: %u MiB\n", (unsigned)mci->capacity >> 20);
 }
 
 /**
@@ -785,25 +785,25 @@ static int mci_startup(struct mci *mci)
 		err = mci_send_cmd(mci, &cmd, NULL);
 
 		if (err) {
-			pr_debug("Can't enable CRC check : %d\n", err);
+			dev_dbg(mci->mci_dev, "Can't enable CRC check : %d\n", err);
 			return err;
 		}
 	}
 #endif
 
-	pr_debug("Put the Card in Identify Mode\n");
+	dev_dbg(mci->mci_dev, "Put the Card in Identify Mode\n");
 
 	/* Put the Card in Identify Mode */
 	mci_setup_cmd(&cmd, mmc_host_is_spi(host) ? MMC_CMD_SEND_CID : MMC_CMD_ALL_SEND_CID, 0, MMC_RSP_R2);
 	err = mci_send_cmd(mci, &cmd, NULL);
 	if (err) {
-		pr_debug("Can't bring card into identify mode: %d\n", err);
+		dev_dbg(mci->mci_dev, "Can't bring card into identify mode: %d\n", err);
 		return err;
 	}
 
 	memcpy(mci->cid, cmd.response, 16);
 
-	pr_debug("Card's identification data is: %08X-%08X-%08X-%08X\n",
+	dev_dbg(mci->mci_dev, "Card's identification data is: %08X-%08X-%08X-%08X\n",
 		mci->cid[0], mci->cid[1], mci->cid[2], mci->cid[3]);
 
 	/*
@@ -812,11 +812,11 @@ static int mci_startup(struct mci *mci)
 	 * This also puts the cards into Standby State
 	 */
 	if (!mmc_host_is_spi(host)) { /* cmd not supported in spi */
-		pr_debug("Get/Set relative address\n");
+		dev_dbg(mci->mci_dev, "Get/Set relative address\n");
 		mci_setup_cmd(&cmd, SD_CMD_SEND_RELATIVE_ADDR, mci->rca << 16, MMC_RSP_R6);
 		err = mci_send_cmd(mci, &cmd, NULL);
 		if (err) {
-			pr_debug("Get/Set relative address failed: %d\n", err);
+			dev_dbg(mci->mci_dev, "Get/Set relative address failed: %d\n", err);
 			return err;
 		}
 	}
@@ -824,19 +824,19 @@ static int mci_startup(struct mci *mci)
 	if (IS_SD(mci))
 		mci->rca = (cmd.response[0] >> 16) & 0xffff;
 
-	pr_debug("Get card's specific data\n");
+	dev_dbg(mci->mci_dev, "Get card's specific data\n");
 	/* Get the Card-Specific Data */
 	mci_setup_cmd(&cmd, MMC_CMD_SEND_CSD, mci->rca << 16, MMC_RSP_R2);
 	err = mci_send_cmd(mci, &cmd, NULL);
 	if (err) {
-		pr_debug("Getting card's specific data failed: %d\n", err);
+		dev_dbg(mci->mci_dev, "Getting card's specific data failed: %d\n", err);
 		return err;
 	}
 
 	/* CSD is of 128 bit */
 	memcpy(mci->csd, cmd.response, 16);
 
-	pr_debug("Card's specific data is: %08X-%08X-%08X-%08X\n",
+	dev_dbg(mci->mci_dev, "Card's specific data is: %08X-%08X-%08X-%08X\n",
 		mci->csd[0], mci->csd[1], mci->csd[2], mci->csd[3]);
 
 	mci_detect_version_from_csd(mci);
@@ -847,25 +847,25 @@ static int mci_startup(struct mci *mci)
 	/* sanitiy? */
 	if (mci->read_bl_len > SECTOR_SIZE) {
 		mci->read_bl_len = SECTOR_SIZE;
-		pr_debug("Limiting max. read block size down to %u\n",
+		dev_dbg(mci->mci_dev, "Limiting max. read block size down to %u\n",
 				mci->read_bl_len);
 	}
 
 	if (mci->write_bl_len > SECTOR_SIZE) {
 		mci->write_bl_len = SECTOR_SIZE;
-		pr_debug("Limiting max. write block size down to %u\n",
+		dev_dbg(mci->mci_dev, "Limiting max. write block size down to %u\n",
 				mci->read_bl_len);
 	}
-	pr_debug("Read block length: %u, Write block length: %u\n",
+	dev_dbg(mci->mci_dev, "Read block length: %u, Write block length: %u\n",
 		mci->read_bl_len, mci->write_bl_len);
 
 	if (!mmc_host_is_spi(host)) { /* cmd not supported in spi */
-		pr_debug("Select the card, and put it into Transfer Mode\n");
+		dev_dbg(mci->mci_dev, "Select the card, and put it into Transfer Mode\n");
 		/* Select the card, and put it into Transfer Mode */
 		mci_setup_cmd(&cmd, MMC_CMD_SELECT_CARD, mci->rca << 16, MMC_RSP_R1b);
 		err = mci_send_cmd(mci, &cmd, NULL);
 		if (err) {
-			pr_debug("Putting in transfer mode failed: %d\n", err);
+			dev_dbg(mci->mci_dev, "Putting in transfer mode failed: %d\n", err);
 			return err;
 		}
 	}
@@ -883,19 +883,19 @@ static int mci_startup(struct mci *mci)
 
 	if (IS_SD(mci)) {
 		if (mci->card_caps & MMC_MODE_4BIT) {
-			pr_debug("Prepare for bus width change\n");
+			dev_dbg(mci->mci_dev, "Prepare for bus width change\n");
 			mci_setup_cmd(&cmd, MMC_CMD_APP_CMD, mci->rca << 16, MMC_RSP_R1);
 			err = mci_send_cmd(mci, &cmd, NULL);
 			if (err) {
-				pr_debug("Preparing SD for bus width change failed: %d\n", err);
+				dev_dbg(mci->mci_dev, "Preparing SD for bus width change failed: %d\n", err);
 				return err;
 			}
 
-			pr_debug("Set SD bus width to 4 bit\n");
+			dev_dbg(mci->mci_dev, "Set SD bus width to 4 bit\n");
 			mci_setup_cmd(&cmd, SD_CMD_APP_SET_BUS_WIDTH, 2, MMC_RSP_R1);
 			err = mci_send_cmd(mci, &cmd, NULL);
 			if (err) {
-				pr_debug("Changing SD bus width failed: %d\n", err);
+				dev_dbg(mci->mci_dev, "Changing SD bus width failed: %d\n", err);
 				/* TODO continue with 1 bit? */
 				return err;
 			}
@@ -908,22 +908,22 @@ static int mci_startup(struct mci *mci)
 			mci_set_clock(mci, 25000000);
 	} else {
 		if (mci->card_caps & MMC_MODE_4BIT) {
-			pr_debug("Set MMC bus width to 4 bit\n");
+			dev_dbg(mci->mci_dev, "Set MMC bus width to 4 bit\n");
 			/* Set the card to use 4 bit*/
 			err = mci_switch(mci, EXT_CSD_CMD_SET_NORMAL,
 					EXT_CSD_BUS_WIDTH, EXT_CSD_BUS_WIDTH_4);
 			if (err) {
-				pr_debug("Changing MMC bus width failed: %d\n", err);
+				dev_dbg(mci->mci_dev, "Changing MMC bus width failed: %d\n", err);
 				return err;
 			}
 			mci_set_bus_width(mci, MMC_BUS_WIDTH_4);
 		} else if (mci->card_caps & MMC_MODE_8BIT) {
-			pr_debug("Set MMC bus width to 8 bit\n");
+			dev_dbg(mci->mci_dev, "Set MMC bus width to 8 bit\n");
 			/* Set the card to use 8 bit*/
 			err = mci_switch(mci, EXT_CSD_CMD_SET_NORMAL,
 					EXT_CSD_BUS_WIDTH, EXT_CSD_BUS_WIDTH_8);
 			if (err) {
-				pr_debug("Changing MMC bus width failed: %d\n", err);
+				dev_dbg(mci->mci_dev, "Changing MMC bus width failed: %d\n", err);
 				return err;
 			}
 			mci_set_bus_width(mci, MMC_BUS_WIDTH_8);
@@ -967,15 +967,15 @@ static int sd_send_if_cond(struct mci *mci)
 		MMC_RSP_R7);
 	err = mci_send_cmd(mci, &cmd, NULL);
 	if (err) {
-		pr_debug("Query interface conditions failed: %d\n", err);
+		dev_dbg(mci->mci_dev, "Query interface conditions failed: %d\n", err);
 		return err;
 	}
 
 	if ((cmd.response[0] & 0xff) != 0xaa) {
-		pr_debug("Card cannot work with hosts supply voltages\n");
+		dev_dbg(mci->mci_dev, "Card cannot work with hosts supply voltages\n");
 		return -EINVAL;
 	} else {
-		pr_debug("SD Card Rev. 2.00 or later detected\n");
+		dev_dbg(mci->mci_dev, "SD Card Rev. 2.00 or later detected\n");
 		mci->version = SD_VERSION_2;
 	}
 
@@ -1000,24 +1000,24 @@ static int __maybe_unused mci_sd_write(struct block_device *blk,
 	struct mci *mci = container_of(blk, struct mci, blk);
 	int rc;
 
-	pr_debug("%s: Write %d block(s), starting at %d\n",
+	dev_dbg(mci->mci_dev, "%s: Write %d block(s), starting at %d\n",
 		__func__, num_blocks, block);
 
 	if (mci->write_bl_len != SECTOR_SIZE) {
-		pr_debug("MMC/SD block size is not %d bytes (its %u bytes instead)\n",
+		dev_dbg(mci->mci_dev, "MMC/SD block size is not %d bytes (its %u bytes instead)\n",
 				SECTOR_SIZE, mci->read_bl_len);
 		return -EINVAL;
 	}
 
 	/* size of the block number field in the MMC/SD command is 32 bit only */
 	if (block > MAX_BUFFER_NUMBER) {
-		pr_debug("Cannot handle block number %d. Too large!\n", block);
+		dev_dbg(mci->mci_dev, "Cannot handle block number %d. Too large!\n", block);
 		return -EINVAL;
 	}
 
 	rc = mci_block_write(mci, buffer, block, num_blocks);
 	if (rc != 0) {
-		pr_debug("Writing block %d failed with %d\n", block, rc);
+		dev_dbg(mci->mci_dev, "Writing block %d failed with %d\n", block, rc);
 		return rc;
 	}
 
@@ -1040,11 +1040,11 @@ static int mci_sd_read(struct block_device *blk, void *buffer, int block,
 	struct mci *mci = container_of(blk, struct mci, blk);
 	int rc;
 
-	pr_debug("%s: Read %d block(s), starting at %d\n",
+	dev_dbg(mci->mci_dev, "%s: Read %d block(s), starting at %d\n",
 		__func__, num_blocks, block);
 
 	if (mci->read_bl_len != 512) {
-		pr_debug("MMC/SD block size is not 512 bytes (its %u bytes instead)\n",
+		dev_dbg(mci->mci_dev, "MMC/SD block size is not 512 bytes (its %u bytes instead)\n",
 				mci->read_bl_len);
 		return -EINVAL;
 	}
@@ -1056,7 +1056,7 @@ static int mci_sd_read(struct block_device *blk, void *buffer, int block,
 
 	rc = mci_read_block(mci, buffer, block, num_blocks);
 	if (rc != 0) {
-		pr_debug("Reading block %d failed with %d\n", block, rc);
+		dev_dbg(mci->mci_dev, "Reading block %d failed with %d\n", block, rc);
 		return rc;
 	}
 
@@ -1244,7 +1244,7 @@ static int mci_card_probe(struct mci *mci)
 	rc = sd_send_op_cond(mci);
 	if (rc && rc == -ETIMEDOUT) {
 		/* If the command timed out, we check for an MMC card */
-		pr_debug("Card seems to be a MultiMediaCard\n");
+		dev_dbg(mci->mci_dev, "Card seems to be a MultiMediaCard\n");
 		rc = mmc_send_op_cond(mci);
 	}
 
@@ -1253,11 +1253,11 @@ static int mci_card_probe(struct mci *mci)
 
 	rc = mci_startup(mci);
 	if (rc) {
-		pr_debug("Card's startup fails with %d\n", rc);
+		dev_dbg(mci->mci_dev, "Card's startup fails with %d\n", rc);
 		goto on_error;
 	}
 
-	pr_debug("Card is up and running now, registering as a disk\n");
+	dev_dbg(mci->mci_dev, "Card is up and running now, registering as a disk\n");
 	mci->ready_for_use = 1;	/* TODO now or later? */
 
 	/*
@@ -1288,7 +1288,7 @@ static int mci_card_probe(struct mci *mci)
 		rc = 0; /* it's not a failure */
 	}
 
-	pr_debug("SD Card successfully added\n");
+	dev_dbg(mci->mci_dev, "SD Card successfully added\n");
 
 on_error:
 	if (rc != 0) {
@@ -1375,7 +1375,7 @@ static int mci_probe(struct device_d *mci_dev)
 		 */
 		rc = add_mci_parameter(mci_dev);
 		if (rc != 0) {
-			pr_debug("Failed to add 'probe' parameter to the MCI device\n");
+			dev_dbg(mci->mci_dev, "Failed to add 'probe' parameter to the MCI device\n");
 			goto on_error;
 		}
 	}
@@ -1385,7 +1385,7 @@ static int mci_probe(struct device_d *mci_dev)
 	/* add params on demand */
 	rc = add_mci_parameter(mci_dev);
 	if (rc != 0) {
-		pr_debug("Failed to add 'probe' parameter to the MCI device\n");
+		dev_dbg(mci->mci_dev, "Failed to add 'probe' parameter to the MCI device\n");
 		goto on_error;
 	}
 #endif
-- 
1.7.9


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 13/15] mci: factor out mci/sd specific startup functions
  2012-02-09 11:53 [PATCH] mmc/sd patches Sascha Hauer
                   ` (11 preceding siblings ...)
  2012-02-09 11:53 ` [PATCH 12/15] mci: replace pr_debug with dev_dbg Sascha Hauer
@ 2012-02-09 11:53 ` Sascha Hauer
  2012-02-09 11:53 ` [PATCH 14/15] mci: cdev_find_free_index won't fail, no need to check Sascha Hauer
  2012-02-09 11:53 ` [PATCH 15/15] mci: Be more verbose on what device is associated to which disk Sascha Hauer
  14 siblings, 0 replies; 17+ messages in thread
From: Sascha Hauer @ 2012-02-09 11:53 UTC (permalink / raw)
  To: barebox

This saves an indention level and makes the code more readable.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/mci-core.c |  133 ++++++++++++++++++++++++++++--------------------
 1 files changed, 77 insertions(+), 56 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 799c5cb..9c9ed48 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -767,6 +767,76 @@ static void mci_extract_card_capacity_from_csd(struct mci *mci)
 	dev_dbg(mci->mci_dev, "Capacity: %u MiB\n", (unsigned)mci->capacity >> 20);
 }
 
+static int mci_startup_sd(struct mci *mci)
+{
+	struct mci_cmd cmd;
+	int err;
+
+	if (mci->card_caps & MMC_MODE_4BIT) {
+		dev_dbg(mci->mci_dev, "Prepare for bus width change\n");
+		mci_setup_cmd(&cmd, MMC_CMD_APP_CMD, mci->rca << 16, MMC_RSP_R1);
+		err = mci_send_cmd(mci, &cmd, NULL);
+		if (err) {
+			dev_dbg(mci->mci_dev, "Preparing SD for bus width change failed: %d\n", err);
+			return err;
+		}
+
+		dev_dbg(mci->mci_dev, "Set SD bus width to 4 bit\n");
+		mci_setup_cmd(&cmd, SD_CMD_APP_SET_BUS_WIDTH, 2, MMC_RSP_R1);
+		err = mci_send_cmd(mci, &cmd, NULL);
+		if (err) {
+			dev_dbg(mci->mci_dev, "Changing SD bus width failed: %d\n", err);
+			/* TODO continue with 1 bit? */
+			return err;
+		}
+		mci_set_bus_width(mci, MMC_BUS_WIDTH_4);
+	}
+	/* if possible, speed up the transfer */
+	if (mci->card_caps & MMC_MODE_HS)
+		mci_set_clock(mci, 50000000);
+	else
+		mci_set_clock(mci, 25000000);
+
+	return 0;
+}
+
+static int mci_startup_mmc(struct mci *mci)
+{
+	int err;
+
+	if (mci->card_caps & MMC_MODE_4BIT) {
+		dev_dbg(mci->mci_dev, "Set MMC bus width to 4 bit\n");
+		/* Set the card to use 4 bit*/
+		err = mci_switch(mci, EXT_CSD_CMD_SET_NORMAL,
+				EXT_CSD_BUS_WIDTH, EXT_CSD_BUS_WIDTH_4);
+		if (err) {
+			dev_dbg(mci->mci_dev, "Changing MMC bus width failed: %d\n", err);
+			return err;
+		}
+		mci_set_bus_width(mci, MMC_BUS_WIDTH_4);
+	} else if (mci->card_caps & MMC_MODE_8BIT) {
+		dev_dbg(mci->mci_dev, "Set MMC bus width to 8 bit\n");
+		/* Set the card to use 8 bit*/
+		err = mci_switch(mci, EXT_CSD_CMD_SET_NORMAL,
+				EXT_CSD_BUS_WIDTH, EXT_CSD_BUS_WIDTH_8);
+		if (err) {
+			dev_dbg(mci->mci_dev, "Changing MMC bus width failed: %d\n", err);
+			return err;
+		}
+		mci_set_bus_width(mci, MMC_BUS_WIDTH_8);
+	}
+	/* if possible, speed up the transfer */
+	if (mci->card_caps & MMC_MODE_HS) {
+		if (mci->card_caps & MMC_MODE_HS_52MHz)
+			mci_set_clock(mci, 52000000);
+		else
+			mci_set_clock(mci, 26000000);
+	} else
+		mci_set_clock(mci, 20000000);
+
+	return 0;
+}
+
 /**
  * Scan the given host interfaces and detect connected MMC/SD cards
  * @param mci MCI instance
@@ -881,62 +951,13 @@ static int mci_startup(struct mci *mci)
 	/* Restrict card's capabilities by what the host can do */
 	mci->card_caps &= host->host_caps;
 
-	if (IS_SD(mci)) {
-		if (mci->card_caps & MMC_MODE_4BIT) {
-			dev_dbg(mci->mci_dev, "Prepare for bus width change\n");
-			mci_setup_cmd(&cmd, MMC_CMD_APP_CMD, mci->rca << 16, MMC_RSP_R1);
-			err = mci_send_cmd(mci, &cmd, NULL);
-			if (err) {
-				dev_dbg(mci->mci_dev, "Preparing SD for bus width change failed: %d\n", err);
-				return err;
-			}
-
-			dev_dbg(mci->mci_dev, "Set SD bus width to 4 bit\n");
-			mci_setup_cmd(&cmd, SD_CMD_APP_SET_BUS_WIDTH, 2, MMC_RSP_R1);
-			err = mci_send_cmd(mci, &cmd, NULL);
-			if (err) {
-				dev_dbg(mci->mci_dev, "Changing SD bus width failed: %d\n", err);
-				/* TODO continue with 1 bit? */
-				return err;
-			}
-			mci_set_bus_width(mci, MMC_BUS_WIDTH_4);
-		}
-		/* if possible, speed up the transfer */
-		if (mci->card_caps & MMC_MODE_HS)
-			mci_set_clock(mci, 50000000);
-		else
-			mci_set_clock(mci, 25000000);
-	} else {
-		if (mci->card_caps & MMC_MODE_4BIT) {
-			dev_dbg(mci->mci_dev, "Set MMC bus width to 4 bit\n");
-			/* Set the card to use 4 bit*/
-			err = mci_switch(mci, EXT_CSD_CMD_SET_NORMAL,
-					EXT_CSD_BUS_WIDTH, EXT_CSD_BUS_WIDTH_4);
-			if (err) {
-				dev_dbg(mci->mci_dev, "Changing MMC bus width failed: %d\n", err);
-				return err;
-			}
-			mci_set_bus_width(mci, MMC_BUS_WIDTH_4);
-		} else if (mci->card_caps & MMC_MODE_8BIT) {
-			dev_dbg(mci->mci_dev, "Set MMC bus width to 8 bit\n");
-			/* Set the card to use 8 bit*/
-			err = mci_switch(mci, EXT_CSD_CMD_SET_NORMAL,
-					EXT_CSD_BUS_WIDTH, EXT_CSD_BUS_WIDTH_8);
-			if (err) {
-				dev_dbg(mci->mci_dev, "Changing MMC bus width failed: %d\n", err);
-				return err;
-			}
-			mci_set_bus_width(mci, MMC_BUS_WIDTH_8);
-		}
-		/* if possible, speed up the transfer */
-		if (mci->card_caps & MMC_MODE_HS) {
-			if (mci->card_caps & MMC_MODE_HS_52MHz)
-				mci_set_clock(mci, 52000000);
-			else
-				mci_set_clock(mci, 26000000);
-		} else
-			mci_set_clock(mci, 20000000);
-	}
+	if (IS_SD(mci))
+		err = mci_startup_sd(mci);
+	else
+		err = mci_startup_mmc(mci);
+
+	if (err)
+		return err;
 
 	/* we setup the blocklength only one times for all accesses to this media  */
 	err = mci_set_blocklen(mci, mci->read_bl_len);
-- 
1.7.9


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 14/15] mci: cdev_find_free_index won't fail, no need to check
  2012-02-09 11:53 [PATCH] mmc/sd patches Sascha Hauer
                   ` (12 preceding siblings ...)
  2012-02-09 11:53 ` [PATCH 13/15] mci: factor out mci/sd specific startup functions Sascha Hauer
@ 2012-02-09 11:53 ` Sascha Hauer
  2012-02-09 11:53 ` [PATCH 15/15] mci: Be more verbose on what device is associated to which disk Sascha Hauer
  14 siblings, 0 replies; 17+ messages in thread
From: Sascha Hauer @ 2012-02-09 11:53 UTC (permalink / raw)
  To: barebox

There will always be the next integer number unless we register
INT_MAX disk devices which is rarely the case.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/mci-core.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 9c9ed48..c39faf3 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -1289,8 +1289,6 @@ static int mci_card_probe(struct mci *mci)
 	mci->blk.ops = &mci_ops;
 
 	rc = cdev_find_free_index("disk");
-	if (rc == -1)
-		pr_err("Cannot find a free number for the disk node\n");
 
 	mci->blk.cdev.name = asprintf("disk%d", rc);
 	mci->blk.blockbits = SECTOR_SHIFT;
-- 
1.7.9


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 15/15] mci: Be more verbose on what device is associated to which disk
  2012-02-09 11:53 [PATCH] mmc/sd patches Sascha Hauer
                   ` (13 preceding siblings ...)
  2012-02-09 11:53 ` [PATCH 14/15] mci: cdev_find_free_index won't fail, no need to check Sascha Hauer
@ 2012-02-09 11:53 ` Sascha Hauer
  2012-02-09 13:32   ` Sascha Hauer
  14 siblings, 1 reply; 17+ messages in thread
From: Sascha Hauer @ 2012-02-09 11:53 UTC (permalink / raw)
  To: barebox

This is quite useful when multiple SD cards are present so spare
some bytes to print this information.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/mci-core.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index c39faf3..17a6656 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -1300,6 +1300,8 @@ static int mci_card_probe(struct mci *mci)
 		goto on_error;
 	}
 
+	dev_info(mci->mci_dev, "registered disk%d\n", rc);
+
 	/* create partitions on demand */
 	rc = parse_partition_table(&mci->blk);
 	if (rc != 0) {
@@ -1382,6 +1384,8 @@ static int mci_probe(struct device_d *mci_dev)
 	mci->mci_dev = mci_dev;
 	mci->host = mci_dev->platform_data;
 
+	dev_info(mci->host->hw_dev, "registered as %s\n", dev_name(mci_dev));
+
 #ifdef CONFIG_MCI_STARTUP
 	/* if enabled, probe the attached card immediately */
 	rc = mci_card_probe(mci);
-- 
1.7.9


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 15/15] mci: Be more verbose on what device is associated to which disk
  2012-02-09 11:53 ` [PATCH 15/15] mci: Be more verbose on what device is associated to which disk Sascha Hauer
@ 2012-02-09 13:32   ` Sascha Hauer
  0 siblings, 0 replies; 17+ messages in thread
From: Sascha Hauer @ 2012-02-09 13:32 UTC (permalink / raw)
  To: barebox

On Thu, Feb 09, 2012 at 12:53:58PM +0100, Sascha Hauer wrote:
> This is quite useful when multiple SD cards are present so spare
> some bytes to print this information.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  drivers/mci/mci-core.c |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
> index c39faf3..17a6656 100644
> --- a/drivers/mci/mci-core.c
> +++ b/drivers/mci/mci-core.c
> @@ -1300,6 +1300,8 @@ static int mci_card_probe(struct mci *mci)
>  		goto on_error;
>  	}
>  
> +	dev_info(mci->mci_dev, "registered disk%d\n", rc);


This doesn't work. With this we will print the return value of
blockdevice_register().

Here is an updated patch.

Sascha

8<------------------------------------

mci: Be more verbose on what device is associated to which  disk

This is quite useful when multiple SD cards are present so spare
some bytes to print this information.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/mci-core.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index c39faf3..c6e8669 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -1241,7 +1241,7 @@ static struct block_device_ops mci_ops = {
 static int mci_card_probe(struct mci *mci)
 {
 	struct mci_host *host = mci->host;
-	int rc;
+	int rc, disknum;
 
 	/* start with a host interface reset */
 	rc = (host->init)(host, mci->mci_dev);
@@ -1288,9 +1288,9 @@ static int mci_card_probe(struct mci *mci)
 	mci->blk.dev = mci->mci_dev;
 	mci->blk.ops = &mci_ops;
 
-	rc = cdev_find_free_index("disk");
+	disknum = cdev_find_free_index("disk");
 
-	mci->blk.cdev.name = asprintf("disk%d", rc);
+	mci->blk.cdev.name = asprintf("disk%d", disknum);
 	mci->blk.blockbits = SECTOR_SHIFT;
 	mci->blk.num_blocks = mci_calc_blk_cnt(mci->capacity, mci->blk.blockbits);
 
@@ -1300,6 +1300,8 @@ static int mci_card_probe(struct mci *mci)
 		goto on_error;
 	}
 
+	dev_info(mci->mci_dev, "registered disk%d\n", disknum);
+
 	/* create partitions on demand */
 	rc = parse_partition_table(&mci->blk);
 	if (rc != 0) {
@@ -1382,6 +1384,8 @@ static int mci_probe(struct device_d *mci_dev)
 	mci->mci_dev = mci_dev;
 	mci->host = mci_dev->platform_data;
 
+	dev_info(mci->host->hw_dev, "registered as %s\n", dev_name(mci_dev));
+
 #ifdef CONFIG_MCI_STARTUP
 	/* if enabled, probe the attached card immediately */
 	rc = mci_card_probe(mci);
-- 
1.7.9

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2012-02-09 13:32 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-09 11:53 [PATCH] mmc/sd patches Sascha Hauer
2012-02-09 11:53 ` [PATCH 01/15] mci: Add complete definitions for the card type Sascha Hauer
2012-02-09 11:53 ` [PATCH 02/15] mci: use card type definitions Sascha Hauer
2012-02-09 11:53 ` [PATCH 03/15] mci: fix high capacity detection Sascha Hauer
2012-02-09 11:53 ` [PATCH 04/15] mci mxs: do not use external define for internal use Sascha Hauer
2012-02-09 11:53 ` [PATCH 05/15] mci core: replace discrete ios values with struct ios Sascha Hauer
2012-02-09 11:53 ` [PATCH 06/15] mci s3c: Do not mess with struct mci_host Sascha Hauer
2012-02-09 11:53 ` [PATCH 07/15] mci s3c: allocate host struct dynamically Sascha Hauer
2012-02-09 11:53 ` [PATCH 08/15] mci s3c: pass around the right pointer Sascha Hauer
2012-02-09 11:53 ` [PATCH 09/15] mci: remove unused device argument from set_ios Sascha Hauer
2012-02-09 11:53 ` [PATCH 10/15] mci core: fix mixup of max write/read block len Sascha Hauer
2012-02-09 11:53 ` [PATCH 11/15] mci: Use struct mci for internal argument passing Sascha Hauer
2012-02-09 11:53 ` [PATCH 12/15] mci: replace pr_debug with dev_dbg Sascha Hauer
2012-02-09 11:53 ` [PATCH 13/15] mci: factor out mci/sd specific startup functions Sascha Hauer
2012-02-09 11:53 ` [PATCH 14/15] mci: cdev_find_free_index won't fail, no need to check Sascha Hauer
2012-02-09 11:53 ` [PATCH 15/15] mci: Be more verbose on what device is associated to which disk Sascha Hauer
2012-02-09 13:32   ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox