Blame view

include/sound/dmaengine_pcm.h 6 KB
1356a6071   Kuninori Morimoto   ASoC: soc-generic...
1
2
  /* SPDX-License-Identifier: GPL-2.0+
   *
e7f73a161   Lars-Peter Clausen   ASoC: Add dmaengi...
3
4
   *  Copyright (C) 2012, Analog Devices Inc.
   *	Author: Lars-Peter Clausen <lars@metafoo.de>
e7f73a161   Lars-Peter Clausen   ASoC: Add dmaengi...
5
   */
1356a6071   Kuninori Morimoto   ASoC: soc-generic...
6

e7f73a161   Lars-Peter Clausen   ASoC: Add dmaengi...
7
8
9
10
  #ifndef __SOUND_DMAENGINE_PCM_H__
  #define __SOUND_DMAENGINE_PCM_H__
  
  #include <sound/pcm.h>
c999836d3   Lars-Peter Clausen   ASoC: dmaengine_p...
11
  #include <sound/soc.h>
e7f73a161   Lars-Peter Clausen   ASoC: Add dmaengi...
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  #include <linux/dmaengine.h>
  
  /**
   * snd_pcm_substream_to_dma_direction - Get dma_transfer_direction for a PCM
   *   substream
   * @substream: PCM substream
   */
  static inline enum dma_transfer_direction
  snd_pcm_substream_to_dma_direction(const struct snd_pcm_substream *substream)
  {
  	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  		return DMA_MEM_TO_DEV;
  	else
  		return DMA_DEV_TO_MEM;
  }
e7f73a161   Lars-Peter Clausen   ASoC: Add dmaengi...
27
28
29
  int snd_hwparams_to_dma_slave_config(const struct snd_pcm_substream *substream,
  	const struct snd_pcm_hw_params *params, struct dma_slave_config *slave_config);
  int snd_dmaengine_pcm_trigger(struct snd_pcm_substream *substream, int cmd);
3528f27a5   Lars-Peter Clausen   ASoC: dmaengine-p...
30
  snd_pcm_uframes_t snd_dmaengine_pcm_pointer(struct snd_pcm_substream *substream);
9883ab229   Lars-Peter Clausen   ASoC: dmaengine-p...
31
  snd_pcm_uframes_t snd_dmaengine_pcm_pointer_no_residue(struct snd_pcm_substream *substream);
e7f73a161   Lars-Peter Clausen   ASoC: Add dmaengi...
32
33
  
  int snd_dmaengine_pcm_open(struct snd_pcm_substream *substream,
7c1c1d4a7   Lars-Peter Clausen   ASoC: dmaengine-p...
34
  	struct dma_chan *chan);
e7f73a161   Lars-Peter Clausen   ASoC: Add dmaengi...
35
  int snd_dmaengine_pcm_close(struct snd_pcm_substream *substream);
7c1c1d4a7   Lars-Peter Clausen   ASoC: dmaengine-p...
36
37
38
  int snd_dmaengine_pcm_open_request_chan(struct snd_pcm_substream *substream,
  	dma_filter_fn filter_fn, void *filter_data);
  int snd_dmaengine_pcm_close_release_chan(struct snd_pcm_substream *substream);
c999836d3   Lars-Peter Clausen   ASoC: dmaengine_p...
39
40
  struct dma_chan *snd_dmaengine_pcm_request_channel(dma_filter_fn filter_fn,
  	void *filter_data);
e7f73a161   Lars-Peter Clausen   ASoC: Add dmaengi...
41
  struct dma_chan *snd_dmaengine_pcm_get_chan(struct snd_pcm_substream *substream);
73fe01cfb   Matthias Reichl   ASoC: dmaengine_p...
42
43
44
45
46
47
48
49
50
  /*
   * The DAI supports packed transfers, eg 2 16-bit samples in a 32-bit word.
   * If this flag is set the dmaengine driver won't put any restriction on
   * the supported sample formats and set the DMA transfer size to undefined.
   * The DAI driver is responsible to disable any unsupported formats in it's
   * configuration and catch corner cases that are not already handled in
   * the ALSA core.
   */
  #define SND_DMAENGINE_PCM_DAI_FLAG_PACK BIT(0)
85c9f9c5f   Lars-Peter Clausen   ASoC: dmaengine-p...
51
52
53
54
55
56
57
58
59
60
  /**
   * struct snd_dmaengine_dai_dma_data - DAI DMA configuration data
   * @addr: Address of the DAI data source or destination register.
   * @addr_width: Width of the DAI data source or destination register.
   * @maxburst: Maximum number of words(note: words, as in units of the
   * src_addr_width member, not bytes) that can be send to or received from the
   * DAI in one burst.
   * @slave_id: Slave requester id for the DMA channel.
   * @filter_data: Custom DMA channel filter data, this will usually be used when
   * requesting the DMA channel.
9bfa24e90   Sylwester Nawrocki   ASoC: Revert "Dro...
61
   * @chan_name: Custom channel name to use when requesting DMA channel.
c0de42bf5   Lars-Peter Clausen   ASoC: dmaengine-p...
62
   * @fifo_size: FIFO size of the DAI controller in bytes
73fe01cfb   Matthias Reichl   ASoC: dmaengine_p...
63
   * @flags: PCM_DAI flags, only SND_DMAENGINE_PCM_DAI_FLAG_PACK for now
85c9f9c5f   Lars-Peter Clausen   ASoC: dmaengine-p...
64
65
66
67
68
69
70
   */
  struct snd_dmaengine_dai_dma_data {
  	dma_addr_t addr;
  	enum dma_slave_buswidth addr_width;
  	u32 maxburst;
  	unsigned int slave_id;
  	void *filter_data;
9bfa24e90   Sylwester Nawrocki   ASoC: Revert "Dro...
71
  	const char *chan_name;
c0de42bf5   Lars-Peter Clausen   ASoC: dmaengine-p...
72
  	unsigned int fifo_size;
73fe01cfb   Matthias Reichl   ASoC: dmaengine_p...
73
  	unsigned int flags;
58876d293   Shengjiu Wang   MLK-16224-2: ASoC...
74
  	unsigned int fifo_num;
85c9f9c5f   Lars-Peter Clausen   ASoC: dmaengine-p...
75
76
77
78
79
80
  };
  
  void snd_dmaengine_pcm_set_config_from_dai_data(
  	const struct snd_pcm_substream *substream,
  	const struct snd_dmaengine_dai_dma_data *dma_data,
  	struct dma_slave_config *config);
c999836d3   Lars-Peter Clausen   ASoC: dmaengine_p...
81
82
83
84
85
86
87
88
89
90
91
  
  /*
   * Try to request the DMA channel using compat_request_channel or
   * compat_filter_fn if it couldn't be requested through devicetree.
   */
  #define SND_DMAENGINE_PCM_FLAG_COMPAT BIT(0)
  /*
   * Don't try to request the DMA channels through devicetree. This flag only
   * makes sense if SND_DMAENGINE_PCM_FLAG_COMPAT is set as well.
   */
  #define SND_DMAENGINE_PCM_FLAG_NO_DT BIT(1)
610f78005   Lars-Peter Clausen   ASoC: dmaengine-p...
92
  /*
d1e1406c6   Lars-Peter Clausen   ASoC: generic-dma...
93
94
95
96
   * The PCM is half duplex and the DMA channel is shared between capture and
   * playback.
   */
  #define SND_DMAENGINE_PCM_FLAG_HALF_DUPLEX BIT(3)
c999836d3   Lars-Peter Clausen   ASoC: dmaengine_p...
97

28c4468b0   Lars-Peter Clausen   ASoC: Add a gener...
98
99
100
101
  /**
   * struct snd_dmaengine_pcm_config - Configuration data for dmaengine based PCM
   * @prepare_slave_config: Callback used to fill in the DMA slave_config for a
   *   PCM substream. Will be called from the PCM drivers hwparams callback.
c999836d3   Lars-Peter Clausen   ASoC: dmaengine_p...
102
103
   * @compat_request_channel: Callback to request a DMA channel for platforms
   *   which do not use devicetree.
2e78a5562   Olivier Moysan   ASoC: dmaengine_p...
104
105
   * @process: Callback used to apply processing on samples transferred from/to
   *   user space.
c999836d3   Lars-Peter Clausen   ASoC: dmaengine_p...
106
107
108
   * @compat_filter_fn: Will be used as the filter function when requesting a
   *  channel for platforms which do not use devicetree. The filter parameter
   *  will be the DAI's DMA data.
194c7dea0   Stephen Warren   ASoC: dmaengine: ...
109
110
111
112
   * @dma_dev: If set, request DMA channel on this device rather than the DAI
   *  device.
   * @chan_names: If set, these custom DMA channel names will be requested at
   *  registration time.
28c4468b0   Lars-Peter Clausen   ASoC: Add a gener...
113
114
   * @pcm_hardware: snd_pcm_hardware struct to be used for the PCM.
   * @prealloc_buffer_size: Size of the preallocated audio buffer.
c999836d3   Lars-Peter Clausen   ASoC: dmaengine_p...
115
116
117
118
119
   *
   * Note: If both compat_request_channel and compat_filter_fn are set
   * compat_request_channel will be used to request the channel and
   * compat_filter_fn will be ignored. Otherwise the channel will be requested
   * using dma_request_channel with compat_filter_fn as the filter function.
28c4468b0   Lars-Peter Clausen   ASoC: Add a gener...
120
121
122
123
124
   */
  struct snd_dmaengine_pcm_config {
  	int (*prepare_slave_config)(struct snd_pcm_substream *substream,
  			struct snd_pcm_hw_params *params,
  			struct dma_slave_config *slave_config);
c999836d3   Lars-Peter Clausen   ASoC: dmaengine_p...
125
126
127
  	struct dma_chan *(*compat_request_channel)(
  			struct snd_soc_pcm_runtime *rtd,
  			struct snd_pcm_substream *substream);
78648092e   Olivier Moysan   ASoC: dmaengine_p...
128
129
130
  	int (*process)(struct snd_pcm_substream *substream,
  		       int channel, unsigned long hwoff,
  		       void *buf, unsigned long bytes);
c999836d3   Lars-Peter Clausen   ASoC: dmaengine_p...
131
  	dma_filter_fn compat_filter_fn;
194c7dea0   Stephen Warren   ASoC: dmaengine: ...
132
133
  	struct device *dma_dev;
  	const char *chan_names[SNDRV_PCM_STREAM_LAST + 1];
28c4468b0   Lars-Peter Clausen   ASoC: Add a gener...
134
135
136
137
138
139
140
141
142
  
  	const struct snd_pcm_hardware *pcm_hardware;
  	unsigned int prealloc_buffer_size;
  };
  
  int snd_dmaengine_pcm_register(struct device *dev,
  	const struct snd_dmaengine_pcm_config *config,
  	unsigned int flags);
  void snd_dmaengine_pcm_unregister(struct device *dev);
21585ee84   Lars-Peter Clausen   ASoC: Add resourc...
143
144
145
  int devm_snd_dmaengine_pcm_register(struct device *dev,
  	const struct snd_dmaengine_pcm_config *config,
  	unsigned int flags);
28c4468b0   Lars-Peter Clausen   ASoC: Add a gener...
146
147
148
  int snd_dmaengine_pcm_prepare_slave_config(struct snd_pcm_substream *substream,
  	struct snd_pcm_hw_params *params,
  	struct dma_slave_config *slave_config);
be7ee5f32   Kuninori Morimoto   ASoC: soc-generic...
149
  #define SND_DMAENGINE_PCM_DRV_NAME "snd_dmaengine_pcm"
e7f73a161   Lars-Peter Clausen   ASoC: Add dmaengi...
150
  #endif