Skip to contentSkip to conversation

add support for MCP16502 PMIC

PATCH RESEND Superseded [email protected] 2 participants 9 messages Dec 11, 2018 – Dec 13, 2018

Subsystems (3)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover add support for MCP16502 PMIC

The resend is because I forgot to add Mark.

MCP16502 is a Power Management IC from Microchip.
It has 4 Buck outputs and 2 LDOs. The buck regulators can be used in two modes: normal(FPWM) and low-power(Auto PFM).

This patch series adds support for the MCP16502 PMIC.

v3:
- use CONFIG_SUSPEND and CONFIG_PM to fix compile errors for some configs

v2:
- use lpm-gpios instead of lpm-gpio in devicetree bindings documentation
- describe the regulators present on the PMIC in the devicetree bindings documentation
- add SPDX license inside a C++ comment
- prefix macro
- remove mcp16502_update_regulator and mcp16502_read
- replace ?: with if-else
- change some if-else with switch statements for legibility
- use regmap helpers for regultor settings during runtime
- make mcp16502_get_status read the status from the PMIC STS registers
- use module_i2c_driver
- use the PMIC's Hibernate registers for suspend-to-mem, the PMIC's Low-power registers for standby and the PMIC's Active registers for normal runtime

Note about mcp16502_suspend:
- mcp16502_gpio_set_mode(mcp, MCP16502_OPMODE_HIB) has now been changed to mcp16502_gpio_set_mode(mcp, MCP16502_OPMODE_LPM) for legibility.

Note that the function call only sets the LPM pin of the PMIC to high. This puts the PMIC in Low-power operating mode. Hibernate operating mode is reached when the MPU sets the PWRHLD line to zero (typically when entering suspend-to-ram).

Andrei Stefanescu (3):
regulator: dt-bindings: add MCP16502 regulator bindings
MAINTAINERS: add maintainer for MCP16502 PMIC driver
regulator: mcp16502: add regulator driver for MCP16502

 .../bindings/regulator/mcp16502-regulator.txt      | 143 ++++++
 MAINTAINERS                                        |   7 +
 drivers/regulator/Kconfig                          |   9 +
 drivers/regulator/Makefile                         |   1 +
 drivers/regulator/mcp16502.c                       | 555 +++++++++++++++++++++
 5 files changed, 715 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/regulator/mcp16502-regulator.txt
 create mode 100644 drivers/regulator/mcp16502.c
Signature · 1 line
2.7.4
#1 lore raw

PATCH RESEND v3 1/3 regulator: dt-bindings: add MCP16502 regulator bindings

This patch describes the compatible and the device tree bindings necessary for the MCP16502 PMIC.

---
 .../bindings/regulator/mcp16502-regulator.txt      | 143 +++++++++++++++++++++
 1 file changed, 143 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/regulator/mcp16502-regulator.txt
Documentation/devicetree/bindings/regulator/mcp16502-regulator.txt new file +143 -0
new file mode 100644
index 0000000..b8f843f
@@ -0,0 +1,143 @@
+MCP16502 PMIC
+
+Required properties:
+- compatible: "microchip,mcp16502"
+- reg: I2C slave address
+- lpm-gpios: GPIO for LPM pin. Note that this GPIO *must* remain high during
+	     suspend-to-ram, keeping the PMIC into HIBERNATE mode.
+- regulators: A node that houses a sub-node for each regulator within
+              the device. Each sub-node is identified using the node's
+              name. The content of each sub-node is defined by the
+              standard binding for regulators; see regulator.txt.
+
+Regualtors of MCP16502 PMIC:
+1) VDD_IO	- Buck (1.2 - 3.7 V)
+2) VDD_DDR	- Buck (0.6 - 1.85 V)
+3) VDD_CORE	- Buck (0.6 - 1.85 V)
+4) VDD_OTHER	- BUCK (0.6 - 1.85 V)
+5) LDO1		- LDO  (1.2 - 3.7 V)
+6) LDO2		- LDO  (1.2 - 3.7 V)
+
+Regulator modes:
+2 - FPWM: higher precision, higher consumption
+4 - AutoPFM: lower precision, lower consumption
+
+Each regulator is defined using the standard binding for regulators.
+
+Example:
+
+mcp16502@5b {
+	compatible = "microchip,mcp16502";
+	reg = <0x5b>;
+	status = "okay";
+	lpm-gpios = <&pioBU 7 GPIO_ACTIVE_HIGH>;
+
+	regulators {
+		VDD_IO {
+			regulator-name = "VDD_IO";
+			regulator-min-microvolt = <1200000>;
+			regulator-max-microvolt = <3700000>;
+			regulator-initial-mode = <2>;
+			regulator-allowed-modes = <2>, <4>;
+			regulator-always-on;
+
+			regulator-state-standby {
+				regulator-on-in-suspend;
+				regulator-mode = <4>;
+			};
+
+			regulator-state-mem {
+				regulator-off-in-suspend;
+				regulator-mode = <4>;
+			};
+		};
+
+		VDD_DDR {
+			regulator-name = "VDD_DDR";
+			regulator-min-microvolt = <600000>;
+			regulator-max-microvolt = <1850000>;
+			regulator-initial-mode = <2>;
+			regulator-allowed-modes = <2>, <4>;
+			regulator-always-on;
+
+			regulator-state-standby {
+				regulator-on-in-suspend;
+				regulator-mode = <4>;
+			};
+
+			regulator-state-mem {
+				regulator-on-in-suspend;
+				regulator-mode = <4>;
+			};
+		};
+
+		VDD_CORE {
+			regulator-name = "VDD_CORE";
+			regulator-min-microvolt = <600000>;
+			regulator-max-microvolt = <1850000>;
+			regulator-initial-mode = <2>;
+			regulator-allowed-modes = <2>, <4>;
+			regulator-always-on;
+
+			regulator-state-standby {
+				regulator-on-in-suspend;
+				regulator-mode = <4>;
+			};
+
+			regulator-state-mem {
+				regulator-off-in-suspend;
+				regulator-mode = <4>;
+			};
+		};
+
+		VDD_OTHER {
+			regulator-name = "VDD_OTHER";
+			regulator-min-microvolt = <600000>;
+			regulator-max-microvolt = <1850000>;
+			regulator-initial-mode = <2>;
+			regulator-allowed-modes = <2>, <4>;
+			regulator-always-on;
+
+			regulator-state-standby {
+				regulator-on-in-suspend;
+				regulator-mode = <4>;
+			};
+
+			regulator-state-mem {
+				regulator-off-in-suspend;
+				regulator-mode = <4>;
+			};
+		};
+
+		LDO1 {
+			regulator-name = "LDO1";
+			regulator-min-microvolt = <1200000>;
+			regulator-max-microvolt = <3700000>;
+			regulator-always-on;
+
+			regulator-state-standby {
+				regulator-on-in-suspend;
+			};
+
+			regulator-state-mem {
+				regulator-off-in-suspend;
+			};
+		};
+
+		LDO2 {
+			regulator-name = "LDO2";
+			regulator-min-microvolt = <1200000>;
+			regulator-max-microvolt = <3700000>;
+			regulator-always-on;
+
+			regulator-state-standby {
+				regulator-on-in-suspend;
+			};
+
+			regulator-state-mem {
+				regulator-off-in-suspend;
+			};
+		};
+
+	};
+};
Signature · 1 line
2.7.4
#2 lore raw

PATCH RESEND v3 2/3 MAINTAINERS: add maintainer for MCP16502 PMIC driver

In reply to [email protected]

This patch adds a maintainer for the MCP16502 PMIC driver.

---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
index b755a89..6a74a65 100644
@@ -9730,6 +9730,13 @@ M:	Ludovic Desroches <[email protected]>
 S:	Maintained
 F:	drivers/mmc/host/atmel-mci.c
 
+MICROCHIP MCP16502 PMIC DRIVER
+M:	Andrei Stefanescu <[email protected]>
+L:	[email protected] (moderated for non-subscribers)
+S:	Maintained
+F:	Documentation/devicetree/bindings/regulator/mcp16502-regulator.txt
+F:	drivers/regulator/mcp16502.c
+
 MICROCHIP MCP3911 ADC DRIVER
 M:	Marcus Folkesson <[email protected]>
 M:	Kent Gustavsson <[email protected]>
Signature · 1 line
2.7.4
#3 lore raw

PATCH RESEND v3 3/3 regulator: mcp16502: add regulator driver for MCP16502

In reply to [email protected]

This patch adds a regulator driver for the MCP16502 PMIC. This drivers supports basic operations through the regulator interface such as:
- setting/reading voltage
- setting/reading operating mode
- reading current status
- transitioning to/from suspend-to-ram and standby power states

---
 drivers/regulator/Kconfig    |   9 +
 drivers/regulator/Makefile   |   1 +
 drivers/regulator/mcp16502.c | 555 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 565 insertions(+)
 create mode 100644 drivers/regulator/mcp16502.c
drivers/regulator/Kconfig +9 -0
index 926cee0..719d9d6 100644
@@ -567,6 +567,15 @@ config REGULATOR_MC13892
 	  Say y here to support the regulators found on the Freescale MC13892
 	  PMIC.
 
+config REGULATOR_MCP16502
+	tristate "Microchip MCP16502 PMIC"
+	depends on I2C && OF
+	help
+	  Say y here to support the MCP16502 PMIC. This driver supports
+	  basic operations (get/set voltage, get/set operating mode)
+	  through the regulator interface. In addition it enables
+	  suspend-to-ram/standby transition.
+
 config REGULATOR_MT6311
 	tristate "MediaTek MT6311 PMIC"
 	depends on I2C
drivers/regulator/Makefile +1 -0
index 72488ef..b12e1c9 100644
@@ -74,6 +74,7 @@ obj-$(CONFIG_REGULATOR_MAX77802) += max77802-regulator.o
 obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o
 obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o
 obj-$(CONFIG_REGULATOR_MC13XXX_CORE) +=  mc13xxx-regulator-core.o
+obj-$(CONFIG_REGULATOR_MCP16502) += mcp16502.o
 obj-$(CONFIG_REGULATOR_MT6311) += mt6311-regulator.o
 obj-$(CONFIG_REGULATOR_MT6323)	+= mt6323-regulator.o
 obj-$(CONFIG_REGULATOR_MT6380)	+= mt6380-regulator.o
drivers/regulator/mcp16502.c new file +555 -0

555 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#4 lore raw

Re: [RESEND PATCH v3 3/3] regulator: mcp16502: add regulator driver for MCP16502

Quoted 3 lines · On Tue, Dec 11, 2018 at 10:09:15AM +0000, [email protected] wrote:

This patch adds a regulator driver for the MCP16502 PMIC. This drivers supports basic operations through the regulator interface such as:

Overall this looks really good, just a couple of comments:

drivers/regulator/mcp16502.c line 3

Quoted 5 lines

+++ b/drivers/regulator/mcp16502.c

drivers/regulator/mcp16502.c new file +3 -0
@@ -0,0 +1,555 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * MCP16502 PMIC driver

SPDX headers need to be C++ comments - please make the entire comment block a C++ one so it looks more intentional.

drivers/regulator/mcp16502.c line 511

Quoted 10 lines
drivers/regulator/mcp16502.c new file +10 -0
+#ifdef CONFIG_SUSPEND
+static int mcp16502_suspend(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct mcp16502 *mcp = i2c_get_clientdata(client);
+
+	mcp16502_gpio_set_mode(mcp, MCP16502_OPMODE_LPM);
+
+	return 0;
+}

This puts the device into low power mode when the suspend function gets called but this might not be safe - devices using the regulator may not be suspended yet so could still need full regulation. Normally a GPIO triggered transition like this would be being done by hardware as part of the process of suspending the SoC. Is there some reason to do this manually?

#5 lore raw

Re: [RESEND PATCH v3 3/3] regulator: mcp16502: add regulator driver for MCP16502

Hi Mark,

Thank you for the review.

Quoted 2 lines

SPDX headers need to be C++ comments - please make the entire comment block a C++ one so it looks more intentional.

I sent a new patch (v4) with the modified comment.

Quoted 8 lines
Quoted 8 lines
drivers/regulator/mcp16502.c new file +8 -0
+#ifdef CONFIG_SUSPEND
+static int mcp16502_suspend(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct mcp16502 *mcp = i2c_get_clientdata(client);
+
+	mcp16502_gpio_set_mode(mcp, MCP16502_OPMODE_LPM);
+
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	return 0;
+}

This puts the device into low power mode when the suspend function gets called but this might not be safe - devices using the regulator may not be suspended yet so could still need full regulation. Normally a GPIO triggered transition like this would be being done by hardware as part of the process of suspending the SoC. Is there some reason to do this manually?

There is a line from the MPU (SHDN) which goes low only when the MPU turns off. That line is already connected to the PMIC and it differentiates between suspend-to-mem and standby. To switch to low-power, the PMIC must be controlled by the GPIO pin LPM.

The suspend sequence is:
- LPM pin goes high (PMIC enters Low-Power <-> Linux standby)
- SHDN goes low (if target suspend state is mem) and then PMIC enters HIBERNATE

Best regards,
Andrei

maintainer
#6 lore raw

Re: [RESEND PATCH v3 3/3] regulator: mcp16502: add regulator driver for MCP16502

Quoted 12 lines · On Wed, Dec 12, 2018 at 08:01:07AM +0000, [email protected] wrote:
Quoted 6 lines

This puts the device into low power mode when the suspend function gets called but this might not be safe - devices using the regulator may not be suspended yet so could still need full regulation. Normally a GPIO triggered transition like this would be being done by hardware as part of the process of suspending the SoC. Is there some reason to do this manually?

There is a line from the MPU (SHDN) which goes low only when the MPU turns off. That line is already connected to the PMIC and it differentiates between suspend-to-mem and standby. To switch to low-power, the PMIC must be controlled by the GPIO pin LPM.

Quoted 4 lines

The suspend sequence is:
- LPM pin goes high (PMIC enters Low-Power <-> Linux standby)
- SHDN goes low (if target suspend state is mem) and then PMIC enters HIBERNATE

This feels like it should be being controlled somewhere else, if it's actually causing a change in the PMIC state it seems like it wants to be done as late as possible in suspend to minimize the risks. At the very least suspend_late() for the driver seems appropriate.

Could you submit a version with this feature at least split out into a separate patch please so we can apply the rest of the code while this is discussed?

#7 lore raw

Re: [RESEND PATCH v3 3/3] regulator: mcp16502: add regulator driver for MCP16502

Hi Mark,

Quoted 16 lines · Mark Brown
Quoted 6 lines · On Wed, Dec 12, 2018 at 08:01:07AM +0000, [email protected] wrote:
Quoted 6 lines

This puts the device into low power mode when the suspend function gets called but this might not be safe - devices using the regulator may not be suspended yet so could still need full regulation. Normally a GPIO triggered transition like this would be being done by hardware as part of the process of suspending the SoC. Is there some reason to do this manually?

Quoted 8 lines

There is a line from the MPU (SHDN) which goes low only when the MPU turns off. That line is already connected to the PMIC and it differentiates between suspend-to-mem and standby. To switch to low-power, the PMIC must be controlled by the GPIO pin LPM.
The suspend sequence is:
- LPM pin goes high (PMIC enters Low-Power <-> Linux standby)
- SHDN goes low (if target suspend state is mem) and then PMIC enters HIBERNATE

Quoted 4 lines

This feels like it should be being controlled somewhere else, if it's actually causing a change in the PMIC state it seems like it wants to be done as late as possible in suspend to minimize the risks. At the very least suspend_late() for the driver seems appropriate.

I tried with both suspend_late/resume_early and suspend_noirq/resume_noirq. Everything seems to work ok.

Which one do you think is more appropriate? I am guessing that during suspend_late some devices may still need to be turned on and that it would be the safest during suspend_noirq.

Note: the GPIO pin used for LPM is a special one (it maintains its voltage during
suspend-to-mem). It is part of the SoC and its methods for setting the values
do not sleep.

Quoted 4 lines

Could you submit a version with this feature at least split out into a separate patch please so we can apply the rest of the code while this is discussed?

Sent one patch series and another patch with the current suspend/resume implementation.

Best regards,
Andrei

maintainer
#8 lore raw

Re: [RESEND PATCH v3 3/3] regulator: mcp16502: add regulator driver for MCP16502

Quoted 6 lines · On Thu, Dec 13, 2018 at 12:19:16PM +0000, [email protected] wrote:

I tried with both suspend_late/resume_early and suspend_noirq/resume_noirq. Everything seems to work ok.

Which one do you think is more appropriate? I am guessing that during suspend_late some devices may still need to be turned on and that it would be the safest during suspend_noirq.

I agree, noirq is going to be the safest option. Can you respin with that please?