From patchwork Thu Oct 19 17:05:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 116414 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp721529qgn; Thu, 19 Oct 2017 10:08:33 -0700 (PDT) X-Received: by 10.98.209.88 with SMTP id t24mr2136465pfl.269.1508432913344; Thu, 19 Oct 2017 10:08:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508432913; cv=none; d=google.com; s=arc-20160816; b=Vh4NB2g1Tc691o273o0qjveoHtovwXuaudH79cjur/l9EbwtjJzzQ+gYArf6L0Y7oH /z1sP+xZToS/YNhrcNOobthV011q06Ha55esIXfPI0IP8BoDpNXR37b789ZuHIhgTJXJ cHV4oCHNiz4u8uWDlnOL7/i+cziEx88oAACOzM2ina2Ut1j9LjBvNkyOM/MyxX4YrhdB sOUJFsnwZpSf8jdJpeb8V2VUMiQwX6JJejIgNWR7MK6KwNRz69W6PHJZaincirC6Ib4N 5sg464xrtsz+lZ9oDCdUQGqqZmjYonI4pSWdUZe9lAIozZcaI3DzDJflSfDHyN1hq5y7 /+Ow== 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=/+R8+WARc0bg2kwO5tllsXPzLLUBegXV48E2koztXnQ=; b=gpStGOG7/s5WKtL2nm6e7NnoAq8mluPuSoAukhf2NnErmvRqTEo/merq7QzWRbXAyI A+1Opj2/HBo9mfIbH2x0dl1aXiZTUCAQhByRefFkJUX8UhsaHTozOsqTc8cWvY5zRLww 9snEO73SEAQFYW/mYCxtCyES/7HSq6ggRHJI3M+KYKyZOvsfSMhTZxgtZNKH4Qy5iz78 yKdq0TLk5X/xDGK05OaibRd9R/7Uc+pU+lHkBoFz6eBOlN1YqVZYjRm4tHYtrR7kaBIz cqK7q/kn4U7Jg9Qk8Q430vr5AO8XXHd+J8S0I33/UAT14a/BrkukpF9ugGlvhrIWJF7o iTLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Fhaf68ae; 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 v1si3120569pgq.533.2017.10.19.10.08.33; Thu, 19 Oct 2017 10:08:33 -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=Fhaf68ae; 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 S1753473AbdJSRIc (ORCPT + 12 others); Thu, 19 Oct 2017 13:08:32 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:47680 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753422AbdJSRIb (ORCPT ); Thu, 19 Oct 2017 13:08:31 -0400 Received: by mail-wm0-f65.google.com with SMTP id t69so17362160wmt.2 for ; Thu, 19 Oct 2017 10:08:30 -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=/+R8+WARc0bg2kwO5tllsXPzLLUBegXV48E2koztXnQ=; b=Fhaf68aeYlwHhAyKU/cfGuJcXIn+431b7SldR/G/pVwZAPdNjU8QhZG7tvIH/ri0rj bNgmelMhSu8xHnJGVC3KFNyF+iARz/sHQ3YV5R/PpCczWiMpRQl4RDGJIJ6+2p7Y3ShZ nYyHojWjGbpas4X5ozOPyNpZGOkhGzkbCr80o= 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=/+R8+WARc0bg2kwO5tllsXPzLLUBegXV48E2koztXnQ=; b=B6h5R5wzv0/BE/yXJBOzkh9cFfq2cfA08w1CrBhnOjvW01z4GuS0IazC3ASbAfexfj zImiCY0IixWQINdiEiCF0XeV9GEPuGxcpIlGVw2DsRhGZB8vW3ie3ATWgAgpEeUSWuxK q0lXpyvd5NCqvbk0whO3S3OnY2kUEZo9TZSQ0xFs/tTR3H29i1lrypgifPjrnhSmBGH7 oyu1iteOi+OJgv6c/XRuQBnxm/CtrdDfhlQ2sQSEHEErplNX4HiFEQfVFP39Cqbq7ORZ IRQSIykg3xp0JI0D2FpD256R5OI0SDRH8srshb/5bm58gz9snNaCL5hKXYw+iFo+bt/P kQzg== X-Gm-Message-State: AMCzsaWSXCBqXstF35lrXZqobbrQYeJiTF78TlX9rh0469CsjaRBqJVg PBzh8LR6fo4lhwg9vrTeZntsNg== X-Google-Smtp-Source: ABhQp+QBQWd81/5cbxg3afpT+bNHT3Po8tiMyUTaUBTZHjnhJAdX7+kodMfi0adoXZPAB2wPN3Bh0Q== X-Received: by 10.28.134.18 with SMTP id i18mr2513696wmd.27.1508432909785; Thu, 19 Oct 2017 10:08:29 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:51c7:d9b7:e14b:6840]) by smtp.gmail.com with ESMTPSA id g16sm14277394wrd.72.2017.10.19.10.08.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Oct 2017 10:08:29 -0700 (PDT) From: Daniel Lezcano To: edubezval@gmail.com, rui.zhang@intel.com Cc: linux-pm@vger.kernel.org, leo.yan@linaro.org, linux-kernel@vger.kernel.org Subject: [PATCH 01/18] thermal/drivers/hisi: Fix missing interrupt enablement Date: Thu, 19 Oct 2017 19:05:43 +0200 Message-Id: <1508432760-17847-1-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <6ac48f08-7fe6-92e9-0801-6ed3bcd05ff1@linaro.org> References: <6ac48f08-7fe6-92e9-0801-6ed3bcd05ff1@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The interrupt for the temperature threshold is not enabled at the end of the probe function, enable it after the setup is complete. On the other side, the irq_enabled is not correctly set as we are checking if the interrupt is masked where 'yes' means irq_enabled=false. irq_get_irqchip_state(data->irq, IRQCHIP_STATE_MASKED, &data->irq_enabled); As we are always enabling the interrupt, it is pointless to check if the interrupt is masked or not, just set irq_enabled to 'true'. Signed-off-by: Daniel Lezcano Reviewed-by: Leo Yan Tested-by: Leo Yan --- drivers/thermal/hisi_thermal.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 9c3ce34..f3b50b0 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -345,8 +345,7 @@ static int hisi_thermal_probe(struct platform_device *pdev) } hisi_thermal_enable_bind_irq_sensor(data); - irq_get_irqchip_state(data->irq, IRQCHIP_STATE_MASKED, - &data->irq_enabled); + data->irq_enabled = true; for (i = 0; i < HISI_MAX_SENSORS; ++i) { ret = hisi_thermal_register_sensor(pdev, data, @@ -358,6 +357,8 @@ static int hisi_thermal_probe(struct platform_device *pdev) hisi_thermal_toggle_sensor(&data->sensors[i], true); } + enable_irq(data->irq); + return 0; } From patchwork Thu Oct 19 17:05:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 116417 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp721734qgn; Thu, 19 Oct 2017 10:08:45 -0700 (PDT) X-Received: by 10.84.197.131 with SMTP id n3mr2013935pld.227.1508432925070; Thu, 19 Oct 2017 10:08:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508432925; cv=none; d=google.com; s=arc-20160816; b=bLsJrRWpf5b+wkj8kd9U+BqIuW95REsjmHJGGyimCDWFmk61bUJb4VLRi+SVu4fsJj QBJBA7j/QPVxpmeS6GsKlTnD6rgizileaXymEcNqdWYX5RdC75dVanDUCKIu3h8ocWqf yUYGQUo/TER4adkIMbobKrnl9OFTy+eLWrZz6BUv1fOgl0s9KEm3VUy2Dic/jtUPHaFD o/vGE+uNwCh/JcfxtlPx/oAlQ4tWzjkSV31lZ5z3iUc8lc8VbWdz8V7zmE7xV2/FoJd8 IA8gWA6wV6PIkUUlXRnTnerNpAsSCbedu0fKeN+PN24qNnhTNAm1TL9z3v/89KV2+4zo V5vw== 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=myNl1kd3kkDnlKDudMbJudZ0nM85VsriuAjESUtGHGE=; b=nyvrRsPR3OtsIpxO+N0AALA8I3xRmTKbIWyKIhOifRlK9AejiHx83Y73VrQjq7dckc VoRpbqpREOxeFum51Mf2O2yiQCFT25gIi9ZQsOWVwhL8oCnWNB+qO4lhemvSedxJOaCF hUiU3oZfbFJ4hAvMdXF8j280VCECrn4eCcIb3bCPCZoFEuyrCDLQiZOjmzDNlC79clHH Ml+rFHSpBJ8a28cjCxOm1J7rb57yU9W3wTQkfGoiVnoRiLIBkRF1gw+6Ghmkyb+7qi+C 5tWCey2e7yaiNrxN9xbeAPA0+z3v5vqWgKVsH/+BGTsMXMJ9vZipf9gwcQpIRmYSDjWd JSLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TKzHXFbw; 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 v22si9602054pfd.212.2017.10.19.10.08.44; Thu, 19 Oct 2017 10:08:45 -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=TKzHXFbw; 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 S1755065AbdJSRIm (ORCPT + 12 others); Thu, 19 Oct 2017 13:08:42 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:51915 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753422AbdJSRIk (ORCPT ); Thu, 19 Oct 2017 13:08:40 -0400 Received: by mail-wr0-f194.google.com with SMTP id j14so9041822wre.8 for ; Thu, 19 Oct 2017 10:08:39 -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=myNl1kd3kkDnlKDudMbJudZ0nM85VsriuAjESUtGHGE=; b=TKzHXFbwqpjPxkMZvWpcc3VUu5vqCl0SW4ves4Ai5nJP0Hkl3yXvn5zfKanv6jiS30 YM6ynvzmLD9N/2mZ+hFcTZRKEOJ94Yf+IOiqtNGoG4vbtxPrI25ymVcQHViizPwnbOUb CqqUoczzWhZQl7hjZp8Zf3f01RD9SftqGnH08= 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=myNl1kd3kkDnlKDudMbJudZ0nM85VsriuAjESUtGHGE=; b=CmZUZpxOim1a/6g1EmAjR7Rvzq61ng5MXB4iuofyOF/rEpD8UqlMi635mzQcPrnr6I sJD9Nq7GDQdNsrRAok40oDedOa9qGTBTyTXKfZYRKwabAhYsHCk6+XDlT5F5d5nJIiTY AuyUaiVVgeZgHl7//P21S26xmbpI6Py1cW3mbOhOIrddaEcE8W/y1pS3lqVDHcpo5U0u YzyCeRQRLB/sdZe0E9wkSU8M9/SQWrntgzE+HmW+R37G9RTYW8zNJbyQv5MaMvFeYU7X /4LJTo1NFILU3bFf/gTIlx1zwKCUEh+P0m/J2QTDDkjXaC7yJI5VngOukRhGnmqBfHQg P5Lg== X-Gm-Message-State: AMCzsaV5e2/x+eYQ5wMQdwa9rqIwoK0GwsnlD8mALAizX+ukRK230IRA SNLSB+cSozZadP9fL+qMarcxbg== X-Google-Smtp-Source: ABhQp+RFhn7BjFvgzvW75rZmqVk/XdqU75Rf+dUfbwlrkW1CI3awWNQrjbzMMI46xrCyByeMM6jpLg== X-Received: by 10.223.134.68 with SMTP id 4mr2391352wrw.67.1508432919126; Thu, 19 Oct 2017 10:08:39 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:51c7:d9b7:e14b:6840]) by smtp.gmail.com with ESMTPSA id g16sm14277394wrd.72.2017.10.19.10.08.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Oct 2017 10:08:38 -0700 (PDT) From: Daniel Lezcano To: edubezval@gmail.com, rui.zhang@intel.com Cc: linux-pm@vger.kernel.org, leo.yan@linaro.org, linux-kernel@vger.kernel.org Subject: [PATCH 07/18] thermal/drivers/hisi: Encapsulate register writes into helpers Date: Thu, 19 Oct 2017 19:05:49 +0200 Message-Id: <1508432760-17847-7-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508432760-17847-1-git-send-email-daniel.lezcano@linaro.org> References: <6ac48f08-7fe6-92e9-0801-6ed3bcd05ff1@linaro.org> <1508432760-17847-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 Hopefully, the function name can help to clarify the semantic of the operations when writing in the register. Signed-off-by: Daniel Lezcano --- drivers/thermal/hisi_thermal.c | 92 ++++++++++++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 22 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index b657ae4..8e8a117 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -26,6 +26,7 @@ #include "thermal_core.h" +#define TEMP0_LAG (0x0) #define TEMP0_TH (0x4) #define TEMP0_RST_TH (0x8) #define TEMP0_CFG (0xC) @@ -96,6 +97,56 @@ static inline long hisi_thermal_round_temp(int temp) hisi_thermal_temp_to_step(temp)); } +static inline void hisi_thermal_set_lag(void __iomem *addr, int value) +{ + writel(value, addr + TEMP0_LAG); +} + +static inline void hisi_thermal_alarm_clear(void __iomem *addr, int value) +{ + writel(value, addr + TEMP0_INT_CLR); +} + +static inline void hisi_thermal_alarm_enable(void __iomem *addr, int value) +{ + writel(value, addr + TEMP0_INT_EN); +} + +static inline void hisi_thermal_alarm_set(void __iomem *addr, int temp) +{ + writel(hisi_thermal_temp_to_step(temp) | 0x0FFFFFF00, addr + TEMP0_TH); +} + +static inline void hisi_thermal_reset_set(void __iomem *addr, int temp) +{ + writel(hisi_thermal_temp_to_step(temp), addr + TEMP0_RST_TH); +} + +static inline void hisi_thermal_reset_enable(void __iomem *addr, int value) +{ + writel(value, addr + TEMP0_RST_MSK); +} + +static inline void hisi_thermal_enable(void __iomem *addr, int value) +{ + writel(value, addr + TEMP0_EN); +} + +static inline void hisi_thermal_sensor_select(void __iomem *addr, int sensor) +{ + writel((sensor << 12), addr + TEMP0_CFG); +} + +static inline int hisi_thermal_get_temperature(void __iomem *addr) +{ + return hisi_thermal_step_to_temp(readl(addr + TEMP0_VALUE)); +} + +static inline void hisi_thermal_hdak_set(void __iomem *addr, int value) +{ + writel(value, addr + TEMP0_CFG); +} + static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data, struct hisi_thermal_sensor *sensor) { @@ -104,22 +155,21 @@ static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data, mutex_lock(&data->thermal_lock); /* disable interrupt */ - writel(0x0, data->regs + TEMP0_INT_EN); - writel(0x1, data->regs + TEMP0_INT_CLR); + hisi_thermal_alarm_enable(data->regs, 0); + hisi_thermal_alarm_clear(data->regs, 1); /* disable module firstly */ - writel(0x0, data->regs + TEMP0_EN); + hisi_thermal_enable(data->regs, 0); /* select sensor id */ - writel((sensor->id << 12), data->regs + TEMP0_CFG); + hisi_thermal_sensor_select(data->regs, sensor->id); /* enable module */ - writel(0x1, data->regs + TEMP0_EN); + hisi_thermal_enable(data->regs, 1); usleep_range(3000, 5000); - val = readl(data->regs + TEMP0_VALUE); - val = hisi_thermal_step_to_temp(val); + val = hisi_thermal_get_temperature(data->regs); mutex_unlock(&data->thermal_lock); @@ -136,28 +186,26 @@ static void hisi_thermal_enable_bind_irq_sensor sensor = &data->sensors; /* setting the hdak time */ - writel(0x0, data->regs + TEMP0_CFG); + hisi_thermal_hdak_set(data->regs, 0); /* disable module firstly */ - writel(0x0, data->regs + TEMP0_RST_MSK); - writel(0x0, data->regs + TEMP0_EN); + hisi_thermal_reset_enable(data->regs, 0); + hisi_thermal_enable(data->regs, 0); /* select sensor id */ - writel((sensor->id << 12), data->regs + TEMP0_CFG); + hisi_thermal_sensor_select(data->regs, sensor->id); /* enable for interrupt */ - writel(hisi_thermal_temp_to_step(sensor->thres_temp) | 0x0FFFFFF00, - data->regs + TEMP0_TH); + hisi_thermal_alarm_set(data->regs, sensor->thres_temp); - writel(hisi_thermal_temp_to_step(HISI_TEMP_RESET), - data->regs + TEMP0_RST_TH); + hisi_thermal_reset_set(data->regs, HISI_TEMP_RESET); /* enable module */ - writel(0x1, data->regs + TEMP0_RST_MSK); - writel(0x1, data->regs + TEMP0_EN); + hisi_thermal_reset_enable(data->regs, 1); + hisi_thermal_enable(data->regs, 1); - writel(0x0, data->regs + TEMP0_INT_CLR); - writel(0x1, data->regs + TEMP0_INT_EN); + hisi_thermal_alarm_clear(data->regs, 0); + hisi_thermal_alarm_enable(data->regs, 1); usleep_range(3000, 5000); @@ -169,9 +217,9 @@ static void hisi_thermal_disable_sensor(struct hisi_thermal_data *data) mutex_lock(&data->thermal_lock); /* disable sensor module */ - writel(0x0, data->regs + TEMP0_INT_EN); - writel(0x0, data->regs + TEMP0_RST_MSK); - writel(0x0, data->regs + TEMP0_EN); + hisi_thermal_enable(data->regs, 0); + hisi_thermal_alarm_enable(data->regs, 0); + hisi_thermal_reset_enable(data->regs, 0); mutex_unlock(&data->thermal_lock); } From patchwork Thu Oct 19 17:05:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 116428 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp724529qgn; Thu, 19 Oct 2017 10:11:28 -0700 (PDT) X-Received: by 10.84.168.5 with SMTP id e5mr2037099plb.150.1508433088235; Thu, 19 Oct 2017 10:11:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508433088; cv=none; d=google.com; s=arc-20160816; b=jmZ5j6jTGyo16YiHDjcKMCR3RV9JfnZ2iibbFLeHjEU4WAbr+rBvBKLVoZk7O9tiF/ ps+5VXLw3ThNg2tx8KXHjB27kuHyeImyFghDnXJiSmb4fGPzAoaNvsvho5SwMTxuM2yV 1wAqkQN/URvQSj3AP7tMItZIaFwJvOeFFNm0MKll6qonLZqN8JkmW8P3gh0Taa5BLRfL FLqdsE35sVeaiCuR7LiM6MDr3fQMMAEAWFey+Lj4pz+8gstzE3OvkJluN06uLoWpmuao y4up4jbYjwxw7KvElgD7age/8xgdd2BMX2tt7KQmfG6kF18wKlI89D/2eFo/RGpc6Hff 4e2w== 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=yz0QlVYN4g5sbf0S4c/Ilr/QnJHDN4zbgTqyOfaGHAY=; b=cTO1RggPiNL7ZmERnjpR3Q8usClIgYv5tiBhHY+tq4vcDtTa4Itx+No/HEaaoJut3z 7HIty46S69nRRrVbN72eTsu2jNyeMfhnCM3khTmLIcWa0Gzgs2zrWBCy5APJKiMwnxOx b2tGWCb4qj43zM0ozu1XvSjgEqSWXrTSaynShJcDlOnCwVYbqnzaIyhK/01vkUFpFtQn FkknCbIF2q/f4m/UtQyXyT+UvXVhuhszmAn6uKFol/onjhm8vu6iXEDhiO1uaZy8Ce2v oZWDuHOgOmwlyn1Drd5mBEiAIH97+9agFHpf10aNrpShrQ+V2StcdgX6b1EfJy143epo gpmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iK7uuQBM; 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 v30si8997866pgn.569.2017.10.19.10.11.28; Thu, 19 Oct 2017 10:11:28 -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=iK7uuQBM; 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 S1753607AbdJSRL0 (ORCPT + 12 others); Thu, 19 Oct 2017 13:11:26 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:51824 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755064AbdJSRIl (ORCPT ); Thu, 19 Oct 2017 13:08:41 -0400 Received: by mail-wm0-f66.google.com with SMTP id f4so17755737wme.0 for ; Thu, 19 Oct 2017 10:08:41 -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=yz0QlVYN4g5sbf0S4c/Ilr/QnJHDN4zbgTqyOfaGHAY=; b=iK7uuQBMMH7tjmR40sW8gVxH9fmrPJRWYHM8/tfE3k1j0CRxN35viDpHqj9oJxIj+2 iVxF1TCeatjy4Fu3GYZOWT0oWnKysSbr7jyHVVEkf8CwXAnyqfas8Wwhupei844lBAiE srKPo+5m9hkr7l7J796mQoEhWw6pFV/cRLgFs= 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=yz0QlVYN4g5sbf0S4c/Ilr/QnJHDN4zbgTqyOfaGHAY=; b=svG28HVZ4kY6+JznUZjmZAWybtg174cifTjFUGpxcC9B6ldScrigJt+yPoyPPE9d/o cywNtJXO6AE/MwpX3dk8TH+/LCSi2gvei98BNXjEQNkcQvAmyydjvkJl2FhllMJfgWQE FlR+d7lHFR+BQ9UlWQSZtQiNCMDqa/cHIeMRWkgkm9v5y8ZkJviwadhmNK5HA6ClyHD2 vRvAXSizNrz1WgBXAbRZpc1P1RO9cMYwSfU9FIcFrDOblz9lB0J9Z6vWWmalNHTRS+rQ YlmtHdQjAOxzJSxJVdN6OguSqMYYcj/Mbosa6KAz/gUOmCXzHdNqj5YIqvKqetoaFfZE boug== X-Gm-Message-State: AMCzsaWvSWTzoVL/KYdVX6ghpR1CyATzbREPiNLjXdc85HG+cqL79gxR 3JwFhSrqXZUKabZWGmW7LF6Dew== X-Google-Smtp-Source: ABhQp+RuqN6CBdsmi3UYHKluB8lJf1IFQVo94CHUdjdYf2lX38Bq2YAr1MNdHMGIQTfPWh+UajZf8g== X-Received: by 10.28.17.77 with SMTP id 74mr2088179wmr.66.1508432920531; Thu, 19 Oct 2017 10:08:40 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:51c7:d9b7:e14b:6840]) by smtp.gmail.com with ESMTPSA id g16sm14277394wrd.72.2017.10.19.10.08.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Oct 2017 10:08:40 -0700 (PDT) From: Daniel Lezcano To: edubezval@gmail.com, rui.zhang@intel.com Cc: linux-pm@vger.kernel.org, leo.yan@linaro.org, linux-kernel@vger.kernel.org Subject: [PATCH 08/18] thermal/drivers/hisi: Fix configuration register setting Date: Thu, 19 Oct 2017 19:05:50 +0200 Message-Id: <1508432760-17847-8-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508432760-17847-1-git-send-email-daniel.lezcano@linaro.org> References: <6ac48f08-7fe6-92e9-0801-6ed3bcd05ff1@linaro.org> <1508432760-17847-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 TEMP0_CFG configuration register contains different field to set up the temperature controller. However in the code, nothing prevents a setup to overwrite the previous one: eg. writing the hdak value overwrites the sensor selection, the sensor selection overwrites the hdak value. In order to prevent such thing, use a regmap-like mechanism by reading the value before, set the corresponding bits and write the result. Signed-off-by: Daniel Lezcano --- drivers/thermal/hisi_thermal.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 8e8a117..690f0bd 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -30,6 +30,8 @@ #define TEMP0_TH (0x4) #define TEMP0_RST_TH (0x8) #define TEMP0_CFG (0xC) +#define TEMP0_CFG_SS_MSK (0xF000) +#define TEMP0_CFG_HDAK_MSK (0x30) #define TEMP0_EN (0x10) #define TEMP0_INT_EN (0x14) #define TEMP0_INT_CLR (0x18) @@ -132,19 +134,41 @@ static inline void hisi_thermal_enable(void __iomem *addr, int value) writel(value, addr + TEMP0_EN); } -static inline void hisi_thermal_sensor_select(void __iomem *addr, int sensor) +static inline int hisi_thermal_get_temperature(void __iomem *addr) { - writel((sensor << 12), addr + TEMP0_CFG); + return hisi_thermal_step_to_temp(readl(addr + TEMP0_VALUE)); } -static inline int hisi_thermal_get_temperature(void __iomem *addr) +/* + * Temperature configuration register - Sensor selection + * + * Bits [19:12] + * + * 0x0: local sensor (default) + * 0x1: remote sensor 1 (ACPU cluster 1) + * 0x2: remote sensor 2 (ACPU cluster 0) + * 0x3: remote sensor 3 (G3D) + */ +static inline void hisi_thermal_sensor_select(void __iomem *addr, int sensor) { - return hisi_thermal_step_to_temp(readl(addr + TEMP0_VALUE)); + writel((readl(addr + TEMP0_CFG) & ~TEMP0_CFG_SS_MSK) | + (sensor << 12), addr + TEMP0_CFG); } +/* + * Temperature configuration register - Hdak conversion polling interval + * + * Bits [5:4] + * + * 0x0 : 0.768 ms + * 0x1 : 6.144 ms + * 0x2 : 49.152 ms + * 0x3 : 393.216 ms + */ static inline void hisi_thermal_hdak_set(void __iomem *addr, int value) { - writel(value, addr + TEMP0_CFG); + writel((readl(addr + TEMP0_CFG) & ~TEMP0_CFG_HDAK_MSK) | + (value << 4), addr + TEMP0_CFG); } static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data, From patchwork Thu Oct 19 17:05:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 116418 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp721779qgn; Thu, 19 Oct 2017 10:08:48 -0700 (PDT) X-Received: by 10.84.133.69 with SMTP id 63mr1988739plf.203.1508432928051; Thu, 19 Oct 2017 10:08:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508432928; cv=none; d=google.com; s=arc-20160816; b=ZjNsauynMpl2eBulqYWOZ/JepYR2ccYkrV0BRnOElSKnefuaen88oLq5AjJOYJYJsZ m+Uy5MO9Qgu2tQ6mbYIKYjVlH4uN5zVc+L7kWYNf2zBKpCHpJOBrjqTxlkvwpRBTV1Xl qm1Yexq0b21Uj4dmLyUBkVgcmJUmM06Mrwv1ZBGh0DpWzsR5BJsJA3vQ9RpJ+BHGoiwl uaB0xiLJxtmegZq3xmdPloHNkWb3vuHU05eJ/ofem2QgWPLjslpkQvl2qa8KcO7cnl1V vbQcPPT0ts3/UFhM7XmYAQvLTQPyDjSy0XyejTfIHfu1OaoWYWyCaS1nc6OQP1JNXaeQ BSww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=ts8esadIK6lmVxzmlJYgcPlyBt5pATi5dW7/Y4LroH0=; b=F+oM19d86Fe8/nkkrXc8DvWjZn1+D2QvYM/ANgboto1GE0u/pEx0PObrVRqKvzToXJ UwGm4YVMFzhQcWosxKMoYob1Cl1KCFhuXyIIX5/pR+wElbc3UCHL399Mr8AWd+LRYPRf HK+syYbLq+yqafIUec16L336d45RA1UmaD46oJ3UsN7pzHvc2v49IYK7WrguVZXefm5d VVmlWni40KblPVWa4ByvK90aSFgynqqlrkNS8al4T2EGXE0/SMORU2CNL4VEzZSlwf23 M9iMvfCseR/b9/w523peAxVgZnWaQT3c5sRaZDyFcsx6RJGSIktOKFE+GNbDAvn2HOz8 WrBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LxIOriTO; 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 v22si9602054pfd.212.2017.10.19.10.08.47; Thu, 19 Oct 2017 10:08:48 -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=LxIOriTO; 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 S1755074AbdJSRIp (ORCPT + 12 others); Thu, 19 Oct 2017 13:08:45 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:52635 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755066AbdJSRIn (ORCPT ); Thu, 19 Oct 2017 13:08:43 -0400 Received: by mail-wr0-f194.google.com with SMTP id k62so9037516wrc.9 for ; Thu, 19 Oct 2017 10:08:43 -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 :mime-version:content-transfer-encoding; bh=ts8esadIK6lmVxzmlJYgcPlyBt5pATi5dW7/Y4LroH0=; b=LxIOriTOxquyqF+hOSv7BkaecwgrAh5sIBkQQH3xJ7BD87IiQ0NnM/EVgrI8CkA4Em LkOBRBn87HEjOFIlYM+mLjMMWWOngCzLqG3HLs66yKU3TlFV6YhhnPrrHAdNC80LCpmc 9g9FmlRG4J98G6IVPJtY+MikIKI1AQNat+gus= 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:mime-version:content-transfer-encoding; bh=ts8esadIK6lmVxzmlJYgcPlyBt5pATi5dW7/Y4LroH0=; b=Gypz7zR/SK0/LpCsz7LoXNn+1yxLYOZrS6deBC5zSaV9vcTeNQ/axWqO8sAcGQ+hsO SQSBRPURYgXg3jyJS11pcQ4/QIrvgsCtk1IQ2bokW5FiYpVlEHj5WKQbe/6IAJzMDtyk KQpz9/66xsB7/supFh9/diuR7sWUrZ5H2n0zROeTwMCa/JKucLLRZONBwNuyEBYK0W1v zi/14y9Ewsmjt2fL6VPx71a3CBIooM2Bc+Nx3FAKQKqKzoBIjNjy+Ol4C2oFG1vHlGVd P0Fmr3YI2RlVi8Y3OlIvH24j1o7/Kv5lPzhDYCTsxvshBYmCMPkrYq+U9gb9TjwIRLfL Yl5g== X-Gm-Message-State: AMCzsaX95CBC8x0i+QrYJLWoh4rac1njh6vh/oejuwm5sSjlSCH6H3Tx 4KYZacgL455mgn/A3BDCmFTpnQ== X-Google-Smtp-Source: ABhQp+TsumPzK173laJoChRz+qNVldYvNEgDbX/cjMwbJj/u2wvYikZVjyoR2mTNPw8D00mKvXbhSw== X-Received: by 10.223.130.13 with SMTP id 13mr1801917wrb.216.1508432922202; Thu, 19 Oct 2017 10:08:42 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:51c7:d9b7:e14b:6840]) by smtp.gmail.com with ESMTPSA id g16sm14277394wrd.72.2017.10.19.10.08.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Oct 2017 10:08:41 -0700 (PDT) From: Daniel Lezcano To: edubezval@gmail.com, rui.zhang@intel.com Cc: linux-pm@vger.kernel.org, leo.yan@linaro.org, linux-kernel@vger.kernel.org Subject: [PATCH 09/18] thermal/drivers/hisi: Remove costly sensor inspection Date: Thu, 19 Oct 2017 19:05:51 +0200 Message-Id: <1508432760-17847-9-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508432760-17847-1-git-send-email-daniel.lezcano@linaro.org> References: <6ac48f08-7fe6-92e9-0801-6ed3bcd05ff1@linaro.org> <1508432760-17847-1-git-send-email-daniel.lezcano@linaro.org> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The sensor is all setup, bind, resetted, acked, etc... every single second. That was the way to workaround a problem with the interrupt bouncing again and again. With the following changes, we fix all in one: - Do the setup, one time, at probe time - Add the IRQF_ONESHOT, ack the interrupt in the threaded handler - Remove the interrupt handler - Set the correct value for the LAG register - Remove all the irq_enabled stuff in the code as the interruption handling is fixed - Remove the 3ms delay - Reorder the initialization routine to be in the right order It ends up to a nicer code and more efficient, the 3-5ms delay is removed from the get_temp() path. Signed-off-by: Daniel Lezcano Reviewed-by: Leo Yan Tested-by: Leo Yan --- drivers/thermal/hisi_thermal.c | 203 +++++++++++++++++++---------------------- 1 file changed, 93 insertions(+), 110 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 690f0bd..c7bdcfe 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -41,6 +41,7 @@ #define HISI_TEMP_BASE (-60000) #define HISI_TEMP_RESET (100000) #define HISI_TEMP_STEP (784) +#define HISI_TEMP_LAG (3500) #define HISI_MAX_SENSORS 4 #define HISI_DEFAULT_SENSOR 2 @@ -60,8 +61,6 @@ struct hisi_thermal_data { struct clk *clk; struct hisi_thermal_sensor sensors; int irq; - bool irq_enabled; - void __iomem *regs; }; @@ -99,9 +98,40 @@ static inline long hisi_thermal_round_temp(int temp) hisi_thermal_temp_to_step(temp)); } +/* + * The lag register contains 5 bits encoding the temperature in steps. + * + * Each time the temperature crosses the threshold boundary, an + * interrupt is raised. It could be when the temperature is going + * above the threshold or below. However, if the temperature is + * fluctuating around this value due to the load, we can receive + * several interrupts which may not desired. + * + * We can setup a temperature representing the delta between the + * threshold and the current temperature when the temperature is + * decreasing. + * + * For instance: the lag register is 5°C, the threshold is 65°C, when + * the temperature reaches 65°C an interrupt is raised and when the + * temperature decrease to 65°C - 5°C another interrupt is raised. + * + * A very short lag can lead to an interrupt storm, a long lag + * increase the latency to react to the temperature changes. In our + * case, that is not really a problem as we are polling the + * temperature. + * + * [0:4] : lag register + * + * The temperature is coded in steps, cf. HISI_TEMP_STEP. + * + * Min : 0x00 : 0.0 °C + * Max : 0x1F : 24.3 °C + * + * The 'value' parameter is in milliCelsius. + */ static inline void hisi_thermal_set_lag(void __iomem *addr, int value) { - writel(value, addr + TEMP0_LAG); + writel((value / HISI_TEMP_STEP) & 0x1F, addr + TEMP0_LAG); } static inline void hisi_thermal_alarm_clear(void __iomem *addr, int value) @@ -171,71 +201,6 @@ static inline void hisi_thermal_hdak_set(void __iomem *addr, int value) (value << 4), addr + TEMP0_CFG); } -static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data, - struct hisi_thermal_sensor *sensor) -{ - long val; - - mutex_lock(&data->thermal_lock); - - /* disable interrupt */ - hisi_thermal_alarm_enable(data->regs, 0); - hisi_thermal_alarm_clear(data->regs, 1); - - /* disable module firstly */ - hisi_thermal_enable(data->regs, 0); - - /* select sensor id */ - hisi_thermal_sensor_select(data->regs, sensor->id); - - /* enable module */ - hisi_thermal_enable(data->regs, 1); - - usleep_range(3000, 5000); - - val = hisi_thermal_get_temperature(data->regs); - - mutex_unlock(&data->thermal_lock); - - return val; -} - -static void hisi_thermal_enable_bind_irq_sensor - (struct hisi_thermal_data *data) -{ - struct hisi_thermal_sensor *sensor; - - mutex_lock(&data->thermal_lock); - - sensor = &data->sensors; - - /* setting the hdak time */ - hisi_thermal_hdak_set(data->regs, 0); - - /* disable module firstly */ - hisi_thermal_reset_enable(data->regs, 0); - hisi_thermal_enable(data->regs, 0); - - /* select sensor id */ - hisi_thermal_sensor_select(data->regs, sensor->id); - - /* enable for interrupt */ - hisi_thermal_alarm_set(data->regs, sensor->thres_temp); - - hisi_thermal_reset_set(data->regs, HISI_TEMP_RESET); - - /* enable module */ - hisi_thermal_reset_enable(data->regs, 1); - hisi_thermal_enable(data->regs, 1); - - hisi_thermal_alarm_clear(data->regs, 0); - hisi_thermal_alarm_enable(data->regs, 1); - - usleep_range(3000, 5000); - - mutex_unlock(&data->thermal_lock); -} - static void hisi_thermal_disable_sensor(struct hisi_thermal_data *data) { mutex_lock(&data->thermal_lock); @@ -253,25 +218,10 @@ static int hisi_thermal_get_temp(void *_sensor, int *temp) struct hisi_thermal_sensor *sensor = _sensor; struct hisi_thermal_data *data = sensor->thermal; - *temp = hisi_thermal_get_sensor_temp(data, sensor); - - dev_dbg(&data->pdev->dev, "id=%d, irq=%d, temp=%d, thres=%d\n", - sensor->id, data->irq_enabled, *temp, sensor->thres_temp); - /* - * Bind irq to sensor for two cases: - * Reenable alarm IRQ if temperature below threshold; - * if irq has been enabled, always set it; - */ - if (data->irq_enabled) { - hisi_thermal_enable_bind_irq_sensor(data); - return 0; - } + *temp = hisi_thermal_get_temperature(data->regs); - if (*temp < sensor->thres_temp) { - data->irq_enabled = true; - hisi_thermal_enable_bind_irq_sensor(data); - enable_irq(data->irq); - } + dev_dbg(&data->pdev->dev, "id=%d, temp=%d, thres=%d\n", + sensor->id, *temp, sensor->thres_temp); return 0; } @@ -280,26 +230,27 @@ static struct thermal_zone_of_device_ops hisi_of_thermal_ops = { .get_temp = hisi_thermal_get_temp, }; -static irqreturn_t hisi_thermal_alarm_irq(int irq, void *dev) +static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) { struct hisi_thermal_data *data = dev; + struct hisi_thermal_sensor *sensor = &data->sensors; + int temp; - disable_irq_nosync(irq); - data->irq_enabled = false; + hisi_thermal_alarm_clear(data->regs, 1); - return IRQ_WAKE_THREAD; -} + temp = hisi_thermal_get_temperature(data->regs); -static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) -{ - struct hisi_thermal_data *data = dev; - struct hisi_thermal_sensor *sensor = &data->sensors; + if (temp >= sensor->thres_temp) { + dev_crit(&data->pdev->dev, "THERMAL ALARM: %d > %d\n", + temp, sensor->thres_temp); - dev_crit(&data->pdev->dev, "THERMAL ALARM: T > %d\n", - sensor->thres_temp); + thermal_zone_device_update(data->sensors.tzd, + THERMAL_EVENT_UNSPECIFIED); - thermal_zone_device_update(data->sensors.tzd, - THERMAL_EVENT_UNSPECIFIED); + } else if (temp < sensor->thres_temp) { + dev_crit(&data->pdev->dev, "THERMAL ALARM stopped: %d < %d\n", + temp, sensor->thres_temp); + } return IRQ_HANDLED; } @@ -352,6 +303,40 @@ static void hisi_thermal_toggle_sensor(struct hisi_thermal_sensor *sensor, on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); } +static int hisi_thermal_setup(struct hisi_thermal_data *data) +{ + struct hisi_thermal_sensor *sensor; + + sensor = &data->sensors; + + /* disable module firstly */ + hisi_thermal_reset_enable(data->regs, 0); + hisi_thermal_enable(data->regs, 0); + + /* select sensor id */ + hisi_thermal_sensor_select(data->regs, sensor->id); + + /* setting the hdak time */ + hisi_thermal_hdak_set(data->regs, 0); + + /* setting lag value between current temp and the threshold */ + hisi_thermal_set_lag(data->regs, HISI_TEMP_LAG); + + /* enable for interrupt */ + hisi_thermal_alarm_set(data->regs, sensor->thres_temp); + + hisi_thermal_reset_set(data->regs, HISI_TEMP_RESET); + + /* enable module */ + hisi_thermal_reset_enable(data->regs, 1); + hisi_thermal_enable(data->regs, 1); + + hisi_thermal_alarm_clear(data->regs, 0); + hisi_thermal_alarm_enable(data->regs, 1); + + return 0; +} + static int hisi_thermal_probe(struct platform_device *pdev) { struct hisi_thermal_data *data; @@ -394,9 +379,6 @@ static int hisi_thermal_probe(struct platform_device *pdev) return ret; } - hisi_thermal_enable_bind_irq_sensor(data); - data->irq_enabled = true; - ret = hisi_thermal_register_sensor(pdev, data, &data->sensors, HISI_DEFAULT_SENSOR); @@ -406,18 +388,21 @@ static int hisi_thermal_probe(struct platform_device *pdev) return ret; } - hisi_thermal_toggle_sensor(&data->sensors, true); + ret = hisi_thermal_setup(data); + if (ret) { + dev_err(&pdev->dev, "Failed to setup the sensor: %d\n", ret); + return ret; + } - ret = devm_request_threaded_irq(&pdev->dev, data->irq, - hisi_thermal_alarm_irq, + ret = devm_request_threaded_irq(&pdev->dev, data->irq, NULL, hisi_thermal_alarm_irq_thread, - 0, "hisi_thermal", data); + IRQF_ONESHOT, "hisi_thermal", data); if (ret < 0) { dev_err(&pdev->dev, "failed to request alarm irq: %d\n", ret); return ret; } - enable_irq(data->irq); + hisi_thermal_toggle_sensor(&data->sensors, true); return 0; } @@ -440,7 +425,6 @@ static int hisi_thermal_suspend(struct device *dev) struct hisi_thermal_data *data = dev_get_drvdata(dev); hisi_thermal_disable_sensor(data); - data->irq_enabled = false; clk_disable_unprepare(data->clk); @@ -456,8 +440,7 @@ static int hisi_thermal_resume(struct device *dev) if (ret) return ret; - data->irq_enabled = true; - hisi_thermal_enable_bind_irq_sensor(data); + hisi_thermal_setup(data); return 0; } From patchwork Thu Oct 19 17:05:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 116427 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp724484qgn; Thu, 19 Oct 2017 10:11:26 -0700 (PDT) X-Received: by 10.84.192.37 with SMTP id b34mr1975689pld.221.1508433086540; Thu, 19 Oct 2017 10:11:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508433086; cv=none; d=google.com; s=arc-20160816; b=P71gPDrWQtW8Ln76ExkQOwTvhcgAZKMFh8AYKY0tU8W9CeK07OaQCOKIYibdTFP5Tg DQK8xo4wjaAzXaTm4FkRrh8+/PW5/DFaOKhtqMiF9jYBQbNaJk60Jx7ZHXfvc+wP2vo1 Iw2hyAFWvZHaOU+hcEuMr93YG1tS0xjvVasPBi2HZg3wSMyr2Rv9AN7FAHAEHQQ1/7uk QE0rXV0Lj7GlG2YdqFqkzojPiGbY19eOPkicjTD2KjCxd/oK0zq2cvOQRpTJU9lWSk9M YSgWruMbi72WH7Ob0t9wNWNVPX48jOza37tma3kQk9/lsRYyGA2653U4fSn6QphYQYYv FvgA== 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=+KujdbHN3qEot2SvxbKORv1M+FH5gPRfR4hO8EKJ3aw=; b=o7MYVmfKR1R8or1Maynq87aXYwT+IcQkyKDC81k7PXm4hJvL7WyvWpNG+5zmya10NK dUvbP4DIc5Qpqp/ZiAqBzeGKeU+aQwcxrBS2zLjindozdKg3HUMeL2t+aDF/SvD0JIbg KKbWZglFt3WUvtw8zPGiJQlvjHAZ2hBCA/lPlYTdB81OqbUe0h0D/rZcMqeBeAYKpsH+ ioZvsTvS4swMTCdJS9GkNrJKycaPku2wCT9smH0TG7CJoOqLYnnU4Ei3yqc8KBUEISx+ 5L0cYeHnf3LI6HkhpuW/oZto/ousoy9yDOIVHk4FbHh9C6GfCzpbkv1CvPn4KGjUVe5S hyhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HoOaGKWu; 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 v30si8997866pgn.569.2017.10.19.10.11.26; Thu, 19 Oct 2017 10:11:26 -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=HoOaGKWu; 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 S1755078AbdJSRIq (ORCPT + 12 others); Thu, 19 Oct 2017 13:08:46 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:44597 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755070AbdJSRIp (ORCPT ); Thu, 19 Oct 2017 13:08:45 -0400 Received: by mail-wr0-f196.google.com with SMTP id z55so2981941wrz.1 for ; Thu, 19 Oct 2017 10:08: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; bh=+KujdbHN3qEot2SvxbKORv1M+FH5gPRfR4hO8EKJ3aw=; b=HoOaGKWuPKzL9HM184hKMZB9Ei7Z+SO13XBU0JUMXlMXiRgTJF/cjGvxwthNp1q1ZX +jti7x0LjO4IRkr699iU41ranDoWTvkvAUVeeKd42fEphN7+6lI6uihxpcPVV6Riaoxw hKkfUD9es4Wy9oZKHBErOWeKKjY4VnmbwhXYI= 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=+KujdbHN3qEot2SvxbKORv1M+FH5gPRfR4hO8EKJ3aw=; b=sPfQYhAWMW3JhjHV2OpPgGukJeu3gMqaggeIbDK5J12Ou8ujkilEN7XKXv24GaZga6 r0HGkHTD2tHoSkBmg5owKpiTTvSif66j5Ej9tbpmV9fx07G4jQPeOzXH4XqBZW9ypI97 +hBaM/koGPJjfd2AJr1nDDIW35SyuESgPP+09mmCBe58TdEllP+1M5c11kZ46XPx5sns wNCM9p2z7/loJl+xWXunwsyqAsdHLdEXJ/yPGWP5InktyKO2Gl6lXJJ75rMPDGBt2gPb PgYm9GpF1iWTiAM1/T0AnRqKLROg56oagX0nPd7kN24j6+xvHTcHbwAwphl4rclQUtDl 5mbw== X-Gm-Message-State: AMCzsaWJ2qtHnv+O/2feF7Vr9U789zznX4MyJRaQK2UsKwJWcE3hEqx8 adgk8o3PgALakatggNrnL4jm7Q== X-Google-Smtp-Source: ABhQp+TAX76NEeRPCvNBkAvp3GjXzjQ3/jZR11eh+HyY6KQUNMQQ5DQ5kgiUYukSlB087dl7DQ3xHg== X-Received: by 10.223.136.246 with SMTP id g51mr2107177wrg.226.1508432923762; Thu, 19 Oct 2017 10:08:43 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:51c7:d9b7:e14b:6840]) by smtp.gmail.com with ESMTPSA id g16sm14277394wrd.72.2017.10.19.10.08.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Oct 2017 10:08:43 -0700 (PDT) From: Daniel Lezcano To: edubezval@gmail.com, rui.zhang@intel.com Cc: linux-pm@vger.kernel.org, leo.yan@linaro.org, linux-kernel@vger.kernel.org Subject: [PATCH 10/18] thermal/drivers/hisi: Rename and remove unused field Date: Thu, 19 Oct 2017 19:05:52 +0200 Message-Id: <1508432760-17847-10-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508432760-17847-1-git-send-email-daniel.lezcano@linaro.org> References: <6ac48f08-7fe6-92e9-0801-6ed3bcd05ff1@linaro.org> <1508432760-17847-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 Rename the 'sensors' field to 'sensor' as we describe only one sensor. Remove the 'sensor_temp' as it is no longer used. Signed-off-by: Daniel Lezcano Reviewed-by: Leo Yan Tested-by: Leo Yan --- drivers/thermal/hisi_thermal.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index c7bdcfe..baa3853 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -49,8 +49,6 @@ struct hisi_thermal_sensor { struct hisi_thermal_data *thermal; struct thermal_zone_device *tzd; - - long sensor_temp; uint32_t id; uint32_t thres_temp; }; @@ -59,9 +57,9 @@ struct hisi_thermal_data { struct mutex thermal_lock; /* protects register data */ struct platform_device *pdev; struct clk *clk; - struct hisi_thermal_sensor sensors; - int irq; + struct hisi_thermal_sensor sensor; void __iomem *regs; + int irq; }; /* @@ -233,7 +231,7 @@ static struct thermal_zone_of_device_ops hisi_of_thermal_ops = { static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) { struct hisi_thermal_data *data = dev; - struct hisi_thermal_sensor *sensor = &data->sensors; + struct hisi_thermal_sensor *sensor = &data->sensor; int temp; hisi_thermal_alarm_clear(data->regs, 1); @@ -244,7 +242,7 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) dev_crit(&data->pdev->dev, "THERMAL ALARM: %d > %d\n", temp, sensor->thres_temp); - thermal_zone_device_update(data->sensors.tzd, + thermal_zone_device_update(data->sensor.tzd, THERMAL_EVENT_UNSPECIFIED); } else if (temp < sensor->thres_temp) { @@ -307,7 +305,7 @@ static int hisi_thermal_setup(struct hisi_thermal_data *data) { struct hisi_thermal_sensor *sensor; - sensor = &data->sensors; + sensor = &data->sensor; /* disable module firstly */ hisi_thermal_reset_enable(data->regs, 0); @@ -380,7 +378,7 @@ static int hisi_thermal_probe(struct platform_device *pdev) } ret = hisi_thermal_register_sensor(pdev, data, - &data->sensors, + &data->sensor, HISI_DEFAULT_SENSOR); if (ret) { dev_err(&pdev->dev, "failed to register thermal sensor: %d\n", @@ -402,7 +400,7 @@ static int hisi_thermal_probe(struct platform_device *pdev) return ret; } - hisi_thermal_toggle_sensor(&data->sensors, true); + hisi_thermal_toggle_sensor(&data->sensor, true); return 0; } @@ -410,7 +408,7 @@ static int hisi_thermal_probe(struct platform_device *pdev) static int hisi_thermal_remove(struct platform_device *pdev) { struct hisi_thermal_data *data = platform_get_drvdata(pdev); - struct hisi_thermal_sensor *sensor = &data->sensors; + struct hisi_thermal_sensor *sensor = &data->sensor; hisi_thermal_toggle_sensor(sensor, false); hisi_thermal_disable_sensor(data); From patchwork Thu Oct 19 17:05:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 116425 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp723832qgn; Thu, 19 Oct 2017 10:10:49 -0700 (PDT) X-Received: by 10.84.211.3 with SMTP id b3mr1981432pli.292.1508433049356; Thu, 19 Oct 2017 10:10:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508433049; cv=none; d=google.com; s=arc-20160816; b=twIzCa/KL3Qtdx0cmOGN0AfjjevXSzdr3U5FZx1pssX8+za6s+JeEGw1EDOcg3N+fL wbZcnFh/v9tp82sgFnhOWaqYNV1SSaWlr38mLWaDmgI9s2Sp8ttLrRfCpe0LMlHqeIIH HOh79StxTwlxhSs/1kXxsKTdBIiVtltxPZ4LO/CUsqIqV/xt+lYSt5yfgVC2C9r8g/pj gCRJ1xZHIJc1PinWeSHNDPVROxzX8HLg/7+TiOwZvcEPpjFDsYg4Z+a89oN6q560ecAJ qZLBDyrIUZwqzdD4aTNAUJRVohsRcrdDsaUAmBXhLaT3BEJNyeVss/yoQlJMS5rtiUKn aV6w== 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=j2AvcOC6gLlpWKKQ1Dwm4/DyfkF2hZ8nsXzPlyo+nV0=; b=j+D0gYylJBvcM5emO6P9rqwmCQoSBTfB7GtnXgnSFv2hvConslJFFXOxKGDz4mpyjl Px+BJXKa8zUr3WA8OjBZyhABT192E/yuQV0lMDUz2FTEWlIAfcUe79XwHugm+180O2zu rr6HpVeEuiOLwTwKi9I/yso1OUyahnmK5xERw6PgtleaJTCyzu1i+3XXUA0l5WVCivwD oPgOolct85w13/B50M1yYVOoXSSo1EX4UHxGrAV0wVbbzcptg1Y4xYuFNMsUt7POca+G iUtOtobK3m6LDvUk0GgGuvQO9lTRsa6/sZbrJ3WHXjVNZv0olNtOOCjyabBILER6HL/b RlUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eqUksaPr; 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 e191si8848778pgc.788.2017.10.19.10.10.49; Thu, 19 Oct 2017 10:10:49 -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=eqUksaPr; 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 S1754094AbdJSRKr (ORCPT + 12 others); Thu, 19 Oct 2017 13:10:47 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:44244 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755085AbdJSRIr (ORCPT ); Thu, 19 Oct 2017 13:08:47 -0400 Received: by mail-wm0-f68.google.com with SMTP id 196so16741140wma.1 for ; Thu, 19 Oct 2017 10:08:47 -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=j2AvcOC6gLlpWKKQ1Dwm4/DyfkF2hZ8nsXzPlyo+nV0=; b=eqUksaPrWQszDuGXRMdnmKXC+BW1knQK6uouht7YIakf2v3tJ7mvtepSqlc4uYMmmP flCfXBajIjOnV4GMBEbG79+uWyQHejvGXouf1EpdHLrKLxUoiezX/VhBsVpRqdhen3Ui EQjm28ewrRtaApJjsT/CvUazATJBvT7nWUemE= 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=j2AvcOC6gLlpWKKQ1Dwm4/DyfkF2hZ8nsXzPlyo+nV0=; b=RHsNMN+LNMBu/OfjFrCC6uFN8J/DUOA1M3+8ki5l54JwbFXmq7wyDoglKHAassRKmi b9UvcZqobxCKKu5qmpyymifj6utIzAHRMhNzn92PXGNEYr9LTUqHq0cmlSy4cp/9u8l6 W5rfreiM5hqfVG6sZoT8ZUWeZdPqac5/aEBZPP3z/hX0nAuRGu6tpiRfrAKgC5mBVXBK T4gyGdFPZZyr5hADtJ3ju8GIt58I6PCm4JGAPRMUBk5nAVDNViTTWVsBOQ8QVnFmtOT1 Xrro9xrbu0SMU+3zBvXUfqUgmS4X0zEEDdwWJ2xJoBJhHrdR2yUjlNoIM9LiFHFo9M52 miag== X-Gm-Message-State: AMCzsaUl3T4kkzuup+zyDn4w2qIkoRqP6n4CmQDt04jN7pvqvWU/oyX2 8lfl5vYG/rA1XdqUBizRL6/fkg== X-Google-Smtp-Source: ABhQp+RRmF6J209oDb5psjXKLFc1nCePF0ptJr6RUo4EKmnWbTMzTXKGSvPNjuPqw9mFUPAFn6XwOw== X-Received: by 10.28.146.18 with SMTP id u18mr2315796wmd.28.1508432926535; Thu, 19 Oct 2017 10:08:46 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:51c7:d9b7:e14b:6840]) by smtp.gmail.com with ESMTPSA id g16sm14277394wrd.72.2017.10.19.10.08.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Oct 2017 10:08:46 -0700 (PDT) From: Daniel Lezcano To: edubezval@gmail.com, rui.zhang@intel.com Cc: linux-pm@vger.kernel.org, leo.yan@linaro.org, linux-kernel@vger.kernel.org Subject: [PATCH 12/18] thermal/drivers/hisi: Remove thermal data back pointer Date: Thu, 19 Oct 2017 19:05:54 +0200 Message-Id: <1508432760-17847-12-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508432760-17847-1-git-send-email-daniel.lezcano@linaro.org> References: <6ac48f08-7fe6-92e9-0801-6ed3bcd05ff1@linaro.org> <1508432760-17847-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 presence of the thermal data pointer in the sensor structure has the unique purpose of accessing the thermal data in the interrupt handler. The sensor pointer is passed when registering the interrupt handler, replace the cookie by the thermal data pointer, so the back pointer is no longer needed. Signed-off-by: Daniel Lezcano --- drivers/thermal/hisi_thermal.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 5382073..b77ca19 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -47,7 +47,6 @@ #define HISI_DEFAULT_SENSOR 2 struct hisi_thermal_sensor { - struct hisi_thermal_data *thermal; struct thermal_zone_device *tzd; uint32_t id; uint32_t thres_temp; @@ -211,10 +210,10 @@ static void hisi_thermal_disable_sensor(struct hisi_thermal_data *data) mutex_unlock(&data->thermal_lock); } -static int hisi_thermal_get_temp(void *_sensor, int *temp) +static int hisi_thermal_get_temp(void *__data, int *temp) { - struct hisi_thermal_sensor *sensor = _sensor; - struct hisi_thermal_data *data = sensor->thermal; + struct hisi_thermal_data *data = __data; + struct hisi_thermal_sensor *sensor = &data->sensor; *temp = hisi_thermal_get_temperature(data->regs); @@ -262,10 +261,10 @@ static int hisi_thermal_register_sensor(struct platform_device *pdev, const struct thermal_trip *trip; sensor->id = index; - sensor->thermal = data; sensor->tzd = devm_thermal_zone_of_sensor_register(&pdev->dev, - sensor->id, sensor, &hisi_of_thermal_ops); + sensor->id, data, + &hisi_of_thermal_ops); if (IS_ERR(sensor->tzd)) { ret = PTR_ERR(sensor->tzd); sensor->tzd = NULL; From patchwork Thu Oct 19 17:05:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 116422 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp722533qgn; Thu, 19 Oct 2017 10:09:30 -0700 (PDT) X-Received: by 10.98.163.2 with SMTP id s2mr2206061pfe.242.1508432970337; Thu, 19 Oct 2017 10:09:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508432970; cv=none; d=google.com; s=arc-20160816; b=r4ZIAhzhbgiLRH8VAwRAPEDrkopJHDEzT8LJhSTpu3Bhm61JRXxOgBrT0PNC9yeEPe JGiqfSKwCrCSmilp+xnHHy/txaUWovR2sVyoFCRGkWgnMKzKAz5fukAvk6ZsKkVAw7Z/ 4hF7y0hRfpstv9KsWABBjMf4cru8EjcuiYWSK5wM74j5e/O4AEI/rk+2O2Esx9Z/wXcM bSTWV/Gf/6yjKQzct1Lhe5qSyoxuuD9aRi9ZLF5BXSm9QYgfslG/ZCU3DXxXUwe1fUfu rBU4GIndwnoEdiRYmE9wBlcy/lfrbJupkjUxvqGI1LJeQXlwGKT1HBPtxEPXr8LZ4LXJ o/PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=l9O69Zgu7L3MlYgYnT3L0ZtiItPcwtBEfH+iilZLcWQ=; b=IbunNU1KT2T3APPSB08vFMRGO/Qrg6jqtt7izXHajjr5sBLdOgC7zRGVXcEpzqiviN LS/q2WQBRmIwzExqMHlC8spRlI/bfOSaVYgaKolcm7Qvq4FcrRwcWIfOo9uc4If+dljC xusqEs7lhk/lMoVT8IzfRoG//ds7zYVmlToQgXxuDEhdjlLvjNObWJ6wJWFCSGiXWNR0 QejhTZ7qbPSqCHwzsV4O2FY5DuNMVB5XnNZzDbZ89VxTtlCPFWqe0kS/yFzB6ukco8Pt TI94AjdNw9k6F6dE9PKBZDeen+ZAITtK2xpEcvHj9cL/3mFpRHdSc2JFyfekwIjdEGvC XmXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QC+V8Bwc; 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 y74si1483044pff.496.2017.10.19.10.09.30; Thu, 19 Oct 2017 10:09:30 -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=QC+V8Bwc; 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 S1755134AbdJSRJ2 (ORCPT + 12 others); Thu, 19 Oct 2017 13:09:28 -0400 Received: from mail-wm0-f45.google.com ([74.125.82.45]:47661 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755101AbdJSRIy (ORCPT ); Thu, 19 Oct 2017 13:08:54 -0400 Received: by mail-wm0-f45.google.com with SMTP id t69so17363984wmt.2 for ; Thu, 19 Oct 2017 10:08:53 -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 :mime-version:content-transfer-encoding; bh=l9O69Zgu7L3MlYgYnT3L0ZtiItPcwtBEfH+iilZLcWQ=; b=QC+V8BwcHryhpJ6XG3FVTaMf1S2290K2df7leCY57/DFi0ZPbkwCBgcQovetXWHSJD Za0pgudRBsFXGogrDnrgiEz977tuHRwauaFoYX4FXaLLhW5ZaPy+KRMwlv/yjitbA1eU vkPgr44KH87Hth5dP9bGMkEWkzLNKveCs6Zus= 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:mime-version:content-transfer-encoding; bh=l9O69Zgu7L3MlYgYnT3L0ZtiItPcwtBEfH+iilZLcWQ=; b=Ty1bxHfPJIZiZ6jMHafxj3yJ+JkkxgrIeg2mzxo6GthaRAdCxMA6C8Q484ooF96GAq nksDSS77G3MlcPrwdtm+9EX4JfzexIDzDaf4vPNUkCrAe0GBIUk+v2HARG7o6EcgCAzn 8qXdkElkOr6CK3bmizbp7oQdP1UO3wbnXMVxwQiN6fiKHyBIqLZbGIWiqqb7hIB450av rzPUK4DEYuC9qEv1pRbuIinp6eNifCjwS76W7IQ/YwCuM+oq8ld8YSkJIfAPoXfezjmk QIA9OFk5JX5ZDtQvZN/x2+obUxolA+gmpfSGkkNFpH0owoFAzPP6FQLBPIOzm+QdT4by 39LQ== X-Gm-Message-State: AMCzsaUstkUcV42TRCOqGrC/xl8I9em4s3o+VuZ2SsoEjybXJSDeWdp2 gx4kyb8+zdx2Rx8IFuoHsNgY+A== X-Google-Smtp-Source: ABhQp+S45k+Et5Dxj0a8T/gkRVeFsK2e3HuqDKvlFFwA7sFPGfXcBFAjRXaDqMWSCuNXPnDsNVUeBw== X-Received: by 10.28.199.75 with SMTP id x72mr2393090wmf.119.1508432932430; Thu, 19 Oct 2017 10:08:52 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:51c7:d9b7:e14b:6840]) by smtp.gmail.com with ESMTPSA id g16sm14277394wrd.72.2017.10.19.10.08.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Oct 2017 10:08:51 -0700 (PDT) From: Daniel Lezcano To: edubezval@gmail.com, rui.zhang@intel.com Cc: linux-pm@vger.kernel.org, leo.yan@linaro.org, linux-kernel@vger.kernel.org, Keerthy , John Stultz Subject: [PATCH 16/18] thermal/drivers/step_wise: Fix temperature regulation misbehavior Date: Thu, 19 Oct 2017 19:05:58 +0200 Message-Id: <1508432760-17847-16-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508432760-17847-1-git-send-email-daniel.lezcano@linaro.org> References: <6ac48f08-7fe6-92e9-0801-6ed3bcd05ff1@linaro.org> <1508432760-17847-1-git-send-email-daniel.lezcano@linaro.org> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org There is a particular situation when the cooling device is cpufreq and the heat dissipation is not efficient enough where the temperature increases little by little until reaching the critical threshold and leading to a SoC reset. The behavior is reproducible on a hikey6220 with bad heat dissipation (eg. stacked with other boards). Running a simple C program doing while(1); for each CPU of the SoC makes the temperature to reach the passive regulation trip point and ends up to the maximum allowed temperature followed by a reset. This issue has been also reported by running the libhugetlbfs test suite. What is observed is a ping pong between two cpu frequencies, 1.2GHz and 900MHz while the temperature continues to grow. It appears the step wise governor calls get_target_state() the first time with the throttle set to true and the trend to 'raising'. The code selects logically the next state, so the cpu frequency decreases from 1.2GHz to 900MHz, so far so good. The temperature decreases immediately but still stays greater than the trip point, then get_target_state() is called again, this time with the throttle set to true *and* the trend to 'dropping'. From there the algorithm assumes we have to step down the state and the cpu frequency jumps back to 1.2GHz. But the temperature is still higher than the trip point, so get_target_state() is called with throttle=1 and trend='raising' again, we jump to 900MHz, then get_target_state() is called with throttle=1 and trend='dropping', we jump to 1.2GHz, etc ... but the temperature does not stabilizes and continues to increase. [ 237.922654] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=1,throttle=1 [ 237.922678] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=1,throttle=1 [ 237.922690] thermal cooling_device0: cur_state=0 [ 237.922701] thermal cooling_device0: old_target=0, target=1 [ 238.026656] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=2,throttle=1 [ 238.026680] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=2,throttle=1 [ 238.026694] thermal cooling_device0: cur_state=1 [ 238.026707] thermal cooling_device0: old_target=1, target=0 [ 238.134647] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=1,throttle=1 [ 238.134667] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=1,throttle=1 [ 238.134679] thermal cooling_device0: cur_state=0 [ 238.134690] thermal cooling_device0: old_target=0, target=1 In this situation the temperature continues to increase while the trend is oscillating between 'dropping' and 'raising'. We need to keep the current state untouched if the throttle is set, so the temperature can decrease or a higher state could be selected, thus preventing this oscillation. Keeping the next_target untouched when 'throttle' is true at 'dropping' time fixes the issue. The following traces show the governor does not change the next state if trend==2 (dropping) and throttle==1. [ 2306.127987] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=1,throttle=1 [ 2306.128009] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=1,throttle=1 [ 2306.128021] thermal cooling_device0: cur_state=0 [ 2306.128031] thermal cooling_device0: old_target=0, target=1 [ 2306.231991] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=2,throttle=1 [ 2306.232016] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=2,throttle=1 [ 2306.232030] thermal cooling_device0: cur_state=1 [ 2306.232042] thermal cooling_device0: old_target=1, target=1 [ 2306.335982] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=0,throttle=1 [ 2306.336006] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=0,throttle=1 [ 2306.336021] thermal cooling_device0: cur_state=1 [ 2306.336034] thermal cooling_device0: old_target=1, target=1 [ 2306.439984] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=2,throttle=1 [ 2306.440008] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=2,throttle=0 [ 2306.440022] thermal cooling_device0: cur_state=1 [ 2306.440034] thermal cooling_device0: old_target=1, target=0 [ ... ] After a while, if the temperature continues to increase, the next state becomes 2 which is 720MHz on the hikey. That results in the temperature stabilizing around the trip point. [ 2455.831982] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=1,throttle=1 [ 2455.832006] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=1,throttle=0 [ 2455.832019] thermal cooling_device0: cur_state=1 [ 2455.832032] thermal cooling_device0: old_target=1, target=1 [ 2455.935985] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=0,throttle=1 [ 2455.936013] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=0,throttle=0 [ 2455.936027] thermal cooling_device0: cur_state=1 [ 2455.936040] thermal cooling_device0: old_target=1, target=1 [ 2456.043984] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=0,throttle=1 [ 2456.044009] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=0,throttle=0 [ 2456.044023] thermal cooling_device0: cur_state=1 [ 2456.044036] thermal cooling_device0: old_target=1, target=1 [ 2456.148001] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=1,throttle=1 [ 2456.148028] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=1,throttle=1 [ 2456.148042] thermal cooling_device0: cur_state=1 [ 2456.148055] thermal cooling_device0: old_target=1, target=2 [ 2456.252009] thermal thermal_zone0: Trip0[type=1,temp=65000]:trend=2,throttle=1 [ 2456.252041] thermal thermal_zone0: Trip1[type=1,temp=75000]:trend=2,throttle=0 [ 2456.252058] thermal cooling_device0: cur_state=2 [ 2456.252075] thermal cooling_device0: old_target=2, target=1 IOW, this change is needed to keep the state for a cooling device if the temperature trend is oscillating while the temperature increases slightly. Without this change, the situation above leads to a catastrophic crash by a hardware reset on hikey. This issue has been reported to happen on an OMAP dra7xx also. Signed-off-by: Daniel Lezcano Cc: Keerthy Cc: John Stultz Cc: Leo Yan Tested-by: Keerthy Reviewed-by: Keerthy --- drivers/thermal/step_wise.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/drivers/thermal/step_wise.c b/drivers/thermal/step_wise.c index be95826..ee047ca 100644 --- a/drivers/thermal/step_wise.c +++ b/drivers/thermal/step_wise.c @@ -31,8 +31,7 @@ * If the temperature is higher than a trip point, * a. if the trend is THERMAL_TREND_RAISING, use higher cooling * state for this trip point - * b. if the trend is THERMAL_TREND_DROPPING, use lower cooling - * state for this trip point + * b. if the trend is THERMAL_TREND_DROPPING, do nothing * c. if the trend is THERMAL_TREND_RAISE_FULL, use upper limit * for this trip point * d. if the trend is THERMAL_TREND_DROP_FULL, use lower limit @@ -94,9 +93,11 @@ static unsigned long get_target_state(struct thermal_instance *instance, if (!throttle) next_target = THERMAL_NO_TARGET; } else { - next_target = cur_state - 1; - if (next_target > instance->upper) - next_target = instance->upper; + if (!throttle) { + next_target = cur_state - 1; + if (next_target > instance->upper) + next_target = instance->upper; + } } break; case THERMAL_TREND_DROP_FULL: