riscv: k210: Enable use of AI ram bank
Subsystems (4)
v2 cover riscv: k210: Enable use of AI ram bank
This ram bank was previously unusable because PLL1 was not started correctly. This series fixes that bug, and allows U-Boot to relocate into the AI ram. This provides an extra 2M of space in which to load payloads.
Second time around and I realized that the bypass clock is no longer necessary (yay). This also necessitates a few more small fixups. I've also added some minor patches to bring the device tree and clock driver closer to what Linux has (or will have). This should be the last round of additions to this series.
Changes in v2:
- Don't re-enable the PLL
- Remove bypass clock, which is no longer necessary
- Simplify PLL instantiation
- Modify clock tree so clint is a child of aclk
- Sync memory dts node with Linux
- Use correct aisram clock
Sean Anderson (16):
clk: k210: Fix PLLs not being enabled
clk: k210: Fix PLL enable always getting taken
clk: k210: Remove bypass clock
clk: k210: Remove k210_register_pll
clk: k210: Move the clint clock to under aclk
clk: Add support for the k210 clock driver pre-relocation
riscv: Enable some devices pre-relocation
lib: fdt: Add fdtdec_setup_mem_size_base_highest
test: Add a test for fdtdec_setup_mem_size_base et al.
ram: Add driver for K210 SRAM
ram: sifive: Default to y only if compiling for fu540
riscv: Probe ram in dram_init
riscv: Enable AI ram on K210
riscv: k210: Rename airam to aisram
riscv: k210: Use AI as the parent clock of aisram, not PLL1
riscv: Don't reserve AI ram in k210 dts
MAINTAINERS | 1 + arch/riscv/cpu/generic/dram.c | 26 +++ arch/riscv/dts/k210.dtsi | 22 +-- arch/sandbox/dts/test.dts | 12 ++ board/sipeed/maix/Kconfig | 2 + board/sipeed/maix/maix.c | 26 --- configs/sandbox64_defconfig | 2 +- configs/sandbox_defconfig | 2 +- configs/sandbox_flattree_defconfig | 2 +- configs/sipeed_maix_bitm_defconfig | 1 + drivers/clk/kendryte/Makefile | 2 +- drivers/clk/kendryte/bypass.c | 273 ----------------------------- drivers/clk/kendryte/clk.c | 61 +++---- drivers/clk/kendryte/pll.c | 26 +-- drivers/ram/Kconfig | 7 + drivers/ram/Makefile | 1 + drivers/ram/kendryte.c | 56 ++++++ drivers/ram/sifive/Kconfig | 2 +- include/configs/sipeed-maix.h | 4 - include/fdtdec.h | 19 +- include/kendryte/bypass.h | 31 ---- include/kendryte/pll.h | 4 - lib/fdtdec.c | 34 +++- test/dm/fdtdec.c | 38 ++++ 24 files changed, 230 insertions(+), 424 deletions(-) delete mode 100644 drivers/clk/kendryte/bypass.c create mode 100644 drivers/ram/kendryte.c delete mode 100644 include/kendryte/bypass.h
Signature · 1 line
2.28.0
PATCH v2 1/16 clk: k210: Fix PLLs not being enabled
After starting or setting the rate of a PLL, the enable bit must be set.
This fixes a bug where the AI ram would not be accessible, because it requires PLL1 to be running.
---
(no changes since v1)
drivers/clk/kendryte/pll.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/clk/kendryte/pll.c +2 -0
@@ -531,6 +531,7 @@ static int k210_pll_enable(struct clk *clk)k210_pll_waitfor_lock (pll); reg &= ~K210_PLL_BYPASS ; + reg |=K210_PLL_EN ;writel (reg, pll->reg);return 0 ;
@@ -550,6 +551,7 @@ static int k210_pll_disable(struct clk *clk)writel (reg, pll->reg); reg &= ~K210_PLL_PWRD ; + reg &= ~K210_PLL_EN ;writel (reg, pll->reg);return 0 ; }
Signature · 1 line
2.28.0
PATCH v2 1/16 clk: k210: Fix PLLs not being enabled
Quoted 5 lines
After starting or setting the rate of a PLL, the enable bit must be set.
This fixes a bug where the AI ram would not be accessible, because it requires PLL1 to be running.
Quoted 8 lines
Signed-off-by Sean Anderson <[email protected]>---
(no changes since v1)
drivers/clk/kendryte/pll.c | 2 ++ 1 file changed, 2 insertions(+)
PATCH v2 2/16 clk: k210: Fix PLL enable always getting taken
In reply to Sean AndersonThis conditional always evaluated as false, regardless of the value of reg. Fix it so that it properly tests the bits in the PLL register. Also test PLL_EN, now that we set it.
---
Changes in v2:
- New
drivers/clk/kendryte/pll.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/clk/kendryte/pll.c +2 -1
@@ -512,7 +512,8 @@ static int k210_pll_enable(struct clk *clk)struct k210_pll *pll =to_k210_pll (clk);u32 reg =readl (pll->reg); -if ((reg |K210_PLL_PWRD ) && !(reg |K210_PLL_RESET )) +if ((reg &K210_PLL_PWRD ) && (reg &K210_PLL_EN ) && + !(reg &K210_PLL_RESET ))return 0 ; reg |=K210_PLL_PWRD ;
Signature · 1 line
2.28.0
PATCH v2 2/16 clk: k210: Fix PLL enable always getting taken
Quoted 6 lines
This conditional always evaluated as false, regardless of the value of reg. Fix it so that it properly tests the bits in the PLL register. Also test
PLL_EN, now that we set it.Reported-by Damien Le Moal <[email protected]>Signed-off-by Sean Anderson <[email protected]>
Quoted 8 lines
---
Changes in v2:
- Newdrivers/clk/kendryte/pll.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
PATCH v2 3/16 clk: k210: Remove bypass clock
In reply to Sean AndersonNow that the PLLs get properly enabled, the bypass clock is no longer necessary.
---
Changes in v2:
- New
drivers/clk/kendryte/Makefile | 2 +- drivers/clk/kendryte/bypass.c | 273 ---------------------------------- drivers/clk/kendryte/clk.c | 43 ++---- include/kendryte/bypass.h | 31 ---- 4 files changed, 15 insertions(+), 334 deletions(-) delete mode 100644 drivers/clk/kendryte/bypass.c delete mode 100644 include/kendryte/bypass.h
drivers/clk/kendryte/Makefile +1 -1
@@ -1 +1 @@ -obj-y += bypass.o clk.o pll.o +obj-y += clk.o pll.o
drivers/clk/kendryte/bypass.c deleted +0 -273
273 lines not on this page · raw message
drivers/clk/kendryte/clk.c +14 -29
73 lines not on this page · raw message
include/kendryte/bypass.h deleted +0 -31
@@ -1,31 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* -* Copyright (C) 2020 Sean Anderson <[email protected]> -*/ -#ifndef K210_BYPASS_H -#define K210_BYPASS_H - -struct clk ; - -struct k210_bypass { -struct clk clk; -struct clk **children;/* Clocks to reparent */ -struct clk **saved_parents;/* Parents saved over en-/dis-able */ -struct clk *bypassee;/* Clock to bypass */ -const struct clk_ops *bypassee_ops;/* Ops of the bypass clock */ -struct clk *alt;/* Clock to set children to when bypassing */ -size_t child_count; -}; - -#define to_k210_bypass (_clk) container_of(_clk, struct k210_bypass, clk) - -int k210_bypass_set_children (struct clk *clk,struct clk **children, -size_t child_count); -struct clk *k210_register_bypass_struct (const char *name, -const char *parent_name, -struct k210_bypass *bypass); -struct clk *k210_register_bypass (const char *name,const char *parent_name, -struct clk *bypassee, -const struct clk_ops *bypassee_ops, -struct clk *alt); -#endif /* K210_BYPASS_H */
Signature · 1 line
2.28.0
PATCH v2 4/16 clk: k210: Remove k210_register_pll
In reply to Sean AndersonThis simplifies the PLL creation process, since we don't have to pass all the parameters individually.
---
Changes in v2:
- New
drivers/clk/kendryte/clk.c | 20 ++++++-------------- drivers/clk/kendryte/pll.c | 21 --------------------- include/kendryte/pll.h | 4 ---- 3 files changed, 6 insertions(+), 39 deletions(-)
drivers/clk/kendryte/clk.c +6 -14
@@ -511,23 +511,15 @@ static int k210_clk_probe(struct udevice *dev) aclk_sels[0 ] = in0; pll2_sels[0 ] = in0; - { -const struct k210_pll_params *params = &k210_plls[0 ]; - + pll =k210_create_pll (&k210_plls[0 ], base); +if (pll)clk_dm (K210_CLK_PLL0 , -k210_register_pll ("pll0" , in0, base + params->off, - base + params->lock_off, params->shift, - params->width)); - } - - { -const struct k210_pll_params *params = &k210_plls[1 ]; +k210_register_pll_struct ("pll0" , in0, pll)); + pll =k210_create_pll (&k210_plls[1 ], base); +if (pll)clk_dm (K210_CLK_PLL1 , -k210_register_pll ("pll1" , in0, base + params->off, - base + params->lock_off, params->shift, - params->width)); - } +k210_register_pll_struct ("pll1" , in0, pll));/* PLL2 is muxed, so set up a composite clock */ mux =k210_create_mux (&k210_muxes[MUXIFY (K210_CLK_PLL2 )], base);
drivers/clk/kendryte/pll.c +0 -21
@@ -578,27 +578,6 @@ struct clk *k210_register_pll_struct(const char *name, const char *parent_name,return clk; } -struct clk *k210_register_pll (const char *name,const char *parent_name, -void __iomem *reg,void __iomem *lock,u8 shift, -u8 width) -{ -struct clk *clk; -struct k210_pll *pll; - - pll =kzalloc (sizeof (*pll),GFP_KERNEL ); -if (!pll) -return ERR_PTR (-ENOMEM ); - pll->reg = reg; - pll->lock = lock; - pll->shift = shift; - pll->width = width; - - clk =k210_register_pll_struct (name, parent_name, pll); -if (IS_ERR (clk)) -kfree (pll); -return clk; -} -U_BOOT_DRIVER (k210_pll) = { .name =CLK_K210_PLL , .id =UCLASS_CLK ,
include/kendryte/pll.h +0 -4
@@ -55,8 +55,4 @@ extern const struct clk_ops k210_pll_ops;struct clk *k210_register_pll_struct (const char *name,const char *parent_name,struct k210_pll *pll); -struct clk *k210_register_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.28.0
PATCH v2 5/16 clk: k210: Move the clint clock to under aclk
In reply to Sean AndersonNo other (real) clocks have the cpu clock as their parent; instead they are children of aclk. Move the clint clock under aclk to match them.
---
Changes in v2:
- New
drivers/clk/kendryte/clk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/kendryte/clk.c +1 -1
@@ -625,7 +625,7 @@ static int k210_clk_probe(struct udevice *dev)/* The MTIME register in CLINT runs at one 50th the CPU clock speed */ clk_dm (K210_CLK_CLINT , -clk_register_fixed_factor (NULL ,"clint" ,"cpu" ,0 ,1 ,50 )); +clk_register_fixed_factor (NULL ,"clint" ,"aclk" ,0 ,1 ,50 ));return 0 ; }
Signature · 1 line
2.28.0
PATCH v2 6/16 clk: Add support for the k210 clock driver pre-relocation
In reply to Sean AndersonVariables which had previously been stored in .bss are moved to .data. In addition, probed needs to be reset when the clock driver is re-bound post-relocation.
---
(no changes since v1)
drivers/clk/kendryte/clk.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/clk/kendryte/clk.c +9 -1
@@ -471,7 +471,14 @@ cleanup_mux:return comp; } -static bool probed; +static bool __section(.data) probed; + +/* reset probed so we will probe again post-relocation */ +static int k210_clk_bind(struct udevice *dev) +{ + probed = false; +return 0 ; +}static int k210_clk_probe (struct udevice *dev) {
@@ -640,5 +647,6 @@ U_BOOT_DRIVER(k210_clk) = { .id = UCLASS_CLK, .of_match = k210_clk_ids, .ops = &k210_clk_ops, + .bind = k210_clk_bind, .probe = k210_clk_probe, };
Signature · 1 line
2.28.0
PATCH v2 6/16 clk: Add support for the k210 clock driver pre-relocation
Quoted 4 lines
Variables which had previously been stored in .bss are moved to .data. In addition, probed needs to be reset when the clock driver is re-bound post-relocation.
Quoted 8 lines
Signed-off-by Sean Anderson <[email protected]>---
(no changes since v1)
drivers/clk/kendryte/clk.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
PATCH v2 7/16 riscv: Enable some devices pre-relocation
In reply to Sean AndersonThese devices are necessary for the clock driver, which is required by the sram driver, to run pre-relocation.
---
(no changes since v1)
arch/riscv/dts/k210.dtsi | 4 ++++ 1 file changed, 4 insertions(+)
arch/riscv/dts/k210.dtsi +4 -0
@@ -91,6 +91,7 @@ <&sysclk K210_CLK_SRAM1>, <&sysclk K210_CLK_PLL1>; clock-names = "sram0", "sram1", "airam"; + u-boot,dm-pre-reloc; }; reserved-memory {
@@ -109,6 +110,7 @@ compatible = "fixed-clock"; #clock-cells = <0>; clock-frequency = <26000000>; + u-boot,dm-pre-reloc; }; };
@@ -503,11 +505,13 @@ "syscon", "simple-mfd"; reg = <0x50440000 0x100>; reg-io-width = <4>; + u-boot,dm-pre-reloc; sysclk: clock-controller { #clock-cells = <1>; compatible = "kendryte,k210-clk"; clocks = <&in0>; + u-boot,dm-pre-reloc; }; sysrst: reset-controller {
Signature · 1 line
2.28.0
PATCH v2 7/16 riscv: Enable some devices pre-relocation
Quoted 11 lines
These devices are necessary for the clock driver, which is required by the sram driver, to run pre-relocation.
Signed-off-by Sean Anderson <[email protected]>---
(no changes since v1)
arch/riscv/dts/k210.dtsi | 4 ++++ 1 file changed, 4 insertions(+)
PATCH v2 8/16 lib: fdt: Add fdtdec_setup_mem_size_base_highest
In reply to Sean AndersonThis is very similar to fdtdec_setup_mem_size_base_lowest, except we pick the highest ram bank, instead of the lowest. This is helpful for boards which use separate but contiguous ram banks, as it leaves the most space for loading programs.
---
(no changes since v1)
include/fdtdec.h | 19 ++++++++++++++++++- lib/fdtdec.c | 34 +++++++++++++++++++++++++++++----- 2 files changed, 47 insertions(+), 6 deletions(-)
include/fdtdec.h +18 -1
@@ -944,7 +944,7 @@ int fdtdec_setup_mem_size_base(void);* gd->ram_start by lowest available memory base * * Decode the /memory 'reg' property to determine the lowest start of the memory -* bank bank and populate the global data with it. +* bank and populate the global data with it. * * This function should be called from a boards dram_init(). This helper * function allows for boards to query the device tree for DRAM size and start
@@ -956,6 +956,23 @@ int fdtdec_setup_mem_size_base(void);*/ int fdtdec_setup_mem_size_base_lowest (void ); +/** +* fdtdec_setup_mem_size_base_highest() - decode and setup gd->ram_size and +* gd->ram_start by highest available memory top +* +* Decode the /memory 'reg' property to determine the highest end of the memory +* bank and populate the global data with it. +* +* This function should be called from a boards dram_init(). This helper +* function allows for boards to query the device tree for DRAM size and start +* address instead of hard coding the value in the case where the memory size +* and start address cannot be detected automatically. +* +* @return 0 if OK, -EINVAL if the /memory node or reg property is missing or +* invalid +*/ +int fdtdec_setup_mem_size_base_highest (void ); +/** * fdtdec_setup_memory_banksize() - decode and populate gd->bd->bi_dram *
lib/fdtdec.c +29 -5
@@ -1123,7 +1123,7 @@ int fdtdec_setup_memory_banksize(void)return 0 ; } -int fdtdec_setup_mem_size_base_lowest (void ) +static int fdtdec_setup_mem_size_base_superlative (bool lowest) {int bank, ret, reg =0 ;struct resource res;
@@ -1131,7 +1131,16 @@ int fdtdec_setup_mem_size_base_lowest(void)phys_size_t size;ofnode mem =ofnode_null (); - gd->ram_base = (unsigned long )~0 ; +/* +* Size must be 1 so we don't underflow when doing the subtraction below +* when lowest = false. Hopefully any real ram banks will have a greater +* size :) +*/ + gd->ram_size =1 ; +if (lowest) + gd->ram_base = (unsigned long )~0 ; +else + gd->ram_base =0 ; mem =get_next_memory_node (mem);if (!ofnode_valid (mem)) {
@@ -1158,17 +1167,32 @@ int fdtdec_setup_mem_size_base_lowest(void) base = (unsigned long )res.start; size = (phys_size_t)(res.end - res.start +1 ); -if (gd->ram_base > base && size) { +if (!size) +continue ; + +if ((lowest && gd->ram_base > base) || + (!lowest && gd->ram_base + gd->ram_size -1 < res.end)) { gd->ram_base = base; gd->ram_size = size; -debug ("%s: Initial DRAM base %lx size %lx\n" , - __func__, base, (unsigned long )size); } } +if (gd->ram_size) +debug ("%s: Initial DRAM base %lx size %lx\n" , __func__, + gd->ram_base, (unsigned long )gd->ram_size);return 0 ; } +int fdtdec_setup_mem_size_base_lowest (void ) +{ +return fdtdec_setup_mem_size_base_superlative (true); +} + +int fdtdec_setup_mem_size_base_highest (void ) +{ +return fdtdec_setup_mem_size_base_superlative (false); +} +#if CONFIG_IS_ENABLED (MULTI_DTB_FIT )# if CONFIG_IS_ENABLED (MULTI_DTB_FIT_GZIP ) ||\CONFIG_IS_ENABLED (MULTI_DTB_FIT_LZO )
Signature · 1 line
2.28.0
PATCH v2 8/16 lib: fdt: Add fdtdec_setup_mem_size_base_highest
Quoted 7 lines
This is very similar to
fdtdec_setup_mem_size_base_lowest, except we pick the highest ram bank, instead of the lowest. This is helpful for boards which use separate but contiguous ram banks, as it leaves the most space for loading programs.Signed-off-by Sean Anderson <[email protected]>Reviewed-by Simon Glass <[email protected]>
Quoted 8 lines
---
(no changes since v1)
include/fdtdec.h | 19 ++++++++++++++++++- lib/fdtdec.c | 34 +++++++++++++++++++++++++++++----- 2 files changed, 47 insertions(+), 6 deletions(-)
PATCH v2 9/16 test: Add a test for fdtdec_setup_mem_size_base et al.
In reply to Sean AndersonThis adds a test for the various methods of extracting ram_base and ram_size from a device tree.
---
(no changes since v1)
arch/sandbox/dts/test.dts | 12 ++++++++++ configs/sandbox64_defconfig | 2 +- configs/sandbox_defconfig | 2 +- configs/sandbox_flattree_defconfig | 2 +- test/dm/fdtdec.c | 38 ++++++++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 3 deletions(-)
arch/sandbox/dts/test.dts +12 -0
@@ -1221,6 +1221,18 @@ compatible = "sandbox,regmap_test"; }; }; + + memory at 0000 { + device_type = "memory"; + reg = <0x1000 0x2000>, + <0x0000 0x1000>; + }; + + memory at 8000 { + device_type = "memory"; + reg = <0x8000 0x0000>, + <0x4000 0x3000>; + }; }; #include "sandbox_pmic.dtsi"
configs/sandbox64_defconfig +1 -1
@@ -1,5 +1,5 @@ CONFIG_SYS_TEXT_BASE=0 -CONFIG_NR_DRAM_BANKS=1 +CONFIG_NR_DRAM_BANKS=4 CONFIG_ENV_SIZE=0x2000 CONFIG_PRE_CON_BUF_ADDR=0x100000 CONFIG_BOOTSTAGE_STASH_ADDR=0x0
configs/sandbox_defconfig +1 -1
@@ -1,5 +1,5 @@ CONFIG_SYS_TEXT_BASE=0 -CONFIG_NR_DRAM_BANKS=1 +CONFIG_NR_DRAM_BANKS=4 CONFIG_ENV_SIZE=0x2000 CONFIG_PRE_CON_BUF_ADDR=0xf0000 CONFIG_BOOTSTAGE_STASH_ADDR=0x0
configs/sandbox_flattree_defconfig +1 -1
@@ -1,5 +1,5 @@ CONFIG_SYS_TEXT_BASE=0 -CONFIG_NR_DRAM_BANKS=1 +CONFIG_NR_DRAM_BANKS=4 CONFIG_ENV_SIZE=0x2000 CONFIG_BOOTSTAGE_STASH_ADDR=0x0 CONFIG_DEFAULT_DEVICE_TREE="sandbox"
test/dm/fdtdec.c +38 -0
@@ -131,3 +131,41 @@ static int dm_test_fdtdec_add_reserved_memory(struct unit_test_state *uts) }DM_TEST (dm_test_fdtdec_add_reserved_memory,UT_TESTF_SCAN_PDATA |UT_TESTF_SCAN_FDT |UT_TESTF_FLAT_TREE ); + +static int _dm_test_fdtdec_setup_mem (struct unit_test_state *uts) +{ +ut_assertok (fdtdec_setup_mem_size_base ()); +ut_asserteq (0x1000 , gd->ram_base); +ut_asserteq (0x2000 , gd->ram_size); + +ut_assertok (fdtdec_setup_mem_size_base_lowest ()); +ut_asserteq (0x0000 , gd->ram_base); +ut_asserteq (0x1000 , gd->ram_size); + +ut_assertok (fdtdec_setup_mem_size_base_highest ()); +ut_asserteq (0x4000 , gd->ram_base); +ut_asserteq (0x3000 , gd->ram_size); + +return 0 ; +} + +/* +* We need to wrap the actual test so that we don't overwrite the ram parameters +* for the rest of U-Boot +*/ +static int dm_test_fdtdec_setup_mem (struct unit_test_state *uts) +{ +int ret; +unsigned long base, size; + + base = gd->ram_base; + size = gd->ram_size; + + ret =_dm_test_fdtdec_setup_mem (uts); + + gd->ram_base = base; + gd->ram_size = size; + +return ret; +} +DM_TEST (dm_test_fdtdec_setup_mem,UT_TESTF_SCAN_FDT |UT_TESTF_FLAT_TREE );
Signature · 1 line
2.28.0
PATCH v2 10/16 ram: Add driver for K210 SRAM
In reply to Sean AndersonThis adds a driver to handle enabling the clock for the AI SRAM. This was previously done in board_init, but it needs to happen before relocation now. An alternative would be to move this to board_init_early_f, but by doing it this way we can use clk_bulk.
---
(no changes since v1)
MAINTAINERS | 1 + drivers/ram/Kconfig | 7 ++++++ drivers/ram/Makefile | 1 + drivers/ram/kendryte.c | 56 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 drivers/ram/kendryte.c
MAINTAINERS +1 -0
@@ -938,6 +938,7 @@ F: doc/device-tree-bindings/mfd/kendryte,k210-sysctl.txt F: doc/device-tree-bindings/pinctrl/kendryte,k210-fpioa.txt F: drivers/clk/kendryte/ F: drivers/pinctrl/kendryte/ +F: drivers/ram/kendryte.c F: include/kendryte/ RNG
drivers/ram/Kconfig +7 -0
@@ -73,6 +73,13 @@ config IMXRT_SDRAM to support external memories like sdram, psram & nand. This driver is for the sdram memory interface with the SEMC. +config K210_SRAM + bool "Enable Kendryte K210 SRAM support" + depends on RAM + help + The Kendryte K210 has three banks of SRAM. This driver does the + necessary initialization. + source "drivers/ram/aspeed/Kconfig" source "drivers/ram/rockchip/Kconfig" source "drivers/ram/sifive/Kconfig"
drivers/ram/Makefile +1 -0
@@ -18,6 +18,7 @@ obj-$(CONFIG_ARCH_ASPEED) += aspeed/ obj-$(CONFIG_K3_J721E_DDRSS) += k3-j721e/ obj-$(CONFIG_IMXRT_SDRAM) += imxrt_sdram.o +obj-$(CONFIG_K210_SRAM) += kendryte.o obj-$(CONFIG_RAM_SIFIVE) += sifive/
drivers/ram/kendryte.c new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH v2 10/16 ram: Add driver for K210 SRAM
Quoted 9 lines
This adds a driver to handle enabling the clock for the AI SRAM. This was previously done in
board_init, but it needs to happen before relocation now. An alternative would be to move this toboard_init_early_f, but by doing it this way we can useclk_bulk.Signed-off-by Sean Anderson <[email protected]>Reviewed-by Simon Glass <[email protected]>---
Quoted 9 lines
(no changes since v1)
MAINTAINERS | 1 + drivers/ram/Kconfig | 7 ++++++ drivers/ram/Makefile | 1 + drivers/ram/kendryte.c | 56 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 drivers/ram/kendryte.c
PATCH v2 11/16 ram: sifive: Default to y only if compiling for fu540
In reply to Sean AndersonOther RISC-V targets should not have RAM_SIFIVE enabled by default.
---
(no changes since v1)
drivers/ram/sifive/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ram/sifive/Kconfig +1 -1
@@ -1,7 +1,7 @@ config RAM_SIFIVE bool "Ram drivers support for SiFive SoCs" depends on RAM && RISCV - default y + default y if TARGET_SIFIVE_FU540 help This enables support for ram drivers of SiFive SoCs.
Signature · 1 line
2.28.0
PATCH v2 11/16 ram: sifive: Default to y only if compiling for fu540
Quoted 11 lines
Other RISC-V targets should not have
RAM_SIFIVEenabled by default.Signed-off-by Sean Anderson <[email protected]>Reviewed-by Pragnesh Patel <[email protected]>---
(no changes since v1)
drivers/ram/sifive/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH v2 12/16 riscv: Probe ram in dram_init
In reply to Sean AndersonIf CONFIG_RAM is enabled, use the ram device to get the base/size of memory. This provides an easy way for boards/cpus to hook into the dram_init logic, without needing to provide a second SYS_CPU.
---
(no changes since v1)
arch/riscv/cpu/generic/dram.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
arch/riscv/cpu/generic/dram.c +26 -0
@@ -4,15 +4,41 @@*/ #include <common.h> +#include <dm.h> #include <fdtdec.h> #include <init.h> +#include <log.h> +#include <ram.h> #include <linux/sizes.h> DECLARE_GLOBAL_DATA_PTR ;int dram_init (void ) { +#if CONFIG_IS_ENABLED (RAM ) +int ret; +struct ram_info info; +struct udevice *dev; + + ret =uclass_get_device (UCLASS_RAM ,0 , &dev); +if (ret) { +debug ("DRAM init failed: %d\n" , ret); +return ret; + } + + ret =ram_get_info (dev, &info); +if (ret) { +debug ("Cannot get DRAM size: %d\n" , ret); +return ret; + } + + gd->ram_base = info.base; + gd->ram_size = info.size; + +return 0 ; +#else return fdtdec_setup_mem_size_base (); +#endif }int dram_init_banksize (void )
Signature · 1 line
2.28.0
PATCH v2 12/16 riscv: Probe ram in dram_init
Quoted 4 lines
If
CONFIG_RAMis enabled, use the ram device to get the base/size of memory. This provides an easy way for boards/cpus to hook into thedram_initlogic, without needing to provide a secondSYS_CPU.
Quoted 8 lines
Signed-off-by Sean Anderson <[email protected]>---
(no changes since v1)
arch/riscv/cpu/generic/dram.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
PATCH v2 13/16 riscv: Enable AI ram on K210
In reply to Sean AndersonCONFIG_SYS_SDRAM_{BASE,SIZE} are no longer necessary. The default get_effective_memsize will also work. The clock driver creates a bunch of devices, so we need to increase the pre-reloc malloc arena.
---
(no changes since v1)
board/sipeed/maix/Kconfig | 2 ++ board/sipeed/maix/maix.c | 26 -------------------------- configs/sipeed_maix_bitm_defconfig | 1 + include/configs/sipeed-maix.h | 4 ---- 4 files changed, 3 insertions(+), 30 deletions(-)
board/sipeed/maix/Kconfig +2 -0
@@ -42,6 +42,8 @@ config BOARD_SPECIFIC_OPTIONS imply CLK_K210 imply DM_RESET imply RESET_SYSCON + imply RAM + imply K210_SRAM imply SYSRESET imply SYSRESET_SYSCON imply PINCTRL
board/sipeed/maix/maix.c +0 -26
@@ -9,33 +9,7 @@#include <fdt_support.h> #include <asm/io.h> -phys_size_t get_effective_memsize (void ) -{ -return CONFIG_SYS_SDRAM_SIZE ; -} -int board_init (void ) { -int ret, i; -const char *const banks[] = {"sram0" ,"sram1" ,"airam" }; -ofnode memory; -struct clk clk; - -/* Enable RAM clocks */ - memory =ofnode_by_compatible (ofnode_null (),"kendryte,k210-sram" ); -if (ofnode_equal (memory,ofnode_null ())) -return -ENOENT ; - -for (i =0 ; i <ARRAY_SIZE (banks); i++) { - ret =clk_get_by_name_nodev (memory, banks[i], &clk); -if (ret) -continue ; - - ret =clk_enable (&clk); -clk_free (&clk); -if (ret) -return ret; - } -return 0 ; }
configs/sipeed_maix_bitm_defconfig +1 -0
@@ -1,4 +1,5 @@ CONFIG_RISCV=y +CONFIG_SYS_MALLOC_F_LEN=0x10000 CONFIG_TARGET_SIPEED_MAIX=y CONFIG_ARCH_RV64I=y CONFIG_STACK_SIZE=0x100000
include/configs/sipeed-maix.h +0 -4
@@ -14,10 +14,6 @@#define CONFIG_SYS_MALLOC_LEN SZ_128K#define CONFIG_SYS_CACHELINE_SIZE 64 -#define CONFIG_SYS_SDRAM_BASE 0x80000000 -/* Don't relocate into AI ram since it isn't set up yet */ -#define CONFIG_SYS_SDRAM_SIZE (SZ_4M + SZ_2M) -/* For early init */ #define K210_SYSCTL_BASE 0x50440000
Signature · 1 line
2.28.0
PATCH v2 13/16 riscv: Enable AI ram on K210
Quoted 7 lines
CONFIG_SYS_SDRAM_{BASE,SIZE} are no longer necessary. The default
get_effective_memsizewill also work. The clock driver creates a bunch of devices, so we need to increase the pre-reloc malloc arena.Signed-off-by Sean Anderson <[email protected]>---
Quoted 8 lines
(no changes since v1)
board/sipeed/maix/Kconfig | 2 ++ board/sipeed/maix/maix.c | 26 -------------------------- configs/sipeed_maix_bitm_defconfig | 1 + include/configs/sipeed-maix.h | 4 ---- 4 files changed, 3 insertions(+), 30 deletions(-)
PATCH v2 14/16 riscv: k210: Rename airam to aisram
In reply to Sean AndersonThis is more consistent with the naming of other ram banks, and matches what Linux is doing.
---
Changes in v2:
- New
arch/riscv/dts/k210.dtsi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/riscv/dts/k210.dtsi +2 -2
@@ -86,11 +86,11 @@ reg = <0x80000000 0x400000>, <0x80400000 0x200000>, <0x80600000 0x200000>; - reg-names = "sram0", "sram1", "airam"; + reg-names = "sram0", "sram1", "aisram"; clocks = <&sysclk K210_CLK_SRAM0>, <&sysclk K210_CLK_SRAM1>, <&sysclk K210_CLK_PLL1>; - clock-names = "sram0", "sram1", "airam"; + clock-names = "sram0", "sram1", "aisram"; u-boot,dm-pre-reloc; };
Signature · 1 line
2.28.0
PATCH v2 14/16 riscv: k210: Rename airam to aisram
Quoted 5 lines
This is more consistent with the naming of other ram banks, and matches what Linux is doing.
Reported-by Damien Le Moal <[email protected]>Signed-off-by Sean Anderson <[email protected]>
Quoted 8 lines
---
Changes in v2:
- Newarch/riscv/dts/k210.dtsi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
PATCH v2 15/16 riscv: k210: Use AI as the parent clock of aisram, not PLL1
In reply to Sean AndersonTesting showed that disabling AI while leaving PLL1 enabled disabled the aisram. This suggests that AI is a more appropriate clock for that ram bank.
---
Changes in v2:
- New
arch/riscv/dts/k210.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/dts/k210.dtsi +1 -1
@@ -89,7 +89,7 @@ reg-names = "sram0", "sram1", "aisram"; clocks = <&sysclk K210_CLK_SRAM0>, <&sysclk K210_CLK_SRAM1>, - <&sysclk K210_CLK_PLL1>; + <&sysclk K210_CLK_AI>; clock-names = "sram0", "sram1", "aisram"; u-boot,dm-pre-reloc; };
Signature · 1 line
2.28.0
PATCH v2 15/16 riscv: k210: Use AI as the parent clock of aisram, not PLL1
Quoted 4 lines
Testing showed that disabling AI while leaving PLL1 enabled disabled the aisram. This suggests that AI is a more appropriate clock for that ram bank.
Quoted 9 lines
Signed-off-by Sean Anderson <[email protected]>---
Changes in v2:
- Newarch/riscv/dts/k210.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH v2 16/16 riscv: Don't reserve AI ram in k210 dts
In reply to Sean AndersonIt is no longer necessary to disallow ai ram, since it is enabled by the sram driver.
---
(no changes since v1)
arch/riscv/dts/k210.dtsi | 12 ------------ 1 file changed, 12 deletions(-)
arch/riscv/dts/k210.dtsi +0 -12
@@ -94,17 +94,6 @@ u-boot,dm-pre-reloc; }; - reserved-memory { - #address-cells = <1>; - #size-cells = <1>; - ranges; - - ai_reserved: ai at 80600000 { - reg = <0x80600000 0x200000>; - reusable; - }; - }; - clocks { in0: osc { compatible = "fixed-clock";
@@ -179,7 +168,6 @@ reg = <0x40800000 0xc00000>; interrupts = <25>; clocks = <&sysclk K210_CLK_AI>; - memory-region = <&ai_reserved>; status = "disabled"; };
Signature · 1 line
2.28.0
v2 cover riscv: k210: Enable use of AI ram bank
In reply to Sean AndersonQuoted 8 lines · Sean Anderson
This ram bank was previously unusable because PLL1 was not started correctly. This series fixes that bug, and allows U-Boot to relocate into the AI ram. This provides an extra 2M of space in which to load payloads.
Second time around and I realized that the bypass clock is no longer necessary (yay). This also necessitates a few more small fixups. I've also added some minor patches to bring the device tree and clock driver closer to what Linux has (or will have). This should be the last round of additions to this series.
I discovered that the clock changes I made cause problems with non-default PLL frequencies (specifically the removal of the bypass clock). I've been working on-and-off on a v3 to fix these problems.
--Sean
Quoted 55 lines
Changes in v2:
- Don't re-enable the PLL
- Remove bypass clock, which is no longer necessary
- Simplify PLL instantiation
- Modify clock tree so clint is a child of aclk
- Sync memory dts node with Linux
- Use correct aisram clockSean Anderson (16):
clk: k210: Fix PLLs not being enabled
clk: k210: Fix PLL enable always getting taken
clk: k210: Remove bypass clock
clk: k210: Removek210_register_pll
clk: k210: Move the clint clock to under aclk
clk: Add support for the k210 clock driver pre-relocation
riscv: Enable some devices pre-relocation
lib: fdt: Addfdtdec_setup_mem_size_base_highest
test: Add a test forfdtdec_setup_mem_size_baseet al.
ram: Add driver for K210 SRAM
ram: sifive: Default to y only if compiling for fu540
riscv: Probe ram indram_init
riscv: Enable AI ram on K210
riscv: k210: Rename airam to aisram
riscv: k210: Use AI as the parent clock of aisram, not PLL1
riscv: Don't reserve AI ram in k210 dtsMAINTAINERS | 1 + arch/riscv/cpu/generic/dram.c | 26 +++ arch/riscv/dts/k210.dtsi | 22 +-- arch/sandbox/dts/test.dts | 12 ++ board/sipeed/maix/Kconfig | 2 + board/sipeed/maix/maix.c | 26 --- configs/sandbox64_defconfig | 2 +- configs/sandbox_defconfig | 2 +- configs/sandbox_flattree_defconfig | 2 +- configs/sipeed_maix_bitm_defconfig | 1 + drivers/clk/kendryte/Makefile | 2 +- drivers/clk/kendryte/bypass.c | 273 ----------------------------- drivers/clk/kendryte/clk.c | 61 +++---- drivers/clk/kendryte/pll.c | 26 +-- drivers/ram/Kconfig | 7 + drivers/ram/Makefile | 1 + drivers/ram/kendryte.c | 56 ++++++ drivers/ram/sifive/Kconfig | 2 +- include/configs/sipeed-maix.h | 4 - include/fdtdec.h | 19 +- include/kendryte/bypass.h | 31 ---- include/kendryte/pll.h | 4 - lib/fdtdec.c | 34 +++- test/dm/fdtdec.c | 38 ++++ 24 files changed, 230 insertions(+), 424 deletions(-) delete mode 100644 drivers/clk/kendryte/bypass.c create mode 100644 drivers/ram/kendryte.c delete mode 100644 include/kendryte/bypass.h