From: Thierry Reding <thierry.reding@gmail.com>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Fabrice Gasnier <fabrice.gasnier@st.com>, linux-pwm@vger.kernel.org
Subject: Re: [PATCH 2/3] pwm: stm32: Remove confusing bitmask
Date: Wed, 16 Oct 2019 11:50:42 +0200 [thread overview]
Message-ID: <20191016095042.GB1303817@ulmo> (raw)
In-Reply-To: <20191016083107.fetprdj7k52hkdvy@pengutronix.de>
[-- Attachment #1: Type: text/plain, Size: 2455 bytes --]
On Wed, Oct 16, 2019 at 10:31:07AM +0200, Uwe Kleine-König wrote:
> On Wed, Oct 16, 2019 at 09:38:41AM +0200, Thierry Reding wrote:
> > Both BKP bits are set in the BDTR register and the code relies on the
> > mask used during write to make sure only one of them is written. Since
> > this isn't immediately obvious, a comment is needed to explain it. The
> > same can be achieved by making explicit what happens, so add another
> > temporary variable that contains only the one bit that is actually ORed
> > into the register and get rid of the comment.
> >
> > Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
> > ---
> > drivers/pwm/pwm-stm32.c | 10 ++++------
> > 1 file changed, 4 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/pwm/pwm-stm32.c b/drivers/pwm/pwm-stm32.c
> > index b12fb11b7a55..8f1f3371e1dd 100644
> > --- a/drivers/pwm/pwm-stm32.c
> > +++ b/drivers/pwm/pwm-stm32.c
> > @@ -493,26 +493,24 @@ static const struct pwm_ops stm32pwm_ops = {
> > static int stm32_pwm_set_breakinput(struct stm32_pwm *priv,
> > int index, int level, int filter)
> > {
> > - u32 bke, shift, mask, bdtr;
> > + u32 bke, bkp, shift, mask, bdtr;
> >
> > if (index == 0) {
> > bke = TIM_BDTR_BKE;
> > + bkp = TIM_BDTR_BKP;
> > shift = TIM_BDTR_BKF_SHIFT;
> > mask = TIM_BDTR_BKE | TIM_BDTR_BKP | TIM_BDTR_BKF;
> > } else {
> > bke = TIM_BDTR_BK2E;
> > + bkp = TIM_BDTR_BK2P;
> > shift = TIM_BDTR_BK2F_SHIFT;
> > mask = TIM_BDTR_BK2E | TIM_BDTR_BK2P | TIM_BDTR_BK2F;
>
> Assuming in the else branch index is always 1, the following would be
> IMHO nicer:
>
> #define TIM_BDTR_BKE(i) BIT(12 + 12 * (i))
> #define TIM_BDTR_BKP(i) BIT(13 + 12 * (i))
> #define TIM_BDTR_BKF_SHIFT(i) (16 + 4 * (i))
>
> ..
>
> bke = TIM_BDTR_BKE(index);
> bkp = TIM_BDTR_BKP(index);
I had thought about that, but ultimately decided against it because
the original defines might match exactly what's in the datasheet, so
there's some value to keep the originals.
I suppose one other alternative would be to let the macros be and do the
computations in the driver instead, something like:
bke = TIM_BDTR_BKE << (index * 12);
bkp = TIM_BDTR_BKP << (index * 12);
bkf = TIM_BDTR_BKF << (index * 4);
But yeah, I agree that having the parameters be part of the macros is
even better.
Fabrice, any objection to redefining the macros as above?
Thierry
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2019-10-16 9:50 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-16 7:38 [PATCH 0/3] pwm: stm32: Minor cleanups Thierry Reding
2019-10-16 7:38 ` [PATCH 1/3] pwm: stm32: Remove clutter from ternary operator Thierry Reding
2019-10-16 8:26 ` Uwe Kleine-König
2019-10-16 9:30 ` Thierry Reding
2019-10-16 7:38 ` [PATCH 2/3] pwm: stm32: Remove confusing bitmask Thierry Reding
2019-10-16 8:31 ` Uwe Kleine-König
2019-10-16 9:50 ` Thierry Reding [this message]
2019-10-16 10:20 ` Fabrice Gasnier
2019-10-16 10:52 ` Uwe Kleine-König
2019-10-16 7:38 ` [PATCH 3/3] pwm: stm32: Pass breakinput instead of its values Thierry Reding
2019-10-16 8:33 ` [PATCH 0/3] pwm: stm32: Minor cleanups Uwe Kleine-König
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=20191016095042.GB1303817@ulmo \
--to=thierry.reding@gmail.com \
--cc=fabrice.gasnier@st.com \
--cc=linux-pwm@vger.kernel.org \
--cc=u.kleine-koenig@pengutronix.de \
/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