riscv: Add Sipeed Maix support
Subsystems (6)
v2 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).
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.01-00455-gad03fd83e1 (Jan 15 2020 - 17:10:24 -0500)
DRAM: 8 MiB MMC: spi at 52000000:slot at 0: 0 In: serial at 38000000 Out: serial at 38000000 Err: serial at 38000000
=>
I would really appreciate feedback! Many of the changes I had to make for this revision were fairly trivial and could have been caught by someone more familiar with the source code than I. In particular, there are still some questions in individual patches which have yet to be answered.
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 (11):
clk: Always use the supplied struct clk
clk: Check that ops of composite clock components exist before calling
riscv: Add headers for asm/global_data.h
riscv: Add an option to default to RV64I
riscv: Add option to disable writes to mcounteren
riscv: Fix incorrect cpu frequency on RV64
riscv: Add initial Sipeed Maix support
riscv: Add device tree for K210
riscv: Add K210 sysctl support
riscv: Add K210 pll support
riscv: Add K210 clock support
arch/riscv/Kconfig | 19 + arch/riscv/cpu/cpu.c | 2 + arch/riscv/dts/Makefile | 1 + arch/riscv/dts/k210-maix-bit.dts | 42 ++ arch/riscv/dts/k210.dtsi | 453 ++++++++++++++++++ arch/riscv/include/asm/global_data.h | 2 + arch/riscv/include/asm/k210_sysctl.h | 43 ++ arch/riscv/lib/Makefile | 1 + arch/riscv/lib/k210_sysctl.c | 21 + board/sipeed/maix/Kconfig | 49 ++ board/sipeed/maix/MAINTAINERS | 13 + board/sipeed/maix/Makefile | 5 + board/sipeed/maix/maix.c | 9 + configs/sipeed_maix_bitm_defconfig | 95 ++++ drivers/clk/Kconfig | 1 + drivers/clk/Makefile | 1 + drivers/clk/clk-composite.c | 65 ++- drivers/clk/clk-divider.c | 6 +- drivers/clk/clk-fixed-factor.c | 3 +- drivers/clk/clk-gate.c | 6 +- drivers/clk/clk-mux.c | 12 +- drivers/clk/imx/clk-gate2.c | 4 +- drivers/clk/kendryte/Kconfig | 7 + drivers/clk/kendryte/Makefile | 1 + drivers/clk/kendryte/clk.c | 390 ++++++++++++++++ drivers/clk/kendryte/clk.h | 27 ++ drivers/clk/kendryte/pll.c | 598 ++++++++++++++++++++++++ drivers/clk/kendryte/pll.h | 38 ++ drivers/cpu/riscv_cpu.c | 2 + include/configs/sipeed-maix.h | 19 + include/dt-bindings/clock/k210-sysctl.h | 54 +++ include/dt-bindings/reset/k210-sysctl.h | 38 ++ 32 files changed, 1985 insertions(+), 42 deletions(-) create mode 100644 arch/riscv/dts/k210-maix-bit.dts create mode 100644 arch/riscv/dts/k210.dtsi create mode 100644 arch/riscv/include/asm/k210_sysctl.h create mode 100644 arch/riscv/lib/k210_sysctl.c create mode 100644 board/sipeed/maix/Kconfig create mode 100644 board/sipeed/maix/MAINTAINERS create mode 100644 board/sipeed/maix/Makefile create mode 100644 board/sipeed/maix/maix.c create mode 100644 configs/sipeed_maix_bitm_defconfig create mode 100644 drivers/clk/kendryte/Kconfig create mode 100644 drivers/clk/kendryte/Makefile create mode 100644 drivers/clk/kendryte/clk.c create mode 100644 drivers/clk/kendryte/clk.h create mode 100644 drivers/clk/kendryte/pll.c create mode 100644 drivers/clk/kendryte/pll.h create mode 100644 include/configs/sipeed-maix.h create mode 100644 include/dt-bindings/clock/k210-sysctl.h create mode 100644 include/dt-bindings/reset/k210-sysctl.h
Signature · 1 line
2.24.1
PATCH v2 1/11 clk: Always use the supplied struct clk
CCF clocks should always use the struct clock passed to their methods for extracting the driver-specific clock information struct. Previously, many functions would use the clk->dev->priv if the device was bound. This could cause problems with composite clocks. The individual clocks in a composite clock did not have the ->dev field filled in. This was fine, because the device-specific clock information would be used. However, since there was no ->dev, there was no way to get the parent clock. This caused the recalc_rate method of the CCF divider clock to fail. One option would be to use the clk->priv field to get the composite clock and from there get the appropriate parent device. However, this would tie the implementation to the composite clock. In general, different devices should not rely on the contents of ->priv from another device.
The simple solution to this problem is to just always use the supplied struct clock. The composite clock now fills in the ->dev pointer of its child clocks. This allows child clocks to make calls like clk_get_parent() without issue.
imx avoided the above problem by using a custom get_rate function with composite clocks.
--- drivers/clk/clk-composite.c | 8 ++++++++ drivers/clk/clk-divider.c | 6 ++---- drivers/clk/clk-fixed-factor.c | 3 +-- drivers/clk/clk-gate.c | 6 ++---- drivers/clk/clk-mux.c | 12 ++++-------- drivers/clk/imx/clk-gate2.c | 4 ++-- 6 files changed, 19 insertions(+), 20 deletions(-)
drivers/clk/clk-composite.c +8 -0
@@ -145,6 +145,14 @@ struct clk *clk_register_composite(struct device *dev, const char *name, goto err; } +if (composite->mux) + composite->mux->dev = clk->dev; +if (composite->rate) + composite->rate->dev = clk->dev; +if (composite->gate) + composite->gate->dev = clk->dev; + +return clk; err:
drivers/clk/clk-divider.c +2 -4
@@ -70,8 +70,7 @@ unsigned long divider_recalc_rate(struct clk *hw, unsigned long parent_rate,static ulong clk_divider_recalc_rate (struct clk *clk) { -struct clk_divider *divider =to_clk_divider (clk_dev_binded (clk) ? -dev_get_clk_ptr (clk->dev) : clk); +struct clk_divider *divider =to_clk_divider (clk);unsigned long parent_rate =clk_get_parent_rate (clk);unsigned int val;
@@ -150,8 +149,7 @@ int divider_get_val(unsigned long rate, unsigned long parent_rate,static ulong clk_divider_set_rate (struct clk *clk,unsigned long rate) { -struct clk_divider *divider =to_clk_divider (clk_dev_binded (clk) ? -dev_get_clk_ptr (clk->dev) : clk); +struct clk_divider *divider =to_clk_divider (clk);unsigned long parent_rate =clk_get_parent_rate (clk);int value;u32 val;
drivers/clk/clk-fixed-factor.c +1 -2
@@ -18,8 +18,7 @@static ulong clk_factor_recalc_rate (struct clk *clk) { -struct clk_fixed_factor *fix = -to_clk_fixed_factor (dev_get_clk_ptr (clk->dev)); +struct clk_fixed_factor *fix =to_clk_fixed_factor (clk);unsigned long parent_rate =clk_get_parent_rate (clk);unsigned long long int rate;
drivers/clk/clk-gate.c +2 -4
@@ -43,8 +43,7 @@*/ static void clk_gate_endisable (struct clk *clk,int enable) { -struct clk_gate *gate =to_clk_gate (clk_dev_binded (clk) ? -dev_get_clk_ptr (clk->dev) : clk); +struct clk_gate *gate =to_clk_gate (clk);int set = gate->flags &CLK_GATE_SET_TO_DISABLE ?1 :0 ;u32 reg;
@@ -86,8 +85,7 @@ static int clk_gate_disable(struct clk *clk)int clk_gate_is_enabled (struct clk *clk) { -struct clk_gate *gate =to_clk_gate (clk_dev_binded (clk) ? -dev_get_clk_ptr (clk->dev) : clk); +struct clk_gate *gate =to_clk_gate (clk);u32 reg;#if CONFIG_IS_ENABLED (SANDBOX_CLK_CCF )
drivers/clk/clk-mux.c +4 -8
@@ -35,8 +35,7 @@int clk_mux_val_to_index (struct clk *clk,u32 *table,unsigned int flags,unsigned int val) { -struct clk_mux *mux =to_clk_mux (clk_dev_binded (clk) ? -dev_get_clk_ptr (clk->dev) : clk); +struct clk_mux *mux =to_clk_mux (clk);int num_parents = mux->num_parents;if (table) {
@@ -79,8 +78,7 @@ unsigned int clk_mux_index_to_val(u32 *table, unsigned int flags, u8 index)u8 clk_mux_get_parent (struct clk *clk) { -struct clk_mux *mux =to_clk_mux (clk_dev_binded (clk) ? -dev_get_clk_ptr (clk->dev) : clk); +struct clk_mux *mux =to_clk_mux (clk);u32 val;#if CONFIG_IS_ENABLED (SANDBOX_CLK_CCF )
@@ -97,8 +95,7 @@ u8 clk_mux_get_parent(struct clk *clk)static int clk_fetch_parent_index (struct clk *clk,struct clk *parent) { -struct clk_mux *mux =to_clk_mux (clk_dev_binded (clk) ? -dev_get_clk_ptr (clk->dev) : clk); +struct clk_mux *mux =to_clk_mux (clk);int i;
@@ -115,8 +112,7 @@ static int clk_fetch_parent_index(struct clk *clk,static int clk_mux_set_parent (struct clk *clk,struct clk *parent) { -struct clk_mux *mux =to_clk_mux (clk_dev_binded (clk) ? -dev_get_clk_ptr (clk->dev) : clk); +struct clk_mux *mux =to_clk_mux (clk);int index;u32 val;u32 reg;
drivers/clk/imx/clk-gate2.c +2 -2
@@ -37,7 +37,7 @@ struct clk_gate2 {static int clk_gate2_enable (struct clk *clk) { -struct clk_gate2 *gate =to_clk_gate2 (dev_get_clk_ptr (clk->dev)); +struct clk_gate2 *gate =to_clk_gate2 (clk);u32 reg; reg =readl (gate->reg);
@@ -50,7 +50,7 @@ static int clk_gate2_enable(struct clk *clk)static int clk_gate2_disable (struct clk *clk) { -struct clk_gate2 *gate =to_clk_gate2 (dev_get_clk_ptr (clk->dev)); +struct clk_gate2 *gate =to_clk_gate2 (clk);u32 reg; reg =readl (gate->reg);
Signature · 1 line
2.24.1
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v2 1/11 clk: Always use the supplied struct clk
Hi Sean
Quoted 13 lines
From: U-Boot [mailto:u-boot-bounces at lists.denx.de] On Behalf Of Sean Anderson
Sent: Thursday, January 16, 2020 6:48 AM
To: U-Boot Mailing List
Subject: [PATCH v2 01/11] clk: Always use the supplied struct clkCCF 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->privif 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 therecalc_ratemethod of the CCF divider clock to fail. One option would be to use theclk->privfield 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_ratefunction with composite clocks.Signed-off-by Sean Anderson <[email protected]>
Quoted 8 lines
--- drivers/clk/clk-composite.c | 8 ++++++++ drivers/clk/clk-divider.c | 6 ++---- drivers/clk/clk-fixed-factor.c | 3 +-- drivers/clk/clk-gate.c | 6 ++---- drivers/clk/clk-mux.c | 12 ++++-------- drivers/clk/imx/clk-gate2.c | 4 ++-- 6 files changed, 19 insertions(+), 20 deletions(-)
This patch is clock relative patch, if it is not a necessary patch for Sipeed Maix support.
Please remove patch 1/11 and 2/11, and send them in another patch-sets.
Rick,
Thanks
Quoted 136 lines
drivers/clk/clk-composite.c +8
-0@@ -145,6 +145,14 @@ struct clk *clk_register_composite(struct device *dev, const char *name, goto err; } +if (composite->mux) + composite->mux->dev = clk->dev; +if (composite->rate) + composite->rate->dev = clk->dev; +if (composite->gate) + composite->gate->dev = clk->dev; + +return clk; err:drivers/clk/clk-divider.c +2
-4@@ -70,8 +70,7 @@ unsigned long divider_recalc_rate(struct clk *hw, unsigned long parent_rate,static ulong clk_divider_recalc_rate (struct clk *clk) { -struct clk_divider *divider =to_clk_divider (clk_dev_binded (clk) ? -dev_get_clk_ptr (clk->dev) : clk); +struct clk_divider *divider =to_clk_divider (clk);unsigned long parent_rate =clk_get_parent_rate (clk);unsigned int val;@@ -150,8 +149,7 @@ int divider_get_val(unsigned long rate, unsigned long parent_rate,static ulong clk_divider_set_rate (struct clk *clk,unsigned long rate) { -struct clk_divider *divider =to_clk_divider (clk_dev_binded (clk) ? -dev_get_clk_ptr (clk->dev) : clk); +struct clk_divider *divider =to_clk_divider (clk);unsigned long parent_rate =clk_get_parent_rate (clk);int value;u32 val;drivers/clk/clk-fixed-factor.c +1
-2@@ -18,8 +18,7 @@static ulong clk_factor_recalc_rate (struct clk *clk) { -struct clk_fixed_factor *fix = -to_clk_fixed_factor (dev_get_clk_ptr (clk->dev)); +struct clk_fixed_factor *fix =to_clk_fixed_factor (clk);unsigned long parent_rate =clk_get_parent_rate (clk);unsigned long long int rate;drivers/clk/clk-gate.c +2
-4@@ -43,8 +43,7 @@*/ static void clk_gate_endisable (struct clk *clk,int enable) { -struct clk_gate *gate =to_clk_gate (clk_dev_binded (clk) ? -dev_get_clk_ptr (clk->dev) : clk); +struct clk_gate *gate =to_clk_gate (clk);int set = gate->flags &CLK_GATE_SET_TO_DISABLE ?1 :0 ;u32 reg;@@ -86,8 +85,7 @@ static int clk_gate_disable(struct clk *clk)int clk_gate_is_enabled (struct clk *clk) { -struct clk_gate *gate =to_clk_gate (clk_dev_binded (clk) ? -dev_get_clk_ptr (clk->dev) : clk); +struct clk_gate *gate =to_clk_gate (clk);u32 reg;#if CONFIG_IS_ENABLED (SANDBOX_CLK_CCF )drivers/clk/clk-mux.c +4
-8@@ -35,8 +35,7 @@int clk_mux_val_to_index (struct clk *clk,u32 *table,unsigned int flags,unsigned int val) { -struct clk_mux *mux =to_clk_mux (clk_dev_binded (clk) ? -dev_get_clk_ptr (clk->dev) : clk); +struct clk_mux *mux =to_clk_mux (clk);int num_parents = mux->num_parents;if (table) {@@ -79,8 +78,7 @@ unsigned int clk_mux_index_to_val(u32 *table, unsigned int flags, u8 index)u8 clk_mux_get_parent (struct clk *clk) { -struct clk_mux *mux =to_clk_mux (clk_dev_binded (clk) ? -dev_get_clk_ptr (clk->dev) : clk); +struct clk_mux *mux =to_clk_mux (clk);u32 val;#if CONFIG_IS_ENABLED (SANDBOX_CLK_CCF )@@ -97,8 +95,7 @@ u8 clk_mux_get_parent(struct clk *clk) static int clk_fetch_parent_index(struct clk *clk, struct clk *parent) { -struct clk_mux *mux =to_clk_mux (clk_dev_binded (clk) ? -dev_get_clk_ptr (clk->dev) : clk); +struct clk_mux *mux =to_clk_mux (clk);int i;@@ -115,8 +112,7 @@ static int clk_fetch_parent_index(struct clk *clk,static int clk_mux_set_parent (struct clk *clk,struct clk *parent) { -struct clk_mux *mux =to_clk_mux (clk_dev_binded (clk) ? -dev_get_clk_ptr (clk->dev) : clk); +struct clk_mux *mux =to_clk_mux (clk);int index;u32 val;u32 reg;drivers/clk/imx/clk-gate2.c +2
-3@@ -37,7 +37,7 @@ struct clk_gate2 {static int clk_gate2_enable (struct clk *clk) { -struct clk_gate2 *gate =to_clk_gate2 (dev_get_clk_ptr (clk->dev)); +struct clk_gate2 *gate =to_clk_gate2 (clk);u32 reg; reg =readl (gate->reg);@@ -50,7 +50,7 @@ static int clk_gate2_enable(struct clk *clk)static int clk_gate2_disable (struct clk *clk) { -struct clk_gate2 *gate =to_clk_gate2 (dev_get_clk_ptr (clk->dev)); +struct clk_gate2 *gate =to_clk_gate2 (clk);u32 reg; reg =readl (gate->reg); --2.24.1
PATCH v2 1/11 clk: Always use the supplied struct clk
Quoted 3 lines
This patch is clock relative patch, if it is not a necessary patch for Sipeed Maix support.
Please remove patch 1/11 and 2/11, and send them in another patch-sets.
Patches 10 and 11 rely on these first two patches. Should I just reference the split off patches in the cover letter?
PATCH v2 1/11 clk: Always use the supplied struct clk
Hi Sean,
Quoted 6 lines
Quoted 3 lines
This patch is clock relative patch, if it is not a necessary patch for Sipeed Maix support.
Please remove patch 1/11 and 2/11, and send them in another patch-sets.Patches 10 and 11 rely on these first two patches. Should I just reference the split off patches in the cover letter?
I am not sure the modifications of clk are ok for other people. It will be better to send pure riscv relative patch-sets.
Thanks,
Rick
PATCH v2 1/11 clk: Always use the supplied struct clk
Quoted 2 lines
I am not sure the modifications of clk are ok for other people. It will be better to send pure riscv relative patch-sets.
Hm, well at the moment removing the dependency on these two patches would probably require a substantial rewrite of patch 11, which would primarily consist of duplicating functionality currently found in the clk_composite driver. I actually think the way clk_composite works at the moment is very confusing, since the imx code which uses it uses some custom functions to smooth out clk_composite's behaviour. These two patches are probably the ones I would like to see merged most of all, since it would make implementing complex clock drivers like on this board much easier. I originally submitted these patches around a month ago [1, 2], so I was hoping that I'd have recieved feedback one way or the other by now.
[1] https://patchwork.ozlabs.org/patch/1215327/
[2] https://patchwork.ozlabs.org/patch/1215328/
PATCH v2 1/11 clk: Always use the supplied struct clk
Quoted 2 lines
[1] https://patchwork.ozlabs.org/patch/1215327/
[2] https://patchwork.ozlabs.org/patch/1215328/
err, these references should be
[1] https://patchwork.ozlabs.org/patch/1215335/
[2] https://patchwork.ozlabs.org/patch/1215337/
PATCH v2 1/11 clk: Always use the supplied struct clk
In reply to Sean AndersonHi Sean,
Quoted 15 lines
Quoted 2 lines
I am not sure the modifications of clk are ok for other people. It will be better to send pure riscv relative patch-sets.
Hm, well at the moment removing the dependency on these two patches would probably require a substantial rewrite of patch 11, which would primarily consist of duplicating functionality currently found in the
clk_compositedriver. I actually think the wayclk_compositeworks at the moment is very confusing, since the imx code which uses it uses some custom functions to smooth out clk_composite's behaviour. These two patches are probably the ones I would like to see merged most of all, since it would make implementing complex clock drivers like on this board much easier. I originally submitted these patches around a month ago [1, 2], so I was hoping that I'd have recieved feedback one way or the other by now.
Quoted 2 lines
[1] https://patchwork.ozlabs.org/patch/1215327/
[2] https://patchwork.ozlabs.org/patch/1215328/
I saw your patches. Unfortunately, there was the Christmas/New year's break and afterwards I had some more urgent tasks to do. Apologize for that...
What I would like to see here is to reuse (or better - make the code less confusing) the code.
Rationale - the CCF was ported from iMX6Q Linux code from the outset.
Then Peng (CC'ed) wanted to adjust it to support composite clocks from i.MX8.
As a result the CCF drifted to be an iMX aligned, but the goal is to have it usable for other archs as well (and reuse from Linux as much as possible).
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200124/075ca6dc/attachment.sig>
PATCH v2 1/11 clk: Always use the supplied struct clk
Quoted 7 lines · Lukasz Majewski
I saw your patches. Unfortunately, there was the Christmas/New year's break and afterwards I had some more urgent tasks to do. Apologize for that...
What I would like to see here is to reuse (or better - make the code less confusing) the code.
Quoted 8 lines
Rationale - the CCF was ported from iMX6Q Linux code from the outset.
Then Peng (CC'ed) wanted to adjust it to support composite clocks from i.MX8.
As a result the CCF drifted to be an iMX aligned, but the goal is to have it usable for other archs as well (and reuse from Linux as much as possible).
Ok, so I believe that these patches are a step in that direction. Is there any specific feedback you would like to give regarding them? I've tried to infer what good default behaviour should be. However, I'm sure there are places where someone more familiar with the CCF would be able to comment on.
--Sean
PATCH v2 1/11 clk: Always use the supplied struct clk
Hi Sean,
Quoted 18 lines · Lukasz Majewski
Quoted 10 lines
I saw your patches. Unfortunately, there was the Christmas/New year's break and afterwards I had some more urgent tasks to do. Apologize for that...
What I would like to see here is to reuse (or better - make the code less confusing) the code.
Rationale - the CCF was ported from iMX6Q Linux code from the outset.
Quoted 6 lines
Then Peng (CC'ed) wanted to adjust it to support composite clocks from i.MX8.
As a result the CCF drifted to be an iMX aligned, but the goal is to have it usable for other archs as well (and reuse from Linux as much as possible).
Quoted 5 lines
Ok, so I believe that these patches are a step in that direction. Is there any specific feedback you would like to give regarding them? I've tried to infer what good default behaviour should be. However, I'm sure there are places where someone more familiar with the CCF would be able to comment on.
I will do the review by the end of the weekend.
Quoted 3 lines
--Sean
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200125/bce98745/attachment.sig>
PATCH v2 1/11 clk: Always use the supplied struct clk
In reply to Sean AndersonHi Sean,
Quoted 2 lines
CCF clocks should always use the struct clock passed to their methods for extracting the driver-specific clock information struct.
This couldn't be done for i.MX8 at least. There was an issue with composite clock on this SoC.
(I've CC'ed Peng, who did this work for i.MX8 - I was testing/developing the framework for i.MX6Q which doesn't support composite clocks).
For some design decisions and the "overall picture" of CCF , please see following doc entry:
https://gitlab.denx.de/u-boot/u-boot/blob/master/doc/imx/clk/ccf.txt
Quoted 2 lines
Previously, many functions would use the
clk->dev->privif the device was bound. This could cause problems with composite clocks.
The problem (in short) is with combining Linux CCF design and U-Boot's DM (more details in the link above).
All the clocks are linked with struct udevice (one search the linked list for proper clock).
However, with Linux the "main" clock structure is 'struct clk, which is embedded in CLK IP block specific structure (i.e. struct clk_gate2).
Problem is that from struct clk we do have pointer to struct udevice (*dev), but there is no direct pointer "up" from struct udevice to struct clk (now we do use udevice's->uclass_priv).
So far so good ....
Problem started with iMX8, where we do have a composite clocks, which would like to be seen as a single one (like struct pllX), but they comprise of a few other "clocks".
To distinct them the clk_dev_binded() was added, which checks if the struct udevice represents "top" composite clock (which shall be visible with e.g. 'clk' command)
Quoted 5 lines
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.
Wasn't there any back pointer available? Or do we need to search the clocks linked list and look for "bind" flag in top level composite clock?
Quoted 6 lines
This caused the
recalc_rate
method of the CCF divider clock to fail. One option would be to use theclk->privfield 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.
Maybe we shall follow:
https://gitlab.denx.de/u-boot/u-boot/blob/master/doc/imx/clk/ccf.txt#L40
Quoted 3 lines
The simple solution to this problem is to just always use the supplied struct clock.
I think that we took this approach in the past. Unfortunately, this caused all clocks being exposed when 'clk' command was run.
Peng - were there any other issues with i.MX8 composite clock implementation?
Quoted 6 lines
The composite clock now fills in the ->dev
pointer of its child clocks. This allows child clocks to make calls likeclk_get_parent()without issue.imx avoided the above problem by using a custom
get_ratefunction with composite clocks.
Do you refer to:
https://gitlab.denx.de/u-boot/u-boot/blob/master/drivers/clk/imx/clk-composite-8m.c#L30
There the clk is cast from (struct clk_composite *)clk->data
(now in U-Boot we do have 4! different implementations of struct clk).
Quoted 40 lines
Signed-off-by Sean Anderson <[email protected]>--- drivers/clk/clk-composite.c | 8 ++++++++ drivers/clk/clk-divider.c | 6 ++---- drivers/clk/clk-fixed-factor.c | 3 +-- drivers/clk/clk-gate.c | 6 ++---- drivers/clk/clk-mux.c | 12 ++++-------- drivers/clk/imx/clk-gate2.c | 4 ++-- 6 files changed, 19 insertions(+), 20 deletions(-)drivers/clk/clk-composite.c +8
-0@@ -145,6 +145,14 @@ struct clk *clk_register_composite(struct device *dev, const char *name, goto err; } +if (composite->mux) + composite->mux->dev = clk->dev; +if (composite->rate) + composite->rate->dev = clk->dev; +if (composite->gate) + composite->gate->dev = clk->dev; + +return clk; err:drivers/clk/clk-divider.c +0
-1@@ -70,8 +70,7 @@ unsigned long divider_recalc_rate(struct clk *hw, unsigned long parent_rate, static ulong clk_divider_recalc_rate(struct clk *clk) { - struct clk_divider *divider =to_clk_divider(clk_dev_binded(clk) ?
drivers/clk/clk-divider.c
Quoted 2 lines
drivers/clk/clk-divider.c +1
-1- dev_get_clk_ptr(clk->dev) : clk); +struct clk_divider *divider =to_clk_divider (clk);
How do you differentiate the "top" level of composite clock from the clocks from which the composite clock is built?
Now we do use the clk_dev_binded().
Quoted 119 lines
drivers/clk/clk-divider.c +0
-1unsigned long parent_rate =clk_get_parent_rate (clk);unsigned int val;@@ -150,8 +149,7 @@ int divider_get_val(unsigned long rate, unsigned long parent_rate, static ulong clk_divider_set_rate(struct clk *clk, unsigned long rate) { - struct clk_divider *divider =to_clk_divider(clk_dev_binded(clk) ?
drivers/clk/clk-divider.c +1
-1- 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;(quoted diff) +0
-0
b/drivers/clk/clk-fixed-factor.cindex711b0588bc..d2401cf440100644drivers/clk/clk-fixed-factor.c +1
-2@@ -18,8 +18,7 @@static ulong clk_factor_recalc_rate (struct clk *clk) { -struct clk_fixed_factor *fix = -to_clk_fixed_factor (dev_get_clk_ptr (clk->dev)); +struct clk_fixed_factor *fix =to_clk_fixed_factor (clk);unsigned long parent_rate =clk_get_parent_rate (clk);unsigned long long int rate;drivers/clk/clk-gate.c +2
-4@@ -43,8 +43,7 @@*/ static void clk_gate_endisable (struct clk *clk,int enable) { -struct clk_gate *gate =to_clk_gate (clk_dev_binded (clk) ? -dev_get_clk_ptr (clk->dev) : clk); +struct clk_gate *gate =to_clk_gate (clk);int set = gate->flags &CLK_GATE_SET_TO_DISABLE ?1 :0 ;u32 reg;@@ -86,8 +85,7 @@ static int clk_gate_disable(struct clk *clk)int clk_gate_is_enabled (struct clk *clk) { -struct clk_gate *gate =to_clk_gate (clk_dev_binded (clk) ? -dev_get_clk_ptr (clk->dev) : clk); +struct clk_gate *gate =to_clk_gate (clk);u32 reg;#if CONFIG_IS_ENABLED (SANDBOX_CLK_CCF )drivers/clk/clk-mux.c +4
-8@@ -35,8 +35,7 @@int clk_mux_val_to_index (struct clk *clk,u32 *table,unsigned int flags,unsigned int val) { -struct clk_mux *mux =to_clk_mux (clk_dev_binded (clk) ? -dev_get_clk_ptr (clk->dev) : clk); +struct clk_mux *mux =to_clk_mux (clk);int num_parents = mux->num_parents;if (table) {@@ -79,8 +78,7 @@ unsigned int clk_mux_index_to_val(u32 *table, unsigned int flags, u8 index) u8 clk_mux_get_parent(struct clk *clk) { - struct clk_mux *mux = to_clk_mux(clk_dev_binded(clk) ? -dev_get_clk_ptr (clk->dev) : clk); + struct clk_mux *mux = to_clk_mux(clk);u32 val;#if CONFIG_IS_ENABLED (SANDBOX_CLK_CCF )@@ -97,8 +95,7 @@ u8 clk_mux_get_parent(struct clk *clk)static int clk_fetch_parent_index (struct clk *clk,struct clk *parent) { -struct clk_mux *mux =to_clk_mux (clk_dev_binded (clk) ? -dev_get_clk_ptr (clk->dev) : clk); +struct clk_mux *mux =to_clk_mux (clk);int i;@@ -115,8 +112,7 @@ static int clk_fetch_parent_index(struct clk *clk,static int clk_mux_set_parent (struct clk *clk,struct clk *parent) { -struct clk_mux *mux =to_clk_mux (clk_dev_binded (clk) ? -dev_get_clk_ptr (clk->dev) : clk); +struct clk_mux *mux =to_clk_mux (clk);int index;u32 val;u32 reg;drivers/clk/imx/clk-gate2.c +1
-1@@ -37,7 +37,7 @@ struct clk_gate2 {static int clk_gate2_enable (struct clk *clk) { -struct clk_gate2 *gate =to_clk_gate2 (dev_get_clk_ptr (clk->dev)); +struct clk_gate2 *gate =to_clk_gate2 (clk);u32 reg;drivers/clk/imx/clk-gate2.c +1
-1reg =readl (gate->reg);@@ -50,7 +50,7 @@ static int clk_gate2_enable(struct clk *clk)static int clk_gate2_disable (struct clk *clk) { -struct clk_gate2 *gate =to_clk_gate2 (dev_get_clk_ptr (clk->dev)); +struct clk_gate2 *gate =to_clk_gate2 (clk);u32 reg;
Quoted 1 line
reg =
readl(gate->reg);
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200126/35d7b875/attachment.sig>
PATCH v2 1/11 clk: Always use the supplied struct clk
Hi Lukasz,
Thanks for the feedback.
Quoted 8 lines · Lukasz Majewski
Hi Sean,
Quoted 2 lines
CCF clocks should always use the struct clock passed to their methods for extracting the driver-specific clock information struct.
This couldn't be done for i.MX8 at least. There was an issue with composite clock on this SoC.
Quoted 7 lines
(I've CC'ed Peng, who did this work for i.MX8 - I was testing/developing the framework for i.MX6Q which doesn't support composite clocks).
For some design decisions and the "overall picture" of CCF , please see following doc entry:
https://gitlab.denx.de/u-boot/u-boot/blob/master/doc/imx/clk/ccf.txt
That documentation was helpful, but it tends to focus more on the "what" than the "why." Perhaps I can help update it when I have a better grasp on the CCF.
Quoted 32 lines
Quoted 2 lines
Previously, many functions would use the
clk->dev->privif the device was bound. This could cause problems with composite clocks.The problem (in short) is with combining Linux CCF design and U-Boot's DM (more details in the link above).
All the clocks are linked with struct udevice (one search the linked list for proper clock).
However, with Linux the "main" clock structure is 'struct clk, which is embedded in CLK IP block specific structure (i.e. struct
clk_gate2).Problem is that from struct clk we do have pointer to struct udevice (*dev), but there is no direct pointer "up" from struct udevice to struct clk (now we do use udevice's->uclass_priv).
So far so good ....
Problem started with iMX8, where we do have a composite clocks, which would like to be seen as a single one (like struct pllX), but they comprise of a few other "clocks".
To distinct them the
clk_dev_binded()was added, which checks if the struct udevice represents "top" composite clock (which shall be visible with e.g. 'clk' command)Quoted 5 lines
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.
Quoted 3 lines
Wasn't there any back pointer available? Or do we need to search the clocks linked list and look for "bind" flag in top level composite clock?
This is just what the clk_get_parent [1] function does.
[1] https://gitlab.denx.de/u-boot/u-boot/blob/master/drivers/clk/clk-uclass.c#L447
Quoted 10 lines
Quoted 7 lines
This caused the
recalc_rate
method of the CCF divider clock to fail. One option would be to use theclk->privfield 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.Maybe we shall follow:
https://gitlab.denx.de/u-boot/u-boot/blob/master/doc/imx/clk/ccf.txt#L40
I think this might be a better option. I just didn't see any other uses of this pointer in the u-boot code.
Quoted 6 lines
Quoted 3 lines
The simple solution to this problem is to just always use the supplied struct clock.
I think that we took this approach in the past. Unfortunately, this caused all clocks being exposed when 'clk' command was run.
This is discussed further below, but an easy option is to just not register the component clocks.
The real problem with the current approach (IMO) is that there is a mismatch between the clock structure and the clock function. If one calls clk_get_rate on some clock, the get_rate function is chosen based on clk->dev->ops. If that clock is a composite clock, the clk_composite_get_rate will then choose the *real* get_rate function to call, and will call it with the appropriate component clock. But then, the get_rate function says "Aha, I know better than you what clock should be passed to me" and calls itself with the composite clock struct instead! This is really unintitive behaviour. If anything, this kind of behaviour should be moved up to clk_get_rate, where it can't cause any harm in composite clocks.
Quoted 11 lines
Peng - were there any other issues with i.MX8 composite clock implementation?
Quoted 6 lines
The composite clock now fills in the ->dev
pointer of its child clocks. This allows child clocks to make calls likeclk_get_parent()without issue.imx avoided the above problem by using a custom
get_ratefunction with composite clocks.
Quoted 7 lines
Do you refer to:
https://gitlab.denx.de/u-boot/u-boot/blob/master/drivers/clk/imx/clk-composite-8m.c#L30There the clk is cast from (struct
clk_composite*)clk->data(now in U-Boot we do have 4! different implementations of struct clk).
Yes. This was really surprising when I saw it the first time, since it is effectively bypassing clk_composite_*.
Quoted 46 lines
Quoted 40 lines
Signed-off-by Sean Anderson <[email protected]>--- drivers/clk/clk-composite.c | 8 ++++++++ drivers/clk/clk-divider.c | 6 ++---- drivers/clk/clk-fixed-factor.c | 3 +-- drivers/clk/clk-gate.c | 6 ++---- drivers/clk/clk-mux.c | 12 ++++-------- drivers/clk/imx/clk-gate2.c | 4 ++-- 6 files changed, 19 insertions(+), 20 deletions(-)drivers/clk/clk-composite.c +8
-0@@ -145,6 +145,14 @@ struct clk *clk_register_composite(struct device *dev, const char *name, goto err; } +if (composite->mux) + composite->mux->dev = clk->dev; +if (composite->rate) + composite->rate->dev = clk->dev; +if (composite->gate) + composite->gate->dev = clk->dev; + +return clk; err:drivers/clk/clk-divider.c +0
-1@@ -70,8 +70,7 @@ unsigned long divider_recalc_rate(struct clk *hw, unsigned long parent_rate, static ulong clk_divider_recalc_rate(struct clk *clk) { - struct clk_divider *divider =to_clk_divider(clk_dev_binded(clk) ?
drivers/clk/clk-divider.c
Quoted 2 lines
drivers/clk/clk-divider.c +1
-1- dev_get_clk_ptr(clk->dev) : clk); +struct clk_divider *divider =to_clk_divider (clk);How do you differentiate the "top" level of composite clock from the clocks from which the composite clock is built?
Quoted 1 line
Now we do use the
clk_dev_binded().
With how I am using it, the clocks from which the composite clock are built are not registered with dm [2]. The only clock which gets bound is the composite clock. This follows the example in [3]. Since all the parameters are known at compile-time, I could even just have a big array with all the struct clk_dividers (or other component clocks) I need. However, I chose to model the imx code.
[2] https://github.com/Forty-Bot/u-boot/blob/maix_v3/drivers/clk/kendryte/clk.c#L84
[3] https://gitlab.denx.de/u-boot/u-boot/blob/master/drivers/clk/imx/clk-composite-8m.c#L117
--Sean
PATCH v2 1/11 clk: Always use the supplied struct clk
Hi Sean,
Quoted 18 lines
Hi Lukasz,
Thanks for the feedback.
Quoted 13 lines · Lukasz Majewski
Hi Sean,
Quoted 3 lines
CCF clocks should always use the struct clock passed to their methods for extracting the driver-specific clock information struct.
This couldn't be done for i.MX8 at least. There was an issue with composite clock on this SoC.
(I've CC'ed Peng, who did this work for i.MX8 - I was testing/developing the framework for i.MX6Q which doesn't support composite clocks).
Quoted 8 lines
Quoted 4 lines
For some design decisions and the "overall picture" of CCF , please see following doc entry:
https://gitlab.denx.de/u-boot/u-boot/blob/master/doc/imx/clk/ccf.txtThat documentation was helpful, but it tends to focus more on the "what" than the "why." Perhaps I can help update it when I have a better grasp on the CCF.
Update is more than welcome, as I was the only author of this document. (It would be good to have it checked from the other "angle").
Quoted 35 lines
Quoted 35 lines
Quoted 4 lines
Previously, many functions would use the
clk->dev->privif the device was bound. This could cause problems with composite clocks.The problem (in short) is with combining Linux CCF design and U-Boot's DM (more details in the link above).
All the clocks are linked with struct udevice (one search the linked list for proper clock).
However, with Linux the "main" clock structure is 'struct clk, which is embedded in CLK IP block specific structure (i.e. struct
clk_gate2).Problem is that from struct clk we do have pointer to struct udevice (*dev), but there is no direct pointer "up" from struct udevice to struct clk (now we do use udevice's->uclass_priv).
So far so good ....
Problem started with iMX8, where we do have a composite clocks, which would like to be seen as a single one (like struct pllX), but they comprise of a few other "clocks".
To distinct them the
clk_dev_binded()was added, which checks if the struct udevice represents "top" composite clock (which shall be visible with e.g. 'clk' command)Quoted 5 lines
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.
Quoted 8 lines
Quoted 3 lines
Wasn't there any back pointer available? Or do we need to search the clocks linked list and look for "bind" flag in top level composite clock?
This is just what the
clk_get_parent[1] function does.[1]
https://gitlab.denx.de/u-boot/u-boot/blob/master/drivers/clk/clk-uclass.c#L447
Ach. Right.
Then the struct clk is used - and as those clocks are not bound to device (to avoid having it visible in e.g. dm tree command output) the clk is passed instead.
It works because the struct clk_composite (defined @ clk-provider.h) has embedded struct clk in it and with container_of we get clk_ops....
Quoted 18 lines
Quoted 10 lines
Quoted 9 lines
This caused the
recalc_rate
method of the CCF divider clock to fail. One option would be to use theclk->privfield 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.Quoted 3 lines
Maybe we shall follow:
https://gitlab.denx.de/u-boot/u-boot/blob/master/doc/imx/clk/ccf.txt#L40I think this might be a better option. I just didn't see any other uses of this pointer in the u-boot code.
Quoted 1 line
Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
The simple solution to this problem is to just always use the supplied struct clock.
I think that we took this approach in the past. Unfortunately, this caused all clocks being exposed when 'clk' command was run.
This is discussed further below, but an easy option is to just not register the component clocks.
You probably mean to not register clocks which 'struct clk' is embedded in struct clk_composite?
Yes, this is what we do want - as we get:
foo (composite clock): ----------------> pll2 ----------> MUX2 ------> gate2
And in dm tree we do want to only see the 'foo'.
Quoted 5 lines
The real problem with the current approach (IMO) is that there is a mismatch between the clock structure and the clock function. If one calls
clk_get_rateon some clock, theget_ratefunction is chosen based onclk->dev->ops.
Yes, exactly. This seems logical to me -> the "top" structure is struct clk, which is a device with proper ops.
(And in U-Boot the 'central' data structure with DM is struct udevice).
Quoted 2 lines
If that clock is a composite clock, the
clk_composite_get_rate
I've found only clk_composite_set_rate @ drivers/clk/clk-composite.c
But, yes it calls its own clk_ops (*mux_ops, *rate_ops, *gate_ops).
Quoted 2 lines
will then choose the *real*
get_ratefunction
to call, and will call it with the appropriate component clock.
Yes, the struct clk_composite has several clocks defined.
Quoted 4 lines
But
then, theget_ratefunction says "Aha, I know better than you what clock should be passed to me" and calls itself with the composite clock struct instead!
Wouldn't clk_get_rate just return 0 when it discovers that clk->dev is NULL for not bound driver (the clk which builds a composite driver)?
Quoted 3 lines
This is really unintitive behaviour. If
anything, this kind of behaviour should be moved up toclk_get_rate, where it can't cause any harm in composite clocks.
Even better, the composite clocks shall be handled in the same way as non composite ones.
To achieve that:
1. The struct clk shall be passed to all clk functions (IIRC this is now true in U-Boot):
- then clk IP block specific structure (e.g. struct clk_gate2) are accessible via container_of on clk pointer
- There shall be clk->dev filled always. In the dev one shall use dev->ops to do the necessary work (even for composite clocks components)
- The struct clk has flags field (clk->flags). New flags:
-- CCF_CLK_COMPOSITE_REGISTERED (visible with dm tree)
-- CCF_CLK_COMPOSITE_HIDDEN (used internally to
gate, mux, etc. the composite clock)
-- clk->dev->flags with CCF_CLK_COMPOSITE_REGISTERED set puts all "servant" clocks to its child_head list (clk->dev->child_head).
__OR__
-- we extend the ccf core to use struct uc_clk_priv (as described:
https://gitlab.denx.de/u-boot/u-boot/blob/master/doc/imx/clk/ccf.txt#L40)
which would have
struct uc_clk_priv {
struct clk *c; /* back pointer to clk */
struct clk_composite *cc;
};
struct clk_composite {
struct clk *mux;
struct clk *gate;
...
(no ops here - they shall be in struct udevice)
};
The overhead is to have extra 4 bytes (or use union and check CCF_CLK_COMPOSITE flags).
For me the more natural seems the approach with using clk->dev->child_head (maybe with some extra new flags defined). U-Boot handles lists pretty well and maybe OF_PLATDATA could be used as well.
Sean, Peng, Simon, feel free to give your ideas and comments about possible solutions.
Quoted 15 lines
Quoted 15 lines
Peng - were there any other issues with i.MX8 composite clock implementation?
Quoted 6 lines
The composite clock now fills in the ->dev
pointer of its child clocks. This allows child clocks to make calls likeclk_get_parent()without issue.imx avoided the above problem by using a custom
get_ratefunction with composite clocks.Do you refer to:
https://gitlab.denx.de/u-boot/u-boot/blob/master/drivers/clk/imx/clk-composite-8m.c#L30
Quoted 7 lines
Quoted 4 lines
There the clk is cast from (struct
clk_composite*)clk->data(now in U-Boot we do have 4! different implementations of struct clk).
Yes. This was really surprising when I saw it the first time, since it is effectively bypassing clk_composite_*.
Unfortunately, two struct clks are from Broadcomm devices, one for some Linux video port and the fourth supports U-Boot's driver model (DM).
Quoted 56 lines
Quoted 47 lines
Quoted 41 lines
Signed-off-by Sean Anderson <[email protected]>--- drivers/clk/clk-composite.c | 8 ++++++++ drivers/clk/clk-divider.c | 6 ++---- drivers/clk/clk-fixed-factor.c | 3 +-- drivers/clk/clk-gate.c | 6 ++---- drivers/clk/clk-mux.c | 12 ++++-------- drivers/clk/imx/clk-gate2.c | 4 ++-- 6 files changed, 19 insertions(+), 20 deletions(-)(quoted diff) +0
-0
b/drivers/clk/clk-composite.cindexa5626c33d1..d0f273d47f100644drivers/clk/clk-composite.c +8
-0@@ -145,6 +145,14 @@ struct clk *clk_register_composite(struct device *dev, const char *name, goto err; } +if (composite->mux) + composite->mux->dev = clk->dev; +if (composite->rate) + composite->rate->dev = clk->dev; +if (composite->gate) + composite->gate->dev = clk->dev; + +return clk; err:drivers/clk/clk-divider.c +0
-1@@ -70,8 +70,7 @@ unsigned long divider_recalc_rate(struct clk *hw, unsigned long parent_rate, static ulong clk_divider_recalc_rate(struct clk *clk) { - struct clk_divider *divider =to_clk_divider(clk_dev_binded(clk) ?
drivers/clk/clk-divider.c
Quoted 2 lines
drivers/clk/clk-divider.c +1
-1- dev_get_clk_ptr(clk->dev) : clk); +struct clk_divider *divider =to_clk_divider (clk);How do you differentiate the "top" level of composite clock from the clocks from which the composite clock is built?
Quoted 1 line
Now we do use the
clk_dev_binded().With how I am using it, the clocks from which the composite clock are built are not registered with dm [2]. The only clock which gets bound is the composite clock. This follows the example in [3]. Since all the parameters are known at compile-time, I could even just have a big array with all the struct
clk_dividers(or other component clocks) I need. However, I chose to model the imx code.
Quoted 7 lines
[2]
https://github.com/Forty-Bot/u-boot/blob/maix_v3/drivers/clk/kendryte/clk.c#L84
[3]
https://gitlab.denx.de/u-boot/u-boot/blob/master/drivers/clk/imx/clk-composite-8m.c#L117--Sean
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200128/8e31ea41/attachment.sig>
PATCH v2 1/11 clk: Always use the supplied struct clk
Quoted 21 lines · Lukasz Majewski
Quoted 4 lines
The real problem with the current approach (IMO) is that there is a mismatch between the clock structure and the clock function. If one calls
clk_get_rateon some clock, theget_ratefunction is chosen based onclk->dev->ops.Yes, exactly. This seems logical to me -> the "top" structure is struct clk, which is a device with proper ops.
(And in U-Boot the 'central' data structure with DM is struct udevice).Quoted 2 lines
If that clock is a composite clock, the
clk_composite_get_rateI've found only
clk_composite_set_rate@drivers/clk/clk-composite.cBut, yes it calls its own
clk_ops(*mux_ops,*rate_ops,*gate_ops).Quoted 2 lines
will then choose the *real*
get_ratefunction
to call, and will call it with the appropriate component clock.Yes, the struct
clk_compositehas several clocks defined.
Quoted 7 lines
Quoted 4 lines
But
then, theget_ratefunction says "Aha, I know better than you what clock should be passed to me" and calls itself with the composite clock struct instead!Wouldn't
clk_get_ratejust return 0 when it discovers thatclk->devis NULL for not bound driver (the clk which builds a composite driver)?
Yes, but then clk_get_parent throws a fit, which gets called by clk_gate_*, clk_fixed_divider_*, clk_mux_*, etc. So this description is really for the case where only the first section of this patch is applied.
Quoted 8 lines
Quoted 3 lines
This is really unintitive behaviour. If
anything, this kind of behaviour should be moved up toclk_get_rate, where it can't cause any harm in composite clocks.Even better, the composite clocks shall be handled in the same way as non composite ones.
Quoted 6 lines
To achieve that:
1. The struct clk shall be passed to all clk functions (IIRC this is now true in U-Boot):
- then clk IP block specific structure (e.g. structclk_gate2) are accessible viacontainer_ofon clk pointer
Ok, so I'm a bit confused about the design decisions here. It seems to me that there are two uses for struct clk:
- struct clk as used by drivers not using the CCF. Here, the structure is effectively an extended parameter list, containing all the data needed to operate on some clock. clk->dev->priv contains whatever the driver wants, and doesn't necessarily have a struct clk. Because these clocks are mostly just parameters, they can be created with xlate and request; there is no one "canonical" struct clk for any given logical clock. These clocks can appear on a device tree, and be acquired by clk_get_by_*.
- struct clk as used by CCF clocks. Here the structure contains specific information configuring each clock. Each struct clk refers to a different logical clock. clk->dev->priv contains a struct clk (though this may not be the same struct clk). These clocks cannot appear in a device tree, and hence cannot be acquired by clk_get_by_* (except for clk_get_by_id which doesn't use the device tree). These clocks are not created by xlate and request.
With this in mind, I'm not sure why one would ever need to call dev_get_clk_ptr. In the first case, clk->dev->priv could be anything, and probably not a clock. In the second case, one already has the "canonical" struct clk.
Quoted 3 lines
- There shall be clk->dev filled always. In the dev one shall use dev->ops to do the necessary work (even for composite clocks components)
Do you mean having a struct device for every clock, even components of a composite clock? I think this is unnecessary, especially for a system with lots of composite clocks. Storing the clock ops in the composite clock's struct works fine, and is conceptually simple.
Quoted 35 lines
- The struct clk has flags field (clk->flags). New flags: -- CCF_CLK_COMPOSITE_REGISTERED (visible with dm tree) -- CCF_CLK_COMPOSITE_HIDDEN (used internally to gate, mux, etc. the composite clock) -- clk->dev->flags with CCF_CLK_COMPOSITE_REGISTERED set puts all "servant" clocks to its child_head list (clk->dev->child_head). __OR__ -- we extend the ccf core to use struct uc_clk_priv (as described: https://gitlab.denx.de/u-boot/u-boot/blob/master/doc/imx/clk/ccf.txt#L40) which would have struct uc_clk_priv { struct clk *c; /* back pointer to clk */ struct clk_composite *cc; }; struct clk_composite { struct clk *mux; struct clk *gate; ... (no ops here - they shall be in struct udevice) }; The overhead is to have extra 4 bytes (or use union and check CCF_CLK_COMPOSITE flags).
Quoted 4 lines
For me the more natural seems the approach with using
clk->dev->child_head(maybe with some extra new flags defined). U-Boot handles lists pretty well and maybeOF_PLATDATAcould be used as well.
I like the private data approach, but couldn't we use the existing clk->data field? E.g. instead of having
struct clk_foo {
struct clk clk;
/* ... */
};clk_register_foo(...)
{
struct clk_foo *foo;
struct clk *clk;
foo = kzalloc(sizeof(*foo));
/* ... */
clk = foo->clk;
clk_register(...);
}int clk_foo_get_rate(struct clk *clk)
{
struct clk_foo *foo = to_clk_foo(clk);
/* ... */
}we do
struct clk_foo {
/* ... */
};clk_register_foo(...)
{
struct clk_foo *foo;
struct clk *clk;
foo = kzalloc(sizeof(*foo));
clk = kzalloc(sizeof(*clk));
/* ... */
clk->data = foo;
clk_register(...);
}int clk_foo_get_rate(struct clk *clk)
{
struct clk_foo *foo = (struct clk_foo *)clk->data;
/* ... */
}Of course, now that I have written this all out, it really feels like the container_of approach all over again...
I think the best way of approaching this may be to simply introduce a get_parent op. CCF already does something like this with clk_mux_get_parent. This would also allow for some clocks to have a NULL ->dev.
--Sean
PATCH v2 1/11 clk: Always use the supplied struct clk
Hi Sean,
Quoted 27 lines · Lukasz Majewski
Quoted 26 lines
Quoted 4 lines
The real problem with the current approach (IMO) is that there is a mismatch between the clock structure and the clock function. If one calls
clk_get_rateon some clock, theget_ratefunction is chosen based onclk->dev->ops.Yes, exactly. This seems logical to me -> the "top" structure is struct clk, which is a device with proper ops.
(And in U-Boot the 'central' data structure with DM is struct udevice).Quoted 2 lines
If that clock is a composite clock, the
clk_composite_get_rateI've found only
clk_composite_set_rate@drivers/clk/clk-composite.cBut, yes it calls its own
clk_ops(*mux_ops,*rate_ops,*gate_ops).Quoted 2 lines
will then choose the *real*
get_ratefunction
to call, and will call it with the appropriate component clock.Yes, the struct
clk_compositehas several clocks defined.Quoted 4 lines
But
then, theget_ratefunction says "Aha, I know better than you what clock should be passed to me" and calls itself with the composite clock struct instead!
Quoted 5 lines
Quoted 3 lines
Wouldn't
clk_get_ratejust return 0 when it discovers thatclk->devis NULL for not bound driver (the clk which builds a composite driver)?Yes, but then
clk_get_parentthrows a fit, which gets called by
Could you explain what "throw a fit" means here? I'm a bit confused.
Quoted 19 lines
clk_gate_*, clk_fixed_divider_*, clk_mux_*, etc. So this description is really for the case where only the first section of this patch is applied.
Quoted 8 lines
Quoted 3 lines
This is really unintitive behaviour. If
anything, this kind of behaviour should be moved up toclk_get_rate, where it can't cause any harm in composite clocks.Even better, the composite clocks shall be handled in the same way as non composite ones.
Quoted 6 lines
To achieve that:
1. The struct clk shall be passed to all clk functions (IIRC this is now true in U-Boot):
- then clk IP block specific structure (e.g. structclk_gate2) are accessible viacontainer_ofon clk pointer
Quoted 11 lines
Ok, so I'm a bit confused about the design decisions here. It seems to me that there are two uses for struct clk:
- struct clk as used by drivers not using the CCF. Here, the structure is effectively an extended parameter list, containing all the data needed to operate on some clock.clk->dev->privcontains whatever the driver wants, and
doesn't necessarily have a struct clk. Because these clocks are mostly
just parameters, they can be created with xlate and request; there is no one "canonical" struct clk for any given logical clock. These clocks can appear on a device tree, and be acquired by clk_get_by_*.
Yes.
Quoted 4 lines
- struct clk as used by CCF clocks. Here the structure
contains specific information configuring each clock. Each struct clkrefers to a different logical clock. clk->dev->privcontains a struct clk (though this may not be the same struct clk).
The struct clk pointer is now stored in the struct's udevice uclass_priv pointer.
For CCF it looks like below:
struct clk_gate2 -> struct clk -> struct udevice *dev -> struct udevice
/|\ | | | -------------uclass_priv<------------
Quoted 1 line
These clocks cannot appear in a device tree
I think they could, but I've followed the approach of Linux CCF in e.g. i.MX6Q SoC.
Quoted 4 lines
, and hence cannot be
acquired by clk_get_by_* (except forclk_get_by_idwhich doesn't use the device tree). These clocks are not created
by xlate and request.
Correct. Those clocks are instantiated in SoC specific file. For example in ./drivers/clk/imx/clk-imx6q.c
Quoted 4 lines
With this in mind, I'm not sure why one would ever need to call
dev_get_clk_ptr. In the first case,clk->dev->privcould be anything, and probably not a clock. In the second case, one already has the "canonical" struct clk.
The problem is that clocks are linked together with struct udevice (_NOT_ struct clk). All clocks are linked together and have the same uclass - UCLASS_CLK.
To access clock - one needs to search this doubly linked list and you get struct udevice from it.
(for example in ./cmd/clk.c)
And then you need a "back pointer" to struct clk to use clock ops/functions. And this back pointer is stored in struct udevice's uclass_priv pointer (accessed via dev_get_clk_ptr).
Quoted 9 lines
Quoted 4 lines
- There shall be
clk->devfilled always. In the dev one
shall usedev->opsto do the necessary work (even for composite
clocks components)Do you mean having a struct device for every clock, even components of a composite clock? I think this is unnecessary, especially for a system with lots of composite clocks. Storing the clock ops in the composite clock's struct works fine, and is conceptually simple.
I agree. We shall avoid creating/instantiating unnecessary udevices.
Quoted 41 lines
Quoted 32 lines
- The struct clk has flags field (
clk->flags). New flags:
--CCF_CLK_COMPOSITE_REGISTERED(visible with dm
tree) --CCF_CLK_COMPOSITE_HIDDEN(used internally togate, mux, etc. the composite clock) -- clk->dev->flags with CCF_CLK_COMPOSITE_REGISTERED set puts all "servant" clocks to its child_head list (clk->dev->child_head). __OR__ -- we extend the ccf core to use struct uc_clk_priv (as described: https://gitlab.denx.de/u-boot/u-boot/blob/master/doc/imx/clk/ccf.txt#L40) which would have struct uc_clk_priv { struct clk *c; /* back pointer to clk */ struct clk_composite *cc; }; struct clk_composite { struct clk *mux; struct clk *gate; ... (no ops here - they shall be in structudevice) };
Quoted 8 lines
The overhead is to have extra 4 bytes (or use union
and checkCCF_CLK_COMPOSITEflags).For me the more natural seems the approach with using
clk->dev->child_head(maybe with some extra new flags defined). U-Boot handles lists pretty well and maybeOF_PLATDATAcould be used as well.
Quoted 5 lines
I like the private data approach, but couldn't we use the existing
clk->datafield? E.g. instead of havingstruct clk_foo { struct clk clk;
This is the approach took from the Linux kernel. This is somewhat similar to having the struct clk_hw:
https://elixir.bootlin.com/linux/latest/source/drivers/clk/imx/clk-gate2.c#L27
Quoted 28 lines
/* ... */ };
clk_register_foo(...){ struct clk_foo *foo; struct clk *clk; foo = kzalloc(sizeof(*foo)); /* ... */ clk = foo->clk; clk_register(...); }int
clk_foo_get_rate(struct clk *clk){ struct clk_foo *foo = to_clk_foo(clk); /* ... */ }we do
struct clk_foo { /* ... */ };
clk_register_foo(...)
Quoted 9 lines
{
struct clk_foo *foo;
struct clk *clk;
foo = kzalloc(sizeof(*foo));
clk = kzalloc(sizeof(*clk));
/* ... */
clk->data = foo;According to the description of struct clk definition (@ ./include/clk.h) the data field has other purposes.
Maybe we shall add a new member of struct clk?
Quoted 11 lines
clk_register(...); }int
clk_foo_get_rate(struct clk *clk){ struct clk_foo *foo = (struct clk_foo *)clk->data; /* ... */ }Of course, now that I have written this all out, it really feels like the
container_ofapproach all over again...
Indeed. Even the access cost is the same as the struct clk is always placed as the first element of e.g. struct clk_gate2
Quoted 5 lines
I think the best way of approaching this may be to simply introduce a
get_parentop. CCF already does something like this withclk_mux_get_parent. This would also allow for some clocks to have a NULL ->dev.
I've thought about this some time ago and wondered if struct clk shouldn't be extended a bit.
Maybe adding there a pointer to "get_parent" would simplify the overall design of CCF?
Then one could set this callback pointer in e.g. clk_register_gate2 (or clk_register_composite) and set clk->dev to NULL to indicate "composite" clock?
So we would have:
static inline bool is_composite_clk(struct clk *clk)
{
return !clk->dev && clk->flags == CCF_CLK_COMPOSITE;
}I'm just wondering if "normal" clocks shall set this clk->get_parent pointer or continue to use clk->dev->parent?
Quoted 2 lines
--Sean
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200130/0431a6cb/attachment.sig>
PATCH v2 1/11 clk: Always use the supplied struct clk
Hi Lukasz,
Quoted 3 lines · Lukasz Majewski
Quoted 1 line
Yes, but then
clk_get_parentthrows a fit, which gets called byCould you explain what "throw a fit" means here? I'm a bit confused.
Ok, so imagine I have a clk_divider in a composite clock. When clk_get_rate gets called on the composite clock, the composite clock then calls clk_divider_get_rate on the divider clock. The first thing that function does is call clk_get_parent_rate, which in turn calls clk_get_parent. This last call fails because the divider clock has a NULL ->dev. The end behaviour is that the parent rate looks like 0, which causes the divider to in turn return 0 as its rate. So while it doesn't throw a fit, we still end up with a bad result.
Quoted 8 lines
Quoted 4 lines
- struct clk as used by CCF clocks. Here the structure
contains specific information configuring each clock. Each struct clkrefers to a different logical clock. clk->dev->privcontains a struct clk (though this may not be the same struct clk).
The struct clk pointer is now stored in the struct's udevice
uclass_privpointer.
Quoted 7 lines
For CCF it looks like below:
struct
clk_gate2-> struct clk -> struct udevice *dev -> struct udevice/|\ | | | -------------uclass_priv<------------
Right, so at best doing dev_get_clk_ptr(clk->dev) in something like clk_divider_set_rate is a no-op, and at worst it breaks something.
Quoted 4 lines
Quoted 1 line
These clocks cannot appear in a device tree
I think they could, but I've followed the approach of Linux CCF in e.g. i.MX6Q SoC.
They could, but none of them have compatible strings at the moment.
Quoted 18 lines
Quoted 4 lines
, and hence cannot be
acquired by clk_get_by_* (except forclk_get_by_idwhich doesn't use the device tree). These clocks are not created
by xlate and request.Correct. Those clocks are instantiated in SoC specific file. For example in
./drivers/clk/imx/clk-imx6q.cQuoted 4 lines
With this in mind, I'm not sure why one would ever need to call
dev_get_clk_ptr. In the first case,clk->dev->privcould be anything, and probably not a clock. In the second case, one already has the "canonical" struct clk.The problem is that clocks are linked together with struct udevice (_NOT_ struct clk). All clocks are linked together and have the same uclass -
UCLASS_CLK.
Quoted 7 lines
To access clock - one needs to search this doubly linked list and you get struct udevice from it.
(for example in./cmd/clk.c)And then you need a "back pointer" to struct clk to use clock ops/functions. And this back pointer is stored in struct udevice's
uclass_privpointer (accessed viadev_get_clk_ptr).
Right, but clock implementations will never need to do this. Whatever clock they get passed is going to be the clock they should use. This is why I think the calls which I removed were unnecessary.
In fact, through this discussion I think the patch as-submitted is probably the least-disruptive way to make composite clocks work in a useful way. The only thing it does is that sometimes clk->dev->priv != clk, but I don't think that anyone was relying on this being the case.
Quoted 87 lines
Quoted 39 lines
Quoted 30 lines
- The struct clk has flags field (
clk->flags). New flags:
--CCF_CLK_COMPOSITE_REGISTERED(visible with dm
tree) --CCF_CLK_COMPOSITE_HIDDEN(used internally togate, mux, etc. the composite clock) -- clk->dev->flags with CCF_CLK_COMPOSITE_REGISTERED set puts all "servant" clocks to its child_head list (clk->dev->child_head). __OR__ -- we extend the ccf core to use struct uc_clk_priv (as described: https://gitlab.denx.de/u-boot/u-boot/blob/master/doc/imx/clk/ccf.txt#L40) which would have struct uc_clk_priv { struct clk *c; /* back pointer to clk */ struct clk_composite *cc; }; struct clk_composite { struct clk *mux; struct clk *gate; ... (no ops here - they shall be in structudevice) };
Quoted 8 lines
The overhead is to have extra 4 bytes (or use union
and checkCCF_CLK_COMPOSITEflags).For me the more natural seems the approach with using
clk->dev->child_head(maybe with some extra new flags defined). U-Boot handles lists pretty well and maybeOF_PLATDATAcould be used as well.Quoted 5 lines
I like the private data approach, but couldn't we use the existing
clk->datafield? E.g. instead of havingstruct clk_foo { struct clk clk;This is the approach took from the Linux kernel. This is somewhat similar to having the struct
clk_hw:
https://elixir.bootlin.com/linux/latest/source/drivers/clk/imx/clk-gate2.c#L27Quoted 36 lines
/* ... */ };
clk_register_foo(...){ struct clk_foo *foo; struct clk *clk; foo = kzalloc(sizeof(*foo)); /* ... */ clk = foo->clk; clk_register(...); }int
clk_foo_get_rate(struct clk *clk){ struct clk_foo *foo = to_clk_foo(clk); /* ... */ }we do
struct clk_foo { /* ... */ };
clk_register_foo(...){ struct clk_foo *foo; struct clk *clk; foo = kzalloc(sizeof(*foo)); clk = kzalloc(sizeof(*clk)); /* ... */
Quoted 6 lines
Quoted 1 line
clk->data = foo;According to the description of struct clk definition (@
./include/clk.h) the data field has other purposes.Maybe we shall add a new member of struct clk?
Well, the CCF doesn't use xlate or register, so this field is unused at the moment.
Quoted 32 lines
Quoted 4 lines
clk_register(...); }Quoted 8 lines
int
clk_foo_get_rate(struct clk *clk){ struct clk_foo *foo = (struct clk_foo *)clk->data; /* ... */ }Of course, now that I have written this all out, it really feels like the
container_ofapproach all over again...Indeed. Even the access cost is the same as the struct clk is always placed as the first element of e.g. struct
clk_gate2Quoted 5 lines
I think the best way of approaching this may be to simply introduce a
get_parentop. CCF already does something like this withclk_mux_get_parent. This would also allow for some clocks to have a NULL ->dev.I've thought about this some time ago and wondered if struct clk shouldn't be extended a bit.
Maybe adding there a pointer to "
get_parent" would simplify the overall design of CCF?Then one could set this callback pointer in e.g.
clk_register_gate2(orclk_register_composite) and setclk->devto NULL to indicate "composite" clock?
Quoted 6 lines
So we would have:
static inline bool
is_composite_clk(struct clk *clk){ return !clk->dev && clk->flags == CCF_CLK_COMPOSITE; }
What would use that predicate?
Quoted 2 lines
I'm just wondering if "normal" clocks shall set this
clk->get_parentpointer or continue to useclk->dev->parent?
Hm, well after thinking it over, I think with the current system having a method for this would not do anything useful, since you still need to get the ops from the udevice (and then you could just use the default behaviour).
If I could make big sweeping changes clock uclass, I would
do something like:
- Split off of_xlate, request, and free into a new clk_device_ops struct, with an optional pointer to clk_ops
- Create a new struct clk_handle containing id, data, a pointer to struct udevice, and a pointer to struct clk
- Add get_parent to clk_ops and change all ops to work on struct clk_handle
- Add a pointer to clk_ops in struct clk, and remove dev, id, and data.
So for users, the api would look like
struct clk_handle clk = clk_get_by_index(dev, 0, &clk); clk_enable(&clk);
ulong rate = clk_get_rate(&clk);
Method calls would roughly look like
ulong clk_get_rate(struct clk_handle *h)
{
struct clk_ops *ops;
if (h->clk)
ops = h->clk->ops;
else
ops = clk_dev_ops(h->dev)->ops;
return ops->get_rate(h);
}Getting the parent would use h->clk->ops->get_parent if it exists, and otherwise use h->dev to figure it out.
For non-CCF drivers, the implementation could look something like
ulong foo_get_rate(struct clk_handle *h)
{
/* Do something with h->id and h->dev */
}struct foo_clk_ops = {
.get_rate = foo_get_rate,
};
struct foo_clk_driver_ops = {
.ops = &foo_clk_ops,
};For drivers using the CCF, the implementation could look like
struct clk_gate *foo_gate;
int foo_probe(struct udevice *dev)
{
foo_gate = /* ... */;
}int foo_request(struct clk_handle *h)
{
h->clk = foo_gate->clk;
}struct foo_clk_driver_ops = {
.request = foo_request,
};
So why these changes?
- Clear separation between the different duties which are both currently handled by struct clk
- Simplification for drivers using the CCF
- Minimal changes for existing users
- Clock consumers have almost the same api
- Every clock driver will need to be changed, but most drivers which don't use CCF never use any fields in clk other than ->dev and ->id
- No need to get the "canonical" clock, since it is pointed at by clk_handle->clk
- Reduction in memory/driver usage since CCF clocks no longer need a udevice for each clock
- Less function calls since each driver using CCF no longer needs to be a proxy for clock ops
Now these are big changes, and definitely would be the subject of their own patch series. As-is, I think the patch as it exists now is the best way to get the most functionality from clk_composite with the least changes to other code.
--Sean
PATCH v2 1/11 clk: Always use the supplied struct clk
Hi Sean,
Quoted 8 lines
Hi Lukasz,
Quoted 4 lines · Lukasz Majewski
Quoted 1 line
Yes, but then
clk_get_parentthrows a fit, which gets called byCould you explain what "throw a fit" means here? I'm a bit confused.
Quoted 8 lines
Ok, so imagine I have a
clk_dividerin a composite clock. Whenclk_get_rategets called on the composite clock, the composite clock then callsclk_divider_get_rateon the divider clock. The first thing that function does is callclk_get_parent_rate, which in turn callsclk_get_parent. This last call fails because the divider clock has a NULL ->dev. The end behaviour is that the parent rate looks like 0, which causes the divider to in turn return 0 as its rate. So while it doesn't throw a fit, we still end up with a bad result.
Thanks for the explanation. Now it is clear.
Quoted 12 lines
Quoted 12 lines
Quoted 6 lines
- struct clk as used by CCF clocks. Here the structure
contains specific information configuring each clock. Each struct clk refers to a different logical clock.clk->dev->privcontains a struct clk (though this may not be the same struct clk).The struct clk pointer is now stored in the struct's udevice
uclass_privpointer.For CCF it looks like below:
Quoted 7 lines
Quoted 5 lines
struct
clk_gate2-> struct clk -> struct udevice *dev -> struct
udevice /|\ || | -------------uclass_priv<------------Right, so at best doing
dev_get_clk_ptr(clk->dev)in something likeclk_divider_set_rateis a no-op, and at worst it breaks something.
Yes, correct.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
These clocks cannot appear in a device tree
I think they could, but I've followed the approach of Linux CCF in e.g. i.MX6Q SoC.
They could, but none of them have compatible strings at the moment.
Ok.
Just informative - in U-Boot I do use DTS ccf node (for iMX6) to have this driver probed with DM.
Quoted 23 lines
Quoted 23 lines
Quoted 5 lines
, and hence cannot be
acquired by clk_get_by_* (except forclk_get_by_idwhich doesn't use the device tree). These clocks are not
created by xlate and request.Correct. Those clocks are instantiated in SoC specific file. For example in
./drivers/clk/imx/clk-imx6q.cQuoted 4 lines
With this in mind, I'm not sure why one would ever need to call
dev_get_clk_ptr. In the first case,clk->dev->privcould be anything, and probably not a clock. In the second case, one already has the "canonical" struct clk.The problem is that clocks are linked together with struct udevice (_NOT_ struct clk). All clocks are linked together and have the same uclass -
UCLASS_CLK.To access clock - one needs to search this doubly linked list and you get struct udevice from it.
(for example in./cmd/clk.c)
Quoted 6 lines
Quoted 3 lines
And then you need a "back pointer" to struct clk to use clock ops/functions. And this back pointer is stored in struct udevice's
uclass_privpointer (accessed viadev_get_clk_ptr).Right, but clock implementations will never need to do this. Whatever clock they get passed is going to be the clock they should use.
Yes. Correct.
Quoted 2 lines
This
is why I think the calls which I removed were unnecessary.
Those calls were for composite clocks. And as I've pointed out earlier the address of e.g. struct clk_gate2 is the same as first its element - the struct clk in this case.
Quoted 5 lines
In fact, through this discussion I think the patch as-submitted is probably the least-disruptive way to make composite clocks work in a useful way. The only thing it does is that sometimes
clk->dev->priv!= clk, but I don't think that anyone was relying on this being the case.
Then - OK. Please resubmit the patch with section added to doc/imx/clk/ccf.txt
(If possible please also review the rest of this document - more review
- the better).
Quoted 91 lines
Quoted 91 lines
Quoted 40 lines
Quoted 31 lines
- The struct clk has flags field (
clk->flags). New flags:
--CCF_CLK_COMPOSITE_REGISTERED(visible with dm
tree) --CCF_CLK_COMPOSITE_HIDDEN(used internally togate, mux, etc. the composite clock) -- clk->dev->flags with
CCF_CLK_COMPOSITE_REGISTEREDset puts all "servant" clocks to itschild_headlist (clk->dev->child_head).__OR__ -- we extend the ccf core to use struct uc_clk_priv (as described: https://gitlab.denx.de/u-boot/u-boot/blob/master/doc/imx/clk/ccf.txt#L40) which would have struct uc_clk_priv { struct clk *c; /* back pointer to clk */ struct clk_composite *cc; }; struct clk_composite { struct clk *mux; struct clk *gate; ... (no ops here - they shall be in structudevice) };
Quoted 8 lines
The overhead is to have extra 4 bytes (or use
union and checkCCF_CLK_COMPOSITEflags).For me the more natural seems the approach with using
clk->dev->child_head(maybe with some extra new flags defined). U-Boot handles lists pretty well and maybeOF_PLATDATAcould be used as well.Quoted 5 lines
I like the private data approach, but couldn't we use the existing
clk->datafield? E.g. instead of havingstruct clk_foo { struct clk clk;This is the approach took from the Linux kernel. This is somewhat similar to having the struct
clk_hw:
https://elixir.bootlin.com/linux/latest/source/drivers/clk/imx/clk-gate2.c#L27Quoted 37 lines
/* ... */ };
clk_register_foo(...){ struct clk_foo *foo; struct clk *clk; foo = kzalloc(sizeof(*foo)); /* ... */ clk = foo->clk; clk_register(...); }int
clk_foo_get_rate(struct clk *clk){ struct clk_foo *foo = to_clk_foo(clk); /* ... */ }we do
struct clk_foo { /* ... */ };
clk_register_foo(...){ struct clk_foo *foo; struct clk *clk; foo = kzalloc(sizeof(*foo)); clk = kzalloc(sizeof(*clk)); /* ... */ clk->data = foo;
Quoted 7 lines
Quoted 4 lines
According to the description of struct clk definition (@
./include/clk.h) the data field has other purposes.Maybe we shall add a new member of struct clk?
Well, the CCF doesn't use xlate or register, so this field is unused at the moment.
I would prefer to not mix the meaning of struct clk members. The xlate is supposed to work with DM/DTS, so we shall not add any new meaning for it.
Quoted 35 lines
Quoted 35 lines
Quoted 5 lines
clk_register(...); }Quoted 8 lines
int
clk_foo_get_rate(struct clk *clk){ struct clk_foo *foo = (struct clk_foo *)clk->data; /* ... */ }Of course, now that I have written this all out, it really feels like the
container_ofapproach all over again...Indeed. Even the access cost is the same as the struct clk is always placed as the first element of e.g. struct
clk_gate2Quoted 5 lines
I think the best way of approaching this may be to simply introduce a
get_parentop. CCF already does something like this withclk_mux_get_parent. This would also allow for some clocks to have a NULL ->dev.I've thought about this some time ago and wondered if struct clk shouldn't be extended a bit.
Maybe adding there a pointer to "
get_parent" would simplify the overall design of CCF?Then one could set this callback pointer in e.g.
clk_register_gate2(orclk_register_composite) and setclk->devto NULL to indicate "composite" clock?So we would have:
Quoted 7 lines
Quoted 4 lines
static inline bool
is_composite_clk(struct clk *clk){ return !clk->dev && clk->flags == CCF_CLK_COMPOSITE; }What would use that predicate?
This was just my proposition. There is no "solid" use case for this function.
Quoted 75 lines
Quoted 3 lines
I'm just wondering if "normal" clocks shall set this
clk->get_parentpointer or continue to useclk->dev->parent?Hm, well after thinking it over, I think with the current system having a method for this would not do anything useful, since you still need to get the ops from the udevice (and then you could just use the default behaviour).
If I could make big sweeping changes clock uclass, I would do something like:
- Split offof_xlate, request, and free into a newclk_device_opsstruct, with an optional pointer toclk_ops
- Create a new structclk_handlecontaining id, data, a
pointer to struct udevice, and a pointer to struct clk
- Addget_parenttoclk_opsand change all ops to work on
structclk_handle
- Add a pointer toclk_opsin struct clk, and remove dev, id, and data.So for users, the api would look like
struct
clk_handleclk =clk_get_by_index(dev, 0, &clk);clk_enable(&clk);
ulong rate =clk_get_rate(&clk);Method calls would roughly look like
ulong
clk_get_rate(struct clk_handle *h){ struct clk_ops *ops; if (h->clk) ops = h->clk->ops; else ops = clk_dev_ops(h->dev)->ops; return ops->get_rate(h); }Getting the parent would use
h->clk->ops->get_parentif it exists, and otherwise useh->devto figure it out.For non-CCF drivers, the implementation could look something like
ulong
foo_get_rate(struct clk_handle *h){ /* Do something with h->id and h->dev */ }struct
foo_clk_ops= {
.get_rate =foo_get_rate,
};struct foo_clk_driver_ops = { .ops = &foo_clk_ops, };For drivers using the CCF, the implementation could look like
struct
clk_gate*foo_gate;int
foo_probe(struct udevice *dev){ foo_gate = /* ... */; }int
foo_request(struct clk_handle *h){ h->clk = foo_gate->clk; }struct
foo_clk_driver_ops= {
.request =foo_request,
};
Quoted 15 lines
So why these changes?
- Clear separation between the different duties which are both currently handled by struct clk
- Simplification for drivers using the CCF
- Minimal changes for existing users
- Clock consumers have almost the same api
- Every clock driver will need to be changed, but most drivers which don't use CCF never use any fields in clk other than ->dev and ->id
- No need to get the "canonical" clock, since it is pointed at byclk_handle->clk
- Reduction in memory/driver usage since CCF clocks no longer need a udevice for each clock
- Less function calls since each driver using CCF no longer needs to be a proxy for clock ops
Solid arguments.
Quoted 5 lines
Now these are big changes, and definitely would be the subject of their own patch series. As-is, I think the patch as it exists now is the best way to get the most functionality from
clk_compositewith the least changes to other code.
Yes. I do agree here.
Please resubmit the aforementioned patch (with ccf.txt doc extension). I will pull it.
Then, if you like, please prepare the patch set for CCF optimization. We could discuss it in detail until the v2020.04 merge window opens. There shall be enough time to have an agreement and prepare those patches for pulling.
Quoted 2 lines
--Sean
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200131/958c935b/attachment.sig>
PATCH v2 2/11 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.
--- drivers/clk/clk-composite.c | 57 +++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 22 deletions(-)
drivers/clk/clk-composite.c +35 -22
@@ -22,7 +22,10 @@ static u8 clk_composite_get_parent(struct clk *clk) (struct clk *)dev_get_clk_ptr(clk->dev) : clk);struct clk *mux = composite->mux; -return clk_mux_get_parent (mux); +if (mux) +return clk_mux_get_parent (mux); +else +return 0 ; }static int clk_composite_set_parent (struct clk *clk,struct clk *parent)
@@ -32,7 +35,10 @@ static int clk_composite_set_parent(struct clk *clk, struct clk *parent)const struct clk_ops *mux_ops = composite->mux_ops;struct clk *mux = composite->mux; -return mux_ops->set_parent (mux, parent); +if (mux && mux_ops) +return mux_ops->set_parent (mux, parent); +else +return -ENOTSUPP ; }static unsigned long clk_composite_recalc_rate (struct clk *clk)
@@ -42,7 +48,10 @@ static unsigned long clk_composite_recalc_rate(struct clk *clk)const struct clk_ops *rate_ops = composite->rate_ops;struct clk *rate = composite->rate; -return rate_ops->get_rate (rate); +if (rate && rate_ops) +return rate_ops->get_rate (rate); +else +return clk_get_parent_rate (clk); }static ulong clk_composite_set_rate (struct clk *clk,unsigned long rate)
@@ -52,7 +61,10 @@ static ulong clk_composite_set_rate(struct clk *clk, unsigned long rate)const struct clk_ops *rate_ops = composite->rate_ops;struct clk *clk_rate = composite->rate; -return rate_ops->set_rate (clk_rate, rate); +if (rate && rate_ops) +return rate_ops->set_rate (clk_rate, rate); +else +return -ENOTSUPP ; }static int clk_composite_enable (struct clk *clk)
@@ -62,7 +74,10 @@ static int clk_composite_enable(struct clk *clk)const struct clk_ops *gate_ops = composite->gate_ops;struct clk *gate = composite->gate; -return gate_ops->enable (gate); +if (gate && gate_ops) +return gate_ops->enable (gate); +else +return -ENOTSUPP ; }static int clk_composite_disable (struct clk *clk)
@@ -72,15 +87,12 @@ static int clk_composite_disable(struct clk *clk)const struct clk_ops *gate_ops = composite->gate_ops;struct clk *gate = composite->gate; - gate_ops->disable (gate); - -return 0 ; +if (gate && gate_ops) +return gate_ops->disable (gate); +else +return -ENOTSUPP ; } -struct clk_ops clk_composite_ops = { -/* This will be set according to clk_register_composite */ -}; - struct clk *clk_register_composite(struct device *dev, const char *name, const char * const *parent_names, int num_parents, struct clk *mux,
@@ -94,7 +106,9 @@ struct clk *clk_register_composite(struct device *dev, const char *name,struct clk *clk;struct clk_composite *composite;int ret; -struct clk_ops *composite_ops = &clk_composite_ops; + +if (!num_parents || (num_parents !=1 && !mux)) +return ERR_PTR (-EINVAL ); composite =kzalloc (sizeof (*composite),GFP_KERNEL );if (!composite)
@@ -103,8 +117,6 @@ struct clk *clk_register_composite(struct device *dev, const char *name,if (mux && mux_ops) { composite->mux = mux; composite->mux_ops = mux_ops; -if (mux_ops->set_parent) - composite_ops->set_parent = clk_composite_set_parent; mux->data = (ulong )composite; }
@@ -113,11 +125,6 @@ struct clk *clk_register_composite(struct device *dev, const char *name, clk =ERR_PTR (-EINVAL ); goto err; } - composite_ops->get_rate = clk_composite_recalc_rate; - -/* .set_rate requires either .round_rate or .determine_rate */ -if (rate_ops->set_rate) - composite_ops->set_rate = clk_composite_set_rate; composite->rate = rate; composite->rate_ops = rate_ops;
@@ -132,8 +139,6 @@ struct clk *clk_register_composite(struct device *dev, const char *name, composite->gate = gate; composite->gate_ops = gate_ops; - composite_ops->enable = clk_composite_enable; - composite_ops->disable = clk_composite_disable; gate->data = (ulong )composite; }
@@ -160,6 +165,14 @@ err:return clk; } +static const struct clk_ops clk_composite_ops = { + .set_parent = clk_composite_set_parent, + .get_rate = clk_composite_recalc_rate, + .set_rate = clk_composite_set_rate, + .enable = clk_composite_enable, + .disable = clk_composite_disable, +}; +U_BOOT_DRIVER (clk_composite) = { .name =UBOOT_DM_CLK_COMPOSITE , .id =UCLASS_CLK ,
Signature · 1 line
2.24.1
PATCH v2 2/11 clk: Check that ops of composite clock components, exist before calling
Hi Sean,
Quoted 10 lines
clk_composite_opswas shared between all devices in the composite clock driver. If one clock had a feature (such as supportingset_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 makesclk_composite_opsconst and sets its functions at compile-time. 3. It adds some basic sanity checks tonum_parents.
Quoted 5 lines
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_parentwas used to determine the parent forclk_register.
Thank you for those checks - up till now this code was tuned for i.MX (and in-fact this SoC's clock tree).
However, I would like to first wait for the consensus regarding the shape of composite clocks (and reply to this mail):
"clk: Always use the supplied struct clk"
Quoted 137 lines
Signed-off-by Sean Anderson <[email protected]>--- drivers/clk/clk-composite.c | 57+++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 22 deletions(-)
drivers/clk/clk-composite.c +4
-1@@ -22,7 +22,10 @@ static u8 clk_composite_get_parent(struct clk *clk) (struct clk *)dev_get_clk_ptr(clk->dev) : clk);struct clk *mux = composite->mux; -return clk_mux_get_parent (mux); +if (mux) +return clk_mux_get_parent (mux); +else +return 0 ; } static int clk_composite_set_parent(struct clk *clk, struct clk*parent) @@ -32,7 +35,10 @@ static int
clk_composite_set_parent(struct clk *clk, struct clk *parent)const structclk_ops*mux_ops=composite->mux_ops; struct clk *mux =composite->mux;drivers/clk/clk-composite.c +4
-1-return mux_ops->set_parent (mux, parent); +if (mux && mux_ops) +return mux_ops->set_parent (mux, parent); +else +return -ENOTSUPP ; }static unsigned long clk_composite_recalc_rate (struct clk *clk)@@ -42,7 +48,10 @@ static unsigned long
clk_composite_recalc_rate(struct clk *clk)const structclk_ops*rate_ops=composite->rate_ops; struct clk *rate =composite->rate;drivers/clk/clk-composite.c +4
-1-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 longrate) @@ -52,7 +61,10 @@ static ulong
clk_composite_set_rate(struct clk *clk, unsigned long rate)const structclk_ops*rate_ops=composite->rate_ops; struct clk*clk_rate=composite->rate;drivers/clk/clk-composite.c +15
-15-return rate_ops->set_rate (clk_rate, rate); +if (rate && rate_ops) +return rate_ops->set_rate (clk_rate, rate); +else +return -ENOTSUPP ; }static int clk_composite_enable (struct clk *clk)@@ -62,7 +74,10 @@ static int clk_composite_enable(struct clk *clk)const struct clk_ops *gate_ops = composite->gate_ops;struct clk *gate = composite->gate; -return gate_ops->enable (gate); +if (gate && gate_ops) +return gate_ops->enable (gate); +else +return -ENOTSUPP ; }static int clk_composite_disable (struct clk *clk)@@ -72,15 +87,12 @@ static int clk_composite_disable(struct clk *clk)const struct clk_ops *gate_ops = composite->gate_ops;struct clk *gate = composite->gate; - gate_ops->disable (gate); - -return 0 ; +if (gate && gate_ops) +return gate_ops->disable (gate); +else +return -ENOTSUPP ; } -struct clk_ops clk_composite_ops = { -/* This will be set according to clk_register_composite */ -}; - struct clk *clk_register_composite(struct device *dev, const char *name, const char * const *parent_names, int num_parents, struct clk *mux,@@ -94,7 +106,9 @@ struct clk *clk_register_composite(struct device *dev, const char *name, struct clk *clk;struct clk_composite *composite;int ret; -struct clk_ops *composite_ops = &clk_composite_ops; + +if (!num_parents || (num_parents !=1 && !mux)) +return ERR_PTR (-EINVAL ); composite =kzalloc (sizeof (*composite),GFP_KERNEL );if (!composite)@@ -103,8 +117,6 @@ struct clk *clk_register_composite(struct device *dev, const char *name, if (mux && mux_ops) { composite->mux = mux; composite->mux_ops = mux_ops; -if (mux_ops->set_parent) - composite_ops->set_parent = clk_composite_set_parent; mux->data = (ulong )composite; }@@ -113,11 +125,6 @@ struct clk *clk_register_composite(struct device *dev, const char *name, clk = ERR_PTR(-EINVAL); goto err; } - composite_ops->get_rate = clk_composite_recalc_rate; - -/* .set_rate requires either .round_rate or .determine_rate */
drivers/clk/clk-composite.c +0
-2-if (rate_ops->set_rate) - composite_ops->set_rate =
clk_composite_set_rate;drivers/clk/clk-composite.c +1
-2composite->rate = rate; composite->rate_ops = rate_ops;@@ -132,8 +139,6 @@ struct clk *clk_register_composite(struct device *dev, const char *name, composite->gate = gate; composite->gate_ops = gate_ops; - composite_ops->enable = clk_composite_enable; - composite_ops->disable = clk_composite_disable; gate->data = (ulong )composite; }@@ -160,6 +165,14 @@ err:return clk; } +static const struct clk_ops clk_composite_ops = {
drivers/clk/clk-composite.c err: · line 178
Quoted 10 lines
drivers/clk/clk-composite.c +7
-0+ .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 ,
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200126/807181c9/attachment.sig>
PATCH v2 3/11 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.
--- 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 <linux/compiler.h> /* Architecture-specific global data */ struct arch_global_data {
Signature · 1 line
2.24.1
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v2 3/11 riscv: Add headers for asm/global_data.h
Hi Sean,
Quoted 6 lines
From: Sean Anderson [mailto:seanga2 at gmail.com]
Sent: Thursday, January 16, 2020 6:51 AM
To: U-Boot Mailing List
Cc: Rick Jian-Zhi Chen(陳建志)
Subject: [PATCH v2 03/11] riscv: Add headers forasm/global_data.h
Quoted 7 lines
This header depended on
bd_tand ulong, but did not include the appropriate headers.Signed-off-by Sean Anderson <[email protected]>--- arch/riscv/include/asm/global_data.h | 2 ++ 1 file changed, 2 insertions(+)
I wonder why the compiling is OK without those appropriate headers.
Thanks,
Rick
Quoted 15 lines
arch/riscv/include/asm/global_data.h +2
-1@@ -11,6 +11,8 @@#define __ASM_GBL_DATA_H#include <asm/smp.h> +#include <asm/u-boot.h> +#include <linux/compiler.h> /* Architecture-specific global data */ struct arch_global_data { --2.24.1
PATCH v2 3/11 riscv: Add headers for asm/global_data.h
Quoted 1 line
I wonder why the compiling is OK without those appropriate headers.
It's likely that all the uses looked like
#include <this_header_includes_ulong.h>
#include <asm/global_data.h>
So it wasn't noticed until it was included first in some file.
PATCH v2 3/11 riscv: Add headers for asm/global_data.h
In reply to Sean AndersonHi Sean,
Quoted 13 lines · Sean Anderson
This header depended on
bd_tand ulong, but did not include the appropriate headers.Signed-off-by Sean Anderson <[email protected]>--- arch/riscv/include/asm/global_data.h | 2 ++ 1 file changed, 2 insertions(+)arch/riscv/include/asm/global_data.h +0
-0
arch/riscv/include/asm/global_data.h line 16
Quoted 6 lines
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 <linux/compiler.h>
asm/u-boot.h is usually included with common.h. ulong is defined in linux/types.h (also included in common.h). It should be sufficient to include common.h in your source files.
Thanks,
Lukas
PATCH v2 3/11 riscv: Add headers for asm/global_data.h
Quoted 6 lines · Lukas Auer
asm/u-boot.his usually included withcommon.h. ulong is defined inlinux/types.h(also included incommon.h). It should be sufficient to includecommon.hin your source files.Thanks,
Lukas
So shouldn't asm/u-boot.h include common.h? Or is that header implicitly assumed to be included with every source file? Is that documented anywhere? To me, the "default" assumption is that any header should be able to be included anywhere and to pull in all of its own dependencies.
--Sean
PATCH v2 3/11 riscv: Add headers for asm/global_data.h
Quoted 5 lines · Sean Anderson
Quoted 4 lines · Lukas Auer
asm/u-boot.his usually included withcommon.h. ulong is defined inlinux/types.h(also included incommon.h). It should be sufficient to includecommon.hin your source files.
Quoted 8 lines
Quoted 2 lines
Thanks,
LukasSo shouldn't
asm/u-boot.hincludecommon.h? Or is that header implicitly assumed to be included with every source file? Is that documented anywhere? To me, the "default" assumption is that any header should be able to be included anywhere and to pull in all of its own dependencies.
You are right, it is not entirely correct like this. I think common.h is assumed to always be included. Unfortunately, I don't know if this is documented anywhere.
Thanks,
Lukas
PATCH v2 4/11 riscv: Add an option to default to RV64I
In reply to Sean AndersonThis allows 64-bit boards to default to the 64-bit instruction set without changing the current default of 32-bit.
--- arch/riscv/Kconfig | 4 ++++ 1 file changed, 4 insertions(+)
arch/riscv/Kconfig +4 -0
@@ -60,8 +60,12 @@ source "arch/riscv/cpu/generic/Kconfig" # architecture-specific options below +config ARCH_DEFAULT_RV64I + bool + choice prompt "Base ISA" + default ARCH_RV64I if ARCH_DEFAULT_RV64I default ARCH_RV32I config ARCH_RV32I
Signature · 1 line
2.24.1
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v2 4/11 riscv: Add an option to default to RV64I
Hi Sean,
Quoted 16 lines
From: Sean Anderson [mailto:seanga2 at gmail.com]
Sent: Thursday, January 16, 2020 6:52 AM
To: U-Boot Mailing List; Rick Jian-Zhi Chen(陳建志)
Subject: [PATCH v2 04/11] riscv: Add an option to default to RV64IThis allows 64-bit boards to default to the 64-bit instruction set without changing the current default of 32-bit.
Signed-off-by Sean Anderson <[email protected]>--- arch/riscv/Kconfig | 4 ++++ 1 file changed, 4 insertions(+)
arch/riscv/Kconfig source "arch/riscv/cpu/generic/Kconfig" · line 62
Quoted 3 lines
arch/riscv/Kconfig +0
-0@@ -60,8 +60,12 @@ source "arch/riscv/cpu/generic/Kconfig" # architecture-specific options below
This is a redundant declaration.
There have CONFIG_ARCH_RV64I=y already in sipeed_maix_bitm_defconfig
Thanks,
Rick
Quoted 12 lines
arch/riscv/Kconfig +4
-1+config ARCH_DEFAULT_RV64I + bool + choice prompt "Base ISA" + default ARCH_RV64I if ARCH_DEFAULT_RV64I default ARCH_RV32I config ARCH_RV32I --2.24.1
PATCH v2 5/11 riscv: Add option to disable writes to mcounteren
In reply to Sean AndersonOn the kendryte k210, writes to mcounteren result in an illegal instruction exception.
---
Changes for v2:
Moved forward in the patch series
arch/riscv/Kconfig | 3 +++ arch/riscv/cpu/cpu.c | 2 ++ 2 files changed, 5 insertions(+)
arch/riscv/Kconfig +3 -0
@@ -226,6 +226,9 @@ config XIP from a NOR flash memory without copying the code to ram. Say yes here if U-Boot boots from flash directly. +config SYS_RISCV_NOCOUNTER + bool "Disable accesses to the mcounteren CSR" + config STACK_SIZE_SHIFT int default 14
arch/riscv/cpu/cpu.c +2 -0
@@ -89,7 +89,9 @@ int arch_cpu_init_dm(void)* Enable perf counters for cycle, time, * and instret counters only */ +#ifndef CONFIG_SYS_RISCV_NOCOUNTER csr_write (CSR_MCOUNTEREN ,GENMASK (2 ,0 )); +#endif /* Disable paging */ if (supports_extension ('s' ))
Signature · 1 line
2.24.1
PATCH v2 5/11 riscv: Add option to disable writes to mcounteren
+ Bin, Anup, Atish
Quoted 17 lines · Sean Anderson
On the kendryte k210, writes to mcounteren result in an illegal instruction exception.
Signed-off-by Sean Anderson <[email protected]>---
Changes for v2:
Moved forward in the patch seriesarch/riscv/Kconfig | 3 +++ arch/riscv/cpu/cpu.c | 2 ++ 2 files changed, 5 insertions(+)arch/riscv/Kconfig +0
-0
arch/riscv/Kconfig config XIP · line 231
Quoted 6 lines
arch/riscv/Kconfig +3
-0@@ -226,6 +226,9 @@ config XIP from a NOR flash memory without copying the code to ram. Say yes here if U-Boot boots from flash directly. +config SYS_RISCV_NOCOUNTER + bool "Disable accesses to the mcounteren CSR" +
Can you rename this to something like RISCV_PRIV_1_9_1?
The k210 implements version 1.9.1 of the privileged spec (if I remember correctly). The mcounteren CSR doesn't exist in that version and therefore triggers the illegal instruction exception. By renaming the config entry, it is clearer why the CSR is missing and is therefore not accessed.
I am not too familiar with the changes between the versions of the spec. Are there other parts of the code we need to adapt?
Thanks,
Lukas
Quoted 17 lines
arch/riscv/Kconfig +0
-0config STACK_SIZE_SHIFT int default 14arch/riscv/cpu/cpu.c +2
-0@@ -89,7 +89,9 @@ int arch_cpu_init_dm(void)* Enable perf counters for cycle, time, * and instret counters only */ +#ifndef CONFIG_SYS_RISCV_NOCOUNTER csr_write (CSR_MCOUNTEREN ,GENMASK (2 ,0 )); +#endif /* Disable paging */ if (supports_extension ('s' ))
PATCH v2 5/11 riscv: Add option to disable writes to mcounteren
Quoted 30 lines · Lukas Auer
+ Bin, Anup, Atish
Quoted 17 lines · Sean Anderson
On the kendryte k210, writes to mcounteren result in an illegal instruction exception.
Signed-off-by Sean Anderson <[email protected]>---
Changes for v2:
Moved forward in the patch seriesarch/riscv/Kconfig | 3 +++ arch/riscv/cpu/cpu.c | 2 ++ 2 files changed, 5 insertions(+)arch/riscv/Kconfig +0
-0arch/riscv/Kconfig config XIP · line 231
Quoted 6 lines
arch/riscv/Kconfig +3
-0@@ -226,6 +226,9 @@ config XIP from a NOR flash memory without copying the code to ram. Say yes here if U-Boot boots from flash directly. +config SYS_RISCV_NOCOUNTER + bool "Disable accesses to the mcounteren CSR" +Can you rename this to something like
RISCV_PRIV_1_9_1?
Quoted 5 lines
The k210 implements version 1.9.1 of the privileged spec (if I remember correctly). The mcounteren CSR doesn't exist in that version and therefore triggers the illegal instruction exception. By renaming the config entry, it is clearer why the CSR is missing and is therefore not accessed.
Thanks, I was not aware that the k210 was following a different spec when I made the change. For v3 I can add this functionality back using the old counter CSRs.
Quoted 2 lines
I am not too familiar with the changes between the versions of the spec. Are there other parts of the code we need to adapt?
From reading the changelog, most of the changes seem related to virtual memory, which doesn't apply to u-boot.
--Sean
PATCH v2 5/11 riscv: Add option to disable writes to mcounteren
Quoted 41 lines · Sean Anderson
Quoted 30 lines · Lukas Auer
+ Bin, Anup, Atish
Quoted 17 lines · Sean Anderson
On the kendryte k210, writes to mcounteren result in an illegal instruction exception.
Signed-off-by Sean Anderson <[email protected]>---
Changes for v2:
Moved forward in the patch seriesarch/riscv/Kconfig | 3 +++ arch/riscv/cpu/cpu.c | 2 ++ 2 files changed, 5 insertions(+)arch/riscv/Kconfig +0
-0arch/riscv/Kconfig config XIP · line 231
Quoted 6 lines
arch/riscv/Kconfig +3
-0@@ -226,6 +226,9 @@ config XIP from a NOR flash memory without copying the code to ram. Say yes here if U-Boot boots from flash directly. +config SYS_RISCV_NOCOUNTER + bool "Disable accesses to the mcounteren CSR" +Can you rename this to something like
RISCV_PRIV_1_9_1?Quoted 5 lines
The k210 implements version 1.9.1 of the privileged spec (if I remember correctly). The mcounteren CSR doesn't exist in that version and therefore triggers the illegal instruction exception. By renaming the config entry, it is clearer why the CSR is missing and is therefore not accessed.
Thanks, I was not aware that the k210 was following a different spec when I made the change. For v3 I can add this functionality back using the old counter CSRs.
Quoted 6 lines
Quoted 2 lines
I am not too familiar with the changes between the versions of the spec. Are there other parts of the code we need to adapt?
From reading the changelog, most of the changes seem related to virtual memory, which doesn't apply to u-boot.
Ok, great. Thanks for checking!
Regards,
Lukas
PATCH v2 6/11 riscv: Fix incorrect cpu frequency on RV64
In reply to Sean AndersonThe riscv_cpu_get_info function does not always zero-out cpu_freq. This can cause spurious higher frequencies.
Signed-off-by Sean Anderson <[email protected]>
---
Changes for v2:
New.
drivers/cpu/riscv_cpu.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/cpu/riscv_cpu.c +2 -0
@@ -29,6 +29,8 @@ static int riscv_cpu_get_info(struct udevice *dev, struct cpu_info *info) {const char *mmu; +/* Zero out the frequency, in case sizeof(ulong) != sizeof(u32) */ + info->cpu_freq =0 ;dev_read_u32 (dev,"clock-frequency" , (u32 *)&info->cpu_freq); mmu =dev_read_string (dev,"mmu-type" );
Signature · 1 line
2.24.1
PATCH v2 6/11 riscv: Fix incorrect cpu frequency on RV64
Quoted 11 lines · Sean Anderson
The
riscv_cpu_get_infofunction does not always zero-outcpu_freq. This can cause spurious higher frequencies.Signed-off-by Sean Anderson <[email protected]>
---
Changes for v2:
New.drivers/cpu/riscv_cpu.c | 2 ++ 1 file changed, 2 insertions(+)
PATCH v2 7/11 riscv: Add initial 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 for 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 | 41 +++++++++++++ board/sipeed/maix/MAINTAINERS | 13 +++++ board/sipeed/maix/Makefile | 5 ++ board/sipeed/maix/maix.c | 9 +++ configs/sipeed_maix_bitm_defconfig | 93 ++++++++++++++++++++++++++++++ include/configs/sipeed-maix.h | 19 ++++++ 7 files changed, 184 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 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 +41 -0
41 lines not on this page · raw message
board/sipeed/maix/MAINTAINERS new file +13 -0
@@ -0,0 +1,13 @@ +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: arch/riscv/include/asm/k210_sysctl.h +F: arch/riscv/lib/k210_sysctl.c +F: board/sipeed/maix/ +F: configs/sipeed_maix_defconfig +F: drivers/clk/kendryte/ +F: include/configs/sipeed-maix.h +F: include/dt-bindings/clock/k210-sysctl.h +F: include/dt-bindings/reset/k210-sysctl.h
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 +9 -0
@@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2019 Sean Anderson <[email protected]> +*/ + +int board_init (void ) +{ +return 0 ; +}
configs/sipeed_maix_bitm_defconfig new file +93 -0
93 lines not on this page · raw message
include/configs/sipeed-maix.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2019 Sean Anderson <[email protected]> +*/ + +#ifndef CONFIGS_SIPEED_MAIX_H +#define CONFIGS_SIPEED_MAIX_H + +#include <linux/sizes.h> + +#define CONFIG_SYS_LOAD_ADDR 0x80000000 +#define CONFIG_SYS_SDRAM_BASE CONFIG_SYS_LOAD_ADDR +#define CONFIG_SYS_SDRAM_SIZE SZ_8M +/* Start just below AI memory */ +#define CONFIG_SYS_INIT_SP_ADDR 0x805FFFFF +#define CONFIG_SYS_MALLOC_LEN SZ_1K +#define CONFIG_SYS_CACHELINE_SIZE 64 + +#endif /* CONFIGS_SIPEED_MAIX_H */
Signature · 1 line
2.24.1
PATCH v2 7/11 riscv: Add initial Sipeed Maix support
Hi Sean,
Quoted 12 lines · Sean Anderson
The Sipeed Maix series is a collection of boards built around the RISC-V Kendryte K210 processor. This processor contains several peripherals to accelerate neural network processing and other "ai" tasks. This includes a "KPU" neural network processor, an audio processor supporting beamforming reception, and a digital video port supporting capture and output at VGA resolution. Other peripherals include 8M of sram (accessible with and without caching); remappable pins, including 40 GPIOs; AES, FFT, and SHA256 accelerators; a DMA controller; and I2C, I2S, and SPI controllers. Maix peripherals vary, but include spi flash; on-board usb-serial bridges; ports for cameras, displays, and sd cards; and ESP32 chips. Currently, only the Sipeed Maix Bit V2.0 (bitm) is supported, but the boards are fairly similar.
Quoted 7 lines
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>;.Signed-off-by Sean Anderson <[email protected]>
This patch should be the last in the patch series, because it requires all other patches in the series.
Quoted 76 lines
---
Changes for 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 later.arch/riscv/Kconfig | 4 ++ board/sipeed/maix/Kconfig | 41 +++++++++++++ board/sipeed/maix/MAINTAINERS | 13 +++++ board/sipeed/maix/Makefile | 5 ++ board/sipeed/maix/maix.c | 9 +++ configs/sipeed_maix_bitm_defconfig | 93 ++++++++++++++++++++++++++++++ include/configs/sipeed-maix.h | 19 ++++++ 7 files changed, 184 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 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 +23
-0@@ -0,0 +1,41 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (C) 2019 Sean Anderson <[email protected]> + +if TARGET_SIPEED_MAIX + +config SYS_BOARD + default "maix" + +config SYS_VENDOR + default "sipeed" + +config SYS_CPU + default "generic" + +config SYS_CONFIG_NAME + default "sipeed-maix" + +config SYS_TEXT_BASE + default 0x80000000 + +config NR_CPUS + default 2 +
board/sipeed/maix/Kconfig line 33
Quoted 10 lines
board/sipeed/maix/Kconfig new file +10
-0+config NR_DRAM_BANKS + default 2 + +config BOARD_SPECIFIC_OPTIONS + def_bool y + select GENERIC_RISCV + select DM_SERIAL + select SIFIVE_SERIAL + select ARCH_DEFAULT_RV64I + select ENV_IS_NOWHERE
ENV_IS_NOWHERE is automatically selected if no other environment provider is available, so no need to include it here. Also, why are you not using the SD card to store the environment?
Quoted 142 lines
board/sipeed/maix/Kconfig new file +8
-0+ select SYS_RISCV_NOCOUNTER + imply SIFIVE_CLINT + imply SPI + imply DM_GPIO + imply CMD_GPIO + imply SYS_NS16550 + imply SYS_MALLOC_F +endifboard/sipeed/maix/MAINTAINERS new file +13
-0@@ -0,0 +1,13 @@ +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: arch/riscv/include/asm/k210_sysctl.h +F: arch/riscv/lib/k210_sysctl.c +F: board/sipeed/maix/ +F: configs/sipeed_maix_defconfig +F: drivers/clk/kendryte/ +F: include/configs/sipeed-maix.h +F: include/dt-bindings/clock/k210-sysctl.h +F: include/dt-bindings/reset/k210-sysctl.hboard/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 +9
-0@@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2019 Sean Anderson <[email protected]> +*/ + +int board_init (void ) +{ +return 0 ; +}configs/sipeed_maix_bitm_defconfig new file +83
-0@@ -0,0 +1,93 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (C) 2019 Sean Anderson <[email protected]> +CONFIG_CREATE_ARCH_SYMLINK=y +CONFIG_RISCV=y +CONFIG_SYS_ARCH="riscv" +CONFIG_SYS_CPU="generic" +CONFIG_SYS_VENDOR="sipeed" +CONFIG_SYS_BOARD="maix" +CONFIG_SYS_CONFIG_NAME="sipeed-maix" +CONFIG_SPL_LDSCRIPT="arch/riscv/cpu/u-boot-spl.lds" +CONFIG_SYS_TEXT_BASE=0x80000000 +CONFIG_SYS_MALLOC_F_LEN=0x1000 +CONFIG_BOARD_SPECIFIC_OPTIONS=y +CONFIG_NR_DRAM_BANKS=2 +CONFIG_BOOTSTAGE_STASH_ADDR=0 +CONFIG_64BIT=y +CONFIG_TARGET_SIPEED_MAIX=y +CONFIG_NR_CPUS=2 +CONFIG_GENERIC_RISCV=y +CONFIG_ARCH_DEFAULT_RV64I=y +CONFIG_ARCH_RV64I=y +CONFIG_CMODEL_MEDLOW=y +CONFIG_RISCV_MMODE=y +CONFIG_RISCV_ISA_C=y +CONFIG_RISCV_ISA_A=y +CONFIG_SIFIVE_CLINT=y +CONFIG_K210_SYSCTL=y +CONFIG_SYS_RISCV_NOCOUNTER=y +CONFIG_ARCH_K210=y +CONFIG_CC_OPTIMIZE_FOR_SIZE=y +CONFIG_SYS_MALLOC_F=y +CONFIG_PHYS_64BIT=y +# CONFIG_ANDROID_BOOT_IMAGE is not set +# CONFIG_FIT is not set +# CONFIG_LEGACY_IMAGE_FORMAT is not set +CONFIG_LOG=y +CONFIG_ARCH_EARLY_INIT_R=y +CONFIG_CMDLINE=y +CONFIG_CMD_ENV_EXISTS=y +CONFIG_CMD_FLASH=y +CONFIG_CMD_SF=y +CONFIG_CMD_LOG=y +# CONFIG_AUTOBOOT is not set +# CONFIG_CMD_BDI is not set +# CONFIG_CMD_CONSOLE is not set +# CONFIG_CMD_BOOTD is not set +# CONFIG_CMD_BOOTM is not set +# CONFIG_CMD_BOOTZ is not set +CONFIG_CMD_BOOTI=y +CONFIG_BOOTM_LINUX=y +# CONFIG_CMD_ELF is not set +CONFIG_CMD_FDT=y +CONFIG_SUPPORT_OF_CONTROL=y +CONFIG_DTC=y +CONFIG_OF_CONTROL=y +CONFIG_OF_SEPARATE=y +CONFIG_ENV_IS_NOWHERE=y +# CONFIG_NET is not set +CONFIG_DM=y +CONFIG_REGMAP=y +CONFIG_SYSCON=y +CONFIG_SIMPLE_BUS=y +CONFIG_OF_TRANSLATE=y +CONFIG_CLK=y +CONFIG_CLK_CCF=y +CONFIG_CLK_COMPOSITE_CCF=y +CONFIG_CPU=y +CONFIG_CPU_RISCV=y +CONFIG_MMC=y +# CONFIG_INPUT is not set +CONFIG_DM_MMC=y +CONFIG_MMC_SPI=y +CONFIG_MMC_QUIRKS=y +CONFIG_MTD=y +CONFIG_DM_MTD=y +CONFIG_DM_SPI_FLASH=y +CONFIG_SPI_FLASH=y +CONFIG_SPI_FLASH_GIGADEVICE=y +# CONFIG_DM_ETH is not set +# CONFIG_PCI is not set +CONFIG_BAUDRATE=115200 +CONFIG_SERIAL_PRESENT=y +CONFIG_DM_SERIAL=y
configs/sipeed_maix_bitm_defconfig line 93
Quoted 10 lines
configs/sipeed_maix_bitm_defconfig new file +10
-0+CONFIG_SIFIVE_SERIAL=y +CONFIG_SPI=y +CONFIG_DM_SPI=y +CONFIG_SPI_MEM=y +CONFIG_DESIGNWARE_SPI=y +CONFIG_TIMER=y +CONFIG_RISCV_TIMER=y +CONFIG_PANIC_HANG=y +CONFIG_OF_LIBFDT=y +# CONFIG_EFI_LOADER is not set
Please use make savedefconfig to generate the defconfig.
Quoted 15 lines
include/configs/sipeed-maix.h new file +9
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2019 Sean Anderson <[email protected]> +*/ + +#ifndef CONFIGS_SIPEED_MAIX_H +#define CONFIGS_SIPEED_MAIX_H + +#include <linux/sizes.h>
include/configs/sipeed-maix.h line 19
Quoted 10 lines
include/configs/sipeed-maix.h new file +10
-0+ +#define CONFIG_SYS_LOAD_ADDR 0x80000000 +#define CONFIG_SYS_SDRAM_BASE CONFIG_SYS_LOAD_ADDR +#define CONFIG_SYS_SDRAM_SIZE SZ_8M +/* Start just below AI memory */ +#define CONFIG_SYS_INIT_SP_ADDR 0x805FFFFF +#define CONFIG_SYS_MALLOC_LEN SZ_1K +#define CONFIG_SYS_CACHELINE_SIZE 64 + +#endif /* CONFIGS_SIPEED_MAIX_H */
How are you booting images? It would be great to include a default boot command.
Please also add a short description on the board and how to use U-Boot with it to the documentation.
Thanks,
Lukas
PATCH v2 7/11 riscv: Add initial Sipeed Maix support
Quoted 22 lines · Lukas Auer
Hi Sean,
Quoted 18 lines · Sean Anderson
The Sipeed Maix series is a collection of boards built around the RISC-V Kendryte K210 processor. This processor contains several peripherals to accelerate neural network processing and other "ai" tasks. This includes a "KPU" neural network processor, an audio processor supporting beamforming reception, and a digital video port supporting capture and output at VGA resolution. Other peripherals include 8M of sram (accessible with and without caching); remappable pins, including 40 GPIOs; AES, FFT, and SHA256 accelerators; a DMA controller; and I2C, I2S, and SPI controllers. Maix peripherals vary, but include spi flash; on-board usb-serial bridges; ports for cameras, displays, and sd cards; and ESP32 chips. Currently, only the Sipeed Maix Bit V2.0 (bitm) is supported, but the boards are fairly similar.
Documentation for Maix boards is located at <http://dl.sipeed.com/MAIX/HDK/>;.
Documentation for the Kendryte K210 is located at
<https://kendryte.com/downloads/>;. However, hardware details are rather lacking, so most technical reference has been taken from the standalone sdk located at
<https://github.com/kendryte/kendryte-standalone-sdk>;.
Quoted 4 lines
Quoted 1 line
Signed-off-by Sean Anderson <[email protected]>This patch should be the last in the patch series, because it requires all other patches in the series.
Ok, will reorder it for v3.
Quoted 81 lines
Quoted 81 lines
---
Changes for 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 later.arch/riscv/Kconfig | 4 ++ board/sipeed/maix/Kconfig | 41 +++++++++++++ board/sipeed/maix/MAINTAINERS | 13 +++++ board/sipeed/maix/Makefile | 5 ++ board/sipeed/maix/maix.c | 9 +++ configs/sipeed_maix_bitm_defconfig | 93 ++++++++++++++++++++++++++++++ include/configs/sipeed-maix.h | 19 ++++++ 7 files changed, 184 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 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 +28
-0@@ -0,0 +1,41 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (C) 2019 Sean Anderson <[email protected]> + +if TARGET_SIPEED_MAIX + +config SYS_BOARD + default "maix" + +config SYS_VENDOR + default "sipeed" + +config SYS_CPU + default "generic" + +config SYS_CONFIG_NAME + default "sipeed-maix" + +config SYS_TEXT_BASE + default 0x80000000 + +config NR_CPUS + default 2 + +config NR_DRAM_BANKS + default 2 + +config BOARD_SPECIFIC_OPTIONS + def_bool y
Quoted 8 lines
board/sipeed/maix/Kconfig line 33
Quoted 5 lines
board/sipeed/maix/Kconfig new file +5
-0+ select GENERIC_RISCV + select DM_SERIAL + select SIFIVE_SERIAL + select ARCH_DEFAULT_RV64I + select ENV_IS_NOWHERE
ENV_IS_NOWHEREis automatically selected if no other environment provider is available, so no need to include it here.
Ok, I will remove that in v3. As a general rule, what sort of things should be in Kconfig vs in the default config? I initially thought that all dependencies should be in Kconfig, but "imply" just seems to set the default, which means it won't be changed if you pick another board and then pick this one.
Quoted 1 line
Also, why are you not using the SD card to store the environment?
I haven't managed to get my SD card working yet. I think it may be too big (it's 32G), so I am planning to find a smaller one.
Quoted 146 lines
Quoted 146 lines
board/sipeed/maix/Kconfig new file +8
-0+ select SYS_RISCV_NOCOUNTER + imply SIFIVE_CLINT + imply SPI + imply DM_GPIO + imply CMD_GPIO + imply SYS_NS16550 + imply SYS_MALLOC_F +endifboard/sipeed/maix/MAINTAINERS new file +13
-0@@ -0,0 +1,13 @@ +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: arch/riscv/include/asm/k210_sysctl.h +F: arch/riscv/lib/k210_sysctl.c +F: board/sipeed/maix/ +F: configs/sipeed_maix_defconfig +F: drivers/clk/kendryte/ +F: include/configs/sipeed-maix.h +F: include/dt-bindings/clock/k210-sysctl.h +F: include/dt-bindings/reset/k210-sysctl.hboard/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 +9
-0@@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2019 Sean Anderson <[email protected]> +*/ + +int board_init (void ) +{ +return 0 ; +}configs/sipeed_maix_bitm_defconfig new file +87
-0@@ -0,0 +1,93 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (C) 2019 Sean Anderson <[email protected]> +CONFIG_CREATE_ARCH_SYMLINK=y +CONFIG_RISCV=y +CONFIG_SYS_ARCH="riscv" +CONFIG_SYS_CPU="generic" +CONFIG_SYS_VENDOR="sipeed" +CONFIG_SYS_BOARD="maix" +CONFIG_SYS_CONFIG_NAME="sipeed-maix" +CONFIG_SPL_LDSCRIPT="arch/riscv/cpu/u-boot-spl.lds" +CONFIG_SYS_TEXT_BASE=0x80000000 +CONFIG_SYS_MALLOC_F_LEN=0x1000 +CONFIG_BOARD_SPECIFIC_OPTIONS=y +CONFIG_NR_DRAM_BANKS=2 +CONFIG_BOOTSTAGE_STASH_ADDR=0 +CONFIG_64BIT=y +CONFIG_TARGET_SIPEED_MAIX=y +CONFIG_NR_CPUS=2 +CONFIG_GENERIC_RISCV=y +CONFIG_ARCH_DEFAULT_RV64I=y +CONFIG_ARCH_RV64I=y +CONFIG_CMODEL_MEDLOW=y +CONFIG_RISCV_MMODE=y +CONFIG_RISCV_ISA_C=y +CONFIG_RISCV_ISA_A=y +CONFIG_SIFIVE_CLINT=y +CONFIG_K210_SYSCTL=y +CONFIG_SYS_RISCV_NOCOUNTER=y +CONFIG_ARCH_K210=y +CONFIG_CC_OPTIMIZE_FOR_SIZE=y +CONFIG_SYS_MALLOC_F=y +CONFIG_PHYS_64BIT=y +# CONFIG_ANDROID_BOOT_IMAGE is not set +# CONFIG_FIT is not set +# CONFIG_LEGACY_IMAGE_FORMAT is not set +CONFIG_LOG=y +CONFIG_ARCH_EARLY_INIT_R=y +CONFIG_CMDLINE=y +CONFIG_CMD_ENV_EXISTS=y +CONFIG_CMD_FLASH=y +CONFIG_CMD_SF=y +CONFIG_CMD_LOG=y +# CONFIG_AUTOBOOT is not set +# CONFIG_CMD_BDI is not set +# CONFIG_CMD_CONSOLE is not set +# CONFIG_CMD_BOOTD is not set +# CONFIG_CMD_BOOTM is not set +# CONFIG_CMD_BOOTZ is not set +CONFIG_CMD_BOOTI=y +CONFIG_BOOTM_LINUX=y +# CONFIG_CMD_ELF is not set +CONFIG_CMD_FDT=y +CONFIG_SUPPORT_OF_CONTROL=y +CONFIG_DTC=y +CONFIG_OF_CONTROL=y +CONFIG_OF_SEPARATE=y +CONFIG_ENV_IS_NOWHERE=y +# CONFIG_NET is not set +CONFIG_DM=y +CONFIG_REGMAP=y +CONFIG_SYSCON=y +CONFIG_SIMPLE_BUS=y +CONFIG_OF_TRANSLATE=y +CONFIG_CLK=y +CONFIG_CLK_CCF=y +CONFIG_CLK_COMPOSITE_CCF=y +CONFIG_CPU=y +CONFIG_CPU_RISCV=y +CONFIG_MMC=y +# CONFIG_INPUT is not set +CONFIG_DM_MMC=y +CONFIG_MMC_SPI=y +CONFIG_MMC_QUIRKS=y +CONFIG_MTD=y +CONFIG_DM_MTD=y +CONFIG_DM_SPI_FLASH=y +CONFIG_SPI_FLASH=y +CONFIG_SPI_FLASH_GIGADEVICE=y +# CONFIG_DM_ETH is not set +# CONFIG_PCI is not set +CONFIG_BAUDRATE=115200 +CONFIG_SERIAL_PRESENT=y +CONFIG_DM_SERIAL=y +CONFIG_SIFIVE_SERIAL=y +CONFIG_SPI=y +CONFIG_DM_SPI=y +CONFIG_SPI_MEM=y
Quoted 8 lines
configs/sipeed_maix_bitm_defconfig line 93
Quoted 6 lines
configs/sipeed_maix_bitm_defconfig new file +6
-0+CONFIG_DESIGNWARE_SPI=y +CONFIG_TIMER=y +CONFIG_RISCV_TIMER=y +CONFIG_PANIC_HANG=y +CONFIG_OF_LIBFDT=y +# CONFIG_EFI_LOADER is not setPlease use make savedefconfig to generate the defconfig.
Ah, I wasn't aware that that was the preferred way.
Quoted 20 lines
Quoted 20 lines
include/configs/sipeed-maix.h new file +14
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2019 Sean Anderson <[email protected]> +*/ + +#ifndef CONFIGS_SIPEED_MAIX_H +#define CONFIGS_SIPEED_MAIX_H + +#include <linux/sizes.h> + +#define CONFIG_SYS_LOAD_ADDR 0x80000000 +#define CONFIG_SYS_SDRAM_BASE CONFIG_SYS_LOAD_ADDR +#define CONFIG_SYS_SDRAM_SIZE SZ_8M +/* Start just below AI memory */
Quoted 8 lines
include/configs/sipeed-maix.h line 19
Quoted 5 lines
include/configs/sipeed-maix.h new file +5
-0+#define CONFIG_SYS_INIT_SP_ADDR 0x805FFFFF +#define CONFIG_SYS_MALLOC_LEN SZ_1K +#define CONFIG_SYS_CACHELINE_SIZE 64 + +#endif /* CONFIGS_SIPEED_MAIX_H */ How are you booting images? It would be great to include a default boot command.
The board I am using has some serial issues which makes it difficult to flash any large images. I can get u-boot to flash after several attempts, but something like the linux kernel is far too unreliable to test regularly. I'm going to see if I can get my hands on another k210 board which hopefully doesn't have these issues.
Quoted 2 lines
Please also add a short description on the board and how to use U-Boot with it to the documentation.
Will something like the commit message work?
Quoted 4 lines
Thanks,
Lukas
PATCH v2 7/11 riscv: Add initial Sipeed Maix support
Quoted 120 lines · Sean Anderson
Quoted 22 lines · Lukas Auer
Hi Sean,
Quoted 18 lines · Sean Anderson
The Sipeed Maix series is a collection of boards built around the RISC-V Kendryte K210 processor. This processor contains several peripherals to accelerate neural network processing and other "ai" tasks. This includes a "KPU" neural network processor, an audio processor supporting beamforming reception, and a digital video port supporting capture and output at VGA resolution. Other peripherals include 8M of sram (accessible with and without caching); remappable pins, including 40 GPIOs; AES, FFT, and SHA256 accelerators; a DMA controller; and I2C, I2S, and SPI controllers. Maix peripherals vary, but include spi flash; on-board usb-serial bridges; ports for cameras, displays, and sd cards; and ESP32 chips. Currently, only the Sipeed Maix Bit V2.0 (bitm) is supported, but the boards are fairly similar.
Documentation for Maix boards is located at <http://dl.sipeed.com/MAIX/HDK/>;;.
Documentation for the Kendryte K210 is located at
<https://kendryte.com/downloads/>;;. However, hardware details are rather lacking, so most technical reference has been taken from the standalone sdk located at
<https://github.com/kendryte/kendryte-standalone-sdk>;;.Quoted 4 lines
Quoted 1 line
Signed-off-by Sean Anderson <[email protected]>This patch should be the last in the patch series, because it requires all other patches in the series.
Ok, will reorder it for v3.
Quoted 81 lines
Quoted 81 lines
---
Changes for 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 later.arch/riscv/Kconfig | 4 ++ board/sipeed/maix/Kconfig | 41 +++++++++++++ board/sipeed/maix/MAINTAINERS | 13 +++++ board/sipeed/maix/Makefile | 5 ++ board/sipeed/maix/maix.c | 9 +++ configs/sipeed_maix_bitm_defconfig | 93 ++++++++++++++++++++++++++++++ include/configs/sipeed-maix.h | 19 ++++++ 7 files changed, 184 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 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 +28
-0@@ -0,0 +1,41 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (C) 2019 Sean Anderson <[email protected]> + +if TARGET_SIPEED_MAIX + +config SYS_BOARD + default "maix" + +config SYS_VENDOR + default "sipeed" + +config SYS_CPU + default "generic" + +config SYS_CONFIG_NAME + default "sipeed-maix" + +config SYS_TEXT_BASE + default 0x80000000 + +config NR_CPUS + default 2 + +config NR_DRAM_BANKS + default 2 + +config BOARD_SPECIFIC_OPTIONS + def_bool yQuoted 8 lines
board/sipeed/maix/Kconfig line 33
Quoted 5 lines
board/sipeed/maix/Kconfig new file +5
-0+ select GENERIC_RISCV + select DM_SERIAL + select SIFIVE_SERIAL + select ARCH_DEFAULT_RV64I + select ENV_IS_NOWHERE
ENV_IS_NOWHEREis automatically selected if no other environment provider is available, so no need to include it here.
Quoted 6 lines
Ok, I will remove that in v3. As a general rule, what sort of things should be in
Kconfigvs in the default config? I initially thought that all dependencies should be inKconfig, but "imply" just seems to set the default, which means it won't be changed if you pick another board and then pick this one.
The Kconfig forms the base configuration, which will be shared by all defconfig variations of the board. So yes, you are correct, it should include all its dependencies such as the peripheral drivers, but also commands that use the peripherals. In the SiFive FU540 configuration, for example, we imply the peripheral drivers (clock, serial, etc.), enable filesystem related options since we have storage, and enable relevant commands.
Not everybody will want or need all configuration options. We therefore try to imply as many of the options as possible, so that they can be deselected as required in the defconfig. They should all be picked up, if you apply different boards. Perhaps you did not run make distclean?
Quoted 5 lines
Quoted 1 line
Also, why are you not using the SD card to store the environment?
I haven't managed to get my SD card working yet. I think it may be too big (it's 32G), so I am planning to find a smaller one.
Interesting, I thought all SD cards support SPI mode.
Quoted 155 lines
Quoted 146 lines
Quoted 146 lines
board/sipeed/maix/Kconfig new file +8
-0+ select SYS_RISCV_NOCOUNTER + imply SIFIVE_CLINT + imply SPI + imply DM_GPIO + imply CMD_GPIO + imply SYS_NS16550 + imply SYS_MALLOC_F +endifboard/sipeed/maix/MAINTAINERS new file +13
-0@@ -0,0 +1,13 @@ +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: arch/riscv/include/asm/k210_sysctl.h +F: arch/riscv/lib/k210_sysctl.c +F: board/sipeed/maix/ +F: configs/sipeed_maix_defconfig +F: drivers/clk/kendryte/ +F: include/configs/sipeed-maix.h +F: include/dt-bindings/clock/k210-sysctl.h +F: include/dt-bindings/reset/k210-sysctl.hboard/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 +9
-0@@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2019 Sean Anderson <[email protected]> +*/ + +int board_init (void ) +{ +return 0 ; +}configs/sipeed_maix_bitm_defconfig new file +87
-0@@ -0,0 +1,93 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (C) 2019 Sean Anderson <[email protected]> +CONFIG_CREATE_ARCH_SYMLINK=y +CONFIG_RISCV=y +CONFIG_SYS_ARCH="riscv" +CONFIG_SYS_CPU="generic" +CONFIG_SYS_VENDOR="sipeed" +CONFIG_SYS_BOARD="maix" +CONFIG_SYS_CONFIG_NAME="sipeed-maix" +CONFIG_SPL_LDSCRIPT="arch/riscv/cpu/u-boot-spl.lds" +CONFIG_SYS_TEXT_BASE=0x80000000 +CONFIG_SYS_MALLOC_F_LEN=0x1000 +CONFIG_BOARD_SPECIFIC_OPTIONS=y +CONFIG_NR_DRAM_BANKS=2 +CONFIG_BOOTSTAGE_STASH_ADDR=0 +CONFIG_64BIT=y +CONFIG_TARGET_SIPEED_MAIX=y +CONFIG_NR_CPUS=2 +CONFIG_GENERIC_RISCV=y +CONFIG_ARCH_DEFAULT_RV64I=y +CONFIG_ARCH_RV64I=y +CONFIG_CMODEL_MEDLOW=y +CONFIG_RISCV_MMODE=y +CONFIG_RISCV_ISA_C=y +CONFIG_RISCV_ISA_A=y +CONFIG_SIFIVE_CLINT=y +CONFIG_K210_SYSCTL=y +CONFIG_SYS_RISCV_NOCOUNTER=y +CONFIG_ARCH_K210=y +CONFIG_CC_OPTIMIZE_FOR_SIZE=y +CONFIG_SYS_MALLOC_F=y +CONFIG_PHYS_64BIT=y +# CONFIG_ANDROID_BOOT_IMAGE is not set +# CONFIG_FIT is not set +# CONFIG_LEGACY_IMAGE_FORMAT is not set +CONFIG_LOG=y +CONFIG_ARCH_EARLY_INIT_R=y +CONFIG_CMDLINE=y +CONFIG_CMD_ENV_EXISTS=y +CONFIG_CMD_FLASH=y +CONFIG_CMD_SF=y +CONFIG_CMD_LOG=y +# CONFIG_AUTOBOOT is not set +# CONFIG_CMD_BDI is not set +# CONFIG_CMD_CONSOLE is not set +# CONFIG_CMD_BOOTD is not set +# CONFIG_CMD_BOOTM is not set +# CONFIG_CMD_BOOTZ is not set +CONFIG_CMD_BOOTI=y +CONFIG_BOOTM_LINUX=y +# CONFIG_CMD_ELF is not set +CONFIG_CMD_FDT=y +CONFIG_SUPPORT_OF_CONTROL=y +CONFIG_DTC=y +CONFIG_OF_CONTROL=y +CONFIG_OF_SEPARATE=y +CONFIG_ENV_IS_NOWHERE=y +# CONFIG_NET is not set +CONFIG_DM=y +CONFIG_REGMAP=y +CONFIG_SYSCON=y +CONFIG_SIMPLE_BUS=y +CONFIG_OF_TRANSLATE=y +CONFIG_CLK=y +CONFIG_CLK_CCF=y +CONFIG_CLK_COMPOSITE_CCF=y +CONFIG_CPU=y +CONFIG_CPU_RISCV=y +CONFIG_MMC=y +# CONFIG_INPUT is not set +CONFIG_DM_MMC=y +CONFIG_MMC_SPI=y +CONFIG_MMC_QUIRKS=y +CONFIG_MTD=y +CONFIG_DM_MTD=y +CONFIG_DM_SPI_FLASH=y +CONFIG_SPI_FLASH=y +CONFIG_SPI_FLASH_GIGADEVICE=y +# CONFIG_DM_ETH is not set +# CONFIG_PCI is not set +CONFIG_BAUDRATE=115200 +CONFIG_SERIAL_PRESENT=y +CONFIG_DM_SERIAL=y +CONFIG_SIFIVE_SERIAL=y +CONFIG_SPI=y +CONFIG_DM_SPI=y +CONFIG_SPI_MEM=yQuoted 8 lines
configs/sipeed_maix_bitm_defconfig line 93
Quoted 6 lines
configs/sipeed_maix_bitm_defconfig new file +6
-0+CONFIG_DESIGNWARE_SPI=y +CONFIG_TIMER=y +CONFIG_RISCV_TIMER=y +CONFIG_PANIC_HANG=y +CONFIG_OF_LIBFDT=y +# CONFIG_EFI_LOADER is not setPlease use make savedefconfig to generate the defconfig.
Quoted 2 lines
Ah, I wasn't aware that that was the preferred way.
No problem, makes it much easier as well. :)
Quoted 29 lines
Quoted 20 lines
Quoted 20 lines
include/configs/sipeed-maix.h new file +14
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2019 Sean Anderson <[email protected]> +*/ + +#ifndef CONFIGS_SIPEED_MAIX_H +#define CONFIGS_SIPEED_MAIX_H + +#include <linux/sizes.h> + +#define CONFIG_SYS_LOAD_ADDR 0x80000000 +#define CONFIG_SYS_SDRAM_BASE CONFIG_SYS_LOAD_ADDR +#define CONFIG_SYS_SDRAM_SIZE SZ_8M +/* Start just below AI memory */ Quoted 8 lines
include/configs/sipeed-maix.h line 19
Quoted 5 lines
include/configs/sipeed-maix.h new file +5
-0+#define CONFIG_SYS_INIT_SP_ADDR 0x805FFFFF +#define CONFIG_SYS_MALLOC_LEN SZ_1K +#define CONFIG_SYS_CACHELINE_SIZE 64 + +#endif /* CONFIGS_SIPEED_MAIX_H */ How are you booting images? It would be great to include a default boot command.
Quoted 6 lines
The board I am using has some serial issues which makes it difficult to flash any large images. I can get u-boot to flash after several attempts, but something like the linux kernel is far too unreliable to test regularly. I'm going to see if I can get my hands on another k210 board which hopefully doesn't have these issues.
Ah ok, that's unfortunate. Thank you for your efforts!
Quoted 5 lines
Quoted 2 lines
Please also add a short description on the board and how to use U-Boot with it to the documentation.
Will something like the commit message work?
Yes definitely. Just add a short description on how to build U-Boot and flash it onto the board. That makes it a lot easier for new users to get started with the board.
Thanks,
Lukas
PATCH v2 7/11 riscv: Add initial Sipeed Maix support
Quoted 1 line · Lukas Auer
Interesting, I thought all SD cards support SPI mode.
I think it's a different issue, but I wasn't sure.
Quoted 7 lines
Quoted 5 lines
The board I am using has some serial issues which makes it difficult to flash any large images. I can get u-boot to flash after several attempts, but something like the linux kernel is far too unreliable to test regularly. I'm going to see if I can get my hands on another k210 board which hopefully doesn't have these issues.
Ah ok, that's unfortunate. Thank you for your efforts!
I have since found a computer where the serial works fine (which implies that the USB hardware on my current computer has some issues). I should be able to flash larger binaries fine now, but the current issue is getting the SPI to work. I think there may be some subtle differences between the driver and the manufacturer's sdk.
I am also having some clock problems, despite (obstensibly) performing the same incantations as the sdk. I guess this is what happens when they refuse to release a technical reference...
--Sean
v2 cover riscv: Add Sipeed Maix support
In reply to Sean AndersonPATCH v2 8/11 riscv: Add device tree for K210
The subject for this patch should be
Subject: [PATCH v2 08/11] riscv: Add device tree for K210
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v2 8/11 riscv: Add device tree for K210
Hi Sean,
Quoted 9 lines
From: Sean Anderson [mailto:seanga2 at gmail.com]
Sent: Thursday, January 16, 2020 7:18 AM
To: U-Boot Mailing List
Cc: Rick Jian-Zhi Chen(陳建志)
Subject: [PATCH v2 08/11] riscv: Add device tree for K210The subject for this patch should be
Subject: [PATCH v2 08/11] riscv: Add device tree for K210
Lacking of contents.
Thanks,
Rick
PATCH v2 8/11 riscv: Add device tree for K210
In reply to Sean AndersonThere is a mirror of ram located at 0x4000000 which is un-cached. This is probably useful for DMA, but I am unsure of how to describe it in this device tree.
The cache-line size is undocumented. Emphirical tests suggest that it is 32 bytes, but I've used 64-bytes to be on the safe side.
Where possible, I have tried to find compatible drivers based on the layout of registers. However, I have not tested most of this functionality, and anything aside from clint0, uarths0, and sysctl should be considered descriptive at best. I would appreciate if anyone could help identify possibly compatible devices, especially for the timers, watchdogs, and rtc.
The documentation for pinconf devices indicates that #pinctrl-cells is a required property, but I am unsure what to put for it. Should that be filled in by a board-specific device tree?
The sysctl device has multiple different unrelated registers. For the moment, I have split off sub-devices for each functionality. In addition to clock and reset control, it also contains DMA handshake registers, and power registers. I have not described those at the moment, and I would appreciate suggestions on how to best describe them.
I'm not sure what the value of spi-max-frequency should be for external sd-card slots. Suggestions are appreciated.
--- arch/riscv/dts/Makefile | 1 + arch/riscv/dts/k210-maix-bit.dts | 42 +++ arch/riscv/dts/k210.dtsi | 453 ++++++++++++++++++++++++ board/sipeed/maix/Kconfig | 3 + configs/sipeed_maix_bitm_defconfig | 1 + include/dt-bindings/clock/k210-sysctl.h | 54 +++ include/dt-bindings/reset/k210-sysctl.h | 38 ++ 7 files changed, 592 insertions(+) create mode 100644 arch/riscv/dts/k210-maix-bit.dts create mode 100644 arch/riscv/dts/k210.dtsi create mode 100644 include/dt-bindings/clock/k210-sysctl.h create mode 100644 include/dt-bindings/reset/k210-sysctl.h
arch/riscv/dts/Makefile +1 -0
@@ -2,6 +2,7 @@ dtb-$(CONFIG_TARGET_AX25_AE350) += ae350_32.dtb ae350_64.dtb dtb-$(CONFIG_TARGET_SIFIVE_FU540) += hifive-unleashed-a00.dtb +dtb-$(CONFIG_TARGET_SIPEED_MAIX) += k210-maix-bit.dtb targets += $(dtb-y)
arch/riscv/dts/k210-maix-bit.dts new file +42 -0
42 lines not on this page · raw message
arch/riscv/dts/k210.dtsi new file +453 -0
453 lines not on this page · raw message
board/sipeed/maix/Kconfig +3 -0
@@ -18,6 +18,9 @@ config SYS_CONFIG_NAME config SYS_TEXT_BASE default 0x80000000 +config DEFAULT_DEVICE_TREE + default "k210-maix-bit" + config NR_CPUS default 2
configs/sipeed_maix_bitm_defconfig +1 -0
@@ -15,6 +15,7 @@ CONFIG_NR_DRAM_BANKS=2 CONFIG_BOOTSTAGE_STASH_ADDR=0 CONFIG_64BIT=y CONFIG_TARGET_SIPEED_MAIX=y +CONFIG_DEFAULT_DEVICE_TREE="k210-maix-bit" CONFIG_NR_CPUS=2 CONFIG_GENERIC_RISCV=y CONFIG_ARCH_DEFAULT_RV64I=y
include/dt-bindings/clock/k210-sysctl.h new file +54 -0
54 lines not on this page · raw message
include/dt-bindings/reset/k210-sysctl.h new file +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 v2 9/11 riscv: Add K210 sysctl support
In reply to Sean AndersonThis driver does nothing but load its children for the moment. Should it be using regmap? I'm not sure how that fits into everything.
---
Changes for v2:
Removed spurious references to mach-k210.
Don't load pre-relocation.
arch/riscv/Kconfig | 11 +++++++ arch/riscv/include/asm/k210_sysctl.h | 43 ++++++++++++++++++++++++++++ arch/riscv/lib/Makefile | 1 + arch/riscv/lib/k210_sysctl.c | 21 ++++++++++++++ board/sipeed/maix/Kconfig | 1 + 5 files changed, 77 insertions(+) create mode 100644 arch/riscv/include/asm/k210_sysctl.h create mode 100644 arch/riscv/lib/k210_sysctl.c
arch/riscv/Kconfig +11 -0
@@ -196,6 +196,14 @@ config RISCV_RDTIME standard rdtime instruction. This is the case for S-mode U-Boot, and is useful for processors that support rdtime in M-mode too. +config K210_SYSCTL + bool + select SYSCON + select SPL_SYSCON if SPL + help + The K210 sysctl block holds memory-mapped control and status + registers associated with clocks, resets, power, and dma handshakes. + config SYS_MALLOC_F_LEN default 0x1000
@@ -240,4 +248,7 @@ config STACK_SIZE_SHIFT config SPL_LDSCRIPT default "arch/riscv/cpu/u-boot-spl.lds" +config ARCH_K210 + bool "Support Kendryte K210 SOCs" + endmenu
arch/riscv/include/asm/k210_sysctl.h new file +43 -0
43 lines not on this page · raw message
arch/riscv/lib/Makefile +1 -0
@@ -14,6 +14,7 @@ ifeq ($(CONFIG_$(SPL_)RISCV_MMODE),y) obj-$(CONFIG_SIFIVE_CLINT) += sifive_clint.o obj-$(CONFIG_ANDES_PLIC) += andes_plic.o obj-$(CONFIG_ANDES_PLMT) += andes_plmt.o +obj-$(CONFIG_K210_SYSCTL) += k210_sysctl.o else obj-$(CONFIG_RISCV_RDTIME) += rdtime.o obj-$(CONFIG_SBI_IPI) += sbi_ipi.o
arch/riscv/lib/k210_sysctl.c new file +21 -0
@@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2019 Sean Anderson <[email protected]> +*/ +#include <asm/k210_sysctl.h> + +#include <dm.h> + +static const struct udevice_id k210_sysctl_ids[] = { + { .compatible ="kendryte,k210-sysctl" , }, + { } +}; + +U_BOOT_DRIVER (k210_sysctl) = { + .name ="k210_sysctl" , + .id =UCLASS_SYSCON , +#if !CONFIG_IS_ENABLED(OF_PLATDATA) + .bind = dm_scan_fdt_dev, +#endif + .of_match = k210_sysctl_ids, +};
board/sipeed/maix/Kconfig +1 -0
@@ -36,6 +36,7 @@ config BOARD_SPECIFIC_OPTIONS select ENV_IS_NOWHERE select SYS_RISCV_NOCOUNTER imply SIFIVE_CLINT + imply K210_SYSCTL imply SPI imply DM_GPIO imply CMD_GPIO
Signature · 1 line
2.24.1
PATCH v2 10/11 riscv: 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 for 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.
board/sipeed/maix/Kconfig | 1 + configs/sipeed_maix_bitm_defconfig | 1 + drivers/clk/Kconfig | 1 + drivers/clk/Makefile | 1 + drivers/clk/kendryte/Kconfig | 7 + drivers/clk/kendryte/Makefile | 1 + drivers/clk/kendryte/pll.c | 598 +++++++++++++++++++++++++++++ drivers/clk/kendryte/pll.h | 38 ++ 8 files changed, 648 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 drivers/clk/kendryte/pll.h
board/sipeed/maix/Kconfig +1 -0
@@ -37,6 +37,7 @@ config BOARD_SPECIFIC_OPTIONS select SYS_RISCV_NOCOUNTER imply SIFIVE_CLINT imply K210_SYSCTL + imply CLK_K210 imply SPI imply DM_GPIO imply CMD_GPIO
configs/sipeed_maix_bitm_defconfig +1 -0
@@ -65,6 +65,7 @@ CONFIG_OF_TRANSLATE=y CONFIG_CLK=y CONFIG_CLK_CCF=y CONFIG_CLK_COMPOSITE_CCF=y +CONFIG_CLK_K210=y CONFIG_CPU=y CONFIG_CPU_RISCV=y CONFIG_MMC=y
drivers/clk/Kconfig +1 -0
@@ -145,6 +145,7 @@ source "drivers/clk/analogbits/Kconfig" source "drivers/clk/at91/Kconfig" source "drivers/clk/exynos/Kconfig" source "drivers/clk/imx/Kconfig" +source "drivers/clk/kendryte/Kconfig" source "drivers/clk/meson/Kconfig" source "drivers/clk/mvebu/Kconfig" source "drivers/clk/owl/Kconfig"
drivers/clk/Makefile +1 -0
@@ -26,6 +26,7 @@ obj-$(CONFIG_CLK_BCM6345) += clk_bcm6345.o obj-$(CONFIG_CLK_BOSTON) += clk_boston.o obj-$(CONFIG_CLK_EXYNOS) += exynos/ obj-$(CONFIG_CLK_HSDK) += clk-hsdk-cgu.o +obj-$(CONFIG_CLK_K210) += kendryte/ obj-$(CONFIG_CLK_MPC83XX) += mpc83xx_clk.o obj-$(CONFIG_CLK_OWL) += owl/ obj-$(CONFIG_CLK_RENESAS) += renesas/
drivers/clk/kendryte/Kconfig new file +7 -0
@@ -0,0 +1,7 @@ +config CLK_K210 + bool "Clock support for Kendryte K210" + depends on K210_SYSCTL + select CLK + select CLK_CCF + help + This enables support clock driver for Kendryte K210 platforms.
drivers/clk/kendryte/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-y += pll.o
drivers/clk/kendryte/pll.c new file +598 -0
598 lines not on this page · raw message
drivers/clk/kendryte/pll.h new file +38 -0
@@ -0,0 +1,38 @@ +#ifndef K210_PLL_H +#define K210_PLL_H + +#include <clk.h> + +#define K210_PLL_CLKR GENMASK(3, 0) +#define K210_PLL_CLKF GENMASK(9, 4) +#define K210_PLL_CLKOD GENMASK(13, 10) +#define K210_PLL_BWADJ GENMASK(19, 14) +#define K210_PLL_RESET BIT(20) +#define K210_PLL_PWRD BIT(21) +#define K210_PLL_INTFB BIT(22) +#define K210_PLL_BYPASS BIT(23) +#define K210_PLL_TEST BIT(24) +#define K210_PLL_EN BIT(25) +#define K210_PLL_TEST_EN BIT(26) + +#define K210_PLL_LOCK 0 +#define K210_PLL_CLEAR_SLIP 2 +#define K210_PLL_TEST_OUT 3 + +struct k210_pll { +struct clk clk; +void __iomem *reg;/* Base PLL register */ +void __iomem *lock;/* Common PLL lock register */ +u8 shift;/* Offset of bits in lock register */ +u8 lock_mask;/* Mask of lock bits to test against, pre-shifted */ +}; + +extern const struct clk_ops k210_pll_ops; + +struct k210_pll *k210_clk_comp_pll (void __iomem *reg,void __iomem *lock, +u8 shift,u8 width); +struct clk *k210_clk_pll (const char *name,const char *parent_name, +void __iomem *reg,void __iomem *lock,u8 shift, +u8 width); + +#endif /* K210_PLL_H */
Signature · 1 line
2.24.1
PATCH v2 11/11 riscv: 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. A common pattern is to create a composite clock composed of several component clocks. For these component clocks, the clk_register_* functions are not used, since they will be registered as part of the composite clock. To create these component clocks, several helper k210_clk_comp_* functions are used. This functionality seems like it would be useful to other drivers also creating composite clocks, so perhaps some general versions should be created. I am not particularly attached to the naming convention, suggestions are welcome.
---
Changes for v2:
Add clk.o to obj-y.
Don't probe before relocation.
arch/riscv/Kconfig | 3 - board/sipeed/maix/Kconfig | 3 + drivers/clk/kendryte/Makefile | 2 +- drivers/clk/kendryte/clk.c | 390 ++++++++++++++++++++++++++++++++++ drivers/clk/kendryte/clk.h | 27 +++ 5 files changed, 421 insertions(+), 4 deletions(-) create mode 100644 drivers/clk/kendryte/clk.c create mode 100644 drivers/clk/kendryte/clk.h
arch/riscv/Kconfig +0 -3
@@ -248,7 +248,4 @@ config STACK_SIZE_SHIFT config SPL_LDSCRIPT default "arch/riscv/cpu/u-boot-spl.lds" -config ARCH_K210 - bool "Support Kendryte K210 SOCs" - endmenu
board/sipeed/maix/Kconfig +3 -0
@@ -27,6 +27,9 @@ config NR_CPUS config NR_DRAM_BANKS default 2 +config SYS_MALLOC_F_LEN + default 0x8000 + config BOARD_SPECIFIC_OPTIONS def_bool y select GENERIC_RISCV
drivers/clk/kendryte/Makefile +1 -1
@@ -1 +1 @@ -obj-y += pll.o +obj-y += clk.o pll.o
drivers/clk/kendryte/clk.c new file +390 -0
390 lines not on this page · raw message
drivers/clk/kendryte/clk.h new file +27 -0
@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2019 Sean Anderson <[email protected]> +*/ + +#ifndef K210_CLK_H +#define K210_CLK_H + +#define LOG_CATEGORY UCLASS_CLK +#include <linux/types.h> +#include <linux/clk-provider.h> + +static inline struct clk *k210_clk_gate (const char *name, +const char *parent_name, +void __iomem *reg,u8 bit_idx) +{ +return clk_register_gate (NULL , name, parent_name,0 , reg, bit_idx,0 , +NULL ); +} + +static inline struct clk *k210_clk_half (const char *name, +const char *parent_name) +{ +return clk_register_fixed_factor (NULL , name, parent_name,0 ,1 ,2 ); +} + +#endif /* K210_CLK_H */
Signature · 1 line
2.24.1