Message ID | 20221115162654.2016820-1-frieder@fris.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2823090wru; Tue, 15 Nov 2022 08:27:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf6FNnJxP4JE6cRQWM2xwNGJyjcGGVTZ+EEaiR6mFzKgN6T6aGUi52odRkC+p1jectURU4B2 X-Received: by 2002:a17:90b:3c11:b0:218:8f2:5af9 with SMTP id pb17-20020a17090b3c1100b0021808f25af9mr1312850pjb.65.1668529662200; Tue, 15 Nov 2022 08:27:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668529662; cv=none; d=google.com; s=arc-20160816; b=TCyWUaPwGg6V34yqSDU+YYdld7uOZbQk7e+JWzsw+af7tmCoheV0yh0SA3zczvXdmk MPXTaweZ/O6334Ri1n/V5Jw6hKL9xbdFZ1bEg11hWQCYKgi8X6eGaTmLmHTwh4NqQuBV 9KWGl2rCHBhDsGn6+zY7vZzP/9jXGVJ4W1iPwJszBXSxOyKcRbOFeiVnH+umjtmE+mQr E0nJqQLWgKcKqWL6t2rynxe4youOJkOZR4caUPAwSO79h5jKP9/kkM1KFumGAv0VKIRr iy7fkPh1bNa5pD0nR9ubMe8iGN7D4Zr3F9+ApPto4jsZP679rJHRh9ELGAyW4IVhMm03 Vhfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=5tgKf+p7vookHNtY0coTIkhFiTMT/dbT9kfNLD5BJEk=; b=fILNle9xBTYY1Y+MgrsUtRnmzPTgTdCdE4C0Qt7JQBYWNcYunxZTD5dOWAwGBWzXUh gqOGPypTjto7e5Ck59F4V6yJebXqYlv81sofGijnHFGkgOXlkt7bCgvWpzzucTKq3JAa RmLUiguCoR9e1/bHXxO3omywHeT/1nQB8m4rZbJhZS7KUKqdrGghNM4SptFZvJ0NZnN8 2c9Pj8E5GmoX9DtFEkgvzbJUvpIwveFnTCBnQnAVzD/fPxNi9xh8HSFodzVu3DWqJX2s jgne2jNas3xAasfPtn7+SF0EEaVmmFPKQvWdcNBEdGbtaq+kIN0JXzUA7zdtyB51B/pk 4/Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fris.de header.s=dkim header.b=PuDasNOC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=fris.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pc5-20020a17090b3b8500b0021406fde039si15112423pjb.156.2022.11.15.08.27.28; Tue, 15 Nov 2022 08:27:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@fris.de header.s=dkim header.b=PuDasNOC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=fris.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238651AbiKOQ1P (ORCPT <rfc822;maxim.cournoyer@gmail.com> + 99 others); Tue, 15 Nov 2022 11:27:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238692AbiKOQ1G (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 15 Nov 2022 11:27:06 -0500 Received: from mail.fris.de (mail.fris.de [116.203.77.234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68A292496D; Tue, 15 Nov 2022 08:27:05 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id BF9FBBFB36; Tue, 15 Nov 2022 17:26:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fris.de; s=dkim; t=1668529622; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding; bh=5tgKf+p7vookHNtY0coTIkhFiTMT/dbT9kfNLD5BJEk=; b=PuDasNOCxilEj2ZLt3Ng3PC9aw+m7AzQ5cN0UluxpTopBj4tpJTrnYEtTnC18ZtKpG3dpz LCKfShB4UHon957EwvINZUg4loKUD4fakqlFhGLIldq0yqwfkjXIUQqG96H4SQGz9VEbxJ Yi+TObf5Pr937nCfotNQXd3wjiIr1+PZ0f38G/9rDspqwhTbKaCb/5zlnZ/dFA8TPmFilH ZyI/17zlxT2M2xE2ADHgQfYobclQt9qbF0CQDEeyowEo4I8VHp4rSzM3YEHUUyuJCFhAkA Abg649ddL6Y3JRkoGlbYxqRl6tW7cu/QRl6VEWOb6V8Xbzz642tPBpofZqxTwQ== From: Frieder Schrempf <frieder@fris.de> To: David Jander <david@protonic.nl>, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org, Marc Kleine-Budde <mkl@pengutronix.de>, Mark Brown <broonie@kernel.org>, Sascha Hauer <s.hauer@pengutronix.de>, Shawn Guo <shawnguo@kernel.org> Cc: Frieder Schrempf <frieder.schrempf@kontron.de>, Fabio Estevam <festevam@gmail.com>, Marek Vasut <marex@denx.de>, stable@vger.kernel.org, Baruch Siach <baruch.siach@siklu.com>, Minghao Chi <chi.minghao@zte.com.cn>, NXP Linux Team <linux-imx@nxp.com>, Pengutronix Kernel Team <kernel@pengutronix.de> Subject: [PATCH v2] spi: spi-imx: Fix spi_bus_clk if requested clock is higher than input clock Date: Tue, 15 Nov 2022 17:26:53 +0100 Message-Id: <20221115162654.2016820-1-frieder@fris.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Last-TLS-Session-Version: TLSv1.3 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749580042804360663?= X-GMAIL-MSGID: =?utf-8?q?1749580159208773474?= |
Series |
[v2] spi: spi-imx: Fix spi_bus_clk if requested clock is higher than input clock
|
|
Commit Message
Frieder Schrempf
Nov. 15, 2022, 4:26 p.m. UTC
From: Frieder Schrempf <frieder.schrempf@kontron.de> In case the requested bus clock is higher than the input clock, the correct dividers (pre = 0, post = 0) are returned from mx51_ecspi_clkdiv(), but *fres is left uninitialized and therefore contains an arbitrary value. This causes trouble for the recently introduced PIO polling feature as the value in spi_imx->spi_bus_clk is used there to calculate for which transfers to enable PIO polling. Fix this by setting *fres even if no clock dividers are in use. This issue was observed on Kontron BL i.MX8MM with an SPI peripheral clock set to 50 MHz by default and a requested SPI bus clock of 80 MHz for the SPI NOR flash. With the fix applied the debug message from mx51_ecspi_clkdiv() now prints the following: spi_imx 30820000.spi: mx51_ecspi_clkdiv: fin: 50000000, fspi: 50000000, post: 0, pre: 0 Fixes: 07e759387788 ("spi: spi-imx: add PIO polling support") Cc: Marc Kleine-Budde <mkl@pengutronix.de> Cc: David Jander <david@protonic.nl> Cc: Fabio Estevam <festevam@gmail.com> Cc: Mark Brown <broonie@kernel.org> Cc: Marek Vasut <marex@denx.de> Cc: stable@vger.kernel.org Signed-off-by: Frieder Schrempf <frieder.schrempf@kontron.de> --- Changes for v2: * Remove the reference and the Fixes tag for commit 6fd8b8503a0d as it is incorrect. --- drivers/spi/spi-imx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Comments
On 15.11.2022 17:26:53, Frieder Schrempf wrote: > From: Frieder Schrempf <frieder.schrempf@kontron.de> > > In case the requested bus clock is higher than the input clock, the correct > dividers (pre = 0, post = 0) are returned from mx51_ecspi_clkdiv(), but > *fres is left uninitialized and therefore contains an arbitrary value. > > This causes trouble for the recently introduced PIO polling feature as the > value in spi_imx->spi_bus_clk is used there to calculate for which > transfers to enable PIO polling. > > Fix this by setting *fres even if no clock dividers are in use. > > This issue was observed on Kontron BL i.MX8MM with an SPI peripheral clock set > to 50 MHz by default and a requested SPI bus clock of 80 MHz for the SPI NOR > flash. > > With the fix applied the debug message from mx51_ecspi_clkdiv() now prints the > following: > > spi_imx 30820000.spi: mx51_ecspi_clkdiv: fin: 50000000, fspi: 50000000, > post: 0, pre: 0 > > Fixes: 07e759387788 ("spi: spi-imx: add PIO polling support") The *fres parameter was introduced in: | Fixes: 6fd8b8503a0d ("spi: spi-imx: Fix out-of-order CS/SCLK operation at low speeds") The exiting code: | if (unlikely(fspi > fin)) | return 0; was not sufficient any more and should be fixed. Marc
On 15.11.22 17:54, Marc Kleine-Budde wrote: > On 15.11.2022 17:26:53, Frieder Schrempf wrote: >> From: Frieder Schrempf <frieder.schrempf@kontron.de> >> >> In case the requested bus clock is higher than the input clock, the correct >> dividers (pre = 0, post = 0) are returned from mx51_ecspi_clkdiv(), but >> *fres is left uninitialized and therefore contains an arbitrary value. >> >> This causes trouble for the recently introduced PIO polling feature as the >> value in spi_imx->spi_bus_clk is used there to calculate for which >> transfers to enable PIO polling. >> >> Fix this by setting *fres even if no clock dividers are in use. >> >> This issue was observed on Kontron BL i.MX8MM with an SPI peripheral clock set >> to 50 MHz by default and a requested SPI bus clock of 80 MHz for the SPI NOR >> flash. >> >> With the fix applied the debug message from mx51_ecspi_clkdiv() now prints the >> following: >> >> spi_imx 30820000.spi: mx51_ecspi_clkdiv: fin: 50000000, fspi: 50000000, >> post: 0, pre: 0 >> >> Fixes: 07e759387788 ("spi: spi-imx: add PIO polling support") You want me to remove this tag? > The *fres parameter was introduced in: > > | Fixes: 6fd8b8503a0d ("spi: spi-imx: Fix out-of-order CS/SCLK operation at low speeds") and instead add back this tag? I wasn't really sure about that. > > The exiting code: > > | if (unlikely(fspi > fin)) > | return 0; > > was not sufficient any more and should be fixed. You want me to add this in the description? Or is this just the explanation for why 6fd8b8503a0d should be in the Fixes tag?
On Tue, Nov 15, 2022 at 1:27 PM Frieder Schrempf <frieder@fris.de> wrote: > > From: Frieder Schrempf <frieder.schrempf@kontron.de> > > In case the requested bus clock is higher than the input clock, the correct > dividers (pre = 0, post = 0) are returned from mx51_ecspi_clkdiv(), but > *fres is left uninitialized and therefore contains an arbitrary value. > > This causes trouble for the recently introduced PIO polling feature as the > value in spi_imx->spi_bus_clk is used there to calculate for which > transfers to enable PIO polling. > > Fix this by setting *fres even if no clock dividers are in use. > > This issue was observed on Kontron BL i.MX8MM with an SPI peripheral clock set > to 50 MHz by default and a requested SPI bus clock of 80 MHz for the SPI NOR > flash. > > With the fix applied the debug message from mx51_ecspi_clkdiv() now prints the > following: > > spi_imx 30820000.spi: mx51_ecspi_clkdiv: fin: 50000000, fspi: 50000000, > post: 0, pre: 0 > > Fixes: 07e759387788 ("spi: spi-imx: add PIO polling support") > Cc: Marc Kleine-Budde <mkl@pengutronix.de> > Cc: David Jander <david@protonic.nl> > Cc: Fabio Estevam <festevam@gmail.com> > Cc: Mark Brown <broonie@kernel.org> > Cc: Marek Vasut <marex@denx.de> > Cc: stable@vger.kernel.org > Signed-off-by: Frieder Schrempf <frieder.schrempf@kontron.de> Thanks for the fix: Tested-by: Fabio Estevam <festevam@gmail.com>
On 15.11.2022 18:14:38, Frieder Schrempf wrote: > On 15.11.22 17:54, Marc Kleine-Budde wrote: > > On 15.11.2022 17:26:53, Frieder Schrempf wrote: > >> From: Frieder Schrempf <frieder.schrempf@kontron.de> > >> > >> In case the requested bus clock is higher than the input clock, the correct > >> dividers (pre = 0, post = 0) are returned from mx51_ecspi_clkdiv(), but > >> *fres is left uninitialized and therefore contains an arbitrary value. > >> > >> This causes trouble for the recently introduced PIO polling feature as the > >> value in spi_imx->spi_bus_clk is used there to calculate for which > >> transfers to enable PIO polling. > >> > >> Fix this by setting *fres even if no clock dividers are in use. > >> > >> This issue was observed on Kontron BL i.MX8MM with an SPI peripheral clock set > >> to 50 MHz by default and a requested SPI bus clock of 80 MHz for the SPI NOR > >> flash. > >> > >> With the fix applied the debug message from mx51_ecspi_clkdiv() now prints the > >> following: > >> > >> spi_imx 30820000.spi: mx51_ecspi_clkdiv: fin: 50000000, fspi: 50000000, > >> post: 0, pre: 0 > >> > >> Fixes: 07e759387788 ("spi: spi-imx: add PIO polling support") > > You want me to remove this tag? > > > The *fres parameter was introduced in: > > > > | Fixes: 6fd8b8503a0d ("spi: spi-imx: Fix out-of-order CS/SCLK operation at low speeds") > > and instead add back this tag? I wasn't really sure about that. Keep both. > > > > The exiting code: > > > > | if (unlikely(fspi > fin)) > > | return 0; > > > > was not sufficient any more and should be fixed. > > You want me to add this in the description? Or is this just the > explanation for why 6fd8b8503a0d should be in the Fixes tag? No need to add the explanation to the patch. Marc
diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c index 30d82cc7300b..468ce0a2b282 100644 --- a/drivers/spi/spi-imx.c +++ b/drivers/spi/spi-imx.c @@ -444,8 +444,7 @@ static unsigned int mx51_ecspi_clkdiv(struct spi_imx_data *spi_imx, unsigned int pre, post; unsigned int fin = spi_imx->spi_clk; - if (unlikely(fspi > fin)) - return 0; + fspi = min(fspi, fin); post = fls(fin) - fls(fspi); if (fin > fspi << post)