From patchwork Mon Oct 21 10:35:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Kucheria X-Patchwork-Id: 177042 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3223777ill; Mon, 21 Oct 2019 03:35:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqwpXnL1+N7jwBFlkMrSUM17lP0c8b/JFOga+LJx94p7NwLifRq8VDRUQ55O7nKAQM3c06fp X-Received: by 2002:a05:6402:17ec:: with SMTP id t12mr1096775edy.37.1571654150699; Mon, 21 Oct 2019 03:35:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571654150; cv=none; d=google.com; s=arc-20160816; b=fvzybq7rKamZZaKGbGebtdLEtLUd4sI8wuVRzE3GEtnqogvxtqKMoNUIsj1A1LPvXU yRrOj9g3GBa4gYjrh3Se2ZE0QkMuKFnPm7BCTX6XpQJXvmw1kudPuZafY7ZD9BvTRUlO Qu9ChBF5TVmJfbdwf7Ul5gOM1c4nCs0vTscDdl/vhXTNHQqN8lptboknnegjCvm6+//A BjfdiMORh7gF5LZyf+CvAJaL0DilAcMnVbK8snbvDNiRnRisEvWn7YM59TCTqAPU9QGB DPtom5nnAWd08O7iOpCXpD87EbxfSpvIfoYPrSTW9Ey2U2u7LvONrj7yp5p81TFnghNC LHBg== 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=LZlCeZrRTo7/0do93bbsot+ttbvRMEOWIgpwlWXPhlQ=; b=xWjpOM8RkNciz4PhcQJ4HMr13nyH/r1JMA6DPNO2my4caorvD5Kssyat8BkYhla+mb f/TrR7/ASqaSSdZpSCIRhy3hKyUfp2SUVrIWPbeyDjf1OJDvsrBsHwk1MUW8nuPmTbAy bgrlFQNYyami6Bzd/fyMjECCAXpSwBMBSsYwWYHYWytEX37lNn2b0rDyeQst0G17MyOX Nqm3irbsjhNzXb+AUbbWgUpClVGVSoyAOGLnTGq23Zo2aOJxv5wciaKyMO7yzjhD41LN XYKUq5ZtLE8L5Do0Q1V7RHhPgFN3ZzduBIwSG14VuXKCRaV+VDu4JMb5gvK49jZJ41Fo aoDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zL8ZrW5N; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 b44si9634713ede.451.2019.10.21.03.35.50; Mon, 21 Oct 2019 03:35:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=zL8ZrW5N; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1728224AbfJUKfs (ORCPT + 26 others); Mon, 21 Oct 2019 06:35:48 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:33764 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728197AbfJUKfr (ORCPT ); Mon, 21 Oct 2019 06:35:47 -0400 Received: by mail-pf1-f195.google.com with SMTP id q10so8192298pfl.0 for ; Mon, 21 Oct 2019 03:35:46 -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=LZlCeZrRTo7/0do93bbsot+ttbvRMEOWIgpwlWXPhlQ=; b=zL8ZrW5Nswpqr8PYA8T7fIK4mVVnRxIouA8raLosaE/PRRBX49O1fSlHN5VI8HgYBN k3HX+93GASSwAaW2Mn08tXvJs0GA6WM37fnYn9PCAIwsmy9SM+ot/qANbHPHBl9ik8YL Eo7lRjXkBjDkz5kpZifLl+Po8Enh6n1zjrEPtH6BULz2eWr6eOereG1CV9T3Qsns8ZWV 4MxHWd2Niz8bHkgJaYiDGSEWO49AUS4v1wTPWJSD/i4QtHqyTz3i4AS/JAxUFD0gxk0c 7OwwH6stPyXXs2oTWl3kj2bhEK6jjO7x9QEJcBUK3YTC3aVpewXYRIFztzII2rLnuddY /dZA== 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=LZlCeZrRTo7/0do93bbsot+ttbvRMEOWIgpwlWXPhlQ=; b=J2q96Gc51wNok5//03xgmu+yvtJ3l/knN1kLsbRnFkccU9rz8JhmoQD22WzXWuhcqH zRhp/rzE2ftA3wbWUnon9eOdkuABsx9mRajqoWYMdwnc7R6JjYc0FeGpiULtMx2yLoub yjJJDrsySsL6KUeW2CPpP/ndDUf/KFMnivox+Cdnwx0Gj88usMxzga/KlGciF6mICKQ6 D4qNf9nVHkQ7qckUtGhVINixKbn9BEbuPs55Ww1QG2zFHOB8B1ZORL4mwOBk12DyR59Q fcfHP7Gq2kNF1cK2820dxS/IxR0voF4JFIqw00df4QiCHeO3kQK/sTqTngaIzX3AwTIN Y+oA== X-Gm-Message-State: APjAAAWWxIypaK2SOtvm3RwKrgHirYRlaA9Vhp82YVFno5sd2f8kMmfU wV1OdokFquZ+et5l4xxGC1E/R47bIyFVUg== X-Received: by 2002:a62:750d:: with SMTP id q13mr21620042pfc.58.1571654145915; Mon, 21 Oct 2019 03:35:45 -0700 (PDT) Received: from localhost ([49.248.62.222]) by smtp.gmail.com with ESMTPSA id t21sm15041040pgi.87.2019.10.21.03.35.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 Oct 2019 03:35:45 -0700 (PDT) From: Amit Kucheria To: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, bjorn.andersson@linaro.org, edubezval@gmail.com, agross@kernel.org, masneyb@onstation.org, swboyd@chromium.org, julia.lawall@lip6.fr, Amit Kucheria , Daniel Lezcano , Mark Rutland , Rob Herring , Zhang Rui Cc: linux-pm@vger.kernel.org Subject: [PATCH v6 01/15] drivers: thermal: tsens: Get rid of id field in tsens_sensor Date: Mon, 21 Oct 2019 16:05:20 +0530 Message-Id: <30206cd47d303d2dcaef87f4e3c7173481a0bddd.1571652874.git.amit.kucheria@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are two fields - id and hw_id - to track what sensor an action was to performed on. This was because the sensors connected to a TSENS IP might not be contiguous i.e. 1, 2, 4, 5 with 3 being skipped. This causes confusion in the code which uses hw_id sometimes and id other times (tsens_get_temp, tsens_get_trend). Switch to only using the hw_id field to track the physical ID of the sensor. When we iterate through all the sensors connected to an IP block, we use an index i to loop through the list of sensors, and then return the actual hw_id that is registered on that index. Signed-off-by: Amit Kucheria Reviewed-by: Stephen Boyd Reviewed-by: Daniel Lezcano --- drivers/thermal/qcom/tsens-8960.c | 4 ++-- drivers/thermal/qcom/tsens-common.c | 16 +++++++++------- drivers/thermal/qcom/tsens.c | 11 +++++------ drivers/thermal/qcom/tsens.h | 10 ++++------ 4 files changed, 20 insertions(+), 21 deletions(-) -- 2.17.1 diff --git a/drivers/thermal/qcom/tsens-8960.c b/drivers/thermal/qcom/tsens-8960.c index e46a4e3f25c42..fb77acb8d13b9 100644 --- a/drivers/thermal/qcom/tsens-8960.c +++ b/drivers/thermal/qcom/tsens-8960.c @@ -245,11 +245,11 @@ static inline int code_to_mdegC(u32 adc_code, const struct tsens_sensor *s) return adc_code * slope + offset; } -static int get_temp_8960(struct tsens_priv *priv, int id, int *temp) +static int get_temp_8960(struct tsens_sensor *s, int *temp) { int ret; u32 code, trdy; - const struct tsens_sensor *s = &priv->sensor[id]; + struct tsens_priv *priv = s->priv; unsigned long timeout; timeout = jiffies + usecs_to_jiffies(TIMEOUT_US); diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-common.c index 528df88012543..c037bdf92c663 100644 --- a/drivers/thermal/qcom/tsens-common.c +++ b/drivers/thermal/qcom/tsens-common.c @@ -83,11 +83,12 @@ 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) +int get_temp_tsens_valid(struct tsens_sensor *s, 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; + struct tsens_priv *priv = s->priv; + int hw_id = s->hw_id; + u32 temp_idx = LAST_TEMP_0 + hw_id; + u32 valid_idx = VALID_0 + hw_id; u32 last_temp = 0, valid, mask; int ret; @@ -123,12 +124,13 @@ int get_temp_tsens_valid(struct tsens_priv *priv, int i, int *temp) return 0; } -int get_temp_common(struct tsens_priv *priv, int i, int *temp) +int get_temp_common(struct tsens_sensor *s, int *temp) { - struct tsens_sensor *s = &priv->sensor[i]; + struct tsens_priv *priv = s->priv; + int hw_id = s->hw_id; int last_temp = 0, ret; - ret = regmap_field_read(priv->rf[LAST_TEMP_0 + s->hw_id], &last_temp); + ret = regmap_field_read(priv->rf[LAST_TEMP_0 + hw_id], &last_temp); if (ret) return ret; diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c index 0627d8615c307..6ed687a6e53cd 100644 --- a/drivers/thermal/qcom/tsens.c +++ b/drivers/thermal/qcom/tsens.c @@ -14,19 +14,19 @@ static int tsens_get_temp(void *data, int *temp) { - const struct tsens_sensor *s = data; + struct tsens_sensor *s = data; struct tsens_priv *priv = s->priv; - return priv->ops->get_temp(priv, s->id, temp); + return priv->ops->get_temp(s, temp); } static int tsens_get_trend(void *data, int trip, enum thermal_trend *trend) { - const struct tsens_sensor *s = data; + struct tsens_sensor *s = data; struct tsens_priv *priv = s->priv; if (priv->ops->get_trend) - return priv->ops->get_trend(priv, s->id, trend); + return priv->ops->get_trend(s, trend); return -ENOTSUPP; } @@ -86,8 +86,7 @@ static int tsens_register(struct tsens_priv *priv) for (i = 0; i < priv->num_sensors; i++) { priv->sensor[i].priv = priv; - priv->sensor[i].id = i; - tzd = devm_thermal_zone_of_sensor_register(priv->dev, i, + tzd = devm_thermal_zone_of_sensor_register(priv->dev, priv->sensor[i].hw_id, &priv->sensor[i], &tsens_of_ops); if (IS_ERR(tzd)) diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h index b89083b61c383..84e5447c56860 100644 --- a/drivers/thermal/qcom/tsens.h +++ b/drivers/thermal/qcom/tsens.h @@ -32,7 +32,6 @@ enum tsens_ver { * @priv: tsens device instance that this sensor is connected to * @tzd: pointer to the thermal zone that this sensor is in * @offset: offset of temperature adjustment curve - * @id: Sensor ID * @hw_id: HW ID can be used in case of platform-specific IDs * @slope: slope of temperature adjustment curve * @status: 8960-specific variable to track 8960 and 8660 status register offset @@ -41,7 +40,6 @@ struct tsens_sensor { struct tsens_priv *priv; struct thermal_zone_device *tzd; int offset; - unsigned int id; unsigned int hw_id; int slope; u32 status; @@ -62,13 +60,13 @@ struct tsens_ops { /* mandatory callbacks */ int (*init)(struct tsens_priv *priv); int (*calibrate)(struct tsens_priv *priv); - int (*get_temp)(struct tsens_priv *priv, int i, int *temp); + int (*get_temp)(struct tsens_sensor *s, int *temp); /* optional callbacks */ int (*enable)(struct tsens_priv *priv, int i); void (*disable)(struct tsens_priv *priv); int (*suspend)(struct tsens_priv *priv); int (*resume)(struct tsens_priv *priv); - int (*get_trend)(struct tsens_priv *priv, int i, enum thermal_trend *trend); + int (*get_trend)(struct tsens_sensor *s, enum thermal_trend *trend); }; #define REG_FIELD_FOR_EACH_SENSOR11(_name, _offset, _startbit, _stopbit) \ @@ -314,8 +312,8 @@ 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); +int get_temp_tsens_valid(struct tsens_sensor *s, int *temp); +int get_temp_common(struct tsens_sensor *s, int *temp); /* TSENS target */ extern const struct tsens_plat_data data_8960;