Skip to content

Commit 4320fb5

Browse files
JhanBoChao-Realtekkartben
authored andcommitted
driver: espi: add espi peripheral channel acpi driver for rts5912
add espi peripheral channel acpi driver for rts5912 Signed-off-by: jhan bo chao <[email protected]>
1 parent 8ceb0d0 commit 4320fb5

File tree

2 files changed

+148
-0
lines changed

2 files changed

+148
-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_HOST_IO
14+
default y
15+
1316
config ESPI_PERIPHERAL_EC_HOST_CMD
1417
default y
1518

drivers/espi/espi_realtek_rts5912.c

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ struct espi_rts5912_config {
2828
volatile struct espi_reg *const espi_reg;
2929
uint32_t espislv_clk_grp;
3030
uint32_t espislv_clk_idx;
31+
#ifdef CONFIG_ESPI_PERIPHERAL_HOST_IO
32+
volatile struct acpi_reg *const acpi_reg;
33+
uint32_t acpi_clk_grp;
34+
uint32_t acpi_clk_idx;
35+
#endif
3136
#ifdef CONFIG_ESPI_PERIPHERAL_EC_HOST_CMD
3237
volatile struct acpi_reg *const promt0_reg;
3338
uint32_t promt0_clk_grp;
@@ -61,6 +66,132 @@ struct espi_rts5912_data {
6166
#endif
6267
};
6368

69+
/*
70+
* =========================================================================
71+
* ESPI Peripheral Host IO (ACPI)
72+
* =========================================================================
73+
*/
74+
75+
#ifdef CONFIG_ESPI_PERIPHERAL_HOST_IO
76+
77+
static void acpi_ibf_isr(const struct device *dev)
78+
{
79+
const struct espi_rts5912_config *const espi_config = dev->config;
80+
struct espi_rts5912_data *espi_data = dev->data;
81+
struct espi_event evt = {ESPI_BUS_PERIPHERAL_NOTIFICATION, ESPI_PERIPHERAL_HOST_IO,
82+
ESPI_PERIPHERAL_NODATA};
83+
struct espi_evt_data_acpi *acpi_evt = (struct espi_evt_data_acpi *)&evt.evt_data;
84+
volatile struct acpi_reg *const acpi_reg = espi_config->acpi_reg;
85+
86+
/* Host put data on input buffer of ACPI EC0 channel */
87+
if (acpi_reg->STS & ACPI_STS_IBF) {
88+
/*
89+
* Indicates if the host sent a command or data.
90+
* 0 = data
91+
* 1 = Command.
92+
*/
93+
acpi_evt->type = acpi_reg->STS & ACPI_STS_CMDSEL ? 1 : 0;
94+
acpi_evt->data = (uint8_t)acpi_reg->IB;
95+
}
96+
espi_send_callbacks(&espi_data->callbacks, dev, evt);
97+
}
98+
99+
static int espi_acpi_setup(const struct device *dev)
100+
{
101+
const struct espi_rts5912_config *const espi_config = dev->config;
102+
struct rts5912_sccon_subsys sccon;
103+
volatile struct acpi_reg *const acpi_reg = espi_config->acpi_reg;
104+
int rc;
105+
106+
if (!device_is_ready(espi_config->clk_dev)) {
107+
LOG_ERR("ACPI clock not ready");
108+
return -ENODEV;
109+
}
110+
111+
sccon.clk_grp = espi_config->acpi_clk_grp;
112+
sccon.clk_idx = espi_config->acpi_clk_idx;
113+
rc = clock_control_on(espi_config->clk_dev, (clock_control_subsys_t)&sccon);
114+
if (rc != 0) {
115+
LOG_ERR("ACPI clock control on failed");
116+
return rc;
117+
}
118+
119+
acpi_reg->VWCTRL1 = (0x00UL << ACPI_VWCTRL1_IRQNUM_Pos) | ACPI_VWCTRL1_ACTEN;
120+
acpi_reg->INTEN = ACPI_INTEN_IBFINTEN;
121+
122+
NVIC_ClearPendingIRQ(DT_IRQ_BY_NAME(DT_DRV_INST(0), acpi_ibf, irq));
123+
124+
/* IBF */
125+
IRQ_CONNECT(DT_IRQ_BY_NAME(DT_DRV_INST(0), acpi_ibf, irq),
126+
DT_IRQ_BY_NAME(DT_DRV_INST(0), acpi_ibf, priority), acpi_ibf_isr,
127+
DEVICE_DT_GET(DT_DRV_INST(0)), 0);
128+
irq_enable(DT_IRQ_BY_NAME(DT_DRV_INST(0), acpi_ibf, irq));
129+
130+
return 0;
131+
}
132+
133+
static int lpc_request_read_acpi(const struct espi_rts5912_config *const espi_config,
134+
enum lpc_peripheral_opcode op, uint32_t *data)
135+
{
136+
volatile struct acpi_reg *const acpi_reg = espi_config->acpi_reg;
137+
138+
switch (op) {
139+
case EACPI_OBF_HAS_CHAR:
140+
*data = acpi_reg->STS & ACPI_STS_OBF ? 1 : 0;
141+
break;
142+
case EACPI_IBF_HAS_CHAR:
143+
*data = acpi_reg->STS & ACPI_STS_IBF ? 1 : 0;
144+
break;
145+
case EACPI_READ_STS:
146+
*data = acpi_reg->STS;
147+
break;
148+
#ifdef CONFIG_ESPI_PERIPHERAL_ACPI_SHM_REGION
149+
case EACPI_GET_SHARED_MEMORY:
150+
*data = (uint32_t)acpi_shd_mem_sram;
151+
break;
152+
#endif
153+
default:
154+
return -EINVAL;
155+
}
156+
157+
return 0;
158+
}
159+
160+
static int lpc_request_write_acpi(const struct espi_rts5912_config *const espi_config,
161+
enum lpc_peripheral_opcode op, uint32_t *data)
162+
{
163+
volatile struct acpi_reg *const acpi_reg = espi_config->acpi_reg;
164+
165+
switch (op) {
166+
case EACPI_WRITE_CHAR:
167+
acpi_reg->OB = *data & 0xff;
168+
break;
169+
case EACPI_WRITE_STS:
170+
acpi_reg->STS = *data & 0xff;
171+
break;
172+
default:
173+
return -EINVAL;
174+
}
175+
176+
return 0;
177+
}
178+
179+
#else /* CONFIG_ESPI_PERIPHERAL_HOST_IO */
180+
181+
static int lpc_request_read_acpi(const struct espi_rts5912_config *const espi_config,
182+
enum lpc_peripheral_opcode op, uint32_t *data)
183+
{
184+
return -ENOTSUP;
185+
}
186+
187+
static int lpc_request_write_acpi(const struct espi_rts5912_config *const espi_config,
188+
enum lpc_peripheral_opcode op, uint32_t *data)
189+
{
190+
return -ENOTSUP;
191+
}
192+
193+
#endif /* CONFIG_ESPI_PERIPHERAL_HOST_IO */
194+
64195
/*
65196
* =========================================================================
66197
* ESPI Peripheral EC Host Command (Promt0)
@@ -1727,6 +1858,15 @@ static int espi_rts5912_init(const struct device *dev)
17271858
/* Setup eSPI bus reset */
17281859
espi_bus_reset_setup(dev);
17291860

1861+
#ifdef CONFIG_ESPI_PERIPHERAL_HOST_IO
1862+
/* Setup ACPI */
1863+
rc = espi_acpi_setup(dev);
1864+
if (rc != 0) {
1865+
LOG_ERR("eSPI ACPI setup failed");
1866+
goto exit;
1867+
}
1868+
#endif
1869+
17301870
#ifdef CONFIG_ESPI_PERIPHERAL_EC_HOST_CMD
17311871
rc = espi_promt0_setup(dev);
17321872
if (rc != 0) {
@@ -1781,6 +1921,11 @@ static const struct espi_rts5912_config espi_rts5912_config = {
17811921
.espi_reg = (volatile struct espi_reg *const)DT_INST_REG_ADDR_BY_NAME(0, espi_target),
17821922
.espislv_clk_grp = DT_CLOCKS_CELL_BY_NAME(DT_DRV_INST(0), espi_target, clk_grp),
17831923
.espislv_clk_idx = DT_CLOCKS_CELL_BY_NAME(DT_DRV_INST(0), espi_target, clk_idx),
1924+
#ifdef CONFIG_ESPI_PERIPHERAL_HOST_IO
1925+
.acpi_reg = (volatile struct acpi_reg *const)DT_INST_REG_ADDR_BY_NAME(0, acpi),
1926+
.acpi_clk_grp = DT_CLOCKS_CELL_BY_NAME(DT_DRV_INST(0), acpi, clk_grp),
1927+
.acpi_clk_idx = DT_CLOCKS_CELL_BY_NAME(DT_DRV_INST(0), acpi, clk_idx),
1928+
#endif
17841929
#ifdef CONFIG_ESPI_PERIPHERAL_EC_HOST_CMD
17851930
.promt0_reg = (volatile struct acpi_reg *const)DT_INST_REG_ADDR_BY_NAME(0, promt0),
17861931
.promt0_clk_grp = DT_CLOCKS_CELL_BY_NAME(DT_DRV_INST(0), promt0, clk_grp),

0 commit comments

Comments
 (0)