From: Peter Meerwald <pmeerw@pmeerw.net>
To: linux-iio@vger.kernel.org
Cc: Peter Meerwald <pmeerw@pmeerw.net>,
Shubhrajyoti Datta <shubhrajyoti@ti.com>
Subject: [PATCH 3/9] staging:iio:hmc5843: Implement timeout in read function
Date: Sat, 27 Jul 2013 17:31:46 +0200 [thread overview]
Message-ID: <1374939112-18237-4-git-send-email-pmeerw@pmeerw.net> (raw)
In-Reply-To: <1374939112-18237-1-git-send-email-pmeerw@pmeerw.net>
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>
---
drivers/staging/iio/magnetometer/hmc5843.c | 18 +++++++++++++++---
1 file 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);
--
1.8.3.4
next prev parent reply other threads:[~2013-07-27 15:32 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-27 15:31 Peter Meerwald
2013-07-27 15:31 ` [PATCH 1/9] staging:iio:hmc5843: Drop I2C detection code Peter Meerwald
2013-08-04 10:01 ` Jonathan Cameron
2013-07-27 15:31 ` [PATCH 2/9] staging:iio:hmc5843: Remove id register #defines, not used anymore Peter Meerwald
2013-08-04 10:02 ` Jonathan Cameron
2013-07-27 15:31 ` Peter Meerwald [this message]
2013-08-04 10:03 ` [PATCH 3/9] staging:iio:hmc5843: Implement timeout in read function Jonathan Cameron
2013-07-27 15:31 ` [PATCH 4/9] staging:iio:hmc5843: 'add' is a poor abbreviation for address Peter Meerwald
2013-08-04 10:04 ` Jonathan Cameron
2013-07-27 15:31 ` [PATCH 5/9] staging:iio:hmc5843: Device has 3 channels, no need to store separately Peter Meerwald
2013-08-04 10:10 ` Jonathan Cameron
2013-07-27 15:31 ` [PATCH 6/9] staging:iio:hmc5843: Trim sampling_frequencies to sampling_freq Peter Meerwald
2013-07-27 18:01 ` Jonathan Cameron
2013-08-04 10:13 ` Jonathan Cameron
2013-07-27 15:31 ` [PATCH 7/9] staging:iio:hmc5843: Split and join lines to make checkpatch happy Peter Meerwald
2013-08-04 10:15 ` Jonathan Cameron
2013-07-27 15:31 ` [PATCH 8/9] staging:iio:hmc5843: Drop unneeded #includes Peter Meerwald
2013-08-04 10:22 ` Jonathan Cameron
2013-07-27 15:31 ` [PATCH 9/9] staging:iio:hmc5843: Use i2c_smbus_read_word_swapped() Peter Meerwald
2013-08-04 10:23 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1374939112-18237-4-git-send-email-pmeerw@pmeerw.net \
--to=pmeerw@pmeerw.net \
--cc=linux-iio@vger.kernel.org \
--cc=shubhrajyoti@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).