[U-Boot] [PATCH] Add support for Faraday RTC IP FTRTC

PoYu_Chuang ratbert at ftcpcw82.faraday.com.tw
Tue Mar 31 10:58:35 CEST 2009


This patch adds support for Faraday Technology RTC IP - FTRTC

Signed-off-by: Po-Yu Chuang <ratbert at faraday-tech.com>
---
diff -ruN u-boot-2009.03/drivers/rtc/ftrtc.c FA5A320LINUX26_u-boot/drivers/rtc/ftrtc.c
--- u-boot-2009.03/drivers/rtc/ftrtc.c	1970-01-01 08:00:00.000000000 +0800
+++ FA5A320LINUX26_u-boot/drivers/rtc/ftrtc.c	2009-03-31 16:28:40.000000000 +0800
@@ -0,0 +1,110 @@
+/*
+ * Faraday FTRTC Real Time Clock
+ *
+ * (C) Copyright 2009 Faraday Technology
+ * Po-Yu Chuang <ratbert at faraday-tech.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#undef	DEBUG
+
+#include <config.h>
+#include <common.h>
+#include <asm/io.h>
+#include <rtc.h>
+#include "ftrtc.h"
+
+static unsigned int	rtc	= CONFIG_SYS_RTC_BASE;
+
+static void
+ftrtc_enable(void)
+{
+	outl(FTRTC_CR_ENABLE, rtc + FTRTC_OFFSET_CR);
+}
+
+/*
+ * return current time in seconds
+ */
+static unsigned long
+ftrtc_time(void)
+{
+	unsigned long	day;
+	unsigned long	hour;
+	unsigned long	minute;
+	unsigned long	second;
+	unsigned long	second2;
+
+	do {
+		second	= inl(rtc + FTRTC_OFFSET_SEC);
+		day	= inl(rtc + FTRTC_OFFSET_DAY);
+		hour	= inl(rtc + FTRTC_OFFSET_HOUR);
+		minute	= inl(rtc + FTRTC_OFFSET_MIN);
+		second2	= inl(rtc + FTRTC_OFFSET_SEC);
+	} while (second != second2);
+
+	return day * 24 * 60 * 60 + hour * 60 * 60 + minute * 60 + second;
+}
+
+/*
+ * Get the current time from the RTC
+ */
+
+int
+rtc_get(struct rtc_time *tmp)
+{
+	unsigned long	now;
+
+	debug("rtc_get(): record register: %x\n", inl(rtc + FTRTC_OFFSET_RECORD));
+
+	now = ftrtc_time() + inl(rtc + FTRTC_OFFSET_RECORD);
+
+	to_tm(now, tmp);
+
+	return 0;
+}
+
+/*
+ * Set the RTC
+ */
+int
+rtc_set(struct rtc_time *tmp)
+{
+	unsigned long	new;
+	unsigned long	now;
+
+	debug("rtc_set(): DATE: %4d-%02d-%02d (wday=%d)  TIME: %2d:%02d:%02d\n",
+		tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday,
+		tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+
+	new	= mktime(tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_hour,
+			 tmp->tm_min, tmp->tm_sec);
+
+	now	= ftrtc_time();
+
+	debug("rtc_set(): write %x to record register\n", new - now);
+
+	outl(new - now, rtc + FTRTC_OFFSET_RECORD);
+
+	return 0;
+}
+
+void
+rtc_reset(void)
+{
+	debug("rtc_reset()\n");
+	ftrtc_enable();
+}
+
diff -ruN u-boot-2009.03/drivers/rtc/ftrtc.h FA5A320LINUX26_u-boot/drivers/rtc/ftrtc.h
--- u-boot-2009.03/drivers/rtc/ftrtc.h	1970-01-01 08:00:00.000000000 +0800
+++ FA5A320LINUX26_u-boot/drivers/rtc/ftrtc.h	2009-03-31 15:19:32.000000000 +0800
@@ -0,0 +1,44 @@
+/*
+ * Faraday FTRTC Real Time Clock
+ *
+ * (C) Copyright 2009 Faraday Technology
+ * Po-Yu Chuang <ratbert at faraday-tech.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __FTRTC_H
+#define __FTRTC_H
+
+#define	FTRTC_OFFSET_SEC	0x00
+#define	FTRTC_OFFSET_MIN	0x04
+#define	FTRTC_OFFSET_HOUR	0x08
+#define	FTRTC_OFFSET_DAY	0x0c
+#define	FTRTC_OFFSET_ALRM_SEC	0x10
+#define	FTRTC_OFFSET_ALRM_MIN	0x14
+#define	FTRTC_OFFSET_ALRM_HOUR	0x18
+#define	FTRTC_OFFSET_RECORD	0x1c
+#define	FTRTC_OFFSET_CR		0x20
+
+/*
+ * RTC Control Register
+ */
+#define	FTRTC_CR_ENABLE		(1 << 0)
+#define	FTRTC_CR_INTERRUPT_SEC	(1 << 1)	/* enable interrupt per second */
+#define	FTRTC_CR_INTERRUPT_MIN	(1 << 2)	/* enable interrupt per minute */
+#define	FTRTC_CR_INTERRUPT_HR	(1 << 3)	/* enable interrupt per hour */
+#define	FTRTC_CR_INTERRUPT_DAY	(1 << 4)	/* enable interrupt per day */
+
+#endif	/* __FTRTC_H */
diff -ruN u-boot-2009.03/drivers/rtc/Makefile FA5A320LINUX26_u-boot/drivers/rtc/Makefile
--- u-boot-2009.03/drivers/rtc/Makefile	2009-03-22 05:04:41.000000000 +0800
+++ FA5A320LINUX26_u-boot/drivers/rtc/Makefile	2009-03-25 10:29:04.000000000 +0800
@@ -40,6 +40,7 @@
 COBJS-$(CONFIG_RTC_DS164x) += ds164x.o
 COBJS-$(CONFIG_RTC_DS174x) += ds174x.o
 COBJS-$(CONFIG_RTC_DS3231) += ds3231.o
+COBJS-$(CONFIG_RTC_FTRTC) += ftrtc.o
 COBJS-$(CONFIG_RTC_ISL1208) += isl1208.o
 COBJS-$(CONFIG_RTC_M41T11) += m41t11.o
 COBJS-$(CONFIG_RTC_M41T60) += m41t60.o


More information about the U-Boot mailing list