All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Lothar Waßmann" <LW@KARO-electronics.de>
To: Shawn Guo <shawn.guo@linaro.org>
Cc: rtc-linux@googlegroups.com,
	Andrew Morton <akpm@linux-foundation.org>,
	Alessandro Zummo <a.zummo@towertech.it>,
	Kim Phillips <kim.phillips@freescale.com>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Stephen Boyd <sboyd@codeaurora.org>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] rtc: snvs: improve timeout handling in snvs_rtc_enable()
Date: Sat, 18 Aug 2012 15:14:04 +0200	[thread overview]
Message-ID: <20527.38172.621130.368019@ipc1.ka-ro> (raw)

Shawn Guo writes:
> On Sat, Aug 18, 2012 at 10:10:08AM +0200, Lothar Waßmann wrote:
> > If snvs_rtc_enable() happens to be descheduled for a period longer
> > than the timout period, a timeout may be indicated even if the RTC
> > status has changed meanwhile. Force a status read at the end of the
> > timeout period to prevent bogus timeout errors.
> > 
> > 
> > Signed-off-by: Lothar Waßmann <LW@KARO-electronics.de>
> > ---
> >  drivers/rtc/rtc-snvs.c |   22 +++++++++++++---------
> >  1 files changed, 13 insertions(+), 9 deletions(-)
> > 
> >  Compile tested only due to lack of HW.
> 
> Tested-by: Shawn Guo <shawn.guo@linaro.org>
> 
> A small nitpick below.
> 
> > 
> > diff --git a/drivers/rtc/rtc-snvs.c b/drivers/rtc/rtc-snvs.c
> > index 912f116..dc921b2 100644
> > --- a/drivers/rtc/rtc-snvs.c
> > +++ b/drivers/rtc/rtc-snvs.c
> > @@ -81,6 +81,13 @@ static void rtc_write_sync_lp(void __iomem *ioaddr)
> >  	}
> >  }
> >  
> > +static int snvs_rtc_enable_done(int enable, void __iomem *addr)
> 
> Can we rename parameter "addr" to "ioaddr" and put it before "enable",
> also change "enable" to bool?
> 
OK. The resulting assembler code of the patch below is identical to
the previous version of this patch.


Signed-off-by: Lothar Waßmann <LW@KARO-electronics.de>
Tested-by: Shawn Guo <shawn.guo@linaro.org>
---
 drivers/rtc/rtc-snvs.c |   22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/drivers/rtc/rtc-snvs.c b/drivers/rtc/rtc-snvs.c
index 912f116..a757cb9 100644
--- a/drivers/rtc/rtc-snvs.c
+++ b/drivers/rtc/rtc-snvs.c
@@ -81,6 +81,13 @@ static void rtc_write_sync_lp(void __iomem *ioaddr)
 	}
 }
 
+static int snvs_rtc_enable_done(void __iomem *ioaddr, bool enable)
+{
+	u32 lpcr = readl(ioaddr + SNVS_LPCR);
+
+	return enable ^ !(lpcr & SNVS_LPCR_SRTC_ENV);
+}
+
 static int snvs_rtc_enable(struct snvs_rtc_data *data, bool enable)
 {
 	unsigned long timeout = jiffies + msecs_to_jiffies(1);
@@ -99,18 +106,15 @@ static int snvs_rtc_enable(struct snvs_rtc_data *data, bool enable)
 	spin_unlock_irqrestore(&data->lock, flags);
 
 	while (1) {
-		lpcr = readl(data->ioaddr + SNVS_LPCR);
+		if (snvs_rtc_enable_done(data->ioaddr, enable))
+			break;
 
-		if (enable) {
-			if (lpcr & SNVS_LPCR_SRTC_ENV)
-				break;
-		} else {
-			if (!(lpcr & SNVS_LPCR_SRTC_ENV))
+		if (time_after(jiffies, timeout)) {
+			if (snvs_rtc_enable_done(data->ioaddr, enable))
 				break;
+			else
+				return -ETIMEDOUT;
 		}
-
-		if (time_after(jiffies, timeout))
-			return -ETIMEDOUT;
 	}
 
 	return 0;

WARNING: multiple messages have this Message-ID (diff)
From: LW@KARO-electronics.de (Lothar Waßmann)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] rtc: snvs: improve timeout handling in snvs_rtc_enable()
Date: Sat, 18 Aug 2012 15:14:04 +0200	[thread overview]
Message-ID: <20527.38172.621130.368019@ipc1.ka-ro> (raw)
In-Reply-To: <20120818124652.GH24242@S2101-09.ap.freescale.net>

Shawn Guo writes:
> On Sat, Aug 18, 2012 at 10:10:08AM +0200, Lothar Wa?mann wrote:
> > If snvs_rtc_enable() happens to be descheduled for a period longer
> > than the timout period, a timeout may be indicated even if the RTC
> > status has changed meanwhile. Force a status read at the end of the
> > timeout period to prevent bogus timeout errors.
> > 
> > 
> > Signed-off-by: Lothar Wa?mann <LW@KARO-electronics.de>
> > ---
> >  drivers/rtc/rtc-snvs.c |   22 +++++++++++++---------
> >  1 files changed, 13 insertions(+), 9 deletions(-)
> > 
> >  Compile tested only due to lack of HW.
> 
> Tested-by: Shawn Guo <shawn.guo@linaro.org>
> 
> A small nitpick below.
> 
> > 
> > diff --git a/drivers/rtc/rtc-snvs.c b/drivers/rtc/rtc-snvs.c
> > index 912f116..dc921b2 100644
> > --- a/drivers/rtc/rtc-snvs.c
> > +++ b/drivers/rtc/rtc-snvs.c
> > @@ -81,6 +81,13 @@ static void rtc_write_sync_lp(void __iomem *ioaddr)
> >  	}
> >  }
> >  
> > +static int snvs_rtc_enable_done(int enable, void __iomem *addr)
> 
> Can we rename parameter "addr" to "ioaddr" and put it before "enable",
> also change "enable" to bool?
> 
OK. The resulting assembler code of the patch below is identical to
the previous version of this patch.


Signed-off-by: Lothar Wa?mann <LW@KARO-electronics.de>
Tested-by: Shawn Guo <shawn.guo@linaro.org>
---
 drivers/rtc/rtc-snvs.c |   22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/drivers/rtc/rtc-snvs.c b/drivers/rtc/rtc-snvs.c
index 912f116..a757cb9 100644
--- a/drivers/rtc/rtc-snvs.c
+++ b/drivers/rtc/rtc-snvs.c
@@ -81,6 +81,13 @@ static void rtc_write_sync_lp(void __iomem *ioaddr)
 	}
 }
 
+static int snvs_rtc_enable_done(void __iomem *ioaddr, bool enable)
+{
+	u32 lpcr = readl(ioaddr + SNVS_LPCR);
+
+	return enable ^ !(lpcr & SNVS_LPCR_SRTC_ENV);
+}
+
 static int snvs_rtc_enable(struct snvs_rtc_data *data, bool enable)
 {
 	unsigned long timeout = jiffies + msecs_to_jiffies(1);
@@ -99,18 +106,15 @@ static int snvs_rtc_enable(struct snvs_rtc_data *data, bool enable)
 	spin_unlock_irqrestore(&data->lock, flags);
 
 	while (1) {
-		lpcr = readl(data->ioaddr + SNVS_LPCR);
+		if (snvs_rtc_enable_done(data->ioaddr, enable))
+			break;
 
-		if (enable) {
-			if (lpcr & SNVS_LPCR_SRTC_ENV)
-				break;
-		} else {
-			if (!(lpcr & SNVS_LPCR_SRTC_ENV))
+		if (time_after(jiffies, timeout)) {
+			if (snvs_rtc_enable_done(data->ioaddr, enable))
 				break;
+			else
+				return -ETIMEDOUT;
 		}
-
-		if (time_after(jiffies, timeout))
-			return -ETIMEDOUT;
 	}
 
 	return 0;
-- 
1.7.2.5


Lothar Wa?mann
-- 
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra?e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch?ftsf?hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info at karo-electronics.de
___________________________________________________________

             reply	other threads:[~2012-08-18 13:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-18 13:14 Lothar Waßmann [this message]
2012-08-18 13:14 ` [PATCH] rtc: snvs: improve timeout handling in snvs_rtc_enable() Lothar Waßmann
2015-05-10 21:42 ` [rtc-linux] " Alexandre Belloni
2015-05-10 21:42   ` Alexandre Belloni
  -- strict thread matches above, loose matches on Subject: below --
2012-08-18  8:10 Lothar Waßmann
2012-08-18 12:46 ` Shawn Guo
2012-09-18 23:07 ` Andrew Morton

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=20527.38172.621130.368019@ipc1.ka-ro \
    --to=lw@karo-electronics.de \
    --cc=a.zummo@towertech.it \
    --cc=akpm@linux-foundation.org \
    --cc=kim.phillips@freescale.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=rtc-linux@googlegroups.com \
    --cc=s.hauer@pengutronix.de \
    --cc=sboyd@codeaurora.org \
    --cc=shawn.guo@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.