From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Michael Walle <michael@walle.cc>
Cc: linux-gpio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org,
linux-pwm@vger.kernel.org, linux-watchdog@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <bgolaszewski@baylibre.com>,
Rob Herring <robh+dt@kernel.org>,
Jean Delvare <jdelvare@suse.com>,
Guenter Roeck <linux@roeck-us.net>,
Lee Jones <lee.jones@linaro.org>,
Thierry Reding <thierry.reding@gmail.com>,
Wim Van Sebroeck <wim@linux-watchdog.org>,
Shawn Guo <shawnguo@kernel.org>, Li Yang <leoyang.li@nxp.com>,
Thomas Gleixner <tglx@linutronix.de>,
Jason Cooper <jason@lakedaemon.net>,
Marc Zyngier <maz@kernel.org>, Mark Brown <broonie@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>, Pavel Machek <pavel@ucw.cz>
Subject: Re: [PATCH v9 06/13] pwm: add support for sl28cpld PWM controller
Date: Tue, 8 Sep 2020 10:12:27 +0200 [thread overview]
Message-ID: <20200908081227.mxumgqipyod6iltr@pengutronix.de> (raw)
In-Reply-To: <20200907213802.26745-7-michael@walle.cc>
[-- Attachment #1: Type: text/plain, Size: 3000 bytes --]
Hello,
just a bit of nitpicking left. If Lee is going to apply, I can care for
a followup patch if need be.
On Mon, Sep 07, 2020 at 11:37:55PM +0200, Michael Walle wrote:
> [..]
> +config PWM_SL28CPLD
> + tristate "Kontron sl28cpld PWM support"
> + depends on MFD_SL28CPLD || COMPILE_TEST
s/ / / (@Lee, maybe fixup during application?)
> + help
> + Generic PWM framework driver for board management controller
> + found on the Kontron sl28 CPLD.
> [...]
> +#define SL28CPLD_PWM_CLK 32000 /* 32 kHz */
> +#define SL28CPLD_PWM_MAX_DUTY_CYCLE(prescaler) (1 << (7 - (prescaler)))
> +#define SL28CPLD_PWM_PERIOD(prescaler) \
> + (NSEC_PER_SEC / SL28CPLD_PWM_CLK * SL28CPLD_PWM_MAX_DUTY_CYCLE(prescaler))
> +
> +/*
> + * We calculate the duty cycle like this:
> + * duty_cycle_ns = pwm_cycle_reg * max_period_ns / max_duty_cycle
> + *
> + * With
> + * max_period_ns = 1 << (7 - prescaler) / pwm_clk * NSEC_PER_SEC
> + * max_duty_cycle = 1 << (7 - prescaler)
> + * this then simplifies to:
> + * duty_cycle_ns = pwm_cycle_reg / pwm_clk * NSEC_PER_SEC
> + *
> + * NSEC_PER_SEC is a multiple of SL28CPLD_PWM_CLK, therefore we're not losing
> + * precision by doing the divison first.
The division you're talking about is NSEC_PER_SEC / pwm_clk which isn't
obvious in the formula in the line above. Maybe:
...
this then simplifies to:
duty_cycle_ns = NSEC_PER_SEC / SL28CPLD_PWM_CLK * pwm_cycle_reg
NSEC_PER_SEC is a multiple of SL28CPLD_PWM_CLK, therefor ...
to make it easier to understand the comment.
> + */
> +#define SL28CPLD_PWM_TO_DUTY_CYCLE(reg) \
> + (NSEC_PER_SEC / SL28CPLD_PWM_CLK * (reg))
> +#define SL28CPLD_PWM_FROM_DUTY_CYCLE(duty_cycle) \
> + (DIV_ROUND_DOWN_ULL((duty_cycle), NSEC_PER_SEC / SL28CPLD_PWM_CLK))
> [...]
> + /*
> + * To avoid glitches when we switch the prescaler, we have to make sure
> + * we have a valid duty cycle for the new mode.
> + *
> + * Take the current prescaler (or the current period length) into
> + * account to decide whether we have to write the duty cycle or the new
> + * prescaler first. If the period length is decreasing we have to
> + * write the duty cycle first.
> + */
> + write_duty_cycle_first = pwm->state.period > state->period;
> +
> + if (write_duty_cycle_first) {
> + ret = sl28cpld_pwm_write(priv, SL28CPLD_PWM_CYCLE, cycle);
> + if (ret)
> + return ret;
> + }
> +
> + ret = sl28cpld_pwm_write(priv, SL28CPLD_PWM_CTRL, ctrl);
> + if (ret)
> + return ret;
> +
> + if (!write_duty_cycle_first) {
> + ret = sl28cpld_pwm_write(priv, SL28CPLD_PWM_CYCLE, cycle);
> + if (ret)
> + return ret;
> + }
Nice! I didn't spend the necessary brain cycles to confirm this
algorithm, but it seems you did :-)
> +
> + return 0;
> +}
> [...]
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 --]
next prev parent reply other threads:[~2020-09-08 8:13 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-07 21:37 [PATCH v9 00/13] Add support for Kontron sl28cpld Michael Walle
2020-09-07 21:37 ` [PATCH v9 01/13] mfd: add simple regmap based I2C driver Michael Walle
2020-09-07 21:37 ` [PATCH v9 02/13] dt-bindings: mfd: Add bindings for sl28cpld Michael Walle
2020-09-07 21:37 ` [PATCH v9 03/13] mfd: simple-mfd-i2c: add sl28cpld support Michael Walle
2020-09-07 21:37 ` [PATCH v9 04/13] irqchip: add sl28cpld interrupt controller support Michael Walle
2020-09-07 21:37 ` [PATCH v9 05/13] watchdog: add support for sl28cpld watchdog Michael Walle
2020-09-07 21:37 ` [PATCH v9 06/13] pwm: add support for sl28cpld PWM controller Michael Walle
2020-09-08 8:12 ` Uwe Kleine-König [this message]
2020-09-07 21:37 ` [PATCH v9 07/13] gpio: add support for the sl28cpld GPIO controller Michael Walle
2020-09-07 21:37 ` [PATCH v9 08/13] hwmon: add support for the sl28cpld hardware monitoring controller Michael Walle
2020-09-07 21:37 ` [PATCH v9 09/13] arm64: dts: freescale: sl28: enable sl28cpld Michael Walle
2020-09-07 21:37 ` [PATCH v9 10/13] arm64: dts: freescale: sl28: map GPIOs to input events Michael Walle
2020-09-07 21:38 ` [PATCH v9 11/13] arm64: dts: freescale: sl28: enable LED support Michael Walle
2020-09-09 9:25 ` Pavel Machek
2020-10-04 9:58 ` Pavel Machek
2020-09-07 21:38 ` [PATCH v9 12/13] arm64: dts: freescale: sl28: enable fan support Michael Walle
2020-09-07 21:38 ` [PATCH v9 13/13] arm64: defconfig: enable the sl28cpld board management controller Michael Walle
2020-09-08 7:42 ` [PATCH v9 00/13] Add support for Kontron sl28cpld Lee Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200908081227.mxumgqipyod6iltr@pengutronix.de \
--to=u.kleine-koenig@pengutronix.de \
--cc=andriy.shevchenko@linux.intel.com \
--cc=bgolaszewski@baylibre.com \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=jason@lakedaemon.net \
--cc=jdelvare@suse.com \
--cc=lee.jones@linaro.org \
--cc=leoyang.li@nxp.com \
--cc=linus.walleij@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=maz@kernel.org \
--cc=michael@walle.cc \
--cc=pavel@ucw.cz \
--cc=robh+dt@kernel.org \
--cc=shawnguo@kernel.org \
--cc=tglx@linutronix.de \
--cc=thierry.reding@gmail.com \
--cc=will@kernel.org \
--cc=wim@linux-watchdog.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).