Skip to content

Commit 8ceb0d0

Browse files
JhanBoChao-Realtekkartben
authored andcommitted
driver: espi: add espi peripheral channel HOST_CMD driver for rts5912
espi: add espi peripheral channel HOST_CMD driver for rts5912 Unlike other chips using IO port 0x800-0x8ff, we utilize shared memory to transfer host command parameters. The AP firmware must have corresponding settings for this configuration. Signed-off-by: jhan bo chao <[email protected]>
1 parent 1bc3025 commit 8ceb0d0

File tree

4 files changed

+192
-0
lines changed

4 files changed

+192
-0
lines changed

drivers/espi/Kconfig.rts5912

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ config ESPI_RTS5912
1010

1111
if ESPI_RTS5912
1212

13+
config ESPI_PERIPHERAL_EC_HOST_CMD
14+
default y
15+
1316
config ESPI_PERIPHERAL_DEBUG_PORT_80
1417
default y
1518

drivers/espi/espi_realtek_rts5912.c

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
LOG_MODULE_REGISTER(espi, CONFIG_ESPI_LOG_LEVEL);
1818

1919
#include "espi_utils.h"
20+
#include "reg/reg_acpi.h"
21+
#include "reg/reg_emi.h"
2022
#include "reg/reg_espi.h"
2123
#include "reg/reg_port80.h"
2224

@@ -26,6 +28,14 @@ struct espi_rts5912_config {
2628
volatile struct espi_reg *const espi_reg;
2729
uint32_t espislv_clk_grp;
2830
uint32_t espislv_clk_idx;
31+
#ifdef CONFIG_ESPI_PERIPHERAL_EC_HOST_CMD
32+
volatile struct acpi_reg *const promt0_reg;
33+
uint32_t promt0_clk_grp;
34+
uint32_t promt0_clk_idx;
35+
volatile struct emi_reg *const emi0_reg;
36+
uint32_t emi0_clk_grp;
37+
uint32_t emi0_clk_idx;
38+
#endif
2939
#ifdef CONFIG_ESPI_PERIPHERAL_DEBUG_PORT_80
3040
volatile struct port80_reg *const port80_reg;
3141
uint32_t port80_clk_grp;
@@ -51,6 +61,88 @@ struct espi_rts5912_data {
5161
#endif
5262
};
5363

64+
/*
65+
* =========================================================================
66+
* ESPI Peripheral EC Host Command (Promt0)
67+
* =========================================================================
68+
*/
69+
70+
#ifdef CONFIG_ESPI_PERIPHERAL_EC_HOST_CMD
71+
72+
#define ESPI_RTK_PERIPHERAL_HOST_CMD_PARAM_SIZE 256
73+
74+
static uint8_t ec_host_cmd_sram[ESPI_RTK_PERIPHERAL_HOST_CMD_PARAM_SIZE] __aligned(256);
75+
76+
static void espi_setup_host_cmd_shm(const struct espi_rts5912_config *const espi_config)
77+
{
78+
volatile struct emi_reg *const emi0_reg = espi_config->emi0_reg;
79+
80+
emi0_reg->SAR = (uint32_t)&ec_host_cmd_sram[0];
81+
}
82+
83+
static void promt0_ibf_isr(const struct device *dev)
84+
{
85+
const struct espi_rts5912_config *const espi_config = dev->config;
86+
volatile struct acpi_reg *const promt0_reg = espi_config->promt0_reg;
87+
struct espi_rts5912_data *data = dev->data;
88+
struct espi_event evt = {.evt_type = ESPI_BUS_PERIPHERAL_NOTIFICATION,
89+
.evt_details = ESPI_PERIPHERAL_EC_HOST_CMD,
90+
.evt_data = ESPI_PERIPHERAL_NODATA};
91+
92+
promt0_reg->STS |= ACPI_STS_STS0;
93+
evt.evt_data = (uint8_t)promt0_reg->IB;
94+
espi_send_callbacks(&data->callbacks, dev, evt);
95+
}
96+
97+
static int espi_promt0_setup(const struct device *dev)
98+
{
99+
const struct espi_rts5912_config *const espi_config = dev->config;
100+
struct rts5912_sccon_subsys sccon;
101+
volatile struct acpi_reg *const promt0_reg = espi_config->promt0_reg;
102+
int rc;
103+
104+
if (!device_is_ready(espi_config->clk_dev)) {
105+
LOG_ERR("Promt0 clock not ready");
106+
return -ENODEV;
107+
}
108+
109+
sccon.clk_grp = espi_config->promt0_clk_grp;
110+
sccon.clk_idx = espi_config->promt0_clk_idx;
111+
112+
rc = clock_control_on(espi_config->clk_dev, (clock_control_subsys_t)&sccon);
113+
if (rc != 0) {
114+
LOG_ERR("Promt0 clock control on failed");
115+
return rc;
116+
}
117+
118+
promt0_reg->STS = 0;
119+
120+
if (promt0_reg->STS & ACPI_STS_IBF) {
121+
rc = promt0_reg->IB;
122+
}
123+
124+
if (promt0_reg->STS & ACPI_STS_IBF) {
125+
promt0_reg->IB |= ACPI_IB_IBCLR;
126+
}
127+
128+
promt0_reg->PTADDR =
129+
CONFIG_ESPI_PERIPHERAL_HOST_CMD_DATA_PORT_NUM | (0x04 << ACPI_PTADDR_OFFSET_Pos);
130+
promt0_reg->VWCTRL1 = ACPI_VWCTRL1_ACTEN;
131+
promt0_reg->INTEN = ACPI_INTEN_IBFINTEN;
132+
133+
NVIC_ClearPendingIRQ(DT_IRQ_BY_NAME(DT_DRV_INST(0), promt0_ibf, irq));
134+
135+
/* IBF */
136+
IRQ_CONNECT(DT_IRQ_BY_NAME(DT_DRV_INST(0), promt0_ibf, irq),
137+
DT_IRQ_BY_NAME(DT_DRV_INST(0), promt0_ibf, priority), promt0_ibf_isr,
138+
DEVICE_DT_GET(DT_DRV_INST(0)), 0);
139+
irq_enable(DT_IRQ_BY_NAME(DT_DRV_INST(0), promt0_ibf, irq));
140+
141+
return 0;
142+
}
143+
144+
#endif /* CONFIG_ESPI_PERIPHERAL_EC_HOST_CMD */
145+
54146
/*
55147
* =========================================================================
56148
* ESPI Peripheral Debug Port 80
@@ -1635,6 +1727,16 @@ static int espi_rts5912_init(const struct device *dev)
16351727
/* Setup eSPI bus reset */
16361728
espi_bus_reset_setup(dev);
16371729

1730+
#ifdef CONFIG_ESPI_PERIPHERAL_EC_HOST_CMD
1731+
rc = espi_promt0_setup(dev);
1732+
if (rc != 0) {
1733+
LOG_ERR("eSPI Promt0 setup failed");
1734+
goto exit;
1735+
}
1736+
1737+
espi_setup_host_cmd_shm(espi_config);
1738+
#endif
1739+
16381740
#ifdef CONFIG_ESPI_PERIPHERAL_DEBUG_PORT_80
16391741
/* Setup Port80 */
16401742
rc = espi_peri_ch_port80_setup(dev);
@@ -1679,6 +1781,15 @@ static const struct espi_rts5912_config espi_rts5912_config = {
16791781
.espi_reg = (volatile struct espi_reg *const)DT_INST_REG_ADDR_BY_NAME(0, espi_target),
16801782
.espislv_clk_grp = DT_CLOCKS_CELL_BY_NAME(DT_DRV_INST(0), espi_target, clk_grp),
16811783
.espislv_clk_idx = DT_CLOCKS_CELL_BY_NAME(DT_DRV_INST(0), espi_target, clk_idx),
1784+
#ifdef CONFIG_ESPI_PERIPHERAL_EC_HOST_CMD
1785+
.promt0_reg = (volatile struct acpi_reg *const)DT_INST_REG_ADDR_BY_NAME(0, promt0),
1786+
.promt0_clk_grp = DT_CLOCKS_CELL_BY_NAME(DT_DRV_INST(0), promt0, clk_grp),
1787+
.promt0_clk_idx = DT_CLOCKS_CELL_BY_NAME(DT_DRV_INST(0), promt0, clk_idx),
1788+
1789+
.emi0_reg = (volatile struct emi_reg *const)DT_INST_REG_ADDR_BY_NAME(0, emi0),
1790+
.emi0_clk_grp = DT_CLOCKS_CELL_BY_NAME(DT_DRV_INST(0), emi0, clk_grp),
1791+
.emi0_clk_idx = DT_CLOCKS_CELL_BY_NAME(DT_DRV_INST(0), emi0, clk_idx),
1792+
#endif
16821793
#ifdef CONFIG_ESPI_PERIPHERAL_DEBUG_PORT_80
16831794
.port80_reg = (volatile struct port80_reg *const)DT_INST_REG_ADDR_BY_NAME(0, port80),
16841795
.port80_clk_grp = DT_CLOCKS_CELL_BY_NAME(DT_DRV_INST(0), port80, clk_grp),

soc/realtek/ec/rts5912/reg/reg_acpi.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2025 Realtek, SIBG-SD7
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_SOC_REALTEK_RTS5912_REG_ACPI_H
8+
#define ZEPHYR_SOC_REALTEK_RTS5912_REG_ACPI_H
9+
10+
struct acpi_reg {
11+
uint32_t STS;
12+
uint32_t IB;
13+
uint32_t OB;
14+
uint32_t PTADDR;
15+
uint32_t INTEN;
16+
uint32_t VWCTRL0;
17+
uint32_t VWCTRL1;
18+
};
19+
20+
/* STS */
21+
#define ACPI_STS_OBF BIT(0)
22+
#define ACPI_STS_IBF BIT(1)
23+
#define ACPI_STS_STS0 BIT(2)
24+
#define ACPI_STS_CMDSEL BIT(3)
25+
#define ACPI_STS_BURST BIT(4)
26+
#define ACPI_STS_STS2 BIT(5)
27+
#define ACPI_STS_STS3 BIT(6)
28+
#define ACPI_STS_STS4 BIT(7)
29+
30+
/* IB */
31+
#define ACPI_IB_IBDAT_Pos (0UL)
32+
#define ACPI_IB_IBDAT_Msk GENMASK(7, 0)
33+
#define ACPI_IB_IBCLR BIT(8)
34+
35+
/* OB */
36+
#define ACPI_OB_OBDAT_Pos (0UL)
37+
#define ACPI_OB_OBDAT_Msk GENMASK(7, 0)
38+
#define ACPI_OB_OBCLR BIT(8)
39+
40+
/* PTADDR */
41+
#define ACPI_PTADDR_ADDR_Pos (0UL)
42+
#define ACPI_PTADDR_ADDR_Msk GENMASK(11, 0)
43+
#define ACPI_PTADDR_OFFSET_Pos (12UL)
44+
#define ACPI_PTADDR_OFFSET_Msk GENMASK(14, 12)
45+
46+
/* INTEN */
47+
#define ACPI_INTEN_OBFINTEN BIT(0)
48+
#define ACPI_INTEN_IBFINTEN BIT(1)
49+
50+
/* VWCTRL0 */
51+
#define ACPI_VWCTRL0_IRQEN BIT(0)
52+
#define ACPI_VWCTRL0_TGLV BIT(1)
53+
54+
/* VWCTRL1 */
55+
#define ACPI_VWCTRL1_IRQNUM_Pos (0UL)
56+
#define ACPI_VWCTRL1_IRQNUM_Msk GENMASK(7, 0)
57+
#define ACPI_VWCTRL1_ACTEN BIT(8)
58+
59+
#endif /* ZEPHYR_SOC_REALTEK_RTS5912_REG_ACPI_H */

soc/realtek/ec/rts5912/reg/reg_emi.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2025 Realtek, SIBG-SD7
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_SOC_REALTEK_RTS5912_REG_EMI_H
8+
#define ZEPHYR_SOC_REALTEK_RTS5912_REG_EMI_H
9+
10+
struct emi_reg {
11+
uint32_t CFG;
12+
uint32_t INTCTRL;
13+
uint32_t IRQNUM;
14+
uint32_t SAR;
15+
uint32_t INTSTS;
16+
uint32_t STS;
17+
};
18+
19+
#endif /* ZEPHYR_SOC_REALTEK_RTS5912_REG_EMI_H */

0 commit comments

Comments
 (0)