From patchwork Wed Mar 20 13:17:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Kucheria X-Patchwork-Id: 160684 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp283095jan; Wed, 20 Mar 2019 06:19:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqz2pZmdIMQMQnw26+IHmaa/AxGoMu7dgy3BhVB/JddVW5mEeID7E9ok3MuN0vdmIzoETjvO X-Received: by 2002:a62:bd13:: with SMTP id a19mr7595397pff.222.1553087981905; Wed, 20 Mar 2019 06:19:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553087981; cv=none; d=google.com; s=arc-20160816; b=t2pldOlifR15V5VlNtFCfhFCRzZ8EFnxNLbdgm3joYa+sM/+fp3Akpk0dKpTGQQU8q UQTN8mHClw/7koH4/ae0xyls/CaYUTPifNN8M0xqJfp7uH8Ml7jubsahqWhCL8nLYirR UYHnngoe/lwvvmzmtxwK9IDFEHwI1m9n4yXbet1lguk+8I9+IsHlneM60asOgQNv3uyy SnZs+RgfymaoZupIo602Omk4ruChQpFFzD94nj6zN+HN8zNGJkPmNHoE/zwLB84RMbTO zKDHdZ3t3piVDhRHCWXuDtp0LeC4C1nnmwVi86JeXB9X1k5W6fEdzcD6+V6HCnHx7I6N L4Qg== 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=a0G0N6buTKooxPqu5bVGNMmItUQCR7PXXaszMXTU5cY=; b=f7t4MO4yMiiSvUAp4oMsmh28L9qO7bXt82bEDrvDK4Vp4qCpFrMqAdopX3iCdRwxf4 DoGgm5D8Wfe7xV7p7wTQ8fjJzQXT+YYNUyOqEBYhSo1JRmf3c2WaFiNp0YteFfIxtHkI b0vPQaR3j1I0k9iYtlETTXA/LH9wznxakQFAnRvV4NhBzYJO9iH6+0+VJnHn+mrxDXKq ODFSchF3I+DzUC8mJaqfht6ZDqFyDPIA6G/Ezya5RGeY8HAvo44a+Iz6D8FD9XPEw78p unreyMkoHMElCGD6y4aUa7qKeQBr5PsFTiB+BNeW1fpYgSqckDP2i27LlvHCEVNojw9X v9oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=I8+sJ+LP; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-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 32si1932137ple.241.2019.03.20.06.19.41; Wed, 20 Mar 2019 06:19:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-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=I8+sJ+LP; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-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 S1728326AbfCTNTk (ORCPT + 15 others); Wed, 20 Mar 2019 09:19:40 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:38140 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727625AbfCTNTj (ORCPT ); Wed, 20 Mar 2019 09:19:39 -0400 Received: by mail-pf1-f193.google.com with SMTP id 10so1931315pfo.5 for ; Wed, 20 Mar 2019 06:19:38 -0700 (PDT) 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=a0G0N6buTKooxPqu5bVGNMmItUQCR7PXXaszMXTU5cY=; b=I8+sJ+LP+z4on0Uy7pXj2R9M+FReLV/2w9thUCSidfJHSBpo7al8y2XT+1ohkAdBpM A/wue3RfnTj51CzjrLNnJjLAyvJKcs28vQYPDhiZtdXJTQzn6PQ8z5As8IG4nth1WZRA BL+0Nnm2c2ClYyfTCyS+TO7hijxBhREfmeUjRtnXNhgmL6yOvRlSGQ5rru0Ix+LUULiy 5pVjLvUJFYdWAZzzJ9R5h8dS8GhGWV35M+ccQRLZPy6fOLCOt45GM370e6QIe2RGbK5V ErO+VnHcMl23ffRV4PF+JmyZcSsJt4rgdNI6q3MXdyE1uMFz5tTay7NCOtfQf9Mmdvm/ dZlw== 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=a0G0N6buTKooxPqu5bVGNMmItUQCR7PXXaszMXTU5cY=; b=OttRlqH72DHrw/iqxCSbUsHmIgmlZpSN3STmX5S5uZLjuzn9lzbX43RGoPKUHyldgC mongWoMrvRy07XW2D1VP+hvYyAdiLx8lhSWBgsfs57P9rfay1O8pIoM/nIL+4pVi8zM/ jOXd1JfclyswsumYgCTN/u/ojspVXoQ+sCRwTl8OfDavsfpaNdoeQYQuluMNngnRNPDK ea3x0KKgB+pnO761fT63rpWf467NgoeU23jq8/s9p+577dsJlUSCRr7UozMiOh9JMh53 7vSVwMyLvy8u+aHU2MelPwqvshwYUGoX3Qeu8kEHBmZYx6RQbHbDgSp5SzCHhRCS/w88 fTmQ== X-Gm-Message-State: APjAAAXtGKqqUrC7zxPzdPAoxQJxZqv4bJIoq87gZ4FSDt7ynE4v7rC1 0YxS3N9eSFgIkUu/2JsQN72kSA== X-Received: by 2002:a62:2e07:: with SMTP id u7mr7444855pfu.176.1553087978358; Wed, 20 Mar 2019 06:19:38 -0700 (PDT) Received: from localhost ([114.143.122.221]) by smtp.gmail.com with ESMTPSA id h3sm2361211pgv.38.2019.03.20.06.19.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 06:19:37 -0700 (PDT) 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: [PATCHv3 17/23] drivers: thermal: tsens: Move get_temp_tsens_v2 to allow sharing Date: Wed, 20 Mar 2019 18:47:57 +0530 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@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 5607c5cc635c..5adbf1a2e0fb 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 716d7f827459..36fbfa6a471e 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 = { @@ -101,7 +66,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 080e15a09ac2..f14a87aa1a47 100644 --- a/drivers/thermal/qcom/tsens.h +++ b/drivers/thermal/qcom/tsens.h @@ -308,6 +308,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);