summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2018-04-16 12:31:43 -0700
committerSascha Hauer <s.hauer@pengutronix.de>2018-04-17 09:13:05 +0200
commit761c6bd4cba4bb3b6ea29a020d7da18534e385a6 (patch)
tree338a5ceca91c30177b645c5f19d79a8436a55cef
parentd84beaa14a4a78000c025c02dc4e157a8b63ad07 (diff)
downloadbarebox-761c6bd4cba4bb3b6ea29a020d7da18534e385a6.tar.gz
barebox-761c6bd4cba4bb3b6ea29a020d7da18534e385a6.tar.xz
ARM: i.MX: Simplify serial bootsource detection for i.MX6 and 7
The algorithm to detect serial mode can be shared between i.M6 and i.MX7 as wall as simplified a bit by replacing swich goto/break/return termination logic with more trivial if statements. This commit also sets the stage for additional improvements in the commits that follow. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--arch/arm/mach-imx/boot.c50
1 files changed, 24 insertions, 26 deletions
diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 96bc2ec941..8a17a9975f 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -281,6 +281,18 @@ void imx53_boot_save_loc(void)
#define IMX6_SRC_SBMR1 0x04
#define IMX6_SRC_SBMR2 0x1c
+#define IMX6_BMOD_SERIAL 0b01
+#define IMX6_BMOD_RESERVED 0b11
+
+static bool imx6_bootsource_reserved(uint32_t sbmr2)
+{
+ return imx53_get_bmod(sbmr2) == IMX6_BMOD_RESERVED;
+}
+
+static bool imx6_bootsource_serial(uint32_t sbmr2)
+{
+ return imx53_get_bmod(sbmr2) == IMX6_BMOD_SERIAL;
+}
void imx6_get_boot_source(enum bootsource *src, int *instance)
{
@@ -289,20 +301,13 @@ void imx6_get_boot_source(enum bootsource *src, int *instance)
uint32_t sbmr2 = readl(src_base + IMX6_SRC_SBMR2);
uint32_t boot_cfg_4_2_0;
- switch (imx53_get_bmod(sbmr2)) {
- case 0: /* Fuses, fall through */
- case 2: /* internal boot */
- goto internal_boot;
- case 1: /* Serial Downloader */
- *src = BOOTSOURCE_SERIAL;
- break;
- case 3: /* reserved */
- break;
- };
-
- return;
+ if (imx6_bootsource_reserved(sbmr2))
+ return;
-internal_boot:
+ if (imx6_bootsource_serial(sbmr2)) {
+ *src = BOOTSOURCE_SERIAL;
+ return;
+ }
/* BOOT_CFG1[7:4] */
switch ((sbmr1 >> 4) & 0xf) {
@@ -361,20 +366,13 @@ void imx7_get_boot_source(enum bootsource *src, int *instance)
uint32_t sbmr1 = readl(src_base + IMX7_SRC_SBMR1);
uint32_t sbmr2 = readl(src_base + IMX7_SRC_SBMR2);
- switch (imx53_get_bmod(sbmr2)) {
- case 0: /* Fuses, fall through */
- case 2: /* internal boot */
- goto internal_boot;
- case 1: /* Serial Downloader */
- *src = BOOTSOURCE_SERIAL;
- break;
- case 3: /* reserved */
- break;
- };
-
- return;
+ if (imx6_bootsource_reserved(sbmr2))
+ return;
-internal_boot:
+ if (imx6_bootsource_serial(sbmr2)) {
+ *src = BOOTSOURCE_SERIAL;
+ return;
+ }
switch ((sbmr1 >> 12) & 0xf) {
case 1: