From patchwork Wed Jun 13 16:06:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Craig Tatlor X-Patchwork-Id: 10462615 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 1C58C603B4 for ; Wed, 13 Jun 2018 16:07:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 077BD28D8D for ; Wed, 13 Jun 2018 16:07:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE16D28D94; Wed, 13 Jun 2018 16:07:36 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 4594F28D8D for ; Wed, 13 Jun 2018 16:07:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935537AbeFMQHU (ORCPT ); Wed, 13 Jun 2018 12:07:20 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:33021 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935500AbeFMQHT (ORCPT ); Wed, 13 Jun 2018 12:07:19 -0400 Received: by mail-pf0-f195.google.com with SMTP id b17-v6so1669424pfi.0; Wed, 13 Jun 2018 09:07:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dcjfljfyhlrqZwWH1+9gew4bvxQUwNYXgP36XZgaDEo=; b=WWwYymagRz/Q4ENRHjfHZS3hactL7l5WHHXAi7mTP/070uEW0lvXKadmu5aOMHAROq GIrAbDKB1EqNbhFm+vREOt/3lb8k7zgnSq+1lSpEIzD8iGiUGlBGQfDzN5jyukN6rm0W tLjB/oaej7Mt/c5z6SpBOSiyXK4++Opuelm6xPI5cYvK9wle7E4K+RaGQXZSy8eCgcji 1ams8GN1hwcTyq0Zn2bXBZCDP5X3mwIOnHLP2hh53+ko4DdggxQ4p4oGSnlfwnu7sYbj IYdrRqHNAFudhD1qyhyMZgTrycQIlF6bc97jmFefnNZW/jbDch1wDfr9tmINvg+994lx ScuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dcjfljfyhlrqZwWH1+9gew4bvxQUwNYXgP36XZgaDEo=; b=kNUDOpxT/4TnHB3XC/6ZVQhbB3+C/aw58c2pcrB2bc1a2AnbvrMzBOHJpX1GCkIUoe LZ6o6XrBME4kgKZC0h4mYyeI53u6ol3k0CBeWNfTN4A05Lpj+TQFyt/Pem1cie2PGq6e UElnhl8T+bIoNxt1q4v8VpTY69xjfyYgoyS7JPHzUijjdtshQsg+N8cdinM1zwf21dY4 vVd+VElEtxqTSv0psE0ZWy+Atv/TUCMZZ4rQui/h9s0fyrvFcq8ZHIAeOXC5edN0ei2U wUc/Nve4wvDMqNn30i7sEr/sluY3xc4nmo1mCjsMPPIdY/GjE6IcemwZFyP69Tt31200 iRnw== X-Gm-Message-State: APt69E0diaRYvNBQbEleMCLuJBFaRqUfO4vu+XtndJCqpK5i3wuSOy+Q MzfAHgTyxhaBq5Rd5bka7g== X-Google-Smtp-Source: ADUXVKJRhAu2Nwt7sl1l7JLXOuSA3jNQy09X8+owo7GM6IA1TrZtShVa+NRgm9o+10tojY7vxziOHg== X-Received: by 2002:a63:b705:: with SMTP id t5-v6mr4575433pgf.343.1528906038831; Wed, 13 Jun 2018 09:07:18 -0700 (PDT) Received: from localhost.localdomain (host81-131-105-100.range81-131.btcentralplus.com. [81.131.105.100]) by smtp.googlemail.com with ESMTPSA id z19-v6sm4459577pfe.163.2018.06.13.09.07.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Jun 2018 09:07:18 -0700 (PDT) From: Craig Tatlor Cc: ctatlor97@gmail.com, linux-arm-msm@vger.kernel.org, Sebastian Reichel , Rob Herring , Mark Rutland , Mauro Carvalho Chehab , "David S. Miller" , Andrew Morton , Greg Kroah-Hartman , Linus Walleij , Randy Dunlap , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 1/4] fixp-arith: add a linear interpolation function Date: Wed, 13 Jun 2018 17:06:22 +0100 Message-Id: <20180613160643.12638-1-ctatlor97@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180407135934.26122-1-ctatlor97@gmail.com> References: <20180407135934.26122-1-ctatlor97@gmail.com> To: unlisted-recipients:; (no To-header on input) Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Adds a function to interpolate against two points, this is carried arount as a helper function by tons of drivers. Signed-off-by: Craig Tatlor --- include/linux/fixp-arith.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/linux/fixp-arith.h b/include/linux/fixp-arith.h index d4686fe1cac7..c21de4f358dd 100644 --- a/include/linux/fixp-arith.h +++ b/include/linux/fixp-arith.h @@ -153,4 +153,24 @@ static inline s32 fixp_sin32_rad(u32 radians, u32 twopi) #define fixp_cos32_rad(rad, twopi) \ fixp_sin32_rad(rad + twopi / 4, twopi) + +/** + * fixp_linear_interpolate() - interpolates a value from two known points + * + * @x0: x value of point 0 + * @y0: y value of point 0 + * @x1: x value of point 1 + * @y1: y value of point 1 + * @x: the linear interpolant + */ +static inline int fixp_linear_interpolate(int x0, int y0, int x1, int y1, int x) +{ + if (y0 == y1 || x == x0) + return y0; + if (x1 == x0 || x == x1) + return y1; + + return y0 + ((y1 - y0) * (x - x0) / (x1 - x0)); +} + #endif