From 64924f26ecff664c913a04fea5a2aed09463bc2a Mon Sep 17 00:00:00 2001 From: Hangfan Li Date: Wed, 4 Mar 2026 14:58:37 +0800 Subject: [PATCH] board: spacemit-k3: Add support for boot console and its pinctrl First usable state reached: SPL booted and console printed --- arch/riscv/cpu/k3/Kconfig | 4 + arch/riscv/dts/k3-pinctrl.dtsi | 46 +++++ arch/riscv/dts/k3-spacemit-deb1.dts | 7 + arch/riscv/dts/k3.dtsi | 36 ++++ include/configs/spacemit-k3-generic.h | 2 +- include/dt-bindings/pinctrl/k3-pinctrl.h | 229 +++++++++++++++++++++++ 6 files changed, 323 insertions(+), 1 deletion(-) create mode 100644 arch/riscv/dts/k3-pinctrl.dtsi create mode 100644 include/dt-bindings/pinctrl/k3-pinctrl.h diff --git a/arch/riscv/cpu/k3/Kconfig b/arch/riscv/cpu/k3/Kconfig index 7935be61c1b..4d44def13a6 100644 --- a/arch/riscv/cpu/k3/Kconfig +++ b/arch/riscv/cpu/k3/Kconfig @@ -19,6 +19,10 @@ config SPACEMIT_K3 imply FIT imply SPL_LOAD_FIT imply SPL_LOAD_FIT_FULL + imply PINCTRL + imply SPL_PINCTRL + imply PINCTRL_SINGLE + imply SYS_NS16550 if SPACEMIT_K3 diff --git a/arch/riscv/dts/k3-pinctrl.dtsi b/arch/riscv/dts/k3-pinctrl.dtsi new file mode 100644 index 00000000000..4d1652c64d2 --- /dev/null +++ b/arch/riscv/dts/k3-pinctrl.dtsi @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: (GPL-2.0 OR MIT) +/* Copyright (c) 2025 Spacemit, Inc */ + +#include + +&pinctrl { + pinctrl_uart0_0: uart0_0_grp { + bootph-all; + pinctrl-single,pins = < + K3_PADCONF(149, MUX_MODE2, (PULL_UP | PAD_DS8)) /* tx */ + K3_PADCONF(150, MUX_MODE2, (PULL_UP | PAD_DS8)) /* rx */ + >; + }; + + pinctrl_uart0_1: uart0_1_grp { + bootph-all; + pinctrl-single,pins = < + K3_PADCONF(132, MUX_MODE2, (PULL_UP | PAD_DS8)) /* tx */ + K3_PADCONF(133, MUX_MODE2, (PULL_UP | PAD_DS8)) /* rx */ + >; + }; + + pinctrl_uart0_2: uart0_2_grp { + bootph-all; + pinctrl-single,pins = < + K3_PADCONF(145, MUX_MODE5, (PULL_UP | PAD_DS8)) /* tx */ + K3_PADCONF(146, MUX_MODE5, (PULL_UP | PAD_DS8)) /* rx */ + >; + }; + + pinctrl_uart0_3: uart0_3_grp { + bootph-all; + pinctrl-single,pins = < + K3_PADCONF(42, MUX_MODE2, (PULL_UP | PAD_DS8)) /* tx */ + K3_PADCONF(43, MUX_MODE2, (PULL_UP | PAD_DS8)) /* rx */ + >; + }; + + pinctrl_uart0_4: uart0_4_grp { + bootph-all; + pinctrl-single,pins = < + K3_PADCONF(93, MUX_MODE3, (PULL_UP | PAD_DS8)) /* tx */ + K3_PADCONF(94, MUX_MODE3, (PULL_UP | PAD_DS8)) /* rx */ + >; + }; +}; diff --git a/arch/riscv/dts/k3-spacemit-deb1.dts b/arch/riscv/dts/k3-spacemit-deb1.dts index 0383d1b79e8..45e4df01061 100644 --- a/arch/riscv/dts/k3-spacemit-deb1.dts +++ b/arch/riscv/dts/k3-spacemit-deb1.dts @@ -4,6 +4,7 @@ */ #include "k3.dtsi" +#include "k3-pinctrl.dtsi" #include "binman.dtsi" / { @@ -19,3 +20,9 @@ reg = <0x00000000 0x00000000 0x00000000 0x80000000>; }; }; + +&serial0 { + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_uart0_0>; + status = "okay"; +}; diff --git a/arch/riscv/dts/k3.dtsi b/arch/riscv/dts/k3.dtsi index 4eb09a40c99..3609c530d6f 100644 --- a/arch/riscv/dts/k3.dtsi +++ b/arch/riscv/dts/k3.dtsi @@ -14,6 +14,42 @@ compatible = "spacemit,k3"; aliases { + serial0 = &serial0; + }; + + soc { + bootph-all; + #address-cells = <2>; + #size-cells = <2>; + compatible = "simple-bus"; + ranges; + + pinctrl: pinctrl@d401e000 { + bootph-all; + compatible = "pinctrl-single"; + reg = <0x0 0xd401e000 0x0 0x400>; + #address-cells = <1>; + #size-cells = <1>; + #pinctrl-cells = <1>; + #gpio-range-cells = <3>; + pinctrl-single,register-width = <32>; + pinctrl-single,function-mask = <0xffff>; + + range: gpio-range { + bootph-all; + #pinctrl-single,gpio-range-cells = <3>; + }; + }; + + serial0: serial@d4017000 { + bootph-all; + compatible = "intel,xscale-uart"; + reg = <0x00000000 0xD4017000 0x00000000 0x00000100>; + reg-shift = <2>; + reg-io-width = <4>; + clock-frequency = <14745600>; + status = "disabled"; + }; }; }; diff --git a/include/configs/spacemit-k3-generic.h b/include/configs/spacemit-k3-generic.h index a70e737a2c8..cdf3c1fdbae 100644 --- a/include/configs/spacemit-k3-generic.h +++ b/include/configs/spacemit-k3-generic.h @@ -6,6 +6,6 @@ #ifndef __CONFIG_H #define __CONFIG_H - +#define CFG_SYS_NS16550_IER 0x40 #endif /* __CONFIG_H */ diff --git a/include/dt-bindings/pinctrl/k3-pinctrl.h b/include/dt-bindings/pinctrl/k3-pinctrl.h new file mode 100644 index 00000000000..d477b56f6c2 --- /dev/null +++ b/include/dt-bindings/pinctrl/k3-pinctrl.h @@ -0,0 +1,229 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef __DT_BINDINGS_K3_PINCTRL_H +#define __DT_BINDINGS_K3_PINCTRL_H + +/* + * For K3: + * +---------+----------+-----------+--------+--------+----------+--------+ + * | pull | drive | schmitter | slew | edge | strong | mux | + * | up/down | strength | trigger | rate | detect | pull | mode | + * +---------+----------+-----------+--------+--------+----------+--------+ + * 3 bits 4 bits 1 bits 1 bit 3 bits 1 bit 3 bits + */ + +/* pinnum list */ +#define GPIO_00 (0) +#define GPIO_01 (1) +#define GPIO_02 (2) +#define GPIO_03 (3) +#define GPIO_04 (4) +#define GPIO_05 (5) +#define GPIO_06 (6) +#define GPIO_07 (7) +#define GPIO_08 (8) +#define GPIO_09 (9) +#define GPIO_10 (10) +#define GPIO_11 (11) +#define GPIO_12 (12) +#define GPIO_13 (13) +#define GPIO_14 (14) +#define GPIO_15 (15) +#define GPIO_16 (16) +#define GPIO_17 (17) +#define GPIO_18 (18) +#define GPIO_19 (19) +#define GPIO_20 (20) +#define GPIO_21 (21) +#define GPIO_22 (22) +#define GPIO_23 (23) +#define GPIO_24 (24) +#define GPIO_25 (25) +#define GPIO_26 (26) +#define GPIO_27 (27) +#define GPIO_28 (28) +#define GPIO_29 (29) +#define GPIO_30 (30) +#define GPIO_31 (31) +#define GPIO_32 (32) +#define GPIO_33 (33) +#define GPIO_34 (34) +#define GPIO_35 (35) +#define GPIO_36 (36) +#define GPIO_37 (37) +#define GPIO_38 (38) +#define GPIO_39 (39) +#define GPIO_40 (40) +#define GPIO_41 (41) +#define GPIO_42 (42) +#define GPIO_43 (43) +#define GPIO_44 (44) +#define GPIO_45 (45) +#define GPIO_46 (46) +#define GPIO_47 (47) +#define GPIO_48 (48) +#define GPIO_49 (49) +#define GPIO_50 (50) +#define GPIO_51 (51) +#define GPIO_52 (52) +#define GPIO_53 (53) +#define GPIO_54 (54) +#define GPIO_55 (55) +#define GPIO_56 (56) +#define GPIO_57 (57) +#define GPIO_58 (58) +#define GPIO_59 (59) +#define GPIO_60 (60) +#define GPIO_61 (61) +#define GPIO_62 (62) +#define GPIO_63 (63) +#define GPIO_64 (64) +#define GPIO_65 (65) +#define GPIO_66 (66) +#define GPIO_67 (67) +#define GPIO_68 (68) +#define GPIO_69 (69) +#define GPIO_70 (70) +#define GPIO_71 (71) +#define GPIO_72 (72) +#define GPIO_73 (73) +#define GPIO_74 (74) +#define GPIO_75 (75) +#define GPIO_76 (76) +#define GPIO_77 (77) +#define GPIO_78 (78) +#define GPIO_79 (79) +#define GPIO_80 (80) +#define GPIO_81 (81) +#define GPIO_82 (82) +#define GPIO_83 (83) +#define GPIO_84 (84) +#define GPIO_85 (85) +#define GPIO_86 (86) +#define GPIO_87 (87) +#define GPIO_88 (88) +#define GPIO_89 (89) +#define GPIO_90 (90) +#define GPIO_91 (91) +#define GPIO_92 (92) +#define GPIO_93 (93) +#define GPIO_94 (94) +#define GPIO_95 (95) +#define GPIO_96 (96) +#define GPIO_97 (97) +#define GPIO_98 (98) +#define GPIO_99 (99) +#define GPIO_100 (100) +#define GPIO_101 (101) +#define GPIO_102 (102) +#define GPIO_103 (103) +#define GPIO_104 (104) +#define GPIO_105 (105) +#define GPIO_106 (106) +#define GPIO_107 (107) +#define GPIO_108 (108) +#define GPIO_109 (109) +#define GPIO_110 (110) +#define GPIO_111 (111) +#define GPIO_112 (112) +#define GPIO_113 (113) +#define GPIO_114 (114) +#define GPIO_115 (115) +#define GPIO_116 (116) +#define GPIO_117 (117) +#define GPIO_118 (118) +#define GPIO_119 (119) +#define GPIO_120 (120) +#define GPIO_121 (121) +#define GPIO_122 (122) +#define GPIO_123 (123) +#define GPIO_124 (124) +#define GPIO_125 (125) +#define GPIO_126 (126) +#define GPIO_127 (127) +#define PWR_SCL (128) +#define PWR_SDA (129) +#define VCXO_EN (130) +#define PMIC_INT_N (131) +#define MMC1_DAT3 (132) +#define MMC1_DAT2 (133) +#define MMC1_DAT1 (134) +#define MMC1_DAT0 (135) +#define MMC1_CMD (136) +#define MMC1_CLK (137) +#define QSPI_DAT0 (138) +#define QSPI_DAT1 (139) +#define QSPI_DAT2 (140) +#define QSPI_DAT3 (141) +#define QSPI_CS0 (142) +#define QSPI_CS1 (143) +#define QSPI_CLK (144) +#define PRI_TDI (145) +#define PRI_TMS (146) +#define PRI_TCK (147) +#define PRI_TDO (148) +#define PWR_SSP_SCLK (149) +#define PWR_SSP_FRM (150) +#define PWR_SSP_TXD (151) +#define PWR_SSP_RXD (152) + +/* pin mux */ +#define PAD_MUX GENMASK(2, 0) +#define MUX_MODE0 0 +#define MUX_MODE1 1 +#define MUX_MODE2 2 +#define MUX_MODE3 3 +#define MUX_MODE4 4 +#define MUX_MODE5 5 +#define MUX_MODE6 6 +#define MUX_MODE7 7 + +#define PAD_STRONG_PULL BIT(3) + +#define PAD_EDGE GENMASK(6, 4) +#define PAD_EDGE_RISE BIT(4) +#define PAD_EDGE_FALL BIT(5) +#define PAD_EDGE_CLEAR BIT(6) + +#define PAD_SLEW_RATE_EN BIT(7) + +#define PAD_SCHMITT BIT(8) + +#define PAD_PULLDOWN BIT(13) +#define PAD_PULLUP BIT(14) +#define PAD_PULL_EN BIT(15) + +/* + * drive strength + * DRIVE[3:0] -> bits[12:9] +*/ +#define PAD_DRIVE GENMASK(12, 9) +#define PAD_DS0 (0 << 9) /* bit[12:9] 0000 */ +#define PAD_DS1 (1 << 9) /* bit[12:9] 0001 */ +#define PAD_DS2 (2 << 9) /* bit[12:9] 0010 */ +#define PAD_DS3 (3 << 9) /* bit[12:9] 0011 */ +#define PAD_DS4 (4 << 9) /* bit[12:9] 0100 */ +#define PAD_DS5 (5 << 9) /* bit[12:9] 0101 */ +#define PAD_DS6 (6 << 9) /* bit[12:9] 0110 */ +#define PAD_DS7 (7 << 9) /* bit[12:9] 0111 */ +#define PAD_DS8 (8 << 9) /* bit[12:9] 1000 */ +#define PAD_DS9 (9 << 9) /* bit[12:9] 1001 */ +#define PAD_DS10 (10 << 9) /* bit[12:9] 1010 */ +#define PAD_DS11 (11 << 9) /* bit[12:9] 1011 */ +#define PAD_DS12 (12 << 9) /* bit[12:9] 1100 */ +#define PAD_DS13 (13 << 9) /* bit[12:9] 1101 */ +#define PAD_DS14 (14 << 9) /* bit[12:9] 1110 */ +#define PAD_DS15 (15 << 9) /* bit[12:9] 1111 */ + +/* pull up/down */ +#define PULL_DIS (0 << 13) /* bit[15:13] 000 */ +#define PULL_UP (6 << 13) /* bit[15:13] 110 */ +#define PULL_DOWN (5 << 13) /* bit[15:13] 101 */ + +// pin reg offset +#define PIN_ID(x) ((x) > 130? (x) + 2: (x)) + +// pinctrl-single,pins +#define K3_PADCONF(pinid, mux, conf) ((PIN_ID(pinid)) << 2) ((conf) | (mux)) + +#endif /* __DT_BINDINGS_K3_PINCTRL_H */