Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp1784999ybc; Sun, 24 Nov 2019 06:10:49 -0800 (PST) X-Google-Smtp-Source: APXvYqzQRz29NMx/xdHtS8xx352vWnA2LLQgc1+RRg8CNqA3ks1oKovg6R3ntQ3lej+XmWvS6SMv X-Received: by 2002:aa7:c59a:: with SMTP id g26mr12755536edq.109.1574604649104; Sun, 24 Nov 2019 06:10:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574604649; cv=none; d=google.com; s=arc-20160816; b=0QCf5MLYGUC7cVvFmQ6rF+be6Mfr567MoR1vOMQwONrtVXsqVCwOH7OyDWHYs4IUkh IYCHXzMk+nc42wwa506wrAtHgcwyQdRn1YP51KABNhwxNVPc7JCtF2W8njJL4UlYPLa6 sQhhXOGAaR4GEBDNymHc8DpROuoX0T5/QPGQFZu+dDeryDfG+/iKvc2A9wWuB7yyx1Iz QNX+4EZuAgnADo8tQeWzKFvw+Omz9ai6LVJajO+abWzZ3CL3gNNzn0qIeFxeAz9cXfz6 Jqwa+9S9ka/sFpABmnEV4g6j46cHgYVo8u76EdGxzDKq34IdrNiTs8WntlVB8EWj7tGp NMIw== 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; bh=uiVaOYC0AJAeDJiNsTnIMMgr41e8eY8TpWvmzxTalS8=; b=soJo5b5kuDaNOrQmtL/gyT37QBkKJAohgXoLvi56e1/46SI0Fb2OWTaE3OiYkQyVkt zhmjb2Ba4N+hroF75FYAXso/PODjWKOuVZMCKtb3kfNRdtK5qfUq42KjgATG13vA5X+g AHIwstMhXuC4MkkJbPVw1+P5ISVtlv6lu4i8NWmo79irB/7wDrhHvFlgWRnU/oeKpCFL eaXjTRcOECSrFdZKVHnATVn//yycF0Xi4DoKiJJ6/BDOXCkvuprdVgrP7rAS0leqac+P G6vfns2ee6n4T35PaQUGPFVl+1346tRZaipZgLmdNzV8Us/VcajH3VeUm5kuZ34HED4+ bN3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UZIHl+Fv; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c3si3109786edx.315.2019.11.24.06.10.24; Sun, 24 Nov 2019 06:10:49 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=UZIHl+Fv; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727125AbfKXOJP (ORCPT + 99 others); Sun, 24 Nov 2019 09:09:15 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:44235 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726767AbfKXOJN (ORCPT ); Sun, 24 Nov 2019 09:09:13 -0500 Received: by mail-pf1-f195.google.com with SMTP id d199so1330965pfd.11; Sun, 24 Nov 2019 06:09:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uiVaOYC0AJAeDJiNsTnIMMgr41e8eY8TpWvmzxTalS8=; b=UZIHl+FvynMquo91lmoV5lbWmLcB+8Iw8tQF+m0vCBO8UCd9CRAQcTeAd+sMHZP4jo B6Xmatc+2rgYJ+34ssDGYNBtJiUINZ7+QB/gQplVjthaNSrMy7CSwwU1ucQLlf6Giaof RmRShwUrp8NUVqYWsha6437Pq0+vhr3TLYELT1yPmV1/KZZmDjeJbQFOq3MaBxRqYQQl SHu6KL9a66DZesCDnoB59cQL5Rh1E/13ZazzHc7ARMdE7lHt6pFFCXdkGHuk2BCh37uM A2hSAc1RcaWOLGy67uLEvZGH2wuKAwZsFzYeDmcmMK3gnM/ALNPxjGQhAOJ1zNSS55O+ yqNg== 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=uiVaOYC0AJAeDJiNsTnIMMgr41e8eY8TpWvmzxTalS8=; b=uFylDnKrPaO6Nmgi1tavMINCYDwrQLnlnR83cYpC4RFCQagBui8i6sv2BOMxmAdq57 Mzen7I9hno87+FhNAb3fdlFDzdYfRjhQ+3TABRUUnXPQuoOfQFPXYM3xv5W93KC5PSqT tf632b94GdNW44sRl49/A4iM3rR7ErrCXU8zcUnaP3kFyDP/Fzk88IzkCnOmHN/BhFyi 4rIew1IkO1U7SXG642iOfzo635edMXIJp/+Xa9l0tFYOf0TeQzPhnLai0RgDNptkX+hr XTJoYiSh5XhEip1d/72f4tFXcX807qSfVAQJwhdiR69SrnEfTSpk7NPmQBWTQD4Ke/Sm s2DQ== X-Gm-Message-State: APjAAAU8127VBFfg6nhL17eKFKofTgwNV9D98yOO8qElJV6RemKNJTas 4+4FjnIRqxznQT+ZoIpFqH+YjBeR870= X-Received: by 2002:aa7:8b1a:: with SMTP id f26mr8162545pfd.81.1574604552956; Sun, 24 Nov 2019 06:09:12 -0800 (PST) Received: from localhost.localdomain ([240f:34:212d:1:368e:e048:68f1:84e7]) by smtp.gmail.com with ESMTPSA id a3sm4816326pgh.91.2019.11.24.06.09.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 24 Nov 2019 06:09:12 -0800 (PST) From: Akinobu Mita To: linux-nvme@lists.infradead.org, linux-hwmon@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Akinobu Mita , Sujith Thomas , Darren Hart , Andy Shevchenko , Zhang Rui , Eduardo Valentin , Daniel Lezcano , Amit Kucheria , Jean Delvare , Guenter Roeck , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg Subject: [PATCH 1/8] add header file for kelvin to/from Celsius conversion helpers Date: Sun, 24 Nov 2019 23:08:43 +0900 Message-Id: <1574604530-9024-2-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1574604530-9024-1-git-send-email-akinobu.mita@gmail.com> References: <1574604530-9024-1-git-send-email-akinobu.mita@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are several helper macros to convert kelvin to/from Celsius in for thermal drivers. These are useful for any other drivers or subsystems, but it's odd to include just for the helpers. This adds a new that provides the equivalent inline functions for any drivers or subsystems. It is intended to replace the helpers in . Cc: Sujith Thomas Cc: Darren Hart Cc: Andy Shevchenko Cc: Zhang Rui Cc: Eduardo Valentin Cc: Daniel Lezcano Cc: Amit Kucheria Cc: Jean Delvare Cc: Guenter Roeck Cc: Keith Busch Cc: Jens Axboe Cc: Christoph Hellwig Cc: Sagi Grimberg Signed-off-by: Akinobu Mita --- include/linux/temperature.h | 39 +++++++++++++++++++++++++++++++++++++++ include/linux/thermal.h | 1 + 2 files changed, 40 insertions(+) create mode 100644 include/linux/temperature.h diff --git a/include/linux/temperature.h b/include/linux/temperature.h new file mode 100644 index 0000000..d7e2aed --- /dev/null +++ b/include/linux/temperature.h @@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_TEMPERATURE_H +#define _LINUX_TEMPERATURE_H + +#include + +#define ABSOLUTE_ZERO_MILLICELSIUS -273150 + +static inline long kelvin_to_millicelsius(long t) +{ + return t * 1000 + ABSOLUTE_ZERO_MILLICELSIUS; +} + +static inline long millicelsius_to_kelvin(long t) +{ + return DIV_ROUND_CLOSEST(t - ABSOLUTE_ZERO_MILLICELSIUS, 1000); +} + +static inline long deci_kelvin_to_celsius(long t) +{ + return DIV_ROUND_CLOSEST(t * 100 + ABSOLUTE_ZERO_MILLICELSIUS, 1000); +} + +static inline long celsius_to_deci_kelvin(long t) +{ + return t * 10 - DIV_ROUND_CLOSEST(ABSOLUTE_ZERO_MILLICELSIUS, 100); +} + +static inline long deci_kelvin_to_millicelsius(long t) +{ + return t * 100 + ABSOLUTE_ZERO_MILLICELSIUS; +} + +static inline long millicelsius_to_deci_kelvin(long t) +{ + return DIV_ROUND_CLOSEST(t - ABSOLUTE_ZERO_MILLICELSIUS, 100); +} + +#endif /* _LINUX_TEMPERATURE_H */ diff --git a/include/linux/thermal.h b/include/linux/thermal.h index e45659c..ed549e4 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include -- 2.7.4