* [PATCH v2 1/3] dt-bindings: mfd: Add StarFive JHB100 SuperIO
2026-12-04 6:06 [PATCH v2 0/3] Add StarFive JHB100 SuperIO and KCS BMC drivers Mason Huo
@ 2026-12-04 6:06 ` Mason Huo
2026-12-04 6:06 ` [PATCH v2 2/3] mfd: Add StarFive JHB100 SuperIO driver Mason Huo
2026-12-04 6:06 ` [PATCH v2 3/3] ipmi: Add StarFive KCS BMC driver Mason Huo
2 siblings, 0 replies; 5+ messages in thread
From: Mason Huo @ 2026-12-04 6:06 UTC (permalink / raw)
To: Lee Jones, Corey Minyard, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: mfd, linux-kernel, devicetree, openipmi-developer, Mason Huo
The StarFive JHB100 BMC SoC has one SuperIO (SIO) block per eSPI
controller, which the host accesses over the eSPI bus. Each block
provides two IPMI Block Transfer (BT) channels, four IPMI Keyboard
Controller Style (KCS) channels, a mailbox, a Post Code Capture (PCC)
unit and a watchdog interface in a single register window. Every
function has its own interrupt, and one more interrupt signals the
de-assertion of the eSPI bus reset.
The layout of the block is fixed, so describe it as a single node. Its
driver instantiates the functions.
Signed-off-by: Mason Huo <mason.huo@starfivetech.com>
---
.../bindings/mfd/starfive,jhb100-sio.yaml | 75 +++++++++++++++++++
1 file changed, 75 insertions(+)
create mode 100644 Documentation/devicetree/bindings/mfd/starfive,jhb100-sio.yaml
diff --git a/Documentation/devicetree/bindings/mfd/starfive,jhb100-sio.yaml b/Documentation/devicetree/bindings/mfd/starfive,jhb100-sio.yaml
new file mode 100644
index 000000000000..dd618206bfe2
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/starfive,jhb100-sio.yaml
@@ -0,0 +1,75 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/starfive,jhb100-sio.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: StarFive JHB100 SuperIO Controller
+
+maintainers:
+ - Mason Huo <mason.huo@starfivetech.com>
+
+description:
+ The JHB100 BMC SoC has one SuperIO (SIO) block per eSPI controller, which
+ the host accesses over the eSPI bus. Each block provides several host
+ facing functions in a single register window, two IPMI Block Transfer (BT)
+ channels, four IPMI Keyboard Controller Style (KCS) channels, a mailbox, a
+ Post Code Capture (PCC) unit, which snoops the writes of the host to I/O
+ port 0x80, and a watchdog interface, each with its own interrupt.
+
+properties:
+ compatible:
+ const: starfive,jhb100-sio
+
+ reg:
+ maxItems: 1
+
+ interrupts:
+ items:
+ - description: BT channel 0 interrupt
+ - description: BT channel 1 interrupt
+ - description: KCS channel 0 interrupt
+ - description: KCS channel 1 interrupt
+ - description: KCS channel 2 interrupt
+ - description: KCS channel 3 interrupt
+ - description: Mailbox interrupt
+ - description: Post Code Capture interrupt
+ - description: Watchdog interface interrupt
+ - description: eSPI bus reset de-assertion interrupt
+
+ interrupt-names:
+ items:
+ - const: bt0
+ - const: bt1
+ - const: kcs0
+ - const: kcs1
+ - const: kcs2
+ - const: kcs3
+ - const: mbox
+ - const: pcc
+ - const: wdi
+ - const: espi
+
+required:
+ - compatible
+ - reg
+ - interrupts
+ - interrupt-names
+
+additionalProperties: false
+
+examples:
+ - |
+ soc {
+ #address-cells = <2>;
+ #size-cells = <2>;
+
+ superio@10582000 {
+ compatible = "starfive,jhb100-sio";
+ reg = <0x0 0x10582000 0x0 0x1000>;
+ interrupts = <280>, <281>, <282>, <283>, <284>, <285>, <286>,
+ <287>, <288>, <57>;
+ interrupt-names = "bt0", "bt1", "kcs0", "kcs1", "kcs2", "kcs3",
+ "mbox", "pcc", "wdi", "espi";
+ };
+ };
--
2.50.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v2 2/3] mfd: Add StarFive JHB100 SuperIO driver
2026-12-04 6:06 [PATCH v2 0/3] Add StarFive JHB100 SuperIO and KCS BMC drivers Mason Huo
2026-12-04 6:06 ` [PATCH v2 1/3] dt-bindings: mfd: Add StarFive JHB100 SuperIO Mason Huo
@ 2026-12-04 6:06 ` Mason Huo
2026-12-04 8:30 ` Uwe Kleine-König
2026-12-04 6:06 ` [PATCH v2 3/3] ipmi: Add StarFive KCS BMC driver Mason Huo
2 siblings, 1 reply; 5+ messages in thread
From: Mason Huo @ 2026-12-04 6:06 UTC (permalink / raw)
To: Lee Jones, Corey Minyard, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: mfd, linux-kernel, devicetree, openipmi-developer, Mason Huo
Add a driver for the SuperIO (SIO) blocks of the StarFive JHB100 BMC SoC.
It registers the functions of a block as MFD cells, for now the four
IPMI KCS channels.
Every instance of a function occupies a 0x100 byte register window of
the block. Each cell gets its window as a memory resource, which its
driver maps. The cells carry no interrupt resources, the driver of a
function looks up its interrupts in the SIO node by name. The functions
are described by a table, so adding the remaining ones only takes their
cells and an entry each.
The instances of a function in all SIO blocks are numbered
consecutively, so the platform device id of a KCS cell is its channel
number. The index of an SIO block follows from its address.
Signed-off-by: Mason Huo <mason.huo@starfivetech.com>
---
MAINTAINERS | 6 ++
drivers/mfd/Kconfig | 13 +++
drivers/mfd/Makefile | 1 +
drivers/mfd/starfive-jhb100-sio.c | 167 ++++++++++++++++++++++++++++++
4 files changed, 187 insertions(+)
create mode 100644 drivers/mfd/starfive-jhb100-sio.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 67ed5e45b61d..53ee9b601dcb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -26834,6 +26834,12 @@ M: Changhuang Liang <changhuang.liang@starfivetech.com>
S: Maintained
F: drivers/soc/starfive/socinfo/jhb100-socinfo.c
+STARFIVE JHB100 SUPERIO DRIVER
+M: Mason Huo <mason.huo@starfivetech.com>
+S: Supported
+F: Documentation/devicetree/bindings/mfd/starfive,jhb100-sio.yaml
+F: drivers/mfd/starfive-jhb100-sio.c
+
STATIC BRANCH/CALL
M: Peter Zijlstra <peterz@infradead.org>
M: Josh Poimboeuf <jpoimboe@kernel.org>
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 0a2778052519..3ffa1c2ed81e 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1633,6 +1633,19 @@ config STMPE_SPI
This is used to enable SPI interface of STMPE
endmenu
+config MFD_STARFIVE_JHB100_SIO
+ tristate "StarFive JHB100 SuperIO"
+ depends on ARCH_STARFIVE || COMPILE_TEST
+ select MFD_CORE
+ help
+ Support for the SuperIO (SIO) blocks of the StarFive JHB100 BMC SoC.
+ The host accesses them over the eSPI bus. This driver registers the
+ functions of each block, e.g. the IPMI KCS channels, which are
+ handled by their own drivers.
+
+ This support is also available as a module. If so, the module
+ will be called starfive-jhb100-sio.
+
config MFD_SUN6I_PRCM
bool "Allwinner A31/A23/A33 PRCM controller"
depends on ARCH_SUNXI || COMPILE_TEST
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 72d3944b0ad8..d4a680fe0e51 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -267,6 +267,7 @@ obj-$(CONFIG_MFD_ALTERA_A10SR) += altera-a10sr.o
obj-$(CONFIG_MFD_ALTERA_SYSMGR) += altera-sysmgr.o
obj-$(CONFIG_MFD_STPMIC1) += stpmic1.o
obj-$(CONFIG_MFD_SUN4I_GPADC) += sun4i-gpadc.o
+obj-$(CONFIG_MFD_STARFIVE_JHB100_SIO) += starfive-jhb100-sio.o
obj-$(CONFIG_MFD_STM32_LPTIMER) += stm32-lptimer.o
obj-$(CONFIG_MFD_STM32_TIMERS) += stm32-timers.o
diff --git a/drivers/mfd/starfive-jhb100-sio.c b/drivers/mfd/starfive-jhb100-sio.c
new file mode 100644
index 000000000000..7efc9135705a
--- /dev/null
+++ b/drivers/mfd/starfive-jhb100-sio.c
@@ -0,0 +1,167 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * StarFive JHB100 SuperIO (SIO) driver
+ *
+ * Copyright (C) 2026 StarFive Technology Co., Ltd.
+ */
+
+#include <linux/array_size.h>
+#include <linux/err.h>
+#include <linux/ioport.h>
+#include <linux/mfd/core.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+
+#define JHB100_SIO_SIZE 0x1000
+
+/* Every instance of a function occupies a register window of this size */
+#define JHB100_SIO_FUNC_SIZE 0x100
+
+/*
+ * The cells only carry the register window of their instance. The interrupts
+ * are those of the SIO node, the driver of a function looks them up there by
+ * name: its own one, followed by the id of the cell if the block has more than
+ * one instance of the function, and "espi", the eSPI bus reset interrupt, which
+ * all functions of the block share.
+ */
+static const struct resource jhb100_sio_kcs0_resources[] = {
+ DEFINE_RES_MEM(0x200, JHB100_SIO_FUNC_SIZE),
+};
+
+static const struct resource jhb100_sio_kcs1_resources[] = {
+ DEFINE_RES_MEM(0x300, JHB100_SIO_FUNC_SIZE),
+};
+
+static const struct resource jhb100_sio_kcs2_resources[] = {
+ DEFINE_RES_MEM(0x400, JHB100_SIO_FUNC_SIZE),
+};
+
+static const struct resource jhb100_sio_kcs3_resources[] = {
+ DEFINE_RES_MEM(0x500, JHB100_SIO_FUNC_SIZE),
+};
+
+static const struct mfd_cell jhb100_sio_kcs_cells[] = {
+ MFD_CELL_BASIC("starfive-kcs-bmc", jhb100_sio_kcs0_resources, NULL, 0, 0),
+ MFD_CELL_BASIC("starfive-kcs-bmc", jhb100_sio_kcs1_resources, NULL, 0, 1),
+ MFD_CELL_BASIC("starfive-kcs-bmc", jhb100_sio_kcs2_resources, NULL, 0, 2),
+ MFD_CELL_BASIC("starfive-kcs-bmc", jhb100_sio_kcs3_resources, NULL, 0, 3),
+};
+
+/**
+ * struct jhb100_sio_func - a function of the SIO block
+ * @cells: MFD cells of the instances of the function in an SIO block
+ * @num_cells: number of entries in @cells
+ *
+ * The instances of a function in all SIO blocks are numbered consecutively,
+ * so the platform device id of a cell is the system wide instance number,
+ * e.g. the KCS channel number.
+ */
+struct jhb100_sio_func {
+ const struct mfd_cell *cells;
+ unsigned int num_cells;
+};
+
+/* Only the KCS channels are supported so far */
+static const struct jhb100_sio_func jhb100_sio_funcs[] = {
+ { jhb100_sio_kcs_cells, ARRAY_SIZE(jhb100_sio_kcs_cells) },
+};
+
+/**
+ * struct jhb100_sio_soc_data - SoC specific description of the SIO blocks
+ * @bases: base addresses of the SIO blocks of the SoC
+ * @num_bases: number of entries in @bases
+ */
+struct jhb100_sio_soc_data {
+ const resource_size_t *bases;
+ unsigned int num_bases;
+};
+
+/*
+ * The index of an SIO block is not described in the devicetree, it follows
+ * from the address of the block.
+ */
+static int jhb100_sio_get_index(struct device *dev, resource_size_t start,
+ unsigned int *index)
+{
+ const struct jhb100_sio_soc_data *data;
+ unsigned int i;
+
+ data = device_get_match_data(dev);
+ if (!data)
+ return -ENODEV;
+
+ for (i = 0; i < data->num_bases; i++) {
+ if (data->bases[i] == start) {
+ *index = i;
+ return 0;
+ }
+ }
+
+ return -EINVAL;
+}
+
+static int jhb100_sio_probe(struct platform_device *pdev)
+{
+ const struct jhb100_sio_func *func;
+ struct device *dev = &pdev->dev;
+ unsigned int index, i;
+ struct resource *mem;
+ int rc;
+
+ /*
+ * The registers are not mapped here, the driver of each function maps
+ * the register window of its instance.
+ */
+ mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!mem || resource_size(mem) < JHB100_SIO_SIZE)
+ return dev_err_probe(dev, -EINVAL, "Invalid register window\n");
+
+ rc = jhb100_sio_get_index(dev, mem->start, &index);
+ if (rc)
+ return dev_err_probe(dev, rc, "Unknown SIO block %pR\n", mem);
+
+ for (i = 0; i < ARRAY_SIZE(jhb100_sio_funcs); i++) {
+ func = &jhb100_sio_funcs[i];
+
+ rc = devm_mfd_add_devices(dev, index * func->num_cells,
+ func->cells, func->num_cells, mem, 0,
+ NULL);
+ if (rc)
+ return dev_err_probe(dev, rc, "Failed to add %s devices\n",
+ func->cells->name);
+ }
+
+ return 0;
+}
+
+static const resource_size_t jhb100_sio_bases[] = {
+ 0x10582000,
+ 0x10d82000,
+};
+
+static const struct jhb100_sio_soc_data jhb100_sio_soc_data = {
+ .bases = jhb100_sio_bases,
+ .num_bases = ARRAY_SIZE(jhb100_sio_bases),
+};
+
+static const struct of_device_id jhb100_sio_match[] = {
+ { .compatible = "starfive,jhb100-sio", .data = &jhb100_sio_soc_data },
+ { }
+};
+MODULE_DEVICE_TABLE(of, jhb100_sio_match);
+
+static struct platform_driver jhb100_sio_driver = {
+ .driver = {
+ .name = "starfive-jhb100-sio",
+ .of_match_table = jhb100_sio_match,
+ .suppress_bind_attrs = true,
+ },
+ .probe = jhb100_sio_probe,
+};
+module_platform_driver(jhb100_sio_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mason Huo <mason.huo@starfivetech.com>");
+MODULE_DESCRIPTION("StarFive JHB100 SuperIO driver");
--
2.50.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v2 2/3] mfd: Add StarFive JHB100 SuperIO driver
2026-12-04 6:06 ` [PATCH v2 2/3] mfd: Add StarFive JHB100 SuperIO driver Mason Huo
@ 2026-12-04 8:30 ` Uwe Kleine-König
0 siblings, 0 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2026-12-04 8:30 UTC (permalink / raw)
To: Mason Huo
Cc: Lee Jones, Corey Minyard, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, mfd, linux-kernel, devicetree, openipmi-developer
[-- Attachment #1: Type: text/plain, Size: 417 bytes --]
Hello,
On Fri, Dec 04, 2026 at 02:06:22PM +0800, Mason Huo wrote:
> +#include <linux/mod_devicetable.h>
> [...]
> +#include <linux/platform_device.h>
Please don't include <linux/mod_devicetable.h> which introduces many
unneeded definitions and thus unneeded build dependencies.
<linux/platform_device.h> already gives you of_device_id, so you should
be set to just drop <linux/mod_devicetable.h>.
Best regards
Uwe
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 3/3] ipmi: Add StarFive KCS BMC driver
2026-12-04 6:06 [PATCH v2 0/3] Add StarFive JHB100 SuperIO and KCS BMC drivers Mason Huo
2026-12-04 6:06 ` [PATCH v2 1/3] dt-bindings: mfd: Add StarFive JHB100 SuperIO Mason Huo
2026-12-04 6:06 ` [PATCH v2 2/3] mfd: Add StarFive JHB100 SuperIO driver Mason Huo
@ 2026-12-04 6:06 ` Mason Huo
2 siblings, 0 replies; 5+ messages in thread
From: Mason Huo @ 2026-12-04 6:06 UTC (permalink / raw)
To: Lee Jones, Corey Minyard, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: mfd, linux-kernel, devicetree, openipmi-developer, Mason Huo
This driver exposes the Keyboard Controller Style (KCS) interface on
StarFive SoCs as a character device. Such SOCs are commonly used
as a BaseBoard Management Controller (BMC) on a server board, and KCS
interface is commonly used to perform the in-band IPMI communication
between the server and its BMC.
Signed-off-by: Mason Huo <mason.huo@starfivetech.com>
---
MAINTAINERS | 5 +
drivers/char/ipmi/Kconfig | 16 ++
drivers/char/ipmi/Makefile | 1 +
drivers/char/ipmi/kcs_bmc_starfive.c | 281 +++++++++++++++++++++++++++
4 files changed, 303 insertions(+)
create mode 100644 drivers/char/ipmi/kcs_bmc_starfive.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 53ee9b601dcb..b1e02a7fa6e5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -26815,6 +26815,11 @@ S: Supported
F: Documentation/devicetree/bindings/interrupt-controller/starfive,jhb100-intc.yaml
F: drivers/irqchip/irq-starfive-jhb100-intc.c
+STARFIVE JHB100 KCS-BMC DRIVER
+M: Mason Huo <mason.huo@starfivetech.com>
+S: Supported
+F: drivers/char/ipmi/kcs_bmc_starfive.c
+
STARFIVE JHB100 PINCTRL DRIVERS
M: Changhuang Liang <changhuang.liang@starfivetech.com>
M: Lianfeng Ouyang <lianfeng.ouyang@starfivetech.com>
diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index 538a7d3c65bf..118f901a4e28 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -149,6 +149,22 @@ config NPCM7XX_KCS_IPMI_BMC
This support is also available as a module. If so, the module
will be called kcs_bmc_npcm7xx.
+config STARFIVE_KCS_IPMI_BMC
+ depends on MFD_STARFIVE_JHB100_SIO || COMPILE_TEST
+ depends on HAS_IOMEM
+ select IPMI_KCS_BMC
+ select REGMAP_MMIO
+ tristate "StarFive KCS IPMI BMC driver"
+ help
+ Provides a driver for the KCS (Keyboard Controller Style) IPMI
+ interface found on StarFive SoCs.
+
+ The driver implements the BMC side of the KCS controller, it
+ provides the access of KCS IO space for BMC side.
+
+ This support is also available as a module. If so, the module
+ will be called kcs_bmc_starfive.
+
config IPMI_KCS_BMC_CDEV_IPMI
depends on IPMI_KCS_BMC
tristate "IPMI character device interface for BMC KCS devices"
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index 4ea450a82242..800d570dd4dc 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -27,5 +27,6 @@ obj-$(CONFIG_IPMI_KCS_BMC_CDEV_IPMI) += kcs_bmc_cdev_ipmi.o
obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
obj-$(CONFIG_ASPEED_KCS_IPMI_BMC) += kcs_bmc_aspeed.o
obj-$(CONFIG_NPCM7XX_KCS_IPMI_BMC) += kcs_bmc_npcm7xx.o
+obj-$(CONFIG_STARFIVE_KCS_IPMI_BMC) += kcs_bmc_starfive.o
obj-$(CONFIG_IPMB_DEVICE_INTERFACE) += ipmb_dev_int.o
obj-$(CONFIG_SSIF_IPMI_BMC) += ssif_bmc.o
diff --git a/drivers/char/ipmi/kcs_bmc_starfive.c b/drivers/char/ipmi/kcs_bmc_starfive.c
new file mode 100644
index 000000000000..51ddf474a382
--- /dev/null
+++ b/drivers/char/ipmi/kcs_bmc_starfive.c
@@ -0,0 +1,281 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 StarFive Technology Co., Ltd.
+ */
+
+#include <linux/bits.h>
+#include <linux/errno.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/mfd/core.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/spinlock.h>
+#include <linux/sprintf.h>
+
+#include "kcs_bmc_device.h"
+
+#define DEVICE_NAME "starfive-kcs-bmc"
+
+/* Register offsets in the register window of a channel */
+#define KCS_DO 0x0
+#define KCS_DI 0x4
+#define KCS_STS 0x8
+
+#define KCS_INT 0xc
+#define KCS_INT_IBF_EN BIT(0)
+#define KCS_INT_IBF_STS BIT(1)
+
+struct starfive_kcs_bmc {
+ struct kcs_bmc_device kcs_bmc;
+ struct regmap *map;
+ /* Protects ie_en and serialises every write to KCS_INT */
+ spinlock_t ie_lock;
+ /* Shadow of the KCS_INT enable bits, restored after eSPI bus reset */
+ u32 ie_en;
+};
+
+static inline struct starfive_kcs_bmc *
+to_starfive_kcs_bmc(struct kcs_bmc_device *kcs_bmc)
+{
+ return container_of(kcs_bmc, struct starfive_kcs_bmc, kcs_bmc);
+}
+
+static u8 starfive_kcs_inb(struct kcs_bmc_device *kcs_bmc, u32 reg)
+{
+ struct starfive_kcs_bmc *priv = to_starfive_kcs_bmc(kcs_bmc);
+ u32 val = 0;
+ int rc;
+
+ rc = regmap_read(priv->map, reg, &val);
+ WARN(rc != 0, "regmap_read() failed: %d\n", rc);
+
+ return rc == 0 ? (u8)val : 0;
+}
+
+static void starfive_kcs_outb(struct kcs_bmc_device *kcs_bmc, u32 reg, u8 data)
+{
+ struct starfive_kcs_bmc *priv = to_starfive_kcs_bmc(kcs_bmc);
+ int rc;
+
+ rc = regmap_write(priv->map, reg, data);
+ WARN(rc != 0, "regmap_write() failed: %d\n", rc);
+}
+
+static void starfive_kcs_updateb(struct kcs_bmc_device *kcs_bmc,
+ u32 reg, u8 mask, u8 data)
+{
+ struct starfive_kcs_bmc *priv = to_starfive_kcs_bmc(kcs_bmc);
+ int rc;
+
+ rc = regmap_update_bits(priv->map, reg, mask, data);
+ WARN(rc != 0, "regmap_update_bits() failed: %d\n", rc);
+}
+
+/*
+ * Write the shadow of the enable bits to KCS_INT. KCS_INT_IBF_STS is a
+ * read-only mirror of the IBF flag in KCS_STS, which the hardware clears
+ * once KCS_DI has been read, so only the enable bits are ever written.
+ */
+static void starfive_kcs_write_ie(struct starfive_kcs_bmc *priv)
+{
+ int rc;
+
+ lockdep_assert_held(&priv->ie_lock);
+
+ rc = regmap_write(priv->map, KCS_INT, priv->ie_en);
+ WARN(rc != 0, "regmap_write() failed: %d\n", rc);
+}
+
+static void starfive_kcs_irq_mask_update(struct kcs_bmc_device *kcs_bmc,
+ u8 mask, u8 state)
+{
+ struct starfive_kcs_bmc *priv = to_starfive_kcs_bmc(kcs_bmc);
+ unsigned long flags;
+
+ /* The hardware has no OBE interrupt */
+ if (!(mask & KCS_BMC_EVENT_TYPE_IBF))
+ return;
+
+ spin_lock_irqsave(&priv->ie_lock, flags);
+ if (state & KCS_BMC_EVENT_TYPE_IBF)
+ priv->ie_en |= KCS_INT_IBF_EN;
+ else
+ priv->ie_en &= ~KCS_INT_IBF_EN;
+ starfive_kcs_write_ie(priv);
+ spin_unlock_irqrestore(&priv->ie_lock, flags);
+}
+
+static void starfive_kcs_hw_init(struct starfive_kcs_bmc *priv)
+{
+ unsigned long flags;
+
+ /* Restore the enables, e.g. after an eSPI bus reset */
+ spin_lock_irqsave(&priv->ie_lock, flags);
+ starfive_kcs_write_ie(priv);
+ spin_unlock_irqrestore(&priv->ie_lock, flags);
+}
+
+static irqreturn_t starfive_kcs_irq(int irq, void *arg)
+{
+ /* The interrupt deasserts once the client has read IDR */
+ return kcs_bmc_handle_event(arg);
+}
+
+/*
+ * "espi" is a dedicated interrupt line which carries a single event: the
+ * host has de-asserted the eSPI bus reset of the SIO block this channel
+ * belongs to. The line is requested with IRQF_SHARED only because every
+ * function of that SIO block (KCS, BT, mailbox, ...) listens to the same
+ * event and has to reprogram its own registers when it fires. It is not
+ * shared with unrelated interrupt sources and there is no per-function
+ * status bit to test, so each occurrence is relevant to all handlers and is
+ * claimed unconditionally. Rewriting KCS_INT from the shadow is idempotent.
+ */
+static irqreturn_t starfive_espi_rst_deassert_irq(int irq, void *arg)
+{
+ struct kcs_bmc_device *kcs_bmc = arg;
+ struct starfive_kcs_bmc *priv = to_starfive_kcs_bmc(kcs_bmc);
+
+ starfive_kcs_hw_init(priv);
+
+ return IRQ_HANDLED;
+}
+
+/*
+ * The cells of the SIO driver have no interrupt resources. The interrupts are
+ * those of the SIO block: "kcs<n>" for channel <n> of the block, which is the
+ * id of the cell, and "espi".
+ */
+static int starfive_kcs_config_irq(struct kcs_bmc_device *kcs_bmc,
+ struct platform_device *pdev)
+{
+ struct platform_device *sio = to_platform_device(pdev->dev.parent);
+ const struct mfd_cell *cell = mfd_get_cell(pdev);
+ struct device *dev = &pdev->dev;
+ char name[16];
+ int rc, irq;
+
+ if (!cell)
+ return -ENODEV;
+
+ snprintf(name, sizeof(name), "kcs%d", cell->id);
+ irq = platform_get_irq_byname(sio, name);
+ if (irq < 0)
+ return irq;
+
+ rc = devm_request_irq(dev, irq, starfive_kcs_irq, 0,
+ dev_name(dev), kcs_bmc);
+ if (rc < 0)
+ return dev_err_probe(dev, rc,
+ "Unable to request kcs IRQ %d\n", irq);
+
+ irq = platform_get_irq_byname(sio, "espi");
+ if (irq < 0)
+ return irq;
+
+ rc = devm_request_irq(dev, irq, starfive_espi_rst_deassert_irq,
+ IRQF_SHARED | IRQF_TRIGGER_RISING,
+ dev_name(dev), kcs_bmc);
+ if (rc < 0)
+ return dev_err_probe(dev, rc,
+ "Unable to request espi reset IRQ %d\n", irq);
+
+ return 0;
+}
+
+static const struct regmap_config starfive_kcs_regmap_config = {
+ .reg_bits = 32,
+ .val_bits = 32,
+ .reg_stride = 4,
+ .max_register = KCS_INT,
+};
+
+static const struct kcs_bmc_device_ops starfive_kcs_ops = {
+ .irq_mask_update = starfive_kcs_irq_mask_update,
+ .io_inputb = starfive_kcs_inb,
+ .io_outputb = starfive_kcs_outb,
+ .io_updateb = starfive_kcs_updateb,
+};
+
+static int starfive_kcs_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct starfive_kcs_bmc *priv;
+ struct kcs_bmc_device *kcs_bmc;
+ void __iomem *base;
+ int rc;
+
+ if (pdev->id < 0)
+ return dev_err_probe(dev, -EINVAL, "Unable to determine the channel\n");
+
+ priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+ if (!priv)
+ return -ENOMEM;
+
+ spin_lock_init(&priv->ie_lock);
+
+ base = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(base))
+ return PTR_ERR(base);
+
+ priv->map = devm_regmap_init_mmio(dev, base, &starfive_kcs_regmap_config);
+ if (IS_ERR(priv->map))
+ return dev_err_probe(dev, PTR_ERR(priv->map),
+ "Couldn't create regmap\n");
+
+ kcs_bmc = &priv->kcs_bmc;
+ kcs_bmc->dev = dev;
+ kcs_bmc->channel = pdev->id;
+ kcs_bmc->ioreg.idr = KCS_DI;
+ kcs_bmc->ioreg.odr = KCS_DO;
+ kcs_bmc->ioreg.str = KCS_STS;
+ kcs_bmc->ops = &starfive_kcs_ops;
+
+ platform_set_drvdata(pdev, priv);
+
+ starfive_kcs_hw_init(priv);
+ rc = starfive_kcs_config_irq(kcs_bmc, pdev);
+ if (rc)
+ return rc;
+
+ rc = kcs_bmc_add_device(kcs_bmc);
+ if (rc)
+ return dev_err_probe(dev, rc, "Failed to register channel %u\n",
+ kcs_bmc->channel);
+
+ dev_dbg(dev, "Channel=%u idr=0x%x odr=0x%x str=0x%x\n",
+ kcs_bmc->channel, kcs_bmc->ioreg.idr, kcs_bmc->ioreg.odr,
+ kcs_bmc->ioreg.str);
+
+ return 0;
+}
+
+static void starfive_kcs_remove(struct platform_device *pdev)
+{
+ struct starfive_kcs_bmc *priv = platform_get_drvdata(pdev);
+ struct kcs_bmc_device *kcs_bmc = &priv->kcs_bmc;
+
+ kcs_bmc_remove_device(kcs_bmc);
+
+ starfive_kcs_irq_mask_update(kcs_bmc,
+ (KCS_BMC_EVENT_TYPE_IBF |
+ KCS_BMC_EVENT_TYPE_OBE),
+ 0);
+}
+
+static struct platform_driver starfive_kcs_bmc_driver = {
+ .driver = {
+ .name = DEVICE_NAME,
+ .suppress_bind_attrs = true,
+ },
+ .probe = starfive_kcs_probe,
+ .remove = starfive_kcs_remove,
+};
+module_platform_driver(starfive_kcs_bmc_driver);
+
+MODULE_ALIAS("platform:" DEVICE_NAME);
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mason Huo <mason.huo@starfivetech.com>");
+MODULE_DESCRIPTION("StarFive device interface to the KCS BMC device");
--
2.50.1
^ permalink raw reply related [flat|nested] 5+ messages in thread