Skip to content

Commit

Permalink
drivers: serial: sam: uart: convert to DT_INST defines
Browse files Browse the repository at this point in the history
Convert driver to use DT_INST_ defines.

see zephyrproject-rtos#23107

Signed-off-by: Gerson Fernando Budke <[email protected]>
  • Loading branch information
nandojve committed Mar 9, 2020
1 parent 6c75058 commit 259a63b
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 258 deletions.
258 changes: 63 additions & 195 deletions drivers/serial/uart_sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,41 @@
* Verify Kconfig configuration
*/

#if CONFIG_UART_SAM_PORT_0 == 1
#if DT_INST_0_ATMEL_SAM_UART

#if DT_UART_SAM_PORT_0_BAUD_RATE == 0
#if DT_INST_0_ATMEL_SAM_UART_CURRENT_SPEED == 0
#error "DT_UART_SAM_PORT_0_BAUD_RATE has to be bigger than 0"
#endif

#endif

#if CONFIG_UART_SAM_PORT_1 == 1
#if DT_INST_1_ATMEL_SAM_UART

#if DT_UART_SAM_PORT_1_BAUD_RATE == 0
#if DT_INST_1_ATMEL_SAM_UART_CURRENT_SPEED == 0
#error "DT_UART_SAM_PORT_1_BAUD_RATE has to be bigger than 0"
#endif

#endif

#if CONFIG_UART_SAM_PORT_2 == 1
#if DT_INST_2_ATMEL_SAM_UART

#if DT_UART_SAM_PORT_2_BAUD_RATE == 0
#if DT_INST_2_ATMEL_SAM_UART_CURRENT_SPEED == 0
#error "DT_UART_SAM_PORT_2_BAUD_RATE has to be bigger than 0"
#endif

#endif

#if CONFIG_UART_SAM_PORT_3 == 1
#if DT_INST_3_ATMEL_SAM_UART

#if DT_UART_SAM_PORT_3_BAUD_RATE == 0
#if DT_INST_3_ATMEL_SAM_UART_CURRENT_SPEED == 0
#error "DT_UART_SAM_PORT_3_BAUD_RATE has to be bigger than 0"
#endif

#endif

#if CONFIG_UART_SAM_PORT_4 == 1
#if DT_INST_4_ATMEL_SAM_UART

#if DT_UART_SAM_PORT_4_BAUD_RATE == 0
#if DT_INST_4_ATMEL_SAM_UART_CURRENT_SPEED == 0
#error "DT_UART_SAM_PORT_4_BAUD_RATE has to be bigger than 0"
#endif

Expand Down Expand Up @@ -364,206 +364,74 @@ static const struct uart_driver_api uart_sam_driver_api = {
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
};

/* UART0 */

#ifdef CONFIG_UART_SAM_PORT_0

#ifdef CONFIG_UART_INTERRUPT_DRIVEN
/* Forward declare function */
static void uart0_sam_irq_config_func(struct device *port);
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */

static const struct uart_sam_dev_cfg uart0_sam_config = {
.regs = UART0,
.periph_id = ID_UART0,
.pin_rx = PIN_UART0_RXD,
.pin_tx = PIN_UART0_TXD,

#ifdef CONFIG_UART_INTERRUPT_DRIVEN
.irq_config_func = uart0_sam_irq_config_func,
#endif
};

static struct uart_sam_dev_data uart0_sam_data = {
.baud_rate = DT_UART_SAM_PORT_0_BAUD_RATE,
};

DEVICE_AND_API_INIT(uart0_sam, DT_UART_SAM_PORT_0_NAME, &uart_sam_init,
&uart0_sam_data, &uart0_sam_config, PRE_KERNEL_1,
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &uart_sam_driver_api);

#ifdef CONFIG_UART_INTERRUPT_DRIVEN
static void uart0_sam_irq_config_func(struct device *port)
{
IRQ_CONNECT(DT_UART_SAM_PORT_0_IRQ,
DT_UART_SAM_PORT_0_IRQ_PRIO,
uart_sam_isr,
DEVICE_GET(uart0_sam), 0);
irq_enable(DT_UART_SAM_PORT_0_IRQ);
#define UART_SAM_INT_DRIVEN_FUNC(n) \
.irq_config_func = uart##n##_sam_irq_config_func,

#define UART_SAM_IRQ_CONNECT(n) \
do { \
IRQ_CONNECT(DT_INST_##n##_ATMEL_SAM_UART_IRQ_0, \
DT_INST_##n##_ATMEL_SAM_UART_IRQ_0_PRIORITY, \
uart_sam_isr, DEVICE_GET(uart##n##_sam), 0); \
irq_enable(DT_INST_##n##_ATMEL_SAM_UART_IRQ_0); \
} while (0)

#define USART_SAM_IRQ_HANDLER_FUNC(n) \
static void uart##n##_sam_irq_config_func(struct device *port)

#define UART_SAM_IRQ_HANDLER(n) \
static void uart##n##_sam_irq_config_func(struct device *port) \
{ \
UART_SAM_IRQ_CONNECT(n); \
}
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
#endif /* CONFIG_UART_SAM_PORT_0 */

/* UART1 */

#ifdef CONFIG_UART_SAM_PORT_1

#ifdef CONFIG_UART_INTERRUPT_DRIVEN
/* Forward declare function */
static void uart1_sam_irq_config_func(struct device *port);
#else
#define UART_SAM_INT_DRIVEN_FUNC(n)
#define USART_SAM_IRQ_HANDLER_FUNC(n)
#define UART_SAM_IRQ_HANDLER(n)
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */

static const struct uart_sam_dev_cfg uart1_sam_config = {
.regs = UART1,
.periph_id = ID_UART1,
.pin_rx = PIN_UART1_RXD,
.pin_tx = PIN_UART1_TXD,

#ifdef CONFIG_UART_INTERRUPT_DRIVEN
.irq_config_func = uart1_sam_irq_config_func,
#endif
};

static struct uart_sam_dev_data uart1_sam_data = {
.baud_rate = DT_UART_SAM_PORT_1_BAUD_RATE,
};

DEVICE_AND_API_INIT(uart1_sam, DT_UART_SAM_PORT_1_NAME, &uart_sam_init,
&uart1_sam_data, &uart1_sam_config, PRE_KERNEL_1,
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &uart_sam_driver_api);

#ifdef CONFIG_UART_INTERRUPT_DRIVEN
static void uart1_sam_irq_config_func(struct device *port)
{
IRQ_CONNECT(DT_UART_SAM_PORT_1_IRQ,
DT_UART_SAM_PORT_1_IRQ_PRIO,
uart_sam_isr,
DEVICE_GET(uart1_sam), 0);
irq_enable(DT_UART_SAM_PORT_1_IRQ);
#define UART_SAM_DEVICE_CONFIG(n, m) \
static const struct uart_sam_dev_cfg uart##n##_sam_config = { \
.regs = (Uart *)DT_INST_##n##_ATMEL_SAM_UART_BASE_ADDRESS, \
.periph_id = DT_INST_##n##_ATMEL_SAM_UART_PERIPHERAL_ID, \
.pin_rx = PIN_UART##m##_RXD, \
.pin_tx = PIN_UART##m##_TXD, \
UART_SAM_INT_DRIVEN_FUNC(n) \
}
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */

#endif /* CONFIG_UART_SAM_PORT_1 */

/* UART2 */

#ifdef CONFIG_UART_SAM_PORT_2

#ifdef CONFIG_UART_INTERRUPT_DRIVEN
/* Forward declare function */
static void uart2_sam_irq_config_func(struct device *port);
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */

static const struct uart_sam_dev_cfg uart2_sam_config = {
.regs = UART2,
.periph_id = ID_UART2,
.pin_rx = PIN_UART2_RXD,
.pin_tx = PIN_UART2_TXD,

#ifdef CONFIG_UART_INTERRUPT_DRIVEN
.irq_config_func = uart2_sam_irq_config_func,
#endif
};

static struct uart_sam_dev_data uart2_sam_data = {
.baud_rate = DT_UART_SAM_PORT_2_BAUD_RATE,
};

DEVICE_AND_API_INIT(uart2_sam, DT_UART_SAM_PORT_2_NAME, &uart_sam_init,
&uart2_sam_data, &uart2_sam_config, PRE_KERNEL_1,
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &uart_sam_driver_api);

#ifdef CONFIG_UART_INTERRUPT_DRIVEN
static void uart2_sam_irq_config_func(struct device *port)
{
IRQ_CONNECT(DT_UART_SAM_PORT_2_IRQ,
DT_UART_SAM_PORT_2_IRQ_PRIO,
uart_sam_isr,
DEVICE_GET(uart2_sam), 0);
irq_enable(DT_UART_SAM_PORT_2_IRQ);
#define UART_SAM_DEVICE_DATA(n) \
static struct uart_sam_dev_data uart##n##_sam_data = { \
.baud_rate = DT_INST_##n##_ATMEL_SAM_UART_CURRENT_SPEED, \
}
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */

#define UART_SAM_DEVICE_INIT(n, m) \
USART_SAM_IRQ_HANDLER_FUNC(n); \
UART_SAM_DEVICE_CONFIG(n, m); \
UART_SAM_DEVICE_DATA(n); \
DEVICE_AND_API_INIT(uart##n##_sam, DT_INST_##n##_ATMEL_SAM_UART_LABEL, \
&uart_sam_init, &uart##n##_sam_data, \
&uart##n##_sam_config, PRE_KERNEL_1, \
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
&uart_sam_driver_api); \
UART_SAM_IRQ_HANDLER(n)

#if DT_INST_0_ATMEL_SAM_UART
UART_SAM_DEVICE_INIT(0, DT_INST_0_ATMEL_SAM_UART_ID);
#endif

/* UART3 */

#ifdef CONFIG_UART_SAM_PORT_3

#ifdef CONFIG_UART_INTERRUPT_DRIVEN
/* Forward declare function */
static void uart3_sam_irq_config_func(struct device *port);
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */

static const struct uart_sam_dev_cfg uart3_sam_config = {
.regs = UART3,
.periph_id = ID_UART3,
.pin_rx = PIN_UART3_RXD,
.pin_tx = PIN_UART3_TXD,

#ifdef CONFIG_UART_INTERRUPT_DRIVEN
.irq_config_func = uart3_sam_irq_config_func,
#if DT_INST_1_ATMEL_SAM_UART
UART_SAM_DEVICE_INIT(1, DT_INST_1_ATMEL_SAM_UART_ID);
#endif
};

static struct uart_sam_dev_data uart3_sam_data = {
.baud_rate = DT_UART_SAM_PORT_3_BAUD_RATE,
};

DEVICE_AND_API_INIT(uart3_sam, DT_UART_SAM_PORT_3_NAME, &uart_sam_init,
&uart3_sam_data, &uart3_sam_config, PRE_KERNEL_1,
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &uart_sam_driver_api);

#ifdef CONFIG_UART_INTERRUPT_DRIVEN
static void uart3_sam_irq_config_func(struct device *port)
{
IRQ_CONNECT(DT_UART_SAM_PORT_3_IRQ,
DT_UART_SAM_PORT_3_IRQ_PRIO,
uart_sam_isr,
DEVICE_GET(uart3_sam), 0);
irq_enable(DT_UART_SAM_PORT_3_IRQ);
}
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */

#if DT_INST_2_ATMEL_SAM_UART
UART_SAM_DEVICE_INIT(2, DT_INST_2_ATMEL_SAM_UART_ID);
#endif

/* UART4 */

#ifdef CONFIG_UART_SAM_PORT_4

#ifdef CONFIG_UART_INTERRUPT_DRIVEN
/* Forward declare function */
static void uart4_sam_irq_config_func(struct device *port);
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */

static const struct uart_sam_dev_cfg uart4_sam_config = {
.regs = UART4,
.periph_id = ID_UART4,
.pin_rx = PIN_UART4_RXD,
.pin_tx = PIN_UART4_TXD,

#ifdef CONFIG_UART_INTERRUPT_DRIVEN
.irq_config_func = uart4_sam_irq_config_func,
#if DT_INST_3_ATMEL_SAM_UART
UART_SAM_DEVICE_INIT(3, DT_INST_3_ATMEL_SAM_UART_ID);
#endif
};

static struct uart_sam_dev_data uart4_sam_data = {
.baud_rate = DT_UART_SAM_PORT_4_BAUD_RATE,
};

DEVICE_AND_API_INIT(uart4_sam, DT_UART_SAM_PORT_4_NAME, &uart_sam_init,
&uart4_sam_data, &uart4_sam_config, PRE_KERNEL_1,
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &uart_sam_driver_api);

#ifdef CONFIG_UART_INTERRUPT_DRIVEN
static void uart4_sam_irq_config_func(struct device *port)
{
IRQ_CONNECT(DT_UART_SAM_PORT_4_IRQ,
DT_UART_SAM_PORT_4_IRQ_PRIO,
uart_sam_isr,
DEVICE_GET(uart4_sam), 0);
irq_enable(DT_UART_SAM_PORT_4_IRQ);
}
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */

#if DT_INST_4_ATMEL_SAM_UART
UART_SAM_DEVICE_INIT(4, DT_INST_4_ATMEL_SAM_UART_ID);
#endif
5 changes: 0 additions & 5 deletions soc/arm/atmel_sam/sam3x/dts_fixup.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@
#define DT_I2C_1_IRQ_PRI DT_ATMEL_SAM_I2C_TWI_40090000_IRQ_0_PRIORITY
#define DT_I2C_1_PERIPHERAL_ID DT_ATMEL_SAM_I2C_TWI_40090000_PERIPHERAL_ID

#define DT_UART_SAM_PORT_0_NAME DT_ATMEL_SAM_UART_400E0800_LABEL
#define DT_UART_SAM_PORT_0_BAUD_RATE DT_ATMEL_SAM_UART_400E0800_CURRENT_SPEED
#define DT_UART_SAM_PORT_0_IRQ DT_ATMEL_SAM_UART_400E0800_IRQ_0
#define DT_UART_SAM_PORT_0_IRQ_PRIO DT_ATMEL_SAM_UART_400E0800_IRQ_0_PRIORITY

#define DT_USART_SAM_PORT_0_NAME DT_ATMEL_SAM_USART_40098000_LABEL
#define DT_USART_SAM_PORT_0_BAUD_RATE DT_ATMEL_SAM_USART_40098000_CURRENT_SPEED
#define DT_USART_SAM_PORT_1_NAME DT_ATMEL_SAM_USART_4009C000_LABEL
Expand Down
9 changes: 0 additions & 9 deletions soc/arm/atmel_sam/sam4e/dts_fixup.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,6 @@
#define DT_SPI_0_IRQ_PRI DT_ATMEL_SAM_SPI_40088000_IRQ_0_PRIORITY
#define DT_SPI_0_PERIPHERAL_ID DT_ATMEL_SAM_SPI_40088000_PERIPHERAL_ID

#define DT_UART_SAM_PORT_0_NAME DT_ATMEL_SAM_UART_400E0600_LABEL
#define DT_UART_SAM_PORT_0_BAUD_RATE DT_ATMEL_SAM_UART_400E0600_CURRENT_SPEED
#define DT_UART_SAM_PORT_0_IRQ DT_ATMEL_SAM_UART_400E0600_IRQ_0
#define DT_UART_SAM_PORT_0_IRQ_PRIO DT_ATMEL_SAM_UART_400E0600_IRQ_0_PRIORITY
#define DT_UART_SAM_PORT_1_NAME DT_ATMEL_SAM_UART_40060600_LABEL
#define DT_UART_SAM_PORT_1_BAUD_RATE DT_ATMEL_SAM_UART_40060600_CURRENT_SPEED
#define DT_UART_SAM_PORT_1_IRQ DT_ATMEL_SAM_UART_40060600_IRQ_0
#define DT_UART_SAM_PORT_1_IRQ_PRIO DT_ATMEL_SAM_UART_40060600_IRQ_0_PRIORITY

#define DT_USART_SAM_PORT_0_NAME DT_ATMEL_SAM_USART_400A0000_LABEL
#define DT_USART_SAM_PORT_0_BAUD_RATE DT_ATMEL_SAM_USART_400A0000_CURRENT_SPEED
#define DT_USART_SAM_PORT_0_IRQ DT_ATMEL_SAM_USART_400A0000_IRQ_0
Expand Down
8 changes: 0 additions & 8 deletions soc/arm/atmel_sam/sam4s/dts_fixup.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@
#define DT_SPI_0_IRQ_PRI DT_ATMEL_SAM_SPI_40008000_IRQ_0_PRIORITY
#define DT_SPI_0_PERIPHERAL_ID DT_ATMEL_SAM_SPI_40008000_PERIPHERAL_ID

#define DT_UART_SAM_PORT_0_NAME DT_ATMEL_SAM_UART_400E0600_LABEL
#define DT_UART_SAM_PORT_0_BAUD_RATE DT_ATMEL_SAM_UART_400E0600_CURRENT_SPEED
#define DT_UART_SAM_PORT_0_IRQ DT_ATMEL_SAM_UART_400E0600_IRQ_0
#define DT_UART_SAM_PORT_0_IRQ_PRIO DT_ATMEL_SAM_UART_400E0600_IRQ_0_PRIORITY
#define DT_UART_SAM_PORT_1_NAME DT_ATMEL_SAM_UART_400E0800_LABEL
#define DT_UART_SAM_PORT_1_BAUD_RATE DT_ATMEL_SAM_UART_400E0800_CURRENT_SPEED
#define DT_UART_SAM_PORT_1_IRQ DT_ATMEL_SAM_UART_400E0800_IRQ_0
#define DT_UART_SAM_PORT_1_IRQ_PRIO DT_ATMEL_SAM_UART_400E0800_IRQ_0_PRIORITY
#define DT_USART_SAM_PORT_0_NAME DT_ATMEL_SAM_USART_40024000_LABEL
#define DT_USART_SAM_PORT_0_BAUD_RATE DT_ATMEL_SAM_USART_40024000_CURRENT_SPEED
#define DT_USART_SAM_PORT_1_NAME DT_ATMEL_SAM_USART_40028000_LABEL
Expand Down
20 changes: 0 additions & 20 deletions soc/arm/atmel_sam/same70/dts_fixup.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,6 @@
#define DT_SPI_1_IRQ_PRI DT_ATMEL_SAM_SPI_40058000_IRQ_0_PRIORITY
#define DT_SPI_1_PERIPHERAL_ID DT_ATMEL_SAM_SPI_40058000_PERIPHERAL_ID

#define DT_UART_SAM_PORT_0_NAME DT_ATMEL_SAM_UART_400E0800_LABEL
#define DT_UART_SAM_PORT_0_BAUD_RATE DT_ATMEL_SAM_UART_400E0800_CURRENT_SPEED
#define DT_UART_SAM_PORT_0_IRQ DT_ATMEL_SAM_UART_400E0800_IRQ_0
#define DT_UART_SAM_PORT_0_IRQ_PRIO DT_ATMEL_SAM_UART_400E0800_IRQ_0_PRIORITY
#define DT_UART_SAM_PORT_1_NAME DT_ATMEL_SAM_UART_400E0A00_LABEL
#define DT_UART_SAM_PORT_1_BAUD_RATE DT_ATMEL_SAM_UART_400E0A00_CURRENT_SPEED
#define DT_UART_SAM_PORT_1_IRQ DT_ATMEL_SAM_UART_400E0A00_IRQ_0
#define DT_UART_SAM_PORT_1_IRQ_PRIO DT_ATMEL_SAM_UART_400E0A00_IRQ_0_PRIORITY
#define DT_UART_SAM_PORT_2_NAME DT_ATMEL_SAM_UART_400E1A00_LABEL
#define DT_UART_SAM_PORT_2_BAUD_RATE DT_ATMEL_SAM_UART_400E1A00_CURRENT_SPEED
#define DT_UART_SAM_PORT_2_IRQ DT_ATMEL_SAM_UART_400E1A00_IRQ_0
#define DT_UART_SAM_PORT_2_IRQ_PRIO DT_ATMEL_SAM_UART_400E1A00_IRQ_0_PRIORITY
#define DT_UART_SAM_PORT_3_NAME DT_ATMEL_SAM_UART_400E1C00_LABEL
#define DT_UART_SAM_PORT_3_BAUD_RATE DT_ATMEL_SAM_UART_400E1C00_CURRENT_SPEED
#define DT_UART_SAM_PORT_3_IRQ DT_ATMEL_SAM_UART_400E1C00_IRQ_0
#define DT_UART_SAM_PORT_3_IRQ_PRIO DT_ATMEL_SAM_UART_400E1C00_IRQ_0_PRIORITY
#define DT_UART_SAM_PORT_4_NAME DT_ATMEL_SAM_UART_400E1E00_LABEL
#define DT_UART_SAM_PORT_4_BAUD_RATE DT_ATMEL_SAM_UART_400E1E00_CURRENT_SPEED
#define DT_UART_SAM_PORT_4_IRQ DT_ATMEL_SAM_UART_400E1E00_IRQ_0
#define DT_UART_SAM_PORT_4_IRQ_PRIO DT_ATMEL_SAM_UART_400E1E00_IRQ_0_PRIORITY
#define DT_USART_SAM_PORT_0_NAME DT_ATMEL_SAM_USART_40024000_LABEL
#define DT_USART_SAM_PORT_0_BAUD_RATE DT_ATMEL_SAM_USART_40024000_CURRENT_SPEED
#define DT_USART_SAM_PORT_0_IRQ DT_ATMEL_SAM_USART_40024000_IRQ_0
Expand Down
Loading

0 comments on commit 259a63b

Please sign in to comment.