Skip to content

Commit ab82fa7

Browse files
geertulinusw
authored andcommitted
gpio: rcar: Prevent module clock disable when wake-up is enabled
When the GPIO module is needed for wake-up, it's module clock must not be disabled. Hence implement irq_chip.irq_set_wake(), which increments/decrements the clock's enable_count when needed, and forwards the wake-up state to the upstream interrupt controller. This fixes wake-up from s2ram using gpio-keys when using a PM Domain to manage the module clock. Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent 3dc1e68 commit ab82fa7

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

drivers/gpio/gpio-rcar.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* GNU General Public License for more details.
1515
*/
1616

17+
#include <linux/clk.h>
1718
#include <linux/err.h>
1819
#include <linux/gpio.h>
1920
#include <linux/init.h>
@@ -37,6 +38,8 @@ struct gpio_rcar_priv {
3738
struct platform_device *pdev;
3839
struct gpio_chip gpio_chip;
3940
struct irq_chip irq_chip;
41+
unsigned int irq_parent;
42+
struct clk *clk;
4043
};
4144

4245
#define IOINTSEL 0x00 /* General IO/Interrupt Switching Register */
@@ -169,6 +172,25 @@ static int gpio_rcar_irq_set_type(struct irq_data *d, unsigned int type)
169172
return 0;
170173
}
171174

175+
static int gpio_rcar_irq_set_wake(struct irq_data *d, unsigned int on)
176+
{
177+
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
178+
struct gpio_rcar_priv *p = container_of(gc, struct gpio_rcar_priv,
179+
gpio_chip);
180+
181+
irq_set_irq_wake(p->irq_parent, on);
182+
183+
if (!p->clk)
184+
return 0;
185+
186+
if (on)
187+
clk_enable(p->clk);
188+
else
189+
clk_disable(p->clk);
190+
191+
return 0;
192+
}
193+
172194
static irqreturn_t gpio_rcar_irq_handler(int irq, void *dev_id)
173195
{
174196
struct gpio_rcar_priv *p = dev_id;
@@ -367,6 +389,12 @@ static int gpio_rcar_probe(struct platform_device *pdev)
367389

368390
platform_set_drvdata(pdev, p);
369391

392+
p->clk = devm_clk_get(dev, NULL);
393+
if (IS_ERR(p->clk)) {
394+
dev_warn(dev, "unable to get clock\n");
395+
p->clk = NULL;
396+
}
397+
370398
pm_runtime_enable(dev);
371399
pm_runtime_get_sync(dev);
372400

@@ -404,8 +432,8 @@ static int gpio_rcar_probe(struct platform_device *pdev)
404432
irq_chip->irq_mask = gpio_rcar_irq_disable;
405433
irq_chip->irq_unmask = gpio_rcar_irq_enable;
406434
irq_chip->irq_set_type = gpio_rcar_irq_set_type;
407-
irq_chip->flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_SET_TYPE_MASKED
408-
| IRQCHIP_MASK_ON_SUSPEND;
435+
irq_chip->irq_set_wake = gpio_rcar_irq_set_wake;
436+
irq_chip->flags = IRQCHIP_SET_TYPE_MASKED | IRQCHIP_MASK_ON_SUSPEND;
409437

410438
ret = gpiochip_add(gpio_chip);
411439
if (ret) {
@@ -420,6 +448,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
420448
goto err1;
421449
}
422450

451+
p->irq_parent = irq->start;
423452
if (devm_request_irq(dev, irq->start, gpio_rcar_irq_handler,
424453
IRQF_SHARED, name, p)) {
425454
dev_err(dev, "failed to request IRQ\n");

0 commit comments

Comments
 (0)