public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Stanley Chu <stanley.chu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
To: linux-scsi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	martin.petersen-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org,
	avri.altman-Sjgp3cTcYWE@public.gmane.org,
	alim.akhtar-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org,
	pedrom.sousa-HKixBCOQz3hWk0Htik3J/w@public.gmane.org
Cc: marc.w.gonzalez-GANU6spQydw@public.gmane.org,
	chun-hung.wu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org,
	kuohong.wang-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org,
	linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	peter.wang-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org,
	matthias.bgg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	Stanley Chu <stanley.chu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
Subject: [PATCH v3 3/5] scsi: ufs: Fix regulator load and icc-level configuration
Date: Mon, 18 Mar 2019 10:14:38 +0800	[thread overview]
Message-ID: <1552875280-16196-5-git-send-email-stanley.chu@mediatek.com> (raw)
In-Reply-To: <1552875280-16196-1-git-send-email-stanley.chu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>

Currently if a regulator has "<name>-fixed-regulator"
property in device tree, it will skip current limit configuration.
This lead to a zero "max_uA" value in struct ufs_vreg.

However, "regulator_set_load" operation shall be required
on those regulators which specifically configured current
limit, otherwise a zero max_uA value may cause unexpected behavior
when this regulator is enabled or set as high power mode.

Similarly, in icc_level configuration flow, icc_level shall be
updated if specified regulator has also configured current limit,
otherwise a zero max_uA will lead to wrong icc_level which may
cause unexpected results after written to device.

Signed-off-by: Stanley Chu <stanley.chu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
---
 drivers/scsi/ufs/ufshcd.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 4e41fdfd0e53..9ae3256a705b 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -6279,19 +6279,19 @@ static u32 ufshcd_find_max_sup_active_icc_level(struct ufs_hba *hba,
 		goto out;
 	}
 
-	if (hba->vreg_info.vcc)
+	if (hba->vreg_info.vcc && hba->vreg_info.vcc->max_uA)
 		icc_level = ufshcd_get_max_icc_level(
 				hba->vreg_info.vcc->max_uA,
 				POWER_DESC_MAX_ACTV_ICC_LVLS - 1,
 				&desc_buf[PWR_DESC_ACTIVE_LVLS_VCC_0]);
 
-	if (hba->vreg_info.vccq)
+	if (hba->vreg_info.vccq && hba->vreg_info.vccq->max_uA)
 		icc_level = ufshcd_get_max_icc_level(
 				hba->vreg_info.vccq->max_uA,
 				icc_level,
 				&desc_buf[PWR_DESC_ACTIVE_LVLS_VCCQ_0]);
 
-	if (hba->vreg_info.vccq2)
+	if (hba->vreg_info.vccq2 && hba->vreg_info.vccq2->max_uA)
 		icc_level = ufshcd_get_max_icc_level(
 				hba->vreg_info.vccq2->max_uA,
 				icc_level,
@@ -6989,6 +6989,15 @@ static int ufshcd_config_vreg_load(struct device *dev, struct ufs_vreg *vreg,
 	if (!vreg)
 		return 0;
 
+	/*
+	 * "set_load" operation shall be required on those regulators
+	 * which specifically configured current limitation. Otherwise
+	 * zero max_uA may cause unexpected behavior when regulator is
+	 * enabled or set as high power mode.
+	 */
+	if (!vreg->max_uA)
+		return 0;
+
 	ret = regulator_set_load(vreg->reg, ua);
 	if (ret < 0) {
 		dev_err(dev, "%s: %s set load (ua=%d) failed, err=%d\n",
-- 
2.18.0

  parent reply	other threads:[~2019-03-18  2:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-18  2:14 scsi: ufs: Fix regulator operations and remove "<name>-fixed-regulator" device tree property Stanley Chu
     [not found] ` <1552875280-16196-1-git-send-email-stanley.chu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
2019-03-18  2:14   ` [PATCH v3 0/5] " Stanley Chu
     [not found]     ` <1552875280-16196-2-git-send-email-stanley.chu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
2019-03-25  1:16       ` Stanley Chu
2019-03-18  2:14   ` [PATCH v3 1/5] scsi: ufs: Remove unused min_uA field in struct ufs_vreg Stanley Chu
     [not found]     ` <1552875280-16196-3-git-send-email-stanley.chu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
2019-03-19  3:06       ` Alim Akhtar
2019-03-18  2:14   ` [PATCH v3 2/5] scsi: ufs: Avoid configuring undefined voltage range on a regulator Stanley Chu
2019-03-18  2:14   ` Stanley Chu [this message]
2019-03-18  2:14   ` [PATCH v3 4/5] scsi: ufs: Change "<name>-max-microamp" to non-mandatory property Stanley Chu
2019-03-18  2:14   ` [PATCH v3 5/5] scsi: ufs: Remove "<name>-fixed-regulator" device tree property Stanley Chu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1552875280-16196-5-git-send-email-stanley.chu@mediatek.com \
    --to=stanley.chu-nus5lvnupcjwk0htik3j/w@public.gmane.org \
    --cc=alim.akhtar-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org \
    --cc=avri.altman-Sjgp3cTcYWE@public.gmane.org \
    --cc=chun-hung.wu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
    --cc=kuohong.wang-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
    --cc=linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-scsi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=marc.w.gonzalez-GANU6spQydw@public.gmane.org \
    --cc=martin.petersen-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org \
    --cc=matthias.bgg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=pedrom.sousa-HKixBCOQz3hWk0Htik3J/w@public.gmane.org \
    --cc=peter.wang-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox