From: Heiko Schocher <hs@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 2/4] arm, at91: add function for waiting if reset ends
Date: Mon, 04 Nov 2013 10:11:58 +0100 [thread overview]
Message-ID: <527764DE.50508@denx.de> (raw)
In-Reply-To: <20131104090320.652303811E2@gemini.denx.de>
Hello Wolfgang,
Am 04.11.2013 10:03, schrieb Wolfgang Denk:
> Dear Heiko,
>
> In message<1383547247-7017-3-git-send-email-hs@denx.de> you wrote:
>> add function for waiting if reset ends. If reset never ends,
>> timeout and print an error message.
>
> I think this patch needs some rework.
>
> First, I think we should point out in the commit mnessage that we're
> not talking about a general hardware reset here (how could the code
> be running if the CPU was helt in reset?), but that we are actually
> talking about the PHY reset.
>
>> arch/arm/cpu/arm926ejs/at91/reset.c | 15 +++++++++++++++
>> arch/arm/include/asm/arch-at91/at91_rstc.h | 1 +
>> 2 files changed, 16 insertions(+)
>
> Second, while I highly appreciate your effort to identify and factor
> out common code, we should then actually use this new common function
> to replace all the occurrences of that common code - i. e. I would
> expect to see modifications at least in the following files:
>
> board/BuS/vl_ma2sc/vl_ma2sc.c
> board/afeb9260/afeb9260.c
> board/atmel/at91sam9260ek/at91sam9260ek.c
> board/atmel/at91sam9263ek/at91sam9263ek.c
> board/atmel/at91sam9m10g45ek/at91sam9m10g45ek.c
> board/bluewater/snapper9260/snapper9260.c
> board/calao/sbc35_a9g20/sbc35_a9g20.c
> board/eukrea/cpu9260/cpu9260.c
> board/taskit/stamp9g20/stamp9g20.c
Yep, full ack, do this in the next version
> Third, I think we should not only replace the waiting for the end og
> the PHY reset loop (and add a timeout to it), but instead we should
> factor out the whole block of code performing the PHY reset. From
> what I've seen, the following piece of code is repeated identical
> (except for formatting) in all these files:
>
> erstl = readl(&rstc->mr)& AT91_RSTC_MR_ERSTL_MASK;
>
> /* Need to reset PHY -> 500ms reset */
> writel(AT91_RSTC_KEY | AT91_RSTC_MR_ERSTL(13) |
> AT91_RSTC_MR_URSTEN,&rstc->mr);
>
> writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST,&rstc->cr);
>
> /* Wait for end hardware reset */
> while (!(readl(&rstc->sr)& AT91_RSTC_SR_NRSTL))
> ;
>
> /* Restore NRST value */
> writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN,
> &rstc->mr);
>
> So we should factor out all of this (and probably call the function
> at91_phy_reset() then?).
Yes.
> Are thwere any AT91 experts out there who actually understand this
> code? In my (very limited) understanding, NRST is the "microcon-
> troller reset pin", so "Wait for end hardware reset" (and polling
> AT91_RSTC_SR_NRSTL) does not make much sense - how could this code be
> running if the microprocessor was helt in reset? After asserting the
> AT91_RSTC_CR_EXTRST (external reset) we are probably waiting for
> something else?
Good question!
>> +void at91_wait_for_reset(int timeout)
>> +{
>> + struct at91_rstc *rstc = (struct at91_rstc *)ATMEL_BASE_RSTC;
>> + int count = 0;
>> +
>> + while (!(readl(&rstc->sr)& AT91_RSTC_SR_NRSTL)) {
>> + if (count>= timeout) {
>> + printf("reset timeout.\n");
>> + return;
>> + }
>> + udelay(10);
>> + timeout++;
>> + }
>> +}
>
> Finally, you should fix the code so that it really times out - this
> code will not, as you initialize count as zero and then wait for
> "count>= timeout", but you never change "count"; instead you
> increment "timeout", so you might have to wait for up to INT_MAX * 10
> us or about 6 hours...
Good catch! Thanks
bye,
Heiko
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
next prev parent reply other threads:[~2013-11-04 9:11 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-04 6:40 [U-Boot] [PATCH v2 0/4] arm, at91: support for the taurus, axm and corvus board Heiko Schocher
2013-11-04 6:40 ` [U-Boot] [PATCH v2 1/4] at91: add defines for reset type Heiko Schocher
2013-11-04 8:16 ` Andreas Bießmann
2013-11-04 19:41 ` [U-Boot] [U-Boot,v2,1/4] " Andreas Bießmann
2013-11-04 6:40 ` [U-Boot] [PATCH v2 2/4] arm, at91: add function for waiting if reset ends Heiko Schocher
2013-11-04 8:20 ` Andreas Bießmann
2013-11-04 9:03 ` Wolfgang Denk
2013-11-04 9:11 ` Heiko Schocher [this message]
2013-11-04 10:35 ` Andreas Bießmann
2013-11-04 6:40 ` [U-Boot] [PATCH v2 3/4] arm, at91: add Siemens board taurus and axm Heiko Schocher
2013-11-04 8:43 ` Andreas Bießmann
2013-11-04 9:09 ` Heiko Schocher
2013-11-04 11:04 ` Andreas Bießmann
2013-11-04 6:40 ` [U-Boot] [PATCH v2 4/4] arm, at91: add siemens corvus board Heiko Schocher
2013-11-04 8:53 ` Andreas Bießmann
2013-11-04 9:53 ` Heiko Schocher
2013-11-04 10:15 ` Andreas Bießmann
2013-11-04 10:32 ` Heiko Schocher
2013-11-04 10:51 ` Andreas Bießmann
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=527764DE.50508@denx.de \
--to=hs@denx.de \
--cc=u-boot@lists.denx.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