Re: [PATCH] gpio: mxc: add power management support

2018-07-17 Thread Fabio Estevam
Hi Anson,

On Mon, Jul 16, 2018 at 3:14 AM, Anson Huang  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?


RE: [PATCH] gpio: mxc: add power management support

2018-07-15 Thread Anson Huang
Hi, Fabio

Anson Huang
Best Regards!


> -Original Message-
> From: Fabio Estevam [mailto:feste...@gmail.com]
> Sent: Sunday, July 15, 2018 12:13 AM
> To: Anson Huang 
> Cc: Linus Walleij ; open list:GPIO SUBSYSTEM
> ; linux-kernel ;
> dl-linux-imx 
> Subject: Re: [PATCH] gpio: mxc: add power management support
> 
> Hi Anson,
> 
> On Fri, Jul 13, 2018 at 10:53 PM, Anson Huang 
> 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. 




Re: [PATCH] gpio: mxc: add power management support

2018-07-14 Thread Fabio Estevam
Hi Anson,

On Fri, Jul 13, 2018 at 10:53 PM, Anson Huang  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


RE: [PATCH] gpio: mxc: add power management support

2018-07-13 Thread Anson Huang
Hi, Fabio

Anson Huang
Best Regards!


> -Original Message-
> From: Fabio Estevam [mailto:feste...@gmail.com]
> Sent: Saturday, July 14, 2018 2:34 AM
> To: Anson Huang 
> Cc: Linus Walleij ; open list:GPIO SUBSYSTEM
> ; linux-kernel ;
> dl-linux-imx 
> Subject: Re: [PATCH] gpio: mxc: add power management support
> 
> Hi Anson,
> 
> On Tue, Jul 10, 2018 at 4:48 AM, Anson Huang 
> 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 
> > ---
> >  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.



Re: [PATCH] gpio: mxc: add power management support

2018-07-13 Thread Fabio Estevam
Hi Anson,

On Tue, Jul 10, 2018 at 4:48 AM, Anson Huang  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 
> ---
>  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.


Re: [PATCH] gpio: mxc: add power management support

2018-07-13 Thread Fabio Estevam
On Fri, Jul 13, 2018 at 4:11 AM, Linus Walleij  wrote:
> On Tue, Jul 10, 2018 at 9:53 AM Anson Huang  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 
>
> 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 


Re: [PATCH] gpio: mxc: add power management support

2018-07-13 Thread Bartosz Golaszewski
2018-07-13 9:11 GMT+02:00 Linus Walleij :
> On Tue, Jul 10, 2018 at 9:53 AM Anson Huang  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 
>
> 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 


Re: [PATCH] gpio: mxc: add power management support

2018-07-13 Thread Linus Walleij
On Tue, Jul 10, 2018 at 9:53 AM Anson Huang  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 

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

Yours,
Linus Walleij


[PATCH] gpio: mxc: add power management support

2018-07-10 Thread Anson Huang
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 
---
 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