mbox series

[v2,0/5] rtc: pcf2127: tamper timestamp and watchdog feature support

Message ID 20190813153600.12406-1-bruno.thomsen@gmail.com (mailing list archive)
Headers show
Series rtc: pcf2127: tamper timestamp and watchdog feature support | expand

Message

Bruno Thomsen Aug. 13, 2019, 3:35 p.m. UTC
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(-)