diff mbox series

[v2,09/11] riscv: Add K210 sysctl support

Message ID 9532cfb9-701c-d4f3-b976-b5c6f6002f8f@gmail.com
State Superseded
Delegated to: Andes
Headers show
Series riscv: Add Sipeed Maix support | expand

Commit Message

Sean Anderson Jan. 15, 2020, 11:20 p.m. UTC
This driver does nothing but load its children for the moment. Should it be
using regmap? I'm not sure how that fits into everything.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---
Changes for v2:
  Removed spurious references to mach-k210.
  Don't load pre-relocation.

 arch/riscv/Kconfig                   | 11 +++++++
 arch/riscv/include/asm/k210_sysctl.h | 43 ++++++++++++++++++++++++++++
 arch/riscv/lib/Makefile              |  1 +
 arch/riscv/lib/k210_sysctl.c         | 21 ++++++++++++++
 board/sipeed/maix/Kconfig            |  1 +
 5 files changed, 77 insertions(+)
 create mode 100644 arch/riscv/include/asm/k210_sysctl.h
 create mode 100644 arch/riscv/lib/k210_sysctl.c
diff mbox series

Patch

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 4c62b8dd77..677cdf5f24 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -196,6 +196,14 @@  config RISCV_RDTIME
 	  standard rdtime instruction. This is the case for S-mode U-Boot, and
 	  is useful for processors that support rdtime in M-mode too.
 
+config K210_SYSCTL
+	bool
+	select SYSCON
+	select SPL_SYSCON if SPL
+	help
+	  The K210 sysctl block holds memory-mapped control and status
+	  registers associated with clocks, resets, power, and dma handshakes.
+
 config SYS_MALLOC_F_LEN
 	default 0x1000
 
@@ -240,4 +248,7 @@  config STACK_SIZE_SHIFT
 config SPL_LDSCRIPT
 	default "arch/riscv/cpu/u-boot-spl.lds"
 
+config ARCH_K210
+	bool "Support Kendryte K210 SOCs"
+
 endmenu
diff --git a/arch/riscv/include/asm/k210_sysctl.h b/arch/riscv/include/asm/k210_sysctl.h
new file mode 100644
index 0000000000..94170f4f31
--- /dev/null
+++ b/arch/riscv/include/asm/k210_sysctl.h
@@ -0,0 +1,43 @@ 
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2019 Sean Anderson <seanga2@gmail.com>
+ */
+
+#ifndef K210_SYSCTL_H
+#define K210_SYSCTL_H
+
+#include <linux/compiler.h>
+
+/*
+ * sysctl registers
+ * Taken from kendryte-standalone-sdk/lib/drivers/include/sysctl.h
+ */
+struct k210_sysctl {
+	u32 git_id;
+	u32 clk_freq;
+	u32 pll0;
+	u32 pll1;
+	u32 pll2;
+	u32 resv5;
+	u32 pll_lock;
+	u32 rom_error;
+	u32 clk_sel[2];
+	u32 clk_en_cent;
+	u32 clk_en_peri;
+	u32 soft_reset;
+	u32 peri_reset;
+	u32 clk_thr[7];
+	u32 misc;
+	u32 peri;
+	u32 spi_sleep;
+	u32 reset_status;
+	u32 dma_sel0;
+	u32 dma_sel1;
+	u32 power_sel;
+	u32 resv28;
+	u32 resv29;
+	u32 resv30;
+	u32 resv31;
+} __packed;
+
+#endif /* K210_SYSCTL_H */
diff --git a/arch/riscv/lib/Makefile b/arch/riscv/lib/Makefile
index c9179a5ff8..4c31e824d9 100644
--- a/arch/riscv/lib/Makefile
+++ b/arch/riscv/lib/Makefile
@@ -14,6 +14,7 @@  ifeq ($(CONFIG_$(SPL_)RISCV_MMODE),y)
 obj-$(CONFIG_SIFIVE_CLINT) += sifive_clint.o
 obj-$(CONFIG_ANDES_PLIC) += andes_plic.o
 obj-$(CONFIG_ANDES_PLMT) += andes_plmt.o
+obj-$(CONFIG_K210_SYSCTL) += k210_sysctl.o
 else
 obj-$(CONFIG_RISCV_RDTIME) += rdtime.o
 obj-$(CONFIG_SBI_IPI) += sbi_ipi.o
diff --git a/arch/riscv/lib/k210_sysctl.c b/arch/riscv/lib/k210_sysctl.c
new file mode 100644
index 0000000000..db2e79c974
--- /dev/null
+++ b/arch/riscv/lib/k210_sysctl.c
@@ -0,0 +1,21 @@ 
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2019 Sean Anderson <seanga2@gmail.com>
+ */
+#include <asm/k210_sysctl.h>
+
+#include <dm.h>
+
+static const struct udevice_id k210_sysctl_ids[] = {
+	{ .compatible = "kendryte,k210-sysctl", },
+	{ }
+};
+
+U_BOOT_DRIVER(k210_sysctl) = {
+	.name = "k210_sysctl",
+	.id = UCLASS_SYSCON,
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
+	.bind = dm_scan_fdt_dev,
+#endif
+	.of_match = k210_sysctl_ids,
+};
diff --git a/board/sipeed/maix/Kconfig b/board/sipeed/maix/Kconfig
index efeaddf317..9ffd3aa7aa 100644
--- a/board/sipeed/maix/Kconfig
+++ b/board/sipeed/maix/Kconfig
@@ -36,6 +36,7 @@  config BOARD_SPECIFIC_OPTIONS
 	select ENV_IS_NOWHERE
 	select SYS_RISCV_NOCOUNTER
 	imply SIFIVE_CLINT
+	imply K210_SYSCTL
 	imply SPI
 	imply DM_GPIO
 	imply CMD_GPIO