diff options
author | Peter Meerwald <pmeerw@pmeerw.net> | 2012-05-17 00:28:08 (GMT) |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-05-17 15:24:55 (GMT) |
commit | 13f6eb69b15beeeaa720293c1281a14413363876 (patch) | |
tree | 05e8e3fb1a7152af198c406e57a3fe2d07676852 /drivers/staging/iio/magnetometer/hmc5843.c | |
parent | 64255031bde68bd0f7ec934b83842619d513cf91 (diff) | |
download | linux-fsl-qoriq-13f6eb69b15beeeaa720293c1281a14413363876.tar.xz |
staging: iio: rework sampling rate setting in hmc5843
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
Acked-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/iio/magnetometer/hmc5843.c')
-rw-r--r-- | drivers/staging/iio/magnetometer/hmc5843.c | 51 |
1 files changed, 24 insertions, 27 deletions
diff --git a/drivers/staging/iio/magnetometer/hmc5843.c b/drivers/staging/iio/magnetometer/hmc5843.c index 27c5521..cf2bab8 100644 --- a/drivers/staging/iio/magnetometer/hmc5843.c +++ b/drivers/staging/iio/magnetometer/hmc5843.c @@ -85,14 +85,6 @@ */ #define HMC5843_RATE_OFFSET 0x02 #define HMC5843_RATE_BITMASK 0x1C -#define RATE_5 0x00 -#define RATE_10 0x01 -#define RATE_20 0x02 -#define RATE_50 0x03 -#define RATE_100 0x04 -#define RATE_200 0x05 -#define RATE_500 0x06 - #define HMC5843_RATE_NOT_USED 0x07 /* @@ -342,6 +334,21 @@ static s32 hmc5843_set_rate(struct i2c_client *client, return i2c_smbus_write_byte_data(client, HMC5843_CONFIG_REG_A, reg_val); } +static int hmc5843_check_sampling_frequency(struct hmc5843_data *data, + const char *buf) +{ + const char * const *samp_freq = regval_to_samp_freq; + int i; + + for (i = 0; i < HMC5843_RATE_NOT_USED; i++) { + if (strncmp(buf, samp_freq[i], + strlen(samp_freq[i])) == 0) + return i; + } + + return -EINVAL; +} + static ssize_t set_sampling_frequency(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) @@ -350,27 +357,17 @@ static ssize_t set_sampling_frequency(struct device *dev, struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct i2c_client *client = to_i2c_client(indio_dev->dev.parent); struct hmc5843_data *data = iio_priv(indio_dev); - unsigned long rate = 0; - - if (strncmp(buf, "0.5" , 3) == 0) - rate = RATE_5; - else if (strncmp(buf, "1" , 1) == 0) - rate = RATE_10; - else if (strncmp(buf, "2", 1) == 0) - rate = RATE_20; - else if (strncmp(buf, "5", 1) == 0) - rate = RATE_50; - else if (strncmp(buf, "10", 2) == 0) - rate = RATE_100; - else if (strncmp(buf, "20" , 2) == 0) - rate = RATE_200; - else if (strncmp(buf, "50" , 2) == 0) - rate = RATE_500; - else - return -EINVAL; + int rate; + + rate = hmc5843_check_sampling_frequency(data, buf); + if (rate < 0) { + dev_err(&client->dev, + "sampling frequency is not supported\n"); + return rate; + } mutex_lock(&data->lock); - dev_dbg(dev, "set rate to %lu\n", rate); + dev_dbg(dev, "set rate to %d\n", rate); if (hmc5843_set_rate(client, rate)) { count = -EINVAL; goto exit; |