summaryrefslogtreecommitdiffstats
path: root/drivers/macintosh
diff options
context:
space:
mode:
authorFinn Thain <fthain@telegraphics.com.au>2018-09-11 20:18:44 -0400
committerMichael Ellerman <mpe@ellerman.id.au>2018-10-08 07:53:10 -0400
commit0792a2c8e0bbda3605b8d42c6b9635be7b19982a (patch)
treeba1ddd80dac3a672746caa2447a217cec910cbee /drivers/macintosh
parent053c5a753e951c5dd1729af2cf4d8107f2e6e09b (diff)
macintosh: Use common code to access RTC
Now that the 68k Mac port has adopted the via-pmu driver, the same RTC code can be shared between m68k and powerpc. Replace duplicated code in arch/powerpc and arch/m68k with common RTC accessors for Cuda and PMU. Drop the problematic WARN_ON which was introduced in commit 22db552b50fa ("powerpc/powermac: Fix rtc read/write functions"). Tested-by: Stan Johnson <userm57@yahoo.com> Signed-off-by: Finn Thain <fthain@telegraphics.com.au> Cc: Geert Uytterhoeven <geert@linux-m68k.org> Cc: Arnd Bergmann <arnd@arndb.de> Acked-by: Geert Uytterhoeven <geert@linux-m68k.org> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Diffstat (limited to 'drivers/macintosh')
-rw-r--r--drivers/macintosh/via-cuda.c35
-rw-r--r--drivers/macintosh/via-pmu.c33
2 files changed, 68 insertions, 0 deletions
diff --git a/drivers/macintosh/via-cuda.c b/drivers/macintosh/via-cuda.c
index 98dd702eb867..bbec6ac0a966 100644
--- a/drivers/macintosh/via-cuda.c
+++ b/drivers/macintosh/via-cuda.c
@@ -766,3 +766,38 @@ cuda_input(unsigned char *buf, int nb)
766 buf, nb, false); 766 buf, nb, false);
767 } 767 }
768} 768}
769
770/* Offset between Unix time (1970-based) and Mac time (1904-based) */
771#define RTC_OFFSET 2082844800
772
773time64_t cuda_get_time(void)
774{
775 struct adb_request req;
776 u32 now;
777
778 if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_GET_TIME) < 0)
779 return 0;
780 while (!req.complete)
781 cuda_poll();
782 if (req.reply_len != 7)
783 pr_err("%s: got %d byte reply\n", __func__, req.reply_len);
784 now = (req.reply[3] << 24) + (req.reply[4] << 16) +
785 (req.reply[5] << 8) + req.reply[6];
786 return (time64_t)now - RTC_OFFSET;
787}
788
789int cuda_set_rtc_time(struct rtc_time *tm)
790{
791 u32 now;
792 struct adb_request req;
793
794 now = lower_32_bits(rtc_tm_to_time64(tm) + RTC_OFFSET);
795 if (cuda_request(&req, NULL, 6, CUDA_PACKET, CUDA_SET_TIME,
796 now >> 24, now >> 16, now >> 8, now) < 0)
797 return -ENXIO;
798 while (!req.complete)
799 cuda_poll();
800 if ((req.reply_len != 3) && (req.reply_len != 7))
801 pr_err("%s: got %d byte reply\n", __func__, req.reply_len);
802 return 0;
803}
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
index d72c450aebe5..60f57e2abf21 100644
--- a/drivers/macintosh/via-pmu.c
+++ b/drivers/macintosh/via-pmu.c
@@ -1737,6 +1737,39 @@ pmu_enable_irled(int on)
1737 pmu_wait_complete(&req); 1737 pmu_wait_complete(&req);
1738} 1738}
1739 1739
1740/* Offset between Unix time (1970-based) and Mac time (1904-based) */
1741#define RTC_OFFSET 2082844800
1742
1743time64_t pmu_get_time(void)
1744{
1745 struct adb_request req;
1746 u32 now;
1747
1748 if (pmu_request(&req, NULL, 1, PMU_READ_RTC) < 0)
1749 return 0;
1750 pmu_wait_complete(&req);
1751 if (req.reply_len != 4)
1752 pr_err("%s: got %d byte reply\n", __func__, req.reply_len);
1753 now = (req.reply[0] << 24) + (req.reply[1] << 16) +
1754 (req.reply[2] << 8) + req.reply[3];
1755 return (time64_t)now - RTC_OFFSET;
1756}
1757
1758int pmu_set_rtc_time(struct rtc_time *tm)
1759{
1760 u32 now;
1761 struct adb_request req;
1762
1763 now = lower_32_bits(rtc_tm_to_time64(tm) + RTC_OFFSET);
1764 if (pmu_request(&req, NULL, 5, PMU_SET_RTC,
1765 now >> 24, now >> 16, now >> 8, now) < 0)
1766 return -ENXIO;
1767 pmu_wait_complete(&req);
1768 if (req.reply_len != 0)
1769 pr_err("%s: got %d byte reply\n", __func__, req.reply_len);
1770 return 0;
1771}
1772
1740void 1773void
1741pmu_restart(void) 1774pmu_restart(void)
1742{ 1775{