|
13 | 13 | #include <zephyr/drivers/dma.h>
|
14 | 14 | #include <zephyr/drivers/clock_control.h>
|
15 | 15 | #include <zephyr/logging/log.h>
|
| 16 | +#include <zephyr/pm/device.h> |
16 | 17 | #include <zephyr/types.h>
|
17 | 18 | #include "rsi_rom_udma.h"
|
18 | 19 | #include "rsi_rom_udma_wrapper.h"
|
@@ -60,6 +61,47 @@ struct dma_siwx91x_data {
|
60 | 61 | */
|
61 | 62 | };
|
62 | 63 |
|
| 64 | +__maybe_unused static int dma_siwx91x_pm_action(const struct device *dev, |
| 65 | + enum pm_device_action action) |
| 66 | +{ |
| 67 | + const struct dma_siwx91x_config *cfg = dev->config; |
| 68 | + struct dma_siwx91x_data *data = dev->data; |
| 69 | + void *udma_handle = NULL; |
| 70 | + UDMA_RESOURCES udma_resources = { |
| 71 | + .reg = cfg->reg, |
| 72 | + .udma_irq_num = cfg->irq_number, |
| 73 | + .desc = cfg->sram_desc_addr, |
| 74 | + }; |
| 75 | + int ret; |
| 76 | + |
| 77 | + switch (action) { |
| 78 | + case PM_DEVICE_ACTION_RESUME: |
| 79 | + ret = clock_control_on(cfg->clock_dev, cfg->clock_subsys); |
| 80 | + if (ret) { |
| 81 | + return ret; |
| 82 | + } |
| 83 | + |
| 84 | + udma_handle = UDMAx_Initialize(&udma_resources, udma_resources.desc, NULL, |
| 85 | + (uint32_t *)&data->udma_handle); |
| 86 | + if (udma_handle != &data->udma_handle) { |
| 87 | + return -EINVAL; |
| 88 | + } |
| 89 | + |
| 90 | + cfg->irq_configure(); |
| 91 | + |
| 92 | + if (UDMAx_DMAEnable(&udma_resources, udma_handle) != 0) { |
| 93 | + return -EBUSY; |
| 94 | + } |
| 95 | + |
| 96 | + break; |
| 97 | + case PM_DEVICE_ACTION_SUSPEND: |
| 98 | + return 0; |
| 99 | + default: |
| 100 | + return -ENOTSUP; |
| 101 | + } |
| 102 | + return 0; |
| 103 | +} |
| 104 | + |
63 | 105 | static enum dma_xfer_dir siwx91x_transfer_direction(uint32_t dir)
|
64 | 106 | {
|
65 | 107 | if (dir == MEMORY_TO_MEMORY) {
|
@@ -591,7 +633,7 @@ static int siwx91x_dma_init(const struct device *dev)
|
591 | 633 | return -EBUSY;
|
592 | 634 | }
|
593 | 635 |
|
594 |
| - return 0; |
| 636 | + return pm_device_driver_init(dev, dma_siwx91x_pm_action); |
595 | 637 | }
|
596 | 638 |
|
597 | 639 | static void siwx91x_dma_isr(const struct device *dev)
|
@@ -701,7 +743,10 @@ static DEVICE_API(dma, siwx91x_dma_api) = {
|
701 | 743 | (siwx91x_dma_chan_desc##inst)), \
|
702 | 744 | .irq_configure = siwx91x_dma_irq_configure_##inst, \
|
703 | 745 | }; \
|
704 |
| - DEVICE_DT_INST_DEFINE(inst, siwx91x_dma_init, NULL, &dma_data_##inst, &dma_cfg_##inst, \ |
705 |
| - POST_KERNEL, CONFIG_DMA_INIT_PRIORITY, &siwx91x_dma_api); |
| 746 | + PM_DEVICE_DT_INST_DEFINE(inst, dma_siwx91x_pm_action); \ |
| 747 | + DEVICE_DT_INST_DEFINE(inst, siwx91x_dma_init, PM_DEVICE_DT_INST_GET(inst), \ |
| 748 | + &dma_data_##inst, &dma_cfg_##inst, POST_KERNEL, \ |
| 749 | + CONFIG_DMA_INIT_PRIORITY, \ |
| 750 | + &siwx91x_dma_api); |
706 | 751 |
|
707 | 752 | DT_INST_FOREACH_STATUS_OKAY(SIWX91X_DMA_INIT)
|
0 commit comments