Skip to contentSkip to conversation

mfd: sprd: Add wakeup capability for PMIC irq

PATCH In review Baolin Wang 3 participants 3 messages May 7, 2020 – May 26, 2020

Subsystems (2)
lore
Share & tools
lore

Baolin Wang

author maintainer
#0 lore raw

PATCH 1/1 mfd: sprd: Add wakeup capability for PMIC irq

When changing to use suspend-to-idle to save power, the PMIC irq can not wakeup the system due to lack of wakeup capability, which will cause the sub-irqs (such as power key) of the PMIC can not wake up the system. Thus we can add the wakeup capability for PMIC irq to solve this issue, as well as removing the IRQF_NO_SUSPEND flag to allow PMIC irq to be a wakeup source.

---
 drivers/mfd/sprd-sc27xx-spi.c | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)
drivers/mfd/sprd-sc27xx-spi.c +29 -1
index ebdf2f1..3064a60 100644
@@ -256,7 +256,7 @@ static int sprd_pmic_probe(struct spi_device *spi)
 	}
 
 	ret = devm_regmap_add_irq_chip(&spi->dev, ddata->regmap, ddata->irq,
-				       IRQF_ONESHOT | IRQF_NO_SUSPEND, 0,
+				       IRQF_ONESHOT, 0,
 				       &ddata->irq_chip, &ddata->irq_data);
 	if (ret) {
 		dev_err(&spi->dev, "Failed to add PMIC irq chip %d\n", ret);
@@ -272,9 +272,36 @@ static int sprd_pmic_probe(struct spi_device *spi)
 		return ret;
 	}
 
+	device_init_wakeup(&spi->dev, 1);
 	return 0;
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int sprd_pmic_suspend(struct device *dev)
+{
+	struct spi_device *spi = to_spi_device(dev);
+	struct sprd_pmic *ddata = spi_get_drvdata(spi);
+
+	if (device_may_wakeup(dev))
+		enable_irq_wake(ddata->irq);
+
+	return 0;
+}
+
+static int sprd_pmic_resume(struct device *dev)
+{
+	struct spi_device *spi = to_spi_device(dev);
+	struct sprd_pmic *ddata = spi_get_drvdata(spi);
+
+	if (device_may_wakeup(dev))
+		disable_irq_wake(ddata->irq);
+
+	return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(sprd_pmic_pm_ops, sprd_pmic_suspend, sprd_pmic_resume);
+
 static const struct of_device_id sprd_pmic_match[] = {
 	{ .compatible = "sprd,sc2731", .data = &sc2731_data },
 	{},
@@ -286,6 +313,7 @@ static int sprd_pmic_probe(struct spi_device *spi)
 		.name = "sc27xx-pmic",
 		.bus = &spi_bus_type,
 		.of_match_table = sprd_pmic_match,
+		.pm = &sprd_pmic_pm_ops,
 	},
 	.probe = sprd_pmic_probe,
 };
Signature · 1 line
1.9.1
reviewer Tested-by on v1 1/1
#1 lore raw
Quoted 10 lines · Baolin Wang

When changing to use suspend-to-idle to save power, the PMIC irq can not wakeup the system due to lack of wakeup capability, which will cause the sub-irqs (such as power key) of the PMIC can not wake up the system. Thus we can add the wakeup capability for PMIC irq to solve this issue, as well as removing the IRQF_NO_SUSPEND flag to allow PMIC irq to be a wakeup source.

Thanks for fixing this issue, with this patch, power key can wakeup s2idle correctly on my sprd board.

Quoted 65 lines
---
 drivers/mfd/sprd-sc27xx-spi.c | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)
drivers/mfd/sprd-sc27xx-spi.c +29 -2
index ebdf2f1..3064a60 100644
@@ -256,7 +256,7 @@ static int sprd_pmic_probe(struct spi_device *spi)
        }
 
        ret = devm_regmap_add_irq_chip(&spi->dev, ddata->regmap, ddata->irq,
-                                      IRQF_ONESHOT | IRQF_NO_SUSPEND, 0,
+                                      IRQF_ONESHOT, 0,
                                       &ddata->irq_chip, &ddata->irq_data);
        if (ret) {
                dev_err(&spi->dev, "Failed to add PMIC irq chip %d\n", ret);
@@ -272,9 +272,36 @@ static int sprd_pmic_probe(struct spi_device *spi)
                return ret;
        }
 
+       device_init_wakeup(&spi->dev, 1);
        return 0;
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int sprd_pmic_suspend(struct device *dev)
+{
+       struct spi_device *spi = to_spi_device(dev);
+       struct sprd_pmic *ddata = spi_get_drvdata(spi);
+
+       if (device_may_wakeup(dev))
+               enable_irq_wake(ddata->irq);
+
+       return 0;
+}
+
+static int sprd_pmic_resume(struct device *dev)
+{
+       struct spi_device *spi = to_spi_device(dev);
+       struct sprd_pmic *ddata = spi_get_drvdata(spi);
+
+       if (device_may_wakeup(dev))
+               disable_irq_wake(ddata->irq);
+
+       return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(sprd_pmic_pm_ops, sprd_pmic_suspend, sprd_pmic_resume);
+
 static const struct of_device_id sprd_pmic_match[] = {
        { .compatible = "sprd,sc2731", .data = &sc2731_data },
        {},
@@ -286,6 +313,7 @@ static int sprd_pmic_probe(struct spi_device *spi)
                .name = "sc27xx-pmic",
                .bus = &spi_bus_type,
                .of_match_table = sprd_pmic_match,
+               .pm = &sprd_pmic_pm_ops,
        },
        .probe = sprd_pmic_probe,
 };
--

1.9.1

#2 lore raw
In reply to Baolin Wang
Quoted 27 lines · Baolin Wang

When changing to use suspend-to-idle to save power, the PMIC irq can not wakeup the system due to lack of wakeup capability, which will cause the sub-irqs (such as power key) of the PMIC can not wake up the system. Thus we can add the wakeup capability for PMIC irq to solve this issue, as well as removing the IRQF_NO_SUSPEND flag to allow PMIC irq to be a wakeup source.

---
 drivers/mfd/sprd-sc27xx-spi.c | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)
drivers/mfd/sprd-sc27xx-spi.c +1 -1
index ebdf2f1..3064a60 100644
@@ -256,7 +256,7 @@ static int sprd_pmic_probe(struct spi_device *spi)
 	}
 
 	ret = devm_regmap_add_irq_chip(&spi->dev, ddata->regmap, ddata->irq,
-				       IRQF_ONESHOT | IRQF_NO_SUSPEND, 0,
+				       IRQF_ONESHOT, 0,
 				       &ddata->irq_chip, &ddata->irq_data);
 	if (ret) {
 		dev_err(&spi->dev, "Failed to add PMIC irq chip %d\n", ret);

drivers/mfd/sprd-sc27xx-spi.c static int sprd_pmic_probe(struct spi_device *spi) · line 275

Quoted 4 lines
drivers/mfd/sprd-sc27xx-spi.c +1 -0
@@ -272,9 +272,36 @@ static int sprd_pmic_probe(struct spi_device *spi)
 		return ret;
 	}
 
+	device_init_wakeup(&spi->dev, 1);

This is a bool. Please use 'true'.

drivers/mfd/sprd-sc27xx-spi.c static int sprd_pmic_probe(struct spi_device *spi) · line 283

Quoted 8 lines
drivers/mfd/sprd-sc27xx-spi.c +5 -0
 	return 0;
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int sprd_pmic_suspend(struct device *dev)
+{
+	struct spi_device *spi = to_spi_device(dev);
+	struct sprd_pmic *ddata = spi_get_drvdata(spi);

Why don't you just use:

dev_get_drvdata(dev)

... and skip the superfluous step?

drivers/mfd/sprd-sc27xx-spi.c static int sprd_pmic_probe(struct spi_device *spi) · line 294

Quoted 10 lines
drivers/mfd/sprd-sc27xx-spi.c +10 -0
+	if (device_may_wakeup(dev))
+		enable_irq_wake(ddata->irq);
+
+	return 0;
+}
+
+static int sprd_pmic_resume(struct device *dev)
+{
+	struct spi_device *spi = to_spi_device(dev);
+	struct sprd_pmic *ddata = spi_get_drvdata(spi);

As above.

Quoted 20 lines
drivers/mfd/sprd-sc27xx-spi.c +10 -0
+	if (device_may_wakeup(dev))
+		disable_irq_wake(ddata->irq);
+
+	return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(sprd_pmic_pm_ops, sprd_pmic_suspend, sprd_pmic_resume);
+
 static const struct of_device_id sprd_pmic_match[] = {
 	{ .compatible = "sprd,sc2731", .data = &sc2731_data },
 	{},
@@ -286,6 +313,7 @@ static int sprd_pmic_probe(struct spi_device *spi)
 		.name = "sc27xx-pmic",
 		.bus = &spi_bus_type,
 		.of_match_table = sprd_pmic_match,
+		.pm = &sprd_pmic_pm_ops,
 	},
 	.probe = sprd_pmic_probe,
 };
Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog