#include <sdhci.h>
#include <zynqmp_tap_delay.h>
-#define SDHCI_ARASAN_ITAPDLY_REGISTER 0xF0F8
-#define SDHCI_ARASAN_OTAPDLY_REGISTER 0xF0FC
-#define SDHCI_ITAPDLY_CHGWIN 0x200
-#define SDHCI_ITAPDLY_ENABLE 0x100
-#define SDHCI_OTAPDLY_ENABLE 0x40
+#define SDHCI_ARASAN_ITAPDLY_REGISTER 0xF0F8
+#define SDHCI_ARASAN_ITAPDLY_SEL_MASK GENMASK(7, 0)
+#define SDHCI_ARASAN_OTAPDLY_REGISTER 0xF0FC
+#define SDHCI_ARASAN_OTAPDLY_SEL_MASK GENMASK(5, 0)
+#define SDHCI_ITAPDLY_CHGWIN BIT(9)
+#define SDHCI_ITAPDLY_ENABLE BIT(8)
+#define SDHCI_OTAPDLY_ENABLE BIT(6)
#define SDHCI_TUNING_LOOP_COUNT 40
#define MMC_BANK2 0x2
struct mmc *mmc = (struct mmc *)host->mmc;
u8 tap_delay, tap_max = 0;
int timing = mode2timing[mmc->selected_mode];
+ u32 regval;
/*
* This is applicable for SDHCI_SPEC_300 and above
tap_delay = (degrees * tap_max) / 360;
+ /* Limit output tap_delay value to 6 bits */
+ tap_delay &= SDHCI_ARASAN_OTAPDLY_SEL_MASK;
+
/* Set the Clock Phase */
- if (tap_delay) {
- u32 regval;
-
- regval = sdhci_readl(host, SDHCI_ARASAN_OTAPDLY_REGISTER);
- regval |= SDHCI_OTAPDLY_ENABLE;
- sdhci_writel(host, regval, SDHCI_ARASAN_OTAPDLY_REGISTER);
- regval |= tap_delay;
- sdhci_writel(host, regval, SDHCI_ARASAN_OTAPDLY_REGISTER);
- }
+ regval = sdhci_readl(host, SDHCI_ARASAN_OTAPDLY_REGISTER);
+ regval |= SDHCI_OTAPDLY_ENABLE;
+ sdhci_writel(host, regval, SDHCI_ARASAN_OTAPDLY_REGISTER);
+ regval &= ~SDHCI_ARASAN_OTAPDLY_SEL_MASK;
+ regval |= tap_delay;
+ sdhci_writel(host, regval, SDHCI_ARASAN_OTAPDLY_REGISTER);
return 0;
}
struct mmc *mmc = (struct mmc *)host->mmc;
u8 tap_delay, tap_max = 0;
int timing = mode2timing[mmc->selected_mode];
+ u32 regval;
/*
* This is applicable for SDHCI_SPEC_300 and above
tap_delay = (degrees * tap_max) / 360;
+ /* Limit input tap_delay value to 8 bits */
+ tap_delay &= SDHCI_ARASAN_ITAPDLY_SEL_MASK;
+
/* Set the Clock Phase */
- if (tap_delay) {
- u32 regval;
-
- regval = sdhci_readl(host, SDHCI_ARASAN_ITAPDLY_REGISTER);
- regval |= SDHCI_ITAPDLY_CHGWIN;
- sdhci_writel(host, regval, SDHCI_ARASAN_ITAPDLY_REGISTER);
- regval |= SDHCI_ITAPDLY_ENABLE;
- sdhci_writel(host, regval, SDHCI_ARASAN_ITAPDLY_REGISTER);
- regval |= tap_delay;
- sdhci_writel(host, regval, SDHCI_ARASAN_ITAPDLY_REGISTER);
- regval &= ~SDHCI_ITAPDLY_CHGWIN;
- sdhci_writel(host, regval, SDHCI_ARASAN_ITAPDLY_REGISTER);
- }
+ regval = sdhci_readl(host, SDHCI_ARASAN_ITAPDLY_REGISTER);
+ regval |= SDHCI_ITAPDLY_CHGWIN;
+ sdhci_writel(host, regval, SDHCI_ARASAN_ITAPDLY_REGISTER);
+ regval |= SDHCI_ITAPDLY_ENABLE;
+ sdhci_writel(host, regval, SDHCI_ARASAN_ITAPDLY_REGISTER);
+ regval &= ~SDHCI_ARASAN_ITAPDLY_SEL_MASK;
+ regval |= tap_delay;
+ sdhci_writel(host, regval, SDHCI_ARASAN_ITAPDLY_REGISTER);
+ regval &= ~SDHCI_ITAPDLY_CHGWIN;
+ sdhci_writel(host, regval, SDHCI_ARASAN_ITAPDLY_REGISTER);
return 0;
}