diff mbox series

[v3,1/4] board: spacemit: add SpacemiT K3 Pico-ITX

Message ID 20261003-00-basic-spacemit-k3-v3-1-dea68cd1bd7d@kernel.org
State Superseded
Delegated to: Tim Ouyang
Headers show
Series riscv: spacemit: Add support for K3 Pico-ITX board | expand

Commit Message

Yixun Lan Oct. 3, 2026, 12:34 a.m. UTC
Add initial support for K3 Pico-ITX board, in this version, the DRAM
information is parsed from DTS "/memory" node. And with UART enabled,
the U-Boot serial console works fine now.

Signed-off-by: Yixun Lan <dlan@kernel.org>
---
 arch/riscv/Kconfig            |  5 +++++
 arch/riscv/cpu/k3/Kconfig     | 18 ++++++++++++++++++
 arch/riscv/cpu/k3/Makefile    |  5 +++++
 arch/riscv/cpu/k3/dram.c      | 21 +++++++++++++++++++++
 board/spacemit/k3/Kconfig     | 30 ++++++++++++++++++++++++++++++
 board/spacemit/k3/MAINTAINERS |  8 ++++++++
 include/configs/spacemit-k3.h | 13 +++++++++++++
 7 files changed, 100 insertions(+)

Comments

E Shattow Oct. 3, 2026, 10:02 a.m. UTC | #1
Hi Yixun,

On 10/2/26 17:34, Yixun Lan wrote:
> Add initial support for K3 Pico-ITX board, in this version, the DRAM
> information is parsed from DTS "/memory" node. And with UART enabled,
> the U-Boot serial console works fine now.
> 
> Signed-off-by: Yixun Lan <dlan@kernel.org>
> ---
>  arch/riscv/Kconfig            |  5 +++++
>  arch/riscv/cpu/k3/Kconfig     | 18 ++++++++++++++++++
>  arch/riscv/cpu/k3/Makefile    |  5 +++++
>  arch/riscv/cpu/k3/dram.c      | 21 +++++++++++++++++++++
>  board/spacemit/k3/Kconfig     | 30 ++++++++++++++++++++++++++++++
>  board/spacemit/k3/MAINTAINERS |  8 ++++++++
>  include/configs/spacemit-k3.h | 13 +++++++++++++
>  7 files changed, 100 insertions(+)
> 
> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> index c1b2890f1f3..386241efd4a 100644
> --- a/arch/riscv/Kconfig
> +++ b/arch/riscv/Kconfig
> @@ -53,6 +53,9 @@ config TARGET_SIPEED_MAIX
>  config TARGET_SPACEMIT_K1
>  	bool "Support Spacemit K1 SoC"
>  
> +config TARGET_SPACEMIT_K3
> +	bool "Support SpacemiT K3 SoC"
> +
>  config TARGET_STARFIVE_VISIONFIVE2
>  	bool "Support StarFive VisionFive2 Board"
>  	select BOARD_LATE_INIT
> @@ -124,6 +127,7 @@ source "board/sophgo/milkv_duo/Kconfig"
>  source "board/sophgo/milkv_duo_256m/Kconfig"
>  source "board/sophgo/licheerv_nano/Kconfig"
>  source "board/spacemit/k1/Kconfig"
> +source "board/spacemit/k3/Kconfig"
>  source "board/starfive/visionfive2/Kconfig"
>  source "board/thead/th1520_lpi4a/Kconfig"
>  source "board/xilinx/mbv/Kconfig"
> @@ -138,6 +142,7 @@ source "arch/riscv/cpu/mpfs/Kconfig"
>  source "arch/riscv/cpu/generic/Kconfig"
>  source "arch/riscv/cpu/jh7110/Kconfig"
>  source "arch/riscv/cpu/k1/Kconfig"
> +source "arch/riscv/cpu/k3/Kconfig"
>  source "arch/riscv/cpu/k230/Kconfig"
>  source "arch/riscv/cpu/th1520/Kconfig"
>  
> diff --git a/arch/riscv/cpu/k3/Kconfig b/arch/riscv/cpu/k3/Kconfig
> new file mode 100644
> index 00000000000..5474ac11243
> --- /dev/null
> +++ b/arch/riscv/cpu/k3/Kconfig
> @@ -0,0 +1,18 @@
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +#
> +# Copyright (C) 2026 Yixun Lan <dlan@kernel.org>
> +
> +if TARGET_SPACEMIT_K3
> +
> +config SPACEMIT_K3
> +	bool
> +	select BINMAN
> +	select ARCH_EARLY_INIT_R
> +	select SYS_CACHE_SHIFT_6
> +	imply CPU
> +	imply CPU_RISCV
> +	imply RISCV_TIMER if RISCV_SMODE
> +	imply CMD_CPU
> +	imply OF_UPSTREAM
> +
> +endif
> diff --git a/arch/riscv/cpu/k3/Makefile b/arch/riscv/cpu/k3/Makefile
> new file mode 100644
> index 00000000000..fba4e4b0a3f
> --- /dev/null
> +++ b/arch/riscv/cpu/k3/Makefile
> @@ -0,0 +1,5 @@
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +#
> +# Copyright (C) 2026 Yixun Lan <dlan@kernel.org>
> +
> +obj-y += dram.o
> diff --git a/arch/riscv/cpu/k3/dram.c b/arch/riscv/cpu/k3/dram.c
> new file mode 100644
> index 00000000000..e20d35dc1bf
> --- /dev/null
> +++ b/arch/riscv/cpu/k3/dram.c
> @@ -0,0 +1,21 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) 2026 Yixun Lan <dlan@kernel.org>
> + */
> +
> +#include <fdtdec.h>
> +#include <init.h>
> +#include <linux/sizes.h>
> +#include <asm/global_data.h>
> +
> +DECLARE_GLOBAL_DATA_PTR;
> +
> +int dram_init(void)
> +{
> +	return fdtdec_setup_mem_size_base();
> +}
> +
> +int dram_init_banksize(void)
> +{
> +	return fdtdec_setup_memory_banksize();
> +}
> diff --git a/board/spacemit/k3/Kconfig b/board/spacemit/k3/Kconfig
> new file mode 100644
> index 00000000000..1a63c73b6bb
> --- /dev/null
> +++ b/board/spacemit/k3/Kconfig
> @@ -0,0 +1,30 @@
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +#
> +# Copyright (C) 2026 Yixun Lan <dlan@kernel.org>
> +
> +if TARGET_SPACEMIT_K3
> +

> +config SYS_BOARD
> +	default "k3"

Let's arbitrarily change user-facing SYS_BOARD to "spacemit_k3" stem of
u-boot config filename "spacemit_k3_defconfig":

+config SYS_BOARD
-	default "k3"
+	default "spacemit_k3"

The use of SYS_BOARD is compiled-in as various runtime outputs e.g.
SMBIOS data structure. I think "spacemit_k3" is not a very interesting
or descriptive name to communicate all the boards that may be supported,
but it is better for a user to see this defconfig filename stem than
simply "k3" as the board name. I do not have any better suggestion
because it is a compile-time substitution and board selection is likely
to be at runtime.

> +
> +config SYS_VENDOR
> +	default "spacemit"
> +
> +config SYS_CPU
> +	default "k3"
> +
> +config SYS_CONFIG_NAME
> +	default "spacemit-k3"
> +

Looks good, thanks for picking up that rename.

> +config TEXT_BASE
> +	default 0x102000000
> +
> +config SPL_OPENSBI_LOAD_ADDR
> +	hex
> +	default 0x100000000
> +
> +config BOARD_SPECIFIC_OPTIONS
> +	def_bool y
> +	select SPACEMIT_K3
> +
> +endif
> diff --git a/board/spacemit/k3/MAINTAINERS b/board/spacemit/k3/MAINTAINERS
> new file mode 100644
> index 00000000000..34cf1ed4453
> --- /dev/null
> +++ b/board/spacemit/k3/MAINTAINERS
> @@ -0,0 +1,8 @@
> +SPACEMIT K3
> +M:	Yixun Lan <dlan@kernel.org>
> +S:	Maintained
> +F:	arch/riscv/cpu/k3/
> +F:	board/spacemit/k3/
> +F:	configs/spacemit_k3_defconfig
> +F:	include/configs/k3.h
> +F:	arch/riscv/dts/k3-u-boot.dtsi
> diff --git a/include/configs/spacemit-k3.h b/include/configs/spacemit-k3.h
> new file mode 100644
> index 00000000000..9dd545e2a3b
> --- /dev/null
> +++ b/include/configs/spacemit-k3.h
> @@ -0,0 +1,13 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * Copyright (C) 2026 Yixun Lan <dlan@kernel.org>
> + */
> +
> +#ifndef __SPACEMIT_K3_H
> +#define __SPACEMIT_K3_H
> +
> +#define CFG_SYS_NS16550_IER	0x40
> +
> +#define RISCV_SMODE_TIMER_FREQ	24000000
> +
> +#endif /* __SPACEMIT_K3_H */
> 

With that, looks good to me.

Reviewed-by: E Shattow <e@freeshell.de>
Yixun Lan Oct. 3, 2026, 11:08 a.m. UTC | #2
Hi E Shattow, 

On 03:02 Sat 03 Oct     , E Shattow wrote:
> Hi Yixun,
> 
..
> > diff --git a/board/spacemit/k3/Kconfig b/board/spacemit/k3/Kconfig
> > new file mode 100644
> > index 00000000000..1a63c73b6bb
> > --- /dev/null
> > +++ b/board/spacemit/k3/Kconfig
> > @@ -0,0 +1,30 @@
> > +# SPDX-License-Identifier: GPL-2.0-or-later
> > +#
> > +# Copyright (C) 2026 Yixun Lan <dlan@kernel.org>
> > +
> > +if TARGET_SPACEMIT_K3
> > +
> 
> > +config SYS_BOARD
> > +	default "k3"
> 
> Let's arbitrarily change user-facing SYS_BOARD to "spacemit_k3" stem of
> u-boot config filename "spacemit_k3_defconfig":
> 
> +config SYS_BOARD
> -	default "k3"
> +	default "spacemit_k3"
> 
> The use of SYS_BOARD is compiled-in as various runtime outputs e.g.
> SMBIOS data structure. 
Could you iterate a bit more on this? I've not seen K3 used SMBIOS or will

> I think "spacemit_k3" is not a very interesting
> or descriptive name to communicate all the boards that may be supported,
> but it is better for a user to see this defconfig filename stem than
> simply "k3" as the board name. I do not have any better suggestion
> because it is a compile-time substitution and board selection is likely
> to be at runtime.
> 
I incline to simply keep it as "k3", I've checked all places refer to SYS_BOARD
which all will be used under SYS_VENDOR realm or somehow has connection with it,
so there should be no conflicts, to me, it's kind of redudant to change to
'spacemit_k3', for reference to arch/Kconfig

config SYS_BOARD
        string
        help
          This option should contain the name of the target board.
          If it is set, either board/<CONFIG_SYS_VENDOR>/<CONFIG_SYS_BOARD>
          or board/<CONFIG_SYS_BOARD> directory is compiled depending on
          whether CONFIG_SYS_VENDOR is set or not.

          This is optional.  For those targets without the board directory,
          leave this option empty.


On the other hand, I do not see SYS_BOARD should strictly follow
the name of defconfig, various board did so

some other source code I checked

cmd/pxe.c:20:   "default-" CONFIG_SYS_ARCH "-" CONFIG_SYS_SOC "-" CONFIG_SYS_BOARD,
config.mk:29:BOARD := $(CONFIG_SYS_BOARD:"%"=%)
env/Kconfig:20:   the file board/<vendor>/<board>/<SYS_BOARD>.env exists. Otherwise the
include/env_default.h:93:#ifdef CONFIG_SYS_BOARD
tools/buildman/boards.py:194:        'board' : 'SYS_BOARD',

> > +
> > +config SYS_VENDOR
> > +	default "spacemit"
> > +
E Shattow Oct. 3, 2026, 11:18 a.m. UTC | #3
On 10/3/26 04:08, Yixun Lan wrote:
> Hi E Shattow, 
> 
> On 03:02 Sat 03 Oct     , E Shattow wrote:
>> Hi Yixun,
>>
> ..
>>> diff --git a/board/spacemit/k3/Kconfig b/board/spacemit/k3/Kconfig
>>> new file mode 100644
>>> index 00000000000..1a63c73b6bb
>>> --- /dev/null
>>> +++ b/board/spacemit/k3/Kconfig
>>> @@ -0,0 +1,30 @@
>>> +# SPDX-License-Identifier: GPL-2.0-or-later
>>> +#
>>> +# Copyright (C) 2026 Yixun Lan <dlan@kernel.org>
>>> +
>>> +if TARGET_SPACEMIT_K3
>>> +
>>
>>> +config SYS_BOARD
>>> +	default "k3"
>>
>> Let's arbitrarily change user-facing SYS_BOARD to "spacemit_k3" stem of
>> u-boot config filename "spacemit_k3_defconfig":
>>
>> +config SYS_BOARD
>> -	default "k3"
>> +	default "spacemit_k3"
>>
>> The use of SYS_BOARD is compiled-in as various runtime outputs e.g.
>> SMBIOS data structure. 
> Could you iterate a bit more on this? I've not seen K3 used SMBIOS or will
> 

Disregard, I got this detail wrong.


>> I think "spacemit_k3" is not a very interesting
>> or descriptive name to communicate all the boards that may be supported,
>> but it is better for a user to see this defconfig filename stem than
>> simply "k3" as the board name. I do not have any better suggestion
>> because it is a compile-time substitution and board selection is likely
>> to be at runtime.
>>
> I incline to simply keep it as "k3", I've checked all places refer to SYS_BOARD
> which all will be used under SYS_VENDOR realm or somehow has connection with it,
> so there should be no conflicts, to me, it's kind of redudant to change to
> 'spacemit_k3', for reference to arch/Kconfig
> 
> config SYS_BOARD
>         string
>         help
>           This option should contain the name of the target board.
>           If it is set, either board/<CONFIG_SYS_VENDOR>/<CONFIG_SYS_BOARD>
>           or board/<CONFIG_SYS_BOARD> directory is compiled depending on
>           whether CONFIG_SYS_VENDOR is set or not.
> 
>           This is optional.  For those targets without the board directory,
>           leave this option empty.
> 
> 
> On the other hand, I do not see SYS_BOARD should strictly follow
> the name of defconfig, various board did so
> 
> some other source code I checked
> 

Yes, keep SYS_BOARD as "k3" is fine. I forgot then that it will affect
the build in this way and that is not any benefit worth changing the
path and everything u-boot build system is looking for. I wish there is
a better name for it than the SoC on a build target that is not just any
one board name, but what we have is not any problem itself.

> cmd/pxe.c:20:   "default-" CONFIG_SYS_ARCH "-" CONFIG_SYS_SOC "-" CONFIG_SYS_BOARD,
> config.mk:29:BOARD := $(CONFIG_SYS_BOARD:"%"=%)
> env/Kconfig:20:   the file board/<vendor>/<board>/<SYS_BOARD>.env exists. Otherwise the
> include/env_default.h:93:#ifdef CONFIG_SYS_BOARD
> tools/buildman/boards.py:194:        'board' : 'SYS_BOARD',
> 
>>> +
>>> +config SYS_VENDOR
>>> +	default "spacemit"
>>> +
> 

Keep R-by tag, no changes requested to SYS_BOARD, thanks!

-E
diff mbox series

Patch

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index c1b2890f1f3..386241efd4a 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -53,6 +53,9 @@  config TARGET_SIPEED_MAIX
 config TARGET_SPACEMIT_K1
 	bool "Support Spacemit K1 SoC"
 
+config TARGET_SPACEMIT_K3
+	bool "Support SpacemiT K3 SoC"
+
 config TARGET_STARFIVE_VISIONFIVE2
 	bool "Support StarFive VisionFive2 Board"
 	select BOARD_LATE_INIT
@@ -124,6 +127,7 @@  source "board/sophgo/milkv_duo/Kconfig"
 source "board/sophgo/milkv_duo_256m/Kconfig"
 source "board/sophgo/licheerv_nano/Kconfig"
 source "board/spacemit/k1/Kconfig"
+source "board/spacemit/k3/Kconfig"
 source "board/starfive/visionfive2/Kconfig"
 source "board/thead/th1520_lpi4a/Kconfig"
 source "board/xilinx/mbv/Kconfig"
@@ -138,6 +142,7 @@  source "arch/riscv/cpu/mpfs/Kconfig"
 source "arch/riscv/cpu/generic/Kconfig"
 source "arch/riscv/cpu/jh7110/Kconfig"
 source "arch/riscv/cpu/k1/Kconfig"
+source "arch/riscv/cpu/k3/Kconfig"
 source "arch/riscv/cpu/k230/Kconfig"
 source "arch/riscv/cpu/th1520/Kconfig"
 
diff --git a/arch/riscv/cpu/k3/Kconfig b/arch/riscv/cpu/k3/Kconfig
new file mode 100644
index 00000000000..5474ac11243
--- /dev/null
+++ b/arch/riscv/cpu/k3/Kconfig
@@ -0,0 +1,18 @@ 
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Copyright (C) 2026 Yixun Lan <dlan@kernel.org>
+
+if TARGET_SPACEMIT_K3
+
+config SPACEMIT_K3
+	bool
+	select BINMAN
+	select ARCH_EARLY_INIT_R
+	select SYS_CACHE_SHIFT_6
+	imply CPU
+	imply CPU_RISCV
+	imply RISCV_TIMER if RISCV_SMODE
+	imply CMD_CPU
+	imply OF_UPSTREAM
+
+endif
diff --git a/arch/riscv/cpu/k3/Makefile b/arch/riscv/cpu/k3/Makefile
new file mode 100644
index 00000000000..fba4e4b0a3f
--- /dev/null
+++ b/arch/riscv/cpu/k3/Makefile
@@ -0,0 +1,5 @@ 
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Copyright (C) 2026 Yixun Lan <dlan@kernel.org>
+
+obj-y += dram.o
diff --git a/arch/riscv/cpu/k3/dram.c b/arch/riscv/cpu/k3/dram.c
new file mode 100644
index 00000000000..e20d35dc1bf
--- /dev/null
+++ b/arch/riscv/cpu/k3/dram.c
@@ -0,0 +1,21 @@ 
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2026 Yixun Lan <dlan@kernel.org>
+ */
+
+#include <fdtdec.h>
+#include <init.h>
+#include <linux/sizes.h>
+#include <asm/global_data.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+int dram_init(void)
+{
+	return fdtdec_setup_mem_size_base();
+}
+
+int dram_init_banksize(void)
+{
+	return fdtdec_setup_memory_banksize();
+}
diff --git a/board/spacemit/k3/Kconfig b/board/spacemit/k3/Kconfig
new file mode 100644
index 00000000000..1a63c73b6bb
--- /dev/null
+++ b/board/spacemit/k3/Kconfig
@@ -0,0 +1,30 @@ 
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Copyright (C) 2026 Yixun Lan <dlan@kernel.org>
+
+if TARGET_SPACEMIT_K3
+
+config SYS_BOARD
+	default "k3"
+
+config SYS_VENDOR
+	default "spacemit"
+
+config SYS_CPU
+	default "k3"
+
+config SYS_CONFIG_NAME
+	default "spacemit-k3"
+
+config TEXT_BASE
+	default 0x102000000
+
+config SPL_OPENSBI_LOAD_ADDR
+	hex
+	default 0x100000000
+
+config BOARD_SPECIFIC_OPTIONS
+	def_bool y
+	select SPACEMIT_K3
+
+endif
diff --git a/board/spacemit/k3/MAINTAINERS b/board/spacemit/k3/MAINTAINERS
new file mode 100644
index 00000000000..34cf1ed4453
--- /dev/null
+++ b/board/spacemit/k3/MAINTAINERS
@@ -0,0 +1,8 @@ 
+SPACEMIT K3
+M:	Yixun Lan <dlan@kernel.org>
+S:	Maintained
+F:	arch/riscv/cpu/k3/
+F:	board/spacemit/k3/
+F:	configs/spacemit_k3_defconfig
+F:	include/configs/k3.h
+F:	arch/riscv/dts/k3-u-boot.dtsi
diff --git a/include/configs/spacemit-k3.h b/include/configs/spacemit-k3.h
new file mode 100644
index 00000000000..9dd545e2a3b
--- /dev/null
+++ b/include/configs/spacemit-k3.h
@@ -0,0 +1,13 @@ 
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2026 Yixun Lan <dlan@kernel.org>
+ */
+
+#ifndef __SPACEMIT_K3_H
+#define __SPACEMIT_K3_H
+
+#define CFG_SYS_NS16550_IER	0x40
+
+#define RISCV_SMODE_TIMER_FREQ	24000000
+
+#endif /* __SPACEMIT_K3_H */