Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795041372; b=IQlyI4Rz2s0Lp0OoLIvAMSJe8IIzFUjokvuPVsBbMxLpqzwY59PXpjnGK/VCR41ewInx 84QWTVNZ0b0QCNbf2rg6iVy1GBNkJ8ZH6t42VnK8hXsQuYi4gUVf0Sw1zkhFjR0h1tCAk 01XS5EFkvIyZeQBiiJCVwYi4tgRSzkUkFP6woeR3bGKdjCqHzNZPRvq7aFBrLZJiIh0R0 Pvi9EP/+oD8ktmO4EOWiL1hMJFMwl3pylxSN1Rpb8adp7PgbYQ5x0yLuRuVBSq9RRNS0L BwkjRmpvZceUQTLMSL/iSflQsUuOyCzsTzJoT4TgeS9enlIrUjorYh2q8NjB351TfvA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795041372; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=tCrFjj9Ylmd0tR3EYif7HPSyZrWJxrFD90W1+szysPw=; b=raRAekDt4iA4NtJhbx3e2JMUEUx4sLiOa64HehxGC+QqCAoPnfdsR0pSzbbqLgqQOBMf 2VLz4IY2s5eEQ5PS5ev+mPvx5HoG0omcsr/fkuY36RNrGIEw66b0Dz5EVJGlqrOLlBG+i UzxKO8sU8DQAKE40jEGrGP6axpttlJQMuRZZTPQw19ANqM+nIGHInx2N1HjTRHzHNKnrs Bkn53jwqseRqC7SCTs7BBew1HQDVhrgVwJ+S7WJFkbdgV0H3uUAaXz2ryTwU45bfnVA80 QVtK35/HFz7A1SuujXOpmzPPGu3yOpS/dEHbeRO7rBfuOI7JwAPMH87AIf69jyIORUA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=AwtiZ+cv; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11B0B606A32C; Wed, 18 Nov 2026 22:36:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=AwtiZ+cv Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2EED21F000C4; Wed, 18 Nov 2026 22:36:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795041371; bh=tCrFjj9Ylmd0tR3EYif7HPSyZrWJxrFD90W1+szysPw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=AwtiZ+cvx8lKiVs4Rm5UJJXDQh9xanCOSC+z/vPnN5HV1t/K4ZX4pRfhVqW/abgLT 7HLsYE1Chv52ghHQXeLxvJBsa9Akq3oDlumcWNRuVBAcrMUvTwyXhR/9yOwYFnG9wk 8A4x0hv3/UU4/XcVjDFiZSfUxdzXvudaCJL9Flaw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Tapio Reijonen , Sasha Levin Subject: [PATCH 6.6 2789/3318] serial: max310x: centralize the RS485 transceiver programming Date: Wed, 18 Nov 2026 15:56:51 +0100 Message-ID: <20261118150444.358992332@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150313.527275416@linuxfoundation.org> References: <20261118150313.527275416@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tapio Reijonen [ Upstream commit 56051740bf9720335a1a56e87a99e3491c33ce54 ] The HDPIXDELAY RTS delays and the MODE1 auto-transceiver enable are programmed in three places - the rs485-config worker, startup() and break_ctl()'s break-off restore - each with its own copy of the register sequence. Move the sequence into a helper, max310x_set_rts_ctl_params(), together with the tx_break guard that keeps the MODE1 write away from a break in progress; the break-off restore reapplies the current configuration through the same helper. No functional change intended. The copies differed only in that startup() clamped the delays to the 4-bit field while the worker wrote them unclamped; the helper clamps, and the difference is unreachable while rs485_config() still rejects delays above 15 ms with -ERANGE. Break-off additionally rewrites HDPIXDELAY with the values it already holds, a no-op on the wire. Assisted-by: Claude:claude-fable-5 Signed-off-by: Tapio Reijonen Link: https://patch.msgid.link/20261008-max310x-rs485-sw-delay-v8-3-6ba881f81e1f@vaisala.com Signed-off-by: Greg Kroah-Hartman Stable-dep-of: 7784d6aee59a ("serial: max310x: fix RS485 delays being programmed as bit-times") Signed-off-by: Sasha Levin --- drivers/tty/serial/max310x.c | 85 ++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 38 deletions(-) diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c index c83f351b7a199..6d50559f4ada0 100644 --- a/drivers/tty/serial/max310x.c +++ b/drivers/tty/serial/max310x.c @@ -895,6 +895,38 @@ static void max310x_set_mctrl(struct uart_port *port, unsigned int mctrl) schedule_work(&one->md_work); } +/* + * Program the chip's RS485 RTS timing (HDPIXDELAY) and the auto + * transceiver control (MODE1) from the current configuration. The + * rs485-config worker, startup() and break_ctl()'s break-off restore + * each carried their own copy of this sequence. + */ +static void max310x_set_rts_ctl_params(struct max310x_one *one) +{ + struct uart_port *port = &one->port; + unsigned int delay; + u8 mode1 = 0; + + delay = (clamp(port->rs485.delay_rts_before_send, 0U, 15U) << 4) | + clamp(port->rs485.delay_rts_after_send, 0U, 15U); + max310x_port_write(port, MAX310X_HDPIXDELAY_REG, delay); + + if (port->rs485.flags & SER_RS485_ENABLED) + mode1 = MAX310X_MODE1_TRNSCVCTRL_BIT; + + /* + * A break owns the transceiver: break_ctl() disabled auto-RTS and + * drives RTS manually, and restores it from the current + * configuration when the break ends. Touching MODE1 here would + * release the transceiver mid-break. + */ + if (one->tx_break) + return; + + max310x_port_update(port, MAX310X_MODE1_REG, + MAX310X_MODE1_TRNSCVCTRL_BIT, mode1); +} + static void max310x_break_ctl(struct uart_port *port, int break_state) { struct max310x_one *one = to_max310x_port(port); @@ -917,10 +949,7 @@ static void max310x_break_ctl(struct uart_port *port, int break_state) max310x_port_update(port, MAX310X_MODE1_REG, MAX310X_MODE1_TRNSCVCTRL_BIT, 0); } else { - max310x_port_update(port, MAX310X_MODE1_REG, - MAX310X_MODE1_TRNSCVCTRL_BIT, - (port->rs485.flags & SER_RS485_ENABLED) ? - MAX310X_MODE1_TRNSCVCTRL_BIT : 0); + max310x_set_rts_ctl_params(one); } max310x_rts_ctl(port, break_state); } @@ -1042,36 +1071,23 @@ static void max310x_set_termios(struct uart_port *port, static void max310x_rs_proc(struct work_struct *ws) { struct max310x_one *one = container_of(ws, struct max310x_one, rs_work); - unsigned int delay, mode1 = 0, mode2 = 0; + unsigned int mode2 = 0; /* * Serialize against break_ctl() and set_termios(), which run under - * port->mutex: the tx_break test below and the MODE1 write must not + * port->mutex: the tx_break-guarded register writes must not * straddle a break starting or ending. */ guard(mutex)(&one->port.state->port.mutex); - delay = (one->port.rs485.delay_rts_before_send << 4) | - one->port.rs485.delay_rts_after_send; - max310x_port_write(&one->port, MAX310X_HDPIXDELAY_REG, delay); + max310x_set_rts_ctl_params(one); - if (one->port.rs485.flags & SER_RS485_ENABLED) { - mode1 = MAX310X_MODE1_TRNSCVCTRL_BIT; + if (one->port.rs485.flags & SER_RS485_ENABLED && + !(one->port.rs485.flags & SER_RS485_RX_DURING_TX)) + mode2 = MAX310X_MODE2_ECHOSUPR_BIT; - if (!(one->port.rs485.flags & SER_RS485_RX_DURING_TX)) - mode2 = MAX310X_MODE2_ECHOSUPR_BIT; - } - - /* - * A break owns the transceiver: break_ctl() disabled auto-RTS and - * drives RTS manually, and restores it when the break ends. Leave - * MODE1 alone meanwhile or the break goes undriven mid-way. - */ - if (!one->tx_break) - max310x_port_update(&one->port, MAX310X_MODE1_REG, - MAX310X_MODE1_TRNSCVCTRL_BIT, mode1); max310x_port_update(&one->port, MAX310X_MODE2_REG, - MAX310X_MODE2_ECHOSUPR_BIT, mode2); + MAX310X_MODE2_ECHOSUPR_BIT, mode2); } static int max310x_rs485_config(struct uart_port *port, struct ktermios *termios, @@ -1115,21 +1131,14 @@ static int max310x_startup(struct uart_port *port) max310x_port_update(port, MAX310X_MODE2_REG, MAX310X_MODE2_FIFORST_BIT, 0); - /* Configure mode1/mode2 to have rs485/rs232 enabled at startup */ - val = (clamp(port->rs485.delay_rts_before_send, 0U, 15U) << 4) | - clamp(port->rs485.delay_rts_after_send, 0U, 15U); - max310x_port_write(port, MAX310X_HDPIXDELAY_REG, val); - - if (port->rs485.flags & SER_RS485_ENABLED) { - max310x_port_update(port, MAX310X_MODE1_REG, - MAX310X_MODE1_TRNSCVCTRL_BIT, - MAX310X_MODE1_TRNSCVCTRL_BIT); + /* Configure the RS485 RTS timing and the RS485/RS232 mode bits. */ + max310x_set_rts_ctl_params(one); - if (!(port->rs485.flags & SER_RS485_RX_DURING_TX)) - max310x_port_update(port, MAX310X_MODE2_REG, - MAX310X_MODE2_ECHOSUPR_BIT, - MAX310X_MODE2_ECHOSUPR_BIT); - } + if (port->rs485.flags & SER_RS485_ENABLED && + !(port->rs485.flags & SER_RS485_RX_DURING_TX)) + max310x_port_update(port, MAX310X_MODE2_REG, + MAX310X_MODE2_ECHOSUPR_BIT, + MAX310X_MODE2_ECHOSUPR_BIT); /* Configure flow control levels */ /* Flow control halt level 96, resume level 48 */ -- 2.53.0