* [PATCH v9 0/3] Change PWM-controlled LED pin active mode and algorithm
@ 2024-02-22 8:12 Nylon Chen
2024-02-22 8:12 ` [PATCH v9 1/3] riscv: dts: sifive: unleashed/unmatched: Remove PWM controlled LED's active-low properties Nylon Chen
` (2 more replies)
0 siblings, 3 replies; 16+ messages in thread
From: Nylon Chen @ 2024-02-22 8:12 UTC (permalink / raw)
To: linux-riscv, devicetree, linux-kernel, linux-pwm, conor, robh+dt,
krzysztof.kozlowski+dt, palmer, paul.walmsley, aou,
thierry.reding, u.kleine-koenig
Cc: vincent.chen, zong.li, nylon.chen, nylon7717
According to the circuit diagram of User LEDs - RGB described in the
manual hifive-unleashed-a00.pdf[0] and hifive-unmatched-schematics-v3.pdf[1].
The behavior of PWM is acitve-high.
According to the descriptionof PWM for pwmcmp in SiFive FU740-C000 Manual[2].
The pwm algorithm is (PW) pulse active time = (D) duty * (T) period.
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.
Updated patches: 1
New patches: 0
Unchanged patches: 2
Links:
- [0]: https://sifive.cdn.prismic.io/sifive/c52a8e32-05ce-4aaf-95c8-7bf8453f8698_hifive-unleashed-a00-schematics-1.pdf
- [1]: https://sifive.cdn.prismic.io/sifive/6a06d6c0-6e66-49b5-8e9e-e68ce76f4192_hifive-unmatched-schematics-v3.pdf
- [2]: https://sifive.cdn.prismic.io/sifive/1a82e600-1f93-4f41-b2d8-86ed8b16acba_fu740-c000-manual-v1p6.pdf
Changed in v9:
- Fix commit message to adhere to 75 columns rule.
- Update commit message's subject.
- Add a variable for inactive logic.
Changed in v8:
- Fix Signed-off-by and Co-developed-by typo.
Changed in v7:
- Remove active-low strings from hifive-unleashed-a00.dts file.
Changed in v6:
- Separate the idempotent test bug fixes into a new patch.
- Move the reversing the duty before the line checking
state->enabled.
- Fix the algorithm and change it to take the minimum value first and
then reverse it.
Changed in v5:
- Add the updates to the PWM algorithm based on version 2 back in.
- Replace div64_ul with DIV_ROUND_UP_ULL to correct the error in the
period value of the idempotent test in pwm_apply_state_debug.
Changed in v4:
- Remove previous updates to the PWM algorithm.
Changed in v3:
- Convert the reference link to standard link.
- Move the inverted function before taking the minimum value.
- Change polarity check condition(high and low).
- Pick the biggest period length possible that is not bigger than the
requested period.
Changed in v2:
- Convert the reference link to standard link.
- Fix typo: s/sifive unmatched:/sifive: unmatched:/.
- Remove active-low from hifive-unleashed-a00.dts.
- Include this reference link in the dts and pwm commit messages.
Nylon Chen (3):
riscv: dts: sifive: unleashed/unmatched: Remove PWM controlled LED's
active-low properties
pwm: sifive: change the PWM controlled LED algorithm
pwm: sifive: Fix the error in the idempotent test within the
pwm_apply_state_debug function
arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts | 12 ++++--------
arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts | 12 ++++--------
drivers/pwm/pwm-sifive.c | 12 +++++++-----
3 files changed, 15 insertions(+), 21 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 16+ messages in thread* [PATCH v9 1/3] riscv: dts: sifive: unleashed/unmatched: Remove PWM controlled LED's active-low properties 2024-02-22 8:12 [PATCH v9 0/3] Change PWM-controlled LED pin active mode and algorithm Nylon Chen @ 2024-02-22 8:12 ` Nylon Chen 2024-02-22 8:12 ` [PATCH v9 2/3] pwm: sifive: change the PWM algorithm Nylon Chen 2024-02-22 8:12 ` [PATCH v9 3/3] pwm: sifive: Fix the error in the idempotent test within the pwm_apply_state_debug function Nylon Chen 2 siblings, 0 replies; 16+ messages in thread From: Nylon Chen @ 2024-02-22 8:12 UTC (permalink / raw) To: linux-riscv, devicetree, linux-kernel, linux-pwm, conor, robh+dt, krzysztof.kozlowski+dt, palmer, paul.walmsley, aou, thierry.reding, u.kleine-koenig Cc: vincent.chen, zong.li, nylon.chen, nylon7717 This removes the active-low properties of the PWM-controlled LEDs in the HiFive Unmatched device tree. The reference is hifive-unleashed-a00.pdf[0] and hifive-unmatched-schematics-v3.pdf[1]. Link: https://sifive.cdn.prismic.io/sifive/c52a8e32-05ce-4aaf-95c8-7bf8453f8698_hifive-unleashed-a00-schematics-1.pdf [0] Link: https://sifive.cdn.prismic.io/sifive/6a06d6c0-6e66-49b5-8e9e-e68ce76f4192_hifive-unmatched-schematics-v3.pdf [1] Co-developed-by: Zong Li <zong.li@sifive.com> Signed-off-by: Zong Li <zong.li@sifive.com> Co-developed-by: Vincent Chen <vincent.chen@sifive.com> Signed-off-by: Vincent Chen <vincent.chen@sifive.com> Signed-off-by: Nylon Chen <nylon.chen@sifive.com> --- arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts | 12 ++++-------- arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts | 12 ++++-------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts b/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts index 900a50526d77..06731b8c7bc3 100644 --- a/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts +++ b/arch/riscv/boot/dts/sifive/hifive-unleashed-a00.dts @@ -49,32 +49,28 @@ led-controller { compatible = "pwm-leds"; led-d1 { - pwms = <&pwm0 0 7812500 PWM_POLARITY_INVERTED>; - active-low; + pwms = <&pwm0 0 7812500 0>; color = <LED_COLOR_ID_GREEN>; max-brightness = <255>; label = "d1"; }; led-d2 { - pwms = <&pwm0 1 7812500 PWM_POLARITY_INVERTED>; - active-low; + pwms = <&pwm0 1 7812500 0>; color = <LED_COLOR_ID_GREEN>; max-brightness = <255>; label = "d2"; }; led-d3 { - pwms = <&pwm0 2 7812500 PWM_POLARITY_INVERTED>; - active-low; + pwms = <&pwm0 2 7812500 0>; color = <LED_COLOR_ID_GREEN>; max-brightness = <255>; label = "d3"; }; led-d4 { - pwms = <&pwm0 3 7812500 PWM_POLARITY_INVERTED>; - active-low; + pwms = <&pwm0 3 7812500 0>; color = <LED_COLOR_ID_GREEN>; max-brightness = <255>; label = "d4"; diff --git a/arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts b/arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts index 07387f9c135c..b328ee80693f 100644 --- a/arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts +++ b/arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts @@ -51,8 +51,7 @@ led-controller-1 { compatible = "pwm-leds"; led-d12 { - pwms = <&pwm0 0 7812500 PWM_POLARITY_INVERTED>; - active-low; + pwms = <&pwm0 0 7812500 0>; color = <LED_COLOR_ID_GREEN>; max-brightness = <255>; label = "d12"; @@ -68,20 +67,17 @@ multi-led { label = "d2"; led-red { - pwms = <&pwm0 2 7812500 PWM_POLARITY_INVERTED>; - active-low; + pwms = <&pwm0 2 7812500 0>; color = <LED_COLOR_ID_RED>; }; led-green { - pwms = <&pwm0 1 7812500 PWM_POLARITY_INVERTED>; - active-low; + pwms = <&pwm0 1 7812500 0>; color = <LED_COLOR_ID_GREEN>; }; led-blue { - pwms = <&pwm0 3 7812500 PWM_POLARITY_INVERTED>; - active-low; + pwms = <&pwm0 3 7812500 0>; color = <LED_COLOR_ID_BLUE>; }; }; -- 2.43.0 ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v9 2/3] pwm: sifive: change the PWM algorithm 2024-02-22 8:12 [PATCH v9 0/3] Change PWM-controlled LED pin active mode and algorithm Nylon Chen 2024-02-22 8:12 ` [PATCH v9 1/3] riscv: dts: sifive: unleashed/unmatched: Remove PWM controlled LED's active-low properties Nylon Chen @ 2024-02-22 8:12 ` Nylon Chen 2024-03-18 18:16 ` Uwe Kleine-König 2024-02-22 8:12 ` [PATCH v9 3/3] pwm: sifive: Fix the error in the idempotent test within the pwm_apply_state_debug function Nylon Chen 2 siblings, 1 reply; 16+ messages in thread From: Nylon Chen @ 2024-02-22 8:12 UTC (permalink / raw) To: linux-riscv, devicetree, linux-kernel, linux-pwm, conor, robh+dt, krzysztof.kozlowski+dt, palmer, paul.walmsley, aou, thierry.reding, u.kleine-koenig Cc: vincent.chen, zong.li, nylon.chen, nylon7717 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. The reference is SiFive FU740-C000 Manual[0] Link: https://sifive.cdn.prismic.io/sifive/1a82e600-1f93-4f41-b2d8-86ed8b16acba_fu740-c000-manual-v1p6.pdf [0] Co-developed-by: Zong Li <zong.li@sifive.com> Signed-off-by: Zong Li <zong.li@sifive.com> Co-developed-by: Vincent Chen <vincent.chen@sifive.com> Signed-off-by: Vincent Chen <vincent.chen@sifive.com> Signed-off-by: Nylon Chen <nylon.chen@sifive.com> --- drivers/pwm/pwm-sifive.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c index eabddb7c7820..a586cfe4191b 100644 --- a/drivers/pwm/pwm-sifive.c +++ b/drivers/pwm/pwm-sifive.c @@ -110,9 +110,10 @@ static int pwm_sifive_get_state(struct pwm_chip *chip, struct pwm_device *pwm, struct pwm_state *state) { struct pwm_sifive_ddata *ddata = pwm_sifive_chip_to_ddata(chip); - u32 duty, val; + u32 duty, val, inactive; - duty = readl(ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm)); + inactive = readl(ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm)); + duty = (1U << PWM_SIFIVE_CMPWIDTH) - 1 - inactive; state->enabled = duty > 0; @@ -123,7 +124,7 @@ static int pwm_sifive_get_state(struct pwm_chip *chip, struct pwm_device *pwm, state->period = ddata->real_period; state->duty_cycle = (u64)duty * ddata->real_period >> PWM_SIFIVE_CMPWIDTH; - state->polarity = PWM_POLARITY_INVERSED; + state->polarity = PWM_POLARITY_NORMAL; return 0; } @@ -139,7 +140,7 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm, int ret = 0; u32 frac; - if (state->polarity != PWM_POLARITY_INVERSED) + if (state->polarity != PWM_POLARITY_NORMAL) return -EINVAL; cur_state = pwm->state; @@ -159,6 +160,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.43.0 ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v9 2/3] pwm: sifive: change the PWM algorithm 2024-02-22 8:12 ` [PATCH v9 2/3] pwm: sifive: change the PWM algorithm Nylon Chen @ 2024-03-18 18:16 ` Uwe Kleine-König 2024-04-02 2:08 ` Nylon Chen 0 siblings, 1 reply; 16+ messages in thread From: Uwe Kleine-König @ 2024-03-18 18:16 UTC (permalink / raw) To: Nylon Chen Cc: linux-riscv, devicetree, linux-kernel, linux-pwm, conor, robh+dt, krzysztof.kozlowski+dt, palmer, paul.walmsley, aou, thierry.reding, vincent.chen, zong.li, nylon7717 [-- Attachment #1: Type: text/plain, Size: 2945 bytes --] On Thu, Feb 22, 2024 at 04:12:30PM +0800, Nylon Chen wrote: > 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. > > The reference is SiFive FU740-C000 Manual[0] > > Link: https://sifive.cdn.prismic.io/sifive/1a82e600-1f93-4f41-b2d8-86ed8b16acba_fu740-c000-manual-v1p6.pdf [0] > > Co-developed-by: Zong Li <zong.li@sifive.com> > Signed-off-by: Zong Li <zong.li@sifive.com> > Co-developed-by: Vincent Chen <vincent.chen@sifive.com> > Signed-off-by: Vincent Chen <vincent.chen@sifive.com> > Signed-off-by: Nylon Chen <nylon.chen@sifive.com> > --- > drivers/pwm/pwm-sifive.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c > index eabddb7c7820..a586cfe4191b 100644 > --- a/drivers/pwm/pwm-sifive.c > +++ b/drivers/pwm/pwm-sifive.c > @@ -110,9 +110,10 @@ static int pwm_sifive_get_state(struct pwm_chip *chip, struct pwm_device *pwm, > struct pwm_state *state) > { > struct pwm_sifive_ddata *ddata = pwm_sifive_chip_to_ddata(chip); > - u32 duty, val; > + u32 duty, val, inactive; > > - duty = readl(ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm)); > + inactive = readl(ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm)); > + duty = (1U << PWM_SIFIVE_CMPWIDTH) - 1 - inactive; > > state->enabled = duty > 0; > > @@ -123,7 +124,7 @@ static int pwm_sifive_get_state(struct pwm_chip *chip, struct pwm_device *pwm, > state->period = ddata->real_period; > state->duty_cycle = > (u64)duty * ddata->real_period >> PWM_SIFIVE_CMPWIDTH; > - state->polarity = PWM_POLARITY_INVERSED; > + state->polarity = PWM_POLARITY_NORMAL; > > return 0; > } > @@ -139,7 +140,7 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm, > int ret = 0; > u32 frac; > > - if (state->polarity != PWM_POLARITY_INVERSED) > + if (state->polarity != PWM_POLARITY_NORMAL) > return -EINVAL; > > cur_state = pwm->state; > @@ -159,6 +160,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 */ Is this still true now that we know that PWM_SIFIVE_PWMCMP is the inactive time in a period? If you fix that, the same claim in the header of the driver needs adaption, too. > frac = min(frac, (1U << PWM_SIFIVE_CMPWIDTH) - 1); > + frac = (1U << PWM_SIFIVE_CMPWIDTH) - 1 - frac; I like the additional variable in pwm_sifive_get_state(). Can you please add one here, too? > mutex_lock(&ddata->lock); > if (state->period != ddata->approx_period) { Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ | [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v9 2/3] pwm: sifive: change the PWM algorithm 2024-03-18 18:16 ` Uwe Kleine-König @ 2024-04-02 2:08 ` Nylon Chen 2024-04-12 2:07 ` Nylon Chen 0 siblings, 1 reply; 16+ messages in thread From: Nylon Chen @ 2024-04-02 2:08 UTC (permalink / raw) To: Uwe Kleine-König Cc: linux-riscv, devicetree, linux-kernel, linux-pwm, conor, robh+dt, krzysztof.kozlowski+dt, palmer, paul.walmsley, aou, thierry.reding, vincent.chen, zong.li, nylon7717 Uwe Kleine-König <u.kleine-koenig@pengutronix.de> 於 2024年3月19日 週二 上午2:16寫道: > > On Thu, Feb 22, 2024 at 04:12:30PM +0800, Nylon Chen wrote: > > 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. > > > > The reference is SiFive FU740-C000 Manual[0] > > > > Link: https://sifive.cdn.prismic.io/sifive/1a82e600-1f93-4f41-b2d8-86ed8b16acba_fu740-c000-manual-v1p6.pdf [0] > > > > Co-developed-by: Zong Li <zong.li@sifive.com> > > Signed-off-by: Zong Li <zong.li@sifive.com> > > Co-developed-by: Vincent Chen <vincent.chen@sifive.com> > > Signed-off-by: Vincent Chen <vincent.chen@sifive.com> > > Signed-off-by: Nylon Chen <nylon.chen@sifive.com> > > --- > > drivers/pwm/pwm-sifive.c | 10 ++++++---- > > 1 file changed, 6 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c > > index eabddb7c7820..a586cfe4191b 100644 > > --- a/drivers/pwm/pwm-sifive.c > > +++ b/drivers/pwm/pwm-sifive.c > > @@ -110,9 +110,10 @@ static int pwm_sifive_get_state(struct pwm_chip *chip, struct pwm_device *pwm, > > struct pwm_state *state) > > { > > struct pwm_sifive_ddata *ddata = pwm_sifive_chip_to_ddata(chip); > > - u32 duty, val; > > + u32 duty, val, inactive; > > > > - duty = readl(ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm)); > > + inactive = readl(ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm)); > > + duty = (1U << PWM_SIFIVE_CMPWIDTH) - 1 - inactive; > > > > state->enabled = duty > 0; > > > > @@ -123,7 +124,7 @@ static int pwm_sifive_get_state(struct pwm_chip *chip, struct pwm_device *pwm, > > state->period = ddata->real_period; > > state->duty_cycle = > > (u64)duty * ddata->real_period >> PWM_SIFIVE_CMPWIDTH; > > - state->polarity = PWM_POLARITY_INVERSED; > > + state->polarity = PWM_POLARITY_NORMAL; > > > > return 0; > > } > > @@ -139,7 +140,7 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm, > > int ret = 0; > > u32 frac; > > > > - if (state->polarity != PWM_POLARITY_INVERSED) > > + if (state->polarity != PWM_POLARITY_NORMAL) > > return -EINVAL; > > > > cur_state = pwm->state; > > @@ -159,6 +160,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 */ > > Is this still true now that we know that PWM_SIFIVE_PWMCMP is the > inactive time in a period? If you fix that, the same claim in the header > of the driver needs adaption, too. I believe the statement is true, but I don't know which part the driver header file refers to. > > > frac = min(frac, (1U << PWM_SIFIVE_CMPWIDTH) - 1); > > + frac = (1U << PWM_SIFIVE_CMPWIDTH) - 1 - frac; > > I like the additional variable in pwm_sifive_get_state(). Can you please > add one here, too? got it > > > mutex_lock(&ddata->lock); > > if (state->period != ddata->approx_period) { > Thank you for taking the time to help me review my implementation. Nylon > Best regards > Uwe > > -- > Pengutronix e.K. | Uwe Kleine-König | > Industrial Linux Solutions | https://www.pengutronix.de/ | ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v9 2/3] pwm: sifive: change the PWM algorithm 2024-04-02 2:08 ` Nylon Chen @ 2024-04-12 2:07 ` Nylon Chen 2024-04-12 7:01 ` Uwe Kleine-König 0 siblings, 1 reply; 16+ messages in thread From: Nylon Chen @ 2024-04-12 2:07 UTC (permalink / raw) To: Uwe Kleine-König Cc: linux-riscv, devicetree, linux-kernel, linux-pwm, conor, robh+dt, krzysztof.kozlowski+dt, palmer, paul.walmsley, aou, thierry.reding, vincent.chen, zong.li, nylon7717 Nylon Chen <nylon.chen@sifive.com> 於 2024年4月2日 週二 上午10:08寫道: > > Uwe Kleine-König <u.kleine-koenig@pengutronix.de> 於 2024年3月19日 週二 上午2:16寫道: > > > > On Thu, Feb 22, 2024 at 04:12:30PM +0800, Nylon Chen wrote: > > > 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. > > > > > > The reference is SiFive FU740-C000 Manual[0] > > > > > > Link: https://sifive.cdn.prismic.io/sifive/1a82e600-1f93-4f41-b2d8-86ed8b16acba_fu740-c000-manual-v1p6.pdf [0] > > > > > > Co-developed-by: Zong Li <zong.li@sifive.com> > > > Signed-off-by: Zong Li <zong.li@sifive.com> > > > Co-developed-by: Vincent Chen <vincent.chen@sifive.com> > > > Signed-off-by: Vincent Chen <vincent.chen@sifive.com> > > > Signed-off-by: Nylon Chen <nylon.chen@sifive.com> > > > --- > > > drivers/pwm/pwm-sifive.c | 10 ++++++---- > > > 1 file changed, 6 insertions(+), 4 deletions(-) > > > > > > diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c > > > index eabddb7c7820..a586cfe4191b 100644 > > > --- a/drivers/pwm/pwm-sifive.c > > > +++ b/drivers/pwm/pwm-sifive.c > > > @@ -110,9 +110,10 @@ static int pwm_sifive_get_state(struct pwm_chip *chip, struct pwm_device *pwm, > > > struct pwm_state *state) > > > { > > > struct pwm_sifive_ddata *ddata = pwm_sifive_chip_to_ddata(chip); > > > - u32 duty, val; > > > + u32 duty, val, inactive; > > > > > > - duty = readl(ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm)); > > > + inactive = readl(ddata->regs + PWM_SIFIVE_PWMCMP(pwm->hwpwm)); > > > + duty = (1U << PWM_SIFIVE_CMPWIDTH) - 1 - inactive; > > > > > > state->enabled = duty > 0; > > > > > > @@ -123,7 +124,7 @@ static int pwm_sifive_get_state(struct pwm_chip *chip, struct pwm_device *pwm, > > > state->period = ddata->real_period; > > > state->duty_cycle = > > > (u64)duty * ddata->real_period >> PWM_SIFIVE_CMPWIDTH; > > > - state->polarity = PWM_POLARITY_INVERSED; > > > + state->polarity = PWM_POLARITY_NORMAL; > > > > > > return 0; > > > } > > > @@ -139,7 +140,7 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm, > > > int ret = 0; > > > u32 frac; > > > > > > - if (state->polarity != PWM_POLARITY_INVERSED) > > > + if (state->polarity != PWM_POLARITY_NORMAL) > > > return -EINVAL; > > > > > > cur_state = pwm->state; > > > @@ -159,6 +160,7 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm, > > > frac = DIV64_U64_ROUND_CLOSEST(num, state->period); Hi Uwe, > > > /* The hardware cannot generate a 100% duty cycle */ Do you mean that if the inference is correct, this comment should be modified? > > > > Is this still true now that we know that PWM_SIFIVE_PWMCMP is the > > inactive time in a period? If you fix that, the same claim in the header > > of the driver needs adaption, too. > I believe the statement is true, but I don't know which part the > driver header file refers to. > > > > > frac = min(frac, (1U << PWM_SIFIVE_CMPWIDTH) - 1); > > > + frac = (1U << PWM_SIFIVE_CMPWIDTH) - 1 - frac; > > > > I like the additional variable in pwm_sifive_get_state(). Can you please > > add one here, too? > got it > > > > > mutex_lock(&ddata->lock); > > > if (state->period != ddata->approx_period) { > > > Thank you for taking the time to help me review my implementation. > > Nylon > > Best regards > > Uwe > > > > -- > > Pengutronix e.K. | Uwe Kleine-König | > > Industrial Linux Solutions | https://www.pengutronix.de/ | ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v9 2/3] pwm: sifive: change the PWM algorithm 2024-04-12 2:07 ` Nylon Chen @ 2024-04-12 7:01 ` Uwe Kleine-König 0 siblings, 0 replies; 16+ messages in thread From: Uwe Kleine-König @ 2024-04-12 7:01 UTC (permalink / raw) To: Nylon Chen Cc: linux-riscv, devicetree, linux-kernel, linux-pwm, conor, robh+dt, krzysztof.kozlowski+dt, palmer, paul.walmsley, aou, thierry.reding, vincent.chen, zong.li, nylon7717 [-- Attachment #1: Type: text/plain, Size: 849 bytes --] Hello, On Fri, Apr 12, 2024 at 10:07:12AM +0800, Nylon Chen wrote: > Nylon Chen <nylon.chen@sifive.com> 於 2024年4月2日 週二 上午10:08寫道: > > Uwe Kleine-König <u.kleine-koenig@pengutronix.de> 於 2024年3月19日 週二 上午2:16寫道: > > > On Thu, Feb 22, 2024 at 04:12:30PM +0800, Nylon Chen wrote: > > > > /* The hardware cannot generate a 100% duty cycle */ > Do you mean that if the inference is correct, this comment should be modified? If the polarity was wrong before and the hardware was believed to not be able to generate a 100% relative duty cycle, then maybe it's really a 0% relative duty cycle that's impossible? Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ | [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v9 3/3] pwm: sifive: Fix the error in the idempotent test within the pwm_apply_state_debug function 2024-02-22 8:12 [PATCH v9 0/3] Change PWM-controlled LED pin active mode and algorithm Nylon Chen 2024-02-22 8:12 ` [PATCH v9 1/3] riscv: dts: sifive: unleashed/unmatched: Remove PWM controlled LED's active-low properties Nylon Chen 2024-02-22 8:12 ` [PATCH v9 2/3] pwm: sifive: change the PWM algorithm Nylon Chen @ 2024-02-22 8:12 ` Nylon Chen 2024-03-18 18:17 ` Uwe Kleine-König 2 siblings, 1 reply; 16+ messages in thread From: Nylon Chen @ 2024-02-22 8:12 UTC (permalink / raw) To: linux-riscv, devicetree, linux-kernel, linux-pwm, conor, robh+dt, krzysztof.kozlowski+dt, palmer, paul.walmsley, aou, thierry.reding, u.kleine-koenig Cc: vincent.chen, zong.li, nylon.chen, nylon7717 Round the result to the nearest whole number. This ensures that real_period is always a reasonable integer that is not lower than the actual value. e.g. $ echo 110 > /sys/devices/platform/led-controller-1/leds/d12/brightness $ .apply is not idempotent (ena=1 pol=0 1739692/4032985) -> (ena=1 pol=0 1739630/4032985) Co-developed-by: Zong Li <zong.li@sifive.com> Signed-off-by: Zong Li <zong.li@sifive.com> Signed-off-by: Nylon Chen <nylon.chen@sifive.com> --- drivers/pwm/pwm-sifive.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c index a586cfe4191b..bebcbebacccd 100644 --- a/drivers/pwm/pwm-sifive.c +++ b/drivers/pwm/pwm-sifive.c @@ -101,7 +101,7 @@ static void pwm_sifive_update_clock(struct pwm_sifive_ddata *ddata, /* As scale <= 15 the shift operation cannot overflow. */ num = (unsigned long long)NSEC_PER_SEC << (PWM_SIFIVE_CMPWIDTH + scale); - ddata->real_period = div64_ul(num, rate); + ddata->real_period = DIV_ROUND_UP_ULL(num, rate); dev_dbg(ddata->chip.dev, "New real_period = %u ns\n", ddata->real_period); } -- 2.43.0 ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v9 3/3] pwm: sifive: Fix the error in the idempotent test within the pwm_apply_state_debug function 2024-02-22 8:12 ` [PATCH v9 3/3] pwm: sifive: Fix the error in the idempotent test within the pwm_apply_state_debug function Nylon Chen @ 2024-03-18 18:17 ` Uwe Kleine-König 2024-04-02 2:01 ` Nylon Chen 0 siblings, 1 reply; 16+ messages in thread From: Uwe Kleine-König @ 2024-03-18 18:17 UTC (permalink / raw) To: Nylon Chen Cc: linux-riscv, devicetree, linux-kernel, linux-pwm, conor, robh+dt, krzysztof.kozlowski+dt, palmer, paul.walmsley, aou, thierry.reding, vincent.chen, zong.li, nylon7717 [-- Attachment #1: Type: text/plain, Size: 1541 bytes --] Hello, On Thu, Feb 22, 2024 at 04:12:31PM +0800, Nylon Chen wrote: > Round the result to the nearest whole number. This ensures that > real_period is always a reasonable integer that is not lower than the > actual value. > > e.g. > $ echo 110 > /sys/devices/platform/led-controller-1/leds/d12/brightness > $ .apply is not idempotent (ena=1 pol=0 1739692/4032985) -> (ena=1 pol=0 1739630/4032985) > > Co-developed-by: Zong Li <zong.li@sifive.com> > Signed-off-by: Zong Li <zong.li@sifive.com> > Signed-off-by: Nylon Chen <nylon.chen@sifive.com> > --- > drivers/pwm/pwm-sifive.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c > index a586cfe4191b..bebcbebacccd 100644 > --- a/drivers/pwm/pwm-sifive.c > +++ b/drivers/pwm/pwm-sifive.c > @@ -101,7 +101,7 @@ static void pwm_sifive_update_clock(struct pwm_sifive_ddata *ddata, > > /* As scale <= 15 the shift operation cannot overflow. */ > num = (unsigned long long)NSEC_PER_SEC << (PWM_SIFIVE_CMPWIDTH + scale); > - ddata->real_period = div64_ul(num, rate); > + ddata->real_period = DIV_ROUND_UP_ULL(num, rate); > dev_dbg(ddata->chip.dev, > "New real_period = %u ns\n", ddata->real_period); > } pwm_sifive_apply has a DIV64_U64_ROUND_CLOSEST(). I wonder if that needs adaption, too?! Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ | [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v9 3/3] pwm: sifive: Fix the error in the idempotent test within the pwm_apply_state_debug function 2024-03-18 18:17 ` Uwe Kleine-König @ 2024-04-02 2:01 ` Nylon Chen 2024-04-12 7:05 ` Uwe Kleine-König 0 siblings, 1 reply; 16+ messages in thread From: Nylon Chen @ 2024-04-02 2:01 UTC (permalink / raw) To: Uwe Kleine-König Cc: linux-riscv, devicetree, linux-kernel, linux-pwm, conor, robh+dt, krzysztof.kozlowski+dt, palmer, paul.walmsley, aou, thierry.reding, vincent.chen, zong.li, nylon7717 Uwe Kleine-König <u.kleine-koenig@pengutronix.de> 於 2024年3月19日 週二 上午2:17寫道: > > Hello, > > On Thu, Feb 22, 2024 at 04:12:31PM +0800, Nylon Chen wrote: > > Round the result to the nearest whole number. This ensures that > > real_period is always a reasonable integer that is not lower than the > > actual value. > > > > e.g. > > $ echo 110 > /sys/devices/platform/led-controller-1/leds/d12/brightness > > $ .apply is not idempotent (ena=1 pol=0 1739692/4032985) -> (ena=1 pol=0 1739630/4032985) > > > > Co-developed-by: Zong Li <zong.li@sifive.com> > > Signed-off-by: Zong Li <zong.li@sifive.com> > > Signed-off-by: Nylon Chen <nylon.chen@sifive.com> > > --- > > drivers/pwm/pwm-sifive.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c > > index a586cfe4191b..bebcbebacccd 100644 > > --- a/drivers/pwm/pwm-sifive.c > > +++ b/drivers/pwm/pwm-sifive.c > > @@ -101,7 +101,7 @@ static void pwm_sifive_update_clock(struct pwm_sifive_ddata *ddata, > > > > /* As scale <= 15 the shift operation cannot overflow. */ > > num = (unsigned long long)NSEC_PER_SEC << (PWM_SIFIVE_CMPWIDTH + scale); > > - ddata->real_period = div64_ul(num, rate); > > + ddata->real_period = DIV_ROUND_UP_ULL(num, rate); > > dev_dbg(ddata->chip.dev, > > "New real_period = %u ns\n", ddata->real_period); > > } Hi Uwe > > pwm_sifive_apply has a DIV64_U64_ROUND_CLOSEST(). I wonder if that needs > adaption, too?! According to my experiments, no adjustment is necessary. > > Best regards > Uwe > > -- > Pengutronix e.K. | Uwe Kleine-König | > Industrial Linux Solutions | https://www.pengutronix.de/ | ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v9 3/3] pwm: sifive: Fix the error in the idempotent test within the pwm_apply_state_debug function 2024-04-02 2:01 ` Nylon Chen @ 2024-04-12 7:05 ` Uwe Kleine-König 2024-12-24 8:34 ` Nylon Chen 0 siblings, 1 reply; 16+ messages in thread From: Uwe Kleine-König @ 2024-04-12 7:05 UTC (permalink / raw) To: Nylon Chen Cc: linux-riscv, devicetree, linux-kernel, linux-pwm, conor, robh+dt, krzysztof.kozlowski+dt, palmer, paul.walmsley, aou, thierry.reding, vincent.chen, zong.li, nylon7717 [-- Attachment #1: Type: text/plain, Size: 2182 bytes --] On Tue, Apr 02, 2024 at 10:01:39AM +0800, Nylon Chen wrote: > Uwe Kleine-König <u.kleine-koenig@pengutronix.de> 於 2024年3月19日 週二 上午2:17寫道: > > > > Hello, > > > > On Thu, Feb 22, 2024 at 04:12:31PM +0800, Nylon Chen wrote: > > > Round the result to the nearest whole number. This ensures that > > > real_period is always a reasonable integer that is not lower than the > > > actual value. > > > > > > e.g. > > > $ echo 110 > /sys/devices/platform/led-controller-1/leds/d12/brightness > > > $ .apply is not idempotent (ena=1 pol=0 1739692/4032985) -> (ena=1 pol=0 1739630/4032985) > > > > > > Co-developed-by: Zong Li <zong.li@sifive.com> > > > Signed-off-by: Zong Li <zong.li@sifive.com> > > > Signed-off-by: Nylon Chen <nylon.chen@sifive.com> > > > --- > > > drivers/pwm/pwm-sifive.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c > > > index a586cfe4191b..bebcbebacccd 100644 > > > --- a/drivers/pwm/pwm-sifive.c > > > +++ b/drivers/pwm/pwm-sifive.c > > > @@ -101,7 +101,7 @@ static void pwm_sifive_update_clock(struct pwm_sifive_ddata *ddata, > > > > > > /* As scale <= 15 the shift operation cannot overflow. */ > > > num = (unsigned long long)NSEC_PER_SEC << (PWM_SIFIVE_CMPWIDTH + scale); > > > - ddata->real_period = div64_ul(num, rate); > > > + ddata->real_period = DIV_ROUND_UP_ULL(num, rate); > > > dev_dbg(ddata->chip.dev, > > > "New real_period = %u ns\n", ddata->real_period); > > > } > Hi Uwe > > > > pwm_sifive_apply has a DIV64_U64_ROUND_CLOSEST(). I wonder if that needs > > adaption, too?! > According to my experiments, no adjustment is necessary. Did you enable PWM_DEBUG and tested with something like: seq 5000 100000 | while read p; do echo p > /sys/class/pwm/pwmchipX/pwmY/period; done and then verified that this test didn't result in kernel messages about wrong settings? Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ | [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v9 3/3] pwm: sifive: Fix the error in the idempotent test within the pwm_apply_state_debug function 2024-04-12 7:05 ` Uwe Kleine-König @ 2024-12-24 8:34 ` Nylon Chen 2024-12-27 15:39 ` Uwe Kleine-König 0 siblings, 1 reply; 16+ messages in thread From: Nylon Chen @ 2024-12-24 8:34 UTC (permalink / raw) To: Uwe Kleine-König Cc: Nylon Chen, linux-riscv, devicetree, linux-kernel, linux-pwm, conor, robh+dt, krzysztof.kozlowski+dt, palmer, paul.walmsley, aou, thierry.reding, vincent.chen, zong.li Uwe Kleine-König <u.kleine-koenig@pengutronix.de> 於 2024年4月12日 週五 下午3:05寫道: > > On Tue, Apr 02, 2024 at 10:01:39AM +0800, Nylon Chen wrote: > > Uwe Kleine-König <u.kleine-koenig@pengutronix.de> 於 2024年3月19日 週二 上午2:17寫道: > > > > > > Hello, > > > > > > On Thu, Feb 22, 2024 at 04:12:31PM +0800, Nylon Chen wrote: > > > > Round the result to the nearest whole number. This ensures that > > > > real_period is always a reasonable integer that is not lower than the > > > > actual value. > > > > > > > > e.g. > > > > $ echo 110 > /sys/devices/platform/led-controller-1/leds/d12/brightness > > > > $ .apply is not idempotent (ena=1 pol=0 1739692/4032985) -> (ena=1 pol=0 1739630/4032985) > > > > > > > > Co-developed-by: Zong Li <zong.li@sifive.com> > > > > Signed-off-by: Zong Li <zong.li@sifive.com> > > > > Signed-off-by: Nylon Chen <nylon.chen@sifive.com> > > > > --- > > > > drivers/pwm/pwm-sifive.c | 2 +- > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c > > > > index a586cfe4191b..bebcbebacccd 100644 > > > > --- a/drivers/pwm/pwm-sifive.c > > > > +++ b/drivers/pwm/pwm-sifive.c > > > > @@ -101,7 +101,7 @@ static void pwm_sifive_update_clock(struct pwm_sifive_ddata *ddata, > > > > > > > > /* As scale <= 15 the shift operation cannot overflow. */ > > > > num = (unsigned long long)NSEC_PER_SEC << (PWM_SIFIVE_CMPWIDTH + scale); > > > > - ddata->real_period = div64_ul(num, rate); > > > > + ddata->real_period = DIV_ROUND_UP_ULL(num, rate); > > > > dev_dbg(ddata->chip.dev, > > > > "New real_period = %u ns\n", ddata->real_period); > > > > } > > Hi Uwe > > > > > > pwm_sifive_apply has a DIV64_U64_ROUND_CLOSEST(). I wonder if that needs > > > adaption, too?! > > According to my experiments, no adjustment is necessary. > > Did you enable PWM_DEBUG and tested with something like: > > seq 5000 100000 | while read p; do echo p > /sys/class/pwm/pwmchipX/pwmY/period; done > Hi Uwe, I apologize for the significant delay in responding to your query, I've now completed a thorough verification of the PWM_DEBUG functionality. The Period Testing: seq 5000 5000 100000 | while read p; do echo $p > /sys/class/pwm/pwmchip0/pwm0/period echo "Testing period: $p" done The Duty Cycle Testing: for percent in 0 25 50 75 100; do duty=$((100000 * percent / 100)) echo $duty > /sys/class/pwm/pwmchip0/pwm0/duty_cycle done - All period values from 5000ns to 100000ns were applied successfully - Various duty cycle ratios were tested without issues - Monitored dmesg output during tests - no kernel messages about wrong settings were observed Let me know if you need any additional test data or have other parameters you'd like me to verify. > and then verified that this test didn't result in kernel messages about > wrong settings? > > Best regards > Uwe > > -- > Pengutronix e.K. | Uwe Kleine-König | > Industrial Linux Solutions | https://www.pengutronix.de/ | -- ========================================== sifive system software team 陳伯綸 Cell phone: 0989057854 E-mail: nylon7717@gmail.com ========================================== ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v9 3/3] pwm: sifive: Fix the error in the idempotent test within the pwm_apply_state_debug function 2024-12-24 8:34 ` Nylon Chen @ 2024-12-27 15:39 ` Uwe Kleine-König 2025-01-06 9:00 ` Nylon Chen 0 siblings, 1 reply; 16+ messages in thread From: Uwe Kleine-König @ 2024-12-27 15:39 UTC (permalink / raw) To: Nylon Chen Cc: Nylon Chen, linux-riscv, devicetree, linux-kernel, linux-pwm, conor, robh+dt, krzysztof.kozlowski+dt, palmer, paul.walmsley, aou, thierry.reding, vincent.chen, zong.li [-- Attachment #1: Type: text/plain, Size: 2907 bytes --] On Tue, Dec 24, 2024 at 04:34:53PM +0800, Nylon Chen wrote: > Uwe Kleine-König <u.kleine-koenig@pengutronix.de> 於 2024年4月12日 週五 下午3:05寫道: > > > > On Tue, Apr 02, 2024 at 10:01:39AM +0800, Nylon Chen wrote: > > > Uwe Kleine-König <u.kleine-koenig@pengutronix.de> 於 2024年3月19日 週二 上午2:17寫道: > > > > > > > > Hello, > > > > > > > > On Thu, Feb 22, 2024 at 04:12:31PM +0800, Nylon Chen wrote: > > > > > Round the result to the nearest whole number. This ensures that > > > > > real_period is always a reasonable integer that is not lower than the > > > > > actual value. > > > > > > > > > > e.g. > > > > > $ echo 110 > /sys/devices/platform/led-controller-1/leds/d12/brightness > > > > > $ .apply is not idempotent (ena=1 pol=0 1739692/4032985) -> (ena=1 pol=0 1739630/4032985) > > > > > > > > > > Co-developed-by: Zong Li <zong.li@sifive.com> > > > > > Signed-off-by: Zong Li <zong.li@sifive.com> > > > > > Signed-off-by: Nylon Chen <nylon.chen@sifive.com> > > > > > --- > > > > > drivers/pwm/pwm-sifive.c | 2 +- > > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > > > diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c > > > > > index a586cfe4191b..bebcbebacccd 100644 > > > > > --- a/drivers/pwm/pwm-sifive.c > > > > > +++ b/drivers/pwm/pwm-sifive.c > > > > > @@ -101,7 +101,7 @@ static void pwm_sifive_update_clock(struct pwm_sifive_ddata *ddata, > > > > > > > > > > /* As scale <= 15 the shift operation cannot overflow. */ > > > > > num = (unsigned long long)NSEC_PER_SEC << (PWM_SIFIVE_CMPWIDTH + scale); > > > > > - ddata->real_period = div64_ul(num, rate); > > > > > + ddata->real_period = DIV_ROUND_UP_ULL(num, rate); > > > > > dev_dbg(ddata->chip.dev, > > > > > "New real_period = %u ns\n", ddata->real_period); > > > > > } > > > Hi Uwe > > > > > > > > pwm_sifive_apply has a DIV64_U64_ROUND_CLOSEST(). I wonder if that needs > > > > adaption, too?! > > > According to my experiments, no adjustment is necessary. > > > > Did you enable PWM_DEBUG and tested with something like: > > > > seq 5000 100000 | while read p; do echo p > /sys/class/pwm/pwmchipX/pwmY/period; done > > > Hi Uwe, > I apologize for the significant delay in responding to your query, > I've now completed a thorough verification of the PWM_DEBUG > functionality. > > The Period Testing: > seq 5000 5000 100000 | while read p; do echo $p > > /sys/class/pwm/pwmchip0/pwm0/period echo "Testing period: $p" done > > The Duty Cycle Testing: > for percent in 0 25 50 75 100; do duty=$((100000 * percent / 100)) > echo $duty > /sys/class/pwm/pwmchip0/pwm0/duty_cycle done This is unlikely to find the issues that I have in mind. If doing ~100k assignments is too much, please keep the +1 step but restrict the interval. Best regards Uwe [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v9 3/3] pwm: sifive: Fix the error in the idempotent test within the pwm_apply_state_debug function 2024-12-27 15:39 ` Uwe Kleine-König @ 2025-01-06 9:00 ` Nylon Chen 2025-01-07 4:52 ` Uwe Kleine-König 0 siblings, 1 reply; 16+ messages in thread From: Nylon Chen @ 2025-01-06 9:00 UTC (permalink / raw) To: Uwe Kleine-König Cc: Nylon Chen, linux-riscv, devicetree, linux-kernel, linux-pwm, conor, robh+dt, krzysztof.kozlowski+dt, palmer, paul.walmsley, aou, thierry.reding, vincent.chen, zong.li Uwe Kleine-König <u.kleine-koenig@baylibre.com> 於 2024年12月27日 週五 下午11:39寫道: > > On Tue, Dec 24, 2024 at 04:34:53PM +0800, Nylon Chen wrote: > > Uwe Kleine-König <u.kleine-koenig@pengutronix.de> 於 2024年4月12日 週五 下午3:05寫道: > > > > > > On Tue, Apr 02, 2024 at 10:01:39AM +0800, Nylon Chen wrote: > > > > Uwe Kleine-König <u.kleine-koenig@pengutronix.de> 於 2024年3月19日 週二 上午2:17寫道: > > > > > > > > > > Hello, > > > > > > > > > > On Thu, Feb 22, 2024 at 04:12:31PM +0800, Nylon Chen wrote: > > > > > > Round the result to the nearest whole number. This ensures that > > > > > > real_period is always a reasonable integer that is not lower than the > > > > > > actual value. > > > > > > > > > > > > e.g. > > > > > > $ echo 110 > /sys/devices/platform/led-controller-1/leds/d12/brightness > > > > > > $ .apply is not idempotent (ena=1 pol=0 1739692/4032985) -> (ena=1 pol=0 1739630/4032985) > > > > > > > > > > > > Co-developed-by: Zong Li <zong.li@sifive.com> > > > > > > Signed-off-by: Zong Li <zong.li@sifive.com> > > > > > > Signed-off-by: Nylon Chen <nylon.chen@sifive.com> > > > > > > --- > > > > > > drivers/pwm/pwm-sifive.c | 2 +- > > > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > > > > > diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c > > > > > > index a586cfe4191b..bebcbebacccd 100644 > > > > > > --- a/drivers/pwm/pwm-sifive.c > > > > > > +++ b/drivers/pwm/pwm-sifive.c > > > > > > @@ -101,7 +101,7 @@ static void pwm_sifive_update_clock(struct pwm_sifive_ddata *ddata, > > > > > > > > > > > > /* As scale <= 15 the shift operation cannot overflow. */ > > > > > > num = (unsigned long long)NSEC_PER_SEC << (PWM_SIFIVE_CMPWIDTH + scale); > > > > > > - ddata->real_period = div64_ul(num, rate); > > > > > > + ddata->real_period = DIV_ROUND_UP_ULL(num, rate); > > > > > > dev_dbg(ddata->chip.dev, > > > > > > "New real_period = %u ns\n", ddata->real_period); > > > > > > } > > > > Hi Uwe > > > > > > > > > > pwm_sifive_apply has a DIV64_U64_ROUND_CLOSEST(). I wonder if that needs > > > > > adaption, too?! > > > > According to my experiments, no adjustment is necessary. > > > > > > Did you enable PWM_DEBUG and tested with something like: > > > > > > seq 5000 100000 | while read p; do echo p > /sys/class/pwm/pwmchipX/pwmY/period; done > > > > > Hi Uwe, > > I apologize for the significant delay in responding to your query, > > I've now completed a thorough verification of the PWM_DEBUG > > functionality. > > > > The Period Testing: > > seq 5000 5000 100000 | while read p; do echo $p > > > /sys/class/pwm/pwmchip0/pwm0/period echo "Testing period: $p" done > > > > The Duty Cycle Testing: > > for percent in 0 25 50 75 100; do duty=$((100000 * percent / 100)) > > echo $duty > /sys/class/pwm/pwmchip0/pwm0/duty_cycle done > > This is unlikely to find the issues that I have in mind. If doing ~100k > assignments is too much, please keep the +1 step but restrict the > interval. Hi Uwe, I have made the following adjustments based on your requirements. Does this align with what you had in mind? - period seq 5000 1 15000 | while read p; do echo $p > /sys/class/pwm/pwmchip0/pwm0/period echo "Testing period: $p" done - duty cycle for duty in $(seq 0 1 10000); do echo $duty > /sys/class/pwm/pwmchip0/pwm0/duty_cycle echo "Testing duty cycle: $duty" done > > Best regards > Uwe ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v9 3/3] pwm: sifive: Fix the error in the idempotent test within the pwm_apply_state_debug function 2025-01-06 9:00 ` Nylon Chen @ 2025-01-07 4:52 ` Uwe Kleine-König 2025-01-07 8:28 ` Nylon Chen 0 siblings, 1 reply; 16+ messages in thread From: Uwe Kleine-König @ 2025-01-07 4:52 UTC (permalink / raw) To: Nylon Chen Cc: Nylon Chen, linux-riscv, devicetree, linux-kernel, linux-pwm, conor, robh+dt, krzysztof.kozlowski+dt, palmer, paul.walmsley, aou, thierry.reding, vincent.chen, zong.li [-- Attachment #1: Type: text/plain, Size: 665 bytes --] Hello Nylon, On Mon, Jan 06, 2025 at 05:00:32PM +0800, Nylon Chen wrote: > Hi Uwe, I have made the following adjustments based on your > requirements. Does this align with what you had in mind? > - period > seq 5000 1 15000 | while read p; do echo $p > > /sys/class/pwm/pwmchip0/pwm0/period echo "Testing period: $p" done > > - duty cycle > for duty in $(seq 0 1 10000); do echo $duty > > /sys/class/pwm/pwmchip0/pwm0/duty_cycle echo "Testing duty cycle: > $duty" done That + doing the same test backwards (i.e. using seq 15000 -1 5000 for the period test and seq 10000 -1 0 for duty_cycle) should catch most rounding bugs. Best regards Uwe [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v9 3/3] pwm: sifive: Fix the error in the idempotent test within the pwm_apply_state_debug function 2025-01-07 4:52 ` Uwe Kleine-König @ 2025-01-07 8:28 ` Nylon Chen 0 siblings, 0 replies; 16+ messages in thread From: Nylon Chen @ 2025-01-07 8:28 UTC (permalink / raw) To: Uwe Kleine-König Cc: Nylon Chen, linux-riscv, devicetree, linux-kernel, linux-pwm, conor, robh+dt, krzysztof.kozlowski+dt, palmer, paul.walmsley, aou, thierry.reding, vincent.chen, zong.li Uwe Kleine-König <u.kleine-koenig@baylibre.com> 於 2025年1月7日 週二 下午12:52寫道: > > Hello Nylon, > > On Mon, Jan 06, 2025 at 05:00:32PM +0800, Nylon Chen wrote: > > Hi Uwe, I have made the following adjustments based on your > > requirements. Does this align with what you had in mind? > > - period > > seq 5000 1 15000 | while read p; do echo $p > > > /sys/class/pwm/pwmchip0/pwm0/period echo "Testing period: $p" done > > > > - duty cycle > > for duty in $(seq 0 1 10000); do echo $duty > > > /sys/class/pwm/pwmchip0/pwm0/duty_cycle echo "Testing duty cycle: > > $duty" done > > That + doing the same test backwards (i.e. using seq 15000 -1 5000 for > the period test and seq 10000 -1 0 for duty_cycle) should catch most > rounding bugs. > Hi Uwe, I understand what you mean now (testing must consider both backwards and forwards). Thank you for taking the time to explain it to me. > Best regards > Uwe ^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2025-01-07 8:28 UTC | newest] Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2024-02-22 8:12 [PATCH v9 0/3] Change PWM-controlled LED pin active mode and algorithm Nylon Chen 2024-02-22 8:12 ` [PATCH v9 1/3] riscv: dts: sifive: unleashed/unmatched: Remove PWM controlled LED's active-low properties Nylon Chen 2024-02-22 8:12 ` [PATCH v9 2/3] pwm: sifive: change the PWM algorithm Nylon Chen 2024-03-18 18:16 ` Uwe Kleine-König 2024-04-02 2:08 ` Nylon Chen 2024-04-12 2:07 ` Nylon Chen 2024-04-12 7:01 ` Uwe Kleine-König 2024-02-22 8:12 ` [PATCH v9 3/3] pwm: sifive: Fix the error in the idempotent test within the pwm_apply_state_debug function Nylon Chen 2024-03-18 18:17 ` Uwe Kleine-König 2024-04-02 2:01 ` Nylon Chen 2024-04-12 7:05 ` Uwe Kleine-König 2024-12-24 8:34 ` Nylon Chen 2024-12-27 15:39 ` Uwe Kleine-König 2025-01-06 9:00 ` Nylon Chen 2025-01-07 4:52 ` Uwe Kleine-König 2025-01-07 8:28 ` Nylon Chen
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®