Linux RTC
 help / color / mirror / Atom feed
From: Nicolas Boullis <nboullis@debian.org>
To: Alessandro Zummo <a.zummo@towertech.it>,
	Alexandre Belloni <alexandre.belloni@free-electrons.com>,
	rtc-linux@googlegroups.com
Subject: [rtc-linux] [PATCH] rtc: ds1307: ensure that any pending alarm is cleared before a new alarm is enabled
Date: Sun, 10 Apr 2016 13:23:05 +0200	[thread overview]
Message-ID: <20160410112305.GB3603@haddock.home> (raw)
In-Reply-To: <20160402221047.GB3600@haddock.home>

If a previously-set alarm was disabled and then triggered, it may still=20
be pending when a new alarm is configured.

Then, if the alarm is enabled before the pending alarm is cleared, then=20
an interrupt is immediately raised.

Unfortunately, when the alarm is cleared and enabled during the same I=C2=
=B2C=20
block write, the chip (at least the DS1339 I have) considers that the=20
alarm is enabled before it is cleared, and raises an interrupt.

This patch ensures that the pending alarm is cleared before the alarm is=20
enabled.

Signed-off-by: Nicolas Boullis <nboullis@debian.org>

---

This solves the same problem my =E2=80=9Crtc: ds1307: clear the interrupts =
on=20
probe=E2=80=9D patch was meant to solve, but I think in a better way since =
the=20
alarm may be triggered after power-on.

diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index b2156ee..cceac0f 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -538,12 +542,8 @@ static int ds1337_set_alarm(struct device *dev, struct=
 rtc_wkalrm *t)
 	buf[5] =3D 0;
 	buf[6] =3D 0;
=20
-	/* optionally enable ALARM1 */
+	/* disable alarms */
 	buf[7] =3D control & ~(DS1337_BIT_A1IE | DS1337_BIT_A2IE);
-	if (t->enabled) {
-		dev_dbg(dev, "alarm IRQ armed\n");
-		buf[7] |=3D DS1337_BIT_A1IE;	/* only ALARM1 is used */
-	}
 	buf[8] =3D status & ~(DS1337_BIT_A1I | DS1337_BIT_A2I);
=20
 	ret =3D ds1307->write_block_data(client,
@@ -553,6 +553,13 @@ static int ds1337_set_alarm(struct device *dev, struct=
 rtc_wkalrm *t)
 		return ret;
 	}
=20
+	/* optionally enable ALARM1 */
+	if (t->enabled) {
+		dev_dbg(dev, "alarm IRQ armed\n");
+		buf[7] |=3D DS1337_BIT_A1IE;	/* only ALARM1 is used */
+		i2c_smbus_write_byte_data(client, DS1337_REG_CONTROL, buf[7]);
+	}
+
 	return 0;
 }
=20

--=20
--=20
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---=20
You received this message because you are subscribed to the Google Groups "=
rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

  reply	other threads:[~2016-04-10 11:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-02 22:10 [rtc-linux] [PATCH 2/2] rtc: ds1307: clear the interrupts on probe Nicolas Boullis
2016-04-10 11:23 ` Nicolas Boullis [this message]
2016-04-18 22:28   ` [rtc-linux] Re: [PATCH] rtc: ds1307: ensure that any pending alarm is cleared before a new alarm is enabled Alexandre Belloni
2016-04-21 21:19     ` Nicolas Boullis

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=20160410112305.GB3603@haddock.home \
    --to=nboullis@debian.org \
    --cc=a.zummo@towertech.it \
    --cc=alexandre.belloni@free-electrons.com \
    --cc=rtc-linux@googlegroups.com \
    /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