Lines Matching +full:reset +full:- +full:time +full:- +full:sec

1 // SPDX-License-Identifier: GPL-2.0+
6 * Steven Scholz, steven.scholz@imc-berlin.de
10 * Date & Time support (no alarms) for Dallas Semiconductor (now Maxim)
11 * DS1307 and DS1338/9 Real Time Clock (RTC).
48 /* MCP7941X-specific bits */
54 /*---------------------------------------------------------------------*/
62 /*---------------------------------------------------------------------*/
76 * Get the current time from the RTC
81 uchar sec, min, hour, mday, wday, mon, year; in rtc_get() local
86 sec = rtc_read (RTC_SEC_REG_ADDR); in rtc_get()
95 "hr: %02x min: %02x sec: %02x\n", in rtc_get()
96 year, mon, mday, wday, hour, min, sec); in rtc_get()
99 if (sec & RTC_SEC_BIT_CH) { in rtc_get()
104 rel = -1; in rtc_get()
116 if (!(sec & MCP7941X_BIT_ST)) { in rtc_get()
124 tmp->tm_sec = bcd2bin (sec & 0x7F); in rtc_get()
125 tmp->tm_min = bcd2bin (min & 0x7F); in rtc_get()
126 tmp->tm_hour = bcd2bin (hour & 0x3F); in rtc_get()
127 tmp->tm_mday = bcd2bin (mday & 0x3F); in rtc_get()
128 tmp->tm_mon = bcd2bin (mon & 0x1F); in rtc_get()
129 tmp->tm_year = bcd2bin (year) + ( bcd2bin (year) >= 70 ? 1900 : 2000); in rtc_get()
130 tmp->tm_wday = bcd2bin ((wday - 1) & 0x07); in rtc_get()
131 tmp->tm_yday = 0; in rtc_get()
132 tmp->tm_isdst= 0; in rtc_get()
134 DEBUGR ("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n", in rtc_get()
135 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday, in rtc_get()
136 tmp->tm_hour, tmp->tm_min, tmp->tm_sec); in rtc_get()
147 DEBUGR ("Set DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n", in rtc_set()
148 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday, in rtc_set()
149 tmp->tm_hour, tmp->tm_min, tmp->tm_sec); in rtc_set()
151 if (tmp->tm_year < 1970 || tmp->tm_year > 2069) in rtc_set()
154 rtc_write (RTC_YR_REG_ADDR, bin2bcd (tmp->tm_year % 100)); in rtc_set()
155 rtc_write (RTC_MON_REG_ADDR, bin2bcd (tmp->tm_mon)); in rtc_set()
158 bin2bcd (tmp->tm_wday + 1) | MCP7941X_BIT_VBATEN); in rtc_set()
160 rtc_write (RTC_DAY_REG_ADDR, bin2bcd (tmp->tm_wday + 1)); in rtc_set()
162 rtc_write (RTC_DATE_REG_ADDR, bin2bcd (tmp->tm_mday)); in rtc_set()
163 rtc_write (RTC_HR_REG_ADDR, bin2bcd (tmp->tm_hour)); in rtc_set()
164 rtc_write (RTC_MIN_REG_ADDR, bin2bcd (tmp->tm_min)); in rtc_set()
166 rtc_write (RTC_SEC_REG_ADDR, bin2bcd (tmp->tm_sec) | MCP7941X_BIT_ST); in rtc_set()
168 rtc_write (RTC_SEC_REG_ADDR, bin2bcd (tmp->tm_sec)); in rtc_set()
176 * Reset the RTC. We setting the date back to 1970-01-01.
214 debug("Set DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n", in ds1307_rtc_set()
215 tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_wday, in ds1307_rtc_set()
216 tm->tm_hour, tm->tm_min, tm->tm_sec); in ds1307_rtc_set()
218 if (tm->tm_year < 1970 || tm->tm_year > 2069) in ds1307_rtc_set()
221 buf[RTC_YR_REG_ADDR] = bin2bcd(tm->tm_year % 100); in ds1307_rtc_set()
222 buf[RTC_MON_REG_ADDR] = bin2bcd(tm->tm_mon); in ds1307_rtc_set()
223 buf[RTC_DAY_REG_ADDR] = bin2bcd(tm->tm_wday + 1); in ds1307_rtc_set()
224 buf[RTC_DATE_REG_ADDR] = bin2bcd(tm->tm_mday); in ds1307_rtc_set()
225 buf[RTC_HR_REG_ADDR] = bin2bcd(tm->tm_hour); in ds1307_rtc_set()
226 buf[RTC_MIN_REG_ADDR] = bin2bcd(tm->tm_min); in ds1307_rtc_set()
227 buf[RTC_SEC_REG_ADDR] = bin2bcd(tm->tm_sec); in ds1307_rtc_set()
259 return -1; in ds1307_rtc_get()
280 tm->tm_sec = bcd2bin(buf[RTC_SEC_REG_ADDR] & 0x7F); in ds1307_rtc_get()
281 tm->tm_min = bcd2bin(buf[RTC_MIN_REG_ADDR] & 0x7F); in ds1307_rtc_get()
282 tm->tm_hour = bcd2bin(buf[RTC_HR_REG_ADDR] & 0x3F); in ds1307_rtc_get()
283 tm->tm_mday = bcd2bin(buf[RTC_DATE_REG_ADDR] & 0x3F); in ds1307_rtc_get()
284 tm->tm_mon = bcd2bin(buf[RTC_MON_REG_ADDR] & 0x1F); in ds1307_rtc_get()
285 tm->tm_year = bcd2bin(buf[RTC_YR_REG_ADDR]) + in ds1307_rtc_get()
288 tm->tm_wday = bcd2bin((buf[RTC_DAY_REG_ADDR] - 1) & 0x07); in ds1307_rtc_get()
289 tm->tm_yday = 0; in ds1307_rtc_get()
290 tm->tm_isdst = 0; in ds1307_rtc_get()
292 debug("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n", in ds1307_rtc_get()
293 tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_wday, in ds1307_rtc_get()
294 tm->tm_hour, tm->tm_min, tm->tm_sec); in ds1307_rtc_get()
327 .reset = ds1307_rtc_reset,
339 .name = "rtc-ds1307",