Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

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>

authored by

Finn Thain and committed by
Greg Kroah-Hartman
a71fa0e3 cda67df5

+41 -18
+41 -18
arch/m68k/mac/misc.c
··· 137 137 } 138 138 139 139 /* 140 + * These values can be found in Inside Macintosh vol. III ch. 2 141 + * which has a description of the RTC chip in the original Mac. 142 + */ 143 + 144 + #define RTC_FLG_READ BIT(7) 145 + #define RTC_FLG_WRITE_PROTECT BIT(7) 146 + #define RTC_CMD_READ(r) (RTC_FLG_READ | (r << 2)) 147 + #define RTC_CMD_WRITE(r) (r << 2) 148 + #define RTC_REG_SECONDS_0 0 149 + #define RTC_REG_SECONDS_1 1 150 + #define RTC_REG_SECONDS_2 2 151 + #define RTC_REG_SECONDS_3 3 152 + #define RTC_REG_WRITE_PROTECT 13 153 + 154 + /* 140 155 * Execute a VIA PRAM/RTC command. For read commands 141 156 * data should point to a one-byte buffer for the 142 157 * resulting data. For write commands it should point ··· 160 145 * This function disables all interrupts while running. 161 146 */ 162 147 163 - static void via_pram_command(int command, __u8 *data) 148 + static void via_rtc_command(int command, __u8 *data) 164 149 { 165 150 unsigned long flags; 166 151 int is_read; 167 152 168 153 local_irq_save(flags); 154 + 155 + /* The least significant bits must be 0b01 according to Inside Mac */ 156 + 157 + command = (command & ~3) | 1; 169 158 170 159 /* Enable the RTC and make sure the strobe line is high */ 171 160 ··· 178 159 if (command & 0xFF00) { /* extended (two-byte) command */ 179 160 via_rtc_send((command & 0xFF00) >> 8); 180 161 via_rtc_send(command & 0xFF); 181 - is_read = command & 0x8000; 162 + is_read = command & (RTC_FLG_READ << 8); 182 163 } else { /* one-byte command */ 183 164 via_rtc_send(command); 184 - is_read = command & 0x80; 165 + is_read = command & RTC_FLG_READ; 185 166 } 186 167 if (is_read) { 187 168 *data = via_rtc_recv(); ··· 220 201 } result, last_result; 221 202 int count = 1; 222 203 223 - via_pram_command(0x81, &last_result.cdata[3]); 224 - via_pram_command(0x85, &last_result.cdata[2]); 225 - via_pram_command(0x89, &last_result.cdata[1]); 226 - via_pram_command(0x8D, &last_result.cdata[0]); 204 + via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_0), &last_result.cdata[3]); 205 + via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_1), &last_result.cdata[2]); 206 + via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_2), &last_result.cdata[1]); 207 + via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_3), &last_result.cdata[0]); 227 208 228 209 /* 229 210 * The NetBSD guys say to loop until you get the same reading ··· 231 212 */ 232 213 233 214 while (1) { 234 - via_pram_command(0x81, &result.cdata[3]); 235 - via_pram_command(0x85, &result.cdata[2]); 236 - via_pram_command(0x89, &result.cdata[1]); 237 - via_pram_command(0x8D, &result.cdata[0]); 215 + via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_0), 216 + &result.cdata[3]); 217 + via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_1), 218 + &result.cdata[2]); 219 + via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_2), 220 + &result.cdata[1]); 221 + via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_3), 222 + &result.cdata[0]); 238 223 239 224 if (result.idata == last_result.idata) 240 225 return (time64_t)result.idata - RTC_OFFSET; ··· 277 254 /* Clear the write protect bit */ 278 255 279 256 temp = 0x55; 280 - via_pram_command(0x35, &temp); 257 + via_rtc_command(RTC_CMD_WRITE(RTC_REG_WRITE_PROTECT), &temp); 281 258 282 259 data.idata = lower_32_bits(time + RTC_OFFSET); 283 - via_pram_command(0x01, &data.cdata[3]); 284 - via_pram_command(0x05, &data.cdata[2]); 285 - via_pram_command(0x09, &data.cdata[1]); 286 - via_pram_command(0x0D, &data.cdata[0]); 260 + via_rtc_command(RTC_CMD_WRITE(RTC_REG_SECONDS_0), &data.cdata[3]); 261 + via_rtc_command(RTC_CMD_WRITE(RTC_REG_SECONDS_1), &data.cdata[2]); 262 + via_rtc_command(RTC_CMD_WRITE(RTC_REG_SECONDS_2), &data.cdata[1]); 263 + via_rtc_command(RTC_CMD_WRITE(RTC_REG_SECONDS_3), &data.cdata[0]); 287 264 288 265 /* Set the write protect bit */ 289 266 290 - temp = 0xD5; 291 - via_pram_command(0x35, &temp); 267 + temp = 0x55 | RTC_FLG_WRITE_PROTECT; 268 + via_rtc_command(RTC_CMD_WRITE(RTC_REG_WRITE_PROTECT), &temp); 292 269 } 293 270 294 271 static void via_shutdown(void)