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 48a6840a6eSwdenk unsigned long mktime (unsigned int, unsigned int, unsigned int, 49a6840a6eSwdenk unsigned int, unsigned int, unsigned int); 50a6840a6eSwdenk 51c6577f72SSimon Glass /** 52fc4860c0SSimon Glass * rtc_read8() - Read an 8-bit register 53fc4860c0SSimon Glass * 54fc4860c0SSimon Glass * @reg: Register to read 55fc4860c0SSimon Glass * @return value read 56fc4860c0SSimon Glass */ 57fc4860c0SSimon Glass int rtc_read8(int reg); 58fc4860c0SSimon Glass 59fc4860c0SSimon Glass /** 60fc4860c0SSimon Glass * rtc_write8() - Write an 8-bit register 61fc4860c0SSimon Glass * 62fc4860c0SSimon Glass * @reg: Register to write 63fc4860c0SSimon Glass * @value: Value to write 64fc4860c0SSimon Glass */ 65fc4860c0SSimon Glass void rtc_write8(int reg, uchar val); 66fc4860c0SSimon Glass 67fc4860c0SSimon Glass /** 68fc4860c0SSimon Glass * rtc_read32() - Read a 32-bit value from the RTC 69fc4860c0SSimon Glass * 70fc4860c0SSimon Glass * @reg: Offset to start reading from 71fc4860c0SSimon Glass * @return value read 72fc4860c0SSimon Glass */ 73fc4860c0SSimon Glass u32 rtc_read32(int reg); 74fc4860c0SSimon Glass 75fc4860c0SSimon Glass /** 76fc4860c0SSimon Glass * rtc_write32() - Write a 32-bit value to the RTC 77fc4860c0SSimon Glass * 78fc4860c0SSimon Glass * @reg: Register to start writing to 79fc4860c0SSimon Glass * @value: Value to write 80fc4860c0SSimon Glass */ 81fc4860c0SSimon Glass void rtc_write32(int reg, u32 value); 82fc4860c0SSimon Glass 83fc4860c0SSimon Glass /** 84c6577f72SSimon Glass * rtc_init() - Set up the real time clock ready for use 85c6577f72SSimon Glass */ 86c6577f72SSimon Glass void rtc_init(void); 87c6577f72SSimon Glass 88199e87c3SSimon Glass /** 89199e87c3SSimon Glass * rtc_calc_weekday() - Work out the weekday from a time 90199e87c3SSimon Glass * 91199e87c3SSimon Glass * This only works for the Gregorian calendar - i.e. after 1752 (in the UK). 92199e87c3SSimon Glass * It sets time->tm_wdaay to the correct day of the week. 93199e87c3SSimon Glass * 94199e87c3SSimon Glass * @time: Time to inspect. tm_wday is updated 95199e87c3SSimon Glass * @return 0 if OK, -EINVAL if the weekday could not be determined 96199e87c3SSimon Glass */ 97199e87c3SSimon Glass int rtc_calc_weekday(struct rtc_time *time); 98199e87c3SSimon Glass 99*9f9276c3SSimon Glass /** 100*9f9276c3SSimon Glass * rtc_to_tm() - Convert a time_t value into a broken-out time 101*9f9276c3SSimon Glass * 102*9f9276c3SSimon Glass * The following fields are set up by this function: 103*9f9276c3SSimon Glass * tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year, tm_wday 104*9f9276c3SSimon Glass * 105*9f9276c3SSimon Glass * Note that tm_yday and tm_isdst are set to 0. 106*9f9276c3SSimon Glass * 107*9f9276c3SSimon Glass * @time_t: Number of seconds since 1970-01-01 00:00:00 108*9f9276c3SSimon Glass * @time: Place to put the broken-out time 109*9f9276c3SSimon Glass * @return 0 if OK, -EINVAL if the weekday could not be determined 110*9f9276c3SSimon Glass */ 111*9f9276c3SSimon Glass int rtc_to_tm(int time_t, struct rtc_time *time); 112*9f9276c3SSimon Glass 113a6840a6eSwdenk #endif /* _RTC_H_ */ 114