From: Roman.Hodek@informatik.uni-erlangen.de (Roman Hodek)
Date: Tue, 16 Dec 1997 00:19:10 +0100 (CET)
To: linux-m68k@lists.linux-m68k.org
Subject: L68K: Heartbeat for Atari
Sender: owner-linux-m68k@phil.uni-sb.de


Below is an adaption of Geert's hearbeart patch for the Atari. It uses
the floppy LED of drive A: (as discussed here recently on the list).
The floppy driver has a flag 'atari_dont_touch_floppy_select' to block
the timer int from fiddling with its select lines, i.e., during any
floppy operations (fd0 or fd1) the heatbeat is off.

BTW, hasn't anybody noticed that no floppies were detected anymore
after my MACH_IS_FALCON patch?? :-) Seems that floppy is a really
useless device under Unix :-)) There was a pair of parens missing...

Roman

------------------------------------------------------------------------------
diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.64.orig/arch/m68k/atari/atari_ksyms.c linux-2.1.64/arch/m68k/atari/atari_ksyms.c
--- linux-2.1.64.orig/arch/m68k/atari/atari_ksyms.c	Wed Dec  3 16:28:17 1997
+++ linux-2.1.64/arch/m68k/atari/atari_ksyms.c	Mon Dec 15 23:12:36 1997
@@ -18,6 +18,7 @@
 EXPORT_SYMBOL(atari_mch_type);
 EXPORT_SYMBOL(atari_hw_present);
 EXPORT_SYMBOL(atari_switches);
+EXPORT_SYMBOL(atari_dont_touch_floppy_select);
 EXPORT_SYMBOL(atari_register_vme_int);
 EXPORT_SYMBOL(atari_unregister_vme_int);
 EXPORT_SYMBOL(stdma_lock);
diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.64.orig/arch/m68k/atari/config.c linux-2.1.64/arch/m68k/atari/config.c
--- linux-2.1.64.orig/arch/m68k/atari/config.c	Fri Nov 28 14:28:25 1997
+++ linux-2.1.64/arch/m68k/atari/config.c	Mon Dec 15 23:12:17 1997
@@ -55,6 +55,7 @@
 u_long atari_mch_type = 0;
 struct atari_hw_present atari_hw_present;
 u_long atari_switches = 0;
+int atari_dont_touch_floppy_select = 0;
 int atari_rtc_year_offset;
 
 extern char m68k_debug_device[];
diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.64.orig/arch/m68k/config.in linux-2.1.64/arch/m68k/config.in
--- linux-2.1.64.orig/arch/m68k/config.in	Mon Dec 15 23:05:20 1997
+++ linux-2.1.64/arch/m68k/config.in	Mon Dec 15 23:17:53 1997
@@ -62,11 +62,13 @@
 #    bool 'DMI Resolver support' CONFIG_GSP_RESOLVER
 #    bool 'A2410 support' CONFIG_GSP_A2410
 #  fi
-  bool 'Use power LED as a heartbeat' CONFIG_HEARTBEAT
 fi
 if [ "$CONFIG_ATARI" = "y" ]; then
   bool 'Support for ST-RAM as swap space' CONFIG_STRAM_SWAP
   bool 'ST-RAM statistics in /proc' CONFIG_STRAM_PROC
+fi
+if [ "$CONFIG_AMIGA" = "y" -o "$CONFIG_ATARI" = "y" ]; then
+  bool 'Use power LED as a heartbeat' CONFIG_HEARTBEAT
 fi
 endmenu
 
diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.64.orig/arch/m68k/kernel/time.c linux-2.1.64/arch/m68k/kernel/time.c
--- linux-2.1.64.orig/arch/m68k/kernel/time.c	Mon Dec 15 23:05:20 1997
+++ linux-2.1.64/arch/m68k/kernel/time.c	Mon Dec 15 23:42:21 1997
@@ -21,8 +21,14 @@
 #ifdef CONFIG_HEARTBEAT
 #include <linux/kernel_stat.h>
 #include <asm/setup.h>
+#ifdef CONFIG_AMIGA
 #include <asm/amigahw.h>
 #include <asm/amigaints.h>
+#endif
+#ifdef CONFIG_ATARI
+#include <asm/atarihw.h>
+#include <asm/atariints.h>
+#endif
 #endif /* CONFIG_HEARTBEAT */
 
 #include <linux/timex.h>
@@ -81,11 +87,12 @@
 	    last_rtc_update = xtime.tv_sec - 600; /* do it again in 60 s */
 	}
 #ifdef CONFIG_HEARTBEAT
+	/* use power LED as a heartbeat instead -- much more useful
+	   for debugging -- based on the version for PReP by Cort */
+	/* acts like an actual heart beat -- ie thump-thump-pause... */
+#ifdef CONFIG_AMIGA
 	if (MACH_IS_AMIGA) {
-	    /* use power LED as a heartbeat instead -- much more useful
-	       for debugging -- based on the version for PReP by Cort */
 	    switch(kstat.interrupts[SYS_IRQS + IRQ_AMIGA_CIAB_TA] % 101) {
-		/* act like an actual heart beat -- ie thump-thump-pause... */
 		case 0:
 		case 20:
 		    ciaa.pra &= ~2;
@@ -96,6 +103,27 @@
 		    break;
 	    }
         }
+#endif
+#ifdef CONFIG_ATARI
+	if (MACH_IS_ATARI && !atari_dont_touch_floppy_select) {
+	    unsigned long flags, tmp;
+	    save_flags(flags);
+	    cli();
+	    sound_ym.rd_data_reg_sel = 14; /* Select PSG Port A */
+	    tmp = sound_ym.rd_data_reg_sel;
+	    switch(kstat.interrupts[IRQ_MFP_TIMC] % 101) {
+	      case 0:
+	      case 20:
+		sound_ym.wd_data = tmp & ~0x02;
+		break;
+	      case 7:
+	      case 27:
+		sound_ym.wd_data = tmp | 0x02;
+		break;
+	    }
+	    restore_flags(flags);
+        }
+#endif
 #endif /* CONFIG_HEARTBEAT */
 }
 
diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.64.orig/drivers/block/ataflop.c linux-2.1.64/drivers/block/ataflop.c
--- linux-2.1.64.orig/drivers/block/ataflop.c	Sat Nov 22 00:01:33 1997
+++ linux-2.1.64/drivers/block/ataflop.c	Tue Dec 16 00:15:22 1997
@@ -460,6 +460,7 @@
 	sound_ym.rd_data_reg_sel = 14; /* Select PSG Port A */
 	tmp = sound_ym.rd_data_reg_sel;
 	sound_ym.wd_data = (tmp | DSKDRVNONE) & ~(drive == 0 ? DSKDRV0 : DSKDRV1);
+	atari_dont_touch_floppy_select = 1;
 	restore_flags(flags);
 
 	/* restore track register to saved value */
@@ -483,6 +484,7 @@
 
 	save_flags(flags);
 	cli(); /* protect against various other ints mucking around with the PSG */
+	atari_dont_touch_floppy_select = 0;
 	sound_ym.rd_data_reg_sel=14;	/* Select PSG Port A */
 	sound_ym.wd_data = sound_ym.rd_data_reg_sel |
 					   MACH_IS_FALCON ? 3 : 7; /* no drives selected */
@@ -1832,7 +1834,7 @@
 	int ok;
 
 	/* Falcon supports only one Floppy */
-	if (drive >= MACH_IS_FALCON ? 1 : 2) return( 0 );
+	if (drive >= (MACH_IS_FALCON ? 1 : 2)) return( 0 );
 	fd_select_drive( drive );
 
 	/* disable interrupt temporarily */
diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.64.orig/include/asm-m68k/atarihw.h linux-2.1.64/include/asm-m68k/atarihw.h
--- linux-2.1.64.orig/include/asm-m68k/atarihw.h	Tue Dec  2 16:03:10 1997
+++ linux-2.1.64/include/asm-m68k/atarihw.h	Mon Dec 15 23:19:06 1997
@@ -27,6 +27,7 @@
 extern u_long atari_mch_type;
 extern u_long atari_switches;
 extern int atari_rtc_year_offset;
+extern int atari_dont_touch_floppy_select;
 
 /* convenience macros for testing machine type */
 #define MACH_IS_ST	((atari_mch_cookie >> 16) == ATARI_MCH_ST)
