drivers: serial: add XMC seris UART support

Add infineon XMC4 series UART support. Driver supports
only poll mode using XMCLib.

Out of 4 available UART's on SoC, only UART1 is confgired
by default in UART mode until GPIO & pinctrl support.

Signed-off-by: Parthiban Nallathambi <parthiban@linumiz.com>
This commit is contained in:
Parthiban Nallathambi 2020-04-21 12:16:59 +02:00 committed by Carles Cufí
parent b687d76d09
commit f4adfd52cb
7 changed files with 108 additions and 0 deletions

View file

@ -212,6 +212,7 @@
/drivers/serial/uart_rtt.c @carlescufi @pkral78
/drivers/serial/Kconfig.xlnx @wjliang
/drivers/serial/uart_xlnx_ps.c @wjliang
/drivers/serial/*xmc4xxx* @parthitce
/drivers/net/ @jukkar @tbursztyka
/drivers/ptp_clock/ @jukkar
/drivers/pwm/*rv32m1* @henrikbrixandersen

View file

@ -30,6 +30,7 @@ zephyr_library_sources_if_kconfig(uart_rv32m1_lpuart.c)
zephyr_library_sources_if_kconfig(uart_liteuart.c)
zephyr_library_sources_ifdef(CONFIG_UART_RTT_DRIVER uart_rtt.c)
zephyr_library_sources_if_kconfig(uart_xlnx_ps.c)
zephyr_library_sources_if_kconfig(uart_xmc4xxx.c)
zephyr_library_sources_ifdef(CONFIG_USERSPACE uart_handlers.c)

View file

@ -124,4 +124,6 @@ source "drivers/serial/Kconfig.rtt"
source "drivers/serial/Kconfig.xlnx"
source "drivers/serial/Kconfig.xmc4xxx"
endif # SERIAL

View file

@ -0,0 +1,12 @@
# Copyright (c) 2020 Linumiz
#
# Author: Parthiban Nallathambi <parthiban@linumiz.com>
# SPDX-License-Identifier: Apache-2.0
config UART_XMC4XXX
depends on SOC_SERIES_XMC_4XXX
bool "XMC4XX UART driver"
select SERIAL_HAS_DRIVER
depends on SOC_FAMILY_XMC && HAS_XMCLIB_UART
help
This option enables the XMC4XX UART driver, for UART_0.

View file

@ -0,0 +1,82 @@
/*
* Copyright (c) 2020 Linumiz
* Author: Parthiban Nallathambi <parthiban@linumiz.com>
*
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT infineon_xmc4xxx_uart
#include <xmc_gpio.h>
#include <xmc_uart.h>
#include <drivers/uart.h>
struct uart_xmc4xxx_data {
XMC_UART_CH_CONFIG_t config;
};
#define DEV_CFG(dev) \
((const struct uart_device_config * const)(dev)->config_info)
#define DEV_DATA(dev) \
((struct uart_xmc4xxx_data * const)(dev)->driver_data)
static int uart_xmc4xxx_poll_in(struct device *dev, unsigned char *c)
{
const struct uart_device_config *config = DEV_CFG(dev);
*(uint16_t *)c =
XMC_UART_CH_GetReceivedData((XMC_USIC_CH_t *)config->base);
return 0;
}
static void uart_xmc4xxx_poll_out(struct device *dev, unsigned char c)
{
const struct uart_device_config *config = DEV_CFG(dev);
XMC_UART_CH_Transmit((XMC_USIC_CH_t *)config->base, (uint16_t)c);
}
static int uart_xmc4xxx_init(struct device *dev)
{
const struct uart_device_config *config = DEV_CFG(dev);
struct uart_xmc4xxx_data *data = DEV_DATA(dev);
XMC_USIC_CH_t *uart = (XMC_USIC_CH_t *)config->base;
data->config.data_bits = 8U;
data->config.stop_bits = 1U;
/* configure PIN 0.0 and 0.1 as UART */
XMC_UART_CH_Init(uart, &(data->config));
XMC_GPIO_SetMode(P0_0, XMC_GPIO_MODE_INPUT_TRISTATE);
XMC_UART_CH_SetInputSource(uart, XMC_UART_CH_INPUT_RXD,
USIC1_C1_DX0_P0_0);
XMC_UART_CH_Start(uart);
XMC_GPIO_SetMode(P0_1,
XMC_GPIO_MODE_OUTPUT_PUSH_PULL | P0_1_AF_U1C1_DOUT0);
return 0;
}
static const struct uart_driver_api uart_xmc4xxx_driver_api = {
.poll_in = uart_xmc4xxx_poll_in,
.poll_out = uart_xmc4xxx_poll_out,
};
#define XMC4XXX_INIT(index) \
static struct uart_xmc4xxx_data xmc4xxx_data_##index = { \
.config.baudrate = DT_INST_PROP(index, current_speed) \
}; \
\
static const struct uart_device_config xmc4xxx_config_##index = { \
.base = (void *)DT_INST_REG_ADDR(index), \
}; \
\
DEVICE_AND_API_INIT(uart_xmc4xxx_##index, DT_INST_LABEL(index), \
&uart_xmc4xxx_init, &xmc4xxx_data_##index, \
&xmc4xxx_config_##index, PRE_KERNEL_1, \
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
&uart_xmc4xxx_driver_api);
DT_INST_FOREACH_STATUS_OKAY(XMC4XXX_INIT)

View file

@ -0,0 +1,9 @@
description: INFINEON XMC4XXX UART
compatible: "infineon,xmc4xxx-uart"
include: uart-controller.yaml
properties:
reg:
required: true

View file

@ -12,5 +12,6 @@ config SOC_SERIES_XMC_4XXX
select SOC_FAMILY_XMC
select CPU_HAS_ARM_MPU
select CPU_HAS_FPU
select HAS_XMCLIB_UART
help
Enable support for XMC 4xxx MCU series