From patchwork Tue Apr 27 19:44:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: thermal-bot for Julien Panis X-Patchwork-Id: 428229 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A47A6C43617 for ; Tue, 27 Apr 2021 19:44:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 89A4261026 for ; Tue, 27 Apr 2021 19:44:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238917AbhD0TpM (ORCPT ); Tue, 27 Apr 2021 15:45:12 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:43138 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238930AbhD0TpL (ORCPT ); Tue, 27 Apr 2021 15:45:11 -0400 Date: Tue, 27 Apr 2021 19:44:26 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1619552667; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u/HBTzlVy+iTy2/CFOC/67wVwNuaGzuBdugBSBM9vNc=; b=cLyIzfnztEEJjT/vkJwBQzqFdM5EKdlHc6IJwPOFgcKbSA0GxkpPEZ84xDgHgmZk3bI78U P1oGtl43sat5tRoeSZ9mHS+PMVS6HnbC+y76VwneyQGtisWckIwkKalqpQFbm08nnsqmxE SDE10VfjYH1iyypKYeUlZUrXHRSapzpAAiSGzwCvjOxGQh+/kHeAxqnuUnok9ME8RrI56S Kdg+OfQeTo61afZ+M68dTL06LdNIprb+AuY820w/O+Hj6rZfYCk5+d/Z3/oEXoPfBLSv9P oPalDnonxSwfIsFF7nSR+RyJ5VJzE8u//QABPeZ7MUu+2+OLqeTH/XyA2ELXpg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1619552667; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u/HBTzlVy+iTy2/CFOC/67wVwNuaGzuBdugBSBM9vNc=; b=QL2QiHwR3fKOSEz1BeG1SJ7izxo9RoPmhSmFMV4ydI6FPZCmM9+ml6gyrQc2C9U9lbPZ6h MBn/UMru60N+RYAA== From: "thermal-bot for Ansuel Smith" Sender: tip-bot2@linutronix.de Reply-to: linux-pm@vger.kernel.org To: linux-pm@vger.kernel.org Subject: [thermal: thermal/next] thermal/drivers/tsens: Replace custom 8960 apis with generic apis Cc: Ansuel Smith , Thara Gopinath , Daniel Lezcano , rui.zhang@intel.com, amitk@kernel.org In-Reply-To: <20210420183343.2272-7-ansuelsmth@gmail.com> References: <20210420183343.2272-7-ansuelsmth@gmail.com> MIME-Version: 1.0 Message-ID: <161955266682.29796.9741277706437488341.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The following commit has been merged into the thermal/next branch of thermal: Commit-ID: dfc1193d4dbd6c3cb68c944413146c940bde290a Gitweb: https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//dfc1193d4dbd6c3cb68c944413146c940bde290a Author: Ansuel Smith AuthorDate: Tue, 20 Apr 2021 20:33:40 +02:00 Committer: Daniel Lezcano CommitterDate: Thu, 22 Apr 2021 14:09:59 +02:00 thermal/drivers/tsens: Replace custom 8960 apis with generic apis Rework calibrate function to use common function. Derive the offset from a missing hardcoded slope table and the data from the nvmem calib efuses. Drop custom get_temp function and use generic api. Signed-off-by: Ansuel Smith Acked-by: Thara Gopinath Signed-off-by: Daniel Lezcano Link: https://lore.kernel.org/r/20210420183343.2272-7-ansuelsmth@gmail.com --- drivers/thermal/qcom/tsens-8960.c | 56 ++++++++---------------------- 1 file changed, 15 insertions(+), 41 deletions(-) diff --git a/drivers/thermal/qcom/tsens-8960.c b/drivers/thermal/qcom/tsens-8960.c index a96d37c..58112f0 100644 --- a/drivers/thermal/qcom/tsens-8960.c +++ b/drivers/thermal/qcom/tsens-8960.c @@ -67,6 +67,13 @@ #define S9_STATUS_OFF 0x3674 #define S10_STATUS_OFF 0x3678 +/* Original slope - 350 to compensate mC to C inaccuracy */ +static u32 tsens_msm8960_slope[] = { + 826, 826, 804, 826, + 761, 782, 782, 849, + 782, 849, 782 + }; + static int suspend_8960(struct tsens_priv *priv) { int ret; @@ -194,9 +201,7 @@ static int calibrate_8960(struct tsens_priv *priv) { int i; char *data; - - ssize_t num_read = priv->num_sensors; - struct tsens_sensor *s = priv->sensor; + u32 p1[11]; data = qfprom_read(priv->dev, "calib"); if (IS_ERR(data)) @@ -204,49 +209,18 @@ static int calibrate_8960(struct tsens_priv *priv) if (IS_ERR(data)) return PTR_ERR(data); - for (i = 0; i < num_read; i++, s++) - s->offset = data[i]; + for (i = 0; i < priv->num_sensors; i++) { + p1[i] = data[i]; + priv->sensor[i].slope = tsens_msm8960_slope[i]; + } + + compute_intercept_slope(priv, p1, NULL, ONE_PT_CALIB); kfree(data); return 0; } -/* Temperature on y axis and ADC-code on x-axis */ -static inline int code_to_mdegC(u32 adc_code, const struct tsens_sensor *s) -{ - int slope, offset; - - slope = thermal_zone_get_slope(s->tzd); - offset = CAL_MDEGC - slope * s->offset; - - return adc_code * slope + offset; -} - -static int get_temp_8960(const struct tsens_sensor *s, int *temp) -{ - int ret; - u32 code, trdy; - struct tsens_priv *priv = s->priv; - unsigned long timeout; - - timeout = jiffies + usecs_to_jiffies(TIMEOUT_US); - do { - ret = regmap_read(priv->tm_map, INT_STATUS_ADDR, &trdy); - if (ret) - return ret; - if (!(trdy & TRDY_MASK)) - continue; - ret = regmap_read(priv->tm_map, s->status, &code); - if (ret) - return ret; - *temp = code_to_mdegC(code, s); - return 0; - } while (time_before(jiffies, timeout)); - - return -ETIMEDOUT; -} - static const struct reg_field tsens_8960_regfields[MAX_REGFIELDS] = { /* ----- SROT ------ */ /* No VERSION information */ @@ -307,7 +281,7 @@ static const struct reg_field tsens_8960_regfields[MAX_REGFIELDS] = { static const struct tsens_ops ops_8960 = { .init = init_common, .calibrate = calibrate_8960, - .get_temp = get_temp_8960, + .get_temp = get_temp_common, .enable = enable_8960, .disable = disable_8960, .suspend = suspend_8960,