From: Alexandre Belloni <alexandre.belloni@free-electrons.com>
To: Juergen Borleis <jbe@pengutronix.de>
Cc: rtc-linux@googlegroups.com,
Alessandro Zummo <a.zummo@towertech.it>,
linux-kernel@vger.kernel.org, kernel@pengutronix.de
Subject: Re: [PATCH 2/3] RTC/PCF85063: fix time/date reading (part II)
Date: Sun, 20 Dec 2015 12:35:40 +0100 [thread overview]
Message-ID: <20151220113540.GD3541@piout.net> (raw)
In-Reply-To: <1449496174-7813-3-git-send-email-jbe@pengutronix.de>
Hi,
On 07/12/2015 at 14:49:33 +0100, Juergen Borleis wrote :
> Use the function to read the whole time/date register in one turn and now
> check if the RTC signals an invalid time/date (due to a battery power loss
> for example). In this case ignore the time/date until it is really set
> again.
>
> Signed-off-by: Juergen Borleis <jbe@pengutronix.de>
> ---
> drivers/rtc/rtc-pcf85063.c | 45 +++++++++++++++++++--------------------------
> 1 file changed, 19 insertions(+), 26 deletions(-)
>
> diff --git a/drivers/rtc/rtc-pcf85063.c b/drivers/rtc/rtc-pcf85063.c
> index 75f2866..abed934 100644
> --- a/drivers/rtc/rtc-pcf85063.c
> +++ b/drivers/rtc/rtc-pcf85063.c
> @@ -22,6 +22,7 @@
> #define PCF85063_REG_CTRL2 0x01
>
> #define PCF85063_REG_SC 0x04 /* datetime */
> +#define PCF85063_REG_SC_OS 0x80
> #define PCF85063_REG_MN 0x05
> #define PCF85063_REG_HR 0x06
> #define PCF85063_REG_DM 0x07
> @@ -77,39 +78,31 @@ static int pcf85063_read_time(struct i2c_client *client, u8 *buf, u16 size)
> */
> static int pcf85063_get_datetime(struct i2c_client *client, struct rtc_time *tm)
> {
> + int rc;
> struct pcf85063 *pcf85063 = i2c_get_clientdata(client);
> - unsigned char buf[13] = { PCF85063_REG_CTRL1 };
> - struct i2c_msg msgs[] = {
> - {/* setup read ptr */
> - .addr = client->addr,
> - .len = 1,
> - .buf = buf
> - },
> - {/* read status + date */
> - .addr = client->addr,
> - .flags = I2C_M_RD,
> - .len = 13,
> - .buf = buf
> - },
> - };
> + u8 regs[7];
>
> - /* read registers */
> - if ((i2c_transfer(client->adapter, msgs, 2)) != 2) {
> - dev_err(&client->dev, "%s: read error\n", __func__);
> - return -EIO;
Isn't that already reading the time and date register in one block? I'd
say you are simply reading less registers. Also, maybe you could use
i2c_smbus_read_block_data?
> + rc = pcf85063_read_time(client, regs, sizeof(regs));
> + if (rc < 0)
> + return rc;
> +
> + /* if the clock has lost its power it makes no sense to use its time */
> + if (regs[0] & PCF85063_REG_SC_OS) {
> + dev_warn(&client->dev, "Power loss detected, invalid time\n");
> + return -EINVAL;
> }
That part is more useful and as I understand it is what you are trying
to fix.
--
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
next prev parent reply other threads:[~2015-12-20 11:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-07 13:49 [PATCH] RTC/PCF85063: fix reading/setting time/date Juergen Borleis
2015-12-07 13:49 ` [PATCH 1/3] RTC/PCF85063: fix time/date reading (part 1) Juergen Borleis
2015-12-07 13:49 ` [PATCH 2/3] RTC/PCF85063: fix time/date reading (part II) Juergen Borleis
2015-12-20 11:35 ` Alexandre Belloni [this message]
2016-01-07 10:12 ` Juergen Borleis
2016-01-21 0:04 ` Alexandre Belloni
2015-12-07 13:49 ` [PATCH 3/3] RTC/PCF85063: fix time/date setting Juergen Borleis
2015-12-20 11:46 ` Alexandre Belloni
2016-01-07 10:13 ` Juergen Borleis
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=20151220113540.GD3541@piout.net \
--to=alexandre.belloni@free-electrons.com \
--cc=a.zummo@towertech.it \
--cc=jbe@pengutronix.de \
--cc=kernel@pengutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=rtc-linux@googlegroups.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;
as well as URLs for NNTP newsgroup(s).