Commit 5022a208 authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab

[media] em28xx: properly implement AC97 wait code

Instead of assuming that msleep() is precise, use a jiffies
based code to wait for AC97 to be available.
Reviewed-by: default avatarFrank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: default avatarMauro Carvalho Chehab <m.chehab@samsung.com>
parent 2276bf70
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
*/ */
#include <linux/init.h> #include <linux/init.h>
#include <linux/jiffies.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -252,16 +253,18 @@ EXPORT_SYMBOL_GPL(em28xx_toggle_reg_bits); ...@@ -252,16 +253,18 @@ EXPORT_SYMBOL_GPL(em28xx_toggle_reg_bits);
*/ */
static int em28xx_is_ac97_ready(struct em28xx *dev) static int em28xx_is_ac97_ready(struct em28xx *dev)
{ {
int ret, i; unsigned long timeout = jiffies + msecs_to_jiffies(EM28XX_AC97_XFER_TIMEOUT);
int ret;
/* Wait up to 50 ms for AC97 command to complete */ /* Wait up to 50 ms for AC97 command to complete */
for (i = 0; i < 10; i++, msleep(5)) { while (time_is_after_jiffies(timeout)) {
ret = em28xx_read_reg(dev, EM28XX_R43_AC97BUSY); ret = em28xx_read_reg(dev, EM28XX_R43_AC97BUSY);
if (ret < 0) if (ret < 0)
return ret; return ret;
if (!(ret & 0x01)) if (!(ret & 0x01))
return 0; return 0;
msleep(5);
} }
em28xx_warn("AC97 command still being executed: not handled properly!\n"); em28xx_warn("AC97 command still being executed: not handled properly!\n");
......
...@@ -186,6 +186,9 @@ ...@@ -186,6 +186,9 @@
/* time in msecs to wait for i2c writes to finish */ /* time in msecs to wait for i2c writes to finish */
#define EM2800_I2C_XFER_TIMEOUT 20 #define EM2800_I2C_XFER_TIMEOUT 20
/* time in msecs to wait for AC97 xfers to finish */
#define EM28XX_AC97_XFER_TIMEOUT 100
/* max. number of button state polling addresses */ /* max. number of button state polling addresses */
#define EM28XX_NUM_BUTTON_ADDRESSES_MAX 5 #define EM28XX_NUM_BUTTON_ADDRESSES_MAX 5
......
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