Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4320677imu; Mon, 14 Jan 2019 20:26:44 -0800 (PST) X-Google-Smtp-Source: ALg8bN5c6XQYx1os9pjvUn7ZDkpQahJo/vhX7Rp665QQn0d040eLqlRLU1/0KFanAQbdPQFXBDEC X-Received: by 2002:a63:cd4c:: with SMTP id a12mr2058260pgj.252.1547526404896; Mon, 14 Jan 2019 20:26:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547526404; cv=none; d=google.com; s=arc-20160816; b=0PJ4ZLvEzFkbt6sNLOWVsMc5aqe0MngwAdmo0822AHAtaokJ9C2qCyXs5Vm3jWTmcF dtY9r9t5mcxA7IVvcq5+q7HJhmZrpnwVdRaJ952Ju+tgTOpqe7Nlv/T65RLYBgo/Pu0h AwoJSLaQP0+T3ayGNEMOuhOWjcR+fboE0y2j6AqP9BJntyeXjDZt0dYttMypdkYXJSn/ PnCIK5M4NuQF3SOOCV8VwQ+cjq2Etf/CNFZcNWenrxbH6Km1Lv5heIWkKyYb5AT137Dj za65FugCPj2ZVx2gxfzLxcut3MT7sbvc7dgI2it3cLUAfJmqurus6PwUmjWS9CROBUgQ Rhqw== 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; bh=Sn9INRAG3HxA8i/sWn2moNlfT7ICMi/MnMLgOvN0pYY=; b=Wpy/20CiGgHk5WBsnZvm/r++KRu5Fq3vz48E264sof4hA7mUyYEzRpEK7iL6y3x2iu so1jPDYIVrXSDApUapOzQ1LIXP2CWNc8C9YgTALQpkO36wimsZd7olLychG8oqhbMLEL fjmdPZ4fLi1zmMinHAyJznu+4/Uk8a2bTJGxcIc/kYtZ9ullo9zGxU8OtWNqCPOzhBqh vgofGuinlLHueRs+7sN44U4L7FO2eF5xWISOIYFKgnLp7W/C6IHGGJAKplqeEuWLXP/F HcClP3MQ+gAzn0LST2Y6aVJCR55llN5Z/i4ZlxqB0sDCD+TwAzfYNycRcer7DsnOR5Zq 5I8g== 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 m39si2210814plg.315.2019.01.14.20.26.29; Mon, 14 Jan 2019 20:26:44 -0800 (PST) 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 S1728270AbfAOEWb (ORCPT + 99 others); Mon, 14 Jan 2019 23:22:31 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:37550 "EHLO kvm5.telegraphics.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728216AbfAOEW3 (ORCPT ); Mon, 14 Jan 2019 23:22:29 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 6921A29E6F; Mon, 14 Jan 2019 23:22:24 -0500 (EST) To: Arnd Bergmann , Greg Kroah-Hartman , Joshua Thompson , Geert Uytterhoeven Cc: linux-kernel@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linuxppc-dev@lists.ozlabs.org Message-Id: <95b208ccdb3276ad6a0a2aacc5de828550a8a024.1547525936.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH v9 12/22] m68k/mac: Use macros for RTC accesses not magic numbers Date: Tue, 15 Jan 2019 15:18:56 +1100 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is intended to improve code style and not affect code behaviour. Acked-by: Geert Uytterhoeven Tested-by: Stan Johnson Signed-off-by: Finn Thain --- arch/m68k/mac/misc.c | 59 ++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/arch/m68k/mac/misc.c b/arch/m68k/mac/misc.c index 78c807025436..af000a015f68 100644 --- a/arch/m68k/mac/misc.c +++ b/arch/m68k/mac/misc.c @@ -136,6 +136,21 @@ static void via_rtc_send(__u8 data) } } +/* + * These values can be found in Inside Macintosh vol. III ch. 2 + * which has a description of the RTC chip in the original Mac. + */ + +#define RTC_FLG_READ BIT(7) +#define RTC_FLG_WRITE_PROTECT BIT(7) +#define RTC_CMD_READ(r) (RTC_FLG_READ | (r << 2)) +#define RTC_CMD_WRITE(r) (r << 2) +#define RTC_REG_SECONDS_0 0 +#define RTC_REG_SECONDS_1 1 +#define RTC_REG_SECONDS_2 2 +#define RTC_REG_SECONDS_3 3 +#define RTC_REG_WRITE_PROTECT 13 + /* * Execute a VIA PRAM/RTC command. For read commands * data should point to a one-byte buffer for the @@ -145,13 +160,17 @@ static void via_rtc_send(__u8 data) * This function disables all interrupts while running. */ -static void via_pram_command(int command, __u8 *data) +static void via_rtc_command(int command, __u8 *data) { unsigned long flags; int is_read; local_irq_save(flags); + /* The least significant bits must be 0b01 according to Inside Mac */ + + command = (command & ~3) | 1; + /* Enable the RTC and make sure the strobe line is high */ via1[vBufB] = (via1[vBufB] | VIA1B_vRTCClk) & ~VIA1B_vRTCEnb; @@ -159,10 +178,10 @@ static void via_pram_command(int command, __u8 *data) if (command & 0xFF00) { /* extended (two-byte) command */ via_rtc_send((command & 0xFF00) >> 8); via_rtc_send(command & 0xFF); - is_read = command & 0x8000; + is_read = command & (RTC_FLG_READ << 8); } else { /* one-byte command */ via_rtc_send(command); - is_read = command & 0x80; + is_read = command & RTC_FLG_READ; } if (is_read) { *data = via_rtc_recv(); @@ -201,10 +220,10 @@ static time64_t via_read_time(void) } result, last_result; int count = 1; - via_pram_command(0x81, &last_result.cdata[3]); - via_pram_command(0x85, &last_result.cdata[2]); - via_pram_command(0x89, &last_result.cdata[1]); - via_pram_command(0x8D, &last_result.cdata[0]); + via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_0), &last_result.cdata[3]); + via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_1), &last_result.cdata[2]); + via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_2), &last_result.cdata[1]); + via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_3), &last_result.cdata[0]); /* * The NetBSD guys say to loop until you get the same reading @@ -212,10 +231,14 @@ static time64_t via_read_time(void) */ while (1) { - via_pram_command(0x81, &result.cdata[3]); - via_pram_command(0x85, &result.cdata[2]); - via_pram_command(0x89, &result.cdata[1]); - via_pram_command(0x8D, &result.cdata[0]); + via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_0), + &result.cdata[3]); + via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_1), + &result.cdata[2]); + via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_2), + &result.cdata[1]); + via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_3), + &result.cdata[0]); if (result.idata == last_result.idata) return (time64_t)result.idata - RTC_OFFSET; @@ -254,18 +277,18 @@ static void via_set_rtc_time(struct rtc_time *tm) /* Clear the write protect bit */ temp = 0x55; - via_pram_command(0x35, &temp); + via_rtc_command(RTC_CMD_WRITE(RTC_REG_WRITE_PROTECT), &temp); data.idata = lower_32_bits(time + RTC_OFFSET); - via_pram_command(0x01, &data.cdata[3]); - via_pram_command(0x05, &data.cdata[2]); - via_pram_command(0x09, &data.cdata[1]); - via_pram_command(0x0D, &data.cdata[0]); + via_rtc_command(RTC_CMD_WRITE(RTC_REG_SECONDS_0), &data.cdata[3]); + via_rtc_command(RTC_CMD_WRITE(RTC_REG_SECONDS_1), &data.cdata[2]); + via_rtc_command(RTC_CMD_WRITE(RTC_REG_SECONDS_2), &data.cdata[1]); + via_rtc_command(RTC_CMD_WRITE(RTC_REG_SECONDS_3), &data.cdata[0]); /* Set the write protect bit */ - temp = 0xD5; - via_pram_command(0x35, &temp); + temp = 0x55 | RTC_FLG_WRITE_PROTECT; + via_rtc_command(RTC_CMD_WRITE(RTC_REG_WRITE_PROTECT), &temp); } static void via_shutdown(void) -- 2.19.2