Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1370511lqa; Mon, 29 Apr 2024 06:53:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW19P3VwqR9bFfmbF1fHIIgnziP6PwCXTNSFgnQPpF4daEQlQ4kpm0dYF/PdtF3EvDE6dPg848D7q8MQnMa6+Bzw30I/1e2XHwYFfcreQ== X-Google-Smtp-Source: AGHT+IGFmkCUB+GjrvQDxVPVwYAf8g98XaZZSMzvnmT/tbCU60CMtZ87PTZXLy3GhB5oT8clkG1j X-Received: by 2002:a05:6871:e804:b0:22e:dd56:a72d with SMTP id qd4-20020a056871e80400b0022edd56a72dmr12756032oac.26.1714398786593; Mon, 29 Apr 2024 06:53:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714398786; cv=pass; d=google.com; s=arc-20160816; b=BQeytbbSiuXLqsrZAcQRnHuS7OynhmrVispw4so6ayn0LPQIFJx+JSCJy+VBARuhqM Wm85ehN8Hna21SHrPepZMF7J00Uw+L+WZqtUFX2f1D0A+g1Ocz6oemEhXdPRCQtzDmCT mbeSEK0PlFstAcUUPztW9SPlTQOphgA3h5k7cEi/XHrrHiNQcS/sr+yVeQ1CZpC+4eOS S2WKsYZQFvQw52IfszHb9rHnTuzfGKdlNXD2iI2Fa0/ITwsuIk/q1tcltfUS/tXTjlp8 lasSE0EuSk088XuyFsJBUOTlckth/8/V8p27X6Iqf1F9HrrfN0rDBrj5WRlq6HmDszG7 hbjg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=subject:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :cc:to:from:date:dkim-signature; bh=JOScwd5emOA8f50rEfismq1Niilar7kDI+5Uq6EhCPs=; fh=loFEvUHAFzhuZq42C34VyQiY5RCQfExc95zEF0wtZsw=; b=sehnM9N4IeFG/rP+tuRt0/TaGdz3A7RpnpyidKbYhPzt2MGHqO+bwJgX2zv3LgFfJ6 tKpKEOksat2okKaSb0tsu7nGAnZtYrqpt92h/8R1YL8I9vZg7rDN5fdBiKsOLNtvg2pb aK8aEZwWNHayDXqar/6KMI76hoK+dRuUXopvZewj87mfs8S+FHWJErQn5cuR7trdMcGq bPxkCPGqozcU9Vtt6nakqFqj9zBVMevrWv3kifw9f+nTSHb/9USYNhbg0J3417u1ju8a 1PTFU6r1yMcBYxe/yAc20q6qbmTZunQV4Cr5n8v9FbJuCe6cjBZyNoRPcM9BwsJGWp85 +HqQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@hugovil.com header.s=x header.b=cYHKVQPi; arc=pass (i=1 spf=pass spfdomain=hugovil.com dkim=pass dkdomain=hugovil.com); spf=pass (google.com: domain of linux-kernel+bounces-162387-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162387-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id r1-20020a63d901000000b0060c1588d333si6678169pgg.791.2024.04.29.06.53.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 06:53:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-162387-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@hugovil.com header.s=x header.b=cYHKVQPi; arc=pass (i=1 spf=pass spfdomain=hugovil.com dkim=pass dkdomain=hugovil.com); spf=pass (google.com: domain of linux-kernel+bounces-162387-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162387-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 7FF292862DF for ; Mon, 29 Apr 2024 13:47:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3D9387641B; Mon, 29 Apr 2024 13:47:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b="cYHKVQPi" Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D673745C5; Mon, 29 Apr 2024 13:47:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.243.120.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714398452; cv=none; b=bJDspt5mPf02BtbxhslPwii8L7knqw3D1MFoGwuQV73jPG1zsGNsa5MR95b3vdH8OfkvWOeifNhvNOtETGoOqmNlAbkXLkCLHcGTbmmVemBGJaiBZQnWIGdiA0Y+IhlYWoxbWvrhkBsubXlBuZM/T5qyO8Ax0/XgaOJH6d08CPM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714398452; c=relaxed/simple; bh=8qW/AiTuh5RfV5Y3WsEwv1Sr3kSET/1uMKux5Eab8c0=; h=Date:From:To:Cc:Message-Id:In-Reply-To:References:Mime-Version: Content-Type:Subject; b=APwWBUtb/sKydEqXFD04le3YDMcLxA/gfkK72Q8TNa2rcy7PXhtKDEDpyC40BLDS6XlUijoxgwtU1bxyijofV09D3IVAVAg8ueWDGCAzaVFf7ypYj2TtVVN4z0AJeCs+iWf8HfGfLOlJGZKBFUBblfPUZElv0KKew9ldQzhd9kA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hugovil.com; spf=pass smtp.mailfrom=hugovil.com; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b=cYHKVQPi; arc=none smtp.client-ip=162.243.120.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hugovil.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hugovil.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=x; h=Subject:Content-Transfer-Encoding:Mime-Version:Message-Id:Cc:To:From :Date:subject:date:message-id:reply-to; bh=JOScwd5emOA8f50rEfismq1Niilar7kDI+5Uq6EhCPs=; b=cYHKVQPi227WuXG120+O8hG3qn XjmPCTL36uOSO+8lXNETngTWDy2ooeTc6iIGIV4yPmFBkcOM7VjDiniSTMLjeYWy0AzyDf4eUWtA/ 1E/EZM0pe7qlFh7UOuMoHB6PEGdU+gmlDnov857ZlO7BE8UcDhR6o7r2lmYPSSGk3RxM=; Received: from [70.80.174.168] (port=58788 helo=pettiford) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1s1RLi-00052M-6X; Mon, 29 Apr 2024 09:47:18 -0400 Date: Mon, 29 Apr 2024 09:47:17 -0400 From: Hugo Villeneuve To: Jiri Slaby Cc: Greg Kroah-Hartman , Jon Ringle , ria.freelander@gmail.com, Hugo Villeneuve , stable@vger.kernel.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Message-Id: <20240429094717.de45ad35814e3c618e08c36b@hugovil.com> In-Reply-To: <17d2cc58-cf68-430d-9248-25abe4c5b0f0@kernel.org> References: <20240426135937.3810959-1-hugo@hugovil.com> <17d2cc58-cf68-430d-9248-25abe4c5b0f0@kernel.org> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 70.80.174.168 X-SA-Exim-Mail-From: hugo@hugovil.com X-Spam-Level: X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * -1.1 NICE_REPLY_A Looks like a legit reply (A) Subject: Re: [PATCH] serial: sc16is7xx: fix bug in sc16is7xx_set_baud() when using prescaler X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.hugovil.com) On Mon, 29 Apr 2024 08:39:22 +0200 Jiri Slaby wrote: > On 26. 04. 24, 15:59, Hugo Villeneuve wrote: > > From: Hugo Villeneuve > > > > When using a high speed clock with a low baud rate, the 4x prescaler is > > automatically selected if required. In that case, sc16is7xx_set_baud() > > properly configures the chip registers, but returns an incorrect baud > > rate by not taking into account the prescaler value. This incorrect baud > > rate is then fed to uart_update_timeout(). > > > > For example, with an input clock of 80MHz, and a selected baud rate of 50, > > sc16is7xx_set_baud() will return 200 instead of 50. > > > > Fix this by first changing the prescaler variable to hold the selected > > prescaler value instead of the MCR bitfield. Then properly take into > > account the selected prescaler value in the return value computation. > > > > Also add better documentation about the divisor value computation. > > > > Fixes: dfeae619d781 ("serial: sc16is7xx") > > Cc: stable@vger.kernel.org > > Signed-off-by: Hugo Villeneuve > > --- > > drivers/tty/serial/sc16is7xx.c | 23 ++++++++++++++++++----- > > 1 file changed, 18 insertions(+), 5 deletions(-) > > > > diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c > > index 03cf30e20b75..dcd6c5615401 100644 > > --- a/drivers/tty/serial/sc16is7xx.c > > +++ b/drivers/tty/serial/sc16is7xx.c > > @@ -555,16 +555,28 @@ static bool sc16is7xx_regmap_noinc(struct device *dev, unsigned int reg) > > return reg == SC16IS7XX_RHR_REG; > > } > > > > +/* > > + * Configure programmable baud rate generator (divisor) according to the > > + * desired baud rate. > > + * > > + * From the datasheet, the divisor is computed according to: > > + * > > + * XTAL1 input frequency > > + * ----------------------- > > + * prescaler > > + * divisor = --------------------------- > > + * baud-rate x sampling-rate > > + */ > > static int sc16is7xx_set_baud(struct uart_port *port, int baud) > > { > > struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); > > u8 lcr; > > - u8 prescaler = 0; > > + int prescaler = 1; > > Ugh, why do you move to signed arithmetics? Hi Jiri, before this patch, the variable prescaler was used to store an 8 bit bitfield. Now the variable meaning is changed to be used as the prescaler value, which can be 1 or 4 in this case. Leaving it as u8 would still be ok, or making it "unsigned int" maybe? Hugo. -- Hugo Villeneuve