linux-watchdog.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marek Behun <marek.behun@nic.cz>
To: Guenter Roeck <linux@roeck-us.net>
Cc: linux-watchdog@vger.kernel.org, wim@linux-watchdog.org
Subject: Re: [PATCH 1/2] watchdog: Add support for Armada 37xx CPU watchdog
Date: Sat, 1 Sep 2018 02:29:30 +0200	[thread overview]
Message-ID: <20180901022930.64ef4062@nic.cz> (raw)
In-Reply-To: <20180830191226.GB6752@roeck-us.net>

Hello Guenter,
I just read in the specification that software does not need to
do debouncing, because when low is read, high is latched into 32 bit
flip flop so that it can be read correctly.
So the correct way is to read low first, then high, and that's it.
I shall write a comment describing this into new code.
Marek

On Thu, 30 Aug 2018 12:12:26 -0700
Guenter Roeck <linux@roeck-us.net> wrote:

> On Thu, Aug 30, 2018 at 08:50:04PM +0200, Marek Behun wrote:
> > > > > +static u64 get_counter_value(struct armada_37xx_watchdog
> > > > > *dev) +{
> > > > > +	u64 val;
> > > > > +
> > > > > +	val = readl(dev->reg + CNTR_COUNT_HIGH);
> > > > > +	val = (val << 32) | readl(dev->reg +
> > > > > CNTR_COUNT_LOW);      
> > > > 
> > > > Is this guaranteed to be consistent ? What happens if there is a
> > > > 32-bit wrap between those two operations ?    
> > > 
> > > hmmm. The address is not divisible by 8, so I can't use
> > > readq :( what do you propose?  
> > 
> > What do you think of this solution?
> > 
> > u64 val;
> > u32 low1, low2;
> > 
> > low1 = readl(dev->reg + CNTR_COUNT_LOW);
> > val = readl(dev->reg + CNTR_COUNT_HIGH);
> > low2 = readl(dev->reg + CNTR_COUNT_LOW);
> > 
> > /*
> >  * If low jumped in this short time more than 2^31, a wrap probably
> >  * occured. Read high again.
> >  */
> > if (low2 - low1 > 0x80000000)
> > 	val = readl(dev->reg + CNTR_COUNT_HIGH);
> > val = (val << 32) | low2;  
> 
> Yes, that is one option. The other would be to read high again
> all the time and repeat reading low if high changed on the second
> read of high.
> 
> 	high1 = readl(dev->reg + CNTR_COUNT_HIGH);
> 	low = readl(dev->reg + CNTR_COUNT_LOW);
> 	high2 = readl(dev->reg + CNTR_COUNT_HIGH);
> 	if (high2 != high1)
> 		low = readl(dev->reg + CNTR_COUNT_LOW);
> 	val = (high2 << 32) | low;
> 
> There is no ambiguity in this case: We _know_ that
> a wrap occurred if high1 and high2 are different.
> 
> Guenter

  reply	other threads:[~2018-09-01  4:40 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-30 14:22 [PATCH 1/2] watchdog: Add support for Armada 37xx CPU watchdog Marek Behún
2018-08-30 14:22 ` [PATCH 2/2] arm64: dts: marvell: armada-37xx: add nodes to support watchdog Marek Behún
2018-08-30 14:28 ` [PATCH 1/2] watchdog: Add support for Armada 37xx CPU watchdog Marek Behun
2018-08-30 14:40   ` Guenter Roeck
2018-08-30 16:28 ` Guenter Roeck
2018-08-30 18:42   ` Marek Behun
2018-08-30 18:50     ` Marek Behun
2018-08-30 19:12       ` Guenter Roeck
2018-09-01  0:29         ` Marek Behun [this message]
2018-09-01  0:47           ` Guenter Roeck
2018-09-02 20:12             ` Marek Behun
2018-09-03  0:55               ` Guenter Roeck
2018-08-30 19:07     ` Guenter Roeck

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=20180901022930.64ef4062@nic.cz \
    --to=marek.behun@nic.cz \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --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).