linux-watchdog.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Cc: Wim Van Sebroeck <wim@linux-watchdog.org>,
	Guenter Roeck <linux@roeck-us.net>,
	Linux Watchdog Mailing List <linux-watchdog@vger.kernel.org>,
	Linux-Renesas <linux-renesas-soc@vger.kernel.org>
Subject: Re: [PATCH] watchdog: renesas_wdt: Add a few cycles delay
Date: Mon, 3 Jun 2019 13:04:46 +0200	[thread overview]
Message-ID: <CAMuHMdUKugUiqAi=o14BTG5Tihq_H04DOs0ixkGEHxc7vo9uCQ@mail.gmail.com> (raw)
In-Reply-To: <OSAPR01MB3089AE3893A8DA4D77F34413D8140@OSAPR01MB3089.jpnprd01.prod.outlook.com>

Hi Shimoda-san,

On Mon, Jun 3, 2019 at 12:28 PM Yoshihiro Shimoda
<yoshihiro.shimoda.uh@renesas.com> wrote:
> > From: Geert Uytterhoeven, Sent: Monday, June 3, 2019 6:59 PM
> > On Mon, Jun 3, 2019 at 11:31 AM Yoshihiro Shimoda
> > <yoshihiro.shimoda.uh@renesas.com> wrote:
> > > According to the hardware manual of R-Car Gen2 and Gen3,
> > > software should wait a few RLCK cycles as following:
> > >  - Delay 2 cycles before setting watchdog counter.
> > >  - Delay 3 cycles before disabling module clock.
> > >
> > > So, this patch adds such delays.
> > >
> > > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> >
> > Thanks for your patch!
>
> Thank you for your review!
>
> > > --- a/drivers/watchdog/renesas_wdt.c
> > > +++ b/drivers/watchdog/renesas_wdt.c
> >
> > > @@ -70,6 +71,16 @@ static int rwdt_init_timeout(struct watchdog_device *wdev)
> > >         return 0;
> > >  }
> > >
> > > +static void rwdt_wait(struct rwdt_priv *priv, unsigned long cycles)
> >
> > "unsigned int" should be sufficiently large.
>
> I got it.
>
> > > +{
> > > +       unsigned long periods, delays;
> > > +
> > > +       periods = DIV_ROUND_UP(priv->clk_rate, cycles);
> >
> > Shouldn't the above be a division with rounding down (i.e. a plain C
> > division), instead of a division with rounding up?
>
> I have no idea which is the correct way (rounding down vs rounding up here).
> At least, I tried to use rounding down before submitting patch and then
> the result seemed the same. So, I submitted this patch with rounding up
> (because the next step also used rounding up...).

If you round up periods, it will decrease the delay, which may become
too small.
If you round up delays, it will increase the delay, which doesn't hurt.

> > > +       delays = DIV_ROUND_UP(1000000UL, periods);
> >
> > Given cycles is always a small number, accuracy can be improved, and one
> > division can be avoided, by calculation this as:
> >
> >     delays = DIV_ROUND_UP(cycles * 1000000 /  priv->clk_rate);
>
> Thank you for your suggest! I think so.
> It should be "s/ \//,/" like below though :)

>         delays = DIV_ROUND_UP(cycles * 1000000, priv->clk_rate);

Oops, indeed. Sorry for that silly mistake.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

  reply	other threads:[~2019-06-03 11:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-03  9:25 [PATCH] watchdog: renesas_wdt: Add a few cycles delay Yoshihiro Shimoda
2019-06-03  9:58 ` Geert Uytterhoeven
2019-06-03 10:28   ` Yoshihiro Shimoda
2019-06-03 11:04     ` Geert Uytterhoeven [this message]
2019-06-05  4:56       ` Yoshihiro Shimoda
2019-06-05  5:04 Yoshihiro Shimoda
2019-06-05  5:21 ` Yoshihiro Shimoda

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='CAMuHMdUKugUiqAi=o14BTG5Tihq_H04DOs0ixkGEHxc7vo9uCQ@mail.gmail.com' \
    --to=geert@linux-m68k.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=wim@linux-watchdog.org \
    --cc=yoshihiro.shimoda.uh@renesas.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;
as well as URLs for NNTP newsgroup(s).