i2s: stm32: 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
19356a0a01
commit
34861b592b
2 changed files with 12 additions and 22 deletions
|
@ -530,7 +530,7 @@ static void dma_rx_callback(const struct device *dma_dev, void *arg,
|
||||||
goto rx_disable;
|
goto rx_disable;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = reload_dma(dev_data->dev_dma_rx, stream->dma_channel,
|
ret = reload_dma(stream->dev_dma, stream->dma_channel,
|
||||||
&stream->dma_cfg,
|
&stream->dma_cfg,
|
||||||
(void *)LL_SPI_DMA_GetRegAddr(cfg->i2s),
|
(void *)LL_SPI_DMA_GetRegAddr(cfg->i2s),
|
||||||
stream->mem_block,
|
stream->mem_block,
|
||||||
|
@ -614,7 +614,7 @@ static void dma_tx_callback(const struct device *dma_dev, void *arg,
|
||||||
/* Assure cache coherency before DMA read operation */
|
/* Assure cache coherency before DMA read operation */
|
||||||
DCACHE_CLEAN(stream->mem_block, mem_block_size);
|
DCACHE_CLEAN(stream->mem_block, mem_block_size);
|
||||||
|
|
||||||
ret = reload_dma(dev_data->dev_dma_tx, stream->dma_channel,
|
ret = reload_dma(stream->dev_dma, stream->dma_channel,
|
||||||
&stream->dma_cfg,
|
&stream->dma_cfg,
|
||||||
stream->mem_block,
|
stream->mem_block,
|
||||||
(void *)LL_SPI_DMA_GetRegAddr(cfg->i2s),
|
(void *)LL_SPI_DMA_GetRegAddr(cfg->i2s),
|
||||||
|
@ -685,14 +685,12 @@ static int i2s_stm32_initialize(const struct device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the binding to the DMA device */
|
/* Get the binding to the DMA device */
|
||||||
dev_data->dev_dma_tx = device_get_binding(dev_data->tx.dma_name);
|
if (!device_is_ready(dev_data->tx.dev_dma)) {
|
||||||
if (!dev_data->dev_dma_tx) {
|
LOG_ERR("%s device not ready", dev_data->tx.dev_dma->name);
|
||||||
LOG_ERR("%s device not found", dev_data->tx.dma_name);
|
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
dev_data->dev_dma_rx = device_get_binding(dev_data->rx.dma_name);
|
if (!device_is_ready(dev_data->rx.dev_dma)) {
|
||||||
if (!dev_data->dev_dma_rx) {
|
LOG_ERR("%s device not ready", dev_data->rx.dev_dma->name);
|
||||||
LOG_ERR("%s device not found", dev_data->rx.dma_name);
|
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -704,7 +702,6 @@ static int i2s_stm32_initialize(const struct device *dev)
|
||||||
static int rx_stream_start(struct stream *stream, const struct device *dev)
|
static int rx_stream_start(struct stream *stream, const struct device *dev)
|
||||||
{
|
{
|
||||||
const struct i2s_stm32_cfg *cfg = DEV_CFG(dev);
|
const struct i2s_stm32_cfg *cfg = DEV_CFG(dev);
|
||||||
struct i2s_stm32_data *const dev_data = DEV_DATA(dev);
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = k_mem_slab_alloc(stream->cfg.mem_slab, &stream->mem_block,
|
ret = k_mem_slab_alloc(stream->cfg.mem_slab, &stream->mem_block,
|
||||||
|
@ -722,7 +719,7 @@ static int rx_stream_start(struct stream *stream, const struct device *dev)
|
||||||
/* remember active RX DMA channel (used in callback) */
|
/* remember active RX DMA channel (used in callback) */
|
||||||
active_dma_rx_channel[stream->dma_channel] = dev;
|
active_dma_rx_channel[stream->dma_channel] = dev;
|
||||||
|
|
||||||
ret = start_dma(dev_data->dev_dma_rx, stream->dma_channel,
|
ret = start_dma(stream->dev_dma, stream->dma_channel,
|
||||||
&stream->dma_cfg,
|
&stream->dma_cfg,
|
||||||
(void *)LL_SPI_DMA_GetRegAddr(cfg->i2s),
|
(void *)LL_SPI_DMA_GetRegAddr(cfg->i2s),
|
||||||
stream->src_addr_increment, stream->mem_block,
|
stream->src_addr_increment, stream->mem_block,
|
||||||
|
@ -744,7 +741,6 @@ static int rx_stream_start(struct stream *stream, const struct device *dev)
|
||||||
static int tx_stream_start(struct stream *stream, const struct device *dev)
|
static int tx_stream_start(struct stream *stream, const struct device *dev)
|
||||||
{
|
{
|
||||||
const struct i2s_stm32_cfg *cfg = DEV_CFG(dev);
|
const struct i2s_stm32_cfg *cfg = DEV_CFG(dev);
|
||||||
struct i2s_stm32_data *const dev_data = DEV_DATA(dev);
|
|
||||||
size_t mem_block_size;
|
size_t mem_block_size;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -767,7 +763,7 @@ static int tx_stream_start(struct stream *stream, const struct device *dev)
|
||||||
/* remember active TX DMA channel (used in callback) */
|
/* remember active TX DMA channel (used in callback) */
|
||||||
active_dma_tx_channel[stream->dma_channel] = dev;
|
active_dma_tx_channel[stream->dma_channel] = dev;
|
||||||
|
|
||||||
ret = start_dma(dev_data->dev_dma_tx, stream->dma_channel,
|
ret = start_dma(stream->dev_dma, stream->dma_channel,
|
||||||
&stream->dma_cfg,
|
&stream->dma_cfg,
|
||||||
stream->mem_block, stream->src_addr_increment,
|
stream->mem_block, stream->src_addr_increment,
|
||||||
(void *)LL_SPI_DMA_GetRegAddr(cfg->i2s),
|
(void *)LL_SPI_DMA_GetRegAddr(cfg->i2s),
|
||||||
|
@ -789,13 +785,11 @@ static int tx_stream_start(struct stream *stream, const struct device *dev)
|
||||||
static void rx_stream_disable(struct stream *stream, const struct device *dev)
|
static void rx_stream_disable(struct stream *stream, const struct device *dev)
|
||||||
{
|
{
|
||||||
const struct i2s_stm32_cfg *cfg = DEV_CFG(dev);
|
const struct i2s_stm32_cfg *cfg = DEV_CFG(dev);
|
||||||
struct i2s_stm32_data *const dev_data = DEV_DATA(dev);
|
|
||||||
const struct device *dev_dma = dev_data->dev_dma_rx;
|
|
||||||
|
|
||||||
LL_I2S_DisableDMAReq_RX(cfg->i2s);
|
LL_I2S_DisableDMAReq_RX(cfg->i2s);
|
||||||
LL_I2S_DisableIT_ERR(cfg->i2s);
|
LL_I2S_DisableIT_ERR(cfg->i2s);
|
||||||
|
|
||||||
dma_stop(dev_dma, stream->dma_channel);
|
dma_stop(stream->dev_dma, stream->dma_channel);
|
||||||
if (stream->mem_block != NULL) {
|
if (stream->mem_block != NULL) {
|
||||||
k_mem_slab_free(stream->cfg.mem_slab, &stream->mem_block);
|
k_mem_slab_free(stream->cfg.mem_slab, &stream->mem_block);
|
||||||
stream->mem_block = NULL;
|
stream->mem_block = NULL;
|
||||||
|
@ -809,13 +803,11 @@ static void rx_stream_disable(struct stream *stream, const struct device *dev)
|
||||||
static void tx_stream_disable(struct stream *stream, const struct device *dev)
|
static void tx_stream_disable(struct stream *stream, const struct device *dev)
|
||||||
{
|
{
|
||||||
const struct i2s_stm32_cfg *cfg = DEV_CFG(dev);
|
const struct i2s_stm32_cfg *cfg = DEV_CFG(dev);
|
||||||
struct i2s_stm32_data *const dev_data = DEV_DATA(dev);
|
|
||||||
const struct device *dev_dma = dev_data->dev_dma_tx;
|
|
||||||
|
|
||||||
LL_I2S_DisableDMAReq_TX(cfg->i2s);
|
LL_I2S_DisableDMAReq_TX(cfg->i2s);
|
||||||
LL_I2S_DisableIT_ERR(cfg->i2s);
|
LL_I2S_DisableIT_ERR(cfg->i2s);
|
||||||
|
|
||||||
dma_stop(dev_dma, stream->dma_channel);
|
dma_stop(stream->dev_dma, stream->dma_channel);
|
||||||
if (stream->mem_block != NULL) {
|
if (stream->mem_block != NULL) {
|
||||||
k_mem_slab_free(stream->cfg.mem_slab, &stream->mem_block);
|
k_mem_slab_free(stream->cfg.mem_slab, &stream->mem_block);
|
||||||
stream->mem_block = NULL;
|
stream->mem_block = NULL;
|
||||||
|
@ -867,7 +859,7 @@ static const struct device *get_dev_from_tx_dma_channel(uint32_t dma_channel)
|
||||||
/* src_dev and dest_dev should be 'MEMORY' or 'PERIPHERAL'. */
|
/* src_dev and dest_dev should be 'MEMORY' or 'PERIPHERAL'. */
|
||||||
#define I2S_DMA_CHANNEL_INIT(index, dir, dir_cap, src_dev, dest_dev) \
|
#define I2S_DMA_CHANNEL_INIT(index, dir, dir_cap, src_dev, dest_dev) \
|
||||||
.dir = { \
|
.dir = { \
|
||||||
.dma_name = DT_DMAS_LABEL_BY_NAME(DT_NODELABEL(i2s##index), dir),\
|
.dev_dma = DEVICE_DT_GET(DT_DMAS_CTLR_BY_NAME(DT_NODELABEL(i2s##index), dir)),\
|
||||||
.dma_channel = \
|
.dma_channel = \
|
||||||
DT_DMAS_CELL_BY_NAME(DT_NODELABEL(i2s##index), dir, channel),\
|
DT_DMAS_CELL_BY_NAME(DT_NODELABEL(i2s##index), dir, channel),\
|
||||||
.dma_cfg = { \
|
.dma_cfg = { \
|
||||||
|
|
|
@ -81,7 +81,7 @@ struct stream {
|
||||||
int32_t state;
|
int32_t state;
|
||||||
struct k_sem sem;
|
struct k_sem sem;
|
||||||
|
|
||||||
const char *dma_name;
|
const struct device *dev_dma;
|
||||||
uint32_t dma_channel;
|
uint32_t dma_channel;
|
||||||
struct dma_config dma_cfg;
|
struct dma_config dma_cfg;
|
||||||
uint8_t priority;
|
uint8_t priority;
|
||||||
|
@ -101,8 +101,6 @@ struct stream {
|
||||||
|
|
||||||
/* Device run time data */
|
/* Device run time data */
|
||||||
struct i2s_stm32_data {
|
struct i2s_stm32_data {
|
||||||
const struct device *dev_dma_tx;
|
|
||||||
const struct device *dev_dma_rx;
|
|
||||||
struct stream rx;
|
struct stream rx;
|
||||||
struct stream tx;
|
struct stream tx;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue