All of lore.kernel.org
 help / color / mirror / Atom feed
* [rtc-linux] [PATCH 2/2] rtc: ds1307: clear the interrupts on probe
@ 2016-04-02 22:10 Nicolas Boullis
  2016-04-10 11:23 ` [rtc-linux] [PATCH] rtc: ds1307: ensure that any pending alarm is cleared before a new alarm is enabled Nicolas Boullis
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Boullis @ 2016-04-02 22:10 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni, rtc-linux

When the alarm is used to switch the computer on, the interrupts are 
disabled, but the interrupt flags are not cleared.

When the alarm is set, later, the interrupt is enabled and the interrupt 
flags are cleared. Unfortunately, at least with my DS1339 chip, it 
behaves as if the interrupt was enabled before the flag was cleared, so 
the interrupt is triggered.

With this patch, the interrupt flags are cleared when the chip is 
probed, so an interrupt is not triggered when the alarm is set.

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

---

Not sure if I should check for errors with (tmp != 2) to be consistent 
with the check after reading the same block, a few lines above, or with 
(tmp < 0)...

diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index b2156ee..19e7353 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -1320,19 +1324,24 @@ static int ds1307_probe(struct i2c_client *client,
 			ds1307->regs[0] |= DS1337_BIT_INTCN
 					| bbsqi_bitpos[ds1307->type];
 			ds1307->regs[0] &= ~(DS1337_BIT_A2IE | DS1337_BIT_A1IE);
+			ds1307->regs[1] &= ~(DS1337_BIT_A2I | DS1337_BIT_A1I);
 
 			want_irq = true;
 		}
 
-		i2c_smbus_write_byte_data(client, DS1337_REG_CONTROL,
-							ds1307->regs[0]);
-
 		/* oscillator fault?  clear flag, and warn */
 		if (ds1307->regs[1] & DS1337_BIT_OSF) {
-			i2c_smbus_write_byte_data(client, DS1337_REG_STATUS,
-				ds1307->regs[1] & ~DS1337_BIT_OSF);
 			dev_warn(&client->dev, "SET TIME!\n");
 		}
+
+		tmp = ds1307->write_block_data(ds1307->client,
+				DS1337_REG_CONTROL, 2, buf);
+		if (tmp != 2) {
+			dev_dbg(&client->dev, "write error %d\n", tmp);
+			err = -EIO;
+			goto exit;
+		}
+
 		break;
 
 	case rx_8025:

-- 
-- 
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.
--- 
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 email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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

* [rtc-linux] [PATCH] rtc: ds1307: ensure that any pending alarm is cleared before a new alarm is enabled
  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
  2016-04-18 22:28   ` [rtc-linux] " Alexandre Belloni
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Boullis @ 2016-04-10 11:23 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni, rtc-linux

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.

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

* [rtc-linux] Re: [PATCH] rtc: ds1307: ensure that any pending alarm is cleared before a new alarm is enabled
  2016-04-10 11:23 ` [rtc-linux] [PATCH] rtc: ds1307: ensure that any pending alarm is cleared before a new alarm is enabled Nicolas Boullis
@ 2016-04-18 22:28   ` Alexandre Belloni
  2016-04-21 21:19     ` Nicolas Boullis
  0 siblings, 1 reply; 4+ messages in thread
From: Alexandre Belloni @ 2016-04-18 22:28 UTC (permalink / raw)
  To: Nicolas Boullis; +Cc: Alessandro Zummo, rtc-linux

On 10/04/2016 at 13:23:05 +0200, Nicolas Boullis wrote :
> If a previously-set alarm was disabled and then triggered, it may still=
=20
> be pending when a new alarm is configured.
>=20
> Then, if the alarm is enabled before the pending alarm is cleared, then=
=20
> an interrupt is immediately raised.
>=20
> Unfortunately, when the alarm is cleared and enabled during the same I=E6=
=B6=8E=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.
>=20
> This patch ensures that the pending alarm is cleared before the alarm is=
=20
> enabled.
>=20
> Signed-off-by: Nicolas Boullis <nboullis@debian.org>
>=20
Applied, thanks.

--=20
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

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

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

* [rtc-linux] Re: [PATCH] rtc: ds1307: ensure that any pending alarm is cleared before a new alarm is enabled
  2016-04-18 22:28   ` [rtc-linux] " Alexandre Belloni
@ 2016-04-21 21:19     ` Nicolas Boullis
  0 siblings, 0 replies; 4+ messages in thread
From: Nicolas Boullis @ 2016-04-21 21:19 UTC (permalink / raw)
  To: Alexandre Belloni; +Cc: Alessandro Zummo, rtc-linux

On Tue, Apr 19, 2016 at 12:28:03AM +0200, Alexandre Belloni wrote:
> Applied, thanks.

Well, you=E2=80=99re doing the hard work of maintaining the RTC subsystem, =
while=20
I am only scratching my itch, so thank YOU for your work.

--=20
Nicolas Boullis

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

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

end of thread, other threads:[~2016-04-21 21:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-02 22:10 [rtc-linux] [PATCH 2/2] rtc: ds1307: clear the interrupts on probe Nicolas Boullis
2016-04-10 11:23 ` [rtc-linux] [PATCH] rtc: ds1307: ensure that any pending alarm is cleared before a new alarm is enabled Nicolas Boullis
2016-04-18 22:28   ` [rtc-linux] " Alexandre Belloni
2016-04-21 21:19     ` Nicolas Boullis

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.