From patchwork Tue Oct 10 18:02:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 9996923 X-Patchwork-Delegate: eduardo.valentin@ti.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 92B3760216 for ; Tue, 10 Oct 2017 18:07:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 88895286C6 for ; Tue, 10 Oct 2017 18:07:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D4EA28700; Tue, 10 Oct 2017 18:07:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0ABD9286C6 for ; Tue, 10 Oct 2017 18:07:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932557AbdJJSHP (ORCPT ); Tue, 10 Oct 2017 14:07:15 -0400 Received: from mail-wm0-f54.google.com ([74.125.82.54]:49029 "EHLO mail-wm0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932646AbdJJSFQ (ORCPT ); Tue, 10 Oct 2017 14:05:16 -0400 Received: by mail-wm0-f54.google.com with SMTP id i124so7424297wmf.3 for ; Tue, 10 Oct 2017 11:05:16 -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=4jSU0ID7ZCGaW3jMpZz+24E3JTJrZbYKmN7VT1hVyDA=; b=PLymuOlrXGhD7Mrx+EaUxvSrXjZPLiGX8f7zeu0XyD/OafiUJqwRWcYHeGZRCwcK1q NLgtYpVA037E3/x/EoqM9rfnOcfnvgx41yWevg9/7usWrQogzAJaWOF0wjq4eQnERXPP JhK1zxmEnFHbxSCYIJW66Mnm2j7RCl2zzNPkw= 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=4jSU0ID7ZCGaW3jMpZz+24E3JTJrZbYKmN7VT1hVyDA=; b=CIG+YLY9jZogS7EqxMVKMDjjEztPZCc+GNuJTwOsvccOcNgu1ORchM5PPjNDeVNzGu RRLeEV8HlzdVW4V9BlCdgYIPXLjt0vGN45GzCY+A3dAlaz0QuzGijXNf2EZaMk5Y9cdP FKFPiR3Z2vXCa0eH8/yyZMwOajv5OPQWcZv9WKmjs6svBTiCxMlEMqXnVMudVEnCEVXH wjaN1mOcgAnVydQ6p1lrDslEZRFppbm5hWsmDEkKXC2uH3LnF8uHzddupMF12HhKgf1T ot5JeRK+wrKCgFtKkMyFuGbKNyysqhYBIKDznbENAHxUzeBb6kkLuKMU/9CUmAN+NVKP Mnxw== X-Gm-Message-State: AMCzsaXwJWQl0miq+CDUx3ieXgAxWFmWR0iqgn2pmigEVmCJ/KiqVyGQ Z7LaTpcergtzT9ntgJ2TaemjO5Prjn0= X-Google-Smtp-Source: AOwi7QBYSWStoM81EnzIWt0eRCkkxK3KURBTCh07oHHX3JdgMWqzyInL+2R1JqyLGh8YGM30GLSY+Q== X-Received: by 10.223.131.65 with SMTP id 59mr12371622wrd.66.1507658715394; Tue, 10 Oct 2017 11:05:15 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:4f9:3ae1:43d2:31ae]) by smtp.gmail.com with ESMTPSA id l73sm12513428wmd.47.2017.10.10.11.05.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Oct 2017 11:05:14 -0700 (PDT) From: Daniel Lezcano To: edubezval@gmail.com, rui.zhang@intel.com Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, kevin.wangtao@linaro.org Subject: [PATCH 18/25] thermal/drivers/hisi: Use round up step value Date: Tue, 10 Oct 2017 20:02:43 +0200 Message-Id: <1507658570-32675-18-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507658570-32675-1-git-send-email-daniel.lezcano@linaro.org> References: <79a5f10c-0fb7-3e4f-caac-c1625904b137@linaro.org> <1507658570-32675-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 X-Virus-Scanned: ClamAV using ClamSMTP From: Kevin Wangtao Use round up division to ensure the programmed value of threshold and the lag are not less than what we set, and in order to keep the accuracy while using round up division, the step value should be a rounded up value. There is no need to use hisi_thermal_round_temp. Signed-off-by: Kevin Wangtao Signed-off-by: Daniel Lezcano --- drivers/thermal/hisi_thermal.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 02d0ad8..befdb28 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -40,7 +40,7 @@ #define HISI_TEMP_BASE (-60000) #define HISI_TEMP_RESET (100000) -#define HISI_TEMP_STEP (784) +#define HISI_TEMP_STEP (785) #define HISI_TEMP_LAG (3500) #define HISI_MAX_SENSORS 4 @@ -63,19 +63,19 @@ struct hisi_thermal_data { /* * The temperature computation on the tsensor is as follow: * Unit: millidegree Celsius - * Step: 255/200 (0.7843) + * Step: 200/255 (0.7843) * Temperature base: -60°C * - * The register is programmed in temperature steps, every step is 784 + * The register is programmed in temperature steps, every step is 785 * millidegree and begins at -60 000 m°C * * The temperature from the steps: * - * Temp = TempBase + (steps x 784) + * Temp = TempBase + (steps x 785) * * and the steps from the temperature: * - * steps = (Temp - TempBase) / 784 + * steps = (Temp - TempBase) / 785 * */ static inline int hisi_thermal_step_to_temp(int step) @@ -85,13 +85,7 @@ static inline int hisi_thermal_step_to_temp(int step) static inline int hisi_thermal_temp_to_step(int temp) { - return (temp - HISI_TEMP_BASE) / HISI_TEMP_STEP; -} - -static inline int hisi_thermal_round_temp(int temp) -{ - return hisi_thermal_step_to_temp( - hisi_thermal_temp_to_step(temp)); + return DIV_ROUND_UP(temp - HISI_TEMP_BASE, HISI_TEMP_STEP); } /* @@ -127,7 +121,7 @@ static inline int hisi_thermal_round_temp(int temp) */ static inline void hisi_thermal_set_lag(void __iomem *addr, int value) { - writel((value / HISI_TEMP_STEP) & 0x1F, addr + TEMP0_LAG); + writel(DIV_ROUND_UP(value, HISI_TEMP_STEP) & 0x1F, addr + TEMP0_LAG); } static inline void hisi_thermal_alarm_clear(void __iomem *addr, int value) @@ -274,7 +268,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 = hisi_thermal_round_temp(trip[i].temperature); + sensor->thres_temp = trip[i].temperature; break; } }