Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1802489lqa; Mon, 29 Apr 2024 22:24:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV1g42WXlFDKLhzD1+agEtG7ejd6LRYowLr4KFH1plHaIsY1VSFnPgadtwNRn8GNnyl4dmcbKCPOTRg/1YSDo7/d7OPKdO1KYqT/8sztw== X-Google-Smtp-Source: AGHT+IFujl0NJGvvM1LYXDfSqAVcmZhrz1YMBQCI0TIaDg11ElInRX1DC65j9NaWnmVjvOMTFEhR X-Received: by 2002:a17:903:228f:b0:1eb:e1b:737a with SMTP id b15-20020a170903228f00b001eb0e1b737amr2103997plh.44.1714454675631; Mon, 29 Apr 2024 22:24:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714454675; cv=pass; d=google.com; s=arc-20160816; b=YJluk0Uy7bw5Ls7b/PIYA5x/n4TSv/nOerGh4B/vkzPs+b8VkXiQGlaMyvs90rbYFs 94mNIPG1xtExQ/tUL6soKgft9s1nEkuNf55MsdxMvPG5HTG3OZO3Q4XinCz3/jneRT88 hR4CXi4+o2CLWx8UK4596LTqDMOl7C/Hojkbt3/Q6pBpxyiRnYh9Iw0nNJXyW5z5kfTU JXG6XKRvGHGYyY7imFgMjp4KPu4iNpswbcimL60x+iirDgKBvICFY7KySxZ2B20fEeKa 8HpAJ47w8q2BOX19CubVNBl7Sr7x1HNyWSNu3Ns+OxUUa57bpBdcTTeU0w/qehag+W50 sC2Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id; bh=D5xXiqJPcQvnAdhsKYWwY5ng2w3w/qDQxjxYllnlVz8=; fh=iGraJ0aWxexPkSxH3pR181VW8NbEzUbsejbDADxKbtA=; b=cApjMev9jBjPkvEj8/pckcCAElLu1eADXZnhzX9Q2kXL8RR5vo+NRSs07zZ3KibsOs cw5zvezF/P+2lsLQUBk3tm0yG/XW7gdjt3mUIl0Np3lsqyDxks7E2YDepyJ3H9WWPDVS rPXKdawmTEuIFEzOU8Ie0t6y7BKLIZzi3miIsI+J4fuapITLjT9+u8Vg1RH2+1wnn0IE mQ6NQ33yx6fMSpmku2jKYTfX3xAx3If50vfa5Zj87zYx4dOX4J0/MIo1p3FGgNMVrEq3 /NrjKhn6yPlv3mX+WEn+op00PoYnbbm4UyA/OpHpfXQMlE8OPQSipMTHFnaJxa9dWc1F VXwg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-163361-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163361-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 mf13-20020a170902fc8d00b001eb4c988a4csi5907773plb.321.2024.04.29.22.24.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 22:24:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-163361-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; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-163361-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163361-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 E86A228266D for ; Tue, 30 Apr 2024 05:23:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BAC8217729; Tue, 30 Apr 2024 05:22:59 +0000 (UTC) Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70C9E5256; Tue, 30 Apr 2024 05:22:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714454579; cv=none; b=SAAXeF4wX9kHa9GEvOv02PQ57CC6ltYuluzLp/yArdXircUQJxbAYFld22ryJYOoq4nvpR2VhTIcLZ7APJD1HK07rhSVJKyhuztc5t9jLvtvN6gE8fCc90/KMJHxHc1exxsOaH5UvmVoLZVev6JLqLm75Zn7PYE62SjHCMTgO80= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714454579; c=relaxed/simple; bh=Kz8gaoGkFIuxrMaQK6fWNTWX0CdyB9VvlppbwWz6Y2s=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=DvDhJC58z8HOJMI9SAcb1MwbEHlLDDjfRhORhIgWy7XbV8DLadM2iuN9QvbanPEIZ67dEroYW5Y8ky43TECrQQ2lwwCPIGwX6Pn00fIN5tQGIMQAV1OFHVF0yZCcLnQykR6JqpeDNMKN0GyVvkZogF8YbqFUpaNRFl7e+uKm1k0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-56e47843cc7so5195151a12.0; Mon, 29 Apr 2024 22:22:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714454576; x=1715059376; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=D5xXiqJPcQvnAdhsKYWwY5ng2w3w/qDQxjxYllnlVz8=; b=GCCP3s/VbGgp9l8EWVK21nmIMDq4UCD5xrU1Ueo8+AtB00PwD1XbZTxvDI3gerUcfH WCpR9ieIhhkK2fOM21aYSAGWX8njbQQRJWt+hn+B1OYIswJtlLOv45vgYg7d+2B8BbPt iRO2/3Vziktwx/kR1Sr6hKAFJad2ZUZM23IaEIDV/LCmXxSV9JPfVnLJZ65zIgm6oq0X vLnwbjyiHfFBljXTDUvOch51O2TK6JUuLXhQp1A+g+tFJltonKdIUjXrcHIgtXqYxke0 OJIH1Itq80Nja30bpYPxxEJxC9rovfb3R3ygTKJxizjmyiY1tnBFZxz6hCBRkCSyQ6il PJTw== X-Forwarded-Encrypted: i=1; AJvYcCXVfp/XqsI8ulzlA+BywW6bOi3olTz35IfAW9qQ1DWGut++27Ao1QrozPKTy7S8U/dAbHi0LKyb2mPVkQKXYN+d8/0/AdAX6vXBZZovfEzDiJ4hhX/TvebnptKxwl7mAq9HxQa6bY94+skZ1lC18xroKdevAI2G5GwlDP9dzyGyO9SX X-Gm-Message-State: AOJu0YwCbPuMNdVAZPw4tQE21wfqs8Sl4tXNzBtNBNRyiegnsxG+oBg8 wRwxBX6YgNKojooX04OPbaA28s26z4gbzIQAQU+BAVFb0svXPGa6 X-Received: by 2002:a17:906:7110:b0:a52:225a:2ebe with SMTP id x16-20020a170906711000b00a52225a2ebemr977474ejj.71.1714454575512; Mon, 29 Apr 2024 22:22:55 -0700 (PDT) Received: from ?IPV6:2a0b:e7c0:0:107::aaaa:69? ([2a0b:e7c0:0:107::aaaa:69]) by smtp.gmail.com with ESMTPSA id ak1-20020a170906888100b00a5906b4e417sm1572741ejc.98.2024.04.29.22.22.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 29 Apr 2024 22:22:55 -0700 (PDT) Message-ID: Date: Tue, 30 Apr 2024 07:22:54 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] serial: sc16is7xx: fix bug in sc16is7xx_set_baud() when using prescaler To: Hugo Villeneuve 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 References: <20240426135937.3810959-1-hugo@hugovil.com> <17d2cc58-cf68-430d-9248-25abe4c5b0f0@kernel.org> <20240429094717.de45ad35814e3c618e08c36b@hugovil.com> Content-Language: en-US From: Jiri Slaby Autocrypt: addr=jirislaby@kernel.org; keydata= xsFNBE6S54YBEACzzjLwDUbU5elY4GTg/NdotjA0jyyJtYI86wdKraekbNE0bC4zV+ryvH4j rrcDwGs6tFVrAHvdHeIdI07s1iIx5R/ndcHwt4fvI8CL5PzPmn5J+h0WERR5rFprRh6axhOk rSD5CwQl19fm4AJCS6A9GJtOoiLpWn2/IbogPc71jQVrupZYYx51rAaHZ0D2KYK/uhfc6neJ i0WqPlbtIlIrpvWxckucNu6ZwXjFY0f3qIRg3Vqh5QxPkojGsq9tXVFVLEkSVz6FoqCHrUTx wr+aw6qqQVgvT/McQtsI0S66uIkQjzPUrgAEtWUv76rM4ekqL9stHyvTGw0Fjsualwb0G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rpnq4f/EYTykbk1sa13Tav6btJ+4QOgbcezWI wZ5w/JVfEJW9JXp3BFAVzRQ5nVrrLDAJZ8Y5ioWcm99JtSIIxXxt9FJaGc1Bgsi5K/+dyTKL wLMJgiBzbVx8G+fCJJ9YtlNOPWhbKPlrQ8+AY52Aagi9WNhe6XfJdh5g6ptiOILm330mkR4g W6nEgZVyIyTq3ekOuruftWL99qpP5zi+eNrMmLRQx9iecDNgFr342R9bTDlb1TLuRb+/tJ98 f/bIWIr0cqQmqQ33FgRhrG1+Xml6UXyJ2jExmlO8JljuOGeXYh6ZkIEyzqzffzBLXZCujlYQ DFXpyMNVJ2ZwPmX2mWEoYuaBU0JN7wM+/zWgOf2zRwhEuD3A2cO2PxoiIfyUEfB9SSmffaK/ S4xXoB6wvGENZ85Hg37C7WDNdaAt6Xh2uQIly5grkgvWppkNy4ZHxE+jeNsU7tg= In-Reply-To: <20240429094717.de45ad35814e3c618e08c36b@hugovil.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 29. 04. 24, 15:47, Hugo Villeneuve wrote: > 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? Both :). What you prefer -- uint matches more IMO, given it's now a value and not a register... thanks, -- js suse labs