From: Jonathan Cameron <jic23@kernel.org>
To: Slawomir Stepien <sst@poczta.fm>,
knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] iio: potentiometer: add driver for Maxim Integrated DS1803
Date: Sun, 10 Apr 2016 12:07:24 +0100 [thread overview]
Message-ID: <570A33EC.1060602@kernel.org> (raw)
In-Reply-To: <20160409111224.GA1789@x220>
On 09/04/16 12:12, Slawomir Stepien wrote:
> On Apr 08, 2016 23:27, Slawomir Stepien wrote:
>> +static int ds1803_read_raw(struct iio_dev *indio_dev,
>> + struct iio_chan_spec const *chan,
>> + int *val, int *val2, long mask)
>> +{
>> + struct ds1803_data *data = iio_priv(indio_dev);
>> + int pot = chan->channel;
>> + int ret;
>> + u16 result;
>> +
>> + switch (mask) {
>> + case IIO_CHAN_INFO_RAW:
>> + ret = i2c_master_recv(data->client, (char *)&result,
>> + indio_dev->num_channels);
>> + if (ret < 0)
>> + return ret;
>> +
>> + /* Get bits for given pot */
>> + *val = (pot == 0 ? result & 0xff : result >> 8);
>> + return IIO_VAL_INT;
>> +
>> + case IIO_CHAN_INFO_SCALE:
>> + *val = 1000 * data->cfg->kohms;
>> + *val2 = DS1803_MAX_POS;
>> + return IIO_VAL_FRACTIONAL;
>> + }
>> +
>> + return -EINVAL;
>> +}
>
> Or maybe this is more clean?
>
> static int ds1803_read_raw(struct iio_dev *indio_dev,
> struct iio_chan_spec const *chan,
> int *val, int *val2, long mask)
> {
> struct ds1803_data *data = iio_priv(indio_dev);
> int pot = chan->channel;
> int ret;
> unsigned char result[indio_dev->num_channels];
I'd use u8 to make it of an explicit size but otherwise this is indeed
a little bit cleaner.
>
> switch (mask) {
> case IIO_CHAN_INFO_RAW:
> ret = i2c_master_recv(data->client, result,
> indio_dev->num_channels);
> if (ret < 0)
> return ret;
>
> *val = result[pot];
> return IIO_VAL_INT;
>
> case IIO_CHAN_INFO_SCALE:
> *val = 1000 * data->cfg->kohms;
> *val2 = DS1803_MAX_POS;
> return IIO_VAL_FRACTIONAL;
> }
>
> return -EINVAL;
> }
>
> What do you think?
>
next prev parent reply other threads:[~2016-04-10 11:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-08 21:27 [PATCH v2] iio: potentiometer: add driver for Maxim Integrated DS1803 Slawomir Stepien
2016-04-09 11:12 ` Slawomir Stepien
2016-04-10 11:07 ` Jonathan Cameron [this message]
2016-04-10 11:13 ` 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=570A33EC.1060602@kernel.org \
--to=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pmeerw@pmeerw.net \
--cc=sst@poczta.fm \
/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.