Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp484049imn; Wed, 27 Jul 2022 11:28:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tmDYczX2lOv0i4JggxqFEzpzo3XB6AXl2FKf2pHcmntj4PI5Vy9W7vJpr+CiAqq5u7VtnH X-Received: by 2002:a17:90b:1e46:b0:1f2:9f69:3f5e with SMTP id pi6-20020a17090b1e4600b001f29f693f5emr5836178pjb.228.1658946539535; Wed, 27 Jul 2022 11:28:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658946539; cv=none; d=google.com; s=arc-20160816; b=Ma9QT2D+uwIZ7cHLii47BLbB3eYXAFQlyax10GEOfJT4ex2zOhyQy+LjQsW8TVUwTi XIXYDoAba/d6KRlKrhWGhMxHIv1xNpxIkD8s43n8Fk99tWHLswjBkDAdCvCfLOiWHbsX G3R6EwM/G1VMamawNUx3ggtztfjaRT+emVxXrUtYUm32bIjmR7DPVwU9/DARTbkeF53a 2DGWIZpUFP3sinXkigV3CYiObOEaIQHDLkgaXVtTBqQcUnV+At30IHFcOcjBFxV8a/oF zz2X5WoW5OXv1Vbnb+IDQRETe1vf8FSlhLY10bMtvrJADohidYL91PuGvB2uA3ZsetWG XgLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zNuwnSkP1e3a1Mr1qsICVRmEN6dJtUV9cwkIPlmeHk4=; b=a5DUmN2hiLyY0CO5UWG1CDlvOPFJO6G31xQRbKI96C6RaPqg3MMj7XsmpRgH7ojnS3 H+6rvtFAoEXT0zhpfNCIYR59jCD8pY4OtlpncoEnMt4q7Rtn4Bep53/EtBT4IhObXUKI te5V5xdzmAvwz7fLSnl+vVhu1CGw/Mrf9d4oeYbkBQOB5Escz3sUDvWCZSDi2VcmFg1d RbxNi6HRMn6V0w0MVasXVQEiHnTTDXa/2WB51FiyH8CJjUUmfQ1z67yXrTa7dDHa2S+J rDbWKXl/RDSioucFumo557j+ZQAIIhJWm0uBgdNJ9l+eTdyoyFw0UDhO0lVmiuLBjz89 aWNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DS17Fi1y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b11-20020a65578b000000b0041288737bc6si21858156pgr.797.2022.07.27.11.28.44; Wed, 27 Jul 2022 11:28:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DS17Fi1y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239128AbiG0QiS (ORCPT + 99 others); Wed, 27 Jul 2022 12:38:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238379AbiG0Qhg (ORCPT ); Wed, 27 Jul 2022 12:37:36 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D6F94F6B7; Wed, 27 Jul 2022 09:28:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 574AFB821A6; Wed, 27 Jul 2022 16:27:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AEDE6C433D7; Wed, 27 Jul 2022 16:27:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939269; bh=WtF9BKyztuDudarIy8lWa8uBbyXGJ5Wc6Q/lzCzgqR8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DS17Fi1yGp4eNpQEp0DI8T0qW6A9qwfw/9nXE6BOuKVyinBMQCI2EOrEXij93JFY9 Eds7+shP+wYuUALflsXQjzrVtR8NSCt8+MlCbamXDLZ12uB+YKfDCzw0k7jVvt4BEG QXtf+InspiSUTJ4V1bqxqfi/G12q9BWNIRcHLv2o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , =?UTF-8?q?Pali=20Roh=C3=A1r?= Subject: [PATCH 5.4 10/87] serial: mvebu-uart: correctly report configured baudrate value Date: Wed, 27 Jul 2022 18:10:03 +0200 Message-Id: <20220727161009.434828786@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161008.993711844@linuxfoundation.org> References: <20220727161008.993711844@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pali Rohár commit 4f532c1e25319e42996ec18a1f473fd50c8e575d upstream. Functions tty_termios_encode_baud_rate() and uart_update_timeout() should be called with the baudrate value which was set to hardware. Linux then report exact values via ioctl(TCGETS2) to userspace. Change mvebu_uart_baud_rate_set() function to return baudrate value which was set to hardware and propagate this value to above mentioned functions. With this change userspace would see precise value in termios c_ospeed field. Fixes: 68a0db1d7da2 ("serial: mvebu-uart: add function to change baudrate") Cc: stable Reviewed-by: Ilpo Järvinen Signed-off-by: Pali Rohár Link: https://lore.kernel.org/r/20220628100922.10717-1-pali@kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/mvebu-uart.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) --- a/drivers/tty/serial/mvebu-uart.c +++ b/drivers/tty/serial/mvebu-uart.c @@ -443,13 +443,13 @@ static void mvebu_uart_shutdown(struct u } } -static int mvebu_uart_baud_rate_set(struct uart_port *port, unsigned int baud) +static unsigned int mvebu_uart_baud_rate_set(struct uart_port *port, unsigned int baud) { unsigned int d_divisor, m_divisor; u32 brdv, osamp; if (!port->uartclk) - return -EOPNOTSUPP; + return 0; /* * The baudrate is derived from the UART clock thanks to two divisors: @@ -473,7 +473,7 @@ static int mvebu_uart_baud_rate_set(stru osamp &= ~OSAMP_DIVISORS_MASK; writel(osamp, port->membase + UART_OSAMP); - return 0; + return DIV_ROUND_CLOSEST(port->uartclk, d_divisor * m_divisor); } static void mvebu_uart_set_termios(struct uart_port *port, @@ -510,15 +510,11 @@ static void mvebu_uart_set_termios(struc 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, - min_baud, max_baud); - } else { - tty_termios_encode_baud_rate(termios, baud, baud); - uart_update_timeout(port, termios->c_cflag, baud); - } + baud = mvebu_uart_baud_rate_set(port, baud); + + /* In case baudrate cannot be changed, report previous old value */ + if (baud == 0 && old) + baud = tty_termios_baud_rate(old); /* Only the following flag changes are supported */ if (old) { @@ -529,6 +525,11 @@ static void mvebu_uart_set_termios(struc termios->c_cflag |= CS8; } + if (baud != 0) { + tty_termios_encode_baud_rate(termios, baud, baud); + uart_update_timeout(port, termios->c_cflag, baud); + } + spin_unlock_irqrestore(&port->lock, flags); }