rtc.h 1.8 KB

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