Commit 26b04774 authored by Srinivas Neeli's avatar Srinivas Neeli Committed by Bartosz Golaszewski

gpio: gpio-xilinx: Add support for suspend and resume

Add support for suspend and resume, pm runtime suspend and resume.
Added free and request calls.
Signed-off-by: default avatarSrinivas Neeli <srinivas.neeli@xilinx.com>
Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarBartosz Golaszewski <bgolaszewski@baylibre.com>
parent a32c7cae
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/of_device.h> #include <linux/of_device.h>
#include <linux/of_platform.h> #include <linux/of_platform.h>
#include <linux/pm_runtime.h>
#include <linux/slab.h> #include <linux/slab.h>
/* Register Offset Definitions */ /* Register Offset Definitions */
...@@ -278,6 +279,39 @@ static void xgpio_save_regs(struct xgpio_instance *chip) ...@@ -278,6 +279,39 @@ static void xgpio_save_regs(struct xgpio_instance *chip)
chip->gpio_dir[1]); chip->gpio_dir[1]);
} }
static int xgpio_request(struct gpio_chip *chip, unsigned int offset)
{
int ret;
ret = pm_runtime_get_sync(chip->parent);
/*
* If the device is already active pm_runtime_get() will return 1 on
* success, but gpio_request still needs to return 0.
*/
return ret < 0 ? ret : 0;
}
static void xgpio_free(struct gpio_chip *chip, unsigned int offset)
{
pm_runtime_put(chip->parent);
}
static int __maybe_unused xgpio_suspend(struct device *dev)
{
struct xgpio_instance *gpio = dev_get_drvdata(dev);
struct irq_data *data = irq_get_irq_data(gpio->irq);
if (!data) {
dev_err(dev, "irq_get_irq_data() failed\n");
return -EINVAL;
}
if (!irqd_is_wakeup_set(data))
return pm_runtime_force_suspend(dev);
return 0;
}
/** /**
* xgpio_remove - Remove method for the GPIO device. * xgpio_remove - Remove method for the GPIO device.
* @pdev: pointer to the platform device * @pdev: pointer to the platform device
...@@ -290,6 +324,9 @@ static int xgpio_remove(struct platform_device *pdev) ...@@ -290,6 +324,9 @@ static int xgpio_remove(struct platform_device *pdev)
{ {
struct xgpio_instance *gpio = platform_get_drvdata(pdev); struct xgpio_instance *gpio = platform_get_drvdata(pdev);
pm_runtime_get_sync(&pdev->dev);
pm_runtime_put_noidle(&pdev->dev);
pm_runtime_disable(&pdev->dev);
clk_disable_unprepare(gpio->clk); clk_disable_unprepare(gpio->clk);
return 0; return 0;
...@@ -305,6 +342,46 @@ static void xgpio_irq_ack(struct irq_data *irq_data) ...@@ -305,6 +342,46 @@ static void xgpio_irq_ack(struct irq_data *irq_data)
{ {
} }
static int __maybe_unused xgpio_resume(struct device *dev)
{
struct xgpio_instance *gpio = dev_get_drvdata(dev);
struct irq_data *data = irq_get_irq_data(gpio->irq);
if (!data) {
dev_err(dev, "irq_get_irq_data() failed\n");
return -EINVAL;
}
if (!irqd_is_wakeup_set(data))
return pm_runtime_force_resume(dev);
return 0;
}
static int __maybe_unused xgpio_runtime_suspend(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct xgpio_instance *gpio = platform_get_drvdata(pdev);
clk_disable(gpio->clk);
return 0;
}
static int __maybe_unused xgpio_runtime_resume(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct xgpio_instance *gpio = platform_get_drvdata(pdev);
return clk_enable(gpio->clk);
}
static const struct dev_pm_ops xgpio_dev_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(xgpio_suspend, xgpio_resume)
SET_RUNTIME_PM_OPS(xgpio_runtime_suspend,
xgpio_runtime_resume, NULL)
};
/** /**
* xgpio_irq_mask - Write the specified signal of the GPIO device. * xgpio_irq_mask - Write the specified signal of the GPIO device.
* @irq_data: per IRQ and chip data passed down to chip functions * @irq_data: per IRQ and chip data passed down to chip functions
...@@ -546,6 +623,8 @@ static int xgpio_probe(struct platform_device *pdev) ...@@ -546,6 +623,8 @@ static int xgpio_probe(struct platform_device *pdev)
chip->gc.of_gpio_n_cells = cells; chip->gc.of_gpio_n_cells = cells;
chip->gc.get = xgpio_get; chip->gc.get = xgpio_get;
chip->gc.set = xgpio_set; chip->gc.set = xgpio_set;
chip->gc.request = xgpio_request;
chip->gc.free = xgpio_free;
chip->gc.set_multiple = xgpio_set_multiple; chip->gc.set_multiple = xgpio_set_multiple;
chip->gc.label = dev_name(&pdev->dev); chip->gc.label = dev_name(&pdev->dev);
...@@ -565,6 +644,9 @@ static int xgpio_probe(struct platform_device *pdev) ...@@ -565,6 +644,9 @@ static int xgpio_probe(struct platform_device *pdev)
dev_err(&pdev->dev, "Failed to prepare clk\n"); dev_err(&pdev->dev, "Failed to prepare clk\n");
return status; return status;
} }
pm_runtime_get_noresume(&pdev->dev);
pm_runtime_set_active(&pdev->dev);
pm_runtime_enable(&pdev->dev);
xgpio_save_regs(chip); xgpio_save_regs(chip);
...@@ -595,7 +677,7 @@ static int xgpio_probe(struct platform_device *pdev) ...@@ -595,7 +677,7 @@ static int xgpio_probe(struct platform_device *pdev)
GFP_KERNEL); GFP_KERNEL);
if (!girq->parents) { if (!girq->parents) {
status = -ENOMEM; status = -ENOMEM;
goto err_unprepare_clk; goto err_pm_put;
} }
girq->parents[0] = chip->irq; girq->parents[0] = chip->irq;
girq->default_type = IRQ_TYPE_NONE; girq->default_type = IRQ_TYPE_NONE;
...@@ -605,12 +687,15 @@ static int xgpio_probe(struct platform_device *pdev) ...@@ -605,12 +687,15 @@ static int xgpio_probe(struct platform_device *pdev)
status = devm_gpiochip_add_data(&pdev->dev, &chip->gc, chip); status = devm_gpiochip_add_data(&pdev->dev, &chip->gc, chip);
if (status) { if (status) {
dev_err(&pdev->dev, "failed to add GPIO chip\n"); dev_err(&pdev->dev, "failed to add GPIO chip\n");
goto err_unprepare_clk; goto err_pm_put;
} }
pm_runtime_put(&pdev->dev);
return 0; return 0;
err_unprepare_clk: err_pm_put:
pm_runtime_disable(&pdev->dev);
pm_runtime_put_noidle(&pdev->dev);
clk_disable_unprepare(chip->clk); clk_disable_unprepare(chip->clk);
return status; return status;
} }
...@@ -628,6 +713,7 @@ static struct platform_driver xgpio_plat_driver = { ...@@ -628,6 +713,7 @@ static struct platform_driver xgpio_plat_driver = {
.driver = { .driver = {
.name = "gpio-xilinx", .name = "gpio-xilinx",
.of_match_table = xgpio_of_match, .of_match_table = xgpio_of_match,
.pm = &xgpio_dev_pm_ops,
}, },
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment