Skip to contentSkip to conversation

soc: qcom: several fixes for SAW handling

PATCH Applied Dmitry Baryshkov 5 participants 10 messages Oct 19 – Nov 8

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover soc: qcom: several fixes for SAW handling

The Qualcomm MSM8996 / MSM8998 / SDM660 platforms use SPM / SAW core to handle lower-power modes and to program core voltage regulators. Apply several small fixes to drivers for that core.

---
Dmitry Baryshkov (3):
soc: qcom: spm: fix the SDM660 silver L2 AVS control value
soc: qcom: spm: don't clobber the SAW control registers
regulator: qcom_spmi: don't take a sleeping lock in the SAW IPI

 drivers/regulator/Kconfig               |  1 +
 drivers/regulator/qcom_spmi-regulator.c | 35 +++++++++++++++++++++++++--------
 drivers/soc/qcom/spm.c                  | 10 ++++++----
 3 files changed, 34 insertions(+), 12 deletions(-)

---
base-commit: 2efb7a11f1aa4d2dc285fe2680cca22cb9f72f64
change-id: 20261019-fix-qcom-saw-e72f93e40991

Best regards,

Signature · 2 lines
With best wishes
Dmitry
#1 lore raw

PATCH 1/3 soc: qcom: spm: fix the SDM660 silver L2 AVS control value

The power cluster L2 SAW of SDM660 is programmed with an AVS control value that differs from the one the vendor kernel uses for this SAW (0x1010031), so the AVS hardware runs with the wrong configuration.

Use the vendor value.

Fixes 13e72c3e2261 ("soc: qcom: spm: Implement support for SAWv4.1, SDM630/660 L2 AVS")
---
 drivers/soc/qcom/spm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soc/qcom/spm.c +1 -1
index f75659fff287..d41c94d32b51 100644
@@ -100,7 +100,7 @@ static const struct spm_reg_data spm_reg_660_gold_l2  = {
 
 static const struct spm_reg_data spm_reg_660_silver_l2  = {
 	.reg_offset = spm_reg_offset_v4_1,
-	.avs_ctl = 0x101c031,
+	.avs_ctl = 0x1010031,
 	.avs_limit = 0x4580458,
 };
 
Signature · 1 line
2.47.3
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] soc: qcom: spm: fix the SDM660 silver L2 AVS control value

Quoted 9 lines · Dmitry Baryshkov

The power cluster L2 SAW of SDM660 is programmed with an AVS control value that differs from the one the vendor kernel uses for this SAW (0x1010031), so the AVS hardware runs with the wrong configuration.

Use the vendor value.

Fixes 13e72c3e2261 ("soc: qcom: spm: Implement support for SAWv4.1, SDM630/660 L2 AVS")

---

Konrad

#3 lore raw

PATCH 2/3 soc: qcom: spm: don't clobber the SAW control registers

In reply to Dmitry Baryshkov

The SAWv4.1 and SAWv2.3 register tables have no sequence entry, so probe copies the all-zero sequence buffer to offset 0 instead, wiping the SPM_CTL, SPM_DLY and SAW_CFG values the boot firmware programmed. On MSM8998 the firmware then still powers the gold cluster down once its last CPU goes offline, but never brings it back: PSCI CPU_ON leaves the first CPU pending and the SoC hangs or resets.

Only write the sequence when the SAW has a sequence entry, like the other registers.

Fixes 13e72c3e2261 ("soc: qcom: spm: Implement support for SAWv4.1, SDM630/660 L2 AVS")
---
 drivers/soc/qcom/spm.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/soc/qcom/spm.c +5 -3
index d41c94d32b51..6f2f14eb9022 100644
@@ -528,9 +528,11 @@ static int spm_dev_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, drv);
 
 	/* Write the SPM sequences first.. */
-	addr = drv->reg_base + drv->reg_data->reg_offset[SPM_REG_SEQ_ENTRY];
-	__iowrite32_copy(addr, drv->reg_data->seq,
-			ARRAY_SIZE(drv->reg_data->seq) / 4);
+	if (drv->reg_data->reg_offset[SPM_REG_SEQ_ENTRY]) {
+		addr = drv->reg_base + drv->reg_data->reg_offset[SPM_REG_SEQ_ENTRY];
+		__iowrite32_copy(addr, drv->reg_data->seq,
+				 ARRAY_SIZE(drv->reg_data->seq) / 4);
+	}
 
 	/*
 	 * ..and then the control registers.
Signature · 1 line
2.47.3
Reviewed-by on v1 2/3
#4 lore raw

Re: [PATCH 2/3] soc: qcom: spm: don't clobber the SAW control registers

Quoted 7 lines · Dmitry Baryshkov

The SAWv4.1 and SAWv2.3 register tables have no sequence entry, so probe copies the all-zero sequence buffer to offset 0 instead, wiping the SPM_CTL, SPM_DLY and SAW_CFG values the boot firmware programmed. On MSM8998 the firmware then still powers the gold cluster down once its last CPU goes offline, but never brings it back: PSCI CPU_ON leaves the first CPU pending and the SoC hangs or resets.

Quoted 6 lines

Only write the sequence when the SAW has a sequence entry, like the other registers.

Fixes 13e72c3e2261 ("soc: qcom: spm: Implement support for SAWv4.1, SDM630/660 L2 AVS")

---

Konrad

Quoted 23 lines
 drivers/soc/qcom/spm.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/soc/qcom/spm.c +5 -3
index d41c94d32b51..6f2f14eb9022 100644
@@ -528,9 +528,11 @@ static int spm_dev_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, drv);
 
 	/* Write the SPM sequences first.. */
-	addr = drv->reg_base + drv->reg_data->reg_offset[SPM_REG_SEQ_ENTRY];
-	__iowrite32_copy(addr, drv->reg_data->seq,
-			ARRAY_SIZE(drv->reg_data->seq) / 4);
+	if (drv->reg_data->reg_offset[SPM_REG_SEQ_ENTRY]) {
+		addr = drv->reg_base + drv->reg_data->reg_offset[SPM_REG_SEQ_ENTRY];
+		__iowrite32_copy(addr, drv->reg_data->seq,
+				 ARRAY_SIZE(drv->reg_data->seq) / 4);
+	}
 
 	/*
 	 * ..and then the control registers.
#5 lore raw

PATCH 3/3 regulator: qcom_spmi: don't take a sleeping lock in the SAW IPI

In reply to Dmitry Baryshkov

The SAW voltage change runs on CPU 0 from an IPI, but it reaches the SAW registers through the syscon regmap, which is protected by a spinlock_t. That is a sleeping lock on PREEMPT_RT, and lockdep complains as soon as VDD_APCC actually changes voltage:

  BUG: Invalid wait context
  ...
  regmap_lock_spinlock+0x18/0x30
  regmap_read+0x3c/0x78
  spmi_saw_set_vdd+0x50/0x1ac
  __flush_smp_call_function_queue+0x1ac/0x334

Map the SAW with a regmap of our own that uses a raw spinlock, and fail the probe when that cannot be done instead of carrying an error pointer around as the SAW regmap.

Fixes 0caecaa87202 ("regulator: qcom_spmi: Add support for SAW")
---
 drivers/regulator/Kconfig               |  1 +
 drivers/regulator/qcom_spmi-regulator.c | 35 +++++++++++++++++++++++++--------
 2 files changed, 28 insertions(+), 8 deletions(-)
drivers/regulator/Kconfig +1 -0
index be6b72daa76f..83a76b78e58c 100644
@@ -1210,6 +1210,7 @@ config REGULATOR_QCOM_SMD_RPM
 config REGULATOR_QCOM_SPMI
 	tristate "Qualcomm SPMI regulator driver"
 	depends on SPMI || COMPILE_TEST
+	select REGMAP_MMIO
 	help
 	  If you say yes to this option, support will be included for the
 	  regulators found in Qualcomm SPMI PMICs.
drivers/regulator/qcom_spmi-regulator.c +27 -8
index c1a41ce70b36..a04ddb1eac94 100644
@@ -12,13 +12,13 @@
 #include <linux/bitops.h>
 #include <linux/slab.h>
 #include <linux/of.h>
+#include <linux/of_address.h>
 #include <linux/of_device.h>
 #include <linux/platform_device.h>
 #include <linux/ktime.h>
 #include <linux/regulator/driver.h>
 #include <linux/regmap.h>
 #include <linux/list.h>
-#include <linux/mfd/syscon.h>
 #include <linux/io.h>
 
 /* Pin control enable input pins. */
@@ -1335,6 +1335,14 @@ static irqreturn_t spmi_regulator_vs_ocp_isr(int irq, void *data)
 
 static struct regmap *saw_regmap;
 
+static const struct regmap_config saw_regmap_config = {
+	.name = "saw",
+	.reg_bits = 32,
+	.val_bits = 32,
+	.reg_stride = 4,
+	.use_raw_spinlock = true,
+};
+
 static void spmi_saw_set_vdd(void *data)
 {
 	u32 vctl, data3, avs_ctl, pmic_sts;
@@ -2504,7 +2512,8 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev)
 	const char *name;
 	struct device *dev = &pdev->dev;
 	struct device_node *node = pdev->dev.of_node;
-	struct device_node *syscon, *reg_node;
+	struct device_node *saw, *reg_node;
+	void __iomem *saw_base;
 	struct property *reg_prop;
 	int ret, lenp;
 	struct list_head *vreg_list;
@@ -2523,12 +2532,22 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev)
 	if (!reg)
 		return -ENODEV;
 
-	syscon = of_parse_phandle(node, "qcom,saw-reg", 0);
-	if (syscon) {
-		saw_regmap = syscon_node_to_regmap(syscon);
-		of_node_put(syscon);
-		if (IS_ERR(saw_regmap))
-			dev_err(dev, "ERROR reading SAW regmap\n");
+	saw = of_parse_phandle(node, "qcom,saw-reg", 0);
+	if (saw) {
+		saw_base = devm_of_iomap(dev, saw, 0, NULL);
+		of_node_put(saw);
+		if (IS_ERR(saw_base))
+			return dev_err_probe(dev, PTR_ERR(saw_base),
+					     "failed to map the SAW\n");
+
+		saw_regmap = devm_regmap_init_mmio(dev, saw_base,
+						   &saw_regmap_config);
+		if (IS_ERR(saw_regmap)) {
+			ret = PTR_ERR(saw_regmap);
+			saw_regmap = NULL;
+			return dev_err_probe(dev, ret,
+					     "failed to set the SAW regmap up\n");
+		}
 	}
 
 	for (; reg->name; reg++) {
Signature · 1 line
2.47.3
Reviewed-by on v1 3/3
#6 lore raw

Re: [PATCH 3/3] regulator: qcom_spmi: don't take a sleeping lock in the SAW IPI

Quoted 4 lines · Dmitry Baryshkov

The SAW voltage change runs on CPU 0 from an IPI, but it reaches the SAW registers through the syscon regmap, which is protected by a spinlock_t. That is a sleeping lock on PREEMPT_RT, and lockdep complains as soon as VDD_APCC actually changes voltage:

The SAW handling barely belongs in that driver to be honest.. but separating it out would make a mess out of sharing the of_node

Konrad

#7 lore raw

Re: [PATCH 3/3] regulator: qcom_spmi: don't take a sleeping lock in the SAW IPI

In reply to Dmitry Baryshkov
Quoted 5 lines · Dmitry Baryshkov
drivers/regulator/qcom_spmi-regulator.c +0 -0
@@ -2523,12 +2532,22 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev)
 	if (!reg)
 		return -ENODEV;

drivers/regulator/qcom_spmi-regulator.c static int qcom_spmi_regulator_probe(struct platform_device *pdev) · line 2537

Quoted 10 lines
drivers/regulator/qcom_spmi-regulator.c +3 -6
 
-	syscon = of_parse_phandle(node, "qcom,saw-reg", 0);
-	if (syscon) {
-		saw_regmap = syscon_node_to_regmap(syscon);
-		of_node_put(syscon);
-		if (IS_ERR(saw_regmap))
-			dev_err(dev, "ERROR reading SAW regmap\n");
+	saw = of_parse_phandle(node, "qcom,saw-reg", 0);
+	if (saw) {
+		saw_base = devm_of_iomap(dev, saw, 0, NULL);

I was asking if the syscon could be made using a raw_spinlock_t if all users do simple reads/writes.

	https://lore.kernel.org/all/20260929-rbrue-suez-upstreaming-mtk-pinctrl-raw-regmap-v1-1-db92943f42cb@gmail.com/T/#u

If the qcom,saw-reg registers are not shared anywhere, then this should work, too.

drivers/regulator/qcom_spmi-regulator.c static int qcom_spmi_regulator_probe(struct platform_device *pdev) · line 2538

Quoted 1 line
drivers/regulator/qcom_spmi-regulator.c +1 -0
+		of_node_put(saw);

Sebastian

maintainer
#8 lore raw
In reply to Dmitry Baryshkov
Quoted 10 lines · Dmitry Baryshkov

The Qualcomm MSM8996 / MSM8998 / SDM660 platforms use SPM / SAW core to handle lower-power modes and to program core voltage regulators. Apply several small fixes to drivers for that core.

---
Dmitry Baryshkov (3):
soc: qcom: spm: fix the SDM660 silver L2 AVS control value
soc: qcom: spm: don't clobber the SAW control registers
regulator: qcom_spmi: don't take a sleeping lock in the SAW IPI

Are there any actual dependencies between the patches here? Please don't create cross tree serieses unless there are dependencies, it just makes it harder to figure out how things will get merged.

maintainer Applied
#9 lore raw

Re: (subset) [PATCH 0/3] soc: qcom: several fixes for SAW handling

In reply to Dmitry Baryshkov
Quoted 3 lines · Dmitry Baryshkov

The Qualcomm MSM8996 / MSM8998 / SDM660 platforms use SPM / SAW core to handle lower-power modes and to program core voltage regulators. Apply several small fixes to drivers for that core.

Applied, thanks!

[1/3] soc: qcom: spm: fix the SDM660 silver L2 AVS control value

      commit: 2fe8c4fa0ae7787e81d3737854ae4ae2c892bd95
[2/3] soc: qcom: spm: don't clobber the SAW control registers
      commit: 25e50bd0fcfb3a53fd505460d87bf67c21da176e

Best regards,

Signature · 1 line
Bjorn Andersson <[email protected]>