ASoC: Fix mpc5200-psc-ac97 to ensure the data ready bit is cleared
PATCH 1/2 ASoC: Fix mpc5200-psc-ac97 to ensure the data ready bit is cleared
From: Grant Likely <[email protected]>
When doing register reads, it is possible for there to be a stale data ready bit set which will cause subsequent reads to return prematurely with incorrect data. This patch fixes the issues by ensuring stale data is cleared before starting another transaction.
---
sound/soc/fsl/mpc5200_psc_ac97.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
sound/soc/fsl/mpc5200_psc_ac97.c +4 -0
@@ -41,6 +41,10 @@ static unsigned short psc_ac97_read(struct snd_ac97 *ac97, unsigned short reg)pr_err ("timeout on ac97 bus (rdy)\n" );return -ENODEV ; } + +/* Force clear the data valid bit */ +in_be32 (&psc_dma->psc_regs->ac97_data); +/* Send the read */ out_be32 (&psc_dma->psc_regs->ac97_cmd, (1 <<31 ) | ((reg &0x7f ) <<24 ));
PATCH 2/2 ASoC: add locking to mpc5200-psc-ac97 driver
From: Grant Likely <[email protected]>
AC97 bus register read/write hooks need to provide locking, but the mpc5200-psc-ac97 driver does not. This patch adds a mutex around the register access routines.
---
sound/soc/fsl/mpc5200_dma.c | 1 + sound/soc/fsl/mpc5200_dma.h | 1 + sound/soc/fsl/mpc5200_psc_ac97.c | 13 ++++++++++++- 3 files changed, 14 insertions(+), 1 deletions(-)
sound/soc/fsl/mpc5200_dma.c +1 -0
@@ -456,6 +456,7 @@ int mpc5200_audio_dma_create(struct of_device *op)return -ENODEV ;spin_lock_init (&psc_dma->lock); +mutex_init (&psc_dma->mutex); psc_dma->id =be32_to_cpu (*prop); psc_dma->irq = irq; psc_dma->psc_regs = regs;
sound/soc/fsl/mpc5200_dma.h +1 -0
@@ -55,6 +55,7 @@ struct psc_dma {unsigned int irq;struct device *dev;spinlock_t lock; +struct mutex mutex;u32 sicr;uint sysclk;int imr;
sound/soc/fsl/mpc5200_psc_ac97.c +12 -1
@@ -34,11 +34,14 @@ static unsigned short psc_ac97_read(struct snd_ac97 *ac97, unsigned short reg)int status;unsigned int val; +mutex_lock (&psc_dma->mutex); +/* Wait for command send status zero = ready */ status =spin_event_timeout (!(in_be16 (&psc_dma->psc_regs->sr_csr.status) & MPC52xx_PSC_SR_CMDSEND),100 ,0 );if (status ==0 ) {pr_err ("timeout on ac97 bus (rdy)\n" ); +mutex_unlock (&psc_dma->mutex);return -ENODEV ; }
@@ -54,16 +57,19 @@ static unsigned short psc_ac97_read(struct snd_ac97 *ac97, unsigned short reg)if (status ==0 ) {pr_err ("timeout on ac97 read (val) %x\n" ,in_be16 (&psc_dma->psc_regs->sr_csr.status)); +mutex_unlock (&psc_dma->mutex);return -ENODEV ; }/* Get the data */ val =in_be32 (&psc_dma->psc_regs->ac97_data);if (((val >>24 ) &0x7f ) != reg) {pr_err ("reg echo error on ac97 read\n" ); +mutex_unlock (&psc_dma->mutex);return -ENODEV ; } val = (val >>8 ) &0xffff ; +mutex_unlock (&psc_dma->mutex);return (unsigned short ) val; }
@@ -72,16 +78,21 @@ static void psc_ac97_write(struct snd_ac97 *ac97, {int status; +mutex_lock (&psc_dma->mutex); +/* Wait for command status zero = ready */ status =spin_event_timeout (!(in_be16 (&psc_dma->psc_regs->sr_csr.status) & MPC52xx_PSC_SR_CMDSEND),100 ,0 );if (status ==0 ) {pr_err ("timeout on ac97 bus (write)\n" ); -return ; + goto out; }/* Write data */ out_be32 (&psc_dma->psc_regs->ac97_cmd, ((reg &0x7f ) <<24 ) | (val <<8 )); + + out: +mutex_unlock (&psc_dma->mutex); }static void psc_ac97_warm_reset (struct snd_ac97 *ac97)
Re: [PATCH 2/2] ASoC: add locking to mpc5200-psc-ac97 driver
Quoted 7 lines · Grant Likely
From: Grant Likely <[email protected]>
AC97 bus register read/write hooks need to provide locking, but the mpc5200-psc-ac97 driver does not. This patch adds a mutex around the register access routines.
Signed-off-by Grant Likely <[email protected]>
Quoted 96 lines
---
sound/soc/fsl/mpc5200_dma.c | 1 +
sound/soc/fsl/mpc5200_dma.h| 1 +sound/soc/fsl/mpc5200_psc_ac97.c| 13 ++++++++++++-3 files changed, 14 insertions(+), 1 deletions(-)sound/soc/fsl/mpc5200_dma.c +1
-0@@ -456,6 +456,7 @@ int mpc5200_audio_dma_create(struct of_device *op) return -ENODEV; spin_lock_init(&psc_dma->lock); + mutex_init(&psc_dma->mutex); psc_dma->id = be32_to_cpu(*prop); psc_dma->irq = irq; psc_dma->psc_regs = regs;sound/soc/fsl/mpc5200_dma.h +1
-0@@ -55,6 +55,7 @@ struct psc_dma { unsigned int irq; struct device *dev; spinlock_t lock; + struct mutex mutex; u32 sicr; uint sysclk; int imr;sound/soc/fsl/mpc5200_psc_ac97.c +2
-0@@ -34,11 +34,14 @@ static unsigned short psc_ac97_read(struct snd_ac97 *ac97, unsigned short reg) int status; unsigned int val; + mutex_lock(&psc_dma->mutex); + /* Wait for command send status zero = ready */status =
spin_event_timeout(!(in_be16(&psc_dma->psc_regs->sr_csr.status) & MPC52xx_PSC_SR_CMDSEND), 100, 0);
if (status == 0) {
pr_err("timeout on ac97 bus (rdy)\n");
+mutex_unlock(&psc_dma->mutex);
return-ENODEV;
}sound/soc/fsl/mpc5200_psc_ac97.c +5
-0@@ -54,16 +57,19 @@ static unsigned short psc_ac97_read(struct snd_ac97 *ac97, unsigned short reg) if (status == 0) { pr_err("timeout on ac97 read (val) %x\n", in_be16(&psc_dma->psc_regs->sr_csr.status)); + mutex_unlock(&psc_dma->mutex); return -ENODEV; } /* Get the data */ val = in_be32(&psc_dma->psc_regs->ac97_data); if (((val >> 24) & 0x7f) != reg) { pr_err("reg echo error on ac97 read\n"); + mutex_unlock(&psc_dma->mutex); return -ENODEV; } val = (val >> 8) & 0xffff; + mutex_unlock(&psc_dma->mutex); return (unsigned short) val; }@@ -72,16 +78,21 @@ static void psc_ac97_write(struct snd_ac97 *ac97, { int status; + mutex_lock(&psc_dma->mutex); + /* Wait for command status zero = ready */status =
spin_event_timeout(!(in_be16(&psc_dma->psc_regs->sr_csr.status) & MPC52xx_PSC_SR_CMDSEND), 100, 0);
if (status == 0) {
pr_err("timeout on ac97 bus (write)\n");
- return;
+ goto out;
}
/* Write data */
out_be32(&psc_dma->psc_regs->ac97_cmd,
((reg &0x7f) << 24) | (val << 8));
+
+ out:
+mutex_unlock(&psc_dma->mutex);
}static void
psc_ac97_warm_reset(struct snd_ac97 *ac97)
Signature · 2 lines
Jon Smirl [email protected]
Re: [PATCH 2/2] ASoC: add locking to mpc5200-psc-ac97 driver
In reply to Grant LikelyHi,
Quoted 47 lines · Grant Likely
From: Grant Likely <[email protected]>
AC97 bus register read/write hooks need to provide locking, but the mpc5200-psc-ac97 driver does not. This patch adds a mutex around the register access routines.
Signed-off-by Grant Likely <[email protected]>---
sound/soc/fsl/mpc5200_dma.c | 1 + sound/soc/fsl/mpc5200_dma.h | 1 + sound/soc/fsl/mpc5200_psc_ac97.c | 13 ++++++++++++- 3 files changed, 14 insertions(+), 1 deletions(-)sound/soc/fsl/mpc5200_dma.c +1
-0@@ -456,6 +456,7 @@ int mpc5200_audio_dma_create(struct of_device *op)return -ENODEV ;spin_lock_init (&psc_dma->lock); +mutex_init (&psc_dma->mutex); psc_dma->id =be32_to_cpu (*prop); psc_dma->irq = irq; psc_dma->psc_regs = regs;sound/soc/fsl/mpc5200_dma.h +1
-0@@ -55,6 +55,7 @@ struct psc_dma {unsigned int irq;struct device *dev;spinlock_t lock; +struct mutex mutex;u32 sicr;uint sysclk;int imr;sound/soc/fsl/mpc5200_psc_ac97.c +0
-0@@ -34,11 +34,14 @@ static unsigned short psc_ac97_read(struct snd_ac97 *ac97, unsigned short reg)int status;unsigned int val;
sound/soc/fsl/mpc5200_psc_ac97.c static unsigned short psc_ac97_read(struct snd_ac97 *ac97, unsigned short reg) · line 46
Quoted 10 lines
sound/soc/fsl/mpc5200_psc_ac97.c +3
-0+mutex_lock (&psc_dma->mutex); +/* Wait for command send status zero = ready */ status =spin_event_timeout (!(in_be16 (&psc_dma->psc_regs->sr_csr.status) & MPC52xx_PSC_SR_CMDSEND),100 ,0 );if (status ==0 ) {pr_err ("timeout on ac97 bus (rdy)\n" ); +mutex_unlock (&psc_dma->mutex);return -ENODEV ;
maybe define an err variable and and a goto out.
Michael
Re: [PATCH 2/2] ASoC: add locking to mpc5200-psc-ac97 driver
Quoted 56 lines · michael
Hi,
Quoted 53 lines · Grant Likely
From: Grant Likely <[email protected]>
AC97 bus register read/write hooks need to provide locking, but the mpc5200-psc-ac97 driver does not. This patch adds a mutex around the register access routines.
Signed-off-by Grant Likely <[email protected]>---
sound/soc/fsl/mpc5200_dma.c | 1 +
sound/soc/fsl/mpc5200_dma.h| 1 +sound/soc/fsl/mpc5200_psc_ac97.c| 13 ++++++++++++-3 files changed, 14 insertions(+), 1 deletions(-)sound/soc/fsl/mpc5200_dma.c +1
-0@@ -456,6 +456,7 @@ int mpc5200_audio_dma_create(struct of_device *op) return -ENODEV; spin_lock_init(&psc_dma->lock); + mutex_init(&psc_dma->mutex); psc_dma->id = be32_to_cpu(*prop); psc_dma->irq = irq; psc_dma->psc_regs = regs;sound/soc/fsl/mpc5200_dma.h +1
-0@@ -55,6 +55,7 @@ struct psc_dma { unsigned int irq; struct device *dev; spinlock_t lock; + struct mutex mutex; u32 sicr; uint sysclk; int imr;sound/soc/fsl/mpc5200_psc_ac97.c +1
-0@@ -34,11 +34,14 @@ static unsigned short psc_ac97_read(struct snd_ac97 *ac97, unsigned short reg) int status; unsigned int val; + mutex_lock(&psc_dma->mutex); + /* Wait for command send status zero = ready */status = spin_event_timeout(!(in_be16(&psc_dma->psc_regs->sr_csr.status) &
Quoted 8 lines
Quoted 6 lines
MPC52xx_PSC_SR_CMDSEND), 100, 0); if (status == 0) {
pr_err("timeout on ac97 bus (rdy)\n");
+mutex_unlock(&psc_dma->mutex);
return-ENODEV;maybe define an err variable and and a goto out.
My first iteration did that, but after looking at it I decided I like this better and it adds (slightly) fewer lines of code.
g.
Signature · 2 lines
Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd.
Quoted 8 lines · Grant Likely
From: Grant Likely <[email protected]>
When doing register reads, it is possible for there to be a stale data ready bit set which will cause subsequent reads to return prematurely with incorrect data. This patch fixes the issues by ensuring stale data is cleared before starting another transaction.
Signed-off-by Grant Likely <[email protected]>
Quoted 23 lines
---
sound/soc/fsl/mpc5200_psc_ac97.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)sound/soc/fsl/mpc5200_psc_ac97.c +4
-0@@ -41,6 +41,10 @@ static unsigned short psc_ac97_read(struct snd_ac97 *ac97, unsigned short reg) pr_err("timeout on ac97 bus (rdy)\n"); return -ENODEV; } + + /* Force clear the data valid bit */ + in_be32(&psc_dma->psc_regs->ac97_data); + /* Send the read */ out_be32(&psc_dma->psc_regs->ac97_cmd, (1<<31) | ((reg & 0x7f) << 24));
Signature · 2 lines
Jon Smirl [email protected]
Mark Brown
AppliedQuoted 6 lines · Grant Likely
From: Grant Likely <[email protected]>
When doing register reads, it is possible for there to be a stale data ready bit set which will cause subsequent reads to return prematurely with incorrect data. This patch fixes the issues by ensuring stale data is cleared before starting another transaction.
Applied both, thanks.