1
2
3
4
5
6
7
8
9
10#include <config.h>
11#include <common.h>
12#include <rtc.h>
13#include <asm/io.h>
14
15struct ftrtc010 {
16 unsigned int sec;
17 unsigned int min;
18 unsigned int hour;
19 unsigned int day;
20 unsigned int alarm_sec;
21 unsigned int alarm_min;
22 unsigned int alarm_hour;
23 unsigned int record;
24 unsigned int cr;
25 unsigned int wsec;
26 unsigned int wmin;
27 unsigned int whour;
28 unsigned int wday;
29 unsigned int intr;
30 unsigned int div;
31 unsigned int rev;
32};
33
34
35
36
37#define FTRTC010_CR_ENABLE (1 << 0)
38#define FTRTC010_CR_INTERRUPT_SEC (1 << 1)
39#define FTRTC010_CR_INTERRUPT_MIN (1 << 2)
40#define FTRTC010_CR_INTERRUPT_HR (1 << 3)
41#define FTRTC010_CR_INTERRUPT_DAY (1 << 4)
42
43static struct ftrtc010 *rtc = (struct ftrtc010 *)CONFIG_FTRTC010_BASE;
44
45static void ftrtc010_enable(void)
46{
47 writel(FTRTC010_CR_ENABLE, &rtc->cr);
48}
49
50
51
52
53static unsigned long ftrtc010_time(void)
54{
55 unsigned long day;
56 unsigned long hour;
57 unsigned long minute;
58 unsigned long second;
59 unsigned long second2;
60
61 do {
62 second = readl(&rtc->sec);
63 day = readl(&rtc->day);
64 hour = readl(&rtc->hour);
65 minute = readl(&rtc->min);
66 second2 = readl(&rtc->sec);
67 } while (second != second2);
68
69 return day * 24 * 60 * 60 + hour * 60 * 60 + minute * 60 + second;
70}
71
72
73
74
75
76int rtc_get(struct rtc_time *tmp)
77{
78 unsigned long now;
79
80 debug("%s(): record register: %x\n",
81 __func__, readl(&rtc->record));
82
83#ifdef CONFIG_FTRTC010_PCLK
84 now = (ftrtc010_time() + readl(&rtc->record)) / RTC_DIV_COUNT;
85#else
86 now = ftrtc010_time() + readl(&rtc->record);
87#endif
88
89 rtc_to_tm(now, tmp);
90
91 return 0;
92}
93
94
95
96
97int rtc_set(struct rtc_time *tmp)
98{
99 unsigned long new;
100 unsigned long now;
101
102 debug("%s(): DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
103 __func__,
104 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
105 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
106
107 new = rtc_mktime(tmp);
108
109 now = ftrtc010_time();
110
111 debug("%s(): write %lx to record register\n", __func__, new - now);
112
113 writel(new - now, &rtc->record);
114
115 return 0;
116}
117
118void rtc_reset(void)
119{
120 debug("%s()\n", __func__);
121 ftrtc010_enable();
122}
123