Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1519590

[PATCH 1/2] staging: iio: ad7606: replace range/range_available with corresponding scale

From Eva Rachel Retuya <eraretuya@gmail.com>
Newsgroups linux.kernel
Subject [PATCH 1/2] staging: iio: ad7606: replace range/range_available with corresponding scale
Date 2016-11-11 07:40 +0100
Message-ID <sCdFf-JU-3@gated-at.bofh.it> (permalink)
References <sCdFf-JU-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Eliminate the non-standard attribute in_voltage_range and move its
functionality under the scale attribute. read_raw() has been taken care
of previously so only write_raw() is handled here.

Additionally, rename the attribute in_voltage_range_available into
in_voltage_scale_available.

Suggested-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Eva Rachel Retuya <eraretuya@gmail.com>
---
 drivers/staging/iio/adc/ad7606.c | 56 ++++++++++++----------------------------
 1 file changed, 16 insertions(+), 40 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
index 4531908..cceb18c 100644
--- a/drivers/staging/iio/adc/ad7606.c
+++ b/drivers/staging/iio/adc/ad7606.c
@@ -161,42 +161,7 @@ static int ad7606_read_raw(struct iio_dev *indio_dev,
 	return -EINVAL;
 }
 
-static ssize_t ad7606_show_range(struct device *dev,
-				 struct device_attribute *attr, char *buf)
-{
-	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	struct ad7606_state *st = iio_priv(indio_dev);
-
-	return sprintf(buf, "%u\n", st->range);
-}
-
-static ssize_t ad7606_store_range(struct device *dev,
-				  struct device_attribute *attr,
-				  const char *buf, size_t count)
-{
-	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
-	struct ad7606_state *st = iio_priv(indio_dev);
-	unsigned long lval;
-	int ret;
-
-	ret = kstrtoul(buf, 10, &lval);
-	if (ret)
-		return ret;
-
-	if (!(lval == 5000 || lval == 10000))
-		return -EINVAL;
-
-	mutex_lock(&indio_dev->mlock);
-	gpiod_set_value(st->gpio_range, lval == 10000);
-	st->range = lval;
-	mutex_unlock(&indio_dev->mlock);
-
-	return count;
-}
-
-static IIO_DEVICE_ATTR(in_voltage_range, S_IRUGO | S_IWUSR,
-		       ad7606_show_range, ad7606_store_range, 0);
-static IIO_CONST_ATTR(in_voltage_range_available, "5000 10000");
+static IIO_CONST_ATTR(in_voltage_scale_available, "5000 10000");
 
 static int ad7606_oversampling_get_index(unsigned int val)
 {
@@ -221,6 +186,19 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,
 	int ret;
 
 	switch (mask) {
+	case IIO_CHAN_INFO_SCALE:
+		if (val2)
+			return -EINVAL;
+
+		if (!(val == 5000 || val == 10000))
+			return -EINVAL;
+
+		mutex_lock(&indio_dev->mlock);
+		gpiod_set_value(st->gpio_range, val == 10000);
+		st->range = val;
+		mutex_unlock(&indio_dev->mlock);
+
+		return 0;
 	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
 		if (val2)
 			return -EINVAL;
@@ -247,8 +225,7 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,
 static IIO_CONST_ATTR(oversampling_ratio_available, "1 2 4 8 16 32 64");
 
 static struct attribute *ad7606_attributes_os_and_range[] = {
-	&iio_dev_attr_in_voltage_range.dev_attr.attr,
-	&iio_const_attr_in_voltage_range_available.dev_attr.attr,
+	&iio_const_attr_in_voltage_scale_available.dev_attr.attr,
 	&iio_const_attr_oversampling_ratio_available.dev_attr.attr,
 	NULL,
 };
@@ -267,8 +244,7 @@ static const struct attribute_group ad7606_attribute_group_os = {
 };
 
 static struct attribute *ad7606_attributes_range[] = {
-	&iio_dev_attr_in_voltage_range.dev_attr.attr,
-	&iio_const_attr_in_voltage_range_available.dev_attr.attr,
+	&iio_const_attr_in_voltage_scale_available.dev_attr.attr,
 	NULL,
 };
 
-- 
2.7.4

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/2] staging: iio: ad7606: move driver out of staging Eva Rachel Retuya <eraretuya@gmail.com> - 2016-11-11 07:40 +0100
  [PATCH 1/2] staging: iio: ad7606: replace range/range_available with corresponding scale Eva Rachel Retuya <eraretuya@gmail.com> - 2016-11-11 07:40 +0100
    Re: [PATCH 1/2] staging: iio: ad7606: replace range/range_available  with corresponding scale Lars-Peter Clausen <lars@metafoo.de> - 2016-11-11 15:20 +0100
      Re: [PATCH 1/2] staging: iio: ad7606: replace range/range_available  with corresponding scale Jonathan Cameron <jic23@kernel.org> - 2016-11-12 15:30 +0100
        Re: [PATCH 1/2] staging: iio: ad7606: replace range/range_available  with corresponding scale Lars-Peter Clausen <lars@metafoo.de> - 2016-11-14 11:40 +0100
          Re: [PATCH 1/2] staging: iio: ad7606: replace range/range_available with corresponding scale Jonathan Cameron <jic23@jic23.retrosnub.co.uk> - 2016-11-14 18:30 +0100
        Re: [PATCH 1/2] staging: iio: ad7606: replace range/range_available  with corresponding scale Linus Walleij <linus.walleij@linaro.org> - 2016-11-14 18:00 +0100
          Re: [PATCH 1/2] staging: iio: ad7606: replace range/range_available  with corresponding scale Lars-Peter Clausen <lars@metafoo.de> - 2016-11-14 20:00 +0100
            Re: [PATCH 1/2] staging: iio: ad7606: replace range/range_available with corresponding scale Jonathan Cameron <jic23@jic23.retrosnub.co.uk> - 2016-11-14 23:20 +0100
            Re: [PATCH 1/2] staging: iio: ad7606: replace range/range_available  with corresponding scale Linus Walleij <linus.walleij@linaro.org> - 2016-11-15 00:20 +0100
              Re: [PATCH 1/2] staging: iio: ad7606: replace range/range_available  with corresponding scale Jonathan Cameron <jic23@kernel.org> - 2016-11-19 13:40 +0100
      Re: [PATCH 1/2] staging: iio: ad7606: replace range/range_available  with corresponding scale Eva Rachel Retuya <eraretuya@gmail.com> - 2016-11-12 15:50 +0100
        Re: [PATCH 1/2] staging: iio: ad7606: replace range/range_available  with corresponding scale Lars-Peter Clausen <lars@metafoo.de> - 2016-11-14 11:30 +0100
  Re: [PATCH 2/2] staging: iio: ad7606: move out of staging Lars-Peter Clausen <lars@metafoo.de> - 2016-11-11 15:30 +0100
    Re: [PATCH 2/2] staging: iio: ad7606: move out of staging Jonathan Cameron <jic23@kernel.org> - 2016-11-12 15:30 +0100
      Re: [PATCH 2/2] staging: iio: ad7606: move out of staging Eva Rachel Retuya <eraretuya@gmail.com> - 2016-11-12 15:40 +0100
        Re: [PATCH 2/2] staging: iio: ad7606: move out of staging Jonathan Cameron <jic23@kernel.org> - 2016-11-12 15:50 +0100

csiph-web