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 | d79de1d | 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 | dfdea73 | 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> |
Simon Glass | 573e3f7 | 2015-04-20 12:37:21 -0600 | [diff] [blame^] | 18 | #include <rtc_def.h> |
wdenk | a6840a6 | 2001-04-09 21:43:07 +0000 | [diff] [blame] | 19 | |
Yuri Tikhonov | 9bacd94 | 2008-03-20 17:56:04 +0300 | [diff] [blame] | 20 | int rtc_get (struct rtc_time *); |
Jean-Christophe PLAGNIOL-VILLARD | 97a2e10 | 2008-09-01 23:06:23 +0200 | [diff] [blame] | 21 | int rtc_set (struct rtc_time *); |
wdenk | a6840a6 | 2001-04-09 21:43:07 +0000 | [diff] [blame] | 22 | void rtc_reset (void); |
| 23 | |
Simon Glass | 538059d | 2014-11-14 18:18:26 -0700 | [diff] [blame] | 24 | /** |
Simon Glass | b4ae600 | 2015-01-19 22:16:10 -0700 | [diff] [blame] | 25 | * rtc_read8() - Read an 8-bit register |
| 26 | * |
| 27 | * @reg: Register to read |
| 28 | * @return value read |
| 29 | */ |
| 30 | int rtc_read8(int reg); |
| 31 | |
| 32 | /** |
| 33 | * rtc_write8() - Write an 8-bit register |
| 34 | * |
| 35 | * @reg: Register to write |
| 36 | * @value: Value to write |
| 37 | */ |
| 38 | void rtc_write8(int reg, uchar val); |
| 39 | |
| 40 | /** |
| 41 | * rtc_read32() - Read a 32-bit value from the RTC |
| 42 | * |
| 43 | * @reg: Offset to start reading from |
| 44 | * @return value read |
| 45 | */ |
| 46 | u32 rtc_read32(int reg); |
| 47 | |
| 48 | /** |
| 49 | * rtc_write32() - Write a 32-bit value to the RTC |
| 50 | * |
| 51 | * @reg: Register to start writing to |
| 52 | * @value: Value to write |
| 53 | */ |
| 54 | void rtc_write32(int reg, u32 value); |
| 55 | |
| 56 | /** |
Simon Glass | 538059d | 2014-11-14 18:18:26 -0700 | [diff] [blame] | 57 | * rtc_init() - Set up the real time clock ready for use |
| 58 | */ |
| 59 | void rtc_init(void); |
| 60 | |
Simon Glass | 2d937bb | 2015-04-20 12:37:17 -0600 | [diff] [blame] | 61 | /** |
| 62 | * rtc_calc_weekday() - Work out the weekday from a time |
| 63 | * |
| 64 | * This only works for the Gregorian calendar - i.e. after 1752 (in the UK). |
| 65 | * It sets time->tm_wdaay to the correct day of the week. |
| 66 | * |
| 67 | * @time: Time to inspect. tm_wday is updated |
| 68 | * @return 0 if OK, -EINVAL if the weekday could not be determined |
| 69 | */ |
| 70 | int rtc_calc_weekday(struct rtc_time *time); |
| 71 | |
Simon Glass | 1299466 | 2015-04-20 12:37:18 -0600 | [diff] [blame] | 72 | /** |
| 73 | * rtc_to_tm() - Convert a time_t value into a broken-out time |
| 74 | * |
| 75 | * The following fields are set up by this function: |
| 76 | * tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year, tm_wday |
| 77 | * |
| 78 | * Note that tm_yday and tm_isdst are set to 0. |
| 79 | * |
| 80 | * @time_t: Number of seconds since 1970-01-01 00:00:00 |
| 81 | * @time: Place to put the broken-out time |
| 82 | * @return 0 if OK, -EINVAL if the weekday could not be determined |
| 83 | */ |
| 84 | int rtc_to_tm(int time_t, struct rtc_time *time); |
| 85 | |
Simon Glass | 4283e84 | 2015-04-20 12:37:19 -0600 | [diff] [blame] | 86 | /** |
| 87 | * rtc_mktime() - Convert a broken-out time into a time_t value |
| 88 | * |
| 89 | * The following fields need to be valid for this function to work: |
| 90 | * tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year |
| 91 | * |
| 92 | * Note that tm_wday and tm_yday are ignored. |
| 93 | * |
| 94 | * @time: Broken-out time to convert |
| 95 | * @return corresponding time_t value, seconds since 1970-01-01 00:00:00 |
| 96 | */ |
| 97 | unsigned long rtc_mktime(const struct rtc_time *time); |
| 98 | |
wdenk | a6840a6 | 2001-04-09 21:43:07 +0000 | [diff] [blame] | 99 | #endif /* _RTC_H_ */ |