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>
2122#include <zephyr/irq.h>
2223LOG_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[] = {
827827static 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
933936static 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)
10861098static 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)
11071119static 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
24322448static 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.
0 commit comments