12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/rtc.h>
18 #include <linux/types.h>
22 #define LS1X_RTC_REG_OFFSET (LS1X_RTC_BASE + 0x20)
23 #define LS1X_RTC_REGS(x) \
24 ((void __iomem *)KSEG1ADDR(LS1X_RTC_REG_OFFSET + (x)))
27 #define SYS_COUNTER_CNTRL (LS1X_RTC_REGS(0x20))
28 #define SYS_CNTRL_ERS (1 << 23)
29 #define SYS_CNTRL_RTS (1 << 20)
30 #define SYS_CNTRL_RM2 (1 << 19)
31 #define SYS_CNTRL_RM1 (1 << 18)
32 #define SYS_CNTRL_RM0 (1 << 17)
33 #define SYS_CNTRL_RS (1 << 16)
34 #define SYS_CNTRL_BP (1 << 14)
35 #define SYS_CNTRL_REN (1 << 13)
36 #define SYS_CNTRL_BRT (1 << 12)
37 #define SYS_CNTRL_TEN (1 << 11)
38 #define SYS_CNTRL_BTT (1 << 10)
39 #define SYS_CNTRL_E0 (1 << 8)
40 #define SYS_CNTRL_ETS (1 << 7)
41 #define SYS_CNTRL_32S (1 << 5)
42 #define SYS_CNTRL_TTS (1 << 4)
43 #define SYS_CNTRL_TM2 (1 << 3)
44 #define SYS_CNTRL_TM1 (1 << 2)
45 #define SYS_CNTRL_TM0 (1 << 1)
46 #define SYS_CNTRL_TS (1 << 0)
49 #define SYS_TOYTRIM (LS1X_RTC_REGS(0))
50 #define SYS_TOYWRITE0 (LS1X_RTC_REGS(4))
51 #define SYS_TOYWRITE1 (LS1X_RTC_REGS(8))
52 #define SYS_TOYREAD0 (LS1X_RTC_REGS(0xC))
53 #define SYS_TOYREAD1 (LS1X_RTC_REGS(0x10))
54 #define SYS_TOYMATCH0 (LS1X_RTC_REGS(0x14))
55 #define SYS_TOYMATCH1 (LS1X_RTC_REGS(0x18))
56 #define SYS_TOYMATCH2 (LS1X_RTC_REGS(0x1C))
59 #define SYS_RTCTRIM (LS1X_RTC_REGS(0x40))
60 #define SYS_RTCWRITE0 (LS1X_RTC_REGS(0x44))
61 #define SYS_RTCREAD0 (LS1X_RTC_REGS(0x48))
62 #define SYS_RTCMATCH0 (LS1X_RTC_REGS(0x4C))
63 #define SYS_RTCMATCH1 (LS1X_RTC_REGS(0x50))
64 #define SYS_RTCMATCH2 (LS1X_RTC_REGS(0x54))
66 #define LS1X_SEC_OFFSET (4)
67 #define LS1X_MIN_OFFSET (10)
68 #define LS1X_HOUR_OFFSET (16)
69 #define LS1X_DAY_OFFSET (21)
70 #define LS1X_MONTH_OFFSET (26)
73 #define LS1X_SEC_MASK (0x3f)
74 #define LS1X_MIN_MASK (0x3f)
75 #define LS1X_HOUR_MASK (0x1f)
76 #define LS1X_DAY_MASK (0x1f)
77 #define LS1X_MONTH_MASK (0x3f)
78 #define LS1X_YEAR_MASK (0xffffffff)
80 #define ls1x_get_sec(t) (((t) >> LS1X_SEC_OFFSET) & LS1X_SEC_MASK)
81 #define ls1x_get_min(t) (((t) >> LS1X_MIN_OFFSET) & LS1X_MIN_MASK)
82 #define ls1x_get_hour(t) (((t) >> LS1X_HOUR_OFFSET) & LS1X_HOUR_MASK)
83 #define ls1x_get_day(t) (((t) >> LS1X_DAY_OFFSET) & LS1X_DAY_MASK)
84 #define ls1x_get_month(t) (((t) >> LS1X_MONTH_OFFSET) & LS1X_MONTH_MASK)
86 #define RTC_CNTR_OK (SYS_CNTRL_E0 | SYS_CNTRL_32S)
106 unsigned long v,
t,
c;
122 dev_err(dev,
"set time timeout!\n");
133 dev_err(dev,
"set time timeout!\n");
142 .read_time = ls1x_rtc_read_time,
143 .set_time = ls1x_rtc_set_time,
154 dev_err(&pdev->
dev,
"rtc counters not working\n");
177 if (IS_ERR(rtcdev)) {
178 ret = PTR_ERR(rtcdev);
182 platform_set_drvdata(pdev, rtcdev);
190 struct rtc_device *rtcdev = platform_get_drvdata(pdev);
193 platform_set_drvdata(pdev,
NULL);
204 .probe = ls1x_rtc_probe,