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: 10861693 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 79AFB17E0 for ; Wed, 20 Mar 2019 13:19:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D4D528A93 for ; Wed, 20 Mar 2019 13:19:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5126729AEB; Wed, 20 Mar 2019 13:19:42 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_WEB autolearn=ham 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 C6F7928A93 for ; Wed, 20 Mar 2019 13:19:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728326AbfCTNTk (ORCPT ); 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-Google-Smtp-Source: APXvYqwLI6vqL98LuRTLBSp3a+Ilff2FY8DtkepVCSdE+SzNRPPuyYNYPhHYbFPuJlUyS4Qroj8smA== 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 X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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);