[PATCH] m68k: switch mac/misc.c to direct use of appropriate cuda/pmu/maciisi requests

kill ADBREQ_RAW use, replace adb_read_time(), etc. with per-type variants,
eliminated remapping from pmu ones, fix the ifdefs (PMU->PMU68K)

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Cc: Roman Zippel <zippel@linux-m68k.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by Al Viro and committed by Linus Torvalds 3272244c b4290a23

+239 -108
+221 -108
arch/m68k/mac/misc.c
··· 39 extern struct mac_booter_data mac_bi_data; 40 static void (*rom_reset)(void); 41 42 - #ifdef CONFIG_ADB 43 - /* 44 - * Return the current time as the number of seconds since January 1, 1904. 45 - */ 46 - 47 - static long adb_read_time(void) 48 { 49 - volatile struct adb_request req; 50 long time; 51 52 - adb_request((struct adb_request *) &req, NULL, 53 - ADBREQ_RAW|ADBREQ_SYNC, 54 - 2, CUDA_PACKET, CUDA_GET_TIME); 55 56 time = (req.reply[3] << 24) | (req.reply[4] << 16) 57 | (req.reply[5] << 8) | req.reply[6]; 58 return time - RTC_OFFSET; 59 } 60 61 - /* 62 - * Set the current system time 63 - */ 64 - 65 - static void adb_write_time(long data) 66 { 67 - volatile struct adb_request req; 68 - 69 data += RTC_OFFSET; 70 71 - adb_request((struct adb_request *) &req, NULL, 72 - ADBREQ_RAW|ADBREQ_SYNC, 73 - 6, CUDA_PACKET, CUDA_SET_TIME, 74 (data >> 24) & 0xFF, (data >> 16) & 0xFF, 75 (data >> 8) & 0xFF, data & 0xFF); 76 } 77 78 - /* 79 - * Get a byte from the NVRAM 80 - */ 81 - 82 - static __u8 adb_read_pram(int offset) 83 { 84 - volatile struct adb_request req; 85 - 86 - adb_request((struct adb_request *) &req, NULL, 87 - ADBREQ_RAW|ADBREQ_SYNC, 88 - 4, CUDA_PACKET, CUDA_GET_PRAM, 89 - (offset >> 8) & 0xFF, offset & 0xFF); 90 return req.reply[3]; 91 } 92 93 - /* 94 - * Write a byte to the NVRAM 95 - */ 96 - 97 - static void adb_write_pram(int offset, __u8 data) 98 { 99 - volatile struct adb_request req; 100 - 101 - adb_request((struct adb_request *) &req, NULL, 102 - ADBREQ_RAW|ADBREQ_SYNC, 103 - 5, CUDA_PACKET, CUDA_SET_PRAM, 104 - (offset >> 8) & 0xFF, offset & 0xFF, 105 - data); 106 } 107 - #endif /* CONFIG_ADB */ 108 109 /* 110 * VIA PRAM/RTC access routines ··· 396 397 static void cuda_restart(void) 398 { 399 - adb_request(NULL, NULL, ADBREQ_RAW|ADBREQ_SYNC, 400 - 2, CUDA_PACKET, CUDA_RESET_SYSTEM); 401 } 402 403 static void cuda_shutdown(void) 404 { 405 - adb_request(NULL, NULL, ADBREQ_RAW|ADBREQ_SYNC, 406 - 2, CUDA_PACKET, CUDA_POWERDOWN); 407 } 408 409 #endif /* CONFIG_ADB_CUDA */ 410 411 - #ifdef CONFIG_ADB_PMU 412 413 void pmu_restart(void) 414 { 415 - adb_request(NULL, NULL, ADBREQ_RAW|ADBREQ_SYNC, 416 - 3, PMU_PACKET, PMU_SET_INTR_MASK, 417 - PMU_INT_ADB|PMU_INT_TICK); 418 - 419 - adb_request(NULL, NULL, ADBREQ_RAW|ADBREQ_SYNC, 420 - 2, PMU_PACKET, PMU_RESET); 421 } 422 423 void pmu_shutdown(void) 424 { 425 - adb_request(NULL, NULL, ADBREQ_RAW|ADBREQ_SYNC, 426 - 3, PMU_PACKET, PMU_SET_INTR_MASK, 427 - PMU_INT_ADB|PMU_INT_TICK); 428 - 429 - adb_request(NULL, NULL, ADBREQ_RAW|ADBREQ_SYNC, 430 - 6, PMU_PACKET, PMU_SHUTDOWN, 431 - 'M', 'A', 'T', 'T'); 432 } 433 434 - #endif /* CONFIG_ADB_PMU */ 435 436 /* 437 *------------------------------------------------------------------- ··· 455 456 void mac_pram_read(int offset, __u8 *buffer, int len) 457 { 458 - __u8 (*func)(int) = NULL; 459 int i; 460 461 - if (macintosh_config->adb_type == MAC_ADB_IISI || 462 - macintosh_config->adb_type == MAC_ADB_PB1 || 463 - macintosh_config->adb_type == MAC_ADB_PB2 || 464 - macintosh_config->adb_type == MAC_ADB_CUDA) { 465 - #ifdef CONFIG_ADB 466 - func = adb_read_pram; 467 - #else 468 - return; 469 - #endif 470 - } else { 471 func = via_read_pram; 472 } 473 for (i = 0 ; i < len ; i++) { 474 buffer[i] = (*func)(offset++); 475 } ··· 478 479 void mac_pram_write(int offset, __u8 *buffer, int len) 480 { 481 - void (*func)(int, __u8) = NULL; 482 int i; 483 484 - if (macintosh_config->adb_type == MAC_ADB_IISI || 485 - macintosh_config->adb_type == MAC_ADB_PB1 || 486 - macintosh_config->adb_type == MAC_ADB_PB2 || 487 - macintosh_config->adb_type == MAC_ADB_CUDA) { 488 - #ifdef CONFIG_ADB 489 - func = adb_write_pram; 490 - #else 491 - return; 492 - #endif 493 - } else { 494 func = via_write_pram; 495 } 496 for (i = 0 ; i < len ; i++) { 497 (*func)(offset++, buffer[i]); 498 } ··· 514 } else if (macintosh_config->adb_type == MAC_ADB_CUDA) { 515 cuda_shutdown(); 516 #endif 517 - #ifdef CONFIG_ADB_PMU 518 } else if (macintosh_config->adb_type == MAC_ADB_PB1 519 || macintosh_config->adb_type == MAC_ADB_PB2) { 520 pmu_shutdown(); ··· 554 } else if (macintosh_config->adb_type == MAC_ADB_CUDA) { 555 cuda_restart(); 556 #endif 557 - #ifdef CONFIG_ADB_PMU 558 } else if (macintosh_config->adb_type == MAC_ADB_PB1 559 || macintosh_config->adb_type == MAC_ADB_PB2) { 560 pmu_restart(); ··· 694 unsigned long now; 695 696 if (!op) { /* read */ 697 - if (macintosh_config->adb_type == MAC_ADB_II) { 698 now = via_read_time(); 699 - } else 700 - #ifdef CONFIG_ADB 701 - if ((macintosh_config->adb_type == MAC_ADB_IISI) || 702 - (macintosh_config->adb_type == MAC_ADB_PB1) || 703 - (macintosh_config->adb_type == MAC_ADB_PB2) || 704 - (macintosh_config->adb_type == MAC_ADB_CUDA)) { 705 - now = adb_read_time(); 706 - } else 707 - #endif 708 - if (macintosh_config->adb_type == MAC_ADB_IOP) { 709 - now = via_read_time(); 710 - } else { 711 now = 0; 712 } 713 ··· 727 now = mktime(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, 728 t->tm_hour, t->tm_min, t->tm_sec); 729 730 - if (macintosh_config->adb_type == MAC_ADB_II) { 731 via_write_time(now); 732 - } else if ((macintosh_config->adb_type == MAC_ADB_IISI) || 733 - (macintosh_config->adb_type == MAC_ADB_PB1) || 734 - (macintosh_config->adb_type == MAC_ADB_PB2) || 735 - (macintosh_config->adb_type == MAC_ADB_CUDA)) { 736 - adb_write_time(now); 737 - } else if (macintosh_config->adb_type == MAC_ADB_IOP) { 738 - via_write_time(now); 739 } 740 #endif 741 }
··· 39 extern struct mac_booter_data mac_bi_data; 40 static void (*rom_reset)(void); 41 42 + #ifdef CONFIG_ADB_CUDA 43 + static long cuda_read_time(void) 44 { 45 + struct adb_request req; 46 long time; 47 48 + if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_GET_TIME) < 0) 49 + return 0; 50 + while (!req.complete) 51 + cuda_poll(); 52 53 time = (req.reply[3] << 24) | (req.reply[4] << 16) 54 | (req.reply[5] << 8) | req.reply[6]; 55 return time - RTC_OFFSET; 56 } 57 58 + static void cuda_write_time(long data) 59 { 60 + struct adb_request req; 61 data += RTC_OFFSET; 62 + if (cuda_request(&req, NULL, 6, CUDA_PACKET, CUDA_SET_TIME, 63 + (data >> 24) & 0xFF, (data >> 16) & 0xFF, 64 + (data >> 8) & 0xFF, data & 0xFF) < 0) 65 + return; 66 + while (!req.complete) 67 + cuda_poll(); 68 + } 69 70 + static __u8 cuda_read_pram(int offset) 71 + { 72 + struct adb_request req; 73 + if (cuda_request(&req, NULL, 4, CUDA_PACKET, CUDA_GET_PRAM, 74 + (offset >> 8) & 0xFF, offset & 0xFF) < 0) 75 + return 0; 76 + while (!req.complete) 77 + cuda_poll(); 78 + return req.reply[3]; 79 + } 80 + 81 + static void cuda_write_pram(int offset, __u8 data) 82 + { 83 + struct adb_request req; 84 + if (cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_SET_PRAM, 85 + (offset >> 8) & 0xFF, offset & 0xFF, data) < 0) 86 + return; 87 + while (!req.complete) 88 + cuda_poll(); 89 + } 90 + #else 91 + #define cuda_read_time() 0 92 + #define cuda_write_time(n) 93 + #define cuda_read_pram NULL 94 + #define cuda_write_pram NULL 95 + #endif 96 + 97 + #ifdef CONFIG_ADB_PMU68K 98 + static long pmu_read_time(void) 99 + { 100 + struct adb_request req; 101 + long time; 102 + 103 + if (pmu_request(&req, NULL, 1, PMU_READ_RTC) < 0) 104 + return 0; 105 + while (!req.complete) 106 + pmu_poll(); 107 + 108 + time = (req.reply[0] << 24) | (req.reply[1] << 16) 109 + | (req.reply[2] << 8) | req.reply[3]; 110 + return time - RTC_OFFSET; 111 + } 112 + 113 + static void pmu_write_time(long data) 114 + { 115 + struct adb_request req; 116 + data += RTC_OFFSET; 117 + if (pmu_request(&req, NULL, 5, PMU_SET_RTC, 118 + (data >> 24) & 0xFF, (data >> 16) & 0xFF, 119 + (data >> 8) & 0xFF, data & 0xFF) < 0) 120 + return; 121 + while (!req.complete) 122 + pmu_poll(); 123 + } 124 + 125 + static __u8 pmu_read_pram(int offset) 126 + { 127 + struct adb_request req; 128 + if (pmu_request(&req, NULL, 3, PMU_READ_NVRAM, 129 + (offset >> 8) & 0xFF, offset & 0xFF) < 0) 130 + return 0; 131 + while (!req.complete) 132 + pmu_poll(); 133 + return req.reply[3]; 134 + } 135 + 136 + static void pmu_write_pram(int offset, __u8 data) 137 + { 138 + struct adb_request req; 139 + if (pmu_request(&req, NULL, 4, PMU_WRITE_NVRAM, 140 + (offset >> 8) & 0xFF, offset & 0xFF, data) < 0) 141 + return; 142 + while (!req.complete) 143 + pmu_poll(); 144 + } 145 + #else 146 + #define pmu_read_time() 0 147 + #define pmu_write_time(n) 148 + #define pmu_read_pram NULL 149 + #define pmu_write_pram NULL 150 + #endif 151 + 152 + #ifdef CONFIG_ADB_MACIISI 153 + extern int maciisi_request(struct adb_request *req, 154 + void (*done)(struct adb_request *), int nbytes, ...); 155 + 156 + static long maciisi_read_time(void) 157 + { 158 + struct adb_request req; 159 + long time; 160 + 161 + if (maciisi_request(&req, NULL, 2, CUDA_PACKET, CUDA_GET_TIME)) 162 + return 0; 163 + 164 + time = (req.reply[3] << 24) | (req.reply[4] << 16) 165 + | (req.reply[5] << 8) | req.reply[6]; 166 + return time - RTC_OFFSET; 167 + } 168 + 169 + static void maciisi_write_time(long data) 170 + { 171 + struct adb_request req; 172 + data += RTC_OFFSET; 173 + maciisi_request(&req, NULL, 6, CUDA_PACKET, CUDA_SET_TIME, 174 (data >> 24) & 0xFF, (data >> 16) & 0xFF, 175 (data >> 8) & 0xFF, data & 0xFF); 176 } 177 178 + static __u8 maciisi_read_pram(int offset) 179 { 180 + struct adb_request req; 181 + if (maciisi_request(&req, NULL, 4, CUDA_PACKET, CUDA_GET_PRAM, 182 + (offset >> 8) & 0xFF, offset & 0xFF)) 183 + return 0; 184 return req.reply[3]; 185 } 186 187 + static void maciisi_write_pram(int offset, __u8 data) 188 { 189 + struct adb_request req; 190 + maciisi_request(&req, NULL, 5, CUDA_PACKET, CUDA_SET_PRAM, 191 + (offset >> 8) & 0xFF, offset & 0xFF, data); 192 } 193 + #else 194 + #define maciisi_read_time() 0 195 + #define maciisi_write_time(n) 196 + #define maciisi_read_pram NULL 197 + #define maciisi_write_pram NULL 198 + #endif 199 200 /* 201 * VIA PRAM/RTC access routines ··· 305 306 static void cuda_restart(void) 307 { 308 + struct adb_request req; 309 + if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_RESET_SYSTEM) < 0) 310 + return; 311 + while (!req.complete) 312 + cuda_poll(); 313 } 314 315 static void cuda_shutdown(void) 316 { 317 + struct adb_request req; 318 + if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_POWERDOWN) < 0) 319 + return; 320 + while (!req.complete) 321 + cuda_poll(); 322 } 323 324 #endif /* CONFIG_ADB_CUDA */ 325 326 + #ifdef CONFIG_ADB_PMU68K 327 328 void pmu_restart(void) 329 { 330 + struct adb_request req; 331 + if (pmu_request(&req, NULL, 332 + 2, PMU_SET_INTR_MASK, PMU_INT_ADB|PMU_INT_TICK) < 0) 333 + return; 334 + while (!req.complete) 335 + pmu_poll(); 336 + if (pmu_request(&req, NULL, 1, PMU_RESET) < 0) 337 + return; 338 + while (!req.complete) 339 + pmu_poll(); 340 } 341 342 void pmu_shutdown(void) 343 { 344 + struct adb_request req; 345 + if (pmu_request(&req, NULL, 346 + 2, PMU_SET_INTR_MASK, PMU_INT_ADB|PMU_INT_TICK) < 0) 347 + return; 348 + while (!req.complete) 349 + pmu_poll(); 350 + if (pmu_request(&req, NULL, 5, PMU_SHUTDOWN, 'M', 'A', 'T', 'T') < 0) 351 + return; 352 + while (!req.complete) 353 + pmu_poll(); 354 } 355 356 + #endif 357 358 /* 359 *------------------------------------------------------------------- ··· 351 352 void mac_pram_read(int offset, __u8 *buffer, int len) 353 { 354 + __u8 (*func)(int); 355 int i; 356 357 + switch(macintosh_config->adb_type) { 358 + case MAC_ADB_IISI: 359 + func = maciisi_read_pram; break; 360 + case MAC_ADB_PB1: 361 + case MAC_ADB_PB2: 362 + func = pmu_read_pram; break; 363 + case MAC_ADB_CUDA: 364 + func = cuda_read_pram; break; 365 + default: 366 func = via_read_pram; 367 } 368 + if (!func) 369 + return; 370 for (i = 0 ; i < len ; i++) { 371 buffer[i] = (*func)(offset++); 372 } ··· 373 374 void mac_pram_write(int offset, __u8 *buffer, int len) 375 { 376 + void (*func)(int, __u8); 377 int i; 378 379 + switch(macintosh_config->adb_type) { 380 + case MAC_ADB_IISI: 381 + func = maciisi_write_pram; break; 382 + case MAC_ADB_PB1: 383 + case MAC_ADB_PB2: 384 + func = pmu_write_pram; break; 385 + case MAC_ADB_CUDA: 386 + func = cuda_write_pram; break; 387 + default: 388 func = via_write_pram; 389 } 390 + if (!func) 391 + return; 392 for (i = 0 ; i < len ; i++) { 393 (*func)(offset++, buffer[i]); 394 } ··· 408 } else if (macintosh_config->adb_type == MAC_ADB_CUDA) { 409 cuda_shutdown(); 410 #endif 411 + #ifdef CONFIG_ADB_PMU68K 412 } else if (macintosh_config->adb_type == MAC_ADB_PB1 413 || macintosh_config->adb_type == MAC_ADB_PB2) { 414 pmu_shutdown(); ··· 448 } else if (macintosh_config->adb_type == MAC_ADB_CUDA) { 449 cuda_restart(); 450 #endif 451 + #ifdef CONFIG_ADB_PMU68K 452 } else if (macintosh_config->adb_type == MAC_ADB_PB1 453 || macintosh_config->adb_type == MAC_ADB_PB2) { 454 pmu_restart(); ··· 588 unsigned long now; 589 590 if (!op) { /* read */ 591 + switch (macintosh_config->adb_type) { 592 + case MAC_ADB_II: 593 + case MAC_ADB_IOP: 594 now = via_read_time(); 595 + break; 596 + case MAC_ADB_IISI: 597 + now = maciisi_read_time(); 598 + break; 599 + case MAC_ADB_PB1: 600 + case MAC_ADB_PB2: 601 + now = pmu_read_time(); 602 + break; 603 + case MAC_ADB_CUDA: 604 + now = cuda_read_time(); 605 + break; 606 + default: 607 now = 0; 608 } 609 ··· 619 now = mktime(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, 620 t->tm_hour, t->tm_min, t->tm_sec); 621 622 + switch (macintosh_config->adb_type) { 623 + case MAC_ADB_II: 624 + case MAC_ADB_IOP: 625 via_write_time(now); 626 + break; 627 + case MAC_ADB_CUDA: 628 + cuda_write_time(now); 629 + break; 630 + case MAC_ADB_PB1: 631 + case MAC_ADB_PB2: 632 + pmu_write_time(now); 633 + break; 634 + case MAC_ADB_IISI: 635 + maciisi_write_time(now); 636 } 637 #endif 638 }
+18
drivers/macintosh/via-maciisi.c
··· 294 printk(KERN_ERR "maciisi_send_request: poll timed out!\n"); 295 } 296 297 /* Enqueue a request, and run the queue if possible */ 298 static int 299 maciisi_write(struct adb_request* req)
··· 294 printk(KERN_ERR "maciisi_send_request: poll timed out!\n"); 295 } 296 297 + int 298 + maciisi_request(struct adb_request *req, void (*done)(struct adb_request *), 299 + int nbytes, ...) 300 + { 301 + va_list list; 302 + int i; 303 + 304 + req->nbytes = nbytes; 305 + req->done = done; 306 + req->reply_expected = 0; 307 + va_start(list, nbytes); 308 + for (i = 0; i < nbytes; i++) 309 + req->data[i++] = va_arg(list, int); 310 + va_end(list); 311 + 312 + return maciisi_send_request(req, 1); 313 + } 314 + 315 /* Enqueue a request, and run the queue if possible */ 316 static int 317 maciisi_write(struct adb_request* req)