aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sh/boards/dreamcast/rtc.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/sh/boards/dreamcast/rtc.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'arch/sh/boards/dreamcast/rtc.c')
-rw-r--r--arch/sh/boards/dreamcast/rtc.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/arch/sh/boards/dreamcast/rtc.c b/arch/sh/boards/dreamcast/rtc.c
new file mode 100644
index 000000000000..379de1629134
--- /dev/null
+++ b/arch/sh/boards/dreamcast/rtc.c
@@ -0,0 +1,81 @@
1/* arch/sh/kernel/rtc-aica.c
2 *
3 * Dreamcast AICA RTC routines.
4 *
5 * Copyright (c) 2001, 2002 M. R. Brown <mrbrown@0xd6.org>
6 * Copyright (c) 2002 Paul Mundt <lethal@chaoticdreams.org>
7 *
8 * Released under the terms of the GNU GPL v2.0.
9 *
10 */
11
12#include <linux/time.h>
13
14#include <asm/io.h>
15
16extern void (*rtc_get_time)(struct timespec *);
17extern int (*rtc_set_time)(const time_t);
18
19/* The AICA RTC has an Epoch of 1/1/1950, so we must subtract 20 years (in
20 seconds to get the standard Unix Epoch when getting the time, and add 20
21 years when setting the time. */
22#define TWENTY_YEARS ((20 * 365LU + 5) * 86400)
23
24/* The AICA RTC is represented by a 32-bit seconds counter stored in 2 16-bit
25 registers.*/
26#define AICA_RTC_SECS_H 0xa0710000
27#define AICA_RTC_SECS_L 0xa0710004
28
29/**
30 * aica_rtc_gettimeofday - Get the time from the AICA RTC
31 * @ts: pointer to resulting timespec
32 *
33 * Grabs the current RTC seconds counter and adjusts it to the Unix Epoch.
34 */
35void aica_rtc_gettimeofday(struct timespec *ts) {
36 unsigned long val1, val2;
37
38 do {
39 val1 = ((ctrl_inl(AICA_RTC_SECS_H) & 0xffff) << 16) |
40 (ctrl_inl(AICA_RTC_SECS_L) & 0xffff);
41
42 val2 = ((ctrl_inl(AICA_RTC_SECS_H) & 0xffff) << 16) |
43 (ctrl_inl(AICA_RTC_SECS_L) & 0xffff);
44 } while (val1 != val2);
45
46 ts->tv_sec = val1 - TWENTY_YEARS;
47
48 /* Can't get nanoseconds with just a seconds counter. */
49 ts->tv_nsec = 0;
50}
51
52/**
53 * aica_rtc_settimeofday - Set the AICA RTC to the current time
54 * @secs: contains the time_t to set
55 *
56 * Adjusts the given @tv to the AICA Epoch and sets the RTC seconds counter.
57 */
58int aica_rtc_settimeofday(const time_t secs) {
59 unsigned long val1, val2;
60 unsigned long adj = secs + TWENTY_YEARS;
61
62 do {
63 ctrl_outl((adj & 0xffff0000) >> 16, AICA_RTC_SECS_H);
64 ctrl_outl((adj & 0xffff), AICA_RTC_SECS_L);
65
66 val1 = ((ctrl_inl(AICA_RTC_SECS_H) & 0xffff) << 16) |
67 (ctrl_inl(AICA_RTC_SECS_L) & 0xffff);
68
69 val2 = ((ctrl_inl(AICA_RTC_SECS_H) & 0xffff) << 16) |
70 (ctrl_inl(AICA_RTC_SECS_L) & 0xffff);
71 } while (val1 != val2);
72
73 return 0;
74}
75
76void aica_time_init(void)
77{
78 rtc_get_time = aica_rtc_gettimeofday;
79 rtc_set_time = aica_rtc_settimeofday;
80}
81