* [PATCH 06/17] gpio: mvebu: add suspend/resume support
[not found] <1414151970-6626-1-git-send-email-thomas.petazzoni@free-electrons.com>
@ 2014-10-24 11:59 ` Thomas Petazzoni
2014-10-24 16:30 ` David Cohen
` (3 more replies)
0 siblings, 4 replies; 12+ messages in thread
From: Thomas Petazzoni @ 2014-10-24 11:59 UTC (permalink / raw)
To: Jason Cooper, Andrew Lunn, Sebastian Hesselbarth, Gregory Clement
Cc: linux-arm-kernel, Tawfik Bayouk, Nadav Haklai, Lior Amsalem,
Ezequiel Garcia, devicetree, Thomas Petazzoni, Linus Walleij,
Alexandre Courbot, linux-gpio
This commit adds the implementation of ->suspend() and ->resume()
platform_driver hooks in order to save and restore the state of the
GPIO configuration. In order to achieve that, additional fields are
added to the mvebu_gpio_chip structure.
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Alexandre Courbot <gnurou@gmail.com>
Cc: linux-gpio@vger.kernel.org
---
drivers/gpio/gpio-mvebu.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 99 insertions(+)
diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index 418e386..dd5545c 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -83,6 +83,14 @@ struct mvebu_gpio_chip {
int irqbase;
struct irq_domain *domain;
int soc_variant;
+
+ /* Used to preserve GPIO registers accross suspend/resume */
+ u32 out_reg;
+ u32 io_conf_reg;
+ u32 blink_en_reg;
+ u32 in_pol_reg;
+ u32 edge_mask_regs[4];
+ u32 level_mask_regs[4];
};
/*
@@ -554,6 +562,93 @@ static const struct of_device_id mvebu_gpio_of_match[] = {
};
MODULE_DEVICE_TABLE(of, mvebu_gpio_of_match);
+static int mvebu_gpio_suspend(struct platform_device *pdev, pm_message_t state)
+{
+ struct mvebu_gpio_chip *mvchip = platform_get_drvdata(pdev);
+ int i;
+
+ mvchip->out_reg = readl(mvebu_gpioreg_out(mvchip));
+ mvchip->io_conf_reg = readl(mvebu_gpioreg_io_conf(mvchip));
+ mvchip->blink_en_reg = readl(mvebu_gpioreg_blink(mvchip));
+ mvchip->in_pol_reg = readl(mvebu_gpioreg_in_pol(mvchip));
+
+ switch (mvchip->soc_variant) {
+ case MVEBU_GPIO_SOC_VARIANT_ORION:
+ mvchip->edge_mask_regs[0] =
+ readl(mvchip->membase + GPIO_EDGE_MASK_OFF);
+ mvchip->level_mask_regs[0] =
+ readl(mvchip->membase + GPIO_LEVEL_MASK_OFF);
+ break;
+ case MVEBU_GPIO_SOC_VARIANT_MV78200:
+ for (i = 0; i < 2; i++) {
+ mvchip->edge_mask_regs[i] =
+ readl(mvchip->membase +
+ GPIO_EDGE_MASK_MV78200_OFF(i));
+ mvchip->level_mask_regs[i] =
+ readl(mvchip->membase +
+ GPIO_LEVEL_MASK_MV78200_OFF(i));
+ }
+ break;
+ case MVEBU_GPIO_SOC_VARIANT_ARMADAXP:
+ for (i = 0; i < 4; i++) {
+ mvchip->edge_mask_regs[i] =
+ readl(mvchip->membase +
+ GPIO_EDGE_MASK_ARMADAXP_OFF(i));
+ mvchip->level_mask_regs[i] =
+ readl(mvchip->membase +
+ GPIO_LEVEL_MASK_ARMADAXP_OFF(i));
+ }
+ break;
+ default:
+ BUG();
+ }
+
+ return 0;
+}
+
+static int mvebu_gpio_resume(struct platform_device *pdev)
+{
+ struct mvebu_gpio_chip *mvchip = platform_get_drvdata(pdev);
+ int i;
+
+ writel(mvchip->out_reg, mvebu_gpioreg_out(mvchip));
+ writel(mvchip->io_conf_reg, mvebu_gpioreg_io_conf(mvchip));
+ writel(mvchip->blink_en_reg, mvebu_gpioreg_blink(mvchip));
+ writel(mvchip->in_pol_reg, mvebu_gpioreg_in_pol(mvchip));
+
+ switch (mvchip->soc_variant) {
+ case MVEBU_GPIO_SOC_VARIANT_ORION:
+ writel(mvchip->edge_mask_regs[0],
+ mvchip->membase + GPIO_EDGE_MASK_OFF);
+ writel(mvchip->level_mask_regs[0],
+ mvchip->membase + GPIO_LEVEL_MASK_OFF);
+ break;
+ case MVEBU_GPIO_SOC_VARIANT_MV78200:
+ for (i = 0; i < 2; i++) {
+ writel(mvchip->edge_mask_regs[i],
+ mvchip->membase + GPIO_EDGE_MASK_MV78200_OFF(i));
+ writel(mvchip->level_mask_regs[i],
+ mvchip->membase +
+ GPIO_LEVEL_MASK_MV78200_OFF(i));
+ }
+ break;
+ case MVEBU_GPIO_SOC_VARIANT_ARMADAXP:
+ for (i = 0; i < 4; i++) {
+ writel(mvchip->edge_mask_regs[i],
+ mvchip->membase +
+ GPIO_EDGE_MASK_ARMADAXP_OFF(i));
+ writel(mvchip->level_mask_regs[i],
+ mvchip->membase +
+ GPIO_LEVEL_MASK_ARMADAXP_OFF(i));
+ }
+ break;
+ default:
+ BUG();
+ }
+
+ return 0;
+}
+
static int mvebu_gpio_probe(struct platform_device *pdev)
{
struct mvebu_gpio_chip *mvchip;
@@ -577,6 +672,8 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
if (!mvchip)
return -ENOMEM;
+ platform_set_drvdata(pdev, mvchip);
+
if (of_property_read_u32(pdev->dev.of_node, "ngpios", &ngpios)) {
dev_err(&pdev->dev, "Missing ngpios OF property\n");
return -ENODEV;
@@ -735,5 +832,7 @@ static struct platform_driver mvebu_gpio_driver = {
.of_match_table = mvebu_gpio_of_match,
},
.probe = mvebu_gpio_probe,
+ .suspend = mvebu_gpio_suspend,
+ .resume = mvebu_gpio_resume,
};
module_platform_driver(mvebu_gpio_driver);
--
2.0.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 06/17] gpio: mvebu: add suspend/resume support
2014-10-24 11:59 ` [PATCH 06/17] gpio: mvebu: add suspend/resume support Thomas Petazzoni
@ 2014-10-24 16:30 ` David Cohen
2014-10-24 20:45 ` Andrew Lunn
2014-10-31 7:00 ` Linus Walleij
` (2 subsequent siblings)
3 siblings, 1 reply; 12+ messages in thread
From: David Cohen @ 2014-10-24 16:30 UTC (permalink / raw)
To: Thomas Petazzoni
Cc: Jason Cooper, Andrew Lunn, Sebastian Hesselbarth, Gregory Clement,
linux-arm-kernel, Tawfik Bayouk, Nadav Haklai, Lior Amsalem,
Ezequiel Garcia, devicetree, Linus Walleij, Alexandre Courbot,
linux-gpio
On Fri, Oct 24, 2014 at 01:59:19PM +0200, Thomas Petazzoni wrote:
> This commit adds the implementation of ->suspend() and ->resume()
> platform_driver hooks in order to save and restore the state of the
> GPIO configuration. In order to achieve that, additional fields are
> added to the mvebu_gpio_chip structure.
>
> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Alexandre Courbot <gnurou@gmail.com>
> Cc: linux-gpio@vger.kernel.org
> ---
> drivers/gpio/gpio-mvebu.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 99 insertions(+)
>
> diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
> index 418e386..dd5545c 100644
> --- a/drivers/gpio/gpio-mvebu.c
> +++ b/drivers/gpio/gpio-mvebu.c
> @@ -83,6 +83,14 @@ struct mvebu_gpio_chip {
> int irqbase;
> struct irq_domain *domain;
> int soc_variant;
> +
> + /* Used to preserve GPIO registers accross suspend/resume */
> + u32 out_reg;
> + u32 io_conf_reg;
> + u32 blink_en_reg;
> + u32 in_pol_reg;
> + u32 edge_mask_regs[4];
> + u32 level_mask_regs[4];
> };
>
> /*
> @@ -554,6 +562,93 @@ static const struct of_device_id mvebu_gpio_of_match[] = {
> };
> MODULE_DEVICE_TABLE(of, mvebu_gpio_of_match);
>
> +static int mvebu_gpio_suspend(struct platform_device *pdev, pm_message_t state)
> +{
> + struct mvebu_gpio_chip *mvchip = platform_get_drvdata(pdev);
> + int i;
> +
> + mvchip->out_reg = readl(mvebu_gpioreg_out(mvchip));
> + mvchip->io_conf_reg = readl(mvebu_gpioreg_io_conf(mvchip));
> + mvchip->blink_en_reg = readl(mvebu_gpioreg_blink(mvchip));
> + mvchip->in_pol_reg = readl(mvebu_gpioreg_in_pol(mvchip));
> +
> + switch (mvchip->soc_variant) {
> + case MVEBU_GPIO_SOC_VARIANT_ORION:
> + mvchip->edge_mask_regs[0] =
> + readl(mvchip->membase + GPIO_EDGE_MASK_OFF);
> + mvchip->level_mask_regs[0] =
> + readl(mvchip->membase + GPIO_LEVEL_MASK_OFF);
> + break;
> + case MVEBU_GPIO_SOC_VARIANT_MV78200:
> + for (i = 0; i < 2; i++) {
> + mvchip->edge_mask_regs[i] =
> + readl(mvchip->membase +
> + GPIO_EDGE_MASK_MV78200_OFF(i));
> + mvchip->level_mask_regs[i] =
> + readl(mvchip->membase +
> + GPIO_LEVEL_MASK_MV78200_OFF(i));
> + }
> + break;
> + case MVEBU_GPIO_SOC_VARIANT_ARMADAXP:
> + for (i = 0; i < 4; i++) {
> + mvchip->edge_mask_regs[i] =
> + readl(mvchip->membase +
> + GPIO_EDGE_MASK_ARMADAXP_OFF(i));
> + mvchip->level_mask_regs[i] =
> + readl(mvchip->membase +
> + GPIO_LEVEL_MASK_ARMADAXP_OFF(i));
> + }
> + break;
> + default:
> + BUG();
Isn't it too severe? Is the platform going too unstable if driver
reaches this case?
I'd consider a WARN() instead.
> + }
> +
> + return 0;
> +}
> +
> +static int mvebu_gpio_resume(struct platform_device *pdev)
> +{
> + struct mvebu_gpio_chip *mvchip = platform_get_drvdata(pdev);
> + int i;
> +
> + writel(mvchip->out_reg, mvebu_gpioreg_out(mvchip));
> + writel(mvchip->io_conf_reg, mvebu_gpioreg_io_conf(mvchip));
> + writel(mvchip->blink_en_reg, mvebu_gpioreg_blink(mvchip));
> + writel(mvchip->in_pol_reg, mvebu_gpioreg_in_pol(mvchip));
> +
> + switch (mvchip->soc_variant) {
> + case MVEBU_GPIO_SOC_VARIANT_ORION:
> + writel(mvchip->edge_mask_regs[0],
> + mvchip->membase + GPIO_EDGE_MASK_OFF);
> + writel(mvchip->level_mask_regs[0],
> + mvchip->membase + GPIO_LEVEL_MASK_OFF);
> + break;
> + case MVEBU_GPIO_SOC_VARIANT_MV78200:
> + for (i = 0; i < 2; i++) {
> + writel(mvchip->edge_mask_regs[i],
> + mvchip->membase + GPIO_EDGE_MASK_MV78200_OFF(i));
> + writel(mvchip->level_mask_regs[i],
> + mvchip->membase +
> + GPIO_LEVEL_MASK_MV78200_OFF(i));
> + }
> + break;
> + case MVEBU_GPIO_SOC_VARIANT_ARMADAXP:
> + for (i = 0; i < 4; i++) {
> + writel(mvchip->edge_mask_regs[i],
> + mvchip->membase +
> + GPIO_EDGE_MASK_ARMADAXP_OFF(i));
> + writel(mvchip->level_mask_regs[i],
> + mvchip->membase +
> + GPIO_LEVEL_MASK_ARMADAXP_OFF(i));
> + }
> + break;
> + default:
> + BUG();
Ditto.
Br, David Cohen
> + }
> +
> + return 0;
> +}
> +
> static int mvebu_gpio_probe(struct platform_device *pdev)
> {
> struct mvebu_gpio_chip *mvchip;
> @@ -577,6 +672,8 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
> if (!mvchip)
> return -ENOMEM;
>
> + platform_set_drvdata(pdev, mvchip);
> +
> if (of_property_read_u32(pdev->dev.of_node, "ngpios", &ngpios)) {
> dev_err(&pdev->dev, "Missing ngpios OF property\n");
> return -ENODEV;
> @@ -735,5 +832,7 @@ static struct platform_driver mvebu_gpio_driver = {
> .of_match_table = mvebu_gpio_of_match,
> },
> .probe = mvebu_gpio_probe,
> + .suspend = mvebu_gpio_suspend,
> + .resume = mvebu_gpio_resume,
> };
> module_platform_driver(mvebu_gpio_driver);
> --
> 2.0.0
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 06/17] gpio: mvebu: add suspend/resume support
2014-10-24 16:30 ` David Cohen
@ 2014-10-24 20:45 ` Andrew Lunn
2014-10-27 5:27 ` Alexandre Courbot
0 siblings, 1 reply; 12+ messages in thread
From: Andrew Lunn @ 2014-10-24 20:45 UTC (permalink / raw)
To: David Cohen
Cc: Thomas Petazzoni, Jason Cooper, Andrew Lunn,
Sebastian Hesselbarth, Gregory Clement, linux-arm-kernel,
Tawfik Bayouk, Nadav Haklai, Lior Amsalem, Ezequiel Garcia,
devicetree, Linus Walleij, Alexandre Courbot, linux-gpio
> > + switch (mvchip->soc_variant) {
> > + case MVEBU_GPIO_SOC_VARIANT_ORION:
> > + mvchip->edge_mask_regs[0] =
> > + readl(mvchip->membase + GPIO_EDGE_MASK_OFF);
> > + mvchip->level_mask_regs[0] =
> > + readl(mvchip->membase + GPIO_LEVEL_MASK_OFF);
> > + break;
> > + case MVEBU_GPIO_SOC_VARIANT_MV78200:
> > + for (i = 0; i < 2; i++) {
> > + mvchip->edge_mask_regs[i] =
> > + readl(mvchip->membase +
> > + GPIO_EDGE_MASK_MV78200_OFF(i));
> > + mvchip->level_mask_regs[i] =
> > + readl(mvchip->membase +
> > + GPIO_LEVEL_MASK_MV78200_OFF(i));
> > + }
> > + break;
> > + case MVEBU_GPIO_SOC_VARIANT_ARMADAXP:
> > + for (i = 0; i < 4; i++) {
> > + mvchip->edge_mask_regs[i] =
> > + readl(mvchip->membase +
> > + GPIO_EDGE_MASK_ARMADAXP_OFF(i));
> > + mvchip->level_mask_regs[i] =
> > + readl(mvchip->membase +
> > + GPIO_LEVEL_MASK_ARMADAXP_OFF(i));
> > + }
> > + break;
> > + default:
> > + BUG();
>
> Isn't it too severe? Is the platform going too unstable if driver
> reaches this case?
> I'd consider a WARN() instead.
This is a common pattern in this driver. So i guess Thomas just
cut/pasted the switch statement from _probe(), which also has the
BUG().
Given that _probe() should of thrown a BUG() in this situation, if it
happens here, it means mvchip->soc_variant has been corrupted, and so
bad things are happening. So a BUG() is maybe called for?
Andrew
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 06/17] gpio: mvebu: add suspend/resume support
2014-10-24 20:45 ` Andrew Lunn
@ 2014-10-27 5:27 ` Alexandre Courbot
2014-10-27 17:45 ` David Cohen
0 siblings, 1 reply; 12+ messages in thread
From: Alexandre Courbot @ 2014-10-27 5:27 UTC (permalink / raw)
To: Andrew Lunn
Cc: David Cohen, Thomas Petazzoni, Jason Cooper,
Sebastian Hesselbarth, Gregory Clement,
linux-arm-kernel@lists.infradead.org, Tawfik Bayouk, Nadav Haklai,
Lior Amsalem, Ezequiel Garcia, devicetree@vger.kernel.org,
Linus Walleij, linux-gpio@vger.kernel.org
On Sat, Oct 25, 2014 at 5:45 AM, Andrew Lunn <andrew@lunn.ch> wrote:
>> > + switch (mvchip->soc_variant) {
>> > + case MVEBU_GPIO_SOC_VARIANT_ORION:
>> > + mvchip->edge_mask_regs[0] =
>> > + readl(mvchip->membase + GPIO_EDGE_MASK_OFF);
>> > + mvchip->level_mask_regs[0] =
>> > + readl(mvchip->membase + GPIO_LEVEL_MASK_OFF);
>> > + break;
>> > + case MVEBU_GPIO_SOC_VARIANT_MV78200:
>> > + for (i = 0; i < 2; i++) {
>> > + mvchip->edge_mask_regs[i] =
>> > + readl(mvchip->membase +
>> > + GPIO_EDGE_MASK_MV78200_OFF(i));
>> > + mvchip->level_mask_regs[i] =
>> > + readl(mvchip->membase +
>> > + GPIO_LEVEL_MASK_MV78200_OFF(i));
>> > + }
>> > + break;
>> > + case MVEBU_GPIO_SOC_VARIANT_ARMADAXP:
>> > + for (i = 0; i < 4; i++) {
>> > + mvchip->edge_mask_regs[i] =
>> > + readl(mvchip->membase +
>> > + GPIO_EDGE_MASK_ARMADAXP_OFF(i));
>> > + mvchip->level_mask_regs[i] =
>> > + readl(mvchip->membase +
>> > + GPIO_LEVEL_MASK_ARMADAXP_OFF(i));
>> > + }
>> > + break;
>> > + default:
>> > + BUG();
>>
>> Isn't it too severe? Is the platform going too unstable if driver
>> reaches this case?
>> I'd consider a WARN() instead.
>
> This is a common pattern in this driver. So i guess Thomas just
> cut/pasted the switch statement from _probe(), which also has the
> BUG().
>
> Given that _probe() should of thrown a BUG() in this situation, if it
> happens here, it means mvchip->soc_variant has been corrupted, and so
> bad things are happening. So a BUG() is maybe called for?
I agree that BUG() is adequate here. probe() should recognize the
exact same set of chips - if we reach this point this means that
either the data has been corrupted or we added support for a new chip
in probe() and forgot suspend/resume. In both cases the driver should
express its discontent.
Acked-by: Alexandre Courbot <acourbot@nvidia.com>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 06/17] gpio: mvebu: add suspend/resume support
2014-10-27 5:27 ` Alexandre Courbot
@ 2014-10-27 17:45 ` David Cohen
0 siblings, 0 replies; 12+ messages in thread
From: David Cohen @ 2014-10-27 17:45 UTC (permalink / raw)
To: Alexandre Courbot
Cc: Andrew Lunn, Thomas Petazzoni, Jason Cooper,
Sebastian Hesselbarth, Gregory Clement,
linux-arm-kernel@lists.infradead.org, Tawfik Bayouk, Nadav Haklai,
Lior Amsalem, Ezequiel Garcia, devicetree@vger.kernel.org,
Linus Walleij, linux-gpio@vger.kernel.org
On Mon, Oct 27, 2014 at 02:27:16PM +0900, Alexandre Courbot wrote:
> On Sat, Oct 25, 2014 at 5:45 AM, Andrew Lunn <andrew@lunn.ch> wrote:
> >> > + switch (mvchip->soc_variant) {
> >> > + case MVEBU_GPIO_SOC_VARIANT_ORION:
> >> > + mvchip->edge_mask_regs[0] =
> >> > + readl(mvchip->membase + GPIO_EDGE_MASK_OFF);
> >> > + mvchip->level_mask_regs[0] =
> >> > + readl(mvchip->membase + GPIO_LEVEL_MASK_OFF);
> >> > + break;
> >> > + case MVEBU_GPIO_SOC_VARIANT_MV78200:
> >> > + for (i = 0; i < 2; i++) {
> >> > + mvchip->edge_mask_regs[i] =
> >> > + readl(mvchip->membase +
> >> > + GPIO_EDGE_MASK_MV78200_OFF(i));
> >> > + mvchip->level_mask_regs[i] =
> >> > + readl(mvchip->membase +
> >> > + GPIO_LEVEL_MASK_MV78200_OFF(i));
> >> > + }
> >> > + break;
> >> > + case MVEBU_GPIO_SOC_VARIANT_ARMADAXP:
> >> > + for (i = 0; i < 4; i++) {
> >> > + mvchip->edge_mask_regs[i] =
> >> > + readl(mvchip->membase +
> >> > + GPIO_EDGE_MASK_ARMADAXP_OFF(i));
> >> > + mvchip->level_mask_regs[i] =
> >> > + readl(mvchip->membase +
> >> > + GPIO_LEVEL_MASK_ARMADAXP_OFF(i));
> >> > + }
> >> > + break;
> >> > + default:
> >> > + BUG();
> >>
> >> Isn't it too severe? Is the platform going too unstable if driver
> >> reaches this case?
> >> I'd consider a WARN() instead.
> >
> > This is a common pattern in this driver. So i guess Thomas just
> > cut/pasted the switch statement from _probe(), which also has the
> > BUG().
> >
> > Given that _probe() should of thrown a BUG() in this situation, if it
> > happens here, it means mvchip->soc_variant has been corrupted, and so
> > bad things are happening. So a BUG() is maybe called for?
>
> I agree that BUG() is adequate here. probe() should recognize the
> exact same set of chips - if we reach this point this means that
> either the data has been corrupted or we added support for a new chip
> in probe() and forgot suspend/resume. In both cases the driver should
> express its discontent.
Just for the records, since I don't know this platform very well :)
IMHO unless this issue is the source of a serious instability or data
corruption, a WARN() would be a better way for the driver express its
discontent. It's way better to have a functional platform for further
debugging.
This driver can also be compiled as a module. I wonder if it's a good
behavior boot the platform and then crash the kernel when loading the
module driver.
But anyway, that would be just me.
Br, David Cohen
>
> Acked-by: Alexandre Courbot <acourbot@nvidia.com>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 06/17] gpio: mvebu: add suspend/resume support
2014-10-24 11:59 ` [PATCH 06/17] gpio: mvebu: add suspend/resume support Thomas Petazzoni
2014-10-24 16:30 ` David Cohen
@ 2014-10-31 7:00 ` Linus Walleij
2014-10-31 7:52 ` Gregory CLEMENT
2014-11-03 13:29 ` Linus Walleij
2014-11-03 17:53 ` Gregory CLEMENT
3 siblings, 1 reply; 12+ messages in thread
From: Linus Walleij @ 2014-10-31 7:00 UTC (permalink / raw)
To: Thomas Petazzoni
Cc: Jason Cooper, Andrew Lunn, Sebastian Hesselbarth, Gregory Clement,
linux-arm-kernel@lists.infradead.org, Tawfik Bayouk, Nadav Haklai,
Lior Amsalem, Ezequiel Garcia, devicetree@vger.kernel.org,
Alexandre Courbot, linux-gpio@vger.kernel.org
On Fri, Oct 24, 2014 at 1:59 PM, Thomas Petazzoni
<thomas.petazzoni@free-electrons.com> wrote:
> This commit adds the implementation of ->suspend() and ->resume()
> platform_driver hooks in order to save and restore the state of the
> GPIO configuration. In order to achieve that, additional fields are
> added to the mvebu_gpio_chip structure.
>
> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Alexandre Courbot <gnurou@gmail.com>
> Cc: linux-gpio@vger.kernel.org
(...)
> + mvchip->out_reg = readl(mvebu_gpioreg_out(mvchip));
> + mvchip->io_conf_reg = readl(mvebu_gpioreg_io_conf(mvchip));
> + mvchip->blink_en_reg = readl(mvebu_gpioreg_blink(mvchip));
> + mvchip->in_pol_reg = readl(mvebu_gpioreg_in_pol(mvchip));
OK...
> + switch (mvchip->soc_variant) {
> + case MVEBU_GPIO_SOC_VARIANT_ORION:
> + mvchip->edge_mask_regs[0] =
> + readl(mvchip->membase + GPIO_EDGE_MASK_OFF);
> + mvchip->level_mask_regs[0] =
> + readl(mvchip->membase + GPIO_LEVEL_MASK_OFF);
> + break;
You are assigning index [0] twice, why? There must be some
reason, and it should be stated in a comment. If the first read
is necessary for hardware reasons, don't assign it but
discard the result.
(void) readl(...);
(This pattern repeats for each save call below.)
> + switch (mvchip->soc_variant) {
> + case MVEBU_GPIO_SOC_VARIANT_ORION:
> + writel(mvchip->edge_mask_regs[0],
> + mvchip->membase + GPIO_EDGE_MASK_OFF);
> + writel(mvchip->level_mask_regs[0],
> + mvchip->membase + GPIO_LEVEL_MASK_OFF);
And on the way up same thing. Now you write
each register twice. Why?
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 06/17] gpio: mvebu: add suspend/resume support
2014-10-31 7:00 ` Linus Walleij
@ 2014-10-31 7:52 ` Gregory CLEMENT
2014-10-31 8:14 ` Thomas Petazzoni
2014-11-03 13:26 ` Linus Walleij
0 siblings, 2 replies; 12+ messages in thread
From: Gregory CLEMENT @ 2014-10-31 7:52 UTC (permalink / raw)
To: Linus Walleij
Cc: Thomas Petazzoni, Jason Cooper, Andrew Lunn,
Sebastian Hesselbarth, linux-arm-kernel@lists.infradead.org,
Tawfik Bayouk, Nadav Haklai, Lior Amsalem, Ezequiel Garcia,
devicetree@vger.kernel.org, Alexandre Courbot,
linux-gpio@vger.kernel.org
Hi Linus,
>
>> + switch (mvchip->soc_variant) {
>> + case MVEBU_GPIO_SOC_VARIANT_ORION:
>> + mvchip->edge_mask_regs[0] =
>> + readl(mvchip->membase + GPIO_EDGE_MASK_OFF);
>> + mvchip->level_mask_regs[0] =
>> + readl(mvchip->membase + GPIO_LEVEL_MASK_OFF);
>> + break;
>
> You are assigning index [0] twice, why? There must be some
> reason, and it should be stated in a comment. If the first read
> is necessary for hardware reasons, don't assign it but
> discard the result.
Maybe I missed something but for me these 2 registers are different:
one is the _EDGE_ mask and the other the _LEVEL_ mask.
Gregory
--
Gregory Clement, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 06/17] gpio: mvebu: add suspend/resume support
2014-10-31 7:52 ` Gregory CLEMENT
@ 2014-10-31 8:14 ` Thomas Petazzoni
2014-11-03 13:26 ` Linus Walleij
1 sibling, 0 replies; 12+ messages in thread
From: Thomas Petazzoni @ 2014-10-31 8:14 UTC (permalink / raw)
To: Gregory CLEMENT
Cc: Linus Walleij, Jason Cooper, Andrew Lunn, Sebastian Hesselbarth,
linux-arm-kernel@lists.infradead.org, Tawfik Bayouk, Nadav Haklai,
Lior Amsalem, Ezequiel Garcia, devicetree@vger.kernel.org,
Alexandre Courbot, linux-gpio@vger.kernel.org
Hello,
On Fri, 31 Oct 2014 08:52:15 +0100, Gregory CLEMENT wrote:
> >> + switch (mvchip->soc_variant) {
> >> + case MVEBU_GPIO_SOC_VARIANT_ORION:
> >> + mvchip->edge_mask_regs[0] =
> >> + readl(mvchip->membase + GPIO_EDGE_MASK_OFF);
> >> + mvchip->level_mask_regs[0] =
> >> + readl(mvchip->membase + GPIO_LEVEL_MASK_OFF);
> >> + break;
> >
> > You are assigning index [0] twice, why? There must be some
> > reason, and it should be stated in a comment. If the first read
> > is necessary for hardware reasons, don't assign it but
> > discard the result.
>
> Maybe I missed something but for me these 2 registers are different:
> one is the _EDGE_ mask and the other the _LEVEL_ mask.
Good that you looked at it Greg because I must admit I did not
understand the comment from Linus :-)
I read things again and both the variable *and* the register offset are
different. I guess it's probably due to a -ENOTENOUGHCOFFEE :-)
Thanks!
Thomas
--
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 06/17] gpio: mvebu: add suspend/resume support
2014-10-31 7:52 ` Gregory CLEMENT
2014-10-31 8:14 ` Thomas Petazzoni
@ 2014-11-03 13:26 ` Linus Walleij
1 sibling, 0 replies; 12+ messages in thread
From: Linus Walleij @ 2014-11-03 13:26 UTC (permalink / raw)
To: Gregory CLEMENT
Cc: Thomas Petazzoni, Jason Cooper, Andrew Lunn,
Sebastian Hesselbarth, linux-arm-kernel@lists.infradead.org,
Tawfik Bayouk, Nadav Haklai, Lior Amsalem, Ezequiel Garcia,
devicetree@vger.kernel.org, Alexandre Courbot,
linux-gpio@vger.kernel.org
On Fri, Oct 31, 2014 at 8:52 AM, Gregory CLEMENT
<gregory.clement@free-electrons.com> wrote:
> Hi Linus,
>>> + switch (mvchip->soc_variant) {
>>> + case MVEBU_GPIO_SOC_VARIANT_ORION:
>>> + mvchip->edge_mask_regs[0] =
>>> + readl(mvchip->membase + GPIO_EDGE_MASK_OFF);
>>> + mvchip->level_mask_regs[0] =
>>> + readl(mvchip->membase + GPIO_LEVEL_MASK_OFF);
>>> + break;
>>
>> You are assigning index [0] twice, why? There must be some
>> reason, and it should be stated in a comment. If the first read
>> is necessary for hardware reasons, don't assign it but
>> discard the result.
>
> Maybe I missed something but for me these 2 registers are different:
> one is the _EDGE_ mask and the other the _LEVEL_ mask.
Yeah haha I must have had a bad perception day :D
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 06/17] gpio: mvebu: add suspend/resume support
2014-10-24 11:59 ` [PATCH 06/17] gpio: mvebu: add suspend/resume support Thomas Petazzoni
2014-10-24 16:30 ` David Cohen
2014-10-31 7:00 ` Linus Walleij
@ 2014-11-03 13:29 ` Linus Walleij
2014-11-03 17:53 ` Gregory CLEMENT
3 siblings, 0 replies; 12+ messages in thread
From: Linus Walleij @ 2014-11-03 13:29 UTC (permalink / raw)
To: Thomas Petazzoni
Cc: Jason Cooper, Andrew Lunn, Sebastian Hesselbarth, Gregory Clement,
linux-arm-kernel@lists.infradead.org, Tawfik Bayouk, Nadav Haklai,
Lior Amsalem, Ezequiel Garcia, devicetree@vger.kernel.org,
Alexandre Courbot, linux-gpio@vger.kernel.org
On Fri, Oct 24, 2014 at 1:59 PM, Thomas Petazzoni
<thomas.petazzoni@free-electrons.com> wrote:
> This commit adds the implementation of ->suspend() and ->resume()
> platform_driver hooks in order to save and restore the state of the
> GPIO configuration. In order to achieve that, additional fields are
> added to the mvebu_gpio_chip structure.
>
> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Alexandre Courbot <gnurou@gmail.com>
> Cc: linux-gpio@vger.kernel.org
Patch applied with Alexandre's ACK.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 06/17] gpio: mvebu: add suspend/resume support
2014-10-24 11:59 ` [PATCH 06/17] gpio: mvebu: add suspend/resume support Thomas Petazzoni
` (2 preceding siblings ...)
2014-11-03 13:29 ` Linus Walleij
@ 2014-11-03 17:53 ` Gregory CLEMENT
2014-11-03 21:21 ` Thomas Petazzoni
3 siblings, 1 reply; 12+ messages in thread
From: Gregory CLEMENT @ 2014-11-03 17:53 UTC (permalink / raw)
To: Thomas Petazzoni, Jason Cooper, Andrew Lunn,
Sebastian Hesselbarth
Cc: linux-arm-kernel, Tawfik Bayouk, Nadav Haklai, Lior Amsalem,
Ezequiel Garcia, devicetree, Linus Walleij, Alexandre Courbot,
linux-gpio
On 24/10/2014 13:59, Thomas Petazzoni wrote:
> This commit adds the implementation of ->suspend() and ->resume()
> platform_driver hooks in order to save and restore the state of the
> GPIO configuration. In order to achieve that, additional fields are
> added to the mvebu_gpio_chip structure.
>
> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Alexandre Courbot <gnurou@gmail.com>
> Cc: linux-gpio@vger.kernel.org
> ---
> drivers/gpio/gpio-mvebu.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 99 insertions(+)
>
> diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
> index 418e386..dd5545c 100644
> --- a/drivers/gpio/gpio-mvebu.c
> +++ b/drivers/gpio/gpio-mvebu.c
> @@ -83,6 +83,14 @@ struct mvebu_gpio_chip {
> int irqbase;
> struct irq_domain *domain;
> int soc_variant;
> +
> + /* Used to preserve GPIO registers accross suspend/resume */
across
> + u32 out_reg;
> + u32 io_conf_reg;
> + u32 blink_en_reg;
> + u32 in_pol_reg;
> + u32 edge_mask_regs[4];
> + u32 level_mask_regs[4];
> };
>
> /*
> @@ -554,6 +562,93 @@ static const struct of_device_id mvebu_gpio_of_match[] = {
> };
> MODULE_DEVICE_TABLE(of, mvebu_gpio_of_match);
>
> +static int mvebu_gpio_suspend(struct platform_device *pdev, pm_message_t state)
> +{
> + struct mvebu_gpio_chip *mvchip = platform_get_drvdata(pdev);
> + int i;
> +
> + mvchip->out_reg = readl(mvebu_gpioreg_out(mvchip));
> + mvchip->io_conf_reg = readl(mvebu_gpioreg_io_conf(mvchip));
> + mvchip->blink_en_reg = readl(mvebu_gpioreg_blink(mvchip));
> + mvchip->in_pol_reg = readl(mvebu_gpioreg_in_pol(mvchip));
> +
> + switch (mvchip->soc_variant) {
> + case MVEBU_GPIO_SOC_VARIANT_ORION:
> + mvchip->edge_mask_regs[0] =
> + readl(mvchip->membase + GPIO_EDGE_MASK_OFF);
> + mvchip->level_mask_regs[0] =
> + readl(mvchip->membase + GPIO_LEVEL_MASK_OFF);
> + break;
> + case MVEBU_GPIO_SOC_VARIANT_MV78200:
> + for (i = 0; i < 2; i++) {
> + mvchip->edge_mask_regs[i] =
> + readl(mvchip->membase +
> + GPIO_EDGE_MASK_MV78200_OFF(i));
> + mvchip->level_mask_regs[i] =
> + readl(mvchip->membase +
> + GPIO_LEVEL_MASK_MV78200_OFF(i));
> + }
> + break;
I don't know if the suspend is supported on this platform but as we were
on the road to remove this platform I don't know it it worth testing it unless
some interested users show up.
I didn't tested it on a mv782xx platform but the patch looks correct:
Reviewed-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
Thanks,
Gregory
--
Gregory Clement, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 06/17] gpio: mvebu: add suspend/resume support
2014-11-03 17:53 ` Gregory CLEMENT
@ 2014-11-03 21:21 ` Thomas Petazzoni
0 siblings, 0 replies; 12+ messages in thread
From: Thomas Petazzoni @ 2014-11-03 21:21 UTC (permalink / raw)
To: Gregory CLEMENT
Cc: Jason Cooper, Andrew Lunn, Sebastian Hesselbarth,
linux-arm-kernel, Tawfik Bayouk, Nadav Haklai, Lior Amsalem,
Ezequiel Garcia, devicetree, Linus Walleij, Alexandre Courbot,
linux-gpio
Dear Gregory CLEMENT,
On Mon, 03 Nov 2014 18:53:29 +0100, Gregory CLEMENT wrote:
> I don't know if the suspend is supported on this platform but as we were
> on the road to remove this platform I don't know it it worth testing it unless
> some interested users show up.
The same can be said of the entire mv78xx0 support in gpio-mvebu: it's
completely unused today. Since the migration to mv78xx0 has not been
started, this platform is still using the old style GPIO driver in
plat-orion/gpio.c. And therefore, all the mv78xx0 specific code in
gpio-mvebu.c is purely "tentative" and has never been actually tested
on HW.
Best regards,
Thomas
--
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2014-11-03 21:21 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1414151970-6626-1-git-send-email-thomas.petazzoni@free-electrons.com>
2014-10-24 11:59 ` [PATCH 06/17] gpio: mvebu: add suspend/resume support Thomas Petazzoni
2014-10-24 16:30 ` David Cohen
2014-10-24 20:45 ` Andrew Lunn
2014-10-27 5:27 ` Alexandre Courbot
2014-10-27 17:45 ` David Cohen
2014-10-31 7:00 ` Linus Walleij
2014-10-31 7:52 ` Gregory CLEMENT
2014-10-31 8:14 ` Thomas Petazzoni
2014-11-03 13:26 ` Linus Walleij
2014-11-03 13:29 ` Linus Walleij
2014-11-03 17:53 ` Gregory CLEMENT
2014-11-03 21:21 ` Thomas Petazzoni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).