Skip to contentSkip to conversation

sysreset: qcom-pshold: Configure PMIC PON reset

PATCH Superseded Sumit Singh Dhami 2 participants 7 messages Sep 2 – Sep 3 Arm (32-bit)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover sysreset: qcom-pshold: Configure PMIC PON reset

The Qualcomm PS_HOLD sysreset driver currently deasserts MPM_PS_HOLD without configuring the reset type in the PMIC PON PBS block. This can result in an incorrect reset sequence on platforms that require the PON PBS reset type to be configured before PS_HOLD deassertion.

Add support for configuring warm and hard reset types through the PMIC PON PBS interface before deasserting MPM_PS_HOLD.

Sumit Singh Dhami (3):
sysreset: qcom-pshold: Configure PON reset type
arm: dts: qcom: Configure Lemans PS_HOLD reset
configs: disable CMD_POWEROFF in snagboot config

 arch/arm/dts/lemans-evk-u-boot.dtsi     |  12 +++
 configs/qcom-snagboot.config            |   1 +
 drivers/sysreset/sysreset_qcom-pshold.c | 137 ++++++++++++++++++++++--
 3 files changed, 143 insertions(+), 7 deletions(-)
Signature · 1 line
2.55.0
#1 lore raw

PATCH 1/3 sysreset: qcom-pshold: Configure PON reset type

Configure the PMIC PON PBS reset type before deasserting MPM PS_HOLD.

The PON PBS reset sequence requires PS_HOLD_RESET_CTL2 to be cleared, the requested reset type to be written to PS_HOLD_SW_CTL, and PS_HOLD_RESET_CTL2 to be enabled again before deasserting MPM_PS_HOLD.

---
 drivers/sysreset/sysreset_qcom-pshold.c | 137 ++++++++++++++++++++++--
 1 file changed, 130 insertions(+), 7 deletions(-)
drivers/sysreset/sysreset_qcom-pshold.c +130 -7
index 45290478536..de7c0b388aa 100644
@@ -13,15 +13,94 @@
 #include <sysreset.h>
 #include <asm/io.h>
 #include <linux/delay.h>
+#include <power/pmic.h>
+
+#define PON_PBS_RESET_TYPE_WARM		0x01
+#define PON_PBS_RESET_TYPE_HARD		0x07
+
+/*
+ * Reset State of PON_PBS_PS_HOLD_RESET_CTL2 register
+ */
+#define PON_PBS_PS_HOLD_RESET_CTL2_S2_RESET_EN_BMSK	0x80
 
 struct qcom_pshold_priv {
 	phys_addr_t base;
+
+	struct udevice *pmic;
+	u32 pbs_base;
+	bool have_pon;
+
+	u32 pon_pbs_pshold_sw_ctl_offset;
+	u32 pon_pbs_pshold_reset_ctl2_offset;
 };
 
+static int qcom_pshold_pon_cfg(struct qcom_pshold_priv *priv, u8 reset_type)
+{
+	int ret;
+
+	ret = pmic_reg_write(priv->pmic,
+			     priv->pbs_base +
+			     priv->pon_pbs_pshold_reset_ctl2_offset,
+			     0x00);
+	if (ret)
+		return ret;
+
+	udelay(100);
+
+	ret = pmic_reg_write(priv->pmic,
+			     priv->pbs_base + priv->pon_pbs_pshold_sw_ctl_offset,
+			     reset_type);
+	if (ret)
+		return ret;
+
+	udelay(300);
+
+	ret = pmic_reg_write(priv->pmic,
+			     priv->pbs_base + priv->pon_pbs_pshold_reset_ctl2_offset,
+			     PON_PBS_PS_HOLD_RESET_CTL2_S2_RESET_EN_BMSK);
+	if (ret)
+		return ret;
+
+	udelay(100);
+
+	return 0;
+}
+
+static int qcom_pshold_read_pon_offset(struct udevice *dev, struct qcom_pshold_priv *priv)
+{
+	int ret;
+
+	ret = dev_read_u32(dev,
+			   "qcom,pbs-pshold-sw-ctl",
+			   &priv->pon_pbs_pshold_sw_ctl_offset);
+	if (ret)
+		return ret;
+
+	ret = dev_read_u32(dev,
+			   "qcom,pbs-pshold-reset-ctl2",
+			   &priv->pon_pbs_pshold_reset_ctl2_offset);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
 static int qcom_pshold_request(struct udevice *dev, enum sysreset_t type)
 {
 	struct qcom_pshold_priv *priv = dev_get_priv(dev);
 
+	if (priv->have_pon) {
+		u8 reset_type = (type == SYSRESET_WARM) ?
+				 PON_PBS_RESET_TYPE_WARM :
+				 PON_PBS_RESET_TYPE_HARD;
+		int ret;
+
+		ret = qcom_pshold_pon_cfg(priv, reset_type);
+		if (ret)
+			debug("%s: failed to configure PON reset type: %d\n",
+			      dev->name, ret);
+	}
+
 	writel(0, priv->base);
 	mdelay(10000);
 
@@ -35,9 +114,53 @@ static struct sysreset_ops qcom_pshold_ops = {
 static int qcom_pshold_probe(struct udevice *dev)
 {
 	struct qcom_pshold_priv *priv = dev_get_priv(dev);
+	struct ofnode_phandle_args args;
+	ofnode pmic_node;
+	int index, ret;
+
+	priv->have_pon = false;
 
 	priv->base = dev_read_addr(dev);
-	return priv->base == FDT_ADDR_T_NONE ? -EINVAL : 0;
+	if (priv->base == FDT_ADDR_T_NONE)
+		return -EINVAL;
+
+	ret = dev_read_phandle_with_args(dev, "qcom,pon", NULL, 0, 0, &args);
+	if (ret)
+		return 0;
+
+	index = ofnode_stringlist_search(args.node, "reg-names", "pbs");
+	if (index < 0) {
+		debug("%s: referenced PON node has no 'pbs' reg\n", dev->name);
+		return 0;
+	}
+
+	ret = ofnode_read_u32_index(args.node, "reg", index, &priv->pbs_base);
+	if (ret) {
+		debug("%s: failed to read PON 'pbs' reg: %d\n", dev->name, ret);
+		return 0;
+	}
+
+	ret = qcom_pshold_read_pon_offset(dev, priv);
+	if (ret) {
+		debug("%s: failed to read PON offset configs: %d\n", dev->name, ret);
+		return 0;
+	}
+
+	pmic_node = ofnode_get_parent(args.node);
+	if (!ofnode_valid(pmic_node)) {
+		debug("%s: failed to get PON's parent PMIC node\n", dev->name);
+		return 0;
+	}
+
+	ret = uclass_get_device_by_ofnode(UCLASS_PMIC, pmic_node, &priv->pmic);
+	if (ret) {
+		debug("%s: failed to get PMIC device: %d\n", dev->name, ret);
+		return 0;
+	}
+
+	priv->have_pon = true;
+
+	return 0;
 }
 
 static const struct udevice_id qcom_pshold_ids[] = {
@@ -46,10 +169,10 @@ static const struct udevice_id qcom_pshold_ids[] = {
 };
 
 U_BOOT_DRIVER(qcom_pshold) = {
-	.name 		= "qcom_pshold",
-	.id 		= UCLASS_SYSRESET,
-	.of_match 	= qcom_pshold_ids,
-	.probe 		= qcom_pshold_probe,
-	.priv_auto	= sizeof(struct qcom_pshold_priv),
-	.ops 		= &qcom_pshold_ops,
+	.name       = "qcom_pshold",
+	.id         = UCLASS_SYSRESET,
+	.of_match   = qcom_pshold_ids,
+	.probe      = qcom_pshold_probe,
+	.priv_auto  = sizeof(struct qcom_pshold_priv),
+	.ops        = &qcom_pshold_ops,
 };
Signature · 1 line
2.55.0
#2 lore raw

Re: [PATCH v1 1/3] sysreset: qcom-pshold: Configure PON reset type

Hi Sumit,

Quoted 5 lines · Sumit Singh Dhami

Configure the PMIC PON PBS reset type before deasserting MPM PS_HOLD.

The PON PBS reset sequence requires PS_HOLD_RESET_CTL2 to be cleared, the requested reset type to be written to PS_HOLD_SW_CTL, and PS_HOLD_RESET_CTL2 to be enabled again before deasserting MPM_PS_HOLD.

why? what does this fix? what do these registers encode? what platforms need this? Please include this context in v2 and in your cover letter. I shouldn't feel the need to look at PMIC register maps to understand what this is for.

Quoted 70 lines
---
 drivers/sysreset/sysreset_qcom-pshold.c | 137 ++++++++++++++++++++++--
 1 file changed, 130 insertions(+), 7 deletions(-)
drivers/sysreset/sysreset_qcom-pshold.c +51 -0
index 45290478536..de7c0b388aa 100644
@@ -13,15 +13,94 @@
 #include <sysreset.h>
 #include <asm/io.h>
 #include <linux/delay.h>
+#include <power/pmic.h>
+
+#define PON_PBS_RESET_TYPE_WARM		0x01
+#define PON_PBS_RESET_TYPE_HARD		0x07
+
+/*
+ * Reset State of PON_PBS_PS_HOLD_RESET_CTL2 register
+ */
+#define PON_PBS_PS_HOLD_RESET_CTL2_S2_RESET_EN_BMSK	0x80
 
 struct qcom_pshold_priv {
 	phys_addr_t base;
+
+	struct udevice *pmic;
+	u32 pbs_base;
+	bool have_pon;
+
+	u32 pon_pbs_pshold_sw_ctl_offset;
+	u32 pon_pbs_pshold_reset_ctl2_offset;
 };
 
+static int qcom_pshold_pon_cfg(struct qcom_pshold_priv *priv, u8 reset_type)
+{
+	int ret;
+
+	ret = pmic_reg_write(priv->pmic,
+			     priv->pbs_base +
+			     priv->pon_pbs_pshold_reset_ctl2_offset,
+			     0x00);
+	if (ret)
+		return ret;
+
+	udelay(100);
+
+	ret = pmic_reg_write(priv->pmic,
+			     priv->pbs_base + priv->pon_pbs_pshold_sw_ctl_offset,
+			     reset_type);
+	if (ret)
+		return ret;
+
+	udelay(300);
+
+	ret = pmic_reg_write(priv->pmic,
+			     priv->pbs_base + priv->pon_pbs_pshold_reset_ctl2_offset,
+			     PON_PBS_PS_HOLD_RESET_CTL2_S2_RESET_EN_BMSK);
+	if (ret)
+		return ret;
+
+	udelay(100);
+
+	return 0;
+}
+
+static int qcom_pshold_read_pon_offset(struct udevice *dev, struct qcom_pshold_priv *priv)
+{
+	int ret;

drivers/sysreset/sysreset_qcom-pshold.c line 81

Quoted 10 lines
drivers/sysreset/sysreset_qcom-pshold.c +10 -0
+
+	ret = dev_read_u32(dev,
+			   "qcom,pbs-pshold-sw-ctl",
+			   &priv->pon_pbs_pshold_sw_ctl_offset);
+	if (ret)
+		return ret;
+
+	ret = dev_read_u32(dev,
+			   "qcom,pbs-pshold-reset-ctl2",
+			   &priv->pon_pbs_pshold_reset_ctl2_offset);

Where are the bindings for this?

why are this offsets read from DT anyway? Do they really vary so much? Can't we just match the pmics ID registers and pick the correct offset per-pmic?

Quoted 86 lines
drivers/sysreset/sysreset_qcom-pshold.c +63 -3
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
 static int qcom_pshold_request(struct udevice *dev, enum sysreset_t type)
 {
 	struct qcom_pshold_priv *priv = dev_get_priv(dev);
 
+	if (priv->have_pon) {
+		u8 reset_type = (type == SYSRESET_WARM) ?
+				 PON_PBS_RESET_TYPE_WARM :
+				 PON_PBS_RESET_TYPE_HARD;
+		int ret;
+
+		ret = qcom_pshold_pon_cfg(priv, reset_type);
+		if (ret)
+			debug("%s: failed to configure PON reset type: %d\n",
+			      dev->name, ret);
+	}
+
 	writel(0, priv->base);
 	mdelay(10000);
 
@@ -35,9 +114,53 @@ static struct sysreset_ops qcom_pshold_ops = {
 static int qcom_pshold_probe(struct udevice *dev)
 {
 	struct qcom_pshold_priv *priv = dev_get_priv(dev);
+	struct ofnode_phandle_args args;
+	ofnode pmic_node;
+	int index, ret;
+
+	priv->have_pon = false;
 
 	priv->base = dev_read_addr(dev);
-	return priv->base == FDT_ADDR_T_NONE ? -EINVAL : 0;
+	if (priv->base == FDT_ADDR_T_NONE)
+		return -EINVAL;
+
+	ret = dev_read_phandle_with_args(dev, "qcom,pon", NULL, 0, 0, &args);
+	if (ret)
+		return 0;
+
+	index = ofnode_stringlist_search(args.node, "reg-names", "pbs");
+	if (index < 0) {
+		debug("%s: referenced PON node has no 'pbs' reg\n", dev->name);
+		return 0;
+	}
+
+	ret = ofnode_read_u32_index(args.node, "reg", index, &priv->pbs_base);
+	if (ret) {
+		debug("%s: failed to read PON 'pbs' reg: %d\n", dev->name, ret);
+		return 0;
+	}
+
+	ret = qcom_pshold_read_pon_offset(dev, priv);
+	if (ret) {
+		debug("%s: failed to read PON offset configs: %d\n", dev->name, ret);
+		return 0;
+	}
+
+	pmic_node = ofnode_get_parent(args.node);
+	if (!ofnode_valid(pmic_node)) {
+		debug("%s: failed to get PON's parent PMIC node\n", dev->name);
+		return 0;
+	}
+
+	ret = uclass_get_device_by_ofnode(UCLASS_PMIC, pmic_node, &priv->pmic);
+	if (ret) {
+		debug("%s: failed to get PMIC device: %d\n", dev->name, ret);
+		return 0;
+	}
+
+	priv->have_pon = true;
+
+	return 0;
 }
 
 static const struct udevice_id qcom_pshold_ids[] = {
@@ -46,10 +169,10 @@ static const struct udevice_id qcom_pshold_ids[] = {
 };
 
 U_BOOT_DRIVER(qcom_pshold) = {
-	.name 		= "qcom_pshold",
-	.id 		= UCLASS_SYSRESET,

drivers/sysreset/sysreset_qcom-pshold.c static const struct udevice_id qcom_pshold_ids[] = { · line 177

Quoted 10 lines
drivers/sysreset/sysreset_qcom-pshold.c +6 -4
-	.of_match 	= qcom_pshold_ids,
-	.probe 		= qcom_pshold_probe,
-	.priv_auto	= sizeof(struct qcom_pshold_priv),
-	.ops 		= &qcom_pshold_ops,
+	.name       = "qcom_pshold",
+	.id         = UCLASS_SYSRESET,
+	.of_match   = qcom_pshold_ids,
+	.probe      = qcom_pshold_probe,
+	.priv_auto  = sizeof(struct qcom_pshold_priv),
+	.ops        = &qcom_pshold_ops,

Please don't spuriously reformat blocks like this.

Quoted 1 line
drivers/sysreset/sysreset_qcom-pshold.c +0 -0
 };
Signature · 1 line
// Casey (she/her)
#3 lore raw

PATCH 2/3 arm: dts: qcom: Configure Lemans PS_HOLD reset

In reply to Sumit Singh Dhami

Add the Qualcomm PS_HOLD sysreset node for the Lemans EVK.

Link the reset driver to the PMIC PON peripheral and provide the PBS PS_HOLD control register offsets required to configure warm and hard resets before deasserting MPM_PS_HOLD.

---
 arch/arm/dts/lemans-evk-u-boot.dtsi | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/arm/dts/lemans-evk-u-boot.dtsi +12 -0
index fd4eaa2fec8..0e676bf4b55 100644
@@ -64,3 +64,15 @@
 		mode-edl = <0x80000000 0x00000001>;
 	};
 };
+
+&soc {
+	restart@c264000 {
+		compatible = "qcom,pshold";
+		reg = <0x0 0x0c264000 0x0 0x4>;
+		qcom,pon = <&pmm8654au_0_pon>;
+		qcom,pbs-pshold-sw-ctl = <0x52>;
+		qcom,pbs-pshold-reset-ctl2 = <0x53>;
+
+		bootph-all;
+	};
+};
Signature · 1 line
2.55.0
#4 lore raw

Re: [PATCH v1 2/3] arm: dts: qcom: Configure Lemans PS_HOLD reset

Quoted 5 lines · Sumit Singh Dhami

Add the Qualcomm PS_HOLD sysreset node for the Lemans EVK.

Link the reset driver to the PMIC PON peripheral and provide the PBS PS_HOLD control register offsets required to configure warm and hard resets before deasserting MPM_PS_HOLD.

please link to the upstream patch adding this node and the new DT bindings, I'd like to see them at least approved by the DT maintainer before we start adding these bindings to U-Boot.

Quoted 26 lines
---
 arch/arm/dts/lemans-evk-u-boot.dtsi | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/arm/dts/lemans-evk-u-boot.dtsi +12 -0
index fd4eaa2fec8..0e676bf4b55 100644
@@ -64,3 +64,15 @@
 		mode-edl = <0x80000000 0x00000001>;
 	};
 };
+
+&soc {
+	restart@c264000 {
+		compatible = "qcom,pshold";
+		reg = <0x0 0x0c264000 0x0 0x4>;
+		qcom,pon = <&pmm8654au_0_pon>;
+		qcom,pbs-pshold-sw-ctl = <0x52>;
+		qcom,pbs-pshold-reset-ctl2 = <0x53>;
+
+		bootph-all;
+	};
+};
Signature · 1 line
// Casey (she/her)
#5 lore raw

PATCH 3/3 configs: disable CMD_POWEROFF in snagboot config

In reply to Sumit Singh Dhami

CMD_POWEROFF requires do_poweroff(), normally provided by psci.c, but PSCI_RESET is disabled in snagboot mode, causing a link failure. Poweroff isn't needed for snagboot recovery, so disable it.

---
 configs/qcom-snagboot.config | 1 +
 1 file changed, 1 insertion(+)
configs/qcom-snagboot.config +1 -0
index d19ad453029..579bcc7732d 100644
@@ -8,6 +8,7 @@ CONFIG_QCOM_SNAGBOOT_MODE=y
 # CONFIG_SAVE_PREV_BL_INITRAMFS_START_ADDR is not set
 # CONFIG_IOMMU is not set
 # CONFIG_REBOOT_MODE_ENV_UPDATE is not set
+# CONFIG_CMD_POWEROFF is not set
 
 # Use default environment instead of loading from storage
 # This ensures snagboot mode works even with corrupted environment
Signature · 1 line
2.55.0
#6 lore raw

Re: [PATCH v1 3/3] configs: disable CMD_POWEROFF in snagboot config

Quoted 3 lines · Sumit Singh Dhami

CMD_POWEROFF requires do_poweroff(), normally provided by psci.c, but PSCI_RESET is disabled in snagboot mode, causing a link failure. Poweroff isn't needed for snagboot recovery, so disable it.

do_poweroff is also provided by sysreset-uclass?

Quoted 18 lines
---
 configs/qcom-snagboot.config | 1 +
 1 file changed, 1 insertion(+)
configs/qcom-snagboot.config +1 -0
index d19ad453029..579bcc7732d 100644
@@ -8,6 +8,7 @@ CONFIG_QCOM_SNAGBOOT_MODE=y
 # CONFIG_SAVE_PREV_BL_INITRAMFS_START_ADDR is not set
 # CONFIG_IOMMU is not set
 # CONFIG_REBOOT_MODE_ENV_UPDATE is not set
+# CONFIG_CMD_POWEROFF is not set
 
 # Use default environment instead of loading from storage
 # This ensures snagboot mode works even with corrupted environment
Signature · 1 line
// Casey (she/her)