iio: light: ltrf216a: Return floating point values

Message ID 20231107192005.285534-1-shreeya.patel@collabora.com
State New
Headers
Series iio: light: ltrf216a: Return floating point values |

Commit Message

Shreeya Patel Nov. 7, 2023, 7:20 p.m. UTC
  For better precision of input light intesity, return floating point
values through sysfs instead of an integer value

Signed-off-by: Shreeya Patel <shreeya.patel@collabora.com>
---
 drivers/iio/light/ltrf216a.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
  

Comments

Shreeya Patel Nov. 21, 2023, 7:35 p.m. UTC | #1
On 08/11/23 00:50, Shreeya Patel wrote:
> For better precision of input light intesity, return floating point
> values through sysfs instead of an integer value

Hi Jonathan,

Gentle ping for this patch. I am not sure if you got time to look at the 
patches
after LPC but just making sure it doesn't get lost between bunch of 
others :)


Thanks,
Shreeya Patel

>
> Signed-off-by: Shreeya Patel <shreeya.patel@collabora.com>
> ---
>   drivers/iio/light/ltrf216a.c | 10 +++++-----
>   1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iio/light/ltrf216a.c b/drivers/iio/light/ltrf216a.c
> index 8de4dd849936..68dc48420a88 100644
> --- a/drivers/iio/light/ltrf216a.c
> +++ b/drivers/iio/light/ltrf216a.c
> @@ -234,7 +234,7 @@ static int ltrf216a_read_data(struct ltrf216a_data *data, u8 addr)
>   static int ltrf216a_get_lux(struct ltrf216a_data *data)
>   {
>   	int ret, greendata;
> -	u64 lux, div;
> +	u64 lux;
>   
>   	ret = ltrf216a_set_power_state(data, true);
>   	if (ret)
> @@ -246,10 +246,9 @@ static int ltrf216a_get_lux(struct ltrf216a_data *data)
>   
>   	ltrf216a_set_power_state(data, false);
>   
> -	lux = greendata * 45 * LTRF216A_WIN_FAC * 100;
> -	div = data->als_gain_fac * data->int_time_fac * 100;
> +	lux = greendata * 45 * LTRF216A_WIN_FAC;
>   
> -	return div_u64(lux, div);
> +	return lux;
>   }
>   
>   static int ltrf216a_read_raw(struct iio_dev *indio_dev,
> @@ -279,7 +278,8 @@ static int ltrf216a_read_raw(struct iio_dev *indio_dev,
>   		if (ret < 0)
>   			return ret;
>   		*val = ret;
> -		return IIO_VAL_INT;
> +		*val2 = data->als_gain_fac * data->int_time_fac;
> +		return IIO_VAL_FRACTIONAL;
>   	case IIO_CHAN_INFO_INT_TIME:
>   		mutex_lock(&data->lock);
>   		ret = ltrf216a_get_int_time(data, val, val2);
  
Jonathan Cameron Nov. 26, 2023, 6:02 p.m. UTC | #2
On Wed, 22 Nov 2023 01:05:41 +0530
Shreeya Patel <shreeya.patel@collabora.com> wrote:

> On 08/11/23 00:50, Shreeya Patel wrote:
> > For better precision of input light intesity, return floating point
> > values through sysfs instead of an integer value  
> 
> Hi Jonathan,
> 
> Gentle ping for this patch. I am not sure if you got time to look at the 
> patches
> after LPC but just making sure it doesn't get lost between bunch of 
> others :)
Hi Shreeya,

Getting there on catching up - for some reason this one didn't reach my inbox, but thankfully
patchwork had it.

Anyhow, applied to the togreg branch of iio.git and pushed out as testing
for all the normal reasons.

Thanks,

Jonathan

> 
> 
> Thanks,
> Shreeya Patel
> 
> >
> > Signed-off-by: Shreeya Patel <shreeya.patel@collabora.com>
> > ---
> >   drivers/iio/light/ltrf216a.c | 10 +++++-----
> >   1 file changed, 5 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/iio/light/ltrf216a.c b/drivers/iio/light/ltrf216a.c
> > index 8de4dd849936..68dc48420a88 100644
> > --- a/drivers/iio/light/ltrf216a.c
> > +++ b/drivers/iio/light/ltrf216a.c
> > @@ -234,7 +234,7 @@ static int ltrf216a_read_data(struct ltrf216a_data *data, u8 addr)
> >   static int ltrf216a_get_lux(struct ltrf216a_data *data)
> >   {
> >   	int ret, greendata;
> > -	u64 lux, div;
> > +	u64 lux;
> >   
> >   	ret = ltrf216a_set_power_state(data, true);
> >   	if (ret)
> > @@ -246,10 +246,9 @@ static int ltrf216a_get_lux(struct ltrf216a_data *data)
> >   
> >   	ltrf216a_set_power_state(data, false);
> >   
> > -	lux = greendata * 45 * LTRF216A_WIN_FAC * 100;
> > -	div = data->als_gain_fac * data->int_time_fac * 100;
> > +	lux = greendata * 45 * LTRF216A_WIN_FAC;
> >   
> > -	return div_u64(lux, div);
> > +	return lux;
> >   }
> >   
> >   static int ltrf216a_read_raw(struct iio_dev *indio_dev,
> > @@ -279,7 +278,8 @@ static int ltrf216a_read_raw(struct iio_dev *indio_dev,
> >   		if (ret < 0)
> >   			return ret;
> >   		*val = ret;
> > -		return IIO_VAL_INT;
> > +		*val2 = data->als_gain_fac * data->int_time_fac;
> > +		return IIO_VAL_FRACTIONAL;
> >   	case IIO_CHAN_INFO_INT_TIME:
> >   		mutex_lock(&data->lock);
> >   		ret = ltrf216a_get_int_time(data, val, val2);  
>
  

Patch

diff --git a/drivers/iio/light/ltrf216a.c b/drivers/iio/light/ltrf216a.c
index 8de4dd849936..68dc48420a88 100644
--- a/drivers/iio/light/ltrf216a.c
+++ b/drivers/iio/light/ltrf216a.c
@@ -234,7 +234,7 @@  static int ltrf216a_read_data(struct ltrf216a_data *data, u8 addr)
 static int ltrf216a_get_lux(struct ltrf216a_data *data)
 {
 	int ret, greendata;
-	u64 lux, div;
+	u64 lux;
 
 	ret = ltrf216a_set_power_state(data, true);
 	if (ret)
@@ -246,10 +246,9 @@  static int ltrf216a_get_lux(struct ltrf216a_data *data)
 
 	ltrf216a_set_power_state(data, false);
 
-	lux = greendata * 45 * LTRF216A_WIN_FAC * 100;
-	div = data->als_gain_fac * data->int_time_fac * 100;
+	lux = greendata * 45 * LTRF216A_WIN_FAC;
 
-	return div_u64(lux, div);
+	return lux;
 }
 
 static int ltrf216a_read_raw(struct iio_dev *indio_dev,
@@ -279,7 +278,8 @@  static int ltrf216a_read_raw(struct iio_dev *indio_dev,
 		if (ret < 0)
 			return ret;
 		*val = ret;
-		return IIO_VAL_INT;
+		*val2 = data->als_gain_fac * data->int_time_fac;
+		return IIO_VAL_FRACTIONAL;
 	case IIO_CHAN_INFO_INT_TIME:
 		mutex_lock(&data->lock);
 		ret = ltrf216a_get_int_time(data, val, val2);