From patchwork Mon Feb 11 13:58:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 10805903 X-Patchwork-Delegate: geert@linux-m68k.org 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 D76D31390 for ; Mon, 11 Feb 2019 13:59:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C76242A267 for ; Mon, 11 Feb 2019 13:59:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B904B2A1BC; Mon, 11 Feb 2019 13:59:55 +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=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 5FBEC2A1BC for ; Mon, 11 Feb 2019 13:59:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727348AbfBKN72 (ORCPT ); Mon, 11 Feb 2019 08:59:28 -0500 Received: from kirsty.vergenet.net ([202.4.237.240]:34766 "EHLO kirsty.vergenet.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726041AbfBKN7Z (ORCPT ); Mon, 11 Feb 2019 08:59:25 -0500 Received: from reginn.horms.nl (watermunt.horms.nl [80.127.179.77]) by kirsty.vergenet.net (Postfix) with ESMTPA id B421A25BEE2; Tue, 12 Feb 2019 00:59:13 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=verge.net.au; s=mail; t=1549893554; bh=4Wt8YgIK6tvMWR7ftlSnQU4JQjmsI43dIhNg/wYW9gQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OO+4k0y59vvKnBb3Ynur832nLt+feqXLUrt5s7/tvbJ+YOsKG2LX/Wxb0/F/7aLLD uRtn0D026TmjaAa8hjfW/hbefwb/DGVRqnocJvhRBe5aZvScHCc37tAEsU3S3TkFBK pWvwtOcvUVA9Q4XQr4xdygImPO5LR7iPdDPjDvXo= Received: by reginn.horms.nl (Postfix, from userid 7100) id B16519404AC; Mon, 11 Feb 2019 14:59:11 +0100 (CET) From: Simon Horman To: Geert Uytterhoeven Cc: Magnus Damm , linux-renesas-soc@vger.kernel.org, linux-clk@vger.kernel.org, Fabrizio Castro , Biju Das , Andrew Morton , linux-kernel@vger.kernel.org, Simon Horman Subject: [PATCH v5 3/6] math64: New DIV64_U64_ROUND_CLOSEST helper Date: Mon, 11 Feb 2019 14:58:55 +0100 Message-Id: <20190211135858.23635-4-horms+renesas@verge.net.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190211135858.23635-1-horms+renesas@verge.net.au> References: <20190211135858.23635-1-horms+renesas@verge.net.au> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Provide DIV64_U64_ROUND_CLOSEST helper which performs division rounded to the closes 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 ovefolow occurs if either the dividend or divisor is 32bit. Signed-off-by: Simon Horman Reviewed-by: 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 */