From patchwork Wed Mar 20 13:17:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Kucheria X-Patchwork-Id: 10861685 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 6ABE9139A for ; Wed, 20 Mar 2019 13:19:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58A1627CAF for ; Wed, 20 Mar 2019 13:19:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4CEDA28AC1; Wed, 20 Mar 2019 13:19:25 +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 E1EEC29AEB for ; Wed, 20 Mar 2019 13:19:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728246AbfCTNTX (ORCPT ); Wed, 20 Mar 2019 09:19:23 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:40748 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728267AbfCTNTW (ORCPT ); Wed, 20 Mar 2019 09:19:22 -0400 Received: by mail-pg1-f195.google.com with SMTP id u9so1792129pgo.7 for ; Wed, 20 Mar 2019 06:19:22 -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=hnKCIBqLKSdwQJ9vlhhug9tJeolwVOLt4rLlaA/Eryo=; b=uRiRyUVTc6/sO336lyIjrdro+0m8gCsB+1nia2+FdzfAJ2nsIEvSdG8ZhuWG1BND5Y XAk/bx5UKMcqYmZsaT3D/5BXerongNPtlF0fRSi03RAX4y3WNN7WD/a4yChumoPppIAy Fp/2k/ttABVXfyGtcZr77N+WxY+1+MpeMELzIOkYEtopYNvGq6PuyH0SBmTk++IFcnHS 41H3YRFwFE2fGIRLYm0Uy9YcZINmjwiXo+E/d70JbCcersMuOK0fLd5Yfj7wrl69Ej4H GR97e3O79TC5bkbal+FZXXy1PauCMBl3g5//sQD1ZPG/hfTzisWaX8lSAwxtSuW2pQjU OIoQ== 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=hnKCIBqLKSdwQJ9vlhhug9tJeolwVOLt4rLlaA/Eryo=; b=IyVDNlrNGvty14xsVjrHyHLKAOb2XyIn7yqyGNrDDXB+Plmmz2vPtRTdKTnfnJhQQx 16N4G/s6zrA8DSWCTd5+5falV/oiiRKVho1qzoSEwowzghq3uafzhbV3xjfFR7g3le5r tc45V0FgG5L5nigKDrELbqw66kd2mBTIg7ZYS17lxMmuLKlKvWi116W51NUfr+LSS90r HMHyf1rHBcDlQmJcuaRBmFOcfwWGqefS4PpxUiw48BxCXcosdHAQlSb1zOaMjOCR+5iQ C65MCmdItGm2Ram5+/ovS5N9HisuHdQED6wWrZ5geOL4D7/4b3jSIF8mI0gcRqBWwt93 akUQ== X-Gm-Message-State: APjAAAUctP+cvKATbi1AluPNm+ckqimqf9D2uIIMETjSNpxX3/TzKPk4 gpoQplWFitwVI5FIO2vQLmL3JA== X-Google-Smtp-Source: APXvYqyxyVShxT9oTD2/Jx0lUzGsg94t3qAXCQ0csUNcXFWaRmOgj/m+GutZrte6KmnzwDCYNNGdqg== X-Received: by 2002:a17:902:27a8:: with SMTP id d37mr8013124plb.164.1553087961594; Wed, 20 Mar 2019 06:19:21 -0700 (PDT) Received: from localhost ([114.143.122.221]) by smtp.gmail.com with ESMTPSA id a24sm2688954pfn.85.2019.03.20.06.19.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 06:19:20 -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 13/23] drivers: thermal: tsens: Add new operation to check if a sensor is enabled Date: Wed, 20 Mar 2019 18:47:53 +0530 Message-Id: <4917d603944b606aa3a621ef6731d3dac7cca14c.1553086065.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 X-Virus-Scanned: ClamAV using ClamSMTP is_sensor_enabled() checks if the sensors are enabled on this platform. It is possible that the SoC might choose not to enable all the sensors that the IP block is capable of supporting. Signed-off-by: Amit Kucheria --- drivers/thermal/qcom/tsens-common.c | 14 ++++++++++++++ drivers/thermal/qcom/tsens-v0_1.c | 1 + drivers/thermal/qcom/tsens-v2.c | 1 + drivers/thermal/qcom/tsens.c | 5 +++++ drivers/thermal/qcom/tsens.h | 1 + 5 files changed, 22 insertions(+) diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-common.c index 9d7a6c328ae0..c76f8cfb25a2 100644 --- a/drivers/thermal/qcom/tsens-common.c +++ b/drivers/thermal/qcom/tsens-common.c @@ -69,6 +69,20 @@ void compute_intercept_slope(struct tsens_priv *priv, u32 *p1, } } +bool is_sensor_enabled(struct tsens_priv *priv, u32 hw_id) +{ + u32 val; + int ret; + + if ((hw_id > (priv->num_sensors - 1)) || (hw_id < 0)) + return -EINVAL; + ret = regmap_field_read(priv->rf[SENSOR_EN], &val); + if (ret) + return ret; + + return val & (1 << hw_id); +} + static inline int code_to_degc(u32 adc_code, const struct tsens_sensor *s) { int degc, num, den; diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c index d171a4a8c454..431255bfd0ef 100644 --- a/drivers/thermal/qcom/tsens-v0_1.c +++ b/drivers/thermal/qcom/tsens-v0_1.c @@ -333,6 +333,7 @@ const struct reg_field tsens_v0_1_regfields[MAX_REGFIELDS] = { /* CTRL_OFFSET */ [TSENS_EN] = REG_FIELD(SROT_CTRL_OFF, 0, 0), [TSENS_SW_RST] = REG_FIELD(SROT_CTRL_OFF, 1, 1), + [SENSOR_EN] = REG_FIELD(SROT_CTRL_OFF, 3, 13), /* ----- TM ------ */ /* INTERRUPT ENABLE */ diff --git a/drivers/thermal/qcom/tsens-v2.c b/drivers/thermal/qcom/tsens-v2.c index e15a302f7878..4b98dbe4e3c3 100644 --- a/drivers/thermal/qcom/tsens-v2.c +++ b/drivers/thermal/qcom/tsens-v2.c @@ -99,6 +99,7 @@ const struct reg_field tsens_v2_regfields[MAX_REGFIELDS] = { /* CTRL_OFF */ [TSENS_EN] = REG_FIELD(SROT_CTRL_OFF, 0, 0), [TSENS_SW_RST] = REG_FIELD(SROT_CTRL_OFF, 1, 1), + [SENSOR_EN] = REG_FIELD(SROT_CTRL_OFF, 3, 18), /* ----- TM ------ */ /* INTERRUPT ENABLE */ diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c index 057b33353ba3..fc44cac31fa5 100644 --- a/drivers/thermal/qcom/tsens.c +++ b/drivers/thermal/qcom/tsens.c @@ -82,6 +82,11 @@ static int tsens_register(struct tsens_priv *priv) struct thermal_zone_device *tzd; for (i = 0; i < priv->num_sensors; i++) { + if (!is_sensor_enabled(priv, priv->sensor[i].hw_id)) { + dev_err(priv->dev, "sensor %d: disabled\n", + priv->sensor[i].hw_id); + continue; + } priv->sensor[i].priv = priv; priv->sensor[i].id = i; tzd = devm_thermal_zone_of_sensor_register(priv->dev, i, diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h index a9390e06b4dd..a3bf7de88ae8 100644 --- a/drivers/thermal/qcom/tsens.h +++ b/drivers/thermal/qcom/tsens.h @@ -307,6 +307,7 @@ 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_common(struct tsens_priv *priv, int i, int *temp); +bool is_sensor_enabled(struct tsens_priv *priv, u32 hw_id); /* TSENS target */ extern const struct tsens_plat_data data_8960;