Re: [U-Boot] [PATCH 16/27] dm: mmc: sdhci: Support CONFIG_BLK and CONFIG_DM_MMC_OPS

2016-07-03 Thread Simon Glass
On 12 June 2016 at 23:30, Simon Glass  wrote:
> Add support for using driver model for block devices and MMC operations in
> this driver.
>
> Signed-off-by: Simon Glass 
> ---
>
>  drivers/mmc/sdhci.c | 40 ++-
>  include/sdhci.h | 80 
> +
>  2 files changed, 119 insertions(+), 1 deletion(-)

Applied to u-boot-dm/next.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 16/27] dm: mmc: sdhci: Support CONFIG_BLK and CONFIG_DM_MMC_OPS

2016-06-12 Thread Simon Glass
Add support for using driver model for block devices and MMC operations in
this driver.

Signed-off-by: Simon Glass 
---

 drivers/mmc/sdhci.c | 40 ++-
 include/sdhci.h | 80 +
 2 files changed, 119 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c
index 6e786c8..7d43f71 100644
--- a/drivers/mmc/sdhci.c
+++ b/drivers/mmc/sdhci.c
@@ -129,9 +129,17 @@ static int sdhci_transfer_data(struct sdhci_host *host, 
struct mmc_data *data,
 #endif
 #define CONFIG_SDHCI_CMD_DEFAULT_TIMEOUT   100
 
+#ifdef CONFIG_DM_MMC_OPS
+static int sdhci_send_command(struct udevice *dev, struct mmc_cmd *cmd,
+ struct mmc_data *data)
+{
+   struct mmc *mmc = mmc_get_mmc_dev(dev);
+
+#else
 static int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd,
-  struct mmc_data *data)
+ struct mmc_data *data)
 {
+#endif
struct sdhci_host *host = mmc->priv;
unsigned int stat = 0;
int ret = 0;
@@ -389,8 +397,14 @@ static void sdhci_set_power(struct sdhci_host *host, 
unsigned short power)
sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
 }
 
+#ifdef CONFIG_DM_MMC_OPS
+static int sdhci_set_ios(struct udevice *dev)
+{
+   struct mmc *mmc = mmc_get_mmc_dev(dev);
+#else
 static void sdhci_set_ios(struct mmc *mmc)
 {
+#endif
u32 ctrl;
struct sdhci_host *host = mmc->priv;
 
@@ -426,6 +440,9 @@ static void sdhci_set_ios(struct mmc *mmc)
ctrl &= ~SDHCI_CTRL_HISPD;
 
sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
+#ifdef CONFIG_DM_MMC_OPS
+   return 0;
+#endif
 }
 
 static int sdhci_init(struct mmc *mmc)
@@ -472,12 +489,25 @@ static int sdhci_init(struct mmc *mmc)
return 0;
 }
 
+#ifdef CONFIG_DM_MMC_OPS
+int sdhci_probe(struct udevice *dev)
+{
+   struct mmc *mmc = mmc_get_mmc_dev(dev);
+
+   return sdhci_init(mmc);
+}
 
+const struct dm_mmc_ops sdhci_ops = {
+   .send_cmd   = sdhci_send_command,
+   .set_ios= sdhci_set_ios,
+};
+#else
 static const struct mmc_ops sdhci_ops = {
.send_cmd   = sdhci_send_command,
.set_ios= sdhci_set_ios,
.init   = sdhci_init,
 };
+#endif
 
 int sdhci_setup_cfg(struct mmc_config *cfg, const char *name, int buswidth,
uint caps, u32 max_clk, u32 min_clk, uint version,
@@ -528,11 +558,18 @@ int sdhci_setup_cfg(struct mmc_config *cfg, const char 
*name, int buswidth,
if (host_caps)
cfg->host_caps |= host_caps;
 
+
cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
 
return 0;
 }
 
+#ifdef CONFIG_BLK
+int sdhci_bind(struct udevice *dev, struct mmc *mmc, struct mmc_config *cfg)
+{
+   return mmc_bind(dev, mmc, cfg);
+}
+#else
 int add_sdhci(struct sdhci_host *host, u32 max_clk, u32 min_clk)
 {
unsigned int caps;
@@ -567,3 +604,4 @@ int add_sdhci(struct sdhci_host *host, u32 max_clk, u32 
min_clk)
 
return 0;
 }
+#endif
diff --git a/include/sdhci.h b/include/sdhci.h
index e0f6667..c4d3b55 100644
--- a/include/sdhci.h
+++ b/include/sdhci.h
@@ -338,5 +338,85 @@ static inline u8 sdhci_readb(struct sdhci_host *host, int 
reg)
 }
 #endif
 
+#ifdef CONFIG_BLK
+/**
+ * sdhci_setup_cfg() - Set up the configuration for DWMMC
+ *
+ * This is used to set up an SDHCI device when you are using CONFIG_BLK.
+ *
+ * This should be called from your MMC driver's probe() method once you have
+ * the information required.
+ *
+ * Generally your driver will have a platform data structure which holds both
+ * the configuration (struct mmc_config) and the MMC device info (struct mmc).
+ * For example:
+ *
+ * struct msm_sdhc_plat {
+ * struct mmc_config cfg;
+ * struct mmc mmc;
+ * };
+ *
+ * ...
+ *
+ * Inside U_BOOT_DRIVER():
+ * .platdata_auto_alloc_size = sizeof(struct msm_sdhc_plat),
+ *
+ * To access platform data:
+ * struct msm_sdhc_plat *plat = dev_get_platdata(dev);
+ *
+ * See msm_sdhci.c for an example.
+ *
+ * @cfg:   Configuration structure to fill in (generally >mmc)
+ * @name:  Device name (normally dev->name)
+ * @buswidth:  Bus width (in bits, such as 4 or 8)
+ * @caps:  Host capabilities (MMC_MODE_...)
+ * @max_clk:   Maximum supported clock speed in HZ (0 for default)
+ * @min_clk:   Minimum supported clock speed in HZ (0 for default)
+ * @version:   Host controller version (generally read from the
+ * SDHCI_HOST_VERSION register)
+ * @quirks:Quick flags (SDHCI_QUIRK_...)
+ * @host_caps: Additional host capabilities (0 if none)
+ */
+int sdhci_setup_cfg(struct mmc_config *cfg, const char *name, int buswidth,
+   uint caps, u32 max_clk, u32 min_clk, uint version,
+   uint quirks, uint host_caps);
+
+/**
+ * sdhci_bind() - Set up a new MMC block device
+ *
+ * This is used to set up an SDHCI block device when you