18 #include <linux/module.h>
19 #include <linux/rtc.h>
25 #include <linux/slab.h>
31 #define VT8500_RTC_TS 0x00
32 #define VT8500_RTC_DS 0x04
33 #define VT8500_RTC_AS 0x08
34 #define VT8500_RTC_CR 0x0c
35 #define VT8500_RTC_TR 0x10
36 #define VT8500_RTC_DR 0x14
37 #define VT8500_RTC_WS 0x18
38 #define VT8500_RTC_CL 0x20
39 #define VT8500_RTC_IS 0x24
40 #define VT8500_RTC_ST 0x28
42 #define INVALID_TIME_BIT (1 << 31)
44 #define DATE_CENTURY_S 19
45 #define DATE_YEAR_S 11
46 #define DATE_YEAR_MASK (0xff << DATE_YEAR_S)
47 #define DATE_MONTH_S 6
48 #define DATE_MONTH_MASK (0x1f << DATE_MONTH_S)
49 #define DATE_DAY_MASK 0x3f
52 #define TIME_DOW_MASK (0x07 << TIME_DOW_S)
53 #define TIME_HOUR_S 14
54 #define TIME_HOUR_MASK (0x3f << TIME_HOUR_S)
56 #define TIME_MIN_MASK (0x7f << TIME_MIN_S)
57 #define TIME_SEC_MASK 0x7f
59 #define ALARM_DAY_S 20
60 #define ALARM_DAY_MASK (0x3f << ALARM_DAY_S)
62 #define ALARM_DAY_BIT (1 << 29)
63 #define ALARM_HOUR_BIT (1 << 28)
64 #define ALARM_MIN_BIT (1 << 27)
65 #define ALARM_SEC_BIT (1 << 26)
67 #define ALARM_ENABLE_MASK (ALARM_DAY_BIT \
72 #define VT8500_RTC_CR_ENABLE (1 << 0)
73 #define VT8500_RTC_CR_24H (1 << 1)
74 #define VT8500_RTC_CR_SM_ENABLE (1 << 2)
75 #define VT8500_RTC_CR_SM_SEC (1 << 3)
76 #define VT8500_RTC_CR_CALIB (1 << 4)
78 #define VT8500_RTC_IS_ALARM (1 << 0)
94 spin_lock(&vt8500_rtc->
lock);
100 spin_unlock(&vt8500_rtc->
lock);
130 static int vt8500_rtc_set_time(
struct device *dev,
struct rtc_time *tm)
135 dev_warn(dev,
"Only years 2000-2199 are supported by the "
153 static int vt8500_rtc_read_alarm(
struct device *dev,
struct rtc_wkalrm *alrm)
172 static int vt8500_rtc_set_alarm(
struct device *dev,
struct rtc_wkalrm *alrm)
186 static int vt8500_alarm_irq_enable(
struct device *dev,
unsigned int enabled)
201 .read_time = vt8500_rtc_read_time,
202 .set_time = vt8500_rtc_set_time,
203 .read_alarm = vt8500_rtc_read_alarm,
204 .set_alarm = vt8500_rtc_set_alarm,
205 .alarm_irq_enable = vt8500_alarm_irq_enable,
210 struct vt8500_rtc *vt8500_rtc;
213 vt8500_rtc = kzalloc(
sizeof(
struct vt8500_rtc),
GFP_KERNEL);
218 platform_set_drvdata(pdev, vt8500_rtc);
221 if (!vt8500_rtc->
res) {
222 dev_err(&pdev->
dev,
"No I/O memory resource defined\n");
229 dev_err(&pdev->
dev,
"No alarm IRQ resource defined\n");
235 resource_size(vt8500_rtc->
res),
238 dev_err(&pdev->
dev,
"failed to request I/O memory\n");
244 resource_size(vt8500_rtc->
res));
246 dev_err(&pdev->
dev,
"Unable to map RTC I/O memory\n");
257 if (IS_ERR(vt8500_rtc->
rtc)) {
258 ret = PTR_ERR(vt8500_rtc->
rtc);
260 "Failed to register RTC device -> %d\n", ret);
265 "rtc alarm", vt8500_rtc);
267 dev_err(&pdev->
dev,
"can't get irq %i, err %d\n",
280 resource_size(vt8500_rtc->
res));
288 struct vt8500_rtc *vt8500_rtc = platform_get_drvdata(pdev);
298 resource_size(vt8500_rtc->
res));
301 platform_set_drvdata(pdev,
NULL);
307 { .compatible =
"via,vt8500-rtc", },
312 .probe = vt8500_rtc_probe,
315 .name =
"vt8500-rtc",