mtk-mmc: Add tune_reg to support more EMMC devices
authorChaotian Jing <chaotian.jing@mediatek.com>
Wed, 11 May 2016 09:56:41 +0000 (17:56 +0800)
committerchrome-bot <chrome-bot@chromium.org>
Sat, 14 May 2016 23:09:14 +0000 (16:09 -0700)
Different EMMC device has different timing, need to find a
register setting to cover all eMMC chips

BUG=chrome-os-partner:52680
BRANCH=None
TEST=Verified on oak-rev5, elm-rev0, elm-rev1 SKU1, elm-rev1 SKU2

Change-Id: I3de39b0ce6c64369d8f58ac3c71586b636639b42
Signed-off-by: Chaotian Jing <chaotian.jing@mediatek.com>
Reviewed-on: https://chromium-review.googlesource.com/344155
Commit-Ready: Yidi Lin <yidi.lin@mediatek.com>
Tested-by: Yidi Lin <yidi.lin@mediatek.com>
Reviewed-by: Julius Werner <jwerner@chromium.org>
src/board/oak/board.c
src/drivers/storage/mtk_mmc.c
src/drivers/storage/mtk_mmc.h

index b4164e3..b6197d7 100644 (file)
@@ -112,6 +112,9 @@ static int sound_setup(void)
 
 static int board_setup(void)
 {
+       MtkMmcTuneReg emmc_tune_reg = {.msdc_iocon = 0, .pad_tune = 0x10 << 16};
+       MtkMmcTuneReg sd_card_tune_reg = {.msdc_iocon = 0, .pad_tune = 0};
+
        sysinfo_install_flags(new_mtk_gpio_input);
 
        MTKI2c *i2c2 = new_mtk_i2c(0x11009000, 0x11000200);
@@ -130,10 +133,11 @@ static int board_setup(void)
        power_set_ops(&pmic->ops);
 
        MtkMmcHost *emmc = new_mtk_mmc_host(0x11230000, 200 * MHz, 50 * MHz,
-                                           8, 0, NULL);
+                                           emmc_tune_reg, 8, 0, NULL);
        GpioOps *card_detect_ops = new_gpio_not(new_mtk_gpio_input(PAD_EINT1));
        MtkMmcHost *sd_card = new_mtk_mmc_host(0x11240000, 200 * MHz, 25 * MHz,
-                                              4, 1, card_detect_ops);
+                                              sd_card_tune_reg, 4, 1,
+                                              card_detect_ops);
 
        list_insert_after(&emmc->mmc.ctrlr.list_node,
                          &fixed_block_dev_controllers);
index 391e4f4..9ac2140 100644 (file)
@@ -384,6 +384,7 @@ static int mtk_mmc_init(BlockDevCtrlrOps *me)
 {
        MtkMmcHost *host = container_of(me, MtkMmcHost, mmc.ctrlr.ops);
        MtkMmcReg *reg = host->reg;
+       MtkMmcTuneReg tune_reg = host->tune_reg;
        mmc_debug("%s called\n", __func__);
 
        /* Configure to MMC/SD mode */
@@ -399,8 +400,8 @@ static int mtk_mmc_init(BlockDevCtrlrOps *me)
        writel(readl(&reg->msdc_int), &reg->msdc_int);
        /* Configure to default data timeout */
        clrsetbits_le32(&reg->sdc_cfg, SDC_CFG_DTOC, DEFAULT_DTOC << 24);
-       /* Sample response by falling clock edge */
-       setbits_le32(&reg->msdc_iocon, MSDC_IOCON_RSPL);
+       writel(tune_reg.msdc_iocon, &reg->msdc_iocon);
+       writel(tune_reg.pad_tune, &reg->pad_tune);
        mtk_mmc_set_buswidth(host, 1);
 
        return 0;
@@ -453,7 +454,8 @@ static int mtk_mmc_update(BlockDevCtrlrOps *me)
 }
 
 MtkMmcHost *new_mtk_mmc_host(uintptr_t ioaddr, uint32_t src_hz, uint32_t max_freq,
-                            int bus_width, int removable, GpioOps *card_detect)
+                            MtkMmcTuneReg tune_reg, int bus_width, int removable,
+                            GpioOps *card_detect)
 {
        MtkMmcHost *ctrlr = xzalloc(sizeof(*ctrlr));
 
@@ -465,6 +467,7 @@ MtkMmcHost *new_mtk_mmc_host(uintptr_t ioaddr, uint32_t src_hz, uint32_t max_fre
        ctrlr->mmc.voltages = MtkMmcVoltages;
        ctrlr->mmc.f_min = MtkMmcMinFreq;
        ctrlr->mmc.f_max = max_freq;
+       ctrlr->tune_reg = tune_reg;
 
        ctrlr->mmc.bus_width = bus_width;
        ctrlr->mmc.bus_hz = ctrlr->mmc.f_min;
index 2832aae..f2aa7e7 100644 (file)
@@ -74,9 +74,15 @@ typedef struct {
 } MtkMmcReg;
 
 typedef struct {
+       uint32_t msdc_iocon;
+       uint32_t pad_tune;
+} MtkMmcTuneReg;
+
+typedef struct {
        MmcCtrlr mmc;
 
        MtkMmcReg *reg;
+       MtkMmcTuneReg tune_reg;
        uint32_t clock;         /* Current clock (MHz) */
        uint32_t src_hz;        /* Source clock (hz) */
 
@@ -87,6 +93,6 @@ typedef struct {
 } MtkMmcHost;
 
 MtkMmcHost *new_mtk_mmc_host(uintptr_t ioaddr, uint32_t src_hz,
-                            uint32_t max_freq, int bus_width,
-                            int removable, GpioOps *card_detect);
+                            uint32_t max_freq, MtkMmcTuneReg tune_reg,
+                            int bus_width, int removable, GpioOps *card_detect);
 #endif // __DRIVERS_STORAGE_MTK_MMC_H_