diff mbox series

[1/5] sunxi: move non-essential code out of s_init()

Message ID 20220125011517.7773-2-andre.przywara@arm.com
State Superseded
Delegated to: Andre Przywara
Headers show
Series sunxi: remove lowlevel_init | expand

Commit Message

Andre Przywara Jan. 25, 2022, 1:15 a.m. UTC
So far all Allwinner based boards were doing some not-so-lowlevel-setup
in lowlevel's s_init() routine.
This includes the initial clock, timer and pinmux setup, among other
things. This is clearly out of the "absolute bare minimum to get started"
scope that lowlevel_init.S suggests for this function.

Since we have an SPL, which is called right after s_init(), move those
calls to our board_init_f() function. As we overwrite this only for
the SPL, this has the added benefit of not doing this setup *again*
shortly afterwards, when running U-Boot proper.

This makes gpio_init() to be called from the SPL only, so pull this code
into a CONFIG_SPL_BUILD protected part to avoid build warnings.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
 arch/arm/mach-sunxi/board.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

Comments

Samuel Holland Jan. 25, 2022, 2:42 a.m. UTC | #1
On 1/24/22 7:15 PM, Andre Przywara wrote:
> So far all Allwinner based boards were doing some not-so-lowlevel-setup
> in lowlevel's s_init() routine.
> This includes the initial clock, timer and pinmux setup, among other
> things. This is clearly out of the "absolute bare minimum to get started"
> scope that lowlevel_init.S suggests for this function.
> 
> Since we have an SPL, which is called right after s_init(), move those
> calls to our board_init_f() function. As we overwrite this only for
> the SPL, this has the added benefit of not doing this setup *again*
> shortly afterwards, when running U-Boot proper.
> 
> This makes gpio_init() to be called from the SPL only, so pull this code
> into a CONFIG_SPL_BUILD protected part to avoid build warnings.
> 
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>

Reviewed-by: Samuel Holland <samuel@sholland.org>

> ---
>  arch/arm/mach-sunxi/board.c | 27 ++++++++++++++-------------
>  1 file changed, 14 insertions(+), 13 deletions(-)
> 
> diff --git a/arch/arm/mach-sunxi/board.c b/arch/arm/mach-sunxi/board.c
> index 3ef179742c5..390c9f8850d 100644
> --- a/arch/arm/mach-sunxi/board.c
> +++ b/arch/arm/mach-sunxi/board.c
> @@ -75,6 +75,7 @@ ulong board_get_usable_ram_top(ulong total_size)
>  }
>  #endif
>  
> +#ifdef CONFIG_SPL_BUILD
>  static int gpio_init(void)
>  {
>  	__maybe_unused uint val;
> @@ -172,7 +173,6 @@ static int gpio_init(void)
>  	return 0;
>  }
>  
> -#if defined(CONFIG_SPL_BOARD_LOAD_IMAGE) && defined(CONFIG_SPL_BUILD)

As far as I can tell, this is the _only_ place that checks
CONFIG_SPL_BOARD_LOAD_IMAGE, so that definition could be removed from everywhere
now.

>  static int spl_board_load_image(struct spl_image_info *spl_image,
>  				struct spl_boot_device *bootdev)
>  {
> @@ -227,18 +227,6 @@ void s_init(void)
>  		"mcr p15, 0, r0, c1, c0, 1\n"
>  		::: "r0");
>  #endif
> -#if defined CONFIG_MACH_SUN6I || defined CONFIG_MACH_SUN8I_H3
> -	/* Enable non-secure access to some peripherals */
> -	tzpc_init();
> -#endif
> -
> -	clock_init();
> -	timer_init();
> -	gpio_init();
> -#if !CONFIG_IS_ENABLED(DM_I2C)
> -	i2c_init_board();
> -#endif
> -	eth_init_board();
>  }
>  
>  #define SUNXI_INVALID_BOOT_SOURCE	-1
> @@ -335,6 +323,19 @@ u32 spl_boot_device(void)
>  
>  void board_init_f(ulong dummy)
>  {
> +#if defined CONFIG_MACH_SUN6I || defined CONFIG_MACH_SUN8I_H3
> +	/* Enable non-secure access to some peripherals */
> +	tzpc_init();
> +#endif
> +
> +	clock_init();
> +	timer_init();
> +	gpio_init();
> +#if !CONFIG_IS_ENABLED(DM_I2C)
> +	i2c_init_board();

You could move this down a few lines, near the call to i2c_init, inside the
existing #if.

> +#endif
> +	eth_init_board();
> +
>  	spl_init();
>  	preloader_console_init();
>  
>
Simon Glass Jan. 27, 2022, 3:41 p.m. UTC | #2
On Mon, 24 Jan 2022 at 18:15, Andre Przywara <andre.przywara@arm.com> wrote:
>
> So far all Allwinner based boards were doing some not-so-lowlevel-setup
> in lowlevel's s_init() routine.
> This includes the initial clock, timer and pinmux setup, among other
> things. This is clearly out of the "absolute bare minimum to get started"
> scope that lowlevel_init.S suggests for this function.
>
> Since we have an SPL, which is called right after s_init(), move those
> calls to our board_init_f() function. As we overwrite this only for
> the SPL, this has the added benefit of not doing this setup *again*
> shortly afterwards, when running U-Boot proper.
>
> This makes gpio_init() to be called from the SPL only, so pull this code
> into a CONFIG_SPL_BUILD protected part to avoid build warnings.
>
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> ---
>  arch/arm/mach-sunxi/board.c | 27 ++++++++++++++-------------
>  1 file changed, 14 insertions(+), 13 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
Tested on: orangepi_pc2, orangepi_pc, A20-OLinuXino_MICRO
Tested-by: Simon Glass <sjg@chromium.org>


>
> diff --git a/arch/arm/mach-sunxi/board.c b/arch/arm/mach-sunxi/board.c
> index 3ef179742c5..390c9f8850d 100644
> --- a/arch/arm/mach-sunxi/board.c
> +++ b/arch/arm/mach-sunxi/board.c
> @@ -75,6 +75,7 @@ ulong board_get_usable_ram_top(ulong total_size)
>  }
>  #endif
>
> +#ifdef CONFIG_SPL_BUILD
>  static int gpio_init(void)
>  {
>         __maybe_unused uint val;
> @@ -172,7 +173,6 @@ static int gpio_init(void)
>         return 0;
>  }
>
> -#if defined(CONFIG_SPL_BOARD_LOAD_IMAGE) && defined(CONFIG_SPL_BUILD)
>  static int spl_board_load_image(struct spl_image_info *spl_image,
>                                 struct spl_boot_device *bootdev)
>  {
> @@ -227,18 +227,6 @@ void s_init(void)
>                 "mcr p15, 0, r0, c1, c0, 1\n"
>                 ::: "r0");
>  #endif
> -#if defined CONFIG_MACH_SUN6I || defined CONFIG_MACH_SUN8I_H3
> -       /* Enable non-secure access to some peripherals */
> -       tzpc_init();
> -#endif
> -
> -       clock_init();
> -       timer_init();
> -       gpio_init();
> -#if !CONFIG_IS_ENABLED(DM_I2C)
> -       i2c_init_board();
> -#endif
> -       eth_init_board();
>  }
>
>  #define SUNXI_INVALID_BOOT_SOURCE      -1
> @@ -335,6 +323,19 @@ u32 spl_boot_device(void)
>
>  void board_init_f(ulong dummy)
>  {
> +#if defined CONFIG_MACH_SUN6I || defined CONFIG_MACH_SUN8I_H3
> +       /* Enable non-secure access to some peripherals */
> +       tzpc_init();
> +#endif
> +
> +       clock_init();
> +       timer_init();
> +       gpio_init();
> +#if !CONFIG_IS_ENABLED(DM_I2C)
> +       i2c_init_board();
> +#endif
> +       eth_init_board();
> +
>         spl_init();
>         preloader_console_init();
>
> --
> 2.17.6
>
diff mbox series

Patch

diff --git a/arch/arm/mach-sunxi/board.c b/arch/arm/mach-sunxi/board.c
index 3ef179742c5..390c9f8850d 100644
--- a/arch/arm/mach-sunxi/board.c
+++ b/arch/arm/mach-sunxi/board.c
@@ -75,6 +75,7 @@  ulong board_get_usable_ram_top(ulong total_size)
 }
 #endif
 
+#ifdef CONFIG_SPL_BUILD
 static int gpio_init(void)
 {
 	__maybe_unused uint val;
@@ -172,7 +173,6 @@  static int gpio_init(void)
 	return 0;
 }
 
-#if defined(CONFIG_SPL_BOARD_LOAD_IMAGE) && defined(CONFIG_SPL_BUILD)
 static int spl_board_load_image(struct spl_image_info *spl_image,
 				struct spl_boot_device *bootdev)
 {
@@ -227,18 +227,6 @@  void s_init(void)
 		"mcr p15, 0, r0, c1, c0, 1\n"
 		::: "r0");
 #endif
-#if defined CONFIG_MACH_SUN6I || defined CONFIG_MACH_SUN8I_H3
-	/* Enable non-secure access to some peripherals */
-	tzpc_init();
-#endif
-
-	clock_init();
-	timer_init();
-	gpio_init();
-#if !CONFIG_IS_ENABLED(DM_I2C)
-	i2c_init_board();
-#endif
-	eth_init_board();
 }
 
 #define SUNXI_INVALID_BOOT_SOURCE	-1
@@ -335,6 +323,19 @@  u32 spl_boot_device(void)
 
 void board_init_f(ulong dummy)
 {
+#if defined CONFIG_MACH_SUN6I || defined CONFIG_MACH_SUN8I_H3
+	/* Enable non-secure access to some peripherals */
+	tzpc_init();
+#endif
+
+	clock_init();
+	timer_init();
+	gpio_init();
+#if !CONFIG_IS_ENABLED(DM_I2C)
+	i2c_init_board();
+#endif
+	eth_init_board();
+
 	spl_init();
 	preloader_console_init();