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