From patchwork Thu Feb 28 12:21:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Kucheria X-Patchwork-Id: 159362 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp576984jad; Thu, 28 Feb 2019 04:27:49 -0800 (PST) X-Google-Smtp-Source: AHgI3IazmFPqOnWZKEL2Ii3oyiWEVZZtgjWAr/xx5UXTIHY4PVM7JOLVFWKUS2JkdVeVbWuNZD+0 X-Received: by 2002:a63:5b43:: with SMTP id l3mr8168258pgm.298.1551356868923; Thu, 28 Feb 2019 04:27:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551356868; cv=none; d=google.com; s=arc-20160816; b=JNnNmTvu287TwOIRpTgPGYrYAMGHdvn2/CRECqIT8H4wDhoKwE2kNtZeElRTojEyEl /h2jsCTGuHLx44tc5BekfV3xHdQ3KAYvzMoXbQKp3chWq84orsjTR+NXbyKK+oLKYeEU kQAgoR6f9UKomzW7C4p1rSsaJC59Tk2HIwBs5pk1aA6OApCgOgFunrlOSCAP+Nsz3G4T k+RxxdmmmA/LOBsz1m6amDcx+VnikyK1z6Qi5tzNVNdvKW4/Qqq7bv+WELk60UDCvhqa j5My6PAD/drrQ9M2M7j0lSkU0xOPtL/UBk5dczyXcWyFc2ZXAFPRZEUpCJYLaWj/TE0p HcOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=kuDa3PTq6kESR0Oy4w3BK/UNqfJyke/AMtphy3RDuRw=; b=qx9ng9GJqtO75gXiA2Cwd5cAwB+kIoj2UYXdFowSB+sjv+YjUwhkH0nus9j075HULY MFvGMjjB4QHXnzAdiKdDMsQ4yfB56IOSTfR2H0doKUHXhYq94t6h4SfMvYF7CV0S3KA2 n2QNmZB8ARtjszgYkzAXSaUa9VK7a1anhb9iFpNmv3KKbAPd+WkjTOoI13TOHuir0qpz 5xiWlz6kI9MtXkbZH2hCAI+mHDfTEmj8T1hRYViLd5fFHg9HMdpLlY7axwTfwXpEaGUM A+dnWv3o5DKIs+cZxkzancU9QVNvWzqs4VZyAZS9fllt8x7+xfjAhhfLmUkEBNW4fciF yopA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=G2rzRguJ; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g9si18392931pfd.234.2019.02.28.04.27.48; Thu, 28 Feb 2019 04:27:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=G2rzRguJ; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731891AbfB1M1r (ORCPT + 11 others); Thu, 28 Feb 2019 07:27:47 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:35733 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731622AbfB1M1r (ORCPT ); Thu, 28 Feb 2019 07:27:47 -0500 Received: by mail-wm1-f65.google.com with SMTP id y15so8772806wma.0 for ; Thu, 28 Feb 2019 04:27:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=kuDa3PTq6kESR0Oy4w3BK/UNqfJyke/AMtphy3RDuRw=; b=G2rzRguJ3gSkHxStd9Hzh9TnP7wdGK0BT/re/M7y8nb5Kmp0RYg5plB/PC6lJ+b35b iNi2n3RM51MzyZbM7lAlJjIF015FLLqbyANSaSOP5eph6jtvH8BpjQf+PmD/Dmss6T+9 NzxeBm7Iq8Nu/Y6brXSe1MuYcW2rFIvHPRYRKyFYdA3fQxCFLElc0yipzOZj0u9986ib 1EPptnNYp80fmYFoE7AI2SvxjY0MOLOtUmu/4ili7PLq48LZS3e3OM3euatfeibY6AYA QOg1efn+zC3YTPo78TtCaGr5ohO3PC878b3fGBzU4yFRkLjJb7kC3P6yt6+3FujJNZtp pjnw== 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:in-reply-to:references; bh=kuDa3PTq6kESR0Oy4w3BK/UNqfJyke/AMtphy3RDuRw=; b=ayx20c81qV76HMmjGkbvP3qUDr/iXLTezNmm0uUDGI+hHWW1oSbnzy+qAdimwMtmpl sM8zvcJsq5rN1x1zKTUMBj92qJNaRoPs2lt+Bv/Er6bm+iPYkG0zunEwhYm9dCG1n3Q+ 4kMUtCDfiaFFOX3dnhU8uu2R1VMR9Yw8DR1Kq9+K2aojGj2TnNzvQNsYyYtRXrjUMtlQ 1U1lcdNFUWTUm/V8xus4FiyQr6MEEvWZIDjX4Jqy6DfC9j1/yHy0I3AH1WzkAdCF1im/ F2ML9oYDxd2x79Aeqph+1iJU2+IbYZla2E/DBYdCHEnyaYiOIloGCNW9yrlqbakf47Or HmSQ== X-Gm-Message-State: AHQUAuYEFWs8dq1SMBo2o4ZRMOQniFSKqkLKhuUA8gYN6nq+M2zwgLOG xbMuvhiMhm+G0qJYuOVoaqTgDQ== X-Received: by 2002:a7b:c929:: with SMTP id h9mr2791511wml.106.1551356865071; Thu, 28 Feb 2019 04:27:45 -0800 (PST) Received: from localhost ([49.248.54.130]) by smtp.gmail.com with ESMTPSA id a8sm5723653wmh.26.2019.02.28.04.27.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Feb 2019 04:27:44 -0800 (PST) From: Amit Kucheria To: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, bjorn.andersson@linaro.org, edubezval@gmail.com, andy.gross@linaro.org, Daniel Lezcano , David Brown , Zhang Rui Cc: linux-pm@vger.kernel.org Subject: [PATCH v2 18/24] drivers: thermal: tsens: Move get_temp_tsens_v2 to allow sharing Date: Thu, 28 Feb 2019 17:51:08 +0530 Message-Id: <30911f4ce9cd5094d4dea29d1e92da3cca6f7537.1551355503.git.amit.kucheria@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Just rename the function and move it to allow code sharing with future versions of TSENS IP Signed-off-by: Amit Kucheria --- drivers/thermal/qcom/tsens-common.c | 35 +++++++++++++++++++++++++++ drivers/thermal/qcom/tsens-v2.c | 37 +---------------------------- drivers/thermal/qcom/tsens.h | 1 + 3 files changed, 37 insertions(+), 36 deletions(-) -- 2.17.1 diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-common.c index 5f838fd798c3..7bab0e640806 100644 --- a/drivers/thermal/qcom/tsens-common.c +++ b/drivers/thermal/qcom/tsens-common.c @@ -102,6 +102,41 @@ static inline int code_to_degc(u32 adc_code, const struct tsens_sensor *s) return degc; } +int get_temp_tsens_valid(struct tsens_priv *priv, int i, int *temp) +{ + struct tsens_sensor *s = &priv->sensor[i]; + u32 temp_idx = LAST_TEMP_0 + s->hw_id; + u32 valid_idx = VALID_0 + s->hw_id; + u32 last_temp = 0, valid, mask; + int ret; + + ret = regmap_field_read(priv->rf[valid_idx], &valid); + if (ret) + return ret; + while (!valid) { + /* Valid bit is 0 for 6 AHB clock cycles. + * At 19.2MHz, 1 AHB clock is ~60ns. + * We should enter this loop very, very rarely. + */ + ndelay(400); + ret = regmap_field_read(priv->rf[valid_idx], &valid); + if (ret) + return ret; + } + + /* Valid bit is set, OK to read the temperature */ + ret = regmap_field_read(priv->rf[temp_idx], &last_temp); + if (ret) + return ret; + + mask = GENMASK(priv->fields[LAST_TEMP_0].msb, + priv->fields[LAST_TEMP_0].lsb); + /* Convert temperature from deciCelsius to milliCelsius */ + *temp = sign_extend32(last_temp, fls(mask) - 1) * 100; + + return 0; +} + int get_temp_common(struct tsens_priv *priv, int i, int *temp) { struct tsens_sensor *s = &priv->sensor[i]; diff --git a/drivers/thermal/qcom/tsens-v2.c b/drivers/thermal/qcom/tsens-v2.c index e180e80f533c..2e2331f5c248 100644 --- a/drivers/thermal/qcom/tsens-v2.c +++ b/drivers/thermal/qcom/tsens-v2.c @@ -25,41 +25,6 @@ #define TM_Sn_STATUS_OFF 0x00a0 #define TM_TRDY_OFF 0x00e4 -static int get_temp_tsens_v2(struct tsens_priv *priv, int i, int *temp) -{ - struct tsens_sensor *s = &priv->sensor[i]; - u32 temp_idx = LAST_TEMP_0 + s->hw_id; - u32 valid_idx = VALID_0 + s->hw_id; - u32 last_temp = 0, valid, mask; - int ret; - - ret = regmap_field_read(priv->rf[valid_idx], &valid); - if (ret) - return ret; - while (!valid) { - /* Valid bit is 0 for 6 AHB clock cycles. - * At 19.2MHz, 1 AHB clock is ~60ns. - * We should enter this loop very, very rarely. - */ - ndelay(400); - ret = regmap_field_read(priv->rf[valid_idx], &valid); - if (ret) - return ret; - } - - /* Valid bit is set, OK to read the temperature */ - ret = regmap_field_read(priv->rf[temp_idx], &last_temp); - if (ret) - return ret; - - mask = GENMASK(priv->fields[LAST_TEMP_0].msb, - priv->fields[LAST_TEMP_0].lsb); - /* Convert temperature from deciCelsius to milliCelsius */ - *temp = sign_extend32(last_temp, fls(mask) - 1) * 100; - - return 0; -} - /* v2.x: 8996, 8998, sdm845 */ const struct tsens_features tsens_v2_feat = { @@ -114,7 +79,7 @@ const struct reg_field tsens_v2_regfields[MAX_REGFIELDS] = { static const struct tsens_ops ops_generic_v2 = { .init = init_common, - .get_temp = get_temp_tsens_v2, + .get_temp = get_temp_tsens_valid, }; const struct tsens_plat_data data_tsens_v2 = { diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h index eb988c1d17c4..1cef2b8431eb 100644 --- a/drivers/thermal/qcom/tsens.h +++ b/drivers/thermal/qcom/tsens.h @@ -363,6 +363,7 @@ struct tsens_priv { char *qfprom_read(struct device *dev, const char *cname); void compute_intercept_slope(struct tsens_priv *priv, u32 *pt1, u32 *pt2, u32 mode); int init_common(struct tsens_priv *priv); +int get_temp_tsens_valid(struct tsens_priv *priv, int i, int *temp); int get_temp_common(struct tsens_priv *priv, int i, int *temp); bool is_sensor_enabled(struct tsens_priv *priv, u32 hw_id);