From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 A6BD32F260C for ; Wed, 17 Sep 2025 12:39:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758112799; cv=none; b=cop0SefANYZEmWrRnp8ezooVyBvVR1xQ0PUzcSryqafh4ZcqoGhM/0tSlrIuiXwgjF0uuA5DaVZFWbqmhbZImPpvQdjeDP6McVy1/8DN7nedyUidWohCMgNljzO4jRtx8uV79QraVvmkjBLLwkwEsHzUZ3MP/Ehn7xD10gA0BIw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758112799; c=relaxed/simple; bh=PaS2a2/znE+omUNzde5Q+XFoGjNmvp+yy6uIt74Vkhg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KYcsLxiU/O0s53Fuy8QxGU7vspcphlpGIuI1REwhuuhzHi0CeqRthu+AKukHV6lthhgknx/Wco117/p++80z+uZ7N3Bg/MPJ+F6bwPzXMC1+Rb0Aey5ZduRzQJF4lhzAAXLxFpt5qjWKV/T22dQ4sK/fOIF1ElMB+CLtdNbIJkc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=h7XyZXdw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="h7XyZXdw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11BDFC4CEF0; Wed, 17 Sep 2025 12:39:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1758112799; bh=PaS2a2/znE+omUNzde5Q+XFoGjNmvp+yy6uIt74Vkhg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h7XyZXdwIbIOvuE7h2tl7rGgW5vvM2I/FwOZsF28zmIeeOKH8cukbd3R2uDLRZRUC Zb87ofui48Jxexx4BxK5PlqfjhP6i6MFnwvbNbuPqUVvDDuMkZyJ6BOBPRGGZbQcuH lMluRtWBI+msvrHULeISqQFby8FvO6cPF3J3kPEPSZaVU2y7FCZgS/7JoSS39+VrY3 MMO/td76f3BsRHU5QGP8VOv68dTGfXzE4ht7LpdbxMqUxngVUnJvYPOKL2rLpuXV6+ YdR2ch1+949bW8qaxfruIEN/HcIt/yR9ST4x8su79BZr3zzsBiPXksjlHGecZB+uis 35XOFvW6ibbHA== From: Sasha Levin To: stable@vger.kernel.org Cc: Hugo Villeneuve , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH 5.15.y] serial: sc16is7xx: fix bug in flow control levels init Date: Wed, 17 Sep 2025 08:39:57 -0400 Message-ID: <20250917123957.515161-1-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <2025091721-moonwalk-barrack-423e@gregkh> References: <2025091721-moonwalk-barrack-423e@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Hugo Villeneuve [ Upstream commit 535fd4c98452c87537a40610abba45daf5761ec6 ] When trying to set MCR[2], XON1 is incorrectly accessed instead. And when writing to the TCR register to configure flow control levels, we are incorrectly writing to the MSR register. The default value of $00 is then used for TCR, which means that selectable trigger levels in FCR are used in place of TCR. TCR/TLR access requires EFR[4] (enable enhanced functions) and MCR[2] to be set. EFR[4] is already set in probe(). MCR access requires LCR[7] to be zero. Since LCR is set to $BF when trying to set MCR[2], XON1 is incorrectly accessed instead because MCR shares the same address space as XON1. Since MCR[2] is unmodified and still zero, when writing to TCR we are in fact writing to MSR because TCR/TLR registers share the same address space as MSR/SPR. Fix by first removing useless reconfiguration of EFR[4] (enable enhanced functions), as it is already enabled in sc16is7xx_probe() since commit 43c51bb573aa ("sc16is7xx: make sure device is in suspend once probed"). Now LCR is $00, which means that MCR access is enabled. Also remove regcache_cache_bypass() calls since we no longer access the enhanced registers set, and TCR is already declared as volatile (in fact by declaring MSR as volatile, which shares the same address). Finally disable access to TCR/TLR registers after modifying them by clearing MCR[2]. Note: the comment about "... and internal clock div" is wrong and can be ignored/removed as access to internal clock div registers (DLL/DLH) is permitted only when LCR[7] is logic 1, not when enhanced features is enabled. And DLL/DLH access is not needed in sc16is7xx_startup(). Fixes: dfeae619d781 ("serial: sc16is7xx") Cc: stable@vger.kernel.org Signed-off-by: Hugo Villeneuve Link: https://lore.kernel.org/r/20250731124451.1108864-1-hugo@hugovil.com Signed-off-by: Greg Kroah-Hartman [ changed regmap variable from one->regmap to s->regmap ] Signed-off-by: Sasha Levin --- drivers/tty/serial/sc16is7xx.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c index d274a847c6ab3..3623d3167950d 100644 --- a/drivers/tty/serial/sc16is7xx.c +++ b/drivers/tty/serial/sc16is7xx.c @@ -1018,7 +1018,6 @@ static int sc16is7xx_config_rs485(struct uart_port *port, static int sc16is7xx_startup(struct uart_port *port) { struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); - struct sc16is7xx_port *s = dev_get_drvdata(port->dev); unsigned int val; sc16is7xx_power(port, 1); @@ -1030,16 +1029,6 @@ static int sc16is7xx_startup(struct uart_port *port) sc16is7xx_port_write(port, SC16IS7XX_FCR_REG, SC16IS7XX_FCR_FIFO_BIT); - /* Enable EFR */ - sc16is7xx_port_write(port, SC16IS7XX_LCR_REG, - SC16IS7XX_LCR_CONF_MODE_B); - - regcache_cache_bypass(s->regmap, true); - - /* Enable write access to enhanced features and internal clock div */ - sc16is7xx_port_write(port, SC16IS7XX_EFR_REG, - SC16IS7XX_EFR_ENABLE_BIT); - /* Enable TCR/TLR */ sc16is7xx_port_update(port, SC16IS7XX_MCR_REG, SC16IS7XX_MCR_TCRTLR_BIT, @@ -1051,7 +1040,8 @@ static int sc16is7xx_startup(struct uart_port *port) SC16IS7XX_TCR_RX_RESUME(24) | SC16IS7XX_TCR_RX_HALT(48)); - regcache_cache_bypass(s->regmap, false); + /* Disable TCR/TLR access */ + sc16is7xx_port_update(port, SC16IS7XX_MCR_REG, SC16IS7XX_MCR_TCRTLR_BIT, 0); /* Now, initialize the UART */ sc16is7xx_port_write(port, SC16IS7XX_LCR_REG, SC16IS7XX_LCR_WORD_LEN_8); -- 2.51.0