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