5 #include <linux/types.h>
6 #include <linux/errno.h>
8 #include <linux/kernel.h>
10 #include <linux/sched.h>
11 #include <linux/time.h>
12 #include <linux/rtc.h>
15 #include <linux/adb.h>
16 #include <linux/cuda.h>
17 #include <linux/pmu.h>
19 #include <asm/uaccess.h>
22 #include <asm/segment.h>
23 #include <asm/setup.h>
28 #define BOOTINFO_COMPAT_1_0
29 #include <asm/bootinfo.h>
30 #include <asm/machdep.h>
34 #define RTC_OFFSET 2082844800
38 #ifdef CONFIG_ADB_CUDA
49 time = (req.
reply[3] << 24) | (req.
reply[4] << 16)
59 (data >> 24) & 0xFF, (data >> 16) & 0xFF,
60 (data >> 8) & 0xFF, data & 0xFF) < 0)
70 (offset >> 8) & 0xFF, offset & 0xFF) < 0)
81 (offset >> 8) & 0xFF, offset & 0xFF, data) < 0)
87 #define cuda_read_time() 0
88 #define cuda_write_time(n)
89 #define cuda_read_pram NULL
90 #define cuda_write_pram NULL
93 #ifdef CONFIG_ADB_PMU68K
104 time = (req.
reply[1] << 24) | (req.
reply[2] << 16)
114 (data >> 24) & 0xFF, (data >> 16) & 0xFF,
115 (data >> 8) & 0xFF, data & 0xFF) < 0)
117 while (!
req.complete)
125 (offset >> 8) & 0xFF, offset & 0xFF) < 0)
127 while (!
req.complete)
136 (offset >> 8) & 0xFF, offset & 0xFF, data) < 0)
138 while (!
req.complete)
142 #define pmu_read_time() 0
143 #define pmu_write_time(n)
144 #define pmu_read_pram NULL
145 #define pmu_write_pram NULL
160 time = (req.
reply[3] << 24) | (req.
reply[4] << 16)
170 (data >> 24) & 0xFF, (data >> 16) & 0xFF,
171 (data >> 8) & 0xFF, data & 0xFF);
178 (offset >> 8) & 0xFF, offset & 0xFF))
187 (offset >> 8) & 0xFF, offset & 0xFF, data);
190 #define maciisi_read_time() 0
191 #define maciisi_write_time(n)
192 #define maciisi_read_pram NULL
193 #define maciisi_write_pram NULL
203 static __u8 via_pram_readbyte(
void)
217 for (i = 0 ; i < 8 ; i++) {
230 static void via_pram_writebyte(
__u8 data)
238 for (i = 0 ; i < 8 ; i++) {
239 bit = data & 0x80? 1 : 0;
255 static void via_pram_command(
int command,
__u8 *data)
266 if (command & 0xFF00) {
267 via_pram_writebyte((command & 0xFF00) >> 8);
268 via_pram_writebyte(command & 0xFF);
269 is_read = command & 0x8000;
271 via_pram_writebyte(command);
272 is_read = command & 0x80;
275 *data = via_pram_readbyte();
277 via_pram_writebyte(*data);
287 static __u8 via_read_pram(
int offset)
292 static void via_write_pram(
int offset,
__u8 data)
303 static long via_read_time(
void)
311 via_pram_command(0x81, &last_result.cdata[3]);
312 via_pram_command(0x85, &last_result.cdata[2]);
313 via_pram_command(0x89, &last_result.cdata[1]);
314 via_pram_command(0x8D, &last_result.cdata[0]);
322 via_pram_command(0x81, &
result.cdata[3]);
323 via_pram_command(0x85, &
result.cdata[2]);
324 via_pram_command(0x89, &
result.cdata[1]);
325 via_pram_command(0x8D, &
result.cdata[0]);
327 if (
result.idata == last_result.idata)
333 last_result.idata =
result.idata;
336 pr_err(
"via_read_time: failed to read a stable value; "
337 "got 0x%08lx then 0x%08lx\n",
338 last_result.idata,
result.idata);
350 static void via_write_time(
long time)
361 via_pram_command(0x35, &temp);
364 via_pram_command(0x01, &data.cdata[3]);
365 via_pram_command(0x05, &data.cdata[2]);
366 via_pram_command(0x09, &data.cdata[1]);
367 via_pram_command(0x0D, &data.cdata[0]);
372 via_pram_command(0x35, &temp);
375 static void via_shutdown(
void)
392 static void oss_shutdown(
void)
397 #ifdef CONFIG_ADB_CUDA
419 #ifdef CONFIG_ADB_PMU68K
472 func = via_read_pram;
476 for (i = 0 ; i < len ; i++) {
477 buffer[
i] = (*func)(offset++);
495 func = via_write_pram;
499 for (i = 0 ; i < len ; i++) {
500 (*func)(offset++, buffer[
i]);
515 #ifdef CONFIG_ADB_CUDA
519 #ifdef CONFIG_ADB_PMU68K
526 printk(
"It is now safe to turn off your Macintosh.\n");
555 #ifdef CONFIG_ADB_CUDA
559 #ifdef CONFIG_ADB_PMU68K
572 unsigned long rombase = 0x40000000;
577 unsigned long addr = (phys&0xFF000000)|0x8777;
578 unsigned long offset = phys-virt;
580 __asm__ __volatile__(
".chip 68030\n\t"
587 "lea %/pc@(1f),%/a0\n\t"
595 "lea %/pc@(0b),%/a0\n\t"
596 "pmove %/a0@, %/tc\n\t"
597 "pmove %/a0@, %/tt0\n\t"
598 "pmove %/a0@, %/tt1\n\t"
600 "movec %/a0, %/vbr\n\t"
601 "movec %/a0, %/cacr\n\t"
602 "movel #0x0808,%/a0\n\t"
603 "movec %/a0, %/cacr\n\t"
604 "movew #0x2700,%/sr\n\t"
605 "movel %1@(0x0),%/a0\n\t"
606 "movec %/a0, %/isp\n\t"
607 "movel %1@(0x4),%/a0\n\t"
611 : :
"r" (offset),
"a" (rombase) :
"a0");
616 printk (
"Restart failed. Please restart manually.\n");
625 #define SECS_PER_MINUTE (60)
626 #define SECS_PER_HOUR (SECS_PER_MINUTE * 60)
627 #define SECS_PER_DAY (SECS_PER_HOUR * 24)
629 static void unmktime(
unsigned long time,
long offset,
630 int *yearp,
int *monp,
int *dayp,
631 int *hourp,
int *minp,
int *secp)
634 static const unsigned short int __mon_yday[2][13] =
637 { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
639 { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
641 long int days, rem,
y, wday, yday;
642 const unsigned short int *
ip;
660 wday = (4 + days) % 7;
661 if (wday < 0) wday += 7;
664 #define DIV(a, b) ((a) / (b) - ((a) % (b) < 0))
665 #define LEAPS_THRU_END_OF(y) (DIV (y, 4) - DIV (y, 100) + DIV (y, 400))
666 #define __isleap(year) \
667 ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
669 while (days < 0 || days >= (
__isleap (y) ? 366 : 365))
672 long int yg = y + days / 365 - (days % 365 < 0);
675 days -= ((yg -
y) * 365
683 for (y = 11; days < (
long int) ip[y]; --
y)
703 now = via_read_time();
724 printk(
"mac_hwclk: read %04d-%02d-%-2d %02d:%02d:%02d\n",
730 printk(
"mac_hwclk: tried to write %04d-%02d-%-2d %02d:%02d:%02d\n",
766 now.
tm_sec = nowtime % 60;
767 now.
tm_min = (nowtime / 60) % 60;