All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 0/2] at91sam9x: driver to use the internal RTT as RTC
@ 2010-03-29 19:39 Alexander Holler
  2010-03-29 19:39 ` [U-Boot] [PATCH 1/2] at91: add defines for RTT and GPBR Alexander Holler
  0 siblings, 1 reply; 13+ messages in thread
From: Alexander Holler @ 2010-03-29 19:39 UTC (permalink / raw)
  To: u-boot

This driver uses the internal RTT as RTC like the linux driver.

To enable it, these defines are needed:

#define CONFIG_CMD_DATE
#define CONFIG_RTC_AT91SAM9
#define CONFIG_RTC_AT91SAM9_RTT AT91_RTT0_BASE /* for AT91SAM9263 */
#define CONFIG_RTC_AT91SAM9_RTT AT91_RTT_BASE /* AT91SAM9260 or AT91SAM9261 */
#define CONFIG_RTC_AT91SAM9_GPBR 0

Tested with an AT91SAM9263.

Regards,

Alexander Holler

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [U-Boot] [PATCH 1/2] at91: add defines for RTT and GPBR
  2010-03-29 19:39 [U-Boot] [PATCH 0/2] at91sam9x: driver to use the internal RTT as RTC Alexander Holler
@ 2010-03-29 19:39 ` Alexander Holler
  2010-03-29 19:39   ` [U-Boot] [PATCH 2/2] at91sam9x: driver to use the internal RTT as RTC Alexander Holler
                     ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Alexander Holler @ 2010-03-29 19:39 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Alexander Holler <holler@ahsoftware.de>
---
 include/asm-arm/arch-at91/at91sam9260.h |    2 ++
 include/asm-arm/arch-at91/at91sam9261.h |    2 ++
 include/asm-arm/arch-at91/at91sam9263.h |    3 +++
 3 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/include/asm-arm/arch-at91/at91sam9260.h b/include/asm-arm/arch-at91/at91sam9260.h
index a60a081..ec04318 100644
--- a/include/asm-arm/arch-at91/at91sam9260.h
+++ b/include/asm-arm/arch-at91/at91sam9260.h
@@ -56,8 +56,10 @@
 #define AT91_PIO_BASE		0xfffff400
 #define AT91_PMC_BASE		0xfffffc00
 #define AT91_RSTC_BASE		0xfffffd00
+#define AT91_RTT_BASE		0xfffffd20
 #define AT91_PIT_BASE		0xfffffd30
 #define AT91_WDT_BASE		0xfffffd40
+#define AT91_GPR_BASE		0xfffffd50
 
 #ifdef CONFIG_AT91_LEGACY
 
diff --git a/include/asm-arm/arch-at91/at91sam9261.h b/include/asm-arm/arch-at91/at91sam9261.h
index 2952292..7ca0283 100644
--- a/include/asm-arm/arch-at91/at91sam9261.h
+++ b/include/asm-arm/arch-at91/at91sam9261.h
@@ -49,8 +49,10 @@
 #define AT91_PIO_BASE		0xfffff400
 #define AT91_PMC_BASE		0xfffffc00
 #define AT91_RSTC_BASE		0xfffffd00
+#define AT91_RTT_BASE		0xfffffd20
 #define AT91_PIT_BASE		0xfffffd30
 #define AT91_WDT_BASE		0xfffffd40
+#define AT91_GPBR_BASE		0xfffffd50
 
 #ifdef CONFIG_AT91_LEGACY
 
diff --git a/include/asm-arm/arch-at91/at91sam9263.h b/include/asm-arm/arch-at91/at91sam9263.h
index c177bd0..4ada1ce 100644
--- a/include/asm-arm/arch-at91/at91sam9263.h
+++ b/include/asm-arm/arch-at91/at91sam9263.h
@@ -61,8 +61,11 @@
 #define AT91_PIO_BASE		0xfffff200
 #define AT91_PMC_BASE		0xfffffc00
 #define AT91_RSTC_BASE		0xfffffd00
+#define AT91_RTT0_BASE		0xfffffd20
 #define AT91_PIT_BASE		0xfffffd30
 #define AT91_WDT_BASE		0xfffffd40
+#define AT91_RTT1_BASE		0xfffffd50
+#define AT91_GPBR_BASE		0xfffffd60
 
 #ifdef CONFIG_AT91_LEGACY
 
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [U-Boot] [PATCH 2/2] at91sam9x: driver to use the internal RTT as RTC
  2010-03-29 19:39 ` [U-Boot] [PATCH 1/2] at91: add defines for RTT and GPBR Alexander Holler
@ 2010-03-29 19:39   ` Alexander Holler
  2010-03-29 20:39     ` Alexander Holler
  2010-04-03 18:36   ` [U-Boot] [PATCH 1/2] at91: add defines for RTT and GPBR Tom
  2010-04-11 17:23   ` Tom
  2 siblings, 1 reply; 13+ messages in thread
From: Alexander Holler @ 2010-03-29 19:39 UTC (permalink / raw)
  To: u-boot

Based on the linux driver.

Signed-off-by: Alexander Holler <holler@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 0000000..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 <holler@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_MR		0x00		/* Real-time Mode Register */
+#define AT91_RTT_AR		0x04		/* Real-time Alarm Register */
+#define AT91_RTT_VR		0x08		/* Real-time Value Register */
+#define AT91_RTT_RTPRES		(0xffff << 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), CONFIG_RTC_AT91SAM9_RTT + AT91_RTT_ ## field)
+#define gpbr_readl() \
+	readl(AT91_GPBR_BASE + 4 * CONFIG_RTC_AT91SAM9_GPBR)
+#define gpbr_writel(val) \
+	writel((val), AT91_GPBR_BASE + 4 * CONFIG_RTC_AT91SAM9_GPBR)
+
+void rtc_reset(void)
+{
+	u32 mr = rtt_readl(MR);
+
+	/* disable interrupts and reset prescaler */
+	mr &= ~AT91_RTT_RTPRES;
+	mr |= ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN | (AT91_SLOW_CLOCK & AT91_RTT_RTPRES));
+	rtt_writel(MR, mr);
+
+	/* Clear values */
+	gpbr_writel(0);
+	rtt_writel(AR, ALARM_DISABLED);
+
+	/* reset and start the timer */
+	rtt_writel(MR, mr | AT91_RTT_RTTRST);
+
+	DPRINTF("Reset DATE\n");
+}
+
+int rtc_get(struct rtc_time *tmp)
+{
+	u32 secs, secs2;
+	u32 offset;
+
+	u32 mr = rtt_readl(MR);
+	if ((mr & AT91_RTT_RTPRES) != AT91_SLOW_CLOCK) {
+		printf("Clock not initialized, use date (re)set!\n");
+		return 0;
+	}
+
+	/* read current time offset */
+	offset = gpbr_readl();
+	if (offset == 0) {
+		printf("Time not set!\n");
+		return 0;
+	}
+
+	/* reread the counter to help sync the two clock domains */
+	secs = rtt_readl(VR);
+	secs2 = rtt_readl(VR);
+	if (secs != secs2)
+		secs = rtt_readl(VR);
+
+	to_tm (offset+secs, tmp);
+
+	DPRINTF("Get 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 );
+
+	return 0;
+}
+
+int rtc_set(struct rtc_time *tmp)
+{
+	u32 secs = mktime(tmp->tm_year, tmp->tm_mon, tmp->tm_mday,
+			tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+	rtc_reset();
+	gpbr_writel(secs);
+
+	DPRINTF("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);
+
+	return 0;
+}
+
+#endif /* CONFIG_CMD_DATE */
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [U-Boot] [PATCH 2/2] at91sam9x: driver to use the internal RTT as RTC
  2010-03-29 19:39   ` [U-Boot] [PATCH 2/2] at91sam9x: driver to use the internal RTT as RTC Alexander Holler
@ 2010-03-29 20:39     ` Alexander Holler
  2010-03-30 11:17       ` [U-Boot] [PATCH 0/1] at91samm9x: fix for the rtc-driver Alexander Holler
  0 siblings, 1 reply; 13+ messages in thread
From: Alexander Holler @ 2010-03-29 20:39 UTC (permalink / raw)
  To: u-boot

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [U-Boot] [PATCH 0/1] at91samm9x: fix for the rtc-driver
  2010-03-29 20:39     ` Alexander Holler
@ 2010-03-30 11:17       ` Alexander Holler
  2010-03-30 11:17         ` [U-Boot] [PATCH 1/1] at91sam9x: driver to use the internal RTT as RTC Alexander Holler
  0 siblings, 1 reply; 13+ messages in thread
From: Alexander Holler @ 2010-03-30 11:17 UTC (permalink / raw)
  To: u-boot

Hello,

here is corrected patch 2/2 to add an driver for at91sam9x which
uses the internal RTT as RTC. Sorry for not testing my last minute
changes before. It was late. ;)

The previous send patch 1/2 which adds some defines is still needed.

Tested on an AT91SAM9263.

Kind regards,

Alexander Holler

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [U-Boot] [PATCH 1/1] at91sam9x: driver to use the internal RTT as RTC
  2010-03-30 11:17       ` [U-Boot] [PATCH 0/1] at91samm9x: fix for the rtc-driver Alexander Holler
@ 2010-03-30 11:17         ` Alexander Holler
  2010-04-03 18:33           ` Tom
  0 siblings, 1 reply; 13+ messages in thread
From: Alexander Holler @ 2010-03-30 11:17 UTC (permalink / raw)
  To: u-boot

Based on the linux driver.

Signed-off-by: Alexander Holler <holler@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 0000000..d0a263a
--- /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 <holler@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_MR		0x00		/* Real-time Mode Register */
+#define AT91_RTT_AR		0x04		/* Real-time Alarm Register */
+#define AT91_RTT_VR		0x08		/* Real-time Value Register */
+#define AT91_RTT_RTPRES		(0xffff << 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), CONFIG_RTC_AT91SAM9_RTT + AT91_RTT_ ## field)
+#define gpbr_readl() \
+	readl(AT91_GPBR_BASE + 4 * CONFIG_RTC_AT91SAM9_GPBR)
+#define gpbr_writel(val) \
+	writel((val), AT91_GPBR_BASE + 4 * CONFIG_RTC_AT91SAM9_GPBR)
+
+void rtc_reset(void)
+{
+	u32 mr = rtt_readl(MR);
+
+	/* disable interrupts and reset prescaler */
+	mr &= ~(AT91_RTT_RTPRES | AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN);
+	mr |= AT91_SLOW_CLOCK & AT91_RTT_RTPRES;
+	rtt_writel(MR, mr);
+
+	/* Clear values */
+	gpbr_writel(0);
+	rtt_writel(AR, ALARM_DISABLED);
+
+	/* reset and start the timer */
+	rtt_writel(MR, mr | AT91_RTT_RTTRST);
+
+	DPRINTF("Reset DATE\n");
+}
+
+int rtc_get(struct rtc_time *tmp)
+{
+	u32 secs, secs2;
+	u32 offset;
+
+	u32 mr = rtt_readl(MR);
+	if ((mr & AT91_RTT_RTPRES) != AT91_SLOW_CLOCK) {
+		printf("Clock not initialized, use date (re)set!\n");
+		return 0;
+	}
+
+	/* read current time offset */
+	offset = gpbr_readl();
+	if (offset == 0) {
+		printf("Time not set!\n");
+		return 0;
+	}
+
+	/* reread the counter to help sync the two clock domains */
+	secs = rtt_readl(VR);
+	secs2 = rtt_readl(VR);
+	if (secs != secs2)
+		secs = rtt_readl(VR);
+
+	to_tm (offset+secs, tmp);
+
+	DPRINTF("Get 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 );
+
+	return 0;
+}
+
+int rtc_set(struct rtc_time *tmp)
+{
+	u32 secs = mktime(tmp->tm_year, tmp->tm_mon, tmp->tm_mday,
+			tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+	rtc_reset();
+	gpbr_writel(secs);
+
+	DPRINTF("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);
+
+	return 0;
+}
+
+#endif /* CONFIG_CMD_DATE */
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [U-Boot] [PATCH 1/1] at91sam9x: driver to use the internal RTT as RTC
  2010-03-30 11:17         ` [U-Boot] [PATCH 1/1] at91sam9x: driver to use the internal RTT as RTC Alexander Holler
@ 2010-04-03 18:33           ` Tom
  2010-04-03 19:30             ` Alexander Holler
  0 siblings, 1 reply; 13+ messages in thread
From: Tom @ 2010-04-03 18:33 UTC (permalink / raw)
  To: u-boot

Alexander Holler wrote:
> Based on the linux driver.
> 

AT91 is moving away from legacy register access to accessing registers
through structures.  Please convert to this change to the new at91
register access through structures.
See doc/README.at91-soc

> Signed-off-by: Alexander Holler <holler@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 0000000..d0a263a
> --- /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 <holler@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

Could this be converted to use the generic 'debug' macro in include/common.h?

> +
> +/* Defines copied from linux/arch/arm/mach-at91/include/mach/at91_rtt.h */
> +#define AT91_RTT_MR		0x00		/* Real-time Mode Register */
> +#define AT91_RTT_AR		0x04		/* Real-time Alarm Register */
> +#define AT91_RTT_VR		0x08		/* Real-time Value Register */
> +#define AT91_RTT_RTPRES		(0xffff << 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), CONFIG_RTC_AT91SAM9_RTT + AT91_RTT_ ## field)
> +#define gpbr_readl() \
> +	readl(AT91_GPBR_BASE + 4 * CONFIG_RTC_AT91SAM9_GPBR)
> +#define gpbr_writel(val) \
> +	writel((val), AT91_GPBR_BASE + 4 * CONFIG_RTC_AT91SAM9_GPBR)
> +
> +void rtc_reset(void)
> +{
> +	u32 mr = rtt_readl(MR);
> +
> +	/* disable interrupts and reset prescaler */
> +	mr &= ~(AT91_RTT_RTPRES | AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN);
> +	mr |= AT91_SLOW_CLOCK & AT91_RTT_RTPRES;
> +	rtt_writel(MR, mr);
> +
> +	/* Clear values */
> +	gpbr_writel(0);
> +	rtt_writel(AR, ALARM_DISABLED);
> +
> +	/* reset and start the timer */
> +	rtt_writel(MR, mr | AT91_RTT_RTTRST);
> +
> +	DPRINTF("Reset DATE\n");
> +}
> +
> +int rtc_get(struct rtc_time *tmp)
> +{

Change parameter name to something more descriptive.
'tmp' implies used locally and this value is passed back.
Maybe 'tm' as to_tmp(.., struct rtc_time *tm) ?

> +	u32 secs, secs2;
> +	u32 offset;
> +
> +	u32 mr = rtt_readl(MR);
> +	if ((mr & AT91_RTT_RTPRES) != AT91_SLOW_CLOCK) {
> +		printf("Clock not initialized, use date (re)set!\n");
> +		return 0;
> +	}
> +
> +	/* read current time offset */
> +	offset = gpbr_readl();
> +	if (offset == 0) {
> +		printf("Time not set!\n");
> +		return 0;
> +	}
> +
> +	/* reread the counter to help sync the two clock domains */
> +	secs = rtt_readl(VR);
> +	secs2 = rtt_readl(VR);
> +	if (secs != secs2)
> +		secs = rtt_readl(VR);
> +
> +	to_tm (offset+secs, tmp);
> +
> +	DPRINTF("Get 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 );
> +
> +	return 0;
> +}
> +
> +int rtc_set(struct rtc_time *tmp)
> +{

Change tmp here too.

> +	u32 secs = mktime(tmp->tm_year, tmp->tm_mon, tmp->tm_mday,
> +			tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
> +	rtc_reset();
> +	gpbr_writel(secs);
> +
> +	DPRINTF("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);
> +
> +	return 0;
> +}
> +
> +#endif /* CONFIG_CMD_DATE */

Tom

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [U-Boot] [PATCH 1/2] at91: add defines for RTT and GPBR
  2010-03-29 19:39 ` [U-Boot] [PATCH 1/2] at91: add defines for RTT and GPBR Alexander Holler
  2010-03-29 19:39   ` [U-Boot] [PATCH 2/2] at91sam9x: driver to use the internal RTT as RTC Alexander Holler
@ 2010-04-03 18:36   ` Tom
  2010-04-03 20:41     ` Alexander Holler
  2010-04-11 17:23   ` Tom
  2 siblings, 1 reply; 13+ messages in thread
From: Tom @ 2010-04-03 18:36 UTC (permalink / raw)
  To: u-boot

Alexander Holler wrote:
> Signed-off-by: Alexander Holler <holler@ahsoftware.de>
> ---
>  include/asm-arm/arch-at91/at91sam9260.h |    2 ++
>  include/asm-arm/arch-at91/at91sam9261.h |    2 ++
>  include/asm-arm/arch-at91/at91sam9263.h |    3 +++
>  3 files changed, 7 insertions(+), 0 deletions(-)
> 

Ack
This change is fine.
Please include this with the changes to the rtc driver in patch 2/2
In general, include all the patches in a patchset when you make a change
to any one of them.

Thanks
Tom

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [U-Boot] [PATCH 1/1] at91sam9x: driver to use the internal RTT as RTC
  2010-04-03 18:33           ` Tom
@ 2010-04-03 19:30             ` Alexander Holler
  2010-04-05 13:19               ` Tom
  0 siblings, 1 reply; 13+ messages in thread
From: Alexander Holler @ 2010-04-03 19:30 UTC (permalink / raw)
  To: u-boot

Am 03.04.2010 20:33, schrieb Tom:
> Alexander Holler wrote:
>
> Change parameter name to something more descriptive.
> 'tmp' implies used locally and this value is passed back.
> Maybe 'tm' as to_tmp(.., struct rtc_time *tm) ?
>

Maybe someone should place a README in drivers/rtc which reads "Don't 
use this stuff as template" as almost every source there uses this tmp.

--------------------------
aholler at laptopahvpn ~/Source/u-boot/drivers/rtc $ PAGER= git grep rtc_get
bfin_rtc.c:int rtc_get(struct rtc_time *tmp)
ds12887.c:int rtc_get (struct rtc_time *tmp)
ds1302.c:rtc_get(struct rtc_time *tmp)
ds1302.c:               printf("ds1302: rtc_get: Clock was halted, clock 
probably "
ds1306.c:int rtc_get (struct rtc_time *tmp)
ds1306.c:int rtc_get (struct rtc_time *tmp)
ds1307.c:int rtc_get (struct rtc_time *tmp)
ds1337.c:int rtc_get (struct rtc_time *tmp)
ds1374.c:int rtc_get (struct rtc_time *tm){
ds1556.c:int rtc_get( struct rtc_time *tmp )
ds164x.c:int rtc_get( struct rtc_time *tmp )
ds174x.c:int rtc_get( struct rtc_time *tmp )
ds3231.c:int rtc_get (struct rtc_time *tmp)
ftrtc010.c:int rtc_get(struct rtc_time *tmp)
isl1208.c:int rtc_get (struct rtc_time *tmp)
m41t11.c:int rtc_get (struct rtc_time *tmp)
m41t60.c:int rtc_get(struct rtc_time *tmp)
m41t62.c:int rtc_get(struct rtc_time *tm)
m41t94.c:int rtc_get(struct rtc_time *tm)
m48t35ax.c:int rtc_get (struct rtc_time *tmp)
max6900.c:int rtc_get (struct rtc_time *tmp)
mc13783-rtc.c:int rtc_get(struct rtc_time *rtc)
mc146818.c:int rtc_get (struct rtc_time *tmp)
mcfrtc.c:int rtc_get(struct rtc_time *tmp)
mk48t59.c:int rtc_get (struct rtc_time *tmp)
mpc5xxx.c:int rtc_get (struct rtc_time *tmp)
mpc8xx.c:int rtc_get (struct rtc_time *tmp)
pcf8563.c:int rtc_get (struct rtc_time *tmp)
pl031.c:int rtc_get(struct rtc_time *tmp)
rs5c372.c:rtc_get (struct rtc_time *tmp)
rtc4543.c:int rtc_get(struct rtc_time *tm)
rx8025.c:int rtc_get (struct rtc_time *tmp)
s3c24x0_rtc.c:int rtc_get(struct rtc_time *tmp)
s3c44b0_rtc.c:int rtc_get (struct rtc_time* tm)
x1205.c:int rtc_get(struct rtc_time *tm)
--------------------------

Happy easter,

Alexander

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [U-Boot] [PATCH 1/2] at91: add defines for RTT and GPBR
  2010-04-03 18:36   ` [U-Boot] [PATCH 1/2] at91: add defines for RTT and GPBR Tom
@ 2010-04-03 20:41     ` Alexander Holler
  2010-04-05 13:29       ` Tom
  0 siblings, 1 reply; 13+ messages in thread
From: Alexander Holler @ 2010-04-03 20:41 UTC (permalink / raw)
  To: u-boot

Am 03.04.2010 20:36, schrieb Tom:
> Alexander Holler wrote:
>> Signed-off-by: Alexander Holler <holler@ahsoftware.de>
>> ---
>> include/asm-arm/arch-at91/at91sam9260.h | 2 ++
>> include/asm-arm/arch-at91/at91sam9261.h | 2 ++
>> include/asm-arm/arch-at91/at91sam9263.h | 3 +++
>> 3 files changed, 7 insertions(+), 0 deletions(-)
>>
>
> Ack
> This change is fine.
> Please include this with the changes to the rtc driver in patch 2/2
> In general, include all the patches in a patchset when you make a change
> to any one of them.

This two patches are unrelated. This patch just makes incomplete headers 
more complete. If something else would use those two defines and anyone 
would revert the patch for rtc-driver the revert would eleminate the 
defines too.

Happy eastern,

Alexander

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [U-Boot] [PATCH 1/1] at91sam9x: driver to use the internal RTT as RTC
  2010-04-03 19:30             ` Alexander Holler
@ 2010-04-05 13:19               ` Tom
  0 siblings, 0 replies; 13+ messages in thread
From: Tom @ 2010-04-05 13:19 UTC (permalink / raw)
  To: u-boot

Alexander Holler wrote:
> Am 03.04.2010 20:33, schrieb Tom:
>> Alexander Holler wrote:
>>
>> Change parameter name to something more descriptive.
>> 'tmp' implies used locally and this value is passed back.
>> Maybe 'tm' as to_tmp(.., struct rtc_time *tm) ?
>>
> 
> Maybe someone should place a README in drivers/rtc which reads "Don't 
> use this stuff as template" as almost every source there uses this tmp.
> 

The important change for this patch is to move to the new Soc access.

The other uses of rtc_time *tmp, I would also consider as problems.
Changing tmp -> tm for your patch is an improvement.
This is good time to make it.

Tom

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [U-Boot] [PATCH 1/2] at91: add defines for RTT and GPBR
  2010-04-03 20:41     ` Alexander Holler
@ 2010-04-05 13:29       ` Tom
  0 siblings, 0 replies; 13+ messages in thread
From: Tom @ 2010-04-05 13:29 UTC (permalink / raw)
  To: u-boot

Alexander Holler wrote:
> Am 03.04.2010 20:36, schrieb Tom:
>> Alexander Holler wrote:
>>> Signed-off-by: Alexander Holler <holler@ahsoftware.de>
>>> ---
>>> include/asm-arm/arch-at91/at91sam9260.h | 2 ++
>>> include/asm-arm/arch-at91/at91sam9261.h | 2 ++
>>> include/asm-arm/arch-at91/at91sam9263.h | 3 +++
>>> 3 files changed, 7 insertions(+), 0 deletions(-)
>>>
>>
>> Ack
>> This change is fine.
>> Please include this with the changes to the rtc driver in patch 2/2
>> In general, include all the patches in a patchset when you make a change
>> to any one of them.
> 
> This two patches are unrelated. This patch just makes incomplete headers 
> more complete. If something else would use those two defines and anyone 
> would revert the patch for rtc-driver the revert would eleminate the 
> defines too.
> 

Patch 2/2 depends on patch 1/2.

 From 2/2

+#define gpbr_readl() \
+	readl(AT91_GPBR_BASE + 4 * CONFIG_RTC_AT91SAM9_GPBR)
+#define gpbr_writel(val) \
+	writel((val), AT91_GPBR_BASE + 4 * CONFIG_RTC_AT91SAM9_GPBR)

 From 1/2

--- a/include/asm-arm/arch-at91/at91sam9260.h
+++ b/include/asm-arm/arch-at91/at91sam9260.h
@@ -56,8 +56,10 @@
  #define AT91_PIO_BASE		0xfffff400
  #define AT91_PMC_BASE		0xfffffc00
  #define AT91_RSTC_BASE		0xfffffd00
+#define AT91_RTT_BASE		0xfffffd20
  #define AT91_PIT_BASE		0xfffffd30
  #define AT91_WDT_BASE		0xfffffd40
+#define AT91_GPR_BASE		0xfffffd50

 From inspection, at least some boards would have an error if 1/2 was
not applied before 2/2.

1/2 is ok by itself.
I will go ahead and apply this patch.

Thanks
Tom

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [U-Boot] [PATCH 1/2] at91: add defines for RTT and GPBR
  2010-03-29 19:39 ` [U-Boot] [PATCH 1/2] at91: add defines for RTT and GPBR Alexander Holler
  2010-03-29 19:39   ` [U-Boot] [PATCH 2/2] at91sam9x: driver to use the internal RTT as RTC Alexander Holler
  2010-04-03 18:36   ` [U-Boot] [PATCH 1/2] at91: add defines for RTT and GPBR Tom
@ 2010-04-11 17:23   ` Tom
  2 siblings, 0 replies; 13+ messages in thread
From: Tom @ 2010-04-11 17:23 UTC (permalink / raw)
  To: u-boot

Alexander Holler wrote:
> Signed-off-by: Alexander Holler <holler@ahsoftware.de>
> ---
>  include/asm-arm/arch-at91/at91sam9260.h |    2 ++
>  include/asm-arm/arch-at91/at91sam9261.h |    2 ++
>  include/asm-arm/arch-at91/at91sam9263.h |    3 +++
>  3 files changed, 7 insertions(+), 0 deletions(-)
> 
> diff --git a/include/asm-arm/arch-at91/at91sam9260.h b/include/asm-arm/arch-at91/at91sam9260.h

I have applied this to arm/next
Thanks
Tom

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2010-04-11 17:23 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-29 19:39 [U-Boot] [PATCH 0/2] at91sam9x: driver to use the internal RTT as RTC Alexander Holler
2010-03-29 19:39 ` [U-Boot] [PATCH 1/2] at91: add defines for RTT and GPBR Alexander Holler
2010-03-29 19:39   ` [U-Boot] [PATCH 2/2] at91sam9x: driver to use the internal RTT as RTC Alexander Holler
2010-03-29 20:39     ` Alexander Holler
2010-03-30 11:17       ` [U-Boot] [PATCH 0/1] at91samm9x: fix for the rtc-driver Alexander Holler
2010-03-30 11:17         ` [U-Boot] [PATCH 1/1] at91sam9x: driver to use the internal RTT as RTC Alexander Holler
2010-04-03 18:33           ` Tom
2010-04-03 19:30             ` Alexander Holler
2010-04-05 13:19               ` Tom
2010-04-03 18:36   ` [U-Boot] [PATCH 1/2] at91: add defines for RTT and GPBR Tom
2010-04-03 20:41     ` Alexander Holler
2010-04-05 13:29       ` Tom
2010-04-11 17:23   ` Tom

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.