Skip to contentSkip to conversation

regulator: max14577: Add set_suspend_mode for MAX77836 LDOs

PATCH Superseded Jad Keskes 2 participants 5 messages Jun 15 – Jun 16

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jad Keskes

author
#0 lore raw

PATCH 1/1 regulator: max14577: Add set_suspend_mode for MAX77836 LDOs

The MAX77836 LDOs support three power modes via the PWRMD field in CNFG1_LDO registers: normal, low-power, and off. Implement the set_suspend_mode callback so the regulator core can switch LDOs to the appropriate mode on system suspend, rather than leaving them in the default operating mode.

Remove the TODO comment that has been sitting here since the driver was first added.

---
 drivers/regulator/max14577-regulator.c | 25 ++++++++++++++++++++++++-
 include/linux/mfd/max14577-private.h   |  3 +++
 2 files changed, 27 insertions(+), 1 deletion(-)
drivers/regulator/max14577-regulator.c +24 -1
index 41fd15adfd1f..b7bd459e8a09 100644
@@ -123,6 +123,29 @@ static const struct regulator_desc max14577_supported_regulators[] = {
 	[MAX14577_CHARGER] = MAX14577_CHARGER_REG,
 };
 
+static int max77836_ldo_set_suspend_mode(struct regulator_dev *rdev,
+		unsigned int mode)
+{
+	unsigned int val;
+
+	switch (mode) {
+	case REGULATOR_MODE_NORMAL:
+		val = MAX77836_CNFG1_LDO_PWRMD_NORMAL;
+		break;
+	case REGULATOR_MODE_IDLE:
+		val = MAX77836_CNFG1_LDO_PWRMD_LPM;
+		break;
+	case REGULATOR_MODE_STANDBY:
+		val = MAX77836_CNFG1_LDO_PWRMD_OFF;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
+		MAX77836_CNFG1_LDO_PWRMD_MASK, val);
+}
+
 static const struct regulator_ops max77836_ldo_ops = {
 	.is_enabled		= regulator_is_enabled_regmap,
 	.enable			= regulator_enable_regmap,
@@ -131,7 +154,7 @@ static const struct regulator_ops max77836_ldo_ops = {
 	.map_voltage		= regulator_map_voltage_linear,
 	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
 	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
-	/* TODO: add .set_suspend_mode */
+	.set_suspend_mode	= max77836_ldo_set_suspend_mode,
 };
 
 #define MAX77836_LDO_REG(num)	{ \
include/linux/mfd/max14577-private.h +3 -0
index dd51a37fa37f..5957e15b568e 100644
@@ -350,6 +350,9 @@ enum max77836_pmic_reg {
 #define MAX77836_CNFG1_LDO_PWRMD_SHIFT		6
 #define MAX77836_CNFG1_LDO_TV_SHIFT		0
 #define MAX77836_CNFG1_LDO_PWRMD_MASK		(0x3 << MAX77836_CNFG1_LDO_PWRMD_SHIFT)
+#define MAX77836_CNFG1_LDO_PWRMD_OFF		(0x0 << MAX77836_CNFG1_LDO_PWRMD_SHIFT)
+#define MAX77836_CNFG1_LDO_PWRMD_LPM		(0x1 << MAX77836_CNFG1_LDO_PWRMD_SHIFT)
+#define MAX77836_CNFG1_LDO_PWRMD_NORMAL		(0x3 << MAX77836_CNFG1_LDO_PWRMD_SHIFT)
 #define MAX77836_CNFG1_LDO_TV_MASK		(0x3f << MAX77836_CNFG1_LDO_TV_SHIFT)
 
 /* LDO1/LDO2 CONFIG2 register */
Signature · 1 line
2.54.0
maintainer
#1 lore raw
Quoted 5 lines · Jad Keskes

The MAX77836 LDOs support three power modes via the PWRMD field in CNFG1_LDO registers: normal, low-power, and off. Implement the set_suspend_mode callback so the regulator core can switch LDOs to the appropriate mode on system suspend, rather than leaving them in the default operating mode.

Are you sure this is a specific suspend mode and not just the regular operating mode for the regulator? It updates the same register as the standard enable/disable and there's nothing in the register names that'd suggest anything other than a standard mode control.

author
#2 lore raw

PATCH v2 1/1 regulator: max14577: Add set_mode/get_mode for MAX77836 LDOs

In reply to Jad Keskes

The MAX77836 LDOs support two operating modes via the PWRMD field in CNFG1_LDO registers: normal and low-power (5 mA max load, reduced quiescent current). Implement the get_mode and set_mode callbacks so consumers can switch between them.

The PWRMD field is the same register used for enable/disable and controls the immediate operating mode, rather than a suspend-specific behavior. Use set_mode instead of the originally-requested set_suspend_mode.

Remove the TODO comment that has been sitting here since the driver was first added.

---
 drivers/regulator/max14577-regulator.c | 43 +++++++++++++++++++++++++-
 include/linux/mfd/max14577-private.h   |  3 ++
 2 files changed, 45 insertions(+), 1 deletion(-)
drivers/regulator/max14577-regulator.c +42 -1
index 41fd15adfd1f..5c56a12dcefc 100644
@@ -123,6 +123,46 @@ static const struct regulator_desc max14577_supported_regulators[] = {
 	[MAX14577_CHARGER] = MAX14577_CHARGER_REG,
 };
 
+static unsigned int max77836_ldo_get_mode(struct regulator_dev *rdev)
+{
+	unsigned int val;
+	int ret;
+
+	ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
+	if (ret)
+		return ret;
+
+	val &= MAX77836_CNFG1_LDO_PWRMD_MASK;
+	switch (val) {
+	case MAX77836_CNFG1_LDO_PWRMD_LPM:
+		return REGULATOR_MODE_IDLE;
+	case MAX77836_CNFG1_LDO_PWRMD_NORMAL:
+		return REGULATOR_MODE_NORMAL;
+	default:
+		return REGULATOR_MODE_INVALID;
+	}
+}
+
+static int max77836_ldo_set_mode(struct regulator_dev *rdev,
+		unsigned int mode)
+{
+	unsigned int val;
+
+	switch (mode) {
+	case REGULATOR_MODE_NORMAL:
+		val = MAX77836_CNFG1_LDO_PWRMD_NORMAL;
+		break;
+	case REGULATOR_MODE_IDLE:
+		val = MAX77836_CNFG1_LDO_PWRMD_LPM;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
+		MAX77836_CNFG1_LDO_PWRMD_MASK, val);
+}
+
 static const struct regulator_ops max77836_ldo_ops = {
 	.is_enabled		= regulator_is_enabled_regmap,
 	.enable			= regulator_enable_regmap,
@@ -131,7 +171,8 @@ static const struct regulator_ops max77836_ldo_ops = {
 	.map_voltage		= regulator_map_voltage_linear,
 	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
 	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
-	/* TODO: add .set_suspend_mode */
+	.get_mode		= max77836_ldo_get_mode,
+	.set_mode		= max77836_ldo_set_mode,
 };
 
 #define MAX77836_LDO_REG(num)	{ \
include/linux/mfd/max14577-private.h +3 -0
index dd51a37fa37f..5957e15b568e 100644
@@ -350,6 +350,9 @@ enum max77836_pmic_reg {
 #define MAX77836_CNFG1_LDO_PWRMD_SHIFT		6
 #define MAX77836_CNFG1_LDO_TV_SHIFT		0
 #define MAX77836_CNFG1_LDO_PWRMD_MASK		(0x3 << MAX77836_CNFG1_LDO_PWRMD_SHIFT)
+#define MAX77836_CNFG1_LDO_PWRMD_OFF		(0x0 << MAX77836_CNFG1_LDO_PWRMD_SHIFT)
+#define MAX77836_CNFG1_LDO_PWRMD_LPM		(0x1 << MAX77836_CNFG1_LDO_PWRMD_SHIFT)
+#define MAX77836_CNFG1_LDO_PWRMD_NORMAL		(0x3 << MAX77836_CNFG1_LDO_PWRMD_SHIFT)
 #define MAX77836_CNFG1_LDO_TV_MASK		(0x3f << MAX77836_CNFG1_LDO_TV_SHIFT)
 
 /* LDO1/LDO2 CONFIG2 register */
Signature · 1 line
2.54.0
maintainer
#3 lore raw

Re: [PATCH v2] regulator: max14577: Add set_mode/get_mode for MAX77836 LDOs

Quoted 4 lines · Jad Keskes

The MAX77836 LDOs support two operating modes via the PWRMD field in CNFG1_LDO registers: normal and low-power (5 mA max load, reduced quiescent current). Implement the get_mode and set_mode callbacks so consumers can switch between them.

Please don't send new patches in reply to old patches or serieses, this makes it harder for both people and tools to understand what is going on - it can bury things in mailboxes and make it difficult to keep track of what current patches are, both for the new patches and the old ones.

maintainer
#4 lore raw

Re: [PATCH v2] regulator: max14577: Add set_mode/get_mode for MAX77836 LDOs

In reply to Jad Keskes
Quoted 14 lines · Jad Keskes

The MAX77836 LDOs support two operating modes via the PWRMD field in CNFG1_LDO registers: normal and low-power (5 mA max load, reduced quiescent current). Implement the get_mode and set_mode callbacks so consumers can switch between them.

drivers/regulator/max14577-regulator.c +9 -0
+static int max77836_ldo_set_mode(struct regulator_dev *rdev,
+		unsigned int mode)
+{
+	unsigned int val;
+
+	switch (mode) {
+	case REGULATOR_MODE_NORMAL:
+		val = MAX77836_CNFG1_LDO_PWRMD_NORMAL;
+		break;

drivers/regulator/max14577-regulator.c static const struct regulator_desc max14577_supported_regulators[] = { · line 164

Quoted 10 lines
drivers/regulator/max14577-regulator.c +10 -0
+	case REGULATOR_MODE_IDLE:
+		val = MAX77836_CNFG1_LDO_PWRMD_LPM;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
+		MAX77836_CNFG1_LDO_PWRMD_MASK, val);
+}

Since this is the same register we're using for enable this will fight with enable, setting the mode will enable the regulator and enabling or disabling will overwrite the mode. You'll need to store the mode in the driver data and have a custom enable operation which applies the current mode when enabling rather than a fixed value.

You should also add a of_map_mode() operation so the mode can be set from DT.