Skip to content

Commit 65194cb

Browse files
geertulinusw
authored andcommitted
gpio: rcar: Fine-grained Runtime PM support
Currently gpio modules are runtime-resumed at probe time. This means the gpio module will be active all the time (except during system suspend, if not configured as a wake-up source). While an R-Car Gen2 gpio module retains pins configured for output at the requested level while put in standby mode, gpio registercannot be accessed while suspended. Unfortunately pm_runtime_get_sync() cannot be called from all contexts where gpio register access is needed. Hence move the Runtime PM handling from probe/remove time to gpio request/free time, which is probably the best we can do. On r8a7791/koelsch, gpio modules 0, 1, 3, and 4 are now suspended during normal use (gpio2 is used for LEDs and regulators, gpio5 for keys, gpio6 for SD-Card CD & WP, gpio7 for keys and regulators). Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent 527b397 commit 65194cb

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

drivers/gpio/gpio-rcar.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,17 +251,32 @@ static void gpio_rcar_config_general_input_output_mode(struct gpio_chip *chip,
251251

252252
static int gpio_rcar_request(struct gpio_chip *chip, unsigned offset)
253253
{
254-
return pinctrl_request_gpio(chip->base + offset);
254+
struct gpio_rcar_priv *p = gpio_to_priv(chip);
255+
int error;
256+
257+
error = pm_runtime_get_sync(&p->pdev->dev);
258+
if (error < 0)
259+
return error;
260+
261+
error = pinctrl_request_gpio(chip->base + offset);
262+
if (error)
263+
pm_runtime_put(&p->pdev->dev);
264+
265+
return error;
255266
}
256267

257268
static void gpio_rcar_free(struct gpio_chip *chip, unsigned offset)
258269
{
270+
struct gpio_rcar_priv *p = gpio_to_priv(chip);
271+
259272
pinctrl_free_gpio(chip->base + offset);
260273

261274
/* Set the GPIO as an input to ensure that the next GPIO request won't
262275
* drive the GPIO pin as an output.
263276
*/
264277
gpio_rcar_config_general_input_output_mode(chip, offset, false);
278+
279+
pm_runtime_put(&p->pdev->dev);
265280
}
266281

267282
static int gpio_rcar_direction_input(struct gpio_chip *chip, unsigned offset)
@@ -405,7 +420,6 @@ static int gpio_rcar_probe(struct platform_device *pdev)
405420
}
406421

407422
pm_runtime_enable(dev);
408-
pm_runtime_get_sync(dev);
409423

410424
io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
411425
irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
@@ -487,7 +501,6 @@ static int gpio_rcar_probe(struct platform_device *pdev)
487501
err1:
488502
gpiochip_remove(gpio_chip);
489503
err0:
490-
pm_runtime_put(dev);
491504
pm_runtime_disable(dev);
492505
return ret;
493506
}
@@ -498,7 +511,6 @@ static int gpio_rcar_remove(struct platform_device *pdev)
498511

499512
gpiochip_remove(&p->gpio_chip);
500513

501-
pm_runtime_put(&pdev->dev);
502514
pm_runtime_disable(&pdev->dev);
503515
return 0;
504516
}

0 commit comments

Comments
 (0)