Skip to contentSkip to conversation

Add support for PMICs used on Tegra 3 devices

PATCH Superseded Svyatoslav Ryhel 2 participants 25 messages Jul 20, 2023 – Aug 10, 2023

v2 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add support for PMICs used on Tegra 3 devices

Patch set adds basic support for PMICs used in many Tegra 3 devices. All PMIC drivers are based on datasheets provided by vendors. Implemented API include regulator set/get voltage enable/disable and basic PMIC r/w capabilities.

Created poweroff API for pmic to be able to call do_poweroff directly from within pmic driver. PMIC responcible for poweroff shoud be marked as system-power-controller in device tree.

Drivers were tested by me on LG P895 (max77663), HTC One X (TPS80032) and ASUS TF300T (tps65911). Calculations and behavior were correct, predictable and reproducible.

---
Changes from v1:
- created poweroff API for PMIC and integrated it call into do_poweroff
- added poweroff function to submitted max77663, tps80032 and tps65911 drivers
- fixed registers asignments for regulators with non-numeric name (ldoln, ldousb, vddctrl)
---

Svyatoslav Ryhel (9):
power: pmic-uclass: implement poweroff ops
cmd: boot: implement PMIC based poweroff
power: pmic: palmas: support TI TPS65913 PMIC
power: pmic: add the base MAX77663 PMIC support
power: regulator: max77663: add regulator support
power: pmic: add the base TPS80031 PMIC support
power: regulator: tps80031: add regulator support
power: pmic: tps65910: add TPS65911 PMIC support
power: regulator: tps65911: add regulator support

 cmd/Kconfig                                  |   6 +
 cmd/boot.c                                   |  40 ++
 doc/device-tree-bindings/pmic/max77663.txt   |  84 +++++
 doc/device-tree-bindings/pmic/tps65911.txt   |  78 ++++
 doc/device-tree-bindings/pmic/tps80031.txt   |  76 ++++
 drivers/power/pmic/Kconfig                   |  12 +
 drivers/power/pmic/Makefile                  |   2 +
 drivers/power/pmic/max77663.c                | 105 ++++++
 drivers/power/pmic/palmas.c                  |   1 +
 drivers/power/pmic/pmic-uclass.c             |  12 +
 drivers/power/pmic/pmic_tps65910_dm.c        |  49 ++-
 drivers/power/pmic/tps80031.c                |  97 +++++
 drivers/power/regulator/Kconfig              |  24 ++
 drivers/power/regulator/Makefile             |   3 +
 drivers/power/regulator/max77663_regulator.c | 358 ++++++++++++++++++
 drivers/power/regulator/tps65911_regulator.c | 377 +++++++++++++++++++
 drivers/power/regulator/tps80031_regulator.c | 296 +++++++++++++++
 include/power/max77663.h                     |  44 +++
 include/power/pmic.h                         |  13 +
 include/power/tps65910_pmic.h                |  52 +++
 include/power/tps80031.h                     |  45 +++
 21 files changed, 1771 insertions(+), 3 deletions(-)
 create mode 100644 doc/device-tree-bindings/pmic/max77663.txt
 create mode 100644 doc/device-tree-bindings/pmic/tps65911.txt
 create mode 100644 doc/device-tree-bindings/pmic/tps80031.txt
 create mode 100644 drivers/power/pmic/max77663.c
 create mode 100644 drivers/power/pmic/tps80031.c
 create mode 100644 drivers/power/regulator/max77663_regulator.c
 create mode 100644 drivers/power/regulator/tps65911_regulator.c
 create mode 100644 drivers/power/regulator/tps80031_regulator.c
 create mode 100644 include/power/max77663.h
 create mode 100644 include/power/tps80031.h
Signature · 1 line
2.39.2
#1 lore raw

PATCH v2 1/9 power: pmic-uclass: implement poweroff ops

PMICs are responsible for device poweroff sequence so lets implement this function.

---
 drivers/power/pmic/pmic-uclass.c | 12 ++++++++++++
 include/power/pmic.h             | 13 +++++++++++++
 2 files changed, 25 insertions(+)
drivers/power/pmic/pmic-uclass.c +12 -0
index 0e2f5e1f41..23803bc96a 100644
@@ -99,6 +99,18 @@ int pmic_get(const char *name, struct udevice **devp)
 	return uclass_get_device_by_name(UCLASS_PMIC, name, devp);
 }
 
+int pmic_poweroff(struct udevice *dev)
+{
+	const struct dm_pmic_ops *ops = dev_get_driver_ops(dev);
+	struct uc_pmic_priv *priv = dev_get_uclass_priv(dev);
+
+	if (!ops || !ops->poweroff ||
+	    !priv->sys_pow_ctrl)
+		return -ENOSYS;
+
+	return ops->poweroff(dev);
+}
+
 int pmic_reg_count(struct udevice *dev)
 {
 	const struct dm_pmic_ops *ops = dev_get_driver_ops(dev);
include/power/pmic.h +13 -0
index 636221692d..d8dd1ceaa3 100644
@@ -157,11 +157,13 @@ struct pmic {
  * Should be implemented by UCLASS_PMIC device drivers. The standard
  * device operations provides the I/O interface for it's childs.
  *
+ * @poweroff:  perform poweroff sequence
  * @reg_count: device's register count
  * @read:      read 'len' bytes at "reg" and store it into the 'buffer'
  * @write:     write 'len' bytes from the 'buffer' to the register at 'reg' address
  */
 struct dm_pmic_ops {
+	int (*poweroff)(struct udevice *dev);
 	int (*reg_count)(struct udevice *dev);
 	int (*read)(struct udevice *dev, uint reg, uint8_t *buffer, int len);
 	int (*write)(struct udevice *dev, uint reg, const uint8_t *buffer,
@@ -242,6 +244,16 @@ int pmic_bind_children(struct udevice *pmic, ofnode parent,
  */
 int pmic_get(const char *name, struct udevice **devp);
 
+/**
+ * pmic_poweroff: call the pmic poweroff sequence
+ *
+ * The required pmic device can be obtained by 'pmic_get()'
+ *
+ * @dev - pointer to the UCLASS_PMIC device
+ * Return: device turns off or negative value of errno.
+ */
+int pmic_poweroff(struct udevice *dev);
+
 /**
  * pmic_reg_count: get the pmic register count
  *
@@ -306,6 +318,7 @@ int pmic_clrsetbits(struct udevice *dev, uint reg, uint clr, uint set);
  */
 struct uc_pmic_priv {
 	uint trans_len;
+	bool sys_pow_ctrl;
 };
 
 #endif /* DM_PMIC */
Signature · 1 line
2.39.2
#2 lore raw

Re: [PATCH v2 1/9] power: pmic-uclass: implement poweroff ops

Hi Svyatoslav,

Quoted 38 lines · Svyatoslav Ryhel

PMICs are responsible for device poweroff sequence so lets implement this function.

---
 drivers/power/pmic/pmic-uclass.c | 12 ++++++++++++
 include/power/pmic.h             | 13 +++++++++++++
 2 files changed, 25 insertions(+)
drivers/power/pmic/pmic-uclass.c +12 -0
index 0e2f5e1f41..23803bc96a 100644
@@ -99,6 +99,18 @@ int pmic_get(const char *name, struct udevice **devp)
        return uclass_get_device_by_name(UCLASS_PMIC, name, devp);
 }
 
+int pmic_poweroff(struct udevice *dev)
+{
+       const struct dm_pmic_ops *ops = dev_get_driver_ops(dev);
+       struct uc_pmic_priv *priv = dev_get_uclass_priv(dev);
+
+       if (!ops || !ops->poweroff ||
+           !priv->sys_pow_ctrl)
+               return -ENOSYS;
+
+       return ops->poweroff(dev);
+}
+
 int pmic_reg_count(struct udevice *dev)
 {
        const struct dm_pmic_ops *ops = dev_get_driver_ops(dev);
include/power/pmic.h +0 -0
index 636221692d..d8dd1ceaa3 100644

include/power/pmic.h struct pmic { · line 166

Quoted 10 lines
include/power/pmic.h +2 -0
@@ -157,11 +157,13 @@ struct pmic {
  * Should be implemented by UCLASS_PMIC device drivers. The standard
  * device operations provides the I/O interface for it's childs.
  *
+ * @poweroff:  perform poweroff sequence
  * @reg_count: device's register count
  * @read:      read 'len' bytes at "reg" and store it into the 'buffer'
  * @write:     write 'len' bytes from the 'buffer' to the register at 'reg' address
  */
 struct dm_pmic_ops {
+       int (*poweroff)(struct udevice *dev);

Please do remember to fully comment each method here too - see p2sb set_hide() for an example.

Quoted 21 lines
include/power/pmic.h +10 -0
        int (*reg_count)(struct udevice *dev);
        int (*read)(struct udevice *dev, uint reg, uint8_t *buffer, int len);
        int (*write)(struct udevice *dev, uint reg, const uint8_t *buffer,
@@ -242,6 +244,16 @@ int pmic_bind_children(struct udevice *pmic, ofnode parent,
  */
 int pmic_get(const char *name, struct udevice **devp);
 
+/**
+ * pmic_poweroff: call the pmic poweroff sequence
+ *
+ * The required pmic device can be obtained by 'pmic_get()'
+ *
+ * @dev - pointer to the UCLASS_PMIC device
+ * Return: device turns off or negative value of errno.
+ */
+int pmic_poweroff(struct udevice *dev);
+
 /**
  * pmic_reg_count: get the pmic register count
  *

include/power/pmic.h int pmic_clrsetbits(struct udevice *dev, uint reg, uint clr, uint set); · line 321

Quoted 4 lines
include/power/pmic.h +1 -0
@@ -306,6 +318,7 @@ int pmic_clrsetbits(struct udevice *dev, uint reg, uint clr, uint set);
  */
 struct uc_pmic_priv {
        uint trans_len;
+       bool sys_pow_ctrl;

comment

Quoted 6 lines
include/power/pmic.h +0 -1
 };
 
 #endif /* DM_PMIC */
--

2.39.2

This needs a test addition to test/dm/pmic.c (perhaps you have it in another patch).

Regards,
Simon

#3 lore raw

Re: [PATCH v2 1/9] power: pmic-uclass: implement poweroff ops

чт, 20 лип. 2023 р. о 22:43 Simon Glass <[email protected]> пише:

Quoted 47 lines

Hi Svyatoslav,

Quoted 43 lines · Svyatoslav Ryhel

PMICs are responsible for device poweroff sequence so lets implement this function.

---
 drivers/power/pmic/pmic-uclass.c | 12 ++++++++++++
 include/power/pmic.h             | 13 +++++++++++++
 2 files changed, 25 insertions(+)
drivers/power/pmic/pmic-uclass.c +12 -0
index 0e2f5e1f41..23803bc96a 100644
@@ -99,6 +99,18 @@ int pmic_get(const char *name, struct udevice **devp)
        return uclass_get_device_by_name(UCLASS_PMIC, name, devp);
 }
 
+int pmic_poweroff(struct udevice *dev)
+{
+       const struct dm_pmic_ops *ops = dev_get_driver_ops(dev);
+       struct uc_pmic_priv *priv = dev_get_uclass_priv(dev);
+
+       if (!ops || !ops->poweroff ||
+           !priv->sys_pow_ctrl)
+               return -ENOSYS;
+
+       return ops->poweroff(dev);
+}
+
 int pmic_reg_count(struct udevice *dev)
 {
        const struct dm_pmic_ops *ops = dev_get_driver_ops(dev);
include/power/pmic.h +1 -0
index 636221692d..d8dd1ceaa3 100644
@@ -157,11 +157,13 @@ struct pmic {
  * Should be implemented by UCLASS_PMIC device drivers. The standard
  * device operations provides the I/O interface for it's childs.
  *
+ * @poweroff:  perform poweroff sequence
  * @reg_count: device's register count
Quoted 9 lines

include/power/pmic.h struct pmic { · line 166

Quoted 5 lines
include/power/pmic.h +1 -0
  * @read:      read 'len' bytes at "reg" and store it into the 'buffer'
  * @write:     write 'len' bytes from the 'buffer' to the register at 'reg' address
  */
 struct dm_pmic_ops {
+       int (*poweroff)(struct udevice *dev);

Please do remember to fully comment each method here too - see p2sb set_hide() for an example.

It is commented in description before ops
+ * @poweroff: perform poweroff sequence

p2sb set_hide() description is nice but it does not fit this case since its description is set before ops.

Quoted 30 lines
Quoted 21 lines
include/power/pmic.h +10 -0
        int (*reg_count)(struct udevice *dev);
        int (*read)(struct udevice *dev, uint reg, uint8_t *buffer, int len);
        int (*write)(struct udevice *dev, uint reg, const uint8_t *buffer,
@@ -242,6 +244,16 @@ int pmic_bind_children(struct udevice *pmic, ofnode parent,
  */
 int pmic_get(const char *name, struct udevice **devp);
 
+/**
+ * pmic_poweroff: call the pmic poweroff sequence
+ *
+ * The required pmic device can be obtained by 'pmic_get()'
+ *
+ * @dev - pointer to the UCLASS_PMIC device
+ * Return: device turns off or negative value of errno.
+ */
+int pmic_poweroff(struct udevice *dev);
+
 /**
  * pmic_reg_count: get the pmic register count
  *

include/power/pmic.h int pmic_clrsetbits(struct udevice *dev, uint reg, uint clr, uint set); · line 321

Quoted 4 lines
include/power/pmic.h +1 -0
@@ -306,6 +318,7 @@ int pmic_clrsetbits(struct udevice *dev, uint reg, uint clr, uint set);
  */
 struct uc_pmic_priv {
        uint trans_len;
+       bool sys_pow_ctrl;

comment

Quoted 2 lines
include/power/pmic.h +0 -0
 };
 
Quoted 7 lines
Quoted 4 lines
include/power/pmic.h +0 -1
 #endif /* DM_PMIC */
--

2.39.2

This needs a test addition to test/dm/pmic.c (perhaps you have it in another patch).

I knew you would ask for this and I have thought about implementing a dm test but I have faced the next issue: poweroff call (in this context) performs device poweroff on success and -err on failure. Iirc sandbox pmic is not dedicated for poweroff and it can not be "emulated" correctly on sandbox (emulation will be just a passing value like for example pmic_reg_count test).

If this is mandatory then tell pls which behavior is expected in the test and I will try to replicate it.

Quoted 2 lines

Regards,
Simon

#4 lore raw

PATCH v2 2/9 cmd: boot: implement PMIC based poweroff

In reply to Svyatoslav Ryhel

Use new PMIC ops to perform device poweroff.

---
 cmd/Kconfig |  6 ++++++
 cmd/boot.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
cmd/Kconfig +6 -0
index ecfd575237..47654297f8 100644
@@ -1439,6 +1439,12 @@ config CMD_POWEROFF
 	help
 	  Poweroff/Shutdown the system
 
+config CMD_PMIC_POWEROFF
+	bool "PMIC poweroff"
+	select CMD_POWEROFF
+	help
+	  Shutdown the system using PMIC poweroff sequence.
+
 config CMD_READ
 	bool "read - Read binary data from a partition"
 	help
cmd/boot.c +40 -0
index 14839c1ced..4270034194 100644
@@ -9,7 +9,13 @@
  */
 #include <common.h>
 #include <command.h>
+#include <dm.h>
+#include <log.h>
 #include <net.h>
+#include <dm/device-internal.h>
+#include <dm/uclass-internal.h>
+#include <power/pmic.h>
+#include <linux/delay.h>
 
 #ifdef CONFIG_CMD_GO
 
@@ -64,6 +70,40 @@ U_BOOT_CMD(
 );
 
 #ifdef CONFIG_CMD_POWEROFF
+#ifdef CONFIG_CMD_PMIC_POWEROFF
+int do_poweroff(struct cmd_tbl *cmdtp, int flag,
+		int argc, char *const argv[])
+{
+	struct uc_pmic_priv *pmic_priv;
+	struct udevice *dev;
+	int ret;
+
+	for (uclass_find_first_device(UCLASS_PMIC, &dev);
+	     dev;
+	     uclass_find_next_device(&dev)) {
+		if (dev && !device_active(dev)) {
+			ret = device_probe(dev);
+			if (ret)
+				return ret;
+		}
+
+		/* value we need to check is set after probe */
+		pmic_priv = dev_get_uclass_priv(dev);
+		if (pmic_priv->sys_pow_ctrl) {
+			ret = pmic_poweroff(dev);
+
+			/* wait some time and then print error */
+			mdelay(5000);
+			log_err("Failed to power off!!!\n");
+			return ret;
+		}
+	}
+
+	/* no device should reach here */
+	return 1;
+}
+#endif
+
 U_BOOT_CMD(
 	poweroff, 1, 0,	do_poweroff,
 	"Perform POWEROFF of the device",
Signature · 1 line
2.39.2
#5 lore raw

Re: [PATCH v2 2/9] cmd: boot: implement PMIC based poweroff

Hi Svyatoslav,

Quoted 86 lines · Svyatoslav Ryhel

Use new PMIC ops to perform device poweroff.

---
 cmd/Kconfig |  6 ++++++
 cmd/boot.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
cmd/Kconfig +6 -0
index ecfd575237..47654297f8 100644
@@ -1439,6 +1439,12 @@ config CMD_POWEROFF
        help
          Poweroff/Shutdown the system
 
+config CMD_PMIC_POWEROFF
+       bool "PMIC poweroff"
+       select CMD_POWEROFF
+       help
+         Shutdown the system using PMIC poweroff sequence.
+
 config CMD_READ
        bool "read - Read binary data from a partition"
        help
cmd/boot.c +40 -1
index 14839c1ced..4270034194 100644
@@ -9,7 +9,13 @@
  */
 #include <common.h>
 #include <command.h>
+#include <dm.h>
+#include <log.h>
 #include <net.h>
+#include <dm/device-internal.h>
+#include <dm/uclass-internal.h>
+#include <power/pmic.h>
+#include <linux/delay.h>
 
 #ifdef CONFIG_CMD_GO
 
@@ -64,6 +70,40 @@ U_BOOT_CMD(
 );
 
 #ifdef CONFIG_CMD_POWEROFF
+#ifdef CONFIG_CMD_PMIC_POWEROFF
+int do_poweroff(struct cmd_tbl *cmdtp, int flag,
+               int argc, char *const argv[])
+{
+       struct uc_pmic_priv *pmic_priv;
+       struct udevice *dev;
+       int ret;
+
+       for (uclass_find_first_device(UCLASS_PMIC, &dev);
+            dev;
+            uclass_find_next_device(&dev)) {
+               if (dev && !device_active(dev)) {
+                       ret = device_probe(dev);
+                       if (ret)
+                               return ret;
+               }
+
+               /* value we need to check is set after probe */
+               pmic_priv = dev_get_uclass_priv(dev);
+               if (pmic_priv->sys_pow_ctrl) {
+                       ret = pmic_poweroff(dev);
+
+                       /* wait some time and then print error */
+                       mdelay(5000);
+                       log_err("Failed to power off!!!\n");
+                       return ret;
+               }
+       }
+
+       /* no device should reach here */
+       return 1;
+}
+#endif
+
 U_BOOT_CMD(
        poweroff, 1, 0, do_poweroff,
        "Perform POWEROFF of the device",
--
Quoted 2 lines

2.39.2

How does this relate to sysreset_walk(SYSRESET_POWER_OFF) and do_poweroff() in cmd/boot.c?

Regards,
Simon

#6 lore raw

Re: [PATCH v2 2/9] cmd: boot: implement PMIC based poweroff

нд, 23 лип. 2023 р. о 06:48 Simon Glass <[email protected]> пише:

Quoted 87 lines

Hi Svyatoslav,

Quoted 83 lines · Svyatoslav Ryhel

Use new PMIC ops to perform device poweroff.

---
 cmd/Kconfig |  6 ++++++
 cmd/boot.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
cmd/Kconfig +6 -0
index ecfd575237..47654297f8 100644
@@ -1439,6 +1439,12 @@ config CMD_POWEROFF
        help
          Poweroff/Shutdown the system
 
+config CMD_PMIC_POWEROFF
+       bool "PMIC poweroff"
+       select CMD_POWEROFF
+       help
+         Shutdown the system using PMIC poweroff sequence.
+
 config CMD_READ
        bool "read - Read binary data from a partition"
        help
cmd/boot.c +40 -0
index 14839c1ced..4270034194 100644
@@ -9,7 +9,13 @@
  */
 #include <common.h>
 #include <command.h>
+#include <dm.h>
+#include <log.h>
 #include <net.h>
+#include <dm/device-internal.h>
+#include <dm/uclass-internal.h>
+#include <power/pmic.h>
+#include <linux/delay.h>
 
 #ifdef CONFIG_CMD_GO
 
@@ -64,6 +70,40 @@ U_BOOT_CMD(
 );
 
 #ifdef CONFIG_CMD_POWEROFF
+#ifdef CONFIG_CMD_PMIC_POWEROFF
+int do_poweroff(struct cmd_tbl *cmdtp, int flag,
+               int argc, char *const argv[])
+{
+       struct uc_pmic_priv *pmic_priv;
+       struct udevice *dev;
+       int ret;
+
+       for (uclass_find_first_device(UCLASS_PMIC, &dev);
+            dev;
+            uclass_find_next_device(&dev)) {
+               if (dev && !device_active(dev)) {
+                       ret = device_probe(dev);
+                       if (ret)
+                               return ret;
+               }
+
+               /* value we need to check is set after probe */
+               pmic_priv = dev_get_uclass_priv(dev);
+               if (pmic_priv->sys_pow_ctrl) {
+                       ret = pmic_poweroff(dev);
+
+                       /* wait some time and then print error */
+                       mdelay(5000);
+                       log_err("Failed to power off!!!\n");
+                       return ret;
+               }
+       }
+
+       /* no device should reach here */
+       return 1;
+}
+#endif
+
 U_BOOT_CMD(
Quoted 9 lines
Quoted 5 lines
cmd/boot.c +0 -1
        poweroff, 1, 0, do_poweroff,
        "Perform POWEROFF of the device",
--

2.39.2

How does this relate to sysreset_walk(SYSRESET_POWER_OFF) and do_poweroff() in cmd/boot.c?

It does not, or at least I might misunderstand you. This is made more to fit embedded devices or at least devices where power off is controlled by PMIC. In this case the device must have DM pmic driver with poweroff function implemented and set in the dts as system-power-controller. If this is true, the maintainer in defconfig enables PMIC driver and CONFIG_CMD_PMIC_POWEROFF so the function above is unlocked and used. This avoids board definitions of do_poweroff like I had to do with my devices and at the same time does not break any other devices since CMD_POWEROFF is still available in unmodded state.

Quoted 2 lines

Regards,
Simon

#7 lore raw

Re: [PATCH v2 2/9] cmd: boot: implement PMIC based poweroff

In reply to Simon Glass

нд, 23 лип. 2023 р. о 06:48 Simon Glass <[email protected]> пише:

Quoted 87 lines

Hi Svyatoslav,

Quoted 83 lines · Svyatoslav Ryhel

Use new PMIC ops to perform device poweroff.

---
 cmd/Kconfig |  6 ++++++
 cmd/boot.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
cmd/Kconfig +6 -0
index ecfd575237..47654297f8 100644
@@ -1439,6 +1439,12 @@ config CMD_POWEROFF
        help
          Poweroff/Shutdown the system
 
+config CMD_PMIC_POWEROFF
+       bool "PMIC poweroff"
+       select CMD_POWEROFF
+       help
+         Shutdown the system using PMIC poweroff sequence.
+
 config CMD_READ
        bool "read - Read binary data from a partition"
        help
cmd/boot.c +40 -0
index 14839c1ced..4270034194 100644
@@ -9,7 +9,13 @@
  */
 #include <common.h>
 #include <command.h>
+#include <dm.h>
+#include <log.h>
 #include <net.h>
+#include <dm/device-internal.h>
+#include <dm/uclass-internal.h>
+#include <power/pmic.h>
+#include <linux/delay.h>
 
 #ifdef CONFIG_CMD_GO
 
@@ -64,6 +70,40 @@ U_BOOT_CMD(
 );
 
 #ifdef CONFIG_CMD_POWEROFF
+#ifdef CONFIG_CMD_PMIC_POWEROFF
+int do_poweroff(struct cmd_tbl *cmdtp, int flag,
+               int argc, char *const argv[])
+{
+       struct uc_pmic_priv *pmic_priv;
+       struct udevice *dev;
+       int ret;
+
+       for (uclass_find_first_device(UCLASS_PMIC, &dev);
+            dev;
+            uclass_find_next_device(&dev)) {
+               if (dev && !device_active(dev)) {
+                       ret = device_probe(dev);
+                       if (ret)
+                               return ret;
+               }
+
+               /* value we need to check is set after probe */
+               pmic_priv = dev_get_uclass_priv(dev);
+               if (pmic_priv->sys_pow_ctrl) {
+                       ret = pmic_poweroff(dev);
+
+                       /* wait some time and then print error */
+                       mdelay(5000);
+                       log_err("Failed to power off!!!\n");
+                       return ret;
+               }
+       }
+
+       /* no device should reach here */
+       return 1;
+}
+#endif
+
 U_BOOT_CMD(
Quoted 9 lines
Quoted 5 lines
cmd/boot.c +0 -1
        poweroff, 1, 0, do_poweroff,
        "Perform POWEROFF of the device",
--

2.39.2

How does this relate to sysreset_walk(SYSRESET_POWER_OFF) and do_poweroff() in cmd/boot.c?

Yes, it seems that I have misunderstood you, but non the less, you say that I have to implement a new separate pmic subdriver just to support poweroff?

Quoted 2 lines

Regards,
Simon

#8 lore raw

Re: [PATCH v2 2/9] cmd: boot: implement PMIC based poweroff

Hi Svyatoslav,

Quoted 99 lines · Svyatoslav Ryhel

нд, 23 лип. 2023 р. о 06:48 Simon Glass <[email protected]> пише:

Quoted 87 lines

Hi Svyatoslav,

Quoted 83 lines · Svyatoslav Ryhel

Use new PMIC ops to perform device poweroff.

---
 cmd/Kconfig |  6 ++++++
 cmd/boot.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
cmd/Kconfig +6 -0
index ecfd575237..47654297f8 100644
@@ -1439,6 +1439,12 @@ config CMD_POWEROFF
        help
          Poweroff/Shutdown the system
 
+config CMD_PMIC_POWEROFF
+       bool "PMIC poweroff"
+       select CMD_POWEROFF
+       help
+         Shutdown the system using PMIC poweroff sequence.
+
 config CMD_READ
        bool "read - Read binary data from a partition"
        help
cmd/boot.c +40 -0
index 14839c1ced..4270034194 100644
@@ -9,7 +9,13 @@
  */
 #include <common.h>
 #include <command.h>
+#include <dm.h>
+#include <log.h>
 #include <net.h>
+#include <dm/device-internal.h>
+#include <dm/uclass-internal.h>
+#include <power/pmic.h>
+#include <linux/delay.h>
 
 #ifdef CONFIG_CMD_GO
 
@@ -64,6 +70,40 @@ U_BOOT_CMD(
 );
 
 #ifdef CONFIG_CMD_POWEROFF
+#ifdef CONFIG_CMD_PMIC_POWEROFF
+int do_poweroff(struct cmd_tbl *cmdtp, int flag,
+               int argc, char *const argv[])
+{
+       struct uc_pmic_priv *pmic_priv;
+       struct udevice *dev;
+       int ret;
+
+       for (uclass_find_first_device(UCLASS_PMIC, &dev);
+            dev;
+            uclass_find_next_device(&dev)) {
+               if (dev && !device_active(dev)) {
+                       ret = device_probe(dev);
+                       if (ret)
+                               return ret;
+               }
+
+               /* value we need to check is set after probe */
+               pmic_priv = dev_get_uclass_priv(dev);
+               if (pmic_priv->sys_pow_ctrl) {
+                       ret = pmic_poweroff(dev);
+
+                       /* wait some time and then print error */
+                       mdelay(5000);
+                       log_err("Failed to power off!!!\n");
+                       return ret;
+               }
+       }
+
+       /* no device should reach here */
+       return 1;
+}
+#endif
+
 U_BOOT_CMD(
Quoted 9 lines
Quoted 5 lines
cmd/boot.c +0 -1
        poweroff, 1, 0, do_poweroff,
        "Perform POWEROFF of the device",
--

2.39.2

How does this relate to sysreset_walk(SYSRESET_POWER_OFF) and do_poweroff() in cmd/boot.c?

Quoted 3 lines

Yes, it seems that I have misunderstood you, but non the less, you say that I have to implement a new separate pmic subdriver just to support poweroff?

Well it sounds like a lot, but it is not that hard. We try to model devices by their functionality, which maps to a uclass, so when we have a multi-function device we tend to model that with children, each with an appropriate uclass.

Regards,
Simon

#9 lore raw

Re: [PATCH v2 2/9] cmd: boot: implement PMIC based poweroff

24 липня 2023 р. 05:28:24 GMT+03:00, Simon Glass <[email protected]> написав(-ла):

Quoted 102 lines

Hi Svyatoslav,

Quoted 99 lines · Svyatoslav Ryhel

нд, 23 лип. 2023 р. о 06:48 Simon Glass <[email protected]> пише:

Quoted 96 lines

Hi Svyatoslav,

Quoted 86 lines · Svyatoslav Ryhel

Use new PMIC ops to perform device poweroff.

---
 cmd/Kconfig |  6 ++++++
 cmd/boot.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
cmd/Kconfig +6 -0
index ecfd575237..47654297f8 100644
@@ -1439,6 +1439,12 @@ config CMD_POWEROFF
        help
          Poweroff/Shutdown the system
 
+config CMD_PMIC_POWEROFF
+       bool "PMIC poweroff"
+       select CMD_POWEROFF
+       help
+         Shutdown the system using PMIC poweroff sequence.
+
 config CMD_READ
        bool "read - Read binary data from a partition"
        help
cmd/boot.c +40 -1
index 14839c1ced..4270034194 100644
@@ -9,7 +9,13 @@
  */
 #include <common.h>
 #include <command.h>
+#include <dm.h>
+#include <log.h>
 #include <net.h>
+#include <dm/device-internal.h>
+#include <dm/uclass-internal.h>
+#include <power/pmic.h>
+#include <linux/delay.h>
 
 #ifdef CONFIG_CMD_GO
 
@@ -64,6 +70,40 @@ U_BOOT_CMD(
 );
 
 #ifdef CONFIG_CMD_POWEROFF
+#ifdef CONFIG_CMD_PMIC_POWEROFF
+int do_poweroff(struct cmd_tbl *cmdtp, int flag,
+               int argc, char *const argv[])
+{
+       struct uc_pmic_priv *pmic_priv;
+       struct udevice *dev;
+       int ret;
+
+       for (uclass_find_first_device(UCLASS_PMIC, &dev);
+            dev;
+            uclass_find_next_device(&dev)) {
+               if (dev && !device_active(dev)) {
+                       ret = device_probe(dev);
+                       if (ret)
+                               return ret;
+               }
+
+               /* value we need to check is set after probe */
+               pmic_priv = dev_get_uclass_priv(dev);
+               if (pmic_priv->sys_pow_ctrl) {
+                       ret = pmic_poweroff(dev);
+
+                       /* wait some time and then print error */
+                       mdelay(5000);
+                       log_err("Failed to power off!!!\n");
+                       return ret;
+               }
+       }
+
+       /* no device should reach here */
+       return 1;
+}
+#endif
+
 U_BOOT_CMD(
        poweroff, 1, 0, do_poweroff,
        "Perform POWEROFF of the device",
--
Quoted 2 lines

2.39.2

How does this relate to sysreset_walk(SYSRESET_POWER_OFF) and do_poweroff() in cmd/boot.c?

Quoted 8 lines
Quoted 3 lines

Yes, it seems that I have misunderstood you, but non the less, you say that I have to implement a new separate pmic subdriver just to support poweroff?

Well it sounds like a lot, but it is not that hard. We try to model devices by their functionality, which maps to a uclass, so when we have a multi-function device we tend to model that with children, each with an appropriate uclass.

Alright, fair. I have prepared and tested sysreset for all PMICs I have sent and for Tegra in general. Unfortunately, they cannot be sent before existing patches are accepted and merged.

Quoted 2 lines

Regards,
Simon

#10 lore raw

Re: [PATCH v2 2/9] cmd: boot: implement PMIC based poweroff

Hi Svyatoslav,

Quoted 110 lines · Svyatoslav Ryhel

24 липня 2023 р. 05:28:24 GMT+03:00, Simon Glass <[email protected]> написав(-ла):

Quoted 106 lines

Hi Svyatoslav,

Quoted 102 lines · Svyatoslav Ryhel

нд, 23 лип. 2023 р. о 06:48 Simon Glass <[email protected]> пише:

Quoted 87 lines

Hi Svyatoslav,

Quoted 83 lines · Svyatoslav Ryhel

Use new PMIC ops to perform device poweroff.

---
 cmd/Kconfig |  6 ++++++
 cmd/boot.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
cmd/Kconfig +6 -0
index ecfd575237..47654297f8 100644
@@ -1439,6 +1439,12 @@ config CMD_POWEROFF
        help
          Poweroff/Shutdown the system
 
+config CMD_PMIC_POWEROFF
+       bool "PMIC poweroff"
+       select CMD_POWEROFF
+       help
+         Shutdown the system using PMIC poweroff sequence.
+
 config CMD_READ
        bool "read - Read binary data from a partition"
        help
cmd/boot.c +40 -0
index 14839c1ced..4270034194 100644
@@ -9,7 +9,13 @@
  */
 #include <common.h>
 #include <command.h>
+#include <dm.h>
+#include <log.h>
 #include <net.h>
+#include <dm/device-internal.h>
+#include <dm/uclass-internal.h>
+#include <power/pmic.h>
+#include <linux/delay.h>
 
 #ifdef CONFIG_CMD_GO
 
@@ -64,6 +70,40 @@ U_BOOT_CMD(
 );
 
 #ifdef CONFIG_CMD_POWEROFF
+#ifdef CONFIG_CMD_PMIC_POWEROFF
+int do_poweroff(struct cmd_tbl *cmdtp, int flag,
+               int argc, char *const argv[])
+{
+       struct uc_pmic_priv *pmic_priv;
+       struct udevice *dev;
+       int ret;
+
+       for (uclass_find_first_device(UCLASS_PMIC, &dev);
+            dev;
+            uclass_find_next_device(&dev)) {
+               if (dev && !device_active(dev)) {
+                       ret = device_probe(dev);
+                       if (ret)
+                               return ret;
+               }
+
+               /* value we need to check is set after probe */
+               pmic_priv = dev_get_uclass_priv(dev);
+               if (pmic_priv->sys_pow_ctrl) {
+                       ret = pmic_poweroff(dev);
+
+                       /* wait some time and then print error */
+                       mdelay(5000);
+                       log_err("Failed to power off!!!\n");
+                       return ret;
+               }
+       }
+
+       /* no device should reach here */
+       return 1;
+}
+#endif
+
 U_BOOT_CMD(
Quoted 9 lines
Quoted 5 lines
cmd/boot.c +0 -1
        poweroff, 1, 0, do_poweroff,
        "Perform POWEROFF of the device",
--

2.39.2

How does this relate to sysreset_walk(SYSRESET_POWER_OFF) and do_poweroff() in cmd/boot.c?

Yes, it seems that I have misunderstood you, but non the less, you say that I have to implement a new separate pmic subdriver just to support poweroff?

Quoted 6 lines
Quoted 4 lines

Well it sounds like a lot, but it is not that hard. We try to model devices by their functionality, which maps to a uclass, so when we have a multi-function device we tend to model that with children, each with an appropriate uclass.

Alright, fair. I have prepared and tested sysreset for all PMICs I have sent and for Tegra in general. Unfortunately, they cannot be sent before existing patches are accepted and merged.

You can ping the maintainer, or just note (in your cover letter) that they depend on another series, e.g. with a patchwork link. I often have 3-4 series backed up.

Regards,
Simon

Quoted 3 lines
Quoted 3 lines

Regards,
Simon

#11 lore raw

Re: [PATCH v2 2/9] cmd: boot: implement PMIC based poweroff

31 липня 2023 р. 20:08:06 GMT+03:00, Simon Glass <[email protected]> написав(-ла):

Quoted 118 lines

Hi Svyatoslav,

Quoted 115 lines · Svyatoslav Ryhel

24 липня 2023 р. 05:28:24 GMT+03:00, Simon Glass <[email protected]> написав(-ла):

Quoted 110 lines

Hi Svyatoslav,

Quoted 99 lines · Svyatoslav Ryhel

нд, 23 лип. 2023 р. о 06:48 Simon Glass <[email protected]> пише:

Quoted 87 lines

Hi Svyatoslav,

Quoted 83 lines · Svyatoslav Ryhel

Use new PMIC ops to perform device poweroff.

---
 cmd/Kconfig |  6 ++++++
 cmd/boot.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
cmd/Kconfig +6 -0
index ecfd575237..47654297f8 100644
@@ -1439,6 +1439,12 @@ config CMD_POWEROFF
        help
          Poweroff/Shutdown the system
 
+config CMD_PMIC_POWEROFF
+       bool "PMIC poweroff"
+       select CMD_POWEROFF
+       help
+         Shutdown the system using PMIC poweroff sequence.
+
 config CMD_READ
        bool "read - Read binary data from a partition"
        help
cmd/boot.c +40 -0
index 14839c1ced..4270034194 100644
@@ -9,7 +9,13 @@
  */
 #include <common.h>
 #include <command.h>
+#include <dm.h>
+#include <log.h>
 #include <net.h>
+#include <dm/device-internal.h>
+#include <dm/uclass-internal.h>
+#include <power/pmic.h>
+#include <linux/delay.h>
 
 #ifdef CONFIG_CMD_GO
 
@@ -64,6 +70,40 @@ U_BOOT_CMD(
 );
 
 #ifdef CONFIG_CMD_POWEROFF
+#ifdef CONFIG_CMD_PMIC_POWEROFF
+int do_poweroff(struct cmd_tbl *cmdtp, int flag,
+               int argc, char *const argv[])
+{
+       struct uc_pmic_priv *pmic_priv;
+       struct udevice *dev;
+       int ret;
+
+       for (uclass_find_first_device(UCLASS_PMIC, &dev);
+            dev;
+            uclass_find_next_device(&dev)) {
+               if (dev && !device_active(dev)) {
+                       ret = device_probe(dev);
+                       if (ret)
+                               return ret;
+               }
+
+               /* value we need to check is set after probe */
+               pmic_priv = dev_get_uclass_priv(dev);
+               if (pmic_priv->sys_pow_ctrl) {
+                       ret = pmic_poweroff(dev);
+
+                       /* wait some time and then print error */
+                       mdelay(5000);
+                       log_err("Failed to power off!!!\n");
+                       return ret;
+               }
+       }
+
+       /* no device should reach here */
+       return 1;
+}
+#endif
+
 U_BOOT_CMD(
Quoted 9 lines
Quoted 5 lines
cmd/boot.c +0 -1
        poweroff, 1, 0, do_poweroff,
        "Perform POWEROFF of the device",
--

2.39.2

How does this relate to sysreset_walk(SYSRESET_POWER_OFF) and do_poweroff() in cmd/boot.c?

Quoted 3 lines

Yes, it seems that I have misunderstood you, but non the less, you say that I have to implement a new separate pmic subdriver just to support poweroff?

Well it sounds like a lot, but it is not that hard. We try to model devices by their functionality, which maps to a uclass, so when we have a multi-function device we tend to model that with children, each with an appropriate uclass.

Quoted 5 lines
Quoted 1 line

Alright, fair. I have prepared and tested sysreset for all PMICs I have sent and for Tegra in general. Unfortunately, they cannot be sent before existing patches are accepted and merged.

You can ping the maintainer, or just note (in your cover letter) that they depend on another series, e.g. with a patchwork link. I often have 3-4 series backed up.

This is definitely a nice advice, thank you. Though, sysreset subdevices will change pmic mfd, so this basically is changing code which even does not exist yet.

P. S. If you remember our recent conversation about gpio cell of pmic, I have tested it with max77663 (single cell pmic) and modded gpio-uclass code. It worked surprisingly well with the regulator handling code I have proposed previously, and can provide gpios for keys and regulators.

Those regulator changes affect mostly rockchip and srm32mp1. Maybe if you have rk3399 or stm32mp1 could you test them?

Best regards,
Svyatoslav R.

Quoted 6 lines

Regards,
Simon

Quoted 3 lines
Quoted 3 lines

Regards,
Simon

#12 lore raw

Re: [PATCH v2 2/9] cmd: boot: implement PMIC based poweroff

Hi Svyatoslav,

Quoted 128 lines · Svyatoslav Ryhel

31 липня 2023 р. 20:08:06 GMT+03:00, Simon Glass <[email protected]> написав(-ла):

Quoted 118 lines

Hi Svyatoslav,

Quoted 115 lines · Svyatoslav Ryhel

24 липня 2023 р. 05:28:24 GMT+03:00, Simon Glass <[email protected]> написав(-ла):

Quoted 110 lines

Hi Svyatoslav,

Quoted 99 lines · Svyatoslav Ryhel

нд, 23 лип. 2023 р. о 06:48 Simon Glass <[email protected]> пише:

Quoted 87 lines

Hi Svyatoslav,

Quoted 83 lines · Svyatoslav Ryhel

Use new PMIC ops to perform device poweroff.

---
 cmd/Kconfig |  6 ++++++
 cmd/boot.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
cmd/Kconfig +6 -0
index ecfd575237..47654297f8 100644
@@ -1439,6 +1439,12 @@ config CMD_POWEROFF
        help
          Poweroff/Shutdown the system
 
+config CMD_PMIC_POWEROFF
+       bool "PMIC poweroff"
+       select CMD_POWEROFF
+       help
+         Shutdown the system using PMIC poweroff sequence.
+
 config CMD_READ
        bool "read - Read binary data from a partition"
        help
cmd/boot.c +40 -0
index 14839c1ced..4270034194 100644
@@ -9,7 +9,13 @@
  */
 #include <common.h>
 #include <command.h>
+#include <dm.h>
+#include <log.h>
 #include <net.h>
+#include <dm/device-internal.h>
+#include <dm/uclass-internal.h>
+#include <power/pmic.h>
+#include <linux/delay.h>
 
 #ifdef CONFIG_CMD_GO
 
@@ -64,6 +70,40 @@ U_BOOT_CMD(
 );
 
 #ifdef CONFIG_CMD_POWEROFF
+#ifdef CONFIG_CMD_PMIC_POWEROFF
+int do_poweroff(struct cmd_tbl *cmdtp, int flag,
+               int argc, char *const argv[])
+{
+       struct uc_pmic_priv *pmic_priv;
+       struct udevice *dev;
+       int ret;
+
+       for (uclass_find_first_device(UCLASS_PMIC, &dev);
+            dev;
+            uclass_find_next_device(&dev)) {
+               if (dev && !device_active(dev)) {
+                       ret = device_probe(dev);
+                       if (ret)
+                               return ret;
+               }
+
+               /* value we need to check is set after probe */
+               pmic_priv = dev_get_uclass_priv(dev);
+               if (pmic_priv->sys_pow_ctrl) {
+                       ret = pmic_poweroff(dev);
+
+                       /* wait some time and then print error */
+                       mdelay(5000);
+                       log_err("Failed to power off!!!\n");
+                       return ret;
+               }
+       }
+
+       /* no device should reach here */
+       return 1;
+}
+#endif
+
 U_BOOT_CMD(
Quoted 9 lines
Quoted 5 lines
cmd/boot.c +0 -1
        poweroff, 1, 0, do_poweroff,
        "Perform POWEROFF of the device",
--

2.39.2

How does this relate to sysreset_walk(SYSRESET_POWER_OFF) and do_poweroff() in cmd/boot.c?

Quoted 3 lines

Yes, it seems that I have misunderstood you, but non the less, you say that I have to implement a new separate pmic subdriver just to support poweroff?

Well it sounds like a lot, but it is not that hard. We try to model devices by their functionality, which maps to a uclass, so when we have a multi-function device we tend to model that with children, each with an appropriate uclass.

Quoted 5 lines
Quoted 1 line

Alright, fair. I have prepared and tested sysreset for all PMICs I have sent and for Tegra in general. Unfortunately, they cannot be sent before existing patches are accepted and merged.

You can ping the maintainer, or just note (in your cover letter) that they depend on another series, e.g. with a patchwork link. I often have 3-4 series backed up.

Quoted 5 lines

This is definitely a nice advice, thank you. Though, sysreset subdevices will change pmic mfd, so this basically is changing code which even does not exist yet.

P. S. If you remember our recent conversation about gpio cell of pmic, I have tested it with max77663 (single cell pmic) and modded gpio-uclass code. It worked surprisingly well with the regulator handling code I have proposed previously, and can provide gpios for keys and regulators.

Those regulator changes affect mostly rockchip and srm32mp1. Maybe if you have rk3399 or stm32mp1 could you test them?

Yes I have rk3399, but I have lost track of your work. Can you please send me the patchwork link for your series?

Regards,
Simon

#13 lore raw

Re: [PATCH v2 2/9] cmd: boot: implement PMIC based poweroff

9 серпня 2023 р. 05:03:41 GMT+03:00, Simon Glass <[email protected]> написав(-ла):

Quoted 131 lines

Hi Svyatoslav,

Quoted 128 lines · Svyatoslav Ryhel

31 липня 2023 р. 20:08:06 GMT+03:00, Simon Glass <[email protected]> написав(-ла):

Quoted 123 lines

Hi Svyatoslav,

Quoted 110 lines · Svyatoslav Ryhel

24 липня 2023 р. 05:28:24 GMT+03:00, Simon Glass <[email protected]> написав(-ла):

Quoted 106 lines

Hi Svyatoslav,

Quoted 102 lines · Svyatoslav Ryhel

нд, 23 лип. 2023 р. о 06:48 Simon Glass <[email protected]> пише:

Quoted 87 lines

Hi Svyatoslav,

Quoted 83 lines · Svyatoslav Ryhel

Use new PMIC ops to perform device poweroff.

---
 cmd/Kconfig |  6 ++++++
 cmd/boot.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
cmd/Kconfig +6 -0
index ecfd575237..47654297f8 100644
@@ -1439,6 +1439,12 @@ config CMD_POWEROFF
        help
          Poweroff/Shutdown the system
 
+config CMD_PMIC_POWEROFF
+       bool "PMIC poweroff"
+       select CMD_POWEROFF
+       help
+         Shutdown the system using PMIC poweroff sequence.
+
 config CMD_READ
        bool "read - Read binary data from a partition"
        help
cmd/boot.c +40 -0
index 14839c1ced..4270034194 100644
@@ -9,7 +9,13 @@
  */
 #include <common.h>
 #include <command.h>
+#include <dm.h>
+#include <log.h>
 #include <net.h>
+#include <dm/device-internal.h>
+#include <dm/uclass-internal.h>
+#include <power/pmic.h>
+#include <linux/delay.h>
 
 #ifdef CONFIG_CMD_GO
 
@@ -64,6 +70,40 @@ U_BOOT_CMD(
 );
 
 #ifdef CONFIG_CMD_POWEROFF
+#ifdef CONFIG_CMD_PMIC_POWEROFF
+int do_poweroff(struct cmd_tbl *cmdtp, int flag,
+               int argc, char *const argv[])
+{
+       struct uc_pmic_priv *pmic_priv;
+       struct udevice *dev;
+       int ret;
+
+       for (uclass_find_first_device(UCLASS_PMIC, &dev);
+            dev;
+            uclass_find_next_device(&dev)) {
+               if (dev && !device_active(dev)) {
+                       ret = device_probe(dev);
+                       if (ret)
+                               return ret;
+               }
+
+               /* value we need to check is set after probe */
+               pmic_priv = dev_get_uclass_priv(dev);
+               if (pmic_priv->sys_pow_ctrl) {
+                       ret = pmic_poweroff(dev);
+
+                       /* wait some time and then print error */
+                       mdelay(5000);
+                       log_err("Failed to power off!!!\n");
+                       return ret;
+               }
+       }
+
+       /* no device should reach here */
+       return 1;
+}
+#endif
+
 U_BOOT_CMD(
Quoted 9 lines
Quoted 5 lines
cmd/boot.c +0 -1
        poweroff, 1, 0, do_poweroff,
        "Perform POWEROFF of the device",
--

2.39.2

How does this relate to sysreset_walk(SYSRESET_POWER_OFF) and do_poweroff() in cmd/boot.c?

Yes, it seems that I have misunderstood you, but non the less, you say that I have to implement a new separate pmic subdriver just to support poweroff?

Quoted 6 lines
Quoted 4 lines

Well it sounds like a lot, but it is not that hard. We try to model devices by their functionality, which maps to a uclass, so when we have a multi-function device we tend to model that with children, each with an appropriate uclass.

Alright, fair. I have prepared and tested sysreset for all PMICs I have sent and for Tegra in general. Unfortunately, they cannot be sent before existing patches are accepted and merged.

You can ping the maintainer, or just note (in your cover letter) that they depend on another series, e.g. with a patchwork link. I often have 3-4 series backed up.

Quoted 8 lines
Quoted 5 lines

This is definitely a nice advice, thank you. Though, sysreset subdevices will change pmic mfd, so this basically is changing code which even does not exist yet.

P. S. If you remember our recent conversation about gpio cell of pmic, I have tested it with max77663 (single cell pmic) and modded gpio-uclass code. It worked surprisingly well with the regulator handling code I have proposed previously, and can provide gpios for keys and regulators.

Those regulator changes affect mostly rockchip and srm32mp1. Maybe if you have rk3399 or stm32mp1 could you test them?

Yes I have rk3399, but I have lost track of your work. Can you please send me the patchwork link for your series?

Jonas Karlman proposed a nice adjustments making my patch less invasive. I enclose the link to regulator changes.

What I can tell from my side, it works correctly and I have adjusted dm tests so they pass and test implemented changes at the same time.

Currently I face i2c errors with pmic always-on/boot-on regulators (regulator probes ok, pmic probes and works ok, i2c gives error on xfer).

Error occurs only if pmic regulator is probed after bind, if it is probed on pmic post_probe I have no error. Maybe you can reproduse this on your hw.

Best regards,
Svyatoslav R.

Link:
https://patchwork.ozlabs.org/project/uboot/list/?series=367513

Quoted 2 lines

Regards,
Simon

#14 lore raw

Re: [PATCH v2 2/9] cmd: boot: implement PMIC based poweroff

Hi Svyatoslav,

Quoted 144 lines · Svyatoslav Ryhel

9 серпня 2023 р. 05:03:41 GMT+03:00, Simon Glass <[email protected]> написав(-ла):

Quoted 131 lines

Hi Svyatoslav,

Quoted 128 lines · Svyatoslav Ryhel

31 липня 2023 р. 20:08:06 GMT+03:00, Simon Glass <[email protected]> написав(-ла):

Quoted 123 lines

Hi Svyatoslav,

Quoted 110 lines · Svyatoslav Ryhel

24 липня 2023 р. 05:28:24 GMT+03:00, Simon Glass <[email protected]> написав(-ла):

Quoted 106 lines

Hi Svyatoslav,

Quoted 102 lines · Svyatoslav Ryhel

нд, 23 лип. 2023 р. о 06:48 Simon Glass <[email protected]> пише:

Quoted 87 lines

Hi Svyatoslav,

Quoted 83 lines · Svyatoslav Ryhel

Use new PMIC ops to perform device poweroff.

---
 cmd/Kconfig |  6 ++++++
 cmd/boot.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
cmd/Kconfig +6 -0
index ecfd575237..47654297f8 100644
@@ -1439,6 +1439,12 @@ config CMD_POWEROFF
        help
          Poweroff/Shutdown the system
 
+config CMD_PMIC_POWEROFF
+       bool "PMIC poweroff"
+       select CMD_POWEROFF
+       help
+         Shutdown the system using PMIC poweroff sequence.
+
 config CMD_READ
        bool "read - Read binary data from a partition"
        help
cmd/boot.c +40 -0
index 14839c1ced..4270034194 100644
@@ -9,7 +9,13 @@
  */
 #include <common.h>
 #include <command.h>
+#include <dm.h>
+#include <log.h>
 #include <net.h>
+#include <dm/device-internal.h>
+#include <dm/uclass-internal.h>
+#include <power/pmic.h>
+#include <linux/delay.h>
 
 #ifdef CONFIG_CMD_GO
 
@@ -64,6 +70,40 @@ U_BOOT_CMD(
 );
 
 #ifdef CONFIG_CMD_POWEROFF
+#ifdef CONFIG_CMD_PMIC_POWEROFF
+int do_poweroff(struct cmd_tbl *cmdtp, int flag,
+               int argc, char *const argv[])
+{
+       struct uc_pmic_priv *pmic_priv;
+       struct udevice *dev;
+       int ret;
+
+       for (uclass_find_first_device(UCLASS_PMIC, &dev);
+            dev;
+            uclass_find_next_device(&dev)) {
+               if (dev && !device_active(dev)) {
+                       ret = device_probe(dev);
+                       if (ret)
+                               return ret;
+               }
+
+               /* value we need to check is set after probe */
+               pmic_priv = dev_get_uclass_priv(dev);
+               if (pmic_priv->sys_pow_ctrl) {
+                       ret = pmic_poweroff(dev);
+
+                       /* wait some time and then print error */
+                       mdelay(5000);
+                       log_err("Failed to power off!!!\n");
+                       return ret;
+               }
+       }
+
+       /* no device should reach here */
+       return 1;
+}
+#endif
+
 U_BOOT_CMD(
Quoted 9 lines
Quoted 5 lines
cmd/boot.c +0 -1
        poweroff, 1, 0, do_poweroff,
        "Perform POWEROFF of the device",
--

2.39.2

How does this relate to sysreset_walk(SYSRESET_POWER_OFF) and do_poweroff() in cmd/boot.c?

Yes, it seems that I have misunderstood you, but non the less, you say that I have to implement a new separate pmic subdriver just to support poweroff?

Quoted 6 lines
Quoted 4 lines

Well it sounds like a lot, but it is not that hard. We try to model devices by their functionality, which maps to a uclass, so when we have a multi-function device we tend to model that with children, each with an appropriate uclass.

Alright, fair. I have prepared and tested sysreset for all PMICs I have sent and for Tegra in general. Unfortunately, they cannot be sent before existing patches are accepted and merged.

You can ping the maintainer, or just note (in your cover letter) that they depend on another series, e.g. with a patchwork link. I often have 3-4 series backed up.

Quoted 8 lines
Quoted 5 lines

This is definitely a nice advice, thank you. Though, sysreset subdevices will change pmic mfd, so this basically is changing code which even does not exist yet.

P. S. If you remember our recent conversation about gpio cell of pmic, I have tested it with max77663 (single cell pmic) and modded gpio-uclass code. It worked surprisingly well with the regulator handling code I have proposed previously, and can provide gpios for keys and regulators.

Those regulator changes affect mostly rockchip and srm32mp1. Maybe if you have rk3399 or stm32mp1 could you test them?

Yes I have rk3399, but I have lost track of your work. Can you please send me the patchwork link for your series?

Quoted 7 lines

Jonas Karlman proposed a nice adjustments making my patch less invasive. I enclose the link to regulator changes.

What I can tell from my side, it works correctly and I have adjusted dm tests so they pass and test implemented changes at the same time.

Currently I face i2c errors with pmic always-on/boot-on regulators (regulator probes ok, pmic probes and works ok, i2c gives error on xfer).

Error occurs only if pmic regulator is probed after bind, if it is probed on pmic post_probe I have no error. Maybe you can reproduse this on your hw.

Well probe after bind is bad. We should let all devices be bound, then worry about probing them when needed.

If you need this to happen from the board, why? It really should be an lazy init, only when needed. If boards need this in general, then let's think about an event to kick it off.

I don't see any failures with that series on Bob,

Quoted 9 lines

Best regards,
Svyatoslav R.

Link:
https://patchwork.ozlabs.org/project/uboot/list/?series=367513

Quoted 2 lines

Regards,
Simon

Regards,
Simon

#15 lore raw

PATCH v2 3/9 power: pmic: palmas: support TI TPS65913 PMIC

In reply to Svyatoslav Ryhel

Existing PALMAS PMIC driver is fully compatible with TI TPS65913 PMIC found in many Tegra 4 devices, like Tegra Note 7 and ASUS TF701T. TPS65913 shares same structure of regulators like TPS659038 so data can be reused.

---
 drivers/power/pmic/palmas.c | 1 +
 1 file changed, 1 insertion(+)
drivers/power/pmic/palmas.c +1 -0
index 6080cbff0b..d6eb9cb433 100644
@@ -87,6 +87,7 @@ static struct dm_pmic_ops palmas_ops = {
 
 static const struct udevice_id palmas_ids[] = {
 	{ .compatible = "ti,tps659038", .data = TPS659038 },
+	{ .compatible = "ti,tps65913" , .data = TPS659038 },
 	{ .compatible = "ti,tps65917" , .data = TPS65917 },
 	{ }
 };
Signature · 1 line
2.39.2
#16 lore raw

PATCH v2 4/9 power: pmic: add the base MAX77663 PMIC support

In reply to Svyatoslav Ryhel

Add support to bind the regulators/child nodes with the pmic. Also adds the pmic i2c based read/write functions to access pmic registers.

---
 doc/device-tree-bindings/pmic/max77663.txt |  84 +++++++++++++++++
 drivers/power/pmic/Kconfig                 |   6 ++
 drivers/power/pmic/Makefile                |   1 +
 drivers/power/pmic/max77663.c              | 105 +++++++++++++++++++++
 include/power/max77663.h                   |  44 +++++++++
 5 files changed, 240 insertions(+)
 create mode 100644 doc/device-tree-bindings/pmic/max77663.txt
 create mode 100644 drivers/power/pmic/max77663.c
 create mode 100644 include/power/max77663.h
doc/device-tree-bindings/pmic/max77663.txt new file +84 -0
new file mode 100644
index 0000000000..ddb7d3eb14
@@ -0,0 +1,84 @@
+MAXIM, MAX77663 PMIC
+
+This device uses two drivers:
+- drivers/power/pmic/max77663.c (for parent device)
+- drivers/power/regulator/max77663_regulator.c (for child regulators)
+
+This chapter describes the binding info for the PMIC driver and regulators.
+
+Required properties for PMIC:
+- compatible: "maxim,max77663"
+- reg: usually 0x1c or 0x3c
+
+With those two properties, the pmic device can be used for read/write only.
+To bind each regulator, the optional regulators subnode should exists.
+
+Optional subnode:
+- name: regulators (subnode list of each device's regulator)
+
+Regulators subnode contains set on supported regulators.
+
+Required properties:
+- regulator-name: used for regulator uclass platform data '.name',
+
+List of supported regulator nodes names for max77663:
+- sd0, sd1, sd2, sd3, ldo0, ldo1, ldo2, ldo3, ldo4, ldo5, ldo6, ldo7, ldo8
+
+Optional:
+- regulator-min-microvolt: minimum allowed Voltage to set
+- regulator-max-microvolt: minimum allowed Voltage to set
+- regulator-always-on: regulator should be never disabled
+- regulator-boot-on: regulator should be enabled by the bootloader
+
+Linux driver binding for this driver is compatible.
+
+Example:
+
+max77663@1c {
+	compatible = "maxim,max77663";
+	reg = <0x1c>;
+
+	regulators {
+		sd0 {
+			regulator-name = "vdd_cpu";
+			regulator-min-microvolt = <800000>;
+			regulator-max-microvolt = <1250000>;
+			regulator-always-on;
+			regulator-boot-on;
+		};
+
+		...
+
+		ldo0 {
+			regulator-name = "avdd_pll";
+			regulator-min-microvolt = <1200000>;
+			regulator-max-microvolt = <1200000>;
+		};
+
+		...
+
+		ldo2 {
+			regulator-name = "avdd_usb";
+			regulator-min-microvolt = <3300000>;
+			regulator-max-microvolt = <3300000>;
+			regulator-always-on;
+			regulator-boot-on;
+		};
+
+		ldo3 {
+			regulator-name = "vdd_sdmmc3";
+			regulator-min-microvolt = <3000000>;
+			regulator-max-microvolt = <3000000>;
+			regulator-always-on;
+			regulator-boot-on;
+		};
+
+		...
+
+		ldo8 {
+			regulator-name = "avdd_dsi_csi";
+			regulator-min-microvolt = <1200000>;
+			regulator-max-microvolt = <1200000>;
+		};
+	};
+};
drivers/power/pmic/Kconfig +6 -0
index 176fb07c65..abea0fe4ed 100644
@@ -184,6 +184,12 @@ config SPL_DM_PMIC_PFUZE100
 	This config enables implementation of driver-model pmic uclass features
 	for PMIC PFUZE100 in SPL. The driver implements read/write operations.
 
+config DM_PMIC_MAX77663
+	bool "Enable Driver Model for PMIC MAX77663"
+	---help---
+	This config enables implementation of driver-model pmic uclass features
+	for PMIC MAX77663. The driver implements read/write operations.
+
 config DM_PMIC_MAX77686
 	bool "Enable Driver Model for PMIC MAX77686"
 	---help---
drivers/power/pmic/Makefile +1 -0
index 0b3b3d62d0..414a9d8225 100644
@@ -6,6 +6,7 @@
 obj-$(CONFIG_$(SPL_TPL_)DM_PMIC) += pmic-uclass.o
 obj-$(CONFIG_$(SPL_)DM_PMIC_FAN53555) += fan53555.o
 obj-$(CONFIG_$(SPL_)DM_PMIC_DA9063) += da9063.o
+obj-$(CONFIG_$(SPL_)DM_PMIC_MAX77663) += max77663.o
 obj-$(CONFIG_DM_PMIC_MAX77686) += max77686.o
 obj-$(CONFIG_DM_PMIC_MAX8998) += max8998.o
 obj-$(CONFIG_DM_PMIC_MC34708) += mc34708.o
drivers/power/pmic/max77663.c new file +105 -0

105 lines not on this page · raw message

include/power/max77663.h new file +44 -0

44 lines not on this page · raw message

Signature · 1 line
2.39.2
#17 lore raw

PATCH v2 5/9 power: regulator: max77663: add regulator support

In reply to Svyatoslav Ryhel

The driver provides regulator set/get voltage enable/disable functions for MAXIM MAX77663 PMICs.

---
 drivers/power/regulator/Kconfig              |   8 +
 drivers/power/regulator/Makefile             |   1 +
 drivers/power/regulator/max77663_regulator.c | 358 +++++++++++++++++++
 3 files changed, 367 insertions(+)
 create mode 100644 drivers/power/regulator/max77663_regulator.c
drivers/power/regulator/Kconfig +8 -0
index eb5aa38c1c..571debd54e 100644
@@ -141,6 +141,14 @@ config SPL_REGULATOR_PWM
 	  This config enables implementation of driver-model regulator uclass
 	  features for PWM regulators in SPL.
 
+config DM_REGULATOR_MAX77663
+	bool "Enable Driver Model for REGULATOR MAX77663"
+	depends on DM_REGULATOR && DM_PMIC_MAX77663
+	---help---
+	This config enables implementation of driver-model regulator uclass
+	features for REGULATOR MAX77663. The driver implements get/set api for:
+	value and enable.
+
 config DM_REGULATOR_MAX77686
 	bool "Enable Driver Model for REGULATOR MAX77686"
 	depends on DM_REGULATOR && DM_PMIC_MAX77686
drivers/power/regulator/Makefile +1 -0
index d9e0cd5949..8d73169b50 100644
@@ -10,6 +10,7 @@ obj-$(CONFIG_REGULATOR_AS3722)	+= as3722_regulator.o
 obj-$(CONFIG_$(SPL_)REGULATOR_AXP) += axp_regulator.o
 obj-$(CONFIG_$(SPL_)REGULATOR_AXP_USB_POWER) += axp_usb_power.o
 obj-$(CONFIG_$(SPL_)DM_REGULATOR_DA9063) += da9063.o
+obj-$(CONFIG_$(SPL_)DM_REGULATOR_MAX77663) += max77663_regulator.o
 obj-$(CONFIG_DM_REGULATOR_MAX77686) += max77686.o
 obj-$(CONFIG_DM_REGULATOR_NPCM8XX) += npcm8xx_regulator.o
 obj-$(CONFIG_$(SPL_)DM_PMIC_PFUZE100) += pfuze100.o
drivers/power/regulator/max77663_regulator.c new file +358 -0

358 lines not on this page · raw message

Signature · 1 line
2.39.2
#18 lore raw

PATCH v2 6/9 power: pmic: add the base TPS80031 PMIC support

In reply to Svyatoslav Ryhel

Add support to bind the regulators/child nodes with the pmic. Also adds the pmic i2c based read/write functions to access pmic registers.

---
 doc/device-tree-bindings/pmic/tps80031.txt | 76 +++++++++++++++++
 drivers/power/pmic/Kconfig                 |  6 ++
 drivers/power/pmic/Makefile                |  1 +
 drivers/power/pmic/tps80031.c              | 97 ++++++++++++++++++++++
 include/power/tps80031.h                   | 45 ++++++++++
 5 files changed, 225 insertions(+)
 create mode 100644 doc/device-tree-bindings/pmic/tps80031.txt
 create mode 100644 drivers/power/pmic/tps80031.c
 create mode 100644 include/power/tps80031.h
doc/device-tree-bindings/pmic/tps80031.txt new file +76 -0
new file mode 100644
index 0000000000..577e6de1c1
@@ -0,0 +1,76 @@
+Texas Instruments, TPS80031/TPS80032 PMIC
+
+This device uses two drivers:
+- drivers/power/pmic/tps80031.c (for parent device)
+- drivers/power/regulator/tps80031_regulator.c (for child regulators)
+
+This chapter describes the binding info for the PMIC driver and regulators.
+
+Required properties for PMIC:
+- compatible: "ti,tps80031" or "ti,tps80032"
+- reg: 0x48
+
+With those two properties, the pmic device can be used for read/write only.
+To bind each regulator, the optional regulators subnode should exists.
+
+Optional subnode:
+- name: regulators (subnode list of each device's regulator)
+
+Regulators subnode contains set on supported regulators.
+
+Required properties:
+- regulator-name: used for regulator uclass platform data '.name',
+
+List of supported regulator nodes names for tps80031/tps80032:
+- smps1, smps2, smps3, smps4, smps5
+- ldo1, ldo2, ldo3, ldo4, ldo5, ldo6, ldo7, ldoln, ldousb
+
+SMPS5 in Linux 3.1.10 is referred as vio, but datasheet clearly names it SMPS5.
+
+Optional:
+- regulator-min-microvolt: minimum allowed Voltage to set
+- regulator-max-microvolt: minimum allowed Voltage to set
+- regulator-always-on: regulator should be never disabled
+- regulator-boot-on: regulator should be enabled by the bootloader
+
+Example:
+
+tps80032@48 {
+	compatible = "ti,tps80032";
+	reg = <0x48>;
+
+	regulators {
+		smps1 {
+			regulator-name = "vdd_cpu";
+			regulator-min-microvolt = <800000>;
+			regulator-max-microvolt = <1250000>;
+			regulator-always-on;
+			regulator-boot-on;
+		};
+
+		...
+
+		smps5 {
+			regulator-name = "vdd_1v8_gen";
+			regulator-min-microvolt = <1800000>;
+			regulator-max-microvolt = <1800000>;
+			regulator-always-on;
+			regulator-boot-on;
+		};
+
+		ldo1 {
+			regulator-name = "avdd_dsi_csi";
+			regulator-min-microvolt = <1200000>;
+			regulator-max-microvolt = <1200000>;
+			regulator-boot-on;
+		};
+
+		...
+
+		ldousb {
+			regulator-name = "avdd_usb";
+			regulator-min-microvolt = <3300000>;
+			regulator-max-microvolt = <3300000>;
+		};
+	};
+};
drivers/power/pmic/Kconfig +6 -0
index abea0fe4ed..d25fe1ce0d 100644
@@ -347,6 +347,12 @@ config DM_PMIC_TPS65910
 	DC-DC converter, 8 LDOs and a RTC. This driver binds the SMPS and LDO
 	pmic children.
 
+config DM_PMIC_TPS80031
+	bool "Enable driver for Texas Instruments TPS80031/TPS80032 PMIC"
+	---help---
+	The TPS80031/TPS80032 are PMIC's containing several LDOs, SMPS.
+	This driver binds the pmic children.
+
 config PMIC_STPMIC1
 	bool "Enable support for STMicroelectronics STPMIC1 PMIC"
 	depends on DM_I2C
drivers/power/pmic/Makefile +1 -0
index 414a9d8225..55ee614364 100644
@@ -27,6 +27,7 @@ obj-$(CONFIG_$(SPL_)PMIC_RN5T567) += rn5t567.o
 obj-$(CONFIG_PMIC_TPS65090) += tps65090.o
 obj-$(CONFIG_PMIC_S5M8767) += s5m8767.o
 obj-$(CONFIG_DM_PMIC_TPS65910) += pmic_tps65910_dm.o
+obj-$(CONFIG_$(SPL_)DM_PMIC_TPS80031) += tps80031.o
 obj-$(CONFIG_$(SPL_)PMIC_PALMAS) += palmas.o
 obj-$(CONFIG_$(SPL_)PMIC_LP873X) += lp873x.o
 obj-$(CONFIG_$(SPL_)PMIC_LP87565) += lp87565.o
drivers/power/pmic/tps80031.c new file +97 -0

97 lines not on this page · raw message

include/power/tps80031.h new file +45 -0

45 lines not on this page · raw message

Signature · 1 line
2.39.2
#19 lore raw

PATCH v2 7/9 power: regulator: tps80031: add regulator support

In reply to Svyatoslav Ryhel

The driver provides regulator set/get voltage enable/disable functions for TI TPS80031/TPS80032 PMICs.

---
 drivers/power/regulator/Kconfig              |   8 +
 drivers/power/regulator/Makefile             |   1 +
 drivers/power/regulator/tps80031_regulator.c | 296 +++++++++++++++++++
 3 files changed, 305 insertions(+)
 create mode 100644 drivers/power/regulator/tps80031_regulator.c
drivers/power/regulator/Kconfig +8 -0
index 571debd54e..f297e408cd 100644
@@ -355,6 +355,14 @@ config DM_REGULATOR_TPS62360
 	implements the get/set api for value only, as the power line is
 	always on.
 
+config DM_REGULATOR_TPS80031
+	bool "Enable driver for TPS80031/TPS80032 PMIC regulators"
+	depends on DM_PMIC_TPS80031
+	---help---
+	This enables implementation of driver-model regulator uclass
+	features for TPS80031/TPS80032 PMICs. The driver implements
+	get/set api for: value and enable.
+
 config DM_REGULATOR_STPMIC1
 	bool "Enable driver for STPMIC1 regulators"
 	depends on DM_REGULATOR && PMIC_STPMIC1
drivers/power/regulator/Makefile +1 -0
index 8d73169b50..3ef55dc534 100644
@@ -33,6 +33,7 @@ obj-$(CONFIG_$(SPL_)DM_REGULATOR_LP87565) += lp87565_regulator.o
 obj-$(CONFIG_$(SPL_)DM_REGULATOR_STM32_VREFBUF) += stm32-vrefbuf.o
 obj-$(CONFIG_DM_REGULATOR_TPS65910) += tps65910_regulator.o
 obj-$(CONFIG_DM_REGULATOR_TPS62360) += tps62360_regulator.o
+obj-$(CONFIG_$(SPL_)DM_REGULATOR_TPS80031) += tps80031_regulator.o
 obj-$(CONFIG_$(SPL_)DM_REGULATOR_STPMIC1) += stpmic1.o
 obj-$(CONFIG_DM_REGULATOR_TPS65941) += tps65941_regulator.o
 obj-$(CONFIG_DM_REGULATOR_SCMI) += scmi_regulator.o
drivers/power/regulator/tps80031_regulator.c new file +296 -0

296 lines not on this page · raw message

Signature · 1 line
2.39.2
#20 lore raw

PATCH v2 8/9 power: pmic: tps65910: add TPS65911 PMIC support

In reply to Svyatoslav Ryhel

Add support to bind the regulators/child nodes with the pmic. Also adds the pmic i2c based read/write functions to access pmic registers.

---
 doc/device-tree-bindings/pmic/tps65911.txt | 78 ++++++++++++++++++++++
 drivers/power/pmic/pmic_tps65910_dm.c      | 49 +++++++++++++-
 include/power/tps65910_pmic.h              | 52 +++++++++++++++
 3 files changed, 176 insertions(+), 3 deletions(-)
 create mode 100644 doc/device-tree-bindings/pmic/tps65911.txt
doc/device-tree-bindings/pmic/tps65911.txt new file +78 -0
new file mode 100644
index 0000000000..29270efbfe
@@ -0,0 +1,78 @@
+Texas Instruments, TPS65911 PMIC
+
+This device uses two drivers:
+- drivers/power/pmic/tps65910.c (for parent device)
+- drivers/power/regulator/tps65911_regulator.c (for child regulators)
+
+This chapter describes the binding info for the PMIC driver and regulators.
+
+Required properties for PMIC:
+- compatible: "ti,tps65911"
+- reg: 0x2d
+
+With those two properties, the pmic device can be used for read/write only.
+To bind each regulator, the optional regulators subnode should exists.
+
+Optional subnode:
+- name: regulators (subnode list of each device's regulator)
+
+Regulators subnode contains set on supported regulators.
+
+Required properties:
+- regulator-name: used for regulator uclass platform data '.name',
+
+List of supported regulator nodes names for tps65911:
+- vdd1, vdd2, vddctrl, vddio
+- ldo1, ldo2, ldo3, ldo4, ldo5, ldo6, ldo7, ldo8
+
+vddio in datasheet is referred as vio, but for reduction of code and
+unification of smps regulators it is named vddio.
+
+Optional:
+- regulator-min-microvolt: minimum allowed Voltage to set
+- regulator-max-microvolt: minimum allowed Voltage to set
+- regulator-always-on: regulator should be never disabled
+- regulator-boot-on: regulator should be enabled by the bootloader
+
+Example:
+
+tps65911@2d {
+	compatible = "ti,tps65911";
+	reg = <0x2d>;
+
+	regulators {
+		vdd1 {
+			regulator-name = "vdd_1v2_backlight";
+			regulator-min-microvolt = <1200000>;
+			regulator-max-microvolt = <1200000>;
+			regulator-always-on;
+			regulator-boot-on;
+		};
+
+		...
+
+		vddio {
+			regulator-name = "vdd_1v8_gen";
+			regulator-min-microvolt = <1800000>;
+			regulator-max-microvolt = <1800000>;
+			regulator-always-on;
+			regulator-boot-on;
+		};
+
+		ldo1 {
+			regulator-name = "vdd_emmc_core";
+			regulator-min-microvolt = <3300000>;
+			regulator-max-microvolt = <3300000>;
+			regulator-always-on;
+			regulator-boot-on;
+		};
+
+		...
+
+		ldo8 {
+			regulator-name = "vdd_ddr_hs";
+			regulator-min-microvolt = <1000000>;
+			regulator-max-microvolt = <1000000>;
+		};
+	};
+};
drivers/power/pmic/pmic_tps65910_dm.c +46 -3

95 lines not on this page · raw message

include/power/tps65910_pmic.h +52 -0

68 lines not on this page · raw message

Signature · 1 line
2.39.2
Reviewed-by on v2 8/9
#21 lore raw

Re: [PATCH v2 8/9] power: pmic: tps65910: add TPS65911 PMIC support

Quoted 5 lines · Svyatoslav Ryhel

Add support to bind the regulators/child nodes with the pmic. Also adds the pmic i2c based read/write functions to access pmic registers.

Quoted 8 lines
---
 doc/device-tree-bindings/pmic/tps65911.txt | 78 ++++++++++++++++++++++
 drivers/power/pmic/pmic_tps65910_dm.c      | 49 +++++++++++++-
 include/power/tps65910_pmic.h              | 52 +++++++++++++++
 3 files changed, 176 insertions(+), 3 deletions(-)
 create mode 100644 doc/device-tree-bindings/pmic/tps65911.txt

nits below

[..]

Quoted 28 lines
drivers/power/pmic/pmic_tps65910_dm.c +7 -1
index e03ddc98d7..770010d53d 100644
@@ -11,13 +11,19 @@
 #include <power/regulator.h>
 #include <power/tps65910_pmic.h>
 
-static const struct pmic_child_info pmic_children_info[] = {
+static const struct pmic_child_info tps65910_children_info[] = {
        { .prefix = "ldo_", .driver = TPS65910_LDO_DRIVER },
        { .prefix = "buck_", .driver = TPS65910_BUCK_DRIVER },
        { .prefix = "boost_", .driver = TPS65910_BOOST_DRIVER },
        { },
 };
 
+static const struct pmic_child_info tps65911_children_info[] = {
+       { .prefix = "ldo", .driver = TPS65911_LDO_DRIVER },
+       { .prefix = "vdd", .driver = TPS65911_VDD_DRIVER },
+       { },
+};
+
 static int pmic_tps65910_reg_count(struct udevice *dev)
 {
        return TPS65910_NUM_REGS;
@@ -47,10 +53,29 @@ static int pmic_tps65910_read(struct udevice *dev, uint reg, u8 *buffer,
        return ret;
 }

drivers/power/pmic/pmic_tps65910_dm.c static int pmic_tps65910_read(struct udevice *dev, uint reg, u8 *buffer, · line 64

Quoted 10 lines
drivers/power/pmic/pmic_tps65910_dm.c +9 -0
 
+static int pmic_tps65910_poweroff(struct udevice *dev)
+{
+       int ret;
+
+       ret = pmic_reg_read(dev, TPS65910_REG_DEVICE_CTRL);
+       if (ret < 0)
+               return ret;
+
+       ret |= DEVCTRL_PWR_OFF_MASK;

Please use a separate var for this. We use ret for return values, as you have above.

Quoted 18 lines
drivers/power/pmic/pmic_tps65910_dm.c +10 -0
+
+       pmic_reg_write(dev, TPS65910_REG_DEVICE_CTRL, ret);
+
+       ret |= DEVCTRL_DEV_OFF_MASK;
+       ret &= ~DEVCTRL_DEV_ON_MASK;
+
+       return pmic_reg_write(dev, TPS65910_REG_DEVICE_CTRL, ret);
+}
+
 static int pmic_tps65910_bind(struct udevice *dev)
 {
        ofnode regulators_node;
        int children;
+       int type = dev_get_driver_data(dev);
 
        regulators_node = dev_read_subnode(dev, "regulators");
        if (!ofnode_valid(regulators_node)) {

drivers/power/pmic/pmic_tps65910_dm.c static int pmic_tps65910_bind(struct udevice *dev) · line 86

Quoted 5 lines
drivers/power/pmic/pmic_tps65910_dm.c +1 -1
@@ -58,7 +83,19 @@ static int pmic_tps65910_bind(struct udevice *dev)
                return -EINVAL;
        }
 
-       children = pmic_bind_children(dev, regulators_node, pmic_children_info);
+       switch (type) {

Why not always binding them?

Quoted 106 lines
drivers/power/pmic/pmic_tps65910_dm.c +19 -1
+       case TPS65910:
+               children = pmic_bind_children(dev, regulators_node,
+                                             tps65910_children_info);
+               break;
+       case TPS65911:
+               children = pmic_bind_children(dev, regulators_node,
+                                             tps65911_children_info);
+               break;
+       default:
+               log_err("unknown PMIC type\n");
+       }
+
        if (!children)
                debug("%s has no children (regulators)\n", dev->name);
 
@@ -67,6 +104,10 @@ static int pmic_tps65910_bind(struct udevice *dev)
 
 static int pmic_tps65910_probe(struct udevice *dev)
 {
+       struct uc_pmic_priv *priv = dev_get_uclass_priv(dev);
+
+       priv->sys_pow_ctrl = dev_read_bool(dev, "ti,system-power-controller");
+
        /* use I2C control interface instead of I2C smartreflex interface to
         * access smartrefelex registers VDD1_OP_REG, VDD1_SR_REG, VDD2_OP_REG
         * and VDD2_SR_REG
@@ -76,13 +117,15 @@ static int pmic_tps65910_probe(struct udevice *dev)
 }
 
 static struct dm_pmic_ops pmic_tps65910_ops = {
+       .poweroff = pmic_tps65910_poweroff,
        .reg_count = pmic_tps65910_reg_count,
        .read = pmic_tps65910_read,
        .write = pmic_tps65910_write,
 };
 
 static const struct udevice_id pmic_tps65910_match[] = {
-       { .compatible = "ti,tps65910" },
+       { .compatible = "ti,tps65910", .data = TPS65910 },
+       { .compatible = "ti,tps65911", .data = TPS65911 },
        { /* sentinel */ }
 };
 
include/power/tps65910_pmic.h +41 -0
index 66214786d3..282863805a 100644
@@ -6,6 +6,9 @@
 #ifndef __TPS65910_PMIC_H_
 #define __TPS65910_PMIC_H_
 
+#define TPS65910                       1
+#define TPS65911                       2
+
 #define TPS65910_I2C_SEL_MASK          (0x1 << 4)
 #define TPS65910_VDD_SR_MASK           (0x1 << 7)
 #define TPS65910_GAIN_SEL_MASK         (0x3 << 6)
@@ -17,6 +20,11 @@
 #define TPS65910_SUPPLY_STATE_OFF      0x0
 #define TPS65910_SUPPLY_STATE_ON       0x1
 
+/* TPS65910 DEVICE_CTRL bits */
+#define DEVCTRL_PWR_OFF_MASK           BIT(7)
+#define DEVCTRL_DEV_ON_MASK            BIT(2)
+#define DEVCTRL_DEV_OFF_MASK           BIT(0)
+
 /* i2c registers */
 enum {
        TPS65910_REG_RTC_SEC                    = 0x00,
@@ -126,4 +134,48 @@ struct tps65910_regulator_pdata {
 #define TPS65910_BOOST_DRIVER  "tps65910_boost"
 #define TPS65910_LDO_DRIVER    "tps65910_ldo"
 
+/* tps65911 i2c registers */
+enum {
+       TPS65911_REG_VIO                        = 0x20,
+       TPS65911_REG_VDD1,
+       TPS65911_REG_VDD1_OP,
+       TPS65911_REG_VDD1_SR,
+       TPS65911_REG_VDD2,
+       TPS65911_REG_VDD2_OP,
+       TPS65911_REG_VDD2_SR,
+       TPS65911_REG_VDDCTRL,
+       TPS65911_REG_VDDCTRL_OP,
+       TPS65911_REG_VDDCTRL_SR,
+       TPS65911_REG_LDO1                       = 0x30,
+       TPS65911_REG_LDO2,
+       TPS65911_REG_LDO5,
+       TPS65911_REG_LDO8,
+       TPS65911_REG_LDO7,
+       TPS65911_REG_LDO6,
+       TPS65911_REG_LDO4,
+       TPS65911_REG_LDO3,
+};
+
+#define TPS65911_VDD_NUM               4
+#define TPS65911_LDO_NUM               8
+
+#define TPS65911_VDD_VOLT_MAX          1500000
+#define TPS65911_VDD_VOLT_MIN          600000
+#define TPS65911_VDD_VOLT_BASE         562500
+
+#define TPS65911_LDO_VOLT_MAX          3300000
+#define TPS65911_LDO_VOLT_BASE         800000
+
+#define TPS65911_LDO_SEL_MASK          (0x3f << 2)

include/power/tps65910_pmic.h struct tps65910_regulator_pdata { · line 179

Quoted 10 lines
include/power/tps65910_pmic.h +10 -0
+
+#define TPS65911_LDO124_VOLT_MAX_HEX   0x32
+#define TPS65911_LDO358_VOLT_MAX_HEX   0x19
+#define TPS65911_LDO358_VOLT_MIN_HEX   0x02
+
+#define TPS65911_LDO124_VOLT_STEP      50000
+#define TPS65911_LDO358_VOLT_STEP      100000
+
+#define TPS65911_VDD_DRIVER            "tps65911_vdd"
+#define TPS65911_LDO_DRIVER            "tps65911_ldo"

Drop the TPS65911 prefixes if you can...this is only included in one file i think.

Quoted 5 lines
include/power/tps65910_pmic.h +1 -1
+
 #endif /* __TPS65910_PMIC_H_ */
--

2.39.2

Regards,
Simon

#22 lore raw

Re: [PATCH v2 8/9] power: pmic: tps65910: add TPS65911 PMIC support

чт, 20 лип. 2023 р. о 22:43 Simon Glass <[email protected]> пише:

Quoted 85 lines · Svyatoslav Ryhel
Quoted 5 lines

Add support to bind the regulators/child nodes with the pmic. Also adds the pmic i2c based read/write functions to access pmic registers.

Quoted 8 lines
---
 doc/device-tree-bindings/pmic/tps65911.txt | 78 ++++++++++++++++++++++
 drivers/power/pmic/pmic_tps65910_dm.c      | 49 +++++++++++++-
 include/power/tps65910_pmic.h              | 52 +++++++++++++++
 3 files changed, 176 insertions(+), 3 deletions(-)
 create mode 100644 doc/device-tree-bindings/pmic/tps65911.txt

nits below

[..]

Quoted 28 lines
drivers/power/pmic/pmic_tps65910_dm.c +7 -1
index e03ddc98d7..770010d53d 100644
@@ -11,13 +11,19 @@
 #include <power/regulator.h>
 #include <power/tps65910_pmic.h>
 
-static const struct pmic_child_info pmic_children_info[] = {
+static const struct pmic_child_info tps65910_children_info[] = {
        { .prefix = "ldo_", .driver = TPS65910_LDO_DRIVER },
        { .prefix = "buck_", .driver = TPS65910_BUCK_DRIVER },
        { .prefix = "boost_", .driver = TPS65910_BOOST_DRIVER },
        { },
 };
 
+static const struct pmic_child_info tps65911_children_info[] = {
+       { .prefix = "ldo", .driver = TPS65911_LDO_DRIVER },
+       { .prefix = "vdd", .driver = TPS65911_VDD_DRIVER },
+       { },
+};
+
 static int pmic_tps65910_reg_count(struct udevice *dev)
 {
        return TPS65910_NUM_REGS;
@@ -47,10 +53,29 @@ static int pmic_tps65910_read(struct udevice *dev, uint reg, u8 *buffer,
        return ret;
 }

drivers/power/pmic/pmic_tps65910_dm.c static int pmic_tps65910_read(struct udevice *dev, uint reg, u8 *buffer, · line 64

Quoted 10 lines
drivers/power/pmic/pmic_tps65910_dm.c +9 -0
 
+static int pmic_tps65910_poweroff(struct udevice *dev)
+{
+       int ret;
+
+       ret = pmic_reg_read(dev, TPS65910_REG_DEVICE_CTRL);
+       if (ret < 0)
+               return ret;
+
+       ret |= DEVCTRL_PWR_OFF_MASK;

Please use a separate var for this. We use ret for return values, as you have above.

Quoted 21 lines
drivers/power/pmic/pmic_tps65910_dm.c +10 -0
+
+       pmic_reg_write(dev, TPS65910_REG_DEVICE_CTRL, ret);
+
+       ret |= DEVCTRL_DEV_OFF_MASK;
+       ret &= ~DEVCTRL_DEV_ON_MASK;
+
+       return pmic_reg_write(dev, TPS65910_REG_DEVICE_CTRL, ret);
+}
+
 static int pmic_tps65910_bind(struct udevice *dev)
 {
        ofnode regulators_node;
        int children;
+       int type = dev_get_driver_data(dev);
 
        regulators_node = dev_read_subnode(dev, "regulators");
        if (!ofnode_valid(regulators_node)) {
@@ -58,7 +83,19 @@ static int pmic_tps65910_bind(struct udevice *dev)
                return -EINVAL;
        }
 
Quoted 5 lines

drivers/power/pmic/pmic_tps65910_dm.c static int pmic_tps65910_bind(struct udevice *dev) · line 86

Quoted 2 lines
drivers/power/pmic/pmic_tps65910_dm.c +1 -1
-       children = pmic_bind_children(dev, regulators_node, pmic_children_info);
+       switch (type) {

Why not always binding them?

They may not be enabled, each pmic has its own regulator driver and they can be enabled separately. Not sure if binding without enabled driver is permitted so I decided to preemptively separate them to avoid any issues.

Quoted 111 lines
Quoted 111 lines
drivers/power/pmic/pmic_tps65910_dm.c +19 -1
+       case TPS65910:
+               children = pmic_bind_children(dev, regulators_node,
+                                             tps65910_children_info);
+               break;
+       case TPS65911:
+               children = pmic_bind_children(dev, regulators_node,
+                                             tps65911_children_info);
+               break;
+       default:
+               log_err("unknown PMIC type\n");
+       }
+
        if (!children)
                debug("%s has no children (regulators)\n", dev->name);
 
@@ -67,6 +104,10 @@ static int pmic_tps65910_bind(struct udevice *dev)
 
 static int pmic_tps65910_probe(struct udevice *dev)
 {
+       struct uc_pmic_priv *priv = dev_get_uclass_priv(dev);
+
+       priv->sys_pow_ctrl = dev_read_bool(dev, "ti,system-power-controller");
+
        /* use I2C control interface instead of I2C smartreflex interface to
         * access smartrefelex registers VDD1_OP_REG, VDD1_SR_REG, VDD2_OP_REG
         * and VDD2_SR_REG
@@ -76,13 +117,15 @@ static int pmic_tps65910_probe(struct udevice *dev)
 }
 
 static struct dm_pmic_ops pmic_tps65910_ops = {
+       .poweroff = pmic_tps65910_poweroff,
        .reg_count = pmic_tps65910_reg_count,
        .read = pmic_tps65910_read,
        .write = pmic_tps65910_write,
 };
 
 static const struct udevice_id pmic_tps65910_match[] = {
-       { .compatible = "ti,tps65910" },
+       { .compatible = "ti,tps65910", .data = TPS65910 },
+       { .compatible = "ti,tps65911", .data = TPS65911 },
        { /* sentinel */ }
 };
 
include/power/tps65910_pmic.h +46 -0
index 66214786d3..282863805a 100644
@@ -6,6 +6,9 @@
 #ifndef __TPS65910_PMIC_H_
 #define __TPS65910_PMIC_H_
 
+#define TPS65910                       1
+#define TPS65911                       2
+
 #define TPS65910_I2C_SEL_MASK          (0x1 << 4)
 #define TPS65910_VDD_SR_MASK           (0x1 << 7)
 #define TPS65910_GAIN_SEL_MASK         (0x3 << 6)
@@ -17,6 +20,11 @@
 #define TPS65910_SUPPLY_STATE_OFF      0x0
 #define TPS65910_SUPPLY_STATE_ON       0x1
 
+/* TPS65910 DEVICE_CTRL bits */
+#define DEVCTRL_PWR_OFF_MASK           BIT(7)
+#define DEVCTRL_DEV_ON_MASK            BIT(2)
+#define DEVCTRL_DEV_OFF_MASK           BIT(0)
+
 /* i2c registers */
 enum {
        TPS65910_REG_RTC_SEC                    = 0x00,
@@ -126,4 +134,48 @@ struct tps65910_regulator_pdata {
 #define TPS65910_BOOST_DRIVER  "tps65910_boost"
 #define TPS65910_LDO_DRIVER    "tps65910_ldo"
 
+/* tps65911 i2c registers */
+enum {
+       TPS65911_REG_VIO                        = 0x20,
+       TPS65911_REG_VDD1,
+       TPS65911_REG_VDD1_OP,
+       TPS65911_REG_VDD1_SR,
+       TPS65911_REG_VDD2,
+       TPS65911_REG_VDD2_OP,
+       TPS65911_REG_VDD2_SR,
+       TPS65911_REG_VDDCTRL,
+       TPS65911_REG_VDDCTRL_OP,
+       TPS65911_REG_VDDCTRL_SR,
+       TPS65911_REG_LDO1                       = 0x30,
+       TPS65911_REG_LDO2,
+       TPS65911_REG_LDO5,
+       TPS65911_REG_LDO8,
+       TPS65911_REG_LDO7,
+       TPS65911_REG_LDO6,
+       TPS65911_REG_LDO4,
+       TPS65911_REG_LDO3,
+};
+
+#define TPS65911_VDD_NUM               4
+#define TPS65911_LDO_NUM               8
+
+#define TPS65911_VDD_VOLT_MAX          1500000
+#define TPS65911_VDD_VOLT_MIN          600000
+#define TPS65911_VDD_VOLT_BASE         562500
+
+#define TPS65911_LDO_VOLT_MAX          3300000
+#define TPS65911_LDO_VOLT_BASE         800000
+
+#define TPS65911_LDO_SEL_MASK          (0x3f << 2)
+
+#define TPS65911_LDO124_VOLT_MAX_HEX   0x32
+#define TPS65911_LDO358_VOLT_MAX_HEX   0x19
+#define TPS65911_LDO358_VOLT_MIN_HEX   0x02
+
Quoted 9 lines

include/power/tps65910_pmic.h struct tps65910_regulator_pdata { · line 179

Quoted 5 lines
include/power/tps65910_pmic.h +5 -0
+#define TPS65911_LDO124_VOLT_STEP      50000
+#define TPS65911_LDO358_VOLT_STEP      100000
+
+#define TPS65911_VDD_DRIVER            "tps65911_vdd"
+#define TPS65911_LDO_DRIVER            "tps65911_ldo"

Drop the TPS65911 prefixes if you can...this is only included in one file i think.

TPS65911 prefixes are included in tps65910 pmic driver and tps65911 regulator driver respectively.

Quoted 8 lines
Quoted 5 lines
include/power/tps65910_pmic.h +1 -1
+
 #endif /* __TPS65910_PMIC_H_ */
--

2.39.2

Regards,
Simon

#23 lore raw

Re: [PATCH v2 8/9] power: pmic: tps65910: add TPS65911 PMIC support

In reply to Simon Glass

чт, 20 лип. 2023 р. о 22:43 Simon Glass <[email protected]> пише:

Quoted 51 lines · Svyatoslav Ryhel
Quoted 5 lines

Add support to bind the regulators/child nodes with the pmic. Also adds the pmic i2c based read/write functions to access pmic registers.

Quoted 8 lines
---
 doc/device-tree-bindings/pmic/tps65911.txt | 78 ++++++++++++++++++++++
 drivers/power/pmic/pmic_tps65910_dm.c      | 49 +++++++++++++-
 include/power/tps65910_pmic.h              | 52 +++++++++++++++
 3 files changed, 176 insertions(+), 3 deletions(-)
 create mode 100644 doc/device-tree-bindings/pmic/tps65911.txt

nits below

[..]

Quoted 29 lines
drivers/power/pmic/pmic_tps65910_dm.c +7 -1
index e03ddc98d7..770010d53d 100644
@@ -11,13 +11,19 @@
 #include <power/regulator.h>
 #include <power/tps65910_pmic.h>
 
-static const struct pmic_child_info pmic_children_info[] = {
+static const struct pmic_child_info tps65910_children_info[] = {
        { .prefix = "ldo_", .driver = TPS65910_LDO_DRIVER },
        { .prefix = "buck_", .driver = TPS65910_BUCK_DRIVER },
        { .prefix = "boost_", .driver = TPS65910_BOOST_DRIVER },
        { },
 };
 
+static const struct pmic_child_info tps65911_children_info[] = {
+       { .prefix = "ldo", .driver = TPS65911_LDO_DRIVER },
+       { .prefix = "vdd", .driver = TPS65911_VDD_DRIVER },
+       { },
+};
+
 static int pmic_tps65910_reg_count(struct udevice *dev)
 {
        return TPS65910_NUM_REGS;
@@ -47,10 +53,29 @@ static int pmic_tps65910_read(struct udevice *dev, uint reg, u8 *buffer,
        return ret;
 }
 
Quoted 13 lines

drivers/power/pmic/pmic_tps65910_dm.c static int pmic_tps65910_read(struct udevice *dev, uint reg, u8 *buffer, · line 64

Quoted 9 lines
drivers/power/pmic/pmic_tps65910_dm.c +9 -0
+static int pmic_tps65910_poweroff(struct udevice *dev)
+{
+       int ret;
+
+       ret = pmic_reg_read(dev, TPS65910_REG_DEVICE_CTRL);
+       if (ret < 0)
+               return ret;
+
+       ret |= DEVCTRL_PWR_OFF_MASK;

Please use a separate var for this. We use ret for return values, as you have above.

I have used ret here because pmic_reg_read returns either value of reg or -errno, I need to modify the value got from TPS65910_REG_DEVICE_CTRL and not to introduce new variable and perform unnecessary reassignments I continued with ret.

Quoted 154 lines
Quoted 18 lines
drivers/power/pmic/pmic_tps65910_dm.c +10 -0
+
+       pmic_reg_write(dev, TPS65910_REG_DEVICE_CTRL, ret);
+
+       ret |= DEVCTRL_DEV_OFF_MASK;
+       ret &= ~DEVCTRL_DEV_ON_MASK;
+
+       return pmic_reg_write(dev, TPS65910_REG_DEVICE_CTRL, ret);
+}
+
 static int pmic_tps65910_bind(struct udevice *dev)
 {
        ofnode regulators_node;
        int children;
+       int type = dev_get_driver_data(dev);
 
        regulators_node = dev_read_subnode(dev, "regulators");
        if (!ofnode_valid(regulators_node)) {

drivers/power/pmic/pmic_tps65910_dm.c static int pmic_tps65910_bind(struct udevice *dev) · line 86

Quoted 5 lines
drivers/power/pmic/pmic_tps65910_dm.c +1 -1
@@ -58,7 +83,19 @@ static int pmic_tps65910_bind(struct udevice *dev)
                return -EINVAL;
        }
 
-       children = pmic_bind_children(dev, regulators_node, pmic_children_info);
+       switch (type) {

Why not always binding them?

Quoted 106 lines
drivers/power/pmic/pmic_tps65910_dm.c +19 -1
+       case TPS65910:
+               children = pmic_bind_children(dev, regulators_node,
+                                             tps65910_children_info);
+               break;
+       case TPS65911:
+               children = pmic_bind_children(dev, regulators_node,
+                                             tps65911_children_info);
+               break;
+       default:
+               log_err("unknown PMIC type\n");
+       }
+
        if (!children)
                debug("%s has no children (regulators)\n", dev->name);
 
@@ -67,6 +104,10 @@ static int pmic_tps65910_bind(struct udevice *dev)
 
 static int pmic_tps65910_probe(struct udevice *dev)
 {
+       struct uc_pmic_priv *priv = dev_get_uclass_priv(dev);
+
+       priv->sys_pow_ctrl = dev_read_bool(dev, "ti,system-power-controller");
+
        /* use I2C control interface instead of I2C smartreflex interface to
         * access smartrefelex registers VDD1_OP_REG, VDD1_SR_REG, VDD2_OP_REG
         * and VDD2_SR_REG
@@ -76,13 +117,15 @@ static int pmic_tps65910_probe(struct udevice *dev)
 }
 
 static struct dm_pmic_ops pmic_tps65910_ops = {
+       .poweroff = pmic_tps65910_poweroff,
        .reg_count = pmic_tps65910_reg_count,
        .read = pmic_tps65910_read,
        .write = pmic_tps65910_write,
 };
 
 static const struct udevice_id pmic_tps65910_match[] = {
-       { .compatible = "ti,tps65910" },
+       { .compatible = "ti,tps65910", .data = TPS65910 },
+       { .compatible = "ti,tps65911", .data = TPS65911 },
        { /* sentinel */ }
 };
 
include/power/tps65910_pmic.h +41 -0
index 66214786d3..282863805a 100644
@@ -6,6 +6,9 @@
 #ifndef __TPS65910_PMIC_H_
 #define __TPS65910_PMIC_H_
 
+#define TPS65910                       1
+#define TPS65911                       2
+
 #define TPS65910_I2C_SEL_MASK          (0x1 << 4)
 #define TPS65910_VDD_SR_MASK           (0x1 << 7)
 #define TPS65910_GAIN_SEL_MASK         (0x3 << 6)
@@ -17,6 +20,11 @@
 #define TPS65910_SUPPLY_STATE_OFF      0x0
 #define TPS65910_SUPPLY_STATE_ON       0x1
 
+/* TPS65910 DEVICE_CTRL bits */
+#define DEVCTRL_PWR_OFF_MASK           BIT(7)
+#define DEVCTRL_DEV_ON_MASK            BIT(2)
+#define DEVCTRL_DEV_OFF_MASK           BIT(0)
+
 /* i2c registers */
 enum {
        TPS65910_REG_RTC_SEC                    = 0x00,
@@ -126,4 +134,48 @@ struct tps65910_regulator_pdata {
 #define TPS65910_BOOST_DRIVER  "tps65910_boost"
 #define TPS65910_LDO_DRIVER    "tps65910_ldo"
 
+/* tps65911 i2c registers */
+enum {
+       TPS65911_REG_VIO                        = 0x20,
+       TPS65911_REG_VDD1,
+       TPS65911_REG_VDD1_OP,
+       TPS65911_REG_VDD1_SR,
+       TPS65911_REG_VDD2,
+       TPS65911_REG_VDD2_OP,
+       TPS65911_REG_VDD2_SR,
+       TPS65911_REG_VDDCTRL,
+       TPS65911_REG_VDDCTRL_OP,
+       TPS65911_REG_VDDCTRL_SR,
+       TPS65911_REG_LDO1                       = 0x30,
+       TPS65911_REG_LDO2,
+       TPS65911_REG_LDO5,
+       TPS65911_REG_LDO8,
+       TPS65911_REG_LDO7,
+       TPS65911_REG_LDO6,
+       TPS65911_REG_LDO4,
+       TPS65911_REG_LDO3,
+};
+
+#define TPS65911_VDD_NUM               4
+#define TPS65911_LDO_NUM               8
+
+#define TPS65911_VDD_VOLT_MAX          1500000
+#define TPS65911_VDD_VOLT_MIN          600000
+#define TPS65911_VDD_VOLT_BASE         562500
+
+#define TPS65911_LDO_VOLT_MAX          3300000
+#define TPS65911_LDO_VOLT_BASE         800000
+
+#define TPS65911_LDO_SEL_MASK          (0x3f << 2)

include/power/tps65910_pmic.h struct tps65910_regulator_pdata { · line 179

Quoted 10 lines
include/power/tps65910_pmic.h +10 -0
+
+#define TPS65911_LDO124_VOLT_MAX_HEX   0x32
+#define TPS65911_LDO358_VOLT_MAX_HEX   0x19
+#define TPS65911_LDO358_VOLT_MIN_HEX   0x02
+
+#define TPS65911_LDO124_VOLT_STEP      50000
+#define TPS65911_LDO358_VOLT_STEP      100000
+
+#define TPS65911_VDD_DRIVER            "tps65911_vdd"
+#define TPS65911_LDO_DRIVER            "tps65911_ldo"

Drop the TPS65911 prefixes if you can...this is only included in one file i think.

Quoted 5 lines
include/power/tps65910_pmic.h +1 -1
+
 #endif /* __TPS65910_PMIC_H_ */
--

2.39.2

Regards,
Simon

#24 lore raw

PATCH v2 9/9 power: regulator: tps65911: add regulator support

In reply to Svyatoslav Ryhel

The driver provides regulator set/get voltage enable/disable functions for TI TPS5911 PMIC.

---
 drivers/power/regulator/Kconfig              |   8 +
 drivers/power/regulator/Makefile             |   1 +
 drivers/power/regulator/tps65911_regulator.c | 377 +++++++++++++++++++
 3 files changed, 386 insertions(+)
 create mode 100644 drivers/power/regulator/tps65911_regulator.c
drivers/power/regulator/Kconfig +8 -0
index f297e408cd..3398f0fbee 100644
@@ -345,6 +345,14 @@ config DM_REGULATOR_TPS65910
 	regulator types of the TPS65910 (BUCK, BOOST and LDO). It implements
 	the get/set api for value and enable.
 
+config DM_REGULATOR_TPS65911
+	bool "Enable driver for TPS65911 PMIC regulators"
+	depends on DM_PMIC_TPS65910
+	---help---
+	The TPS65911 PMIC provides 4 SMPSs and 8 LDOs. This driver supports all
+	regulator types of the TPS65911. It implements the get/set api for value
+	and enable.
+
 config DM_REGULATOR_TPS62360
 	bool "Enable driver for TPS6236x Power Regulator"
 	depends on DM_REGULATOR
drivers/power/regulator/Makefile +1 -0
index 3ef55dc534..c2ab1b7721 100644
@@ -32,6 +32,7 @@ obj-$(CONFIG_$(SPL_)DM_REGULATOR_LP873X) += lp873x_regulator.o
 obj-$(CONFIG_$(SPL_)DM_REGULATOR_LP87565) += lp87565_regulator.o
 obj-$(CONFIG_$(SPL_)DM_REGULATOR_STM32_VREFBUF) += stm32-vrefbuf.o
 obj-$(CONFIG_DM_REGULATOR_TPS65910) += tps65910_regulator.o
+obj-$(CONFIG_DM_REGULATOR_TPS65911) += tps65911_regulator.o
 obj-$(CONFIG_DM_REGULATOR_TPS62360) += tps62360_regulator.o
 obj-$(CONFIG_$(SPL_)DM_REGULATOR_TPS80031) += tps80031_regulator.o
 obj-$(CONFIG_$(SPL_)DM_REGULATOR_STPMIC1) += stpmic1.o
drivers/power/regulator/tps65911_regulator.c new file +377 -0

377 lines not on this page · raw message

Signature · 1 line
2.39.2