Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Miscellaneous Mac68K-specific stuff |
| 3 | */ |
| 4 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | #include <linux/types.h> |
| 6 | #include <linux/errno.h> |
| 7 | #include <linux/miscdevice.h> |
| 8 | #include <linux/kernel.h> |
| 9 | #include <linux/delay.h> |
| 10 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/time.h> |
| 12 | #include <linux/rtc.h> |
| 13 | #include <linux/mm.h> |
| 14 | |
| 15 | #include <linux/adb.h> |
| 16 | #include <linux/cuda.h> |
| 17 | #include <linux/pmu.h> |
| 18 | |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 19 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <asm/segment.h> |
| 22 | #include <asm/setup.h> |
| 23 | #include <asm/macintosh.h> |
| 24 | #include <asm/mac_via.h> |
| 25 | #include <asm/mac_oss.h> |
| 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <asm/machdep.h> |
| 28 | |
| 29 | /* Offset between Unix time (1970-based) and Mac time (1904-based) */ |
| 30 | |
| 31 | #define RTC_OFFSET 2082844800 |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | static void (*rom_reset)(void); |
| 34 | |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 35 | #ifdef CONFIG_ADB_CUDA |
| 36 | static long cuda_read_time(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | { |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 38 | struct adb_request req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | long time; |
| 40 | |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 41 | if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_GET_TIME) < 0) |
| 42 | return 0; |
| 43 | while (!req.complete) |
| 44 | cuda_poll(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | time = (req.reply[3] << 24) | (req.reply[4] << 16) |
| 47 | | (req.reply[5] << 8) | req.reply[6]; |
| 48 | return time - RTC_OFFSET; |
| 49 | } |
| 50 | |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 51 | static void cuda_write_time(long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 53 | struct adb_request req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | data += RTC_OFFSET; |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 55 | if (cuda_request(&req, NULL, 6, CUDA_PACKET, CUDA_SET_TIME, |
| 56 | (data >> 24) & 0xFF, (data >> 16) & 0xFF, |
| 57 | (data >> 8) & 0xFF, data & 0xFF) < 0) |
| 58 | return; |
| 59 | while (!req.complete) |
| 60 | cuda_poll(); |
| 61 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 63 | static __u8 cuda_read_pram(int offset) |
| 64 | { |
| 65 | struct adb_request req; |
| 66 | if (cuda_request(&req, NULL, 4, CUDA_PACKET, CUDA_GET_PRAM, |
| 67 | (offset >> 8) & 0xFF, offset & 0xFF) < 0) |
| 68 | return 0; |
| 69 | while (!req.complete) |
| 70 | cuda_poll(); |
| 71 | return req.reply[3]; |
| 72 | } |
| 73 | |
| 74 | static void cuda_write_pram(int offset, __u8 data) |
| 75 | { |
| 76 | struct adb_request req; |
| 77 | if (cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_SET_PRAM, |
| 78 | (offset >> 8) & 0xFF, offset & 0xFF, data) < 0) |
| 79 | return; |
| 80 | while (!req.complete) |
| 81 | cuda_poll(); |
| 82 | } |
| 83 | #else |
| 84 | #define cuda_read_time() 0 |
| 85 | #define cuda_write_time(n) |
| 86 | #define cuda_read_pram NULL |
| 87 | #define cuda_write_pram NULL |
| 88 | #endif |
| 89 | |
Finn Thain | d643e2d | 2010-06-02 15:58:24 +0200 | [diff] [blame] | 90 | #ifdef CONFIG_ADB_PMU68K |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 91 | static long pmu_read_time(void) |
| 92 | { |
| 93 | struct adb_request req; |
| 94 | long time; |
| 95 | |
| 96 | if (pmu_request(&req, NULL, 1, PMU_READ_RTC) < 0) |
| 97 | return 0; |
| 98 | while (!req.complete) |
| 99 | pmu_poll(); |
| 100 | |
Finn Thain | d643e2d | 2010-06-02 15:58:24 +0200 | [diff] [blame] | 101 | time = (req.reply[1] << 24) | (req.reply[2] << 16) |
| 102 | | (req.reply[3] << 8) | req.reply[4]; |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 103 | return time - RTC_OFFSET; |
| 104 | } |
| 105 | |
| 106 | static void pmu_write_time(long data) |
| 107 | { |
| 108 | struct adb_request req; |
| 109 | data += RTC_OFFSET; |
| 110 | if (pmu_request(&req, NULL, 5, PMU_SET_RTC, |
| 111 | (data >> 24) & 0xFF, (data >> 16) & 0xFF, |
| 112 | (data >> 8) & 0xFF, data & 0xFF) < 0) |
| 113 | return; |
| 114 | while (!req.complete) |
| 115 | pmu_poll(); |
| 116 | } |
| 117 | |
| 118 | static __u8 pmu_read_pram(int offset) |
| 119 | { |
| 120 | struct adb_request req; |
| 121 | if (pmu_request(&req, NULL, 3, PMU_READ_NVRAM, |
| 122 | (offset >> 8) & 0xFF, offset & 0xFF) < 0) |
| 123 | return 0; |
| 124 | while (!req.complete) |
| 125 | pmu_poll(); |
| 126 | return req.reply[3]; |
| 127 | } |
| 128 | |
| 129 | static void pmu_write_pram(int offset, __u8 data) |
| 130 | { |
| 131 | struct adb_request req; |
| 132 | if (pmu_request(&req, NULL, 4, PMU_WRITE_NVRAM, |
| 133 | (offset >> 8) & 0xFF, offset & 0xFF, data) < 0) |
| 134 | return; |
| 135 | while (!req.complete) |
| 136 | pmu_poll(); |
| 137 | } |
| 138 | #else |
| 139 | #define pmu_read_time() 0 |
| 140 | #define pmu_write_time(n) |
| 141 | #define pmu_read_pram NULL |
| 142 | #define pmu_write_pram NULL |
| 143 | #endif |
| 144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | /* |
| 146 | * VIA PRAM/RTC access routines |
| 147 | * |
| 148 | * Must be called with interrupts disabled and |
| 149 | * the RTC should be enabled. |
| 150 | */ |
| 151 | |
| 152 | static __u8 via_pram_readbyte(void) |
| 153 | { |
| 154 | int i,reg; |
| 155 | __u8 data; |
| 156 | |
| 157 | reg = via1[vBufB] & ~VIA1B_vRTCClk; |
| 158 | |
| 159 | /* Set the RTC data line to be an input. */ |
| 160 | |
| 161 | via1[vDirB] &= ~VIA1B_vRTCData; |
| 162 | |
| 163 | /* The bits of the byte come out in MSB order */ |
| 164 | |
| 165 | data = 0; |
| 166 | for (i = 0 ; i < 8 ; i++) { |
| 167 | via1[vBufB] = reg; |
| 168 | via1[vBufB] = reg | VIA1B_vRTCClk; |
| 169 | data = (data << 1) | (via1[vBufB] & VIA1B_vRTCData); |
| 170 | } |
| 171 | |
| 172 | /* Return RTC data line to output state */ |
| 173 | |
| 174 | via1[vDirB] |= VIA1B_vRTCData; |
| 175 | |
| 176 | return data; |
| 177 | } |
| 178 | |
| 179 | static void via_pram_writebyte(__u8 data) |
| 180 | { |
| 181 | int i,reg,bit; |
| 182 | |
| 183 | reg = via1[vBufB] & ~(VIA1B_vRTCClk | VIA1B_vRTCData); |
| 184 | |
| 185 | /* The bits of the byte go in in MSB order */ |
| 186 | |
| 187 | for (i = 0 ; i < 8 ; i++) { |
| 188 | bit = data & 0x80? 1 : 0; |
| 189 | data <<= 1; |
| 190 | via1[vBufB] = reg | bit; |
| 191 | via1[vBufB] = reg | bit | VIA1B_vRTCClk; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | /* |
| 196 | * Execute a VIA PRAM/RTC command. For read commands |
| 197 | * data should point to a one-byte buffer for the |
| 198 | * resulting data. For write commands it should point |
| 199 | * to the data byte to for the command. |
| 200 | * |
| 201 | * This function disables all interrupts while running. |
| 202 | */ |
| 203 | |
| 204 | static void via_pram_command(int command, __u8 *data) |
| 205 | { |
| 206 | unsigned long flags; |
| 207 | int is_read; |
| 208 | |
| 209 | local_irq_save(flags); |
| 210 | |
| 211 | /* Enable the RTC and make sure the strobe line is high */ |
| 212 | |
| 213 | via1[vBufB] = (via1[vBufB] | VIA1B_vRTCClk) & ~VIA1B_vRTCEnb; |
| 214 | |
| 215 | if (command & 0xFF00) { /* extended (two-byte) command */ |
| 216 | via_pram_writebyte((command & 0xFF00) >> 8); |
| 217 | via_pram_writebyte(command & 0xFF); |
| 218 | is_read = command & 0x8000; |
| 219 | } else { /* one-byte command */ |
| 220 | via_pram_writebyte(command); |
| 221 | is_read = command & 0x80; |
| 222 | } |
| 223 | if (is_read) { |
| 224 | *data = via_pram_readbyte(); |
| 225 | } else { |
| 226 | via_pram_writebyte(*data); |
| 227 | } |
| 228 | |
| 229 | /* All done, disable the RTC */ |
| 230 | |
| 231 | via1[vBufB] |= VIA1B_vRTCEnb; |
| 232 | |
| 233 | local_irq_restore(flags); |
| 234 | } |
| 235 | |
| 236 | static __u8 via_read_pram(int offset) |
| 237 | { |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | static void via_write_pram(int offset, __u8 data) |
| 242 | { |
| 243 | } |
| 244 | |
| 245 | /* |
| 246 | * Return the current time in seconds since January 1, 1904. |
| 247 | * |
| 248 | * This only works on machines with the VIA-based PRAM/RTC, which |
| 249 | * is basically any machine with Mac II-style ADB. |
| 250 | */ |
| 251 | |
| 252 | static long via_read_time(void) |
| 253 | { |
| 254 | union { |
Finn Thain | 75a2385 | 2011-07-18 00:06:10 +1000 | [diff] [blame] | 255 | __u8 cdata[4]; |
| 256 | long idata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } result, last_result; |
Finn Thain | 75a2385 | 2011-07-18 00:06:10 +1000 | [diff] [blame] | 258 | int count = 1; |
| 259 | |
| 260 | via_pram_command(0x81, &last_result.cdata[3]); |
| 261 | via_pram_command(0x85, &last_result.cdata[2]); |
| 262 | via_pram_command(0x89, &last_result.cdata[1]); |
| 263 | via_pram_command(0x8D, &last_result.cdata[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | |
| 265 | /* |
| 266 | * The NetBSD guys say to loop until you get the same reading |
| 267 | * twice in a row. |
| 268 | */ |
| 269 | |
Finn Thain | 75a2385 | 2011-07-18 00:06:10 +1000 | [diff] [blame] | 270 | while (1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | via_pram_command(0x81, &result.cdata[3]); |
| 272 | via_pram_command(0x85, &result.cdata[2]); |
| 273 | via_pram_command(0x89, &result.cdata[1]); |
| 274 | via_pram_command(0x8D, &result.cdata[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | |
Finn Thain | 75a2385 | 2011-07-18 00:06:10 +1000 | [diff] [blame] | 276 | if (result.idata == last_result.idata) |
| 277 | return result.idata - RTC_OFFSET; |
| 278 | |
| 279 | if (++count > 10) |
| 280 | break; |
| 281 | |
| 282 | last_result.idata = result.idata; |
| 283 | } |
| 284 | |
| 285 | pr_err("via_read_time: failed to read a stable value; " |
| 286 | "got 0x%08lx then 0x%08lx\n", |
| 287 | last_result.idata, result.idata); |
| 288 | |
| 289 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | /* |
| 293 | * Set the current time to a number of seconds since January 1, 1904. |
| 294 | * |
| 295 | * This only works on machines with the VIA-based PRAM/RTC, which |
| 296 | * is basically any machine with Mac II-style ADB. |
| 297 | */ |
| 298 | |
| 299 | static void via_write_time(long time) |
| 300 | { |
| 301 | union { |
| 302 | __u8 cdata[4]; |
| 303 | long idata; |
| 304 | } data; |
| 305 | __u8 temp; |
| 306 | |
| 307 | /* Clear the write protect bit */ |
| 308 | |
| 309 | temp = 0x55; |
| 310 | via_pram_command(0x35, &temp); |
| 311 | |
| 312 | data.idata = time + RTC_OFFSET; |
| 313 | via_pram_command(0x01, &data.cdata[3]); |
| 314 | via_pram_command(0x05, &data.cdata[2]); |
| 315 | via_pram_command(0x09, &data.cdata[1]); |
| 316 | via_pram_command(0x0D, &data.cdata[0]); |
| 317 | |
| 318 | /* Set the write protect bit */ |
| 319 | |
| 320 | temp = 0xD5; |
| 321 | via_pram_command(0x35, &temp); |
| 322 | } |
| 323 | |
| 324 | static void via_shutdown(void) |
| 325 | { |
| 326 | if (rbv_present) { |
| 327 | via2[rBufB] &= ~0x04; |
| 328 | } else { |
| 329 | /* Direction of vDirB is output */ |
| 330 | via2[vDirB] |= 0x04; |
| 331 | /* Send a value of 0 on that line */ |
| 332 | via2[vBufB] &= ~0x04; |
| 333 | mdelay(1000); |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | /* |
| 338 | * FIXME: not sure how this is supposed to work exactly... |
| 339 | */ |
| 340 | |
| 341 | static void oss_shutdown(void) |
| 342 | { |
| 343 | oss->rom_ctrl = OSS_POWEROFF; |
| 344 | } |
| 345 | |
| 346 | #ifdef CONFIG_ADB_CUDA |
| 347 | |
| 348 | static void cuda_restart(void) |
| 349 | { |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 350 | struct adb_request req; |
| 351 | if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_RESET_SYSTEM) < 0) |
| 352 | return; |
| 353 | while (!req.complete) |
| 354 | cuda_poll(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | static void cuda_shutdown(void) |
| 358 | { |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 359 | struct adb_request req; |
| 360 | if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_POWERDOWN) < 0) |
| 361 | return; |
| 362 | while (!req.complete) |
| 363 | cuda_poll(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | #endif /* CONFIG_ADB_CUDA */ |
| 367 | |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 368 | #ifdef CONFIG_ADB_PMU68K |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
| 370 | void pmu_restart(void) |
| 371 | { |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 372 | struct adb_request req; |
| 373 | if (pmu_request(&req, NULL, |
| 374 | 2, PMU_SET_INTR_MASK, PMU_INT_ADB|PMU_INT_TICK) < 0) |
| 375 | return; |
| 376 | while (!req.complete) |
| 377 | pmu_poll(); |
| 378 | if (pmu_request(&req, NULL, 1, PMU_RESET) < 0) |
| 379 | return; |
| 380 | while (!req.complete) |
| 381 | pmu_poll(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | void pmu_shutdown(void) |
| 385 | { |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 386 | struct adb_request req; |
| 387 | if (pmu_request(&req, NULL, |
| 388 | 2, PMU_SET_INTR_MASK, PMU_INT_ADB|PMU_INT_TICK) < 0) |
| 389 | return; |
| 390 | while (!req.complete) |
| 391 | pmu_poll(); |
| 392 | if (pmu_request(&req, NULL, 5, PMU_SHUTDOWN, 'M', 'A', 'T', 'T') < 0) |
| 393 | return; |
| 394 | while (!req.complete) |
| 395 | pmu_poll(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | } |
| 397 | |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 398 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
| 400 | /* |
| 401 | *------------------------------------------------------------------- |
| 402 | * Below this point are the generic routines; they'll dispatch to the |
| 403 | * correct routine for the hardware on which we're running. |
| 404 | *------------------------------------------------------------------- |
| 405 | */ |
| 406 | |
| 407 | void mac_pram_read(int offset, __u8 *buffer, int len) |
| 408 | { |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 409 | __u8 (*func)(int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | int i; |
| 411 | |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 412 | switch(macintosh_config->adb_type) { |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 413 | case MAC_ADB_PB1: |
| 414 | case MAC_ADB_PB2: |
| 415 | func = pmu_read_pram; break; |
Finn Thain | f74faec | 2016-12-31 19:56:26 -0500 | [diff] [blame^] | 416 | case MAC_ADB_EGRET: |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 417 | case MAC_ADB_CUDA: |
| 418 | func = cuda_read_pram; break; |
| 419 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | func = via_read_pram; |
| 421 | } |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 422 | if (!func) |
| 423 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | for (i = 0 ; i < len ; i++) { |
| 425 | buffer[i] = (*func)(offset++); |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | void mac_pram_write(int offset, __u8 *buffer, int len) |
| 430 | { |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 431 | void (*func)(int, __u8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | int i; |
| 433 | |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 434 | switch(macintosh_config->adb_type) { |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 435 | case MAC_ADB_PB1: |
| 436 | case MAC_ADB_PB2: |
| 437 | func = pmu_write_pram; break; |
Finn Thain | f74faec | 2016-12-31 19:56:26 -0500 | [diff] [blame^] | 438 | case MAC_ADB_EGRET: |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 439 | case MAC_ADB_CUDA: |
| 440 | func = cuda_write_pram; break; |
| 441 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | func = via_write_pram; |
| 443 | } |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 444 | if (!func) |
| 445 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | for (i = 0 ; i < len ; i++) { |
| 447 | (*func)(offset++, buffer[i]); |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | void mac_poweroff(void) |
| 452 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | if (oss_present) { |
| 454 | oss_shutdown(); |
| 455 | } else if (macintosh_config->adb_type == MAC_ADB_II) { |
| 456 | via_shutdown(); |
| 457 | #ifdef CONFIG_ADB_CUDA |
Finn Thain | f74faec | 2016-12-31 19:56:26 -0500 | [diff] [blame^] | 458 | } else if (macintosh_config->adb_type == MAC_ADB_EGRET || |
| 459 | macintosh_config->adb_type == MAC_ADB_CUDA) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | cuda_shutdown(); |
| 461 | #endif |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 462 | #ifdef CONFIG_ADB_PMU68K |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | } else if (macintosh_config->adb_type == MAC_ADB_PB1 |
| 464 | || macintosh_config->adb_type == MAC_ADB_PB2) { |
| 465 | pmu_shutdown(); |
| 466 | #endif |
| 467 | } |
| 468 | local_irq_enable(); |
| 469 | printk("It is now safe to turn off your Macintosh.\n"); |
| 470 | while(1); |
| 471 | } |
| 472 | |
| 473 | void mac_reset(void) |
| 474 | { |
| 475 | if (macintosh_config->adb_type == MAC_ADB_II) { |
| 476 | unsigned long flags; |
| 477 | |
| 478 | /* need ROMBASE in booter */ |
| 479 | /* indeed, plus need to MAP THE ROM !! */ |
| 480 | |
| 481 | if (mac_bi_data.rombase == 0) |
| 482 | mac_bi_data.rombase = 0x40800000; |
| 483 | |
| 484 | /* works on some */ |
| 485 | rom_reset = (void *) (mac_bi_data.rombase + 0xa); |
| 486 | |
| 487 | if (macintosh_config->ident == MAC_MODEL_SE30) { |
| 488 | /* |
| 489 | * MSch: Machines known to crash on ROM reset ... |
| 490 | */ |
| 491 | } else { |
| 492 | local_irq_save(flags); |
| 493 | |
| 494 | rom_reset(); |
| 495 | |
| 496 | local_irq_restore(flags); |
| 497 | } |
| 498 | #ifdef CONFIG_ADB_CUDA |
Finn Thain | f74faec | 2016-12-31 19:56:26 -0500 | [diff] [blame^] | 499 | } else if (macintosh_config->adb_type == MAC_ADB_EGRET || |
| 500 | macintosh_config->adb_type == MAC_ADB_CUDA) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | cuda_restart(); |
| 502 | #endif |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 503 | #ifdef CONFIG_ADB_PMU68K |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | } else if (macintosh_config->adb_type == MAC_ADB_PB1 |
| 505 | || macintosh_config->adb_type == MAC_ADB_PB2) { |
| 506 | pmu_restart(); |
| 507 | #endif |
| 508 | } else if (CPU_IS_030) { |
| 509 | |
| 510 | /* 030-specific reset routine. The idea is general, but the |
| 511 | * specific registers to reset are '030-specific. Until I |
| 512 | * have a non-030 machine, I can't test anything else. |
| 513 | * -- C. Scott Ananian <cananian@alumni.princeton.edu> |
| 514 | */ |
| 515 | |
| 516 | unsigned long rombase = 0x40000000; |
| 517 | |
| 518 | /* make a 1-to-1 mapping, using the transparent tran. reg. */ |
| 519 | unsigned long virt = (unsigned long) mac_reset; |
| 520 | unsigned long phys = virt_to_phys(mac_reset); |
Al Viro | 77add9f | 2006-01-12 01:06:18 -0800 | [diff] [blame] | 521 | unsigned long addr = (phys&0xFF000000)|0x8777; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | unsigned long offset = phys-virt; |
| 523 | local_irq_disable(); /* lets not screw this up, ok? */ |
| 524 | __asm__ __volatile__(".chip 68030\n\t" |
| 525 | "pmove %0,%/tt0\n\t" |
| 526 | ".chip 68k" |
Al Viro | 77add9f | 2006-01-12 01:06:18 -0800 | [diff] [blame] | 527 | : : "m" (addr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | /* Now jump to physical address so we can disable MMU */ |
| 529 | __asm__ __volatile__( |
| 530 | ".chip 68030\n\t" |
| 531 | "lea %/pc@(1f),%/a0\n\t" |
| 532 | "addl %0,%/a0\n\t"/* fixup target address and stack ptr */ |
| 533 | "addl %0,%/sp\n\t" |
| 534 | "pflusha\n\t" |
| 535 | "jmp %/a0@\n\t" /* jump into physical memory */ |
| 536 | "0:.long 0\n\t" /* a constant zero. */ |
| 537 | /* OK. Now reset everything and jump to reset vector. */ |
| 538 | "1:\n\t" |
| 539 | "lea %/pc@(0b),%/a0\n\t" |
| 540 | "pmove %/a0@, %/tc\n\t" /* disable mmu */ |
| 541 | "pmove %/a0@, %/tt0\n\t" /* disable tt0 */ |
| 542 | "pmove %/a0@, %/tt1\n\t" /* disable tt1 */ |
| 543 | "movel #0, %/a0\n\t" |
| 544 | "movec %/a0, %/vbr\n\t" /* clear vector base register */ |
| 545 | "movec %/a0, %/cacr\n\t" /* disable caches */ |
| 546 | "movel #0x0808,%/a0\n\t" |
| 547 | "movec %/a0, %/cacr\n\t" /* flush i&d caches */ |
| 548 | "movew #0x2700,%/sr\n\t" /* set up status register */ |
| 549 | "movel %1@(0x0),%/a0\n\t"/* load interrupt stack pointer */ |
| 550 | "movec %/a0, %/isp\n\t" |
| 551 | "movel %1@(0x4),%/a0\n\t" /* load reset vector */ |
| 552 | "reset\n\t" /* reset external devices */ |
| 553 | "jmp %/a0@\n\t" /* jump to the reset vector */ |
| 554 | ".chip 68k" |
| 555 | : : "r" (offset), "a" (rombase) : "a0"); |
| 556 | } |
| 557 | |
| 558 | /* should never get here */ |
| 559 | local_irq_enable(); |
| 560 | printk ("Restart failed. Please restart manually.\n"); |
| 561 | while(1); |
| 562 | } |
| 563 | |
| 564 | /* |
| 565 | * This function translates seconds since 1970 into a proper date. |
| 566 | * |
| 567 | * Algorithm cribbed from glibc2.1, __offtime(). |
| 568 | */ |
| 569 | #define SECS_PER_MINUTE (60) |
| 570 | #define SECS_PER_HOUR (SECS_PER_MINUTE * 60) |
| 571 | #define SECS_PER_DAY (SECS_PER_HOUR * 24) |
| 572 | |
| 573 | static void unmktime(unsigned long time, long offset, |
| 574 | int *yearp, int *monp, int *dayp, |
| 575 | int *hourp, int *minp, int *secp) |
| 576 | { |
| 577 | /* How many days come before each month (0-12). */ |
| 578 | static const unsigned short int __mon_yday[2][13] = |
| 579 | { |
| 580 | /* Normal years. */ |
| 581 | { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }, |
| 582 | /* Leap years. */ |
| 583 | { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } |
| 584 | }; |
| 585 | long int days, rem, y, wday, yday; |
| 586 | const unsigned short int *ip; |
| 587 | |
| 588 | days = time / SECS_PER_DAY; |
| 589 | rem = time % SECS_PER_DAY; |
| 590 | rem += offset; |
| 591 | while (rem < 0) { |
| 592 | rem += SECS_PER_DAY; |
| 593 | --days; |
| 594 | } |
| 595 | while (rem >= SECS_PER_DAY) { |
| 596 | rem -= SECS_PER_DAY; |
| 597 | ++days; |
| 598 | } |
| 599 | *hourp = rem / SECS_PER_HOUR; |
| 600 | rem %= SECS_PER_HOUR; |
| 601 | *minp = rem / SECS_PER_MINUTE; |
| 602 | *secp = rem % SECS_PER_MINUTE; |
| 603 | /* January 1, 1970 was a Thursday. */ |
| 604 | wday = (4 + days) % 7; /* Day in the week. Not currently used */ |
| 605 | if (wday < 0) wday += 7; |
| 606 | y = 1970; |
| 607 | |
| 608 | #define DIV(a, b) ((a) / (b) - ((a) % (b) < 0)) |
| 609 | #define LEAPS_THRU_END_OF(y) (DIV (y, 4) - DIV (y, 100) + DIV (y, 400)) |
| 610 | #define __isleap(year) \ |
| 611 | ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0)) |
| 612 | |
| 613 | while (days < 0 || days >= (__isleap (y) ? 366 : 365)) |
| 614 | { |
| 615 | /* Guess a corrected year, assuming 365 days per year. */ |
| 616 | long int yg = y + days / 365 - (days % 365 < 0); |
| 617 | |
| 618 | /* Adjust DAYS and Y to match the guessed year. */ |
| 619 | days -= ((yg - y) * 365 |
| 620 | + LEAPS_THRU_END_OF (yg - 1) |
| 621 | - LEAPS_THRU_END_OF (y - 1)); |
| 622 | y = yg; |
| 623 | } |
| 624 | *yearp = y - 1900; |
| 625 | yday = days; /* day in the year. Not currently used. */ |
| 626 | ip = __mon_yday[__isleap(y)]; |
| 627 | for (y = 11; days < (long int) ip[y]; --y) |
| 628 | continue; |
| 629 | days -= ip[y]; |
| 630 | *monp = y; |
| 631 | *dayp = days + 1; /* day in the month */ |
| 632 | return; |
| 633 | } |
| 634 | |
| 635 | /* |
| 636 | * Read/write the hardware clock. |
| 637 | */ |
| 638 | |
| 639 | int mac_hwclk(int op, struct rtc_time *t) |
| 640 | { |
| 641 | unsigned long now; |
| 642 | |
| 643 | if (!op) { /* read */ |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 644 | switch (macintosh_config->adb_type) { |
| 645 | case MAC_ADB_II: |
| 646 | case MAC_ADB_IOP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | now = via_read_time(); |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 648 | break; |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 649 | case MAC_ADB_PB1: |
| 650 | case MAC_ADB_PB2: |
| 651 | now = pmu_read_time(); |
| 652 | break; |
Finn Thain | f74faec | 2016-12-31 19:56:26 -0500 | [diff] [blame^] | 653 | case MAC_ADB_EGRET: |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 654 | case MAC_ADB_CUDA: |
| 655 | now = cuda_read_time(); |
| 656 | break; |
| 657 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | now = 0; |
| 659 | } |
| 660 | |
| 661 | t->tm_wday = 0; |
| 662 | unmktime(now, 0, |
| 663 | &t->tm_year, &t->tm_mon, &t->tm_mday, |
| 664 | &t->tm_hour, &t->tm_min, &t->tm_sec); |
Finn Thain | 40f7f9c | 2008-11-18 20:45:20 +0100 | [diff] [blame] | 665 | #if 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | printk("mac_hwclk: read %04d-%02d-%-2d %02d:%02d:%02d\n", |
Finn Thain | 40f7f9c | 2008-11-18 20:45:20 +0100 | [diff] [blame] | 667 | t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, |
| 668 | t->tm_hour, t->tm_min, t->tm_sec); |
| 669 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | } else { /* write */ |
Finn Thain | 40f7f9c | 2008-11-18 20:45:20 +0100 | [diff] [blame] | 671 | #if 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | printk("mac_hwclk: tried to write %04d-%02d-%-2d %02d:%02d:%02d\n", |
Finn Thain | 40f7f9c | 2008-11-18 20:45:20 +0100 | [diff] [blame] | 673 | t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, |
| 674 | t->tm_hour, t->tm_min, t->tm_sec); |
| 675 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | now = mktime(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, |
| 678 | t->tm_hour, t->tm_min, t->tm_sec); |
| 679 | |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 680 | switch (macintosh_config->adb_type) { |
| 681 | case MAC_ADB_II: |
| 682 | case MAC_ADB_IOP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | via_write_time(now); |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 684 | break; |
Finn Thain | f74faec | 2016-12-31 19:56:26 -0500 | [diff] [blame^] | 685 | case MAC_ADB_EGRET: |
Al Viro | 3272244 | 2006-01-12 01:06:13 -0800 | [diff] [blame] | 686 | case MAC_ADB_CUDA: |
| 687 | cuda_write_time(now); |
| 688 | break; |
| 689 | case MAC_ADB_PB1: |
| 690 | case MAC_ADB_PB2: |
| 691 | pmu_write_time(now); |
| 692 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | } |
| 695 | return 0; |
| 696 | } |
| 697 | |
| 698 | /* |
| 699 | * Set minutes/seconds in the hardware clock |
| 700 | */ |
| 701 | |
| 702 | int mac_set_clock_mmss (unsigned long nowtime) |
| 703 | { |
| 704 | struct rtc_time now; |
| 705 | |
| 706 | mac_hwclk(0, &now); |
| 707 | now.tm_sec = nowtime % 60; |
| 708 | now.tm_min = (nowtime / 60) % 60; |
| 709 | mac_hwclk(1, &now); |
| 710 | |
| 711 | return 0; |
| 712 | } |