From: Lars-Peter Clausen <lars@metafoo.de>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Greg Kroah-Hartman <gregkh@suse.de>,
devel@driverdev.osuosl.org, drivers@analog.com,
Michael Hennerich <michael.hennerich@analog.com>,
linux-iio@vger.kernel.org, Jonathan Cameron <jic23@cam.ac.uk>,
device-drivers-devel@blackfin.uclinux.org
Subject: Re: [PATCH 2/4] staging:iio:dac:ad5791: Allow asymmetrical reference voltages
Date: Thu, 20 Oct 2011 08:54:16 +0200 [thread overview]
Message-ID: <4E9FC598.10306@metafoo.de> (raw)
In-Reply-To: <20111019210429.GF24215@longonot.mountain>
On 10/19/2011 11:04 PM, Dan Carpenter wrote:
> On Wed, Oct 19, 2011 at 05:47:50PM +0200, Lars-Peter Clausen wrote:
>> @@ -225,6 +226,7 @@ static int ad5791_read_raw(struct iio_dev *indio_dev,
>> long m)
>> {
>> struct ad5791_state *st = iio_priv(indio_dev);
>> + u64 val64;
>> int ret;
>>
>> switch (m) {
>> @@ -234,12 +236,16 @@ static int ad5791_read_raw(struct iio_dev *indio_dev,
>> return ret;
>> *val &= AD5791_DAC_MASK;
>> *val >>= chan->scan_type.shift;
>> - *val -= (1 << (chan->scan_type.realbits - 1));
>> return IIO_VAL_INT;
>> case (1 << IIO_CHAN_INFO_SCALE_SHARED):
>> *val = 0;
>> *val2 = (st->vref_mv * 1000) >> chan->scan_type.realbits;
>> return IIO_VAL_INT_PLUS_MICRO;
>> + case (1 << IIO_CHAN_INFO_OFFSET_SHARED):
>> + val64 = (((u64)st->vref_neg_mv) << chan->scan_type.realbits);
>> + do_div(val64, st->vref_mv);
>> + *val = -val64;
>> + return IIO_VAL_INT;
>
> Why does iio use switch over a bitfield? If the values are mutually
> exclusive then why not just use an enum?
>
I wondered the very same and couldn't find a good explanation. I wanted to
write a small RFC today converting the core and maybe 2-3 drivers to use the
unshifted variants to see what Jonathan thinks about it.
> Hm... "m" stands for mask and it gets created using the
> IIO_UNMOD_EVENT_CODE() macro or sometimes it's just one bit at a
> time copied from &chan->info_mask... Odd.
>
IIO_UNMOD_EVENT_CODE is only used for events which use a different callback
function, so for the read_raw/write_raw callbacks we currently only ever
pass one channel info type at a time.
- Lars
next prev parent reply other threads:[~2011-10-20 6:53 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-19 15:47 [PATCH 1/4] staging:iio:dac:ad5791: Use correct DAC bit-size Lars-Peter Clausen
2011-10-19 15:47 ` [PATCH 2/4] staging:iio:dac:ad5791: Allow asymmetrical reference voltages Lars-Peter Clausen
2011-10-19 21:04 ` Dan Carpenter
2011-10-20 6:54 ` Lars-Peter Clausen [this message]
2011-10-20 7:58 ` Jonathan Cameron
2011-10-19 15:47 ` [PATCH 3/4] staging:iio:dac:ad5791: Convert attributes to new naming spec Lars-Peter Clausen
2011-10-19 15:47 ` [PATCH 4/4] staging:iio:dac:ad5791: Fix scale unit Lars-Peter Clausen
-- strict thread matches above, loose matches on Subject: below --
2011-10-19 12:23 [PATCH 1/4] staging:iio:dac:ad5791: Use correct DAC bit-size Lars-Peter Clausen
2011-10-19 12:23 ` [PATCH 2/4] staging:iio:dac:ad5791: Allow asymmetrical reference voltages Lars-Peter Clausen
2011-10-19 13:01 ` Jonathan Cameron
2011-10-19 13:21 ` Lars-Peter Clausen
2011-10-19 13:39 ` 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=4E9FC598.10306@metafoo.de \
--to=lars@metafoo.de \
--cc=dan.carpenter@oracle.com \
--cc=devel@driverdev.osuosl.org \
--cc=device-drivers-devel@blackfin.uclinux.org \
--cc=drivers@analog.com \
--cc=gregkh@suse.de \
--cc=jic23@cam.ac.uk \
--cc=linux-iio@vger.kernel.org \
--cc=michael.hennerich@analog.com \
/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.