drivers: serial: uart_sam0: rework devicetree support
Rework the devicetree to utilize new DT_INST macros and extract per instance data for clocks and dma from devicetree. We update the atmel,sam0-uart binding for dma to replace the rxdma and txdma properties with proper 'dmas' property. Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
parent
70ae3361f8
commit
bd639fc332
2 changed files with 56 additions and 117 deletions
|
@ -1045,15 +1045,14 @@ static const struct uart_driver_api uart_sam0_driver_api = {
|
||||||
};
|
};
|
||||||
|
|
||||||
#if CONFIG_UART_INTERRUPT_DRIVEN || CONFIG_UART_ASYNC_API
|
#if CONFIG_UART_INTERRUPT_DRIVEN || CONFIG_UART_ASYNC_API
|
||||||
#define DT_ATMEL_SAM0_UART_SERCOM_IRQ(n, m) DT_ATMEL_SAM0_UART_SERCOM_ ## n ## _IRQ_ ## m
|
|
||||||
#define DT_ATMEL_SAM0_UART_SERCOM_IRQ_PRIORITY(n, m) DT_ATMEL_SAM0_UART_SERCOM_ ## n ## _IRQ_ ## m ## _PRIORITY
|
|
||||||
|
|
||||||
#define SAM0_UART_IRQ_CONNECT(n, m) \
|
#define SAM0_UART_IRQ_CONNECT(n, m) \
|
||||||
do { \
|
do { \
|
||||||
IRQ_CONNECT(DT_ATMEL_SAM0_UART_SERCOM_IRQ(n, m), \
|
IRQ_CONNECT(DT_INST_IRQ_BY_IDX(n, m, irq), \
|
||||||
DT_ATMEL_SAM0_UART_SERCOM_IRQ_PRIORITY(n, m), \
|
DT_INST_IRQ_BY_IDX(n, m, priority), \
|
||||||
uart_sam0_isr, DEVICE_GET(uart_sam0_##n), 0); \
|
uart_sam0_isr, \
|
||||||
irq_enable(DT_ATMEL_SAM0_UART_SERCOM_IRQ(n, m)); \
|
DEVICE_GET(uart_sam0_##n), 0); \
|
||||||
|
irq_enable(DT_INST_IRQ_BY_IDX(n, m, irq)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define UART_SAM0_IRQ_HANDLER_DECL(n) \
|
#define UART_SAM0_IRQ_HANDLER_DECL(n) \
|
||||||
|
@ -1084,120 +1083,53 @@ static void uart_sam0_irq_config_##n(struct device *dev) \
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CONFIG_UART_ASYNC_API
|
#if CONFIG_UART_ASYNC_API
|
||||||
#ifndef DT_ATMEL_SAM0_UART_SERCOM_0_TXDMA
|
#define UART_SAM0_DMA_CHANNELS(n) \
|
||||||
#define DT_ATMEL_SAM0_UART_SERCOM_0_TXDMA 0xFFU
|
.tx_dma_request = ATMEL_SAM0_DT_INST_DMA_TRIGSRC(n, tx), \
|
||||||
#endif
|
.tx_dma_channel = ATMEL_SAM0_DT_INST_DMA_CHANNEL(n, tx), \
|
||||||
#ifndef DT_ATMEL_SAM0_UART_SERCOM_0_RXDMA
|
.rx_dma_request = ATMEL_SAM0_DT_INST_DMA_TRIGSRC(n, rx), \
|
||||||
#define DT_ATMEL_SAM0_UART_SERCOM_0_RXDMA 0xFFU
|
.rx_dma_channel = ATMEL_SAM0_DT_INST_DMA_CHANNEL(n, rx),
|
||||||
#endif
|
|
||||||
#ifndef DT_ATMEL_SAM0_UART_SERCOM_1_TXDMA
|
|
||||||
#define DT_ATMEL_SAM0_UART_SERCOM_1_TXDMA 0xFFU
|
|
||||||
#endif
|
|
||||||
#ifndef DT_ATMEL_SAM0_UART_SERCOM_1_RXDMA
|
|
||||||
#define DT_ATMEL_SAM0_UART_SERCOM_1_RXDMA 0xFFU
|
|
||||||
#endif
|
|
||||||
#ifndef DT_ATMEL_SAM0_UART_SERCOM_2_TXDMA
|
|
||||||
#define DT_ATMEL_SAM0_UART_SERCOM_2_TXDMA 0xFFU
|
|
||||||
#endif
|
|
||||||
#ifndef DT_ATMEL_SAM0_UART_SERCOM_2_RXDMA
|
|
||||||
#define DT_ATMEL_SAM0_UART_SERCOM_2_RXDMA 0xFFU
|
|
||||||
#endif
|
|
||||||
#ifndef DT_ATMEL_SAM0_UART_SERCOM_3_TXDMA
|
|
||||||
#define DT_ATMEL_SAM0_UART_SERCOM_3_TXDMA 0xFFU
|
|
||||||
#endif
|
|
||||||
#ifndef DT_ATMEL_SAM0_UART_SERCOM_3_RXDMA
|
|
||||||
#define DT_ATMEL_SAM0_UART_SERCOM_3_RXDMA 0xFFU
|
|
||||||
#endif
|
|
||||||
#ifndef DT_ATMEL_SAM0_UART_SERCOM_4_TXDMA
|
|
||||||
#define DT_ATMEL_SAM0_UART_SERCOM_4_TXDMA 0xFFU
|
|
||||||
#endif
|
|
||||||
#ifndef DT_ATMEL_SAM0_UART_SERCOM_4_RXDMA
|
|
||||||
#define DT_ATMEL_SAM0_UART_SERCOM_4_RXDMA 0xFFU
|
|
||||||
#endif
|
|
||||||
#ifndef DT_ATMEL_SAM0_UART_SERCOM_5_TXDMA
|
|
||||||
#define DT_ATMEL_SAM0_UART_SERCOM_5_TXDMA 0xFFU
|
|
||||||
#endif
|
|
||||||
#ifndef DT_ATMEL_SAM0_UART_SERCOM_5_RXDMA
|
|
||||||
#define DT_ATMEL_SAM0_UART_SERCOM_5_RXDMA 0xFFU
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define UART_SAM0_DMA_CHANNELS(n) \
|
|
||||||
.tx_dma_request = SERCOM##n##_DMAC_ID_TX, \
|
|
||||||
.tx_dma_channel = DT_ATMEL_SAM0_UART_SERCOM_##n##_TXDMA, \
|
|
||||||
.rx_dma_request = SERCOM##n##_DMAC_ID_RX, \
|
|
||||||
.rx_dma_channel = DT_ATMEL_SAM0_UART_SERCOM_##n##_RXDMA
|
|
||||||
#else
|
#else
|
||||||
#define UART_SAM0_DMA_CHANNELS(n)
|
#define UART_SAM0_DMA_CHANNELS(n)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define UART_SAM0_SERCOM_PADS(n) \
|
#define UART_SAM0_SERCOM_PADS(n) \
|
||||||
(DT_ATMEL_SAM0_UART_SERCOM_##n##_RXPO << SERCOM_USART_CTRLA_RXPO_Pos) | \
|
(DT_INST_PROP(n, rxpo) << SERCOM_USART_CTRLA_RXPO_Pos) | \
|
||||||
(DT_ATMEL_SAM0_UART_SERCOM_##n##_TXPO << SERCOM_USART_CTRLA_TXPO_Pos)
|
(DT_INST_PROP(n, txpo) << SERCOM_USART_CTRLA_TXPO_Pos)
|
||||||
|
|
||||||
#ifdef MCLK
|
#ifdef MCLK
|
||||||
#define UART_SAM0_CONFIG_DEFN(n) \
|
#define UART_SAM0_CONFIG_DEFN(n) \
|
||||||
static const struct uart_sam0_dev_cfg uart_sam0_config_##n = { \
|
static const struct uart_sam0_dev_cfg uart_sam0_config_##n = { \
|
||||||
.regs = (SercomUsart *)DT_ATMEL_SAM0_UART_SERCOM_##n##_BASE_ADDRESS, \
|
.regs = (SercomUsart *)DT_INST_REG_ADDR(n), \
|
||||||
.baudrate = DT_ATMEL_SAM0_UART_SERCOM_##n##_CURRENT_SPEED, \
|
.baudrate = DT_INST_PROP(n, current_speed), \
|
||||||
.mclk = MCLK_SERCOM##n, \
|
.mclk = (volatile uint32_t *)MCLK_MASK_DT_INT_REG_ADDR(n), \
|
||||||
.mclk_mask = MCLK_SERCOM##n##_MASK, \
|
.mclk_mask = BIT(DT_INST_CLOCKS_CELL_BY_NAME(n, mclk, bit)), \
|
||||||
.gclk_core_id = SERCOM##n##_GCLK_ID_CORE, \
|
.gclk_core_id = DT_INST_CLOCKS_CELL_BY_NAME(n, gclk, periph_ch),\
|
||||||
.pads = UART_SAM0_SERCOM_PADS(n), \
|
.pads = UART_SAM0_SERCOM_PADS(n), \
|
||||||
UART_SAM0_IRQ_HANDLER_FUNC(n) \
|
UART_SAM0_IRQ_HANDLER_FUNC(n) \
|
||||||
UART_SAM0_DMA_CHANNELS(n) \
|
UART_SAM0_DMA_CHANNELS(n) \
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#define UART_SAM0_CONFIG_DEFN(n) \
|
#define UART_SAM0_CONFIG_DEFN(n) \
|
||||||
static const struct uart_sam0_dev_cfg uart_sam0_config_##n = { \
|
static const struct uart_sam0_dev_cfg uart_sam0_config_##n = { \
|
||||||
.regs = (SercomUsart *)DT_ATMEL_SAM0_UART_SERCOM_##n##_BASE_ADDRESS, \
|
.regs = (SercomUsart *)DT_INST_REG_ADDR(n), \
|
||||||
.baudrate = DT_ATMEL_SAM0_UART_SERCOM_##n##_CURRENT_SPEED, \
|
.baudrate = DT_INST_PROP(n, current_speed), \
|
||||||
.pm_apbcmask = PM_APBCMASK_SERCOM##n, \
|
.pm_apbcmask = BIT(DT_INST_CLOCKS_CELL_BY_NAME(n, pm, bit)), \
|
||||||
.gclk_clkctrl_id = GCLK_CLKCTRL_ID_SERCOM##n##_CORE, \
|
.gclk_clkctrl_id = DT_INST_CLOCKS_CELL_BY_NAME(n, gclk, clkctrl_id),\
|
||||||
.pads = UART_SAM0_SERCOM_PADS(n), \
|
.pads = UART_SAM0_SERCOM_PADS(n), \
|
||||||
UART_SAM0_IRQ_HANDLER_FUNC(n) \
|
UART_SAM0_IRQ_HANDLER_FUNC(n) \
|
||||||
UART_SAM0_DMA_CHANNELS(n) \
|
UART_SAM0_DMA_CHANNELS(n) \
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define UART_SAM0_DEVICE_INIT(n) \
|
#define UART_SAM0_DEVICE_INIT(n) \
|
||||||
static struct uart_sam0_dev_data uart_sam0_data_##n; \
|
static struct uart_sam0_dev_data uart_sam0_data_##n; \
|
||||||
UART_SAM0_IRQ_HANDLER_DECL(n); \
|
UART_SAM0_IRQ_HANDLER_DECL(n); \
|
||||||
UART_SAM0_CONFIG_DEFN(n); \
|
UART_SAM0_CONFIG_DEFN(n); \
|
||||||
DEVICE_AND_API_INIT(uart_sam0_##n, DT_ATMEL_SAM0_UART_SERCOM_##n##_LABEL, \
|
DEVICE_AND_API_INIT(uart_sam0_##n, DT_INST_LABEL(n), \
|
||||||
uart_sam0_init, &uart_sam0_data_##n, \
|
uart_sam0_init, &uart_sam0_data_##n, \
|
||||||
&uart_sam0_config_##n, PRE_KERNEL_1, \
|
&uart_sam0_config_##n, PRE_KERNEL_1, \
|
||||||
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
|
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
|
||||||
&uart_sam0_driver_api); \
|
&uart_sam0_driver_api); \
|
||||||
UART_SAM0_IRQ_HANDLER(n)
|
UART_SAM0_IRQ_HANDLER(n)
|
||||||
|
|
||||||
#if DT_ATMEL_SAM0_UART_SERCOM_0_BASE_ADDRESS
|
DT_INST_FOREACH(UART_SAM0_DEVICE_INIT)
|
||||||
UART_SAM0_DEVICE_INIT(0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if DT_ATMEL_SAM0_UART_SERCOM_1_BASE_ADDRESS
|
|
||||||
UART_SAM0_DEVICE_INIT(1)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if DT_ATMEL_SAM0_UART_SERCOM_2_BASE_ADDRESS
|
|
||||||
UART_SAM0_DEVICE_INIT(2)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if DT_ATMEL_SAM0_UART_SERCOM_3_BASE_ADDRESS
|
|
||||||
UART_SAM0_DEVICE_INIT(3)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if DT_ATMEL_SAM0_UART_SERCOM_4_BASE_ADDRESS
|
|
||||||
UART_SAM0_DEVICE_INIT(4)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if DT_ATMEL_SAM0_UART_SERCOM_5_BASE_ADDRESS
|
|
||||||
UART_SAM0_DEVICE_INIT(5)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if DT_ATMEL_SAM0_UART_SERCOM_6_BASE_ADDRESS
|
|
||||||
UART_SAM0_DEVICE_INIT(6)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if DT_ATMEL_SAM0_UART_SERCOM7_BASE_ADDRESS
|
|
||||||
UART_SAM0_DEVICE_INIT(7)
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -27,12 +27,19 @@ properties:
|
||||||
required: true
|
required: true
|
||||||
description: Transmit Data Pinout
|
description: Transmit Data Pinout
|
||||||
|
|
||||||
rxdma:
|
dmas:
|
||||||
type: int
|
description: |
|
||||||
required: false
|
Optional TX & RX dma specifiers. Each specifier will have a phandle
|
||||||
description: Receive DMA channel
|
reference to the dmac controller, the channel number, and peripheral
|
||||||
|
trigger source.
|
||||||
|
|
||||||
txdma:
|
For example dmas for TX, RX on SERCOM3
|
||||||
type: int
|
dmas = <&dmac 0 0xb>, <&dmac 0 0xa>;
|
||||||
required: false
|
|
||||||
description: Transmit DMA channel
|
dma-names:
|
||||||
|
description: |
|
||||||
|
Required if the dmas property exists. This should be "tx" and "rx"
|
||||||
|
to match the dmas property.
|
||||||
|
|
||||||
|
For example
|
||||||
|
dma-names = "tx", "rx";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue