summaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
authorArnaud Ebalard <arno@natisbad.org>2014-12-10 15:54:08 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2014-12-10 17:41:16 -0800
commit10df1e6787647f381a90689a5285555275f1a3a3 (patch)
treee6b6f545b69c5578e81207be99daca41c917bca6 /drivers/rtc
parentb5f4184d1439b6c5b36f54804b194f0b93a5b232 (diff)
downloadtalos-op-linux-10df1e6787647f381a90689a5285555275f1a3a3.tar.gz
talos-op-linux-10df1e6787647f381a90689a5285555275f1a3a3.zip
drivers/rtc/rtc-isl12057.c: add proper handling of oscillator failure bit
As suggested by Uwe, instead of clearing oscillator failure bit unconditionally at driver load, this patch adds proper handling of the flag. The driver now returns -ENODATA when reading time from the device and oscillator failure bit is set. The flag is now cleared only when the a new time value is pushed to the device. Signed-off-by: Arnaud Ebalard <arno@natisbad.org> Reported-by: Uwe Kleine-König <uwe@kleine-koenig.org> Acked-by: Uwe Kleine-König <uwe@kleine-koenig.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Alessandro Zummo <a.zummo@towertech.it> Cc: Peter Huewe <peter.huewe@infineon.com> Cc: Linus Walleij <linus.walleij@linaro.org> Cc: Thierry Reding <treding@nvidia.com> Cc: Mark Brown <broonie@kernel.org> Cc: Grant Likely <grant.likely@linaro.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/rtc-isl12057.c47
1 files changed, 33 insertions, 14 deletions
diff --git a/drivers/rtc/rtc-isl12057.c b/drivers/rtc/rtc-isl12057.c
index b538fabfcfd3..fe562820a54a 100644
--- a/drivers/rtc/rtc-isl12057.c
+++ b/drivers/rtc/rtc-isl12057.c
@@ -164,17 +164,32 @@ static int isl12057_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct isl12057_rtc_data *data = dev_get_drvdata(dev);
u8 regs[ISL12057_RTC_SEC_LEN];
+ unsigned int sr;
int ret;
mutex_lock(&data->lock);
+ ret = regmap_read(data->regmap, ISL12057_REG_SR, &sr);
+ if (ret) {
+ dev_err(dev, "%s: unable to read oscillator status flag\n",
+ __func__);
+ goto out;
+ } else {
+ if (sr & ISL12057_REG_SR_OSF) {
+ ret = -ENODATA;
+ goto out;
+ }
+ }
+
ret = regmap_bulk_read(data->regmap, ISL12057_REG_RTC_SC, regs,
ISL12057_RTC_SEC_LEN);
+ if (ret)
+ dev_err(dev, "%s: unable to read RTC time\n", __func__);
+
+out:
mutex_unlock(&data->lock);
- if (ret) {
- dev_err(dev, "%s: RTC read failed\n", __func__);
+ if (ret)
return ret;
- }
isl12057_rtc_regs_to_tm(tm, regs);
@@ -194,10 +209,22 @@ static int isl12057_rtc_set_time(struct device *dev, struct rtc_time *tm)
mutex_lock(&data->lock);
ret = regmap_bulk_write(data->regmap, ISL12057_REG_RTC_SC, regs,
ISL12057_RTC_SEC_LEN);
- mutex_unlock(&data->lock);
+ if (ret) {
+ dev_err(dev, "%s: writing RTC time failed\n", __func__);
+ goto out;
+ }
- if (ret)
- dev_err(dev, "%s: RTC write failed\n", __func__);
+ /*
+ * Now that RTC time has been updated, let's clear oscillator
+ * failure flag, if needed.
+ */
+ ret = regmap_update_bits(data->regmap, ISL12057_REG_SR,
+ ISL12057_REG_SR_OSF, 0);
+ if (ret < 0)
+ dev_err(dev, "Unable to clear oscillator failure bit\n");
+
+out:
+ mutex_unlock(&data->lock);
return ret;
}
@@ -219,14 +246,6 @@ static int isl12057_check_rtc_status(struct device *dev, struct regmap *regmap)
return ret;
}
- /* Clear oscillator failure bit if needed */
- ret = regmap_update_bits(regmap, ISL12057_REG_SR,
- ISL12057_REG_SR_OSF, 0);
- if (ret < 0) {
- dev_err(dev, "Unable to clear oscillator failure bit\n");
- return ret;
- }
-
/* Clear alarm bit if needed */
ret = regmap_update_bits(regmap, ISL12057_REG_SR,
ISL12057_REG_SR_A1F, 0);
OpenPOWER on IntegriCloud