blob: 147a225c6b0a651c5694e7b45ffc1af26601bcfd [file] [log] [blame]
wdenkaffae2b2002-08-17 09:36:01 +00001/*
2 * (C) Copyright 2001
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkaffae2b2002-08-17 09:36:01 +00006 */
7
8/*
9 * Date & Time support for internal RTC of MPC8xx
10 */
11
12/*#define DEBUG*/
13
14#include <common.h>
15#include <command.h>
16#include <rtc.h>
17
Michal Simek871c18d2008-07-14 19:45:37 +020018#if defined(CONFIG_CMD_DATE)
wdenkaffae2b2002-08-17 09:36:01 +000019
20/* ------------------------------------------------------------------------- */
21
Yuri Tikhonovb73a19e2008-03-20 17:56:04 +030022int rtc_get (struct rtc_time *tmp)
wdenkaffae2b2002-08-17 09:36:01 +000023{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020024 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
wdenkaffae2b2002-08-17 09:36:01 +000025 ulong tim;
26
27 tim = immr->im_sit.sit_rtc;
28
Simon Glass9f9276c2015-04-20 12:37:18 -060029 rtc_to_tm(tim, tmp);
wdenkaffae2b2002-08-17 09:36:01 +000030
31 debug ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
32 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
33 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
Yuri Tikhonovb73a19e2008-03-20 17:56:04 +030034
35 return 0;
wdenkaffae2b2002-08-17 09:36:01 +000036}
37
Jean-Christophe PLAGNIOL-VILLARDd1e23192008-09-01 23:06:23 +020038int rtc_set (struct rtc_time *tmp)
wdenkaffae2b2002-08-17 09:36:01 +000039{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020040 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
wdenkaffae2b2002-08-17 09:36:01 +000041 ulong tim;
42
43 debug ( "Set DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
44 tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
45 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
46
Simon Glass71420982015-04-20 12:37:19 -060047 tim = rtc_mktime(tmp);
wdenkaffae2b2002-08-17 09:36:01 +000048
49 immr->im_sitk.sitk_rtck = KAPWR_KEY;
50 immr->im_sit.sit_rtc = tim;
Jean-Christophe PLAGNIOL-VILLARDd1e23192008-09-01 23:06:23 +020051
52 return 0;
wdenkaffae2b2002-08-17 09:36:01 +000053}
54
55void rtc_reset (void)
56{
57 return; /* nothing to do */
58}
59
Jon Loeliger068b60a2007-07-10 10:27:39 -050060#endif