Skip to content

Commit f3ddb06

Browse files
GTLin08kartben
authored andcommitted
soc: ite: ilm: it51xxx: Support RAM code size up to 4K
Previously, the RAM code size was limited to 1K, causing issues when the code exceeded this limit. This update modifies the implementation to support RAM code sizes up to 4K test: zephyrproject/zephyr/tests/drivers/flash/common --> pass Signed-off-by: Tim Lin <[email protected]>
1 parent 12cba7a commit f3ddb06

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

soc/ite/ec/it51xxx/chip_chipregs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ struct gctrl_it51xxx_regs {
307307
#define IT51XXX_GCTRL_LRSIPGWR BIT(0)
308308
/* 0x38: Special Control 9 */
309309
#define IT51XXX_GCTRL_ALTIE BIT(4)
310+
/* 0x47: Scratch SRAM0 Base Address */
311+
#define IT51XXX_SEL_SRAM0_BASE_4K 0x04
310312
/* 0x48: Scratch ROM 0 Size */
311313
#define IT51XXX_GCTRL_SCRSIZE_4K 0x03
312314

soc/ite/ec/it51xxx/ilm_wrapper.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010

1111
void __soc_ram_code custom_reset_instr_cache(void)
1212
{
13-
struct gctrl_it51xxx_regs *const gctrl_regs = GCTRL_IT51XXX_REGS_BASE;
14-
15-
/* I-Cache tag sram reset */
16-
gctrl_regs->GCTRL_SCR0BAR = 0;
1713
/* Make sure the I-Cache is reset */
1814
__asm__ volatile("fence.i" ::: "memory");
1915
}

soc/ite/ec/it51xxx/linker.ld

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ SECTIONS
257257
/* Claim RAM for ILM mappings; must be 4k-aligned and each mapping is 4k in size */
258258
SECTION_PROLOGUE(ilm_ram,(NOLOAD),ALIGN(0x1000))
259259
{
260+
/* On IT51XXX chip, scratch RAM must start at RAM_BASE+0x1000 */
261+
. += 0x1000;
260262
__ilm_ram_start = .;
261263
. += __ilm_flash_end - __ilm_flash_start;
262264
__ilm_ram_end = .;

soc/ite/ec/it51xxx/soc.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,8 @@ void soc_prep_hook(void)
102102
struct gpio_ite_ec_regs *const gpio_regs = GPIO_ITE_EC_REGS_BASE;
103103
struct gctrl_ite_ec_regs *const gctrl_regs = GCTRL_ITE_EC_REGS_BASE;
104104

105-
/* Scratch ROM0 is 4kb size */
106-
gctrl_regs->GCTRL_SCR0SZR = IT51XXX_GCTRL_SCRSIZE_4K;
107-
108-
/* Scratch ROM0 is 4kb size */
109-
gctrl_regs->GCTRL_SCR0SZR = IT51XXX_GCTRL_SCRSIZE_4K;
105+
/* Scratch SRAM0 uses the 4KB based form 0x801000h */
106+
gctrl_regs->GCTRL_SCR0BAR = IT51XXX_SEL_SRAM0_BASE_4K;
110107

111108
/* bit4: wake up CPU if it is in low power mode and an interrupt is pending. */
112109
gctrl_regs->GCTRL_SPCTRL9 |= IT51XXX_GCTRL_ALTIE;

soc/ite/ec/it8xxx2/ilm.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,13 @@ static int it8xxx2_configure_ilm_block(const struct ilm_config *const config, vo
8080
if ((uintptr_t)ram_addr < RAM_BASE) {
8181
return -EFAULT; /* Not in RAM */
8282
}
83-
const int dirmap_index = ((uintptr_t)ram_addr - RAM_BASE) / ILM_BLOCK_SIZE;
8483

84+
#ifdef CONFIG_SOC_IT51XXX
85+
/* Since IT51XXX only supports one 4KB ILM block (SCAR0), set dirmap_index to 0 directly. */
86+
const int dirmap_index = 0;
87+
#else
88+
const int dirmap_index = ((uintptr_t)ram_addr - RAM_BASE) / ILM_BLOCK_SIZE;
89+
#endif
8590
if (dirmap_index >= ARRAY_SIZE(config->scar_regs)) {
8691
return -EFAULT; /* Past the end of RAM */
8792
}
@@ -101,8 +106,10 @@ static int it8xxx2_configure_ilm_block(const struct ilm_config *const config, vo
101106

102107
int irq_key = irq_lock();
103108

109+
#if !defined(CONFIG_SOC_IT51XXX)
104110
/* Ensure scratch RAM for block data access is enabled */
105111
scar->h = SCARH_ENABLE;
112+
#endif
106113
/* Copy block contents from flash into RAM */
107114
memcpy(ram_addr, flash_addr, copy_sz);
108115
/* Program SCAR */
@@ -116,6 +123,11 @@ static int it8xxx2_configure_ilm_block(const struct ilm_config *const config, vo
116123
}
117124
scar->h = scarh_value;
118125

126+
#ifdef CONFIG_SOC_IT51XXX
127+
struct gctrl_it51xxx_regs *const gctrl_regs = GCTRL_IT51XXX_REGS_BASE;
128+
/* Scratch ROM0 is 4kb size */
129+
gctrl_regs->GCTRL_SCR0SZR = IT51XXX_GCTRL_SCRSIZE_4K;
130+
#endif
119131
irq_unlock(irq_key);
120132
return 0;
121133
}

0 commit comments

Comments
 (0)