7 #include <linux/module.h>
8 #include <linux/kernel.h>
11 #include <linux/rtc.h>
15 #define AB3100_RTC_CLOCK_RATE 32768
27 #define AB3100_RTC 0x53
29 #define RTC_SETTING 0x30
31 #define AB3100_AL0 0x56
32 #define AB3100_AL1 0x57
33 #define AB3100_AL2 0x58
34 #define AB3100_AL3 0x59
36 #define AB3100_TI0 0x5a
37 #define AB3100_TI1 0x5b
38 #define AB3100_TI2 0x5c
39 #define AB3100_TI3 0x5d
40 #define AB3100_TI4 0x5e
41 #define AB3100_TI5 0x5f
46 static int ab3100_rtc_set_mmss(
struct device *
dev,
unsigned long secs)
55 buf[0] = (fat_time) & 0xFF;
56 buf[1] = (fat_time >> 8) & 0xFF;
57 buf[2] = (fat_time >> 16) & 0xFF;
58 buf[3] = (fat_time >> 24) & 0xFF;
59 buf[4] = (fat_time >> 32) & 0xFF;
60 buf[5] = (fat_time >> 40) & 0xFF;
62 for (i = 0; i < 6; i++) {
87 if (!(rtcval & 0x01)) {
88 dev_info(dev,
"clock not set (lost power)");
101 fat_time = ((
u64) buf[5] << 40) | ((
u64) buf[4] << 32) |
102 ((
u64) buf[3] << 24) | ((
u64) buf[2] << 16) |
103 ((
u64) buf[1] << 8) | (
u64) buf[0];
104 time = (
unsigned long) (fat_time /
137 fat_time = ((
u64) buf[3] << 40) | ((
u64) buf[2] << 32) |
138 ((
u64) buf[1] << 24) | ((
u64) buf[0] << 16);
146 static int ab3100_rtc_set_alarm(
struct device *dev,
struct rtc_wkalrm *alarm)
149 unsigned char buf[4];
157 buf[0] = (fat_time >> 16) & 0xFF;
158 buf[1] = (fat_time >> 24) & 0xFF;
159 buf[2] = (fat_time >> 32) & 0xFF;
160 buf[3] = (fat_time >> 40) & 0xFF;
163 for (i = 0; i < 4; i++) {
175 static int ab3100_rtc_irq_enable(
struct device *dev,
unsigned int enabled)
195 .read_time = ab3100_rtc_read_time,
196 .set_mmss = ab3100_rtc_set_mmss,
197 .read_alarm = ab3100_rtc_read_alarm,
198 .set_alarm = ab3100_rtc_set_alarm,
199 .alarm_irq_enable = ab3100_rtc_irq_enable,
212 dev_err(&pdev->
dev,
"unable to read RTC register\n");
217 dev_warn(&pdev->
dev,
"not default value in RTC reg 0x%x\n",
221 if ((regval & 1) == 0) {
238 platform_set_drvdata(pdev, rtc);
245 struct rtc_device *rtc = platform_get_drvdata(pdev);
248 platform_set_drvdata(pdev,
NULL);
254 .name =
"ab3100-rtc",
257 .remove =
__exit_p(ab3100_rtc_remove),
260 static int __init ab3100_rtc_init(
void)
266 static void __exit ab3100_rtc_exit(
void)