35
35
#define RZN1_RTC_CTL2_WUST BIT(5)
36
36
#define RZN1_RTC_CTL2_STOPPED (RZN1_RTC_CTL2_WAIT | RZN1_RTC_CTL2_WST)
37
37
38
- #define RZN1_RTC_SEC 0x14
39
- #define RZN1_RTC_MIN 0x18
40
- #define RZN1_RTC_HOUR 0x1c
41
- #define RZN1_RTC_WEEK 0x20
42
- #define RZN1_RTC_DAY 0x24
43
- #define RZN1_RTC_MONTH 0x28
44
- #define RZN1_RTC_YEAR 0x2c
38
+ #define RZN1_RTC_TIME 0x30
39
+ #define RZN1_RTC_TIME_MIN_SHIFT 8
40
+ #define RZN1_RTC_TIME_HOUR_SHIFT 16
41
+ #define RZN1_RTC_CAL 0x34
42
+ #define RZN1_RTC_CAL_DAY_SHIFT 8
43
+ #define RZN1_RTC_CAL_MON_SHIFT 16
44
+ #define RZN1_RTC_CAL_YEAR_SHIFT 24
45
45
46
46
#define RZN1_RTC_SUBU 0x38
47
47
#define RZN1_RTC_SUBU_DEV BIT(7)
52
52
#define RZN1_RTC_ALW 0x48
53
53
54
54
#define RZN1_RTC_SECC 0x4c
55
- #define RZN1_RTC_MINC 0x50
56
- #define RZN1_RTC_HOURC 0x54
57
- #define RZN1_RTC_WEEKC 0x58
58
- #define RZN1_RTC_DAYC 0x5c
59
- #define RZN1_RTC_MONTHC 0x60
60
- #define RZN1_RTC_YEARC 0x64
55
+ #define RZN1_RTC_TIMEC 0x68
56
+ #define RZN1_RTC_CALC 0x6c
61
57
62
58
struct rzn1_rtc {
63
59
struct rtc_device * rtcdev ;
@@ -66,13 +62,18 @@ struct rzn1_rtc {
66
62
67
63
static void rzn1_rtc_get_time_snapshot (struct rzn1_rtc * rtc , struct rtc_time * tm )
68
64
{
69
- tm -> tm_sec = readl (rtc -> base + RZN1_RTC_SECC );
70
- tm -> tm_min = readl (rtc -> base + RZN1_RTC_MINC );
71
- tm -> tm_hour = readl (rtc -> base + RZN1_RTC_HOURC );
72
- tm -> tm_wday = readl (rtc -> base + RZN1_RTC_WEEKC );
73
- tm -> tm_mday = readl (rtc -> base + RZN1_RTC_DAYC );
74
- tm -> tm_mon = readl (rtc -> base + RZN1_RTC_MONTHC );
75
- tm -> tm_year = readl (rtc -> base + RZN1_RTC_YEARC );
65
+ u32 val ;
66
+
67
+ val = readl (rtc -> base + RZN1_RTC_TIMEC );
68
+ tm -> tm_sec = bcd2bin (val );
69
+ tm -> tm_min = bcd2bin (val >> RZN1_RTC_TIME_MIN_SHIFT );
70
+ tm -> tm_hour = bcd2bin (val >> RZN1_RTC_TIME_HOUR_SHIFT );
71
+
72
+ val = readl (rtc -> base + RZN1_RTC_CALC );
73
+ tm -> tm_wday = val & 0x0f ;
74
+ tm -> tm_mday = bcd2bin (val >> RZN1_RTC_CAL_DAY_SHIFT );
75
+ tm -> tm_mon = bcd2bin (val >> RZN1_RTC_CAL_MON_SHIFT ) - 1 ;
76
+ tm -> tm_year = bcd2bin (val >> RZN1_RTC_CAL_YEAR_SHIFT ) + 100 ;
76
77
}
77
78
78
79
static int rzn1_rtc_read_time (struct device * dev , struct rtc_time * tm )
@@ -90,16 +91,9 @@ static int rzn1_rtc_read_time(struct device *dev, struct rtc_time *tm)
90
91
91
92
rzn1_rtc_get_time_snapshot (rtc , tm );
92
93
secs = readl (rtc -> base + RZN1_RTC_SECC );
93
- if (tm -> tm_sec != secs )
94
+ if (tm -> tm_sec != bcd2bin ( secs ) )
94
95
rzn1_rtc_get_time_snapshot (rtc , tm );
95
96
96
- tm -> tm_sec = bcd2bin (tm -> tm_sec );
97
- tm -> tm_min = bcd2bin (tm -> tm_min );
98
- tm -> tm_hour = bcd2bin (tm -> tm_hour );
99
- tm -> tm_mday = bcd2bin (tm -> tm_mday );
100
- tm -> tm_mon = bcd2bin (tm -> tm_mon ) - 1 ;
101
- tm -> tm_year = bcd2bin (tm -> tm_year ) + 100 ;
102
-
103
97
return 0 ;
104
98
}
105
99
@@ -109,13 +103,6 @@ static int rzn1_rtc_set_time(struct device *dev, struct rtc_time *tm)
109
103
u32 val ;
110
104
int ret ;
111
105
112
- tm -> tm_sec = bin2bcd (tm -> tm_sec );
113
- tm -> tm_min = bin2bcd (tm -> tm_min );
114
- tm -> tm_hour = bin2bcd (tm -> tm_hour );
115
- tm -> tm_mday = bin2bcd (tm -> tm_mday );
116
- tm -> tm_mon = bin2bcd (tm -> tm_mon + 1 );
117
- tm -> tm_year = bin2bcd (tm -> tm_year - 100 );
118
-
119
106
val = readl (rtc -> base + RZN1_RTC_CTL2 );
120
107
if (!(val & RZN1_RTC_CTL2_STOPPED )) {
121
108
/* Hold the counter if it was counting up */
@@ -129,13 +116,17 @@ static int rzn1_rtc_set_time(struct device *dev, struct rtc_time *tm)
129
116
return ret ;
130
117
}
131
118
132
- writel (tm -> tm_sec , rtc -> base + RZN1_RTC_SEC );
133
- writel (tm -> tm_min , rtc -> base + RZN1_RTC_MIN );
134
- writel (tm -> tm_hour , rtc -> base + RZN1_RTC_HOUR );
135
- writel (tm -> tm_wday , rtc -> base + RZN1_RTC_WEEK );
136
- writel (tm -> tm_mday , rtc -> base + RZN1_RTC_DAY );
137
- writel (tm -> tm_mon , rtc -> base + RZN1_RTC_MONTH );
138
- writel (tm -> tm_year , rtc -> base + RZN1_RTC_YEAR );
119
+ val = bin2bcd (tm -> tm_sec );
120
+ val |= bin2bcd (tm -> tm_min ) << RZN1_RTC_TIME_MIN_SHIFT ;
121
+ val |= bin2bcd (tm -> tm_hour ) << RZN1_RTC_TIME_HOUR_SHIFT ;
122
+ writel (val , rtc -> base + RZN1_RTC_TIME );
123
+
124
+ val = tm -> tm_wday ;
125
+ val |= bin2bcd (tm -> tm_mday ) << RZN1_RTC_CAL_DAY_SHIFT ;
126
+ val |= bin2bcd (tm -> tm_mon + 1 ) << RZN1_RTC_CAL_MON_SHIFT ;
127
+ val |= bin2bcd (tm -> tm_year - 100 ) << RZN1_RTC_CAL_YEAR_SHIFT ;
128
+ writel (val , rtc -> base + RZN1_RTC_CAL );
129
+
139
130
writel (0 , rtc -> base + RZN1_RTC_CTL2 );
140
131
141
132
return 0 ;
0 commit comments