Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7190343rwb; Tue, 15 Nov 2022 08:46:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf4AxdeG2U+0nCrhAVphuEe9KP/31ZSu3yowU7yW0n9p2DkazZKBKv9YZ6bWEsSAx69VuW62 X-Received: by 2002:a17:907:20d1:b0:78d:554f:fb16 with SMTP id qq17-20020a17090720d100b0078d554ffb16mr14475125ejb.151.1668530814251; Tue, 15 Nov 2022 08:46:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668530814; cv=none; d=google.com; s=arc-20160816; b=CnPp2yEs9IOcoTN2HVt+QSCa1olRPlse4u9VD6SwOQ2hYAOrksK9JRvU+mWEzFXRKW JMTyggs0T+XHeeT+YLMvU9c0w7p9pVpU5f7N6L9jWdqVwo5tYCN8pN/CPS3iU5w1+6kE WRHQHuGkEU2/dFniQHxpY2zY/2zMnxQGPnAsuWwHf0lb1QfOBnQJxyNNSjz55rCwh3Yu QmuA/HqiM1AD5wCC9hBDmLTzazQuj+zxF+P8RkCBIdltZ9OYlZqYuasYcVDiECNrHXYC I0Yj5rDVUUzCZU01zOkJnacLJIjUr2DX/eph4lu5VpVYjc5+CXkih2sHIWDfnLqNkZyx rRGg== 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=C4LnN75ZJGeCz9hy3XT4dIQ9QgHsqGAcTbNSzRrmDiY=; b=ogh4MxO9pfbo4x2/OBiXS/dKCLs0bHqk8z869pS6+Pu7Bq0qbtWzIeBPSpD2UbPf5k tOi8Kh1OZG+ipoJX/OPnE2xrjY4psPeWX9zuZ0+vX7GdMFFaPFR2XDp66SGlZr0PSCsc o67k4gxvBkjyDtKRkhQUS26JlVpjCH5W/aMgXM4sHZ6eNosOQnlVA/yJkVRHemmOHc6V 1YbO2lpyUXSkYGupXvzzZ5CUOoW4Hl6jvNiV9B8l+uP9RcYDypD4bXXBnTe3qe1z7HL0 OBt/gQT+kKaoxjec6+HW+KgedIjXtIWe6hVsnjdctOnrr2nbyZ2HHP97VeNdXy4Ko3ug l6eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fris.de header.s=dkim header.b=vaXBey0y; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z5-20020a056402274500b00461d6a4afd1si13203378edd.8.2022.11.15.08.46.32; Tue, 15 Nov 2022 08:46:54 -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=vaXBey0y; 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 S231232AbiKOQZE (ORCPT + 90 others); Tue, 15 Nov 2022 11:25:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238606AbiKOQZA (ORCPT ); Tue, 15 Nov 2022 11:25:00 -0500 X-Greylist: delayed 643 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 15 Nov 2022 08:24:57 PST Received: from mail.fris.de (mail.fris.de [116.203.77.234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A3B3D103; Tue, 15 Nov 2022 08:24:57 -0800 (PST) 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 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: X-Mailing-List: linux-kernel@vger.kernel.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) -- 2.38.1