From: Jonathan Cameron <jic23@kernel.org>
To: Peter Meerwald <pmeerw@pmeerw.net>
Cc: linux-iio@vger.kernel.org
Subject: Re: [PATCH 2/4] iio: adjd_s311: Use INT_TIME channel info
Date: Sat, 14 Sep 2013 12:15:25 +0100 [thread overview]
Message-ID: <5234454D.8070505@kernel.org> (raw)
In-Reply-To: <1378653659-15665-3-git-send-email-pmeerw@pmeerw.net>
On 09/08/13 16:20, Peter Meerwald wrote:
> Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
Applied to the togreg branch of iio.git
While we are here, Hardware gain is not being correctly used here. That is only
documented for output devices. For input it probably corresponds to calibscale
but I haven't looked in any real detail. Ah well, this is in the ABI now
so even if we fix it we'll have to carry this interface for quite some time anyway.
Jonathan
> ---
> drivers/iio/light/adjd_s311.c | 72 ++++++++++++-----------------------------
> 1 file changed, 21 insertions(+), 51 deletions(-)
>
> diff --git a/drivers/iio/light/adjd_s311.c b/drivers/iio/light/adjd_s311.c
> index 23cff79..8853251 100644
> --- a/drivers/iio/light/adjd_s311.c
> +++ b/drivers/iio/light/adjd_s311.c
> @@ -114,43 +114,6 @@ static int adjd_s311_read_data(struct iio_dev *indio_dev, u8 reg, int *val)
> return 0;
> }
>
> -static ssize_t adjd_s311_read_int_time(struct iio_dev *indio_dev,
> - uintptr_t private, const struct iio_chan_spec *chan, char *buf)
> -{
> - struct adjd_s311_data *data = iio_priv(indio_dev);
> - s32 ret;
> -
> - ret = i2c_smbus_read_word_data(data->client,
> - ADJD_S311_INT_REG(chan->address));
> - if (ret < 0)
> - return ret;
> -
> - return sprintf(buf, "%d\n", ret & ADJD_S311_INT_MASK);
> -}
> -
> -static ssize_t adjd_s311_write_int_time(struct iio_dev *indio_dev,
> - uintptr_t private, const struct iio_chan_spec *chan, const char *buf,
> - size_t len)
> -{
> - struct adjd_s311_data *data = iio_priv(indio_dev);
> - unsigned long int_time;
> - int ret;
> -
> - ret = kstrtoul(buf, 10, &int_time);
> - if (ret)
> - return ret;
> -
> - if (int_time > ADJD_S311_INT_MASK)
> - return -EINVAL;
> -
> - ret = i2c_smbus_write_word_data(data->client,
> - ADJD_S311_INT_REG(chan->address), int_time);
> - if (ret < 0)
> - return ret;
> -
> - return len;
> -}
> -
> static irqreturn_t adjd_s311_trigger_handler(int irq, void *p)
> {
> struct iio_poll_func *pf = p;
> @@ -186,25 +149,16 @@ done:
> return IRQ_HANDLED;
> }
>
> -static const struct iio_chan_spec_ext_info adjd_s311_ext_info[] = {
> - {
> - .name = "integration_time",
> - .read = adjd_s311_read_int_time,
> - .write = adjd_s311_write_int_time,
> - },
> - { }
> -};
> -
> #define ADJD_S311_CHANNEL(_color, _scan_idx) { \
> .type = IIO_INTENSITY, \
> .modified = 1, \
> .address = (IDX_##_color), \
> .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
> - BIT(IIO_CHAN_INFO_HARDWAREGAIN), \
> + BIT(IIO_CHAN_INFO_HARDWAREGAIN) | \
> + BIT(IIO_CHAN_INFO_INT_TIME), \
> .channel2 = (IIO_MOD_LIGHT_##_color), \
> .scan_index = (_scan_idx), \
> .scan_type = IIO_ST('u', 10, 16, 0), \
> - .ext_info = adjd_s311_ext_info, \
> }
>
> static const struct iio_chan_spec adjd_s311_channels[] = {
> @@ -236,6 +190,18 @@ static int adjd_s311_read_raw(struct iio_dev *indio_dev,
> return ret;
> *val = ret & ADJD_S311_CAP_MASK;
> return IIO_VAL_INT;
> + case IIO_CHAN_INFO_INT_TIME:
> + ret = i2c_smbus_read_word_data(data->client,
> + ADJD_S311_INT_REG(chan->address));
> + if (ret < 0)
> + return ret;
> + *val = 0;
> + /*
> + * not documented, based on measurement:
> + * 4095 LSBs correspond to roughly 4 ms
> + */
> + *val2 = ret & ADJD_S311_INT_MASK;
> + return IIO_VAL_INT_PLUS_MICRO;
> }
> return -EINVAL;
> }
> @@ -245,16 +211,20 @@ static int adjd_s311_write_raw(struct iio_dev *indio_dev,
> int val, int val2, long mask)
> {
> struct adjd_s311_data *data = iio_priv(indio_dev);
> - int ret;
>
> switch (mask) {
> case IIO_CHAN_INFO_HARDWAREGAIN:
> if (val < 0 || val > ADJD_S311_CAP_MASK)
> return -EINVAL;
>
> - ret = i2c_smbus_write_byte_data(data->client,
> + return i2c_smbus_write_byte_data(data->client,
> ADJD_S311_CAP_REG(chan->address), val);
> - return ret;
> + case IIO_CHAN_INFO_INT_TIME:
> + if (val != 0 || val2 < 0 || val2 > ADJD_S311_INT_MASK)
> + return -EINVAL;
> +
> + return i2c_smbus_write_word_data(data->client,
> + ADJD_S311_INT_REG(chan->address), val2);
> }
> return -EINVAL;
> }
>
next prev parent reply other threads:[~2013-09-14 10:15 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-08 15:20 [PATCH 0/4] add INT_TIME and drivers using it Peter Meerwald
2013-09-08 15:20 ` [PATCH 1/4] iio: Add INT_TIME (integration time) channel info attribute Peter Meerwald
2013-09-14 11:11 ` Jonathan Cameron
2013-09-08 15:20 ` [PATCH 2/4] iio: adjd_s311: Use INT_TIME channel info Peter Meerwald
2013-09-14 11:15 ` Jonathan Cameron [this message]
2013-09-08 15:20 ` [PATCH 3/4] iio: Add tsl4531 ambient light sensor driver Peter Meerwald
2013-09-14 11:21 ` Jonathan Cameron
2013-09-14 19:13 ` Peter Meerwald
2013-09-14 20:18 ` Jonathan Cameron
2013-09-08 15:20 ` [PATCH 4/4] iio: Add tcs3472 color " Peter Meerwald
2013-09-14 11:42 ` Jonathan Cameron
2013-09-14 19:38 ` [PATCH v2] " Peter Meerwald
2013-09-14 20:46 ` Jonathan Cameron
2013-09-15 15:51 ` Peter Meerwald
2013-09-15 15:52 ` [PATCH] iio: Fix tcs3472 buffer size Peter Meerwald
2013-09-15 16:54 ` 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=5234454D.8070505@kernel.org \
--to=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=pmeerw@pmeerw.net \
/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).