Message ID | 20221115181002.2068270-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 l7csp2876093wru; Tue, 15 Nov 2022 10:18:09 -0800 (PST) X-Google-Smtp-Source: AA0mqf5uAcDubLJzDfWaKyaoTxc1GFHA0RPLs/GqFbuxLT2xtMCRF8D9unitoE/Cw8H4yrSQ/yvr X-Received: by 2002:a17:90a:aa16:b0:205:fa0b:798c with SMTP id k22-20020a17090aaa1600b00205fa0b798cmr1674169pjq.179.1668536288326; Tue, 15 Nov 2022 10:18:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668536288; cv=none; d=google.com; s=arc-20160816; b=Hs1baUm+0EdLOmbpcXT0vl4LNq42ls0S3anKXXnDBtksPQhlkHGjDlIRY/Q+h9FZS5 spUyCBqJ7/Npu0tj1HGp0k2Rrnkd/6Kls4LHLInb6X3yN2KZENKTMtf4K6Ar5s2p+ziV KKPUQqUhPrNkq2Q04KwKJ2rieMuAuY7xQCFTJaZVEYbHCz8XtD+plsVGmYdLLBhNrmF/ VgsX+90yGz01moGDUbRrI+RLFM6NFxOUYsyfnS+7QKYbp86OsAdPwG56A0OGjElgZ7gd fqJUdTPqWlmmVUQEGIHa3WwlQthobC50pYewSt6bFt2oPsTdYjGcfhehmCsxPdTaRH5N y2Kg== 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=H45maZABLXregYfqLWfeajAgJSlwlOq3Okec5GHiVqQ=; b=ycn+lnpvqbShNjz1YnbgIuBZM1FkewoVFzaQb/4enk9pDPYJU4zqXJKOchGHjFGbpV W8BXIDsFth4NCMm8PkGaBOZx2XKDcfWNSsEyakJPDaNKXTmlOtxkv7/kfW3l31ysTLok EnsUxnt9xjOeFdbAF+sYmU3lA5afS/EJwa83xDsoc+92NEts5bOloEzQw0NrONGq2GLd b4elgntf0XNoo+k568B9CN84I3xZrDdjxj6SktxcOSdih635/OW2hdhuIaIEy/dXEkH1 3ZnciOWM3Qr6zCI0yNcVvH7u8N316fMyBPpml5094KPG6YuX2d9yh00/dg486YR27tZx +4ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fris.de header.s=dkim header.b="tQX//QtZ"; 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 w9-20020a170902d70900b0017a8a84a3b6si10824505ply.106.2022.11.15.10.17.53; Tue, 15 Nov 2022 10:18:08 -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="tQX//QtZ"; 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 S230129AbiKOSK3 (ORCPT <rfc822;maxim.cournoyer@gmail.com> + 99 others); Tue, 15 Nov 2022 13:10:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232489AbiKOSKV (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 15 Nov 2022 13:10:21 -0500 X-Greylist: delayed 6968 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 15 Nov 2022 10:10:16 PST Received: from mail.fris.de (mail.fris.de [IPv6:2a01:4f8:c2c:390b::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E014D23E89; Tue, 15 Nov 2022 10:10:16 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 48EBBBFAAB; Tue, 15 Nov 2022 19:10:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fris.de; s=dkim; t=1668535814; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding; bh=H45maZABLXregYfqLWfeajAgJSlwlOq3Okec5GHiVqQ=; b=tQX//QtZ+IrdGz7dRr777MgmC/yKvVgO1bgw+PhI6TvciqiL06D05PgqRuSVYEAQ9nY89p nV4jT3M4ZoDCcxk9wMiOftdlWn/yDqooGK21N8JE8jQz5G3NSfhsRUf05v7RNN56hK6cfW ZkjrkgnvXNl8vNvsayySjmtuI0tECvLiR4RYInUf7b2FZvnK6rlaxAKcwQ1YZE6IIdVqma lJqkcnKxhx6cmlKT1PJ79OnjAASZtEsViftUEos5kMYezQ+XyEHwG1Gs2fQPPGaLgqX9UF xve9YsRTePL4qOdf5CoUXJTn2Doz4QLtcMTcHp+FeWkrBQGSWd82sOi2iG/eQA== 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>, Marek Vasut <marex@denx.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>, 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 v3] spi: spi-imx: Fix spi_bus_clk if requested clock is higher than input clock Date: Tue, 15 Nov 2022 19:10:00 +0100 Message-Id: <20221115181002.2068270-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?1749587107475269472?= X-GMAIL-MSGID: =?utf-8?q?1749587107475269472?= |
Series |
[v3] spi: spi-imx: Fix spi_bus_clk if requested clock is higher than input clock
|
|
Commit Message
Frieder Schrempf
Nov. 15, 2022, 6:10 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: 6fd8b8503a0d ("spi: spi-imx: Fix out-of-order CS/SCLK operation at low speeds") 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> Tested-by: Fabio Estevam <festevam@gmail.com> --- Changes for v3: * Add back the Fixes tag for commit 6fd8b8503a0d * Add Fabio's Tested-by (Thanks!) 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 11/15/22 19:10, 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: 6fd8b8503a0d ("spi: spi-imx: Fix out-of-order CS/SCLK operation at low speeds") > 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> > Tested-by: Fabio Estevam <festevam@gmail.com> > --- > > Changes for v3: > > * Add back the Fixes tag for commit 6fd8b8503a0d > * Add Fabio's Tested-by (Thanks!) > > 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(-) > > 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) Can you also test the SPI flash at some 100 kHz, just to see whether it still works properly ? (to retain behavior fixed first in 6fd8b8503a0dc ("spi: spi-imx: Fix out-of-order CS/SCLK operation at low speeds") ) The fix here does look fine by me however.
On 16.11.22 00:49, Marek Vasut wrote: > On 11/15/22 19:10, 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: 6fd8b8503a0d ("spi: spi-imx: Fix out-of-order CS/SCLK operation >> at low speeds") >> 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> >> Tested-by: Fabio Estevam <festevam@gmail.com> >> --- >> >> Changes for v3: >> >> * Add back the Fixes tag for commit 6fd8b8503a0d >> * Add Fabio's Tested-by (Thanks!) >> >> 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(-) >> >> 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) > > Can you also test the SPI flash at some 100 kHz, just to see whether it > still works properly ? (to retain behavior fixed first in 6fd8b8503a0dc > ("spi: spi-imx: Fix out-of-order CS/SCLK operation at low speeds") ) > > The fix here does look fine by me however. I successfully tested at 100 kHZ SPI bus clock. As in this case fspi is lower than fin, the patch doesn't change anything in the code path and therefore the behavior introduced in 6fd8b8503a0dc stays the same as without the patch.
On 11/16/22 09:17, Frieder Schrempf wrote: > On 16.11.22 00:49, Marek Vasut wrote: >> On 11/15/22 19:10, 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: 6fd8b8503a0d ("spi: spi-imx: Fix out-of-order CS/SCLK operation >>> at low speeds") >>> 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> >>> Tested-by: Fabio Estevam <festevam@gmail.com> >>> --- >>> >>> Changes for v3: >>> >>> * Add back the Fixes tag for commit 6fd8b8503a0d >>> * Add Fabio's Tested-by (Thanks!) >>> >>> 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(-) >>> >>> 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) >> >> Can you also test the SPI flash at some 100 kHz, just to see whether it >> still works properly ? (to retain behavior fixed first in 6fd8b8503a0dc >> ("spi: spi-imx: Fix out-of-order CS/SCLK operation at low speeds") ) >> >> The fix here does look fine by me however. > > I successfully tested at 100 kHZ SPI bus clock. As in this case fspi is > lower than fin, the patch doesn't change anything in the code path and > therefore the behavior introduced in 6fd8b8503a0dc stays the same as > without the patch. Acked-by: Marek Vasut <marex@denx.de> Thanks for the extra check !
On Tue, 15 Nov 2022 19:10:00 +0100, 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. > > [...] Applied to broonie/spi.git for-next Thanks! [1/1] spi: spi-imx: Fix spi_bus_clk if requested clock is higher than input clock commit: db2d2dc9a0b58c6faefb6b002fdbed4f0362d1a4 All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark
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)