1 // SPDX-License-Identifier: GPL-2.0+
3 * Freescale i.MX27 RTC Driver
5 * Copyright (C) 2012 Philippe Reynes <tremyfr@yahoo.fr>
11 #include <asm/arch/imx-regs.h>
14 #define HOUR_MASK 0x1f
18 int rtc_get(struct rtc_time *time)
20 struct rtc_regs *rtc_regs = (struct rtc_regs *)IMX_RTC_BASE;
21 uint32_t day, hour, min, sec;
23 day = readl(&rtc_regs->dayr);
24 hour = readl(&rtc_regs->hourmin);
25 sec = readl(&rtc_regs->seconds);
27 min = (hour >> MIN_SHIFT) & MIN_MASK;
28 hour = (hour >> HOUR_SHIFT) & HOUR_MASK;
30 sec += min * 60 + hour * 3600 + day * 24 * 3600;
37 int rtc_set(struct rtc_time *time)
39 struct rtc_regs *rtc_regs = (struct rtc_regs *)IMX_RTC_BASE;
40 uint32_t day, hour, min, sec;
42 sec = rtc_mktime(time);
44 day = sec / (24 * 3600);
45 sec = sec % (24 * 3600);
51 hour = (hour & HOUR_MASK) << HOUR_SHIFT;
52 hour |= (min & MIN_MASK) << MIN_SHIFT;
54 writel(day, &rtc_regs->dayr);
55 writel(hour, &rtc_regs->hourmin);
56 writel(sec, &rtc_regs->seconds);