[PATCH v2 2/2] scsi: ufs: core: Replace hard coded vcc-off delay with a variable

Bao D. Nguyen posted 2 patches 2 months, 1 week ago
There is a newer version of this series
[PATCH v2 2/2] scsi: ufs: core: Replace hard coded vcc-off delay with a variable
Posted by Bao D. Nguyen 2 months, 1 week ago
After the ufs device vcc is powered off, all the ufs device
manufacturers require a minimum of 1ms of power-off time before
vcc can be powered on again. This requirement has been verified
with all the ufs device manufacturer's datasheets.

Replace the hard coded 5ms delay with a variable using a default
setting of 5ms. This allows the platform drivers to override this
setting to improve the system resume latency by reducing the sleep
time as needed.

Signed-off-by: Bao D. Nguyen <quic_nguyenb@quicinc.com>
---
 drivers/ufs/core/ufshcd.c | 10 +++++++++-
 include/ufs/ufshcd.h      |  2 ++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index e8842dc..593c9d0 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -9741,7 +9741,8 @@ static void ufshcd_vreg_set_lpm(struct ufs_hba *hba)
 	 * All UFS devices require delay after VCC power rail is turned-off.
 	 */
 	if (vcc_off && hba->vreg_info.vcc && !hba->vreg_info.vcc->always_on)
-		usleep_range(5000, 5100);
+		usleep_range(hba->sleep_post_vcc_off,
+			     hba->sleep_post_vcc_off + 100);
 }
 
 #ifdef CONFIG_PM
@@ -10665,6 +10666,13 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
 						UFS_SLEEP_PWR_MODE,
 						UIC_LINK_HIBERN8_STATE);
 
+	/*
+	 * Most ufs devices require 1ms delay after vcc is powered off before
+	 * it can be powered on again. Set the default to 5ms. The platform
+	 * drivers can override this setting as needed.
+	 */
+	hba->sleep_post_vcc_off = 5000;
+
 	init_completion(&hba->dev_cmd.complete);
 
 	err = ufshcd_hba_init(hba);
diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h
index 1d39437..ad49979 100644
--- a/include/ufs/ufshcd.h
+++ b/include/ufs/ufshcd.h
@@ -1140,6 +1140,8 @@ struct ufs_hba {
 	int critical_health_count;
 	atomic_t dev_lvl_exception_count;
 	u64 dev_lvl_exception_id;
+
+	u32 sleep_post_vcc_off;
 };
 
 /**
-- 
2.7.4
Re: [PATCH v2 2/2] scsi: ufs: core: Replace hard coded vcc-off delay with a variable
Posted by Peter Wang (王信友) 2 months, 1 week ago
On Thu, 2025-10-09 at 13:10 -0700, Bao D. Nguyen wrote:
> 
> +       /*
> +        * Most ufs devices require 1ms delay after vcc is powered
> off before
> +        * it can be powered on again. Set the default to 5ms. The
> platform
> +        * drivers can override this setting as needed.
> +        */
> +       hba->sleep_post_vcc_off = 5000;
> +
> 

Hi Bao,

Since 2ms is sufficient for most devices, wouldn't it make
sense to set the default value to 2ms?


>         init_completion(&hba->dev_cmd.complete);
> 
>         err = ufshcd_hba_init(hba);
> diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h
> index 1d39437..ad49979 100644
> --- a/include/ufs/ufshcd.h
> +++ b/include/ufs/ufshcd.h
> @@ -1140,6 +1140,8 @@ struct ufs_hba {
>         int critical_health_count;
>         atomic_t dev_lvl_exception_count;
>         u64 dev_lvl_exception_id;
> +
> +       u32 sleep_post_vcc_off;
> 

The name sleep_post_vcc_off might be misunderstood as a 
status or a flag. I suggest changing it to a more explicit 
name, such as vcc_off_delay_ms.


Thanks
Peter


Re: [PATCH v2 2/2] scsi: ufs: core: Replace hard coded vcc-off delay with a variable
Posted by Bao D. Nguyen 2 months ago
On 10/12/2025 8:58 PM, Peter Wang (王信友) wrote:
> On Thu, 2025-10-09 at 13:10 -0700, Bao D. Nguyen wrote:
>>
>> +       /*
>> +        * Most ufs devices require 1ms delay after vcc is powered
>> off before
>> +        * it can be powered on again. Set the default to 5ms. The
>> platform
>> +        * drivers can override this setting as needed.
>> +        */
>> +       hba->sleep_post_vcc_off = 5000;
>> +
>>
> 
> Hi Bao,
> 
> Since 2ms is sufficient for most devices, wouldn't it make
> sense to set the default value to 2ms?

Agree Peter. This was my preference as well.

> 
> 
>>          init_completion(&hba->dev_cmd.complete);
>>
>>          err = ufshcd_hba_init(hba);
>> diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h
>> index 1d39437..ad49979 100644
>> --- a/include/ufs/ufshcd.h
>> +++ b/include/ufs/ufshcd.h
>> @@ -1140,6 +1140,8 @@ struct ufs_hba {
>>          int critical_health_count;
>>          atomic_t dev_lvl_exception_count;
>>          u64 dev_lvl_exception_id;
>> +
>> +       u32 sleep_post_vcc_off;
>>
> 
> The name sleep_post_vcc_off might be misunderstood as a
> status or a flag. I suggest changing it to a more explicit
> name, such as vcc_off_delay_ms.

Sure Peter. I will make the change.

Thanks, Bao

> 
> 
> Thanks
> Peter
> 
>