From patchwork Wed Sep 11 07:16:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Kucheria X-Patchwork-Id: 173589 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp374101ilq; Wed, 11 Sep 2019 00:16:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqxYTx60akevb4yz8/aYSXwVxq7rcQ+90SbgMisA3orD/Kl90Sz54ar09DY+m7JBIytp8Jb6 X-Received: by 2002:a50:adea:: with SMTP id b39mr34360759edd.16.1568186208608; Wed, 11 Sep 2019 00:16:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568186208; cv=none; d=google.com; s=arc-20160816; b=Fy7zeYa9vy7wLwY9AiQB/wVg55W49p8IMC8NwEq0lac9bdvxc1amDFyf1+XlxbAXAp 2olJvrNz4Nn5rMCFTB5mOKouzmzuScKORbOffkaGxmMKy7IX649PhOwxujtwgqsNfZoR Df0Uc+6YwKzBxWNbDDzVkKrbr5iSkOFeO+wTVqnvs81cyg8oyB2TIzRO6IoB3z7GJsRD 8Jx8Bva+dfTeutp0SczL2G85nyzaDuJeeEPIer8eA9rXoNZaJuo09nZ4SAiluzxi0f3/ 56zUHyOWOK95bePmC9Z9cG94xXZStk4T2/CumBpuSl7/UkUs+msUTaJ8rgXonZaqFCaY APaA== 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=TYv2LRSteD77Ft4oMs2p5uadS2z0S5817oCjy76gUik=; b=yQqksBxjmcGYlHiomFkFs8kFT+3FT10rHD6ROk1hRLsGvtqvX/fkISOVWWfNkJHbOr ATQ/A6m4PyGww9kb8SNDCbF4jnGDk3G1Gz//qmnLsyyccWa0/0fuHk+qah1TFEfhXhFo FPIXN3pCCQIA3I1moIy86EYtYpLLWszmGbKpfg5EBwDZsfUlA0QRtTj5topD56DSUtLS NQKKUkdhUSRujSB6EX95mzdA+mLNb7qvJ/v0e2lbrsUonECKT/akUE05oY9u9NvXiKNb qbm9lUE0/8/sC6x7MPakFIsopjx+YE8ALvqFQFHV99MF8vgJMVGaC33o+H3lbSGLAZWn 6vMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kj1j7ZaZ; 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 u2si2623689edp.191.2019.09.11.00.16.47; Wed, 11 Sep 2019 00:16:48 -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=kj1j7ZaZ; 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 S1726981AbfIKHQq (ORCPT + 27 others); Wed, 11 Sep 2019 03:16:46 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:43842 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726838AbfIKHQp (ORCPT ); Wed, 11 Sep 2019 03:16:45 -0400 Received: by mail-pl1-f194.google.com with SMTP id 4so9766047pld.10 for ; Wed, 11 Sep 2019 00:16:44 -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=TYv2LRSteD77Ft4oMs2p5uadS2z0S5817oCjy76gUik=; b=kj1j7ZaZnPMmsnHMvLk21yvm6k06hUpqx9YhvZYRoF6tMhQMm0Xwl9/12rAOGIgwzx eq7LSwvZ4sQ+28fB0GlNOPcQAO3YX3dYBDIaViLNagUmizZpuQ6Di0kx8+8BVsqL+s7N 00GftV/JgicBTz/hUdyP5F676NgJcH3W8ipSdvX2WpWvjRALyUOXSdeLmH9foo3KszN1 V7uKmYfr2nV4eXhYXRSet6ddkiSS7qTTz5/723Vn5/wQReRwyM+Wc3qtErxADzeRSngj dkNSJqcMxS4eZxtOMzpLdkxgr/+uinY1c9PS8tL188zltSAY6AZAfsP25ffuY1jclE76 xH5w== 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=TYv2LRSteD77Ft4oMs2p5uadS2z0S5817oCjy76gUik=; b=d5+mGtJ9LsVxDeTx9yoDeYuVusoo6LD+qWdqN3yMZKuHJGtDfGjgxKkqrE56SvYjM6 CictoTxotJH3sHWKLEjPqyTqP8cK245UjC8mKQZMNThiSTkZVxfEyYY9hV2i90t0Uqwt Hqm52gRf3cFImznL6y3oh1LKq/Vr0P3jf9F+j38saofUGFoajMZ9OyVFtJTLUBULh5mf Z71OlbEQEo3TpiP1Vk87fEDxWVXqJkmo0C9uw5FpH2AAKe3BncFY81cS1Xvw8mdwuKlt A26iNAQZFKS1y8VJoS952T2n09VVnPHLy9D8KiiPNi7tx2J2HYLydVXq5JBxVw3BGdTA 4Sxw== X-Gm-Message-State: APjAAAVnga14FDAF44RftaQUFl+I0GIBdcci4Wss9yJaUQjk8seugnjW mqWhmmgjDN7G5jY9pKtEU6HLFPOWKV5+Sw== X-Received: by 2002:a17:902:8506:: with SMTP id bj6mr36138092plb.79.1568186204168; Wed, 11 Sep 2019 00:16:44 -0700 (PDT) Received: from localhost ([49.248.201.118]) by smtp.gmail.com with ESMTPSA id j2sm20842070pfe.130.2019.09.11.00.16.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Sep 2019 00:16:43 -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, Daniel Lezcano , Mark Rutland , Rob Herring , Zhang Rui Cc: linux-pm@vger.kernel.org Subject: [PATCH v3 01/15] drivers: thermal: tsens: Get rid of id field in tsens_sensor Date: Wed, 11 Sep 2019 12:46:18 +0530 Message-Id: <0ada60b1b216346e3e9e2429af8c2b7c9901c938.1568185732.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 8d9b721dadb6..3e1436fda1eb 100644 --- a/drivers/thermal/qcom/tsens-8960.c +++ b/drivers/thermal/qcom/tsens-8960.c @@ -243,11 +243,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 528df8801254..c037bdf92c66 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 0627d8615c30..6ed687a6e53c 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 2fd94997245b..d022e726d074 100644 --- a/drivers/thermal/qcom/tsens.h +++ b/drivers/thermal/qcom/tsens.h @@ -31,7 +31,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 @@ -40,7 +39,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; @@ -61,13 +59,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) \ @@ -313,8 +311,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;