From patchwork Mon Mar 25 16:35:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 10869617 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E42FF186D for ; Mon, 25 Mar 2019 16:36:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D3B1E29166 for ; Mon, 25 Mar 2019 16:36:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C833B2949B; Mon, 25 Mar 2019 16:36:21 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable 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 81ED529166 for ; Mon, 25 Mar 2019 16:36:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729125AbfCYQgV (ORCPT ); Mon, 25 Mar 2019 12:36:21 -0400 Received: from kirsty.vergenet.net ([202.4.237.240]:42086 "EHLO kirsty.vergenet.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725788AbfCYQgV (ORCPT ); Mon, 25 Mar 2019 12:36:21 -0400 Received: from reginn.horms.nl (watermunt.horms.nl [80.127.179.77]) by kirsty.vergenet.net (Postfix) with ESMTPA id BAC3325BF15; Tue, 26 Mar 2019 03:36:10 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=verge.net.au; s=mail; t=1553531771; bh=40aXj6/gt4xoni++7qBcCs23s4Ow0DogxkOQvF6oujY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CZbkl2dQyUaMvdVt22tOByqEVMj5A0051fSzhmiI8eu0p7CIlLphJ01L3xxJvP/6h /6Kcxmgavfzsw+VE6uuOilgdIP8VGqtPQuH6nxNbvV/1woY6g3oH9ALuGvz2vxdwHl kv8Mc2gr1zeDNLvb16ugBpnHZRFX/2QCskssS59U= Received: by reginn.horms.nl (Postfix, from userid 7100) id DF306940857; Mon, 25 Mar 2019 17:36:08 +0100 (CET) From: Simon Horman To: Geert Uytterhoeven Cc: Magnus Damm , linux-renesas-soc@vger.kernel.org, linux-clk@vger.kernel.org, Simon Horman Subject: [PATCH v6 4/7] math64: New DIV64_U64_ROUND_CLOSEST helper Date: Mon, 25 Mar 2019 17:35:53 +0100 Message-Id: <20190325163556.22025-5-horms+renesas@verge.net.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190325163556.22025-1-horms+renesas@verge.net.au> References: <20190325163556.22025-1-horms+renesas@verge.net.au> Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Provide DIV64_U64_ROUND_CLOSEST helper which performs division rounded to the closest integer using an unsigned 64bit dividend and divisor. This will be used in a follow-up patch to allow calculation of clock divisors with high frequency parents in the R-Car Gen3 CPG MSSR driver where overflow occurs if either the dividend or divisor is 32bit. Signed-off-by: Simon Horman Reviewed-by: Geert Uytterhoeven --- v6 - Updated changelog as per suggestions from Sergei Shtylyov and Geert Uytterhoeven - Added Reviewed-by tag from Geert Uytterhoeven v5 - New separate patch to add DIV64_U64_ROUND_CLOSEST --- include/linux/math64.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/linux/math64.h b/include/linux/math64.h index bb2c84afb80c..65bef21cdddb 100644 --- a/include/linux/math64.h +++ b/include/linux/math64.h @@ -284,4 +284,17 @@ static inline u64 mul_u64_u32_div(u64 a, u32 mul, u32 divisor) #define DIV64_U64_ROUND_UP(ll, d) \ ({ u64 _tmp = (d); div64_u64((ll) + _tmp - 1, _tmp); }) +/** + * DIV64_U64_ROUND_CLOSEST - unsigned 64bit divide with 64bit divisor rounded to nearest integer + * @dividend: unsigned 64bit dividend + * @divisor: unsigned 64bit divisor + * + * Divide unsigned 64bit dividend by unsigned 64bit divisor + * and round to closest integer. + * + * Return: dividend / divisor rounded to nearest integer + */ +#define DIV64_U64_ROUND_CLOSEST(dividend, divisor) \ + ({ u64 _tmp = (divisor); div64_u64((dividend) + _tmp / 2, _tmp); }) + #endif /* _LINUX_MATH64_H */