Skip to contentSkip to conversation

riscv: Add Sipeed Maix support

PATCH Superseded Sean Anderson 2 participants 13 messages Dec 31, 2019 – Jan 2, 2020

Subsystems (7)

v1 of 14 Superseded Latest is v14 →

lore
Share & tools
lore
#0 lore raw

cover riscv: Add Sipeed Maix support

This patch series adds support for Sipeed Maix boards and the Kendryte K210 CPU. Currently, only the Maix Bit V2.0 is supported, however other models are similar. This series depends on
<https://patchwork.ozlabs.org/patch/1215326/> and
<https://patchwork.ozlabs.org/patch/1215327/>.
(log: Include missing header for log.h)
(clk: Include missing headers for linux/clk-provider.h)

To flash u-boot to a maix bit, run
kflash -tp /dev/<your tty here> -B bit_mic -S SLOW u-boot-dtb.bin

Boot output should look like the following:

U-Boot 2020.01-rc5+ (Dec 31 2019 - 16:05:31 -0500)

CPU:   rv64acdfim
DRAM:  8 MiB
MMC:
In:    serial at 38000000
Out:   serial at 38000000
Err:   serial at 38000000
Model: Sipeed Maix

=>

Sean Anderson (11):
clk: Always use the supplied struct clk
clk: Check that ops of composite clock components exist before calling
riscv: Add headers for asm/global_data.h
riscv: Add an option to default to RV64I
riscv: Enable SiFive UART support pre-relocation
riscv: Add initial Sipeed Maix support
riscv: Add device tree for K210
riscv: Add K210 sysctl support
riscv: Add K210 pll support
riscv: Add K210 clock support
riscv: Add option to disable writes to mcounteren

 arch/riscv/Kconfig                      |  16 +
 arch/riscv/cpu/cpu.c                    |   2 +
 arch/riscv/dts/Makefile                 |   1 +
 arch/riscv/dts/k210-maix-bit.dts        |  42 +++
 arch/riscv/dts/k210.dtsi                | 455 ++++++++++++++++++++++++
 arch/riscv/include/asm/global_data.h    |   2 +
 arch/riscv/include/asm/k210_sysctl.h    |  43 +++
 arch/riscv/lib/Makefile                 |   1 +
 arch/riscv/lib/k210_sysctl.c            |  22 ++
 board/sipeed/maix/Kconfig               |  49 +++
 board/sipeed/maix/MAINTAINERS           |  13 +
 board/sipeed/maix/Makefile              |   5 +
 board/sipeed/maix/maix.c                |   9 +
 configs/sipeed_maix_bitm_config         | 139 ++++++++
 drivers/clk/Kconfig                     |   1 +
 drivers/clk/Makefile                    |   1 +
 drivers/clk/clk-composite.c             |  65 ++--
 drivers/clk/clk-divider.c               |   6 +-
 drivers/clk/clk-fixed-factor.c          |   3 +-
 drivers/clk/clk-gate.c                  |   6 +-
 drivers/clk/clk-mux.c                   |  12 +-
 drivers/clk/imx/clk-gate2.c             |   4 +-
 drivers/clk/kendryte/Kconfig            |   7 +
 drivers/clk/kendryte/Makefile           |   1 +
 drivers/clk/kendryte/clk.c              | 391 ++++++++++++++++++++
 drivers/clk/kendryte/clk.h              |  27 ++
 drivers/clk/kendryte/pll.c              | 455 ++++++++++++++++++++++++
 drivers/clk/kendryte/pll.h              |  38 ++
 drivers/serial/serial_sifive.c          |   1 +
 include/configs/sipeed-maix.h           |  19 +
 include/dt-bindings/clock/k210-sysctl.h |  54 +++
 include/dt-bindings/reset/k210-sysctl.h |  39 ++
 32 files changed, 1887 insertions(+), 42 deletions(-)
 create mode 100644 arch/riscv/dts/k210-maix-bit.dts
 create mode 100644 arch/riscv/dts/k210.dtsi
 create mode 100644 arch/riscv/include/asm/k210_sysctl.h
 create mode 100644 arch/riscv/lib/k210_sysctl.c
 create mode 100644 board/sipeed/maix/Kconfig
 create mode 100644 board/sipeed/maix/MAINTAINERS
 create mode 100644 board/sipeed/maix/Makefile
 create mode 100644 board/sipeed/maix/maix.c
 create mode 100644 configs/sipeed_maix_bitm_config
 create mode 100644 drivers/clk/kendryte/Kconfig
 create mode 100644 drivers/clk/kendryte/Makefile
 create mode 100644 drivers/clk/kendryte/clk.c
 create mode 100644 drivers/clk/kendryte/clk.h
 create mode 100644 drivers/clk/kendryte/pll.c
 create mode 100644 drivers/clk/kendryte/pll.h
 create mode 100644 include/configs/sipeed-maix.h
 create mode 100644 include/dt-bindings/clock/k210-sysctl.h
 create mode 100644 include/dt-bindings/reset/k210-sysctl.h
Signature · 1 line
2.24.1
#1 lore raw

PATCH 1/11 clk: Always use the supplied struct clk

CCF clocks should always use the struct clock passed to their methods for extracting the driver-specific clock information struct. Previously, many functions would use the clk->dev->priv if the device was bound. This could cause problems with composite clocks. The individual clocks in a composite clock did not have the ->dev field filled in. This was fine, because the device-specific clock information would be used. However, since there was no ->dev, there was no way to get the parent clock. This caused the recalc_rate method of the CCF divider clock to fail. One option would be to use the clk->priv field to get the composite clock and from there get the appropriate parent device. However, this would tie the implementation to the composite clock. In general, different devices should not rely on the contents of ->priv from another device.

The simple solution to this problem is to just always use the supplied struct clock. The composite clock now fills in the ->dev pointer of its child clocks. This allows child clocks to make calls like clk_get_parent() without issue.

imx avoided the above problem by using a custom get_rate function with composite clocks.

---
This patch was previously submitted as
<https://patchwork.ozlabs.org/patch/1215335/>.

 drivers/clk/clk-composite.c    |  8 ++++++++
 drivers/clk/clk-divider.c      |  6 ++----
 drivers/clk/clk-fixed-factor.c |  3 +--
 drivers/clk/clk-gate.c         |  6 ++----
 drivers/clk/clk-mux.c          | 12 ++++--------
 drivers/clk/imx/clk-gate2.c    |  4 ++--
 6 files changed, 19 insertions(+), 20 deletions(-)
drivers/clk/clk-composite.c +8 -0
index a5626c33d1..d0f273d47f 100644
@@ -145,6 +145,14 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
 		goto err;
 	}
 
+	if (composite->mux)
+		composite->mux->dev = clk->dev;
+	if (composite->rate)
+		composite->rate->dev = clk->dev;
+	if (composite->gate)
+		composite->gate->dev = clk->dev;
+
+
 	return clk;
 
 err:
drivers/clk/clk-divider.c +2 -4
index 822e09b084..bfa05f24a3 100644
@@ -70,8 +70,7 @@ unsigned long divider_recalc_rate(struct clk *hw, unsigned long parent_rate,
 
 static ulong clk_divider_recalc_rate(struct clk *clk)
 {
-	struct clk_divider *divider = to_clk_divider(clk_dev_binded(clk) ?
-			dev_get_clk_ptr(clk->dev) : clk);
+	struct clk_divider *divider = to_clk_divider(clk);
 	unsigned long parent_rate = clk_get_parent_rate(clk);
 	unsigned int val;
 
@@ -150,8 +149,7 @@ int divider_get_val(unsigned long rate, unsigned long parent_rate,
 
 static ulong clk_divider_set_rate(struct clk *clk, unsigned long rate)
 {
-	struct clk_divider *divider = to_clk_divider(clk_dev_binded(clk) ?
-			dev_get_clk_ptr(clk->dev) : clk);
+	struct clk_divider *divider = to_clk_divider(clk);
 	unsigned long parent_rate = clk_get_parent_rate(clk);
 	int value;
 	u32 val;
drivers/clk/clk-fixed-factor.c +1 -2
index 711b0588bc..d2401cf440 100644
@@ -18,8 +18,7 @@
 
 static ulong clk_factor_recalc_rate(struct clk *clk)
 {
-	struct clk_fixed_factor *fix =
-		to_clk_fixed_factor(dev_get_clk_ptr(clk->dev));
+	struct clk_fixed_factor *fix = to_clk_fixed_factor(clk);
 	unsigned long parent_rate = clk_get_parent_rate(clk);
 	unsigned long long int rate;
 
drivers/clk/clk-gate.c +2 -4
index 70b8794554..b2933bc24a 100644
@@ -43,8 +43,7 @@
  */
 static void clk_gate_endisable(struct clk *clk, int enable)
 {
-	struct clk_gate *gate = to_clk_gate(clk_dev_binded(clk) ?
-			dev_get_clk_ptr(clk->dev) : clk);
+	struct clk_gate *gate = to_clk_gate(clk);
 	int set = gate->flags & CLK_GATE_SET_TO_DISABLE ? 1 : 0;
 	u32 reg;
 
@@ -86,8 +85,7 @@ static int clk_gate_disable(struct clk *clk)
 
 int clk_gate_is_enabled(struct clk *clk)
 {
-	struct clk_gate *gate = to_clk_gate(clk_dev_binded(clk) ?
-			dev_get_clk_ptr(clk->dev) : clk);
+	struct clk_gate *gate = to_clk_gate(clk);
 	u32 reg;
 
 #if CONFIG_IS_ENABLED(SANDBOX_CLK_CCF)
drivers/clk/clk-mux.c +4 -8
index 5acc0b8cbd..67b4afef28 100644
@@ -35,8 +35,7 @@
 int clk_mux_val_to_index(struct clk *clk, u32 *table, unsigned int flags,
 			 unsigned int val)
 {
-	struct clk_mux *mux = to_clk_mux(clk_dev_binded(clk) ?
-			dev_get_clk_ptr(clk->dev) : clk);
+	struct clk_mux *mux = to_clk_mux(clk);
 	int num_parents = mux->num_parents;
 
 	if (table) {
@@ -79,8 +78,7 @@ unsigned int clk_mux_index_to_val(u32 *table, unsigned int flags, u8 index)
 
 u8 clk_mux_get_parent(struct clk *clk)
 {
-	struct clk_mux *mux = to_clk_mux(clk_dev_binded(clk) ?
-			dev_get_clk_ptr(clk->dev) : clk);
+	struct clk_mux *mux = to_clk_mux(clk);
 	u32 val;
 
 #if CONFIG_IS_ENABLED(SANDBOX_CLK_CCF)
@@ -97,8 +95,7 @@ u8 clk_mux_get_parent(struct clk *clk)
 static int clk_fetch_parent_index(struct clk *clk,
 				  struct clk *parent)
 {
-	struct clk_mux *mux = to_clk_mux(clk_dev_binded(clk) ?
-			dev_get_clk_ptr(clk->dev) : clk);
+	struct clk_mux *mux = to_clk_mux(clk);
 
 	int i;
 
@@ -115,8 +112,7 @@ static int clk_fetch_parent_index(struct clk *clk,
 
 static int clk_mux_set_parent(struct clk *clk, struct clk *parent)
 {
-	struct clk_mux *mux = to_clk_mux(clk_dev_binded(clk) ?
-			dev_get_clk_ptr(clk->dev) : clk);
+	struct clk_mux *mux = to_clk_mux(clk);
 	int index;
 	u32 val;
 	u32 reg;
drivers/clk/imx/clk-gate2.c +2 -2
index 1b9db6e791..e32c0cb53e 100644
@@ -37,7 +37,7 @@ struct clk_gate2 {
 
 static int clk_gate2_enable(struct clk *clk)
 {
-	struct clk_gate2 *gate = to_clk_gate2(dev_get_clk_ptr(clk->dev));
+	struct clk_gate2 *gate = to_clk_gate2(clk);
 	u32 reg;
 
 	reg = readl(gate->reg);
@@ -50,7 +50,7 @@ static int clk_gate2_enable(struct clk *clk)
 
 static int clk_gate2_disable(struct clk *clk)
 {
-	struct clk_gate2 *gate = to_clk_gate2(dev_get_clk_ptr(clk->dev));
+	struct clk_gate2 *gate = to_clk_gate2(clk);
 	u32 reg;
 
 	reg = readl(gate->reg);
Signature · 1 line
2.24.1
#2 lore raw

PATCH 1/11 clk: Always use the supplied struct clk

+ Lukasz

Quoted 17 lines · Sean Anderson

CCF clocks should always use the struct clock passed to their methods for extracting the driver-specific clock information struct. Previously, many functions would use the clk->dev->priv if the device was bound. This could cause problems with composite clocks. The individual clocks in a composite clock did not have the ->dev field filled in. This was fine, because the device-specific clock information would be used. However, since there was no ->dev, there was no way to get the parent clock. This caused the recalc_rate method of the CCF divider clock to fail. One option would be to use the clk->priv field to get the composite clock and from there get the appropriate parent device. However, this would tie the implementation to the composite clock. In general, different devices should not rely on the contents of ->priv from another device.

The simple solution to this problem is to just always use the supplied struct clock. The composite clock now fills in the ->dev pointer of its child clocks. This allows child clocks to make calls like clk_get_parent() without issue.

Quoted 5 lines

imx avoided the above problem by using a custom get_rate function with composite clocks.

---

#3 lore raw

PATCH 2/11 clk: Check that ops of composite clock components exist, before calling

In reply to Sean Anderson

clk_composite_ops was shared between all devices in the composite clock driver. If one clock had a feature (such as supporting set_parent) which another clock did not, it could call a null pointer dereference.

This patch does three things
1. It adds null-pointer checks to all composite clock functions.
2. It makes clk_composite_ops const and sets its functions at compile-time.
3. It adds some basic sanity checks to num_parents.

The combined effect of these changes is that any of mux, rate, or gate can be NULL, and composite clocks will still function normally. Previously, at least mux had to exist, since clk_composite_get_parent was used to determine the parent for clk_register.

---
This patch was previously submitted as
<https://patchwork.ozlabs.org/patch/1215337/>.

 drivers/clk/clk-composite.c | 57 +++++++++++++++++++++++--------------
 1 file changed, 35 insertions(+), 22 deletions(-)
drivers/clk/clk-composite.c +35 -22
index d0f273d47f..ea9982fd57 100644
@@ -22,7 +22,10 @@ static u8 clk_composite_get_parent(struct clk *clk)
 		(struct clk *)dev_get_clk_ptr(clk->dev) : clk);
 	struct clk *mux = composite->mux;
 
-	return clk_mux_get_parent(mux);
+	if (mux)
+		return clk_mux_get_parent(mux);
+	else
+		return 0;
 }
 
 static int clk_composite_set_parent(struct clk *clk, struct clk *parent)
@@ -32,7 +35,10 @@ static int clk_composite_set_parent(struct clk *clk, struct clk *parent)
 	const struct clk_ops *mux_ops = composite->mux_ops;
 	struct clk *mux = composite->mux;
 
-	return mux_ops->set_parent(mux, parent);
+	if (mux && mux_ops)
+		return mux_ops->set_parent(mux, parent);
+	else
+		return -ENOTSUPP;
 }
 
 static unsigned long clk_composite_recalc_rate(struct clk *clk)
@@ -42,7 +48,10 @@ static unsigned long clk_composite_recalc_rate(struct clk *clk)
 	const struct clk_ops *rate_ops = composite->rate_ops;
 	struct clk *rate = composite->rate;
 
-	return rate_ops->get_rate(rate);
+	if (rate && rate_ops)
+		return rate_ops->get_rate(rate);
+	else
+		return clk_get_parent_rate(clk);
 }
 
 static ulong clk_composite_set_rate(struct clk *clk, unsigned long rate)
@@ -52,7 +61,10 @@ static ulong clk_composite_set_rate(struct clk *clk, unsigned long rate)
 	const struct clk_ops *rate_ops = composite->rate_ops;
 	struct clk *clk_rate = composite->rate;
 
-	return rate_ops->set_rate(clk_rate, rate);
+	if (rate && rate_ops)
+		return rate_ops->set_rate(clk_rate, rate);
+	else
+		return -ENOTSUPP;
 }
 
 static int clk_composite_enable(struct clk *clk)
@@ -62,7 +74,10 @@ static int clk_composite_enable(struct clk *clk)
 	const struct clk_ops *gate_ops = composite->gate_ops;
 	struct clk *gate = composite->gate;
 
-	return gate_ops->enable(gate);
+	if (gate && gate_ops)
+		return gate_ops->enable(gate);
+	else
+		return -ENOTSUPP;
 }
 
 static int clk_composite_disable(struct clk *clk)
@@ -72,15 +87,12 @@ static int clk_composite_disable(struct clk *clk)
 	const struct clk_ops *gate_ops = composite->gate_ops;
 	struct clk *gate = composite->gate;
 
-	gate_ops->disable(gate);
-
-	return 0;
+	if (gate && gate_ops)
+		return gate_ops->disable(gate);
+	else
+		return -ENOTSUPP;
 }
 
-struct clk_ops clk_composite_ops = {
-	/* This will be set according to clk_register_composite */
-};
-
 struct clk *clk_register_composite(struct device *dev, const char *name,
 				   const char * const *parent_names,
 				   int num_parents, struct clk *mux,
@@ -94,7 +106,9 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
 	struct clk *clk;
 	struct clk_composite *composite;
 	int ret;
-	struct clk_ops *composite_ops = &clk_composite_ops;
+
+	if (!num_parents || (num_parents != 1 && !mux))
+		return ERR_PTR(-EINVAL);
 
 	composite = kzalloc(sizeof(*composite), GFP_KERNEL);
 	if (!composite)
@@ -103,8 +117,6 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
 	if (mux && mux_ops) {
 		composite->mux = mux;
 		composite->mux_ops = mux_ops;
-		if (mux_ops->set_parent)
-			composite_ops->set_parent = clk_composite_set_parent;
 		mux->data = (ulong)composite;
 	}
 
@@ -113,11 +125,6 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
 			clk = ERR_PTR(-EINVAL);
 			goto err;
 		}
-		composite_ops->get_rate = clk_composite_recalc_rate;
-
-		/* .set_rate requires either .round_rate or .determine_rate */
-		if (rate_ops->set_rate)
-			composite_ops->set_rate = clk_composite_set_rate;
 
 		composite->rate = rate;
 		composite->rate_ops = rate_ops;
@@ -132,8 +139,6 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
 
 		composite->gate = gate;
 		composite->gate_ops = gate_ops;
-		composite_ops->enable = clk_composite_enable;
-		composite_ops->disable = clk_composite_disable;
 		gate->data = (ulong)composite;
 	}
 
@@ -160,6 +165,14 @@ err:
 	return clk;
 }
 
+static const struct clk_ops clk_composite_ops = {
+	.set_parent = clk_composite_set_parent,
+	.get_rate = clk_composite_recalc_rate,
+	.set_rate = clk_composite_set_rate,
+	.enable = clk_composite_enable,
+	.disable = clk_composite_disable,
+};
+
 U_BOOT_DRIVER(clk_composite) = {
 	.name	= UBOOT_DM_CLK_COMPOSITE,
 	.id	= UCLASS_CLK,
Signature · 1 line
2.24.1
#4 lore raw

PATCH 3/11 riscv: Add headers for asm/global_data.h

In reply to Sean Anderson

This header depended on bd_t and ulong, but did not include the appropriate headers.

---
 arch/riscv/include/asm/global_data.h | 2 ++
 1 file changed, 2 insertions(+)
arch/riscv/include/asm/global_data.h +2 -0
index b74bd7e738..4f0c12b402 100644
@@ -11,6 +11,8 @@
 #define __ASM_GBL_DATA_H
 
 #include <asm/smp.h>
+#include <asm/u-boot.h>
+#include <linux/compiler.h>
 
 /* Architecture-specific global data */
 struct arch_global_data {
Signature · 1 line
2.24.1
#5 lore raw

PATCH 4/11 riscv: Add an option to default to RV64I

In reply to Sean Anderson

This allows 64-bit boards to default to the 64-bit instruction set without changing the current default of 32-bit.

---
 arch/riscv/Kconfig | 4 ++++
 1 file changed, 4 insertions(+)
arch/riscv/Kconfig +4 -0
index 85e15ebffa..9a7b0334c2 100644
@@ -60,8 +60,12 @@ source "arch/riscv/cpu/generic/Kconfig"
 
 # architecture-specific options below
 
+config ARCH_DEFAULT_RV64I
+	bool
+
 choice
 	prompt "Base ISA"
+	default ARCH_RV64I if ARCH_DEFAULT_RV64I
 	default ARCH_RV32I
 
 config ARCH_RV32I
Signature · 1 line
2.24.1
#6 lore raw

PATCH 5/11 riscv: Enable SiFive UART support pre-relocation

In reply to Sean Anderson

Many other serial drivers are enabled pre-relocation to allow printing of console messages before relocating. This should also be enabled for the SiFive serial driver.

---
 drivers/serial/serial_sifive.c | 1 +
 1 file changed, 1 insertion(+)
drivers/serial/serial_sifive.c +1 -0
index c142ccdf3d..e103d2520e 100644
@@ -203,6 +203,7 @@ U_BOOT_DRIVER(serial_sifive) = {
 	.platdata_auto_alloc_size = sizeof(struct sifive_uart_platdata),
 	.probe = sifive_serial_probe,
 	.ops	= &sifive_serial_ops,
+	.flags = DM_FLAG_PRE_RELOC,
 };
 
 #ifdef CONFIG_DEBUG_UART_SIFIVE
Signature · 1 line
2.24.1
#7 lore raw

PATCH 6/11 riscv: Add initial Sipeed Maix support

In reply to Sean Anderson

The Sipeed Maix series is a collection of boards built around the RISC-V Kendryte K210 processor. This processor contains several peripherals to accelerate neural network processing and other "ai" tasks. This includes a "KPU" neural network processor, an audio processor supporting beamforming reception, and a digital video port supporting capture and output at VGA resolution. Other peripherals include 8M of sram (accessible with and without caching); remappable pins, including 40 GPIOs; AES, FFT, and SHA256 accelerators; a DMA controller; and I2C, I2S, and SPI controllers. Maix peripherals vary, but include spi flash; on-board usb-serial bridges; ports for cameras, displays, and sd cards; and ESP32 chips. Currently, only the Sipeed Maix Bit V2.0 (bitm) is supported, but the boards are fairly similar.

Documentation for Maix boards is located at <http://dl.sipeed.com/MAIX/HDK/>.
Documentation for the Kendryte K210 is located at
<https://kendryte.com/downloads/>. However, hardware details are rather lacking, so most technical reference has been taken from the standalone sdk located at
<https://github.com/kendryte/kendryte-standalone-sdk>.

---
 arch/riscv/Kconfig              |   4 +
 board/sipeed/maix/Kconfig       |  40 ++++++++++
 board/sipeed/maix/MAINTAINERS   |   6 ++
 board/sipeed/maix/Makefile      |   5 ++
 board/sipeed/maix/maix.c        |   9 +++
 configs/sipeed_maix_bitm_config | 136 ++++++++++++++++++++++++++++++++
 include/configs/sipeed-maix.h   |  19 +++++
 7 files changed, 219 insertions(+)
 create mode 100644 board/sipeed/maix/Kconfig
 create mode 100644 board/sipeed/maix/MAINTAINERS
 create mode 100644 board/sipeed/maix/Makefile
 create mode 100644 board/sipeed/maix/maix.c
 create mode 100644 configs/sipeed_maix_bitm_config
 create mode 100644 include/configs/sipeed-maix.h
arch/riscv/Kconfig +4 -0
index 9a7b0334c2..62c9616220 100644
@@ -20,6 +20,9 @@ config TARGET_QEMU_VIRT
 config TARGET_SIFIVE_FU540
 	bool "Support SiFive FU540 Board"
 
+config TARGET_SIPEED_MAIX
+	bool "Support Sipeed Maix Board"
+
 endchoice
 
 config SYS_ICACHE_OFF
@@ -53,6 +56,7 @@ source "board/AndesTech/ax25-ae350/Kconfig"
 source "board/emulation/qemu-riscv/Kconfig"
 source "board/microchip/mpfs_icicle/Kconfig"
 source "board/sifive/fu540/Kconfig"
+source "board/sipeed/maix/Kconfig"
 
 # platform-specific options below
 source "arch/riscv/cpu/ax25/Kconfig"
board/sipeed/maix/Kconfig new file +40 -0
new file mode 100644
index 0000000000..e64517a5cc
@@ -0,0 +1,40 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2019 Sean Anderson <[email protected]>
+
+if TARGET_SIPEED_MAIX
+
+config SYS_BOARD
+	default "maix"
+
+config SYS_VENDOR
+	default "sipeed"
+
+config SYS_CPU
+	default "generic"
+
+config SYS_CONFIG_NAME
+	default "sipeed-maix"
+
+config SYS_TEXT_BASE
+	default 0x80000000
+
+config NR_CPUS
+	default 2
+
+config NR_DRAM_BANKS
+	default 2
+
+config BOARD_SPECIFIC_OPTIONS
+	def_bool y
+	select GENERIC_RISCV
+	select DM_SERIAL
+	select SIFIVE_SERIAL
+	select ARCH_DEFAULT_RV64I
+	select ENV_IS_NOWHERE
+	imply SIFIVE_CLINT
+	imply SPI
+	imply DM_GPIO
+	imply CMD_GPIO
+	imply SYS_NS16550
+	imply SYS_MALLOC_F
+endif
board/sipeed/maix/MAINTAINERS new file +6 -0
new file mode 100644
index 0000000000..3632cd1c4c
@@ -0,0 +1,6 @@
+Sipeed Maix BOARD
+M:	Sean Anderson <[email protected]>
+S:	Maintained
+F:	board/sipeed/maix/
+F:	include/configs/sipeed-maix.h
+F:	configs/sipeed_maix_defconfig
board/sipeed/maix/Makefile new file +5 -0
new file mode 100644
index 0000000000..4acff5b31e
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (c) 2019 Western Digital Corporation or its affiliates.
+
+obj-y += maix.o
board/sipeed/maix/maix.c new file +9 -0
new file mode 100644
index 0000000000..f8e773acf7
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2019 Sean Anderson <[email protected]>
+ */
+
+int board_init(void)
+{
+	return 0;
+}
configs/sipeed_maix_bitm_config new file +136 -0

136 lines not on this page · raw message

include/configs/sipeed-maix.h new file +19 -0
new file mode 100644
index 0000000000..598f7dfdd0
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2019 Sean Anderson <[email protected]>
+ */
+
+#ifndef CONFIGS_SIPEED_MAIX_H
+#define CONFIGS_SIPEED_MAIX_H
+
+#include <linux/sizes.h>
+
+#define CONFIG_SYS_LOAD_ADDR 0x80000000
+#define CONFIG_SYS_SDRAM_BASE CONFIG_SYS_LOAD_ADDR
+#define CONFIG_SYS_SDRAM_SIZE SZ_8M
+/* Start just below AI memory */
+#define CONFIG_SYS_INIT_SP_ADDR 0x805FFFFF
+#define CONFIG_SYS_MALLOC_LEN SZ_8K
+#define CONFIG_SYS_CACHELINE_SIZE 64
+
+#endif /* CONFIGS_SIPEED_MAIX_H */
Signature · 1 line
2.24.1
#8 lore raw

PATCH 7/11 riscv: Add device tree for K210

In reply to Sean Anderson

There is a mirror of ram located at 0x4000000 which is un-cached. This is probably useful for DMA, but I am unsure of how to describe it in this device tree.

The cache-line size is undocumented. Emphirical tests suggest that it is 32 bytes, but I've used 64-bytes to be on the safe side.

Where possible, I have tried to find compatible drivers based on the layout of registers. However, I have not tested most of this functionality, and anything aside from clint0, uarths0, and sysctl should be considered descriptive at best. I would appreciate if anyone could help identify possibly compatible devices, especially for the timers, watchdogs, and rtc.

The documentation for pinconf devices indicates that #pinctrl-cells is a required property, but I am unsure what to put for it. Should that be filled in by a board-specific device tree?

The sysctl device has multiple different unrelated registers. For the moment, I have split off sub-devices for each functionality. In addition to clock and reset control, it also contains DMA handshake registers, and power registers. I have not described those at the moment, and I would appreciate suggestions on how to best describe them.

I'm not sure what the value of spi-max-frequency should be for external sd-card slots. Suggestions are appreciated.

---
 arch/riscv/dts/Makefile                 |   1 +
 arch/riscv/dts/k210-maix-bit.dts        |  42 +++
 arch/riscv/dts/k210.dtsi                | 442 ++++++++++++++++++++++++
 board/sipeed/maix/Kconfig               |   3 +
 configs/sipeed_maix_bitm_config         |   1 +
 include/dt-bindings/clock/k210-sysctl.h |  54 +++
 include/dt-bindings/reset/k210-sysctl.h |  39 +++
 7 files changed, 582 insertions(+)
 create mode 100644 arch/riscv/dts/k210-maix-bit.dts
 create mode 100644 arch/riscv/dts/k210.dtsi
 create mode 100644 include/dt-bindings/clock/k210-sysctl.h
 create mode 100644 include/dt-bindings/reset/k210-sysctl.h
arch/riscv/dts/Makefile +1 -0
index 4f30e6936f..3a6f96c67d 100644
@@ -2,6 +2,7 @@
 
 dtb-$(CONFIG_TARGET_AX25_AE350) += ae350_32.dtb ae350_64.dtb
 dtb-$(CONFIG_TARGET_SIFIVE_FU540) += hifive-unleashed-a00.dtb
+dtb-$(CONFIG_TARGET_SIPEED_MAIX) += k210-maix-bit.dtb
 
 targets += $(dtb-y)
 
arch/riscv/dts/k210-maix-bit.dts new file +42 -0

42 lines not on this page · raw message

arch/riscv/dts/k210.dtsi new file +442 -0

442 lines not on this page · raw message

board/sipeed/maix/Kconfig +3 -0
index e64517a5cc..ec9acd61ca 100644
@@ -18,6 +18,9 @@ config SYS_CONFIG_NAME
 config SYS_TEXT_BASE
 	default 0x80000000
 
+config DEFAULT_DEVICE_TREE
+	default "k210-maix-bit"
+
 config NR_CPUS
 	default 2
 
configs/sipeed_maix_bitm_config +1 -0
index 97a246e307..70bb566cb1 100644
@@ -18,6 +18,7 @@ CONFIG_BOOTSTAGE_STASH_ADDR=0
 CONFIG_IDENT_STRING=""
 CONFIG_64BIT=y
 CONFIG_TARGET_SIPEED_MAIX=y
+CONFIG_DEFAULT_DEVICE_TREE="k210-maix-bit"
 CONFIG_NR_CPUS=2
 CONFIG_GENERIC_RISCV=y
 CONFIG_ARCH_DEFAULT_RV64I=y
include/dt-bindings/clock/k210-sysctl.h new file +54 -0

54 lines not on this page · raw message

include/dt-bindings/reset/k210-sysctl.h new file +39 -0
new file mode 100644
index 0000000000..01605224f9
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2019 Sean Anderson <[email protected]>
+ */
+
+#ifndef RESET_K210_SYSCTL_H
+#define RESET_K210_SYSCTL_H
+
+#define K210_RST_SOC 0
+#define K210_RST_ROM 1
+#define K210_RST_DMA 2
+#define K210_RST_AI 3
+#define K210_RST_DVP 4
+#define K210_RST_FFT 5
+#define K210_RST_GPIO 6
+#define K210_RST_SPI0 7
+#define K210_RST_SPI1 8
+#define K210_RST_SPI2 9
+#define K210_RST_SPI3 10
+#define K210_RST_I2S0 11
+#define K210_RST_I2S1 12
+#define K210_RST_I2S2 13
+#define K210_RST_I2C0 14
+#define K210_RST_I2C1 15
+#define K210_RST_I2C2 16
+#define K210_RST_UART1 17
+#define K210_RST_UART2 18
+#define K210_RST_UART3 19
+#define K210_RST_AES 20
+#define K210_RST_FPIOA 21
+#define K210_RST_TIMER0 22
+#define K210_RST_TIMER1 23
+#define K210_RST_TIMER2 24
+#define K210_RST_WDT0 25
+#define K210_RST_WDT1 26
+#define K210_RST_SHA 27
+#define K210_RST_RTC 28
+
+#endif /* RESET_K210_SYSCTL_H */
Signature · 1 line
2.24.1
#9 lore raw

PATCH 8/11 riscv: Add K210 sysctl support

In reply to Sean Anderson

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.

---
 arch/riscv/Kconfig                   | 11 +++++++
 arch/riscv/Makefile                  |  6 ++++
 arch/riscv/include/asm/k210_sysctl.h | 43 ++++++++++++++++++++++++++++
 arch/riscv/lib/Makefile              |  1 +
 arch/riscv/lib/k210_sysctl.c         | 22 ++++++++++++++
 arch/riscv/mach-k210/Makefile        |  1 +
 board/sipeed/maix/Kconfig            |  2 ++
 configs/sipeed_maix_bitm_config      |  1 +
 8 files changed, 87 insertions(+)
 create mode 100644 arch/riscv/include/asm/k210_sysctl.h
 create mode 100644 arch/riscv/lib/k210_sysctl.c
 create mode 100644 arch/riscv/mach-k210/Makefile
arch/riscv/Kconfig +11 -0
index 62c9616220..13518b0440 100644
@@ -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
 
@@ -237,4 +245,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
arch/riscv/Makefile +6 -0
index 0b80eb8d86..390178e149 100644
@@ -30,6 +30,12 @@ ARCH_FLAGS = -march=$(ARCH_BASE)$(ARCH_A)$(ARCH_C) -mabi=$(ABI) \
 PLATFORM_CPPFLAGS	+= $(ARCH_FLAGS)
 CFLAGS_EFI		+= $(ARCH_FLAGS)
 
+machine-$(CONFIG_ARCH_K210) += k210
+
+machdirs := $(patsubst %,arch/riscv/mach-%/,$(machine-y))
+PLATFORM_CPPFLAGS += $(patsubst %,-I$(srctree)/%include,$(machdirs))
+libs-y += $(machdirs)
+
 head-y := arch/riscv/cpu/start.o
 
 libs-y += arch/riscv/cpu/
arch/riscv/include/asm/k210_sysctl.h new file +43 -0

43 lines not on this page · raw message

arch/riscv/lib/Makefile +1 -0
index c9179a5ff8..4c31e824d9 100644
@@ -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
arch/riscv/lib/k210_sysctl.c new file +22 -0
new file mode 100644
index 0000000000..f0b66aa36a
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2019 Sean Anderson <[email protected]>
+ */
+#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,
+	.flags = DM_FLAG_PRE_RELOC,
+};
arch/riscv/mach-k210/Makefile new file +1 -0
new file mode 100644
index 0000000000..6defe5ccb2
@@ -0,0 +1 @@
+obj-y := sysctl.o
board/sipeed/maix/Kconfig +2 -0
index ec9acd61ca..257135b2cb 100644
@@ -34,7 +34,9 @@ config BOARD_SPECIFIC_OPTIONS
 	select SIFIVE_SERIAL
 	select ARCH_DEFAULT_RV64I
 	select ENV_IS_NOWHERE
+	select ARCH_K210
 	imply SIFIVE_CLINT
+	imply K210_SYSCTL
 	imply SPI
 	imply DM_GPIO
 	imply CMD_GPIO
configs/sipeed_maix_bitm_config +1 -0
index 70bb566cb1..bb2d2e7932 100644
@@ -28,6 +28,7 @@ CONFIG_RISCV_MMODE=y
 CONFIG_RISCV_ISA_C=y
 CONFIG_RISCV_ISA_A=y
 CONFIG_SIFIVE_CLINT=y
+CONFIG_K210_SYSCTL=y
 CONFIG_SHOW_REGS=y
 CONFIG_STACK_SIZE_SHIFT=14
 CONFIG_ARCH_K210=y
Signature · 1 line
2.24.1
#10 lore raw

PATCH 9/11 riscv: Add K210 pll support

In reply to Sean Anderson

This pll code is primarily based on the code from the kendryte standalone sdk in lib/drivers/sysctl.c. k210_pll_calc_params is roughly analogous to the algorithm used to set the pll frequency, but it has been completely rewritten to be fixed-point based.

---
 arch/riscv/mach-k210/Makefile   |   1 -
 board/sipeed/maix/Kconfig       |   1 +
 configs/sipeed_maix_bitm_config |   1 +
 drivers/clk/Kconfig             |   1 +
 drivers/clk/Makefile            |   1 +
 drivers/clk/kendryte/Kconfig    |   7 +
 drivers/clk/kendryte/Makefile   |   1 +
 drivers/clk/kendryte/pll.c      | 455 ++++++++++++++++++++++++++++++++
 drivers/clk/kendryte/pll.h      |  38 +++
 9 files changed, 505 insertions(+), 1 deletion(-)
 delete mode 100644 arch/riscv/mach-k210/Makefile
 create mode 100644 drivers/clk/kendryte/Kconfig
 create mode 100644 drivers/clk/kendryte/Makefile
 create mode 100644 drivers/clk/kendryte/pll.c
 create mode 100644 drivers/clk/kendryte/pll.h
arch/riscv/mach-k210/Makefile deleted +0 -1
deleted file mode 100644
index 6defe5ccb2..0000000000
@@ -1 +0,0 @@
-obj-y := sysctl.o
board/sipeed/maix/Kconfig +1 -0
index 257135b2cb..838f2fb263 100644
@@ -37,6 +37,7 @@ config BOARD_SPECIFIC_OPTIONS
 	select ARCH_K210
 	imply SIFIVE_CLINT
 	imply K210_SYSCTL
+	imply CLK_K210
 	imply SPI
 	imply DM_GPIO
 	imply CMD_GPIO
configs/sipeed_maix_bitm_config +1 -0
index bb2d2e7932..f20145feac 100644
@@ -95,6 +95,7 @@ CONFIG_BLOCK_CACHE=y
 CONFIG_CLK=y
 CONFIG_CLK_CCF=y
 CONFIG_CLK_COMPOSITE_CCF=y
+CONFIG_CLK_K210=y
 CONFIG_CPU=y
 CONFIG_CPU_RISCV=y
 CONFIG_MMC=y
drivers/clk/Kconfig +1 -0
index 16d4237f89..af75c7c4cf 100644
@@ -145,6 +145,7 @@ source "drivers/clk/analogbits/Kconfig"
 source "drivers/clk/at91/Kconfig"
 source "drivers/clk/exynos/Kconfig"
 source "drivers/clk/imx/Kconfig"
+source "drivers/clk/kendryte/Kconfig"
 source "drivers/clk/meson/Kconfig"
 source "drivers/clk/mvebu/Kconfig"
 source "drivers/clk/owl/Kconfig"
drivers/clk/Makefile +1 -0
index 06131edb9f..4f3893f6fc 100644
@@ -26,6 +26,7 @@ obj-$(CONFIG_CLK_BCM6345) += clk_bcm6345.o
 obj-$(CONFIG_CLK_BOSTON) += clk_boston.o
 obj-$(CONFIG_CLK_EXYNOS) += exynos/
 obj-$(CONFIG_CLK_HSDK) += clk-hsdk-cgu.o
+obj-$(CONFIG_CLK_K210) += kendryte/
 obj-$(CONFIG_CLK_MPC83XX) += mpc83xx_clk.o
 obj-$(CONFIG_CLK_OWL) += owl/
 obj-$(CONFIG_CLK_RENESAS) += renesas/
drivers/clk/kendryte/Kconfig new file +7 -0
new file mode 100644
index 0000000000..a178d50f5e
@@ -0,0 +1,7 @@
+config CLK_K210
+	bool "Clock support for Kendryte K210"
+	depends on K210_SYSCTL
+	select CLK
+	select CLK_CCF
+	help
+	  This enables support clock driver for Kendryte K210 platforms.
drivers/clk/kendryte/Makefile new file +1 -0
new file mode 100644
index 0000000000..c56d93ea1c
@@ -0,0 +1 @@
+obj-y += pll.o
drivers/clk/kendryte/pll.c new file +455 -0

455 lines not on this page · raw message

drivers/clk/kendryte/pll.h new file +38 -0
new file mode 100644
index 0000000000..6a8734a295
@@ -0,0 +1,38 @@
+#ifndef K210_PLL_H
+#define K210_PLL_H
+
+#include <clk.h>
+
+#define K210_PLL_CLKR GENMASK(3, 0)
+#define K210_PLL_CLKF GENMASK(9, 4)
+#define K210_PLL_CLKOD GENMASK(13, 10)
+#define K210_PLL_BWADJ GENMASK(19, 14)
+#define K210_PLL_RESET BIT(20)
+#define K210_PLL_PWRD BIT(21)
+#define K210_PLL_INTFB BIT(22)
+#define K210_PLL_BYPASS BIT(23)
+#define K210_PLL_TEST BIT(24)
+#define K210_PLL_EN BIT(25)
+#define K210_PLL_TEST_EN BIT(26)
+
+#define K210_PLL_LOCK 0
+#define K210_PLL_CLEAR_SLIP 2
+#define K210_PLL_TEST_OUT 3
+
+struct k210_pll {
+	struct clk clk;
+	void __iomem *reg; /* Base PLL register */
+	void __iomem *lock; /* Common PLL lock register */
+	u8 shift; /* Offset of bits in lock register */
+	u8 lock_mask; /* Mask of lock bits to test against, pre-shifted */
+};
+
+extern const struct clk_ops k210_pll_ops;
+
+struct k210_pll *k210_clk_comp_pll(void __iomem *reg, void __iomem *lock,
+				   u8 shift, u8 width);
+struct clk *k210_clk_pll(const char *name, const char *parent_name,
+			 void __iomem *reg, void __iomem *lock, u8 shift,
+			 u8 width);
+
+#endif /* K210_PLL_H */
Signature · 1 line
2.24.1
#11 lore raw

PATCH 10/11 riscv: Add K210 clock support

In reply to Sean Anderson

Due to the large number of clocks, I decided to use the CCF. The overall structure is modeled after the imx code. A common pattern is to create a composite clock composed of several component clocks. For these component clocks, the clk_register_* functions are not used, since they will be registered as part of the composite clock. To create these component clocks, several helper k210_clk_comp_* functions are used. This functionality seems like it would be useful to other drivers also creating composite clocks, so perhaps some general versions should be created. I am not particularly attached to the naming convention, suggestions are welcome.

---
 arch/riscv/Kconfig              |   3 -
 arch/riscv/Makefile             |   6 -
 arch/riscv/dts/k210.dtsi        |  13 ++
 board/sipeed/maix/Kconfig       |   4 +-
 configs/sipeed_maix_bitm_config |   1 -
 drivers/clk/kendryte/clk.c      | 391 ++++++++++++++++++++++++++++++++
 drivers/clk/kendryte/clk.h      |  27 +++
 7 files changed, 434 insertions(+), 11 deletions(-)
 create mode 100644 drivers/clk/kendryte/clk.c
 create mode 100644 drivers/clk/kendryte/clk.h
arch/riscv/Kconfig +0 -3
index 13518b0440..d85235a378 100644
@@ -245,7 +245,4 @@ config STACK_SIZE_SHIFT
 config SPL_LDSCRIPT
 	default "arch/riscv/cpu/u-boot-spl.lds"
 
-config ARCH_K210
-	bool "Support Kendryte K210 SOCs"
-
 endmenu
arch/riscv/Makefile +0 -6
index 390178e149..0b80eb8d86 100644
@@ -30,12 +30,6 @@ ARCH_FLAGS = -march=$(ARCH_BASE)$(ARCH_A)$(ARCH_C) -mabi=$(ABI) \
 PLATFORM_CPPFLAGS	+= $(ARCH_FLAGS)
 CFLAGS_EFI		+= $(ARCH_FLAGS)
 
-machine-$(CONFIG_ARCH_K210) += k210
-
-machdirs := $(patsubst %,arch/riscv/mach-%/,$(machine-y))
-PLATFORM_CPPFLAGS += $(patsubst %,-I$(srctree)/%include,$(machdirs))
-libs-y += $(machdirs)
-
 head-y := arch/riscv/cpu/start.o
 
 libs-y += arch/riscv/cpu/
arch/riscv/dts/k210.dtsi +13 -0
index c17e206579..5e86fe3fdc 100644
@@ -27,6 +27,7 @@
 			compatible = "fixed-clock";
 			#clock-cells = <0>;
 			clock-frequency = <26000000>;
+			u-boot,dm-pre-reloc;
 		};
 	};
 
@@ -371,6 +372,18 @@
 				compatible = "kendryte,k210-clk";
 				clocks = <&in0>;
 				#clock-cells = <1>;
+				assigned-clocks = <&sysclk K210_CLK_ACLK>,
+				                  <&sysclk K210_CLK_PLL0>,
+				                  <&sysclk K210_CLK_PLL1>,
+						  <&sysclk K210_CLK_PLL2>;
+				assigned-clock-parents = <&sysclk K210_CLK_PLL0>,
+				                         <0>,
+							 <0>,
+							 <&in0>;
+				assigned-clock-rates = <793000000>,
+				                       <390000000>,
+						       <390000000>,
+						       <793000000>;
 			};
 
 			sysrst: reset-controller {
board/sipeed/maix/Kconfig +3 -1
index 838f2fb263..6a25086ef4 100644
@@ -27,6 +27,9 @@ config NR_CPUS
 config NR_DRAM_BANKS
 	default 2
 
+config SYS_MALLOC_F_LEN
+	default 0x8000
+
 config BOARD_SPECIFIC_OPTIONS
 	def_bool y
 	select GENERIC_RISCV
@@ -34,7 +37,6 @@ config BOARD_SPECIFIC_OPTIONS
 	select SIFIVE_SERIAL
 	select ARCH_DEFAULT_RV64I
 	select ENV_IS_NOWHERE
-	select ARCH_K210
 	imply SIFIVE_CLINT
 	imply K210_SYSCTL
 	imply CLK_K210
configs/sipeed_maix_bitm_config +0 -1
index f20145feac..0088748ae0 100644
@@ -31,7 +31,6 @@ CONFIG_SIFIVE_CLINT=y
 CONFIG_K210_SYSCTL=y
 CONFIG_SHOW_REGS=y
 CONFIG_STACK_SIZE_SHIFT=14
-CONFIG_ARCH_K210=y
 CONFIG_LOCALVERSION=""
 CONFIG_CC_OPTIMIZE_FOR_SIZE=y
 CONFIG_SYS_MALLOC_F=y
drivers/clk/kendryte/clk.c new file +391 -0

391 lines not on this page · raw message

drivers/clk/kendryte/clk.h new file +27 -0
new file mode 100644
index 0000000000..17d0f5de1b
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2019 Sean Anderson <[email protected]>
+ */
+
+#ifndef K210_CLK_H
+#define K210_CLK_H
+
+#define LOG_CATEGORY UCLASS_CLK
+#include <linux/types.h>
+#include <linux/clk-provider.h>
+
+static inline struct clk *k210_clk_gate(const char *name,
+					const char *parent_name,
+					void __iomem *reg, u8 bit_idx)
+{
+	return clk_register_gate(NULL, name, parent_name, 0, reg, bit_idx, 0,
+				 NULL);
+}
+
+static inline struct clk *k210_clk_half(const char *name,
+				        const char *parent_name)
+{
+	return clk_register_fixed_factor(NULL, name, parent_name, 0, 1, 2);
+}
+
+#endif /* K210_CLK_H */
Signature · 1 line
2.24.1
#12 lore raw

PATCH 11/11 riscv: Add option to disable writes to mcounteren

In reply to Sean Anderson

On the kendryte k210, writes to mcounteren result in an illegal instruction exception.

---
 arch/riscv/cpu/cpu.c            | 2 ++
 board/sipeed/maix/Kconfig       | 1 +
 configs/sipeed_maix_bitm_config | 1 +
 3 files changed, 4 insertions(+)
arch/riscv/cpu/cpu.c +2 -0
index e457f6acbf..df9eae663c 100644
@@ -89,7 +89,9 @@ int arch_cpu_init_dm(void)
 		 * Enable perf counters for cycle, time,
 		 * and instret counters only
 		 */
+#ifndef CONFIG_SYS_RISCV_NOCOUNTER
 		csr_write(CSR_MCOUNTEREN, GENMASK(2, 0));
+#endif
 
 		/* Disable paging */
 		if (supports_extension('s'))
board/sipeed/maix/Kconfig +1 -0
index 6a25086ef4..c456c47fb2 100644
@@ -37,6 +37,7 @@ config BOARD_SPECIFIC_OPTIONS
 	select SIFIVE_SERIAL
 	select ARCH_DEFAULT_RV64I
 	select ENV_IS_NOWHERE
+	select SYS_RISCV_NOCOUNTER
 	imply SIFIVE_CLINT
 	imply K210_SYSCTL
 	imply CLK_K210
configs/sipeed_maix_bitm_config +1 -0
index 0088748ae0..73075e3016 100644
@@ -30,6 +30,7 @@ CONFIG_RISCV_ISA_A=y
 CONFIG_SIFIVE_CLINT=y
 CONFIG_K210_SYSCTL=y
 CONFIG_SHOW_REGS=y
+CONFIG_SYS_RISCV_NOCOUNTER=y
 CONFIG_STACK_SIZE_SHIFT=14
 CONFIG_LOCALVERSION=""
 CONFIG_CC_OPTIMIZE_FOR_SIZE=y
Signature · 1 line
2.24.1