blob: 563e8a4a3610da545394c852b5baa9dd1c00ba22 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
trem78befb62012-08-08 07:04:46 +00002/*
3 * Freescale i.MX27 RTC Driver
4 *
5 * Copyright (C) 2012 Philippe Reynes <tremyfr@yahoo.fr>
trem78befb62012-08-08 07:04:46 +00006 */
7
8#include <common.h>
9#include <rtc.h>
10#include <asm/io.h>
11#include <asm/arch/imx-regs.h>
12
13#define HOUR_SHIFT 8
14#define HOUR_MASK 0x1f
15#define MIN_SHIFT 0
16#define MIN_MASK 0x3f
17
18int rtc_get(struct rtc_time *time)
19{
20 struct rtc_regs *rtc_regs = (struct rtc_regs *)IMX_RTC_BASE;
21 uint32_t day, hour, min, sec;
22
23 day = readl(&rtc_regs->dayr);
24 hour = readl(&rtc_regs->hourmin);
25 sec = readl(&rtc_regs->seconds);
26
27 min = (hour >> MIN_SHIFT) & MIN_MASK;
28 hour = (hour >> HOUR_SHIFT) & HOUR_MASK;
29
30 sec += min * 60 + hour * 3600 + day * 24 * 3600;
31
Simon Glass9f9276c2015-04-20 12:37:18 -060032 rtc_to_tm(sec, time);
trem78befb62012-08-08 07:04:46 +000033
34 return 0;
35}
36
37int rtc_set(struct rtc_time *time)
38{
39 struct rtc_regs *rtc_regs = (struct rtc_regs *)IMX_RTC_BASE;
40 uint32_t day, hour, min, sec;
41
Simon Glass71420982015-04-20 12:37:19 -060042 sec = rtc_mktime(time);
trem78befb62012-08-08 07:04:46 +000043
44 day = sec / (24 * 3600);
45 sec = sec % (24 * 3600);
46 hour = sec / 3600;
47 sec = sec % 3600;
48 min = sec / 60;
49 sec = sec % 60;
50
51 hour = (hour & HOUR_MASK) << HOUR_SHIFT;
52 hour |= (min & MIN_MASK) << MIN_SHIFT;
53
54 writel(day, &rtc_regs->dayr);
55 writel(hour, &rtc_regs->hourmin);
56 writel(sec, &rtc_regs->seconds);
57
58 return 0;
59}
60
61void rtc_reset(void)
62{
Chris Packhamfbd81792018-03-21 15:40:35 +130063 /* nothing to do */
trem78befb62012-08-08 07:04:46 +000064}