drivers: spi: sam0: Convert dma to use DEVICE_DT_GET
Replace device_get_binding with DEVICE_DT_GET for getting access to the dma controller device. Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
parent
c2f7382007
commit
0f0308c197
1 changed files with 13 additions and 19 deletions
|
@ -33,7 +33,7 @@ struct spi_sam0_config {
|
||||||
uint16_t gclk_clkctrl_id;
|
uint16_t gclk_clkctrl_id;
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_SPI_ASYNC
|
#ifdef CONFIG_SPI_ASYNC
|
||||||
char *dma_dev;
|
const struct device *dma_dev;
|
||||||
uint8_t tx_dma_request;
|
uint8_t tx_dma_request;
|
||||||
uint8_t tx_dma_channel;
|
uint8_t tx_dma_channel;
|
||||||
uint8_t rx_dma_request;
|
uint8_t rx_dma_request;
|
||||||
|
@ -46,7 +46,6 @@ struct spi_sam0_data {
|
||||||
struct spi_context ctx;
|
struct spi_context ctx;
|
||||||
#ifdef CONFIG_SPI_ASYNC
|
#ifdef CONFIG_SPI_ASYNC
|
||||||
const struct device *dev;
|
const struct device *dev;
|
||||||
const struct device *dma;
|
|
||||||
uint32_t dma_segment_len;
|
uint32_t dma_segment_len;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
@ -473,20 +472,19 @@ static int spi_sam0_dma_rx_load(const struct device *dev, uint8_t *buf,
|
||||||
dma_blk.source_address = (uint32_t)(&(regs->DATA.reg));
|
dma_blk.source_address = (uint32_t)(&(regs->DATA.reg));
|
||||||
dma_blk.source_addr_adj = DMA_ADDR_ADJ_NO_CHANGE;
|
dma_blk.source_addr_adj = DMA_ADDR_ADJ_NO_CHANGE;
|
||||||
|
|
||||||
retval = dma_config(data->dma, cfg->rx_dma_channel,
|
retval = dma_config(cfg->dma_dev, cfg->rx_dma_channel,
|
||||||
&dma_cfg);
|
&dma_cfg);
|
||||||
if (retval != 0) {
|
if (retval != 0) {
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
return dma_start(data->dma, cfg->rx_dma_channel);
|
return dma_start(cfg->dma_dev, cfg->rx_dma_channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int spi_sam0_dma_tx_load(const struct device *dev, const uint8_t *buf,
|
static int spi_sam0_dma_tx_load(const struct device *dev, const uint8_t *buf,
|
||||||
size_t len)
|
size_t len)
|
||||||
{
|
{
|
||||||
const struct spi_sam0_config *cfg = dev->config;
|
const struct spi_sam0_config *cfg = dev->config;
|
||||||
struct spi_sam0_data *data = dev->data;
|
|
||||||
SercomSpi *regs = cfg->regs;
|
SercomSpi *regs = cfg->regs;
|
||||||
struct dma_config dma_cfg = { 0 };
|
struct dma_config dma_cfg = { 0 };
|
||||||
struct dma_block_config dma_blk = { 0 };
|
struct dma_block_config dma_blk = { 0 };
|
||||||
|
@ -513,14 +511,14 @@ static int spi_sam0_dma_tx_load(const struct device *dev, const uint8_t *buf,
|
||||||
dma_blk.dest_address = (uint32_t)(&(regs->DATA.reg));
|
dma_blk.dest_address = (uint32_t)(&(regs->DATA.reg));
|
||||||
dma_blk.dest_addr_adj = DMA_ADDR_ADJ_NO_CHANGE;
|
dma_blk.dest_addr_adj = DMA_ADDR_ADJ_NO_CHANGE;
|
||||||
|
|
||||||
retval = dma_config(data->dma, cfg->tx_dma_channel,
|
retval = dma_config(cfg->dma_dev, cfg->tx_dma_channel,
|
||||||
&dma_cfg);
|
&dma_cfg);
|
||||||
|
|
||||||
if (retval != 0) {
|
if (retval != 0) {
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
return dma_start(data->dma, cfg->tx_dma_channel);
|
return dma_start(cfg->dma_dev, cfg->tx_dma_channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool spi_sam0_dma_advance_segment(const struct device *dev)
|
static bool spi_sam0_dma_advance_segment(const struct device *dev)
|
||||||
|
@ -607,8 +605,8 @@ static void spi_sam0_dma_rx_done(const struct device *dma_dev, void *arg,
|
||||||
|
|
||||||
retval = spi_sam0_dma_advance_buffers(dev);
|
retval = spi_sam0_dma_advance_buffers(dev);
|
||||||
if (retval != 0) {
|
if (retval != 0) {
|
||||||
dma_stop(data->dma, cfg->tx_dma_channel);
|
dma_stop(cfg->dma_dev, cfg->tx_dma_channel);
|
||||||
dma_stop(data->dma, cfg->rx_dma_channel);
|
dma_stop(cfg->dma_dev, cfg->rx_dma_channel);
|
||||||
spi_context_cs_control(&data->ctx, false);
|
spi_context_cs_control(&data->ctx, false);
|
||||||
spi_context_complete(&data->ctx, retval);
|
spi_context_complete(&data->ctx, retval);
|
||||||
return;
|
return;
|
||||||
|
@ -626,10 +624,6 @@ static int spi_sam0_transceive_async(const struct device *dev,
|
||||||
struct spi_sam0_data *data = dev->data;
|
struct spi_sam0_data *data = dev->data;
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
if (!data->dma) {
|
|
||||||
return -ENOTSUP;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Transmit clocks the output and we use receive to determine when
|
* Transmit clocks the output and we use receive to determine when
|
||||||
* the transmit is done, so we always need both
|
* the transmit is done, so we always need both
|
||||||
|
@ -658,8 +652,8 @@ static int spi_sam0_transceive_async(const struct device *dev,
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_cs:
|
err_cs:
|
||||||
dma_stop(data->dma, cfg->tx_dma_channel);
|
dma_stop(cfg->dma_dev, cfg->tx_dma_channel);
|
||||||
dma_stop(data->dma, cfg->rx_dma_channel);
|
dma_stop(cfg->dma_dev, cfg->rx_dma_channel);
|
||||||
|
|
||||||
spi_context_cs_control(&data->ctx, false);
|
spi_context_cs_control(&data->ctx, false);
|
||||||
|
|
||||||
|
@ -706,10 +700,10 @@ static int spi_sam0_init(const struct device *dev)
|
||||||
wait_synchronization(regs);
|
wait_synchronization(regs);
|
||||||
|
|
||||||
#ifdef CONFIG_SPI_ASYNC
|
#ifdef CONFIG_SPI_ASYNC
|
||||||
|
if (!device_is_ready(cfg->dma_dev)) {
|
||||||
data->dma = device_get_binding(cfg->dma_dev);
|
return -ENODEV;
|
||||||
|
}
|
||||||
data->dev = dev;
|
data->dev = dev;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
spi_context_unlock_unconditionally(&data->ctx);
|
spi_context_unlock_unconditionally(&data->ctx);
|
||||||
|
@ -731,7 +725,7 @@ static const struct spi_driver_api spi_sam0_driver_api = {
|
||||||
|
|
||||||
#if CONFIG_SPI_ASYNC
|
#if CONFIG_SPI_ASYNC
|
||||||
#define SPI_SAM0_DMA_CHANNELS(n) \
|
#define SPI_SAM0_DMA_CHANNELS(n) \
|
||||||
.dma_dev = ATMEL_SAM0_DT_INST_DMA_NAME(n, tx), \
|
.dma_dev = DEVICE_DT_GET(ATMEL_SAM0_DT_INST_DMA_CTLR(n, tx)), \
|
||||||
.tx_dma_request = ATMEL_SAM0_DT_INST_DMA_TRIGSRC(n, tx), \
|
.tx_dma_request = ATMEL_SAM0_DT_INST_DMA_TRIGSRC(n, tx), \
|
||||||
.tx_dma_channel = ATMEL_SAM0_DT_INST_DMA_CHANNEL(n, tx), \
|
.tx_dma_channel = ATMEL_SAM0_DT_INST_DMA_CHANNEL(n, tx), \
|
||||||
.rx_dma_request = ATMEL_SAM0_DT_INST_DMA_TRIGSRC(n, rx), \
|
.rx_dma_request = ATMEL_SAM0_DT_INST_DMA_TRIGSRC(n, rx), \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue