From patchwork Tue Nov 15 16:13:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frieder Schrempf X-Patchwork-Id: 13043957 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DF2FBC4332F for ; Tue, 15 Nov 2022 16:15:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=M5cGZIA8BC/BHpWPbfPn5BfIcfqb+zqhyJHoYj/w1wE=; b=0uNjKZgh/DvDhb aILTFpCbcJ/mIB9iN0EtlMgMltfAyZLqRGlB0Ji15bIOQv44E+gUDPH3vTJwUNI1dSpieardIsand iu4E99Q9/A1WQLMt24F1ph1Qof6zA7dJ0eUrZ8Qx+Qo3VvgRReMevl08Esp2ahY0u2PO1qRR5RcQS UReA2g87m2n3gI2PPT0au04L2HujuHQGgVzKKmjWUIbyEDibOkBLirdssdshoK6ngXv9KYsX2z2Pa s0O/8i7+M9HZiv8M6UmnKqQV6jww9ncPcdWsmr4z6Znn+qR84+HzcYdoQB36jQZJoiv2AuSjqa8o3 4tiVTB6ZrcpflSTkg3kA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ouyZo-00Cdxs-Fz; Tue, 15 Nov 2022 16:14:20 +0000 Received: from mail.fris.de ([116.203.77.234]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ouyZl-00Cdum-DZ for linux-arm-kernel@lists.infradead.org; Tue, 15 Nov 2022 16:14:19 +0000 Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 5C5CBBFADB; Tue, 15 Nov 2022 17:13:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fris.de; s=dkim; t=1668528845; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding; bh=C4LnN75ZJGeCz9hy3XT4dIQ9QgHsqGAcTbNSzRrmDiY=; b=vaXBey0yBOBIRCWMnptaIpwnlve+A/dln0kZWT8PjmQaZfxv6L8krfrflgqYl0cIrOhYqe yD9pQlF96yqlV3/dIYj1jIxTtlDrj+sDYczzY8FgNgxca5YiVe3Yn+5tbPkXlfqBqNqZHl S0XCgFE2ckfiGdHaUpaKyUaD7yD+xed3Uk7SPyCxGzTAf+NMyN1e0Kua+RKtlSpqkQz+Dr h7AbCf1T1RWbaH2LqWHvQD4Oq3UpU4SmIk6mWhRHHDrZSPlZHlLiY6UF6LnB+8TkWn5kqO vFCtWQwOIFQhKM7k/GOiZRV6f8Q6pcVhiqJTI7tIbfW3/bH23tnI9c98I0q/LA== From: Frieder Schrempf To: David Jander , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org, Marc Kleine-Budde , Marek Vasut , Mark Brown , Sascha Hauer , Shawn Guo Cc: Frieder Schrempf , Fabio Estevam , stable@vger.kernel.org, Baruch Siach , Minghao Chi , NXP Linux Team , Pengutronix Kernel Team Subject: [PATCH] spi: spi-imx: Fix spi_bus_clk if requested clock is higher than input clock Date: Tue, 15 Nov 2022 17:13:30 +0100 Message-Id: <20221115161331.1972336-1-frieder@fris.de> MIME-Version: 1.0 X-Last-TLS-Session-Version: TLSv1.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221115_081417_969359_F381D2F7 X-CRM114-Status: GOOD ( 15.46 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Frieder Schrempf 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. Less serious but also incorrect, it causes the calculation of the delay for propagation of register changes added in commit 6fd8b8503a0d ("spi: spi-imx: Fix out-of-order CS/SCLK operation at low speeds") to be wrong, as not the actual bus clock but the potentially higher requested bus clock is used. 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 Cc: David Jander Cc: Fabio Estevam Cc: Mark Brown Cc: Marek Vasut Cc: stable@vger.kernel.org Signed-off-by: Frieder Schrempf --- 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)