From: James Hilliard <james.hilliard1@gmail.com>
To: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Jiri Slaby" <jirislaby@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Chen-Yu Tsai" <wens@kernel.org>,
"Jernej Skrabec" <jernej.skrabec@gmail.com>,
"Samuel Holland" <samuel@sholland.org>
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 <james.hilliard1@gmail.com>
Subject: [PATCH v4 2/5] serial: 8250: share the RX trigger conversion helper
Date: Tue, 27 Oct 2026 17:05:30 -0600 [thread overview]
Message-ID: <20261027-submit-h616-uart-fifo-v1-v4-2-d37e018fd0a6@gmail.com> (raw)
In-Reply-To: <20261027-submit-h616-uart-fifo-v1-v4-0-d37e018fd0a6@gmail.com>
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 <james.hilliard1@gmail.com>
---
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 <linux/bits.h>
+#include <linux/errno.h>
#include <linux/serial_8250.h>
#include <linux/serial_core.h>
#include <linux/dmaengine.h>
@@ -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
next prev parent reply other threads:[~2026-10-27 23:05 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 23:05 [PATCH v4 0/5] serial: 8250_dw: describe the Allwinner H616 UART configuration James Hilliard
2026-10-27 23:05 ` [PATCH v4 1/5] serial: 8250_dw: select port setup through platform data James Hilliard
2026-10-28 8:56 ` Andy Shevchenko
2026-10-28 9:40 ` Andy Shevchenko
2026-10-27 23:05 ` James Hilliard [this message]
2026-10-28 8:30 ` [PATCH v4 2/5] serial: 8250: share the RX trigger conversion helper Ilpo Järvinen
2026-10-28 9:38 ` Andy Shevchenko
2026-10-28 9:37 ` Andy Shevchenko
2026-10-27 23:05 ` [PATCH v4 3/5] dt-bindings: serial: snps-dw-apb-uart: add Allwinner H616 James Hilliard
2026-10-28 8:06 ` Krzysztof Kozlowski
2026-10-27 23:05 ` [PATCH v4 4/5] serial: 8250_dw: configure the Allwinner H616 UART James Hilliard
2026-10-28 8:39 ` Ilpo Järvinen
2026-10-28 8:53 ` James Hilliard
2026-10-28 8:57 ` Ilpo Järvinen
2026-10-28 11:05 ` Andy Shevchenko
2026-10-27 23:05 ` [PATCH v4 5/5] arm64: dts: allwinner: h616: describe the UART integration James Hilliard
2026-10-28 8:57 ` [PATCH v4 0/5] serial: 8250_dw: describe the Allwinner H616 UART configuration Andre Przywara
2026-10-28 9:04 ` James Hilliard
2026-10-28 9:04 ` Chen-Yu Tsai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261027-submit-h616-uart-fifo-v1-v4-2-d37e018fd0a6@gmail.com \
--to=james.hilliard1@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jernej.skrabec@gmail.com \
--cc=jirislaby@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=robh@kernel.org \
--cc=samuel@sholland.org \
--cc=wens@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®