From: Andrew Morton <akpm@linux-foundation.org>
To: Thierry Reding <thierry.reding@avionic-design.de>
Cc: Alessandro Zummo <a.zummo@towertech.it>,
rtc-linux@googlegroups.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH RESEND] rtc: Add NXP PCF8523 support
Date: Tue, 27 Nov 2012 13:36:14 -0800 [thread overview]
Message-ID: <20121127133614.c8ff3be2.akpm@linux-foundation.org> (raw)
In-Reply-To: <1353683857-20010-1-git-send-email-thierry.reding@avionic-design.de>
On Fri, 23 Nov 2012 16:17:37 +0100
Thierry Reding <thierry.reding@avionic-design.de> wrote:
> This commit adds an RTC driver for PCF8523 chips by NXP Semiconductors.
> No support is currently provided for the alarm and interrupt functions.
> Only the time and date functionality is implemented.
>
> ...
>
> +static int pcf8523_rtc_read_time(struct device *dev, struct rtc_time *tm)
> +{
> + struct i2c_client *client = to_i2c_client(dev);
> + u8 start = REG_SECONDS, regs[7];
> + struct i2c_msg msgs[2];
> + int err;
> +
> + msgs[0].addr = client->addr;
> + msgs[0].flags = 0;
> + msgs[0].len = 1;
> + msgs[0].buf = &start;
> +
> + msgs[1].addr = client->addr;
> + msgs[1].flags = I2C_M_RD;
> + msgs[1].len = sizeof(regs);
> + msgs[1].buf = regs;
> +
> + err = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
> + if (err < 0)
> + return err;
> +
> + if (regs[0] & REG_SECONDS_OS) {
> + dev_dbg(dev, "clock integrity is not guaranteed\n");
> +
> + /* try to clear the flag */
The comment explains the "what", which was pretty obvious from the code.
But readers want to know "why".
> + regs[0] &= ~REG_SECONDS_OS;
> +
> + err = pcf8523_write(client, REG_SECONDS, regs[0]);
> + if (err < 0)
> + return err;
> + }
> +
> + tm->tm_sec = bcd2bin(regs[0] & 0x7f);
> + tm->tm_min = bcd2bin(regs[1] & 0x7f);
> + tm->tm_hour = bcd2bin(regs[2] & 0x3f);
> + tm->tm_mday = bcd2bin(regs[3] & 0x3f);
> + tm->tm_wday = regs[4] & 0x7;
> + tm->tm_mon = bcd2bin(regs[5] & 0x1f);
> + tm->tm_year = bcd2bin(regs[6]) + 100;
> +
> + return rtc_valid_tm(tm);
> +}
> +
> +static int pcf8523_rtc_set_time(struct device *dev, struct rtc_time *tm)
> +{
> + struct i2c_client *client = to_i2c_client(dev);
> + struct i2c_msg msg;
> + u8 regs[8];
> + int err;
> +
> + err = pcf8523_stop_rtc(client);
> + if (err < 0)
> + return err;
> +
> + regs[0] = REG_SECONDS;
> + regs[1] = bin2bcd(tm->tm_sec);
> + regs[2] = bin2bcd(tm->tm_min);
> + regs[3] = bin2bcd(tm->tm_hour);
> + regs[4] = bin2bcd(tm->tm_mday);
> + regs[5] = tm->tm_wday;
> + regs[6] = bin2bcd(tm->tm_mon);
> + regs[7] = bin2bcd(tm->tm_year - 100);
> +
> + msg.addr = client->addr;
> + msg.flags = 0;
> + msg.len = sizeof(regs);
> + msg.buf = regs;
> +
> + err = i2c_transfer(client->adapter, &msg, 1);
> + if (err < 0)
> + return err;
Should we restart the rtc if the transfer failed?
> + return pcf8523_start_rtc(client);
> +}
>
> ...
>
prev parent reply other threads:[~2012-11-27 21:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-23 15:17 [PATCH RESEND] rtc: Add NXP PCF8523 support Thierry Reding
2012-11-27 21:36 ` Andrew Morton [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=20121127133614.c8ff3be2.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=a.zummo@towertech.it \
--cc=linux-kernel@vger.kernel.org \
--cc=rtc-linux@googlegroups.com \
--cc=thierry.reding@avionic-design.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.