All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] TSL2550: extended mode bugfix
@ 2009-08-05 15:08 Michele De Candia (VT)
       [not found] ` <4A79A055.1010602-EZxuzQJkuwwybS5Ee8rs3A@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Michele De Candia (VT) @ 2009-08-05 15:08 UTC (permalink / raw)
  To: Linux I2C

Hi all,
according to the TAOS Application Note 'Controlling a Backlight with the
TSL2550 Ambient Light Sensor' (page 14), the actual lux value in
extended mode should be obtained multiplying the calculated lux value by 5.
The following patch should fix the lux calculation in this case.

Regards,
Michele De Candia
--

Signed-off-by: Michele Jr De Candia <michele.decandia-EZxuzQJkuwwybS5Ee8rs3A@public.gmane.org>

drivers/i2c/chips/tsl2550.c |    7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/chips/tsl2550.c b/drivers/i2c/chips/tsl2550.c
index b96f302..04b87e0 100644
--- a/drivers/i2c/chips/tsl2550.c
+++ b/drivers/i2c/chips/tsl2550.c
@@ -279,7 +279,7 @@ static ssize_t __tsl2550_show_lux(struct i2c_client
*client, char *buf)
{
     u8 ch0, ch1;
     int ret;
-
+    struct tsl2550_data *data = i2c_get_clientdata(client);
     ret = tsl2550_get_adc_value(client, TSL2550_READ_ADC0);
     if (ret < 0)
         return ret;
@@ -293,7 +293,10 @@ static ssize_t __tsl2550_show_lux(struct i2c_client
*client, char *buf)
     ch1 = ret;

     /* Do the job */
-    ret = tsl2550_calculate_lux(ch0, ch1);
+    if (!data->operating_mode)
+        ret = tsl2550_calculate_lux(ch0, ch1);
+    else
+        ret = tsl2550_calculate_lux(ch0, ch1) * 5;
     if (ret < 0)
         return ret;

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

* Re: [PATCH] TSL2550: extended mode bugfix
       [not found] ` <4A79A055.1010602-EZxuzQJkuwwybS5Ee8rs3A@public.gmane.org>
@ 2009-08-05 15:14   ` Jean Delvare
       [not found]     ` <20090805171452.592a2bbd-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
       [not found]     ` <4A79AAF5.9000702@valueteam.com>
  0 siblings, 2 replies; 5+ messages in thread
From: Jean Delvare @ 2009-08-05 15:14 UTC (permalink / raw)
  To: Michele De Candia (VT); +Cc: Linux I2C

Hi Michele,

On Wed, 05 Aug 2009 17:08:05 +0200, Michele De Candia (VT) wrote:
> Hi all,
> according to the TAOS Application Note 'Controlling a Backlight with the
> TSL2550 Ambient Light Sensor' (page 14), the actual lux value in
> extended mode should be obtained multiplying the calculated lux value by 5.
> The following patch should fix the lux calculation in this case.
> 
> Regards,
> Michele De Candia
> --
> 
> Signed-off-by: Michele Jr De Candia <michele.decandia-EZxuzQJkuwwybS5Ee8rs3A@public.gmane.org>
> 
> drivers/i2c/chips/tsl2550.c |    7 +++++--
> 1 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/i2c/chips/tsl2550.c b/drivers/i2c/chips/tsl2550.c
> index b96f302..04b87e0 100644
> --- a/drivers/i2c/chips/tsl2550.c
> +++ b/drivers/i2c/chips/tsl2550.c
> @@ -279,7 +279,7 @@ static ssize_t __tsl2550_show_lux(struct i2c_client
> *client, char *buf)
> {
>      u8 ch0, ch1;

I don't know what your e-mail client is doing to the source code, but
it's bad. It replaces tabs with spaces and folds long lines at least -
I won't be able to apply your patch. Please either fix your client, or
attach the patch instead of inlining it.

>      int ret;
> -
> +    struct tsl2550_data *data = i2c_get_clientdata(client);
>      ret = tsl2550_get_adc_value(client, TSL2550_READ_ADC0);
>      if (ret < 0)
>          return ret;
> @@ -293,7 +293,10 @@ static ssize_t __tsl2550_show_lux(struct i2c_client
> *client, char *buf)
>      ch1 = ret;
> 
>      /* Do the job */
> -    ret = tsl2550_calculate_lux(ch0, ch1);
> +    if (!data->operating_mode)
> +        ret = tsl2550_calculate_lux(ch0, ch1);
> +    else
> +        ret = tsl2550_calculate_lux(ch0, ch1) * 5;
>      if (ret < 0)
>          return ret;

Operating on values before you check for errors is wrong. I'd rather do:

    ret = tsl2550_calculate_lux(ch0, ch1);
    if (ret < 0)
        return ret;
    if (data->operating_mode == 1) /* extended mode */
        ret *= 5;

OK?

-- 
Jean Delvare

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

* Re: [PATCH] TSL2550: extended mode bugfix
       [not found]     ` <20090805171452.592a2bbd-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
@ 2009-08-05 15:22       ` Wolfram Sang
  0 siblings, 0 replies; 5+ messages in thread
From: Wolfram Sang @ 2009-08-05 15:22 UTC (permalink / raw)
  To: Jean Delvare; +Cc: Michele De Candia (VT), Linux I2C

[-- Attachment #1: Type: text/plain, Size: 583 bytes --]

> Operating on values before you check for errors is wrong. I'd rather do:
> 
>     ret = tsl2550_calculate_lux(ch0, ch1);
>     if (ret < 0)
>         return ret;
>     if (data->operating_mode == 1) /* extended mode */
>         ret *= 5;

I just wanted to suggest the same :) Pity that "operating_mode" is exported to
sysfs, "extended_mode" would have been a better name, me thinks...

Regards,

   Wolfram

-- 
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

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

* Re: [PATCH] TSL2550: extended mode bugfix
       [not found]       ` <4A79AAF5.9000702-EZxuzQJkuwwybS5Ee8rs3A@public.gmane.org>
@ 2009-08-05 16:00         ` Wolfram Sang
  2009-11-09 16:33         ` Jean Delvare
  1 sibling, 0 replies; 5+ messages in thread
From: Wolfram Sang @ 2009-08-05 16:00 UTC (permalink / raw)
  To: Michele De Candia (VT); +Cc: Jean Delvare, Linux I2C

[-- Attachment #1: Type: text/plain, Size: 629 bytes --]

> About the name of 'operating_mode' field, I think it can be changed in  
> 'extended_mode' as Wolfram Sang has suggested.
> What do you think about it?

Nope, because it is exported to userspace via sysfs, this is not possible.
There may be already software depending on this name. And to have internally
one name and externally another won't help reducing the confusion :) Having an
extra comment as Jean suggested is the way to go.

Regards,

   Wolfram

-- 
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

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

* Re: [PATCH] TSL2550: extended mode bugfix
       [not found]       ` <4A79AAF5.9000702-EZxuzQJkuwwybS5Ee8rs3A@public.gmane.org>
  2009-08-05 16:00         ` Wolfram Sang
@ 2009-11-09 16:33         ` Jean Delvare
  1 sibling, 0 replies; 5+ messages in thread
From: Jean Delvare @ 2009-11-09 16:33 UTC (permalink / raw)
  To: Michele De Candia (VT); +Cc: Linux I2C, w.sang-bIcnvbaLZ9MEGnE8C9+IrQ

Hi Michele,

On Wed, 05 Aug 2009 17:53:25 +0200, Michele De Candia (VT) wrote:
> Hi Jean,
> in attachment you can find the patch with your suggestions applied.

It seems this fix somehow felt through the cracks. Sorry about that,
I'm applying it now.

-- 
Jean Delvare

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

end of thread, other threads:[~2009-11-09 16:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-05 15:08 [PATCH] TSL2550: extended mode bugfix Michele De Candia (VT)
     [not found] ` <4A79A055.1010602-EZxuzQJkuwwybS5Ee8rs3A@public.gmane.org>
2009-08-05 15:14   ` Jean Delvare
     [not found]     ` <20090805171452.592a2bbd-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2009-08-05 15:22       ` Wolfram Sang
     [not found]     ` <4A79AAF5.9000702@valueteam.com>
     [not found]       ` <4A79AAF5.9000702-EZxuzQJkuwwybS5Ee8rs3A@public.gmane.org>
2009-08-05 16:00         ` Wolfram Sang
2009-11-09 16:33         ` Jean Delvare

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.