Commit 3272244c2b1a8f13cec83c04b8245fa7fcb47a27
Committed by
Linus Torvalds
1 parent
b4290a23cf
Exists in
master
and in
4 other branches
[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>
Showing 2 changed files with 236 additions and 105 deletions Side-by-side Diff
arch/m68k/mac/misc.c
... | ... | @@ -39,72 +39,163 @@ |
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 | - */ | |
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 | +} | |
64 | 69 | |
65 | -static void adb_write_time(long data) | |
70 | +static __u8 cuda_read_pram(int offset) | |
66 | 71 | { |
67 | - volatile struct adb_request req; | |
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 | +} | |
68 | 80 | |
69 | - data += RTC_OFFSET; | |
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 | |
70 | 96 | |
71 | - adb_request((struct adb_request *) &req, NULL, | |
72 | - ADBREQ_RAW|ADBREQ_SYNC, | |
73 | - 6, CUDA_PACKET, CUDA_SET_TIME, | |
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, | |
74 | 118 | (data >> 24) & 0xFF, (data >> 16) & 0xFF, |
75 | - (data >> 8) & 0xFF, data & 0xFF); | |
119 | + (data >> 8) & 0xFF, data & 0xFF) < 0) | |
120 | + return; | |
121 | + while (!req.complete) | |
122 | + pmu_poll(); | |
76 | 123 | } |
77 | 124 | |
78 | -/* | |
79 | - * Get a byte from the NVRAM | |
80 | - */ | |
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 | +} | |
81 | 135 | |
82 | -static __u8 adb_read_pram(int offset) | |
136 | +static void pmu_write_pram(int offset, __u8 data) | |
83 | 137 | { |
84 | - volatile struct adb_request req; | |
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 | |
85 | 151 | |
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]; | |
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; | |
91 | 167 | } |
92 | 168 | |
93 | -/* | |
94 | - * Write a byte to the NVRAM | |
95 | - */ | |
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 | +} | |
96 | 177 | |
97 | -static void adb_write_pram(int offset, __u8 data) | |
178 | +static __u8 maciisi_read_pram(int offset) | |
98 | 179 | { |
99 | - volatile struct adb_request req; | |
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 | +} | |
100 | 186 | |
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); | |
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); | |
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 |
111 | 202 | |
112 | 203 | |
113 | 204 | |
114 | 205 | |
115 | 206 | |
... | ... | @@ -305,42 +396,55 @@ |
305 | 396 | |
306 | 397 | static void cuda_restart(void) |
307 | 398 | { |
308 | - adb_request(NULL, NULL, ADBREQ_RAW|ADBREQ_SYNC, | |
309 | - 2, CUDA_PACKET, CUDA_RESET_SYSTEM); | |
399 | + struct adb_request req; | |
400 | + if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_RESET_SYSTEM) < 0) | |
401 | + return; | |
402 | + while (!req.complete) | |
403 | + cuda_poll(); | |
310 | 404 | } |
311 | 405 | |
312 | 406 | static void cuda_shutdown(void) |
313 | 407 | { |
314 | - adb_request(NULL, NULL, ADBREQ_RAW|ADBREQ_SYNC, | |
315 | - 2, CUDA_PACKET, CUDA_POWERDOWN); | |
408 | + struct adb_request req; | |
409 | + if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_POWERDOWN) < 0) | |
410 | + return; | |
411 | + while (!req.complete) | |
412 | + cuda_poll(); | |
316 | 413 | } |
317 | 414 | |
318 | 415 | #endif /* CONFIG_ADB_CUDA */ |
319 | 416 | |
320 | -#ifdef CONFIG_ADB_PMU | |
417 | +#ifdef CONFIG_ADB_PMU68K | |
321 | 418 | |
322 | 419 | void pmu_restart(void) |
323 | 420 | { |
324 | - adb_request(NULL, NULL, ADBREQ_RAW|ADBREQ_SYNC, | |
325 | - 3, PMU_PACKET, PMU_SET_INTR_MASK, | |
326 | - PMU_INT_ADB|PMU_INT_TICK); | |
327 | - | |
328 | - adb_request(NULL, NULL, ADBREQ_RAW|ADBREQ_SYNC, | |
329 | - 2, PMU_PACKET, PMU_RESET); | |
421 | + struct adb_request req; | |
422 | + if (pmu_request(&req, NULL, | |
423 | + 2, PMU_SET_INTR_MASK, PMU_INT_ADB|PMU_INT_TICK) < 0) | |
424 | + return; | |
425 | + while (!req.complete) | |
426 | + pmu_poll(); | |
427 | + if (pmu_request(&req, NULL, 1, PMU_RESET) < 0) | |
428 | + return; | |
429 | + while (!req.complete) | |
430 | + pmu_poll(); | |
330 | 431 | } |
331 | 432 | |
332 | 433 | void pmu_shutdown(void) |
333 | 434 | { |
334 | - adb_request(NULL, NULL, ADBREQ_RAW|ADBREQ_SYNC, | |
335 | - 3, PMU_PACKET, PMU_SET_INTR_MASK, | |
336 | - PMU_INT_ADB|PMU_INT_TICK); | |
337 | - | |
338 | - adb_request(NULL, NULL, ADBREQ_RAW|ADBREQ_SYNC, | |
339 | - 6, PMU_PACKET, PMU_SHUTDOWN, | |
340 | - 'M', 'A', 'T', 'T'); | |
435 | + struct adb_request req; | |
436 | + if (pmu_request(&req, NULL, | |
437 | + 2, PMU_SET_INTR_MASK, PMU_INT_ADB|PMU_INT_TICK) < 0) | |
438 | + return; | |
439 | + while (!req.complete) | |
440 | + pmu_poll(); | |
441 | + if (pmu_request(&req, NULL, 5, PMU_SHUTDOWN, 'M', 'A', 'T', 'T') < 0) | |
442 | + return; | |
443 | + while (!req.complete) | |
444 | + pmu_poll(); | |
341 | 445 | } |
342 | 446 | |
343 | -#endif /* CONFIG_ADB_PMU */ | |
447 | +#endif | |
344 | 448 | |
345 | 449 | /* |
346 | 450 | *------------------------------------------------------------------- |
347 | 451 | |
348 | 452 | |
... | ... | @@ -351,21 +455,22 @@ |
351 | 455 | |
352 | 456 | void mac_pram_read(int offset, __u8 *buffer, int len) |
353 | 457 | { |
354 | - __u8 (*func)(int) = NULL; | |
458 | + __u8 (*func)(int); | |
355 | 459 | int i; |
356 | 460 | |
357 | - if (macintosh_config->adb_type == MAC_ADB_IISI || | |
358 | - macintosh_config->adb_type == MAC_ADB_PB1 || | |
359 | - macintosh_config->adb_type == MAC_ADB_PB2 || | |
360 | - macintosh_config->adb_type == MAC_ADB_CUDA) { | |
361 | -#ifdef CONFIG_ADB | |
362 | - func = adb_read_pram; | |
363 | -#else | |
364 | - return; | |
365 | -#endif | |
366 | - } else { | |
461 | + switch(macintosh_config->adb_type) { | |
462 | + case MAC_ADB_IISI: | |
463 | + func = maciisi_read_pram; break; | |
464 | + case MAC_ADB_PB1: | |
465 | + case MAC_ADB_PB2: | |
466 | + func = pmu_read_pram; break; | |
467 | + case MAC_ADB_CUDA: | |
468 | + func = cuda_read_pram; break; | |
469 | + default: | |
367 | 470 | func = via_read_pram; |
368 | 471 | } |
472 | + if (!func) | |
473 | + return; | |
369 | 474 | for (i = 0 ; i < len ; i++) { |
370 | 475 | buffer[i] = (*func)(offset++); |
371 | 476 | } |
372 | 477 | |
373 | 478 | |
... | ... | @@ -373,21 +478,22 @@ |
373 | 478 | |
374 | 479 | void mac_pram_write(int offset, __u8 *buffer, int len) |
375 | 480 | { |
376 | - void (*func)(int, __u8) = NULL; | |
481 | + void (*func)(int, __u8); | |
377 | 482 | int i; |
378 | 483 | |
379 | - if (macintosh_config->adb_type == MAC_ADB_IISI || | |
380 | - macintosh_config->adb_type == MAC_ADB_PB1 || | |
381 | - macintosh_config->adb_type == MAC_ADB_PB2 || | |
382 | - macintosh_config->adb_type == MAC_ADB_CUDA) { | |
383 | -#ifdef CONFIG_ADB | |
384 | - func = adb_write_pram; | |
385 | -#else | |
386 | - return; | |
387 | -#endif | |
388 | - } else { | |
484 | + switch(macintosh_config->adb_type) { | |
485 | + case MAC_ADB_IISI: | |
486 | + func = maciisi_write_pram; break; | |
487 | + case MAC_ADB_PB1: | |
488 | + case MAC_ADB_PB2: | |
489 | + func = pmu_write_pram; break; | |
490 | + case MAC_ADB_CUDA: | |
491 | + func = cuda_write_pram; break; | |
492 | + default: | |
389 | 493 | func = via_write_pram; |
390 | 494 | } |
495 | + if (!func) | |
496 | + return; | |
391 | 497 | for (i = 0 ; i < len ; i++) { |
392 | 498 | (*func)(offset++, buffer[i]); |
393 | 499 | } |
... | ... | @@ -408,7 +514,7 @@ |
408 | 514 | } else if (macintosh_config->adb_type == MAC_ADB_CUDA) { |
409 | 515 | cuda_shutdown(); |
410 | 516 | #endif |
411 | -#ifdef CONFIG_ADB_PMU | |
517 | +#ifdef CONFIG_ADB_PMU68K | |
412 | 518 | } else if (macintosh_config->adb_type == MAC_ADB_PB1 |
413 | 519 | || macintosh_config->adb_type == MAC_ADB_PB2) { |
414 | 520 | pmu_shutdown(); |
... | ... | @@ -448,7 +554,7 @@ |
448 | 554 | } else if (macintosh_config->adb_type == MAC_ADB_CUDA) { |
449 | 555 | cuda_restart(); |
450 | 556 | #endif |
451 | -#ifdef CONFIG_ADB_PMU | |
557 | +#ifdef CONFIG_ADB_PMU68K | |
452 | 558 | } else if (macintosh_config->adb_type == MAC_ADB_PB1 |
453 | 559 | || macintosh_config->adb_type == MAC_ADB_PB2) { |
454 | 560 | pmu_restart(); |
455 | 561 | |
... | ... | @@ -588,20 +694,22 @@ |
588 | 694 | unsigned long now; |
589 | 695 | |
590 | 696 | if (!op) { /* read */ |
591 | - if (macintosh_config->adb_type == MAC_ADB_II) { | |
697 | + switch (macintosh_config->adb_type) { | |
698 | + case MAC_ADB_II: | |
699 | + case MAC_ADB_IOP: | |
592 | 700 | now = via_read_time(); |
593 | - } else | |
594 | -#ifdef CONFIG_ADB | |
595 | - if ((macintosh_config->adb_type == MAC_ADB_IISI) || | |
596 | - (macintosh_config->adb_type == MAC_ADB_PB1) || | |
597 | - (macintosh_config->adb_type == MAC_ADB_PB2) || | |
598 | - (macintosh_config->adb_type == MAC_ADB_CUDA)) { | |
599 | - now = adb_read_time(); | |
600 | - } else | |
601 | -#endif | |
602 | - if (macintosh_config->adb_type == MAC_ADB_IOP) { | |
603 | - now = via_read_time(); | |
604 | - } else { | |
701 | + break; | |
702 | + case MAC_ADB_IISI: | |
703 | + now = maciisi_read_time(); | |
704 | + break; | |
705 | + case MAC_ADB_PB1: | |
706 | + case MAC_ADB_PB2: | |
707 | + now = pmu_read_time(); | |
708 | + break; | |
709 | + case MAC_ADB_CUDA: | |
710 | + now = cuda_read_time(); | |
711 | + break; | |
712 | + default: | |
605 | 713 | now = 0; |
606 | 714 | } |
607 | 715 | |
608 | 716 | |
... | ... | @@ -619,15 +727,20 @@ |
619 | 727 | now = mktime(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, |
620 | 728 | t->tm_hour, t->tm_min, t->tm_sec); |
621 | 729 | |
622 | - if (macintosh_config->adb_type == MAC_ADB_II) { | |
730 | + switch (macintosh_config->adb_type) { | |
731 | + case MAC_ADB_II: | |
732 | + case MAC_ADB_IOP: | |
623 | 733 | via_write_time(now); |
624 | - } else if ((macintosh_config->adb_type == MAC_ADB_IISI) || | |
625 | - (macintosh_config->adb_type == MAC_ADB_PB1) || | |
626 | - (macintosh_config->adb_type == MAC_ADB_PB2) || | |
627 | - (macintosh_config->adb_type == MAC_ADB_CUDA)) { | |
628 | - adb_write_time(now); | |
629 | - } else if (macintosh_config->adb_type == MAC_ADB_IOP) { | |
630 | - via_write_time(now); | |
734 | + break; | |
735 | + case MAC_ADB_CUDA: | |
736 | + cuda_write_time(now); | |
737 | + break; | |
738 | + case MAC_ADB_PB1: | |
739 | + case MAC_ADB_PB2: | |
740 | + pmu_write_time(now); | |
741 | + break; | |
742 | + case MAC_ADB_IISI: | |
743 | + maciisi_write_time(now); | |
631 | 744 | } |
632 | 745 | #endif |
633 | 746 | } |
drivers/macintosh/via-maciisi.c
... | ... | @@ -294,6 +294,24 @@ |
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) |