All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v4 10/17] dm: mmc: rpi: Convert Raspberry Pi to driver model for MMC
Date: Fri, 20 Jan 2017 07:07:45 -0700	[thread overview]
Message-ID: <20170120140752.16296-11-sjg@chromium.org> (raw)
In-Reply-To: <20170120140752.16296-1-sjg@chromium.org>

Convert the bcm2835 SDHCI driver over to support CONFIG_DM_MMC and move
all boards over. There is no need to keep the old code since there are no
other users.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v4: None
Changes in v3: None

 board/raspberrypi/rpi/rpi.c | 13 --------
 configs/rpi_2_defconfig     |  1 +
 configs/rpi_3_32b_defconfig |  1 +
 configs/rpi_3_defconfig     |  1 +
 configs/rpi_defconfig       |  1 +
 drivers/mmc/bcm2835_sdhci.c | 81 ++++++++++++++++++++++++++++++++++++---------
 6 files changed, 69 insertions(+), 29 deletions(-)

diff --git a/board/raspberrypi/rpi/rpi.c b/board/raspberrypi/rpi/rpi.c
index dd318df72b2..3d44cd4e55d 100644
--- a/board/raspberrypi/rpi/rpi.c
+++ b/board/raspberrypi/rpi/rpi.c
@@ -454,19 +454,6 @@ int board_init(void)
 	return bcm2835_power_on_module(BCM2835_MBOX_POWER_DEVID_USB_HCD);
 }
 
-int board_mmc_init(bd_t *bis)
-{
-	int ret;
-
-	bcm2835_power_on_module(BCM2835_MBOX_POWER_DEVID_SDHCI);
-
-	ret = bcm2835_get_mmc_clock();
-	if (ret)
-		return ret;
-
-	return bcm2835_sdhci_init(BCM2835_SDHCI_BASE, ret);
-}
-
 int ft_board_setup(void *blob, bd_t *bd)
 {
 	/*
diff --git a/configs/rpi_2_defconfig b/configs/rpi_2_defconfig
index 090a0b07140..3d6f2a33377 100644
--- a/configs/rpi_2_defconfig
+++ b/configs/rpi_2_defconfig
@@ -14,6 +14,7 @@ CONFIG_CMD_USB=y
 # CONFIG_CMD_FPGA is not set
 CONFIG_CMD_GPIO=y
 CONFIG_OF_EMBED=y
+CONFIG_DM_MMC=y
 CONFIG_MMC_SDHCI=y
 CONFIG_MMC_SDHCI_BCM2835=y
 CONFIG_DM_ETH=y
diff --git a/configs/rpi_3_32b_defconfig b/configs/rpi_3_32b_defconfig
index 785bf21e9a3..ca0ef7afe74 100644
--- a/configs/rpi_3_32b_defconfig
+++ b/configs/rpi_3_32b_defconfig
@@ -15,6 +15,7 @@ CONFIG_CMD_USB=y
 # CONFIG_CMD_FPGA is not set
 CONFIG_CMD_GPIO=y
 CONFIG_OF_EMBED=y
+CONFIG_DM_MMC=y
 CONFIG_MMC_SDHCI=y
 CONFIG_MMC_SDHCI_BCM2835=y
 CONFIG_DM_ETH=y
diff --git a/configs/rpi_3_defconfig b/configs/rpi_3_defconfig
index 5ff8ed1cf2b..185a56c2807 100644
--- a/configs/rpi_3_defconfig
+++ b/configs/rpi_3_defconfig
@@ -15,6 +15,7 @@ CONFIG_CMD_USB=y
 # CONFIG_CMD_FPGA is not set
 CONFIG_CMD_GPIO=y
 CONFIG_OF_EMBED=y
+CONFIG_DM_MMC=y
 CONFIG_MMC_SDHCI=y
 CONFIG_MMC_SDHCI_BCM2835=y
 CONFIG_DM_ETH=y
diff --git a/configs/rpi_defconfig b/configs/rpi_defconfig
index 5d44f297267..89ecef8994e 100644
--- a/configs/rpi_defconfig
+++ b/configs/rpi_defconfig
@@ -14,6 +14,7 @@ CONFIG_CMD_USB=y
 # CONFIG_CMD_FPGA is not set
 CONFIG_CMD_GPIO=y
 CONFIG_OF_EMBED=y
+CONFIG_DM_MMC=y
 CONFIG_MMC_SDHCI=y
 CONFIG_MMC_SDHCI_BCM2835=y
 CONFIG_DM_ETH=y
diff --git a/drivers/mmc/bcm2835_sdhci.c b/drivers/mmc/bcm2835_sdhci.c
index cb2bd40c65e..c96c35a9da4 100644
--- a/drivers/mmc/bcm2835_sdhci.c
+++ b/drivers/mmc/bcm2835_sdhci.c
@@ -37,14 +37,23 @@
  */
 
 #include <common.h>
+#include <dm.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <sdhci.h>
-#include <mach/timer.h>
+#include <asm/arch/msg.h>
+#include <asm/arch/mbox.h>
 #include <mach/sdhci.h>
+#include <mach/timer.h>
 
 /* 400KHz is max freq for card ID etc. Use that as min */
 #define MIN_FREQ 400000
 
+struct bcm2835_sdhci_plat {
+	struct mmc_config cfg;
+	struct mmc mmc;
+};
+
 struct bcm2835_sdhci_host {
 	struct sdhci_host host;
 	uint twoticks_delay;
@@ -57,7 +66,7 @@ static inline struct bcm2835_sdhci_host *to_bcm(struct sdhci_host *host)
 }
 
 static inline void bcm2835_sdhci_raw_writel(struct sdhci_host *host, u32 val,
-						int reg)
+					    int reg)
 {
 	struct bcm2835_sdhci_host *bcm_host = to_bcm(host);
 
@@ -149,16 +158,33 @@ static const struct sdhci_ops bcm2835_ops = {
 	.read_b = bcm2835_sdhci_readb,
 };
 
-int bcm2835_sdhci_init(u32 regbase, u32 emmc_freq)
+static int bcm2835_sdhci_bind(struct udevice *dev)
 {
-	struct bcm2835_sdhci_host *bcm_host;
-	struct sdhci_host *host;
+	struct bcm2835_sdhci_plat *plat = dev_get_platdata(dev);
 
-	bcm_host = calloc(1, sizeof(*bcm_host));
-	if (!bcm_host) {
-		printf("sdhci_host calloc fail!\n");
-		return -ENOMEM;
+	return sdhci_bind(dev, &plat->mmc, &plat->cfg);
+}
+
+static int bcm2835_sdhci_probe(struct udevice *dev)
+{
+	struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+	struct bcm2835_sdhci_plat *plat = dev_get_platdata(dev);
+	struct bcm2835_sdhci_host *priv = dev_get_priv(dev);
+	struct sdhci_host *host = &priv->host;
+	fdt_addr_t base;
+	int emmc_freq;
+	int ret;
+
+	base = dev_get_addr(dev);
+	if (base == FDT_ADDR_T_NONE)
+		return -EINVAL;
+
+	ret = bcm2835_get_mmc_clock();
+	if (ret < 0) {
+		debug("%s: Failed to set MMC clock (err=%d)\n", __func__, ret);
+		return ret;
 	}
+	emmc_freq = ret;
 
 	/*
 	 * See the comments in bcm2835_sdhci_raw_writel().
@@ -173,18 +199,41 @@ int bcm2835_sdhci_init(u32 regbase, u32 emmc_freq)
 	 * Multiply by 1000000 to get uS per two ticks.
 	 * +1 for hack rounding.
 	 */
-	bcm_host->twoticks_delay = ((2 * 1000000) / MIN_FREQ) + 1;
-	bcm_host->last_write = 0;
+	priv->twoticks_delay = ((2 * 1000000) / MIN_FREQ) + 1;
+	priv->last_write = 0;
 
-	host = &bcm_host->host;
-	host->name = "bcm2835_sdhci";
-	host->ioaddr = (void *)(unsigned long)regbase;
+	host->name = dev->name;
+	host->ioaddr = (void *)base;
 	host->quirks = SDHCI_QUIRK_BROKEN_VOLTAGE | SDHCI_QUIRK_BROKEN_R1B |
 		SDHCI_QUIRK_WAIT_SEND_CMD | SDHCI_QUIRK_NO_HISPD_BIT;
 	host->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195;
 	host->ops = &bcm2835_ops;
 
-	add_sdhci(host, emmc_freq, MIN_FREQ);
+	ret = sdhci_setup_cfg(&plat->cfg, host, emmc_freq, MIN_FREQ);
+	if (ret) {
+		debug("%s: Failed to setup SDHCI (err=%d)\n", __func__, ret);
+		return ret;
+	}
+
+	upriv->mmc = &plat->mmc;
+	host->mmc = &plat->mmc;
+	host->mmc->priv = host;
 
-	return 0;
+	return sdhci_probe(dev);
 }
+
+static const struct udevice_id bcm2835_sdhci_match[] = {
+	{ .compatible = "brcm,bcm2835-sdhci" },
+	{ /* sentinel */ }
+};
+
+U_BOOT_DRIVER(sdhci_cdns) = {
+	.name = "sdhci-bcm2835",
+	.id = UCLASS_MMC,
+	.of_match = bcm2835_sdhci_match,
+	.bind = bcm2835_sdhci_bind,
+	.probe = bcm2835_sdhci_probe,
+	.priv_auto_alloc_size = sizeof(struct bcm2835_sdhci_host),
+	.platdata_auto_alloc_size = sizeof(struct bcm2835_sdhci_plat),
+	.ops = &sdhci_ops,
+};
-- 
2.11.0.483.g087da7b7c-goog

  parent reply	other threads:[~2017-01-20 14:07 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-20 14:07 [U-Boot] [PATCH v4 00/17] arm: rpi: Enable USB, Ethernet, MMC, Video driver model on Raspberry Pi Simon Glass
2017-01-20 14:07 ` [U-Boot] [PATCH v4 01/17] dm: mmc: Set up the MMC device when controller is probed Simon Glass
2017-01-24  6:21   ` Jaehoon Chung
2017-01-20 14:07 ` [U-Boot] [PATCH v4 02/17] dm: video: Correct line clearing code Simon Glass
2017-01-24 14:55   ` Anatolij Gustschin
2017-01-20 14:07 ` [U-Boot] [PATCH v4 03/17] string: Use memcpy() within memmove() when we can Simon Glass
2017-01-23 18:13   ` Tom Rini
2017-01-20 14:07 ` [U-Boot] [PATCH v4 04/17] arm: rpi: Drop the GPIO device addresses Simon Glass
2017-01-20 14:07 ` [U-Boot] [PATCH v4 05/17] arm: rpi: Drop CONFIG_CONS_INDEX Simon Glass
2017-01-20 14:07 ` [U-Boot] [PATCH v4 06/17] dm: arm: rpi: Move to driver model for USB Simon Glass
2017-01-20 14:07 ` [U-Boot] [PATCH v4 07/17] dm: arm: rpi: Use driver model for Ethernet Simon Glass
2017-01-20 14:07 ` [U-Boot] [PATCH v4 08/17] arm: rpi: Add a file to handle messages Simon Glass
2017-01-20 14:07 ` [U-Boot] [PATCH v4 09/17] arm: rpi: Add a function to obtain the MMC clock Simon Glass
2017-01-20 14:07 ` Simon Glass [this message]
2017-01-24  6:51   ` [U-Boot] [PATCH v4 10/17] dm: mmc: rpi: Convert Raspberry Pi to driver model for MMC Jaehoon Chung
2017-01-20 14:07 ` [U-Boot] [PATCH v4 11/17] dm: arm: rpi: Drop CONFIG_OF_EMBED Simon Glass
2017-01-20 14:07 ` [U-Boot] [PATCH v4 12/17] video: arm: rpi: Move the video query out of the driver Simon Glass
2017-01-24 14:51   ` Anatolij Gustschin
2017-01-20 14:07 ` [U-Boot] [PATCH v4 13/17] video: arm: rpi: Move the video settings " Simon Glass
2017-01-24 14:52   ` Anatolij Gustschin
2017-01-20 14:07 ` [U-Boot] [PATCH v4 14/17] dm: video: Refactor lcd_simplefb to prepare for driver model Simon Glass
2017-01-24 14:20   ` Anatolij Gustschin
2017-01-20 14:07 ` [U-Boot] [PATCH v4 15/17] dm: video: Add driver-model support to lcd_simplefb Simon Glass
2017-01-24 14:23   ` Anatolij Gustschin
2017-01-20 14:07 ` [U-Boot] [PATCH v4 16/17] dm: video: arm: rpi: Convert to use driver model for video Simon Glass
2017-01-24 14:29   ` Anatolij Gustschin
2017-01-20 14:07 ` [U-Boot] [PATCH v4 17/17] arm: rpi: Add a TODO to move all messages into the msg handler Simon Glass
2017-01-23 18:22 ` [U-Boot] [PATCH v4 00/17] arm: rpi: Enable USB, Ethernet, MMC, Video driver model on Raspberry Pi Tom Rini
2017-02-06 15:32   ` Simon Glass
2017-04-01  4:19     ` Simon Glass
2017-04-01  4:34       ` Simon Glass
2017-04-05 13:41         ` Tom Rini
2017-04-05 22:25           ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170120140752.16296-11-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.