Skip to contentSkip to conversation

x86/boot: Use BASE_BAUD and DEFAULT_SERIAL_PORT

PATCH RESEND Applied Thorsten Blum 2 participants 2 messages Aug 19 – Sep 2 x86

lore
Share & tools
lore
#0 lore raw

PATCH RESEND v2 1/1 x86/boot: Use BASE_BAUD and DEFAULT_SERIAL_PORT

Replace the hard-coded baud rate and ttyS0 port with the existing BASE_BAUD and DEFAULT_SERIAL_PORT macros.

In parse_earlyprintk(), assign the port directly and drop the redundant index variable as well as the bases array to simplify the code.

No functional change.

---
Changes in v2:
- Drop patch 1/2 from the series after feedback from Dave
- v1: https://lore.kernel.org/r/[email protected]/

---
 arch/x86/boot/early_serial_console.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
arch/x86/boot/early_serial_console.c +5 -8
index 5b83beab89e1..ce6b588dfed0 100644
@@ -22,6 +22,7 @@
 #define DLH             1       /*  Divisor latch High        */
 
 #define DEFAULT_BAUD 9600
+#define BASE_BAUD (1843200 / 16)
 
 static void early_serial_init(int port, int baud)
 {
@@ -33,7 +34,7 @@ static void early_serial_init(int port, int baud)
 	outb(0, port + FCR);	/* no fifo */
 	outb(0x3, port + MCR);	/* DTR + RTS */
 
-	divisor	= 115200 / baud;
+	divisor	= BASE_BAUD / baud;
 	c = inb(port + LCR);
 	outb(c | DLAB, port + LCR);
 	outb(divisor & 0xff, port + DLL);
@@ -74,16 +75,13 @@ static void parse_earlyprintk(void)
 			else
 				pos = e - arg;
 		} else if (!strncmp(arg + pos, "ttyS", 4)) {
-			static const int bases[] = { 0x3f8, 0x2f8 };
-			int idx = 0;
-
 			/* += strlen("ttyS"); */
 			pos += 4;
 
 			if (arg[pos++] == '1')
-				idx = 1;
-
-			port = bases[idx];
+				port = 0x2f8; /* ttyS1 */
+			else
+				port = DEFAULT_SERIAL_PORT;
 		}
 
 		if (arg[pos] == ',')
@@ -98,7 +96,6 @@ static void parse_earlyprintk(void)
 		early_serial_init(port, baud);
 }
 
-#define BASE_BAUD (1843200/16)
 static unsigned int probe_baud(int port)
 {
 	unsigned char lcr, dll, dlh;
merge bot Applied
#1 lore raw
The following commit has been merged into the x86/boot branch of tip:

The following commit has been merged into the x86/boot branch of tip:

Commit-ID:     6744e454d877e51394ed15e48e25c97dd6c62099
Gitweb:        https://git.kernel.org/tip/6744e454d877e51394ed15e48e25c97dd6c62099
Author:        Thorsten Blum <[email protected]>
AuthorDate:    Wed, 19 Aug 2026 10:25:29 +02:00
Committer:     Dave Hansen <[email protected]>
CommitterDate: Wed, 02 Sep 2026 14:08:29 -07:00

x86/boot: Use BASE_BAUD and DEFAULT_SERIAL_PORT

Replace the hard-coded baud rate and ttyS0 port with the existing BASE_BAUD and DEFAULT_SERIAL_PORT macros.

In parse_earlyprintk(), assign the port directly and drop the redundant index variable as well as the bases array to simplify the code.

No functional change.

---
 arch/x86/boot/early_serial_console.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
arch/x86/boot/early_serial_console.c +5 -8
index 5b83bea..39fcd55 100644
@@ -22,6 +22,7 @@
 #define DLH             1       /*  Divisor latch High        */
 
 #define DEFAULT_BAUD 9600
+#define BASE_BAUD (1843200 / 16)
 
 static void early_serial_init(int port, int baud)
 {
@@ -33,7 +34,7 @@ static void early_serial_init(int port, int baud)
 	outb(0, port + FCR);	/* no fifo */
 	outb(0x3, port + MCR);	/* DTR + RTS */
 
-	divisor	= 115200 / baud;
+	divisor	= BASE_BAUD / baud;
 	c = inb(port + LCR);
 	outb(c | DLAB, port + LCR);
 	outb(divisor & 0xff, port + DLL);
@@ -74,16 +75,13 @@ static void parse_earlyprintk(void)
 			else
 				pos = e - arg;
 		} else if (!strncmp(arg + pos, "ttyS", 4)) {
-			static const int bases[] = { 0x3f8, 0x2f8 };
-			int idx = 0;
-
 			/* += strlen("ttyS"); */
 			pos += 4;
 
 			if (arg[pos++] == '1')
-				idx = 1;
-
-			port = bases[idx];
+				port = 0x2f8; /* ttyS1 */
+			else
+				port = DEFAULT_SERIAL_PORT;
 		}
 
 		if (arg[pos] == ',')
@@ -98,7 +96,6 @@ static void parse_earlyprintk(void)
 		early_serial_init(port, baud);
 }
 
-#define BASE_BAUD (1843200/16)
 static unsigned int probe_baud(int port)
 {
 	unsigned char lcr, dll, dlh;