1 #ifndef _RTC_H_
2 #define _RTC_H_
3
4 #include <stdlib.h>
5 #include <sunxi_hal_common.h>
6 /*
7 * The struct used to pass data via the following ioctl. Similar to the
8 * struct tm in <time.h>, but it needs to be here so that the kernel
9 * source is self contained, allowing cross-compiles, etc. etc.
10 */
11
12 struct rtc_time
13 {
14 int tm_sec;
15 int tm_min;
16 int tm_hour;
17 int tm_mday;
18 int tm_mon;
19 int tm_year;
20 int tm_wday;
21 int tm_yday;
22 int tm_isdst;
23 };
24
25 typedef s64 time64_t;
26 /*
27 * This data structure is inspired by the EFI (v0.92) wakeup
28 * alarm API.
29 */
30 struct rtc_wkalrm
31 {
32 unsigned char enabled; /* 0 = alarm disabled, 1 = alarm enabled */
33 unsigned char pending; /* 0 = alarm not pending, 1 = alarm pending */
34 struct rtc_time time; /* time the alarm is set to */
35 };
36
37 typedef enum
38 {
39 RTC_IRQ_ERROR = -3,
40 RTC_CLK_ERROR = -2,
41 RTC_ERROR = -1,
42 RTC_OK = 0,
43 }hal_rtc_status_t;
44
45 int rtc_month_days(unsigned int month, unsigned int year);
46 int rtc_year_days(unsigned int day, unsigned int month, unsigned int year);
47 int rtc_valid_tm(struct rtc_time *tm);
48 time64_t rtc_tm_to_time64(struct rtc_time *tm);
49 void rtc_time64_to_tm(time64_t time, struct rtc_time *tm);
50
51 /*
52 * rtc_tm_sub - Return the difference in seconds.
53 */
rtc_tm_sub(struct rtc_time * lhs,struct rtc_time * rhs)54 static inline time64_t rtc_tm_sub(struct rtc_time *lhs, struct rtc_time *rhs)
55 {
56 return rtc_tm_to_time64(lhs) - rtc_tm_to_time64(rhs);
57 }
58
is_leap_year(unsigned int year)59 static inline int is_leap_year(unsigned int year)
60 {
61 return (!(year % 4) && (year % 100)) || !(year % 400);
62 }
63
64
65 /**
66 * Deprecated. Use rtc_time64_to_tm().
67 */
rtc_time_to_tm(unsigned long time,struct rtc_time * tm)68 static inline void rtc_time_to_tm(unsigned long time, struct rtc_time *tm)
69 {
70 rtc_time64_to_tm(time, tm);
71 }
72
73 /**
74 * Deprecated. Use rtc_tm_to_time64().
75 */
rtc_tm_to_time(struct rtc_time * tm,unsigned long * time)76 static inline int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time)
77 {
78 *time = rtc_tm_to_time64(tm);
79
80 return 0;
81 }
82 #endif /* _UAPI_LINUX_RTC_H_ */
83