diff options
author | Peter Meerwald <pmeerw@pmeerw.net> | 2013-07-27 15:31:00 (GMT) |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2013-08-04 10:08:16 (GMT) |
commit | 4dedf31cd1c28c732a17ddeb9cfdf90b5b860faa (patch) | |
tree | 0214e00430f5e5c2736784a4d2866a59c4939ca2 /drivers/staging/iio | |
parent | a34778f3a7cf20ffb7f7f93fd96a9c456b2a96c6 (diff) | |
download | linux-4dedf31cd1c28c732a17ddeb9cfdf90b5b860faa.tar.xz |
staging:iio:hmc5843: Implement timeout in read function
avoid polling data ready bit forever; msleep() may be too long
for high sampling frequencies but the driver interface does not
support buffering
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
Cc: Shubhrajyoti Datta <shubhrajyoti@ti.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/staging/iio')
-rw-r--r-- | drivers/staging/iio/magnetometer/hmc5843.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/drivers/staging/iio/magnetometer/hmc5843.c b/drivers/staging/iio/magnetometer/hmc5843.c index c281342..79117ad 100644 --- a/drivers/staging/iio/magnetometer/hmc5843.c +++ b/drivers/staging/iio/magnetometer/hmc5843.c @@ -26,6 +26,7 @@ #include <linux/types.h> #include <linux/iio/iio.h> #include <linux/iio/sysfs.h> +#include <linux/delay.h> #define HMC5843_CONFIG_REG_A 0x00 #define HMC5843_CONFIG_REG_B 0x01 @@ -210,11 +211,22 @@ static int hmc5843_read_measurement(struct iio_dev *indio_dev, struct i2c_client *client = to_i2c_client(indio_dev->dev.parent); struct hmc5843_data *data = iio_priv(indio_dev); s32 result; + int tries = 150; mutex_lock(&data->lock); - result = i2c_smbus_read_byte_data(client, HMC5843_STATUS_REG); - while (!(result & HMC5843_DATA_READY)) - result = i2c_smbus_read_byte_data(client, HMC5843_STATUS_REG); + while (tries-- > 0) { + result = i2c_smbus_read_byte_data(client, + HMC5843_STATUS_REG); + if (result & HMC5843_DATA_READY) + break; + msleep(20); + } + + if (tries < 0) { + dev_err(&client->dev, "data not ready\n"); + mutex_unlock(&data->lock); + return -EIO; + } result = i2c_smbus_read_word_data(client, address); mutex_unlock(&data->lock); |