Skip to contentSkip to conversation

spi: support the SpacemiT K1 SPI controller

PATCH Superseded Alex Elder 4 participants 11 messages Oct 27, 2025 – Nov 14, 2025

Subsystems (4)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Alex Elder

author
#0 lore raw

v6 cover spi: support the SpacemiT K1 SPI controller

This series adds support for the SPI controller found in the SpacemiT K1 SoC. The driver currently supports only master mode. The controller has two 32-entry FIFOs and supports PIO and DMA for transfers.

Version 6 is identical to version 5, other than being rebased onto a current linux-next/master.

-Alex

This series is available here:
https://github.com/riscstar/linux/tree/outgoing/spi-v6

Between version 5 and version 6:
- Rebase only

Here is version 5 of this series:
https://lore.kernel.org/lkml/[email protected]/

Between version 4 and version 5:
- Added Yixun's Reviewed-by tag on patch 3

Here is version 4 of this series:
https://lore.kernel.org/lkml/[email protected]/

Between version 3 and version 4 (all suggested by Yixun):
- Fixed an underrun/overrun comment error
- Renamed a pinctrl node
- Formatted dmas and dma-names properties on one line

Here is version 3 of this series:
https://lore.kernel.org/lkml/[email protected]/

Between version 2 and version 3:
- Add Conor's Acked-by to patch 1
- Add Rob's Reviewed-by to patch 1
- Added imply_PDMA to the SPI_SPACEMIT_K1 Kconfig option
- Fixed a bug pointed out by Vivian (and Troy) in word-sized reads
- Added a comment stating we use 1, 2, or 4 bytes per word
- Cleaned up DMA channels properly in case of failure setting up
- No longer use devm_*() for allocating DMA channels or buffer
- Moved the SPI controller into the dma-bus memory region

Here is version 2 of this series:
https://lore.kernel.org/lkml/[email protected]/

Between version 1 and version 2:
- Use enum rather than const for the binding compatible string
- Omit the label and status property in the binding example
- The spi-spacemit-k1.o make target is now added in sorted order
- The SPI_SPACEMIT_K1 config option is added in sorted order
- The SPI_SPACEMIT_K1 config does *not* depend on MMP_PDMA, however MMP_PDMA is checked at runtime, and if not enabled, DMA will not be used
- Read/modify/writes of registers no longer use an additional "virt" variable to hold the address accessed
- The k1_spi_driver_data->ioaddr field has been renamed base
- The DMA address for the base address is maintained, rather than saving the DMA address of the data register
- The spi-max-frequency property value is now bounds checked
- A local variable is now initialized to 0 in k1_spi_write_word()
- The driver name is now "k1-spi"
- DT aliases are used rather than spacemit,k1-ssp-id for bus number
- The order of two pin control properties was changed as requested
- Clock names and DMA names are now on one line in the "k1.dtsi"
- The interrupts property is used rather than interrupts-extended
- The order of two pin control properties was changed as requested
- Clock names and DMA names are now on one line in the "k1.dtsi"
- The interrupts property is used rather than interrupts-extended

Here is version 1 of this series:
https://lore.kernel.org/lkml/[email protected]/

Alex Elder (3):
dt-bindings: spi: add SpacemiT K1 SPI support
spi: spacemit: introduce SpacemiT K1 SPI controller driver
riscv: dts: spacemit: define a SPI controller node

 .../bindings/spi/spacemit,k1-spi.yaml         |  84 ++
 .../boot/dts/spacemit/k1-bananapi-f3.dts      |  15 +-
 arch/riscv/boot/dts/spacemit/k1-pinctrl.dtsi  |  20 +
 arch/riscv/boot/dts/spacemit/k1.dtsi          |  15 +
 drivers/spi/Kconfig                           |   9 +
 drivers/spi/Makefile                          |   1 +
 drivers/spi/spi-spacemit-k1.c                 | 965 ++++++++++++++++++
 7 files changed, 1105 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/spi/spacemit,k1-spi.yaml
 create mode 100644 drivers/spi/spi-spacemit-k1.c

base-commit: 8fec172c82c2b5f6f8e47ab837c1dc91ee3d1b87

Signature · 1 line
2.48.1
author
#1 lore raw

PATCH v6 1/3 dt-bindings: spi: add SpacemiT K1 SPI support

Add support for the SPI controller implemented by the SpacemiT K1 SoC.

---
 .../bindings/spi/spacemit,k1-spi.yaml         | 84 +++++++++++++++++++
 1 file changed, 84 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spi/spacemit,k1-spi.yaml
Documentation/devicetree/bindings/spi/spacemit,k1-spi.yaml new file +84 -0
new file mode 100644
index 0000000000000..e82c7f8d0b981
@@ -0,0 +1,84 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/spi/spacemit,k1-spi.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SpacemiT K1 SoC Serial Peripheral Interface (SPI)
+
+maintainers:
+  - Alex Elder <[email protected]>
+
+description:
+  The SpacemiT K1 SoC implements a SPI controller that has two 32-entry
+  FIFOs, for transmit and receive.  Details are currently available in
+  section 18.2.1 of the K1 User Manual, found in the SpacemiT Keystone
+  K1 Documentation[1].  The controller transfers words using PIO.  DMA
+  transfers are supported as well, if both TX and RX DMA channels are
+  specified,
+
+  [1] https://developer.spacemit.com/documentation
+
+allOf:
+  - $ref: /schemas/spi/spi-controller.yaml#
+
+properties:
+  compatible:
+    const: spacemit,k1-spi
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    items:
+      - description: Core clock
+      - description: Bus clock
+
+  clock-names:
+    items:
+      - const: core
+      - const: bus
+
+  resets:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  dmas:
+    items:
+      - description: RX DMA channel
+      - description: TX DMA channel
+
+  dma-names:
+    items:
+      - const: rx
+      - const: tx
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+  - resets
+  - interrupts
+
+unevaluatedProperties: false
+
+examples:
+  - |
+
+    #include <dt-bindings/clock/spacemit,k1-syscon.h>
+    spi@d401c000 {
+        compatible = "spacemit,k1-spi";
+        reg = <0xd401c000 0x30>;
+        #address-cells = <1>;
+        #size-cells = <0>;
+        clocks = <&syscon_apbc CLK_SSP3>,
+                 <&syscon_apbc CLK_SSP3_BUS>;
+        clock-names = "core", "bus";
+        resets = <&syscon_apbc RESET_SSP3>;
+        interrupts = <55>;
+        dmas = <&pdma 20>, <&pdma 19>;
+        dma-names = "rx", "tx";
+    };
Signature · 1 line
2.48.1
author
#3 lore raw

PATCH v6 2/3 spi: spacemit: introduce SpacemiT K1 SPI controller driver

In reply to Alex Elder

This patch introduces the driver for the SPI controller found in the SpacemiT K1 SoC. Currently the driver supports master mode only. The SPI hardware implements RX and TX FIFOs, 32 entries each, and supports both PIO and DMA mode transfers.

---
 drivers/spi/Kconfig           |   9 +
 drivers/spi/Makefile          |   1 +
 drivers/spi/spi-spacemit-k1.c | 965 ++++++++++++++++++++++++++++++++++
 3 files changed, 975 insertions(+)
 create mode 100644 drivers/spi/spi-spacemit-k1.c
drivers/spi/Kconfig +9 -0
index 4d8f00c850c14..2e933edab1718 100644
@@ -1071,6 +1071,15 @@ config SPI_SG2044_NOR
 	  also supporting 3Byte address devices and 4Byte address
 	  devices.
 
+config SPI_SPACEMIT_K1
+	tristate "K1 SPI Controller"
+	depends on ARCH_SPACEMIT || COMPILE_TEST
+	depends on OF
+	imply MMP_PDMA if ARCH_SPACEMIT
+	default ARCH_SPACEMIT
+	help
+	  Enable support for the SpacemiT K1 SPI controller.
+
 config SPI_SPRD
 	tristate "Spreadtrum SPI controller"
 	depends on ARCH_SPRD || COMPILE_TEST
drivers/spi/Makefile +1 -0
index 8ff74a13faaa8..c17e7d62dbe16 100644
@@ -140,6 +140,7 @@ obj-$(CONFIG_SPI_SIFIVE)		+= spi-sifive.o
 obj-$(CONFIG_SPI_SLAVE_MT27XX)          += spi-slave-mt27xx.o
 obj-$(CONFIG_SPI_SN_F_OSPI)		+= spi-sn-f-ospi.o
 obj-$(CONFIG_SPI_SG2044_NOR)	+= spi-sg2044-nor.o
+obj-$(CONFIG_SPI_SPACEMIT_K1)		+= spi-spacemit-k1.o
 obj-$(CONFIG_SPI_SPRD)			+= spi-sprd.o
 obj-$(CONFIG_SPI_SPRD_ADI)		+= spi-sprd-adi.o
 obj-$(CONFIG_SPI_STM32) 		+= spi-stm32.o
drivers/spi/spi-spacemit-k1.c new file +965 -0

965 lines not on this page · raw message

Signature · 1 line
2.48.1
reviewer
#4 lore raw

Re: [PATCH v6 2/3] spi: spacemit: introduce SpacemiT K1 SPI controller driver

Quoted 18 lines · Alex Elder

This patch introduces the driver for the SPI controller found in the SpacemiT K1 SoC. Currently the driver supports master mode only. The SPI hardware implements RX and TX FIFOs, 32 entries each, and supports both PIO and DMA mode transfers.

---
 drivers/spi/Kconfig           |   9 +
 drivers/spi/Makefile          |   1 +
 drivers/spi/spi-spacemit-k1.c | 965 ++++++++++++++++++++++++++++++++++
 3 files changed, 975 insertions(+)
 create mode 100644 drivers/spi/spi-spacemit-k1.c
drivers/spi/Kconfig +0 -0
index 4d8f00c850c14..2e933edab1718 100644

drivers/spi/Kconfig config SPI_SG2044_NOR · line 1079

Quoted 9 lines
drivers/spi/Kconfig +6 -0
@@ -1071,6 +1071,15 @@ config SPI_SG2044_NOR
 	  also supporting 3Byte address devices and 4Byte address
 	  devices.
 
+config SPI_SPACEMIT_K1
+	tristate "K1 SPI Controller"
+	depends on ARCH_SPACEMIT || COMPILE_TEST
+	depends on OF
+	imply MMP_PDMA if ARCH_SPACEMIT
+	default ARCH_SPACEMIT

SPI needs to be a built-in feature?
if not, how about:
default m if ARCH_SPACEMIT

- Troy

author
#5 lore raw

Re: [PATCH v6 2/3] spi: spacemit: introduce SpacemiT K1 SPI controller driver

Quoted 22 lines · Troy Mitchell
Quoted 21 lines · Alex Elder

This patch introduces the driver for the SPI controller found in the SpacemiT K1 SoC. Currently the driver supports master mode only. The SPI hardware implements RX and TX FIFOs, 32 entries each, and supports both PIO and DMA mode transfers.

---
  drivers/spi/Kconfig           |   9 +
  drivers/spi/Makefile          |   1 +
  drivers/spi/spi-spacemit-k1.c | 965 ++++++++++++++++++++++++++++++++++
  3 files changed, 975 insertions(+)

create mode 100644 drivers/spi/spi-spacemit-k1.c

drivers/spi/Kconfig +0 -0
index 4d8f00c850c14..2e933edab1718 100644
@@ -1071,6 +1071,15 @@ config SPI_SG2044_NOR
  	  also supporting 3Byte address devices and 4Byte address
  	  devices.
 
Quoted 9 lines

drivers/spi/Kconfig config SPI_SG2044_NOR · line 1079

Quoted 6 lines
drivers/spi/Kconfig +6 -0
+config SPI_SPACEMIT_K1
+	tristate "K1 SPI Controller"
+	depends on ARCH_SPACEMIT || COMPILE_TEST
+	depends on OF
+	imply MMP_PDMA if ARCH_SPACEMIT
+	default ARCH_SPACEMIT

SPI needs to be a built-in feature?
if not, how about:
default m if ARCH_SPACEMIT

I finally implemented this today and while testing I found a bug in the module removal code. It's been more than two weeks since I got any feedback on this series, and although I've been holding back on posting I think it's time to send a new version.

In addition to this suggestion, I have two bug fixes plus your Ack on patch 1, so I just posted v7.

-Alex

#6 lore raw

Re: [PATCH v6 2/3] spi: spacemit: introduce SpacemiT K1 SPI controller driver

In reply to Alex Elder
kernel test robot noticed the following build errors:

Hi Alex,

kernel test robot noticed the following build errors:

[auto build test ERROR on 8fec172c82c2b5f6f8e47ab837c1dc91ee3d1b87]

url:    https://github.com/intel-lab-lkp/linux/commits/Alex-Elder/dt-bindings-spi-add-SpacemiT-K1-SPI-support/20251027-211246
base:   8fec172c82c2b5f6f8e47ab837c1dc91ee3d1b87
patch link:    https://lore.kernel.org/r/20251027125504.297033-3-elder%40riscstar.com
patch subject: [PATCH v6 2/3] spi: spacemit: introduce SpacemiT K1 SPI controller driver
config: csky-allmodconfig (https://download.01.org/0day-ci/archive/20251031/[email protected]/config)
compiler: csky-linux-gcc (GCC) 15.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251031/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>, old ones prefixed by <<):

>> ERROR: modpost: "__udivdi3" [drivers/spi/spi-spacemit-k1.ko] undefined!
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#7 lore raw

Re: [PATCH v6 2/3] spi: spacemit: introduce SpacemiT K1 SPI controller driver

In reply to Alex Elder
kernel test robot noticed the following build errors:

Hi Alex,

kernel test robot noticed the following build errors:

[auto build test ERROR on 8fec172c82c2b5f6f8e47ab837c1dc91ee3d1b87]

url:    https://github.com/intel-lab-lkp/linux/commits/Alex-Elder/dt-bindings-spi-add-SpacemiT-K1-SPI-support/20251027-211246
base:   8fec172c82c2b5f6f8e47ab837c1dc91ee3d1b87
patch link:    https://lore.kernel.org/r/20251027125504.297033-3-elder%40riscstar.com
patch subject: [PATCH v6 2/3] spi: spacemit: introduce SpacemiT K1 SPI controller driver
config: hexagon-allmodconfig (https://download.01.org/0day-ci/archive/20251031/[email protected]/config)
compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251031/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>, old ones prefixed by <<):

>> ERROR: modpost: "__hexagon_udivdi3" [drivers/spi/spi-spacemit-k1.ko] undefined!

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for DMA_CMA
Depends on [n]: HAVE_DMA_CONTIGUOUS [=n] && CMA [=y]
Selected by [m]:
- SND_SOC_K1_I2S [=m] && SOUND [=m] && SND [=m] && SND_SOC [=m] && (COMPILE_TEST [=y] || ARCH_SPACEMIT) && HAVE_CLK [=y]

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author
#8 lore raw

PATCH v6 3/3 riscv: dts: spacemit: define a SPI controller node

In reply to Alex Elder

Define a node for the fourth SoC SPI controller (number 3) on the SpacemiT K1 SoC.

Enable it on the Banana Pi BPI-F3 board, which exposes this feature via its GPIO block:

  GPIO PIN 19:  MOSI
  GPIO PIN 21:  MISO
  GPIO PIN 23:  SCLK
  GPIO PIN 24:  SS (inverted)

Define pincontrol configurations for the pins as used on that board.

(This was tested using a GigaDevice GD25Q64E SPI NOR chip.)

---
 .../boot/dts/spacemit/k1-bananapi-f3.dts      |  7 +++++++
 arch/riscv/boot/dts/spacemit/k1-pinctrl.dtsi  | 20 +++++++++++++++++++
 arch/riscv/boot/dts/spacemit/k1.dtsi          | 15 ++++++++++++++
 3 files changed, 42 insertions(+)
arch/riscv/boot/dts/spacemit/k1-bananapi-f3.dts +7 -0
index 33ca816bfd4b3..0b0478c6f273d 100644
@@ -16,6 +16,7 @@ aliases {
 		serial0 = &uart0;
 		i2c2 = &i2c2;
 		i2c8 = &i2c8;
+		spi3 = &spi3;
 	};
 
 	chosen {
@@ -258,6 +259,12 @@ dldo7 {
 	};
 };
 
+&spi3 {
+	pinctrl-0 = <&ssp3_0_cfg>;
+	pinctrl-names = "default";
+	status = "okay";
+};
+
 &uart0 {
 	pinctrl-names = "default";
 	pinctrl-0 = <&uart0_2_cfg>;
arch/riscv/boot/dts/spacemit/k1-pinctrl.dtsi +20 -0
index 4eef81d583f3d..c4b9f6265a31a 100644
@@ -516,4 +516,24 @@ pwm14-1-pins {
 			drive-strength = <32>;
 		};
 	};
+
+	ssp3_0_cfg: ssp3-0-cfg {
+		ssp3-0-pins {
+			pinmux = <K1_PADCONF(75, 2)>,	/* SCLK */
+				 <K1_PADCONF(77, 2)>,	/* MOSI  */
+				 <K1_PADCONF(78, 2)>;	/* MISO */
+
+			bias-disable;
+			drive-strength = <19>;
+			power-source = <3300>;
+		};
+
+		ssp3-0-frm-pins {
+			pinmux = <K1_PADCONF(76, 2)>;	/* FRM (frame) */
+
+			bias-pull-up = <0>;
+			drive-strength = <19>;
+			power-source = <3300>;
+		};
+	};
 };
arch/riscv/boot/dts/spacemit/k1.dtsi +15 -0
index af35f9cd64351..990246a3b50ff 100644
@@ -823,6 +823,21 @@ uart9: serial@d4017800 {
 				status = "disabled";
 			};
 
+			spi3: spi@d401c000 {
+				compatible = "spacemit,k1-spi";
+				reg = <0x0 0xd401c000 0x0 0x30>;
+				#address-cells = <1>;
+				#size-cells = <0>;
+				clocks = <&syscon_apbc CLK_SSP3>,
+					 <&syscon_apbc CLK_SSP3_BUS>;
+				clock-names = "core", "bus";
+				resets = <&syscon_apbc RESET_SSP3>;
+				interrupts = <55>;
+				dmas = <&pdma 20>, <&pdma 19>;
+				dma-names = "rx", "tx";
+				status = "disabled";
+			};
+
 			/* sec_uart1: 0xf0612000, not available from Linux */
 		};
 
Signature · 1 line
2.48.1
maintainer
#9 lore raw
In reply to Alex Elder
Quoted 9 lines · Alex Elder

Between version 5 and version 6:
- Rebase only

Here is version 5 of this series:
https://lore.kernel.org/lkml/[email protected]/

Between version 4 and version 5:
- Added Yixun's Reviewed-by tag on patch 3

Please stop doing all these resends, this is just making things noisy and pushing you further down the review queue. You should not resend to collect tags, and you should leave a reasonable time for review.

author
#10 lore raw
Quoted 8 lines · Mark Brown
Quoted 6 lines · Alex Elder

Between version 5 and version 6:
- Rebase only

Here is version 5 of this series:

   https://lore.kernel.org/lkml/[email protected]/
Quoted 7 lines
Quoted 3 lines

Between version 4 and version 5:
- Added Yixun's Reviewed-by tag on patch 3

Please stop doing all these resends, this is just making things noisy and pushing you further down the review queue. You should not resend to collect tags, and you should leave a reasonable time for review.

OK, no more. -Alex