Skip to contentSkip to conversation

spacemit: introduce P1 PMIC support

PATCH Superseded Alex Elder 2 participants 13 messages Jul 2, 2025 – Jul 10, 2025

Subsystems (6)

v7 of 13 Superseded Latest is v13 →

lore
Share & tools
lore

Alex Elder

author
#0 lore raw

v7 cover spacemit: introduce P1 PMIC support

The SpacemiT P1 is an I2C-controlled PMIC that implements 6 buck converters and 12 LDOs. It contains a load switch, ADC channels, GPIOs, a real-time clock, and a watchdog timer.

This series introduces a multifunction driver for the P1 PMIC as well as drivers for its regulators and RTC.

In v6, a new patch was added to change the simple MFD driver to allow the regmap max_register value in the simple MFD configuration. However it also removed the option of specifying a "full" regmap configuration, and that was not what Lee Jones actually wanted.

This version adds the max_register option, but also retains the ability to supply a full regmap config. (If both are specified, the max_register value is ignored.)

-Alex

This series is available here:
https://github.com/riscstar/linux/tree/outgoing/pmic-v7

Between version 5 and version 6:
- Revise patch 2 to preserve the option to provide a full regmap config

Here is version 6 of this series:
https://lore.kernel.org/lkml/[email protected]/

Between version 5 and version 6:
- Added Rob Herring's reviewed-by to patch 1
- Add the simple MFD functionality suggested by Lee Jones
- Update patch 3 (previously 2) accordingly

Here is version 5 of this series:
https://lore.kernel.org/lkml/[email protected]/

Between version 4 and version 5:
- Only check the seconds register for change when looping on read
- Return without re-enabling the RTC if writing registers fails
- If the RTC is disabled when reading, return an error

Here is version 4 of this series:
https://lore.kernel.org/lkml/[email protected]/

More complete history is available at that link.

Alex Elder (8):
dt-bindings: mfd: add support the SpacemiT P1 PMIC
mfd: simple-mfd-i2c: specify max_register
mfd: simple-mfd-i2c: add SpacemiT P1 support
regulator: spacemit: support SpacemiT P1 regulators
rtc: spacemit: support the SpacemiT P1 RTC
riscv: dts: spacemit: enable the i2c8 adapter
riscv: dts: spacemit: define fixed regulators
riscv: dts: spacemit: define regulator constraints

 .../devicetree/bindings/mfd/spacemit,p1.yaml  |  86 +++++++++
 .../boot/dts/spacemit/k1-bananapi-f3.dts      | 138 +++++++++++++++
 arch/riscv/boot/dts/spacemit/k1-pinctrl.dtsi  |   7 +
 arch/riscv/boot/dts/spacemit/k1.dtsi          |  11 ++
 drivers/mfd/Kconfig                           |  11 ++
 drivers/mfd/simple-mfd-i2c.c                  |  27 ++-
 drivers/mfd/simple-mfd-i2c.h                  |   1 +
 drivers/regulator/Kconfig                     |  12 ++
 drivers/regulator/Makefile                    |   1 +
 drivers/regulator/spacemit-p1.c               | 157 ++++++++++++++++
 drivers/rtc/Kconfig                           |  10 ++
 drivers/rtc/Makefile                          |   1 +
 drivers/rtc/rtc-spacemit-p1.c                 | 167 ++++++++++++++++++
 13 files changed, 626 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mfd/spacemit,p1.yaml
 create mode 100644 drivers/regulator/spacemit-p1.c
 create mode 100644 drivers/rtc/rtc-spacemit-p1.c

base-commit: 50c8770a42faf8b1c7abe93e7c114337f580a97d

Signature · 1 line
2.45.2
author
#1 lore raw

PATCH v7 1/8 dt-bindings: mfd: add support the SpacemiT P1 PMIC

Enable the SpacemiT P1, which is an I2C-controlled PMIC. Initially only the RTC and regulators will be supported.

---
 .../devicetree/bindings/mfd/spacemit,p1.yaml  | 86 +++++++++++++++++++
 1 file changed, 86 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/spacemit,p1.yaml
Documentation/devicetree/bindings/mfd/spacemit,p1.yaml new file +86 -0
new file mode 100644
index 0000000000000..5cc34d4934b54
@@ -0,0 +1,86 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/spacemit,p1.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SpacemiT P1 Power Management Integrated Circuit
+
+maintainers:
+  - Troy Mitchell <[email protected]>
+
+description:
+  P1 is an I2C-controlled PMIC produced by SpacemiT.  It implements six
+  constant-on-time buck converters and twelve low-dropout regulators.
+  It also contains a load switch, watchdog timer, real-time clock, eight
+  12-bit ADC channels, and six GPIOs.  Additional details are available
+  in the "Power Stone/P1" section at the following link.
+    https://developer.spacemit.com/documentation
+
+properties:
+  compatible:
+    const: spacemit,p1
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  vin-supply:
+    description: Input supply phandle.
+
+  regulators:
+    type: object
+
+    patternProperties:
+      "^(buck[1-6]|aldo[1-4]|dldo[1-7])$":
+        type: object
+        $ref: /schemas/regulator/regulator.yaml#
+        unevaluatedProperties: false
+
+    unevaluatedProperties: false
+
+required:
+  - compatible
+  - reg
+  - interrupts
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        pmic@41 {
+            compatible = "spacemit,p1";
+            reg = <0x41>;
+            interrupts = <64>;
+
+            regulators {
+                buck1 {
+                    regulator-name = "buck1";
+                    regulator-min-microvolt = <500000>;
+                    regulator-max-microvolt = <3450000>;
+                    regulator-ramp-delay = <5000>;
+                    regulator-always-on;
+                };
+
+                aldo1 {
+                    regulator-name = "aldo1";
+                    regulator-min-microvolt = <500000>;
+                    regulator-max-microvolt = <3400000>;
+                    regulator-boot-on;
+                };
+
+                dldo1 {
+                    regulator-name = "dldo1";
+                    regulator-min-microvolt = <500000>;
+                    regulator-max-microvolt = <3400000>;
+                    regulator-boot-on;
+                };
+            };
+        };
+    };
Signature · 1 line
2.45.2
author
#2 lore raw

PATCH v7 2/8 mfd: simple-mfd-i2c: specify max_register

In reply to Alex Elder

All devices supported by simple MFD use the same 8-bit register 8-bit value regmap configuration. There is an option available for a device to specify a custom configuration, but no existing device uses it.

Rather than specify a "full" regmap configuration to use this option, Lee Jones suggested allowing just the max_register value to be specified in the simple_mfd_data structure.

---
v2: - Allow max_register *and* regmap_config to be supplied

 drivers/mfd/simple-mfd-i2c.c | 15 ++++++++++++---
 drivers/mfd/simple-mfd-i2c.h |  1 +
 2 files changed, 13 insertions(+), 3 deletions(-)
drivers/mfd/simple-mfd-i2c.c +12 -3
index 22159913bea03..3f959f4f98261 100644
@@ -33,16 +33,25 @@ static int simple_mfd_i2c_probe(struct i2c_client *i2c)
 {
 	const struct simple_mfd_data *simple_mfd_data;
 	const struct regmap_config *regmap_config;
+	struct regmap_config config;
 	struct regmap *regmap;
 	int ret;
 
 	simple_mfd_data = device_get_match_data(&i2c->dev);
 
 	/* If no regmap_config is specified, use the default 8reg and 8val bits */
-	if (!simple_mfd_data || !simple_mfd_data->regmap_config)
+	if (simple_mfd_data) {
+		if (simple_mfd_data->regmap_config)
+			config = *simple_mfd_data->regmap_config;
+		else
+			config = regmap_config_8r_8v;
+
+		if (simple_mfd_data->max_register)
+			config.max_register = simple_mfd_data->max_register;
+		regmap_config = &config;
+	} else {
 		regmap_config = &regmap_config_8r_8v;
-	else
-		regmap_config = simple_mfd_data->regmap_config;
+	}
 
 	regmap = devm_regmap_init_i2c(i2c, regmap_config);
 	if (IS_ERR(regmap))
drivers/mfd/simple-mfd-i2c.h +1 -0
index 7cb2bdd347d97..706b6f53155ff 100644
@@ -27,6 +27,7 @@ struct simple_mfd_data {
 	const struct regmap_config *regmap_config;
 	const struct mfd_cell *mfd_cell;
 	size_t mfd_cell_size;
+	unsigned int max_register;
 };
 
 #endif /* __MFD_SIMPLE_MFD_I2C_H */
Signature · 1 line
2.45.2
maintainer
#3 lore raw

Re: [PATCH v7 2/8] mfd: simple-mfd-i2c: specify max_register

Quoted 23 lines · Alex Elder

All devices supported by simple MFD use the same 8-bit register 8-bit value regmap configuration. There is an option available for a device to specify a custom configuration, but no existing device uses it.

Rather than specify a "full" regmap configuration to use this option, Lee Jones suggested allowing just the max_register value to be specified in the simple_mfd_data structure.

---
v2: - Allow max_register *and* regmap_config to be supplied

 drivers/mfd/simple-mfd-i2c.c | 15 ++++++++++++---
 drivers/mfd/simple-mfd-i2c.h |  1 +
 2 files changed, 13 insertions(+), 3 deletions(-)
drivers/mfd/simple-mfd-i2c.c +0 -0
index 22159913bea03..3f959f4f98261 100644

drivers/mfd/simple-mfd-i2c.c static int simple_mfd_i2c_probe(struct i2c_client *i2c) · line 37

Quoted 5 lines
drivers/mfd/simple-mfd-i2c.c +1 -0
@@ -33,16 +33,25 @@ static int simple_mfd_i2c_probe(struct i2c_client *i2c)
 {
 	const struct simple_mfd_data *simple_mfd_data;
 	const struct regmap_config *regmap_config;
 
+	struct regmap_config config;

Why do we need another regmap_config?

Can't we just remove the const and make use of the one above?

drivers/mfd/simple-mfd-i2c.c static int simple_mfd_i2c_probe(struct i2c_client *i2c) · line 45

Quoted 10 lines
drivers/mfd/simple-mfd-i2c.c +3 -1
 	struct regmap *regmap;
 	int ret;
 
 	simple_mfd_data = device_get_match_data(&i2c->dev);
 
 	/* If no regmap_config is specified, use the default 8reg and 8val bits */
-	if (!simple_mfd_data || !simple_mfd_data->regmap_config)
+	if (simple_mfd_data) {
+		if (simple_mfd_data->regmap_config)
+			config = *simple_mfd_data->regmap_config;
			regmap_config = simple_mfd_data->regmap_config;

drivers/mfd/simple-mfd-i2c.c static int simple_mfd_i2c_probe(struct i2c_client *i2c) · line 47

Quoted 2 lines
drivers/mfd/simple-mfd-i2c.c +2 -0
+		else
+			config = regmap_config_8r_8v;
			regmap_config = &regmap_config_8r_8v;

drivers/mfd/simple-mfd-i2c.c static int simple_mfd_i2c_probe(struct i2c_client *i2c) · line 53

Quoted 6 lines
drivers/mfd/simple-mfd-i2c.c +5 -0
+
+		if (simple_mfd_data->max_register)
+			config.max_register = simple_mfd_data->max_register;
+		regmap_config = &config;
+	} else {
 		regmap_config = &regmap_config_8r_8v;

I suspect we don't need to have this line twice.

Either re-jig the if () above (I suspect this explains the existing complexity [multiple conditions]) or pre-set regmap_config to regmap_config_8r_8v and only over-write it if the conditions are met.

Quoted 15 lines
drivers/mfd/simple-mfd-i2c.c +1 -1
-	else -		regmap_config = simple_mfd_data->regmap_config;
+	}
 
 	regmap = devm_regmap_init_i2c(i2c, regmap_config); if
 	(IS_ERR(regmap)) diff --git a/drivers/mfd/simple-mfd-i2c.h
 	b/drivers/mfd/simple-mfd-i2c.h index
 	7cb2bdd347d97..706b6f53155ff 100644 ---
 	a/drivers/mfd/simple-mfd-i2c.h +++
 	b/drivers/mfd/simple-mfd-i2c.h @@ -27,6 +27,7 @@ struct
 	simple_mfd_data { const struct regmap_config *regmap_config;
 	const struct mfd_cell *mfd_cell; size_t mfd_cell_size; +
 	unsigned int max_register; };
 
 #endif /* __MFD_SIMPLE_MFD_I2C_H */ -- 2.45.2
Signature · 1 line
Lee Jones [李琼斯]
maintainer
#4 lore raw

Re: [PATCH v7 2/8] mfd: simple-mfd-i2c: specify max_register

Quoted 61 lines · Lee Jones
Quoted 23 lines · Alex Elder

All devices supported by simple MFD use the same 8-bit register 8-bit value regmap configuration. There is an option available for a device to specify a custom configuration, but no existing device uses it.

Rather than specify a "full" regmap configuration to use this option, Lee Jones suggested allowing just the max_register value to be specified in the simple_mfd_data structure.

---
v2: - Allow max_register *and* regmap_config to be supplied

 drivers/mfd/simple-mfd-i2c.c | 15 ++++++++++++---
 drivers/mfd/simple-mfd-i2c.h |  1 +
 2 files changed, 13 insertions(+), 3 deletions(-)
drivers/mfd/simple-mfd-i2c.c +0 -0
index 22159913bea03..3f959f4f98261 100644

drivers/mfd/simple-mfd-i2c.c static int simple_mfd_i2c_probe(struct i2c_client *i2c) · line 37

Quoted 5 lines
drivers/mfd/simple-mfd-i2c.c +1 -0
@@ -33,16 +33,25 @@ static int simple_mfd_i2c_probe(struct i2c_client *i2c)
 {
 	const struct simple_mfd_data *simple_mfd_data;
 	const struct regmap_config *regmap_config;
 
+	struct regmap_config config;

Why do we need another regmap_config?

Can't we just remove the const and make use of the one above?

drivers/mfd/simple-mfd-i2c.c static int simple_mfd_i2c_probe(struct i2c_client *i2c) · line 45

Quoted 10 lines
drivers/mfd/simple-mfd-i2c.c +3 -1
 	struct regmap *regmap;
 	int ret;
 
 	simple_mfd_data = device_get_match_data(&i2c->dev);
 
 	/* If no regmap_config is specified, use the default 8reg and 8val bits */
-	if (!simple_mfd_data || !simple_mfd_data->regmap_config)
+	if (simple_mfd_data) {
+		if (simple_mfd_data->regmap_config)
+			config = *simple_mfd_data->regmap_config;
			regmap_config = simple_mfd_data->regmap_config;

drivers/mfd/simple-mfd-i2c.c static int simple_mfd_i2c_probe(struct i2c_client *i2c) · line 47

Quoted 2 lines
drivers/mfd/simple-mfd-i2c.c +2 -0
+		else
+			config = regmap_config_8r_8v;
			regmap_config = &regmap_config_8r_8v;

drivers/mfd/simple-mfd-i2c.c static int simple_mfd_i2c_probe(struct i2c_client *i2c) · line 53

Quoted 6 lines
drivers/mfd/simple-mfd-i2c.c +5 -0
+
+		if (simple_mfd_data->max_register)
+			config.max_register = simple_mfd_data->max_register;
+		regmap_config = &config;
+	} else {
 		regmap_config = &regmap_config_8r_8v;

I suspect we don't need to have this line twice.

Quoted 3 lines

Either re-jig the if () above (I suspect this explains the existing complexity [multiple conditions]) or pre-set regmap_config to regmap_config_8r_8v and only over-write it if the conditions are met.

Not sure why this whole thing had to be reworked.

Why didn't the 2-liner I gave you work for you?

Signature · 1 line
Lee Jones [李琼斯]
author
#5 lore raw

Re: [PATCH v7 2/8] mfd: simple-mfd-i2c: specify max_register

In reply to Lee Jones
Quoted 29 lines · Lee Jones
Quoted 26 lines · Alex Elder

All devices supported by simple MFD use the same 8-bit register 8-bit value regmap configuration. There is an option available for a device to specify a custom configuration, but no existing device uses it.

Rather than specify a "full" regmap configuration to use this option, Lee Jones suggested allowing just the max_register value to be specified in the simple_mfd_data structure.

---
v2: - Allow max_register *and* regmap_config to be supplied

  drivers/mfd/simple-mfd-i2c.c | 15 ++++++++++++---
  drivers/mfd/simple-mfd-i2c.h |  1 +
  2 files changed, 13 insertions(+), 3 deletions(-)
drivers/mfd/simple-mfd-i2c.c +0 -0
index 22159913bea03..3f959f4f98261 100644
@@ -33,16 +33,25 @@ static int simple_mfd_i2c_probe(struct i2c_client *i2c)
  {
  	const struct simple_mfd_data *simple_mfd_data;
  	const struct regmap_config *regmap_config;
Quoted 5 lines

drivers/mfd/simple-mfd-i2c.c static int simple_mfd_i2c_probe(struct i2c_client *i2c) · line 36

Quoted 1 line
drivers/mfd/simple-mfd-i2c.c +1 -0
+	struct regmap_config config;

Why do we need another regmap_config?

Can't we just remove the const and make use of the one above?

If we change the global one, it changes for all users.

In my next version I will modify the global one temporarily and zero the max_register field again after the devm_regmap_init_i2c() call. That doesn't protect against concurrent probes but I don't think that's a problem.

Quoted 26 lines

drivers/mfd/simple-mfd-i2c.c static int simple_mfd_i2c_probe(struct i2c_client *i2c) · line 45

Quoted 10 lines
drivers/mfd/simple-mfd-i2c.c +3 -1
  	struct regmap *regmap;
  	int ret;
 
  	simple_mfd_data = device_get_match_data(&i2c->dev);
 
  	/* If no regmap_config is specified, use the default 8reg and 8val bits */
-	if (!simple_mfd_data || !simple_mfd_data->regmap_config)
+	if (simple_mfd_data) {
+		if (simple_mfd_data->regmap_config)
+			config = *simple_mfd_data->regmap_config;
			regmap_config = simple_mfd_data->regmap_config;

drivers/mfd/simple-mfd-i2c.c static int simple_mfd_i2c_probe(struct i2c_client *i2c) · line 47

Quoted 2 lines
drivers/mfd/simple-mfd-i2c.c +2 -0
+		else
+			config = regmap_config_8r_8v;
			regmap_config = &regmap_config_8r_8v;

drivers/mfd/simple-mfd-i2c.c static int simple_mfd_i2c_probe(struct i2c_client *i2c) · line 53

Quoted 6 lines
drivers/mfd/simple-mfd-i2c.c +5 -0
+
+		if (simple_mfd_data->max_register)
+			config.max_register = simple_mfd_data->max_register;
+		regmap_config = &config;
+	} else {
  		regmap_config = &regmap_config_8r_8v;

I suspect we don't need to have this line twice.

Quoted 3 lines

Either re-jig the if () above (I suspect this explains the existing complexity [multiple conditions]) or pre-set regmap_config to regmap_config_8r_8v and only over-write it if the conditions are met.

Sure, that would work, but it won't be needed if I just use the (non-const) global config.

Thanks for the review.

-Alex

Quoted 17 lines
Quoted 16 lines
drivers/mfd/simple-mfd-i2c.c +1 -1
-	else -		regmap_config = simple_mfd_data->regmap_config;
+	}
 
  	regmap = devm_regmap_init_i2c(i2c, regmap_config); if
  	(IS_ERR(regmap)) diff --git a/drivers/mfd/simple-mfd-i2c.h
  	b/drivers/mfd/simple-mfd-i2c.h index
  	7cb2bdd347d97..706b6f53155ff 100644 ---
  	a/drivers/mfd/simple-mfd-i2c.h +++
  	b/drivers/mfd/simple-mfd-i2c.h @@ -27,6 +27,7 @@ struct
  	simple_mfd_data { const struct regmap_config *regmap_config;
  	const struct mfd_cell *mfd_cell; size_t mfd_cell_size; +
  	unsigned int max_register; };
 
  #endif /* __MFD_SIMPLE_MFD_I2C_H */ -- 2.45.2
author
#6 lore raw

PATCH v7 3/8 mfd: simple-mfd-i2c: add SpacemiT P1 support

In reply to Alex Elder

Enable support for the RTC and regulators found in the SpacemiT P1 PMIC. Support is implemented by the simple I2C MFD driver.

The P1 PMIC is normally implemented with the SpacemiT K1 SoC. This PMIC provides 6 buck converters and 12 LDO regulators. It also implements a switch, watchdog timer, real-time clock, and more. Initially its RTC and regulators are supported.

---
 drivers/mfd/Kconfig          | 11 +++++++++++
 drivers/mfd/simple-mfd-i2c.c | 12 ++++++++++++
 2 files changed, 23 insertions(+)
drivers/mfd/Kconfig +11 -0
index 6fb3768e3d71c..01805c3eec57d 100644
@@ -1182,6 +1182,17 @@ config MFD_QCOM_RPM
 	  Say M here if you want to include support for the Qualcomm RPM as a
 	  module. This will build a module called "qcom_rpm".
 
+config MFD_SPACEMIT_P1
+	tristate "SpacemiT P1 PMIC"
+	depends on I2C
+	select MFD_SIMPLE_MFD_I2C
+	help
+	  This option supports the I2C-based SpacemiT P1 PMIC, which
+	  contains regulators, a power switch, GPIOs, an RTC, and more.
+	  This option is selected when any of the supported sub-devices
+	  is configured.  The basic functionality is implemented by the
+	  simple MFD I2C driver.
+
 config MFD_SPMI_PMIC
 	tristate "Qualcomm SPMI PMICs"
 	depends on ARCH_QCOM || COMPILE_TEST
drivers/mfd/simple-mfd-i2c.c +12 -0
index 3f959f4f98261..a8f658eaf4108 100644
@@ -102,12 +102,24 @@ static const struct simple_mfd_data maxim_mon_max77705 = {
 	.mfd_cell_size = ARRAY_SIZE(max77705_sensor_cells),
 };
 
+static const struct mfd_cell spacemit_p1_cells[] = {
+	{ .name = "spacemit-p1-regulator", },
+	{ .name = "spacemit-p1-rtc", },
+};
+
+static const struct simple_mfd_data spacemit_p1 = {
+	.mfd_cell = spacemit_p1_cells,
+	.mfd_cell_size = ARRAY_SIZE(spacemit_p1_cells),
+	.max_register = 0xaa,
+};
+
 static const struct of_device_id simple_mfd_i2c_of_match[] = {
 	{ .compatible = "kontron,sl28cpld" },
 	{ .compatible = "silergy,sy7636a", .data = &silergy_sy7636a},
 	{ .compatible = "maxim,max5970", .data = &maxim_max5970},
 	{ .compatible = "maxim,max5978", .data = &maxim_max5970},
 	{ .compatible = "maxim,max77705-battery", .data = &maxim_mon_max77705},
+	{ .compatible = "spacemit,p1", .data = &spacemit_p1, },
 	{}
 };
 MODULE_DEVICE_TABLE(of, simple_mfd_i2c_of_match);
Signature · 1 line
2.45.2
maintainer
#7 lore raw

Re: [PATCH v7 3/8] mfd: simple-mfd-i2c: add SpacemiT P1 support

Quoted 8 lines · Alex Elder

Enable support for the RTC and regulators found in the SpacemiT P1 PMIC. Support is implemented by the simple I2C MFD driver.

The P1 PMIC is normally implemented with the SpacemiT K1 SoC. This PMIC provides 6 buck converters and 12 LDO regulators. It also implements a switch, watchdog timer, real-time clock, and more. Initially its RTC and regulators are supported.

Quoted 5 lines
---
 drivers/mfd/Kconfig          | 11 +++++++++++
 drivers/mfd/simple-mfd-i2c.c | 12 ++++++++++++
 2 files changed, 23 insertions(+)

Looks good.

Signature · 1 line
Lee Jones [李琼斯]
author
#8 lore raw

PATCH v7 4/8 regulator: spacemit: support SpacemiT P1 regulators

In reply to Alex Elder

Add support for the regulators found in the SpacemiT P1 PMIC. This PMIC provides 6 buck converters and 12 LDO regulators.

The PMIC is implemented as a multi-function device. These regulators are probed based on this driver being named in a MFD cell in the simple MFD I2C driver.

---
 drivers/regulator/Kconfig       |  12 +++
 drivers/regulator/Makefile      |   1 +
 drivers/regulator/spacemit-p1.c | 157 ++++++++++++++++++++++++++++++++
 3 files changed, 170 insertions(+)
 create mode 100644 drivers/regulator/spacemit-p1.c
drivers/regulator/Kconfig +12 -0
index 7423954153b07..3e7feeebf8aca 100644
@@ -1395,6 +1395,18 @@ config REGULATOR_SLG51000
 	  The SLG51000 is seven compact and customizable low dropout
 	  regulators.
 
+config REGULATOR_SPACEMIT_P1
+	tristate "SpacemiT P1 regulators"
+	depends on ARCH_SPACEMIT || COMPILE_TEST
+	select MFD_SPACEMIT_P1
+	default ARCH_SPACEMIT
+	help
+	  Enable support for regulators implemented by the SpacemiT P1
+	  power controller.  The P1 implements 6 high-efficiency buck
+	  converters and 12 programmable LDO regulators.  To compile this
+	  driver as a module, choose M here.  The module will be called
+	  "spacemit-pmic".
+
 config REGULATOR_STM32_BOOSTER
 	tristate "STMicroelectronics STM32 BOOSTER"
 	depends on ARCH_STM32 || COMPILE_TEST
drivers/regulator/Makefile +1 -0
index be98b29d6675d..278f5b8d1c7d7 100644
@@ -162,6 +162,7 @@ obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o
 obj-$(CONFIG_REGULATOR_SC2731) += sc2731-regulator.o
 obj-$(CONFIG_REGULATOR_SKY81452) += sky81452-regulator.o
 obj-$(CONFIG_REGULATOR_SLG51000) += slg51000-regulator.o
+obj-$(CONFIG_REGULATOR_SPACEMIT_P1) += spacemit-p1.o
 obj-$(CONFIG_REGULATOR_STM32_BOOSTER) += stm32-booster.o
 obj-$(CONFIG_REGULATOR_STM32_VREFBUF) += stm32-vrefbuf.o
 obj-$(CONFIG_REGULATOR_STM32_PWR) += stm32-pwr.o
drivers/regulator/spacemit-p1.c new file +157 -0

157 lines not on this page · raw message

Signature · 1 line
2.45.2
author
#9 lore raw

PATCH v7 5/8 rtc: spacemit: support the SpacemiT P1 RTC

In reply to Alex Elder

Add support for the RTC found in the SpacemiT P1 PMIC. Initially only setting and reading the time are supported.

The PMIC is implemented as a multi-function device. This RTC is probed based on this driver being named in a MFD cell in the simple MFD I2C driver.

---
 drivers/rtc/Kconfig           |  10 ++
 drivers/rtc/Makefile          |   1 +
 drivers/rtc/rtc-spacemit-p1.c | 167 ++++++++++++++++++++++++++++++++++
 3 files changed, 178 insertions(+)
 create mode 100644 drivers/rtc/rtc-spacemit-p1.c
drivers/rtc/Kconfig +10 -0
index 9aec922613cec..93620f2c9b29c 100644
@@ -406,6 +406,16 @@ config RTC_DRV_MAX77686
 	  This driver can also be built as a module. If so, the module
 	  will be called rtc-max77686.
 
+config RTC_DRV_SPACEMIT_P1
+	tristate "SpacemiT P1 RTC"
+	depends on ARCH_SPACEMIT || COMPILE_TEST
+	select MFD_SPACEMIT_P1
+	default ARCH_SPACEMIT
+	help
+	  Enable support for the RTC function in the SpacemiT P1 PMIC.
+	  This driver can also be built as a module, which will be called
+	  "spacemit-p1-rtc".
+
 config RTC_DRV_NCT3018Y
 	tristate "Nuvoton NCT3018Y"
 	depends on OF
drivers/rtc/Makefile +1 -0
index 4619aa2ac4697..a24ff6ad5ca58 100644
@@ -171,6 +171,7 @@ obj-$(CONFIG_RTC_DRV_SD2405AL)	+= rtc-sd2405al.o
 obj-$(CONFIG_RTC_DRV_SD3078)	+= rtc-sd3078.o
 obj-$(CONFIG_RTC_DRV_SH)	+= rtc-sh.o
 obj-$(CONFIG_RTC_DRV_SNVS)	+= rtc-snvs.o
+obj-$(CONFIG_RTC_DRV_SPACEMIT_P1)	+= rtc-spacemit-p1.o
 obj-$(CONFIG_RTC_DRV_SPEAR)	+= rtc-spear.o
 obj-$(CONFIG_RTC_DRV_STARFIRE)	+= rtc-starfire.o
 obj-$(CONFIG_RTC_DRV_STK17TA8)	+= rtc-stk17ta8.o
drivers/rtc/rtc-spacemit-p1.c new file +167 -0

167 lines not on this page · raw message

Signature · 1 line
2.45.2
author
#10 lore raw

PATCH v7 6/8 riscv: dts: spacemit: enable the i2c8 adapter

In reply to Alex Elder

Define properties for the I2C adapter that provides access to the SpacemiT P1 PMIC. Enable this adapter on the Banana Pi BPI-F3.

---
 arch/riscv/boot/dts/spacemit/k1-bananapi-f3.dts | 15 +++++++++++++++
 arch/riscv/boot/dts/spacemit/k1-pinctrl.dtsi    |  7 +++++++
 arch/riscv/boot/dts/spacemit/k1.dtsi            | 11 +++++++++++
 3 files changed, 33 insertions(+)
arch/riscv/boot/dts/spacemit/k1-bananapi-f3.dts +15 -0
index fe22c747c5012..7c9f91c88e01a 100644
@@ -40,6 +40,21 @@ &emmc {
 	status = "okay";
 };
 
+&i2c8 {
+	pinctrl-0 = <&i2c8_cfg>;
+	pinctrl-names = "default";
+	#address-cells = <1>;
+	#size-cells = <0>;
+	status = "okay";
+
+	pmic@41 {
+		compatible = "spacemit,p1";
+		reg = <0x41>;
+		interrupts = <64>;
+		status = "okay";
+	};
+};
+
 &uart0 {
 	pinctrl-names = "default";
 	pinctrl-0 = <&uart0_2_cfg>;
arch/riscv/boot/dts/spacemit/k1-pinctrl.dtsi +7 -0
index 283663647a86f..9d6d4503fe751 100644
@@ -11,6 +11,13 @@
 #define K1_GPIO(x)	(x / 32) (x % 32)
 
 &pinctrl {
+	i2c8_cfg: i2c8-cfg {
+		i2c8-0-pins {
+			pinmux = <K1_PADCONF(93, 0)>,	/* PWR_SCL */
+				 <K1_PADCONF(94, 0)>;	/* PWR_SDA */
+		};
+	};
+
 	uart0_2_cfg: uart0-2-cfg {
 		uart0-2-pins {
 			pinmux = <K1_PADCONF(68, 2)>,
arch/riscv/boot/dts/spacemit/k1.dtsi +11 -0
index 14097f1f6f447..a85239e8e430b 100644
@@ -483,6 +483,17 @@ gpio: gpio@d4019000 {
 				      <&pinctrl 3 0 96 32>;
 		};
 
+		i2c8: i2c@d401d800 {
+			compatible = "spacemit,k1-i2c";
+			reg = <0x0 0xd401d800 0x0 0x38>;
+			interrupts = <19>;
+			clocks = <&syscon_apbc CLK_TWSI8>,
+				 <&syscon_apbc CLK_TWSI8_BUS>;
+			clock-names = "func", "bus";
+			clock-frequency = <400000>;
+			status = "disabled";
+		};
+
 		pinctrl: pinctrl@d401e000 {
 			compatible = "spacemit,k1-pinctrl";
 			reg = <0x0 0xd401e000 0x0 0x400>;
Signature · 1 line
2.45.2
author
#11 lore raw

PATCH v7 7/8 riscv: dts: spacemit: define fixed regulators

In reply to Alex Elder

Define the DC power input and the 4v power as fixed supplies in the Banana Pi BPI-F3.

---
 .../boot/dts/spacemit/k1-bananapi-f3.dts      | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
arch/riscv/boot/dts/spacemit/k1-bananapi-f3.dts +19 -0
index 7c9f91c88e01a..a1c184b814262 100644
@@ -28,6 +28,25 @@ led1 {
 			default-state = "on";
 		};
 	};
+
+	reg_dc_in: dc-in-12v {
+		compatible = "regulator-fixed";
+		regulator-name = "dc_in_12v";
+		regulator-min-microvolt = <12000000>;
+		regulator-max-microvolt = <12000000>;
+		regulator-boot-on;
+		regulator-always-on;
+	};
+
+	reg_vcc_4v: vcc-4v {
+		compatible = "regulator-fixed";
+		regulator-name = "vcc_4v";
+		regulator-min-microvolt = <4000000>;
+		regulator-max-microvolt = <4000000>;
+		regulator-boot-on;
+		regulator-always-on;
+		vin-supply = <&reg_dc_in>;
+	};
 };
 
 &emmc {
Signature · 1 line
2.45.2
author
#12 lore raw

PATCH v7 8/8 riscv: dts: spacemit: define regulator constraints

In reply to Alex Elder

Define basic constraints for the regulators in the SpacemiT P1 PMIC, as implemented in the Banana Pi BPI-F3.

---
 .../boot/dts/spacemit/k1-bananapi-f3.dts      | 104 ++++++++++++++++++
 1 file changed, 104 insertions(+)
arch/riscv/boot/dts/spacemit/k1-bananapi-f3.dts +104 -0
index a1c184b814262..83907cc1d5ccf 100644
@@ -70,7 +70,111 @@ pmic@41 {
 		compatible = "spacemit,p1";
 		reg = <0x41>;
 		interrupts = <64>;
+		vin-supply = <&reg_vcc_4v>;
 		status = "okay";
+
+		regulators {
+			buck1 {
+				regulator-min-microvolt = <500000>;
+				regulator-max-microvolt = <3450000>;
+				regulator-ramp-delay = <5000>;
+				regulator-always-on;
+			};
+
+			buck2 {
+				regulator-min-microvolt = <500000>;
+				regulator-max-microvolt = <3450000>;
+				regulator-ramp-delay = <5000>;
+				regulator-always-on;
+			};
+
+			buck3 {
+				regulator-min-microvolt = <500000>;
+				regulator-max-microvolt = <1800000>;
+				regulator-ramp-delay = <5000>;
+				regulator-always-on;
+			};
+
+			buck4 {
+				regulator-min-microvolt = <500000>;
+				regulator-max-microvolt = <3300000>;
+				regulator-ramp-delay = <5000>;
+				regulator-always-on;
+			};
+
+			buck5 {
+				regulator-min-microvolt = <500000>;
+				regulator-max-microvolt = <3450000>;
+				regulator-ramp-delay = <5000>;
+				regulator-always-on;
+			};
+
+			buck6 {
+				regulator-min-microvolt = <500000>;
+				regulator-max-microvolt = <3450000>;
+				regulator-ramp-delay = <5000>;
+				regulator-always-on;
+			};
+
+			aldo1 {
+				regulator-min-microvolt = <500000>;
+				regulator-max-microvolt = <3400000>;
+				regulator-boot-on;
+			};
+
+			aldo2 {
+				regulator-min-microvolt = <500000>;
+				regulator-max-microvolt = <3400000>;
+			};
+
+			aldo3 {
+				regulator-min-microvolt = <500000>;
+				regulator-max-microvolt = <3400000>;
+			};
+
+			aldo4 {
+				regulator-min-microvolt = <500000>;
+				regulator-max-microvolt = <3400000>;
+			};
+
+			dldo1 {
+				regulator-min-microvolt = <500000>;
+				regulator-max-microvolt = <3400000>;
+				regulator-boot-on;
+			};
+
+			dldo2 {
+				regulator-min-microvolt = <500000>;
+				regulator-max-microvolt = <3400000>;
+			};
+
+			dldo3 {
+				regulator-min-microvolt = <500000>;
+				regulator-max-microvolt = <3400000>;
+			};
+
+			dldo4 {
+				regulator-min-microvolt = <500000>;
+				regulator-max-microvolt = <3400000>;
+				regulator-always-on;
+			};
+
+			dldo5 {
+				regulator-min-microvolt = <500000>;
+				regulator-max-microvolt = <3400000>;
+			};
+
+			dldo6 {
+				regulator-min-microvolt = <500000>;
+				regulator-max-microvolt = <3400000>;
+				regulator-always-on;
+			};
+
+			dldo7 {
+				regulator-min-microvolt = <500000>;
+				regulator-max-microvolt = <3400000>;
+			};
+		};
 	};
 };
 
Signature · 1 line
2.45.2