Skip to content

Commit 1bc3025

Browse files
JhanBoChao-Realtekkartben
authored andcommitted
driver: espi: add espi peripheral channel port 80 driver for rts5912
add espi peripheral channel port 80 driver for rts5912 Signed-off-by: jhan bo chao <[email protected]>
1 parent 1c461e3 commit 1bc3025

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-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_DEBUG_PORT_80
14+
default y
15+
1316
config ESPI_OOB_CHANNEL
1417
default y
1518

drivers/espi/espi_realtek_rts5912.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@ LOG_MODULE_REGISTER(espi, CONFIG_ESPI_LOG_LEVEL);
1818

1919
#include "espi_utils.h"
2020
#include "reg/reg_espi.h"
21+
#include "reg/reg_port80.h"
2122

2223
BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) == 1, "support only one espi compatible node");
2324

2425
struct espi_rts5912_config {
2526
volatile struct espi_reg *const espi_reg;
2627
uint32_t espislv_clk_grp;
2728
uint32_t espislv_clk_idx;
29+
#ifdef CONFIG_ESPI_PERIPHERAL_DEBUG_PORT_80
30+
volatile struct port80_reg *const port80_reg;
31+
uint32_t port80_clk_grp;
32+
uint32_t port80_clk_idx;
33+
#endif
2834
const struct device *clk_dev;
2935
const struct pinctrl_dev_config *pcfg;
3036
};
@@ -45,6 +51,62 @@ struct espi_rts5912_data {
4551
#endif
4652
};
4753

54+
/*
55+
* =========================================================================
56+
* ESPI Peripheral Debug Port 80
57+
* =========================================================================
58+
*/
59+
60+
#ifdef CONFIG_ESPI_PERIPHERAL_DEBUG_PORT_80
61+
62+
static void espi_port80_isr(const struct device *dev)
63+
{
64+
const struct espi_rts5912_config *const espi_config = dev->config;
65+
struct espi_rts5912_data *espi_data = dev->data;
66+
struct espi_event evt = {ESPI_BUS_PERIPHERAL_NOTIFICATION,
67+
ESPI_PERIPHERAL_INDEX_0 << 16 | ESPI_PERIPHERAL_DEBUG_PORT80,
68+
ESPI_PERIPHERAL_NODATA};
69+
volatile struct port80_reg *const port80_reg = espi_config->port80_reg;
70+
71+
evt.evt_data = port80_reg->DATA;
72+
espi_send_callbacks(&espi_data->callbacks, dev, evt);
73+
}
74+
75+
static int espi_peri_ch_port80_setup(const struct device *dev)
76+
{
77+
const struct espi_rts5912_config *const espi_config = dev->config;
78+
struct rts5912_sccon_subsys sccon;
79+
volatile struct port80_reg *const port80_reg = espi_config->port80_reg;
80+
int rc;
81+
82+
if (!device_is_ready(espi_config->clk_dev)) {
83+
return -ENODEV;
84+
}
85+
86+
sccon.clk_grp = espi_config->port80_clk_grp;
87+
sccon.clk_idx = espi_config->port80_clk_idx;
88+
89+
rc = clock_control_on(espi_config->clk_dev, (clock_control_subsys_t)&sccon);
90+
if (rc != 0) {
91+
return rc;
92+
}
93+
94+
port80_reg->ADDR = 0x80UL;
95+
port80_reg->CFG = PORT80_CFG_CLRFLG | PORT80_CFG_THREEN;
96+
port80_reg->INTEN = PORT80_INTEN_THREINTEN;
97+
98+
NVIC_ClearPendingIRQ(DT_IRQ_BY_NAME(DT_DRV_INST(0), port80, irq));
99+
100+
IRQ_CONNECT(DT_IRQ_BY_NAME(DT_DRV_INST(0), port80, irq),
101+
DT_IRQ_BY_NAME(DT_DRV_INST(0), port80, priority), espi_port80_isr,
102+
DEVICE_DT_GET(DT_DRV_INST(0)), 0);
103+
irq_enable(DT_IRQ_BY_NAME(DT_DRV_INST(0), port80, irq));
104+
105+
return 0;
106+
}
107+
108+
#endif /* CONFIG_ESPI_PERIPHERAL_DEBUG_PORT_80 */
109+
48110
/*
49111
* =========================================================================
50112
* ESPI VWIRE channel
@@ -1573,6 +1635,15 @@ static int espi_rts5912_init(const struct device *dev)
15731635
/* Setup eSPI bus reset */
15741636
espi_bus_reset_setup(dev);
15751637

1638+
#ifdef CONFIG_ESPI_PERIPHERAL_DEBUG_PORT_80
1639+
/* Setup Port80 */
1640+
rc = espi_peri_ch_port80_setup(dev);
1641+
if (rc != 0) {
1642+
LOG_ERR("eSPI Port80 setup failed");
1643+
goto exit;
1644+
}
1645+
#endif
1646+
15761647
#ifdef CONFIG_ESPI_VWIRE_CHANNEL
15771648
/* Setup eSPI virtual-wire channel */
15781649
espi_vw_ch_setup(dev);
@@ -1608,6 +1679,11 @@ static const struct espi_rts5912_config espi_rts5912_config = {
16081679
.espi_reg = (volatile struct espi_reg *const)DT_INST_REG_ADDR_BY_NAME(0, espi_target),
16091680
.espislv_clk_grp = DT_CLOCKS_CELL_BY_NAME(DT_DRV_INST(0), espi_target, clk_grp),
16101681
.espislv_clk_idx = DT_CLOCKS_CELL_BY_NAME(DT_DRV_INST(0), espi_target, clk_idx),
1682+
#ifdef CONFIG_ESPI_PERIPHERAL_DEBUG_PORT_80
1683+
.port80_reg = (volatile struct port80_reg *const)DT_INST_REG_ADDR_BY_NAME(0, port80),
1684+
.port80_clk_grp = DT_CLOCKS_CELL_BY_NAME(DT_DRV_INST(0), port80, clk_grp),
1685+
.port80_clk_idx = DT_CLOCKS_CELL_BY_NAME(DT_DRV_INST(0), port80, clk_idx),
1686+
#endif
16111687
.clk_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(0)),
16121688
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(0),
16131689
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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_PORT80_H
8+
#define ZEPHYR_SOC_REALTEK_RTS5912_REG_PORT80_H
9+
10+
struct port80_reg {
11+
const uint32_t STS;
12+
uint32_t CFG;
13+
uint32_t INTEN;
14+
uint32_t DATA;
15+
uint32_t ADDR;
16+
};
17+
18+
/* STS */
19+
#define PORT80_STS_FIFOEM BIT(0)
20+
#define PORT80_STS_FIFOFUL BIT(1)
21+
#define PORT80_STS_FIFOOVRN BIT(2)
22+
23+
/* CFG */
24+
#define PORT80_CFG_CLRFLG BIT(0)
25+
#define PORT80_CFG_THRE GENMASK(2, 1)
26+
#define PORT80_CFG_THREEN BIT(7)
27+
#define PORT80_CFG_UARTPASS BIT(8)
28+
29+
/* INTEN */
30+
#define PORT80_INTEN_THREINTEN BIT(0)
31+
32+
/* DATA */
33+
#define PORT80_DATA_DATA GENMASK(7, 0)
34+
35+
/* ADDR */
36+
#define PORT80_ADDR_ADDR GENMASK(7, 0)
37+
38+
#endif /* ZEPHYR_SOC_REALTEK_RTS5912_REG_PORT80_H */

0 commit comments

Comments
 (0)