S3C I2S: lrsync function made to work with IRQs disabled.
PATCH 5/10 S3C I2S: lrsync function made to work with IRQs disabled.
s3c2412_snd_lrsync() maybe reached with IRQs disabled and if LRCLK is dead due to improper initialization of CPU or CODEC, the system gets stuck in the loop because jiffies may never get updated. Implemented counter based wait mechanism for atleast the same timeout period.
--- sound/soc/s3c24xx/s3c-i2s-v2.c | 16 ++++++++++------ 1 files changed, 10 insertions(+), 6 deletions(-)
sound/soc/s3c24xx/s3c-i2s-v2.c +10 -6
@@ -230,6 +230,8 @@ static void s3c2412_snd_rxctrl(struct s3c_i2sv2_info *i2s, int on)pr_debug ("%s: IIS: CON=%x MOD=%x FIC=%x\n" , __func__, con, mod, fic); } +#define msecs_to_loops (t) (loops_per_jiffy / 1000 * HZ * t) +/* * Wait for the LR signal to allow synchronisation to the L/R clock * from the codec. May only be needed for slave mode.
@@ -237,19 +239,21 @@ static void s3c2412_snd_rxctrl(struct s3c_i2sv2_info *i2s, int on)static int s3c2412_snd_lrsync (struct s3c_i2sv2_info *i2s) {u32 iiscon; -unsigned long timeout = jiffies +msecs_to_jiffies (5 ); +unsigned long loops =msecs_to_loops (5 );pr_debug ("Entered %s\n" , __func__); -while (1 ) { +while (--loops) { iiscon =readl (i2s->regs +S3C2412_IISCON );if (iiscon &S3C2412_IISCON_LRINDEX )break ; -if (timeout < jiffies) { -printk (KERN_ERR "%s: timeout\n" , __func__); -return -ETIMEDOUT ; - } +cpu_relax (); + } + +if (!loops) { +printk (KERN_ERR "%s: timeout\n" , __func__); +return -ETIMEDOUT ; }return 0 ;
Signature · 1 line
1.6.2.5
PATCH 5/10 S3C I2S: lrsync function made to work with IRQs disabled.
Quoted 5 lines · Jassi
s3c2412_snd_lrsync()maybe reached with IRQs disabled and if LRCLK is dead due to improper initialization of CPU or CODEC, the system gets stuck in the loop because jiffies may never get updated. Implemented counter based wait mechanism for atleast the same timeout period.
I'll apply this but...
Quoted 1 line
+#define
msecs_to_loops(t)(loops_per_jiffy/ 1000 * HZ * t)
...this really should be moved into a standard header since it's a bit of a namespace violation. Also, there's a jiffies_to_msecs function.
PATCH 5/10 S3C I2S: lrsync function made to work with IRQs disabled.
In reply to JassiQuoted 34 lines · Jassi
s3c2412_snd_lrsync()maybe reached with IRQs disabled and if LRCLK is dead due to improper initialization of CPU or CODEC, the system gets stuck in the loop because jiffies may never get updated. Implemented counter based wait mechanism for atleast the same timeout period.Signed-off-by Jassi <[email protected]>--- sound/soc/s3c24xx/s3c-i2s-v2.c | 16 ++++++++++------ 1 files changed, 10 insertions(+), 6 deletions(-)sound/soc/s3c24xx/s3c-i2s-v2.c +3
-2@@ -230,6 +230,8 @@ static void s3c2412_snd_rxctrl(struct s3c_i2sv2_info *i2s, int on)pr_debug ("%s: IIS: CON=%x MOD=%x FIC=%x\n" , __func__, con, mod, fic); } +#define msecs_to_loops (t) (loops_per_jiffy / 1000 * HZ * t) +/* * Wait for the LR signal to allow synchronisation to the L/R clock * from the codec. May only be needed for slave mode. @@ -237,19 +239,21 @@ static void s3c2412_snd_rxctrl(struct s3c_i2sv2_info *i2s, int on)static int s3c2412_snd_lrsync (struct s3c_i2sv2_info *i2s) {u32 iiscon; -unsigned long timeout = jiffies +msecs_to_jiffies (5 ); +unsigned long loops =msecs_to_loops (5 );pr_debug ("Entered %s\n" , __func__); -while (1 ) {
sound/soc/s3c24xx/s3c-i2s-v2.c static void s3c2412_snd_rxctrl(struct s3c_i2sv2_info *i2s, int on) · line 251
Quoted 10 lines
sound/soc/s3c24xx/s3c-i2s-v2.c +2
-4+while (--loops) { iiscon =readl (i2s->regs +S3C2412_IISCON );if (iiscon &S3C2412_IISCON_LRINDEX )break ; -if (timeout < jiffies) { -printk (KERN_ERR "%s: timeout\n" , __func__); -return -ETIMEDOUT ; - } +cpu_relax ();
I don't think cpu_relax() gives a defined 'timeout' length, thus this loop is of a very indeterminate length of timeout.
Signature · 4 lines
Ben Q: What's a light-year? A: One-third less calories than a regular year.
PATCH 5/10 S3C I2S: lrsync function made to work with IRQs disabled.
Quoted 40 lines · Ben Dooks
Quoted 39 lines · Jassi
s3c2412_snd_lrsync()maybe reached with IRQs disabled and if LRCLK is dead due to improper initialization of CPU or CODEC, the system gets stuck in the loop because jiffies may never get updated. Implemented counter based wait mechanism for atleast the same timeout period.Signed-off-by Jassi <[email protected]>---
?sound/soc/s3c24xx/s3c-i2s-v2.c | ? 16 ++++++++++------ ?1 files changed, 10 insertions(+), 6 deletions(-)sound/soc/s3c24xx/s3c-i2s-v2.c +2
-0@@ -230,6 +230,8 @@ static void s3c2412_snd_rxctrl(struct s3c_i2sv2_info *i2s, int on) ? ? ? pr_debug("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic); ?} +#define msecs_to_loops (t) (loops_per_jiffy / 1000 * HZ * t) +?/*
? * Wait for the LR signal to allow synchronisation to the L/R clock ? * from the codec. May only be needed for slave mode.sound/soc/s3c24xx/s3c-i2s-v2.c +2
-2@@ -237,19 +239,21 @@ static void s3c2412_snd_rxctrl(struct s3c_i2sv2_info *i2s, int on) ?static int s3c2412_snd_lrsync(struct s3c_i2sv2_info *i2s) ?{ ? ? ? u32 iiscon; - ? ? unsigned long timeout = jiffies + msecs_to_jiffies(5); + ? ? unsigned long loops = msecs_to_loops(5); ? ? ? pr_debug("Entered %s\n", __func__); - ? ? while (1) { + ? ? while (--loops) { ? ? ? ? ? ? ? iiscon = readl(i2s->regs + S3C2412_IISCON); ? ? ? ? ? ? ? if (iiscon & S3C2412_IISCON_LRINDEX) ? ? ? ? ? ? ? ? ? ? ? break;
Quoted 8 lines
sound/soc/s3c24xx/s3c-i2s-v2.c static void s3c2412_snd_rxctrl(struct s3c_i2sv2_info *i2s, int on) · line 251
Quoted 5 lines
sound/soc/s3c24xx/s3c-i2s-v2.c +1
-4- ? ? ? ? ? ? if (timeout < jiffies) { - ? ? ? ? ? ? ? ? ? ? printk(KERN_ERR "%s: timeout\n", __func__); - ? ? ? ? ? ? ? ? ? ? return -ETIMEDOUT; - ? ? ? ? ? ? } + ? ? ? ? ? ? cpu_relax();I don't think
cpu_relax()gives a defined 'timeout' length, thus this loop is of a very indeterminate length of timeout.
Ofcourse the total delay is non-deterministic. Besides, there is no hard limit on the amount of time we want to wait on lrsync. And this non-deterministic delay comes into picture only when the I2S is broken. It is second best option to simply hanging.
Total wait period is _atleast_ what we want, as is mentioned in the changelog.
Besides, i think we can do without the cpu_relax(), no?
PATCH 5/10 S3C I2S: lrsync function made to work with IRQs disabled.
Quoted 10 lines · jassi brar
Quoted 2 lines · Ben Dooks
I don't think
cpu_relax()gives a defined 'timeout' length, thus this loop is of a very indeterminate length of timeout.Ofcourse the total delay is non-deterministic. Besides, there is no hard limit on the amount of time we want to wait on lrsync. And this non-deterministic delay comes into picture only when the I2S is broken. It is second best option to simply hanging.
Total wait period is _atleast_ what we want, as is mentioned in the changelog.
The length of time you should need to wait for a LRCLK transition is given by the sample rate - even 1ms is a very generous timeout for 8kHz, which is the lowest sample rate you'd really expect to see. The actual value isn't terribly important since we should never hit it when things aren't broken.