diff --git a/drivers/dma/dma_cavs.c b/drivers/dma/dma_cavs.c index 6eb0af1b36a454..16fc3cf4a2d7fd 100644 --- a/drivers/dma/dma_cavs.c +++ b/drivers/dma/dma_cavs.c @@ -97,7 +97,7 @@ static void dw_dma_isr(void *arg) * freed in the user callback function once * all the blocks are transferred. */ - chan_data->dma_blkcallback(dev, channel, 0); + chan_data->dma_blkcallback(chan_data->blkcallback_arg, channel, 0); } } @@ -108,7 +108,7 @@ static void dw_dma_isr(void *arg) k_free(chan_data->lli); chan_data->lli = NULL; if (chan_data->dma_tfrcallback) { - chan_data->dma_tfrcallback(dev, channel, 0); + chan_data->dma_tfrcallback(chan_data->tfrcallback_arg, channel, 0); } } } @@ -262,8 +262,10 @@ static int dw_dma_config(struct device *dev, u32_t channel, */ if (cfg->complete_callback_en) { chan_data->dma_blkcallback = cfg->dma_callback; + chan_data->blkcallback_arg = cfg->callback_arg; } else { chan_data->dma_tfrcallback = cfg->dma_callback; + chan_data->tfrcallback_arg = cfg->callback_arg; } return 0; diff --git a/drivers/dma/dma_cavs.h b/drivers/dma/dma_cavs.h index b4cb4fd6163322..849492494750e4 100644 --- a/drivers/dma/dma_cavs.h +++ b/drivers/dma/dma_cavs.h @@ -45,9 +45,11 @@ struct dma_chan_data { struct dw_lli2 *lli; u32_t cfg_lo; u32_t cfg_hi; - void (*dma_blkcallback)(struct device *dev, u32_t channel, + void *blkcallback_arg; + void (*dma_blkcallback)(void *arg, u32_t channel, int error_code); - void (*dma_tfrcallback)(struct device *dev, u32_t channel, + void *tfrcallback_arg; + void (*dma_tfrcallback)(void *arg, u32_t channel, int error_code); }; diff --git a/drivers/dma/dma_nios2_msgdma.c b/drivers/dma/dma_nios2_msgdma.c index 967e293c094bab..e843e722c81b0b 100644 --- a/drivers/dma/dma_nios2_msgdma.c +++ b/drivers/dma/dma_nios2_msgdma.c @@ -25,7 +25,8 @@ struct nios2_msgdma_dev_cfg { alt_msgdma_standard_descriptor desc; u32_t direction; struct k_sem sem_lock; - void (*dma_callback)(struct device *dev, u32_t id, + void *callback_arg; + void (*dma_callback)(void *arg, u32_t id, int error_code); }; @@ -61,7 +62,7 @@ static void nios2_msgdma_callback(void *context) LOG_DBG("msgdma csr status Reg: 0x%x", status); - dev_cfg->dma_callback((struct device *)context, 0, err_code); + dev_cfg->dma_callback(dev_cfg->callback_arg, 0, err_code); } static int nios2_msgdma_config(struct device *dev, u32_t channel, @@ -103,6 +104,7 @@ static int nios2_msgdma_config(struct device *dev, u32_t channel, k_sem_take(&dev_cfg->sem_lock, K_FOREVER); dev_cfg->dma_callback = cfg->dma_callback; + dev_cfg->callback_arg = cfg->callback_arg; dev_cfg->direction = cfg->channel_direction; dma_block = cfg->head_block; control = ALTERA_MSGDMA_DESCRIPTOR_CONTROL_TRANSFER_COMPLETE_IRQ_MASK | diff --git a/drivers/dma/dma_qmsi.c b/drivers/dma/dma_qmsi.c index db2f61a1390051..13cf1908465dfe 100644 --- a/drivers/dma/dma_qmsi.c +++ b/drivers/dma/dma_qmsi.c @@ -41,7 +41,7 @@ struct dma_qmsi_driver_data { u32_t device_power_state; qm_dma_context_t saved_ctx; #endif - void (*dma_user_callback[QM_DMA_CHANNEL_NUM])(struct device *dev, + void (*dma_user_callback[QM_DMA_CHANNEL_NUM])(void *arg, u32_t channel_id, int error_code); }; @@ -60,7 +60,8 @@ static void dma_drv_callback(void *callback_context, u32_t len, channel = context->index; data = context->dev->driver_data; - data->dma_user_callback[channel](context->dev, channel, error_code); + data->dma_user_callback[channel](data->callback_data[channel], + channel, error_code); } static int width_index(u32_t num_bytes, u32_t *index) @@ -171,6 +172,7 @@ static int dma_qmsi_chan_config(struct device *dev, u32_t channel, /* TODO: add support for using other DMA transfer types. */ qmsi_cfg.transfer_type = QM_DMA_TYPE_SINGLE; + data->callback_data[channel] = config->callback_arg; data->dma_user_callback[channel] = config->dma_callback; dma_context[channel].index = channel; diff --git a/drivers/dma/dma_sam_xdmac.c b/drivers/dma/dma_sam_xdmac.c index 39c15495f48864..123c2e14e8800d 100644 --- a/drivers/dma/dma_sam_xdmac.c +++ b/drivers/dma/dma_sam_xdmac.c @@ -26,6 +26,7 @@ LOG_MODULE_REGISTER(dma_sam_xdmac) /* DMA channel configuration */ struct sam_xdmac_channel_cfg { + void *callback_arg; dma_callback callback; }; @@ -73,7 +74,8 @@ static void sam_xdmac_isr(void *arg) /* Execute callback */ if (channel_cfg->callback) { - channel_cfg->callback(dev, channel, err); + channel_cfg->callback(channel_cfg->callback_arg, + channel, err); } } } @@ -254,6 +256,7 @@ static int sam_xdmac_config(struct device *dev, u32_t channel, } dev_data->dma_channels[channel].callback = cfg->dma_callback; + dev_data->dma_channels[channel].callback_arg = cfg->callback_arg; (void)memset(&transfer_cfg, 0, sizeof(transfer_cfg)); transfer_cfg.sa = cfg->head_block->source_address; diff --git a/drivers/dma/dma_sam_xdmac.h b/drivers/dma/dma_sam_xdmac.h index 9562f0c752566b..e7b4425a2f8e57 100644 --- a/drivers/dma/dma_sam_xdmac.h +++ b/drivers/dma/dma_sam_xdmac.h @@ -18,7 +18,7 @@ extern "C" { #endif /** DMA transfer callback */ -typedef void (*dma_callback)(struct device *dev, u32_t channel, int error_code); +typedef void (*dma_callback)(void *arg, u32_t channel, int error_code); /* XDMA_MBR_UBC */ #define XDMA_UBC_NDE (0x1u << 24) diff --git a/drivers/dma/dma_stm32f4x.c b/drivers/dma/dma_stm32f4x.c index f6e6d76d4b9556..9de35aa3ef2825 100644 --- a/drivers/dma/dma_stm32f4x.c +++ b/drivers/dma/dma_stm32f4x.c @@ -48,8 +48,8 @@ struct dma_stm32_stream { struct device *dev; struct dma_stm32_stream_reg regs; bool busy; - - void (*dma_callback)(struct device *dev, u32_t id, + void *callback_arg; + void (*dma_callback)(void *arg, u32_t id, int error_code); }; @@ -249,12 +249,12 @@ static void dma_stm32_irq_handler(void *arg, u32_t id) if ((irqstatus & DMA_STM32_TCI) && (config & DMA_STM32_SCR_TCIE)) { dma_stm32_irq_clear(ddata, id, DMA_STM32_TCI); - stream->dma_callback(stream->dev, id, 0); + stream->dma_callback(stream->callback_arg, id, 0); } else { LOG_ERR("Internal error: IRQ status: 0x%x\n", irqstatus); dma_stm32_irq_clear(ddata, id, irqstatus); - stream->dma_callback(stream->dev, id, -EIO); + stream->dma_callback(stream->callback_arg, id, -EIO); } } @@ -389,6 +389,7 @@ static int dma_stm32_config(struct device *dev, u32_t id, stream->busy = true; stream->dma_callback = config->dma_callback; stream->direction = config->channel_direction; + stream->callback_arg = config->callback_arg; if (stream->direction == MEMORY_TO_PERIPHERAL) { regs->sm0ar = (u32_t)config->head_block->source_address; diff --git a/include/dma.h b/include/dma.h index 9812dcda28c7dc..6394a53a855b8f 100644 --- a/include/dma.h +++ b/include/dma.h @@ -149,7 +149,7 @@ struct dma_config { u32_t dest_burst_length : 16; u32_t block_count; struct dma_block_config *head_block; - void * callback_arg; + void *callback_arg; void (*dma_callback)(void *callback_arg, u32_t channel, int error_code); };