Blame view
drivers/rtc/mcfrtc.c
2.19 KB
83d290c56 SPDX: Convert all... |
1 |
// SPDX-License-Identifier: GPL-2.0+ |
8e585f02f Added M5329AFEE a... |
2 |
/* |
5cdc07c7e Update header files |
3 4 |
* Copyright (C) 2004-2007 Freescale Semiconductor, Inc. * TsiChung Liew (Tsi-Chung.Liew@freescale.com) |
8e585f02f Added M5329AFEE a... |
5 6 7 |
*/ #include <common.h> |
3e66c0780 Fix some build er... |
8 |
|
8e585f02f Added M5329AFEE a... |
9 10 |
#include <command.h> #include <rtc.h> |
5cdc07c7e Update header files |
11 12 |
#include <asm/immap.h> #include <asm/rtc.h> |
8e585f02f Added M5329AFEE a... |
13 |
|
8e585f02f Added M5329AFEE a... |
14 |
#undef RTC_DEBUG |
6d0f6bcf3 rename CFG_ macro... |
15 |
#ifndef CONFIG_SYS_MCFRTC_BASE |
8e585f02f Added M5329AFEE a... |
16 17 18 19 20 |
#error RTC_BASE is not defined! #endif #define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0) #define STARTOFTIME 1970 |
b73a19e16 LWMON5: POST RTC fix |
21 |
int rtc_get(struct rtc_time *tmp) |
8e585f02f Added M5329AFEE a... |
22 |
{ |
6d0f6bcf3 rename CFG_ macro... |
23 |
volatile rtc_t *rtc = (rtc_t *) (CONFIG_SYS_MCFRTC_BASE); |
8e585f02f Added M5329AFEE a... |
24 25 26 27 28 29 30 31 32 33 34 |
int rtc_days, rtc_hrs, rtc_mins; int tim; rtc_days = rtc->days; rtc_hrs = rtc->hourmin >> 8; rtc_mins = RTC_HOURMIN_MINUTES(rtc->hourmin); tim = (rtc_days * 24) + rtc_hrs; tim = (tim * 60) + rtc_mins; tim = (tim * 60) + rtc->seconds; |
9f9276c34 dm: rtc: Rename t... |
35 |
rtc_to_tm(tim, tmp); |
8e585f02f Added M5329AFEE a... |
36 37 38 39 40 41 42 43 44 45 |
tmp->tm_yday = 0; tmp->tm_isdst = 0; #ifdef RTC_DEBUG printf("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d ", tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); #endif |
b73a19e16 LWMON5: POST RTC fix |
46 47 |
return 0; |
8e585f02f Added M5329AFEE a... |
48 |
} |
d1e231941 rtc: allow rtc_se... |
49 |
int rtc_set(struct rtc_time *tmp) |
8e585f02f Added M5329AFEE a... |
50 |
{ |
6d0f6bcf3 rename CFG_ macro... |
51 |
volatile rtc_t *rtc = (rtc_t *) (CONFIG_SYS_MCFRTC_BASE); |
8e585f02f Added M5329AFEE a... |
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
static int month_days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int days, i, months; if (tmp->tm_year > 2037) { printf("Unable to handle. Exceeding integer limitation! "); tmp->tm_year = 2027; } #ifdef RTC_DEBUG printf("Set DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d ", tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); #endif /* calculate days by years */ for (i = STARTOFTIME, days = 0; i < tmp->tm_year; i++) { days += 365 + isleap(i); } /* calculate days by months */ months = tmp->tm_mon - 1; for (i = 0; i < months; i++) { days += month_days[i]; if (i == 1) days += isleap(i); } days += tmp->tm_mday - 1; rtc->days = days; rtc->hourmin = (tmp->tm_hour << 8) | tmp->tm_min; rtc->seconds = tmp->tm_sec; |
d1e231941 rtc: allow rtc_se... |
89 90 |
return 0; |
8e585f02f Added M5329AFEE a... |
91 92 93 94 |
} void rtc_reset(void) { |
6d0f6bcf3 rename CFG_ macro... |
95 |
volatile rtc_t *rtc = (rtc_t *) (CONFIG_SYS_MCFRTC_BASE); |
8e585f02f Added M5329AFEE a... |
96 97 98 99 100 101 102 103 104 |
if ((rtc->cr & RTC_CR_EN) == 0) { printf("real-time-clock was stopped. Now starting... "); rtc->cr |= RTC_CR_EN; } rtc->cr |= RTC_CR_SWR; } |