From patchwork Wed Feb 14 16:28:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 10219431 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CC1BC601C2 for ; Wed, 14 Feb 2018 16:30:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA22928C58 for ; Wed, 14 Feb 2018 16:30:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE4ED28C6C; Wed, 14 Feb 2018 16:30:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 252FC28C58 for ; Wed, 14 Feb 2018 16:30:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Content-Type: MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Date:Message-Id:In-Reply-To:Subject:To:From:Reply-To :Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:References: List-Owner; bh=CqQOsOT6a5esIez9CFYcDXFxXIG7JV3E1pQqdooTN5s=; b=ritZD1fL1NtfJ/ ni19sMz7K2zqfwzz9Ior36EIVqlIG3yUVgvt+Bxcvip2bcGTGemyb/qvJ4wbCPmKEK2bCCsqbTczK VEXfU4k1VAt4qd57Hs7hIsWy7VtXBglbkRjSCLg4csZ+Z+wFNVt9jx3KzG3uViMC/UufINdfJqZGl LzdWlrbt6bZnacHLWIYEOFAkr4LbHaShq1LiKOa7adZGemhmRScxhFgh+1HVviEpcnN4tCN9gLHqG dF3fD/In+f9kdWTr9oKRpMdG6iFM2UDOosoicOwjjZc7GX/SlVrYiwRSaBTik2Yapn/oVDEwlT9Wm IFhQk50mYF6cfOnkJEOQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1elzwS-0003QM-B0; Wed, 14 Feb 2018 16:29:56 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1elzwL-0003P2-TV; Wed, 14 Feb 2018 16:29:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Date:Message-Id:In-Reply-To:Subject:Cc: To:From:Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:References:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=kmXTpg9Xf+mRFMY2+Y5+mnuTk7SxBb7zJgyXN6fMt8Q=; b=C7oD9eKOk65xTSMp29gyF189Jl GQpH45pFGXWT3kAEpWaup4UeK4vizPMIQa6VmJ8AazNYu3oM3UMYmpRBEIn3sM181a/jYNCVGXQzX +BqKRpLAGl2VxtzNZI/lm/FNWf80MD5Hbad4QW/WqrG0cbEm46RSMxL5B+kMk1Af9jgRmqOdl9KRy O+GOmLt/pOizCZBhrhtPBZUEch1mqlMqUCvf8ToyrYC0O503P2QGgnCNj4xgQnvw8PaDXrM6AJmfP sI/5LAD3t5/oXf7DQOsc99aPrdfWCZ33xKl0ZZ+3+RxIoINcWxLdkxgcmwImdLlj0xXe5d/iLnPh9 ++hHutrA==; Received: from heliosphere.sirena.org.uk ([2a01:7e01::f03c:91ff:fed4:a3b6]) by casper.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1elzwI-0008Qx-Gc; Wed, 14 Feb 2018 16:29:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sirena.org.uk; s=20170815-heliosphere; h=Date:Message-Id:In-Reply-To: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:References: List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner: List-Archive; bh=kmXTpg9Xf+mRFMY2+Y5+mnuTk7SxBb7zJgyXN6fMt8Q=; b=QqaF6DYqVLgE Yu7VwhVrRJG6my4pKg5ioqPjrK/m/Zls5XgFCA1O10sk+61TeqWnYqfl1jHZwLKLf5pyRWb4DQPup gZ0zCmNbREPZgGdS+0soa1fe79jcaZ8fkzTHjwuUGAG9nXGt+OUely0PqvfXhS0/NZ6BSpo+kURHW 4guyg=; Received: from debutante.sirena.org.uk ([2001:470:1f1d:6b5::3] helo=debutante) by heliosphere.sirena.org.uk with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1elzvG-0005qn-8i; Wed, 14 Feb 2018 16:28:42 +0000 Received: from broonie by debutante with local (Exim 4.90_1) (envelope-from ) id 1elzvF-0005oU-Pj; Wed, 14 Feb 2018 16:28:41 +0000 From: Mark Brown To: Trent Piepho Subject: Applied "spi: bcm2835aux: Avoid 64-bit arithmetic in xfer len calc" to the spi tree In-Reply-To: <20180212193814.17644-1-tpiepho@impinj.com> Message-Id: Date: Wed, 14 Feb 2018 16:28:41 +0000 X-Bad-Reply: In-Reply-To but no 'Re:' in Subject. X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180214_162946_568693_2AA218DC X-CRM114-Status: GOOD ( 17.91 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Wahren , Florian Fainelli , Ray Jui , linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org, Eric Anholt , Mark Brown , "Gustavo A . R . Silva" , linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The patch spi: bcm2835aux: Avoid 64-bit arithmetic in xfer len calc has been applied to the spi tree at https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git 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 From d704afffe65c8fab424963c1ba4ec4364c2d6a82 Mon Sep 17 00:00:00 2001 From: Trent Piepho Date: Mon, 12 Feb 2018 11:38:14 -0800 Subject: [PATCH] spi: bcm2835aux: Avoid 64-bit arithmetic in xfer len calc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We want to check for xfers that are over 30 microseconds. Rather than find how many µs a xfer will take, instead find how many bytes can be transferred in 30 µs. The latter must be less than 32 bits (since our clock speed is limited to 32 bits), while the former involves 64 bit quantities and more arithmetic operations. Signed-off-by: Trent Piepho Signed-off-by: Mark Brown --- drivers/spi/spi-bcm2835aux.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/spi/spi-bcm2835aux.c b/drivers/spi/spi-bcm2835aux.c index 7428091d3f5b..1431cb98fe40 100644 --- a/drivers/spi/spi-bcm2835aux.c +++ b/drivers/spi/spi-bcm2835aux.c @@ -321,7 +321,6 @@ static int bcm2835aux_spi_transfer_one(struct spi_master *master, struct bcm2835aux_spi *bs = spi_master_get_devdata(master); unsigned long spi_hz, clk_hz, speed; unsigned long spi_used_hz; - unsigned long long xfer_time_us; /* calculate the registers to handle * @@ -358,20 +357,21 @@ static int bcm2835aux_spi_transfer_one(struct spi_master *master, bs->rx_len = tfr->len; bs->pending = 0; - /* calculate the estimated time in us the transfer runs - * note that there are are 2 idle clocks after each - * chunk getting transferred - in our case the chunk size - * is 3 bytes, so we approximate this by 9 bits/byte + /* Calculate the estimated time in us the transfer runs. Note that + * there are are 2 idle clocks cycles after each chunk getting + * transferred - in our case the chunk size is 3 bytes, so we + * approximate this by 9 cycles/byte. This is used to find the number + * of Hz per byte per polling limit. E.g., we can transfer 1 byte in + * 30 µs per 300,000 Hz of bus clock. */ - xfer_time_us = tfr->len * 9 * 1000000; - do_div(xfer_time_us, spi_used_hz); - +#define HZ_PER_BYTE ((9 * 1000000) / BCM2835_AUX_SPI_POLLING_LIMIT_US) /* run in polling mode for short transfers */ - if (xfer_time_us < BCM2835_AUX_SPI_POLLING_LIMIT_US) + if (tfr->len < spi_used_hz / HZ_PER_BYTE) return bcm2835aux_spi_transfer_one_poll(master, spi, tfr); /* run in interrupt mode for all others */ return bcm2835aux_spi_transfer_one_irq(master, spi, tfr); +#undef HZ_PER_BYTE } static int bcm2835aux_spi_prepare_message(struct spi_master *master,