linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] misc: Add clock control logic into Aspeed LPC SNOOP driver
@ 2020-12-02  5:16 John Wang
  2020-12-02  5:16 ` [PATCH 2/2] ARM: dts: aspeed: Add LCLK to lpc-snoop John Wang
  2020-12-08  2:19 ` [PATCH 1/2] misc: Add clock control logic into Aspeed LPC SNOOP driver Joel Stanley
  0 siblings, 2 replies; 5+ messages in thread
From: John Wang @ 2020-12-02  5:16 UTC (permalink / raw)
  To: xuxiaohan, yulei.sh
  Cc: Jae Hyun Yoo, Vernon Mauery, Joel Stanley, Andrew Jeffery,
	moderated list:ARM/ASPEED MACHINE SUPPORT,
	moderated list:ARM/ASPEED MACHINE SUPPORT, open list

From: Jae Hyun Yoo <jae.hyun.yoo@intel.com>

If LPC SNOOP driver is registered ahead of lpc-ctrl module, LPC
SNOOP block will be enabled without heart beating of LCLK until
lpc-ctrl enables the LCLK. This issue causes improper handling on
host interrupts when the host sends interrupt in that time frame.
Then kernel eventually forcibly disables the interrupt with
dumping stack and printing a 'nobody cared this irq' message out.

To prevent this issue, all LPC sub-nodes should enable LCLK
individually so this patch adds clock control logic into the LPC
SNOOP driver.

Signed-off-by: Jae Hyun Yoo <jae.hyun.yoo@intel.com>
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
Signed-off-by: John Wang <wangzhiqiang.bj@bytedance.com>
---
 drivers/soc/aspeed/aspeed-lpc-snoop.c | 30 ++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/drivers/soc/aspeed/aspeed-lpc-snoop.c b/drivers/soc/aspeed/aspeed-lpc-snoop.c
index 682ba0eb4eba..20acac6342ef 100644
--- a/drivers/soc/aspeed/aspeed-lpc-snoop.c
+++ b/drivers/soc/aspeed/aspeed-lpc-snoop.c
@@ -11,6 +11,7 @@
  */
 
 #include <linux/bitops.h>
+#include <linux/clk.h>
 #include <linux/interrupt.h>
 #include <linux/fs.h>
 #include <linux/kfifo.h>
@@ -67,6 +68,7 @@ struct aspeed_lpc_snoop_channel {
 struct aspeed_lpc_snoop {
 	struct regmap		*regmap;
 	int			irq;
+	struct clk		*clk;
 	struct aspeed_lpc_snoop_channel chan[NUM_SNOOP_CHANNELS];
 };
 
@@ -282,22 +284,42 @@ static int aspeed_lpc_snoop_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
+	lpc_snoop->clk = devm_clk_get(dev, NULL);
+	if (IS_ERR(lpc_snoop->clk)) {
+		rc = PTR_ERR(lpc_snoop->clk);
+		if (rc != -EPROBE_DEFER)
+			dev_err(dev, "couldn't get clock\n");
+		return rc;
+	}
+	rc = clk_prepare_enable(lpc_snoop->clk);
+	if (rc) {
+		dev_err(dev, "couldn't enable clock\n");
+		return rc;
+	}
+
 	rc = aspeed_lpc_snoop_config_irq(lpc_snoop, pdev);
 	if (rc)
-		return rc;
+		goto err;
 
 	rc = aspeed_lpc_enable_snoop(lpc_snoop, dev, 0, port);
 	if (rc)
-		return rc;
+		goto err;
 
 	/* Configuration of 2nd snoop channel port is optional */
 	if (of_property_read_u32_index(dev->of_node, "snoop-ports",
 				       1, &port) == 0) {
 		rc = aspeed_lpc_enable_snoop(lpc_snoop, dev, 1, port);
-		if (rc)
+		if (rc) {
 			aspeed_lpc_disable_snoop(lpc_snoop, 0);
+			goto err;
+		}
 	}
 
+	return 0;
+
+err:
+	clk_disable_unprepare(lpc_snoop->clk);
+
 	return rc;
 }
 
@@ -309,6 +331,8 @@ static int aspeed_lpc_snoop_remove(struct platform_device *pdev)
 	aspeed_lpc_disable_snoop(lpc_snoop, 0);
 	aspeed_lpc_disable_snoop(lpc_snoop, 1);
 
+	clk_disable_unprepare(lpc_snoop->clk);
+
 	return 0;
 }
 
-- 
2.25.1


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

* [PATCH 2/2] ARM: dts: aspeed: Add LCLK to lpc-snoop
  2020-12-02  5:16 [PATCH 1/2] misc: Add clock control logic into Aspeed LPC SNOOP driver John Wang
@ 2020-12-02  5:16 ` John Wang
  2020-12-08  2:20   ` Joel Stanley
  2020-12-08  2:19 ` [PATCH 1/2] misc: Add clock control logic into Aspeed LPC SNOOP driver Joel Stanley
  1 sibling, 1 reply; 5+ messages in thread
From: John Wang @ 2020-12-02  5:16 UTC (permalink / raw)
  To: xuxiaohan, yulei.sh
  Cc: Rob Herring, Joel Stanley, Andrew Jeffery,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	moderated list:ARM/ASPEED MACHINE SUPPORT,
	moderated list:ARM/ASPEED MACHINE SUPPORT, open list

Signed-off-by: John Wang <wangzhiqiang.bj@bytedance.com>
---
 arch/arm/boot/dts/aspeed-g4.dtsi | 1 +
 arch/arm/boot/dts/aspeed-g5.dtsi | 1 +
 arch/arm/boot/dts/aspeed-g6.dtsi | 1 +
 3 files changed, 3 insertions(+)

diff --git a/arch/arm/boot/dts/aspeed-g4.dtsi b/arch/arm/boot/dts/aspeed-g4.dtsi
index f606fc01ff13..2364b660f2e4 100644
--- a/arch/arm/boot/dts/aspeed-g4.dtsi
+++ b/arch/arm/boot/dts/aspeed-g4.dtsi
@@ -370,6 +370,7 @@ lpc_snoop: lpc-snoop@10 {
 						compatible = "aspeed,ast2400-lpc-snoop";
 						reg = <0x10 0x8>;
 						interrupts = <8>;
+						clocks = <&syscon ASPEED_CLK_GATE_LCLK>;
 						status = "disabled";
 					};
 
diff --git a/arch/arm/boot/dts/aspeed-g5.dtsi b/arch/arm/boot/dts/aspeed-g5.dtsi
index 19288495f41a..30bbf7452b90 100644
--- a/arch/arm/boot/dts/aspeed-g5.dtsi
+++ b/arch/arm/boot/dts/aspeed-g5.dtsi
@@ -496,6 +496,7 @@ lpc_snoop: lpc-snoop@10 {
 						compatible = "aspeed,ast2500-lpc-snoop";
 						reg = <0x10 0x8>;
 						interrupts = <8>;
+						clocks = <&syscon ASPEED_CLK_GATE_LCLK>;
 						status = "disabled";
 					};
 
diff --git a/arch/arm/boot/dts/aspeed-g6.dtsi b/arch/arm/boot/dts/aspeed-g6.dtsi
index 97ca743363d7..4b1013870fb1 100644
--- a/arch/arm/boot/dts/aspeed-g6.dtsi
+++ b/arch/arm/boot/dts/aspeed-g6.dtsi
@@ -520,6 +520,7 @@ lpc_snoop: lpc-snoop@0 {
 						compatible = "aspeed,ast2600-lpc-snoop";
 						reg = <0x0 0x80>;
 						interrupts = <GIC_SPI 144 IRQ_TYPE_LEVEL_HIGH>;
+						clocks = <&syscon ASPEED_CLK_GATE_LCLK>;
 						status = "disabled";
 					};
 
-- 
2.25.1


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

* Re: [PATCH 1/2] misc: Add clock control logic into Aspeed LPC SNOOP driver
  2020-12-02  5:16 [PATCH 1/2] misc: Add clock control logic into Aspeed LPC SNOOP driver John Wang
  2020-12-02  5:16 ` [PATCH 2/2] ARM: dts: aspeed: Add LCLK to lpc-snoop John Wang
@ 2020-12-08  2:19 ` Joel Stanley
  2020-12-08  9:06   ` [External] " John Wang
  1 sibling, 1 reply; 5+ messages in thread
From: Joel Stanley @ 2020-12-08  2:19 UTC (permalink / raw)
  To: John Wang
  Cc: xuxiaohan, 郁雷,
	Jae Hyun Yoo, Vernon Mauery, Andrew Jeffery,
	moderated list:ARM/ASPEED MACHINE SUPPORT,
	moderated list:ARM/ASPEED MACHINE SUPPORT, open list

On Wed, 2 Dec 2020 at 05:16, John Wang <wangzhiqiang.bj@bytedance.com> wrote:
>
> From: Jae Hyun Yoo <jae.hyun.yoo@intel.com>
>
> If LPC SNOOP driver is registered ahead of lpc-ctrl module, LPC
> SNOOP block will be enabled without heart beating of LCLK until
> lpc-ctrl enables the LCLK. This issue causes improper handling on
> host interrupts when the host sends interrupt in that time frame.
> Then kernel eventually forcibly disables the interrupt with
> dumping stack and printing a 'nobody cared this irq' message out.
>
> To prevent this issue, all LPC sub-nodes should enable LCLK
> individually so this patch adds clock control logic into the LPC
> SNOOP driver.
>
> Signed-off-by: Jae Hyun Yoo <jae.hyun.yoo@intel.com>
> Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
> Signed-off-by: John Wang <wangzhiqiang.bj@bytedance.com>

Reviewed-by: Joel Stanley <joel@jms.id.au>

Thanks for sending these John. It is an excellent idea to upstream
fixes that have been developed.

I assume we will have the same issue for all devices that use the LPC
bus? eg. vuart, bt, kcs, lpc2ahb? It looks like only the lpc-ctrl
(lpc2ahb) does this so far:

git grep -l clk drivers/soc/aspeed/aspeed-p2a-ctrl.c
drivers/soc/aspeed/aspeed-lpc-ctrl.c
drivers/char/ipmi/kcs_bmc_aspeed.c drivers/char/ipmi/bt-bmc.c
drivers/soc/aspeed/aspeed-lpc-ctrl.c




> ---
>  drivers/soc/aspeed/aspeed-lpc-snoop.c | 30 ++++++++++++++++++++++++---
>  1 file changed, 27 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/soc/aspeed/aspeed-lpc-snoop.c b/drivers/soc/aspeed/aspeed-lpc-snoop.c
> index 682ba0eb4eba..20acac6342ef 100644
> --- a/drivers/soc/aspeed/aspeed-lpc-snoop.c
> +++ b/drivers/soc/aspeed/aspeed-lpc-snoop.c
> @@ -11,6 +11,7 @@
>   */
>
>  #include <linux/bitops.h>
> +#include <linux/clk.h>
>  #include <linux/interrupt.h>
>  #include <linux/fs.h>
>  #include <linux/kfifo.h>
> @@ -67,6 +68,7 @@ struct aspeed_lpc_snoop_channel {
>  struct aspeed_lpc_snoop {
>         struct regmap           *regmap;
>         int                     irq;
> +       struct clk              *clk;
>         struct aspeed_lpc_snoop_channel chan[NUM_SNOOP_CHANNELS];
>  };
>
> @@ -282,22 +284,42 @@ static int aspeed_lpc_snoop_probe(struct platform_device *pdev)
>                 return -ENODEV;
>         }
>
> +       lpc_snoop->clk = devm_clk_get(dev, NULL);
> +       if (IS_ERR(lpc_snoop->clk)) {
> +               rc = PTR_ERR(lpc_snoop->clk);
> +               if (rc != -EPROBE_DEFER)
> +                       dev_err(dev, "couldn't get clock\n");
> +               return rc;
> +       }
> +       rc = clk_prepare_enable(lpc_snoop->clk);
> +       if (rc) {
> +               dev_err(dev, "couldn't enable clock\n");
> +               return rc;
> +       }
> +
>         rc = aspeed_lpc_snoop_config_irq(lpc_snoop, pdev);
>         if (rc)
> -               return rc;
> +               goto err;
>
>         rc = aspeed_lpc_enable_snoop(lpc_snoop, dev, 0, port);
>         if (rc)
> -               return rc;
> +               goto err;
>
>         /* Configuration of 2nd snoop channel port is optional */
>         if (of_property_read_u32_index(dev->of_node, "snoop-ports",
>                                        1, &port) == 0) {
>                 rc = aspeed_lpc_enable_snoop(lpc_snoop, dev, 1, port);
> -               if (rc)
> +               if (rc) {
>                         aspeed_lpc_disable_snoop(lpc_snoop, 0);
> +                       goto err;
> +               }
>         }
>
> +       return 0;
> +
> +err:
> +       clk_disable_unprepare(lpc_snoop->clk);
> +
>         return rc;
>  }
>
> @@ -309,6 +331,8 @@ static int aspeed_lpc_snoop_remove(struct platform_device *pdev)
>         aspeed_lpc_disable_snoop(lpc_snoop, 0);
>         aspeed_lpc_disable_snoop(lpc_snoop, 1);
>
> +       clk_disable_unprepare(lpc_snoop->clk);
> +
>         return 0;
>  }
>
> --
> 2.25.1
>

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

* Re: [PATCH 2/2] ARM: dts: aspeed: Add LCLK to lpc-snoop
  2020-12-02  5:16 ` [PATCH 2/2] ARM: dts: aspeed: Add LCLK to lpc-snoop John Wang
@ 2020-12-08  2:20   ` Joel Stanley
  0 siblings, 0 replies; 5+ messages in thread
From: Joel Stanley @ 2020-12-08  2:20 UTC (permalink / raw)
  To: John Wang
  Cc: xuxiaohan, 郁雷,
	Rob Herring, Andrew Jeffery,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	moderated list:ARM/ASPEED MACHINE SUPPORT,
	moderated list:ARM/ASPEED MACHINE SUPPORT, open list

On Wed, 2 Dec 2020 at 05:16, John Wang <wangzhiqiang.bj@bytedance.com> wrote:
>

Can you add a note here about why we are adding these so it's clear is
a fix/enhancement?

Also add a Fixes line for both patches.

> Signed-off-by: John Wang <wangzhiqiang.bj@bytedance.com>


Reviewed-by: Joel Stanley <joel@jms.id.au>

> ---
>  arch/arm/boot/dts/aspeed-g4.dtsi | 1 +
>  arch/arm/boot/dts/aspeed-g5.dtsi | 1 +
>  arch/arm/boot/dts/aspeed-g6.dtsi | 1 +
>  3 files changed, 3 insertions(+)
>
> diff --git a/arch/arm/boot/dts/aspeed-g4.dtsi b/arch/arm/boot/dts/aspeed-g4.dtsi
> index f606fc01ff13..2364b660f2e4 100644
> --- a/arch/arm/boot/dts/aspeed-g4.dtsi
> +++ b/arch/arm/boot/dts/aspeed-g4.dtsi
> @@ -370,6 +370,7 @@ lpc_snoop: lpc-snoop@10 {
>                                                 compatible = "aspeed,ast2400-lpc-snoop";
>                                                 reg = <0x10 0x8>;
>                                                 interrupts = <8>;
> +                                               clocks = <&syscon ASPEED_CLK_GATE_LCLK>;
>                                                 status = "disabled";
>                                         };
>
> diff --git a/arch/arm/boot/dts/aspeed-g5.dtsi b/arch/arm/boot/dts/aspeed-g5.dtsi
> index 19288495f41a..30bbf7452b90 100644
> --- a/arch/arm/boot/dts/aspeed-g5.dtsi
> +++ b/arch/arm/boot/dts/aspeed-g5.dtsi
> @@ -496,6 +496,7 @@ lpc_snoop: lpc-snoop@10 {
>                                                 compatible = "aspeed,ast2500-lpc-snoop";
>                                                 reg = <0x10 0x8>;
>                                                 interrupts = <8>;
> +                                               clocks = <&syscon ASPEED_CLK_GATE_LCLK>;
>                                                 status = "disabled";
>                                         };
>
> diff --git a/arch/arm/boot/dts/aspeed-g6.dtsi b/arch/arm/boot/dts/aspeed-g6.dtsi
> index 97ca743363d7..4b1013870fb1 100644
> --- a/arch/arm/boot/dts/aspeed-g6.dtsi
> +++ b/arch/arm/boot/dts/aspeed-g6.dtsi
> @@ -520,6 +520,7 @@ lpc_snoop: lpc-snoop@0 {
>                                                 compatible = "aspeed,ast2600-lpc-snoop";
>                                                 reg = <0x0 0x80>;
>                                                 interrupts = <GIC_SPI 144 IRQ_TYPE_LEVEL_HIGH>;
> +                                               clocks = <&syscon ASPEED_CLK_GATE_LCLK>;
>                                                 status = "disabled";
>                                         };
>
> --
> 2.25.1
>

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

* Re: [External] Re: [PATCH 1/2] misc: Add clock control logic into Aspeed LPC SNOOP driver
  2020-12-08  2:19 ` [PATCH 1/2] misc: Add clock control logic into Aspeed LPC SNOOP driver Joel Stanley
@ 2020-12-08  9:06   ` John Wang
  0 siblings, 0 replies; 5+ messages in thread
From: John Wang @ 2020-12-08  9:06 UTC (permalink / raw)
  To: Joel Stanley
  Cc: Lotus Xu, 郁雷,
	Jae Hyun Yoo, Vernon Mauery, Andrew Jeffery,
	moderated list:ARM/ASPEED MACHINE SUPPORT,
	moderated list:ARM/ASPEED MACHINE SUPPORT, open list

On Tue, Dec 8, 2020 at 10:19 AM Joel Stanley <joel@jms.id.au> wrote:
>
> On Wed, 2 Dec 2020 at 05:16, John Wang <wangzhiqiang.bj@bytedance.com> wrote:
> >
> > From: Jae Hyun Yoo <jae.hyun.yoo@intel.com>
> >
> > If LPC SNOOP driver is registered ahead of lpc-ctrl module, LPC
> > SNOOP block will be enabled without heart beating of LCLK until
> > lpc-ctrl enables the LCLK. This issue causes improper handling on
> > host interrupts when the host sends interrupt in that time frame.
> > Then kernel eventually forcibly disables the interrupt with
> > dumping stack and printing a 'nobody cared this irq' message out.
> >
> > To prevent this issue, all LPC sub-nodes should enable LCLK
> > individually so this patch adds clock control logic into the LPC
> > SNOOP driver.
> >
> > Signed-off-by: Jae Hyun Yoo <jae.hyun.yoo@intel.com>
> > Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
> > Signed-off-by: John Wang <wangzhiqiang.bj@bytedance.com>
>
> Reviewed-by: Joel Stanley <joel@jms.id.au>
>
> Thanks for sending these John. It is an excellent idea to upstream
> fixes that have been developed.
>
> I assume we will have the same issue for all devices that use the LPC
> bus? eg. vuart, bt, kcs, lpc2ahb? It looks like only the lpc-ctrl
> (lpc2ahb) does this so far:

ok that's on my todo list.  :)

>
> git grep -l clk drivers/soc/aspeed/aspeed-p2a-ctrl.c
> drivers/soc/aspeed/aspeed-lpc-ctrl.c
> drivers/char/ipmi/kcs_bmc_aspeed.c drivers/char/ipmi/bt-bmc.c
> drivers/soc/aspeed/aspeed-lpc-ctrl.c
>
>
>
>
> > ---
> >  drivers/soc/aspeed/aspeed-lpc-snoop.c | 30 ++++++++++++++++++++++++---
> >  1 file changed, 27 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/soc/aspeed/aspeed-lpc-snoop.c b/drivers/soc/aspeed/aspeed-lpc-snoop.c
> > index 682ba0eb4eba..20acac6342ef 100644
> > --- a/drivers/soc/aspeed/aspeed-lpc-snoop.c
> > +++ b/drivers/soc/aspeed/aspeed-lpc-snoop.c
> > @@ -11,6 +11,7 @@
> >   */
> >
> >  #include <linux/bitops.h>
> > +#include <linux/clk.h>
> >  #include <linux/interrupt.h>
> >  #include <linux/fs.h>
> >  #include <linux/kfifo.h>
> > @@ -67,6 +68,7 @@ struct aspeed_lpc_snoop_channel {
> >  struct aspeed_lpc_snoop {
> >         struct regmap           *regmap;
> >         int                     irq;
> > +       struct clk              *clk;
> >         struct aspeed_lpc_snoop_channel chan[NUM_SNOOP_CHANNELS];
> >  };
> >
> > @@ -282,22 +284,42 @@ static int aspeed_lpc_snoop_probe(struct platform_device *pdev)
> >                 return -ENODEV;
> >         }
> >
> > +       lpc_snoop->clk = devm_clk_get(dev, NULL);
> > +       if (IS_ERR(lpc_snoop->clk)) {
> > +               rc = PTR_ERR(lpc_snoop->clk);
> > +               if (rc != -EPROBE_DEFER)
> > +                       dev_err(dev, "couldn't get clock\n");
> > +               return rc;
> > +       }
> > +       rc = clk_prepare_enable(lpc_snoop->clk);
> > +       if (rc) {
> > +               dev_err(dev, "couldn't enable clock\n");
> > +               return rc;
> > +       }
> > +
> >         rc = aspeed_lpc_snoop_config_irq(lpc_snoop, pdev);
> >         if (rc)
> > -               return rc;
> > +               goto err;
> >
> >         rc = aspeed_lpc_enable_snoop(lpc_snoop, dev, 0, port);
> >         if (rc)
> > -               return rc;
> > +               goto err;
> >
> >         /* Configuration of 2nd snoop channel port is optional */
> >         if (of_property_read_u32_index(dev->of_node, "snoop-ports",
> >                                        1, &port) == 0) {
> >                 rc = aspeed_lpc_enable_snoop(lpc_snoop, dev, 1, port);
> > -               if (rc)
> > +               if (rc) {
> >                         aspeed_lpc_disable_snoop(lpc_snoop, 0);
> > +                       goto err;
> > +               }
> >         }
> >
> > +       return 0;
> > +
> > +err:
> > +       clk_disable_unprepare(lpc_snoop->clk);
> > +
> >         return rc;
> >  }
> >
> > @@ -309,6 +331,8 @@ static int aspeed_lpc_snoop_remove(struct platform_device *pdev)
> >         aspeed_lpc_disable_snoop(lpc_snoop, 0);
> >         aspeed_lpc_disable_snoop(lpc_snoop, 1);
> >
> > +       clk_disable_unprepare(lpc_snoop->clk);
> > +
> >         return 0;
> >  }
> >
> > --
> > 2.25.1
> >

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

end of thread, other threads:[~2020-12-08  9:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-02  5:16 [PATCH 1/2] misc: Add clock control logic into Aspeed LPC SNOOP driver John Wang
2020-12-02  5:16 ` [PATCH 2/2] ARM: dts: aspeed: Add LCLK to lpc-snoop John Wang
2020-12-08  2:20   ` Joel Stanley
2020-12-08  2:19 ` [PATCH 1/2] misc: Add clock control logic into Aspeed LPC SNOOP driver Joel Stanley
2020-12-08  9:06   ` [External] " John Wang

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