From patchwork Wed Aug 30 08:47:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 111282 Delivered-To: patch@linaro.org Received: by 10.140.95.112 with SMTP id h103csp595119qge; Wed, 30 Aug 2017 01:48:58 -0700 (PDT) X-Received: by 10.84.194.195 with SMTP id h61mr1025279pld.435.1504082938718; Wed, 30 Aug 2017 01:48:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504082938; cv=none; d=google.com; s=arc-20160816; b=iF6HeBtpWPDzcqSLkfwsJZono97SPDQNGaonlbYztYP6BJI7ToIq023DOj9Z1nzjUF ko8uOeV7lodIbgOCIO2Pniwr6hli+AUO/Ln6UvxGmiOr3vkWkQ16vpOilfmoTqEDHCcs YeRg6xe3ajUaN/gFP0Q+xEugQQIbeU9Jpxr9+kAgZnRigyvlkIZ+wxenc/aqkGNiIkzu zadLn255G9vTeVgH2hHRp4lTDoiQBDCVgJ6uDKcAltOvkw7LGOVL2CGK6TMN0Jl2wVTG APfcBANLst+8VRJRxDe9mrNuF9QBps/UEMduKCjA2Fjle6DlEGWHi5u1vwAh7dt2Ir4V x/pg== 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:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=4+rAp94M2r7NZFrIVYg29+O5v7953i37MtsvlqJrtR4=; b=TNqybdrkb4501BRtC61+fBEvoLhuvLOUnyE7PHOLsAhWS6y6PyoE/+CHw5w0eRrIi9 XK/zRdRvG4tn46glVH1BymtJZkZNGj2irox96DTKNjbUxyaQi4SMFaophFFS4tc6Jpu2 ytzTbT5VH1PcBl/zbTO5ebhexi+XfW85hnSmEAqld1xQPJcq94iX7hFE7DAs/KSbbgfY JKyNdNjviGszZDOF7Mr61kbsXDCpZTvsL2cSQxUl87BZh1/QX9gA9gYHMswzmO712bUR yXG19smwB5OCWqR3BnesKRlI9kQ3l42K9dbZbiCC251cvqHIourAeQcCcjjSjw62VJEM hURA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SsnBMlNu; 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 i7si3903435pgt.598.2017.08.30.01.48.58; Wed, 30 Aug 2017 01:48:58 -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=SsnBMlNu; 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 S1751547AbdH3Isz (ORCPT + 26 others); Wed, 30 Aug 2017 04:48:55 -0400 Received: from mail-wm0-f43.google.com ([74.125.82.43]:38096 "EHLO mail-wm0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751484AbdH3Isw (ORCPT ); Wed, 30 Aug 2017 04:48:52 -0400 Received: by mail-wm0-f43.google.com with SMTP id t201so6048426wmt.1 for ; Wed, 30 Aug 2017 01:48:51 -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; bh=4+rAp94M2r7NZFrIVYg29+O5v7953i37MtsvlqJrtR4=; b=SsnBMlNu2WwG5mCcWJJtk8rkVBoI1V7V48t/zKizAgtit5Wn46GVdr8bUc5Xl4Ko/B /GwZkJ6OzuY6xANOAqz0WgEpcwLdxv1Il+g7GVklO9GryWG/ZeqeYjy/mMFkJYBYyLK2 7nHYixj4gTi62vC5hbMDfz8Hr1YjHJyXvVJ44= 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; bh=4+rAp94M2r7NZFrIVYg29+O5v7953i37MtsvlqJrtR4=; b=OJBaOZeGHfiE67eF+kpquTDtdDdT2PMUsAirqiLkK3b4taVRI8uWKNkwhXUhIaHMBT IF7GenNK5zEYB8e2y61izBGU7vgFm/XZKxeV1ntaKfXZDjRndmbaAweevdwuANLr/ONT 8O5tF9N7mVgnnLUoz2PdiuF0Ov/pHjZdzoGtqKnXRqEz+jOVUrL44JTv58YDT1r2/559 lEpuqznfi2nh+Yi2nPknaA3K2Uh1mxs+RF94ZGiokPWx+nrIi9KZh5OYzCeasToX79Xo 0zBb2drONygUmDZ0FIitSbdIoBMUugYPhLGn3PyrpB0/rWF4C6wFPoJderVEIQO3QiUF bPJw== X-Gm-Message-State: AHYfb5h5ZkB1bblsmU/fdxJuMEPVGi1Xhx66wd1ckE3v1rZDddRPmuwv qV25jNvRDWzQIcNp X-Received: by 10.28.109.81 with SMTP id i78mr803211wmc.24.1504082930946; Wed, 30 Aug 2017 01:48:50 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:b0b0:ba2b:b9fd:8a33]) by smtp.gmail.com with ESMTPSA id q24sm4032811wrc.26.2017.08.30.01.48.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Aug 2017 01:48:50 -0700 (PDT) From: Daniel Lezcano To: rui.zhang@intel.com, edubezval@gmail.com Cc: daniel.lezcano@linaro.org, linux-pm@vger.kernel.org, kevin.wangtao@linaro.org, leo.yan@linaro.org, linux-kernel@vger.kernel.org (open list) Subject: [PATCH 05/13] thermal/drivers/hisi: Fix multiple alarm interrupts firing Date: Wed, 30 Aug 2017 10:47:29 +0200 Message-Id: <1504082857-21702-5-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504082857-21702-1-git-send-email-daniel.lezcano@linaro.org> References: <1504082857-21702-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The DT specifies a threshold of 65000, we setup the register with a value in the temperature resolution for the controller, 64656. When we reach 64656, the interrupt fires, the interrupt is disabled. Then the irq thread runs and calls thermal_zone_device_update() which will call in turn hisi_thermal_get_temp(). The function will look if the temperature decreased, assuming it was more than 65000, but that is not the case because the current temperature is 64656 (because of the rounding when setting the threshold). This condition being true, we re-enable the interrupt which fires immediately after exiting the irq thread. That happens again and again until the temperature goes to more than 65000. Potentially, there is here an interrupt storm if the temperature stabilizes at this temperature. A very unlikely case but possible. In any case, it does not make sense to handle dozens of alarm interrupt for nothing. Fix this by rounding the threshold value to the controller resolution so the check against the threshold is consistent with the one set in the controller. Signed-off-by: Daniel Lezcano --- drivers/thermal/hisi_thermal.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index b58ad40..524310d 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -90,6 +90,12 @@ static inline long hisi_thermal_temp_to_step(long temp) return (temp - HISI_TEMP_BASE) / HISI_TEMP_STEP; } +static inline long hisi_thermal_round_temp(int temp) +{ + return hisi_thermal_step_to_temp( + hisi_thermal_temp_to_step(temp)); +} + static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data, struct hisi_thermal_sensor *sensor) { @@ -221,7 +227,7 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) sensor = &data->sensors; dev_crit(&data->pdev->dev, "THERMAL ALARM: T > %d\n", - sensor->thres_temp / 1000); + sensor->thres_temp); mutex_unlock(&data->thermal_lock); thermal_zone_device_update(data->sensors.tzd, @@ -255,7 +261,7 @@ static int hisi_thermal_register_sensor(struct platform_device *pdev, for (i = 0; i < of_thermal_get_ntrips(sensor->tzd); i++) { if (trip[i].type == THERMAL_TRIP_PASSIVE) { - sensor->thres_temp = trip[i].temperature; + sensor->thres_temp = hisi_thermal_round_temp(trip[i].temperature); break; } }