Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp476577imm; Wed, 13 Jun 2018 03:39:40 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL7+PHyO/b0fE3s8w2WbqEWqC+5O/VL7v6Ny0sA583vUbcfFzRU8AWAFoC6rHfA4czEYpEF X-Received: by 2002:a17:902:7791:: with SMTP id o17-v6mr4612647pll.130.1528886380866; Wed, 13 Jun 2018 03:39:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528886380; cv=none; d=google.com; s=arc-20160816; b=HvujwQp9vR+fPkFVpB2ui6IoFYifbCFjgxmRXlO3mqtNOISZWl54i9QU9GGy/FmVsu dyUVgPBrJ8TVD3s+qU6IQtfsQk4R0DeBBtr+bhvayMz+ULkOL7wxzFWg+F4xv0l93Egj uNJ/0/N2oUYVy63NHXmbrGNVTjwwQQhbTC/sbC6mUDfXjiwUjE8rLYySmLff7YuPicXe LVdqdQdcg8NJZGrRXB5wDV2SDs3vd/qJg1snl5qSg+ZFH4PVOqCPSrgrRiGDZ4yAOhLX SEPQ2UKVNjf2xUkSc5cC2S8yGWPLHpkBLgNBWSJFmABzaXNZRy9lxyXZuFn9bWotGutp B3IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:subject:from:references:in-reply-to :message-id:cc:to:arc-authentication-results; bh=szF0PCHR79mVY+o8VEOGdJkSPcyaTnbWWeb0tgNmbuk=; b=083X/+SLFH2PsVhgKRpUNZ/y7+AE9mipvVnCEyFkU8zFGRkP+sWmJ3gPW5nQrk3nAf kZATtPHtHUecJdVvQ+C01azTuCqtsJFHR7od/q12Hom7u2Md7H044mNT7VsJ+A4OD2J8 kv+0QdVp16Ytk+MM7ta/GFC27ef71wzNbZ0MWUm5aHWxNKl0hgZ6mMrHYdwPiR5uqXPF 8TqtjbGZVW9Ge2sFojgTo4Vg3XkmJ5kUUN0SoQc+ZvK+rbNt1DC18C+49WXFdwhCxCl0 43bNall5ZU3UTNjifnlYkwwcq3UOwBgyImljDLJ3gn//UoPS/WmJl2aONuf1lThqhaXW sZeQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q7-v6si2623967pll.445.2018.06.13.03.39.26; Wed, 13 Jun 2018 03:39:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935319AbeFMKiR (ORCPT + 99 others); Wed, 13 Jun 2018 06:38:17 -0400 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:48012 "EHLO kvm5.telegraphics.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935275AbeFMKiG (ORCPT ); Wed, 13 Jun 2018 06:38:06 -0400 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 89151285D0; Wed, 13 Jun 2018 06:38:02 -0400 (EDT) To: Benjamin Herrenschmidt Cc: Michael Schmitz , , , , Geert Uytterhoeven , Paul Mackerras , Michael Ellerman Message-Id: In-Reply-To: References: From: Finn Thain Subject: [PATCH v3 10/12] macintosh: Use common code to access RTC Date: Wed, 13 Jun 2018 06:38:02 -0400 (EDT) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that the 68k Mac port has adopted the via-pmu driver, it must access the PMU RTC using the appropriate command format. The same code can now be used for both m68k and powerpc. Replace the RTC code that's duplicated in arch/powerpc and arch/m68k with common RTC accessors for Cuda and PMU devices. Cc: Geert Uytterhoeven Cc: Paul Mackerras , Cc: Michael Ellerman Tested-by: Stan Johnson Signed-off-by: Finn Thain --- arch/m68k/mac/misc.c | 64 ++--------------------------- arch/powerpc/platforms/powermac/time.c | 74 +--------------------------------- drivers/macintosh/via-cuda.c | 34 ++++++++++++++++ drivers/macintosh/via-pmu.c | 32 +++++++++++++++ include/linux/cuda.h | 3 ++ include/linux/pmu.h | 3 ++ 6 files changed, 78 insertions(+), 132 deletions(-) diff --git a/arch/m68k/mac/misc.c b/arch/m68k/mac/misc.c index 28090a44fa09..397f9f942a9f 100644 --- a/arch/m68k/mac/misc.c +++ b/arch/m68k/mac/misc.c @@ -33,34 +33,6 @@ static void (*rom_reset)(void); #ifdef CONFIG_ADB_CUDA -static long cuda_read_time(void) -{ - struct adb_request req; - long time; - - if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_GET_TIME) < 0) - return 0; - while (!req.complete) - cuda_poll(); - - time = (req.reply[3] << 24) | (req.reply[4] << 16) | - (req.reply[5] << 8) | req.reply[6]; - return time - RTC_OFFSET; -} - -static void cuda_write_time(long data) -{ - struct adb_request req; - - data += RTC_OFFSET; - if (cuda_request(&req, NULL, 6, CUDA_PACKET, CUDA_SET_TIME, - (data >> 24) & 0xFF, (data >> 16) & 0xFF, - (data >> 8) & 0xFF, data & 0xFF) < 0) - return; - while (!req.complete) - cuda_poll(); -} - static __u8 cuda_read_pram(int offset) { struct adb_request req; @@ -86,34 +58,6 @@ static void cuda_write_pram(int offset, __u8 data) #endif /* CONFIG_ADB_CUDA */ #ifdef CONFIG_ADB_PMU -static long pmu_read_time(void) -{ - struct adb_request req; - long time; - - if (pmu_request(&req, NULL, 1, PMU_READ_RTC) < 0) - return 0; - while (!req.complete) - pmu_poll(); - - time = (req.reply[1] << 24) | (req.reply[2] << 16) | - (req.reply[3] << 8) | req.reply[4]; - return time - RTC_OFFSET; -} - -static void pmu_write_time(long data) -{ - struct adb_request req; - - data += RTC_OFFSET; - if (pmu_request(&req, NULL, 5, PMU_SET_RTC, - (data >> 24) & 0xFF, (data >> 16) & 0xFF, - (data >> 8) & 0xFF, data & 0xFF) < 0) - return; - while (!req.complete) - pmu_poll(); -} - static __u8 pmu_read_pram(int offset) { struct adb_request req; @@ -635,12 +579,12 @@ int mac_hwclk(int op, struct rtc_time *t) #ifdef CONFIG_ADB_CUDA case MAC_ADB_EGRET: case MAC_ADB_CUDA: - now = cuda_read_time(); + now = cuda_get_time(); break; #endif #ifdef CONFIG_ADB_PMU case MAC_ADB_PB2: - now = pmu_read_time(); + now = pmu_get_time(); break; #endif default: @@ -671,12 +615,12 @@ int mac_hwclk(int op, struct rtc_time *t) #ifdef CONFIG_ADB_CUDA case MAC_ADB_EGRET: case MAC_ADB_CUDA: - cuda_write_time(now); + cuda_set_time(now); break; #endif #ifdef CONFIG_ADB_PMU case MAC_ADB_PB2: - pmu_write_time(now); + pmu_set_time(now); break; #endif default: diff --git a/arch/powerpc/platforms/powermac/time.c b/arch/powerpc/platforms/powermac/time.c index 274af6fa388e..e9c1f3dafe2f 100644 --- a/arch/powerpc/platforms/powermac/time.c +++ b/arch/powerpc/platforms/powermac/time.c @@ -42,9 +42,6 @@ #define DBG(x...) #endif -/* Apparently the RTC stores seconds since 1 Jan 1904 */ -#define RTC_OFFSET 2082844800 - /* * Calibrate the decrementer frequency with the VIA timer 1. */ @@ -103,43 +100,8 @@ static unsigned long from_rtc_time(struct rtc_time *tm) #endif #ifdef CONFIG_ADB_CUDA -static unsigned long cuda_get_time(void) -{ - struct adb_request req; - unsigned int now; - - if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_GET_TIME) < 0) - return 0; - while (!req.complete) - cuda_poll(); - if (req.reply_len != 7) - printk(KERN_ERR "cuda_get_time: got %d byte reply\n", - req.reply_len); - now = (req.reply[3] << 24) + (req.reply[4] << 16) - + (req.reply[5] << 8) + req.reply[6]; - return ((unsigned long)now) - RTC_OFFSET; -} - #define cuda_get_rtc_time(tm) to_rtc_time(cuda_get_time(), (tm)) - -static int cuda_set_rtc_time(struct rtc_time *tm) -{ - unsigned int nowtime; - struct adb_request req; - - nowtime = from_rtc_time(tm) + RTC_OFFSET; - if (cuda_request(&req, NULL, 6, CUDA_PACKET, CUDA_SET_TIME, - nowtime >> 24, nowtime >> 16, nowtime >> 8, - nowtime) < 0) - return -ENXIO; - while (!req.complete) - cuda_poll(); - if ((req.reply_len != 3) && (req.reply_len != 7)) - printk(KERN_ERR "cuda_set_rtc_time: got %d byte reply\n", - req.reply_len); - return 0; -} - +#define cuda_set_rtc_time(tm) cuda_set_time(from_rtc_time(tm)) #else #define cuda_get_time() 0 #define cuda_get_rtc_time(tm) @@ -147,40 +109,8 @@ static int cuda_set_rtc_time(struct rtc_time *tm) #endif #ifdef CONFIG_ADB_PMU -static unsigned long pmu_get_time(void) -{ - struct adb_request req; - unsigned int now; - - if (pmu_request(&req, NULL, 1, PMU_READ_RTC) < 0) - return 0; - pmu_wait_complete(&req); - if (req.reply_len != 4) - printk(KERN_ERR "pmu_get_time: got %d byte reply from PMU\n", - req.reply_len); - now = (req.reply[0] << 24) + (req.reply[1] << 16) - + (req.reply[2] << 8) + req.reply[3]; - return ((unsigned long)now) - RTC_OFFSET; -} - #define pmu_get_rtc_time(tm) to_rtc_time(pmu_get_time(), (tm)) - -static int pmu_set_rtc_time(struct rtc_time *tm) -{ - unsigned int nowtime; - struct adb_request req; - - nowtime = from_rtc_time(tm) + RTC_OFFSET; - if (pmu_request(&req, NULL, 5, PMU_SET_RTC, nowtime >> 24, - nowtime >> 16, nowtime >> 8, nowtime) < 0) - return -ENXIO; - pmu_wait_complete(&req); - if (req.reply_len != 0) - printk(KERN_ERR "pmu_set_rtc_time: %d byte reply from PMU\n", - req.reply_len); - return 0; -} - +#define pmu_set_rtc_time(tm) pmu_set_time(from_rtc_time(tm)) #else #define pmu_get_time() 0 #define pmu_get_rtc_time(tm) diff --git a/drivers/macintosh/via-cuda.c b/drivers/macintosh/via-cuda.c index 019556136e77..8e7fb2115f10 100644 --- a/drivers/macintosh/via-cuda.c +++ b/drivers/macintosh/via-cuda.c @@ -771,3 +771,37 @@ cuda_input(unsigned char *buf, int nb) buf, nb, false); } } + +/* Offset between Unix time (1970-based) and Mac time (1904-based) */ +#define RTC_OFFSET 2082844800 + +unsigned long cuda_get_time(void) +{ + struct adb_request req; + unsigned long now; + + if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_GET_TIME) < 0) + return 0; + while (!req.complete) + cuda_poll(); + if (req.reply_len != 7) + pr_err("%s: got %d byte reply\n", __func__, req.reply_len); + now = (req.reply[3] << 24) + (req.reply[4] << 16) + + (req.reply[5] << 8) + req.reply[6]; + return now - RTC_OFFSET; +} + +int cuda_set_time(unsigned long now) +{ + struct adb_request req; + + now += RTC_OFFSET; + if (cuda_request(&req, NULL, 6, CUDA_PACKET, CUDA_SET_TIME, + now >> 24, now >> 16, now >> 8, now) < 0) + return -ENXIO; + while (!req.complete) + cuda_poll(); + if ((req.reply_len != 3) && (req.reply_len != 7)) + pr_err("%s: got %d byte reply\n", __func__, req.reply_len); + return 0; +} diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c index 22cb7d94e3ce..38d7dd0bdb28 100644 --- a/drivers/macintosh/via-pmu.c +++ b/drivers/macintosh/via-pmu.c @@ -1820,6 +1820,38 @@ pmu_shutdown(void) ; } +/* Offset between Unix time (1970-based) and Mac time (1904-based) */ +#define RTC_OFFSET 2082844800 + +unsigned long pmu_get_time(void) +{ + struct adb_request req; + unsigned long now; + + if (pmu_request(&req, NULL, 1, PMU_READ_RTC) < 0) + return 0; + pmu_wait_complete(&req); + if (req.reply_len != 4) + pr_err("%s: got %d byte reply\n", __func__, req.reply_len); + now = (req.reply[0] << 24) + (req.reply[1] << 16) + + (req.reply[2] << 8) + req.reply[3]; + return now - RTC_OFFSET; +} + +int pmu_set_time(unsigned long now) +{ + struct adb_request req; + + now += RTC_OFFSET; + if (pmu_request(&req, NULL, 5, PMU_SET_RTC, + now >> 24, now >> 16, now >> 8, now) < 0) + return -ENXIO; + pmu_wait_complete(&req); + if (req.reply_len != 0) + pr_err("%s: got %d byte reply\n", __func__, req.reply_len); + return 0; +} + int pmu_present(void) { diff --git a/include/linux/cuda.h b/include/linux/cuda.h index 056867f09a01..a68669f746e1 100644 --- a/include/linux/cuda.h +++ b/include/linux/cuda.h @@ -16,4 +16,7 @@ extern int cuda_request(struct adb_request *req, void (*done)(struct adb_request *), int nbytes, ...); extern void cuda_poll(void); +extern unsigned long cuda_get_time(void); +extern int cuda_set_time(unsigned long now); + #endif /* _LINUX_CUDA_H */ diff --git a/include/linux/pmu.h b/include/linux/pmu.h index 9ac8fc60ad49..feefd0bff9cf 100644 --- a/include/linux/pmu.h +++ b/include/linux/pmu.h @@ -34,6 +34,9 @@ static inline void pmu_resume(void) {} #endif +extern unsigned long pmu_get_time(void); +extern int pmu_set_time(unsigned long now); + extern void pmu_enable_irled(int on); extern void pmu_restart(void); -- 2.16.4