Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp70952pxa; Tue, 18 Aug 2020 16:16:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwR1r9KbzQe6I+FD9v/zaxNyJrOqFRW6dJiszpnTJopnrH7C+Z1ilIIgtjFqrqbeeIOX5hH X-Received: by 2002:aa7:c1d4:: with SMTP id d20mr22209275edp.81.1597792561000; Tue, 18 Aug 2020 16:16:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597792560; cv=none; d=google.com; s=arc-20160816; b=jttYHXeqjgNdGOE33Gr9J8hdE1RUGazCBkpZBVP4Gp0da+VGsYegNBblz2ZRDxfVbl PrwIgDe0+u7mEsGOP8BwZJYiD6GHiEhLZjQUL4BkxtCG65iAUoEi8tltBV00H6FhbMAq 7WwAUKGI6BBh3vhP5VM4YgYmd4zfySBNAhvQiDHj+2gp8fOdvEOTVh1rbgTQ9N9qOE7f +l2N5kVrnHpFuSoLtYwVyiwiDEKdVLGHFd3ynF1+xjQBzQFhIiV6JD5MZoXFmP5pMC3v WK9FFfzNLnOHxS9yWzy/IJ58l4vncj7rDHtfd4aI32EYLMt/nR2bFHt5AARB+qbckieX lalw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/CQP6Mp+jMuAdeJV/E9lJgqu50DuZ6HxUkaNbDh+BH8=; b=qmZCRTXiw1MB06ylrp+3JMenjyLhu1cU7kVo2VvzCOL9nCd+UNaVVhq7s4U0Arjh6A VUMO4kMlcGTf/uhD2ALnSurTh+yuCCgoo+Q3i9wGvCXylad0qNHbEVz/m4+1+8JwvlL8 uyENIJKPeqSE2djUirJKMpHjl9Ubf3o3jnQXXm0+lqFCik7IsjY5lCvXHecyN0jOzXIe Fx3ijDTY3atSeiW3b63XcWhw/LbgEeVRmjzROUGCKYFbLkJsSKTczbZjheMBQ6QPxm4/ PTA/Ftguz0avSEyCy4yctj4n4xRY5mKIEWNzqgz7k7TGR/fNgPDZJfe+WTb25Cey9ero ybVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@melexis.com header.s=google header.b=WLwkvH0X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s15si13994704eji.64.2020.08.18.16.15.22; Tue, 18 Aug 2020 16:16:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@melexis.com header.s=google header.b=WLwkvH0X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726825AbgHRViR (ORCPT + 99 others); Tue, 18 Aug 2020 17:38:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726735AbgHRViN (ORCPT ); Tue, 18 Aug 2020 17:38:13 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3B34C061343 for ; Tue, 18 Aug 2020 14:38:12 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id r4so19549896wrx.9 for ; Tue, 18 Aug 2020 14:38:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=melexis.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/CQP6Mp+jMuAdeJV/E9lJgqu50DuZ6HxUkaNbDh+BH8=; b=WLwkvH0X34iEz89yjYbiz9Pnl2Xb2a4TL2wKrUbnaXz9CeFlqMZ82f2i/dUPQ8TZsm BA93t7gmcpGQT4hjzxtmTr4e50mTi5oxht7xTmCW/5o+NxvhCKd7C2Dx+anOgMN2KtOJ K5LAdJH0zgM0K36ZZHxTOtCqcXdTjsggQBtxcbJ23CjL8eT42LUz8kgDnQDjNaZhSFF2 h7mNmKlwn8+WGcuqo14+Y8IJMjiV6WV9yUcOB2BdD10lUWCs6RvL66H5lmxb1N446VRE KNhxU19b4kG2Bq8iczJDmqWriLfhauF62eakCeGzbDwHJdvZz8mWlmT5HjU+QT/Xwrez 1y3w== 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:mime-version:content-transfer-encoding; bh=/CQP6Mp+jMuAdeJV/E9lJgqu50DuZ6HxUkaNbDh+BH8=; b=Yg4GOzIlHnMxnsSjv7RX2xATXOZPbqDPqDxEp8J8nldTU2t5muPAdkvX0cxpsPC+W3 1woqWldiB5d0cRVeM40/HI0CuU1j8X6fxLIk4ghSzDdtfJoZgndVBmUqEfPObWezMtYt jk575QeroVrKwDETaHmGMVm105XyFoV5akxWTujoaZz1P/hXxw0oNv9yyQO+HUeRJHKw 41ESnxxMzeMiAsnCDNmjbDi3sFneEd5KlN9ZPGhq9SHqeJ5w/sbY4Tr4Tw5VhoJ7Ghhv 2bIStHPK9VB41HcFzLXziRigg3sr7JdsGaoypu9Hktp7zcjqe9smuF/JyJuvKQXQXISB fkAg== X-Gm-Message-State: AOAM530U3Tq2zCf3+McRk5PKEQ+t8i3VOV+b6fhHgO1XN7r2Srmpmh+W SDOfQPYR0EjUeofMZXR/g2QFMg== X-Received: by 2002:adf:df08:: with SMTP id y8mr23448704wrl.152.1597786690523; Tue, 18 Aug 2020 14:38:10 -0700 (PDT) Received: from localhost.localdomain ([88.116.83.106]) by smtp.gmail.com with ESMTPSA id z207sm1797860wmc.2.2020.08.18.14.38.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Aug 2020 14:38:09 -0700 (PDT) From: Crt Mori To: Jonathan Cameron Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Crt Mori , Andy Shevchenko Subject: [PATCH v6 1/5] iio:temperature:mlx90632: Reduce number of equal calulcations Date: Tue, 18 Aug 2020 23:37:33 +0200 Message-Id: <20200818213737.140613-2-cmo@melexis.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200818213737.140613-1-cmo@melexis.com> References: <20200818213737.140613-1-cmo@melexis.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org TAdut4 was calculated each iteration although it did not change. In light of near future additions of the Extended range DSP calculations, this function refactoring will help reduce unrelated changes in that series as well as reduce the number of new functions needed. Signed-off-by: Crt Mori Reviewed-by: Andy Shevchenko --- drivers/iio/temperature/mlx90632.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/iio/temperature/mlx90632.c b/drivers/iio/temperature/mlx90632.c index 51b812bcff2e..c3de10ba5b1e 100644 --- a/drivers/iio/temperature/mlx90632.c +++ b/drivers/iio/temperature/mlx90632.c @@ -374,11 +374,11 @@ static s32 mlx90632_calc_temp_ambient(s16 ambient_new_raw, s16 ambient_old_raw, } static s32 mlx90632_calc_temp_object_iteration(s32 prev_object_temp, s64 object, - s64 TAdut, s32 Fa, s32 Fb, + s64 TAdut, s64 TAdut4, s32 Fa, s32 Fb, s32 Ga, s16 Ha, s16 Hb, u16 emissivity) { - s64 calcedKsTO, calcedKsTA, ir_Alpha, TAdut4, Alpha_corr; + s64 calcedKsTO, calcedKsTA, ir_Alpha, Alpha_corr; s64 Ha_customer, Hb_customer; Ha_customer = ((s64)Ha * 1000000LL) >> 14ULL; @@ -393,30 +393,35 @@ static s32 mlx90632_calc_temp_object_iteration(s32 prev_object_temp, s64 object, Alpha_corr = emissivity * div64_s64(Alpha_corr, 100000LL); Alpha_corr = div64_s64(Alpha_corr, 1000LL); ir_Alpha = div64_s64((s64)object * 10000000LL, Alpha_corr); - TAdut4 = (div64_s64(TAdut, 10000LL) + 27315) * - (div64_s64(TAdut, 10000LL) + 27315) * - (div64_s64(TAdut, 10000LL) + 27315) * - (div64_s64(TAdut, 10000LL) + 27315); return (int_sqrt64(int_sqrt64(ir_Alpha * 1000000000000LL + TAdut4)) - 27315 - Hb_customer) * 10; } +static s64 mlx90632_calc_ta4(s64 TAdut, s64 scale) +{ + return (div64_s64(TAdut, scale) + 27315) * + (div64_s64(TAdut, scale) + 27315) * + (div64_s64(TAdut, scale) + 27315) * + (div64_s64(TAdut, scale) + 27315); +} + static s32 mlx90632_calc_temp_object(s64 object, s64 ambient, s32 Ea, s32 Eb, s32 Fa, s32 Fb, s32 Ga, s16 Ha, s16 Hb, u16 tmp_emi) { - s64 kTA, kTA0, TAdut; + s64 kTA, kTA0, TAdut, TAdut4; s64 temp = 25000; s8 i; kTA = (Ea * 1000LL) >> 16LL; kTA0 = (Eb * 1000LL) >> 8LL; TAdut = div64_s64(((ambient - kTA0) * 1000000LL), kTA) + 25 * 1000000LL; + TAdut4 = mlx90632_calc_ta4(TAdut, 10000LL); /* Iterations of calculation as described in datasheet */ for (i = 0; i < 5; ++i) { - temp = mlx90632_calc_temp_object_iteration(temp, object, TAdut, + temp = mlx90632_calc_temp_object_iteration(temp, object, TAdut, TAdut4, Fa, Fb, Ga, Ha, Hb, tmp_emi); } -- 2.25.1