xref: /rk3399_rockchip-uboot/include/rtc.h (revision 714209832db1064886680b138f1abf9ce235b2c3)
1a6840a6eSwdenk /*
2a6840a6eSwdenk  * (C) Copyright 2001
3a6840a6eSwdenk  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4a6840a6eSwdenk  *
51a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
6a6840a6eSwdenk  */
7a6840a6eSwdenk 
8a6840a6eSwdenk /*
9a6840a6eSwdenk  * Generic RTC interface.
10a6840a6eSwdenk  */
11a6840a6eSwdenk #ifndef _RTC_H_
12a6840a6eSwdenk #define _RTC_H_
13a6840a6eSwdenk 
14885fc78cSAlbin Tonnerre /* bcd<->bin functions are needed by almost all the RTC drivers, let's include
15885fc78cSAlbin Tonnerre  * it there instead of in evey single driver */
16885fc78cSAlbin Tonnerre 
17885fc78cSAlbin Tonnerre #include <bcd.h>
18885fc78cSAlbin Tonnerre 
19a6840a6eSwdenk /*
20a6840a6eSwdenk  * The struct used to pass data from the generic interface code to
21a6840a6eSwdenk  * the hardware dependend low-level code ande vice versa. Identical
22a6840a6eSwdenk  * to struct rtc_time used by the Linux kernel.
23a6840a6eSwdenk  *
24a6840a6eSwdenk  * Note that there are small but significant differences to the
25a6840a6eSwdenk  * common "struct time":
26a6840a6eSwdenk  *
27a6840a6eSwdenk  *		struct time:		struct rtc_time:
28a6840a6eSwdenk  * tm_mon	0 ... 11		1 ... 12
29a6840a6eSwdenk  * tm_year	years since 1900	years since 0
30a6840a6eSwdenk  */
31a6840a6eSwdenk 
32a6840a6eSwdenk struct rtc_time {
33a6840a6eSwdenk 	int tm_sec;
34a6840a6eSwdenk 	int tm_min;
35a6840a6eSwdenk 	int tm_hour;
36a6840a6eSwdenk 	int tm_mday;
37a6840a6eSwdenk 	int tm_mon;
38a6840a6eSwdenk 	int tm_year;
39a6840a6eSwdenk 	int tm_wday;
40a6840a6eSwdenk 	int tm_yday;
41a6840a6eSwdenk 	int tm_isdst;
42a6840a6eSwdenk };
43a6840a6eSwdenk 
44b73a19e1SYuri Tikhonov int rtc_get (struct rtc_time *);
45d1e23194SJean-Christophe PLAGNIOL-VILLARD int rtc_set (struct rtc_time *);
46a6840a6eSwdenk void rtc_reset (void);
47a6840a6eSwdenk 
48c6577f72SSimon Glass /**
49fc4860c0SSimon Glass  * rtc_read8() - Read an 8-bit register
50fc4860c0SSimon Glass  *
51fc4860c0SSimon Glass  * @reg:	Register to read
52fc4860c0SSimon Glass  * @return value read
53fc4860c0SSimon Glass  */
54fc4860c0SSimon Glass int rtc_read8(int reg);
55fc4860c0SSimon Glass 
56fc4860c0SSimon Glass /**
57fc4860c0SSimon Glass  * rtc_write8() - Write an 8-bit register
58fc4860c0SSimon Glass  *
59fc4860c0SSimon Glass  * @reg:	Register to write
60fc4860c0SSimon Glass  * @value:	Value to write
61fc4860c0SSimon Glass  */
62fc4860c0SSimon Glass void rtc_write8(int reg, uchar val);
63fc4860c0SSimon Glass 
64fc4860c0SSimon Glass /**
65fc4860c0SSimon Glass  * rtc_read32() - Read a 32-bit value from the RTC
66fc4860c0SSimon Glass  *
67fc4860c0SSimon Glass  * @reg:	Offset to start reading from
68fc4860c0SSimon Glass  * @return value read
69fc4860c0SSimon Glass  */
70fc4860c0SSimon Glass u32 rtc_read32(int reg);
71fc4860c0SSimon Glass 
72fc4860c0SSimon Glass /**
73fc4860c0SSimon Glass  * rtc_write32() - Write a 32-bit value to the RTC
74fc4860c0SSimon Glass  *
75fc4860c0SSimon Glass  * @reg:	Register to start writing to
76fc4860c0SSimon Glass  * @value:	Value to write
77fc4860c0SSimon Glass  */
78fc4860c0SSimon Glass void rtc_write32(int reg, u32 value);
79fc4860c0SSimon Glass 
80fc4860c0SSimon Glass /**
81c6577f72SSimon Glass  * rtc_init() - Set up the real time clock ready for use
82c6577f72SSimon Glass  */
83c6577f72SSimon Glass void rtc_init(void);
84c6577f72SSimon Glass 
85199e87c3SSimon Glass /**
86199e87c3SSimon Glass  * rtc_calc_weekday() - Work out the weekday from a time
87199e87c3SSimon Glass  *
88199e87c3SSimon Glass  * This only works for the Gregorian calendar - i.e. after 1752 (in the UK).
89199e87c3SSimon Glass  * It sets time->tm_wdaay to the correct day of the week.
90199e87c3SSimon Glass  *
91199e87c3SSimon Glass  * @time:	Time to inspect. tm_wday is updated
92199e87c3SSimon Glass  * @return 0 if OK, -EINVAL if the weekday could not be determined
93199e87c3SSimon Glass  */
94199e87c3SSimon Glass int rtc_calc_weekday(struct rtc_time *time);
95199e87c3SSimon Glass 
969f9276c3SSimon Glass /**
979f9276c3SSimon Glass  * rtc_to_tm() - Convert a time_t value into a broken-out time
989f9276c3SSimon Glass  *
999f9276c3SSimon Glass  * The following fields are set up by this function:
1009f9276c3SSimon Glass  *	tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year, tm_wday
1019f9276c3SSimon Glass  *
1029f9276c3SSimon Glass  * Note that tm_yday and tm_isdst are set to 0.
1039f9276c3SSimon Glass  *
1049f9276c3SSimon Glass  * @time_t:	Number of seconds since 1970-01-01 00:00:00
1059f9276c3SSimon Glass  * @time:	Place to put the broken-out time
1069f9276c3SSimon Glass  * @return 0 if OK, -EINVAL if the weekday could not be determined
1079f9276c3SSimon Glass  */
1089f9276c3SSimon Glass int rtc_to_tm(int time_t, struct rtc_time *time);
1099f9276c3SSimon Glass 
110*71420983SSimon Glass /**
111*71420983SSimon Glass  * rtc_mktime() - Convert a broken-out time into a time_t value
112*71420983SSimon Glass  *
113*71420983SSimon Glass  * The following fields need to be valid for this function to work:
114*71420983SSimon Glass  *	tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year
115*71420983SSimon Glass  *
116*71420983SSimon Glass  * Note that tm_wday and tm_yday are ignored.
117*71420983SSimon Glass  *
118*71420983SSimon Glass  * @time:	Broken-out time to convert
119*71420983SSimon Glass  * @return corresponding time_t value, seconds since 1970-01-01 00:00:00
120*71420983SSimon Glass  */
121*71420983SSimon Glass unsigned long rtc_mktime(const struct rtc_time *time);
122*71420983SSimon Glass 
123a6840a6eSwdenk #endif	/* _RTC_H_ */
124