* [PATCH v2 00/13] Add SpacemiT K3 FML13V05 EC keyboard support
@ 2026-12-04 4:20 ` Wang Yang
0 siblings, 0 replies; 27+ messages in thread
From: Wang Yang @ 2026-12-04 4:20 UTC (permalink / raw)
To: linux-kernel
Cc: Benson Leung, Tzung-Bi Shih, Guenter Roeck, chrome-platform,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Yixun Lan,
Troy Mitchell, devicetree, linux-riscv, spacemit, Philipp Zabel,
Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
Aurelien Jarno, Conor Dooley, Krishnamoorthi M, yh_chung
This series enables the built-in keyboard on the DeepComputing FML13V05.
The SpacemiT K3 host exposes the EC command window through the eSPI
Peripheral Channel. The EC implements the Chrome EC host protocol, and
the existing Chrome EC keyboard driver reports input events.
Changes since v1:
- Share LPC-style polling, protocol v2/v3 transfers and readmem between
the LPC and K3 transports. Keep the K3 window mapping and recovery in
the K3 transport. A command that times out is not replayed.
- Let the EC core request the IRQ. Existing transports keep their
low-level default and K3 uses the rising edge specified by the board.
- Add the EC binding before the controller binding that references it.
Derive the CPU window from ranges and specify the link frequency in Hz.
The second peripheral base retains the vendor board value, 0xcac8c000.
- Correct the pin pull settings, command status clearing and negotiated
clock selection. Check packet bounds and EC readiness. On resume,
check a pending recovery before enabling the EC event IRQ.
- Order the five RISC-V configuration entries using savedefconfig.
The AMD host RFC models chip-select targets and controller operations.
K3 needs a CPU-mapped Peripheral Channel window and a way to recover the
host link following a timeout. The Aspeed series covers the BMC side.
On next-20261202, an earlier revision booted on FML13V05 from NVMe with
test-only PCIe and DT additions. After a mainboard reset with the EC
still powered, the EC reported FML13V05-V01.06. The built-in keyboard
reported a left Shift press and release, and the EC IRQ count rose from
zero to two. The change since that test is confined to the K3 EC
transport's link check at probe and resume.
OpenAI Codex assisted with refactoring, review of v1 feedback, commit
messages and test preparation.
v1: https://lore.kernel.org/all/20261118085742.1817536-1-yang.wang@deepcomputing.io/
AMD RFC: https://lore.kernel.org/all/20260804115259.4065638-1-krishnamoorthi.m@amd.com/
Aspeed: https://lore.kernel.org/all/20260313-upstream_espi-v1-0-9504428e1f43@aspeedtech.com/
Wang Yang (13):
platform/chrome: Correct LPC EC readmem bounds
platform/chrome: Extract LPC-style EC protocol helpers
platform/chrome: Allow transport-specific LPC response timeouts
platform/chrome: Allow transports to select EC IRQ flags
dt-bindings: embedded-controller: Add SpacemiT K3 EC window
dt-bindings: bus: Add SpacemiT K3 Intel eSPI controller
bus: Add SpacemiT K3 eSPI controller support
platform/chrome: Allow ChromeOS platform support on RISC-V
platform/chrome: Add SpacemiT K3 eSPI EC transport
riscv: dts: spacemit: Add K3 eSPI pin group
riscv: dts: spacemit: Describe the K3 eSPI controller
riscv: dts: spacemit: Enable the FML13V05 EC keyboard
riscv: defconfig: Enable the FML13V05 EC keyboard modules
.../bindings/bus/spacemit,k3-espi.yaml | 149 ++++
.../spacemit,k3-cros-ec.yaml | 77 ++
.../spacemit/k3-deepcomputing-fml13v05.dts | 137 +++
arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi | 24 +
arch/riscv/boot/dts/spacemit/k3.dtsi | 30 +
arch/riscv/configs/defconfig | 5 +
drivers/bus/Kconfig | 10 +
drivers/bus/Makefile | 1 +
drivers/bus/spacemit-k3-espi.c | 799 ++++++++++++++++++
drivers/platform/chrome/Kconfig | 20 +-
drivers/platform/chrome/Makefile | 4 +-
drivers/platform/chrome/cros_ec.c | 3 +-
.../platform/chrome/cros_ec_espi_spacemit.c | 568 +++++++++++++
drivers/platform/chrome/cros_ec_lpc.c | 239 +-----
drivers/platform/chrome/cros_ec_lpc_proto.c | 246 ++++++
drivers/platform/chrome/cros_ec_lpc_proto.h | 36 +
include/linux/platform_data/cros_ec_proto.h | 2 +
include/linux/spacemit-k3-espi.h | 20 +
18 files changed, 2152 insertions(+), 218 deletions(-)
create mode 100644 Documentation/devicetree/bindings/bus/spacemit,k3-espi.yaml
create mode 100644 Documentation/devicetree/bindings/embedded-controller/spacemit,k3-cros-ec.yaml
create mode 100644 drivers/bus/spacemit-k3-espi.c
create mode 100644 drivers/platform/chrome/cros_ec_espi_spacemit.c
create mode 100644 drivers/platform/chrome/cros_ec_lpc_proto.c
create mode 100644 drivers/platform/chrome/cros_ec_lpc_proto.h
create mode 100644 include/linux/spacemit-k3-espi.h
base-commit: 799dd936553182df5770dde7f38d94c8337df75a
--
2.43.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH v2 01/13] platform/chrome: Correct LPC EC readmem bounds
2026-12-04 4:20 ` Wang Yang
(?)
@ 2026-12-04 4:20 ` Wang Yang
-1 siblings, 0 replies; 27+ messages in thread
From: Wang Yang @ 2026-12-04 4:20 UTC (permalink / raw)
To: linux-kernel; +Cc: Benson Leung, Tzung-Bi Shih, Guenter Roeck, chrome-platform
Reject offsets outside the EC memory map before calculating the
remaining space. Allow fixed-length reads ending exactly at the
end of the map and reject oversized reads without underflow.
Prepared with OpenAI Codex assistance.
Signed-off-by: Wang Yang <yang.wang@deepcomputing.io>
---
drivers/platform/chrome/cros_ec_lpc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/platform/chrome/cros_ec_lpc.c b/drivers/platform/chrome/cros_ec_lpc.c
index 1e683e90a9df..4ddd3ca0effa 100644
--- a/drivers/platform/chrome/cros_ec_lpc.c
+++ b/drivers/platform/chrome/cros_ec_lpc.c
@@ -417,7 +417,7 @@ static int cros_ec_lpc_readmem(struct cros_ec_device *ec, unsigned int offset,
int cnt = 0;
int ret;
- if (offset >= EC_MEMMAP_SIZE - bytes)
+ if (offset >= EC_MEMMAP_SIZE || bytes > EC_MEMMAP_SIZE - offset)
return -EINVAL;
/* fixed length */
--
2.43.0
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v2 02/13] platform/chrome: Extract LPC-style EC protocol helpers
2026-12-04 4:20 ` Wang Yang
(?)
(?)
@ 2026-12-04 4:21 ` Wang Yang
-1 siblings, 0 replies; 27+ messages in thread
From: Wang Yang @ 2026-12-04 4:21 UTC (permalink / raw)
To: linux-kernel; +Cc: Benson Leung, Tzung-Bi Shih, Guenter Roeck, chrome-platform
Move response polling, v2/v3 host commands and readmem into shared
helpers. Keep LPC ACPI/DMI/MEC enumeration and hardware byte access
in the LPC driver. Use a static byte-access table and pass the device
specific memory-map base to the shared readmem helper.
Link the helpers into the existing cros-ec-proto module so LPC
keeps its existing module filename and protocol dependency.
Prepared with OpenAI Codex assistance.
Signed-off-by: Wang Yang <yang.wang@deepcomputing.io>
---
drivers/platform/chrome/Kconfig | 6 +
drivers/platform/chrome/Makefile | 3 +-
drivers/platform/chrome/cros_ec_lpc.c | 239 ++-----------------
drivers/platform/chrome/cros_ec_lpc_proto.c | 245 ++++++++++++++++++++
drivers/platform/chrome/cros_ec_lpc_proto.h | 32 +++
5 files changed, 309 insertions(+), 216 deletions(-)
create mode 100644 drivers/platform/chrome/cros_ec_lpc_proto.c
create mode 100644 drivers/platform/chrome/cros_ec_lpc_proto.h
diff --git a/drivers/platform/chrome/Kconfig b/drivers/platform/chrome/Kconfig
index ca2e8442026e..2c11eb4ec95d 100644
--- a/drivers/platform/chrome/Kconfig
+++ b/drivers/platform/chrome/Kconfig
@@ -140,10 +140,16 @@ config CROS_EC_UART
To compile this driver as a module, choose M here: the
module will be called cros_ec_uart.
+config CROS_EC_LPC_PROTO
+ bool
+ help
+ Include the LPC-style host command helpers in cros-ec-proto.
+
config CROS_EC_LPC
tristate "ChromeOS Embedded Controller (LPC)"
depends on CROS_EC && ACPI && (X86 || COMPILE_TEST)
depends on HAS_IOPORT
+ select CROS_EC_LPC_PROTO
help
If you say Y here, you get support for talking to the ChromeOS EC
over an LPC bus, including the LPC Microchip EC (MEC) variant.
diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/Makefile
index b981a1bb5bd8..00d3d9fba1e0 100644
--- a/drivers/platform/chrome/Makefile
+++ b/drivers/platform/chrome/Makefile
@@ -25,7 +25,8 @@ endif
obj-$(CONFIG_CROS_EC_TYPEC) += cros-ec-typec.o
obj-$(CONFIG_CROS_EC_LPC) += cros_ec_lpcs.o
-cros-ec-proto-objs := cros_ec_proto.o cros_ec_trace.o
+cros-ec-proto-y := cros_ec_proto.o cros_ec_trace.o
+cros-ec-proto-$(CONFIG_CROS_EC_LPC_PROTO) += cros_ec_lpc_proto.o
obj-$(CONFIG_CROS_EC_PROTO) += cros-ec-proto.o
obj-$(CONFIG_CROS_KBD_LED_BACKLIGHT) += cros_kbd_led_backlight.o
obj-$(CONFIG_CROS_EC_CHARDEV) += cros_ec_chardev.o
diff --git a/drivers/platform/chrome/cros_ec_lpc.c b/drivers/platform/chrome/cros_ec_lpc.c
index 4ddd3ca0effa..08b635abbd13 100644
--- a/drivers/platform/chrome/cros_ec_lpc.c
+++ b/drivers/platform/chrome/cros_ec_lpc.c
@@ -27,6 +27,7 @@
#include "cros_ec.h"
#include "cros_ec_lpc_mec.h"
+#include "cros_ec_lpc_proto.h"
#define DRV_NAME "cros_ec_lpcs"
#define ACPI_DRV_NAME "GOOG0004"
@@ -206,239 +207,47 @@ static int cros_ec_lpc_direct_write(struct cros_ec_lpc *ec_lpc, unsigned int off
return sum;
}
-static int ec_response_timed_out(struct cros_ec_lpc *ec_lpc)
+static int cros_ec_lpc_read(struct cros_ec_device *ec, unsigned int offset,
+ unsigned int length, u8 *dest)
{
- unsigned long one_second = jiffies + HZ;
- u8 data;
- int ret;
-
- usleep_range(200, 300);
- do {
- ret = ec_lpc->read(ec_lpc, EC_LPC_ADDR_HOST_CMD, 1, &data);
- if (ret < 0)
- return ret;
- if (!(data & EC_LPC_STATUS_BUSY_MASK))
- return 0;
- usleep_range(100, 200);
- } while (time_before(jiffies, one_second));
+ struct cros_ec_lpc *ec_lpc = ec->priv;
- return 1;
+ return ec_lpc->read(ec_lpc, offset, length, dest);
}
-static int cros_ec_pkt_xfer_lpc(struct cros_ec_device *ec,
- struct cros_ec_command *msg)
+static int cros_ec_lpc_write(struct cros_ec_device *ec, unsigned int offset,
+ unsigned int length, const u8 *src)
{
struct cros_ec_lpc *ec_lpc = ec->priv;
- struct ec_host_response response;
- u8 sum;
- int ret = 0;
- u8 *dout;
-
- ret = cros_ec_prepare_tx(ec, msg);
- if (ret < 0)
- goto done;
-
- /* Write buffer */
- ret = ec_lpc->write(ec_lpc, EC_LPC_ADDR_HOST_PACKET, ret, ec->dout);
- if (ret < 0)
- goto done;
-
- /* Here we go */
- sum = EC_COMMAND_PROTOCOL_3;
- ret = ec_lpc->write(ec_lpc, EC_LPC_ADDR_HOST_CMD, 1, &sum);
- if (ret < 0)
- goto done;
-
- ret = ec_response_timed_out(ec_lpc);
- if (ret < 0)
- goto done;
- if (ret) {
- dev_warn(ec->dev, "EC response timed out\n");
- ret = -EIO;
- goto done;
- }
-
- /* Check result */
- ret = ec_lpc->read(ec_lpc, EC_LPC_ADDR_HOST_DATA, 1, &sum);
- if (ret < 0)
- goto done;
- msg->result = ret;
- ret = cros_ec_check_result(ec, msg);
- if (ret)
- goto done;
-
- /* Read back response */
- dout = (u8 *)&response;
- ret = ec_lpc->read(ec_lpc, EC_LPC_ADDR_HOST_PACKET, sizeof(response),
- dout);
- if (ret < 0)
- goto done;
- sum = ret;
- msg->result = response.result;
-
- if (response.data_len > msg->insize) {
- dev_err(ec->dev,
- "packet too long (%d bytes, expected %d)",
- response.data_len, msg->insize);
- ret = -EMSGSIZE;
- goto done;
- }
+ return ec_lpc->write(ec_lpc, offset, length, src);
+}
- /* Read response and process checksum */
- ret = ec_lpc->read(ec_lpc, EC_LPC_ADDR_HOST_PACKET +
- sizeof(response), response.data_len,
- msg->data);
- if (ret < 0)
- goto done;
- sum += ret;
-
- if (sum) {
- dev_err(ec->dev,
- "bad packet checksum %02x\n",
- response.checksum);
- ret = -EBADMSG;
- goto done;
- }
+static const struct cros_ec_lpc_io cros_ec_lpc_io = {
+ .read = cros_ec_lpc_read,
+ .write = cros_ec_lpc_write,
+};
- /* Return actual amount of data received */
- ret = response.data_len;
-done:
- return ret;
+static int cros_ec_pkt_xfer_lpc(struct cros_ec_device *ec,
+ struct cros_ec_command *msg)
+{
+ return cros_ec_lpc_pkt_xfer(ec, &cros_ec_lpc_io, msg);
}
static int cros_ec_cmd_xfer_lpc(struct cros_ec_device *ec,
struct cros_ec_command *msg)
{
- struct cros_ec_lpc *ec_lpc = ec->priv;
- struct ec_lpc_host_args args;
- u8 sum;
- int ret = 0;
-
- if (msg->outsize > EC_PROTO2_MAX_PARAM_SIZE ||
- msg->insize > EC_PROTO2_MAX_PARAM_SIZE) {
- dev_err(ec->dev,
- "invalid buffer sizes (out %d, in %d)\n",
- msg->outsize, msg->insize);
- return -EINVAL;
- }
-
- /* Now actually send the command to the EC and get the result */
- args.flags = EC_HOST_ARGS_FLAG_FROM_HOST;
- args.command_version = msg->version;
- args.data_size = msg->outsize;
-
- /* Initialize checksum */
- sum = msg->command + args.flags + args.command_version + args.data_size;
-
- /* Copy data and update checksum */
- ret = ec_lpc->write(ec_lpc, EC_LPC_ADDR_HOST_PARAM, msg->outsize,
- msg->data);
- if (ret < 0)
- goto done;
- sum += ret;
-
- /* Finalize checksum and write args */
- args.checksum = sum;
- ret = ec_lpc->write(ec_lpc, EC_LPC_ADDR_HOST_ARGS, sizeof(args),
- (u8 *)&args);
- if (ret < 0)
- goto done;
-
- /* Here we go */
- sum = msg->command;
- ret = ec_lpc->write(ec_lpc, EC_LPC_ADDR_HOST_CMD, 1, &sum);
- if (ret < 0)
- goto done;
-
- ret = ec_response_timed_out(ec_lpc);
- if (ret < 0)
- goto done;
- if (ret) {
- dev_warn(ec->dev, "EC response timed out\n");
- ret = -EIO;
- goto done;
- }
-
- /* Check result */
- ret = ec_lpc->read(ec_lpc, EC_LPC_ADDR_HOST_DATA, 1, &sum);
- if (ret < 0)
- goto done;
- msg->result = ret;
- ret = cros_ec_check_result(ec, msg);
- if (ret)
- goto done;
-
- /* Read back args */
- ret = ec_lpc->read(ec_lpc, EC_LPC_ADDR_HOST_ARGS, sizeof(args), (u8 *)&args);
- if (ret < 0)
- goto done;
-
- if (args.data_size > msg->insize) {
- dev_err(ec->dev,
- "packet too long (%d bytes, expected %d)",
- args.data_size, msg->insize);
- ret = -ENOSPC;
- goto done;
- }
-
- /* Start calculating response checksum */
- sum = msg->command + args.flags + args.command_version + args.data_size;
-
- /* Read response and update checksum */
- ret = ec_lpc->read(ec_lpc, EC_LPC_ADDR_HOST_PARAM, args.data_size,
- msg->data);
- if (ret < 0)
- goto done;
- sum += ret;
-
- /* Verify checksum */
- if (args.checksum != sum) {
- dev_err(ec->dev,
- "bad packet checksum, expected %02x, got %02x\n",
- args.checksum, sum);
- ret = -EBADMSG;
- goto done;
- }
-
- /* Return actual amount of data received */
- ret = args.data_size;
-done:
- return ret;
+ return cros_ec_lpc_cmd_xfer(ec, &cros_ec_lpc_io, msg);
}
-/* Returns num bytes read, or negative on error. Doesn't need locking. */
-static int cros_ec_lpc_readmem(struct cros_ec_device *ec, unsigned int offset,
- unsigned int bytes, void *dest)
+static int cros_ec_cmd_readmem_lpc(struct cros_ec_device *ec,
+ unsigned int offset, unsigned int bytes,
+ void *dest)
{
struct cros_ec_lpc *ec_lpc = ec->priv;
- int i = offset;
- char *s = dest;
- int cnt = 0;
- int ret;
-
- if (offset >= EC_MEMMAP_SIZE || bytes > EC_MEMMAP_SIZE - offset)
- return -EINVAL;
-
- /* fixed length */
- if (bytes) {
- ret = ec_lpc->read(ec_lpc, ec_lpc->mmio_memory_base + offset, bytes, s);
- if (ret < 0)
- return ret;
- return bytes;
- }
-
- /* string */
- for (; i < EC_MEMMAP_SIZE; i++, s++) {
- ret = ec_lpc->read(ec_lpc, ec_lpc->mmio_memory_base + i, 1, s);
- if (ret < 0)
- return ret;
- cnt++;
- if (!*s)
- break;
- }
- return cnt;
+ return cros_ec_lpc_readmem(ec, &cros_ec_lpc_io, ec_lpc->mmio_memory_base,
+ offset, bytes, dest);
}
static void cros_ec_lpc_acpi_notify(acpi_handle device, u32 value, void *data)
@@ -645,7 +454,7 @@ static int cros_ec_lpc_probe(struct platform_device *pdev)
ec_dev->phys_name = dev_name(dev);
ec_dev->cmd_xfer = cros_ec_cmd_xfer_lpc;
ec_dev->pkt_xfer = cros_ec_pkt_xfer_lpc;
- ec_dev->cmd_readmem = cros_ec_lpc_readmem;
+ ec_dev->cmd_readmem = cros_ec_cmd_readmem_lpc;
ec_dev->priv = ec_lpc;
/*
diff --git a/drivers/platform/chrome/cros_ec_lpc_proto.c b/drivers/platform/chrome/cros_ec_lpc_proto.c
new file mode 100644
index 000000000000..1dfc32a6ecd7
--- /dev/null
+++ b/drivers/platform/chrome/cros_ec_lpc_proto.c
@@ -0,0 +1,245 @@
+// SPDX-License-Identifier: GPL-2.0
+// LPC-style host command protocol for ChromeOS Embedded Controllers.
+// Copyright (C) 2012-2015 Google, Inc
+
+#include <linux/delay.h>
+#include <linux/jiffies.h>
+#include <linux/export.h>
+#include <linux/platform_data/cros_ec_commands.h>
+#include <linux/platform_data/cros_ec_proto.h>
+
+#include "cros_ec_lpc_proto.h"
+
+static int ec_response_timed_out(struct cros_ec_device *ec,
+ const struct cros_ec_lpc_io *io)
+{
+ unsigned long one_second = jiffies + HZ;
+ u8 data;
+ int ret;
+
+ usleep_range(200, 300);
+ do {
+ ret = io->read(ec, EC_LPC_ADDR_HOST_CMD, 1, &data);
+ if (ret < 0)
+ return ret;
+ if (!(data & EC_LPC_STATUS_BUSY_MASK))
+ return 0;
+ usleep_range(100, 200);
+ } while (time_before(jiffies, one_second));
+
+ return 1;
+}
+
+int cros_ec_lpc_pkt_xfer(struct cros_ec_device *ec,
+ const struct cros_ec_lpc_io *io,
+ struct cros_ec_command *msg)
+{
+ struct ec_host_response response;
+ u8 sum;
+ int ret = 0;
+ u8 *dout;
+
+ ret = cros_ec_prepare_tx(ec, msg);
+ if (ret < 0)
+ goto done;
+
+ /* Write buffer */
+ ret = io->write(ec, EC_LPC_ADDR_HOST_PACKET, ret, ec->dout);
+ if (ret < 0)
+ goto done;
+
+ /* Here we go */
+ sum = EC_COMMAND_PROTOCOL_3;
+ ret = io->write(ec, EC_LPC_ADDR_HOST_CMD, 1, &sum);
+ if (ret < 0)
+ goto done;
+
+ ret = ec_response_timed_out(ec, io);
+ if (ret < 0)
+ goto done;
+ if (ret) {
+ dev_warn(ec->dev, "EC response timed out\n");
+ ret = -EIO;
+ goto done;
+ }
+
+ /* Check result */
+ ret = io->read(ec, EC_LPC_ADDR_HOST_DATA, 1, &sum);
+ if (ret < 0)
+ goto done;
+ msg->result = ret;
+ ret = cros_ec_check_result(ec, msg);
+ if (ret)
+ goto done;
+
+ /* Read back response */
+ dout = (u8 *)&response;
+ ret = io->read(ec, EC_LPC_ADDR_HOST_PACKET, sizeof(response), dout);
+ if (ret < 0)
+ goto done;
+ sum = ret;
+
+ msg->result = response.result;
+
+ if (response.data_len > msg->insize) {
+ dev_err(ec->dev,
+ "packet too long (%d bytes, expected %d)",
+ response.data_len, msg->insize);
+ ret = -EMSGSIZE;
+ goto done;
+ }
+
+ /* Read response and process checksum */
+ ret = io->read(ec, EC_LPC_ADDR_HOST_PACKET + sizeof(response),
+ response.data_len, msg->data);
+ if (ret < 0)
+ goto done;
+ sum += ret;
+
+ if (sum) {
+ dev_err(ec->dev,
+ "bad packet checksum %02x\n",
+ response.checksum);
+ ret = -EBADMSG;
+ goto done;
+ }
+
+ /* Return actual amount of data received */
+ ret = response.data_len;
+done:
+ return ret;
+}
+EXPORT_SYMBOL_GPL(cros_ec_lpc_pkt_xfer);
+
+int cros_ec_lpc_cmd_xfer(struct cros_ec_device *ec,
+ const struct cros_ec_lpc_io *io,
+ struct cros_ec_command *msg)
+{
+ struct ec_lpc_host_args args;
+ u8 sum;
+ int ret = 0;
+
+ if (msg->outsize > EC_PROTO2_MAX_PARAM_SIZE ||
+ msg->insize > EC_PROTO2_MAX_PARAM_SIZE) {
+ dev_err(ec->dev,
+ "invalid buffer sizes (out %d, in %d)\n",
+ msg->outsize, msg->insize);
+ return -EINVAL;
+ }
+
+ /* Now actually send the command to the EC and get the result */
+ args.flags = EC_HOST_ARGS_FLAG_FROM_HOST;
+ args.command_version = msg->version;
+ args.data_size = msg->outsize;
+
+ /* Initialize checksum */
+ sum = msg->command + args.flags + args.command_version + args.data_size;
+
+ /* Copy data and update checksum */
+ ret = io->write(ec, EC_LPC_ADDR_HOST_PARAM, msg->outsize, msg->data);
+ if (ret < 0)
+ goto done;
+ sum += ret;
+
+ /* Finalize checksum and write args */
+ args.checksum = sum;
+ ret = io->write(ec, EC_LPC_ADDR_HOST_ARGS, sizeof(args), (u8 *)&args);
+ if (ret < 0)
+ goto done;
+
+ /* Here we go */
+ sum = msg->command;
+ ret = io->write(ec, EC_LPC_ADDR_HOST_CMD, 1, &sum);
+ if (ret < 0)
+ goto done;
+
+ ret = ec_response_timed_out(ec, io);
+ if (ret < 0)
+ goto done;
+ if (ret) {
+ dev_warn(ec->dev, "EC response timed out\n");
+ ret = -EIO;
+ goto done;
+ }
+
+ /* Check result */
+ ret = io->read(ec, EC_LPC_ADDR_HOST_DATA, 1, &sum);
+ if (ret < 0)
+ goto done;
+ msg->result = ret;
+ ret = cros_ec_check_result(ec, msg);
+ if (ret)
+ goto done;
+
+ /* Read back args */
+ ret = io->read(ec, EC_LPC_ADDR_HOST_ARGS, sizeof(args), (u8 *)&args);
+ if (ret < 0)
+ goto done;
+
+ if (args.data_size > msg->insize) {
+ dev_err(ec->dev,
+ "packet too long (%d bytes, expected %d)",
+ args.data_size, msg->insize);
+ ret = -ENOSPC;
+ goto done;
+ }
+
+ /* Start calculating response checksum */
+ sum = msg->command + args.flags + args.command_version + args.data_size;
+
+ /* Read response and update checksum */
+ ret = io->read(ec, EC_LPC_ADDR_HOST_PARAM, args.data_size, msg->data);
+ if (ret < 0)
+ goto done;
+ sum += ret;
+
+ /* Verify checksum */
+ if (args.checksum != sum) {
+ dev_err(ec->dev,
+ "bad packet checksum, expected %02x, got %02x\n",
+ args.checksum, sum);
+ ret = -EBADMSG;
+ goto done;
+ }
+
+ /* Return actual amount of data received */
+ ret = args.data_size;
+done:
+ return ret;
+}
+EXPORT_SYMBOL_GPL(cros_ec_lpc_cmd_xfer);
+
+/* Returns num bytes read, or negative on error. Doesn't need locking. */
+int cros_ec_lpc_readmem(struct cros_ec_device *ec,
+ const struct cros_ec_lpc_io *io, unsigned int memmap_base,
+ unsigned int offset, unsigned int bytes, void *dest)
+{
+ int i = offset;
+ char *s = dest;
+ int cnt = 0;
+ int ret;
+
+ if (offset >= EC_MEMMAP_SIZE || bytes > EC_MEMMAP_SIZE - offset)
+ return -EINVAL;
+
+ /* fixed length */
+ if (bytes) {
+ ret = io->read(ec, memmap_base + offset, bytes, s);
+ if (ret < 0)
+ return ret;
+ return bytes;
+ }
+
+ /* string */
+ for (; i < EC_MEMMAP_SIZE; i++, s++) {
+ ret = io->read(ec, memmap_base + i, 1, s);
+ if (ret < 0)
+ return ret;
+ cnt++;
+ if (!*s)
+ break;
+ }
+
+ return cnt;
+}
+EXPORT_SYMBOL_GPL(cros_ec_lpc_readmem);
diff --git a/drivers/platform/chrome/cros_ec_lpc_proto.h b/drivers/platform/chrome/cros_ec_lpc_proto.h
new file mode 100644
index 000000000000..7f884ffe823a
--- /dev/null
+++ b/drivers/platform/chrome/cros_ec_lpc_proto.h
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __CROS_EC_LPC_PROTO_H
+#define __CROS_EC_LPC_PROTO_H
+
+#include <linux/types.h>
+
+struct cros_ec_device;
+struct cros_ec_command;
+
+/**
+ * struct cros_ec_lpc_io - byte access to an LPC-style EC interface
+ * @read: Read bytes, returning their checksum or a negative error.
+ * @write: Write bytes, returning their checksum or a negative error.
+ */
+struct cros_ec_lpc_io {
+ int (*read)(struct cros_ec_device *ec, unsigned int offset,
+ unsigned int length, u8 *dest);
+ int (*write)(struct cros_ec_device *ec, unsigned int offset,
+ unsigned int length, const u8 *src);
+};
+
+int cros_ec_lpc_pkt_xfer(struct cros_ec_device *ec,
+ const struct cros_ec_lpc_io *io,
+ struct cros_ec_command *msg);
+int cros_ec_lpc_cmd_xfer(struct cros_ec_device *ec,
+ const struct cros_ec_lpc_io *io,
+ struct cros_ec_command *msg);
+int cros_ec_lpc_readmem(struct cros_ec_device *ec,
+ const struct cros_ec_lpc_io *io, unsigned int memmap_base,
+ unsigned int offset, unsigned int bytes, void *dest);
+
+#endif /* __CROS_EC_LPC_PROTO_H */
--
2.43.0
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH v2 03/13] platform/chrome: Allow transport-specific LPC response timeouts
2026-12-04 4:20 ` Wang Yang
` (2 preceding siblings ...)
(?)
@ 2026-12-04 4:21 ` Wang Yang
-1 siblings, 0 replies; 27+ messages in thread
From: Wang Yang @ 2026-12-04 4:21 UTC (permalink / raw)
To: linux-kernel; +Cc: Benson Leung, Tzung-Bi Shih, Guenter Roeck, chrome-platform
Preserve the LPC default of one second and -EIO. Let a transport
supply a deadline and timeout error without copying the polling loop.
Prepared with OpenAI Codex assistance.
Signed-off-by: Wang Yang <yang.wang@deepcomputing.io>
---
drivers/platform/chrome/cros_ec_lpc_proto.c | 9 +++++----
drivers/platform/chrome/cros_ec_lpc_proto.h | 4 ++++
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/platform/chrome/cros_ec_lpc_proto.c b/drivers/platform/chrome/cros_ec_lpc_proto.c
index 1dfc32a6ecd7..f0bd70e70a9c 100644
--- a/drivers/platform/chrome/cros_ec_lpc_proto.c
+++ b/drivers/platform/chrome/cros_ec_lpc_proto.c
@@ -13,7 +13,8 @@
static int ec_response_timed_out(struct cros_ec_device *ec,
const struct cros_ec_lpc_io *io)
{
- unsigned long one_second = jiffies + HZ;
+ unsigned long timeout = jiffies + (io->response_timeout_ms ?
+ msecs_to_jiffies(io->response_timeout_ms) : HZ);
u8 data;
int ret;
@@ -25,7 +26,7 @@ static int ec_response_timed_out(struct cros_ec_device *ec,
if (!(data & EC_LPC_STATUS_BUSY_MASK))
return 0;
usleep_range(100, 200);
- } while (time_before(jiffies, one_second));
+ } while (time_before(jiffies, timeout));
return 1;
}
@@ -59,7 +60,7 @@ int cros_ec_lpc_pkt_xfer(struct cros_ec_device *ec,
goto done;
if (ret) {
dev_warn(ec->dev, "EC response timed out\n");
- ret = -EIO;
+ ret = io->timeout_error ?: -EIO;
goto done;
}
@@ -158,7 +159,7 @@ int cros_ec_lpc_cmd_xfer(struct cros_ec_device *ec,
goto done;
if (ret) {
dev_warn(ec->dev, "EC response timed out\n");
- ret = -EIO;
+ ret = io->timeout_error ?: -EIO;
goto done;
}
diff --git a/drivers/platform/chrome/cros_ec_lpc_proto.h b/drivers/platform/chrome/cros_ec_lpc_proto.h
index 7f884ffe823a..9276fb09807d 100644
--- a/drivers/platform/chrome/cros_ec_lpc_proto.h
+++ b/drivers/platform/chrome/cros_ec_lpc_proto.h
@@ -11,12 +11,16 @@ struct cros_ec_command;
* struct cros_ec_lpc_io - byte access to an LPC-style EC interface
* @read: Read bytes, returning their checksum or a negative error.
* @write: Write bytes, returning their checksum or a negative error.
+ * @response_timeout_ms: Response timeout in milliseconds, or zero for one second.
+ * @timeout_error: Negative timeout error, or zero for the LPC default (-EIO).
*/
struct cros_ec_lpc_io {
int (*read)(struct cros_ec_device *ec, unsigned int offset,
unsigned int length, u8 *dest);
int (*write)(struct cros_ec_device *ec, unsigned int offset,
unsigned int length, const u8 *src);
+ unsigned int response_timeout_ms;
+ int timeout_error;
};
int cros_ec_lpc_pkt_xfer(struct cros_ec_device *ec,
--
2.43.0
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH v2 04/13] platform/chrome: Allow transports to select EC IRQ flags
2026-12-04 4:20 ` Wang Yang
` (3 preceding siblings ...)
(?)
@ 2026-12-04 4:21 ` Wang Yang
-1 siblings, 0 replies; 27+ messages in thread
From: Wang Yang @ 2026-12-04 4:21 UTC (permalink / raw)
To: linux-kernel; +Cc: Benson Leung, Tzung-Bi Shih, Guenter Roeck, chrome-platform
Initialize IRQ flags to IRQF_TRIGGER_LOW | IRQF_ONESHOT when the EC
device is allocated. Use these flags when registering the interrupt so
a transport can rely on the trigger type configured by its firmware.
Prepared with OpenAI Codex assistance.
Signed-off-by: Wang Yang <yang.wang@deepcomputing.io>
---
drivers/platform/chrome/cros_ec.c | 3 ++-
include/linux/platform_data/cros_ec_proto.h | 2 ++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/platform/chrome/cros_ec.c b/drivers/platform/chrome/cros_ec.c
index 81631b363402..5c2ce6b74975 100644
--- a/drivers/platform/chrome/cros_ec.c
+++ b/drivers/platform/chrome/cros_ec.c
@@ -63,6 +63,7 @@ struct cros_ec_device *cros_ec_device_alloc(struct device *dev)
return NULL;
ec_dev->dev = dev;
+ ec_dev->irqflags = IRQF_TRIGGER_LOW | IRQF_ONESHOT;
ec_dev->max_response = sizeof(struct ec_response_get_protocol_info);
ec_dev->max_request = sizeof(struct ec_params_rwsig_action);
ec_dev->suspend_timeout_ms = EC_HOST_SLEEP_TIMEOUT_DEFAULT;
@@ -247,7 +248,7 @@ int cros_ec_register(struct cros_ec_device *ec_dev)
err = devm_request_threaded_irq(dev, ec_dev->irq,
cros_ec_irq_handler,
cros_ec_irq_thread,
- IRQF_TRIGGER_LOW | IRQF_ONESHOT,
+ ec_dev->irqflags,
"chromeos-ec", ec_dev);
if (err)
goto exit;
diff --git a/include/linux/platform_data/cros_ec_proto.h b/include/linux/platform_data/cros_ec_proto.h
index a1ccecf5e1f8..6307f520db55 100644
--- a/include/linux/platform_data/cros_ec_proto.h
+++ b/include/linux/platform_data/cros_ec_proto.h
@@ -111,6 +111,7 @@ struct cros_ec_command {
* @proto_version: The protocol version used for this device.
* @priv: Private data.
* @irq: Interrupt to use.
+ * @irqflags: Interrupt request flags, defaulting to IRQF_TRIGGER_LOW | IRQF_ONESHOT.
* @id: Device id.
* @din: Input buffer (for data from EC). This buffer will always be
* dword-aligned and include enough space for up to 7 word-alignment
@@ -181,6 +182,7 @@ struct cros_ec_device {
u16 proto_version;
void *priv;
int irq;
+ unsigned long irqflags;
u8 *din;
u8 *dout;
int din_size;
--
2.43.0
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH v2 05/13] dt-bindings: embedded-controller: Add SpacemiT K3 EC window
2026-12-04 4:20 ` Wang Yang
@ 2026-12-04 4:21 ` Wang Yang
-1 siblings, 0 replies; 27+ messages in thread
From: Wang Yang @ 2026-12-04 4:21 UTC (permalink / raw)
To: linux-kernel
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Benson Leung,
Guenter Roeck, Yixun Lan, Troy Mitchell, devicetree,
chrome-platform, linux-riscv, spacemit
Describe the K3 non-linear peripheral window before the controller
binding references it. Reuse the existing keyboard and I2C tunnel
schemas. Keep the Google EC binding unchanged.
Prepared with OpenAI Codex assistance.
Signed-off-by: Wang Yang <yang.wang@deepcomputing.io>
---
.../spacemit,k3-cros-ec.yaml | 77 +++++++++++++++++++
1 file changed, 77 insertions(+)
create mode 100644 Documentation/devicetree/bindings/embedded-controller/spacemit,k3-cros-ec.yaml
diff --git a/Documentation/devicetree/bindings/embedded-controller/spacemit,k3-cros-ec.yaml b/Documentation/devicetree/bindings/embedded-controller/spacemit,k3-cros-ec.yaml
new file mode 100644
index 000000000000..fa9343e3ebf7
--- /dev/null
+++ b/Documentation/devicetree/bindings/embedded-controller/spacemit,k3-cros-ec.yaml
@@ -0,0 +1,77 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/embedded-controller/spacemit,k3-cros-ec.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ChromeOS EC on the SpacemiT K3 peripheral window
+
+maintainers:
+ - Wang Yang <yang.wang@deepcomputing.io>
+
+description: |
+ The embedded controller implements ChromeOS EC host commands through the
+ memory-mapped peripheral window of the SpacemiT K3 eSPI controller. The
+ window uses a non-linear LPC register layout. Offset 0x00 provides host
+ command writes and status reads; offset 0x01 provides host data/results.
+ Protocol v2 arguments and parameters are at 0x10 and 0x18, protocol v3
+ packets at 0x100, and the EC memory map at 0x200. This programming interface
+ is distinct from an EC connected to an ordinary SPI controller. Child
+ functions use the common ChromeOS EC host-command interface. Devices on
+ an EC-controlled I2C bus are described below an I2C tunnel child.
+
+properties:
+ compatible:
+ const: spacemit,k3-cros-ec
+
+ reg:
+ maxItems: 1
+ description: EC peripheral memory window, at least 0x300 bytes.
+
+ interrupts:
+ maxItems: 1
+
+ wakeup-source: true
+
+ keyboard-controller:
+ $ref: /schemas/input/google,cros-ec-keyb.yaml#
+
+patternProperties:
+ "^i2c-tunnel[0-9]*$":
+ type: object
+ $ref: /schemas/i2c/google,cros-ec-i2c-tunnel.yaml#
+
+required:
+ - compatible
+ - reg
+ - interrupts
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/interrupt-controller/irq.h>
+
+ bus {
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ ec@0 {
+ compatible = "spacemit,k3-cros-ec";
+ reg = <0x0 0x1000>;
+ interrupt-parent = <&gpio>;
+ interrupts = <1 11 IRQ_TYPE_EDGE_RISING>;
+
+ i2c-tunnel {
+ compatible = "google,cros-ec-i2c-tunnel";
+ #address-cells = <1>;
+ #size-cells = <0>;
+ google,remote-bus = <4>;
+
+ battery@b {
+ compatible = "sbs,sbs-battery";
+ reg = <0xb>;
+ };
+ };
+ };
+ };
--
2.43.0
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH v2 05/13] dt-bindings: embedded-controller: Add SpacemiT K3 EC window
@ 2026-12-04 4:21 ` Wang Yang
0 siblings, 0 replies; 27+ messages in thread
From: Wang Yang @ 2026-12-04 4:21 UTC (permalink / raw)
To: linux-kernel
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Benson Leung,
Guenter Roeck, Yixun Lan, Troy Mitchell, devicetree,
chrome-platform, linux-riscv, spacemit
Describe the K3 non-linear peripheral window before the controller
binding references it. Reuse the existing keyboard and I2C tunnel
schemas. Keep the Google EC binding unchanged.
Prepared with OpenAI Codex assistance.
Signed-off-by: Wang Yang <yang.wang@deepcomputing.io>
---
.../spacemit,k3-cros-ec.yaml | 77 +++++++++++++++++++
1 file changed, 77 insertions(+)
create mode 100644 Documentation/devicetree/bindings/embedded-controller/spacemit,k3-cros-ec.yaml
diff --git a/Documentation/devicetree/bindings/embedded-controller/spacemit,k3-cros-ec.yaml b/Documentation/devicetree/bindings/embedded-controller/spacemit,k3-cros-ec.yaml
new file mode 100644
index 000000000000..fa9343e3ebf7
--- /dev/null
+++ b/Documentation/devicetree/bindings/embedded-controller/spacemit,k3-cros-ec.yaml
@@ -0,0 +1,77 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/embedded-controller/spacemit,k3-cros-ec.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ChromeOS EC on the SpacemiT K3 peripheral window
+
+maintainers:
+ - Wang Yang <yang.wang@deepcomputing.io>
+
+description: |
+ The embedded controller implements ChromeOS EC host commands through the
+ memory-mapped peripheral window of the SpacemiT K3 eSPI controller. The
+ window uses a non-linear LPC register layout. Offset 0x00 provides host
+ command writes and status reads; offset 0x01 provides host data/results.
+ Protocol v2 arguments and parameters are at 0x10 and 0x18, protocol v3
+ packets at 0x100, and the EC memory map at 0x200. This programming interface
+ is distinct from an EC connected to an ordinary SPI controller. Child
+ functions use the common ChromeOS EC host-command interface. Devices on
+ an EC-controlled I2C bus are described below an I2C tunnel child.
+
+properties:
+ compatible:
+ const: spacemit,k3-cros-ec
+
+ reg:
+ maxItems: 1
+ description: EC peripheral memory window, at least 0x300 bytes.
+
+ interrupts:
+ maxItems: 1
+
+ wakeup-source: true
+
+ keyboard-controller:
+ $ref: /schemas/input/google,cros-ec-keyb.yaml#
+
+patternProperties:
+ "^i2c-tunnel[0-9]*$":
+ type: object
+ $ref: /schemas/i2c/google,cros-ec-i2c-tunnel.yaml#
+
+required:
+ - compatible
+ - reg
+ - interrupts
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/interrupt-controller/irq.h>
+
+ bus {
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ ec@0 {
+ compatible = "spacemit,k3-cros-ec";
+ reg = <0x0 0x1000>;
+ interrupt-parent = <&gpio>;
+ interrupts = <1 11 IRQ_TYPE_EDGE_RISING>;
+
+ i2c-tunnel {
+ compatible = "google,cros-ec-i2c-tunnel";
+ #address-cells = <1>;
+ #size-cells = <0>;
+ google,remote-bus = <4>;
+
+ battery@b {
+ compatible = "sbs,sbs-battery";
+ reg = <0xb>;
+ };
+ };
+ };
+ };
--
2.43.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 27+ messages in thread* Re: [PATCH v2 05/13] dt-bindings: embedded-controller: Add SpacemiT K3 EC window
2026-12-04 4:21 ` Wang Yang
(?)
@ 2026-12-04 4:32 ` sashiko-bot
-1 siblings, 0 replies; 27+ messages in thread
From: sashiko-bot @ 2026-12-04 4:32 UTC (permalink / raw)
To: Wang Yang; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] dt-bindings: spacemit,k3-cros-ec duplicates schema and blocks EC
sub-devices
- [Low] dt-bindings: commit message omits rationale for separate K3 EC
schema
--
commit 4f4efb4e453c6a6ced3361059125c9028c2520f6
Author: Wang Yang <yang.wang@deepcomputing.io>
> dt-bindings: embedded-controller: Add SpacemiT K3 EC window
>
> Describe the K3 non-linear peripheral window before the controller
> binding references it. Reuse the existing keyboard and I2C tunnel
> schemas. Keep the Google EC binding unchanged.
>
> Prepared with OpenAI Codex assistance.
>
> Signed-off-by: Wang Yang <yang.wang@deepcomputing.io>
[Severity: Low]
Could the commit message explain why google,cros-ec.yaml is kept unchanged
instead of extending it or sharing a common schema?
Right now it only states what the patch does without explaining why a
standalone schema is needed, why only keyboard-controller and i2c-tunnel
children are permitted, or why a SoC-specific spacemit,k3-cros-ec
compatible is used for the ChromeOS EC interface.
> diff --git a/Documentation/devicetree/bindings/embedded-controller/spacemit,k3-cros-ec.yaml b/Documentation/devicetree/bindings/embedded-controller/spacemit,k3-cros-ec.yaml
> new file mode 100644
> index 0000000000000..fa9343e3ebf7b
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/embedded-controller/spacemit,k3-cros-ec.yaml
> @@ -0,0 +1,77 @@
[ ... ]
> + keyboard-controller:
> + $ref: /schemas/input/google,cros-ec-keyb.yaml#
> +
> +patternProperties:
> + "^i2c-tunnel[0-9]*$":
> + type: object
> + $ref: /schemas/i2c/google,cros-ec-i2c-tunnel.yaml#
> +
> +required:
> + - compatible
> + - reg
> + - interrupts
> +
> +additionalProperties: false
[Severity: Low]
Does closing this standalone schema with additionalProperties: false block
valid ChromeOS EC sub-devices that the driver populates?
cros_ec_register() populates all DT children via devm_of_platform_populate(),
so dtbs_check will reject standard sub-nodes such as pwm, typec, extcon,
regulator, or gpio-controller on boards using this binding.
Every property and requirement here is already a subset of
google,cros-ec.yaml, whose allOf rules already require reg and interrupts
while forbidding SPI-, RPMSG-, and FPMCU-only properties without new
conditionals. Controller bindings like mtk,scp.yaml reference it directly.
Adding spacemit,k3-cros-ec to google,cros-ec.yaml, or factoring the shared
ChromeOS EC properties and child nodes into a common schema referenced by
both, would avoid duplicating the binding and keep all EC sub-devices valid.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204042112.2985112-1-yang.wang@deepcomputing.io?part=5
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH v2 06/13] dt-bindings: bus: Add SpacemiT K3 Intel eSPI controller
2026-12-04 4:20 ` Wang Yang
@ 2026-12-04 4:21 ` Wang Yang
-1 siblings, 0 replies; 27+ messages in thread
From: Wang Yang @ 2026-12-04 4:21 UTC (permalink / raw)
To: linux-kernel
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Yixun Lan,
Troy Mitchell, devicetree, linux-riscv, spacemit
Describe the Intel eSPI protocol replacing LPC and its CPU-accessible
peripheral window. Reference the already-added K3 EC schema from
the first commit. Use vendor properties and frequency units in Hz.
Prepared with OpenAI Codex assistance.
Signed-off-by: Wang Yang <yang.wang@deepcomputing.io>
---
.../bindings/bus/spacemit,k3-espi.yaml | 149 ++++++++++++++++++
1 file changed, 149 insertions(+)
create mode 100644 Documentation/devicetree/bindings/bus/spacemit,k3-espi.yaml
diff --git a/Documentation/devicetree/bindings/bus/spacemit,k3-espi.yaml b/Documentation/devicetree/bindings/bus/spacemit,k3-espi.yaml
new file mode 100644
index 000000000000..4bd13cc33c90
--- /dev/null
+++ b/Documentation/devicetree/bindings/bus/spacemit,k3-espi.yaml
@@ -0,0 +1,149 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/bus/spacemit,k3-espi.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SpacemiT K3 eSPI controller
+
+maintainers:
+ - Yixun Lan <dlan@kernel.org>
+
+description: |
+ The K3 controller implements the Intel Enhanced Serial Peripheral Interface
+ (eSPI), which replaces LPC. This is a different protocol from the ordinary
+ SPI bus implemented by the Freescale/NXP controller called eSPI.
+
+ The controller connects the application processor to an embedded controller.
+ It exposes a CPU-accessible peripheral-channel window, translated by ranges.
+ EC clients access command, response and memory-map registers through this
+ window. The controller manages clocks, resets, channel negotiation and link
+ recovery after an EC reboot.
+
+properties:
+ compatible:
+ const: spacemit,k3-espi
+
+ reg:
+ maxItems: 1
+
+ '#address-cells':
+ const: 1
+
+ '#size-cells':
+ const: 1
+
+ ranges:
+ maxItems: 1
+
+ clocks:
+ items:
+ - description: Serial clock source
+ - description: Serial clock
+ - description: Bus clock
+
+ clock-names:
+ items:
+ - const: sclk_src
+ - const: sclk
+ - const: mclk
+
+ resets:
+ items:
+ - description: Bus reset
+ - description: Serial clock reset
+
+ spacemit,pr-mem-base1:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ description: Base address programmed into the controller's second peripheral-channel memory base register.
+
+ max-frequency:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ description: Maximum eSPI serial clock frequency in Hz.
+ enum: [20000000, 25000000, 33333333, 50000000, 66666666]
+ default: 20000000
+
+ spacemit,io-mode:
+ $ref: /schemas/types.yaml#/definitions/string
+ description: Requested number of eSPI data lines.
+ enum: [single, dual, quad]
+ default: single
+
+ spacemit,alert-mode:
+ $ref: /schemas/types.yaml#/definitions/string
+ description: Use the shared IO1 line or the dedicated alert pin.
+ enum: [io1, pin]
+ default: io1
+
+ spacemit,alert-type:
+ $ref: /schemas/types.yaml#/definitions/string
+ description: Electrical mode of the dedicated alert pin.
+ enum: [open-drain, push-pull]
+ default: open-drain
+
+ spacemit,watchdog-timeout:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ description: Controller watchdog counter value.
+ maximum: 65535
+ default: 65535
+
+ spacemit,crc-enable:
+ type: boolean
+ description: Enable link CRC checking.
+
+ spacemit,auto-gating-enable:
+ type: boolean
+ description: Enable automatic controller clock gating.
+
+ spacemit,peripheral-channel-enable:
+ type: boolean
+ description: Enable the peripheral channel. Required for an enabled EC child.
+
+ spacemit,vwire-channel-enable:
+ type: boolean
+ description: Enable the virtual-wire channel.
+
+ spacemit,oob-channel-enable:
+ type: boolean
+ description: Enable the out-of-band channel.
+
+ spacemit,flash-channel-enable:
+ type: boolean
+ description: Enable the flash access channel.
+
+patternProperties:
+ '^ec@[0-9a-f]+$':
+ $ref: /schemas/embedded-controller/spacemit,k3-cros-ec.yaml#
+
+required:
+ - compatible
+ - reg
+ - '#address-cells'
+ - '#size-cells'
+ - ranges
+ - clocks
+ - clock-names
+ - resets
+ - spacemit,pr-mem-base1
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/clock/spacemit,k3-clocks.h>
+ #include <dt-bindings/reset/spacemit,k3-resets.h>
+
+ espi@cac8c000 {
+ compatible = "spacemit,k3-espi";
+ reg = <0xcac8c000 0x1000>;
+ ranges = <0 0x84000000 0x1000>;
+ clocks = <&syscon_apmu CLK_APMU_ESPI_SCLK_SRC>,
+ <&syscon_apmu CLK_APMU_ESPI_SCLK>,
+ <&syscon_apmu CLK_APMU_ESPI_MCLK>;
+ clock-names = "sclk_src", "sclk", "mclk";
+ resets = <&syscon_apmu RESET_APMU_ESPI_MCLK>,
+ <&syscon_apmu RESET_APMU_ESPI_SCLK>;
+ #address-cells = <1>;
+ #size-cells = <1>;
+ spacemit,pr-mem-base1 = <0xcac8c000>;
+ };
--
2.43.0
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH v2 06/13] dt-bindings: bus: Add SpacemiT K3 Intel eSPI controller
@ 2026-12-04 4:21 ` Wang Yang
0 siblings, 0 replies; 27+ messages in thread
From: Wang Yang @ 2026-12-04 4:21 UTC (permalink / raw)
To: linux-kernel
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Yixun Lan,
Troy Mitchell, devicetree, linux-riscv, spacemit
Describe the Intel eSPI protocol replacing LPC and its CPU-accessible
peripheral window. Reference the already-added K3 EC schema from
the first commit. Use vendor properties and frequency units in Hz.
Prepared with OpenAI Codex assistance.
Signed-off-by: Wang Yang <yang.wang@deepcomputing.io>
---
.../bindings/bus/spacemit,k3-espi.yaml | 149 ++++++++++++++++++
1 file changed, 149 insertions(+)
create mode 100644 Documentation/devicetree/bindings/bus/spacemit,k3-espi.yaml
diff --git a/Documentation/devicetree/bindings/bus/spacemit,k3-espi.yaml b/Documentation/devicetree/bindings/bus/spacemit,k3-espi.yaml
new file mode 100644
index 000000000000..4bd13cc33c90
--- /dev/null
+++ b/Documentation/devicetree/bindings/bus/spacemit,k3-espi.yaml
@@ -0,0 +1,149 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/bus/spacemit,k3-espi.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SpacemiT K3 eSPI controller
+
+maintainers:
+ - Yixun Lan <dlan@kernel.org>
+
+description: |
+ The K3 controller implements the Intel Enhanced Serial Peripheral Interface
+ (eSPI), which replaces LPC. This is a different protocol from the ordinary
+ SPI bus implemented by the Freescale/NXP controller called eSPI.
+
+ The controller connects the application processor to an embedded controller.
+ It exposes a CPU-accessible peripheral-channel window, translated by ranges.
+ EC clients access command, response and memory-map registers through this
+ window. The controller manages clocks, resets, channel negotiation and link
+ recovery after an EC reboot.
+
+properties:
+ compatible:
+ const: spacemit,k3-espi
+
+ reg:
+ maxItems: 1
+
+ '#address-cells':
+ const: 1
+
+ '#size-cells':
+ const: 1
+
+ ranges:
+ maxItems: 1
+
+ clocks:
+ items:
+ - description: Serial clock source
+ - description: Serial clock
+ - description: Bus clock
+
+ clock-names:
+ items:
+ - const: sclk_src
+ - const: sclk
+ - const: mclk
+
+ resets:
+ items:
+ - description: Bus reset
+ - description: Serial clock reset
+
+ spacemit,pr-mem-base1:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ description: Base address programmed into the controller's second peripheral-channel memory base register.
+
+ max-frequency:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ description: Maximum eSPI serial clock frequency in Hz.
+ enum: [20000000, 25000000, 33333333, 50000000, 66666666]
+ default: 20000000
+
+ spacemit,io-mode:
+ $ref: /schemas/types.yaml#/definitions/string
+ description: Requested number of eSPI data lines.
+ enum: [single, dual, quad]
+ default: single
+
+ spacemit,alert-mode:
+ $ref: /schemas/types.yaml#/definitions/string
+ description: Use the shared IO1 line or the dedicated alert pin.
+ enum: [io1, pin]
+ default: io1
+
+ spacemit,alert-type:
+ $ref: /schemas/types.yaml#/definitions/string
+ description: Electrical mode of the dedicated alert pin.
+ enum: [open-drain, push-pull]
+ default: open-drain
+
+ spacemit,watchdog-timeout:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ description: Controller watchdog counter value.
+ maximum: 65535
+ default: 65535
+
+ spacemit,crc-enable:
+ type: boolean
+ description: Enable link CRC checking.
+
+ spacemit,auto-gating-enable:
+ type: boolean
+ description: Enable automatic controller clock gating.
+
+ spacemit,peripheral-channel-enable:
+ type: boolean
+ description: Enable the peripheral channel. Required for an enabled EC child.
+
+ spacemit,vwire-channel-enable:
+ type: boolean
+ description: Enable the virtual-wire channel.
+
+ spacemit,oob-channel-enable:
+ type: boolean
+ description: Enable the out-of-band channel.
+
+ spacemit,flash-channel-enable:
+ type: boolean
+ description: Enable the flash access channel.
+
+patternProperties:
+ '^ec@[0-9a-f]+$':
+ $ref: /schemas/embedded-controller/spacemit,k3-cros-ec.yaml#
+
+required:
+ - compatible
+ - reg
+ - '#address-cells'
+ - '#size-cells'
+ - ranges
+ - clocks
+ - clock-names
+ - resets
+ - spacemit,pr-mem-base1
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/clock/spacemit,k3-clocks.h>
+ #include <dt-bindings/reset/spacemit,k3-resets.h>
+
+ espi@cac8c000 {
+ compatible = "spacemit,k3-espi";
+ reg = <0xcac8c000 0x1000>;
+ ranges = <0 0x84000000 0x1000>;
+ clocks = <&syscon_apmu CLK_APMU_ESPI_SCLK_SRC>,
+ <&syscon_apmu CLK_APMU_ESPI_SCLK>,
+ <&syscon_apmu CLK_APMU_ESPI_MCLK>;
+ clock-names = "sclk_src", "sclk", "mclk";
+ resets = <&syscon_apmu RESET_APMU_ESPI_MCLK>,
+ <&syscon_apmu RESET_APMU_ESPI_SCLK>;
+ #address-cells = <1>;
+ #size-cells = <1>;
+ spacemit,pr-mem-base1 = <0xcac8c000>;
+ };
--
2.43.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 27+ messages in thread* Re: [PATCH v2 06/13] dt-bindings: bus: Add SpacemiT K3 Intel eSPI controller
2026-12-04 4:21 ` Wang Yang
(?)
@ 2026-12-04 4:44 ` sashiko-bot
-1 siblings, 0 replies; 27+ messages in thread
From: sashiko-bot @ 2026-12-04 4:44 UTC (permalink / raw)
To: Wang Yang; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [Medium] dt-bindings: bus: raw uint32 spacemit,pr-mem-base1 instead of
ranges/reg
- [Medium] dt-bindings: bus: unitless watchdog counter and policy
toggles in DT ABI
- [Medium] dt-bindings: bus: patternProperties locks eSPI bus to single
EC compatible
- [Medium] dt-bindings: bus: spacemit,k3-espi: exposes internal CCU mux
in clocks
- [Low] dt-bindings: bus: unprefixed max-frequency property misnamed and
misordered
- [Low] dt-bindings: bus: missing schema constraints for dependent eSPI
properties
- [Low] dt-bindings: bus: multiple resets lack reset-names and invert
clocks order
- [Low] dt-bindings: commit message has inaccurate series reference and
revision notes
--
commit 622dd2b421fba8b4cbf3a78e0da3e8ce4dbb3c5d
Author: Wang Yang <yang.wang@deepcomputing.io>
> dt-bindings: bus: Add SpacemiT K3 Intel eSPI controller
>
> Describe the Intel eSPI protocol replacing LPC and its CPU-accessible
> peripheral window. Reference the already-added K3 EC schema from
> the first commit. Use vendor properties and frequency units in Hz.
>
> Prepared with OpenAI Codex assistance.
>
> Signed-off-by: Wang Yang <yang.wang@deepcomputing.io>
[Severity: Low]
The commit message refers to "the already-added K3 EC schema from the first
commit", but spacemit,k3-cros-ec.yaml was added in commit "dt-bindings:
embedded-controller: Add SpacemiT K3 EC window", not the first patch of the
series. Permanent git history should name the schema directly rather than
relying on series numbering.
The changelog also reads like revision notes rather than a standalone
explanation of the new binding, and "Use vendor properties and frequency
units in Hz" does not match the schema (max-frequency has neither a vendor
prefix nor a -hz suffix, and spacemit,watchdog-timeout is a raw counter).
> diff --git a/Documentation/devicetree/bindings/bus/spacemit,k3-espi.yaml b/Documentation/devicetree/bindings/bus/spacemit,k3-espi.yaml
> new file mode 100644
> index 0000000000000..4bd13cc33c908
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/bus/spacemit,k3-espi.yaml
[ ... ]
> + clocks:
> + items:
> + - description: Serial clock source
> + - description: Serial clock
> + - description: Bus clock
> +
> + clock-names:
> + items:
> + - const: sclk_src
> + - const: sclk
> + - const: mclk
[Severity: Medium]
Should sclk_src be required in clocks? In drivers/clk/spacemit/ccu-k3.c,
APMU_ESPI_CLK_RES_CTRL has only two gated clock outputs to the eSPI block
(espi_mclk and espi_sclk, matching the two reset domains), while
espi_sclk_src is an ungated internal APMU parent mux feeding espi_sclk.
Exposing sclk_src bakes a Linux CCU driver limitation (espi_sclk lacking
CLK_SET_RATE_PARENT and ccu_mix_calc_best_rate() not propagating rate
rounding to parents) into the permanent DT ABI. Propagating
CLK_SET_RATE_PARENT in the clock driver and using assigned-clocks in DT
would let clocks list only sclk and mclk.
> + resets:
> + items:
> + - description: Bus reset
> + - description: Serial clock reset
[Severity: Low]
Should this binding include a reset-names property for the two resets?
Documentation/devicetree/bindings/writing-bindings.rst recommends
reset-names when there is more than one reset entry, and listing bus before
serial here inverts the order used by clocks, inviting positional mixups in
DTS files.
> + spacemit,pr-mem-base1:
> + $ref: /schemas/types.yaml#/definitions/uint32
> + description: Base address programmed into the controller's second peripheral-channel memory base register.
[Severity: Medium]
Why is a hardware memory base address modeled as a required uint32 vendor
property instead of ranges or reg? Encoding an address as uint32 hardcodes
32-bit addressing on a 64-bit SoC (k3.dtsi uses 2-cell addresses under soc),
bypasses DT address translation, and leaves the address space unspecified.
In the example, spacemit,pr-mem-base1 is set to 0xcac8c000, duplicating the
controller's own MMIO reg base. If this register describes a second
peripheral window it should use ranges or reg; if it only parks an unused
window at the controller base, that address is already known from reg.
> + max-frequency:
> + $ref: /schemas/types.yaml#/definitions/uint32
> + description: Maximum eSPI serial clock frequency in Hz.
> + enum: [20000000, 25000000, 33333333, 50000000, 66666666]
> + default: 20000000
[Severity: Low]
Is unprefixed max-frequency appropriate for a bus controller binding?
Across the tree max-frequency is an MMC-specific property, whereas bus and
controller bindings use the core clock-frequency property (ordered before
vendor properties) or a vendor-prefixed property with a -hz unit suffix such
as spacemit,max-frequency-hz.
[ ... ]
> + spacemit,alert-mode:
> + $ref: /schemas/types.yaml#/definitions/string
> + description: Use the shared IO1 line or the dedicated alert pin.
> + enum: [io1, pin]
> + default: io1
> +
> + spacemit,alert-type:
> + $ref: /schemas/types.yaml#/definitions/string
> + description: Electrical mode of the dedicated alert pin.
> + enum: [open-drain, push-pull]
> + default: open-drain
[Severity: Low]
Can spacemit,alert-type be restricted in the schema to when
spacemit,alert-mode is "pin"? Without a constraint, contradictory nodes
that set alert-mode to "io1" alongside alert-type pass dtbs_check silently.
Similarly, spacemit,peripheral-channel-enable states in prose that it is
required for an enabled EC child, but no schema rule enforces it.
> + spacemit,watchdog-timeout:
> + $ref: /schemas/types.yaml#/definitions/uint32
> + description: Controller watchdog counter value.
> + maximum: 65535
> + default: 65535
> +
> + spacemit,crc-enable:
> + type: boolean
> + description: Enable link CRC checking.
> +
> + spacemit,auto-gating-enable:
> + type: boolean
> + description: Enable automatic controller clock gating.
> +
> + spacemit,peripheral-channel-enable:
> + type: boolean
> + description: Enable the peripheral channel. Required for an enabled EC child.
> +
> + spacemit,vwire-channel-enable:
> + type: boolean
> + description: Enable the virtual-wire channel.
> +
> + spacemit,oob-channel-enable:
> + type: boolean
> + description: Enable the out-of-band channel.
> +
> + spacemit,flash-channel-enable:
> + type: boolean
> + description: Enable the flash access channel.
[Severity: Medium]
Do these register-level and policy properties belong in the permanent DT
ABI? spacemit,watchdog-timeout exposes a unitless 16-bit counter without a
standard time unit suffix (such as -us or -ms) or documented tick rate.
spacemit,crc-enable and spacemit,auto-gating-enable are runtime controller
policy rather than board hardware description, and the four
*-channel-enable booleans duplicate Intel eSPI capability negotiation and
child-node presence, forcing DTS files to mirror static driver defaults.
> +patternProperties:
> + '^ec@[0-9a-f]+$':
> + $ref: /schemas/embedded-controller/spacemit,k3-cros-ec.yaml#
[Severity: Medium]
Does patternProperties lock this SoC eSPI bus controller to a single
ChromeOS EC compatible? Combined with additionalProperties: false and the
const compatible in spacemit,k3-cros-ec.yaml, no K3 board can attach a
different eSPI peripheral or use the standard embedded-controller@ node name
without modifying the controller schema.
Matching generic child nodes (such as '@[0-9a-f]+$' with type: object,
additionalProperties: true, and required: [reg]) lets each attached eSPI
device be validated by its own compatible-matched schema.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204042112.2985112-1-yang.wang@deepcomputing.io?part=6
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH v2 07/13] bus: Add SpacemiT K3 eSPI controller support
2026-12-04 4:20 ` Wang Yang
@ 2026-12-04 4:21 ` Wang Yang
-1 siblings, 0 replies; 27+ messages in thread
From: Wang Yang @ 2026-12-04 4:21 UTC (permalink / raw)
To: linux-kernel
Cc: Yixun Lan, Troy Mitchell, Philipp Zabel, linux-riscv, spacemit
Initialize clocks, resets, link negotiation and windows before
populating EC children. Preserve unrelated asynchronous status bits,
clear completion before commands and use the negotiated clock source.
The controller is vendor-derived from revision 29b78afb484b,
originally authored by goumin <min.gou@spacemit.com>.
The AMD eSPI bus RFC (20260804115259.4065638-1-krishnamoorthi.m@amd.com)
was reviewed. Target/channel APIs, DT enumeration, MMIO peripheral
access and recovery integration remain discussion points; this
series does not claim that the platform-parent model is approved.
Select an I/O width supported by the endpoint and wiring. For the
peripheral channel, read its configuration at the negotiated rate
and wait for READY before programming the CPU window.
Prepared with OpenAI Codex assistance.
Signed-off-by: Wang Yang <yang.wang@deepcomputing.io>
---
drivers/bus/Kconfig | 10 +
drivers/bus/Makefile | 1 +
drivers/bus/spacemit-k3-espi.c | 799 +++++++++++++++++++++++++++++++
include/linux/spacemit-k3-espi.h | 20 +
4 files changed, 830 insertions(+)
create mode 100644 drivers/bus/spacemit-k3-espi.c
create mode 100644 include/linux/spacemit-k3-espi.h
diff --git a/drivers/bus/Kconfig b/drivers/bus/Kconfig
index e4b1db809187..4f47b23c996f 100644
--- a/drivers/bus/Kconfig
+++ b/drivers/bus/Kconfig
@@ -149,6 +149,16 @@ config STM32_DBG_BUS
platforms when the debug configuration is not accessible by the
normal world.
+config SPACEMIT_ESPI_BUS
+ bool "SpacemiT K3 eSPI controller"
+ depends on OF && HAS_IOMEM
+ depends on ARCH_SPACEMIT || COMPILE_TEST
+ help
+ Enable the SpacemiT K3 eSPI controller, including clock and reset
+ management, link initialization and recovery after an EC reboot.
+ Register child devices described in the device tree so their
+ drivers can access the peripheral shared-memory window.
+
config STM32_FIREWALL
bool "STM32 Firewall framework"
depends on (ARCH_STM32 || COMPILE_TEST) && OF
diff --git a/drivers/bus/Makefile b/drivers/bus/Makefile
index a01f97fef3e8..a59fc1901a9b 100644
--- a/drivers/bus/Makefile
+++ b/drivers/bus/Makefile
@@ -26,6 +26,7 @@ obj-$(CONFIG_OMAP_OCP2SCP) += omap-ocp2scp.o
obj-$(CONFIG_QCOM_EBI2) += qcom-ebi2.o
obj-$(CONFIG_QCOM_SSC_BLOCK_BUS) += qcom-ssc-block-bus.o
obj-$(CONFIG_STM32_DBG_BUS) += stm32_dbg_bus.o
+obj-$(CONFIG_SPACEMIT_ESPI_BUS) += spacemit-k3-espi.o
obj-$(CONFIG_STM32_FIREWALL) += stm32_firewall.o stm32_rifsc.o stm32_etzpc.o
obj-$(CONFIG_SUN50I_DE2_BUS) += sun50i-de2.o
obj-$(CONFIG_SUNXI_RSB) += sunxi-rsb.o
diff --git a/drivers/bus/spacemit-k3-espi.c b/drivers/bus/spacemit-k3-espi.c
new file mode 100644
index 000000000000..1e3a4d4f5235
--- /dev/null
+++ b/drivers/bus/spacemit-k3-espi.c
@@ -0,0 +1,799 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * SpacemiT K3 eSPI controller driver
+ *
+ * This driver owns controller-level initialization and recovery so child
+ * devices such as cros_ec_espi can treat the peripheral shared memory window
+ * as a transport and ask the parent controller to recover the link when the
+ * EC reboots underneath Linux.
+ */
+
+#include <linux/bitfield.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/reset.h>
+#include <linux/spacemit-k3-espi.h>
+#include <linux/wordpart.h>
+
+#define ESPI_DN_TXHDR 0x00
+#define ESPI_DN_TXDATA_PORT 0x0c
+#define ESPI_GLOBAL_CONTROL_0 0x30
+#define ESPI_GLOBAL_CONTROL_1 0x34
+#define ESPI_PR_BASE_ADDR_MEM0 0x38
+#define ESPI_PR_BASE_ADDR_MEM1 0x3c
+#define ESPI_SLAVE0_CONFIG 0x68
+#define ESPI_SLAVE0_INT_EN 0x6c
+#define ESPI_SLAVE0_INT_STS 0x70
+
+#define ESPI_DNCMD_TYPE_MASK GENMASK(2, 0)
+#define ESPI_DNCMD_EN BIT(3)
+#define ESPI_DNCMD_SLAVE_SEL_MASK GENMASK(5, 4)
+
+#define ESPI_DNCMD_SET_CONFIGURATION 0x00
+#define ESPI_DNCMD_GET_CONFIGURATION 0x01
+#define ESPI_DNCMD_IN_BAND_RESET 0x02
+
+#define ESPI_FLASH_REQ_INT BIT(31)
+#define ESPI_RXOOB_INT BIT(30)
+#define ESPI_RXMSG_INT BIT(29)
+#define ESPI_DNCMD_INT BIT(28)
+#define ESPI_RXVW_GRP3_INT BIT(27)
+#define ESPI_RXVW_GRP2_INT BIT(26)
+#define ESPI_RXVW_GRP1_INT BIT(25)
+#define ESPI_RXVW_GRP0_INT BIT(24)
+#define ESPI_PROTOCOL_ERR_INT BIT(15)
+#define ESPI_RXFLASH_OFLOW_INT BIT(14)
+#define ESPI_RXMSG_OFLOW_INT BIT(13)
+#define ESPI_RXOOB_OFLOW_INT BIT(12)
+#define ESPI_ILLEGAL_LEN_INT BIT(11)
+#define ESPI_ILLEGAL_TAG_INT BIT(10)
+#define ESPI_UNSUCSS_CPL_INT BIT(9)
+#define ESPI_INVALID_CT_RSP_INT BIT(8)
+#define ESPI_UNKNOWN_RSP_INT BIT(7)
+#define ESPI_NON_FATAL_INT BIT(6)
+#define ESPI_FATAL_ERR_INT BIT(5)
+#define ESPI_NO_RSP_INT BIT(4)
+#define ESPI_CRC_ERR_INT BIT(2)
+#define ESPI_WAIT_TIMEOUT_INT BIT(1)
+#define ESPI_BUS_ERR_INT BIT(0)
+
+#define ESPI_CALLBACK_INT (ESPI_FLASH_REQ_INT | \
+ ESPI_RXOOB_INT | \
+ ESPI_RXMSG_INT | \
+ ESPI_DNCMD_INT | \
+ ESPI_RXVW_GRP3_INT | \
+ ESPI_RXVW_GRP2_INT | \
+ ESPI_RXVW_GRP1_INT | \
+ ESPI_RXVW_GRP0_INT)
+#define ESPI_PROTOCOL_INT (ESPI_PROTOCOL_ERR_INT | \
+ ESPI_RXFLASH_OFLOW_INT | \
+ ESPI_RXMSG_OFLOW_INT | \
+ ESPI_RXOOB_OFLOW_INT | \
+ ESPI_ILLEGAL_LEN_INT | \
+ ESPI_ILLEGAL_TAG_INT | \
+ ESPI_UNSUCSS_CPL_INT | \
+ ESPI_INVALID_CT_RSP_INT | \
+ ESPI_UNKNOWN_RSP_INT | \
+ ESPI_CRC_ERR_INT | \
+ ESPI_WAIT_TIMEOUT_INT | \
+ ESPI_BUS_ERR_INT)
+#define ESPI_RESPONSE_INT (ESPI_NON_FATAL_INT | \
+ ESPI_FATAL_ERR_INT | \
+ ESPI_NO_RSP_INT)
+#define ESPI_ALL_INT (ESPI_CALLBACK_INT | \
+ ESPI_PROTOCOL_INT | \
+ ESPI_RESPONSE_INT)
+
+#define ESPI_MST_STOP_EN BIT(3)
+#define ESPI_CONTROL_WATCHDOG_EN BIT(0)
+#define ESPI_CONTROL_WATCHDOG_CNT_MASK GENMASK(23, 8)
+
+#define ESPI_CRC_CHECK_EN BIT(31)
+#define ESPI_ALERT_MODE_SEL BIT(30)
+#define ESPI_IO_MODE_SEL_MASK GENMASK(29, 28)
+#define ESPI_CLK_FREQ_SEL_MASK GENMASK(27, 25)
+#define ESPI_PR_CHANNEL_ENABLE BIT(3)
+#define ESPI_VW_CHANNEL_ENABLE BIT(2)
+#define ESPI_OOB_CHANNEL_ENABLE BIT(1)
+#define ESPI_FLASH_CHANNEL_ENABLE BIT(0)
+
+#define ESPI_ESPI_RSTN BIT(5)
+#define ESPI_SW_RST BIT(0)
+
+#define ESPI_SLAVE_GEN_CFG 0x08
+#define ESPI_SLAVE_PERI_CFG 0x10
+#define ESPI_SLAVE_VWIRE_CFG 0x20
+#define ESPI_SLAVE_OOB_CFG 0x30
+#define ESPI_SLAVE_FLASH_CFG 0x40
+#define ESPI_CHANNEL_READY BIT(1)
+
+#define ESPI_GEN_CRC_ENABLE BIT(31)
+#define ESPI_GEN_ALERT_MODE_PIN BIT(28)
+#define ESPI_GEN_IO_MODE_SUP_MASK GENMASK(25, 24)
+#define ESPI_GEN_OPEN_DRAIN_ALERT_SEL BIT(23)
+#define ESPI_GEN_OPEN_DRAIN_ALERT_SUP BIT(19)
+#define ESPI_GEN_OP_FREQ_SUP_MASK GENMASK(18, 16)
+#define ESPI_GEN_OP_FREQ_SEL_MASK GENMASK(22, 20)
+#define ESPI_GEN_IO_MODE_SEL_MASK GENMASK(27, 26)
+#define ESPI_GEN_FLASH_CHAN_SUP BIT(3)
+#define ESPI_GEN_OOB_CHAN_SUP BIT(2)
+#define ESPI_GEN_VWIRE_CHAN_SUP BIT(1)
+#define ESPI_GEN_PERI_CHAN_SUP BIT(0)
+
+#define ESPI_GEN_IO_MODE_SINGLE 0x0
+#define ESPI_GEN_IO_MODE_DUAL 0x1
+#define ESPI_GEN_IO_MODE_QUAD 0x2
+
+#define ESPI_GEN_OP_FREQ_20MHZ 0x0
+#define ESPI_GEN_OP_FREQ_25MHZ 0x1
+#define ESPI_GEN_OP_FREQ_33MHZ 0x2
+#define ESPI_GEN_OP_FREQ_50MHZ 0x3
+#define ESPI_GEN_OP_FREQ_66MHZ 0x4
+
+#define ESPI_ENABLE_PR_CHANNEL 0x1115
+#define ESPI_ENABLE_VW_CHANNEL 0x70701
+#define ESPI_ENABLE_OOB_CHANNEL 0x111
+#define ESPI_ENABLE_FLASH_CHANNEL 0x11125
+
+#define ESPI_CFG_TIMEOUT_US 50000
+#define ESPI_TX_IDLE_TIMEOUT_US 1000
+
+#define SPACEMIT_ESPI_DEFAULT_FREQ_HZ 20000000
+#define SPACEMIT_ESPI_DEFAULT_WDT 0xffff
+
+struct spacemit_espi {
+ struct device *dev;
+ struct clk_bulk_data *clks;
+ int num_clks;
+ struct clk *sclk;
+ struct clk *sclk_src;
+ struct reset_control *resets;
+ bool clocks_enabled;
+ void __iomem *regs;
+ u32 pr_mem_base0;
+ u32 pr_mem_base1;
+ u32 max_freq_hz;
+ u32 watchdog_timeout;
+ u32 io_mode;
+ bool alert_pin_mode;
+ bool alert_open_drain;
+ bool crc_enable;
+ bool enable_peri;
+ bool enable_vwire;
+ bool enable_oob;
+ bool enable_flash;
+ bool auto_gating;
+ /* Serialize controller setup, PM and EC-triggered link recovery. */
+ struct mutex lock;
+};
+
+static u32 spacemit_espi_txhdr_reg(unsigned int index)
+{
+ return ESPI_DN_TXHDR + ((index + 1) & ~0x3);
+}
+
+static u32 spacemit_espi_txhdr_shift(unsigned int index)
+{
+ return ((index + 1) & 0x3) * 8;
+}
+
+static void spacemit_espi_write_hdr(struct spacemit_espi *espi, unsigned int index,
+ u8 value)
+{
+ u32 reg = spacemit_espi_txhdr_reg(index);
+ u32 shift = spacemit_espi_txhdr_shift(index);
+ u32 data;
+
+ data = readl(espi->regs + reg);
+ data &= ~(GENMASK(7, 0) << shift);
+ data |= (u32)value << shift;
+ writel(data, espi->regs + reg);
+}
+
+static u8 spacemit_espi_read_hdr(struct spacemit_espi *espi, unsigned int index)
+{
+ u32 reg = spacemit_espi_txhdr_reg(index);
+ u32 shift = spacemit_espi_txhdr_shift(index);
+
+ return (readl(espi->regs + reg) >> shift) & 0xff;
+}
+
+static void spacemit_espi_trigger_cmd(struct spacemit_espi *espi, u32 cmd_type)
+{
+ u32 val;
+
+ /* Clear stale command status before the transfer can complete. */
+ writel(ESPI_DNCMD_INT | ESPI_PROTOCOL_INT | ESPI_RESPONSE_INT,
+ espi->regs + ESPI_SLAVE0_INT_STS);
+
+ val = readl(espi->regs + ESPI_DN_TXHDR);
+ val &= ~(ESPI_DNCMD_TYPE_MASK | ESPI_DNCMD_EN |
+ ESPI_DNCMD_SLAVE_SEL_MASK);
+ val |= FIELD_PREP(ESPI_DNCMD_TYPE_MASK, cmd_type);
+ val |= ESPI_DNCMD_EN;
+ writel(val, espi->regs + ESPI_DN_TXHDR);
+}
+
+static int spacemit_espi_wait_tx_idle(struct spacemit_espi *espi)
+{
+ unsigned int timeout = ESPI_TX_IDLE_TIMEOUT_US;
+
+ do {
+ if (!(readl(espi->regs + ESPI_DN_TXHDR) & ESPI_DNCMD_EN))
+ return 0;
+ udelay(1);
+ } while (--timeout);
+
+ return -EBUSY;
+}
+
+static int spacemit_espi_poll_status(struct spacemit_espi *espi, u32 expected)
+{
+ unsigned int timeout = ESPI_CFG_TIMEOUT_US / 10;
+ u32 status;
+
+ do {
+ status = readl(espi->regs + ESPI_SLAVE0_INT_STS);
+ status &= expected | ESPI_PROTOCOL_INT | ESPI_RESPONSE_INT;
+ if (!status) {
+ fsleep(10);
+ continue;
+ }
+
+ writel(status, espi->regs + ESPI_SLAVE0_INT_STS);
+
+ if (status & (ESPI_PROTOCOL_INT | ESPI_RESPONSE_INT))
+ return -EIO;
+
+ if (status & expected)
+ return 0;
+
+ fsleep(10);
+ } while (--timeout);
+
+ return -ETIMEDOUT;
+}
+
+static int spacemit_espi_cmd_get_config(struct spacemit_espi *espi, u16 addr, u32 *value)
+{
+ int ret;
+
+ spacemit_espi_write_hdr(espi, 0, 0);
+ spacemit_espi_write_hdr(espi, 1, addr >> 8);
+ spacemit_espi_write_hdr(espi, 2, addr);
+ spacemit_espi_trigger_cmd(espi, ESPI_DNCMD_GET_CONFIGURATION);
+
+ ret = spacemit_espi_poll_status(espi, ESPI_DNCMD_INT);
+ if (ret)
+ return ret;
+
+ *value = spacemit_espi_read_hdr(espi, 3);
+ *value |= (u32)spacemit_espi_read_hdr(espi, 4) << 8;
+ *value |= (u32)spacemit_espi_read_hdr(espi, 5) << 16;
+ *value |= (u32)spacemit_espi_read_hdr(espi, 6) << 24;
+
+ return 0;
+}
+
+static int spacemit_espi_cmd_set_config(struct spacemit_espi *espi, u16 addr, u32 value)
+{
+ spacemit_espi_write_hdr(espi, 0, 0);
+ spacemit_espi_write_hdr(espi, 1, addr >> 8);
+ spacemit_espi_write_hdr(espi, 2, addr);
+ spacemit_espi_write_hdr(espi, 3, value);
+ spacemit_espi_write_hdr(espi, 4, value >> 8);
+ spacemit_espi_write_hdr(espi, 5, value >> 16);
+ spacemit_espi_write_hdr(espi, 6, value >> 24);
+ spacemit_espi_trigger_cmd(espi, ESPI_DNCMD_SET_CONFIGURATION);
+
+ return spacemit_espi_poll_status(espi, ESPI_DNCMD_INT);
+}
+
+static void spacemit_espi_enable_irqs(struct spacemit_espi *espi)
+{
+ writel(ESPI_ALL_INT, espi->regs + ESPI_SLAVE0_INT_EN);
+}
+
+static void spacemit_espi_reset_controller(struct spacemit_espi *espi)
+{
+ u32 val;
+
+ val = readl(espi->regs + ESPI_GLOBAL_CONTROL_1);
+ val &= ~ESPI_ESPI_RSTN;
+ writel(val, espi->regs + ESPI_GLOBAL_CONTROL_1);
+
+ val = readl(espi->regs + ESPI_GLOBAL_CONTROL_1);
+ val |= ESPI_ESPI_RSTN | ESPI_SW_RST;
+ writel(val, espi->regs + ESPI_GLOBAL_CONTROL_1);
+}
+
+static int spacemit_espi_send_inband_reset(struct spacemit_espi *espi)
+{
+ int ret;
+
+ spacemit_espi_trigger_cmd(espi, ESPI_DNCMD_IN_BAND_RESET);
+ ret = spacemit_espi_wait_tx_idle(espi);
+ if (ret)
+ return ret;
+ fsleep(1000);
+ writel(ESPI_DNCMD_INT | ESPI_PROTOCOL_INT | ESPI_RESPONSE_INT,
+ espi->regs + ESPI_SLAVE0_INT_STS);
+
+ return 0;
+}
+
+static u32 spacemit_espi_freq_to_sel(u32 hz)
+{
+ switch (hz) {
+ case 66666666:
+ return ESPI_GEN_OP_FREQ_66MHZ;
+ case 50000000:
+ return ESPI_GEN_OP_FREQ_50MHZ;
+ case 33333333:
+ return ESPI_GEN_OP_FREQ_33MHZ;
+ case 25000000:
+ return ESPI_GEN_OP_FREQ_25MHZ;
+ case 20000000:
+ default:
+ return ESPI_GEN_OP_FREQ_20MHZ;
+ }
+}
+
+static int spacemit_espi_set_rate(struct spacemit_espi *espi, u32 sel)
+{
+ static const unsigned long rates[] = {
+ 20000000, 25000000, 33333333, 50000000, 66666666,
+ };
+ int ret;
+
+ if (sel >= ARRAY_SIZE(rates))
+ return -EINVAL;
+
+ ret = clk_set_rate(espi->sclk_src, rates[sel]);
+ if (ret)
+ return ret;
+
+ if (clk_get_rate(espi->sclk_src) != rates[sel] ||
+ clk_get_rate(espi->sclk) != rates[sel])
+ return -EINVAL;
+
+ return 0;
+}
+
+static u32 spacemit_espi_build_negotiated_config(struct spacemit_espi *espi,
+ u32 slave_caps)
+{
+ u32 cfg = 0;
+ u32 io_caps = FIELD_GET(ESPI_GEN_IO_MODE_SUP_MASK, slave_caps);
+ u32 io_mode = ESPI_GEN_IO_MODE_SINGLE;
+ u32 freq;
+
+ if (espi->crc_enable)
+ cfg |= ESPI_GEN_CRC_ENABLE;
+
+ if (espi->alert_pin_mode) {
+ cfg |= ESPI_GEN_ALERT_MODE_PIN;
+ if (espi->alert_open_drain &&
+ (slave_caps & ESPI_GEN_OPEN_DRAIN_ALERT_SUP))
+ cfg |= ESPI_GEN_OPEN_DRAIN_ALERT_SEL;
+ }
+
+ if (espi->io_mode == ESPI_GEN_IO_MODE_QUAD && (io_caps & BIT(1)))
+ io_mode = ESPI_GEN_IO_MODE_QUAD;
+ else if (espi->io_mode >= ESPI_GEN_IO_MODE_DUAL && (io_caps & BIT(0)))
+ io_mode = ESPI_GEN_IO_MODE_DUAL;
+ freq = min_t(u32, spacemit_espi_freq_to_sel(espi->max_freq_hz),
+ FIELD_GET(ESPI_GEN_OP_FREQ_SUP_MASK, slave_caps));
+ cfg |= FIELD_PREP(ESPI_GEN_IO_MODE_SEL_MASK, io_mode);
+ cfg |= FIELD_PREP(ESPI_GEN_OP_FREQ_SEL_MASK, freq);
+
+ if (espi->enable_peri && (slave_caps & ESPI_GEN_PERI_CHAN_SUP))
+ cfg |= ESPI_GEN_PERI_CHAN_SUP;
+ if (espi->enable_vwire && (slave_caps & ESPI_GEN_VWIRE_CHAN_SUP))
+ cfg |= ESPI_GEN_VWIRE_CHAN_SUP;
+ if (espi->enable_oob && (slave_caps & ESPI_GEN_OOB_CHAN_SUP))
+ cfg |= ESPI_GEN_OOB_CHAN_SUP;
+ if (espi->enable_flash && (slave_caps & ESPI_GEN_FLASH_CHAN_SUP))
+ cfg |= ESPI_GEN_FLASH_CHAN_SUP;
+
+ return cfg;
+}
+
+static int spacemit_espi_configure_channels(struct spacemit_espi *espi, u32 cfg)
+{
+ int ret;
+
+ if (cfg & ESPI_GEN_PERI_CHAN_SUP) {
+ ret = spacemit_espi_cmd_set_config(espi, ESPI_SLAVE_PERI_CFG,
+ ESPI_ENABLE_PR_CHANNEL);
+ if (ret)
+ return ret;
+ }
+
+ if (cfg & ESPI_GEN_VWIRE_CHAN_SUP) {
+ ret = spacemit_espi_cmd_set_config(espi, ESPI_SLAVE_VWIRE_CFG,
+ ESPI_ENABLE_VW_CHANNEL);
+ if (ret)
+ return ret;
+ }
+
+ if (cfg & ESPI_GEN_OOB_CHAN_SUP) {
+ ret = spacemit_espi_cmd_set_config(espi, ESPI_SLAVE_OOB_CFG,
+ ESPI_ENABLE_OOB_CHANNEL);
+ if (ret)
+ return ret;
+ }
+
+ if (cfg & ESPI_GEN_FLASH_CHAN_SUP) {
+ ret = spacemit_espi_cmd_set_config(espi, ESPI_SLAVE_FLASH_CFG,
+ ESPI_ENABLE_FLASH_CHANNEL);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+static void spacemit_espi_apply_controller_config(struct spacemit_espi *espi, u32 cfg)
+{
+ u32 val;
+ u32 mask = ESPI_CRC_CHECK_EN | ESPI_ALERT_MODE_SEL |
+ ESPI_IO_MODE_SEL_MASK | ESPI_CLK_FREQ_SEL_MASK |
+ ESPI_PR_CHANNEL_ENABLE | ESPI_VW_CHANNEL_ENABLE |
+ ESPI_OOB_CHANNEL_ENABLE | ESPI_FLASH_CHANNEL_ENABLE;
+
+ val = readl(espi->regs + ESPI_SLAVE0_CONFIG);
+ val &= ~mask;
+
+ if (cfg & ESPI_GEN_CRC_ENABLE)
+ val |= ESPI_CRC_CHECK_EN;
+ if (cfg & ESPI_GEN_ALERT_MODE_PIN)
+ val |= ESPI_ALERT_MODE_SEL;
+
+ val |= FIELD_PREP(ESPI_IO_MODE_SEL_MASK,
+ FIELD_GET(ESPI_GEN_IO_MODE_SEL_MASK, cfg));
+ val |= FIELD_PREP(ESPI_CLK_FREQ_SEL_MASK,
+ FIELD_GET(ESPI_GEN_OP_FREQ_SEL_MASK, cfg));
+
+ if (cfg & ESPI_GEN_PERI_CHAN_SUP)
+ val |= ESPI_PR_CHANNEL_ENABLE;
+ if (cfg & ESPI_GEN_VWIRE_CHAN_SUP)
+ val |= ESPI_VW_CHANNEL_ENABLE;
+ if (cfg & ESPI_GEN_OOB_CHAN_SUP)
+ val |= ESPI_OOB_CHANNEL_ENABLE;
+ if (cfg & ESPI_GEN_FLASH_CHAN_SUP)
+ val |= ESPI_FLASH_CHANNEL_ENABLE;
+
+ writel(val, espi->regs + ESPI_SLAVE0_CONFIG);
+}
+
+static void spacemit_espi_program_window(struct spacemit_espi *espi)
+{
+ u32 val;
+
+ val = readl(espi->regs + ESPI_GLOBAL_CONTROL_0);
+ val &= ~(ESPI_CONTROL_WATCHDOG_CNT_MASK | ESPI_MST_STOP_EN);
+ val |= ESPI_CONTROL_WATCHDOG_EN;
+ val |= FIELD_PREP(ESPI_CONTROL_WATCHDOG_CNT_MASK,
+ espi->watchdog_timeout);
+ if (espi->auto_gating)
+ val |= ESPI_MST_STOP_EN;
+ writel(val, espi->regs + ESPI_GLOBAL_CONTROL_0);
+
+ writel(espi->pr_mem_base0, espi->regs + ESPI_PR_BASE_ADDR_MEM0);
+ writel(espi->pr_mem_base1, espi->regs + ESPI_PR_BASE_ADDR_MEM1);
+}
+
+static int spacemit_espi_parse_dt(struct platform_device *pdev,
+ struct spacemit_espi *espi)
+{
+ struct device *dev = &pdev->dev;
+ struct device_node *np = dev->of_node;
+ struct resource range;
+ const char *str;
+ int ret;
+
+ espi->max_freq_hz = SPACEMIT_ESPI_DEFAULT_FREQ_HZ;
+ of_property_read_u32(np, "max-frequency", &espi->max_freq_hz);
+ if (espi->max_freq_hz != 20000000 && espi->max_freq_hz != 25000000 &&
+ espi->max_freq_hz != 33333333 && espi->max_freq_hz != 50000000 &&
+ espi->max_freq_hz != 66666666)
+ return dev_err_probe(dev, -EINVAL, "unsupported link frequency\n");
+
+ espi->watchdog_timeout = SPACEMIT_ESPI_DEFAULT_WDT;
+ of_property_read_u32(np, "spacemit,watchdog-timeout", &espi->watchdog_timeout);
+ if (espi->watchdog_timeout > SPACEMIT_ESPI_DEFAULT_WDT)
+ return -EINVAL;
+
+ ret = of_range_to_resource(np, 0, &range);
+ if (ret)
+ return dev_err_probe(dev, ret, "missing peripheral memory range\n");
+ if (upper_32_bits(range.start))
+ return -EINVAL;
+ espi->pr_mem_base0 = lower_32_bits(range.start);
+
+ ret = of_property_read_u32(np, "spacemit,pr-mem-base1", &espi->pr_mem_base1);
+ if (ret)
+ return dev_err_probe(dev, ret, "missing peripheral memory window 1 base\n");
+
+ if (!of_property_read_string(np, "spacemit,io-mode", &str)) {
+ if (!strcmp(str, "quad"))
+ espi->io_mode = ESPI_GEN_IO_MODE_QUAD;
+ else if (!strcmp(str, "dual"))
+ espi->io_mode = ESPI_GEN_IO_MODE_DUAL;
+ else
+ espi->io_mode = ESPI_GEN_IO_MODE_SINGLE;
+ } else {
+ espi->io_mode = ESPI_GEN_IO_MODE_SINGLE;
+ }
+
+ if (!of_property_read_string(np, "spacemit,alert-mode", &str))
+ espi->alert_pin_mode = !strcmp(str, "pin");
+ else
+ espi->alert_pin_mode = false;
+
+ if (!of_property_read_string(np, "spacemit,alert-type", &str))
+ espi->alert_open_drain = !strcmp(str, "open-drain");
+ else
+ espi->alert_open_drain = true;
+
+ espi->crc_enable = of_property_read_bool(np, "spacemit,crc-enable");
+ espi->enable_peri = of_property_read_bool(np, "spacemit,peripheral-channel-enable");
+ if (!espi->enable_peri && of_get_available_child_count(np))
+ return dev_err_probe(dev, -EINVAL, "EC requires the peripheral channel\n");
+ espi->enable_vwire = of_property_read_bool(np, "spacemit,vwire-channel-enable");
+ espi->enable_oob = of_property_read_bool(np, "spacemit,oob-channel-enable");
+ espi->enable_flash = of_property_read_bool(np, "spacemit,flash-channel-enable");
+ espi->auto_gating = of_property_read_bool(np, "spacemit,auto-gating-enable");
+
+ return 0;
+}
+
+static int spacemit_espi_enable_clks(struct device *dev, struct spacemit_espi *espi)
+{
+ int ret;
+
+ if (!espi->num_clks || espi->clocks_enabled)
+ return 0;
+
+ ret = clk_bulk_prepare_enable(espi->num_clks, espi->clks);
+ if (ret) {
+ dev_err(dev, "failed to enable clocks: %d\n", ret);
+ return ret;
+ }
+
+ espi->clocks_enabled = true;
+ return 0;
+}
+
+static void spacemit_espi_disable_clks(struct spacemit_espi *espi)
+{
+ if (!espi->num_clks || !espi->clocks_enabled)
+ return;
+
+ clk_bulk_disable_unprepare(espi->num_clks, espi->clks);
+ espi->clocks_enabled = false;
+}
+
+static int spacemit_espi_init_locked(struct spacemit_espi *espi)
+{
+ u32 slave_caps = 0;
+ u32 channel;
+ u32 cfg;
+ int err, ret;
+
+ ret = spacemit_espi_enable_clks(espi->dev, espi);
+ if (ret)
+ return ret;
+
+ ret = reset_control_deassert(espi->resets);
+ if (ret)
+ return ret;
+
+ ret = clk_set_parent(espi->sclk, espi->sclk_src);
+ if (ret)
+ return ret;
+ ret = spacemit_espi_set_rate(espi, ESPI_GEN_OP_FREQ_20MHZ);
+ if (ret)
+ return ret;
+
+ spacemit_espi_enable_irqs(espi);
+ writel(ESPI_ALL_INT, espi->regs + ESPI_SLAVE0_INT_STS);
+
+ spacemit_espi_reset_controller(espi);
+ /* In-band reset and capability negotiation start at 20 MHz, single IO. */
+ spacemit_espi_apply_controller_config(espi, 0);
+ ret = spacemit_espi_send_inband_reset(espi);
+ if (ret)
+ return ret;
+
+ ret = spacemit_espi_cmd_get_config(espi, ESPI_SLAVE_GEN_CFG, &slave_caps);
+ if (ret)
+ return ret;
+
+ cfg = spacemit_espi_build_negotiated_config(espi, slave_caps);
+ if (espi->enable_peri && !(cfg & ESPI_GEN_PERI_CHAN_SUP))
+ return -EOPNOTSUPP;
+
+ ret = spacemit_espi_configure_channels(espi, cfg);
+ if (ret)
+ return ret;
+ ret = spacemit_espi_cmd_set_config(espi, ESPI_SLAVE_GEN_CFG, cfg);
+ if (ret)
+ return ret;
+
+ /* Switch the source mux only after the slave accepts the new rate. */
+ ret = spacemit_espi_set_rate(espi,
+ FIELD_GET(ESPI_GEN_OP_FREQ_SEL_MASK, cfg));
+ if (ret)
+ return ret;
+
+ spacemit_espi_apply_controller_config(espi, cfg);
+ if (espi->enable_peri) {
+ ret = read_poll_timeout(spacemit_espi_cmd_get_config, err,
+ err || (channel & ESPI_CHANNEL_READY),
+ 1000, ESPI_CFG_TIMEOUT_US, false,
+ espi, ESPI_SLAVE_PERI_CFG, &channel);
+ if (err || ret)
+ return err ?: ret;
+ }
+
+ spacemit_espi_program_window(espi);
+
+ return 0;
+}
+
+/**
+ * spacemit_k3_espi_recover() - Reinitialize the controller and negotiate the link
+ * @dev: K3 eSPI controller device
+ *
+ * Context: Process context. This function may sleep.
+ * Return: 0 on success or a negative error code.
+ */
+int spacemit_k3_espi_recover(struct device *dev)
+{
+ struct spacemit_espi *espi;
+ int ret;
+
+ if (!dev)
+ return -EINVAL;
+
+ espi = dev_get_drvdata(dev);
+ if (!espi)
+ return -ENODEV;
+
+ mutex_lock(&espi->lock);
+ ret = spacemit_espi_init_locked(espi);
+ mutex_unlock(&espi->lock);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(spacemit_k3_espi_recover);
+
+static void spacemit_espi_cleanup(void *data)
+{
+ struct spacemit_espi *espi = data;
+
+ reset_control_assert(espi->resets);
+ spacemit_espi_disable_clks(espi);
+}
+
+static int spacemit_espi_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct spacemit_espi *espi;
+ struct resource *res;
+ int ret;
+
+ espi = devm_kzalloc(dev, sizeof(*espi), GFP_KERNEL);
+ if (!espi)
+ return -ENOMEM;
+
+ espi->dev = dev;
+ mutex_init(&espi->lock);
+
+ espi->num_clks = devm_clk_bulk_get_all(dev, &espi->clks);
+ if (espi->num_clks < 0)
+ return dev_err_probe(dev, espi->num_clks,
+ "failed to get clocks\n");
+
+ espi->sclk_src = devm_clk_get(dev, "sclk_src");
+ if (IS_ERR(espi->sclk_src))
+ return dev_err_probe(dev, PTR_ERR(espi->sclk_src),
+ "failed to get sclk source\n");
+
+ espi->sclk = devm_clk_get(dev, "sclk");
+ if (IS_ERR(espi->sclk))
+ return dev_err_probe(dev, PTR_ERR(espi->sclk),
+ "failed to get sclk\n");
+
+ espi->resets = devm_reset_control_array_get_optional_exclusive(dev);
+ if (IS_ERR(espi->resets))
+ return dev_err_probe(dev, PTR_ERR(espi->resets),
+ "failed to get resets\n");
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ espi->regs = devm_ioremap_resource(dev, res);
+ if (IS_ERR(espi->regs))
+ return PTR_ERR(espi->regs);
+
+ ret = spacemit_espi_parse_dt(pdev, espi);
+ if (ret)
+ return ret;
+ platform_set_drvdata(pdev, espi);
+
+ ret = spacemit_espi_enable_clks(dev, espi);
+ if (ret)
+ return ret;
+
+ ret = reset_control_deassert(espi->resets);
+ if (ret) {
+ dev_err_probe(dev, ret, "failed to deassert resets\n");
+ goto err_disable_clks;
+ }
+
+ ret = devm_add_action_or_reset(dev, spacemit_espi_cleanup, espi);
+ if (ret)
+ return ret;
+
+ ret = spacemit_k3_espi_recover(dev);
+ if (ret)
+ return dev_err_probe(dev, ret, "controller initialization failed\n");
+
+ ret = devm_of_platform_populate(dev);
+ if (ret)
+ return dev_err_probe(dev, ret, "failed to populate child devices\n");
+
+ return 0;
+
+err_disable_clks:
+ spacemit_espi_disable_clks(espi);
+ return ret;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int spacemit_espi_suspend_noirq(struct device *dev)
+{
+ struct spacemit_espi *espi = dev_get_drvdata(dev);
+
+ spacemit_espi_disable_clks(espi);
+ return 0;
+}
+
+static int spacemit_espi_resume_noirq(struct device *dev)
+{
+ return spacemit_k3_espi_recover(dev);
+}
+#endif
+
+static const struct dev_pm_ops spacemit_espi_pm_ops = {
+ SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(spacemit_espi_suspend_noirq,
+ spacemit_espi_resume_noirq)
+};
+
+static const struct of_device_id spacemit_espi_of_match[] = {
+ { .compatible = "spacemit,k3-espi" },
+ {}
+};
+MODULE_DEVICE_TABLE(of, spacemit_espi_of_match);
+
+static struct platform_driver spacemit_espi_driver = {
+ .probe = spacemit_espi_probe,
+ .driver = {
+ .name = "spacemit-k3-espi",
+ .of_match_table = spacemit_espi_of_match,
+ .pm = pm_ptr(&spacemit_espi_pm_ops),
+ },
+};
+module_platform_driver(spacemit_espi_driver);
+
+MODULE_DESCRIPTION("SpacemiT K3 eSPI controller driver");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/spacemit-k3-espi.h b/include/linux/spacemit-k3-espi.h
new file mode 100644
index 000000000000..a2a75e2b7f39
--- /dev/null
+++ b/include/linux/spacemit-k3-espi.h
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef _LINUX_SPACEMIT_K3_ESPI_H
+#define _LINUX_SPACEMIT_K3_ESPI_H
+
+#include <linux/errno.h>
+#include <linux/kconfig.h>
+
+struct device;
+
+#if IS_ENABLED(CONFIG_SPACEMIT_ESPI_BUS)
+int spacemit_k3_espi_recover(struct device *dev);
+#else
+static inline int spacemit_k3_espi_recover(struct device *dev)
+{
+ return -EOPNOTSUPP;
+}
+#endif
+
+#endif /* _LINUX_SPACEMIT_K3_ESPI_H */
--
2.43.0
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH v2 07/13] bus: Add SpacemiT K3 eSPI controller support
@ 2026-12-04 4:21 ` Wang Yang
0 siblings, 0 replies; 27+ messages in thread
From: Wang Yang @ 2026-12-04 4:21 UTC (permalink / raw)
To: linux-kernel
Cc: Yixun Lan, Troy Mitchell, Philipp Zabel, linux-riscv, spacemit
Initialize clocks, resets, link negotiation and windows before
populating EC children. Preserve unrelated asynchronous status bits,
clear completion before commands and use the negotiated clock source.
The controller is vendor-derived from revision 29b78afb484b,
originally authored by goumin <min.gou@spacemit.com>.
The AMD eSPI bus RFC (20260804115259.4065638-1-krishnamoorthi.m@amd.com)
was reviewed. Target/channel APIs, DT enumeration, MMIO peripheral
access and recovery integration remain discussion points; this
series does not claim that the platform-parent model is approved.
Select an I/O width supported by the endpoint and wiring. For the
peripheral channel, read its configuration at the negotiated rate
and wait for READY before programming the CPU window.
Prepared with OpenAI Codex assistance.
Signed-off-by: Wang Yang <yang.wang@deepcomputing.io>
---
drivers/bus/Kconfig | 10 +
drivers/bus/Makefile | 1 +
drivers/bus/spacemit-k3-espi.c | 799 +++++++++++++++++++++++++++++++
include/linux/spacemit-k3-espi.h | 20 +
4 files changed, 830 insertions(+)
create mode 100644 drivers/bus/spacemit-k3-espi.c
create mode 100644 include/linux/spacemit-k3-espi.h
diff --git a/drivers/bus/Kconfig b/drivers/bus/Kconfig
index e4b1db809187..4f47b23c996f 100644
--- a/drivers/bus/Kconfig
+++ b/drivers/bus/Kconfig
@@ -149,6 +149,16 @@ config STM32_DBG_BUS
platforms when the debug configuration is not accessible by the
normal world.
+config SPACEMIT_ESPI_BUS
+ bool "SpacemiT K3 eSPI controller"
+ depends on OF && HAS_IOMEM
+ depends on ARCH_SPACEMIT || COMPILE_TEST
+ help
+ Enable the SpacemiT K3 eSPI controller, including clock and reset
+ management, link initialization and recovery after an EC reboot.
+ Register child devices described in the device tree so their
+ drivers can access the peripheral shared-memory window.
+
config STM32_FIREWALL
bool "STM32 Firewall framework"
depends on (ARCH_STM32 || COMPILE_TEST) && OF
diff --git a/drivers/bus/Makefile b/drivers/bus/Makefile
index a01f97fef3e8..a59fc1901a9b 100644
--- a/drivers/bus/Makefile
+++ b/drivers/bus/Makefile
@@ -26,6 +26,7 @@ obj-$(CONFIG_OMAP_OCP2SCP) += omap-ocp2scp.o
obj-$(CONFIG_QCOM_EBI2) += qcom-ebi2.o
obj-$(CONFIG_QCOM_SSC_BLOCK_BUS) += qcom-ssc-block-bus.o
obj-$(CONFIG_STM32_DBG_BUS) += stm32_dbg_bus.o
+obj-$(CONFIG_SPACEMIT_ESPI_BUS) += spacemit-k3-espi.o
obj-$(CONFIG_STM32_FIREWALL) += stm32_firewall.o stm32_rifsc.o stm32_etzpc.o
obj-$(CONFIG_SUN50I_DE2_BUS) += sun50i-de2.o
obj-$(CONFIG_SUNXI_RSB) += sunxi-rsb.o
diff --git a/drivers/bus/spacemit-k3-espi.c b/drivers/bus/spacemit-k3-espi.c
new file mode 100644
index 000000000000..1e3a4d4f5235
--- /dev/null
+++ b/drivers/bus/spacemit-k3-espi.c
@@ -0,0 +1,799 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * SpacemiT K3 eSPI controller driver
+ *
+ * This driver owns controller-level initialization and recovery so child
+ * devices such as cros_ec_espi can treat the peripheral shared memory window
+ * as a transport and ask the parent controller to recover the link when the
+ * EC reboots underneath Linux.
+ */
+
+#include <linux/bitfield.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/reset.h>
+#include <linux/spacemit-k3-espi.h>
+#include <linux/wordpart.h>
+
+#define ESPI_DN_TXHDR 0x00
+#define ESPI_DN_TXDATA_PORT 0x0c
+#define ESPI_GLOBAL_CONTROL_0 0x30
+#define ESPI_GLOBAL_CONTROL_1 0x34
+#define ESPI_PR_BASE_ADDR_MEM0 0x38
+#define ESPI_PR_BASE_ADDR_MEM1 0x3c
+#define ESPI_SLAVE0_CONFIG 0x68
+#define ESPI_SLAVE0_INT_EN 0x6c
+#define ESPI_SLAVE0_INT_STS 0x70
+
+#define ESPI_DNCMD_TYPE_MASK GENMASK(2, 0)
+#define ESPI_DNCMD_EN BIT(3)
+#define ESPI_DNCMD_SLAVE_SEL_MASK GENMASK(5, 4)
+
+#define ESPI_DNCMD_SET_CONFIGURATION 0x00
+#define ESPI_DNCMD_GET_CONFIGURATION 0x01
+#define ESPI_DNCMD_IN_BAND_RESET 0x02
+
+#define ESPI_FLASH_REQ_INT BIT(31)
+#define ESPI_RXOOB_INT BIT(30)
+#define ESPI_RXMSG_INT BIT(29)
+#define ESPI_DNCMD_INT BIT(28)
+#define ESPI_RXVW_GRP3_INT BIT(27)
+#define ESPI_RXVW_GRP2_INT BIT(26)
+#define ESPI_RXVW_GRP1_INT BIT(25)
+#define ESPI_RXVW_GRP0_INT BIT(24)
+#define ESPI_PROTOCOL_ERR_INT BIT(15)
+#define ESPI_RXFLASH_OFLOW_INT BIT(14)
+#define ESPI_RXMSG_OFLOW_INT BIT(13)
+#define ESPI_RXOOB_OFLOW_INT BIT(12)
+#define ESPI_ILLEGAL_LEN_INT BIT(11)
+#define ESPI_ILLEGAL_TAG_INT BIT(10)
+#define ESPI_UNSUCSS_CPL_INT BIT(9)
+#define ESPI_INVALID_CT_RSP_INT BIT(8)
+#define ESPI_UNKNOWN_RSP_INT BIT(7)
+#define ESPI_NON_FATAL_INT BIT(6)
+#define ESPI_FATAL_ERR_INT BIT(5)
+#define ESPI_NO_RSP_INT BIT(4)
+#define ESPI_CRC_ERR_INT BIT(2)
+#define ESPI_WAIT_TIMEOUT_INT BIT(1)
+#define ESPI_BUS_ERR_INT BIT(0)
+
+#define ESPI_CALLBACK_INT (ESPI_FLASH_REQ_INT | \
+ ESPI_RXOOB_INT | \
+ ESPI_RXMSG_INT | \
+ ESPI_DNCMD_INT | \
+ ESPI_RXVW_GRP3_INT | \
+ ESPI_RXVW_GRP2_INT | \
+ ESPI_RXVW_GRP1_INT | \
+ ESPI_RXVW_GRP0_INT)
+#define ESPI_PROTOCOL_INT (ESPI_PROTOCOL_ERR_INT | \
+ ESPI_RXFLASH_OFLOW_INT | \
+ ESPI_RXMSG_OFLOW_INT | \
+ ESPI_RXOOB_OFLOW_INT | \
+ ESPI_ILLEGAL_LEN_INT | \
+ ESPI_ILLEGAL_TAG_INT | \
+ ESPI_UNSUCSS_CPL_INT | \
+ ESPI_INVALID_CT_RSP_INT | \
+ ESPI_UNKNOWN_RSP_INT | \
+ ESPI_CRC_ERR_INT | \
+ ESPI_WAIT_TIMEOUT_INT | \
+ ESPI_BUS_ERR_INT)
+#define ESPI_RESPONSE_INT (ESPI_NON_FATAL_INT | \
+ ESPI_FATAL_ERR_INT | \
+ ESPI_NO_RSP_INT)
+#define ESPI_ALL_INT (ESPI_CALLBACK_INT | \
+ ESPI_PROTOCOL_INT | \
+ ESPI_RESPONSE_INT)
+
+#define ESPI_MST_STOP_EN BIT(3)
+#define ESPI_CONTROL_WATCHDOG_EN BIT(0)
+#define ESPI_CONTROL_WATCHDOG_CNT_MASK GENMASK(23, 8)
+
+#define ESPI_CRC_CHECK_EN BIT(31)
+#define ESPI_ALERT_MODE_SEL BIT(30)
+#define ESPI_IO_MODE_SEL_MASK GENMASK(29, 28)
+#define ESPI_CLK_FREQ_SEL_MASK GENMASK(27, 25)
+#define ESPI_PR_CHANNEL_ENABLE BIT(3)
+#define ESPI_VW_CHANNEL_ENABLE BIT(2)
+#define ESPI_OOB_CHANNEL_ENABLE BIT(1)
+#define ESPI_FLASH_CHANNEL_ENABLE BIT(0)
+
+#define ESPI_ESPI_RSTN BIT(5)
+#define ESPI_SW_RST BIT(0)
+
+#define ESPI_SLAVE_GEN_CFG 0x08
+#define ESPI_SLAVE_PERI_CFG 0x10
+#define ESPI_SLAVE_VWIRE_CFG 0x20
+#define ESPI_SLAVE_OOB_CFG 0x30
+#define ESPI_SLAVE_FLASH_CFG 0x40
+#define ESPI_CHANNEL_READY BIT(1)
+
+#define ESPI_GEN_CRC_ENABLE BIT(31)
+#define ESPI_GEN_ALERT_MODE_PIN BIT(28)
+#define ESPI_GEN_IO_MODE_SUP_MASK GENMASK(25, 24)
+#define ESPI_GEN_OPEN_DRAIN_ALERT_SEL BIT(23)
+#define ESPI_GEN_OPEN_DRAIN_ALERT_SUP BIT(19)
+#define ESPI_GEN_OP_FREQ_SUP_MASK GENMASK(18, 16)
+#define ESPI_GEN_OP_FREQ_SEL_MASK GENMASK(22, 20)
+#define ESPI_GEN_IO_MODE_SEL_MASK GENMASK(27, 26)
+#define ESPI_GEN_FLASH_CHAN_SUP BIT(3)
+#define ESPI_GEN_OOB_CHAN_SUP BIT(2)
+#define ESPI_GEN_VWIRE_CHAN_SUP BIT(1)
+#define ESPI_GEN_PERI_CHAN_SUP BIT(0)
+
+#define ESPI_GEN_IO_MODE_SINGLE 0x0
+#define ESPI_GEN_IO_MODE_DUAL 0x1
+#define ESPI_GEN_IO_MODE_QUAD 0x2
+
+#define ESPI_GEN_OP_FREQ_20MHZ 0x0
+#define ESPI_GEN_OP_FREQ_25MHZ 0x1
+#define ESPI_GEN_OP_FREQ_33MHZ 0x2
+#define ESPI_GEN_OP_FREQ_50MHZ 0x3
+#define ESPI_GEN_OP_FREQ_66MHZ 0x4
+
+#define ESPI_ENABLE_PR_CHANNEL 0x1115
+#define ESPI_ENABLE_VW_CHANNEL 0x70701
+#define ESPI_ENABLE_OOB_CHANNEL 0x111
+#define ESPI_ENABLE_FLASH_CHANNEL 0x11125
+
+#define ESPI_CFG_TIMEOUT_US 50000
+#define ESPI_TX_IDLE_TIMEOUT_US 1000
+
+#define SPACEMIT_ESPI_DEFAULT_FREQ_HZ 20000000
+#define SPACEMIT_ESPI_DEFAULT_WDT 0xffff
+
+struct spacemit_espi {
+ struct device *dev;
+ struct clk_bulk_data *clks;
+ int num_clks;
+ struct clk *sclk;
+ struct clk *sclk_src;
+ struct reset_control *resets;
+ bool clocks_enabled;
+ void __iomem *regs;
+ u32 pr_mem_base0;
+ u32 pr_mem_base1;
+ u32 max_freq_hz;
+ u32 watchdog_timeout;
+ u32 io_mode;
+ bool alert_pin_mode;
+ bool alert_open_drain;
+ bool crc_enable;
+ bool enable_peri;
+ bool enable_vwire;
+ bool enable_oob;
+ bool enable_flash;
+ bool auto_gating;
+ /* Serialize controller setup, PM and EC-triggered link recovery. */
+ struct mutex lock;
+};
+
+static u32 spacemit_espi_txhdr_reg(unsigned int index)
+{
+ return ESPI_DN_TXHDR + ((index + 1) & ~0x3);
+}
+
+static u32 spacemit_espi_txhdr_shift(unsigned int index)
+{
+ return ((index + 1) & 0x3) * 8;
+}
+
+static void spacemit_espi_write_hdr(struct spacemit_espi *espi, unsigned int index,
+ u8 value)
+{
+ u32 reg = spacemit_espi_txhdr_reg(index);
+ u32 shift = spacemit_espi_txhdr_shift(index);
+ u32 data;
+
+ data = readl(espi->regs + reg);
+ data &= ~(GENMASK(7, 0) << shift);
+ data |= (u32)value << shift;
+ writel(data, espi->regs + reg);
+}
+
+static u8 spacemit_espi_read_hdr(struct spacemit_espi *espi, unsigned int index)
+{
+ u32 reg = spacemit_espi_txhdr_reg(index);
+ u32 shift = spacemit_espi_txhdr_shift(index);
+
+ return (readl(espi->regs + reg) >> shift) & 0xff;
+}
+
+static void spacemit_espi_trigger_cmd(struct spacemit_espi *espi, u32 cmd_type)
+{
+ u32 val;
+
+ /* Clear stale command status before the transfer can complete. */
+ writel(ESPI_DNCMD_INT | ESPI_PROTOCOL_INT | ESPI_RESPONSE_INT,
+ espi->regs + ESPI_SLAVE0_INT_STS);
+
+ val = readl(espi->regs + ESPI_DN_TXHDR);
+ val &= ~(ESPI_DNCMD_TYPE_MASK | ESPI_DNCMD_EN |
+ ESPI_DNCMD_SLAVE_SEL_MASK);
+ val |= FIELD_PREP(ESPI_DNCMD_TYPE_MASK, cmd_type);
+ val |= ESPI_DNCMD_EN;
+ writel(val, espi->regs + ESPI_DN_TXHDR);
+}
+
+static int spacemit_espi_wait_tx_idle(struct spacemit_espi *espi)
+{
+ unsigned int timeout = ESPI_TX_IDLE_TIMEOUT_US;
+
+ do {
+ if (!(readl(espi->regs + ESPI_DN_TXHDR) & ESPI_DNCMD_EN))
+ return 0;
+ udelay(1);
+ } while (--timeout);
+
+ return -EBUSY;
+}
+
+static int spacemit_espi_poll_status(struct spacemit_espi *espi, u32 expected)
+{
+ unsigned int timeout = ESPI_CFG_TIMEOUT_US / 10;
+ u32 status;
+
+ do {
+ status = readl(espi->regs + ESPI_SLAVE0_INT_STS);
+ status &= expected | ESPI_PROTOCOL_INT | ESPI_RESPONSE_INT;
+ if (!status) {
+ fsleep(10);
+ continue;
+ }
+
+ writel(status, espi->regs + ESPI_SLAVE0_INT_STS);
+
+ if (status & (ESPI_PROTOCOL_INT | ESPI_RESPONSE_INT))
+ return -EIO;
+
+ if (status & expected)
+ return 0;
+
+ fsleep(10);
+ } while (--timeout);
+
+ return -ETIMEDOUT;
+}
+
+static int spacemit_espi_cmd_get_config(struct spacemit_espi *espi, u16 addr, u32 *value)
+{
+ int ret;
+
+ spacemit_espi_write_hdr(espi, 0, 0);
+ spacemit_espi_write_hdr(espi, 1, addr >> 8);
+ spacemit_espi_write_hdr(espi, 2, addr);
+ spacemit_espi_trigger_cmd(espi, ESPI_DNCMD_GET_CONFIGURATION);
+
+ ret = spacemit_espi_poll_status(espi, ESPI_DNCMD_INT);
+ if (ret)
+ return ret;
+
+ *value = spacemit_espi_read_hdr(espi, 3);
+ *value |= (u32)spacemit_espi_read_hdr(espi, 4) << 8;
+ *value |= (u32)spacemit_espi_read_hdr(espi, 5) << 16;
+ *value |= (u32)spacemit_espi_read_hdr(espi, 6) << 24;
+
+ return 0;
+}
+
+static int spacemit_espi_cmd_set_config(struct spacemit_espi *espi, u16 addr, u32 value)
+{
+ spacemit_espi_write_hdr(espi, 0, 0);
+ spacemit_espi_write_hdr(espi, 1, addr >> 8);
+ spacemit_espi_write_hdr(espi, 2, addr);
+ spacemit_espi_write_hdr(espi, 3, value);
+ spacemit_espi_write_hdr(espi, 4, value >> 8);
+ spacemit_espi_write_hdr(espi, 5, value >> 16);
+ spacemit_espi_write_hdr(espi, 6, value >> 24);
+ spacemit_espi_trigger_cmd(espi, ESPI_DNCMD_SET_CONFIGURATION);
+
+ return spacemit_espi_poll_status(espi, ESPI_DNCMD_INT);
+}
+
+static void spacemit_espi_enable_irqs(struct spacemit_espi *espi)
+{
+ writel(ESPI_ALL_INT, espi->regs + ESPI_SLAVE0_INT_EN);
+}
+
+static void spacemit_espi_reset_controller(struct spacemit_espi *espi)
+{
+ u32 val;
+
+ val = readl(espi->regs + ESPI_GLOBAL_CONTROL_1);
+ val &= ~ESPI_ESPI_RSTN;
+ writel(val, espi->regs + ESPI_GLOBAL_CONTROL_1);
+
+ val = readl(espi->regs + ESPI_GLOBAL_CONTROL_1);
+ val |= ESPI_ESPI_RSTN | ESPI_SW_RST;
+ writel(val, espi->regs + ESPI_GLOBAL_CONTROL_1);
+}
+
+static int spacemit_espi_send_inband_reset(struct spacemit_espi *espi)
+{
+ int ret;
+
+ spacemit_espi_trigger_cmd(espi, ESPI_DNCMD_IN_BAND_RESET);
+ ret = spacemit_espi_wait_tx_idle(espi);
+ if (ret)
+ return ret;
+ fsleep(1000);
+ writel(ESPI_DNCMD_INT | ESPI_PROTOCOL_INT | ESPI_RESPONSE_INT,
+ espi->regs + ESPI_SLAVE0_INT_STS);
+
+ return 0;
+}
+
+static u32 spacemit_espi_freq_to_sel(u32 hz)
+{
+ switch (hz) {
+ case 66666666:
+ return ESPI_GEN_OP_FREQ_66MHZ;
+ case 50000000:
+ return ESPI_GEN_OP_FREQ_50MHZ;
+ case 33333333:
+ return ESPI_GEN_OP_FREQ_33MHZ;
+ case 25000000:
+ return ESPI_GEN_OP_FREQ_25MHZ;
+ case 20000000:
+ default:
+ return ESPI_GEN_OP_FREQ_20MHZ;
+ }
+}
+
+static int spacemit_espi_set_rate(struct spacemit_espi *espi, u32 sel)
+{
+ static const unsigned long rates[] = {
+ 20000000, 25000000, 33333333, 50000000, 66666666,
+ };
+ int ret;
+
+ if (sel >= ARRAY_SIZE(rates))
+ return -EINVAL;
+
+ ret = clk_set_rate(espi->sclk_src, rates[sel]);
+ if (ret)
+ return ret;
+
+ if (clk_get_rate(espi->sclk_src) != rates[sel] ||
+ clk_get_rate(espi->sclk) != rates[sel])
+ return -EINVAL;
+
+ return 0;
+}
+
+static u32 spacemit_espi_build_negotiated_config(struct spacemit_espi *espi,
+ u32 slave_caps)
+{
+ u32 cfg = 0;
+ u32 io_caps = FIELD_GET(ESPI_GEN_IO_MODE_SUP_MASK, slave_caps);
+ u32 io_mode = ESPI_GEN_IO_MODE_SINGLE;
+ u32 freq;
+
+ if (espi->crc_enable)
+ cfg |= ESPI_GEN_CRC_ENABLE;
+
+ if (espi->alert_pin_mode) {
+ cfg |= ESPI_GEN_ALERT_MODE_PIN;
+ if (espi->alert_open_drain &&
+ (slave_caps & ESPI_GEN_OPEN_DRAIN_ALERT_SUP))
+ cfg |= ESPI_GEN_OPEN_DRAIN_ALERT_SEL;
+ }
+
+ if (espi->io_mode == ESPI_GEN_IO_MODE_QUAD && (io_caps & BIT(1)))
+ io_mode = ESPI_GEN_IO_MODE_QUAD;
+ else if (espi->io_mode >= ESPI_GEN_IO_MODE_DUAL && (io_caps & BIT(0)))
+ io_mode = ESPI_GEN_IO_MODE_DUAL;
+ freq = min_t(u32, spacemit_espi_freq_to_sel(espi->max_freq_hz),
+ FIELD_GET(ESPI_GEN_OP_FREQ_SUP_MASK, slave_caps));
+ cfg |= FIELD_PREP(ESPI_GEN_IO_MODE_SEL_MASK, io_mode);
+ cfg |= FIELD_PREP(ESPI_GEN_OP_FREQ_SEL_MASK, freq);
+
+ if (espi->enable_peri && (slave_caps & ESPI_GEN_PERI_CHAN_SUP))
+ cfg |= ESPI_GEN_PERI_CHAN_SUP;
+ if (espi->enable_vwire && (slave_caps & ESPI_GEN_VWIRE_CHAN_SUP))
+ cfg |= ESPI_GEN_VWIRE_CHAN_SUP;
+ if (espi->enable_oob && (slave_caps & ESPI_GEN_OOB_CHAN_SUP))
+ cfg |= ESPI_GEN_OOB_CHAN_SUP;
+ if (espi->enable_flash && (slave_caps & ESPI_GEN_FLASH_CHAN_SUP))
+ cfg |= ESPI_GEN_FLASH_CHAN_SUP;
+
+ return cfg;
+}
+
+static int spacemit_espi_configure_channels(struct spacemit_espi *espi, u32 cfg)
+{
+ int ret;
+
+ if (cfg & ESPI_GEN_PERI_CHAN_SUP) {
+ ret = spacemit_espi_cmd_set_config(espi, ESPI_SLAVE_PERI_CFG,
+ ESPI_ENABLE_PR_CHANNEL);
+ if (ret)
+ return ret;
+ }
+
+ if (cfg & ESPI_GEN_VWIRE_CHAN_SUP) {
+ ret = spacemit_espi_cmd_set_config(espi, ESPI_SLAVE_VWIRE_CFG,
+ ESPI_ENABLE_VW_CHANNEL);
+ if (ret)
+ return ret;
+ }
+
+ if (cfg & ESPI_GEN_OOB_CHAN_SUP) {
+ ret = spacemit_espi_cmd_set_config(espi, ESPI_SLAVE_OOB_CFG,
+ ESPI_ENABLE_OOB_CHANNEL);
+ if (ret)
+ return ret;
+ }
+
+ if (cfg & ESPI_GEN_FLASH_CHAN_SUP) {
+ ret = spacemit_espi_cmd_set_config(espi, ESPI_SLAVE_FLASH_CFG,
+ ESPI_ENABLE_FLASH_CHANNEL);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+static void spacemit_espi_apply_controller_config(struct spacemit_espi *espi, u32 cfg)
+{
+ u32 val;
+ u32 mask = ESPI_CRC_CHECK_EN | ESPI_ALERT_MODE_SEL |
+ ESPI_IO_MODE_SEL_MASK | ESPI_CLK_FREQ_SEL_MASK |
+ ESPI_PR_CHANNEL_ENABLE | ESPI_VW_CHANNEL_ENABLE |
+ ESPI_OOB_CHANNEL_ENABLE | ESPI_FLASH_CHANNEL_ENABLE;
+
+ val = readl(espi->regs + ESPI_SLAVE0_CONFIG);
+ val &= ~mask;
+
+ if (cfg & ESPI_GEN_CRC_ENABLE)
+ val |= ESPI_CRC_CHECK_EN;
+ if (cfg & ESPI_GEN_ALERT_MODE_PIN)
+ val |= ESPI_ALERT_MODE_SEL;
+
+ val |= FIELD_PREP(ESPI_IO_MODE_SEL_MASK,
+ FIELD_GET(ESPI_GEN_IO_MODE_SEL_MASK, cfg));
+ val |= FIELD_PREP(ESPI_CLK_FREQ_SEL_MASK,
+ FIELD_GET(ESPI_GEN_OP_FREQ_SEL_MASK, cfg));
+
+ if (cfg & ESPI_GEN_PERI_CHAN_SUP)
+ val |= ESPI_PR_CHANNEL_ENABLE;
+ if (cfg & ESPI_GEN_VWIRE_CHAN_SUP)
+ val |= ESPI_VW_CHANNEL_ENABLE;
+ if (cfg & ESPI_GEN_OOB_CHAN_SUP)
+ val |= ESPI_OOB_CHANNEL_ENABLE;
+ if (cfg & ESPI_GEN_FLASH_CHAN_SUP)
+ val |= ESPI_FLASH_CHANNEL_ENABLE;
+
+ writel(val, espi->regs + ESPI_SLAVE0_CONFIG);
+}
+
+static void spacemit_espi_program_window(struct spacemit_espi *espi)
+{
+ u32 val;
+
+ val = readl(espi->regs + ESPI_GLOBAL_CONTROL_0);
+ val &= ~(ESPI_CONTROL_WATCHDOG_CNT_MASK | ESPI_MST_STOP_EN);
+ val |= ESPI_CONTROL_WATCHDOG_EN;
+ val |= FIELD_PREP(ESPI_CONTROL_WATCHDOG_CNT_MASK,
+ espi->watchdog_timeout);
+ if (espi->auto_gating)
+ val |= ESPI_MST_STOP_EN;
+ writel(val, espi->regs + ESPI_GLOBAL_CONTROL_0);
+
+ writel(espi->pr_mem_base0, espi->regs + ESPI_PR_BASE_ADDR_MEM0);
+ writel(espi->pr_mem_base1, espi->regs + ESPI_PR_BASE_ADDR_MEM1);
+}
+
+static int spacemit_espi_parse_dt(struct platform_device *pdev,
+ struct spacemit_espi *espi)
+{
+ struct device *dev = &pdev->dev;
+ struct device_node *np = dev->of_node;
+ struct resource range;
+ const char *str;
+ int ret;
+
+ espi->max_freq_hz = SPACEMIT_ESPI_DEFAULT_FREQ_HZ;
+ of_property_read_u32(np, "max-frequency", &espi->max_freq_hz);
+ if (espi->max_freq_hz != 20000000 && espi->max_freq_hz != 25000000 &&
+ espi->max_freq_hz != 33333333 && espi->max_freq_hz != 50000000 &&
+ espi->max_freq_hz != 66666666)
+ return dev_err_probe(dev, -EINVAL, "unsupported link frequency\n");
+
+ espi->watchdog_timeout = SPACEMIT_ESPI_DEFAULT_WDT;
+ of_property_read_u32(np, "spacemit,watchdog-timeout", &espi->watchdog_timeout);
+ if (espi->watchdog_timeout > SPACEMIT_ESPI_DEFAULT_WDT)
+ return -EINVAL;
+
+ ret = of_range_to_resource(np, 0, &range);
+ if (ret)
+ return dev_err_probe(dev, ret, "missing peripheral memory range\n");
+ if (upper_32_bits(range.start))
+ return -EINVAL;
+ espi->pr_mem_base0 = lower_32_bits(range.start);
+
+ ret = of_property_read_u32(np, "spacemit,pr-mem-base1", &espi->pr_mem_base1);
+ if (ret)
+ return dev_err_probe(dev, ret, "missing peripheral memory window 1 base\n");
+
+ if (!of_property_read_string(np, "spacemit,io-mode", &str)) {
+ if (!strcmp(str, "quad"))
+ espi->io_mode = ESPI_GEN_IO_MODE_QUAD;
+ else if (!strcmp(str, "dual"))
+ espi->io_mode = ESPI_GEN_IO_MODE_DUAL;
+ else
+ espi->io_mode = ESPI_GEN_IO_MODE_SINGLE;
+ } else {
+ espi->io_mode = ESPI_GEN_IO_MODE_SINGLE;
+ }
+
+ if (!of_property_read_string(np, "spacemit,alert-mode", &str))
+ espi->alert_pin_mode = !strcmp(str, "pin");
+ else
+ espi->alert_pin_mode = false;
+
+ if (!of_property_read_string(np, "spacemit,alert-type", &str))
+ espi->alert_open_drain = !strcmp(str, "open-drain");
+ else
+ espi->alert_open_drain = true;
+
+ espi->crc_enable = of_property_read_bool(np, "spacemit,crc-enable");
+ espi->enable_peri = of_property_read_bool(np, "spacemit,peripheral-channel-enable");
+ if (!espi->enable_peri && of_get_available_child_count(np))
+ return dev_err_probe(dev, -EINVAL, "EC requires the peripheral channel\n");
+ espi->enable_vwire = of_property_read_bool(np, "spacemit,vwire-channel-enable");
+ espi->enable_oob = of_property_read_bool(np, "spacemit,oob-channel-enable");
+ espi->enable_flash = of_property_read_bool(np, "spacemit,flash-channel-enable");
+ espi->auto_gating = of_property_read_bool(np, "spacemit,auto-gating-enable");
+
+ return 0;
+}
+
+static int spacemit_espi_enable_clks(struct device *dev, struct spacemit_espi *espi)
+{
+ int ret;
+
+ if (!espi->num_clks || espi->clocks_enabled)
+ return 0;
+
+ ret = clk_bulk_prepare_enable(espi->num_clks, espi->clks);
+ if (ret) {
+ dev_err(dev, "failed to enable clocks: %d\n", ret);
+ return ret;
+ }
+
+ espi->clocks_enabled = true;
+ return 0;
+}
+
+static void spacemit_espi_disable_clks(struct spacemit_espi *espi)
+{
+ if (!espi->num_clks || !espi->clocks_enabled)
+ return;
+
+ clk_bulk_disable_unprepare(espi->num_clks, espi->clks);
+ espi->clocks_enabled = false;
+}
+
+static int spacemit_espi_init_locked(struct spacemit_espi *espi)
+{
+ u32 slave_caps = 0;
+ u32 channel;
+ u32 cfg;
+ int err, ret;
+
+ ret = spacemit_espi_enable_clks(espi->dev, espi);
+ if (ret)
+ return ret;
+
+ ret = reset_control_deassert(espi->resets);
+ if (ret)
+ return ret;
+
+ ret = clk_set_parent(espi->sclk, espi->sclk_src);
+ if (ret)
+ return ret;
+ ret = spacemit_espi_set_rate(espi, ESPI_GEN_OP_FREQ_20MHZ);
+ if (ret)
+ return ret;
+
+ spacemit_espi_enable_irqs(espi);
+ writel(ESPI_ALL_INT, espi->regs + ESPI_SLAVE0_INT_STS);
+
+ spacemit_espi_reset_controller(espi);
+ /* In-band reset and capability negotiation start at 20 MHz, single IO. */
+ spacemit_espi_apply_controller_config(espi, 0);
+ ret = spacemit_espi_send_inband_reset(espi);
+ if (ret)
+ return ret;
+
+ ret = spacemit_espi_cmd_get_config(espi, ESPI_SLAVE_GEN_CFG, &slave_caps);
+ if (ret)
+ return ret;
+
+ cfg = spacemit_espi_build_negotiated_config(espi, slave_caps);
+ if (espi->enable_peri && !(cfg & ESPI_GEN_PERI_CHAN_SUP))
+ return -EOPNOTSUPP;
+
+ ret = spacemit_espi_configure_channels(espi, cfg);
+ if (ret)
+ return ret;
+ ret = spacemit_espi_cmd_set_config(espi, ESPI_SLAVE_GEN_CFG, cfg);
+ if (ret)
+ return ret;
+
+ /* Switch the source mux only after the slave accepts the new rate. */
+ ret = spacemit_espi_set_rate(espi,
+ FIELD_GET(ESPI_GEN_OP_FREQ_SEL_MASK, cfg));
+ if (ret)
+ return ret;
+
+ spacemit_espi_apply_controller_config(espi, cfg);
+ if (espi->enable_peri) {
+ ret = read_poll_timeout(spacemit_espi_cmd_get_config, err,
+ err || (channel & ESPI_CHANNEL_READY),
+ 1000, ESPI_CFG_TIMEOUT_US, false,
+ espi, ESPI_SLAVE_PERI_CFG, &channel);
+ if (err || ret)
+ return err ?: ret;
+ }
+
+ spacemit_espi_program_window(espi);
+
+ return 0;
+}
+
+/**
+ * spacemit_k3_espi_recover() - Reinitialize the controller and negotiate the link
+ * @dev: K3 eSPI controller device
+ *
+ * Context: Process context. This function may sleep.
+ * Return: 0 on success or a negative error code.
+ */
+int spacemit_k3_espi_recover(struct device *dev)
+{
+ struct spacemit_espi *espi;
+ int ret;
+
+ if (!dev)
+ return -EINVAL;
+
+ espi = dev_get_drvdata(dev);
+ if (!espi)
+ return -ENODEV;
+
+ mutex_lock(&espi->lock);
+ ret = spacemit_espi_init_locked(espi);
+ mutex_unlock(&espi->lock);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(spacemit_k3_espi_recover);
+
+static void spacemit_espi_cleanup(void *data)
+{
+ struct spacemit_espi *espi = data;
+
+ reset_control_assert(espi->resets);
+ spacemit_espi_disable_clks(espi);
+}
+
+static int spacemit_espi_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct spacemit_espi *espi;
+ struct resource *res;
+ int ret;
+
+ espi = devm_kzalloc(dev, sizeof(*espi), GFP_KERNEL);
+ if (!espi)
+ return -ENOMEM;
+
+ espi->dev = dev;
+ mutex_init(&espi->lock);
+
+ espi->num_clks = devm_clk_bulk_get_all(dev, &espi->clks);
+ if (espi->num_clks < 0)
+ return dev_err_probe(dev, espi->num_clks,
+ "failed to get clocks\n");
+
+ espi->sclk_src = devm_clk_get(dev, "sclk_src");
+ if (IS_ERR(espi->sclk_src))
+ return dev_err_probe(dev, PTR_ERR(espi->sclk_src),
+ "failed to get sclk source\n");
+
+ espi->sclk = devm_clk_get(dev, "sclk");
+ if (IS_ERR(espi->sclk))
+ return dev_err_probe(dev, PTR_ERR(espi->sclk),
+ "failed to get sclk\n");
+
+ espi->resets = devm_reset_control_array_get_optional_exclusive(dev);
+ if (IS_ERR(espi->resets))
+ return dev_err_probe(dev, PTR_ERR(espi->resets),
+ "failed to get resets\n");
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ espi->regs = devm_ioremap_resource(dev, res);
+ if (IS_ERR(espi->regs))
+ return PTR_ERR(espi->regs);
+
+ ret = spacemit_espi_parse_dt(pdev, espi);
+ if (ret)
+ return ret;
+ platform_set_drvdata(pdev, espi);
+
+ ret = spacemit_espi_enable_clks(dev, espi);
+ if (ret)
+ return ret;
+
+ ret = reset_control_deassert(espi->resets);
+ if (ret) {
+ dev_err_probe(dev, ret, "failed to deassert resets\n");
+ goto err_disable_clks;
+ }
+
+ ret = devm_add_action_or_reset(dev, spacemit_espi_cleanup, espi);
+ if (ret)
+ return ret;
+
+ ret = spacemit_k3_espi_recover(dev);
+ if (ret)
+ return dev_err_probe(dev, ret, "controller initialization failed\n");
+
+ ret = devm_of_platform_populate(dev);
+ if (ret)
+ return dev_err_probe(dev, ret, "failed to populate child devices\n");
+
+ return 0;
+
+err_disable_clks:
+ spacemit_espi_disable_clks(espi);
+ return ret;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int spacemit_espi_suspend_noirq(struct device *dev)
+{
+ struct spacemit_espi *espi = dev_get_drvdata(dev);
+
+ spacemit_espi_disable_clks(espi);
+ return 0;
+}
+
+static int spacemit_espi_resume_noirq(struct device *dev)
+{
+ return spacemit_k3_espi_recover(dev);
+}
+#endif
+
+static const struct dev_pm_ops spacemit_espi_pm_ops = {
+ SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(spacemit_espi_suspend_noirq,
+ spacemit_espi_resume_noirq)
+};
+
+static const struct of_device_id spacemit_espi_of_match[] = {
+ { .compatible = "spacemit,k3-espi" },
+ {}
+};
+MODULE_DEVICE_TABLE(of, spacemit_espi_of_match);
+
+static struct platform_driver spacemit_espi_driver = {
+ .probe = spacemit_espi_probe,
+ .driver = {
+ .name = "spacemit-k3-espi",
+ .of_match_table = spacemit_espi_of_match,
+ .pm = pm_ptr(&spacemit_espi_pm_ops),
+ },
+};
+module_platform_driver(spacemit_espi_driver);
+
+MODULE_DESCRIPTION("SpacemiT K3 eSPI controller driver");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/spacemit-k3-espi.h b/include/linux/spacemit-k3-espi.h
new file mode 100644
index 000000000000..a2a75e2b7f39
--- /dev/null
+++ b/include/linux/spacemit-k3-espi.h
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef _LINUX_SPACEMIT_K3_ESPI_H
+#define _LINUX_SPACEMIT_K3_ESPI_H
+
+#include <linux/errno.h>
+#include <linux/kconfig.h>
+
+struct device;
+
+#if IS_ENABLED(CONFIG_SPACEMIT_ESPI_BUS)
+int spacemit_k3_espi_recover(struct device *dev);
+#else
+static inline int spacemit_k3_espi_recover(struct device *dev)
+{
+ return -EOPNOTSUPP;
+}
+#endif
+
+#endif /* _LINUX_SPACEMIT_K3_ESPI_H */
--
2.43.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v2 08/13] platform/chrome: Allow ChromeOS platform support on RISC-V
2026-12-04 4:20 ` Wang Yang
` (7 preceding siblings ...)
(?)
@ 2026-12-04 4:21 ` Wang Yang
-1 siblings, 0 replies; 27+ messages in thread
From: Wang Yang @ 2026-12-04 4:21 UTC (permalink / raw)
To: linux-kernel; +Cc: Benson Leung, Tzung-Bi Shih, chrome-platform
Allow RISC-V boards to enable ChromeOS EC and its child drivers
without selecting COMPILE_TEST.
Prepared with OpenAI Codex assistance.
Signed-off-by: Wang Yang <yang.wang@deepcomputing.io>
---
drivers/platform/chrome/Kconfig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/platform/chrome/Kconfig b/drivers/platform/chrome/Kconfig
index 2c11eb4ec95d..2e4fec3820f5 100644
--- a/drivers/platform/chrome/Kconfig
+++ b/drivers/platform/chrome/Kconfig
@@ -5,7 +5,7 @@
menuconfig CHROME_PLATFORMS
bool "Platform support for Chrome hardware"
- depends on X86 || ARM || ARM64 || COMPILE_TEST
+ depends on X86 || ARM || ARM64 || RISCV || COMPILE_TEST
depends on !CPU_BIG_ENDIAN || COMPILE_TEST
help
Say Y here to get to see options for platform support for
--
2.43.0
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH v2 09/13] platform/chrome: Add SpacemiT K3 eSPI EC transport
2026-12-04 4:20 ` Wang Yang
@ 2026-12-04 4:21 ` Wang Yang
-1 siblings, 0 replies; 27+ messages in thread
From: Wang Yang @ 2026-12-04 4:21 UTC (permalink / raw)
To: linux-kernel
Cc: Benson Leung, Tzung-Bi Shih, Yixun Lan, Troy Mitchell,
Guenter Roeck, chrome-platform, linux-riscv, spacemit
Map the K3 non-linear window and reuse the common LPC-style protocol
helpers. Keep K3 readiness, five-second timeout and link recovery
in the vendor backend. Recover a timed-out link without replaying
a command that may already have executed. Let the EC core request
the firmware-configured event IRQ.
Use module cros_ec_espi_spacemit, CONFIG_CROS_EC_SPACEMIT_K3 and
compatible spacemit,k3-cros-ec. This is a K3-specific interface.
Require the firmware event IRQ before accessing the EC. Serialize host
commands and direct memory reads with link recovery. Retry transient
negotiation failures, then wait for the EC ID on the established link.
Give the already negotiated link time to publish its ID before resetting
it at probe. Recover synchronously during protocol negotiation. Once
the core installs the dedicated GPIO IRQ action, defer link recovery to
a workqueue so the GPIO bank thread can service other pins. Prevent
queued recovery from outliving a failed probe. Reject window accesses
while recovery is active. Check request and response sizes against the
K3 packet window.
Check a pending link recovery before enabling the event IRQ on resume.
Prepared with OpenAI Codex assistance.
Signed-off-by: Wang Yang <yang.wang@deepcomputing.io>
---
drivers/platform/chrome/Kconfig | 12 +
drivers/platform/chrome/Makefile | 1 +
.../platform/chrome/cros_ec_espi_spacemit.c | 568 ++++++++++++++++++
3 files changed, 581 insertions(+)
create mode 100644 drivers/platform/chrome/cros_ec_espi_spacemit.c
diff --git a/drivers/platform/chrome/Kconfig b/drivers/platform/chrome/Kconfig
index 2e4fec3820f5..11a8320b202d 100644
--- a/drivers/platform/chrome/Kconfig
+++ b/drivers/platform/chrome/Kconfig
@@ -160,6 +160,18 @@ config CROS_EC_LPC
To compile this driver as a module, choose M here: the
module will be called cros_ec_lpcs.
+config CROS_EC_SPACEMIT_K3
+ tristate "SpacemiT K3 ChromeOS EC over eSPI"
+ depends on CROS_EC && SPACEMIT_ESPI_BUS
+ select CROS_EC_LPC_PROTO
+ help
+ Support a ChromeOS EC connected through the SpacemiT K3 eSPI
+ peripheral shared-memory window. The transport supports host
+ command protocol versions 2 and 3 and EC event interrupts.
+
+ To compile this driver as a module, choose M here: the module
+ will be called cros_ec_espi_spacemit.
+
config CROS_EC_PROTO
tristate
help
diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/Makefile
index 00d3d9fba1e0..a0731d359104 100644
--- a/drivers/platform/chrome/Makefile
+++ b/drivers/platform/chrome/Makefile
@@ -15,6 +15,7 @@ obj-$(CONFIG_CROS_EC_I2C) += cros_ec_i2c.o
obj-$(CONFIG_CROS_EC_ISHTP) += cros_ec_ishtp.o
obj-$(CONFIG_CROS_TYPEC_SWITCH) += cros_typec_switch.o
obj-$(CONFIG_CROS_EC_RPMSG) += cros_ec_rpmsg.o
+obj-$(CONFIG_CROS_EC_SPACEMIT_K3) += cros_ec_espi_spacemit.o
obj-$(CONFIG_CROS_EC_SPI) += cros_ec_spi.o
obj-$(CONFIG_CROS_EC_UART) += cros_ec_uart.o
cros_ec_lpcs-objs := cros_ec_lpc.o cros_ec_lpc_mec.o
diff --git a/drivers/platform/chrome/cros_ec_espi_spacemit.c b/drivers/platform/chrome/cros_ec_espi_spacemit.c
new file mode 100644
index 000000000000..cb5c37d1a24d
--- /dev/null
+++ b/drivers/platform/chrome/cros_ec_espi_spacemit.c
@@ -0,0 +1,568 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * ChromeOS EC interface for the SpacemiT K3 eSPI controller
+ *
+ * Copyright (c) 2012 The Chromium OS Authors.
+ * Copyright (c) 2024 SpacemiT, Inc.
+ *
+ * This driver provides the SpacemiT K3 eSPI window for ChromeOS EC communication.
+ * It converts LPC I/O port accesses to eSPI shared memory accesses while maintaining
+ * compatibility with the existing ChromeOS EC protocol stack.
+ */
+
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/jiffies.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/platform_data/cros_ec_commands.h>
+#include <linux/platform_data/cros_ec_proto.h>
+#include <linux/platform_device.h>
+#include <linux/pm_wakeup.h>
+#include <linux/slab.h>
+#include <linux/spacemit-k3-espi.h>
+#include <linux/suspend.h>
+#include <linux/workqueue.h>
+
+#include "cros_ec.h"
+#include "cros_ec_lpc_proto.h"
+
+#define DRV_NAME "cros_ec_espi_spacemit"
+
+/* eSPI shared memory access timeout */
+#define ESPI_CMD_TIMEOUT_MS 5000
+
+/*
+ * After an EC reboot the transport may recover well before the EC firmware
+ * finishes repopulating the shared memory window. Allow a longer grace period
+ * here so the first post-reboot command does not immediately fall into another
+ * full timeout cycle.
+ */
+#define ESPI_READY_TIMEOUT_MS 20000
+#define ESPI_READY_POLL_INTERVAL_US 20000
+#define ESPI_RECOVERY_RETRY_INTERVAL_MS 5000
+#define ESPI_INVALID_STATUS_VALUE 0xff
+#define ESPI_INVALID_STATUS_MAX_POLLS 5
+
+/*
+ * eSPI Shared Memory Address Mapping for EC Communication
+ *
+ * This driver converts LPC I/O port accesses to eSPI shared memory accesses.
+ * The original LPC addresses are mapped to offsets within the eSPI shared memory region.
+ *
+ * Memory Layout in eSPI Shared Memory:
+ * 0x000: Host command register (EC_LPC_ADDR_HOST_CMD -> 0x000)
+ * 0x001: Host data register (EC_LPC_ADDR_HOST_DATA -> 0x001)
+ * 0x010-0x013: Host arguments (4 bytes; 0x014-0x017 reserved)
+ * 0x018-0x113: Protocol v2 parameters (up to 252 bytes)
+ * 0x100-0x1FF: Packet data area (256 bytes for protocol v3)
+ * 0x200-0x2FF: Memory map region (256 bytes)
+ *
+ * Protocol v2 parameters and protocol v3 packets are used separately.
+ */
+
+/* eSPI shared memory offsets */
+#define ESPI_HOST_CMD_OFFSET 0x000 /* EC_LPC_ADDR_HOST_CMD -> 0x000 */
+#define ESPI_HOST_DATA_OFFSET 0x001 /* EC_LPC_ADDR_HOST_DATA -> 0x001 */
+#define ESPI_HOST_ARGS_OFFSET 0x010 /* EC_LPC_ADDR_HOST_ARGS -> 0x010 */
+#define ESPI_HOST_PARAM_OFFSET 0x018 /* EC_LPC_ADDR_HOST_PARAM -> 0x018 */
+#define ESPI_HOST_PACKET_OFFSET 0x100 /* EC_LPC_ADDR_HOST_PACKET -> 0x100 */
+#define ESPI_MEMMAP_OFFSET 0x200 /* EC_LPC_ADDR_MEMMAP -> 0x200 */
+#define ESPI_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
+
+/**
+ * struct cros_ec_espi - eSPI device-specific data
+ * @espi_shared_mem_base: Base address of eSPI shared memory region
+ * @invalid_status_polls: Consecutive absent-endpoint status reads
+ * @needs_recovery: Restore the link before the next window access.
+ * @ec: EC whose peripheral window is being recovered.
+ * @recovery_work: Restore the link outside the GPIO interrupt thread.
+ * @io_mutex: Serialize window accesses and changes to the recovery state.
+ */
+struct cros_ec_espi {
+ void __iomem *espi_shared_mem_base;
+ unsigned int invalid_status_polls;
+ bool needs_recovery;
+ struct cros_ec_device *ec;
+ struct work_struct recovery_work;
+ /* Serialize commands, direct reads and recovery state transitions. */
+ struct mutex io_mutex;
+};
+
+/* Validate an entire transfer before touching the shared window. */
+static int lpc_to_espi_offset(struct cros_ec_device *ec, u32 lpc_addr,
+ unsigned int length)
+{
+ u32 start, size, offset;
+
+ if (lpc_addr == EC_LPC_ADDR_HOST_CMD || lpc_addr == EC_LPC_ADDR_HOST_DATA) {
+ if (length != 1)
+ return -EMSGSIZE;
+ return lpc_addr == EC_LPC_ADDR_HOST_CMD ?
+ ESPI_HOST_CMD_OFFSET : ESPI_HOST_DATA_OFFSET;
+ }
+
+ if (lpc_addr >= EC_LPC_ADDR_MEMMAP &&
+ lpc_addr < EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SIZE) {
+ start = EC_LPC_ADDR_MEMMAP;
+ size = EC_MEMMAP_SIZE;
+ offset = ESPI_MEMMAP_OFFSET;
+ } else if (ec->proto_version > 2 &&
+ lpc_addr >= EC_LPC_ADDR_HOST_PACKET &&
+ lpc_addr < EC_LPC_ADDR_HOST_PACKET + EC_LPC_HOST_PACKET_SIZE) {
+ start = EC_LPC_ADDR_HOST_PACKET;
+ size = EC_LPC_HOST_PACKET_SIZE;
+ offset = ESPI_HOST_PACKET_OFFSET;
+ } else if (ec->proto_version <= 2 &&
+ lpc_addr >= EC_LPC_ADDR_HOST_ARGS &&
+ lpc_addr < EC_LPC_ADDR_HOST_PARAM) {
+ start = EC_LPC_ADDR_HOST_ARGS;
+ size = EC_LPC_ADDR_HOST_PARAM - EC_LPC_ADDR_HOST_ARGS;
+ offset = ESPI_HOST_ARGS_OFFSET;
+ } else if (ec->proto_version <= 2 &&
+ lpc_addr >= EC_LPC_ADDR_HOST_PARAM &&
+ lpc_addr < EC_LPC_ADDR_HOST_PARAM + ESPI_HOST_PARAM_SIZE) {
+ start = EC_LPC_ADDR_HOST_PARAM;
+ size = ESPI_HOST_PARAM_SIZE;
+ offset = ESPI_HOST_PARAM_OFFSET;
+ } else {
+ return -EINVAL;
+ }
+
+ if (length > size - (lpc_addr - start))
+ return -EMSGSIZE;
+
+ return offset + lpc_addr - start;
+}
+
+/* Return the checksum of the bytes read from the peripheral window. */
+static int cros_ec_espi_read_bytes(struct cros_ec_device *ec,
+ unsigned int offset, unsigned int length,
+ u8 *dest)
+{
+ struct cros_ec_espi *ec_espi = ec->priv;
+ void __iomem *addr;
+ int espi_offset;
+ u8 sum = 0;
+ int i;
+
+ espi_offset = lpc_to_espi_offset(ec, offset, length);
+ if (espi_offset < 0)
+ return espi_offset;
+
+ for (i = 0; i < length; ++i) {
+ addr = ec_espi->espi_shared_mem_base + espi_offset + i;
+
+ /* eSPI shared memory: 1-byte access */
+ dest[i] = readb(addr);
+ sum += dest[i];
+ }
+
+ if (offset == EC_LPC_ADDR_HOST_CMD) {
+ if (*dest == ESPI_INVALID_STATUS_VALUE)
+ ec_espi->invalid_status_polls++;
+ else
+ ec_espi->invalid_status_polls = 0;
+ }
+
+ if (offset == EC_LPC_ADDR_HOST_CMD &&
+ ec_espi->invalid_status_polls >= ESPI_INVALID_STATUS_MAX_POLLS)
+ return -ETIMEDOUT;
+
+ /* Return checksum of all bytes read */
+ return sum;
+}
+
+/* Return the checksum of the bytes written to the peripheral window. */
+static int cros_ec_espi_write_bytes(struct cros_ec_device *ec,
+ unsigned int offset, unsigned int length,
+ const u8 *msg)
+{
+ struct cros_ec_espi *ec_espi = ec->priv;
+ void __iomem *addr;
+ int espi_offset;
+ u8 sum = 0;
+ int i;
+
+ espi_offset = lpc_to_espi_offset(ec, offset, length);
+ if (espi_offset < 0)
+ return espi_offset;
+
+ for (i = 0; i < length; ++i) {
+ addr = ec_espi->espi_shared_mem_base + espi_offset + i;
+
+ /* eSPI shared memory: 1-byte access */
+ writeb(msg[i], addr);
+ sum += msg[i];
+ }
+
+ /* Return checksum of all bytes written */
+ return sum;
+}
+
+static const struct cros_ec_lpc_io cros_ec_espi_io = {
+ .read = cros_ec_espi_read_bytes,
+ .write = cros_ec_espi_write_bytes,
+ .response_timeout_ms = ESPI_CMD_TIMEOUT_MS,
+ .timeout_error = -ETIMEDOUT,
+};
+
+static int cros_ec_pkt_xfer_espi_once(struct cros_ec_device *ec,
+ struct cros_ec_command *msg)
+{
+ struct cros_ec_espi *ec_espi = ec->priv;
+
+ if (msg->outsize > EC_LPC_HOST_PACKET_SIZE - sizeof(struct ec_host_request) ||
+ msg->insize > EC_LPC_HOST_PACKET_SIZE - sizeof(struct ec_host_response))
+ return -EMSGSIZE;
+
+ ec_espi->invalid_status_polls = 0;
+ usleep_range(500, 1000);
+
+ return cros_ec_lpc_pkt_xfer(ec, &cros_ec_espi_io, msg);
+}
+
+static int cros_ec_cmd_xfer_espi_once(struct cros_ec_device *ec,
+ struct cros_ec_command *msg)
+{
+ struct cros_ec_espi *ec_espi = ec->priv;
+
+ if (msg->outsize > ESPI_HOST_PARAM_SIZE || msg->insize > ESPI_HOST_PARAM_SIZE)
+ return -EMSGSIZE;
+
+ ec_espi->invalid_status_polls = 0;
+ usleep_range(500, 1000);
+
+ return cros_ec_lpc_cmd_xfer(ec, &cros_ec_espi_io, msg);
+}
+
+static bool cros_ec_espi_valid_id(const u8 *buf)
+{
+ return buf[0] == 'E' && buf[1] == 'C';
+}
+
+static int cros_ec_espi_read_id(struct cros_ec_device *ec, u8 *buf)
+{
+ return cros_ec_espi_read_bytes(ec, EC_LPC_ADDR_MEMMAP + EC_MEMMAP_ID, 2, buf);
+}
+
+static int cros_ec_espi_wait_for_id(struct cros_ec_device *ec,
+ unsigned long deadline)
+{
+ u8 id[2];
+ int ret;
+
+ do {
+ ret = cros_ec_espi_read_id(ec, id);
+ if (ret < 0)
+ return ret;
+ if (cros_ec_espi_valid_id(id)) {
+ /* The ID appears before the command window is ready. */
+ msleep(100);
+ return 0;
+ }
+ usleep_range(ESPI_READY_POLL_INTERVAL_US,
+ ESPI_READY_POLL_INTERVAL_US + 10000);
+ } while (time_before(jiffies, deadline));
+
+ return -ETIMEDOUT;
+}
+
+static int cros_ec_espi_recover_controller(struct cros_ec_device *ec,
+ unsigned long deadline)
+{
+ unsigned long interval = msecs_to_jiffies(ESPI_RECOVERY_RETRY_INTERVAL_MS);
+ int ret;
+
+ do {
+ ret = spacemit_k3_espi_recover(ec->dev->parent);
+ if (!ret)
+ return cros_ec_espi_wait_for_id(ec, deadline);
+ if (ret != -ETIMEDOUT && ret != -EBUSY && ret != -EIO)
+ return ret;
+ if (time_after_eq(jiffies + interval, deadline))
+ break;
+ msleep(ESPI_RECOVERY_RETRY_INTERVAL_MS);
+ } while (time_before(jiffies, deadline));
+
+ return ret;
+}
+
+/* The parent may already have negotiated the link and mapped the window. */
+static int cros_ec_espi_check_link(struct cros_ec_device *ec)
+{
+ unsigned long deadline = jiffies + msecs_to_jiffies(ESPI_READY_TIMEOUT_MS);
+ int ret;
+
+ ret = cros_ec_espi_wait_for_id(ec, jiffies +
+ msecs_to_jiffies(ESPI_RECOVERY_RETRY_INTERVAL_MS));
+ if (ret == -ETIMEDOUT)
+ ret = cros_ec_espi_recover_controller(ec, deadline);
+
+ return ret;
+}
+
+static void cros_ec_espi_recovery_work(struct work_struct *work)
+{
+ struct cros_ec_espi *ec_espi = container_of(work, struct cros_ec_espi,
+ recovery_work);
+ unsigned long deadline = jiffies + msecs_to_jiffies(ESPI_READY_TIMEOUT_MS);
+ int ret;
+
+ mutex_lock(&ec_espi->io_mutex);
+ if (!ec_espi->needs_recovery) {
+ mutex_unlock(&ec_espi->io_mutex);
+ return;
+ }
+ mutex_unlock(&ec_espi->io_mutex);
+
+ /* While recovery owns the window, new callers return -EHOSTDOWN. */
+ ret = cros_ec_espi_recover_controller(ec_espi->ec, deadline);
+ if (ret) {
+ dev_warn_ratelimited(ec_espi->ec->dev, "link recovery failed: %d\n", ret);
+ return;
+ }
+
+ mutex_lock(&ec_espi->io_mutex);
+ ec_espi->needs_recovery = false;
+ mutex_unlock(&ec_espi->io_mutex);
+}
+
+/* Called with io_mutex held. */
+static int cros_ec_espi_ensure_ready(struct cros_ec_device *ec)
+{
+ struct cros_ec_espi *ec_espi = ec->priv;
+ unsigned long deadline;
+ int ret;
+
+ if (!ec_espi->needs_recovery)
+ return 0;
+
+ /*
+ * The core negotiates the protocol before requesting our dedicated
+ * IRQ. Once its action is installed, transfers may already run in
+ * the GPIO interrupt thread, even before cros_ec_register() returns.
+ */
+ if (irq_has_action(ec->irq)) {
+ queue_work(system_freezable_wq, &ec_espi->recovery_work);
+ return -EHOSTDOWN;
+ }
+
+ /* The initial protocol negotiation needs a working link immediately. */
+ deadline = jiffies + msecs_to_jiffies(ESPI_READY_TIMEOUT_MS);
+ ret = cros_ec_espi_recover_controller(ec, deadline);
+ ec_espi->needs_recovery = !!ret;
+ return ret;
+}
+
+static int cros_ec_espi_xfer(struct cros_ec_device *ec,
+ struct cros_ec_command *msg,
+ int (*xfer_once)(struct cros_ec_device *ec,
+ struct cros_ec_command *msg))
+{
+ struct cros_ec_espi *ec_espi = ec->priv;
+ int ret;
+
+ mutex_lock(&ec_espi->io_mutex);
+ ret = cros_ec_espi_ensure_ready(ec);
+ if (ret)
+ goto unlock;
+
+ ret = xfer_once(ec, msg);
+ /*
+ * A lost completion does not mean that the EC did not execute the
+ * command. Repair the link without replaying a potentially destructive
+ * operation, such as an I2C passthrough write.
+ */
+ if (ret == -ETIMEDOUT) {
+ ec_espi->needs_recovery = true;
+ cros_ec_espi_ensure_ready(ec);
+ }
+unlock:
+ mutex_unlock(&ec_espi->io_mutex);
+
+ return ret;
+}
+
+static int cros_ec_pkt_xfer_espi(struct cros_ec_device *ec,
+ struct cros_ec_command *msg)
+{
+ return cros_ec_espi_xfer(ec, msg, cros_ec_pkt_xfer_espi_once);
+}
+
+static int cros_ec_cmd_xfer_espi(struct cros_ec_device *ec,
+ struct cros_ec_command *msg)
+{
+ return cros_ec_espi_xfer(ec, msg, cros_ec_cmd_xfer_espi_once);
+}
+
+static int cros_ec_espi_readmem(struct cros_ec_device *ec, unsigned int offset,
+ unsigned int bytes, void *dest)
+{
+ struct cros_ec_espi *ec_espi = ec->priv;
+ int ret;
+
+ mutex_lock(&ec_espi->io_mutex);
+ ret = cros_ec_espi_ensure_ready(ec);
+ if (!ret)
+ ret = cros_ec_lpc_readmem(ec, &cros_ec_espi_io, EC_LPC_ADDR_MEMMAP,
+ offset, bytes, dest);
+ mutex_unlock(&ec_espi->io_mutex);
+
+ return ret;
+}
+
+static int cros_ec_espi_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct cros_ec_device *ec;
+ struct cros_ec_espi *ec_espi;
+ struct resource *res;
+ int irq, ret;
+
+ irq = platform_get_irq(pdev, 0);
+ if (irq < 0)
+ return irq;
+
+ ec_espi = devm_kzalloc(dev, sizeof(*ec_espi), GFP_KERNEL);
+ if (!ec_espi)
+ return -ENOMEM;
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!res || resource_size(res) < 0x300)
+ return -EINVAL;
+ ec_espi->espi_shared_mem_base = devm_ioremap_resource(dev, res);
+ if (IS_ERR(ec_espi->espi_shared_mem_base))
+ return PTR_ERR(ec_espi->espi_shared_mem_base);
+
+ mutex_init(&ec_espi->io_mutex);
+
+ ec = cros_ec_device_alloc(dev);
+ if (!ec)
+ return -ENOMEM;
+
+ ec->phys_name = dev_name(dev);
+ ec->irq = irq;
+ /* Use the IRQ trigger type specified by the board's device tree. */
+ ec->irqflags = IRQF_ONESHOT;
+ ec->cmd_xfer = cros_ec_cmd_xfer_espi;
+ ec->pkt_xfer = cros_ec_pkt_xfer_espi;
+ ec->cmd_readmem = cros_ec_espi_readmem;
+ ec->priv = ec_espi;
+ platform_set_drvdata(pdev, ec);
+ ec_espi->ec = ec;
+ INIT_WORK(&ec_espi->recovery_work, cros_ec_espi_recovery_work);
+
+ ret = cros_ec_espi_check_link(ec);
+ if (ret)
+ return dev_err_probe(dev, ret, "EC is not ready\n");
+
+ if (of_property_read_bool(dev->of_node, "wakeup-source")) {
+ ret = devm_device_init_wakeup(dev);
+ if (ret)
+ return ret;
+ }
+
+ ret = cros_ec_register(ec);
+ if (ret) {
+ /* An IRQ during registration may already have queued recovery. */
+ disable_work_sync(&ec_espi->recovery_work);
+ return dev_err_probe(dev, ret, "failed to register EC\n");
+ }
+
+ return 0;
+}
+
+static void cros_ec_espi_remove(struct platform_device *pdev)
+{
+ struct cros_ec_device *ec = platform_get_drvdata(pdev);
+ struct cros_ec_espi *ec_espi = ec->priv;
+
+ disable_work_sync(&ec_espi->recovery_work);
+ cros_ec_unregister(ec);
+}
+
+static const struct of_device_id cros_ec_espi_of_match[] = {
+ { .compatible = "spacemit,k3-cros-ec" },
+ {}
+};
+MODULE_DEVICE_TABLE(of, cros_ec_espi_of_match);
+
+#ifdef CONFIG_PM_SLEEP
+static int cros_ec_espi_prepare(struct device *dev)
+{
+ struct cros_ec_device *ec_dev = dev_get_drvdata(dev);
+
+ return cros_ec_suspend_prepare(ec_dev);
+}
+
+static void cros_ec_espi_complete(struct device *dev)
+{
+ struct cros_ec_device *ec_dev = dev_get_drvdata(dev);
+
+ cros_ec_resume_complete(ec_dev);
+}
+
+static int cros_ec_espi_suspend_late(struct device *dev)
+{
+ struct cros_ec_device *ec_dev = dev_get_drvdata(dev);
+ struct cros_ec_espi *ec_espi = ec_dev->priv;
+
+ disable_work_sync(&ec_espi->recovery_work);
+ return cros_ec_suspend_late(ec_dev);
+}
+
+static int cros_ec_espi_resume_early(struct device *dev)
+{
+ struct cros_ec_device *ec_dev = dev_get_drvdata(dev);
+ struct cros_ec_espi *ec_espi = ec_dev->priv;
+ int ret = 0;
+
+ /* Recovery work is still frozen when the core sends its resume event. */
+ mutex_lock(&ec_espi->io_mutex);
+ if (ec_espi->needs_recovery) {
+ ret = cros_ec_espi_check_link(ec_dev);
+ ec_espi->needs_recovery = !!ret;
+ }
+ enable_work(&ec_espi->recovery_work);
+ mutex_unlock(&ec_espi->io_mutex);
+
+ /* Balance suspend_late() even if the link needs another recovery. */
+ cros_ec_resume_early(ec_dev);
+ return ret;
+}
+#endif
+
+static const struct dev_pm_ops cros_ec_espi_pm_ops = {
+#ifdef CONFIG_PM_SLEEP
+ .prepare = cros_ec_espi_prepare,
+ .complete = cros_ec_espi_complete,
+#endif
+ SET_LATE_SYSTEM_SLEEP_PM_OPS(cros_ec_espi_suspend_late,
+ cros_ec_espi_resume_early)
+};
+
+static struct platform_driver cros_ec_espi_driver = {
+ .driver = {
+ .name = DRV_NAME,
+ .of_match_table = cros_ec_espi_of_match,
+ .pm = &cros_ec_espi_pm_ops,
+ /*
+ * Child devices may probe before us, and they racily
+ * check our drvdata pointer. Force synchronous probe until
+ * those races are resolved.
+ */
+ .probe_type = PROBE_FORCE_SYNCHRONOUS,
+ },
+ .probe = cros_ec_espi_probe,
+ .remove = cros_ec_espi_remove,
+};
+
+module_platform_driver(cros_ec_espi_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("SpacemiT K3 eSPI transport for the ChromeOS EC protocol");
+MODULE_ALIAS("platform:" DRV_NAME);
--
2.43.0
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH v2 09/13] platform/chrome: Add SpacemiT K3 eSPI EC transport
@ 2026-12-04 4:21 ` Wang Yang
0 siblings, 0 replies; 27+ messages in thread
From: Wang Yang @ 2026-12-04 4:21 UTC (permalink / raw)
To: linux-kernel
Cc: Benson Leung, Tzung-Bi Shih, Yixun Lan, Troy Mitchell,
Guenter Roeck, chrome-platform, linux-riscv, spacemit
Map the K3 non-linear window and reuse the common LPC-style protocol
helpers. Keep K3 readiness, five-second timeout and link recovery
in the vendor backend. Recover a timed-out link without replaying
a command that may already have executed. Let the EC core request
the firmware-configured event IRQ.
Use module cros_ec_espi_spacemit, CONFIG_CROS_EC_SPACEMIT_K3 and
compatible spacemit,k3-cros-ec. This is a K3-specific interface.
Require the firmware event IRQ before accessing the EC. Serialize host
commands and direct memory reads with link recovery. Retry transient
negotiation failures, then wait for the EC ID on the established link.
Give the already negotiated link time to publish its ID before resetting
it at probe. Recover synchronously during protocol negotiation. Once
the core installs the dedicated GPIO IRQ action, defer link recovery to
a workqueue so the GPIO bank thread can service other pins. Prevent
queued recovery from outliving a failed probe. Reject window accesses
while recovery is active. Check request and response sizes against the
K3 packet window.
Check a pending link recovery before enabling the event IRQ on resume.
Prepared with OpenAI Codex assistance.
Signed-off-by: Wang Yang <yang.wang@deepcomputing.io>
---
drivers/platform/chrome/Kconfig | 12 +
drivers/platform/chrome/Makefile | 1 +
.../platform/chrome/cros_ec_espi_spacemit.c | 568 ++++++++++++++++++
3 files changed, 581 insertions(+)
create mode 100644 drivers/platform/chrome/cros_ec_espi_spacemit.c
diff --git a/drivers/platform/chrome/Kconfig b/drivers/platform/chrome/Kconfig
index 2e4fec3820f5..11a8320b202d 100644
--- a/drivers/platform/chrome/Kconfig
+++ b/drivers/platform/chrome/Kconfig
@@ -160,6 +160,18 @@ config CROS_EC_LPC
To compile this driver as a module, choose M here: the
module will be called cros_ec_lpcs.
+config CROS_EC_SPACEMIT_K3
+ tristate "SpacemiT K3 ChromeOS EC over eSPI"
+ depends on CROS_EC && SPACEMIT_ESPI_BUS
+ select CROS_EC_LPC_PROTO
+ help
+ Support a ChromeOS EC connected through the SpacemiT K3 eSPI
+ peripheral shared-memory window. The transport supports host
+ command protocol versions 2 and 3 and EC event interrupts.
+
+ To compile this driver as a module, choose M here: the module
+ will be called cros_ec_espi_spacemit.
+
config CROS_EC_PROTO
tristate
help
diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/Makefile
index 00d3d9fba1e0..a0731d359104 100644
--- a/drivers/platform/chrome/Makefile
+++ b/drivers/platform/chrome/Makefile
@@ -15,6 +15,7 @@ obj-$(CONFIG_CROS_EC_I2C) += cros_ec_i2c.o
obj-$(CONFIG_CROS_EC_ISHTP) += cros_ec_ishtp.o
obj-$(CONFIG_CROS_TYPEC_SWITCH) += cros_typec_switch.o
obj-$(CONFIG_CROS_EC_RPMSG) += cros_ec_rpmsg.o
+obj-$(CONFIG_CROS_EC_SPACEMIT_K3) += cros_ec_espi_spacemit.o
obj-$(CONFIG_CROS_EC_SPI) += cros_ec_spi.o
obj-$(CONFIG_CROS_EC_UART) += cros_ec_uart.o
cros_ec_lpcs-objs := cros_ec_lpc.o cros_ec_lpc_mec.o
diff --git a/drivers/platform/chrome/cros_ec_espi_spacemit.c b/drivers/platform/chrome/cros_ec_espi_spacemit.c
new file mode 100644
index 000000000000..cb5c37d1a24d
--- /dev/null
+++ b/drivers/platform/chrome/cros_ec_espi_spacemit.c
@@ -0,0 +1,568 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * ChromeOS EC interface for the SpacemiT K3 eSPI controller
+ *
+ * Copyright (c) 2012 The Chromium OS Authors.
+ * Copyright (c) 2024 SpacemiT, Inc.
+ *
+ * This driver provides the SpacemiT K3 eSPI window for ChromeOS EC communication.
+ * It converts LPC I/O port accesses to eSPI shared memory accesses while maintaining
+ * compatibility with the existing ChromeOS EC protocol stack.
+ */
+
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/jiffies.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/platform_data/cros_ec_commands.h>
+#include <linux/platform_data/cros_ec_proto.h>
+#include <linux/platform_device.h>
+#include <linux/pm_wakeup.h>
+#include <linux/slab.h>
+#include <linux/spacemit-k3-espi.h>
+#include <linux/suspend.h>
+#include <linux/workqueue.h>
+
+#include "cros_ec.h"
+#include "cros_ec_lpc_proto.h"
+
+#define DRV_NAME "cros_ec_espi_spacemit"
+
+/* eSPI shared memory access timeout */
+#define ESPI_CMD_TIMEOUT_MS 5000
+
+/*
+ * After an EC reboot the transport may recover well before the EC firmware
+ * finishes repopulating the shared memory window. Allow a longer grace period
+ * here so the first post-reboot command does not immediately fall into another
+ * full timeout cycle.
+ */
+#define ESPI_READY_TIMEOUT_MS 20000
+#define ESPI_READY_POLL_INTERVAL_US 20000
+#define ESPI_RECOVERY_RETRY_INTERVAL_MS 5000
+#define ESPI_INVALID_STATUS_VALUE 0xff
+#define ESPI_INVALID_STATUS_MAX_POLLS 5
+
+/*
+ * eSPI Shared Memory Address Mapping for EC Communication
+ *
+ * This driver converts LPC I/O port accesses to eSPI shared memory accesses.
+ * The original LPC addresses are mapped to offsets within the eSPI shared memory region.
+ *
+ * Memory Layout in eSPI Shared Memory:
+ * 0x000: Host command register (EC_LPC_ADDR_HOST_CMD -> 0x000)
+ * 0x001: Host data register (EC_LPC_ADDR_HOST_DATA -> 0x001)
+ * 0x010-0x013: Host arguments (4 bytes; 0x014-0x017 reserved)
+ * 0x018-0x113: Protocol v2 parameters (up to 252 bytes)
+ * 0x100-0x1FF: Packet data area (256 bytes for protocol v3)
+ * 0x200-0x2FF: Memory map region (256 bytes)
+ *
+ * Protocol v2 parameters and protocol v3 packets are used separately.
+ */
+
+/* eSPI shared memory offsets */
+#define ESPI_HOST_CMD_OFFSET 0x000 /* EC_LPC_ADDR_HOST_CMD -> 0x000 */
+#define ESPI_HOST_DATA_OFFSET 0x001 /* EC_LPC_ADDR_HOST_DATA -> 0x001 */
+#define ESPI_HOST_ARGS_OFFSET 0x010 /* EC_LPC_ADDR_HOST_ARGS -> 0x010 */
+#define ESPI_HOST_PARAM_OFFSET 0x018 /* EC_LPC_ADDR_HOST_PARAM -> 0x018 */
+#define ESPI_HOST_PACKET_OFFSET 0x100 /* EC_LPC_ADDR_HOST_PACKET -> 0x100 */
+#define ESPI_MEMMAP_OFFSET 0x200 /* EC_LPC_ADDR_MEMMAP -> 0x200 */
+#define ESPI_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
+
+/**
+ * struct cros_ec_espi - eSPI device-specific data
+ * @espi_shared_mem_base: Base address of eSPI shared memory region
+ * @invalid_status_polls: Consecutive absent-endpoint status reads
+ * @needs_recovery: Restore the link before the next window access.
+ * @ec: EC whose peripheral window is being recovered.
+ * @recovery_work: Restore the link outside the GPIO interrupt thread.
+ * @io_mutex: Serialize window accesses and changes to the recovery state.
+ */
+struct cros_ec_espi {
+ void __iomem *espi_shared_mem_base;
+ unsigned int invalid_status_polls;
+ bool needs_recovery;
+ struct cros_ec_device *ec;
+ struct work_struct recovery_work;
+ /* Serialize commands, direct reads and recovery state transitions. */
+ struct mutex io_mutex;
+};
+
+/* Validate an entire transfer before touching the shared window. */
+static int lpc_to_espi_offset(struct cros_ec_device *ec, u32 lpc_addr,
+ unsigned int length)
+{
+ u32 start, size, offset;
+
+ if (lpc_addr == EC_LPC_ADDR_HOST_CMD || lpc_addr == EC_LPC_ADDR_HOST_DATA) {
+ if (length != 1)
+ return -EMSGSIZE;
+ return lpc_addr == EC_LPC_ADDR_HOST_CMD ?
+ ESPI_HOST_CMD_OFFSET : ESPI_HOST_DATA_OFFSET;
+ }
+
+ if (lpc_addr >= EC_LPC_ADDR_MEMMAP &&
+ lpc_addr < EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SIZE) {
+ start = EC_LPC_ADDR_MEMMAP;
+ size = EC_MEMMAP_SIZE;
+ offset = ESPI_MEMMAP_OFFSET;
+ } else if (ec->proto_version > 2 &&
+ lpc_addr >= EC_LPC_ADDR_HOST_PACKET &&
+ lpc_addr < EC_LPC_ADDR_HOST_PACKET + EC_LPC_HOST_PACKET_SIZE) {
+ start = EC_LPC_ADDR_HOST_PACKET;
+ size = EC_LPC_HOST_PACKET_SIZE;
+ offset = ESPI_HOST_PACKET_OFFSET;
+ } else if (ec->proto_version <= 2 &&
+ lpc_addr >= EC_LPC_ADDR_HOST_ARGS &&
+ lpc_addr < EC_LPC_ADDR_HOST_PARAM) {
+ start = EC_LPC_ADDR_HOST_ARGS;
+ size = EC_LPC_ADDR_HOST_PARAM - EC_LPC_ADDR_HOST_ARGS;
+ offset = ESPI_HOST_ARGS_OFFSET;
+ } else if (ec->proto_version <= 2 &&
+ lpc_addr >= EC_LPC_ADDR_HOST_PARAM &&
+ lpc_addr < EC_LPC_ADDR_HOST_PARAM + ESPI_HOST_PARAM_SIZE) {
+ start = EC_LPC_ADDR_HOST_PARAM;
+ size = ESPI_HOST_PARAM_SIZE;
+ offset = ESPI_HOST_PARAM_OFFSET;
+ } else {
+ return -EINVAL;
+ }
+
+ if (length > size - (lpc_addr - start))
+ return -EMSGSIZE;
+
+ return offset + lpc_addr - start;
+}
+
+/* Return the checksum of the bytes read from the peripheral window. */
+static int cros_ec_espi_read_bytes(struct cros_ec_device *ec,
+ unsigned int offset, unsigned int length,
+ u8 *dest)
+{
+ struct cros_ec_espi *ec_espi = ec->priv;
+ void __iomem *addr;
+ int espi_offset;
+ u8 sum = 0;
+ int i;
+
+ espi_offset = lpc_to_espi_offset(ec, offset, length);
+ if (espi_offset < 0)
+ return espi_offset;
+
+ for (i = 0; i < length; ++i) {
+ addr = ec_espi->espi_shared_mem_base + espi_offset + i;
+
+ /* eSPI shared memory: 1-byte access */
+ dest[i] = readb(addr);
+ sum += dest[i];
+ }
+
+ if (offset == EC_LPC_ADDR_HOST_CMD) {
+ if (*dest == ESPI_INVALID_STATUS_VALUE)
+ ec_espi->invalid_status_polls++;
+ else
+ ec_espi->invalid_status_polls = 0;
+ }
+
+ if (offset == EC_LPC_ADDR_HOST_CMD &&
+ ec_espi->invalid_status_polls >= ESPI_INVALID_STATUS_MAX_POLLS)
+ return -ETIMEDOUT;
+
+ /* Return checksum of all bytes read */
+ return sum;
+}
+
+/* Return the checksum of the bytes written to the peripheral window. */
+static int cros_ec_espi_write_bytes(struct cros_ec_device *ec,
+ unsigned int offset, unsigned int length,
+ const u8 *msg)
+{
+ struct cros_ec_espi *ec_espi = ec->priv;
+ void __iomem *addr;
+ int espi_offset;
+ u8 sum = 0;
+ int i;
+
+ espi_offset = lpc_to_espi_offset(ec, offset, length);
+ if (espi_offset < 0)
+ return espi_offset;
+
+ for (i = 0; i < length; ++i) {
+ addr = ec_espi->espi_shared_mem_base + espi_offset + i;
+
+ /* eSPI shared memory: 1-byte access */
+ writeb(msg[i], addr);
+ sum += msg[i];
+ }
+
+ /* Return checksum of all bytes written */
+ return sum;
+}
+
+static const struct cros_ec_lpc_io cros_ec_espi_io = {
+ .read = cros_ec_espi_read_bytes,
+ .write = cros_ec_espi_write_bytes,
+ .response_timeout_ms = ESPI_CMD_TIMEOUT_MS,
+ .timeout_error = -ETIMEDOUT,
+};
+
+static int cros_ec_pkt_xfer_espi_once(struct cros_ec_device *ec,
+ struct cros_ec_command *msg)
+{
+ struct cros_ec_espi *ec_espi = ec->priv;
+
+ if (msg->outsize > EC_LPC_HOST_PACKET_SIZE - sizeof(struct ec_host_request) ||
+ msg->insize > EC_LPC_HOST_PACKET_SIZE - sizeof(struct ec_host_response))
+ return -EMSGSIZE;
+
+ ec_espi->invalid_status_polls = 0;
+ usleep_range(500, 1000);
+
+ return cros_ec_lpc_pkt_xfer(ec, &cros_ec_espi_io, msg);
+}
+
+static int cros_ec_cmd_xfer_espi_once(struct cros_ec_device *ec,
+ struct cros_ec_command *msg)
+{
+ struct cros_ec_espi *ec_espi = ec->priv;
+
+ if (msg->outsize > ESPI_HOST_PARAM_SIZE || msg->insize > ESPI_HOST_PARAM_SIZE)
+ return -EMSGSIZE;
+
+ ec_espi->invalid_status_polls = 0;
+ usleep_range(500, 1000);
+
+ return cros_ec_lpc_cmd_xfer(ec, &cros_ec_espi_io, msg);
+}
+
+static bool cros_ec_espi_valid_id(const u8 *buf)
+{
+ return buf[0] == 'E' && buf[1] == 'C';
+}
+
+static int cros_ec_espi_read_id(struct cros_ec_device *ec, u8 *buf)
+{
+ return cros_ec_espi_read_bytes(ec, EC_LPC_ADDR_MEMMAP + EC_MEMMAP_ID, 2, buf);
+}
+
+static int cros_ec_espi_wait_for_id(struct cros_ec_device *ec,
+ unsigned long deadline)
+{
+ u8 id[2];
+ int ret;
+
+ do {
+ ret = cros_ec_espi_read_id(ec, id);
+ if (ret < 0)
+ return ret;
+ if (cros_ec_espi_valid_id(id)) {
+ /* The ID appears before the command window is ready. */
+ msleep(100);
+ return 0;
+ }
+ usleep_range(ESPI_READY_POLL_INTERVAL_US,
+ ESPI_READY_POLL_INTERVAL_US + 10000);
+ } while (time_before(jiffies, deadline));
+
+ return -ETIMEDOUT;
+}
+
+static int cros_ec_espi_recover_controller(struct cros_ec_device *ec,
+ unsigned long deadline)
+{
+ unsigned long interval = msecs_to_jiffies(ESPI_RECOVERY_RETRY_INTERVAL_MS);
+ int ret;
+
+ do {
+ ret = spacemit_k3_espi_recover(ec->dev->parent);
+ if (!ret)
+ return cros_ec_espi_wait_for_id(ec, deadline);
+ if (ret != -ETIMEDOUT && ret != -EBUSY && ret != -EIO)
+ return ret;
+ if (time_after_eq(jiffies + interval, deadline))
+ break;
+ msleep(ESPI_RECOVERY_RETRY_INTERVAL_MS);
+ } while (time_before(jiffies, deadline));
+
+ return ret;
+}
+
+/* The parent may already have negotiated the link and mapped the window. */
+static int cros_ec_espi_check_link(struct cros_ec_device *ec)
+{
+ unsigned long deadline = jiffies + msecs_to_jiffies(ESPI_READY_TIMEOUT_MS);
+ int ret;
+
+ ret = cros_ec_espi_wait_for_id(ec, jiffies +
+ msecs_to_jiffies(ESPI_RECOVERY_RETRY_INTERVAL_MS));
+ if (ret == -ETIMEDOUT)
+ ret = cros_ec_espi_recover_controller(ec, deadline);
+
+ return ret;
+}
+
+static void cros_ec_espi_recovery_work(struct work_struct *work)
+{
+ struct cros_ec_espi *ec_espi = container_of(work, struct cros_ec_espi,
+ recovery_work);
+ unsigned long deadline = jiffies + msecs_to_jiffies(ESPI_READY_TIMEOUT_MS);
+ int ret;
+
+ mutex_lock(&ec_espi->io_mutex);
+ if (!ec_espi->needs_recovery) {
+ mutex_unlock(&ec_espi->io_mutex);
+ return;
+ }
+ mutex_unlock(&ec_espi->io_mutex);
+
+ /* While recovery owns the window, new callers return -EHOSTDOWN. */
+ ret = cros_ec_espi_recover_controller(ec_espi->ec, deadline);
+ if (ret) {
+ dev_warn_ratelimited(ec_espi->ec->dev, "link recovery failed: %d\n", ret);
+ return;
+ }
+
+ mutex_lock(&ec_espi->io_mutex);
+ ec_espi->needs_recovery = false;
+ mutex_unlock(&ec_espi->io_mutex);
+}
+
+/* Called with io_mutex held. */
+static int cros_ec_espi_ensure_ready(struct cros_ec_device *ec)
+{
+ struct cros_ec_espi *ec_espi = ec->priv;
+ unsigned long deadline;
+ int ret;
+
+ if (!ec_espi->needs_recovery)
+ return 0;
+
+ /*
+ * The core negotiates the protocol before requesting our dedicated
+ * IRQ. Once its action is installed, transfers may already run in
+ * the GPIO interrupt thread, even before cros_ec_register() returns.
+ */
+ if (irq_has_action(ec->irq)) {
+ queue_work(system_freezable_wq, &ec_espi->recovery_work);
+ return -EHOSTDOWN;
+ }
+
+ /* The initial protocol negotiation needs a working link immediately. */
+ deadline = jiffies + msecs_to_jiffies(ESPI_READY_TIMEOUT_MS);
+ ret = cros_ec_espi_recover_controller(ec, deadline);
+ ec_espi->needs_recovery = !!ret;
+ return ret;
+}
+
+static int cros_ec_espi_xfer(struct cros_ec_device *ec,
+ struct cros_ec_command *msg,
+ int (*xfer_once)(struct cros_ec_device *ec,
+ struct cros_ec_command *msg))
+{
+ struct cros_ec_espi *ec_espi = ec->priv;
+ int ret;
+
+ mutex_lock(&ec_espi->io_mutex);
+ ret = cros_ec_espi_ensure_ready(ec);
+ if (ret)
+ goto unlock;
+
+ ret = xfer_once(ec, msg);
+ /*
+ * A lost completion does not mean that the EC did not execute the
+ * command. Repair the link without replaying a potentially destructive
+ * operation, such as an I2C passthrough write.
+ */
+ if (ret == -ETIMEDOUT) {
+ ec_espi->needs_recovery = true;
+ cros_ec_espi_ensure_ready(ec);
+ }
+unlock:
+ mutex_unlock(&ec_espi->io_mutex);
+
+ return ret;
+}
+
+static int cros_ec_pkt_xfer_espi(struct cros_ec_device *ec,
+ struct cros_ec_command *msg)
+{
+ return cros_ec_espi_xfer(ec, msg, cros_ec_pkt_xfer_espi_once);
+}
+
+static int cros_ec_cmd_xfer_espi(struct cros_ec_device *ec,
+ struct cros_ec_command *msg)
+{
+ return cros_ec_espi_xfer(ec, msg, cros_ec_cmd_xfer_espi_once);
+}
+
+static int cros_ec_espi_readmem(struct cros_ec_device *ec, unsigned int offset,
+ unsigned int bytes, void *dest)
+{
+ struct cros_ec_espi *ec_espi = ec->priv;
+ int ret;
+
+ mutex_lock(&ec_espi->io_mutex);
+ ret = cros_ec_espi_ensure_ready(ec);
+ if (!ret)
+ ret = cros_ec_lpc_readmem(ec, &cros_ec_espi_io, EC_LPC_ADDR_MEMMAP,
+ offset, bytes, dest);
+ mutex_unlock(&ec_espi->io_mutex);
+
+ return ret;
+}
+
+static int cros_ec_espi_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct cros_ec_device *ec;
+ struct cros_ec_espi *ec_espi;
+ struct resource *res;
+ int irq, ret;
+
+ irq = platform_get_irq(pdev, 0);
+ if (irq < 0)
+ return irq;
+
+ ec_espi = devm_kzalloc(dev, sizeof(*ec_espi), GFP_KERNEL);
+ if (!ec_espi)
+ return -ENOMEM;
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!res || resource_size(res) < 0x300)
+ return -EINVAL;
+ ec_espi->espi_shared_mem_base = devm_ioremap_resource(dev, res);
+ if (IS_ERR(ec_espi->espi_shared_mem_base))
+ return PTR_ERR(ec_espi->espi_shared_mem_base);
+
+ mutex_init(&ec_espi->io_mutex);
+
+ ec = cros_ec_device_alloc(dev);
+ if (!ec)
+ return -ENOMEM;
+
+ ec->phys_name = dev_name(dev);
+ ec->irq = irq;
+ /* Use the IRQ trigger type specified by the board's device tree. */
+ ec->irqflags = IRQF_ONESHOT;
+ ec->cmd_xfer = cros_ec_cmd_xfer_espi;
+ ec->pkt_xfer = cros_ec_pkt_xfer_espi;
+ ec->cmd_readmem = cros_ec_espi_readmem;
+ ec->priv = ec_espi;
+ platform_set_drvdata(pdev, ec);
+ ec_espi->ec = ec;
+ INIT_WORK(&ec_espi->recovery_work, cros_ec_espi_recovery_work);
+
+ ret = cros_ec_espi_check_link(ec);
+ if (ret)
+ return dev_err_probe(dev, ret, "EC is not ready\n");
+
+ if (of_property_read_bool(dev->of_node, "wakeup-source")) {
+ ret = devm_device_init_wakeup(dev);
+ if (ret)
+ return ret;
+ }
+
+ ret = cros_ec_register(ec);
+ if (ret) {
+ /* An IRQ during registration may already have queued recovery. */
+ disable_work_sync(&ec_espi->recovery_work);
+ return dev_err_probe(dev, ret, "failed to register EC\n");
+ }
+
+ return 0;
+}
+
+static void cros_ec_espi_remove(struct platform_device *pdev)
+{
+ struct cros_ec_device *ec = platform_get_drvdata(pdev);
+ struct cros_ec_espi *ec_espi = ec->priv;
+
+ disable_work_sync(&ec_espi->recovery_work);
+ cros_ec_unregister(ec);
+}
+
+static const struct of_device_id cros_ec_espi_of_match[] = {
+ { .compatible = "spacemit,k3-cros-ec" },
+ {}
+};
+MODULE_DEVICE_TABLE(of, cros_ec_espi_of_match);
+
+#ifdef CONFIG_PM_SLEEP
+static int cros_ec_espi_prepare(struct device *dev)
+{
+ struct cros_ec_device *ec_dev = dev_get_drvdata(dev);
+
+ return cros_ec_suspend_prepare(ec_dev);
+}
+
+static void cros_ec_espi_complete(struct device *dev)
+{
+ struct cros_ec_device *ec_dev = dev_get_drvdata(dev);
+
+ cros_ec_resume_complete(ec_dev);
+}
+
+static int cros_ec_espi_suspend_late(struct device *dev)
+{
+ struct cros_ec_device *ec_dev = dev_get_drvdata(dev);
+ struct cros_ec_espi *ec_espi = ec_dev->priv;
+
+ disable_work_sync(&ec_espi->recovery_work);
+ return cros_ec_suspend_late(ec_dev);
+}
+
+static int cros_ec_espi_resume_early(struct device *dev)
+{
+ struct cros_ec_device *ec_dev = dev_get_drvdata(dev);
+ struct cros_ec_espi *ec_espi = ec_dev->priv;
+ int ret = 0;
+
+ /* Recovery work is still frozen when the core sends its resume event. */
+ mutex_lock(&ec_espi->io_mutex);
+ if (ec_espi->needs_recovery) {
+ ret = cros_ec_espi_check_link(ec_dev);
+ ec_espi->needs_recovery = !!ret;
+ }
+ enable_work(&ec_espi->recovery_work);
+ mutex_unlock(&ec_espi->io_mutex);
+
+ /* Balance suspend_late() even if the link needs another recovery. */
+ cros_ec_resume_early(ec_dev);
+ return ret;
+}
+#endif
+
+static const struct dev_pm_ops cros_ec_espi_pm_ops = {
+#ifdef CONFIG_PM_SLEEP
+ .prepare = cros_ec_espi_prepare,
+ .complete = cros_ec_espi_complete,
+#endif
+ SET_LATE_SYSTEM_SLEEP_PM_OPS(cros_ec_espi_suspend_late,
+ cros_ec_espi_resume_early)
+};
+
+static struct platform_driver cros_ec_espi_driver = {
+ .driver = {
+ .name = DRV_NAME,
+ .of_match_table = cros_ec_espi_of_match,
+ .pm = &cros_ec_espi_pm_ops,
+ /*
+ * Child devices may probe before us, and they racily
+ * check our drvdata pointer. Force synchronous probe until
+ * those races are resolved.
+ */
+ .probe_type = PROBE_FORCE_SYNCHRONOUS,
+ },
+ .probe = cros_ec_espi_probe,
+ .remove = cros_ec_espi_remove,
+};
+
+module_platform_driver(cros_ec_espi_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("SpacemiT K3 eSPI transport for the ChromeOS EC protocol");
+MODULE_ALIAS("platform:" DRV_NAME);
--
2.43.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v2 10/13] riscv: dts: spacemit: Add K3 eSPI pin group
2026-12-04 4:20 ` Wang Yang
@ 2026-12-04 4:21 ` Wang Yang
-1 siblings, 0 replies; 27+ messages in thread
From: Wang Yang @ 2026-12-04 4:21 UTC (permalink / raw)
To: linux-kernel
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Yixun Lan,
Troy Mitchell, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, devicetree, linux-riscv, spacemit
Use normal pull-up explicitly and describe 25 mA drive as DS10 at 1.8 V.
Prepared with OpenAI Codex assistance.
Signed-off-by: Wang Yang <yang.wang@deepcomputing.io>
---
arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi | 24 ++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi b/arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi
index cb4f4f4e33af..90f2de7a5c07 100644
--- a/arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi
+++ b/arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi
@@ -11,6 +11,30 @@
#define K3_GPIO(x) (x / 32) (x % 32)
&pinctrl {
+ espi0_2_cfg: espi0-2-cfg {
+ espi0-0-pins {
+ pinmux = <K3_PADCONF(91, 4)>, /* espi0 d0 */
+ <K3_PADCONF(92, 4)>, /* espi0 d1 */
+ <K3_PADCONF(93, 4)>, /* espi0 d2 */
+ <K3_PADCONF(94, 4)>, /* espi0 d3 */
+ <K3_PADCONF(95, 4)>, /* espi0 cs */
+ <K3_PADCONF(97, 4)>, /* espi0 reset */
+ <K3_PADCONF(98, 4)>; /* espi0 alert */
+
+ bias-pull-up = <0>; /* normal pull-up */
+ drive-strength = <25>; /* DS10 at 1.8V */
+ power-source = <1800>;
+ };
+
+ espi0-1-pins {
+ pinmux = <K3_PADCONF(96, 4)>; /* espi0 clk */
+
+ bias-pull-down; /* normal pull-down */
+ drive-strength = <25>; /* DS10 at 1.8V */
+ power-source = <1800>;
+ };
+ };
+
gmac0_rgmii_0_cfg: gmac0-rgmii-0-cfg {
gmac0-rgmii-0-pins {
pinmux = <K3_PADCONF(0, 1)>, /* gmac0_rxdv */
--
2.43.0
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH v2 10/13] riscv: dts: spacemit: Add K3 eSPI pin group
@ 2026-12-04 4:21 ` Wang Yang
0 siblings, 0 replies; 27+ messages in thread
From: Wang Yang @ 2026-12-04 4:21 UTC (permalink / raw)
To: linux-kernel
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Yixun Lan,
Troy Mitchell, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, devicetree, linux-riscv, spacemit
Use normal pull-up explicitly and describe 25 mA drive as DS10 at 1.8 V.
Prepared with OpenAI Codex assistance.
Signed-off-by: Wang Yang <yang.wang@deepcomputing.io>
---
arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi | 24 ++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi b/arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi
index cb4f4f4e33af..90f2de7a5c07 100644
--- a/arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi
+++ b/arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi
@@ -11,6 +11,30 @@
#define K3_GPIO(x) (x / 32) (x % 32)
&pinctrl {
+ espi0_2_cfg: espi0-2-cfg {
+ espi0-0-pins {
+ pinmux = <K3_PADCONF(91, 4)>, /* espi0 d0 */
+ <K3_PADCONF(92, 4)>, /* espi0 d1 */
+ <K3_PADCONF(93, 4)>, /* espi0 d2 */
+ <K3_PADCONF(94, 4)>, /* espi0 d3 */
+ <K3_PADCONF(95, 4)>, /* espi0 cs */
+ <K3_PADCONF(97, 4)>, /* espi0 reset */
+ <K3_PADCONF(98, 4)>; /* espi0 alert */
+
+ bias-pull-up = <0>; /* normal pull-up */
+ drive-strength = <25>; /* DS10 at 1.8V */
+ power-source = <1800>;
+ };
+
+ espi0-1-pins {
+ pinmux = <K3_PADCONF(96, 4)>; /* espi0 clk */
+
+ bias-pull-down; /* normal pull-down */
+ drive-strength = <25>; /* DS10 at 1.8V */
+ power-source = <1800>;
+ };
+ };
+
gmac0_rgmii_0_cfg: gmac0-rgmii-0-cfg {
gmac0-rgmii-0-pins {
pinmux = <K3_PADCONF(0, 1)>, /* gmac0_rxdv */
--
2.43.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 27+ messages in thread* Re: [PATCH v2 10/13] riscv: dts: spacemit: Add K3 eSPI pin group
2026-12-04 4:21 ` Wang Yang
(?)
@ 2026-12-04 4:41 ` sashiko-bot
-1 siblings, 0 replies; 27+ messages in thread
From: sashiko-bot @ 2026-12-04 4:41 UTC (permalink / raw)
To: Wang Yang; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] riscv: dts: spacemit: espi0_2_cfg missing /omit-if-no-ref/ in
k3-pinctrl.dtsi
- [Low] riscv: dts: spacemit: commit message omits hardware context for
eSPI pin group
--
commit 573b76a43a83fcb0efa8f4f16e5cf89723836fe3
Author: Wang Yang <yang.wang@deepcomputing.io>
> riscv: dts: spacemit: Add K3 eSPI pin group
>
> Use normal pull-up explicitly and describe 25 mA drive as DS10 at 1.8 V.
>
> Prepared with OpenAI Codex assistance.
>
> Signed-off-by: Wang Yang <yang.wang@deepcomputing.io>
[Severity: Low]
The commit message reads like a patch revision note rather than a
standalone changelog. Should it describe the espi0_2_cfg group being
added (pads 91-98 in alt function 4, pull-down on clk vs pull-up on the
other pins, and why 1.8 V power-source is fixed at the SoC level)?
> diff --git a/arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi b/arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi
> index cb4f4f4e33aff..90f2de7a5c07c 100644
> --- a/arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi
> +++ b/arch/riscv/boot/dts/spacemit/k3-pinctrl.dtsi
> @@ -11,6 +11,30 @@
> #define K3_GPIO(x) (x / 32) (x % 32)
>
> &pinctrl {
> + espi0_2_cfg: espi0-2-cfg {
[Severity: Low]
Should espi0_2_cfg be marked with /omit-if-no-ref/ like the other
optional peripheral pin groups in k3-pinctrl.dtsi? Without it, dtc
emits espi0-2-cfg and both pin subnodes into every K3 board DTB, even on
boards such as k3-pico-itx.dts that do not use eSPI.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204042112.2985112-1-yang.wang@deepcomputing.io?part=10
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH v2 11/13] riscv: dts: spacemit: Describe the K3 eSPI controller
2026-12-04 4:20 ` Wang Yang
@ 2026-12-04 4:21 ` Wang Yang
-1 siblings, 0 replies; 27+ messages in thread
From: Wang Yang @ 2026-12-04 4:21 UTC (permalink / raw)
To: linux-kernel
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Yixun Lan,
Troy Mitchell, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, devicetree, linux-riscv, spacemit
Describe the controller resources and corrected link properties.
Require explicit MEM1 configuration; retain the BSP value until vendor
register documentation establishes a different interpretation.
Prepared with OpenAI Codex assistance.
Signed-off-by: Wang Yang <yang.wang@deepcomputing.io>
---
arch/riscv/boot/dts/spacemit/k3.dtsi | 30 ++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/arch/riscv/boot/dts/spacemit/k3.dtsi b/arch/riscv/boot/dts/spacemit/k3.dtsi
index e89d2cc5ca8c..88a265973d13 100644
--- a/arch/riscv/boot/dts/spacemit/k3.dtsi
+++ b/arch/riscv/boot/dts/spacemit/k3.dtsi
@@ -648,6 +648,36 @@ gmac1_axi_setup: stmmac-axi-config {
};
};
+ espi0: espi@cac8c000 {
+ compatible = "spacemit,k3-espi";
+ reg = <0x0 0xcac8c000 0x0 0x1000>;
+ ranges = <0x0 0x0 0x84000000 0x1000>;
+ #address-cells = <1>;
+ #size-cells = <1>;
+ clocks = <&syscon_apmu CLK_APMU_ESPI_SCLK_SRC>,
+ <&syscon_apmu CLK_APMU_ESPI_SCLK>,
+ <&syscon_apmu CLK_APMU_ESPI_MCLK>;
+ clock-names = "sclk_src", "sclk", "mclk";
+ resets = <&syscon_apmu RESET_APMU_ESPI_MCLK>,
+ <&syscon_apmu RESET_APMU_ESPI_SCLK>;
+ assigned-clocks = <&syscon_apmu CLK_APMU_ESPI_SCLK>;
+ assigned-clock-parents = <&syscon_apmu CLK_APMU_ESPI_SCLK_SRC>;
+ max-frequency = <20000000>;
+ spacemit,pr-mem-base1 = <0xcac8c000>;
+ spacemit,io-mode = "single";
+ spacemit,alert-mode = "io1";
+ spacemit,alert-type = "open-drain";
+ spacemit,watchdog-timeout = <0xffff>;
+ spacemit,crc-enable;
+ spacemit,auto-gating-enable;
+ spacemit,peripheral-channel-enable;
+ spacemit,vwire-channel-enable;
+ spacemit,oob-channel-enable;
+ spacemit,flash-channel-enable;
+
+ status = "disabled";
+ };
+
eth2: ethernet@cac8e000 {
compatible = "spacemit,k3-dwmac", "snps,dwmac-5.40a";
reg = <0x0 0xcac8e000 0x0 0x2000>;
--
2.43.0
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH v2 11/13] riscv: dts: spacemit: Describe the K3 eSPI controller
@ 2026-12-04 4:21 ` Wang Yang
0 siblings, 0 replies; 27+ messages in thread
From: Wang Yang @ 2026-12-04 4:21 UTC (permalink / raw)
To: linux-kernel
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Yixun Lan,
Troy Mitchell, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, devicetree, linux-riscv, spacemit
Describe the controller resources and corrected link properties.
Require explicit MEM1 configuration; retain the BSP value until vendor
register documentation establishes a different interpretation.
Prepared with OpenAI Codex assistance.
Signed-off-by: Wang Yang <yang.wang@deepcomputing.io>
---
arch/riscv/boot/dts/spacemit/k3.dtsi | 30 ++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/arch/riscv/boot/dts/spacemit/k3.dtsi b/arch/riscv/boot/dts/spacemit/k3.dtsi
index e89d2cc5ca8c..88a265973d13 100644
--- a/arch/riscv/boot/dts/spacemit/k3.dtsi
+++ b/arch/riscv/boot/dts/spacemit/k3.dtsi
@@ -648,6 +648,36 @@ gmac1_axi_setup: stmmac-axi-config {
};
};
+ espi0: espi@cac8c000 {
+ compatible = "spacemit,k3-espi";
+ reg = <0x0 0xcac8c000 0x0 0x1000>;
+ ranges = <0x0 0x0 0x84000000 0x1000>;
+ #address-cells = <1>;
+ #size-cells = <1>;
+ clocks = <&syscon_apmu CLK_APMU_ESPI_SCLK_SRC>,
+ <&syscon_apmu CLK_APMU_ESPI_SCLK>,
+ <&syscon_apmu CLK_APMU_ESPI_MCLK>;
+ clock-names = "sclk_src", "sclk", "mclk";
+ resets = <&syscon_apmu RESET_APMU_ESPI_MCLK>,
+ <&syscon_apmu RESET_APMU_ESPI_SCLK>;
+ assigned-clocks = <&syscon_apmu CLK_APMU_ESPI_SCLK>;
+ assigned-clock-parents = <&syscon_apmu CLK_APMU_ESPI_SCLK_SRC>;
+ max-frequency = <20000000>;
+ spacemit,pr-mem-base1 = <0xcac8c000>;
+ spacemit,io-mode = "single";
+ spacemit,alert-mode = "io1";
+ spacemit,alert-type = "open-drain";
+ spacemit,watchdog-timeout = <0xffff>;
+ spacemit,crc-enable;
+ spacemit,auto-gating-enable;
+ spacemit,peripheral-channel-enable;
+ spacemit,vwire-channel-enable;
+ spacemit,oob-channel-enable;
+ spacemit,flash-channel-enable;
+
+ status = "disabled";
+ };
+
eth2: ethernet@cac8e000 {
compatible = "spacemit,k3-dwmac", "snps,dwmac-5.40a";
reg = <0x0 0xcac8e000 0x0 0x2000>;
--
2.43.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 27+ messages in thread* Re: [PATCH v2 11/13] riscv: dts: spacemit: Describe the K3 eSPI controller
2026-12-04 4:21 ` Wang Yang
(?)
@ 2026-12-04 4:48 ` sashiko-bot
-1 siblings, 0 replies; 27+ messages in thread
From: sashiko-bot @ 2026-12-04 4:48 UTC (permalink / raw)
To: Wang Yang; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] riscv: dts: spacemit: espi0 sets spacemit,pr-mem-base1 to its
own MMIO base
- [Low] riscv: dts: spacemit: commit message uses revision-delta
phrasing
- [Low] riscv: dts: spacemit: board-level eSPI flags hardcoded in shared
k3.dtsi
--
commit f467024ef82df1d6d6bcf1c8b90cb44fb44533de
Author: Wang Yang <yang.wang@deepcomputing.io>
> riscv: dts: spacemit: Describe the K3 eSPI controller
>
> Describe the controller resources and corrected link properties.
> Require explicit MEM1 configuration; retain the BSP value until vendor
> register documentation establishes a different interpretation.
>
> Prepared with OpenAI Codex assistance.
>
> Signed-off-by: Wang Yang <yang.wang@deepcomputing.io>
[Severity: Low]
Can the commit message be rewritten to stand on its own? This patch adds
the espi0 node to k3.dtsi for the first time, so "corrected link properties"
reads like revision-changelog wording that belongs below the "---"
separator.
Similarly, "Require explicit MEM1 configuration" describes a binding and
driver policy from earlier patches in the series rather than what this DTS
change does. Describing why the K3 eSPI node is added and how its resources
are configured would make the permanent commit log clearer.
> diff --git a/arch/riscv/boot/dts/spacemit/k3.dtsi b/arch/riscv/boot/dts/spacemit/k3.dtsi
> index e89d2cc5ca8cc..88a265973d13d 100644
> --- a/arch/riscv/boot/dts/spacemit/k3.dtsi
> +++ b/arch/riscv/boot/dts/spacemit/k3.dtsi
> @@ -648,6 +648,36 @@ gmac1_axi_setup: stmmac-axi-config {
> };
> };
>
> + espi0: espi@cac8c000 {
> + compatible = "spacemit,k3-espi";
> + reg = <0x0 0xcac8c000 0x0 0x1000>;
> + ranges = <0x0 0x0 0x84000000 0x1000>;
[ ... ]
> + max-frequency = <20000000>;
> + spacemit,pr-mem-base1 = <0xcac8c000>;
[Severity: Medium]
Should spacemit,pr-mem-base1 point to the controller's own MMIO register
base (0xcac8c000)? spacemit_espi_program_window() writes this value
directly into ESPI_PR_BASE_ADDR_MEM1, which the binding documents as the
second peripheral-channel memory base register.
If ESPI_PR_BASE_ADDR_MEM1 configures a second peripheral memory decode
window, programming 0xcac8c000 aliases the eSPI controller's own control
registers and omits the window from standard DT ranges translation. If the
register has different hardware semantics, retaining an unverified BSP value
bakes an inaccurate description into the stable Devicetree ABI.
> + spacemit,io-mode = "single";
> + spacemit,alert-mode = "io1";
> + spacemit,alert-type = "open-drain";
> + spacemit,watchdog-timeout = <0xffff>;
> + spacemit,crc-enable;
> + spacemit,auto-gating-enable;
> + spacemit,peripheral-channel-enable;
> + spacemit,vwire-channel-enable;
> + spacemit,oob-channel-enable;
> + spacemit,flash-channel-enable;
[Severity: Low]
Should these board-level link and channel properties live in the board DTS
rather than k3.dtsi? Because spacemit_espi_parse_dt() reads the six
boolean flags with of_property_read_bool(), placing them in the shared SoC
file forces boards to inherit them or use /delete-property/ to disable them.
In particular, inheriting the vwire, OOB, and flash channel flags causes
spacemit_espi_configure_channels() to enable those channels on any EC that
advertises them, even though drivers/bus/spacemit-k3-espi.c has no IRQ
handler or RX drain path for them.
In addition, spacemit,alert-type = "open-drain" is ignored when
spacemit,alert-mode is "io1", and the five link value properties
(max-frequency, io-mode, alert-mode, alert-type, and watchdog-timeout) all
duplicate the binding and driver defaults.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204042112.2985112-1-yang.wang@deepcomputing.io?part=11
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH v2 12/13] riscv: dts: spacemit: Enable the FML13V05 EC keyboard
2026-12-04 4:20 ` Wang Yang
@ 2026-12-04 4:21 ` Wang Yang
-1 siblings, 0 replies; 27+ messages in thread
From: Wang Yang @ 2026-12-04 4:21 UTC (permalink / raw)
To: linux-kernel
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Yixun Lan,
Troy Mitchell, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, devicetree, linux-riscv, spacemit
Enable the EC window, GPIO event IRQ and existing EC keyboard driver.
Prepared with OpenAI Codex assistance.
Signed-off-by: Wang Yang <yang.wang@deepcomputing.io>
---
.../spacemit/k3-deepcomputing-fml13v05.dts | 137 ++++++++++++++++++
1 file changed, 137 insertions(+)
diff --git a/arch/riscv/boot/dts/spacemit/k3-deepcomputing-fml13v05.dts b/arch/riscv/boot/dts/spacemit/k3-deepcomputing-fml13v05.dts
index a80d32fe6f7f..6b292cca70cd 100644
--- a/arch/riscv/boot/dts/spacemit/k3-deepcomputing-fml13v05.dts
+++ b/arch/riscv/boot/dts/spacemit/k3-deepcomputing-fml13v05.dts
@@ -3,6 +3,8 @@
* Copyright (C) 2026 DeepComputing (HK) Limited
*/
+#include <dt-bindings/input/input.h>
+
#include "k3.dtsi"
#include "k3-pinctrl.dtsi"
@@ -32,6 +34,141 @@ reg_aux_vcc5v: regulator-aux-vcc5v {
};
};
+&espi0 {
+ pinctrl-0 = <&espi0_2_cfg>;
+ pinctrl-names = "default";
+
+ status = "okay";
+
+ ec: ec@0 {
+ compatible = "spacemit,k3-cros-ec";
+ reg = <0x0 0x1000>;
+ interrupt-parent = <&gpio>;
+ interrupts = <1 11 IRQ_TYPE_EDGE_RISING>;
+
+ keyboard-controller {
+ compatible = "google,cros-ec-keyb";
+ keypad,num-rows = <8>;
+ keypad,num-columns = <16>;
+ linux,keymap = <
+ /* Row 0 */
+ MATRIX_KEY(0x00, 0x00, KEY_C)
+ MATRIX_KEY(0x00, 0x01, KEY_DELETE)
+ MATRIX_KEY(0x00, 0x02, KEY_Q)
+ MATRIX_KEY(0x00, 0x03, KEY_RIGHTALT)
+ MATRIX_KEY(0x00, 0x05, KEY_X)
+ MATRIX_KEY(0x00, 0x06, KEY_V)
+ MATRIX_KEY(0x00, 0x07, KEY_M)
+ MATRIX_KEY(0x00, 0x08, KEY_DOT)
+ MATRIX_KEY(0x00, 0x09, KEY_RIGHTSHIFT)
+ MATRIX_KEY(0x00, 0x0a, KEY_COMMA)
+ MATRIX_KEY(0x00, 0x0c, KEY_RIGHTCTRL)
+ MATRIX_KEY(0x00, 0x0d, KEY_SLASH)
+ MATRIX_KEY(0x00, 0x0e, KEY_APOSTROPHE)
+
+ /* Row 1 */
+ MATRIX_KEY(0x01, 0x03, KEY_LEFTALT)
+ MATRIX_KEY(0x01, 0x04, KEY_SPACE)
+ MATRIX_KEY(0x01, 0x05, KEY_Z)
+ MATRIX_KEY(0x01, 0x06, KEY_B)
+ MATRIX_KEY(0x01, 0x07, KEY_N)
+ MATRIX_KEY(0x01, 0x08, KEY_DOWN)
+ MATRIX_KEY(0x01, 0x09, KEY_LEFTSHIFT)
+ MATRIX_KEY(0x01, 0x0c, KEY_LEFTCTRL)
+ MATRIX_KEY(0x01, 0x0d, KEY_UP)
+ MATRIX_KEY(0x01, 0x0e, KEY_ENTER)
+ MATRIX_KEY(0x01, 0x0f, KEY_F8)
+
+ /* Row 2 */
+ MATRIX_KEY(0x02, 0x02, KEY_FN)
+ MATRIX_KEY(0x02, 0x04, KEY_E)
+ MATRIX_KEY(0x02, 0x05, KEY_F2)
+ MATRIX_KEY(0x02, 0x06, KEY_G)
+ MATRIX_KEY(0x02, 0x07, KEY_H)
+ MATRIX_KEY(0x02, 0x08, KEY_BACKSLASH)
+ MATRIX_KEY(0x02, 0x0a, KEY_F7)
+ MATRIX_KEY(0x02, 0x0d, KEY_MINUS)
+ MATRIX_KEY(0x02, 0x0f, KEY_RIGHT)
+
+ /* Row 3 */
+ MATRIX_KEY(0x03, 0x01, KEY_LEFTMETA)
+ MATRIX_KEY(0x03, 0x02, KEY_TAB)
+ MATRIX_KEY(0x03, 0x04, KEY_F4)
+ MATRIX_KEY(0x03, 0x05, KEY_F1)
+ MATRIX_KEY(0x03, 0x06, KEY_T)
+ MATRIX_KEY(0x03, 0x07, KEY_Y)
+ MATRIX_KEY(0x03, 0x08, KEY_O)
+ MATRIX_KEY(0x03, 0x0a, KEY_F6)
+ MATRIX_KEY(0x03, 0x0b, KEY_F9)
+ MATRIX_KEY(0x03, 0x0d, KEY_F12)
+
+ /* Row 4 */
+ MATRIX_KEY(0x04, 0x02, KEY_GRAVE)
+ MATRIX_KEY(0x04, 0x04, KEY_CAPSLOCK)
+ MATRIX_KEY(0x04, 0x05, KEY_S)
+ MATRIX_KEY(0x04, 0x06, KEY_5)
+ MATRIX_KEY(0x04, 0x07, KEY_6)
+ MATRIX_KEY(0x04, 0x08, KEY_F10)
+ MATRIX_KEY(0x04, 0x0a, KEY_F5)
+ MATRIX_KEY(0x04, 0x0d, KEY_0)
+ MATRIX_KEY(0x04, 0x0e, KEY_EQUAL)
+
+ /* Row 5 */
+ MATRIX_KEY(0x05, 0x02, KEY_1)
+ MATRIX_KEY(0x05, 0x04, KEY_3)
+ MATRIX_KEY(0x05, 0x05, KEY_2)
+ MATRIX_KEY(0x05, 0x06, KEY_4)
+ MATRIX_KEY(0x05, 0x07, KEY_7)
+ MATRIX_KEY(0x05, 0x08, KEY_9)
+ MATRIX_KEY(0x05, 0x0a, KEY_8)
+ MATRIX_KEY(0x05, 0x0b, KEY_102ND)
+ MATRIX_KEY(0x05, 0x0d, KEY_P)
+ MATRIX_KEY(0x05, 0x0e, KEY_BACKSPACE)
+
+ /* Row 6 */
+ MATRIX_KEY(0x06, 0x04, KEY_F3)
+ MATRIX_KEY(0x06, 0x05, KEY_W)
+ MATRIX_KEY(0x06, 0x06, KEY_R)
+ MATRIX_KEY(0x06, 0x07, KEY_U)
+ MATRIX_KEY(0x06, 0x08, KEY_F11)
+ MATRIX_KEY(0x06, 0x0a, KEY_I)
+ MATRIX_KEY(0x06, 0x0b, KEY_LEFT)
+ MATRIX_KEY(0x06, 0x0d, KEY_LEFTBRACE)
+ MATRIX_KEY(0x06, 0x0e, KEY_RIGHTBRACE)
+
+ /* Row 7 */
+ MATRIX_KEY(0x07, 0x02, KEY_A)
+ MATRIX_KEY(0x07, 0x05, KEY_ESC)
+ MATRIX_KEY(0x07, 0x06, KEY_F)
+ MATRIX_KEY(0x07, 0x07, KEY_J)
+ MATRIX_KEY(0x07, 0x08, KEY_L)
+ MATRIX_KEY(0x07, 0x0a, KEY_K)
+ MATRIX_KEY(0x07, 0x0d, KEY_SEMICOLON)
+ MATRIX_KEY(0x07, 0x0e, KEY_D)
+
+ /* Fn layer (row + 8). */
+ MATRIX_KEY(0x08, 0x01, KEY_INSERT) /* Fn+Delete */
+ MATRIX_KEY(0x09, 0x08, KEY_PAGEDOWN) /* Fn+Down */
+ MATRIX_KEY(0x09, 0x0d, KEY_PAGEUP) /* Fn+Up */
+ MATRIX_KEY(0x09, 0x0f, KEY_BRIGHTNESSUP) /* Fn+F8 */
+ MATRIX_KEY(0x0a, 0x05, KEY_VOLUMEDOWN) /* Fn+F2 */
+ MATRIX_KEY(0x0a, 0x0a, KEY_BRIGHTNESSDOWN) /* Fn+F7 */
+ MATRIX_KEY(0x0a, 0x0f, KEY_END) /* Fn+Right */
+ MATRIX_KEY(0x0b, 0x04, KEY_PREVIOUSSONG) /* Fn+F4 */
+ MATRIX_KEY(0x0b, 0x05, KEY_MUTE) /* Fn+F1 */
+ MATRIX_KEY(0x0b, 0x0a, KEY_NEXTSONG) /* Fn+F6 */
+ MATRIX_KEY(0x0b, 0x0b, KEY_SWITCHVIDEOMODE) /* Fn+F9 */
+ MATRIX_KEY(0x0b, 0x0d, KEY_CONFIG) /* Fn+F12 */
+ MATRIX_KEY(0x0c, 0x08, KEY_RFKILL) /* Fn+F10 */
+ MATRIX_KEY(0x0c, 0x0a, KEY_PLAYPAUSE) /* Fn+F5 */
+ MATRIX_KEY(0x0e, 0x04, KEY_VOLUMEUP) /* Fn+F3 */
+ MATRIX_KEY(0x0e, 0x08, KEY_SYSRQ) /* Fn+F11 */
+ MATRIX_KEY(0x0e, 0x0b, KEY_HOME) /* Fn+Left */
+ >;
+ };
+ };
+};
+
&i2c8 {
pinctrl-names = "default";
pinctrl-0 = <&i2c8_cfg>;
--
2.43.0
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH v2 12/13] riscv: dts: spacemit: Enable the FML13V05 EC keyboard
@ 2026-12-04 4:21 ` Wang Yang
0 siblings, 0 replies; 27+ messages in thread
From: Wang Yang @ 2026-12-04 4:21 UTC (permalink / raw)
To: linux-kernel
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Yixun Lan,
Troy Mitchell, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Alexandre Ghiti, devicetree, linux-riscv, spacemit
Enable the EC window, GPIO event IRQ and existing EC keyboard driver.
Prepared with OpenAI Codex assistance.
Signed-off-by: Wang Yang <yang.wang@deepcomputing.io>
---
.../spacemit/k3-deepcomputing-fml13v05.dts | 137 ++++++++++++++++++
1 file changed, 137 insertions(+)
diff --git a/arch/riscv/boot/dts/spacemit/k3-deepcomputing-fml13v05.dts b/arch/riscv/boot/dts/spacemit/k3-deepcomputing-fml13v05.dts
index a80d32fe6f7f..6b292cca70cd 100644
--- a/arch/riscv/boot/dts/spacemit/k3-deepcomputing-fml13v05.dts
+++ b/arch/riscv/boot/dts/spacemit/k3-deepcomputing-fml13v05.dts
@@ -3,6 +3,8 @@
* Copyright (C) 2026 DeepComputing (HK) Limited
*/
+#include <dt-bindings/input/input.h>
+
#include "k3.dtsi"
#include "k3-pinctrl.dtsi"
@@ -32,6 +34,141 @@ reg_aux_vcc5v: regulator-aux-vcc5v {
};
};
+&espi0 {
+ pinctrl-0 = <&espi0_2_cfg>;
+ pinctrl-names = "default";
+
+ status = "okay";
+
+ ec: ec@0 {
+ compatible = "spacemit,k3-cros-ec";
+ reg = <0x0 0x1000>;
+ interrupt-parent = <&gpio>;
+ interrupts = <1 11 IRQ_TYPE_EDGE_RISING>;
+
+ keyboard-controller {
+ compatible = "google,cros-ec-keyb";
+ keypad,num-rows = <8>;
+ keypad,num-columns = <16>;
+ linux,keymap = <
+ /* Row 0 */
+ MATRIX_KEY(0x00, 0x00, KEY_C)
+ MATRIX_KEY(0x00, 0x01, KEY_DELETE)
+ MATRIX_KEY(0x00, 0x02, KEY_Q)
+ MATRIX_KEY(0x00, 0x03, KEY_RIGHTALT)
+ MATRIX_KEY(0x00, 0x05, KEY_X)
+ MATRIX_KEY(0x00, 0x06, KEY_V)
+ MATRIX_KEY(0x00, 0x07, KEY_M)
+ MATRIX_KEY(0x00, 0x08, KEY_DOT)
+ MATRIX_KEY(0x00, 0x09, KEY_RIGHTSHIFT)
+ MATRIX_KEY(0x00, 0x0a, KEY_COMMA)
+ MATRIX_KEY(0x00, 0x0c, KEY_RIGHTCTRL)
+ MATRIX_KEY(0x00, 0x0d, KEY_SLASH)
+ MATRIX_KEY(0x00, 0x0e, KEY_APOSTROPHE)
+
+ /* Row 1 */
+ MATRIX_KEY(0x01, 0x03, KEY_LEFTALT)
+ MATRIX_KEY(0x01, 0x04, KEY_SPACE)
+ MATRIX_KEY(0x01, 0x05, KEY_Z)
+ MATRIX_KEY(0x01, 0x06, KEY_B)
+ MATRIX_KEY(0x01, 0x07, KEY_N)
+ MATRIX_KEY(0x01, 0x08, KEY_DOWN)
+ MATRIX_KEY(0x01, 0x09, KEY_LEFTSHIFT)
+ MATRIX_KEY(0x01, 0x0c, KEY_LEFTCTRL)
+ MATRIX_KEY(0x01, 0x0d, KEY_UP)
+ MATRIX_KEY(0x01, 0x0e, KEY_ENTER)
+ MATRIX_KEY(0x01, 0x0f, KEY_F8)
+
+ /* Row 2 */
+ MATRIX_KEY(0x02, 0x02, KEY_FN)
+ MATRIX_KEY(0x02, 0x04, KEY_E)
+ MATRIX_KEY(0x02, 0x05, KEY_F2)
+ MATRIX_KEY(0x02, 0x06, KEY_G)
+ MATRIX_KEY(0x02, 0x07, KEY_H)
+ MATRIX_KEY(0x02, 0x08, KEY_BACKSLASH)
+ MATRIX_KEY(0x02, 0x0a, KEY_F7)
+ MATRIX_KEY(0x02, 0x0d, KEY_MINUS)
+ MATRIX_KEY(0x02, 0x0f, KEY_RIGHT)
+
+ /* Row 3 */
+ MATRIX_KEY(0x03, 0x01, KEY_LEFTMETA)
+ MATRIX_KEY(0x03, 0x02, KEY_TAB)
+ MATRIX_KEY(0x03, 0x04, KEY_F4)
+ MATRIX_KEY(0x03, 0x05, KEY_F1)
+ MATRIX_KEY(0x03, 0x06, KEY_T)
+ MATRIX_KEY(0x03, 0x07, KEY_Y)
+ MATRIX_KEY(0x03, 0x08, KEY_O)
+ MATRIX_KEY(0x03, 0x0a, KEY_F6)
+ MATRIX_KEY(0x03, 0x0b, KEY_F9)
+ MATRIX_KEY(0x03, 0x0d, KEY_F12)
+
+ /* Row 4 */
+ MATRIX_KEY(0x04, 0x02, KEY_GRAVE)
+ MATRIX_KEY(0x04, 0x04, KEY_CAPSLOCK)
+ MATRIX_KEY(0x04, 0x05, KEY_S)
+ MATRIX_KEY(0x04, 0x06, KEY_5)
+ MATRIX_KEY(0x04, 0x07, KEY_6)
+ MATRIX_KEY(0x04, 0x08, KEY_F10)
+ MATRIX_KEY(0x04, 0x0a, KEY_F5)
+ MATRIX_KEY(0x04, 0x0d, KEY_0)
+ MATRIX_KEY(0x04, 0x0e, KEY_EQUAL)
+
+ /* Row 5 */
+ MATRIX_KEY(0x05, 0x02, KEY_1)
+ MATRIX_KEY(0x05, 0x04, KEY_3)
+ MATRIX_KEY(0x05, 0x05, KEY_2)
+ MATRIX_KEY(0x05, 0x06, KEY_4)
+ MATRIX_KEY(0x05, 0x07, KEY_7)
+ MATRIX_KEY(0x05, 0x08, KEY_9)
+ MATRIX_KEY(0x05, 0x0a, KEY_8)
+ MATRIX_KEY(0x05, 0x0b, KEY_102ND)
+ MATRIX_KEY(0x05, 0x0d, KEY_P)
+ MATRIX_KEY(0x05, 0x0e, KEY_BACKSPACE)
+
+ /* Row 6 */
+ MATRIX_KEY(0x06, 0x04, KEY_F3)
+ MATRIX_KEY(0x06, 0x05, KEY_W)
+ MATRIX_KEY(0x06, 0x06, KEY_R)
+ MATRIX_KEY(0x06, 0x07, KEY_U)
+ MATRIX_KEY(0x06, 0x08, KEY_F11)
+ MATRIX_KEY(0x06, 0x0a, KEY_I)
+ MATRIX_KEY(0x06, 0x0b, KEY_LEFT)
+ MATRIX_KEY(0x06, 0x0d, KEY_LEFTBRACE)
+ MATRIX_KEY(0x06, 0x0e, KEY_RIGHTBRACE)
+
+ /* Row 7 */
+ MATRIX_KEY(0x07, 0x02, KEY_A)
+ MATRIX_KEY(0x07, 0x05, KEY_ESC)
+ MATRIX_KEY(0x07, 0x06, KEY_F)
+ MATRIX_KEY(0x07, 0x07, KEY_J)
+ MATRIX_KEY(0x07, 0x08, KEY_L)
+ MATRIX_KEY(0x07, 0x0a, KEY_K)
+ MATRIX_KEY(0x07, 0x0d, KEY_SEMICOLON)
+ MATRIX_KEY(0x07, 0x0e, KEY_D)
+
+ /* Fn layer (row + 8). */
+ MATRIX_KEY(0x08, 0x01, KEY_INSERT) /* Fn+Delete */
+ MATRIX_KEY(0x09, 0x08, KEY_PAGEDOWN) /* Fn+Down */
+ MATRIX_KEY(0x09, 0x0d, KEY_PAGEUP) /* Fn+Up */
+ MATRIX_KEY(0x09, 0x0f, KEY_BRIGHTNESSUP) /* Fn+F8 */
+ MATRIX_KEY(0x0a, 0x05, KEY_VOLUMEDOWN) /* Fn+F2 */
+ MATRIX_KEY(0x0a, 0x0a, KEY_BRIGHTNESSDOWN) /* Fn+F7 */
+ MATRIX_KEY(0x0a, 0x0f, KEY_END) /* Fn+Right */
+ MATRIX_KEY(0x0b, 0x04, KEY_PREVIOUSSONG) /* Fn+F4 */
+ MATRIX_KEY(0x0b, 0x05, KEY_MUTE) /* Fn+F1 */
+ MATRIX_KEY(0x0b, 0x0a, KEY_NEXTSONG) /* Fn+F6 */
+ MATRIX_KEY(0x0b, 0x0b, KEY_SWITCHVIDEOMODE) /* Fn+F9 */
+ MATRIX_KEY(0x0b, 0x0d, KEY_CONFIG) /* Fn+F12 */
+ MATRIX_KEY(0x0c, 0x08, KEY_RFKILL) /* Fn+F10 */
+ MATRIX_KEY(0x0c, 0x0a, KEY_PLAYPAUSE) /* Fn+F5 */
+ MATRIX_KEY(0x0e, 0x04, KEY_VOLUMEUP) /* Fn+F3 */
+ MATRIX_KEY(0x0e, 0x08, KEY_SYSRQ) /* Fn+F11 */
+ MATRIX_KEY(0x0e, 0x0b, KEY_HOME) /* Fn+Left */
+ >;
+ };
+ };
+};
+
&i2c8 {
pinctrl-names = "default";
pinctrl-0 = <&i2c8_cfg>;
--
2.43.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v2 13/13] riscv: defconfig: Enable the FML13V05 EC keyboard modules
2026-12-04 4:20 ` Wang Yang
@ 2026-12-04 4:21 ` Wang Yang
-1 siblings, 0 replies; 27+ messages in thread
From: Wang Yang @ 2026-12-04 4:21 UTC (permalink / raw)
To: linux-kernel
Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
linux-riscv
Enable the K3 controller and build EC transport and keyboard as modules.
Prepared with OpenAI Codex assistance.
Signed-off-by: Wang Yang <yang.wang@deepcomputing.io>
---
arch/riscv/configs/defconfig | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/riscv/configs/defconfig b/arch/riscv/configs/defconfig
index 21e7011a3b1d..de3d0c27748f 100644
--- a/arch/riscv/configs/defconfig
+++ b/arch/riscv/configs/defconfig
@@ -112,6 +112,7 @@ CONFIG_PCIE_FU740=y
CONFIG_PCIE_STARFIVE_HOST=m
CONFIG_DEVTMPFS=y
CONFIG_DEVTMPFS_MOUNT=y
+CONFIG_SPACEMIT_ESPI_BUS=y
CONFIG_SIFIVE_CCACHE=y
CONFIG_MTD=y
CONFIG_MTD_BLOCK=y
@@ -149,6 +150,7 @@ CONFIG_INPUT_MOUSEDEV=y
CONFIG_INPUT_EVDEV=y
CONFIG_KEYBOARD_GPIO=y
CONFIG_KEYBOARD_SUN4I_LRADC=m
+CONFIG_KEYBOARD_CROS_EC=m
CONFIG_SERIAL_8250=y
CONFIG_SERIAL_8250_CONSOLE=y
CONFIG_SERIAL_8250_DW=y
@@ -260,6 +262,9 @@ CONFIG_VIRTIO_PCI=y
CONFIG_VIRTIO_BALLOON=y
CONFIG_VIRTIO_INPUT=y
CONFIG_VIRTIO_MMIO=y
+CONFIG_CHROME_PLATFORMS=y
+CONFIG_CROS_EC=m
+CONFIG_CROS_EC_SPACEMIT_K3=m
CONFIG_CLK_SOPHGO_CV1800=y
CONFIG_CLK_SOPHGO_SG2042_PLL=y
CONFIG_CLK_SOPHGO_SG2042_CLKGEN=y
--
2.43.0
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v2 13/13] riscv: defconfig: Enable the FML13V05 EC keyboard modules
@ 2026-12-04 4:21 ` Wang Yang
0 siblings, 0 replies; 27+ messages in thread
From: Wang Yang @ 2026-12-04 4:21 UTC (permalink / raw)
To: linux-kernel
Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
linux-riscv
Enable the K3 controller and build EC transport and keyboard as modules.
Prepared with OpenAI Codex assistance.
Signed-off-by: Wang Yang <yang.wang@deepcomputing.io>
---
arch/riscv/configs/defconfig | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/riscv/configs/defconfig b/arch/riscv/configs/defconfig
index 21e7011a3b1d..de3d0c27748f 100644
--- a/arch/riscv/configs/defconfig
+++ b/arch/riscv/configs/defconfig
@@ -112,6 +112,7 @@ CONFIG_PCIE_FU740=y
CONFIG_PCIE_STARFIVE_HOST=m
CONFIG_DEVTMPFS=y
CONFIG_DEVTMPFS_MOUNT=y
+CONFIG_SPACEMIT_ESPI_BUS=y
CONFIG_SIFIVE_CCACHE=y
CONFIG_MTD=y
CONFIG_MTD_BLOCK=y
@@ -149,6 +150,7 @@ CONFIG_INPUT_MOUSEDEV=y
CONFIG_INPUT_EVDEV=y
CONFIG_KEYBOARD_GPIO=y
CONFIG_KEYBOARD_SUN4I_LRADC=m
+CONFIG_KEYBOARD_CROS_EC=m
CONFIG_SERIAL_8250=y
CONFIG_SERIAL_8250_CONSOLE=y
CONFIG_SERIAL_8250_DW=y
@@ -260,6 +262,9 @@ CONFIG_VIRTIO_PCI=y
CONFIG_VIRTIO_BALLOON=y
CONFIG_VIRTIO_INPUT=y
CONFIG_VIRTIO_MMIO=y
+CONFIG_CHROME_PLATFORMS=y
+CONFIG_CROS_EC=m
+CONFIG_CROS_EC_SPACEMIT_K3=m
CONFIG_CLK_SOPHGO_CV1800=y
CONFIG_CLK_SOPHGO_SG2042_PLL=y
CONFIG_CLK_SOPHGO_SG2042_CLKGEN=y
--
2.43.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 27+ messages in thread