forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/arch/powerpc/platforms/powermac/time.c
....@@ -28,7 +28,6 @@
2828 #include <asm/sections.h>
2929 #include <asm/prom.h>
3030 #include <asm/io.h>
31
-#include <asm/pgtable.h>
3231 #include <asm/machdep.h>
3332 #include <asm/time.h>
3433 #include <asm/nvram.h>
....@@ -43,13 +42,6 @@
4342 #else
4443 #define DBG(x...)
4544 #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
5345
5446 /*
5547 * Calibrate the decrementer frequency with the VIA timer 1.
....@@ -75,7 +67,7 @@
7567 long __init pmac_time_init(void)
7668 {
7769 s32 delta = 0;
78
-#ifdef CONFIG_NVRAM
70
+#if defined(CONFIG_NVRAM) && defined(CONFIG_PPC32)
7971 int dst;
8072
8173 delta = ((s32)pmac_xpram_read(PMAC_XPRAM_MACHINE_LOC + 0x9)) << 16;
....@@ -90,98 +82,6 @@
9082 return delta;
9183 }
9284
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
-
18585 #ifdef CONFIG_PMAC_SMU
18686 static time64_t smu_get_time(void)
18787 {
....@@ -191,11 +91,6 @@
19191 return 0;
19292 return rtc_tm_to_time64(&tm);
19393 }
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
19994 #endif
20095
20196 /* Can't be __init, it's called when suspending and resuming */
....@@ -203,12 +98,18 @@
20398 {
20499 /* Get the time from the RTC, used only at boot time */
205100 switch (sys_ctrler) {
101
+#ifdef CONFIG_ADB_CUDA
206102 case SYS_CTRLER_CUDA:
207103 return cuda_get_time();
104
+#endif
105
+#ifdef CONFIG_ADB_PMU
208106 case SYS_CTRLER_PMU:
209107 return pmu_get_time();
108
+#endif
109
+#ifdef CONFIG_PMAC_SMU
210110 case SYS_CTRLER_SMU:
211111 return smu_get_time();
112
+#endif
212113 default:
213114 return 0;
214115 }
....@@ -218,15 +119,21 @@
218119 {
219120 /* Get the time from the RTC, used only at boot time */
220121 switch (sys_ctrler) {
122
+#ifdef CONFIG_ADB_CUDA
221123 case SYS_CTRLER_CUDA:
222
- cuda_get_rtc_time(tm);
124
+ rtc_time64_to_tm(cuda_get_time(), tm);
223125 break;
126
+#endif
127
+#ifdef CONFIG_ADB_PMU
224128 case SYS_CTRLER_PMU:
225
- pmu_get_rtc_time(tm);
129
+ rtc_time64_to_tm(pmu_get_time(), tm);
226130 break;
131
+#endif
132
+#ifdef CONFIG_PMAC_SMU
227133 case SYS_CTRLER_SMU:
228134 smu_get_rtc_time(tm, 1);
229135 break;
136
+#endif
230137 default:
231138 ;
232139 }
....@@ -235,12 +142,18 @@
235142 int pmac_set_rtc_time(struct rtc_time *tm)
236143 {
237144 switch (sys_ctrler) {
145
+#ifdef CONFIG_ADB_CUDA
238146 case SYS_CTRLER_CUDA:
239147 return cuda_set_rtc_time(tm);
148
+#endif
149
+#ifdef CONFIG_ADB_PMU
240150 case SYS_CTRLER_PMU:
241151 return pmu_set_rtc_time(tm);
152
+#endif
153
+#ifdef CONFIG_PMAC_SMU
242154 case SYS_CTRLER_SMU:
243155 return smu_set_rtc_time(tm, 1);
156
+#endif
244157 default:
245158 return -ENODEV;
246159 }