From: Heiko Schocher <hs@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/2] rtc: add support for Micro Crystal RV-3029-C2 RTC
Date: Wed, 12 Jan 2011 08:20:05 +0100 [thread overview]
Message-ID: <1294816806-32614-1-git-send-email-hs@denx.de> (raw)
Signed-off-by: Heiko Schocher <hs@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 0000000..3ebc768
--- /dev/null
+++ b/drivers/rtc/rv3029.c
@@ -0,0 +1,124 @@
+/*
+ * (C) Copyright 2010
+ * Heiko Schocher, DENX Software Engineering, hs at 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_LEN 7
+
+#define RV3029C2_W_SECONDS 0x00
+#define RV3029C2_W_MINUTES 0x01
+#define RV3029C2_W_HOURS 0x02
+#define RV3029C2_W_DATE 0x03
+#define RV3029C2_W_DAYS 0x04
+#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,
+ buf, RTC_RV3029_PAGE_LEN);
+
+ /* give the RTC some time to update */
+ udelay(1000);
+ return 0;
+}
+
+void rtc_reset (void)
+{
+ int ret;
+ unsigned char buf[RTC_RV3029_PAGE_LEN];
+
+ buf[0] = RTC_RV3029_CTRL_SYS_R;
+ ret = i2c_write(CONFIG_SYS_I2C_RTC_ADDR, RTC_RV3029_CTRL_RESET, 1,
+ buf, 1);
+}
--
1.7.3.4
next reply other threads:[~2011-01-12 7:20 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-12 7:20 Heiko Schocher [this message]
2011-01-12 7:20 ` [U-Boot] [PATCH 2/2] mpc5200, digsy_mtc: add support for rev5 board version Heiko Schocher
2011-01-12 7:59 ` Wolfgang Denk
2011-01-12 9:15 ` Heiko Schocher
2011-01-12 9:37 ` Wolfgang Denk
2011-01-12 10:00 ` Detlev Zundel
2011-01-12 10:26 ` Heiko Schocher
2011-01-12 13:42 ` Wolfgang Denk
2011-01-12 10:20 ` Detlev Zundel
2011-01-12 13:39 ` Stefan Roese
2011-01-13 7:25 ` [U-Boot] [PATCH 2/2 v2] " Heiko Schocher
2011-01-14 10:42 ` Detlev Zundel
2011-01-18 22:35 ` Wolfgang Denk
2011-01-18 22:35 ` [U-Boot] [PATCH 1/2] rtc: add support for Micro Crystal RV-3029-C2 RTC Wolfgang Denk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1294816806-32614-1-git-send-email-hs@denx.de \
--to=hs@denx.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.