From patchwork Thu Oct 19 17:05:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 116420 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp722010qgn; Thu, 19 Oct 2017 10:08:58 -0700 (PDT) X-Received: by 10.159.218.135 with SMTP id w7mr2031809plp.229.1508432938735; Thu, 19 Oct 2017 10:08:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508432938; cv=none; d=google.com; s=arc-20160816; b=ZKXzkFpGgzBvOdyEc9YocybGyTJxVqbJJKFOpuEjbRDoiJ0cBtZe9Xb7ifgPUGIEON Wd2K8VpbMFEh2TV2bD59QXpOiFPXwyRCOBzwp9K91Qkurb5ToqEyCbGQemf8OzFAW083 24WBq0scNtaatCz3TMvCZ6Z2WxSk29/TDf2g0u6dsO8c3KTS8N7V1nMUwZuzPJ8gI2wy RFptyl8vMcNpmmf34Y6rVcZIMptUy5M6Iu0ZPRofEQ8yxaso5Bn9WrfVqHc1dzzAvj/i +JYo/T+IWDhh5fVKqyahmBHj4wVN/bpiTtNuIrigv4rrEKT6GlMrDcEFIgWORFu78M2y BB6A== 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=GXkHr9S270dLkhuUiQbappPpev4Lnh5qNTan11darjg=; b=R19yhpY/ghULkJ6zWoXYW3HoStSnscNaPiMSX3IyAmvG/Sb1n8ARSo57FRpfo08qhK qJ0CMq0/rXt8+19OeQ8jkw39Pe1c5bh+bbhTD6DCUc9pQek6d6tHMi4COTBNKruciKxR jnaqi0dV2m3RIaiWJlpKxUdk3oWKqhzBB5hxd5FqrCSlThgTp3kleeLWhOIRGgusJ4eG +Y4/iYw8heJh4Jm2xCbMfB7WD1vHDY7KvYg4kPPI/ZueMK1Ckqs5+0yLFwyueBqBNmY1 vOYX1zU5oooSBaNEU77aWvhv2ERiVlFi/gG/PvtOf4yJ/Y1dfStw8Wb8USUIYEZzWiYW eoxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ia654xIC; 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 l11si4409160pgq.28.2017.10.19.10.08.58; Thu, 19 Oct 2017 10:08:58 -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=Ia654xIC; 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 S1755153AbdJSRI4 (ORCPT + 27 others); Thu, 19 Oct 2017 13:08:56 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:46606 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755116AbdJSRIw (ORCPT ); Thu, 19 Oct 2017 13:08:52 -0400 Received: by mail-wr0-f193.google.com with SMTP id l1so9047364wrc.3 for ; Thu, 19 Oct 2017 10:08:51 -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=GXkHr9S270dLkhuUiQbappPpev4Lnh5qNTan11darjg=; b=Ia654xICXE8HzrLX1/kp6jzYSQr2IpLOwwKziBGuqftSx5GFpY5Ip9aB2z4shxUhPa U8ll8AFx8x0HjC9Ff4V2UvgbzYIF6tr1qrF4xkrmWbJiITvjoi6RQTGVW2JfsSUVHg6x C0ay8/ZWeK3DJBDAEyL9DRg2JuAEJXX98Byuk= 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=GXkHr9S270dLkhuUiQbappPpev4Lnh5qNTan11darjg=; b=GXkZ63KhYUluviA6j+zGYDDoCx1do1bvWRm6kfkV5fgMxl4/c/mOkO722iBSdSmSPB gXjhChWsypMRIr8ga5ZlMqGiY6iGRgte+ppt/L9Lv7LmwBajhzPJpsV62Ic3z0Z2gpK5 FtvrHIDS5lrhY3UVhctBMuxNe5w0FMkQW2fr3iHwn8T5oWQ4z/e+qYSwMntaTmeSz943 pPg1cJ2jcZZLB80s8ZqMIyRyVH6L1CWnu1w9nzKROL2bgjK471WZh8fIgZhwKIB1W4De VMaBqG78FSn0h9JvgCv38QQoR8kq50MMyY6ceJZc4O2SPEcG+cRaQVcfe4ODykgvMIOl G79A== X-Gm-Message-State: AMCzsaVGABCqQkf3iDgtgLJ5ztQ80LbnNX9EyEZ0jA3NNTdruyDybKlx iamCCQAbveOfwR1DMQ/UA1XsDQ== X-Google-Smtp-Source: ABhQp+RuUsknBGGYmcCrhUleBaFE0r8uRCXP65bO8tnd/Da4z0pDxlIXiKSCKmynLryt84MMEZQzkA== X-Received: by 10.223.185.78 with SMTP id b14mr2271703wrg.197.1508432930916; Thu, 19 Oct 2017 10:08:50 -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.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Oct 2017 10:08:50 -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, Kevin Wangtao Subject: [PATCH 15/18] thermal/drivers/hisi: Use round up step value Date: Thu, 19 Oct 2017 19:05:57 +0200 Message-Id: <1508432760-17847-15-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-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 Tested-by: Daniel Lezcano # hikey6220 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 b9e4a9a..b48e47e 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; } }