xref: /rk3399_rockchip-uboot/include/rtc.h (revision aac5119822041febafdab3fc9ab6dbbe6ea96bff)
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>
18*aac51198SSimon Glass #include <rtc_def.h>
19a6840a6eSwdenk 
20b73a19e1SYuri Tikhonov int rtc_get (struct rtc_time *);
21d1e23194SJean-Christophe PLAGNIOL-VILLARD int rtc_set (struct rtc_time *);
22a6840a6eSwdenk void rtc_reset (void);
23a6840a6eSwdenk 
24c6577f72SSimon Glass /**
25fc4860c0SSimon Glass  * rtc_read8() - Read an 8-bit register
26fc4860c0SSimon Glass  *
27fc4860c0SSimon Glass  * @reg:	Register to read
28fc4860c0SSimon Glass  * @return value read
29fc4860c0SSimon Glass  */
30fc4860c0SSimon Glass int rtc_read8(int reg);
31fc4860c0SSimon Glass 
32fc4860c0SSimon Glass /**
33fc4860c0SSimon Glass  * rtc_write8() - Write an 8-bit register
34fc4860c0SSimon Glass  *
35fc4860c0SSimon Glass  * @reg:	Register to write
36fc4860c0SSimon Glass  * @value:	Value to write
37fc4860c0SSimon Glass  */
38fc4860c0SSimon Glass void rtc_write8(int reg, uchar val);
39fc4860c0SSimon Glass 
40fc4860c0SSimon Glass /**
41fc4860c0SSimon Glass  * rtc_read32() - Read a 32-bit value from the RTC
42fc4860c0SSimon Glass  *
43fc4860c0SSimon Glass  * @reg:	Offset to start reading from
44fc4860c0SSimon Glass  * @return value read
45fc4860c0SSimon Glass  */
46fc4860c0SSimon Glass u32 rtc_read32(int reg);
47fc4860c0SSimon Glass 
48fc4860c0SSimon Glass /**
49fc4860c0SSimon Glass  * rtc_write32() - Write a 32-bit value to the RTC
50fc4860c0SSimon Glass  *
51fc4860c0SSimon Glass  * @reg:	Register to start writing to
52fc4860c0SSimon Glass  * @value:	Value to write
53fc4860c0SSimon Glass  */
54fc4860c0SSimon Glass void rtc_write32(int reg, u32 value);
55fc4860c0SSimon Glass 
56fc4860c0SSimon Glass /**
57c6577f72SSimon Glass  * rtc_init() - Set up the real time clock ready for use
58c6577f72SSimon Glass  */
59c6577f72SSimon Glass void rtc_init(void);
60c6577f72SSimon Glass 
61199e87c3SSimon Glass /**
62199e87c3SSimon Glass  * rtc_calc_weekday() - Work out the weekday from a time
63199e87c3SSimon Glass  *
64199e87c3SSimon Glass  * This only works for the Gregorian calendar - i.e. after 1752 (in the UK).
65199e87c3SSimon Glass  * It sets time->tm_wdaay to the correct day of the week.
66199e87c3SSimon Glass  *
67199e87c3SSimon Glass  * @time:	Time to inspect. tm_wday is updated
68199e87c3SSimon Glass  * @return 0 if OK, -EINVAL if the weekday could not be determined
69199e87c3SSimon Glass  */
70199e87c3SSimon Glass int rtc_calc_weekday(struct rtc_time *time);
71199e87c3SSimon Glass 
729f9276c3SSimon Glass /**
739f9276c3SSimon Glass  * rtc_to_tm() - Convert a time_t value into a broken-out time
749f9276c3SSimon Glass  *
759f9276c3SSimon Glass  * The following fields are set up by this function:
769f9276c3SSimon Glass  *	tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year, tm_wday
779f9276c3SSimon Glass  *
789f9276c3SSimon Glass  * Note that tm_yday and tm_isdst are set to 0.
799f9276c3SSimon Glass  *
809f9276c3SSimon Glass  * @time_t:	Number of seconds since 1970-01-01 00:00:00
819f9276c3SSimon Glass  * @time:	Place to put the broken-out time
829f9276c3SSimon Glass  * @return 0 if OK, -EINVAL if the weekday could not be determined
839f9276c3SSimon Glass  */
849f9276c3SSimon Glass int rtc_to_tm(int time_t, struct rtc_time *time);
859f9276c3SSimon Glass 
8671420983SSimon Glass /**
8771420983SSimon Glass  * rtc_mktime() - Convert a broken-out time into a time_t value
8871420983SSimon Glass  *
8971420983SSimon Glass  * The following fields need to be valid for this function to work:
9071420983SSimon Glass  *	tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year
9171420983SSimon Glass  *
9271420983SSimon Glass  * Note that tm_wday and tm_yday are ignored.
9371420983SSimon Glass  *
9471420983SSimon Glass  * @time:	Broken-out time to convert
9571420983SSimon Glass  * @return corresponding time_t value, seconds since 1970-01-01 00:00:00
9671420983SSimon Glass  */
9771420983SSimon Glass unsigned long rtc_mktime(const struct rtc_time *time);
9871420983SSimon Glass 
99a6840a6eSwdenk #endif	/* _RTC_H_ */
100