m68k/mac: Use macros for RTC accesses not magic numbers
authorFinn Thain <fthain@telegraphics.com.au>
Tue, 15 Jan 2019 04:18:56 +0000 (15:18 +1100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 22 Jan 2019 09:21:45 +0000 (10:21 +0100)
This is intended to improve code style and not affect code behaviour.

Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
Tested-by: Stan Johnson <userm57@yahoo.com>
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/m68k/mac/misc.c

index 78c80702543639026a0a0f14d3f9d56b7eb1e68c..af000a015f68e8f7a0d31ac1325d1cf24d99474d 100644 (file)
@@ -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)