mmc: omap_hsmmc: use mmc_get_blk_desc() to get the block device desc
[oweals/u-boot.git] / drivers / mmc / omap_hsmmc.c
index b3268467dcc904e660bd5b09463704b6cbf247ea..d985ac7b144edd1f3e4d29f2e2cbb98a4fea293c 100644 (file)
@@ -37,6 +37,9 @@
 #include <asm/gpio.h>
 #include <asm/arch/sys_proto.h>
 #endif
+#ifdef CONFIG_MMC_OMAP36XX_PINS
+#include <asm/arch/mux.h>
+#endif
 #include <dm.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -75,7 +78,16 @@ static int mmc_read_data(struct hsmmc *mmc_base, char *buf, unsigned int size);
 static int mmc_write_data(struct hsmmc *mmc_base, const char *buf,
                        unsigned int siz);
 
-#if defined(OMAP_HSMMC_USE_GPIO) && !defined(CONFIG_DM_MMC)
+static inline struct omap_hsmmc_data *omap_hsmmc_get_data(struct mmc *mmc)
+{
+#ifdef CONFIG_DM_MMC
+       return dev_get_priv(mmc->dev);
+#else
+       return (struct omap_hsmmc_data *)mmc->priv;
+#endif
+}
+
+ #if defined(OMAP_HSMMC_USE_GPIO) && !defined(CONFIG_DM_MMC)
 static int omap_mmc_setup_gpio_in(int gpio, const char *label)
 {
        int ret;
@@ -102,12 +114,22 @@ static unsigned char mmc_board_init(struct mmc *mmc)
        t2_t *t2_base = (t2_t *)T2_BASE;
        struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
        u32 pbias_lite;
+#ifdef CONFIG_MMC_OMAP36XX_PINS
+       u32 wkup_ctrl = readl(OMAP34XX_CTRL_WKUP_CTRL);
+#endif
 
        pbias_lite = readl(&t2_base->pbias_lite);
        pbias_lite &= ~(PBIASLITEPWRDNZ1 | PBIASLITEPWRDNZ0);
 #ifdef CONFIG_TARGET_OMAP3_CAIRO
        /* for cairo board, we need to set up 1.8 Volt bias level on MMC1 */
        pbias_lite &= ~PBIASLITEVMODE0;
+#endif
+#ifdef CONFIG_MMC_OMAP36XX_PINS
+       if (get_cpu_family() == CPU_OMAP36XX) {
+               /* Disable extended drain IO before changing PBIAS */
+               wkup_ctrl &= ~OMAP34XX_CTRL_WKUP_CTRL_GPIO_IO_PWRDNZ;
+               writel(wkup_ctrl, OMAP34XX_CTRL_WKUP_CTRL);
+       }
 #endif
        writel(pbias_lite, &t2_base->pbias_lite);
 
@@ -115,6 +137,13 @@ static unsigned char mmc_board_init(struct mmc *mmc)
                PBIASSPEEDCTRL0 | PBIASLITEPWRDNZ0,
                &t2_base->pbias_lite);
 
+#ifdef CONFIG_MMC_OMAP36XX_PINS
+       if (get_cpu_family() == CPU_OMAP36XX)
+               /* Enable extended drain IO after changing PBIAS */
+               writel(wkup_ctrl |
+                               OMAP34XX_CTRL_WKUP_CTRL_GPIO_IO_PWRDNZ,
+                               OMAP34XX_CTRL_WKUP_CTRL);
+#endif
        writel(readl(&t2_base->devconf0) | MMCSDIO1ADPCLKISEL,
                &t2_base->devconf0);
 
@@ -137,7 +166,7 @@ static unsigned char mmc_board_init(struct mmc *mmc)
 
 #if defined(CONFIG_OMAP54XX) || defined(CONFIG_OMAP44XX)
        /* PBIAS config needed for MMC1 only */
-       if (mmc->block_dev.devnum == 0)
+       if (mmc_get_blk_desc(mmc)->devnum == 0)
                vmmc_pbias_config(LDO_VOLT_3V0);
 #endif
 
@@ -174,12 +203,13 @@ void mmc_init_stream(struct hsmmc *mmc_base)
 
 static int omap_hsmmc_init_setup(struct mmc *mmc)
 {
+       struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc);
        struct hsmmc *mmc_base;
        unsigned int reg_val;
        unsigned int dsor;
        ulong start;
 
-       mmc_base = ((struct omap_hsmmc_data *)mmc->priv)->base_addr;
+       mmc_base = priv->base_addr;
        mmc_board_init(mmc);
 
        writel(readl(&mmc_base->sysconfig) | MMC_SOFTRESET,
@@ -284,11 +314,12 @@ static void mmc_reset_controller_fsm(struct hsmmc *mmc_base, u32 bit)
 static int omap_hsmmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
                        struct mmc_data *data)
 {
+       struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc);
        struct hsmmc *mmc_base;
        unsigned int flags, mmc_stat;
        ulong start;
 
-       mmc_base = ((struct omap_hsmmc_data *)mmc->priv)->base_addr;
+       mmc_base = priv->base_addr;
        start = get_timer(0);
        while ((readl(&mmc_base->pstate) & (DATI_MASK | CMDI_MASK)) != 0) {
                if (get_timer(0) - start > MAX_RETRY_MS) {
@@ -513,11 +544,12 @@ static int mmc_write_data(struct hsmmc *mmc_base, const char *buf,
 
 static int omap_hsmmc_set_ios(struct mmc *mmc)
 {
+       struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc);
        struct hsmmc *mmc_base;
        unsigned int dsor = 0;
        ulong start;
 
-       mmc_base = ((struct omap_hsmmc_data *)mmc->priv)->base_addr;
+       mmc_base = priv->base_addr;
        /* configue bus width */
        switch (mmc->bus_width) {
        case 8:
@@ -571,7 +603,7 @@ static int omap_hsmmc_set_ios(struct mmc *mmc)
 #ifdef CONFIG_DM_MMC
 static int omap_hsmmc_getcd(struct mmc *mmc)
 {
-       struct omap_hsmmc_data *priv = mmc->priv;
+       struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc);
        int value;
 
        value = dm_gpio_get_value(&priv->cd_gpio);
@@ -586,7 +618,7 @@ static int omap_hsmmc_getcd(struct mmc *mmc)
 
 static int omap_hsmmc_getwp(struct mmc *mmc)
 {
-       struct omap_hsmmc_data *priv = mmc->priv;
+       struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc);
        int value;
 
        value = dm_gpio_get_value(&priv->wp_gpio);
@@ -598,11 +630,11 @@ static int omap_hsmmc_getwp(struct mmc *mmc)
 #else
 static int omap_hsmmc_getcd(struct mmc *mmc)
 {
-       struct omap_hsmmc_data *priv_data = mmc->priv;
+       struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc);
        int cd_gpio;
 
        /* if no CD return as 1 */
-       cd_gpio = priv_data->cd_gpio;
+       cd_gpio = priv->cd_gpio;
        if (cd_gpio < 0)
                return 1;
 
@@ -612,11 +644,11 @@ static int omap_hsmmc_getcd(struct mmc *mmc)
 
 static int omap_hsmmc_getwp(struct mmc *mmc)
 {
-       struct omap_hsmmc_data *priv_data = mmc->priv;
+       struct omap_hsmmc_data *priv = omap_hsmmc_get_data(mmc);
        int wp_gpio;
 
        /* if no WP return as 0 */
-       wp_gpio = priv_data->wp_gpio;
+       wp_gpio = priv->wp_gpio;
        if (wp_gpio < 0)
                return 0;
 
@@ -641,23 +673,23 @@ int omap_mmc_init(int dev_index, uint host_caps_mask, uint f_max, int cd_gpio,
                int wp_gpio)
 {
        struct mmc *mmc;
-       struct omap_hsmmc_data *priv_data;
+       struct omap_hsmmc_data *priv;
        struct mmc_config *cfg;
        uint host_caps_val;
 
-       priv_data = malloc(sizeof(*priv_data));
-       if (priv_data == NULL)
+       priv = malloc(sizeof(*priv));
+       if (priv == NULL)
                return -1;
 
        host_caps_val = MMC_MODE_4BIT | MMC_MODE_HS_52MHz | MMC_MODE_HS;
 
        switch (dev_index) {
        case 0:
-               priv_data->base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE;
+               priv->base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE;
                break;
 #ifdef OMAP_HSMMC2_BASE
        case 1:
-               priv_data->base_addr = (struct hsmmc *)OMAP_HSMMC2_BASE;
+               priv->base_addr = (struct hsmmc *)OMAP_HSMMC2_BASE;
 #if (defined(CONFIG_OMAP44XX) || defined(CONFIG_OMAP54XX) || \
        defined(CONFIG_DRA7XX) || defined(CONFIG_AM33XX) || \
        defined(CONFIG_AM43XX) || defined(CONFIG_SOC_KEYSTONE)) && \
@@ -669,7 +701,7 @@ int omap_mmc_init(int dev_index, uint host_caps_mask, uint f_max, int cd_gpio,
 #endif
 #ifdef OMAP_HSMMC3_BASE
        case 2:
-               priv_data->base_addr = (struct hsmmc *)OMAP_HSMMC3_BASE;
+               priv->base_addr = (struct hsmmc *)OMAP_HSMMC3_BASE;
 #if defined(CONFIG_DRA7XX) && defined(CONFIG_HSMMC3_8BIT)
                /* Enable 8-bit interface for eMMC on DRA7XX */
                host_caps_val |= MMC_MODE_8BIT;
@@ -677,16 +709,16 @@ int omap_mmc_init(int dev_index, uint host_caps_mask, uint f_max, int cd_gpio,
                break;
 #endif
        default:
-               priv_data->base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE;
+               priv->base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE;
                return 1;
        }
 #ifdef OMAP_HSMMC_USE_GPIO
        /* on error gpio values are set to -1, which is what we want */
-       priv_data->cd_gpio = omap_mmc_setup_gpio_in(cd_gpio, "mmc_cd");
-       priv_data->wp_gpio = omap_mmc_setup_gpio_in(wp_gpio, "mmc_wp");
+       priv->cd_gpio = omap_mmc_setup_gpio_in(cd_gpio, "mmc_cd");
+       priv->wp_gpio = omap_mmc_setup_gpio_in(wp_gpio, "mmc_wp");
 #endif
 
-       cfg = &priv_data->cfg;
+       cfg = &priv->cfg;
 
        cfg->name = "OMAP SD/MMC";
        cfg->ops = &omap_hsmmc_ops;
@@ -717,7 +749,7 @@ int omap_mmc_init(int dev_index, uint host_caps_mask, uint f_max, int cd_gpio,
        if ((get_cpu_family() == CPU_OMAP34XX) && (get_cpu_rev() <= CPU_3XX_ES21))
                cfg->b_max = 1;
 #endif
-       mmc = mmc_create(cfg, priv_data);
+       mmc = mmc_create(cfg, priv);
        if (mmc == NULL)
                return -1;
 
@@ -728,7 +760,7 @@ static int omap_hsmmc_ofdata_to_platdata(struct udevice *dev)
 {
        struct omap_hsmmc_data *priv = dev_get_priv(dev);
        const void *fdt = gd->fdt_blob;
-       int node = dev->of_offset;
+       int node = dev_of_offset(dev);
        struct mmc_config *cfg;
        int val;