.. | .. |
---|
28 | 28 | #include <asm/sections.h> |
---|
29 | 29 | #include <asm/prom.h> |
---|
30 | 30 | #include <asm/io.h> |
---|
31 | | -#include <asm/pgtable.h> |
---|
32 | 31 | #include <asm/machdep.h> |
---|
33 | 32 | #include <asm/time.h> |
---|
34 | 33 | #include <asm/nvram.h> |
---|
.. | .. |
---|
43 | 42 | #else |
---|
44 | 43 | #define DBG(x...) |
---|
45 | 44 | #endif |
---|
46 | | - |
---|
47 | | -/* |
---|
48 | | - * Offset between Unix time (1970-based) and Mac time (1904-based). Cuda and PMU |
---|
49 | | - * times wrap in 2040. If we need to handle later times, the read_time functions |
---|
50 | | - * need to be changed to interpret wrapped times as post-2040. |
---|
51 | | - */ |
---|
52 | | -#define RTC_OFFSET 2082844800 |
---|
53 | 45 | |
---|
54 | 46 | /* |
---|
55 | 47 | * Calibrate the decrementer frequency with the VIA timer 1. |
---|
.. | .. |
---|
75 | 67 | long __init pmac_time_init(void) |
---|
76 | 68 | { |
---|
77 | 69 | s32 delta = 0; |
---|
78 | | -#ifdef CONFIG_NVRAM |
---|
| 70 | +#if defined(CONFIG_NVRAM) && defined(CONFIG_PPC32) |
---|
79 | 71 | int dst; |
---|
80 | 72 | |
---|
81 | 73 | delta = ((s32)pmac_xpram_read(PMAC_XPRAM_MACHINE_LOC + 0x9)) << 16; |
---|
.. | .. |
---|
90 | 82 | return delta; |
---|
91 | 83 | } |
---|
92 | 84 | |
---|
93 | | -#ifdef CONFIG_ADB_CUDA |
---|
94 | | -static time64_t cuda_get_time(void) |
---|
95 | | -{ |
---|
96 | | - struct adb_request req; |
---|
97 | | - time64_t now; |
---|
98 | | - |
---|
99 | | - if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_GET_TIME) < 0) |
---|
100 | | - return 0; |
---|
101 | | - while (!req.complete) |
---|
102 | | - cuda_poll(); |
---|
103 | | - if (req.reply_len != 7) |
---|
104 | | - printk(KERN_ERR "cuda_get_time: got %d byte reply\n", |
---|
105 | | - req.reply_len); |
---|
106 | | - now = (u32)((req.reply[3] << 24) + (req.reply[4] << 16) + |
---|
107 | | - (req.reply[5] << 8) + req.reply[6]); |
---|
108 | | - /* it's either after year 2040, or the RTC has gone backwards */ |
---|
109 | | - WARN_ON(now < RTC_OFFSET); |
---|
110 | | - |
---|
111 | | - return now - RTC_OFFSET; |
---|
112 | | -} |
---|
113 | | - |
---|
114 | | -#define cuda_get_rtc_time(tm) rtc_time64_to_tm(cuda_get_time(), (tm)) |
---|
115 | | - |
---|
116 | | -static int cuda_set_rtc_time(struct rtc_time *tm) |
---|
117 | | -{ |
---|
118 | | - u32 nowtime; |
---|
119 | | - struct adb_request req; |
---|
120 | | - |
---|
121 | | - nowtime = lower_32_bits(rtc_tm_to_time64(tm) + RTC_OFFSET); |
---|
122 | | - if (cuda_request(&req, NULL, 6, CUDA_PACKET, CUDA_SET_TIME, |
---|
123 | | - nowtime >> 24, nowtime >> 16, nowtime >> 8, |
---|
124 | | - nowtime) < 0) |
---|
125 | | - return -ENXIO; |
---|
126 | | - while (!req.complete) |
---|
127 | | - cuda_poll(); |
---|
128 | | - if ((req.reply_len != 3) && (req.reply_len != 7)) |
---|
129 | | - printk(KERN_ERR "cuda_set_rtc_time: got %d byte reply\n", |
---|
130 | | - req.reply_len); |
---|
131 | | - return 0; |
---|
132 | | -} |
---|
133 | | - |
---|
134 | | -#else |
---|
135 | | -#define cuda_get_time() 0 |
---|
136 | | -#define cuda_get_rtc_time(tm) |
---|
137 | | -#define cuda_set_rtc_time(tm) 0 |
---|
138 | | -#endif |
---|
139 | | - |
---|
140 | | -#ifdef CONFIG_ADB_PMU |
---|
141 | | -static time64_t pmu_get_time(void) |
---|
142 | | -{ |
---|
143 | | - struct adb_request req; |
---|
144 | | - time64_t now; |
---|
145 | | - |
---|
146 | | - if (pmu_request(&req, NULL, 1, PMU_READ_RTC) < 0) |
---|
147 | | - return 0; |
---|
148 | | - pmu_wait_complete(&req); |
---|
149 | | - if (req.reply_len != 4) |
---|
150 | | - printk(KERN_ERR "pmu_get_time: got %d byte reply from PMU\n", |
---|
151 | | - req.reply_len); |
---|
152 | | - now = (u32)((req.reply[0] << 24) + (req.reply[1] << 16) + |
---|
153 | | - (req.reply[2] << 8) + req.reply[3]); |
---|
154 | | - |
---|
155 | | - /* it's either after year 2040, or the RTC has gone backwards */ |
---|
156 | | - WARN_ON(now < RTC_OFFSET); |
---|
157 | | - |
---|
158 | | - return now - RTC_OFFSET; |
---|
159 | | -} |
---|
160 | | - |
---|
161 | | -#define pmu_get_rtc_time(tm) rtc_time64_to_tm(pmu_get_time(), (tm)) |
---|
162 | | - |
---|
163 | | -static int pmu_set_rtc_time(struct rtc_time *tm) |
---|
164 | | -{ |
---|
165 | | - u32 nowtime; |
---|
166 | | - struct adb_request req; |
---|
167 | | - |
---|
168 | | - nowtime = lower_32_bits(rtc_tm_to_time64(tm) + RTC_OFFSET); |
---|
169 | | - if (pmu_request(&req, NULL, 5, PMU_SET_RTC, nowtime >> 24, |
---|
170 | | - nowtime >> 16, nowtime >> 8, nowtime) < 0) |
---|
171 | | - return -ENXIO; |
---|
172 | | - pmu_wait_complete(&req); |
---|
173 | | - if (req.reply_len != 0) |
---|
174 | | - printk(KERN_ERR "pmu_set_rtc_time: %d byte reply from PMU\n", |
---|
175 | | - req.reply_len); |
---|
176 | | - return 0; |
---|
177 | | -} |
---|
178 | | - |
---|
179 | | -#else |
---|
180 | | -#define pmu_get_time() 0 |
---|
181 | | -#define pmu_get_rtc_time(tm) |
---|
182 | | -#define pmu_set_rtc_time(tm) 0 |
---|
183 | | -#endif |
---|
184 | | - |
---|
185 | 85 | #ifdef CONFIG_PMAC_SMU |
---|
186 | 86 | static time64_t smu_get_time(void) |
---|
187 | 87 | { |
---|
.. | .. |
---|
191 | 91 | return 0; |
---|
192 | 92 | return rtc_tm_to_time64(&tm); |
---|
193 | 93 | } |
---|
194 | | - |
---|
195 | | -#else |
---|
196 | | -#define smu_get_time() 0 |
---|
197 | | -#define smu_get_rtc_time(tm, spin) |
---|
198 | | -#define smu_set_rtc_time(tm, spin) 0 |
---|
199 | 94 | #endif |
---|
200 | 95 | |
---|
201 | 96 | /* Can't be __init, it's called when suspending and resuming */ |
---|
.. | .. |
---|
203 | 98 | { |
---|
204 | 99 | /* Get the time from the RTC, used only at boot time */ |
---|
205 | 100 | switch (sys_ctrler) { |
---|
| 101 | +#ifdef CONFIG_ADB_CUDA |
---|
206 | 102 | case SYS_CTRLER_CUDA: |
---|
207 | 103 | return cuda_get_time(); |
---|
| 104 | +#endif |
---|
| 105 | +#ifdef CONFIG_ADB_PMU |
---|
208 | 106 | case SYS_CTRLER_PMU: |
---|
209 | 107 | return pmu_get_time(); |
---|
| 108 | +#endif |
---|
| 109 | +#ifdef CONFIG_PMAC_SMU |
---|
210 | 110 | case SYS_CTRLER_SMU: |
---|
211 | 111 | return smu_get_time(); |
---|
| 112 | +#endif |
---|
212 | 113 | default: |
---|
213 | 114 | return 0; |
---|
214 | 115 | } |
---|
.. | .. |
---|
218 | 119 | { |
---|
219 | 120 | /* Get the time from the RTC, used only at boot time */ |
---|
220 | 121 | switch (sys_ctrler) { |
---|
| 122 | +#ifdef CONFIG_ADB_CUDA |
---|
221 | 123 | case SYS_CTRLER_CUDA: |
---|
222 | | - cuda_get_rtc_time(tm); |
---|
| 124 | + rtc_time64_to_tm(cuda_get_time(), tm); |
---|
223 | 125 | break; |
---|
| 126 | +#endif |
---|
| 127 | +#ifdef CONFIG_ADB_PMU |
---|
224 | 128 | case SYS_CTRLER_PMU: |
---|
225 | | - pmu_get_rtc_time(tm); |
---|
| 129 | + rtc_time64_to_tm(pmu_get_time(), tm); |
---|
226 | 130 | break; |
---|
| 131 | +#endif |
---|
| 132 | +#ifdef CONFIG_PMAC_SMU |
---|
227 | 133 | case SYS_CTRLER_SMU: |
---|
228 | 134 | smu_get_rtc_time(tm, 1); |
---|
229 | 135 | break; |
---|
| 136 | +#endif |
---|
230 | 137 | default: |
---|
231 | 138 | ; |
---|
232 | 139 | } |
---|
.. | .. |
---|
235 | 142 | int pmac_set_rtc_time(struct rtc_time *tm) |
---|
236 | 143 | { |
---|
237 | 144 | switch (sys_ctrler) { |
---|
| 145 | +#ifdef CONFIG_ADB_CUDA |
---|
238 | 146 | case SYS_CTRLER_CUDA: |
---|
239 | 147 | return cuda_set_rtc_time(tm); |
---|
| 148 | +#endif |
---|
| 149 | +#ifdef CONFIG_ADB_PMU |
---|
240 | 150 | case SYS_CTRLER_PMU: |
---|
241 | 151 | return pmu_set_rtc_time(tm); |
---|
| 152 | +#endif |
---|
| 153 | +#ifdef CONFIG_PMAC_SMU |
---|
242 | 154 | case SYS_CTRLER_SMU: |
---|
243 | 155 | return smu_set_rtc_time(tm, 1); |
---|
| 156 | +#endif |
---|
244 | 157 | default: |
---|
245 | 158 | return -ENODEV; |
---|
246 | 159 | } |
---|