Re: [U-Boot] [PATCH 1/2] rtc: add support for Micro Crystal RV-3029-C2 RTC

2011-01-18 Thread Wolfgang Denk
Dear Heiko Schocher,

In message 1294816806-32614-1-git-send-email...@denx.de you wrote:
 Signed-off-by: Heiko Schocher h...@denx.de
 ---
  drivers/rtc/Makefile |1 +
  drivers/rtc/rv3029.c |  124 
 ++
  2 files changed, 125 insertions(+), 0 deletions(-)
  create mode 100644 drivers/rtc/rv3029.c

Applied, thanks.

Best regards,

Wolfgang Denk

-- 
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: w...@denx.de
It's all Klatchian to me.
- Terry Pratchett  Stephen Briggs, _The Discworld Companion_
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 1/2] rtc: add support for Micro Crystal RV-3029-C2 RTC

2011-01-11 Thread Heiko Schocher
Signed-off-by: Heiko Schocher h...@denx.de
---
 drivers/rtc/Makefile |1 +
 drivers/rtc/rv3029.c |  124 ++
 2 files changed, 125 insertions(+), 0 deletions(-)
 create mode 100644 drivers/rtc/rv3029.c

diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 916d73f..e4be4a4 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -60,6 +60,7 @@ COBJS-$(CONFIG_RTC_PL031) += pl031.o
 COBJS-$(CONFIG_RTC_PT7C4338) += pt7c4338.o
 COBJS-$(CONFIG_RTC_RS5C372A) += rs5c372.o
 COBJS-$(CONFIG_RTC_RTC4543) += rtc4543.o
+COBJS-$(CONFIG_RTC_RV3029) += rv3029.o
 COBJS-$(CONFIG_RTC_RX8025) += rx8025.o
 COBJS-$(CONFIG_RTC_S3C24X0) += s3c24x0_rtc.o
 COBJS-$(CONFIG_RTC_S3C44B0) += s3c44b0_rtc.o
diff --git a/drivers/rtc/rv3029.c b/drivers/rtc/rv3029.c
new file mode 100644
index 000..3ebc768
--- /dev/null
+++ b/drivers/rtc/rv3029.c
@@ -0,0 +1,124 @@
+/*
+ * (C) Copyright 2010
+ * Heiko Schocher, DENX Software Engineering, h...@denx.de
+ *
+ * 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
+ */
+#include common.h
+#include command.h
+#include i2c.h
+#include rtc.h
+
+#define RTC_RV3029_CTRL_RESET  0x04
+#define RTC_RV3029_CTRL_SYS_R  (1  4)
+
+#define RTC_RV3029_CLOCK_PAGE  0x08
+#define RTC_RV3029_PAGE_LEN7
+
+#define RV3029C2_W_SECONDS 0x00
+#define RV3029C2_W_MINUTES 0x01
+#define RV3029C2_W_HOURS   0x02
+#define RV3029C2_W_DATE0x03
+#define RV3029C2_W_DAYS0x04
+#define RV3029C2_W_MONTHS  0x05
+#define RV3029C2_W_YEARS   0x06
+
+#define RV3029C2_REG_HR_12_24  (1  6)  /* 24h/12h mode */
+#define RV3029C2_REG_HR_PM (1  5)  /* PM/AM bit in 12h mode */
+
+int rtc_get( struct rtc_time *tmp )
+{
+   int ret;
+   unsigned char buf[RTC_RV3029_PAGE_LEN];
+
+   ret = i2c_read(CONFIG_SYS_I2C_RTC_ADDR, RTC_RV3029_CLOCK_PAGE, 1, buf, \
+   RTC_RV3029_PAGE_LEN);
+   if (ret) {
+   printf(%s: error reading RTC: %x\n, __func__, ret);
+   return -1;
+   }
+   tmp-tm_sec  = bcd2bin( buf[RV3029C2_W_SECONDS]  0x7f);
+   tmp-tm_min  = bcd2bin( buf[RV3029C2_W_MINUTES]  0x7f);
+   if (buf[RV3029C2_W_HOURS]  RV3029C2_REG_HR_12_24) {
+   /* 12h format */
+   tmp-tm_hour = bcd2bin(buf[RV3029C2_W_HOURS]  0x1f);
+   if (buf[RV3029C2_W_HOURS]  RV3029C2_REG_HR_PM)
+   /* PM flag set */
+   tmp-tm_hour += 12;
+   } else
+   tmp-tm_hour = bcd2bin(buf[RV3029C2_W_HOURS]  0x3f);
+
+   tmp-tm_mday = bcd2bin( buf[RV3029C2_W_DATE]  0x3F );
+   tmp-tm_mon  = bcd2bin( buf[RV3029C2_W_MONTHS]  0x1F );
+   tmp-tm_wday = bcd2bin( buf[RV3029C2_W_DAYS]  0x07 );
+   /* RTC supports only years  1999 */
+   tmp-tm_year = bcd2bin( buf[RV3029C2_W_YEARS]) + 2000;
+   tmp-tm_yday = 0;
+   tmp-tm_isdst = 0;
+
+#ifdef RTC_DEBUG
+   printf( 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 );
+
+#endif
+   return 0;
+}
+
+int rtc_set( struct rtc_time *tmp )
+{
+   int ret;
+   unsigned char buf[RTC_RV3029_PAGE_LEN];
+#ifdef RTC_DEBUG
+   printf( 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);
+#endif
+
+   if (tmp-tm_year  2000) {
+   printf(RTC: year %d  2000 not possible\n, tmp-tm_year);
+   return -1;
+   }
+   buf[RV3029C2_W_SECONDS] = bin2bcd(tmp-tm_sec);
+   buf[RV3029C2_W_MINUTES] = bin2bcd(tmp-tm_min);
+   buf[RV3029C2_W_HOURS] = bin2bcd(tmp-tm_hour);
+   /* set 24h format */
+   buf[RV3029C2_W_HOURS] = ~RV3029C2_REG_HR_12_24;
+   buf[RV3029C2_W_DATE] = bin2bcd(tmp-tm_mday);
+   buf[RV3029C2_W_DAYS] = bin2bcd(tmp-tm_wday);
+   buf[RV3029C2_W_MONTHS] = bin2bcd(tmp-tm_mon);
+   tmp-tm_year -= 2000;
+   buf[RV3029C2_W_YEARS] = bin2bcd(tmp-tm_year);
+   ret = i2c_write(CONFIG_SYS_I2C_RTC_ADDR, RTC_RV3029_CLOCK_PAGE, 1,
+