From patchwork Mon Feb 12 19:38:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Trent Piepho X-Patchwork-Id: 10214279 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 96E4D60236 for ; Mon, 12 Feb 2018 19:38:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D3F228D31 for ; Mon, 12 Feb 2018 19:38:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81D5728D40; Mon, 12 Feb 2018 19:38:39 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D95A628D31 for ; Mon, 12 Feb 2018 19:38:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751034AbeBLTii (ORCPT ); Mon, 12 Feb 2018 14:38:38 -0500 Received: from mail-bl2nam02on0101.outbound.protection.outlook.com ([104.47.38.101]:56672 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750930AbeBLTig (ORCPT ); Mon, 12 Feb 2018 14:38:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=impinj.onmicrosoft.com; s=selector1-impinj-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=EMbr6Q1DSGpz0V+Roc0+C+322v22Dd3mc6Fq5+njSdI=; b=ojlvXvtN18uzs2Wc2ToH/BTq4B4dDc02AISP6k40pjqOmL58eYdxKS+QKRGa8sNbFU/3XWbna4blZ9v5+BMg945j/suc9vPa1G/JvNQsQim3gyOoW2cSHicJSNVDht0InM+1n8vqs9HnewmWMKwkFIwqxKTybn2CI/iam5XDf38= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=tpiepho@impinj.com; Received: from impinj.com (216.207.205.253) by MWHPR0601MB3754.namprd06.prod.outlook.com (2603:10b6:301:7d::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.485.10; Mon, 12 Feb 2018 19:38:29 +0000 From: Trent Piepho To: linux-spi@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: "Gustavo A . R . Silva" , Mark Brown , Eric Anholt , Stefan Wahren , Florian Fainelli , Ray Jui , Trent Piepho Subject: [PATCH] spi: bcm2835aux: Avoid 64-bit arithmetic in xfer len calc Date: Mon, 12 Feb 2018 11:38:14 -0800 Message-Id: <20180212193814.17644-1-tpiepho@impinj.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <1518463905.25398.281.camel@impinj.com> References: <1518463905.25398.281.camel@impinj.com> MIME-Version: 1.0 X-Originating-IP: [216.207.205.253] X-ClientProxiedBy: MWHPR12CA0071.namprd12.prod.outlook.com (2603:10b6:300:103::33) To MWHPR0601MB3754.namprd06.prod.outlook.com (2603:10b6:301:7d::19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8ddda1ef-1342-4270-b42a-08d5725031b9 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:MWHPR0601MB3754; X-Microsoft-Exchange-Diagnostics: 1; MWHPR0601MB3754; 3:/8yQTrU23R4icxY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FAwmR0TFWdAsJ9Vp0zGeW9r1jMiBa8snJC69Y3bkhg1/69JBLgYi0wc3ml5G/5a7HXHeLMoj83OSxcwzLUNy+NwW/cEu/v+lvCQaA+rtNLrTbiW9F6A7YZM20vKMiCU8OZKe+gYvxhDGvInkjv7I9KKR4klC8/sjeaeej1djETCBuLrJzeX34Cwvzt/ih2Q/xhPBD3YcuDH3bA3cZ3mtNXnozCni2cClw3jZhJQLIyScPLkTwAazAgaIN5/CRInGxtYQ60il0W3lXQmShlqvTfbWX5Fl2WlKfUlQS1NirS3InBFfBIu5O5+bPqyAOADAxMdnSH2ESU0I; 4:a17dWkAKfMYi7LOMl0s5az+fdElgel9cMarAmAEme+JDK+VonMepnvb0ldst7RCz710e3ecDf/2Hxvo6msJuNfoD8EsETGyzRezZNPgUqbR/OPk4TJGQu0hRmaTekVzmW7ai5T0z6L7gzCkBv8ot8ocLGs3riGooJFiEu3qdDmLst+dcZUpUIwS/lceZV2cdLjAAugFHGUrC2DTkNTP8fyq0+IhneMOaOtNzHUzU8aZzNORt1hWOmaR9YZDUtV/mic0LehlbtB8D3fSEOU+37g== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231101)(2400082)(944501161)(3002001)(10201501046)(6041288)(20161123564045)(20161123560045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(6072148)(201708071742011); SRVR:MWHPR0601MB3754; BCL:0; PCL:0; RULEID:; SRVR:MWHPR0601MB3754; X-Forefront-PRVS: 0581B5AB35 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(396003)(376002)(39380400002)(39840400004)(346002)(366004)(199004)(189003)(6666003)(1076002)(2906002)(68736007)(23676004)(54906003)(86362001)(186003)(53936002)(81166006)(8936002)(59450400001)(50466002)(69596002)(105586002)(26005)(316002)(478600001)(16526019)(81156014)(97736004)(47776003)(50226002)(1857600001)(386003)(66066001)(2950100002)(305945005)(2870700001)(106356001)(25786009)(7736002)(4326008)(7416002)(39060400002)(107886003)(76176011)(5660300001)(8676002)(52116002)(36756003)(6116002)(55016002)(3846002)(21086003)(7696005); DIR:OUT; SFP:1102; SCL:1; SRVR:MWHPR0601MB3754; H:impinj.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: impinj.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtNV0hQUjA2MDFNQjM3NTQ7MjM6TU5oR0FQeVQwb0MzRExJaU5rTVlLTDhJ?= =?utf-8?B?bFlyZ0QySWkzZlF5d1hlNFg2SXkwM0hBekdjTU1peGVYNGZZVnU2SDNWRWxN?= =?utf-8?B?UCtDcUREUS81WHFwcW9mZXlLNTd1dEhVeU43V1FwSXhzSmRVTHVpK0tXVkxI?= =?utf-8?B?YUpsMjI3UFAxb3dlU3FldmdVMDdMS1QrSjE1d0lvcmswYWQzWVE4djkxL0RF?= =?utf-8?B?QTNZY1lGL0FrbWxSdjJaTkZxbmswd2NsaFZLTUQxMDhERmJETVVMS3NUMWNH?= =?utf-8?B?bjZzSWpEQ3dFTmdVSEZ1bU4zMjRWVWh3dWhndHc3YzlUczVJaDFpcldRaGRa?= =?utf-8?B?MkhkLzRrV3lUS2VxckpMNGdqaFExOERsOVMvNzhmaHliQjVyZStaaEorMEdu?= =?utf-8?B?dWxybERDeUpQK1pyeUxYekNyc1F3bFhlZGxZeVNtSEJaY25UaWR3R1VSM3Vj?= =?utf-8?B?MGc4V1pncHBvMmorWDlLNldmNHZGSnFNUzlIMUZ0dkdZeXJWWkd2RCtYSVcv?= =?utf-8?B?cklNYzZ4bmdDWUk5Wm9qbml6L0JMTUpXRDBQcXZESzdaUXVKUTA0ZlRQZ2NV?= =?utf-8?B?alFiaUI0UDluYlozc053WUFKVXJnakhMQ3NpcnUrZU5XbH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0aW3gAu7K4Unn7TemUhVkVprhmyXSCq25VlFuULySreUi+RFshgxZl5w8icj/LjLQworqXcf+NVhzG1OpIAl5iCSlMGXPXV24Og SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: impinj.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Feb 2018 19:38:29.9059 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8ddda1ef-1342-4270-b42a-08d5725031b9 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 6de70f0f-7357-4529-a415-d8cbb7e93e5e X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR0601MB3754 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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,