Commit ede7fb45 authored by Anson Huang's avatar Anson Huang Committed by Greg Kroah-Hartman

gpio: mxc: move gpio noirq suspend/resume to syscore phase

commit 1a5287a3 upstream.

During noirq suspend/resume phase, GPIO irq could arrive
and its registers like IMR will be changed by irq handle
process, to make the GPIO registers exactly when it is
powered ON after resume, move the GPIO noirq suspend/resume
callback to syscore suspend/resume phase, local irq is
disabled at this phase so GPIO registers are atomic.

Fixes: c19fdaee ("gpio: mxc: add power management support")
Signed-off-by: default avatarAnson Huang <Anson.Huang@nxp.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarMartin Hundebøll <martin@geanix.com>
Cc: <stable@vger.kernel.org> # 4.19.x+
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent b1765ebd
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <linux/irqchip/chained_irq.h> #include <linux/irqchip/chained_irq.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/syscore_ops.h>
#include <linux/gpio/driver.h> #include <linux/gpio/driver.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_device.h> #include <linux/of_device.h>
...@@ -550,33 +551,38 @@ static void mxc_gpio_restore_regs(struct mxc_gpio_port *port) ...@@ -550,33 +551,38 @@ static void mxc_gpio_restore_regs(struct mxc_gpio_port *port)
writel(port->gpio_saved_reg.dr, port->base + GPIO_DR); writel(port->gpio_saved_reg.dr, port->base + GPIO_DR);
} }
static int __maybe_unused mxc_gpio_noirq_suspend(struct device *dev) static int mxc_gpio_syscore_suspend(void)
{ {
struct platform_device *pdev = to_platform_device(dev); struct mxc_gpio_port *port;
struct mxc_gpio_port *port = platform_get_drvdata(pdev);
mxc_gpio_save_regs(port); /* walk through all ports */
clk_disable_unprepare(port->clk); list_for_each_entry(port, &mxc_gpio_ports, node) {
mxc_gpio_save_regs(port);
clk_disable_unprepare(port->clk);
}
return 0; return 0;
} }
static int __maybe_unused mxc_gpio_noirq_resume(struct device *dev) static void mxc_gpio_syscore_resume(void)
{ {
struct platform_device *pdev = to_platform_device(dev); struct mxc_gpio_port *port;
struct mxc_gpio_port *port = platform_get_drvdata(pdev);
int ret; int ret;
ret = clk_prepare_enable(port->clk); /* walk through all ports */
if (ret) list_for_each_entry(port, &mxc_gpio_ports, node) {
return ret; ret = clk_prepare_enable(port->clk);
mxc_gpio_restore_regs(port); if (ret) {
pr_err("mxc: failed to enable gpio clock %d\n", ret);
return 0; return;
}
mxc_gpio_restore_regs(port);
}
} }
static const struct dev_pm_ops mxc_gpio_dev_pm_ops = { static struct syscore_ops mxc_gpio_syscore_ops = {
SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(mxc_gpio_noirq_suspend, mxc_gpio_noirq_resume) .suspend = mxc_gpio_syscore_suspend,
.resume = mxc_gpio_syscore_resume,
}; };
static struct platform_driver mxc_gpio_driver = { static struct platform_driver mxc_gpio_driver = {
...@@ -584,7 +590,6 @@ static struct platform_driver mxc_gpio_driver = { ...@@ -584,7 +590,6 @@ static struct platform_driver mxc_gpio_driver = {
.name = "gpio-mxc", .name = "gpio-mxc",
.of_match_table = mxc_gpio_dt_ids, .of_match_table = mxc_gpio_dt_ids,
.suppress_bind_attrs = true, .suppress_bind_attrs = true,
.pm = &mxc_gpio_dev_pm_ops,
}, },
.probe = mxc_gpio_probe, .probe = mxc_gpio_probe,
.id_table = mxc_gpio_devtype, .id_table = mxc_gpio_devtype,
...@@ -592,6 +597,8 @@ static struct platform_driver mxc_gpio_driver = { ...@@ -592,6 +597,8 @@ static struct platform_driver mxc_gpio_driver = {
static int __init gpio_mxc_init(void) static int __init gpio_mxc_init(void)
{ {
register_syscore_ops(&mxc_gpio_syscore_ops);
return platform_driver_register(&mxc_gpio_driver); return platform_driver_register(&mxc_gpio_driver);
} }
subsys_initcall(gpio_mxc_init); subsys_initcall(gpio_mxc_init);
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