Lines Matching +full:strobe +full:- +full:dll +full:- +full:delay +full:- +full:target
1 // SPDX-License-Identifier: GPL-2.0
5 * derived from the OF-version.
14 #include <linux/delay.h>
23 #include <linux/mmc/slot-gpio.h>
28 #include "sdhci-cqhci.h"
29 #include "sdhci-pltfm.h"
30 #include "sdhci-esdhc.h"
73 /* dll control register */
82 #define ESDHC_TUNE_CTRL_MAX ((1 << 7) - 1)
84 /* strobe dll register */
140 * open ended multi-blk IO. Otherwise the TC INT wouldn't
221 * struct esdhc_platform_data - platform data for esdhc on i.MX
234 unsigned int tuning_step; /* The delay cell steps in tuning procedure */
235 unsigned int tuning_start_tap; /* The start delay cell point in tuning procedure */
236 unsigned int strobe_dll_delay_target; /* The delay cell for strobe pad (read clock) */
348 * the card init, but at this stage, mmc_host->card is not
364 { .compatible = "fsl,imx25-esdhc", .data = &esdhc_imx25_data, },
365 { .compatible = "fsl,imx35-esdhc", .data = &esdhc_imx35_data, },
366 { .compatible = "fsl,imx51-esdhc", .data = &esdhc_imx51_data, },
367 { .compatible = "fsl,imx53-esdhc", .data = &esdhc_imx53_data, },
368 { .compatible = "fsl,imx6sx-usdhc", .data = &usdhc_imx6sx_data, },
369 { .compatible = "fsl,imx6sl-usdhc", .data = &usdhc_imx6sl_data, },
370 { .compatible = "fsl,imx6sll-usdhc", .data = &usdhc_imx6sll_data, },
371 { .compatible = "fsl,imx6q-usdhc", .data = &usdhc_imx6q_data, },
372 { .compatible = "fsl,imx6ull-usdhc", .data = &usdhc_imx6ull_data, },
373 { .compatible = "fsl,imx7d-usdhc", .data = &usdhc_imx7d_data, },
374 { .compatible = "fsl,imx7ulp-usdhc", .data = &usdhc_imx7ulp_data, },
375 { .compatible = "fsl,imx8qxp-usdhc", .data = &usdhc_imx8qxp_data, },
376 { .compatible = "fsl,imx8mm-usdhc", .data = &usdhc_imx8mm_data, },
377 { .compatible = "fsl,imxrt1050-usdhc", .data = &usdhc_imxrt1050_data, },
378 { .compatible = "nxp,s32g2-usdhc", .data = &usdhc_s32g2_data, },
385 return data->socdata == &esdhc_imx25_data; in is_imx25_esdhc()
390 return data->socdata == &esdhc_imx53_data; in is_imx53_esdhc()
395 return !!(data->socdata->flags & ESDHC_FLAG_USDHC); in esdhc_is_usdhc()
400 void __iomem *base = host->ioaddr + (reg & ~0x3); in esdhc_clrset_le()
406 #define DRIVER_NAME "sdhci-esdhc-imx"
408 pr_err("%s: " DRIVER_NAME ": " f, mmc_hostname(host->mmc), ## x)
427 readw(host->ioaddr + ESDHC_DEBUG_SEL_AND_STATUS_REG)); in esdhc_dump_debug_regs()
439 ret = readl_poll_timeout(host->ioaddr + ESDHC_PRSSTAT, present_state, in esdhc_wait_for_card_clock_gate_off()
441 if (ret == -ETIMEDOUT) in esdhc_wait_for_card_clock_gate_off()
442 dev_warn(mmc_dev(host->mmc), "%s: card clock still not gate off in 100us!.\n", __func__); in esdhc_wait_for_card_clock_gate_off()
453 buswidth = USDHC_GET_BUSWIDTH(readl(host->ioaddr + SDHCI_HOST_CONTROL)); in usdhc_auto_tuning_mode_sel_and_en()
473 * DAT[1], and adjust the delay cell wrongly. in usdhc_auto_tuning_mode_sel_and_en()
478 if (imx_data->init_card_type == MMC_TYPE_SDIO) in usdhc_auto_tuning_mode_sel_and_en()
485 reg = readl(host->ioaddr + ESDHC_MIX_CTRL); in usdhc_auto_tuning_mode_sel_and_en()
487 writel(reg, host->ioaddr + ESDHC_MIX_CTRL); in usdhc_auto_tuning_mode_sel_and_en()
494 u32 val = readl(host->ioaddr + reg); in esdhc_readl_le()
500 /* move dat[0-3] bits */ in esdhc_readl_le()
507 /* ignore bit[0-15] as it stores cap_1 register val for mx6sl */ in esdhc_readl_le()
508 if (imx_data->socdata->flags & ESDHC_FLAG_HAVE_CAP1) in esdhc_readl_le()
526 if (imx_data->socdata->flags & ESDHC_FLAG_HAVE_CAP1) in esdhc_readl_le()
527 val = readl(host->ioaddr + SDHCI_CAPABILITIES) & 0xFFFF; in esdhc_readl_le()
540 if (IS_ERR_OR_NULL(imx_data->pins_100mhz)) in esdhc_readl_le()
542 if (IS_ERR_OR_NULL(imx_data->pins_200mhz)) in esdhc_readl_le()
564 if ((imx_data->multiblock_status == WAIT_FOR_INT) && in esdhc_readl_le()
567 writel(SDHCI_INT_RESPONSE, host->ioaddr + in esdhc_readl_le()
569 imx_data->multiblock_status = NO_CMD_PENDING; in esdhc_readl_le()
589 * and set D3CD bit will make eSDHC re-sample the card in esdhc_writel_le()
591 * re-sample it by the following steps. in esdhc_writel_le()
593 data = readl(host->ioaddr + SDHCI_HOST_CONTROL); in esdhc_writel_le()
595 writel(data, host->ioaddr + SDHCI_HOST_CONTROL); in esdhc_writel_le()
597 writel(data, host->ioaddr + SDHCI_HOST_CONTROL); in esdhc_writel_le()
606 if (unlikely((imx_data->socdata->flags & ESDHC_FLAG_MULTIBLK_NO_INT) in esdhc_writel_le()
610 v = readl(host->ioaddr + ESDHC_VENDOR_SPEC); in esdhc_writel_le()
612 writel(v, host->ioaddr + ESDHC_VENDOR_SPEC); in esdhc_writel_le()
614 if (imx_data->multiblock_status == MULTIBLK_IN_PROCESS) in esdhc_writel_le()
619 writel(data, host->ioaddr + SDHCI_TRANSFER_MODE); in esdhc_writel_le()
620 imx_data->multiblock_status = WAIT_FOR_INT; in esdhc_writel_le()
624 writel(val, host->ioaddr + reg); in esdhc_writel_le()
646 val = readl(host->ioaddr + ESDHC_VENDOR_SPEC); in esdhc_readw_le()
651 if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) in esdhc_readw_le()
652 val = readl(host->ioaddr + ESDHC_MIX_CTRL); in esdhc_readw_le()
653 else if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING) in esdhc_readw_le()
655 val = readl(host->ioaddr + SDHCI_AUTO_CMD_STATUS); in esdhc_readw_le()
670 u32 m = readl(host->ioaddr + ESDHC_MIX_CTRL); in esdhc_readw_le()
678 ret = readw(host->ioaddr + SDHCI_TRANSFER_MODE); in esdhc_readw_le()
684 return readw(host->ioaddr + reg); in esdhc_readw_le()
695 new_val = readl(host->ioaddr + ESDHC_VENDOR_SPEC); in esdhc_writew_le()
700 writel(new_val, host->ioaddr + ESDHC_VENDOR_SPEC); in esdhc_writew_le()
705 new_val = readl(host->ioaddr + ESDHC_VENDOR_SPEC); in esdhc_writew_le()
710 writel(new_val, host->ioaddr + ESDHC_VENDOR_SPEC); in esdhc_writew_le()
711 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING) { in esdhc_writew_le()
712 u32 v = readl(host->ioaddr + SDHCI_AUTO_CMD_STATUS); in esdhc_writew_le()
713 u32 m = readl(host->ioaddr + ESDHC_MIX_CTRL); in esdhc_writew_le()
728 writel(v, host->ioaddr + SDHCI_AUTO_CMD_STATUS); in esdhc_writew_le()
729 writel(m, host->ioaddr + ESDHC_MIX_CTRL); in esdhc_writew_le()
733 if ((imx_data->socdata->flags & ESDHC_FLAG_MULTIBLK_NO_INT) in esdhc_writew_le()
734 && (host->cmd->opcode == SD_IO_RW_EXTENDED) in esdhc_writew_le()
735 && (host->cmd->data->blocks > 1) in esdhc_writew_le()
736 && (host->cmd->data->flags & MMC_DATA_READ)) { in esdhc_writew_le()
738 v = readl(host->ioaddr + ESDHC_VENDOR_SPEC); in esdhc_writew_le()
740 writel(v, host->ioaddr + ESDHC_VENDOR_SPEC); in esdhc_writew_le()
745 u32 m = readl(host->ioaddr + ESDHC_MIX_CTRL); in esdhc_writew_le()
752 writel(m, host->ioaddr + ESDHC_MIX_CTRL); in esdhc_writew_le()
758 m = readl(host->ioaddr + ESDHC_WTMK_LVL); in esdhc_writew_le()
781 writel(m, host->ioaddr + ESDHC_WTMK_LVL); in esdhc_writew_le()
787 imx_data->scratchpad = val; in esdhc_writew_le()
791 if (host->cmd->opcode == MMC_STOP_TRANSMISSION) in esdhc_writew_le()
794 if ((host->cmd->opcode == MMC_SET_BLOCK_COUNT) && in esdhc_writew_le()
795 (imx_data->socdata->flags & ESDHC_FLAG_MULTIBLK_NO_INT)) in esdhc_writew_le()
796 imx_data->multiblock_status = MULTIBLK_IN_PROCESS; in esdhc_writew_le()
800 host->ioaddr + SDHCI_TRANSFER_MODE); in esdhc_writew_le()
802 writel(val << 16 | imx_data->scratchpad, in esdhc_writew_le()
803 host->ioaddr + SDHCI_TRANSFER_MODE); in esdhc_writew_le()
819 val = readl(host->ioaddr + reg); in esdhc_readb_le()
828 return readb(host->ioaddr + reg); in esdhc_readb_le()
868 new_val = readl(host->ioaddr + SDHCI_HOST_CONTROL); in esdhc_writeb_le()
893 new_val = readl(host->ioaddr + ESDHC_MIX_CTRL); in esdhc_writeb_le()
895 host->ioaddr + ESDHC_MIX_CTRL); in esdhc_writeb_le()
896 imx_data->is_ddr = 0; in esdhc_writeb_le()
914 return pltfm_host->clock; in esdhc_pltfm_get_max_clock()
921 return pltfm_host->clock / 256 / 16; in esdhc_pltfm_get_min_clock()
929 unsigned int host_clock = pltfm_host->clock; in esdhc_pltfm_set_clock()
930 int ddr_pre_div = imx_data->is_ddr ? 2 : 1; in esdhc_pltfm_set_clock()
937 val = readl(host->ioaddr + ESDHC_VENDOR_SPEC); in esdhc_pltfm_set_clock()
939 host->ioaddr + ESDHC_VENDOR_SPEC); in esdhc_pltfm_set_clock()
944 host->mmc->actual_clock = 0; in esdhc_pltfm_set_clock()
954 val = readl(host->ioaddr + ESDHC_DLL_CTRL); in esdhc_pltfm_set_clock()
955 writel(val | BIT(10), host->ioaddr + ESDHC_DLL_CTRL); in esdhc_pltfm_set_clock()
956 temp = readl(host->ioaddr + ESDHC_DLL_CTRL); in esdhc_pltfm_set_clock()
957 writel(val, host->ioaddr + ESDHC_DLL_CTRL); in esdhc_pltfm_set_clock()
967 if ((imx_data->socdata->flags & ESDHC_FLAG_ERR010450) && in esdhc_pltfm_set_clock()
968 (!(host->quirks2 & SDHCI_QUIRK2_NO_1_8_V))) { in esdhc_pltfm_set_clock()
971 max_clock = imx_data->is_ddr ? 45000000 : 150000000; in esdhc_pltfm_set_clock()
983 host->mmc->actual_clock = host_clock / (div * pre_div * ddr_pre_div); in esdhc_pltfm_set_clock()
984 dev_dbg(mmc_dev(host->mmc), "desired SD clock: %d, actual: %d\n", in esdhc_pltfm_set_clock()
985 clock, host->mmc->actual_clock); in esdhc_pltfm_set_clock()
988 div--; in esdhc_pltfm_set_clock()
997 ret = readl_poll_timeout(host->ioaddr + ESDHC_PRSSTAT, temp, in esdhc_pltfm_set_clock()
999 if (ret == -ETIMEDOUT) in esdhc_pltfm_set_clock()
1000 dev_warn(mmc_dev(host->mmc), "card clock still not stable in 100us!.\n"); in esdhc_pltfm_set_clock()
1003 val = readl(host->ioaddr + ESDHC_VENDOR_SPEC); in esdhc_pltfm_set_clock()
1005 host->ioaddr + ESDHC_VENDOR_SPEC); in esdhc_pltfm_set_clock()
1014 struct esdhc_platform_data *boarddata = &imx_data->boarddata; in esdhc_pltfm_get_ro()
1016 switch (boarddata->wp_type) { in esdhc_pltfm_get_ro()
1018 return mmc_gpio_get_ro(host->mmc); in esdhc_pltfm_get_ro()
1020 return !(readl(host->ioaddr + SDHCI_PRESENT_STATE) & in esdhc_pltfm_get_ro()
1026 return -ENOSYS; in esdhc_pltfm_get_ro()
1058 ctrl = readl(host->ioaddr + ESDHC_MIX_CTRL); in esdhc_reset_tuning()
1060 if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) { in esdhc_reset_tuning()
1063 writel(ctrl, host->ioaddr + ESDHC_MIX_CTRL); in esdhc_reset_tuning()
1064 writel(0, host->ioaddr + ESDHC_TUNE_CTRL_STATUS); in esdhc_reset_tuning()
1065 } else if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING) { in esdhc_reset_tuning()
1066 writel(ctrl, host->ioaddr + ESDHC_MIX_CTRL); in esdhc_reset_tuning()
1067 ctrl = readl(host->ioaddr + SDHCI_AUTO_CMD_STATUS); in esdhc_reset_tuning()
1070 writel(ctrl, host->ioaddr + SDHCI_AUTO_CMD_STATUS); in esdhc_reset_tuning()
1072 ret = readl_poll_timeout(host->ioaddr + SDHCI_AUTO_CMD_STATUS, in esdhc_reset_tuning()
1074 if (ret == -ETIMEDOUT) in esdhc_reset_tuning()
1075 dev_warn(mmc_dev(host->mmc), in esdhc_reset_tuning()
1082 ctrl = readl(host->ioaddr + SDHCI_INT_STATUS); in esdhc_reset_tuning()
1084 writel(ctrl, host->ioaddr + SDHCI_INT_STATUS); in esdhc_reset_tuning()
1095 imx_data->init_card_type = card->type; in usdhc_init_card()
1107 if (host->timing == MMC_TIMING_UHS_DDR50) in usdhc_execute_tuning()
1113 * correct delay cell. in usdhc_execute_tuning()
1118 if (!err && !host->tuning_err) in usdhc_execute_tuning()
1130 /* FIXME: delay a bit for card to be ready for next tuning due to errors */ in esdhc_prepare_tuning()
1135 ret = readb_poll_timeout(host->ioaddr + SDHCI_SOFTWARE_RESET, sw_rst, in esdhc_prepare_tuning()
1137 if (ret == -ETIMEDOUT) in esdhc_prepare_tuning()
1138 dev_warn(mmc_dev(host->mmc), in esdhc_prepare_tuning()
1141 reg = readl(host->ioaddr + ESDHC_MIX_CTRL); in esdhc_prepare_tuning()
1144 writel(reg, host->ioaddr + ESDHC_MIX_CTRL); in esdhc_prepare_tuning()
1145 writel(val << 8, host->ioaddr + ESDHC_TUNE_CTRL_STATUS); in esdhc_prepare_tuning()
1146 dev_dbg(mmc_dev(host->mmc), in esdhc_prepare_tuning()
1147 "tuning with delay 0x%x ESDHC_TUNE_CTRL_STATUS 0x%x\n", in esdhc_prepare_tuning()
1148 val, readl(host->ioaddr + ESDHC_TUNE_CTRL_STATUS)); in esdhc_prepare_tuning()
1155 reg = readl(host->ioaddr + ESDHC_MIX_CTRL); in esdhc_post_tuning()
1157 writel(reg, host->ioaddr + ESDHC_MIX_CTRL); in esdhc_post_tuning()
1161 * find the largest pass window, and use the average delay of this
1173 /* find the mininum delay first which can pass tuning */ in esdhc_executing_tuning()
1176 if (!mmc_send_tuning(host->mmc, opcode, NULL)) in esdhc_executing_tuning()
1181 /* find the maxinum delay which can not pass tuning */ in esdhc_executing_tuning()
1185 if (mmc_send_tuning(host->mmc, opcode, NULL)) { in esdhc_executing_tuning()
1186 max -= ESDHC_TUNE_CTRL_STEP; in esdhc_executing_tuning()
1192 win_length = max - min + 1; in esdhc_executing_tuning()
1204 /* use average delay to get the best timing */ in esdhc_executing_tuning()
1207 ret = mmc_send_tuning(host->mmc, opcode, NULL); in esdhc_executing_tuning()
1210 dev_dbg(mmc_dev(host->mmc), "tuning %s at 0x%x ret %d\n", in esdhc_executing_tuning()
1221 m = readl(host->ioaddr + ESDHC_MIX_CTRL); in esdhc_hs400_enhanced_strobe()
1222 if (ios->enhanced_strobe) in esdhc_hs400_enhanced_strobe()
1226 writel(m, host->ioaddr + ESDHC_MIX_CTRL); in esdhc_hs400_enhanced_strobe()
1236 dev_dbg(mmc_dev(host->mmc), "change pinctrl state for uhs %d\n", uhs); in esdhc_change_pinstate()
1238 if (IS_ERR(imx_data->pinctrl) || in esdhc_change_pinstate()
1239 IS_ERR(imx_data->pins_100mhz) || in esdhc_change_pinstate()
1240 IS_ERR(imx_data->pins_200mhz)) in esdhc_change_pinstate()
1241 return -EINVAL; in esdhc_change_pinstate()
1246 pinctrl = imx_data->pins_100mhz; in esdhc_change_pinstate()
1251 pinctrl = imx_data->pins_200mhz; in esdhc_change_pinstate()
1255 return pinctrl_select_default_state(mmc_dev(host->mmc)); in esdhc_change_pinstate()
1258 return pinctrl_select_state(imx_data->pinctrl, pinctrl); in esdhc_change_pinstate()
1266 * edge of data_strobe line. Due to the time delay between CLK line and
1267 * data_strobe line, if the delay time is larger than one clock cycle,
1278 /* disable clock before enabling strobe dll */ in esdhc_set_strobe_dll()
1279 writel(readl(host->ioaddr + ESDHC_VENDOR_SPEC) & in esdhc_set_strobe_dll()
1281 host->ioaddr + ESDHC_VENDOR_SPEC); in esdhc_set_strobe_dll()
1284 /* force a reset on strobe dll */ in esdhc_set_strobe_dll()
1286 host->ioaddr + ESDHC_STROBE_DLL_CTRL); in esdhc_set_strobe_dll()
1287 /* clear the reset bit on strobe dll before any setting */ in esdhc_set_strobe_dll()
1288 writel(0, host->ioaddr + ESDHC_STROBE_DLL_CTRL); in esdhc_set_strobe_dll()
1291 * enable strobe dll ctrl and adjust the delay target in esdhc_set_strobe_dll()
1294 if (imx_data->boarddata.strobe_dll_delay_target) in esdhc_set_strobe_dll()
1295 strobe_delay = imx_data->boarddata.strobe_dll_delay_target; in esdhc_set_strobe_dll()
1301 writel(v, host->ioaddr + ESDHC_STROBE_DLL_CTRL); in esdhc_set_strobe_dll()
1304 ret = readl_poll_timeout(host->ioaddr + ESDHC_STROBE_DLL_STATUS, v, in esdhc_set_strobe_dll()
1306 if (ret == -ETIMEDOUT) in esdhc_set_strobe_dll()
1307 dev_warn(mmc_dev(host->mmc), in esdhc_set_strobe_dll()
1308 "warning! HS400 strobe DLL status REF/SLV not lock in 50us, STROBE DLL status is %x!\n", v); in esdhc_set_strobe_dll()
1316 struct esdhc_platform_data *boarddata = &imx_data->boarddata; in esdhc_set_uhs_signaling()
1319 m = readl(host->ioaddr + ESDHC_MIX_CTRL); in esdhc_set_uhs_signaling()
1321 imx_data->is_ddr = 0; in esdhc_set_uhs_signaling()
1330 writel(m, host->ioaddr + ESDHC_MIX_CTRL); in esdhc_set_uhs_signaling()
1335 writel(m, host->ioaddr + ESDHC_MIX_CTRL); in esdhc_set_uhs_signaling()
1336 imx_data->is_ddr = 1; in esdhc_set_uhs_signaling()
1337 if (boarddata->delay_line) { in esdhc_set_uhs_signaling()
1339 v = boarddata->delay_line << in esdhc_set_uhs_signaling()
1344 writel(v, host->ioaddr + ESDHC_DLL_CTRL); in esdhc_set_uhs_signaling()
1349 writel(m, host->ioaddr + ESDHC_MIX_CTRL); in esdhc_set_uhs_signaling()
1350 imx_data->is_ddr = 1; in esdhc_set_uhs_signaling()
1351 /* update clock after enable DDR for strobe DLL lock */ in esdhc_set_uhs_signaling()
1352 host->ops->set_clock(host, host->clock); in esdhc_set_uhs_signaling()
1368 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in esdhc_reset()
1369 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in esdhc_reset()
1400 cqhci_irq(host->mmc, intmask, cmd_error, data_error); in esdhc_cqhci_irq()
1437 struct cqhci_host *cq_host = host->mmc->cqe_private; in sdhci_esdhc_imx_hwinit()
1445 writel(ESDHC_WTMK_DEFAULT_VAL, host->ioaddr + ESDHC_WTMK_LVL); in sdhci_esdhc_imx_hwinit()
1458 writel(readl(host->ioaddr + SDHCI_HOST_CONTROL) in sdhci_esdhc_imx_hwinit()
1460 host->ioaddr + SDHCI_HOST_CONTROL); in sdhci_esdhc_imx_hwinit()
1466 if (!(imx_data->socdata->flags & ESDHC_FLAG_SKIP_ERR004536)) { in sdhci_esdhc_imx_hwinit()
1467 writel(readl(host->ioaddr + 0x6c) & ~BIT(7), in sdhci_esdhc_imx_hwinit()
1468 host->ioaddr + 0x6c); in sdhci_esdhc_imx_hwinit()
1471 /* disable DLL_CTRL delay line settings */ in sdhci_esdhc_imx_hwinit()
1472 writel(0x0, host->ioaddr + ESDHC_DLL_CTRL); in sdhci_esdhc_imx_hwinit()
1483 if (imx_data->socdata->flags & ESDHC_FLAG_CQHCI) { in sdhci_esdhc_imx_hwinit()
1484 tmp = readl(host->ioaddr + ESDHC_VEND_SPEC2); in sdhci_esdhc_imx_hwinit()
1486 writel(tmp, host->ioaddr + ESDHC_VEND_SPEC2); in sdhci_esdhc_imx_hwinit()
1488 host->quirks &= ~SDHCI_QUIRK_NO_BUSY_IRQ; in sdhci_esdhc_imx_hwinit()
1491 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING) { in sdhci_esdhc_imx_hwinit()
1492 tmp = readl(host->ioaddr + ESDHC_TUNING_CTRL); in sdhci_esdhc_imx_hwinit()
1500 if (imx_data->boarddata.tuning_start_tap) in sdhci_esdhc_imx_hwinit()
1501 tmp |= imx_data->boarddata.tuning_start_tap; in sdhci_esdhc_imx_hwinit()
1505 if (imx_data->boarddata.tuning_step) { in sdhci_esdhc_imx_hwinit()
1506 tmp |= imx_data->boarddata.tuning_step in sdhci_esdhc_imx_hwinit()
1514 * add some delay after every tuning command, because in sdhci_esdhc_imx_hwinit()
1524 writel(tmp, host->ioaddr + ESDHC_TUNING_CTRL); in sdhci_esdhc_imx_hwinit()
1525 } else if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) { in sdhci_esdhc_imx_hwinit()
1531 tmp = readl(host->ioaddr + ESDHC_TUNING_CTRL); in sdhci_esdhc_imx_hwinit()
1533 writel(tmp, host->ioaddr + ESDHC_TUNING_CTRL); in sdhci_esdhc_imx_hwinit()
1556 struct cqhci_host *cq_host = mmc->cqe_private; in esdhc_cqe_enable()
1569 if (count-- == 0) { in esdhc_cqe_enable()
1570 dev_warn(mmc_dev(host->mmc), in esdhc_cqe_enable()
1583 if (host->flags & SDHCI_REQ_USE_DMA) in esdhc_cqe_enable()
1585 if (!(host->quirks2 & SDHCI_QUIRK2_SUPPORT_SINGLE)) in esdhc_cqe_enable()
1597 dev_err(mmc_dev(host->mmc), in esdhc_cqe_enable()
1620 struct device_node *np = pdev->dev.of_node; in sdhci_esdhc_imx_probe_dt()
1621 struct esdhc_platform_data *boarddata = &imx_data->boarddata; in sdhci_esdhc_imx_probe_dt()
1624 if (of_property_read_bool(np, "fsl,wp-controller")) in sdhci_esdhc_imx_probe_dt()
1625 boarddata->wp_type = ESDHC_WP_CONTROLLER; in sdhci_esdhc_imx_probe_dt()
1632 if (of_property_read_bool(np, "wp-gpios")) in sdhci_esdhc_imx_probe_dt()
1633 boarddata->wp_type = ESDHC_WP_GPIO; in sdhci_esdhc_imx_probe_dt()
1635 of_property_read_u32(np, "fsl,tuning-step", &boarddata->tuning_step); in sdhci_esdhc_imx_probe_dt()
1636 of_property_read_u32(np, "fsl,tuning-start-tap", in sdhci_esdhc_imx_probe_dt()
1637 &boarddata->tuning_start_tap); in sdhci_esdhc_imx_probe_dt()
1639 of_property_read_u32(np, "fsl,strobe-dll-delay-target", in sdhci_esdhc_imx_probe_dt()
1640 &boarddata->strobe_dll_delay_target); in sdhci_esdhc_imx_probe_dt()
1641 if (of_property_read_bool(np, "no-1-8-v")) in sdhci_esdhc_imx_probe_dt()
1642 host->quirks2 |= SDHCI_QUIRK2_NO_1_8_V; in sdhci_esdhc_imx_probe_dt()
1644 if (of_property_read_u32(np, "fsl,delay-line", &boarddata->delay_line)) in sdhci_esdhc_imx_probe_dt()
1645 boarddata->delay_line = 0; in sdhci_esdhc_imx_probe_dt()
1647 mmc_of_parse_voltage(host->mmc, &host->ocr_mask); in sdhci_esdhc_imx_probe_dt()
1649 if (esdhc_is_usdhc(imx_data) && !IS_ERR(imx_data->pinctrl)) { in sdhci_esdhc_imx_probe_dt()
1650 imx_data->pins_100mhz = pinctrl_lookup_state(imx_data->pinctrl, in sdhci_esdhc_imx_probe_dt()
1652 imx_data->pins_200mhz = pinctrl_lookup_state(imx_data->pinctrl, in sdhci_esdhc_imx_probe_dt()
1657 ret = mmc_of_parse(host->mmc); in sdhci_esdhc_imx_probe_dt()
1662 if (!(host->mmc->caps & MMC_CAP_8_BIT_DATA)) in sdhci_esdhc_imx_probe_dt()
1663 host->mmc->caps2 &= ~(MMC_CAP2_HS400 | MMC_CAP2_HS400_ES); in sdhci_esdhc_imx_probe_dt()
1665 if (mmc_gpio_get_cd(host->mmc) >= 0) in sdhci_esdhc_imx_probe_dt()
1666 host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION; in sdhci_esdhc_imx_probe_dt()
1688 imx_data->socdata = device_get_match_data(&pdev->dev); in sdhci_esdhc_imx_probe()
1690 if (imx_data->socdata->flags & ESDHC_FLAG_PMQOS) in sdhci_esdhc_imx_probe()
1691 cpu_latency_qos_add_request(&imx_data->pm_qos_req, 0); in sdhci_esdhc_imx_probe()
1693 imx_data->clk_ipg = devm_clk_get(&pdev->dev, "ipg"); in sdhci_esdhc_imx_probe()
1694 if (IS_ERR(imx_data->clk_ipg)) { in sdhci_esdhc_imx_probe()
1695 err = PTR_ERR(imx_data->clk_ipg); in sdhci_esdhc_imx_probe()
1699 imx_data->clk_ahb = devm_clk_get(&pdev->dev, "ahb"); in sdhci_esdhc_imx_probe()
1700 if (IS_ERR(imx_data->clk_ahb)) { in sdhci_esdhc_imx_probe()
1701 err = PTR_ERR(imx_data->clk_ahb); in sdhci_esdhc_imx_probe()
1705 imx_data->clk_per = devm_clk_get(&pdev->dev, "per"); in sdhci_esdhc_imx_probe()
1706 if (IS_ERR(imx_data->clk_per)) { in sdhci_esdhc_imx_probe()
1707 err = PTR_ERR(imx_data->clk_per); in sdhci_esdhc_imx_probe()
1711 pltfm_host->clk = imx_data->clk_per; in sdhci_esdhc_imx_probe()
1712 err = clk_prepare_enable(imx_data->clk_per); in sdhci_esdhc_imx_probe()
1715 err = clk_prepare_enable(imx_data->clk_ipg); in sdhci_esdhc_imx_probe()
1718 err = clk_prepare_enable(imx_data->clk_ahb); in sdhci_esdhc_imx_probe()
1722 pltfm_host->clock = clk_get_rate(pltfm_host->clk); in sdhci_esdhc_imx_probe()
1723 if (!pltfm_host->clock) { in sdhci_esdhc_imx_probe()
1724 dev_err(mmc_dev(host->mmc), "could not get clk rate\n"); in sdhci_esdhc_imx_probe()
1725 err = -EINVAL; in sdhci_esdhc_imx_probe()
1729 imx_data->pinctrl = devm_pinctrl_get(&pdev->dev); in sdhci_esdhc_imx_probe()
1730 if (IS_ERR(imx_data->pinctrl)) in sdhci_esdhc_imx_probe()
1731 dev_warn(mmc_dev(host->mmc), "could not get pinctrl\n"); in sdhci_esdhc_imx_probe()
1734 host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN; in sdhci_esdhc_imx_probe()
1735 host->mmc->caps |= MMC_CAP_1_8V_DDR | MMC_CAP_3_3V_DDR; in sdhci_esdhc_imx_probe()
1738 if (!(imx_data->socdata->flags & ESDHC_FLAG_SKIP_CD_WAKE)) in sdhci_esdhc_imx_probe()
1739 host->mmc->caps |= MMC_CAP_CD_WAKE; in sdhci_esdhc_imx_probe()
1741 if (!(imx_data->socdata->flags & ESDHC_FLAG_HS200)) in sdhci_esdhc_imx_probe()
1742 host->quirks2 |= SDHCI_QUIRK2_BROKEN_HS200; in sdhci_esdhc_imx_probe()
1745 writel(0x0, host->ioaddr + ESDHC_MIX_CTRL); in sdhci_esdhc_imx_probe()
1746 writel(0x0, host->ioaddr + SDHCI_AUTO_CMD_STATUS); in sdhci_esdhc_imx_probe()
1747 writel(0x0, host->ioaddr + ESDHC_TUNE_CTRL_STATUS); in sdhci_esdhc_imx_probe()
1753 host->mmc_host_ops.execute_tuning = usdhc_execute_tuning; in sdhci_esdhc_imx_probe()
1759 host->mmc_host_ops.init_card = usdhc_init_card; in sdhci_esdhc_imx_probe()
1762 if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) in sdhci_esdhc_imx_probe()
1766 if (imx_data->socdata->flags & ESDHC_FLAG_ERR004536) in sdhci_esdhc_imx_probe()
1767 host->quirks |= SDHCI_QUIRK_BROKEN_ADMA; in sdhci_esdhc_imx_probe()
1769 if (imx_data->socdata->flags & ESDHC_FLAG_HS400) in sdhci_esdhc_imx_probe()
1770 host->mmc->caps2 |= MMC_CAP2_HS400; in sdhci_esdhc_imx_probe()
1772 if (imx_data->socdata->flags & ESDHC_FLAG_BROKEN_AUTO_CMD23) in sdhci_esdhc_imx_probe()
1773 host->quirks2 |= SDHCI_QUIRK2_ACMD23_BROKEN; in sdhci_esdhc_imx_probe()
1775 if (imx_data->socdata->flags & ESDHC_FLAG_HS400_ES) { in sdhci_esdhc_imx_probe()
1776 host->mmc->caps2 |= MMC_CAP2_HS400_ES; in sdhci_esdhc_imx_probe()
1777 host->mmc_host_ops.hs400_enhanced_strobe = in sdhci_esdhc_imx_probe()
1781 if (imx_data->socdata->flags & ESDHC_FLAG_CQHCI) { in sdhci_esdhc_imx_probe()
1782 host->mmc->caps2 |= MMC_CAP2_CQE | MMC_CAP2_CQE_DCMD; in sdhci_esdhc_imx_probe()
1783 cq_host = devm_kzalloc(&pdev->dev, sizeof(*cq_host), GFP_KERNEL); in sdhci_esdhc_imx_probe()
1785 err = -ENOMEM; in sdhci_esdhc_imx_probe()
1789 cq_host->mmio = host->ioaddr + ESDHC_CQHCI_ADDR_OFFSET; in sdhci_esdhc_imx_probe()
1790 cq_host->ops = &esdhc_cqhci_ops; in sdhci_esdhc_imx_probe()
1792 err = cqhci_init(cq_host, host->mmc, false); in sdhci_esdhc_imx_probe()
1811 if ((host->mmc->pm_caps & MMC_PM_KEEP_POWER) && in sdhci_esdhc_imx_probe()
1812 (host->mmc->pm_caps & MMC_PM_WAKE_SDIO_IRQ)) in sdhci_esdhc_imx_probe()
1813 device_set_wakeup_capable(&pdev->dev, true); in sdhci_esdhc_imx_probe()
1815 pm_runtime_set_active(&pdev->dev); in sdhci_esdhc_imx_probe()
1816 pm_runtime_set_autosuspend_delay(&pdev->dev, 50); in sdhci_esdhc_imx_probe()
1817 pm_runtime_use_autosuspend(&pdev->dev); in sdhci_esdhc_imx_probe()
1818 pm_suspend_ignore_children(&pdev->dev, 1); in sdhci_esdhc_imx_probe()
1819 pm_runtime_enable(&pdev->dev); in sdhci_esdhc_imx_probe()
1824 clk_disable_unprepare(imx_data->clk_ahb); in sdhci_esdhc_imx_probe()
1826 clk_disable_unprepare(imx_data->clk_ipg); in sdhci_esdhc_imx_probe()
1828 clk_disable_unprepare(imx_data->clk_per); in sdhci_esdhc_imx_probe()
1830 if (imx_data->socdata->flags & ESDHC_FLAG_PMQOS) in sdhci_esdhc_imx_probe()
1831 cpu_latency_qos_remove_request(&imx_data->pm_qos_req); in sdhci_esdhc_imx_probe()
1843 pm_runtime_get_sync(&pdev->dev); in sdhci_esdhc_imx_remove()
1844 dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff); in sdhci_esdhc_imx_remove()
1845 pm_runtime_disable(&pdev->dev); in sdhci_esdhc_imx_remove()
1846 pm_runtime_put_noidle(&pdev->dev); in sdhci_esdhc_imx_remove()
1850 clk_disable_unprepare(imx_data->clk_per); in sdhci_esdhc_imx_remove()
1851 clk_disable_unprepare(imx_data->clk_ipg); in sdhci_esdhc_imx_remove()
1852 clk_disable_unprepare(imx_data->clk_ahb); in sdhci_esdhc_imx_remove()
1854 if (imx_data->socdata->flags & ESDHC_FLAG_PMQOS) in sdhci_esdhc_imx_remove()
1855 cpu_latency_qos_remove_request(&imx_data->pm_qos_req); in sdhci_esdhc_imx_remove()
1868 if (host->mmc->caps2 & MMC_CAP2_CQE) { in sdhci_esdhc_suspend()
1869 ret = cqhci_suspend(host->mmc); in sdhci_esdhc_suspend()
1874 if ((imx_data->socdata->flags & ESDHC_FLAG_STATE_LOST_IN_LPMODE) && in sdhci_esdhc_suspend()
1875 (host->tuning_mode != SDHCI_TUNING_MODE_1)) { in sdhci_esdhc_suspend()
1876 mmc_retune_timer_stop(host->mmc); in sdhci_esdhc_suspend()
1877 mmc_retune_needed(host->mmc); in sdhci_esdhc_suspend()
1880 if (host->tuning_mode != SDHCI_TUNING_MODE_3) in sdhci_esdhc_suspend()
1881 mmc_retune_needed(host->mmc); in sdhci_esdhc_suspend()
1891 ret = mmc_gpio_set_cd_wake(host->mmc, true); in sdhci_esdhc_suspend()
1905 /* re-initialize hw state in case it's lost in low power mode */ in sdhci_esdhc_resume()
1912 if (host->mmc->caps2 & MMC_CAP2_CQE) in sdhci_esdhc_resume()
1913 ret = cqhci_resume(host->mmc); in sdhci_esdhc_resume()
1916 ret = mmc_gpio_set_cd_wake(host->mmc, false); in sdhci_esdhc_resume()
1930 if (host->mmc->caps2 & MMC_CAP2_CQE) { in sdhci_esdhc_runtime_suspend()
1931 ret = cqhci_suspend(host->mmc); in sdhci_esdhc_runtime_suspend()
1940 if (host->tuning_mode != SDHCI_TUNING_MODE_3) in sdhci_esdhc_runtime_suspend()
1941 mmc_retune_needed(host->mmc); in sdhci_esdhc_runtime_suspend()
1943 imx_data->actual_clock = host->mmc->actual_clock; in sdhci_esdhc_runtime_suspend()
1945 clk_disable_unprepare(imx_data->clk_per); in sdhci_esdhc_runtime_suspend()
1946 clk_disable_unprepare(imx_data->clk_ipg); in sdhci_esdhc_runtime_suspend()
1947 clk_disable_unprepare(imx_data->clk_ahb); in sdhci_esdhc_runtime_suspend()
1949 if (imx_data->socdata->flags & ESDHC_FLAG_PMQOS) in sdhci_esdhc_runtime_suspend()
1950 cpu_latency_qos_remove_request(&imx_data->pm_qos_req); in sdhci_esdhc_runtime_suspend()
1962 if (imx_data->socdata->flags & ESDHC_FLAG_PMQOS) in sdhci_esdhc_runtime_resume()
1963 cpu_latency_qos_add_request(&imx_data->pm_qos_req, 0); in sdhci_esdhc_runtime_resume()
1965 if (imx_data->socdata->flags & ESDHC_FLAG_CLK_RATE_LOST_IN_PM_RUNTIME) in sdhci_esdhc_runtime_resume()
1966 clk_set_rate(imx_data->clk_per, pltfm_host->clock); in sdhci_esdhc_runtime_resume()
1968 err = clk_prepare_enable(imx_data->clk_ahb); in sdhci_esdhc_runtime_resume()
1972 err = clk_prepare_enable(imx_data->clk_per); in sdhci_esdhc_runtime_resume()
1976 err = clk_prepare_enable(imx_data->clk_ipg); in sdhci_esdhc_runtime_resume()
1980 esdhc_pltfm_set_clock(host, imx_data->actual_clock); in sdhci_esdhc_runtime_resume()
1986 if (host->mmc->caps2 & MMC_CAP2_CQE) in sdhci_esdhc_runtime_resume()
1987 err = cqhci_resume(host->mmc); in sdhci_esdhc_runtime_resume()
1992 clk_disable_unprepare(imx_data->clk_ipg); in sdhci_esdhc_runtime_resume()
1994 clk_disable_unprepare(imx_data->clk_per); in sdhci_esdhc_runtime_resume()
1996 clk_disable_unprepare(imx_data->clk_ahb); in sdhci_esdhc_runtime_resume()
1998 if (imx_data->socdata->flags & ESDHC_FLAG_PMQOS) in sdhci_esdhc_runtime_resume()
1999 cpu_latency_qos_remove_request(&imx_data->pm_qos_req); in sdhci_esdhc_runtime_resume()
2012 .name = "sdhci-esdhc-imx",