Lines Matching +full:chan +full:- +full:name

1 // SPDX-License-Identifier: GPL-2.0
3 * arch/sh/drivers/dma/dma-api.c
5 * SuperH-specific DMA management API
24 struct dma_info *get_dma_info(unsigned int chan) in get_dma_info() argument
33 if ((chan < info->first_vchannel_nr) || in get_dma_info()
34 (chan >= info->first_vchannel_nr + info->nr_channels)) in get_dma_info()
49 if (dmac_name && (strcmp(dmac_name, info->name) != 0)) in get_dma_info_by_name()
68 nr += info->nr_channels; in get_nr_channels()
73 struct dma_channel *get_dma_channel(unsigned int chan) in get_dma_channel() argument
75 struct dma_info *info = get_dma_info(chan); in get_dma_channel()
80 return ERR_PTR(-EINVAL); in get_dma_channel()
82 for (i = 0; i < info->nr_channels; i++) { in get_dma_channel()
83 channel = &info->channels[i]; in get_dma_channel()
84 if (channel->vchan == chan) in get_dma_channel()
92 int get_dma_residue(unsigned int chan) in get_dma_residue() argument
94 struct dma_info *info = get_dma_info(chan); in get_dma_residue()
95 struct dma_channel *channel = get_dma_channel(chan); in get_dma_residue()
97 if (info->ops->get_residue) in get_dma_residue()
98 return info->ops->get_residue(channel); in get_dma_residue()
116 * request_dma_bycap - Allocate a DMA channel based on its capabilities
122 * number if a match is found, or %-ENODEV if no match is found.
138 if (strcmp(*dmac, info->name) == 0) { in request_dma_bycap()
144 return -ENODEV; in request_dma_bycap()
146 for (i = 0; i < info->nr_channels; i++) { in request_dma_bycap()
147 struct dma_channel *channel = &info->channels[i]; in request_dma_bycap()
149 if (unlikely(!channel->caps)) in request_dma_bycap()
153 if (!search_cap(channel->caps, *p)) in request_dma_bycap()
155 if (request_dma(channel->chan, dev_id) == 0) in request_dma_bycap()
156 return channel->chan; in request_dma_bycap()
160 return -EINVAL; in request_dma_bycap()
170 for (i = 0; i < info->nr_channels; i++) { in dmac_search_free_channel()
171 channel = &info->channels[i]; in dmac_search_free_channel()
173 return -ENODEV; in dmac_search_free_channel()
175 if (atomic_read(&channel->busy) == 0) in dmac_search_free_channel()
179 if (info->ops->request) { in dmac_search_free_channel()
180 int result = info->ops->request(channel); in dmac_search_free_channel()
184 atomic_set(&channel->busy, 1); in dmac_search_free_channel()
185 return channel->chan; in dmac_search_free_channel()
188 return -ENOSYS; in dmac_search_free_channel()
191 int request_dma(unsigned int chan, const char *dev_id) in request_dma() argument
194 struct dma_info *info = get_dma_info(chan); in request_dma()
197 channel = get_dma_channel(chan); in request_dma()
198 if (atomic_xchg(&channel->busy, 1)) in request_dma()
199 return -EBUSY; in request_dma()
201 strlcpy(channel->dev_id, dev_id, sizeof(channel->dev_id)); in request_dma()
203 if (info->ops->request) { in request_dma()
204 result = info->ops->request(channel); in request_dma()
206 atomic_set(&channel->busy, 0); in request_dma()
215 void free_dma(unsigned int chan) in free_dma() argument
217 struct dma_info *info = get_dma_info(chan); in free_dma()
218 struct dma_channel *channel = get_dma_channel(chan); in free_dma()
220 if (info->ops->free) in free_dma()
221 info->ops->free(channel); in free_dma()
223 atomic_set(&channel->busy, 0); in free_dma()
227 void dma_wait_for_completion(unsigned int chan) in dma_wait_for_completion() argument
229 struct dma_info *info = get_dma_info(chan); in dma_wait_for_completion()
230 struct dma_channel *channel = get_dma_channel(chan); in dma_wait_for_completion()
232 if (channel->flags & DMA_TEI_CAPABLE) { in dma_wait_for_completion()
233 wait_event(channel->wait_queue, in dma_wait_for_completion()
234 (info->ops->get_residue(channel) == 0)); in dma_wait_for_completion()
238 while (info->ops->get_residue(channel)) in dma_wait_for_completion()
250 if (strcmp(dmac, info->name) == 0) { in register_chan_caps()
256 return -ENODEV; in register_chan_caps()
258 for (i = 0; i < info->nr_channels; i++, caps++) { in register_chan_caps()
261 if ((info->first_channel_nr + i) != caps->ch_num) in register_chan_caps()
262 return -EINVAL; in register_chan_caps()
264 channel = &info->channels[i]; in register_chan_caps()
265 channel->caps = caps->caplist; in register_chan_caps()
272 void dma_configure_channel(unsigned int chan, unsigned long flags) in dma_configure_channel() argument
274 struct dma_info *info = get_dma_info(chan); in dma_configure_channel()
275 struct dma_channel *channel = get_dma_channel(chan); in dma_configure_channel()
277 if (info->ops->configure) in dma_configure_channel()
278 info->ops->configure(channel, flags); in dma_configure_channel()
282 int dma_xfer(unsigned int chan, unsigned long from, in dma_xfer() argument
285 struct dma_info *info = get_dma_info(chan); in dma_xfer()
286 struct dma_channel *channel = get_dma_channel(chan); in dma_xfer()
288 channel->sar = from; in dma_xfer()
289 channel->dar = to; in dma_xfer()
290 channel->count = size; in dma_xfer()
291 channel->mode = mode; in dma_xfer()
293 return info->ops->xfer(channel); in dma_xfer()
297 int dma_extend(unsigned int chan, unsigned long op, void *param) in dma_extend() argument
299 struct dma_info *info = get_dma_info(chan); in dma_extend()
300 struct dma_channel *channel = get_dma_channel(chan); in dma_extend()
302 if (info->ops->extend) in dma_extend()
303 return info->ops->extend(channel, op, param); in dma_extend()
305 return -ENOSYS; in dma_extend()
325 for (i = 0; i < info->nr_channels; i++) { in dma_proc_show()
326 struct dma_channel *channel = info->channels + i; in dma_proc_show()
328 if (!(channel->flags & DMA_CONFIGURED)) in dma_proc_show()
332 info->name, channel->dev_id); in dma_proc_show()
343 INIT_LIST_HEAD(&info->list); in register_dmac()
346 info->name, info->nr_channels, info->nr_channels > 1 ? "s" : ""); in register_dmac()
348 BUG_ON((info->flags & DMAC_CHANNELS_CONFIGURED) && !info->channels); in register_dmac()
350 info->pdev = platform_device_register_simple(info->name, -1, in register_dmac()
352 if (IS_ERR(info->pdev)) in register_dmac()
353 return PTR_ERR(info->pdev); in register_dmac()
356 * Don't touch pre-configured channels in register_dmac()
358 if (!(info->flags & DMAC_CHANNELS_CONFIGURED)) { in register_dmac()
361 size = sizeof(struct dma_channel) * info->nr_channels; in register_dmac()
363 info->channels = kzalloc(size, GFP_KERNEL); in register_dmac()
364 if (!info->channels) in register_dmac()
365 return -ENOMEM; in register_dmac()
369 info->first_vchannel_nr = total_channels; in register_dmac()
370 for (i = 0; i < info->nr_channels; i++) { in register_dmac()
371 struct dma_channel *chan = &info->channels[i]; in register_dmac() local
373 atomic_set(&chan->busy, 0); in register_dmac()
375 chan->chan = info->first_channel_nr + i; in register_dmac()
376 chan->vchan = info->first_channel_nr + i + total_channels; in register_dmac()
378 memcpy(chan->dev_id, "Unused", 7); in register_dmac()
380 if (info->flags & DMAC_CHANNELS_TEI_CAPABLE) in register_dmac()
381 chan->flags |= DMA_TEI_CAPABLE; in register_dmac()
383 init_waitqueue_head(&chan->wait_queue); in register_dmac()
384 dma_create_sysfs_files(chan, info); in register_dmac()
387 list_add(&info->list, &registered_dmac_list); in register_dmac()
397 for (i = 0; i < info->nr_channels; i++) in unregister_dmac()
398 dma_remove_sysfs_files(info->channels + i, info); in unregister_dmac()
400 if (!(info->flags & DMAC_CHANNELS_CONFIGURED)) in unregister_dmac()
401 kfree(info->channels); in unregister_dmac()
403 list_del(&info->list); in unregister_dmac()
404 platform_device_unregister(info->pdev); in unregister_dmac()
411 return proc_create_single("dma", 0, NULL, dma_proc_show) ? 0 : -ENOMEM; in dma_api_init()
415 MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>");