summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorJoshua Clayton <stillcompiling@gmail.com>2016-01-04 21:31:23 +0300
committerAlexandre Belloni <alexandre.belloni@free-electrons.com>2016-03-14 19:08:04 +0300
commitf07fa9242ee72e8a1e926458759b895b3f1de115 (patch)
treed976c0fc11a8275c9039962c4c648cbb69f1a66d /drivers
parent1e094b946c1e2186b412118c2af3cc602cad3ac4 (diff)
downloadlinux-f07fa9242ee72e8a1e926458759b895b3f1de115.tar.xz
rtc: pcf2123: avoid resetting the clock if possible
pcf2123 data sheet recommends a software reset when the chip is first powered on. This change avoids resetting the chip every time the driver is loaded, which has some negative effects. There are several registers including a clock rate adjustment that really should survive a reload of the driver (or reboot). In addition, stopping and restarting the clock to verify the chip is there is not a good thing once the time is set. According to the data sheet, the seconds register has a 1 in the high bit when the voltage has gotten low. We check for this condition, as well as whether the time retrieved from the chip is valid. We reset the rtc only if the time is not reliable and valid. This is sufficient for checking for the presence of the chip, as either all zeros or all 0xff will result in an invalid time/date Signed-off-by: Joshua Clayton <stillcompiling@gmail.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/rtc/rtc-pcf2123.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/drivers/rtc/rtc-pcf2123.c b/drivers/rtc/rtc-pcf2123.c
index 2d886d435e14..d9a44ad1239b 100644
--- a/drivers/rtc/rtc-pcf2123.c
+++ b/drivers/rtc/rtc-pcf2123.c
@@ -215,6 +215,11 @@ static int pcf2123_rtc_read_time(struct device *dev, struct rtc_time *tm)
if (ret < 0)
return ret;
+ if (rxbuf[0] & OSC_HAS_STOPPED) {
+ dev_info(dev, "clock was stopped. Time is not valid\n");
+ return -EINVAL;
+ }
+
tm->tm_sec = bcd2bin(rxbuf[0] & 0x7F);
tm->tm_min = bcd2bin(rxbuf[1] & 0x7F);
tm->tm_hour = bcd2bin(rxbuf[2] & 0x3F); /* rtc hr 0-23 */
@@ -314,6 +319,7 @@ static const struct rtc_class_ops pcf2123_rtc_ops = {
static int pcf2123_probe(struct spi_device *spi)
{
struct rtc_device *rtc;
+ struct rtc_time tm;
struct pcf2123_plat_data *pdata;
int ret, i;
@@ -323,10 +329,13 @@ static int pcf2123_probe(struct spi_device *spi)
return -ENOMEM;
spi->dev.platform_data = pdata;
- ret = pcf2123_reset(&spi->dev);
+ ret = pcf2123_rtc_read_time(&spi->dev, &tm);
if (ret < 0) {
- dev_err(&spi->dev, "chip not found\n");
- goto kfree_exit;
+ ret = pcf2123_reset(&spi->dev);
+ if (ret < 0) {
+ dev_err(&spi->dev, "chip not found\n");
+ goto kfree_exit;
+ }
}
dev_info(&spi->dev, "chip found, driver version " DRV_VERSION "\n");