driver: serial: Add UART driver initial version of RTS5912.
Add UART driver for Realtek RTS5912. Signed-off-by: Lin Yu-Cheng <lin_yu_cheng@realtek.com>
This commit is contained in:
parent
2656029c3a
commit
a3c0b03915
6 changed files with 139 additions and 0 deletions
|
@ -61,6 +61,7 @@ zephyr_library_sources_ifdef(CONFIG_UART_RCAR uart_rcar.c)
|
|||
zephyr_library_sources_ifdef(CONFIG_UART_RENESAS_RA uart_renesas_ra.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_UART_RENESAS_RZ_SCIF uart_renesas_rz_scif.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_UART_RPI_PICO_PIO uart_rpi_pico_pio.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_UART_RTS5912 uart_realtek_rts5912.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_UART_RTT_DRIVER uart_rtt.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_UART_RV32M1_LPUART uart_rv32m1_lpuart.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_UART_RZT2M uart_rzt2m.c)
|
||||
|
|
|
@ -230,4 +230,6 @@ source "drivers/serial/Kconfig.si32"
|
|||
|
||||
source "drivers/serial/Kconfig.wch_usart"
|
||||
|
||||
source "drivers/serial/Kconfig.realtek_rts5912"
|
||||
|
||||
endif # SERIAL
|
||||
|
|
19
drivers/serial/Kconfig.realtek_rts5912
Normal file
19
drivers/serial/Kconfig.realtek_rts5912
Normal file
|
@ -0,0 +1,19 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Copyright (c) 2024 Realtek Semiconductor Corporation, SIBG-SD7
|
||||
#
|
||||
|
||||
config UART_RTS5912
|
||||
bool "UART driver for Realtek RTS5912 EC"
|
||||
default y if DT_HAS_REALTEK_RTS5912_UART_ENABLED
|
||||
select PINCTRL
|
||||
select CLOCK_CONTROL
|
||||
help
|
||||
This option enables the RTS5912 UART wrapper driver.
|
||||
|
||||
config UART_RTS5912_INIT_PRIORITY
|
||||
int "RTS5912 UART wrapper init priority"
|
||||
default 49
|
||||
depends on UART_RTS5912
|
||||
help
|
||||
Initialization priority for Realtek RTS5912 UART wrapper driver.
|
75
drivers/serial/uart_realtek_rts5912.c
Normal file
75
drivers/serial/uart_realtek_rts5912.c
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Copyright (c) 2024 Realtek Semiconductor Corporation, SIBG-SD7
|
||||
* Author: Lin Yu-Cheng <lin_yu_cheng@realtek.com>
|
||||
*/
|
||||
|
||||
#define DT_DRV_COMPAT realtek_rts5912_uart
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/drivers/pinctrl.h>
|
||||
#include <zephyr/drivers/uart.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
#include <zephyr/drivers/clock_control.h>
|
||||
#include <zephyr/drivers/clock_control/clock_control_rts5912.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
LOG_MODULE_REGISTER(uart_rts5912, CONFIG_UART_LOG_LEVEL);
|
||||
|
||||
BUILD_ASSERT(CONFIG_UART_RTS5912_INIT_PRIORITY < CONFIG_SERIAL_INIT_PRIORITY,
|
||||
"The uart_realtek_rts5912 driver must be initialized before the uart_ns16550 driver");
|
||||
|
||||
/* device config */
|
||||
struct uart_rts5912_device_config {
|
||||
const struct pinctrl_dev_config *pcfg;
|
||||
const struct device *clk_dev;
|
||||
struct rts5912_sccon_subsys sccon_cfg;
|
||||
};
|
||||
|
||||
/** Device data structure */
|
||||
struct uart_rts5912_dev_data {
|
||||
};
|
||||
|
||||
static int rts5912_uart_init(const struct device *dev)
|
||||
{
|
||||
const struct uart_rts5912_device_config *const dev_cfg = dev->config;
|
||||
int rc;
|
||||
|
||||
if (!device_is_ready(dev_cfg->clk_dev)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
rc = clock_control_on(dev_cfg->clk_dev, (clock_control_subsys_t)&dev_cfg->sccon_cfg);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = pinctrl_apply_state(dev_cfg->pcfg, PINCTRL_STATE_DEFAULT);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define UART_RTS5912_DEVICE_INIT(n) \
|
||||
PINCTRL_DT_INST_DEFINE(n); \
|
||||
\
|
||||
static const struct uart_rts5912_device_config uart_rts5912_dev_cfg_##n = { \
|
||||
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
|
||||
.clk_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(n)), \
|
||||
.sccon_cfg = \
|
||||
{ \
|
||||
.clk_grp = DT_INST_CLOCKS_CELL_BY_NAME(n, uart##n, clk_grp), \
|
||||
.clk_idx = DT_INST_CLOCKS_CELL_BY_NAME(n, uart##n, clk_idx), \
|
||||
}, \
|
||||
}; \
|
||||
\
|
||||
static struct uart_rts5912_dev_data uart_rts5912_dev_data_##n; \
|
||||
\
|
||||
DEVICE_DT_INST_DEFINE(n, &rts5912_uart_init, NULL, &uart_rts5912_dev_data_##n, \
|
||||
&uart_rts5912_dev_cfg_##n, PRE_KERNEL_1, \
|
||||
CONFIG_UART_RTS5912_INIT_PRIORITY, NULL);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(UART_RTS5912_DEVICE_INIT)
|
|
@ -92,6 +92,24 @@
|
|||
status = "okay";
|
||||
};
|
||||
|
||||
uart0: uart@40010100 {
|
||||
compatible = "ns16550";
|
||||
reg = <0x40010100 0x100>;
|
||||
reg-shift = <2>;
|
||||
clock-frequency = <25000000>;
|
||||
interrupts = <191 0>;
|
||||
status = "disabled";
|
||||
};
|
||||
|
||||
uart0_wrapper: uart_wrapper@40010200 {
|
||||
compatible = "realtek,rts5912-uart";
|
||||
reg = <0x40010200 0x0020>;
|
||||
port = <0>;
|
||||
clocks = <&sccon RTS5912_SCCON_UART UART0_CLKPWR>;
|
||||
clock-names = "uart0";
|
||||
status = "disabled";
|
||||
};
|
||||
|
||||
pinctrl: pin-controller@40090000 {
|
||||
compatible = "realtek,rts5912-pinctrl";
|
||||
#address-cells = <1>;
|
||||
|
|
24
dts/bindings/serial/realtek,rts5912-uart.yaml
Normal file
24
dts/bindings/serial/realtek,rts5912-uart.yaml
Normal file
|
@ -0,0 +1,24 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Copyright (c) 2024 Realtek Semiconductor Corporation, SIBG-SD7
|
||||
#
|
||||
|
||||
description: Realtek RTS5912 UART
|
||||
|
||||
compatible: "realtek,rts5912-uart"
|
||||
|
||||
include: [uart-controller.yaml, pinctrl-device.yaml]
|
||||
|
||||
properties:
|
||||
reg:
|
||||
required: true
|
||||
|
||||
port:
|
||||
type: int
|
||||
required: true
|
||||
|
||||
pinctrl-0:
|
||||
required: true
|
||||
|
||||
pinctrl-names:
|
||||
required: true
|
Loading…
Add table
Add a link
Reference in a new issue