linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH/RFC 0/3] renesas: irqchip: Use wakeup_path i.s.o. explicit clock handling
@ 2017-11-09 13:48 Geert Uytterhoeven
  2017-11-09 13:48 ` [PATCH/RFC 1/3] irqchip/renesas-intc-irqpin: " Geert Uytterhoeven
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2017-11-09 13:48 UTC (permalink / raw)
  To: Rafael J . Wysocki, Ulf Hansson, Kevin Hilman
  Cc: Thomas Gleixner, Jason Cooper, Marc Zyngier, Linus Walleij,
	linux-pm, linux-gpio, linux-renesas-soc, linux-kernel,
	Geert Uytterhoeven

	Hi all,

If an interrupt controller in a Renesas ARM SoC is part of a Clock
Domain, and it is part of the wakeup path, it must be kept active during
system suspend.

Currently this is handled in all interrupt controller drivers by
explicitly increasing the use count of the module clock when the device
is part of the wakeup path.  However, this explicit clock handling is
merely a workaround for a failure to properly communicate wakeup
information to the device core.

Hence this series fixes the affected drivers by setting the devices'
power.wakeup_path fields instead, to indicate they are part of the
wakeup path.  Depending on the PM Domain's active_wakeup configuration,
the genpd core code will keep the device enabled (and the clock running)
during system suspend when needed.

Note that most of these patches depend on the series "[PATCH v2 0/3] PM
/ Domain: renesas: Fix active wakeup behavior", hence they should not be
applied yet.

This has been tested on r8a73a4/ape6evm, r8a7740/armadillo,
r8a7791/koelsch, r8a7795/salvator-x and -xs, r8a7796/salvator-x, and
sh73a0/kzm9g.

Thanks for your comments!

Geert Uytterhoeven (3):
  irqchip/renesas-intc-irqpin: Use wakeup_path i.s.o. explicit clock
    handling
  irqchip/renesas-irqc: Use wakeup_path i.s.o. explicit clock handling
  gpio: rcar: Use wakeup_path i.s.o. explicit clock handling

 drivers/gpio/gpio-rcar.c                  | 43 +++++++++++++----------------
 drivers/irqchip/irq-renesas-intc-irqpin.c | 45 +++++++++++++------------------
 drivers/irqchip/irq-renesas-irqc.c        | 35 ++++++++++++------------
 3 files changed, 54 insertions(+), 69 deletions(-)

-- 
2.7.4

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH/RFC 1/3] irqchip/renesas-intc-irqpin: Use wakeup_path i.s.o. explicit clock handling
  2017-11-09 13:48 [PATCH/RFC 0/3] renesas: irqchip: Use wakeup_path i.s.o. explicit clock handling Geert Uytterhoeven
@ 2017-11-09 13:48 ` Geert Uytterhoeven
  2017-11-09 13:48 ` [PATCH/RFC 2/3] irqchip/renesas-irqc: " Geert Uytterhoeven
  2017-11-09 13:48 ` [PATCH/RFC 3/3] gpio: rcar: " Geert Uytterhoeven
  2 siblings, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2017-11-09 13:48 UTC (permalink / raw)
  To: Rafael J . Wysocki, Ulf Hansson, Kevin Hilman
  Cc: Thomas Gleixner, Jason Cooper, Marc Zyngier, Linus Walleij,
	linux-pm, linux-gpio, linux-renesas-soc, linux-kernel,
	Geert Uytterhoeven

Since commit 705bc96c2c15313c ("irqchip: renesas-intc-irqpin: Add
minimal runtime PM support"), when an IRQ is used for wakeup, the INTC
block's module clock (if exists) is manually kept running during system
suspend, to make sure the device stays active.

However, this explicit clock handling is merely a workaround for a
failure to properly communicate wakeup information to the device core.

Instead, set the device's power.wakeup_path field, to indicate this
device is part of the wakeup path.  Depending on the PM Domain's
active_wakeup configuration, the genpd core code will keep the device
enabled (and the clock running) during system suspend when needed.
This allows for the removal of all explicit clock handling code from the
driver.

Note that the dev_pm_info.wakeup_path field exists only if
CONFIG_PM_SLEEP is enabled, hence the whole suspend infrastructure is
protected by #ifdef CONFIG_PM_SLEEP.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
This driver is used on Renesas R-Mobile and R-Car Gen1 platforms.

As (1) the pm-rmobile driver already keeps wakeup sources active during
system suspend, and (2) the INTC block on R-Car Gen1 doesn't have a
controllable module clock, this patch should be safe to apply.

v3:
  - New.
---
 drivers/irqchip/irq-renesas-intc-irqpin.c | 45 +++++++++++++------------------
 1 file changed, 18 insertions(+), 27 deletions(-)

diff --git a/drivers/irqchip/irq-renesas-intc-irqpin.c b/drivers/irqchip/irq-renesas-intc-irqpin.c
index 06f29cf5018a151f..85ed4c9b9fd5b90f 100644
--- a/drivers/irqchip/irq-renesas-intc-irqpin.c
+++ b/drivers/irqchip/irq-renesas-intc-irqpin.c
@@ -17,7 +17,6 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include <linux/clk.h>
 #include <linux/init.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
@@ -78,16 +77,14 @@ struct intc_irqpin_priv {
 	struct platform_device *pdev;
 	struct irq_chip irq_chip;
 	struct irq_domain *irq_domain;
-	struct clk *clk;
 	unsigned shared_irqs:1;
-	unsigned needs_clk:1;
+	unsigned wakeup_path:1;
 	u8 shared_irq_mask;
 };
 
 struct intc_irqpin_config {
 	unsigned int irlm_bit;
 	unsigned needs_irlm:1;
-	unsigned needs_clk:1;
 };
 
 static unsigned long intc_irqpin_read32(void __iomem *iomem)
@@ -287,15 +284,7 @@ static int intc_irqpin_irq_set_wake(struct irq_data *d, unsigned int on)
 	int hw_irq = irqd_to_hwirq(d);
 
 	irq_set_irq_wake(p->irq[hw_irq].requested_irq, on);
-
-	if (!p->clk)
-		return 0;
-
-	if (on)
-		clk_enable(p->clk);
-	else
-		clk_disable(p->clk);
-
+	p->wakeup_path = on;
 	return 0;
 }
 
@@ -365,12 +354,10 @@ static const struct irq_domain_ops intc_irqpin_irq_domain_ops = {
 static const struct intc_irqpin_config intc_irqpin_irlm_r8a777x = {
 	.irlm_bit = 23, /* ICR0.IRLM0 */
 	.needs_irlm = 1,
-	.needs_clk = 0,
 };
 
 static const struct intc_irqpin_config intc_irqpin_rmobile = {
 	.needs_irlm = 0,
-	.needs_clk = 1,
 };
 
 static const struct of_device_id intc_irqpin_dt_ids[] = {
@@ -422,18 +409,6 @@ static int intc_irqpin_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, p);
 
 	config = of_device_get_match_data(dev);
-	if (config)
-		p->needs_clk = config->needs_clk;
-
-	p->clk = devm_clk_get(dev, NULL);
-	if (IS_ERR(p->clk)) {
-		if (p->needs_clk) {
-			dev_err(dev, "unable to get clock\n");
-			ret = PTR_ERR(p->clk);
-			goto err0;
-		}
-		p->clk = NULL;
-	}
 
 	pm_runtime_enable(dev);
 	pm_runtime_get_sync(dev);
@@ -602,12 +577,28 @@ static int intc_irqpin_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int intc_irqpin_suspend(struct device *dev)
+{
+	struct intc_irqpin_priv *p = dev_get_drvdata(dev);
+
+	dev->power.wakeup_path = p->wakeup_path;
+	return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(intc_irqpin_pm_ops, intc_irqpin_suspend, NULL);
+#define DEV_PM_OPS	&intc_irqpin_pm_ops
+#else
+#define DEV_PM_OPS	NULL
+#endif
+
 static struct platform_driver intc_irqpin_device_driver = {
 	.probe		= intc_irqpin_probe,
 	.remove		= intc_irqpin_remove,
 	.driver		= {
 		.name	= "renesas_intc_irqpin",
 		.of_match_table = intc_irqpin_dt_ids,
+		.pm	= DEV_PM_OPS,
 	}
 };
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH/RFC 2/3] irqchip/renesas-irqc: Use wakeup_path i.s.o. explicit clock handling
  2017-11-09 13:48 [PATCH/RFC 0/3] renesas: irqchip: Use wakeup_path i.s.o. explicit clock handling Geert Uytterhoeven
  2017-11-09 13:48 ` [PATCH/RFC 1/3] irqchip/renesas-intc-irqpin: " Geert Uytterhoeven
@ 2017-11-09 13:48 ` Geert Uytterhoeven
  2017-11-09 13:48 ` [PATCH/RFC 3/3] gpio: rcar: " Geert Uytterhoeven
  2 siblings, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2017-11-09 13:48 UTC (permalink / raw)
  To: Rafael J . Wysocki, Ulf Hansson, Kevin Hilman
  Cc: Thomas Gleixner, Jason Cooper, Marc Zyngier, Linus Walleij,
	linux-pm, linux-gpio, linux-renesas-soc, linux-kernel,
	Geert Uytterhoeven

Since commit 6f46aedb9c85873b ("irqchip: renesas-irqc: Add wake-up
support"), when an IRQ is used for wakeup, the INTC
block's module clock is manually kept running during system suspend, to
make sure the device stays active.

However, this explicit clock handling is merely a workaround for a
failure to properly communicate wakeup information to the device core.

Instead, set the device's power.wakeup_path field, to indicate this
device is part of the wakeup path.  Depending on the PM Domain's
active_wakeup configuration, the genpd core code will keep the device
enabled (and the clock running) during system suspend when needed.
This allows for the removal of all explicit clock handling code from the
driver.

Note that the dev_pm_info.wakeup_path field exists only if
CONFIG_PM_SLEEP is enabled, hence the whole suspend infrastructure is
protected by #ifdef CONFIG_PM_SLEEP.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
To avoid regressions, this must not be applied before "soc: renesas:
rcar-sysc: Keep wakeup sources active during system suspend" has landed
upstream, hence the "RFC"!

This driver is used on Renesas R-Mobile, R-Car Gen2/3, and RZ/G1
platforms.  While the pm-rmobile driver already keeps wakeup sources
active during system suspend, this is not the case on R-Car Gen2/3 and
RZ/G1 yet.

v3:
  - New.
---
 drivers/irqchip/irq-renesas-irqc.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
index 52304b139aa46a60..d91dab43268f9d0a 100644
--- a/drivers/irqchip/irq-renesas-irqc.c
+++ b/drivers/irqchip/irq-renesas-irqc.c
@@ -17,7 +17,6 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include <linux/clk.h>
 #include <linux/init.h>
 #include <linux/platform_device.h>
 #include <linux/spinlock.h>
@@ -64,7 +63,7 @@ struct irqc_priv {
 	struct platform_device *pdev;
 	struct irq_chip_generic *gc;
 	struct irq_domain *irq_domain;
-	struct clk *clk;
+	unsigned wakeup_path:1;
 };
 
 static struct irqc_priv *irq_data_to_priv(struct irq_data *data)
@@ -111,15 +110,7 @@ static int irqc_irq_set_wake(struct irq_data *d, unsigned int on)
 	int hw_irq = irqd_to_hwirq(d);
 
 	irq_set_irq_wake(p->irq[hw_irq].requested_irq, on);
-
-	if (!p->clk)
-		return 0;
-
-	if (on)
-		clk_enable(p->clk);
-	else
-		clk_disable(p->clk);
-
+	p->wakeup_path = on;
 	return 0;
 }
 
@@ -159,12 +150,6 @@ static int irqc_probe(struct platform_device *pdev)
 	p->pdev = pdev;
 	platform_set_drvdata(pdev, p);
 
-	p->clk = devm_clk_get(&pdev->dev, NULL);
-	if (IS_ERR(p->clk)) {
-		dev_warn(&pdev->dev, "unable to get clock\n");
-		p->clk = NULL;
-	}
-
 	pm_runtime_enable(&pdev->dev);
 	pm_runtime_get_sync(&pdev->dev);
 
@@ -276,6 +261,21 @@ static int irqc_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int irqc_suspend(struct device *dev)
+{
+	struct irqc_priv *p = dev_get_drvdata(dev);
+
+	dev->power.wakeup_path = p->wakeup_path;
+	return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(irqc_pm_ops, irqc_suspend, NULL);
+#define DEV_PM_OPS	&irqc_pm_ops
+#else
+#define DEV_PM_OPS	NULL
+#endif
+
 static const struct of_device_id irqc_dt_ids[] = {
 	{ .compatible = "renesas,irqc", },
 	{},
@@ -288,6 +288,7 @@ static struct platform_driver irqc_device_driver = {
 	.driver		= {
 		.name	= "renesas_irqc",
 		.of_match_table	= irqc_dt_ids,
+		.pm	= DEV_PM_OPS,
 	}
 };
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH/RFC 3/3] gpio: rcar: Use wakeup_path i.s.o. explicit clock handling
  2017-11-09 13:48 [PATCH/RFC 0/3] renesas: irqchip: Use wakeup_path i.s.o. explicit clock handling Geert Uytterhoeven
  2017-11-09 13:48 ` [PATCH/RFC 1/3] irqchip/renesas-intc-irqpin: " Geert Uytterhoeven
  2017-11-09 13:48 ` [PATCH/RFC 2/3] irqchip/renesas-irqc: " Geert Uytterhoeven
@ 2017-11-09 13:48 ` Geert Uytterhoeven
  2 siblings, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2017-11-09 13:48 UTC (permalink / raw)
  To: Rafael J . Wysocki, Ulf Hansson, Kevin Hilman
  Cc: Thomas Gleixner, Jason Cooper, Marc Zyngier, Linus Walleij,
	linux-pm, linux-gpio, linux-renesas-soc, linux-kernel,
	Geert Uytterhoeven

Since commit ab82fa7da4dce5c7 ("gpio: rcar: Prevent module clock disable
when wake-up is enabled"), when a GPIO is used for wakeup, the GPIO
block's module clock (if exists) is manually kept running during system
suspend, to make sure the device stays active.

However, this explicit clock handling is merely a workaround for a
failure to properly communicate wakeup information to the device core.

Instead, set the device's power.wakeup_path field, to indicate this
device is part of the wakeup path.  Depending on the PM Domain's
active_wakeup configuration, the genpd core code will keep the device
enabled (and the clock running) during system suspend when needed.
This allows for the removal of all explicit clock handling code from the
driver.

Note that the dev_pm_info.wakeup_path field exists only if
CONFIG_PM_SLEEP is enabled, hence the whole suspend infrastructure is
protected by #ifdef CONFIG_PM_SLEEP.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
To avoid regressions, this must not be applied before "soc: renesas:
rcar-sysc: Keep wakeup sources active during system suspend" has landed
upstream, hence the "RFC"!

This driver is used on Renesas R-Car and RZ/G1 platforms.
While the GPIO block on R-Car Gen1 doesn't have a controllable module
clock and is thus fine, the rcar-sysc driver doesn't keep wakeup sources
active during system suspend yet on R-Car Gen2 and Gen3, and on RZ/G1.

v3:
  - New.
---
 drivers/gpio/gpio-rcar.c | 43 ++++++++++++++++++-------------------------
 1 file changed, 18 insertions(+), 25 deletions(-)

diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
index 2cf5f458928b2af7..12bf87414213614d 100644
--- a/drivers/gpio/gpio-rcar.c
+++ b/drivers/gpio/gpio-rcar.c
@@ -14,7 +14,6 @@
  * GNU General Public License for more details.
  */
 
-#include <linux/clk.h>
 #include <linux/err.h>
 #include <linux/gpio.h>
 #include <linux/init.h>
@@ -37,10 +36,9 @@ struct gpio_rcar_priv {
 	struct platform_device *pdev;
 	struct gpio_chip gpio_chip;
 	struct irq_chip irq_chip;
-	struct clk *clk;
 	unsigned int irq_parent;
 	bool has_both_edge_trigger;
-	bool needs_clk;
+	bool wakeup_path;
 };
 
 #define IOINTSEL 0x00	/* General IO/Interrupt Switching Register */
@@ -186,14 +184,7 @@ static int gpio_rcar_irq_set_wake(struct irq_data *d, unsigned int on)
 		}
 	}
 
-	if (!p->clk)
-		return 0;
-
-	if (on)
-		clk_enable(p->clk);
-	else
-		clk_disable(p->clk);
-
+	p->wakeup_path = on;
 	return 0;
 }
 
@@ -330,17 +321,14 @@ static int gpio_rcar_direction_output(struct gpio_chip *chip, unsigned offset,
 
 struct gpio_rcar_info {
 	bool has_both_edge_trigger;
-	bool needs_clk;
 };
 
 static const struct gpio_rcar_info gpio_rcar_info_gen1 = {
 	.has_both_edge_trigger = false,
-	.needs_clk = false,
 };
 
 static const struct gpio_rcar_info gpio_rcar_info_gen2 = {
 	.has_both_edge_trigger = true,
-	.needs_clk = true,
 };
 
 static const struct of_device_id gpio_rcar_of_table[] = {
@@ -403,7 +391,6 @@ static int gpio_rcar_parse_dt(struct gpio_rcar_priv *p, unsigned int *npins)
 	ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, 0, &args);
 	*npins = ret == 0 ? args.args[2] : RCAR_MAX_GPIO_PER_BANK;
 	p->has_both_edge_trigger = info->has_both_edge_trigger;
-	p->needs_clk = info->needs_clk;
 
 	if (*npins == 0 || *npins > RCAR_MAX_GPIO_PER_BANK) {
 		dev_warn(&p->pdev->dev,
@@ -415,6 +402,21 @@ static int gpio_rcar_parse_dt(struct gpio_rcar_priv *p, unsigned int *npins)
 	return 0;
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int gpio_rcar_suspend(struct device *dev)
+{
+	struct gpio_rcar_priv *p = dev_get_drvdata(dev);
+
+	dev->power.wakeup_path = p->wakeup_path;
+	return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(gpio_rcar_pm_ops, gpio_rcar_suspend, NULL);
+#define DEV_PM_OPS	&gpio_rcar_pm_ops
+#else
+#define DEV_PM_OPS	NULL
+#endif
+
 static int gpio_rcar_probe(struct platform_device *pdev)
 {
 	struct gpio_rcar_priv *p;
@@ -440,16 +442,6 @@ static int gpio_rcar_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, p);
 
-	p->clk = devm_clk_get(dev, NULL);
-	if (IS_ERR(p->clk)) {
-		if (p->needs_clk) {
-			dev_err(dev, "unable to get clock\n");
-			ret = PTR_ERR(p->clk);
-			goto err0;
-		}
-		p->clk = NULL;
-	}
-
 	pm_runtime_enable(dev);
 
 	irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
@@ -536,6 +528,7 @@ static struct platform_driver gpio_rcar_device_driver = {
 	.remove		= gpio_rcar_remove,
 	.driver		= {
 		.name	= "gpio_rcar",
+		.pm     = DEV_PM_OPS,
 		.of_match_table = of_match_ptr(gpio_rcar_of_table),
 	}
 };
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-11-09 13:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-09 13:48 [PATCH/RFC 0/3] renesas: irqchip: Use wakeup_path i.s.o. explicit clock handling Geert Uytterhoeven
2017-11-09 13:48 ` [PATCH/RFC 1/3] irqchip/renesas-intc-irqpin: " Geert Uytterhoeven
2017-11-09 13:48 ` [PATCH/RFC 2/3] irqchip/renesas-irqc: " Geert Uytterhoeven
2017-11-09 13:48 ` [PATCH/RFC 3/3] gpio: rcar: " Geert Uytterhoeven

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).