Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp1510539ybx; Thu, 31 Oct 2019 11:39:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqwMhjWppoqwT5YxqhEhDqSl0owF5TqRkcDvj9vt9uz1lQt6nhsVxv34XBRlUqXH10YcRbdg X-Received: by 2002:a50:9555:: with SMTP id v21mr7982096eda.90.1572547144846; Thu, 31 Oct 2019 11:39:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572547144; cv=none; d=google.com; s=arc-20160816; b=GIycnZbNk8jIWc6BoOo0OTav5qNZ1DCB2cV1FVfn0OP7dccvMJbolfF5VD/IQtqync 4bvDO4yACuiNKbARh8NOxb8oKP+ULx4iY1dBlTZf8LF3f0Xj+z7QKM5X2FOYY3YBcx+C scTov5xpmn4NggSNlcW+aCB3vJBubymWhEHxk09cSaPnZfMSonVhRdV7CVT7m4QxqpnO 5g657l4V86UdZlWiv9YH0Lp04OU18nqimhuL/sqiDj4Ylh2lqr/oeMnkrJii2sn1U+LW pS9esnFnq7erY77BaTNnQjvxCjo9cV7ZfG/SuGHXehWmaW30JQTLLii4jPQSTGgulxsz XNBQ== 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=rO1z1JlGDHGdy6zVD5fls33iWqIXWjt9KmTfIa3Qj2w=; b=oMN3IiQ+mp9dVz30Ifx8dzlPj92SlYRg/zX3yXtn0g7dxsGUFCUz24EFbjZwda5WWm cojrkeLwNGyMSNHeHyf4BEQkxrROrn3+cGJPGyn4KqsHVnqzUVRlK95lZPQaF3BJzChc mJBo7LSPXLDC9ppR5CkuVAwd29HHCQrIbT/WveJIglUQzxSMjGBJPdL3ji4fMZVzs2s2 BAlbtn2bIYHB+sWo76xUtLCSAW2Qy6vAO2U4PG7fv2bfzWeir2sf9LDgq3e4KFfM7ols w2sX8YoH64UinZg8pVOl2clqaAUyKjHViEeuccNh3Yy5LIpa0VPtM+pH29466ZmD3fi3 u2fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ORqnI9Il; 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 d7si4983363eda.429.2019.10.31.11.38.41; Thu, 31 Oct 2019 11:39:04 -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=ORqnI9Il; 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 S1729396AbfJaSh5 (ORCPT + 99 others); Thu, 31 Oct 2019 14:37:57 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:41915 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729266AbfJaSh4 (ORCPT ); Thu, 31 Oct 2019 14:37:56 -0400 Received: by mail-pl1-f194.google.com with SMTP id t10so3069953plr.8 for ; Thu, 31 Oct 2019 11:37:55 -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=rO1z1JlGDHGdy6zVD5fls33iWqIXWjt9KmTfIa3Qj2w=; b=ORqnI9IlV/hEKajizXIQ38aByJEbH16XAIJ47m762ndSW+Cg7/flRjMn9Dex39IfBV fk/l/3LRz+65JvRSp7HpTojtAeLqCwLiCM/le6ZAdo+dg851R3QBk+A7Kdka/V0n/oad qQqdKuN/+MUc0OmepCu+YWZ3aEZsjh4F55BsTSnZk0pa9wsS+T9Ppjk9FZX65Agq1ZCR 0y5H4PCwSOodflkhRWihZLipb1RQMKN6J5jvZ7qelvK0F7iZnQAtqFGY8vuG+KwocAdI e3wbKqm4FhdhZskFhhNIQRdkmeFtiJcVU/VCoXt7oHb4wjZQbxbvu1x4USkKFXXr9X1Z vfgA== 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=rO1z1JlGDHGdy6zVD5fls33iWqIXWjt9KmTfIa3Qj2w=; b=mYcKF9y44jcX72r7hA6pWlbcULOcRSYuvT2bPcG1Ah1P7YYKgmGByUSOSibHd9ZI8F NeTn/MdP675uEgiCxUPLTQpt9114o+8Q0Wq/yuBYzyJC9MMDw4KkIaA6NWvyuPFNfmat hSc+ZiJ4bGkGr1h0QmMZctgrNKTbSRbN9ItMpad8haYkHRC/eYOzhD7YetmzbuJ4jumF Xwzt/rw8eqUbxbN1gQEC8eSvqr1IGMxufqlC2UiZRUwVaobS6pjfF99H1JxnvsTry81t T5z1S3GYJEyr7MwR2872fSmqlUVaw49IidSz2GMVnQeGnbet3d4jcZOkUU+9jC55Nl8t Yfsw== X-Gm-Message-State: APjAAAVZD/uarNkWabZ3Gm6/yxiOm+/ceD7KiBd9JG1rN5q9ic0ZBU+U 5HIXK49m6ti1LWjWRntGwvedDRuqm/NaXg== X-Received: by 2002:a17:902:9a88:: with SMTP id w8mr7780658plp.129.1572547074428; Thu, 31 Oct 2019 11:37:54 -0700 (PDT) Received: from localhost ([49.248.58.234]) by smtp.gmail.com with ESMTPSA id x14sm3744161pfm.96.2019.10.31.11.37.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 31 Oct 2019 11:37:53 -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 v7 01/15] drivers: thermal: tsens: Get rid of id field in tsens_sensor Date: Fri, 1 Nov 2019 00:07:25 +0530 Message-Id: <30206cd47d303d2dcaef87f4e3c7173481a0bddd.1572526427.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(-) diff --git a/drivers/thermal/qcom/tsens-8960.c b/drivers/thermal/qcom/tsens-8960.c index e46a4e3f25c4..fb77acb8d13b 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 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 b89083b61c38..84e5447c5686 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; -- 2.17.1