Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1p8XBQ-0004HJ-PS for mharc-grub-devel@gnu.org; Thu, 22 Dec 2022 20:49:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p8XBP-0004GL-6T for grub-devel@gnu.org; Thu, 22 Dec 2022 20:49:11 -0500 Received: from gate.crashing.org ([63.228.1.57]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p8XBN-0002G3-Kh for grub-devel@gnu.org; Thu, 22 Dec 2022 20:49:10 -0500 Received: from u0f3226c756e75a.ant.amazon.com (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 2BN1m0pK029703; Thu, 22 Dec 2022 19:48:07 -0600 From: Benjamin Herrenschmidt To: grub-devel@gnu.org Cc: Daniel Kiper Subject: [PATCH v3 4/8] ns8250: Move base clock definition to a header Date: Fri, 23 Dec 2022 12:47:55 +1100 Message-Id: <20221223014759.2112747-5-benh@kernel.crashing.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221223014759.2112747-1-benh@kernel.crashing.org> References: <20221223014759.2112747-1-benh@kernel.crashing.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=63.228.1.57; envelope-from=benh@kernel.crashing.org; helo=gate.crashing.org X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Dec 2022 01:49:11 -0000 And while at it, unify it as clock frequency in HZ, to match the value in "struct grub_serial_config" and do the division by 16 in one common place. This will simplify adding SPCR support. Signed-off-by: Benjamin Herrenschmidt --- grub-core/term/ns8250.c | 15 ++++++++------- include/grub/ns8250.h | 13 +++++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/grub-core/term/ns8250.c b/grub-core/term/ns8250.c index 43b9b3719..9e0ebff5a 100644 --- a/grub-core/term/ns8250.c +++ b/grub-core/term/ns8250.c @@ -37,12 +37,6 @@ static const grub_port_t serial_hw_io_addr[] = GRUB_MACHINE_SERIAL_PORTS; 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) { @@ -71,7 +65,14 @@ serial_get_divisor (const struct grub_serial_port *port __attribute__ ((unused)) 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) diff --git a/include/grub/ns8250.h b/include/grub/ns8250.h index 7947ba9c9..697637912 100644 --- a/include/grub/ns8250.h +++ b/include/grub/ns8250.h @@ -70,6 +70,19 @@ /* 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 -- 2.34.1