#include <malloc.h>
#include <asm/io.h>
#include <asm/arch/sdmmc_defs.h>
+#include <asm-generic/gpio.h>
+#include <linux/delay.h>
-#define DAVINCI_MAX_BLOCKS (32)
#define WATCHDOG_COUNT (100000)
#define get_val(addr) REG(addr)
#define clear_bit(addr, val) set_val((addr), (get_val(addr) & ~(val)))
#ifdef CONFIG_DM_MMC
-struct davinci_of_data {
- const char *name;
- u8 version;
-};
-
/* Davinci MMC board definitions */
struct davinci_mmc_priv {
struct davinci_mmc_regs *reg_base; /* Register base address */
uint input_clk; /* Input clock to MMC controller */
- uint version; /* MMC Controller version */
-};
-
-struct davinci_mmc_plat
-{
- struct mmc_config cfg;
- struct mmc mmc;
+ struct gpio_desc cd_gpio; /* Card Detect GPIO */
+ struct gpio_desc wp_gpio; /* Write Protect GPIO */
};
#endif
/* Clear status registers */
mmcstatus = get_val(®s->mmcst0);
- fifo_words = (host->version == MMC_CTLR_VERSION_2) ? 16 : 8;
+ fifo_words = 16;
fifo_bytes = fifo_words << 2;
/* Wait for any previous busy signal to be cleared */
set_val(®s->mmcfifoctl,
(MMCFIFOCTL_FIFOLEV | MMCFIFOCTL_FIFORST));
- if (host->version == MMC_CTLR_VERSION_2)
- cmddata |= MMCCMD_DMATRIG;
+ cmddata |= MMCCMD_DMATRIG;
cmddata |= MMCCMD_WDATX;
if (data->flags == MMC_DATA_READ) {
.init = dmmc_init,
};
#else
+
+static int davinci_mmc_getcd(struct udevice *dev)
+{
+ int value = -1;
+#if CONFIG_IS_ENABLED(DM_GPIO)
+ struct davinci_mmc_priv *priv = dev_get_priv(dev);
+ value = dm_gpio_get_value(&priv->cd_gpio);
+#endif
+ /* if no CD return as 1 */
+ if (value < 0)
+ return 1;
+
+ return value;
+}
+
+static int davinci_mmc_getwp(struct udevice *dev)
+{
+ int value = -1;
+#if CONFIG_IS_ENABLED(DM_GPIO)
+ struct davinci_mmc_priv *priv = dev_get_priv(dev);
+
+ value = dm_gpio_get_value(&priv->wp_gpio);
+#endif
+ /* if no WP return as 0 */
+ if (value < 0)
+ return 0;
+
+ return value;
+}
+
static const struct dm_mmc_ops davinci_mmc_ops = {
.send_cmd = davinci_mmc_send_cmd,
.set_ios = davinci_mmc_set_ios,
+ .get_cd = davinci_mmc_getcd,
+ .get_wp = davinci_mmc_getwp,
};
#endif
struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
struct davinci_mmc_plat *plat = dev_get_platdata(dev);
struct davinci_mmc_priv *priv = dev_get_priv(dev);
- struct mmc_config *cfg = &plat->cfg;
- struct davinci_of_data *data =
- (struct davinci_of_data *)dev_get_driver_data(dev);
- cfg->f_min = 200000;
- cfg->f_max = 25000000;
- cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34,
- cfg->host_caps = MMC_MODE_4BIT, /* DA850 supports only 4-bit SD/MMC */
- cfg->b_max = DAVINCI_MAX_BLOCKS;
-
- if (data) {
- cfg->name = data->name;
- priv->version = data->version;
- }
- priv->reg_base = (struct davinci_mmc_regs *)dev_read_addr(dev);
+ priv->reg_base = plat->reg_base;
priv->input_clk = clk_get(DAVINCI_MMCSD_CLKID);
-
+#if CONFIG_IS_ENABLED(DM_GPIO)
+ /* These GPIOs are optional */
+ gpio_request_by_name(dev, "cd-gpios", 0, &priv->cd_gpio, GPIOD_IS_IN);
+ gpio_request_by_name(dev, "wp-gpios", 0, &priv->wp_gpio, GPIOD_IS_IN);
+#endif
upriv->mmc = &plat->mmc;
return davinci_dm_mmc_init(dev);
return mmc_bind(dev, &plat->mmc, &plat->cfg);
}
+#if CONFIG_IS_ENABLED(OF_CONTROL)
+static int davinci_mmc_ofdata_to_platdata(struct udevice *dev)
+{
+ struct davinci_mmc_plat *plat = dev_get_platdata(dev);
+ struct mmc_config *cfg = &plat->cfg;
-const struct davinci_of_data davinci_mmc_host_info[] = {
- {
- .name = "dm6441-mmc",
- .version = MMC_CTLR_VERSION_1,
- },
- {
- .name = "da830-mmc",
- .version = MMC_CTLR_VERSION_2,
- },
- {},
-};
+ plat->reg_base = (struct davinci_mmc_regs *)dev_read_addr(dev);
+ cfg->f_min = 200000;
+ cfg->f_max = 25000000;
+ cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34,
+ cfg->host_caps = MMC_MODE_4BIT, /* DA850 supports only 4-bit SD/MMC */
+ cfg->b_max = DAVINCI_MAX_BLOCKS;
+ cfg->name = "da830-mmc";
+
+ return 0;
+}
static const struct udevice_id davinci_mmc_ids[] = {
- {
- .compatible = "ti,dm6441-mmc",
- .data = (ulong) &davinci_mmc_host_info[MMC_CTLR_VERSION_1]
- },
- {
- .compatible = "ti,da830-mmc",
- .data = (ulong) &davinci_mmc_host_info[MMC_CTLR_VERSION_2]
- },
+ { .compatible = "ti,da830-mmc" },
{},
};
-
+#endif
U_BOOT_DRIVER(davinci_mmc_drv) = {
.name = "davinci_mmc",
.id = UCLASS_MMC,
+#if CONFIG_IS_ENABLED(OF_CONTROL)
.of_match = davinci_mmc_ids,
+ .platdata_auto_alloc_size = sizeof(struct davinci_mmc_plat),
+ .ofdata_to_platdata = davinci_mmc_ofdata_to_platdata,
+#endif
#if CONFIG_BLK
.bind = davinci_mmc_bind,
#endif
.probe = davinci_mmc_probe,
.ops = &davinci_mmc_ops,
- .platdata_auto_alloc_size = sizeof(struct davinci_mmc_plat),
.priv_auto_alloc_size = sizeof(struct davinci_mmc_priv),
+#if !CONFIG_IS_ENABLED(OF_CONTROL)
+ .flags = DM_FLAG_PRE_RELOC,
+#endif
};
#endif