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: 10861715 X-Patchwork-Delegate: eduardo.valentin@ti.com 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 A3DD917E0 for ; Wed, 20 Mar 2019 13:20:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9176E29BE9 for ; Wed, 20 Mar 2019 13:20:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 850BF29B83; Wed, 20 Mar 2019 13:20:23 +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=unavailable 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 237C029BF1 for ; Wed, 20 Mar 2019 13:20:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727625AbfCTNTl (ORCPT ); Wed, 20 Mar 2019 09:19:41 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:39850 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728323AbfCTNTj (ORCPT ); Wed, 20 Mar 2019 09:19:39 -0400 Received: by mail-pf1-f194.google.com with SMTP id i17so1925970pfo.6 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=LXr7JUqSsnhs4W6QbkI1Ode3GsHlRECUixG4NGTqx9+Ch5fRRGj+XkFi2J4NIB+X0m /5Gx5fl5MokF2Y6wqhA1qwaMtiDuywYWlciLyx7m5ND1KgYKuJCDEVA3zxdyKAC6idn+ lONKyXnIElAWuRq/00AMpmwx6i6yeTGfk+fHNtLRp+lhmspSLMfrwI6nwOm16Mx3K7DZ IEOAuXCzyIxTwZzDz8PqEek9DDJ/E00qMKduWScTjSrsVdLB4PPSeuAQRkiSpeswMh9X yfxaWLtivn1C+65w2G3q3fNkJ/RghBVdGk16RG2vkJ9Pn/NfvjWPYwMDkwfFtArmkZ5g YIbw== X-Gm-Message-State: APjAAAUxtz34nRIENvoubZyO1EDUmfn921UbU15tB2Cn8R2VTc6+lm5J 8oIY4Iz1Vm9BUv2PKLVBG2ZYyQ== 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-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@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);