diff options
Diffstat (limited to 'sound/soc/kirkwood')
-rw-r--r-- | sound/soc/kirkwood/Kconfig | 20 | ||||
-rw-r--r-- | sound/soc/kirkwood/Makefile | 9 | ||||
-rw-r--r-- | sound/soc/kirkwood/kirkwood-dma.c | 383 | ||||
-rw-r--r-- | sound/soc/kirkwood/kirkwood-dma.h | 17 | ||||
-rw-r--r-- | sound/soc/kirkwood/kirkwood-i2s.c | 495 | ||||
-rw-r--r-- | sound/soc/kirkwood/kirkwood-i2s.h | 17 | ||||
-rw-r--r-- | sound/soc/kirkwood/kirkwood-openrd.c | 126 | ||||
-rw-r--r-- | sound/soc/kirkwood/kirkwood.h | 129 |
8 files changed, 1196 insertions, 0 deletions
diff --git a/sound/soc/kirkwood/Kconfig b/sound/soc/kirkwood/Kconfig new file mode 100644 index 000000000000..16ec2a2dba4d --- /dev/null +++ b/sound/soc/kirkwood/Kconfig | |||
@@ -0,0 +1,20 @@ | |||
1 | config SND_KIRKWOOD_SOC | ||
2 | tristate "SoC Audio for the Marvell Kirkwood chip" | ||
3 | depends on ARCH_KIRKWOOD | ||
4 | help | ||
5 | Say Y or M if you want to add support for codecs attached to | ||
6 | the Kirkwood I2S interface. You will also need to select the | ||
7 | audio interfaces to support below. | ||
8 | |||
9 | config SND_KIRKWOOD_SOC_I2S | ||
10 | tristate | ||
11 | |||
12 | config SND_KIRKWOOD_SOC_OPENRD | ||
13 | tristate "SoC Audio support for Kirkwood Openrd Client" | ||
14 | depends on SND_KIRKWOOD_SOC && MACH_OPENRD_CLIENT | ||
15 | select SND_KIRKWOOD_SOC_I2S | ||
16 | select SND_SOC_CS42L51 | ||
17 | help | ||
18 | Say Y if you want to add support for SoC audio on | ||
19 | Openrd Client. | ||
20 | |||
diff --git a/sound/soc/kirkwood/Makefile b/sound/soc/kirkwood/Makefile new file mode 100644 index 000000000000..33a16dcab5b5 --- /dev/null +++ b/sound/soc/kirkwood/Makefile | |||
@@ -0,0 +1,9 @@ | |||
1 | snd-soc-kirkwood-objs := kirkwood-dma.o | ||
2 | snd-soc-kirkwood-i2s-objs := kirkwood-i2s.o | ||
3 | |||
4 | obj-$(CONFIG_SND_KIRKWOOD_SOC) += snd-soc-kirkwood.o | ||
5 | obj-$(CONFIG_SND_KIRKWOOD_SOC_I2S) += snd-soc-kirkwood-i2s.o | ||
6 | |||
7 | snd-soc-openrd-objs := kirkwood-openrd.o | ||
8 | |||
9 | obj-$(CONFIG_SND_KIRKWOOD_SOC_OPENRD) += snd-soc-openrd.o | ||
diff --git a/sound/soc/kirkwood/kirkwood-dma.c b/sound/soc/kirkwood/kirkwood-dma.c new file mode 100644 index 000000000000..a30205be3e2b --- /dev/null +++ b/sound/soc/kirkwood/kirkwood-dma.c | |||
@@ -0,0 +1,383 @@ | |||
1 | /* | ||
2 | * kirkwood-dma.c | ||
3 | * | ||
4 | * (c) 2010 Arnaud Patard <apatard@mandriva.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License as published by the | ||
8 | * Free Software Foundation; either version 2 of the License, or (at your | ||
9 | * option) any later version. | ||
10 | */ | ||
11 | |||
12 | #include <linux/init.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <linux/device.h> | ||
15 | #include <linux/io.h> | ||
16 | #include <linux/slab.h> | ||
17 | #include <linux/interrupt.h> | ||
18 | #include <linux/dma-mapping.h> | ||
19 | #include <linux/mbus.h> | ||
20 | #include <sound/soc.h> | ||
21 | #include "kirkwood-dma.h" | ||
22 | #include "kirkwood.h" | ||
23 | |||
24 | #define KIRKWOOD_RATES \ | ||
25 | (SNDRV_PCM_RATE_44100 | \ | ||
26 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000) | ||
27 | #define KIRKWOOD_FORMATS \ | ||
28 | (SNDRV_PCM_FMTBIT_S16_LE | \ | ||
29 | SNDRV_PCM_FMTBIT_S24_LE | \ | ||
30 | SNDRV_PCM_FMTBIT_S32_LE) | ||
31 | |||
32 | struct kirkwood_dma_priv { | ||
33 | struct snd_pcm_substream *play_stream; | ||
34 | struct snd_pcm_substream *rec_stream; | ||
35 | struct kirkwood_dma_data *data; | ||
36 | }; | ||
37 | |||
38 | static struct snd_pcm_hardware kirkwood_dma_snd_hw = { | ||
39 | .info = (SNDRV_PCM_INFO_INTERLEAVED | | ||
40 | SNDRV_PCM_INFO_MMAP | | ||
41 | SNDRV_PCM_INFO_MMAP_VALID | | ||
42 | SNDRV_PCM_INFO_BLOCK_TRANSFER | | ||
43 | SNDRV_PCM_INFO_PAUSE), | ||
44 | .formats = KIRKWOOD_FORMATS, | ||
45 | .rates = KIRKWOOD_RATES, | ||
46 | .rate_min = 44100, | ||
47 | .rate_max = 96000, | ||
48 | .channels_min = 1, | ||
49 | .channels_max = 2, | ||
50 | .buffer_bytes_max = KIRKWOOD_SND_MAX_PERIOD_BYTES * KIRKWOOD_SND_MAX_PERIODS, | ||
51 | .period_bytes_min = KIRKWOOD_SND_MIN_PERIOD_BYTES, | ||
52 | .period_bytes_max = KIRKWOOD_SND_MAX_PERIOD_BYTES, | ||
53 | .periods_min = KIRKWOOD_SND_MIN_PERIODS, | ||
54 | .periods_max = KIRKWOOD_SND_MAX_PERIODS, | ||
55 | .fifo_size = 0, | ||
56 | }; | ||
57 | |||
58 | static u64 kirkwood_dma_dmamask = 0xFFFFFFFFUL; | ||
59 | |||
60 | static irqreturn_t kirkwood_dma_irq(int irq, void *dev_id) | ||
61 | { | ||
62 | struct kirkwood_dma_priv *prdata = dev_id; | ||
63 | struct kirkwood_dma_data *priv = prdata->data; | ||
64 | unsigned long mask, status, cause; | ||
65 | |||
66 | mask = readl(priv->io + KIRKWOOD_INT_MASK); | ||
67 | status = readl(priv->io + KIRKWOOD_INT_CAUSE) & mask; | ||
68 | |||
69 | cause = readl(priv->io + KIRKWOOD_ERR_CAUSE); | ||
70 | if (unlikely(cause)) { | ||
71 | printk(KERN_WARNING "%s: got err interrupt 0x%lx\n", | ||
72 | __func__, cause); | ||
73 | writel(cause, priv->io + KIRKWOOD_ERR_CAUSE); | ||
74 | return IRQ_HANDLED; | ||
75 | } | ||
76 | |||
77 | /* we've enabled only bytes interrupts ... */ | ||
78 | if (status & ~(KIRKWOOD_INT_CAUSE_PLAY_BYTES | \ | ||
79 | KIRKWOOD_INT_CAUSE_REC_BYTES)) { | ||
80 | printk(KERN_WARNING "%s: unexpected interrupt %lx\n", | ||
81 | __func__, status); | ||
82 | return IRQ_NONE; | ||
83 | } | ||
84 | |||
85 | /* ack int */ | ||
86 | writel(status, priv->io + KIRKWOOD_INT_CAUSE); | ||
87 | |||
88 | if (status & KIRKWOOD_INT_CAUSE_PLAY_BYTES) | ||
89 | snd_pcm_period_elapsed(prdata->play_stream); | ||
90 | |||
91 | if (status & KIRKWOOD_INT_CAUSE_REC_BYTES) | ||
92 | snd_pcm_period_elapsed(prdata->rec_stream); | ||
93 | |||
94 | return IRQ_HANDLED; | ||
95 | } | ||
96 | |||
97 | static void kirkwood_dma_conf_mbus_windows(void __iomem *base, int win, | ||
98 | unsigned long dma, | ||
99 | struct mbus_dram_target_info *dram) | ||
100 | { | ||
101 | int i; | ||
102 | |||
103 | /* First disable and clear windows */ | ||
104 | writel(0, base + KIRKWOOD_AUDIO_WIN_CTRL_REG(win)); | ||
105 | writel(0, base + KIRKWOOD_AUDIO_WIN_BASE_REG(win)); | ||
106 | |||
107 | /* try to find matching cs for current dma address */ | ||
108 | for (i = 0; i < dram->num_cs; i++) { | ||
109 | struct mbus_dram_window *cs = dram->cs + i; | ||
110 | if ((cs->base & 0xffff0000) < (dma & 0xffff0000)) { | ||
111 | writel(cs->base & 0xffff0000, | ||
112 | base + KIRKWOOD_AUDIO_WIN_BASE_REG(win)); | ||
113 | writel(((cs->size - 1) & 0xffff0000) | | ||
114 | (cs->mbus_attr << 8) | | ||
115 | (dram->mbus_dram_target_id << 4) | 1, | ||
116 | base + KIRKWOOD_AUDIO_WIN_CTRL_REG(win)); | ||
117 | } | ||
118 | } | ||
119 | } | ||
120 | |||
121 | static int kirkwood_dma_open(struct snd_pcm_substream *substream) | ||
122 | { | ||
123 | int err; | ||
124 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
125 | struct snd_soc_pcm_runtime *soc_runtime = substream->private_data; | ||
126 | struct snd_soc_dai *cpu_dai = soc_runtime->dai->cpu_dai; | ||
127 | struct kirkwood_dma_data *priv; | ||
128 | struct kirkwood_dma_priv *prdata = cpu_dai->private_data; | ||
129 | unsigned long addr; | ||
130 | |||
131 | priv = snd_soc_dai_get_dma_data(cpu_dai, substream); | ||
132 | snd_soc_set_runtime_hwparams(substream, &kirkwood_dma_snd_hw); | ||
133 | |||
134 | /* Ensure that all constraints linked to dma burst are fullfilled */ | ||
135 | err = snd_pcm_hw_constraint_minmax(runtime, | ||
136 | SNDRV_PCM_HW_PARAM_BUFFER_BYTES, | ||
137 | priv->burst * 2, | ||
138 | KIRKWOOD_AUDIO_BUF_MAX-1); | ||
139 | if (err < 0) | ||
140 | return err; | ||
141 | |||
142 | err = snd_pcm_hw_constraint_step(runtime, 0, | ||
143 | SNDRV_PCM_HW_PARAM_BUFFER_BYTES, | ||
144 | priv->burst); | ||
145 | if (err < 0) | ||
146 | return err; | ||
147 | |||
148 | err = snd_pcm_hw_constraint_step(substream->runtime, 0, | ||
149 | SNDRV_PCM_HW_PARAM_PERIOD_BYTES, | ||
150 | priv->burst); | ||
151 | if (err < 0) | ||
152 | return err; | ||
153 | |||
154 | if (soc_runtime->dai->cpu_dai->private_data == NULL) { | ||
155 | prdata = kzalloc(sizeof(struct kirkwood_dma_priv), GFP_KERNEL); | ||
156 | if (prdata == NULL) | ||
157 | return -ENOMEM; | ||
158 | |||
159 | prdata->data = priv; | ||
160 | |||
161 | err = request_irq(priv->irq, kirkwood_dma_irq, IRQF_SHARED, | ||
162 | "kirkwood-i2s", prdata); | ||
163 | if (err) { | ||
164 | kfree(prdata); | ||
165 | return -EBUSY; | ||
166 | } | ||
167 | |||
168 | soc_runtime->dai->cpu_dai->private_data = prdata; | ||
169 | |||
170 | /* | ||
171 | * Enable Error interrupts. We're only ack'ing them but | ||
172 | * it's usefull for diagnostics | ||
173 | */ | ||
174 | writel((unsigned long)-1, priv->io + KIRKWOOD_ERR_MASK); | ||
175 | } | ||
176 | |||
177 | addr = virt_to_phys(substream->dma_buffer.area); | ||
178 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | ||
179 | prdata->play_stream = substream; | ||
180 | kirkwood_dma_conf_mbus_windows(priv->io, | ||
181 | KIRKWOOD_PLAYBACK_WIN, addr, priv->dram); | ||
182 | } else { | ||
183 | prdata->rec_stream = substream; | ||
184 | kirkwood_dma_conf_mbus_windows(priv->io, | ||
185 | KIRKWOOD_RECORD_WIN, addr, priv->dram); | ||
186 | } | ||
187 | |||
188 | return 0; | ||
189 | } | ||
190 | |||
191 | static int kirkwood_dma_close(struct snd_pcm_substream *substream) | ||
192 | { | ||
193 | struct snd_soc_pcm_runtime *soc_runtime = substream->private_data; | ||
194 | struct snd_soc_dai *cpu_dai = soc_runtime->dai->cpu_dai; | ||
195 | struct kirkwood_dma_priv *prdata = cpu_dai->private_data; | ||
196 | struct kirkwood_dma_data *priv; | ||
197 | |||
198 | priv = snd_soc_dai_get_dma_data(cpu_dai, substream); | ||
199 | |||
200 | if (!prdata || !priv) | ||
201 | return 0; | ||
202 | |||
203 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
204 | prdata->play_stream = NULL; | ||
205 | else | ||
206 | prdata->rec_stream = NULL; | ||
207 | |||
208 | if (!prdata->play_stream && !prdata->rec_stream) { | ||
209 | writel(0, priv->io + KIRKWOOD_ERR_MASK); | ||
210 | free_irq(priv->irq, prdata); | ||
211 | kfree(prdata); | ||
212 | soc_runtime->dai->cpu_dai->private_data = NULL; | ||
213 | } | ||
214 | |||
215 | return 0; | ||
216 | } | ||
217 | |||
218 | static int kirkwood_dma_hw_params(struct snd_pcm_substream *substream, | ||
219 | struct snd_pcm_hw_params *params) | ||
220 | { | ||
221 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
222 | |||
223 | snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer); | ||
224 | runtime->dma_bytes = params_buffer_bytes(params); | ||
225 | |||
226 | return 0; | ||
227 | } | ||
228 | |||
229 | static int kirkwood_dma_hw_free(struct snd_pcm_substream *substream) | ||
230 | { | ||
231 | snd_pcm_set_runtime_buffer(substream, NULL); | ||
232 | return 0; | ||
233 | } | ||
234 | |||
235 | static int kirkwood_dma_prepare(struct snd_pcm_substream *substream) | ||
236 | { | ||
237 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
238 | struct snd_soc_pcm_runtime *soc_runtime = substream->private_data; | ||
239 | struct snd_soc_dai *cpu_dai = soc_runtime->dai->cpu_dai; | ||
240 | struct kirkwood_dma_data *priv; | ||
241 | unsigned long size, count; | ||
242 | |||
243 | priv = snd_soc_dai_get_dma_data(cpu_dai, substream); | ||
244 | |||
245 | /* compute buffer size in term of "words" as requested in specs */ | ||
246 | size = frames_to_bytes(runtime, runtime->buffer_size); | ||
247 | size = (size>>2)-1; | ||
248 | count = snd_pcm_lib_period_bytes(substream); | ||
249 | |||
250 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | ||
251 | writel(count, priv->io + KIRKWOOD_PLAY_BYTE_INT_COUNT); | ||
252 | writel(runtime->dma_addr, priv->io + KIRKWOOD_PLAY_BUF_ADDR); | ||
253 | writel(size, priv->io + KIRKWOOD_PLAY_BUF_SIZE); | ||
254 | } else { | ||
255 | writel(count, priv->io + KIRKWOOD_REC_BYTE_INT_COUNT); | ||
256 | writel(runtime->dma_addr, priv->io + KIRKWOOD_REC_BUF_ADDR); | ||
257 | writel(size, priv->io + KIRKWOOD_REC_BUF_SIZE); | ||
258 | } | ||
259 | |||
260 | |||
261 | return 0; | ||
262 | } | ||
263 | |||
264 | static snd_pcm_uframes_t kirkwood_dma_pointer(struct snd_pcm_substream | ||
265 | *substream) | ||
266 | { | ||
267 | struct snd_soc_pcm_runtime *soc_runtime = substream->private_data; | ||
268 | struct snd_soc_dai *cpu_dai = soc_runtime->dai->cpu_dai; | ||
269 | struct kirkwood_dma_data *priv; | ||
270 | snd_pcm_uframes_t count; | ||
271 | |||
272 | priv = snd_soc_dai_get_dma_data(cpu_dai, substream); | ||
273 | |||
274 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
275 | count = bytes_to_frames(substream->runtime, | ||
276 | readl(priv->io + KIRKWOOD_PLAY_BYTE_COUNT)); | ||
277 | else | ||
278 | count = bytes_to_frames(substream->runtime, | ||
279 | readl(priv->io + KIRKWOOD_REC_BYTE_COUNT)); | ||
280 | |||
281 | return count; | ||
282 | } | ||
283 | |||
284 | struct snd_pcm_ops kirkwood_dma_ops = { | ||
285 | .open = kirkwood_dma_open, | ||
286 | .close = kirkwood_dma_close, | ||
287 | .ioctl = snd_pcm_lib_ioctl, | ||
288 | .hw_params = kirkwood_dma_hw_params, | ||
289 | .hw_free = kirkwood_dma_hw_free, | ||
290 | .prepare = kirkwood_dma_prepare, | ||
291 | .pointer = kirkwood_dma_pointer, | ||
292 | }; | ||
293 | |||
294 | static int kirkwood_dma_preallocate_dma_buffer(struct snd_pcm *pcm, | ||
295 | int stream) | ||
296 | { | ||
297 | struct snd_pcm_substream *substream = pcm->streams[stream].substream; | ||
298 | struct snd_dma_buffer *buf = &substream->dma_buffer; | ||
299 | size_t size = kirkwood_dma_snd_hw.buffer_bytes_max; | ||
300 | |||
301 | buf->dev.type = SNDRV_DMA_TYPE_DEV; | ||
302 | buf->dev.dev = pcm->card->dev; | ||
303 | buf->area = dma_alloc_coherent(pcm->card->dev, size, | ||
304 | &buf->addr, GFP_KERNEL); | ||
305 | if (!buf->area) | ||
306 | return -ENOMEM; | ||
307 | buf->bytes = size; | ||
308 | buf->private_data = NULL; | ||
309 | |||
310 | return 0; | ||
311 | } | ||
312 | |||
313 | static int kirkwood_dma_new(struct snd_card *card, | ||
314 | struct snd_soc_dai *dai, struct snd_pcm *pcm) | ||
315 | { | ||
316 | int ret; | ||
317 | |||
318 | if (!card->dev->dma_mask) | ||
319 | card->dev->dma_mask = &kirkwood_dma_dmamask; | ||
320 | if (!card->dev->coherent_dma_mask) | ||
321 | card->dev->coherent_dma_mask = 0xffffffff; | ||
322 | |||
323 | if (dai->playback.channels_min) { | ||
324 | ret = kirkwood_dma_preallocate_dma_buffer(pcm, | ||
325 | SNDRV_PCM_STREAM_PLAYBACK); | ||
326 | if (ret) | ||
327 | return ret; | ||
328 | } | ||
329 | |||
330 | if (dai->capture.channels_min) { | ||
331 | ret = kirkwood_dma_preallocate_dma_buffer(pcm, | ||
332 | SNDRV_PCM_STREAM_CAPTURE); | ||
333 | if (ret) | ||
334 | return ret; | ||
335 | } | ||
336 | |||
337 | return 0; | ||
338 | } | ||
339 | |||
340 | static void kirkwood_dma_free_dma_buffers(struct snd_pcm *pcm) | ||
341 | { | ||
342 | struct snd_pcm_substream *substream; | ||
343 | struct snd_dma_buffer *buf; | ||
344 | int stream; | ||
345 | |||
346 | for (stream = 0; stream < 2; stream++) { | ||
347 | substream = pcm->streams[stream].substream; | ||
348 | if (!substream) | ||
349 | continue; | ||
350 | buf = &substream->dma_buffer; | ||
351 | if (!buf->area) | ||
352 | continue; | ||
353 | |||
354 | dma_free_coherent(pcm->card->dev, buf->bytes, | ||
355 | buf->area, buf->addr); | ||
356 | buf->area = NULL; | ||
357 | } | ||
358 | } | ||
359 | |||
360 | struct snd_soc_platform kirkwood_soc_platform = { | ||
361 | .name = "kirkwood-dma", | ||
362 | .pcm_ops = &kirkwood_dma_ops, | ||
363 | .pcm_new = kirkwood_dma_new, | ||
364 | .pcm_free = kirkwood_dma_free_dma_buffers, | ||
365 | }; | ||
366 | EXPORT_SYMBOL_GPL(kirkwood_soc_platform); | ||
367 | |||
368 | static int __init kirkwood_soc_platform_init(void) | ||
369 | { | ||
370 | return snd_soc_register_platform(&kirkwood_soc_platform); | ||
371 | } | ||
372 | module_init(kirkwood_soc_platform_init); | ||
373 | |||
374 | static void __exit kirkwood_soc_platform_exit(void) | ||
375 | { | ||
376 | snd_soc_unregister_platform(&kirkwood_soc_platform); | ||
377 | } | ||
378 | module_exit(kirkwood_soc_platform_exit); | ||
379 | |||
380 | MODULE_AUTHOR("Arnaud Patard <apatard@mandriva.com>"); | ||
381 | MODULE_DESCRIPTION("Marvell Kirkwood Audio DMA module"); | ||
382 | MODULE_LICENSE("GPL"); | ||
383 | |||
diff --git a/sound/soc/kirkwood/kirkwood-dma.h b/sound/soc/kirkwood/kirkwood-dma.h new file mode 100644 index 000000000000..ba4454cd34f1 --- /dev/null +++ b/sound/soc/kirkwood/kirkwood-dma.h | |||
@@ -0,0 +1,17 @@ | |||
1 | /* | ||
2 | * kirkwood-dma.h | ||
3 | * | ||
4 | * (c) 2010 Arnaud Patard <apatard@mandriva.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License as published by the | ||
8 | * Free Software Foundation; either version 2 of the License, or (at your | ||
9 | * option) any later version. | ||
10 | */ | ||
11 | |||
12 | #ifndef _KIRKWOOD_DMA_H | ||
13 | #define _KIRKWOOD_DMA_H | ||
14 | |||
15 | extern struct snd_soc_platform kirkwood_soc_platform; | ||
16 | |||
17 | #endif | ||
diff --git a/sound/soc/kirkwood/kirkwood-i2s.c b/sound/soc/kirkwood/kirkwood-i2s.c new file mode 100644 index 000000000000..981ffc2a13c8 --- /dev/null +++ b/sound/soc/kirkwood/kirkwood-i2s.c | |||
@@ -0,0 +1,495 @@ | |||
1 | /* | ||
2 | * kirkwood-i2s.c | ||
3 | * | ||
4 | * (c) 2010 Arnaud Patard <apatard@mandriva.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License as published by the | ||
8 | * Free Software Foundation; either version 2 of the License, or (at your | ||
9 | * option) any later version. | ||
10 | */ | ||
11 | |||
12 | #include <linux/init.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <linux/platform_device.h> | ||
15 | #include <linux/io.h> | ||
16 | #include <linux/slab.h> | ||
17 | #include <linux/mbus.h> | ||
18 | #include <linux/delay.h> | ||
19 | #include <sound/pcm.h> | ||
20 | #include <sound/pcm_params.h> | ||
21 | #include <sound/soc.h> | ||
22 | #include <plat/audio.h> | ||
23 | #include "kirkwood-i2s.h" | ||
24 | #include "kirkwood.h" | ||
25 | |||
26 | #define DRV_NAME "kirkwood-i2s" | ||
27 | |||
28 | #define KIRKWOOD_I2S_RATES \ | ||
29 | (SNDRV_PCM_RATE_44100 | \ | ||
30 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000) | ||
31 | #define KIRKWOOD_I2S_FORMATS \ | ||
32 | (SNDRV_PCM_FMTBIT_S16_LE | \ | ||
33 | SNDRV_PCM_FMTBIT_S24_LE | \ | ||
34 | SNDRV_PCM_FMTBIT_S32_LE) | ||
35 | |||
36 | |||
37 | struct snd_soc_dai kirkwood_i2s_dai; | ||
38 | static struct kirkwood_dma_data *priv; | ||
39 | |||
40 | static int kirkwood_i2s_set_fmt(struct snd_soc_dai *cpu_dai, | ||
41 | unsigned int fmt) | ||
42 | { | ||
43 | unsigned long mask; | ||
44 | unsigned long value; | ||
45 | |||
46 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
47 | case SND_SOC_DAIFMT_RIGHT_J: | ||
48 | mask = KIRKWOOD_I2S_CTL_RJ; | ||
49 | break; | ||
50 | case SND_SOC_DAIFMT_LEFT_J: | ||
51 | mask = KIRKWOOD_I2S_CTL_LJ; | ||
52 | break; | ||
53 | case SND_SOC_DAIFMT_I2S: | ||
54 | mask = KIRKWOOD_I2S_CTL_I2S; | ||
55 | break; | ||
56 | default: | ||
57 | return -EINVAL; | ||
58 | } | ||
59 | |||
60 | /* | ||
61 | * Set same format for playback and record | ||
62 | * This avoids some troubles. | ||
63 | */ | ||
64 | value = readl(priv->io+KIRKWOOD_I2S_PLAYCTL); | ||
65 | value &= ~KIRKWOOD_I2S_CTL_JUST_MASK; | ||
66 | value |= mask; | ||
67 | writel(value, priv->io+KIRKWOOD_I2S_PLAYCTL); | ||
68 | |||
69 | value = readl(priv->io+KIRKWOOD_I2S_RECCTL); | ||
70 | value &= ~KIRKWOOD_I2S_CTL_JUST_MASK; | ||
71 | value |= mask; | ||
72 | writel(value, priv->io+KIRKWOOD_I2S_RECCTL); | ||
73 | |||
74 | return 0; | ||
75 | } | ||
76 | |||
77 | static inline void kirkwood_set_dco(void __iomem *io, unsigned long rate) | ||
78 | { | ||
79 | unsigned long value; | ||
80 | |||
81 | value = KIRKWOOD_DCO_CTL_OFFSET_0; | ||
82 | switch (rate) { | ||
83 | default: | ||
84 | case 44100: | ||
85 | value |= KIRKWOOD_DCO_CTL_FREQ_11; | ||
86 | break; | ||
87 | case 48000: | ||
88 | value |= KIRKWOOD_DCO_CTL_FREQ_12; | ||
89 | break; | ||
90 | case 96000: | ||
91 | value |= KIRKWOOD_DCO_CTL_FREQ_24; | ||
92 | break; | ||
93 | } | ||
94 | writel(value, io + KIRKWOOD_DCO_CTL); | ||
95 | |||
96 | /* wait for dco locked */ | ||
97 | do { | ||
98 | cpu_relax(); | ||
99 | value = readl(io + KIRKWOOD_DCO_SPCR_STATUS); | ||
100 | value &= KIRKWOOD_DCO_SPCR_STATUS; | ||
101 | } while (value == 0); | ||
102 | } | ||
103 | |||
104 | static int kirkwood_i2s_hw_params(struct snd_pcm_substream *substream, | ||
105 | struct snd_pcm_hw_params *params, | ||
106 | struct snd_soc_dai *dai) | ||
107 | { | ||
108 | unsigned int i2s_reg, reg; | ||
109 | unsigned long i2s_value, value; | ||
110 | |||
111 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | ||
112 | i2s_reg = KIRKWOOD_I2S_PLAYCTL; | ||
113 | reg = KIRKWOOD_PLAYCTL; | ||
114 | } else { | ||
115 | i2s_reg = KIRKWOOD_I2S_RECCTL; | ||
116 | reg = KIRKWOOD_RECCTL; | ||
117 | } | ||
118 | |||
119 | /* set dco conf */ | ||
120 | kirkwood_set_dco(priv->io, params_rate(params)); | ||
121 | |||
122 | i2s_value = readl(priv->io+i2s_reg); | ||
123 | i2s_value &= ~KIRKWOOD_I2S_CTL_SIZE_MASK; | ||
124 | |||
125 | value = readl(priv->io+reg); | ||
126 | value &= ~KIRKWOOD_PLAYCTL_SIZE_MASK; | ||
127 | |||
128 | /* | ||
129 | * Size settings in play/rec i2s control regs and play/rec control | ||
130 | * regs must be the same. | ||
131 | */ | ||
132 | switch (params_format(params)) { | ||
133 | case SNDRV_PCM_FORMAT_S16_LE: | ||
134 | i2s_value |= KIRKWOOD_I2S_CTL_SIZE_16; | ||
135 | value |= KIRKWOOD_PLAYCTL_SIZE_16_C; | ||
136 | break; | ||
137 | /* | ||
138 | * doesn't work... S20_3LE != kirkwood 20bit format ? | ||
139 | * | ||
140 | case SNDRV_PCM_FORMAT_S20_3LE: | ||
141 | i2s_value |= KIRKWOOD_I2S_CTL_SIZE_20; | ||
142 | value |= KIRKWOOD_PLAYCTL_SIZE_20; | ||
143 | break; | ||
144 | */ | ||
145 | case SNDRV_PCM_FORMAT_S24_LE: | ||
146 | i2s_value |= KIRKWOOD_I2S_CTL_SIZE_24; | ||
147 | value |= KIRKWOOD_PLAYCTL_SIZE_24; | ||
148 | break; | ||
149 | case SNDRV_PCM_FORMAT_S32_LE: | ||
150 | i2s_value |= KIRKWOOD_I2S_CTL_SIZE_32; | ||
151 | value |= KIRKWOOD_PLAYCTL_SIZE_32; | ||
152 | break; | ||
153 | default: | ||
154 | return -EINVAL; | ||
155 | } | ||
156 | |||
157 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | ||
158 | value &= ~KIRKWOOD_PLAYCTL_MONO_MASK; | ||
159 | if (params_channels(params) == 1) | ||
160 | value |= KIRKWOOD_PLAYCTL_MONO_BOTH; | ||
161 | else | ||
162 | value |= KIRKWOOD_PLAYCTL_MONO_OFF; | ||
163 | } | ||
164 | |||
165 | writel(i2s_value, priv->io+i2s_reg); | ||
166 | writel(value, priv->io+reg); | ||
167 | |||
168 | return 0; | ||
169 | } | ||
170 | |||
171 | static int kirkwood_i2s_play_trigger(struct snd_pcm_substream *substream, | ||
172 | int cmd, struct snd_soc_dai *dai) | ||
173 | { | ||
174 | unsigned long value; | ||
175 | |||
176 | /* | ||
177 | * specs says KIRKWOOD_PLAYCTL must be read 2 times before | ||
178 | * changing it. So read 1 time here and 1 later. | ||
179 | */ | ||
180 | value = readl(priv->io + KIRKWOOD_PLAYCTL); | ||
181 | |||
182 | switch (cmd) { | ||
183 | case SNDRV_PCM_TRIGGER_START: | ||
184 | /* stop audio, enable interrupts */ | ||
185 | value = readl(priv->io + KIRKWOOD_PLAYCTL); | ||
186 | value |= KIRKWOOD_PLAYCTL_PAUSE; | ||
187 | writel(value, priv->io + KIRKWOOD_PLAYCTL); | ||
188 | |||
189 | value = readl(priv->io + KIRKWOOD_INT_MASK); | ||
190 | value |= KIRKWOOD_INT_CAUSE_PLAY_BYTES; | ||
191 | writel(value, priv->io + KIRKWOOD_INT_MASK); | ||
192 | |||
193 | /* configure audio & enable i2s playback */ | ||
194 | value = readl(priv->io + KIRKWOOD_PLAYCTL); | ||
195 | value &= ~KIRKWOOD_PLAYCTL_BURST_MASK; | ||
196 | value &= ~(KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE | ||
197 | | KIRKWOOD_PLAYCTL_SPDIF_EN); | ||
198 | |||
199 | if (priv->burst == 32) | ||
200 | value |= KIRKWOOD_PLAYCTL_BURST_32; | ||
201 | else | ||
202 | value |= KIRKWOOD_PLAYCTL_BURST_128; | ||
203 | value |= KIRKWOOD_PLAYCTL_I2S_EN; | ||
204 | writel(value, priv->io + KIRKWOOD_PLAYCTL); | ||
205 | break; | ||
206 | |||
207 | case SNDRV_PCM_TRIGGER_STOP: | ||
208 | /* stop audio, disable interrupts */ | ||
209 | value = readl(priv->io + KIRKWOOD_PLAYCTL); | ||
210 | value |= KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE; | ||
211 | writel(value, priv->io + KIRKWOOD_PLAYCTL); | ||
212 | |||
213 | value = readl(priv->io + KIRKWOOD_INT_MASK); | ||
214 | value &= ~KIRKWOOD_INT_CAUSE_PLAY_BYTES; | ||
215 | writel(value, priv->io + KIRKWOOD_INT_MASK); | ||
216 | |||
217 | /* disable all playbacks */ | ||
218 | value = readl(priv->io + KIRKWOOD_PLAYCTL); | ||
219 | value &= ~(KIRKWOOD_PLAYCTL_I2S_EN | KIRKWOOD_PLAYCTL_SPDIF_EN); | ||
220 | writel(value, priv->io + KIRKWOOD_PLAYCTL); | ||
221 | break; | ||
222 | |||
223 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
224 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
225 | value = readl(priv->io + KIRKWOOD_PLAYCTL); | ||
226 | value |= KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE; | ||
227 | writel(value, priv->io + KIRKWOOD_PLAYCTL); | ||
228 | break; | ||
229 | |||
230 | case SNDRV_PCM_TRIGGER_RESUME: | ||
231 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
232 | value = readl(priv->io + KIRKWOOD_PLAYCTL); | ||
233 | value &= ~(KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE); | ||
234 | writel(value, priv->io + KIRKWOOD_PLAYCTL); | ||
235 | break; | ||
236 | |||
237 | default: | ||
238 | return -EINVAL; | ||
239 | } | ||
240 | |||
241 | return 0; | ||
242 | } | ||
243 | |||
244 | static int kirkwood_i2s_rec_trigger(struct snd_pcm_substream *substream, | ||
245 | int cmd, struct snd_soc_dai *dai) | ||
246 | { | ||
247 | unsigned long value; | ||
248 | |||
249 | value = readl(priv->io + KIRKWOOD_RECCTL); | ||
250 | |||
251 | switch (cmd) { | ||
252 | case SNDRV_PCM_TRIGGER_START: | ||
253 | /* stop audio, enable interrupts */ | ||
254 | value = readl(priv->io + KIRKWOOD_RECCTL); | ||
255 | value |= KIRKWOOD_RECCTL_PAUSE; | ||
256 | writel(value, priv->io + KIRKWOOD_RECCTL); | ||
257 | |||
258 | value = readl(priv->io + KIRKWOOD_INT_MASK); | ||
259 | value |= KIRKWOOD_INT_CAUSE_REC_BYTES; | ||
260 | writel(value, priv->io + KIRKWOOD_INT_MASK); | ||
261 | |||
262 | /* configure audio & enable i2s record */ | ||
263 | value = readl(priv->io + KIRKWOOD_RECCTL); | ||
264 | value &= ~KIRKWOOD_RECCTL_BURST_MASK; | ||
265 | value &= ~KIRKWOOD_RECCTL_MONO; | ||
266 | value &= ~(KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_MUTE | ||
267 | | KIRKWOOD_RECCTL_SPDIF_EN); | ||
268 | |||
269 | if (priv->burst == 32) | ||
270 | value |= KIRKWOOD_RECCTL_BURST_32; | ||
271 | else | ||
272 | value |= KIRKWOOD_RECCTL_BURST_128; | ||
273 | value |= KIRKWOOD_RECCTL_I2S_EN; | ||
274 | |||
275 | writel(value, priv->io + KIRKWOOD_RECCTL); | ||
276 | break; | ||
277 | |||
278 | case SNDRV_PCM_TRIGGER_STOP: | ||
279 | /* stop audio, disable interrupts */ | ||
280 | value = readl(priv->io + KIRKWOOD_RECCTL); | ||
281 | value |= KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_MUTE; | ||
282 | writel(value, priv->io + KIRKWOOD_RECCTL); | ||
283 | |||
284 | value = readl(priv->io + KIRKWOOD_INT_MASK); | ||
285 | value &= ~KIRKWOOD_INT_CAUSE_REC_BYTES; | ||
286 | writel(value, priv->io + KIRKWOOD_INT_MASK); | ||
287 | |||
288 | /* disable all records */ | ||
289 | value = readl(priv->io + KIRKWOOD_RECCTL); | ||
290 | value &= ~(KIRKWOOD_RECCTL_I2S_EN | KIRKWOOD_RECCTL_SPDIF_EN); | ||
291 | writel(value, priv->io + KIRKWOOD_RECCTL); | ||
292 | break; | ||
293 | |||
294 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
295 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
296 | value = readl(priv->io + KIRKWOOD_RECCTL); | ||
297 | value |= KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_MUTE; | ||
298 | writel(value, priv->io + KIRKWOOD_RECCTL); | ||
299 | break; | ||
300 | |||
301 | case SNDRV_PCM_TRIGGER_RESUME: | ||
302 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
303 | value = readl(priv->io + KIRKWOOD_RECCTL); | ||
304 | value &= ~(KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_MUTE); | ||
305 | writel(value, priv->io + KIRKWOOD_RECCTL); | ||
306 | break; | ||
307 | |||
308 | default: | ||
309 | return -EINVAL; | ||
310 | } | ||
311 | |||
312 | return 0; | ||
313 | } | ||
314 | |||
315 | static int kirkwood_i2s_trigger(struct snd_pcm_substream *substream, int cmd, | ||
316 | struct snd_soc_dai *dai) | ||
317 | { | ||
318 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
319 | return kirkwood_i2s_play_trigger(substream, cmd, dai); | ||
320 | else | ||
321 | return kirkwood_i2s_rec_trigger(substream, cmd, dai); | ||
322 | |||
323 | return 0; | ||
324 | } | ||
325 | |||
326 | static int kirkwood_i2s_probe(struct platform_device *pdev, | ||
327 | struct snd_soc_dai *dai) | ||
328 | { | ||
329 | unsigned long value; | ||
330 | unsigned int reg_data; | ||
331 | |||
332 | /* put system in a "safe" state : */ | ||
333 | /* disable audio interrupts */ | ||
334 | writel(0xffffffff, priv->io + KIRKWOOD_INT_CAUSE); | ||
335 | writel(0, priv->io + KIRKWOOD_INT_MASK); | ||
336 | |||
337 | reg_data = readl(priv->io + 0x1200); | ||
338 | reg_data &= (~(0x333FF8)); | ||
339 | reg_data |= 0x111D18; | ||
340 | writel(reg_data, priv->io + 0x1200); | ||
341 | |||
342 | msleep(500); | ||
343 | |||
344 | reg_data = readl(priv->io + 0x1200); | ||
345 | reg_data &= (~(0x333FF8)); | ||
346 | reg_data |= 0x111D18; | ||
347 | writel(reg_data, priv->io + 0x1200); | ||
348 | |||
349 | /* disable playback/record */ | ||
350 | value = readl(priv->io + KIRKWOOD_PLAYCTL); | ||
351 | value &= ~(KIRKWOOD_PLAYCTL_I2S_EN|KIRKWOOD_PLAYCTL_SPDIF_EN); | ||
352 | writel(value, priv->io + KIRKWOOD_PLAYCTL); | ||
353 | |||
354 | value = readl(priv->io + KIRKWOOD_RECCTL); | ||
355 | value &= ~(KIRKWOOD_RECCTL_I2S_EN | KIRKWOOD_RECCTL_SPDIF_EN); | ||
356 | writel(value, priv->io + KIRKWOOD_RECCTL); | ||
357 | |||
358 | return 0; | ||
359 | |||
360 | } | ||
361 | |||
362 | static void kirkwood_i2s_remove(struct platform_device *pdev, | ||
363 | struct snd_soc_dai *dai) | ||
364 | { | ||
365 | } | ||
366 | |||
367 | static struct snd_soc_dai_ops kirkwood_i2s_dai_ops = { | ||
368 | .trigger = kirkwood_i2s_trigger, | ||
369 | .hw_params = kirkwood_i2s_hw_params, | ||
370 | .set_fmt = kirkwood_i2s_set_fmt, | ||
371 | }; | ||
372 | |||
373 | |||
374 | struct snd_soc_dai kirkwood_i2s_dai = { | ||
375 | .name = DRV_NAME, | ||
376 | .id = 0, | ||
377 | .probe = kirkwood_i2s_probe, | ||
378 | .remove = kirkwood_i2s_remove, | ||
379 | .playback = { | ||
380 | .channels_min = 1, | ||
381 | .channels_max = 2, | ||
382 | .rates = KIRKWOOD_I2S_RATES, | ||
383 | .formats = KIRKWOOD_I2S_FORMATS,}, | ||
384 | .capture = { | ||
385 | .channels_min = 1, | ||
386 | .channels_max = 2, | ||
387 | .rates = KIRKWOOD_I2S_RATES, | ||
388 | .formats = KIRKWOOD_I2S_FORMATS,}, | ||
389 | .ops = &kirkwood_i2s_dai_ops, | ||
390 | }; | ||
391 | EXPORT_SYMBOL_GPL(kirkwood_i2s_dai); | ||
392 | |||
393 | static __devinit int kirkwood_i2s_dev_probe(struct platform_device *pdev) | ||
394 | { | ||
395 | struct resource *mem; | ||
396 | struct kirkwood_asoc_platform_data *data = | ||
397 | pdev->dev.platform_data; | ||
398 | int err; | ||
399 | |||
400 | priv = kzalloc(sizeof(struct kirkwood_dma_data), GFP_KERNEL); | ||
401 | if (!priv) { | ||
402 | dev_err(&pdev->dev, "allocation failed\n"); | ||
403 | err = -ENOMEM; | ||
404 | goto error; | ||
405 | } | ||
406 | |||
407 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
408 | if (!mem) { | ||
409 | dev_err(&pdev->dev, "platform_get_resource failed\n"); | ||
410 | err = -ENXIO; | ||
411 | goto err_alloc; | ||
412 | } | ||
413 | |||
414 | priv->mem = request_mem_region(mem->start, SZ_16K, DRV_NAME); | ||
415 | if (!priv->mem) { | ||
416 | dev_err(&pdev->dev, "request_mem_region failed\n"); | ||
417 | err = -EBUSY; | ||
418 | goto error; | ||
419 | } | ||
420 | |||
421 | priv->io = ioremap(priv->mem->start, SZ_16K); | ||
422 | if (!priv->io) { | ||
423 | dev_err(&pdev->dev, "ioremap failed\n"); | ||
424 | err = -ENOMEM; | ||
425 | goto err_iomem; | ||
426 | } | ||
427 | |||
428 | priv->irq = platform_get_irq(pdev, 0); | ||
429 | if (priv->irq <= 0) { | ||
430 | dev_err(&pdev->dev, "platform_get_irq failed\n"); | ||
431 | err = -ENXIO; | ||
432 | goto err_ioremap; | ||
433 | } | ||
434 | |||
435 | if (!data || !data->dram) { | ||
436 | dev_err(&pdev->dev, "no platform data ?!\n"); | ||
437 | err = -EINVAL; | ||
438 | goto err_ioremap; | ||
439 | } | ||
440 | |||
441 | priv->dram = data->dram; | ||
442 | priv->burst = data->burst; | ||
443 | |||
444 | kirkwood_i2s_dai.capture.dma_data = priv; | ||
445 | kirkwood_i2s_dai.playback.dma_data = priv; | ||
446 | |||
447 | return snd_soc_register_dai(&kirkwood_i2s_dai); | ||
448 | |||
449 | err_ioremap: | ||
450 | iounmap(priv->io); | ||
451 | err_iomem: | ||
452 | release_mem_region(priv->mem->start, SZ_16K); | ||
453 | err_alloc: | ||
454 | kfree(priv); | ||
455 | error: | ||
456 | return err; | ||
457 | } | ||
458 | |||
459 | static __devexit int kirkwood_i2s_dev_remove(struct platform_device *pdev) | ||
460 | { | ||
461 | if (priv) { | ||
462 | iounmap(priv->io); | ||
463 | release_mem_region(priv->mem->start, SZ_16K); | ||
464 | kfree(priv); | ||
465 | } | ||
466 | snd_soc_unregister_dai(&kirkwood_i2s_dai); | ||
467 | return 0; | ||
468 | } | ||
469 | |||
470 | static struct platform_driver kirkwood_i2s_driver = { | ||
471 | .probe = kirkwood_i2s_dev_probe, | ||
472 | .remove = kirkwood_i2s_dev_remove, | ||
473 | .driver = { | ||
474 | .name = DRV_NAME, | ||
475 | .owner = THIS_MODULE, | ||
476 | }, | ||
477 | }; | ||
478 | |||
479 | static int __init kirkwood_i2s_init(void) | ||
480 | { | ||
481 | return platform_driver_register(&kirkwood_i2s_driver); | ||
482 | } | ||
483 | module_init(kirkwood_i2s_init); | ||
484 | |||
485 | static void __exit kirkwood_i2s_exit(void) | ||
486 | { | ||
487 | platform_driver_unregister(&kirkwood_i2s_driver); | ||
488 | } | ||
489 | module_exit(kirkwood_i2s_exit); | ||
490 | |||
491 | /* Module information */ | ||
492 | MODULE_AUTHOR("Arnaud Patard, <apatard@mandriva.com>"); | ||
493 | MODULE_DESCRIPTION("Kirkwood I2S SoC Interface"); | ||
494 | MODULE_LICENSE("GPL"); | ||
495 | MODULE_ALIAS("platform:kirkwood-i2s"); | ||
diff --git a/sound/soc/kirkwood/kirkwood-i2s.h b/sound/soc/kirkwood/kirkwood-i2s.h new file mode 100644 index 000000000000..c5595c616d7a --- /dev/null +++ b/sound/soc/kirkwood/kirkwood-i2s.h | |||
@@ -0,0 +1,17 @@ | |||
1 | /* | ||
2 | * kirkwood-i2s.h | ||
3 | * | ||
4 | * (c) 2010 Arnaud Patard <apatard@mandriva.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License as published by the | ||
8 | * Free Software Foundation; either version 2 of the License, or (at your | ||
9 | * option) any later version. | ||
10 | */ | ||
11 | |||
12 | #ifndef _KIRKWOOD_I2S_H | ||
13 | #define _KIRKWOOD_I2S_H | ||
14 | |||
15 | extern struct snd_soc_dai kirkwood_i2s_dai; | ||
16 | |||
17 | #endif | ||
diff --git a/sound/soc/kirkwood/kirkwood-openrd.c b/sound/soc/kirkwood/kirkwood-openrd.c new file mode 100644 index 000000000000..0353d06bc41a --- /dev/null +++ b/sound/soc/kirkwood/kirkwood-openrd.c | |||
@@ -0,0 +1,126 @@ | |||
1 | /* | ||
2 | * kirkwood-openrd.c | ||
3 | * | ||
4 | * (c) 2010 Arnaud Patard <apatard@mandriva.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License as published by the | ||
8 | * Free Software Foundation; either version 2 of the License, or (at your | ||
9 | * option) any later version. | ||
10 | */ | ||
11 | |||
12 | #include <linux/module.h> | ||
13 | #include <linux/moduleparam.h> | ||
14 | #include <linux/interrupt.h> | ||
15 | #include <linux/platform_device.h> | ||
16 | #include <linux/slab.h> | ||
17 | #include <sound/soc.h> | ||
18 | #include <mach/kirkwood.h> | ||
19 | #include <plat/audio.h> | ||
20 | #include <asm/mach-types.h> | ||
21 | #include "kirkwood-i2s.h" | ||
22 | #include "kirkwood-dma.h" | ||
23 | #include "../codecs/cs42l51.h" | ||
24 | |||
25 | static int openrd_client_hw_params(struct snd_pcm_substream *substream, | ||
26 | struct snd_pcm_hw_params *params) | ||
27 | { | ||
28 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
29 | struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; | ||
30 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; | ||
31 | int ret; | ||
32 | unsigned int freq, fmt; | ||
33 | |||
34 | fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS; | ||
35 | ret = snd_soc_dai_set_fmt(cpu_dai, fmt); | ||
36 | if (ret < 0) | ||
37 | return ret; | ||
38 | |||
39 | ret = snd_soc_dai_set_fmt(codec_dai, fmt); | ||
40 | if (ret < 0) | ||
41 | return ret; | ||
42 | |||
43 | switch (params_rate(params)) { | ||
44 | default: | ||
45 | case 44100: | ||
46 | freq = 11289600; | ||
47 | break; | ||
48 | case 48000: | ||
49 | freq = 12288000; | ||
50 | break; | ||
51 | case 96000: | ||
52 | freq = 24576000; | ||
53 | break; | ||
54 | } | ||
55 | |||
56 | return snd_soc_dai_set_sysclk(codec_dai, 0, freq, SND_SOC_CLOCK_IN); | ||
57 | |||
58 | } | ||
59 | |||
60 | static struct snd_soc_ops openrd_client_ops = { | ||
61 | .hw_params = openrd_client_hw_params, | ||
62 | }; | ||
63 | |||
64 | |||
65 | static struct snd_soc_dai_link openrd_client_dai[] = { | ||
66 | { | ||
67 | .name = "CS42L51", | ||
68 | .stream_name = "CS42L51 HiFi", | ||
69 | .cpu_dai = &kirkwood_i2s_dai, | ||
70 | .codec_dai = &cs42l51_dai, | ||
71 | .ops = &openrd_client_ops, | ||
72 | }, | ||
73 | }; | ||
74 | |||
75 | |||
76 | static struct snd_soc_card openrd_client = { | ||
77 | .name = "OpenRD Client", | ||
78 | .platform = &kirkwood_soc_platform, | ||
79 | .dai_link = openrd_client_dai, | ||
80 | .num_links = ARRAY_SIZE(openrd_client_dai), | ||
81 | }; | ||
82 | |||
83 | static struct snd_soc_device openrd_client_snd_devdata = { | ||
84 | .card = &openrd_client, | ||
85 | .codec_dev = &soc_codec_device_cs42l51, | ||
86 | }; | ||
87 | |||
88 | static struct platform_device *openrd_client_snd_device; | ||
89 | |||
90 | static int __init openrd_client_init(void) | ||
91 | { | ||
92 | int ret; | ||
93 | |||
94 | if (!machine_is_openrd_client()) | ||
95 | return 0; | ||
96 | |||
97 | openrd_client_snd_device = platform_device_alloc("soc-audio", -1); | ||
98 | if (!openrd_client_snd_device) | ||
99 | return -ENOMEM; | ||
100 | |||
101 | platform_set_drvdata(openrd_client_snd_device, | ||
102 | &openrd_client_snd_devdata); | ||
103 | openrd_client_snd_devdata.dev = &openrd_client_snd_device->dev; | ||
104 | |||
105 | ret = platform_device_add(openrd_client_snd_device); | ||
106 | if (ret) { | ||
107 | printk(KERN_ERR "%s: platform_device_add failed\n", __func__); | ||
108 | platform_device_put(openrd_client_snd_device); | ||
109 | } | ||
110 | |||
111 | return ret; | ||
112 | } | ||
113 | |||
114 | static void __exit openrd_client_exit(void) | ||
115 | { | ||
116 | platform_device_unregister(openrd_client_snd_device); | ||
117 | } | ||
118 | |||
119 | module_init(openrd_client_init); | ||
120 | module_exit(openrd_client_exit); | ||
121 | |||
122 | /* Module information */ | ||
123 | MODULE_AUTHOR("Arnaud Patard <apatard@mandriva.com>"); | ||
124 | MODULE_DESCRIPTION("ALSA SoC OpenRD Client"); | ||
125 | MODULE_LICENSE("GPL"); | ||
126 | MODULE_ALIAS("platform:soc-audio"); | ||
diff --git a/sound/soc/kirkwood/kirkwood.h b/sound/soc/kirkwood/kirkwood.h new file mode 100644 index 000000000000..bb6e6a5648c9 --- /dev/null +++ b/sound/soc/kirkwood/kirkwood.h | |||
@@ -0,0 +1,129 @@ | |||
1 | /* | ||
2 | * kirkwood.h | ||
3 | * | ||
4 | * (c) 2010 Arnaud Patard <apatard@mandriva.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License as published by the | ||
8 | * Free Software Foundation; either version 2 of the License, or (at your | ||
9 | * option) any later version. | ||
10 | */ | ||
11 | |||
12 | #ifndef _KIRKWOOD_AUDIO_H | ||
13 | #define _KIRKWOOD_AUDIO_H | ||
14 | |||
15 | #define KIRKWOOD_RECORD_WIN 0 | ||
16 | #define KIRKWOOD_PLAYBACK_WIN 1 | ||
17 | #define KIRKWOOD_MAX_AUDIO_WIN 2 | ||
18 | |||
19 | #define KIRKWOOD_AUDIO_WIN_BASE_REG(win) (0xA00 + ((win)<<3)) | ||
20 | #define KIRKWOOD_AUDIO_WIN_CTRL_REG(win) (0xA04 + ((win)<<3)) | ||
21 | |||
22 | |||
23 | #define KIRKWOOD_RECCTL 0x1000 | ||
24 | #define KIRKWOOD_RECCTL_SPDIF_EN (1<<11) | ||
25 | #define KIRKWOOD_RECCTL_I2S_EN (1<<10) | ||
26 | #define KIRKWOOD_RECCTL_PAUSE (1<<9) | ||
27 | #define KIRKWOOD_RECCTL_MUTE (1<<8) | ||
28 | #define KIRKWOOD_RECCTL_BURST_MASK (3<<5) | ||
29 | #define KIRKWOOD_RECCTL_BURST_128 (2<<5) | ||
30 | #define KIRKWOOD_RECCTL_BURST_32 (1<<5) | ||
31 | #define KIRKWOOD_RECCTL_MONO (1<<4) | ||
32 | #define KIRKWOOD_RECCTL_MONO_CHAN_RIGHT (1<<3) | ||
33 | #define KIRKWOOD_RECCTL_MONO_CHAN_LEFT (0<<3) | ||
34 | #define KIRKWOOD_RECCTL_SIZE_MASK (7<<0) | ||
35 | #define KIRKWOOD_RECCTL_SIZE_16 (7<<0) | ||
36 | #define KIRKWOOD_RECCTL_SIZE_16_C (3<<0) | ||
37 | #define KIRKWOOD_RECCTL_SIZE_20 (2<<0) | ||
38 | #define KIRKWOOD_RECCTL_SIZE_24 (1<<0) | ||
39 | #define KIRKWOOD_RECCTL_SIZE_32 (0<<0) | ||
40 | |||
41 | #define KIRKWOOD_REC_BUF_ADDR 0x1004 | ||
42 | #define KIRKWOOD_REC_BUF_SIZE 0x1008 | ||
43 | #define KIRKWOOD_REC_BYTE_COUNT 0x100C | ||
44 | |||
45 | #define KIRKWOOD_PLAYCTL 0x1100 | ||
46 | #define KIRKWOOD_PLAYCTL_PLAY_BUSY (1<<16) | ||
47 | #define KIRKWOOD_PLAYCTL_BURST_MASK (3<<11) | ||
48 | #define KIRKWOOD_PLAYCTL_BURST_128 (2<<11) | ||
49 | #define KIRKWOOD_PLAYCTL_BURST_32 (1<<11) | ||
50 | #define KIRKWOOD_PLAYCTL_PAUSE (1<<9) | ||
51 | #define KIRKWOOD_PLAYCTL_SPDIF_MUTE (1<<8) | ||
52 | #define KIRKWOOD_PLAYCTL_MONO_MASK (3<<5) | ||
53 | #define KIRKWOOD_PLAYCTL_MONO_BOTH (3<<5) | ||
54 | #define KIRKWOOD_PLAYCTL_MONO_OFF (0<<5) | ||
55 | #define KIRKWOOD_PLAYCTL_I2S_MUTE (1<<7) | ||
56 | #define KIRKWOOD_PLAYCTL_SPDIF_EN (1<<4) | ||
57 | #define KIRKWOOD_PLAYCTL_I2S_EN (1<<3) | ||
58 | #define KIRKWOOD_PLAYCTL_SIZE_MASK (7<<0) | ||
59 | #define KIRKWOOD_PLAYCTL_SIZE_16 (7<<0) | ||
60 | #define KIRKWOOD_PLAYCTL_SIZE_16_C (3<<0) | ||
61 | #define KIRKWOOD_PLAYCTL_SIZE_20 (2<<0) | ||
62 | #define KIRKWOOD_PLAYCTL_SIZE_24 (1<<0) | ||
63 | #define KIRKWOOD_PLAYCTL_SIZE_32 (0<<0) | ||
64 | |||
65 | #define KIRKWOOD_PLAY_BUF_ADDR 0x1104 | ||
66 | #define KIRKWOOD_PLAY_BUF_SIZE 0x1108 | ||
67 | #define KIRKWOOD_PLAY_BYTE_COUNT 0x110C | ||
68 | |||
69 | #define KIRKWOOD_DCO_CTL 0x1204 | ||
70 | #define KIRKWOOD_DCO_CTL_OFFSET_MASK (0xFFF<<2) | ||
71 | #define KIRKWOOD_DCO_CTL_OFFSET_0 (0x800<<2) | ||
72 | #define KIRKWOOD_DCO_CTL_FREQ_MASK (3<<0) | ||
73 | #define KIRKWOOD_DCO_CTL_FREQ_11 (0<<0) | ||
74 | #define KIRKWOOD_DCO_CTL_FREQ_12 (1<<0) | ||
75 | #define KIRKWOOD_DCO_CTL_FREQ_24 (2<<0) | ||
76 | |||
77 | #define KIRKWOOD_DCO_SPCR_STATUS 0x120c | ||
78 | #define KIRKWOOD_DCO_SPCR_STATUS_DCO_LOCK (1<<16) | ||
79 | |||
80 | #define KIRKWOOD_ERR_CAUSE 0x1300 | ||
81 | #define KIRKWOOD_ERR_MASK 0x1304 | ||
82 | |||
83 | #define KIRKWOOD_INT_CAUSE 0x1308 | ||
84 | #define KIRKWOOD_INT_MASK 0x130C | ||
85 | #define KIRKWOOD_INT_CAUSE_PLAY_BYTES (1<<14) | ||
86 | #define KIRKWOOD_INT_CAUSE_REC_BYTES (1<<13) | ||
87 | #define KIRKWOOD_INT_CAUSE_DMA_PLAY_END (1<<7) | ||
88 | #define KIRKWOOD_INT_CAUSE_DMA_PLAY_3Q (1<<6) | ||
89 | #define KIRKWOOD_INT_CAUSE_DMA_PLAY_HALF (1<<5) | ||
90 | #define KIRKWOOD_INT_CAUSE_DMA_PLAY_1Q (1<<4) | ||
91 | #define KIRKWOOD_INT_CAUSE_DMA_REC_END (1<<3) | ||
92 | #define KIRKWOOD_INT_CAUSE_DMA_REC_3Q (1<<2) | ||
93 | #define KIRKWOOD_INT_CAUSE_DMA_REC_HALF (1<<1) | ||
94 | #define KIRKWOOD_INT_CAUSE_DMA_REC_1Q (1<<0) | ||
95 | |||
96 | #define KIRKWOOD_REC_BYTE_INT_COUNT 0x1310 | ||
97 | #define KIRKWOOD_PLAY_BYTE_INT_COUNT 0x1314 | ||
98 | #define KIRKWOOD_BYTE_INT_COUNT_MASK 0xffffff | ||
99 | |||
100 | #define KIRKWOOD_I2S_PLAYCTL 0x2508 | ||
101 | #define KIRKWOOD_I2S_RECCTL 0x2408 | ||
102 | #define KIRKWOOD_I2S_CTL_JUST_MASK (0xf<<26) | ||
103 | #define KIRKWOOD_I2S_CTL_LJ (0<<26) | ||
104 | #define KIRKWOOD_I2S_CTL_I2S (5<<26) | ||
105 | #define KIRKWOOD_I2S_CTL_RJ (8<<26) | ||
106 | #define KIRKWOOD_I2S_CTL_SIZE_MASK (3<<30) | ||
107 | #define KIRKWOOD_I2S_CTL_SIZE_16 (3<<30) | ||
108 | #define KIRKWOOD_I2S_CTL_SIZE_20 (2<<30) | ||
109 | #define KIRKWOOD_I2S_CTL_SIZE_24 (1<<30) | ||
110 | #define KIRKWOOD_I2S_CTL_SIZE_32 (0<<30) | ||
111 | |||
112 | #define KIRKWOOD_AUDIO_BUF_MAX (16*1024*1024) | ||
113 | |||
114 | /* Theses values come from the marvell alsa driver */ | ||
115 | /* need to find where they come from */ | ||
116 | #define KIRKWOOD_SND_MIN_PERIODS 8 | ||
117 | #define KIRKWOOD_SND_MAX_PERIODS 16 | ||
118 | #define KIRKWOOD_SND_MIN_PERIOD_BYTES 0x4000 | ||
119 | #define KIRKWOOD_SND_MAX_PERIOD_BYTES 0x4000 | ||
120 | |||
121 | struct kirkwood_dma_data { | ||
122 | struct resource *mem; | ||
123 | void __iomem *io; | ||
124 | int irq; | ||
125 | int burst; | ||
126 | struct mbus_dram_target_info *dram; | ||
127 | }; | ||
128 | |||
129 | #endif | ||