blob: b1a4bf05ec3b56a882f79bc429a38292ab52dc5e [file] [log] [blame]
wdenka6840a62001-04-09 21:43:07 +00001/*
2 * (C) Copyright 2001
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenka6840a62001-04-09 21:43:07 +00006 */
7
8/*
9 * Generic RTC interface.
10 */
11#ifndef _RTC_H_
12#define _RTC_H_
13
Albin Tonnerredfdea732009-08-13 15:31:12 +020014/* 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>
18
wdenka6840a62001-04-09 21:43:07 +000019/*
20 * The struct used to pass data from the generic interface code to
21 * the hardware dependend low-level code ande vice versa. Identical
22 * to struct rtc_time used by the Linux kernel.
23 *
24 * Note that there are small but significant differences to the
25 * common "struct time":
26 *
Wolfgang Denka1be4762008-05-20 16:00:29 +020027 * struct time: struct rtc_time:
wdenka6840a62001-04-09 21:43:07 +000028 * tm_mon 0 ... 11 1 ... 12
29 * tm_year years since 1900 years since 0
30 */
31
32struct rtc_time {
33 int tm_sec;
34 int tm_min;
35 int tm_hour;
36 int tm_mday;
37 int tm_mon;
38 int tm_year;
39 int tm_wday;
40 int tm_yday;
41 int tm_isdst;
42};
43
Yuri Tikhonov9bacd942008-03-20 17:56:04 +030044int rtc_get (struct rtc_time *);
Jean-Christophe PLAGNIOL-VILLARD97a2e102008-09-01 23:06:23 +020045int rtc_set (struct rtc_time *);
wdenka6840a62001-04-09 21:43:07 +000046void rtc_reset (void);
47
Simon Glass538059d2014-11-14 18:18:26 -070048/**
Simon Glassb4ae6002015-01-19 22:16:10 -070049 * rtc_read8() - Read an 8-bit register
50 *
51 * @reg: Register to read
52 * @return value read
53 */
54int rtc_read8(int reg);
55
56/**
57 * rtc_write8() - Write an 8-bit register
58 *
59 * @reg: Register to write
60 * @value: Value to write
61 */
62void rtc_write8(int reg, uchar val);
63
64/**
65 * rtc_read32() - Read a 32-bit value from the RTC
66 *
67 * @reg: Offset to start reading from
68 * @return value read
69 */
70u32 rtc_read32(int reg);
71
72/**
73 * rtc_write32() - Write a 32-bit value to the RTC
74 *
75 * @reg: Register to start writing to
76 * @value: Value to write
77 */
78void rtc_write32(int reg, u32 value);
79
80/**
Simon Glass538059d2014-11-14 18:18:26 -070081 * rtc_init() - Set up the real time clock ready for use
82 */
83void rtc_init(void);
84
Simon Glass2d937bb2015-04-20 12:37:17 -060085/**
86 * rtc_calc_weekday() - Work out the weekday from a time
87 *
88 * This only works for the Gregorian calendar - i.e. after 1752 (in the UK).
89 * It sets time->tm_wdaay to the correct day of the week.
90 *
91 * @time: Time to inspect. tm_wday is updated
92 * @return 0 if OK, -EINVAL if the weekday could not be determined
93 */
94int rtc_calc_weekday(struct rtc_time *time);
95
Simon Glass12994662015-04-20 12:37:18 -060096/**
97 * rtc_to_tm() - Convert a time_t value into a broken-out time
98 *
99 * The following fields are set up by this function:
100 * tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year, tm_wday
101 *
102 * Note that tm_yday and tm_isdst are set to 0.
103 *
104 * @time_t: Number of seconds since 1970-01-01 00:00:00
105 * @time: Place to put the broken-out time
106 * @return 0 if OK, -EINVAL if the weekday could not be determined
107 */
108int rtc_to_tm(int time_t, struct rtc_time *time);
109
Simon Glass4283e842015-04-20 12:37:19 -0600110/**
111 * rtc_mktime() - Convert a broken-out time into a time_t value
112 *
113 * The following fields need to be valid for this function to work:
114 * tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year
115 *
116 * Note that tm_wday and tm_yday are ignored.
117 *
118 * @time: Broken-out time to convert
119 * @return corresponding time_t value, seconds since 1970-01-01 00:00:00
120 */
121unsigned long rtc_mktime(const struct rtc_time *time);
122
wdenka6840a62001-04-09 21:43:07 +0000123#endif /* _RTC_H_ */