Linux-RISC-V Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/13] Add SpacemiT K3 FML13V05 EC keyboard support
@ 2026-12-04  4:20 Wang Yang
  2026-12-04  4:21 ` [PATCH v2 05/13] dt-bindings: embedded-controller: Add SpacemiT K3 EC window Wang Yang
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ 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] 9+ messages in thread

* [PATCH v2 05/13] dt-bindings: embedded-controller: Add SpacemiT K3 EC window
  2026-12-04  4:20 [PATCH v2 00/13] Add SpacemiT K3 FML13V05 EC keyboard support Wang Yang
@ 2026-12-04  4:21 ` Wang Yang
  2026-12-04  4:21 ` [PATCH v2 06/13] dt-bindings: bus: Add SpacemiT K3 Intel eSPI controller Wang Yang
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ 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] 9+ messages in thread

* [PATCH v2 06/13] dt-bindings: bus: Add SpacemiT K3 Intel eSPI controller
  2026-12-04  4:20 [PATCH v2 00/13] Add SpacemiT K3 FML13V05 EC keyboard support Wang Yang
  2026-12-04  4:21 ` [PATCH v2 05/13] dt-bindings: embedded-controller: Add SpacemiT K3 EC window Wang Yang
@ 2026-12-04  4:21 ` Wang Yang
  2026-12-04  4:21 ` [PATCH v2 07/13] bus: Add SpacemiT K3 eSPI controller support Wang Yang
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ 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] 9+ messages in thread

* [PATCH v2 07/13] bus: Add SpacemiT K3 eSPI controller support
  2026-12-04  4:20 [PATCH v2 00/13] Add SpacemiT K3 FML13V05 EC keyboard support Wang Yang
  2026-12-04  4:21 ` [PATCH v2 05/13] dt-bindings: embedded-controller: Add SpacemiT K3 EC window Wang Yang
  2026-12-04  4:21 ` [PATCH v2 06/13] dt-bindings: bus: Add SpacemiT K3 Intel eSPI controller Wang Yang
@ 2026-12-04  4:21 ` Wang Yang
  2026-12-04  4:21 ` [PATCH v2 09/13] platform/chrome: Add SpacemiT K3 eSPI EC transport Wang Yang
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ 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] 9+ messages in thread

* [PATCH v2 09/13] platform/chrome: Add SpacemiT K3 eSPI EC transport
  2026-12-04  4:20 [PATCH v2 00/13] Add SpacemiT K3 FML13V05 EC keyboard support Wang Yang
                   ` (2 preceding siblings ...)
  2026-12-04  4:21 ` [PATCH v2 07/13] bus: Add SpacemiT K3 eSPI controller support Wang Yang
@ 2026-12-04  4:21 ` Wang Yang
  2026-12-04  4:21 ` [PATCH v2 10/13] riscv: dts: spacemit: Add K3 eSPI pin group Wang Yang
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ 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] 9+ messages in thread

* [PATCH v2 10/13] riscv: dts: spacemit: Add K3 eSPI pin group
  2026-12-04  4:20 [PATCH v2 00/13] Add SpacemiT K3 FML13V05 EC keyboard support Wang Yang
                   ` (3 preceding siblings ...)
  2026-12-04  4:21 ` [PATCH v2 09/13] platform/chrome: Add SpacemiT K3 eSPI EC transport Wang Yang
@ 2026-12-04  4:21 ` Wang Yang
  2026-12-04  4:21 ` [PATCH v2 11/13] riscv: dts: spacemit: Describe the K3 eSPI controller Wang Yang
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ 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] 9+ messages in thread

* [PATCH v2 11/13] riscv: dts: spacemit: Describe the K3 eSPI controller
  2026-12-04  4:20 [PATCH v2 00/13] Add SpacemiT K3 FML13V05 EC keyboard support Wang Yang
                   ` (4 preceding siblings ...)
  2026-12-04  4:21 ` [PATCH v2 10/13] riscv: dts: spacemit: Add K3 eSPI pin group Wang Yang
@ 2026-12-04  4:21 ` Wang Yang
  2026-12-04  4:21 ` [PATCH v2 12/13] riscv: dts: spacemit: Enable the FML13V05 EC keyboard Wang Yang
  2026-12-04  4:21 ` [PATCH v2 13/13] riscv: defconfig: Enable the FML13V05 EC keyboard modules Wang Yang
  7 siblings, 0 replies; 9+ 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] 9+ messages in thread

* [PATCH v2 12/13] riscv: dts: spacemit: Enable the FML13V05 EC keyboard
  2026-12-04  4:20 [PATCH v2 00/13] Add SpacemiT K3 FML13V05 EC keyboard support Wang Yang
                   ` (5 preceding siblings ...)
  2026-12-04  4:21 ` [PATCH v2 11/13] riscv: dts: spacemit: Describe the K3 eSPI controller Wang Yang
@ 2026-12-04  4:21 ` Wang Yang
  2026-12-04  4:21 ` [PATCH v2 13/13] riscv: defconfig: Enable the FML13V05 EC keyboard modules Wang Yang
  7 siblings, 0 replies; 9+ 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] 9+ messages in thread

* [PATCH v2 13/13] riscv: defconfig: Enable the FML13V05 EC keyboard modules
  2026-12-04  4:20 [PATCH v2 00/13] Add SpacemiT K3 FML13V05 EC keyboard support Wang Yang
                   ` (6 preceding siblings ...)
  2026-12-04  4:21 ` [PATCH v2 12/13] riscv: dts: spacemit: Enable the FML13V05 EC keyboard Wang Yang
@ 2026-12-04  4:21 ` Wang Yang
  7 siblings, 0 replies; 9+ 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] 9+ messages in thread

end of thread, other threads:[~2026-12-04  4:22 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04  4:20 [PATCH v2 00/13] Add SpacemiT K3 FML13V05 EC keyboard support Wang Yang
2026-12-04  4:21 ` [PATCH v2 05/13] dt-bindings: embedded-controller: Add SpacemiT K3 EC window Wang Yang
2026-12-04  4:21 ` [PATCH v2 06/13] dt-bindings: bus: Add SpacemiT K3 Intel eSPI controller Wang Yang
2026-12-04  4:21 ` [PATCH v2 07/13] bus: Add SpacemiT K3 eSPI controller support Wang Yang
2026-12-04  4:21 ` [PATCH v2 09/13] platform/chrome: Add SpacemiT K3 eSPI EC transport Wang Yang
2026-12-04  4:21 ` [PATCH v2 10/13] riscv: dts: spacemit: Add K3 eSPI pin group Wang Yang
2026-12-04  4:21 ` [PATCH v2 11/13] riscv: dts: spacemit: Describe the K3 eSPI controller Wang Yang
2026-12-04  4:21 ` [PATCH v2 12/13] riscv: dts: spacemit: Enable the FML13V05 EC keyboard Wang Yang
2026-12-04  4:21 ` [PATCH v2 13/13] riscv: defconfig: Enable the FML13V05 EC keyboard modules Wang Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox