From patchwork Mon Sep 4 19:56:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 111607 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp1935278qge; Mon, 4 Sep 2017 12:57:53 -0700 (PDT) X-Received: by 10.84.217.221 with SMTP id d29mr1702919plj.309.1504555073113; Mon, 04 Sep 2017 12:57:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504555073; cv=none; d=google.com; s=arc-20160816; b=K+P5sfcpXPKAFNotfK6Sriu7WE1f+zihlQ8W5wY3lA/JzyWMCwGB6/2UDq81Nm3+qG RJwqKDKBLA4wL0RSW1+0SJujqZyD6QE3bVlHtyrk3kBy7WscGlDFzcRBLNNnFyzUIowH yQ5XfXxBi8s+CnT0aScysFiripgzagD+qOs48KEdtJA5X/UdUa1uKzv1R+g5KpQGt2Cx Ggoa8kJNSM6y+5txOcMU4Py6kRksPr7rLKXq0yVPVN70ywZbickXhwlGXEOiuhEZkauK 8TW2jIQrbktrlJjGQBbGnf9lND6BEW9nhYmTsaEcbI2tt/QT1EUXl1hE3mUVhDgR0I8f wOwg== 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=JhdkkJiHQ5XrqCWufTQWevXb2F70BZ7yIA5hrygNHqI=; b=KfImhFZKu9GAhzjQQjLhzhswFo3HkWEMiijFt+M4hWmErUXYzirZ+1OOeiDntsPiRT jtX7up7nrLxKAnGQSvvzFPrloW6gPdhYJESyEEB5uwnvtWQ7PpWiz1PBd62uWXvVXDTk A1eDBpy5cHruQAQp3VQJHCTvBnJyBGUdaNfWGI/JkWzoTsT68Nq4AAvfQyIqjYQFRJHe kiReRy4bfNMkyVU0aDSzOsZqUcKUDEl3IBv81+cnlvx+DMEKYUghoWOQj/jPPzKuColI 1PBakdvAwSYqi3H9YBxRMtgoU/45jMKoZ3jdostgsFTjeFrr/63B3uW8Sg5S4/jYUa+K sQdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BvUpPO26; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 g1si5992406pln.738.2017.09.04.12.57.52; Mon, 04 Sep 2017 12:57:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=BvUpPO26; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1754033AbdIDT5q (ORCPT + 12 others); Mon, 4 Sep 2017 15:57:46 -0400 Received: from mail-wr0-f181.google.com ([209.85.128.181]:37243 "EHLO mail-wr0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754009AbdIDT5k (ORCPT ); Mon, 4 Sep 2017 15:57:40 -0400 Received: by mail-wr0-f181.google.com with SMTP id n33so3986164wrn.4 for ; Mon, 04 Sep 2017 12:57:40 -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=JhdkkJiHQ5XrqCWufTQWevXb2F70BZ7yIA5hrygNHqI=; b=BvUpPO2699282hpyurPKnI2nEi+qQS3xaNcsdrYjpsqjQWHTvgcyCB9s3jhLK7KecG I3oc4bdMX6CTobx0CfjJBdYK2NwODmInFm2qgSx9i8eoLWFezP4XifhjfOSr03825In1 4XaDVuBc07GLy2yNeMw6XZ+ISEkjBtf7RI6Kw= 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=JhdkkJiHQ5XrqCWufTQWevXb2F70BZ7yIA5hrygNHqI=; b=msMvl18Ex3SZItIoBSYpG/AITtuPXcP1OPoZp62hYM78Bc077bcT5aOugLpxcpdS1R Gxu8gu0kjZ61j/50A4spvEmySqg1odn1oidIYHqx8X54G3JL0LUvFjasc9bSmWniLEqW oZS3R50h9V7R5toNxppfUNOIwlL0uOn/j/CGjD3Czu0drkkaTctgiAp+fv7Uy8F+4eXa Cs9FmLmIuNs0+2sHDuLV07hI47OIOnpiVEz3e+UMt2fzfAAe0wKkKNGVILH5RbA1PfKu +79y+qnK4ydy6lOT9Kd216Dh46m5YjiQE+e3bDnU1gORbUjh0lU5k3rq6m9aalFr1e+4 wTJw== X-Gm-Message-State: AHPjjUhP2F3NTigSExRn9Vrkr/kpDUvMTVabdt2TiuEESyObzAz7a9o3 owfbWwcctoo3Ej/b X-Google-Smtp-Source: ADKCNb7mPEdqt8F+4Gd4bcA9xl5yCC6cwGJOvpBKtqLVMEADEMlng7rWCDz8CPIUwduSRWZHCRULng== X-Received: by 10.223.169.83 with SMTP id u77mr865439wrc.268.1504555059233; Mon, 04 Sep 2017 12:57:39 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:f567:7c41:be9d:9286]) by smtp.gmail.com with ESMTPSA id 23sm10798976wrt.44.2017.09.04.12.57.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Sep 2017 12:57:38 -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 Subject: [PATCH V2 05/13] thermal/drivers/hisi: Fix multiple alarm interrupts firing Date: Mon, 4 Sep 2017 21:56:04 +0200 Message-Id: <1504554972-2624-5-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504554972-2624-1-git-send-email-daniel.lezcano@linaro.org> References: <1504554972-2624-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@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 Reviewed-by: Leo Yan Tested-by: Leo Yan --- 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 583bc19..f523197 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; } }