linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Slawomir Stepien <sst@poczta.fm>
To: jic23@kernel.org, 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: Sat, 9 Apr 2016 13:12:24 +0200	[thread overview]
Message-ID: <20160409111224.GA1789@x220> (raw)
In-Reply-To: <20160408212725.GA10249@x220>

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];

	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?

-- 
Slawomir Stepien

  reply	other threads:[~2016-04-09 11:12 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 [this message]
2016-04-10 11:07   ` Jonathan Cameron
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=20160409111224.GA1789@x220 \
    --to=sst@poczta.fm \
    --cc=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 \
    /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).