linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bruno Thomsen <bruno.thomsen@gmail.com>
To: linux-rtc@vger.kernel.org, linux-watchdog@vger.kernel.org
Cc: alexandre.belloni@bootlin.com, a.zummo@towertech.it,
	wim@linux-watchdog.org, linux@roeck-us.net,
	u.kleine-koenig@pengutronix.de, sean.nyekjaer@prevas.dk,
	bth@kamstrup.com, bruno.thomsen@gmail.com
Subject: [PATCH v2 0/5] rtc: pcf2127: tamper timestamp and watchdog feature support
Date: Tue, 13 Aug 2019 17:35:55 +0200	[thread overview]
Message-ID: <20190813153600.12406-1-bruno.thomsen@gmail.com> (raw)

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


             reply	other threads:[~2019-08-13 15:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-13 15:35 Bruno Thomsen [this message]
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

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=20190813153600.12406-1-bruno.thomsen@gmail.com \
    --to=bruno.thomsen@gmail.com \
    --cc=a.zummo@towertech.it \
    --cc=alexandre.belloni@bootlin.com \
    --cc=bth@kamstrup.com \
    --cc=linux-rtc@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=sean.nyekjaer@prevas.dk \
    --cc=u.kleine-koenig@pengutronix.de \
    --cc=wim@linux-watchdog.org \
    /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;
as well as URLs for NNTP newsgroup(s).