omap3: mmc: Allow for MMC controller slot change
authorPaul Kocialkowski <contact@paulk.fr>
Fri, 5 Sep 2014 19:05:32 +0000 (21:05 +0200)
committerPaul Kocialkowski <contact@paulk.fr>
Sat, 6 Sep 2014 18:18:54 +0000 (20:18 +0200)
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
board/omap3430sdp/omap3430sdp.c
board/tam3517/tam3517.c
cpu/omap3/mmc.c
cpu/omap4/mmc.c
include/asm/arch-omap3/mmc_host_def.h
include/common.h
include/mmc.h
lib/board.c

index d8a2c1b..20457e7 100644 (file)
@@ -623,7 +623,7 @@ int mmc_boot(void)
 
        printf("Starting X-loader on MMC \n");
 
-       ret = mmc_init(1);
+       ret = mmc_init(0);
        if(ret == 0){
                printf("\n MMC init failed \n");
                return 0;
index 1b33421..b89b0f6 100644 (file)
@@ -117,7 +117,7 @@ extern dpll_param *get_mpu_dpll_param(void);
 extern dpll_param *get_core_dpll_param(void);
 extern dpll_param *get_per_dpll_param(void);
 
-extern int mmc_init(int verbose);
+extern int mmc_init(int slot);
 extern block_dev_desc_t *mmc_get_dev(int dev);
 
 #define __raw_readl(a)    (*(volatile unsigned int *)(a))
@@ -971,7 +971,7 @@ int mmc_boot(unsigned char *buf)
 
        printf("Starting X-loader on MMC \n");
 
-       ret = mmc_init(1);
+       ret = mmc_init(0);
        if(ret == 0){
                printf("\n MMC init failed \n");
                return 0;
index 92db9db..aa93eb2 100644 (file)
@@ -50,6 +50,9 @@ const unsigned short mmc_transspeed_val[15][4] = {
 mmc_card_data cur_card_data;
 static block_dev_desc_t mmc_blk_dev;
 
+int mmc_slot = 0;
+unsigned int mmc_base = OMAP_HSMMC_BASE1;
+
 block_dev_desc_t *mmc_get_dev(int dev)
 {
        return ((block_dev_desc_t *) &mmc_blk_dev);
@@ -60,10 +63,20 @@ void twl4030_mmc_config(void)
 {
        unsigned char data;
 
-       data = 0x20;
-       i2c_write(0x4B, 0x82, 1, &data, 1);
-       data = 0x2;
-       i2c_write(0x4B, 0x85, 1, &data, 1);
+       switch (mmc_slot) {
+               case 0:
+                       data = 0x20;
+                       i2c_write(0x4B, 0x82, 1, &data, 1);
+                       data = 0x2;
+                       i2c_write(0x4B, 0x85, 1, &data, 1);
+                       break;
+               case 1:
+                       data = 0x20;
+                       i2c_write(0x4B, 0x86, 1, &data, 1);
+                       data = 0xB;
+                       i2c_write(0x4B, 0x89, 1, &data, 1);
+                       break;
+       }
 }
 #endif
 
@@ -75,11 +88,19 @@ unsigned char mmc_board_init(void)
        twl4030_mmc_config();
 #endif
 
-       value = CONTROL_PBIAS_LITE;
-       CONTROL_PBIAS_LITE = value | (1 << 2) | (1 << 1) | (1 << 9);
+       switch (mmc_slot) {
+               case 0:
+                       value = CONTROL_PBIAS_LITE;
+                       CONTROL_PBIAS_LITE = value | (1 << 2) | (1 << 1) | (1 << 9);
 
-       value = CONTROL_DEV_CONF0;
-       CONTROL_DEV_CONF0 = value | (1 << 24);
+                       value = CONTROL_DEV_CONF0;
+                       CONTROL_DEV_CONF0 = value | (1 << 24);
+                       break;
+               case 1:
+                       value = CONTROL_DEV_CONF1;
+                       CONTROL_DEV_CONF1 = value | (1 << 6);
+                       break;
+       }
 
        return 1;
 }
@@ -88,29 +109,29 @@ void mmc_init_stream(void)
 {
        volatile unsigned int mmc_stat;
 
-       OMAP_HSMMC_CON |= INIT_INITSTREAM;
+       OMAP_HSMMC_CON(mmc_base) |= INIT_INITSTREAM;
 
-       OMAP_HSMMC_CMD = MMC_CMD0;
+       OMAP_HSMMC_CMD(mmc_base) = MMC_CMD0;
        do {
-               mmc_stat = OMAP_HSMMC_STAT;
+               mmc_stat = OMAP_HSMMC_STAT(mmc_base);
        } while (!(mmc_stat & CC_MASK));
 
-       OMAP_HSMMC_STAT = CC_MASK;
+       OMAP_HSMMC_STAT(mmc_base) = CC_MASK;
 
-       OMAP_HSMMC_CMD = MMC_CMD0;
+       OMAP_HSMMC_CMD(mmc_base) = MMC_CMD0;
        do {
-               mmc_stat = OMAP_HSMMC_STAT;
+               mmc_stat = OMAP_HSMMC_STAT(mmc_base);
        } while (!(mmc_stat & CC_MASK));
 
-       OMAP_HSMMC_STAT = OMAP_HSMMC_STAT;
-       OMAP_HSMMC_CON &= ~INIT_INITSTREAM;
+       OMAP_HSMMC_STAT(mmc_base) = OMAP_HSMMC_STAT(mmc_base);
+       OMAP_HSMMC_CON(mmc_base) &= ~INIT_INITSTREAM;
 }
 
 unsigned char mmc_clock_config(unsigned int iclk, unsigned short clk_div)
 {
        unsigned int val;
 
-       mmc_reg_out(OMAP_HSMMC_SYSCTL, (ICE_MASK | DTO_MASK | CEN_MASK),
+       mmc_reg_out(OMAP_HSMMC_SYSCTL(mmc_base), (ICE_MASK | DTO_MASK | CEN_MASK),
                    (ICE_STOP | DTO_15THDTO | CEN_DISABLE));
 
        switch (iclk) {
@@ -126,13 +147,13 @@ unsigned char mmc_clock_config(unsigned int iclk, unsigned short clk_div)
        default:
                return 0;
        }
-       mmc_reg_out(OMAP_HSMMC_SYSCTL,
+       mmc_reg_out(OMAP_HSMMC_SYSCTL(mmc_base),
                    ICE_MASK | CLKD_MASK, (val << CLKD_OFFSET) | ICE_OSCILLATE);
 
-       while ((OMAP_HSMMC_SYSCTL & ICS_MASK) == ICS_NOTREADY) {
+       while ((OMAP_HSMMC_SYSCTL(mmc_base) & ICS_MASK) == ICS_NOTREADY) {
        }
 
-       OMAP_HSMMC_SYSCTL |= CEN_ENABLE;
+       OMAP_HSMMC_SYSCTL(mmc_base) |= CEN_ENABLE;
        return 1;
 }
 
@@ -142,25 +163,25 @@ unsigned char mmc_init_setup(void)
 
        mmc_board_init();
 
-       OMAP_HSMMC_SYSCONFIG |= MMC_SOFTRESET;
-       while ((OMAP_HSMMC_SYSSTATUS & RESETDONE) == 0) ;
+       OMAP_HSMMC_SYSCONFIG(mmc_base) |= MMC_SOFTRESET;
+       while ((OMAP_HSMMC_SYSSTATUS(mmc_base) & RESETDONE) == 0) ;
 
-       OMAP_HSMMC_SYSCTL |= SOFTRESETALL;
-       while ((OMAP_HSMMC_SYSCTL & SOFTRESETALL) != 0x0) ;
+       OMAP_HSMMC_SYSCTL(mmc_base) |= SOFTRESETALL;
+       while ((OMAP_HSMMC_SYSCTL(mmc_base) & SOFTRESETALL) != 0x0) ;
 
-       OMAP_HSMMC_HCTL = DTW_1_BITMODE | SDBP_PWROFF | SDVS_3V0;
-       OMAP_HSMMC_CAPA |= VS30_3V0SUP | VS18_1V8SUP;
+       OMAP_HSMMC_HCTL(mmc_base) = DTW_1_BITMODE | SDBP_PWROFF | SDVS_3V0;
+       OMAP_HSMMC_CAPA(mmc_base) |= VS30_3V0SUP | VS18_1V8SUP;
 
-       reg_val = OMAP_HSMMC_CON & RESERVED_MASK;
+       reg_val = OMAP_HSMMC_CON(mmc_base) & RESERVED_MASK;
 
-       OMAP_HSMMC_CON = CTPL_MMC_SD | reg_val | WPP_ACTIVEHIGH |
+       OMAP_HSMMC_CON(mmc_base) = CTPL_MMC_SD | reg_val | WPP_ACTIVEHIGH |
            CDP_ACTIVEHIGH | MIT_CTO | DW8_1_4BITMODE | MODE_FUNC |
            STR_BLOCK | HR_NOHOSTRESP | INIT_NOINIT | NOOPENDRAIN;
 
        mmc_clock_config(CLK_INITSEQ, 0);
-       OMAP_HSMMC_HCTL |= SDBP_PWRON;
+       OMAP_HSMMC_HCTL(mmc_base) |= SDBP_PWRON;
 
-       OMAP_HSMMC_IE = 0x307f0033;
+       OMAP_HSMMC_IE(mmc_base) = 0x307f0033;
 
        mmc_init_stream();
        return 1;
@@ -171,31 +192,31 @@ unsigned char mmc_send_cmd(unsigned int cmd, unsigned int arg,
 {
        volatile unsigned int mmc_stat;
 
-       while ((OMAP_HSMMC_PSTATE & DATI_MASK) == DATI_CMDDIS) {
+       while ((OMAP_HSMMC_PSTATE(mmc_base) & DATI_MASK) == DATI_CMDDIS) {
        }
 
-       OMAP_HSMMC_BLK = BLEN_512BYTESLEN | NBLK_STPCNT;
-       OMAP_HSMMC_STAT = 0xFFFFFFFF;
-       OMAP_HSMMC_ARG = arg;
-       OMAP_HSMMC_CMD = cmd | CMD_TYPE_NORMAL | CICE_NOCHECK |
+       OMAP_HSMMC_BLK(mmc_base) = BLEN_512BYTESLEN | NBLK_STPCNT;
+       OMAP_HSMMC_STAT(mmc_base) = 0xFFFFFFFF;
+       OMAP_HSMMC_ARG(mmc_base) = arg;
+       OMAP_HSMMC_CMD(mmc_base) = cmd | CMD_TYPE_NORMAL | CICE_NOCHECK |
            CCCE_NOCHECK | MSBS_SGLEBLK | ACEN_DISABLE | BCE_DISABLE |
            DE_DISABLE;
 
        while (1) {
                do {
-                       mmc_stat = OMAP_HSMMC_STAT;
+                       mmc_stat = OMAP_HSMMC_STAT(mmc_base);
                } while (mmc_stat == 0);
 
                if ((mmc_stat & ERRI_MASK) != 0)
                        return (unsigned char) mmc_stat;
 
                if (mmc_stat & CC_MASK) {
-                       OMAP_HSMMC_STAT = CC_MASK;
-                       response[0] = OMAP_HSMMC_RSP10;
+                       OMAP_HSMMC_STAT(mmc_base) = CC_MASK;
+                       response[0] = OMAP_HSMMC_RSP10(mmc_base);
                        if ((cmd & RSP_TYPE_MASK) == RSP_TYPE_LGHT136) {
-                               response[1] = OMAP_HSMMC_RSP32;
-                               response[2] = OMAP_HSMMC_RSP54;
-                               response[3] = OMAP_HSMMC_RSP76;
+                               response[1] = OMAP_HSMMC_RSP32(mmc_base);
+                               response[2] = OMAP_HSMMC_RSP54(mmc_base);
+                               response[3] = OMAP_HSMMC_RSP76(mmc_base);
                        }
                        break;
                }
@@ -213,7 +234,7 @@ unsigned char mmc_read_data(unsigned int *output_buf)
         */
        while (1) {
                do {
-                       mmc_stat = OMAP_HSMMC_STAT;
+                       mmc_stat = OMAP_HSMMC_STAT(mmc_base);
                } while (mmc_stat == 0);
 
                if ((mmc_stat & ERRI_MASK) != 0)
@@ -222,19 +243,19 @@ unsigned char mmc_read_data(unsigned int *output_buf)
                if (mmc_stat & BRR_MASK) {
                        unsigned int k;
 
-                       OMAP_HSMMC_STAT |= BRR_MASK;
+                       OMAP_HSMMC_STAT(mmc_base) |= BRR_MASK;
                        for (k = 0; k < MMCSD_SECTOR_SIZE / 4; k++) {
-                               *output_buf = OMAP_HSMMC_DATA;
+                               *output_buf = OMAP_HSMMC_DATA(mmc_base);
                                output_buf++;
                                read_count += 4;
                        }
                }
 
                if (mmc_stat & BWR_MASK)
-                       OMAP_HSMMC_STAT |= BWR_MASK;
+                       OMAP_HSMMC_STAT(mmc_base) |= BWR_MASK;
 
                if (mmc_stat & TC_MASK) {
-                       OMAP_HSMMC_STAT |= TC_MASK;
+                       OMAP_HSMMC_STAT(mmc_base) |= TC_MASK;
                        break;
                }
        }
@@ -278,8 +299,8 @@ unsigned char mmc_detect_card(mmc_card_data *mmc_card_cur)
                mmc_card_cur->card_type = MMC_CARD;
                ocr_value |= MMC_OCR_REG_ACCESS_MODE_SECTOR;
                ret_cmd41 = MMC_CMD1;
-               OMAP_HSMMC_CON &= ~OD;
-               OMAP_HSMMC_CON |= OPENDRAIN;
+               OMAP_HSMMC_CON(mmc_base) &= ~OD;
+               OMAP_HSMMC_CON(mmc_base) |= OPENDRAIN;
        }
 
        argument = ocr_value;
@@ -347,8 +368,9 @@ unsigned char mmc_detect_card(mmc_card_data *mmc_card_cur)
                mmc_card_cur->RCA = ((mmc_resp_r6 *) resp)->newpublishedrca;
        }
 
-       OMAP_HSMMC_CON &= ~OD;
-       OMAP_HSMMC_CON |= NOOPENDRAIN;
+       OMAP_HSMMC_CON(mmc_base) &= ~OD;
+       OMAP_HSMMC_CON(mmc_base) |= NOOPENDRAIN;
+
        return 1;
 }
 
@@ -527,10 +549,23 @@ unsigned long mmc_bread(int dev_num, unsigned long blknr, lbaint_t blkcnt,
        return 1;
 }
 
-int mmc_init(int verbose)
+int mmc_init(int slot)
 {
        unsigned char ret;
 
+       switch (slot) {
+               case 0:
+                       mmc_slot = slot;
+                       mmc_base = OMAP_HSMMC_BASE1;
+                       break;
+               case 1:
+                       mmc_slot = slot;
+                       mmc_base = OMAP_HSMMC_BASE2;
+                       break;
+               default:
+                       return 0;
+       }
+
        ret = configure_mmc(&cur_card_data);
 
        if (ret == 1) {
@@ -551,6 +586,7 @@ int mmc_init(int verbose)
        }
        else 
                return 0;
+
 }
 
 int mmc_read(ulong src, uchar *dst, int size)
index 5484342..2920b83 100644 (file)
@@ -504,7 +504,7 @@ unsigned long mmc_bread(int dev_num, unsigned long blknr, lbaint_t blkcnt,
        return 1;
 }
 
-int mmc_init(int verbose)
+int mmc_init(int slot)
 {
        unsigned char ret = configure_mmc(&cur_card_data);
 
index 408d1e2..552deb6 100644 (file)
 /*
  * OMAP HSMMC register definitions
  */
-#define OMAP_HSMMC_SYSCONFIG   (*(volatile unsigned int *) 0x4809C010)
-#define OMAP_HSMMC_SYSSTATUS   (*(volatile unsigned int *) 0x4809C014)
-#define OMAP_HSMMC_CON         (*(volatile unsigned int *) 0x4809C02C)
-#define OMAP_HSMMC_BLK         (*(volatile unsigned int *) 0x4809C104)
-#define OMAP_HSMMC_ARG         (*(volatile unsigned int *) 0x4809C108)
-#define OMAP_HSMMC_CMD         (*(volatile unsigned int *) 0x4809C10C)
-#define OMAP_HSMMC_RSP10       (*(volatile unsigned int *) 0x4809C110)
-#define OMAP_HSMMC_RSP32       (*(volatile unsigned int *) 0x4809C114)
-#define OMAP_HSMMC_RSP54       (*(volatile unsigned int *) 0x4809C118)
-#define OMAP_HSMMC_RSP76       (*(volatile unsigned int *) 0x4809C11C)
-#define OMAP_HSMMC_DATA                (*(volatile unsigned int *) 0x4809C120)
-#define OMAP_HSMMC_PSTATE      (*(volatile unsigned int *) 0x4809C124)
-#define OMAP_HSMMC_HCTL                (*(volatile unsigned int *) 0x4809C128)
-#define OMAP_HSMMC_SYSCTL      (*(volatile unsigned int *) 0x4809C12C)
-#define OMAP_HSMMC_STAT                (*(volatile unsigned int *) 0x4809C130)
-#define OMAP_HSMMC_IE          (*(volatile unsigned int *) 0x4809C134)
-#define OMAP_HSMMC_CAPA                (*(volatile unsigned int *) 0x4809C140)
+
+#define OMAP_HSMMC_BASE1               0x4809C000
+#define OMAP_HSMMC_BASE2               0x480B4000
+
+#define OMAP_HSMMC_SYSCONFIG(base)     (*(volatile unsigned int *) (base + 0x10))
+#define OMAP_HSMMC_SYSSTATUS(base)     (*(volatile unsigned int *) (base + 0x14))
+#define OMAP_HSMMC_CON(base)           (*(volatile unsigned int *) (base + 0x2C))
+#define OMAP_HSMMC_BLK(base)           (*(volatile unsigned int *) (base + 0x104))
+#define OMAP_HSMMC_ARG(base)           (*(volatile unsigned int *) (base + 0x108))
+#define OMAP_HSMMC_CMD(base)           (*(volatile unsigned int *) (base + 0x10C))
+#define OMAP_HSMMC_RSP10(base)         (*(volatile unsigned int *) (base + 0x110))
+#define OMAP_HSMMC_RSP32(base)         (*(volatile unsigned int *) (base + 0x114))
+#define OMAP_HSMMC_RSP54(base)         (*(volatile unsigned int *) (base + 0x118))
+#define OMAP_HSMMC_RSP76(base)         (*(volatile unsigned int *) (base + 0x11C))
+#define OMAP_HSMMC_DATA(base)          (*(volatile unsigned int *) (base + 0x120))
+#define OMAP_HSMMC_PSTATE(base)                (*(volatile unsigned int *) (base + 0x124))
+#define OMAP_HSMMC_HCTL(base)          (*(volatile unsigned int *) (base + 0x128))
+#define OMAP_HSMMC_SYSCTL(base)                (*(volatile unsigned int *) (base + 0x12C))
+#define OMAP_HSMMC_STAT(base)          (*(volatile unsigned int *) (base + 0x130))
+#define OMAP_HSMMC_IE(base)            (*(volatile unsigned int *) (base + 0x134))
+#define OMAP_HSMMC_CAPA(base)          (*(volatile unsigned int *) (base + 0x140))
 
 /* T2 Register definitions */
 #define CONTROL_DEV_CONF0      (*(volatile unsigned int *) 0x48002274)
+#define CONTROL_DEV_CONF1      (*(volatile unsigned int *) 0x480022D8)
 #define CONTROL_PBIAS_LITE     (*(volatile unsigned int *) 0x48002520)
 
 /*
index a3c5092..5c16589 100644 (file)
@@ -110,7 +110,7 @@ void        hang            (void) __attribute__ ((noreturn));
 
 extern int do_load_serial_bin (ulong offset, int baudrate);
 extern u32 get_mem_type(void);
-extern int mmc_init(int verbose);
+extern int mmc_init(int slot);
 extern int misc_init_r(void);
 
 extern int sprintf (char *__s, const char *__format, ...);
index 19c76fe..c720247 100644 (file)
@@ -49,7 +49,7 @@
 #define SD_CMD_APP_SET_BUS_WIDTH       6
 #define SD_CMD_APP_SEND_OP_COND                41
 
-int mmc_init(int verbose);
+int mmc_init(int slot);
 int mmc_read(ulong src, uchar *dst, int size);
 int mmc_write(uchar *src, ulong dst, int size);
 int mmc2info(ulong addr);
index 0f6b960..1d88fc7 100644 (file)
@@ -83,6 +83,9 @@ void start_armboot (void)
        int size;
        uchar *buf;
        int *first_instruction;
+#ifdef CONFIG_MMC
+       int slot;
+#endif
 #if defined(CFG_ONENAND) || defined(CFG_NAND_K9F1G08R0A)
        int i;
 #endif
@@ -98,13 +101,19 @@ void start_armboot (void)
 
 #ifdef CONFIG_MMC
        /* first try mmc */
-       if (mmc_init(1)) {
-               size = file_fat_read("u-boot.bin", buf, 0);
-               if (size > 0) {
+#ifdef CONFIG_MMC_SLOT_MAX
+       for (slot = 0; slot <= CONFIG_MMC_SLOT_MAX; slot++) {
+#else
+       if (slot = 0) {
+#endif
+               if (buf == (uchar *)CFG_LOADADDR && mmc_init(slot)) {
+                       size = file_fat_read("u-boot.bin", buf, 0);
+                       if (size > 0) {
 #ifdef CFG_PRINTF
-                       printf("Loading u-boot.bin from mmc\n");
+                               printf("Loading u-boot.bin from mmc\n");
 #endif
-                       buf += size;
+                               buf += size;
+                       }
                }
        }
 #endif