All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Cooper <u-boot@lakedaemon.net>
To: u-boot@lists.denx.de
Subject: [U-Boot] RFC [PATCH 1/5] drivers/rtc: add Marvell Integrated RTC.
Date: Tue, 26 Jul 2011 21:19:22 +0000	[thread overview]
Message-ID: <1311715171-13128-1-git-send-email-u-boot@lakedaemon.net> (raw)
In-Reply-To: <05ec95501d6c02ffeb1bc38d09fdca99142956a3.1307979826.git.u-boot@lakedaemon.net>


Signed-off-by: Jason Cooper <u-boot@lakedaemon.net>
---
 drivers/rtc/Makefile      |    1 +
 drivers/rtc/mvinteg_rtc.c |  151 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/rtc/mvinteg_rtc.h |   89 ++++++++++++++++++++++++++
 3 files changed, 241 insertions(+), 0 deletions(-)
 create mode 100644 drivers/rtc/mvinteg_rtc.c
 create mode 100644 drivers/rtc/mvinteg_rtc.h

diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index e4be4a4..ed63e9c 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -55,6 +55,7 @@ COBJS-$(CONFIG_MCFRTC) += mcfrtc.o
 COBJS-$(CONFIG_RTC_MK48T59) += mk48t59.o
 COBJS-$(CONFIG_RTC_MPC5200) += mpc5xxx.o
 COBJS-$(CONFIG_RTC_MPC8xx) += mpc8xx.o
+COBJS-$(CONFIG_RTC_MVINTEG) += mvinteg_rtc.o
 COBJS-$(CONFIG_RTC_PCF8563) += pcf8563.o
 COBJS-$(CONFIG_RTC_PL031) += pl031.o
 COBJS-$(CONFIG_RTC_PT7C4338) += pt7c4338.o
diff --git a/drivers/rtc/mvinteg_rtc.c b/drivers/rtc/mvinteg_rtc.c
new file mode 100644
index 0000000..295e4f7
--- /dev/null
+++ b/drivers/rtc/mvinteg_rtc.c
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2011
+ * Jason Cooper <u-boot@lakedaemon.net>
+ *
+ * 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
+ */
+
+/*
+ * Date & Time support for Marvell Integrated RTC
+ */
+
+#include <common.h>
+#include <command.h>
+#include <rtc.h>
+#include "mvinteg_rtc.h"
+
+/* This RTC does not support century, so we assume 20 */
+#define CENTURY 20
+
+int rtc_get(struct rtc_time *t)
+{
+	u32 time;
+	u32 date;
+	u8  tens;
+	u8  single;
+
+	/* read the time register */
+	time = MV_REG_READ(MVINTEG_RTCTIME_REG);
+
+	/* read the date register */
+	date = MV_REG_READ(MVINTEG_RTCDATE_REG);
+
+	/* seconds */
+	tens   = ((time & MVINTEG_10SEC_MSK) >> MVINTEG_10SEC_SFT);
+	single = ((time & MVINTEG_SEC_MSK)   >> MVINTEG_SEC_SFT);
+	t->tm_sec = 10 * tens + single;
+
+	/* minutes */
+	tens   = ((time & MVINTEG_10MIN_MSK) >> MVINTEG_10MIN_SFT);
+	single = ((time & MVINTEG_MIN_MSK)   >> MVINTEG_MIN_SFT);
+	t->tm_min = 10 * tens + single;
+
+	/* hours */
+	tens   = ((time & MVINTEG_10HOUR_MSK) >> MVINTEG_10HOUR_SFT);
+	single = ((time & MVINTEG_HOUR_MSK)   >> MVINTEG_HOUR_SFT);
+	t->tm_hour = 10 * tens + single;
+
+	/* day */
+	t->tm_wday = ((time & MVINTEG_DAY_MSK) >> MVINTEG_DAY_SFT);
+	t->tm_wday--;
+
+	/* date */
+	tens   = ((date & MVINTEG_10DATE_MSK) >> MVINTEG_10DATE_SFT);
+	single = ((date & MVINTEG_DATE_MSK)   >> MVINTEG_DATE_SFT);
+	t->tm_mday = 10 * tens + single;
+
+	/* month */
+	tens   = ((date & MVINTEG_10MON_MSK) >> MVINTEG_10MON_SFT);
+	single = ((date & MVINTEG_MON_MSK)   >> MVINTEG_MON_SFT);
+	t->tm_mon = 10 * tens + single;
+
+	/* year */
+	tens   = ((date & MVINTEG_10YEAR_MSK) >> MVINTEG_10YEAR_SFT);
+	single = ((date & MVINTEG_YEAR_MSK)   >> MVINTEG_YEAR_SFT);
+	t->tm_year = (CENTURY * 100) + (10 * tens) + single;
+
+	/* not supported in this RTC */
+	t->tm_yday  = 0;
+	t->tm_isdst = 0;
+
+	return 0;
+}
+
+int rtc_set(struct rtc_time *t)
+{
+	u32 time = 0;
+	u32 date = 0;
+	u32 tens;
+	u32 single;
+
+	/* seconds */
+	tens   = t->tm_sec / 10;
+	single = t->tm_sec % 10;
+	time |= ((tens   << MVINTEG_10SEC_SFT) & MVINTEG_10SEC_MSK) |
+		((single << MVINTEG_SEC_SFT)   & MVINTEG_SEC_MSK);
+
+	/* minutes */
+	tens   = t->tm_min / 10;
+	single = t->tm_min % 10;
+	time |= ((tens   << MVINTEG_10MIN_SFT) & MVINTEG_10MIN_MSK) |
+		((single << MVINTEG_MIN_SFT)   & MVINTEG_MIN_MSK);
+
+	/* hours (24) */
+	tens   = t->tm_hour / 10;
+	single = t->tm_hour % 10;
+	time |= ((tens   << MVINTEG_10HOUR_SFT) & MVINTEG_10HOUR_MSK) |
+		((single << MVINTEG_HOUR_SFT)   & MVINTEG_HOUR_MSK);
+
+	/* day */
+	single = t->tm_wday + 1;
+	time |= ((single << MVINTEG_DAY_SFT) & MVINTEG_DAY_MSK);
+
+	/* date */
+	tens   = t->tm_mday / 10;
+	single = t->tm_mday % 10;
+	date |= ((tens   << MVINTEG_10DATE_SFT) & MVINTEG_10DATE_MSK) |
+		((single << MVINTEG_DATE_SFT)   & MVINTEG_DATE_MSK);
+
+	/* month */
+	tens   = t->tm_mon / 10;
+	single = t->tm_mon % 10;
+	date |= ((tens   << MVINTEG_10MON_SFT) & MVINTEG_10MON_MSK) |
+		((single << MVINTEG_MON_SFT)   & MVINTEG_MON_MSK);
+
+	/* year */
+	if ((t->tm_year / 100) != CENTURY)
+		printf("Warning: Only century %d supported.\n", CENTURY);
+	tens   = (t->tm_year % 100) / 10;
+	single = (t->tm_year % 100) % 10;
+	date |= ((tens   << MVINTEG_10YEAR_SFT) & MVINTEG_10YEAR_MSK) |
+		((single << MVINTEG_YEAR_SFT)   & MVINTEG_YEAR_MSK);
+
+	/* write the time register */
+	MV_REG_WRITE(MVINTEG_RTCTIME_REG, time);
+
+	/* write the date register */
+	MV_REG_WRITE(MVINTEG_RTCDATE_REG, date);
+
+	return 0;
+}
+
+void rtc_reset(void)
+{
+	/* no init routine for this RTC needed */
+}
diff --git a/drivers/rtc/mvinteg_rtc.h b/drivers/rtc/mvinteg_rtc.h
new file mode 100644
index 0000000..522c5d0
--- /dev/null
+++ b/drivers/rtc/mvinteg_rtc.h
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2011
+ * Jason Cooper <u-boot@lakedaemon.net>
+ *
+ * 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
+ */
+
+/*
+ * Date & Time support for Marvell Integrated RTC
+ */
+
+#ifndef _MVINTEG_RTC_H_
+#define _MVINTEG_RTC_H_
+
+#include <compiler.h>
+
+#define INTERNAL_REG_BASE_ADDR 0xf1000000
+
+/* register operations macros */
+#define MV_REG_READ(offset) \
+	le32_to_cpu( \
+	*(volatile unsigned int *)(INTERNAL_REG_BASE_ADDR + offset))
+
+#define MV_REG_WRITE(offset, data) \
+	do { \
+		*(volatile unsigned int *)(INTERNAL_REG_BASE_ADDR + offset) = \
+		cpu_to_le32(data); \
+	} while (0);
+
+/* RTC registers */
+#define MVINTEG_RTCTIME_REG 0x10300
+#define MVINTEG_RTCDATE_REG 0x10304
+
+/* time register */
+#define MVINTEG_SEC_SFT		0
+#define MVINTEG_SEC_MSK		(0xf << MVINTEG_SEC_SFT)
+#define MVINTEG_10SEC_SFT	4
+#define MVINTEG_10SEC_MSK	(0x7 << MVINTEG_10SEC_SFT)
+
+#define MVINTEG_MIN_SFT		8
+#define MVINTEG_MIN_MSK		(0xf << MVINTEG_MIN_SFT)
+#define MVINTEG_10MIN_SFT	12
+#define MVINTEG_10MIN_MSK	(0x7 << MVINTEG_10MIN_SFT)
+
+#define MVINTEG_HOUR_SFT	16
+#define MVINTEG_HOUR_MSK	(0xf << MVINTEG_HOUR_SFT)
+#define MVINTEG_10HOUR_SFT	20
+#define MVINTEG_10HOUR_MSK	(0x3 << MVINTEG_10HOUR_SFT)
+
+#define MVINTEG_HRFMT_SFT	22
+#define MVINTEG_HRFMT12_MSK	(0x1 << MVINTEG_HRFMT_SFT)
+#define MVINTEG_HRFMT24_MSK	(0x0 << MVINTEG_HRFMT_SFT)
+
+#define MVINTEG_DAY_SFT		24
+#define MVINTEG_DAY_MSK		(0x7 << MVINTEG_DAY_SFT)
+
+/* date register */
+#define MVINTEG_DATE_SFT	0
+#define MVINTEG_DATE_MSK	(0xf << MVINTEG_DATE_SFT)
+#define MVINTEG_10DATE_SFT	4
+#define MVINTEG_10DATE_MSK	(0x3 << MVINTEG_10DATE_SFT)
+
+#define MVINTEG_MON_SFT		8
+#define MVINTEG_MON_MSK		(0xf << MVINTEG_MON_SFT)
+#define MVINTEG_10MON_SFT	12
+#define MVINTEG_10MON_MSK	(0x1 << MVINTEG_10MON_SFT)
+
+#define MVINTEG_YEAR_SFT	16
+#define MVINTEG_YEAR_MSK	(0xf << MVINTEG_YEAR_SFT)
+#define MVINTEG_10YEAR_SFT	20
+#define MVINTEG_10YEAR_MSK	(0xf << MVINTEG_10YEAR_SFT)
+
+#endif
-- 
1.7.0.4

  parent reply	other threads:[~2011-07-26 21:19 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-13 15:54 [U-Boot] [PATCH 0/1 v4] RFC: Dreamplug support u-boot at lakedaemon.net
2011-06-13 15:54 ` [U-Boot] [PATCH 1/1 v4] RFC: dreamplug: Initial support u-boot at lakedaemon.net
2011-06-13 15:59   ` Prafulla Wadaskar
2011-06-13 16:07     ` Jason
2011-06-13 16:46       ` Wolfgang Denk
2011-06-13 16:51         ` Jason
2011-07-21 19:36           ` Clint Adams
2011-07-21 20:26             ` Jason
2011-07-21 20:56               ` Clint Adams
2011-07-21 21:17                 ` Jason
2011-07-26 21:19   ` [U-Boot] RFC [PATCH 0/5 v5] add dreamplug support Jason Cooper
2011-09-11 22:10     ` [U-Boot] [PATCH v6] dreamplug: initial board support u-boot at lakedaemon.net
2011-09-12  7:37       ` Igor Grinberg
2011-09-12 11:36         ` Jason
2011-09-12 11:45       ` [U-Boot] [PATCH v7] " Jason Cooper
2011-09-13  7:32         ` Igor Grinberg
2011-09-13 13:53           ` Jason
2011-09-13 11:56         ` Prafulla Wadaskar
2011-09-13 13:00           ` Wolfgang Denk
2011-09-13 14:17             ` Jason
2011-09-14  6:39               ` Prafulla Wadaskar
2011-09-18 17:58                 ` Albert ARIBAUD
2011-09-18 18:27                   ` Albert ARIBAUD
2011-09-18 18:39                   ` Jason
2011-09-18 20:28                     ` Wolfgang Denk
2011-09-18 20:58                       ` Jason
2011-09-18 19:06         ` [U-Boot] [PATCH v8] " Jason Cooper
2011-10-03  4:37           ` Prafulla Wadaskar
2011-07-26 21:19   ` Jason Cooper [this message]
2011-07-27 18:12     ` [U-Boot] RFC [PATCH 1/5] drivers/rtc: add Marvell Integrated RTC Prafulla Wadaskar
2011-07-28  1:22       ` Jason
2011-07-28 19:09         ` Prafulla Wadaskar
2011-07-26 21:19   ` [U-Boot] RFC [PATCH 2/5] arm/kirkwood: print speeds with cpu info Jason Cooper
2011-07-27 18:21     ` Prafulla Wadaskar
2011-07-28  1:31       ` Jason
2011-07-28 19:14         ` Prafulla Wadaskar
2011-10-06 18:13     ` Wolfgang Denk
2011-10-07 12:37       ` Jason
2011-07-26 21:19   ` [U-Boot] RFC [PATCH 3/5] usb: Some EHCI chipsets are slow to respond Jason Cooper
2011-07-27 18:23     ` Prafulla Wadaskar
2011-07-28  1:37       ` Jason
2011-07-28 19:16         ` Prafulla Wadaskar
2011-07-29 14:31           ` Jason
2011-07-26 21:19   ` [U-Boot] RFC [PATCH 4/5 v5] dreamplug: initial board support Jason Cooper
2011-07-27 18:38     ` Prafulla Wadaskar
2011-07-28  2:02       ` Jason
2011-07-28 19:37         ` Prafulla Wadaskar
2011-07-29 15:18           ` Jason
2011-07-29 18:57             ` Prafulla Wadaskar
2011-07-29 19:43               ` Jason
2011-10-06 18:15     ` Wolfgang Denk
2011-10-07 12:40       ` Jason
2011-07-26 21:19   ` [U-Boot] RFC [PATCH 5/5 v5] dreamplug: use MACH_TYPE_DREAMPLUG Jason Cooper
2011-07-27 18:40     ` Prafulla Wadaskar
2011-07-28  2:08       ` Jason
2011-07-28  7:25         ` Bdale Garbee
2011-07-28 12:43           ` Jason
2011-07-28 13:44             ` Bdale Garbee
2011-07-28 19:39         ` Prafulla Wadaskar
2011-07-29 15:25           ` Jason

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=1311715171-13128-1-git-send-email-u-boot@lakedaemon.net \
    --to=u-boot@lakedaemon.net \
    --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.