From patchwork Fri Jun 25 14:36:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 12345447 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2CE0C2B9F4 for ; Fri, 25 Jun 2021 14:39:07 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C10AC61973 for ; Fri, 25 Jun 2021 14:39:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C10AC61973 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=e116G5PZARGHhScsVOsGRbnI73uD5GlVOX0fpBTMYbM=; b=IWWghOnWAibHIU +UNMhfIVb+00eauk8pf43iras38CdbJ/bGUlZ/Tnnvh5wFcboy/OUDY8kJ/Bl749KQV+M+erDWRNj OP+TdMMwZzWZfxnUJUECckFWIID4kLDWCTWb/pNmIbAewsTLZtUdb/jFGY7eftceqAOniR5QDFiUU M+4VHVGxonjvokr7PvydoS3jDINrNzj7i4E1JdHzZzD6xWDQtiDtAj+mPHF512uAp7/KpPVTXBp0/ UAI3TYwvRir/7nqvBz34KtEzxRhJWO4ysFtd+OlnGwDhdt6msXb5saxuo+JLYD1dh+RlIdA9WXMn1 ACu1XRR5FDbzdz7qUPqA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lwmxP-001y6I-EK; Fri, 25 Jun 2021 14:37:23 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lwmx0-001xys-4W for linux-arm-kernel@lists.infradead.org; Fri, 25 Jun 2021 14:37:00 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id B8D7A61973; Fri, 25 Jun 2021 14:36:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624631817; bh=Do7JpeaMbcTZFmYRsJ6KflWqZQ5cEUS3jxE0VeBISec=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZTdbKCzUtkhY7+XRY51c+GDNXCRzLEbq3Unv+8CmnL6pEvnnMWq8KLWIKpYMuT2UL kZK9J01yj1nE9cJWHYoeVIhg2EzvIbFdSRyET9EH2C2jMEEFxJoC3phIjiStcWv1By 26HLjqprxUTvPpjDszhHEEpQeRwaIKeyTzhiX6OJkt9jtkmDNtpglEBhReGmqbuNr3 xVCUjh1hHg+smMXaxH7Q2z9259NFaMfAKSkHCb77uGTf4vVwLja+i2wMwBWt7880// Nz77Xgm6CySATbSUmm2TDYH1wxCMovyDS8jG7FQdS7rWlT5x1c6kgVrQCoVVz0YCKW m/Rg7DpasPbIQ== Received: by pali.im (Postfix) id 7A14660E; Fri, 25 Jun 2021 16:36:57 +0200 (CEST) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Michael Turquette , Stephen Boyd , Rob Herring , Greg Kroah-Hartman Cc: Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Vladimir Vid , =?utf-8?q?Marek_Beh=C3=BAn?= , Geert Uytterhoeven , linux-clk@vger.kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 03/11] serial: mvebu-uart: correctly calculate minimal possible baudrate Date: Fri, 25 Jun 2021 16:36:09 +0200 Message-Id: <20210625143617.12826-4-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210625143617.12826-1-pali@kernel.org> References: <20210624224909.6350-1-pali@kernel.org> <20210625143617.12826-1-pali@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210625_073658_240236_10BE33F1 X-CRM114-Status: GOOD ( 12.47 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org For default (x16) scheme which is currently used by mvebu-uart.c driver, maximal divisor of UART base clock is 1023*16. Therefore there is limit for minimal supported baudrate. This change calculate it correctly and prevents setting invalid divisor 0 into hardware registers. Signed-off-by: Pali Rohár Fixes: 68a0db1d7da2 ("serial: mvebu-uart: add function to change baudrate") --- drivers/tty/serial/mvebu-uart.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/mvebu-uart.c b/drivers/tty/serial/mvebu-uart.c index dc0c26824ddb..f8b0016db847 100644 --- a/drivers/tty/serial/mvebu-uart.c +++ b/drivers/tty/serial/mvebu-uart.c @@ -481,7 +481,7 @@ static void mvebu_uart_set_termios(struct uart_port *port, struct ktermios *old) { unsigned long flags; - unsigned int baud; + unsigned int baud, min_baud, max_baud; spin_lock_irqsave(&port->lock, flags); @@ -500,16 +500,21 @@ static void mvebu_uart_set_termios(struct uart_port *port, port->ignore_status_mask |= STAT_RX_RDY(port) | STAT_BRK_ERR; /* + * Maximal divisor is 1023 * 16 when using default (x16) scheme. * Maximum achievable frequency with simple baudrate divisor is 230400. * Since the error per bit frame would be of more than 15%, achieving * higher frequencies would require to implement the fractional divisor * feature. */ - baud = uart_get_baud_rate(port, termios, old, 0, 230400); + min_baud = DIV_ROUND_UP(port->uartclk, 1023 * 16); + max_baud = 230400; + + baud = uart_get_baud_rate(port, termios, old, min_baud, max_baud); if (mvebu_uart_baud_rate_set(port, baud)) { /* No clock available, baudrate cannot be changed */ if (old) - baud = uart_get_baud_rate(port, old, NULL, 0, 230400); + baud = uart_get_baud_rate(port, old, NULL, + min_baud, max_baud); } else { tty_termios_encode_baud_rate(termios, baud, baud); uart_update_timeout(port, termios->c_cflag, baud);