49 #include <linux/kernel.h>
50 #include <linux/module.h>
52 #include <linux/rtc.h>
54 #include <linux/slab.h>
58 #define dev_dbg_stamp(dev) dev_dbg(dev, "%s:%i: here i am\n", __func__, __LINE__)
67 #define RTC_ISTAT_WRITE_COMPLETE 0x8000
68 #define RTC_ISTAT_WRITE_PENDING 0x4000
69 #define RTC_ISTAT_ALARM_DAY 0x0040
70 #define RTC_ISTAT_24HR 0x0020
71 #define RTC_ISTAT_HOUR 0x0010
72 #define RTC_ISTAT_MIN 0x0008
73 #define RTC_ISTAT_SEC 0x0004
74 #define RTC_ISTAT_ALARM 0x0002
75 #define RTC_ISTAT_STOPWATCH 0x0001
78 #define DAY_BITS_OFF 17
79 #define HOUR_BITS_OFF 12
80 #define MIN_BITS_OFF 6
81 #define SEC_BITS_OFF 0
86 static inline u32 rtc_time_to_bfin(
unsigned long now)
89 u32 min = (now % (60 * 60)) / 60;
90 u32 hour = (now % (60 * 60 * 24)) / (60 * 60);
91 u32 days = (now / (60 * 60 * 24));
97 static inline unsigned long rtc_bfin_to_time(
u32 rtc_bfin)
104 static inline void rtc_bfin_to_tm(
u32 rtc_bfin,
struct rtc_time *
tm)
143 static void bfin_rtc_sync_pending(
struct device *
dev)
157 static void bfin_rtc_reset(
struct device *dev,
u16 rtc_ictl)
161 bfin_rtc_sync_pending(dev);
185 bool write_complete =
false;
186 u16 rtc_istat, rtc_istat_clear, rtc_ictl,
bits;
195 if (rtc_istat & bits) {
196 rtc_istat_clear |=
bits;
197 write_complete =
true;
202 if (rtc_ictl & bits) {
203 if (rtc_istat & bits) {
204 rtc_istat_clear |=
bits;
210 if (rtc_ictl & bits) {
211 if (rtc_istat & bits) {
212 rtc_istat_clear |=
bits;
220 if (write_complete || events) {
227 static void bfin_rtc_int_set(
u16 rtc_int)
232 static void bfin_rtc_int_clear(
u16 rtc_int)
236 static void bfin_rtc_int_set_alarm(
struct bfin_rtc *rtc)
244 static int bfin_rtc_alarm_irq_enable(
struct device *dev,
unsigned int enabled)
250 bfin_rtc_int_set_alarm(rtc);
257 static int bfin_rtc_read_time(
struct device *dev,
struct rtc_time *tm)
264 bfin_rtc_sync_pending(dev);
271 static int bfin_rtc_set_time(
struct device *dev,
struct rtc_time *tm)
282 bfin_rtc_sync_pending(dev);
295 bfin_rtc_sync_pending(dev);
312 bfin_rtc_sync_pending(dev);
315 bfin_rtc_int_set_alarm(rtc);
320 static int bfin_rtc_proc(
struct device *dev,
struct seq_file *seq)
322 #define yesno(x) ((x) ? "yes" : "no")
327 "wkalarm_IRQ\t: %s\n"
328 "seconds_IRQ\t: %s\n",
337 .read_time = bfin_rtc_read_time,
338 .set_time = bfin_rtc_set_time,
339 .read_alarm = bfin_rtc_read_alarm,
340 .set_alarm = bfin_rtc_set_alarm,
341 .proc = bfin_rtc_proc,
342 .alarm_irq_enable = bfin_rtc_alarm_irq_enable,
358 platform_set_drvdata(pdev, rtc);
393 struct bfin_rtc *rtc = platform_get_drvdata(pdev);
396 bfin_rtc_reset(dev, 0);
399 platform_set_drvdata(pdev,
NULL);
412 if (device_may_wakeup(dev)) {
414 bfin_rtc_sync_pending(dev);
416 bfin_rtc_int_clear(0);
427 if (device_may_wakeup(dev))
444 # define bfin_rtc_suspend NULL
445 # define bfin_rtc_resume NULL
453 .probe = bfin_rtc_probe,