From patchwork Thu Jun 7 18:12:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Craig Tatlor X-Patchwork-Id: 10453329 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 3444B6053F for ; Thu, 7 Jun 2018 18:13:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 25E0D22B26 for ; Thu, 7 Jun 2018 18:13:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A2B828565; Thu, 7 Jun 2018 18:13:41 +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 CD86C22B26 for ; Thu, 7 Jun 2018 18:13:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934794AbeFGSNY (ORCPT ); Thu, 7 Jun 2018 14:13:24 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:46375 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933757AbeFGSNU (ORCPT ); Thu, 7 Jun 2018 14:13:20 -0400 Received: by mail-lf0-f68.google.com with SMTP id j13-v6so16091781lfb.13; Thu, 07 Jun 2018 11:13: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=QYdOtheuhBfQfvUO11xaXHz8W8uoEQEswg3rzwzKzeFeZDtBbwdJ//laH1Upib0pCW wrdFm/kXBAKUYGCtbwONGsOjP9mvyMNopDmVFTQjHJIIvED3m8frifZBwCVTc9rVXRkd txjYLZ28wQnqDqtGZpkasL+1cmROsEFohtccVDuxDcVORRDpew7RAUXJU8vc8puwjeAn c39IHT+jXF7BKqYGpawZJij+V8LnL2GNzC5NdOpEecDILILK1aED/7ZjPqGj5/+dpJ5q kfP3R0hXVMZncK5TwAewhQCTWkyt2z1Xyk6DrdGtrmmC8O6H1EOqNt14Ip0qgtSaS2cG VeOA== 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=a/5GR8uYO5Koh1FyC6TlmyIs2l2hUDfehg8NNqrXZmJ+mory9ImT8q+vhOdHPHJoJu s8ATURksZ9otbXAk2ipmN+JfBHQG+8WJQgVY7rdGockdT2J05W9UZS0r1md32WhJeqsj Olr24ZCQP1n3NKPW0Lqu22mv0ET9kKYUD4mAiSPuyB+K6p7QomIZKnViRWx+P2tGivwG VIzc7shwUfjdq346GTs2v7xRDg3xc/v9nGEM2CJfheIOYOybc2GZw2FZToTWkm+vRKv1 Z/6K8DzhOPkJA5V3mVVmAW7VPuvaNNv8XvaZOk/doGmrz7UbgaxKDHK+fVUwcdsGcezC ZhIg== X-Gm-Message-State: APt69E3Qq+h7AXSKysRLgi6GRtbJaZPAMOYwVjfhEZSEDnbATGQuYVC5 QsAU6Ej6ZvMgIFcizHIOZg== X-Google-Smtp-Source: ADUXVKK9AHihVMtw4nn67t7iLIS4l6hCYsdS8QyNeTf0fI/if1a8mL8uTZYcfUsj+STAFaWvqidATQ== X-Received: by 2002:a2e:44c6:: with SMTP id b67-v6mr2245039ljf.120.1528395198693; Thu, 07 Jun 2018 11:13: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 w4-v6sm3329722ljh.88.2018.06.07.11.13.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jun 2018 11:13:17 -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" , Greg Kroah-Hartman , Andrew Morton , Linus Walleij , Randy Dunlap , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 1/4] fixp-arith: add a linear interpolation function Date: Thu, 7 Jun 2018 19:12:49 +0100 Message-Id: <20180607181306.9766-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 Reviewed-by: Linus Walleij --- 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