lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230605104830.68552-1-raagjadav@gmail.com>
Date:   Mon,  5 Jun 2023 16:18:29 +0530
From:   Raag Jadav <raagjadav@...il.com>
To:     Liam Girdwood <lgirdwood@...il.com>,
        Mark Brown <broonie@...nel.org>
Cc:     linux-kernel@...r.kernel.org, Raag Jadav <raagjadav@...il.com>
Subject: [PATCH 1/2] regulator: act8945a: rely on hardware for operating mode

Convert ->get_mode() and ->set_mode() hooks to read/write operating mode
from/to hardware instead of relying on driver memory.
While at it, map fixed-frequency PWM regulators to REGULATOR_MODE_FAST.

Signed-off-by: Raag Jadav <raagjadav@...il.com>
---
 drivers/regulator/act8945a-regulator.c | 62 ++++++++++++++++++--------
 1 file changed, 44 insertions(+), 18 deletions(-)

diff --git a/drivers/regulator/act8945a-regulator.c b/drivers/regulator/act8945a-regulator.c
index e26264529b74..bd54d76efcbc 100644
--- a/drivers/regulator/act8945a-regulator.c
+++ b/drivers/regulator/act8945a-regulator.c
@@ -65,12 +65,10 @@ enum {
 	ACT8945A_ID_LDO2,
 	ACT8945A_ID_LDO3,
 	ACT8945A_ID_LDO4,
-	ACT8945A_ID_MAX,
 };
 
 struct act8945a_pmic {
 	struct regmap *regmap;
-	u32 op_mode[ACT8945A_ID_MAX];
 };
 
 static const struct linear_range act8945a_voltage_ranges[] = {
@@ -142,6 +140,7 @@ static unsigned int act8945a_of_map_mode(unsigned int mode)
 {
 	switch (mode) {
 	case ACT8945A_REGULATOR_MODE_FIXED:
+		return REGULATOR_MODE_FAST;
 	case ACT8945A_REGULATOR_MODE_NORMAL:
 		return REGULATOR_MODE_NORMAL;
 	case ACT8945A_REGULATOR_MODE_LOWPOWER:
@@ -153,10 +152,9 @@ static unsigned int act8945a_of_map_mode(unsigned int mode)
 
 static int act8945a_set_mode(struct regulator_dev *rdev, unsigned int mode)
 {
-	struct act8945a_pmic *act8945a = rdev_get_drvdata(rdev);
 	struct regmap *regmap = rdev->regmap;
 	int id = rdev_get_id(rdev);
-	int reg, ret, val = 0;
+	int reg, val = 0;
 
 	switch (id) {
 	case ACT8945A_ID_DCDC1:
@@ -185,36 +183,64 @@ static int act8945a_set_mode(struct regulator_dev *rdev, unsigned int mode)
 	}
 
 	switch (mode) {
-	case REGULATOR_MODE_STANDBY:
-		if (id > ACT8945A_ID_DCDC3)
-			val = BIT(5);
-		break;
+	case REGULATOR_MODE_FAST:
 	case REGULATOR_MODE_NORMAL:
 		if (id <= ACT8945A_ID_DCDC3)
 			val = BIT(5);
 		break;
+	case REGULATOR_MODE_STANDBY:
+		if (id > ACT8945A_ID_DCDC3)
+			val = BIT(5);
+		break;
 	default:
 		return -EINVAL;
 	}
 
-	ret = regmap_update_bits(regmap, reg, BIT(5), val);
-	if (ret)
-		return ret;
-
-	act8945a->op_mode[id] = mode;
-
-	return 0;
+	return regmap_update_bits(regmap, reg, BIT(5), val);
 }
 
 static unsigned int act8945a_get_mode(struct regulator_dev *rdev)
 {
-	struct act8945a_pmic *act8945a = rdev_get_drvdata(rdev);
+	struct regmap *regmap = rdev->regmap;
 	int id = rdev_get_id(rdev);
+	int reg, ret, val = 0;
 
-	if (id < ACT8945A_ID_DCDC1 || id >= ACT8945A_ID_MAX)
+	switch (id) {
+	case ACT8945A_ID_DCDC1:
+		reg = ACT8945A_DCDC1_CTRL;
+		break;
+	case ACT8945A_ID_DCDC2:
+		reg = ACT8945A_DCDC2_CTRL;
+		break;
+	case ACT8945A_ID_DCDC3:
+		reg = ACT8945A_DCDC3_CTRL;
+		break;
+	case ACT8945A_ID_LDO1:
+		reg = ACT8945A_LDO1_CTRL;
+		break;
+	case ACT8945A_ID_LDO2:
+		reg = ACT8945A_LDO2_CTRL;
+		break;
+	case ACT8945A_ID_LDO3:
+		reg = ACT8945A_LDO3_CTRL;
+		break;
+	case ACT8945A_ID_LDO4:
+		reg = ACT8945A_LDO4_CTRL;
+		break;
+	default:
 		return -EINVAL;
+	}
 
-	return act8945a->op_mode[id];
+	ret = regmap_read(regmap, reg, &val);
+	if (ret)
+		return ret;
+
+	if (id <= ACT8945A_ID_DCDC3 && (val & BIT(5)))
+		return REGULATOR_MODE_FAST;
+	else if	(id > ACT8945A_ID_DCDC3 && !(val & BIT(5)))
+		return REGULATOR_MODE_NORMAL;
+	else
+		return REGULATOR_MODE_STANDBY;
 }
 
 static const struct regulator_ops act8945a_ops = {
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ