rtc.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * (C) Copyright 2001
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. /*
  8. * Generic RTC interface.
  9. */
  10. #ifndef _RTC_H_
  11. #define _RTC_H_
  12. /* bcd<->bin functions are needed by almost all the RTC drivers, let's include
  13. * it there instead of in evey single driver */
  14. #include <bcd.h>
  15. /*
  16. * The struct used to pass data from the generic interface code to
  17. * the hardware dependend low-level code ande vice versa. Identical
  18. * to struct rtc_time used by the Linux kernel.
  19. *
  20. * Note that there are small but significant differences to the
  21. * common "struct time":
  22. *
  23. * struct time: struct rtc_time:
  24. * tm_mon 0 ... 11 1 ... 12
  25. * tm_year years since 1900 years since 0
  26. */
  27. struct rtc_time {
  28. int tm_sec;
  29. int tm_min;
  30. int tm_hour;
  31. int tm_mday;
  32. int tm_mon;
  33. int tm_year;
  34. int tm_wday;
  35. int tm_yday;
  36. int tm_isdst;
  37. };
  38. int rtc_get (struct rtc_time *);
  39. int rtc_set (struct rtc_time *);
  40. void rtc_reset (void);
  41. unsigned long mktime (unsigned int, unsigned int, unsigned int,
  42. unsigned int, unsigned int, unsigned int);
  43. /**
  44. * rtc_read8() - Read an 8-bit register
  45. *
  46. * @reg: Register to read
  47. * @return value read
  48. */
  49. int rtc_read8(int reg);
  50. /**
  51. * rtc_write8() - Write an 8-bit register
  52. *
  53. * @reg: Register to write
  54. * @value: Value to write
  55. */
  56. void rtc_write8(int reg, uchar val);
  57. /**
  58. * rtc_read32() - Read a 32-bit value from the RTC
  59. *
  60. * @reg: Offset to start reading from
  61. * @return value read
  62. */
  63. u32 rtc_read32(int reg);
  64. /**
  65. * rtc_write32() - Write a 32-bit value to the RTC
  66. *
  67. * @reg: Register to start writing to
  68. * @value: Value to write
  69. */
  70. void rtc_write32(int reg, u32 value);
  71. /**
  72. * rtc_init() - Set up the real time clock ready for use
  73. */
  74. void rtc_init(void);
  75. /**
  76. * rtc_calc_weekday() - Work out the weekday from a time
  77. *
  78. * This only works for the Gregorian calendar - i.e. after 1752 (in the UK).
  79. * It sets time->tm_wdaay to the correct day of the week.
  80. *
  81. * @time: Time to inspect. tm_wday is updated
  82. * @return 0 if OK, -EINVAL if the weekday could not be determined
  83. */
  84. int rtc_calc_weekday(struct rtc_time *time);
  85. /**
  86. * rtc_to_tm() - Convert a time_t value into a broken-out time
  87. *
  88. * The following fields are set up by this function:
  89. * tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year, tm_wday
  90. *
  91. * Note that tm_yday and tm_isdst are set to 0.
  92. *
  93. * @time_t: Number of seconds since 1970-01-01 00:00:00
  94. * @time: Place to put the broken-out time
  95. * @return 0 if OK, -EINVAL if the weekday could not be determined
  96. */
  97. int rtc_to_tm(int time_t, struct rtc_time *time);
  98. #endif /* _RTC_H_ */