[PATCH 3/4] board/BuR/common: split br_resetc_bmode function

Bernhard Messerklinger bernhard.messerklinger at br-automation.com
Tue Oct 29 09:52:11 CET 2024


Split br_resetc_bmode function to add support for reading of reset
reason in board code with br_resetc_bmode_get.

Signed-off-by: Bernhard Messerklinger <bernhard.messerklinger at br-automation.com>
---

 board/BuR/common/br_resetc.c | 129 ++++++++++++++++++++---------------
 board/BuR/common/br_resetc.h |   1 +
 2 files changed, 74 insertions(+), 56 deletions(-)

diff --git a/board/BuR/common/br_resetc.c b/board/BuR/common/br_resetc.c
index 827ea6ba35..28fa87033f 100644
--- a/board/BuR/common/br_resetc.c
+++ b/board/BuR/common/br_resetc.c
@@ -113,9 +113,73 @@ int br_resetc_bmode(void)
 {
 	int rc = 0;
 	u16 regw;
+	unsigned int bmode = 0;
+
+	if (!resetc.i2cdev)
+		rc = resetc_init();
+
+	if (rc != 0)
+		return rc;
+
+	board_boot_led(1);
+
+	rc = br_resetc_bmode_get(&bmode);
+	if (rc != 0)
+		return rc;
+
+	LCD_SETCURSOR(1, 8);
+
+	switch (bmode) {
+	case BMODE_PME:
+		LCD_PUTS("entering PME-Mode (netscript).         ");
+		regw = 0x0C0C;
+		break;
+	case BMODE_DEFAULTAR:
+		LCD_PUTS("entering BOOT-mode.                    ");
+		regw = 0x0000;
+		break;
+	case BMODE_DIAG:
+		LCD_PUTS("entering DIAGNOSE-mode.                ");
+		regw = 0x0F0F;
+		break;
+	case BMODE_SERVICE:
+		LCD_PUTS("entering SERVICE mode.                 ");
+		regw = 0xB4B4;
+		break;
+	case BMODE_RUN:
+		LCD_PUTS("loading OS...                          ");
+		regw = 0x0404;
+		break;
+	}
+
+	board_boot_led(0);
+
+	if (resetc.is_psoc)
+		rc = dm_i2c_write(resetc.i2cdev, RSTCTRL_SCRATCHREG0,
+				  (u8 *)&regw, 2);
+	else
+		rc = dm_i2c_write(resetc.i2cdev, RSTCTRL_SCRATCHREG0,
+				  (u8 *)&regw, 1);
+
+	if (rc != 0)
+		printf("WARN: cannot write into resetcontroller!\n");
+
+	if (resetc.is_psoc)
+		printf("Reset: PSOC controller\n");
+	else
+		printf("Reset: STM32 controller\n");
+
+	printf("Mode:  %s\n", bootmodeascii[regw & 0x0F]);
+	env_set_ulong("b_mode", regw & 0x0F);
+
+	return rc;
+}
+
+int br_resetc_bmode_get(unsigned int *bmode)
+{
+	int rc = 0;
 	u8 regb, scr;
 	int cnt;
-	unsigned int bmode = 0;
 
 	if (!resetc.i2cdev)
 		rc = resetc_init();
@@ -135,13 +199,11 @@ int br_resetc_bmode(void)
 		return -1;
 	}
 
-	board_boot_led(1);
-
 	/* special bootmode from resetcontroller */
 	if (regb & 0x4) {
-		bmode = BMODE_DIAG;
+		*bmode = BMODE_DIAG;
 	} else if (regb & 0x8) {
-		bmode = BMODE_DEFAULTAR;
+		*bmode = BMODE_DEFAULTAR;
 	} else if (board_boot_key() != 0) {
 		cnt = 4;
 		do {
@@ -168,68 +230,23 @@ int br_resetc_bmode(void)
 
 		switch (cnt) {
 		case 0:
-			bmode = BMODE_PME;
+			*bmode = BMODE_PME;
 			break;
 		case 1:
-			bmode = BMODE_DEFAULTAR;
+			*bmode = BMODE_DEFAULTAR;
 			break;
 		case 2:
-			bmode = BMODE_DIAG;
+			*bmode = BMODE_DIAG;
 			break;
 		case 3:
-			bmode = BMODE_SERVICE;
+			*bmode = BMODE_SERVICE;
 			break;
 		}
 	} else if ((regb & 0x1) || scr == 0xCC) {
-		bmode = BMODE_PME;
+		*bmode = BMODE_PME;
 	} else {
-		bmode = BMODE_RUN;
+		*bmode = BMODE_RUN;
 	}
 
-	LCD_SETCURSOR(1, 8);
-
-	switch (bmode) {
-	case BMODE_PME:
-		LCD_PUTS("entering PME-Mode (netscript).         ");
-		regw = 0x0C0C;
-		break;
-	case BMODE_DEFAULTAR:
-		LCD_PUTS("entering BOOT-mode.                    ");
-		regw = 0x0000;
-		break;
-	case BMODE_DIAG:
-		LCD_PUTS("entering DIAGNOSE-mode.                ");
-		regw = 0x0F0F;
-		break;
-	case BMODE_SERVICE:
-		LCD_PUTS("entering SERVICE mode.                 ");
-		regw = 0xB4B4;
-		break;
-	case BMODE_RUN:
-		LCD_PUTS("loading OS...                          ");
-		regw = 0x0404;
-		break;
-	}
-
-	board_boot_led(0);
-
-	if (resetc.is_psoc)
-		rc = dm_i2c_write(resetc.i2cdev, RSTCTRL_SCRATCHREG0,
-				  (u8 *)&regw, 2);
-	else
-		rc = dm_i2c_write(resetc.i2cdev, RSTCTRL_SCRATCHREG0,
-				  (u8 *)&regw, 1);
-
-	if (rc != 0)
-		printf("WARN: cannot write into resetcontroller!\n");
-
-	if (resetc.is_psoc)
-		printf("Reset: PSOC controller\n");
-	else
-		printf("Reset: STM32 controller\n");
-
-	printf("Mode:  %s\n", bootmodeascii[regw & 0x0F]);
-	env_set_ulong("b_mode", regw & 0x0F);
-
 	return rc;
 }
diff --git a/board/BuR/common/br_resetc.h b/board/BuR/common/br_resetc.h
index 999045b867..3bd5ac20ae 100644
--- a/board/BuR/common/br_resetc.h
+++ b/board/BuR/common/br_resetc.h
@@ -11,6 +11,7 @@
 int br_resetc_regget(u8 reg, u8 *dst);
 int br_resetc_regset(u8 reg, u8 val);
 int br_resetc_bmode(void);
+int br_resetc_bmode_get(unsigned int *bmode);
 
 /* reset controller register defines */
 #define RSTCTRL_CTRLREG		0x01
-- 
2.46.1



More information about the U-Boot mailing list