Subject: [PATCH] Make serial console more friendly

From: Klaus Naumann <[email-masked]>
Date: Sat, 16 Jun 2001 17:21:18 +0200 (CEST)

Hi all,

after a long time of being busy and absent from Linux/MIPS
I got around hacking a bit again.
Attached is what came out of this. The patch will make it possible
to use any (supported!) speed for the serial console.
How to use: Apply against any recent 2.4 cvs kernel, compile. 
In the PROM command monitor type "setenv dbaud 38400" (now you probably
need to change the serial setup of your client, i.e. minicom) and boot the
kernel.
If you're getting strange chars at the login prompt you need
to change your getty config.

Ralf: Can you please check and apply the patch ? Thanks !
(There are also some small code beautifications in the patch)

		Enjoy !, Klaus

-- 
Full Name   : Klaus Naumann     | (http://www.mgnet.de/) (Germany)
Nickname    : Spock             | Org.: Mad Guys Network
Phone / FAX : ++49/177/7862964  | E-Mail: ([email-masked])
PGP Key     : www.mgnet.de/keys/key_spock.txt
diff -Nur linux.orig/drivers/sgi/char/sgiserial.c linux/drivers/sgi/char/sgiserial.c
--- linux.orig/drivers/sgi/char/sgiserial.c	Thu Jun 14 20:28:46 2001
+++ linux/drivers/sgi/char/sgiserial.c	Sat Jun 16 17:04:02 2001
@@ -13,6 +13,13 @@
  * thorough pass to merge in the rest of the updates.
  * Better still, someone really ought to make it a common
  * code module for both platforms.   [email-masked]
+ *
+ *
+ *
+ * 20010616 - Klaus Naumann <[email-masked]> : Make serial console work with
+ *                                             any speed - not only 9600
+ *
+ *
  */
 
 #include <linux/config.h> /* for CONFIG_REMOTE_DEBUG */
@@ -97,6 +104,7 @@
 DECLARE_TASK_QUEUE(tq_serial);
 
 struct tty_driver serial_driver, callout_driver;
+struct console *sgisercon;
 static int serial_refcount;
 
 /* serial subtype definitions */
@@ -684,7 +692,7 @@
 	save_flags(flags); cli();
 
 #ifdef SERIAL_DEBUG_OPEN
-	printk("starting up ttys%d (irq %d)...", info->line, info->irq);
+	printk("starting up ttys%d (irq %d)...\n", info->line, info->irq);
 #endif
 
 	/*
@@ -1772,11 +1780,19 @@
 		change_speed(info);
 	}
 
+	/* If this is the serial console change the speed to 
+	 * the right value
+	 */
+	if (info->is_cons) {
+		info->tty->termios->c_cflag = sgisercon->cflag;
+		change_speed(info);		
+	}
+
 	info->session = current->session;
 	info->pgrp = current->pgrp;
 
 #ifdef SERIAL_DEBUG_OPEN
-	printk("rs_open ttys%d successful...", info->line);
+	printk("rs_open ttys%d successful...\n", info->line);
 #endif
 	return 0;
 }
@@ -1826,9 +1842,6 @@
 	}
 	if(o && i)
 		io = 1;
-	if (ss->zs_baud != 9562)	/* Don't ask... */
-		panic("Bad console baud rate %d", ss->zs_baud);
-
 
 	/* Set flag variable for this port so that it cannot be
 	 * opened for other uses by accident.
@@ -2039,7 +2052,6 @@
 rs_cons_hook(int chip, int out, int line)
 {
 	int channel;
-
 	
 	if(chip)
 		panic("rs_cons_hook called with chip not zero");
@@ -2124,11 +2136,11 @@
 static int __init zs_console_setup(struct console *con, char *options)
 {
 	struct sgi_serial *info;
-	int	baud = 9600;
+	int	baud;
 	int	bits = 8;
 	int	parity = 'n';
 	int	cflag = CREAD | HUPCL | CLOCAL;
-	char	*s;
+	char	*s, *dbaud;
 	int     i, brg;
     
 	if (options) {
@@ -2139,6 +2151,21 @@
 		if (*s) parity = *s++;
 		if (*s) bits   = *s - '0';
 	}
+	else {
+		/* If the user doesn't set console=... try to read the
+		 * PROM variable - if this fails use 9600 baud and
+		 * inform the user about the problem
+		 */
+		dbaud = ArcGetEnvironmentVariable("dbaud");
+		if(dbaud) baud = simple_strtoul(dbaud, NULL, 10);
+		else {
+			/* Use prom_printf() to make sure that the user
+			 * is getting anything ...
+			 */
+			prom_printf("No dbaud set in PROM ?!? Using 9600.\n");
+			baud = 9600;
+		}
+	}
 
 	/*
 	 *	Now construct a cflag setting.
@@ -2193,7 +2220,8 @@
 	info = zs_soft + con->index;
 	info->is_cons = 1;
     
-	printk("Console: ttyS%d (Zilog8530)\n", info->line);
+	printk("Console: ttyS%d (Zilog8530), %d baud\n", 
+						info->line, baud);
 
 	i = con->cflag & CBAUD;
 	if (con->cflag & CBAUDEX) {
@@ -2232,6 +2260,8 @@
 		zscons_regs[4] |= SB2;
 	else
 		zscons_regs[4] |= SB1;
+	
+	sgisercon = con;
 
 	brg = BPS_TO_BRG(baud, ZS_CLOCK / info->clk_divisor);
 	zscons_regs[12] = brg & 0xff;

---

From: Ralf Baechle <[email-masked]>
Date: Sat, 16 Jun 2001 20:06:23 +0200

> (There are also some small code beautifications in the patch)

Applied.

  Ralf