gpio: tegra186: Implement system suspend/resume support
Subsystems (2)
PATCH 1/2 gpio: tegra186: Implement system suspend/resume support
From: Thierry Reding <[email protected]>
Backup GPIO control registers on suspend and restore them on resume to ensure that the GPIOs' configuration remains the same across suspend and resume.
--- drivers/gpio/gpio-tegra186.c | 51 ++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)
drivers/gpio/gpio-tegra186.c +51 -0
@@ -64,6 +64,12 @@ struct tegra_gpio {const struct tegra_gpio_soc *soc;void __iomem *base; + +struct tegra_gpio_context { +u32 value; +u32 control; +u32 config; + } *context; }; static const struct tegra_gpio_port *
@@ -455,6 +461,11 @@ static int tegra186_gpio_probe(struct platform_device *pdev)for (i =0 ; i < gpio->soc->num_ports; i++) gpio->gpio.ngpio += gpio->soc->ports[i].pins; + gpio->context =devm_kmalloc_array (gpio->gpio.parent, gpio->gpio.ngpio, +sizeof (*gpio->context),GFP_KERNEL ); +if (!gpio->context) +return -ENOMEM ; + names =devm_kcalloc (gpio->gpio.parent, gpio->gpio.ngpio,sizeof (*names),GFP_KERNEL );if (!names)
@@ -526,6 +537,45 @@ static int tegra186_gpio_remove(struct platform_device *pdev)return 0 ; } +static int tegra186_gpio_suspend (struct device *dev) +{ +struct tegra_gpio *gpio =dev_get_drvdata (dev); +unsigned int i; + +for (i =0 ; i < gpio->gpio.ngpio; i++) { +struct tegra_gpio_context *context = &gpio->context[i]; +void __iomem *base =tegra186_gpio_get_base (gpio, i); + + context->config =readl (base +TEGRA186_GPIO_ENABLE_CONFIG ); + context->control =readl (base +TEGRA186_GPIO_OUTPUT_CONTROL ); + context->value =readl (base +TEGRA186_GPIO_OUTPUT_VALUE ); + } + +return 0 ; +} + +static int tegra186_gpio_resume (struct device *dev) +{ +struct tegra_gpio *gpio =dev_get_drvdata (dev); +unsigned int i; + +for (i =0 ; i < gpio->gpio.ngpio; i++) { +struct tegra_gpio_context *context = &gpio->context[i]; +void __iomem *base =tegra186_gpio_get_base (gpio, i); + +writel (context->value, base +TEGRA186_GPIO_OUTPUT_VALUE ); +writel (context->control, base +TEGRA186_GPIO_OUTPUT_CONTROL ); +writel (context->config, base +TEGRA186_GPIO_ENABLE_CONFIG ); + } + +return 0 ; +} + +static const struct dev_pm_ops tegra186_gpio_pm = { + .suspend_late = tegra186_gpio_suspend, + .resume_early = tegra186_gpio_resume, +}; +#define TEGRA186_MAIN_GPIO_PORT (port, base, count, controller) \ [TEGRA186_MAIN_GPIO_PORT_##port] = { \ .name = #port, \
@@ -680,6 +730,7 @@ static struct platform_driver tegra186_gpio_driver = { .driver = { .name = "tegra186-gpio", .of_match_table = tegra186_gpio_of_match, + .pm = &tegra186_gpio_pm, }, .probe = tegra186_gpio_probe, .remove = tegra186_gpio_remove,
Signature · 1 line
2.23.0
PATCH v5 2/2 gpio: tegra186: Implement wake event support
From: Thierry Reding <[email protected]>
The GPIO controller doesn't have any controls to enable the system to wake up from low power states based on activity on GPIO pins. An extra hardware block that is part of the power management controller (PMC) contains these controls. In order for the GPIO controller to be able to cooperate with the PMC, obtain a reference to the PMC's IRQ domain and make it a parent to the GPIO controller's IRQ domain. This way the PMC gets an opportunity to program the additional registers required to enable wakeup sources on suspend.
Based on additional work by Bitan Biswas <[email protected]>.
---
Changes in v5:
- rebase on top of new hierarchical IRQ domain support
Changes in v4:
- implement gpio_irq_chip.to_fwspec() instead of gpio_chip.to_irq()
- initialize missing irq_domain_ops.free()
Changes in v3:
- use irq_create_fwspec_mapping() instead of irq_domain_alloc_irqs()
- initialize tegra_gpio_soc.instance field on Tegra186
Changes in v2:
- don't use wakeup-parent property but look up PMC by compatible
drivers/gpio/Kconfig | 1 + drivers/gpio/gpio-tegra186.c | 97 +++++++++++++++++++++++++++++------- 2 files changed, 80 insertions(+), 18 deletions(-)
drivers/gpio/Kconfig +1 -0
@@ -531,6 +531,7 @@ config GPIO_TEGRA186 depends on ARCH_TEGRA_186_SOC || COMPILE_TEST depends on OF_GPIO select GPIOLIB_IRQCHIP + select IRQ_DOMAIN_HIERARCHY help Say yes here to support GPIO pins on NVIDIA Tegra186 SoCs.
drivers/gpio/gpio-tegra186.c +79 -18
177 lines not on this page · raw message
Signature · 1 line
2.23.0
Re: [PATCH v5 2/2] gpio: tegra186: Implement wake event support
Quoted 11 lines · Thierry Reding
From: Thierry Reding <[email protected]>
The GPIO controller doesn't have any controls to enable the system to wake up from low power states based on activity on GPIO pins. An extra hardware block that is part of the power management controller (PMC) contains these controls. In order for the GPIO controller to be able to cooperate with the PMC, obtain a reference to the PMC's IRQ domain and make it a parent to the GPIO controller's IRQ domain. This way the PMC gets an opportunity to program the additional registers required to enable wakeup sources on suspend.
Quoted 6 lines
Based on additional work by Bitan Biswas <[email protected]>.
Signed-off-by Thierry Reding <[email protected]>---
Changes in v5:
- rebase on top of new hierarchical IRQ domain support
Patch applied!
Also a special thanks for standing out to my sometimes flimsy and handwavy engineering, and I'm happy we landed this the way I imagined it. Sort of.
Yours,
Linus Walleij
Quoted 88 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Backup GPIO control registers on suspend and restore them on resume to ensure that the GPIOs' configuration remains the same across suspend and resume.
Signed-off-by Thierry Reding <[email protected]>--- drivers/gpio/gpio-tegra186.c | 51 ++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)drivers/gpio/gpio-tegra186.c +50
-0@@ -64,6 +64,12 @@ struct tegra_gpio {const struct tegra_gpio_soc *soc;void __iomem *base; + +struct tegra_gpio_context { +u32 value; +u32 control; +u32 config; + } *context; }; static const struct tegra_gpio_port *@@ -455,6 +461,11 @@ static int tegra186_gpio_probe(struct platform_device *pdev)for (i =0 ; i < gpio->soc->num_ports; i++) gpio->gpio.ngpio += gpio->soc->ports[i].pins; + gpio->context =devm_kmalloc_array (gpio->gpio.parent, gpio->gpio.ngpio, +sizeof (*gpio->context),GFP_KERNEL ); +if (!gpio->context) +return -ENOMEM ; + names =devm_kcalloc (gpio->gpio.parent, gpio->gpio.ngpio,sizeof (*names),GFP_KERNEL );if (!names)@@ -526,6 +537,45 @@ static int tegra186_gpio_remove(struct platform_device *pdev)return 0 ; } +static int tegra186_gpio_suspend (struct device *dev) +{ +struct tegra_gpio *gpio =dev_get_drvdata (dev); +unsigned int i; + +for (i =0 ; i < gpio->gpio.ngpio; i++) { +struct tegra_gpio_context *context = &gpio->context[i]; +void __iomem *base =tegra186_gpio_get_base (gpio, i); + + context->config =readl (base +TEGRA186_GPIO_ENABLE_CONFIG ); + context->control =readl (base +TEGRA186_GPIO_OUTPUT_CONTROL ); + context->value =readl (base +TEGRA186_GPIO_OUTPUT_VALUE ); + } + +return 0 ; +} + +static int tegra186_gpio_resume (struct device *dev) +{ +struct tegra_gpio *gpio =dev_get_drvdata (dev); +unsigned int i; + +for (i =0 ; i < gpio->gpio.ngpio; i++) { +struct tegra_gpio_context *context = &gpio->context[i]; +void __iomem *base =tegra186_gpio_get_base (gpio, i); + +writel (context->value, base +TEGRA186_GPIO_OUTPUT_VALUE ); +writel (context->control, base +TEGRA186_GPIO_OUTPUT_CONTROL ); +writel (context->config, base +TEGRA186_GPIO_ENABLE_CONFIG ); + } + +return 0 ; +} + +static const struct dev_pm_ops tegra186_gpio_pm = { + .suspend_late = tegra186_gpio_suspend, + .resume_early = tegra186_gpio_resume, +}; +#define TEGRA186_MAIN_GPIO_PORT (port, base, count, controller) \ [TEGRA186_MAIN_GPIO_PORT_##port] = { \ .name = #port, \
drivers/gpio/gpio-tegra186.c static struct platform_driver tegra186_gpio_driver = { · line 736
Quoted 7 lines
drivers/gpio/gpio-tegra186.c +1
-0@@ -680,6 +730,7 @@ static struct platform_driver tegra186_gpio_driver = { .driver = { .name = "tegra186-gpio", .of_match_table = tegra186_gpio_of_match, + .pm = &tegra186_gpio_pm, }, .probe = tegra186_gpio_probe, .remove = tegra186_gpio_remove,
I see jetson Xavier RTC wakeup test fail with this patch. It no longer reaches the UART shell after suspend exit. Jetson-TX2 works fine with this patch. There seems to be some hang on Xavier.
-regards,
Bitan
Quoted 3 lines · Bitan Biswas
I see jetson Xavier RTC wakeup test fail with this patch. It no longer reaches the UART shell after suspend exit. Jetson-TX2 works fine with this patch. There seems to be some hang on Xavier.
That sounds like some very typical situation where you need proper wakeup handling, so that the chip does not suspend if any irq lines are flagged as wakeup-capable and in use.
Yours,
Linus Walleij