Skip to content

Commit f796c26

Browse files
JasonLin-RealTeknordicjm
authored andcommitted
[nrf fromtree] driver: serial: Add UART driver initial version of RTS5912.
Add UART driver for Realtek RTS5912. Signed-off-by: Adam Kondraciuk <[email protected]> (cherry picked from commit a3c0b03) Signed-off-by: Lin Yu-Cheng <[email protected]>
1 parent 1a487ce commit f796c26

File tree

6 files changed

+139
-0
lines changed

6 files changed

+139
-0
lines changed

drivers/serial/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ zephyr_library_sources_ifdef(CONFIG_UART_RCAR uart_rcar.c)
6161
zephyr_library_sources_ifdef(CONFIG_UART_RENESAS_RA uart_renesas_ra.c)
6262
zephyr_library_sources_ifdef(CONFIG_UART_RENESAS_RZ_SCIF uart_renesas_rz_scif.c)
6363
zephyr_library_sources_ifdef(CONFIG_UART_RPI_PICO_PIO uart_rpi_pico_pio.c)
64+
zephyr_library_sources_ifdef(CONFIG_UART_RTS5912 uart_realtek_rts5912.c)
6465
zephyr_library_sources_ifdef(CONFIG_UART_RTT_DRIVER uart_rtt.c)
6566
zephyr_library_sources_ifdef(CONFIG_UART_RV32M1_LPUART uart_rv32m1_lpuart.c)
6667
zephyr_library_sources_ifdef(CONFIG_UART_RZT2M uart_rzt2m.c)

drivers/serial/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,6 @@ source "drivers/serial/Kconfig.si32"
230230

231231
source "drivers/serial/Kconfig.wch_usart"
232232

233+
source "drivers/serial/Kconfig.realtek_rts5912"
234+
233235
endif # SERIAL
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
#
3+
# Copyright (c) 2024 Realtek Semiconductor Corporation, SIBG-SD7
4+
#
5+
6+
config UART_RTS5912
7+
bool "UART driver for Realtek RTS5912 EC"
8+
default y if DT_HAS_REALTEK_RTS5912_UART_ENABLED
9+
select PINCTRL
10+
select CLOCK_CONTROL
11+
help
12+
This option enables the RTS5912 UART wrapper driver.
13+
14+
config UART_RTS5912_INIT_PRIORITY
15+
int "RTS5912 UART wrapper init priority"
16+
default 49
17+
depends on UART_RTS5912
18+
help
19+
Initialization priority for Realtek RTS5912 UART wrapper driver.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright (c) 2024 Realtek Semiconductor Corporation, SIBG-SD7
5+
* Author: Lin Yu-Cheng <[email protected]>
6+
*/
7+
8+
#define DT_DRV_COMPAT realtek_rts5912_uart
9+
10+
#include <zephyr/kernel.h>
11+
#include <zephyr/drivers/pinctrl.h>
12+
#include <zephyr/drivers/uart.h>
13+
#include <zephyr/drivers/gpio.h>
14+
#include <zephyr/drivers/clock_control.h>
15+
#include <zephyr/drivers/clock_control/clock_control_rts5912.h>
16+
#include <zephyr/logging/log.h>
17+
18+
LOG_MODULE_REGISTER(uart_rts5912, CONFIG_UART_LOG_LEVEL);
19+
20+
BUILD_ASSERT(CONFIG_UART_RTS5912_INIT_PRIORITY < CONFIG_SERIAL_INIT_PRIORITY,
21+
"The uart_realtek_rts5912 driver must be initialized before the uart_ns16550 driver");
22+
23+
/* device config */
24+
struct uart_rts5912_device_config {
25+
const struct pinctrl_dev_config *pcfg;
26+
const struct device *clk_dev;
27+
struct rts5912_sccon_subsys sccon_cfg;
28+
};
29+
30+
/** Device data structure */
31+
struct uart_rts5912_dev_data {
32+
};
33+
34+
static int rts5912_uart_init(const struct device *dev)
35+
{
36+
const struct uart_rts5912_device_config *const dev_cfg = dev->config;
37+
int rc;
38+
39+
if (!device_is_ready(dev_cfg->clk_dev)) {
40+
return -ENODEV;
41+
}
42+
43+
rc = clock_control_on(dev_cfg->clk_dev, (clock_control_subsys_t)&dev_cfg->sccon_cfg);
44+
if (rc != 0) {
45+
return rc;
46+
}
47+
48+
rc = pinctrl_apply_state(dev_cfg->pcfg, PINCTRL_STATE_DEFAULT);
49+
if (rc != 0) {
50+
return rc;
51+
}
52+
53+
return 0;
54+
}
55+
56+
#define UART_RTS5912_DEVICE_INIT(n) \
57+
PINCTRL_DT_INST_DEFINE(n); \
58+
\
59+
static const struct uart_rts5912_device_config uart_rts5912_dev_cfg_##n = { \
60+
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
61+
.clk_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(n)), \
62+
.sccon_cfg = \
63+
{ \
64+
.clk_grp = DT_INST_CLOCKS_CELL_BY_NAME(n, uart##n, clk_grp), \
65+
.clk_idx = DT_INST_CLOCKS_CELL_BY_NAME(n, uart##n, clk_idx), \
66+
}, \
67+
}; \
68+
\
69+
static struct uart_rts5912_dev_data uart_rts5912_dev_data_##n; \
70+
\
71+
DEVICE_DT_INST_DEFINE(n, &rts5912_uart_init, NULL, &uart_rts5912_dev_data_##n, \
72+
&uart_rts5912_dev_cfg_##n, PRE_KERNEL_1, \
73+
CONFIG_UART_RTS5912_INIT_PRIORITY, NULL);
74+
75+
DT_INST_FOREACH_STATUS_OKAY(UART_RTS5912_DEVICE_INIT)

dts/arm/realtek/ec/rts5912.dtsi

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,24 @@
9292
status = "okay";
9393
};
9494

95+
uart0: uart@40010100 {
96+
compatible = "ns16550";
97+
reg = <0x40010100 0x100>;
98+
reg-shift = <2>;
99+
clock-frequency = <25000000>;
100+
interrupts = <191 0>;
101+
status = "disabled";
102+
};
103+
104+
uart0_wrapper: uart_wrapper@40010200 {
105+
compatible = "realtek,rts5912-uart";
106+
reg = <0x40010200 0x0020>;
107+
port = <0>;
108+
clocks = <&sccon RTS5912_SCCON_UART UART0_CLKPWR>;
109+
clock-names = "uart0";
110+
status = "disabled";
111+
};
112+
95113
pinctrl: pin-controller@40090000 {
96114
compatible = "realtek,rts5912-pinctrl";
97115
#address-cells = <1>;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
#
3+
# Copyright (c) 2024 Realtek Semiconductor Corporation, SIBG-SD7
4+
#
5+
6+
description: Realtek RTS5912 UART
7+
8+
compatible: "realtek,rts5912-uart"
9+
10+
include: [uart-controller.yaml, pinctrl-device.yaml]
11+
12+
properties:
13+
reg:
14+
required: true
15+
16+
port:
17+
type: int
18+
required: true
19+
20+
pinctrl-0:
21+
required: true
22+
23+
pinctrl-names:
24+
required: true

0 commit comments

Comments
 (0)