misc.c 16 KB

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