All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Jonathan Cameron <jic23@kernel.org>
Cc: linux-iio@vger.kernel.org, Jonathan Cameron <jic23@cam.ac.uk>
Subject: Re: [PATCH 4/4] staging:iio: Proof of concept input driver.
Date: Fri, 08 Jun 2012 17:27:21 +0200	[thread overview]
Message-ID: <4FD219D9.5010008@metafoo.de> (raw)
In-Reply-To: <1338406594-14550-5-git-send-email-jic23@kernel.org>

On 05/30/2012 09:36 PM, Jonathan Cameron wrote:
> From: Jonathan Cameron <jic23@cam.ac.uk>
> 
> This is no where near ready to merge.  Lots of stuff missing.
> 
> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
> ---
>  drivers/staging/iio/Kconfig     |   11 +++
>  drivers/staging/iio/Makefile    |    1 +
>  drivers/staging/iio/iio_input.c |  176 +++++++++++++++++++++++++++++++++++++++
>  drivers/staging/iio/iio_input.h |   23 +++++
>  4 files changed, 211 insertions(+)
> 
> diff --git a/drivers/staging/iio/Kconfig b/drivers/staging/iio/Kconfig
> index 04cd6ec..022463e 100644
> --- a/drivers/staging/iio/Kconfig
> +++ b/drivers/staging/iio/Kconfig
> @@ -4,6 +4,17 @@
[...]
> +};
> +
> +static int iio_channel_value(u8 *data,
> +			     const struct iio_chan_spec *chan,
> +			     int *val)
> +{
> +	int value;
> +
> +	if (chan->scan_type.sign == 's') {
> +		switch (chan->scan_type.storagebits) {
> +		case 8:
> +			value = *(s8 *)(data);
> +			break;
> +		case 16:
> +			value = *(s16 *)(data);
> +			break;
> +		case 32:
> +			value = *(s32 *)(data);
> +			break;
> +		default:
> +			return -EINVAL;
> +		}
> +		value >>= chan->scan_type.shift;
> +		value &= (1 << chan->scan_type.realbits) - 1;
> +		value = (value << (sizeof(value)*8 - chan->scan_type.realbits))
> +			>> (sizeof(value)*8 - chan->scan_type.realbits);

This looks scarey. There is a sign_extend32 function. It probably makes
sense to add one which works on ints. Btw. I think until the sign extension
the type should still be unsigned. This will also get rid of the duplicated
code.

> +	} else {
> +		switch (chan->scan_type.storagebits) {
> +		case 8:
> +			value = *(u8 *)(data);
> +			break;
> +		case 16:
> +			value = *(u16 *)(data);
> +			break;
> +		case 32:
> +			value = *(u32 *)(data);
> +			break;
> +		default:
> +			return -EINVAL;
> +		}
> +		value >>= chan->scan_type.shift;
> +		value &= (1 << chan->scan_type.realbits) - 1;
> +	}
> +	*val = value;

This function probably needs to be extended to deal with the endianness
field of the scan type at some point.
> +
> +	return 0;
> +}
> +
> +static int iio_input_store_to(u8 *data, void *private)
> +{
> +	struct iio_input_state *st = private;
> +	struct iio_channel *channel;
> +	struct iio_input_channel_data *input_data;
> +	int offset = 0;
> +	int value, ret;
> +
> +	channel = iio_channel_cb_get_channels(st->buff);
> +	while (channel->indio_dev) {
> +		input_data = channel->data;
> +		offset = ALIGN(offset,
> +			       channel->channel->scan_type.storagebits/8);
> +		offset += channel->channel->scan_type.storagebits/8;

Maybe I'm missing something, but shouldn't offset be increased after reading
the data?

> +		ret = iio_channel_value(&data[offset],
> +					channel->channel,
> +					&value);
> +		if (ret < 0)
> +			return ret;
> +		input_report_abs(st->idev, input_data->code, value);
> +	}
> +	input_sync(st->idev);
> +
> +	return 0;
> +}
> +
[...]

  reply	other threads:[~2012-06-08 15:27 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-30 19:36 [PATCH 0/4 V2] staging:iio: Add support for multiple buffers Jonathan Cameron
2012-05-30 19:36 ` [PATCH 1/4] " Jonathan Cameron
2012-06-08 15:13   ` Lars-Peter Clausen
2012-06-09 12:17     ` Jonathan Cameron
2012-06-09 11:50       ` Lars-Peter Clausen
2012-06-09 17:56         ` Jonathan Cameron
2012-05-30 19:36 ` [PATCH 2/4] staging:iio:in kernel users: Add a data field for channel specific info Jonathan Cameron
2012-05-30 19:36 ` [PATCH 3/4] staging:iio: add a callback buffer for in kernel push interface Jonathan Cameron
2012-05-30 19:36 ` [PATCH 4/4] staging:iio: Proof of concept input driver Jonathan Cameron
2012-06-08 15:27   ` Lars-Peter Clausen [this message]
2012-06-09 17:56     ` Jonathan Cameron
  -- strict thread matches above, loose matches on Subject: below --
2012-10-31 10:30 [PATCH 0/4 V6] staging:iio: Add support for multiple buffers (testing required!) Jonathan Cameron
2012-10-31 10:30 ` [PATCH 4/4] staging:iio: Proof of concept input driver Jonathan Cameron
2012-10-31 14:40   ` Peter Meerwald
2012-11-02 11:02     ` Jonathan Cameron
2012-10-13  9:24 [PATCH 0/4 V5] staging:iio: Add support for multiple buffers (testing required!) Jonathan Cameron
2012-10-13  9:24 ` [PATCH 4/4] staging:iio: Proof of concept input driver Jonathan Cameron
2012-10-13  9:57   ` Jonathan Cameron
2012-06-30 19:06 [PATCH 0/4 V3] staging:iio: Add support for multiple buffers Jonathan Cameron
2012-06-30 19:06 ` [PATCH 4/4] staging:iio: Proof of concept input driver Jonathan Cameron
2012-04-10 20:38 [RFC PATCH 0/4 V2] Add push based interface for non userspace iio users Jonathan Cameron
2012-04-10 20:38 ` [PATCH 4/4] staging:iio: Proof of concept input driver 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=4FD219D9.5010008@metafoo.de \
    --to=lars@metafoo.de \
    --cc=jic23@cam.ac.uk \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    /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.