Message ID | 20221103080043.3033414-1-sean@geanix.com |
---|---|
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 l7csp387885wru; Thu, 3 Nov 2022 01:18:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7nB4dswj0Wuq+Q5q2kDWp8LRH8n6oeH9VFIu3hzzzGuVfHjiNWd2Cxnidw0d87C00hZiBl X-Received: by 2002:a17:907:97d5:b0:7ac:5f72:6c1a with SMTP id js21-20020a17090797d500b007ac5f726c1amr27443941ejc.126.1667463516335; Thu, 03 Nov 2022 01:18:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667463516; cv=none; d=google.com; s=arc-20160816; b=oOeUKlwKn3Do7UHq3ZXwt6j6zVL++P2Fwrmj/LbGI6Ae1Rj82bV8cXM0SSepXTMZmC FdoG7rO5HN6hjoxNCKaTRkat9kfgFIrtnFOdU8uP882/VIL0WyaBcHksPo0BisFL2s28 /10IAft56CfwFpd5VnEMeNdoXtrWlr+ONrM2C4SVMh+cHvrCg7gdd72Fg49Uf0SVk7U4 bvlIO5U/PjwaS8ayJZ+XYRcntCWtJBOywm5qTI/O76iwoMqpbrDOMINaKLu66i1kv87R T03m4Se7BrfaLihBx9ApYgerjRxcHW8K5Bysf21ZiOO7ZaDCjmgIPmQ+M5mmrl3r9aC/ TL8g== 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=6m4iaglPuwTIbYvPaN1dsDtdJ0SXxitYbRrhMUr702k=; b=hnllPKo5BS6DoLlJH7acK+L8x0Toq+dAASH/zduswFIjqIqByAKKgyMWpxWTbX9hGW cIU0XsQaiqwIUq7xe1QGP4odhYfpvYBybrC2LPe7dZ5FEcelXoFhc/9DOeIMDhL/EeCX p1HHWkDz7abGaYAbdp9s+8P7Hjmz44T6Sir5WJpoyBj9Tx2644ff5Lf92ntOjM3AOqZM sTu2MncIpgGfw04PtasyBhPt41X5SJR3MB9MNd2bOIEXJ959c1+T8Mfnbi+cnXeX1jPC 8c9RONnFz/FTQd2BxusOIpYvsQzVNTHm4gPewRm+kyWGmqi+8X9Ww/4tJBB97Aj/Q+et N/fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@geanix.com header.s=first header.b=MItX3BnD; 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=NONE sp=NONE dis=NONE) header.from=geanix.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cs15-20020a170906dc8f00b0078e1b6060f7si572799ejc.299.2022.11.03.01.18.12; Thu, 03 Nov 2022 01:18:36 -0700 (PDT) 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=@geanix.com header.s=first header.b=MItX3BnD; 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=NONE sp=NONE dis=NONE) header.from=geanix.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230384AbiKCIQZ (ORCPT <rfc822;yves.mi.zy@gmail.com> + 99 others); Thu, 3 Nov 2022 04:16:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229551AbiKCIQX (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 3 Nov 2022 04:16:23 -0400 X-Greylist: delayed 600 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 03 Nov 2022 01:16:22 PDT Received: from first.geanix.com (first.geanix.com [116.203.34.67]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F8985FAD; Thu, 3 Nov 2022 01:16:22 -0700 (PDT) Received: from zen.. (unknown [185.17.218.86]) by first.geanix.com (Postfix) with ESMTPSA id 104815827E; Thu, 3 Nov 2022 08:01:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=geanix.com; s=first; t=1667462464; bh=AxBdGD11GmXU93SjZlmfOt6f3j2/0l1361xkEdsg1iY=; h=From:To:Cc:Subject:Date; b=MItX3BnDqsJI383c0+PBt/GME0eDbQLDxRiavRuKSNAy/yQpifuYqntqZYZY4xU8w +L4mJtyxMKjUDBl9CfhtrsoG5TM2ZqQ145mOVW46Y4uKXA6Y2/lZ85ZmRfBNSdQr7y wYHJDxLX70KD/05Vf1D9SjdxSOr6tn7hBIt7bVhCGLb11TNl0rtN4G5FDP0rk9PtgD OKhZVlTaf8/VzC6Va67o7OV7G/dZEZ9zcz25LJa70BNLagI6dtXlfkv20iOWNTKCYH GokLqv+abyfNy7MBBLu508XAjUPreBF54rQHx/7KwQxobCPWq+W/gDv22xxCCZk/hs lXWo8gAr6H5rQ== From: Sean Nyekjaer <sean@geanix.com> To: Alain Volmat <alain.volmat@foss.st.com>, Mark Brown <broonie@kernel.org>, Maxime Coquelin <mcoquelin.stm32@gmail.com>, Alexandre Torgue <alexandre.torgue@foss.st.com> Cc: Sean Nyekjaer <sean@geanix.com>, linux-spi@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] spi: stm32: fix stm32_spi_prepare_mbr() that halves spi clk for every run Date: Thu, 3 Nov 2022 09:00:42 +0100 Message-Id: <20221103080043.3033414-1-sean@geanix.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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?1748462224428377173?= X-GMAIL-MSGID: =?utf-8?q?1748462224428377173?= |
Series |
spi: stm32: fix stm32_spi_prepare_mbr() that halves spi clk for every run
|
|
Commit Message
Sean Nyekjaer
Nov. 3, 2022, 8 a.m. UTC
When this driver is used with a driver that uses preallocated spi_transfer
structs. The speed_hz is halved by every run. This results in:
spi_stm32 44004000.spi: SPI transfer setup failed
ads7846 spi0.0: SPI transfer failed: -22
Example when running with DIV_ROUND_UP():
- First run; speed_hz = 1000000, spi->clk_rate 125000000
div 125 -> mbrdiv = 7, cur_speed = 976562
- Second run; speed_hz = 976562
div 128,00007 (roundup to 129) -> mbrdiv = 8, cur_speed = 488281
- Third run; speed_hz = 488281
div 256,000131072067109 (roundup to 257) and then -EINVAL is returned.
Use DIV_ROUND_CLOSEST to allow to round down and allow us to keep the
set speed.
Signed-off-by: Sean Nyekjaer <sean@geanix.com>
---
drivers/spi/spi-stm32.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Thu, 3 Nov 2022 09:00:42 +0100, Sean Nyekjaer wrote: > When this driver is used with a driver that uses preallocated spi_transfer > structs. The speed_hz is halved by every run. This results in: > > spi_stm32 44004000.spi: SPI transfer setup failed > ads7846 spi0.0: SPI transfer failed: -22 > > Example when running with DIV_ROUND_UP(): > - First run; speed_hz = 1000000, spi->clk_rate 125000000 > div 125 -> mbrdiv = 7, cur_speed = 976562 > - Second run; speed_hz = 976562 > div 128,00007 (roundup to 129) -> mbrdiv = 8, cur_speed = 488281 > - Third run; speed_hz = 488281 > div 256,000131072067109 (roundup to 257) and then -EINVAL is returned. > > [...] Applied to https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next Thanks! [1/1] spi: stm32: fix stm32_spi_prepare_mbr() that halves spi clk for every run commit: 62aa1a344b0904549f6de7af958e8a1136fd5228 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-stm32.c b/drivers/spi/spi-stm32.c index 6fe617b445a5..d6833361409d 100644 --- a/drivers/spi/spi-stm32.c +++ b/drivers/spi/spi-stm32.c @@ -434,7 +434,7 @@ static int stm32_spi_prepare_mbr(struct stm32_spi *spi, u32 speed_hz, u32 div, mbrdiv; /* Ensure spi->clk_rate is even */ - div = DIV_ROUND_UP(spi->clk_rate & ~0x1, speed_hz); + div = DIV_ROUND_CLOSEST(spi->clk_rate & ~0x1, speed_hz); /* * SPI framework set xfer->speed_hz to master->max_speed_hz if