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: 160679 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp282776jan; Wed, 20 Mar 2019 06:19:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqyysF6r8LI+0bFcOrmAtVy06r8wPQp3Ea/alDlCcixv5ypwyKBsOFK8j8PtXecGnRaK4QLa X-Received: by 2002:a63:5321:: with SMTP id h33mr7502994pgb.168.1553087964947; Wed, 20 Mar 2019 06:19:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553087964; cv=none; d=google.com; s=arc-20160816; b=XI4MpGuOku4vwoJUjEuoXbQ5gaOljd8bNx1htScbw9SFvc+PjgTFwWQ+vx/qLsgORL f9CCrpUcQdTzLbep48b2HzlLiTNXNuC3rZlaqVsvoJ3V9iG+BbFeFdRiIhXwCfU01Mil bCbTT+MOfnrI15xdMoMMD1G8qXO8ZCBx2XXVN4d6elxUS9D+52nR5RpaH42tfUt5oQIQ rN/9sH8vCJAS1wBgw7ovUILqM9VUN5tnPChIiKbxuSjuH66eG/qk+a0WsG1Ov/xOcSK+ agTFH35nlh0wMaUxlVUDZ7T9zw6xRwxJQ+jm95lde8Ulcn9InODRXkLjSzWBTbSVuD8R D8Hw== 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=hnKCIBqLKSdwQJ9vlhhug9tJeolwVOLt4rLlaA/Eryo=; b=Oy1TSQ9kkDQQIhYCYZubau39TKQNnDkkfKkg6dAVlr1TKSoIBjmYeGGBcwTfYga1c0 qnVndxJxFBGzTKrx8jFyJR/KxqWK8DLXaMpCdX6ed+xR4CpFBT1+f+H/ajfV/t0Xrkrx kUXZvo+bFYXy9Yt2eKFsS0jjNNILjSicktXSq26vqd6iGXGDK5YDEKAEKVt3rK2M5THp IanAm5bBFc+dwgckamoar/ID83htpswFN70bHjwpRBrrAZqfdTod8s0oAiwtQ/s5mC1g FX6MnxBKwr7FNZcaNsFQfGbHkvrkb2Qf/Dxid/f4xpg+60nHbn0eE2vhSuD1iFJaCxoS lV/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uRiRyUVT; 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 139si1631572pga.219.2019.03.20.06.19.24; Wed, 20 Mar 2019 06:19:24 -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=uRiRyUVT; 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 S1727927AbfCTNTX (ORCPT + 15 others); Wed, 20 Mar 2019 09:19:23 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:39814 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728246AbfCTNTW (ORCPT ); Wed, 20 Mar 2019 09:19:22 -0400 Received: by mail-pf1-f193.google.com with SMTP id i17so1925449pfo.6 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=UZGrVjRF2lQ/c6b4ECcU0+wDhVag33gukk+EV9ZcQP7VSJ3dbUcUV9rlEGuOlr1FUo +mTPs5Oa3mcrm8b+qQnXuYi6hJ3gcyD6kkUnjANEj8X9N+UO1DM5G6fBrdXOPblKxgvQ bFwhBpcvc1OPq6vyvm5EgeBtwnYHHf10uMt3+o2C9ammOZFK+Puf+Ne/+xbIyQiZ/Hjr 2swf3gjraQ9ZKVlVLzOxqXUx4297bSNOlsJkSmef0iHM+ao2efEk3Bzxx3VY1SqyB0ew beNNdvOcKdemreLgTRftQT8RlZWowF5/WwbpeJH4CFy0qZjUa5aaVUgpdYia6fdE1ta6 y4AQ== X-Gm-Message-State: APjAAAW/8NTktKJJqfdjz9AbUgMpgF7Q+j35pNgDk4bUKaWsxWA6mYoP k1e4DQZeIBUld27nlBLSn4lhKQ== 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-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 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;