Skip to content

Commit 6c1143b

Browse files
avri-altman-sndkmartinkpetersen
authored andcommitted
scsi: ufs: core: Use ufshcd_wait_for_register() in HCE init
The current so called "inner loop" in ufshcd_hba_execute_hce() is open coding ufshcd_wait_for_register(). Replace it by ufshcd_wait_for_register(). This is a code simplification - no functional change. Signed-off-by: Avri Altman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Bart Van Assche <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 10c58d7 commit 6c1143b

File tree

1 file changed

+30
-37
lines changed

1 file changed

+30
-37
lines changed

drivers/ufs/core/ufshcd.c

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4826,51 +4826,44 @@ EXPORT_SYMBOL_GPL(ufshcd_hba_stop);
48264826
*/
48274827
static int ufshcd_hba_execute_hce(struct ufs_hba *hba)
48284828
{
4829-
int retry_outer = 3;
4830-
int retry_inner;
4829+
int retry;
48314830

4832-
start:
4833-
if (ufshcd_is_hba_active(hba))
4834-
/* change controller state to "reset state" */
4835-
ufshcd_hba_stop(hba);
4831+
for (retry = 3; retry > 0; retry--) {
4832+
if (ufshcd_is_hba_active(hba))
4833+
/* change controller state to "reset state" */
4834+
ufshcd_hba_stop(hba);
48364835

4837-
/* UniPro link is disabled at this point */
4838-
ufshcd_set_link_off(hba);
4836+
/* UniPro link is disabled at this point */
4837+
ufshcd_set_link_off(hba);
48394838

4840-
ufshcd_vops_hce_enable_notify(hba, PRE_CHANGE);
4839+
ufshcd_vops_hce_enable_notify(hba, PRE_CHANGE);
48414840

4842-
/* start controller initialization sequence */
4843-
ufshcd_hba_start(hba);
4841+
/* start controller initialization sequence */
4842+
ufshcd_hba_start(hba);
48444843

4845-
/*
4846-
* To initialize a UFS host controller HCE bit must be set to 1.
4847-
* During initialization the HCE bit value changes from 1->0->1.
4848-
* When the host controller completes initialization sequence
4849-
* it sets the value of HCE bit to 1. The same HCE bit is read back
4850-
* to check if the controller has completed initialization sequence.
4851-
* So without this delay the value HCE = 1, set in the previous
4852-
* instruction might be read back.
4853-
* This delay can be changed based on the controller.
4854-
*/
4855-
ufshcd_delay_us(hba->vps->hba_enable_delay_us, 100);
4844+
/*
4845+
* To initialize a UFS host controller HCE bit must be set to 1.
4846+
* During initialization the HCE bit value changes from 1->0->1.
4847+
* When the host controller completes initialization sequence
4848+
* it sets the value of HCE bit to 1. The same HCE bit is read back
4849+
* to check if the controller has completed initialization sequence.
4850+
* So without this delay the value HCE = 1, set in the previous
4851+
* instruction might be read back.
4852+
* This delay can be changed based on the controller.
4853+
*/
4854+
ufshcd_delay_us(hba->vps->hba_enable_delay_us, 100);
48564855

4857-
/* wait for the host controller to complete initialization */
4858-
retry_inner = 50;
4859-
while (!ufshcd_is_hba_active(hba)) {
4860-
if (retry_inner) {
4861-
retry_inner--;
4862-
} else {
4863-
dev_err(hba->dev,
4864-
"Controller enable failed\n");
4865-
if (retry_outer) {
4866-
retry_outer--;
4867-
goto start;
4868-
}
4869-
return -EIO;
4870-
}
4871-
usleep_range(1000, 1100);
4856+
/* wait for the host controller to complete initialization */
4857+
if (!ufshcd_wait_for_register(hba, REG_CONTROLLER_ENABLE, CONTROLLER_ENABLE,
4858+
CONTROLLER_ENABLE, 1000, 50))
4859+
break;
4860+
4861+
dev_err(hba->dev, "Enabling the controller failed\n");
48724862
}
48734863

4864+
if (!retry)
4865+
return -EIO;
4866+
48744867
/* enable UIC related interrupts */
48754868
ufshcd_enable_intr(hba, UFSHCD_UIC_MASK);
48764869

0 commit comments

Comments
 (0)