rtc.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. void to_tm (int, struct rtc_time *);
  42. unsigned long mktime (unsigned int, unsigned int, unsigned int,
  43. unsigned int, unsigned int, unsigned int);
  44. /**
  45. * rtc_read8() - Read an 8-bit register
  46. *
  47. * @reg: Register to read
  48. * @return value read
  49. */
  50. int rtc_read8(int reg);
  51. /**
  52. * rtc_write8() - Write an 8-bit register
  53. *
  54. * @reg: Register to write
  55. * @value: Value to write
  56. */
  57. void rtc_write8(int reg, uchar val);
  58. /**
  59. * rtc_read32() - Read a 32-bit value from the RTC
  60. *
  61. * @reg: Offset to start reading from
  62. * @return value read
  63. */
  64. u32 rtc_read32(int reg);
  65. /**
  66. * rtc_write32() - Write a 32-bit value to the RTC
  67. *
  68. * @reg: Register to start writing to
  69. * @value: Value to write
  70. */
  71. void rtc_write32(int reg, u32 value);
  72. /**
  73. * rtc_init() - Set up the real time clock ready for use
  74. */
  75. void rtc_init(void);
  76. /**
  77. * rtc_calc_weekday() - Work out the weekday from a time
  78. *
  79. * This only works for the Gregorian calendar - i.e. after 1752 (in the UK).
  80. * It sets time->tm_wdaay to the correct day of the week.
  81. *
  82. * @time: Time to inspect. tm_wday is updated
  83. * @return 0 if OK, -EINVAL if the weekday could not be determined
  84. */
  85. int rtc_calc_weekday(struct rtc_time *time);
  86. #endif /* _RTC_H_ */