The gmtime() function returns the number of years since 1900.
On PCs, the "design" of CMOS dates is such that the years (in this case)
are years since 2000. Fix up RTC emulation as follows:
- if year is > 99, subtract 100
- if year is 99 (20th century) take it as it is
Signed-off-by: Ronald G. Minnich <rminnich@gmail.com>
[ penberg@kernel.org: cleanups ]
Signed-off-by: Pekka Enberg <penberg@kernel.org>
{
struct tm *tm;
time_t ti;
+ int year;
time(&ti);
ioport__write8(data, bin2bcd(tm->tm_mon + 1));
break;
case RTC_YEAR:
- ioport__write8(data, bin2bcd(tm->tm_year));
+ /*
+ * The gmtime() function returns time since 1900. The CMOS
+ * standard is time since 2000. If the year is < 100, do
+ * nothing; if it is > 100, subtract 100; this is the best fit
+ * with the twisted CMOS logic.
+ */
+ year = tm->tm_year;
+ if (year > 99)
+ year -= 100;
+ ioport__write8(data, bin2bcd(year));
break;
default:
ioport__write8(data, rtc.cmos_data[rtc.cmos_idx]);