3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
9 * Generic RTC interface.
14 /* bcd<->bin functions are needed by almost all the RTC drivers, let's include
15 * it there instead of in evey single driver */
24 * get() - get the current time
26 * Returns the current time read from the RTC device. The driver
27 * is responsible for setting up every field in the structure.
29 * @dev: Device to read from
30 * @time: Place to put the time that is read
32 int (*get)(struct udevice *dev, struct rtc_time *time);
35 * set() - set the current time
37 * Sets the time in the RTC device. The driver can expect every
38 * field to be set correctly.
40 * @dev: Device to read from
41 * @time: Time to write
43 int (*set)(struct udevice *dev, const struct rtc_time *time);
46 * reset() - reset the RTC to a known-good state
48 * This function resets the RTC to a known-good state. The time may
49 * be unset by this method, so should be set after this method is
52 * @dev: Device to read from
53 * @return 0 if OK, -ve on error
55 int (*reset)(struct udevice *dev);
58 * read8() - Read an 8-bit register
60 * @dev: Device to read from
61 * @reg: Register to read
62 * @return value read, or -ve on error
64 int (*read8)(struct udevice *dev, unsigned int reg);
67 * write8() - Write an 8-bit register
69 * @dev: Device to write to
70 * @reg: Register to write
71 * @value: Value to write
72 * @return 0 if OK, -ve on error
74 int (*write8)(struct udevice *dev, unsigned int reg, int val);
77 /* Access the operations for an RTC device */
78 #define rtc_get_ops(dev) ((struct rtc_ops *)(dev)->driver->ops)
81 * dm_rtc_get() - Read the time from an RTC
83 * @dev: Device to read from
84 * @time: Place to put the current time
85 * @return 0 if OK, -ve on error
87 int dm_rtc_get(struct udevice *dev, struct rtc_time *time);
90 * dm_rtc_put() - Write a time to an RTC
92 * @dev: Device to read from
93 * @time: Time to write into the RTC
94 * @return 0 if OK, -ve on error
96 int dm_rtc_set(struct udevice *dev, struct rtc_time *time);
99 * dm_rtc_reset() - reset the RTC to a known-good state
101 * If the RTC appears to be broken (e.g. it is not counting up in seconds)
102 * it may need to be reset to a known good state. This function achieves this.
103 * After resetting the RTC the time should then be set to a known value by
106 * @dev: Device to read from
107 * @return 0 if OK, -ve on error
109 int dm_rtc_reset(struct udevice *dev);
112 * rtc_read8() - Read an 8-bit register
114 * @dev: Device to read from
115 * @reg: Register to read
116 * @return value read, or -ve on error
118 int rtc_read8(struct udevice *dev, unsigned int reg);
121 * rtc_write8() - Write an 8-bit register
123 * @dev: Device to write to
124 * @reg: Register to write
125 * @value: Value to write
126 * @return 0 if OK, -ve on error
128 int rtc_write8(struct udevice *dev, unsigned int reg, int val);
131 * rtc_read16() - Read a 16-bit value from the RTC
133 * @dev: Device to read from
134 * @reg: Offset to start reading from
135 * @valuep: Place to put the value that is read
136 * @return 0 if OK, -ve on error
138 int rtc_read16(struct udevice *dev, unsigned int reg, u16 *valuep);
141 * rtc_write16() - Write a 16-bit value to the RTC
143 * @dev: Device to write to
144 * @reg: Register to start writing to
145 * @value: Value to write
146 * @return 0 if OK, -ve on error
148 int rtc_write16(struct udevice *dev, unsigned int reg, u16 value);
151 * rtc_read32() - Read a 32-bit value from the RTC
153 * @dev: Device to read from
154 * @reg: Offset to start reading from
155 * @valuep: Place to put the value that is read
156 * @return 0 if OK, -ve on error
158 int rtc_read32(struct udevice *dev, unsigned int reg, u32 *valuep);
161 * rtc_write32() - Write a 32-bit value to the RTC
163 * @dev: Device to write to
164 * @reg: Register to start writing to
165 * @value: Value to write
166 * @return 0 if OK, -ve on error
168 int rtc_write32(struct udevice *dev, unsigned int reg, u32 value);
171 int rtc_get (struct rtc_time *);
172 int rtc_set (struct rtc_time *);
173 void rtc_reset (void);
174 void rtc_enable_32khz_output(void);
177 * rtc_read8() - Read an 8-bit register
179 * @reg: Register to read
182 int rtc_read8(int reg);
185 * rtc_write8() - Write an 8-bit register
187 * @reg: Register to write
188 * @value: Value to write
190 void rtc_write8(int reg, uchar val);
193 * rtc_read32() - Read a 32-bit value from the RTC
195 * @reg: Offset to start reading from
198 u32 rtc_read32(int reg);
201 * rtc_write32() - Write a 32-bit value to the RTC
203 * @reg: Register to start writing to
204 * @value: Value to write
206 void rtc_write32(int reg, u32 value);
209 * rtc_init() - Set up the real time clock ready for use
215 * rtc_calc_weekday() - Work out the weekday from a time
217 * This only works for the Gregorian calendar - i.e. after 1752 (in the UK).
218 * It sets time->tm_wdaay to the correct day of the week.
220 * @time: Time to inspect. tm_wday is updated
221 * @return 0 if OK, -EINVAL if the weekday could not be determined
223 int rtc_calc_weekday(struct rtc_time *time);
226 * rtc_to_tm() - Convert a time_t value into a broken-out time
228 * The following fields are set up by this function:
229 * tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year, tm_wday
231 * Note that tm_yday and tm_isdst are set to 0.
233 * @time_t: Number of seconds since 1970-01-01 00:00:00
234 * @time: Place to put the broken-out time
235 * @return 0 if OK, -EINVAL if the weekday could not be determined
237 int rtc_to_tm(int time_t, struct rtc_time *time);
240 * rtc_mktime() - Convert a broken-out time into a time_t value
242 * The following fields need to be valid for this function to work:
243 * tm_sec, tm_min, tm_hour, tm_mday, tm_mon, tm_year
245 * Note that tm_wday and tm_yday are ignored.
247 * @time: Broken-out time to convert
248 * @return corresponding time_t value, seconds since 1970-01-01 00:00:00
250 unsigned long rtc_mktime(const struct rtc_time *time);