1
From: Jason Cooper <u-boot@lakedaemon.net>
3
rewrite of the not-merged code from Globalscale Technologies. This RTC is
4
known to exist in the DreamPlug platform and is accessed via two registers.
6
Signed-off-by: Jason Cooper <u-boot@lakedaemon.net>
9
- I completely rewrote this, should I add mention of Commercial/GPL2+/BSD
10
(pick your license) source files I based it on?
11
http://people.debian.org/~clint/dreamplug/dreamplug-uboot-gti.tar.gz
12
- The link is a dirty git tree. The uncommitted stuff is how they
13
modified Guruplug u-boot to work on the Dreamplug.
14
- chmod -x the changed files to undo the windows fs stuff.
15
- the usb storage changes are already in.
16
- I'm close on the SPI flash stuff.
17
- This patch is the RTC driver.
18
- Their MPP cfg is cleaner than mine, I'll use theirs.
19
- I'll add the clock stuff in a future patch.
20
- I feel that register definitions should be somewhere else, like SoC code.
21
But I don't know if this is Dreamplug-specific, kirkwood-specific, or other?
22
- common/cmd_date.c assumes I2C interface, is that harmless?
23
- common/cmd_date.c checks return value. The register ops have no return
24
value. I assume it's safe to always return zero?
25
- Is there an easy way to calc the day of the year based on the info in the
26
date register? I don't like leaving that set ot zero.
27
- This is compile-tested. Once I get back to my Dreamplug, I will test.
28
- checkpatch has 2 warnings about volatile. My understanding is that it is
29
needed when reading/writing registers.
31
drivers/rtc/Makefile | 1 +
32
drivers/rtc/mvinteg_rtc.c | 151 +++++++++++++++++++++++++++++++++++++++++++
33
drivers/rtc/mvinteg_rtc.h | 89 +++++++++++++++++++++++++
34
include/configs/dreamplug.h | 8 ++
35
4 files changed, 249 insertions(+), 0 deletions(-)
36
create mode 100644 drivers/rtc/mvinteg_rtc.c
37
create mode 100644 drivers/rtc/mvinteg_rtc.h
39
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
40
index e4be4a4..ed63e9c 100644
41
--- a/drivers/rtc/Makefile
42
+++ b/drivers/rtc/Makefile
43
@@ -55,6 +55,7 @@ COBJS-$(CONFIG_MCFRTC) += mcfrtc.o
44
COBJS-$(CONFIG_RTC_MK48T59) += mk48t59.o
45
COBJS-$(CONFIG_RTC_MPC5200) += mpc5xxx.o
46
COBJS-$(CONFIG_RTC_MPC8xx) += mpc8xx.o
47
+COBJS-$(CONFIG_RTC_MVINTEG) += mvinteg_rtc.o
48
COBJS-$(CONFIG_RTC_PCF8563) += pcf8563.o
49
COBJS-$(CONFIG_RTC_PL031) += pl031.o
50
COBJS-$(CONFIG_RTC_PT7C4338) += pt7c4338.o
51
diff --git a/drivers/rtc/mvinteg_rtc.c b/drivers/rtc/mvinteg_rtc.c
53
index 0000000..1fcfba5
55
+++ b/drivers/rtc/mvinteg_rtc.c
58
+ * Copyright (C) 2011
59
+ * Jason Cooper <u-boot@lakedaemon.net>
61
+ * See file CREDITS for list of people who contributed to this
64
+ * This program is free software; you can redistribute it and/or
65
+ * modify it under the terms of the GNU General Public License as
66
+ * published by the Free Software Foundation; either version 2 of
67
+ * the License, or (at your option) any later version.
69
+ * This program is distributed in the hope that it will be useful,
70
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
71
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72
+ * GNU General Public License for more details.
74
+ * You should have received a copy of the GNU General Public License
75
+ * along with this program; if not, write to the Free Software
76
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
81
+ * Date & Time support for Marvell Integrated RTC
87
+#include "mvinteg_rtc.h"
89
+/* This RTC does not support century, so we assume 20 */
92
+int rtc_get(struct rtc_time *t)
99
+ /* read the time register */
100
+ time = MV_REG_READ(MVINTEG_RTCTIME_REG);
102
+ /* read the date register */
103
+ date = MV_REG_READ(MVINTEG_RTCDATE_REG);
106
+ tens = ((time & MVINTEG_10SEC_MSK) >> MVINTEG_10SEC_SFT);
107
+ single = ((time & MVINTEG_SEC_MSK) >> MVINTEG_SEC_SFT);
108
+ t->tm_sec = 10 * tens + single;
111
+ tens = ((time & MVINTEG_10MIN_MSK) >> MVINTEG_10MIN_SFT);
112
+ single = ((time & MVINTEG_MIN_MSK) >> MVINTEG_MIN_SFT);
113
+ t->tm_min = 10 * tens + single;
116
+ tens = ((time & MVINTEG_10HOUR_MSK) >> MVINTEG_10HOUR_SFT);
117
+ single = ((time & MVINTEG_HOUR_MSK) >> MVINTEG_HOUR_SFT);
118
+ t->tm_hour = 10 * tens + single;
121
+ t->tm_wday = ((time & MVINTEG_DAY_MSK) >> MVINTEG_DAY_SFT);
125
+ tens = ((date & MVINTEG_10DATE_MSK) >> MVINTEG_10DATE_SFT);
126
+ single = ((date & MVINTEG_DATE_MSK) >> MVINTEG_DATE_SFT);
127
+ t->tm_mday = 10 * tens + single;
130
+ tens = ((date & MVINTEG_10MON_MSK) >> MVINTEG_10MON_SFT);
131
+ single = ((date & MVINTEG_MON_MSK) >> MVINTEG_MON_SFT);
132
+ t->tm_mon = 10 * tens + single;
135
+ tens = ((date * MVINTEG_10YEAR_MSK) >> MVINTEG_10YEAR_SFT);
136
+ single = ((date & MVINTEG_YEAR_MSK) >> MVINTEG_YEAR_SFT);
137
+ t->tm_year = (CENTURY * 100) + (10 * tens) + single;
139
+ /* not supported in this RTC */
146
+int rtc_set(struct rtc_time *t)
154
+ tens = t->tm_sec / 10;
155
+ single = t->tm_sec % 10;
156
+ time |= ((tens << MVINTEG_10SEC_SFT) & MVINTEG_10SEC_MSK) |
157
+ ((single << MVINTEG_SEC_SFT) & MVINTEG_SEC_MSK);
160
+ tens = t->tm_min / 10;
161
+ single = t->tm_min % 10;
162
+ time |= ((tens << MVINTEG_10MIN_SFT) & MVINTEG_10MIN_MSK) |
163
+ ((single << MVINTEG_MIN_SFT) & MVINTEG_MIN_MSK);
166
+ tens = t->tm_hour / 10;
167
+ single = t->tm_hour % 10;
168
+ time |= ((tens << MVINTEG_10HOUR_SFT) & MVINTEG_10HOUR_MSK) |
169
+ ((single << MVINTEG_HOUR_SFT) & MVINTEG_HOUR_MSK);
172
+ single = t->tm_wday + 1;
173
+ time |= ((single << MVINTEG_DAY_SFT) & MVINTEG_DAY_MSK);
176
+ tens = t->tm_mday / 10;
177
+ single = t->tm_mday % 10;
178
+ date |= ((tens << MVINTEG_10DATE_SFT) & MVINTEG_10DATE_MSK) |
179
+ ((single << MVINTEG_DATE_SFT) & MVINTEG_DATE_MSK);
182
+ tens = t->tm_mon / 10;
183
+ single = t->tm_mon % 10;
184
+ date |= ((tens << MVINTEG_10MON_SFT) & MVINTEG_10MON_MSK) |
185
+ ((single << MVINTEG_MON_SFT) & MVINTEG_MON_MSK);
188
+ if ((t->tm_year / 100) != CENTURY)
189
+ printf("Warning: Only century %d supported.\n", CENTURY);
190
+ tens = (t->tm_year % 100) / 10;
191
+ single = (t->tm_year % 100) % 10;
192
+ date |= ((tens << MVINTEG_10YEAR_SFT) & MVINTEG_10YEAR_MSK) |
193
+ ((single << MVINTEG_YEAR_SFT) & MVINTEG_YEAR_MSK);
195
+ /* write the time register */
196
+ MV_REG_WRITE(MVINTEG_RTCTIME_REG, time);
198
+ /* write the date register */
199
+ MV_REG_WRITE(MVINTEG_RTCDATE_REG, date);
204
+void rtc_reset(void)
206
+ /* no init routine for this RTC needed */
208
diff --git a/drivers/rtc/mvinteg_rtc.h b/drivers/rtc/mvinteg_rtc.h
210
index 0000000..08070d9
212
+++ b/drivers/rtc/mvinteg_rtc.h
215
+ * Copyright (C) 2011
216
+ * Jason Cooper <u-boot@lakedaemon.net>
218
+ * See file CREDITS for list of people who contributed to this
221
+ * This program is free software; you can redistribute it and/or
222
+ * modify it under the terms of the GNU General Public License as
223
+ * published by the Free Software Foundation; either version 2 of
224
+ * the License, or (at your option) any later version.
226
+ * This program is distributed in the hope that it will be useful,
227
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
228
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
229
+ * GNU General Public License for more details.
231
+ * You should have received a copy of the GNU General Public License
232
+ * along with this program; if not, write to the Free Software
233
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
234
+ * MA 02111-1307 USA
238
+ * Date & Time support for Marvell Integrated RTC
241
+#ifndef _MVINTEG_RTC_H_
242
+#define _MVINTEG_RTC_H_
244
+#include <compiler.h>
246
+#define INTERNAL_REG_BASE_ADDR 0xf1000000
248
+/* register operations macros */
249
+#define MV_REG_READ(offset) \
251
+ *(volatile unsigned int *)(INTERNAL_REG_BASE_ADDR + offset))
253
+#define MV_REG_WRITE(offset, data) \
255
+ *(volatile unsigned int *)(INTERNAL_REG_BASE_ADDR + offset) = \
256
+ cpu_to_le32(data) \
260
+#define MVINTEG_RTCTIME_REG 0x10300
261
+#define MVINTEG_RTCDATE_REG 0x10304
264
+#define MVINTEG_SEC_SFT 0
265
+#define MVINTEG_SEC_MSK (0xf << MVINTEG_SEC_SFT)
266
+#define MVINTEG_10SEC_SFT 4
267
+#define MVINTEG_10SEC_MSK (0x7 << MVINTEG_10SEC_SFT)
269
+#define MVINTEG_MIN_SFT 8
270
+#define MVINTEG_MIN_MSK (0xf << MVINTEG_MIN_SFT)
271
+#define MVINTEG_10MIN_SFT 12
272
+#define MVINTEG_10MIN_MSK (0x7 << MVINTEG_10MIN_SFT)
274
+#define MVINTEG_HOUR_SFT 16
275
+#define MVINTEG_HOUR_MSK (0xf << MVINTEG_HOUR_SFT)
276
+#define MVINTEG_10HOUR_SFT 20
277
+#define MVINTEG_10HOUR_MSK (0x3 << MVINTEG_10HOUR_SFT)
279
+#define MVINTEG_HRFMT_SFT 22
280
+#define MVINTEG_HRFMT12_MSK (0x1 << MVINTEG_HRFMT_SFT)
281
+#define MVINTEG_HRFMT24_MSK (0x0 << MVINTEG_HRFMT_SFT)
283
+#define MVINTEG_DAY_SFT 24
284
+#define MVINTEG_DAY_MSK (0x7 << MVINTEG_DAY_SFT)
287
+#define MVINTEG_DATE_SFT 0
288
+#define MVINTEG_DATE_MSK (0xf << MVINTEG_DATE_SFT)
289
+#define MVINTEG_10DATE_SFT 4
290
+#define MVINTEG_10DATE_MSK (0x3 << MVINTEG_10DATE_SFT)
292
+#define MVINTEG_MON_SFT 8
293
+#define MVINTEG_MON_MSK (0xf << MVINTEG_MON_SFT)
294
+#define MVINTEG_10MON_SFT 12
295
+#define MVINTEG_10MON_MSK (0x1 << MVINTEG_10MON_SFT)
297
+#define MVINTEG_YEAR_SFT 16
298
+#define MVINTEG_YEAR_MSK (0xf << MVINTEG_YEAR_SFT)
299
+#define MVINTEG_10YEAR_SFT 20
300
+#define MVINTEG_10YEAR_MSK (0xf << MVINTEG_10YEAR_SFT)
303
diff --git a/include/configs/dreamplug.h b/include/configs/dreamplug.h
304
index 6aceed9..ed153fe 100644
305
--- a/include/configs/dreamplug.h
306
+++ b/include/configs/dreamplug.h
308
#define CONFIG_SYS_ATA_IDE0_OFFSET MV_SATA_PORT0_OFFSET
309
#endif /*CONFIG_MVSATA_IDE*/
312
+ * RTC driver configuration
314
+#ifdef CONFIG_CMD_DATE
315
+#define CONFIG_RTC_MVINTEG
316
+#endif /* CONFIG_CMD_DATE */
319
#define CONFIG_SYS_ALT_MEMTEST
321
#endif /* _CONFIG_DREAMPLUG_H */