Messages in this thread | | | Date | Sun, 29 Nov 2020 19:10:50 +0100 | From | Uwe Kleine-König <> | Subject | Re: [PATCH v2] pwm: bcm2835: Support apply function for atomic configuration |
| |
On Sat, Nov 28, 2020 at 01:02:06PM +0100, Lino Sanfilippo wrote: > Use the newer apply function of pwm_ops instead of config, enable, disable > and set_polarity. > > This guarantees atomic changes of the pwm controller configuration. It also > reduces the size of the driver. > > This has been tested on a Raspberry PI 4. > > v2: Fixed compiler error
Changelog between review rounds go to below the tripple-dash below.
> Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de> > --- > drivers/pwm/pwm-bcm2835.c | 64 ++++++++++++++++------------------------------- > 1 file changed, 21 insertions(+), 43 deletions(-) > > diff --git a/drivers/pwm/pwm-bcm2835.c b/drivers/pwm/pwm-bcm2835.c > index 6841dcf..dad7443 100644 > --- a/drivers/pwm/pwm-bcm2835.c > +++ b/drivers/pwm/pwm-bcm2835.c > @@ -58,13 +58,14 @@ static void bcm2835_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) > writel(value, pc->base + PWM_CONTROL); > } > > -static int bcm2835_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, > - int duty_ns, int period_ns) > +static int bcm2835_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, > + const struct pwm_state *state) > { > + > struct bcm2835_pwm *pc = to_bcm2835_pwm(chip); > unsigned long rate = clk_get_rate(pc->clk); > unsigned long scaler; > - u32 period; > + u32 value; > > if (!rate) { > dev_err(pc->dev, "failed to get clock rate\n"); > @@ -72,65 +73,42 @@ static int bcm2835_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, > } > > scaler = DIV_ROUND_CLOSEST(NSEC_PER_SEC, rate); > - period = DIV_ROUND_CLOSEST(period_ns, scaler); > + /* set period */ > + value = DIV_ROUND_CLOSEST_ULL(state->period, scaler);
You're storing an unsigned long long (i.e. 64 bits) in an u32. If you are sure that this won't discard relevant bits, please explain this in a comment for the cursory reader.
Also note that round_closed is probably wrong, as .apply() is supposed to round down the period to the next achievable period. (But fixing this has to do done in a separate patch.)
Best regards Uwe
-- Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ | [unhandled content-type:application/pgp-signature] | |