diff options
Diffstat (limited to 'sound/soc/nuc900')
-rw-r--r-- | sound/soc/nuc900/Kconfig | 27 | ||||
-rw-r--r-- | sound/soc/nuc900/Makefile | 11 | ||||
-rw-r--r-- | sound/soc/nuc900/nuc900-ac97.c | 430 | ||||
-rw-r--r-- | sound/soc/nuc900/nuc900-audio.c | 81 | ||||
-rw-r--r-- | sound/soc/nuc900/nuc900-audio.h | 117 | ||||
-rw-r--r-- | sound/soc/nuc900/nuc900-pcm.c | 354 |
6 files changed, 1020 insertions, 0 deletions
diff --git a/sound/soc/nuc900/Kconfig b/sound/soc/nuc900/Kconfig new file mode 100644 index 000000000000..a0ed1c618f60 --- /dev/null +++ b/sound/soc/nuc900/Kconfig | |||
@@ -0,0 +1,27 @@ | |||
1 | ## | ||
2 | ## NUC900 series AC97 API | ||
3 | ## | ||
4 | config SND_SOC_NUC900 | ||
5 | tristate "SoC Audio for NUC900 series" | ||
6 | depends on ARCH_W90X900 | ||
7 | help | ||
8 | This option enables support for AC97 mode on the NUC900 SoC. | ||
9 | |||
10 | config SND_SOC_NUC900_AC97 | ||
11 | tristate | ||
12 | select AC97_BUS | ||
13 | select SND_AC97_CODEC | ||
14 | select SND_SOC_AC97_BUS | ||
15 | |||
16 | |||
17 | ## | ||
18 | ## Boards | ||
19 | ## | ||
20 | config SND_SOC_NUC900EVB | ||
21 | tristate "NUC900 AC97 support for demo board" | ||
22 | depends on SND_SOC_NUC900 | ||
23 | select SND_SOC_NUC900_AC97 | ||
24 | select SND_SOC_AC97_CODEC | ||
25 | help | ||
26 | Select this option to enable audio (AC97) on the | ||
27 | NUC900 demoboard. | ||
diff --git a/sound/soc/nuc900/Makefile b/sound/soc/nuc900/Makefile new file mode 100644 index 000000000000..7e46c7150316 --- /dev/null +++ b/sound/soc/nuc900/Makefile | |||
@@ -0,0 +1,11 @@ | |||
1 | # NUC900 series audio | ||
2 | snd-soc-nuc900-pcm-objs := nuc900-pcm.o | ||
3 | snd-soc-nuc900-ac97-objs := nuc900-ac97.o | ||
4 | |||
5 | obj-$(CONFIG_SND_SOC_NUC900) += snd-soc-nuc900-pcm.o | ||
6 | obj-$(CONFIG_SND_SOC_NUC900_AC97) += snd-soc-nuc900-ac97.o | ||
7 | |||
8 | # Boards | ||
9 | snd-soc-nuc900-audio-objs := nuc900-audio.o | ||
10 | |||
11 | obj-$(CONFIG_SND_SOC_NUC900EVB) += snd-soc-nuc900-audio.o | ||
diff --git a/sound/soc/nuc900/nuc900-ac97.c b/sound/soc/nuc900/nuc900-ac97.c new file mode 100644 index 000000000000..caa7c901bc2e --- /dev/null +++ b/sound/soc/nuc900/nuc900-ac97.c | |||
@@ -0,0 +1,430 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2009-2010 Nuvoton technology corporation. | ||
3 | * | ||
4 | * Wan ZongShun <mcuos.com@gmail.com> | ||
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;version 2 of the License. | ||
9 | * | ||
10 | */ | ||
11 | |||
12 | #include <linux/init.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <linux/slab.h> | ||
15 | #include <linux/device.h> | ||
16 | #include <linux/delay.h> | ||
17 | #include <linux/mutex.h> | ||
18 | #include <linux/suspend.h> | ||
19 | #include <sound/core.h> | ||
20 | #include <sound/pcm.h> | ||
21 | #include <sound/initval.h> | ||
22 | #include <sound/soc.h> | ||
23 | #include <linux/device.h> | ||
24 | #include <linux/clk.h> | ||
25 | |||
26 | #include <mach/mfp.h> | ||
27 | |||
28 | #include "nuc900-audio.h" | ||
29 | |||
30 | static DEFINE_MUTEX(ac97_mutex); | ||
31 | struct nuc900_audio *nuc900_ac97_data; | ||
32 | |||
33 | static int nuc900_checkready(void) | ||
34 | { | ||
35 | struct nuc900_audio *nuc900_audio = nuc900_ac97_data; | ||
36 | |||
37 | if (!(AUDIO_READ(nuc900_audio->mmio + ACTL_ACIS0) & CODEC_READY)) | ||
38 | return -EPERM; | ||
39 | |||
40 | return 0; | ||
41 | } | ||
42 | |||
43 | /* AC97 controller reads codec register */ | ||
44 | static unsigned short nuc900_ac97_read(struct snd_ac97 *ac97, | ||
45 | unsigned short reg) | ||
46 | { | ||
47 | struct nuc900_audio *nuc900_audio = nuc900_ac97_data; | ||
48 | unsigned long timeout = 0x10000, val; | ||
49 | |||
50 | mutex_lock(&ac97_mutex); | ||
51 | |||
52 | val = nuc900_checkready(); | ||
53 | if (!!val) { | ||
54 | dev_err(nuc900_audio->dev, "AC97 codec is not ready\n"); | ||
55 | goto out; | ||
56 | } | ||
57 | |||
58 | /* set the R_WB bit and write register index */ | ||
59 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_ACOS1, R_WB | reg); | ||
60 | |||
61 | /* set the valid frame bit and valid slots */ | ||
62 | val = AUDIO_READ(nuc900_audio->mmio + ACTL_ACOS0); | ||
63 | val |= (VALID_FRAME | SLOT1_VALID); | ||
64 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_ACOS0, val); | ||
65 | |||
66 | udelay(100); | ||
67 | |||
68 | /* polling the AC_R_FINISH */ | ||
69 | while (!(AUDIO_READ(nuc900_audio->mmio + ACTL_ACCON) & AC_R_FINISH) | ||
70 | && timeout--) | ||
71 | mdelay(1); | ||
72 | |||
73 | if (!timeout) { | ||
74 | dev_err(nuc900_audio->dev, "AC97 read register time out !\n"); | ||
75 | val = -EPERM; | ||
76 | goto out; | ||
77 | } | ||
78 | |||
79 | val = AUDIO_READ(nuc900_audio->mmio + ACTL_ACOS0) ; | ||
80 | val &= ~SLOT1_VALID; | ||
81 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_ACOS0, val); | ||
82 | |||
83 | if (AUDIO_READ(nuc900_audio->mmio + ACTL_ACIS1) >> 2 != reg) { | ||
84 | dev_err(nuc900_audio->dev, | ||
85 | "R_INDEX of REG_ACTL_ACIS1 not match!\n"); | ||
86 | } | ||
87 | |||
88 | udelay(100); | ||
89 | val = (AUDIO_READ(nuc900_audio->mmio + ACTL_ACIS2) & 0xFFFF); | ||
90 | |||
91 | out: | ||
92 | mutex_unlock(&ac97_mutex); | ||
93 | return val; | ||
94 | } | ||
95 | |||
96 | /* AC97 controller writes to codec register */ | ||
97 | static void nuc900_ac97_write(struct snd_ac97 *ac97, unsigned short reg, | ||
98 | unsigned short val) | ||
99 | { | ||
100 | struct nuc900_audio *nuc900_audio = nuc900_ac97_data; | ||
101 | unsigned long tmp, timeout = 0x10000; | ||
102 | |||
103 | mutex_lock(&ac97_mutex); | ||
104 | |||
105 | tmp = nuc900_checkready(); | ||
106 | if (!!tmp) | ||
107 | dev_err(nuc900_audio->dev, "AC97 codec is not ready\n"); | ||
108 | |||
109 | /* clear the R_WB bit and write register index */ | ||
110 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_ACOS1, reg); | ||
111 | |||
112 | /* write register value */ | ||
113 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_ACOS2, val); | ||
114 | |||
115 | /* set the valid frame bit and valid slots */ | ||
116 | tmp = AUDIO_READ(nuc900_audio->mmio + ACTL_ACOS0); | ||
117 | tmp |= SLOT1_VALID | SLOT2_VALID | VALID_FRAME; | ||
118 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_ACOS0, tmp); | ||
119 | |||
120 | udelay(100); | ||
121 | |||
122 | /* polling the AC_W_FINISH */ | ||
123 | while ((AUDIO_READ(nuc900_audio->mmio + ACTL_ACCON) & AC_W_FINISH) | ||
124 | && timeout--) | ||
125 | mdelay(1); | ||
126 | |||
127 | if (!timeout) | ||
128 | dev_err(nuc900_audio->dev, "AC97 write register time out !\n"); | ||
129 | |||
130 | tmp = AUDIO_READ(nuc900_audio->mmio + ACTL_ACOS0); | ||
131 | tmp &= ~(SLOT1_VALID | SLOT2_VALID); | ||
132 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_ACOS0, tmp); | ||
133 | |||
134 | mutex_unlock(&ac97_mutex); | ||
135 | |||
136 | } | ||
137 | |||
138 | static void nuc900_ac97_warm_reset(struct snd_ac97 *ac97) | ||
139 | { | ||
140 | struct nuc900_audio *nuc900_audio = nuc900_ac97_data; | ||
141 | unsigned long val; | ||
142 | |||
143 | mutex_lock(&ac97_mutex); | ||
144 | |||
145 | /* warm reset AC 97 */ | ||
146 | val = AUDIO_READ(nuc900_audio->mmio + ACTL_ACCON); | ||
147 | val |= AC_W_RES; | ||
148 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_ACCON, val); | ||
149 | |||
150 | udelay(100); | ||
151 | |||
152 | val = nuc900_checkready(); | ||
153 | if (!!val) | ||
154 | dev_err(nuc900_audio->dev, "AC97 codec is not ready\n"); | ||
155 | |||
156 | mutex_unlock(&ac97_mutex); | ||
157 | } | ||
158 | |||
159 | static void nuc900_ac97_cold_reset(struct snd_ac97 *ac97) | ||
160 | { | ||
161 | struct nuc900_audio *nuc900_audio = nuc900_ac97_data; | ||
162 | unsigned long val; | ||
163 | |||
164 | mutex_lock(&ac97_mutex); | ||
165 | |||
166 | /* reset Audio Controller */ | ||
167 | val = AUDIO_READ(nuc900_audio->mmio + ACTL_RESET); | ||
168 | val |= ACTL_RESET_BIT; | ||
169 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_RESET, val); | ||
170 | |||
171 | val = AUDIO_READ(nuc900_audio->mmio + ACTL_RESET); | ||
172 | val &= (~ACTL_RESET_BIT); | ||
173 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_RESET, val); | ||
174 | |||
175 | /* reset AC-link interface */ | ||
176 | |||
177 | val = AUDIO_READ(nuc900_audio->mmio + ACTL_RESET); | ||
178 | val |= AC_RESET; | ||
179 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_RESET, val); | ||
180 | |||
181 | val = AUDIO_READ(nuc900_audio->mmio + ACTL_RESET); | ||
182 | val &= ~AC_RESET; | ||
183 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_RESET, val); | ||
184 | |||
185 | /* cold reset AC 97 */ | ||
186 | val = AUDIO_READ(nuc900_audio->mmio + ACTL_ACCON); | ||
187 | val |= AC_C_RES; | ||
188 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_ACCON, val); | ||
189 | |||
190 | val = AUDIO_READ(nuc900_audio->mmio + ACTL_ACCON); | ||
191 | val &= (~AC_C_RES); | ||
192 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_ACCON, val); | ||
193 | |||
194 | udelay(100); | ||
195 | |||
196 | mutex_unlock(&ac97_mutex); | ||
197 | |||
198 | } | ||
199 | |||
200 | /* AC97 controller operations */ | ||
201 | struct snd_ac97_bus_ops soc_ac97_ops = { | ||
202 | .read = nuc900_ac97_read, | ||
203 | .write = nuc900_ac97_write, | ||
204 | .reset = nuc900_ac97_cold_reset, | ||
205 | .warm_reset = nuc900_ac97_warm_reset, | ||
206 | } | ||
207 | EXPORT_SYMBOL_GPL(soc_ac97_ops); | ||
208 | |||
209 | static int nuc900_ac97_trigger(struct snd_pcm_substream *substream, | ||
210 | int cmd, struct snd_soc_dai *dai) | ||
211 | { | ||
212 | struct nuc900_audio *nuc900_audio = nuc900_ac97_data; | ||
213 | int ret; | ||
214 | unsigned long val, tmp; | ||
215 | |||
216 | ret = 0; | ||
217 | |||
218 | switch (cmd) { | ||
219 | case SNDRV_PCM_TRIGGER_START: | ||
220 | case SNDRV_PCM_TRIGGER_RESUME: | ||
221 | val = AUDIO_READ(nuc900_audio->mmio + ACTL_RESET); | ||
222 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | ||
223 | tmp = AUDIO_READ(nuc900_audio->mmio + ACTL_ACOS0); | ||
224 | tmp |= (SLOT3_VALID | SLOT4_VALID | VALID_FRAME); | ||
225 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_ACOS0, tmp); | ||
226 | |||
227 | tmp = AUDIO_READ(nuc900_audio->mmio + ACTL_PSR); | ||
228 | tmp |= (P_DMA_END_IRQ | P_DMA_MIDDLE_IRQ); | ||
229 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_PSR, tmp); | ||
230 | val |= AC_PLAY; | ||
231 | } else { | ||
232 | tmp = AUDIO_READ(nuc900_audio->mmio + ACTL_RSR); | ||
233 | tmp |= (R_DMA_END_IRQ | R_DMA_MIDDLE_IRQ); | ||
234 | |||
235 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_RSR, tmp); | ||
236 | val |= AC_RECORD; | ||
237 | } | ||
238 | |||
239 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_RESET, val); | ||
240 | |||
241 | break; | ||
242 | case SNDRV_PCM_TRIGGER_STOP: | ||
243 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
244 | val = AUDIO_READ(nuc900_audio->mmio + ACTL_RESET); | ||
245 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | ||
246 | tmp = AUDIO_READ(nuc900_audio->mmio + ACTL_ACOS0); | ||
247 | tmp &= ~(SLOT3_VALID | SLOT4_VALID); | ||
248 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_ACOS0, tmp); | ||
249 | |||
250 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_PSR, RESET_PRSR); | ||
251 | val &= ~AC_PLAY; | ||
252 | } else { | ||
253 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_RSR, RESET_PRSR); | ||
254 | val &= ~AC_RECORD; | ||
255 | } | ||
256 | |||
257 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_RESET, val); | ||
258 | |||
259 | break; | ||
260 | default: | ||
261 | ret = -EINVAL; | ||
262 | } | ||
263 | |||
264 | return ret; | ||
265 | } | ||
266 | |||
267 | static int nuc900_ac97_probe(struct platform_device *pdev, | ||
268 | struct snd_soc_dai *dai) | ||
269 | { | ||
270 | struct nuc900_audio *nuc900_audio = nuc900_ac97_data; | ||
271 | unsigned long val; | ||
272 | |||
273 | mutex_lock(&ac97_mutex); | ||
274 | |||
275 | /* enable unit clock */ | ||
276 | clk_enable(nuc900_audio->clk); | ||
277 | |||
278 | /* enable audio controller and AC-link interface */ | ||
279 | val = AUDIO_READ(nuc900_audio->mmio + ACTL_CON); | ||
280 | val |= (IIS_AC_PIN_SEL | ACLINK_EN); | ||
281 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_CON, val); | ||
282 | |||
283 | mutex_unlock(&ac97_mutex); | ||
284 | |||
285 | return 0; | ||
286 | } | ||
287 | |||
288 | static void nuc900_ac97_remove(struct platform_device *pdev, | ||
289 | struct snd_soc_dai *dai) | ||
290 | { | ||
291 | struct nuc900_audio *nuc900_audio = nuc900_ac97_data; | ||
292 | |||
293 | clk_disable(nuc900_audio->clk); | ||
294 | } | ||
295 | |||
296 | static struct snd_soc_dai_ops nuc900_ac97_dai_ops = { | ||
297 | .trigger = nuc900_ac97_trigger, | ||
298 | }; | ||
299 | |||
300 | struct snd_soc_dai nuc900_ac97_dai = { | ||
301 | .name = "nuc900-ac97", | ||
302 | .probe = nuc900_ac97_probe, | ||
303 | .remove = nuc900_ac97_remove, | ||
304 | .ac97_control = 1, | ||
305 | .playback = { | ||
306 | .rates = SNDRV_PCM_RATE_8000_48000, | ||
307 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | ||
308 | .channels_min = 1, | ||
309 | .channels_max = 2, | ||
310 | }, | ||
311 | .capture = { | ||
312 | .rates = SNDRV_PCM_RATE_8000_48000, | ||
313 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | ||
314 | .channels_min = 1, | ||
315 | .channels_max = 2, | ||
316 | }, | ||
317 | .ops = &nuc900_ac97_dai_ops, | ||
318 | } | ||
319 | EXPORT_SYMBOL_GPL(nuc900_ac97_dai); | ||
320 | |||
321 | static int __devinit nuc900_ac97_drvprobe(struct platform_device *pdev) | ||
322 | { | ||
323 | struct nuc900_audio *nuc900_audio; | ||
324 | int ret; | ||
325 | |||
326 | if (nuc900_ac97_data) | ||
327 | return -EBUSY; | ||
328 | |||
329 | nuc900_audio = kzalloc(sizeof(struct nuc900_audio), GFP_KERNEL); | ||
330 | if (!nuc900_audio) | ||
331 | return -ENOMEM; | ||
332 | |||
333 | spin_lock_init(&nuc900_audio->lock); | ||
334 | |||
335 | nuc900_audio->res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
336 | if (!nuc900_audio->res) { | ||
337 | ret = -ENODEV; | ||
338 | goto out0; | ||
339 | } | ||
340 | |||
341 | if (!request_mem_region(nuc900_audio->res->start, | ||
342 | resource_size(nuc900_audio->res), pdev->name)) { | ||
343 | ret = -EBUSY; | ||
344 | goto out0; | ||
345 | } | ||
346 | |||
347 | nuc900_audio->mmio = ioremap(nuc900_audio->res->start, | ||
348 | resource_size(nuc900_audio->res)); | ||
349 | if (!nuc900_audio->mmio) { | ||
350 | ret = -ENOMEM; | ||
351 | goto out1; | ||
352 | } | ||
353 | |||
354 | nuc900_audio->clk = clk_get(&pdev->dev, NULL); | ||
355 | if (IS_ERR(nuc900_audio->clk)) { | ||
356 | ret = PTR_ERR(nuc900_audio->clk); | ||
357 | goto out2; | ||
358 | } | ||
359 | |||
360 | nuc900_audio->irq_num = platform_get_irq(pdev, 0); | ||
361 | if (!nuc900_audio->irq_num) { | ||
362 | ret = -EBUSY; | ||
363 | goto out2; | ||
364 | } | ||
365 | |||
366 | nuc900_ac97_data = nuc900_audio; | ||
367 | |||
368 | nuc900_audio->dev = nuc900_ac97_dai.dev = &pdev->dev; | ||
369 | |||
370 | ret = snd_soc_register_dai(&nuc900_ac97_dai); | ||
371 | if (ret) | ||
372 | goto out3; | ||
373 | |||
374 | mfp_set_groupg(nuc900_audio->dev); /* enbale ac97 multifunction pin*/ | ||
375 | |||
376 | return 0; | ||
377 | |||
378 | out3: | ||
379 | clk_put(nuc900_audio->clk); | ||
380 | out2: | ||
381 | iounmap(nuc900_audio->mmio); | ||
382 | out1: | ||
383 | release_mem_region(nuc900_audio->res->start, | ||
384 | resource_size(nuc900_audio->res)); | ||
385 | out0: | ||
386 | kfree(nuc900_audio); | ||
387 | return ret; | ||
388 | } | ||
389 | |||
390 | static int __devexit nuc900_ac97_drvremove(struct platform_device *pdev) | ||
391 | { | ||
392 | |||
393 | snd_soc_unregister_dai(&nuc900_ac97_dai); | ||
394 | |||
395 | clk_put(nuc900_ac97_data->clk); | ||
396 | iounmap(nuc900_ac97_data->mmio); | ||
397 | release_mem_region(nuc900_ac97_data->res->start, | ||
398 | resource_size(nuc900_ac97_data->res)); | ||
399 | |||
400 | nuc900_ac97_data = NULL; | ||
401 | |||
402 | return 0; | ||
403 | } | ||
404 | |||
405 | static struct platform_driver nuc900_ac97_driver = { | ||
406 | .driver = { | ||
407 | .name = "nuc900-audio", | ||
408 | .owner = THIS_MODULE, | ||
409 | }, | ||
410 | .probe = nuc900_ac97_drvprobe, | ||
411 | .remove = __devexit_p(nuc900_ac97_drvremove), | ||
412 | }; | ||
413 | |||
414 | static int __init nuc900_ac97_init(void) | ||
415 | { | ||
416 | return platform_driver_register(&nuc900_ac97_driver); | ||
417 | } | ||
418 | |||
419 | static void __exit nuc900_ac97_exit(void) | ||
420 | { | ||
421 | platform_driver_unregister(&nuc900_ac97_driver); | ||
422 | } | ||
423 | |||
424 | module_init(nuc900_ac97_init); | ||
425 | module_exit(nuc900_ac97_exit); | ||
426 | |||
427 | MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>"); | ||
428 | MODULE_DESCRIPTION("NUC900 AC97 SoC driver!"); | ||
429 | MODULE_LICENSE("GPL"); | ||
430 | MODULE_ALIAS("platform:nuc900-ac97"); | ||
diff --git a/sound/soc/nuc900/nuc900-audio.c b/sound/soc/nuc900/nuc900-audio.c new file mode 100644 index 000000000000..72e6f518f7b2 --- /dev/null +++ b/sound/soc/nuc900/nuc900-audio.c | |||
@@ -0,0 +1,81 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2010 Nuvoton technology corporation. | ||
3 | * | ||
4 | * Wan ZongShun <mcuos.com@gmail.com> | ||
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;version 2 of the License. | ||
9 | * | ||
10 | */ | ||
11 | |||
12 | #include <linux/module.h> | ||
13 | #include <linux/moduleparam.h> | ||
14 | #include <linux/timer.h> | ||
15 | #include <linux/interrupt.h> | ||
16 | #include <linux/platform_device.h> | ||
17 | |||
18 | #include <sound/core.h> | ||
19 | #include <sound/pcm.h> | ||
20 | #include <sound/soc.h> | ||
21 | #include <sound/soc-dapm.h> | ||
22 | |||
23 | #include "../codecs/ac97.h" | ||
24 | #include "nuc900-audio.h" | ||
25 | |||
26 | static struct snd_soc_dai_link nuc900evb_ac97_dai = { | ||
27 | .name = "AC97", | ||
28 | .stream_name = "AC97 HiFi", | ||
29 | .cpu_dai = &nuc900_ac97_dai, | ||
30 | .codec_dai = &ac97_dai, | ||
31 | }; | ||
32 | |||
33 | static struct snd_soc_card nuc900evb_audio_machine = { | ||
34 | .name = "NUC900EVB_AC97", | ||
35 | .dai_link = &nuc900evb_ac97_dai, | ||
36 | .num_links = 1, | ||
37 | .platform = &nuc900_soc_platform, | ||
38 | }; | ||
39 | |||
40 | static struct snd_soc_device nuc900evb_ac97_devdata = { | ||
41 | .card = &nuc900evb_audio_machine, | ||
42 | .codec_dev = &soc_codec_dev_ac97, | ||
43 | }; | ||
44 | |||
45 | static struct platform_device *nuc900evb_asoc_dev; | ||
46 | |||
47 | static int __init nuc900evb_audio_init(void) | ||
48 | { | ||
49 | int ret; | ||
50 | |||
51 | ret = -ENOMEM; | ||
52 | nuc900evb_asoc_dev = platform_device_alloc("soc-audio", -1); | ||
53 | if (!nuc900evb_asoc_dev) | ||
54 | goto out; | ||
55 | |||
56 | /* nuc900 board audio device */ | ||
57 | platform_set_drvdata(nuc900evb_asoc_dev, &nuc900evb_ac97_devdata); | ||
58 | |||
59 | nuc900evb_ac97_devdata.dev = &nuc900evb_asoc_dev->dev; | ||
60 | ret = platform_device_add(nuc900evb_asoc_dev); | ||
61 | |||
62 | if (ret) { | ||
63 | platform_device_put(nuc900evb_asoc_dev); | ||
64 | nuc900evb_asoc_dev = NULL; | ||
65 | } | ||
66 | |||
67 | out: | ||
68 | return ret; | ||
69 | } | ||
70 | |||
71 | static void __exit nuc900evb_audio_exit(void) | ||
72 | { | ||
73 | platform_device_unregister(nuc900evb_asoc_dev); | ||
74 | } | ||
75 | |||
76 | module_init(nuc900evb_audio_init); | ||
77 | module_exit(nuc900evb_audio_exit); | ||
78 | |||
79 | MODULE_LICENSE("GPL"); | ||
80 | MODULE_DESCRIPTION("NUC900 Series ASoC audio support"); | ||
81 | MODULE_AUTHOR("Wan ZongShun"); | ||
diff --git a/sound/soc/nuc900/nuc900-audio.h b/sound/soc/nuc900/nuc900-audio.h new file mode 100644 index 000000000000..3038f519729f --- /dev/null +++ b/sound/soc/nuc900/nuc900-audio.h | |||
@@ -0,0 +1,117 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2010 Nuvoton technology corporation. | ||
3 | * | ||
4 | * Wan ZongShun <mcuos.com@gmail.com> | ||
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;version 2 of the License. | ||
9 | * | ||
10 | */ | ||
11 | |||
12 | #ifndef _NUC900_AUDIO_H | ||
13 | #define _NUC900_AUDIO_H | ||
14 | |||
15 | #include <linux/io.h> | ||
16 | |||
17 | /* Audio Control Registers */ | ||
18 | #define ACTL_CON 0x00 | ||
19 | #define ACTL_RESET 0x04 | ||
20 | #define ACTL_RDSTB 0x08 | ||
21 | #define ACTL_RDST_LENGTH 0x0C | ||
22 | #define ACTL_RDSTC 0x10 | ||
23 | #define ACTL_RSR 0x14 | ||
24 | #define ACTL_PDSTB 0x18 | ||
25 | #define ACTL_PDST_LENGTH 0x1C | ||
26 | #define ACTL_PDSTC 0x20 | ||
27 | #define ACTL_PSR 0x24 | ||
28 | #define ACTL_IISCON 0x28 | ||
29 | #define ACTL_ACCON 0x2C | ||
30 | #define ACTL_ACOS0 0x30 | ||
31 | #define ACTL_ACOS1 0x34 | ||
32 | #define ACTL_ACOS2 0x38 | ||
33 | #define ACTL_ACIS0 0x3C | ||
34 | #define ACTL_ACIS1 0x40 | ||
35 | #define ACTL_ACIS2 0x44 | ||
36 | #define ACTL_COUNTER 0x48 | ||
37 | |||
38 | /* bit definition of REG_ACTL_CON register */ | ||
39 | #define R_DMA_IRQ 0x1000 | ||
40 | #define T_DMA_IRQ 0x0800 | ||
41 | #define IIS_AC_PIN_SEL 0x0100 | ||
42 | #define FIFO_TH 0x0080 | ||
43 | #define ADC_EN 0x0010 | ||
44 | #define M80_EN 0x0008 | ||
45 | #define ACLINK_EN 0x0004 | ||
46 | #define IIS_EN 0x0002 | ||
47 | |||
48 | /* bit definition of REG_ACTL_RESET register */ | ||
49 | #define W5691_PLAY 0x20000 | ||
50 | #define ACTL_RESET_BIT 0x10000 | ||
51 | #define RECORD_RIGHT_CHNNEL 0x08000 | ||
52 | #define RECORD_LEFT_CHNNEL 0x04000 | ||
53 | #define PLAY_RIGHT_CHNNEL 0x02000 | ||
54 | #define PLAY_LEFT_CHNNEL 0x01000 | ||
55 | #define DAC_PLAY 0x00800 | ||
56 | #define ADC_RECORD 0x00400 | ||
57 | #define M80_PLAY 0x00200 | ||
58 | #define AC_RECORD 0x00100 | ||
59 | #define AC_PLAY 0x00080 | ||
60 | #define IIS_RECORD 0x00040 | ||
61 | #define IIS_PLAY 0x00020 | ||
62 | #define DAC_RESET 0x00010 | ||
63 | #define ADC_RESET 0x00008 | ||
64 | #define M80_RESET 0x00004 | ||
65 | #define AC_RESET 0x00002 | ||
66 | #define IIS_RESET 0x00001 | ||
67 | |||
68 | /* bit definition of REG_ACTL_ACCON register */ | ||
69 | #define AC_BCLK_PU_EN 0x20 | ||
70 | #define AC_R_FINISH 0x10 | ||
71 | #define AC_W_FINISH 0x08 | ||
72 | #define AC_W_RES 0x04 | ||
73 | #define AC_C_RES 0x02 | ||
74 | |||
75 | /* bit definition of ACTL_RSR register */ | ||
76 | #define R_FIFO_EMPTY 0x04 | ||
77 | #define R_DMA_END_IRQ 0x02 | ||
78 | #define R_DMA_MIDDLE_IRQ 0x01 | ||
79 | |||
80 | /* bit definition of ACTL_PSR register */ | ||
81 | #define P_FIFO_EMPTY 0x04 | ||
82 | #define P_DMA_END_IRQ 0x02 | ||
83 | #define P_DMA_MIDDLE_IRQ 0x01 | ||
84 | |||
85 | /* bit definition of ACTL_ACOS0 register */ | ||
86 | #define SLOT1_VALID 0x01 | ||
87 | #define SLOT2_VALID 0x02 | ||
88 | #define SLOT3_VALID 0x04 | ||
89 | #define SLOT4_VALID 0x08 | ||
90 | #define VALID_FRAME 0x10 | ||
91 | |||
92 | /* bit definition of ACTL_ACOS1 register */ | ||
93 | #define R_WB 0x80 | ||
94 | |||
95 | #define CODEC_READY 0x10 | ||
96 | #define RESET_PRSR 0x00 | ||
97 | #define AUDIO_WRITE(addr, val) __raw_writel(val, addr) | ||
98 | #define AUDIO_READ(addr) __raw_readl(addr) | ||
99 | |||
100 | struct nuc900_audio { | ||
101 | void __iomem *mmio; | ||
102 | spinlock_t lock; | ||
103 | dma_addr_t dma_addr[2]; | ||
104 | unsigned long buffersize[2]; | ||
105 | unsigned long irq_num; | ||
106 | struct snd_pcm_substream *substream; | ||
107 | struct resource *res; | ||
108 | struct clk *clk; | ||
109 | struct device *dev; | ||
110 | |||
111 | }; | ||
112 | |||
113 | extern struct nuc900_audio *nuc900_ac97_data; | ||
114 | extern struct snd_soc_dai nuc900_ac97_dai; | ||
115 | extern struct snd_soc_platform nuc900_soc_platform; | ||
116 | |||
117 | #endif /*end _NUC900_AUDIO_H */ | ||
diff --git a/sound/soc/nuc900/nuc900-pcm.c b/sound/soc/nuc900/nuc900-pcm.c new file mode 100644 index 000000000000..e81e803b3a63 --- /dev/null +++ b/sound/soc/nuc900/nuc900-pcm.c | |||
@@ -0,0 +1,354 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2010 Nuvoton technology corporation. | ||
3 | * | ||
4 | * Wan ZongShun <mcuos.com@gmail.com> | ||
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;version 2 of the License. | ||
9 | * | ||
10 | */ | ||
11 | |||
12 | #include <linux/module.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/io.h> | ||
15 | #include <linux/platform_device.h> | ||
16 | #include <linux/slab.h> | ||
17 | #include <linux/dma-mapping.h> | ||
18 | |||
19 | #include <sound/core.h> | ||
20 | #include <sound/pcm.h> | ||
21 | #include <sound/pcm_params.h> | ||
22 | #include <sound/soc.h> | ||
23 | |||
24 | #include <mach/hardware.h> | ||
25 | |||
26 | #include "nuc900-audio.h" | ||
27 | |||
28 | static const struct snd_pcm_hardware nuc900_pcm_hardware = { | ||
29 | .info = SNDRV_PCM_INFO_INTERLEAVED | | ||
30 | SNDRV_PCM_INFO_BLOCK_TRANSFER | | ||
31 | SNDRV_PCM_INFO_MMAP | | ||
32 | SNDRV_PCM_INFO_MMAP_VALID | | ||
33 | SNDRV_PCM_INFO_PAUSE | | ||
34 | SNDRV_PCM_INFO_RESUME, | ||
35 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | ||
36 | .channels_min = 1, | ||
37 | .channels_max = 2, | ||
38 | .buffer_bytes_max = 4*1024, | ||
39 | .period_bytes_min = 1*1024, | ||
40 | .period_bytes_max = 4*1024, | ||
41 | .periods_min = 1, | ||
42 | .periods_max = 1024, | ||
43 | }; | ||
44 | |||
45 | static int nuc900_dma_hw_params(struct snd_pcm_substream *substream, | ||
46 | struct snd_pcm_hw_params *params) | ||
47 | { | ||
48 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
49 | struct nuc900_audio *nuc900_audio = runtime->private_data; | ||
50 | unsigned long flags; | ||
51 | int ret = 0; | ||
52 | |||
53 | spin_lock_irqsave(&nuc900_audio->lock, flags); | ||
54 | |||
55 | ret = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params)); | ||
56 | if (ret < 0) | ||
57 | return ret; | ||
58 | |||
59 | nuc900_audio->substream = substream; | ||
60 | nuc900_audio->dma_addr[substream->stream] = runtime->dma_addr; | ||
61 | nuc900_audio->buffersize[substream->stream] = | ||
62 | params_buffer_bytes(params); | ||
63 | |||
64 | spin_unlock_irqrestore(&nuc900_audio->lock, flags); | ||
65 | |||
66 | return ret; | ||
67 | } | ||
68 | |||
69 | static void nuc900_update_dma_register(struct snd_pcm_substream *substream, | ||
70 | dma_addr_t dma_addr, size_t count) | ||
71 | { | ||
72 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
73 | struct nuc900_audio *nuc900_audio = runtime->private_data; | ||
74 | void __iomem *mmio_addr, *mmio_len; | ||
75 | |||
76 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | ||
77 | mmio_addr = nuc900_audio->mmio + ACTL_PDSTB; | ||
78 | mmio_len = nuc900_audio->mmio + ACTL_PDST_LENGTH; | ||
79 | } else { | ||
80 | mmio_addr = nuc900_audio->mmio + ACTL_RDSTB; | ||
81 | mmio_len = nuc900_audio->mmio + ACTL_RDST_LENGTH; | ||
82 | } | ||
83 | |||
84 | AUDIO_WRITE(mmio_addr, dma_addr); | ||
85 | AUDIO_WRITE(mmio_len, count); | ||
86 | } | ||
87 | |||
88 | static void nuc900_dma_start(struct snd_pcm_substream *substream) | ||
89 | { | ||
90 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
91 | struct nuc900_audio *nuc900_audio = runtime->private_data; | ||
92 | unsigned long val; | ||
93 | |||
94 | val = AUDIO_READ(nuc900_audio->mmio + ACTL_CON); | ||
95 | val |= (T_DMA_IRQ | R_DMA_IRQ); | ||
96 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_CON, val); | ||
97 | } | ||
98 | |||
99 | static void nuc900_dma_stop(struct snd_pcm_substream *substream) | ||
100 | { | ||
101 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
102 | struct nuc900_audio *nuc900_audio = runtime->private_data; | ||
103 | unsigned long val; | ||
104 | |||
105 | val = AUDIO_READ(nuc900_audio->mmio + ACTL_CON); | ||
106 | val &= ~(T_DMA_IRQ | R_DMA_IRQ); | ||
107 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_CON, val); | ||
108 | } | ||
109 | |||
110 | static irqreturn_t nuc900_dma_interrupt(int irq, void *dev_id) | ||
111 | { | ||
112 | struct snd_pcm_substream *substream = dev_id; | ||
113 | struct nuc900_audio *nuc900_audio = substream->runtime->private_data; | ||
114 | unsigned long val; | ||
115 | |||
116 | spin_lock(&nuc900_audio->lock); | ||
117 | |||
118 | val = AUDIO_READ(nuc900_audio->mmio + ACTL_CON); | ||
119 | |||
120 | if (val & R_DMA_IRQ) { | ||
121 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_CON, val | R_DMA_IRQ); | ||
122 | |||
123 | val = AUDIO_READ(nuc900_audio->mmio + ACTL_RSR); | ||
124 | |||
125 | if (val & R_DMA_MIDDLE_IRQ) { | ||
126 | val |= R_DMA_MIDDLE_IRQ; | ||
127 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_RSR, val); | ||
128 | } | ||
129 | |||
130 | if (val & R_DMA_END_IRQ) { | ||
131 | val |= R_DMA_END_IRQ; | ||
132 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_RSR, val); | ||
133 | } | ||
134 | } else if (val & T_DMA_IRQ) { | ||
135 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_CON, val | T_DMA_IRQ); | ||
136 | |||
137 | val = AUDIO_READ(nuc900_audio->mmio + ACTL_PSR); | ||
138 | |||
139 | if (val & P_DMA_MIDDLE_IRQ) { | ||
140 | val |= P_DMA_MIDDLE_IRQ; | ||
141 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_PSR, val); | ||
142 | } | ||
143 | |||
144 | if (val & P_DMA_END_IRQ) { | ||
145 | val |= P_DMA_END_IRQ; | ||
146 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_PSR, val); | ||
147 | } | ||
148 | } else { | ||
149 | dev_err(nuc900_audio->dev, "Wrong DMA interrupt status!\n"); | ||
150 | spin_unlock(&nuc900_audio->lock); | ||
151 | return IRQ_HANDLED; | ||
152 | } | ||
153 | |||
154 | spin_unlock(&nuc900_audio->lock); | ||
155 | |||
156 | snd_pcm_period_elapsed(substream); | ||
157 | |||
158 | return IRQ_HANDLED; | ||
159 | } | ||
160 | |||
161 | static int nuc900_dma_hw_free(struct snd_pcm_substream *substream) | ||
162 | { | ||
163 | snd_pcm_lib_free_pages(substream); | ||
164 | return 0; | ||
165 | } | ||
166 | |||
167 | static int nuc900_dma_prepare(struct snd_pcm_substream *substream) | ||
168 | { | ||
169 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
170 | struct nuc900_audio *nuc900_audio = runtime->private_data; | ||
171 | unsigned long flags, val; | ||
172 | |||
173 | spin_lock_irqsave(&nuc900_audio->lock, flags); | ||
174 | |||
175 | nuc900_update_dma_register(substream, | ||
176 | nuc900_audio->dma_addr[substream->stream], | ||
177 | nuc900_audio->buffersize[substream->stream]); | ||
178 | |||
179 | val = AUDIO_READ(nuc900_audio->mmio + ACTL_RESET); | ||
180 | |||
181 | switch (runtime->channels) { | ||
182 | case 1: | ||
183 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | ||
184 | val &= ~(PLAY_LEFT_CHNNEL | PLAY_RIGHT_CHNNEL); | ||
185 | val |= PLAY_RIGHT_CHNNEL; | ||
186 | } else { | ||
187 | val &= ~(RECORD_LEFT_CHNNEL | RECORD_RIGHT_CHNNEL); | ||
188 | val |= RECORD_RIGHT_CHNNEL; | ||
189 | } | ||
190 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_RESET, val); | ||
191 | break; | ||
192 | case 2: | ||
193 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
194 | val |= (PLAY_LEFT_CHNNEL | PLAY_RIGHT_CHNNEL); | ||
195 | else | ||
196 | val |= (RECORD_LEFT_CHNNEL | RECORD_RIGHT_CHNNEL); | ||
197 | AUDIO_WRITE(nuc900_audio->mmio + ACTL_RESET, val); | ||
198 | break; | ||
199 | default: | ||
200 | return -EINVAL; | ||
201 | } | ||
202 | spin_unlock_irqrestore(&nuc900_audio->lock, flags); | ||
203 | return 0; | ||
204 | } | ||
205 | |||
206 | static int nuc900_dma_trigger(struct snd_pcm_substream *substream, int cmd) | ||
207 | { | ||
208 | int ret = 0; | ||
209 | |||
210 | switch (cmd) { | ||
211 | case SNDRV_PCM_TRIGGER_START: | ||
212 | case SNDRV_PCM_TRIGGER_RESUME: | ||
213 | nuc900_dma_start(substream); | ||
214 | break; | ||
215 | |||
216 | case SNDRV_PCM_TRIGGER_STOP: | ||
217 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
218 | nuc900_dma_stop(substream); | ||
219 | break; | ||
220 | |||
221 | default: | ||
222 | ret = -EINVAL; | ||
223 | break; | ||
224 | } | ||
225 | |||
226 | return ret; | ||
227 | } | ||
228 | |||
229 | int nuc900_dma_getposition(struct snd_pcm_substream *substream, | ||
230 | dma_addr_t *src, dma_addr_t *dst) | ||
231 | { | ||
232 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
233 | struct nuc900_audio *nuc900_audio = runtime->private_data; | ||
234 | |||
235 | if (src != NULL) | ||
236 | *src = AUDIO_READ(nuc900_audio->mmio + ACTL_PDSTC); | ||
237 | |||
238 | if (dst != NULL) | ||
239 | *dst = AUDIO_READ(nuc900_audio->mmio + ACTL_RDSTC); | ||
240 | |||
241 | return 0; | ||
242 | } | ||
243 | |||
244 | static snd_pcm_uframes_t nuc900_dma_pointer(struct snd_pcm_substream *substream) | ||
245 | { | ||
246 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
247 | dma_addr_t src, dst; | ||
248 | unsigned long res; | ||
249 | |||
250 | nuc900_dma_getposition(substream, &src, &dst); | ||
251 | |||
252 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) | ||
253 | res = dst - runtime->dma_addr; | ||
254 | else | ||
255 | res = src - runtime->dma_addr; | ||
256 | |||
257 | return bytes_to_frames(substream->runtime, res); | ||
258 | } | ||
259 | |||
260 | static int nuc900_dma_open(struct snd_pcm_substream *substream) | ||
261 | { | ||
262 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
263 | struct nuc900_audio *nuc900_audio; | ||
264 | |||
265 | snd_soc_set_runtime_hwparams(substream, &nuc900_pcm_hardware); | ||
266 | |||
267 | nuc900_audio = nuc900_ac97_data; | ||
268 | |||
269 | if (request_irq(nuc900_audio->irq_num, nuc900_dma_interrupt, | ||
270 | IRQF_DISABLED, "nuc900-dma", substream)) | ||
271 | return -EBUSY; | ||
272 | |||
273 | runtime->private_data = nuc900_audio; | ||
274 | |||
275 | return 0; | ||
276 | } | ||
277 | |||
278 | static int nuc900_dma_close(struct snd_pcm_substream *substream) | ||
279 | { | ||
280 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
281 | struct nuc900_audio *nuc900_audio = runtime->private_data; | ||
282 | |||
283 | free_irq(nuc900_audio->irq_num, substream); | ||
284 | |||
285 | return 0; | ||
286 | } | ||
287 | |||
288 | static int nuc900_dma_mmap(struct snd_pcm_substream *substream, | ||
289 | struct vm_area_struct *vma) | ||
290 | { | ||
291 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
292 | |||
293 | return dma_mmap_writecombine(substream->pcm->card->dev, vma, | ||
294 | runtime->dma_area, | ||
295 | runtime->dma_addr, | ||
296 | runtime->dma_bytes); | ||
297 | } | ||
298 | |||
299 | static struct snd_pcm_ops nuc900_dma_ops = { | ||
300 | .open = nuc900_dma_open, | ||
301 | .close = nuc900_dma_close, | ||
302 | .ioctl = snd_pcm_lib_ioctl, | ||
303 | .hw_params = nuc900_dma_hw_params, | ||
304 | .hw_free = nuc900_dma_hw_free, | ||
305 | .prepare = nuc900_dma_prepare, | ||
306 | .trigger = nuc900_dma_trigger, | ||
307 | .pointer = nuc900_dma_pointer, | ||
308 | .mmap = nuc900_dma_mmap, | ||
309 | }; | ||
310 | |||
311 | static void nuc900_dma_free_dma_buffers(struct snd_pcm *pcm) | ||
312 | { | ||
313 | snd_pcm_lib_preallocate_free_for_all(pcm); | ||
314 | } | ||
315 | |||
316 | static u64 nuc900_pcm_dmamask = DMA_BIT_MASK(32); | ||
317 | static int nuc900_dma_new(struct snd_card *card, | ||
318 | struct snd_soc_dai *dai, struct snd_pcm *pcm) | ||
319 | { | ||
320 | if (!card->dev->dma_mask) | ||
321 | card->dev->dma_mask = &nuc900_pcm_dmamask; | ||
322 | if (!card->dev->coherent_dma_mask) | ||
323 | card->dev->coherent_dma_mask = DMA_BIT_MASK(32); | ||
324 | |||
325 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, | ||
326 | card->dev, 4 * 1024, (4 * 1024) - 1); | ||
327 | |||
328 | return 0; | ||
329 | } | ||
330 | |||
331 | struct snd_soc_platform nuc900_soc_platform = { | ||
332 | .name = "nuc900-dma", | ||
333 | .pcm_ops = &nuc900_dma_ops, | ||
334 | .pcm_new = nuc900_dma_new, | ||
335 | .pcm_free = nuc900_dma_free_dma_buffers, | ||
336 | } | ||
337 | EXPORT_SYMBOL_GPL(nuc900_soc_platform); | ||
338 | |||
339 | static int __init nuc900_soc_platform_init(void) | ||
340 | { | ||
341 | return snd_soc_register_platform(&nuc900_soc_platform); | ||
342 | } | ||
343 | |||
344 | static void __exit nuc900_soc_platform_exit(void) | ||
345 | { | ||
346 | snd_soc_unregister_platform(&nuc900_soc_platform); | ||
347 | } | ||
348 | |||
349 | module_init(nuc900_soc_platform_init); | ||
350 | module_exit(nuc900_soc_platform_exit); | ||
351 | |||
352 | MODULE_AUTHOR("Wan ZongShun, <mcuos.com@gmail.com>"); | ||
353 | MODULE_DESCRIPTION("nuc900 Audio DMA module"); | ||
354 | MODULE_LICENSE("GPL"); | ||