summaryrefslogtreecommitdiff
path: root/chip/it83xx
diff options
context:
space:
mode:
Diffstat (limited to 'chip/it83xx')
-rw-r--r--chip/it83xx/registers.h22
-rw-r--r--chip/it83xx/system.c37
2 files changed, 50 insertions, 9 deletions
diff --git a/chip/it83xx/registers.h b/chip/it83xx/registers.h
index 227cdc2f99..57d73f7a26 100644
--- a/chip/it83xx/registers.h
+++ b/chip/it83xx/registers.h
@@ -1100,7 +1100,7 @@ REG8(IT83XX_PMC_BASE + (ch > LPC_PM2 ? 5 : 8) + (ch << 4))
/* Battery backed RAM indices. */
enum bram_indices {
/* reset flags uses 4 bytes */
- BRAM_IDX_RESET_FLAGS = 0,
+ BRAM_IDX_RESET_FLAGS0 = 0,
BRAM_IDX_RESET_FLAGS1 = 1,
BRAM_IDX_RESET_FLAGS2 = 2,
BRAM_IDX_RESET_FLAGS3 = 3,
@@ -1111,7 +1111,7 @@ enum bram_indices {
/* index 6 ~ 7 are reserved */
- BRAM_IDX_SCRATCHPAD = 8,
+ BRAM_IDX_SCRATCHPAD0 = 8,
BRAM_IDX_SCRATCHPAD1 = 9,
BRAM_IDX_SCRATCHPAD2 = 0xa,
BRAM_IDX_SCRATCHPAD3 = 0xb,
@@ -1120,17 +1120,31 @@ enum bram_indices {
/* NVCONTEXT uses 16 bytes */
BRAM_IDX_NVCONTEXT = 0x10,
BRAM_IDX_NVCONTEXT_END = 0x1F,
+
+ /* offset 0x20 ~ 0x7b are reserved for future use. */
+
+ /* This field is used to indicate BRAM is valid or not. */
+ BRAM_IDX_VALID_FLAGS0 = 0x7c,
+ BRAM_IDX_VALID_FLAGS1 = 0x7d,
+ BRAM_IDX_VALID_FLAGS2 = 0x7e,
+ BRAM_IDX_VALID_FLAGS3 = 0x7f
+ /* offset 0x7f is the end of BRAM bank 0. */
};
-#define BRAM_RESET_FLAGS IT83XX_BRAM_BANK0(BRAM_IDX_RESET_FLAGS)
+#define BRAM_RESET_FLAGS0 IT83XX_BRAM_BANK0(BRAM_IDX_RESET_FLAGS0)
#define BRAM_RESET_FLAGS1 IT83XX_BRAM_BANK0(BRAM_IDX_RESET_FLAGS1)
#define BRAM_RESET_FLAGS2 IT83XX_BRAM_BANK0(BRAM_IDX_RESET_FLAGS2)
#define BRAM_RESET_FLAGS3 IT83XX_BRAM_BANK0(BRAM_IDX_RESET_FLAGS3)
-#define BRAM_SCRATCHPAD IT83XX_BRAM_BANK0(BRAM_IDX_SCRATCHPAD)
+#define BRAM_SCRATCHPAD0 IT83XX_BRAM_BANK0(BRAM_IDX_SCRATCHPAD0)
#define BRAM_SCRATCHPAD1 IT83XX_BRAM_BANK0(BRAM_IDX_SCRATCHPAD1)
#define BRAM_SCRATCHPAD2 IT83XX_BRAM_BANK0(BRAM_IDX_SCRATCHPAD2)
#define BRAM_SCRATCHPAD3 IT83XX_BRAM_BANK0(BRAM_IDX_SCRATCHPAD3)
+#define BRAM_VALID_FLAGS0 IT83XX_BRAM_BANK0(BRAM_IDX_VALID_FLAGS0)
+#define BRAM_VALID_FLAGS1 IT83XX_BRAM_BANK0(BRAM_IDX_VALID_FLAGS1)
+#define BRAM_VALID_FLAGS2 IT83XX_BRAM_BANK0(BRAM_IDX_VALID_FLAGS2)
+#define BRAM_VALID_FLAGS3 IT83XX_BRAM_BANK0(BRAM_IDX_VALID_FLAGS3)
+
#define IT83XX_BRAM_BANK1(i) REG8(IT83XX_BRAM_BASE + 0x80 + i)
/*
diff --git a/chip/it83xx/system.c b/chip/it83xx/system.c
index 6a2c80cf84..87a97e1021 100644
--- a/chip/it83xx/system.c
+++ b/chip/it83xx/system.c
@@ -63,7 +63,7 @@ static void check_reset_cause(void)
/* Restore then clear saved reset flags. */
if (!(flags & RESET_FLAG_POWER_ON)) {
- flags |= BRAM_RESET_FLAGS << 24;
+ flags |= BRAM_RESET_FLAGS0 << 24;
flags |= BRAM_RESET_FLAGS1 << 16;
flags |= BRAM_RESET_FLAGS2 << 8;
flags |= BRAM_RESET_FLAGS3;
@@ -73,7 +73,7 @@ static void check_reset_cause(void)
flags &= ~RESET_FLAG_WATCHDOG;
}
- BRAM_RESET_FLAGS = 0;
+ BRAM_RESET_FLAGS0 = 0;
BRAM_RESET_FLAGS1 = 0;
BRAM_RESET_FLAGS2 = 0;
BRAM_RESET_FLAGS3 = 0;
@@ -122,6 +122,33 @@ void chip_pre_init(void)
IT83XX_SMB_SLVISELR &= ~(1 << 4);
}
+#define BRAM_VALID_MAGIC 0x4252414D /* "BRAM" */
+#define BRAM_VALID_MAGIC_FIELD0 (BRAM_VALID_MAGIC & 0xff)
+#define BRAM_VALID_MAGIC_FIELD1 ((BRAM_VALID_MAGIC >> 8) & 0xff)
+#define BRAM_VALID_MAGIC_FIELD2 ((BRAM_VALID_MAGIC >> 16) & 0xff)
+#define BRAM_VALID_MAGIC_FIELD3 ((BRAM_VALID_MAGIC >> 24) & 0xff)
+void chip_bram_valid(void)
+{
+ int i;
+
+ if ((BRAM_VALID_FLAGS0 != BRAM_VALID_MAGIC_FIELD0) ||
+ (BRAM_VALID_FLAGS1 != BRAM_VALID_MAGIC_FIELD1) ||
+ (BRAM_VALID_FLAGS2 != BRAM_VALID_MAGIC_FIELD2) ||
+ (BRAM_VALID_FLAGS3 != BRAM_VALID_MAGIC_FIELD3)) {
+ /*
+ * Magic does not match, so BRAM must be uninitialized. Clear
+ * entire Bank0 BRAM, and set magic value.
+ */
+ for (i = 0; i < BRAM_IDX_VALID_FLAGS0; i++)
+ IT83XX_BRAM_BANK0(i) = 0;
+
+ BRAM_VALID_FLAGS0 = BRAM_VALID_MAGIC_FIELD0;
+ BRAM_VALID_FLAGS1 = BRAM_VALID_MAGIC_FIELD1;
+ BRAM_VALID_FLAGS2 = BRAM_VALID_MAGIC_FIELD2;
+ BRAM_VALID_FLAGS3 = BRAM_VALID_MAGIC_FIELD3;
+ }
+}
+
void system_pre_init(void)
{
/* No initialization required */
@@ -142,7 +169,7 @@ void system_reset(int flags)
save_flags |= RESET_FLAG_HIBERNATE;
/* Store flags to battery backed RAM. */
- BRAM_RESET_FLAGS = save_flags >> 24;
+ BRAM_RESET_FLAGS0 = save_flags >> 24;
BRAM_RESET_FLAGS1 = (save_flags >> 16) & 0xff;
BRAM_RESET_FLAGS2 = (save_flags >> 8) & 0xff;
BRAM_RESET_FLAGS3 = save_flags & 0xff;
@@ -187,7 +214,7 @@ int system_set_scratchpad(uint32_t value)
BRAM_SCRATCHPAD3 = (value >> 24) & 0xff;
BRAM_SCRATCHPAD2 = (value >> 16) & 0xff;
BRAM_SCRATCHPAD1 = (value >> 8) & 0xff;
- BRAM_SCRATCHPAD = value & 0xff;
+ BRAM_SCRATCHPAD0 = value & 0xff;
return EC_SUCCESS;
}
@@ -199,7 +226,7 @@ uint32_t system_get_scratchpad(void)
value |= BRAM_SCRATCHPAD3 << 24;
value |= BRAM_SCRATCHPAD2 << 16;
value |= BRAM_SCRATCHPAD1 << 8;
- value |= BRAM_SCRATCHPAD;
+ value |= BRAM_SCRATCHPAD0;
return value;
}