fix(ufs): disables controller if enabled

ufs controller needs to be disabled if already enabled, without
this we noticed a crash at linkstartup during reinit

Signed-off-by: anans <anans@google.com>
Change-Id: I523c5d57c1d34f6404a6368ee3f364fbffd2e542
This commit is contained in:
anans 2022-03-21 09:59:18 +05:30 committed by Anand Saminathan
parent 50593e696e
commit b3f03b2013
2 changed files with 34 additions and 0 deletions

View File

@ -146,11 +146,43 @@ static int ufshc_hce_enable(uintptr_t base)
return 0;
}
static int ufshc_hce_disable(uintptr_t base)
{
unsigned int data;
int timeout;
/* Disable Host Controller */
mmio_write_32(base + HCE, HCE_DISABLE);
timeout = HCE_DISABLE_TIMEOUT_US;
do {
data = mmio_read_32(base + HCE);
if ((data & HCE_ENABLE) == HCE_DISABLE) {
break;
}
udelay(1);
} while (--timeout > 0);
if (timeout <= 0) {
return -ETIMEDOUT;
}
return 0;
}
static int ufshc_reset(uintptr_t base)
{
unsigned int data;
int retries, result;
/* disable controller if enabled */
if (mmio_read_32(base + HCE) & HCE_ENABLE) {
result = ufshc_hce_disable(base);
if (result != 0) {
return -EIO;
}
}
for (retries = 0; retries < HCE_ENABLE_OUTER_RETRIES; ++retries) {
result = ufshc_hce_enable(base);
if (result == 0) {

View File

@ -69,6 +69,7 @@
/* Host Controller Enable */
#define HCE 0x34
#define HCE_ENABLE 1
#define HCE_DISABLE 0
/* Host UIC Error Code PHY Adapter Layer */
#define UECPA 0x38
@ -264,6 +265,7 @@
#define HCE_ENABLE_OUTER_RETRIES 3
#define HCE_ENABLE_INNER_RETRIES 50
#define HCE_ENABLE_TIMEOUT_US 100
#define HCE_DISABLE_TIMEOUT_US 1000
#define FDEVICEINIT_TIMEOUT_MS 1500