Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 43 additions & 4 deletions drivers/dma/dma_rtl87x2g.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ static int dma_rtl87x2g_configure(const struct device *dev, uint32_t channel,
#endif

dma_channel_num = dma_rtl87x2g_ch2num(cfg->reg, channel);
if (dma_channel_num < 0) {
return -EINVAL;
}

dma_channel = (GDMA_ChannelTypeDef *)cfg->channel_base_table[dma_channel_num];

GDMA_InitTypeDef dma_init_struct;
Expand Down Expand Up @@ -342,6 +346,10 @@ static int dma_rtl87x2g_reload(const struct device *dev, uint32_t channel, uint3
GDMA_ChannelTypeDef *dma_channel;

dma_channel_num = dma_rtl87x2g_ch2num(cfg->reg, channel);
if (dma_channel_num < 0) {
return -EINVAL;
}

dma_channel = (GDMA_ChannelTypeDef *)cfg->channel_base_table[dma_channel_num];

if (channel >= cfg->channels) {
Expand Down Expand Up @@ -388,6 +396,10 @@ static int dma_rtl87x2g_start(const struct device *dev, uint32_t channel)
GDMA_ChannelTypeDef *dma_channel;

dma_channel_num = dma_rtl87x2g_ch2num(cfg->reg, channel);
if (dma_channel_num < 0) {
return -EINVAL;
}

dma_channel = (GDMA_ChannelTypeDef *)cfg->channel_base_table[dma_channel_num];

if (channel >= cfg->channels) {
Expand Down Expand Up @@ -436,6 +448,10 @@ static int dma_rtl87x2g_stop(const struct device *dev, uint32_t channel)
GDMA_ChannelTypeDef *dma_channel;

dma_channel_num = dma_rtl87x2g_ch2num(cfg->reg, channel);
if (dma_channel_num < 0) {
return -EINVAL;
}

dma_channel = (GDMA_ChannelTypeDef *)cfg->channel_base_table[dma_channel_num];

if (channel >= cfg->channels) {
Expand All @@ -460,6 +476,10 @@ static int dma_rtl87x2g_suspend(const struct device *dev, uint32_t channel)
GDMA_ChannelTypeDef *dma_channel;

dma_channel_num = dma_rtl87x2g_ch2num(cfg->reg, channel);
if (dma_channel_num < 0) {
return -EINVAL;
}

dma_channel = (GDMA_ChannelTypeDef *)cfg->channel_base_table[dma_channel_num];

if (channel >= cfg->channels) {
Expand All @@ -486,6 +506,10 @@ static int dma_rtl87x2g_resume(const struct device *dev, uint32_t channel)
GDMA_ChannelTypeDef *dma_channel;

dma_channel_num = dma_rtl87x2g_ch2num(cfg->reg, channel);
if (dma_channel_num < 0) {
return -EINVAL;
}

dma_channel = (GDMA_ChannelTypeDef *)cfg->channel_base_table[dma_channel_num];

if (channel >= cfg->channels) {
Expand Down Expand Up @@ -513,10 +537,17 @@ static int dma_rtl87x2g_get_status(const struct device *dev, uint32_t ch, struct
{
const struct dma_rtl87x2g_config *cfg = dev->config;
struct dma_rtl87x2g_data *data = dev->data;
int dma_channel_num = dma_rtl87x2g_ch2num(cfg->reg, ch);
GDMA_ChannelTypeDef *dma_channel =
(GDMA_ChannelTypeDef *)cfg->channel_base_table[dma_channel_num];
bool suspending = GDMA_GetSuspendChannelStatus(dma_channel);
int dma_channel_num;
GDMA_ChannelTypeDef *dma_channel;
bool suspending;

dma_channel_num = dma_rtl87x2g_ch2num(cfg->reg, ch);
if (dma_channel_num < 0) {
return -EINVAL;
}

dma_channel = (GDMA_ChannelTypeDef *)cfg->channel_base_table[dma_channel_num];
suspending = GDMA_GetSuspendChannelStatus(dma_channel);

if (ch >= cfg->channels) {
LOG_ERR("channel must be < %" PRIu32 " (%" PRIu32 ")", cfg->channels, ch);
Expand Down Expand Up @@ -565,6 +596,10 @@ static int dma_rtl87x2g_init(const struct device *dev)

for (uint32_t i = 0; i < cfg->channels; i++) {
dma_channel_num = dma_rtl87x2g_ch2num(cfg->reg, i);
if (dma_channel_num < 0) {
return -EINVAL;
}

if (dma_channel_num >= 0) {
GDMA_INTConfig(dma_channel_num,
GDMA_INT_Transfer | GDMA_INT_Error | GDMA_INT_Block,
Expand All @@ -589,6 +624,10 @@ static void dma_rtl87x2g_isr(const struct device *dev)

for (uint32_t i = 0; i < cfg->channels; i++) {
dma_channel_num = dma_rtl87x2g_ch2num(cfg->reg, i);
if (dma_channel_num < 0) {
return -EINVAL;
}

dma_channel = (GDMA_ChannelTypeDef *)cfg->channel_base_table[dma_channel_num];
errflag = ((GDMA_TypeDef *)cfg->reg)->GDMA_STATUSERR_L & BIT(dma_channel_num);
ftfflag = ((GDMA_TypeDef *)cfg->reg)->GDMA_STATUSTFR_L & BIT(dma_channel_num);
Expand Down
31 changes: 29 additions & 2 deletions drivers/serial/Kconfig.rtl87x2g
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# RTL87X2G uart configuration

# Copyright(c) 2020, Realtek Semiconductor Corporation.
# Copyright(c) 2025, Realtek Semiconductor Corporation.
# SPDX-License-Identifier: Apache-2.0

config UART_RTL87X2G
Expand All @@ -16,4 +16,31 @@ config UART_RTL87X2G
select DMA if UART_ASYNC_API

help
Enable the RTL87X2G uart driver.
Enable the rtl87x2g uart driver.

if UART_RTL87X2G
config UART_RTL87X2G_KEEP_ACTIVE_AFTER_RX_WAKEUP
bool "Keep active after rx wakeup"
default y
depends on PM_DEVICE
help
Keep active and do not allow the system to suspend after rx wakeup.

if UART_RTL87X2G_KEEP_ACTIVE_AFTER_RX_WAKEUP
config UART_RTL87X2G_KEEP_ACTIVE_MSEC
int "Milliseconds to keep active"
default 10000
help
Time to keep active after rx wakeup in milliseconds.
Note: This does not mean that the system will sleep immediately
after timeout, it depends on other check status.

endif # UART_RTL87X2G_KEEP_ACTIVE_AFTER_RX_WAKEUP

config UART_RTL87X2G_RX_THRESHOLD
int "Rx threshold level to trigger interrupt"
default 10
help
The Rx threshold level to trigger rx interrupt, range from 1 to 29.

endif # UART_RTL87X2G
Loading