From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa.local.altlinux.org X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.1 X-Yandex-Fwd: 2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1653064197; bh=jO0sk2ryTwr73jm4N5TNkhMDiSyzy6BwFQrLFPBCHGA=; h=Reply-To:In-Reply-To:References:Date:Subject:Cc:To:From: Message-Id; b=ewOXyqHV+ZR6Hx/WH4oDeqxFYkL9nwj+I8s+yIVZXE7mpFesyDUDEeh7krarWE3KL P28krrDZMhC8vXGM9IGnIiNUQVHFLoERrvOrj6HdIr8nBQFqTXN0JlI1/WbUrW2nDO ektgTctk/yMBElyv5Zorg7rNY20CERo3CVgUt+xE= Authentication-Results: sas8-743d099bef85.qloud-c.yandex.net; dkim=pass header.i=@yandex.ru From: asheplyakov@yandex.ru To: devel@lists.altlinux.org Date: Fri, 20 May 2022 20:28:32 +0400 Message-Id: <20220520162849.1554351-19-asheplyakov@yandex.ru> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220520162849.1554351-1-asheplyakov@yandex.ru> References: <20220520162849.1554351-1-asheplyakov@yandex.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Cc: Alexey Sheplyakov , "Vadim V . Vlasov" , Evgeny Sinelnikov , Vitaly Chikunov , Igor Chudov , Greg Kroah-Hartman , Serge Semin , Andy Shevchenko Subject: [devel] [PATCH 18/35] [rejected] serial: 8250_dw: verify clock rate in dw8250_set_termios X-BeenThere: devel@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: ALT Linux Team development discussions List-Id: ALT Linux Team development discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 May 2022 16:30:03 -0000 Archived-At: List-Archive: List-Post: From: Alexey Sheplyakov Refuse to change the clock rate if clk_round_rate() returns a rate which is way too off (i.e. by more than 1/16 from the one necessary for a given baud rate). In particular this happens if the requested rate is below the minimum supported by the clock. Fixes the UART console on Baikal-M SoC. Without this patch the console gets garbled immediately after loading the driver. dw8250_set_termios tries to configure the baud rate (115200), and calls clk_round_rate to figure out the supported rate closest to 1843200 Hz (which is 115200 * 16). However the (SoC-specific) clock driver returns 4705882 Hz. This frequency is way too off, hence after setting it the console gets garbled. Signed-off-by: Alexey Sheplyakov Signed-off-by: Vadim V. Vlasov Cc: Andy Shevchenko Cc: Greg Kroah-Hartman Cc: Serge Semin X-feature-Baikal-M --- drivers/tty/serial/8250/8250_dw.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c index 1769808031c5..ec7e8169c983 100644 --- a/drivers/tty/serial/8250/8250_dw.c +++ b/drivers/tty/serial/8250/8250_dw.c @@ -329,14 +329,15 @@ dw8250_do_pm(struct uart_port *port, unsigned int state, unsigned int old) static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios, struct ktermios *old) { - unsigned long newrate = tty_termios_baud_rate(termios) * 16; + unsigned long baud = tty_termios_baud_rate(termios); + unsigned long newrate = baud * 16; struct dw8250_data *d = to_dw8250_data(p->private_data); long rate; int ret; clk_disable_unprepare(d->clk); rate = clk_round_rate(d->clk, newrate); - if (rate > 0) { + if (rate > 0 && rate >= baud * 15 && rate <= baud * 17) { /* * Note that any clock-notifer worker will block in * serial8250_update_uartclk() until we are done. -- 2.32.0