rtc.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * inclue/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. if(pdc_tod_read(&tod_data) < 0)
  41. return RTC_24H | RTC_BATT_BAD;
  42. // most of the remainder of this function is:
  43. // Copyright (C) 1991, 1993, 1997, 1998 Free Software Foundation, Inc.
  44. // This was originally a part of the GNU C Library.
  45. // It is distributed under the GPL, and was swiped from offtime.c
  46. days = tod_data.tod_sec / SECS_PER_DAY;
  47. rem = tod_data.tod_sec % SECS_PER_DAY;
  48. wtime->tm_hour = rem / SECS_PER_HOUR;
  49. rem %= SECS_PER_HOUR;
  50. wtime->tm_min = rem / 60;
  51. wtime->tm_sec = rem % 60;
  52. y = 1970;
  53. #define DIV(a, b) ((a) / (b) - ((a) % (b) < 0))
  54. #define LEAPS_THRU_END_OF(y) (DIV (y, 4) - DIV (y, 100) + DIV (y, 400))
  55. while (days < 0 || days >= (__isleap (y) ? 366 : 365))
  56. {
  57. /* Guess a corrected year, assuming 365 days per year. */
  58. long int yg = y + days / 365 - (days % 365 < 0);
  59. /* Adjust DAYS and Y to match the guessed year. */
  60. days -= ((yg - y) * 365
  61. + LEAPS_THRU_END_OF (yg - 1)
  62. - LEAPS_THRU_END_OF (y - 1));
  63. y = yg;
  64. }
  65. wtime->tm_year = y - 1900;
  66. ip = __mon_yday[__isleap(y)];
  67. for (y = 11; days < (long int) ip[y]; --y)
  68. continue;
  69. days -= ip[y];
  70. wtime->tm_mon = y;
  71. wtime->tm_mday = days + 1;
  72. return RTC_24H;
  73. }
  74. static int set_rtc_time(struct rtc_time *wtime)
  75. {
  76. u_int32_t secs;
  77. secs = mktime(wtime->tm_year + 1900, wtime->tm_mon + 1, wtime->tm_mday,
  78. wtime->tm_hour, wtime->tm_min, wtime->tm_sec);
  79. if(pdc_tod_set(secs, 0) < 0)
  80. return -1;
  81. else
  82. return 0;
  83. }
  84. static inline unsigned int get_rtc_ss(void)
  85. {
  86. struct rtc_time h;
  87. get_rtc_time(&h);
  88. return h.tm_sec;
  89. }
  90. static inline int get_rtc_pll(struct rtc_pll_info *pll)
  91. {
  92. return -EINVAL;
  93. }
  94. static inline int set_rtc_pll(struct rtc_pll_info *pll)
  95. {
  96. return -EINVAL;
  97. }
  98. #endif /* __KERNEL__ */
  99. #endif /* __ASM_RTC_H__ */