From patchwork Tue Mar 10 17:00:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 11429951 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D748B18E8 for ; Tue, 10 Mar 2020 17:01:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B143022525 for ; Tue, 10 Mar 2020 17:01:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726669AbgCJRBY (ORCPT ); Tue, 10 Mar 2020 13:01:24 -0400 Received: from bin-mail-out-05.binero.net ([195.74.38.228]:28489 "EHLO bin-mail-out-05.binero.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727146AbgCJRBX (ORCPT ); Tue, 10 Mar 2020 13:01:23 -0400 X-Halon-ID: be57ab94-62f0-11ea-aa6d-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2392.dip0.t-ipconnect.de [79.202.35.146]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id be57ab94-62f0-11ea-aa6d-005056917f90; Tue, 10 Mar 2020 18:01:11 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: linux-pm@vger.kernel.org, linux-renesas-soc@vger.kernel.org Cc: =?utf-8?q?Niklas_S=C3=B6derlund?= Subject: [PATCH 1/3] thermal: rcar_thermal: Always update thermal zone on interrupt Date: Tue, 10 Mar 2020 18:00:27 +0100 Message-Id: <20200310170029.1648996-2-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200310170029.1648996-1-niklas.soderlund+renesas@ragnatech.se> References: <20200310170029.1648996-1-niklas.soderlund+renesas@ragnatech.se> MIME-Version: 1.0 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org Since commit a1ade5653804b8eb ("thermal: rcar: check every rcar_thermal_update_temp() return value") the temperature is always read in rcar_thermal_get_current_temp() so comparing it before and after enabling interrupts have little effect. Remove the check and always update the thermal zone when we get an interrupt that the temperature have changed. Signed-off-by: Niklas Söderlund Reviewed-by: Geert Uytterhoeven --- drivers/thermal/rcar_thermal.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/drivers/thermal/rcar_thermal.c b/drivers/thermal/rcar_thermal.c index 8f1aafa2044e5ba7..f379eb5f8b9ecd14 100644 --- a/drivers/thermal/rcar_thermal.c +++ b/drivers/thermal/rcar_thermal.c @@ -387,28 +387,17 @@ static void _rcar_thermal_irq_ctrl(struct rcar_thermal_priv *priv, int enable) static void rcar_thermal_work(struct work_struct *work) { struct rcar_thermal_priv *priv; - int cctemp, nctemp; int ret; priv = container_of(work, struct rcar_thermal_priv, work.work); - ret = rcar_thermal_get_current_temp(priv, &cctemp); - if (ret < 0) - return; - ret = rcar_thermal_update_temp(priv); if (ret < 0) return; rcar_thermal_irq_enable(priv); - ret = rcar_thermal_get_current_temp(priv, &nctemp); - if (ret < 0) - return; - - if (nctemp != cctemp) - thermal_zone_device_update(priv->zone, - THERMAL_EVENT_UNSPECIFIED); + thermal_zone_device_update(priv->zone, THERMAL_EVENT_UNSPECIFIED); } static u32 rcar_thermal_had_changed(struct rcar_thermal_priv *priv, u32 status) From patchwork Tue Mar 10 17:00:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 11429941 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5EBA992A for ; Tue, 10 Mar 2020 17:01:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 41F23222C3 for ; Tue, 10 Mar 2020 17:01:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726481AbgCJRBX (ORCPT ); Tue, 10 Mar 2020 13:01:23 -0400 Received: from bin-mail-out-05.binero.net ([195.74.38.228]:28499 "EHLO bin-mail-out-05.binero.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726716AbgCJRBW (ORCPT ); Tue, 10 Mar 2020 13:01:22 -0400 X-Halon-ID: beaacbdb-62f0-11ea-aa6d-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2392.dip0.t-ipconnect.de [79.202.35.146]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id beaacbdb-62f0-11ea-aa6d-005056917f90; Tue, 10 Mar 2020 18:01:12 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: linux-pm@vger.kernel.org, linux-renesas-soc@vger.kernel.org Cc: =?utf-8?q?Niklas_S=C3=B6derlund?= Subject: [PATCH 2/3] thermal: rcar_thermal: Do not store ctemp in rcar_thermal_priv Date: Tue, 10 Mar 2020 18:00:28 +0100 Message-Id: <20200310170029.1648996-3-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200310170029.1648996-1-niklas.soderlund+renesas@ragnatech.se> References: <20200310170029.1648996-1-niklas.soderlund+renesas@ragnatech.se> MIME-Version: 1.0 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org There is no need to cache the ctemp value in the private data structure as it's always prefetched before it's used. Remove it from the structure and have rcar_thermal_update_temp return the value instead of storing it. Signed-off-by: Niklas Söderlund Reviewed-by: Geert Uytterhoeven --- drivers/thermal/rcar_thermal.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/drivers/thermal/rcar_thermal.c b/drivers/thermal/rcar_thermal.c index f379eb5f8b9ecd14..953dc28d1dd1d499 100644 --- a/drivers/thermal/rcar_thermal.c +++ b/drivers/thermal/rcar_thermal.c @@ -95,7 +95,6 @@ struct rcar_thermal_priv { struct mutex lock; struct list_head list; int id; - u32 ctemp; }; #define rcar_thermal_for_each_priv(pos, common) \ @@ -201,7 +200,6 @@ static int rcar_thermal_update_temp(struct rcar_thermal_priv *priv) struct device *dev = rcar_priv_to_dev(priv); int i; u32 ctemp, old, new; - int ret = -EINVAL; mutex_lock(&priv->lock); @@ -247,32 +245,28 @@ static int rcar_thermal_update_temp(struct rcar_thermal_priv *priv) ((ctemp - 1) << 0))); } - dev_dbg(dev, "thermal%d %d -> %d\n", priv->id, priv->ctemp, ctemp); - - priv->ctemp = ctemp; - ret = 0; err_out_unlock: mutex_unlock(&priv->lock); - return ret; + + return ctemp ? ctemp : -EINVAL; } static int rcar_thermal_get_current_temp(struct rcar_thermal_priv *priv, int *temp) { - int tmp; - int ret; + int ctemp, tmp; - ret = rcar_thermal_update_temp(priv); - if (ret < 0) - return ret; + ctemp = rcar_thermal_update_temp(priv); + if (ctemp < 0) + return ctemp; mutex_lock(&priv->lock); if (priv->chip->ctemp_bands == 1) - tmp = MCELSIUS((priv->ctemp * 5) - 65); - else if (priv->ctemp < 24) - tmp = MCELSIUS(((priv->ctemp * 55) - 720) / 10); + tmp = MCELSIUS((ctemp * 5) - 65); + else if (ctemp < 24) + tmp = MCELSIUS(((ctemp * 55) - 720) / 10); else - tmp = MCELSIUS((priv->ctemp * 5) - 60); + tmp = MCELSIUS((ctemp * 5) - 60); mutex_unlock(&priv->lock); /* Guaranteed operating range is -45C to 125C. */ From patchwork Tue Mar 10 17:00:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 11429945 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4537692A for ; Tue, 10 Mar 2020 17:01:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1EF24222C4 for ; Tue, 10 Mar 2020 17:01:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726395AbgCJRBX (ORCPT ); Tue, 10 Mar 2020 13:01:23 -0400 Received: from bin-mail-out-05.binero.net ([195.74.38.228]:28505 "EHLO bin-mail-out-05.binero.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726716AbgCJRBX (ORCPT ); Tue, 10 Mar 2020 13:01:23 -0400 X-Halon-ID: bf03e7c3-62f0-11ea-aa6d-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2392.dip0.t-ipconnect.de [79.202.35.146]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id bf03e7c3-62f0-11ea-aa6d-005056917f90; Tue, 10 Mar 2020 18:01:12 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: linux-pm@vger.kernel.org, linux-renesas-soc@vger.kernel.org Cc: =?utf-8?q?Niklas_S=C3=B6derlund?= Subject: [PATCH 3/3] thermal: rcar_thermal: Remove lock in rcar_thermal_get_current_temp() Date: Tue, 10 Mar 2020 18:00:29 +0100 Message-Id: <20200310170029.1648996-4-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200310170029.1648996-1-niklas.soderlund+renesas@ragnatech.se> References: <20200310170029.1648996-1-niklas.soderlund+renesas@ragnatech.se> MIME-Version: 1.0 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org With the ctemp value returned instead of cached in the private data structure their is no need to take the lock when translating ctemp into a temperature. Signed-off-by: Niklas Söderlund Reviewed-by: Geert Uytterhoeven --- drivers/thermal/rcar_thermal.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/thermal/rcar_thermal.c b/drivers/thermal/rcar_thermal.c index 953dc28d1dd1d499..8bdcb449bd280a18 100644 --- a/drivers/thermal/rcar_thermal.c +++ b/drivers/thermal/rcar_thermal.c @@ -254,24 +254,20 @@ static int rcar_thermal_update_temp(struct rcar_thermal_priv *priv) static int rcar_thermal_get_current_temp(struct rcar_thermal_priv *priv, int *temp) { - int ctemp, tmp; + int ctemp; ctemp = rcar_thermal_update_temp(priv); if (ctemp < 0) return ctemp; - mutex_lock(&priv->lock); + /* Guaranteed operating range is -45C to 125C. */ + if (priv->chip->ctemp_bands == 1) - tmp = MCELSIUS((ctemp * 5) - 65); + *temp = MCELSIUS((ctemp * 5) - 65); else if (ctemp < 24) - tmp = MCELSIUS(((ctemp * 55) - 720) / 10); + *temp = MCELSIUS(((ctemp * 55) - 720) / 10); else - tmp = MCELSIUS((ctemp * 5) - 60); - mutex_unlock(&priv->lock); - - /* Guaranteed operating range is -45C to 125C. */ - - *temp = tmp; + *temp = MCELSIUS((ctemp * 5) - 60); return 0; }