Renesas RZ/N1 SoC initial support
Subsystems (7)
cover Renesas RZ/N1 SoC initial support
The RZ/N1 is a family of SoC devices from Renesas [1], featuring ARM Cortex-A7 and/or Cortex-M3 CPU, industrial ethernet protocols, integrated Ethernet switch, and numerous peripherals.
This is a first step in upstreaming support for the RZ/N1 family. Currently it contains just enough to boot to the u-boot prompt. Additional patches will follow to support flash, SD, USB, Ethernet, etc.
At this point, I am looking for general feedback about the overall direction and structure. I'm aware of several checkpatch warnings, and some TODO/FIXME items, which will be addressed.
This work is based on a vendor-supplied u-boot 2017.01 tree [2], which supports several eval boards, none of which I have access to. Instead development has been done on a Schneider LCES2 board, which is fairly similar to the Renesas RZ/N1D-DB Demo board.
The patches are currently against v2022.10-rc2.
[1] https://www.renesas.com/us/en/products/microcontrollers-microprocessors/rz-mpus/rzn1
[2] https://github.com/renesas-rz/rzn1_u-boot/tree/rzn1-stable
Michel Pollet (1):
tools: Add tool to create Renesas SPKG images
Ralph Siemsen (8):
ARM: armv7: add non-SPL enable for Cortex SMPEN
clk: renesas: prepare for non-RCAR clock drivers
clk: renesas: add R906G032 driver
pinctrl: renesas: add R906G032 driver
ram: cadence: add driver for Cadence EDAC
dts: basic devicetree for Renesas RZ/N1 SoC
ARM: rzn1: basic support for Renesas RZ/N1 SoC
board: schneider: add LCES board support
arch/arm/Kconfig | 17 + arch/arm/Makefile | 1 + arch/arm/cpu/armv7/Kconfig | 5 + arch/arm/dts/r9a06g032-rzn1d400-lces.dts | 50 ++ arch/arm/dts/r9a06g032.dtsi | 225 ++++++ arch/arm/mach-rzn1/Kconfig | 32 + arch/arm/mach-rzn1/Makefile | 3 + arch/arm/mach-rzn1/cpu_info.c | 20 + board/schneider/lces/Kconfig | 12 + board/schneider/lces/Makefile | 3 + board/schneider/lces/ddr_timing.c | 140 ++++ .../lces/jedec_ddr3_2g_x16_1333h_500_cl8.h | 399 ++++++++++ board/schneider/lces/lces.c | 41 + configs/lces_defconfig | 26 + drivers/clk/renesas/Kconfig | 8 +- drivers/clk/renesas/Makefile | 6 +- drivers/clk/renesas/r9a06g032-clocks.c | 734 ++++++++++++++++++ drivers/pinctrl/Makefile | 1 + drivers/pinctrl/renesas/Kconfig | 7 + drivers/pinctrl/renesas/Makefile | 1 + drivers/pinctrl/renesas/pinctrl-rzn1.c | 398 ++++++++++ drivers/ram/Kconfig | 1 + drivers/ram/Makefile | 2 + drivers/ram/cadence/Kconfig | 24 + drivers/ram/cadence/Makefile | 1 + drivers/ram/cadence/ddr_async.c | 295 +++++++ drivers/ram/cadence/ddr_ctrl.c | 414 ++++++++++ drivers/ram/cadence/ddr_ctrl.h | 172 ++++ include/configs/lces.h | 22 + include/dt-bindings/clock/r9a06g032-sysctrl.h | 148 ++++ include/dt-bindings/pinctrl/rzn1-pinctrl.h | 141 ++++ tools/Makefile | 2 + tools/spkg_header.h | 49 ++ tools/spkg_utility.c | 306 ++++++++ 34 files changed, 3702 insertions(+), 4 deletions(-) create mode 100644 arch/arm/dts/r9a06g032-rzn1d400-lces.dts create mode 100644 arch/arm/dts/r9a06g032.dtsi create mode 100644 arch/arm/mach-rzn1/Kconfig create mode 100644 arch/arm/mach-rzn1/Makefile create mode 100644 arch/arm/mach-rzn1/cpu_info.c create mode 100644 board/schneider/lces/Kconfig create mode 100644 board/schneider/lces/Makefile create mode 100644 board/schneider/lces/ddr_timing.c create mode 100644 board/schneider/lces/jedec_ddr3_2g_x16_1333h_500_cl8.h create mode 100644 board/schneider/lces/lces.c create mode 100644 configs/lces_defconfig create mode 100644 drivers/clk/renesas/r9a06g032-clocks.c create mode 100644 drivers/pinctrl/renesas/pinctrl-rzn1.c create mode 100644 drivers/ram/cadence/Kconfig create mode 100644 drivers/ram/cadence/Makefile create mode 100644 drivers/ram/cadence/ddr_async.c create mode 100644 drivers/ram/cadence/ddr_ctrl.c create mode 100644 drivers/ram/cadence/ddr_ctrl.h create mode 100644 include/configs/lces.h create mode 100644 include/dt-bindings/clock/r9a06g032-sysctrl.h create mode 100644 include/dt-bindings/pinctrl/rzn1-pinctrl.h create mode 100644 tools/spkg_header.h create mode 100644 tools/spkg_utility.c
Signature · 1 line
2.25.1
RFC PATCH 1/9 ARM: armv7: add non-SPL enable for Cortex SMPEN
Commit 2564fce7eea3 ("sunxi: move Cortex SMPEN setting into start.S") added SPL_ARMV7_SET_CORTEX_SMPEN to enable setting SMP bit. For platforms not using SPL boot, add the corresponding non-SPL config, so that CONFIG_IS_ENABLED(ARMV7_SET_CORTEX_SMPEN) works as expected.
---
This will be used by the following commit that adds ARCH_RZN1.
arch/arm/cpu/armv7/Kconfig | 5 +++++ 1 file changed, 5 insertions(+)
arch/arm/cpu/armv7/Kconfig +5 -0
@@ -107,6 +107,11 @@ config ARMV7_LPAE Say Y here to use the long descriptor page table format. This is required if U-Boot runs in HYP mode. +config ARMV7_SET_CORTEX_SMPEN + bool + help + Enable the ARM Cortex ACTLR.SMP enable bit in U-boot. + config SPL_ARMV7_SET_CORTEX_SMPEN bool help
Signature · 1 line
2.25.1
RFC PATCH 2/9 clk: renesas: prepare for non-RCAR clock drivers
In reply to Ralph SiemsenAllow CONFIG_CLK_RENESAS to be set without bringing in RCAR-GEN2/3 code.
CONFIG_RENESAS is used in drivers/clk/Makefile to control recursion into the drivers/clk/renesas subdirectory. It also controls compilation of renesas-cpg-mssr.c support code for the RCAR-GEN2 and RCAR-GEN3 devices.
The support code contains platform specific hardware access (TMU_BASE), and it is not needed for other Renesas devices such as RZ/N1. Therefore, alter Makefile to build renesas-cpg-mssr.c only for RCAR-GEN2 and RCAR-GEN3.
---
drivers/clk/renesas/Kconfig | 2 +- drivers/clk/renesas/Makefile | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-)
drivers/clk/renesas/Kconfig +1 -1
@@ -1,6 +1,6 @@ config CLK_RENESAS bool "Renesas clock drivers" - depends on CLK && ARCH_RMOBILE + depends on CLK && (ARCH_RMOBILE || ARCH_RZN1) help Enable support for clock present on Renesas RCar SoCs.
drivers/clk/renesas/Makefile +2 -3
@@ -1,5 +1,4 @@ -obj-$(CONFIG_CLK_RENESAS) += renesas-cpg-mssr.o -obj-$(CONFIG_CLK_RCAR_GEN2) += clk-rcar-gen2.o +obj-$(CONFIG_CLK_RCAR_GEN2) += clk-rcar-gen2.o renesas-cpg-mssr.o obj-$(CONFIG_CLK_R8A774A1) += r8a774a1-cpg-mssr.o obj-$(CONFIG_CLK_R8A774B1) += r8a774b1-cpg-mssr.o obj-$(CONFIG_CLK_R8A774C0) += r8a774c0-cpg-mssr.o
@@ -9,7 +8,7 @@ obj-$(CONFIG_CLK_R8A7791) += r8a7791-cpg-mssr.o obj-$(CONFIG_CLK_R8A7792) += r8a7792-cpg-mssr.o obj-$(CONFIG_CLK_R8A7793) += r8a7791-cpg-mssr.o obj-$(CONFIG_CLK_R8A7794) += r8a7794-cpg-mssr.o -obj-$(CONFIG_CLK_RCAR_GEN3) += clk-rcar-gen3.o +obj-$(CONFIG_CLK_RCAR_GEN3) += clk-rcar-gen3.o renesas-cpg-mssr.o obj-$(CONFIG_CLK_R8A7795) += r8a7795-cpg-mssr.o obj-$(CONFIG_CLK_R8A7796) += r8a7796-cpg-mssr.o obj-$(CONFIG_CLK_R8A77965) += r8a77965-cpg-mssr.o
Signature · 1 line
2.25.1
Re: [RFC PATCH v1 2/9] clk: renesas: prepare for non-RCAR clock drivers
Quoted 42 lines · Ralph Siemsen
Allow
CONFIG_CLK_RENESASto be set without bringing in RCAR-GEN2/3 code.
CONFIG_RENESASis used indrivers/clk/Makefileto control recursion into thedrivers/clk/renesassubdirectory. It also controls compilation ofrenesas-cpg-mssr.csupport code for the RCAR-GEN2 and RCAR-GEN3 devices.The support code contains platform specific hardware access (
TMU_BASE), and it is not needed for other Renesas devices such as RZ/N1. Therefore, alterMakefileto buildrenesas-cpg-mssr.conly for RCAR-GEN2 and RCAR-GEN3.Signed-off-by Ralph Siemsen <[email protected]>---
drivers/clk/renesas/Kconfig | 2 +- drivers/clk/renesas/Makefile | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-)drivers/clk/renesas/Kconfig +1
-1@@ -1,6 +1,6 @@ config CLK_RENESAS bool "Renesas clock drivers" - depends on CLK && ARCH_RMOBILE + depends on CLK && (ARCH_RMOBILE || ARCH_RZN1) help Enable support for clock present on Renesas RCar SoCs.drivers/clk/renesas/Makefile +1
-2@@ -1,5 +1,4 @@ -obj-$(CONFIG_CLK_RENESAS) += renesas-cpg-mssr.o -obj-$(CONFIG_CLK_RCAR_GEN2) += clk-rcar-gen2.o +obj-$(CONFIG_CLK_RCAR_GEN2) += clk-rcar-gen2.o renesas-cpg-mssr.o obj-$(CONFIG_CLK_R8A774A1) += r8a774a1-cpg-mssr.o obj-$(CONFIG_CLK_R8A774B1) += r8a774b1-cpg-mssr.o obj-$(CONFIG_CLK_R8A774C0) += r8a774c0-cpg-mssr.o
drivers/clk/renesas/Makefile obj-$(CONFIG_CLK_R8A7791) += r8a7791-cpg-mssr.o · line 14
Quoted 8 lines
drivers/clk/renesas/Makefile +1
-1@@ -9,7 +8,7 @@ obj-$(CONFIG_CLK_R8A7791) += r8a7791-cpg-mssr.o obj-$(CONFIG_CLK_R8A7792) += r8a7792-cpg-mssr.o obj-$(CONFIG_CLK_R8A7793) += r8a7791-cpg-mssr.o obj-$(CONFIG_CLK_R8A7794) += r8a7794-cpg-mssr.o -obj-$(CONFIG_CLK_RCAR_GEN3) += clk-rcar-gen3.o +obj-$(CONFIG_CLK_RCAR_GEN3) += clk-rcar-gen3.o renesas-cpg-mssr.o obj-$(CONFIG_CLK_R8A7795) += r8a7795-cpg-mssr.o obj-$(CONFIG_CLK_R8A7796) += r8a7796-cpg-mssr.o obj-$(CONFIG_CLK_R8A77965) += r8a77965-cpg-mssr.o
RFC PATCH 3/9 clk: renesas: add R906G032 driver
In reply to Ralph SiemsenClock driver for the Renesas RZ/N1 SoC family. This is based on the Linux kernel drivers/clk/renesas/r9a06g032-clocks.c.
Notable difference: this version avoids allocating a 'struct clk' for each clock source, as this is problematic before relocation. Instead, it uses the same approach as existing Renesas RCAR2/3 clock drivers, using a temporary structure filled on-the-fly.
---
- TODO: add support for div_table
drivers/clk/renesas/Kconfig | 6 + drivers/clk/renesas/Makefile | 1 + drivers/clk/renesas/r9a06g032-clocks.c | 734 +++++++++++++++++++++++++ 3 files changed, 741 insertions(+) create mode 100644 drivers/clk/renesas/r9a06g032-clocks.c
drivers/clk/renesas/Kconfig +6 -0
@@ -120,3 +120,9 @@ config CLK_R8A779A0 depends on CLK_RCAR_GEN3 help Enable this to support the clocks on Renesas R8A779A0 SoC. + +config CLK_R9A06G032 + bool "Renesas R9A06G032 clock driver" + depends on CLK_RENESAS + help + Enable this to support the clocks on Renesas R9A06G032 SoC.
drivers/clk/renesas/Makefile +1 -0
@@ -17,3 +17,4 @@ obj-$(CONFIG_CLK_R8A77980) += r8a77980-cpg-mssr.o obj-$(CONFIG_CLK_R8A77990) += r8a77990-cpg-mssr.o obj-$(CONFIG_CLK_R8A77995) += r8a77995-cpg-mssr.o obj-$(CONFIG_CLK_R8A779A0) += r8a779a0-cpg-mssr.o +obj-$(CONFIG_CLK_R9A06G032) += r9a06g032-clocks.o
drivers/clk/renesas/r9a06g032-clocks.c new file +734 -0
734 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [RFC PATCH v1 3/9] clk: renesas: add R906G032 driver
Quoted 23 lines · Ralph Siemsen
Clock driver for the Renesas RZ/N1 SoC family. This is based on the Linux kernel
drivers/clk/renesas/r9a06g032-clocks.c.Notable difference: this version avoids allocating a 'struct clk' for each clock source, as this is problematic before relocation. Instead, it uses the same approach as existing Renesas RCAR2/3 clock drivers, using a temporary structure filled on-the-fly.
Signed-off-by Ralph Siemsen <[email protected]>---
- TODO: add support fordiv_tabledrivers/clk/renesas/Kconfig | 6 + drivers/clk/renesas/Makefile | 1 + drivers/clk/renesas/r9a06g032-clocks.c | 734 +++++++++++++++++++++++++ 3 files changed, 741 insertions(+)create mode 100644
drivers/clk/renesas/r9a06g032-clocks.cdrivers/clk/renesas/Kconfig +0
-0
drivers/clk/renesas/Kconfig config CLK_R8A779A0 · line 128
Quoted 9 lines
drivers/clk/renesas/Kconfig +6
-0@@ -120,3 +120,9 @@ config CLK_R8A779A0 depends on CLK_RCAR_GEN3 help Enable this to support the clocks on Renesas R8A779A0 SoC. + +config CLK_R9A06G032 + bool "Renesas R9A06G032 clock driver" + depends on CLK_RENESAS + help + Enable this to support the clocks on Renesas R9A06G032 SoC.
nit: on the
...
Quoted 27 lines
drivers/clk/renesas/Makefile +1
-0@@ -17,3 +17,4 @@ obj-$(CONFIG_CLK_R8A77980) += r8a77980-cpg-mssr.o obj-$(CONFIG_CLK_R8A77990) += r8a77990-cpg-mssr.o obj-$(CONFIG_CLK_R8A77995) += r8a77995-cpg-mssr.o obj-$(CONFIG_CLK_R8A779A0) += r8a779a0-cpg-mssr.o +obj-$(CONFIG_CLK_R9A06G032) += r9a06g032-clocks.odrivers/clk/renesas/r9a06g032-clocks.c new file +12
-0@@ -0,0 +1,734 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* R9A06G032 clock driver +* +* Copyright (C) 2018 Renesas Electronics Europe Limited +* +* Michel Pollet <[email protected]>, <[email protected]> +*/ + +#include <common.h> +#include <clk-uclass.h> +#include <dm.h>
drivers/clk/renesas/r9a06g032-clocks.c line 22
Quoted 10 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +10
-0+#include <regmap.h> +#include <syscon.h> +#include <linux/bitops.h> +#include <linux/clk-provider.h> +#include <linux/delay.h> +#include <asm/io.h> + +#include <dt-bindings/clock/r9a06g032-sysctrl.h> + +struct r9a06g032_gate {
Can you add some documentation for each of the fields? Same for r9a06g032_clkdesc.
https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html
drivers/clk/renesas/r9a06g032-clocks.c line 24
Quoted 2 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +2
-0+u16 gate, reset, ready, midle, + scon, mirack, mistat;
What are the scon/mirack/mistat fields for? You define them for a lot of clocks, but I don't see them used in the driver.
drivers/clk/renesas/r9a06g032-clocks.c line 31
Quoted 7 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +7
-0+}; + +/* This is used to describe a clock for instantiation */ +struct r9a06g032_clkdesc { +const char *name; +uint32_t managed:1 ; +uint32_t type:3 ;
I wonder if we could define the enum here?
Quoted 14 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +14
-0+ uint32_t index: 8; + uint32_t source : 8; /* source index + 1 (0 == none) */ +/* these are used to populate the bitsel struct */ +union { +struct r9a06g032_gate gate; +/* for dividers */ +struct { +unsigned int div_min :10 , div_max :10 , reg:10 ; +u16 div_table[4 ]; + }; +/* For fixed-factor ones */ +struct { +u16 div, mul; + };
drivers/clk/renesas/r9a06g032-clocks.c line 55
Quoted 10 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +10
-0+/* for dual gate */ +struct { +uint16_t group :1 ; +u16 sel, g1, r1, g2, r2; + } dual; + }; +}; + +#define I_GATE (_clk, _rst, _rdy, _midle, _scon, _mirack, _mistat) \ + { .gate = _clk, .reset = _rst, \
If these fields have bitfield inside them, then those bitfields should
be assigned/constructed separately. That is, if .reset is actually a combined
offset/bit, then you need to expose those in the macro. Since you have a lot of these, you might want to do something like
#define BIT_OFFSET GENMASK(15, 5)
#define BIT_SHIFT GENMASK(4, 0)
#define PACK_BIT(offset, shift) (FIELD_PREP(BIT_OFFSET, offset) | FIELD_PREP(BIT_SHIFT, shift))
drivers/clk/renesas/r9a06g032-clocks.c line 57
Quoted 2 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +2
-0+ .ready = _rdy, .midle = _midle, \ + .scon = _scon, .mirack = _mirack, .mistat = _mistat }
Please put each assignment on a separate line
Quoted 17 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +17
-0+#define D_GATE (_idx, _n, _src, ...) \ + { .type = K_GATE, .index = R9A06G032_##_idx, \ + .source = 1 + R9A06G032_##_src, .name = _n, \ + .gate = I_GATE(__VA_ARGS__) } +#define D_MODULE (_idx, _n, _src, ...) \ + { .type = K_GATE, .index = R9A06G032_##_idx, \ + .source = 1 + R9A06G032_##_src, .name = _n, \ + .managed = 1, .gate = I_GATE(__VA_ARGS__) } +#define D_ROOT (_idx, _n, _mul, _div) \ + { .type = K_FFC, .index = R9A06G032_##_idx, .name = _n, \ + .div = _div, .mul = _mul } +#define D_FFC (_idx, _n, _src, _div) \ + { .type = K_FFC, .index = R9A06G032_##_idx, \ + .source = 1 + R9A06G032_##_src, .name = _n, \ + .div = _div, .mul = 1} +#define D_DIV (_idx, _n, _src, _reg, _min, _max, ...) \ + { .type = K_DIV, .index = R9A06G032_##_idx, \
drivers/clk/renesas/r9a06g032-clocks.c line 84
Quoted 10 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +10
-0+ .source = 1 + R9A06G032_##_src, .name = _n, \ + .reg = _reg, .div_min = _min, .div_max = _max, \ + .div_table = { __VA_ARGS__ } } +#define D_UGATE (_idx, _n, _src, _g, _g1, _r1, _g2, _r2) \ + { .type = K_DUALGATE, .index = R9A06G032_##_idx, \ + .source = 1 + R9A06G032_##_src, .name = _n, \ + .dual = { .group = _g, \ + .g1 = _g1, .r1 = _r1, .g2 = _g2, .r2 = _r2 }, } + +enum {K_GATE =0 ,K_FFC ,K_DIV ,K_BITSEL ,K_DUALGATE };
Please put each member on a separate line.
Quoted 28 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +28
-0+ +/* Internal clock IDs */ +#define R9A06G032_CLKOUT 0 +#define R9A06G032_CLKOUT_D10 2 +#define R9A06G032_CLKOUT_D16 3 +#define R9A06G032_CLKOUT_D160 4 +#define R9A06G032_CLKOUT_D1OR2 5 +#define R9A06G032_CLKOUT_D20 6 +#define R9A06G032_CLKOUT_D40 7 +#define R9A06G032_CLKOUT_D5 8 +#define R9A06G032_CLKOUT_D8 9 +#define R9A06G032_DIV_ADC 10 +#define R9A06G032_DIV_I2C 11 +#define R9A06G032_DIV_NAND 12 +#define R9A06G032_DIV_P1_PG 13 +#define R9A06G032_DIV_P2_PG 14 +#define R9A06G032_DIV_P3_PG 15 +#define R9A06G032_DIV_P4_PG 16 +#define R9A06G032_DIV_P5_PG 17 +#define R9A06G032_DIV_P6_PG 18 +#define R9A06G032_DIV_QSPI0 19 +#define R9A06G032_DIV_QSPI1 20 +#define R9A06G032_DIV_REF_SYNC 21 +#define R9A06G032_DIV_SDIO0 22 +#define R9A06G032_DIV_SDIO1 23 +#define R9A06G032_DIV_SWITCH 24 +#define R9A06G032_DIV_UART 25 +#define R9A06G032_DIV_MOTOR 64
drivers/clk/renesas/r9a06g032-clocks.c line 122
Quoted 10 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +10
-0+#define R9A06G032_CLK_DDRPHY_PLLCLK_D4 78 +#define R9A06G032_CLK_ECAT100_D4 79 +#define R9A06G032_CLK_HSR100_D2 80 +#define R9A06G032_CLK_REF_SYNC_D4 81 +#define R9A06G032_CLK_REF_SYNC_D8 82 +#define R9A06G032_CLK_SERCOS100_D2 83 +#define R9A06G032_DIV_CA7 84 + +#define R9A06G032_UART_GROUP_012 154 +#define R9A06G032_UART_GROUP_34567 155
Can you put these in your dt-bindings header? I think that would make it much clearer why there are gaps, and would avoid someone accidentally duplicating a clock id (although I suppose your array initializer below might complain?)
Quoted 196 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +196
-0+#define R9A06G032_CLOCK_COUNT (R9A06G032_UART_GROUP_34567 + 1) + +static const struct r9a06g032_clkdesc r9a06g032_clocks[] = { +D_ROOT (CLKOUT ,"clkout" ,25 ,1 ), +D_ROOT (CLK_PLL_USB ,"clk_pll_usb" ,12 ,10 ), +D_FFC (CLKOUT_D10 ,"clkout_d10" ,CLKOUT ,10 ), +D_FFC (CLKOUT_D16 ,"clkout_d16" ,CLKOUT ,16 ), +D_FFC (CLKOUT_D160 ,"clkout_d160" ,CLKOUT ,160 ), +D_DIV (CLKOUT_D1OR2 ,"clkout_d1or2" ,CLKOUT ,0 ,1 ,2 ), +D_FFC (CLKOUT_D20 ,"clkout_d20" ,CLKOUT ,20 ), +D_FFC (CLKOUT_D40 ,"clkout_d40" ,CLKOUT ,40 ), +D_FFC (CLKOUT_D5 ,"clkout_d5" ,CLKOUT ,5 ), +D_FFC (CLKOUT_D8 ,"clkout_d8" ,CLKOUT ,8 ), +D_DIV (DIV_ADC ,"div_adc" ,CLKOUT ,77 ,50 ,250 ), +D_DIV (DIV_I2C ,"div_i2c" ,CLKOUT ,78 ,12 ,16 ), +D_DIV (DIV_NAND ,"div_nand" ,CLKOUT ,82 ,12 ,32 ), +D_DIV (DIV_P1_PG ,"div_p1_pg" ,CLKOUT ,68 ,12 ,200 ), +D_DIV (DIV_P2_PG ,"div_p2_pg" ,CLKOUT ,62 ,12 ,128 ), +D_DIV (DIV_P3_PG ,"div_p3_pg" ,CLKOUT ,64 ,8 ,128 ), +D_DIV (DIV_P4_PG ,"div_p4_pg" ,CLKOUT ,66 ,8 ,128 ), +D_DIV (DIV_P5_PG ,"div_p5_pg" ,CLKOUT ,71 ,10 ,40 ), +D_DIV (DIV_P6_PG ,"div_p6_pg" ,CLKOUT ,18 ,12 ,64 ), +D_DIV (DIV_QSPI0 ,"div_qspi0" ,CLKOUT ,73 ,3 ,7 ), +D_DIV (DIV_QSPI1 ,"div_qspi1" ,CLKOUT ,25 ,3 ,7 ), +D_DIV (DIV_REF_SYNC ,"div_ref_sync" ,CLKOUT ,56 ,2 ,16 ,2 ,4 ,8 ,16 ), +D_DIV (DIV_SDIO0 ,"div_sdio0" ,CLKOUT ,74 ,20 ,128 ), +D_DIV (DIV_SDIO1 ,"div_sdio1" ,CLKOUT ,75 ,20 ,128 ), +D_DIV (DIV_SWITCH ,"div_switch" ,CLKOUT ,37 ,5 ,40 ), +D_DIV (DIV_UART ,"div_uart" ,CLKOUT ,79 ,12 ,128 ), +D_GATE (CLK_25_PG4 ,"clk_25_pg4" ,CLKOUT_D40 ,0x749 ,0x74a ,0x74b ,0 ,0xae3 ,0 ,0 ), +D_GATE (CLK_25_PG5 ,"clk_25_pg5" ,CLKOUT_D40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LK_REF_SYNC_D4 ,0x21b ,0x21c ,0x21d ,0 ,0 ,0 ,0 ), +D_MODULE (HCLK_UART5 ,"hclk_uart5" ,CLK_REF_SYNC_D4 ,0x220 ,0x221 ,0x222 ,0 ,0 ,0 ,0 ), +D_MODULE (HCLK_UART6 ,"hclk_uart6" ,CLK_REF_SYNC_D4 ,0x223 ,0x224 ,0x225 ,0 ,0 ,0 ,0 ), +D_MODULE (HCLK_UART7 ,"hclk_uart7" ,CLK_REF_SYNC_D4 ,0x226 ,0x227 ,0x228 ,0 ,0 ,0 ,0 ), +/* +* These are not hardware clocks, but are needed to handle the special +* case where we have a 'selector bit' that doesn't just change the +* parent for a clock, but also the gate it's supposed to use. +*/ + { + .index =R9A06G032_UART_GROUP_012 , + .name ="uart_group_012" , + .type =K_BITSEL , + .source =1 +R9A06G032_DIV_UART , +/* R9A06G032_SYSCTRL_REG_PWRCTRL_PG0_0 */ + .dual.sel = ((0x34 /4 ) <<5 ) |30 , + .dual.group =0 , + }, + { + .index =R9A06G032_UART_GROUP_34567 , + .name ="uart_group_34567" , + .type =K_BITSEL , + .source =1 +R9A06G032_DIV_P2_PG , +/* R9A06G032_SYSCTRL_REG_PWRCTRL_PG1_PR2 */ + .dual.sel = ((0xec /4 ) <<5 ) |24 , + .dual.group =1 , + }, +D_UGATE (CLK_UART0 ,"clk_uart0" ,UART_GROUP_012 ,0 ,0x1b2 ,0x1b3 ,0x1b4 ,0x1b5 ), +D_UGATE (CLK_UART1 ,"clk_uart1" ,UART_GROUP_012 ,0 ,0x1b6 ,0x1b7 ,0x1b8 ,0x1b9 ), +D_UGATE (CLK_UART2 ,"clk_uart2" ,UART_GROUP_012 ,0 ,0x1ba ,0x1bb ,0x1bc ,0x1bd ), +D_UGATE (CLK_UART3 ,"clk_uart3" ,UART_GROUP_34567 ,1 ,0x760 ,0x761 ,0x762 ,0x763 ), +D_UGATE (CLK_UART4 ,"clk_uart4" ,UART_GROUP_34567 ,1 ,0x764 ,0x765 ,0x766 ,0x767 ), +D_UGATE (CLK_UART5 ,"clk_uart5" ,UART_GROUP_34567 ,1 ,0x768 ,0x769 ,0x76a ,0x76b ), +D_UGATE (CLK_UART6 ,"clk_uart6" ,UART_GROUP_34567 ,1 ,0x76c ,0x76d ,0x76e ,0x76f ), +D_UGATE (CLK_UART7 ,"clk_uart7" ,UART_GROUP_34567 ,1 ,0x770 ,0x771 ,0x772 ,0x773 ), +}; + +struct r9a06g032_priv { +struct regmap *regmap; +struct clk mclk; +}; + +static const struct r9a06g032_clkdesc *r9a06g032_clk_get (struct clk *clk) +{ +const unsigned long clkid = clk->id &0xffff ; +int i; + +for (i =0 ; i <ARRAY_SIZE (r9a06g032_clocks); i++) { +if (r9a06g032_clocks[i].index == clkid) +return &r9a06g032_clocks[i]; + }
drivers/clk/renesas/r9a06g032-clocks.c line 329
Quoted 10 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +10
-0+ +return NULL ; +} + +static int r9a06g032_clk_get_parent (struct clk *clk,struct clk *parent) +{ +const struct r9a06g032_clkdesc *desc =r9a06g032_clk_get (clk); + +if (!desc) +return -ENODEV ;
ENOENT please
see https://u-boot.readthedocs.io/en/latest/develop/driver-model/design.html#error-codes
drivers/clk/renesas/r9a06g032-clocks.c line 330
Quoted 2 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +2
-0+ +if (desc->source ==0 )
if (!desc->source)
although I would reverse the clauses to make the condition clearer
drivers/clk/renesas/r9a06g032-clocks.c line 332
Quoted 1 line
drivers/clk/renesas/r9a06g032-clocks.c new file +1
-0+ parent->id = ~0 ;/* Top-level clock */
Can you use a define for this (instead of referring to ~0 everywhere)
drivers/clk/renesas/r9a06g032-clocks.c line 336
Quoted 4 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +4
-0+else + parent->id = desc->source -1 ; + + parent->dev = clk->dev;
I think you need to clk_request here.
drivers/clk/renesas/r9a06g032-clocks.c line 346
Quoted 9 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +9
-0+return 0 ; +} + +static ulong r9a06g032_clk_get_parent_rate (struct clk *clk) +{ +struct clk parent; + +if (r9a06g032_clk_get_parent (clk, &parent)) { +debug ("Failed to get parent clock for id=%lu\b" , clk->id);
dev_dbg please
drivers/clk/renesas/r9a06g032-clocks.c line 345
Quoted 1 line
drivers/clk/renesas/r9a06g032-clocks.c new file +1
-0+return 0 ;
Return -ENOENT here please. You can check for this with IS_ERR.
drivers/clk/renesas/r9a06g032-clocks.c line 352
Quoted 5 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +5
-0+ } + +if (parent.id == ~0 ) { +struct r9a06g032_priv *clocks =dev_get_priv (clk->dev); +ulong rate =clk_get_rate (&clocks->mclk);
You need a newline here
Quoted 4 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +4
-0+return rate; + } + +return clk_get_rate (&parent);
drivers/clk/renesas/r9a06g032-clocks.c line 366
Quoted 10 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +10
-0+} + +/* register/bit pairs are encoded as an uint16_t */ +static void +clk_rdesc_set (struct r9a06g032_priv *clocks, +u16 one,unsigned int on) +{ +uint offset =4 * (one >>5 ); +uint mask =1U << (one &0x1f ); +uint val = ((!!on) << (one &0x1f ));
Please either use bitfields for this, or use FIELD_GET() and friends.
drivers/clk/renesas/r9a06g032-clocks.c line 373
Quoted 6 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +6
-0+regmap_update_bits (clocks->regmap, offset, mask, val); +} + +static int +clk_rdesc_get (struct r9a06g032_priv *clocks, +uint16_t one)
I think this all fits on one line?
Quoted 11 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +11
-0+{ +uint offset =4 * (one >>5 ); +u32 val =0 ; + +regmap_read (clocks->regmap, offset, &val); + +return !!(val & (1U << (one &0x1f ))); +} + +/* +* Cheating a little bit here: leverage the existing code to control the
drivers/clk/renesas/r9a06g032-clocks.c line 394
Quoted 10 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +10
-0+* per-clock reset. It should really be handled by a reset controller instead. +*/ +void clk_rzn1_reset_state (struct clk *clk,int on) +{ +struct r9a06g032_priv *clocks =dev_get_priv (clk->dev); +const struct r9a06g032_clkdesc *desc =r9a06g032_clk_get (clk); +assert (desc); +assert (desc->type ==K_GATE ); +const struct r9a06g032_gate *g = &desc->gate; +assert (g->reset);
Please order declarations all at the beginning. In this case, you will need to do something like
struct r9a06g032_priv *clocks = dev_get_priv(clk->dev); const struct r9a06g032_clkdesc *desc = r9a06g032_clk_get(clk); const struct r9a06g032_gate *g; assert(desc); assert(desc->type == K_GATE); g = &desc->gate assert(g->reset);
Quoted 5 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +5
-0+clk_rdesc_set (clocks, g->reset, on); +} + +/* +* This implements the R9A06G032 clock gate 'driver'. We cannot use the system's
drivers/clk/renesas/r9a06g032-clocks.c line 410
Quoted 10 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +10
-0+* clock gate framework as the gates on the R9A06G032 have a special enabling +* sequence, therefore we use this little proxy. +*/ +static int r9a06g032_clk_gate_set (struct clk *clk,int on) +{ +struct r9a06g032_priv *clocks =dev_get_priv (clk->dev); +const struct r9a06g032_clkdesc *desc =r9a06g032_clk_get (clk); +assert (desc); +assert (desc->type ==K_GATE ); +const struct r9a06g032_gate *g = &desc->gate;
ditto
Quoted 58 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +58
-0+clk_rdesc_set (clocks, g->gate, on); +/* De-assert reset */ +if (g->reset) +clk_rdesc_set (clocks, g->reset,1 ); + +/* Hardware manual recommends 5us delay after enabling clock & reset */ +udelay (5 ); + +/* If the peripheral is memory mapped (i.e. an AXI slave), there is an +* associated SLVRDY bit in the System Controller that needs to be set +* so that the FlexWAY bus fabric passes on the read/write requests. +*/ +if (g->ready || g->midle) { +if (g->ready) +clk_rdesc_set (clocks, g->ready, on); +/* Clear 'Master Idle Request' bit */ +if (g->midle) +clk_rdesc_set (clocks, g->midle, !on); + } +/* Note: We don't wait for FlexWAY Socket Connection signal */ + +return 0 ; +} + +static int r9a06g032_clk_gate_enable (struct clk *clk) +{ +return r9a06g032_clk_gate_set (clk,1 ); +} + +static int r9a06g032_clk_gate_disable (struct clk *clk) +{ +return r9a06g032_clk_gate_set (clk,0 ); +} + +/* +* Fixed factor clock +*/ +static ulong r9a06g032_ffc_get_rate (struct clk *clk) +{ +const struct r9a06g032_clkdesc *desc =r9a06g032_clk_get (clk); +unsigned long parent_rate =r9a06g032_clk_get_parent_rate (clk); +unsigned long long rate; + +if (parent_rate ==0 ) { +debug ("%s: parent_rate is zero\n" , __func__); +return 0 ; + } + + rate = (unsigned long long )parent_rate * desc->mul; + rate =DIV_ROUND_UP (rate, desc->div); +return (ulong )rate; +} + +/* +* This implements R9A06G032 clock divider 'driver'. This differs from the +* standard clk_divider because the set_rate method must also set b[31] to +* trigger the hardware rate change. In theory it should also wait for this +* bit to clear.
drivers/clk/renesas/r9a06g032-clocks.c line 479
Quoted 10 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +10
-0+*/ +static ulong r9a06g032_div_get_rate (struct clk *clk) +{ +struct r9a06g032_priv *clocks =dev_get_priv (clk->dev); +const struct r9a06g032_clkdesc *desc =r9a06g032_clk_get (clk); +unsigned long parent_rate =r9a06g032_clk_get_parent_rate (clk); +u32 div =0 ; + +if (parent_rate ==0 ) { +debug ("%s: parent_rate is zero\n" , __func__);
Didn't you already log this?
drivers/clk/renesas/r9a06g032-clocks.c line 489
Quoted 10 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +10
-0+return 0 ; + } + +regmap_read (clocks->regmap,4 * desc->reg, &div); + +if (div < desc->div_min) + div = desc->div_min; +else if (div > desc->div_max) + div = desc->div_max; +return DIV_ROUND_UP (parent_rate, div);
DIV_ROUND_CLOSEST?
Quoted 15 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +15
-0+} + +static ulong r9a06g032_div_set_rate (struct clk *clk,ulong rate) +{ +struct r9a06g032_priv *clocks =dev_get_priv (clk->dev); +const struct r9a06g032_clkdesc *desc =r9a06g032_clk_get (clk); +unsigned long parent_rate =r9a06g032_clk_get_parent_rate (clk); + +if (parent_rate ==0 ) { +debug ("%s: parent_rate is zero\n" , __func__); +return 0 ; + } + +/* + 1 to cope with rates that have the remainder dropped */ +u32 div =DIV_ROUND_UP (parent_rate, rate +1 );
drivers/clk/renesas/r9a06g032-clocks.c line 514
Quoted 10 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +10
-0+ +/* Clamp to allowable range */ +if (div < desc->div_min) + div = desc->div_min; +else if (div > desc->div_max) + div = desc->div_max; + +/* TODO: use the .div_table if provided */ +if (desc->div_table[0 ]) +pr_err ("ERROR: %s: div_table not implemented\n" , __func__);
dev_err
But can't you just leave out the div_table member?
drivers/clk/renesas/r9a06g032-clocks.c line 517
Quoted 3 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +3
-0+ +pr_devel ("%s clkid %lu rate %ld parent %ld div %d\n" , __func__, clk->id, + rate, parent_rate, div);
dev_dbg
Quoted 68 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +68
-0+ +/* +* Need to write the bit 31 with the divider value to +* latch it. Technically we should wait until it has been +* cleared too. +* TODO: Find whether this callback is sleepable, in case +* the hardware /does/ require some sort of spinloop here. +*/ +regmap_write (clocks->regmap,4 * desc->reg, div |BIT (31 )); + +return 0 ; +} + +/* +* Dual gate. This handles toggling the approprate clock/reset bits, +* which depends on the mux setting above. +*/ +static int r9a06g032_clk_dualgate_setenable (struct r9a06g032_priv *clocks, +const struct r9a06g032_clkdesc *desc, +int enable) +{ +u8 sel_bit =clk_rdesc_get (clocks, desc->dual.sel); +u16 gate[2 ] = { desc->dual.g1, desc->dual.g2 }; +u16 reset[2 ] = { desc->dual.r1, desc->dual.r2 }; + +/* we always turn off the 'other' gate, regardless */ +clk_rdesc_set (clocks, gate[!sel_bit],0 ); +if (reset[!sel_bit]) +clk_rdesc_set (clocks, reset[!sel_bit],1 ); + +/* set the gate as requested */ +clk_rdesc_set (clocks, gate[sel_bit], enable); +if (reset[sel_bit]) +clk_rdesc_set (clocks, reset[sel_bit],1 ); + +return 0 ; +} + +static int r9a06g032_clk_dualgate_enable (struct clk *clk) +{ +struct r9a06g032_priv *clocks =dev_get_priv (clk->dev); +const struct r9a06g032_clkdesc *desc =r9a06g032_clk_get (clk); + +return r9a06g032_clk_dualgate_setenable (clocks, desc,1 ); +} + +static int r9a06g032_clk_dualgate_disable (struct clk *clk) +{ +struct r9a06g032_priv *clocks =dev_get_priv (clk->dev); +const struct r9a06g032_clkdesc *desc =r9a06g032_clk_get (clk); + +return r9a06g032_clk_dualgate_setenable (clocks, desc,0 ); +} + +static int r9a06g032_clk_dualgate_is_enabled (struct clk *clk) +{ +struct r9a06g032_priv *clocks =dev_get_priv (clk->dev); +const struct r9a06g032_clkdesc *desc =r9a06g032_clk_get (clk); +u8 sel_bit =clk_rdesc_get (clocks, desc->dual.sel); +u16 gate[2 ] = { desc->dual.g1, desc->dual.g2 }; + +return clk_rdesc_get (clocks, gate[sel_bit]); +} + +/* +* Main clock driver +*/ +static int r9a06g032_clk_enable (struct clk *clk)
drivers/clk/renesas/r9a06g032-clocks.c line 595
Quoted 10 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +10
-0+{ +const struct r9a06g032_clkdesc *desc =r9a06g032_clk_get (clk); + +switch (desc->type) { +case K_GATE : +return r9a06g032_clk_gate_enable (clk); +case K_DUALGATE : +return r9a06g032_clk_dualgate_enable (clk); +default : +printf ("ERROR: %s:%d unhandled type=%d\n" , __func__, __LINE__, desc->type);
Assert or dev_dbg is better here. This is "impossible" so we try and avoid increasing image size in these cases.
Quoted 95 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +95
-0+break ; + } + +return 0 ; +} + +static int r9a06g032_clk_disable (struct clk *clk) +{ +const struct r9a06g032_clkdesc *desc =r9a06g032_clk_get (clk); + +switch (desc->type) { +case K_GATE : +return r9a06g032_clk_gate_disable (clk); +case K_DUALGATE : +return r9a06g032_clk_dualgate_disable (clk); +default : +printf ("ERROR: %s:%d unhandled type=%d\n" , __func__, __LINE__, desc->type); +break ; + } + +return 0 ; +} + +static ulong r9a06g032_clk_get_rate (struct clk *clk) +{ +const struct r9a06g032_clkdesc *desc =r9a06g032_clk_get (clk); +ulong ret =0 ; + +assert (desc); + +switch (desc->type) { +case K_FFC : + ret =r9a06g032_ffc_get_rate (clk); +break ; +case K_GATE : + ret =r9a06g032_clk_get_parent_rate (clk); +break ; +case K_DIV : + ret =r9a06g032_div_get_rate (clk); +break ; +case K_BITSEL : +/* +* Look at the mux to determine parent. +* 0 means it is coming from UART DIV (group 012 or 34567) +* 1 means it is coming from USB_PLL +*/ +if (r9a06g032_clk_dualgate_is_enabled (clk)) { +struct clk clk = { .id =R9A06G032_CLK_PLL_USB }; + ret =r9a06g032_clk_get_parent_rate (&clk); + } + ret =r9a06g032_clk_get_parent_rate (clk); +break ; +case K_DUALGATE : + ret =r9a06g032_clk_get_parent_rate (clk); +break ; + } + +return ret; +} + +static ulong r9a06g032_clk_set_rate (struct clk *clk,ulong rate) +{ +const struct r9a06g032_clkdesc *desc =r9a06g032_clk_get (clk); +ulong ret =0 ; + +assert (desc); + +switch (desc->type) { +case K_DIV : + ret =r9a06g032_div_set_rate (clk, rate); +break ; +default : +printf ("ERROR: %s:%d not implemented yet\n" , __func__, __LINE__); + }; + +return ret; +} + +static int r9a06g032_clk_of_xlate (struct clk *clk,struct ofnode_phandle_args *args) +{ +if (args->args_count !=1 ) { +debug ("Invalid args_count: %d\n" , args->args_count); +return -EINVAL ; + } + + clk->id = args->args[0 ]; + +return 0 ; +} + +static const struct clk_ops r9a06g032_clk_ops = { + .enable = r9a06g032_clk_enable, + .disable = r9a06g032_clk_disable, + .get_rate = r9a06g032_clk_get_rate, + .set_rate = r9a06g032_clk_set_rate,
drivers/clk/renesas/r9a06g032-clocks.c line 700
Quoted 10 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +10
-0+ .of_xlate = r9a06g032_clk_of_xlate, +}; + +static int r9a06g032_clk_probe (struct udevice *dev) +{ +struct r9a06g032_priv *priv =dev_get_priv (dev); +int err; + + priv->regmap =syscon_regmap_lookup_by_phandle (dev,"regmap" ); +if (!priv->regmap) {
IS_ERR(priv->regmap)
drivers/clk/renesas/r9a06g032-clocks.c line 701
Quoted 1 line
drivers/clk/renesas/r9a06g032-clocks.c new file +1
-0+pr_err ("unable to find regmap\n" );
dev_dbg
drivers/clk/renesas/r9a06g032-clocks.c line 697
Quoted 1 line
drivers/clk/renesas/r9a06g032-clocks.c new file +1
-0+return -ENODEV ;
return ERR_PTR(priv->regmap)
Quoted 6 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +6
-0+ } + +/* Enable S/W reset */ +regmap_write (priv->regmap,0x120 ,0x41 ); + + err =clk_get_by_name (dev,"mclk" , &priv->mclk);
drivers/clk/renesas/r9a06g032-clocks.c line 718
Quoted 10 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +10
-0+if (err) +return err; + +return 0 ; +} + +static int r9a06g032_clk_remove (struct udevice *dev) +{ +return 0 ; +}
Not necessary.
Quoted 7 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +6
-0+ +static const struct udevice_id r9a06g032_clk_ids[] = { + { .compatible ="renesas,r9a06g032-sysctrl" }, + { } +}; +
drivers/clk/renesas/r9a06g032-clocks.c line 734
Quoted 10 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +10
-0+U_BOOT_DRIVER (clk_r9a06g032) = { + .name ="clk_r9a06g032" , + .id =UCLASS_CLK , + .of_match = r9a06g032_clk_ids, + .priv_auto =sizeof (struct r9a06g032_priv ), + .ops = &r9a06g032_clk_ops, + .probe = &r9a06g032_clk_probe, + .remove = &r9a06g032_clk_remove, + .flags =DM_FLAG_PRE_RELOC , +};
The overall structure looks good; most of these things you should be able to iron out fairly easily.
--Sean
Re: [RFC PATCH v1 3/9] clk: renesas: add R906G032 driver
Quoted 6 lines · Sean Anderson
+
drivers/clk/renesas/r9a06g032-clocks.c line 24
Quoted 2 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +2
-0+u16 gate, reset, ready, midle, + scon, mirack, mistat;What are the scon/mirack/mistat fields for? You define them for a lot of clocks, but I don't see them used in the driver.
These came from the Linux driver of the same name. I can only speculate that in turn, the Linux driver definitions were auto-generated from vendor provided XML or similar documentation.
I figured that it would be best to match the Linux kernel clock driver. That way fixes can easily be shared. In fact while doing this work, I found an error in the clock table [1] and I also made some simplifications [2].
Regarding the unused fields (scon, mirack, mistat): I am not really sure what their purpose is. Maybe there is some value in having them. I'll try to find out more information about them. If we do decide to drop them, I would like to keep it synchronised with the Linux driver.
Quoted 9 lines
drivers/clk/renesas/r9a06g032-clocks.c line 31
Quoted 7 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +7
-0+}; + +/* This is used to describe a clock for instantiation */ +struct r9a06g032_clkdesc { +const char *name; +uint32_t managed:1 ; +uint32_t type:3 ;I wonder if we could define the enum here?
This is still part of the code which I've intentionally kept identical to the Linux driver. I do agree that moving the enum seems reasonable, I'll put together a patch for this (and test it) and see if I can get it accepted on the kernel side.
Quoted 29 lines
Quoted 14 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +14
-0+ uint32_t index: 8; + uint32_t source : 8; /* source index + 1 (0 == none) */ +/* these are used to populate the bitsel struct */ +union { +struct r9a06g032_gate gate; +/* for dividers */ +struct { +unsigned int div_min :10 , div_max :10 , reg:10 ; +u16 div_table[4 ]; + }; +/* For fixed-factor ones */ +struct { +u16 div, mul; + };drivers/clk/renesas/r9a06g032-clocks.c line 55
Quoted 10 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +10
-0+/* for dual gate */ +struct { +uint16_t group :1 ; +u16 sel, g1, r1, g2, r2; + } dual; + }; +}; + +#define I_GATE (_clk, _rst, _rdy, _midle, _scon, _mirack, _mistat) \ + { .gate = _clk, .reset = _rst, \If these fields have bitfield inside them, then those bitfields should
be assigned/constructed separately. That is, if .reset is actually a combined
offset/bit, then you need to expose those in the macro. Since you have a lot of these, you might want to do something like
Quoted 4 lines
#define
BIT_OFFSETGENMASK(15, 5)
#defineBIT_SHIFTGENMASK(4, 0)#define
PACK_BIT(offset, shift)(FIELD_PREP(BIT_OFFSET, offset)|FIELD_PREP(BIT_SHIFT, shift))
I think it happened before I started working on RZ/N1, but there seemed to be quite a few iterations on how to represent the clock tree. At one point there were macros to assign/construct the bitfield values. And then a different way, and eventually the direct hex values you now see in the clock tables.
At the risk of re-opening old wounds (luckily not mine) I decided to just leave this part exactly as-is in the Linux driver.
Quoted 6 lines
Quoted 6 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +6
-0+ +/* Internal clock IDs */ +#define R9A06G032_CLKOUT 0 +#define R9A06G032_CLKOUT_D10 2 +#define R9A06G032_CLKOUT_D16 3 +#define R9A06G032_CLKOUT_D160 4
Quoted 8 lines
drivers/clk/renesas/r9a06g032-clocks.c line 122
Quoted 3 lines
[...]
drivers/clk/renesas/r9a06g032-clocks.c new file +2
-0+#define R9A06G032_UART_GROUP_012 154 +#define R9A06G032_UART_GROUP_34567 155Can you put these in your dt-bindings header? I think that would make it much clearer why there are gaps, and would avoid someone accidentally duplicating a clock id (although I suppose your array initializer below might complain?)
In fact quite a few of them are in the dt-bindings already, see include/dt-bindings/clock/r9a06g032-sysctrl.h
I'm not really sure why some of these are defined in the .C file while others are in the dt-bindings header. Like much of the other bits, this was something I just carried over as-is from the Linux driver.
Quoted 3 lines
drivers/clk/renesas/r9a06g032-clocks.c line 332
Quoted 1 line
drivers/clk/renesas/r9a06g032-clocks.c new file +1
-0+ parent->id = ~0 ;/* Top-level clock */ Can you use a define for this (instead of referring to ~0 everywhere)
Yes, that sounds reasonable. My list of fixes (for both Linux driver and the u-boot one) is going to get rather long ;-)
Quoted 6 lines
drivers/clk/renesas/r9a06g032-clocks.c line 336
Quoted 4 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +4
-0+else + parent->id = desc->source -1 ; + + parent->dev = clk->dev;I think you need to
clk_requesthere.
Normally clk_request is called by a driver wishing to use a particular clock. That is not the case here. This is in a helper function used to compute the current rate of a given clock. It only looks at the local table (struct r9a06g032_clkdsc).
Quoted 10 lines
drivers/clk/renesas/r9a06g032-clocks.c line 366
Quoted 8 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +8
-0+/* register/bit pairs are encoded as an uint16_t */ +static void +clk_rdesc_set (struct r9a06g032_priv *clocks, +u16 one,unsigned int on) +{ +uint offset =4 * (one >>5 ); +uint mask =1U << (one &0x1f ); +uint val = ((!!on) << (one &0x1f ));Please either use bitfields for this, or use
FIELD_GET()and friends.
Yes, this would be clearer - however as mentioned above, there was already quite a bit of teeth-gnashing about this encoding. I will prepare a patch for the Linux side and see what kind of reply I get.
I would very much prefer to keep both in sync as much as possible.
Quoted 28 lines
Quoted 28 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +28
-0+/* +* Fixed factor clock +*/ +static ulong r9a06g032_ffc_get_rate (struct clk *clk) +{ +const struct r9a06g032_clkdesc *desc =r9a06g032_clk_get (clk); +unsigned long parent_rate =r9a06g032_clk_get_parent_rate (clk); +unsigned long long rate; + +if (parent_rate ==0 ) { +debug ("%s: parent_rate is zero\n" , __func__); +return 0 ; + } + + rate = (unsigned long long )parent_rate * desc->mul; + rate =DIV_ROUND_UP (rate, desc->div); +return (ulong )rate; +} + +/* +* This implements R9A06G032 clock divider 'driver'. This differs from the +* standard clk_divider because the set_rate method must also set b[31] to +* trigger the hardware rate change. In theory it should also wait for this +* bit to clear. +*/ +static ulong r9a06g032_div_get_rate (struct clk *clk) +{ +struct r9a06g032_priv *clocks =dev_get_priv (clk->dev);
Quoted 8 lines
drivers/clk/renesas/r9a06g032-clocks.c line 479
Quoted 6 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +6
-0+const struct r9a06g032_clkdesc *desc =r9a06g032_clk_get (clk); +unsigned long parent_rate =r9a06g032_clk_get_parent_rate (clk); +u32 div =0 ; + +if (parent_rate ==0 ) { +debug ("%s: parent_rate is zero\n" , __func__);Didn't you already log this?
It is for a different clock type. However I will see if I do something to avoid the duplication.
Quoted 13 lines
drivers/clk/renesas/r9a06g032-clocks.c line 489
Quoted 11 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +10
-0+return 0 ; + } + +regmap_read (clocks->regmap,4 * desc->reg, &div); + +if (div < desc->div_min) + div = desc->div_min; +else if (div > desc->div_max) + div = desc->div_max; +return DIV_ROUND_UP (parent_rate, div);
DIV_ROUND_CLOSEST?
I'm hesitant to change the logic on this, as it could subtly alter the values.
Quoted 7 lines
drivers/clk/renesas/r9a06g032-clocks.c line 514
Quoted 3 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +3
-0+/* TODO: use the .div_table if provided */ +if (desc->div_table[0 ]) +pr_err ("ERROR: %s: div_table not implemented\n" , __func__);
dev_errBut can't you just leave out the
div_tablemember?
Only a few of the clocks have a div_table, but for those, the table specifies the allowable divider values. So right now, the code cannot correctly set such clocks, as it may try programming illegal values (most likely with the result that you don't get the expected rate).
The Linux driver does implement the div_table logic, I simply did not carry it over yet to u-boot. Mostly because I have not yet had need for one of the few clocks which does use the table. I do plan to add it.
Quoted 9 lines
Quoted 9 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +9
-0+/* +* Main clock driver +*/ +static int r9a06g032_clk_enable (struct clk *clk) +{ +const struct r9a06g032_clkdesc *desc =r9a06g032_clk_get (clk); + +switch (desc->type) { +case K_GATE :
Quoted 8 lines
drivers/clk/renesas/r9a06g032-clocks.c line 595
Quoted 5 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +5
-0+return r9a06g032_clk_gate_enable (clk); +case K_DUALGATE : +return r9a06g032_clk_dualgate_enable (clk); +default : +printf ("ERROR: %s:%d unhandled type=%d\n" , __func__, __LINE__, desc->type);Assert or
dev_dbgis better here. This is "impossible" so we try and avoid increasing image size in these cases.
Fair enough. Though I have to say I have been bitten by this kind of thing a few times. After having spent time debugging-via-printf, I would then discover an assert or dev_dbg that points out the exact problem. If only I had enabled DEBUG for that file! And yet if I enable DEBUG globally, there is so much noise, that I don't notice the one message that might have been helpful.
Quoted 2 lines
The overall structure looks good; most of these things you should be able to iron out fairly easily.
I have skipped over a few of the smaller points regarding return values, etc, but I will address them in next version of the patch. Thanks again for your time reviewing this.
Regards,
-Ralph
Re: [RFC PATCH v1 3/9] clk: renesas: add R906G032 driver
Quoted 5 lines · Ralph Siemsen
Quoted 4 lines · Sean Anderson
+
Quoted 2 lines
+ u16 gate, reset, ready, midle,
+ scon, mirack, mistat;
Quoted 8 lines
Quoted 2 lines
What are the scon/mirack/mistat fields for? You define them for a lot of clocks, but I don't see them used in the driver.
These came from the Linux driver of the same name. I can only speculate that in turn, the Linux driver definitions were auto-generated from vendor provided XML or similar documentation.
I figured that it would be best to match the Linux kernel clock driver. That way fixes can easily be shared. In fact while doing this work, I found an error in the clock table [1] and I also made some simplifications [2].
Regarding the unused fields (scon, mirack, mistat): I am not really sure what their purpose is. Maybe there is some value in having them. I'll try to find out more information about them. If we do decide to drop them, I would like to keep it synchronised with the Linux driver.
OK, well if you don't use them then perhaps you can just leave them in the macro but remove them from the struct. That way you can add support for them later if you need to, but they don't take up space in the mean time. A comment summarizing your explanation above would be helpful.
Quoted 45 lines
Quoted 9 lines
drivers/clk/renesas/r9a06g032-clocks.c line 31
Quoted 7 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +7
-0+}; + +/* This is used to describe a clock for instantiation */ +struct r9a06g032_clkdesc { + const char *name; + uint32_t managed: 1; + uint32_t type: 3;I wonder if we could define the enum here?
This is still part of the code which I've intentionally kept identical to the Linux driver. I do agree that moving the enum seems reasonable, I'll put together a patch for this (and test it) and see if I can get it accepted on the kernel side.
Quoted 29 lines
Quoted 20 lines
+
uint32_tindex: 8;
+uint32_tsource : 8; /* source index + 1 (0 == none) */ + /* these are used to populate the bitsel struct */ + union {
+ structr9a06g032_gategate;
+ /* for dividers */
+ struct {
+ unsigned intdiv_min: 10,div_max: 10, reg: 10; + u16 div_table[4];
+ };
+ /* For fixed-factor ones */
+ struct {
+ u16 div, mul;
+ };
+ /* for dual gate */
+ struct {
+uint16_tgroup : 1;
+ u16 sel, g1, r1, g2, r2;
+ } dual;
+ };drivers/clk/renesas/r9a06g032-clocks.c line 55
Quoted 4 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +4
-0+}; + +#define I_GATE (_clk, _rst, _rdy, _midle, _scon, _mirack, _mistat) \ + { .gate = _clk, .reset = _rst, \If these fields have bitfield inside them, then those bitfields should
be assigned/constructed separately. That is, if .reset is actually a combined
offset/bit, then you need to expose those in the macro. Since you have a lot of these, you might want to do something like
Quoted 8 lines
Quoted 4 lines
#define BIT_OFFSET
GENMASK(15, 5)
#define BIT_SHIFTGENMASK(4, 0)#define
PACK_BIT(offset, shift)(FIELD_PREP(BIT_OFFSET, offset)|FIELD_PREP(BIT_SHIFT, shift))I think it happened before I started working on RZ/N1, but there seemed to be quite a few iterations on how to represent the clock tree. At one point there were macros to assign/construct the bitfield values. And then a different way, and eventually the direct hex values you now see in the clock tables.
At the risk of re-opening old wounds (luckily not mine) I decided to just leave this part exactly as-is in the Linux driver.
Can you link to that discussion? The earliest discussion of that series I could find was [1], and there's no mention of the encoding. This encoding scheme seems to be used only for this SoC, and not for any of the other renesas drivers. I suspect that this just wasn't reviewed in detail the first time around...
[1] https://lore.kernel.org/all/[email protected]/
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +6
-0+ +/* Internal clock IDs */ +#define R9A06G032_CLKOUT 0 +#define R9A06G032_CLKOUT_D10 2 +#define R9A06G032_CLKOUT_D16 3 +#define R9A06G032_CLKOUT_D160 4Quoted 8 lines
drivers/clk/renesas/r9a06g032-clocks.c line 122
Quoted 3 lines
[...]
drivers/clk/renesas/r9a06g032-clocks.c new file +2
-0+#define R9A06G032_UART_GROUP_012 154 +#define R9A06G032_UART_GROUP_34567 155Can you put these in your dt-bindings header? I think that would make it much clearer why there are gaps, and would avoid someone accidentally duplicating a clock id (although I suppose your array initializer below might complain?)
Quoted 3 lines
In fact quite a few of them are in the dt-bindings already, see
include/dt-bindings/clock/r9a06g032-sysctrl.hI'm not really sure why some of these are defined in the .C file while others are in the dt-bindings header. Like much of the other bits, this was something I just carried over as-is from the Linux driver.
I think these are "internal" clocks (that is, clocks which don't really exist like intermediate dividers) whereas the others are public-facing clocks. It's up to you, but maybe have a comment noting where the other ids come from.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
+
parent->id= ~0; /* Top-level clock */Can you use a define for this (instead of referring to ~0 everywhere)
Yes, that sounds reasonable. My list of fixes (for both Linux driver and the u-boot one) is going to get rather long ;-)
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
+ else
+parent->id=desc->source- 1;
+
+parent->dev=clk->dev;I think you need to
clk_requesthere.Normally
clk_requestis called by a driver wishing to use a particular clock. That is not the case here. This is in a helper function used to compute the current rate of a given clock. It only looks at the local table (structr9a06g032_clkdsc).
You call clk_get_rate on it. Any time you "create" a new clock, you must call clk_request.
Quoted 52 lines
Quoted 10 lines
drivers/clk/renesas/r9a06g032-clocks.c line 366
Quoted 8 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +8
-0+/* register/bit pairs are encoded as an uint16_t */ +static void +clk_rdesc_set (struct r9a06g032_priv *clocks, + u16 one, unsigned int on) +{ + uint offset = 4 * (one >> 5); + uint mask = 1U << (one & 0x1f); + uint val = ((!!on) << (one & 0x1f));Please either use bitfields for this, or use
FIELD_GET()and friends.Yes, this would be clearer - however as mentioned above, there was already quite a bit of teeth-gnashing about this encoding. I will prepare a patch for the Linux side and see what kind of reply I get.
I would very much prefer to keep both in sync as much as possible.
Quoted 28 lines
Quoted 28 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +28
-0+/* +* Fixed factor clock +*/ +static ulong r9a06g032_ffc_get_rate (struct clk *clk) +{ + const struct r9a06g032_clkdesc *desc = r9a06g032_clk_get(clk); + unsigned long parent_rate = r9a06g032_clk_get_parent_rate(clk); + unsigned long long rate; + + if (parent_rate == 0) { + debug("%s: parent_rate is zero\n", __func__); + return 0; + } + + rate = (unsigned long long)parent_rate * desc->mul; + rate = DIV_ROUND_UP(rate, desc->div); + return (ulong)rate; +} + +/* +* This implements R9A06G032 clock divider 'driver'. This differs from the +* standard clk_divider because the set_rate method must also set b[31] to +* trigger the hardware rate change. In theory it should also wait for this +* bit to clear. +*/ +static ulong r9a06g032_div_get_rate (struct clk *clk) +{ + struct r9a06g032_priv *clocks = dev_get_priv(clk->dev);Quoted 8 lines
Quoted 6 lines
+ const struct
r9a06g032_clkdesc*desc =r9a06g032_clk_get(clk); + unsigned longparent_rate=r9a06g032_clk_get_parent_rate(clk); + u32 div = 0;
+
+ if (parent_rate== 0) {
+debug("%s: parent_rate is zero\n", __func__);Didn't you already log this?
Quoted 1 line
It is for a different clock type. However I will see if I do something to avoid the duplication.
I mean in r9a06g032_clk_get_parent_rate. You can also just do
if (!parent_rate)
...
Quoted 14 lines
Quoted 13 lines
drivers/clk/renesas/r9a06g032-clocks.c line 489
Quoted 11 lines
+ return 0;
+ }drivers/clk/renesas/r9a06g032-clocks.c new file +8
-0+ + regmap_read(clocks->regmap, 4 * desc->reg, &div); + + if (div < desc->div_min) + div = desc->div_min; + else if (div > desc->div_max) + div = desc->div_max; + return DIV_ROUND_UP(parent_rate, div);
DIV_ROUND_CLOSEST?
Quoted 1 line
I'm hesitant to change the logic on this, as it could subtly alter the values.
Well if you have 2MHz divided by 3, the resulting rate is closer to 666667 kHz than 666666 Hz.
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
+ /* TODO: use the .div_table if provided */
+ if (desc->div_table[0])
+pr_err("ERROR: %s: div_table not implemented\n", __func__);
dev_errBut can't you just leave out the
div_tablemember?Only a few of the clocks have a
div_table, but for those, the table specifies the allowable divider values. So right now, the code cannot correctly set such clocks, as it may try programming illegal values (most likely with the result that you don't get the expected rate).The Linux driver does implement the
div_tablelogic, I simply did not carry it over yet to u-boot. Mostly because I have not yet had need for one of the few clocks which does use the table. I do plan to add it.
OK
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
drivers/clk/renesas/r9a06g032-clocks.c new file +9
-0+/* +* Main clock driver +*/ +static int r9a06g032_clk_enable (struct clk *clk) +{ + const struct r9a06g032_clkdesc *desc = r9a06g032_clk_get(clk); + + switch (desc->type) { + case K_GATE:Quoted 8 lines
Quoted 5 lines
+ return
r9a06g032_clk_gate_enable(clk);
+ caseK_DUALGATE:
+ returnr9a06g032_clk_dualgate_enable(clk);
+ default:
+printf("ERROR: %s:%d unhandled type=%d\n", __func__, __LINE__, desc->type);Assert or
dev_dbgis better here. This is "impossible" so we try and avoid increasing image size in these cases.
Quoted 1 line
Fair enough. Though I have to say I have been bitten by this kind of thing a few times. After having spent time debugging-via-printf, I would then discover an assert or
dev_dbgthat points out the exact problem. If only I had enabled DEBUG for that file! And yet if I enable DEBUG globally, there is so much noise, that I don't notice the one message that might have been helpful.
I generally stick a #define DEBUG at the top of a file any time I get an error with no message. You still return 0, so I suggest returning -EINVAL (or something else uncommon) so you have somewhere to start.
Quoted 7 lines
Quoted 2 lines
The overall structure looks good; most of these things you should be able to iron out fairly easily.
I have skipped over a few of the smaller points regarding return values, etc, but I will address them in next version of the patch. Thanks again for your time reviewing this.
Regards,
-Ralph
Re: [RFC PATCH v1 3/9] clk: renesas: add R906G032 driver
Quoted 6 lines · Sean Anderson
Quoted 1 line
Regarding the unused fields (scon, mirack, mistat): I am not really sure what their purpose is. Maybe there is some value in having them. I'll try to find out more information about them. If we do decide to drop them, I would like to keep it synchronised with the Linux driver.
OK, well if you don't use them then perhaps you can just leave them in the macro but remove them from the struct. That way you can add support for them later if you need to, but they don't take up space in the mean time. A comment summarizing your explanation above would be helpful.
I did figure out (mostly) what they are for, so I can see some value in keeping at least some of them. But as you said, they are currently unused, so dropping them from the structure make sense.
I have prepared patches for this firstly on the kernel side, and then I will make the same change in this u-boot driver. Stay tuned :-)
Quoted 11 lines
Quoted 3 lines
I think it happened before I started working on RZ/N1, but there seemed to be quite a few iterations on how to represent the clock tree. At one point there were macros to assign/construct the bitfield values. And then a different way, and eventually the direct hex values you now see in the clock tables.
At the risk of re-opening old wounds (luckily not mine) I decided to just leave this part exactly as-is in the Linux driver.
Can you link to that discussion? The earliest discussion of that series I could find was [1], and there's no mention of the encoding. This encoding scheme seems to be used only for this SoC, and not for any of the other renesas drivers. I suspect that this just wasn't reviewed in detail the first time around...
That link [1] is the current driver, which uses the packed encoding (with a register offset and bit number stored as a packed uint16_t).
This is based (loosely) on an earlier version of the driver, which you can find in the Schneider kernel repo [2] on the 4.19 and older branch. This version stores clock information is in the device tree [3] and uses _BIT() macro in the clock tables [4]
[2] https://github.com/renesas-rz/rzn1_linux/tree/rzn1-stable-v4.19/drivers/clk/rzn1
[3] https://github.com/renesas-rz/rzn1_linux/blob/rzn1-stable-v4.19/arch/arm/boot/dts/rzn1-clocks.dtsi
Evidently this was not deemed suitable, and thus morphed into the version that did get merged [1]. At least that is my guess, I don't know for sure what transpired.
I have modified the clock table so that the register offset and bitnum are explicit values, rather than packed together. I will run this up the kernel side and see if they agree. Am still trying to test it though...
Quoted 8 lines
Quoted 3 lines
In fact quite a few of them are in the dt-bindings already, see
include/dt-bindings/clock/r9a06g032-sysctrl.hI'm not really sure why some of these are defined in the .C file while others are in the dt-bindings header. Like much of the other bits, this was something I just carried over as-is from the Linux driver.
I think these are "internal" clocks (that is, clocks which don't really exist like intermediate dividers) whereas the others are public-facing clocks. It's up to you, but maybe have a comment noting where the other ids come from.
I guess that is plausible explanation.. I will add a comment...
Quoted 11 lines
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
+ else
+parent->id=desc->source- 1;
+
+parent->dev=clk->dev;I think you need to
clk_requesthere.Normally
clk_requestis called by a driver wishing to use a particular clock. That is not the case here. This is in a helper function used to compute the current rate of a given clock. It only looks at the local table (structr9a06g032_clkdsc).You call
clk_get_rateon it. Any time you "create" a new clock, you must callclk_request.
So the situation here is similar to that on the mediatek patches from Weijie Gao [5], where you made a similar comment. These are not real clocks, they have no ops->request, and the only field used is clk->id. This is done primarily to avoid a bunch of malloc of struct clk, particularly in the early u-boot (before relocation).
[5] https://lore.kernel.org/all/[email protected]/
Quoted 6 lines
Quoted 1 line
It is for a different clock type. However I will see if I do something to avoid the duplication.
I mean in
r9a06g032_clk_get_parent_rate. You can also just doif (!parent_rate)
...
I've fixed this (and several similar instances elsewhere).
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
DIV_ROUND_CLOSEST?I'm hesitant to change the logic on this, as it could subtly alter the values.
Well if you have 2MHz divided by 3, the resulting rate is closer to 666667 kHz than 666666 Hz.
While I can't argue with the math, the linux driver upon which this is based uses DIV_ROUND_UP everywhere. Maybe that is something to also re-consider, but for the time being, I don't want to make the change even more complicated...
Quoted 5 lines
Quoted 1 line
Fair enough. Though I have to say I have been bitten by this kind of thing a few times. After having spent time debugging-via-printf, I would then discover an assert or
dev_dbgthat points out the exact problem. If only I had enabled DEBUG for that file! And yet if I enable DEBUG globally, there is so much noise, that I don't notice the one message that might have been helpful.I generally stick a
#define DEBUGat the top of a file any time I get an error with no message. You still return 0, so I suggest returning-EINVAL(or something else uncommon) so you have somewhere to start.
Yep, that works fine when developing a driver... but if you are debugging a board, it is often not clear which file(s) should get sprinkled with DEBUG... and turning it on globally is too verbose to be useful in most cases.
Anyhow, thanks for your review, and v3 will be posted eventually, once I get the kernel side sorted.
-Ralph
Re: [RFC PATCH v1 3/9] clk: renesas: add R906G032 driver
Hi Sean,
I finally got around to posting v3 of this patch series. I wanted to touch on a few issues you had mentioned in previous review.
Quoted 11 lines · Ralph Siemsen
Quoted 9 lines · Sean Anderson
Quoted 4 lines
Regarding the unused fields (scon, mirack, mistat): I am not really sure what their purpose is. Maybe there is some value in having them. I'll try to find out more information about them. If we do decide to drop them, I would like to keep it synchronised with the Linux driver.
OK, well if you don't use them then perhaps you can just leave them in the macro but remove them from the struct. That way you can add support for them later if you need to, but they don't take up space in the mean time. A comment summarizing your explanation above would be helpful.
So I ended up doing as you suggested: keeping the values in the tables, in case they are needed in the future, but omitting them from the structure to save space.
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
DIV_ROUND_CLOSEST?I'm hesitant to change the logic on this, as it could subtly alter the values.
Well if you have 2MHz divided by 3, the resulting rate is closer to 666667 kHz than 666666 Hz.
This could result in the chosen clock rate being higher than what was requested. And in turn that could result in violating the spec of a hardware device.
So I have kept the original logic here.
Regards
Ralph
RFC PATCH 4/9 pinctrl: renesas: add R906G032 driver
In reply to Ralph SiemsenPinctrl/pinconf driver for Renesas RZ/N1 (R906G032) SoC.
This is quite rudimentary right now, and only supports applying a default pin configuration as specified by the device tree.
TODO:
- iterate over subnodes, so we can handle groups of pins with different bias/strength settings
- use the regmap_update_bits for level1/level2 register updates --> does not exist for regmap_ranges, consider adding?
---
drivers/pinctrl/Makefile | 1 + drivers/pinctrl/renesas/Kconfig | 7 + drivers/pinctrl/renesas/Makefile | 1 + drivers/pinctrl/renesas/pinctrl-rzn1.c | 398 +++++++++++++++++++++ include/dt-bindings/pinctrl/rzn1-pinctrl.h | 141 ++++++++ 5 files changed, 548 insertions(+) create mode 100644 drivers/pinctrl/renesas/pinctrl-rzn1.c create mode 100644 include/dt-bindings/pinctrl/rzn1-pinctrl.h
drivers/pinctrl/Makefile +1 -0
@@ -14,6 +14,7 @@ obj-$(CONFIG_PINCTRL_INTEL) += intel/ obj-$(CONFIG_ARCH_MTMIPS) += mtmips/ obj-$(CONFIG_ARCH_NPCM) += nuvoton/ obj-$(CONFIG_ARCH_RMOBILE) += renesas/ +obj-$(CONFIG_ARCH_RZN1) += renesas/ obj-$(CONFIG_PINCTRL_SANDBOX) += pinctrl-sandbox.o obj-$(CONFIG_PINCTRL_SUNXI) += sunxi/ obj-$(CONFIG_PINCTRL_UNIPHIER) += uniphier/
drivers/pinctrl/renesas/Kconfig +7 -0
@@ -121,3 +121,10 @@ config PINCTRL_PFC_R7S72100 Support pin multiplexing control on Renesas RZ/A1 R7S72100 SoCs. endif + +config PINCTRL_RZN1 + bool "Renesas RZ/N1 R906G032 pin control driver" + depends on ARCH_RZN1 + default y if ARCH_RZN1 + help + Support pin multiplexing control on Renesas RZ/N1 R906G032 SoCs.
drivers/pinctrl/renesas/Makefile +1 -0
@@ -17,3 +17,4 @@ obj-$(CONFIG_PINCTRL_PFC_R8A77990) += pfc-r8a77990.o obj-$(CONFIG_PINCTRL_PFC_R8A77995) += pfc-r8a77995.o obj-$(CONFIG_PINCTRL_PFC_R8A779A0) += pfc-r8a779a0.o obj-$(CONFIG_PINCTRL_PFC_R7S72100) += pfc-r7s72100.o +obj-$(CONFIG_PINCTRL_RZN1) += pinctrl-rzn1.o
drivers/pinctrl/renesas/pinctrl-rzn1.c new file +398 -0
398 lines not on this page · raw message
include/dt-bindings/pinctrl/rzn1-pinctrl.h new file +141 -0
141 lines not on this page · raw message
Signature · 1 line
2.25.1
RFC PATCH 5/9 ram: cadence: add driver for Cadence EDAC
In reply to Ralph SiemsenDriver for Cadence EDAC DDR controller, as found in the Renesas RZ/N1. Only basic setup, not using the ECC features.
---
drivers/ram/Kconfig | 1 + drivers/ram/Makefile | 2 + drivers/ram/cadence/Kconfig | 24 ++ drivers/ram/cadence/Makefile | 1 + drivers/ram/cadence/ddr_async.c | 295 +++++++++++++++++++++++ drivers/ram/cadence/ddr_ctrl.c | 414 ++++++++++++++++++++++++++++++++ drivers/ram/cadence/ddr_ctrl.h | 172 +++++++++++++ 7 files changed, 909 insertions(+) create mode 100644 drivers/ram/cadence/Kconfig create mode 100644 drivers/ram/cadence/Makefile create mode 100644 drivers/ram/cadence/ddr_async.c create mode 100644 drivers/ram/cadence/ddr_ctrl.c create mode 100644 drivers/ram/cadence/ddr_ctrl.h
drivers/ram/Kconfig +1 -0
@@ -97,6 +97,7 @@ config IMXRT_SDRAM This driver is for the sdram memory interface with the SEMC. source "drivers/ram/aspeed/Kconfig" +source "drivers/ram/cadence/Kconfig" source "drivers/ram/rockchip/Kconfig" source "drivers/ram/sifive/Kconfig" source "drivers/ram/stm32mp1/Kconfig"
drivers/ram/Makefile +2 -0
@@ -22,3 +22,5 @@ obj-$(CONFIG_IMXRT_SDRAM) += imxrt_sdram.o obj-$(CONFIG_RAM_SIFIVE) += sifive/ obj-$(CONFIG_ARCH_OCTEON) += octeon/ + +obj-$(CONFIG_CADENCE_DDR_CTRL) += cadence/
drivers/ram/cadence/Kconfig new file +24 -0
@@ -0,0 +1,24 @@ +if RAM || SPL_RAM + +config CADENCE_DDR_CTRL + bool "Enable Cadence DDR controller" + depends on DM + help + Enable support for Cadence DDR controller, as found on + the Renesas RZ/N1 SoC. This controller has a large number + of registers which need to be programmed, mostly using values + obtained from Denali SOMA files via a TCL script. + +if CADENCE_DDR_CTRL + +# TODO: convert this to devicetree option +config CADENCE_DDR_CTRL_ENABLE_ECC + bool "Enable ECC support" + +# TODO: conver this to devicetree option +config CADENCE_DDR_CTRL_8BIT_WIDTH + bool "Reduce data width from 16 to 8 bits" + +endif + +endif
drivers/ram/cadence/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_CADENCE_DDR_CTRL) += ddr_async.o ddr_ctrl.o
drivers/ram/cadence/ddr_async.c new file +295 -0
295 lines not on this page · raw message
drivers/ram/cadence/ddr_ctrl.c new file +414 -0
414 lines not on this page · raw message
drivers/ram/cadence/ddr_ctrl.h new file +172 -0
172 lines not on this page · raw message
Signature · 1 line
2.25.1
RFC PATCH 6/9 dts: basic devicetree for Renesas RZ/N1 SoC
In reply to Ralph SiemsenThis is taken from Linux kernel 5.17, and contains just bare minimum
functionality: CPU, UART and system timer.
Additional functionality (from newer kernel versions) will be added later. Note that the Linux side is under active development.
---
The following changes were made, compared with Linux 5.17:
1) Add node for system controller registers. Declare it as syscon to provide a regmap interface.
2) In the clock controller node (renesas,r9a06g032-sysctrl), replace regs with regmap.
3) Add syscon-reset node, making use of the syscon regmap.
I could not find a way to avoid 1) and 2). Putting "syscon" in the compatible string for the clock controller leads to a catch-22, where the driver fails to initialize, and then boot hangs.
arch/arm/dts/r9a06g032.dtsi | 225 ++++++++++++++++++ include/dt-bindings/clock/r9a06g032-sysctrl.h | 148 ++++++++++++ 2 files changed, 373 insertions(+) create mode 100644 arch/arm/dts/r9a06g032.dtsi create mode 100644 include/dt-bindings/clock/r9a06g032-sysctrl.h
arch/arm/dts/r9a06g032.dtsi new file +225 -0
@@ -0,0 +1,225 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Base Device Tree Source for the Renesas RZ/N1D (R9A06G032) + * + * Copyright (C) 2018 Renesas Electronics Europe Limited + * + */ + +#include <dt-bindings/interrupt-controller/arm-gic.h> +#include <dt-bindings/clock/r9a06g032-sysctrl.h> + +/ { + compatible = "renesas,r9a06g032"; + #address-cells = <1>; + #size-cells = <1>; + + cpus { + #address-cells = <1>; + #size-cells = <0>; + + cpu@0 { + device_type = "cpu"; + compatible = "arm,cortex-a7"; + reg = <0>; + clocks = <&sysctrl R9A06G032_CLK_A7MP>; + }; + + cpu@1 { + device_type = "cpu"; + compatible = "arm,cortex-a7"; + reg = <1>; + clocks = <&sysctrl R9A06G032_CLK_A7MP>; + enable-method = "renesas,r9a06g032-smp"; + cpu-release-addr = <0 0x4000c204>; + }; + }; + + ext_jtag_clk: extjtagclk { + #clock-cells = <0>; + compatible = "fixed-clock"; + clock-frequency = <0>; + }; + + ext_mclk: extmclk { + #clock-cells = <0>; + compatible = "fixed-clock"; + clock-frequency = <40000000>; + }; + + ext_rgmii_ref: extrgmiiref { + #clock-cells = <0>; + compatible = "fixed-clock"; + clock-frequency = <0>; + }; + + ext_rtc_clk: extrtcclk { + #clock-cells = <0>; + compatible = "fixed-clock"; + clock-frequency = <0>; + }; + + soc { + compatible = "simple-bus"; + #address-cells = <1>; + #size-cells = <1>; + interrupt-parent = <&gic>; + ranges; + + plat_regs: system-controller@4000c000 { + compatible = "syscon"; + reg = <0x4000c000 0x1000>; + u-boot,dm-pre-reloc; + }; + + sysctrl: clock { + compatible = "renesas,r9a06g032-sysctrl"; + #clock-cells = <1>; + regmap = <&plat_regs>; + u-boot,dm-pre-reloc; + + clocks = <&ext_mclk>, <&ext_rtc_clk>, + <&ext_jtag_clk>, <&ext_rgmii_ref>; + clock-names = "mclk", "rtc", "jtag", "rgmii_ref_ext"; + }; + + ddrctrl: memory-controller@4000d000 { + compatible = "cadence,ddr-ctrl"; + reg = <0x4000d000 0x1000>, <0x4000e000 0x100>; + reg-names = "ddrc", "phy"; + interrupts = <GIC_SPI 76 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&sysctrl R9A06G032_CLK_DDRC>, <&sysctrl R9A06G032_HCLK_DDRC>; + clock-names = "clk_ddrc", "hclk_ddrc"; + status = "disabled"; + }; + + uart0: serial@40060000 { + compatible = "renesas,r9a06g032-uart", "renesas,rzn1-uart", "snps,dw-apb-uart"; + reg = <0x40060000 0x400>; + interrupts = <GIC_SPI 6 IRQ_TYPE_LEVEL_HIGH>; + reg-shift = <2>; + reg-io-width = <4>; + clocks = <&sysctrl R9A06G032_CLK_UART0>, <&sysctrl R9A06G032_HCLK_UART0>; + clock-names = "baudclk", "apb_pclk"; + status = "disabled"; + }; + + uart1: serial@40061000 { + compatible = "renesas,r9a06g032-uart", "renesas,rzn1-uart", "snps,dw-apb-uart"; + reg = <0x40061000 0x400>; + interrupts = <GIC_SPI 7 IRQ_TYPE_LEVEL_HIGH>; + reg-shift = <2>; + reg-io-width = <4>; + clocks = <&sysctrl R9A06G032_CLK_UART1>, <&sysctrl R9A06G032_HCLK_UART1>; + clock-names = "baudclk", "apb_pclk"; + status = "disabled"; + }; + + uart2: serial@40062000 { + compatible = "renesas,r9a06g032-uart", "renesas,rzn1-uart", "snps,dw-apb-uart"; + reg = <0x40062000 0x400>; + interrupts = <GIC_SPI 8 IRQ_TYPE_LEVEL_HIGH>; + reg-shift = <2>; + reg-io-width = <4>; + clocks = <&sysctrl R9A06G032_CLK_UART2>, <&sysctrl R9A06G032_HCLK_UART2>; + clock-names = "baudclk", "apb_pclk"; + status = "disabled"; + }; + + uart3: serial@50000000 { + compatible = "renesas,r9a06g032-uart", "renesas,rzn1-uart"; + reg = <0x50000000 0x400>; + interrupts = <GIC_SPI 86 IRQ_TYPE_LEVEL_HIGH>; + reg-shift = <2>; + reg-io-width = <4>; + clocks = <&sysctrl R9A06G032_CLK_UART3>, <&sysctrl R9A06G032_HCLK_UART3>; + clock-names = "baudclk", "apb_pclk"; + status = "disabled"; + }; + + uart4: serial@50001000 { + compatible = "renesas,r9a06g032-uart", "renesas,rzn1-uart"; + reg = <0x50001000 0x400>; + interrupts = <GIC_SPI 87 IRQ_TYPE_LEVEL_HIGH>; + reg-shift = <2>; + reg-io-width = <4>; + clocks = <&sysctrl R9A06G032_CLK_UART4>, <&sysctrl R9A06G032_HCLK_UART4>; + clock-names = "baudclk", "apb_pclk"; + status = "disabled"; + }; + + uart5: serial@50002000 { + compatible = "renesas,r9a06g032-uart", "renesas,rzn1-uart"; + reg = <0x50002000 0x400>; + interrupts = <GIC_SPI 88 IRQ_TYPE_LEVEL_HIGH>; + reg-shift = <2>; + reg-io-width = <4>; + clocks = <&sysctrl R9A06G032_CLK_UART5>, <&sysctrl R9A06G032_HCLK_UART5>; + clock-names = "baudclk", "apb_pclk"; + status = "disabled"; + }; + + uart6: serial@50003000 { + compatible = "renesas,r9a06g032-uart", "renesas,rzn1-uart"; + reg = <0x50003000 0x400>; + interrupts = <GIC_SPI 89 IRQ_TYPE_LEVEL_HIGH>; + reg-shift = <2>; + reg-io-width = <4>; + clocks = <&sysctrl R9A06G032_CLK_UART6>, <&sysctrl R9A06G032_HCLK_UART6>; + clock-names = "baudclk", "apb_pclk"; + status = "disabled"; + }; + + uart7: serial@50004000 { + compatible = "renesas,r9a06g032-uart", "renesas,rzn1-uart"; + reg = <0x50004000 0x400>; + interrupts = <GIC_SPI 90 IRQ_TYPE_LEVEL_HIGH>; + reg-shift = <2>; + reg-io-width = <4>; + clocks = <&sysctrl R9A06G032_CLK_UART7>, <&sysctrl R9A06G032_HCLK_UART7>; + clock-names = "baudclk", "apb_pclk"; + status = "disabled"; + }; + + pinctrl: pinctrl@40067000 { + compatible = "renesas,r9a06g032-pinctrl", "renesas,rzn1-pinctrl"; + reg = <0x40067000 0x1000>, <0x51000000 0x480>; + clocks = <&sysctrl R9A06G032_HCLK_PINCONFIG>; + clock-names = "bus"; + status = "disabled"; + }; + + gic: interrupt-controller@44101000 { + compatible = "arm,gic-400", "arm,cortex-a7-gic"; + interrupt-controller; + #interrupt-cells = <3>; + reg = <0x44101000 0x1000>, /* Distributer */ + <0x44102000 0x2000>, /* CPU interface */ + <0x44104000 0x2000>, /* Virt interface control */ + <0x44106000 0x2000>; /* Virt CPU interface */ + interrupts = + <GIC_PPI 9 (GIC_CPU_MASK_SIMPLE(2) | IRQ_TYPE_LEVEL_HIGH)>; + }; + }; + + timer { + compatible = "arm,cortex-a7-timer", + "arm,armv7-timer"; + interrupt-parent = <&gic>; + arm,cpu-registers-not-fw-configured; + always-on; + interrupts = + <GIC_PPI 13 (GIC_CPU_MASK_SIMPLE(2) | IRQ_TYPE_LEVEL_LOW)>, + <GIC_PPI 14 (GIC_CPU_MASK_SIMPLE(2) | IRQ_TYPE_LEVEL_LOW)>, + <GIC_PPI 11 (GIC_CPU_MASK_SIMPLE(2) | IRQ_TYPE_LEVEL_LOW)>, + <GIC_PPI 10 (GIC_CPU_MASK_SIMPLE(2) | IRQ_TYPE_LEVEL_LOW)>; + }; + + reboot { + compatible = "syscon-reboot"; + regmap = <&plat_regs>; + offset = <0x198>; /* sysctrl.RSTEN */ + mask = <0x40>; /* bit 6 = SWRST_REQ */ + value = <0x40>; + }; +};
include/dt-bindings/clock/r9a06g032-sysctrl.h new file +148 -0
148 lines not on this page · raw message
Signature · 1 line
2.25.1
RFC PATCH 7/9 ARM: rzn1: basic support for Renesas RZ/N1 SoC
In reply to Ralph SiemsenThe RZ/N1 is a family of SoC devics from Renesas, featuring:
* ARM Cortex-A7 CPU (single/dual core) and/or Cortex-M3
* Integrated SRAM up to 6MB
* Integrated gigabit ethernet switch
* Optional DDR2/3 controller
* I2C, SPI, UART, NAND, QSPI, SDIO, USB, CAN, RTC, LCD
Add basic support in the form of ARCH_RZN1 symbol.
---
arch/arm/Kconfig | 17 +++++++++++++++++ arch/arm/Makefile | 1 + arch/arm/mach-rzn1/Kconfig | 18 ++++++++++++++++++ arch/arm/mach-rzn1/Makefile | 3 +++ arch/arm/mach-rzn1/cpu_info.c | 20 ++++++++++++++++++++ 5 files changed, 59 insertions(+) create mode 100644 arch/arm/mach-rzn1/Kconfig create mode 100644 arch/arm/mach-rzn1/Makefile create mode 100644 arch/arm/mach-rzn1/cpu_info.c
arch/arm/Kconfig +17 -0
@@ -1083,6 +1083,21 @@ config ARCH_RMOBILE imply SYS_THUMB_BUILD imply ARCH_MISC_INIT if DISPLAY_CPUINFO +config ARCH_RZN1 + bool "Reneasa RZ/N1 SoC" + select CLK + select CLK_RENESAS + select CLK_R9A06G032 + select DM + select DM_ETH + select DM_SERIAL + select PINCTRL + select PINCONF + select REGMAP + select SYSRESET + select SYSRESET_SYSCON + imply CMD_DM + config ARCH_SNAPDRAGON bool "Qualcomm Snapdragon SoCs" select ARM64
@@ -2243,6 +2258,8 @@ source "arch/arm/mach-owl/Kconfig" source "arch/arm/mach-rmobile/Kconfig" +source "arch/arm/mach-rzn1/Kconfig" + source "arch/arm/mach-meson/Kconfig" source "arch/arm/mach-mediatek/Kconfig"
arch/arm/Makefile +1 -0
@@ -76,6 +76,7 @@ machine-$(CONFIG_ARCH_ORION5X) += orion5x machine-$(CONFIG_ARCH_OWL) += owl machine-$(CONFIG_ARCH_RMOBILE) += rmobile machine-$(CONFIG_ARCH_ROCKCHIP) += rockchip +machine-$(CONFIG_ARCH_RZN1) += rzn1 machine-$(CONFIG_ARCH_S5PC1XX) += s5pc1xx machine-$(CONFIG_ARCH_SNAPDRAGON) += snapdragon machine-$(CONFIG_ARCH_SOCFPGA) += socfpga
arch/arm/mach-rzn1/Kconfig new file +18 -0
@@ -0,0 +1,18 @@ +if ARCH_RZN1 + +choice + prompt "Target Renesas RZ/N1 SoC select" + default RZN1 + +config RZN1 + bool "Renesas ARM SoCs RZ/N1 (32bit)" + select CPU_V7A + select ARMV7_SET_CORTEX_SMPEN if !SPL + select SPL_ARMV7_SET_CORTEX_SMPEN if SPL + +endchoice + +config SYS_SOC + default "rzn1" + +endif
arch/arm/mach-rzn1/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0+ + +obj-y = cpu_info.o
arch/arm/mach-rzn1/cpu_info.c new file +20 -0
@@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include <common.h> +#include <cpu_func.h> + +#if !CONFIG_IS_ENABLED (SYS_DCACHE_OFF ) +void enable_caches (void ) +{ +/* FIXME: when enabled, boot hangs at relocate_code */ +//dcache_enable(); +} +#endif + +#ifdef CONFIG_DISPLAY_CPUINFO +int print_cpuinfo (void ) +{ +printf ("CPU: Renesas Electronics RZ/N1\n" ); +return 0 ; +} +#endif
Signature · 1 line
2.25.1
RFC PATCH 8/9 board: schneider: add LCES board support
In reply to Ralph SiemsenAdd support for Schneider Electronics LCES1 / LCES2 boards, which are based on the Reneasas RZ/N1 SoC devices.
The intention is to support both boards using a single defconfig, and to handle the differences at runtime.
---
TODO: remove the debug UART settings from lces_defconfig.
arch/arm/dts/r9a06g032-rzn1d400-lces.dts | 50 +++ arch/arm/mach-rzn1/Kconfig | 14 + board/schneider/lces/Kconfig | 12 + board/schneider/lces/Makefile | 3 + board/schneider/lces/ddr_timing.c | 140 ++++++ .../lces/jedec_ddr3_2g_x16_1333h_500_cl8.h | 399 ++++++++++++++++++ board/schneider/lces/lces.c | 41 ++ configs/lces_defconfig | 26 ++ include/configs/lces.h | 22 + 9 files changed, 707 insertions(+) create mode 100644 arch/arm/dts/r9a06g032-rzn1d400-lces.dts create mode 100644 board/schneider/lces/Kconfig create mode 100644 board/schneider/lces/Makefile create mode 100644 board/schneider/lces/ddr_timing.c create mode 100644 board/schneider/lces/jedec_ddr3_2g_x16_1333h_500_cl8.h create mode 100644 board/schneider/lces/lces.c create mode 100644 configs/lces_defconfig create mode 100644 include/configs/lces.h
arch/arm/dts/r9a06g032-rzn1d400-lces.dts new file +50 -0
@@ -0,0 +1,50 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Device Tree Source for Schneider LCES Board + * + * Based on r9a06g032-rzn1d400-db.dts + */ + +/dts-v1/; + +#include "r9a06g032.dtsi" +#include <dt-bindings/pinctrl/rzn1-pinctrl.h> + +/ { + model = "Schneider LCES Board"; + compatible = "schneider,rzn1d400-lces", "renesas,r9a06g032"; + + chosen { + stdout-path = "serial0:115200n8"; + }; + + aliases { + serial0 = &uart0; + }; + + /* TODO: (RFS) only RZN1D has DDR */ + memory { + device_type = "memory"; + reg = <0x80000000 0x10000000>; + }; +}; + +&ddrctrl { + status = "okay"; +}; +&pinctrl { + status = "okay"; + + pins_uart0: pins_uart0 { + pinmux = < + RZN1_PINMUX(103, RZN1_FUNC_UART0_I) /* UART0_TXD */ + RZN1_PINMUX(104, RZN1_FUNC_UART0_I) /* UART0_RXD */ + >; + bias-disable; + }; +}; +&uart0 { + pinctrl-0 = <&pins_uart0>; + pinctrl-names = "default"; + status = "okay"; +};
arch/arm/mach-rzn1/Kconfig +14 -0
@@ -15,4 +15,18 @@ endchoice config SYS_SOC default "rzn1" +choice + prompt "Board select" + default TARGET_SCHNEIDER_LCES + +config TARGET_SCHNEIDER_LCES + bool "Schneider LCES board" + help + Support the Schneider LCES1 and LCES2 boards, which are based + on the Renesas RZ/N1 SoC. + +endchoice + +source "board/schneider/lces/Kconfig" + endif
board/schneider/lces/Kconfig new file +12 -0
@@ -0,0 +1,12 @@ +if TARGET_SCHNEIDER_LCES + +config SYS_BOARD + default "lces" + +config SYS_VENDOR + default "schneider" + +config SYS_CONFIG_NAME + default "lces" + +endif
board/schneider/lces/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0+ + +obj-y := lces.o ddr_timing.o
board/schneider/lces/ddr_timing.c new file +140 -0
140 lines not on this page · raw message
board/schneider/lces/jedec_ddr3_2g_x16_1333h_500_cl8.h new file +399 -0
399 lines not on this page · raw message
board/schneider/lces/lces.c new file +41 -0
41 lines not on this page · raw message
configs/lces_defconfig new file +26 -0
@@ -0,0 +1,26 @@ +CONFIG_ARM=y +CONFIG_SYS_ARCH_TIMER=y +CONFIG_SYS_THUMB_BUILD=y +CONFIG_ARCH_RZN1=y +CONFIG_SYS_TEXT_BASE=0x20040000 +CONFIG_SYS_MALLOC_LEN=0xb0000 +CONFIG_SYS_MALLOC_F_LEN=0x800 +CONFIG_NR_DRAM_BANKS=1 +CONFIG_DEFAULT_DEVICE_TREE="r9a06g032-rzn1d400-lces" +CONFIG_DEBUG_UART_BASE=0x40060000 +CONFIG_DEBUG_UART_CLOCK=20000000 +CONFIG_SYS_LOAD_ADDR=0x80008000 +CONFIG_DEBUG_UART=y +CONFIG_SYS_MEMTEST_START=0x80000000 +CONFIG_SYS_MEMTEST_END=0x8fffffff +CONFIG_CMD_MEMTEST=y +CONFIG_SYS_ALT_MEMTEST=y +# CONFIG_SYS_ALT_MEMTEST_BITFLIP is not set +CONFIG_CMD_CLK=y +CONFIG_OF_CONTROL=y +CONFIG_RAM=y +CONFIG_CADENCE_DDR_CTRL=y +CONFIG_DEBUG_UART_SHIFT=2 +CONFIG_DEBUG_UART_ANNOUNCE=y +CONFIG_SYS_NS16550=y +# CONFIG_EFI_LOADER is not set
include/configs/lces.h new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Configuration settings for the Schneider LCES board +*/ + +#ifndef __LCES_H +#define __LCES_H + +/* Internal RAM */ +#define CONFIG_SYS_INIT_RAM_ADDR 0x20000000 +#define CONFIG_SYS_INIT_RAM_SIZE (1 * 1024 * 1024) + +/* DDR */ +#define CONFIG_SYS_SDRAM_BASE 0x80000000 +#define CONFIG_SYS_SDRAM_SIZE (256 * 1024 * 1024) + +#define CONFIG_SYS_MONITOR_LEN (512 * 1024) + +/* Serial port is memory-mapped as 32-bit registers */ +#define CONFIG_SYS_NS16550_MEM32 + +#endif /* __LCES2_H */
Signature · 1 line
2.25.1
RFC PATCH 9/9 tools: Add tool to create Renesas SPKG images
In reply to Ralph SiemsenFrom: Michel Pollet <[email protected]>
Renesas RZ/N1 devices contain BootROM code that loads a custom SPKG image from QSPI, NAND or USB DFU. This tool converts a binary image into an SPKG.
SPKGs can optionally be signed, however this tool does not currently support signed SPKGs.
---
This tool could possibly be incorporated into mkimage / imagetools. However it is unclear how to handle the extra commandline parameters (NAND ECC settings, etc). So for now it is stand-alone tool.
tools/Makefile | 2 + tools/spkg_header.h | 49 +++++++ tools/spkg_utility.c | 306 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 357 insertions(+) create mode 100644 tools/spkg_header.h create mode 100644 tools/spkg_utility.c
tools/Makefile +2 -0
@@ -68,6 +68,8 @@ HOSTCFLAGS_img2srec.o := -pedantic hostprogs-$(CONFIG_XWAY_SWAP_BYTES) += xway-swap-bytes HOSTCFLAGS_xway-swap-bytes.o := -pedantic +hostprogs-$(CONFIG_ARCH_RZN1) += spkg_utility + hostprogs-y += mkenvimage mkenvimage-objs := mkenvimage.o os_support.o lib/crc32.o
tools/spkg_header.h new file +49 -0
49 lines not on this page · raw message
tools/spkg_utility.c new file +306 -0
306 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [RFC PATCH v1 9/9] tools: Add tool to create Renesas SPKG images
Quoted 9 lines · On Tuesday 09 August 2022 08:59:59 Ralph Siemsen wrote:
From: Michel Pollet <[email protected]>
Renesas RZ/N1 devices contain BootROM code that loads a custom SPKG image from QSPI, NAND or USB DFU. This tool converts a binary image into an SPKG.
SPKGs can optionally be signed, however this tool does not currently support signed SPKGs.
Quoted 6 lines
Signed-off-by Michel Pollet <[email protected]>Signed-off-by Ralph Siemsen <[email protected]>---
This tool could possibly be incorporated into mkimage / imagetools. However it is unclear how to handle the extra commandline parameters (NAND ECC settings, etc). So for now it is stand-alone tool.
Hello! You can use for example config file, like it has kwbimage.c which is integrated into mkimage and has support for NAND ECC settings.
It is really better if BootROM specific image format is included in standard mkimage and dumpimage tools instead of new custom vendor tools.
Re: [RFC PATCH v1 9/9] tools: Add tool to create Renesas SPKG images
Quoted 17 lines · On Tuesday 09 August 2022 15:03:48 Pali Rohár wrote:
Quoted 9 lines · On Tuesday 09 August 2022 08:59:59 Ralph Siemsen wrote:
From: Michel Pollet <[email protected]>
Renesas RZ/N1 devices contain BootROM code that loads a custom SPKG image from QSPI, NAND or USB DFU. This tool converts a binary image into an SPKG.
SPKGs can optionally be signed, however this tool does not currently support signed SPKGs.
Quoted 6 lines
Signed-off-by Michel Pollet <[email protected]>Signed-off-by Ralph Siemsen <[email protected]>---
This tool could possibly be incorporated into mkimage / imagetools. However it is unclear how to handle the extra commandline parameters (NAND ECC settings, etc). So for now it is stand-alone tool.
Quoted 2 lines
Hello! You can use for example config file, like it has
kwbimage.cwhich is integrated into mkimage and has support for NAND ECC settings.
Or another option could be to extend mkimage tool to accept new argument for specifying NAND settings. As we can see more image formats have support for it, so some abstraction in mkimage makes sense here.
Quoted 2 lines
It is really better if BootROM specific image format is included in standard mkimage and dumpimage tools instead of new custom vendor tools.
Re: [RFC PATCH v1 9/9] tools: Add tool to create Renesas SPKG images
Hi Pali,
Quoted 3 lines · On Tuesday 09 August 2022 15:03:48 Pali Rohár wrote:
Hello! You can use for example config file, like it has
kwbimage.cwhich is integrated into mkimage and has support for NAND ECC settings.
Thank you, I was unaware of this config file approach. From a quick look at doc/README.kwbimage it seems quite reasonable for device-specific parameters.
Quoted 4 lines · Pali Rohár
Or another option could be to extend mkimage tool to accept new argument for specifying NAND settings. As we can see more image formats have support for it, so some abstraction in mkimage makes sense here.
In principle I agree. But practically speaking I see two problems:
1) mkimage already has far too many options
2) covering all possible vendor-specific values/encodings of NAND parameters would be quite a task
So I am inclined to keep it simple for now, and try using a config file.
Ralph
Re: [RFC PATCH v1 9/9] tools: Add tool to create Renesas SPKG images
Hello!
Quoted 10 lines · On Tuesday 09 August 2022 11:54:30 Ralph Siemsen wrote:
Hi Pali,
Quoted 3 lines · On Tuesday 09 August 2022 15:03:48 Pali Rohár wrote:
Hello! You can use for example config file, like it has
kwbimage.cwhich is integrated into mkimage and has support for NAND ECC settings.Thank you, I was unaware of this config file approach. From a quick look at doc/README.kwbimage it seems quite reasonable for device-specific parameters.
This documentation is not probably up-to-date. List of all kwbimage config options can be visible in kwbimage_generate_config() function.
Quoted 8 lines · Pali Rohár
Quoted 4 lines
Or another option could be to extend mkimage tool to accept new argument for specifying NAND settings. As we can see more image formats have support for it, so some abstraction in mkimage makes sense here.
In principle I agree. But practically speaking I see two problems:
1) mkimage already has far too many options
I know. But for nand there can be just --nand suboption1,suboption2,... format. For other non-nand vendor specific option it would be an issue. Maybe something like --vendor option or --image-options ... could be used?
Quoted 2 lines
2) covering all possible vendor-specific values/encodings of NAND parameters would be quite a task
Yea, it is problematic. But... is not everything related to NAND just common to what can be specified in device tree properties for nand node? And de-facto already known and well-defined?
Because I cannot imagine what else for what there is not already device tree binding, could be required for vendor bootrom. (But maybe I just do not see it...)
Quoted 3 lines
So I am inclined to keep it simple for now, and try using a config file.
Ralph
Keep it simple is the best option!
In the worst case, in the future, some of the options introduced by your config file format, would be possible to specify also via command line arguments. So I do not see any issue with this config file approach.
Just one suggestion: It is a good idea to also implement "verify_header" mkimage callback. Build process then use it to verify that generated image is really correct.
Re: [RFC PATCH v1 9/9] tools: Add tool to create Renesas SPKG images
Quoted 3 lines · Pali Rohár
This documentation is not probably up-to-date. List of all kwbimage config options can be visible in
kwbimage_generate_config()function.
I will check the code as well.
Quoted 6 lines
Quoted 1 line
1) mkimage already has far too many options
I know. But for nand there can be just --nand suboption1,suboption2,... format. For other non-nand vendor specific option it would be an issue. Maybe something like --vendor option or --image-options ... could be used?
In my case this would work, as there are only 3 parameters for NAND. However in general, it could get pretty messy, I see at least ten different NAND parameters described in the NAND DT binding.
Quoted 6 lines
Quoted 2 lines
2) covering all possible vendor-specific values/encodings of NAND parameters would be quite a task
Yea, it is problematic. But... is not everything related to NAND just common to what can be specified in device tree properties for nand node? And de-facto already known and well-defined?
I did have the thought of using device tree. It does have the advantage that it is a known format with defined parameters.
Quoted 3 lines
Because I cannot imagine what else for what there is not already device tree binding, could be required for vendor bootrom. (But maybe I just do not see it...)
In quite a few cases, the DT parameters are incomplete, or just hints (see "nand-ecc-maximize"), that trigger various run-time decisions about the actual parameters.
Duplicating this logic in mkimage seems difficult, bordering on impossible if it depends on run-time identification of the flash chip, for example.
Quoted 3 lines
Just one suggestion: It is a good idea to also implement "
verify_header" mkimage callback. Build process then use it to verify that generated image is really correct.
I'll check it out, thanks!
Ralph
Re: [RFC PATCH v1 9/9] tools: Add tool to create Renesas SPKG images
In reply to Ralph SiemsenHi Ralph,
Quoted 17 lines · Ralph Siemsen
Hi Pali,
Quoted 3 lines · On Tuesday 09 August 2022 15:03:48 Pali Rohár wrote:
Hello! You can use for example config file, like it has
kwbimage.cwhich is integrated into mkimage and has support for NAND ECC settings.Thank you, I was unaware of this config file approach. From a quick look at doc/README.kwbimage it seems quite reasonable for device-specific parameters.
Quoted 4 lines · Pali Rohár
Or another option could be to extend mkimage tool to accept new argument for specifying NAND settings. As we can see more image formats have support for it, so some abstraction in mkimage makes sense here.
Quoted 6 lines
In principle I agree. But practically speaking I see two problems:
1) mkimage already has far too many options
2) covering all possible vendor-specific values/encodings of NAND parameters would be quite a taskSo I am inclined to keep it simple for now, and try using a config file.
The traditional way to handle this is to specify a config file with -n. See e.g. mtk_image
--Sean
Re: [RFC PATCH v1 9/9] tools: Add tool to create Renesas SPKG images
Quoted 3 lines · Sean Anderson
The traditional way to handle this is to specify a config file with -n. See e.g.
mtk_image
Thanks Pali and Sean. I have converted this tool to work as part of mkimage, with a config file for the extra parameters. Patch v2 to follow.
Ralph
RFC PATCH v2 9/9 tools: spkgimage: add Renesas SPKG format
In reply to Ralph SiemsenRenesas RZ/N1 devices contain BootROM code that loads a custom SPKG image from QSPI, NAND or USB DFU. Support this format in mkimage tool.
SPKGs can optionally be signed, however creation of signed SPKG is not currently supported.
Example of how to use it:
tools/mkimage -n board/schneider/lces/spkgimage.cfg \ -T spkgimage -a 0x20040000 -e 0x20040000 \ -d u-boot.bin u-boot.bin.spkg
The config file (spkgimage.cfg in this example) contains additional parameters such as NAND ECC settings.
---
Changes in v2:
- rewrote the stand-alone spkg_utility to integrate into mkimage
board/schneider/lces/spkgimage.cfg | 26 +++ boot/image.c | 1 + include/image.h | 1 + tools/Makefile | 1 + tools/spkgimage.c | 303 +++++++++++++++++++++++++++++ tools/spkgimage.h | 39 ++++ 6 files changed, 371 insertions(+) create mode 100644 board/schneider/lces/spkgimage.cfg create mode 100644 tools/spkgimage.c create mode 100644 tools/spkgimage.h
board/schneider/lces/spkgimage.cfg new file +26 -0
@@ -0,0 +1,26 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# (C) Copyright 2022 Schneider Electric +# +# SPKG image header, for booting on RZ/N1 + +# b[35:32] SPKG version +VERSION 1 + +# b[42:41] ECC Block size: 0=256 bytes, 1=512 bytes, 2=1024 bytes +NAND_ECC_BLOCK_SIZE 1 + +# b[45] NAND enable (boolean) +NAND_ECC_ENABLE 1 + +# b[50:48] ECC Scheme: 0=BCH2 1=BCH4 2=BCH8 3=BCH16 4=BCH24 5=BCH32 +NAND_ECC_SCHEME 3 + +# b[63:56] ECC bytes per block +NAND_BYTES_PER_ECC_BLOCK 28 + +# Provide dummy BLp header (boolean) +ADD_DUMMY_BLP 1 + +# Pad the image to a multiple of +PADDING 64K
boot/image.c +1 -0
@@ -179,6 +179,7 @@ static const table_entry_t uimage_type[] = { { IH_TYPE_COPRO, "copro", "Coprocessor Image"}, { IH_TYPE_SUNXI_EGON, "sunxi_egon", "Allwinner eGON Boot Image" }, { IH_TYPE_SUNXI_TOC0, "sunxi_toc0", "Allwinner TOC0 Boot Image" }, + { IH_TYPE_RENESAS_SPKG, "spkgimage", "Renesas SPKG Image" }, { -1, "", "", }, };
include/image.h +1 -0
@@ -229,6 +229,7 @@ enum {IH_TYPE_COPRO ,/* Coprocessor Image for remoteproc*/ IH_TYPE_SUNXI_EGON ,/* Allwinner eGON Boot Image */ IH_TYPE_SUNXI_TOC0 ,/* Allwinner TOC0 Boot Image */ +IH_TYPE_RENESAS_SPKG ,/* Renesas SPKG image */ IH_TYPE_COUNT, /* Number of image types */ };
tools/Makefile +1 -0
@@ -131,6 +131,7 @@ dumpimage-mkimage-objs := aisimage.o \ stm32image.o \ $(ROCKCHIP_OBS) \ socfpgaimage.o \ + spkgimage.o \ sunxi_egon.o \ lib/crc16-ccitt.o \ lib/hash-checksum.o \
tools/spkgimage.c new file +303 -0
303 lines not on this page · raw message
tools/spkgimage.h new file +39 -0
@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* +* Renesas RZ/N1 Package Table format +* (C) 2015-2016 Renesas Electronics Europe, LTD +* All rights reserved. +* +* Converted to mkimage plug-in +* (C) Copyright 2022 Schneider Electric +*/ + +#ifndef _SPKGIMAGE_H_ +#define _SPKGIMAGE_H_ + +#define SPKG_HEADER_SIGNATURE {'R', 'Z', 'N', '1'} +#define SPKG_HEADER_SIZE 24 +#define SPKG_HEADER_COUNT 8 +#define SPKG_BLP_SIZE 264 +#define SPKG_CRC_SIZE 4 + +/* SPKG header */ +struct spkg_hdr { +uint8_t signature[4 ]; +uint8_t version; +uint8_t ecc; +uint8_t ecc_scheme; +uint8_t ecc_bytes; +uint32_t payload_length;/* only HIGHER 24 bits */ +uint32_t load_address; +uint32_t execution_offset; +uint32_t crc;/* of this header */ +} __packed; + +struct spkg_file { +struct spkg_hdr header[SPKG_HEADER_COUNT ]; +uint8_t payload[0 ]; +/* then the CRC */ +} __packed; + +#endif
Signature · 1 line
2.25.1
Re: [RFC PATCH v2 9/9] tools: spkgimage: add Renesas SPKG format
Quoted 21 lines · Ralph Siemsen
Renesas RZ/N1 devices contain BootROM code that loads a custom SPKG image from QSPI, NAND or USB DFU. Support this format in mkimage tool.
SPKGs can optionally be signed, however creation of signed SPKG is not currently supported.
Example of how to use it:
tools/mkimage -n board/schneider/lces/spkgimage.cfg \ -T spkgimage -a 0x20040000 -e 0x20040000 \ -d u-boot.bin u-boot.bin.spkgThe config file (spkgimage.cfg in this example) contains additional parameters such as NAND ECC settings.
Signed-off-by Ralph Siemsen <[email protected]>---
Changes in v2:
- rewrote the stand-alonespkg_utilityto integrate into mkimage
Quoted 6 lines
board/schneider/lces/spkgimage.cfg | 26 +++ boot/image.c | 1 + include/image.h | 1 + tools/Makefile | 1 + tools/spkgimage.c | 303 +++++++++++++++++++++++++++++ tools/spkgimage.h | 39 ++++
Please document your format in doc/mkimage.1
Quoted 100 lines
6 files changed, 371 insertions(+)create mode 100644 board/schneider/lces/spkgimage.cfg create mode 100644
tools/spkgimage.c
create mode 100644tools/spkgimage.hboard/schneider/lces/spkgimage.cfg new file +26
-0@@ -0,0 +1,26 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# (C) Copyright 2022 Schneider Electric +# +# SPKG image header, for booting on RZ/N1 + +# b[35:32] SPKG version +VERSION 1 + +# b[42:41] ECC Block size: 0=256 bytes, 1=512 bytes, 2=1024 bytes +NAND_ECC_BLOCK_SIZE 1 + +# b[45] NAND enable (boolean) +NAND_ECC_ENABLE 1 + +# b[50:48] ECC Scheme: 0=BCH2 1=BCH4 2=BCH8 3=BCH16 4=BCH24 5=BCH32 +NAND_ECC_SCHEME 3 + +# b[63:56] ECC bytes per block +NAND_BYTES_PER_ECC_BLOCK 28 + +# Provide dummy BLp header (boolean) +ADD_DUMMY_BLP 1 + +# Pad the image to a multiple of +PADDING 64Kboot/image.c +1
-0@@ -179,6 +179,7 @@ static const table_entry_t uimage_type[] = { { IH_TYPE_COPRO, "copro", "Coprocessor Image"}, { IH_TYPE_SUNXI_EGON, "sunxi_egon", "Allwinner eGON Boot Image" }, { IH_TYPE_SUNXI_TOC0, "sunxi_toc0", "Allwinner TOC0 Boot Image" }, + { IH_TYPE_RENESAS_SPKG, "spkgimage", "Renesas SPKG Image" }, { -1, "", "", }, };include/image.h +1
-0@@ -229,6 +229,7 @@ enum {IH_TYPE_COPRO ,/* Coprocessor Image for remoteproc*/ IH_TYPE_SUNXI_EGON ,/* Allwinner eGON Boot Image */ IH_TYPE_SUNXI_TOC0 ,/* Allwinner TOC0 Boot Image */ +IH_TYPE_RENESAS_SPKG ,/* Renesas SPKG image */ IH_TYPE_COUNT, /* Number of image types */ };tools/Makefile +1
-0@@ -131,6 +131,7 @@ dumpimage-mkimage-objs := aisimage.o \ stm32image.o \ $(ROCKCHIP_OBS) \ socfpgaimage.o \ + spkgimage.o \ sunxi_egon.o \ lib/crc16-ccitt.o \ lib/hash-checksum.o \tools/spkgimage.c new file +21
-0@@ -0,0 +1,303 @@ +// SPDX-License-Identifier: BSD-2-Clause +/* +* Generate Renesas RZ/N1 BootROM header (SPKG) +* (C) Copyright 2022 Schneider Electric +* +* Based on spkg_utility.c +* (C) Copyright 2016 Renesas Electronics Europe Ltd +*/ + +#include "imagetool.h" +#include <limits.h> +#include <image.h> +#include <stdarg.h> +#include <stdint.h> +#include <u-boot/crc.h> +#include "spkgimage.h" + +static struct spkg_file out_buf; + +static uint32_t padding; +
tools/spkgimage.c line 31
Quoted 10 lines
tools/spkgimage.c new file +10
-0+/* Note: the ordering of the bitfields does not matter */ +static struct config_file { +unsigned int version:1 ; +unsigned int ecc_block_size:2 ; +unsigned int ecc_enable:1 ; +unsigned int ecc_scheme:3 ; +unsigned int ecc_bytes:8 ; +unsigned int blp_len; +unsigned int padding; +} conf;
I wonder if you could just fill in the header directly. This is for a userspace tool, and this struct will be created at most once. It's OK to use 10 bytes :)
tools/spkgimage.c line 44
Quoted 12 lines
tools/spkgimage.c new file +12
-0+static int spkgimage_parse_config_line (char *line) +{ +char *saveptr; +char *delim ="\t " ; +char *name =strtok_r (line, delim, &saveptr); +char *val_str =strtok_r (NULL , delim, &saveptr); +int value =atoi (val_str); + +if (!strcmp ("VERSION" , name)) { + conf.version = value; + }else if (!strcmp ("NAND_ECC_ENABLE" , name)) { + conf.ecc_enable = value;
Can you add some checks for the valid range of values? E.g. NAND_ECC_SCHEME should be 0 <= value <= 5
Quoted 8 lines
tools/spkgimage.c new file +8
-0+ }else if (!strcmp ("NAND_ECC_BLOCK_SIZE" , name)) { + conf.ecc_block_size = value; + }else if (!strcmp ("NAND_ECC_SCHEME" , name)) { + conf.ecc_scheme = value; + }else if (!strcmp ("NAND_BYTES_PER_ECC_BLOCK" , name)) { + conf.ecc_bytes = value; + }else if (!strcmp ("ADD_DUMMY_BLP" , name)) { + conf.blp_len = value ?SPKG_BLP_SIZE :0 ;
tools/spkgimage.c line 62
Quoted 10 lines
tools/spkgimage.c new file +10
-0+ }else if (!strcmp ("PADDING" , name)) { +if (strrchr (val_str,'K' )) + conf.padding = value *1024 ; +else if (strrchr (val_str,'M' )) + conf.padding = value *1024 *1024 ; +else + conf.padding = value; + }else { +fprintf (stderr,"Error: unknown keyword '%s' in config\n" , + name);
perhaps print the line number?
Quoted 25 lines
tools/spkgimage.c new file +25
-0+return -EINVAL ; + } + +return 0 ; +} + +static int spkgimage_parse_config_file (char *filename) +{ +FILE *fcfg; +char line[256 ]; +size_t len; + + fcfg =fopen (filename,"r" ); +if (!fcfg) +return -EINVAL ; + +while (fgets (line,sizeof (line), fcfg)) { +/* Skip blank lines and comments */ +if (line[0 ] =='\n' || line[0 ] =='#' ) +continue ; + +/* Strip the trailing newline */ + len =strlen (line); +if (line[len -1 ] =='\n' ) + line[--len] =0 ;
tools/spkgimage.c line 97
Quoted 10 lines
tools/spkgimage.c new file +10
-0+ +/* Parse the line */ +if (spkgimage_parse_config_line (line)) +return -EINVAL ; + } + +fclose (fcfg); + +/* Avoid divide-by-zero later on */ +if (conf.padding ==0 )
if (!conf.padding)
Quoted 21 lines
tools/spkgimage.c new file +21
-0+ conf.padding =1 ; + +return 0 ; +} + +static int spkgimage_check_params (struct image_tool_params *params) +{ +if (!params->addr) { +fprintf (stderr,"Error: Load Address must be set.\n" ); +return -EINVAL ; + } + +if (!params->imagename || !params->imagename[0 ]) { +fprintf (stderr,"Error: Image name must be set.\n" ); +return -EINVAL ; + } + +if (!params->datafile) { +fprintf (stderr,"Error: Data filename must be set.\n" ); +return -EINVAL ; + }
tools/spkgimage.c line 128
Quoted 10 lines
tools/spkgimage.c new file +10
-0+ +return 0 ; +} + +static int spkgimage_verify_header (unsigned char *ptr,int size, +struct image_tool_params *param) +{ +struct spkg_file *file = (struct spkg_file *)ptr; +struct spkg_hdr *header = (struct spkg_hdr *)ptr; +char signature[4 ] =SPKG_HEADER_SIGNATURE ;
If this naming does not come from documentation, I would suggest something like SPKG_HEADER_MAGIC, since this is not a signature, or even a CRC.
Quoted 130 lines
tools/spkgimage.c new file +130
-0+uint32_t payload_length; +uint32_t crc; +uint8_t *crc_buf; + +/* Check the signature */ +if (memcmp (header->signature, signature,4 )) { +fprintf (stderr,"Error: invalid signature bytes\n" ); +return -EINVAL ; + } + +/* Check the CRC */ + crc =crc32 (0 , ptr,SPKG_HEADER_SIZE -SPKG_CRC_SIZE ); +if (crc != header->crc) { +fprintf (stderr,"Error: invalid header CRC=\n" ); +return -EINVAL ; + } + +/* Check all copies of header are the same */ +for (int i =1 ; i <SPKG_HEADER_COUNT ; i++) { +if (memcmp (&header[0 ], &header[i],SPKG_HEADER_SIZE )) { +fprintf (stderr,"Error: header %d mismatch\n" , i); +return -EINVAL ; + } + } + +/* Check the payload CRC */ + payload_length =le32_to_cpu (header->payload_length) >>8 ; + crc_buf = file->payload + payload_length -SPKG_CRC_SIZE ; + crc =crc32 (0 , file->payload, payload_length -SPKG_CRC_SIZE ); +if (crc_buf[0 ] != (crc &0xff ) || + crc_buf[1 ] != (crc >>8 &0xff ) || + crc_buf[2 ] != (crc >>16 &0xff ) || + crc_buf[3 ] != (crc >>24 &0xff )) { +fprintf (stderr,"Error: invalid payload CRC\n" ); +return -EINVAL ; + } + +return 0 ; +} + +static void spkgimage_print_header (const void *ptr) +{ +const struct spkg_hdr *h = ptr; +uint32_t offset =le32_to_cpu (h->execution_offset); + +printf ("Image type\t: Renesas SPKG Image\n" ); +printf ("Marker\t\t: %c%c%c%c\n" , h->signature[0 ], h->signature[1 ], + h->signature[2 ], h->signature[3 ]); +printf ("Version\t\t: %d\n" , h->version); +printf ("ECC\t\t: " ); +if (h->ecc &0x20 ) +printf ("Scheme %d, Block size %d, Strength %d\n" , + h->ecc_scheme, (h->ecc >>1 ) &3 , h->ecc_bytes); +else +printf ("Not enabled\n" ); +printf ("Payload length\t: %d\n" ,le32_to_cpu (h->payload_length) >>8 ); +printf ("Load address\t: 0x%08x\n" ,le32_to_cpu (h->load_address)); +printf ("Execution offset: 0x%08x (%s mode)\n" , offset & ~1 , + offset &1 ?"THUMB" :"ARM" ); +printf ("Header checksum\t: 0x%08x\n" ,le32_to_cpu (h->crc)); +} + +static inline uint32_t roundup (uint32_t x,uint32_t y) +{ +return ((x + y -1 ) / y) * y; +} + +static int spkgimage_vrec_header (struct image_tool_params *params, +struct image_type_params *tparams) +{ +struct stat s; + +/* Parse the config file */ +if (spkgimage_parse_config_file (params->imagename)) { +fprintf (stderr,"Error parsing config file\n" ); +exit (EXIT_FAILURE ); + } + +/* Get size of input data file */ +if (stat (params->datafile, &s)) { +fprintf (stderr,"Could not stat data file: %s: %s\n" , + params->datafile,strerror (errno)); +exit (EXIT_FAILURE ); + } + params->orig_file_size = s.st_size; + +/* Determine size of resulting SPKG file */ +uint32_t header_len =SPKG_HEADER_SIZE *SPKG_HEADER_COUNT ; +uint32_t payload_len = conf.blp_len + s.st_size +SPKG_CRC_SIZE ; +uint32_t total_len = header_len + payload_len; + +/* Round up to next multiple of padding size */ +uint32_t padded_len =roundup (total_len, conf.padding); + +/* Number of padding bytes to add */ + padding = padded_len - total_len; + +/* Fixup payload_len to include padding bytes */ + payload_len += padding; + +/* Prepare the header */ +struct spkg_hdr header = { + .signature =SPKG_HEADER_SIGNATURE , + .version = conf.version, + .ecc = (conf.ecc_enable <<5 ) | (conf.ecc_block_size <<1 ), + .ecc_scheme = conf.ecc_scheme, + .ecc_bytes = conf.ecc_bytes, + .payload_length =cpu_to_le32 (payload_len <<8 ), + .load_address =cpu_to_le32 (params->addr), + .execution_offset =cpu_to_le32 (params->ep - params->addr), + }; + header.crc =crc32 (0 , (uint8_t *)&header, +sizeof (header) -SPKG_CRC_SIZE ); + +/* Fill the SPKG with the headers */ +for (int i =0 ; i <SPKG_HEADER_COUNT ; i++) +memcpy (&out_buf.header[i], &header,sizeof (header)); + +/* Extra bytes to allocate in the output file */ +return conf.blp_len + padding +4 ; +} + +static void spkgimage_set_header (void *ptr,struct stat *sbuf,int ifd, +struct image_tool_params *params) +{ +uint8_t *payload = ptr +SPKG_HEADER_SIZE *SPKG_HEADER_COUNT ; +uint8_t *file_end = payload + conf.blp_len + params->orig_file_size; +uint8_t *crc_buf = file_end + padding; +uint32_t crc; +
tools/spkgimage.c line 268
Quoted 10 lines
tools/spkgimage.c new file +10
-0+/* Make room for the Dummy BLp header */ +memmove (payload + conf.blp_len, payload, params->orig_file_size); + +/* Fill the SPKG with the Dummy BLp */ +memset (payload,0x88 , conf.blp_len); + +/* +* mkimage copy_file() pads the input file with zeros. +* Replace those zeros with flash friendly one bits. +* The original version skipped the fist 4 bytes,
nit: first
Quoted 6 lines
tools/spkgimage.c new file +6
-0+* probably an oversight, but for consistency we +* keep the same behaviour. +*/ +memset (file_end +4 ,0xff , padding -4 ); + +/* Add Payload CRC */
tools/spkgimage.c line 284
Quoted 10 lines
tools/spkgimage.c new file +10
-0+ crc =crc32 (0 , payload, crc_buf - payload); + crc_buf[0 ] = crc; + crc_buf[1 ] = crc >>8 ; + crc_buf[2 ] = crc >>16 ; + crc_buf[3 ] = crc >>24 ; +} + +static int spkgimage_check_image_types (uint8_t type) +{ +return type ==IH_TYPE_RENESAS_SPKG ?0 :1 ;
This function is not necessary if you only support one type.
Quoted 31 lines
tools/spkgimage.c new file +19
-0+} + +/* +* spkgimage type parameter definition +*/ +U_BOOT_IMAGE_TYPE ( + spkgimage, +"Renesas SPKG Image" , +sizeof (out_buf), + &out_buf, + spkgimage_check_params, + spkgimage_verify_header, + spkgimage_print_header, + spkgimage_set_header, +NULL , + spkgimage_check_image_types, +NULL , + spkgimage_vrec_header +);tools/spkgimage.h new file +6
-0@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* +* Renesas RZ/N1 Package Table format +* (C) 2015-2016 Renesas Electronics Europe, LTD +* All rights reserved. +*
tools/spkgimage.h line 16
Quoted 10 lines
tools/spkgimage.h new file +10
-0+* Converted to mkimage plug-in +* (C) Copyright 2022 Schneider Electric +*/ + +#ifndef _SPKGIMAGE_H_ +#define _SPKGIMAGE_H_ + +#define SPKG_HEADER_SIGNATURE {'R', 'Z', 'N', '1'} +#define SPKG_HEADER_SIZE 24 +#define SPKG_HEADER_COUNT 8
What are the other 7 headers for? Should you print them out above?
Quoted 14 lines
tools/spkgimage.h new file +13
-0+#define SPKG_BLP_SIZE 264 +#define SPKG_CRC_SIZE 4 + +/* SPKG header */ +struct spkg_hdr { +uint8_t signature[4 ]; +uint8_t version; +uint8_t ecc; +uint8_t ecc_scheme; +uint8_t ecc_bytes; +uint32_t payload_length;/* only HIGHER 24 bits */ +uint32_t load_address; +uint32_t execution_offset;
tools/spkgimage.h line 39
Quoted 10 lines
tools/spkgimage.h new file +10
-0+ uint32_t crc; /* of this header */ +} __packed; + +struct spkg_file { +struct spkg_hdr header[SPKG_HEADER_COUNT ]; +uint8_t payload[0 ]; +/* then the CRC */ +} __packed; + +#endif
--Sean
Re: [RFC PATCH v2 9/9] tools: spkgimage: add Renesas SPKG format
Quoted 9 lines · Sean Anderson
Quoted 7 lines
board/schneider/lces/spkgimage.cfg | 26 +++ boot/image.c | 1 + include/image.h | 1 + tools/Makefile | 1 + tools/spkgimage.c | 303 +++++++++++++++++++++++++++++ tools/spkgimage.h | 39 ++++Please document your format in doc/mkimage.1
Okay, will be added in the next version.
Quoted 6 lines
Quoted 6 lines
tools/spkgimage.c new file +6
-0+/* Note: the ordering of the bitfields does not matter */ +static struct config_file { + unsigned int version:1; + unsigned int ecc_block_size:2; + unsigned int ecc_enable:1; + unsigned int ecc_scheme:3;
Quoted 8 lines
tools/spkgimage.c line 31
Quoted 4 lines
tools/spkgimage.c new file +4
-0+ unsigned int ecc_bytes:8; +unsigned int blp_len; +unsigned int padding; +} conf;I wonder if you could just fill in the header directly. This is for a userspace tool, and this struct will be created at most once. It's OK to use 10 bytes :)
I could fill the header directly, but I figured it would be cleaner to keep the config file parsing separate from header generation.
As for the use of bitfields, this was not really about saving space, but rather a cheap way to ensure the values from the config file do not exceed their allocated bit-width in the header. The previous stand-alone code has a somewhat similar construct, from which I pinched the idea.
Quoted 16 lines
tools/spkgimage.c line 44
Quoted 13 lines
tools/spkgimage.c new file +12
-0+static int spkgimage_parse_config_line (char *line) +{ +char *saveptr; +char *delim ="\t " ; +char *name =strtok_r (line, delim, &saveptr); +char *val_str =strtok_r (NULL , delim, &saveptr); +int value =atoi (val_str); + +if (!strcmp ("VERSION" , name)) { + conf.version = value; + }else if (!strcmp ("NAND_ECC_ENABLE" , name)) { + conf.ecc_enable = value;Can you add some checks for the valid range of values? E.g.
NAND_ECC_SCHEMEshould be 0 <= value <= 5
Yes, will add some range checks where they make sense. Probably with a helper function.
Quoted 19 lines
Quoted 8 lines
tools/spkgimage.c new file +8
-0+ }else if (!strcmp ("NAND_ECC_BLOCK_SIZE" , name)) { + conf.ecc_block_size = value; + }else if (!strcmp ("NAND_ECC_SCHEME" , name)) { + conf.ecc_scheme = value; + }else if (!strcmp ("NAND_BYTES_PER_ECC_BLOCK" , name)) { + conf.ecc_bytes = value; + }else if (!strcmp ("ADD_DUMMY_BLP" , name)) { + conf.blp_len = value ?SPKG_BLP_SIZE :0 ;tools/spkgimage.c line 62
Quoted 10 lines
tools/spkgimage.c new file +10
-0+ }else if (!strcmp ("PADDING" , name)) { +if (strrchr (val_str,'K' )) + conf.padding = value *1024 ; +else if (strrchr (val_str,'M' )) + conf.padding = value *1024 *1024 ; +else + conf.padding = value; + }else { +fprintf (stderr,"Error: unknown keyword '%s' in config\n" , + name);
Quoted 1 line
perhaps print the line number?
Good idea, will do.
Quoted 4 lines
tools/spkgimage.c line 97
Quoted 2 lines
tools/spkgimage.c new file +2
-0+/* Avoid divide-by-zero later on */ +if (conf.padding ==0 )if (!conf.padding)
Will do.
Quoted 10 lines
tools/spkgimage.c line 128
Quoted 6 lines
tools/spkgimage.c new file +6
-0+static int spkgimage_verify_header (unsigned char *ptr,int size, +struct image_tool_params *param) +{ +struct spkg_file *file = (struct spkg_file *)ptr; +struct spkg_hdr *header = (struct spkg_hdr *)ptr; +char signature[4 ] =SPKG_HEADER_SIGNATURE ;If this naming does not come from documentation, I would suggest something like
SPKG_HEADER_MAGIC, since this is not a signature, or even a CRC.
The name does in fact come from the RZ/N1 documentation. However I agree that SPKG_HEADER_MAGIC would better reflect what these bytes actually are.
Quoted 6 lines
tools/spkgimage.c line 268
Quoted 4 lines
tools/spkgimage.c new file +4
-0+/* +* mkimage copy_file() pads the input file with zeros. +* Replace those zeros with flash friendly one bits. +* The original version skipped the fist 4 bytes, nit: first
Well spotted, thanks.
Quoted 5 lines
tools/spkgimage.c line 284
Quoted 3 lines
tools/spkgimage.c new file +3
-0+static int spkgimage_check_image_types (uint8_t type) +{ +return type ==IH_TYPE_RENESAS_SPKG ?0 :1 ;This function is not necessary if you only support one type.
Without this function, mkimage kept telling me that my format (spkgimage) was not supported, and none of my callbacks got invoked. It only complained when trying to generate a header. When listing the supported formats, spkgimage showed up correctly.
I'll take another look on Monday, maybe I missed something obvious.
Quoted 5 lines
tools/spkgimage.h line 16
Quoted 3 lines
tools/spkgimage.h new file +3
-0+#define SPKG_HEADER_SIGNATURE {'R', 'Z', 'N', '1'} +#define SPKG_HEADER_SIZE 24 +#define SPKG_HEADER_COUNT 8What are the other 7 headers for? Should you print them out above?
There are 8 identical copies of the 24-byte header. This is meant to help with NAND booting, where the header is read before ECC settings are known. The BootROM validates the header CRC and will try up to 8 headers before giving up.
Since they are identical, I only printed values from one header. However in the validation function, I do check that all eight copies match.
Thanks for your feedback!
-Ralph
Re: [RFC PATCH v2 9/9] tools: spkgimage: add Renesas SPKG format
Hi Sean,
I've implemented most of the suggestions. I will post an updated series, since it seems that sending v2 of just one patch has confused patchwork.
However so as not to entirely remove confusion, the updated series will be v3, since I already used v2 for the one patch. :-P
Quoted 7 lines · Ralph Siemsen
Quoted 4 lines
I wonder if you could just fill in the header directly. This is for a userspace tool, and this struct will be created at most once. It's OK to use 10 bytes :)
I could fill the header directly, but I figured it would be cleaner to keep the config file parsing separate from header generation.
Does it seem reasonable to keep these structures separated?
Quoted 11 lines
Quoted 10 lines
tools/spkgimage.c line 128
Quoted 6 lines
tools/spkgimage.c new file +6
-0+static int spkgimage_verify_header (unsigned char *ptr,int size, +struct image_tool_params *param) +{ +struct spkg_file *file = (struct spkg_file *)ptr; +struct spkg_hdr *header = (struct spkg_hdr *)ptr; +char signature[4 ] =SPKG_HEADER_SIGNATURE ;If this naming does not come from documentation, I would suggest something like
SPKG_HEADER_MAGIC, since this is not a signature, or even a CRC.
Quoted 3 lines
The name does in fact come from the RZ/N1 documentation. However I agree that
SPKG_HEADER_MAGICwould better reflect what these bytes actually are.
Upon checking the documentation, it turns out they use the term "marker" rather than "signature" for these bytes. So I have switched the code to match.
Quoted 6 lines
Quoted 5 lines
tools/spkgimage.c line 284
Quoted 3 lines
tools/spkgimage.c new file +3
-0+static int spkgimage_check_image_types (uint8_t type) +{ +return type ==IH_TYPE_RENESAS_SPKG ?0 :1 ;This function is not necessary if you only support one type.
Quoted 6 lines
Without this function, mkimage kept telling me that my format (spkgimage) was not supported, and none of my callbacks got invoked. It only complained when trying to generate a header. When listing the supported formats, spkgimage showed up correctly.
I'll take another look on Monday, maybe I missed something obvious.
I have re-checked this:
- without the function, mkimage complains that spkgimage is unknown
- with a function that unconditionally returns 0, it works fine
If it really is meant to work without the function, then a bug must have crept in elsewhere...
Regards,
-Ralph
Re: [RFC PATCH v2 9/9] tools: spkgimage: add Renesas SPKG format
Quoted 11 lines · Ralph Siemsen
Hi Sean,
I've implemented most of the suggestions. I will post an updated series, since it seems that sending v2 of just one patch has confused patchwork.
However so as not to entirely remove confusion, the updated series will be v3, since I already used v2 for the one patch. :-P
Quoted 1 line · Ralph Siemsen
Quoted 1 line
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
I wonder if you could just fill in the header directly. This is for a userspace tool, and this struct will be created at most once. It's OK to use 10 bytes :)
I could fill the header directly, but I figured it would be cleaner to keep the config file parsing separate from header generation.
Does it seem reasonable to keep these structures separated?
Yes, that is fine.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
tools/spkgimage.c line 128
Quoted 6 lines
tools/spkgimage.c new file +6
-0+static int spkgimage_verify_header (unsigned char *ptr,int size, +struct image_tool_params *param) +{ +struct spkg_file *file = (struct spkg_file *)ptr; +struct spkg_hdr *header = (struct spkg_hdr *)ptr; +char signature[4 ] =SPKG_HEADER_SIGNATURE ;If this naming does not come from documentation, I would suggest something like
SPKG_HEADER_MAGIC, since this is not a signature, or even a CRC.
Quoted 7 lines
Quoted 3 lines
The name does in fact come from the RZ/N1 documentation. However I agree that
SPKG_HEADER_MAGICwould better reflect what these bytes actually are.Upon checking the documentation, it turns out they use the term "marker" rather than "signature" for these bytes. So I have switched the code to match.
That sounds good.
Quoted 11 lines
Quoted 11 lines
Quoted 5 lines
tools/spkgimage.c line 284
Quoted 3 lines
tools/spkgimage.c new file +3
-0+static int spkgimage_check_image_types (uint8_t type) +{ +return type ==IH_TYPE_RENESAS_SPKG ?0 :1 ;This function is not necessary if you only support one type.
Without this function, mkimage kept telling me that my format (spkgimage) was not supported, and none of my callbacks got invoked. It only complained when trying to generate a header. When listing the supported formats, spkgimage showed up correctly.
Quoted 8 lines
Quoted 1 line
I'll take another look on Monday, maybe I missed something obvious.
I have re-checked this:
- without the function, mkimage complains that spkgimage is unknown
- with a function that unconditionally returns 0, it works fineIf it really is meant to work without the function, then a bug must have crept in elsewhere...
Huh. I did a quick grep so maybe I missed something. IMO this *should* work without a function, because we have tons of drivers which just have an equality check. In any case, you can just do
return type == IH_TYPE_RENESAS_SPKG ? 0 : -EINVAL;
--Sean
Re: [RFC PATCH v2 9/9] tools: spkgimage: add Renesas SPKG format
Quoted 17 lines · Sean Anderson
Quoted 17 lines
Quoted 6 lines
Quoted 5 lines
tools/spkgimage.c line 284
Quoted 3 lines
tools/spkgimage.c new file +3
-0+static int spkgimage_check_image_types (uint8_t type) +{ +return type ==IH_TYPE_RENESAS_SPKG ?0 :1 ;This function is not necessary if you only support one type.
Quoted 6 lines
Without this function, mkimage kept telling me that my format (spkgimage) was not supported, and none of my callbacks got invoked. It only complained when trying to generate a header. When listing the supported formats, spkgimage showed up correctly.
I'll take another look on Monday, maybe I missed something obvious.
I have re-checked this:
- without the function, mkimage complains that spkgimage is unknown
- with a function that unconditionally returns 0, it works fine
Quoted 8 lines
Quoted 2 lines
If it really is meant to work without the function, then a bug must have crept in elsewhere...
Huh. I did a quick grep so maybe I missed something. IMO this *should* work without a function, because we have tons of drivers which just have an equality check. In any case, you can just do
return type ==
IH_TYPE_RENESAS_SPKG? 0 :-EINVAL;
It works fine when I use the following for the function:
static int spkgimage_check_image_types(uint8_t type)
{
return 0;
}However if no function is provided, i.e. U_BOOT_IMAGE_TYPE has NULL for check_image_type field, then mkimage fails with the error:
tools/mkimage: unsupported type Renesas SPKG Image
Looking at this a bit more, it seems to be due to:
struct image_type_params *imagetool_get_type(int type)
{
...snip...
for (curr = start; curr != end; curr++) {
if ((*curr)->check_image_type) {
if (!(*curr)->check_image_type(type))
return *curr;
}
}
return NULL;
}So the only way to get non-NULL from imagetool_get_type is for there to be a callback function, and it must return zero. And this in turn causes mkimage to bail out quite early in main():
/* set tparams as per input type_id */
tparams = imagetool_get_type(params.type);
if (tparams == NULL && !params.lflag) {
fprintf (stderr, "%s: unsupported type %s\n",
params.cmdname, genimg_get_type_name(params.type));
exit (EXIT_FAILURE);
}Unless I am missing something, it seems I must provide a function.
-Ralph
PS I will post an updated series (v3) eventually. I'm working on making changes to the clock driver on the kernel side, to keep it in sync with the changes you requested in the u-boot side.