linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] leds: leds-pca963x: workaround group blink scaling issue
@ 2016-10-13 13:16 ` Matt Ranostay
  2016-10-13 14:05   ` Jacek Anaszewski
  2016-10-25  7:15   ` Jacek Anaszewski
  0 siblings, 2 replies; 10+ messages in thread
From: Matt Ranostay @ 2016-10-13 13:16 UTC (permalink / raw)
  To: linux-kernel, devicetree; +Cc: Matt Ranostay, Tony Lindgren, Jacek Anaszewski

PCA9632TK part seems to incorrectly blink at ~1.3x of the programmed
rate. This patchset add a nxp,period-scale devicetree property to
adjust for this misconfiguration.

Cc: Tony Lindgren <tony@atomide.com>
Cc: Jacek Anaszewski <j.anaszewski@samsung.com>
Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
---
 Documentation/devicetree/bindings/leds/pca963x.txt |  3 +++
 drivers/leds/leds-pca963x.c                        | 18 +++++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/leds/pca963x.txt b/Documentation/devicetree/bindings/leds/pca963x.txt
index dafbe9931c2b..dfbdb123a9bf 100644
--- a/Documentation/devicetree/bindings/leds/pca963x.txt
+++ b/Documentation/devicetree/bindings/leds/pca963x.txt
@@ -7,6 +7,9 @@ Optional properties:
 - nxp,totem-pole : use totem pole (push-pull) instead of open-drain (pca9632 defaults
   to open-drain, newer chips to totem pole)
 - nxp,hw-blink : use hardware blinking instead of software blinking
+- nxp,period-scale : In some configurations, the chip blinks faster than expected.
+		     This parameter provides a scaling ratio (fixed point, decimal divided
+		     by 1000) to compensate, e.g. 1300=1.3x and 750=0.75x.
 
 Each led is represented as a sub-node of the nxp,pca963x device.
 
diff --git a/drivers/leds/leds-pca963x.c b/drivers/leds/leds-pca963x.c
index 407eba11e187..b6ce1f2ec33e 100644
--- a/drivers/leds/leds-pca963x.c
+++ b/drivers/leds/leds-pca963x.c
@@ -59,6 +59,7 @@ struct pca963x_chipdef {
 	u8			grpfreq;
 	u8			ledout_base;
 	int			n_leds;
+	unsigned int		scaling;
 };
 
 static struct pca963x_chipdef pca963x_chipdefs[] = {
@@ -189,6 +190,14 @@ static int pca963x_led_set(struct led_classdev *led_cdev,
 	return pca963x_brightness(pca963x, value);
 }
 
+static unsigned int pca963x_period_scale(struct pca963x_led *pca963x,
+	unsigned int val)
+{
+	unsigned int scaling = pca963x->chip->chipdef->scaling;
+
+	return scaling ? DIV_ROUND_CLOSEST(val * scaling, 1000) : val;
+}
+
 static int pca963x_blink_set(struct led_classdev *led_cdev,
 		unsigned long *delay_on, unsigned long *delay_off)
 {
@@ -207,14 +216,14 @@ static int pca963x_blink_set(struct led_classdev *led_cdev,
 		time_off = 500;
 	}
 
-	period = time_on + time_off;
+	period = pca963x_period_scale(pca963x, time_on + time_off);
 
 	/* If period not supported by hardware, default to someting sane. */
 	if ((period < PCA963X_BLINK_PERIOD_MIN) ||
 	    (period > PCA963X_BLINK_PERIOD_MAX)) {
 		time_on = 500;
 		time_off = 500;
-		period = time_on + time_off;
+		period = pca963x_period_scale(pca963x, 1000);
 	}
 
 	/*
@@ -222,7 +231,7 @@ static int pca963x_blink_set(struct led_classdev *led_cdev,
 	 *	(time_on / period) = (GDC / 256) ->
 	 *		GDC = ((time_on * 256) / period)
 	 */
-	gdc = (time_on * 256) / period;
+	gdc = (pca963x_period_scale(pca963x, time_on) * 256) / period;
 
 	/*
 	 * From manual: period = ((GFRQ + 1) / 24) in seconds.
@@ -294,6 +303,9 @@ pca963x_dt_init(struct i2c_client *client, struct pca963x_chipdef *chip)
 	else
 		pdata->blink_type = PCA963X_SW_BLINK;
 
+	if (of_property_read_u32(np, "nxp,period-scale", &chip->scaling))
+		chip->scaling = 1000;
+
 	return pdata;
 }
 
-- 
2.7.4

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

* Re: [PATCH] leds: leds-pca963x: workaround group blink scaling issue
  2016-10-13 13:16 ` [PATCH] leds: leds-pca963x: workaround group blink scaling issue Matt Ranostay
@ 2016-10-13 14:05   ` Jacek Anaszewski
  2016-10-13 14:20     ` Matt Ranostay
  2016-10-25  7:15   ` Jacek Anaszewski
  1 sibling, 1 reply; 10+ messages in thread
From: Jacek Anaszewski @ 2016-10-13 14:05 UTC (permalink / raw)
  To: Matt Ranostay, linux-kernel, devicetree; +Cc: Matt Ranostay, Tony Lindgren

Hi Matt,

On 10/13/2016 03:16 PM, Matt Ranostay wrote:
> PCA9632TK part seems to incorrectly blink at ~1.3x of the programmed
> rate. This patchset add a nxp,period-scale devicetree property to
> adjust for this misconfiguration.
>
> Cc: Tony Lindgren <tony@atomide.com>
> Cc: Jacek Anaszewski <j.anaszewski@samsung.com>
> Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
> ---
>  Documentation/devicetree/bindings/leds/pca963x.txt |  3 +++
>  drivers/leds/leds-pca963x.c                        | 18 +++++++++++++++---
>  2 files changed, 18 insertions(+), 3 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/leds/pca963x.txt b/Documentation/devicetree/bindings/leds/pca963x.txt
> index dafbe9931c2b..dfbdb123a9bf 100644
> --- a/Documentation/devicetree/bindings/leds/pca963x.txt
> +++ b/Documentation/devicetree/bindings/leds/pca963x.txt
> @@ -7,6 +7,9 @@ Optional properties:
>  - nxp,totem-pole : use totem pole (push-pull) instead of open-drain (pca9632 defaults
>    to open-drain, newer chips to totem pole)
>  - nxp,hw-blink : use hardware blinking instead of software blinking
> +- nxp,period-scale : In some configurations, the chip blinks faster than expected.
> +		     This parameter provides a scaling ratio (fixed point, decimal divided
> +		     by 1000) to compensate, e.g. 1300=1.3x and 750=0.75x.

Why DT property? Is it somehow dependent on the board configuration?
How this period-scale value is calculated? Is it inferred empirically?

>  Each led is represented as a sub-node of the nxp,pca963x device.
>
> diff --git a/drivers/leds/leds-pca963x.c b/drivers/leds/leds-pca963x.c
> index 407eba11e187..b6ce1f2ec33e 100644
> --- a/drivers/leds/leds-pca963x.c
> +++ b/drivers/leds/leds-pca963x.c
> @@ -59,6 +59,7 @@ struct pca963x_chipdef {
>  	u8			grpfreq;
>  	u8			ledout_base;
>  	int			n_leds;
> +	unsigned int		scaling;
>  };
>
>  static struct pca963x_chipdef pca963x_chipdefs[] = {
> @@ -189,6 +190,14 @@ static int pca963x_led_set(struct led_classdev *led_cdev,
>  	return pca963x_brightness(pca963x, value);
>  }
>
> +static unsigned int pca963x_period_scale(struct pca963x_led *pca963x,
> +	unsigned int val)
> +{
> +	unsigned int scaling = pca963x->chip->chipdef->scaling;
> +
> +	return scaling ? DIV_ROUND_CLOSEST(val * scaling, 1000) : val;
> +}
> +
>  static int pca963x_blink_set(struct led_classdev *led_cdev,
>  		unsigned long *delay_on, unsigned long *delay_off)
>  {
> @@ -207,14 +216,14 @@ static int pca963x_blink_set(struct led_classdev *led_cdev,
>  		time_off = 500;
>  	}
>
> -	period = time_on + time_off;
> +	period = pca963x_period_scale(pca963x, time_on + time_off);
>
>  	/* If period not supported by hardware, default to someting sane. */
>  	if ((period < PCA963X_BLINK_PERIOD_MIN) ||
>  	    (period > PCA963X_BLINK_PERIOD_MAX)) {
>  		time_on = 500;
>  		time_off = 500;
> -		period = time_on + time_off;
> +		period = pca963x_period_scale(pca963x, 1000);
>  	}
>
>  	/*
> @@ -222,7 +231,7 @@ static int pca963x_blink_set(struct led_classdev *led_cdev,
>  	 *	(time_on / period) = (GDC / 256) ->
>  	 *		GDC = ((time_on * 256) / period)
>  	 */
> -	gdc = (time_on * 256) / period;
> +	gdc = (pca963x_period_scale(pca963x, time_on) * 256) / period;
>
>  	/*
>  	 * From manual: period = ((GFRQ + 1) / 24) in seconds.
> @@ -294,6 +303,9 @@ pca963x_dt_init(struct i2c_client *client, struct pca963x_chipdef *chip)
>  	else
>  		pdata->blink_type = PCA963X_SW_BLINK;
>
> +	if (of_property_read_u32(np, "nxp,period-scale", &chip->scaling))
> +		chip->scaling = 1000;
> +
>  	return pdata;
>  }
>
>


-- 
Best regards,
Jacek Anaszewski

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

* Re: [PATCH] leds: leds-pca963x: workaround group blink scaling issue
  2016-10-13 14:05   ` Jacek Anaszewski
@ 2016-10-13 14:20     ` Matt Ranostay
  2016-10-14  6:36       ` Jacek Anaszewski
  0 siblings, 1 reply; 10+ messages in thread
From: Matt Ranostay @ 2016-10-13 14:20 UTC (permalink / raw)
  To: Jacek Anaszewski; +Cc: linux-kernel, devicetree, Matt Ranostay, Tony Lindgren

On Thu, Oct 13, 2016 at 4:05 PM, Jacek Anaszewski
<j.anaszewski@samsung.com> wrote:
> Hi Matt,
>
> On 10/13/2016 03:16 PM, Matt Ranostay wrote:
>>
>> PCA9632TK part seems to incorrectly blink at ~1.3x of the programmed
>> rate. This patchset add a nxp,period-scale devicetree property to
>> adjust for this misconfiguration.
>>
>> Cc: Tony Lindgren <tony@atomide.com>
>> Cc: Jacek Anaszewski <j.anaszewski@samsung.com>
>> Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
>> ---
>>  Documentation/devicetree/bindings/leds/pca963x.txt |  3 +++
>>  drivers/leds/leds-pca963x.c                        | 18
>> +++++++++++++++---
>>  2 files changed, 18 insertions(+), 3 deletions(-)
>>
>> diff --git a/Documentation/devicetree/bindings/leds/pca963x.txt
>> b/Documentation/devicetree/bindings/leds/pca963x.txt
>> index dafbe9931c2b..dfbdb123a9bf 100644
>> --- a/Documentation/devicetree/bindings/leds/pca963x.txt
>> +++ b/Documentation/devicetree/bindings/leds/pca963x.txt
>> @@ -7,6 +7,9 @@ Optional properties:
>>  - nxp,totem-pole : use totem pole (push-pull) instead of open-drain
>> (pca9632 defaults
>>    to open-drain, newer chips to totem pole)
>>  - nxp,hw-blink : use hardware blinking instead of software blinking
>> +- nxp,period-scale : In some configurations, the chip blinks faster than
>> expected.
>> +                    This parameter provides a scaling ratio (fixed point,
>> decimal divided
>> +                    by 1000) to compensate, e.g. 1300=1.3x and 750=0.75x.
>
>
> Why DT property? Is it somehow dependent on the board configuration?
> How this period-scale value is calculated? Is it inferred empirically?
>

We empirically discovered and verified this with an logic analyzer on
multiple batches of this part.
Reason for the DT entry is we aren't 100% sure that it is always going
to be the same with different board revs.

Could be that parts clock acts differently with supply voltage.   This
has been calculated by setting it an expected value, and measuring the
actual result with the logic analyzer.

>
>>  Each led is represented as a sub-node of the nxp,pca963x device.
>>
>> diff --git a/drivers/leds/leds-pca963x.c b/drivers/leds/leds-pca963x.c
>> index 407eba11e187..b6ce1f2ec33e 100644
>> --- a/drivers/leds/leds-pca963x.c
>> +++ b/drivers/leds/leds-pca963x.c
>> @@ -59,6 +59,7 @@ struct pca963x_chipdef {
>>         u8                      grpfreq;
>>         u8                      ledout_base;
>>         int                     n_leds;
>> +       unsigned int            scaling;
>>  };
>>
>>  static struct pca963x_chipdef pca963x_chipdefs[] = {
>> @@ -189,6 +190,14 @@ static int pca963x_led_set(struct led_classdev
>> *led_cdev,
>>         return pca963x_brightness(pca963x, value);
>>  }
>>
>> +static unsigned int pca963x_period_scale(struct pca963x_led *pca963x,
>> +       unsigned int val)
>> +{
>> +       unsigned int scaling = pca963x->chip->chipdef->scaling;
>> +
>> +       return scaling ? DIV_ROUND_CLOSEST(val * scaling, 1000) : val;
>> +}
>> +
>>  static int pca963x_blink_set(struct led_classdev *led_cdev,
>>                 unsigned long *delay_on, unsigned long *delay_off)
>>  {
>> @@ -207,14 +216,14 @@ static int pca963x_blink_set(struct led_classdev
>> *led_cdev,
>>                 time_off = 500;
>>         }
>>
>> -       period = time_on + time_off;
>> +       period = pca963x_period_scale(pca963x, time_on + time_off);
>>
>>         /* If period not supported by hardware, default to someting sane.
>> */
>>         if ((period < PCA963X_BLINK_PERIOD_MIN) ||
>>             (period > PCA963X_BLINK_PERIOD_MAX)) {
>>                 time_on = 500;
>>                 time_off = 500;
>> -               period = time_on + time_off;
>> +               period = pca963x_period_scale(pca963x, 1000);
>>         }
>>
>>         /*
>> @@ -222,7 +231,7 @@ static int pca963x_blink_set(struct led_classdev
>> *led_cdev,
>>          *      (time_on / period) = (GDC / 256) ->
>>          *              GDC = ((time_on * 256) / period)
>>          */
>> -       gdc = (time_on * 256) / period;
>> +       gdc = (pca963x_period_scale(pca963x, time_on) * 256) / period;
>>
>>         /*
>>          * From manual: period = ((GFRQ + 1) / 24) in seconds.
>> @@ -294,6 +303,9 @@ pca963x_dt_init(struct i2c_client *client, struct
>> pca963x_chipdef *chip)
>>         else
>>                 pdata->blink_type = PCA963X_SW_BLINK;
>>
>> +       if (of_property_read_u32(np, "nxp,period-scale", &chip->scaling))
>> +               chip->scaling = 1000;
>> +
>>         return pdata;
>>  }
>>
>>
>
>
> --
> Best regards,
> Jacek Anaszewski

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

* Re: [PATCH] leds: leds-pca963x: workaround group blink scaling issue
  2016-10-13 14:20     ` Matt Ranostay
@ 2016-10-14  6:36       ` Jacek Anaszewski
  2016-10-14 14:20         ` Tony Lindgren
  0 siblings, 1 reply; 10+ messages in thread
From: Jacek Anaszewski @ 2016-10-14  6:36 UTC (permalink / raw)
  To: Matt Ranostay
  Cc: linux-kernel, devicetree, Matt Ranostay, Tony Lindgren,
	Rob Herring, Mark Rutland

On 10/13/2016 04:20 PM, Matt Ranostay wrote:
> On Thu, Oct 13, 2016 at 4:05 PM, Jacek Anaszewski
> <j.anaszewski@samsung.com> wrote:
>> Hi Matt,
>>
>> On 10/13/2016 03:16 PM, Matt Ranostay wrote:
>>>
>>> PCA9632TK part seems to incorrectly blink at ~1.3x of the programmed
>>> rate. This patchset add a nxp,period-scale devicetree property to
>>> adjust for this misconfiguration.
>>>
>>> Cc: Tony Lindgren <tony@atomide.com>
>>> Cc: Jacek Anaszewski <j.anaszewski@samsung.com>
>>> Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
>>> ---
>>>  Documentation/devicetree/bindings/leds/pca963x.txt |  3 +++
>>>  drivers/leds/leds-pca963x.c                        | 18
>>> +++++++++++++++---
>>>  2 files changed, 18 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/Documentation/devicetree/bindings/leds/pca963x.txt
>>> b/Documentation/devicetree/bindings/leds/pca963x.txt
>>> index dafbe9931c2b..dfbdb123a9bf 100644
>>> --- a/Documentation/devicetree/bindings/leds/pca963x.txt
>>> +++ b/Documentation/devicetree/bindings/leds/pca963x.txt
>>> @@ -7,6 +7,9 @@ Optional properties:
>>>  - nxp,totem-pole : use totem pole (push-pull) instead of open-drain
>>> (pca9632 defaults
>>>    to open-drain, newer chips to totem pole)
>>>  - nxp,hw-blink : use hardware blinking instead of software blinking
>>> +- nxp,period-scale : In some configurations, the chip blinks faster than
>>> expected.
>>> +                    This parameter provides a scaling ratio (fixed point,
>>> decimal divided
>>> +                    by 1000) to compensate, e.g. 1300=1.3x and 750=0.75x.
>>
>>
>> Why DT property? Is it somehow dependent on the board configuration?
>> How this period-scale value is calculated? Is it inferred empirically?
>>
>
> We empirically discovered and verified this with an logic analyzer on
> multiple batches of this part.
> Reason for the DT entry is we aren't 100% sure that it is always going
> to be the same with different board revs.
>
> Could be that parts clock acts differently with supply voltage.   This
> has been calculated by setting it an expected value, and measuring the
> actual result with the logic analyzer.

I'd like to have DT maintainer's ack for this.

Cc Rob and Mark.

>>>  Each led is represented as a sub-node of the nxp,pca963x device.
>>>
>>> diff --git a/drivers/leds/leds-pca963x.c b/drivers/leds/leds-pca963x.c
>>> index 407eba11e187..b6ce1f2ec33e 100644
>>> --- a/drivers/leds/leds-pca963x.c
>>> +++ b/drivers/leds/leds-pca963x.c
>>> @@ -59,6 +59,7 @@ struct pca963x_chipdef {
>>>         u8                      grpfreq;
>>>         u8                      ledout_base;
>>>         int                     n_leds;
>>> +       unsigned int            scaling;
>>>  };
>>>
>>>  static struct pca963x_chipdef pca963x_chipdefs[] = {
>>> @@ -189,6 +190,14 @@ static int pca963x_led_set(struct led_classdev
>>> *led_cdev,
>>>         return pca963x_brightness(pca963x, value);
>>>  }
>>>
>>> +static unsigned int pca963x_period_scale(struct pca963x_led *pca963x,
>>> +       unsigned int val)
>>> +{
>>> +       unsigned int scaling = pca963x->chip->chipdef->scaling;
>>> +
>>> +       return scaling ? DIV_ROUND_CLOSEST(val * scaling, 1000) : val;
>>> +}
>>> +
>>>  static int pca963x_blink_set(struct led_classdev *led_cdev,
>>>                 unsigned long *delay_on, unsigned long *delay_off)
>>>  {
>>> @@ -207,14 +216,14 @@ static int pca963x_blink_set(struct led_classdev
>>> *led_cdev,
>>>                 time_off = 500;
>>>         }
>>>
>>> -       period = time_on + time_off;
>>> +       period = pca963x_period_scale(pca963x, time_on + time_off);
>>>
>>>         /* If period not supported by hardware, default to someting sane.
>>> */
>>>         if ((period < PCA963X_BLINK_PERIOD_MIN) ||
>>>             (period > PCA963X_BLINK_PERIOD_MAX)) {
>>>                 time_on = 500;
>>>                 time_off = 500;
>>> -               period = time_on + time_off;
>>> +               period = pca963x_period_scale(pca963x, 1000);
>>>         }
>>>
>>>         /*
>>> @@ -222,7 +231,7 @@ static int pca963x_blink_set(struct led_classdev
>>> *led_cdev,
>>>          *      (time_on / period) = (GDC / 256) ->
>>>          *              GDC = ((time_on * 256) / period)
>>>          */
>>> -       gdc = (time_on * 256) / period;
>>> +       gdc = (pca963x_period_scale(pca963x, time_on) * 256) / period;
>>>
>>>         /*
>>>          * From manual: period = ((GFRQ + 1) / 24) in seconds.
>>> @@ -294,6 +303,9 @@ pca963x_dt_init(struct i2c_client *client, struct
>>> pca963x_chipdef *chip)
>>>         else
>>>                 pdata->blink_type = PCA963X_SW_BLINK;
>>>
>>> +       if (of_property_read_u32(np, "nxp,period-scale", &chip->scaling))
>>> +               chip->scaling = 1000;
>>> +
>>>         return pdata;
>>>  }
>>>
>>>
>>
>>
>> --
>> Best regards,
>> Jacek Anaszewski
> --
> To unsubscribe from this list: send the line "unsubscribe devicetree" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
>
>


-- 
Best regards,
Jacek Anaszewski

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

* Re: [PATCH] leds: leds-pca963x: workaround group blink scaling issue
  2016-10-14  6:36       ` Jacek Anaszewski
@ 2016-10-14 14:20         ` Tony Lindgren
  2016-10-15 12:00           ` Matt Ranostay
  0 siblings, 1 reply; 10+ messages in thread
From: Tony Lindgren @ 2016-10-14 14:20 UTC (permalink / raw)
  To: Jacek Anaszewski
  Cc: Matt Ranostay, linux-kernel, devicetree, Matt Ranostay,
	Rob Herring, Mark Rutland

* Jacek Anaszewski <j.anaszewski@samsung.com> [161013 23:37]:
> On 10/13/2016 04:20 PM, Matt Ranostay wrote:
> > On Thu, Oct 13, 2016 at 4:05 PM, Jacek Anaszewski
> > <j.anaszewski@samsung.com> wrote:
> > > Why DT property? Is it somehow dependent on the board configuration?
> > > How this period-scale value is calculated? Is it inferred empirically?
> > > 
> > 
> > We empirically discovered and verified this with an logic analyzer on
> > multiple batches of this part.
> > Reason for the DT entry is we aren't 100% sure that it is always going
> > to be the same with different board revs.
> > 
> > Could be that parts clock acts differently with supply voltage.   This
> > has been calculated by setting it an expected value, and measuring the
> > actual result with the logic analyzer.
> 
> I'd like to have DT maintainer's ack for this.
> 
> Cc Rob and Mark.

How about do this based on the compatible property instead? If there
are multiple manufacturers for this part and only a certain
parts have this issue we should have multiple compatible properties.

Then if it turns out all of them need this scaling there's no need
to update the binding.

Regards,

Tony

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

* Re: [PATCH] leds: leds-pca963x: workaround group blink scaling issue
  2016-10-14 14:20         ` Tony Lindgren
@ 2016-10-15 12:00           ` Matt Ranostay
  2016-10-17  7:58             ` Jacek Anaszewski
  0 siblings, 1 reply; 10+ messages in thread
From: Matt Ranostay @ 2016-10-15 12:00 UTC (permalink / raw)
  To: Tony Lindgren
  Cc: Jacek Anaszewski, linux-kernel, devicetree, Matt Ranostay,
	Rob Herring, Mark Rutland

On Fri, Oct 14, 2016 at 7:20 AM, Tony Lindgren <tony@atomide.com> wrote:
> * Jacek Anaszewski <j.anaszewski@samsung.com> [161013 23:37]:
>> On 10/13/2016 04:20 PM, Matt Ranostay wrote:
>> > On Thu, Oct 13, 2016 at 4:05 PM, Jacek Anaszewski
>> > <j.anaszewski@samsung.com> wrote:
>> > > Why DT property? Is it somehow dependent on the board configuration?
>> > > How this period-scale value is calculated? Is it inferred empirically?
>> > >
>> >
>> > We empirically discovered and verified this with an logic analyzer on
>> > multiple batches of this part.
>> > Reason for the DT entry is we aren't 100% sure that it is always going
>> > to be the same with different board revs.
>> >
>> > Could be that parts clock acts differently with supply voltage.   This
>> > has been calculated by setting it an expected value, and measuring the
>> > actual result with the logic analyzer.
>>
>> I'd like to have DT maintainer's ack for this.
>>
>> Cc Rob and Mark.
>
> How about do this based on the compatible property instead? If there
> are multiple manufacturers for this part and only a certain
> parts have this issue we should have multiple compatible properties.
>

I could only find that NXP as the manufacturer of that part. It is
possible since the clock is internal to the chipset that the vdd of
2.5V is doing something undefined.

> Then if it turns out all of them need this scaling there's no need
> to update the binding.

Understandable.

>
> Regards,
>
> Tony

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

* Re: [PATCH] leds: leds-pca963x: workaround group blink scaling issue
  2016-10-15 12:00           ` Matt Ranostay
@ 2016-10-17  7:58             ` Jacek Anaszewski
  2016-10-18 13:49               ` Rob Herring
  0 siblings, 1 reply; 10+ messages in thread
From: Jacek Anaszewski @ 2016-10-17  7:58 UTC (permalink / raw)
  To: Matt Ranostay, Tony Lindgren
  Cc: linux-kernel, devicetree, Matt Ranostay, Rob Herring, Mark Rutland

On 10/15/2016 02:00 PM, Matt Ranostay wrote:
> On Fri, Oct 14, 2016 at 7:20 AM, Tony Lindgren <tony@atomide.com> wrote:
>> * Jacek Anaszewski <j.anaszewski@samsung.com> [161013 23:37]:
>>> On 10/13/2016 04:20 PM, Matt Ranostay wrote:
>>>> On Thu, Oct 13, 2016 at 4:05 PM, Jacek Anaszewski
>>>> <j.anaszewski@samsung.com> wrote:
>>>>> Why DT property? Is it somehow dependent on the board configuration?
>>>>> How this period-scale value is calculated? Is it inferred empirically?
>>>>>
>>>>
>>>> We empirically discovered and verified this with an logic analyzer on
>>>> multiple batches of this part.
>>>> Reason for the DT entry is we aren't 100% sure that it is always going
>>>> to be the same with different board revs.
>>>>
>>>> Could be that parts clock acts differently with supply voltage.   This
>>>> has been calculated by setting it an expected value, and measuring the
>>>> actual result with the logic analyzer.
>>>
>>> I'd like to have DT maintainer's ack for this.
>>>
>>> Cc Rob and Mark.
>>
>> How about do this based on the compatible property instead? If there
>> are multiple manufacturers for this part and only a certain
>> parts have this issue we should have multiple compatible properties.
>>
>
> I could only find that NXP as the manufacturer of that part. It is
> possible since the clock is internal to the chipset that the vdd of
> 2.5V is doing something undefined.
>
>> Then if it turns out all of them need this scaling there's no need
>> to update the binding.
>
> Understandable.

Since at present we can't guarantee that all produced devices
are affected, then we should strive to avoid breaking any existing
users of the possible non-affected devices.

In view of that the addition of a new "compatible" proposed by Tony
seems most reasonable.

Still, DT maintainer's opinion is required.

-- 
Best regards,
Jacek Anaszewski

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

* Re: [PATCH] leds: leds-pca963x: workaround group blink scaling issue
  2016-10-17  7:58             ` Jacek Anaszewski
@ 2016-10-18 13:49               ` Rob Herring
  2016-10-18 14:17                 ` Jacek Anaszewski
  0 siblings, 1 reply; 10+ messages in thread
From: Rob Herring @ 2016-10-18 13:49 UTC (permalink / raw)
  To: Jacek Anaszewski
  Cc: Matt Ranostay, Tony Lindgren, linux-kernel, devicetree,
	Matt Ranostay, Mark Rutland

On Mon, Oct 17, 2016 at 09:58:26AM +0200, Jacek Anaszewski wrote:
> On 10/15/2016 02:00 PM, Matt Ranostay wrote:
> > On Fri, Oct 14, 2016 at 7:20 AM, Tony Lindgren <tony@atomide.com> wrote:
> > > * Jacek Anaszewski <j.anaszewski@samsung.com> [161013 23:37]:
> > > > On 10/13/2016 04:20 PM, Matt Ranostay wrote:
> > > > > On Thu, Oct 13, 2016 at 4:05 PM, Jacek Anaszewski
> > > > > <j.anaszewski@samsung.com> wrote:
> > > > > > Why DT property? Is it somehow dependent on the board configuration?
> > > > > > How this period-scale value is calculated? Is it inferred empirically?
> > > > > > 
> > > > > 
> > > > > We empirically discovered and verified this with an logic analyzer on
> > > > > multiple batches of this part.
> > > > > Reason for the DT entry is we aren't 100% sure that it is always going
> > > > > to be the same with different board revs.
> > > > > 
> > > > > Could be that parts clock acts differently with supply voltage.   This
> > > > > has been calculated by setting it an expected value, and measuring the
> > > > > actual result with the logic analyzer.
> > > > 
> > > > I'd like to have DT maintainer's ack for this.
> > > > 
> > > > Cc Rob and Mark.
> > > 
> > > How about do this based on the compatible property instead? If there
> > > are multiple manufacturers for this part and only a certain
> > > parts have this issue we should have multiple compatible properties.
> > > 
> > 
> > I could only find that NXP as the manufacturer of that part. It is
> > possible since the clock is internal to the chipset that the vdd of
> > 2.5V is doing something undefined.
> > 
> > > Then if it turns out all of them need this scaling there's no need
> > > to update the binding.
> > 
> > Understandable.
> 
> Since at present we can't guarantee that all produced devices
> are affected, then we should strive to avoid breaking any existing
> users of the possible non-affected devices.
> 
> In view of that the addition of a new "compatible" proposed by Tony
> seems most reasonable.
> 
> Still, DT maintainer's opinion is required.

Seems like a quirk of this board, so I think the added property is fine.

It could be existing users just didn't notice the rate being off. 30% is 
probably not all that noticeable to the human eye.

Rob

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

* Re: [PATCH] leds: leds-pca963x: workaround group blink scaling issue
  2016-10-18 13:49               ` Rob Herring
@ 2016-10-18 14:17                 ` Jacek Anaszewski
  0 siblings, 0 replies; 10+ messages in thread
From: Jacek Anaszewski @ 2016-10-18 14:17 UTC (permalink / raw)
  To: Rob Herring
  Cc: Matt Ranostay, Tony Lindgren, linux-kernel, devicetree,
	Matt Ranostay, Mark Rutland

On 10/18/2016 03:49 PM, Rob Herring wrote:
> On Mon, Oct 17, 2016 at 09:58:26AM +0200, Jacek Anaszewski wrote:
>> On 10/15/2016 02:00 PM, Matt Ranostay wrote:
>>> On Fri, Oct 14, 2016 at 7:20 AM, Tony Lindgren <tony@atomide.com> wrote:
>>>> * Jacek Anaszewski <j.anaszewski@samsung.com> [161013 23:37]:
>>>>> On 10/13/2016 04:20 PM, Matt Ranostay wrote:
>>>>>> On Thu, Oct 13, 2016 at 4:05 PM, Jacek Anaszewski
>>>>>> <j.anaszewski@samsung.com> wrote:
>>>>>>> Why DT property? Is it somehow dependent on the board configuration?
>>>>>>> How this period-scale value is calculated? Is it inferred empirically?
>>>>>>>
>>>>>>
>>>>>> We empirically discovered and verified this with an logic analyzer on
>>>>>> multiple batches of this part.
>>>>>> Reason for the DT entry is we aren't 100% sure that it is always going
>>>>>> to be the same with different board revs.
>>>>>>
>>>>>> Could be that parts clock acts differently with supply voltage.   This
>>>>>> has been calculated by setting it an expected value, and measuring the
>>>>>> actual result with the logic analyzer.
>>>>>
>>>>> I'd like to have DT maintainer's ack for this.
>>>>>
>>>>> Cc Rob and Mark.
>>>>
>>>> How about do this based on the compatible property instead? If there
>>>> are multiple manufacturers for this part and only a certain
>>>> parts have this issue we should have multiple compatible properties.
>>>>
>>>
>>> I could only find that NXP as the manufacturer of that part. It is
>>> possible since the clock is internal to the chipset that the vdd of
>>> 2.5V is doing something undefined.
>>>
>>>> Then if it turns out all of them need this scaling there's no need
>>>> to update the binding.
>>>
>>> Understandable.
>>
>> Since at present we can't guarantee that all produced devices
>> are affected, then we should strive to avoid breaking any existing
>> users of the possible non-affected devices.
>>
>> In view of that the addition of a new "compatible" proposed by Tony
>> seems most reasonable.
>>
>> Still, DT maintainer's opinion is required.
>
> Seems like a quirk of this board, so I think the added property is fine.
>
> It could be existing users just didn't notice the rate being off. 30% is
> probably not all that noticeable to the human eye.

Thanks for the feedback. I infer that you wouldn't mind if
I added your ack to this commit then?

-- 
Best regards,
Jacek Anaszewski

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

* Re: [PATCH] leds: leds-pca963x: workaround group blink scaling issue
  2016-10-13 13:16 ` [PATCH] leds: leds-pca963x: workaround group blink scaling issue Matt Ranostay
  2016-10-13 14:05   ` Jacek Anaszewski
@ 2016-10-25  7:15   ` Jacek Anaszewski
  1 sibling, 0 replies; 10+ messages in thread
From: Jacek Anaszewski @ 2016-10-25  7:15 UTC (permalink / raw)
  To: Matt Ranostay, linux-kernel, devicetree
  Cc: Matt Ranostay, Tony Lindgren, Rob Herring

Hi Matt,

Patch applied.

Thanks,
Jacek Anaszewski

On 10/13/2016 03:16 PM, Matt Ranostay wrote:
> PCA9632TK part seems to incorrectly blink at ~1.3x of the programmed
> rate. This patchset add a nxp,period-scale devicetree property to
> adjust for this misconfiguration.
>
> Cc: Tony Lindgren <tony@atomide.com>
> Cc: Jacek Anaszewski <j.anaszewski@samsung.com>
> Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
> ---
>  Documentation/devicetree/bindings/leds/pca963x.txt |  3 +++
>  drivers/leds/leds-pca963x.c                        | 18 +++++++++++++++---
>  2 files changed, 18 insertions(+), 3 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/leds/pca963x.txt b/Documentation/devicetree/bindings/leds/pca963x.txt
> index dafbe9931c2b..dfbdb123a9bf 100644
> --- a/Documentation/devicetree/bindings/leds/pca963x.txt
> +++ b/Documentation/devicetree/bindings/leds/pca963x.txt
> @@ -7,6 +7,9 @@ Optional properties:
>  - nxp,totem-pole : use totem pole (push-pull) instead of open-drain (pca9632 defaults
>    to open-drain, newer chips to totem pole)
>  - nxp,hw-blink : use hardware blinking instead of software blinking
> +- nxp,period-scale : In some configurations, the chip blinks faster than expected.
> +		     This parameter provides a scaling ratio (fixed point, decimal divided
> +		     by 1000) to compensate, e.g. 1300=1.3x and 750=0.75x.
>
>  Each led is represented as a sub-node of the nxp,pca963x device.
>
> diff --git a/drivers/leds/leds-pca963x.c b/drivers/leds/leds-pca963x.c
> index 407eba11e187..b6ce1f2ec33e 100644
> --- a/drivers/leds/leds-pca963x.c
> +++ b/drivers/leds/leds-pca963x.c
> @@ -59,6 +59,7 @@ struct pca963x_chipdef {
>  	u8			grpfreq;
>  	u8			ledout_base;
>  	int			n_leds;
> +	unsigned int		scaling;
>  };
>
>  static struct pca963x_chipdef pca963x_chipdefs[] = {
> @@ -189,6 +190,14 @@ static int pca963x_led_set(struct led_classdev *led_cdev,
>  	return pca963x_brightness(pca963x, value);
>  }
>
> +static unsigned int pca963x_period_scale(struct pca963x_led *pca963x,
> +	unsigned int val)
> +{
> +	unsigned int scaling = pca963x->chip->chipdef->scaling;
> +
> +	return scaling ? DIV_ROUND_CLOSEST(val * scaling, 1000) : val;
> +}
> +
>  static int pca963x_blink_set(struct led_classdev *led_cdev,
>  		unsigned long *delay_on, unsigned long *delay_off)
>  {
> @@ -207,14 +216,14 @@ static int pca963x_blink_set(struct led_classdev *led_cdev,
>  		time_off = 500;
>  	}
>
> -	period = time_on + time_off;
> +	period = pca963x_period_scale(pca963x, time_on + time_off);
>
>  	/* If period not supported by hardware, default to someting sane. */
>  	if ((period < PCA963X_BLINK_PERIOD_MIN) ||
>  	    (period > PCA963X_BLINK_PERIOD_MAX)) {
>  		time_on = 500;
>  		time_off = 500;
> -		period = time_on + time_off;
> +		period = pca963x_period_scale(pca963x, 1000);
>  	}
>
>  	/*
> @@ -222,7 +231,7 @@ static int pca963x_blink_set(struct led_classdev *led_cdev,
>  	 *	(time_on / period) = (GDC / 256) ->
>  	 *		GDC = ((time_on * 256) / period)
>  	 */
> -	gdc = (time_on * 256) / period;
> +	gdc = (pca963x_period_scale(pca963x, time_on) * 256) / period;
>
>  	/*
>  	 * From manual: period = ((GFRQ + 1) / 24) in seconds.
> @@ -294,6 +303,9 @@ pca963x_dt_init(struct i2c_client *client, struct pca963x_chipdef *chip)
>  	else
>  		pdata->blink_type = PCA963X_SW_BLINK;
>
> +	if (of_property_read_u32(np, "nxp,period-scale", &chip->scaling))
> +		chip->scaling = 1000;
> +
>  	return pdata;
>  }
>
>


-- 
Best regards,
Jacek Anaszewski

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

end of thread, other threads:[~2016-10-25  7:15 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20161013131622eucas1p2e419c58b25f2c61da22d390f2adfacfd@eucas1p2.samsung.com>
2016-10-13 13:16 ` [PATCH] leds: leds-pca963x: workaround group blink scaling issue Matt Ranostay
2016-10-13 14:05   ` Jacek Anaszewski
2016-10-13 14:20     ` Matt Ranostay
2016-10-14  6:36       ` Jacek Anaszewski
2016-10-14 14:20         ` Tony Lindgren
2016-10-15 12:00           ` Matt Ranostay
2016-10-17  7:58             ` Jacek Anaszewski
2016-10-18 13:49               ` Rob Herring
2016-10-18 14:17                 ` Jacek Anaszewski
2016-10-25  7:15   ` Jacek Anaszewski

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