Move the m68k-specific code elsewhere to make the driver generic.
Change the vmode calculation from logical OR to bitwise OR, since it is
obviously wrong.
Signed-off-by: Finn Thain fth...@telegraphics.com.au
---
BTW, I didn't change the SCSI ID location in NVRAM. This code says 16
whereas atari_scsi says 14. Which one is correct?
---
arch/m68k/atari/Makefile |2
arch/m68k/atari/nvram.c | 255 ++
drivers/char/nvram.c | 280 +--
3 files changed, 292 insertions(+), 245 deletions(-)
Index: linux/arch/m68k/atari/nvram.c
===
--- /dev/null 1970-01-01 00:00:00.0 +
+++ linux/arch/m68k/atari/nvram.c 2015-06-28 11:41:29.0 +1000
@@ -0,0 +1,255 @@
+/*
+ * CMOS/NV-RAM driver for Atari. Adapted from drivers/char/nvram.c.
+ * Copyright (C) 1997 Roman Hodek roman.ho...@informatik.uni-erlangen.de
+ * idea by and with help from Richard Jelinek r...@suse.de
+ * Portions copyright (c) 2001,2002 Sun Microsystems (thoc...@sun.com)
+ * Further contributions from Cesar Barros, Erik Gilling, Tim Hockin and
+ * Wim Van Sebroeck.
+ */
+
+#include linux/errno.h
+#include linux/init.h
+#include linux/mc146818rtc.h
+#include linux/module.h
+#include linux/nvram.h
+#include linux/proc_fs.h
+#include linux/seq_file.h
+#include linux/spinlock.h
+#include linux/types.h
+#include asm/atarihw.h
+#include asm/atariints.h
+
+#define NVRAM_BYTES50
+
+/* It is worth noting that these functions all access bytes of general
+ * purpose memory in the NVRAM - that is to say, they all add the
+ * NVRAM_FIRST_BYTE offset. Pass them offsets into NVRAM as if you did not
+ * know about the RTC cruft.
+ */
+
+/* Note that *all* calls to CMOS_READ and CMOS_WRITE must be done with
+ * rtc_lock held. Due to the index-port/data-port design of the RTC, we
+ * don't want two different things trying to get to it at once. (e.g. the
+ * periodic 11 min sync from kernel/time/ntp.c vs. this driver.)
+ */
+
+unsigned char __nvram_read_byte(int i)
+{
+ return CMOS_READ(NVRAM_FIRST_BYTE + i);
+}
+
+unsigned char nvram_read_byte(int i)
+{
+ unsigned long flags;
+ unsigned char c;
+
+ spin_lock_irqsave(rtc_lock, flags);
+ c = __nvram_read_byte(i);
+ spin_unlock_irqrestore(rtc_lock, flags);
+ return c;
+}
+EXPORT_SYMBOL(nvram_read_byte);
+
+/* This races nicely with trying to read with checksum checking */
+void __nvram_write_byte(unsigned char c, int i)
+{
+ CMOS_WRITE(c, NVRAM_FIRST_BYTE + i);
+}
+
+void nvram_write_byte(unsigned char c, int i)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(rtc_lock, flags);
+ __nvram_write_byte(c, i);
+ spin_unlock_irqrestore(rtc_lock, flags);
+}
+
+/* On Ataris, the checksum is over all bytes except the checksum bytes
+ * themselves; these are at the very end.
+ */
+#define ATARI_CKS_RANGE_START 0
+#define ATARI_CKS_RANGE_END47
+#define ATARI_CKS_LOC 48
+
+int __nvram_check_checksum(void)
+{
+ int i;
+ unsigned char sum = 0;
+
+ for (i = ATARI_CKS_RANGE_START; i = ATARI_CKS_RANGE_END; ++i)
+ sum += __nvram_read_byte(i);
+ return (__nvram_read_byte(ATARI_CKS_LOC) == (~sum 0xff))
+ (__nvram_read_byte(ATARI_CKS_LOC + 1) == (sum 0xff));
+}
+
+int nvram_check_checksum(void)
+{
+ unsigned long flags;
+ int rv;
+
+ spin_lock_irqsave(rtc_lock, flags);
+ rv = __nvram_check_checksum();
+ spin_unlock_irqrestore(rtc_lock, flags);
+ return rv;
+}
+EXPORT_SYMBOL(nvram_check_checksum);
+
+static void __nvram_set_checksum(void)
+{
+ int i;
+ unsigned char sum = 0;
+
+ for (i = ATARI_CKS_RANGE_START; i = ATARI_CKS_RANGE_END; ++i)
+ sum += __nvram_read_byte(i);
+ __nvram_write_byte(~sum, ATARI_CKS_LOC);
+ __nvram_write_byte(sum, ATARI_CKS_LOC + 1);
+}
+
+#ifdef CONFIG_PROC_FS
+static struct {
+ unsigned char val;
+ char *name;
+} boot_prefs[] = {
+ { 0x80, TOS },
+ { 0x40, ASV },
+ { 0x20, NetBSD (?) },
+ { 0x10, Linux },
+ { 0x00, unspecified },
+};
+
+static char *languages[] = {
+ English (US),
+ German,
+ French,
+ English (UK),
+ Spanish,
+ Italian,
+ 6 (undefined),
+ Swiss (French),
+ Swiss (German),
+};
+
+static char *dateformat[] = {
+ MM%cDD%cYY,
+ DD%cMM%cYY,
+ YY%cMM%cDD,
+ YY%cDD%cMM,
+ 4 (undefined),
+ 5 (undefined),
+ 6 (undefined),
+ 7 (undefined),
+};
+
+static char *colors[] = {
+ 2, 4, 16, 256, 65536, ??, ??, ??
+};
+
+static void atari_nvram_proc_read(unsigned char *nvram, struct seq_file *seq,
+ void *offset)
+{
+ int checksum;
+ int i;
+ unsigned vmode;
+
+ spin_lock_irq(rtc_lock);
+ checksum =