From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793142348; b=VPy1puLC6TKI44PiTyB6V8vd1uBgZJeU8LfO4vJHzCfUAloxJTz0LgBqwVb3RGjTI2rH SBJjC22a0jD3wUHvFtFOOqSVSwhK9J2k22rKiZCWWdCOVBJ6Oesqygvrq6jQcEC5ZLxx2 yXwE62Nfzp8n702SNfMFmQxD51lxN1T0D1rFrqePqy/lvMJF3qKJxsDt6bpPlbMc+Pr2f pUkJZN1oZArH3dD9ruv2il/G20ka5QNDIkjCJFaqy+pHTt7VR7mJ9EQB9FN3pRAFGXDt6 TXV0RjgvykhiO35MCIUSDGUwhbAPgpnBqj/GCSbBBf8ucdh1wSupJnkSuhX8qpcqSKA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793142348; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:Date:Subject: MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id: References:In-Reply-To:To:Cc:X-Mailer; bh=AhsVd9Fsi+UcY/XjunpIc7bQ1eO+aEtcrlfgyGAcjFk=; b=kSr763jE00Gj+QZiFAAECH6fyy4CWBd2FN27hYL3IQ9GQbVeraj8mphIb7sg2vmU2fWj cGm8+uD5KDxbmku+iyTV2U7Dy1cJ99hJc+LGoqqDxyU8B/skEvwdYM1XyrnnSAA1KE0t7 CIcN+DJHOuWNdo0MnhGeONtKhfFuWwMG/OmSlzOzX9PSoQZ7K9yPHhm0ZT70YjSx8JknK Kz+a8bDjxUrh6FWruiw+1ABTie7JtkS3IMH98GjsEY57be2er8uRCz7zHnBK2/HT+ejsJ 9rwIJieknYBXECPr84Im+aSbBFN9LOxUmVJ+/fShhKZ/IibuV38gamYBRlv9uQV4DbQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Oy8Ns+OC; arc=none smtp.remote-ip=209.85.210.53 Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B4F8606A329 for ; Tue, 27 Oct 2026 23:05:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0B4F8606A329 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Oy8Ns+OC Received: by mail-ot1-f53.google.com with SMTP id 46e09a7af769-844a8bf7e25so256185a34.1 for ; Tue, 27 Oct 2026 16:05:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793142347; x=1793747147; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=AhsVd9Fsi+UcY/XjunpIc7bQ1eO+aEtcrlfgyGAcjFk=; b=Oy8Ns+OCuC8ms5bppmSME9oA5Rj8eAcfHuQdFl+6a68Uh/Yh4JezhkNOUtwi2fYGS0 LQ4bfKrOfnWNOVfHrDj2JaL8Q1f9TRiCjKqOO3a+CGjr7AG8HXv/iRti4XirkbkOxAJd iKd9uTPNgd8ICiFtbWFFdOzMlbYlPfoN75I9YOMXl5jPLt84T+0uj1oA4sPIHYUYAkPO PKsdlY2vdCf5evctBKpLJaBChE7jzkDhv9Y8gRcDtFo7XRlu8niEL3QqbprUdCBoJUNf LvchEAOGktphaYcq9HiQYAvucYhV5bES3OfQWOQ5Ptbf1udgIalmmHqRPLFJw0rf11Gu AFCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793142347; x=1793747147; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=AhsVd9Fsi+UcY/XjunpIc7bQ1eO+aEtcrlfgyGAcjFk=; b=DAjzAS3gIoGpVDdrzP0rvEseJCLC3dbhiOZIZk7uhXOGy47GkEvPAHyXTc3ngz+aCV aW0oPNJpznGj23AIg0l2KLTe5q+Q5mDp5+6vB7/mb3zimfVsjsXZ3WnSoamM3YBGYNu3 3vFn5Yc9DCebwlHosZrj40ErT+E9GjTpQP3dpPjHSVxT7IQAn0E1zIA/A4w7I+11uaS0 gb5TKgriKmHzc+vNBKZW70q75A2VcomWfT8G0e1Eo99xQ/Vs7ze5CoZ8EZ2eMEj3iIRT VSDk77W+RIvRDzSl6zuwEDuifYDkv8J16I86SPp7SH0r4UCRkqLEdVEY6YtVhTZVUEjU MDYQ== X-Gm-Message-State: AFq9FYLV2bDeHw8IgPc4uHKwwJHt1I2yPy31/a3Id0jaxpgTiRUqyzZB u4vPbwhqKZOQIO5mTmBwB/4bjbsxsNjS1s8o59UD97Yo5q7lDg8oxSr+ X-Gm-Gg: AYBFou0ncBcxWXtcflBZK+Pa7hmqkJAJ0xM8aGqIe6vmbZOuL1Ky7p7+jIMPNTW6Jf8 YFZhfcLaAIcTmnrsUc3buVatPvEZXD3ny9wEEkTf4BVHO9+kw42AvQWWKWcJJ0F1enDRtWuJDbR 2z/sSVawNlOhRMCGhNriIUuYpVTK8j6bT6PWs3LQ6vfPwQkgLGLszUZOFoJwv//gYtwz/sxeI79 psZtsiVwRKlV1CGUr9AKkr6Afa6aBrM1KUxewR5+xi82eny+bYnequV4MwpPolRGnV2csuP3YNE USmxU4Cxrqt2CC059l1WKWUg9pFXWjsxjvSwhbCk2HdeMHPNYZ1/foxkxRmOZwAPboGT/F02ePw 4mlyl9MfEuqlG7nccnokK70Ib/hvNvqgv+IcEMfFKeUS48/mAO/fzdVNoZf229TLQbtVh+rfHcN C45R0o64LzYnyAQWGw8YQBWPH2w7WEiTAWFMLa5ZDSnPgYSKid23oWzzTUm4Telbvupkvv1WDUY 0PNT5E9rHMsfZdpU/Fa/7akfN4+/5Z42W/weAW5InRrLYdJFa3XyxZ2VakVNxZ1CGLAsR0Km4CB Tki8albVOyE5BI0y3Sazd1DNdsqTtfGjeF3kGgOH9njsT+VFQ5DsDMkwDcpOg1MB6/Rh/6kk59j f67ZPpTq76/JoE2KGWVLDD13BD+2A8kY9bMWJ9izJV6Os0b151j1jgFRmvaZQtlGD1B2/3APlbH /qtA== X-Received: by 2002:a05:6820:3385:20b0:713:da3b:901d with SMTP id 006d021491bc7-713f21629bfmr243308eaf.79.1793142346826; Tue, 27 Oct 2026 16:05:46 -0700 (PDT) Received: from [127.0.1.1] (174-29-1-49.hlrn.qwest.net. [174.29.1.49]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-850fb0741c9sm12093328a34.10.2026.10.27.16.05.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2026 16:05:46 -0700 (PDT) From: James Hilliard Date: Tue, 27 Oct 2026 17:05:30 -0600 Subject: [PATCH v4 2/5] serial: 8250: share the RX trigger conversion helper X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261027-submit-h616-uart-fifo-v1-v4-2-d37e018fd0a6@gmail.com> References: <20261027-submit-h616-uart-fifo-v1-v4-0-d37e018fd0a6@gmail.com> In-Reply-To: <20261027-submit-h616-uart-fifo-v1-v4-0-d37e018fd0a6@gmail.com> To: Greg Kroah-Hartman , Jiri Slaby , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andy Shevchenko , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, James Hilliard X-Mailer: b4 0.15.2 Extract the receive-trigger threshold search into serial8250_bytes_to_fcr() so drivers with per-port threshold tables can use the same conversion as the generic 8250 implementation. Include the unsupported-table check in the helper and preserve the existing nearest-lower selection and highest-encoding fallback. Signed-off-by: James Hilliard --- drivers/tty/serial/8250/8250.h | 16 ++++++++++++++++ drivers/tty/serial/8250/8250_port.c | 12 +----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/drivers/tty/serial/8250/8250.h b/drivers/tty/serial/8250/8250.h index 21ed9c41b751..195ed58a2231 100644 --- a/drivers/tty/serial/8250/8250.h +++ b/drivers/tty/serial/8250/8250.h @@ -8,6 +8,7 @@ */ #include +#include #include #include #include @@ -73,6 +74,21 @@ struct serial8250_config { unsigned int flags; }; +static inline int serial8250_bytes_to_fcr(const unsigned char *rxtrig_bytes, + unsigned char bytes) +{ + if (!rxtrig_bytes[UART_FCR_R_TRIG_BITS(UART_FCR_R_TRIG_00)]) + return -EOPNOTSUPP; + + for (unsigned int i = 1; i < UART_FCR_R_TRIG_MAX_STATE; i++) { + if (bytes < rxtrig_bytes[i]) + /* Use the nearest lower value */ + return (i - 1) << UART_FCR_R_TRIG_SHIFT; + } + + return UART_FCR_R_TRIG_11; +} + enum uart_port_type { /* Internal 8250 only */ UART_PORT_AIROHA = 124, diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c index 36b2b0a2c05c..c332963dc2ed 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -3018,18 +3018,8 @@ static int fcr_get_rxtrig_bytes(struct uart_8250_port *up) static int bytes_to_fcr_rxtrig(struct uart_8250_port *up, unsigned char bytes) { const struct serial8250_config *conf_type = &uart_config[up->port.type]; - int i; - if (!conf_type->rxtrig_bytes[UART_FCR_R_TRIG_BITS(UART_FCR_R_TRIG_00)]) - return -EOPNOTSUPP; - - for (i = 1; i < UART_FCR_R_TRIG_MAX_STATE; i++) { - if (bytes < conf_type->rxtrig_bytes[i]) - /* Use the nearest lower value */ - return (--i) << UART_FCR_R_TRIG_SHIFT; - } - - return UART_FCR_R_TRIG_11; + return serial8250_bytes_to_fcr(conf_type->rxtrig_bytes, bytes); } static int do_get_rxtrig(struct tty_port *port) -- 2.53.0