misc.c 16 KB

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