LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v2] ARM: imx6: mask all interrupts before calling stby-poweroff sequence
@ 2021-08-17 12:25 Oleksij Rempel
  2021-09-22  2:37 ` Shawn Guo
  0 siblings, 1 reply; 4+ messages in thread
From: Oleksij Rempel @ 2021-08-17 12:25 UTC (permalink / raw)
  To: Shawn Guo, Sascha Hauer
  Cc: Oleksij Rempel, kernel, linux-arm-kernel, linux-kernel,
	Fabio Estevam, linux-imx

Any pending interrupt can prevent entering standby based power off state.
To avoid it, mask all interrupts.

Fixes: 8148d2136002 ("ARM: imx6: register pm_power_off handler if "fsl,pmic-stby-poweroff" is set")
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 arch/arm/mach-imx/pm-imx6.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/arch/arm/mach-imx/pm-imx6.c b/arch/arm/mach-imx/pm-imx6.c
index 9244437cb1b9..63887ade411a 100644
--- a/arch/arm/mach-imx/pm-imx6.c
+++ b/arch/arm/mach-imx/pm-imx6.c
@@ -59,8 +59,11 @@
 #define MX6Q_SUSPEND_OCRAM_SIZE		0x1000
 #define MX6_MAX_MMDC_IO_NUM		33
 
+#define GIC_DIST_ENABLE_CLEAR		0x180
+
 static void __iomem *ccm_base;
 static void __iomem *suspend_ocram_base;
+static void __iomem *gic_raw_dist_base;
 static void (*imx6_suspend_in_ocram_fn)(void __iomem *ocram_vbase);
 
 /*
@@ -592,6 +595,7 @@ static int __init imx6q_suspend_init(const struct imx6_pm_socdata *socdata)
 static void __init imx6_pm_common_init(const struct imx6_pm_socdata
 					*socdata)
 {
+	struct device_node *np;
 	struct regmap *gpr;
 	int ret;
 
@@ -615,10 +619,29 @@ static void __init imx6_pm_common_init(const struct imx6_pm_socdata
 	if (!IS_ERR(gpr))
 		regmap_update_bits(gpr, IOMUXC_GPR1, IMX6Q_GPR1_GINT,
 				   IMX6Q_GPR1_GINT);
+
+	np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-gic");
+	gic_raw_dist_base = of_iomap(np, 0);
+}
+
+static void imx_gic_mask_all(void)
+{
+	int i;
+
+	if (WARN_ON(!gic_raw_dist_base))
+		return;
+
+	for (i = 0; i < 4; i++)
+		writel_relaxed(~0, gic_raw_dist_base + GIC_DIST_ENABLE_CLEAR + 4 * i);
 }
 
 static void imx6_pm_stby_poweroff(void)
 {
+	/*
+	 * A pending interrupt can prevent power off signal to be activated.
+	 * So, mask all interrupts to avoid it.
+	 */
+	imx_gic_mask_all();
 	imx6_set_lpm(STOP_POWER_OFF);
 	imx6q_suspend_finish(0);
 
-- 
2.30.2


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

* Re: [PATCH v2] ARM: imx6: mask all interrupts before calling stby-poweroff sequence
  2021-08-17 12:25 [PATCH v2] ARM: imx6: mask all interrupts before calling stby-poweroff sequence Oleksij Rempel
@ 2021-09-22  2:37 ` Shawn Guo
  2021-09-22  2:57   ` Florian Fainelli
  0 siblings, 1 reply; 4+ messages in thread
From: Shawn Guo @ 2021-09-22  2:37 UTC (permalink / raw)
  To: Oleksij Rempel
  Cc: Sascha Hauer, kernel, linux-arm-kernel, linux-kernel,
	Fabio Estevam, linux-imx

On Tue, Aug 17, 2021 at 02:25:00PM +0200, Oleksij Rempel wrote:
> Any pending interrupt can prevent entering standby based power off state.
> To avoid it, mask all interrupts.
> 
> Fixes: 8148d2136002 ("ARM: imx6: register pm_power_off handler if "fsl,pmic-stby-poweroff" is set")
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  arch/arm/mach-imx/pm-imx6.c | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/arch/arm/mach-imx/pm-imx6.c b/arch/arm/mach-imx/pm-imx6.c
> index 9244437cb1b9..63887ade411a 100644
> --- a/arch/arm/mach-imx/pm-imx6.c
> +++ b/arch/arm/mach-imx/pm-imx6.c
> @@ -59,8 +59,11 @@
>  #define MX6Q_SUSPEND_OCRAM_SIZE		0x1000
>  #define MX6_MAX_MMDC_IO_NUM		33
>  
> +#define GIC_DIST_ENABLE_CLEAR		0x180
> +
>  static void __iomem *ccm_base;
>  static void __iomem *suspend_ocram_base;
> +static void __iomem *gic_raw_dist_base;
>  static void (*imx6_suspend_in_ocram_fn)(void __iomem *ocram_vbase);
>  
>  /*
> @@ -592,6 +595,7 @@ static int __init imx6q_suspend_init(const struct imx6_pm_socdata *socdata)
>  static void __init imx6_pm_common_init(const struct imx6_pm_socdata
>  					*socdata)
>  {
> +	struct device_node *np;
>  	struct regmap *gpr;
>  	int ret;
>  
> @@ -615,10 +619,29 @@ static void __init imx6_pm_common_init(const struct imx6_pm_socdata
>  	if (!IS_ERR(gpr))
>  		regmap_update_bits(gpr, IOMUXC_GPR1, IMX6Q_GPR1_GINT,
>  				   IMX6Q_GPR1_GINT);
> +
> +	np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-gic");
> +	gic_raw_dist_base = of_iomap(np, 0);
> +}
> +
> +static void imx_gic_mask_all(void)
> +{
> +	int i;
> +
> +	if (WARN_ON(!gic_raw_dist_base))
> +		return;
> +
> +	for (i = 0; i < 4; i++)
> +		writel_relaxed(~0, gic_raw_dist_base + GIC_DIST_ENABLE_CLEAR + 4 * i);

Is it possible to have a helper function in GIC driver, that we can
simply call into?

Shawn

>  }
>  
>  static void imx6_pm_stby_poweroff(void)
>  {
> +	/*
> +	 * A pending interrupt can prevent power off signal to be activated.
> +	 * So, mask all interrupts to avoid it.
> +	 */
> +	imx_gic_mask_all();
>  	imx6_set_lpm(STOP_POWER_OFF);
>  	imx6q_suspend_finish(0);
>  
> -- 
> 2.30.2
> 

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

* Re: [PATCH v2] ARM: imx6: mask all interrupts before calling stby-poweroff sequence
  2021-09-22  2:37 ` Shawn Guo
@ 2021-09-22  2:57   ` Florian Fainelli
  2021-09-28 13:39     ` Oleksij Rempel
  0 siblings, 1 reply; 4+ messages in thread
From: Florian Fainelli @ 2021-09-22  2:57 UTC (permalink / raw)
  To: Shawn Guo, Oleksij Rempel
  Cc: Sascha Hauer, kernel, linux-arm-kernel, linux-kernel,
	Fabio Estevam, linux-imx



On 9/21/2021 7:37 PM, Shawn Guo wrote:
> On Tue, Aug 17, 2021 at 02:25:00PM +0200, Oleksij Rempel wrote:
>> Any pending interrupt can prevent entering standby based power off state.
>> To avoid it, mask all interrupts.
>>
>> Fixes: 8148d2136002 ("ARM: imx6: register pm_power_off handler if "fsl,pmic-stby-poweroff" is set")
>> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
>> ---
>>   arch/arm/mach-imx/pm-imx6.c | 23 +++++++++++++++++++++++
>>   1 file changed, 23 insertions(+)
>>
>> diff --git a/arch/arm/mach-imx/pm-imx6.c b/arch/arm/mach-imx/pm-imx6.c
>> index 9244437cb1b9..63887ade411a 100644
>> --- a/arch/arm/mach-imx/pm-imx6.c
>> +++ b/arch/arm/mach-imx/pm-imx6.c
>> @@ -59,8 +59,11 @@
>>   #define MX6Q_SUSPEND_OCRAM_SIZE		0x1000
>>   #define MX6_MAX_MMDC_IO_NUM		33
>>   
>> +#define GIC_DIST_ENABLE_CLEAR		0x180
>> +
>>   static void __iomem *ccm_base;
>>   static void __iomem *suspend_ocram_base;
>> +static void __iomem *gic_raw_dist_base;
>>   static void (*imx6_suspend_in_ocram_fn)(void __iomem *ocram_vbase);
>>   
>>   /*
>> @@ -592,6 +595,7 @@ static int __init imx6q_suspend_init(const struct imx6_pm_socdata *socdata)
>>   static void __init imx6_pm_common_init(const struct imx6_pm_socdata
>>   					*socdata)
>>   {
>> +	struct device_node *np;
>>   	struct regmap *gpr;
>>   	int ret;
>>   
>> @@ -615,10 +619,29 @@ static void __init imx6_pm_common_init(const struct imx6_pm_socdata
>>   	if (!IS_ERR(gpr))
>>   		regmap_update_bits(gpr, IOMUXC_GPR1, IMX6Q_GPR1_GINT,
>>   				   IMX6Q_GPR1_GINT);
>> +
>> +	np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-gic");
>> +	gic_raw_dist_base = of_iomap(np, 0);
>> +}
>> +
>> +static void imx_gic_mask_all(void)
>> +{
>> +	int i;
>> +
>> +	if (WARN_ON(!gic_raw_dist_base))
>> +		return;
>> +
>> +	for (i = 0; i < 4; i++)
>> +		writel_relaxed(~0, gic_raw_dist_base + GIC_DIST_ENABLE_CLEAR + 4 * i);
> 
> Is it possible to have a helper function in GIC driver, that we can
> simply call into?

Cannot you call gic_cpu_if_down(0) which would presumably have the same 
effect?
-- 
Florian

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

* Re: [PATCH v2] ARM: imx6: mask all interrupts before calling stby-poweroff sequence
  2021-09-22  2:57   ` Florian Fainelli
@ 2021-09-28 13:39     ` Oleksij Rempel
  0 siblings, 0 replies; 4+ messages in thread
From: Oleksij Rempel @ 2021-09-28 13:39 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: Shawn Guo, Sascha Hauer, linux-kernel, linux-imx, kernel,
	Fabio Estevam, linux-arm-kernel

On Tue, Sep 21, 2021 at 07:57:49PM -0700, Florian Fainelli wrote:
> 
> 
> On 9/21/2021 7:37 PM, Shawn Guo wrote:
> > On Tue, Aug 17, 2021 at 02:25:00PM +0200, Oleksij Rempel wrote:
> > > Any pending interrupt can prevent entering standby based power off state.
> > > To avoid it, mask all interrupts.
> > > 
> > > Fixes: 8148d2136002 ("ARM: imx6: register pm_power_off handler if "fsl,pmic-stby-poweroff" is set")
> > > Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> > > ---
> > >   arch/arm/mach-imx/pm-imx6.c | 23 +++++++++++++++++++++++
> > >   1 file changed, 23 insertions(+)
> > > 
> > > diff --git a/arch/arm/mach-imx/pm-imx6.c b/arch/arm/mach-imx/pm-imx6.c
> > > index 9244437cb1b9..63887ade411a 100644
> > > --- a/arch/arm/mach-imx/pm-imx6.c
> > > +++ b/arch/arm/mach-imx/pm-imx6.c
> > > @@ -59,8 +59,11 @@
> > >   #define MX6Q_SUSPEND_OCRAM_SIZE		0x1000
> > >   #define MX6_MAX_MMDC_IO_NUM		33
> > > +#define GIC_DIST_ENABLE_CLEAR		0x180
> > > +
> > >   static void __iomem *ccm_base;
> > >   static void __iomem *suspend_ocram_base;
> > > +static void __iomem *gic_raw_dist_base;
> > >   static void (*imx6_suspend_in_ocram_fn)(void __iomem *ocram_vbase);
> > >   /*
> > > @@ -592,6 +595,7 @@ static int __init imx6q_suspend_init(const struct imx6_pm_socdata *socdata)
> > >   static void __init imx6_pm_common_init(const struct imx6_pm_socdata
> > >   					*socdata)
> > >   {
> > > +	struct device_node *np;
> > >   	struct regmap *gpr;
> > >   	int ret;
> > > @@ -615,10 +619,29 @@ static void __init imx6_pm_common_init(const struct imx6_pm_socdata
> > >   	if (!IS_ERR(gpr))
> > >   		regmap_update_bits(gpr, IOMUXC_GPR1, IMX6Q_GPR1_GINT,
> > >   				   IMX6Q_GPR1_GINT);
> > > +
> > > +	np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-gic");
> > > +	gic_raw_dist_base = of_iomap(np, 0);
> > > +}
> > > +
> > > +static void imx_gic_mask_all(void)
> > > +{
> > > +	int i;
> > > +
> > > +	if (WARN_ON(!gic_raw_dist_base))
> > > +		return;
> > > +
> > > +	for (i = 0; i < 4; i++)
> > > +		writel_relaxed(~0, gic_raw_dist_base + GIC_DIST_ENABLE_CLEAR + 4 * i);
> > 
> > Is it possible to have a helper function in GIC driver, that we can
> > simply call into?
> 
> Cannot you call gic_cpu_if_down(0) which would presumably have the same
> effect?

Good idea, thank you! It works.

Regards,
Oleksij
-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

end of thread, other threads:[~2021-09-28 13:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-17 12:25 [PATCH v2] ARM: imx6: mask all interrupts before calling stby-poweroff sequence Oleksij Rempel
2021-09-22  2:37 ` Shawn Guo
2021-09-22  2:57   ` Florian Fainelli
2021-09-28 13:39     ` Oleksij Rempel

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).