From: Jonathan Cameron <jic23@kernel.org>
To: linux-iio@vger.kernel.org
Cc: lars@metafoo.de, Jonathan Cameron <jic23@kernel.org>
Subject: [PATCH 04/11] iio:accel:kxsd9 use new read_avail to replace accel_scan_available.
Date: Sun, 17 Nov 2013 15:14:55 +0000 [thread overview]
Message-ID: <1384701302-26564-5-git-send-email-jic23@kernel.org> (raw)
In-Reply-To: <1384701302-26564-1-git-send-email-jic23@kernel.org>
Note that there is a small abi change in here as we will gain an in_
prefix on the accel_scan_available. We have tightened the abi in recent
times so that the in_ prefix is no the standard thing to do.
This change is probably in the if no one notices, it doesn't count as
breakage category.
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
drivers/iio/accel/kxsd9.c | 52 ++++++++++++++++++++++++-----------------------
1 file changed, 27 insertions(+), 25 deletions(-)
diff --git a/drivers/iio/accel/kxsd9.c b/drivers/iio/accel/kxsd9.c
index d72118d1189c..d99601f4219b 100644
--- a/drivers/iio/accel/kxsd9.c
+++ b/drivers/iio/accel/kxsd9.c
@@ -57,13 +57,28 @@ struct kxsd9_state {
u8 tx[KXSD9_STATE_TX_SIZE];
};
-#define KXSD9_SCALE_2G "0.011978"
-#define KXSD9_SCALE_4G "0.023927"
-#define KXSD9_SCALE_6G "0.035934"
-#define KXSD9_SCALE_8G "0.047853"
-
-/* reverse order */
-static const int kxsd9_micro_scales[4] = { 47853, 35934, 23927, 11978 };
+static const int kxsd9_scales[] = { 0, 11978,
+ 0, 23927,
+ 0, 35934,
+ 0, 47853 };
+
+static int kxsd9_read_avail(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ const int **vals,
+ int *type,
+ int *length,
+ long mask_el)
+{
+ switch (mask_el) {
+ case IIO_CHAN_INFO_SCALE:
+ *length = ARRAY_SIZE(kxsd9_scales);
+ *vals = kxsd9_scales;
+ *type = IIO_VAL_INT_PLUS_MICRO;
+ return IIO_AVAIL_LIST;
+ default:
+ return -EINVAL;
+ }
+}
static int kxsd9_write_scale(struct iio_dev *indio_dev, int micro)
{
@@ -72,7 +87,7 @@ static int kxsd9_write_scale(struct iio_dev *indio_dev, int micro)
bool foundit = false;
for (i = 0; i < 4; i++)
- if (micro == kxsd9_micro_scales[i]) {
+ if (micro == kxsd9_scales[ (3 - i) * 2 + 1]) {
foundit = true;
break;
}
@@ -117,17 +132,6 @@ static int kxsd9_read(struct iio_dev *indio_dev, u8 address)
return (((u16)(st->rx[0])) << 8) | (st->rx[1] & 0xF0);
}
-static IIO_CONST_ATTR(accel_scale_available,
- KXSD9_SCALE_2G " "
- KXSD9_SCALE_4G " "
- KXSD9_SCALE_6G " "
- KXSD9_SCALE_8G);
-
-static struct attribute *kxsd9_attributes[] = {
- &iio_const_attr_accel_scale_available.dev_attr.attr,
- NULL,
-};
-
static int kxsd9_write_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int val,
@@ -164,7 +168,7 @@ static int kxsd9_read_raw(struct iio_dev *indio_dev,
ret = spi_w8r8(st->us, KXSD9_READ(KXSD9_REG_CTRL_C));
if (ret)
goto error_ret;
- *val2 = kxsd9_micro_scales[ret & KXSD9_FS_MASK];
+ *val2 = kxsd9_scales[(3 - (ret & KXSD9_FS_MASK))* 2 + 1];
ret = IIO_VAL_INT_PLUS_MICRO;
break;
}
@@ -179,6 +183,8 @@ error_ret:
.channel2 = IIO_MOD_##axis, \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
+ .info_mask_shared_by_type_available = \
+ BIT(IIO_CHAN_INFO_SCALE), \
.address = KXSD9_REG_##axis, \
}
@@ -192,10 +198,6 @@ static const struct iio_chan_spec kxsd9_channels[] = {
}
};
-static const struct attribute_group kxsd9_attribute_group = {
- .attrs = kxsd9_attributes,
-};
-
static int kxsd9_power_up(struct kxsd9_state *st)
{
int ret;
@@ -213,8 +215,8 @@ static int kxsd9_power_up(struct kxsd9_state *st)
static const struct iio_info kxsd9_info = {
.read_raw = &kxsd9_read_raw,
+ .read_avail = &kxsd9_read_avail,
.write_raw = &kxsd9_write_raw,
- .attrs = &kxsd9_attribute_group,
.driver_module = THIS_MODULE,
};
--
1.8.4.2
next prev parent reply other threads:[~2013-11-17 14:14 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-17 15:14 [RFC PATCH 00/11] IIO: Add core support for _available interfaces Jonathan Cameron
2013-11-17 15:14 ` [PATCH 01/11] iio:core: add a callback to allow drivers to provide _available attributes Jonathan Cameron
2013-11-17 15:14 ` [PATCH 02/11] staging:iio:dummy driver: Add example usecases for the new *_available interface Jonathan Cameron
2013-11-17 15:14 ` [PATCH 03/11] iio:accel:bma180 use new read_avail to replace *_available attrs Jonathan Cameron
2013-11-17 15:14 ` Jonathan Cameron [this message]
2013-11-17 15:14 ` [PATCH 05/11] iio:st sensors: remove custom sampling frequence attribute in favour of core support Jonathan Cameron
2013-11-18 18:25 ` Lars-Peter Clausen
2013-11-17 15:14 ` [PATCH 06/11] iio: ad_sigma_delta provide macro parameters for available info masks Jonathan Cameron
2013-11-17 15:14 ` [PATCH 07/11] iio:adc:ad7793: use samp_freq element of info_mask_shared_by_all Jonathan Cameron
2013-11-18 18:29 ` Lars-Peter Clausen
2013-11-18 20:52 ` Jonathan Cameron
2013-11-17 15:14 ` [PATCH 08/11] iio:adc:ad7793: Use the read_avail callback to provide the scale and sampling frequency interfaces Jonathan Cameron
2013-11-17 15:15 ` [PATCH 09/11] iio:adc:ad7791 Provide sampling frequency and scale_available access via core Jonathan Cameron
2013-11-17 15:15 ` [PATCH 10/11] staging:iio:adc:ad7192 use infomask* to provide access to sampling frequency and scale_available Jonathan Cameron
2013-11-17 15:15 ` [PATCH 11/11] iio:adc:mcp3422: use core to provide _available information rather than custom attrs 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=1384701302-26564-5-git-send-email-jic23@kernel.org \
--to=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.