16 #include <linux/kernel.h>
21 #include <linux/rtc.h>
24 #include <linux/module.h>
26 #define DRV_VERSION "0.1"
28 #define RTC_REG_SIZE 0x20000
29 #define RTC_OFFSET 0x1fff0
31 #define RTC_FLAGS (RTC_OFFSET + 0)
32 #define RTC_CENTURY (RTC_OFFSET + 1)
33 #define RTC_SECONDS_ALARM (RTC_OFFSET + 2)
34 #define RTC_MINUTES_ALARM (RTC_OFFSET + 3)
35 #define RTC_HOURS_ALARM (RTC_OFFSET + 4)
36 #define RTC_DATE_ALARM (RTC_OFFSET + 5)
37 #define RTC_INTERRUPTS (RTC_OFFSET + 6)
38 #define RTC_WATCHDOG (RTC_OFFSET + 7)
39 #define RTC_CALIBRATION (RTC_OFFSET + 8)
40 #define RTC_SECONDS (RTC_OFFSET + 9)
41 #define RTC_MINUTES (RTC_OFFSET + 10)
42 #define RTC_HOURS (RTC_OFFSET + 11)
43 #define RTC_DAY (RTC_OFFSET + 12)
44 #define RTC_DATE (RTC_OFFSET + 13)
45 #define RTC_MONTH (RTC_OFFSET + 14)
46 #define RTC_YEAR (RTC_OFFSET + 15)
48 #define RTC_SECONDS_MASK 0x7f
49 #define RTC_DAY_MASK 0x07
50 #define RTC_CAL_MASK 0x3f
56 #define RTC_FLAGS_AF 0x40
57 #define RTC_FLAGS_PF 0x20
58 #define RTC_WRITE 0x02
62 #define RTC_INTS_AIE 0x40
100 static int stk17ta8_rtc_read_time(
struct device *dev,
struct rtc_time *tm)
106 unsigned int century;
135 dev_err(dev,
"retrieved date/time is not valid.\n");
141 static void stk17ta8_rtc_update_alarm(
struct rtc_plat_data *pdata)
144 unsigned long irqflags;
167 spin_unlock_irqrestore(&pdata->
lock, irqflags);
170 static int stk17ta8_rtc_set_alarm(
struct device *dev,
struct rtc_wkalrm *alrm)
183 stk17ta8_rtc_update_alarm(pdata);
187 static int stk17ta8_rtc_read_alarm(
struct device *dev,
struct rtc_wkalrm *alrm)
209 spin_lock(&pdata->
lock);
220 spin_unlock(&pdata->
lock);
224 static int stk17ta8_rtc_alarm_irq_enable(
struct device *dev,
236 stk17ta8_rtc_update_alarm(pdata);
241 .read_time = stk17ta8_rtc_read_time,
242 .set_time = stk17ta8_rtc_set_time,
243 .read_alarm = stk17ta8_rtc_read_alarm,
244 .set_alarm = stk17ta8_rtc_set_alarm,
245 .alarm_irq_enable = stk17ta8_rtc_alarm_irq_enable,
258 for (count = 0; size > 0 && pos <
RTC_OFFSET; count++, size--)
259 *buf++ =
readb(ioaddr + pos++);
265 loff_t pos,
size_t size)
273 for (count = 0; size > 0 && pos <
RTC_OFFSET; count++, size--)
274 writeb(*buf++, ioaddr + pos++);
284 .read = stk17ta8_nvram_read,
285 .write = stk17ta8_nvram_write,
327 platform_set_drvdata(pdev, pdata);
328 if (pdata->
irq > 0) {
330 if (devm_request_irq(&pdev->
dev, pdata->
irq,
331 stk17ta8_rtc_interrupt,
333 pdev->
name, pdev) < 0) {
334 dev_warn(&pdev->
dev,
"interrupt not available.\n");
341 if (IS_ERR(pdata->
rtc))
342 return PTR_ERR(pdata->
rtc);
365 .probe = stk17ta8_rtc_probe,