linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] iio: add iio_read_channel_offset() consumer api
@ 2012-08-16  7:39 Kim, Milo
  2012-08-16  7:42 ` Peter Meerwald
  2012-08-16  8:19 ` Lars-Peter Clausen
  0 siblings, 2 replies; 7+ messages in thread
From: Kim, Milo @ 2012-08-16  7:39 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: Lars-Peter Clausen, jic23, linux-kernel, linux-iio

This allows the iio consumer to get the offset of the channel.
The value of offset can be used when calculating the result such
as 'result = raw * scale + offset'.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
---
 drivers/iio/inkern.c         |   21 +++++++++++++++++++++
 include/linux/iio/consumer.h |    9 +++++++++
 2 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
index b5afc2f..bd09245 100644
--- a/drivers/iio/inkern.c
+++ b/drivers/iio/inkern.c
@@ -269,6 +269,27 @@ err_unlock:
 }
 EXPORT_SYMBOL_GPL(iio_read_channel_scale);
 
+int iio_read_channel_offset(struct iio_channel *chan, int *val)
+{
+	int val2, ret;
+
+	mutex_lock(&chan->indio_dev->info_exist_lock);
+	if (chan->indio_dev->info == NULL) {
+		ret = -ENODEV;
+		goto err_unlock;
+	}
+
+	ret = chan->indio_dev->info->read_raw(chan->indio_dev,
+					      chan->channel,
+					      val, &val2,
+					      IIO_CHAN_INFO_OFFSET);
+err_unlock:
+	mutex_unlock(&chan->indio_dev->info_exist_lock);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(iio_read_channel_offset);
+
 int iio_get_channel_type(struct iio_channel *chan, enum iio_chan_type *type)
 {
 	int ret = 0;
diff --git a/include/linux/iio/consumer.h b/include/linux/iio/consumer.h
index e2657e6..d9d69fa 100644
--- a/include/linux/iio/consumer.h
+++ b/include/linux/iio/consumer.h
@@ -93,4 +93,13 @@ int iio_get_channel_type(struct iio_channel *channel,
 int iio_read_channel_scale(struct iio_channel *chan, int *val,
 			   int *val2);
 
+/**
+ * iio_read_channel_offset() - read offset from a given channel
+ * @channel:		The channel being queried.
+ * @val:		Offset Value read back.
+ *
+ * Note offset can be used in the consumer when calculating the result
+ * such as 'result = raw * scale + offset'.
+ */
+int iio_read_channel_offset(struct iio_channel *chan, int *val);
 #endif
-- 
1.7.2.5


Best Regards,
Milo



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] iio: add iio_read_channel_offset() consumer api
  2012-08-16  7:39 [PATCH 1/3] iio: add iio_read_channel_offset() consumer api Kim, Milo
@ 2012-08-16  7:42 ` Peter Meerwald
  2012-08-16  7:49   ` Kim, Milo
  2012-08-16  8:19 ` Lars-Peter Clausen
  1 sibling, 1 reply; 7+ messages in thread
From: Peter Meerwald @ 2012-08-16  7:42 UTC (permalink / raw)
  To: Kim, Milo
  Cc: Jonathan Cameron, Lars-Peter Clausen, jic23, linux-kernel, linux-iio


comment below

p.

> This allows the iio consumer to get the offset of the channel.
> The value of offset can be used when calculating the result such
> as 'result = raw * scale + offset'.
> 
> Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
> ---
>  drivers/iio/inkern.c         |   21 +++++++++++++++++++++
>  include/linux/iio/consumer.h |    9 +++++++++
>  2 files changed, 30 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
> index b5afc2f..bd09245 100644
> --- a/drivers/iio/inkern.c
> +++ b/drivers/iio/inkern.c
> @@ -269,6 +269,27 @@ err_unlock:
>  }
>  EXPORT_SYMBOL_GPL(iio_read_channel_scale);
>  
> +int iio_read_channel_offset(struct iio_channel *chan, int *val)
> +{
> +	int val2, ret;
> +
> +	mutex_lock(&chan->indio_dev->info_exist_lock);
> +	if (chan->indio_dev->info == NULL) {
> +		ret = -ENODEV;
> +		goto err_unlock;
> +	}
> +
> +	ret = chan->indio_dev->info->read_raw(chan->indio_dev,
> +					      chan->channel,
> +					      val, &val2,
> +					      IIO_CHAN_INFO_OFFSET);
> +err_unlock:
> +	mutex_unlock(&chan->indio_dev->info_exist_lock);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(iio_read_channel_offset);
> +
>  int iio_get_channel_type(struct iio_channel *chan, enum iio_chan_type *type)
>  {
>  	int ret = 0;
> diff --git a/include/linux/iio/consumer.h b/include/linux/iio/consumer.h
> index e2657e6..d9d69fa 100644
> --- a/include/linux/iio/consumer.h
> +++ b/include/linux/iio/consumer.h
> @@ -93,4 +93,13 @@ int iio_get_channel_type(struct iio_channel *channel,
>  int iio_read_channel_scale(struct iio_channel *chan, int *val,
>  			   int *val2);
>  
> +/**
> + * iio_read_channel_offset() - read offset from a given channel
> + * @channel:		The channel being queried.

the parameter is 'chan', not 'channel'

> + * @val:		Offset Value read back.
> + *
> + * Note offset can be used in the consumer when calculating the result
> + * such as 'result = raw * scale + offset'.
> + */
> +int iio_read_channel_offset(struct iio_channel *chan, int *val);
>  #endif
> 

-- 

Peter Meerwald
+43-664-2444418 (mobile)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH 1/3] iio: add iio_read_channel_offset() consumer api
  2012-08-16  7:42 ` Peter Meerwald
@ 2012-08-16  7:49   ` Kim, Milo
  2012-08-16 18:56     ` Jonathan Cameron
  0 siblings, 1 reply; 7+ messages in thread
From: Kim, Milo @ 2012-08-16  7:49 UTC (permalink / raw)
  To: Peter Meerwald
  Cc: Jonathan Cameron, Lars-Peter Clausen, jic23, linux-kernel, linux-iio

> >  int iio_read_channel_scale(struct iio_channel *chan, int *val,
> >  			   int *val2);
> >
> > +/**
> > + * iio_read_channel_offset() - read offset from a given channel
> > + * @channel:		The channel being queried.
> 
> the parameter is 'chan', not 'channel'
> 

Oops, this is copy-and-paste disaster.
The description of iio_read_channel_scale() also needs correction.
Thanks for catching this !

After getting other feedbacks, separate patch will be submitted.

Best Regards,
Milo

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] iio: add iio_read_channel_offset() consumer api
  2012-08-16  7:39 [PATCH 1/3] iio: add iio_read_channel_offset() consumer api Kim, Milo
  2012-08-16  7:42 ` Peter Meerwald
@ 2012-08-16  8:19 ` Lars-Peter Clausen
  2012-08-16  8:25   ` Lars-Peter Clausen
  2012-08-16  8:32   ` Jonathan Cameron
  1 sibling, 2 replies; 7+ messages in thread
From: Lars-Peter Clausen @ 2012-08-16  8:19 UTC (permalink / raw)
  To: Kim, Milo; +Cc: Jonathan Cameron, jic23, linux-kernel, linux-iio

On 08/16/2012 09:39 AM, Kim, Milo wrote:
> This allows the iio consumer to get the offset of the channel.
> The value of offset can be used when calculating the result such
> as 'result = raw * scale + offset'.

result = (raw + offset) * scale

Otherwise it looks good, except for:

> +/**
> + * iio_read_channel_offset() - read offset from a given channel
> + * @channel:		The channel being queried.
> + * @val:		Offset Value read back.
> + *
> + * Note offset can be used in the consumer when calculating the result
> + * such as 'result = raw * scale + offset'.
> + */

The documentation should go in the c file.

> +int iio_read_channel_offset(struct iio_channel *chan, int *val);
>  #endif


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] iio: add iio_read_channel_offset() consumer api
  2012-08-16  8:19 ` Lars-Peter Clausen
@ 2012-08-16  8:25   ` Lars-Peter Clausen
  2012-08-16  8:32   ` Jonathan Cameron
  1 sibling, 0 replies; 7+ messages in thread
From: Lars-Peter Clausen @ 2012-08-16  8:25 UTC (permalink / raw)
  To: Kim, Milo; +Cc: Jonathan Cameron, jic23, linux-kernel, linux-iio

On 08/16/2012 10:19 AM, Lars-Peter Clausen wrote:
> On 08/16/2012 09:39 AM, Kim, Milo wrote:
>> This allows the iio consumer to get the offset of the channel.
>> The value of offset can be used when calculating the result such
>> as 'result = raw * scale + offset'.
> 
> result = (raw + offset) * scale
> 
> Otherwise it looks good, except for:
> 
>> +/**
>> + * iio_read_channel_offset() - read offset from a given channel
>> + * @channel:		The channel being queried.
>> + * @val:		Offset Value read back.
>> + *
>> + * Note offset can be used in the consumer when calculating the result
>> + * such as 'result = raw * scale + offset'.
>> + */
> 
> The documentation should go in the c file.

Just saw that for the other functions in consumer.h it is in the header as
well, so ignore that comment above.

> 
>> +int iio_read_channel_offset(struct iio_channel *chan, int *val);
>>  #endif
> 
> --
> 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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] iio: add iio_read_channel_offset() consumer api
  2012-08-16  8:19 ` Lars-Peter Clausen
  2012-08-16  8:25   ` Lars-Peter Clausen
@ 2012-08-16  8:32   ` Jonathan Cameron
  1 sibling, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2012-08-16  8:32 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Kim, Milo, Jonathan Cameron, jic23, linux-kernel, linux-iio

On 16/08/12 09:19, Lars-Peter Clausen wrote:
> On 08/16/2012 09:39 AM, Kim, Milo wrote:
>> This allows the iio consumer to get the offset of the channel.
>> The value of offset can be used when calculating the result such
>> as 'result = raw * scale + offset'.
> result = (raw + offset) * scale
>
> Otherwise it looks good, except for:
>
>> +/**
>> + * iio_read_channel_offset() - read offset from a given channel
>> + * @channel:		The channel being queried.
>> + * @val:		Offset Value read back.
>> + *
>> + * Note offset can be used in the consumer when calculating the result
>> + * such as 'result = raw * scale + offset'.
>> + */
> The documentation should go in the c file.
I've often wondered about this myself.  Looking quickly about it does
appear that it is more popular to do it in c file...  Guess I've been wrong
for quite some time.  For now it's probably better to keep this docs
in the header and do the move all in one go given all the other docs
are here in this header.

I can see the arguments either way, but have not as yet seen anyone
stamp their foot on what is the 'one true way'.

>
>> +int iio_read_channel_offset(struct iio_channel *chan, int *val);
>>   #endif


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] iio: add iio_read_channel_offset() consumer api
  2012-08-16  7:49   ` Kim, Milo
@ 2012-08-16 18:56     ` Jonathan Cameron
  0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2012-08-16 18:56 UTC (permalink / raw)
  To: Kim, Milo
  Cc: Peter Meerwald, Lars-Peter Clausen, jic23, linux-kernel, linux-iio

On 08/16/2012 08:49 AM, Kim, Milo wrote:
>>>  int iio_read_channel_scale(struct iio_channel *chan, int *val,
>>>  			   int *val2);
>>>
>>> +/**
>>> + * iio_read_channel_offset() - read offset from a given channel
>>> + * @channel:		The channel being queried.
>>
>> the parameter is 'chan', not 'channel'
>>
> 
> Oops, this is copy-and-paste disaster.
> The description of iio_read_channel_scale() also needs correction.
> Thanks for catching this !
good point.  Feel free to send a separate patch fixing that ;)
> 
> After getting other feedbacks, separate patch will be submitted.
> 
> Best Regards,
> Milo
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-08-16 18:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-16  7:39 [PATCH 1/3] iio: add iio_read_channel_offset() consumer api Kim, Milo
2012-08-16  7:42 ` Peter Meerwald
2012-08-16  7:49   ` Kim, Milo
2012-08-16 18:56     ` Jonathan Cameron
2012-08-16  8:19 ` Lars-Peter Clausen
2012-08-16  8:25   ` Lars-Peter Clausen
2012-08-16  8:32   ` Jonathan Cameron

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).