Lines Matching +full:dma +full:- +full:channels
4 * SPDX-License-Identifier: Apache-2.0
8 #include <zephyr/drivers/dma.h>
14 /* FSP DMAC handler should be called within DMA ISR */
31 /* DMA call back */
48 /* Dma context should be the first in data structure */
50 struct dma_channel_data *channels; member
55 struct dmac_cb_ctx *cb_ctx = (struct dmac_cb_ctx *)args->p_context; in dmac_rz_cb_handler()
56 uint32_t channel = cb_ctx->channel; in dmac_rz_cb_handler()
57 const struct device *dev = cb_ctx->dmac_dev; in dmac_rz_cb_handler()
58 struct dma_renesas_rz_data *data = dev->data; in dmac_rz_cb_handler()
59 dma_callback_t user_cb = data->channels[channel].user_cb; in dmac_rz_cb_handler()
60 void *user_data = data->channels[channel].user_data; in dmac_rz_cb_handler()
63 user_cb(dev, user_data, channel, args->event); in dmac_rz_cb_handler()
69 const struct dma_renesas_rz_config *config = dev->config; in dma_channel_common_checks()
70 struct dma_renesas_rz_data *data = dev->data; in dma_channel_common_checks()
72 if (channel >= config->num_channels) { in dma_channel_common_checks()
73 LOG_ERR("%d: Invalid DMA channel %d.", __LINE__, channel); in dma_channel_common_checks()
74 return -EINVAL; in dma_channel_common_checks()
77 if (!data->channels[channel].is_configured) { in dma_channel_common_checks()
78 LOG_ERR("%d: DMA channel %d should first be configured.", __LINE__, channel); in dma_channel_common_checks()
79 return -EINVAL; in dma_channel_common_checks()
88 if ((cfg == NULL) || (cfg->head_block == NULL)) { in dma_channel_config_check_parameters()
90 return -EFAULT; in dma_channel_config_check_parameters()
93 if (1 < cfg->block_count) { in dma_channel_config_check_parameters()
96 return -ENOTSUP; in dma_channel_config_check_parameters()
99 if (cfg->source_chaining_en || cfg->dest_chaining_en) { in dma_channel_config_check_parameters()
101 return -ENOTSUP; in dma_channel_config_check_parameters()
104 if (cfg->head_block->dest_scatter_count || cfg->head_block->source_gather_count || in dma_channel_config_check_parameters()
105 cfg->head_block->source_gather_interval || cfg->head_block->dest_scatter_interval) { in dma_channel_config_check_parameters()
107 return -ENOTSUP; in dma_channel_config_check_parameters()
141 return -ENOTSUP; in dma_channel_set_size()
150 const struct dma_renesas_rz_config *config = dev->config; in dma_channel_config_save_parameters()
151 struct dma_renesas_rz_data *data = dev->data; in dma_channel_config_save_parameters()
152 transfer_info_t *p_info = data->channels[channel].fsp_cfg.p_info; in dma_channel_config_save_parameters()
154 (dmac_b_extended_cfg_t *)data->channels[channel].fsp_cfg.p_extend; in dma_channel_config_save_parameters()
160 switch (cfg->head_block->dest_addr_adj) { in dma_channel_config_save_parameters()
162 p_info->dest_addr_mode = TRANSFER_ADDR_MODE_FIXED; in dma_channel_config_save_parameters()
165 p_info->dest_addr_mode = TRANSFER_ADDR_MODE_INCREMENTED; in dma_channel_config_save_parameters()
169 return -ENOTSUP; in dma_channel_config_save_parameters()
172 switch (cfg->head_block->source_addr_adj) { in dma_channel_config_save_parameters()
174 p_info->src_addr_mode = TRANSFER_ADDR_MODE_FIXED; in dma_channel_config_save_parameters()
177 p_info->src_addr_mode = TRANSFER_ADDR_MODE_INCREMENTED; in dma_channel_config_save_parameters()
181 return -ENOTSUP; in dma_channel_config_save_parameters()
185 p_info->src_size = dma_channel_set_size(cfg->source_data_size); in dma_channel_config_save_parameters()
186 p_info->dest_size = dma_channel_set_size(cfg->dest_data_size); in dma_channel_config_save_parameters()
189 p_info->p_src = (void const *volatile)cfg->head_block->source_address; in dma_channel_config_save_parameters()
190 p_info->p_dest = (void *volatile)cfg->head_block->dest_address; in dma_channel_config_save_parameters()
191 p_info->length = cfg->head_block->block_size; in dma_channel_config_save_parameters()
197 p_info->p_next1_src = NULL; in dma_channel_config_save_parameters()
198 p_info->p_next1_dest = NULL; in dma_channel_config_save_parameters()
199 p_info->next1_length = 1; in dma_channel_config_save_parameters()
200 p_extend->continuous_setting = DMAC_B_CONTINUOUS_SETTING_TRANSFER_ONCE; in dma_channel_config_save_parameters()
203 p_extend->unit = config->unit; in dma_channel_config_save_parameters()
204 p_extend->channel = channel; in dma_channel_config_save_parameters()
207 p_extend->dmac_int_irq = data->channels[channel].irq; in dma_channel_config_save_parameters()
208 p_extend->dmac_int_ipl = data->channels[channel].irq_ipl; in dma_channel_config_save_parameters()
211 data->channels[channel].user_cb = cfg->dma_callback; in dma_channel_config_save_parameters()
212 data->channels[channel].user_data = cfg->user_data; in dma_channel_config_save_parameters()
213 data->channels[channel].cb_ctx.dmac_dev = dev; in dma_channel_config_save_parameters()
214 data->channels[channel].cb_ctx.channel = channel; in dma_channel_config_save_parameters()
215 p_extend->p_callback = dmac_rz_cb_handler; in dma_channel_config_save_parameters()
216 p_extend->p_context = (void *)&data->channels[channel].cb_ctx; in dma_channel_config_save_parameters()
219 p_extend->ack_mode = DMAC_B_ACK_MODE_MASK_DACK_OUTPUT; in dma_channel_config_save_parameters()
220 p_extend->external_detection_mode = DMAC_B_EXTERNAL_DETECTION_NO_DETECTION; in dma_channel_config_save_parameters()
221 p_extend->internal_detection_mode = DMAC_B_INTERNAL_DETECTION_NO_DETECTION; in dma_channel_config_save_parameters()
224 switch (cfg->channel_direction) { in dma_channel_config_save_parameters()
226 p_info->mode = TRANSFER_MODE_BLOCK; in dma_channel_config_save_parameters()
227 p_extend->activation_request_source_select = in dma_channel_config_save_parameters()
229 p_extend->activation_source = DMAC_TRIGGER_EVENT_SOFTWARE_TRIGGER; in dma_channel_config_save_parameters()
232 p_info->mode = TRANSFER_MODE_NORMAL; in dma_channel_config_save_parameters()
233 p_extend->activation_request_source_select = in dma_channel_config_save_parameters()
235 p_extend->activation_source = cfg->dma_slot; in dma_channel_config_save_parameters()
238 p_info->mode = TRANSFER_MODE_NORMAL; in dma_channel_config_save_parameters()
239 p_extend->activation_request_source_select = DMAC_B_REQUEST_DIRECTION_SOURCE_MODULE; in dma_channel_config_save_parameters()
240 p_extend->activation_source = cfg->dma_slot; in dma_channel_config_save_parameters()
244 return -ENOTSUP; in dma_channel_config_save_parameters()
247 data->channels[channel].direction = cfg->channel_direction; in dma_channel_config_save_parameters()
253 if (cfg->channel_priority == 0) { in dma_channel_config_save_parameters()
254 p_extend->channel_scheduling = DMAC_B_CHANNEL_SCHEDULING_FIXED; in dma_channel_config_save_parameters()
256 p_extend->channel_scheduling = DMAC_B_CHANNEL_SCHEDULING_ROUND_ROBIN; in dma_channel_config_save_parameters()
259 if (1 < cfg->block_count) { in dma_channel_config_save_parameters()
262 p_extend->dmac_mode = DMAC_B_MODE_SELECT_REGISTER; in dma_channel_config_save_parameters()
271 const struct dma_renesas_rz_config *config = dev->config; in dma_renesas_rz_get_status()
272 struct dma_renesas_rz_data *data = dev->data; in dma_renesas_rz_get_status()
282 p_info = data->channels[channel].fsp_cfg.p_info; in dma_renesas_rz_get_status()
285 ret = config->fsp_api->infoGet(data->channels[channel].fsp_ctrl, &properties); in dma_renesas_rz_get_status()
287 LOG_ERR("%d: Failed to get info dma channel %d info with status %d.", __LINE__, in dma_renesas_rz_get_status()
289 return -EIO; in dma_renesas_rz_get_status()
294 status->dir = data->channels[channel].direction; in dma_renesas_rz_get_status()
295 status->pending_length = properties.transfer_length_remaining; in dma_renesas_rz_get_status()
296 status->busy = status->pending_length ? true : false; in dma_renesas_rz_get_status()
297 status->total_copied = p_info->length - properties.transfer_length_remaining; in dma_renesas_rz_get_status()
304 struct dma_renesas_rz_data *data = dev->data; in dma_renesas_rz_suspend()
312 dmac_b_instance_ctrl_t *p_ctrl = (dmac_b_instance_ctrl_t *)data->channels[channel].fsp_ctrl; in dma_renesas_rz_suspend()
318 p_ctrl->p_reg->GRP[group].CH[prv_channel].CHCTRL = R_DMAC_B0_GRP_CH_CHCTRL_SETSUS_Msk; in dma_renesas_rz_suspend()
321 FSP_HARDWARE_REGISTER_WAIT(p_ctrl->p_reg->GRP[group].CH[prv_channel].CHSTAT_b.SUS, 1); in dma_renesas_rz_suspend()
328 struct dma_renesas_rz_data *data = dev->data; in dma_renesas_rz_resume()
336 dmac_b_instance_ctrl_t *p_ctrl = (dmac_b_instance_ctrl_t *)data->channels[channel].fsp_ctrl; in dma_renesas_rz_resume()
342 if (0 == p_ctrl->p_reg->GRP[group].CH[prv_channel].CHSTAT_b.SUS) { in dma_renesas_rz_resume()
343 LOG_ERR("%d: DMA channel not suspend.", channel); in dma_renesas_rz_resume()
344 return -EINVAL; in dma_renesas_rz_resume()
348 p_ctrl->p_reg->GRP[group].CH[prv_channel].CHCTRL |= R_DMAC_B0_GRP_CH_CHCTRL_CLRSUS_Msk; in dma_renesas_rz_resume()
355 const struct dma_renesas_rz_config *config = dev->config; in dma_renesas_rz_stop()
356 struct dma_renesas_rz_data *data = dev->data; in dma_renesas_rz_stop()
364 ret = config->fsp_api->disable(data->channels[channel].fsp_ctrl); in dma_renesas_rz_stop()
367 LOG_ERR("%d: Failed to stop dma channel %d info with status %d.", __LINE__, channel, in dma_renesas_rz_stop()
369 return -EIO; in dma_renesas_rz_stop()
377 const struct dma_renesas_rz_config *config = dev->config; in dma_renesas_rz_start()
378 struct dma_renesas_rz_data *data = dev->data; in dma_renesas_rz_start()
387 p_extend = data->channels[channel].fsp_cfg.p_extend; in dma_renesas_rz_start()
389 ret = config->fsp_api->enable(data->channels[channel].fsp_ctrl); in dma_renesas_rz_start()
392 LOG_ERR("%d: Failed to start %d dma channel with status %d.", __LINE__, channel, in dma_renesas_rz_start()
394 return -EIO; in dma_renesas_rz_start()
397 if (DMAC_TRIGGER_EVENT_SOFTWARE_TRIGGER == p_extend->activation_source) { in dma_renesas_rz_start()
398 ret = config->fsp_api->softwareStart(data->channels[channel].fsp_ctrl, in dma_renesas_rz_start()
402 LOG_ERR("%d: Failed to trigger %d dma channel with status %d.", __LINE__, in dma_renesas_rz_start()
404 return -EIO; in dma_renesas_rz_start()
413 const struct dma_renesas_rz_config *config = dev->config; in dma_renesas_rz_config()
414 struct dma_renesas_rz_data *data = dev->data; in dma_renesas_rz_config()
418 if (channel >= config->num_channels) { in dma_renesas_rz_config()
419 LOG_ERR("%d: Invalid DMA channel %d.", __LINE__, channel); in dma_renesas_rz_config()
420 return -EINVAL; in dma_renesas_rz_config()
434 channel_cfg = &data->channels[channel]; in dma_renesas_rz_config()
438 if (data->channels[channel].is_configured) { in dma_renesas_rz_config()
439 config->fsp_api->close(channel_cfg->fsp_ctrl); in dma_renesas_rz_config()
442 ret = config->fsp_api->open(channel_cfg->fsp_ctrl, &channel_cfg->fsp_cfg); in dma_renesas_rz_config()
445 LOG_ERR("%d: Failed to configure %d dma channel with status %d.", __LINE__, channel, in dma_renesas_rz_config()
447 return -EIO; in dma_renesas_rz_config()
450 data->channels[channel].is_configured = true; in dma_renesas_rz_config()
457 const struct dma_renesas_rz_config *config = dev->config; in dma_renesas_rz_reload()
458 struct dma_renesas_rz_data *data = dev->data; in dma_renesas_rz_reload()
468 return -EINVAL; in dma_renesas_rz_reload()
471 transfer_info_t *p_info = data->channels[channel].fsp_cfg.p_info; in dma_renesas_rz_reload()
473 p_info->length = size; in dma_renesas_rz_reload()
474 p_info->p_src = (void const *volatile)src; in dma_renesas_rz_reload()
475 p_info->p_dest = (void *volatile)dst; in dma_renesas_rz_reload()
477 ret = config->fsp_api->reconfigure(data->channels[channel].fsp_ctrl, p_info); in dma_renesas_rz_reload()
480 LOG_ERR("%d: Failed to reload %d dma channel with status %d.", __LINE__, channel, in dma_renesas_rz_reload()
482 return -EIO; in dma_renesas_rz_reload()
492 return -EINVAL; in dma_renesas_rz_get_attribute()
499 return -ENOSYS; in dma_renesas_rz_get_attribute()
508 return -EINVAL; in dma_renesas_rz_get_attribute()
517 const struct dma_renesas_rz_config *config = dev->config; in dma_renesas_rz_channel_filter()
518 struct dma_renesas_rz_data *data = dev->data; in dma_renesas_rz_channel_filter()
520 if (channel >= config->num_channels) { in dma_renesas_rz_channel_filter()
521 LOG_ERR("%d: Invalid DMA channel %d.", __LINE__, channel); in dma_renesas_rz_channel_filter()
522 return -EINVAL; in dma_renesas_rz_channel_filter()
525 irq_enable(data->channels[channel].irq); in dma_renesas_rz_channel_filter()
526 /* All DMA channels support triggered by periodic sources so always return true */ in dma_renesas_rz_channel_filter()
532 const struct dma_renesas_rz_config *config = dev->config; in dma_renesas_rz_channel_release()
533 struct dma_renesas_rz_data *data = dev->data; in dma_renesas_rz_channel_release()
536 if (channel >= config->num_channels) { in dma_renesas_rz_channel_release()
537 LOG_ERR("%d: Invalid DMA channel %d.", __LINE__, channel); in dma_renesas_rz_channel_release()
540 irq_disable(data->channels[channel].irq); in dma_renesas_rz_channel_release()
541 ret = config->fsp_api->close(data->channels[channel].fsp_ctrl); in dma_renesas_rz_channel_release()
544 LOG_ERR("%d: Failed to release %d dma channel with status %d.", __LINE__, channel, in dma_renesas_rz_channel_release()
549 static DEVICE_API(dma, dma_api) = {
564 const struct dma_renesas_rz_config *config = dev->config; in renesas_rz_dma_init()
566 config->irq_configure(); in renesas_rz_dma_init()
633 .channels = dma_rz_##inst##_channels}; \