From patchwork Fri Sep 22 09:42:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Wangtao \(Kevin, Kirin\)" X-Patchwork-Id: 114007 Delivered-To: patch@linaro.org Received: by 10.80.163.150 with SMTP id s22csp2886060edb; Fri, 22 Sep 2017 02:51:29 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCAvDbruXDYOocsrLNcC2xyC+MTVUIM9c+1r02UMkR4pbv7tG422kLeqtpbExqnooLI6XQM X-Received: by 10.101.69.8 with SMTP id n8mr8709155pgq.167.1506073889203; Fri, 22 Sep 2017 02:51:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506073889; cv=none; d=google.com; s=arc-20160816; b=D5BKvkWe5zKMwJeLMTXGMHcQb90wACjUigmyAfQiNt/zp/e/NvTT57Xgjon59QSZ7e dRUtE6sSb7A3cSvdlMq+oZZKVGWoD0b8+VndXyyy+zNdS2mMtTIXxTKusrTeWUwBST8b 7/UUxcPxk1p96XswpFYTFeutgLIDVGXBPIr0RGL0hnzpjjtiDTDgHRhnxt1tMd6pEX8n 8MmFHPT4RqHf8QN7A0ufwFqIbC+mqeaaj5gtJideOI6/UQqk1CkCOG+K9nmdfrrPeGzK W1lvg9kB/Zti6FsYi3pajlkVWCwcbavNl6YxuNNwc0irOeXatxG34Gb3IPGZCMjEhZ9w Ie0g== 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 :arc-authentication-results; bh=8P6FqYSTX7RhLkK0cTcs+7X5G1tjXM8sr73DVpBUwk0=; b=Oc4nC1O8cci505DFhhCn/Y47os6pPAWym3lpH6qupg57uGHvcFe6bqbaFyYR8UlV3T bauARjZGz69Cs+jHZ7H7ut1XY16UbewjZ/1QmCUImsrbvidIRQjAohLt5lDl9iDpyqTT AvHTdJBZBNpdCHu+D4+BFWmaPilDqLMVgW4qhmJWH4Sb2AiyQS4czUnO5S9tAun+T8BN dQQwF3fuXqdYs5wZdZ31nIvKdAz9NxCwi7bvGMR9Ias3DmAVF6blonrRM9LDvRXZPLo9 Qyng91KE4Zg8RH8pMFH6JwcwvXHzhpfSzjlRjOCipOXIOzNmf33SmjtVnkgcRQZKErPV NVBw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q87si2492153pfa.98.2017.09.22.02.51.28; Fri, 22 Sep 2017 02:51:29 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752258AbdIVJv1 (ORCPT + 26 others); Fri, 22 Sep 2017 05:51:27 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:6974 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751903AbdIVJt1 (ORCPT ); Fri, 22 Sep 2017 05:49:27 -0400 Received: from 172.30.72.58 (EHLO DGGEMS403-HUB.china.huawei.com) ([172.30.72.58]) by dggrg04-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DHT00602; Fri, 22 Sep 2017 17:49:20 +0800 (CST) Received: from HSH1000038028.huawei.com (10.177.161.152) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.301.0; Fri, 22 Sep 2017 17:49:10 +0800 From: Tao Wang To: , , , , , , CC: , , , , , , , , , , , Kevin Wangtao Subject: [PATCH 2/9] thermal/drivers/hisi: use round up step value Date: Fri, 22 Sep 2017 17:42:05 +0800 Message-ID: <1506073332-92438-3-git-send-email-kevin.wangtao@hisilicon.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1506073332-92438-1-git-send-email-kevin.wangtao@hisilicon.com> References: <1506073332-92438-1-git-send-email-kevin.wangtao@hisilicon.com> MIME-Version: 1.0 X-Originating-IP: [10.177.161.152] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090203.59C4DCA1.004F, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: e149e59e30c9246686733c6e9fa08711 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 divide to ensure the programmed value of threshold and lag not less than we set, and in order to keep the accuracy while using round up divide, the step value should also be a round up value. Then there is no need to use hisi_thermal_round_temp. Signed-off-by: Kevin Wangtao --- drivers/thermal/hisi_thermal.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) -- 2.8.1 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index c43e3df..c8b651d 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; } }