Skip to content

Commit

Permalink
drivers: serial: sam: usart: 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 24a5c37 commit 31a13cd
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 176 deletions.
178 changes: 59 additions & 119 deletions drivers/serial/usart_sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@
* Verify Kconfig configuration
*/

#if CONFIG_USART_SAM_PORT_0 == 1
#if DT_INST_0_ATMEL_SAM_USART == 1

#if DT_USART_SAM_PORT_0_BAUD_RATE == 0
#error "DT_USART_SAM_PORT_0_BAUD_RATE has to be bigger than 0"
#if DT_INST_0_ATMEL_SAM_USART_CURRENT_SPEED == 0
#error "DT_INST_0_ATMEL_SAM_USART_CURRENT_SPEED has to be bigger than 0"
#endif

#endif

#if CONFIG_USART_SAM_PORT_1 == 1
#if DT_INST_1_ATMEL_SAM_USART == 1

#if DT_USART_SAM_PORT_1_BAUD_RATE == 0
#error "DT_USART_SAM_PORT_1_BAUD_RATE has to be bigger than 0"
#if DT_INST_1_ATMEL_SAM_USART_CURRENT_SPEED == 0
#error "DT_INST_1_ATMEL_SAM_USART_CURRENT_SPEED has to be bigger than 0"
#endif

#endif

#if CONFIG_USART_SAM_PORT_2 == 1
#if DT_INST_2_ATMEL_SAM_USART == 1

#if DT_USART_SAM_PORT_2_BAUD_RATE == 0
#error "DT_USART_SAM_PORT_2_BAUD_RATE has to be bigger than 0"
#if DT_INST_2_ATMEL_SAM_USART_CURRENT_SPEED == 0
#error "DT_INST_2_ATMEL_SAM_USART_CURRENT_SPEED has to be bigger than 0"
#endif

#endif
Expand Down Expand Up @@ -349,125 +349,65 @@ static const struct uart_driver_api usart_sam_driver_api = {
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
};

/* USART0 */

#ifdef CONFIG_USART_SAM_PORT_0

#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);
#define USART_SAM_INT_DRIVEN_FUNC(n) \
.irq_config_func = usart##n##_sam_irq_config_func

#define USART_SAM_IRQ_CONNECT(n) \
do { \
IRQ_CONNECT(DT_INST_##n##_ATMEL_SAM_USART_IRQ_0, \
DT_INST_##n##_ATMEL_SAM_USART_IRQ_0_PRIORITY, \
usart_sam_isr, DEVICE_GET(usart##n##_sam), 0); \
irq_enable(DT_INST_##n##_ATMEL_SAM_USART_IRQ_0); \
} while (0)

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

#define USART_SAM_IRQ_HANDLER(n) \
static void usart##n##_sam_irq_config_func(struct device *port) \
{ \
USART_SAM_IRQ_CONNECT(n); \
}
#else
#define USART_SAM_INT_DRIVEN_FUNC(n)
#define USART_SAM_IRQ_HANDLER_FUNC(n)
#define USART_SAM_IRQ_HANDLER(n)
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */

#endif

/* USART1 */

#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);
#define USART_SAM_DEVICE_CONFIG(n, m) \
static const struct usart_sam_dev_cfg usart##n##_sam_config = { \
.regs = (Usart *)DT_INST_##n##_ATMEL_SAM_USART_BASE_ADDRESS, \
.periph_id = DT_INST_##n##_ATMEL_SAM_USART_PERIPHERAL_ID, \
.pin_rx = PIN_USART##m##_RXD, \
.pin_tx = PIN_USART##m##_TXD, \
USART_SAM_INT_DRIVEN_FUNC(n) \
}

#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);
#define USART_SAM_DEVICE_DATA(n) \
static struct usart_sam_dev_data usart##n##_sam_data = { \
.baud_rate = DT_INST_##n##_ATMEL_SAM_USART_CURRENT_SPEED, \
}
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */

#define USART_SAM_DEVICE_INIT(n, m) \
USART_SAM_IRQ_HANDLER_FUNC(n); \
USART_SAM_DEVICE_CONFIG(n, m); \
USART_SAM_DEVICE_DATA(n); \
DEVICE_AND_API_INIT(usart##n##_sam, DT_INST_##n##_ATMEL_SAM_USART_LABEL,\
&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_IRQ_HANDLER(n)

#if DT_INST_0_ATMEL_SAM_USART
USART_SAM_DEVICE_INIT(0, DT_INST_0_ATMEL_SAM_USART_ID);
#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,
#if DT_INST_1_ATMEL_SAM_USART
USART_SAM_DEVICE_INIT(1, DT_INST_1_ATMEL_SAM_USART_ID);
#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 */

#if DT_INST_2_ATMEL_SAM_USART
USART_SAM_DEVICE_INIT(2, DT_INST_2_ATMEL_SAM_USART_ID);
#endif
9 changes: 0 additions & 9 deletions soc/arm/atmel_sam/sam3x/dts_fixup.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,4 @@
#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_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
#define DT_USART_SAM_PORT_1_BAUD_RATE DT_ATMEL_SAM_USART_4009C000_CURRENT_SPEED
#define DT_USART_SAM_PORT_2_NAME DT_ATMEL_SAM_USART_400A0000_LABEL
#define DT_USART_SAM_PORT_2_BAUD_RATE DT_ATMEL_SAM_USART_400A0000_CURRENT_SPEED
#define DT_USART_SAM_PORT_3_NAME DT_ATMEL_SAM_USART_400A4000_LABEL
#define DT_USART_SAM_PORT_3_BAUD_RATE DT_ATMEL_SAM_USART_400A4000_CURRENT_SPEED

/* End of SoC Level DTS fixup file */
11 changes: 0 additions & 11 deletions soc/arm/atmel_sam/sam4e/dts_fixup.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,4 @@
#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_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
#define DT_USART_SAM_PORT_0_IRQ_PRIO DT_ATMEL_SAM_USART_400A0000_IRQ_0_PRIORITY
#define DT_USART_SAM_PORT_0_PERIPHERAL_ID DT_ATMEL_SAM_USART_400A0000_PERIPHERAL_ID
#define DT_USART_SAM_PORT_1_NAME DT_ATMEL_SAM_USART_400A4000_LABEL
#define DT_USART_SAM_PORT_1_BAUD_RATE DT_ATMEL_SAM_USART_400A4000_CURRENT_SPEED
#define DT_USART_SAM_PORT_1_IRQ DT_ATMEL_SAM_USART_400A4000_IRQ_0
#define DT_USART_SAM_PORT_1_IRQ_PRIO DT_ATMEL_SAM_USART_400A4000_IRQ_0_PRIORITY
#define DT_USART_SAM_PORT_1_PERIPHERAL_ID DT_ATMEL_SAM_USART_400A4000_PERIPHERAL_ID

/* End of SoC Level DTS fixup file */
5 changes: 0 additions & 5 deletions soc/arm/atmel_sam/sam4s/dts_fixup.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,4 @@
#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_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
#define DT_USART_SAM_PORT_1_BAUD_RATE DT_ATMEL_SAM_USART_40028000_CURRENT_SPEED

/* End of SoC Level DTS fixup file */
16 changes: 0 additions & 16 deletions soc/arm/atmel_sam/same70/dts_fixup.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +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_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
#define DT_USART_SAM_PORT_0_IRQ_PRIO DT_ATMEL_SAM_USART_40024000_IRQ_0_PRIORITY
#define DT_USART_SAM_PORT_0_PERIPHERAL_ID DT_ATMEL_SAM_USART_40024000_PERIPHERAL_ID
#define DT_USART_SAM_PORT_1_NAME DT_ATMEL_SAM_USART_40028000_LABEL
#define DT_USART_SAM_PORT_1_BAUD_RATE DT_ATMEL_SAM_USART_40028000_CURRENT_SPEED
#define DT_USART_SAM_PORT_1_IRQ DT_ATMEL_SAM_USART_40028000_IRQ_0
#define DT_USART_SAM_PORT_1_IRQ_PRIO DT_ATMEL_SAM_USART_40028000_IRQ_0_PRIORITY
#define DT_USART_SAM_PORT_1_PERIPHERAL_ID DT_ATMEL_SAM_USART_40028000_PERIPHERAL_ID
#define DT_USART_SAM_PORT_2_NAME DT_ATMEL_SAM_USART_4002C000_LABEL
#define DT_USART_SAM_PORT_2_BAUD_RATE DT_ATMEL_SAM_USART_4002C000_CURRENT_SPEED
#define DT_USART_SAM_PORT_2_IRQ DT_ATMEL_SAM_USART_4002C000_IRQ_0
#define DT_USART_SAM_PORT_2_IRQ_PRIO DT_ATMEL_SAM_USART_4002C000_IRQ_0_PRIORITY
#define DT_USART_SAM_PORT_2_PERIPHERAL_ID DT_ATMEL_SAM_USART_4002C000_PERIPHERAL_ID

#define DT_ADC_0_BASE_ADDRESS DT_ATMEL_SAM_AFEC_4003C000_BASE_ADDRESS
#define DT_ADC_0_IRQ DT_ATMEL_SAM_AFEC_4003C000_IRQ_0
#define DT_ADC_0_IRQ_PRI DT_ATMEL_SAM_AFEC_4003C000_IRQ_0_PRIORITY
Expand Down
16 changes: 0 additions & 16 deletions soc/arm/atmel_sam/samv71/dts_fixup.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,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_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
#define DT_USART_SAM_PORT_0_IRQ_PRIO DT_ATMEL_SAM_USART_40024000_IRQ_0_PRIORITY
#define DT_USART_SAM_PORT_0_PERIPHERAL_ID DT_ATMEL_SAM_USART_40024000_PERIPHERAL_ID
#define DT_USART_SAM_PORT_1_NAME DT_ATMEL_SAM_USART_40028000_LABEL
#define DT_USART_SAM_PORT_1_BAUD_RATE DT_ATMEL_SAM_USART_40028000_CURRENT_SPEED
#define DT_USART_SAM_PORT_1_IRQ DT_ATMEL_SAM_USART_40028000_IRQ_0
#define DT_USART_SAM_PORT_1_IRQ_PRIO DT_ATMEL_SAM_USART_40028000_IRQ_0_PRIORITY
#define DT_USART_SAM_PORT_1_PERIPHERAL_ID DT_ATMEL_SAM_USART_40028000_PERIPHERAL_ID
#define DT_USART_SAM_PORT_2_NAME DT_ATMEL_SAM_USART_4002C000_LABEL
#define DT_USART_SAM_PORT_2_BAUD_RATE DT_ATMEL_SAM_USART_4002C000_CURRENT_SPEED
#define DT_USART_SAM_PORT_2_IRQ DT_ATMEL_SAM_USART_4002C000_IRQ_0
#define DT_USART_SAM_PORT_2_IRQ_PRIO DT_ATMEL_SAM_USART_4002C000_IRQ_0_PRIORITY
#define DT_USART_SAM_PORT_2_PERIPHERAL_ID DT_ATMEL_SAM_USART_4002C000_PERIPHERAL_ID

#define DT_ADC_0_BASE_ADDRESS DT_ATMEL_SAM_AFEC_4003C000_BASE_ADDRESS
#define DT_ADC_0_IRQ DT_ATMEL_SAM_AFEC_4003C000_IRQ_0
#define DT_ADC_0_IRQ_PRI DT_ATMEL_SAM_AFEC_4003C000_IRQ_0_PRIORITY
Expand Down

0 comments on commit 31a13cd

Please sign in to comment.