Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1374737
| From | Jonathan Cameron <jic23@kernel.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH v2] iio: potentiometer: add driver for Maxim Integrated DS1803 |
| Date | 2016-04-10 13:10 +0200 |
| Message-ID | <rmlpE-3YS-3@gated-at.bofh.it> (permalink) |
| References | <rlM8y-1zv-15@gated-at.bofh.it> <rlZ5L-41P-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
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?
>
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v2] iio: potentiometer: add driver for Maxim Integrated DS1803 Slawomir Stepien <sst@poczta.fm> - 2016-04-08 23:30 +0200
Re: [PATCH v2] iio: potentiometer: add driver for Maxim Integrated DS1803 Slawomir Stepien <sst@poczta.fm> - 2016-04-09 13:20 +0200
Re: [PATCH v2] iio: potentiometer: add driver for Maxim Integrated DS1803 Jonathan Cameron <jic23@kernel.org> - 2016-04-10 13:10 +0200
Re: [PATCH v2] iio: potentiometer: add driver for Maxim Integrated DS1803 Jonathan Cameron <jic23@kernel.org> - 2016-04-10 13:20 +0200
csiph-web