linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Change PWM-controlled LED pin active mode and algorithm
@ 2023-01-13  8:31 Nylon Chen
  2023-01-13  8:31 ` [PATCH 1/2] riscv: dts: sifive unmatched: Remove PWM controlled LED's active-low properties Nylon Chen
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Nylon Chen @ 2023-01-13  8:31 UTC (permalink / raw)
  To: paul.walmsley, palmer, linux-kernel, linux-riscv
  Cc: nylon7717, zong.li, greentime.hu, vincent.chen, Nylon Chen

According to the circuit diagram of User LEDs - RGB described in the
manual hifive-unmatched-schematics-v3.pdf[0].
The behavior of PWM is acitve-high.

According to the descriptionof PWM for pwmcmp in SiFive FU740-C000
Manual[1].
The pwm algorithm is (PW) pulse active time  = (D) duty * (T) period[2].
The `frac` variable is pulse "inactive" time so we need to invert it.

So this patchset removes active-low in DTS and adds reverse logic to
the driver.

[0]:https://sifive-china.oss-cn-zhangjiakou.aliyuncs.com/HiFIve%20Unmatched/hifive-unmatched-schematics-v3.pdf
[1]:https://sifive-china.oss-cn-zhangjiakou.aliyuncs.com/HiFIve%20Unmatched/fu740-c000-manual-v1p2.pdf
[2]:https://en.wikipedia.org/wiki/Duty_cycle

Nylon Chen (2):
  riscv: dts: sifive unmatched: Remove PWM controlled LED's active-low
    properties
  pwm: sifive: change the PWM controlled LED algorithm

 arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts | 4 ----
 drivers/pwm/pwm-sifive.c                            | 1 +
 2 files changed, 1 insertion(+), 4 deletions(-)

-- 
2.36.1


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

* [PATCH 1/2] riscv: dts: sifive unmatched: Remove PWM controlled LED's active-low properties
  2023-01-13  8:31 [PATCH 0/2] Change PWM-controlled LED pin active mode and algorithm Nylon Chen
@ 2023-01-13  8:31 ` Nylon Chen
  2023-01-17 13:57   ` Conor Dooley
  2023-01-13  8:31 ` [PATCH 2/2] pwm: sifive: change the PWM controlled LED algorithm Nylon Chen
  2023-01-13 18:32 ` [PATCH 0/2] Change PWM-controlled LED pin active mode and algorithm Conor Dooley
  2 siblings, 1 reply; 14+ messages in thread
From: Nylon Chen @ 2023-01-13  8:31 UTC (permalink / raw)
  To: paul.walmsley, palmer, linux-kernel, linux-riscv
  Cc: nylon7717, zong.li, greentime.hu, vincent.chen, Nylon Chen

This removes the active-low properties of the PWM-controlled LEDs in
the HiFive Unmatched device tree.

Signed-off-by: Nylon Chen <nylon.chen@sifive.com>
Reviewed-by: Vincent Chen <vincent.chen@sifive.com>
---
 arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts b/arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts
index 07387f9c135c..11f08a545ee6 100644
--- a/arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts
+++ b/arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts
@@ -52,7 +52,6 @@ led-controller-1 {
 
 		led-d12 {
 			pwms = <&pwm0 0 7812500 PWM_POLARITY_INVERTED>;
-			active-low;
 			color = <LED_COLOR_ID_GREEN>;
 			max-brightness = <255>;
 			label = "d12";
@@ -69,19 +68,16 @@ multi-led {
 
 			led-red {
 				pwms = <&pwm0 2 7812500 PWM_POLARITY_INVERTED>;
-				active-low;
 				color = <LED_COLOR_ID_RED>;
 			};
 
 			led-green {
 				pwms = <&pwm0 1 7812500 PWM_POLARITY_INVERTED>;
-				active-low;
 				color = <LED_COLOR_ID_GREEN>;
 			};
 
 			led-blue {
 				pwms = <&pwm0 3 7812500 PWM_POLARITY_INVERTED>;
-				active-low;
 				color = <LED_COLOR_ID_BLUE>;
 			};
 		};
-- 
2.36.1


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

* [PATCH 2/2] pwm: sifive: change the PWM controlled LED algorithm
  2023-01-13  8:31 [PATCH 0/2] Change PWM-controlled LED pin active mode and algorithm Nylon Chen
  2023-01-13  8:31 ` [PATCH 1/2] riscv: dts: sifive unmatched: Remove PWM controlled LED's active-low properties Nylon Chen
@ 2023-01-13  8:31 ` Nylon Chen
  2023-01-13 18:32 ` [PATCH 0/2] Change PWM-controlled LED pin active mode and algorithm Conor Dooley
  2 siblings, 0 replies; 14+ messages in thread
From: Nylon Chen @ 2023-01-13  8:31 UTC (permalink / raw)
  To: paul.walmsley, palmer, linux-kernel, linux-riscv
  Cc: nylon7717, zong.li, greentime.hu, vincent.chen, Nylon Chen

The `frac` variable represents the pulse inactive time, and the result of
this algorithm is the pulse active time. Therefore, we must reverse the
result.

Signed-off-by: Nylon Chen <nylon.chen@sifive.com>
Reviewed-by: Vincent Chen <vincent.chen@sifive.com>
---
 drivers/pwm/pwm-sifive.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c
index 62b6acc6373d..a5eda165d071 100644
--- a/drivers/pwm/pwm-sifive.c
+++ b/drivers/pwm/pwm-sifive.c
@@ -158,6 +158,7 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm,
 	frac = DIV64_U64_ROUND_CLOSEST(num, state->period);
 	/* The hardware cannot generate a 100% duty cycle */
 	frac = min(frac, (1U << PWM_SIFIVE_CMPWIDTH) - 1);
+	frac = (1U << PWM_SIFIVE_CMPWIDTH) - 1 - frac;
 
 	mutex_lock(&ddata->lock);
 	if (state->period != ddata->approx_period) {
-- 
2.36.1


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

* Re: [PATCH 0/2] Change PWM-controlled LED pin active mode and algorithm
  2023-01-13  8:31 [PATCH 0/2] Change PWM-controlled LED pin active mode and algorithm Nylon Chen
  2023-01-13  8:31 ` [PATCH 1/2] riscv: dts: sifive unmatched: Remove PWM controlled LED's active-low properties Nylon Chen
  2023-01-13  8:31 ` [PATCH 2/2] pwm: sifive: change the PWM controlled LED algorithm Nylon Chen
@ 2023-01-13 18:32 ` Conor Dooley
  2023-01-13 19:24   ` Jessica Clarke
  2 siblings, 1 reply; 14+ messages in thread
From: Conor Dooley @ 2023-01-13 18:32 UTC (permalink / raw)
  To: Nylon Chen
  Cc: paul.walmsley, palmer, linux-kernel, linux-riscv, nylon7717,
	zong.li, greentime.hu, vincent.chen, Thierry Reding,
	Uwe Kleine-König, linux-pwm

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

+CC Uwe, Thierry, linux-pwm

Hey Nylon,

Please run scripts/get_maintainer.pl before sending patches, you missed
both me & the PWM maintainers unfortunately!
AFAIK, the PWM maintainers use patchwork, so you will probably have to
resend this patchset so that it is on their radar.
I've marked the series as "Changes Requested" on the RISC-V one.

On Fri, Jan 13, 2023 at 04:31:13PM +0800, Nylon Chen wrote:

> According to the circuit diagram of User LEDs - RGB described in the
> manual hifive-unmatched-schematics-v3.pdf[0].
> The behavior of PWM is acitve-high.
> 
> According to the descriptionof PWM for pwmcmp in SiFive FU740-C000
> Manual[1].
> The pwm algorithm is (PW) pulse active time  = (D) duty * (T) period[2].
> The `frac` variable is pulse "inactive" time so we need to invert it.
> 
> So this patchset removes active-low in DTS and adds reverse logic to
> the driver.
> 
> [0]:https://sifive-china.oss-cn-zhangjiakou.aliyuncs.com/HiFIve%20Unmatched/hifive-unmatched-schematics-v3.pdf
> [1]:https://sifive-china.oss-cn-zhangjiakou.aliyuncs.com/HiFIve%20Unmatched/fu740-c000-manual-v1p2.pdf
> [2]:https://en.wikipedia.org/wiki/Duty_cycle

Please delete link 2, convert the other two to standard Link: tags and
put this information in the dts patch. Possibly into the PWM patch too,
depending on what the PWM maintainers think.
This info should be in the commit history IMO and the commit message for
the dts patch says what's obvious from the diff without any explanation
as to why.

I did a bit of looking around on lore, to see if I could figure out
why it was done like this in the first place, and I found:
https://lore.kernel.org/linux-pwm/CAJ2_jOG2M03aLBgUOgGjWH9CUxq2aTG97eSX70=UaSbGCMMF_g@mail.gmail.com/

That doesn't explain the driver, but it does explain the dts being that
way. Perhaps a Fixes tag is also in order? But only if both patches get
one, otherwise backporting would lead to breakage.

The min() construct appears to have been there since the RFC driver was
first posted.

Thanks,
Conor.

> 
> Nylon Chen (2):
>   riscv: dts: sifive unmatched: Remove PWM controlled LED's active-low

nit: s/sifive unmatched:/sifive: unmatched:/

>     properties
>   pwm: sifive: change the PWM controlled LED algorithm
> 
>  arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts | 4 ----
>  drivers/pwm/pwm-sifive.c                            | 1 +
>  2 files changed, 1 insertion(+), 4 deletions(-)
> 
> -- 
> 2.36.1
> 
> 
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH 0/2] Change PWM-controlled LED pin active mode and algorithm
  2023-01-13 18:32 ` [PATCH 0/2] Change PWM-controlled LED pin active mode and algorithm Conor Dooley
@ 2023-01-13 19:24   ` Jessica Clarke
  2023-01-14 14:00     ` Conor Dooley
                       ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Jessica Clarke @ 2023-01-13 19:24 UTC (permalink / raw)
  To: Conor Dooley
  Cc: Nylon Chen, Paul Walmsley, Palmer Dabbelt,
	Linux Kernel Mailing List, linux-riscv, nylon7717, zong.li,
	greentime.hu, vincent.chen, Thierry Reding,
	Uwe Kleine-König, linux-pwm

On 13 Jan 2023, at 18:32, Conor Dooley <conor@kernel.org> wrote:
> 
> +CC Uwe, Thierry, linux-pwm
> 
> Hey Nylon,
> 
> Please run scripts/get_maintainer.pl before sending patches, you missed
> both me & the PWM maintainers unfortunately!
> AFAIK, the PWM maintainers use patchwork, so you will probably have to
> resend this patchset so that it is on their radar.
> I've marked the series as "Changes Requested" on the RISC-V one.
> 
> On Fri, Jan 13, 2023 at 04:31:13PM +0800, Nylon Chen wrote:
> 
>> According to the circuit diagram of User LEDs - RGB described in the
>> manual hifive-unmatched-schematics-v3.pdf[0].
>> The behavior of PWM is acitve-high.
>> 
>> According to the descriptionof PWM for pwmcmp in SiFive FU740-C000
>> Manual[1].
>> The pwm algorithm is (PW) pulse active time  = (D) duty * (T) period[2].
>> The `frac` variable is pulse "inactive" time so we need to invert it.
>> 
>> So this patchset removes active-low in DTS and adds reverse logic to
>> the driver.
>> 
>> [0]:https://sifive-china.oss-cn-zhangjiakou.aliyuncs.com/HiFIve%20Unmatched/hifive-unmatched-schematics-v3.pdf
>> [1]:https://sifive-china.oss-cn-zhangjiakou.aliyuncs.com/HiFIve%20Unmatched/fu740-c000-manual-v1p2.pdf
>> [2]:https://en.wikipedia.org/wiki/Duty_cycle
> 
> Please delete link 2, convert the other two to standard Link: tags and
> put this information in the dts patch. Possibly into the PWM patch too,
> depending on what the PWM maintainers think.
> This info should be in the commit history IMO and the commit message for
> the dts patch says what's obvious from the diff without any explanation
> as to why.
> 
> I did a bit of looking around on lore, to see if I could figure out
> why it was done like this in the first place, and I found:
> https://lore.kernel.org/linux-pwm/CAJ2_jOG2M03aLBgUOgGjWH9CUxq2aTG97eSX70=UaSbGCMMF_g@mail.gmail.com/

That DTS documentation makes no sense to me, why does what the LED is
wired to matter? Whether you have your transistor next to ground or
next to Vdd doesn’t matter, what matters is whether the transistor is
on or off. Maybe what they mean is whether the *PWM's output* / *the
transistor's input* is pulled to ground or Vdd? In which case the
property would indeed not apply here.

Unless that’s written assuming the LED is wired directly to the PWM, in
which case it would make sense, but that’s a very narrow-minded view of
what the PWM output is (directly) driving.

Jess

> That doesn't explain the driver, but it does explain the dts being that
> way. Perhaps a Fixes tag is also in order? But only if both patches get
> one, otherwise backporting would lead to breakage.
> 
> The min() construct appears to have been there since the RFC driver was
> first posted.
> 
> Thanks,
> Conor.
> 
>> 
>> Nylon Chen (2):
>>  riscv: dts: sifive unmatched: Remove PWM controlled LED's active-low
> 
> nit: s/sifive unmatched:/sifive: unmatched:/
> 
>>    properties
>>  pwm: sifive: change the PWM controlled LED algorithm
>> 
>> arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts | 4 ----
>> drivers/pwm/pwm-sifive.c                            | 1 +
>> 2 files changed, 1 insertion(+), 4 deletions(-)
>> 
>> -- 
>> 2.36.1
>> 
>> 
>> _______________________________________________
>> linux-riscv mailing list
>> linux-riscv@lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/linux-riscv
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv


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

* Re: [PATCH 0/2] Change PWM-controlled LED pin active mode and algorithm
  2023-01-13 19:24   ` Jessica Clarke
@ 2023-01-14 14:00     ` Conor Dooley
  2023-01-18  2:32       ` Nylon Chen
  2023-01-17  9:32     ` Nylon Chen
  2023-01-18  2:30     ` Nylon Chen
  2 siblings, 1 reply; 14+ messages in thread
From: Conor Dooley @ 2023-01-14 14:00 UTC (permalink / raw)
  To: Jessica Clarke
  Cc: Nylon Chen, Paul Walmsley, Palmer Dabbelt,
	Linux Kernel Mailing List, linux-riscv, nylon7717, zong.li,
	greentime.hu, vincent.chen, Thierry Reding,
	Uwe Kleine-König, linux-pwm

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

Hi Jess!

On Fri, Jan 13, 2023 at 07:24:56PM +0000, Jessica Clarke wrote:
> On 13 Jan 2023, at 18:32, Conor Dooley <conor@kernel.org> wrote:
> > 

> > Please run scripts/get_maintainer.pl before sending patches, you missed
> > both me & the PWM maintainers unfortunately!
> > AFAIK, the PWM maintainers use patchwork, so you will probably have to
> > resend this patchset so that it is on their radar.
> > I've marked the series as "Changes Requested" on the RISC-V one.
> > 
> > On Fri, Jan 13, 2023 at 04:31:13PM +0800, Nylon Chen wrote:
> > 
> >> According to the circuit diagram of User LEDs - RGB described in the
> >> manual hifive-unmatched-schematics-v3.pdf[0].
> >> The behavior of PWM is acitve-high.
> >> 
> >> According to the descriptionof PWM for pwmcmp in SiFive FU740-C000
> >> Manual[1].
> >> The pwm algorithm is (PW) pulse active time  = (D) duty * (T) period[2].
> >> The `frac` variable is pulse "inactive" time so we need to invert it.
> >> 
> >> So this patchset removes active-low in DTS and adds reverse logic to
> >> the driver.
> >> 
> >> [0]:https://sifive-china.oss-cn-zhangjiakou.aliyuncs.com/HiFIve%20Unmatched/hifive-unmatched-schematics-v3.pdf
> >> [1]:https://sifive-china.oss-cn-zhangjiakou.aliyuncs.com/HiFIve%20Unmatched/fu740-c000-manual-v1p2.pdf
> >> [2]:https://en.wikipedia.org/wiki/Duty_cycle
> > 
> > Please delete link 2, convert the other two to standard Link: tags and
> > put this information in the dts patch. Possibly into the PWM patch too,
> > depending on what the PWM maintainers think.
> > This info should be in the commit history IMO and the commit message for
> > the dts patch says what's obvious from the diff without any explanation
> > as to why.
> > 
> > I did a bit of looking around on lore, to see if I could figure out
> > why it was done like this in the first place, and I found:
> > https://lore.kernel.org/linux-pwm/CAJ2_jOG2M03aLBgUOgGjWH9CUxq2aTG97eSX70=UaSbGCMMF_g@mail.gmail.com/
> 
> That DTS documentation makes no sense to me, why does what the LED is
> wired to matter?

```
      active-low:
        description:
          For PWMs where the LED is wired to supply rather than ground.
```

> Whether you have your transistor next to ground or
> next to Vdd doesn’t matter, what matters is whether the transistor is
> on or off. Maybe what they mean is whether the *PWM's output* / *the
> transistor's input* is pulled to ground or Vdd? In which case the
> property would indeed not apply here.
> 
> Unless that’s written assuming the LED is wired directly to the PWM, in
> which case it would make sense, but that’s a very narrow-minded view of
> what the PWM output is (directly) driving.

I would suspect that it was written with that assumption.
Probably was the case on the specific board this property was originally
added for.

Maybe it'd be a bit more foolproof written as "For LEDs that are
illuminated while the PWM output is low. For example, where an LED is
wired between supply and the PWM output."?


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH 0/2] Change PWM-controlled LED pin active mode and algorithm
  2023-01-13 19:24   ` Jessica Clarke
  2023-01-14 14:00     ` Conor Dooley
@ 2023-01-17  9:32     ` Nylon Chen
  2023-01-17 15:08       ` Ron Economos
  2023-01-18  2:30     ` Nylon Chen
  2 siblings, 1 reply; 14+ messages in thread
From: Nylon Chen @ 2023-01-17  9:32 UTC (permalink / raw)
  To: Jessica Clarke
  Cc: Conor Dooley, Paul Walmsley, Palmer Dabbelt,
	Linux Kernel Mailing List, linux-riscv, nylon7717, zong.li,
	greentime.hu, vincent.chen, Thierry Reding,
	Uwe Kleine-König, linux-pwm

Hi Conor, Jessica

thanks for your reply.

Jessica Clarke <jrtc27@jrtc27.com> 於 2023年1月14日 週六 上午3:24寫道:
>
> On 13 Jan 2023, at 18:32, Conor Dooley <conor@kernel.org> wrote:
> >
> > +CC Uwe, Thierry, linux-pwm
> >
> > Hey Nylon,
> >
> > Please run scripts/get_maintainer.pl before sending patches, you missed
> > both me & the PWM maintainers unfortunately!
> > AFAIK, the PWM maintainers use patchwork, so you will probably have to
> > resend this patchset so that it is on their radar.
> > I've marked the series as "Changes Requested" on the RISC-V one.
I got it. I will base it on get_maintainer.pl, re-sent it.
> >
> > On Fri, Jan 13, 2023 at 04:31:13PM +0800, Nylon Chen wrote:
> >
> >> According to the circuit diagram of User LEDs - RGB described in the
> >> manual hifive-unmatched-schematics-v3.pdf[0].
> >> The behavior of PWM is acitve-high.
> >>
> >> According to the descriptionof PWM for pwmcmp in SiFive FU740-C000
> >> Manual[1].
> >> The pwm algorithm is (PW) pulse active time  = (D) duty * (T) period[2].
> >> The `frac` variable is pulse "inactive" time so we need to invert it.
> >>
> >> So this patchset removes active-low in DTS and adds reverse logic to
> >> the driver.
> >>
> >> [0]:https://sifive-china.oss-cn-zhangjiakou.aliyuncs.com/HiFIve%20Unmatched/hifive-unmatched-schematics-v3.pdf
> >> [1]:https://sifive-china.oss-cn-zhangjiakou.aliyuncs.com/HiFIve%20Unmatched/fu740-c000-manual-v1p2.pdf
> >> [2]:https://en.wikipedia.org/wiki/Duty_cycle
> >
> > Please delete link 2, convert the other two to standard Link: tags and
> > put this information in the dts patch. Possibly into the PWM patch too,
> > depending on what the PWM maintainers think.
I got it. I will fix it.
> > This info should be in the commit history IMO and the commit message for
> > the dts patch says what's obvious from the diff without any explanation
> > as to why.
> >
> > I did a bit of looking around on lore, to see if I could figure out
> > why it was done like this in the first place, and I found:
> > https://lore.kernel.org/linux-pwm/CAJ2_jOG2M03aLBgUOgGjWH9CUxq2aTG97eSX70=UaSbGCMMF_g@mail.gmail.com/
>
> That DTS documentation makes no sense to me, why does what the LED is
> wired to matter? Whether you have your transistor next to ground or
> next to Vdd doesn’t matter, what matters is whether the transistor is
> on or off. Maybe what they mean is whether the *PWM's output* / *the
> transistor's input* is pulled to ground or Vdd? In which case the
> property would indeed not apply here.
>
> Unless that’s written assuming the LED is wired directly to the PWM, in
> which case it would make sense, but that’s a very narrow-minded view of
> what the PWM output is (directly) driving.
>
> Jess
>
This is a HiFive Unmatched/Unleashed LED-PWM layout

            VDD
               |
               |
           _____
           \        /   LED
            \     /
              ---
               |
               |
               |
         ______
        |              |
        -             |
        ^    -->    |------ PWM
        |___|___|
               |
               |
              __
               -
            GND

- the waveform
e.g. duty=30s, period=100s, actvie-high = 30%, active-low = 70%

V
^
|
| ----------|
|             |
|             |
|______ |__________ > t

When VCC is high, the LED will be illuminated, which is an active-high
logic. This is why we need to remove "active-low".

So, according to my understanding, Unleashed's DTS should also remove
active-low.
> > That doesn't explain the driver, but it does explain the dts being that
> > way. Perhaps a Fixes tag is also in order? But only if both patches get
> > one, otherwise backporting would lead to breakage.
> >
> > The min() construct appears to have been there since the RFC driver was
> > first posted.
> >
> > Thanks,
> > Conor.
> >
> >>
> >> Nylon Chen (2):
> >>  riscv: dts: sifive unmatched: Remove PWM controlled LED's active-low
> >
> > nit: s/sifive unmatched:/sifive: unmatched:/
I got it. I will fix it.

> >
> >>    properties
> >>  pwm: sifive: change the PWM controlled LED algorithm
> >>
> >> arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts | 4 ----
> >> drivers/pwm/pwm-sifive.c                            | 1 +
> >> 2 files changed, 1 insertion(+), 4 deletions(-)
> >>
> >> --
> >> 2.36.1
> >>
> >>
> >> _______________________________________________
> >> linux-riscv mailing list
> >> linux-riscv@lists.infradead.org
> >> http://lists.infradead.org/mailman/listinfo/linux-riscv
> > _______________________________________________
> > linux-riscv mailing list
> > linux-riscv@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/linux-riscv
>

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

* Re: [PATCH 1/2] riscv: dts: sifive unmatched: Remove PWM controlled LED's active-low properties
  2023-01-13  8:31 ` [PATCH 1/2] riscv: dts: sifive unmatched: Remove PWM controlled LED's active-low properties Nylon Chen
@ 2023-01-17 13:57   ` Conor Dooley
  0 siblings, 0 replies; 14+ messages in thread
From: Conor Dooley @ 2023-01-17 13:57 UTC (permalink / raw)
  To: Nylon Chen
  Cc: paul.walmsley, palmer, linux-kernel, linux-riscv, nylon7717,
	zong.li, greentime.hu, vincent.chen

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

Hey Nylon,

On Fri, Jan 13, 2023 at 04:31:14PM +0800, Nylon Chen wrote:
> This removes the active-low properties of the PWM-controlled LEDs in
> the HiFive Unmatched device tree.

Does unleashed also have the same issue?
It has the same compatible at the very least.

Thanks,
Conor.

> 
> Signed-off-by: Nylon Chen <nylon.chen@sifive.com>
> Reviewed-by: Vincent Chen <vincent.chen@sifive.com>
> ---
>  arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts | 4 ----
>  1 file changed, 4 deletions(-)
> 
> diff --git a/arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts b/arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts
> index 07387f9c135c..11f08a545ee6 100644
> --- a/arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts
> +++ b/arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts
> @@ -52,7 +52,6 @@ led-controller-1 {
>  
>  		led-d12 {
>  			pwms = <&pwm0 0 7812500 PWM_POLARITY_INVERTED>;
> -			active-low;
>  			color = <LED_COLOR_ID_GREEN>;
>  			max-brightness = <255>;
>  			label = "d12";
> @@ -69,19 +68,16 @@ multi-led {
>  
>  			led-red {
>  				pwms = <&pwm0 2 7812500 PWM_POLARITY_INVERTED>;
> -				active-low;
>  				color = <LED_COLOR_ID_RED>;
>  			};
>  
>  			led-green {
>  				pwms = <&pwm0 1 7812500 PWM_POLARITY_INVERTED>;
> -				active-low;
>  				color = <LED_COLOR_ID_GREEN>;
>  			};
>  
>  			led-blue {
>  				pwms = <&pwm0 3 7812500 PWM_POLARITY_INVERTED>;
> -				active-low;
>  				color = <LED_COLOR_ID_BLUE>;
>  			};
>  		};
> -- 
> 2.36.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH 0/2] Change PWM-controlled LED pin active mode and algorithm
  2023-01-17  9:32     ` Nylon Chen
@ 2023-01-17 15:08       ` Ron Economos
  2023-01-18  1:46         ` Ron Economos
  0 siblings, 1 reply; 14+ messages in thread
From: Ron Economos @ 2023-01-17 15:08 UTC (permalink / raw)
  To: Nylon Chen, Jessica Clarke
  Cc: Conor Dooley, Paul Walmsley, Palmer Dabbelt,
	Linux Kernel Mailing List, linux-riscv, nylon7717, zong.li,
	greentime.hu, vincent.chen, Thierry Reding,
	Uwe Kleine-König, linux-pwm

On 1/17/23 1:32 AM, Nylon Chen wrote:
> Hi Conor, Jessica
>
> thanks for your reply.
>
> Jessica Clarke <jrtc27@jrtc27.com> 於 2023年1月14日 週六 上午3:24寫道:
>> On 13 Jan 2023, at 18:32, Conor Dooley <conor@kernel.org> wrote:
>>> +CC Uwe, Thierry, linux-pwm
>>>
>>> Hey Nylon,
>>>
>>> Please run scripts/get_maintainer.pl before sending patches, you missed
>>> both me & the PWM maintainers unfortunately!
>>> AFAIK, the PWM maintainers use patchwork, so you will probably have to
>>> resend this patchset so that it is on their radar.
>>> I've marked the series as "Changes Requested" on the RISC-V one.
> I got it. I will base it on get_maintainer.pl, re-sent it.
>>> On Fri, Jan 13, 2023 at 04:31:13PM +0800, Nylon Chen wrote:
>>>
>>>> According to the circuit diagram of User LEDs - RGB described in the
>>>> manual hifive-unmatched-schematics-v3.pdf[0].
>>>> The behavior of PWM is acitve-high.
>>>>
>>>> According to the descriptionof PWM for pwmcmp in SiFive FU740-C000
>>>> Manual[1].
>>>> The pwm algorithm is (PW) pulse active time  = (D) duty * (T) period[2].
>>>> The `frac` variable is pulse "inactive" time so we need to invert it.
>>>>
>>>> So this patchset removes active-low in DTS and adds reverse logic to
>>>> the driver.
>>>>
>>>> [0]:https://sifive-china.oss-cn-zhangjiakou.aliyuncs.com/HiFIve%20Unmatched/hifive-unmatched-schematics-v3.pdf
>>>> [1]:https://sifive-china.oss-cn-zhangjiakou.aliyuncs.com/HiFIve%20Unmatched/fu740-c000-manual-v1p2.pdf
>>>> [2]:https://en.wikipedia.org/wiki/Duty_cycle
>>> Please delete link 2, convert the other two to standard Link: tags and
>>> put this information in the dts patch. Possibly into the PWM patch too,
>>> depending on what the PWM maintainers think.
> I got it. I will fix it.
>>> This info should be in the commit history IMO and the commit message for
>>> the dts patch says what's obvious from the diff without any explanation
>>> as to why.
>>>
>>> I did a bit of looking around on lore, to see if I could figure out
>>> why it was done like this in the first place, and I found:
>>> https://lore.kernel.org/linux-pwm/CAJ2_jOG2M03aLBgUOgGjWH9CUxq2aTG97eSX70=UaSbGCMMF_g@mail.gmail.com/
>> That DTS documentation makes no sense to me, why does what the LED is
>> wired to matter? Whether you have your transistor next to ground or
>> next to Vdd doesn’t matter, what matters is whether the transistor is
>> on or off. Maybe what they mean is whether the *PWM's output* / *the
>> transistor's input* is pulled to ground or Vdd? In which case the
>> property would indeed not apply here.
>>
>> Unless that’s written assuming the LED is wired directly to the PWM, in
>> which case it would make sense, but that’s a very narrow-minded view of
>> what the PWM output is (directly) driving.
>>
>> Jess
>>
> This is a HiFive Unmatched/Unleashed LED-PWM layout
>
>              VDD
>                 |
>                 |
>             _____
>             \        /   LED
>              \     /
>                ---
>                 |
>                 |
>                 |
>           ______
>          |              |
>          -             |
>          ^    -->    |------ PWM
>          |___|___|
>                 |
>                 |
>                __
>                 -
>              GND
>
> - the waveform
> e.g. duty=30s, period=100s, actvie-high = 30%, active-low = 70%
>
> V
> ^
> |
> | ----------|
> |             |
> |             |
> |______ |__________ > t
>
> When VCC is high, the LED will be illuminated, which is an active-high
> logic. This is why we need to remove "active-low".
>
> So, according to my understanding, Unleashed's DTS should also remove
> active-low.
>>> That doesn't explain the driver, but it does explain the dts being that
>>> way. Perhaps a Fixes tag is also in order? But only if both patches get
>>> one, otherwise backporting would lead to breakage.
>>>
>>> The min() construct appears to have been there since the RFC driver was
>>> first posted.
>>>
>>> Thanks,
>>> Conor.
>>>
>>>> Nylon Chen (2):
>>>>   riscv: dts: sifive unmatched: Remove PWM controlled LED's active-low
>>> nit: s/sifive unmatched:/sifive: unmatched:/
> I got it. I will fix it.
>
>>>>     properties
>>>>   pwm: sifive: change the PWM controlled LED algorithm
>>>>
>>>> arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts | 4 ----
>>>> drivers/pwm/pwm-sifive.c                            | 1 +
>>>> 2 files changed, 1 insertion(+), 4 deletions(-)
>>>>
>>>> --
>>>> 2.36.1

I've tested this patch. For some reason, the heartbeat function no 
longer works for D12. This is my /etc/udev/rules.d/99-pwm-leds.rules 
file contents:

# D12 LED: heartbeat
SUBSYSTEM=="leds", KERNEL=="d12", ACTION=="add", ATTR{trigger}="heartbeat"

# D2 RGB LED: boot status
SUBSYSTEM=="leds", KERNEL=="d2", ACTION=="add", 
ATTR{trigger}="default-on", ATTR{multi_intensity}="25 25 25"

This is from https://github.com/sifive/meta-sifive, but modified for the 
multi_intensity driver introduced in Linux 6.0.



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

* Re: [PATCH 0/2] Change PWM-controlled LED pin active mode and algorithm
  2023-01-17 15:08       ` Ron Economos
@ 2023-01-18  1:46         ` Ron Economos
  2023-01-18  3:40           ` Ron Economos
  0 siblings, 1 reply; 14+ messages in thread
From: Ron Economos @ 2023-01-18  1:46 UTC (permalink / raw)
  To: Nylon Chen, Jessica Clarke
  Cc: Conor Dooley, Paul Walmsley, Palmer Dabbelt,
	Linux Kernel Mailing List, linux-riscv, nylon7717, zong.li,
	greentime.hu, vincent.chen, Thierry Reding,
	Uwe Kleine-König, linux-pwm

On 1/17/23 7:08 AM, Ron Economos wrote:
> On 1/17/23 1:32 AM, Nylon Chen wrote:
>> Hi Conor, Jessica
>>
>> thanks for your reply.
>>
>> Jessica Clarke <jrtc27@jrtc27.com> 於 2023年1月14日 週六 上午3:24寫道:
>>> On 13 Jan 2023, at 18:32, Conor Dooley <conor@kernel.org> wrote:
>>>> +CC Uwe, Thierry, linux-pwm
>>>>
>>>> Hey Nylon,
>>>>
>>>> Please run scripts/get_maintainer.pl before sending patches, you 
>>>> missed
>>>> both me & the PWM maintainers unfortunately!
>>>> AFAIK, the PWM maintainers use patchwork, so you will probably have to
>>>> resend this patchset so that it is on their radar.
>>>> I've marked the series as "Changes Requested" on the RISC-V one.
>> I got it. I will base it on get_maintainer.pl, re-sent it.
>>>> On Fri, Jan 13, 2023 at 04:31:13PM +0800, Nylon Chen wrote:
>>>>
>>>>> According to the circuit diagram of User LEDs - RGB described in the
>>>>> manual hifive-unmatched-schematics-v3.pdf[0].
>>>>> The behavior of PWM is acitve-high.
>>>>>
>>>>> According to the descriptionof PWM for pwmcmp in SiFive FU740-C000
>>>>> Manual[1].
>>>>> The pwm algorithm is (PW) pulse active time  = (D) duty * (T) 
>>>>> period[2].
>>>>> The `frac` variable is pulse "inactive" time so we need to invert it.
>>>>>
>>>>> So this patchset removes active-low in DTS and adds reverse logic to
>>>>> the driver.
>>>>>
>>>>> [0]:https://sifive-china.oss-cn-zhangjiakou.aliyuncs.com/HiFIve%20Unmatched/hifive-unmatched-schematics-v3.pdf 
>>>>>
>>>>> [1]:https://sifive-china.oss-cn-zhangjiakou.aliyuncs.com/HiFIve%20Unmatched/fu740-c000-manual-v1p2.pdf 
>>>>>
>>>>> [2]:https://en.wikipedia.org/wiki/Duty_cycle
>>>> Please delete link 2, convert the other two to standard Link: tags and
>>>> put this information in the dts patch. Possibly into the PWM patch 
>>>> too,
>>>> depending on what the PWM maintainers think.
>> I got it. I will fix it.
>>>> This info should be in the commit history IMO and the commit 
>>>> message for
>>>> the dts patch says what's obvious from the diff without any 
>>>> explanation
>>>> as to why.
>>>>
>>>> I did a bit of looking around on lore, to see if I could figure out
>>>> why it was done like this in the first place, and I found:
>>>> https://lore.kernel.org/linux-pwm/CAJ2_jOG2M03aLBgUOgGjWH9CUxq2aTG97eSX70=UaSbGCMMF_g@mail.gmail.com/ 
>>>>
>>> That DTS documentation makes no sense to me, why does what the LED is
>>> wired to matter? Whether you have your transistor next to ground or
>>> next to Vdd doesn’t matter, what matters is whether the transistor is
>>> on or off. Maybe what they mean is whether the *PWM's output* / *the
>>> transistor's input* is pulled to ground or Vdd? In which case the
>>> property would indeed not apply here.
>>>
>>> Unless that’s written assuming the LED is wired directly to the PWM, in
>>> which case it would make sense, but that’s a very narrow-minded view of
>>> what the PWM output is (directly) driving.
>>>
>>> Jess
>>>
>> This is a HiFive Unmatched/Unleashed LED-PWM layout
>>
>>              VDD
>>                 |
>>                 |
>>             _____
>>             \        /   LED
>>              \     /
>>                ---
>>                 |
>>                 |
>>                 |
>>           ______
>>          |              |
>>          -             |
>>          ^    -->    |------ PWM
>>          |___|___|
>>                 |
>>                 |
>>                __
>>                 -
>>              GND
>>
>> - the waveform
>> e.g. duty=30s, period=100s, actvie-high = 30%, active-low = 70%
>>
>> V
>> ^
>> |
>> | ----------|
>> |             |
>> |             |
>> |______ |__________ > t
>>
>> When VCC is high, the LED will be illuminated, which is an active-high
>> logic. This is why we need to remove "active-low".
>>
>> So, according to my understanding, Unleashed's DTS should also remove
>> active-low.
>>>> That doesn't explain the driver, but it does explain the dts being 
>>>> that
>>>> way. Perhaps a Fixes tag is also in order? But only if both patches 
>>>> get
>>>> one, otherwise backporting would lead to breakage.
>>>>
>>>> The min() construct appears to have been there since the RFC driver 
>>>> was
>>>> first posted.
>>>>
>>>> Thanks,
>>>> Conor.
>>>>
>>>>> Nylon Chen (2):
>>>>>   riscv: dts: sifive unmatched: Remove PWM controlled LED's 
>>>>> active-low
>>>> nit: s/sifive unmatched:/sifive: unmatched:/
>> I got it. I will fix it.
>>
>>>>>     properties
>>>>>   pwm: sifive: change the PWM controlled LED algorithm
>>>>>
>>>>> arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts | 4 ----
>>>>> drivers/pwm/pwm-sifive.c                            | 1 +
>>>>> 2 files changed, 1 insertion(+), 4 deletions(-)
>>>>>
>>>>> -- 
>>>>> 2.36.1
>
> I've tested this patch. For some reason, the heartbeat function no 
> longer works for D12. This is my /etc/udev/rules.d/99-pwm-leds.rules 
> file contents:
>
> # D12 LED: heartbeat
> SUBSYSTEM=="leds", KERNEL=="d12", ACTION=="add", 
> ATTR{trigger}="heartbeat"
>
> # D2 RGB LED: boot status
> SUBSYSTEM=="leds", KERNEL=="d2", ACTION=="add", 
> ATTR{trigger}="default-on", ATTR{multi_intensity}="25 25 25"
>
> This is from https://github.com/sifive/meta-sifive, but modified for 
> the multi_intensity driver introduced in Linux 6.0.
>
I've instrumented this patch with some printks. The reason the heartbeat 
doesn't work is that setting the LEDs to maximum brightness causes the 
variable "frac" to be set to -1 instead of 0.

You can test it with:

# /bin/echo "255" > /sys/class/leds/d12/brightness



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

* Re: [PATCH 0/2] Change PWM-controlled LED pin active mode and algorithm
  2023-01-13 19:24   ` Jessica Clarke
  2023-01-14 14:00     ` Conor Dooley
  2023-01-17  9:32     ` Nylon Chen
@ 2023-01-18  2:30     ` Nylon Chen
  2 siblings, 0 replies; 14+ messages in thread
From: Nylon Chen @ 2023-01-18  2:30 UTC (permalink / raw)
  To: Jessica Clarke
  Cc: Conor Dooley, Paul Walmsley, Palmer Dabbelt,
	Linux Kernel Mailing List, linux-riscv, nylon7717, zong.li,
	greentime.hu, vincent.chen, Thierry Reding,
	Uwe Kleine-König, linux-pwm

Hi Jess,

as you said, I use LED directly connected to PWM logic to modify it.

As I stated in my previous article, the key is that the lower the PWM
output is, the brighter the LED light is(active-low), the higher the
PWM output is, the brighter the LED light is(active-high).

Therefore, I would point out the waveform diagram below, the output
result remains the same for the circuit, but when you use
active-low/active-high to look at it, you will get two completely
different results of brightness.

e.g. duty=30s, period=100s, actvie-high = 30%, active-low = 70%

V
^
|
| ----------|
|             |
|             |
|______ |__________ > t

Jessica Clarke <jrtc27@jrtc27.com> 於 2023年1月14日 週六 上午3:24寫道:
>
> On 13 Jan 2023, at 18:32, Conor Dooley <conor@kernel.org> wrote:
> >
> > +CC Uwe, Thierry, linux-pwm
> >
> > Hey Nylon,
> >
> > Please run scripts/get_maintainer.pl before sending patches, you missed
> > both me & the PWM maintainers unfortunately!
> > AFAIK, the PWM maintainers use patchwork, so you will probably have to
> > resend this patchset so that it is on their radar.
> > I've marked the series as "Changes Requested" on the RISC-V one.
> >
> > On Fri, Jan 13, 2023 at 04:31:13PM +0800, Nylon Chen wrote:
> >
> >> According to the circuit diagram of User LEDs - RGB described in the
> >> manual hifive-unmatched-schematics-v3.pdf[0].
> >> The behavior of PWM is acitve-high.
> >>
> >> According to the descriptionof PWM for pwmcmp in SiFive FU740-C000
> >> Manual[1].
> >> The pwm algorithm is (PW) pulse active time  = (D) duty * (T) period[2].
> >> The `frac` variable is pulse "inactive" time so we need to invert it.
> >>
> >> So this patchset removes active-low in DTS and adds reverse logic to
> >> the driver.
> >>
> >> [0]:https://sifive-china.oss-cn-zhangjiakou.aliyuncs.com/HiFIve%20Unmatched/hifive-unmatched-schematics-v3.pdf
> >> [1]:https://sifive-china.oss-cn-zhangjiakou.aliyuncs.com/HiFIve%20Unmatched/fu740-c000-manual-v1p2.pdf
> >> [2]:https://en.wikipedia.org/wiki/Duty_cycle
> >
> > Please delete link 2, convert the other two to standard Link: tags and
> > put this information in the dts patch. Possibly into the PWM patch too,
> > depending on what the PWM maintainers think.
> > This info should be in the commit history IMO and the commit message for
> > the dts patch says what's obvious from the diff without any explanation
> > as to why.
> >
> > I did a bit of looking around on lore, to see if I could figure out
> > why it was done like this in the first place, and I found:
> > https://lore.kernel.org/linux-pwm/CAJ2_jOG2M03aLBgUOgGjWH9CUxq2aTG97eSX70=UaSbGCMMF_g@mail.gmail.com/
>
> That DTS documentation makes no sense to me, why does what the LED is
> wired to matter? Whether you have your transistor next to ground or
> next to Vdd doesn’t matter, what matters is whether the transistor is
> on or off. Maybe what they mean is whether the *PWM's output* / *the
> transistor's input* is pulled to ground or Vdd? In which case the
> property would indeed not apply here.
>
> Unless that’s written assuming the LED is wired directly to the PWM, in
> which case it would make sense, but that’s a very narrow-minded view of
> what the PWM output is (directly) driving.
>
> Jess
>
> > That doesn't explain the driver, but it does explain the dts being that
> > way. Perhaps a Fixes tag is also in order? But only if both patches get
> > one, otherwise backporting would lead to breakage.
> >
> > The min() construct appears to have been there since the RFC driver was
> > first posted.
> >
> > Thanks,
> > Conor.
> >
> >>
> >> Nylon Chen (2):
> >>  riscv: dts: sifive unmatched: Remove PWM controlled LED's active-low
> >
> > nit: s/sifive unmatched:/sifive: unmatched:/
> >
> >>    properties
> >>  pwm: sifive: change the PWM controlled LED algorithm
> >>
> >> arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts | 4 ----
> >> drivers/pwm/pwm-sifive.c                            | 1 +
> >> 2 files changed, 1 insertion(+), 4 deletions(-)
> >>
> >> --
> >> 2.36.1
> >>
> >>
> >> _______________________________________________
> >> linux-riscv mailing list
> >> linux-riscv@lists.infradead.org
> >> http://lists.infradead.org/mailman/listinfo/linux-riscv
> > _______________________________________________
> > linux-riscv mailing list
> > linux-riscv@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/linux-riscv
>

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

* Re: [PATCH 0/2] Change PWM-controlled LED pin active mode and algorithm
  2023-01-14 14:00     ` Conor Dooley
@ 2023-01-18  2:32       ` Nylon Chen
  2023-01-18  8:13         ` Conor Dooley
  0 siblings, 1 reply; 14+ messages in thread
From: Nylon Chen @ 2023-01-18  2:32 UTC (permalink / raw)
  To: Conor Dooley
  Cc: Jessica Clarke, Paul Walmsley, Palmer Dabbelt,
	Linux Kernel Mailing List, linux-riscv, nylon7717, zong.li,
	greentime.hu, vincent.chen, Thierry Reding,
	Uwe Kleine-König, linux-pwm

Conor Dooley <conor@kernel.org> 於 2023年1月14日 週六 下午10:00寫道:
>
> Hi Jess!
>
> On Fri, Jan 13, 2023 at 07:24:56PM +0000, Jessica Clarke wrote:
> > On 13 Jan 2023, at 18:32, Conor Dooley <conor@kernel.org> wrote:
> > >
>
> > > Please run scripts/get_maintainer.pl before sending patches, you missed
> > > both me & the PWM maintainers unfortunately!
> > > AFAIK, the PWM maintainers use patchwork, so you will probably have to
> > > resend this patchset so that it is on their radar.
> > > I've marked the series as "Changes Requested" on the RISC-V one.
> > >
> > > On Fri, Jan 13, 2023 at 04:31:13PM +0800, Nylon Chen wrote:
> > >
> > >> According to the circuit diagram of User LEDs - RGB described in the
> > >> manual hifive-unmatched-schematics-v3.pdf[0].
> > >> The behavior of PWM is acitve-high.
> > >>
> > >> According to the descriptionof PWM for pwmcmp in SiFive FU740-C000
> > >> Manual[1].
> > >> The pwm algorithm is (PW) pulse active time  = (D) duty * (T) period[2].
> > >> The `frac` variable is pulse "inactive" time so we need to invert it.
> > >>
> > >> So this patchset removes active-low in DTS and adds reverse logic to
> > >> the driver.
> > >>
> > >> [0]:https://sifive-china.oss-cn-zhangjiakou.aliyuncs.com/HiFIve%20Unmatched/hifive-unmatched-schematics-v3.pdf
> > >> [1]:https://sifive-china.oss-cn-zhangjiakou.aliyuncs.com/HiFIve%20Unmatched/fu740-c000-manual-v1p2.pdf
> > >> [2]:https://en.wikipedia.org/wiki/Duty_cycle
> > >
> > > Please delete link 2, convert the other two to standard Link: tags and
> > > put this information in the dts patch. Possibly into the PWM patch too,
> > > depending on what the PWM maintainers think.
> > > This info should be in the commit history IMO and the commit message for
> > > the dts patch says what's obvious from the diff without any explanation
> > > as to why.
> > >
> > > I did a bit of looking around on lore, to see if I could figure out
> > > why it was done like this in the first place, and I found:
> > > https://lore.kernel.org/linux-pwm/CAJ2_jOG2M03aLBgUOgGjWH9CUxq2aTG97eSX70=UaSbGCMMF_g@mail.gmail.com/
> >
> > That DTS documentation makes no sense to me, why does what the LED is
> > wired to matter?
>
> ```
>       active-low:
>         description:
>           For PWMs where the LED is wired to supply rather than ground.
> ```
>
> > Whether you have your transistor next to ground or
> > next to Vdd doesn’t matter, what matters is whether the transistor is
> > on or off. Maybe what they mean is whether the *PWM's output* / *the
> > transistor's input* is pulled to ground or Vdd? In which case the
> > property would indeed not apply here.
> >
> > Unless that’s written assuming the LED is wired directly to the PWM, in
> > which case it would make sense, but that’s a very narrow-minded view of
> > what the PWM output is (directly) driving.
>
> I would suspect that it was written with that assumption.
> Probably was the case on the specific board this property was originally
> added for.
>
Hi Conor

As you can see, there is also the same description in U-Boot.

But in U-Boot, the DTS of Unmatched/Unleashed has not been added active-low.

This is because active-high should be correct if we look at the circuit diagram.
> Maybe it'd be a bit more foolproof written as "For LEDs that are
> illuminated while the PWM output is low. For example, where an LED is
> wired between supply and the PWM output."?
>

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

* Re: [PATCH 0/2] Change PWM-controlled LED pin active mode and algorithm
  2023-01-18  1:46         ` Ron Economos
@ 2023-01-18  3:40           ` Ron Economos
  0 siblings, 0 replies; 14+ messages in thread
From: Ron Economos @ 2023-01-18  3:40 UTC (permalink / raw)
  To: Nylon Chen, Jessica Clarke
  Cc: Conor Dooley, Paul Walmsley, Palmer Dabbelt,
	Linux Kernel Mailing List, linux-riscv, nylon7717, zong.li,
	greentime.hu, vincent.chen, Thierry Reding,
	Uwe Kleine-König, linux-pwm

On 1/17/23 5:46 PM, Ron Economos wrote:
> On 1/17/23 7:08 AM, Ron Economos wrote:
>> On 1/17/23 1:32 AM, Nylon Chen wrote:
>>> Hi Conor, Jessica
>>>
>>> thanks for your reply.
>>>
>>> Jessica Clarke <jrtc27@jrtc27.com> 於 2023年1月14日 週六 上午3:24寫道:
>>>> On 13 Jan 2023, at 18:32, Conor Dooley <conor@kernel.org> wrote:
>>>>> +CC Uwe, Thierry, linux-pwm
>>>>>
>>>>> Hey Nylon,
>>>>>
>>>>> Please run scripts/get_maintainer.pl before sending patches, you 
>>>>> missed
>>>>> both me & the PWM maintainers unfortunately!
>>>>> AFAIK, the PWM maintainers use patchwork, so you will probably 
>>>>> have to
>>>>> resend this patchset so that it is on their radar.
>>>>> I've marked the series as "Changes Requested" on the RISC-V one.
>>> I got it. I will base it on get_maintainer.pl, re-sent it.
>>>>> On Fri, Jan 13, 2023 at 04:31:13PM +0800, Nylon Chen wrote:
>>>>>
>>>>>> According to the circuit diagram of User LEDs - RGB described in the
>>>>>> manual hifive-unmatched-schematics-v3.pdf[0].
>>>>>> The behavior of PWM is acitve-high.
>>>>>>
>>>>>> According to the descriptionof PWM for pwmcmp in SiFive FU740-C000
>>>>>> Manual[1].
>>>>>> The pwm algorithm is (PW) pulse active time  = (D) duty * (T) 
>>>>>> period[2].
>>>>>> The `frac` variable is pulse "inactive" time so we need to invert 
>>>>>> it.
>>>>>>
>>>>>> So this patchset removes active-low in DTS and adds reverse logic to
>>>>>> the driver.
>>>>>>
>>>>>> [0]:https://sifive-china.oss-cn-zhangjiakou.aliyuncs.com/HiFIve%20Unmatched/hifive-unmatched-schematics-v3.pdf 
>>>>>>
>>>>>> [1]:https://sifive-china.oss-cn-zhangjiakou.aliyuncs.com/HiFIve%20Unmatched/fu740-c000-manual-v1p2.pdf 
>>>>>>
>>>>>> [2]:https://en.wikipedia.org/wiki/Duty_cycle
>>>>> Please delete link 2, convert the other two to standard Link: tags 
>>>>> and
>>>>> put this information in the dts patch. Possibly into the PWM patch 
>>>>> too,
>>>>> depending on what the PWM maintainers think.
>>> I got it. I will fix it.
>>>>> This info should be in the commit history IMO and the commit 
>>>>> message for
>>>>> the dts patch says what's obvious from the diff without any 
>>>>> explanation
>>>>> as to why.
>>>>>
>>>>> I did a bit of looking around on lore, to see if I could figure out
>>>>> why it was done like this in the first place, and I found:
>>>>> https://lore.kernel.org/linux-pwm/CAJ2_jOG2M03aLBgUOgGjWH9CUxq2aTG97eSX70=UaSbGCMMF_g@mail.gmail.com/ 
>>>>>
>>>> That DTS documentation makes no sense to me, why does what the LED is
>>>> wired to matter? Whether you have your transistor next to ground or
>>>> next to Vdd doesn’t matter, what matters is whether the transistor is
>>>> on or off. Maybe what they mean is whether the *PWM's output* / *the
>>>> transistor's input* is pulled to ground or Vdd? In which case the
>>>> property would indeed not apply here.
>>>>
>>>> Unless that’s written assuming the LED is wired directly to the 
>>>> PWM, in
>>>> which case it would make sense, but that’s a very narrow-minded 
>>>> view of
>>>> what the PWM output is (directly) driving.
>>>>
>>>> Jess
>>>>
>>> This is a HiFive Unmatched/Unleashed LED-PWM layout
>>>
>>>              VDD
>>>                 |
>>>                 |
>>>             _____
>>>             \        /   LED
>>>              \     /
>>>                ---
>>>                 |
>>>                 |
>>>                 |
>>>           ______
>>>          |              |
>>>          -             |
>>>          ^    -->    |------ PWM
>>>          |___|___|
>>>                 |
>>>                 |
>>>                __
>>>                 -
>>>              GND
>>>
>>> - the waveform
>>> e.g. duty=30s, period=100s, actvie-high = 30%, active-low = 70%
>>>
>>> V
>>> ^
>>> |
>>> | ----------|
>>> |             |
>>> |             |
>>> |______ |__________ > t
>>>
>>> When VCC is high, the LED will be illuminated, which is an active-high
>>> logic. This is why we need to remove "active-low".
>>>
>>> So, according to my understanding, Unleashed's DTS should also remove
>>> active-low.
>>>>> That doesn't explain the driver, but it does explain the dts being 
>>>>> that
>>>>> way. Perhaps a Fixes tag is also in order? But only if both 
>>>>> patches get
>>>>> one, otherwise backporting would lead to breakage.
>>>>>
>>>>> The min() construct appears to have been there since the RFC 
>>>>> driver was
>>>>> first posted.
>>>>>
>>>>> Thanks,
>>>>> Conor.
>>>>>
>>>>>> Nylon Chen (2):
>>>>>>   riscv: dts: sifive unmatched: Remove PWM controlled LED's 
>>>>>> active-low
>>>>> nit: s/sifive unmatched:/sifive: unmatched:/
>>> I got it. I will fix it.
>>>
>>>>>>     properties
>>>>>>   pwm: sifive: change the PWM controlled LED algorithm
>>>>>>
>>>>>> arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts | 4 ----
>>>>>> drivers/pwm/pwm-sifive.c                            | 1 +
>>>>>> 2 files changed, 1 insertion(+), 4 deletions(-)
>>>>>>
>>>>>> -- 
>>>>>> 2.36.1
>>
>> I've tested this patch. For some reason, the heartbeat function no 
>> longer works for D12. This is my /etc/udev/rules.d/99-pwm-leds.rules 
>> file contents:
>>
>> # D12 LED: heartbeat
>> SUBSYSTEM=="leds", KERNEL=="d12", ACTION=="add", 
>> ATTR{trigger}="heartbeat"
>>
>> # D2 RGB LED: boot status
>> SUBSYSTEM=="leds", KERNEL=="d2", ACTION=="add", 
>> ATTR{trigger}="default-on", ATTR{multi_intensity}="25 25 25"
>>
>> This is from https://github.com/sifive/meta-sifive, but modified for 
>> the multi_intensity driver introduced in Linux 6.0.
>>
> I've instrumented this patch with some printks. The reason the 
> heartbeat doesn't work is that setting the LEDs to maximum brightness 
> causes the variable "frac" to be set to -1 instead of 0.
>
> You can test it with:
>
> # /bin/echo "255" > /sys/class/leds/d12/brightness
>
Sorry for the noise, I didn't apply the patch correctly. It works fine.



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

* Re: [PATCH 0/2] Change PWM-controlled LED pin active mode and algorithm
  2023-01-18  2:32       ` Nylon Chen
@ 2023-01-18  8:13         ` Conor Dooley
  0 siblings, 0 replies; 14+ messages in thread
From: Conor Dooley @ 2023-01-18  8:13 UTC (permalink / raw)
  To: Nylon Chen
  Cc: Jessica Clarke, Paul Walmsley, Palmer Dabbelt,
	Linux Kernel Mailing List, linux-riscv, nylon7717, zong.li,
	greentime.hu, vincent.chen, Thierry Reding,
	Uwe Kleine-König, linux-pwm

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

Hey Nylon,

On Wed, Jan 18, 2023 at 10:32:25AM +0800, Nylon Chen wrote:
> Conor Dooley <conor@kernel.org> 於 2023年1月14日 週六 下午10:00寫道:
> > On Fri, Jan 13, 2023 at 07:24:56PM +0000, Jessica Clarke wrote:
> > > On 13 Jan 2023, at 18:32, Conor Dooley <conor@kernel.org> wrote:

> > > > Please delete link 2, convert the other two to standard Link: tags and
> > > > put this information in the dts patch. Possibly into the PWM patch too,
> > > > depending on what the PWM maintainers think.
> > > > This info should be in the commit history IMO and the commit message for
> > > > the dts patch says what's obvious from the diff without any explanation
> > > > as to why.
> > > >
> > > > I did a bit of looking around on lore, to see if I could figure out
> > > > why it was done like this in the first place, and I found:
> > > > https://lore.kernel.org/linux-pwm/CAJ2_jOG2M03aLBgUOgGjWH9CUxq2aTG97eSX70=UaSbGCMMF_g@mail.gmail.com/
> > >
> > > That DTS documentation makes no sense to me, why does what the LED is
> > > wired to matter?
> >
> > ```
> >       active-low:
> >         description:
> >           For PWMs where the LED is wired to supply rather than ground.
> > ```
> >
> > > Whether you have your transistor next to ground or
> > > next to Vdd doesn’t matter, what matters is whether the transistor is
> > > on or off. Maybe what they mean is whether the *PWM's output* / *the
> > > transistor's input* is pulled to ground or Vdd? In which case the
> > > property would indeed not apply here.
> > >
> > > Unless that’s written assuming the LED is wired directly to the PWM, in
> > > which case it would make sense, but that’s a very narrow-minded view of
> > > what the PWM output is (directly) driving.
> >
> > I would suspect that it was written with that assumption.
> > Probably was the case on the specific board this property was originally
> > added for.

> As you can see, there is also the same description in U-Boot.
> 
> But in U-Boot, the DTS of Unmatched/Unleashed has not been added active-low.
> 
> This is because active-high should be correct if we look at the circuit diagram.

I am loathe to speak for Jess, but I don't think either of us are
disagreeing with your patches. I was just trying to understand why it was
wrong in the first place to see if it was intentionally inverted, or if
there was something that could be improve to stop it happening again.
Apologies if that got lost in translation.

> > Maybe it'd be a bit more foolproof written as "For LEDs that are
> > illuminated while the PWM output is low. For example, where an LED is
> > wired between supply and the PWM output."?

Thanks,
Conor.


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

end of thread, other threads:[~2023-01-18  8:59 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-13  8:31 [PATCH 0/2] Change PWM-controlled LED pin active mode and algorithm Nylon Chen
2023-01-13  8:31 ` [PATCH 1/2] riscv: dts: sifive unmatched: Remove PWM controlled LED's active-low properties Nylon Chen
2023-01-17 13:57   ` Conor Dooley
2023-01-13  8:31 ` [PATCH 2/2] pwm: sifive: change the PWM controlled LED algorithm Nylon Chen
2023-01-13 18:32 ` [PATCH 0/2] Change PWM-controlled LED pin active mode and algorithm Conor Dooley
2023-01-13 19:24   ` Jessica Clarke
2023-01-14 14:00     ` Conor Dooley
2023-01-18  2:32       ` Nylon Chen
2023-01-18  8:13         ` Conor Dooley
2023-01-17  9:32     ` Nylon Chen
2023-01-17 15:08       ` Ron Economos
2023-01-18  1:46         ` Ron Economos
2023-01-18  3:40           ` Ron Economos
2023-01-18  2:30     ` Nylon Chen

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