static int mv_rtc_init(void) { MV_RTC_TIME time; struct timespec tv; struct device *dev; mvRtcTimeGet(&time); dev = device_create(rtc_class, NULL, -1, NULL, "mv_rtc"); /* Date which is not in the 21 century will stop the RTC on 00:00:00 - 01/01/2000, write operation will trigger it */ if ((time.year == 0) && (time.month == 1) && (time.date == 1)) { mvRtcTimeSet(&time); printk(KERN_INFO "RTC has been updated!!!\n"); } tv.tv_nsec = 0; /* same as in the U-Boot we use the year for century 20 only */ tv.tv_sec = mktime ( time.year + 2000, time.month, time.date, time.hours, time.minutes, time.seconds); do_settimeofday(&tv); set_rtc = mv_set_rtc; rtc_device_register("kw-rtc", dev, &rtc_ops, THIS_MODULE); printk("RTC registered\n"); return 0; }
static int mv_rtc_read_time(struct device *dev, struct rtc_time *tm) { MV_RTC_TIME time; unsigned long temp_t; mvRtcTimeGet(&time); /* same as in the U-Boot we use the year for century 20 only */ temp_t = mktime ( time.year + 2000, time.month, time.date, time.hours, time.minutes, time.seconds); rtc_time_to_tm(temp_t, tm); return 0; }
int rtc_get( struct rtc_time *tmp ) { MV_RTC_TIME time; #ifdef MV_INCLUDE_RTC mvRtcTimeGet(&time); #elif defined(CONFIG_RTC_DS1338_DS1339) mvRtcDS133xTimeGet(&time); #endif tmp->tm_year = (CENTURY * 100) + time.year; tmp->tm_mon = time.month; tmp->tm_mday = time.date; tmp->tm_wday = time.day; tmp->tm_hour = time.hours; tmp->tm_min = time.minutes; tmp->tm_sec = time.seconds; tmp->tm_yday = 0; tmp->tm_isdst= 0; #ifdef RTC_DEBUG printf( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n", tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec ); #endif return 0; }