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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 30 Jan 2019 17:07:22 +0800
From:   Axel Lin <axel.lin@...ics.com>
To:     Mark Brown <broonie@...nel.org>
Cc:     Bartosz Golaszewski <bgolaszewski@...libre.com>,
        Liam Girdwood <lgirdwood@...il.com>,
        linux-kernel@...r.kernel.org, Axel Lin <axel.lin@...ics.com>
Subject: [PATCH 2/2] regulator: max77650: Convert to use regulator_enable/disable/is_enabled_regmap

By setting enable_reg, enable_mask, enable_val and disable_val, we can
use the regulator_enable/disable/is_enabled_regmap helpers. With this
change, then regB field can be removed from struct max77650_regulator_desc.

Signed-off-by: Axel Lin <axel.lin@...ics.com>
---
Hi Bartosz,
I don't have this h/w, please help to review and test it.

I think the only difference is the is_enabled checking:
Before the patch, it returns en != MAX77650_REGULATOR_DISABLED;
After the patch, it returns en == MAX77650_REGULATOR_ENABLED
I'm not sure if this difference does matter or not.

Thanks,
Axel
 drivers/regulator/max77650-regulator.c | 87 +++++++-------------------
 1 file changed, 23 insertions(+), 64 deletions(-)

diff --git a/drivers/regulator/max77650-regulator.c b/drivers/regulator/max77650-regulator.c
index 5afb91400832..90c0f73f3fad 100644
--- a/drivers/regulator/max77650-regulator.c
+++ b/drivers/regulator/max77650-regulator.c
@@ -13,8 +13,6 @@
 #include <linux/regulator/driver.h>
 
 #define MAX77650_REGULATOR_EN_CTRL_MASK		GENMASK(3, 0)
-#define MAX77650_REGULATOR_EN_CTRL_BITS(_reg) \
-		((_reg) & MAX77650_REGULATOR_EN_CTRL_MASK)
 #define MAX77650_REGULATOR_ENABLED		GENMASK(2, 1)
 #define MAX77650_REGULATOR_DISABLED		BIT(2)
 
@@ -41,7 +39,6 @@ enum {
 struct max77650_regulator_desc {
 	struct regulator_desc desc;
 	unsigned int regA;
-	unsigned int regB;
 };
 
 static const u32 max77651_sbb1_regulator_volt_table[] = {
@@ -86,50 +83,6 @@ static const int max77650_current_limit_table[] = {
 	1000000, 866000, 707000, 500000,
 };
 
-static int max77650_regulator_is_enabled(struct regulator_dev *rdev)
-{
-	struct max77650_regulator_desc *rdesc;
-	struct regmap *map;
-	int val, rv, en;
-
-	rdesc = rdev_get_drvdata(rdev);
-	map = rdev_get_regmap(rdev);
-
-	rv = regmap_read(map, rdesc->regB, &val);
-	if (rv)
-		return rv;
-
-	en = MAX77650_REGULATOR_EN_CTRL_BITS(val);
-
-	return en != MAX77650_REGULATOR_DISABLED;
-}
-
-static int max77650_regulator_enable(struct regulator_dev *rdev)
-{
-	struct max77650_regulator_desc *rdesc;
-	struct regmap *map;
-
-	rdesc = rdev_get_drvdata(rdev);
-	map = rdev_get_regmap(rdev);
-
-	return regmap_update_bits(map, rdesc->regB,
-				  MAX77650_REGULATOR_EN_CTRL_MASK,
-				  MAX77650_REGULATOR_ENABLED);
-}
-
-static int max77650_regulator_disable(struct regulator_dev *rdev)
-{
-	struct max77650_regulator_desc *rdesc;
-	struct regmap *map;
-
-	rdesc = rdev_get_drvdata(rdev);
-	map = rdev_get_regmap(rdev);
-
-	return regmap_update_bits(map, rdesc->regB,
-				  MAX77650_REGULATOR_EN_CTRL_MASK,
-				  MAX77650_REGULATOR_DISABLED);
-}
-
 static int max77650_regulator_set_voltage_sel(struct regulator_dev *rdev,
 					      unsigned int sel)
 {
@@ -140,7 +93,7 @@ static int max77650_regulator_set_voltage_sel(struct regulator_dev *rdev,
 	 * If the regulator is disabled, we can program the desired
 	 * voltage right away.
 	 */
-	if (!max77650_regulator_is_enabled(rdev))
+	if (!regulator_is_enabled_regmap(rdev))
 		return regulator_set_voltage_sel_regmap(rdev, sel);
 
 	/*
@@ -189,7 +142,7 @@ static int max77651_regulator_sbb1_set_voltage_sel(struct regulator_dev *rdev,
 	 * If the regulator is disabled, we can program the desired
 	 * voltage right away.
 	 */
-	if (!max77650_regulator_is_enabled(rdev))
+	if (!regulator_is_enabled_regmap(rdev))
 		return regulator_set_voltage_sel_regmap(rdev, sel);
 
 	curr = regulator_get_voltage_sel_regmap(rdev);
@@ -264,9 +217,9 @@ static int max77650_regulator_set_current_limit(struct regulator_dev *rdev,
 }
 
 static const struct regulator_ops max77650_regulator_LDO_ops = {
-	.is_enabled		= max77650_regulator_is_enabled,
-	.enable			= max77650_regulator_enable,
-	.disable		= max77650_regulator_disable,
+	.is_enabled		= regulator_is_enabled_regmap,
+	.enable			= regulator_enable_regmap,
+	.disable		= regulator_disable_regmap,
 	.list_voltage		= regulator_list_voltage_linear,
 	.map_voltage		= regulator_map_voltage_linear,
 	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
@@ -275,9 +228,9 @@ static const struct regulator_ops max77650_regulator_LDO_ops = {
 };
 
 static const struct regulator_ops max77650_regulator_SBB_ops = {
-	.is_enabled		= max77650_regulator_is_enabled,
-	.enable			= max77650_regulator_enable,
-	.disable		= max77650_regulator_disable,
+	.is_enabled		= regulator_is_enabled_regmap,
+	.enable			= regulator_enable_regmap,
+	.disable		= regulator_disable_regmap,
 	.list_voltage		= regulator_list_voltage_linear,
 	.map_voltage		= regulator_map_voltage_linear,
 	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
@@ -289,9 +242,9 @@ static const struct regulator_ops max77650_regulator_SBB_ops = {
 
 /* Special case for max77651 SBB1 - non-linear voltage mapping. */
 static const struct regulator_ops max77651_SBB1_regulator_ops = {
-	.is_enabled		= max77650_regulator_is_enabled,
-	.enable			= max77650_regulator_enable,
-	.disable		= max77650_regulator_disable,
+	.is_enabled		= regulator_is_enabled_regmap,
+	.enable			= regulator_enable_regmap,
+	.disable		= regulator_disable_regmap,
 	.list_voltage		= regulator_list_voltage_table,
 	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
 	.set_voltage_sel	= max77651_regulator_sbb1_set_voltage_sel,
@@ -313,6 +266,10 @@ static struct max77650_regulator_desc max77650_LDO_desc = {
 		.n_voltages		= 128,
 		.vsel_mask		= MAX77650_REGULATOR_V_LDO_MASK,
 		.vsel_reg		= MAX77650_REG_CNFG_LDO_A,
+		.enable_reg		= MAX77650_REG_CNFG_LDO_B,
+		.enable_mask		= MAX77650_REGULATOR_EN_CTRL_MASK,
+		.enable_val		= MAX77650_REGULATOR_ENABLED,
+		.disable_val		= MAX77650_REGULATOR_DISABLED,
 		.active_discharge_off	= MAX77650_REGULATOR_AD_DISABLED,
 		.active_discharge_on	= MAX77650_REGULATOR_AD_ENABLED,
 		.active_discharge_mask	= MAX77650_REGULATOR_AD_MASK,
@@ -321,7 +278,6 @@ static struct max77650_regulator_desc max77650_LDO_desc = {
 		.type			= REGULATOR_VOLTAGE,
 	},
 	.regA		= MAX77650_REG_CNFG_LDO_A,
-	.regB		= MAX77650_REG_CNFG_LDO_B,
 };
 
 static struct max77650_regulator_desc max77650_SBB0_desc = {
@@ -337,6 +293,10 @@ static struct max77650_regulator_desc max77650_SBB0_desc = {
 		.n_voltages		= 64,
 		.vsel_mask		= MAX77650_REGULATOR_V_SBB_MASK,
 		.vsel_reg		= MAX77650_REG_CNFG_SBB0_A,
+		.enable_reg		= MAX77650_REG_CNFG_LDO_B,
+		.enable_mask		= MAX77650_REGULATOR_EN_CTRL_MASK,
+		.enable_val		= MAX77650_REGULATOR_ENABLED,
+		.disable_val		= MAX77650_REGULATOR_DISABLED,
 		.active_discharge_off	= MAX77650_REGULATOR_AD_DISABLED,
 		.active_discharge_on	= MAX77650_REGULATOR_AD_ENABLED,
 		.active_discharge_mask	= MAX77650_REGULATOR_AD_MASK,
@@ -345,7 +305,6 @@ static struct max77650_regulator_desc max77650_SBB0_desc = {
 		.type			= REGULATOR_VOLTAGE,
 	},
 	.regA		= MAX77650_REG_CNFG_SBB0_A,
-	.regB		= MAX77650_REG_CNFG_SBB0_B,
 };
 
 static struct max77650_regulator_desc max77650_SBB1_desc = {
@@ -361,6 +320,10 @@ static struct max77650_regulator_desc max77650_SBB1_desc = {
 		.n_voltages		= 64,
 		.vsel_mask		= MAX77650_REGULATOR_V_SBB_MASK,
 		.vsel_reg		= MAX77650_REG_CNFG_SBB1_A,
+		.enable_reg		= MAX77650_REG_CNFG_LDO_B,
+		.enable_mask		= MAX77650_REGULATOR_EN_CTRL_MASK,
+		.enable_val		= MAX77650_REGULATOR_ENABLED,
+		.disable_val		= MAX77650_REGULATOR_DISABLED,
 		.active_discharge_off	= MAX77650_REGULATOR_AD_DISABLED,
 		.active_discharge_on	= MAX77650_REGULATOR_AD_ENABLED,
 		.active_discharge_mask	= MAX77650_REGULATOR_AD_MASK,
@@ -369,7 +332,6 @@ static struct max77650_regulator_desc max77650_SBB1_desc = {
 		.type			= REGULATOR_VOLTAGE,
 	},
 	.regA		= MAX77650_REG_CNFG_SBB1_A,
-	.regB		= MAX77650_REG_CNFG_SBB1_B,
 };
 
 static struct max77650_regulator_desc max77651_SBB1_desc = {
@@ -392,7 +354,6 @@ static struct max77650_regulator_desc max77651_SBB1_desc = {
 		.type			= REGULATOR_VOLTAGE,
 	},
 	.regA		= MAX77650_REG_CNFG_SBB1_A,
-	.regB		= MAX77650_REG_CNFG_SBB1_B,
 };
 
 static struct max77650_regulator_desc max77650_SBB2_desc = {
@@ -416,7 +377,6 @@ static struct max77650_regulator_desc max77650_SBB2_desc = {
 		.type			= REGULATOR_VOLTAGE,
 	},
 	.regA		= MAX77650_REG_CNFG_SBB2_A,
-	.regB		= MAX77650_REG_CNFG_SBB2_B,
 };
 
 static struct max77650_regulator_desc max77651_SBB2_desc = {
@@ -440,7 +400,6 @@ static struct max77650_regulator_desc max77651_SBB2_desc = {
 		.type			= REGULATOR_VOLTAGE,
 	},
 	.regA		= MAX77650_REG_CNFG_SBB2_A,
-	.regB		= MAX77650_REG_CNFG_SBB2_B,
 };
 
 static int max77650_regulator_probe(struct platform_device *pdev)
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ