Commit a71fa0e3 authored by Finn Thain's avatar Finn Thain Committed by Greg Kroah-Hartman

m68k/mac: Use macros for RTC accesses not magic numbers

This is intended to improve code style and not affect code behaviour.
Acked-by: default avatarGeert Uytterhoeven <geert@linux-m68k.org>
Tested-by: default avatarStan Johnson <userm57@yahoo.com>
Signed-off-by: default avatarFinn Thain <fthain@telegraphics.com.au>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent cda67df5
...@@ -136,6 +136,21 @@ static void via_rtc_send(__u8 data) ...@@ -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 * Execute a VIA PRAM/RTC command. For read commands
* data should point to a one-byte buffer for the * data should point to a one-byte buffer for the
...@@ -145,13 +160,17 @@ static void via_rtc_send(__u8 data) ...@@ -145,13 +160,17 @@ static void via_rtc_send(__u8 data)
* This function disables all interrupts while running. * 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; unsigned long flags;
int is_read; int is_read;
local_irq_save(flags); 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 */ /* Enable the RTC and make sure the strobe line is high */
via1[vBufB] = (via1[vBufB] | VIA1B_vRTCClk) & ~VIA1B_vRTCEnb; via1[vBufB] = (via1[vBufB] | VIA1B_vRTCClk) & ~VIA1B_vRTCEnb;
...@@ -159,10 +178,10 @@ static void via_pram_command(int command, __u8 *data) ...@@ -159,10 +178,10 @@ static void via_pram_command(int command, __u8 *data)
if (command & 0xFF00) { /* extended (two-byte) command */ if (command & 0xFF00) { /* extended (two-byte) command */
via_rtc_send((command & 0xFF00) >> 8); via_rtc_send((command & 0xFF00) >> 8);
via_rtc_send(command & 0xFF); via_rtc_send(command & 0xFF);
is_read = command & 0x8000; is_read = command & (RTC_FLG_READ << 8);
} else { /* one-byte command */ } else { /* one-byte command */
via_rtc_send(command); via_rtc_send(command);
is_read = command & 0x80; is_read = command & RTC_FLG_READ;
} }
if (is_read) { if (is_read) {
*data = via_rtc_recv(); *data = via_rtc_recv();
...@@ -201,10 +220,10 @@ static time64_t via_read_time(void) ...@@ -201,10 +220,10 @@ static time64_t via_read_time(void)
} result, last_result; } result, last_result;
int count = 1; int count = 1;
via_pram_command(0x81, &last_result.cdata[3]); via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_0), &last_result.cdata[3]);
via_pram_command(0x85, &last_result.cdata[2]); via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_1), &last_result.cdata[2]);
via_pram_command(0x89, &last_result.cdata[1]); via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_2), &last_result.cdata[1]);
via_pram_command(0x8D, &last_result.cdata[0]); 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 * The NetBSD guys say to loop until you get the same reading
...@@ -212,10 +231,14 @@ static time64_t via_read_time(void) ...@@ -212,10 +231,14 @@ static time64_t via_read_time(void)
*/ */
while (1) { while (1) {
via_pram_command(0x81, &result.cdata[3]); via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_0),
via_pram_command(0x85, &result.cdata[2]); &result.cdata[3]);
via_pram_command(0x89, &result.cdata[1]); via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_1),
via_pram_command(0x8D, &result.cdata[0]); &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) if (result.idata == last_result.idata)
return (time64_t)result.idata - RTC_OFFSET; return (time64_t)result.idata - RTC_OFFSET;
...@@ -254,18 +277,18 @@ static void via_set_rtc_time(struct rtc_time *tm) ...@@ -254,18 +277,18 @@ static void via_set_rtc_time(struct rtc_time *tm)
/* Clear the write protect bit */ /* Clear the write protect bit */
temp = 0x55; 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); data.idata = lower_32_bits(time + RTC_OFFSET);
via_pram_command(0x01, &data.cdata[3]); via_rtc_command(RTC_CMD_WRITE(RTC_REG_SECONDS_0), &data.cdata[3]);
via_pram_command(0x05, &data.cdata[2]); via_rtc_command(RTC_CMD_WRITE(RTC_REG_SECONDS_1), &data.cdata[2]);
via_pram_command(0x09, &data.cdata[1]); via_rtc_command(RTC_CMD_WRITE(RTC_REG_SECONDS_2), &data.cdata[1]);
via_pram_command(0x0D, &data.cdata[0]); via_rtc_command(RTC_CMD_WRITE(RTC_REG_SECONDS_3), &data.cdata[0]);
/* Set the write protect bit */ /* Set the write protect bit */
temp = 0xD5; temp = 0x55 | RTC_FLG_WRITE_PROTECT;
via_pram_command(0x35, &temp); via_rtc_command(RTC_CMD_WRITE(RTC_REG_WRITE_PROTECT), &temp);
} }
static void via_shutdown(void) static void via_shutdown(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment