Skip to content

Commit a62f157

Browse files
GTLin08kartben
authored andcommitted
drivers/espi: ite: Add it51xxx compatibility with it8xxx2 support retained
The driver originally supported only it8xxx2 series. This updates introduces compatibility allow it to also support it51xxx series with minimal changes. Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com>
1 parent b12717b commit a62f157

File tree

6 files changed

+95
-13
lines changed

6 files changed

+95
-13
lines changed

drivers/espi/Kconfig.it8xxx2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ config ESPI_IT8XXX2
55
bool "ITE IT8XXX2 embedded controller ESPI driver"
66
default y
77
depends on DT_HAS_ITE_IT8XXX2_ESPI_ENABLED
8-
depends on SOC_IT8XXX2
8+
depends on SOC_IT8XXX2 || SOC_IT51XXX
99
help
1010
Enable ITE IT8XXX2 ESPI driver.
1111

drivers/espi/espi_it8xxx2.c

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <assert.h>
1010
#include <zephyr/drivers/espi.h>
1111
#include <zephyr/drivers/gpio.h>
12+
#include <zephyr/drivers/interrupt_controller/wuc_ite_it51xxx.h>
1213
#include <zephyr/drivers/interrupt_controller/wuc_ite_it8xxx2.h>
1314
#include <zephyr/kernel.h>
1415
#include <zephyr/sys/util.h>
@@ -21,8 +22,7 @@
2122
#include <zephyr/irq.h>
2223
LOG_MODULE_REGISTER(espi, CONFIG_ESPI_LOG_LEVEL);
2324

24-
#define ESPI_IT8XXX2_GET_GCTRL_BASE \
25-
((struct gctrl_it8xxx2_regs *)DT_REG_ADDR(DT_NODELABEL(gctrl)))
25+
#define ESPI_ITE_GET_GCTRL_BASE ((struct gctrl_ite_ec_regs *)DT_REG_ADDR(DT_NODELABEL(gctrl)))
2626

2727
#define IT8XXX2_ESPI_IRQ DT_INST_IRQ_BY_IDX(0, 0, irq)
2828
#define IT8XXX2_ESPI_VW_IRQ DT_INST_IRQ_BY_IDX(0, 1, irq)
@@ -827,9 +827,10 @@ static const struct ec2i_t smfi_settings[] = {
827827
static void smfi_it8xxx2_init(const struct device *dev)
828828
{
829829
const struct espi_it8xxx2_config *const config = dev->config;
830-
struct smfi_it8xxx2_regs *const smfi_reg =
831-
(struct smfi_it8xxx2_regs *)config->base_smfi;
832-
struct gctrl_it8xxx2_regs *const gctrl = ESPI_IT8XXX2_GET_GCTRL_BASE;
830+
struct smfi_ite_ec_regs *const smfi_reg = (struct smfi_ite_ec_regs *)config->base_smfi;
831+
832+
#ifdef CONFIG_SOC_SERIES_IT8XXX2
833+
struct gctrl_ite_ec_regs *const gctrl = ESPI_ITE_GET_GCTRL_BASE;
833834
uint8_t h2ram_offset;
834835

835836
/* Set the host to RAM cycle address offset */
@@ -838,6 +839,7 @@ static void smfi_it8xxx2_init(const struct device *dev)
838839
gctrl->GCTRL_H2ROFSR =
839840
(gctrl->GCTRL_H2ROFSR & ~IT8XXX2_ESPI_H2RAM_OFFSET_MASK) |
840841
h2ram_offset;
842+
#endif
841843

842844
#ifdef CONFIG_ESPI_PERIPHERAL_EC_HOST_CMD
843845
memset(&h2ram_pool[CONFIG_ESPI_PERIPHERAL_HOST_CMD_PARAM_PORT_NUM], 0,
@@ -929,12 +931,13 @@ static void pnpcfg_it8xxx2_configure(const struct device *dev,
929931

930932
#define PNPCFG(_s) \
931933
pnpcfg_it8xxx2_configure(dev, _s##_settings, ARRAY_SIZE(_s##_settings))
934+
extern uint8_t _h2ram_pool_start[];
932935

933936
static void pnpcfg_it8xxx2_init(const struct device *dev)
934937
{
935938
const struct espi_it8xxx2_config *const config = dev->config;
936939
struct ec2i_regs *const ec2i = (struct ec2i_regs *)config->base_ec2i;
937-
struct gctrl_it8xxx2_regs *const gctrl = ESPI_IT8XXX2_GET_GCTRL_BASE;
940+
struct gctrl_ite_ec_regs *const gctrl = ESPI_ITE_GET_GCTRL_BASE;
938941

939942
/* The register pair to access PNPCFG is 004Eh and 004Fh */
940943
gctrl->GCTRL_BADRSEL = 0x1;
@@ -953,6 +956,15 @@ static void pnpcfg_it8xxx2_init(const struct device *dev)
953956
#if defined(CONFIG_ESPI_PERIPHERAL_EC_HOST_CMD) || \
954957
defined(CONFIG_ESPI_PERIPHERAL_ACPI_SHM_REGION)
955958
PNPCFG(smfi);
959+
960+
#ifdef CONFIG_SOC_SERIES_IT51XXX
961+
uint8_t h2ram_pool_idx;
962+
963+
h2ram_pool_idx = ((uint32_t)_h2ram_pool_start & IT8XXX2_ESPI_H2RAM_BASEADDR_MASK) /
964+
IT8XXX2_ESPI_H2RAM_POOL_SIZE_MAX;
965+
/* H2RAM 4K page select */
966+
ec2i_it8xxx2_write(dev, HOST_INDEX_DSLDC13, h2ram_pool_idx);
967+
#endif
956968
#endif
957969
}
958970

@@ -1086,7 +1098,7 @@ static void pmc1_it8xxx2_init(const struct device *dev)
10861098
static void port80_it8xxx2_isr(const struct device *dev)
10871099
{
10881100
struct espi_it8xxx2_data *const data = dev->data;
1089-
struct gctrl_it8xxx2_regs *const gctrl = ESPI_IT8XXX2_GET_GCTRL_BASE;
1101+
struct gctrl_ite_ec_regs *const gctrl = ESPI_ITE_GET_GCTRL_BASE;
10901102
struct espi_event evt = {
10911103
ESPI_BUS_PERIPHERAL_NOTIFICATION,
10921104
(ESPI_PERIPHERAL_INDEX_0 << 16) | ESPI_PERIPHERAL_DEBUG_PORT80,
@@ -1107,7 +1119,7 @@ static void port80_it8xxx2_isr(const struct device *dev)
11071119
static void port80_it8xxx2_init(const struct device *dev)
11081120
{
11091121
ARG_UNUSED(dev);
1110-
struct gctrl_it8xxx2_regs *const gctrl = ESPI_IT8XXX2_GET_GCTRL_BASE;
1122+
struct gctrl_ite_ec_regs *const gctrl = ESPI_ITE_GET_GCTRL_BASE;
11111123

11121124
/* Accept Port 80h (and 81h) Cycle */
11131125
if (IS_ENABLED(CONFIG_ESPI_IT8XXX2_PORT_81_CYCLE)) {
@@ -2395,7 +2407,11 @@ void espi_it8xxx2_enable_trans_irq(const struct device *dev, bool enable)
23952407
} else {
23962408
irq_disable(IT8XXX2_TRANS_IRQ);
23972409
/* Clear pending interrupt */
2410+
#ifdef CONFIG_SOC_SERIES_IT51XXX
2411+
it51xxx_wuc_clear_status(config->wuc.wucs, config->wuc.mask);
2412+
#else
23982413
it8xxx2_wuc_clear_status(config->wuc.wucs, config->wuc.mask);
2414+
#endif
23992415
}
24002416
}
24012417

@@ -2431,7 +2447,7 @@ void espi_it8xxx2_espi_reset_isr(const struct device *port,
24312447
#define ESPI_IT8XXX2_ESPI_RESET_PIN 2
24322448
static void espi_it8xxx2_enable_reset(void)
24332449
{
2434-
struct gpio_it8xxx2_regs *const gpio_regs = GPIO_IT8XXX2_REG_BASE;
2450+
struct gpio_ite_ec_regs *const gpio_regs = GPIO_ITE_EC_REGS_BASE;
24352451
static struct gpio_callback espi_reset_cb;
24362452

24372453
/* eSPI reset is enabled on GPD2 */
@@ -2472,7 +2488,7 @@ static int espi_it8xxx2_init(const struct device *dev)
24722488
(struct espi_vw_regs *)config->base_espi_vw;
24732489
struct espi_slave_regs *const slave_reg =
24742490
(struct espi_slave_regs *)config->base_espi_slave;
2475-
struct gctrl_it8xxx2_regs *const gctrl = ESPI_IT8XXX2_GET_GCTRL_BASE;
2491+
struct gctrl_ite_ec_regs *const gctrl = ESPI_ITE_GET_GCTRL_BASE;
24762492

24772493
/* configure VCC detector */
24782494
gctrl->GCTRL_RSTS = (gctrl->GCTRL_RSTS &
@@ -2539,8 +2555,13 @@ static int espi_it8xxx2_init(const struct device *dev)
25392555
slave_reg->ESGCTRL2 |= IT8XXX2_ESPI_TO_WUC_ENABLE;
25402556

25412557
/* Enable WU42 of WUI */
2558+
#ifdef CONFIG_SOC_SERIES_IT51XXX
2559+
it51xxx_wuc_clear_status(config->wuc.wucs, config->wuc.mask);
2560+
it51xxx_wuc_enable(config->wuc.wucs, config->wuc.mask);
2561+
#else
25422562
it8xxx2_wuc_clear_status(config->wuc.wucs, config->wuc.mask);
25432563
it8xxx2_wuc_enable(config->wuc.wucs, config->wuc.mask);
2564+
#endif
25442565
/*
25452566
* Only register isr here, the interrupt only need to be enabled
25462567
* before CPU and RAM clocks gated in the idle function.

dts/riscv/ite/it51xxx.dtsi

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,31 @@
11891189
kso17-gpios = <&gpioc 5 (GPIO_OPEN_DRAIN | GPIO_PULL_UP)>;
11901190
};
11911191

1192+
espi0: espi@f03100 {
1193+
compatible = "ite,it8xxx2-espi";
1194+
reg = <0x00f03100 0xd8 /* eSPI slave */
1195+
0x00f03200 0x9a /* eSPI VW */
1196+
0x00f03300 0xd0 /* eSPI Queue 0 */
1197+
0x00f03400 0xc0 /* eSPI Queue 1 */
1198+
0x00f01200 6 /* EC2I bridge */
1199+
0x00f01300 11 /* Host KBC */
1200+
0x00f01500 0x100 /* Host PMC */
1201+
0x00f01000 0xd1>; /* SMFI */
1202+
interrupts = <IT51XXX_IRQ_ESPI IRQ_TYPE_LEVEL_HIGH
1203+
IT51XXX_IRQ_ESPI_VW IRQ_TYPE_LEVEL_HIGH
1204+
IT51XXX_IRQ_KBC_IBF IRQ_TYPE_LEVEL_HIGH
1205+
IT51XXX_IRQ_KBC_OBE IRQ_TYPE_LEVEL_HIGH
1206+
IT51XXX_IRQ_PMC1_IBF IRQ_TYPE_LEVEL_HIGH
1207+
IT51XXX_IRQ_PCH_P80 IRQ_TYPE_LEVEL_HIGH
1208+
IT51XXX_IRQ_PMC2_IBF IRQ_TYPE_LEVEL_HIGH
1209+
IT51XXX_IRQ_WKINTD IRQ_TYPE_LEVEL_HIGH>;
1210+
interrupt-parent = <&intc>;
1211+
wucctrl = <&wuc_wu42>;
1212+
#address-cells = <1>;
1213+
#size-cells = <1>;
1214+
status = "disabled";
1215+
};
1216+
11921217
twd0: watchdog@f04780 {
11931218
compatible = "ite,it51xxx-watchdog";
11941219
reg = <0x00f04780 0x20>;

soc/ite/ec/it51xxx/chip_chipregs.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,16 @@ struct gctrl_it51xxx_regs {
267267
volatile uint8_t reserved_1d_1f[3];
268268
/* 0x20: Reset Control 5 */
269269
volatile uint8_t GCTRL_RSTC5;
270-
/* 0x21-0x37: reserved_21_37 */
271-
volatile uint8_t reserved_21_37[23];
270+
/* 0x21-0x2f: reserved_21_2f */
271+
volatile uint8_t reserved_21_2f[15];
272+
/* 0x30: Port 80h/81h Status Register */
273+
volatile uint8_t GCTRL_P80H81HSR;
274+
/* 0x31: Port 80h Data Register */
275+
volatile uint8_t GCTRL_P80HDR;
276+
/* 0x32: Port 81h Data Register */
277+
volatile uint8_t GCTRL_P81HDR;
278+
/* 0x33-0x37: reserved_33_37 */
279+
volatile uint8_t reserved_33_37[5];
272280
/* 0x38: Special Control 9 */
273281
volatile uint8_t GCTRL_SPCTRL9;
274282
/* 0x39-0x46: reserved_39_46 */

soc/ite/ec/it51xxx/linker.ld

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,19 @@ SECTIONS
377377

378378
__data_region_end = .;
379379

380+
SECTION_DATA_PROLOGUE(.h2ram_pool,(NOLOAD),)
381+
{
382+
/*
383+
* Append h2ram_pool section at the end of used memory, so gap
384+
* due to alignment is still available for newly added variables
385+
*/
386+
. = ALIGN(0x1000);
387+
_h2ram_pool_start = .;
388+
KEEP(*(.h2ram_pool))
389+
_h2ram_pool_end = .;
390+
} GROUP_DATA_LINK_IN(RAMABLE_REGION, RAMABLE_REGION)
391+
_h2ram_pool_size = ABSOLUTE(_h2ram_pool_end - _h2ram_pool_start);
392+
380393
__kernel_ram_end = .;
381394
__kernel_ram_size = __kernel_ram_end - __kernel_ram_start;
382395

soc/ite/ec/it51xxx/soc.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <soc_common.h>
88
#include <zephyr/kernel.h>
99

10+
#include "soc_espi.h"
11+
1012
static mm_reg_t ecpm_base = DT_REG_ADDR(DT_NODELABEL(ecpm));
1113
/* it51xxx ECPM registers definition */
1214
/* 0x03: PLL Control */
@@ -57,12 +59,25 @@ void riscv_idle(enum chip_pll_mode mode, unsigned int key)
5759
csr_clear(mie, MIP_MEIP);
5860
sys_trace_idle();
5961

62+
#ifdef CONFIG_ESPI
63+
/*
64+
* H2RAM feature requires RAM clock to be active. Since the below doze
65+
* mode will disable CPU and RAM clocks, enable eSPI transaction
66+
* interrupt to restore clocks. With this interrupt, EC will not defer
67+
* eSPI bus while transaction is accepted.
68+
*/
69+
espi_ite_ec_enable_trans_irq(ESPI_ITE_SOC_DEV, true);
70+
#endif
6071
/* Chip doze after wfi instruction */
6172
chip_pll_ctrl(mode);
6273

6374
/* Wait for interrupt */
6475
__asm__ volatile("wfi");
6576

77+
#ifdef CONFIG_ESPI
78+
/* CPU has been woken up, the interrupt is no longer needed */
79+
espi_ite_ec_enable_trans_irq(ESPI_ITE_SOC_DEV, false);
80+
#endif
6681
/*
6782
* Enable M-mode external interrupt
6883
* An interrupt can not be fired yet until we enable global interrupt

0 commit comments

Comments
 (0)