aboutsummaryrefslogtreecommitdiffstats
path: root/sound/arm
diff options
context:
space:
mode:
Diffstat (limited to 'sound/arm')
-rw-r--r--sound/arm/Kconfig9
-rw-r--r--sound/arm/Makefile4
-rw-r--r--sound/arm/aaci.c6
-rw-r--r--sound/arm/pxa2xx-ac97-lib.c384
-rw-r--r--sound/arm/pxa2xx-ac97.c251
-rw-r--r--sound/arm/pxa2xx-pcm-lib.c278
-rw-r--r--sound/arm/pxa2xx-pcm.c252
-rw-r--r--sound/arm/pxa2xx-pcm.h13
-rw-r--r--sound/arm/sa11xx-uda1341.c7
9 files changed, 717 insertions, 487 deletions
diff --git a/sound/arm/Kconfig b/sound/arm/Kconfig
index 351e19ea3785..f8e6de48d816 100644
--- a/sound/arm/Kconfig
+++ b/sound/arm/Kconfig
@@ -32,11 +32,20 @@ config SND_PXA2XX_PCM
32 tristate 32 tristate
33 select SND_PCM 33 select SND_PCM
34 34
35config SND_PXA2XX_LIB
36 tristate
37 select SND_AC97_CODEC if SND_PXA2XX_LIB_AC97
38
39config SND_PXA2XX_LIB_AC97
40 bool
41
35config SND_PXA2XX_AC97 42config SND_PXA2XX_AC97
36 tristate "AC97 driver for the Intel PXA2xx chip" 43 tristate "AC97 driver for the Intel PXA2xx chip"
37 depends on ARCH_PXA 44 depends on ARCH_PXA
38 select SND_PXA2XX_PCM 45 select SND_PXA2XX_PCM
39 select SND_AC97_CODEC 46 select SND_AC97_CODEC
47 select SND_PXA2XX_LIB
48 select SND_PXA2XX_LIB_AC97
40 help 49 help
41 Say Y or M if you want to support any AC97 codec attached to 50 Say Y or M if you want to support any AC97 codec attached to
42 the PXA2xx AC97 interface. 51 the PXA2xx AC97 interface.
diff --git a/sound/arm/Makefile b/sound/arm/Makefile
index 4ef6dd00c6ee..2054de11de8a 100644
--- a/sound/arm/Makefile
+++ b/sound/arm/Makefile
@@ -11,5 +11,9 @@ snd-aaci-objs := aaci.o devdma.o
11obj-$(CONFIG_SND_PXA2XX_PCM) += snd-pxa2xx-pcm.o 11obj-$(CONFIG_SND_PXA2XX_PCM) += snd-pxa2xx-pcm.o
12snd-pxa2xx-pcm-objs := pxa2xx-pcm.o 12snd-pxa2xx-pcm-objs := pxa2xx-pcm.o
13 13
14obj-$(CONFIG_SND_PXA2XX_LIB) += snd-pxa2xx-lib.o
15snd-pxa2xx-lib-y := pxa2xx-pcm-lib.o
16snd-pxa2xx-lib-$(CONFIG_SND_PXA2XX_LIB_AC97) += pxa2xx-ac97-lib.o
17
14obj-$(CONFIG_SND_PXA2XX_AC97) += snd-pxa2xx-ac97.o 18obj-$(CONFIG_SND_PXA2XX_AC97) += snd-pxa2xx-ac97.o
15snd-pxa2xx-ac97-objs := pxa2xx-ac97.o 19snd-pxa2xx-ac97-objs := pxa2xx-ac97.o
diff --git a/sound/arm/aaci.c b/sound/arm/aaci.c
index b0a474494966..89096e811a4b 100644
--- a/sound/arm/aaci.c
+++ b/sound/arm/aaci.c
@@ -999,7 +999,7 @@ static struct aaci * __devinit aaci_init_card(struct amba_device *dev)
999 card = snd_card_new(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, 999 card = snd_card_new(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
1000 THIS_MODULE, sizeof(struct aaci)); 1000 THIS_MODULE, sizeof(struct aaci));
1001 if (card == NULL) 1001 if (card == NULL)
1002 return ERR_PTR(-ENOMEM); 1002 return NULL;
1003 1003
1004 card->private_free = aaci_free_card; 1004 card->private_free = aaci_free_card;
1005 1005
@@ -1083,8 +1083,8 @@ static int __devinit aaci_probe(struct amba_device *dev, void *id)
1083 return ret; 1083 return ret;
1084 1084
1085 aaci = aaci_init_card(dev); 1085 aaci = aaci_init_card(dev);
1086 if (IS_ERR(aaci)) { 1086 if (!aaci) {
1087 ret = PTR_ERR(aaci); 1087 ret = -ENOMEM;
1088 goto out; 1088 goto out;
1089 } 1089 }
1090 1090
diff --git a/sound/arm/pxa2xx-ac97-lib.c b/sound/arm/pxa2xx-ac97-lib.c
new file mode 100644
index 000000000000..34c1d94f921e
--- /dev/null
+++ b/sound/arm/pxa2xx-ac97-lib.c
@@ -0,0 +1,384 @@
1/*
2 * Based on sound/arm/pxa2xx-ac97.c and sound/soc/pxa/pxa2xx-ac97.c
3 * which contain:
4 *
5 * Author: Nicolas Pitre
6 * Created: Dec 02, 2004
7 * Copyright: MontaVista Software Inc.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/kernel.h>
15#include <linux/platform_device.h>
16#include <linux/interrupt.h>
17#include <linux/clk.h>
18#include <linux/delay.h>
19
20#include <sound/ac97_codec.h>
21#include <sound/pxa2xx-lib.h>
22
23#include <asm/irq.h>
24#include <mach/hardware.h>
25#include <mach/pxa-regs.h>
26#include <mach/pxa2xx-gpio.h>
27#include <mach/audio.h>
28
29static DEFINE_MUTEX(car_mutex);
30static DECLARE_WAIT_QUEUE_HEAD(gsr_wq);
31static volatile long gsr_bits;
32static struct clk *ac97_clk;
33static struct clk *ac97conf_clk;
34
35/*
36 * Beware PXA27x bugs:
37 *
38 * o Slot 12 read from modem space will hang controller.
39 * o CDONE, SDONE interrupt fails after any slot 12 IO.
40 *
41 * We therefore have an hybrid approach for waiting on SDONE (interrupt or
42 * 1 jiffy timeout if interrupt never comes).
43 */
44
45unsigned short pxa2xx_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
46{
47 unsigned short val = -1;
48 volatile u32 *reg_addr;
49
50 mutex_lock(&car_mutex);
51
52 /* set up primary or secondary codec space */
53 if (cpu_is_pxa25x() && reg == AC97_GPIO_STATUS)
54 reg_addr = ac97->num ? &SMC_REG_BASE : &PMC_REG_BASE;
55 else
56 reg_addr = ac97->num ? &SAC_REG_BASE : &PAC_REG_BASE;
57 reg_addr += (reg >> 1);
58
59 /* start read access across the ac97 link */
60 GSR = GSR_CDONE | GSR_SDONE;
61 gsr_bits = 0;
62 val = *reg_addr;
63 if (reg == AC97_GPIO_STATUS)
64 goto out;
65 if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1) <= 0 &&
66 !((GSR | gsr_bits) & GSR_SDONE)) {
67 printk(KERN_ERR "%s: read error (ac97_reg=%d GSR=%#lx)\n",
68 __func__, reg, GSR | gsr_bits);
69 val = -1;
70 goto out;
71 }
72
73 /* valid data now */
74 GSR = GSR_CDONE | GSR_SDONE;
75 gsr_bits = 0;
76 val = *reg_addr;
77 /* but we've just started another cycle... */
78 wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1);
79
80out: mutex_unlock(&car_mutex);
81 return val;
82}
83EXPORT_SYMBOL_GPL(pxa2xx_ac97_read);
84
85void pxa2xx_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
86 unsigned short val)
87{
88 volatile u32 *reg_addr;
89
90 mutex_lock(&car_mutex);
91
92 /* set up primary or secondary codec space */
93 if (cpu_is_pxa25x() && reg == AC97_GPIO_STATUS)
94 reg_addr = ac97->num ? &SMC_REG_BASE : &PMC_REG_BASE;
95 else
96 reg_addr = ac97->num ? &SAC_REG_BASE : &PAC_REG_BASE;
97 reg_addr += (reg >> 1);
98
99 GSR = GSR_CDONE | GSR_SDONE;
100 gsr_bits = 0;
101 *reg_addr = val;
102 if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_CDONE, 1) <= 0 &&
103 !((GSR | gsr_bits) & GSR_CDONE))
104 printk(KERN_ERR "%s: write error (ac97_reg=%d GSR=%#lx)\n",
105 __func__, reg, GSR | gsr_bits);
106
107 mutex_unlock(&car_mutex);
108}
109EXPORT_SYMBOL_GPL(pxa2xx_ac97_write);
110
111#ifdef CONFIG_PXA25x
112static inline void pxa_ac97_warm_pxa25x(void)
113{
114 gsr_bits = 0;
115
116 GCR |= GCR_WARM_RST | GCR_PRIRDY_IEN | GCR_SECRDY_IEN;
117 wait_event_timeout(gsr_wq, gsr_bits & (GSR_PCR | GSR_SCR), 1);
118}
119
120static inline void pxa_ac97_cold_pxa25x(void)
121{
122 GCR &= GCR_COLD_RST; /* clear everything but nCRST */
123 GCR &= ~GCR_COLD_RST; /* then assert nCRST */
124
125 gsr_bits = 0;
126
127 GCR = GCR_COLD_RST;
128 GCR |= GCR_CDONE_IE|GCR_SDONE_IE;
129 wait_event_timeout(gsr_wq, gsr_bits & (GSR_PCR | GSR_SCR), 1);
130}
131#endif
132
133#ifdef CONFIG_PXA27x
134static inline void pxa_ac97_warm_pxa27x(void)
135{
136 gsr_bits = 0;
137
138 /* warm reset broken on Bulverde,
139 so manually keep AC97 reset high */
140 pxa_gpio_mode(113 | GPIO_OUT | GPIO_DFLT_HIGH);
141 udelay(10);
142 GCR |= GCR_WARM_RST;
143 pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT);
144 udelay(500);
145}
146
147static inline void pxa_ac97_cold_pxa27x(void)
148{
149 GCR &= GCR_COLD_RST; /* clear everything but nCRST */
150 GCR &= ~GCR_COLD_RST; /* then assert nCRST */
151
152 gsr_bits = 0;
153
154 /* PXA27x Developers Manual section 13.5.2.2.1 */
155 clk_enable(ac97conf_clk);
156 udelay(5);
157 clk_disable(ac97conf_clk);
158 GCR = GCR_COLD_RST;
159 udelay(50);
160}
161#endif
162
163#ifdef CONFIG_PXA3xx
164static inline void pxa_ac97_warm_pxa3xx(void)
165{
166 int timeout = 100;
167
168 gsr_bits = 0;
169
170 /* Can't use interrupts */
171 GCR |= GCR_WARM_RST;
172 while (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)) && timeout--)
173 mdelay(1);
174}
175
176static inline void pxa_ac97_cold_pxa3xx(void)
177{
178 int timeout = 1000;
179
180 /* Hold CLKBPB for 100us */
181 GCR = 0;
182 GCR = GCR_CLKBPB;
183 udelay(100);
184 GCR = 0;
185
186 GCR &= GCR_COLD_RST; /* clear everything but nCRST */
187 GCR &= ~GCR_COLD_RST; /* then assert nCRST */
188
189 gsr_bits = 0;
190
191 /* Can't use interrupts on PXA3xx */
192 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
193
194 GCR = GCR_WARM_RST | GCR_COLD_RST;
195 while (!(GSR & (GSR_PCR | GSR_SCR)) && timeout--)
196 mdelay(10);
197}
198#endif
199
200bool pxa2xx_ac97_try_warm_reset(struct snd_ac97 *ac97)
201{
202#ifdef CONFIG_PXA25x
203 if (cpu_is_pxa25x())
204 pxa_ac97_warm_pxa25x();
205 else
206#endif
207#ifdef CONFIG_PXA27x
208 if (cpu_is_pxa27x())
209 pxa_ac97_warm_pxa27x();
210 else
211#endif
212#ifdef CONFIG_PXA3xx
213 if (cpu_is_pxa3xx())
214 pxa_ac97_warm_pxa3xx();
215 else
216#endif
217 BUG();
218
219 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR))) {
220 printk(KERN_INFO "%s: warm reset timeout (GSR=%#lx)\n",
221 __func__, gsr_bits);
222
223 return false;
224 }
225
226 return true;
227}
228EXPORT_SYMBOL_GPL(pxa2xx_ac97_try_warm_reset);
229
230bool pxa2xx_ac97_try_cold_reset(struct snd_ac97 *ac97)
231{
232#ifdef CONFIG_PXA25x
233 if (cpu_is_pxa25x())
234 pxa_ac97_cold_pxa25x();
235 else
236#endif
237#ifdef CONFIG_PXA27x
238 if (cpu_is_pxa27x())
239 pxa_ac97_cold_pxa27x();
240 else
241#endif
242#ifdef CONFIG_PXA3xx
243 if (cpu_is_pxa3xx())
244 pxa_ac97_cold_pxa3xx();
245 else
246#endif
247 BUG();
248
249 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR))) {
250 printk(KERN_INFO "%s: cold reset timeout (GSR=%#lx)\n",
251 __func__, gsr_bits);
252
253 return false;
254 }
255
256 return true;
257}
258EXPORT_SYMBOL_GPL(pxa2xx_ac97_try_cold_reset);
259
260
261void pxa2xx_ac97_finish_reset(struct snd_ac97 *ac97)
262{
263 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
264 GCR |= GCR_SDONE_IE|GCR_CDONE_IE;
265}
266EXPORT_SYMBOL_GPL(pxa2xx_ac97_finish_reset);
267
268static irqreturn_t pxa2xx_ac97_irq(int irq, void *dev_id)
269{
270 long status;
271
272 status = GSR;
273 if (status) {
274 GSR = status;
275 gsr_bits |= status;
276 wake_up(&gsr_wq);
277
278 /* Although we don't use those we still need to clear them
279 since they tend to spuriously trigger when MMC is used
280 (hardware bug? go figure)... */
281 if (cpu_is_pxa27x()) {
282 MISR = MISR_EOC;
283 PISR = PISR_EOC;
284 MCSR = MCSR_EOC;
285 }
286
287 return IRQ_HANDLED;
288 }
289
290 return IRQ_NONE;
291}
292
293#ifdef CONFIG_PM
294int pxa2xx_ac97_hw_suspend(void)
295{
296 GCR |= GCR_ACLINK_OFF;
297 clk_disable(ac97_clk);
298 return 0;
299}
300EXPORT_SYMBOL_GPL(pxa2xx_ac97_hw_suspend);
301
302int pxa2xx_ac97_hw_resume(void)
303{
304 if (cpu_is_pxa25x() || cpu_is_pxa27x()) {
305 pxa_gpio_mode(GPIO31_SYNC_AC97_MD);
306 pxa_gpio_mode(GPIO30_SDATA_OUT_AC97_MD);
307 pxa_gpio_mode(GPIO28_BITCLK_AC97_MD);
308 pxa_gpio_mode(GPIO29_SDATA_IN_AC97_MD);
309 }
310 if (cpu_is_pxa27x()) {
311 /* Use GPIO 113 as AC97 Reset on Bulverde */
312 pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT);
313 }
314 clk_enable(ac97_clk);
315 return 0;
316}
317EXPORT_SYMBOL_GPL(pxa2xx_ac97_hw_resume);
318#endif
319
320int __devinit pxa2xx_ac97_hw_probe(struct platform_device *dev)
321{
322 int ret;
323
324 ret = request_irq(IRQ_AC97, pxa2xx_ac97_irq, 0, "AC97", NULL);
325 if (ret < 0)
326 goto err;
327
328 if (cpu_is_pxa25x() || cpu_is_pxa27x()) {
329 pxa_gpio_mode(GPIO31_SYNC_AC97_MD);
330 pxa_gpio_mode(GPIO30_SDATA_OUT_AC97_MD);
331 pxa_gpio_mode(GPIO28_BITCLK_AC97_MD);
332 pxa_gpio_mode(GPIO29_SDATA_IN_AC97_MD);
333 }
334
335 if (cpu_is_pxa27x()) {
336 /* Use GPIO 113 as AC97 Reset on Bulverde */
337 pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT);
338 ac97conf_clk = clk_get(&dev->dev, "AC97CONFCLK");
339 if (IS_ERR(ac97conf_clk)) {
340 ret = PTR_ERR(ac97conf_clk);
341 ac97conf_clk = NULL;
342 goto err_irq;
343 }
344 }
345
346 ac97_clk = clk_get(&dev->dev, "AC97CLK");
347 if (IS_ERR(ac97_clk)) {
348 ret = PTR_ERR(ac97_clk);
349 ac97_clk = NULL;
350 goto err_irq;
351 }
352
353 return clk_enable(ac97_clk);
354
355err_irq:
356 GCR |= GCR_ACLINK_OFF;
357 if (ac97conf_clk) {
358 clk_put(ac97conf_clk);
359 ac97conf_clk = NULL;
360 }
361 free_irq(IRQ_AC97, NULL);
362err:
363 return ret;
364}
365EXPORT_SYMBOL_GPL(pxa2xx_ac97_hw_probe);
366
367void pxa2xx_ac97_hw_remove(struct platform_device *dev)
368{
369 GCR |= GCR_ACLINK_OFF;
370 free_irq(IRQ_AC97, NULL);
371 if (ac97conf_clk) {
372 clk_put(ac97conf_clk);
373 ac97conf_clk = NULL;
374 }
375 clk_disable(ac97_clk);
376 clk_put(ac97_clk);
377 ac97_clk = NULL;
378}
379EXPORT_SYMBOL_GPL(pxa2xx_ac97_hw_remove);
380
381MODULE_AUTHOR("Nicolas Pitre");
382MODULE_DESCRIPTION("Intel/Marvell PXA sound library");
383MODULE_LICENSE("GPL");
384
diff --git a/sound/arm/pxa2xx-ac97.c b/sound/arm/pxa2xx-ac97.c
index 199cca3366df..c2635beb4c88 100644
--- a/sound/arm/pxa2xx-ac97.c
+++ b/sound/arm/pxa2xx-ac97.c
@@ -12,198 +12,27 @@
12 12
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/kernel.h>
16#include <linux/platform_device.h> 15#include <linux/platform_device.h>
17#include <linux/interrupt.h>
18#include <linux/wait.h>
19#include <linux/clk.h>
20#include <linux/delay.h>
21 16
22#include <sound/core.h> 17#include <sound/core.h>
23#include <sound/pcm.h> 18#include <sound/pcm.h>
24#include <sound/ac97_codec.h> 19#include <sound/ac97_codec.h>
25#include <sound/initval.h> 20#include <sound/initval.h>
21#include <sound/pxa2xx-lib.h>
26 22
27#include <asm/irq.h>
28#include <linux/mutex.h>
29#include <mach/hardware.h> 23#include <mach/hardware.h>
30#include <mach/pxa-regs.h> 24#include <mach/pxa-regs.h>
31#include <mach/pxa2xx-gpio.h>
32#include <mach/audio.h> 25#include <mach/audio.h>
33 26
34#include "pxa2xx-pcm.h" 27#include "pxa2xx-pcm.h"
35 28
36
37static DEFINE_MUTEX(car_mutex);
38static DECLARE_WAIT_QUEUE_HEAD(gsr_wq);
39static volatile long gsr_bits;
40static struct clk *ac97_clk;
41#ifdef CONFIG_PXA27x
42static struct clk *ac97conf_clk;
43#endif
44
45/*
46 * Beware PXA27x bugs:
47 *
48 * o Slot 12 read from modem space will hang controller.
49 * o CDONE, SDONE interrupt fails after any slot 12 IO.
50 *
51 * We therefore have an hybrid approach for waiting on SDONE (interrupt or
52 * 1 jiffy timeout if interrupt never comes).
53 */
54
55static unsigned short pxa2xx_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
56{
57 unsigned short val = -1;
58 volatile u32 *reg_addr;
59
60 mutex_lock(&car_mutex);
61
62 /* set up primary or secondary codec space */
63 reg_addr = (ac97->num & 1) ? &SAC_REG_BASE : &PAC_REG_BASE;
64 reg_addr += (reg >> 1);
65
66 /* start read access across the ac97 link */
67 GSR = GSR_CDONE | GSR_SDONE;
68 gsr_bits = 0;
69 val = *reg_addr;
70 if (reg == AC97_GPIO_STATUS)
71 goto out;
72 if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1) <= 0 &&
73 !((GSR | gsr_bits) & GSR_SDONE)) {
74 printk(KERN_ERR "%s: read error (ac97_reg=%d GSR=%#lx)\n",
75 __func__, reg, GSR | gsr_bits);
76 val = -1;
77 goto out;
78 }
79
80 /* valid data now */
81 GSR = GSR_CDONE | GSR_SDONE;
82 gsr_bits = 0;
83 val = *reg_addr;
84 /* but we've just started another cycle... */
85 wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1);
86
87out: mutex_unlock(&car_mutex);
88 return val;
89}
90
91static void pxa2xx_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short val)
92{
93 volatile u32 *reg_addr;
94
95 mutex_lock(&car_mutex);
96
97 /* set up primary or secondary codec space */
98 reg_addr = (ac97->num & 1) ? &SAC_REG_BASE : &PAC_REG_BASE;
99 reg_addr += (reg >> 1);
100
101 GSR = GSR_CDONE | GSR_SDONE;
102 gsr_bits = 0;
103 *reg_addr = val;
104 if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_CDONE, 1) <= 0 &&
105 !((GSR | gsr_bits) & GSR_CDONE))
106 printk(KERN_ERR "%s: write error (ac97_reg=%d GSR=%#lx)\n",
107 __func__, reg, GSR | gsr_bits);
108
109 mutex_unlock(&car_mutex);
110}
111
112static void pxa2xx_ac97_reset(struct snd_ac97 *ac97) 29static void pxa2xx_ac97_reset(struct snd_ac97 *ac97)
113{ 30{
114 /* First, try cold reset */ 31 if (!pxa2xx_ac97_try_cold_reset(ac97)) {
115#ifdef CONFIG_PXA3xx 32 pxa2xx_ac97_try_warm_reset(ac97);
116 int timeout;
117
118 /* Hold CLKBPB for 100us */
119 GCR = 0;
120 GCR = GCR_CLKBPB;
121 udelay(100);
122 GCR = 0;
123#endif
124
125 GCR &= GCR_COLD_RST; /* clear everything but nCRST */
126 GCR &= ~GCR_COLD_RST; /* then assert nCRST */
127
128 gsr_bits = 0;
129#ifdef CONFIG_PXA27x
130 /* PXA27x Developers Manual section 13.5.2.2.1 */
131 clk_enable(ac97conf_clk);
132 udelay(5);
133 clk_disable(ac97conf_clk);
134 GCR = GCR_COLD_RST;
135 udelay(50);
136#elif defined(CONFIG_PXA3xx)
137 timeout = 1000;
138 /* Can't use interrupts on PXA3xx */
139 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
140
141 GCR = GCR_WARM_RST | GCR_COLD_RST;
142 while (!(GSR & (GSR_PCR | GSR_SCR)) && timeout--)
143 mdelay(10);
144#else
145 GCR = GCR_COLD_RST;
146 GCR |= GCR_CDONE_IE|GCR_SDONE_IE;
147 wait_event_timeout(gsr_wq, gsr_bits & (GSR_PCR | GSR_SCR), 1);
148#endif
149
150 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR))) {
151 printk(KERN_INFO "%s: cold reset timeout (GSR=%#lx)\n",
152 __func__, gsr_bits);
153
154 /* let's try warm reset */
155 gsr_bits = 0;
156#ifdef CONFIG_PXA27x
157 /* warm reset broken on Bulverde,
158 so manually keep AC97 reset high */
159 pxa_gpio_mode(113 | GPIO_OUT | GPIO_DFLT_HIGH);
160 udelay(10);
161 GCR |= GCR_WARM_RST;
162 pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT);
163 udelay(500);
164#elif defined(CONFIG_PXA3xx)
165 timeout = 100;
166 /* Can't use interrupts */
167 GCR |= GCR_WARM_RST;
168 while (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)) && timeout--)
169 mdelay(1);
170#else
171 GCR |= GCR_WARM_RST|GCR_PRIRDY_IEN|GCR_SECRDY_IEN;
172 wait_event_timeout(gsr_wq, gsr_bits & (GSR_PCR | GSR_SCR), 1);
173#endif
174
175 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)))
176 printk(KERN_INFO "%s: warm reset timeout (GSR=%#lx)\n",
177 __func__, gsr_bits);
178 }
179
180 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
181 GCR |= GCR_SDONE_IE|GCR_CDONE_IE;
182}
183
184static irqreturn_t pxa2xx_ac97_irq(int irq, void *dev_id)
185{
186 long status;
187
188 status = GSR;
189 if (status) {
190 GSR = status;
191 gsr_bits |= status;
192 wake_up(&gsr_wq);
193
194#ifdef CONFIG_PXA27x
195 /* Although we don't use those we still need to clear them
196 since they tend to spuriously trigger when MMC is used
197 (hardware bug? go figure)... */
198 MISR = MISR_EOC;
199 PISR = PISR_EOC;
200 MCSR = MCSR_EOC;
201#endif
202
203 return IRQ_HANDLED;
204 } 33 }
205 34
206 return IRQ_NONE; 35 pxa2xx_ac97_finish_reset(ac97);
207} 36}
208 37
209static struct snd_ac97_bus_ops pxa2xx_ac97_ops = { 38static struct snd_ac97_bus_ops pxa2xx_ac97_ops = {
@@ -215,7 +44,7 @@ static struct snd_ac97_bus_ops pxa2xx_ac97_ops = {
215static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_out = { 44static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_out = {
216 .name = "AC97 PCM out", 45 .name = "AC97 PCM out",
217 .dev_addr = __PREG(PCDR), 46 .dev_addr = __PREG(PCDR),
218 .drcmr = &DRCMRTXPCDR, 47 .drcmr = &DRCMR(12),
219 .dcmd = DCMD_INCSRCADDR | DCMD_FLOWTRG | 48 .dcmd = DCMD_INCSRCADDR | DCMD_FLOWTRG |
220 DCMD_BURST32 | DCMD_WIDTH4, 49 DCMD_BURST32 | DCMD_WIDTH4,
221}; 50};
@@ -223,7 +52,7 @@ static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_out = {
223static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_in = { 52static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_in = {
224 .name = "AC97 PCM in", 53 .name = "AC97 PCM in",
225 .dev_addr = __PREG(PCDR), 54 .dev_addr = __PREG(PCDR),
226 .drcmr = &DRCMRRXPCDR, 55 .drcmr = &DRCMR(11),
227 .dcmd = DCMD_INCTRGADDR | DCMD_FLOWSRC | 56 .dcmd = DCMD_INCTRGADDR | DCMD_FLOWSRC |
228 DCMD_BURST32 | DCMD_WIDTH4, 57 DCMD_BURST32 | DCMD_WIDTH4,
229}; 58};
@@ -288,17 +117,19 @@ static int pxa2xx_ac97_do_suspend(struct snd_card *card, pm_message_t state)
288 snd_ac97_suspend(pxa2xx_ac97_ac97); 117 snd_ac97_suspend(pxa2xx_ac97_ac97);
289 if (platform_ops && platform_ops->suspend) 118 if (platform_ops && platform_ops->suspend)
290 platform_ops->suspend(platform_ops->priv); 119 platform_ops->suspend(platform_ops->priv);
291 GCR |= GCR_ACLINK_OFF;
292 clk_disable(ac97_clk);
293 120
294 return 0; 121 return pxa2xx_ac97_hw_suspend();
295} 122}
296 123
297static int pxa2xx_ac97_do_resume(struct snd_card *card) 124static int pxa2xx_ac97_do_resume(struct snd_card *card)
298{ 125{
299 pxa2xx_audio_ops_t *platform_ops = card->dev->platform_data; 126 pxa2xx_audio_ops_t *platform_ops = card->dev->platform_data;
127 int rc;
128
129 rc = pxa2xx_ac97_hw_resume();
130 if (rc)
131 return rc;
300 132
301 clk_enable(ac97_clk);
302 if (platform_ops && platform_ops->resume) 133 if (platform_ops && platform_ops->resume)
303 platform_ops->resume(platform_ops->priv); 134 platform_ops->resume(platform_ops->priv);
304 snd_ac97_resume(pxa2xx_ac97_ac97); 135 snd_ac97_resume(pxa2xx_ac97_ac97);
@@ -354,40 +185,17 @@ static int __devinit pxa2xx_ac97_probe(struct platform_device *dev)
354 if (ret) 185 if (ret)
355 goto err; 186 goto err;
356 187
357 ret = request_irq(IRQ_AC97, pxa2xx_ac97_irq, 0, "AC97", NULL); 188 ret = pxa2xx_ac97_hw_probe(dev);
358 if (ret < 0) 189 if (ret)
359 goto err;
360
361 pxa_gpio_mode(GPIO31_SYNC_AC97_MD);
362 pxa_gpio_mode(GPIO30_SDATA_OUT_AC97_MD);
363 pxa_gpio_mode(GPIO28_BITCLK_AC97_MD);
364 pxa_gpio_mode(GPIO29_SDATA_IN_AC97_MD);
365#ifdef CONFIG_PXA27x
366 /* Use GPIO 113 as AC97 Reset on Bulverde */
367 pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT);
368 ac97conf_clk = clk_get(&dev->dev, "AC97CONFCLK");
369 if (IS_ERR(ac97conf_clk)) {
370 ret = PTR_ERR(ac97conf_clk);
371 ac97conf_clk = NULL;
372 goto err;
373 }
374#endif
375
376 ac97_clk = clk_get(&dev->dev, "AC97CLK");
377 if (IS_ERR(ac97_clk)) {
378 ret = PTR_ERR(ac97_clk);
379 ac97_clk = NULL;
380 goto err; 190 goto err;
381 }
382 clk_enable(ac97_clk);
383 191
384 ret = snd_ac97_bus(card, 0, &pxa2xx_ac97_ops, NULL, &ac97_bus); 192 ret = snd_ac97_bus(card, 0, &pxa2xx_ac97_ops, NULL, &ac97_bus);
385 if (ret) 193 if (ret)
386 goto err; 194 goto err_remove;
387 memset(&ac97_template, 0, sizeof(ac97_template)); 195 memset(&ac97_template, 0, sizeof(ac97_template));
388 ret = snd_ac97_mixer(ac97_bus, &ac97_template, &pxa2xx_ac97_ac97); 196 ret = snd_ac97_mixer(ac97_bus, &ac97_template, &pxa2xx_ac97_ac97);
389 if (ret) 197 if (ret)
390 goto err; 198 goto err_remove;
391 199
392 snprintf(card->shortname, sizeof(card->shortname), 200 snprintf(card->shortname, sizeof(card->shortname),
393 "%s", snd_ac97_get_short_name(pxa2xx_ac97_ac97)); 201 "%s", snd_ac97_get_short_name(pxa2xx_ac97_ac97));
@@ -401,22 +209,11 @@ static int __devinit pxa2xx_ac97_probe(struct platform_device *dev)
401 return 0; 209 return 0;
402 } 210 }
403 211
404 err: 212err_remove:
213 pxa2xx_ac97_hw_remove(dev);
214err:
405 if (card) 215 if (card)
406 snd_card_free(card); 216 snd_card_free(card);
407 if (ac97_clk) {
408 GCR |= GCR_ACLINK_OFF;
409 free_irq(IRQ_AC97, NULL);
410 clk_disable(ac97_clk);
411 clk_put(ac97_clk);
412 ac97_clk = NULL;
413 }
414#ifdef CONFIG_PXA27x
415 if (ac97conf_clk) {
416 clk_put(ac97conf_clk);
417 ac97conf_clk = NULL;
418 }
419#endif
420 return ret; 217 return ret;
421} 218}
422 219
@@ -427,15 +224,7 @@ static int __devexit pxa2xx_ac97_remove(struct platform_device *dev)
427 if (card) { 224 if (card) {
428 snd_card_free(card); 225 snd_card_free(card);
429 platform_set_drvdata(dev, NULL); 226 platform_set_drvdata(dev, NULL);
430 GCR |= GCR_ACLINK_OFF; 227 pxa2xx_ac97_hw_remove(dev);
431 free_irq(IRQ_AC97, NULL);
432 clk_disable(ac97_clk);
433 clk_put(ac97_clk);
434 ac97_clk = NULL;
435#ifdef CONFIG_PXA27x
436 clk_put(ac97conf_clk);
437 ac97conf_clk = NULL;
438#endif
439 } 228 }
440 229
441 return 0; 230 return 0;
diff --git a/sound/arm/pxa2xx-pcm-lib.c b/sound/arm/pxa2xx-pcm-lib.c
new file mode 100644
index 000000000000..1c93eb77cb99
--- /dev/null
+++ b/sound/arm/pxa2xx-pcm-lib.c
@@ -0,0 +1,278 @@
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation.
5 */
6
7#include <linux/module.h>
8#include <linux/dma-mapping.h>
9
10#include <sound/core.h>
11#include <sound/pcm.h>
12#include <sound/pcm_params.h>
13#include <sound/pxa2xx-lib.h>
14
15#include <asm/dma.h>
16#include <mach/pxa-regs.h>
17
18#include "pxa2xx-pcm.h"
19
20static const struct snd_pcm_hardware pxa2xx_pcm_hardware = {
21 .info = SNDRV_PCM_INFO_MMAP |
22 SNDRV_PCM_INFO_MMAP_VALID |
23 SNDRV_PCM_INFO_INTERLEAVED |
24 SNDRV_PCM_INFO_PAUSE |
25 SNDRV_PCM_INFO_RESUME,
26 .formats = SNDRV_PCM_FMTBIT_S16_LE |
27 SNDRV_PCM_FMTBIT_S24_LE |
28 SNDRV_PCM_FMTBIT_S32_LE,
29 .period_bytes_min = 32,
30 .period_bytes_max = 8192 - 32,
31 .periods_min = 1,
32 .periods_max = PAGE_SIZE/sizeof(pxa_dma_desc),
33 .buffer_bytes_max = 128 * 1024,
34 .fifo_size = 32,
35};
36
37int __pxa2xx_pcm_hw_params(struct snd_pcm_substream *substream,
38 struct snd_pcm_hw_params *params)
39{
40 struct snd_pcm_runtime *runtime = substream->runtime;
41 struct pxa2xx_runtime_data *rtd = runtime->private_data;
42 size_t totsize = params_buffer_bytes(params);
43 size_t period = params_period_bytes(params);
44 pxa_dma_desc *dma_desc;
45 dma_addr_t dma_buff_phys, next_desc_phys;
46
47 snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
48 runtime->dma_bytes = totsize;
49
50 dma_desc = rtd->dma_desc_array;
51 next_desc_phys = rtd->dma_desc_array_phys;
52 dma_buff_phys = runtime->dma_addr;
53 do {
54 next_desc_phys += sizeof(pxa_dma_desc);
55 dma_desc->ddadr = next_desc_phys;
56 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
57 dma_desc->dsadr = dma_buff_phys;
58 dma_desc->dtadr = rtd->params->dev_addr;
59 } else {
60 dma_desc->dsadr = rtd->params->dev_addr;
61 dma_desc->dtadr = dma_buff_phys;
62 }
63 if (period > totsize)
64 period = totsize;
65 dma_desc->dcmd = rtd->params->dcmd | period | DCMD_ENDIRQEN;
66 dma_desc++;
67 dma_buff_phys += period;
68 } while (totsize -= period);
69 dma_desc[-1].ddadr = rtd->dma_desc_array_phys;
70
71 return 0;
72}
73EXPORT_SYMBOL(__pxa2xx_pcm_hw_params);
74
75int __pxa2xx_pcm_hw_free(struct snd_pcm_substream *substream)
76{
77 struct pxa2xx_runtime_data *rtd = substream->runtime->private_data;
78
79 if (rtd && rtd->params)
80 *rtd->params->drcmr = 0;
81
82 snd_pcm_set_runtime_buffer(substream, NULL);
83 return 0;
84}
85EXPORT_SYMBOL(__pxa2xx_pcm_hw_free);
86
87int pxa2xx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
88{
89 struct pxa2xx_runtime_data *prtd = substream->runtime->private_data;
90 int ret = 0;
91
92 switch (cmd) {
93 case SNDRV_PCM_TRIGGER_START:
94 DDADR(prtd->dma_ch) = prtd->dma_desc_array_phys;
95 DCSR(prtd->dma_ch) = DCSR_RUN;
96 break;
97
98 case SNDRV_PCM_TRIGGER_STOP:
99 case SNDRV_PCM_TRIGGER_SUSPEND:
100 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
101 DCSR(prtd->dma_ch) &= ~DCSR_RUN;
102 break;
103
104 case SNDRV_PCM_TRIGGER_RESUME:
105 DCSR(prtd->dma_ch) |= DCSR_RUN;
106 break;
107 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
108 DDADR(prtd->dma_ch) = prtd->dma_desc_array_phys;
109 DCSR(prtd->dma_ch) |= DCSR_RUN;
110 break;
111
112 default:
113 ret = -EINVAL;
114 }
115
116 return ret;
117}
118EXPORT_SYMBOL(pxa2xx_pcm_trigger);
119
120snd_pcm_uframes_t
121pxa2xx_pcm_pointer(struct snd_pcm_substream *substream)
122{
123 struct snd_pcm_runtime *runtime = substream->runtime;
124 struct pxa2xx_runtime_data *prtd = runtime->private_data;
125
126 dma_addr_t ptr = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
127 DSADR(prtd->dma_ch) : DTADR(prtd->dma_ch);
128 snd_pcm_uframes_t x = bytes_to_frames(runtime, ptr - runtime->dma_addr);
129
130 if (x == runtime->buffer_size)
131 x = 0;
132 return x;
133}
134EXPORT_SYMBOL(pxa2xx_pcm_pointer);
135
136int __pxa2xx_pcm_prepare(struct snd_pcm_substream *substream)
137{
138 struct pxa2xx_runtime_data *prtd = substream->runtime->private_data;
139
140 DCSR(prtd->dma_ch) &= ~DCSR_RUN;
141 DCSR(prtd->dma_ch) = 0;
142 DCMD(prtd->dma_ch) = 0;
143 *prtd->params->drcmr = prtd->dma_ch | DRCMR_MAPVLD;
144
145 return 0;
146}
147EXPORT_SYMBOL(__pxa2xx_pcm_prepare);
148
149void pxa2xx_pcm_dma_irq(int dma_ch, void *dev_id)
150{
151 struct snd_pcm_substream *substream = dev_id;
152 struct pxa2xx_runtime_data *rtd = substream->runtime->private_data;
153 int dcsr;
154
155 dcsr = DCSR(dma_ch);
156 DCSR(dma_ch) = dcsr & ~DCSR_STOPIRQEN;
157
158 if (dcsr & DCSR_ENDINTR) {
159 snd_pcm_period_elapsed(substream);
160 } else {
161 printk(KERN_ERR "%s: DMA error on channel %d (DCSR=%#x)\n",
162 rtd->params->name, dma_ch, dcsr);
163 snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
164 }
165}
166EXPORT_SYMBOL(pxa2xx_pcm_dma_irq);
167
168int __pxa2xx_pcm_open(struct snd_pcm_substream *substream)
169{
170 struct snd_pcm_runtime *runtime = substream->runtime;
171 struct pxa2xx_runtime_data *rtd;
172 int ret;
173
174 runtime->hw = pxa2xx_pcm_hardware;
175
176 /*
177 * For mysterious reasons (and despite what the manual says)
178 * playback samples are lost if the DMA count is not a multiple
179 * of the DMA burst size. Let's add a rule to enforce that.
180 */
181 ret = snd_pcm_hw_constraint_step(runtime, 0,
182 SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 32);
183 if (ret)
184 goto out;
185
186 ret = snd_pcm_hw_constraint_step(runtime, 0,
187 SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 32);
188 if (ret)
189 goto out;
190
191 ret = snd_pcm_hw_constraint_integer(runtime,
192 SNDRV_PCM_HW_PARAM_PERIODS);
193 if (ret < 0)
194 goto out;
195
196 ret = -ENOMEM;
197 rtd = kmalloc(sizeof(*rtd), GFP_KERNEL);
198 if (!rtd)
199 goto out;
200 rtd->dma_desc_array =
201 dma_alloc_writecombine(substream->pcm->card->dev, PAGE_SIZE,
202 &rtd->dma_desc_array_phys, GFP_KERNEL);
203 if (!rtd->dma_desc_array)
204 goto err1;
205
206 runtime->private_data = rtd;
207 return 0;
208
209 err1:
210 kfree(rtd);
211 out:
212 return ret;
213}
214EXPORT_SYMBOL(__pxa2xx_pcm_open);
215
216int __pxa2xx_pcm_close(struct snd_pcm_substream *substream)
217{
218 struct snd_pcm_runtime *runtime = substream->runtime;
219 struct pxa2xx_runtime_data *rtd = runtime->private_data;
220
221 dma_free_writecombine(substream->pcm->card->dev, PAGE_SIZE,
222 rtd->dma_desc_array, rtd->dma_desc_array_phys);
223 kfree(rtd);
224 return 0;
225}
226EXPORT_SYMBOL(__pxa2xx_pcm_close);
227
228int pxa2xx_pcm_mmap(struct snd_pcm_substream *substream,
229 struct vm_area_struct *vma)
230{
231 struct snd_pcm_runtime *runtime = substream->runtime;
232 return dma_mmap_writecombine(substream->pcm->card->dev, vma,
233 runtime->dma_area,
234 runtime->dma_addr,
235 runtime->dma_bytes);
236}
237EXPORT_SYMBOL(pxa2xx_pcm_mmap);
238
239int pxa2xx_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
240{
241 struct snd_pcm_substream *substream = pcm->streams[stream].substream;
242 struct snd_dma_buffer *buf = &substream->dma_buffer;
243 size_t size = pxa2xx_pcm_hardware.buffer_bytes_max;
244 buf->dev.type = SNDRV_DMA_TYPE_DEV;
245 buf->dev.dev = pcm->card->dev;
246 buf->private_data = NULL;
247 buf->area = dma_alloc_writecombine(pcm->card->dev, size,
248 &buf->addr, GFP_KERNEL);
249 if (!buf->area)
250 return -ENOMEM;
251 buf->bytes = size;
252 return 0;
253}
254EXPORT_SYMBOL(pxa2xx_pcm_preallocate_dma_buffer);
255
256void pxa2xx_pcm_free_dma_buffers(struct snd_pcm *pcm)
257{
258 struct snd_pcm_substream *substream;
259 struct snd_dma_buffer *buf;
260 int stream;
261
262 for (stream = 0; stream < 2; stream++) {
263 substream = pcm->streams[stream].substream;
264 if (!substream)
265 continue;
266 buf = &substream->dma_buffer;
267 if (!buf->area)
268 continue;
269 dma_free_writecombine(pcm->card->dev, buf->bytes,
270 buf->area, buf->addr);
271 buf->area = NULL;
272 }
273}
274EXPORT_SYMBOL(pxa2xx_pcm_free_dma_buffers);
275
276MODULE_AUTHOR("Nicolas Pitre");
277MODULE_DESCRIPTION("Intel PXA2xx sound library");
278MODULE_LICENSE("GPL");
diff --git a/sound/arm/pxa2xx-pcm.c b/sound/arm/pxa2xx-pcm.c
index 381094aab235..535704f77496 100644
--- a/sound/arm/pxa2xx-pcm.c
+++ b/sound/arm/pxa2xx-pcm.c
@@ -10,183 +10,20 @@
10 * published by the Free Software Foundation. 10 * published by the Free Software Foundation.
11 */ 11 */
12 12
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/device.h>
16#include <linux/slab.h>
17#include <linux/dma-mapping.h>
18
19#include <sound/core.h> 13#include <sound/core.h>
20#include <sound/pcm.h> 14#include <sound/pxa2xx-lib.h>
21#include <sound/pcm_params.h>
22
23#include <asm/dma.h>
24#include <mach/hardware.h>
25#include <mach/pxa-regs.h>
26 15
27#include "pxa2xx-pcm.h" 16#include "pxa2xx-pcm.h"
28 17
29
30static const struct snd_pcm_hardware pxa2xx_pcm_hardware = {
31 .info = SNDRV_PCM_INFO_MMAP |
32 SNDRV_PCM_INFO_MMAP_VALID |
33 SNDRV_PCM_INFO_INTERLEAVED |
34 SNDRV_PCM_INFO_PAUSE,
35 .formats = SNDRV_PCM_FMTBIT_S16_LE,
36 .period_bytes_min = 32,
37 .period_bytes_max = 8192 - 32,
38 .periods_min = 1,
39 .periods_max = PAGE_SIZE/sizeof(pxa_dma_desc),
40 .buffer_bytes_max = 128 * 1024,
41 .fifo_size = 32,
42};
43
44struct pxa2xx_runtime_data {
45 int dma_ch;
46 struct pxa2xx_pcm_dma_params *params;
47 pxa_dma_desc *dma_desc_array;
48 dma_addr_t dma_desc_array_phys;
49};
50
51static int pxa2xx_pcm_hw_params(struct snd_pcm_substream *substream,
52 struct snd_pcm_hw_params *params)
53{
54 struct snd_pcm_runtime *runtime = substream->runtime;
55 struct pxa2xx_runtime_data *rtd = runtime->private_data;
56 size_t totsize = params_buffer_bytes(params);
57 size_t period = params_period_bytes(params);
58 pxa_dma_desc *dma_desc;
59 dma_addr_t dma_buff_phys, next_desc_phys;
60
61 snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
62 runtime->dma_bytes = totsize;
63
64 dma_desc = rtd->dma_desc_array;
65 next_desc_phys = rtd->dma_desc_array_phys;
66 dma_buff_phys = runtime->dma_addr;
67 do {
68 next_desc_phys += sizeof(pxa_dma_desc);
69 dma_desc->ddadr = next_desc_phys;
70 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
71 dma_desc->dsadr = dma_buff_phys;
72 dma_desc->dtadr = rtd->params->dev_addr;
73 } else {
74 dma_desc->dsadr = rtd->params->dev_addr;
75 dma_desc->dtadr = dma_buff_phys;
76 }
77 if (period > totsize)
78 period = totsize;
79 dma_desc->dcmd = rtd->params->dcmd | period | DCMD_ENDIRQEN;
80 dma_desc++;
81 dma_buff_phys += period;
82 } while (totsize -= period);
83 dma_desc[-1].ddadr = rtd->dma_desc_array_phys;
84
85 return 0;
86}
87
88static int pxa2xx_pcm_hw_free(struct snd_pcm_substream *substream)
89{
90 struct pxa2xx_runtime_data *rtd = substream->runtime->private_data;
91
92 *rtd->params->drcmr = 0;
93 snd_pcm_set_runtime_buffer(substream, NULL);
94 return 0;
95}
96
97static int pxa2xx_pcm_prepare(struct snd_pcm_substream *substream) 18static int pxa2xx_pcm_prepare(struct snd_pcm_substream *substream)
98{ 19{
99 struct pxa2xx_pcm_client *client = substream->private_data; 20 struct pxa2xx_pcm_client *client = substream->private_data;
100 struct snd_pcm_runtime *runtime = substream->runtime;
101 struct pxa2xx_runtime_data *rtd = runtime->private_data;
102 21
103 DCSR(rtd->dma_ch) &= ~DCSR_RUN; 22 __pxa2xx_pcm_prepare(substream);
104 DCSR(rtd->dma_ch) = 0;
105 DCMD(rtd->dma_ch) = 0;
106 *rtd->params->drcmr = rtd->dma_ch | DRCMR_MAPVLD;
107 23
108 return client->prepare(substream); 24 return client->prepare(substream);
109} 25}
110 26
111static int pxa2xx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
112{
113 struct pxa2xx_runtime_data *rtd = substream->runtime->private_data;
114 int ret = 0;
115
116 switch (cmd) {
117 case SNDRV_PCM_TRIGGER_START:
118 DDADR(rtd->dma_ch) = rtd->dma_desc_array_phys;
119 DCSR(rtd->dma_ch) = DCSR_RUN;
120 break;
121
122 case SNDRV_PCM_TRIGGER_STOP:
123 case SNDRV_PCM_TRIGGER_SUSPEND:
124 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
125 DCSR(rtd->dma_ch) &= ~DCSR_RUN;
126 break;
127
128 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
129 DCSR(rtd->dma_ch) |= DCSR_RUN;
130 break;
131
132 default:
133 ret = -EINVAL;
134 }
135
136 return ret;
137}
138
139static void pxa2xx_pcm_dma_irq(int dma_ch, void *dev_id)
140{
141 struct snd_pcm_substream *substream = dev_id;
142 struct pxa2xx_runtime_data *rtd = substream->runtime->private_data;
143 int dcsr;
144
145 dcsr = DCSR(dma_ch);
146 DCSR(dma_ch) = dcsr & ~DCSR_STOPIRQEN;
147
148 if (dcsr & DCSR_ENDINTR) {
149 snd_pcm_period_elapsed(substream);
150 } else {
151 printk( KERN_ERR "%s: DMA error on channel %d (DCSR=%#x)\n",
152 rtd->params->name, dma_ch, dcsr );
153 snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
154 }
155}
156
157static snd_pcm_uframes_t pxa2xx_pcm_pointer(struct snd_pcm_substream *substream)
158{
159 struct snd_pcm_runtime *runtime = substream->runtime;
160 struct pxa2xx_runtime_data *rtd = runtime->private_data;
161 dma_addr_t ptr = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
162 DSADR(rtd->dma_ch) : DTADR(rtd->dma_ch);
163 snd_pcm_uframes_t x = bytes_to_frames(runtime, ptr - runtime->dma_addr);
164 if (x == runtime->buffer_size)
165 x = 0;
166 return x;
167}
168
169static int
170pxa2xx_pcm_hw_rule_mult32(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule)
171{
172 struct snd_interval *i = hw_param_interval(params, rule->var);
173 int changed = 0;
174
175 if (i->min & 31) {
176 i->min = (i->min & ~31) + 32;
177 i->openmin = 0;
178 changed = 1;
179 }
180
181 if (i->max & 31) {
182 i->max &= ~31;
183 i->openmax = 0;
184 changed = 1;
185 }
186
187 return changed;
188}
189
190static int pxa2xx_pcm_open(struct snd_pcm_substream *substream) 27static int pxa2xx_pcm_open(struct snd_pcm_substream *substream)
191{ 28{
192 struct pxa2xx_pcm_client *client = substream->private_data; 29 struct pxa2xx_pcm_client *client = substream->private_data;
@@ -194,33 +31,11 @@ static int pxa2xx_pcm_open(struct snd_pcm_substream *substream)
194 struct pxa2xx_runtime_data *rtd; 31 struct pxa2xx_runtime_data *rtd;
195 int ret; 32 int ret;
196 33
197 runtime->hw = pxa2xx_pcm_hardware; 34 ret = __pxa2xx_pcm_open(substream);
198
199 /*
200 * For mysterious reasons (and despite what the manual says)
201 * playback samples are lost if the DMA count is not a multiple
202 * of the DMA burst size. Let's add a rule to enforce that.
203 */
204 ret = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
205 pxa2xx_pcm_hw_rule_mult32, NULL,
206 SNDRV_PCM_HW_PARAM_PERIOD_BYTES, -1);
207 if (ret)
208 goto out;
209 ret = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
210 pxa2xx_pcm_hw_rule_mult32, NULL,
211 SNDRV_PCM_HW_PARAM_BUFFER_BYTES, -1);
212 if (ret) 35 if (ret)
213 goto out; 36 goto out;
214 37
215 ret = -ENOMEM; 38 rtd = runtime->private_data;
216 rtd = kmalloc(sizeof(*rtd), GFP_KERNEL);
217 if (!rtd)
218 goto out;
219 rtd->dma_desc_array =
220 dma_alloc_writecombine(substream->pcm->card->dev, PAGE_SIZE,
221 &rtd->dma_desc_array_phys, GFP_KERNEL);
222 if (!rtd->dma_desc_array)
223 goto err1;
224 39
225 rtd->params = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ? 40 rtd->params = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
226 client->playback_params : client->capture_params; 41 client->playback_params : client->capture_params;
@@ -230,17 +45,13 @@ static int pxa2xx_pcm_open(struct snd_pcm_substream *substream)
230 goto err2; 45 goto err2;
231 rtd->dma_ch = ret; 46 rtd->dma_ch = ret;
232 47
233 runtime->private_data = rtd;
234 ret = client->startup(substream); 48 ret = client->startup(substream);
235 if (!ret) 49 if (!ret)
236 goto out; 50 goto out;
237 51
238 pxa_free_dma(rtd->dma_ch); 52 pxa_free_dma(rtd->dma_ch);
239 err2: 53 err2:
240 dma_free_writecombine(substream->pcm->card->dev, PAGE_SIZE, 54 __pxa2xx_pcm_close(substream);
241 rtd->dma_desc_array, rtd->dma_desc_array_phys);
242 err1:
243 kfree(rtd);
244 out: 55 out:
245 return ret; 56 return ret;
246} 57}
@@ -252,69 +63,22 @@ static int pxa2xx_pcm_close(struct snd_pcm_substream *substream)
252 63
253 pxa_free_dma(rtd->dma_ch); 64 pxa_free_dma(rtd->dma_ch);
254 client->shutdown(substream); 65 client->shutdown(substream);
255 dma_free_writecombine(substream->pcm->card->dev, PAGE_SIZE,
256 rtd->dma_desc_array, rtd->dma_desc_array_phys);
257 kfree(rtd);
258 return 0;
259}
260 66
261static int 67 return __pxa2xx_pcm_close(substream);
262pxa2xx_pcm_mmap(struct snd_pcm_substream *substream, struct vm_area_struct *vma)
263{
264 struct snd_pcm_runtime *runtime = substream->runtime;
265 return dma_mmap_writecombine(substream->pcm->card->dev, vma,
266 runtime->dma_area,
267 runtime->dma_addr,
268 runtime->dma_bytes);
269} 68}
270 69
271static struct snd_pcm_ops pxa2xx_pcm_ops = { 70static struct snd_pcm_ops pxa2xx_pcm_ops = {
272 .open = pxa2xx_pcm_open, 71 .open = pxa2xx_pcm_open,
273 .close = pxa2xx_pcm_close, 72 .close = pxa2xx_pcm_close,
274 .ioctl = snd_pcm_lib_ioctl, 73 .ioctl = snd_pcm_lib_ioctl,
275 .hw_params = pxa2xx_pcm_hw_params, 74 .hw_params = __pxa2xx_pcm_hw_params,
276 .hw_free = pxa2xx_pcm_hw_free, 75 .hw_free = __pxa2xx_pcm_hw_free,
277 .prepare = pxa2xx_pcm_prepare, 76 .prepare = pxa2xx_pcm_prepare,
278 .trigger = pxa2xx_pcm_trigger, 77 .trigger = pxa2xx_pcm_trigger,
279 .pointer = pxa2xx_pcm_pointer, 78 .pointer = pxa2xx_pcm_pointer,
280 .mmap = pxa2xx_pcm_mmap, 79 .mmap = pxa2xx_pcm_mmap,
281}; 80};
282 81
283static int pxa2xx_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
284{
285 struct snd_pcm_substream *substream = pcm->streams[stream].substream;
286 struct snd_dma_buffer *buf = &substream->dma_buffer;
287 size_t size = pxa2xx_pcm_hardware.buffer_bytes_max;
288 buf->dev.type = SNDRV_DMA_TYPE_DEV;
289 buf->dev.dev = pcm->card->dev;
290 buf->private_data = NULL;
291 buf->area = dma_alloc_writecombine(pcm->card->dev, size,
292 &buf->addr, GFP_KERNEL);
293 if (!buf->area)
294 return -ENOMEM;
295 buf->bytes = size;
296 return 0;
297}
298
299static void pxa2xx_pcm_free_dma_buffers(struct snd_pcm *pcm)
300{
301 struct snd_pcm_substream *substream;
302 struct snd_dma_buffer *buf;
303 int stream;
304
305 for (stream = 0; stream < 2; stream++) {
306 substream = pcm->streams[stream].substream;
307 if (!substream)
308 continue;
309 buf = &substream->dma_buffer;
310 if (!buf->area)
311 continue;
312 dma_free_writecombine(pcm->card->dev, buf->bytes,
313 buf->area, buf->addr);
314 buf->area = NULL;
315 }
316}
317
318static u64 pxa2xx_pcm_dmamask = 0xffffffff; 82static u64 pxa2xx_pcm_dmamask = 0xffffffff;
319 83
320int pxa2xx_pcm_new(struct snd_card *card, struct pxa2xx_pcm_client *client, 84int pxa2xx_pcm_new(struct snd_card *card, struct pxa2xx_pcm_client *client,
diff --git a/sound/arm/pxa2xx-pcm.h b/sound/arm/pxa2xx-pcm.h
index b79f1e803780..5c4a4d38a083 100644
--- a/sound/arm/pxa2xx-pcm.h
+++ b/sound/arm/pxa2xx-pcm.h
@@ -9,14 +9,15 @@
9 * it under the terms of the GNU General Public License version 2 as 9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation. 10 * published by the Free Software Foundation.
11 */ 11 */
12#include <asm/dma.h>
12 13
13struct pxa2xx_pcm_dma_params { 14struct pxa2xx_runtime_data {
14 char *name; /* stream identifier */ 15 int dma_ch;
15 u32 dcmd; /* DMA descriptor dcmd field */ 16 struct pxa2xx_pcm_dma_params *params;
16 volatile u32 *drcmr; /* the DMA request channel to use */ 17 pxa_dma_desc *dma_desc_array;
17 u32 dev_addr; /* device physical address for DMA */ 18 dma_addr_t dma_desc_array_phys;
18}; 19};
19 20
20struct pxa2xx_pcm_client { 21struct pxa2xx_pcm_client {
21 struct pxa2xx_pcm_dma_params *playback_params; 22 struct pxa2xx_pcm_dma_params *playback_params;
22 struct pxa2xx_pcm_dma_params *capture_params; 23 struct pxa2xx_pcm_dma_params *capture_params;
diff --git a/sound/arm/sa11xx-uda1341.c b/sound/arm/sa11xx-uda1341.c
index b9c51bf8cd71..1dcd51d81d10 100644
--- a/sound/arm/sa11xx-uda1341.c
+++ b/sound/arm/sa11xx-uda1341.c
@@ -442,7 +442,8 @@ static void audio_process_dma(struct audio_stream *s)
442 442
443 /* we are requested to process synchronization DMA transfer */ 443 /* we are requested to process synchronization DMA transfer */
444 if (s->tx_spin) { 444 if (s->tx_spin) {
445 snd_assert(s->stream_id == SNDRV_PCM_STREAM_PLAYBACK, return); 445 if (snd_BUG_ON(s->stream_id != SNDRV_PCM_STREAM_PLAYBACK))
446 return;
446 /* fill the xmit dma buffers and return */ 447 /* fill the xmit dma buffers and return */
447#ifdef HH_VERSION 448#ifdef HH_VERSION
448 sa1100_dma_set_spin(s->dmach, FORCE_CLOCK_ADDR, FORCE_CLOCK_SIZE); 449 sa1100_dma_set_spin(s->dmach, FORCE_CLOCK_ADDR, FORCE_CLOCK_SIZE);
@@ -472,7 +473,7 @@ static void audio_process_dma(struct audio_stream *s)
472 continue; /* special case */ 473 continue; /* special case */
473 } else { 474 } else {
474 offset = dma_size * s->period; 475 offset = dma_size * s->period;
475 snd_assert(dma_size <= DMA_BUF_SIZE, ); 476 snd_BUG_ON(dma_size > DMA_BUF_SIZE);
476 } 477 }
477#ifdef HH_VERSION 478#ifdef HH_VERSION
478 ret = sa1100_dma_queue_buffer(s->dmach, s, runtime->dma_addr + offset, dma_size); 479 ret = sa1100_dma_queue_buffer(s->dmach, s, runtime->dma_addr + offset, dma_size);
@@ -879,7 +880,7 @@ void snd_sa11xx_uda1341_free(struct snd_card *card)
879 audio_dma_free(&chip->s[SNDRV_PCM_STREAM_CAPTURE]); 880 audio_dma_free(&chip->s[SNDRV_PCM_STREAM_CAPTURE]);
880} 881}
881 882
882static int __init sa11xx_uda1341_probe(struct platform_device *devptr) 883static int __devinit sa11xx_uda1341_probe(struct platform_device *devptr)
883{ 884{
884 int err; 885 int err;
885 struct snd_card *card; 886 struct snd_card *card;