From patchwork Thu Feb 28 12:21:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Kucheria X-Patchwork-Id: 159358 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp576632jad; Thu, 28 Feb 2019 04:27:24 -0800 (PST) X-Google-Smtp-Source: AHgI3IaNvaq6uMEfiAeoGvHguI6V7xLH0+MCPQokHMVa6YG7bXeYrVyQDqH8VFIQhSbkFSe2+hNR X-Received: by 2002:a63:3193:: with SMTP id x141mr8191323pgx.438.1551356844013; Thu, 28 Feb 2019 04:27:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551356844; cv=none; d=google.com; s=arc-20160816; b=0WKQeJYRV6++UWg18Y7yhRI32nZYdkc25Nuv2SlOCUjs7fMOKCo9hcwFqPIsdAm1H8 vkGyE5ZOt6s10XBd+Eqzl+T62eduGAHlUcSgT668sf14nR0k7dpnL8HIGdPGiWdn2Bjv mRVJQ2rHXFi5hDIHMLin+K6XrALddWEYL1th6/xpZ/52j6VNZJwkN1uheiAeTlhqPJ1b mFchcTXboLxKu1z8qP3kJh025tO4oJ17Ud6aNdu77DR1a6W8+Wju3snK5YvLzuDBTxLL MDNTkwqLhO3SAoo52KA4Y7ow8gWVsqVPlU/loRw7ikpp75e2KXZgPC0G+Ivc2Vaq1Ls2 EiUA== 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=/1gd8IKg0q3LX4r6cAyTmT7v/j8x/tNCsc6wFDx80aM=; b=EaNLPTDx/3BdnadIo08sTlKIp2a0+HaD0iHMmVu294OBqanQQzTJgXRRGHGCKKR1tz uzj0JpYnF3L3PJcE/MMprWafNoD7wXc9ieMuT8bkLRCMU2MhNwWnYWoaefdFRGBGUSB0 BZQxOmlP3dzN2o4nFVAn8WU3wMU9qtRnh2X5u91y58zIPBcKRNgxLWEgPyMHUTFjjz7N Or6nN5iRZMiASZy72FjEWCNAeclKoWjSt4uPGdR4YeE3rAUFLtVwnST3lH+ig7ncYWa/ cB4cYQZ2IYdzr1oyE3UBhWeKxTkEy6asaPIuFekFnIHxU+0/Ue+7e92yn2Jed2qCULuW VDag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FEtnL2+z; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 l84si8188625pfi.35.2019.02.28.04.27.23; Thu, 28 Feb 2019 04:27:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=FEtnL2+z; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1731489AbfB1M1W (ORCPT + 11 others); Thu, 28 Feb 2019 07:27:22 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:39931 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731300AbfB1M1W (ORCPT ); Thu, 28 Feb 2019 07:27:22 -0500 Received: by mail-wm1-f65.google.com with SMTP id z84so8737271wmg.4 for ; Thu, 28 Feb 2019 04:27:21 -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=/1gd8IKg0q3LX4r6cAyTmT7v/j8x/tNCsc6wFDx80aM=; b=FEtnL2+zEr1y4zaaSepprM7ePpRRUD5cagUQjg1rd3c7yC0S+8GoZzEkEhs7tPrOd6 Dhg16OAHXf+azPP9cZc6M/5Z4ydJI4orAHoFMEvFNa/OCy0bNazmakxaIvxnx72j5OHj rFINWiNYW4HZp/oK9u3KFSB65iGOBiewYd3/ApmrEhldqEiRprG5wVXpHIUdy6wU/LdG AWIJmo4+BFphq1TzKml9Ow+346gSFmvLHapF3I3wnrzGhvzCW4cUfYfRHrO/V+a1QU6w FkdIXDmfa7OqOlDGbl1ODVXdai+mapQtmMVuHgChIkSJerxgMAfW7NyRAfwRsPix6Nf9 Ehgg== 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=/1gd8IKg0q3LX4r6cAyTmT7v/j8x/tNCsc6wFDx80aM=; b=geP/ZRn3kSPhj0bCg0oXvfybgrxV29PjZZw3O1SIOf807S/ggv7g1dmhoOZcVGUVEi BBMMBCX3mOajlDoxSd834a87WRgtVOYpLGLKLpTBmXFRIfEeA07bQm4zqRZDgjROhyrL me06OCtTNv4yZYyBvjwI2o6StbqAZDHzga5qUnLfR5shevG/TWP09cEYa+oaJpHHvbzD hju94YceAvBv68F6uKQXYWFSYwxTThUbWk1fZajjGIRyplMNdw/CFhy08qidbvh3vChS +KwaSA55NPgmlJjJyj3Q5Fz7a2l57FibwXDn+tM9AObZwiHNdSpZ0a4BNLIqo50J0nTa FzUQ== X-Gm-Message-State: AHQUAua2YPnD6NOsVcrh7PENDaY5yF9QSctVX86HKNjjVfxuUvkX1W9E OeTtBFUqZaqHfdWH/Bo0eYWCTw== X-Received: by 2002:a1c:101:: with SMTP id 1mr2800221wmb.128.1551356840423; Thu, 28 Feb 2019 04:27:20 -0800 (PST) Received: from localhost ([49.248.54.130]) by smtp.gmail.com with ESMTPSA id t133sm4333009wmf.3.2019.02.28.04.27.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Feb 2019 04:27:19 -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 v2 14/24] drivers: thermal: tsens: Add new operation to check if a sensor is enabled Date: Thu, 28 Feb 2019 17:51:04 +0530 Message-Id: <6d377f9e12f513edde6e82ed28803172c45731ab.1551355503.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 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 8d632de2c7f8..c58ba4c200bc 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 1c0428daa9c4..837e7872e512 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 e021b6dd2420..7346bfc9efe6 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 a93d14dee69b..023fed3352e3 100644 --- a/drivers/thermal/qcom/tsens.h +++ b/drivers/thermal/qcom/tsens.h @@ -362,6 +362,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;