From: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
To: linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Alessandro Zummo <a.zummo@towertech.it>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Subject: Re: [PATCH 1/2] rtc: hym8563: Read the valid flag directly instead of caching it
Date: Thu, 12 Dec 2019 11:43:20 +0100 [thread overview]
Message-ID: <20191212104320.GD855977@aptenodytes> (raw)
In-Reply-To: <20191212103658.937528-1-paul.kocialkowski@bootlin.com>
[-- Attachment #1: Type: text/plain, Size: 2683 bytes --]
Hi,
On Thu 12 Dec 19, 11:36, Paul Kocialkowski wrote:
> The RTC has a valid bit in the seconds register that indicates whether
> power was lost since the pevious time set. This bit is currently read
> once at probe time, cached and updated with set_time.
>
> Howeever, caching the bit may prevent detecting power loss at runtime
> (which can happen if the RTC's supply is distinct from the the platform's).
>
> Writing the seconds register when setting time will clear the bit,
> so there should be no downside in reading the bit directly instead of
> caching it.
>
> Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
> ---
> drivers/rtc/rtc-hym8563.c | 17 +++++++----------
> 1 file changed, 7 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/rtc/rtc-hym8563.c b/drivers/rtc/rtc-hym8563.c
> index 443f6d05ce29..584a7815f246 100644
> --- a/drivers/rtc/rtc-hym8563.c
> +++ b/drivers/rtc/rtc-hym8563.c
> @@ -78,7 +78,6 @@
> struct hym8563 {
> struct i2c_client *client;
> struct rtc_device *rtc;
> - bool valid;
> #ifdef CONFIG_COMMON_CLK
> struct clk_hw clkout_hw;
> #endif
> @@ -95,15 +94,16 @@ static int hym8563_rtc_read_time(struct device *dev, struct rtc_time *tm)
> u8 buf[7];
> int ret;
>
> - if (!hym8563->valid) {
> - dev_warn(&client->dev, "no valid clock/calendar values available\n");
> - return -EPERM;
> - }
> -
> ret = i2c_smbus_read_i2c_block_data(client, HYM8563_SEC, 7, buf);
> if (ret < 0)
> return ret;
>
> + if (ret & HYM8563_SEC_VL) {
Ouch, I should be checking buf[0] here. Sorry about that, will send v2.
Cheers,
Paul
> + dev_warn(&client->dev,
> + "no valid clock/calendar values available\n");
> + return -EPERM;
> + }
> +
> tm->tm_sec = bcd2bin(buf[0] & HYM8563_SEC_MASK);
> tm->tm_min = bcd2bin(buf[1] & HYM8563_MIN_MASK);
> tm->tm_hour = bcd2bin(buf[2] & HYM8563_HOUR_MASK);
> @@ -157,8 +157,6 @@ static int hym8563_rtc_set_time(struct device *dev, struct rtc_time *tm)
> if (ret < 0)
> return ret;
>
> - hym8563->valid = true;
> -
> return 0;
> }
>
> @@ -556,9 +554,8 @@ static int hym8563_probe(struct i2c_client *client,
> if (ret < 0)
> return ret;
>
> - hym8563->valid = !(ret & HYM8563_SEC_VL);
> dev_dbg(&client->dev, "rtc information is %s\n",
> - hym8563->valid ? "valid" : "invalid");
> + (ret & HYM8563_SEC_VL) ? "invalid" : "valid");
>
> hym8563->rtc = devm_rtc_device_register(&client->dev, client->name,
> &hym8563_rtc_ops, THIS_MODULE);
> --
> 2.24.0
>
--
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
prev parent reply other threads:[~2019-12-12 10:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-12 10:36 [PATCH 1/2] rtc: hym8563: Read the valid flag directly instead of caching it Paul Kocialkowski
2019-12-12 10:36 ` [PATCH 2/2] rtc: hym8563: Return -EINVAL if the time is known to be invalid Paul Kocialkowski
2019-12-12 10:43 ` Paul Kocialkowski [this message]
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=20191212104320.GD855977@aptenodytes \
--to=paul.kocialkowski@bootlin.com \
--cc=a.zummo@towertech.it \
--cc=alexandre.belloni@bootlin.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=thomas.petazzoni@bootlin.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