Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012, Analog Devices Inc. |
| 3 | * Author: Lars-Peter Clausen <lars@metafoo.de> |
| 4 | * |
| 5 | * Based on: |
| 6 | * imx-pcm-dma-mx2.c, Copyright 2009 Sascha Hauer <s.hauer@pengutronix.de> |
| 7 | * mxs-pcm.c, Copyright (C) 2011 Freescale Semiconductor, Inc. |
| 8 | * ep93xx-pcm.c, Copyright (C) 2006 Lennert Buytenhek <buytenh@wantstofly.org> |
| 9 | * Copyright (C) 2006 Applied Data Systems |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify it |
| 12 | * under the terms of the GNU General Public License as published by the |
| 13 | * Free Software Foundation; either version 2 of the License, or (at your |
| 14 | * option) any later version. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along |
| 17 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | * |
| 20 | */ |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/init.h> |
| 23 | #include <linux/dmaengine.h> |
| 24 | #include <linux/slab.h> |
| 25 | #include <sound/pcm.h> |
| 26 | #include <sound/pcm_params.h> |
| 27 | #include <sound/soc.h> |
| 28 | |
| 29 | #include <sound/dmaengine_pcm.h> |
| 30 | |
| 31 | struct dmaengine_pcm_runtime_data { |
| 32 | struct dma_chan *dma_chan; |
Lars-Peter Clausen | 3528f27 | 2012-06-11 20:11:42 +0200 | [diff] [blame] | 33 | dma_cookie_t cookie; |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 34 | |
| 35 | unsigned int pos; |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | static inline struct dmaengine_pcm_runtime_data *substream_to_prtd( |
| 39 | const struct snd_pcm_substream *substream) |
| 40 | { |
| 41 | return substream->runtime->private_data; |
| 42 | } |
| 43 | |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 44 | struct dma_chan *snd_dmaengine_pcm_get_chan(struct snd_pcm_substream *substream) |
| 45 | { |
| 46 | struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream); |
| 47 | |
| 48 | return prtd->dma_chan; |
| 49 | } |
| 50 | EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_get_chan); |
| 51 | |
| 52 | /** |
| 53 | * snd_hwparams_to_dma_slave_config - Convert hw_params to dma_slave_config |
| 54 | * @substream: PCM substream |
| 55 | * @params: hw_params |
| 56 | * @slave_config: DMA slave config |
| 57 | * |
| 58 | * This function can be used to initialize a dma_slave_config from a substream |
| 59 | * and hw_params in a dmaengine based PCM driver implementation. |
| 60 | */ |
| 61 | int snd_hwparams_to_dma_slave_config(const struct snd_pcm_substream *substream, |
| 62 | const struct snd_pcm_hw_params *params, |
| 63 | struct dma_slave_config *slave_config) |
| 64 | { |
| 65 | enum dma_slave_buswidth buswidth; |
Takashi Iwai | a655f75 | 2013-10-25 16:33:12 +0200 | [diff] [blame] | 66 | int bits; |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 67 | |
Peter Ujfalusi | 732814c | 2014-07-03 07:51:53 +0300 | [diff] [blame] | 68 | bits = params_physical_width(params); |
Takashi Iwai | a655f75 | 2013-10-25 16:33:12 +0200 | [diff] [blame] | 69 | if (bits < 8 || bits > 64) |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 70 | return -EINVAL; |
Takashi Iwai | a655f75 | 2013-10-25 16:33:12 +0200 | [diff] [blame] | 71 | else if (bits == 8) |
| 72 | buswidth = DMA_SLAVE_BUSWIDTH_1_BYTE; |
| 73 | else if (bits == 16) |
| 74 | buswidth = DMA_SLAVE_BUSWIDTH_2_BYTES; |
Peter Ujfalusi | 75f850f | 2014-07-03 07:51:55 +0300 | [diff] [blame] | 75 | else if (bits == 24) |
| 76 | buswidth = DMA_SLAVE_BUSWIDTH_3_BYTES; |
Takashi Iwai | a655f75 | 2013-10-25 16:33:12 +0200 | [diff] [blame] | 77 | else if (bits <= 32) |
| 78 | buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES; |
| 79 | else |
| 80 | buswidth = DMA_SLAVE_BUSWIDTH_8_BYTES; |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 81 | |
| 82 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 83 | slave_config->direction = DMA_MEM_TO_DEV; |
| 84 | slave_config->dst_addr_width = buswidth; |
| 85 | } else { |
| 86 | slave_config->direction = DMA_DEV_TO_MEM; |
| 87 | slave_config->src_addr_width = buswidth; |
| 88 | } |
| 89 | |
Lars-Peter Clausen | 5fa70f7 | 2013-04-03 11:02:56 +0200 | [diff] [blame] | 90 | slave_config->device_fc = false; |
| 91 | |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 92 | return 0; |
| 93 | } |
| 94 | EXPORT_SYMBOL_GPL(snd_hwparams_to_dma_slave_config); |
| 95 | |
Lars-Peter Clausen | 85c9f9c | 2013-04-03 11:06:02 +0200 | [diff] [blame] | 96 | /** |
| 97 | * snd_dmaengine_pcm_set_config_from_dai_data() - Initializes a dma slave config |
| 98 | * using DAI DMA data. |
| 99 | * @substream: PCM substream |
| 100 | * @dma_data: DAI DMA data |
| 101 | * @slave_config: DMA slave configuration |
| 102 | * |
| 103 | * Initializes the {dst,src}_addr, {dst,src}_maxburst, {dst,src}_addr_width and |
| 104 | * slave_id fields of the DMA slave config from the same fields of the DAI DMA |
| 105 | * data struct. The src and dst fields will be initialized depending on the |
| 106 | * direction of the substream. If the substream is a playback stream the dst |
| 107 | * fields will be initialized, if it is a capture stream the src fields will be |
| 108 | * initialized. The {dst,src}_addr_width field will only be initialized if the |
Matthias Reichl | 73fe01c | 2016-04-27 15:26:51 +0200 | [diff] [blame] | 109 | * SND_DMAENGINE_PCM_DAI_FLAG_PACK flag is set or if the addr_width field of |
| 110 | * the DAI DMA data struct is not equal to DMA_SLAVE_BUSWIDTH_UNDEFINED. If |
| 111 | * both conditions are met the latter takes priority. |
Lars-Peter Clausen | 85c9f9c | 2013-04-03 11:06:02 +0200 | [diff] [blame] | 112 | */ |
| 113 | void snd_dmaengine_pcm_set_config_from_dai_data( |
| 114 | const struct snd_pcm_substream *substream, |
| 115 | const struct snd_dmaengine_dai_dma_data *dma_data, |
| 116 | struct dma_slave_config *slave_config) |
| 117 | { |
| 118 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 119 | slave_config->dst_addr = dma_data->addr; |
| 120 | slave_config->dst_maxburst = dma_data->maxburst; |
Matthias Reichl | 73fe01c | 2016-04-27 15:26:51 +0200 | [diff] [blame] | 121 | if (dma_data->flags & SND_DMAENGINE_PCM_DAI_FLAG_PACK) |
| 122 | slave_config->dst_addr_width = |
| 123 | DMA_SLAVE_BUSWIDTH_UNDEFINED; |
Lars-Peter Clausen | 85c9f9c | 2013-04-03 11:06:02 +0200 | [diff] [blame] | 124 | if (dma_data->addr_width != DMA_SLAVE_BUSWIDTH_UNDEFINED) |
| 125 | slave_config->dst_addr_width = dma_data->addr_width; |
| 126 | } else { |
| 127 | slave_config->src_addr = dma_data->addr; |
| 128 | slave_config->src_maxburst = dma_data->maxburst; |
Matthias Reichl | 73fe01c | 2016-04-27 15:26:51 +0200 | [diff] [blame] | 129 | if (dma_data->flags & SND_DMAENGINE_PCM_DAI_FLAG_PACK) |
| 130 | slave_config->src_addr_width = |
| 131 | DMA_SLAVE_BUSWIDTH_UNDEFINED; |
Lars-Peter Clausen | 85c9f9c | 2013-04-03 11:06:02 +0200 | [diff] [blame] | 132 | if (dma_data->addr_width != DMA_SLAVE_BUSWIDTH_UNDEFINED) |
| 133 | slave_config->src_addr_width = dma_data->addr_width; |
| 134 | } |
| 135 | |
| 136 | slave_config->slave_id = dma_data->slave_id; |
| 137 | } |
| 138 | EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_set_config_from_dai_data); |
| 139 | |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 140 | static void dmaengine_pcm_dma_complete(void *arg) |
| 141 | { |
| 142 | struct snd_pcm_substream *substream = arg; |
| 143 | struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream); |
| 144 | |
| 145 | prtd->pos += snd_pcm_lib_period_bytes(substream); |
| 146 | if (prtd->pos >= snd_pcm_lib_buffer_bytes(substream)) |
| 147 | prtd->pos = 0; |
| 148 | |
| 149 | snd_pcm_period_elapsed(substream); |
| 150 | } |
| 151 | |
| 152 | static int dmaengine_pcm_prepare_and_submit(struct snd_pcm_substream *substream) |
| 153 | { |
| 154 | struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream); |
| 155 | struct dma_chan *chan = prtd->dma_chan; |
| 156 | struct dma_async_tx_descriptor *desc; |
| 157 | enum dma_transfer_direction direction; |
Peter Ujfalusi | e7736cd | 2012-09-24 10:58:04 +0300 | [diff] [blame] | 158 | unsigned long flags = DMA_CTRL_ACK; |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 159 | |
| 160 | direction = snd_pcm_substream_to_dma_direction(substream); |
| 161 | |
Peter Ujfalusi | e7736cd | 2012-09-24 10:58:04 +0300 | [diff] [blame] | 162 | if (!substream->runtime->no_period_wakeup) |
| 163 | flags |= DMA_PREP_INTERRUPT; |
| 164 | |
Mika Westerberg | 7a08cf70 | 2012-03-05 14:02:14 +0100 | [diff] [blame] | 165 | prtd->pos = 0; |
Vinod Koul | 41ba6b7 | 2012-03-26 17:28:08 +0530 | [diff] [blame] | 166 | desc = dmaengine_prep_dma_cyclic(chan, |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 167 | substream->runtime->dma_addr, |
| 168 | snd_pcm_lib_buffer_bytes(substream), |
Peter Ujfalusi | e7736cd | 2012-09-24 10:58:04 +0300 | [diff] [blame] | 169 | snd_pcm_lib_period_bytes(substream), direction, flags); |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 170 | |
| 171 | if (!desc) |
| 172 | return -ENOMEM; |
| 173 | |
| 174 | desc->callback = dmaengine_pcm_dma_complete; |
| 175 | desc->callback_param = substream; |
Lars-Peter Clausen | 3528f27 | 2012-06-11 20:11:42 +0200 | [diff] [blame] | 176 | prtd->cookie = dmaengine_submit(desc); |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 177 | |
| 178 | return 0; |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * snd_dmaengine_pcm_trigger - dmaengine based PCM trigger implementation |
| 183 | * @substream: PCM substream |
| 184 | * @cmd: Trigger command |
| 185 | * |
| 186 | * Returns 0 on success, a negative error code otherwise. |
| 187 | * |
| 188 | * This function can be used as the PCM trigger callback for dmaengine based PCM |
| 189 | * driver implementations. |
| 190 | */ |
| 191 | int snd_dmaengine_pcm_trigger(struct snd_pcm_substream *substream, int cmd) |
| 192 | { |
| 193 | struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream); |
Tushar Behera | 02fb05a | 2014-05-19 14:53:53 +0530 | [diff] [blame] | 194 | struct snd_pcm_runtime *runtime = substream->runtime; |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 195 | int ret; |
| 196 | |
| 197 | switch (cmd) { |
| 198 | case SNDRV_PCM_TRIGGER_START: |
| 199 | ret = dmaengine_pcm_prepare_and_submit(substream); |
| 200 | if (ret) |
| 201 | return ret; |
| 202 | dma_async_issue_pending(prtd->dma_chan); |
| 203 | break; |
| 204 | case SNDRV_PCM_TRIGGER_RESUME: |
| 205 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 206 | dmaengine_resume(prtd->dma_chan); |
| 207 | break; |
| 208 | case SNDRV_PCM_TRIGGER_SUSPEND: |
Tushar Behera | 02fb05a | 2014-05-19 14:53:53 +0530 | [diff] [blame] | 209 | if (runtime->info & SNDRV_PCM_INFO_PAUSE) |
| 210 | dmaengine_pause(prtd->dma_chan); |
| 211 | else |
Lars-Peter Clausen | bc0e734 | 2015-10-20 11:46:31 +0200 | [diff] [blame] | 212 | dmaengine_terminate_async(prtd->dma_chan); |
Tushar Behera | 02fb05a | 2014-05-19 14:53:53 +0530 | [diff] [blame] | 213 | break; |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 214 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 215 | dmaengine_pause(prtd->dma_chan); |
| 216 | break; |
| 217 | case SNDRV_PCM_TRIGGER_STOP: |
Lars-Peter Clausen | bc0e734 | 2015-10-20 11:46:31 +0200 | [diff] [blame] | 218 | dmaengine_terminate_async(prtd->dma_chan); |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 219 | break; |
| 220 | default: |
| 221 | return -EINVAL; |
| 222 | } |
| 223 | |
| 224 | return 0; |
| 225 | } |
| 226 | EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_trigger); |
| 227 | |
| 228 | /** |
Lars-Peter Clausen | 9883ab2 | 2012-06-11 20:11:41 +0200 | [diff] [blame] | 229 | * snd_dmaengine_pcm_pointer_no_residue - dmaengine based PCM pointer implementation |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 230 | * @substream: PCM substream |
| 231 | * |
Lars-Peter Clausen | 9883ab2 | 2012-06-11 20:11:41 +0200 | [diff] [blame] | 232 | * This function is deprecated and should not be used by new drivers, as its |
| 233 | * results may be unreliable. |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 234 | */ |
Lars-Peter Clausen | 9883ab2 | 2012-06-11 20:11:41 +0200 | [diff] [blame] | 235 | snd_pcm_uframes_t snd_dmaengine_pcm_pointer_no_residue(struct snd_pcm_substream *substream) |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 236 | { |
| 237 | struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream); |
| 238 | return bytes_to_frames(substream->runtime, prtd->pos); |
| 239 | } |
Lars-Peter Clausen | 9883ab2 | 2012-06-11 20:11:41 +0200 | [diff] [blame] | 240 | EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_pointer_no_residue); |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 241 | |
Lars-Peter Clausen | 3528f27 | 2012-06-11 20:11:42 +0200 | [diff] [blame] | 242 | /** |
| 243 | * snd_dmaengine_pcm_pointer - dmaengine based PCM pointer implementation |
| 244 | * @substream: PCM substream |
| 245 | * |
| 246 | * This function can be used as the PCM pointer callback for dmaengine based PCM |
| 247 | * driver implementations. |
| 248 | */ |
| 249 | snd_pcm_uframes_t snd_dmaengine_pcm_pointer(struct snd_pcm_substream *substream) |
| 250 | { |
| 251 | struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream); |
| 252 | struct dma_tx_state state; |
| 253 | enum dma_status status; |
| 254 | unsigned int buf_size; |
| 255 | unsigned int pos = 0; |
| 256 | |
| 257 | status = dmaengine_tx_status(prtd->dma_chan, prtd->cookie, &state); |
| 258 | if (status == DMA_IN_PROGRESS || status == DMA_PAUSED) { |
| 259 | buf_size = snd_pcm_lib_buffer_bytes(substream); |
| 260 | if (state.residue > 0 && state.residue <= buf_size) |
| 261 | pos = buf_size - state.residue; |
| 262 | } |
| 263 | |
| 264 | return bytes_to_frames(substream->runtime, pos); |
| 265 | } |
| 266 | EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_pointer); |
| 267 | |
Lars-Peter Clausen | c999836 | 2013-04-15 19:19:51 +0200 | [diff] [blame] | 268 | /** |
| 269 | * snd_dmaengine_pcm_request_channel - Request channel for the dmaengine PCM |
| 270 | * @filter_fn: Filter function used to request the DMA channel |
| 271 | * @filter_data: Data passed to the DMA filter function |
| 272 | * |
| 273 | * Returns NULL or the requested DMA channel. |
| 274 | * |
| 275 | * This function request a DMA channel for usage with dmaengine PCM. |
| 276 | */ |
| 277 | struct dma_chan *snd_dmaengine_pcm_request_channel(dma_filter_fn filter_fn, |
Lars-Peter Clausen | 7c1c1d4 | 2013-04-15 19:19:48 +0200 | [diff] [blame] | 278 | void *filter_data) |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 279 | { |
| 280 | dma_cap_mask_t mask; |
| 281 | |
| 282 | dma_cap_zero(mask); |
| 283 | dma_cap_set(DMA_SLAVE, mask); |
| 284 | dma_cap_set(DMA_CYCLIC, mask); |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 285 | |
Lars-Peter Clausen | 7c1c1d4 | 2013-04-15 19:19:48 +0200 | [diff] [blame] | 286 | return dma_request_channel(mask, filter_fn, filter_data); |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 287 | } |
Lars-Peter Clausen | c999836 | 2013-04-15 19:19:51 +0200 | [diff] [blame] | 288 | EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_request_channel); |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 289 | |
| 290 | /** |
| 291 | * snd_dmaengine_pcm_open - Open a dmaengine based PCM substream |
| 292 | * @substream: PCM substream |
Lars-Peter Clausen | 7c1c1d4 | 2013-04-15 19:19:48 +0200 | [diff] [blame] | 293 | * @chan: DMA channel to use for data transfers |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 294 | * |
| 295 | * Returns 0 on success, a negative error code otherwise. |
| 296 | * |
Lars-Peter Clausen | 7c1c1d4 | 2013-04-15 19:19:48 +0200 | [diff] [blame] | 297 | * The function should usually be called from the pcm open callback. Note that |
| 298 | * this function will use private_data field of the substream's runtime. So it |
Masanari Iida | 1a6ab46 | 2015-03-04 10:56:13 +0900 | [diff] [blame] | 299 | * is not available to your pcm driver implementation. |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 300 | */ |
| 301 | int snd_dmaengine_pcm_open(struct snd_pcm_substream *substream, |
Lars-Peter Clausen | 7c1c1d4 | 2013-04-15 19:19:48 +0200 | [diff] [blame] | 302 | struct dma_chan *chan) |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 303 | { |
| 304 | struct dmaengine_pcm_runtime_data *prtd; |
| 305 | int ret; |
| 306 | |
Lars-Peter Clausen | 7c1c1d4 | 2013-04-15 19:19:48 +0200 | [diff] [blame] | 307 | if (!chan) |
| 308 | return -ENXIO; |
| 309 | |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 310 | ret = snd_pcm_hw_constraint_integer(substream->runtime, |
| 311 | SNDRV_PCM_HW_PARAM_PERIODS); |
| 312 | if (ret < 0) |
| 313 | return ret; |
| 314 | |
| 315 | prtd = kzalloc(sizeof(*prtd), GFP_KERNEL); |
| 316 | if (!prtd) |
| 317 | return -ENOMEM; |
| 318 | |
Lars-Peter Clausen | 7c1c1d4 | 2013-04-15 19:19:48 +0200 | [diff] [blame] | 319 | prtd->dma_chan = chan; |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 320 | |
| 321 | substream->runtime->private_data = prtd; |
| 322 | |
| 323 | return 0; |
| 324 | } |
| 325 | EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_open); |
| 326 | |
| 327 | /** |
Lars-Peter Clausen | 7c1c1d4 | 2013-04-15 19:19:48 +0200 | [diff] [blame] | 328 | * snd_dmaengine_pcm_open_request_chan - Open a dmaengine based PCM substream and request channel |
| 329 | * @substream: PCM substream |
| 330 | * @filter_fn: Filter function used to request the DMA channel |
| 331 | * @filter_data: Data passed to the DMA filter function |
| 332 | * |
| 333 | * Returns 0 on success, a negative error code otherwise. |
| 334 | * |
| 335 | * This function will request a DMA channel using the passed filter function and |
| 336 | * data. The function should usually be called from the pcm open callback. Note |
| 337 | * that this function will use private_data field of the substream's runtime. So |
Masanari Iida | 1a6ab46 | 2015-03-04 10:56:13 +0900 | [diff] [blame] | 338 | * it is not available to your pcm driver implementation. |
Lars-Peter Clausen | 7c1c1d4 | 2013-04-15 19:19:48 +0200 | [diff] [blame] | 339 | */ |
| 340 | int snd_dmaengine_pcm_open_request_chan(struct snd_pcm_substream *substream, |
| 341 | dma_filter_fn filter_fn, void *filter_data) |
| 342 | { |
| 343 | return snd_dmaengine_pcm_open(substream, |
Lars-Peter Clausen | c999836 | 2013-04-15 19:19:51 +0200 | [diff] [blame] | 344 | snd_dmaengine_pcm_request_channel(filter_fn, filter_data)); |
Lars-Peter Clausen | 7c1c1d4 | 2013-04-15 19:19:48 +0200 | [diff] [blame] | 345 | } |
| 346 | EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_open_request_chan); |
| 347 | |
| 348 | /** |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 349 | * snd_dmaengine_pcm_close - Close a dmaengine based PCM substream |
| 350 | * @substream: PCM substream |
| 351 | */ |
| 352 | int snd_dmaengine_pcm_close(struct snd_pcm_substream *substream) |
| 353 | { |
| 354 | struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream); |
| 355 | |
Lars-Peter Clausen | bc0e734 | 2015-10-20 11:46:31 +0200 | [diff] [blame] | 356 | dmaengine_synchronize(prtd->dma_chan); |
Lars-Peter Clausen | e7f73a1 | 2012-02-22 10:49:08 +0100 | [diff] [blame] | 357 | kfree(prtd); |
| 358 | |
| 359 | return 0; |
| 360 | } |
| 361 | EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_close); |
Lothar Waßmann | cba69b4 | 2012-11-22 13:31:10 +0100 | [diff] [blame] | 362 | |
Lars-Peter Clausen | 7c1c1d4 | 2013-04-15 19:19:48 +0200 | [diff] [blame] | 363 | /** |
| 364 | * snd_dmaengine_pcm_release_chan_close - Close a dmaengine based PCM substream and release channel |
| 365 | * @substream: PCM substream |
| 366 | * |
| 367 | * Releases the DMA channel associated with the PCM substream. |
| 368 | */ |
| 369 | int snd_dmaengine_pcm_close_release_chan(struct snd_pcm_substream *substream) |
| 370 | { |
| 371 | struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream); |
| 372 | |
Lars-Peter Clausen | bc0e734 | 2015-10-20 11:46:31 +0200 | [diff] [blame] | 373 | dmaengine_synchronize(prtd->dma_chan); |
Lars-Peter Clausen | 7c1c1d4 | 2013-04-15 19:19:48 +0200 | [diff] [blame] | 374 | dma_release_channel(prtd->dma_chan); |
Lars-Peter Clausen | bc0e734 | 2015-10-20 11:46:31 +0200 | [diff] [blame] | 375 | kfree(prtd); |
Lars-Peter Clausen | 7c1c1d4 | 2013-04-15 19:19:48 +0200 | [diff] [blame] | 376 | |
Lars-Peter Clausen | bc0e734 | 2015-10-20 11:46:31 +0200 | [diff] [blame] | 377 | return 0; |
Lars-Peter Clausen | 7c1c1d4 | 2013-04-15 19:19:48 +0200 | [diff] [blame] | 378 | } |
| 379 | EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_close_release_chan); |
| 380 | |
Lothar Waßmann | cba69b4 | 2012-11-22 13:31:10 +0100 | [diff] [blame] | 381 | MODULE_LICENSE("GPL"); |