From: Jonathan Cameron <jic23@kernel.org>
To: Guenter Roeck <linux@roeck-us.net>
Cc: linux-iio@vger.kernel.org, devicetree-discuss@lists.ozlabs.org,
Naveen Krishna Chatradhi <ch.naveen@samsung.com>,
Lars-Peter Clausen <lars@metafoo.de>,
Doug Anderson <dianders@chromium.org>,
Tomasz Figa <tomasz.figa@gmail.com>,
Grant Likely <grant.likely@secretlab.ca>,
Rob Herring <rob.herring@calxeda.com>
Subject: Re: [PATCH 07/11] iio/adc: (max1363) Fix data conversion problems
Date: Sat, 02 Feb 2013 10:08:48 +0000 [thread overview]
Message-ID: <510CE5B0.3050207@kernel.org> (raw)
In-Reply-To: <1359668588-13678-8-git-send-email-linux@roeck-us.net>
On 01/31/2013 09:43 PM, Guenter Roeck wrote:
> For chips with more than 8 bit ADC resolution, received data was always
> masked against 0xfff, ie with a 12 bit mask. This can result in bad data
> for chips with 10 bit resolution if those chips have higher bits set
> (seen with MAX1139).
>
> The receive buffer was defined as char array. This could result in
> unintentional sign extensions if the upper bit in a received byte
> was set. Since the chip is configured for unipolar mode, we never
> have to handle negative values, and sign extensions are never needed.
>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Applied to togreg branch of iio.git
> ---
> drivers/iio/adc/max1363.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c
> index 2c773b4..fdc8be9 100644
> --- a/drivers/iio/adc/max1363.c
> +++ b/drivers/iio/adc/max1363.c
> @@ -334,7 +334,7 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev,
> {
> int ret = 0;
> s32 data;
> - char rxbuf[2];
> + u8 rxbuf[2];
> struct max1363_state *st = iio_priv(indio_dev);
> struct i2c_client *client = st->client;
>
> @@ -366,7 +366,8 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev,
> ret = data;
> goto error_ret;
> }
> - data = (s32)(rxbuf[1]) | ((s32)(rxbuf[0] & 0x0F)) << 8;
> + data = (rxbuf[1] | rxbuf[0] << 8) &
> + ((1 << st->chip_info->bits) - 1);
> } else {
> /* Get reading */
> data = i2c_master_recv(client, rxbuf, 1);
>
next prev parent reply other threads:[~2013-02-02 10:08 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-31 21:42 [RFC 00/11] staging/iio: Devicetree support Guenter Roeck
2013-01-31 21:42 ` [PATCH 01/11] staging/iio: (iio_hwmon) Use devm_kzalloc Guenter Roeck
2013-02-02 9:50 ` Jonathan Cameron
2013-01-31 21:42 ` [PATCH 02/11] staging/iio: (iio_hwmon) Add support for sysfs name attribute Guenter Roeck
2013-02-02 9:52 ` Jonathan Cameron
2013-01-31 21:43 ` [PATCH 03/11] staging/iio: (iio_hwmon) Basic devicetree support Guenter Roeck
2013-02-02 9:54 ` Jonathan Cameron
2013-01-31 21:43 ` [PATCH 04/11] iio/adc: (lp8788) Provide OF node information to iio device Guenter Roeck
2013-02-02 9:55 ` Jonathan Cameron
2013-01-31 21:43 ` [PATCH 05/11] iio/adc: (max1363) " Guenter Roeck
2013-02-02 10:06 ` Jonathan Cameron
2013-01-31 21:43 ` [PATCH 06/11] iio/adc: (max1363) Remove duplicate code Guenter Roeck
2013-02-02 10:07 ` Jonathan Cameron
2013-01-31 21:43 ` [PATCH 07/11] iio/adc: (max1363) Fix data conversion problems Guenter Roeck
2013-02-02 10:08 ` Jonathan Cameron [this message]
2013-01-31 21:43 ` [RFC 08/11] iio: Update iio_channel_get_all and iio_channel_get_all_cb API Guenter Roeck
2013-02-02 10:14 ` Jonathan Cameron
2013-01-31 21:43 ` [RFC 09/11] iio: Simplify iio_map_array_unregister API Guenter Roeck
2013-02-02 10:16 ` Jonathan Cameron
2013-01-31 21:43 ` [RFC 10/11] iio: Add OF support Guenter Roeck
2013-01-31 22:20 ` Peter Meerwald
2013-01-31 22:46 ` Guenter Roeck
2013-02-01 11:58 ` Lars-Peter Clausen
2013-02-01 14:33 ` Guenter Roeck
2013-02-01 14:59 ` Lars-Peter Clausen
2013-02-01 19:42 ` Guenter Roeck
2013-02-02 14:37 ` Lars-Peter Clausen
2013-02-02 16:14 ` Guenter Roeck
2013-02-02 10:29 ` Jonathan Cameron
2013-02-02 16:10 ` Guenter Roeck
2013-02-03 11:39 ` Jonathan Cameron
2013-02-03 11:47 ` Lars-Peter Clausen
2013-02-03 11:52 ` Lars-Peter Clausen
2013-02-03 11:57 ` Jonathan Cameron
2013-02-03 16:28 ` Guenter Roeck
2013-01-31 21:43 ` [RFC 11/11] iio/adc: (max1363) Add basic OF bindings and external vref support Guenter Roeck
2013-02-02 10:33 ` Jonathan Cameron
2013-02-02 16:13 ` Guenter Roeck
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=510CE5B0.3050207@kernel.org \
--to=jic23@kernel.org \
--cc=ch.naveen@samsung.com \
--cc=devicetree-discuss@lists.ozlabs.org \
--cc=dianders@chromium.org \
--cc=grant.likely@secretlab.ca \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=rob.herring@calxeda.com \
--cc=tomasz.figa@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox