linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rtc: msm6242: Remove unneeded msm6242_set()/msm6242_clear() functions
@ 2019-11-16 11:46 Kars de Jong
  2019-11-18 14:19 ` Alexandre Belloni
  2019-11-18 14:19 ` Geert Uytterhoeven
  0 siblings, 2 replies; 3+ messages in thread
From: Kars de Jong @ 2019-11-16 11:46 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni
  Cc: linux-rtc, linux-kernel, Kars de Jong, Geert Uytterhoeven

The msm6242_set()/msm6242_clear() functions are used when writing to Control
Register D to set or clear the HOLD bit when reading the current time from
the RTC.

Doing this with a read-modify-write cycle will potentially clear an
interrupt condition which occurs between the read and the write.

The datasheet states the following about this:

  When writing the HOLD or 30 second adjust bits of register D, it is
  necessary to write the IRQ FLAG bit to a "1".

Since the only other bits in the register are the 30 second adjust bit
(which is not used) and the BUSY bit (which is read-only), the
read-modify-write cycle can be replaced by a simple write with the IRQ FLAG
bit set to 1 and the other bits (except HOLD) set to 0.

Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Tested-by: Kars de Jong <jongk@linux-m68k.org>
Signed-off-by: Kars de Jong <jongk@linux-m68k.org>
---
 drivers/rtc/rtc-msm6242.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/drivers/rtc/rtc-msm6242.c b/drivers/rtc/rtc-msm6242.c
index b1f2bedee77e..80e364baac53 100644
--- a/drivers/rtc/rtc-msm6242.c
+++ b/drivers/rtc/rtc-msm6242.c
@@ -88,28 +88,16 @@ static inline void msm6242_write(struct msm6242_priv *priv, unsigned int val,
 	__raw_writel(val, &priv->regs[reg]);
 }
 
-static inline void msm6242_set(struct msm6242_priv *priv, unsigned int val,
-			       unsigned int reg)
-{
-	msm6242_write(priv, msm6242_read(priv, reg) | val, reg);
-}
-
-static inline void msm6242_clear(struct msm6242_priv *priv, unsigned int val,
-				 unsigned int reg)
-{
-	msm6242_write(priv, msm6242_read(priv, reg) & ~val, reg);
-}
-
 static void msm6242_lock(struct msm6242_priv *priv)
 {
 	int cnt = 5;
 
-	msm6242_set(priv, MSM6242_CD_HOLD, MSM6242_CD);
+	msm6242_write(priv, MSM6242_CD_HOLD|MSM6242_CD_IRQ_FLAG, MSM6242_CD);
 
 	while ((msm6242_read(priv, MSM6242_CD) & MSM6242_CD_BUSY) && cnt) {
-		msm6242_clear(priv, MSM6242_CD_HOLD, MSM6242_CD);
+		msm6242_write(priv, MSM6242_CD_IRQ_FLAG, MSM6242_CD);
 		udelay(70);
-		msm6242_set(priv, MSM6242_CD_HOLD, MSM6242_CD);
+		msm6242_write(priv, MSM6242_CD_HOLD|MSM6242_CD_IRQ_FLAG, MSM6242_CD);
 		cnt--;
 	}
 
@@ -120,7 +108,7 @@ static void msm6242_lock(struct msm6242_priv *priv)
 
 static void msm6242_unlock(struct msm6242_priv *priv)
 {
-	msm6242_clear(priv, MSM6242_CD_HOLD, MSM6242_CD);
+	msm6242_write(priv, MSM6242_CD_IRQ_FLAG, MSM6242_CD);
 }
 
 static int msm6242_read_time(struct device *dev, struct rtc_time *tm)
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] rtc: msm6242: Remove unneeded msm6242_set()/msm6242_clear() functions
  2019-11-16 11:46 [PATCH] rtc: msm6242: Remove unneeded msm6242_set()/msm6242_clear() functions Kars de Jong
@ 2019-11-18 14:19 ` Alexandre Belloni
  2019-11-18 14:19 ` Geert Uytterhoeven
  1 sibling, 0 replies; 3+ messages in thread
From: Alexandre Belloni @ 2019-11-18 14:19 UTC (permalink / raw)
  To: Kars de Jong
  Cc: Alessandro Zummo, linux-rtc, linux-kernel, Geert Uytterhoeven

On 16/11/2019 12:46:20+0100, Kars de Jong wrote:
> The msm6242_set()/msm6242_clear() functions are used when writing to Control
> Register D to set or clear the HOLD bit when reading the current time from
> the RTC.
> 
> Doing this with a read-modify-write cycle will potentially clear an
> interrupt condition which occurs between the read and the write.
> 
> The datasheet states the following about this:
> 
>   When writing the HOLD or 30 second adjust bits of register D, it is
>   necessary to write the IRQ FLAG bit to a "1".
> 
> Since the only other bits in the register are the 30 second adjust bit
> (which is not used) and the BUSY bit (which is read-only), the
> read-modify-write cycle can be replaced by a simple write with the IRQ FLAG
> bit set to 1 and the other bits (except HOLD) set to 0.
> 
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Tested-by: Kars de Jong <jongk@linux-m68k.org>
> Signed-off-by: Kars de Jong <jongk@linux-m68k.org>
> ---
>  drivers/rtc/rtc-msm6242.c | 20 ++++----------------
>  1 file changed, 4 insertions(+), 16 deletions(-)
> 
Applied, thanks.

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] rtc: msm6242: Remove unneeded msm6242_set()/msm6242_clear() functions
  2019-11-16 11:46 [PATCH] rtc: msm6242: Remove unneeded msm6242_set()/msm6242_clear() functions Kars de Jong
  2019-11-18 14:19 ` Alexandre Belloni
@ 2019-11-18 14:19 ` Geert Uytterhoeven
  1 sibling, 0 replies; 3+ messages in thread
From: Geert Uytterhoeven @ 2019-11-18 14:19 UTC (permalink / raw)
  To: Kars de Jong
  Cc: Alessandro Zummo, Alexandre Belloni, linux-rtc,
	Linux Kernel Mailing List

On Sat, Nov 16, 2019 at 12:46 PM Kars de Jong <jongk@linux-m68k.org> wrote:
> The msm6242_set()/msm6242_clear() functions are used when writing to Control
> Register D to set or clear the HOLD bit when reading the current time from
> the RTC.
>
> Doing this with a read-modify-write cycle will potentially clear an
> interrupt condition which occurs between the read and the write.
>
> The datasheet states the following about this:
>
>   When writing the HOLD or 30 second adjust bits of register D, it is
>   necessary to write the IRQ FLAG bit to a "1".
>
> Since the only other bits in the register are the 30 second adjust bit
> (which is not used) and the BUSY bit (which is read-only), the
> read-modify-write cycle can be replaced by a simple write with the IRQ FLAG
> bit set to 1 and the other bits (except HOLD) set to 0.
>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Tested-by: Kars de Jong <jongk@linux-m68k.org>
> Signed-off-by: Kars de Jong <jongk@linux-m68k.org>

Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-11-18 14:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-16 11:46 [PATCH] rtc: msm6242: Remove unneeded msm6242_set()/msm6242_clear() functions Kars de Jong
2019-11-18 14:19 ` Alexandre Belloni
2019-11-18 14:19 ` Geert Uytterhoeven

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).