Add support for Faraday RTC IP FTRTC
PATCH 1/1 Add support for Faraday RTC IP FTRTC
This patch adds support for Faraday Technology RTC IP - FTRTC
---
drivers/rtc/ftrtc.c +110 -0
@@ -0,0 +1,110 @@ +/* +* Faraday FTRTC Real Time Clock +* +* (C) Copyright 2009 Faraday Technology +* Po-Yu Chuang <[email protected]> +* +* 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 (); +} +
drivers/rtc/ftrtc.h +44 -0
44 lines not on this page · raw message
drivers/rtc/Makefile +1 -0
@@ -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
PATCH 1/1 Add support for Faraday RTC IP FTRTC
Dear PoYu_Chuang,
drivers/rtc/ftrtc.c
Quoted 10 lines · In message <[email protected]> you wrote:
This patch adds support for Faraday Technology RTC IP - FTRTC
Signed-off-by Po-Yu Chuang <[email protected]>---
diff -ruNu-boot-2009.03/drivers/rtc/ftrtc.cFA5A320LINUX26_u-boot/drivers/rtc/ftrtc.cdrivers/rtc/ftrtc.c +1
-0@@ -0,0 +1,110 @@ +static unsigned int rtc =CONFIG_SYS_RTC_BASE ;
Please use a proper C structure to describe the RTC; do not use base address plus offsets.
drivers/rtc/ftrtc.c line 36
Quoted 5 lines
drivers/rtc/ftrtc.c +5
-0+static void +ftrtc_enable (void ) +{ +outl (FTRTC_CR_ENABLE , rtc +FTRTC_OFFSET_CR ); +}
outl() is not portable across architectures?
drivers/rtc/ftrtc.c line 55
Quoted 6 lines
drivers/rtc/ftrtc.c +6
-0+ 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);
inl() is not portable across architectures?
drivers/rtc/ftrtc.c line 70
Quoted 4 lines
drivers/rtc/ftrtc.c +4
-0+{ +unsigned long now; + +debug ("rtc_get(): record register: %x\n" ,inl (rtc +FTRTC_OFFSET_RECORD ));
Line too long.
Quoted 4 lines
diff -ruN
u-boot-2009.03/drivers/rtc/ftrtc.hFA5A320LINUX26_u-boot/drivers/rtc/ftrtc.hdrivers/rtc/ftrtc.h +0
-0@@ -0,0 +1,44 @@
...
drivers/rtc/ftrtc.h line 33
Quoted 12 lines
drivers/rtc/ftrtc.h +12
-0+#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
Please use a proper C structure to describe the RTC; do not use base address plus offsets.
drivers/rtc/ftrtc.h line 42
Quoted 8 lines
drivers/rtc/ftrtc.h +8
-0+/* +* 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 */
Lines too long.
Best regards,
Wolfgang Denk
Signature · 8 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: [email protected] There is a theory which states that if ever anyone discovers exactly what the Universe is for and why it is here, it will instantly dis- appear and be replaced by something even more bizarre and inexpli- cable. There is another theory which states that this has already happened. -- Douglas Adams, "The Hitchhiker's Guide to the Galaxy"