Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1431509 > unrolled thread

Re: [PATCH 1/1] drivers:iio:light:isl29125: added macros for sensing range

Started byJonathan Cameron <jic23@kernel.org>
First post2016-06-26 16:00 +0200
Last post2016-06-27 16:00 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH 1/1] drivers:iio:light:isl29125: added macros for sensing  range Jonathan Cameron <jic23@kernel.org> - 2016-06-26 16:00 +0200
    Re: [PATCH 1/1] drivers:iio:light:isl29125: added macros for sensing  range Peter Meerwald-Stadler <pmeerw@pmeerw.net> - 2016-06-27 16:00 +0200

#1431509 — Re: [PATCH 1/1] drivers:iio:light:isl29125: added macros for sensing range

FromJonathan Cameron <jic23@kernel.org>
Date2016-06-26 16:00 +0200
SubjectRe: [PATCH 1/1] drivers:iio:light:isl29125: added macros for sensing range
Message-ID<rOiLo-3E7-13@gated-at.bofh.it>
On 24/06/16 12:16, Bijosh Thykkoottathil wrote:
> Added macros for sensing range as the corresponding magic numbers
> were used at multiple places.
>    - SENSING_RANGE_0 for 375 lux full range
>    - SENSING_RANGE_1 for 10k lux full range
> 
> Signed-off-by: Bijosh Thykkoottathil <bijosh.t@hotmail.com>
Hi Bijosh,

Macros are great for making cases of 'magic numbers' more readable.
However here we are wrapping up 'real' numbers in macros that actually
obscure what they are...

Now the fact they are used twice does make it a little more worthwhile.
Peter, what do you think?  Your driver so up to you ;)
*one buck passed*
> ---
>  drivers/iio/light/isl29125.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/light/isl29125.c b/drivers/iio/light/isl29125.c
> index e2945a2..83a5a7a 100644
> --- a/drivers/iio/light/isl29125.c
> +++ b/drivers/iio/light/isl29125.c
> @@ -44,6 +44,9 @@
>  #define ISL29125_MODE_B 0x3
>  #define ISL29125_MODE_RGB 0x5
>  
> +#define SENSING_RANGE_0 5722   /* 375 lux full range */
> +#define SENSING_RANGE_1 152590 /* 10k lux full range */
> +
>  #define ISL29125_MODE_RANGE BIT(3)
>  
>  #define ISL29125_STATUS_CONV BIT(1)
> @@ -140,9 +143,9 @@ static int isl29125_read_raw(struct iio_dev *indio_dev,
>  	case IIO_CHAN_INFO_SCALE:
>  		*val = 0;
>  		if (data->conf1 & ISL29125_MODE_RANGE)
> -			*val2 = 152590; /* 10k lux full range */
> +			*val2 = SENSING_RANGE_1; /* 10k lux full range */
>  		else
> -			*val2 = 5722; /* 375 lux full range */
> +			*val2 = SENSING_RANGE_0; /* 375 lux full range */
>  		return IIO_VAL_INT_PLUS_MICRO;
>  	}
>  	return -EINVAL;
> @@ -158,9 +161,9 @@ static int isl29125_write_raw(struct iio_dev *indio_dev,
>  	case IIO_CHAN_INFO_SCALE:
>  		if (val != 0)
>  			return -EINVAL;
> -		if (val2 == 152590)
> +		if (val2 == SENSING_RANGE_1)
>  			data->conf1 |= ISL29125_MODE_RANGE;
> -		else if (val2 == 5722)
> +		else if (val2 == SENSING_RANGE_0)
>  			data->conf1 &= ~ISL29125_MODE_RANGE;
>  		else
>  			return -EINVAL;
> 

[toc] | [next] | [standalone]


#1432058

FromPeter Meerwald-Stadler <pmeerw@pmeerw.net>
Date2016-06-27 16:00 +0200
Message-ID<rOFeW-XV-35@gated-at.bofh.it>
In reply to#1431509
> On 24/06/16 12:16, Bijosh Thykkoottathil wrote:
> > Added macros for sensing range as the corresponding magic numbers
> > were used at multiple places.
> >    - SENSING_RANGE_0 for 375 lux full range
> >    - SENSING_RANGE_1 for 10k lux full range

> Macros are great for making cases of 'magic numbers' more readable.
> However here we are wrapping up 'real' numbers in macros that actually
> obscure what they are...
> 
> Now the fact they are used twice does make it a little more worthwhile.
> Peter, what do you think?  Your driver so up to you ;)

I'm fine with the proposed change, but a proper prefix is required, hence
ISL29125_SENSING_RANGE_0 and _1

regards, p.

> > ---
> >  drivers/iio/light/isl29125.c | 11 +++++++----
> >  1 file changed, 7 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/iio/light/isl29125.c b/drivers/iio/light/isl29125.c
> > index e2945a2..83a5a7a 100644
> > --- a/drivers/iio/light/isl29125.c
> > +++ b/drivers/iio/light/isl29125.c
> > @@ -44,6 +44,9 @@
> >  #define ISL29125_MODE_B 0x3
> >  #define ISL29125_MODE_RGB 0x5
> >  
> > +#define SENSING_RANGE_0 5722   /* 375 lux full range */
> > +#define SENSING_RANGE_1 152590 /* 10k lux full range */
> > +
> >  #define ISL29125_MODE_RANGE BIT(3)
> >  
> >  #define ISL29125_STATUS_CONV BIT(1)
> > @@ -140,9 +143,9 @@ static int isl29125_read_raw(struct iio_dev *indio_dev,
> >  	case IIO_CHAN_INFO_SCALE:
> >  		*val = 0;
> >  		if (data->conf1 & ISL29125_MODE_RANGE)
> > -			*val2 = 152590; /* 10k lux full range */
> > +			*val2 = SENSING_RANGE_1; /* 10k lux full range */
> >  		else
> > -			*val2 = 5722; /* 375 lux full range */
> > +			*val2 = SENSING_RANGE_0; /* 375 lux full range */
> >  		return IIO_VAL_INT_PLUS_MICRO;
> >  	}
> >  	return -EINVAL;
> > @@ -158,9 +161,9 @@ static int isl29125_write_raw(struct iio_dev *indio_dev,
> >  	case IIO_CHAN_INFO_SCALE:
> >  		if (val != 0)
> >  			return -EINVAL;
> > -		if (val2 == 152590)
> > +		if (val2 == SENSING_RANGE_1)
> >  			data->conf1 |= ISL29125_MODE_RANGE;
> > -		else if (val2 == 5722)
> > +		else if (val2 == SENSING_RANGE_0)
> >  			data->conf1 &= ~ISL29125_MODE_RANGE;
> >  		else
> >  			return -EINVAL;
> > 
> 

-- 

Peter Meerwald-Stadler
+43-664-2444418 (mobile)

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web