at91sam9x: driver to use the internal RTT as RTC
Subsystems (2)
cover at91sam9x: driver to use the internal RTT as RTC
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
PATCH 1/2 at91: add defines for RTT and GPBR
--- 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(-)
include/asm-arm/arch-at91/at91sam9260.h +2 -0
@@ -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
include/asm-arm/arch-at91/at91sam9261.h +2 -0
@@ -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
include/asm-arm/arch-at91/at91sam9263.h +3 -0
@@ -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
Signature · 1 line
1.6.2.5
PATCH 2/2 at91sam9x: driver to use the internal RTT as RTC
Based on the linux driver.
--- 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
README +1 -0
@@ -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.
drivers/rtc/Makefile +1 -0
@@ -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)
drivers/rtc/at91sam9-rtc.c new file +162 -0
162 lines not on this page · raw message
Signature · 1 line
1.6.2.5
PATCH 2/2 at91sam9x: driver to use the internal RTT as RTC
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
cover at91samm9x: fix for the rtc-driver
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
PATCH 1/1 at91sam9x: driver to use the internal RTT as RTC
Based on the linux driver.
--- 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
README +1 -0
@@ -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.
drivers/rtc/Makefile +1 -0
@@ -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)
drivers/rtc/at91sam9-rtc.c new file +162 -0
162 lines not on this page · raw message
Signature · 1 line
1.6.2.5
PATCH 1/1 at91sam9x: driver to use the internal RTT as RTC
Quoted 2 lines · Alexander Holler
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
Quoted 98 lines
Signed-off-by Alexander Holler <[email protected]>--- 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.cREADME +1
-0@@ -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.drivers/rtc/Makefile +1
-0@@ -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)drivers/rtc/at91sam9-rtc.c new file +60
-0@@ -0,0 +1,162 @@ +/* +* "RTT as Real Time Clock" driver for AT91SAM9 SoC family +* +* (C) Copyright 2010 +* Alexander Holler <[email protected]> +* +* 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>
drivers/rtc/at91sam9-rtc.c line 70
Quoted 10 lines
drivers/rtc/at91sam9-rtc.c new file +10
-0+ +#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?
Quoted 36 lines
drivers/rtc/at91sam9-rtc.c new file +36
-0+ +/* 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 );
drivers/rtc/at91sam9-rtc.c line 116
Quoted 10 lines
drivers/rtc/at91sam9-rtc.c new file +10
-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) ?
Quoted 23 lines
drivers/rtc/at91sam9-rtc.c new file +23
-0+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);
drivers/rtc/at91sam9-rtc.c line 149
Quoted 10 lines
drivers/rtc/at91sam9-rtc.c new file +10
-0+ +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.
drivers/rtc/at91sam9-rtc.c line 162
Quoted 13 lines
drivers/rtc/at91sam9-rtc.c new file +13
-0+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
PATCH 1/1 at91sam9x: driver to use the internal RTT as RTC
Am 03.04.2010 20:33, schrieb Tom:
Quoted 6 lines
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
PATCH 1/1 at91sam9x: driver to use the internal RTT as RTC
Quoted 11 lines · Alexander Holler
Am 03.04.2010 20:33, schrieb Tom:
Quoted 6 lines
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/rtcwhich 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
PATCH 1/2 at91: add defines for RTT and GPBR
In reply to Alexander HollerQuoted 7 lines · Alexander Holler
Signed-off-by Alexander Holler <[email protected]>--- 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
PATCH 1/2 at91: add defines for RTT and GPBR
Am 03.04.2010 20:36, schrieb Tom:
Quoted 9 lines
Quoted 7 lines · Alexander Holler
Signed-off-by Alexander Holler <[email protected]>---
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(-)
Quoted 5 lines
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
PATCH 1/2 at91: add defines for RTT and GPBR
Quoted 16 lines · Alexander Holler
Am 03.04.2010 20:36, schrieb Tom:
Quoted 9 lines
Quoted 7 lines · Alexander Holler
Signed-off-by Alexander Holler <[email protected]>---
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(-)Quoted 5 lines
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.
Quoted 5 lines
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
include/asm-arm/arch-at91/at91sam9260.h +2 -0
@@ -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
PATCH 1/2 at91: add defines for RTT and GPBR
In reply to Alexander Hollerinclude/asm-arm/arch-at91/at91sam9260.h
Quoted 8 lines · Alexander Holler
Signed-off-by Alexander Holler <[email protected]>--- 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(-)include/asm-arm/arch-at91/at91sam9260.h +0
-0
I have applied this to arm/next
Thanks
Tom