diff options
author | Manuel Lauss <manuel.lauss@googlemail.com> | 2011-07-25 07:44:45 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2011-07-26 10:40:51 -0400 |
commit | b3c70c9ea62a3ae6c63536e43fa28f965a56de91 (patch) | |
tree | 7adb8e6488c0a01df75368635490ae144c0632e6 /sound/soc/au1x | |
parent | ee47b364860bb21580cc105e6bb6e0dd76b75ad2 (diff) |
ASoC: Alchemy AC97C/I2SC audio support
This patch adds ASoC support for the AC97 and I2S controllers
on the old Au1000/Au1500/Au1100 chips,
AC97 Tested on a Db1500. I2S untested since none of the boards
actually have an I2S codec wired up (just test pins).
Signed-off-by: Manuel Lauss <manuel.lauss@googlemail.com>
Acked-by: Liam Girdwood <lrg@ti.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/au1x')
-rw-r--r-- | sound/soc/au1x/Kconfig | 19 | ||||
-rw-r--r-- | sound/soc/au1x/Makefile | 8 | ||||
-rw-r--r-- | sound/soc/au1x/ac97c.c | 365 | ||||
-rw-r--r-- | sound/soc/au1x/dma.c | 377 | ||||
-rw-r--r-- | sound/soc/au1x/i2sc.c | 347 | ||||
-rw-r--r-- | sound/soc/au1x/psc.h | 19 |
6 files changed, 1126 insertions, 9 deletions
diff --git a/sound/soc/au1x/Kconfig b/sound/soc/au1x/Kconfig index 4b67140fdec3..0460b428862c 100644 --- a/sound/soc/au1x/Kconfig +++ b/sound/soc/au1x/Kconfig | |||
@@ -18,6 +18,25 @@ config SND_SOC_AU1XPSC_AC97 | |||
18 | select SND_AC97_CODEC | 18 | select SND_AC97_CODEC |
19 | select SND_SOC_AC97_BUS | 19 | select SND_SOC_AC97_BUS |
20 | 20 | ||
21 | ## | ||
22 | ## Au1000/1500/1100 DMA + AC97C/I2SC | ||
23 | ## | ||
24 | config SND_SOC_AU1XAUDIO | ||
25 | tristate "SoC Audio for Au1000/Au1500/Au1100" | ||
26 | depends on MIPS_ALCHEMY | ||
27 | help | ||
28 | This is a driver set for the AC97 unit and the | ||
29 | old DMA controller as found on the Au1000/Au1500/Au1100 chips. | ||
30 | |||
31 | config SND_SOC_AU1XAC97C | ||
32 | tristate | ||
33 | select AC97_BUS | ||
34 | select SND_AC97_CODEC | ||
35 | select SND_SOC_AC97_BUS | ||
36 | |||
37 | config SND_SOC_AU1XI2SC | ||
38 | tristate | ||
39 | |||
21 | 40 | ||
22 | ## | 41 | ## |
23 | ## Boards | 42 | ## Boards |
diff --git a/sound/soc/au1x/Makefile b/sound/soc/au1x/Makefile index 16873076e8c4..ff5531eee613 100644 --- a/sound/soc/au1x/Makefile +++ b/sound/soc/au1x/Makefile | |||
@@ -3,9 +3,17 @@ snd-soc-au1xpsc-dbdma-objs := dbdma2.o | |||
3 | snd-soc-au1xpsc-i2s-objs := psc-i2s.o | 3 | snd-soc-au1xpsc-i2s-objs := psc-i2s.o |
4 | snd-soc-au1xpsc-ac97-objs := psc-ac97.o | 4 | snd-soc-au1xpsc-ac97-objs := psc-ac97.o |
5 | 5 | ||
6 | # Au1000/1500/1100 Audio units | ||
7 | snd-soc-au1x-dma-objs := dma.o | ||
8 | snd-soc-au1x-ac97c-objs := ac97c.o | ||
9 | snd-soc-au1x-i2sc-objs := i2sc.o | ||
10 | |||
6 | obj-$(CONFIG_SND_SOC_AU1XPSC) += snd-soc-au1xpsc-dbdma.o | 11 | obj-$(CONFIG_SND_SOC_AU1XPSC) += snd-soc-au1xpsc-dbdma.o |
7 | obj-$(CONFIG_SND_SOC_AU1XPSC_I2S) += snd-soc-au1xpsc-i2s.o | 12 | obj-$(CONFIG_SND_SOC_AU1XPSC_I2S) += snd-soc-au1xpsc-i2s.o |
8 | obj-$(CONFIG_SND_SOC_AU1XPSC_AC97) += snd-soc-au1xpsc-ac97.o | 13 | obj-$(CONFIG_SND_SOC_AU1XPSC_AC97) += snd-soc-au1xpsc-ac97.o |
14 | obj-$(CONFIG_SND_SOC_AU1XAUDIO) += snd-soc-au1x-dma.o | ||
15 | obj-$(CONFIG_SND_SOC_AU1XAC97C) += snd-soc-au1x-ac97c.o | ||
16 | obj-$(CONFIG_SND_SOC_AU1XI2SC) += snd-soc-au1x-i2sc.o | ||
9 | 17 | ||
10 | # Boards | 18 | # Boards |
11 | snd-soc-db1200-objs := db1200.o | 19 | snd-soc-db1200-objs := db1200.o |
diff --git a/sound/soc/au1x/ac97c.c b/sound/soc/au1x/ac97c.c new file mode 100644 index 000000000000..9c05f381d95e --- /dev/null +++ b/sound/soc/au1x/ac97c.c | |||
@@ -0,0 +1,365 @@ | |||
1 | /* | ||
2 | * Au1000/Au1500/Au1100 AC97C controller driver for ASoC | ||
3 | * | ||
4 | * (c) 2011 Manuel Lauss <manuel.lauss@googlemail.com> | ||
5 | * | ||
6 | * based on the old ALSA driver originally written by | ||
7 | * Charles Eidsness <charles@cooper-street.com> | ||
8 | */ | ||
9 | |||
10 | #include <linux/init.h> | ||
11 | #include <linux/module.h> | ||
12 | #include <linux/slab.h> | ||
13 | #include <linux/device.h> | ||
14 | #include <linux/delay.h> | ||
15 | #include <linux/mutex.h> | ||
16 | #include <linux/platform_device.h> | ||
17 | #include <linux/suspend.h> | ||
18 | #include <sound/core.h> | ||
19 | #include <sound/pcm.h> | ||
20 | #include <sound/initval.h> | ||
21 | #include <sound/soc.h> | ||
22 | #include <asm/mach-au1x00/au1000.h> | ||
23 | |||
24 | #include "psc.h" | ||
25 | |||
26 | /* register offsets and bits */ | ||
27 | #define AC97_CONFIG 0x00 | ||
28 | #define AC97_STATUS 0x04 | ||
29 | #define AC97_DATA 0x08 | ||
30 | #define AC97_CMDRESP 0x0c | ||
31 | #define AC97_ENABLE 0x10 | ||
32 | |||
33 | #define CFG_RC(x) (((x) & 0x3ff) << 13) /* valid rx slots mask */ | ||
34 | #define CFG_XS(x) (((x) & 0x3ff) << 3) /* valid tx slots mask */ | ||
35 | #define CFG_SG (1 << 2) /* sync gate */ | ||
36 | #define CFG_SN (1 << 1) /* sync control */ | ||
37 | #define CFG_RS (1 << 0) /* acrst# control */ | ||
38 | #define STAT_XU (1 << 11) /* tx underflow */ | ||
39 | #define STAT_XO (1 << 10) /* tx overflow */ | ||
40 | #define STAT_RU (1 << 9) /* rx underflow */ | ||
41 | #define STAT_RO (1 << 8) /* rx overflow */ | ||
42 | #define STAT_RD (1 << 7) /* codec ready */ | ||
43 | #define STAT_CP (1 << 6) /* command pending */ | ||
44 | #define STAT_TE (1 << 4) /* tx fifo empty */ | ||
45 | #define STAT_TF (1 << 3) /* tx fifo full */ | ||
46 | #define STAT_RE (1 << 1) /* rx fifo empty */ | ||
47 | #define STAT_RF (1 << 0) /* rx fifo full */ | ||
48 | #define CMD_SET_DATA(x) (((x) & 0xffff) << 16) | ||
49 | #define CMD_GET_DATA(x) ((x) & 0xffff) | ||
50 | #define CMD_READ (1 << 7) | ||
51 | #define CMD_WRITE (0 << 7) | ||
52 | #define CMD_IDX(x) ((x) & 0x7f) | ||
53 | #define EN_D (1 << 1) /* DISable bit */ | ||
54 | #define EN_CE (1 << 0) /* clock enable bit */ | ||
55 | |||
56 | /* how often to retry failed codec register reads/writes */ | ||
57 | #define AC97_RW_RETRIES 5 | ||
58 | |||
59 | #define AC97_RATES \ | ||
60 | SNDRV_PCM_RATE_CONTINUOUS | ||
61 | |||
62 | #define AC97_FMTS \ | ||
63 | (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE) | ||
64 | |||
65 | /* instance data. There can be only one, MacLeod!!!!, fortunately there IS only | ||
66 | * once AC97C on early Alchemy chips. The newer ones aren't so lucky. | ||
67 | */ | ||
68 | static struct au1xpsc_audio_data *ac97c_workdata; | ||
69 | #define ac97_to_ctx(x) ac97c_workdata | ||
70 | |||
71 | static inline unsigned long RD(struct au1xpsc_audio_data *ctx, int reg) | ||
72 | { | ||
73 | return __raw_readl(ctx->mmio + reg); | ||
74 | } | ||
75 | |||
76 | static inline void WR(struct au1xpsc_audio_data *ctx, int reg, unsigned long v) | ||
77 | { | ||
78 | __raw_writel(v, ctx->mmio + reg); | ||
79 | wmb(); | ||
80 | } | ||
81 | |||
82 | static unsigned short au1xac97c_ac97_read(struct snd_ac97 *ac97, | ||
83 | unsigned short r) | ||
84 | { | ||
85 | struct au1xpsc_audio_data *ctx = ac97_to_ctx(ac97); | ||
86 | unsigned int tmo, retry; | ||
87 | unsigned long data; | ||
88 | |||
89 | data = ~0; | ||
90 | retry = AC97_RW_RETRIES; | ||
91 | do { | ||
92 | mutex_lock(&ctx->lock); | ||
93 | |||
94 | tmo = 5; | ||
95 | while ((RD(ctx, AC97_STATUS) & STAT_CP) && tmo--) | ||
96 | udelay(21); /* wait an ac97 frame time */ | ||
97 | if (!tmo) { | ||
98 | pr_debug("ac97rd timeout #1\n"); | ||
99 | goto next; | ||
100 | } | ||
101 | |||
102 | WR(ctx, AC97_CMDRESP, CMD_IDX(r) | CMD_READ); | ||
103 | |||
104 | /* stupid errata: data is only valid for 21us, so | ||
105 | * poll, Forrest, poll... | ||
106 | */ | ||
107 | tmo = 0x10000; | ||
108 | while ((RD(ctx, AC97_STATUS) & STAT_CP) && tmo--) | ||
109 | asm volatile ("nop"); | ||
110 | data = RD(ctx, AC97_CMDRESP); | ||
111 | |||
112 | if (!tmo) | ||
113 | pr_debug("ac97rd timeout #2\n"); | ||
114 | |||
115 | next: | ||
116 | mutex_unlock(&ctx->lock); | ||
117 | } while (--retry && !tmo); | ||
118 | |||
119 | pr_debug("AC97RD %04x %04lx %d\n", r, data, retry); | ||
120 | |||
121 | return retry ? data & 0xffff : 0xffff; | ||
122 | } | ||
123 | |||
124 | static void au1xac97c_ac97_write(struct snd_ac97 *ac97, unsigned short r, | ||
125 | unsigned short v) | ||
126 | { | ||
127 | struct au1xpsc_audio_data *ctx = ac97_to_ctx(ac97); | ||
128 | unsigned int tmo, retry; | ||
129 | |||
130 | retry = AC97_RW_RETRIES; | ||
131 | do { | ||
132 | mutex_lock(&ctx->lock); | ||
133 | |||
134 | for (tmo = 5; (RD(ctx, AC97_STATUS) & STAT_CP) && tmo; tmo--) | ||
135 | udelay(21); | ||
136 | if (!tmo) { | ||
137 | pr_debug("ac97wr timeout #1\n"); | ||
138 | goto next; | ||
139 | } | ||
140 | |||
141 | WR(ctx, AC97_CMDRESP, CMD_WRITE | CMD_IDX(r) | CMD_SET_DATA(v)); | ||
142 | |||
143 | for (tmo = 10; (RD(ctx, AC97_STATUS) & STAT_CP) && tmo; tmo--) | ||
144 | udelay(21); | ||
145 | if (!tmo) | ||
146 | pr_debug("ac97wr timeout #2\n"); | ||
147 | next: | ||
148 | mutex_unlock(&ctx->lock); | ||
149 | } while (--retry && !tmo); | ||
150 | |||
151 | pr_debug("AC97WR %04x %04x %d\n", r, v, retry); | ||
152 | } | ||
153 | |||
154 | static void au1xac97c_ac97_warm_reset(struct snd_ac97 *ac97) | ||
155 | { | ||
156 | struct au1xpsc_audio_data *ctx = ac97_to_ctx(ac97); | ||
157 | |||
158 | WR(ctx, AC97_CONFIG, ctx->cfg | CFG_SG | CFG_SN); | ||
159 | msleep(20); | ||
160 | WR(ctx, AC97_CONFIG, ctx->cfg | CFG_SG); | ||
161 | WR(ctx, AC97_CONFIG, ctx->cfg); | ||
162 | } | ||
163 | |||
164 | static void au1xac97c_ac97_cold_reset(struct snd_ac97 *ac97) | ||
165 | { | ||
166 | struct au1xpsc_audio_data *ctx = ac97_to_ctx(ac97); | ||
167 | int i; | ||
168 | |||
169 | WR(ctx, AC97_CONFIG, ctx->cfg | CFG_RS); | ||
170 | msleep(500); | ||
171 | WR(ctx, AC97_CONFIG, ctx->cfg); | ||
172 | |||
173 | /* wait for codec ready */ | ||
174 | i = 50; | ||
175 | while (((RD(ctx, AC97_STATUS) & STAT_RD) == 0) && --i) | ||
176 | msleep(20); | ||
177 | if (!i) | ||
178 | printk(KERN_ERR "ac97c: codec not ready after cold reset\n"); | ||
179 | } | ||
180 | |||
181 | /* AC97 controller operations */ | ||
182 | struct snd_ac97_bus_ops soc_ac97_ops = { | ||
183 | .read = au1xac97c_ac97_read, | ||
184 | .write = au1xac97c_ac97_write, | ||
185 | .reset = au1xac97c_ac97_cold_reset, | ||
186 | .warm_reset = au1xac97c_ac97_warm_reset, | ||
187 | }; | ||
188 | EXPORT_SYMBOL_GPL(soc_ac97_ops); /* globals be gone! */ | ||
189 | |||
190 | static int alchemy_ac97c_startup(struct snd_pcm_substream *substream, | ||
191 | struct snd_soc_dai *dai) | ||
192 | { | ||
193 | struct au1xpsc_audio_data *ctx = snd_soc_dai_get_drvdata(dai); | ||
194 | snd_soc_dai_set_dma_data(dai, substream, &ctx->dmaids[0]); | ||
195 | return 0; | ||
196 | } | ||
197 | |||
198 | static struct snd_soc_dai_ops alchemy_ac97c_ops = { | ||
199 | .startup = alchemy_ac97c_startup, | ||
200 | }; | ||
201 | |||
202 | static int au1xac97c_dai_probe(struct snd_soc_dai *dai) | ||
203 | { | ||
204 | return ac97c_workdata ? 0 : -ENODEV; | ||
205 | } | ||
206 | |||
207 | static struct snd_soc_dai_driver au1xac97c_dai_driver = { | ||
208 | .name = "alchemy-ac97c", | ||
209 | .ac97_control = 1, | ||
210 | .probe = au1xac97c_dai_probe, | ||
211 | .playback = { | ||
212 | .rates = AC97_RATES, | ||
213 | .formats = AC97_FMTS, | ||
214 | .channels_min = 2, | ||
215 | .channels_max = 2, | ||
216 | }, | ||
217 | .capture = { | ||
218 | .rates = AC97_RATES, | ||
219 | .formats = AC97_FMTS, | ||
220 | .channels_min = 2, | ||
221 | .channels_max = 2, | ||
222 | }, | ||
223 | .ops = &alchemy_ac97c_ops, | ||
224 | }; | ||
225 | |||
226 | static int __devinit au1xac97c_drvprobe(struct platform_device *pdev) | ||
227 | { | ||
228 | int ret; | ||
229 | struct resource *r; | ||
230 | struct au1xpsc_audio_data *ctx; | ||
231 | |||
232 | ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); | ||
233 | if (!ctx) | ||
234 | return -ENOMEM; | ||
235 | |||
236 | mutex_init(&ctx->lock); | ||
237 | |||
238 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
239 | if (!r) { | ||
240 | ret = -ENODEV; | ||
241 | goto out0; | ||
242 | } | ||
243 | |||
244 | ret = -EBUSY; | ||
245 | if (!request_mem_region(r->start, resource_size(r), pdev->name)) | ||
246 | goto out0; | ||
247 | |||
248 | ctx->mmio = ioremap_nocache(r->start, resource_size(r)); | ||
249 | if (!ctx->mmio) | ||
250 | goto out1; | ||
251 | |||
252 | r = platform_get_resource(pdev, IORESOURCE_DMA, 0); | ||
253 | if (!r) | ||
254 | goto out1; | ||
255 | ctx->dmaids[SNDRV_PCM_STREAM_PLAYBACK] = r->start; | ||
256 | |||
257 | r = platform_get_resource(pdev, IORESOURCE_DMA, 1); | ||
258 | if (!r) | ||
259 | goto out1; | ||
260 | ctx->dmaids[SNDRV_PCM_STREAM_CAPTURE] = r->start; | ||
261 | |||
262 | /* switch it on */ | ||
263 | WR(ctx, AC97_ENABLE, EN_D | EN_CE); | ||
264 | WR(ctx, AC97_ENABLE, EN_CE); | ||
265 | |||
266 | ctx->cfg = CFG_RC(3) | CFG_XS(3); | ||
267 | WR(ctx, AC97_CONFIG, ctx->cfg); | ||
268 | |||
269 | platform_set_drvdata(pdev, ctx); | ||
270 | |||
271 | ret = snd_soc_register_dai(&pdev->dev, &au1xac97c_dai_driver); | ||
272 | if (ret) | ||
273 | goto out1; | ||
274 | |||
275 | ac97c_workdata = ctx; | ||
276 | return 0; | ||
277 | |||
278 | |||
279 | snd_soc_unregister_dai(&pdev->dev); | ||
280 | out1: | ||
281 | release_mem_region(r->start, resource_size(r)); | ||
282 | out0: | ||
283 | kfree(ctx); | ||
284 | return ret; | ||
285 | } | ||
286 | |||
287 | static int __devexit au1xac97c_drvremove(struct platform_device *pdev) | ||
288 | { | ||
289 | struct au1xpsc_audio_data *ctx = platform_get_drvdata(pdev); | ||
290 | struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
291 | |||
292 | snd_soc_unregister_dai(&pdev->dev); | ||
293 | |||
294 | WR(ctx, AC97_ENABLE, EN_D); /* clock off, disable */ | ||
295 | |||
296 | iounmap(ctx->mmio); | ||
297 | release_mem_region(r->start, resource_size(r)); | ||
298 | kfree(ctx); | ||
299 | |||
300 | ac97c_workdata = NULL; /* MDEV */ | ||
301 | |||
302 | return 0; | ||
303 | } | ||
304 | |||
305 | #ifdef CONFIG_PM | ||
306 | static int au1xac97c_drvsuspend(struct device *dev) | ||
307 | { | ||
308 | struct au1xpsc_audio_data *ctx = dev_get_drvdata(dev); | ||
309 | |||
310 | WR(ctx, AC97_ENABLE, EN_D); /* clock off, disable */ | ||
311 | |||
312 | return 0; | ||
313 | } | ||
314 | |||
315 | static int au1xac97c_drvresume(struct device *dev) | ||
316 | { | ||
317 | struct au1xpsc_audio_data *ctx = dev_get_drvdata(dev); | ||
318 | |||
319 | WR(ctx, AC97_ENABLE, EN_D | EN_CE); | ||
320 | WR(ctx, AC97_ENABLE, EN_CE); | ||
321 | WR(ctx, AC97_CONFIG, ctx->cfg); | ||
322 | |||
323 | return 0; | ||
324 | } | ||
325 | |||
326 | static const struct dev_pm_ops au1xpscac97_pmops = { | ||
327 | .suspend = au1xac97c_drvsuspend, | ||
328 | .resume = au1xac97c_drvresume, | ||
329 | }; | ||
330 | |||
331 | #define AU1XPSCAC97_PMOPS (&au1xpscac97_pmops) | ||
332 | |||
333 | #else | ||
334 | |||
335 | #define AU1XPSCAC97_PMOPS NULL | ||
336 | |||
337 | #endif | ||
338 | |||
339 | static struct platform_driver au1xac97c_driver = { | ||
340 | .driver = { | ||
341 | .name = "alchemy-ac97c", | ||
342 | .owner = THIS_MODULE, | ||
343 | .pm = AU1XPSCAC97_PMOPS, | ||
344 | }, | ||
345 | .probe = au1xac97c_drvprobe, | ||
346 | .remove = __devexit_p(au1xac97c_drvremove), | ||
347 | }; | ||
348 | |||
349 | static int __init au1xac97c_load(void) | ||
350 | { | ||
351 | ac97c_workdata = NULL; | ||
352 | return platform_driver_register(&au1xac97c_driver); | ||
353 | } | ||
354 | |||
355 | static void __exit au1xac97c_unload(void) | ||
356 | { | ||
357 | platform_driver_unregister(&au1xac97c_driver); | ||
358 | } | ||
359 | |||
360 | module_init(au1xac97c_load); | ||
361 | module_exit(au1xac97c_unload); | ||
362 | |||
363 | MODULE_LICENSE("GPL"); | ||
364 | MODULE_DESCRIPTION("Au1000/1500/1100 AC97C ASoC driver"); | ||
365 | MODULE_AUTHOR("Manuel Lauss"); | ||
diff --git a/sound/soc/au1x/dma.c b/sound/soc/au1x/dma.c new file mode 100644 index 000000000000..7aa5b7606777 --- /dev/null +++ b/sound/soc/au1x/dma.c | |||
@@ -0,0 +1,377 @@ | |||
1 | /* | ||
2 | * Au1000/Au1500/Au1100 Audio DMA support. | ||
3 | * | ||
4 | * (c) 2011 Manuel Lauss <manuel.lauss@googlemail.com> | ||
5 | * | ||
6 | * copied almost verbatim from the old ALSA driver, written by | ||
7 | * Charles Eidsness <charles@cooper-street.com> | ||
8 | */ | ||
9 | |||
10 | #include <linux/module.h> | ||
11 | #include <linux/init.h> | ||
12 | #include <linux/platform_device.h> | ||
13 | #include <linux/slab.h> | ||
14 | #include <linux/dma-mapping.h> | ||
15 | #include <sound/core.h> | ||
16 | #include <sound/pcm.h> | ||
17 | #include <sound/pcm_params.h> | ||
18 | #include <sound/soc.h> | ||
19 | #include <asm/mach-au1x00/au1000.h> | ||
20 | #include <asm/mach-au1x00/au1000_dma.h> | ||
21 | |||
22 | #include "psc.h" | ||
23 | |||
24 | #define ALCHEMY_PCM_FMTS \ | ||
25 | (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8 | \ | ||
26 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | \ | ||
27 | SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE | \ | ||
28 | SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE | \ | ||
29 | SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE | \ | ||
30 | 0) | ||
31 | |||
32 | struct pcm_period { | ||
33 | u32 start; | ||
34 | u32 relative_end; /* relative to start of buffer */ | ||
35 | struct pcm_period *next; | ||
36 | }; | ||
37 | |||
38 | struct audio_stream { | ||
39 | struct snd_pcm_substream *substream; | ||
40 | int dma; | ||
41 | struct pcm_period *buffer; | ||
42 | unsigned int period_size; | ||
43 | unsigned int periods; | ||
44 | }; | ||
45 | |||
46 | struct alchemy_pcm_ctx { | ||
47 | struct audio_stream stream[2]; /* playback & capture */ | ||
48 | }; | ||
49 | |||
50 | static void au1000_release_dma_link(struct audio_stream *stream) | ||
51 | { | ||
52 | struct pcm_period *pointer; | ||
53 | struct pcm_period *pointer_next; | ||
54 | |||
55 | stream->period_size = 0; | ||
56 | stream->periods = 0; | ||
57 | pointer = stream->buffer; | ||
58 | if (!pointer) | ||
59 | return; | ||
60 | do { | ||
61 | pointer_next = pointer->next; | ||
62 | kfree(pointer); | ||
63 | pointer = pointer_next; | ||
64 | } while (pointer != stream->buffer); | ||
65 | stream->buffer = NULL; | ||
66 | } | ||
67 | |||
68 | static int au1000_setup_dma_link(struct audio_stream *stream, | ||
69 | unsigned int period_bytes, | ||
70 | unsigned int periods) | ||
71 | { | ||
72 | struct snd_pcm_substream *substream = stream->substream; | ||
73 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
74 | struct pcm_period *pointer; | ||
75 | unsigned long dma_start; | ||
76 | int i; | ||
77 | |||
78 | dma_start = virt_to_phys(runtime->dma_area); | ||
79 | |||
80 | if (stream->period_size == period_bytes && | ||
81 | stream->periods == periods) | ||
82 | return 0; /* not changed */ | ||
83 | |||
84 | au1000_release_dma_link(stream); | ||
85 | |||
86 | stream->period_size = period_bytes; | ||
87 | stream->periods = periods; | ||
88 | |||
89 | stream->buffer = kmalloc(sizeof(struct pcm_period), GFP_KERNEL); | ||
90 | if (!stream->buffer) | ||
91 | return -ENOMEM; | ||
92 | pointer = stream->buffer; | ||
93 | for (i = 0; i < periods; i++) { | ||
94 | pointer->start = (u32)(dma_start + (i * period_bytes)); | ||
95 | pointer->relative_end = (u32) (((i+1) * period_bytes) - 0x1); | ||
96 | if (i < periods - 1) { | ||
97 | pointer->next = kmalloc(sizeof(struct pcm_period), | ||
98 | GFP_KERNEL); | ||
99 | if (!pointer->next) { | ||
100 | au1000_release_dma_link(stream); | ||
101 | return -ENOMEM; | ||
102 | } | ||
103 | pointer = pointer->next; | ||
104 | } | ||
105 | } | ||
106 | pointer->next = stream->buffer; | ||
107 | return 0; | ||
108 | } | ||
109 | |||
110 | static void au1000_dma_stop(struct audio_stream *stream) | ||
111 | { | ||
112 | if (stream->buffer) | ||
113 | disable_dma(stream->dma); | ||
114 | } | ||
115 | |||
116 | static void au1000_dma_start(struct audio_stream *stream) | ||
117 | { | ||
118 | if (!stream->buffer) | ||
119 | return; | ||
120 | |||
121 | init_dma(stream->dma); | ||
122 | if (get_dma_active_buffer(stream->dma) == 0) { | ||
123 | clear_dma_done0(stream->dma); | ||
124 | set_dma_addr0(stream->dma, stream->buffer->start); | ||
125 | set_dma_count0(stream->dma, stream->period_size >> 1); | ||
126 | set_dma_addr1(stream->dma, stream->buffer->next->start); | ||
127 | set_dma_count1(stream->dma, stream->period_size >> 1); | ||
128 | } else { | ||
129 | clear_dma_done1(stream->dma); | ||
130 | set_dma_addr1(stream->dma, stream->buffer->start); | ||
131 | set_dma_count1(stream->dma, stream->period_size >> 1); | ||
132 | set_dma_addr0(stream->dma, stream->buffer->next->start); | ||
133 | set_dma_count0(stream->dma, stream->period_size >> 1); | ||
134 | } | ||
135 | enable_dma_buffers(stream->dma); | ||
136 | start_dma(stream->dma); | ||
137 | } | ||
138 | |||
139 | static irqreturn_t au1000_dma_interrupt(int irq, void *ptr) | ||
140 | { | ||
141 | struct audio_stream *stream = (struct audio_stream *)ptr; | ||
142 | struct snd_pcm_substream *substream = stream->substream; | ||
143 | |||
144 | switch (get_dma_buffer_done(stream->dma)) { | ||
145 | case DMA_D0: | ||
146 | stream->buffer = stream->buffer->next; | ||
147 | clear_dma_done0(stream->dma); | ||
148 | set_dma_addr0(stream->dma, stream->buffer->next->start); | ||
149 | set_dma_count0(stream->dma, stream->period_size >> 1); | ||
150 | enable_dma_buffer0(stream->dma); | ||
151 | break; | ||
152 | case DMA_D1: | ||
153 | stream->buffer = stream->buffer->next; | ||
154 | clear_dma_done1(stream->dma); | ||
155 | set_dma_addr1(stream->dma, stream->buffer->next->start); | ||
156 | set_dma_count1(stream->dma, stream->period_size >> 1); | ||
157 | enable_dma_buffer1(stream->dma); | ||
158 | break; | ||
159 | case (DMA_D0 | DMA_D1): | ||
160 | pr_debug("DMA %d missed interrupt.\n", stream->dma); | ||
161 | au1000_dma_stop(stream); | ||
162 | au1000_dma_start(stream); | ||
163 | break; | ||
164 | case (~DMA_D0 & ~DMA_D1): | ||
165 | pr_debug("DMA %d empty irq.\n", stream->dma); | ||
166 | } | ||
167 | snd_pcm_period_elapsed(substream); | ||
168 | return IRQ_HANDLED; | ||
169 | } | ||
170 | |||
171 | static const struct snd_pcm_hardware alchemy_pcm_hardware = { | ||
172 | .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | | ||
173 | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BATCH, | ||
174 | .formats = ALCHEMY_PCM_FMTS, | ||
175 | .rates = SNDRV_PCM_RATE_8000_192000, | ||
176 | .rate_min = SNDRV_PCM_RATE_8000, | ||
177 | .rate_max = SNDRV_PCM_RATE_192000, | ||
178 | .channels_min = 2, | ||
179 | .channels_max = 2, | ||
180 | .period_bytes_min = 1024, | ||
181 | .period_bytes_max = 16 * 1024 - 1, | ||
182 | .periods_min = 4, | ||
183 | .periods_max = 255, | ||
184 | .buffer_bytes_max = 128 * 1024, | ||
185 | .fifo_size = 16, | ||
186 | }; | ||
187 | |||
188 | static inline struct alchemy_pcm_ctx *ss_to_ctx(struct snd_pcm_substream *ss) | ||
189 | { | ||
190 | struct snd_soc_pcm_runtime *rtd = ss->private_data; | ||
191 | return snd_soc_platform_get_drvdata(rtd->platform); | ||
192 | } | ||
193 | |||
194 | static inline struct audio_stream *ss_to_as(struct snd_pcm_substream *ss) | ||
195 | { | ||
196 | struct alchemy_pcm_ctx *ctx = ss_to_ctx(ss); | ||
197 | return &(ctx->stream[ss->stream]); | ||
198 | } | ||
199 | |||
200 | static int alchemy_pcm_open(struct snd_pcm_substream *substream) | ||
201 | { | ||
202 | struct alchemy_pcm_ctx *ctx = ss_to_ctx(substream); | ||
203 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
204 | int *dmaids, s = substream->stream; | ||
205 | char *name; | ||
206 | |||
207 | dmaids = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream); | ||
208 | if (!dmaids) | ||
209 | return -ENODEV; /* whoa, has ordering changed? */ | ||
210 | |||
211 | /* DMA setup */ | ||
212 | name = (s == SNDRV_PCM_STREAM_PLAYBACK) ? "audio-tx" : "audio-rx"; | ||
213 | ctx->stream[s].dma = request_au1000_dma(dmaids[s], name, | ||
214 | au1000_dma_interrupt, IRQF_DISABLED, | ||
215 | &ctx->stream[s]); | ||
216 | set_dma_mode(ctx->stream[s].dma, | ||
217 | get_dma_mode(ctx->stream[s].dma) & ~DMA_NC); | ||
218 | |||
219 | ctx->stream[s].substream = substream; | ||
220 | ctx->stream[s].buffer = NULL; | ||
221 | snd_soc_set_runtime_hwparams(substream, &alchemy_pcm_hardware); | ||
222 | |||
223 | return 0; | ||
224 | } | ||
225 | |||
226 | static int alchemy_pcm_close(struct snd_pcm_substream *substream) | ||
227 | { | ||
228 | struct alchemy_pcm_ctx *ctx = ss_to_ctx(substream); | ||
229 | int stype = substream->stream; | ||
230 | |||
231 | ctx->stream[stype].substream = NULL; | ||
232 | free_au1000_dma(ctx->stream[stype].dma); | ||
233 | |||
234 | return 0; | ||
235 | } | ||
236 | |||
237 | static int alchemy_pcm_hw_params(struct snd_pcm_substream *substream, | ||
238 | struct snd_pcm_hw_params *hw_params) | ||
239 | { | ||
240 | struct audio_stream *stream = ss_to_as(substream); | ||
241 | int err; | ||
242 | |||
243 | err = snd_pcm_lib_malloc_pages(substream, | ||
244 | params_buffer_bytes(hw_params)); | ||
245 | if (err < 0) | ||
246 | return err; | ||
247 | err = au1000_setup_dma_link(stream, | ||
248 | params_period_bytes(hw_params), | ||
249 | params_periods(hw_params)); | ||
250 | if (err) | ||
251 | snd_pcm_lib_free_pages(substream); | ||
252 | |||
253 | return err; | ||
254 | } | ||
255 | |||
256 | static int alchemy_pcm_hw_free(struct snd_pcm_substream *substream) | ||
257 | { | ||
258 | struct audio_stream *stream = ss_to_as(substream); | ||
259 | au1000_release_dma_link(stream); | ||
260 | return snd_pcm_lib_free_pages(substream); | ||
261 | } | ||
262 | |||
263 | static int alchemy_pcm_trigger(struct snd_pcm_substream *substream, int cmd) | ||
264 | { | ||
265 | struct audio_stream *stream = ss_to_as(substream); | ||
266 | int err = 0; | ||
267 | |||
268 | switch (cmd) { | ||
269 | case SNDRV_PCM_TRIGGER_START: | ||
270 | au1000_dma_start(stream); | ||
271 | break; | ||
272 | case SNDRV_PCM_TRIGGER_STOP: | ||
273 | au1000_dma_stop(stream); | ||
274 | break; | ||
275 | default: | ||
276 | err = -EINVAL; | ||
277 | break; | ||
278 | } | ||
279 | return err; | ||
280 | } | ||
281 | |||
282 | static snd_pcm_uframes_t alchemy_pcm_pointer(struct snd_pcm_substream *ss) | ||
283 | { | ||
284 | struct audio_stream *stream = ss_to_as(ss); | ||
285 | long location; | ||
286 | |||
287 | location = get_dma_residue(stream->dma); | ||
288 | location = stream->buffer->relative_end - location; | ||
289 | if (location == -1) | ||
290 | location = 0; | ||
291 | return bytes_to_frames(ss->runtime, location); | ||
292 | } | ||
293 | |||
294 | static struct snd_pcm_ops alchemy_pcm_ops = { | ||
295 | .open = alchemy_pcm_open, | ||
296 | .close = alchemy_pcm_close, | ||
297 | .ioctl = snd_pcm_lib_ioctl, | ||
298 | .hw_params = alchemy_pcm_hw_params, | ||
299 | .hw_free = alchemy_pcm_hw_free, | ||
300 | .trigger = alchemy_pcm_trigger, | ||
301 | .pointer = alchemy_pcm_pointer, | ||
302 | }; | ||
303 | |||
304 | static void alchemy_pcm_free_dma_buffers(struct snd_pcm *pcm) | ||
305 | { | ||
306 | snd_pcm_lib_preallocate_free_for_all(pcm); | ||
307 | } | ||
308 | |||
309 | static int alchemy_pcm_new(struct snd_soc_pcm_runtime *rtd) | ||
310 | { | ||
311 | struct snd_pcm *pcm = rtd->pcm; | ||
312 | |||
313 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS, | ||
314 | snd_dma_continuous_data(GFP_KERNEL), 65536, (4096 * 1024) - 1); | ||
315 | |||
316 | return 0; | ||
317 | } | ||
318 | |||
319 | struct snd_soc_platform_driver alchemy_pcm_soc_platform = { | ||
320 | .ops = &alchemy_pcm_ops, | ||
321 | .pcm_new = alchemy_pcm_new, | ||
322 | .pcm_free = alchemy_pcm_free_dma_buffers, | ||
323 | }; | ||
324 | |||
325 | static int __devinit alchemy_pcm_drvprobe(struct platform_device *pdev) | ||
326 | { | ||
327 | struct alchemy_pcm_ctx *ctx; | ||
328 | int ret; | ||
329 | |||
330 | ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); | ||
331 | if (!ctx) | ||
332 | return -ENOMEM; | ||
333 | |||
334 | platform_set_drvdata(pdev, ctx); | ||
335 | |||
336 | ret = snd_soc_register_platform(&pdev->dev, &alchemy_pcm_soc_platform); | ||
337 | if (ret) | ||
338 | kfree(ctx); | ||
339 | |||
340 | return ret; | ||
341 | } | ||
342 | |||
343 | static int __devexit alchemy_pcm_drvremove(struct platform_device *pdev) | ||
344 | { | ||
345 | struct alchemy_pcm_ctx *ctx = platform_get_drvdata(pdev); | ||
346 | |||
347 | snd_soc_unregister_platform(&pdev->dev); | ||
348 | kfree(ctx); | ||
349 | |||
350 | return 0; | ||
351 | } | ||
352 | |||
353 | static struct platform_driver alchemy_pcmdma_driver = { | ||
354 | .driver = { | ||
355 | .name = "alchemy-pcm-dma", | ||
356 | .owner = THIS_MODULE, | ||
357 | }, | ||
358 | .probe = alchemy_pcm_drvprobe, | ||
359 | .remove = __devexit_p(alchemy_pcm_drvremove), | ||
360 | }; | ||
361 | |||
362 | static int __init alchemy_pcmdma_load(void) | ||
363 | { | ||
364 | return platform_driver_register(&alchemy_pcmdma_driver); | ||
365 | } | ||
366 | |||
367 | static void __exit alchemy_pcmdma_unload(void) | ||
368 | { | ||
369 | platform_driver_unregister(&alchemy_pcmdma_driver); | ||
370 | } | ||
371 | |||
372 | module_init(alchemy_pcmdma_load); | ||
373 | module_exit(alchemy_pcmdma_unload); | ||
374 | |||
375 | MODULE_LICENSE("GPL"); | ||
376 | MODULE_DESCRIPTION("Au1000/Au1500/Au1100 Audio DMA driver"); | ||
377 | MODULE_AUTHOR("Manuel Lauss"); | ||
diff --git a/sound/soc/au1x/i2sc.c b/sound/soc/au1x/i2sc.c new file mode 100644 index 000000000000..b4172fdd2c48 --- /dev/null +++ b/sound/soc/au1x/i2sc.c | |||
@@ -0,0 +1,347 @@ | |||
1 | /* | ||
2 | * Au1000/Au1500/Au1100 I2S controller driver for ASoC | ||
3 | * | ||
4 | * (c) 2011 Manuel Lauss <manuel.lauss@googlemail.com> | ||
5 | * | ||
6 | * Note: clock supplied to the I2S controller must be 256x samplerate. | ||
7 | */ | ||
8 | |||
9 | #include <linux/init.h> | ||
10 | #include <linux/module.h> | ||
11 | #include <linux/slab.h> | ||
12 | #include <linux/suspend.h> | ||
13 | #include <sound/core.h> | ||
14 | #include <sound/pcm.h> | ||
15 | #include <sound/initval.h> | ||
16 | #include <sound/soc.h> | ||
17 | #include <asm/mach-au1x00/au1000.h> | ||
18 | |||
19 | #include "psc.h" | ||
20 | |||
21 | #define I2S_RXTX 0x00 | ||
22 | #define I2S_CFG 0x04 | ||
23 | #define I2S_ENABLE 0x08 | ||
24 | |||
25 | #define CFG_XU (1 << 25) /* tx underflow */ | ||
26 | #define CFG_XO (1 << 24) | ||
27 | #define CFG_RU (1 << 23) | ||
28 | #define CFG_RO (1 << 22) | ||
29 | #define CFG_TR (1 << 21) | ||
30 | #define CFG_TE (1 << 20) | ||
31 | #define CFG_TF (1 << 19) | ||
32 | #define CFG_RR (1 << 18) | ||
33 | #define CFG_RF (1 << 17) | ||
34 | #define CFG_ICK (1 << 12) /* clock invert */ | ||
35 | #define CFG_PD (1 << 11) /* set to make I2SDIO INPUT */ | ||
36 | #define CFG_LB (1 << 10) /* loopback */ | ||
37 | #define CFG_IC (1 << 9) /* word select invert */ | ||
38 | #define CFG_FM_I2S (0 << 7) /* I2S format */ | ||
39 | #define CFG_FM_LJ (1 << 7) /* left-justified */ | ||
40 | #define CFG_FM_RJ (2 << 7) /* right-justified */ | ||
41 | #define CFG_FM_MASK (3 << 7) | ||
42 | #define CFG_TN (1 << 6) /* tx fifo en */ | ||
43 | #define CFG_RN (1 << 5) /* rx fifo en */ | ||
44 | #define CFG_SZ_8 (0x08) | ||
45 | #define CFG_SZ_16 (0x10) | ||
46 | #define CFG_SZ_18 (0x12) | ||
47 | #define CFG_SZ_20 (0x14) | ||
48 | #define CFG_SZ_24 (0x18) | ||
49 | #define CFG_SZ_MASK (0x1f) | ||
50 | #define EN_D (1 << 1) /* DISable */ | ||
51 | #define EN_CE (1 << 0) /* clock enable */ | ||
52 | |||
53 | /* only limited by clock generator and board design */ | ||
54 | #define AU1XI2SC_RATES \ | ||
55 | SNDRV_PCM_RATE_CONTINUOUS | ||
56 | |||
57 | #define AU1XI2SC_FMTS \ | ||
58 | (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8 | \ | ||
59 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | \ | ||
60 | SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE | \ | ||
61 | SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_U18_3LE | \ | ||
62 | SNDRV_PCM_FMTBIT_S18_3BE | SNDRV_PCM_FMTBIT_U18_3BE | \ | ||
63 | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_U20_3LE | \ | ||
64 | SNDRV_PCM_FMTBIT_S20_3BE | SNDRV_PCM_FMTBIT_U20_3BE | \ | ||
65 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE | \ | ||
66 | SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE | \ | ||
67 | 0) | ||
68 | |||
69 | static inline unsigned long RD(struct au1xpsc_audio_data *ctx, int reg) | ||
70 | { | ||
71 | return __raw_readl(ctx->mmio + reg); | ||
72 | } | ||
73 | |||
74 | static inline void WR(struct au1xpsc_audio_data *ctx, int reg, unsigned long v) | ||
75 | { | ||
76 | __raw_writel(v, ctx->mmio + reg); | ||
77 | wmb(); | ||
78 | } | ||
79 | |||
80 | static int au1xi2s_set_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt) | ||
81 | { | ||
82 | struct au1xpsc_audio_data *ctx = snd_soc_dai_get_drvdata(cpu_dai); | ||
83 | unsigned long c; | ||
84 | int ret; | ||
85 | |||
86 | ret = -EINVAL; | ||
87 | c = ctx->cfg; | ||
88 | |||
89 | c &= ~CFG_FM_MASK; | ||
90 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | ||
91 | case SND_SOC_DAIFMT_I2S: | ||
92 | c |= CFG_FM_I2S; | ||
93 | break; | ||
94 | case SND_SOC_DAIFMT_MSB: | ||
95 | c |= CFG_FM_RJ; | ||
96 | break; | ||
97 | case SND_SOC_DAIFMT_LSB: | ||
98 | c |= CFG_FM_LJ; | ||
99 | break; | ||
100 | default: | ||
101 | goto out; | ||
102 | } | ||
103 | |||
104 | c &= ~(CFG_IC | CFG_ICK); /* IB-IF */ | ||
105 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { | ||
106 | case SND_SOC_DAIFMT_NB_NF: | ||
107 | c |= CFG_IC | CFG_ICK; | ||
108 | break; | ||
109 | case SND_SOC_DAIFMT_NB_IF: | ||
110 | c |= CFG_IC; | ||
111 | break; | ||
112 | case SND_SOC_DAIFMT_IB_NF: | ||
113 | c |= CFG_ICK; | ||
114 | break; | ||
115 | case SND_SOC_DAIFMT_IB_IF: | ||
116 | break; | ||
117 | default: | ||
118 | goto out; | ||
119 | } | ||
120 | |||
121 | /* I2S controller only supports master */ | ||
122 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | ||
123 | case SND_SOC_DAIFMT_CBS_CFS: /* CODEC slave */ | ||
124 | break; | ||
125 | default: | ||
126 | goto out; | ||
127 | } | ||
128 | |||
129 | ret = 0; | ||
130 | ctx->cfg = c; | ||
131 | out: | ||
132 | return ret; | ||
133 | } | ||
134 | |||
135 | static int au1xi2s_trigger(struct snd_pcm_substream *substream, | ||
136 | int cmd, struct snd_soc_dai *dai) | ||
137 | { | ||
138 | struct au1xpsc_audio_data *ctx = snd_soc_dai_get_drvdata(dai); | ||
139 | int stype = SUBSTREAM_TYPE(substream); | ||
140 | |||
141 | switch (cmd) { | ||
142 | case SNDRV_PCM_TRIGGER_START: | ||
143 | case SNDRV_PCM_TRIGGER_RESUME: | ||
144 | /* power up */ | ||
145 | WR(ctx, I2S_ENABLE, EN_D | EN_CE); | ||
146 | WR(ctx, I2S_ENABLE, EN_CE); | ||
147 | ctx->cfg |= (stype == PCM_TX) ? CFG_TN : CFG_RN; | ||
148 | WR(ctx, I2S_CFG, ctx->cfg); | ||
149 | break; | ||
150 | case SNDRV_PCM_TRIGGER_STOP: | ||
151 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
152 | ctx->cfg &= ~((stype == PCM_TX) ? CFG_TN : CFG_RN); | ||
153 | WR(ctx, I2S_CFG, ctx->cfg); | ||
154 | WR(ctx, I2S_ENABLE, EN_D); /* power off */ | ||
155 | break; | ||
156 | default: | ||
157 | return -EINVAL; | ||
158 | } | ||
159 | |||
160 | return 0; | ||
161 | } | ||
162 | |||
163 | static unsigned long msbits_to_reg(int msbits) | ||
164 | { | ||
165 | switch (msbits) { | ||
166 | case 8: | ||
167 | return CFG_SZ_8; | ||
168 | case 16: | ||
169 | return CFG_SZ_16; | ||
170 | case 18: | ||
171 | return CFG_SZ_18; | ||
172 | case 20: | ||
173 | return CFG_SZ_20; | ||
174 | case 24: | ||
175 | return CFG_SZ_24; | ||
176 | } | ||
177 | return 0; | ||
178 | } | ||
179 | |||
180 | static int au1xi2s_hw_params(struct snd_pcm_substream *substream, | ||
181 | struct snd_pcm_hw_params *params, | ||
182 | struct snd_soc_dai *dai) | ||
183 | { | ||
184 | struct au1xpsc_audio_data *ctx = snd_soc_dai_get_drvdata(dai); | ||
185 | unsigned long v; | ||
186 | |||
187 | v = msbits_to_reg(params->msbits); | ||
188 | if (!v) | ||
189 | return -EINVAL; | ||
190 | |||
191 | ctx->cfg &= ~CFG_SZ_MASK; | ||
192 | ctx->cfg |= v; | ||
193 | return 0; | ||
194 | } | ||
195 | |||
196 | static int au1xi2s_startup(struct snd_pcm_substream *substream, | ||
197 | struct snd_soc_dai *dai) | ||
198 | { | ||
199 | struct au1xpsc_audio_data *ctx = snd_soc_dai_get_drvdata(dai); | ||
200 | snd_soc_dai_set_dma_data(dai, substream, &ctx->dmaids[0]); | ||
201 | return 0; | ||
202 | } | ||
203 | |||
204 | static const struct snd_soc_dai_ops au1xi2s_dai_ops = { | ||
205 | .startup = au1xi2s_startup, | ||
206 | .trigger = au1xi2s_trigger, | ||
207 | .hw_params = au1xi2s_hw_params, | ||
208 | .set_fmt = au1xi2s_set_fmt, | ||
209 | }; | ||
210 | |||
211 | static struct snd_soc_dai_driver au1xi2s_dai_driver = { | ||
212 | .symmetric_rates = 1, | ||
213 | .playback = { | ||
214 | .rates = AU1XI2SC_RATES, | ||
215 | .formats = AU1XI2SC_FMTS, | ||
216 | .channels_min = 2, | ||
217 | .channels_max = 2, | ||
218 | }, | ||
219 | .capture = { | ||
220 | .rates = AU1XI2SC_RATES, | ||
221 | .formats = AU1XI2SC_FMTS, | ||
222 | .channels_min = 2, | ||
223 | .channels_max = 2, | ||
224 | }, | ||
225 | .ops = &au1xi2s_dai_ops, | ||
226 | }; | ||
227 | |||
228 | static int __devinit au1xi2s_drvprobe(struct platform_device *pdev) | ||
229 | { | ||
230 | int ret; | ||
231 | struct resource *r; | ||
232 | struct au1xpsc_audio_data *ctx; | ||
233 | |||
234 | ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); | ||
235 | if (!ctx) | ||
236 | return -ENOMEM; | ||
237 | |||
238 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
239 | if (!r) { | ||
240 | ret = -ENODEV; | ||
241 | goto out0; | ||
242 | } | ||
243 | |||
244 | ret = -EBUSY; | ||
245 | if (!request_mem_region(r->start, resource_size(r), pdev->name)) | ||
246 | goto out0; | ||
247 | |||
248 | ctx->mmio = ioremap_nocache(r->start, resource_size(r)); | ||
249 | if (!ctx->mmio) | ||
250 | goto out1; | ||
251 | |||
252 | r = platform_get_resource(pdev, IORESOURCE_DMA, 0); | ||
253 | if (!r) | ||
254 | goto out1; | ||
255 | ctx->dmaids[SNDRV_PCM_STREAM_PLAYBACK] = r->start; | ||
256 | |||
257 | r = platform_get_resource(pdev, IORESOURCE_DMA, 1); | ||
258 | if (!r) | ||
259 | goto out1; | ||
260 | ctx->dmaids[SNDRV_PCM_STREAM_CAPTURE] = r->start; | ||
261 | |||
262 | platform_set_drvdata(pdev, ctx); | ||
263 | |||
264 | ret = snd_soc_register_dai(&pdev->dev, &au1xi2s_dai_driver); | ||
265 | if (ret) | ||
266 | goto out1; | ||
267 | |||
268 | return 0; | ||
269 | |||
270 | snd_soc_unregister_dai(&pdev->dev); | ||
271 | out1: | ||
272 | release_mem_region(r->start, resource_size(r)); | ||
273 | out0: | ||
274 | kfree(ctx); | ||
275 | return ret; | ||
276 | } | ||
277 | |||
278 | static int __devexit au1xi2s_drvremove(struct platform_device *pdev) | ||
279 | { | ||
280 | struct au1xpsc_audio_data *ctx = platform_get_drvdata(pdev); | ||
281 | struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
282 | |||
283 | snd_soc_unregister_dai(&pdev->dev); | ||
284 | |||
285 | WR(ctx, I2S_ENABLE, EN_D); /* clock off, disable */ | ||
286 | |||
287 | iounmap(ctx->mmio); | ||
288 | release_mem_region(r->start, resource_size(r)); | ||
289 | kfree(ctx); | ||
290 | |||
291 | return 0; | ||
292 | } | ||
293 | |||
294 | #ifdef CONFIG_PM | ||
295 | static int au1xi2s_drvsuspend(struct device *dev) | ||
296 | { | ||
297 | struct au1xpsc_audio_data *ctx = dev_get_drvdata(dev); | ||
298 | |||
299 | WR(ctx, I2S_ENABLE, EN_D); /* clock off, disable */ | ||
300 | |||
301 | return 0; | ||
302 | } | ||
303 | |||
304 | static int au1xi2s_drvresume(struct device *dev) | ||
305 | { | ||
306 | return 0; | ||
307 | } | ||
308 | |||
309 | static const struct dev_pm_ops au1xi2sc_pmops = { | ||
310 | .suspend = au1xi2s_drvsuspend, | ||
311 | .resume = au1xi2s_drvresume, | ||
312 | }; | ||
313 | |||
314 | #define AU1XI2SC_PMOPS (&au1xi2sc_pmops) | ||
315 | |||
316 | #else | ||
317 | |||
318 | #define AU1XI2SC_PMOPS NULL | ||
319 | |||
320 | #endif | ||
321 | |||
322 | static struct platform_driver au1xi2s_driver = { | ||
323 | .driver = { | ||
324 | .name = "alchemy-i2sc", | ||
325 | .owner = THIS_MODULE, | ||
326 | .pm = AU1XI2SC_PMOPS, | ||
327 | }, | ||
328 | .probe = au1xi2s_drvprobe, | ||
329 | .remove = __devexit_p(au1xi2s_drvremove), | ||
330 | }; | ||
331 | |||
332 | static int __init au1xi2s_load(void) | ||
333 | { | ||
334 | return platform_driver_register(&au1xi2s_driver); | ||
335 | } | ||
336 | |||
337 | static void __exit au1xi2s_unload(void) | ||
338 | { | ||
339 | platform_driver_unregister(&au1xi2s_driver); | ||
340 | } | ||
341 | |||
342 | module_init(au1xi2s_load); | ||
343 | module_exit(au1xi2s_unload); | ||
344 | |||
345 | MODULE_LICENSE("GPL"); | ||
346 | MODULE_DESCRIPTION("Au1000/1500/1100 I2S ASoC driver"); | ||
347 | MODULE_AUTHOR("Manuel Lauss"); | ||
diff --git a/sound/soc/au1x/psc.h b/sound/soc/au1x/psc.h index b30eadd422a7..c59b9e544e72 100644 --- a/sound/soc/au1x/psc.h +++ b/sound/soc/au1x/psc.h | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * Au12x0/Au1550 PSC ALSA ASoC audio support. | 2 | * Alchemy ALSA ASoC audio support. |
3 | * | 3 | * |
4 | * (c) 2007-2008 MSC Vertriebsges.m.b.H., | 4 | * (c) 2007-2011 MSC Vertriebsges.m.b.H., |
5 | * Manuel Lauss <manuel.lauss@gmail.com> | 5 | * Manuel Lauss <manuel.lauss@gmail.com> |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify |
@@ -13,7 +13,13 @@ | |||
13 | #ifndef _AU1X_PCM_H | 13 | #ifndef _AU1X_PCM_H |
14 | #define _AU1X_PCM_H | 14 | #define _AU1X_PCM_H |
15 | 15 | ||
16 | /* DBDMA helpers */ | 16 | #define PCM_TX 0 |
17 | #define PCM_RX 1 | ||
18 | |||
19 | #define SUBSTREAM_TYPE(substream) \ | ||
20 | ((substream)->stream == SNDRV_PCM_STREAM_PLAYBACK ? PCM_TX : PCM_RX) | ||
21 | |||
22 | /* PSC/DBDMA helpers */ | ||
17 | extern struct platform_device *au1xpsc_pcm_add(struct platform_device *pdev); | 23 | extern struct platform_device *au1xpsc_pcm_add(struct platform_device *pdev); |
18 | extern void au1xpsc_pcm_destroy(struct platform_device *dmapd); | 24 | extern void au1xpsc_pcm_destroy(struct platform_device *dmapd); |
19 | 25 | ||
@@ -27,15 +33,10 @@ struct au1xpsc_audio_data { | |||
27 | 33 | ||
28 | unsigned long pm[2]; | 34 | unsigned long pm[2]; |
29 | struct mutex lock; | 35 | struct mutex lock; |
36 | int dmaids[2]; | ||
30 | struct platform_device *dmapd; | 37 | struct platform_device *dmapd; |
31 | }; | 38 | }; |
32 | 39 | ||
33 | #define PCM_TX 0 | ||
34 | #define PCM_RX 1 | ||
35 | |||
36 | #define SUBSTREAM_TYPE(substream) \ | ||
37 | ((substream)->stream == SNDRV_PCM_STREAM_PLAYBACK ? PCM_TX : PCM_RX) | ||
38 | |||
39 | /* easy access macros */ | 40 | /* easy access macros */ |
40 | #define PSC_CTRL(x) ((unsigned long)((x)->mmio) + PSC_CTRL_OFFSET) | 41 | #define PSC_CTRL(x) ((unsigned long)((x)->mmio) + PSC_CTRL_OFFSET) |
41 | #define PSC_SEL(x) ((unsigned long)((x)->mmio) + PSC_SEL_OFFSET) | 42 | #define PSC_SEL(x) ((unsigned long)((x)->mmio) + PSC_SEL_OFFSET) |