Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
From: Erik Schumacher <erik.schumacher@iris-sensing.com>
To: "u.kleine-koenig@baylibre.com" <u.kleine-koenig@baylibre.com>
Cc: "kernel@pengutronix.de" <kernel@pengutronix.de>,
	"thierry.reding@gmail.com" <thierry.reding@gmail.com>,
	"s.hauer@pengutronix.de" <s.hauer@pengutronix.de>,
	"festevam@gmail.com" <festevam@gmail.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"shawnguo@kernel.org" <shawnguo@kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"imx@lists.linux.dev" <imx@lists.linux.dev>,
	"linux-pwm@vger.kernel.org" <linux-pwm@vger.kernel.org>
Subject: Re: [PATCH v2] pwm: imx-tpm: Use correct MODULO value for EPWM mode
Date: Fri, 25 Oct 2024 07:25:50 +0000	[thread overview]
Message-ID: <6d884afde9d41b6efff7be5f820f8121f38e8321.camel@iris-sensing.com> (raw)
In-Reply-To: <wqjwdjqsjn5yngbkdpbinwtonxdpugy6n6nide7fcodhpto4hh@7yxigtrvvu2n>

Hello,

thanks for the review.

Am Donnerstag, dem 24.10.2024 um 23:01 +0200 schrieb Uwe Kleine-König:
> Hello,
> 
> [dropping anson.huang@nxp.com from Cc]
> 
> On Thu, Oct 24, 2024 at 06:41:07AM +0000, Erik Schumacher wrote:
> > The modulo register defines the period of the edge-aligned PWM mode
> > (which is the only mode implemented). The reference manual states:
> > "The EPWM period is determined by (MOD + 0001h) ..." So the value that
> > is written to the MOD register must therefore be one less than the
> > calculated period length.
> > A correct MODULO value is particularly relevant if the PWM has to output
> > a high frequency due to a low period value.
> > 
> > Fixes: 738a1cfec2ed ("pwm: Add i.MX TPM PWM driver support")
> > Cc: stable@vger.kernel.org
> > 
> > Signed-off-by: Erik Schumacher <erik.schumacher@iris-sensing.com>
> 
> No empty line between these trailer lines please.

Noted for v3!

> 
> > diff --git a/drivers/pwm/pwm-imx-tpm.c b/drivers/pwm/pwm-imx-tpm.c
> > index 96ea343856f0..a05b66ffe208 100644
> > --- a/drivers/pwm/pwm-imx-tpm.c
> > +++ b/drivers/pwm/pwm-imx-tpm.c
> > @@ -106,7 +106,7 @@ static int pwm_imx_tpm_round_state(struct pwm_chip *chip,
> >  	p->prescale = prescale;
> >  
> >  	period_count = (clock_unit + ((1 << prescale) >> 1)) >> prescale;
> > -	p->mod = period_count;
> > +	p->mod = period_count - 1;
> 
> This looks bogus if period_count is 0.
> 

That's true. It can only be 0 if someone is requesting a period from
the PWM that is lower than the period of the clock feeding the PWM.
But, it would be an invalid config and returning -EINVAL there seems to
be the right thing (instead of underflowing the integer). I will add
such a check.

> Best regards
> Uwe

Kind regards
Erik

      reply	other threads:[~2024-10-25  7:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-24  6:41 [PATCH v2] pwm: imx-tpm: Use correct MODULO value for EPWM mode Erik Schumacher
2024-10-24 21:01 ` Uwe Kleine-König
2024-10-25  7:25   ` Erik Schumacher [this message]

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=6d884afde9d41b6efff7be5f820f8121f38e8321.camel@iris-sensing.com \
    --to=erik.schumacher@iris-sensing.com \
    --cc=festevam@gmail.com \
    --cc=imx@lists.linux.dev \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    --cc=thierry.reding@gmail.com \
    --cc=u.kleine-koenig@baylibre.com \
    /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