[U-Boot] [PATCH 2/2] at91sam9x: driver to use the internal RTT as RTC

2010-03-29 Thread Alexander Holler
Based on the linux driver.

Signed-off-by: Alexander Holler hol...@ahsoftware.de
---
 README |1 +
 drivers/rtc/Makefile   |1 +
 drivers/rtc/at91sam9-rtc.c |  162 
 3 files changed, 164 insertions(+), 0 deletions(-)
 create mode 100644 drivers/rtc/at91sam9-rtc.c

diff --git a/README b/README
index 940b507..afe2aa6 100644
--- a/README
+++ b/README
@@ -733,6 +733,7 @@ The following options need to be configured:
CONFIG_RTC_ISL1208  - use Intersil ISL1208 RTC
CONFIG_RTC_MAX6900  - use Maxim, Inc. MAX6900 RTC
CONFIG_SYS_RTC_DS1337_NOOSC - Turn off the OSC output for 
DS1337
+   CONFIG_RTC_AT91SAM9 - use internal RTT of AT91SAM9x
 
Note that if the RTC uses I2C, then the I2C interface
must also be configured. See I2C Support, below.
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 772a49a..4a48231 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -62,6 +62,7 @@ COBJS-$(CONFIG_RTC_RX8025) += rx8025.o
 COBJS-$(CONFIG_RTC_S3C24X0) += s3c24x0_rtc.o
 COBJS-$(CONFIG_RTC_S3C44B0) += s3c44b0_rtc.o
 COBJS-$(CONFIG_RTC_X1205) += x1205.o
+COBJS-$(CONFIG_RTC_AT91SAM9) += at91sam9-rtc.o
 
 COBJS  := $(sort $(COBJS-y))
 SRCS   := $(COBJS:.o=.c)
diff --git a/drivers/rtc/at91sam9-rtc.c b/drivers/rtc/at91sam9-rtc.c
new file mode 100644
index 000..5eb7b91
--- /dev/null
+++ b/drivers/rtc/at91sam9-rtc.c
@@ -0,0 +1,162 @@
+/*
+ * RTT as Real Time Clock driver for AT91SAM9 SoC family
+ *
+ * (C) Copyright 2010
+ * Alexander Holler hol...@ahsoftware.de
+ *
+ * Based on rtc-at91sam9.c from Michel Benoit
+ * Based on rtc-at91rm9200.c by Rick Bronson
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+/*
+ * This driver uses two configurable hardware resources that live in the
+ * AT91SAM9 backup power domain (intended to be powered at all times)
+ * to implement the Real Time Clock interfaces
+ *
+ *  - A Real-time Timer (RTT) counts up in seconds from a base time.
+ *We can't assign the counter value (CRTV) ... but we can reset it.
+ *
+ *  - One of the General Purpose Backup Registers (GPBRs) holds the
+ *base time, normally an offset from the beginning of the POSIX
+ *epoch (1970-Jan-1 00:00:00 UTC).  Some systems also include the
+ *local timezone's offset.
+ *
+ * The RTC's value is the RTT counter plus that offset.  The RTC's alarm
+ * is likewise a base (ALMV) plus that offset.
+ *
+ * Not all RTTs will be used as RTCs; some systems have multiple RTTs to
+ * choose from, or a real RTC module.  All systems have multiple GPBR
+ * registers available, likewise usable for more than RTC support.
+ *
+ * In addition to CONFIG_CMD_DATE these additional defines must be set:
+ *
+ * #define CONFIG_RTC_AT91SAM9
+ * #define CONFIG_RTC_AT91SAM9_RTT AT91_RTT0_BASE
+ * #define CONFIG_RTC_AT91SAM9_GPBR 0
+ *
+ */
+#include common.h
+#include command.h
+#include asm/arch/io.h
+#include asm/arch/hardware.h
+#include rtc.h
+
+#if defined(CONFIG_CMD_DATE)
+
+#undef RTC_DEBUG
+
+#ifdef RTC_DEBUG
+#  define DPRINTF(x,args...)   printf(at91sam9-rtc:  x , ##args)
+#else
+#  define DPRINTF(x,args...)
+#endif
+
+/* Defines copied from linux/arch/arm/mach-at91/include/mach/at91_rtt.h */
+#define AT91_RTT_MR0x00/* Real-time Mode Register */
+#define AT91_RTT_AR0x04/* Real-time Alarm Register */
+#define AT91_RTT_VR0x08/* Real-time Value Register */
+#define AT91_RTT_RTPRES(0x  0)   /* Real-time Timer 
Prescaler Value */
+#define AT91_RTT_ALMIEN(1  16)   /* Alarm Interrupt 
Enable */
+#define AT91_RTT_RTTINCIEN (1  17)   /* Real Time Timer Increment 
Interrupt Enable */
+#define AT91_RTT_RTTRST(1  18)   /* Real Time Timer 
Restart */
+
+/*
+ * We store ALARM_DISABLED in ALMV to record that no alarm is set.
+ * It's also the reset value for that field.
+ */
+#define ALARM_DISABLED ((u32)~0)
+
+#define rtt_readl(field) \
+   readl(CONFIG_RTC_AT91SAM9_RTT + AT91_RTT_ ## field)
+#define rtt_writel(field, val) \
+   writel((val), 

Re: [U-Boot] [PATCH 2/2] at91sam9x: driver to use the internal RTT as RTC

2010-03-29 Thread Alexander Holler
Uups,

looks like I have corrupted the set date functionality with one of my 
last minute changes (as I've just discovered). I will send a fixed patch 
2/2 tomorrow.

Regards,

Alexander Holler
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot