Commit cff2e4d2 authored by Alexandre Belloni's avatar Alexandre Belloni

rtc: rv3029: correctly handle PON and VLOW2

In case the data is invalid (PON or VLOW2 are set in STATUS, explicitly
tell userspace that the time is invalid. Only remove VLOW2 when setting a
new valid time.

Link: https://lore.kernel.org/r/20191214221022.622482-12-alexandre.belloni@bootlin.comSigned-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent f630f728
...@@ -159,20 +159,21 @@ static int rv3029_eeprom_enter(struct rv3029_data *rv3029) ...@@ -159,20 +159,21 @@ static int rv3029_eeprom_enter(struct rv3029_data *rv3029)
ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr); ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr);
if (ret < 0) if (ret < 0)
return ret; return ret;
if (sr & (RV3029_STATUS_VLOW1 | RV3029_STATUS_VLOW2)) { if (sr & RV3029_STATUS_VLOW2)
return -ENODEV;
if (sr & RV3029_STATUS_VLOW1) {
/* We clear the bits and retry once just in case /* We clear the bits and retry once just in case
* we had a brown out in early startup. * we had a brown out in early startup.
*/ */
ret = regmap_update_bits(rv3029->regmap, RV3029_STATUS, ret = regmap_update_bits(rv3029->regmap, RV3029_STATUS,
RV3029_STATUS_VLOW1 | RV3029_STATUS_VLOW1, 0);
RV3029_STATUS_VLOW2, 0);
if (ret < 0) if (ret < 0)
return ret; return ret;
usleep_range(1000, 10000); usleep_range(1000, 10000);
ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr); ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr);
if (ret < 0) if (ret < 0)
return ret; return ret;
if (sr & (RV3029_STATUS_VLOW1 | RV3029_STATUS_VLOW2)) { if (sr & RV3029_STATUS_VLOW1) {
dev_err(rv3029->dev, dev_err(rv3029->dev,
"Supply voltage is too low to safely access the EEPROM.\n"); "Supply voltage is too low to safely access the EEPROM.\n");
return -ENODEV; return -ENODEV;
...@@ -306,9 +307,17 @@ static irqreturn_t rv3029_handle_irq(int irq, void *dev_id) ...@@ -306,9 +307,17 @@ static irqreturn_t rv3029_handle_irq(int irq, void *dev_id)
static int rv3029_read_time(struct device *dev, struct rtc_time *tm) static int rv3029_read_time(struct device *dev, struct rtc_time *tm)
{ {
struct rv3029_data *rv3029 = dev_get_drvdata(dev); struct rv3029_data *rv3029 = dev_get_drvdata(dev);
unsigned int sr;
int ret; int ret;
u8 regs[RV3029_WATCH_SECTION_LEN] = { 0, }; u8 regs[RV3029_WATCH_SECTION_LEN] = { 0, };
ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr);
if (ret < 0)
return ret;
if (sr & (RV3029_STATUS_VLOW2 | RV3029_STATUS_PON))
return -EINVAL;
ret = regmap_bulk_read(rv3029->regmap, RV3029_W_SEC, regs, ret = regmap_bulk_read(rv3029->regmap, RV3029_W_SEC, regs,
RV3029_WATCH_SECTION_LEN); RV3029_WATCH_SECTION_LEN);
if (ret < 0) { if (ret < 0) {
...@@ -454,9 +463,9 @@ static int rv3029_set_time(struct device *dev, struct rtc_time *tm) ...@@ -454,9 +463,9 @@ static int rv3029_set_time(struct device *dev, struct rtc_time *tm)
if (ret < 0) if (ret < 0)
return ret; return ret;
/* clear PON bit */ /* clear PON and VLOW2 bits */
return regmap_update_bits(rv3029->regmap, RV3029_STATUS, return regmap_update_bits(rv3029->regmap, RV3029_STATUS,
RV3029_STATUS_PON, 0); RV3029_STATUS_PON | RV3029_STATUS_VLOW2, 0);
} }
static int rv3029_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) static int rv3029_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment