From patchwork Thu Feb 7 10:49:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Kucheria X-Patchwork-Id: 157733 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp609967jaa; Thu, 7 Feb 2019 04:56:20 -0800 (PST) X-Google-Smtp-Source: AHgI3IbGd5LSN5zAuodr/nbkw9pYGnLkGy2QDM5C8objRHTwHVrztHVvJ5SPdfrZso8B0BOzW/pT X-Received: by 2002:a63:ef50:: with SMTP id c16mr5776112pgk.3.1549544180214; Thu, 07 Feb 2019 04:56:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549544180; cv=none; d=google.com; s=arc-20160816; b=CoTURNPBwIdb47gtIG0203NmSqsG364XES9UaR5wayTJOPxFSh9dQxktFOgPP+vU1H wRSMJbmFAH1Lc63lDcCtVXV9QirvoD9OczFk0UKz5zGNEUDJftik7FJBS/T9n9kF5a/j Ql+pVWL1zGagJg6gAqbP17MTegeD9JfwaTyG0276uPdn9bFH1xphfQEfo4+iCzQgrl/l eQbSXcXPhVAC6VczgGB3Lhm45fNbb677kFyst/nwvX5GGnrRO6WHC/EudwQt5XNYP5XM 7LU7LubiiSR1bEjuVQpp44oRks2O/NUGFe7TzP85/31VyDmN5cWWIHV3ZKz4HHIUJ7HL cFow== 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=IMOq2Akho+4m31uQd4WeKnRvq63fThBL3U3/6BakR0U=; b=0+p3QUVVAqCB1OkbfHRcS5beu1yc1xen8HzxlfNakkl+rh3l+r7a+Y9oaIPSHqetzM Ut/RaonC2cU9CnGhwmfLbgaQD74E/xXzAxCfnru3isIiMDpDxo6y5zKnG7PbwpuMsLpH M8bW6UEvCbEZxxKRsmFVJ6Mf+x1MnVIOerw6g5CLn6FMUf6fEQ0HMw6O4j93fE9F7kFo 4zm7gzH4LQsOLNonbhKG0WOAVNy5RBuZSZSKHCzxaSHDSHEAAPShVf9qJt7QJvklX+Gu c0NsBrYBgsXWWgK4lc4WP7mmh/xMRPNFVkctJJ3aiwFaI7vt/nAQawfvgPStirOM9/X5 /LpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PKclIgRj; 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 a11si9338061pla.20.2019.02.07.04.56.19; Thu, 07 Feb 2019 04:56:20 -0800 (PST) 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=PKclIgRj; 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 S1726949AbfBGM4T (ORCPT + 15 others); Thu, 7 Feb 2019 07:56:19 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:35810 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726844AbfBGM4T (ORCPT ); Thu, 7 Feb 2019 07:56:19 -0500 Received: by mail-pl1-f196.google.com with SMTP id p8so4746376plo.2 for ; Thu, 07 Feb 2019 04:56:18 -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=IMOq2Akho+4m31uQd4WeKnRvq63fThBL3U3/6BakR0U=; b=PKclIgRj5qFjo8HkiY9vUen1nTxxtJ/v8aVnsKPwXq9MJ6+0VZkc7lAT4jY7aokXG6 htrP6kt4lR4PwjHD3XcGchoGyxNuRWZJxfJbeMsXcweTXpOrm6ySHdA3ZwDrIknVSz8e VNxfsLquNary7T6P9pXTHNbMoN/KBPQUVFXeyqOAYV7hRv/Jc9WOwdBSw+UrG93FgrzS jwNd9vkjZTiazewwhNhkCo+mMBhcEut8o9zjJJVNHt+EAmBwvnCgesYHC5kQtzeqm8AE D8GHidEm7FKVk/h1PvY/gn9p+c2lgbdlDJXAqrxIcCn6wcgXMjrGlImuR1xW7tpT/PYr CWGQ== 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=IMOq2Akho+4m31uQd4WeKnRvq63fThBL3U3/6BakR0U=; b=dTGs1FF9rZrPlcSePcqFrphp3M30EVN67x9/7oFgcsqy+i4otqeuL5fDhYDcWhZInb rsVD9eKPx/B69IpJGxK7m16jiGG3xWf762bPgF4QXJN0+4ORpxQjL7ZLCkwQw89WifO7 Xl+pU/RIv++S32P/mrhqlQLn2pV6sP1DJ4cWfQcXRu4ofhoG7xD5/UETwWZ58nCp6XcI BFbKE3WF2JzYJvvkYM/LZBpBuQhiM+k4Batm9w7ogYETY1fWqCQUBCsEvBy9sx8G+Eb2 VH8JOzhkdRpsN3xcY5oQ8sKVFXJOoqN+7RfBV1r66WazpMrB5XjTe5Yu9xJVtdSaI/lr T6Ow== X-Gm-Message-State: AHQUAuY3yPbbJIIp575hEKXikgrBZRuJi8MV2L4dI9iIplGgGXd8h7rG Hc7X9/XQuVDr5pssBTNTt6/gzQ== X-Received: by 2002:a17:902:2ec1:: with SMTP id r59mr16575570plb.254.1549544178148; Thu, 07 Feb 2019 04:56:18 -0800 (PST) Received: from localhost ([2402:3a80:c80:4138:75dd:3900:1d90:762f]) by smtp.gmail.com with ESMTPSA id n186sm11863521pfn.137.2019.02.07.04.56.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Feb 2019 04:56:17 -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 v1 14/24] drivers: thermal: tsens: Add new operation to check if a sensor is enabled Date: Thu, 7 Feb 2019 16:19:32 +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 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(+) -- 2.17.1 diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-common.c index 39cd5733fd44..020409d8daf0 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 02907751c201..ad1052e05e45 100644 --- a/drivers/thermal/qcom/tsens-v0_1.c +++ b/drivers/thermal/qcom/tsens-v0_1.c @@ -332,6 +332,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 ------ */ /* UPPER_LOWER_INTERRUPT_CTRL */ diff --git a/drivers/thermal/qcom/tsens-v2.c b/drivers/thermal/qcom/tsens-v2.c index 962e47c54dca..e0aac59d72ec 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 20d89f8a6c3e..da4cfb23dfe9 100644 --- a/drivers/thermal/qcom/tsens.h +++ b/drivers/thermal/qcom/tsens.h @@ -254,6 +254,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;