.. | .. |
---|
569 | 569 | unsigned char ibuf[16]; |
---|
570 | 570 | int ibuf_len = 0; |
---|
571 | 571 | int complete = 0; |
---|
| 572 | + bool full; |
---|
572 | 573 | |
---|
573 | 574 | spin_lock_irqsave(&cuda_lock, flags); |
---|
574 | 575 | |
---|
.. | .. |
---|
656 | 657 | break; |
---|
657 | 658 | |
---|
658 | 659 | 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) |
---|
661 | 663 | (void)in_8(&via[SR]); |
---|
662 | 664 | else |
---|
663 | 665 | *reply_ptr++ = in_8(&via[SR]); |
---|
664 | | - if (!TREQ_asserted(status)) { |
---|
| 666 | + if (!TREQ_asserted(status) || full) { |
---|
665 | 667 | if (mcu_is_egret) |
---|
666 | 668 | assert_TACK(); |
---|
667 | 669 | /* that's all folks */ |
---|
.. | .. |
---|
766 | 768 | buf, nb, false); |
---|
767 | 769 | } |
---|
768 | 770 | } |
---|
| 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 | +} |
---|