rtc.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * include/asm-parisc/rtc.h
  3. *
  4. * Copyright 2002 Randolph CHung <tausq@debian.org>
  5. *
  6. * Based on: include/asm-ppc/rtc.h and the genrtc driver in the
  7. * 2.4 parisc linux tree
  8. */
  9. #ifndef __ASM_RTC_H__
  10. #define __ASM_RTC_H__
  11. #ifdef __KERNEL__
  12. #include <linux/rtc.h>
  13. #include <asm/pdc.h>
  14. #define SECS_PER_HOUR (60 * 60)
  15. #define SECS_PER_DAY (SECS_PER_HOUR * 24)
  16. #define RTC_PIE 0x40 /* periodic interrupt enable */
  17. #define RTC_AIE 0x20 /* alarm interrupt enable */
  18. #define RTC_UIE 0x10 /* update-finished interrupt enable */
  19. #define RTC_BATT_BAD 0x100 /* battery bad */
  20. /* some dummy definitions */
  21. #define RTC_SQWE 0x08 /* enable square-wave output */
  22. #define RTC_DM_BINARY 0x04 /* all time/date values are BCD if clear */
  23. #define RTC_24H 0x02 /* 24 hour mode - else hours bit 7 means pm */
  24. #define RTC_DST_EN 0x01 /* auto switch DST - works f. USA only */
  25. # define __isleap(year) \
  26. ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
  27. /* How many days come before each month (0-12). */
  28. static const unsigned short int __mon_yday[2][13] =
  29. {
  30. /* Normal years. */
  31. { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
  32. /* Leap years. */
  33. { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
  34. };
  35. static inline unsigned int get_rtc_time(struct rtc_time *wtime)
  36. {
  37. struct pdc_tod tod_data;
  38. long int days, rem, y;
  39. const unsigned short int *ip;
  40. memset(wtime, 0, sizeof(*wtime));
  41. if (pdc_tod_read(&tod_data) < 0)
  42. return RTC_24H | RTC_BATT_BAD;
  43. // most of the remainder of this function is:
  44. // Copyright (C) 1991, 1993, 1997, 1998 Free Software Foundation, Inc.
  45. // This was originally a part of the GNU C Library.
  46. // It is distributed under the GPL, and was swiped from offtime.c
  47. days = tod_data.tod_sec / SECS_PER_DAY;
  48. rem = tod_data.tod_sec % SECS_PER_DAY;
  49. wtime->tm_hour = rem / SECS_PER_HOUR;
  50. rem %= SECS_PER_HOUR;
  51. wtime->tm_min = rem / 60;
  52. wtime->tm_sec = rem % 60;
  53. y = 1970;
  54. #define DIV(a, b) ((a) / (b) - ((a) % (b) < 0))
  55. #define LEAPS_THRU_END_OF(y) (DIV (y, 4) - DIV (y, 100) + DIV (y, 400))
  56. while (days < 0 || days >= (__isleap (y) ? 366 : 365))
  57. {
  58. /* Guess a corrected year, assuming 365 days per year. */
  59. long int yg = y + days / 365 - (days % 365 < 0);
  60. /* Adjust DAYS and Y to match the guessed year. */
  61. days -= ((yg - y) * 365
  62. + LEAPS_THRU_END_OF (yg - 1)
  63. - LEAPS_THRU_END_OF (y - 1));
  64. y = yg;
  65. }
  66. wtime->tm_year = y - 1900;
  67. ip = __mon_yday[__isleap(y)];
  68. for (y = 11; days < (long int) ip[y]; --y)
  69. continue;
  70. days -= ip[y];
  71. wtime->tm_mon = y;
  72. wtime->tm_mday = days + 1;
  73. return RTC_24H;
  74. }
  75. static int set_rtc_time(struct rtc_time *wtime)
  76. {
  77. u_int32_t secs;
  78. secs = mktime(wtime->tm_year + 1900, wtime->tm_mon + 1, wtime->tm_mday,
  79. wtime->tm_hour, wtime->tm_min, wtime->tm_sec);
  80. if(pdc_tod_set(secs, 0) < 0)
  81. return -1;
  82. else
  83. return 0;
  84. }
  85. static inline unsigned int get_rtc_ss(void)
  86. {
  87. struct rtc_time h;
  88. get_rtc_time(&h);
  89. return h.tm_sec;
  90. }
  91. static inline int get_rtc_pll(struct rtc_pll_info *pll)
  92. {
  93. return -EINVAL;
  94. }
  95. static inline int set_rtc_pll(struct rtc_pll_info *pll)
  96. {
  97. return -EINVAL;
  98. }
  99. #endif /* __KERNEL__ */
  100. #endif /* __ASM_RTC_H__ */