[U-Boot] [PATCH 1/3] rtc: add driver for internal RTC on kirkwood SoC
Chris Packham
judge.packham at gmail.com
Fri May 13 03:29:20 CEST 2011
From: Luuk Paulussen <luuk.paulussen at alliedtelesis.co.nz>
Signed-off-by: Luuk Paulussen <luuk.paulussen at alliedtelesis.co.nz>
Acked-by: Chris Packham <chris.packham at alliedtelesis.co.nz>
Cc: Prafulla Wadaskar <prafulla at marvell.com>
---
arch/arm/include/asm/arch-kirkwood/kirkwood.h | 2 +
drivers/rtc/Makefile | 1 +
drivers/rtc/kirkwood.c | 76 +++++++++++++++++++++++++
3 files changed, 79 insertions(+), 0 deletions(-)
create mode 100644 drivers/rtc/kirkwood.c
diff --git a/arch/arm/include/asm/arch-kirkwood/kirkwood.h b/arch/arm/include/asm/arch-kirkwood/kirkwood.h
index 0104418..15922eb 100644
--- a/arch/arm/include/asm/arch-kirkwood/kirkwood.h
+++ b/arch/arm/include/asm/arch-kirkwood/kirkwood.h
@@ -50,6 +50,8 @@
#define KW_MPP_BASE (KW_REGISTER(0x10000))
#define KW_GPIO0_BASE (KW_REGISTER(0x10100))
#define KW_GPIO1_BASE (KW_REGISTER(0x10140))
+#define KW_RTC_TIME (KW_REGISTER(0x10300))
+#define KW_RTC_DATE (KW_REGISTER(0x10304))
#define KW_NANDF_BASE (KW_REGISTER(0x10418))
#define KW_SPI_BASE (KW_REGISTER(0x10600))
#define KW_CPU_WIN_BASE (KW_REGISTER(0x20000))
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index e4be4a4..ec064d9 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -43,6 +43,7 @@ COBJS-$(CONFIG_RTC_DS174x) += ds174x.o
COBJS-$(CONFIG_RTC_DS3231) += ds3231.o
COBJS-$(CONFIG_RTC_FTRTC010) += ftrtc010.o
COBJS-$(CONFIG_RTC_ISL1208) += isl1208.o
+COBJS-$(CONFIG_RTC_KIRKWOOD) += kirkwood.o
COBJS-$(CONFIG_RTC_M41T11) += m41t11.o
COBJS-$(CONFIG_RTC_M41T60) += m41t60.o
COBJS-$(CONFIG_RTC_M41T62) += m41t62.o
diff --git a/drivers/rtc/kirkwood.c b/drivers/rtc/kirkwood.c
new file mode 100644
index 0000000..5c9bc81
--- /dev/null
+++ b/drivers/rtc/kirkwood.c
@@ -0,0 +1,76 @@
+/*
+ * Driver for the RTC in Marvell SoCs.
+ *
+ * Based on Linux Kernel driver.
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <common.h>
+#include <command.h>
+#include <rtc.h>
+#include <bcd.h>
+#include <asm/arch/kirkwood.h>
+
+#if defined(CONFIG_CMD_DATE)
+
+#define RTC_TIME_REG_OFFS 0
+#define RTC_SECONDS_OFFS 0
+#define RTC_MINUTES_OFFS 8
+#define RTC_HOURS_OFFS 16
+#define RTC_WDAY_OFFS 24
+#define RTC_HOURS_12H_MODE (1 << 22) /* 12 hours mode */
+
+#define RTC_DATE_REG_OFFS 4
+#define RTC_MDAY_OFFS 0
+#define RTC_MONTH_OFFS 8
+#define RTC_YEAR_OFFS 16
+#define KIRKWOOD_YEAR_BASE 2000
+
+int rtc_set(struct rtc_time *tmp)
+{
+ ulong rtc_reg;
+
+ GregorianDay (tmp);
+
+ rtc_reg = (bin2bcd(tmp->tm_sec) << RTC_SECONDS_OFFS) |
+ (bin2bcd(tmp->tm_min) << RTC_MINUTES_OFFS) |
+ (bin2bcd(tmp->tm_hour) << RTC_HOURS_OFFS) |
+ (bin2bcd(tmp->tm_wday) << RTC_WDAY_OFFS);
+ writel(rtc_reg, KW_RTC_TIME);
+
+ rtc_reg = (bin2bcd(tmp->tm_mday) << RTC_MDAY_OFFS) |
+ (bin2bcd(tmp->tm_mon + 1) << RTC_MONTH_OFFS) |
+ (bin2bcd(tmp->tm_year - KIRKWOOD_YEAR_BASE) << RTC_YEAR_OFFS);
+ writel(rtc_reg, KW_RTC_DATE);
+
+ return 0;
+}
+
+int rtc_get(struct rtc_time *tmp)
+{
+ ulong rtc_time, rtc_date;
+
+ rtc_time = readl(KW_RTC_TIME);
+ rtc_date = readl(KW_RTC_DATE);
+
+ tmp->tm_sec = bcd2bin(rtc_time & 0x7f);
+ tmp->tm_min = bcd2bin((rtc_time >> RTC_MINUTES_OFFS) & 0x7f);
+ tmp->tm_hour = bcd2bin((rtc_time >> RTC_HOURS_OFFS) & 0x3f); /* assume 24 hours mode */
+ tmp->tm_mday = bcd2bin(rtc_date & 0x3f);
+ tmp->tm_wday = bcd2bin((rtc_time >> RTC_WDAY_OFFS) & 0x7);
+ tmp->tm_mon = bcd2bin((rtc_date >> RTC_MONTH_OFFS) & 0x3f) - 1;
+ /* hw counts from year 2000, but tm_year is relative to 0 */
+ tmp->tm_year = bcd2bin((rtc_date >> RTC_YEAR_OFFS) & 0xff) + KIRKWOOD_YEAR_BASE;
+
+ return 0;
+}
+
+void rtc_reset(void)
+{
+ return;
+}
+
+#endif /* CONFIG_CMD_DATE */
--
1.7.4.1
More information about the U-Boot
mailing list