* [U-Boot] [PATCH 2/3] A320: driver for FTRTC010 real time clock
@ 2009-06-23 13:35 Po-Yu Chuang
2009-06-23 23:47 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 1 reply; 4+ messages in thread
From: Po-Yu Chuang @ 2009-06-23 13:35 UTC (permalink / raw)
To: u-boot
This patch adds an FTRTC010 driver for Faraday A320 evaluation board.
Signed-off-by: Po-Yu Chuang <ratbert@faraday-tech.com>
---
Index: drivers/rtc/Makefile
===================================================================
RCS file: /usr/local/cvsroot/ctd/u-boot-2009.06/drivers/rtc/Makefile,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- drivers/rtc/Makefile 15 Jun 2009 06:47:53 -0000 1.1.1.1
+++ drivers/rtc/Makefile 16 Jun 2009 13:45:55 -0000 1.2
@@ -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) += ftrtc010.o
COBJS-$(CONFIG_RTC_ISL1208) += isl1208.o
COBJS-$(CONFIG_RTC_M41T11) += m41t11.o
COBJS-$(CONFIG_RTC_M41T60) += m41t60.o
Index: drivers/rtc/ftrtc010.c
===================================================================
RCS file: drivers/rtc/ftrtc010.c
diff -N drivers/rtc/ftrtc010.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ drivers/rtc/ftrtc010.c 23 Jun 2009 06:12:15 -0000 1.5
@@ -0,0 +1,125 @@
+/*
+ * Faraday FTRTC Real Time Clock
+ *
+ * (C) Copyright 2009 Faraday Technology
+ * Po-Yu Chuang <ratbert@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 <rtc.h>
+
+struct ftrtc010 {
+ unsigned int sec; /* 0x00 */
+ unsigned int min; /* 0x04 */
+ unsigned int hour; /* 0x08 */
+ unsigned int day; /* 0x0c */
+ unsigned int alarm_sec; /* 0x10 */
+ unsigned int alarm_min; /* 0x14 */
+ unsigned int alarm_hour; /* 0x18 */
+ unsigned int record; /* 0x1c */
+ unsigned int cr; /* 0x20 */
+};
+
+/*
+ * RTC Control Register
+ */
+#define FTRTC010_CR_ENABLE (1 << 0)
+#define FTRTC010_CR_INTERRUPT_SEC (1 << 1) /* per second irq */
+#define FTRTC010_CR_INTERRUPT_MIN (1 << 2) /* per minute irq */
+#define FTRTC010_CR_INTERRUPT_HR (1 << 3) /* per hour irq */
+#define FTRTC010_CR_INTERRUPT_DAY (1 << 4) /* per day irq */
+
+static volatile struct ftrtc010 *rtc = (struct ftrtc010 *)CONFIG_SYS_RTC_BASE;
+
+static void ftrtc_enable (void)
+{
+ rtc->cr = cpu_to_le32 (FTRTC010_CR_ENABLE);
+}
+
+/*
+ * 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 = le32_to_cpu (rtc->sec);
+ day = le32_to_cpu (rtc->day);
+ hour = le32_to_cpu (rtc->hour);
+ minute = le32_to_cpu (rtc->min);
+ second2 = le32_to_cpu (rtc->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 ("%s(): record register: %x\n",
+ __func__, le32_to_cpu (rtc->record));
+
+ now = ftrtc_time () + le32_to_cpu (rtc->record);
+
+ to_tm (now, tmp);
+
+ return 0;
+}
+
+/*
+ * Set the RTC
+ */
+int rtc_set (struct rtc_time *tmp)
+{
+ unsigned long new;
+ unsigned long now;
+
+ debug ("%s(): DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
+ __func__,
+ 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 ("%s(): write %lx to record register\n", __func__, new - now);
+
+ rtc->record = cpu_to_le32 (new - now);
+
+ return 0;
+}
+
+void rtc_reset (void)
+{
+ debug ("%s()\n", __func__);
+ ftrtc_enable ();
+}
^ permalink raw reply [flat|nested] 4+ messages in thread
* [U-Boot] [PATCH 2/3] A320: driver for FTRTC010 real time clock
2009-06-23 13:35 [U-Boot] [PATCH 2/3] A320: driver for FTRTC010 real time clock Po-Yu Chuang
@ 2009-06-23 23:47 ` Jean-Christophe PLAGNIOL-VILLARD
2009-06-24 5:05 ` Po-Yu Chuang
0 siblings, 1 reply; 4+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2009-06-23 23:47 UTC (permalink / raw)
To: u-boot
> +
> +static volatile struct ftrtc010 *rtc = (struct ftrtc010 *)CONFIG_SYS_RTC_BASE;
> +
> +static void ftrtc_enable (void)
you use it at one please only the reset
> +{
> + rtc->cr = cpu_to_le32 (FTRTC010_CR_ENABLE);
so please move this code there
> +}
> +
> +/*
> + * 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 = le32_to_cpu (rtc->sec);
please use proper accessor
readl/writel
Best Regards,
J.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [U-Boot] [PATCH 2/3] A320: driver for FTRTC010 real time clock
2009-06-23 23:47 ` Jean-Christophe PLAGNIOL-VILLARD
@ 2009-06-24 5:05 ` Po-Yu Chuang
2009-06-24 8:47 ` Detlev Zundel
0 siblings, 1 reply; 4+ messages in thread
From: Po-Yu Chuang @ 2009-06-24 5:05 UTC (permalink / raw)
To: u-boot
Dear Jean-Christophe PLAGNIOL-VILLARD,
2009/6/24 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>:
>> +
>> +static volatile struct ftrtc010 *rtc = (struct ftrtc010 *)CONFIG_SYS_RTC_BASE;
>> +
>> +static void ftrtc_enable (void)
> you use it at one please only the reset
Sorry, I don't understand what do you mean
>> +{
>> + ? ? rtc->cr = cpu_to_le32 (FTRTC010_CR_ENABLE);
> so please move this code there
>> +}
>> +
>> +/*
>> + * 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 ?= le32_to_cpu (rtc->sec);
> please use proper accessor
> readl/writel
Should I use
second = readl(&rtc->sec);
or just
second = rtc->sec;
Best regards,
Po-Yu Chuang
^ permalink raw reply [flat|nested] 4+ messages in thread
* [U-Boot] [PATCH 2/3] A320: driver for FTRTC010 real time clock
2009-06-24 5:05 ` Po-Yu Chuang
@ 2009-06-24 8:47 ` Detlev Zundel
0 siblings, 0 replies; 4+ messages in thread
From: Detlev Zundel @ 2009-06-24 8:47 UTC (permalink / raw)
To: u-boot
Hi Po-Yu Chuang,
> Dear Jean-Christophe PLAGNIOL-VILLARD,
>
> 2009/6/24 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>:
>>> +
>>> +static volatile struct ftrtc010 *rtc = (struct ftrtc010 *)CONFIG_SYS_RTC_BASE;
>>> +
>>> +static void ftrtc_enable (void)
>> you use it at one please only the reset
> Sorry, I don't understand what do you mean
I guess he means that he doesn't like functions which are only called
from one place - he'd rather like to see the code directly at the
callers site.
However I do not agree here - functions have also a documentation
effect, so I vote to keep the function. If neccessary, we could declare
the function inline, but this is really overkill here.
>>> +{
>>> + ? ? rtc->cr = cpu_to_le32 (FTRTC010_CR_ENABLE);
>> so please move this code there
>>> +}
>>> +
>>> +/*
>>> + * 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 ?= le32_to_cpu (rtc->sec);
>> please use proper accessor
>> readl/writel
> Should I use
> second = readl(&rtc->sec);
Yep.
Cheers
Detlev
--
BUGS:
It is not yet possible to change operating system by writing to
/proc/sys/kernel/ostype.
-- Linux sysctl(2) man page
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-06-24 8:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-23 13:35 [U-Boot] [PATCH 2/3] A320: driver for FTRTC010 real time clock Po-Yu Chuang
2009-06-23 23:47 ` Jean-Christophe PLAGNIOL-VILLARD
2009-06-24 5:05 ` Po-Yu Chuang
2009-06-24 8:47 ` Detlev Zundel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox