misc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Miscellaneous Mac68K-specific stuff
  4. */
  5. #include <linux/types.h>
  6. #include <linux/errno.h>
  7. #include <linux/kernel.h>
  8. #include <linux/delay.h>
  9. #include <linux/sched.h>
  10. #include <linux/time.h>
  11. #include <linux/rtc.h>
  12. #include <linux/mm.h>
  13. #include <linux/adb.h>
  14. #include <linux/cuda.h>
  15. #include <linux/pmu.h>
  16. #include <linux/uaccess.h>
  17. #include <asm/io.h>
  18. #include <asm/setup.h>
  19. #include <asm/macintosh.h>
  20. #include <asm/mac_via.h>
  21. #include <asm/mac_oss.h>
  22. #include <asm/machdep.h>
  23. /*
  24. * Offset between Unix time (1970-based) and Mac time (1904-based). Cuda and PMU
  25. * times wrap in 2040. If we need to handle later times, the read_time functions
  26. * need to be changed to interpret wrapped times as post-2040.
  27. */
  28. #define RTC_OFFSET 2082844800
  29. static void (*rom_reset)(void);
  30. #if IS_ENABLED(CONFIG_NVRAM)
  31. #ifdef CONFIG_ADB_CUDA
  32. static unsigned char cuda_pram_read_byte(int offset)
  33. {
  34. struct adb_request req;
  35. if (cuda_request(&req, NULL, 4, CUDA_PACKET, CUDA_GET_PRAM,
  36. (offset >> 8) & 0xFF, offset & 0xFF) < 0)
  37. return 0;
  38. while (!req.complete)
  39. cuda_poll();
  40. return req.reply[3];
  41. }
  42. static void cuda_pram_write_byte(unsigned char data, int offset)
  43. {
  44. struct adb_request req;
  45. if (cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_SET_PRAM,
  46. (offset >> 8) & 0xFF, offset & 0xFF, data) < 0)
  47. return;
  48. while (!req.complete)
  49. cuda_poll();
  50. }
  51. #endif /* CONFIG_ADB_CUDA */
  52. #ifdef CONFIG_ADB_PMU
  53. static unsigned char pmu_pram_read_byte(int offset)
  54. {
  55. struct adb_request req;
  56. if (pmu_request(&req, NULL, 3, PMU_READ_XPRAM,
  57. offset & 0xFF, 1) < 0)
  58. return 0;
  59. pmu_wait_complete(&req);
  60. return req.reply[0];
  61. }
  62. static void pmu_pram_write_byte(unsigned char data, int offset)
  63. {
  64. struct adb_request req;
  65. if (pmu_request(&req, NULL, 4, PMU_WRITE_XPRAM,
  66. offset & 0xFF, 1, data) < 0)
  67. return;
  68. pmu_wait_complete(&req);
  69. }
  70. #endif /* CONFIG_ADB_PMU */
  71. #endif /* CONFIG_NVRAM */
  72. /*
  73. * VIA PRAM/RTC access routines
  74. *
  75. * Must be called with interrupts disabled and
  76. * the RTC should be enabled.
  77. */
  78. static __u8 via_rtc_recv(void)
  79. {
  80. int i, reg;
  81. __u8 data;
  82. reg = via1[vBufB] & ~VIA1B_vRTCClk;
  83. /* Set the RTC data line to be an input. */
  84. via1[vDirB] &= ~VIA1B_vRTCData;
  85. /* The bits of the byte come out in MSB order */
  86. data = 0;
  87. for (i = 0 ; i < 8 ; i++) {
  88. via1[vBufB] = reg;
  89. via1[vBufB] = reg | VIA1B_vRTCClk;
  90. data = (data << 1) | (via1[vBufB] & VIA1B_vRTCData);
  91. }
  92. /* Return RTC data line to output state */
  93. via1[vDirB] |= VIA1B_vRTCData;
  94. return data;
  95. }
  96. static void via_rtc_send(__u8 data)
  97. {
  98. int i, reg, bit;
  99. reg = via1[vBufB] & ~(VIA1B_vRTCClk | VIA1B_vRTCData);
  100. /* The bits of the byte go in in MSB order */
  101. for (i = 0 ; i < 8 ; i++) {
  102. bit = data & 0x80? 1 : 0;
  103. data <<= 1;
  104. via1[vBufB] = reg | bit;
  105. via1[vBufB] = reg | bit | VIA1B_vRTCClk;
  106. }
  107. }
  108. /*
  109. * These values can be found in Inside Macintosh vol. III ch. 2
  110. * which has a description of the RTC chip in the original Mac.
  111. */
  112. #define RTC_FLG_READ BIT(7)
  113. #define RTC_FLG_WRITE_PROTECT BIT(7)
  114. #define RTC_CMD_READ(r) (RTC_FLG_READ | (r << 2))
  115. #define RTC_CMD_WRITE(r) (r << 2)
  116. #define RTC_REG_SECONDS_0 0
  117. #define RTC_REG_SECONDS_1 1
  118. #define RTC_REG_SECONDS_2 2
  119. #define RTC_REG_SECONDS_3 3
  120. #define RTC_REG_WRITE_PROTECT 13
  121. /*
  122. * Inside Mac has no information about two-byte RTC commands but
  123. * the MAME/MESS source code has the essentials.
  124. */
  125. #define RTC_REG_XPRAM 14
  126. #define RTC_CMD_XPRAM_READ (RTC_CMD_READ(RTC_REG_XPRAM) << 8)
  127. #define RTC_CMD_XPRAM_WRITE (RTC_CMD_WRITE(RTC_REG_XPRAM) << 8)
  128. #define RTC_CMD_XPRAM_ARG(a) (((a & 0xE0) << 3) | ((a & 0x1F) << 2))
  129. /*
  130. * Execute a VIA PRAM/RTC command. For read commands
  131. * data should point to a one-byte buffer for the
  132. * resulting data. For write commands it should point
  133. * to the data byte to for the command.
  134. *
  135. * This function disables all interrupts while running.
  136. */
  137. static void via_rtc_command(int command, __u8 *data)
  138. {
  139. unsigned long flags;
  140. int is_read;
  141. local_irq_save(flags);
  142. /* The least significant bits must be 0b01 according to Inside Mac */
  143. command = (command & ~3) | 1;
  144. /* Enable the RTC and make sure the strobe line is high */
  145. via1[vBufB] = (via1[vBufB] | VIA1B_vRTCClk) & ~VIA1B_vRTCEnb;
  146. if (command & 0xFF00) { /* extended (two-byte) command */
  147. via_rtc_send((command & 0xFF00) >> 8);
  148. via_rtc_send(command & 0xFF);
  149. is_read = command & (RTC_FLG_READ << 8);
  150. } else { /* one-byte command */
  151. via_rtc_send(command);
  152. is_read = command & RTC_FLG_READ;
  153. }
  154. if (is_read) {
  155. *data = via_rtc_recv();
  156. } else {
  157. via_rtc_send(*data);
  158. }
  159. /* All done, disable the RTC */
  160. via1[vBufB] |= VIA1B_vRTCEnb;
  161. local_irq_restore(flags);
  162. }
  163. #if IS_ENABLED(CONFIG_NVRAM)
  164. static unsigned char via_pram_read_byte(int offset)
  165. {
  166. unsigned char temp;
  167. via_rtc_command(RTC_CMD_XPRAM_READ | RTC_CMD_XPRAM_ARG(offset), &temp);
  168. return temp;
  169. }
  170. static void via_pram_write_byte(unsigned char data, int offset)
  171. {
  172. unsigned char temp;
  173. temp = 0x55;
  174. via_rtc_command(RTC_CMD_WRITE(RTC_REG_WRITE_PROTECT), &temp);
  175. temp = data;
  176. via_rtc_command(RTC_CMD_XPRAM_WRITE | RTC_CMD_XPRAM_ARG(offset), &temp);
  177. temp = 0x55 | RTC_FLG_WRITE_PROTECT;
  178. via_rtc_command(RTC_CMD_WRITE(RTC_REG_WRITE_PROTECT), &temp);
  179. }
  180. #endif /* CONFIG_NVRAM */
  181. /*
  182. * Return the current time in seconds since January 1, 1904.
  183. *
  184. * This only works on machines with the VIA-based PRAM/RTC, which
  185. * is basically any machine with Mac II-style ADB.
  186. */
  187. static time64_t via_read_time(void)
  188. {
  189. union {
  190. __u8 cdata[4];
  191. __u32 idata;
  192. } result, last_result;
  193. int count = 1;
  194. via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_0), &last_result.cdata[3]);
  195. via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_1), &last_result.cdata[2]);
  196. via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_2), &last_result.cdata[1]);
  197. via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_3), &last_result.cdata[0]);
  198. /*
  199. * The NetBSD guys say to loop until you get the same reading
  200. * twice in a row.
  201. */
  202. while (1) {
  203. via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_0),
  204. &result.cdata[3]);
  205. via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_1),
  206. &result.cdata[2]);
  207. via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_2),
  208. &result.cdata[1]);
  209. via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_3),
  210. &result.cdata[0]);
  211. if (result.idata == last_result.idata)
  212. return (time64_t)result.idata - RTC_OFFSET;
  213. if (++count > 10)
  214. break;
  215. last_result.idata = result.idata;
  216. }
  217. pr_err("%s: failed to read a stable value; got 0x%08x then 0x%08x\n",
  218. __func__, last_result.idata, result.idata);
  219. return 0;
  220. }
  221. /*
  222. * Set the current time to a number of seconds since January 1, 1904.
  223. *
  224. * This only works on machines with the VIA-based PRAM/RTC, which
  225. * is basically any machine with Mac II-style ADB.
  226. */
  227. static void via_set_rtc_time(struct rtc_time *tm)
  228. {
  229. union {
  230. __u8 cdata[4];
  231. __u32 idata;
  232. } data;
  233. __u8 temp;
  234. time64_t time;
  235. time = mktime64(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
  236. tm->tm_hour, tm->tm_min, tm->tm_sec);
  237. /* Clear the write protect bit */
  238. temp = 0x55;
  239. via_rtc_command(RTC_CMD_WRITE(RTC_REG_WRITE_PROTECT), &temp);
  240. data.idata = lower_32_bits(time + RTC_OFFSET);
  241. via_rtc_command(RTC_CMD_WRITE(RTC_REG_SECONDS_0), &data.cdata[3]);
  242. via_rtc_command(RTC_CMD_WRITE(RTC_REG_SECONDS_1), &data.cdata[2]);
  243. via_rtc_command(RTC_CMD_WRITE(RTC_REG_SECONDS_2), &data.cdata[1]);
  244. via_rtc_command(RTC_CMD_WRITE(RTC_REG_SECONDS_3), &data.cdata[0]);
  245. /* Set the write protect bit */
  246. temp = 0x55 | RTC_FLG_WRITE_PROTECT;
  247. via_rtc_command(RTC_CMD_WRITE(RTC_REG_WRITE_PROTECT), &temp);
  248. }
  249. static void via_shutdown(void)
  250. {
  251. if (rbv_present) {
  252. via2[rBufB] &= ~0x04;
  253. } else {
  254. /* Direction of vDirB is output */
  255. via2[vDirB] |= 0x04;
  256. /* Send a value of 0 on that line */
  257. via2[vBufB] &= ~0x04;
  258. mdelay(1000);
  259. }
  260. }
  261. static void oss_shutdown(void)
  262. {
  263. oss->rom_ctrl = OSS_POWEROFF;
  264. }
  265. #ifdef CONFIG_ADB_CUDA
  266. static void cuda_restart(void)
  267. {
  268. struct adb_request req;
  269. if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_RESET_SYSTEM) < 0)
  270. return;
  271. while (!req.complete)
  272. cuda_poll();
  273. }
  274. static void cuda_shutdown(void)
  275. {
  276. struct adb_request req;
  277. if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_POWERDOWN) < 0)
  278. return;
  279. /* Avoid infinite polling loop when PSU is not under Cuda control */
  280. switch (macintosh_config->ident) {
  281. case MAC_MODEL_C660:
  282. case MAC_MODEL_Q605:
  283. case MAC_MODEL_Q605_ACC:
  284. case MAC_MODEL_P475:
  285. case MAC_MODEL_P475F:
  286. return;
  287. }
  288. while (!req.complete)
  289. cuda_poll();
  290. }
  291. #endif /* CONFIG_ADB_CUDA */
  292. /*
  293. *-------------------------------------------------------------------
  294. * Below this point are the generic routines; they'll dispatch to the
  295. * correct routine for the hardware on which we're running.
  296. *-------------------------------------------------------------------
  297. */
  298. #if IS_ENABLED(CONFIG_NVRAM)
  299. unsigned char mac_pram_read_byte(int addr)
  300. {
  301. switch (macintosh_config->adb_type) {
  302. case MAC_ADB_IOP:
  303. case MAC_ADB_II:
  304. case MAC_ADB_PB1:
  305. return via_pram_read_byte(addr);
  306. #ifdef CONFIG_ADB_CUDA
  307. case MAC_ADB_EGRET:
  308. case MAC_ADB_CUDA:
  309. return cuda_pram_read_byte(addr);
  310. #endif
  311. #ifdef CONFIG_ADB_PMU
  312. case MAC_ADB_PB2:
  313. return pmu_pram_read_byte(addr);
  314. #endif
  315. default:
  316. return 0xFF;
  317. }
  318. }
  319. void mac_pram_write_byte(unsigned char val, int addr)
  320. {
  321. switch (macintosh_config->adb_type) {
  322. case MAC_ADB_IOP:
  323. case MAC_ADB_II:
  324. case MAC_ADB_PB1:
  325. via_pram_write_byte(val, addr);
  326. break;
  327. #ifdef CONFIG_ADB_CUDA
  328. case MAC_ADB_EGRET:
  329. case MAC_ADB_CUDA:
  330. cuda_pram_write_byte(val, addr);
  331. break;
  332. #endif
  333. #ifdef CONFIG_ADB_PMU
  334. case MAC_ADB_PB2:
  335. pmu_pram_write_byte(val, addr);
  336. break;
  337. #endif
  338. default:
  339. break;
  340. }
  341. }
  342. ssize_t mac_pram_get_size(void)
  343. {
  344. return 256;
  345. }
  346. #endif /* CONFIG_NVRAM */
  347. void mac_poweroff(void)
  348. {
  349. if (oss_present) {
  350. oss_shutdown();
  351. } else if (macintosh_config->adb_type == MAC_ADB_II) {
  352. via_shutdown();
  353. #ifdef CONFIG_ADB_CUDA
  354. } else if (macintosh_config->adb_type == MAC_ADB_EGRET ||
  355. macintosh_config->adb_type == MAC_ADB_CUDA) {
  356. cuda_shutdown();
  357. #endif
  358. #ifdef CONFIG_ADB_PMU
  359. } else if (macintosh_config->adb_type == MAC_ADB_PB2) {
  360. pmu_shutdown();
  361. #endif
  362. }
  363. pr_crit("It is now safe to turn off your Macintosh.\n");
  364. local_irq_disable();
  365. while(1);
  366. }
  367. void mac_reset(void)
  368. {
  369. if (macintosh_config->adb_type == MAC_ADB_II &&
  370. macintosh_config->ident != MAC_MODEL_SE30) {
  371. /* need ROMBASE in booter */
  372. /* indeed, plus need to MAP THE ROM !! */
  373. if (mac_bi_data.rombase == 0)
  374. mac_bi_data.rombase = 0x40800000;
  375. /* works on some */
  376. rom_reset = (void *) (mac_bi_data.rombase + 0xa);
  377. local_irq_disable();
  378. rom_reset();
  379. #ifdef CONFIG_ADB_CUDA
  380. } else if (macintosh_config->adb_type == MAC_ADB_EGRET ||
  381. macintosh_config->adb_type == MAC_ADB_CUDA) {
  382. cuda_restart();
  383. #endif
  384. #ifdef CONFIG_ADB_PMU
  385. } else if (macintosh_config->adb_type == MAC_ADB_PB2) {
  386. pmu_restart();
  387. #endif
  388. } else if (CPU_IS_030) {
  389. /* 030-specific reset routine. The idea is general, but the
  390. * specific registers to reset are '030-specific. Until I
  391. * have a non-030 machine, I can't test anything else.
  392. * -- C. Scott Ananian <[email protected]>
  393. */
  394. unsigned long rombase = 0x40000000;
  395. /* make a 1-to-1 mapping, using the transparent tran. reg. */
  396. unsigned long virt = (unsigned long) mac_reset;
  397. unsigned long phys = virt_to_phys(mac_reset);
  398. unsigned long addr = (phys&0xFF000000)|0x8777;
  399. unsigned long offset = phys-virt;
  400. local_irq_disable(); /* lets not screw this up, ok? */
  401. __asm__ __volatile__(".chip 68030\n\t"
  402. "pmove %0,%/tt0\n\t"
  403. ".chip 68k"
  404. : : "m" (addr));
  405. /* Now jump to physical address so we can disable MMU */
  406. __asm__ __volatile__(
  407. ".chip 68030\n\t"
  408. "lea %/pc@(1f),%/a0\n\t"
  409. "addl %0,%/a0\n\t"/* fixup target address and stack ptr */
  410. "addl %0,%/sp\n\t"
  411. "pflusha\n\t"
  412. "jmp %/a0@\n\t" /* jump into physical memory */
  413. "0:.long 0\n\t" /* a constant zero. */
  414. /* OK. Now reset everything and jump to reset vector. */
  415. "1:\n\t"
  416. "lea %/pc@(0b),%/a0\n\t"
  417. "pmove %/a0@, %/tc\n\t" /* disable mmu */
  418. "pmove %/a0@, %/tt0\n\t" /* disable tt0 */
  419. "pmove %/a0@, %/tt1\n\t" /* disable tt1 */
  420. "movel #0, %/a0\n\t"
  421. "movec %/a0, %/vbr\n\t" /* clear vector base register */
  422. "movec %/a0, %/cacr\n\t" /* disable caches */
  423. "movel #0x0808,%/a0\n\t"
  424. "movec %/a0, %/cacr\n\t" /* flush i&d caches */
  425. "movew #0x2700,%/sr\n\t" /* set up status register */
  426. "movel %1@(0x0),%/a0\n\t"/* load interrupt stack pointer */
  427. "movec %/a0, %/isp\n\t"
  428. "movel %1@(0x4),%/a0\n\t" /* load reset vector */
  429. "reset\n\t" /* reset external devices */
  430. "jmp %/a0@\n\t" /* jump to the reset vector */
  431. ".chip 68k"
  432. : : "r" (offset), "a" (rombase) : "a0");
  433. }
  434. /* should never get here */
  435. pr_crit("Restart failed. Please restart manually.\n");
  436. local_irq_disable();
  437. while(1);
  438. }
  439. /*
  440. * This function translates seconds since 1970 into a proper date.
  441. *
  442. * Algorithm cribbed from glibc2.1, __offtime().
  443. *
  444. * This is roughly same as rtc_time64_to_tm(), which we should probably
  445. * use here, but it's only available when CONFIG_RTC_LIB is enabled.
  446. */
  447. #define SECS_PER_MINUTE (60)
  448. #define SECS_PER_HOUR (SECS_PER_MINUTE * 60)
  449. #define SECS_PER_DAY (SECS_PER_HOUR * 24)
  450. static void unmktime(time64_t time, long offset,
  451. int *yearp, int *monp, int *dayp,
  452. int *hourp, int *minp, int *secp)
  453. {
  454. /* How many days come before each month (0-12). */
  455. static const unsigned short int __mon_yday[2][13] =
  456. {
  457. /* Normal years. */
  458. { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
  459. /* Leap years. */
  460. { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
  461. };
  462. int days, rem, y, wday, yday;
  463. const unsigned short int *ip;
  464. days = div_u64_rem(time, SECS_PER_DAY, &rem);
  465. rem += offset;
  466. while (rem < 0) {
  467. rem += SECS_PER_DAY;
  468. --days;
  469. }
  470. while (rem >= SECS_PER_DAY) {
  471. rem -= SECS_PER_DAY;
  472. ++days;
  473. }
  474. *hourp = rem / SECS_PER_HOUR;
  475. rem %= SECS_PER_HOUR;
  476. *minp = rem / SECS_PER_MINUTE;
  477. *secp = rem % SECS_PER_MINUTE;
  478. /* January 1, 1970 was a Thursday. */
  479. wday = (4 + days) % 7; /* Day in the week. Not currently used */
  480. if (wday < 0) wday += 7;
  481. y = 1970;
  482. #define DIV(a, b) ((a) / (b) - ((a) % (b) < 0))
  483. #define LEAPS_THRU_END_OF(y) (DIV (y, 4) - DIV (y, 100) + DIV (y, 400))
  484. #define __isleap(year) \
  485. ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
  486. while (days < 0 || days >= (__isleap (y) ? 366 : 365))
  487. {
  488. /* Guess a corrected year, assuming 365 days per year. */
  489. long int yg = y + days / 365 - (days % 365 < 0);
  490. /* Adjust DAYS and Y to match the guessed year. */
  491. days -= (yg - y) * 365 +
  492. LEAPS_THRU_END_OF(yg - 1) - LEAPS_THRU_END_OF(y - 1);
  493. y = yg;
  494. }
  495. *yearp = y - 1900;
  496. yday = days; /* day in the year. Not currently used. */
  497. ip = __mon_yday[__isleap(y)];
  498. for (y = 11; days < (long int) ip[y]; --y)
  499. continue;
  500. days -= ip[y];
  501. *monp = y;
  502. *dayp = days + 1; /* day in the month */
  503. return;
  504. }
  505. /*
  506. * Read/write the hardware clock.
  507. */
  508. int mac_hwclk(int op, struct rtc_time *t)
  509. {
  510. time64_t now;
  511. if (!op) { /* read */
  512. switch (macintosh_config->adb_type) {
  513. case MAC_ADB_IOP:
  514. case MAC_ADB_II:
  515. case MAC_ADB_PB1:
  516. now = via_read_time();
  517. break;
  518. #ifdef CONFIG_ADB_CUDA
  519. case MAC_ADB_EGRET:
  520. case MAC_ADB_CUDA:
  521. now = cuda_get_time();
  522. break;
  523. #endif
  524. #ifdef CONFIG_ADB_PMU
  525. case MAC_ADB_PB2:
  526. now = pmu_get_time();
  527. break;
  528. #endif
  529. default:
  530. now = 0;
  531. }
  532. t->tm_wday = 0;
  533. unmktime(now, 0,
  534. &t->tm_year, &t->tm_mon, &t->tm_mday,
  535. &t->tm_hour, &t->tm_min, &t->tm_sec);
  536. pr_debug("%s: read %ptR\n", __func__, t);
  537. } else { /* write */
  538. pr_debug("%s: tried to write %ptR\n", __func__, t);
  539. switch (macintosh_config->adb_type) {
  540. case MAC_ADB_IOP:
  541. case MAC_ADB_II:
  542. case MAC_ADB_PB1:
  543. via_set_rtc_time(t);
  544. break;
  545. #ifdef CONFIG_ADB_CUDA
  546. case MAC_ADB_EGRET:
  547. case MAC_ADB_CUDA:
  548. cuda_set_rtc_time(t);
  549. break;
  550. #endif
  551. #ifdef CONFIG_ADB_PMU
  552. case MAC_ADB_PB2:
  553. pmu_set_rtc_time(t);
  554. break;
  555. #endif
  556. default:
  557. return -ENODEV;
  558. }
  559. }
  560. return 0;
  561. }