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: 115435 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp4041301qgn; Tue, 10 Oct 2017 11:07:18 -0700 (PDT) X-Received: by 10.84.130.35 with SMTP id 32mr12681177plc.368.1507658838644; Tue, 10 Oct 2017 11:07:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507658838; cv=none; d=google.com; s=arc-20160816; b=p7IMft1pW8PeiEuA1iO9e5ucZd3BLuMCxfgrRHcgoHZS2MVScPDzbAXLPj7G4N7+OV DydQ1V7jhOVm78dpF+KmPout3ctqz4n53ni6QTFMNp7/O7hnGE09WRX527bvRGGMFhLq ETibpWcg/AVRCwtwMO+DQkvJgPesJBj7TohScqK59b/eQ2GBW9E7hHxjINILMeq58MTv E5e+3XW62DdIzWwGf7cDB1ysvgUj2Bojamk3vNSHuxlYZbFOm5KbpF9Jhg+R/WQ9RpaF T/WAfyTNxv3FhV4/UKAgI6dE4CVAb6CiNciiF95L5naBkliFH/dVtn6YEo59Bso1HZpf KCjw== 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=4jSU0ID7ZCGaW3jMpZz+24E3JTJrZbYKmN7VT1hVyDA=; b=ce1zncLj/gacK2KuYUquwAdSzK29FjYRiMWHwLC5IcWMkRsq+Aw0j0VvY0MvM1EW+t QcZk2YSXzFLws5Lv1vXFLn5dph4WLznAa7w50iysNS6kIIAZ47SzMnrapFMmEK95yiTH Tzb6Zta2Q2ZtcE0UDRO/kCQFJ06XiBYM0TOx4Bvm8h4iNEP6N44lzEjfMko9ZJOXrKnS G4lrn+7A2GUot+cIS5Reh8g8T25N2XIFbpDtPm5aiKjZgGANfiH0ZsqYtMwpnnhBSQaR GbqEeLECo8J15ZvzBR4KP3wnIHlblYCF+7tMRYk70XRfmeoFHFhDrane6hmm6Y8X6t2v jTYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PLymuOlr; 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 44si9460332pla.680.2017.10.10.11.07.18; Tue, 10 Oct 2017 11:07:18 -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=PLymuOlr; 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 S932764AbdJJSHP (ORCPT + 26 others); Tue, 10 Oct 2017 14:07:15 -0400 Received: from mail-wm0-f52.google.com ([74.125.82.52]:45736 "EHLO mail-wm0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932647AbdJJSFQ (ORCPT ); Tue, 10 Oct 2017 14:05:16 -0400 Received: by mail-wm0-f52.google.com with SMTP id q124so7517326wmb.0 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=Xkmn+fepk8vkG55ZSU8ETL/ktgJ+j6Q6GnsKUvVZV8qsNJ3TS3y9ceY2cqeYiHNTMI D1GHVEyv+Smcx3qfgc0yJIZT+dVch8Pz5y8DkkELlAvwEFl+7bHwKFzob3PY8/A4MCvh iGHi8uNlwXPXVH1T7WsrQsOUX/ESBGpVK2NzDjG/ch7urTuyhgoYayz5dyFHGfyMMmFR KUPV6lQ1Mf4lOR1Gx6abTtP0WtUO3RfwVVZRt2a2qo2Nv5Z3eYDTfTpnyNrct78zHqxW D34L4OzxXpIA74Mx9wba3CtIj2OKfwmXj5yPIEeEQguoJFxGXsJuscl/SfnorHe6HEJ/ gdbw== X-Gm-Message-State: AMCzsaUEig1CNY2RI25xKqJWoQZtBR2hVMw/Ody+ovNWwh12q2BhDsSc +7mlug5WuRB42Du5DRPZ8N/HUQ== 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.7.4 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; } }