All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpio: mxc: add power management support
@ 2018-07-10  7:48 Anson Huang
  2018-07-13  7:11 ` Linus Walleij
  2018-07-13 18:33 ` Fabio Estevam
  0 siblings, 2 replies; 9+ messages in thread
From: Anson Huang @ 2018-07-10  7:48 UTC (permalink / raw)
  To: linus.walleij, linux-gpio, linux-kernel; +Cc: Linux-imx

GPIO registers could lose context on some i.MX SoCs,
like on i.MX7D, when enter LPSR mode, the whole SoC
will be powered off except LPSR domain, GPIO banks
will lose context in this case, need to restore
the context after resume from LPSR mode.

This patch adds GPIO save/restore for those necessary
registers, and put the save/restore operations in noirq
suspend/resume phase, since GPIO is fundamental module
which could be used by other peripherals' resume phase.

Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
---
 drivers/gpio/gpio-mxc.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c
index 2f28299..0fc52d8 100644
--- a/drivers/gpio/gpio-mxc.c
+++ b/drivers/gpio/gpio-mxc.c
@@ -45,6 +45,15 @@ struct mxc_gpio_hwdata {
 	unsigned fall_edge;
 };
 
+struct mxc_gpio_reg_saved {
+	u32 icr1;
+	u32 icr2;
+	u32 imr;
+	u32 gdir;
+	u32 edge_sel;
+	u32 dr;
+};
+
 struct mxc_gpio_port {
 	struct list_head node;
 	void __iomem *base;
@@ -55,6 +64,7 @@ struct mxc_gpio_port {
 	struct gpio_chip gc;
 	struct device *dev;
 	u32 both_edges;
+	struct mxc_gpio_reg_saved gpio_saved_reg;
 };
 
 static struct mxc_gpio_hwdata imx1_imx21_gpio_hwdata = {
@@ -497,6 +507,8 @@ static int mxc_gpio_probe(struct platform_device *pdev)
 
 	list_add_tail(&port->node, &mxc_gpio_ports);
 
+	platform_set_drvdata(pdev, port);
+
 	return 0;
 
 out_irqdomain_remove:
@@ -507,11 +519,67 @@ static int mxc_gpio_probe(struct platform_device *pdev)
 	return err;
 }
 
+static void mxc_gpio_save_regs(struct mxc_gpio_port *port)
+{
+	if (mxc_gpio_hwtype == IMX21_GPIO)
+		return;
+
+	port->gpio_saved_reg.icr1 = readl(port->base + GPIO_ICR1);
+	port->gpio_saved_reg.icr2 = readl(port->base + GPIO_ICR2);
+	port->gpio_saved_reg.imr = readl(port->base + GPIO_IMR);
+	port->gpio_saved_reg.gdir = readl(port->base + GPIO_GDIR);
+	port->gpio_saved_reg.edge_sel = readl(port->base + GPIO_EDGE_SEL);
+	port->gpio_saved_reg.dr = readl(port->base + GPIO_DR);
+}
+
+static void mxc_gpio_restore_regs(struct mxc_gpio_port *port)
+{
+	if (mxc_gpio_hwtype == IMX21_GPIO)
+		return;
+
+	writel(port->gpio_saved_reg.icr1, port->base + GPIO_ICR1);
+	writel(port->gpio_saved_reg.icr2, port->base + GPIO_ICR2);
+	writel(port->gpio_saved_reg.imr, port->base + GPIO_IMR);
+	writel(port->gpio_saved_reg.gdir, port->base + GPIO_GDIR);
+	writel(port->gpio_saved_reg.edge_sel, port->base + GPIO_EDGE_SEL);
+	writel(port->gpio_saved_reg.dr, port->base + GPIO_DR);
+}
+
+static int __maybe_unused mxc_gpio_noirq_suspend(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct mxc_gpio_port *port = platform_get_drvdata(pdev);
+
+	mxc_gpio_save_regs(port);
+	clk_disable_unprepare(port->clk);
+
+	return 0;
+}
+
+static int __maybe_unused mxc_gpio_noirq_resume(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct mxc_gpio_port *port = platform_get_drvdata(pdev);
+	int ret;
+
+	ret = clk_prepare_enable(port->clk);
+	if (ret)
+		return ret;
+	mxc_gpio_restore_regs(port);
+
+	return 0;
+}
+
+static const struct dev_pm_ops mxc_gpio_dev_pm_ops = {
+	SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(mxc_gpio_noirq_suspend, mxc_gpio_noirq_resume)
+};
+
 static struct platform_driver mxc_gpio_driver = {
 	.driver		= {
 		.name	= "gpio-mxc",
 		.of_match_table = mxc_gpio_dt_ids,
 		.suppress_bind_attrs = true,
+		.pm = &mxc_gpio_dev_pm_ops,
 	},
 	.probe		= mxc_gpio_probe,
 	.id_table	= mxc_gpio_devtype,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] gpio: mxc: add power management support
  2018-07-10  7:48 [PATCH] gpio: mxc: add power management support Anson Huang
@ 2018-07-13  7:11 ` Linus Walleij
  2018-07-13  7:19   ` Bartosz Golaszewski
  2018-07-13 17:57   ` Fabio Estevam
  2018-07-13 18:33 ` Fabio Estevam
  1 sibling, 2 replies; 9+ messages in thread
From: Linus Walleij @ 2018-07-13  7:11 UTC (permalink / raw)
  To: Anson Huang, Fabio Estevam, Bartosz Golaszewski
  Cc: open list:GPIO SUBSYSTEM, linux-kernel, NXP Linux Team

On Tue, Jul 10, 2018 at 9:53 AM Anson Huang <Anson.Huang@nxp.com> wrote:

> GPIO registers could lose context on some i.MX SoCs,
> like on i.MX7D, when enter LPSR mode, the whole SoC
> will be powered off except LPSR domain, GPIO banks
> will lose context in this case, need to restore
> the context after resume from LPSR mode.
>
> This patch adds GPIO save/restore for those necessary
> registers, and put the save/restore operations in noirq
> suspend/resume phase, since GPIO is fundamental module
> which could be used by other peripherals' resume phase.
>
> Signed-off-by: Anson Huang <Anson.Huang@nxp.com>

Hoping for some review on this before applying...
Fabio? Bartosz?

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] gpio: mxc: add power management support
  2018-07-13  7:11 ` Linus Walleij
@ 2018-07-13  7:19   ` Bartosz Golaszewski
  2018-07-13 17:57   ` Fabio Estevam
  1 sibling, 0 replies; 9+ messages in thread
From: Bartosz Golaszewski @ 2018-07-13  7:19 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Anson Huang, Fabio Estevam, open list:GPIO SUBSYSTEM,
	linux-kernel, NXP Linux Team

2018-07-13 9:11 GMT+02:00 Linus Walleij <linus.walleij@linaro.org>:
> On Tue, Jul 10, 2018 at 9:53 AM Anson Huang <Anson.Huang@nxp.com> wrote:
>
>> GPIO registers could lose context on some i.MX SoCs,
>> like on i.MX7D, when enter LPSR mode, the whole SoC
>> will be powered off except LPSR domain, GPIO banks
>> will lose context in this case, need to restore
>> the context after resume from LPSR mode.
>>
>> This patch adds GPIO save/restore for those necessary
>> registers, and put the save/restore operations in noirq
>> suspend/resume phase, since GPIO is fundamental module
>> which could be used by other peripherals' resume phase.
>>
>> Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
>
> Hoping for some review on this before applying...
> Fabio? Bartosz?
>
> Yours,
> Linus Walleij

I'm not familiar with these SoCs but the code looks good and clean to me.

Reviewed-by: Bartosz Golaszewski <brgl@bgdev.pl>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] gpio: mxc: add power management support
  2018-07-13  7:11 ` Linus Walleij
  2018-07-13  7:19   ` Bartosz Golaszewski
@ 2018-07-13 17:57   ` Fabio Estevam
  1 sibling, 0 replies; 9+ messages in thread
From: Fabio Estevam @ 2018-07-13 17:57 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Anson Huang, Fabio Estevam, Bartosz Golaszewski,
	open list:GPIO SUBSYSTEM, linux-kernel, NXP Linux Team

On Fri, Jul 13, 2018 at 4:11 AM, Linus Walleij <linus.walleij@linaro.org> wrote:
> On Tue, Jul 10, 2018 at 9:53 AM Anson Huang <Anson.Huang@nxp.com> wrote:
>
>> GPIO registers could lose context on some i.MX SoCs,
>> like on i.MX7D, when enter LPSR mode, the whole SoC
>> will be powered off except LPSR domain, GPIO banks
>> will lose context in this case, need to restore
>> the context after resume from LPSR mode.
>>
>> This patch adds GPIO save/restore for those necessary
>> registers, and put the save/restore operations in noirq
>> suspend/resume phase, since GPIO is fundamental module
>> which could be used by other peripherals' resume phase.
>>
>> Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
>
> Hoping for some review on this before applying...
> Fabio? Bartosz?

Now I could find the patch on my Gmail Inbox :-)

It looks good to me:

Reviewed-by: Fabio Estevam <fabio.estevam@nxp.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] gpio: mxc: add power management support
  2018-07-10  7:48 [PATCH] gpio: mxc: add power management support Anson Huang
  2018-07-13  7:11 ` Linus Walleij
@ 2018-07-13 18:33 ` Fabio Estevam
  2018-07-14  1:53   ` Anson Huang
  1 sibling, 1 reply; 9+ messages in thread
From: Fabio Estevam @ 2018-07-13 18:33 UTC (permalink / raw)
  To: Anson Huang
  Cc: Linus Walleij, open list:GPIO SUBSYSTEM, linux-kernel, NXP Linux Team

Hi Anson,

On Tue, Jul 10, 2018 at 4:48 AM, Anson Huang <Anson.Huang@nxp.com> wrote:
> GPIO registers could lose context on some i.MX SoCs,
> like on i.MX7D, when enter LPSR mode, the whole SoC

After further reviewing this patchI have a question: here you say that
i.MX7D needs to save some registers.

> will be powered off except LPSR domain, GPIO banks
> will lose context in this case, need to restore
> the context after resume from LPSR mode.
>
> This patch adds GPIO save/restore for those necessary
> registers, and put the save/restore operations in noirq
> suspend/resume phase, since GPIO is fundamental module
> which could be used by other peripherals' resume phase.
>
> Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
> ---
>  drivers/gpio/gpio-mxc.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 68 insertions(+)
>
> diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c
> index 2f28299..0fc52d8 100644
> --- a/drivers/gpio/gpio-mxc.c
> +++ b/drivers/gpio/gpio-mxc.c
> @@ -45,6 +45,15 @@ struct mxc_gpio_hwdata {
>         unsigned fall_edge;
>  };
>
> +struct mxc_gpio_reg_saved {
> +       u32 icr1;
> +       u32 icr2;
> +       u32 imr;
> +       u32 gdir;
> +       u32 edge_sel;
> +       u32 dr;
> +};
> +
>  struct mxc_gpio_port {
>         struct list_head node;
>         void __iomem *base;
> @@ -55,6 +64,7 @@ struct mxc_gpio_port {
>         struct gpio_chip gc;
>         struct device *dev;
>         u32 both_edges;
> +       struct mxc_gpio_reg_saved gpio_saved_reg;
>  };
>
>  static struct mxc_gpio_hwdata imx1_imx21_gpio_hwdata = {
> @@ -497,6 +507,8 @@ static int mxc_gpio_probe(struct platform_device *pdev)
>
>         list_add_tail(&port->node, &mxc_gpio_ports);
>
> +       platform_set_drvdata(pdev, port);
> +
>         return 0;
>
>  out_irqdomain_remove:
> @@ -507,11 +519,67 @@ static int mxc_gpio_probe(struct platform_device *pdev)
>         return err;
>  }
>
> +static void mxc_gpio_save_regs(struct mxc_gpio_port *port)
> +{
> +       if (mxc_gpio_hwtype == IMX21_GPIO)
> +               return;

but here you only block IMX21_GPIO.

This means that mx31/mx35/mx51/mx53/mx6 will execute this code too
now. Is this always safe?

Shouldn't it this save/restore be executed only on mx7d?

Please clarify.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [PATCH] gpio: mxc: add power management support
  2018-07-13 18:33 ` Fabio Estevam
@ 2018-07-14  1:53   ` Anson Huang
  2018-07-14 16:13     ` Fabio Estevam
  0 siblings, 1 reply; 9+ messages in thread
From: Anson Huang @ 2018-07-14  1:53 UTC (permalink / raw)
  To: Fabio Estevam
  Cc: Linus Walleij, open list:GPIO SUBSYSTEM, linux-kernel, dl-linux-imx

Hi, Fabio

Anson Huang
Best Regards!


> -----Original Message-----
> From: Fabio Estevam [mailto:festevam@gmail.com]
> Sent: Saturday, July 14, 2018 2:34 AM
> To: Anson Huang <anson.huang@nxp.com>
> Cc: Linus Walleij <linus.walleij@linaro.org>; open list:GPIO SUBSYSTEM
> <linux-gpio@vger.kernel.org>; linux-kernel <linux-kernel@vger.kernel.org>;
> dl-linux-imx <linux-imx@nxp.com>
> Subject: Re: [PATCH] gpio: mxc: add power management support
> 
> Hi Anson,
> 
> On Tue, Jul 10, 2018 at 4:48 AM, Anson Huang <Anson.Huang@nxp.com>
> wrote:
> > GPIO registers could lose context on some i.MX SoCs, like on i.MX7D,
> > when enter LPSR mode, the whole SoC
> 
> After further reviewing this patchI have a question: here you say that i.MX7D
> needs to save some registers.
> 
> > will be powered off except LPSR domain, GPIO banks will lose context
> > in this case, need to restore the context after resume from LPSR mode.
> >
> > This patch adds GPIO save/restore for those necessary registers, and
> > put the save/restore operations in noirq suspend/resume phase, since
> > GPIO is fundamental module which could be used by other peripherals'
> > resume phase.
> >
> > Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
> > ---
> >  drivers/gpio/gpio-mxc.c | 68
> > +++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 68 insertions(+)
> >
> > diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c index
> > 2f28299..0fc52d8 100644
> > --- a/drivers/gpio/gpio-mxc.c
> > +++ b/drivers/gpio/gpio-mxc.c
> > @@ -45,6 +45,15 @@ struct mxc_gpio_hwdata {
> >         unsigned fall_edge;
> >  };
> >
> > +struct mxc_gpio_reg_saved {
> > +       u32 icr1;
> > +       u32 icr2;
> > +       u32 imr;
> > +       u32 gdir;
> > +       u32 edge_sel;
> > +       u32 dr;
> > +};
> > +
> >  struct mxc_gpio_port {
> >         struct list_head node;
> >         void __iomem *base;
> > @@ -55,6 +64,7 @@ struct mxc_gpio_port {
> >         struct gpio_chip gc;
> >         struct device *dev;
> >         u32 both_edges;
> > +       struct mxc_gpio_reg_saved gpio_saved_reg;
> >  };
> >
> >  static struct mxc_gpio_hwdata imx1_imx21_gpio_hwdata = { @@ -497,6
> > +507,8 @@ static int mxc_gpio_probe(struct platform_device *pdev)
> >
> >         list_add_tail(&port->node, &mxc_gpio_ports);
> >
> > +       platform_set_drvdata(pdev, port);
> > +
> >         return 0;
> >
> >  out_irqdomain_remove:
> > @@ -507,11 +519,67 @@ static int mxc_gpio_probe(struct platform_device
> *pdev)
> >         return err;
> >  }
> >
> > +static void mxc_gpio_save_regs(struct mxc_gpio_port *port) {
> > +       if (mxc_gpio_hwtype == IMX21_GPIO)
> > +               return;
> 
> but here you only block IMX21_GPIO.
> 
> This means that mx31/mx35/mx51/mx53/mx6 will execute this code too now.
> Is this always safe?
> 
> Shouldn't it this save/restore be executed only on mx7d?
> 
> Please clarify.
Here are the details, i.MX7D LPSR mode and i.MX8QM/8QXP etc.' suspend/resume
may cause GPIO bank lose power, so need to save/restore, for other i.MX SoCs,
although no need to do save/restore, but doing it is NOT harmful, so do you think
we should add SoC type check here?

Anson.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] gpio: mxc: add power management support
  2018-07-14  1:53   ` Anson Huang
@ 2018-07-14 16:13     ` Fabio Estevam
  2018-07-16  6:14       ` Anson Huang
  0 siblings, 1 reply; 9+ messages in thread
From: Fabio Estevam @ 2018-07-14 16:13 UTC (permalink / raw)
  To: Anson Huang
  Cc: Linus Walleij, open list:GPIO SUBSYSTEM, linux-kernel, dl-linux-imx

Hi Anson,

On Fri, Jul 13, 2018 at 10:53 PM, Anson Huang <anson.huang@nxp.com> wrote:

> Here are the details, i.MX7D LPSR mode and i.MX8QM/8QXP etc.' suspend/resume
> may cause GPIO bank lose power, so need to save/restore, for other i.MX SoCs,
> although no need to do save/restore, but doing it is NOT harmful, so do you think
> we should add SoC type check here?

I think it would be safer to restrict the save/restore operations to mx7/mx8.

You can add a fsl,imx7d-gpio compatible entry in the driver.

Thanks

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [PATCH] gpio: mxc: add power management support
  2018-07-14 16:13     ` Fabio Estevam
@ 2018-07-16  6:14       ` Anson Huang
  2018-07-17 13:43         ` Fabio Estevam
  0 siblings, 1 reply; 9+ messages in thread
From: Anson Huang @ 2018-07-16  6:14 UTC (permalink / raw)
  To: Fabio Estevam
  Cc: Linus Walleij, open list:GPIO SUBSYSTEM, linux-kernel, dl-linux-imx

Hi, Fabio

Anson Huang
Best Regards!


> -----Original Message-----
> From: Fabio Estevam [mailto:festevam@gmail.com]
> Sent: Sunday, July 15, 2018 12:13 AM
> To: Anson Huang <anson.huang@nxp.com>
> Cc: Linus Walleij <linus.walleij@linaro.org>; open list:GPIO SUBSYSTEM
> <linux-gpio@vger.kernel.org>; linux-kernel <linux-kernel@vger.kernel.org>;
> dl-linux-imx <linux-imx@nxp.com>
> Subject: Re: [PATCH] gpio: mxc: add power management support
> 
> Hi Anson,
> 
> On Fri, Jul 13, 2018 at 10:53 PM, Anson Huang <anson.huang@nxp.com>
> wrote:
> 
> > Here are the details, i.MX7D LPSR mode and i.MX8QM/8QXP etc.'
> > suspend/resume may cause GPIO bank lose power, so need to
> > save/restore, for other i.MX SoCs, although no need to do
> > save/restore, but doing it is NOT harmful, so do you think we should add SoC
> type check here?
> 
> I think it would be safer to restrict the save/restore operations to mx7/mx8.
> 
> You can add a fsl,imx7d-gpio compatible entry in the driver.
> 
> Thanks
OK, since i.MX7D has same GPIO type as i.MX35, to make it simple, I just added
a flag to indicate whether it supports save/restore, only i.MX7D enables
the flag now, since other i.MX8 SoCs' dts is NOT upstreamed yet, so I did NOT add
support for i.MX8 SoCs, please help review V2 patch, thanks.

Anson. 



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] gpio: mxc: add power management support
  2018-07-16  6:14       ` Anson Huang
@ 2018-07-17 13:43         ` Fabio Estevam
  0 siblings, 0 replies; 9+ messages in thread
From: Fabio Estevam @ 2018-07-17 13:43 UTC (permalink / raw)
  To: Anson Huang
  Cc: Linus Walleij, open list:GPIO SUBSYSTEM, linux-kernel, dl-linux-imx

Hi Anson,

On Mon, Jul 16, 2018 at 3:14 AM, Anson Huang <anson.huang@nxp.com> wrote:

> OK, since i.MX7D has same GPIO type as i.MX35, to make it simple, I just added
> a flag to indicate whether it supports save/restore, only i.MX7D enables

In imx7s.dtsi the gpio nodes have:

compatible = "fsl,imx7d-gpio", "fsl,imx35-gpio";

If you add fsl,imx7d-gpio entry in the gpio driver, then the match
will be done against "fsl,imx7d-gpio" since it is more specific.

Then in the mx8 dts you can add:

compatible = "fsl,imx8m-gpio", "fsl,imx7d-gpio";

and it will also match the more generic "fsl,imx7d-gpio" compatible.

> the flag now, since other i.MX8 SoCs' dts is NOT upstreamed yet, so I did NOT add
> support for i.MX8 SoCs, please help review V2 patch, thanks.

I did not see the v2. Did you put me on Cc?

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-07-17 13:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-10  7:48 [PATCH] gpio: mxc: add power management support Anson Huang
2018-07-13  7:11 ` Linus Walleij
2018-07-13  7:19   ` Bartosz Golaszewski
2018-07-13 17:57   ` Fabio Estevam
2018-07-13 18:33 ` Fabio Estevam
2018-07-14  1:53   ` Anson Huang
2018-07-14 16:13     ` Fabio Estevam
2018-07-16  6:14       ` Anson Huang
2018-07-17 13:43         ` Fabio Estevam

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.