Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp727988ybl; Wed, 11 Dec 2019 06:39:19 -0800 (PST) X-Google-Smtp-Source: APXvYqwuNbwagQ8wKlYbbutOmZyicP6wzbw1KjK9Eneu7FzKh/cfd84qW9KaaMWtJub3Xu6ziVbM X-Received: by 2002:a9d:22a8:: with SMTP id y37mr2424765ota.359.1576075159608; Wed, 11 Dec 2019 06:39:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576075159; cv=none; d=google.com; s=arc-20160816; b=Xsyao19cP9W6QmaHMrQbOkNeef0Yw0u4xGIMDg6/FwtI4Kyh84lqrGTP+Ej/Rh4CjT HGQekhsVX5W+DgFqwbeXsGftIYqvjIR2mMVVAgTdbxRQHwQcRcd098RtVZZCGnULei47 9sshHbUFay8zpAxctx6Vvtc0pYK1EmxvAuawEC8mJOsJuWClC+7gYGo3JYmzpnbdnMOd BAJw8hjWsIqX47g2upPdQjPEBftUXW+xxx4pZWD3CLSCtGFHMpwzQk7ArhZzF/xcZw+K oYt8u+HnNYaDppwpeBM9bucwC2Flh9LHRjEPylq4RNZfB4TO5ncD/xuH6RuwiqOYhZBA v33Q== 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=l0g2yitOap2PZ563u5lrVGdcbHo44KhhJk/TqjJ9Bls=; b=jVy6HgobYwcLPkbWpvQMo83SuT2+JzSF7vi7we0BjYhSmZCpU7es0WMyG0TqmXMoOP qYeMaRIhRmj8MAOQDNb4cAHk3A74rIVv0ZAjS9AZBAwBzJRLk6wNFI9pxPOQnyJp3Ia/ USxrqf9pBHzS9S58OBo8K9Y2nADgO+nN38MiDyCDSebxoJ/WeDPowhefSvl+afbb6v7/ 37ZiyzzcCY92KgQHnGjcXp/wD0WjM+4UUuVCGainfXLSOlhlY9Ih8jGMyb6YiJvN5ftl 5MNX3gpNm4TzS70f9qGbpDd2XfY3wPpIt6nVJrHw4dOSCXvWHI1TJSYMT5ChJrjb/8hK dh3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="n/zyW7ze"; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-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 h22si1235013oie.15.2019.12.11.06.39.09; Wed, 11 Dec 2019 06:39:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-wireless-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="n/zyW7ze"; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-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 S1729934AbfLKOi4 (ORCPT + 99 others); Wed, 11 Dec 2019 09:38:56 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:33854 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727554AbfLKOi4 (ORCPT ); Wed, 11 Dec 2019 09:38:56 -0500 Received: by mail-pf1-f193.google.com with SMTP id l127so635229pfl.1; Wed, 11 Dec 2019 06:38:55 -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=l0g2yitOap2PZ563u5lrVGdcbHo44KhhJk/TqjJ9Bls=; b=n/zyW7zeFhMU5gj3nvHALhoD0Cni+mTg66+JciqG64jKfxuDYWCuHFshRuKw9PzcVR UPAhcWK8PMXQJvYTKwWVJxtE93sBSkxt97rrtEQIGwWkoZ1GYIbhP1dc6cBA47HAr7fq 7HZyBS8L+8zimgtYc0u2Qxogpoe9wos3NUr+I8uQNBQ2QVMH43qaylcRH6Fy7GLt4cV7 Q3DztC7PRqjIfQG8uHRpfhPlvaIVfJ23nQyyG/nE6Xu/em+ek7hvnX2atXSHwTL/ryKg m776Nu2T7ruyegOFT76AFo2uyLAC2UWE0ZgYTo6SUra3dBBLtNc3N/WoplLyovVh9w/h MbTw== 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=l0g2yitOap2PZ563u5lrVGdcbHo44KhhJk/TqjJ9Bls=; b=X3z3ZBLIMFZxvR4ua9ijL0Nml+3XlF/t+QpYloNcNtRU4fp22cgMFkjrR4j+Y2jW3U K8Spg/rH7JkoEdr6uZXnXhhroU20v3zUiprz0d4qVGYAaJeXumk+JaOUC5E/l33q/ZBN N39Lc/q8FEHL/AJQK6PqE3DRLUTHkvhzo3421F7NwFRjw/8mqfzv9xQ+eiOflfpNGMTq xPNM6iWd9gAT2Pp8zwx/u909isjg+C0ZShuMZ2Xgyp4ioMwLwwjqf4fFEDRfZC9KYGCH 02SGUMcKu/6lqVkZjYHBYp7z2vSluodzm09pQec5bP1Bq1T6hawE9nQblYzaPtDWawvi eQ8w== X-Gm-Message-State: APjAAAUnnEpjOmMkiuTrXoKEnG+wOxwh5TssAVSgCbnlVPV2gWe3nwTp gosv68uxkzcqr+5o1U/nakzDyMLIfSepCQ== X-Received: by 2002:a63:ea17:: with SMTP id c23mr4526029pgi.85.1576075135462; Wed, 11 Dec 2019 06:38:55 -0800 (PST) Received: from localhost.localdomain ([240f:34:212d:1:368e:e048:68f1:84e7]) by smtp.gmail.com with ESMTPSA id q11sm3444239pff.111.2019.12.11.06.38.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Dec 2019 06:38:54 -0800 (PST) From: Akinobu Mita To: linux-nvme@lists.infradead.org, linux-hwmon@vger.kernel.org, linux-pm@vger.kernel.org, linux-wireless@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Akinobu Mita , Sujith Thomas , Darren Hart , Andy Shevchenko , Zhang Rui , Daniel Lezcano , Amit Kucheria , Jean Delvare , Guenter Roeck , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Kalle Valo , Stanislaw Gruszka , Johannes Berg , Emmanuel Grumbach , Luca Coelho , Intel Linux Wireless , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler Subject: [PATCH v3 01/12] add helpers for kelvin to/from Celsius conversion Date: Wed, 11 Dec 2019 23:38:08 +0900 Message-Id: <1576075099-3441-2-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1576075099-3441-1-git-send-email-akinobu.mita@gmail.com> References: <1576075099-3441-1-git-send-email-akinobu.mita@gmail.com> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@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: Daniel Lezcano Cc: Amit Kucheria Cc: Jean Delvare Cc: Guenter Roeck Cc: Keith Busch Cc: Jens Axboe Cc: Christoph Hellwig Cc: Sagi Grimberg Cc: Kalle Valo Cc: Stanislaw Gruszka Cc: Johannes Berg Cc: Emmanuel Grumbach Cc: Luca Coelho Cc: Intel Linux Wireless Cc: Jonathan Cameron Cc: Hartmut Knaack Cc: Lars-Peter Clausen Cc: Peter Meerwald-Stadler Signed-off-by: Akinobu Mita --- * v3 - rename new header name from to - add milli_kelvin_to_millicelsius() and millicelsius_to_milli_kelvin() and use them for implementing other helpers - add MILLIDEGREE_PER_DEGREE and MILLIDEGREE_PER_DECIDEGREE and replace the hardcoded constants - add kelvin_to_celsius() and celsius_to_kelvin() in include/linux/units.h | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 include/linux/units.h diff --git a/include/linux/units.h b/include/linux/units.h new file mode 100644 index 0000000..aaf7163 --- /dev/null +++ b/include/linux/units.h @@ -0,0 +1,84 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_UNITS_H +#define _LINUX_UNITS_H + +#include + +#define ABSOLUTE_ZERO_MILLICELSIUS -273150 + +static inline long milli_kelvin_to_millicelsius(long t) +{ + return t + ABSOLUTE_ZERO_MILLICELSIUS; +} + +static inline long millicelsius_to_milli_kelvin(long t) +{ + return t - ABSOLUTE_ZERO_MILLICELSIUS; +} + +#define MILLIDEGREE_PER_DEGREE 1000 +#define MILLIDEGREE_PER_DECIDEGREE 100 + +static inline long kelvin_to_millicelsius(long t) +{ + return milli_kelvin_to_millicelsius(t * MILLIDEGREE_PER_DEGREE); +} + +static inline long millicelsius_to_kelvin(long t) +{ + t = millicelsius_to_milli_kelvin(t); + + return DIV_ROUND_CLOSEST(t, MILLIDEGREE_PER_DEGREE); +} + +static inline long deci_kelvin_to_celsius(long t) +{ + t = milli_kelvin_to_millicelsius(t * MILLIDEGREE_PER_DECIDEGREE); + + return DIV_ROUND_CLOSEST(t, MILLIDEGREE_PER_DEGREE); +} + +static inline long celsius_to_deci_kelvin(long t) +{ + t = millicelsius_to_milli_kelvin(t * MILLIDEGREE_PER_DEGREE); + + return DIV_ROUND_CLOSEST(t, MILLIDEGREE_PER_DECIDEGREE); +} + +/** + * deci_kelvin_to_millicelsius_with_offset - convert Kelvin to Celsius + * @t: temperature value in decidegrees Kelvin + * @offset: difference between Kelvin and Celsius in millidegrees + * + * Return: temperature value in millidegrees Celsius + */ +static inline long deci_kelvin_to_millicelsius_with_offset(long t, long offset) +{ + return t * MILLIDEGREE_PER_DECIDEGREE - offset; +} + +static inline long deci_kelvin_to_millicelsius(long t) +{ + return milli_kelvin_to_millicelsius(t * MILLIDEGREE_PER_DECIDEGREE); +} + +static inline long millicelsius_to_deci_kelvin(long t) +{ + t = millicelsius_to_milli_kelvin(t); + + return DIV_ROUND_CLOSEST(t, MILLIDEGREE_PER_DECIDEGREE); +} + +static inline long kelvin_to_celsius(long t) +{ + return t + DIV_ROUND_CLOSEST(ABSOLUTE_ZERO_MILLICELSIUS, + MILLIDEGREE_PER_DEGREE); +} + +static inline long celsius_to_kelvin(long t) +{ + return t - DIV_ROUND_CLOSEST(ABSOLUTE_ZERO_MILLICELSIUS, + MILLIDEGREE_PER_DEGREE); +} + +#endif /* _LINUX_UNITS_H */ -- 2.7.4