linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Lars-Peter Clausen <lars@metafoo.de>
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: Sat, 09 Jun 2012 18:56:22 +0100	[thread overview]
Message-ID: <4FD38E46.8020205@kernel.org> (raw)
In-Reply-To: <4FD219D9.5010008@metafoo.de>

On 06/08/2012 04:27 PM, Lars-Peter Clausen wrote:
> 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.
Not sure there is any real reason not to use sign_extend32 as is. Can
just convert much later at the input_report_abs call.
> 
>> +	} 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.
Yup.  Lots of extensions needed to this driver....
>> +
>> +	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?
Indeed.  I'm clearly going mad ;)
> 
>> +		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;
>> +}
>> +
> [...]
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2012-06-09 17:56 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
2012-06-09 17:56     ` Jonathan Cameron [this message]
  -- 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=4FD38E46.8020205@kernel.org \
    --to=jic23@kernel.org \
    --cc=jic23@cam.ac.uk \
    --cc=lars@metafoo.de \
    --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 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).