riscv: Add Sipeed Maix support
Subsystems (14)
v6 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/1215327/>
(clk: Include missing headers for linux/clk-provider.h).
This will (hopefully) be the last version of this series adding any new functionality, other than that needed to fix the bugs below.
Known Bugs/Limitations:
- Accessing the AI ram hangs, limiting available ram to 6M
- The MMC cannot be accessed with the dw_spi driver
- Trying to boot an image with bootm fails with
ERROR: Failed to allocate 0x7d60 bytes below 0x80000000.
To flash u-boot to a maix bit, run
kflash -tp /dev/<your tty here> -B bit_mic u-boot-dtb.bin
Boot output should look like the following:
U-Boot 2020.04-rc2-00087-g2221cc09c1-dirty (Feb 28 2020 - 13:53:09 -0500)
DRAM: 8 MiB In: serial at 38000000 Out: serial at 38000000 Err: serial at 38000000
=>
Changes for v6:
- Remove spi, pinmux, gpio, led, and wdt support --- to be added in separate patches
- Rebase onto master
- Clear IPIs before enabling them
- Reorganize code so checkpatch errors less
Changes for v5:
- Rebase onto master
- Add pinconf support
- Add gpio support
- Store environment in spi flash
- Group patches by prefix
- Add additional documentation
- Add SMP support
- Add WDT support
Changes for v4:
- Linted several patches
- Updated the copyright year for several files
- Added tests for syscon-reset, simple-pm-bus, and the pll calc_rate function
- Added/updated documentation
- Fixed SPI for the nor flash
- Fixed PLLs not enabling/setting rate properly
- RISCV_PRIV_1_9_1 now (un)defines all diferring CSRs, and also disables VM
- More devicetree changes
Changes for v3:
- Remove patch to set RV64I as default
- Remove patch for a separate sysctl driver
- Split off cpu frequency patch into its own series
- Reorder support/devicetree patches to come last
- Add patch for reset driver
- Add simple-pm-bus for busses with their own clocks
- Add additional documentation
- Reword mcounteren patch to refer to the RISC-V priv spec 1.9.1
- Many devicetree changes
- Switch to "make savedefconfig" to generate the config
Changes for v2:
- Many bugfixes for the device tree
- Modify the config to build without errors
- Add support for keeping internal PLL frequencies in-range
- Fix several rebase-induced artifacts
Sean Anderson (19):
clk: Always use the supplied struct clk
clk: Check that ops of composite clock components exist before calling
clk: Unconditionally recursively en-/dis-able clocks
clk: Add functions to register CCF clock structs
clk: Add K210 pll support
clk: Add a bypass clock for K210
clk: Add K210 clock support
dm: Add support for simple-pm-bus
dm: Fix error handling for dev_read_addr_ptr
reset: Add generic reset driver
lib: Always set errno in hcreate_r
riscv: Add headers for asm/global_data.h
riscv: Fix race conditions when initializing IPI
riscv: Add option to support RISC-V privileged spec 1.9
riscv: Allow use of reset drivers
riscv: Try to get cpu frequency from a "clocks" node if it exists
riscv: Enable cpu clock if it is present
riscv: Add device tree for K210 and Sipeed Maix BitM
riscv: Add Sipeed Maix support
MAINTAINERS | 7 + arch/riscv/Kconfig | 14 + arch/riscv/cpu/cpu.c | 15 + arch/riscv/cpu/start.S | 2 + arch/riscv/dts/Makefile | 1 + arch/riscv/dts/k210-maix-bit.dts | 47 ++ arch/riscv/dts/k210.dtsi | 599 +++++++++++++++++ arch/riscv/include/asm/csr.h | 40 ++ arch/riscv/include/asm/global_data.h | 2 + arch/riscv/include/asm/smp.h | 43 ++ arch/riscv/lib/andes_plic.c | 34 +- arch/riscv/lib/reset.c | 2 + arch/riscv/lib/sbi_ipi.c | 5 + arch/riscv/lib/sifive_clint.c | 33 +- arch/riscv/lib/smp.c | 56 +- arch/sandbox/dts/test.dts | 21 + arch/sandbox/include/asm/clk.h | 1 + board/sipeed/maix/Kconfig | 48 ++ board/sipeed/maix/MAINTAINERS | 11 + board/sipeed/maix/Makefile | 5 + board/sipeed/maix/maix.c | 54 ++ configs/sandbox_defconfig | 2 + configs/sipeed_maix_bitm_defconfig | 8 + doc/board/index.rst | 1 + doc/board/sipeed/index.rst | 9 + doc/board/sipeed/maix.rst | 298 +++++++++ .../bus/simple-pm-bus.txt | 44 ++ .../mfd/kendryte,k210-sysctl.txt | 33 + .../reset/syscon-reset.txt | 36 ++ doc/imx/clk/ccf.txt | 63 +- drivers/clk/Kconfig | 1 + drivers/clk/Makefile | 1 + drivers/clk/clk-composite.c | 145 +++-- drivers/clk/clk-divider.c | 62 +- drivers/clk/clk-fixed-factor.c | 3 +- drivers/clk/clk-gate.c | 44 +- drivers/clk/clk-mux.c | 12 +- drivers/clk/clk-uclass.c | 60 +- drivers/clk/imx/clk-gate2.c | 4 +- drivers/clk/imx/clk-imx8mp.c | 2 +- drivers/clk/kendryte/Kconfig | 12 + drivers/clk/kendryte/Makefile | 1 + drivers/clk/kendryte/bypass.c | 270 ++++++++ drivers/clk/kendryte/clk.c | 489 ++++++++++++++ drivers/clk/kendryte/pll.c | 601 ++++++++++++++++++ drivers/core/Kconfig | 7 + drivers/core/Makefile | 1 + drivers/core/read.c | 2 +- drivers/core/simple-pm-bus.c | 56 ++ drivers/cpu/riscv_cpu.c | 39 +- drivers/pinctrl/broadcom/pinctrl-bcm283x.c | 2 +- drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 2 +- drivers/reset/Kconfig | 5 + drivers/reset/Makefile | 1 + drivers/reset/reset-syscon.c | 80 +++ include/configs/sipeed-maix.h | 24 + include/dm/read.h | 4 +- include/dt-bindings/clock/k210-sysctl.h | 59 ++ include/dt-bindings/mfd/k210-sysctl.h | 38 ++ include/dt-bindings/reset/k210-sysctl.h | 38 ++ include/kendryte/bypass.h | 31 + include/kendryte/clk.h | 35 + include/kendryte/pll.h | 57 ++ include/linux/clk-provider.h | 9 + include/test/export.h | 16 + lib/hashtable.c | 8 +- test/dm/Makefile | 3 + test/dm/k210_pll.c | 96 +++ test/dm/simple-pm-bus.c | 45 ++ test/dm/syscon-reset.c | 58 ++ 70 files changed, 3673 insertions(+), 284 deletions(-) create mode 100644 arch/riscv/dts/k210-maix-bit.dts create mode 100644 arch/riscv/dts/k210.dtsi 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_defconfig create mode 100644 doc/board/sipeed/index.rst create mode 100644 doc/board/sipeed/maix.rst create mode 100644 doc/device-tree-bindings/bus/simple-pm-bus.txt create mode 100644 doc/device-tree-bindings/mfd/kendryte,k210-sysctl.txt create mode 100644 doc/device-tree-bindings/reset/syscon-reset.txt create mode 100644 drivers/clk/kendryte/Kconfig create mode 100644 drivers/clk/kendryte/Makefile create mode 100644 drivers/clk/kendryte/bypass.c create mode 100644 drivers/clk/kendryte/clk.c create mode 100644 drivers/clk/kendryte/pll.c create mode 100644 drivers/core/simple-pm-bus.c create mode 100644 drivers/reset/reset-syscon.c create mode 100644 include/configs/sipeed-maix.h create mode 100644 include/dt-bindings/clock/k210-sysctl.h create mode 100644 include/dt-bindings/mfd/k210-sysctl.h create mode 100644 include/dt-bindings/reset/k210-sysctl.h create mode 100644 include/kendryte/bypass.h create mode 100644 include/kendryte/clk.h create mode 100644 include/kendryte/pll.h create mode 100644 include/test/export.h create mode 100644 test/dm/k210_pll.c create mode 100644 test/dm/simple-pm-bus.c create mode 100644 test/dm/syscon-reset.c
Signature · 1 line
2.25.0
PATCH v6 1/19 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.
---
Changes in v4:
- Lint
Changes in v3:
- Documented new assumptions in the CCF
- Wrapped docs to 80 columns
doc/imx/clk/ccf.txt | 63 +++++++++++++++++----------------- drivers/clk/clk-composite.c | 7 ++++ 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 +-- 7 files changed, 50 insertions(+), 51 deletions(-)
doc/imx/clk/ccf.txt +32 -31
@@ -1,42 +1,37 @@ Introduction: ============= -This documentation entry describes the Common Clock Framework [CCF] -port from Linux kernel (v5.1.12) to U-Boot. +This documentation entry describes the Common Clock Framework [CCF] port from +Linux kernel (v5.1.12) to U-Boot. -This code is supposed to bring CCF to IMX based devices (imx6q, imx7 -imx8). Moreover, it also provides some common clock code, which would -allow easy porting of CCF Linux code to other platforms. +This code is supposed to bring CCF to IMX based devices (imx6q, imx7 imx8). +Moreover, it also provides some common clock code, which would allow easy +porting of CCF Linux code to other platforms. Design decisions: ================= -* U-Boot's driver model [DM] for clk differs from Linux CCF. The most - notably difference is the lack of support for hierarchical clocks and - "clock as a manager driver" (single clock DTS node acts as a starting - point for all other clocks). +* U-Boot's driver model [DM] for clk differs from Linux CCF. The most notably + difference is the lack of support for hierarchical clocks and "clock as a + manager driver" (single clock DTS node acts as a starting point for all other + clocks). -* The clk_get_rate() caches the previously read data if CLK_GET_RATE_NOCACHE - is not set (no need for recursive access). +* The clk_get_rate() caches the previously read data if CLK_GET_RATE_NOCACHE is + not set (no need for recursive access). -* On purpose the "manager" clk driver (clk-imx6q.c) is not using large - table to store pointers to clocks - e.g. clk[IMX6QDL_CLK_USDHC2_SEL] = .... - Instead we use udevice's linked list for the same class (UCLASS_CLK). +* On purpose the "manager" clk driver (clk-imx6q.c) is not using large table to + store pointers to clocks - e.g. clk[IMX6QDL_CLK_USDHC2_SEL] = .... Instead we + use udevice's linked list for the same class (UCLASS_CLK). Rationale: ---------- - When porting the code as is from Linux, one would need ~1KiB of RAM to - store it. This is way too much if we do plan to use this driver in SPL. + When porting the code as is from Linux, one would need ~1KiB of RAM to store + it. This is way too much if we do plan to use this driver in SPL. * The "central" structure of this patch series is struct udevice and its uclass_priv field contains the struct clk pointer (to the originally created one). -* Up till now U-Boot's driver model (DM) CLK operates on udevice (main - access to clock is by udevice ops) - In the CCF the access to struct clk (embodying pointer to *dev) is - possible via dev_get_clk_ptr() (it is a wrapper on dev_get_uclass_priv()). - * To keep things simple the struct udevice's uclass_priv pointer is used to store back pointer to corresponding struct clk. However, it is possible to modify clk-uclass.c file and add there struct uc_clk_priv, which would have
@@ -45,13 +40,17 @@ Design decisions: setting .per_device_auto_alloc_size = sizeof(struct uc_clk_priv)) the uclass_priv stores the pointer to struct clk. +* Non-CCF clocks do not have a pointer to a clock in clk->dev->priv. In the case + of composite clocks, clk->dev->priv may not match clk. Drivers should always + use the struct clk which is passed to them, and not clk->dev->priv. + * It is advised to add common clock code (like already added rate and flags) to the struct clk, which is a top level description of the clock. * U-Boot's driver model already provides the facility to automatically allocate - (via private_alloc_size) device private data (accessible via dev->priv). - It may look appealing to use this feature to allocate private structures for - CCF clk devices e.g. divider (struct clk_divider *divider) for IMX6Q clock. + (via private_alloc_size) device private data (accessible via dev->priv). It + may look appealing to use this feature to allocate private structures for CCF + clk devices e.g. divider (struct clk_divider *divider) for IMX6Q clock. The above feature had not been used for following reasons: - The original CCF Linux kernel driver is the "manager" for clocks - it
@@ -64,21 +63,23 @@ Design decisions: * I've added the clk_get_parent(), which reads parent's dev->uclass_priv to provide parent's struct clk pointer. This seems the easiest way to get - child/parent relationship for struct clk in U-Boot's udevice based clocks. + child/parent relationship for struct clk in U-Boot's udevice based clocks. In + the future arbitrary parents may be supported by adding a get_parent function + to clk_ops. * Linux's CCF 'struct clk_core' corresponds to U-Boot's udevice in 'struct clk'. Clock IP block agnostic flags from 'struct clk_core' (e.g. NOCACHE) have been - moved from this struct one level up to 'struct clk'. + moved from this struct one level up to 'struct clk'. Many flags are + unimplemented at the moment. * For tests the new ./test/dm/clk_ccf.c and ./drivers/clk/clk_sandbox_ccf.c files have been introduced. The latter setups the CCF clock structure for - sandbox by reusing, if possible, generic clock primitives - like divier - and mux. The former file provides code to tests this setup. + sandbox by reusing, if possible, generic clock primitives - like divier and + mux. The former file provides code to tests this setup. For sandbox new CONFIG_SANDBOX_CLK_CCF Kconfig define has been introduced. - All new primitives added for new architectures must have corresponding test - in the two aforementioned files. - + All new primitives added for new architectures must have corresponding test in + the two aforementioned files. Testing (sandbox): ==================
drivers/clk/clk-composite.c +7 -0
@@ -147,6 +147,13 @@ 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
@@ -72,8 +72,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;
@@ -152,8 +151,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
@@ -20,8 +20,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
@@ -45,8 +45,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;
@@ -88,8 +87,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
@@ -37,8 +37,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) {
@@ -81,8 +80,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 )
@@ -99,8 +97,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;
@@ -117,8 +114,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
@@ -39,7 +39,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);
@@ -52,7 +52,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.25.0
PATCH v6 2/19 clk: Check that ops of composite clock components exist before calling
In reply to Sean Andersonclk_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.
---
Changes in v4:
- Return ENOTSUPP not ENOSYS with no set_parent
Changes in v3:
- Don't return an error code where a no-op would be fine
drivers/clk/clk-composite.c | 57 +++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 22 deletions(-)
drivers/clk/clk-composite.c +35 -22
@@ -24,7 +24,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)
@@ -34,7 +37,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)
@@ -44,7 +50,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)
@@ -54,7 +63,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 clk_get_rate (clk); }static int clk_composite_enable (struct clk *clk)
@@ -64,7 +76,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 0 ; }static int clk_composite_disable (struct clk *clk)
@@ -74,15 +89,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 0 ; } -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,
@@ -96,7 +108,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)
@@ -105,8 +119,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; }
@@ -115,11 +127,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;
@@ -134,8 +141,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; }
@@ -161,6 +166,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.25.0
PATCH v6 3/19 clk: Unconditionally recursively en-/dis-able clocks
In reply to Sean AndersonFor clocks not in the CCF, their parents will not have UCLASS_CLK, so we just enable them as normal. The enable count is local to the struct clk, but this will never result in the actual en-/dis-able op being called (unless the same struct clk is enabled twice).
For clocks in the CCF, we always traverse up the tree when enabling. Previously, CCF clocks without id set would be skipped, stopping the traversal too early.
---
Changes in v5:
- Clear enable_count on request
Changes in v4:
- Lint
Changes in v3:
- New
drivers/clk/clk-uclass.c | 60 ++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 33 deletions(-)
drivers/clk/clk-uclass.c +27 -33
@@ -410,6 +410,7 @@ int clk_request(struct udevice *dev, struct clk *clk) ops =clk_dev_ops (dev); clk->dev = dev; + clk->enable_count =0 ;if (!ops->request)return 0 ;
@@ -522,7 +523,6 @@ int clk_set_parent(struct clk *clk, struct clk *parent)int clk_enable (struct clk *clk) {const struct clk_ops *ops; -struct clk *clkp =NULL ;int ret;debug ("%s(clk=%p \"%s\")\n" , __func__, clk, clk->dev->name);
@@ -531,32 +531,29 @@ int clk_enable(struct clk *clk) ops =clk_dev_ops (clk->dev);if (CONFIG_IS_ENABLED (CLK_CCF )) { -/* Take id 0 as a non-valid clk, such as dummy */ -if (clk->id && !clk_get_by_id (clk->id, &clkp)) { -if (clkp->enable_count) { - clkp->enable_count++; -return 0 ; - } -if (clkp->dev->parent && -device_get_uclass_id (clkp->dev) ==UCLASS_CLK ) { - ret =clk_enable (dev_get_clk_ptr (clkp->dev->parent)); -if (ret) { -printf ("Enable %s failed\n" , - clkp->dev->parent->name); -return ret; - } +if (clk->enable_count) { + clk->enable_count++; +return 0 ; + } +if (clk->dev->parent && +device_get_uclass_id (clk->dev->parent) ==UCLASS_CLK ) { + ret =clk_enable (dev_get_clk_ptr (clk->dev->parent)); +if (ret) { +printf ("Enable %s failed\n" , + clk->dev->parent->name); +return ret; } }if (ops->enable) { ret = ops->enable (clk);if (ret) { -printf ("Enable %s failed\n" , clk->dev->name); +printf ("Enable %s failed (error %d)\n" , + clk->dev->name, ret);return ret; } } -if (clkp) - clkp->enable_count++; + clk->enable_count++; }else {if (!ops->enable)return -ENOSYS ;
@@ -582,7 +579,6 @@ int clk_enable_bulk(struct clk_bulk *bulk)int clk_disable (struct clk *clk) {const struct clk_ops *ops; -struct clk *clkp =NULL ;int ret;debug ("%s(clk=%p)\n" , __func__, clk);
@@ -591,29 +587,27 @@ int clk_disable(struct clk *clk) ops =clk_dev_ops (clk->dev);if (CONFIG_IS_ENABLED (CLK_CCF )) { -if (clk->id && !clk_get_by_id (clk->id, &clkp)) { -if (clkp->enable_count ==0 ) { -printf ("clk %s already disabled\n" , - clkp->dev->name); -return 0 ; - } - -if (--clkp->enable_count >0 ) -return 0 ; +if (clk->enable_count ==0 ) { +printf ("clk %s already disabled\n" , + clk->dev->name); +return 0 ; } +if (--clk->enable_count >0 ) +return 0 ; +if (ops->disable) { ret = ops->disable (clk);if (ret)return ret; } -if (clkp && clkp->dev->parent && -device_get_uclass_id (clkp->dev) ==UCLASS_CLK ) { - ret =clk_disable (dev_get_clk_ptr (clkp->dev->parent)); +if (clk->dev->parent && +device_get_uclass_id (clk->dev) ==UCLASS_CLK ) { + ret =clk_disable (dev_get_clk_ptr (clk->dev->parent));if (ret) { -printf ("Disable %s failed\n" , - clkp->dev->parent->name); +printf ("Disable %s failed (error %d)\n" , + clk->dev->parent->name, ret);return ret; } }
Signature · 1 line
2.25.0
PATCH v6 3/19 clk: Unconditionally recursively en-/dis-able clocks
Hi Sean
Quoted 30 lines
For clocks not in the CCF, their parents will not have
UCLASS_CLK, so we just enable them as normal. The enable count is local to the struct clk, but this will never result in the actual en-/dis-able op being called (unless the same struct clk is enabled twice).For clocks in the CCF, we always traverse up the tree when enabling. Previously, CCF clocks without id set would be skipped, stopping the traversal too early.
Signed-off-by Sean Anderson <[email protected]>Acked-by Lukasz Majewski <[email protected]>---
Changes in v5:
- Clearenable_counton requestChanges in v4:
- LintChanges in v3:
- Newdrivers/clk/clk-uclass.c | 60 ++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 33 deletions(-)drivers/clk/clk-uclass.c +0
-0
drivers/clk/clk-uclass.c int clk_request(struct udevice *dev, struct clk *clk) · line 413
Quoted 4 lines
drivers/clk/clk-uclass.c +1
-0@@ -410,6 +410,7 @@ int clk_request(struct udevice *dev, struct clk *clk) ops =clk_dev_ops (dev); clk->dev = dev; + clk->enable_count =0 ;
Lukasz has taged Acked-by in v3.
Re: [PATCH v3 03/12] clk: Unconditionally recursively en-/dis-able clocks
This patch shall be fixed and freeze.
But you add a new modification (Clear enable_count on request)in v5 and v6. Although it seem to look fine and nothing big deal.
I just highlight it here, and if Lukasz have no other comment further. I will pull it via riscv tree later.
Thanks,
Rick
Quoted 111 lines
drivers/clk/clk-uclass.c +26
-34if (!ops->request)return 0 ;@@ -522,7 +523,6 @@ int clk_set_parent(struct clk *clk, struct clk *parent)int clk_enable (struct clk *clk) {const struct clk_ops *ops; -struct clk *clkp =NULL ;int ret;debug ("%s(clk=%p \"%s\")\n" , __func__, clk, clk->dev->name);@@ -531,32 +531,29 @@ int clk_enable(struct clk *clk) ops =clk_dev_ops (clk->dev);if (CONFIG_IS_ENABLED (CLK_CCF )) { -/* Take id 0 as a non-valid clk, such as dummy */ -if (clk->id && !clk_get_by_id (clk->id, &clkp)) { -if (clkp->enable_count) { - clkp->enable_count++; -return 0 ; - } -if (clkp->dev->parent && -device_get_uclass_id (clkp->dev) ==UCLASS_CLK ) { - ret =clk_enable (dev_get_clk_ptr (clkp->dev->parent)); -if (ret) { -printf ("Enable %s failed\n" , - clkp->dev->parent->name); -return ret; - } +if (clk->enable_count) { + clk->enable_count++; +return 0 ; + } +if (clk->dev->parent && +device_get_uclass_id (clk->dev->parent) ==UCLASS_CLK ) { + ret =clk_enable (dev_get_clk_ptr (clk->dev->parent)); +if (ret) { +printf ("Enable %s failed\n" , + clk->dev->parent->name); +return ret; } }if (ops->enable) { ret = ops->enable (clk);if (ret) { -printf ("Enable %s failed\n" , clk->dev->name); +printf ("Enable %s failed (error %d)\n" , + clk->dev->name, ret);return ret; } } -if (clkp) - clkp->enable_count++; + clk->enable_count++; }else {if (!ops->enable)return -ENOSYS ;@@ -582,7 +579,6 @@ int clk_enable_bulk(struct clk_bulk *bulk)int clk_disable (struct clk *clk) {const struct clk_ops *ops; -struct clk *clkp =NULL ;int ret;debug ("%s(clk=%p)\n" , __func__, clk);@@ -591,29 +587,27 @@ int clk_disable(struct clk *clk) ops =clk_dev_ops (clk->dev);if (CONFIG_IS_ENABLED (CLK_CCF )) { -if (clk->id && !clk_get_by_id (clk->id, &clkp)) { -if (clkp->enable_count ==0 ) { -printf ("clk %s already disabled\n" , - clkp->dev->name); -return 0 ; - } - -if (--clkp->enable_count >0 ) -return 0 ; +if (clk->enable_count ==0 ) { +printf ("clk %s already disabled\n" , + clk->dev->name); +return 0 ; } +if (--clk->enable_count >0 ) +return 0 ; +if (ops->disable) { ret = ops->disable (clk);if (ret)return ret; } -if (clkp && clkp->dev->parent && -device_get_uclass_id (clkp->dev) ==UCLASS_CLK ) { - ret =clk_disable (dev_get_clk_ptr (clkp->dev->parent)); +if (clk->dev->parent && +device_get_uclass_id (clk->dev) ==UCLASS_CLK ) { + ret =clk_disable (dev_get_clk_ptr (clk->dev->parent));if (ret) { -printf ("Disable %s failed\n" , - clkp->dev->parent->name); +printf ("Disable %s failed (error %d)\n" , + clk->dev->parent->name, ret);return ret; } } --2.25.0
PATCH v6 3/19 clk: Unconditionally recursively en-/dis-able clocks
Hi Sean
Quoted 38 lines
Quoted 30 lines
For clocks not in the CCF, their parents will not have
UCLASS_CLK, so we just enable them as normal. The enable count is local to the struct clk, but this will never result in the actual en-/dis-able op being called (unless the same struct clk is enabled twice).For clocks in the CCF, we always traverse up the tree when enabling. Previously, CCF clocks without id set would be skipped, stopping the traversal too early.
Signed-off-by Sean Anderson <[email protected]>Acked-by Lukasz Majewski <[email protected]>---
Changes in v5:
- Clearenable_counton requestChanges in v4:
- LintChanges in v3:
- Newdrivers/clk/clk-uclass.c | 60 ++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 33 deletions(-)drivers/clk/clk-uclass.c +0
-0drivers/clk/clk-uclass.c int clk_request(struct udevice *dev, struct clk *clk) · line 413
Quoted 4 lines
drivers/clk/clk-uclass.c +1
-0@@ -410,6 +410,7 @@ int clk_request(struct udevice *dev, struct clk *clk) ops =clk_dev_ops (dev); clk->dev = dev; + clk->enable_count =0 ;Lukasz has taged Acked-by in v3.
Re: [PATCH v3 03/12] clk: Unconditionally recursively en-/dis-able clocks
Quoted 6 lines
This patch shall be fixed and freeze.
But you add a new modification (Clearenable_counton request)in v5 and v6. Although it seem to look fine and nothing big deal.
I just highlight it here, and if Lukasz have no other comment further. I will pull it via riscv tree later.
I have told you in v5, that this patch have conflict with u-boot/master please rebase it.
But it still conflict in v6.
https://patchwork.ozlabs.org/patch/1246836/
Applying: clk: Always use the supplied struct clk
Applying: clk: Check that ops of composite clock components exist before calling
Applying: clk: Unconditionally recursively en-/dis-able clocks
error: patch failed: drivers/clk/clk-uclass.c:522
error: drivers/clk/clk-uclass.c: patch does not apply
Patch failed at 0003 clk: Unconditionally recursively en-/dis-able clocks The copy of the patch that failed is found in: .git/rebase-apply/patch When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Quoted 116 lines
Thanks,
RickQuoted 111 lines
drivers/clk/clk-uclass.c +26
-34if (!ops->request)return 0 ;@@ -522,7 +523,6 @@ int clk_set_parent(struct clk *clk, struct clk *parent)int clk_enable (struct clk *clk) {const struct clk_ops *ops; -struct clk *clkp =NULL ;int ret;debug ("%s(clk=%p \"%s\")\n" , __func__, clk, clk->dev->name);@@ -531,32 +531,29 @@ int clk_enable(struct clk *clk) ops =clk_dev_ops (clk->dev);if (CONFIG_IS_ENABLED (CLK_CCF )) { -/* Take id 0 as a non-valid clk, such as dummy */ -if (clk->id && !clk_get_by_id (clk->id, &clkp)) { -if (clkp->enable_count) { - clkp->enable_count++; -return 0 ; - } -if (clkp->dev->parent && -device_get_uclass_id (clkp->dev) ==UCLASS_CLK ) { - ret =clk_enable (dev_get_clk_ptr (clkp->dev->parent)); -if (ret) { -printf ("Enable %s failed\n" , - clkp->dev->parent->name); -return ret; - } +if (clk->enable_count) { + clk->enable_count++; +return 0 ; + } +if (clk->dev->parent && +device_get_uclass_id (clk->dev->parent) ==UCLASS_CLK ) { + ret =clk_enable (dev_get_clk_ptr (clk->dev->parent)); +if (ret) { +printf ("Enable %s failed\n" , + clk->dev->parent->name); +return ret; } }if (ops->enable) { ret = ops->enable (clk);if (ret) { -printf ("Enable %s failed\n" , clk->dev->name); +printf ("Enable %s failed (error %d)\n" , + clk->dev->name, ret);return ret; } } -if (clkp) - clkp->enable_count++; + clk->enable_count++; }else {if (!ops->enable)return -ENOSYS ;@@ -582,7 +579,6 @@ int clk_enable_bulk(struct clk_bulk *bulk)int clk_disable (struct clk *clk) {const struct clk_ops *ops; -struct clk *clkp =NULL ;int ret;debug ("%s(clk=%p)\n" , __func__, clk);@@ -591,29 +587,27 @@ int clk_disable(struct clk *clk) ops =clk_dev_ops (clk->dev);if (CONFIG_IS_ENABLED (CLK_CCF )) { -if (clk->id && !clk_get_by_id (clk->id, &clkp)) { -if (clkp->enable_count ==0 ) { -printf ("clk %s already disabled\n" , - clkp->dev->name); -return 0 ; - } - -if (--clkp->enable_count >0 ) -return 0 ; +if (clk->enable_count ==0 ) { +printf ("clk %s already disabled\n" , + clk->dev->name); +return 0 ; } +if (--clk->enable_count >0 ) +return 0 ; +if (ops->disable) { ret = ops->disable (clk);if (ret)return ret; } -if (clkp && clkp->dev->parent && -device_get_uclass_id (clkp->dev) ==UCLASS_CLK ) { - ret =clk_disable (dev_get_clk_ptr (clkp->dev->parent)); +if (clk->dev->parent && +device_get_uclass_id (clk->dev) ==UCLASS_CLK ) { + ret =clk_disable (dev_get_clk_ptr (clk->dev->parent));if (ret) { -printf ("Disable %s failed\n" , - clkp->dev->parent->name); +printf ("Disable %s failed (error %d)\n" , + clk->dev->parent->name, ret);return ret; } } --2.25.0
PATCH v6 3/19 clk: Unconditionally recursively en-/dis-able clocks
Quoted 53 lines · Rick Chen
Hi Sean
Quoted 38 lines
Quoted 30 lines
For clocks not in the CCF, their parents will not have
UCLASS_CLK, so we just enable them as normal. The enable count is local to the struct clk, but this will never result in the actual en-/dis-able op being called (unless the same struct clk is enabled twice).For clocks in the CCF, we always traverse up the tree when enabling. Previously, CCF clocks without id set would be skipped, stopping the traversal too early.
Signed-off-by Sean Anderson <[email protected]>Acked-by Lukasz Majewski <[email protected]>---
Changes in v5:
- Clearenable_counton requestChanges in v4:
- LintChanges in v3:
- Newdrivers/clk/clk-uclass.c | 60 ++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 33 deletions(-)drivers/clk/clk-uclass.c +0
-0drivers/clk/clk-uclass.c int clk_request(struct udevice *dev, struct clk *clk) · line 413
Quoted 4 lines
drivers/clk/clk-uclass.c +1
-0@@ -410,6 +410,7 @@ int clk_request(struct udevice *dev, struct clk *clk) ops =clk_dev_ops (dev); clk->dev = dev; + clk->enable_count =0 ;Lukasz has taged Acked-by in v3.
Re: [PATCH v3 03/12] clk: Unconditionally recursively en-/dis-able clocksQuoted 6 lines
This patch shall be fixed and freeze.
But you add a new modification (Clearenable_counton request)in v5 and v6. Although it seem to look fine and nothing big deal.
I just highlight it here, and if Lukasz have no other comment further. I will pull it via riscv tree later.I have told you in v5, that this patch have conflict with u-boot/master please rebase it.
But it still conflict in v6.
Quoted 12 lines
Applying: clk: Always use the supplied struct clk
Applying: clk: Check that ops of composite clock components exist before calling
Applying: clk: Unconditionally recursively en-/dis-able clocks
error: patch failed:drivers/clk/clk-uclass.c:522
error:drivers/clk/clk-uclass.c: patch does not apply
Patch failed at 0003 clk: Unconditionally recursively en-/dis-able clocks The copy of the patch that failed is found in: .git/rebase-apply/patch When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
This was just rebased against u-boot/master. Should I be rebasing against a different branch? The commit I am working off is
$ git show upstream/master commit 1efb9796f80e1394f080be1b4f3173ff108ad1f2 (upstream/master, upstream/WIP/03Mar2020, upstream/HEAD) Merge: 8aad16916d 9aa886cc0b Author: Tom Rini <[email protected]> Date: Tue Mar 3 21:48:49 2020 -0500
Merge tag 'dm-pull-3mar20' of git://git.denx.de/u-boot-dm
Fixes for power domain on device removal
Quoted 116 lines
Quoted 116 lines
Thanks,
RickQuoted 111 lines
drivers/clk/clk-uclass.c +26
-34if (!ops->request)return 0 ;@@ -522,7 +523,6 @@ int clk_set_parent(struct clk *clk, struct clk *parent)int clk_enable (struct clk *clk) {const struct clk_ops *ops; -struct clk *clkp =NULL ;int ret;debug ("%s(clk=%p \"%s\")\n" , __func__, clk, clk->dev->name);@@ -531,32 +531,29 @@ int clk_enable(struct clk *clk) ops =clk_dev_ops (clk->dev);if (CONFIG_IS_ENABLED (CLK_CCF )) { -/* Take id 0 as a non-valid clk, such as dummy */ -if (clk->id && !clk_get_by_id (clk->id, &clkp)) { -if (clkp->enable_count) { - clkp->enable_count++; -return 0 ; - } -if (clkp->dev->parent && -device_get_uclass_id (clkp->dev) ==UCLASS_CLK ) { - ret =clk_enable (dev_get_clk_ptr (clkp->dev->parent)); -if (ret) { -printf ("Enable %s failed\n" , - clkp->dev->parent->name); -return ret; - } +if (clk->enable_count) { + clk->enable_count++; +return 0 ; + } +if (clk->dev->parent && +device_get_uclass_id (clk->dev->parent) ==UCLASS_CLK ) { + ret =clk_enable (dev_get_clk_ptr (clk->dev->parent)); +if (ret) { +printf ("Enable %s failed\n" , + clk->dev->parent->name); +return ret; } }if (ops->enable) { ret = ops->enable (clk);if (ret) { -printf ("Enable %s failed\n" , clk->dev->name); +printf ("Enable %s failed (error %d)\n" , + clk->dev->name, ret);return ret; } } -if (clkp) - clkp->enable_count++; + clk->enable_count++; }else {if (!ops->enable)return -ENOSYS ;@@ -582,7 +579,6 @@ int clk_enable_bulk(struct clk_bulk *bulk)int clk_disable (struct clk *clk) {const struct clk_ops *ops; -struct clk *clkp =NULL ;int ret;debug ("%s(clk=%p)\n" , __func__, clk);@@ -591,29 +587,27 @@ int clk_disable(struct clk *clk) ops =clk_dev_ops (clk->dev);if (CONFIG_IS_ENABLED (CLK_CCF )) { -if (clk->id && !clk_get_by_id (clk->id, &clkp)) { -if (clkp->enable_count ==0 ) { -printf ("clk %s already disabled\n" , - clkp->dev->name); -return 0 ; - } - -if (--clkp->enable_count >0 ) -return 0 ; +if (clk->enable_count ==0 ) { +printf ("clk %s already disabled\n" , + clk->dev->name); +return 0 ; } +if (--clk->enable_count >0 ) +return 0 ; +if (ops->disable) { ret = ops->disable (clk);if (ret)return ret; } -if (clkp && clkp->dev->parent && -device_get_uclass_id (clkp->dev) ==UCLASS_CLK ) { - ret =clk_disable (dev_get_clk_ptr (clkp->dev->parent)); +if (clk->dev->parent && +device_get_uclass_id (clk->dev) ==UCLASS_CLK ) { + ret =clk_disable (dev_get_clk_ptr (clk->dev->parent));if (ret) { -printf ("Disable %s failed\n" , - clkp->dev->parent->name); +printf ("Disable %s failed (error %d)\n" , + clk->dev->parent->name, ret);return ret; } } --2.25.0
PATCH v6 3/19 clk: Unconditionally recursively en-/dis-able clocks
Hi Sean
Quoted 67 lines · Rick Chen
Quoted 53 lines
Hi Sean
Quoted 38 lines
Quoted 30 lines
For clocks not in the CCF, their parents will not have
UCLASS_CLK, so we just enable them as normal. The enable count is local to the struct clk, but this will never result in the actual en-/dis-able op being called (unless the same struct clk is enabled twice).For clocks in the CCF, we always traverse up the tree when enabling. Previously, CCF clocks without id set would be skipped, stopping the traversal too early.
Signed-off-by Sean Anderson <[email protected]>Acked-by Lukasz Majewski <[email protected]>---
Changes in v5:
- Clearenable_counton requestChanges in v4:
- LintChanges in v3:
- Newdrivers/clk/clk-uclass.c | 60 ++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 33 deletions(-)drivers/clk/clk-uclass.c +0
-0drivers/clk/clk-uclass.c int clk_request(struct udevice *dev, struct clk *clk) · line 413
Quoted 4 lines
drivers/clk/clk-uclass.c +1
-0@@ -410,6 +410,7 @@ int clk_request(struct udevice *dev, struct clk *clk) ops =clk_dev_ops (dev); clk->dev = dev; + clk->enable_count =0 ;Lukasz has taged Acked-by in v3.
Re: [PATCH v3 03/12] clk: Unconditionally recursively en-/dis-able clocksQuoted 6 lines
This patch shall be fixed and freeze.
But you add a new modification (Clearenable_counton request)in v5 and v6. Although it seem to look fine and nothing big deal.
I just highlight it here, and if Lukasz have no other comment further. I will pull it via riscv tree later.I have told you in v5, that this patch have conflict with u-boot/master please rebase it.
But it still conflict in v6.Quoted 12 lines
Applying: clk: Always use the supplied struct clk
Applying: clk: Check that ops of composite clock components exist before calling
Applying: clk: Unconditionally recursively en-/dis-able clocks
error: patch failed:drivers/clk/clk-uclass.c:522
error:drivers/clk/clk-uclass.c: patch does not apply
Patch failed at 0003 clk: Unconditionally recursively en-/dis-able clocks The copy of the patch that failed is found in: .git/rebase-apply/patch When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Quoted 2 lines
This was just rebased against u-boot/master. Should I be rebasing against a different branch? The commit I am working off is
It is just fine to sync with u-boot/master. Before I send a PR, I shall sync to u-boot/master too.
Thanks,
Rick
Quoted 128 lines
$ git show upstream/master commit 1efb9796f80e1394f080be1b4f3173ff108ad1f2 (upstream/master, upstream/WIP/03Mar2020, upstream/HEAD) Merge: 8aad16916d 9aa886cc0b Author: Tom Rini <[email protected]> Date: Tue Mar 3 21:48:49 2020 -0500Merge tag 'dm-pull-3mar20' of
git://git.denx.de/u-boot-dmFixes for power domain on device removal
Quoted 116 lines
Quoted 116 lines
Thanks,
RickQuoted 111 lines
drivers/clk/clk-uclass.c +26
-34if (!ops->request)return 0 ;@@ -522,7 +523,6 @@ int clk_set_parent(struct clk *clk, struct clk *parent)int clk_enable (struct clk *clk) {const struct clk_ops *ops; -struct clk *clkp =NULL ;int ret;debug ("%s(clk=%p \"%s\")\n" , __func__, clk, clk->dev->name);@@ -531,32 +531,29 @@ int clk_enable(struct clk *clk) ops =clk_dev_ops (clk->dev);if (CONFIG_IS_ENABLED (CLK_CCF )) { -/* Take id 0 as a non-valid clk, such as dummy */ -if (clk->id && !clk_get_by_id (clk->id, &clkp)) { -if (clkp->enable_count) { - clkp->enable_count++; -return 0 ; - } -if (clkp->dev->parent && -device_get_uclass_id (clkp->dev) ==UCLASS_CLK ) { - ret =clk_enable (dev_get_clk_ptr (clkp->dev->parent)); -if (ret) { -printf ("Enable %s failed\n" , - clkp->dev->parent->name); -return ret; - } +if (clk->enable_count) { + clk->enable_count++; +return 0 ; + } +if (clk->dev->parent && +device_get_uclass_id (clk->dev->parent) ==UCLASS_CLK ) { + ret =clk_enable (dev_get_clk_ptr (clk->dev->parent)); +if (ret) { +printf ("Enable %s failed\n" , + clk->dev->parent->name); +return ret; } }if (ops->enable) { ret = ops->enable (clk);if (ret) { -printf ("Enable %s failed\n" , clk->dev->name); +printf ("Enable %s failed (error %d)\n" , + clk->dev->name, ret);return ret; } } -if (clkp) - clkp->enable_count++; + clk->enable_count++; }else {if (!ops->enable)return -ENOSYS ;@@ -582,7 +579,6 @@ int clk_enable_bulk(struct clk_bulk *bulk)int clk_disable (struct clk *clk) {const struct clk_ops *ops; -struct clk *clkp =NULL ;int ret;debug ("%s(clk=%p)\n" , __func__, clk);@@ -591,29 +587,27 @@ int clk_disable(struct clk *clk) ops =clk_dev_ops (clk->dev);if (CONFIG_IS_ENABLED (CLK_CCF )) { -if (clk->id && !clk_get_by_id (clk->id, &clkp)) { -if (clkp->enable_count ==0 ) { -printf ("clk %s already disabled\n" , - clkp->dev->name); -return 0 ; - } - -if (--clkp->enable_count >0 ) -return 0 ; +if (clk->enable_count ==0 ) { +printf ("clk %s already disabled\n" , + clk->dev->name); +return 0 ; } +if (--clk->enable_count >0 ) +return 0 ; +if (ops->disable) { ret = ops->disable (clk);if (ret)return ret; } -if (clkp && clkp->dev->parent && -device_get_uclass_id (clkp->dev) ==UCLASS_CLK ) { - ret =clk_disable (dev_get_clk_ptr (clkp->dev->parent)); +if (clk->dev->parent && +device_get_uclass_id (clk->dev) ==UCLASS_CLK ) { + ret =clk_disable (dev_get_clk_ptr (clk->dev->parent));if (ret) { -printf ("Disable %s failed\n" , - clkp->dev->parent->name); +printf ("Disable %s failed (error %d)\n" , + clk->dev->parent->name, ret);return ret; } } --2.25.0
PATCH v6 3/19 clk: Unconditionally recursively en-/dis-able clocks
Quoted 22 lines · Rick Chen
Hi Sean
Quoted 21 lines · Rick Chen
Quoted 19 lines
Hi Sean
I have told you in v5, that this patch have conflict with u-boot/master please rebase it.
But it still conflict in v6.https://patchwork.ozlabs.org/patch/1246836/
Applying: clk: Always use the supplied struct clk
Applying: clk: Check that ops of composite clock components exist before calling
Applying: clk: Unconditionally recursively en-/dis-able clocks
error: patch failed:drivers/clk/clk-uclass.c:522
error:drivers/clk/clk-uclass.c: patch does not apply
Patch failed at 0003 clk: Unconditionally recursively en-/dis-able clocks The copy of the patch that failed is found in: .git/rebase-apply/patch When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Quoted 8 lines
Quoted 2 lines
This was just rebased against u-boot/master. Should I be rebasing against a different branch? The commit I am working off is
It is just fine to sync with u-boot/master. Before I send a PR, I shall sync to u-boot/master too.
Thanks,
Rick
I think I found the issue. I made a commit to add some more log messages to that file, and it seems to have changed the line numbers. Next patch I will rebase without that commit.
--Sean
PATCH v6 4/19 clk: Add functions to register CCF clock structs
In reply to Sean AndersonThis patch adds alternate versions of the clk_*_register functions for use with statically-allocated struct clks. This allows drivers to define clocks at compile-time and register them at run-time without malloc-ing. This increases the size of the binary, but should not affect ram usage (since the clocks now no longer live on the heap).
---
Changes in v5:
- New
drivers/clk/clk-composite.c | 103 +++++++++++++++++++---------------- drivers/clk/clk-divider.c | 56 +++++++++---------- drivers/clk/clk-gate.c | 38 ++++++++----- include/linux/clk-provider.h | 9 +++ 4 files changed, 112 insertions(+), 94 deletions(-)
drivers/clk/clk-composite.c +55 -48
@@ -95,6 +95,51 @@ static int clk_composite_disable(struct clk *clk)return 0 ; } +struct clk *clk_register_composite_struct (const char *name, +const char *const *parent_names, +int num_parents, +struct clk_composite *composite) +{ +int ret; +struct clk *clk; + +if (!num_parents || (num_parents !=1 && !composite->mux)) +return ERR_PTR (-EINVAL ); + +if (composite->mux && composite->mux_ops) + composite->mux->data = (ulong )composite; + +if (composite->rate && composite->rate_ops) { +if (!composite->rate_ops->get_rate) +return ERR_PTR (-EINVAL ); + + composite->rate->data = (ulong )composite; + } + +if (composite->gate && composite->gate_ops) { +if (!composite->gate_ops->enable || + !composite->gate_ops->disable) +return ERR_PTR (-EINVAL ); + + composite->gate->data = (ulong )composite; + } + + clk = &composite->clk; + ret =clk_register (clk,UBOOT_DM_CLK_COMPOSITE , name, + parent_names[clk_composite_get_parent (clk)]); +if (ret) + clk =ERR_PTR (ret); + +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; +} + struct clk *clk_register_composite(struct device *dev, const char *name, const char * const *parent_names, int num_parents, struct clk *mux,
@@ -107,62 +152,24 @@ struct clk *clk_register_composite(struct device *dev, const char *name, {struct clk *clk;struct clk_composite *composite; -int ret; - -if (!num_parents || (num_parents !=1 && !mux)) -return ERR_PTR (-EINVAL ); composite =kzalloc (sizeof (*composite),GFP_KERNEL );if (!composite)return ERR_PTR (-ENOMEM ); -if (mux && mux_ops) { - composite->mux = mux; - composite->mux_ops = mux_ops; - mux->data = (ulong )composite; - } + composite->mux = mux; + composite->mux_ops = mux_ops; -if (rate && rate_ops) { -if (!rate_ops->get_rate) { - clk =ERR_PTR (-EINVAL ); - goto err; - } + composite->rate = rate; + composite->rate_ops = rate_ops; - composite->rate = rate; - composite->rate_ops = rate_ops; - rate->data = (ulong )composite; - } + composite->gate = gate; + composite->gate_ops = gate_ops; -if (gate && gate_ops) { -if (!gate_ops->enable || !gate_ops->disable) { - clk =ERR_PTR (-EINVAL ); - goto err; - } - - composite->gate = gate; - composite->gate_ops = gate_ops; - gate->data = (ulong )composite; - } - - clk = &composite->clk; - ret =clk_register (clk,UBOOT_DM_CLK_COMPOSITE , name, - parent_names[clk_composite_get_parent (clk)]); -if (ret) { - clk =ERR_PTR (ret); - 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: -kfree (composite); + clk =clk_register_composite_struct (name, parent_names, num_parents, + composite); +if (IS_ERR (clk)) +kfree (composite);return clk; }
drivers/clk/clk-divider.c +25 -31
81 lines not on this page · raw message
drivers/clk/clk-gate.c +23 -15
@@ -111,6 +111,27 @@ const struct clk_ops clk_gate_ops = { .get_rate = clk_generic_get_rate, }; +struct clk *clk_register_gate_struct (const char *name,const char *parent_name, +struct clk_gate *gate) +{ +int ret; +struct clk *clk; + +if (gate->flags &CLK_GATE_HIWORD_MASK ) { +if (gate->bit_idx >15 ) { +pr_err ("gate bit exceeds LOWORD field\n" ); +return ERR_PTR (-EINVAL ); + } + } + + clk = &gate->clk; + + ret =clk_register (clk,UBOOT_DM_CLK_GATE , name, parent_name); +if (ret) +return ERR_PTR (ret); +return clk; +} + struct clk *clk_register_gate(struct device *dev, const char *name, const char *parent_name, unsigned long flags, void __iomem *reg, u8 bit_idx,
@@ -118,14 +139,6 @@ struct clk *clk_register_gate(struct device *dev, const char *name, {struct clk_gate *gate;struct clk *clk; -int ret; - -if (clk_gate_flags &CLK_GATE_HIWORD_MASK ) { -if (bit_idx >15 ) { -pr_err ("gate bit exceeds LOWORD field\n" ); -return ERR_PTR (-EINVAL ); - } - }/* allocate the gate */ gate =kzalloc (sizeof (*gate),GFP_KERNEL );
@@ -140,14 +153,9 @@ struct clk *clk_register_gate(struct device *dev, const char *name, gate->io_gate_val = *(u32 *)reg;#endif - clk = &gate->clk; - - ret =clk_register (clk,UBOOT_DM_CLK_GATE , name, parent_name); -if (ret) { + clk =clk_register_gate_struct (name, parent_name, gate); +if (IS_ERR (clk))kfree (gate); -return ERR_PTR (ret); - } -return clk; }
include/linux/clk-provider.h +9 -0
@@ -95,6 +95,8 @@ struct clk *clk_register_gate(struct device *dev, const char *name, const char *parent_name, unsigned long flags, void __iomem *reg, u8 bit_idx, u8 clk_gate_flags, spinlock_t *lock); +struct clk *clk_register_gate_struct (const char *name,const char *parent_name, +struct clk_gate *gate);struct clk_div_table {unsigned int val;
@@ -166,6 +168,10 @@ struct clk *clk_register_composite(struct device *dev, const char *name, struct clk *rate_clk, const struct clk_ops *rate_ops, struct clk *gate_clk, const struct clk_ops *gate_ops, unsigned long flags); +struct clk *clk_register_composite_struct (const char *name, +const char *const *parent_names, +int num_parents, +struct clk_composite *composite);int clk_register (struct clk *clk,const char *drv_name,const char *name,const char *parent_name);
@@ -178,6 +184,9 @@ struct clk *clk_register_divider(struct device *dev, const char *name, const char *parent_name, unsigned long flags, void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags); +struct clk *clk_register_divider_struct (const char *name, +const char *parent_name, +struct clk_divider *div); struct clk *clk_register_mux(struct device *dev, const char *name, const char * const *parent_names, u8 num_parents,
Signature · 1 line
2.25.0
PATCH v6 4/19 clk: Add functions to register CCF clock structs
Hi Sean
Quoted 9 lines
This patch adds alternate versions of the clk_*_register functions for use with statically-allocated struct clks. This allows drivers to define clocks at compile-time and register them at run-time without malloc-ing. This increases the size of the binary, but should not affect ram usage (since the clocks now no longer live on the heap).
Signed-off-by Sean Anderson <[email protected]>---
This is a new patch since v5 and still lack of tag of MAINTAINERs. I will prefer to exclude it in the later pull request of riscv tree.
Thanks,
Rick
Quoted 326 lines
Changes in v5:
- Newdrivers/clk/clk-composite.c | 103 +++++++++++++++++++---------------- drivers/clk/clk-divider.c | 56 +++++++++---------- drivers/clk/clk-gate.c | 38 ++++++++----- include/linux/clk-provider.h | 9 +++ 4 files changed, 112 insertions(+), 94 deletions(-)drivers/clk/clk-composite.c +55
-48@@ -95,6 +95,51 @@ static int clk_composite_disable(struct clk *clk)return 0 ; } +struct clk *clk_register_composite_struct (const char *name, +const char *const *parent_names, +int num_parents, +struct clk_composite *composite) +{ +int ret; +struct clk *clk; + +if (!num_parents || (num_parents !=1 && !composite->mux)) +return ERR_PTR (-EINVAL ); + +if (composite->mux && composite->mux_ops) + composite->mux->data = (ulong )composite; + +if (composite->rate && composite->rate_ops) { +if (!composite->rate_ops->get_rate) +return ERR_PTR (-EINVAL ); + + composite->rate->data = (ulong )composite; + } + +if (composite->gate && composite->gate_ops) { +if (!composite->gate_ops->enable || + !composite->gate_ops->disable) +return ERR_PTR (-EINVAL ); + + composite->gate->data = (ulong )composite; + } + + clk = &composite->clk; + ret =clk_register (clk,UBOOT_DM_CLK_COMPOSITE , name, + parent_names[clk_composite_get_parent (clk)]); +if (ret) + clk =ERR_PTR (ret); + +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; +} + struct clk *clk_register_composite(struct device *dev, const char *name, const char * const *parent_names, int num_parents, struct clk *mux,@@ -107,62 +152,24 @@ struct clk *clk_register_composite(struct device *dev, const char *name, {struct clk *clk;struct clk_composite *composite; -int ret; - -if (!num_parents || (num_parents !=1 && !mux)) -return ERR_PTR (-EINVAL ); composite =kzalloc (sizeof (*composite),GFP_KERNEL );if (!composite)return ERR_PTR (-ENOMEM ); -if (mux && mux_ops) { - composite->mux = mux; - composite->mux_ops = mux_ops; - mux->data = (ulong )composite; - } + composite->mux = mux; + composite->mux_ops = mux_ops; -if (rate && rate_ops) { -if (!rate_ops->get_rate) { - clk =ERR_PTR (-EINVAL ); - goto err; - } + composite->rate = rate; + composite->rate_ops = rate_ops; - composite->rate = rate; - composite->rate_ops = rate_ops; - rate->data = (ulong )composite; - } + composite->gate = gate; + composite->gate_ops = gate_ops; -if (gate && gate_ops) { -if (!gate_ops->enable || !gate_ops->disable) { - clk =ERR_PTR (-EINVAL ); - goto err; - } - - composite->gate = gate; - composite->gate_ops = gate_ops; - gate->data = (ulong )composite; - } - - clk = &composite->clk; - ret =clk_register (clk,UBOOT_DM_CLK_COMPOSITE , name, - parent_names[clk_composite_get_parent (clk)]); -if (ret) { - clk =ERR_PTR (ret); - 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: -kfree (composite); + clk =clk_register_composite_struct (name, parent_names, num_parents, + composite); +if (IS_ERR (clk)) +kfree (composite);return clk; }drivers/clk/clk-divider.c +25
-31@@ -178,22 +178,37 @@ const struct clk_ops clk_divider_ops = { .set_rate = clk_divider_set_rate, }; -static struct clk *_register_divider (struct device *dev,const char *name, -const char *parent_name,unsigned long flags, -void __iomem *reg,u8 shift,u8 width, -u8 clk_divider_flags,const struct clk_div_table *table) +struct clk *clk_register_divider_struct (const char *name, +const char *parent_name, +struct clk_divider *div) { -struct clk_divider *div; -struct clk *clk;int ret; +struct clk *clk; -if (clk_divider_flags &CLK_DIVIDER_HIWORD_MASK ) { -if (width + shift >16 ) { +if (div->flags &CLK_DIVIDER_HIWORD_MASK ) { +if (div->width + div->shift >16 ) {pr_warn ("divider value exceeds LOWORD field\n" );return ERR_PTR (-EINVAL ); } } +/* register the clock */ + clk = &div->clk; + + ret =clk_register (clk,UBOOT_DM_CLK_CCF_DIVIDER , name, parent_name); +if (ret) +return ERR_PTR (ret); +return clk; +} + +struct clk *clk_register_divider (struct device *dev,const char *name, +const char *parent_name,unsigned long flags, +void __iomem *reg,u8 shift,u8 width, +u8 clk_divider_flags) +{ +struct clk_divider *div; +struct clk *clk; +/* allocate the divider */ div =kzalloc (sizeof (*div),GFP_KERNEL );if (!div)@@ -204,34 +219,13 @@ static struct clk *_register_divider(struct device *dev, const char *name, div->shift = shift; div->width = width; div->flags = clk_divider_flags; - div->table = table;#if CONFIG_IS_ENABLED (SANDBOX_CLK_CCF ) div->io_divider_val = *(u32 *)reg;#endif -/* register the clock */ - clk = &div->clk; - - ret =clk_register (clk,UBOOT_DM_CLK_CCF_DIVIDER , name, parent_name); -if (ret) { -kfree (div); -return ERR_PTR (ret); - } - -return clk; -} - -struct clk *clk_register_divider (struct device *dev,const char *name, -const char *parent_name,unsigned long flags, -void __iomem *reg,u8 shift,u8 width, -u8 clk_divider_flags) -{ -struct clk *clk; - - clk =_register_divider (dev, name, parent_name, flags, reg, shift, - width, clk_divider_flags,NULL ); + clk =clk_register_divider_struct (name, parent_name, div);if (IS_ERR (clk)) -return ERR_CAST (clk); +kfree (div);return clk; }drivers/clk/clk-gate.c +23
-15@@ -111,6 +111,27 @@ const struct clk_ops clk_gate_ops = { .get_rate = clk_generic_get_rate, }; +struct clk *clk_register_gate_struct (const char *name,const char *parent_name, +struct clk_gate *gate) +{ +int ret; +struct clk *clk; + +if (gate->flags &CLK_GATE_HIWORD_MASK ) { +if (gate->bit_idx >15 ) { +pr_err ("gate bit exceeds LOWORD field\n" ); +return ERR_PTR (-EINVAL ); + } + } + + clk = &gate->clk; + + ret =clk_register (clk,UBOOT_DM_CLK_GATE , name, parent_name); +if (ret) +return ERR_PTR (ret); +return clk; +} + struct clk *clk_register_gate(struct device *dev, const char *name, const char *parent_name, unsigned long flags, void __iomem *reg, u8 bit_idx,@@ -118,14 +139,6 @@ struct clk *clk_register_gate(struct device *dev, const char *name, {struct clk_gate *gate;struct clk *clk; -int ret; - -if (clk_gate_flags &CLK_GATE_HIWORD_MASK ) { -if (bit_idx >15 ) { -pr_err ("gate bit exceeds LOWORD field\n" ); -return ERR_PTR (-EINVAL ); - } - }/* allocate the gate */ gate =kzalloc (sizeof (*gate),GFP_KERNEL );@@ -140,14 +153,9 @@ struct clk *clk_register_gate(struct device *dev, const char *name, gate->io_gate_val = *(u32 *)reg;#endif - clk = &gate->clk; - - ret =clk_register (clk,UBOOT_DM_CLK_GATE , name, parent_name); -if (ret) { + clk =clk_register_gate_struct (name, parent_name, gate); +if (IS_ERR (clk))kfree (gate); -return ERR_PTR (ret); - } -return clk; }include/linux/clk-provider.h +9
-1@@ -95,6 +95,8 @@ struct clk *clk_register_gate(struct device *dev, const char *name, const char *parent_name, unsigned long flags, void __iomem *reg, u8 bit_idx, u8 clk_gate_flags, spinlock_t *lock); +struct clk *clk_register_gate_struct (const char *name,const char *parent_name, +struct clk_gate *gate);struct clk_div_table {unsigned int val;@@ -166,6 +168,10 @@ struct clk *clk_register_composite(struct device *dev, const char *name, struct clk *rate_clk, const struct clk_ops *rate_ops, struct clk *gate_clk, const struct clk_ops *gate_ops, unsigned long flags); +struct clk *clk_register_composite_struct (const char *name, +const char *const *parent_names, +int num_parents, +struct clk_composite *composite);int clk_register (struct clk *clk,const char *drv_name,const char *name,const char *parent_name);@@ -178,6 +184,9 @@ struct clk *clk_register_divider(struct device *dev, const char *name, const char *parent_name, unsigned long flags, void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags); +struct clk *clk_register_divider_struct (const char *name, +const char *parent_name, +struct clk_divider *div); struct clk *clk_register_mux(struct device *dev, const char *name, const char * const *parent_names, u8 num_parents, --2.25.0
PATCH v6 4/19 clk: Add functions to register CCF clock structs
Quoted 12 lines · Rick Chen
Hi Sean
Quoted 9 lines
This patch adds alternate versions of the clk_*_register functions for use with statically-allocated struct clks. This allows drivers to define clocks at compile-time and register them at run-time without malloc-ing. This increases the size of the binary, but should not affect ram usage (since the clocks now no longer live on the heap).
Signed-off-by Sean Anderson <[email protected]>---
Quoted 5 lines
This is a new patch since v5 and still lack of tag of MAINTAINERs. I will prefer to exclude it in the later pull request of riscv tree.
Thanks,
Rick
Lukas, can you comment one way or the other on this?
Thanks,
Sean
PATCH v6 5/19 clk: Add K210 pll support
In reply to Sean AndersonThis 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.
---
Changes in v6:
- Reformat code to reduce checkpatch errors
Changes in v5:
- Add function to register from a struct
Changes in v4:
- Rename the reference clock to "divider clock", and input clock to "reference clock" to match the upstream documentation.
- Add a test for calc_params. This currently resides in test/dm, but perhaps it should be moved to its own directory.
- Update MAINTAINERS
- Update copyright
- Lint
Changes in v3:
- Add an option to not include support for setting the pll rate. This saves around 1K in the final executable.
- Remove udelays to suppress warnings
- Bypass PLL after enabling, instead of before
- Check if the PLL is enabled already before doing a reset
- Fix bug with locked mask
Changes in v2:
- Rename driver to "k210_clk_pll"
- Add additional in-line documentation on algorithm and PLLs
- Restrict the range of internal VCO and reference frequencies
- Don't load driver before relocation
- Remove spurious references to mach-k210
drivers/clk/Kconfig | 1 + drivers/clk/Makefile | 1 + drivers/clk/kendryte/Kconfig | 12 + drivers/clk/kendryte/Makefile | 1 + drivers/clk/kendryte/pll.c | 601 ++++++++++++++++++++++++++++++++++ include/kendryte/pll.h | 57 ++++ include/test/export.h | 16 + test/dm/Makefile | 1 + test/dm/k210_pll.c | 96 ++++++ 9 files changed, 786 insertions(+) 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 include/kendryte/pll.h create mode 100644 include/test/export.h create mode 100644 test/dm/k210_pll.c
drivers/clk/Kconfig +1 -0
@@ -155,6 +155,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
@@ -27,6 +27,7 @@ obj-$(CONFIG_CLK_BOSTON) += clk_boston.o obj-$(CONFIG_CLK_EXYNOS) += exynos/ obj-$(CONFIG_$(SPL_TPL_)CLK_INTEL) += intel/ 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 +12 -0
@@ -0,0 +1,12 @@ +config CLK_K210 + bool "Clock support for Kendryte K210" + depends on CLK && CLK_CCF + help + This enables support clock driver for Kendryte K210 platforms. + +config CLK_K210_SET_RATE + bool "Enable setting the Kendryte K210 PLL rate" + depends on CLK_K210 + help + Add functionality to calculate new rates for K210 PLLs. Enabling this + feature adds around 1K to U-Boot's final size.
drivers/clk/kendryte/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-y += pll.o
drivers/clk/kendryte/pll.c new file +601 -0
601 lines not on this page · raw message
include/kendryte/pll.h new file +57 -0
57 lines not on this page · raw message
include/test/export.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2020 Sean Anderson <[email protected]> +*/ + +#ifndef TEST_EXPORT_H +#define TEST_EXPORT_H + +/* Declare something static, unless we are doing unit tests */ +#ifdef CONFIG_UNIT_TEST +#define TEST_STATIC +#else +#define TEST_STATIC static +#endif + +#endif /* TEST_EXPORT_H */
test/dm/Makefile +1 -0
@@ -70,4 +70,5 @@ obj-$(CONFIG_DMA) += dma.o obj-$(CONFIG_DM_MDIO) += mdio.o obj-$(CONFIG_DM_MDIO_MUX) += mdio_mux.o obj-$(CONFIG_DM_RNG) += rng.o +obj-$(CONFIG_CLK_K210_SET_RATE) += k210_pll.o endif
test/dm/k210_pll.c new file +96 -0
96 lines not on this page · raw message
Signature · 1 line
2.25.0
PATCH v6 6/19 clk: Add a bypass clock for K210
In reply to Sean AndersonThis is a small driver to do a software bypass of a clock if hardware bypass is not working. I have tried to write this in a generic fashion, so that it could be potentially broken out of the kendryte code at some future date. For the K210, it is used to have aclk bypass pll0 and use in0 instead so that the CPU keeps on working.
---
Changes in v5:
- Add function to register from a struct bypass
Changes in v4:
- New
drivers/clk/kendryte/Makefile | 2 +- drivers/clk/kendryte/bypass.c | 270 ++++++++++++++++++++++++++++++++++ include/kendryte/bypass.h | 31 ++++ 3 files changed, 302 insertions(+), 1 deletion(-) create mode 100644 drivers/clk/kendryte/bypass.c create mode 100644 include/kendryte/bypass.h
drivers/clk/kendryte/Makefile +1 -1
@@ -1 +1 @@ -obj-y += pll.o +obj-y += bypass.o pll.o
drivers/clk/kendryte/bypass.c new file +270 -0
270 lines not on this page · raw message
include/kendryte/bypass.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2020 Sean Anderson <[email protected]> +*/ +#ifndef K210_BYPASS_H +#define K210_BYPASS_H + +#include <clk.h> + +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.25.0
PATCH v6 7/19 clk: Add K210 clock support
In reply to Sean AndersonDue to the large number of clocks, I decided to use the CCF. The overall structure is modeled after the imx code. Clocks are stored in several arrays. There are some translation macros (FOOIFY()) which allow for more dense packing. A possible improvement could be to only store the parameters we need, instead of the whole CCF struct.
---
Changes in v6:
- Reformat code so checkpatch generates fewer warnings
- Give "fictional" clocks their own ids
- Rename sysctl CLK_FREQ register to UART_BAUD to better reflect its semantics
Changes in v5:
- Don't unmap priv->reg
- Remove comment on APB clocks since it has been clarified by Kendryte
- Add i2s mclks
- Reorder clock ids to be continuous
- Rewrite to statically allocate all clocks. This has helped find several bugs (since it is easy to see when a clock has the wrong register).
- Fix ACLK sometimes having the wrong parent
- Fix SPI3 having the wrong divider
- Prevent being probed multiple times on failure
Changes in v4:
- Reparent aclk before configuring pll0
- Update copyright
- Lint
Changes in v3:
- Removed sysctl struct, replacing it with defines. This is to have the same interface to sysctl from C as from the device tree.
- Fixed clocks having the same id
- Fixed clocks not using the correct register/bits
- Aligned the defines in headers
Changes in v2:
- Add clk.o to obj-y
- Don't probe before relocation
MAINTAINERS | 7 + .../mfd/kendryte,k210-sysctl.txt | 33 ++ drivers/clk/kendryte/Kconfig | 2 +- drivers/clk/kendryte/Makefile | 2 +- drivers/clk/kendryte/clk.c | 489 ++++++++++++++++++ include/dt-bindings/clock/k210-sysctl.h | 59 +++ include/dt-bindings/mfd/k210-sysctl.h | 38 ++ include/kendryte/clk.h | 35 ++ 8 files changed, 663 insertions(+), 2 deletions(-) create mode 100644 doc/device-tree-bindings/mfd/kendryte,k210-sysctl.txt create mode 100644 drivers/clk/kendryte/clk.c create mode 100644 include/dt-bindings/clock/k210-sysctl.h create mode 100644 include/dt-bindings/mfd/k210-sysctl.h create mode 100644 include/kendryte/clk.h
MAINTAINERS +7 -0
@@ -807,6 +807,13 @@ F: arch/riscv/ F: cmd/riscv/ F: tools/prelink-riscv.c +RISC-V KENDRYTE +M: Sean Anderson <[email protected]> +S: Maintained +F: doc/device-tree-bindings/mfd/kendryte,k210-sysctl.txt +F: drivers/clk/kendryte/ +F: include/kendryte/ + RNG M: Sughosh Ganu <[email protected]> R: Heinrich Schuchardt <[email protected]>
doc/device-tree-bindings/mfd/kendryte,k210-sysctl.txt new file +33 -0
@@ -0,0 +1,33 @@ +Kendryte K210 Sysctl + +This binding describes the K210 sysctl device, which contains many miscellaneous +registers controlling system functionality. This node is a register map and can +be reference by other bindings which need a phandle to the K210 sysctl regmap. + +Required properties: +- compatible: should be + "kendryte,k210-sysctl", "syscon", "simple-mfd" +- reg: address and length of the sysctl registers +- reg-io-width: must be <4> + +Clock sub-node + +This node is a binding for the clock tree driver + +Required properties: +- compatible: should be "kendryte,k210-clk" +- clocks: phandle to the "in0" external oscillator +- #clock-cells: must be <1> + +Example: +sysctl: syscon at 50440000 { + compatible = "kendryte,k210-sysctl", "syscon", "simple-mfd"; + reg = <0x50440000 0x100>; + reg-io-width = <4>; + + sysclk: clock-controller { + compatible = "kendryte,k210-clk"; + clocks = <&in0>; + #clock-cells = <1>; + }; +};
drivers/clk/kendryte/Kconfig +1 -1
@@ -1,6 +1,6 @@ config CLK_K210 bool "Clock support for Kendryte K210" - depends on CLK && CLK_CCF + depends on CLK && CLK_CCF && CLK_COMPOSITE_CCF help This enables support clock driver for Kendryte K210 platforms.
drivers/clk/kendryte/Makefile +1 -1
@@ -1 +1 @@ -obj-y += bypass.o pll.o +obj-y += bypass.o clk.o pll.o
drivers/clk/kendryte/clk.c new file +489 -0
489 lines not on this page · raw message
include/dt-bindings/clock/k210-sysctl.h new file +59 -0
59 lines not on this page · raw message
include/dt-bindings/mfd/k210-sysctl.h new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2020 Sean Anderson <[email protected]> +*/ + +#ifndef K210_SYSCTL_H +#define K210_SYSCTL_H + +/* Taken from kendryte-standalone-sdk/lib/drivers/include/sysctl.h */ +#define K210_SYSCTL_GIT_ID 0x00/* Git short commit id */ +#define K210_SYSCTL_UART_BAUD 0x04/* Default UARTHS baud rate */ +#define K210_SYSCTL_PLL0 0x08/* PLL0 controller */ +#define K210_SYSCTL_PLL1 0x0C/* PLL1 controller */ +#define K210_SYSCTL_PLL2 0x10/* PLL2 controller */ +#define K210_SYSCTL_PLL_LOCK 0x18/* PLL lock tester */ +#define K210_SYSCTL_ROM_ERROR 0x1C/* AXI ROM detector */ +#define K210_SYSCTL_SEL0 0x20/* Clock select controller0 */ +#define K210_SYSCTL_SEL1 0x24/* Clock select controller1 */ +#define K210_SYSCTL_EN_CENT 0x28/* Central clock enable */ +#define K210_SYSCTL_EN_PERI 0x2C/* Peripheral clock enable */ +#define K210_SYSCTL_SOFT_RESET 0x30/* Soft reset ctrl */ +#define K210_SYSCTL_PERI_RESET 0x34/* Peripheral reset controller */ +#define K210_SYSCTL_THR0 0x38/* Clock threshold controller 0 */ +#define K210_SYSCTL_THR1 0x3C/* Clock threshold controller 1 */ +#define K210_SYSCTL_THR2 0x40/* Clock threshold controller 2 */ +#define K210_SYSCTL_THR3 0x44/* Clock threshold controller 3 */ +#define K210_SYSCTL_THR4 0x48/* Clock threshold controller 4 */ +#define K210_SYSCTL_THR5 0x4C/* Clock threshold controller 5 */ +#define K210_SYSCTL_THR6 0x50/* Clock threshold controller 6 */ +#define K210_SYSCTL_MISC 0x54/* Miscellaneous controller */ +#define K210_SYSCTL_PERI 0x58/* Peripheral controller */ +#define K210_SYSCTL_SPI_SLEEP 0x5C/* SPI sleep controller */ +#define K210_SYSCTL_RESET_STAT 0x60/* Reset source status */ +#define K210_SYSCTL_DMA_SEL0 0x64/* DMA handshake selector */ +#define K210_SYSCTL_DMA_SEL1 0x68/* DMA handshake selector */ +#define K210_SYSCTL_POWER_SEL 0x6C/* IO Power Mode Select controller */ + +#endif /* K210_SYSCTL_H */
include/kendryte/clk.h new file +35 -0
@@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2019-20 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 ); +} + +static inline struct clk *k210_clk_div (const char *name, +const char *parent_name, +void __iomem *reg,u8 shift,u8 width) +{ +return clk_register_divider (NULL , name, parent_name,0 , reg, shift, + width,0 ); +} + +#endif /* K210_CLK_H */
Signature · 1 line
2.25.0
PATCH v6 8/19 dm: Add support for simple-pm-bus
In reply to Sean AndersonThis type of bus is used in Linux to designate buses which have power domains and/or clocks which need to be enabled before their child devices can be used. Because power domains are automatically enabled before probing in U-Boot, we just need to enable any clocks present.
---
Changes in v5:
- Reorder includes (simple pm)
Changes in v4:
- Split the bus off into its own driver
- Add test
- Fix line spacing in Kconfig
- Lint
Changes in v3:
- New
arch/sandbox/dts/test.dts | 6 ++ arch/sandbox/include/asm/clk.h | 1 + configs/sandbox_defconfig | 1 + .../bus/simple-pm-bus.txt | 44 +++++++++++++++ drivers/core/Kconfig | 7 +++ drivers/core/Makefile | 1 + drivers/core/simple-pm-bus.c | 56 +++++++++++++++++++ test/dm/Makefile | 1 + test/dm/simple-pm-bus.c | 45 +++++++++++++++ 9 files changed, 162 insertions(+) create mode 100644 doc/device-tree-bindings/bus/simple-pm-bus.txt create mode 100644 drivers/core/simple-pm-bus.c create mode 100644 test/dm/simple-pm-bus.c
arch/sandbox/dts/test.dts +6 -0
@@ -934,6 +934,12 @@ mdio: mdio-test { compatible = "sandbox,mdio"; }; + + pm-bus-test { + compatible = "simple-pm-bus"; + clocks = <&clk_sandbox 4>; + power-domains = <&pwrdom 1>; + }; }; #include "sandbox_pmic.dtsi"
arch/sandbox/include/asm/clk.h +1 -0
@@ -21,6 +21,7 @@ enum sandbox_clk_id {SANDBOX_CLK_ID_I2C ,SANDBOX_CLK_ID_UART1 ,SANDBOX_CLK_ID_UART2 , +SANDBOX_CLK_ID_BUS , SANDBOX_CLK_ID_COUNT, };
configs/sandbox_defconfig +1 -0
@@ -90,6 +90,7 @@ CONFIG_REGMAP=y CONFIG_SYSCON=y CONFIG_DEVRES=y CONFIG_DEBUG_DEVRES=y +CONFIG_SIMPLE_PM_BUS=y CONFIG_ADC=y CONFIG_ADC_SANDBOX=y CONFIG_AXI=y
doc/device-tree-bindings/bus/simple-pm-bus.txt new file +44 -0
44 lines not on this page · raw message
drivers/core/Kconfig +7 -0
@@ -195,6 +195,13 @@ config SPL_SIMPLE_BUS Supports the 'simple-bus' driver, which is used on some systems in SPL. +config SIMPLE_PM_BUS + bool "Support simple-pm-bus driver" + depends on DM && OF_CONTROL && CLK && POWER_DOMAIN + help + Supports the 'simple-pm-bus' driver, which is used for busses that + have power domains and/or clocks which need to be enabled before use. + config OF_TRANSLATE bool "Translate addresses using fdt_translate_address" depends on DM && OF_CONTROL
drivers/core/Makefile +1 -0
@@ -6,6 +6,7 @@ obj-y += device.o fdtaddr.o lists.o root.o uclass.o util.o obj-$(CONFIG_DEVRES) += devres.o obj-$(CONFIG_$(SPL_)DM_DEVICE_REMOVE) += device-remove.o obj-$(CONFIG_$(SPL_)SIMPLE_BUS) += simple-bus.o +obj-$(CONFIG_SIMPLE_PM_BUS) += simple-pm-bus.o obj-$(CONFIG_DM) += dump.o obj-$(CONFIG_$(SPL_TPL_)REGMAP) += regmap.o obj-$(CONFIG_$(SPL_TPL_)SYSCON) += syscon-uclass.o
drivers/core/simple-pm-bus.c new file +56 -0
56 lines not on this page · raw message
test/dm/Makefile +1 -0
@@ -71,4 +71,5 @@ obj-$(CONFIG_DM_MDIO) += mdio.o obj-$(CONFIG_DM_MDIO_MUX) += mdio_mux.o obj-$(CONFIG_DM_RNG) += rng.o obj-$(CONFIG_CLK_K210_SET_RATE) += k210_pll.o +obj-$(CONFIG_SIMPLE_PM_BUS) += simple-pm-bus.o endif
test/dm/simple-pm-bus.c new file +45 -0
45 lines not on this page · raw message
Signature · 1 line
2.25.0
PATCH v6 9/19 dm: Fix error handling for dev_read_addr_ptr
In reply to Sean Andersondev_read_addr_ptr had different semantics depending on whether OF_LIVE was enabled. This patch converts both implementations to return NULL on error, and converts all call sites which check for FDT_ADDR_T_NONE to check for NULL instead. This patch also removes the call to map_physmem, since we have dev_remap_addr* for those semantics.
---
Changes in v5:
- New
drivers/clk/imx/clk-imx8mp.c | 2 +- drivers/core/read.c | 2 +- drivers/pinctrl/broadcom/pinctrl-bcm283x.c | 2 +- drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 2 +- include/dm/read.h | 4 +++- 5 files changed, 7 insertions(+), 5 deletions(-)
drivers/clk/imx/clk-imx8mp.c +1 -1
@@ -281,7 +281,7 @@ static int imx8mp_clk_probe(struct udevice *dev)clk_dm (IMX8MP_SYS_PLL2_1000M ,imx_clk_fixed_factor ("sys_pll2_1000m" ,"sys_pll2_out" ,1 ,1 )); base =dev_read_addr_ptr (dev); -if (base == (void *)FDT_ADDR_T_NONE ) +if (!base)return -EINVAL ;clk_dm (IMX8MP_CLK_A53_SRC ,imx_clk_mux2 ("arm_a53_src" , base +0x8000 ,24 ,3 , imx8mp_a53_sels,ARRAY_SIZE (imx8mp_a53_sels)));
drivers/core/read.c +1 -1
@@ -154,7 +154,7 @@ void *dev_read_addr_ptr(const struct udevice *dev) {fdt_addr_t addr =dev_read_addr (dev); -return (addr ==FDT_ADDR_T_NONE ) ?NULL :map_sysmem (addr,0 ); +return (addr ==FDT_ADDR_T_NONE ) ?NULL : addr; }void *dev_remap_addr (const struct udevice *dev)
drivers/pinctrl/broadcom/pinctrl-bcm283x.c +1 -1
@@ -116,7 +116,7 @@ int bcm283x_pinctl_probe(struct udevice *dev) } priv->base_reg =dev_read_addr_ptr (dev); -if (priv->base_reg == (void *)FDT_ADDR_T_NONE ) { +if (!priv->base_reg) {debug ("%s: Failed to get base address\n" , __func__);return -EINVAL ; }
drivers/pinctrl/mediatek/pinctrl-mtk-common.c +1 -1
@@ -630,7 +630,7 @@ int mtk_pinctrl_common_probe(struct udevice *dev,int ret; priv->base =dev_read_addr_ptr (dev); -if (priv->base == (void *)FDT_ADDR_T_NONE ) +if (!priv->base)return -EINVAL ; priv->soc = soc;
include/dm/read.h +3 -1
@@ -715,7 +715,9 @@ static inline fdt_addr_t dev_read_addr(const struct udevice *dev)static inline void *dev_read_addr_ptr (const struct udevice *dev) { -return devfdt_get_addr_ptr (dev); +void *addr =devfdt_get_addr_ptr (dev); + +return ((fdt_addr_t )addr ==FDT_ADDR_T_NONE ) ?NULL : addr; }static inline fdt_addr_t dev_read_addr_pci (const struct udevice *dev)
Signature · 1 line
2.25.0
PATCH v6 10/19 reset: Add generic reset driver
In reply to Sean AndersonThis patch adds a generic reset driver. It is designed to be useful when one has a register in a regmap which contains bits that reset other devices. I thought this seemed like a very generic use, so here is a generic driver. The overall structure has been modeled on the syscon-reboot driver.
---
Changes in v5:
- Reorder includes
- Include linux/err.h explicitly
Changes in v4:
- Added basic test
- Fix incorrect usage of regmap_update_bits
Changes in v3:
- New
arch/sandbox/dts/test.dts | 15 ++++ configs/sandbox_defconfig | 1 + .../reset/syscon-reset.txt | 36 +++++++++ drivers/reset/Kconfig | 5 ++ drivers/reset/Makefile | 1 + drivers/reset/reset-syscon.c | 80 +++++++++++++++++++ test/dm/Makefile | 1 + test/dm/syscon-reset.c | 58 ++++++++++++++ 8 files changed, 197 insertions(+) create mode 100644 doc/device-tree-bindings/reset/syscon-reset.txt create mode 100644 drivers/reset/reset-syscon.c create mode 100644 test/dm/syscon-reset.c
arch/sandbox/dts/test.dts +15 -0
@@ -940,6 +940,21 @@ clocks = <&clk_sandbox 4>; power-domains = <&pwrdom 1>; }; + + resetc2: syscon-reset { + compatible = "syscon-reset"; + #reset-cells = <1>; + regmap = <&syscon0>; + offset = <1>; + mask = <0x27FFFFFF>; + assert-high = <0>; + }; + + syscon-reset-test { + compatible = "sandbox,misc_sandbox"; + resets = <&resetc2 15>, <&resetc2 30>, <&resetc2 60>; + reset-names = "valid", "no_mask", "out_of_range"; + }; }; #include "sandbox_pmic.dtsi"
configs/sandbox_defconfig +1 -0
@@ -191,6 +191,7 @@ CONFIG_DM_RESET=y CONFIG_SANDBOX_RESET=y CONFIG_DM_RNG=y CONFIG_RNG_SANDBOX=y +CONFIG_RESET_SYSCON=y CONFIG_DM_RTC=y CONFIG_RTC_RV8803=y CONFIG_DEBUG_UART_SANDBOX=y
doc/device-tree-bindings/reset/syscon-reset.txt new file +36 -0
@@ -0,0 +1,36 @@ +Generic SYSCON mapped register reset driver + +This is a generic reset driver using syscon to map the reset register. +The reset is generally performed with a write to the reset register +defined by the register map pointed by syscon reference plus the offset and +shifted by the reset specifier/ + +To assert a reset on some device, the equivalent of the following operation is +performed, where reset_id is the reset specifier from the device's resets +property. + + if (BIT(reset_id) & mask) + regmap[offset][reset_id] = assert-high; + +Required properties: +- compatible: should contain "syscon-reset" +- #reset-cells: must be 1 +- regmap: this is phandle to the register map node +- offset: offset in the register map for the reboot register (in bytes) + +Optional properties: +- mask: accept only the reset specifiers defined by the mask (32 bit) +- assert-high: Bit to write when asserting a reset. Defaults to 1. + +Default will be little endian mode, 32 bit access only. + +Example: + + reset-controller { + compatible = "syscon-reset"; + #reset-cells = <1>; + regmap = <&sysctl>; + offset = <0x20>; + mask = <0x27FFFFFF>; + assert-high = <0>; + };
drivers/reset/Kconfig +5 -0
@@ -148,4 +148,9 @@ config RESET_IMX7 help Support for reset controller on i.MX7/8 SoCs. +config RESET_SYSCON + bool "Enable generic syscon reset driver support" + depends on DM_RESET + help + Support generic syscon mapped register reset devices. endmenu
drivers/reset/Makefile +1 -0
@@ -23,3 +23,4 @@ obj-$(CONFIG_RESET_MTMIPS) += reset-mtmips.o obj-$(CONFIG_RESET_SUNXI) += reset-sunxi.o obj-$(CONFIG_RESET_HISILICON) += reset-hisilicon.o obj-$(CONFIG_RESET_IMX7) += reset-imx7.o +obj-$(CONFIG_RESET_SYSCON) += reset-syscon.o
drivers/reset/reset-syscon.c new file +80 -0
80 lines not on this page · raw message
test/dm/Makefile +1 -0
@@ -72,4 +72,5 @@ obj-$(CONFIG_DM_MDIO_MUX) += mdio_mux.o obj-$(CONFIG_DM_RNG) += rng.o obj-$(CONFIG_CLK_K210_SET_RATE) += k210_pll.o obj-$(CONFIG_SIMPLE_PM_BUS) += simple-pm-bus.o +obj-$(CONFIG_RESET_SYSCON) += syscon-reset.o endif
test/dm/syscon-reset.c new file +58 -0
58 lines not on this page · raw message
Signature · 1 line
2.25.0
PATCH v6 11/19 lib: Always set errno in hcreate_r
In reply to Sean AndersonThis could give a confusing error message if it failed and didn't set errno.
---
Changes in v5:
- New
lib/hashtable.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
lib/hashtable.c +6 -2
@@ -109,8 +109,10 @@ int hcreate_r(size_t nel, struct hsearch_data *htab) }/* There is still another table active. Return with error. */ -if (htab->table !=NULL ) +if (htab->table !=NULL ) { +__set_errno (EINVAL );return 0 ; + }/* Change nel to the first prime number not smaller as nel. */ nel |=1 ;/* make odd */
@@ -123,8 +125,10 @@ int hcreate_r(size_t nel, struct hsearch_data *htab)/* allocate memory and zero out */ htab->table = (struct env_entry_node *)calloc (htab->size +1 ,sizeof (struct env_entry_node )); -if (htab->table ==NULL ) +if (htab->table ==NULL ) { +__set_errno (ENOMEM );return 0 ; + }/* everything went alright */ return 1 ;
Signature · 1 line
2.25.0
PATCH v6 12/19 riscv: Add headers for asm/global_data.h
In reply to Sean AndersonThis header depended on bd_t and ulong, but did not include the appropriate headers.
---
Changes in v4:
- Include compiler.h not linux/compiler.h
arch/riscv/include/asm/global_data.h | 2 ++ 1 file changed, 2 insertions(+)
arch/riscv/include/asm/global_data.h +2 -0
@@ -11,6 +11,8 @@#define __ASM_GBL_DATA_H#include <asm/smp.h> +#include <asm/u-boot.h> +#include <compiler.h> /* Architecture-specific global data */ struct arch_global_data {
Signature · 1 line
2.25.0
PATCH v6 13/19 riscv: Fix race conditions when initializing IPI
In reply to Sean AndersonThe IPI code could have race conditions in several places.
* Several harts could race on the value of gd->arch->clint/plic
* Non-boot harts could race with the main hart on the DM subsystem In addition, if an IPI was pending when U-Boot started, it would cause the IPI handler to jump to address 0.
To address these problems, a new function riscv_init_ipi is introduced. It is called once during arch_cpu_init_dm. Before this point, no riscv_*_ipi functions may be called. Access is synchronized by gd->arch->ipi_ready.
---
Changes in v6:
- Fix some formatting
- Clear IPIs before enabling interrupts instead of using a ipi_ready flag
- Only print messages on error in smp code
Changes in v5:
- New
arch/riscv/cpu/cpu.c | 6 ++++ arch/riscv/cpu/start.S | 2 ++ arch/riscv/include/asm/smp.h | 43 +++++++++++++++++++++++++++ arch/riscv/lib/andes_plic.c | 34 ++++++++------------- arch/riscv/lib/sbi_ipi.c | 5 ++++ arch/riscv/lib/sifive_clint.c | 33 +++++++-------------- arch/riscv/lib/smp.c | 56 ++++++++--------------------------- 7 files changed, 92 insertions(+), 87 deletions(-)
arch/riscv/cpu/cpu.c +6 -0
@@ -96,6 +96,12 @@ int arch_cpu_init_dm(void)csr_write (CSR_SATP ,0 ); } +#ifdef CONFIG_SMP + ret =riscv_init_ipi (); +if (ret) +return ret; +#endif +return 0 ; }
arch/riscv/cpu/start.S +2 -0
@@ -67,6 +67,8 @@ _start: #else li t0, SIE_SSIE #endif + /* Clear any pending IPIs */ + csrc MODE_PREFIX(ip), t0 csrs MODE_PREFIX(ie), t0 #endif
arch/riscv/include/asm/smp.h +43 -0
47 lines not on this page · raw message
arch/riscv/lib/andes_plic.c +12 -22
@@ -30,20 +30,6 @@#define SEND_IPI_TO_HART (hart) (0x80 >> (hart))DECLARE_GLOBAL_DATA_PTR ; -static int init_plic (void ); - -#define PLIC_BASE_GET (void) \ - do { \ - long *ret; \ - \ - if (!gd->arch.plic) { \ - ret = syscon_get_first_range(RISCV_SYSCON_PLIC); \ - if (IS_ERR(ret)) \ - return PTR_ERR(ret); \ - gd->arch.plic = ret; \ - init_plic(); \ - } \ - } while (0)static int enable_ipi (int hart) {
@@ -93,13 +79,21 @@ static int init_plic(void)return -ENODEV ; } +int riscv_init_ipi (void ) +{ +int ret =syscon_get_first_range (RISCV_SYSCON_PLIC ); + +if (IS_ERR (ret)) +return PTR_ERR (ret); + gd->arch.plic = ret; + +return init_plic (); +} +int riscv_send_ipi (int hart) { -unsigned int ipi; +unsigned int ipi = (SEND_IPI_TO_HART (hart) << (8 * gd->arch.boot_hart)); -PLIC_BASE_GET (); - - ipi = (SEND_IPI_TO_HART (hart) << (8 * gd->arch.boot_hart));writel (ipi, (void __iomem *)PENDING_REG (gd->arch.plic, gd->arch.boot_hart));
@@ -110,8 +104,6 @@ int riscv_clear_ipi(int hart) {u32 source_id; -PLIC_BASE_GET (); - source_id =readl ((void __iomem *)CLAIM_REG (gd->arch.plic, hart));writel (source_id, (void __iomem *)CLAIM_REG (gd->arch.plic, hart));
@@ -120,8 +112,6 @@ int riscv_clear_ipi(int hart)int riscv_get_ipi (int hart,int *pending) { -PLIC_BASE_GET (); - *pending =readl ((void __iomem *)PENDING_REG (gd->arch.plic, gd->arch.boot_hart)); *pending = !!(*pending &SEND_IPI_TO_HART (hart));
arch/riscv/lib/sbi_ipi.c +5 -0
@@ -7,6 +7,11 @@#include <common.h> #include <asm/sbi.h> +int riscv_init_ipi (void ) +{ +return 0 ; +} +int riscv_send_ipi (int hart) {ulong mask;
arch/riscv/lib/sifive_clint.c +11 -22
@@ -24,22 +24,8 @@DECLARE_GLOBAL_DATA_PTR ; -#define CLINT_BASE_GET (void) \ - do { \ - long *ret; \ - \ - if (!gd->arch.clint) { \ - ret = syscon_get_first_range(RISCV_SYSCON_CLINT); \ - if (IS_ERR(ret)) \ - return PTR_ERR(ret); \ - gd->arch.clint = ret; \ - } \ - } while (0) -int riscv_get_time (u64 *time) { -CLINT_BASE_GET (); - *time =readq ((void __iomem *)MTIME_REG (gd->arch.clint));return 0 ;
@@ -47,17 +33,24 @@ int riscv_get_time(u64 *time)int riscv_set_timecmp (int hart,u64 cmp) { -CLINT_BASE_GET (); -writeq (cmp, (void __iomem *)MTIMECMP_REG (gd->arch.clint, hart));return 0 ; } +int riscv_init_ipi (void ) +{ +long *ret =syscon_get_first_range (RISCV_SYSCON_CLINT ); + +if (IS_ERR (ret)) +return PTR_ERR (ret); + gd->arch.clint = ret; + +return 0 ; +} +int riscv_send_ipi (int hart) { -CLINT_BASE_GET (); -writel (1 , (void __iomem *)MSIP_REG (gd->arch.clint, hart));return 0 ;
@@ -65,8 +58,6 @@ int riscv_send_ipi(int hart)int riscv_clear_ipi (int hart) { -CLINT_BASE_GET (); -writel (0 , (void __iomem *)MSIP_REG (gd->arch.clint, hart));return 0 ;
@@ -74,8 +65,6 @@ int riscv_clear_ipi(int hart)int riscv_get_ipi (int hart,int *pending) { -CLINT_BASE_GET (); - *pending =readl ((void __iomem *)MSIP_REG (gd->arch.clint, hart));return 0 ;
arch/riscv/lib/smp.c +13 -43
79 lines not on this page · raw message
Signature · 1 line
2.25.0
PATCH v6 13/19 riscv: Fix race conditions when initializing IPI
Hi Sean
Quoted 10 lines
The IPI code could have race conditions in several places.
* Several harts could race on the value of gd->arch->clint/plic
* Non-boot harts could race with the main hart on the DM subsystem In addition, if an IPI was pending when U-Boot started, it would cause the IPI handler to jump to address 0.To address these problems, a new function
riscv_init_ipiis introduced. It is called once duringarch_cpu_init_dm. Before this point, no riscv_*_ipi functions may be called. Access is synchronized bygd->arch->ipi_ready.
Quoted 7 lines
Signed-off-by Sean Anderson <[email protected]>---
Can you try to clear mip/sip in startup flow before
secondary_hart_loop:
Maybe it can help to overcome the problem of callingriscv_clear_ipi()beforeriscv_init_ipi()that you added.
How is the verified result about trying to clear mip/sip in startup flow ? I have asked you twice in v5, but you still have no response about it.
[PATCH v5 27/33] riscv: Fix race conditions when initializing IPI
https://patchwork.ozlabs.org/patch/1246864/#2377119
Thanks
Rick
Quoted 348 lines
Changes in v6:
- Fix some formatting
- Clear IPIs before enabling interrupts instead of using aipi_readyflag
- Only print messages on error in smp codeChanges in v5:
- Newarch/riscv/cpu/cpu.c | 6 ++++ arch/riscv/cpu/start.S | 2 ++ arch/riscv/include/asm/smp.h | 43 +++++++++++++++++++++++++++ arch/riscv/lib/andes_plic.c | 34 ++++++++------------- arch/riscv/lib/sbi_ipi.c | 5 ++++ arch/riscv/lib/sifive_clint.c | 33 +++++++-------------- arch/riscv/lib/smp.c | 56 ++++++++--------------------------- 7 files changed, 92 insertions(+), 87 deletions(-)arch/riscv/cpu/cpu.c +6
-0@@ -96,6 +96,12 @@ int arch_cpu_init_dm(void)csr_write (CSR_SATP ,0 ); } +#ifdef CONFIG_SMP + ret =riscv_init_ipi (); +if (ret) +return ret; +#endif +return 0 ; }arch/riscv/cpu/start.S +2
-0@@ -67,6 +67,8 @@ _start: #else li t0, SIE_SSIE #endif + /* Clear any pending IPIs */ + csrc MODE_PREFIX(ip), t0 csrs MODE_PREFIX(ie), t0 #endifarch/riscv/include/asm/smp.h +43
-0@@ -51,4 +51,47 @@ void handle_ipi(ulong hart);*/ int smp_call_function (ulong addr,ulong arg0,ulong arg1,int wait); +/** +* riscv_init_ipi() - Initialize inter-process interrupt (IPI) driver +* +* Platform code must provide this function. This function is called once after +* the cpu driver is initialized. No other riscv_*_ipi() calls will be made +* before this function is called. +* +* @return 0 if OK, -ve on error +*/ +int riscv_init_ipi (void ); + +/** +* riscv_send_ipi() - Send inter-processor interrupt (IPI) +* +* Platform code must provide this function. +* +* @hart: Hart ID of receiving hart +* @return 0 if OK, -ve on error +*/ +int riscv_send_ipi (int hart); + +/** +* riscv_clear_ipi() - Clear inter-processor interrupt (IPI) +* +* Platform code must provide this function. +* +* @hart: Hart ID of hart to be cleared +* @return 0 if OK, -ve on error +*/ +int riscv_clear_ipi (int hart); + +/** +* riscv_get_ipi() - Get status of inter-processor interrupt (IPI) +* +* Platform code must provide this function. +* +* @hart: Hart ID of hart to be checked +* @pending: Pointer to variable with result of the check, +* 1 if IPI is pending, 0 otherwise +* @return 0 if OK, -ve on error +*/ +int riscv_get_ipi (int hart,int *pending); +#endif arch/riscv/lib/andes_plic.c +12
-22@@ -30,20 +30,6 @@#define SEND_IPI_TO_HART (hart) (0x80 >> (hart))DECLARE_GLOBAL_DATA_PTR ; -static int init_plic (void ); - -#define PLIC_BASE_GET (void) \ - do { \ - long *ret; \ - \ - if (!gd->arch.plic) { \ - ret = syscon_get_first_range(RISCV_SYSCON_PLIC); \ - if (IS_ERR(ret)) \ - return PTR_ERR(ret); \ - gd->arch.plic = ret; \ - init_plic(); \ - } \ - } while (0)static int enable_ipi (int hart) {@@ -93,13 +79,21 @@ static int init_plic(void)return -ENODEV ; } +int riscv_init_ipi (void ) +{ +int ret =syscon_get_first_range (RISCV_SYSCON_PLIC ); + +if (IS_ERR (ret)) +return PTR_ERR (ret); + gd->arch.plic = ret; + +return init_plic (); +} +int riscv_send_ipi (int hart) { -unsigned int ipi; +unsigned int ipi = (SEND_IPI_TO_HART (hart) << (8 * gd->arch.boot_hart)); -PLIC_BASE_GET (); - - ipi = (SEND_IPI_TO_HART (hart) << (8 * gd->arch.boot_hart));writel (ipi, (void __iomem *)PENDING_REG (gd->arch.plic, gd->arch.boot_hart));@@ -110,8 +104,6 @@ int riscv_clear_ipi(int hart) {u32 source_id; -PLIC_BASE_GET (); - source_id =readl ((void __iomem *)CLAIM_REG (gd->arch.plic, hart));writel (source_id, (void __iomem *)CLAIM_REG (gd->arch.plic, hart));@@ -120,8 +112,6 @@ int riscv_clear_ipi(int hart)int riscv_get_ipi (int hart,int *pending) { -PLIC_BASE_GET (); - *pending =readl ((void __iomem *)PENDING_REG (gd->arch.plic, gd->arch.boot_hart)); *pending = !!(*pending &SEND_IPI_TO_HART (hart));arch/riscv/lib/sbi_ipi.c +5
-0@@ -7,6 +7,11 @@#include <common.h> #include <asm/sbi.h> +int riscv_init_ipi (void ) +{ +return 0 ; +} +int riscv_send_ipi (int hart) {ulong mask;arch/riscv/lib/sifive_clint.c +11
-22@@ -24,22 +24,8 @@DECLARE_GLOBAL_DATA_PTR ; -#define CLINT_BASE_GET (void) \ - do { \ - long *ret; \ - \ - if (!gd->arch.clint) { \ - ret = syscon_get_first_range(RISCV_SYSCON_CLINT); \ - if (IS_ERR(ret)) \ - return PTR_ERR(ret); \ - gd->arch.clint = ret; \ - } \ - } while (0) -int riscv_get_time (u64 *time) { -CLINT_BASE_GET (); - *time =readq ((void __iomem *)MTIME_REG (gd->arch.clint));return 0 ;@@ -47,17 +33,24 @@ int riscv_get_time(u64 *time)int riscv_set_timecmp (int hart,u64 cmp) { -CLINT_BASE_GET (); -writeq (cmp, (void __iomem *)MTIMECMP_REG (gd->arch.clint, hart));return 0 ; } +int riscv_init_ipi (void ) +{ +long *ret =syscon_get_first_range (RISCV_SYSCON_CLINT ); + +if (IS_ERR (ret)) +return PTR_ERR (ret); + gd->arch.clint = ret; + +return 0 ; +} +int riscv_send_ipi (int hart) { -CLINT_BASE_GET (); -writel (1 , (void __iomem *)MSIP_REG (gd->arch.clint, hart));return 0 ;@@ -65,8 +58,6 @@ int riscv_send_ipi(int hart)int riscv_clear_ipi (int hart) { -CLINT_BASE_GET (); -writel (0 , (void __iomem *)MSIP_REG (gd->arch.clint, hart));return 0 ;@@ -74,8 +65,6 @@ int riscv_clear_ipi(int hart)int riscv_get_ipi (int hart,int *pending) { -CLINT_BASE_GET (); - *pending =readl ((void __iomem *)MSIP_REG (gd->arch.clint, hart));return 0 ;arch/riscv/lib/smp.c +13
-44@@ -12,38 +12,6 @@DECLARE_GLOBAL_DATA_PTR ; -/** -* riscv_send_ipi() - Send inter-processor interrupt (IPI) -* -* Platform code must provide this function. -* -* @hart: Hart ID of receiving hart -* @return 0 if OK, -ve on error -*/ -extern int riscv_send_ipi (int hart); - -/** -* riscv_clear_ipi() - Clear inter-processor interrupt (IPI) -* -* Platform code must provide this function. -* -* @hart: Hart ID of hart to be cleared -* @return 0 if OK, -ve on error -*/ -extern int riscv_clear_ipi (int hart); - -/** -* riscv_get_ipi() - Get status of inter-processor interrupt (IPI) -* -* Platform code must provide this function. -* -* @hart: Hart ID of hart to be checked -* @pending: Pointer to variable with result of the check, -* 1 if IPI is pending, 0 otherwise -* @return 0 if OK, -ve on error -*/ -extern int riscv_get_ipi (int hart,int *pending); -static int send_ipi_many (struct ipi_data *ipi,int wait) {ofnode node, cpus;@@ -114,7 +82,6 @@ void handle_ipi(ulong hart)return ;__smp_mb (); - smp_function = (void (*)(ulong ,ulong ,ulong ))gd->arch.ipi[hart].addr;invalidate_icache_all ();@@ -124,7 +91,13 @@ void handle_ipi(ulong hart)*/ ret =riscv_clear_ipi (hart);if (ret) { -pr_err ("Cannot clear IPI of hart %ld\n" , hart); +pr_err ("Cannot clear IPI of hart %ld (error %d)\n" , hart, ret); +return ; + } + +/* Sanity check */ +if (!smp_function) { +pr_err ("smp_function is NULL on hart %ld\n" , hart);return ; }@@ -133,14 +106,11 @@ void handle_ipi(ulong hart)int smp_call_function (ulong addr,ulong arg0,ulong arg1,int wait) { -int ret =0 ; -struct ipi_data ipi; +struct ipi_data ipi = { + .addr = addr, + .arg0 = arg0, + .arg1 = arg1, + }; - ipi.addr = addr; - ipi.arg0 = arg0; - ipi.arg1 = arg1; - - ret =send_ipi_many (&ipi, wait); - -return ret; +return send_ipi_many (&ipi, wait); } --2.25.0
PATCH v6 13/19 riscv: Fix race conditions when initializing IPI
Quoted 20 lines · Rick Chen
Hi Sean
Quoted 10 lines
The IPI code could have race conditions in several places.
* Several harts could race on the value of gd->arch->clint/plic
* Non-boot harts could race with the main hart on the DM subsystem In addition, if an IPI was pending when U-Boot started, it would cause the IPI handler to jump to address 0.To address these problems, a new function
riscv_init_ipiis introduced. It is called once duringarch_cpu_init_dm. Before this point, no riscv_*_ipi functions may be called. Access is synchronized bygd->arch->ipi_ready.Quoted 7 lines
Signed-off-by Sean Anderson <[email protected]>---
Can you try to clear mip/sip in startup flow before
secondary_hart_loop:
Maybe it can help to overcome the problem of callingriscv_clear_ipi()beforeriscv_init_ipi()that you added.
Quoted 8 lines
How is the verified result about trying to clear mip/sip in startup flow ? I have asked you twice in v5, but you still have no response about it.
[PATCH v5 27/33] riscv: Fix race conditions when initializing IPI
https://patchwork.ozlabs.org/patch/1246864/#2377119Thanks
Rick
I managed to get it working, and this patch incorporates that change. However, I forgot to update the commit message. The original issue I had was related to an accidental change to my config, and not to the clearing of MIP.
--Sean
PATCH v6 13/19 riscv: Fix race conditions when initializing IPI
Hi Sean
Quoted 27 lines · Rick Chen
Quoted 26 lines
Hi Sean
Quoted 10 lines
The IPI code could have race conditions in several places.
* Several harts could race on the value of gd->arch->clint/plic
* Non-boot harts could race with the main hart on the DM subsystem In addition, if an IPI was pending when U-Boot started, it would cause the IPI handler to jump to address 0.To address these problems, a new function
riscv_init_ipiis introduced. It is called once duringarch_cpu_init_dm. Before this point, no riscv_*_ipi functions may be called. Access is synchronized bygd->arch->ipi_ready.Quoted 7 lines
Signed-off-by Sean Anderson <[email protected]>---
Can you try to clear mip/sip in startup flow before
secondary_hart_loop:
Maybe it can help to overcome the problem of callingriscv_clear_ipi()beforeriscv_init_ipi()that you added.How is the verified result about trying to clear mip/sip in startup flow ? I have asked you twice in v5, but you still have no response about it.
[PATCH v5 27/33] riscv: Fix race conditions when initializing IPI
https://patchwork.ozlabs.org/patch/1246864/#2377119
Quoted 7 lines
Quoted 2 lines
Thanks
RickI managed to get it working, and this patch incorporates that change. However, I forgot to update the commit message. The original issue I had was related to an accidental change to my config, and not to the clearing of MIP.
So it is not a race condition issue, right ?
Maybe you shall split this into two patchs as below
patch 1
riscv: Clear pending ipi in start code
Describe that it can how and what it help to fix the problem you encounter more detail
e.g.
(Perhaps the prior stage sends an IPI but does not clear it) ...
patch 2
riscv: refine ipi initialize code flow
Describe that your motivation and intention more detail e.g.
I think the macro approach is a bit confusing,
since it's unclear at first glance what function
will be initializing the clint/plic.
Given U-Boot's otherwise completely SMP-unsafe design,
I think it's better to be explicit and conservative in these areas.
It can help us to roll back and debug in the future.
Thanks,
Rick
Quoted 2 lines
--Sean
PATCH v6 13/19 riscv: Fix race conditions when initializing IPI
Quoted 32 lines · Rick Chen
Hi Sean
Quoted 30 lines · Rick Chen
Quoted 28 lines
Hi Sean
Quoted 10 lines
The IPI code could have race conditions in several places.
* Several harts could race on the value of gd->arch->clint/plic
* Non-boot harts could race with the main hart on the DM subsystem In addition, if an IPI was pending when U-Boot started, it would cause the IPI handler to jump to address 0.To address these problems, a new function
riscv_init_ipiis introduced. It is called once duringarch_cpu_init_dm. Before this point, no riscv_*_ipi functions may be called. Access is synchronized bygd->arch->ipi_ready.Quoted 7 lines
Signed-off-by Sean Anderson <[email protected]>---
Can you try to clear mip/sip in startup flow before
secondary_hart_loop:
Maybe it can help to overcome the problem of callingriscv_clear_ipi()beforeriscv_init_ipi()that you added.How is the verified result about trying to clear mip/sip in startup flow ? I have asked you twice in v5, but you still have no response about it.
[PATCH v5 27/33] riscv: Fix race conditions when initializing IPI
https://patchwork.ozlabs.org/patch/1246864/#2377119Thanks
Rick
Quoted 6 lines
Quoted 4 lines
I managed to get it working, and this patch incorporates that change. However, I forgot to update the commit message. The original issue I had was related to an accidental change to my config, and not to the clearing of MIP.
So it is not a race condition issue, right ?
It is sort of a race condition? If the IP CSR is not cleared, then we can have a race condition.
Quoted 20 lines
Maybe you shall split this into two patchs as below
patch 1
riscv: Clear pending ipi in start code
Describe that it can how and what it help to fix the problem you encounter more detail
e.g.
(Perhaps the prior stage sends an IPI but does not clear it) ...patch 2
riscv: refine ipi initialize code flow
Describe that your motivation and intention more detail e.g.
I think the macro approach is a bit confusing,
since it's unclear at first glance what function
will be initializing the clint/plic.
Given U-Boot's otherwise completely SMP-unsafe design,
I think it's better to be explicit and conservative in these areas.
Quoted 4 lines
It can help us to roll back and debug in the future.
Thanks,
Rick
This will be split in the next revision.
Quoted 2 lines
Quoted 2 lines
--Sean
PATCH v6 14/19 riscv: Add option to support RISC-V privileged spec 1.9
In reply to Sean AndersonSome older processors (notably the Kendryte K210) use an older version of the RISC-V privileged specification. The primary changes between the old and new are in virtual memory, and in the merging of three separate counter enable CSRs. Using the new CSR on an old processor causes an illegal instruction exception. This patch adds an option to use the old CSRs instead of the new one.
---
Changes in v6:
- Reformat so chechpatch errors less
Changes in v5:
- Rename to 1.9 to reflect the spec as implemented by the k210
Changes in v4:
- Fixed CSRs not being defined properly (thanks bmeng)
- Added ifdefs for all changed CSRs (e.g. for VM)
- Also properly disable VM on boot
Changes in v3:
- Renamed from "riscv: Add option to disable writes to mcounteren"
- Added original functionality back for older priv specs.
Changes in v2:
- Moved forward in the patch series
arch/riscv/Kconfig | 10 +++++++++ arch/riscv/cpu/cpu.c | 9 ++++++++ arch/riscv/include/asm/csr.h | 40 ++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+)
arch/riscv/Kconfig +10 -0
@@ -225,6 +225,16 @@ config XIP config SHOW_REGS bool "Show registers on unhandled exception" +config RISCV_PRIV_1_9 + bool "Use version 1.9 of the RISC-V priviledged specification" + help + Older versions of the RISC-V priviledged specification had + separate counter enable CSRs for each privilege mode. Writing + to the unified mcounteren CSR on a processor implementing the + old specification will result in an illegal instruction + exception. In addition to counter CSR changes, the way virtual + memory is configured was also changed. + config STACK_SIZE_SHIFT int default 14
arch/riscv/cpu/cpu.c +9 -0
@@ -89,11 +89,20 @@ int arch_cpu_init_dm(void)* Enable perf counters for cycle, time, * and instret counters only */ +#ifdef CONFIG_RISCV_PRIV_1_9 +csr_write (CSR_MSCOUNTEREN ,GENMASK (2 ,0 )); +csr_write (CSR_MUCOUNTEREN ,GENMASK (2 ,0 )); +#else csr_write (CSR_MCOUNTEREN ,GENMASK (2 ,0 )); +#endif /* Disable paging */ if (supports_extension('s')) +#ifdef CONFIG_RISCV_PRIV_1_9 +csr_read_clear (CSR_MSTATUS ,SR_VM ); +#else csr_write (CSR_SATP ,0 ); +#endif }#ifdef CONFIG_SMP
arch/riscv/include/asm/csr.h +40 -0
@@ -15,7 +15,11 @@#define SR_SIE _AC(0x00000002, UL)/* Supervisor Interrupt Enable */ #define SR_SPIE _AC(0x00000020, UL)/* Previous Supervisor IE */ #define SR_SPP _AC(0x00000100, UL)/* Previously Supervisor */ +#ifdef CONFIG_RISCV_PRIV_1_9 +#define SR_PUM _AC(0x00040000, UL)/* Protect User Memory Access */ +#else #define SR_SUM _AC(0x00040000, UL)/* Supervisor User Memory Access */ +#endif #define SR_FS _AC(0x00006000, UL)/* Floating-point Status */ #define SR_FS_OFF _AC(0x00000000, UL)
@@ -29,6 +33,22 @@#define SR_XS_CLEAN _AC(0x00010000, UL)#define SR_XS_DIRTY _AC(0x00018000, UL) +#ifdef CONFIG_RISCV_PRIV_1_9 +#define SR_VM _AC(0x1F000000, UL)/* Virtualization Management */ +#define SR_VM_MODE_BARE _AC(0x00000000, UL)/* No translation or protection */ +#define SR_VM_MODE_BB _AC(0x01000000, UL)/* Single base-and-bound */ +/* Separate instruction and data base-and-bound */ +#define SR_VM_MODE_BBID _AC(0x02000000, UL) +#ifndef CONFIG_64BIT +#define SR_VM_MODE_32 _AC(0x08000000, UL) +#define SR_VM_MODE SR_VM_MODE_32 +#else +#define SR_VM_MODE_39 _AC(0x09000000, UL) +#define SR_VM_MODE_48 _AC(0x0A000000, UL) +#define SR_VM_MODE SR_VM_MODE_39 +#endif +#endif +#ifndef CONFIG_64BIT #define SR_SD _AC(0x80000000, UL)/* FS/XS dirty */ #else
@@ -36,6 +56,7 @@#endif /* SATP flags */ +#ifndef CONFIG_RISCV_PRIV_1_9 #ifndef CONFIG_64BIT #define SATP_PPN _AC(0x003FFFFF, UL)#define SATP_MODE_32 _AC(0x80000000, UL)
@@ -45,6 +66,7 @@#define SATP_MODE_39 _AC(0x8000000000000000, UL)#define SATP_MODE SATP_MODE_39#endif +#endif /* SCAUSE */ #define SCAUSE_IRQ_FLAG (_AC(1, UL) << (__riscv_xlen - 1))
@@ -88,17 +110,35 @@#define CSR_SCAUSE 0x142#define CSR_STVAL 0x143#define CSR_SIP 0x144 +#ifdef CONFIG_RISCV_PRIV_1_9 +#define CSR_SPTBR 0x180 +#else #define CSR_SATP 0x180 +#endif #define CSR_MSTATUS 0x300#define CSR_MISA 0x301#define CSR_MIE 0x304#define CSR_MTVEC 0x305 +#ifdef CONFIG_RISCV_PRIV_1_9 +#define CSR_MUCOUNTEREN 0x320 +#define CSR_MSCOUNTEREN 0x321 +#define CSR_MHCOUNTEREN 0x322 +#else #define CSR_MCOUNTEREN 0x306 +#endif #define CSR_MSCRATCH 0x340#define CSR_MEPC 0x341#define CSR_MCAUSE 0x342#define CSR_MTVAL 0x343#define CSR_MIP 0x344 +#ifdef CONFIG_RISCV_PRIV_1_9 +#define CSR_MBASE 0x380 +#define CSR_MBOUND 0x381 +#define CSR_MIBASE 0x382 +#define CSR_MIBOUND 0x383 +#define CSR_MDBASE 0x384 +#define CSR_MDBOUND 0x385 +#endif #define CSR_CYCLEH 0xc80#define CSR_TIMEH 0xc81#define CSR_INSTRETH 0xc82
Signature · 1 line
2.25.0
PATCH v6 15/19 riscv: Allow use of reset drivers
In reply to Sean AndersonCurrently, one cannot use a reset driver on RISC-V. Follow the MIPS example, and disable the default reset handler when the sysreset driver is enabled.
---
Changes in v3:
- New
arch/riscv/lib/reset.c | 2 ++ 1 file changed, 2 insertions(+)
arch/riscv/lib/reset.c +2 -0
@@ -7,6 +7,7 @@#include <command.h> #include <hang.h> +#ifndef CONFIG_SYSRESET int do_reset (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) {printf ("resetting ...\n" );
@@ -16,3 +17,4 @@ int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return 0; } +#endif
Signature · 1 line
2.25.0
PATCH v6 16/19 riscv: Try to get cpu frequency from a "clocks" node if it exists
In reply to Sean AndersonInstead of always using the "clock-frequency" property to determine cpu frequency, try using a clock in "clocks" if it exists. This patch also fixes a bug where there could be spurious higher frequencies if sizeof(u32) != sizeof(ulong).
---
This patch was previously sumbitted on its own as
https://patchwork.ozlabs.org/patch/1232420/
This patch is the combination of the patches
https://patchwork.ozlabs.org/patch/1223933/
https://patchwork.ozlabs.org/patch/1224957/
"riscv: Fix incorrect cpu frequency on RV64" "riscv: Try to get cpu frequency from device tree"
Changes in v5:
- Include linux/err.h explicitly
- Reword commit message
Changes in v4:
- New
drivers/cpu/riscv_cpu.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
drivers/cpu/riscv_cpu.c +18 -1
@@ -3,12 +3,14 @@* Copyright (C) 2018, Bin Meng <[email protected]> */ +#include <clk.h> #include <common.h> #include <cpu.h> #include <dm.h> #include <errno.h> #include <dm/device-internal.h> #include <dm/lists.h> +#include <linux/err.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -27,9 +29,24 @@ static int riscv_cpu_get_desc(struct udevice *dev, char *buf, int size)static int riscv_cpu_get_info (struct udevice *dev,struct cpu_info *info) { +int ret; +struct clk clk;const char *mmu; -dev_read_u32 (dev,"clock-frequency" , (u32 *)&info->cpu_freq); +/* Zero out the frequency, in case sizeof(ulong) != sizeof(u32) */ + info->cpu_freq =0 ; + +/* First try getting the frequency from the assigned clock */ + ret =clk_get_by_index (dev,0 , &clk); +if (!ret) { + ret =clk_get_rate (&clk); +if (!IS_ERR_VALUE (ret)) + info->cpu_freq = ret; +clk_free (&clk); + } + +if (!info->cpu_freq) +dev_read_u32 (dev,"clock-frequency" , (u32 *)&info->cpu_freq); mmu =dev_read_string (dev,"mmu-type" );if (!mmu)
Signature · 1 line
2.25.0
PATCH v6 17/19 riscv: Enable cpu clock if it is present
In reply to Sean AndersonThe cpu clock is probably already enabled if we are executing code (though we could be executing from a different core). This patch prevents the cpu clock or its parents from being disabled.
---
This patch was previously submitted on its own as
https://patchwork.ozlabs.org/patch/1232420/
Changes in v4:
- New
drivers/cpu/riscv_cpu.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/cpu/riscv_cpu.c +20 -0
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0+ /* * Copyright (C) 2018, Bin Meng <[email protected]> +* Copyright (C) 2020, Sean Anderson <[email protected]> */ #include <clk.h>
@@ -117,6 +118,24 @@ static int riscv_cpu_bind(struct udevice *dev)return 0 ; } +static int riscv_cpu_probe (struct udevice *dev) +{ +int ret =0 ; +struct clk clk; + +/* Get a clock if it exists */ + ret =clk_get_by_index (dev,0 , &clk); +if (ret) +return 0 ; + + ret =clk_enable (&clk); +clk_free (&clk); +if (ret == -ENOSYS || ret == -ENOTSUPP ) +return 0 ; +else +return ret; +} +static const struct cpu_ops riscv_cpu_ops = { .get_desc = riscv_cpu_get_desc, .get_info = riscv_cpu_get_info,
@@ -133,6 +152,7 @@ U_BOOT_DRIVER(riscv_cpu) = { .id = UCLASS_CPU, .of_match = riscv_cpu_ids, .bind = riscv_cpu_bind, + .probe = riscv_cpu_probe, .ops = &riscv_cpu_ops, .flags = DM_FLAG_PRE_RELOC, };
Signature · 1 line
2.25.0
PATCH v6 18/19 riscv: Add device tree for K210 and Sipeed Maix BitM
In reply to Sean AndersonWhere possible, I have tried to find compatible drivers based on the layout of registers. However, many devices remain untested. All untested devices have been left disabled, but some tentative properties (such as compatible strings, and clocks, interrupts, and resets properties) have been added.
---
Changes in v6:
- Remove spi, gpio, pinmux, wdt, and led bindings
- Use consistent capitalization for hex digits
Changes in v5:
- Add more compatible strings
- Add cache line size
- Document CPUs as rocket cores
- Flesh out the gpio devices
- Add ports for audio and video devices
- Add fpioa pinctrl support
- Configure pins for MMC on SPI1
- Enable MMC
- Fix a couple uart properties (Thanks laanwj)
- Reorder ram now that relocation is handled with CONFIG_SYS defines
- Enable WDT
- Add pinctrl properties
- Add gpio support
- Add led support
- Add assorted AV bindings
- Add compatible strings for ram
- Use GPIO-based CS for MMC
- Limit SPI flash to 50 MHz
Changes in v4:
- Set regs sizes to full address range
- Remove clock-frequency property from cpus
- Add spi-max-frequency to spi devices from documentation
- Add more compatible strings for each device
- Add AI ram as a separate memory bank. Its clock is disabled on boot, and it cannot be accessed
- Reorder memory banks so u-boot relocates higher, leaving more room to load boot images
- Add designware ssi CTRL0 field shifts to spi devices
- Don't enable the MMC slot
- Update copyright
- Lint
Changes in v3:
- Move this patch to the end of the series
- Add a max frequency for spi3
- Remov unused compatible strings from spi-flash at 0
- Add s and u to isa string
- Fix mmu-type
- Remove cache-line size since it is unused (in u-boot) and undocumented (upstream)
- Add timer interrupts to clint0
- Round up various registers
- Add riscv,max-priority to plic
- Add apb* busses, since they have clocks which need to be enabled to access their devices
- Change uart compatible strings to "snps,dw-apb-uart", since that appears to match their registers
- Add compatible string for wdt*
- Add system reset device under sysctl
- Add reset device under sysctl
Changes in v2:
- Model changed to "Sipeed Maix Bit" to match file name
- Value of stdout-path fixed
- SD card slot compatible changed to "mmc-spi-slot"
- "jedec,spi-nor" added to spi flash compatible list
- Aliases for spi busses added
- timebase-frequency divided by 50 to match timer speed
- cpu-frequency renamed to clock-frequency
- CPUX_intc restyled to cpuX_intc
- "kendryte,k210-soc" added to soc compatible list for future-proofing
- PLIC handle renamed to plic0 from pic0
- K210_RST_SOC removed from sysrst, due to not being located in the reset register
- K210_RST_* numbers changed to match their bit offset within the reset register
- gpio_controller restyled to gpio-controller
- Added a second clock to the dma binding to match what the driver expects
- Changed "snps,designware-spi" compatible string to "snps,dw-apb-ssi" to match the correct driver
- Added a name to the spi clocks
- Added reg-io-width property to spi bindings
- Assigned a default parent to K210_CLK_SPI3
- Removed assigned clocks for ACLK and PLLs
- Removed u-boot,dm-pre-reloc bindings
arch/riscv/dts/Makefile | 1 + arch/riscv/dts/k210-maix-bit.dts | 47 ++ arch/riscv/dts/k210.dtsi | 599 ++++++++++++++++++++++++ include/dt-bindings/reset/k210-sysctl.h | 38 ++ 4 files changed, 685 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/reset/k210-sysctl.h
arch/riscv/dts/Makefile +1 -0
@@ -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 +47 -0
47 lines not on this page · raw message
arch/riscv/dts/k210.dtsi new file +599 -0
599 lines not on this page · raw message
include/dt-bindings/reset/k210-sysctl.h new file +38 -0
@@ -0,0 +1,38 @@ +/* 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_ROM 0 +#define K210_RST_DMA 1 +#define K210_RST_AI 2 +#define K210_RST_DVP 3 +#define K210_RST_FFT 4 +#define K210_RST_GPIO 5 +#define K210_RST_SPI0 6 +#define K210_RST_SPI1 7 +#define K210_RST_SPI2 8 +#define K210_RST_SPI3 9 +#define K210_RST_I2S0 10 +#define K210_RST_I2S1 11 +#define K210_RST_I2S2 12 +#define K210_RST_I2C0 13 +#define K210_RST_I2C1 14 +#define K210_RST_I2C2 15 +#define K210_RST_UART1 16 +#define K210_RST_UART2 17 +#define K210_RST_UART3 18 +#define K210_RST_AES 19 +#define K210_RST_FPIOA 20 +#define K210_RST_TIMER0 21 +#define K210_RST_TIMER1 22 +#define K210_RST_TIMER2 23 +#define K210_RST_WDT0 24 +#define K210_RST_WDT1 25 +#define K210_RST_SHA 26 +#define K210_RST_RTC 29 + +#endif /* RESET_K210_SYSCTL_H */
Signature · 1 line
2.25.0
PATCH v6 18/19 riscv: Add device tree for K210 and Sipeed Maix BitM
Hi Sean
Quoted 90 lines
Where possible, I have tried to find compatible drivers based on the layout of registers. However, many devices remain untested. All untested devices have been left disabled, but some tentative properties (such as compatible strings, and clocks, interrupts, and resets properties) have been added.
Signed-off-by Sean Anderson <[email protected]>---
Changes in v6:
- Remove spi, gpio, pinmux, wdt, and led bindings
- Use consistent capitalization for hex digitsChanges in v5:
- Add more compatible strings
- Add cache line size
- Document CPUs as rocket cores
- Flesh out the gpio devices
- Add ports for audio and video devices
- Add fpioa pinctrl support
- Configure pins for MMC on SPI1
- Enable MMC
- Fix a couple uart properties (Thanks laanwj)
- Reorder ram now that relocation is handled withCONFIG_SYSdefines
- Enable WDT
- Add pinctrl properties
- Add gpio support
- Add led support
- Add assorted AV bindings
- Add compatible strings for ram
- Use GPIO-based CS for MMC
- Limit SPI flash to 50 MHzChanges in v4:
- Set regs sizes to full address range
- Remove clock-frequency property from cpus
- Add spi-max-frequency to spi devices from documentation
- Add more compatible strings for each device
- Add AI ram as a separate memory bank. Its clock is disabled on boot, and it cannot be accessed
- Reorder memory banks so u-boot relocates higher, leaving more room to load boot images
- Add designware ssi CTRL0 field shifts to spi devices
- Don't enable the MMC slot
- Update copyright
- LintChanges in v3:
- Move this patch to the end of the series
- Add a max frequency for spi3
- Remov unused compatible strings from spi-flash at 0
- Add s and u to isa string
- Fix mmu-type
- Remove cache-line size since it is unused (in u-boot) and undocumented (upstream)
- Add timer interrupts to clint0
- Round up various registers
- Add riscv,max-priority to plic
- Add apb* busses, since they have clocks which need to be enabled to access their devices
- Change uart compatible strings to "snps,dw-apb-uart", since that appears to match their registers
- Add compatible string for wdt*
- Add system reset device under sysctl
- Add reset device under sysctlChanges in v2:
- Model changed to "Sipeed Maix Bit" to match file name
- Value of stdout-path fixed
- SD card slot compatible changed to "mmc-spi-slot"
- "jedec,spi-nor" added to spi flash compatible list
- Aliases for spi busses added
- timebase-frequency divided by 50 to match timer speed
- cpu-frequency renamed to clock-frequency
-CPUX_intcrestyled tocpuX_intc
- "kendryte,k210-soc" added to soc compatible list for future-proofing
- PLIC handle renamed to plic0 from pic0
-K210_RST_SOCremoved from sysrst, due to not being located in the reset register
- K210_RST_* numbers changed to match their bit offset within the reset register
-gpio_controllerrestyled to gpio-controller
- Added a second clock to the dma binding to match what the driver expects
- Changed "snps,designware-spi" compatible string to "snps,dw-apb-ssi" to match the correct driver
- Added a name to the spi clocks
- Added reg-io-width property to spi bindings
- Assigned a default parent toK210_CLK_SPI3
- Removed assigned clocks for ACLK and PLLs
- Removed u-boot,dm-pre-reloc bindings
Quoted 4 lines
arch/riscv/dts/Makefile | 1 + arch/riscv/dts/k210-maix-bit.dts | 47 ++ arch/riscv/dts/k210.dtsi | 599 ++++++++++++++++++++++++ include/dt-bindings/reset/k210-sysctl.h | 38 ++
It is not proper to mix them in one patch.
Thanks,
Rick
Quoted 722 lines
4 files changed, 685 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/reset/k210-sysctl.harch/riscv/dts/Makefile +1
-0@@ -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 +47
-0@@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2019-20 Sean Anderson <[email protected]> + */ + +/dts-v1/; + +#include "k210.dtsi" + +#include <dt-bindings/gpio/gpio.h> + +/ { + model = "Sipeed Maix Bit 2.0"; + compatible = "sipeed,maix-bitm", "sipeed,maix-bit", "kendryte,k210"; + + chosen { + stdout-path = "serial0:115200"; + }; + + sound { + compatible = "simple-audio-card"; + simple-audio-card,format = "i2s"; + status = "disabled"; + + simple-audio-card,cpu { + sound-dai = <&i2s0 0>; + }; + + simple-audio-card,codec { + sound-dai = <&mic>; + }; + }; + + mic: mic { + #sound-dai-cells = <0>; + compatible = "memsensing,msm61s4030h0"; + status = "disabled"; + }; +}; + +&uarths0 { + status = "okay"; +}; + +&i2s0 { + #sound-dai-cells = <1>; +};arch/riscv/dts/k210.dtsi new file +599
-0@@ -0,0 +1,599 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2019-20 Sean Anderson <[email protected]> + */ + +#include <dt-bindings/clock/k210-sysctl.h> +#include <dt-bindings/mfd/k210-sysctl.h> +#include <dt-bindings/reset/k210-sysctl.h> + +/ { + /* + * Although the K210 is a 64-bit CPU, the address bus is only 32-bits + * wide, and the upper half of all addresses is ignored. + */ + #address-cells = <1>; + #size-cells = <1>; + compatible = "kendryte,k210"; + + aliases { + gpio0 = &gpio0; + gpio1 = &gpio1_0; + serial0 = &uarths0; + serial1 = &uart1; + serial2 = &uart2; + serial3 = &uart3; + spi0 = &spi0; + spi1 = &spi1; + spi2 = &spi2; + spi3 = &spi3; + }; + + clocks { + in0: osc { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <26000000>; + }; + }; + + cpus { + #address-cells = <1>; + #size-cells = <0>; + timebase-frequency = <7800000>; + cpu0: cpu at 0 { + device_type = "cpu"; + compatible = "kendryte,k210", "sifive,rocket0", "riscv"; + reg = <0>; + riscv,isa = "rv64imafdgc"; + mmu-type = "sv39"; + i-cache-block-size = <64>; + i-cache-size = <0x8000>; + d-cache-block-size = <64>; + d-cache-size = <0x8000>; + clocks = <&sysclk K210_CLK_CPU>; + cpu0_intc: interrupt-controller { + #interrupt-cells = <1>; + interrupt-controller; + compatible = "riscv,cpu-intc"; + }; + }; + cpu1: cpu at 1 { + device_type = "cpu"; + compatible = "kendryte,k210", "sifive,rocket0", "riscv"; + reg = <1>; + riscv,isa = "rv64imafdgc"; + mmu-type = "sv39"; + i-cache-block-size = <64>; + i-cache-size = <0x8000>; + d-cache-block-size = <64>; + d-cache-size = <0x8000>; + clocks = <&sysclk K210_CLK_CPU>; + cpu1_intc: interrupt-controller { + #interrupt-cells = <1>; + interrupt-controller; + compatible = "riscv,cpu-intc"; + }; + }; + }; + + sram0: memory at 80000000 { + device_type = "memory"; + compatible = "kendryte,k210-sram"; + reg = <0x80000000 0x400000>; + clocks = <&sysclk K210_CLK_SRAM0>; + }; + + sram1: memory at 80400000 { + device_type = "memory"; + reg = <0x80400000 0x200000>; + compatible = "kendryte,k210-sram"; + clocks = <&sysclk K210_CLK_SRAM1>; + }; + + airam: memory at 80600000 { + device_type = "memory"; + reg = <0x80600000 0x200000>; + compatible = "kendryte,k210-airam"; + clocks = <&sysclk K210_CLK_PLL1>; + }; + + reserved-memory { + #address-cells = <1>; + #size-cells = <1>; + ranges; + + ai_reserved: ai at 80600000 { + reg = <0x80600000 0x200000>; + reusable; + }; + }; + + soc { + #address-cells = <1>; + #size-cells = <1>; + compatible = "kendryte,k210-soc", "simple-bus"; + ranges; + interrupt-parent = <&plic0>; + + debug0: debug at 0 { + compatible = "kendryte,k210-debug", "riscv,debug"; + reg = <0x0 0x1000>; + }; + + rom0: nvmem at 1000 { + reg = <0x1000 0x1000>; + read-only; + }; + + clint0: interrupt-controller at 2000000 { + #interrupt-cells = <1>; + compatible = "kendryte,k210-clint", "riscv,clint0"; + reg = <0x2000000 0x1000>; + interrupt-controller; + interrupts-extended = <&cpu0_intc 3>, <&cpu0_intc 7>, + <&cpu1_intc 3>, <&cpu1_intc 7>; + clocks = <&sysclk K210_CLK_CPU>; + }; + + plic0: interrupt-controller at C000000 { + #interrupt-cells = <1>; + compatible = "kendryte,k210-plic", "riscv,plic0"; + reg = <0xC000000 0x4000000>; + interrupt-controller; + interrupts-extended = <&cpu0_intc 9>, <&cpu0_intc 11>, + <&cpu1_intc 9>, <&cpu1_intc 11>; + riscv,ndev = <65>; + riscv,max-priority = <7>; + }; + + uarths0: serial at 38000000 { + compatible = "kendryte,k210-uarths", "sifive,uart0"; + reg = <0x38000000 0x1000>; + interrupts = <33>; + clocks = <&sysclk K210_CLK_CPU>; + status = "disabled"; + }; + + gpio0: gpio-controller at 38001000 { + #interrupt-cells = <2>; + #gpio-cells = <2>; + compatible = "kendryte,k210-gpiohs", "sifive,gpio0"; + reg = <0x38001000 0x1000>; + interrupt-controller; + interrupts = <34 35 36 37 38 39 40 41 + 42 43 44 45 46 47 48 49 + 50 51 52 53 54 55 56 57 + 58 59 60 61 62 63 64 65>; + gpio-controller; + ngpios = <32>; + status = "disabled"; + }; + + kpu0: ai at 40800000 { + compatible = "kendryte,k210-ai"; + reg = <0x40800000 0xc00000>; + interrupts = <25>; + clocks = <&sysclk K210_CLK_AI>; + memory-region = <&ai_reserved>; + status = "disabled"; + }; + + fft0: fft at 42000000 { + compatible = "kendryte,k210-fft"; + reg = <0x42000000 0x400000>; + interrupts = <26>; + clocks = <&sysclk K210_CLK_FFT>; + resets = <&sysrst K210_RST_FFT>; + status = "disabled"; + }; + + dmac0: dma-controller at 50000000 { + compatible = "kendryte,k210-dmac", "snps,axi-dma-1.01a"; + reg = <0x50000000 0x1000>; + interrupts = <27 28 29 30 31 32>; + clocks = <&sysclk K210_CLK_DMA>, <&sysclk K210_CLK_DMA>; + clock-names = "core-clk", "cfgr-clk"; + resets = <&sysrst K210_RST_DMA>; + dma-channels = <6>; + snps,dma-masters = <2>; + snps,data-width = <5>; + snps,block-size = <0x400000 0x400000 0x400000 + 0x400000 0x400000 0x400000>; + snps,axi-max-burst-len = <256>; + status = "disabled"; + }; + + apb0: bus at 50200000 { + #address-cells = <1>; + #size-cells = <1>; + compatible = "kendryte,k210-apb", "simple-pm-bus"; + ranges; + clocks = <&sysclk K210_CLK_APB0>; + + gpio1: gpio-controller at 50200000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "kendryte,k210-gpio", + "snps,dw-apb-gpio"; + reg = <0x50200000 0x80>; + clocks = <&sysclk K210_CLK_GPIO>; + resets = <&sysrst K210_RST_GPIO>; + status = "disabled"; + + gpio1_0: gpio1 at 0 { + #gpio-cells = <2>; + #interrupt-cells = <2>; + compatible = "snps,dw-apb-gpio-port"; + reg = <0>; + interrupt-controller; + interrupts = <23>; + gpio-controller; + snps,nr-gpios = <8>; + }; + }; + + uart1: serial at 50210000 { + compatible = "kendryte,k210-uart", + "snps,dw-apb-uart"; + reg = <0x50210000 0x100>; + interrupts = <11>; + clocks = <&sysclk K210_CLK_UART1>; + resets = <&sysrst K210_RST_UART1>; + reg-io-width = <4>; + reg-shift = <2>; + dcd-override; + dsr-override; + cts-override; + ri-override; + status = "disabled"; + }; + + uart2: serial at 50220000 { + compatible = "kendryte,k210-uart", + "snps,dw-apb-uart"; + reg = <0x50220000 0x100>; + interrupts = <12>; + clocks = <&sysclk K210_CLK_UART2>; + resets = <&sysrst K210_RST_UART2>; + reg-io-width = <4>; + reg-shift = <2>; + dcd-override; + dsr-override; + cts-override; + ri-override; + status = "disabled"; + }; + + uart3: serial at 50230000 { + compatible = "kendryte,k210-uart", + "snps,dw-apb-uart"; + reg = <0x50230000 0x100>; + interrupts = <13>; + clocks = <&sysclk K210_CLK_UART3>; + resets = <&sysrst K210_RST_UART3>; + reg-io-width = <4>; + reg-shift = <2>; + dcd-override; + dsr-override; + cts-override; + ri-override; + status = "disabled"; + }; + + spi2: spi at 50240000 { + compatible = "kendryte,k120-spislave", + "snps,dw-apb-ssi"; + spi-slave; + reg = <0x50240000 0x100>; + interrupts = <2>; + clocks = <&sysclk K210_CLK_SPI2>; + resets = <&sysrst K210_RST_SPI2>; + spi-max-frequency = <25000000>; + /* + * Likely not the only offset change, but this + * is the only one which is documented. + */ + snps,tmod-offset = <8>; + status = "disabled"; + }; + + i2s0: i2s at 50250000 { + compatible = "kendryte,k210-i2s", + "snps,designware-i2s"; + reg = <0x50250000 0x200>; + interrupts = <5>; + clocks = <&sysclk K210_CLK_I2S0>; + clock-names = "i2sclk"; + resets = <&sysrst K210_RST_I2S0>; + status = "disabled"; + }; + + apu0: sound at 520250200 { + compatible = "kendryte,k210-apu"; + reg = <0x50250200 0x200>; + status = "disabled"; + }; + + i2s1: i2s at 50260000 { + compatible = "kendryte,k210-i2s", + "snps,designware-i2s"; + reg = <0x50260000 0x200>; + interrupts = <6>; + clocks = <&sysclk K210_CLK_I2S1>; + clock-names = "i2sclk"; + resets = <&sysrst K210_RST_I2S1>; + status = "disabled"; + }; + + i2s2: i2s at 50270000 { + compatible = "kendryte,k210-i2s", + "snps,designware-i2s"; + reg = <0x50270000 0x200>; + interrupts = <7>; + clocks = <&sysclk K210_CLK_I2S2>; + clock-names = "i2sclk"; + resets = <&sysrst K210_RST_I2S2>; + status = "disabled"; + }; + + i2c0: i2c at 50280000 { + compatible = "kendryte,k210-i2c", + "snps,designware-i2c"; + reg = <0x50280000 0x100>; + interrupts = <8>; + clocks = <&sysclk K210_CLK_I2C0>; + resets = <&sysrst K210_RST_I2C0>; + status = "disabled"; + }; + + i2c1: i2c at 50290000 { + compatible = "kendryte,k210-i2c", + "snps,designware-i2c"; + reg = <0x50290000 0x100>; + interrupts = <9>; + clocks = <&sysclk K210_CLK_I2C1>; + resets = <&sysrst K210_RST_I2C1>; + status = "disabled"; + }; + + i2c2: i2c at 502A0000 { + compatible = "kendryte,k210-i2c", + "snps,designware-i2c"; + reg = <0x502A0000 0x100>; + interrupts = <10>; + clocks = <&sysclk K210_CLK_I2C2>; + resets = <&sysrst K210_RST_I2C2>; + status = "disabled"; + }; + + fpioa: pinmux at 502B0000 { + compatible = "kendryte,k210-fpioa"; + reg = <0x502B0000 0x100>; + clocks = <&sysclk K210_CLK_FPIOA>; + resets = <&sysrst K210_RST_FPIOA>; + status = "disabled"; + }; + + sha256: sha256 at 502C0000 { + compatible = "kendryte,k210-sha256"; + reg = <0x502C0000 0x100>; + clocks = <&sysclk K210_CLK_SHA>; + resets = <&sysrst K210_RST_SHA>; + status = "disabled"; + }; + + timer0: timer at 502D0000 { + compatible = "kendryte,k210-timer", + "snps,dw-apb-timer"; + reg = <0x502D0000 0x100>; + interrupts = <14 15>; + clocks = <&sysclk K210_CLK_TIMER0>; + clock-names = "timer"; + resets = <&sysrst K210_RST_TIMER0>; + status = "disabled"; + }; + + timer1: timer at 502E0000 { + compatible = "kendryte,k210-timer", + "snps,dw-apb-timer"; + reg = <0x502E0000 0x100>; + interrupts = <16 17>; + clocks = <&sysclk K210_CLK_TIMER1>; + clock-names = "timer"; + resets = <&sysrst K210_RST_TIMER1>; + status = "disabled"; + }; + + timer2: timer at 502F0000 { + compatible = "kendryte,k210-timer", + "snps,dw-apb-timer"; + reg = <0x502F0000 0x100>; + interrupts = <18 19>; + clocks = <&sysclk K210_CLK_TIMER2>; + clock-names = "timer"; + resets = <&sysrst K210_RST_TIMER2>; + status = "disabled"; + }; + }; + + apb1: bus at 50400000 { + #address-cells = <1>; + #size-cells = <1>; + compatible = "kendryte,k210-apb", "simple-pm-bus"; + ranges; + clocks = <&sysclk K210_CLK_APB1>; + + wdt0: watchdog at 50400000 { + compatible = "kendryte,k210-wdt", "snps,dw-wdt"; + reg = <0x50400000 0x100>; + interrupts = <21>; + clocks = <&sysclk K210_CLK_WDT0>; + resets = <&sysrst K210_RST_WDT0>; + status = "disabled"; + }; + + wdt1: watchdog at 50410000 { + compatible = "kendryte,k210-wdt", "snps,dw-wdt"; + reg = <0x50410000 0x100>; + interrupts = <22>; + clocks = <&sysclk K210_CLK_WDT1>; + resets = <&sysrst K210_RST_WDT1>; + status = "disabled"; + }; + + otp0: nvmem at 50420000 { + #address-cells = <1>; + #size-cells = <1>; + compatible = "kendryte,k210-otp"; + reg = <0x50420000 0x100>, + <0x88000000 0x20000>; + reg-names = "reg", "mem"; + clocks = <&sysclk K210_CLK_ROM>; + resets = <&sysrst K210_RST_ROM>; + read-only; + status = "disabled"; + + /* Bootloader */ + firmware at 00000 { + reg = <0x00000 0xC200>; + }; + + /* + * config string as described in RISC-V + * privileged spec 1.9 + */ + config-1-9 at 1c000 { + reg = <0x1C000 0x1000>; + }; + + /* + * Device tree containing only registers, + * interrupts, and cpus + */ + fdt at 1d000 { + reg = <0x1D000 0x2000>; + }; + + /* CPU/ROM credits */ + credits at 1f000 { + reg = <0x1F000 0x1000>; + }; + }; + + dvp0: camera at 50430000 { + compatible = "kendryte,k210-dvp"; + reg = <0x50430000 0x100>; + interrupts = <24>; + clocks = <&sysclk K210_CLK_DVP>; + resets = <&sysrst K210_RST_DVP>; + status = "disabled"; + }; + + sysctl: syscon at 50440000 { + compatible = "kendryte,k210-sysctl", + "syscon", "simple-mfd"; + reg = <0x50440000 0x100>; + reg-io-width = <4>; + + sysclk: clock-controller { + #clock-cells = <1>; + compatible = "kendryte,k210-clk"; + clocks = <&in0>; + }; + + sysrst: reset-controller { + compatible = "kendryte,k210-rst", + "syscon-reset"; + #reset-cells = <1>; + regmap = <&sysctl>; + offset = <K210_SYSCTL_PERI_RESET>; + mask = <0x27FFFFFF>; + assert-high = <1>; + }; + + reboot { + compatible = "syscon-reboot"; + regmap = <&sysctl>; + offset = <K210_SYSCTL_SOFT_RESET>; + mask = <1>; + value = <1>; + }; + }; + + aes0: aes at 50450000 { + compatible = "kendryte,k210-aes"; + reg = <0x50450000 0x100>; + clocks = <&sysclk K210_CLK_AES>; + resets = <&sysrst K210_RST_AES>; + status = "disabled"; + }; + + rtc: rtc at 50460000 { + compatible = "kendryte,k210-rtc"; + reg = <0x50460000 0x100>; + clocks = <&in0>; + resets = <&sysrst K210_RST_RTC>; + interrupts = <20>; + status = "disabled"; + }; + }; + + apb2: bus at 52000000 { + #address-cells = <1>; + #size-cells = <1>; + compatible = "kendryte,k210-apb", "simple-pm-bus"; + ranges; + clocks = <&sysclk K210_CLK_APB2>; + + spi0: spi at 52000000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "kendryte,k210-spi", + "snps,dw-apb-ssi"; + reg = <0x52000000 0x100>; + interrupts = <1>; + clocks = <&sysclk K210_CLK_SPI0>; + clock-names = "ssi_clk"; + resets = <&sysrst K210_RST_SPI0>; + spi-max-frequency = <25000000>; + num-cs = <4>; + reg-io-width = <4>; + status = "disabled"; + }; + + spi1: spi at 53000000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "kendryte,k210-spi", + "snps,dw-apb-ssi"; + reg = <0x53000000 0x100>; + interrupts = <2>; + clocks = <&sysclk K210_CLK_SPI1>; + clock-names = "ssi_clk"; + resets = <&sysrst K210_RST_SPI1>; + spi-max-frequency = <25000000>; + num-cs = <4>; + reg-io-width = <4>; + status = "disabled"; + }; + + spi3: spi at 54000000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "kendryte,k210-spi", + "snps,dw-apb-ssi"; + reg = <0x54000000 0x200>; + interrupts = <4>; + clocks = <&sysclk K210_CLK_SPI3>; + clock-names = "ssi_clk"; + resets = <&sysrst K210_RST_SPI3>; + /* Could possibly go up to 200 MHz */ + spi-max-frequency = <100000000>; + num-cs = <4>; + reg-io-width = <4>; + status = "disabled"; + }; + }; + }; +};include/dt-bindings/reset/k210-sysctl.h new file +38
-1@@ -0,0 +1,38 @@ +/* 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_ROM 0 +#define K210_RST_DMA 1 +#define K210_RST_AI 2 +#define K210_RST_DVP 3 +#define K210_RST_FFT 4 +#define K210_RST_GPIO 5 +#define K210_RST_SPI0 6 +#define K210_RST_SPI1 7 +#define K210_RST_SPI2 8 +#define K210_RST_SPI3 9 +#define K210_RST_I2S0 10 +#define K210_RST_I2S1 11 +#define K210_RST_I2S2 12 +#define K210_RST_I2C0 13 +#define K210_RST_I2C1 14 +#define K210_RST_I2C2 15 +#define K210_RST_UART1 16 +#define K210_RST_UART2 17 +#define K210_RST_UART3 18 +#define K210_RST_AES 19 +#define K210_RST_FPIOA 20 +#define K210_RST_TIMER0 21 +#define K210_RST_TIMER1 22 +#define K210_RST_TIMER2 23 +#define K210_RST_WDT0 24 +#define K210_RST_WDT1 25 +#define K210_RST_SHA 26 +#define K210_RST_RTC 29 + +#endif /* RESET_K210_SYSCTL_H */ --2.25.0
PATCH v6 18/19 riscv: Add device tree for K210 and Sipeed Maix BitM
Quoted 92 lines · Rick Chen
Hi Sean
Quoted 90 lines
Where possible, I have tried to find compatible drivers based on the layout of registers. However, many devices remain untested. All untested devices have been left disabled, but some tentative properties (such as compatible strings, and clocks, interrupts, and resets properties) have been added.
Signed-off-by Sean Anderson <[email protected]>---
Changes in v6:
- Remove spi, gpio, pinmux, wdt, and led bindings
- Use consistent capitalization for hex digitsChanges in v5:
- Add more compatible strings
- Add cache line size
- Document CPUs as rocket cores
- Flesh out the gpio devices
- Add ports for audio and video devices
- Add fpioa pinctrl support
- Configure pins for MMC on SPI1
- Enable MMC
- Fix a couple uart properties (Thanks laanwj)
- Reorder ram now that relocation is handled withCONFIG_SYSdefines
- Enable WDT
- Add pinctrl properties
- Add gpio support
- Add led support
- Add assorted AV bindings
- Add compatible strings for ram
- Use GPIO-based CS for MMC
- Limit SPI flash to 50 MHzChanges in v4:
- Set regs sizes to full address range
- Remove clock-frequency property from cpus
- Add spi-max-frequency to spi devices from documentation
- Add more compatible strings for each device
- Add AI ram as a separate memory bank. Its clock is disabled on boot, and it cannot be accessed
- Reorder memory banks so u-boot relocates higher, leaving more room to load boot images
- Add designware ssi CTRL0 field shifts to spi devices
- Don't enable the MMC slot
- Update copyright
- LintChanges in v3:
- Move this patch to the end of the series
- Add a max frequency for spi3
- Remov unused compatible strings from spi-flash at 0
- Add s and u to isa string
- Fix mmu-type
- Remove cache-line size since it is unused (in u-boot) and undocumented (upstream)
- Add timer interrupts to clint0
- Round up various registers
- Add riscv,max-priority to plic
- Add apb* busses, since they have clocks which need to be enabled to access their devices
- Change uart compatible strings to "snps,dw-apb-uart", since that appears to match their registers
- Add compatible string for wdt*
- Add system reset device under sysctl
- Add reset device under sysctlChanges in v2:
- Model changed to "Sipeed Maix Bit" to match file name
- Value of stdout-path fixed
- SD card slot compatible changed to "mmc-spi-slot"
- "jedec,spi-nor" added to spi flash compatible list
- Aliases for spi busses added
- timebase-frequency divided by 50 to match timer speed
- cpu-frequency renamed to clock-frequency
-CPUX_intcrestyled tocpuX_intc
- "kendryte,k210-soc" added to soc compatible list for future-proofing
- PLIC handle renamed to plic0 from pic0
-K210_RST_SOCremoved from sysrst, due to not being located in the reset register
- K210_RST_* numbers changed to match their bit offset within the reset register
-gpio_controllerrestyled to gpio-controller
- Added a second clock to the dma binding to match what the driver expects
- Changed "snps,designware-spi" compatible string to "snps,dw-apb-ssi" to match the correct driver
- Added a name to the spi clocks
- Added reg-io-width property to spi bindings
- Assigned a default parent toK210_CLK_SPI3
- Removed assigned clocks for ACLK and PLLs
- Removed u-boot,dm-pre-reloc bindings
Quoted 6 lines
Quoted 4 lines
arch/riscv/dts/Makefile | 1 + arch/riscv/dts/k210-maix-bit.dts | 47 ++ arch/riscv/dts/k210.dtsi | 599 ++++++++++++++++++++++++ include/dt-bindings/reset/k210-sysctl.h | 38 ++It is not proper to mix them in one patch.
The bindings and the device trees?
Quoted 4 lines
Thanks,
Rick
--Sean
PATCH v6 18/19 riscv: Add device tree for K210 and Sipeed Maix BitM
Hi Sean
Quoted 93 lines · Rick Chen
Quoted 92 lines
Hi Sean
Quoted 90 lines
Where possible, I have tried to find compatible drivers based on the layout of registers. However, many devices remain untested. All untested devices have been left disabled, but some tentative properties (such as compatible strings, and clocks, interrupts, and resets properties) have been added.
Signed-off-by Sean Anderson <[email protected]>---
Changes in v6:
- Remove spi, gpio, pinmux, wdt, and led bindings
- Use consistent capitalization for hex digitsChanges in v5:
- Add more compatible strings
- Add cache line size
- Document CPUs as rocket cores
- Flesh out the gpio devices
- Add ports for audio and video devices
- Add fpioa pinctrl support
- Configure pins for MMC on SPI1
- Enable MMC
- Fix a couple uart properties (Thanks laanwj)
- Reorder ram now that relocation is handled withCONFIG_SYSdefines
- Enable WDT
- Add pinctrl properties
- Add gpio support
- Add led support
- Add assorted AV bindings
- Add compatible strings for ram
- Use GPIO-based CS for MMC
- Limit SPI flash to 50 MHzChanges in v4:
- Set regs sizes to full address range
- Remove clock-frequency property from cpus
- Add spi-max-frequency to spi devices from documentation
- Add more compatible strings for each device
- Add AI ram as a separate memory bank. Its clock is disabled on boot, and it cannot be accessed
- Reorder memory banks so u-boot relocates higher, leaving more room to load boot images
- Add designware ssi CTRL0 field shifts to spi devices
- Don't enable the MMC slot
- Update copyright
- LintChanges in v3:
- Move this patch to the end of the series
- Add a max frequency for spi3
- Remov unused compatible strings from spi-flash at 0
- Add s and u to isa string
- Fix mmu-type
- Remove cache-line size since it is unused (in u-boot) and undocumented (upstream)
- Add timer interrupts to clint0
- Round up various registers
- Add riscv,max-priority to plic
- Add apb* busses, since they have clocks which need to be enabled to access their devices
- Change uart compatible strings to "snps,dw-apb-uart", since that appears to match their registers
- Add compatible string for wdt*
- Add system reset device under sysctl
- Add reset device under sysctlChanges in v2:
- Model changed to "Sipeed Maix Bit" to match file name
- Value of stdout-path fixed
- SD card slot compatible changed to "mmc-spi-slot"
- "jedec,spi-nor" added to spi flash compatible list
- Aliases for spi busses added
- timebase-frequency divided by 50 to match timer speed
- cpu-frequency renamed to clock-frequency
-CPUX_intcrestyled tocpuX_intc
- "kendryte,k210-soc" added to soc compatible list for future-proofing
- PLIC handle renamed to plic0 from pic0
-K210_RST_SOCremoved from sysrst, due to not being located in the reset register
- K210_RST_* numbers changed to match their bit offset within the reset register
-gpio_controllerrestyled to gpio-controller
- Added a second clock to the dma binding to match what the driver expects
- Changed "snps,designware-spi" compatible string to "snps,dw-apb-ssi" to match the correct driver
- Added a name to the spi clocks
- Added reg-io-width property to spi bindings
- Assigned a default parent toK210_CLK_SPI3
- Removed assigned clocks for ACLK and PLLs
- Removed u-boot,dm-pre-reloc bindings
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
arch/riscv/dts/Makefile | 1 + arch/riscv/dts/k210-maix-bit.dts | 47 ++ arch/riscv/dts/k210.dtsi | 599 ++++++++++++++++++++++++ include/dt-bindings/reset/k210-sysctl.h | 38 ++It is not proper to mix them in one patch.
The bindings and the device trees?
Sorry, there are three k210-sysctl.h and I confuse them.
+#include <dt-bindings/clock/k210-sysctl.h>
+#include <dt-bindings/mfd/k210-sysctl.h>
+#include <dt-bindings/reset/k210-sysctl.h>
I thought it shall be put in [PATCH v6 07/19] clk: Add K210 clock support.
Please drop this suggestion.
Thanks,
Rick
Quoted 7 lines
Quoted 5 lines
Thanks,
Rick--Sean
PATCH v6 19/19 riscv: Add Sipeed Maix support
In reply to Sean AndersonThe 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>.
---
Changes in v6:
- Remove trailing whitespace from documentation
- Remove configuration for spi/pinmux/gpio features
- Flesh out documentation some more
Changes in v5:
- Configure relocation location with CONFIG_SYS_SDRAM_*
- Enable ram clocks
- Add pinmux/gpio/led support
- Remove (broken) MMC support
- Store the environment in flash
- Add partitions
- Add bootcmd
- Add docs for pinctrl and booting
Changes in v4:
- Rework documentation to be organized by board mfg not cpu mfg
- Update docs to reflect working SPI support
- Add proper spi support
- Don't define unneecessary macros in config.h
- Lower the default stack so it isn't clobbered on relocation
- Update MAINTAINERS
- Update copyright
Changes in v3:
- Reorder to be last in the patch series
- Add documentation for the board
- Generate defconfig with "make savedefconfig"
- Update Kconfig to imply most features we need
- Update MAINTAINERS
Changes in v2:
- Select CONFIG_SYS_RISCV_NOCOUNTER
- Imply CONFIG_CLK_K210
- Remove spurious references to CONFIG_ARCH_K210
- Remove many configs from defconfig where the defaults were fine
- Add a few "not set" lines to suppress unneeded defaults
- Reduce pre-reloc malloc space, now that clocks initialization happens later
arch/riscv/Kconfig | 4 + board/sipeed/maix/Kconfig | 48 +++++ board/sipeed/maix/MAINTAINERS | 11 ++ board/sipeed/maix/Makefile | 5 + board/sipeed/maix/maix.c | 54 ++++++ configs/sipeed_maix_bitm_defconfig | 8 + doc/board/index.rst | 1 + doc/board/sipeed/index.rst | 9 + doc/board/sipeed/maix.rst | 298 +++++++++++++++++++++++++++++ include/configs/sipeed-maix.h | 24 +++ 10 files changed, 462 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_defconfig create mode 100644 doc/board/sipeed/index.rst create mode 100644 doc/board/sipeed/maix.rst create mode 100644 include/configs/sipeed-maix.h
arch/riscv/Kconfig +4 -0
@@ -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 +48 -0
48 lines not on this page · raw message
board/sipeed/maix/MAINTAINERS new file +11 -0
@@ -0,0 +1,11 @@ +Sipeed Maix BOARD +M: Sean Anderson <[email protected]> +S: Maintained +F: arch/riscv/dts/k210.dtsi +F: arch/riscv/dts/k210-maix-bit.dts +F: board/sipeed/maix/ +F: configs/sipeed_maix_defconfig +F: doc/board/sipeed/ +F: include/configs/sipeed-maix.h +F: include/dt-bindings/*/k210-sysctl.h +F: test/dm/k210_pll.c
board/sipeed/maix/Makefile new file +5 -0
@@ -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 +54 -0
54 lines not on this page · raw message
configs/sipeed_maix_bitm_defconfig new file +8 -0
@@ -0,0 +1,8 @@ +CONFIG_RISCV=y +CONFIG_TARGET_SIPEED_MAIX=y +CONFIG_ARCH_RV64I=y +CONFIG_SYS_REDUNDAND_ENVIRONMENT=y +# CONFIG_NET is not set +# CONFIG_INPUT is not set +# CONFIG_DM_ETH is not set +# CONFIG_EFI_LOADER is not set
doc/board/index.rst +1 -0
@@ -16,5 +16,6 @@ Board-specific doc renesas/index rockchip/index sifive/index + sipeed/index st/index xilinx/index
doc/board/sipeed/index.rst new file +9 -0
@@ -0,0 +1,9 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +Sipeed +====== + +.. toctree:: + :maxdepth: 2 + + maix
doc/board/sipeed/maix.rst new file +298 -0
298 lines not on this page · raw message
include/configs/sipeed-maix.h new file +24 -0
@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2019-20 Sean Anderson <[email protected]> +*/ + +#ifndef CONFIGS_SIPEED_MAIX_H +#define CONFIGS_SIPEED_MAIX_H + +#include <linux/sizes.h> + +#define CONFIG_SYS_LOAD_ADDR 0x80000000 +/* Start just below the second bank so we don't clobber it during reloc */ +#define CONFIG_SYS_INIT_SP_ADDR 0x803FFFFF +#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 + +#endif /* CONFIGS_SIPEED_MAIX_H */
Signature · 1 line
2.25.0
PATCH v6 19/19 riscv: Add Sipeed Maix support
Hi Sean
Quoted 20 lines
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>.
Quoted 2 lines
Signed-off-by Sean Anderson <[email protected]>---
This patch applying fail
Applying: riscv: Add Sipeed Maix support
error: patch failed: doc/board/index.rst:16
error: doc/board/index.rst: patch does not apply
Patch failed at 0001 riscv: Add Sipeed Maix support
The copy of the patch that failed is found in: .git/rebase-apply/patch When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".
I have replied to you the same result in v5
[v5,33/33] riscv: Add Sipeed Maix support
https://patchwork.ozlabs.org/patch/1246869/#2376311
By the way,
you can not mix them (arch, board, configs, doc)together in a patch. arch/riscv/Kconfig
board/sipeed/maix/ ...
configs/sipeed_maix_bitm_defconfigdoc/board/index.rst
Thanks,
Rick
Quoted 602 lines
Changes in v6:
- Remove trailing whitespace from documentation
- Remove configuration for spi/pinmux/gpio features
- Flesh out documentation some moreChanges in v5:
- Configure relocation location with CONFIG_SYS_SDRAM_*
- Enable ram clocks
- Add pinmux/gpio/led support
- Remove (broken) MMC support
- Store the environment in flash
- Add partitions
- Add bootcmd
- Add docs for pinctrl and bootingChanges in v4:
- Rework documentation to be organized by board mfg not cpu mfg
- Update docs to reflect working SPI support
- Add proper spi support
- Don't define unneecessary macros inconfig.h
- Lower the default stack so it isn't clobbered on relocation
- UpdateMAINTAINERS
- Update copyrightChanges in v3:
- Reorder to be last in the patch series
- Add documentation for the board
- Generate defconfig with "make savedefconfig"
- UpdateKconfigto imply most features we need
- UpdateMAINTAINERSChanges in v2:
- SelectCONFIG_SYS_RISCV_NOCOUNTER
- ImplyCONFIG_CLK_K210
- Remove spurious references toCONFIG_ARCH_K210
- Remove many configs from defconfig where the defaults were fine
- Add a few "not set" lines to suppress unneeded defaults
- Reduce pre-reloc malloc space, now that clocks initialization happens laterarch/riscv/Kconfig | 4 + board/sipeed/maix/Kconfig | 48 +++++ board/sipeed/maix/MAINTAINERS | 11 ++ board/sipeed/maix/Makefile | 5 + board/sipeed/maix/maix.c | 54 ++++++ configs/sipeed_maix_bitm_defconfig | 8 + doc/board/index.rst | 1 + doc/board/sipeed/index.rst | 9 + doc/board/sipeed/maix.rst | 298 +++++++++++++++++++++++++++++ include/configs/sipeed-maix.h | 24 +++ 10 files changed, 462 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_defconfig create mode 100644 doc/board/sipeed/index.rst create mode 100644 doc/board/sipeed/maix.rst create mode 100644 include/configs/sipeed-maix.harch/riscv/Kconfig +4
-0@@ -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 +48
-0@@ -0,0 +1,48 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (C) 2019-20 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 DEFAULT_DEVICE_TREE + default "k210-maix-bit" + +config NR_CPUS + default 2 + +config NR_DRAM_BANKS + default 3 + +config BOARD_SPECIFIC_OPTIONS + def_bool y + select GENERIC_RISCV + select RISCV_PRIV_1_9 + imply SMP + imply OF_BOARD_SETUP + imply DM_SERIAL + imply SIFIVE_SERIAL + imply SIFIVE_CLINT + imply POWER_DOMAIN + imply SIMPLE_PM_BUS + imply CLK_CCF + imply CLK_COMPOSITE_CCF + imply CLK_K210 + imply DM_RESET + imply RESET_SYSCON + imply SYSRESET + imply SYSRESET_SYSCON +endifboard/sipeed/maix/MAINTAINERS new file +11
-0@@ -0,0 +1,11 @@ +Sipeed Maix BOARD +M: Sean Anderson <[email protected]> +S: Maintained +F: arch/riscv/dts/k210.dtsi +F: arch/riscv/dts/k210-maix-bit.dts +F: board/sipeed/maix/ +F: configs/sipeed_maix_defconfig +F: doc/board/sipeed/ +F: include/configs/sipeed-maix.h +F: include/dt-bindings/*/k210-sysctl.h +F: test/dm/k210_pll.cboard/sipeed/maix/Makefile new file +5
-0@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (c) 2019 Western Digital Corporation or its affiliates. + +obj-y += maix.oboard/sipeed/maix/maix.c new file +54
-0@@ -0,0 +1,54 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2019 Sean Anderson <[email protected]> +*/ + +#include <common.h> +#include <clk.h> +#include <dm.h> +#include <fdt_support.h> + +phys_size_t get_effective_memsize (void ) +{ +return CONFIG_SYS_SDRAM_SIZE ; +} + +int board_init (void ) +{ +int ret; +ofnode bank =ofnode_null (); + +/* Enable RAM clocks */ +while (true) { +struct clk clk; + + bank =ofnode_by_prop_value (bank,"device_type" ,"memory" , +sizeof ("memory" )); +if (ofnode_equal (bank,ofnode_null ())) +break ; + + ret =clk_get_by_index_nodev (bank,0 , &clk); +if (ret) +continue ; + + ret =clk_enable (&clk); +clk_free (&clk); +if (ret) +return ret; + } +return 0 ; +} + +int ft_board_setup (void *blob,bd_t *bd) +{ +int i; +u64 base[CONFIG_NR_DRAM_BANKS ]; +u64 size[CONFIG_NR_DRAM_BANKS ]; + +for (i =0 ; i <CONFIG_NR_DRAM_BANKS ; i++) { + base[i] = bd->bi_dram[i].start; + size[i] = bd->bi_dram[i].size; + } + +return fdt_fixup_memory_banks (blob, base, size,CONFIG_NR_DRAM_BANKS ); +}configs/sipeed_maix_bitm_defconfig new file +8
-0@@ -0,0 +1,8 @@ +CONFIG_RISCV=y +CONFIG_TARGET_SIPEED_MAIX=y +CONFIG_ARCH_RV64I=y +CONFIG_SYS_REDUNDAND_ENVIRONMENT=y +# CONFIG_NET is not set +# CONFIG_INPUT is not set +# CONFIG_DM_ETH is not set +# CONFIG_EFI_LOADER is not setdoc/board/index.rst +1
-0@@ -16,5 +16,6 @@ Board-specific doc renesas/index rockchip/index sifive/index + sipeed/index st/index xilinx/indexdoc/board/sipeed/index.rst new file +9
-0@@ -0,0 +1,9 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +Sipeed +====== + +.. toctree:: + :maxdepth: 2 + + maixdoc/board/sipeed/maix.rst new file +298
-0@@ -0,0 +1,298 @@ +.. SPDX-License-Identifier: GPL-2.0+ +.. Copyright (C) 2020 Sean Anderson <[email protected]> + +Maix Bit +======== + +Several of the Sipeed Maix series of boards cotain the Kendryte K210 processor, +a 64-bit RISC-V CPU. 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 available from +`Sipeed's website <http://dl.sipeed.com/MAIX/HDK/>`_. +Documentation for the Kendryte K210 is available from +`Kendryte's website <https://kendryte.com/downloads/>`_. However, hardware +details are rather lacking, so most technical reference has been taken from the +`standalone sdk <https://github.com/kendryte/kendryte-standalone-sdk>`_. + +Build and boot steps +-------------------- + +To build u-boot, run + +.. code-block:: none + + make sipeed_maix_bitm_defconfig + make CROSS_COMPILE=<your cross compile prefix> + +To flash u-boot to a maix bit, run + +.. code-block:: none + + kflash -tp /dev/<your tty here> -B bit_mic u-boot-dtb.bin + +Boot output should look like the following: + +.. code-block:: none + + U-Boot 2020.04-rc2-00087-g2221cc09c1-dirty (Feb 28 2020 - 13:53:09 -0500) + + DRAM: 8 MiB + In: serial at 38000000 + Out: serial at 38000000 + Err: serial at 38000000 + => + +Loading Images +^^^^^^^^^^^^^^ + +To load a kernel, transfer it over serial. + +.. code-block:: none + + => loady 80000000 1500000 + ## Switch baudrate to 1500000 bps and press ENTER ... + + *** baud: 1500000 + + *** baud: 1500000 *** + ## Ready for binary (ymodem) download to 0x80000000 at 1500000 bps... + C + *** file: loader.bin + $ sz -vv loader.bin + Sending: loader.bin + Bytes Sent:2478208 BPS:72937 + Sending: + Ymodem sectors/kbytes sent: 0/ 0k + Transfer complete + + *** exit status: 0 *** + ## Total Size = 0x0025d052 = 2478162 Bytes + ## Switch baudrate to 115200 bps and press ESC ... + + *** baud: 115200 + + *** baud: 115200 *** + => + +Running Programs +^^^^^^^^^^^^^^^^ + +Binaries +"""""""" + +To run a bare binary, use the ``go`` command: + +.. code-block:: none + + => loady + ## Ready for binary (ymodem) download to 0x80000000 at 115200 bps... + C + *** file: ./examples/standalone/hello_world.bin + $ sz -vv ./examples/standalone/hello_world.bin + Sending: hello_world.bin + Bytes Sent: 4864 BPS:649 + Sending: + Ymodem sectors/kbytes sent: 0/ 0k + Transfer complete + + *** exit status: 0 *** + (CAN) packets, 5 retries + ## Total Size = 0x000012f8 = 4856 Bytes + => go 80000000 + ## Starting application at 0x80000000 ... + Example expects ABI version 9 + Actual U-Boot ABI version 9 + Hello World + argc = 1 + argv[0] = "80000000" + argv[1] = "<NULL>" + Hit any key to exit ... + +Legacy Images +""""""""""""" + +To run legacy images, use the ``bootm`` command: + +.. code-block:: none + + $ tools/mkimage -A riscv -O u-boot -T standalone -C none -a 80000000 -e 80000000 -d examples/standalone/hello_world.bin hello_world.img + Image Name: + Created: Thu Mar 5 12:04:10 2020 + Image Type: RISC-V U-Boot Standalone Program (uncompressed) + Data Size: 4856 Bytes = 4.74 KiB = 0.00 MiB + Load Address: 80000000 + Entry Point: 80000000 + + $ picocom -b 115200 /dev/ttyUSB0i + => loady + ## Ready for binary (ymodem) download to 0x80000000 at 115200 bps... + C + *** file: hello_world.img + $ sz -vv hello_world.img + Sending: hello_world.img + Bytes Sent: 4992 BPS:665 + Sending: + Ymodem sectors/kbytes sent: 0/ 0k + Transfer complete + + *** exit status: 0 *** + CAN) packets, 3 retries + ## Total Size = 0x00001338 = 4920 Bytes + => bootm + ## Booting kernel from Legacy Image at 80000000 ... + Image Name: + Image Type: RISC-V U-Boot Standalone Program (uncompressed) + Data Size: 4856 Bytes = 4.7 KiB + Load Address: 80000000 + Entry Point: 80000000 + Verifying Checksum ... OK + Loading Standalone Program + Example expects ABI version 9 + Actual U-Boot ABI version 9 + Hello World + argc = 0 + argv[0] = "<NULL>" + Hit any key to exit ... + +Over- and Under-clocking +------------------------ + +To change the clock speed of the K210, you will need to enable +``CONFIG_CLK_K210_SET_RATE`` and edit the board's device tree. To do this, add a +section to ``arch/riscv/arch/riscv/dts/k210-maix-bit.dts`` like the following: + +.. code-block:: + + &sysclk { + assigned-clocks = <&sysclk K210_CLK_PLL0>; + assigned-clock-rates = <800000000>; + }; + +There are three PLLs on the K210: PLL0 is the parent of most of the components, +including the CPU and RAM. PLL1 is the parent of the neural network coprocessor. +PLL2 is the parent of the sound processing devices. Note that child clocks of +PLL0 and PLL2 run at *half* the speed of the PLLs. For example, if PLL0 is +running at 800 MHz, then the CPU will run at 400 MHz. This is the example given +above. The CPU can be overclocked to around 600 MHz, and underclocked to 26 MHz. + +It is possible to set PLL2's parent to PLL0. The plls are more accurate when +converting between similar frequencies. This makes it easier to get an accurate +frequency for I2S. As an example, consider sampling an I2S device at 44.1 kHz. +On this device, the I2S serial clock runs at 64 times the sample rate. +Therefore, we would like to run PLL2 at an even multiple of 2.8224 MHz. If +PLL2's parent is IN0, we could use a frequency of 390 MHz (the same as the CPU's +default speed). Dividing by 138 yields a serial clock of about 2.8261 MHz. This +results in a sample rate of 44.158 kHz---around 50 Hz or .1% too fast. If, +instead, we set PLL2's parent to PLL1 running at 390 MHz, and request a rate of +2.8224 * 136 = 383.8464 MHz, the achieved rate is 383.90625 MHz. Dividing by 136 +yields a serial clock of about 2.8228 MHz. This results in a sample rate of +44.107 kHz---just 7 Hz or .02% too fast. This configuration is shown in the +following example: + +.. code-block:: + + &sysclk { + assigned-clocks = <&sysclk K210_CLK_PLL1>, <&sysclk K210_CLK_PLL2>; + assigned-clock-parents = <0>, <&sysclk K210_CLK_PLL1>; + assigned-clock-rates = <390000000>, <383846400>; + }; + +There are a couple of quirks to the PLLs. First, there are more frequency ratios +just above and below 1.0, but there is a small gap around 1.0. To be explicit, +if the input frequency is 100 MHz, it would be impossible to have an output of +99 or 101 MHz. In addition, there is a maximum frequency for the internal VCO, +so higher input/output frequencies will be less accurate than lower ones. + +Technical Details +----------------- + +Boot Sequence +^^^^^^^^^^^^^ + +1. ``RESET`` pin is deasserted. +2. Both harts begin executing at ``0x00001000``. +3. Both harts jump to firmware at ``0x88000000``. +4. One hart is chosen as a boot hart. +5. Firmware reads value of pin ``IO_16`` (ISP). + + * If the pin is low, enter ISP mode. This mode allows loading data to ram, + writing it to flash, and booting from specific addresses. + * If the pin is high, continue boot. +6. Firmware reads the next stage from flash (SPI3) to address ``0x80000000``. + + * If byte 0 is 1, the next stage is decrypted using the built-in AES + accelerator and the one-time programmable, 128-bit AES key. + * Bytes 1 to 4 hold the length of the next stage. + * The SHA-256 sum of the next stage is automatically calculated, and verified + against the 32 bytes following the next stage. +7. The boot hart sends an IPI to the other hart telling it to jump to the next + stage. +8. The boot hart jumps to ``0x80000000``. + +Memory Map +^^^^^^^^^^ + +========== ========= =========== +Address Size Description +========== ========= =========== +0x00000000 0x1000 debug +0x00001000 0x1000 rom +0x02000000 0x1000 clint +0x0C000000 0x4000000 plic +0x38000000 0x1000 uarths +0x38001000 0x1000 gpiohs +0x40000000 0x400000 sram0 (non-cached) +0x40400000 0x200000 sram1 (non-cached) +0x40600000 0x200000 airam (non-cached) +0x40800000 0xC00000 kpu +0x42000000 0x400000 fft +0x50000000 0x1000 dmac +0x50200000 0x200000 apb0 +0x50200000 0x80 gpio +0x50210000 0x100 uart0 +0x50220000 0x100 uart1 +0x50230000 0x100 uart2 +0x50240000 0x100 spi slave +0x50250000 0x200 i2s0 +0x50250200 0x200 apu +0x50260000 0x200 i2s1 +0x50270000 0x200 i2s2 +0x50280000 0x100 i2c0 +0x50290000 0x100 i2c1 +0x502A0000 0x100 i2c2 +0x502B0000 0x100 fpioa +0x502C0000 0x100 sha256 +0x502D0000 0x100 timer0 +0x502E0000 0x100 timer1 +0x502F0000 0x100 timer2 +0x50400000 0x200000 apb1 +0x50400000 0x100 wdt0 +0x50410000 0x100 wdt1 +0x50420000 0x100 otp control +0x50430000 0x100 dvp +0x50440000 0x100 sysctl +0x50450000 0x100 aes +0x50460000 0x100 rtc +0x52000000 0x4000000 apb2 +0x52000000 0x100 spi0 +0x53000000 0x100 spi1 +0x54000000 0x200 spi3 +0x80000000 0x400000 sram0 (cached) +0x80400000 0x200000 sram1 (cached) +0x80600000 0x200000 airam (cached) +0x88000000 0x20000 otp +0x88000000 0xC200 firmware +0x8801C000 0x1000 riscv priv spec 1.9 config +0x8801D000 0x2000 flattened device tree (contains only addresses and + interrupts) +0x8801f000 0x1000 credits +========== ========= ===========include/configs/sipeed-maix.h new file +24
-1@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2019-20 Sean Anderson <[email protected]> +*/ + +#ifndef CONFIGS_SIPEED_MAIX_H +#define CONFIGS_SIPEED_MAIX_H + +#include <linux/sizes.h> + +#define CONFIG_SYS_LOAD_ADDR 0x80000000 +/* Start just below the second bank so we don't clobber it during reloc */ +#define CONFIG_SYS_INIT_SP_ADDR 0x803FFFFF +#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 + +#endif /* CONFIGS_SIPEED_MAIX_H */ --2.25.0
PATCH v6 19/19 riscv: Add Sipeed Maix support
Quoted 36 lines · Rick Chen
Hi Sean
Quoted 20 lines
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>.Quoted 2 lines
Signed-off-by Sean Anderson <[email protected]>---
This patch applying fail
Applying: riscv: Add Sipeed Maix support
error: patch failed:doc/board/index.rst:16
error:doc/board/index.rst: patch does not apply
Patch failed at 0001 riscv: Add Sipeed Maix support
The copy of the patch that failed is found in: .git/rebase-apply/patch When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".
Quoted 3 lines
I have replied to you the same result in v5
[v5,33/33] riscv: Add Sipeed Maix support
https://patchwork.ozlabs.org/patch/1246869/#2376311
As above, I just rebased against u-boot/master. I'm not sure what's causing the problem here.
Quoted 7 lines
By the way,
you can not mix them (arch, board, configs, doc)together in a patch.arch/riscv/Kconfig
board/sipeed/maix/ ...
configs/sipeed_maix_bitm_defconfigdoc/board/index.rst
Is there a preferred order for adding these? I will split them for v7.
Quoted 2 lines
Thanks,
Rick
PATCH v6 19/19 riscv: Add Sipeed Maix support
Hi Sean
Quoted 45 lines · Rick Chen
Quoted 36 lines
Hi Sean
Quoted 20 lines
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>.Quoted 2 lines
Signed-off-by Sean Anderson <[email protected]>---
This patch applying fail
Applying: riscv: Add Sipeed Maix support
error: patch failed:doc/board/index.rst:16
error:doc/board/index.rst: patch does not apply
Patch failed at 0001 riscv: Add Sipeed Maix support
The copy of the patch that failed is found in: .git/rebase-apply/patch When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".Quoted 3 lines
I have replied to you the same result in v5
[v5,33/33] riscv: Add Sipeed Maix support
https://patchwork.ozlabs.org/patch/1246869/#2376311As above, I just rebased against u-boot/master. I'm not sure what's causing the problem here.
Quoted 1 line
Quoted 8 lines
Quoted 6 lines
By the way,
you can not mix them (arch, board, configs, doc)together in a patch.arch/riscv/Kconfig
board/sipeed/maix/ ...
configs/sipeed_maix_bitm_defconfigdoc/board/index.rstIs there a preferred order for adding these? I will split them for v7.
Maybe you can group them as two patchs
patch 19/20
arch/riscv/Kconfig
board/sipeed/maix/Kconfig
board/sipeed/maix/MAINTAINERS
board/sipeed/maix/Makefile
board/sipeed/maix/maix.c
configs/sipeed_maix_bitm_defconfig
include/configs/sipeed-maix.h
patch 19/20
doc/board/index.rst
doc/board/sipeed/index.rst
doc/board/sipeed/maix.rst
Thanks,
Rick
Quoted 4 lines
Quoted 3 lines
Thanks,
Rick