Linux LED subsystem development
 help / color / mirror / Atom feed
* [PATCH] leds: leds-mc13783: Fix MC13892 keypad led access
@ 2016-10-09 13:37 ` Alexander Kurz
  2016-10-09 17:41   ` Alexander Shiyan
  2016-10-10 12:14   ` Jacek Anaszewski
  0 siblings, 2 replies; 12+ messages in thread
From: Alexander Kurz @ 2016-10-09 13:37 UTC (permalink / raw)
  To: Richard Purdie
  Cc: Jacek Anaszewski, Alexander Shiyan, Bryan Wu, linux-leds,
	Alexander Kurz

Fix the register access shift argument calculation introduced with
commit a59ce6584d56 ("leds: leds-mc13783: Add MC34708 LED support")
and re-enable access to the "keypad" led for MC13892 MFC devices.

Signed-off-by: Alexander Kurz <akurz@blala.de>
---
 drivers/leds/leds-mc13783.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c
index a2e4c17..2421cf10 100644
--- a/drivers/leds/leds-mc13783.c
+++ b/drivers/leds/leds-mc13783.c
@@ -84,8 +84,9 @@ static int mc13xxx_led_set(struct led_classdev *led_cdev,
 	case MC13892_LED_MD:
 	case MC13892_LED_AD:
 	case MC13892_LED_KP:
-		reg = (led->id - MC13892_LED_MD) / 2;
-		shift = 3 + (led->id - MC13892_LED_MD) * 12;
+		off = led->id - MC13892_LED_MD;
+		reg = off / 2;
+		shift = 3 + (off - reg * 2) * 12;
 		break;
 	case MC13892_LED_R:
 	case MC13892_LED_G:
-- 
2.1.4

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

* Re: [PATCH] leds: leds-mc13783: Fix MC13892 keypad led access
  2016-10-09 13:37 ` [PATCH] leds: leds-mc13783: Fix MC13892 keypad led access Alexander Kurz
@ 2016-10-09 17:41   ` Alexander Shiyan
  2016-10-09 19:15     ` Alexander Kurz
  2016-10-10 12:14   ` Jacek Anaszewski
  1 sibling, 1 reply; 12+ messages in thread
From: Alexander Shiyan @ 2016-10-09 17:41 UTC (permalink / raw)
  To: Alexander Kurz; +Cc: Jacek Anaszewski, Bryan Wu, linux-leds, Richard Purdie

>Воскресенье,  9 октября 2016, 16:37 +03:00 от Alexander Kurz <akurz@blala.de>:
>
>Fix the register access shift argument calculation introduced with
>commit a59ce6584d56 ("leds: leds-mc13783: Add MC34708 LED support")
>and re-enable access to the "keypad" led for MC13892 MFC devices.
>
>Signed-off-by: Alexander Kurz < akurz@blala.de >
>---
> drivers/leds/leds-mc13783.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
>diff --git a/drivers/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c
>index a2e4c17..2421cf10 100644
>--- a/drivers/leds/leds-mc13783.c
>+++ b/drivers/leds/leds-mc13783.c
>@@ -84,8 +84,9 @@ static int mc13xxx_led_set(struct led_classdev *led_cdev,
> case MC13892_LED_MD:
> case MC13892_LED_AD:
> case MC13892_LED_KP:
>-reg = (led->id - MC13892_LED_MD) / 2;
>-shift = 3 + (led->id - MC13892_LED_MD) * 12;
>+off = led->id - MC13892_LED_MD;
>+reg = off / 2;
>+shift = 3 + (off - reg * 2) * 12;
> break;
> case MC13892_LED_R:
> case MC13892_LED_G:

I am suspect the next caclulation is more readable:

reg = (led->id - MC13892_LED_MD) / 2;
off = ((led->id - MC13892_LED_MD) % 2) * 12;
shift = 3 +  off;

---


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

* Re: [PATCH] leds: leds-mc13783: Fix MC13892 keypad led access
  2016-10-09 17:41   ` Alexander Shiyan
@ 2016-10-09 19:15     ` Alexander Kurz
  0 siblings, 0 replies; 12+ messages in thread
From: Alexander Kurz @ 2016-10-09 19:15 UTC (permalink / raw)
  To: Alexander Shiyan; +Cc: Jacek Anaszewski, Bryan Wu, linux-leds, Richard Purdie

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1504 bytes --]



On Sun, 9 Oct 2016, Alexander Shiyan wrote:

> >Воскресенье,  9 октября 2016, 16:37 +03:00 от Alexander Kurz <akurz@blala.de>:
> >
> >Fix the register access shift argument calculation introduced with
> >commit a59ce6584d56 ("leds: leds-mc13783: Add MC34708 LED support")
> >and re-enable access to the "keypad" led for MC13892 MFC devices.
> >
> >Signed-off-by: Alexander Kurz < akurz@blala.de >
> >---
> > drivers/leds/leds-mc13783.c | 5 +++--
> > 1 file changed, 3 insertions(+), 2 deletions(-)
> >
> >diff --git a/drivers/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c
> >index a2e4c17..2421cf10 100644
> >--- a/drivers/leds/leds-mc13783.c
> >+++ b/drivers/leds/leds-mc13783.c
> >@@ -84,8 +84,9 @@ static int mc13xxx_led_set(struct led_classdev *led_cdev,
> > case MC13892_LED_MD:
> > case MC13892_LED_AD:
> > case MC13892_LED_KP:
> >-reg = (led->id - MC13892_LED_MD) / 2;
> >-shift = 3 + (led->id - MC13892_LED_MD) * 12;
> >+off = led->id - MC13892_LED_MD;
> >+reg = off / 2;
> >+shift = 3 + (off - reg * 2) * 12;
> > break;
> > case MC13892_LED_R:
> > case MC13892_LED_G:
> 
> I am suspect the next caclulation is more readable:
> 
> reg = (led->id - MC13892_LED_MD) / 2;
> off = ((led->id - MC13892_LED_MD) % 2) * 12;
> shift = 3 +  off;
Probably yes, but it introduces different styles of calculating
basically the same data in this function (see some lines above and
below the patched lines / not visible in the patch context)
I just kept it to a uniform style.

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

* Re: [PATCH] leds: leds-mc13783: Fix MC13892 keypad led access
  2016-10-09 13:37 ` [PATCH] leds: leds-mc13783: Fix MC13892 keypad led access Alexander Kurz
  2016-10-09 17:41   ` Alexander Shiyan
@ 2016-10-10 12:14   ` Jacek Anaszewski
  2016-10-10 12:22     ` Alexander Shiyan
  2016-10-10 12:52     ` Alexander Kurz
  1 sibling, 2 replies; 12+ messages in thread
From: Jacek Anaszewski @ 2016-10-10 12:14 UTC (permalink / raw)
  To: Alexander Kurz, Richard Purdie; +Cc: Alexander Shiyan, Bryan Wu, linux-leds

Hi Alexander,

Thanks for the patch.

On 10/09/2016 03:37 PM, Alexander Kurz wrote:
> Fix the register access shift argument calculation introduced with
> commit a59ce6584d56 ("leds: leds-mc13783: Add MC34708 LED support")
> and re-enable access to the "keypad" led for MC13892 MFC devices.
>
> Signed-off-by: Alexander Kurz <akurz@blala.de>
> ---
>  drivers/leds/leds-mc13783.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c
> index a2e4c17..2421cf10 100644
> --- a/drivers/leds/leds-mc13783.c
> +++ b/drivers/leds/leds-mc13783.c
> @@ -84,8 +84,9 @@ static int mc13xxx_led_set(struct led_classdev *led_cdev,
>  	case MC13892_LED_MD:
>  	case MC13892_LED_AD:
>  	case MC13892_LED_KP:
> -		reg = (led->id - MC13892_LED_MD) / 2;
> -		shift = 3 + (led->id - MC13892_LED_MD) * 12;
> +		off = led->id - MC13892_LED_MD;
> +		reg = off / 2;
> +		shift = 3 + (off - reg * 2) * 12;
>  		break;
>  	case MC13892_LED_R:
>  	case MC13892_LED_G:
>

While trying to analyze these calculations I noticed a discrepancy
between DT documentation and the enum in the header file.

Documentation/devicetree/bindings/mfd/mc13xxx.txt:

MC13892 LED IDs:
     0  : Main display
     1  : AUX display
     2  : Keypad
     3  : Red
     4  : Green
     5  : Blue

include/linux/mfd/mc13xxx.h:

enum {
         /* MC13783 LED IDs */
         MC13783_LED_MD,
         MC13783_LED_AD,
         MC13783_LED_KP,
         MC13783_LED_R1,
         MC13783_LED_G1,
         MC13783_LED_B1,
         MC13783_LED_R2,
         MC13783_LED_G2,
         MC13783_LED_B2,
         MC13783_LED_R3,
         MC13783_LED_G3,
         MC13783_LED_B3,
         /* MC13892 LED IDs */
         MC13892_LED_MD,
         MC13892_LED_AD,
         MC13892_LED_KP,
         MC13892_LED_R,
         MC13892_LED_G,
         MC13892_LED_B,
         /* MC34708 LED IDs */
         MC34708_LED_R,
         MC34708_LED_G,
}

Keypad LED enum identifier is 15, but documentation states
that it is 2. The code seems to expect the former:

off = led->id - MC13892_LED_MD; //15 - 13 = 2
reg = off / 2; // 2 / 2 = 1
shift = 3 + (off - reg * 2) * 12; // 3 + (2 - 1*2) = 3

It should write value << 3 to the register 52.

According to the documentation [0] LEDKP0, LEDKP1 and LEDKP2
are driven by bits 9,10 and 11 respectively. The calculations
don't seem to be in line with that. Could you point what I
am missing?

[0] http://www.nxp.com/files/analog/doc/data_sheet/MC13892.pdf

-- 
Best regards,
Jacek Anaszewski

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

* Re: [PATCH] leds: leds-mc13783: Fix MC13892 keypad led access
  2016-10-10 12:14   ` Jacek Anaszewski
@ 2016-10-10 12:22     ` Alexander Shiyan
  2016-10-10 13:06       ` Jacek Anaszewski
  2016-10-10 12:52     ` Alexander Kurz
  1 sibling, 1 reply; 12+ messages in thread
From: Alexander Shiyan @ 2016-10-10 12:22 UTC (permalink / raw)
  To: Jacek Anaszewski; +Cc: Bryan Wu, linux-leds, Alexander Kurz, Richard Purdie

>Понедельник, 10 октября 2016, 15:14 +03:00 от Jacek Anaszewski <j.anaszewski@samsung.com>:
>
>Hi Alexander,
>
>Thanks for the patch.
>
>On 10/09/2016 03:37 PM, Alexander Kurz wrote:
>> Fix the register access shift argument calculation introduced with
>> commit a59ce6584d56 ("leds: leds-mc13783: Add MC34708 LED support")
>> and re-enable access to the "keypad" led for MC13892 MFC devices.
>>
>> Signed-off-by: Alexander Kurz < akurz@blala.de >
>> ---
>>  drivers/leds/leds-mc13783.c | 5 +++--
>>  1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c
>> index a2e4c17..2421cf10 100644
>> --- a/drivers/leds/leds-mc13783.c
>> +++ b/drivers/leds/leds-mc13783.c
>> @@ -84,8 +84,9 @@ static int mc13xxx_led_set(struct led_classdev *led_cdev,
>>  case MC13892_LED_MD:
>>  case MC13892_LED_AD:
>>  case MC13892_LED_KP:
>> -reg = (led->id - MC13892_LED_MD) / 2;
>> -shift = 3 + (led->id - MC13892_LED_MD) * 12;
>> +off = led->id - MC13892_LED_MD;
>> +reg = off / 2;
>> +shift = 3 + (off - reg * 2) * 12;
>>  break;
>>  case MC13892_LED_R:
>>  case MC13892_LED_G:
>>
>
>While trying to analyze these calculations I noticed a discrepancy
>between DT documentation and the enum in the header file.
>
>Documentation/devicetree/bindings/mfd/mc13xxx.txt:
>
>MC13892 LED IDs:
>     0  : Main display
>     1  : AUX display
>     2  : Keypad
>     3  : Red
>     4  : Green
>     5  : Blue
>
>include/linux/mfd/mc13xxx.h:
>
>enum {
>         /* MC13783 LED IDs */
>         MC13783_LED_MD,
>         MC13783_LED_AD,
>         MC13783_LED_KP,
>         MC13783_LED_R1,
>         MC13783_LED_G1,
>         MC13783_LED_B1,
>         MC13783_LED_R2,
>         MC13783_LED_G2,
>         MC13783_LED_B2,
>         MC13783_LED_R3,
>         MC13783_LED_G3,
>         MC13783_LED_B3,
>         /* MC13892 LED IDs */
>         MC13892_LED_MD,
>         MC13892_LED_AD,
>         MC13892_LED_KP,
>         MC13892_LED_R,
>         MC13892_LED_G,
>         MC13892_LED_B,
>         /* MC34708 LED IDs */
>         MC34708_LED_R,
>         MC34708_LED_G,
>}
>
>Keypad LED enum identifier is 15, but documentation states
>that it is 2. The code seems to expect the former:

The driver uses calculation:

if (of_property_read_u32(child, "reg", &tmp))
  continue;
pdata->led[i].id = leds->devtype->led_min + tmp;

Where led_min = MC13892_LED_MD for MC13892.

---


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

* Re: [PATCH] leds: leds-mc13783: Fix MC13892 keypad led access
  2016-10-10 12:14   ` Jacek Anaszewski
  2016-10-10 12:22     ` Alexander Shiyan
@ 2016-10-10 12:52     ` Alexander Kurz
  2016-10-10 13:12       ` Jacek Anaszewski
  1 sibling, 1 reply; 12+ messages in thread
From: Alexander Kurz @ 2016-10-10 12:52 UTC (permalink / raw)
  To: Jacek Anaszewski; +Cc: Richard Purdie, Alexander Shiyan, Bryan Wu, linux-leds

Hi Jacek,

On Mon, 10 Oct 2016, Jacek Anaszewski wrote:

> Hi Alexander,
> 
> Thanks for the patch.
> 
> On 10/09/2016 03:37 PM, Alexander Kurz wrote:
> > Fix the register access shift argument calculation introduced with
> > commit a59ce6584d56 ("leds: leds-mc13783: Add MC34708 LED support")
> > and re-enable access to the "keypad" led for MC13892 MFC devices.
> > 
> > Signed-off-by: Alexander Kurz <akurz@blala.de>
> > ---
> >  drivers/leds/leds-mc13783.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c
> > index a2e4c17..2421cf10 100644
> > --- a/drivers/leds/leds-mc13783.c
> > +++ b/drivers/leds/leds-mc13783.c
> > @@ -84,8 +84,9 @@ static int mc13xxx_led_set(struct led_classdev *led_cdev,
> >  	case MC13892_LED_MD:
> >  	case MC13892_LED_AD:
> >  	case MC13892_LED_KP:
> > -		reg = (led->id - MC13892_LED_MD) / 2;
> > -		shift = 3 + (led->id - MC13892_LED_MD) * 12;
> > +		off = led->id - MC13892_LED_MD;
> > +		reg = off / 2;
> > +		shift = 3 + (off - reg * 2) * 12;
> >  		break;
> >  	case MC13892_LED_R:
> >  	case MC13892_LED_G:
> > 
> 
> While trying to analyze these calculations I noticed a discrepancy
> between DT documentation and the enum in the header file.
> 
> Documentation/devicetree/bindings/mfd/mc13xxx.txt:
> 
> MC13892 LED IDs:
>     0  : Main display
>     1  : AUX display
>     2  : Keypad
>     3  : Red
>     4  : Green
>     5  : Blue
> 
> include/linux/mfd/mc13xxx.h:
> 
> enum {
>         /* MC13783 LED IDs */
>         MC13783_LED_MD,
>         MC13783_LED_AD,
>         MC13783_LED_KP,
>         MC13783_LED_R1,
>         MC13783_LED_G1,
>         MC13783_LED_B1,
>         MC13783_LED_R2,
>         MC13783_LED_G2,
>         MC13783_LED_B2,
>         MC13783_LED_R3,
>         MC13783_LED_G3,
>         MC13783_LED_B3,
>         /* MC13892 LED IDs */
>         MC13892_LED_MD,
>         MC13892_LED_AD,
>         MC13892_LED_KP,
>         MC13892_LED_R,
>         MC13892_LED_G,
>         MC13892_LED_B,
>         /* MC34708 LED IDs */
>         MC34708_LED_R,
>         MC34708_LED_G,
> }
> 
> Keypad LED enum identifier is 15, but documentation states
> that it is 2. The code seems to expect the former:
> 
> off = led->id - MC13892_LED_MD; //15 - 13 = 2
> reg = off / 2; // 2 / 2 = 1
> shift = 3 + (off - reg * 2) * 12; // 3 + (2 - 1*2) = 3
> 
> It should write value << 3 to the register 52.
> 
> According to the documentation [0] LEDKP0, LEDKP1 and LEDKP2
> are driven by bits 9,10 and 11 respectively. The calculations
> don't seem to be in line with that. Could you point what I
> am missing?
> 
> [0] http://www.nxp.com/files/analog/doc/data_sheet/MC13892.pdf

The numbering mentioned in the DT documentation is used as offset
for the device specific struct mc13xxx_led_devtype.led_min
>                if (of_property_read_u32(child, "reg", &tmp))
>                        continue;
>                pdata->led[i].id = leds->devtype->led_min + tmp;
e.g. MC13892_LED_KP = MC13892_LED_MD + 2

Hope this clarifies your question,
regards, Alexander

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

* Re: [PATCH] leds: leds-mc13783: Fix MC13892 keypad led access
  2016-10-10 12:22     ` Alexander Shiyan
@ 2016-10-10 13:06       ` Jacek Anaszewski
  0 siblings, 0 replies; 12+ messages in thread
From: Jacek Anaszewski @ 2016-10-10 13:06 UTC (permalink / raw)
  To: Alexander Shiyan; +Cc: Bryan Wu, linux-leds, Alexander Kurz, Richard Purdie

On 10/10/2016 02:22 PM, Alexander Shiyan wrote:
>> Понедельник, 10 октября 2016, 15:14 +03:00 от Jacek Anaszewski <j.anaszewski@samsung.com>:
>>
>> Hi Alexander,
>>
>> Thanks for the patch.
>>
>> On 10/09/2016 03:37 PM, Alexander Kurz wrote:
>>> Fix the register access shift argument calculation introduced with
>>> commit a59ce6584d56 ("leds: leds-mc13783: Add MC34708 LED support")
>>> and re-enable access to the "keypad" led for MC13892 MFC devices.
>>>
>>> Signed-off-by: Alexander Kurz < akurz@blala.de >
>>> ---
>>>  drivers/leds/leds-mc13783.c | 5 +++--
>>>  1 file changed, 3 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c
>>> index a2e4c17..2421cf10 100644
>>> --- a/drivers/leds/leds-mc13783.c
>>> +++ b/drivers/leds/leds-mc13783.c
>>> @@ -84,8 +84,9 @@ static int mc13xxx_led_set(struct led_classdev *led_cdev,
>>>  case MC13892_LED_MD:
>>>  case MC13892_LED_AD:
>>>  case MC13892_LED_KP:
>>> -reg = (led->id - MC13892_LED_MD) / 2;
>>> -shift = 3 + (led->id - MC13892_LED_MD) * 12;
>>> +off = led->id - MC13892_LED_MD;
>>> +reg = off / 2;
>>> +shift = 3 + (off - reg * 2) * 12;
>>>  break;
>>>  case MC13892_LED_R:
>>>  case MC13892_LED_G:
>>>
>>
>> While trying to analyze these calculations I noticed a discrepancy
>> between DT documentation and the enum in the header file.
>>
>> Documentation/devicetree/bindings/mfd/mc13xxx.txt:
>>
>> MC13892 LED IDs:
>>      0  : Main display
>>      1  : AUX display
>>      2  : Keypad
>>      3  : Red
>>      4  : Green
>>      5  : Blue
>>
>> include/linux/mfd/mc13xxx.h:
>>
>> enum {
>>          /* MC13783 LED IDs */
>>          MC13783_LED_MD,
>>          MC13783_LED_AD,
>>          MC13783_LED_KP,
>>          MC13783_LED_R1,
>>          MC13783_LED_G1,
>>          MC13783_LED_B1,
>>          MC13783_LED_R2,
>>          MC13783_LED_G2,
>>          MC13783_LED_B2,
>>          MC13783_LED_R3,
>>          MC13783_LED_G3,
>>          MC13783_LED_B3,
>>          /* MC13892 LED IDs */
>>          MC13892_LED_MD,
>>          MC13892_LED_AD,
>>          MC13892_LED_KP,
>>          MC13892_LED_R,
>>          MC13892_LED_G,
>>          MC13892_LED_B,
>>          /* MC34708 LED IDs */
>>          MC34708_LED_R,
>>          MC34708_LED_G,
>> }
>>
>> Keypad LED enum identifier is 15, but documentation states
>> that it is 2. The code seems to expect the former:
>
> The driver uses calculation:
>
> if (of_property_read_u32(child, "reg", &tmp))
>   continue;
> pdata->led[i].id = leds->devtype->led_min + tmp;
>
> Where led_min = MC13892_LED_MD for MC13892.

Right, thanks for spotting this.

-- 
Best regards,
Jacek Anaszewski

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

* Re: [PATCH] leds: leds-mc13783: Fix MC13892 keypad led access
  2016-10-10 12:52     ` Alexander Kurz
@ 2016-10-10 13:12       ` Jacek Anaszewski
  2016-10-10 13:24         ` Alexander Kurz
  0 siblings, 1 reply; 12+ messages in thread
From: Jacek Anaszewski @ 2016-10-10 13:12 UTC (permalink / raw)
  To: Alexander Kurz; +Cc: Richard Purdie, Alexander Shiyan, Bryan Wu, linux-leds

Hi Alexander,

On 10/10/2016 02:52 PM, Alexander Kurz wrote:
> Hi Jacek,
>
> On Mon, 10 Oct 2016, Jacek Anaszewski wrote:
>
>> Hi Alexander,
>>
>> Thanks for the patch.
>>
>> On 10/09/2016 03:37 PM, Alexander Kurz wrote:
>>> Fix the register access shift argument calculation introduced with
>>> commit a59ce6584d56 ("leds: leds-mc13783: Add MC34708 LED support")
>>> and re-enable access to the "keypad" led for MC13892 MFC devices.
>>>
>>> Signed-off-by: Alexander Kurz <akurz@blala.de>
>>> ---
>>>  drivers/leds/leds-mc13783.c | 5 +++--
>>>  1 file changed, 3 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c
>>> index a2e4c17..2421cf10 100644
>>> --- a/drivers/leds/leds-mc13783.c
>>> +++ b/drivers/leds/leds-mc13783.c
>>> @@ -84,8 +84,9 @@ static int mc13xxx_led_set(struct led_classdev *led_cdev,
>>>  	case MC13892_LED_MD:
>>>  	case MC13892_LED_AD:
>>>  	case MC13892_LED_KP:
>>> -		reg = (led->id - MC13892_LED_MD) / 2;
>>> -		shift = 3 + (led->id - MC13892_LED_MD) * 12;
>>> +		off = led->id - MC13892_LED_MD;
>>> +		reg = off / 2;
>>> +		shift = 3 + (off - reg * 2) * 12;
>>>  		break;
>>>  	case MC13892_LED_R:
>>>  	case MC13892_LED_G:
>>>
>>
>> While trying to analyze these calculations I noticed a discrepancy
>> between DT documentation and the enum in the header file.
>>
>> Documentation/devicetree/bindings/mfd/mc13xxx.txt:
>>
>> MC13892 LED IDs:
>>     0  : Main display
>>     1  : AUX display
>>     2  : Keypad
>>     3  : Red
>>     4  : Green
>>     5  : Blue
>>
>> include/linux/mfd/mc13xxx.h:
>>
>> enum {
>>         /* MC13783 LED IDs */
>>         MC13783_LED_MD,
>>         MC13783_LED_AD,
>>         MC13783_LED_KP,
>>         MC13783_LED_R1,
>>         MC13783_LED_G1,
>>         MC13783_LED_B1,
>>         MC13783_LED_R2,
>>         MC13783_LED_G2,
>>         MC13783_LED_B2,
>>         MC13783_LED_R3,
>>         MC13783_LED_G3,
>>         MC13783_LED_B3,
>>         /* MC13892 LED IDs */
>>         MC13892_LED_MD,
>>         MC13892_LED_AD,
>>         MC13892_LED_KP,
>>         MC13892_LED_R,
>>         MC13892_LED_G,
>>         MC13892_LED_B,
>>         /* MC34708 LED IDs */
>>         MC34708_LED_R,
>>         MC34708_LED_G,
>> }
>>
>> Keypad LED enum identifier is 15, but documentation states
>> that it is 2. The code seems to expect the former:
>>
>> off = led->id - MC13892_LED_MD; //15 - 13 = 2
>> reg = off / 2; // 2 / 2 = 1
>> shift = 3 + (off - reg * 2) * 12; // 3 + (2 - 1*2) = 3
>>
>> It should write value << 3 to the register 52.
>>
>> According to the documentation [0] LEDKP0, LEDKP1 and LEDKP2
>> are driven by bits 9,10 and 11 respectively. The calculations
>> don't seem to be in line with that. Could you point what I
>> am missing?
>>
>> [0] http://www.nxp.com/files/analog/doc/data_sheet/MC13892.pdf
>
> The numbering mentioned in the DT documentation is used as offset
> for the device specific struct mc13xxx_led_devtype.led_min
>>                if (of_property_read_u32(child, "reg", &tmp))
>>                        continue;
>>                pdata->led[i].id = leds->devtype->led_min + tmp;
> e.g. MC13892_LED_KP = MC13892_LED_MD + 2
>
> Hope this clarifies your question,

Thanks but not entirely - what with the second part of question related
to the register layout?

-- 
Best regards,
Jacek Anaszewski

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

* Re: [PATCH] leds: leds-mc13783: Fix MC13892 keypad led access
  2016-10-10 13:12       ` Jacek Anaszewski
@ 2016-10-10 13:24         ` Alexander Kurz
  2016-10-10 14:32           ` Jacek Anaszewski
  0 siblings, 1 reply; 12+ messages in thread
From: Alexander Kurz @ 2016-10-10 13:24 UTC (permalink / raw)
  To: Jacek Anaszewski; +Cc: Richard Purdie, Alexander Shiyan, Bryan Wu, linux-leds



On Mon, 10 Oct 2016, Jacek Anaszewski wrote:

> Hi Alexander,
> > > It should write value << 3 to the register 52.
> > > 
> > > According to the documentation [0] LEDKP0, LEDKP1 and LEDKP2
> > > are driven by bits 9,10 and 11 respectively. The calculations
> > > don't seem to be in line with that. Could you point what I
> > > am missing?
LEDKP0, LEDKP1 and LEDKP2 controlles the led current setting, but ...

> > > 
> > > [0] http://www.nxp.com/files/analog/doc/data_sheet/MC13892.pdf
> > 
> > The numbering mentioned in the DT documentation is used as offset
> > for the device specific struct mc13xxx_led_devtype.led_min
> > >                if (of_property_read_u32(child, "reg", &tmp))
> > >                        continue;
> > >                pdata->led[i].id = leds->devtype->led_min + tmp;
> > e.g. MC13892_LED_KP = MC13892_LED_MD + 2
> > 
> > Hope this clarifies your question,
> 
> Thanks but not entirely - what with the second part of question related
> to the register layout?
The LED brightness is controlled via the duty cycle bits allowing
64 brightness values, setting bits/registers like
LED  | reg | bits
-----+-----+------
main | 0   | 3..8
aux  | 0   | 15..20
kp   | 1   | 3..8
red  | 2   | 3..8
green| 2   | 15..20
blue | 3   | 3..8

hope to got your question right,
 cheers, Alexander
> 
> -- 
> Best regards,
> Jacek Anaszewski
> 

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

* Re: [PATCH] leds: leds-mc13783: Fix MC13892 keypad led access
  2016-10-10 13:24         ` Alexander Kurz
@ 2016-10-10 14:32           ` Jacek Anaszewski
  2016-10-10 14:52             ` Alexander Kurz
  0 siblings, 1 reply; 12+ messages in thread
From: Jacek Anaszewski @ 2016-10-10 14:32 UTC (permalink / raw)
  To: Alexander Kurz; +Cc: Richard Purdie, Alexander Shiyan, Bryan Wu, linux-leds

On 10/10/2016 03:24 PM, Alexander Kurz wrote:
>
>
> On Mon, 10 Oct 2016, Jacek Anaszewski wrote:
>
>> Hi Alexander,
>>>> It should write value << 3 to the register 52.
>>>>
>>>> According to the documentation [0] LEDKP0, LEDKP1 and LEDKP2
>>>> are driven by bits 9,10 and 11 respectively. The calculations
>>>> don't seem to be in line with that. Could you point what I
>>>> am missing?
> LEDKP0, LEDKP1 and LEDKP2 controlles the led current setting, but ...
>
>>>>
>>>> [0] http://www.nxp.com/files/analog/doc/data_sheet/MC13892.pdf
>>>
>>> The numbering mentioned in the DT documentation is used as offset
>>> for the device specific struct mc13xxx_led_devtype.led_min
>>>>                if (of_property_read_u32(child, "reg", &tmp))
>>>>                        continue;
>>>>                pdata->led[i].id = leds->devtype->led_min + tmp;
>>> e.g. MC13892_LED_KP = MC13892_LED_MD + 2
>>>
>>> Hope this clarifies your question,
>>
>> Thanks but not entirely - what with the second part of question related
>> to the register layout?
> The LED brightness is controlled via the duty cycle bits allowing
> 64 brightness values, setting bits/registers like
> LED  | reg | bits
> -----+-----+------
> main | 0   | 3..8
> aux  | 0   | 15..20
> kp   | 1   | 3..8
> red  | 2   | 3..8
> green| 2   | 15..20
> blue | 3   | 3..8

So it doesn't seem to reflect what is shown in the Table 164.
on the site 148 of the document I mentioned in the previous
message. Could you please give a reference to the documentation
you're using?

-- 
Best regards,
Jacek Anaszewski

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

* Re: [PATCH] leds: leds-mc13783: Fix MC13892 keypad led access
  2016-10-10 14:32           ` Jacek Anaszewski
@ 2016-10-10 14:52             ` Alexander Kurz
  2016-10-11  8:18               ` Jacek Anaszewski
  0 siblings, 1 reply; 12+ messages in thread
From: Alexander Kurz @ 2016-10-10 14:52 UTC (permalink / raw)
  To: Jacek Anaszewski; +Cc: Richard Purdie, Alexander Shiyan, Bryan Wu, linux-leds



On Mon, 10 Oct 2016, Jacek Anaszewski wrote:

> On 10/10/2016 03:24 PM, Alexander Kurz wrote:
> > 
> > 
> > On Mon, 10 Oct 2016, Jacek Anaszewski wrote:
> > 
> > > Hi Alexander,
> > > > > It should write value << 3 to the register 52.
> > > > > 
> > > > > According to the documentation [0] LEDKP0, LEDKP1 and LEDKP2
> > > > > are driven by bits 9,10 and 11 respectively. The calculations
> > > > > don't seem to be in line with that. Could you point what I
> > > > > am missing?
> > LEDKP0, LEDKP1 and LEDKP2 controlles the led current setting, but ...
> > 
> > > > > 
> > > > > [0] http://www.nxp.com/files/analog/doc/data_sheet/MC13892.pdf
> > > > 
> > > > The numbering mentioned in the DT documentation is used as offset
> > > > for the device specific struct mc13xxx_led_devtype.led_min
> > > > >                if (of_property_read_u32(child, "reg", &tmp))
> > > > >                        continue;
> > > > >                pdata->led[i].id = leds->devtype->led_min + tmp;
> > > > e.g. MC13892_LED_KP = MC13892_LED_MD + 2
> > > > 
> > > > Hope this clarifies your question,
> > > 
> > > Thanks but not entirely - what with the second part of question related
> > > to the register layout?
> > The LED brightness is controlled via the duty cycle bits allowing
> > 64 brightness values, setting bits/registers like
> > LED  | reg | bits
> > -----+-----+------
> > main | 0   | 3..8
> > aux  | 0   | 15..20
> > kp   | 1   | 3..8
> > red  | 2   | 3..8
> > green| 2   | 15..20
> > blue | 3   | 3..8

So, I have probably introduced some confusion by 
using "LED Control #reg" as "reg" from Table 163-166.

> So it doesn't seem to reflect what is shown in the Table 164.
> on the site 148 of the document I mentioned in the previous
> message. Could you please give a reference to the documentation
> you're using?

Exactly the same datasheet.
Again, brightness controlling bits with verbatim Register numbering

LED  | Register | LED Control | bits
-----+----------+-------------+-----
main | 51       | 0           | 3..8
aux  | 51       | 0           | 15..20
kp   | 52       | 1           | 3..8
red  | 53       | 2           | 3..8
green| 53       | 2           | 15..20
blue | 54       | 3           | 3..8


Cheers, Alexander

> 
> -- 
> Best regards,
> Jacek Anaszewski
> 

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

* Re: [PATCH] leds: leds-mc13783: Fix MC13892 keypad led access
  2016-10-10 14:52             ` Alexander Kurz
@ 2016-10-11  8:18               ` Jacek Anaszewski
  0 siblings, 0 replies; 12+ messages in thread
From: Jacek Anaszewski @ 2016-10-11  8:18 UTC (permalink / raw)
  To: Alexander Kurz; +Cc: Richard Purdie, Alexander Shiyan, Bryan Wu, linux-leds

On 10/10/2016 04:52 PM, Alexander Kurz wrote:
>
>
> On Mon, 10 Oct 2016, Jacek Anaszewski wrote:
>
>> On 10/10/2016 03:24 PM, Alexander Kurz wrote:
>>>
>>>
>>> On Mon, 10 Oct 2016, Jacek Anaszewski wrote:
>>>
>>>> Hi Alexander,
>>>>>> It should write value << 3 to the register 52.
>>>>>>
>>>>>> According to the documentation [0] LEDKP0, LEDKP1 and LEDKP2
>>>>>> are driven by bits 9,10 and 11 respectively. The calculations
>>>>>> don't seem to be in line with that. Could you point what I
>>>>>> am missing?
>>> LEDKP0, LEDKP1 and LEDKP2 controlles the led current setting, but ...
>>>
>>>>>>
>>>>>> [0] http://www.nxp.com/files/analog/doc/data_sheet/MC13892.pdf
>>>>>
>>>>> The numbering mentioned in the DT documentation is used as offset
>>>>> for the device specific struct mc13xxx_led_devtype.led_min
>>>>>>                if (of_property_read_u32(child, "reg", &tmp))
>>>>>>                        continue;
>>>>>>                pdata->led[i].id = leds->devtype->led_min + tmp;
>>>>> e.g. MC13892_LED_KP = MC13892_LED_MD + 2
>>>>>
>>>>> Hope this clarifies your question,
>>>>
>>>> Thanks but not entirely - what with the second part of question related
>>>> to the register layout?
>>> The LED brightness is controlled via the duty cycle bits allowing
>>> 64 brightness values, setting bits/registers like
>>> LED  | reg | bits
>>> -----+-----+------
>>> main | 0   | 3..8
>>> aux  | 0   | 15..20
>>> kp   | 1   | 3..8
>>> red  | 2   | 3..8
>>> green| 2   | 15..20
>>> blue | 3   | 3..8
>
> So, I have probably introduced some confusion by
> using "LED Control #reg" as "reg" from Table 163-166.
>
>> So it doesn't seem to reflect what is shown in the Table 164.
>> on the site 148 of the document I mentioned in the previous
>> message. Could you please give a reference to the documentation
>> you're using?
>
> Exactly the same datasheet.
> Again, brightness controlling bits with verbatim Register numbering
>
> LED  | Register | LED Control | bits
> -----+----------+-------------+-----
> main | 51       | 0           | 3..8
> aux  | 51       | 0           | 15..20
> kp   | 52       | 1           | 3..8
> red  | 53       | 2           | 3..8
> green| 53       | 2           | 15..20
> blue | 54       | 3           | 3..8

OK, now everything is clear, thanks.
I've applied the patch to the for-4.10 branch of linux-leds.git.

-- 
Best regards,
Jacek Anaszewski

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

end of thread, other threads:[~2016-10-11  8:18 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CGME20161009134104eucas1p17d4028424741a2b6c758b268e50e6e12@eucas1p1.samsung.com>
2016-10-09 13:37 ` [PATCH] leds: leds-mc13783: Fix MC13892 keypad led access Alexander Kurz
2016-10-09 17:41   ` Alexander Shiyan
2016-10-09 19:15     ` Alexander Kurz
2016-10-10 12:14   ` Jacek Anaszewski
2016-10-10 12:22     ` Alexander Shiyan
2016-10-10 13:06       ` Jacek Anaszewski
2016-10-10 12:52     ` Alexander Kurz
2016-10-10 13:12       ` Jacek Anaszewski
2016-10-10 13:24         ` Alexander Kurz
2016-10-10 14:32           ` Jacek Anaszewski
2016-10-10 14:52             ` Alexander Kurz
2016-10-11  8:18               ` Jacek Anaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox