linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: u.kleine-koenig@pengutronix.de (Uwe Kleine-König)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 03/15] ARM: mxs: Add reset routines
Date: Thu, 2 Dec 2010 08:27:50 +0100	[thread overview]
Message-ID: <20101202072750.GM32355@pengutronix.de> (raw)
In-Reply-To: <AANLkTinavvbQFGQhcAZF+ZBV1OuiZYu0XaBYSM7YuuKG@mail.gmail.com>

Hi Shawn,

On Thu, Dec 02, 2010 at 02:02:39PM +0800, Shawn Guo wrote:
> Hi Uwe,
> 
> 2010/11/30 Uwe Kleine-K?nig <u.kleine-koenig@pengutronix.de>:
> > Hello,
> >
> [...]
> >
> >> + ? ? /* Poll CLKGATE set */
> >> + ? ? timeout = 0x400;
> >> + ? ? while ((!(__raw_readl(reset_addr) & MXS_MODULE_CLKGATE)) && --timeout)
> >> + ? ? ? ? ? ? /* nothing */;
> >> + ? ? if (!timeout)
> >> + ? ? ? ? ? ? goto error;
> >> +
> >> + ? ? /* Clear SFTRST */
> >> + ? ? val = __raw_readl(reset_addr);
> >> + ? ? val &= ~MXS_MODULE_SFTRST;
> >> + ? ? __raw_writel(val, reset_addr);
> >> + ? ? /* Wait 1us */
> >> + ? ? udelay(1);
> >> + ? ? /* Poll SFTRST cleared */
> >> + ? ? timeout = 0x400;
> >> + ? ? while ((__raw_readl(reset_addr) & MXS_MODULE_SFTRST) && --timeout)
> >> + ? ? ? ? ? ? /* nothing */;
> >> + ? ? if (!timeout)
> >> + ? ? ? ? ? ? goto error;
> >> +
> >> + ? ? /* Clear CLKGATE */
> >> + ? ? val = __raw_readl(reset_addr);
> >> + ? ? val &= ~MXS_MODULE_CLKGATE;
> >> + ? ? __raw_writel(val, reset_addr);
> >> + ? ? /* Wait 1us */
> >> + ? ? udelay(1);
> >> + ? ? /* Poll CLKGATE cleared */
> >> + ? ? timeout = 0x400;
> >> + ? ? while ((__raw_readl(reset_addr) & MXS_MODULE_CLKGATE) && --timeout)
> >> + ? ? ? ? ? ? /* nothing */;
> >> + ? ? if (!timeout)
> >> + ? ? ? ? ? ? goto error;
> >
> > There are quite some repetitions in this function. ?If you could get it
> > down to something that looks like
> >
> > ? ? ? ?clear SFTRST
> > ? ? ? ?udelay
> > ? ? ? ?poll SFTRST cleared
> >
> > ? ? ? ?clear CLKGATE
> > ? ? ? ?set SFTRST
> > ? ? ? ?udelay
> > ? ? ? ?poll CLKGATE set
> >
> > ? ? ? ?clear SFTRST
> > ? ? ? ?udelay
> > ? ? ? ?poll SFTRST cleared
> >
> > ? ? ? ?clear CLKGATE
> > ? ? ? ?udelay
> > ? ? ? ?poll CLKGATE cleared
> >
> > it's IMHO better than the comment above. ?If "clear CLKGATE" and "set
> > SFTRST" can be done in a single step this might be done like that:
> >
> > ? ? ? ?/* comment describing setmask_poll */
> > ? ? ? ?static int setmask_poll(void __iomem *addr, u32 set, u32 mask,
> > ? ? ? ? ? ? ? ?u32 pollval, u32 pollmask, u32 *curval)
> > ? ? ? ?{
> > ? ? ? ? ? ? ? ?int timeout = 0x400;
> >
> > ? ? ? ? ? ? ? ?*curval &= ~mask;
> > ? ? ? ? ? ? ? ?*curval |= set;
> > ? ? ? ? ? ? ? ?__raw_writel(*curval, addr)
> >
> > ? ? ? ? ? ? ? ?/*
> > ? ? ? ? ? ? ? ? * some nice comment about 1us being a good idea
> > ? ? ? ? ? ? ? ? */
> > ? ? ? ? ? ? ? ?udelay(1);
> >
> > ? ? ? ? ? ? ? ?do {
> > ? ? ? ? ? ? ? ? ? ? ? ?*curval = __raw_readl(addr);
> > ? ? ? ? ? ? ? ? ? ? ? ?if ((*curval & pollmask) == pollval)
> > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?return 0;
> >
> > ? ? ? ? ? ? ? ?} while(--timeout);
> >
> > ? ? ? ? ? ? ? ?return 1;
> > ? ? ? ?}
> >
> > ? ? ? ?int mxs_reset_block(void __iomem *reset_addr)
> > ? ? ? ?{
> > ? ? ? ? ? ? ? ?u32 val = __raw_readl(reset_addr);
> > ? ? ? ? ? ? ? ?int ret;
> >
> > ? ? ? ? ? ? ? ?/* clear SFTRST and poll SFTRST becoming clear */
> > ? ? ? ? ? ? ? ?ret = setmask_poll(reset_addr,
> > ? ? ? ? ? ? ? ? ? ? ? ?0, MXS_MODULE_SFTRST,
> > ? ? ? ? ? ? ? ? ? ? ? ?0, MXS_MODULE_SFTRST, &val);
> > ? ? ? ? ? ? ? ?if (ret)
> > ? ? ? ? ? ? ? ? ? ? ? ?goto error;
> >
> > ? ? ? ? ? ? ? ?/* clear CLKGATE, set SFTRST and poll CLKGATE becoming set */
> > ? ? ? ? ? ? ? ?ret = setmask_poll(reset_addr,
> > ? ? ? ? ? ? ? ? ? ? ? ?MXS_MODULE_SFTRST, MXS_MODULE_SFTRST | MXS_MODULE_CLKGATE,
> > ? ? ? ? ? ? ? ? ? ? ? ?0, MXS_MODULE_CLKGATE, &val);
> > ? ? ? ? ? ? ? ?if (ret)
> > ? ? ? ? ? ? ? ? ? ? ? ?goto error;
> >
> > ? ? ? ? ? ? ? ?...
> > ? ? ? ?}
> >
> > Well, not very nice, but IMHO better that your code. ?Maybe
> > mxs_reset_block fits in a Terminal that way without decreasing the font
> > size :-)
> >
> I checked designer about doing "clear CLKGATE" and "set SFTRST" in a
> single step, and got the following feedback.
> 
> "Per HW design, it is not safe to get those two done by write once
> time. By two step write, one instruction period interval can be
> ensured at least for clock  enabling before sync. Soft reset.  Your
> code is only once time write in fact, so it shall not be equal to two
> write operation."
> 
> In this case, how do the following changes look to you?
> 
> /*
>  * Clear the bit and poll it cleared, the bit has to be
>  * SFTRST(bit 31) or CLKGATE (bit 30) of block control register.
for the function it doesn't have to be one of these bits.  Maybe:

	Clear the bit and poll it cleared.  This is usually called with
	a reset address and mask being either SFTRST(bit 31) or CLKGATE
	(bit 30).

>  */
> static int clear_poll_bit(void __iomem *addr, u32 mask)
> {
>         int timeout = 0x400;
> 
>         /* clear the bit */
>         __raw_writel(mask, addr + MXS_CLR_ADDR);
ah, so there is a clr register, that's nice.

> 
>         /*
>          * SFTRST needs 3 GPMI clocks to settle, the reference manual
>          * recommends to wait 1us.
>          */
>         udelay(1);
> 
>         /* poll the bit becoming clear */
>         while ((__raw_readl(addr) & mask) && --timeout)
>                 /* nothing */;
> 
>         if (unlikely(!timeout))
>                 return 1;
> 
>         return 0;
return !timeout; ?

> }
> 
> int mxs_reset_block(void __iomem *reset_addr)
> {
>         int ret;
>         int timeout = 0x400;
> 
>         /* clear and poll SFTRST */
>         ret = clear_poll_bit(reset_addr, MXS_MODULE_SFTRST);
>         if (ret)
>                 goto error;
> 
>         /* clear CLKGATE */
>         __raw_writel(MXS_MODULE_CLKGATE, reset_addr + MXS_CLR_ADDR);
>         /* set SFTRST to reset the block */
>         __raw_writel(MXS_MODULE_SFTRST, reset_addr + MXS_SET_ADDR);
>         udelay(1);
>         /* poll CLKGATE becoming set */
>         while ((!(__raw_readl(reset_addr) & MXS_MODULE_CLKGATE)) && --timeout)
>                 /* nothing */;
>         if (unlikely(!timeout))
>                 goto error;
> 
>         /* clear and poll SFTRST */
>         ret = clear_poll_bit(reset_addr, MXS_MODULE_SFTRST);
>         if (ret)
>                 goto error;
> 
>         /* clear and poll CLKGATE */
>         ret = clear_poll_bit(reset_addr, MXS_MODULE_CLKGATE);
>         if (ret)
>                 goto error;
> 
	return 0;

> error:
>         pr_err("%s(%p): module reset timeout\n", __func__, reset_addr);
>         return -ETIMEDOUT;
> }
Other than that it looks much better IMHO.

Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

  reply	other threads:[~2010-12-02  7:27 UTC|newest]

Thread overview: 146+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-26  6:48 [PATCH 00/15] ARM: mxs: Add initial support for MX23 and MX28 Shawn Guo
2010-11-26  6:49 ` [PATCH 01/15] ARM: mxs: Add core definitions Shawn Guo
2010-11-26 11:30   ` Uwe Kleine-König
2010-11-29  7:21     ` Shawn Guo
2010-11-26  6:49 ` [PATCH 02/15] ARM: mxs: Add helper definition and function Shawn Guo
2010-11-26  6:49 ` [PATCH 03/15] ARM: mxs: Add reset routines Shawn Guo
2010-11-26  9:31   ` Lothar Waßmann
2010-11-26  9:57     ` Uwe Kleine-König
2010-11-26 10:38       ` Lothar Waßmann
2010-11-26 11:32         ` Uwe Kleine-König
2010-11-26 12:53           ` Lothar Waßmann
2010-11-29  9:25           ` [PATCH] prevent 'BUG: sleeping function called from invalid context' in arch_reset() Lothar Waßmann
2010-11-29  9:58             ` Uwe Kleine-König
2010-12-06 16:13               ` Uwe Kleine-König
2010-11-26 14:16         ` [PATCH 03/15] ARM: mxs: Add reset routines Xinyu Chen
2010-11-26 14:38           ` Lothar Waßmann
2010-11-26  6:49 ` [PATCH 04/15] ARM: mxs: Add interrupt support Shawn Guo
2010-11-30 13:56   ` Uwe Kleine-König
2010-11-30 17:02     ` Russell King - ARM Linux
2010-12-01 11:23     ` Shawn Guo
2010-11-26  6:49 ` [PATCH 05/15] ARM: mxs: Add low-level debug UART support Shawn Guo
2010-11-30 15:48   ` Uwe Kleine-König
2010-11-26  6:49 ` [PATCH 06/15] ARM: mxs: Add timer support Shawn Guo
2010-11-30 16:13   ` Uwe Kleine-König
2010-12-02 14:44     ` Shawn Guo
2010-12-02 15:20       ` Thomas Gleixner
2010-12-02 16:48       ` Uwe Kleine-König
2010-11-26  6:49 ` [PATCH 07/15] ARM: mxs: Add gpio support Shawn Guo
2010-11-30 16:21   ` Uwe Kleine-König
2010-11-26  6:49 ` [PATCH 08/15] ARM: mxs: Add iomux support Shawn Guo
2010-11-30 16:32   ` Uwe Kleine-König
2010-11-26  6:49 ` [PATCH 09/15] ARM: mxs: Add clock support Shawn Guo
2010-11-30 16:39   ` Uwe Kleine-König
2010-12-07 13:09     ` Shawn Guo
2010-12-07 13:33       ` Uwe Kleine-König
2010-12-07 13:53         ` Shawn Guo
2010-12-02 15:07   ` Uwe Kleine-König
2010-12-03  5:07     ` Shawn Guo
2010-11-26  6:49 ` [PATCH 10/15] ARM: mxs: Add static memory mapping Shawn Guo
2010-11-26  6:49 ` [PATCH 11/15] ARM: mxs: Dynamically allocate duart devices Shawn Guo
2010-11-26  6:49 ` [PATCH 12/15] ARM: mxs: Dynamically allocate fec devices Shawn Guo
2010-11-30 20:01   ` Uwe Kleine-König
2010-11-26  6:49 ` [PATCH 13/15] ARM: mxs: Add initial mx23evk support Shawn Guo
2010-11-30 20:02   ` Uwe Kleine-König
2010-11-26  6:49 ` [PATCH 14/15] ARM: mxs: Add initial mx28evk support Shawn Guo
2010-11-30 20:06   ` Uwe Kleine-König
2010-11-26  6:49 ` [PATCH 15/15] ARM: mxs: Add build configuration for mxs Shawn Guo
2010-11-30 20:08   ` Uwe Kleine-König
2010-11-29 11:59 ` [PATCH v2 01/15] ARM: mxs: Add core definitions Shawn Guo
2010-11-30  9:21   ` Uwe Kleine-König
2010-11-29 11:59 ` [PATCH v2 02/15] ARM: mxs: Add helper definition and function Shawn Guo
2010-11-29 11:59 ` [PATCH v2 03/15] ARM: mxs: Add reset routines Shawn Guo
2010-11-30 10:25   ` Uwe Kleine-König
2010-12-01 10:45     ` Shawn Guo
2010-12-01 10:59       ` Uwe Kleine-König
2010-12-01 11:34         ` Shawn Guo
2010-12-02  6:02     ` Shawn Guo
2010-12-02  7:27       ` Uwe Kleine-König [this message]
2010-12-02  9:40   ` Uwe Kleine-König
2010-12-02 10:16     ` Shawn Guo
2010-11-29 11:59 ` [PATCH v2 06/15] ARM: mxs: Add timer support Shawn Guo
2010-11-29 11:59 ` [PATCH v2 10/15] ARM: mxs: Add static memory mapping Shawn Guo
2010-11-29 11:59 ` [PATCH v2 15/15] ARM: mxs: Add build configuration for mxs Shawn Guo
2010-12-07 16:31 ` [PATCH v3 01/15] ARM: mxs: Add core definitions Shawn Guo
2010-12-07 20:18   ` Uwe Kleine-König
2010-12-08  4:50     ` Shawn Guo
2010-12-08  9:17       ` Uwe Kleine-König
2010-12-07 16:31 ` [PATCH v3 03/15] ARM: mxs: Add reset routines Shawn Guo
2010-12-07 20:27   ` Uwe Kleine-König
2010-12-08  7:33   ` Lothar Waßmann
2010-12-08 20:31     ` Uwe Kleine-König
2010-12-09  8:51       ` Shawn Guo
2010-12-09  8:55         ` Uwe Kleine-König
2010-12-07 16:31 ` [PATCH v2 04/15] ARM: mxs: Add interrupt support Shawn Guo
2010-12-07 21:03   ` Uwe Kleine-König
2010-12-08  8:27     ` Shawn Guo
2010-12-08  9:39       ` Uwe Kleine-König
2010-12-08 10:46         ` Shawn Guo
2010-12-08 12:09           ` Uwe Kleine-König
2010-12-08 12:31             ` Shawn Guo
2010-12-08  8:56     ` Shawn Guo
2010-12-08  9:14       ` Uwe Kleine-König
2010-12-08  8:24   ` Lothar Waßmann
2010-12-07 16:31 ` [PATCH v2 05/15] ARM: mxs: Add low-level debug UART support Shawn Guo
2010-12-08 20:27   ` Uwe Kleine-König
2010-12-09  2:02     ` Shawn Guo
2010-12-09  8:42       ` Uwe Kleine-König
2010-12-07 16:31 ` [PATCH v3 06/15] ARM: mxs: Add timer support Shawn Guo
2010-12-07 21:18   ` Uwe Kleine-König
2010-12-08  5:58     ` Shawn Guo
2010-12-08  9:25       ` Uwe Kleine-König
2010-12-08  8:30   ` Lothar Waßmann
2010-12-08  9:31     ` Uwe Kleine-König
2010-12-07 16:31 ` [PATCH v2 07/15] ARM: mxs: Add gpio support Shawn Guo
2010-12-08  7:21   ` Lothar Waßmann
2010-12-07 16:31 ` [PATCH v2 08/15] ARM: mxs: Add iomux support Shawn Guo
2010-12-08  7:25   ` Lothar Waßmann
2010-12-08 10:52     ` Shawn Guo
2010-12-08 10:56       ` Uwe Kleine-König
2010-12-08 11:29         ` Shawn Guo
2010-12-08 11:32           ` Lothar Waßmann
2010-12-09  6:15             ` Shawn Guo
2010-12-09  8:43               ` Uwe Kleine-König
2010-12-07 16:31 ` [PATCH v2 09/15] ARM: mxs: Add clock support Shawn Guo
2010-12-08 20:57   ` Uwe Kleine-König
2010-12-09  1:44     ` Shawn Guo
2010-12-09  8:41   ` Uwe Kleine-König
2010-12-09 10:04     ` Shawn Guo
2010-12-09 10:30     ` Shawn Guo
2010-12-07 16:32 ` [PATCH v2 12/15] ARM: mxs: Dynamically allocate fec devices Shawn Guo
2010-12-07 16:32 ` [PATCH v2 13/15] ARM: mxs: Add initial mx23evk support Shawn Guo
2010-12-07 16:32 ` [PATCH v2 14/15] ARM: mxs: Add initial mx28evk support Shawn Guo
2010-12-08 20:28   ` Uwe Kleine-König
2010-12-09  7:04     ` Shawn Guo
2010-12-09  8:32       ` Uwe Kleine-König
2010-12-09  9:03         ` Shawn Guo
2010-12-09  9:37           ` Uwe Kleine-König
2010-12-09 10:17             ` Shawn Guo
2010-12-09 12:27               ` Lothar Waßmann
2010-12-09 13:38                 ` Shawn Guo
2010-12-09 13:54                   ` Shawn Guo
2010-12-07 16:32 ` [PATCH v3 15/15] ARM: mxs: Add build configuration for mxs Shawn Guo
2010-12-10 14:51   ` Uwe Kleine-König
2010-12-10 15:05     ` Shawn Guo
2010-12-09 15:12 ` [PATCH v4 01/15] ARM: mxs: Add core definitions Shawn Guo
2010-12-09 17:37   ` Russell King - ARM Linux
2010-12-09 15:12 ` [PATCH v3 02/15] ARM: mxs: Add helper definition and function Shawn Guo
2010-12-09 15:12 ` [PATCH v4 03/15] ARM: mxs: Add reset routines Shawn Guo
2010-12-09 15:12 ` [PATCH v3 04/15] ARM: mxs: Add interrupt support Shawn Guo
2010-12-09 15:12 ` [PATCH v3 05/15] ARM: mxs: Add low-level debug UART support Shawn Guo
2010-12-09 15:12 ` [PATCH v4 06/15] ARM: mxs: Add timer support Shawn Guo
2010-12-09 15:12 ` [PATCH v3 07/15] ARM: mxs: Add gpio support Shawn Guo
2010-12-09 16:47   ` Lothar Waßmann
2010-12-10  7:06     ` Shawn Guo
2010-12-10  7:23       ` Shawn Guo
2010-12-10  8:11         ` Uwe Kleine-König
2010-12-10 15:32           ` Shawn Guo
2010-12-09 15:12 ` [PATCH v3 08/15] ARM: mxs: Add iomux support Shawn Guo
2010-12-09 16:12   ` Lothar Waßmann
2010-12-09 15:12 ` [PATCH v3 09/15] ARM: mxs: Add clock support Shawn Guo
2010-12-09 21:11   ` Uwe Kleine-König
2010-12-09 15:12 ` [PATCH v2 10/15] ARM: mxs: Add static memory mapping Shawn Guo
2010-12-09 15:12 ` [PATCH v2 11/15] ARM: mxs: Dynamically allocate duart devices Shawn Guo
2010-12-09 15:12 ` [PATCH v3 12/15] ARM: mxs: Dynamically allocate fec devices Shawn Guo
2010-12-09 15:12 ` [PATCH v3 13/15] ARM: mxs: Add initial mx23evk support Shawn Guo
2010-12-09 15:12 ` [PATCH v3 14/15] ARM: mxs: Add initial mx28evk support Shawn Guo

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=20101202072750.GM32355@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.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).