Root/
Source at commit 0b4b338e2a7be677ba82329d7b573b4b097cf070 created 11 years 6 days ago. By Lars-Peter Clausen, ASoC: mxs: Embed the mxs_dma_data struct in the mxs_pcm_dma_params struct | |
---|---|
1 | /* |
2 | * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved. |
3 | * |
4 | * Based on sound/soc/imx/imx-pcm-dma-mx2.c |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
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 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19 | */ |
20 | |
21 | #include <linux/clk.h> |
22 | #include <linux/delay.h> |
23 | #include <linux/device.h> |
24 | #include <linux/dma-mapping.h> |
25 | #include <linux/init.h> |
26 | #include <linux/interrupt.h> |
27 | #include <linux/module.h> |
28 | #include <linux/platform_device.h> |
29 | #include <linux/slab.h> |
30 | #include <linux/dmaengine.h> |
31 | |
32 | #include <sound/core.h> |
33 | #include <sound/initval.h> |
34 | #include <sound/pcm.h> |
35 | #include <sound/pcm_params.h> |
36 | #include <sound/soc.h> |
37 | #include <sound/dmaengine_pcm.h> |
38 | |
39 | #include "mxs-pcm.h" |
40 | |
41 | static struct snd_pcm_hardware snd_mxs_hardware = { |
42 | .info = SNDRV_PCM_INFO_MMAP | |
43 | SNDRV_PCM_INFO_MMAP_VALID | |
44 | SNDRV_PCM_INFO_PAUSE | |
45 | SNDRV_PCM_INFO_RESUME | |
46 | SNDRV_PCM_INFO_INTERLEAVED, |
47 | .formats = SNDRV_PCM_FMTBIT_S16_LE | |
48 | SNDRV_PCM_FMTBIT_S20_3LE | |
49 | SNDRV_PCM_FMTBIT_S24_LE, |
50 | .channels_min = 2, |
51 | .channels_max = 2, |
52 | .period_bytes_min = 32, |
53 | .period_bytes_max = 8192, |
54 | .periods_min = 1, |
55 | .periods_max = 52, |
56 | .buffer_bytes_max = 64 * 1024, |
57 | .fifo_size = 32, |
58 | |
59 | }; |
60 | |
61 | static bool filter(struct dma_chan *chan, void *param) |
62 | { |
63 | struct mxs_pcm_dma_params *dma_params = param; |
64 | |
65 | if (!mxs_dma_is_apbx(chan)) |
66 | return false; |
67 | |
68 | if (chan->chan_id != dma_params->chan_num) |
69 | return false; |
70 | |
71 | chan->private = &dma_params->dma_data; |
72 | |
73 | return true; |
74 | } |
75 | |
76 | static int snd_mxs_pcm_hw_params(struct snd_pcm_substream *substream, |
77 | struct snd_pcm_hw_params *params) |
78 | { |
79 | snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer); |
80 | |
81 | return 0; |
82 | } |
83 | |
84 | static int snd_mxs_open(struct snd_pcm_substream *substream) |
85 | { |
86 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
87 | |
88 | snd_soc_set_runtime_hwparams(substream, &snd_mxs_hardware); |
89 | |
90 | return snd_dmaengine_pcm_open(substream, filter, |
91 | snd_soc_dai_get_dma_data(rtd->cpu_dai, substream)); |
92 | } |
93 | |
94 | static int snd_mxs_pcm_mmap(struct snd_pcm_substream *substream, |
95 | struct vm_area_struct *vma) |
96 | { |
97 | struct snd_pcm_runtime *runtime = substream->runtime; |
98 | |
99 | return dma_mmap_writecombine(substream->pcm->card->dev, vma, |
100 | runtime->dma_area, |
101 | runtime->dma_addr, |
102 | runtime->dma_bytes); |
103 | } |
104 | |
105 | static struct snd_pcm_ops mxs_pcm_ops = { |
106 | .open = snd_mxs_open, |
107 | .close = snd_dmaengine_pcm_close, |
108 | .ioctl = snd_pcm_lib_ioctl, |
109 | .hw_params = snd_mxs_pcm_hw_params, |
110 | .trigger = snd_dmaengine_pcm_trigger, |
111 | .pointer = snd_dmaengine_pcm_pointer_no_residue, |
112 | .mmap = snd_mxs_pcm_mmap, |
113 | }; |
114 | |
115 | static int mxs_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream) |
116 | { |
117 | struct snd_pcm_substream *substream = pcm->streams[stream].substream; |
118 | struct snd_dma_buffer *buf = &substream->dma_buffer; |
119 | size_t size = snd_mxs_hardware.buffer_bytes_max; |
120 | |
121 | buf->dev.type = SNDRV_DMA_TYPE_DEV; |
122 | buf->dev.dev = pcm->card->dev; |
123 | buf->private_data = NULL; |
124 | buf->area = dma_alloc_writecombine(pcm->card->dev, size, |
125 | &buf->addr, GFP_KERNEL); |
126 | if (!buf->area) |
127 | return -ENOMEM; |
128 | buf->bytes = size; |
129 | |
130 | return 0; |
131 | } |
132 | |
133 | static u64 mxs_pcm_dmamask = DMA_BIT_MASK(32); |
134 | static int mxs_pcm_new(struct snd_soc_pcm_runtime *rtd) |
135 | { |
136 | struct snd_card *card = rtd->card->snd_card; |
137 | struct snd_pcm *pcm = rtd->pcm; |
138 | int ret = 0; |
139 | |
140 | if (!card->dev->dma_mask) |
141 | card->dev->dma_mask = &mxs_pcm_dmamask; |
142 | if (!card->dev->coherent_dma_mask) |
143 | card->dev->coherent_dma_mask = DMA_BIT_MASK(32); |
144 | |
145 | if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) { |
146 | ret = mxs_pcm_preallocate_dma_buffer(pcm, |
147 | SNDRV_PCM_STREAM_PLAYBACK); |
148 | if (ret) |
149 | goto out; |
150 | } |
151 | |
152 | if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) { |
153 | ret = mxs_pcm_preallocate_dma_buffer(pcm, |
154 | SNDRV_PCM_STREAM_CAPTURE); |
155 | if (ret) |
156 | goto out; |
157 | } |
158 | |
159 | out: |
160 | return ret; |
161 | } |
162 | |
163 | static void mxs_pcm_free(struct snd_pcm *pcm) |
164 | { |
165 | struct snd_pcm_substream *substream; |
166 | struct snd_dma_buffer *buf; |
167 | int stream; |
168 | |
169 | for (stream = 0; stream < 2; stream++) { |
170 | substream = pcm->streams[stream].substream; |
171 | if (!substream) |
172 | continue; |
173 | |
174 | buf = &substream->dma_buffer; |
175 | if (!buf->area) |
176 | continue; |
177 | |
178 | dma_free_writecombine(pcm->card->dev, buf->bytes, |
179 | buf->area, buf->addr); |
180 | buf->area = NULL; |
181 | } |
182 | } |
183 | |
184 | static struct snd_soc_platform_driver mxs_soc_platform = { |
185 | .ops = &mxs_pcm_ops, |
186 | .pcm_new = mxs_pcm_new, |
187 | .pcm_free = mxs_pcm_free, |
188 | }; |
189 | |
190 | int mxs_pcm_platform_register(struct device *dev) |
191 | { |
192 | return snd_soc_register_platform(dev, &mxs_soc_platform); |
193 | } |
194 | EXPORT_SYMBOL_GPL(mxs_pcm_platform_register); |
195 | |
196 | void mxs_pcm_platform_unregister(struct device *dev) |
197 | { |
198 | snd_soc_unregister_platform(dev); |
199 | } |
200 | EXPORT_SYMBOL_GPL(mxs_pcm_platform_unregister); |
201 | |
202 | MODULE_LICENSE("GPL"); |
203 |
Branches:
ben-wpan
ben-wpan-stefan
javiroman/ks7010
jz-2.6.34
jz-2.6.34-rc5
jz-2.6.34-rc6
jz-2.6.34-rc7
jz-2.6.35
jz-2.6.36
jz-2.6.37
jz-2.6.38
jz-2.6.39
jz-3.0
jz-3.1
jz-3.11
jz-3.12
jz-3.13
jz-3.15
jz-3.16
jz-3.18-dt
jz-3.2
jz-3.3
jz-3.4
jz-3.5
jz-3.6
jz-3.6-rc2-pwm
jz-3.9
jz-3.9-clk
jz-3.9-rc8
jz47xx
jz47xx-2.6.38
master
Tags:
od-2011-09-04
od-2011-09-18
v2.6.34-rc5
v2.6.34-rc6
v2.6.34-rc7
v3.9