hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/macintosh/via-cuda.c
....@@ -569,6 +569,7 @@
569569 unsigned char ibuf[16];
570570 int ibuf_len = 0;
571571 int complete = 0;
572
+ bool full;
572573
573574 spin_lock_irqsave(&cuda_lock, flags);
574575
....@@ -656,12 +657,13 @@
656657 break;
657658
658659 case reading:
659
- if (reading_reply ? ARRAY_FULL(current_req->reply, reply_ptr)
660
- : ARRAY_FULL(cuda_rbuf, reply_ptr))
660
+ full = reading_reply ? ARRAY_FULL(current_req->reply, reply_ptr)
661
+ : ARRAY_FULL(cuda_rbuf, reply_ptr);
662
+ if (full)
661663 (void)in_8(&via[SR]);
662664 else
663665 *reply_ptr++ = in_8(&via[SR]);
664
- if (!TREQ_asserted(status)) {
666
+ if (!TREQ_asserted(status) || full) {
665667 if (mcu_is_egret)
666668 assert_TACK();
667669 /* that's all folks */
....@@ -766,3 +768,38 @@
766768 buf, nb, false);
767769 }
768770 }
771
+
772
+/* Offset between Unix time (1970-based) and Mac time (1904-based) */
773
+#define RTC_OFFSET 2082844800
774
+
775
+time64_t cuda_get_time(void)
776
+{
777
+ struct adb_request req;
778
+ u32 now;
779
+
780
+ if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_GET_TIME) < 0)
781
+ return 0;
782
+ while (!req.complete)
783
+ cuda_poll();
784
+ if (req.reply_len != 7)
785
+ pr_err("%s: got %d byte reply\n", __func__, req.reply_len);
786
+ now = (req.reply[3] << 24) + (req.reply[4] << 16) +
787
+ (req.reply[5] << 8) + req.reply[6];
788
+ return (time64_t)now - RTC_OFFSET;
789
+}
790
+
791
+int cuda_set_rtc_time(struct rtc_time *tm)
792
+{
793
+ u32 now;
794
+ struct adb_request req;
795
+
796
+ now = lower_32_bits(rtc_tm_to_time64(tm) + RTC_OFFSET);
797
+ if (cuda_request(&req, NULL, 6, CUDA_PACKET, CUDA_SET_TIME,
798
+ now >> 24, now >> 16, now >> 8, now) < 0)
799
+ return -ENXIO;
800
+ while (!req.complete)
801
+ cuda_poll();
802
+ if ((req.reply_len != 3) && (req.reply_len != 7))
803
+ pr_err("%s: got %d byte reply\n", __func__, req.reply_len);
804
+ return 0;
805
+}