Date: Mon, 17 Nov 1997 14:06:19 GMT
From: Roman Hodek <rnhodek@faui22c.informatik.uni-erlangen.de>
To: linux-m68k@lists.linux-m68k.org
Subject: L68K: fix for serial console problems
Sender: owner-linux-m68k@phil.uni-sb.de


I now thought again about the initialization problems in the serial
console, and finally found a solution :-) If the device initialization
and setup of the 'write' and 'wait_key' field is moved into
serial_console_setup(), everything works as expected. Just 'setup' is
kind of a misnomer then, 'init' would be better...

BTW, the same initialization problem applies to PC code, too, a mail
to Miquel is on the way :-)

The patch below fixes things and also removes a leftover debugging
code (that didn't any harm).

Jes: Just ignore it :-) Geert: You can integrate it into general m68k
sercons stuff.

Roman

------------------------------------------------------------------------------
diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.64.orig/drivers/char/m68kserial.c linux-2.1.64/drivers/char/m68kserial.c
--- linux-2.1.64.orig/drivers/char/m68kserial.c	Mon Nov 17 12:47:38 1997
+++ linux-2.1.64/drivers/char/m68kserial.c	Mon Nov 17 14:54:45 1997
@@ -140,7 +140,6 @@
 static struct termios *serial_termios_locked[NR_PORTS];
 #ifdef CONFIG_SERIAL_CONSOLE
 static struct console sercons;
-static int serial_console_cflag;
 #endif
 
 #ifndef MIN
@@ -1718,18 +1717,42 @@
 			break;
 	}
 
-	serial_console_cflag = cflag;
+	/* Initialization of the port and filling in the missing fields of the
+	 * sercons struct must happen here, since register_console() already uses
+	 * write to print the log buffer. */
+	
+	/* Currently this supports the Amiga builtin port only */
+	if (MACH_IS_AMIGA && sercons.index == 0) {
+		sercons.write = amiga_serial_console_write;
+		sercons.wait_key = amiga_serial_console_wait_key;
+		/* no initialization yet */
+		/* amiga_init_serial_console(rs_table+sercons.index, */
+		/*			     serial_console_cflag); */
+	}
+	/* On Atari, Modem1 (ttyS0) and Modem2 (ttyS1) are supported
+	 * Note: On a TT, 57.6 and 115.2 kbps are not possible and are replaced by
+	 * 76.8 and 153.6 kbps. */
+	else if (MACH_IS_ATARI && sercons.index == 0) {
+		sercons.write = atari_mfp_console_write;
+		sercons.wait_key = atari_mfp_console_wait_key;
+		atari_init_mfp_port( cflag );
+	}
+	else if (MACH_IS_ATARI && sercons.index == 1) {
+		sercons.write = atari_scc_console_write;
+		sercons.wait_key = atari_scc_console_wait_key;
+		atari_init_scc_port( cflag );
+	}
 }
 
 static struct console sercons = {
 	"ttyS",
-	NULL,			/* filled in by serial_console_init */
+	NULL,			/* filled in by serial_console_setup */
 	NULL,
 	serial_console_device,
-	NULL,			/* filled in by serial_console_init */
+	NULL,			/* filled in by serial_console_setup */
 	NULL,
 	serial_console_setup,
-	0 /*CON_PRINTBUFFER*/,
+	CON_PRINTBUFFER,
 	0,
 	NULL
 };
@@ -1750,37 +1773,7 @@
  */
 long serial_console_init(long kmem_start, long kmem_end)
 {
-	/*
-	 * This sets sercons.index and serial_console_cflag
-	 * Unfortunately, register_console() also calls sercons.write for printing
-	 * the buffer. But we can't set up the write method before we know the
-	 * index... sounds like chicken and egg, doesn't it? :-) Bad design...
-	 */
 	register_console(&sercons);
-	
-	/* Currently this supports the Amiga builtin port only */
-	if (MACH_IS_AMIGA && sercons.index == 0) {
-		sercons.write = amiga_serial_console_write;
-		sercons.wait_key = amiga_serial_console_wait_key;
-		/* no initialization yet */
-		/* amiga_init_serial_console(rs_table+sercons.index, */
-		/*			     serial_console_cflag); */
-	}
-	/* On Atari, Modem1 (ttyS0) and Modem2 (ttyS1) are supported
-	 * Note: On a TT, 57.6 and 115.2 kbps are not possible and are replaced by
-	 * 76.8 and 153.6 kbps. */
-	else if (MACH_IS_ATARI && sercons.index == 0) {
-		sercons.write = atari_mfp_console_write;
-		sercons.wait_key = atari_mfp_console_wait_key;
-		atari_init_mfp_port( serial_console_cflag );
-	}
-	else if (MACH_IS_ATARI && sercons.index == 1) {
-		sercons.write = atari_scc_console_write;
-		sercons.wait_key = atari_scc_console_wait_key;
-		sercons.flags &= ~CON_ENABLED;
-		atari_init_scc_port( serial_console_cflag );
-		sercons.flags |= CON_ENABLED;
-	}
 	return kmem_start;
 }
 #endif
