ITE: drivers/bbram: add magic number to compare in initial
BBRAM content should be cleared when boot from cutoff. Compare magic number to decide whether to clear entire BBRAM. Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com>
This commit is contained in:
parent
e0cb96c4e3
commit
95ba8e3fe4
2 changed files with 49 additions and 2 deletions
|
@ -13,6 +13,12 @@
|
||||||
#include <logging/log.h>
|
#include <logging/log.h>
|
||||||
LOG_MODULE_REGISTER(bbram, CONFIG_BBRAM_LOG_LEVEL);
|
LOG_MODULE_REGISTER(bbram, CONFIG_BBRAM_LOG_LEVEL);
|
||||||
|
|
||||||
|
#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)
|
||||||
|
|
||||||
/** Device config */
|
/** Device config */
|
||||||
struct bbram_it8xxx2_config {
|
struct bbram_it8xxx2_config {
|
||||||
/** BBRAM base address */
|
/** BBRAM base address */
|
||||||
|
@ -53,7 +59,30 @@ static const struct bbram_driver_api bbram_it8xxx2_driver_api = {
|
||||||
|
|
||||||
static int bbram_it8xxx2_init(const struct device *dev)
|
static int bbram_it8xxx2_init(const struct device *dev)
|
||||||
{
|
{
|
||||||
ARG_UNUSED(dev);
|
const struct bbram_it8xxx2_config *config = dev->config;
|
||||||
|
uint8_t *base_addr = (uint8_t *)config->base_addr;
|
||||||
|
uint8_t *bram_valid_flag0 = base_addr + BRAM_IDX_VALID_FLAGS0;
|
||||||
|
uint8_t *bram_valid_flag1 = base_addr + BRAM_IDX_VALID_FLAGS1;
|
||||||
|
uint8_t *bram_valid_flag2 = base_addr + BRAM_IDX_VALID_FLAGS2;
|
||||||
|
uint8_t *bram_valid_flag3 = base_addr + BRAM_IDX_VALID_FLAGS3;
|
||||||
|
|
||||||
|
if ((*bram_valid_flag0 != BRAM_VALID_MAGIC_FIELD0) ||
|
||||||
|
(*bram_valid_flag1 != BRAM_VALID_MAGIC_FIELD1) ||
|
||||||
|
(*bram_valid_flag2 != BRAM_VALID_MAGIC_FIELD2) ||
|
||||||
|
(*bram_valid_flag3 != BRAM_VALID_MAGIC_FIELD3)) {
|
||||||
|
/*
|
||||||
|
* Magic does not match, so BRAM must be uninitialized. Clear
|
||||||
|
* entire Bank0 BRAM, and set magic value.
|
||||||
|
*/
|
||||||
|
for (int i = 0; i < BRAM_IDX_VALID_FLAGS0; i++) {
|
||||||
|
*(base_addr + i) = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
*bram_valid_flag0 = BRAM_VALID_MAGIC_FIELD0;
|
||||||
|
*bram_valid_flag1 = BRAM_VALID_MAGIC_FIELD1;
|
||||||
|
*bram_valid_flag2 = BRAM_VALID_MAGIC_FIELD2;
|
||||||
|
*bram_valid_flag3 = BRAM_VALID_MAGIC_FIELD3;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020 ITE Corporation. All Rights Reserved.
|
* Copyright (c) 2020 ITE Corporation. All Rights Reserved.
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
@ -1876,6 +1876,24 @@ struct gctrl_it8xxx2_regs {
|
||||||
/* bit[2] = 1: Enable global reset. */
|
/* bit[2] = 1: Enable global reset. */
|
||||||
#define IT8XXX2_GCTRL_GRST BIT(2)
|
#define IT8XXX2_GCTRL_GRST BIT(2)
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* (22xxh) Battery-backed SRAM (BRAM) registers
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef __ASSEMBLER__
|
||||||
|
/* Battery backed RAM indices. */
|
||||||
|
#define BRAM_MAGIC_FIELD_OFFSET 0xbc
|
||||||
|
enum bram_indices {
|
||||||
|
|
||||||
|
/* This field is used to indicate BRAM is valid or not. */
|
||||||
|
BRAM_IDX_VALID_FLAGS0 = BRAM_MAGIC_FIELD_OFFSET,
|
||||||
|
BRAM_IDX_VALID_FLAGS1,
|
||||||
|
BRAM_IDX_VALID_FLAGS2,
|
||||||
|
BRAM_IDX_VALID_FLAGS3
|
||||||
|
};
|
||||||
|
#endif /* !__ASSEMBLER__ */
|
||||||
|
|
||||||
#ifndef __ASSEMBLER__
|
#ifndef __ASSEMBLER__
|
||||||
/*
|
/*
|
||||||
* EC2I bridge registers
|
* EC2I bridge registers
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue