Commit 250c7a61 authored by Russell King's avatar Russell King

ALSA: AACI: fix timeout duration

Relying on the access time of peripherals is unreliable - it depends
on the speed of the CPU and the bus.  On Versatile Express, these
timeouts were expiring, causing the driver to fail.

Add udelay(1) to ensure that they don't expire early, and adjust
timeouts to give a reasonable margin over the response times.
Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
parent 69058cd6
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#define DRIVER_NAME "aaci-pl041" #define DRIVER_NAME "aaci-pl041"
#define FRAME_PERIOD_US 21
/* /*
* PM support is not complete. Turn it off. * PM support is not complete. Turn it off.
*/ */
...@@ -64,8 +66,8 @@ static void aaci_ac97_write(struct snd_ac97 *ac97, unsigned short reg, ...@@ -64,8 +66,8 @@ static void aaci_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
unsigned short val) unsigned short val)
{ {
struct aaci *aaci = ac97->private_data; struct aaci *aaci = ac97->private_data;
int timeout;
u32 v; u32 v;
int timeout = 5000;
if (ac97->num >= 4) if (ac97->num >= 4)
return; return;
...@@ -81,10 +83,13 @@ static void aaci_ac97_write(struct snd_ac97 *ac97, unsigned short reg, ...@@ -81,10 +83,13 @@ static void aaci_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
writel(val << 4, aaci->base + AACI_SL2TX); writel(val << 4, aaci->base + AACI_SL2TX);
writel(reg << 12, aaci->base + AACI_SL1TX); writel(reg << 12, aaci->base + AACI_SL1TX);
/* /* Initially, wait one frame period */
* Wait for the transmission of both slots to complete. udelay(FRAME_PERIOD_US);
*/
/* And then wait an additional eight frame periods for it to be sent */
timeout = FRAME_PERIOD_US * 8;
do { do {
udelay(1);
v = readl(aaci->base + AACI_SLFR); v = readl(aaci->base + AACI_SLFR);
} while ((v & (SLFR_1TXB|SLFR_2TXB)) && --timeout); } while ((v & (SLFR_1TXB|SLFR_2TXB)) && --timeout);
...@@ -101,9 +106,8 @@ static void aaci_ac97_write(struct snd_ac97 *ac97, unsigned short reg, ...@@ -101,9 +106,8 @@ static void aaci_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
static unsigned short aaci_ac97_read(struct snd_ac97 *ac97, unsigned short reg) static unsigned short aaci_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
{ {
struct aaci *aaci = ac97->private_data; struct aaci *aaci = ac97->private_data;
int timeout, retries = 10;
u32 v; u32 v;
int timeout = 5000;
int retries = 10;
if (ac97->num >= 4) if (ac97->num >= 4)
return ~0; return ~0;
...@@ -117,10 +121,13 @@ static unsigned short aaci_ac97_read(struct snd_ac97 *ac97, unsigned short reg) ...@@ -117,10 +121,13 @@ static unsigned short aaci_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
*/ */
writel((reg << 12) | (1 << 19), aaci->base + AACI_SL1TX); writel((reg << 12) | (1 << 19), aaci->base + AACI_SL1TX);
/* /* Initially, wait one frame period */
* Wait for the transmission to complete. udelay(FRAME_PERIOD_US);
*/
/* And then wait an additional eight frame periods for it to be sent */
timeout = FRAME_PERIOD_US * 8;
do { do {
udelay(1);
v = readl(aaci->base + AACI_SLFR); v = readl(aaci->base + AACI_SLFR);
} while ((v & SLFR_1TXB) && --timeout); } while ((v & SLFR_1TXB) && --timeout);
...@@ -130,17 +137,13 @@ static unsigned short aaci_ac97_read(struct snd_ac97 *ac97, unsigned short reg) ...@@ -130,17 +137,13 @@ static unsigned short aaci_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
goto out; goto out;
} }
/* /* Now wait for the response frame */
* Give the AC'97 codec more than enough time udelay(FRAME_PERIOD_US);
* to respond. (42us = ~2 frames at 48kHz.)
*/
udelay(42);
/* /* And then wait an additional eight frame periods for data */
* Wait for slot 2 to indicate data. timeout = FRAME_PERIOD_US * 8;
*/
timeout = 5000;
do { do {
udelay(1);
cond_resched(); cond_resched();
v = readl(aaci->base + AACI_SLFR) & (SLFR_1RXV|SLFR_2RXV); v = readl(aaci->base + AACI_SLFR) & (SLFR_1RXV|SLFR_2RXV);
} while ((v != (SLFR_1RXV|SLFR_2RXV)) && --timeout); } while ((v != (SLFR_1RXV|SLFR_2RXV)) && --timeout);
...@@ -179,6 +182,7 @@ aaci_chan_wait_ready(struct aaci_runtime *aacirun, unsigned long mask) ...@@ -179,6 +182,7 @@ aaci_chan_wait_ready(struct aaci_runtime *aacirun, unsigned long mask)
int timeout = 5000; int timeout = 5000;
do { do {
udelay(1);
val = readl(aacirun->base + AACI_SR); val = readl(aacirun->base + AACI_SR);
} while (val & mask && timeout--); } while (val & mask && timeout--);
} }
...@@ -874,7 +878,7 @@ static int __devinit aaci_probe_ac97(struct aaci *aaci) ...@@ -874,7 +878,7 @@ static int __devinit aaci_probe_ac97(struct aaci *aaci)
* Give the AC'97 codec more than enough time * Give the AC'97 codec more than enough time
* to wake up. (42us = ~2 frames at 48kHz.) * to wake up. (42us = ~2 frames at 48kHz.)
*/ */
udelay(42); udelay(FRAME_PERIOD_US * 2);
ret = snd_ac97_bus(aaci->card, 0, &aaci_bus_ops, aaci, &ac97_bus); ret = snd_ac97_bus(aaci->card, 0, &aaci_bus_ops, aaci, &ac97_bus);
if (ret) if (ret)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment