|
@@ -382,10 +382,25 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t)
|
|
t->tm_mday = bcd2bin(ds1307->regs[DS1307_REG_MDAY] & 0x3f);
|
|
t->tm_mday = bcd2bin(ds1307->regs[DS1307_REG_MDAY] & 0x3f);
|
|
tmp = ds1307->regs[DS1307_REG_MONTH] & 0x1f;
|
|
tmp = ds1307->regs[DS1307_REG_MONTH] & 0x1f;
|
|
t->tm_mon = bcd2bin(tmp) - 1;
|
|
t->tm_mon = bcd2bin(tmp) - 1;
|
|
-
|
|
|
|
- /* assume 20YY not 19YY, and ignore DS1337_BIT_CENTURY */
|
|
|
|
t->tm_year = bcd2bin(ds1307->regs[DS1307_REG_YEAR]) + 100;
|
|
t->tm_year = bcd2bin(ds1307->regs[DS1307_REG_YEAR]) + 100;
|
|
|
|
|
|
|
|
+#ifdef CONFIG_RTC_DRV_DS1307_CENTURY
|
|
|
|
+ switch (ds1307->type) {
|
|
|
|
+ case ds_1337:
|
|
|
|
+ case ds_1339:
|
|
|
|
+ case ds_3231:
|
|
|
|
+ if (ds1307->regs[DS1307_REG_MONTH] & DS1337_BIT_CENTURY)
|
|
|
|
+ t->tm_year += 100;
|
|
|
|
+ break;
|
|
|
|
+ case ds_1340:
|
|
|
|
+ if (ds1307->regs[DS1307_REG_HOUR] & DS1340_BIT_CENTURY)
|
|
|
|
+ t->tm_year += 100;
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+#endif
|
|
|
|
+
|
|
dev_dbg(dev, "%s secs=%d, mins=%d, "
|
|
dev_dbg(dev, "%s secs=%d, mins=%d, "
|
|
"hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n",
|
|
"hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n",
|
|
"read", t->tm_sec, t->tm_min,
|
|
"read", t->tm_sec, t->tm_min,
|
|
@@ -409,6 +424,27 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
|
|
t->tm_hour, t->tm_mday,
|
|
t->tm_hour, t->tm_mday,
|
|
t->tm_mon, t->tm_year, t->tm_wday);
|
|
t->tm_mon, t->tm_year, t->tm_wday);
|
|
|
|
|
|
|
|
+#ifdef CONFIG_RTC_DRV_DS1307_CENTURY
|
|
|
|
+ if (t->tm_year < 100)
|
|
|
|
+ return -EINVAL;
|
|
|
|
+
|
|
|
|
+ switch (ds1307->type) {
|
|
|
|
+ case ds_1337:
|
|
|
|
+ case ds_1339:
|
|
|
|
+ case ds_3231:
|
|
|
|
+ case ds_1340:
|
|
|
|
+ if (t->tm_year > 299)
|
|
|
|
+ return -EINVAL;
|
|
|
|
+ default:
|
|
|
|
+ if (t->tm_year > 199)
|
|
|
|
+ return -EINVAL;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+#else
|
|
|
|
+ if (t->tm_year < 100 || t->tm_year > 199)
|
|
|
|
+ return -EINVAL;
|
|
|
|
+#endif
|
|
|
|
+
|
|
buf[DS1307_REG_SECS] = bin2bcd(t->tm_sec);
|
|
buf[DS1307_REG_SECS] = bin2bcd(t->tm_sec);
|
|
buf[DS1307_REG_MIN] = bin2bcd(t->tm_min);
|
|
buf[DS1307_REG_MIN] = bin2bcd(t->tm_min);
|
|
buf[DS1307_REG_HOUR] = bin2bcd(t->tm_hour);
|
|
buf[DS1307_REG_HOUR] = bin2bcd(t->tm_hour);
|
|
@@ -424,11 +460,13 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
|
|
case ds_1337:
|
|
case ds_1337:
|
|
case ds_1339:
|
|
case ds_1339:
|
|
case ds_3231:
|
|
case ds_3231:
|
|
- buf[DS1307_REG_MONTH] |= DS1337_BIT_CENTURY;
|
|
|
|
|
|
+ if (t->tm_year > 199)
|
|
|
|
+ buf[DS1307_REG_MONTH] |= DS1337_BIT_CENTURY;
|
|
break;
|
|
break;
|
|
case ds_1340:
|
|
case ds_1340:
|
|
- buf[DS1307_REG_HOUR] |= DS1340_BIT_CENTURY_EN
|
|
|
|
- | DS1340_BIT_CENTURY;
|
|
|
|
|
|
+ buf[DS1307_REG_HOUR] |= DS1340_BIT_CENTURY_EN;
|
|
|
|
+ if (t->tm_year > 199)
|
|
|
|
+ buf[DS1307_REG_HOUR] |= DS1340_BIT_CENTURY;
|
|
break;
|
|
break;
|
|
case mcp794xx:
|
|
case mcp794xx:
|
|
/*
|
|
/*
|