12 #include <linux/module.h>
15 #include <linux/slab.h>
16 #include <linux/rtc.h>
22 #define REG_RTC_INIR 0x00
23 #define REG_RTC_AER 0x04
24 #define REG_RTC_FCR 0x08
25 #define REG_RTC_TLR 0x0C
26 #define REG_RTC_CLR 0x10
27 #define REG_RTC_TSSR 0x14
28 #define REG_RTC_DWR 0x18
29 #define REG_RTC_TAR 0x1C
30 #define REG_RTC_CAR 0x20
31 #define REG_RTC_LIR 0x24
32 #define REG_RTC_RIER 0x28
33 #define REG_RTC_RIIR 0x2C
34 #define REG_RTC_TTR 0x30
37 #define AERRWENB 0x10000
38 #define INIRRESET 0xa5eb1357
39 #define AERPOWERON 0xA965
40 #define AERPOWEROFF 0x0000
41 #define LEAPYEAR 0x0001
43 #define TICKINTENB 0x0002
44 #define ALARMINTENB 0x0001
62 static irqreturn_t nuc900_rtc_interrupt(
int irq,
void *_rtc)
65 unsigned long events = 0, rtc_irq;
70 rtc_irq &= ~ALARMINTENB;
76 rtc_irq &= ~TICKINTENB;
100 return ERR_PTR(-
EPERM);
105 static int nuc900_rtc_bcd2bin(
unsigned int timereg,
126 dev_warn(dev,
"The year will be between 1970-1999, right?\n");
137 static int nuc900_alarm_irq_enable(
struct device *dev,
unsigned int enabled)
159 return nuc900_rtc_bcd2bin(timeval, clrval, tm);
169 nuc900_rtc_bin2bcd(dev, tm, &gettm);
171 err = check_rtc_access_enable(rtc);
184 static int nuc900_rtc_read_alarm(
struct device *dev,
struct rtc_wkalrm *alrm)
192 return nuc900_rtc_bcd2bin(timeval, carval, &alrm->
time);
195 static int nuc900_rtc_set_alarm(
struct device *dev,
struct rtc_wkalrm *alrm)
202 nuc900_rtc_bin2bcd(dev, &alrm->
time, &tm);
204 err = check_rtc_access_enable(rtc);
208 val = tm.bcd_mday | tm.bcd_mon | tm.bcd_year;
211 val = tm.bcd_sec | tm.bcd_min | tm.bcd_hour;
218 .read_time = nuc900_rtc_read_time,
219 .set_time = nuc900_rtc_set_time,
220 .read_alarm = nuc900_rtc_read_alarm,
221 .set_alarm = nuc900_rtc_set_alarm,
222 .alarm_irq_enable = nuc900_alarm_irq_enable,
228 struct nuc900_rtc *nuc900_rtc;
231 nuc900_rtc = kzalloc(
sizeof(
struct nuc900_rtc),
GFP_KERNEL);
233 dev_err(&pdev->
dev,
"kzalloc nuc900_rtc failed\n");
238 dev_err(&pdev->
dev,
"platform_get_resource failed\n");
245 dev_err(&pdev->
dev,
"request_mem_region failed\n");
252 dev_err(&pdev->
dev,
"ioremap rtc_reg failed\n");
257 platform_set_drvdata(pdev, nuc900_rtc);
261 if (IS_ERR(nuc900_rtc->
rtcdev)) {
262 dev_err(&pdev->
dev,
"rtc device register failed\n");
263 err = PTR_ERR(nuc900_rtc->
rtcdev);
272 0,
"nuc900rtc", nuc900_rtc)) {
273 dev_err(&pdev->
dev,
"NUC900 RTC request irq failed\n");
283 fail1:
kfree(nuc900_rtc);
289 struct nuc900_rtc *nuc900_rtc = platform_get_drvdata(pdev);
301 platform_set_drvdata(pdev,
NULL);
309 .name =
"nuc900-rtc",
314 static int __init nuc900_rtc_init(
void)
319 static void __exit nuc900_rtc_exit(
void)