Skip to contentSkip to conversation

scsi: ufs: core: Let delay value after LPM can be modified by vendor

PATCH RESEND Superseded zhe wang 2 participants 3 messages Oct 20, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

zhe wang

author
#0 lore raw

PATCH RESEND 1/1 scsi: ufs: core: Let delay value after LPM can be modified by vendor

From: Zhe Wang <[email protected]>

Some UFS devices require that the VCC should drop below 0.1V after turning off, otherwise device may not resume successfully. And because the power-off rate is different on different SOC platforms. Therefore, we hope that the delay can be modified by vendor to adjust the most appropriate delay value.

---
 drivers/ufs/core/ufshcd.c | 11 +++++++++--
 include/ufs/ufshcd.h      |  2 ++
 2 files changed, 11 insertions(+), 2 deletions(-)
drivers/ufs/core/ufshcd.c +9 -2
index 7256e6c43ca6..f6350231da0e 100644
@@ -89,6 +89,9 @@
 /* Polling time to wait for fDeviceInit */
 #define FDEVICEINIT_COMPL_TIMEOUT 1500 /* millisecs */
 
+/* Default value of turn off VCC rail: 5000us */
+#define UFS_VCC_TURNOFF_DELAY_US 5000
+
 #define ufshcd_toggle_vreg(_dev, _vreg, _on)				\
 	({                                                              \
 		int _ret;                                               \
@@ -7784,6 +7787,9 @@ static int ufs_get_device_desc(struct ufs_hba *hba)
 
 	ufs_fixup_device_setup(hba);
 
+	if (hba->dev_quirks & UFS_DEVICE_QUIRK_DELAY_AFTER_LPM && !hba->vcc_turnoff_delay)
+		hba->vcc_turnoff_delay = UFS_VCC_TURNOFF_DELAY_US;
+
 	ufshcd_wb_probe(hba, desc_buf);
 
 	ufshcd_temp_notif_probe(hba, desc_buf);
@@ -8917,8 +8923,9 @@ static void ufshcd_vreg_set_lpm(struct ufs_hba *hba)
 	 * Some UFS devices require delay after VCC power rail is turned-off.
 	 */
 	if (vcc_off && hba->vreg_info.vcc &&
-		hba->dev_quirks & UFS_DEVICE_QUIRK_DELAY_AFTER_LPM)
-		usleep_range(5000, 5100);
+		hba->dev_quirks & UFS_DEVICE_QUIRK_DELAY_AFTER_LPM &&
+		hba->vcc_turnoff_delay)
+		usleep_range(hba->vcc_turnoff_delay, hba->vcc_turnoff_delay + 100);
 }
 
 #ifdef CONFIG_PM
include/ufs/ufshcd.h +2 -0
index 9f28349ebcff..bfde3cb962fb 100644
@@ -828,6 +828,7 @@ struct ufs_hba_monitor {
  *	device
  * @complete_put: whether or not to call ufshcd_rpm_put() from inside
  *	ufshcd_resume_complete()
+ * @vcc_turnoff_delay: VCC turnoff delay value.
  */
 struct ufs_hba {
 	void __iomem *mmio_base;
@@ -975,6 +976,7 @@ struct ufs_hba {
 #endif
 	u32 luns_avail;
 	bool complete_put;
+	u32 vcc_turnoff_delay;
 };
 
 /* Returns true if clocks can be gated. Otherwise false */
Signature · 1 line
2.17.1
reviewer
#1 lore raw
Quoted 29 lines

From: Zhe Wang <[email protected]>

Some UFS devices require that the VCC should drop below 0.1V after turning off, otherwise device may not resume successfully. And because the power-off rate is different on different SOC platforms. Therefore, we hope that the delay can be modified by vendor to adjust the most appropriate delay value.

---
 drivers/ufs/core/ufshcd.c | 11 +++++++++--
 include/ufs/ufshcd.h      |  2 ++
 2 files changed, 11 insertions(+), 2 deletions(-)
drivers/ufs/core/ufshcd.c +3 -0
index 7256e6c43ca6..f6350231da0e 100644
@@ -89,6 +89,9 @@
 /* Polling time to wait for fDeviceInit */
 #define FDEVICEINIT_COMPL_TIMEOUT 1500 /* millisecs */
 
+/* Default value of turn off VCC rail: 5000us */
+#define UFS_VCC_TURNOFF_DELAY_US 5000
+
 #define ufshcd_toggle_vreg(_dev, _vreg, _on)                           \
        ({                                                              \
                int _ret;                                               \

drivers/ufs/core/ufshcd.c static int ufs_get_device_desc(struct ufs_hba · line 7793

Quoted 7 lines
drivers/ufs/core/ufshcd.c +2 -0
@@ -7784,6 +7787,9 @@ static int ufs_get_device_desc(struct ufs_hba
 *hba)
 
        ufs_fixup_device_setup(hba);
 
+       if (hba->dev_quirks & UFS_DEVICE_QUIRK_DELAY_AFTER_LPM &&
 !hba->vcc_turnoff_delay)
+               hba->vcc_turnoff_delay = UFS_VCC_TURNOFF_DELAY_US;

Couldn't find where otherwise you are setting this value? Also, UFS_DEVICE_QUIRK_DELAY_AFTER_LPM is only set for MTK. Are you planning at some point adding your own host driver?

Quoted 31 lines
drivers/ufs/core/ufshcd.c +1 -0
+
        ufshcd_wb_probe(hba, desc_buf);
        ufshcd_temp_notif_probe(hba, desc_buf);
drivers/ufs/core/ufshcd.c +3 -2
@@ -8917,8 +8923,9 @@ static void ufshcd_vreg_set_lpm(struct ufs_hba
 *hba)
         * Some UFS devices require delay after VCC power rail is turned-off.
         */
        if (vcc_off && hba->vreg_info.vcc &&
-               hba->dev_quirks & UFS_DEVICE_QUIRK_DELAY_AFTER_LPM)
-               usleep_range(5000, 5100);
+               hba->dev_quirks & UFS_DEVICE_QUIRK_DELAY_AFTER_LPM &&
+               hba->vcc_turnoff_delay)
+               usleep_range(hba->vcc_turnoff_delay, hba->vcc_turnoff_delay +
 100);
 }

#ifdef CONFIG_PM

include/ufs/ufshcd.h +1 -0
index 9f28349ebcff..bfde3cb962fb 100644
@@ -828,6 +828,7 @@ struct ufs_hba_monitor {
  *     device
  * @complete_put: whether or not to call ufshcd_rpm_put() from inside
  *     ufshcd_resume_complete()
+ * @vcc_turnoff_delay: VCC turnoff delay value.
  */
 struct ufs_hba {
        void __iomem *mmio_base;

include/ufs/ufshcd.h struct ufs_hba { · line 979

Quoted 4 lines
include/ufs/ufshcd.h +1 -0
@@ -975,6 +976,7 @@ struct ufs_hba {
 #endif
        u32 luns_avail;
        bool complete_put;
+       u32 vcc_turnoff_delay;

Can this be part of struct ufs_vreg instead?
Also maybe vcc_turnoff_delay_us?

Thanks,
Avri

Quoted 5 lines
include/ufs/ufshcd.h +0 -1
 };
 
 /* Returns true if clocks can be gated. Otherwise false */
--

2.17.1

author
#2 lore raw
Quoted 32 lines · Avri Altman <[email protected]> 于2022年10月20日周四 15:16写道:
Quoted 32 lines

From: Zhe Wang <[email protected]>

Some UFS devices require that the VCC should drop below 0.1V after turning off, otherwise device may not resume successfully. And because the power-off rate is different on different SOC platforms. Therefore, we hope that the delay can be modified by vendor to adjust the most appropriate delay value.

---
 drivers/ufs/core/ufshcd.c | 11 +++++++++--
 include/ufs/ufshcd.h      |  2 ++
 2 files changed, 11 insertions(+), 2 deletions(-)
drivers/ufs/core/ufshcd.c +3 -0
index 7256e6c43ca6..f6350231da0e 100644
@@ -89,6 +89,9 @@
 /* Polling time to wait for fDeviceInit */
 #define FDEVICEINIT_COMPL_TIMEOUT 1500 /* millisecs */
 
+/* Default value of turn off VCC rail: 5000us */
+#define UFS_VCC_TURNOFF_DELAY_US 5000
+
 #define ufshcd_toggle_vreg(_dev, _vreg, _on)                           \
        ({                                                              \
                int _ret;                                               \
@@ -7784,6 +7787,9 @@ static int ufs_get_device_desc(struct ufs_hba
 *hba)
 
Quoted 9 lines

drivers/ufs/core/ufshcd.c static int ufs_get_device_desc(struct ufs_hba *hba) · line 7791

Quoted 5 lines
drivers/ufs/core/ufshcd.c +2 -0
        ufs_fixup_device_setup(hba);
 
+       if (hba->dev_quirks & UFS_DEVICE_QUIRK_DELAY_AFTER_LPM &&
 !hba->vcc_turnoff_delay)
+               hba->vcc_turnoff_delay = UFS_VCC_TURNOFF_DELAY_US;

Couldn't find where otherwise you are setting this value? Also, UFS_DEVICE_QUIRK_DELAY_AFTER_LPM is only set for MTK. Are you planning at some point adding your own host driver?

We are still preparing and discussing our own UFS host driver code, which will be uploaded once we are done.

Quoted 38 lines
Quoted 31 lines
drivers/ufs/core/ufshcd.c +1 -0
+
        ufshcd_wb_probe(hba, desc_buf);
        ufshcd_temp_notif_probe(hba, desc_buf);
drivers/ufs/core/ufshcd.c +3 -2
@@ -8917,8 +8923,9 @@ static void ufshcd_vreg_set_lpm(struct ufs_hba
 *hba)
         * Some UFS devices require delay after VCC power rail is turned-off.
         */
        if (vcc_off && hba->vreg_info.vcc &&
-               hba->dev_quirks & UFS_DEVICE_QUIRK_DELAY_AFTER_LPM)
-               usleep_range(5000, 5100);
+               hba->dev_quirks & UFS_DEVICE_QUIRK_DELAY_AFTER_LPM &&
+               hba->vcc_turnoff_delay)
+               usleep_range(hba->vcc_turnoff_delay, hba->vcc_turnoff_delay +
 100);
 }

#ifdef CONFIG_PM

include/ufs/ufshcd.h +1 -0
index 9f28349ebcff..bfde3cb962fb 100644
@@ -828,6 +828,7 @@ struct ufs_hba_monitor {
  *     device
  * @complete_put: whether or not to call ufshcd_rpm_put() from inside
  *     ufshcd_resume_complete()
+ * @vcc_turnoff_delay: VCC turnoff delay value.
  */
 struct ufs_hba {
        void __iomem *mmio_base;

include/ufs/ufshcd.h struct ufs_hba { · line 979

Quoted 4 lines
include/ufs/ufshcd.h +1 -0
@@ -975,6 +976,7 @@ struct ufs_hba {
 #endif
        u32 luns_avail;
        bool complete_put;
+       u32 vcc_turnoff_delay;

Can this be part of struct ufs_vreg instead?
Also maybe vcc_turnoff_delay_us?

Quoted 8 lines

Thanks,
Avri

Quoted 5 lines
include/ufs/ufshcd.h +0 -1
 };
 
 /* Returns true if clocks can be gated. Otherwise false */
--

2.17.1

Thanks for your suggestion, I will modify it in V2.

Thanks,
Zhe Wang