From nobody Tue Jun 16 08:59:29 2026 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) (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 1BCB9355F22; Fri, 17 Apr 2026 15:34:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.243.120.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776440045; cv=none; b=B/srIRR0PGvFMWuBXBFfoz0z4sY3Bz/w4DxJpawEPdzKGgKX8IBj6qSA4cNcir5+xLQH55UZi3OifF5EfiRhNIKXTK/PWBgTYhmlrN2glla7keP8Am4YXPW204uw2ym/nbi5++y4gBX6oDbYgHefk0Ggq1RENh/jX3KDbqwo3uI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776440045; c=relaxed/simple; bh=5fwFWD64q/284R3V91Vc+AQbiReL+DimReCrmgsVQik=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Pynj9pPnxgZOJAw+xKvjJqwIhbtrcMDjchLFMKTFnyLcrOWx9mitp2FfV252Ci4b6LL9ezfvPMkm7wHoFJe43/8j1/WA0P28Tzd8/5Pgm9bwJI/jBq8DzaEeFssiBwTAIzOhZ0MWFehoN1huVSjwtUMLiSapPXLO/byuAbWkLXo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com; spf=pass smtp.mailfrom=hugovil.com; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b=FEZRosRI; arc=none smtp.client-ip=162.243.120.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hugovil.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b="FEZRosRI" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=default; h=Cc:To:Message-Id:Content-Transfer-Encoding:MIME-Version: Subject:Date:From:subject:date:message-id:reply-to; bh=tJI+cGERKhwRtiKOq4c7VXzLEXcvXpKZtt7AuIqICpY=; b=FEZRosRIcMJOh6ACnP14sSgxp2 Gl0tWoJBL02ReTE5MX0cDQ8st9R9wq46yqm5DC+pI8SNZVQg9C4YdIJluIY9zV39dCGwv4P32m/3j YaDdHP1iZN3arUZMLvSaR9yEJlkEfbhr6+4vEE+/2GI4U6OlCG/P1/WSprADL20+oqjw=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168] helo=pettiford.lan) by mail.hugovil.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wDkZk-000000006G1-0Bsw; Fri, 17 Apr 2026 10:53:44 -0400 From: Hugo Villeneuve Date: Fri, 17 Apr 2026 10:53:28 -0400 Subject: [PATCH 01/10] serial: max310x: uniformize clock/freq types Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260417-max310x-2-v1-1-b424e105ecac@dimonoff.com> References: <20260417-max310x-2-v1-0-b424e105ecac@dimonoff.com> In-Reply-To: <20260417-max310x-2-v1-0-b424e105ecac@dimonoff.com> To: Greg Kroah-Hartman , Jiri Slaby Cc: hugo@hugovil.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Hugo Villeneuve X-Mailer: b4 0.14.2 X-Spam_score: -1.0 X-Spam_bar: - From: Hugo Villeneuve max310x_set_ref_clk() returns a 32-bits clock value, so there is no need to have parameters and intermediate values defined as long. Change clock and freq types to int. Signed-off-by: Hugo Villeneuve --- drivers/tty/serial/max310x.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c index ac7d3f197c3a5ce3531d5607f48e21a807314021..7c1c3696f5684d6dcaf1149e54b= fa96c202c7b26 100644 --- a/drivers/tty/serial/max310x.c +++ b/drivers/tty/serial/max310x.c @@ -545,7 +545,7 @@ static int max310x_set_baud(struct uart_port *port, int= baud) return (16*port->uartclk) / (c*(16*div + frac)); } =20 -static int max310x_update_best_err(unsigned long f, long *besterr) +static int max310x_update_best_err(unsigned int f, long *besterr) { /* Use baudrate 115200 for calculate error */ long err =3D f % (460800 * 16); @@ -559,11 +559,11 @@ static int max310x_update_best_err(unsigned long f, l= ong *besterr) } =20 static s32 max310x_set_ref_clk(struct device *dev, struct max310x_port *s, - unsigned long freq, bool xtal) + unsigned int freq, bool xtal) { unsigned int div, clksrc, pllcfg =3D 0; long besterr =3D -1; - unsigned long fdiv, fmul, bestfreq =3D freq; + unsigned int fdiv, fmul, bestfreq =3D freq; =20 /* First, update error without PLL */ max310x_update_best_err(freq, &besterr); @@ -1268,7 +1268,8 @@ static int max310x_probe(struct device *dev, const st= ruct max310x_devtype *devty const struct max310x_if_cfg *if_cfg, struct regmap *regmaps[], int irq) { - int i, ret, fmin, fmax, freq; + unsigned int fmin, fmax, freq; + int i, ret; struct max310x_port *s; s32 uartclk =3D 0; bool xtal; --=20 2.47.3 From nobody Tue Jun 16 08:59:29 2026 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) (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 75B8033F369; Fri, 17 Apr 2026 15:33:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.243.120.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776440036; cv=none; b=UiyyWpRWvT/wSlFqfKui1CS+YjVhataO7AMEU9WqDEhY6Et6qBjEPdEqirDeOPS0M3pG25VBH1zWsQfR8VrabYuir27PKUu1xrzXT6KGWYe3pfJEsGQK3G23thYPkE+vY2EY9qZx9vgkpZKaIBEQJXLcuZxdFFsJzAB3w+z7sJw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776440036; c=relaxed/simple; bh=9M/m7/iEXerd05V7b7L2yr85SujnxzgnSV/Dt86WMZo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bZ1umJFTchyYMMixV1BsOMv4Soh6NWbIvxmWtmoEpl8+K+swMjOwjM56Fxou644ZlsZuNkg3om0rBoU2HOuID/Ov97ug7dv8xpxMwYUre4O8nXflPJAiYmtEoQOvvsZ7QzD5u3IfKVaBMafwLjBBygreZNRGGFD4xaXny/jxlws= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com; spf=pass smtp.mailfrom=hugovil.com; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b=ShuAP7V0; arc=none smtp.client-ip=162.243.120.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hugovil.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b="ShuAP7V0" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=default; h=Cc:To:Message-Id:Content-Transfer-Encoding:MIME-Version: Subject:Date:From:subject:date:message-id:reply-to; bh=PVatuzDeuSgICP14v/Pc8l1OJ0TJ78LckqcaMkywL2k=; b=ShuAP7V00gyviTsINZtyrd2MbW PkdjyDnOAqDpnAhi/WtWykxwbSg7duTjostU0MONe1nbBOV4/KAyef0loXJO/I/mEVVIhqsmBElWg XFvbEj7UDCbZlOIvaRS1fTimp+zHoxlLictXNEHFoMQGAx5+f27BAzd7a4mGV174lN5Q=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168] helo=pettiford.lan) by mail.hugovil.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wDkZk-000000006G1-26ah; Fri, 17 Apr 2026 10:53:45 -0400 From: Hugo Villeneuve Date: Fri, 17 Apr 2026 10:53:29 -0400 Subject: [PATCH 02/10] serial: max310x: simplify max310x_update_best_err() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260417-max310x-2-v1-2-b424e105ecac@dimonoff.com> References: <20260417-max310x-2-v1-0-b424e105ecac@dimonoff.com> In-Reply-To: <20260417-max310x-2-v1-0-b424e105ecac@dimonoff.com> To: Greg Kroah-Hartman , Jiri Slaby Cc: hugo@hugovil.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Hugo Villeneuve X-Mailer: b4 0.14.2 X-Spam_score: -1.0 X-Spam_bar: - From: Hugo Villeneuve besterr was defined as a signed type was to make sure that the first call to max310x_update_best_err() would always set besterr. Also there is no need for it to be a long. By changing its type to unsigned int and initial value to UINT_MAX, max310x_update_best_err() can be simplified and be more efficient while achieving the same initial result. Signed-off-by: Hugo Villeneuve --- drivers/tty/serial/max310x.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c index 7c1c3696f5684d6dcaf1149e54bfa96c202c7b26..b68a17ebd10b84fa2ecfc521efa= 454cb248f90b5 100644 --- a/drivers/tty/serial/max310x.c +++ b/drivers/tty/serial/max310x.c @@ -545,12 +545,12 @@ static int max310x_set_baud(struct uart_port *port, i= nt baud) return (16*port->uartclk) / (c*(16*div + frac)); } =20 -static int max310x_update_best_err(unsigned int f, long *besterr) +static int max310x_update_best_err(unsigned int f, unsigned int *besterr) { /* Use baudrate 115200 for calculate error */ - long err =3D f % (460800 * 16); + unsigned int err =3D f % (460800 * 16); =20 - if ((*besterr < 0) || (*besterr > err)) { + if (*besterr > err) { *besterr =3D err; return 0; } @@ -562,7 +562,7 @@ static s32 max310x_set_ref_clk(struct device *dev, stru= ct max310x_port *s, unsigned int freq, bool xtal) { unsigned int div, clksrc, pllcfg =3D 0; - long besterr =3D -1; + unsigned int besterr =3D UINT_MAX; unsigned int fdiv, fmul, bestfreq =3D freq; =20 /* First, update error without PLL */ --=20 2.47.3 From nobody Tue Jun 16 08:59:29 2026 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) (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 40CE7327C13; Fri, 17 Apr 2026 15:33:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.243.120.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776440030; cv=none; b=C5HXyYqRek83A0ZSnR1Phk3ILQp/KcjfEOG70h3Di7cKY729fWRFUf0vgyn/uzShOFGq8n0QNX4KC+/Tj7hLxh17p/D3u0P1LEEV7O2ldEyoXkd99eQGhcrKAm0bDTTTgMsZ8qShphbSFCwWjwv4ulir9flovGSwRP8A6RPQb+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776440030; c=relaxed/simple; bh=4U0P3A5wrxly9jIJ5YkfKdkeyY9my7q2UQ4LbHi4KRs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LSD6BDiMnJqADAUeZ3bkcMZJTlbr6vCnkoquOV0nPOXqT6i03RxKL6bLDmU6qVY52jW6glsi1tR2Fo5/ttoCA9wi6AAMY2a6sV3mtatQHOLwmNspTJWRNgKzOd5AJgQnadOe5fWfDDyMmq/yrn671ZAzV8hTFGYOOtpIcC0L6RQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com; spf=pass smtp.mailfrom=hugovil.com; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b=dXdaAToO; arc=none smtp.client-ip=162.243.120.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hugovil.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b="dXdaAToO" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=default; h=Cc:To:Message-Id:Content-Transfer-Encoding:MIME-Version: Subject:Date:From:subject:date:message-id:reply-to; bh=YEeGNMfEveyhN4xQnnwYA24tkEbgabYnkwZa9juJ0IU=; b=dXdaAToO2hn0m+5occo9gUDnvs tv6GrUD+A45l5eQgpWp5/lUOpNitVUfo0Gq4JjKizVMWeZGul3dLNq1hq4tjsmJ9I7o1MFGLKcbYj reYnNi7IyB6XlkjLlw/qe0bIyp/z3Y+ac57ypN5k3Gz3W8dCe2RbwZHU9vYXDckqYs8o=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168] helo=pettiford.lan) by mail.hugovil.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wDkZl-000000006G1-13NJ; Fri, 17 Apr 2026 10:53:45 -0400 From: Hugo Villeneuve Date: Fri, 17 Apr 2026 10:53:30 -0400 Subject: [PATCH 03/10] serial: max310x: change return type of max310x_set_ref_clk() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260417-max310x-2-v1-3-b424e105ecac@dimonoff.com> References: <20260417-max310x-2-v1-0-b424e105ecac@dimonoff.com> In-Reply-To: <20260417-max310x-2-v1-0-b424e105ecac@dimonoff.com> To: Greg Kroah-Hartman , Jiri Slaby Cc: hugo@hugovil.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Hugo Villeneuve X-Mailer: b4 0.14.2 X-Spam_score: -1.0 X-Spam_bar: - From: Hugo Villeneuve Having max310x_set_ref_clk() return an s32 as both an error code and a frequency value is ambiguous. Fix by passing a pointer to the frequency value that will then be updated, and simply return a status. Signed-off-by: Hugo Villeneuve --- drivers/tty/serial/max310x.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c index b68a17ebd10b84fa2ecfc521efa454cb248f90b5..cf27e597ea41541331c8786fe4b= 4ded39b53d291 100644 --- a/drivers/tty/serial/max310x.c +++ b/drivers/tty/serial/max310x.c @@ -558,8 +558,8 @@ static int max310x_update_best_err(unsigned int f, unsi= gned int *besterr) return 1; } =20 -static s32 max310x_set_ref_clk(struct device *dev, struct max310x_port *s, - unsigned int freq, bool xtal) +static int max310x_set_ref_clk(struct device *dev, struct max310x_port *s, + unsigned int freq, unsigned int *fref, bool xtal) { unsigned int div, clksrc, pllcfg =3D 0; unsigned int besterr =3D UINT_MAX; @@ -632,7 +632,9 @@ static s32 max310x_set_ref_clk(struct device *dev, stru= ct max310x_port *s, "clock is not stable\n"); } =20 - return bestfreq; + *fref =3D bestfreq; + + return 0; } =20 static void max310x_batch_write(struct uart_port *port, u8 *txbuf, unsigne= d int len) @@ -1271,7 +1273,7 @@ static int max310x_probe(struct device *dev, const st= ruct max310x_devtype *devty unsigned int fmin, fmax, freq; int i, ret; struct max310x_port *s; - s32 uartclk =3D 0; + unsigned int uartclk =3D 0; bool xtal; =20 for (i =3D 0; i < devtype->nr; i++) @@ -1357,11 +1359,9 @@ static int max310x_probe(struct device *dev, const s= truct max310x_devtype *devty regmap_write(regmaps[i], MAX310X_MODE1_REG, devtype->mode1); } =20 - uartclk =3D max310x_set_ref_clk(dev, s, freq, xtal); - if (uartclk < 0) { - ret =3D uartclk; + ret =3D max310x_set_ref_clk(dev, s, freq, &uartclk, xtal); + if (ret < 0) goto out_uart; - } =20 dev_dbg(dev, "Reference clock set to %i Hz\n", uartclk); =20 --=20 2.47.3 From nobody Tue Jun 16 08:59:29 2026 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) (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 A02443314C3; Fri, 17 Apr 2026 15:33:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.243.120.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776440033; cv=none; b=ep4kmwBdsvM0PqllYLSWS2I6/dSvDxPeyozCxNlqjI588ZRPP4Qrf/1d5AndInNK5b/EdEGKX6qJzivlAgM3JToTA2GYEoDVXMf3urvy7jq2eXP6ShMfzdajQY0Fz1szKi3FyGsUXSrUsNyWf2As7vqU8TgbjdiZo7rzoOAdyG0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776440033; c=relaxed/simple; bh=G1/C2+OJXrbp1b/vTRImwESyawyH0PGepnCv9IgnW88=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Nr1lZnTpVO2yfIib6lMQajzg6Ad+uR2wHDBoJ3UyxISfOkIcO/eXmXC82sDonRmlfhqJHjoNmD3nftgfB6B6RlXPYS2phDwdc+bdtZHnkoxIWhJJeXRC6Wbc7vSx8q8l6WlaN9FiZyWLwktwRGQaRJ5X/0VRi5O5CID9nZhaYF0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com; spf=pass smtp.mailfrom=hugovil.com; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b=mv7Zkotm; arc=none smtp.client-ip=162.243.120.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hugovil.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b="mv7Zkotm" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=default; h=Cc:To:Message-Id:Content-Transfer-Encoding:MIME-Version: Subject:Date:From:subject:date:message-id:reply-to; bh=SrOuTDRQ+SPwftrBjxPzGmOX6OSsXdLvn+A6nL4ojqc=; b=mv7ZkotmJSLi+Q2fAB5/USojXA EM0kR2Cd8Z6loN1cUYDCQor8rpbV6Ta1P4jGSE+UfuegV0t3XW9dPF5zM7F82J8XXWiBMlqcSFV6A M8Se17rXdQ9brAn5+Mn7Yi2LDnrLnkpfGHfW6vNDABh2cffPjlid2I6cwE5BeohlXaJc=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168] helo=pettiford.lan) by mail.hugovil.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wDkZl-000000006G1-2weW; Fri, 17 Apr 2026 10:53:45 -0400 From: Hugo Villeneuve Date: Fri, 17 Apr 2026 10:53:31 -0400 Subject: [PATCH 04/10] serial: max310x: update baudrate comments for err calculation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260417-max310x-2-v1-4-b424e105ecac@dimonoff.com> References: <20260417-max310x-2-v1-0-b424e105ecac@dimonoff.com> In-Reply-To: <20260417-max310x-2-v1-0-b424e105ecac@dimonoff.com> To: Greg Kroah-Hartman , Jiri Slaby Cc: hugo@hugovil.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Hugo Villeneuve X-Mailer: b4 0.14.2 X-Spam_score: -1.0 X-Spam_bar: - From: Hugo Villeneuve The baudrate used to compute the best error was changed from 115200 to 460800 in commit 35240ba26a93 ("tty: max310x: Fix invalid baudrate divisors calculator"), but the comment was not updated, so fix it. Signed-off-by: Hugo Villeneuve --- drivers/tty/serial/max310x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c index cf27e597ea41541331c8786fe4b4ded39b53d291..f689958736f71b15b7c113214cd= a60db4aa7c593 100644 --- a/drivers/tty/serial/max310x.c +++ b/drivers/tty/serial/max310x.c @@ -547,7 +547,7 @@ static int max310x_set_baud(struct uart_port *port, int= baud) =20 static int max310x_update_best_err(unsigned int f, unsigned int *besterr) { - /* Use baudrate 115200 for calculate error */ + /* Use high-enough baudrate to calculate error */ unsigned int err =3D f % (460800 * 16); =20 if (*besterr > err) { --=20 2.47.3 From nobody Tue Jun 16 08:59:29 2026 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) (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 A4A52192D8A; Fri, 17 Apr 2026 14:53:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.243.120.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776437635; cv=none; b=hKyjmy97/GDyLny2kA8b5K5kl2znggw/LgijHP2/srO7MGFAmGsxZq2e7ZxgqB3zy81KDVHuj+w4LZfV4f6SG3lrP/thALeOcaxp/1j+KdhzSfdLo4+zgcUKi2Za0iwO5hUBxj8u3Kr/6VNX0ZBtg6zZVU21XrAkizazOc6zePg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776437635; c=relaxed/simple; bh=UNudewfjvyoV8ABjfnvOj20qV1TrUz1eiZ21jyqfUII=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=F+1DcjZerePys92dgy9Bbo0oNSlnMzsQc439c2WxzANHSSwUnSzbytYxiTaPbalCdEKqVL84/fr2ikrO46roQ9epHYj0kkXoa8f9PAD0UCBlvC05Tif7gMM3nUW2D9UNYNxXhhYSTpx+XiDRLJTYoiHJqemM25P04w2MnVHEDQw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com; spf=pass smtp.mailfrom=hugovil.com; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b=FzvQDmIX; arc=none smtp.client-ip=162.243.120.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hugovil.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b="FzvQDmIX" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=default; h=Cc:To:Message-Id:Content-Transfer-Encoding:MIME-Version: Subject:Date:From:subject:date:message-id:reply-to; bh=Sx0/zlAN75BLOsrNobfWggda/c+gvNYRx6rqXR8H2mc=; b=FzvQDmIXE5yNkRpuBuioaXTgLE EmgCmcR0NRxLA5vrDO0hnGeizWceolia3cbuA0r8cqzLHxPcZqTwhWoaUGtu5Ff9XY2BZ0yUyd9E8 oHUcQncpwxwSO39jKtoupsm/SOUjQ02NwhE2X2ocRrVx6CKgGZoWXY3p/29Ym4rzmRMU=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168] helo=pettiford.lan) by mail.hugovil.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wDkZm-000000006G1-0TqZ; Fri, 17 Apr 2026 10:53:46 -0400 From: Hugo Villeneuve Date: Fri, 17 Apr 2026 10:53:32 -0400 Subject: [PATCH 05/10] serial: max310x: improve max310x_set_ref_clk() efficiency Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260417-max310x-2-v1-5-b424e105ecac@dimonoff.com> References: <20260417-max310x-2-v1-0-b424e105ecac@dimonoff.com> In-Reply-To: <20260417-max310x-2-v1-0-b424e105ecac@dimonoff.com> To: Greg Kroah-Hartman , Jiri Slaby Cc: hugo@hugovil.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Hugo Villeneuve X-Mailer: b4 0.14.2 X-Spam_score: -1.0 X-Spam_bar: - From: Hugo Villeneuve The same basic code is duplicated for each of the four PLL multiplier values, so simplify and streamline it. Doing so allows us to avoid some unnecessary (fdiv * factor) multiplications for some fdiv values and replace the second "if" statement with an "else if" and avoid a useless comparison. Signed-off-by: Hugo Villeneuve --- drivers/tty/serial/max310x.c | 91 +++++++++++++++++++++++++---------------= ---- 1 file changed, 52 insertions(+), 39 deletions(-) diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c index f689958736f71b15b7c113214cda60db4aa7c593..1cd7632831a2826ddd42127b1cd= e2a10dfa412f0 100644 --- a/drivers/tty/serial/max310x.c +++ b/drivers/tty/serial/max310x.c @@ -258,6 +258,17 @@ #define MAX14830_BRGCFG_CLKDIS_BIT (1 << 6) /* Clock Disable */ #define MAX14830_REV_ID (0xb0) =20 +struct max310x_clk_config_t { + u8 prediv; /* Predivider */ + u8 pll_mult; /* PLL multiplier */ + unsigned int fref; /* + * Reference clock for fractional baud rate generator: + * PLL enabled: (freq / prediv) x pll_mult + * PLL disabled: freq + */ + unsigned int err; /* Computed error for selected parameters */ +}; + struct max310x_if_cfg { int (*extended_reg_enable)(struct device *dev, bool enable); u8 rev_id_offset; @@ -545,70 +556,72 @@ static int max310x_set_baud(struct uart_port *port, i= nt baud) return (16*port->uartclk) / (c*(16*div + frac)); } =20 -static int max310x_update_best_err(unsigned int f, unsigned int *besterr) +static void max310x_try_cfg(unsigned int fdiv, u8 div, u8 pll_mult, + struct max310x_clk_config_t *cfg) { + unsigned int fmul =3D fdiv * pll_mult; + unsigned int err; + /* Use high-enough baudrate to calculate error */ - unsigned int err =3D f % (460800 * 16); + err =3D fmul % (460800 * 16); =20 - if (*besterr > err) { - *besterr =3D err; - return 0; + if (cfg->err > err) { + cfg->err =3D err; + cfg->pll_mult =3D pll_mult; + cfg->prediv =3D div; + cfg->fref =3D fmul; } +} =20 - return 1; +static u8 max310x_pll_mult_to_id(u8 pll_mult) +{ + switch (pll_mult) { + case 144: return 3; + case 96: return 2; + case 48: return 1; + case 6: + default: return 0; + } } =20 static int max310x_set_ref_clk(struct device *dev, struct max310x_port *s, unsigned int freq, unsigned int *fref, bool xtal) { - unsigned int div, clksrc, pllcfg =3D 0; - unsigned int besterr =3D UINT_MAX; - unsigned int fdiv, fmul, bestfreq =3D freq; + unsigned int div, fdiv, clksrc; + struct max310x_clk_config_t cfg; + + cfg.err =3D UINT_MAX; + cfg.prediv =3D 0; + cfg.fref =3D freq; =20 /* First, update error without PLL */ - max310x_update_best_err(freq, &besterr); + max310x_try_cfg(freq, 1, 1, &cfg); =20 /* Try all possible PLL dividers */ - for (div =3D 1; (div <=3D 63) && besterr; div++) { + for (div =3D 1; (div <=3D 63) && cfg.err; div++) { fdiv =3D DIV_ROUND_CLOSEST(freq, div); =20 - /* Try multiplier 6 */ - fmul =3D fdiv * 6; if ((fdiv >=3D 500000) && (fdiv <=3D 800000)) - if (!max310x_update_best_err(fmul, &besterr)) { - pllcfg =3D (0 << 6) | div; - bestfreq =3D fmul; - } - /* Try multiplier 48 */ - fmul =3D fdiv * 48; - if ((fdiv >=3D 850000) && (fdiv <=3D 1200000)) - if (!max310x_update_best_err(fmul, &besterr)) { - pllcfg =3D (1 << 6) | div; - bestfreq =3D fmul; - } - /* Try multiplier 96 */ - fmul =3D fdiv * 96; + max310x_try_cfg(fdiv, div, 6, &cfg); /* PLL x6 */ + else if ((fdiv >=3D 850000) && (fdiv <=3D 1200000)) + max310x_try_cfg(fdiv, div, 48, &cfg); /* PLL x48 */ + if ((fdiv >=3D 425000) && (fdiv <=3D 1000000)) - if (!max310x_update_best_err(fmul, &besterr)) { - pllcfg =3D (2 << 6) | div; - bestfreq =3D fmul; - } - /* Try multiplier 144 */ - fmul =3D fdiv * 144; + max310x_try_cfg(fdiv, div, 96, &cfg); /* PLL x96 */ + if ((fdiv >=3D 390000) && (fdiv <=3D 667000)) - if (!max310x_update_best_err(fmul, &besterr)) { - pllcfg =3D (3 << 6) | div; - bestfreq =3D fmul; - } + max310x_try_cfg(fdiv, div, 144, &cfg); /* PLL x144 */ } =20 /* Configure clock source */ clksrc =3D MAX310X_CLKSRC_EXTCLK_BIT | (xtal ? MAX310X_CLKSRC_CRYST_BIT := 0); =20 /* Configure PLL */ - if (pllcfg) { + if (cfg.prediv) { + u8 pll_id =3D max310x_pll_mult_to_id(cfg.pll_mult); + clksrc |=3D MAX310X_CLKSRC_PLL_BIT; - regmap_write(s->regmap, MAX310X_PLLCFG_REG, pllcfg); + regmap_write(s->regmap, MAX310X_PLLCFG_REG, (pll_id << 6) | cfg.prediv); } else clksrc |=3D MAX310X_CLKSRC_PLLBYP_BIT; =20 @@ -632,7 +645,7 @@ static int max310x_set_ref_clk(struct device *dev, stru= ct max310x_port *s, "clock is not stable\n"); } =20 - *fref =3D bestfreq; + *fref =3D cfg.fref; =20 return 0; } --=20 2.47.3 From nobody Tue Jun 16 08:59:29 2026 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) (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 C81523368A6; Fri, 17 Apr 2026 14:53:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.243.120.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776437636; cv=none; b=qqFggkP9v2xK8zY59hv3ieN5Yn6ahH8J3HOgebOa4E5zA94FLBS25RCbezXyT0jy8Q3ldfDD0jgW9hIB8Aq/KXdZ6gkChxlEr2CrI/i1XvyIV5v8r4yzVAsdWYqBJgP1YEuatAAmmwP8dwbb4XQ+yVXKSYwHQYxzugWCoa+hzys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776437636; c=relaxed/simple; bh=+pIaZzAs214qq7wlqYLmJOyYlaKwAUslx+SMNpjIF34=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TqcUe423Fo1ekEoZPqLDvC2v2Umyl7AXSBIfeQpavI2EKnvn3vyW4oZpavXM1yp+j4zOU6uD8ySl/Yn5QgycnbxTHdR0mFjxxJr4uvr3W9WrT08RhHUeg9VoXboFxDytDQw2IV+Xvk4G7OdPnlb9R7iEm52n1b0xbqb4kWN6iMQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com; spf=pass smtp.mailfrom=hugovil.com; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b=Vu3Tx5bz; arc=none smtp.client-ip=162.243.120.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hugovil.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b="Vu3Tx5bz" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=default; h=Cc:To:Message-Id:Content-Transfer-Encoding:MIME-Version: Subject:Date:From:subject:date:message-id:reply-to; bh=dEidonsVfR94iviIc/z1aiRPexoSv2nJaBbs9rX+3KE=; b=Vu3Tx5bzoAHootUXl12wTzH56X WJG7gNfoo+pkT6ImfyU9KQ75Q/S44gvF4x7gh2c6ecUSV3s2AicvTcRyxNxWdwvrd5na/E93ESzUo MxRW+2Wt14krJdN5LW6P/E5+rqnBhwaAL4Nhrno1sk1GOKmBFIQBPO+v3WxO3ytihfeQ=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168] helo=pettiford.lan) by mail.hugovil.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wDkZm-000000006G1-3IHz; Fri, 17 Apr 2026 10:53:47 -0400 From: Hugo Villeneuve Date: Fri, 17 Apr 2026 10:53:33 -0400 Subject: [PATCH 06/10] serial: max310x: use regmap_read_poll_timeout() for busy wait Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260417-max310x-2-v1-6-b424e105ecac@dimonoff.com> References: <20260417-max310x-2-v1-0-b424e105ecac@dimonoff.com> In-Reply-To: <20260417-max310x-2-v1-0-b424e105ecac@dimonoff.com> To: Greg Kroah-Hartman , Jiri Slaby Cc: hugo@hugovil.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Hugo Villeneuve X-Mailer: b4 0.14.2 X-Spam_score: -1.0 X-Spam_bar: - From: Hugo Villeneuve Simplify busy wait stages by using regmap_read_poll_timeout(). Signed-off-by: Hugo Villeneuve --- Note that the "val" variable is move to the function scope in prevision for reuse by the next patch. --- drivers/tty/serial/max310x.c | 44 +++++++++++++++++-----------------------= ---- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c index 1cd7632831a2826ddd42127b1cde2a10dfa412f0..7ab5e4bd87ee6c87dd211bc52a3= a4eb169a2b202 100644 --- a/drivers/tty/serial/max310x.c +++ b/drivers/tty/serial/max310x.c @@ -241,12 +241,12 @@ #define MAX310X_WRITE_BIT 0x80 =20 /* Port startup definitions */ -#define MAX310X_PORT_STARTUP_WAIT_RETRIES 20 /* Number of retries */ -#define MAX310X_PORT_STARTUP_WAIT_DELAY_MS 10 /* Delay between retries */ +#define MAX310X_PORT_STARTUP_SLEEP_US 10000 /* Delay between retries */ +#define MAX310X_PORT_STARTUP_TIMEOUT_US (20 * MAX310X_PORT_STARTUP_SLEEP_U= S) /* Total timeout */ =20 /* Crystal-related definitions */ -#define MAX310X_XTAL_WAIT_RETRIES 20 /* Number of retries */ -#define MAX310X_XTAL_WAIT_DELAY_MS 10 /* Delay between retries */ +#define MAX310X_XTAL_SLEEP_US 10000 /* Delay between retries */ +#define MAX310X_XTAL_TIMEOUT_US (20 * MAX310X_XTAL_SLEEP_US) /* Total tim= eout */ =20 /* MAX3107 specific */ #define MAX3107_REV_ID (0xa0) @@ -587,7 +587,7 @@ static u8 max310x_pll_mult_to_id(u8 pll_mult) static int max310x_set_ref_clk(struct device *dev, struct max310x_port *s, unsigned int freq, unsigned int *fref, bool xtal) { - unsigned int div, fdiv, clksrc; + unsigned int div, fdiv, clksrc, val; struct max310x_clk_config_t cfg; =20 cfg.err =3D UINT_MAX; @@ -629,18 +629,13 @@ static int max310x_set_ref_clk(struct device *dev, st= ruct max310x_port *s, =20 /* Wait for crystal */ if (xtal) { - bool stable =3D false; - unsigned int try =3D 0, val =3D 0; + int ret; =20 - do { - msleep(MAX310X_XTAL_WAIT_DELAY_MS); - regmap_read(s->regmap, MAX310X_STS_IRQSTS_REG, &val); - - if (val & MAX310X_STS_CLKREADY_BIT) - stable =3D true; - } while (!stable && (++try < MAX310X_XTAL_WAIT_RETRIES)); - - if (!stable) + ret =3D regmap_read_poll_timeout(s->regmap, MAX310X_STS_IRQSTS_REG, + val, val & MAX310X_STS_CLKREADY_BIT, + MAX310X_XTAL_SLEEP_US, + MAX310X_XTAL_TIMEOUT_US); + if (ret) return dev_err_probe(dev, -EAGAIN, "clock is not stable\n"); } @@ -1346,8 +1341,7 @@ static int max310x_probe(struct device *dev, const st= ruct max310x_devtype *devty goto out_clk; =20 for (i =3D 0; i < devtype->nr; i++) { - bool started =3D false; - unsigned int try =3D 0, val =3D 0; + unsigned int val; =20 /* Reset port */ regmap_write(regmaps[i], MAX310X_MODE2_REG, @@ -1356,15 +1350,11 @@ static int max310x_probe(struct device *dev, const = struct max310x_devtype *devty regmap_write(regmaps[i], MAX310X_MODE2_REG, 0); =20 /* Wait for port startup */ - do { - msleep(MAX310X_PORT_STARTUP_WAIT_DELAY_MS); - regmap_read(regmaps[i], MAX310X_BRGDIVLSB_REG, &val); - - if (val =3D=3D 0x01) - started =3D true; - } while (!started && (++try < MAX310X_PORT_STARTUP_WAIT_RETRIES)); - - if (!started) { + ret =3D regmap_read_poll_timeout(regmaps[i], MAX310X_BRGDIVLSB_REG, + val, val =3D=3D 0x01, + MAX310X_PORT_STARTUP_SLEEP_US, + MAX310X_PORT_STARTUP_TIMEOUT_US); + if (ret) { ret =3D dev_err_probe(dev, -EAGAIN, "port reset failed\n"); goto out_uart; } --=20 2.47.3 From nobody Tue Jun 16 08:59:29 2026 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) (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 D7A11343D64; Fri, 17 Apr 2026 14:53:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.243.120.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776437635; cv=none; b=JIvQyZK/cHOidjPQ5tlxfNF9Z2za/te3Wkghlad8iBy1e28JXr4LCjW1mLUdJXeksnqRfRxXvii1d/nbtgMaJoTuO68lJayyJvy+duXOhN21LPI1UqtpqFGoGrDGdAK3gtQdKSKQ6U+k+oykVD50Q5yA+LZbwqmE/TcPRPMUeqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776437635; c=relaxed/simple; bh=fJGl8rTHcD0lYeArsdepEP62C/lB3VZQGfCqwCoSL2k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UoMtmLBe5Zr/W7PCw48A4BaJ4ifNieAhGTkXNZ55KZG6kzjS98m4e76R0O0gR7x0ssreYvIqwtoA1LAg2HugJ+H3aw658B7sza+LsNB9p6FvxaDifMm3HZEHd1yARu5LhYLGJ2VSTo2Sr0VYd4nfIZ++u6RjqFZNkK9f4sPlUCM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com; spf=pass smtp.mailfrom=hugovil.com; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b=L4OWErt2; arc=none smtp.client-ip=162.243.120.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hugovil.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b="L4OWErt2" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=default; h=Cc:To:Message-Id:Content-Transfer-Encoding:MIME-Version: Subject:Date:From:subject:date:message-id:reply-to; bh=LLJbvgMZ7HRJjKFqcc755Hb791ZghHSrxSCXtUi5C+I=; b=L4OWErt23Uwrr2RANq+R0dYqdN H74WB8Hgndc8MaHtwfRVB96HNZYQ0sKYgxs4sKVby4O8PH3czs3AN/hCCeCo3KWUhLBX8a9BsvYC1 LEacCVXxGzkLcWUXGwtHalLFPtlokhOrIQS9D8NfWOy1YHcPsE+Vm8qo98Gll1rJ9JoE=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168] helo=pettiford.lan) by mail.hugovil.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wDkZn-000000006G1-1RYn; Fri, 17 Apr 2026 10:53:47 -0400 From: Hugo Villeneuve Date: Fri, 17 Apr 2026 10:53:34 -0400 Subject: [PATCH 07/10] serial: max310x: use FIELD_PREP macro to set PLL bitfields Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260417-max310x-2-v1-7-b424e105ecac@dimonoff.com> References: <20260417-max310x-2-v1-0-b424e105ecac@dimonoff.com> In-Reply-To: <20260417-max310x-2-v1-0-b424e105ecac@dimonoff.com> To: Greg Kroah-Hartman , Jiri Slaby Cc: hugo@hugovil.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Hugo Villeneuve X-Mailer: b4 0.14.2 X-Spam_score: -1.0 X-Spam_bar: - From: Hugo Villeneuve Use FIELD_PREP macros to improve code readability. Signed-off-by: Hugo Villeneuve --- drivers/tty/serial/max310x.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c index 7ab5e4bd87ee6c87dd211bc52a3a4eb169a2b202..b4449b68cfeee07d1d6d3206cf5= 8f72fac00044e 100644 --- a/drivers/tty/serial/max310x.c +++ b/drivers/tty/serial/max310x.c @@ -9,6 +9,7 @@ * Based on max3107.c, by Aavamobile */ =20 +#include #include #include #include @@ -621,7 +622,9 @@ static int max310x_set_ref_clk(struct device *dev, stru= ct max310x_port *s, u8 pll_id =3D max310x_pll_mult_to_id(cfg.pll_mult); =20 clksrc |=3D MAX310X_CLKSRC_PLL_BIT; - regmap_write(s->regmap, MAX310X_PLLCFG_REG, (pll_id << 6) | cfg.prediv); + val =3D FIELD_PREP(MAX310X_PLLCFG_PLLFACTOR_MASK, pll_id) | + FIELD_PREP(MAX310X_PLLCFG_PREDIV_MASK, cfg.prediv); + regmap_write(s->regmap, MAX310X_PLLCFG_REG, val); } else clksrc |=3D MAX310X_CLKSRC_PLLBYP_BIT; =20 --=20 2.47.3 From nobody Tue Jun 16 08:59:29 2026 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) (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 07D87311C1B; Fri, 17 Apr 2026 14:53:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.243.120.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776437636; cv=none; b=RgKW9Au3UY9sFg5nf59/BKNpW2QBkgwyceq5O6QiB/VI0J6M95Yx2bFI2mQMUyMVATJa6p0TGv51+P8Q/OG1rOnB377NzRmpBYRFphZJhkzsyFDMmiQWMeknPkDKSD0+rJlX3GEBWdC5mKp8Rti8e/dhJw0h16s6tSrvijm/Ssc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776437636; c=relaxed/simple; bh=kY7UuLOXJqNHhd8TlOjTgCVHd7nQGl5XJeQ3F2Wz8X4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=khkJzhuR9UWL8VT5+JIIN6NNYfNaPuAeQHqi8sYKwl0OrOMG7Oi7sjnq7rdygWFy9PLqurEWxAjHJpEDaAdtE/88zPgEj1QJkD+LHqEpTB52TH1l1+lXp4qRyv2F9ibYDYG1QmZz0osWc1xlS/4kFxEU0k07Fw66UquS1AyGhY4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com; spf=pass smtp.mailfrom=hugovil.com; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b=PeFHkOJf; arc=none smtp.client-ip=162.243.120.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hugovil.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b="PeFHkOJf" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=default; h=Cc:To:Message-Id:Content-Transfer-Encoding:MIME-Version: Subject:Date:From:subject:date:message-id:reply-to; bh=9tic9WMN1uLlZw0Uqah/+Q0/FRTkYJROicLvqRMAgU0=; b=PeFHkOJfUjDmLmTyVOHSDU9KHZ g9CRGaOXuix/bdbqitu/MYKBVLIQ1dTkijuU/ygtggouzgdRrYCdnuVeA4VBqFyQxU2aQAK8mnPAs oNk8RxsNlMY/6NZe1KN5UHkA/2GUJAX4XEbpgse28IBhJ9BwIl1hjaXjVG7NOf4ZBg6I=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168] helo=pettiford.lan) by mail.hugovil.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wDkZn-000000006G1-3Ow7; Fri, 17 Apr 2026 10:53:48 -0400 From: Hugo Villeneuve Date: Fri, 17 Apr 2026 10:53:35 -0400 Subject: [PATCH 08/10] serial: max310x: allow driver to be built with SPI or I2C Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260417-max310x-2-v1-8-b424e105ecac@dimonoff.com> References: <20260417-max310x-2-v1-0-b424e105ecac@dimonoff.com> In-Reply-To: <20260417-max310x-2-v1-0-b424e105ecac@dimonoff.com> To: Greg Kroah-Hartman , Jiri Slaby Cc: hugo@hugovil.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Hugo Villeneuve X-Mailer: b4 0.14.2 X-Spam_score: -1.0 X-Spam_bar: - From: Hugo Villeneuve If SPI is disabled, the max310x driver cannot be selected. Allow driver to be selected if either I2C or SPI is set. Signed-off-by: Hugo Villeneuve --- drivers/tty/serial/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig index 9aa61c93d7bc6d164b9c493f140477b793ca8afe..296fa20340bd59196f7d1394687= edac10fc73adf 100644 --- a/drivers/tty/serial/Kconfig +++ b/drivers/tty/serial/Kconfig @@ -321,7 +321,7 @@ config SERIAL_MAX3100 =20 config SERIAL_MAX310X tristate "MAX310X support" - depends on SPI_MASTER + depends on SPI_MASTER || I2C select SERIAL_CORE select REGMAP_SPI if SPI_MASTER select REGMAP_I2C if I2C --=20 2.47.3 From nobody Tue Jun 16 08:59:29 2026 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) (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 B90DA3C1980; Fri, 17 Apr 2026 14:53:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.243.120.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776437637; cv=none; b=I2xnmJ5yEO9HBWR7jQU6vjr5BFpMa+dLq5WFv7ChKnqS7naPtbEz6dHrmcCQP0S9Z9zORnGXGYrxad/NQBobPhPBU1+VWExwQwz2BnpKYsUJEurA35GUASc6DjNs2cJARLSXcG7At7nxdYGFoFaJiDjHHBtQrCdd94ktWCeOeUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776437637; c=relaxed/simple; bh=AheMHbjZxMZt3qjVkcx+GhSx9S6San+RLOlqhYvndYc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=grpf/C07hw8k7Co/ebAJvBEfp+7XmwaJv5g74R65//2uYDktdjgMqFmGOFjjsSapyS4pwlAoE58fTz61nvFGaUsI5w8lTBCwUo4gYC4sfvVo+nINYCWmfeDZfAAQp6N6Lph+SIsBzik/9c1yJ3wjgOz96usIjV4ynFY1q9Ahbsc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com; spf=pass smtp.mailfrom=hugovil.com; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b=kmvERybo; arc=none smtp.client-ip=162.243.120.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hugovil.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b="kmvERybo" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=default; h=Cc:To:Message-Id:Content-Transfer-Encoding:MIME-Version: Subject:Date:From:subject:date:message-id:reply-to; bh=cduXsqdP4aet+jHHPTocIt514wp7jfm/O8IjyOrGA3E=; b=kmvERybo5E3A/8ysZDATm49reu W69QY0imU16IcOuWJFMhtk/mBYxIegoTVEJc110CSUH7NB2UiM/W25E7TqhtYq26Fx4SWcVHq/d3M uUPK6XfIMJebyJxpo/nLbmZwgVCz1EfIitxW0rI4B1hKpXrfKyRd1r9ABX47kzIhgyEk=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168] helo=pettiford.lan) by mail.hugovil.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wDkZo-000000006G1-21ZE; Fri, 17 Apr 2026 10:53:49 -0400 From: Hugo Villeneuve Date: Fri, 17 Apr 2026 10:53:36 -0400 Subject: [PATCH 09/10] serial: max310x: move variables to while() scope Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260417-max310x-2-v1-9-b424e105ecac@dimonoff.com> References: <20260417-max310x-2-v1-0-b424e105ecac@dimonoff.com> In-Reply-To: <20260417-max310x-2-v1-0-b424e105ecac@dimonoff.com> To: Greg Kroah-Hartman , Jiri Slaby Cc: hugo@hugovil.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Hugo Villeneuve X-Mailer: b4 0.14.2 X-Spam_score: -1.0 X-Spam_bar: - From: Hugo Villeneuve txlen, to_send and tail variables are only used within the while() loop. Move them to that scope to keep them closer to their usage and improve readability. Signed-off-by: Hugo Villeneuve --- drivers/tty/serial/max310x.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c index b4449b68cfeee07d1d6d3206cf58f72fac00044e..748306d1a9329694e90ec4f096d= d00e39d457fda 100644 --- a/drivers/tty/serial/max310x.c +++ b/drivers/tty/serial/max310x.c @@ -761,8 +761,6 @@ static void max310x_handle_rx(struct uart_port *port, u= nsigned int rxlen) static void max310x_handle_tx(struct uart_port *port) { struct tty_port *tport =3D &port->state->port; - unsigned int txlen, to_send; - unsigned char *tail; =20 if (unlikely(port->x_char)) { max310x_port_write(port, MAX310X_THR_REG, port->x_char); @@ -779,6 +777,9 @@ static void max310x_handle_tx(struct uart_port *port) * We could do that in one SPI transaction, but meh. */ while (!kfifo_is_empty(&tport->xmit_fifo)) { + unsigned int txlen, to_send; + unsigned char *tail; + /* Limit to space available in TX FIFO */ txlen =3D max310x_port_read(port, MAX310X_TXFIFOLVL_REG); txlen =3D port->fifosize - txlen; --=20 2.47.3 From nobody Tue Jun 16 08:59:29 2026 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) (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 939063C3BFE; Fri, 17 Apr 2026 14:53:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.243.120.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776437637; cv=none; b=ugXDg/49Leu8PYTauxFEEPsGHGr88z+4vIGj0AdkzpxhFscDf94VtlC29pVlV1cRhyNuGhWabHYf1Gc9pUbK2/udRzU02/jJXEAFh6Nop12hkieF2jBjTJt/K68C1pBmSuLOZ0EzttywPd6DZCypwZy8H3q007KkOdDQNRG47Ow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776437637; c=relaxed/simple; bh=wObiIqMcNdEQXV7Hzzt0v2+CpCLKuq8rheKiJxg2LvE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nOTcVIH2ZpsanN0wZl8Ip6NkiLWKARWr+FONn04t0SpoLQBd67u8fD0dk2vd7eBpgQDetFmdSnJFVkDs3OQHEKxd7HOVDUKWODF4vq+m/kzp4rpwLz+VXqyZKCxFKfbBGjrkHJu+9Qo1BLysOzNjQfJ+fuSZPn2EvhGb6Uli93U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com; spf=pass smtp.mailfrom=hugovil.com; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b=W/q5dedm; arc=none smtp.client-ip=162.243.120.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=hugovil.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hugovil.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=hugovil.com header.i=@hugovil.com header.b="W/q5dedm" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=default; h=Cc:To:Message-Id:Content-Transfer-Encoding:MIME-Version: Subject:Date:From:subject:date:message-id:reply-to; bh=NsW39ciRTFfIB9gxo/s0Uk0V/Zf9zf+Ew3TDN23WMC0=; b=W/q5dedmtFfnBix+1DDxdsMtIx XvxRnEaHuoaPpidLVlT0zbtrlv2r2iBLPQBuXU6H96Yy6L+EuEYswIINBJRaD2IbbnE8sDz6ixsAI 9ukQHgm41VBtcgEyv9ktL9mRc4bIM2IUAphttyLRSU6f0hglBS/CEjAVvk5ZbOmLL35w=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168] helo=pettiford.lan) by mail.hugovil.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wDkZp-000000006G1-15aM; Fri, 17 Apr 2026 10:53:50 -0400 From: Hugo Villeneuve Date: Fri, 17 Apr 2026 10:53:37 -0400 Subject: [PATCH 10/10] serial: max310x: add comments for PLL limits Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260417-max310x-2-v1-10-b424e105ecac@dimonoff.com> References: <20260417-max310x-2-v1-0-b424e105ecac@dimonoff.com> In-Reply-To: <20260417-max310x-2-v1-0-b424e105ecac@dimonoff.com> To: Greg Kroah-Hartman , Jiri Slaby Cc: hugo@hugovil.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Hugo Villeneuve X-Mailer: b4 0.14.2 X-Spam_score: -1.0 X-Spam_bar: - From: Hugo Villeneuve Add comments to help clarify the provenance of the various hardcoded values used in computing the ref clk. Assisted-by: Gemini:Pro Signed-off-by: Hugo Villeneuve --- drivers/tty/serial/max310x.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c index 748306d1a9329694e90ec4f096dd00e39d457fda..9f423b3b4201d0db07bbd7b1593= 4db36249e7620 100644 --- a/drivers/tty/serial/max310x.c +++ b/drivers/tty/serial/max310x.c @@ -585,6 +585,23 @@ static u8 max310x_pll_mult_to_id(u8 pll_mult) } } =20 +/* + * From table 7 in datasheet: PLLFactor Selector Guide + * + * +-----------+----------------+-------------------+-------------------+ + * | PLLFactor | MULTIPLICATION | fPLLIN | fREF | + * | (1 & 0) | FACTOR +---------+---------+---------+---------+ + * | | | MIN | MAX | MIN | MAX | + * +-----------+----------------+---------+---------+---------+---------+ + * | 0 | 6 | 500kHz | 800kHz | 3MHz | 4.8MHz | + * +-----------+----------------+---------+---------+---------+---------+ + * | 1 | 48 | 850kHz | 1.2MHz | 40.8MHz | 56MHz | + * +-----------+----------------+---------+---------+---------+---------+ + * | 2 | 96 | 425kHz | 1MHz | 40.8MHz | 96MHz | + * +-----------+----------------+---------+---------+---------+---------+ + * | 3 | 144 | 390kHz | 667kHz | 56MHz | 96MHz | + * +-----------+----------------+---------+---------+---------+---------+ + */ static int max310x_set_ref_clk(struct device *dev, struct max310x_port *s, unsigned int freq, unsigned int *fref, bool xtal) { --=20 2.47.3