3 * David Müller ELSOFT AG Switzerland. d.mueller@elsoft.ch
5 * SPDX-License-Identifier: GPL-2.0+
9 * Date & Time support for the built-in Samsung S3C24X0 RTC
15 #if (defined(CONFIG_CMD_DATE))
17 #include <asm/arch/s3c24x0_cpu.h>
21 #include <linux/compiler.h>
29 static inline void SetRTC_Access(RTC_ACCESS a
)
31 struct s3c24x0_rtc
*rtc
= s3c24x0_get_base_rtc();
35 writeb(readb(&rtc
->rtccon
) | 0x01, &rtc
->rtccon
);
39 writeb(readb(&rtc
->rtccon
) & ~0x01, &rtc
->rtccon
);
44 /* ------------------------------------------------------------------------- */
46 int rtc_get(struct rtc_time
*tmp
)
48 struct s3c24x0_rtc
*rtc
= s3c24x0_get_base_rtc();
49 uchar sec
, min
, hour
, mday
, wday
, mon
, year
;
50 __maybe_unused uchar a_sec
, a_min
, a_hour
, a_date
,
51 a_mon
, a_year
, a_armed
;
53 /* enable access to RTC registers */
54 SetRTC_Access(RTC_ENABLE
);
56 /* read RTC registers */
58 sec
= readb(&rtc
->bcdsec
);
59 min
= readb(&rtc
->bcdmin
);
60 hour
= readb(&rtc
->bcdhour
);
61 mday
= readb(&rtc
->bcddate
);
62 wday
= readb(&rtc
->bcdday
);
63 mon
= readb(&rtc
->bcdmon
);
64 year
= readb(&rtc
->bcdyear
);
65 } while (sec
!= readb(&rtc
->bcdsec
));
67 /* read ALARM registers */
68 a_sec
= readb(&rtc
->almsec
);
69 a_min
= readb(&rtc
->almmin
);
70 a_hour
= readb(&rtc
->almhour
);
71 a_date
= readb(&rtc
->almdate
);
72 a_mon
= readb(&rtc
->almmon
);
73 a_year
= readb(&rtc
->almyear
);
74 a_armed
= readb(&rtc
->rtcalm
);
76 /* disable access to RTC registers */
77 SetRTC_Access(RTC_DISABLE
);
80 printf("Get RTC year: %02x mon/cent: %02x mday: %02x wday: %02x "
81 "hr: %02x min: %02x sec: %02x\n",
82 year
, mon
, mday
, wday
, hour
, min
, sec
);
83 printf("Alarms: %02x: year: %02x month: %02x date: %02x hour: "
84 "%02x min: %02x sec: %02x\n",
85 a_armed
, a_year
, a_mon
, a_date
, a_hour
, a_min
, a_sec
);
88 tmp
->tm_sec
= bcd2bin(sec
& 0x7F);
89 tmp
->tm_min
= bcd2bin(min
& 0x7F);
90 tmp
->tm_hour
= bcd2bin(hour
& 0x3F);
91 tmp
->tm_mday
= bcd2bin(mday
& 0x3F);
92 tmp
->tm_mon
= bcd2bin(mon
& 0x1F);
93 tmp
->tm_year
= bcd2bin(year
);
94 tmp
->tm_wday
= bcd2bin(wday
& 0x07);
95 if (tmp
->tm_year
< 70)
102 printf("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
103 tmp
->tm_year
, tmp
->tm_mon
, tmp
->tm_mday
, tmp
->tm_wday
,
104 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
110 int rtc_set(struct rtc_time
*tmp
)
112 struct s3c24x0_rtc
*rtc
= s3c24x0_get_base_rtc();
113 uchar sec
, min
, hour
, mday
, wday
, mon
, year
;
116 printf("Set DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
117 tmp
->tm_year
, tmp
->tm_mon
, tmp
->tm_mday
, tmp
->tm_wday
,
118 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
120 year
= bin2bcd(tmp
->tm_year
% 100);
121 mon
= bin2bcd(tmp
->tm_mon
);
122 wday
= bin2bcd(tmp
->tm_wday
);
123 mday
= bin2bcd(tmp
->tm_mday
);
124 hour
= bin2bcd(tmp
->tm_hour
);
125 min
= bin2bcd(tmp
->tm_min
);
126 sec
= bin2bcd(tmp
->tm_sec
);
128 /* enable access to RTC registers */
129 SetRTC_Access(RTC_ENABLE
);
131 /* write RTC registers */
132 writeb(sec
, &rtc
->bcdsec
);
133 writeb(min
, &rtc
->bcdmin
);
134 writeb(hour
, &rtc
->bcdhour
);
135 writeb(mday
, &rtc
->bcddate
);
136 writeb(wday
, &rtc
->bcdday
);
137 writeb(mon
, &rtc
->bcdmon
);
138 writeb(year
, &rtc
->bcdyear
);
140 /* disable access to RTC registers */
141 SetRTC_Access(RTC_DISABLE
);
148 struct s3c24x0_rtc
*rtc
= s3c24x0_get_base_rtc();
150 writeb((readb(&rtc
->rtccon
) & ~0x06) | 0x08, &rtc
->rtccon
);
151 writeb(readb(&rtc
->rtccon
) & ~(0x08 | 0x01), &rtc
->rtccon
);