static int dead_ports = 0;
-#ifdef GRUB_MACHINE_MIPS_LOONGSON
-#define DEFAULT_BASE_CLOCK (2 * 115200)
-#else
-#define DEFAULT_BASE_CLOCK 115200
-#endif
-
static grub_uint8_t
ns8250_reg_read (struct grub_serial_port *port, grub_addr_t reg)
{
grub_uint32_t divisor;
grub_uint32_t actual_speed, error;
- base_clock = config->base_clock ? (config->base_clock >> 4) : DEFAULT_BASE_CLOCK;
+ /* Get the UART input clock frequency. */
+ base_clock = config->base_clock ? config->base_clock : UART_DEFAULT_BASE_CLOCK;
+
+ /*
+ * The UART uses 16 times oversampling for the BRG, so adjust the value
+ * accordingly to calculate the divisor.
+ */
+ base_clock >>= 4;
divisor = (base_clock + (config->speed / 2)) / config->speed;
if (config->speed == 0)
/* Turn on DTR, RTS, and OUT2. */
#define UART_ENABLE_OUT2 0x08
+/*
+ * Default clock input of the UART (feeds the baud rate generator).
+ *
+ * The standard value here is 1.8432 MHz, which corresponds to
+ * 115200 bauds * 16 (16 times oversampling).
+ *
+ */
+#ifdef GRUB_MACHINE_MIPS_LOONGSON
+#define UART_DEFAULT_BASE_CLOCK ((2 * 115200) << 4)
+#else
+#define UART_DEFAULT_BASE_CLOCK (115200 << 4)
+#endif
+
#ifndef ASM_FILE
#include <grub/cpu/io.h>