Browse Source

Merge changes Iaf21883b,I523c5d57,I57164923 into integration

* changes:
  fix(ufs): read and write attribute based on spec
  fix(ufs): disables controller if enabled
  refactor(ufs): adds a function for fdeviceinit
pull/1985/head
Manish Pandey 3 years ago
committed by TrustedFirmware Code Review
parent
commit
efceb6bead
  1. 71
      drivers/ufs/ufs.c
  2. 4
      include/drivers/ufs.h

71
drivers/ufs/ufs.c

@ -146,11 +146,43 @@ static int ufshc_hce_enable(uintptr_t base)
return 0; 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) static int ufshc_reset(uintptr_t base)
{ {
unsigned int data; unsigned int data;
int retries, result; 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) { for (retries = 0; retries < HCE_ENABLE_OUTER_RETRIES; ++retries) {
result = ufshc_hce_enable(base); result = ufshc_hce_enable(base);
if (result == 0) { if (result == 0) {
@ -408,7 +440,7 @@ static int ufs_prepare_query(utp_utrd_t *utrd, uint8_t op, uint8_t idn,
break; break;
case QUERY_WRITE_ATTR: case QUERY_WRITE_ATTR:
query_upiu->query_func = QUERY_FUNC_STD_WRITE; query_upiu->query_func = QUERY_FUNC_STD_WRITE;
memcpy((void *)&query_upiu->ts.attr.value, (void *)buf, length); query_upiu->ts.attr.value = htobe32(*((uint32_t *)buf));
break; break;
default: default:
assert(0); assert(0);
@ -594,12 +626,14 @@ static void ufs_query(uint8_t op, uint8_t idn, uint8_t index, uint8_t sel,
case QUERY_READ_FLAG: case QUERY_READ_FLAG:
*(uint32_t *)buf = (uint32_t)resp->ts.flag.value; *(uint32_t *)buf = (uint32_t)resp->ts.flag.value;
break; break;
case QUERY_READ_ATTR:
case QUERY_READ_DESC: case QUERY_READ_DESC:
memcpy((void *)buf, memcpy((void *)buf,
(void *)(utrd.resp_upiu + sizeof(query_resp_upiu_t)), (void *)(utrd.resp_upiu + sizeof(query_resp_upiu_t)),
size); size);
break; break;
case QUERY_READ_ATTR:
*(uint32_t *)buf = htobe32(resp->ts.attr.value);
break;
default: default:
/* Do nothing in default case */ /* Do nothing in default case */
break; break;
@ -733,16 +767,41 @@ size_t ufs_write_blocks(int lun, int lba, const uintptr_t buf, size_t size)
return size - resp->res_trans_cnt; return size - resp->res_trans_cnt;
} }
static int ufs_set_fdevice_init(void)
{
unsigned int result;
int timeout;
ufs_set_flag(FLAG_DEVICE_INIT);
timeout = FDEVICEINIT_TIMEOUT_MS;
do {
result = ufs_read_flag(FLAG_DEVICE_INIT);
if (!result) {
break;
}
mdelay(5);
timeout -= 5;
} while (timeout > 0);
if (result != 0U) {
return -ETIMEDOUT;
}
return 0;
}
static void ufs_enum(void) static void ufs_enum(void)
{ {
unsigned int blk_num, blk_size; unsigned int blk_num, blk_size;
int i; int i, result;
ufs_verify_init(); ufs_verify_init();
ufs_verify_ready(); ufs_verify_ready();
ufs_set_flag(FLAG_DEVICE_INIT); result = ufs_set_fdevice_init();
mdelay(200); assert(result == 0);
/* dump available LUNs */ /* dump available LUNs */
for (i = 0; i < UFS_MAX_LUNS; i++) { for (i = 0; i < UFS_MAX_LUNS; i++) {
ufs_read_capacity(i, &blk_num, &blk_size); ufs_read_capacity(i, &blk_num, &blk_size);
@ -751,6 +810,8 @@ static void ufs_enum(void)
i, blk_num, blk_size); i, blk_num, blk_size);
} }
} }
(void)result;
} }
static void ufs_get_device_info(struct ufs_dev_desc *card_data) static void ufs_get_device_info(struct ufs_dev_desc *card_data)

4
include/drivers/ufs.h

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

Loading…
Cancel
Save