drivers: serial: usart_sam: rework device tree support
Reworked usart_sam driver to utilize new DT_INST macros as part of this rework we also now get pin ctrl/mux configuration information from the device tree instead of via Kconfig and defines in soc_pinmap.h We remove defines from dts_fixup.h and soc_pinmap.h and associated Kconfig symbols that are no longer needed due to getting all that information from devicetree. Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
parent
fa8aa11f71
commit
e7c7f911a9
11 changed files with 48 additions and 312 deletions
|
@ -4,6 +4,8 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define DT_DRV_COMPAT atmel_sam_usart
|
||||
|
||||
/** @file
|
||||
* @brief USART driver for Atmel SAM MCU family.
|
||||
*
|
||||
|
@ -19,34 +21,6 @@
|
|||
#include <soc.h>
|
||||
#include <drivers/uart.h>
|
||||
|
||||
/*
|
||||
* Verify Kconfig configuration
|
||||
*/
|
||||
|
||||
#if CONFIG_USART_SAM_PORT_0 == 1
|
||||
|
||||
#if DT_USART_SAM_PORT_0_BAUD_RATE == 0
|
||||
#error "DT_USART_SAM_PORT_0_BAUD_RATE has to be bigger than 0"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if CONFIG_USART_SAM_PORT_1 == 1
|
||||
|
||||
#if DT_USART_SAM_PORT_1_BAUD_RATE == 0
|
||||
#error "DT_USART_SAM_PORT_1_BAUD_RATE has to be bigger than 0"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if CONFIG_USART_SAM_PORT_2 == 1
|
||||
|
||||
#if DT_USART_SAM_PORT_2_BAUD_RATE == 0
|
||||
#error "DT_USART_SAM_PORT_2_BAUD_RATE has to be bigger than 0"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* Device constant configuration parameters */
|
||||
struct usart_sam_dev_cfg {
|
||||
Usart *regs;
|
||||
|
@ -349,125 +323,53 @@ static const struct uart_driver_api usart_sam_driver_api = {
|
|||
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
||||
};
|
||||
|
||||
/* USART0 */
|
||||
|
||||
#ifdef CONFIG_USART_SAM_PORT_0
|
||||
#define USART_SAM_DECLARE_CFG(n, IRQ_FUNC_INIT) \
|
||||
static const struct usart_sam_dev_cfg usart##n##_sam_config = { \
|
||||
.regs = (Usart *)DT_INST_REG_ADDR(n), \
|
||||
.periph_id = DT_INST_PROP(n, peripheral_id), \
|
||||
\
|
||||
.pin_rx = ATMEL_SAM_DT_PIN(n, 0), \
|
||||
.pin_tx = ATMEL_SAM_DT_PIN(n, 1), \
|
||||
\
|
||||
IRQ_FUNC_INIT \
|
||||
}
|
||||
|
||||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
||||
/* Forward declare function */
|
||||
static void usart0_sam_irq_config_func(struct device *port);
|
||||
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
||||
|
||||
static const struct usart_sam_dev_cfg usart0_sam_config = {
|
||||
.regs = USART0,
|
||||
.periph_id = DT_USART_SAM_PORT_0_PERIPHERAL_ID,
|
||||
.pin_rx = PIN_USART0_RXD,
|
||||
.pin_tx = PIN_USART0_TXD,
|
||||
|
||||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
||||
.irq_config_func = usart0_sam_irq_config_func,
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct usart_sam_dev_data usart0_sam_data = {
|
||||
.baud_rate = DT_USART_SAM_PORT_0_BAUD_RATE,
|
||||
};
|
||||
|
||||
DEVICE_AND_API_INIT(usart0_sam, DT_USART_SAM_PORT_0_NAME, &usart_sam_init,
|
||||
&usart0_sam_data, &usart0_sam_config, PRE_KERNEL_1,
|
||||
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &usart_sam_driver_api);
|
||||
|
||||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
||||
static void usart0_sam_irq_config_func(struct device *port)
|
||||
{
|
||||
IRQ_CONNECT(DT_USART_SAM_PORT_0_IRQ,
|
||||
DT_USART_SAM_PORT_0_IRQ_PRIO,
|
||||
usart_sam_isr,
|
||||
DEVICE_GET(usart0_sam), 0);
|
||||
irq_enable(DT_USART_SAM_PORT_0_IRQ);
|
||||
}
|
||||
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
||||
|
||||
#define USART_SAM_CONFIG_FUNC(n) \
|
||||
static void usart##n##_sam_irq_config_func(struct device *port) \
|
||||
{ \
|
||||
IRQ_CONNECT(DT_INST_IRQN(n), \
|
||||
DT_INST_IRQ(n, priority), \
|
||||
usart_sam_isr, \
|
||||
DEVICE_GET(usart##n##_sam), 0); \
|
||||
irq_enable(DT_INST_IRQN(n)); \
|
||||
}
|
||||
#define USART_SAM_IRQ_CFG_FUNC_INIT(n) \
|
||||
.irq_config_func = usart##n##_sam_irq_config_func
|
||||
#define USART_SAM_INIT_CFG(n) \
|
||||
USART_SAM_DECLARE_CFG(n, USART_SAM_IRQ_CFG_FUNC_INIT(n))
|
||||
#else
|
||||
#define USART_SAM_CONFIG_FUNC(n)
|
||||
#define USART_SAM_IRQ_CFG_FUNC_INIT
|
||||
#define USART_SAM_INIT_CFG(n) \
|
||||
USART_SAM_DECLARE_CFG(n, USART_SAM_IRQ_CFG_FUNC_INIT)
|
||||
#endif
|
||||
|
||||
/* USART1 */
|
||||
#define USART_SAM_INIT(n) \
|
||||
static struct usart_sam_dev_data usart##n##_sam_data = { \
|
||||
.baud_rate = DT_INST_PROP(n, current_speed), \
|
||||
}; \
|
||||
\
|
||||
static const struct usart_sam_dev_cfg usart##n##_sam_config; \
|
||||
\
|
||||
DEVICE_AND_API_INIT(usart##n##_sam, DT_INST_LABEL(n), \
|
||||
&usart_sam_init, &usart##n##_sam_data, \
|
||||
&usart##n##_sam_config, PRE_KERNEL_1, \
|
||||
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
|
||||
&usart_sam_driver_api); \
|
||||
\
|
||||
USART_SAM_CONFIG_FUNC(n) \
|
||||
\
|
||||
USART_SAM_INIT_CFG(n)
|
||||
|
||||
#ifdef CONFIG_USART_SAM_PORT_1
|
||||
|
||||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
||||
/* Forward declare function */
|
||||
static void usart1_sam_irq_config_func(struct device *port);
|
||||
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
||||
|
||||
static const struct usart_sam_dev_cfg usart1_sam_config = {
|
||||
.regs = USART1,
|
||||
.periph_id = DT_USART_SAM_PORT_1_PERIPHERAL_ID,
|
||||
.pin_rx = PIN_USART1_RXD,
|
||||
.pin_tx = PIN_USART1_TXD,
|
||||
|
||||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
||||
.irq_config_func = usart1_sam_irq_config_func,
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct usart_sam_dev_data usart1_sam_data = {
|
||||
.baud_rate = DT_USART_SAM_PORT_1_BAUD_RATE,
|
||||
};
|
||||
|
||||
DEVICE_AND_API_INIT(usart1_sam, DT_USART_SAM_PORT_1_NAME, &usart_sam_init,
|
||||
&usart1_sam_data, &usart1_sam_config, PRE_KERNEL_1,
|
||||
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &usart_sam_driver_api);
|
||||
|
||||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
||||
static void usart1_sam_irq_config_func(struct device *port)
|
||||
{
|
||||
IRQ_CONNECT(DT_USART_SAM_PORT_1_IRQ,
|
||||
DT_USART_SAM_PORT_1_IRQ_PRIO,
|
||||
usart_sam_isr,
|
||||
DEVICE_GET(usart1_sam), 0);
|
||||
irq_enable(DT_USART_SAM_PORT_1_IRQ);
|
||||
}
|
||||
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
||||
|
||||
#endif
|
||||
|
||||
/* USART2 */
|
||||
|
||||
#ifdef CONFIG_USART_SAM_PORT_2
|
||||
|
||||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
||||
/* Forward declare function */
|
||||
static void usart2_sam_irq_config_func(struct device *port);
|
||||
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
||||
|
||||
static const struct usart_sam_dev_cfg usart2_sam_config = {
|
||||
.regs = USART2,
|
||||
.periph_id = DT_USART_SAM_PORT_2_PERIPHERAL_ID,
|
||||
.pin_rx = PIN_USART2_RXD,
|
||||
.pin_tx = PIN_USART2_TXD,
|
||||
|
||||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
||||
.irq_config_func = usart2_sam_irq_config_func,
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct usart_sam_dev_data usart2_sam_data = {
|
||||
.baud_rate = DT_USART_SAM_PORT_2_BAUD_RATE,
|
||||
};
|
||||
|
||||
DEVICE_AND_API_INIT(usart2_sam, DT_USART_SAM_PORT_2_NAME, &usart_sam_init,
|
||||
&usart2_sam_data, &usart2_sam_config, PRE_KERNEL_1,
|
||||
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &usart_sam_driver_api);
|
||||
|
||||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
||||
static void usart2_sam_irq_config_func(struct device *port)
|
||||
{
|
||||
IRQ_CONNECT(DT_USART_SAM_PORT_2_IRQ,
|
||||
DT_USART_SAM_PORT_2_IRQ_PRIO,
|
||||
usart_sam_isr,
|
||||
DEVICE_GET(usart2_sam), 0);
|
||||
irq_enable(DT_USART_SAM_PORT_2_IRQ);
|
||||
}
|
||||
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
||||
|
||||
#endif
|
||||
DT_INST_FOREACH(USART_SAM_INIT)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue