linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/5] rtc: pcf2127: tamper timestamp and watchdog feature support
@ 2019-08-13 15:35 Bruno Thomsen
  2019-08-13 15:35 ` [PATCH v2 1/5] rtc: pcf2127: convert to devm_rtc_allocate_device Bruno Thomsen
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Bruno Thomsen @ 2019-08-13 15:35 UTC (permalink / raw)
  To: linux-rtc, linux-watchdog
  Cc: alexandre.belloni, a.zummo, wim, linux, u.kleine-koenig,
	sean.nyekjaer, bth, bruno.thomsen

Hi all

This patch series still adds support for 2 chip features; tamper timestamp
and watchdog. Including code cleanup which improves code readability of the
device driver and better aligned with kernel coding style. There is also a
bugfix of pcf2127_rtc_read_time() which causes accidental watchdog disabling,
which was not included in v1.

All review comments from v1 have been handled.
The series now adds watchdog feature before tamper as the later needs to call
pcf2127_wdt_active_ping() as workaround for CTRL2 watchdog issue.

I have also tested if reading the other watchdog control register called WD_CTL
results in disabling of the watchdog feature, but that is luckily not the case.

Test script[1] for tamper function can be used to test the feature and verify
that the pcb circuit is working without issues during EMC immunity tests.

 Starting tamper detection (dev: rtc0, irq: rtc-tamper-irq)!
 event: FALLING EDGE offset: 12 timestamp: [1565695589.907980206]
 Tamper! Tue Aug 13 11:26:31 UTC 2019 (1565695591)
 event: FALLING EDGE offset: 12 timestamp: [1565695595.759132013]
 Tamper! Tue Aug 13 11:26:36 UTC 2019 (1565695596)


Watchdog driver has been tested with systemd version 242 and the following
/etc/systemd/system.conf parameters:

 RuntimeWatchdogSec=30
 ShutdownWatchdogSec=4min


Bug in pcf2127_rtc_read_time() can be reproduced with the following code:

	unsigned char test[10];

	ret = regmap_read(pcf2127->regmap, PCF2127_REG_WD_VAL,
			  (unsigned int *)(test));
	dev_info(dev, "%s: before, wd_val=%02x\n",
		 __func__, test[0]);

 /* "regmap_read/regmap_bulk_read()" */

	ret = regmap_read(pcf2127->regmap, PCF2127_REG_WD_VAL,
			  (unsigned int *)(test));
	dev_info(dev, "%s: after, wd_val=%02x\n",
		 __func__, test[0]);

Which output something like this when using hwclock -r -f /dev/rtc0 in dmesg:

 [ 1407.334031] rtc-pcf2127-spi spi1.0: pcf2127_rtc_read_time: before, wd_val=12
 [ 1407.342521] rtc-pcf2127-spi spi1.0: pcf2127_rtc_read_time: after, wd_val=00
 [ 2104.383726] rtc-pcf2127-spi spi1.0: pcf2127_rtc_read_time: before, wd_val=17
 [ 2104.392212] rtc-pcf2127-spi spi1.0: pcf2127_rtc_read_time: after, wd_val=00
 [ 2800.393418] rtc-pcf2127-spi spi1.0: pcf2127_rtc_read_time: before, wd_val=14
 [ 2800.401950] rtc-pcf2127-spi spi1.0: pcf2127_rtc_read_time: after, wd_val=00

After bugfix patch:

 [  125.095718] rtc-pcf2127-spi spi1.0: pcf2127_rtc_read_time: before, wd_val=16
 [  125.104010] rtc-pcf2127-spi spi1.0: pcf2127_rtc_read_time: after, wd_val=16
 [  128.415844] rtc-pcf2127-spi spi1.0: pcf2127_rtc_read_time: before, wd_val=13
 [  128.424134] rtc-pcf2127-spi spi1.0: pcf2127_rtc_read_time: after, wd_val=13


I also have a battery switch-over mode patch, but I will send it later as
it might need configuration based on hardware design.

/Bruno

[1] https://github.com/baxeno/linux-emc-test/blob/master/tamper/tamper.sh

Bruno Thomsen (5):
  rtc: pcf2127: convert to devm_rtc_allocate_device
  rtc: pcf2127: cleanup register and bit defines
  rtc: pcf2127: bugfix: read rtc disables watchdog
  rtc: pcf2127: add watchdog feature support
  rtc: pcf2127: add tamper detection support

 drivers/rtc/Kconfig       |   7 +-
 drivers/rtc/rtc-pcf2127.c | 387 +++++++++++++++++++++++++++++++++-----
 2 files changed, 343 insertions(+), 51 deletions(-)

-- 
2.21.0


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

end of thread, other threads:[~2019-08-14 13:34 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-13 15:35 [PATCH v2 0/5] rtc: pcf2127: tamper timestamp and watchdog feature support Bruno Thomsen
2019-08-13 15:35 ` [PATCH v2 1/5] rtc: pcf2127: convert to devm_rtc_allocate_device Bruno Thomsen
2019-08-13 15:35 ` [PATCH v2 2/5] rtc: pcf2127: cleanup register and bit defines Bruno Thomsen
2019-08-13 15:35 ` [PATCH v2 3/5] rtc: pcf2127: bugfix: read rtc disables watchdog Bruno Thomsen
2019-08-13 15:35 ` [PATCH v2 4/5] rtc: pcf2127: add watchdog feature support Bruno Thomsen
2019-08-13 16:19   ` Guenter Roeck
2019-08-14 13:25     ` Bruno Thomsen
2019-08-14 13:34       ` Guenter Roeck
2019-08-13 15:36 ` [PATCH v2 5/5] rtc: pcf2127: add tamper detection support Bruno Thomsen

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