diff mbox series

[v1,3/3] scsi: ufs-mediatek: enable low-power mode for hibern8 state

Message ID 20200117035108.19699-4-stanley.chu@mediatek.com (mailing list archive)
State Mainlined
Commit fdb2c232497296025c27e47d379fe55ba46ff9e6
Headers show
Series scsi: ufs-mediatek: add MediaTek vendor implementation part II | expand

Commit Message

Stanley Chu Jan. 17, 2020, 3:51 a.m. UTC
In MediaTek Chipsets, UniPro link and ufshci can enter proprietary
low-power mode while link is in hibern8 state.

Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
---
 drivers/scsi/ufs/ufs-mediatek.c | 53 +++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

Comments

Alim Akhtar Jan. 19, 2020, 2:27 p.m. UTC | #1
On Fri, Jan 17, 2020 at 9:44 AM Stanley Chu <stanley.chu@mediatek.com> wrote:
>
> In MediaTek Chipsets, UniPro link and ufshci can enter proprietary
> low-power mode while link is in hibern8 state.
>
> Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
> ---
Reviewed-by: Alim Akhtar <alim.akhtar@samsung.com>

>  drivers/scsi/ufs/ufs-mediatek.c | 53 +++++++++++++++++++++++++++++++++
>  1 file changed, 53 insertions(+)
>
> diff --git a/drivers/scsi/ufs/ufs-mediatek.c b/drivers/scsi/ufs/ufs-mediatek.c
> index d5194d0c4ef5..f32f3f34f6d0 100644
> --- a/drivers/scsi/ufs/ufs-mediatek.c
> +++ b/drivers/scsi/ufs/ufs-mediatek.c
> @@ -382,11 +382,60 @@ static void ufs_mtk_device_reset(struct ufs_hba *hba)
>         dev_info(hba->dev, "device reset done\n");
>  }
>
> +static int ufs_mtk_link_set_hpm(struct ufs_hba *hba)
> +{
> +       int err;
> +
> +       err = ufshcd_hba_enable(hba);
> +       if (err)
> +               return err;
> +
> +       err = ufshcd_dme_set(hba,
> +                            UIC_ARG_MIB_SEL(VS_UNIPROPOWERDOWNCONTROL, 0),
> +                            0);
> +       if (err)
> +               return err;
> +
> +       err = ufshcd_uic_hibern8_exit(hba);
> +       if (!err)
> +               ufshcd_set_link_active(hba);
> +       else
> +               return err;
> +
> +       err = ufshcd_make_hba_operational(hba);
> +       if (err)
> +               return err;
> +
> +       return 0;
> +}
> +
> +static int ufs_mtk_link_set_lpm(struct ufs_hba *hba)
> +{
> +       int err;
> +
> +       err = ufshcd_dme_set(hba,
> +                            UIC_ARG_MIB_SEL(VS_UNIPROPOWERDOWNCONTROL, 0),
> +                            1);
> +       if (err) {
> +               /* Resume UniPro state for following error recovery */
> +               ufshcd_dme_set(hba,
> +                              UIC_ARG_MIB_SEL(VS_UNIPROPOWERDOWNCONTROL, 0),
> +                              0);
> +               return err;
> +       }
> +
> +       return 0;
> +}
> +
>  static int ufs_mtk_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)
>  {
> +       int err;
>         struct ufs_mtk_host *host = ufshcd_get_variant(hba);
>
>         if (ufshcd_is_link_hibern8(hba)) {
> +               err = ufs_mtk_link_set_lpm(hba);
> +               if (err)
> +                       return -EAGAIN;
>                 phy_power_off(host->mphy);
>                 ufs_mtk_setup_ref_clk(hba, false);
>         }
> @@ -397,10 +446,14 @@ static int ufs_mtk_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)
>  static int ufs_mtk_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op)
>  {
>         struct ufs_mtk_host *host = ufshcd_get_variant(hba);
> +       int err;
>
>         if (ufshcd_is_link_hibern8(hba)) {
>                 ufs_mtk_setup_ref_clk(hba, true);
>                 phy_power_on(host->mphy);
> +               err = ufs_mtk_link_set_hpm(hba);
> +               if (err)
> +                       return err;
>         }
>
>         return 0;
> --
> 2.18.0
Asutosh Das (asd) Jan. 20, 2020, 8:52 p.m. UTC | #2
On 1/16/2020 7:51 PM, Stanley Chu wrote:
> In MediaTek Chipsets, UniPro link and ufshci can enter proprietary
> low-power mode while link is in hibern8 state.
> 
> Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
> ---

Reviewed-by: Asutosh Das <asutoshd@codeaurora.org>

>   drivers/scsi/ufs/ufs-mediatek.c | 53 +++++++++++++++++++++++++++++++++
>   1 file changed, 53 insertions(+)
> 
> diff --git a/drivers/scsi/ufs/ufs-mediatek.c b/drivers/scsi/ufs/ufs-mediatek.c
> index d5194d0c4ef5..f32f3f34f6d0 100644
> --- a/drivers/scsi/ufs/ufs-mediatek.c
> +++ b/drivers/scsi/ufs/ufs-mediatek.c
> @@ -382,11 +382,60 @@ static void ufs_mtk_device_reset(struct ufs_hba *hba)
>   	dev_info(hba->dev, "device reset done\n");
>   }
>   
> +static int ufs_mtk_link_set_hpm(struct ufs_hba *hba)
> +{
> +	int err;
> +
> +	err = ufshcd_hba_enable(hba);
> +	if (err)
> +		return err;
> +
> +	err = ufshcd_dme_set(hba,
> +			     UIC_ARG_MIB_SEL(VS_UNIPROPOWERDOWNCONTROL, 0),
> +			     0);
> +	if (err)
> +		return err;
> +
> +	err = ufshcd_uic_hibern8_exit(hba);
> +	if (!err)
> +		ufshcd_set_link_active(hba);
> +	else
> +		return err;
> +
> +	err = ufshcd_make_hba_operational(hba);
> +	if (err)
> +		return err;
> +
> +	return 0;
> +}
> +
> +static int ufs_mtk_link_set_lpm(struct ufs_hba *hba)
> +{
> +	int err;
> +
> +	err = ufshcd_dme_set(hba,
> +			     UIC_ARG_MIB_SEL(VS_UNIPROPOWERDOWNCONTROL, 0),
> +			     1);
> +	if (err) {
> +		/* Resume UniPro state for following error recovery */
> +		ufshcd_dme_set(hba,
> +			       UIC_ARG_MIB_SEL(VS_UNIPROPOWERDOWNCONTROL, 0),
> +			       0);
> +		return err;
> +	}
> +
> +	return 0;
> +}
> +
>   static int ufs_mtk_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)
>   {
> +	int err;
>   	struct ufs_mtk_host *host = ufshcd_get_variant(hba);
>   
>   	if (ufshcd_is_link_hibern8(hba)) {
> +		err = ufs_mtk_link_set_lpm(hba);
> +		if (err)
> +			return -EAGAIN;
>   		phy_power_off(host->mphy);
>   		ufs_mtk_setup_ref_clk(hba, false);
>   	}
> @@ -397,10 +446,14 @@ static int ufs_mtk_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)
>   static int ufs_mtk_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op)
>   {
>   	struct ufs_mtk_host *host = ufshcd_get_variant(hba);
> +	int err;
>   
>   	if (ufshcd_is_link_hibern8(hba)) {
>   		ufs_mtk_setup_ref_clk(hba, true);
>   		phy_power_on(host->mphy);
> +		err = ufs_mtk_link_set_hpm(hba);
> +		if (err)
> +			return err;
>   	}
>   
>   	return 0;
>
diff mbox series

Patch

diff --git a/drivers/scsi/ufs/ufs-mediatek.c b/drivers/scsi/ufs/ufs-mediatek.c
index d5194d0c4ef5..f32f3f34f6d0 100644
--- a/drivers/scsi/ufs/ufs-mediatek.c
+++ b/drivers/scsi/ufs/ufs-mediatek.c
@@ -382,11 +382,60 @@  static void ufs_mtk_device_reset(struct ufs_hba *hba)
 	dev_info(hba->dev, "device reset done\n");
 }
 
+static int ufs_mtk_link_set_hpm(struct ufs_hba *hba)
+{
+	int err;
+
+	err = ufshcd_hba_enable(hba);
+	if (err)
+		return err;
+
+	err = ufshcd_dme_set(hba,
+			     UIC_ARG_MIB_SEL(VS_UNIPROPOWERDOWNCONTROL, 0),
+			     0);
+	if (err)
+		return err;
+
+	err = ufshcd_uic_hibern8_exit(hba);
+	if (!err)
+		ufshcd_set_link_active(hba);
+	else
+		return err;
+
+	err = ufshcd_make_hba_operational(hba);
+	if (err)
+		return err;
+
+	return 0;
+}
+
+static int ufs_mtk_link_set_lpm(struct ufs_hba *hba)
+{
+	int err;
+
+	err = ufshcd_dme_set(hba,
+			     UIC_ARG_MIB_SEL(VS_UNIPROPOWERDOWNCONTROL, 0),
+			     1);
+	if (err) {
+		/* Resume UniPro state for following error recovery */
+		ufshcd_dme_set(hba,
+			       UIC_ARG_MIB_SEL(VS_UNIPROPOWERDOWNCONTROL, 0),
+			       0);
+		return err;
+	}
+
+	return 0;
+}
+
 static int ufs_mtk_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)
 {
+	int err;
 	struct ufs_mtk_host *host = ufshcd_get_variant(hba);
 
 	if (ufshcd_is_link_hibern8(hba)) {
+		err = ufs_mtk_link_set_lpm(hba);
+		if (err)
+			return -EAGAIN;
 		phy_power_off(host->mphy);
 		ufs_mtk_setup_ref_clk(hba, false);
 	}
@@ -397,10 +446,14 @@  static int ufs_mtk_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)
 static int ufs_mtk_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op)
 {
 	struct ufs_mtk_host *host = ufshcd_get_variant(hba);
+	int err;
 
 	if (ufshcd_is_link_hibern8(hba)) {
 		ufs_mtk_setup_ref_clk(hba, true);
 		phy_power_on(host->mphy);
+		err = ufs_mtk_link_set_hpm(hba);
+		if (err)
+			return err;
 	}
 
 	return 0;