Linux IIO development
 help / color / mirror / Atom feed
From: Jaehoon Chung <jh80.chung@samsung.com>
To: Beomho Seo <beomho.seo@samsung.com>, linux-iio@vger.kernel.org
Cc: Jonathan Cameron <jic23@kernel.org>,
	Myungjoo Ham <myungjoo.ham@samsung.com>
Subject: Re: [PATCH 1/2] iio: cm36651:  Fix read/write integration time function.
Date: Fri, 07 Feb 2014 20:46:37 +0900	[thread overview]
Message-ID: <52F4C79D.6010909@samsung.com> (raw)
In-Reply-To: <52F4BFCD.2080203@samsung.com>

On 02/07/2014 08:13 PM, Beomho Seo wrote:
> 
> This patch is fixed [read/write] integration time function.
> cm36651 have integration time from 1 to 640 milliseconds.
> But, print more then the thounsand second. when call *_integration_time attribute.
> Because read_integration_time function return IIO_VAL_INT.
> read integration time function is changed return IIO_VAL_INT_PLUS_MICRO;
> And then .write_raw_get_fmt callback function for parse a fixed-point number from a string.
> Some description is revised milliseconds unit.
> 
> This patch have been tested on exynos4 board.
> 
> Signed-off-by: Beomho Seo <beomho.seo@samsung.com>
> ---
>  drivers/iio/light/cm36651.c |   71 ++++++++++++++++++++++++-------------------
>  1 file changed, 40 insertions(+), 31 deletions(-)
> 
> diff --git a/drivers/iio/light/cm36651.c b/drivers/iio/light/cm36651.c
> index 0a142af..076780c 100644
> --- a/drivers/iio/light/cm36651.c
> +++ b/drivers/iio/light/cm36651.c
> @@ -50,10 +50,10 @@
>  #define CM36651_CS_CONF2_DEFAULT_BIT	0x08
> 
>  /* CS_CONF3 channel integration time */
> -#define CM36651_CS_IT1			0x00 /* Integration time 80000 usec */
> -#define CM36651_CS_IT2			0x40 /* Integration time 160000 usec */
> -#define CM36651_CS_IT3			0x80 /* Integration time 320000 usec */
> -#define CM36651_CS_IT4			0xC0 /* Integration time 640000 usec */
> +#define CM36651_CS_IT1			0x00 /* Integration time 80 msec */
> +#define CM36651_CS_IT2			0x40 /* Integration time 160 msec */
> +#define CM36651_CS_IT3			0x80 /* Integration time 320 msec */
> +#define CM36651_CS_IT4			0xC0 /* Integration time 640 msec */
> 
>  /* PS_CONF1 command code */
>  #define CM36651_PS_ENABLE		0x00
> @@ -64,10 +64,10 @@
>  #define CM36651_PS_PERS4		0x0C
> 
>  /* PS_CONF1 command code: integration time */
> -#define CM36651_PS_IT1			0x00 /* Integration time 320 usec */
> -#define CM36651_PS_IT2			0x10 /* Integration time 420 usec */
> -#define CM36651_PS_IT3			0x20 /* Integration time 520 usec */
> -#define CM36651_PS_IT4			0x30 /* Integration time 640 usec */
> +#define CM36651_PS_IT1			0x00 /* Integration time 0.32 msec */
> +#define CM36651_PS_IT2			0x10 /* Integration time 0.42 msec */
> +#define CM36651_PS_IT3			0x20 /* Integration time 0.52 msec */
> +#define CM36651_PS_IT4			0x30 /* Integration time 0.64 msec */
> 
>  /* PS_CONF1 command code: duty ratio */
>  #define CM36651_PS_DR1			0x00 /* Duty ratio 1/80 */
> @@ -93,8 +93,8 @@
>  #define CM36651_CLOSE_PROXIMITY		0x32
>  #define CM36651_FAR_PROXIMITY			0x33
> 
> -#define CM36651_CS_INT_TIME_AVAIL	"80000 160000 320000 640000"
> -#define CM36651_PS_INT_TIME_AVAIL	"320 420 520 640"
> +#define CM36651_CS_INT_TIME_AVAIL	"0.08 0.16 0.32 0.64"
> +#define CM36651_PS_INT_TIME_AVAIL	"0.000320 0.000420 0.000520 0.000640"
> 
>  enum cm36651_operation_mode {
>  	CM36651_LIGHT_EN,
> @@ -356,30 +356,30 @@ static int cm36651_read_channel(struct cm36651_data *cm36651,
>  }
> 
>  static int cm36651_read_int_time(struct cm36651_data *cm36651,
> -				struct iio_chan_spec const *chan, int *val)
> +				struct iio_chan_spec const *chan, int *val2)
>  {
>  	switch (chan->type) {
>  	case IIO_LIGHT:
>  		if (cm36651->cs_int_time[chan->address] == CM36651_CS_IT1)
> -			*val = 80000;
> +			*val2 = 80000;
>  		else if (cm36651->cs_int_time[chan->address] == CM36651_CS_IT2)
> -			*val = 160000;
> +			*val2 = 160000;
>  		else if (cm36651->cs_int_time[chan->address] == CM36651_CS_IT3)
> -			*val = 320000;
> +			*val2 = 320000;
>  		else if (cm36651->cs_int_time[chan->address] == CM36651_CS_IT4)
> -			*val = 640000;
> +			*val2 = 640000;
>  		else
>  			return -EINVAL;
>  		break;
>  	case IIO_PROXIMITY:
>  		if (cm36651->ps_int_time == CM36651_PS_IT1)
> -			*val = 320;
> +			*val2 = 320;
>  		else if (cm36651->ps_int_time == CM36651_PS_IT2)
> -			*val = 420;
> +			*val2 = 420;
>  		else if (cm36651->ps_int_time == CM36651_PS_IT3)
> -			*val = 520;
> +			*val2 = 520;
>  		else if (cm36651->ps_int_time == CM36651_PS_IT4)
> -			*val = 640;
> +			*val2 = 640;
>  		else
>  			return -EINVAL;
>  		break;
> @@ -387,11 +387,11 @@ static int cm36651_read_int_time(struct cm36651_data *cm36651,
>  		return -EINVAL;
>  	}
> 
> -	return IIO_VAL_INT;
> +	return IIO_VAL_INT_PLUS_MICRO;
>  }
> 
>  static int cm36651_write_int_time(struct cm36651_data *cm36651,
> -				struct iio_chan_spec const *chan, int val)
> +				struct iio_chan_spec const *chan, int val2)
I didn't know why do you change from val to val2?
This is just changing variable name, isn't?

>  {
>  	struct i2c_client *client = cm36651->client;
>  	struct i2c_client *ps_client = cm36651->ps_client;
> @@ -399,13 +399,13 @@ static int cm36651_write_int_time(struct cm36651_data *cm36651,
> 
>  	switch (chan->type) {
>  	case IIO_LIGHT:
> -		if (val == 80000)
> +		if (val2 == 80000)
>  			int_time = CM36651_CS_IT1;
> -		else if (val == 160000)
> +		else if (val2 == 160000)
>  			int_time = CM36651_CS_IT2;
> -		else if (val == 320000)
> +		else if (val2 == 320000)
>  			int_time = CM36651_CS_IT3;
> -		else if (val == 640000)
> +		else if (val2 == 640000)
>  			int_time = CM36651_CS_IT4;
>  		else
>  			return -EINVAL;
> @@ -419,13 +419,13 @@ static int cm36651_write_int_time(struct cm36651_data *cm36651,
>  		cm36651->cs_int_time[chan->address] = int_time;
>  		break;
>  	case IIO_PROXIMITY:
> -		if (val == 320)
> +		if (val2 == 320)
>  			int_time = CM36651_PS_IT1;
> -		else if (val == 420)
> +		else if (val2 == 420)
>  			int_time = CM36651_PS_IT2;
> -		else if (val == 520)
> +		else if (val2 == 520)
>  			int_time = CM36651_PS_IT3;
> -		else if (val == 640)
> +		else if (val2 == 640)
>  			int_time = CM36651_PS_IT4;
>  		else
>  			return -EINVAL;
> @@ -459,7 +459,8 @@ static int cm36651_read_raw(struct iio_dev *indio_dev,
>  		ret = cm36651_read_channel(cm36651, chan, val);
>  		break;
>  	case IIO_CHAN_INFO_INT_TIME:
> -		ret = cm36651_read_int_time(cm36651, chan, val);
> +		*val = 0;
> +		ret = cm36651_read_int_time(cm36651, chan, val2);
>  		break;
>  	default:
>  		ret = -EINVAL;
> @@ -479,7 +480,7 @@ static int cm36651_write_raw(struct iio_dev *indio_dev,
>  	int ret = -EINVAL;
> 
>  	if (mask == IIO_CHAN_INFO_INT_TIME) {
> -		ret = cm36651_write_int_time(cm36651, chan, val);
> +		ret = cm36651_write_int_time(cm36651, chan, val2);
>  		if (ret < 0)
>  			dev_err(&client->dev, "Integration time write failed\n");
>  	}
> @@ -487,6 +488,13 @@ static int cm36651_write_raw(struct iio_dev *indio_dev,
>  	return ret;
>  }
> 
> +static int cm36651_write_raw_get_fmt(struct iio_dev *indio_dev,
> +				struct iio_chan_spec const *chan,
> +				long mask)
> +{
> +	return IIO_VAL_INT_PLUS_MICRO;
> +}
> +
>  static int cm36651_read_prox_thresh(struct iio_dev *indio_dev,
>  					const struct iio_chan_spec *chan,
>  					enum iio_event_type type,
> @@ -614,6 +622,7 @@ static const struct iio_info cm36651_info = {
>  	.driver_module		= THIS_MODULE,
>  	.read_raw		= &cm36651_read_raw,
>  	.write_raw		= &cm36651_write_raw,
> +	.write_raw_get_fmt	= &cm36651_write_raw_get_fmt,
>  	.read_event_value	= &cm36651_read_prox_thresh,
>  	.write_event_value	= &cm36651_write_prox_thresh,
>  	.read_event_config	= &cm36651_read_prox_event_config,
> 

  reply	other threads:[~2014-02-07 11:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-07 11:13 [PATCH 1/2] iio: cm36651: Fix read/write integration time function Beomho Seo
2014-02-07 11:46 ` Jaehoon Chung [this message]
2014-02-08 12:17   ` 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=52F4C79D.6010909@samsung.com \
    --to=jh80.chung@samsung.com \
    --cc=beomho.seo@samsung.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=myungjoo.ham@samsung.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