If there is an unhandled KCS/BPC pending interrupt after reboot,
the KCS/BPC Linux driver may trigger interrupts immediately upon
registering the irq. However, since the driver is not yet initialized
to handle them, this can lead to unexpected behavior.

To prevent this, disable KCS/BPC interrupts in u-boot to avoid pending
interrupts from being raised before the Linux driver is fully initialized.

Signed-off-by: Stanley Chu <ys...@nuvoton.com>
Signed-off-by: Jim Liu <jjl...@nuvoton.com>
---
 arch/arm/dts/nuvoton-common-npcm8xx.dtsi |  2 +-
 drivers/misc/npcm_host_intf.c            | 21 ++++++++++++++++++++-
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/arch/arm/dts/nuvoton-common-npcm8xx.dtsi 
b/arch/arm/dts/nuvoton-common-npcm8xx.dtsi
index be06b2a0cae..6866005336f 100644
--- a/arch/arm/dts/nuvoton-common-npcm8xx.dtsi
+++ b/arch/arm/dts/nuvoton-common-npcm8xx.dtsi
@@ -141,7 +141,7 @@
 
                        host_intf: host_intf@9f000 {
                                compatible = "nuvoton,npcm845-host-intf";
-                               reg = <0x9f000 0x1000>;
+                               reg = <0x9f000 0x1000>, <0x7000 0x40>;
                                type = "espi";
                                ioaddr = <0x4e>;
                                channel-support = <0xf>;
diff --git a/drivers/misc/npcm_host_intf.c b/drivers/misc/npcm_host_intf.c
index 2c89bd7a167..e3b0663625b 100644
--- a/drivers/misc/npcm_host_intf.c
+++ b/drivers/misc/npcm_host_intf.c
@@ -45,10 +45,20 @@
 #define ESPI_TEN_ENABLE                0x55
 #define ESPI_TEN_DISABLE       0
 
+/* KCS/BPC interrupt control */
+#define BPCFEN                 0x46
+#define FRIE                   BIT(3)
+#define HRIE                   BIT(4)
+#define KCS1CTL                        0x18
+#define KCS2CTL                        0x2a
+#define KCS3CTL                        0x3c
+#define IBFIE                  BIT(0)
+#define OBEIE                  BIT(1)
+
 static int npcm_host_intf_bind(struct udevice *dev)
 {
        struct regmap *syscon;
-       void __iomem *base;
+       void __iomem *base, *kcs_base;
        u32 ch_supp, val;
        u32 ioaddr;
        const char *type;
@@ -104,6 +114,15 @@ static int npcm_host_intf_bind(struct udevice *dev)
        /* Release host wait */
        setbits_8(SMC_CTL_REG_ADDR, SMC_CTL_HOSTWAIT);
 
+       kcs_base = dev_read_addr_index_ptr(dev, 1);
+       if (kcs_base) {
+               /* Disable KCS/BPC interrupts */
+               clrbits_8(kcs_base + BPCFEN, FRIE | HRIE);
+               clrbits_8(kcs_base + KCS1CTL, IBFIE | OBEIE);
+               clrbits_8(kcs_base + KCS2CTL, IBFIE | OBEIE);
+               clrbits_8(kcs_base + KCS3CTL, IBFIE | OBEIE);
+       }
+
        return 0;
 }
 
-- 
2.34.1

Reply via email to