All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeffrey Hugo <jeffrey.l.hugo@gmail.com>
To: lgirdwood@gmail.com, broonie@kernel.org
Cc: agross@kernel.org, bjorn.andersson@linaro.org,
	robh+dt@kernel.org, mark.rutland@arm.com,
	linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
	devicetree@vger.kernel.org,
	Jeffrey Hugo <jeffrey.l.hugo@gmail.com>
Subject: [PATCH v3 2/7] drivers: regulator: qcom_spmi: Refactor get_mode/set_mode
Date: Thu, 13 Jun 2019 07:22:39 -0700	[thread overview]
Message-ID: <20190613142239.8779-1-jeffrey.l.hugo@gmail.com> (raw)
In-Reply-To: <20190613142157.8674-1-jeffrey.l.hugo@gmail.com>

spmi_regulator_common_get_mode and spmi_regulator_common_set_mode use
multi-level ifs which mirror a switch statement.  Refactor to use a switch
statement to make the code flow more clear.

Signed-off-by: Jeffrey Hugo <jeffrey.l.hugo@gmail.com>
---
 drivers/regulator/qcom_spmi-regulator.c | 28 ++++++++++++++++---------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/drivers/regulator/qcom_spmi-regulator.c b/drivers/regulator/qcom_spmi-regulator.c
index fd55438c25d6..1c18fe5969b5 100644
--- a/drivers/regulator/qcom_spmi-regulator.c
+++ b/drivers/regulator/qcom_spmi-regulator.c
@@ -911,13 +911,14 @@ static unsigned int spmi_regulator_common_get_mode(struct regulator_dev *rdev)
 
 	spmi_vreg_read(vreg, SPMI_COMMON_REG_MODE, &reg, 1);
 
-	if (reg & SPMI_COMMON_MODE_HPM_MASK)
+	switch (reg) {
+	case SPMI_COMMON_MODE_HPM_MASK:
 		return REGULATOR_MODE_NORMAL;
-
-	if (reg & SPMI_COMMON_MODE_AUTO_MASK)
+	case SPMI_COMMON_MODE_AUTO_MASK:
 		return REGULATOR_MODE_FAST;
-
-	return REGULATOR_MODE_IDLE;
+	default:
+		return REGULATOR_MODE_IDLE;
+	}
 }
 
 static int
@@ -925,12 +926,19 @@ spmi_regulator_common_set_mode(struct regulator_dev *rdev, unsigned int mode)
 {
 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
 	u8 mask = SPMI_COMMON_MODE_HPM_MASK | SPMI_COMMON_MODE_AUTO_MASK;
-	u8 val = 0;
+	u8 val;
 
-	if (mode == REGULATOR_MODE_NORMAL)
+	switch (mode) {
+	case REGULATOR_MODE_NORMAL:
 		val = SPMI_COMMON_MODE_HPM_MASK;
-	else if (mode == REGULATOR_MODE_FAST)
+		break;
+	case REGULATOR_MODE_FAST:
 		val = SPMI_COMMON_MODE_AUTO_MASK;
+		break;
+	default:
+		val = 0;
+		break;
+	}
 
 	return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_MODE, val, mask);
 }
@@ -1834,9 +1842,9 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev)
 			}
 		}
 
-		if (vreg->logical_type == SPMI_REGULATOR_LOGICAL_TYPE_HFS430) {
+		if (vreg->set_points->count == 1) {
 			/* since there is only one range */
-			range = spmi_regulator_find_range(vreg);
+			range = vreg->set_points->range;
 			vreg->desc.uV_step = range->step_uV;
 		}
 
-- 
2.17.1


  parent reply	other threads:[~2019-06-13 15:03 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-13 14:21 [PATCH v2 0/7] PM8005 and PMS405 regulator support Jeffrey Hugo
2019-06-13 14:21 ` Jeffrey Hugo
2019-06-13 14:22 ` [PATCH v3 1/7] drivers: regulator: qcom_spmi: enable linear range info Jeffrey Hugo
2019-06-13 15:10   ` Bjorn Andersson
2019-06-13 15:28     ` Jeffrey Hugo
2019-06-13 14:22 ` Jeffrey Hugo [this message]
2019-06-13 15:12   ` [PATCH v3 2/7] drivers: regulator: qcom_spmi: Refactor get_mode/set_mode Bjorn Andersson
2019-06-13 15:24     ` Bjorn Andersson
2019-06-13 15:37       ` Jeffrey Hugo
2019-06-13 14:23 ` [PATCH v3 3/7] dt-bindings: qcom_spmi: Document PM8005 regulators Jeffrey Hugo
2019-06-13 14:23 ` [PATCH v3 4/7] regulator: qcom_spmi: Add support for PM8005 Jeffrey Hugo
2019-06-13 15:25   ` Bjorn Andersson
2019-06-13 14:24 ` [PATCH v3 5/7] arm64: dts: msm8998-mtp: Add pm8005_s1 regulator Jeffrey Hugo
2019-06-13 14:24 ` [PATCH v3 6/7] dt-bindings: qcom_spmi: Document pms405 support Jeffrey Hugo
2019-06-13 15:36   ` Bjorn Andersson
2019-06-13 15:40     ` Jeffrey Hugo
2019-06-13 14:24 ` [PATCH v3 7/7] drivers: regulator: qcom: add PMS405 SPMI regulator Jeffrey Hugo
2019-06-13 15:33   ` Bjorn Andersson
2019-06-13 15:41     ` Jeffrey Hugo

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=20190613142239.8779-1-jeffrey.l.hugo@gmail.com \
    --to=jeffrey.l.hugo@gmail.com \
    --cc=agross@kernel.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=robh+dt@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.