diff mbox series

[2/2] xilinx: Move bootmode detection to separate function

Message ID fa842338784a5b28a42ff2f29cc4402d0113d85d.1586764879.git.michal.simek@xilinx.com
State Accepted
Commit 51f6c52e6b12d7bc7a82db566057efe731f5aae9
Headers show
Series [1/2] xilinx: Move initrd_high setup to common location | expand

Commit Message

Michal Simek April 13, 2020, 8:01 a.m. UTC
Create special function for reading bootmode on Versal and ZynqMP.
Zynq is using specific function (without mask) already.
Future patches will be calling this function from different location too.

Signed-off-by: Michal Simek <michal.simek at xilinx.com>
---

 board/xilinx/versal/board.c  | 23 ++++++++++++++++-------
 board/xilinx/zynqmp/zynqmp.c | 28 +++++++++++++++++++---------
 2 files changed, 35 insertions(+), 16 deletions(-)

Comments

Michal Simek April 30, 2020, 7:35 a.m. UTC | #1
po 13. 4. 2020 v 10:01 odes?latel Michal Simek <michal.simek at xilinx.com> napsal:
>
> Create special function for reading bootmode on Versal and ZynqMP.
> Zynq is using specific function (without mask) already.
> Future patches will be calling this function from different location too.
>
> Signed-off-by: Michal Simek <michal.simek at xilinx.com>
> ---
>
>  board/xilinx/versal/board.c  | 23 ++++++++++++++++-------
>  board/xilinx/zynqmp/zynqmp.c | 28 +++++++++++++++++++---------
>  2 files changed, 35 insertions(+), 16 deletions(-)
>
> diff --git a/board/xilinx/versal/board.c b/board/xilinx/versal/board.c
> index 2900dfb44e93..483e3ce2f79a 100644
> --- a/board/xilinx/versal/board.c
> +++ b/board/xilinx/versal/board.c
> @@ -82,9 +82,23 @@ int board_early_init_r(void)
>         return 0;
>  }
>
> -int board_late_init(void)
> +static u8 versal_get_bootmode(void)
>  {
> +       u8 bootmode;
>         u32 reg = 0;
> +
> +       reg = readl(&crp_base->boot_mode_usr);
> +
> +       if (reg >> BOOT_MODE_ALT_SHIFT)
> +               reg >>= BOOT_MODE_ALT_SHIFT;
> +
> +       bootmode = reg & BOOT_MODES_MASK;
> +
> +       return bootmode;
> +}
> +
> +int board_late_init(void)
> +{
>         u8 bootmode;
>         struct udevice *dev;
>         int bootseq = -1;
> @@ -99,12 +113,7 @@ int board_late_init(void)
>                 return 0;
>         }
>
> -       reg = readl(&crp_base->boot_mode_usr);
> -
> -       if (reg >> BOOT_MODE_ALT_SHIFT)
> -               reg >>= BOOT_MODE_ALT_SHIFT;
> -
> -       bootmode = reg & BOOT_MODES_MASK;
> +       bootmode = versal_get_bootmode();
>
>         puts("Bootmode: ");
>         switch (bootmode) {
> diff --git a/board/xilinx/zynqmp/zynqmp.c b/board/xilinx/zynqmp/zynqmp.c
> index 66a43974e68d..a2a0d563318e 100644
> --- a/board/xilinx/zynqmp/zynqmp.c
> +++ b/board/xilinx/zynqmp/zynqmp.c
> @@ -552,9 +552,26 @@ static int set_fdtfile(void)
>         return 0;
>  }
>
> -int board_late_init(void)
> +static u8 zynqmp_get_bootmode(void)
>  {
> +       u8 bootmode;
>         u32 reg = 0;
> +       int ret;
> +
> +       ret = zynqmp_mmio_read((ulong)&crlapb_base->boot_mode, &reg);
> +       if (ret)
> +               return -EINVAL;
> +
> +       if (reg >> BOOT_MODE_ALT_SHIFT)
> +               reg >>= BOOT_MODE_ALT_SHIFT;
> +
> +       bootmode = reg & BOOT_MODES_MASK;
> +
> +       return bootmode;
> +}
> +
> +int board_late_init(void)
> +{
>         u8 bootmode;
>         struct udevice *dev;
>         int bootseq = -1;
> @@ -578,14 +595,7 @@ int board_late_init(void)
>         if (ret)
>                 return ret;
>
> -       ret = zynqmp_mmio_read((ulong)&crlapb_base->boot_mode, &reg);
> -       if (ret)
> -               return -EINVAL;
> -
> -       if (reg >> BOOT_MODE_ALT_SHIFT)
> -               reg >>= BOOT_MODE_ALT_SHIFT;
> -
> -       bootmode = reg & BOOT_MODES_MASK;
> +       bootmode = zynqmp_get_bootmode();
>
>         puts("Bootmode: ");
>         switch (bootmode) {
> --
> 2.26.0
>

Applied.
M
diff mbox series

Patch

diff --git a/board/xilinx/versal/board.c b/board/xilinx/versal/board.c
index 2900dfb44e93..483e3ce2f79a 100644
--- a/board/xilinx/versal/board.c
+++ b/board/xilinx/versal/board.c
@@ -82,9 +82,23 @@  int board_early_init_r(void)
 	return 0;
 }
 
-int board_late_init(void)
+static u8 versal_get_bootmode(void)
 {
+	u8 bootmode;
 	u32 reg = 0;
+
+	reg = readl(&crp_base->boot_mode_usr);
+
+	if (reg >> BOOT_MODE_ALT_SHIFT)
+		reg >>= BOOT_MODE_ALT_SHIFT;
+
+	bootmode = reg & BOOT_MODES_MASK;
+
+	return bootmode;
+}
+
+int board_late_init(void)
+{
 	u8 bootmode;
 	struct udevice *dev;
 	int bootseq = -1;
@@ -99,12 +113,7 @@  int board_late_init(void)
 		return 0;
 	}
 
-	reg = readl(&crp_base->boot_mode_usr);
-
-	if (reg >> BOOT_MODE_ALT_SHIFT)
-		reg >>= BOOT_MODE_ALT_SHIFT;
-
-	bootmode = reg & BOOT_MODES_MASK;
+	bootmode = versal_get_bootmode();
 
 	puts("Bootmode: ");
 	switch (bootmode) {
diff --git a/board/xilinx/zynqmp/zynqmp.c b/board/xilinx/zynqmp/zynqmp.c
index 66a43974e68d..a2a0d563318e 100644
--- a/board/xilinx/zynqmp/zynqmp.c
+++ b/board/xilinx/zynqmp/zynqmp.c
@@ -552,9 +552,26 @@  static int set_fdtfile(void)
 	return 0;
 }
 
-int board_late_init(void)
+static u8 zynqmp_get_bootmode(void)
 {
+	u8 bootmode;
 	u32 reg = 0;
+	int ret;
+
+	ret = zynqmp_mmio_read((ulong)&crlapb_base->boot_mode, &reg);
+	if (ret)
+		return -EINVAL;
+
+	if (reg >> BOOT_MODE_ALT_SHIFT)
+		reg >>= BOOT_MODE_ALT_SHIFT;
+
+	bootmode = reg & BOOT_MODES_MASK;
+
+	return bootmode;
+}
+
+int board_late_init(void)
+{
 	u8 bootmode;
 	struct udevice *dev;
 	int bootseq = -1;
@@ -578,14 +595,7 @@  int board_late_init(void)
 	if (ret)
 		return ret;
 
-	ret = zynqmp_mmio_read((ulong)&crlapb_base->boot_mode, &reg);
-	if (ret)
-		return -EINVAL;
-
-	if (reg >> BOOT_MODE_ALT_SHIFT)
-		reg >>= BOOT_MODE_ALT_SHIFT;
-
-	bootmode = reg & BOOT_MODES_MASK;
+	bootmode = zynqmp_get_bootmode();
 
 	puts("Bootmode: ");
 	switch (bootmode) {