[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 39 extern struct mac_booter_data mac_bi_data; 40 40 static void (*rom_reset)(void); 41 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) 42 + #ifdef CONFIG_ADB_CUDA 43 + static long cuda_read_time(void) 48 44 { 49 - volatile struct adb_request req; 45 + struct adb_request req; 50 46 long time; 51 47 52 - adb_request((struct adb_request *) &req, NULL, 53 - ADBREQ_RAW|ADBREQ_SYNC, 54 - 2, CUDA_PACKET, CUDA_GET_TIME); 48 + if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_GET_TIME) < 0) 49 + return 0; 50 + while (!req.complete) 51 + cuda_poll(); 55 52 56 53 time = (req.reply[3] << 24) | (req.reply[4] << 16) 57 54 | (req.reply[5] << 8) | req.reply[6]; 58 55 return time - RTC_OFFSET; 59 56 } 60 57 61 - /* 62 - * Set the current system time 63 - */ 64 - 65 - static void adb_write_time(long data) 58 + static void cuda_write_time(long data) 66 59 { 67 - volatile struct adb_request req; 68 - 60 + struct adb_request req; 69 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 + } 70 69 71 - adb_request((struct adb_request *) &req, NULL, 72 - ADBREQ_RAW|ADBREQ_SYNC, 73 - 6, CUDA_PACKET, CUDA_SET_TIME, 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, 74 174 (data >> 24) & 0xFF, (data >> 16) & 0xFF, 75 175 (data >> 8) & 0xFF, data & 0xFF); 76 176 } 77 177 78 - /* 79 - * Get a byte from the NVRAM 80 - */ 81 - 82 - static __u8 adb_read_pram(int offset) 178 + static __u8 maciisi_read_pram(int offset) 83 179 { 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); 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; 90 184 return req.reply[3]; 91 185 } 92 186 93 - /* 94 - * Write a byte to the NVRAM 95 - */ 96 - 97 - static void adb_write_pram(int offset, __u8 data) 187 + static void maciisi_write_pram(int offset, __u8 data) 98 188 { 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); 189 + struct adb_request req; 190 + maciisi_request(&req, NULL, 5, CUDA_PACKET, CUDA_SET_PRAM, 191 + (offset >> 8) & 0xFF, offset & 0xFF, data); 106 192 } 107 - #endif /* CONFIG_ADB */ 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 108 199 109 200 /* 110 201 * VIA PRAM/RTC access routines ··· 396 305 397 306 static void cuda_restart(void) 398 307 { 399 - adb_request(NULL, NULL, ADBREQ_RAW|ADBREQ_SYNC, 400 - 2, CUDA_PACKET, CUDA_RESET_SYSTEM); 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(); 401 313 } 402 314 403 315 static void cuda_shutdown(void) 404 316 { 405 - adb_request(NULL, NULL, ADBREQ_RAW|ADBREQ_SYNC, 406 - 2, CUDA_PACKET, CUDA_POWERDOWN); 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(); 407 322 } 408 323 409 324 #endif /* CONFIG_ADB_CUDA */ 410 325 411 - #ifdef CONFIG_ADB_PMU 326 + #ifdef CONFIG_ADB_PMU68K 412 327 413 328 void pmu_restart(void) 414 329 { 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); 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(); 421 340 } 422 341 423 342 void pmu_shutdown(void) 424 343 { 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'); 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(); 432 354 } 433 355 434 - #endif /* CONFIG_ADB_PMU */ 356 + #endif 435 357 436 358 /* 437 359 *------------------------------------------------------------------- ··· 455 351 456 352 void mac_pram_read(int offset, __u8 *buffer, int len) 457 353 { 458 - __u8 (*func)(int) = NULL; 354 + __u8 (*func)(int); 459 355 int i; 460 356 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 { 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: 471 366 func = via_read_pram; 472 367 } 368 + if (!func) 369 + return; 473 370 for (i = 0 ; i < len ; i++) { 474 371 buffer[i] = (*func)(offset++); 475 372 } ··· 478 373 479 374 void mac_pram_write(int offset, __u8 *buffer, int len) 480 375 { 481 - void (*func)(int, __u8) = NULL; 376 + void (*func)(int, __u8); 482 377 int i; 483 378 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 { 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: 494 388 func = via_write_pram; 495 389 } 390 + if (!func) 391 + return; 496 392 for (i = 0 ; i < len ; i++) { 497 393 (*func)(offset++, buffer[i]); 498 394 } ··· 514 408 } else if (macintosh_config->adb_type == MAC_ADB_CUDA) { 515 409 cuda_shutdown(); 516 410 #endif 517 - #ifdef CONFIG_ADB_PMU 411 + #ifdef CONFIG_ADB_PMU68K 518 412 } else if (macintosh_config->adb_type == MAC_ADB_PB1 519 413 || macintosh_config->adb_type == MAC_ADB_PB2) { 520 414 pmu_shutdown(); ··· 554 448 } else if (macintosh_config->adb_type == MAC_ADB_CUDA) { 555 449 cuda_restart(); 556 450 #endif 557 - #ifdef CONFIG_ADB_PMU 451 + #ifdef CONFIG_ADB_PMU68K 558 452 } else if (macintosh_config->adb_type == MAC_ADB_PB1 559 453 || macintosh_config->adb_type == MAC_ADB_PB2) { 560 454 pmu_restart(); ··· 694 588 unsigned long now; 695 589 696 590 if (!op) { /* read */ 697 - if (macintosh_config->adb_type == MAC_ADB_II) { 591 + switch (macintosh_config->adb_type) { 592 + case MAC_ADB_II: 593 + case MAC_ADB_IOP: 698 594 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 { 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: 711 607 now = 0; 712 608 } 713 609 ··· 727 619 now = mktime(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, 728 620 t->tm_hour, t->tm_min, t->tm_sec); 729 621 730 - if (macintosh_config->adb_type == MAC_ADB_II) { 622 + switch (macintosh_config->adb_type) { 623 + case MAC_ADB_II: 624 + case MAC_ADB_IOP: 731 625 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); 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); 739 636 } 740 637 #endif 741 638 }
+18
drivers/macintosh/via-maciisi.c
··· 294 294 printk(KERN_ERR "maciisi_send_request: poll timed out!\n"); 295 295 } 296 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 + 297 315 /* Enqueue a request, and run the queue if possible */ 298 316 static int 299 317 maciisi_write(struct adb_request* req)