diff options
author | apatard@mandriva.com <apatard@mandriva.com> | 2010-05-31 07:49:14 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2010-05-31 08:16:37 -0400 |
commit | f9b95980f87f021f8c69646738929189838ad035 (patch) | |
tree | 99ea04355647ccf423786804ddb56131d618c448 /sound/soc/kirkwood | |
parent | 492e2bf141478e2c1ce3abfda381f73d1f2108f5 (diff) |
ASoC: kirkwood: Add i2s support
This patch enables support for the i2s controller available on kirkwood
platforms
Signed-off-by: Arnaud Patard <apatard@mandriva.com>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/kirkwood')
-rw-r--r-- | sound/soc/kirkwood/Kconfig | 11 | ||||
-rw-r--r-- | sound/soc/kirkwood/Makefile | 6 | ||||
-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 | 485 | ||||
-rw-r--r-- | sound/soc/kirkwood/kirkwood-i2s.h | 17 | ||||
-rw-r--r-- | sound/soc/kirkwood/kirkwood.h | 126 |
7 files changed, 1045 insertions, 0 deletions
diff --git a/sound/soc/kirkwood/Kconfig b/sound/soc/kirkwood/Kconfig new file mode 100644 index 000000000000..5e151544cec1 --- /dev/null +++ b/sound/soc/kirkwood/Kconfig | |||
@@ -0,0 +1,11 @@ | |||
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 | |||
diff --git a/sound/soc/kirkwood/Makefile b/sound/soc/kirkwood/Makefile new file mode 100644 index 000000000000..89dd3e19e159 --- /dev/null +++ b/sound/soc/kirkwood/Makefile | |||
@@ -0,0 +1,6 @@ | |||
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 | |||
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..0adc59778d5a --- /dev/null +++ b/sound/soc/kirkwood/kirkwood-i2s.c | |||
@@ -0,0 +1,485 @@ | |||
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 | writel(i2s_value, priv->io+i2s_reg); | ||
157 | writel(value, priv->io+reg); | ||
158 | |||
159 | return 0; | ||
160 | } | ||
161 | |||
162 | static int kirkwood_i2s_play_trigger(struct snd_pcm_substream *substream, | ||
163 | int cmd, struct snd_soc_dai *dai) | ||
164 | { | ||
165 | unsigned long value; | ||
166 | |||
167 | /* | ||
168 | * specs says KIRKWOOD_PLAYCTL must be read 2 times before | ||
169 | * changing it. So read 1 time here and 1 later. | ||
170 | */ | ||
171 | value = readl(priv->io + KIRKWOOD_PLAYCTL); | ||
172 | |||
173 | switch (cmd) { | ||
174 | case SNDRV_PCM_TRIGGER_START: | ||
175 | /* stop audio, enable interrupts */ | ||
176 | value = readl(priv->io + KIRKWOOD_PLAYCTL); | ||
177 | value |= KIRKWOOD_PLAYCTL_PAUSE; | ||
178 | writel(value, priv->io + KIRKWOOD_PLAYCTL); | ||
179 | |||
180 | value = readl(priv->io + KIRKWOOD_INT_MASK); | ||
181 | value |= KIRKWOOD_INT_CAUSE_PLAY_BYTES; | ||
182 | writel(value, priv->io + KIRKWOOD_INT_MASK); | ||
183 | |||
184 | /* configure audio & enable i2s playback */ | ||
185 | value = readl(priv->io + KIRKWOOD_PLAYCTL); | ||
186 | value &= ~KIRKWOOD_PLAYCTL_BURST_MASK; | ||
187 | value &= ~(KIRKWOOD_PLAYCTL_PAUSE|KIRKWOOD_PLAYCTL_SPDIF_EN); | ||
188 | |||
189 | if (priv->burst == 32) | ||
190 | value |= KIRKWOOD_PLAYCTL_BURST_32; | ||
191 | else | ||
192 | value |= KIRKWOOD_PLAYCTL_BURST_128; | ||
193 | value |= KIRKWOOD_PLAYCTL_I2S_EN; | ||
194 | writel(value, priv->io + KIRKWOOD_PLAYCTL); | ||
195 | break; | ||
196 | |||
197 | case SNDRV_PCM_TRIGGER_STOP: | ||
198 | /* stop audio, disable interrupts */ | ||
199 | value = readl(priv->io + KIRKWOOD_PLAYCTL); | ||
200 | value |= KIRKWOOD_PLAYCTL_PAUSE; | ||
201 | writel(value, priv->io + KIRKWOOD_PLAYCTL); | ||
202 | |||
203 | value = readl(priv->io + KIRKWOOD_INT_MASK); | ||
204 | value &= ~KIRKWOOD_INT_CAUSE_PLAY_BYTES; | ||
205 | writel(value, priv->io + KIRKWOOD_INT_MASK); | ||
206 | |||
207 | /* disable all playbacks */ | ||
208 | value = readl(priv->io + KIRKWOOD_PLAYCTL); | ||
209 | value &= ~(KIRKWOOD_PLAYCTL_I2S_EN | KIRKWOOD_PLAYCTL_SPDIF_EN); | ||
210 | writel(value, priv->io + KIRKWOOD_PLAYCTL); | ||
211 | break; | ||
212 | |||
213 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
214 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
215 | value = readl(priv->io + KIRKWOOD_PLAYCTL); | ||
216 | value |= KIRKWOOD_PLAYCTL_PAUSE; | ||
217 | writel(value, priv->io + KIRKWOOD_PLAYCTL); | ||
218 | break; | ||
219 | |||
220 | case SNDRV_PCM_TRIGGER_RESUME: | ||
221 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
222 | value = readl(priv->io + KIRKWOOD_PLAYCTL); | ||
223 | value &= ~KIRKWOOD_PLAYCTL_PAUSE; | ||
224 | writel(value, priv->io + KIRKWOOD_PLAYCTL); | ||
225 | break; | ||
226 | |||
227 | default: | ||
228 | return -EINVAL; | ||
229 | } | ||
230 | |||
231 | return 0; | ||
232 | } | ||
233 | |||
234 | static int kirkwood_i2s_rec_trigger(struct snd_pcm_substream *substream, | ||
235 | int cmd, struct snd_soc_dai *dai) | ||
236 | { | ||
237 | unsigned long value; | ||
238 | |||
239 | value = readl(priv->io + KIRKWOOD_RECCTL); | ||
240 | |||
241 | switch (cmd) { | ||
242 | case SNDRV_PCM_TRIGGER_START: | ||
243 | /* stop audio, enable interrupts */ | ||
244 | value = readl(priv->io + KIRKWOOD_RECCTL); | ||
245 | value |= KIRKWOOD_RECCTL_PAUSE; | ||
246 | writel(value, priv->io + KIRKWOOD_RECCTL); | ||
247 | |||
248 | value = readl(priv->io + KIRKWOOD_INT_MASK); | ||
249 | value |= KIRKWOOD_INT_CAUSE_REC_BYTES; | ||
250 | writel(value, priv->io + KIRKWOOD_INT_MASK); | ||
251 | |||
252 | /* configure audio & enable i2s record */ | ||
253 | value = readl(priv->io + KIRKWOOD_RECCTL); | ||
254 | value &= ~KIRKWOOD_RECCTL_BURST_MASK; | ||
255 | value &= ~KIRKWOOD_RECCTL_MONO; | ||
256 | value &= ~(KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_SPDIF_EN); | ||
257 | |||
258 | if (priv->burst == 32) | ||
259 | value |= KIRKWOOD_RECCTL_BURST_32; | ||
260 | else | ||
261 | value |= KIRKWOOD_RECCTL_BURST_128; | ||
262 | value |= KIRKWOOD_RECCTL_I2S_EN; | ||
263 | |||
264 | writel(value, priv->io + KIRKWOOD_RECCTL); | ||
265 | break; | ||
266 | |||
267 | case SNDRV_PCM_TRIGGER_STOP: | ||
268 | /* stop audio, disable interrupts */ | ||
269 | value = readl(priv->io + KIRKWOOD_RECCTL); | ||
270 | value |= KIRKWOOD_RECCTL_PAUSE; | ||
271 | writel(value, priv->io + KIRKWOOD_RECCTL); | ||
272 | |||
273 | value = readl(priv->io + KIRKWOOD_INT_MASK); | ||
274 | value &= ~KIRKWOOD_INT_CAUSE_REC_BYTES; | ||
275 | writel(value, priv->io + KIRKWOOD_INT_MASK); | ||
276 | |||
277 | /* disable all records */ | ||
278 | value = readl(priv->io + KIRKWOOD_RECCTL); | ||
279 | value &= ~(KIRKWOOD_RECCTL_I2S_EN | KIRKWOOD_RECCTL_SPDIF_EN); | ||
280 | writel(value, priv->io + KIRKWOOD_RECCTL); | ||
281 | break; | ||
282 | |||
283 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
284 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
285 | value = readl(priv->io + KIRKWOOD_RECCTL); | ||
286 | value |= KIRKWOOD_RECCTL_PAUSE; | ||
287 | writel(value, priv->io + KIRKWOOD_RECCTL); | ||
288 | break; | ||
289 | |||
290 | case SNDRV_PCM_TRIGGER_RESUME: | ||
291 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
292 | value = readl(priv->io + KIRKWOOD_RECCTL); | ||
293 | value &= ~KIRKWOOD_RECCTL_PAUSE; | ||
294 | writel(value, priv->io + KIRKWOOD_RECCTL); | ||
295 | break; | ||
296 | |||
297 | default: | ||
298 | return -EINVAL; | ||
299 | break; | ||
300 | } | ||
301 | |||
302 | return 0; | ||
303 | } | ||
304 | |||
305 | static int kirkwood_i2s_trigger(struct snd_pcm_substream *substream, int cmd, | ||
306 | struct snd_soc_dai *dai) | ||
307 | { | ||
308 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | ||
309 | return kirkwood_i2s_play_trigger(substream, cmd, dai); | ||
310 | else | ||
311 | return kirkwood_i2s_rec_trigger(substream, cmd, dai); | ||
312 | |||
313 | return 0; | ||
314 | } | ||
315 | |||
316 | static int kirkwood_i2s_probe(struct platform_device *pdev, | ||
317 | struct snd_soc_dai *dai) | ||
318 | { | ||
319 | unsigned long value; | ||
320 | unsigned int reg_data; | ||
321 | |||
322 | /* put system in a "safe" state : */ | ||
323 | /* disable audio interrupts */ | ||
324 | writel(0xffffffff, priv->io + KIRKWOOD_INT_CAUSE); | ||
325 | writel(0, priv->io + KIRKWOOD_INT_MASK); | ||
326 | |||
327 | reg_data = readl(priv->io + 0x1200); | ||
328 | reg_data &= (~(0x333FF8)); | ||
329 | reg_data |= 0x111D18; | ||
330 | writel(reg_data, priv->io + 0x1200); | ||
331 | |||
332 | msleep(500); | ||
333 | |||
334 | reg_data = readl(priv->io + 0x1200); | ||
335 | reg_data &= (~(0x333FF8)); | ||
336 | reg_data |= 0x111D18; | ||
337 | writel(reg_data, priv->io + 0x1200); | ||
338 | |||
339 | /* disable playback/record */ | ||
340 | value = readl(priv->io + KIRKWOOD_PLAYCTL); | ||
341 | value &= ~(KIRKWOOD_PLAYCTL_I2S_EN|KIRKWOOD_PLAYCTL_SPDIF_EN); | ||
342 | writel(value, priv->io + KIRKWOOD_PLAYCTL); | ||
343 | |||
344 | value = readl(priv->io + KIRKWOOD_RECCTL); | ||
345 | value &= ~(KIRKWOOD_RECCTL_I2S_EN | KIRKWOOD_RECCTL_SPDIF_EN); | ||
346 | writel(value, priv->io + KIRKWOOD_RECCTL); | ||
347 | |||
348 | return 0; | ||
349 | |||
350 | } | ||
351 | |||
352 | static void kirkwood_i2s_remove(struct platform_device *pdev, | ||
353 | struct snd_soc_dai *dai) | ||
354 | { | ||
355 | } | ||
356 | |||
357 | static struct snd_soc_dai_ops kirkwood_i2s_dai_ops = { | ||
358 | .trigger = kirkwood_i2s_trigger, | ||
359 | .hw_params = kirkwood_i2s_hw_params, | ||
360 | .set_fmt = kirkwood_i2s_set_fmt, | ||
361 | }; | ||
362 | |||
363 | |||
364 | struct snd_soc_dai kirkwood_i2s_dai = { | ||
365 | .name = DRV_NAME, | ||
366 | .id = 0, | ||
367 | .probe = kirkwood_i2s_probe, | ||
368 | .remove = kirkwood_i2s_remove, | ||
369 | .playback = { | ||
370 | .channels_min = 1, | ||
371 | .channels_max = 2, | ||
372 | .rates = KIRKWOOD_I2S_RATES, | ||
373 | .formats = KIRKWOOD_I2S_FORMATS,}, | ||
374 | .capture = { | ||
375 | .channels_min = 1, | ||
376 | .channels_max = 2, | ||
377 | .rates = KIRKWOOD_I2S_RATES, | ||
378 | .formats = KIRKWOOD_I2S_FORMATS,}, | ||
379 | .ops = &kirkwood_i2s_dai_ops, | ||
380 | }; | ||
381 | EXPORT_SYMBOL_GPL(kirkwood_i2s_dai); | ||
382 | |||
383 | static __devinit int kirkwood_i2s_dev_probe(struct platform_device *pdev) | ||
384 | { | ||
385 | struct resource *mem; | ||
386 | struct kirkwood_asoc_platform_data *data = | ||
387 | pdev->dev.platform_data; | ||
388 | int err; | ||
389 | |||
390 | priv = kzalloc(sizeof(struct kirkwood_dma_data), GFP_KERNEL); | ||
391 | if (!priv) { | ||
392 | dev_err(&pdev->dev, "allocation failed\n"); | ||
393 | err = -ENOMEM; | ||
394 | goto error; | ||
395 | } | ||
396 | |||
397 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
398 | if (!mem) { | ||
399 | dev_err(&pdev->dev, "platform_get_resource failed\n"); | ||
400 | err = -ENXIO; | ||
401 | goto err_alloc; | ||
402 | } | ||
403 | |||
404 | priv->mem = request_mem_region(mem->start, SZ_16K, DRV_NAME); | ||
405 | if (!priv->mem) { | ||
406 | dev_err(&pdev->dev, "request_mem_region failed\n"); | ||
407 | err = -EBUSY; | ||
408 | goto error; | ||
409 | } | ||
410 | |||
411 | priv->io = ioremap(priv->mem->start, SZ_16K); | ||
412 | if (!priv->io) { | ||
413 | dev_err(&pdev->dev, "ioremap failed\n"); | ||
414 | err = -ENOMEM; | ||
415 | goto err_iomem; | ||
416 | } | ||
417 | |||
418 | priv->irq = platform_get_irq(pdev, 0); | ||
419 | if (priv->irq <= 0) { | ||
420 | dev_err(&pdev->dev, "platform_get_irq failed\n"); | ||
421 | err = -ENXIO; | ||
422 | goto err_ioremap; | ||
423 | } | ||
424 | |||
425 | if (!data || !data->dram) { | ||
426 | dev_err(&pdev->dev, "no platform data ?!\n"); | ||
427 | err = -EINVAL; | ||
428 | goto err_ioremap; | ||
429 | } | ||
430 | |||
431 | priv->dram = data->dram; | ||
432 | priv->burst = data->burst; | ||
433 | |||
434 | kirkwood_i2s_dai.capture.dma_data = priv; | ||
435 | kirkwood_i2s_dai.playback.dma_data = priv; | ||
436 | |||
437 | return snd_soc_register_dai(&kirkwood_i2s_dai); | ||
438 | |||
439 | err_ioremap: | ||
440 | iounmap(priv->io); | ||
441 | err_iomem: | ||
442 | release_mem_region(priv->mem->start, SZ_16K); | ||
443 | err_alloc: | ||
444 | kfree(priv); | ||
445 | error: | ||
446 | return err; | ||
447 | } | ||
448 | |||
449 | static __devexit int kirkwood_i2s_dev_remove(struct platform_device *pdev) | ||
450 | { | ||
451 | if (priv) { | ||
452 | iounmap(priv->io); | ||
453 | release_mem_region(priv->mem->start, SZ_16K); | ||
454 | kfree(priv); | ||
455 | } | ||
456 | snd_soc_unregister_dai(&kirkwood_i2s_dai); | ||
457 | return 0; | ||
458 | } | ||
459 | |||
460 | static struct platform_driver kirkwood_i2s_driver = { | ||
461 | .probe = kirkwood_i2s_dev_probe, | ||
462 | .remove = kirkwood_i2s_dev_remove, | ||
463 | .driver = { | ||
464 | .name = DRV_NAME, | ||
465 | .owner = THIS_MODULE, | ||
466 | }, | ||
467 | }; | ||
468 | |||
469 | static int __init kirkwood_i2s_init(void) | ||
470 | { | ||
471 | return platform_driver_register(&kirkwood_i2s_driver); | ||
472 | } | ||
473 | module_init(kirkwood_i2s_init); | ||
474 | |||
475 | static void __exit kirkwood_i2s_exit(void) | ||
476 | { | ||
477 | platform_driver_unregister(&kirkwood_i2s_driver); | ||
478 | } | ||
479 | module_exit(kirkwood_i2s_exit); | ||
480 | |||
481 | /* Module information */ | ||
482 | MODULE_AUTHOR("Arnaud Patard, <apatard@mandriva.com>"); | ||
483 | MODULE_DESCRIPTION("Kirkwood I2S SoC Interface"); | ||
484 | MODULE_LICENSE("GPL"); | ||
485 | 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.h b/sound/soc/kirkwood/kirkwood.h new file mode 100644 index 000000000000..b6e4f68d71dd --- /dev/null +++ b/sound/soc/kirkwood/kirkwood.h | |||
@@ -0,0 +1,126 @@ | |||
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_I2S_MUTE (1<<7) | ||
53 | #define KIRKWOOD_PLAYCTL_SPDIF_EN (1<<4) | ||
54 | #define KIRKWOOD_PLAYCTL_I2S_EN (1<<3) | ||
55 | #define KIRKWOOD_PLAYCTL_SIZE_MASK (7<<0) | ||
56 | #define KIRKWOOD_PLAYCTL_SIZE_16 (7<<0) | ||
57 | #define KIRKWOOD_PLAYCTL_SIZE_16_C (3<<0) | ||
58 | #define KIRKWOOD_PLAYCTL_SIZE_20 (2<<0) | ||
59 | #define KIRKWOOD_PLAYCTL_SIZE_24 (1<<0) | ||
60 | #define KIRKWOOD_PLAYCTL_SIZE_32 (0<<0) | ||
61 | |||
62 | #define KIRKWOOD_PLAY_BUF_ADDR 0x1104 | ||
63 | #define KIRKWOOD_PLAY_BUF_SIZE 0x1108 | ||
64 | #define KIRKWOOD_PLAY_BYTE_COUNT 0x110C | ||
65 | |||
66 | #define KIRKWOOD_DCO_CTL 0x1204 | ||
67 | #define KIRKWOOD_DCO_CTL_OFFSET_MASK (0xFFF<<2) | ||
68 | #define KIRKWOOD_DCO_CTL_OFFSET_0 (0x800<<2) | ||
69 | #define KIRKWOOD_DCO_CTL_FREQ_MASK (3<<0) | ||
70 | #define KIRKWOOD_DCO_CTL_FREQ_11 (0<<0) | ||
71 | #define KIRKWOOD_DCO_CTL_FREQ_12 (1<<0) | ||
72 | #define KIRKWOOD_DCO_CTL_FREQ_24 (2<<0) | ||
73 | |||
74 | #define KIRKWOOD_DCO_SPCR_STATUS 0x120c | ||
75 | #define KIRKWOOD_DCO_SPCR_STATUS_DCO_LOCK (1<<16) | ||
76 | |||
77 | #define KIRKWOOD_ERR_CAUSE 0x1300 | ||
78 | #define KIRKWOOD_ERR_MASK 0x1304 | ||
79 | |||
80 | #define KIRKWOOD_INT_CAUSE 0x1308 | ||
81 | #define KIRKWOOD_INT_MASK 0x130C | ||
82 | #define KIRKWOOD_INT_CAUSE_PLAY_BYTES (1<<14) | ||
83 | #define KIRKWOOD_INT_CAUSE_REC_BYTES (1<<13) | ||
84 | #define KIRKWOOD_INT_CAUSE_DMA_PLAY_END (1<<7) | ||
85 | #define KIRKWOOD_INT_CAUSE_DMA_PLAY_3Q (1<<6) | ||
86 | #define KIRKWOOD_INT_CAUSE_DMA_PLAY_HALF (1<<5) | ||
87 | #define KIRKWOOD_INT_CAUSE_DMA_PLAY_1Q (1<<4) | ||
88 | #define KIRKWOOD_INT_CAUSE_DMA_REC_END (1<<3) | ||
89 | #define KIRKWOOD_INT_CAUSE_DMA_REC_3Q (1<<2) | ||
90 | #define KIRKWOOD_INT_CAUSE_DMA_REC_HALF (1<<1) | ||
91 | #define KIRKWOOD_INT_CAUSE_DMA_REC_1Q (1<<0) | ||
92 | |||
93 | #define KIRKWOOD_REC_BYTE_INT_COUNT 0x1310 | ||
94 | #define KIRKWOOD_PLAY_BYTE_INT_COUNT 0x1314 | ||
95 | #define KIRKWOOD_BYTE_INT_COUNT_MASK 0xffffff | ||
96 | |||
97 | #define KIRKWOOD_I2S_PLAYCTL 0x2508 | ||
98 | #define KIRKWOOD_I2S_RECCTL 0x2408 | ||
99 | #define KIRKWOOD_I2S_CTL_JUST_MASK (0xf<<26) | ||
100 | #define KIRKWOOD_I2S_CTL_LJ (0<<26) | ||
101 | #define KIRKWOOD_I2S_CTL_I2S (5<<26) | ||
102 | #define KIRKWOOD_I2S_CTL_RJ (8<<26) | ||
103 | #define KIRKWOOD_I2S_CTL_SIZE_MASK (3<<30) | ||
104 | #define KIRKWOOD_I2S_CTL_SIZE_16 (3<<30) | ||
105 | #define KIRKWOOD_I2S_CTL_SIZE_20 (2<<30) | ||
106 | #define KIRKWOOD_I2S_CTL_SIZE_24 (1<<30) | ||
107 | #define KIRKWOOD_I2S_CTL_SIZE_32 (0<<30) | ||
108 | |||
109 | #define KIRKWOOD_AUDIO_BUF_MAX (16*1024*1024) | ||
110 | |||
111 | /* Theses values come from the marvell alsa driver */ | ||
112 | /* need to find where they come from */ | ||
113 | #define KIRKWOOD_SND_MIN_PERIODS 8 | ||
114 | #define KIRKWOOD_SND_MAX_PERIODS 16 | ||
115 | #define KIRKWOOD_SND_MIN_PERIOD_BYTES 0x4000 | ||
116 | #define KIRKWOOD_SND_MAX_PERIOD_BYTES 0x4000 | ||
117 | |||
118 | struct kirkwood_dma_data { | ||
119 | struct resource *mem; | ||
120 | void __iomem *io; | ||
121 | int irq; | ||
122 | int burst; | ||
123 | struct mbus_dram_target_info *dram; | ||
124 | }; | ||
125 | |||
126 | #endif | ||