Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5062698imu; Tue, 25 Dec 2018 16:53:57 -0800 (PST) X-Google-Smtp-Source: ALg8bN51ycgXPExWvtSWvpsEzLCo02C3tgvqT1X+fyvwZtctDJbvaBEi3ahcg5G3VszVEI8uRfeE X-Received: by 2002:a63:2507:: with SMTP id l7mr16441001pgl.22.1545785637880; Tue, 25 Dec 2018 16:53:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545785637; cv=none; d=google.com; s=arc-20160816; b=dTcXpTQ3X5SR7fN+7N0aDaMbAjctkzPoYavVN2MgHtGQ79D5Y9HI0NfNA2L3Zq4zzk NffCDIkVNO6HHHDjnqycS5wBplEAteD0lIoTy5CgQ450FArOt51J+vvVqx4VnbGvRI3S 23uEFN4pztmWkNFtSLUG5Dw3DOzmbNx/HbGKaMk7bBCOhxPlkSvm3Y4IQE7RABnjidIg JUZsg2ctBau+A7XCAyWXaFZHIWC0P0GTJ4h/64+JK1cNAFaUyitutohJQ8LCoOiPVevC r7SbJJXbrN9syTo9PJHH1VetLxPP4sBsdpa1h/0CljGljfM/PVl0wb3JoIvTgFGBB5yK /nKg== 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=KobH0Voy2Ct2PtDNEj9Z0stgQvYtOb0mMvcWAdu7OFU=; b=UOF378bolaS/pj7wo51KKqCYzCtNFvzITbrDb4M6GCNB1AylWOfVrke3eGnkKzKVmm LiT6B6QCV7onQAju9Re/NyU3IQ4OjCe5oEr7U7TNBygFTep953TKJaKsCPMxgW79y/oO sL0JhqqWqwJrmG4gbhb3gTLqpqShU39LSLo6ig3vJ6Dobw+tWD1Sg7tTrFK//Nb8G0P0 +hJ8WvW0OdpARAqjJKl7uKC+KJ8MKadte9tq0uVuIUMyVPMDTtU43NiYhRn8jv9kf0TE FHWm8XOgNGokjPw02G5Hh0P7ZvYv8BWp6zHQBdlMJFIPej3qjYHu+M/hXYq3V1LE4xyX AQTw== 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 m198si32072014pga.98.2018.12.25.16.53.43; Tue, 25 Dec 2018 16:53:57 -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 S1729761AbeLZApS (ORCPT + 99 others); Tue, 25 Dec 2018 19:45:18 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:57352 "EHLO kvm5.telegraphics.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726002AbeLZAoB (ORCPT ); Tue, 25 Dec 2018 19:44:01 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id 343D829521; Tue, 25 Dec 2018 19:43:56 -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: <1db6094a7b876537d747621b30db8743c9d4c2da.1545784679.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH v8 11/25] m68k/mac: Use macros for RTC accesses not magic numbers Date: Wed, 26 Dec 2018 11:37:59 +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. Signed-off-by: Finn Thain Acked-by: Geert Uytterhoeven Tested-by: Stan Johnson --- 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 9f6849deecea..475c93e4048c 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