2 * Freescale i.MX27 RTC Driver
4 * Copyright (C) 2012 Philippe Reynes <tremyfr@yahoo.fr>
6 * SPDX-License-Identifier: GPL-2.0+
12 #include <asm/arch/imx-regs.h>
15 #define HOUR_MASK 0x1f
19 int rtc_get(struct rtc_time *time)
21 struct rtc_regs *rtc_regs = (struct rtc_regs *)IMX_RTC_BASE;
22 uint32_t day, hour, min, sec;
24 day = readl(&rtc_regs->dayr);
25 hour = readl(&rtc_regs->hourmin);
26 sec = readl(&rtc_regs->seconds);
28 min = (hour >> MIN_SHIFT) & MIN_MASK;
29 hour = (hour >> HOUR_SHIFT) & HOUR_MASK;
31 sec += min * 60 + hour * 3600 + day * 24 * 3600;
38 int rtc_set(struct rtc_time *time)
40 struct rtc_regs *rtc_regs = (struct rtc_regs *)IMX_RTC_BASE;
41 uint32_t day, hour, min, sec;
43 sec = rtc_mktime(time);
45 day = sec / (24 * 3600);
46 sec = sec % (24 * 3600);
52 hour = (hour & HOUR_MASK) << HOUR_SHIFT;
53 hour |= (min & MIN_MASK) << MIN_SHIFT;
55 writel(day, &rtc_regs->dayr);
56 writel(hour, &rtc_regs->hourmin);
57 writel(sec, &rtc_regs->seconds);
64 struct rtc_regs *rtc_regs = (struct rtc_regs *)IMX_RTC_BASE;
66 writel(0, &rtc_regs->dayr);
67 writel(0, &rtc_regs->hourmin);
68 writel(0, &rtc_regs->seconds);