diff options
author | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2011-09-19 13:45:01 -0400 |
---|---|---|
committer | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2011-09-20 02:09:57 -0400 |
commit | 628daa8d5abfd904a7329a660c5c374212230123 (patch) | |
tree | 83981d6c9566dd6bb16c45ea43938df8ed5d350f /arch/powerpc/platforms/powernv/opal-rtc.c | |
parent | ec27329ffb3b4f619be9f0065c473fcb36ea52ce (diff) |
powerpc/powernv: Add RTC and NVRAM support plus RTAS fallbacks
Implements OPAL RTC and NVRAM support and wire all that up to
the powernv platform.
We use RTAS for RTC as a fallback if available. Using RTAS for nvram
is not supported yet, pending some rework/cleanup and generalization
of the pSeries & CHRP code. We also use RTAS fallbacks for power off
and reboot
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'arch/powerpc/platforms/powernv/opal-rtc.c')
-rw-r--r-- | arch/powerpc/platforms/powernv/opal-rtc.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/arch/powerpc/platforms/powernv/opal-rtc.c b/arch/powerpc/platforms/powernv/opal-rtc.c new file mode 100644 index 000000000000..2aa7641aac9b --- /dev/null +++ b/arch/powerpc/platforms/powernv/opal-rtc.c | |||
@@ -0,0 +1,97 @@ | |||
1 | /* | ||
2 | * PowerNV Real Time Clock. | ||
3 | * | ||
4 | * Copyright 2011 IBM Corp. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * as published by the Free Software Foundation; either version | ||
9 | * 2 of the License, or (at your option) any later version. | ||
10 | */ | ||
11 | |||
12 | |||
13 | #include <linux/kernel.h> | ||
14 | #include <linux/time.h> | ||
15 | #include <linux/bcd.h> | ||
16 | #include <linux/rtc.h> | ||
17 | #include <linux/delay.h> | ||
18 | |||
19 | #include <asm/opal.h> | ||
20 | #include <asm/firmware.h> | ||
21 | |||
22 | static void opal_to_tm(u32 y_m_d, u64 h_m_s_ms, struct rtc_time *tm) | ||
23 | { | ||
24 | tm->tm_year = ((bcd2bin(y_m_d >> 24) * 100) + | ||
25 | bcd2bin((y_m_d >> 16) & 0xff)) - 1900; | ||
26 | tm->tm_mon = bcd2bin((y_m_d >> 8) & 0xff) - 1; | ||
27 | tm->tm_mday = bcd2bin(y_m_d & 0xff); | ||
28 | tm->tm_hour = bcd2bin((h_m_s_ms >> 56) & 0xff); | ||
29 | tm->tm_min = bcd2bin((h_m_s_ms >> 48) & 0xff); | ||
30 | tm->tm_sec = bcd2bin((h_m_s_ms >> 40) & 0xff); | ||
31 | |||
32 | GregorianDay(tm); | ||
33 | } | ||
34 | |||
35 | unsigned long __init opal_get_boot_time(void) | ||
36 | { | ||
37 | struct rtc_time tm; | ||
38 | u32 y_m_d; | ||
39 | u64 h_m_s_ms; | ||
40 | long rc = OPAL_BUSY; | ||
41 | |||
42 | while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) { | ||
43 | rc = opal_rtc_read(&y_m_d, &h_m_s_ms); | ||
44 | if (rc == OPAL_BUSY_EVENT) | ||
45 | opal_poll_events(NULL); | ||
46 | else | ||
47 | mdelay(10); | ||
48 | } | ||
49 | if (rc != OPAL_SUCCESS) | ||
50 | return 0; | ||
51 | opal_to_tm(y_m_d, h_m_s_ms, &tm); | ||
52 | return mktime(tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, | ||
53 | tm.tm_hour, tm.tm_min, tm.tm_sec); | ||
54 | } | ||
55 | |||
56 | void opal_get_rtc_time(struct rtc_time *tm) | ||
57 | { | ||
58 | long rc = OPAL_BUSY; | ||
59 | u32 y_m_d; | ||
60 | u64 h_m_s_ms; | ||
61 | |||
62 | while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) { | ||
63 | rc = opal_rtc_read(&y_m_d, &h_m_s_ms); | ||
64 | if (rc == OPAL_BUSY_EVENT) | ||
65 | opal_poll_events(NULL); | ||
66 | else | ||
67 | mdelay(10); | ||
68 | } | ||
69 | if (rc != OPAL_SUCCESS) | ||
70 | return; | ||
71 | opal_to_tm(y_m_d, h_m_s_ms, tm); | ||
72 | } | ||
73 | |||
74 | int opal_set_rtc_time(struct rtc_time *tm) | ||
75 | { | ||
76 | long rc = OPAL_BUSY; | ||
77 | u32 y_m_d = 0; | ||
78 | u64 h_m_s_ms = 0; | ||
79 | |||
80 | y_m_d |= ((u32)bin2bcd((tm->tm_year + 1900) / 100)) << 24; | ||
81 | y_m_d |= ((u32)bin2bcd((tm->tm_year + 1900) % 100)) << 16; | ||
82 | y_m_d |= ((u32)bin2bcd((tm->tm_mon + 1))) << 8; | ||
83 | y_m_d |= ((u32)bin2bcd(tm->tm_mday)); | ||
84 | |||
85 | h_m_s_ms |= ((u64)bin2bcd(tm->tm_hour)) << 56; | ||
86 | h_m_s_ms |= ((u64)bin2bcd(tm->tm_min)) << 48; | ||
87 | h_m_s_ms |= ((u64)bin2bcd(tm->tm_sec)) << 40; | ||
88 | |||
89 | while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) { | ||
90 | rc = opal_rtc_write(y_m_d, h_m_s_ms); | ||
91 | if (rc == OPAL_BUSY_EVENT) | ||
92 | opal_poll_events(NULL); | ||
93 | else | ||
94 | mdelay(10); | ||
95 | } | ||
96 | return rc == OPAL_SUCCESS ? 0 : -EIO; | ||
97 | } | ||