2 * Freescale i.MX27 RTC Driver
4 * Copyright (C) 2012 Philippe Reynes <tremyfr@yahoo.fr>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <asm/arch/imx-regs.h>
28 #define HOUR_MASK 0x1f
32 int rtc_get(struct rtc_time *time)
34 struct rtc_regs *rtc_regs = (struct rtc_regs *)IMX_RTC_BASE;
35 uint32_t day, hour, min, sec;
37 day = readl(&rtc_regs->dayr);
38 hour = readl(&rtc_regs->hourmin);
39 sec = readl(&rtc_regs->seconds);
41 min = (hour >> MIN_SHIFT) & MIN_MASK;
42 hour = (hour >> HOUR_SHIFT) & HOUR_MASK;
44 sec += min * 60 + hour * 3600 + day * 24 * 3600;
51 int rtc_set(struct rtc_time *time)
53 struct rtc_regs *rtc_regs = (struct rtc_regs *)IMX_RTC_BASE;
54 uint32_t day, hour, min, sec;
56 sec = mktime(time->tm_year, time->tm_mon, time->tm_mday,
57 time->tm_hour, time->tm_min, time->tm_sec);
59 day = sec / (24 * 3600);
60 sec = sec % (24 * 3600);
66 hour = (hour & HOUR_MASK) << HOUR_SHIFT;
67 hour |= (min & MIN_MASK) << MIN_SHIFT;
69 writel(day, &rtc_regs->dayr);
70 writel(hour, &rtc_regs->hourmin);
71 writel(sec, &rtc_regs->seconds);
78 struct rtc_regs *rtc_regs = (struct rtc_regs *)IMX_RTC_BASE;
80 writel(0, &rtc_regs->dayr);
81 writel(0, &rtc_regs->hourmin);
82 writel(0, &rtc_regs->seconds);