drivers: serial: add RZT2M uart driver
This adds a UART driver for the Renesas RZ/T2M Serial Communication Interface. The driver implements: * Polling API, * Interrupt-driven API. Signed-off-by: Wojciech Sipak <wsipak@antmicro.com>
This commit is contained in:
parent
b1c83c0335
commit
4e35d0e354
9 changed files with 639 additions and 0 deletions
|
|
@ -13,5 +13,15 @@
|
|||
|
||||
chosen {
|
||||
zephyr,sram = &cpu0_atcm;
|
||||
zephyr,console = &uart0;
|
||||
zephyr,shell-uart = &uart0;
|
||||
};
|
||||
};
|
||||
|
||||
&uart0 {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&uart3 {
|
||||
status = "okay";
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,3 +3,8 @@
|
|||
|
||||
CONFIG_SOC_RENESAS_RZT2M=y
|
||||
CONFIG_BOARD_RZT2M_STARTER_KIT=y
|
||||
|
||||
CONFIG_SERIAL=y
|
||||
CONFIG_CONSOLE=y
|
||||
CONFIG_UART_CONSOLE=y
|
||||
CONFIG_UART_INTERRUPT_DRIVEN=y
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ zephyr_library_sources_ifdef(CONFIG_UART_SEDI uart_sedi.c)
|
|||
zephyr_library_sources_ifdef(CONFIG_UART_BCM2711_MU uart_bcm2711.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_UART_INTEL_LW uart_intel_lw.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_UART_RA uart_ra.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_UART_RZT2M uart_rzt2m.c)
|
||||
|
||||
zephyr_library_sources_ifdef(CONFIG_USERSPACE uart_handlers.c)
|
||||
|
||||
|
|
|
|||
|
|
@ -255,4 +255,6 @@ source "drivers/serial/Kconfig.intel_lw"
|
|||
|
||||
source "drivers/serial/Kconfig.ra"
|
||||
|
||||
source "drivers/serial/Kconfig.rzt2m"
|
||||
|
||||
endif # SERIAL
|
||||
|
|
|
|||
11
drivers/serial/Kconfig.rzt2m
Normal file
11
drivers/serial/Kconfig.rzt2m
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# Copyright (c) 2023 Antmicro <www.antmicro.com>
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config UART_RZT2M
|
||||
bool "Renesas RZ/T2M UART Driver"
|
||||
default y
|
||||
depends on DT_HAS_RENESAS_RZT2M_UART_ENABLED
|
||||
select SERIAL_HAS_DRIVER
|
||||
select SERIAL_SUPPORT_INTERRUPT
|
||||
help
|
||||
Enable Renesas RZ/T2M UART Driver.
|
||||
435
drivers/serial/uart_rzt2m.c
Normal file
435
drivers/serial/uart_rzt2m.c
Normal file
|
|
@ -0,0 +1,435 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Antmicro <www.antmicro.com>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "uart_rzt2m.h"
|
||||
#include "zephyr/spinlock.h"
|
||||
#include "zephyr/sys/printk.h"
|
||||
#include <zephyr/drivers/uart.h>
|
||||
#include <zephyr/sys/util.h>
|
||||
#include <zephyr/irq.h>
|
||||
#include <stdint.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <soc.h>
|
||||
|
||||
#define DT_DRV_COMPAT renesas_rzt2m_uart
|
||||
|
||||
LOG_MODULE_REGISTER(uart_renesas_rzt2m, CONFIG_UART_LOG_LEVEL);
|
||||
|
||||
struct rzt2m_device_config {
|
||||
mm_reg_t base;
|
||||
uart_irq_config_func_t irq_config_func;
|
||||
};
|
||||
|
||||
struct rzt2m_device_data {
|
||||
struct uart_config uart_cfg;
|
||||
struct k_spinlock lock;
|
||||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
||||
uart_irq_callback_user_data_t callback;
|
||||
void *callback_data;
|
||||
#endif
|
||||
};
|
||||
|
||||
static int rzt2m_poll_in(const struct device *dev, unsigned char *c)
|
||||
{
|
||||
if (!dev || !dev->config || !dev->data) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
const struct rzt2m_device_config *config = dev->config;
|
||||
struct rzt2m_device_data *data = dev->data;
|
||||
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
|
||||
if (FRSR_R(*FRSR(config->base)) == 0) {
|
||||
k_spin_unlock(&data->lock, key);
|
||||
return -1;
|
||||
}
|
||||
*c = *RDR(config->base) & RDR_MASK_RDAT;
|
||||
*CFCLR(config->base) |= CFCLR_MASK_RDRFC;
|
||||
|
||||
if (FRSR_R(*FRSR(config->base)) == 0) {
|
||||
*FFCLR(config->base) |= FFCLR_MASK_DRC;
|
||||
}
|
||||
|
||||
k_spin_unlock(&data->lock, key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void rzt2m_poll_out(const struct device *dev, unsigned char c)
|
||||
{
|
||||
if (!dev || !dev->config || !dev->data) {
|
||||
return;
|
||||
}
|
||||
|
||||
const struct rzt2m_device_config *config = dev->config;
|
||||
struct rzt2m_device_data *data = dev->data;
|
||||
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
|
||||
int fifo_count = FTSR_T(*FTSR(config->base));
|
||||
|
||||
while (fifo_count == MAX_FIFO_DEPTH) {
|
||||
fifo_count = FTSR_T(*FTSR(config->base));
|
||||
}
|
||||
|
||||
*TDR(config->base) = c;
|
||||
|
||||
/* Clear `Transmit data empty flag`. */
|
||||
*CFCLR(config->base) |= CFCLR_MASK_TDREC;
|
||||
|
||||
k_spin_unlock(&data->lock, key);
|
||||
}
|
||||
|
||||
static int rzt2m_err_check(const struct device *dev)
|
||||
{
|
||||
const struct rzt2m_device_config *config = dev->config;
|
||||
|
||||
uint32_t status = *CSR(config->base);
|
||||
uint32_t retval = 0;
|
||||
|
||||
if (status & CSR_MASK_ORER) {
|
||||
retval |= UART_ERROR_OVERRUN;
|
||||
}
|
||||
if (status & CSR_MASK_FER) {
|
||||
retval |= UART_ERROR_FRAMING;
|
||||
}
|
||||
if (status & CSR_MASK_PER) {
|
||||
retval |= UART_ERROR_PARITY;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
||||
static int uart_rzt2m_irq_tx_ready(const struct device *dev);
|
||||
|
||||
static int rzt2m_fifo_fill(const struct device *dev, const uint8_t *tx_data, int size)
|
||||
{
|
||||
struct rzt2m_device_data *data = dev->data;
|
||||
const struct rzt2m_device_config *config = dev->config;
|
||||
int num_tx = 0;
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
|
||||
while ((size - num_tx > 0) && uart_rzt2m_irq_tx_ready(dev)) {
|
||||
*TDR(config->base) = (uint8_t)tx_data[num_tx++];
|
||||
}
|
||||
|
||||
k_spin_unlock(&data->lock, key);
|
||||
return num_tx;
|
||||
}
|
||||
|
||||
static int rzt2m_fifo_read(const struct device *dev, uint8_t *rx_data, const int size)
|
||||
{
|
||||
struct rzt2m_device_data *data = dev->data;
|
||||
const struct rzt2m_device_config *config = dev->config;
|
||||
int num_rx = 0;
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
|
||||
while (num_rx < size && (FRSR_R(*FRSR(config->base)))) {
|
||||
rx_data[num_rx++] = *RDR(config->base);
|
||||
}
|
||||
*CFCLR(config->base) = CFCLR_MASK_RDRFC;
|
||||
*FFCLR(config->base) = FFCLR_MASK_DRC;
|
||||
k_spin_unlock(&data->lock, key);
|
||||
return num_rx;
|
||||
}
|
||||
|
||||
static void uart_rzt2m_irq_rx_enable(const struct device *dev)
|
||||
{
|
||||
const struct rzt2m_device_config *config = dev->config;
|
||||
*CCR0(config->base) |= CCR0_MASK_RIE | CCR0_MASK_RE;
|
||||
}
|
||||
|
||||
static void uart_rzt2m_irq_rx_disable(const struct device *dev)
|
||||
{
|
||||
const struct rzt2m_device_config *config = dev->config;
|
||||
*CCR0(config->base) &= ~CCR0_MASK_RIE;
|
||||
}
|
||||
|
||||
static void uart_rzt2m_irq_tx_enable(const struct device *dev)
|
||||
{
|
||||
const struct rzt2m_device_config *config = dev->config;
|
||||
/* These bits must be set simultaneously. */
|
||||
*CCR0(config->base) |= CCR0_MASK_TE | CCR0_MASK_TIE | CCR0_MASK_TEIE;
|
||||
}
|
||||
|
||||
static void uart_rzt2m_irq_tx_disable(const struct device *dev)
|
||||
{
|
||||
const struct rzt2m_device_config *config = dev->config;
|
||||
*CCR0(config->base) &= ~(CCR0_MASK_TIE | CCR0_MASK_TEIE);
|
||||
}
|
||||
|
||||
static int uart_rzt2m_irq_tx_ready(const struct device *dev)
|
||||
{
|
||||
const struct rzt2m_device_config *config = dev->config;
|
||||
|
||||
if (FTSR_T(*FTSR(config->base)) == MAX_FIFO_DEPTH ||
|
||||
((*CCR0(config->base) & CCR0_MASK_TIE) == 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int uart_rzt2m_irq_rx_ready(const struct device *dev)
|
||||
{
|
||||
const struct rzt2m_device_config *config = dev->config;
|
||||
|
||||
if (FRSR_R(*FRSR(config->base))) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uart_rzt2m_irq_is_pending(const struct device *dev)
|
||||
{
|
||||
const struct rzt2m_device_config *config = dev->config;
|
||||
|
||||
if ((*CSR(config->base) & (CSR_MASK_RDRF)) || (*FRSR(config->base) & FRSR_MASK_DR)) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void uart_rzt2m_irq_callback_set(const struct device *dev, uart_irq_callback_user_data_t cb,
|
||||
void *cb_data)
|
||||
{
|
||||
struct rzt2m_device_data *data = dev->data;
|
||||
|
||||
data->callback = cb;
|
||||
data->callback_data = cb_data;
|
||||
}
|
||||
|
||||
static int uart_rzt2m_irq_update(const struct device *dev)
|
||||
{
|
||||
const struct rzt2m_device_config *config = dev->config;
|
||||
|
||||
*CFCLR(config->base) = CFCLR_MASK_RDRFC;
|
||||
*FFCLR(config->base) = FFCLR_MASK_DRC;
|
||||
return 1;
|
||||
}
|
||||
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
||||
|
||||
static const struct uart_driver_api rzt2m_uart_api = {
|
||||
.poll_in = rzt2m_poll_in,
|
||||
.poll_out = rzt2m_poll_out,
|
||||
.err_check = rzt2m_err_check,
|
||||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
||||
.fifo_fill = rzt2m_fifo_fill,
|
||||
.fifo_read = rzt2m_fifo_read,
|
||||
.irq_rx_enable = uart_rzt2m_irq_rx_enable,
|
||||
.irq_rx_disable = uart_rzt2m_irq_rx_disable,
|
||||
.irq_tx_enable = uart_rzt2m_irq_tx_enable,
|
||||
.irq_tx_disable = uart_rzt2m_irq_tx_disable,
|
||||
.irq_tx_ready = uart_rzt2m_irq_tx_ready,
|
||||
.irq_rx_ready = uart_rzt2m_irq_rx_ready,
|
||||
.irq_is_pending = uart_rzt2m_irq_is_pending,
|
||||
.irq_callback_set = uart_rzt2m_irq_callback_set,
|
||||
.irq_update = uart_rzt2m_irq_update,
|
||||
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
||||
};
|
||||
|
||||
static int rzt2m_module_start(const struct device *dev)
|
||||
{
|
||||
if (!dev || !dev->config || !dev->data) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
const struct rzt2m_device_config *config = dev->config;
|
||||
struct rzt2m_device_data *data = dev->data;
|
||||
int interface_id = BASE_TO_IFACE_ID(config->base);
|
||||
unsigned int irqkey = irq_lock();
|
||||
volatile uint32_t dummy;
|
||||
|
||||
k_spinlock_key_t key = k_spin_lock(&data->lock);
|
||||
|
||||
if (interface_id < 5) {
|
||||
/* Dummy-read at least one time as stated in 8.3.1 of the User's Manual: Hardware */
|
||||
*MSTPCRA &= ~(MSTPCRA_MASK_SCIx(interface_id));
|
||||
dummy = *MSTPCRA;
|
||||
} else {
|
||||
LOG_ERR("SCI modules in the secure domain on RZT2M are not supported.");
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
/* Dummy-read at least five times as stated in 8.3.1 of the User's Manual: Hardware */
|
||||
dummy = *RDR(config->base);
|
||||
dummy = *RDR(config->base);
|
||||
dummy = *RDR(config->base);
|
||||
dummy = *RDR(config->base);
|
||||
dummy = *RDR(config->base);
|
||||
|
||||
k_spin_unlock(&data->lock, key);
|
||||
irq_unlock(irqkey);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rzt2m_uart_init(const struct device *dev)
|
||||
{
|
||||
const struct rzt2m_device_config *config = dev->config;
|
||||
struct rzt2m_device_data *data = dev->data;
|
||||
uint32_t baud_setting = 0;
|
||||
uint32_t baud_settings[] = {CCR2_BAUD_SETTING_9600, CCR2_BAUD_SETTING_115200};
|
||||
|
||||
rzt2m_unlock_prcrs(PRCRS_GPIO);
|
||||
rzt2m_unlock_prcrn(PRCRN_PRC1 | PRCRN_PRC2);
|
||||
|
||||
/* The module needs to be started
|
||||
* to allow any operation on the registers of Serial Communications Interface.
|
||||
*/
|
||||
int ret = rzt2m_module_start(dev);
|
||||
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Disable transmitter, receiver, interrupts. */
|
||||
*CCR0(config->base) = CCR0_DEFAULT_VALUE;
|
||||
while (*CCR0(config->base) & (CCR0_MASK_RE | CCR0_MASK_TE)) {
|
||||
}
|
||||
|
||||
*CCR1(config->base) = CCR1_DEFAULT_VALUE;
|
||||
*CCR2(config->base) = CCR2_DEFAULT_VALUE;
|
||||
*CCR3(config->base) = CCR3_DEFAULT_VALUE;
|
||||
*CCR4(config->base) = CCR4_DEFAULT_VALUE;
|
||||
|
||||
*CFCLR(config->base) = CFCLR_ALL_FLAG_CLEAR;
|
||||
*FFCLR(config->base) = FFCLR_MASK_DRC;
|
||||
|
||||
/* Use FIFO mode. */
|
||||
*CCR3(config->base) |= (CCR3_MASK_FM);
|
||||
|
||||
switch (data->uart_cfg.stop_bits) {
|
||||
case UART_CFG_STOP_BITS_1:
|
||||
/* Default value, already set. */
|
||||
break;
|
||||
case UART_CFG_STOP_BITS_2:
|
||||
*CCR3(config->base) |= CCR3_MASK_STP;
|
||||
break;
|
||||
default:
|
||||
LOG_ERR("Selected bit stop length is not supported: %u.", data->uart_cfg.stop_bits);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
switch (data->uart_cfg.data_bits) {
|
||||
case UART_CFG_DATA_BITS_7:
|
||||
*CCR3(config->base) |= CCR3_CHR_7BIT;
|
||||
break;
|
||||
case UART_CFG_DATA_BITS_8:
|
||||
*CCR3(config->base) |= CCR3_CHR_8BIT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERR("Selected number of data bits is not supported: %u.",
|
||||
data->uart_cfg.data_bits);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if (data->uart_cfg.baudrate > ARRAY_SIZE(baud_settings)) {
|
||||
LOG_ERR("Selected baudrate variant is not supported: %u.", data->uart_cfg.baudrate);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
baud_setting = baud_settings[data->uart_cfg.baudrate];
|
||||
|
||||
*CCR2(config->base) &= ~(CCR2_MASK_BAUD_SETTING);
|
||||
*CCR2(config->base) |= (baud_setting & CCR2_MASK_BAUD_SETTING);
|
||||
|
||||
*CCR1(config->base) |= (CCR1_MASK_NFEN | CCR1_MASK_SPB2DT | CCR1_MASK_SPB2IO);
|
||||
|
||||
switch (data->uart_cfg.parity) {
|
||||
case UART_CFG_PARITY_NONE:
|
||||
/* Default value, already set. */
|
||||
break;
|
||||
case UART_CFG_PARITY_EVEN:
|
||||
*CCR1(config->base) |= CCR1_MASK_PE;
|
||||
break;
|
||||
case UART_CFG_PARITY_ODD:
|
||||
*CCR1(config->base) |= (CCR1_MASK_PE | CCR1_MASK_PM);
|
||||
break;
|
||||
default:
|
||||
LOG_ERR("Unsupported parity: %u", data->uart_cfg.parity);
|
||||
}
|
||||
|
||||
/* Specify trigger thresholds and clear FIFOs. */
|
||||
*FCR(config->base) = FCR_MASK_TFRST | FCR_MASK_RFRST | FCR_TTRG_15 | FCR_RTRG_15;
|
||||
|
||||
/* Enable the clock. */
|
||||
*CCR3(config->base) &= ~CCR3_MASK_CKE;
|
||||
*CCR3(config->base) |= CCR3_CKE_ENABLE;
|
||||
|
||||
/* Clear status flags. */
|
||||
*CFCLR(config->base) = CFCLR_ALL_FLAG_CLEAR;
|
||||
*FFCLR(config->base) = FFCLR_MASK_DRC;
|
||||
|
||||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
||||
config->irq_config_func(dev);
|
||||
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
||||
|
||||
/* Start trasmitter and receiver. */
|
||||
*CCR0(config->base) |= (CCR0_MASK_TE | CCR0_MASK_RE);
|
||||
while (!(*CCR0(config->base) & CCR0_MASK_RE)) {
|
||||
}
|
||||
while (!(*CCR0(config->base) & CCR0_MASK_TE)) {
|
||||
}
|
||||
|
||||
rzt2m_lock_prcrs(PRCRS_GPIO);
|
||||
rzt2m_lock_prcrn(PRCRN_PRC1 | PRCRN_PRC2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void uart_rzt2m_isr(const struct device *dev)
|
||||
{
|
||||
const struct rzt2m_device_config *config = dev->config;
|
||||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
||||
struct rzt2m_device_data *data = dev->data;
|
||||
|
||||
if (data->callback) {
|
||||
data->callback(dev, data->callback_data);
|
||||
}
|
||||
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
||||
|
||||
*CFCLR(config->base) = CFCLR_MASK_RDRFC;
|
||||
*FFCLR(config->base) = FFCLR_MASK_DRC;
|
||||
}
|
||||
|
||||
#define UART_RZT2M_IRQ_CONNECT(n, irq_name) \
|
||||
do { \
|
||||
IRQ_CONNECT(DT_INST_IRQ_BY_NAME(n, irq_name, irq), \
|
||||
DT_INST_IRQ_BY_NAME(n, irq_name, priority), uart_rzt2m_isr, \
|
||||
DEVICE_DT_INST_GET(n), DT_INST_IRQ_BY_NAME(n, irq_name, flags)); \
|
||||
irq_enable(DT_INST_IRQ_BY_NAME(n, irq_name, irq)); \
|
||||
} while (false)
|
||||
|
||||
#define UART_RZT2M_CONFIG_FUNC(n) \
|
||||
static void uart##n##_rzt2m_irq_config(const struct device *port) \
|
||||
{ \
|
||||
UART_RZT2M_IRQ_CONNECT(n, rx_err); \
|
||||
UART_RZT2M_IRQ_CONNECT(n, rx); \
|
||||
UART_RZT2M_IRQ_CONNECT(n, tx); \
|
||||
UART_RZT2M_IRQ_CONNECT(n, tx_end); \
|
||||
}
|
||||
|
||||
#define UART_RZT2M_INIT(n) \
|
||||
static struct rzt2m_device_data rzt2m_uart_##n##data = { \
|
||||
.uart_cfg = \
|
||||
{ \
|
||||
.baudrate = DT_INST_ENUM_IDX(n, current_speed), \
|
||||
.parity = DT_INST_ENUM_IDX_OR(n, parity, UART_CFG_PARITY_NONE), \
|
||||
.stop_bits = \
|
||||
DT_INST_ENUM_IDX_OR(n, stop_bits, UART_CFG_STOP_BITS_1), \
|
||||
.data_bits = \
|
||||
DT_INST_ENUM_IDX_OR(n, data_bits, UART_CFG_DATA_BITS_8), \
|
||||
}, \
|
||||
}; \
|
||||
UART_RZT2M_CONFIG_FUNC(n); \
|
||||
static const struct rzt2m_device_config rzt2m_uart_##n##_config = { \
|
||||
.base = DT_INST_REG_ADDR(n), .irq_config_func = uart##n##_rzt2m_irq_config}; \
|
||||
DEVICE_DT_INST_DEFINE(n, &rzt2m_uart_init, NULL, &rzt2m_uart_##n##data, \
|
||||
&rzt2m_uart_##n##_config, PRE_KERNEL_1, CONFIG_SERIAL_INIT_PRIORITY, \
|
||||
&rzt2m_uart_api);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(UART_RZT2M_INIT)
|
||||
124
drivers/serial/uart_rzt2m.h
Normal file
124
drivers/serial/uart_rzt2m.h
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Antmicro <www.antmicro.com>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_DRIVERS_SERIAL_UART_RZT2M_H_
|
||||
#define ZEPHYR_DRIVERS_SERIAL_UART_RZT2M_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define MAX_FIFO_DEPTH 16
|
||||
|
||||
#define RDR(base) ((volatile uint32_t *)(base))
|
||||
#define TDR(base) ((volatile uint32_t *)(base + 0x04))
|
||||
#define CCR0(base) ((volatile uint32_t *)(base + 0x08))
|
||||
#define CCR1(base) ((volatile uint32_t *)(base + 0x0c))
|
||||
#define CCR2(base) ((volatile uint32_t *)(base + 0x10))
|
||||
#define CCR3(base) ((volatile uint32_t *)(base + 0x14))
|
||||
#define CCR4(base) ((volatile uint32_t *)(base + 0x18))
|
||||
#define FCR(base) ((volatile uint32_t *)(base + 0x24))
|
||||
#define CSR(base) ((volatile uint32_t *)(base + 0x48))
|
||||
#define FRSR(base) ((volatile uint32_t *)(base + 0x50))
|
||||
#define FTSR(base) ((volatile uint32_t *)(base + 0x54))
|
||||
#define CFCLR(base) ((volatile uint32_t *)(base + 0x68))
|
||||
#define FFCLR(base) ((volatile uint32_t *)(base + 0x70))
|
||||
|
||||
#define CCR0_DEFAULT_VALUE 0x0
|
||||
#define CCR1_DEFAULT_VALUE 0x00000010
|
||||
#define CCR2_DEFAULT_VALUE 0xff00ff04
|
||||
#define CCR3_DEFAULT_VALUE 0x00001203
|
||||
#define CCR4_DEFAULT_VALUE 0x0
|
||||
|
||||
#define RDR_MASK_RDAT GENMASK(8, 0)
|
||||
|
||||
#define CCR0_MASK_RE BIT(0)
|
||||
#define CCR0_MASK_TE BIT(4)
|
||||
#define CCR0_MASK_DCME BIT(9)
|
||||
#define CCR0_MASK_IDSEL BIT(10)
|
||||
#define CCR0_MASK_RIE BIT(16)
|
||||
#define CCR0_MASK_TIE BIT(20)
|
||||
#define CCR0_MASK_TEIE BIT(21)
|
||||
#define CCR0_MASK_SSE BIT(24)
|
||||
|
||||
#define CCR1_MASK_CTSE BIT(0)
|
||||
#define CCR1_MASK_SPB2DT BIT(4)
|
||||
#define CCR1_MASK_SPB2IO BIT(5)
|
||||
#define CCR1_MASK_PE BIT(8)
|
||||
#define CCR1_MASK_PM BIT(9)
|
||||
#define CCR1_MASK_NFEN BIT(28)
|
||||
|
||||
#define CCR2_MASK_BGDM BIT(4)
|
||||
#define CCR2_MASK_ABCS BIT(5)
|
||||
#define CCR2_MASK_ABCSE BIT(6)
|
||||
#define CCR2_MASK_BRR GENMASK(15, 8)
|
||||
#define CCR2_MASK_BRME BIT(16)
|
||||
#define CCR2_MASK_CKS GENMASK(21, 20)
|
||||
#define CCR2_MASK_MDDR GENMASK(31, 24)
|
||||
#define CCR2_MASK_BAUD_SETTING \
|
||||
(CCR2_MASK_BRME | CCR2_MASK_ABCSE | CCR2_MASK_ABCS | CCR2_MASK_BGDM | CCR2_MASK_CKS | \
|
||||
CCR2_MASK_BRR | CCR2_MASK_MDDR)
|
||||
|
||||
#define CCR3_MASK_STP BIT(14)
|
||||
#define CCR3_MASK_MP BIT(19)
|
||||
#define CCR3_MASK_FM BIT(20)
|
||||
#define CCR3_MASK_CKE (BIT(24) | BIT(25))
|
||||
#define CCR3_CKE_ENABLE BIT(24)
|
||||
#define CCR3_CHR_7BIT (BIT(8) | BIT(9))
|
||||
#define CCR3_CHR_8BIT BIT(9)
|
||||
|
||||
#define CCR4_MASK_ASEN BIT(16)
|
||||
#define CCR4_MASK_ATEN BIT(17)
|
||||
|
||||
#define FCR_MASK_TFRST BIT(15)
|
||||
#define FCR_MASK_RFRST BIT(23)
|
||||
#define FCR_MASK_TTRG GENMASK(12, 8)
|
||||
#define FCR_MASK_RTRG GENMASK(20, 16)
|
||||
#define FCR_TTRG_15 (15 << 8)
|
||||
#define FCR_RTRG_15 (15 << 16)
|
||||
|
||||
#define CSR_MASK_ORER BIT(24)
|
||||
#define CSR_MASK_PER BIT(27)
|
||||
#define CSR_MASK_FER BIT(28)
|
||||
#define CSR_MASK_TDRE BIT(29)
|
||||
#define CSR_MASK_TEND BIT(30)
|
||||
#define CSR_MASK_RDRF BIT(31)
|
||||
|
||||
#define FRSR_MASK_DR BIT(0)
|
||||
#define FRSR_R(val) ((val >> 7) & 0x3f)
|
||||
|
||||
#define FTSR_T(val) (val & 0x3f)
|
||||
|
||||
#define CFCLR_MASK_ERSC BIT(4)
|
||||
#define CFCLR_MASK_DCMFC BIT(16)
|
||||
#define CFCLR_MASK_DPERC BIT(17)
|
||||
#define CFCLR_MASK_DFERC BIT(18)
|
||||
#define CFCLR_MASK_ORERC BIT(24)
|
||||
#define CFCLR_MASK_MFFC BIT(26)
|
||||
#define CFCLR_MASK_PERC BIT(27)
|
||||
#define CFCLR_MASK_FERC BIT(28)
|
||||
#define CFCLR_MASK_TDREC BIT(29)
|
||||
#define CFCLR_MASK_RDRFC BIT(31)
|
||||
#define CFCLR_ALL_FLAG_CLEAR \
|
||||
(CFCLR_MASK_ERSC | CFCLR_MASK_DCMFC | CFCLR_MASK_DPERC | CFCLR_MASK_DFERC | \
|
||||
CFCLR_MASK_ORERC | CFCLR_MASK_MFFC | CFCLR_MASK_PERC | CFCLR_MASK_FERC | \
|
||||
CFCLR_MASK_TDREC | CFCLR_MASK_RDRFC)
|
||||
|
||||
#define FFCLR_MASK_DRC BIT(0)
|
||||
|
||||
#define MSTPCRA (volatile uint32_t *)(0x80280000 + 0x300)
|
||||
#define MSTPCRA_MASK_SCIx(x) BIT(x + 8)
|
||||
#define BASE_TO_IFACE_ID(base) ((base & 0x1000000) ? 5 : ((base & 0xff00) >> 10) - 4)
|
||||
|
||||
#define CCR2_MDDR_128 BIT(31)
|
||||
#define CCR2_CKS_0 0
|
||||
#define CCR2_BRME_0 0
|
||||
#define CCR2_BRR_243 (0xf3 << 8)
|
||||
#define CCR2_BRR_39 (0x27 << 8)
|
||||
#define CCR2_BGDM_1 BIT(4)
|
||||
|
||||
#define CCR2_BAUD_SETTING_9600 (CCR2_MDDR_128 | CCR2_BRR_243)
|
||||
#define CCR2_BAUD_SETTING_115200 (CCR2_MDDR_128 | CCR2_BRR_39 | CCR2_BGDM_1)
|
||||
|
||||
#endif /* ZEPHYR_DRIVERS_SERIAL_UART_RZT2M_H_ */
|
||||
|
|
@ -88,5 +88,30 @@
|
|||
reg = <0x81281a00 0x10>;
|
||||
reg-io-width = <4>;
|
||||
};
|
||||
|
||||
uart0: serial@80001000 {
|
||||
compatible = "renesas,rzt2m-uart";
|
||||
reg = <0x80001000 0x1000>;
|
||||
current-speed = <115200>;
|
||||
interrupts = <GIC_SPI 288 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>,
|
||||
<GIC_SPI 289 IRQ_TYPE_EDGE IRQ_DEFAULT_PRIORITY>,
|
||||
<GIC_SPI 290 IRQ_TYPE_EDGE IRQ_DEFAULT_PRIORITY>,
|
||||
<GIC_SPI 291 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
|
||||
interrupt-names = "rx_err", "rx", "tx", "tx_end";
|
||||
status = "disabled";
|
||||
};
|
||||
|
||||
uart3: serial@80001c00 {
|
||||
compatible = "renesas,rzt2m-uart";
|
||||
reg = <0x80001c00 0x1000>;
|
||||
current-speed = <115200>;
|
||||
interrupts = <GIC_SPI 300 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>,
|
||||
<GIC_SPI 301 IRQ_TYPE_EDGE IRQ_DEFAULT_PRIORITY>,
|
||||
<GIC_SPI 302 IRQ_TYPE_EDGE IRQ_DEFAULT_PRIORITY>,
|
||||
<GIC_SPI 303 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
|
||||
interrupt-names = "rx_err", "rx", "tx", "tx_end";
|
||||
status = "disabled";
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
|
|
|||
26
dts/bindings/serial/renesas,rzt2m-uart.yaml
Normal file
26
dts/bindings/serial/renesas,rzt2m-uart.yaml
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# Copyright (c) 2023 Antmicro <www.antmicro.com>
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
description: Renesas RZ/T2M UART
|
||||
|
||||
compatible: "renesas,rzt2m-uart"
|
||||
|
||||
include:
|
||||
- name: uart-controller.yaml
|
||||
- name: pinctrl-device.yaml
|
||||
|
||||
properties:
|
||||
reg:
|
||||
required: true
|
||||
|
||||
current-speed:
|
||||
required: true
|
||||
description: |
|
||||
Initial baud rate setting for UART. Only a fixed set of baud
|
||||
rates is currently supported.
|
||||
enum:
|
||||
- 9600
|
||||
- 115200
|
||||
|
||||
interrupts:
|
||||
required: true
|
||||
Loading…
Reference in a new issue