Skip to content

Commit 513aa78

Browse files
LaurentiuM1234nashif
authored andcommitted
dma: add channel release callback
This is useful for releasing channel resources "allocated" during channel request. These resources can refer to enabled IRQs, PDs, etc... Signed-off-by: Laurentiu Mihalcea <[email protected]>
1 parent 4a2f89b commit 513aa78

File tree

1 file changed

+21
-0
lines changed
  • include/zephyr/drivers

1 file changed

+21
-0
lines changed

include/zephyr/drivers/dma.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,20 @@ typedef int (*dma_api_get_attribute)(const struct device *dev, uint32_t type, ui
352352
typedef bool (*dma_api_chan_filter)(const struct device *dev,
353353
int channel, void *filter_param);
354354

355+
/**
356+
* @typedef dma_chan_release
357+
* @brief channel release function call
358+
*
359+
* used to release channel resources "allocated" during the
360+
* request phase. These resources can refer to enabled PDs, IRQs
361+
* etc...
362+
*
363+
* @param dev Pointer to the DMA device instance
364+
* @param channel channel id to use
365+
*/
366+
typedef void (*dma_api_chan_release)(const struct device *dev,
367+
uint32_t channel);
368+
355369
__subsystem struct dma_driver_api {
356370
dma_api_config config;
357371
dma_api_reload reload;
@@ -362,6 +376,7 @@ __subsystem struct dma_driver_api {
362376
dma_api_get_status get_status;
363377
dma_api_get_attribute get_attribute;
364378
dma_api_chan_filter chan_filter;
379+
dma_api_chan_release chan_release;
365380
};
366381
/**
367382
* @endcond
@@ -595,13 +610,19 @@ __syscall void dma_release_channel(const struct device *dev,
595610
static inline void z_impl_dma_release_channel(const struct device *dev,
596611
uint32_t channel)
597612
{
613+
const struct dma_driver_api *api =
614+
(const struct dma_driver_api *)dev->api;
598615
struct dma_context *dma_ctx = (struct dma_context *)dev->data;
599616

600617
if (dma_ctx->magic != DMA_MAGIC) {
601618
return;
602619
}
603620

604621
if ((int)channel < dma_ctx->dma_channels) {
622+
if (api->chan_release) {
623+
api->chan_release(dev, channel);
624+
}
625+
605626
atomic_clear_bit(dma_ctx->atomic, channel);
606627
}
607628

0 commit comments

Comments
 (0)