linux-hwmon.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 00/12] add header file for kelvin to/from Celsius conversion helpers
@ 2019-12-15  5:16 Akinobu Mita
  2019-12-15  5:16 ` [PATCH v4 01/12] add helpers for kelvin to/from Celsius conversion Akinobu Mita
                   ` (12 more replies)
  0 siblings, 13 replies; 15+ messages in thread
From: Akinobu Mita @ 2019-12-15  5:16 UTC (permalink / raw)
  To: linux-nvme, linux-hwmon, linux-pm, linux-wireless, linux-iio,
	linux-kernel, akpm
  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

There are several helper macros to convert kelvin to/from Celsius in
<linux/thermal.h> for thermal drivers.  These are useful for any other
drivers or subsystems, but it's odd to include <linux/thermal.h> just for
the helpers.

This adds a new <linux/units.h> that provides the equivalent inline
functions for any drivers or subsystems, and switches all the users of
conversion helpers in <linux/thermal.h> to use <linux/units.h>
helpers.

* v4
- add Reviewed-by and Acked-by tags
- change include order
- keep the line over 80 characters because this change doesn't make it longer
- remove "wireless: " in the title

* v3
- rename new header name from <linux/temperature.h> to <linux/units.h>
- 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 <linux/units.h>
- add Reviewed-by tags
- switch iwlegacy driver to use <linux/units.h> helpers
- switch iwlwifi driver to use <linux/units.h> helpers
- remove unused TO_MCELSIUS macro in armada thermal driver
- switch qcom-vadc-common module to use <linux/units.h> helpers

* v2
- add deci_kelvin_to_millicelsius_with_offset() in linux/temperature.h
- stop including linux/temperature.h from linux/thermal.h
- include <linux/temperature.h> explicitly from thermal drivers
- fix s/temprature/temperature/ typo in commit log
- use deci_kelvin_to_millicelsius_with_offset() in ACPI thermal zone driver
- don't mix up another fix (format string for cellsius value)
- add Acked-by and Reviewed-by tags

Akinobu Mita (12):
  add helpers for kelvin to/from Celsius conversion
  ACPI: thermal: switch to use <linux/units.h> helpers
  platform/x86: asus-wmi: switch to use <linux/units.h> helpers
  platform/x86: intel_menlow: switch to use <linux/units.h> helpers
  thermal: int340x: switch to use <linux/units.h> helpers
  thermal: intel_pch: switch to use <linux/units.h> helpers
  nvme: hwmon: switch to use <linux/units.h> helpers
  thermal: remove kelvin to/from Celsius conversion helpers from
    <linux/thermal.h>
  iwlegacy: use <linux/units.h> helpers
  iwlwifi: use <linux/units.h> helpers
  thermal: armada: remove unused TO_MCELSIUS macro
  iio: adc: qcom-vadc-common: use <linux/units.h> helpers

 drivers/acpi/thermal.c                             | 34 ++++-----
 drivers/iio/adc/qcom-vadc-common.c                 |  6 +-
 drivers/iio/adc/qcom-vadc-common.h                 |  1 -
 drivers/net/wireless/intel/iwlegacy/4965-mac.c     |  3 +-
 drivers/net/wireless/intel/iwlegacy/4965.c         | 11 +--
 drivers/net/wireless/intel/iwlegacy/common.h       |  3 -
 drivers/net/wireless/intel/iwlwifi/dvm/dev.h       |  5 --
 drivers/net/wireless/intel/iwlwifi/dvm/devices.c   |  6 +-
 drivers/nvme/host/hwmon.c                          | 13 ++--
 drivers/platform/x86/asus-wmi.c                    |  7 +-
 drivers/platform/x86/intel_menlow.c                |  9 ++-
 drivers/thermal/armada_thermal.c                   |  2 -
 .../intel/int340x_thermal/int340x_thermal_zone.c   |  7 +-
 drivers/thermal/intel/intel_pch_thermal.c          |  3 +-
 include/linux/thermal.h                            | 11 ---
 include/linux/units.h                              | 84 ++++++++++++++++++++++
 16 files changed, 137 insertions(+), 68 deletions(-)
 create mode 100644 include/linux/units.h

Cc: Sujith Thomas <sujith.thomas@intel.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Andy Shevchenko <andy@infradead.org>
Cc: Zhang Rui <rui.zhang@intel.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Amit Kucheria <amit.kucheria@verdurent.com>
Cc: Jean Delvare <jdelvare@suse.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Keith Busch <kbusch@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagi@grimberg.me>
Cc: Kalle Valo <kvalo@codeaurora.org>
Cc: Stanislaw Gruszka <sgruszka@redhat.com>
Cc: Johannes Berg <johannes.berg@intel.com>
Cc: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
Cc: Luca Coelho <luciano.coelho@intel.com>
Cc: Intel Linux Wireless <linuxwifi@intel.com>
Cc: Jonathan Cameron <jic23@kernel.org>
Cc: Hartmut Knaack <knaack.h@gmx.de>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
-- 
2.7.4


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v4 01/12] add helpers for kelvin to/from Celsius conversion
  2019-12-15  5:16 [PATCH v4 00/12] add header file for kelvin to/from Celsius conversion helpers Akinobu Mita
@ 2019-12-15  5:16 ` Akinobu Mita
  2019-12-15  5:16 ` [PATCH v4 02/12] ACPI: thermal: switch to use <linux/units.h> helpers Akinobu Mita
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Akinobu Mita @ 2019-12-15  5:16 UTC (permalink / raw)
  To: linux-nvme, linux-hwmon, linux-pm, linux-wireless, linux-iio,
	linux-kernel, akpm
  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

There are several helper macros to convert kelvin to/from Celsius in
<linux/thermal.h> for thermal drivers.  These are useful for any other
drivers or subsystems, but it's odd to include <linux/thermal.h> just for
the helpers.

This adds a new <linux/units.h> that provides the equivalent inline
functions for any drivers or subsystems.  It is intended to replace the
helpers in <linux/thermal.h>.

Cc: Sujith Thomas <sujith.thomas@intel.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Andy Shevchenko <andy@infradead.org>
Cc: Zhang Rui <rui.zhang@intel.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Amit Kucheria <amit.kucheria@verdurent.com>
Cc: Jean Delvare <jdelvare@suse.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Keith Busch <kbusch@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagi@grimberg.me>
Cc: Kalle Valo <kvalo@codeaurora.org>
Cc: Stanislaw Gruszka <sgruszka@redhat.com>
Cc: Johannes Berg <johannes.berg@intel.com>
Cc: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
Cc: Luca Coelho <luciano.coelho@intel.com>
Cc: Intel Linux Wireless <linuxwifi@intel.com>
Cc: Jonathan Cameron <jic23@kernel.org>
Cc: Hartmut Knaack <knaack.h@gmx.de>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
* v4
- add Reviewed-by tag

 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 <linux/kernel.h>
+
+#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


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v4 02/12] ACPI: thermal: switch to use <linux/units.h> helpers
  2019-12-15  5:16 [PATCH v4 00/12] add header file for kelvin to/from Celsius conversion helpers Akinobu Mita
  2019-12-15  5:16 ` [PATCH v4 01/12] add helpers for kelvin to/from Celsius conversion Akinobu Mita
@ 2019-12-15  5:16 ` Akinobu Mita
  2019-12-15  5:16 ` [PATCH v4 03/12] platform/x86: asus-wmi: " Akinobu Mita
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Akinobu Mita @ 2019-12-15  5:16 UTC (permalink / raw)
  To: linux-nvme, linux-hwmon, linux-pm, linux-wireless, linux-iio,
	linux-kernel, akpm
  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

This switches the ACPI thermal zone driver to use celsius_to_deci_kelvin(),
deci_kelvin_to_celsius(), and deci_kelvin_to_millicelsius_with_offset() in
<linux/units.h> instead of helpers in <linux/thermal.h>.

This is preparation for centralizing the kelvin to/from Celsius conversion
helpers in <linux/units.h>.

Cc: Sujith Thomas <sujith.thomas@intel.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Andy Shevchenko <andy@infradead.org>
Cc: Zhang Rui <rui.zhang@intel.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Amit Kucheria <amit.kucheria@verdurent.com>
Cc: Jean Delvare <jdelvare@suse.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Keith Busch <kbusch@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
* v4
- change include order
- keep the line over 80 characters because this change doesn't make it longer

 drivers/acpi/thermal.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index d831a61..19067a5 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -27,6 +27,7 @@
 #include <linux/acpi.h>
 #include <linux/workqueue.h>
 #include <linux/uaccess.h>
+#include <linux/units.h>
 
 #define PREFIX "ACPI: "
 
@@ -172,7 +173,7 @@ struct acpi_thermal {
 	struct acpi_handle_list devices;
 	struct thermal_zone_device *thermal_zone;
 	int tz_enabled;
-	int kelvin_offset;
+	int kelvin_offset;	/* in millidegrees */
 	struct work_struct thermal_check_work;
 };
 
@@ -297,7 +298,8 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
 			if (crt == -1) {
 				tz->trips.critical.flags.valid = 0;
 			} else if (crt > 0) {
-				unsigned long crt_k = CELSIUS_TO_DECI_KELVIN(crt);
+				unsigned long crt_k = celsius_to_deci_kelvin(crt);
+
 				/*
 				 * Allow override critical threshold
 				 */
@@ -333,7 +335,7 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
 		if (psv == -1) {
 			status = AE_SUPPORT;
 		} else if (psv > 0) {
-			tmp = CELSIUS_TO_DECI_KELVIN(psv);
+			tmp = celsius_to_deci_kelvin(psv);
 			status = AE_OK;
 		} else {
 			status = acpi_evaluate_integer(tz->device->handle,
@@ -413,7 +415,7 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
 					break;
 				if (i == 1)
 					tz->trips.active[0].temperature =
-						CELSIUS_TO_DECI_KELVIN(act);
+						celsius_to_deci_kelvin(act);
 				else
 					/*
 					 * Don't allow override higher than
@@ -421,9 +423,9 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
 					 */
 					tz->trips.active[i - 1].temperature =
 						(tz->trips.active[i - 2].temperature <
-						CELSIUS_TO_DECI_KELVIN(act) ?
+						celsius_to_deci_kelvin(act) ?
 						tz->trips.active[i - 2].temperature :
-						CELSIUS_TO_DECI_KELVIN(act));
+						celsius_to_deci_kelvin(act));
 				break;
 			} else {
 				tz->trips.active[i].temperature = tmp;
@@ -519,7 +521,7 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp)
 	if (result)
 		return result;
 
-	*temp = DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET(tz->temperature,
+	*temp = deci_kelvin_to_millicelsius_with_offset(tz->temperature,
 							tz->kelvin_offset);
 	return 0;
 }
@@ -624,7 +626,7 @@ static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
 
 	if (tz->trips.critical.flags.valid) {
 		if (!trip) {
-			*temp = DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET(
+			*temp = deci_kelvin_to_millicelsius_with_offset(
 				tz->trips.critical.temperature,
 				tz->kelvin_offset);
 			return 0;
@@ -634,7 +636,7 @@ static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
 
 	if (tz->trips.hot.flags.valid) {
 		if (!trip) {
-			*temp = DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET(
+			*temp = deci_kelvin_to_millicelsius_with_offset(
 				tz->trips.hot.temperature,
 				tz->kelvin_offset);
 			return 0;
@@ -644,7 +646,7 @@ static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
 
 	if (tz->trips.passive.flags.valid) {
 		if (!trip) {
-			*temp = DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET(
+			*temp = deci_kelvin_to_millicelsius_with_offset(
 				tz->trips.passive.temperature,
 				tz->kelvin_offset);
 			return 0;
@@ -655,7 +657,7 @@ static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
 	for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
 		tz->trips.active[i].flags.valid; i++) {
 		if (!trip) {
-			*temp = DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET(
+			*temp = deci_kelvin_to_millicelsius_with_offset(
 				tz->trips.active[i].temperature,
 				tz->kelvin_offset);
 			return 0;
@@ -672,7 +674,7 @@ static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
 	struct acpi_thermal *tz = thermal->devdata;
 
 	if (tz->trips.critical.flags.valid) {
-		*temperature = DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET(
+		*temperature = deci_kelvin_to_millicelsius_with_offset(
 				tz->trips.critical.temperature,
 				tz->kelvin_offset);
 		return 0;
@@ -692,7 +694,7 @@ static int thermal_get_trend(struct thermal_zone_device *thermal,
 
 	if (type == THERMAL_TRIP_ACTIVE) {
 		int trip_temp;
-		int temp = DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET(
+		int temp = deci_kelvin_to_millicelsius_with_offset(
 					tz->temperature, tz->kelvin_offset);
 		if (thermal_get_trip_temp(thermal, trip, &trip_temp))
 			return -EINVAL;
@@ -1043,9 +1045,9 @@ static void acpi_thermal_guess_offset(struct acpi_thermal *tz)
 {
 	if (tz->trips.critical.flags.valid &&
 	    (tz->trips.critical.temperature % 5) == 1)
-		tz->kelvin_offset = 2731;
+		tz->kelvin_offset = 273100;
 	else
-		tz->kelvin_offset = 2732;
+		tz->kelvin_offset = 273200;
 }
 
 static void acpi_thermal_check_fn(struct work_struct *work)
@@ -1087,7 +1089,7 @@ static int acpi_thermal_add(struct acpi_device *device)
 	INIT_WORK(&tz->thermal_check_work, acpi_thermal_check_fn);
 
 	pr_info(PREFIX "%s [%s] (%ld C)\n", acpi_device_name(device),
-		acpi_device_bid(device), DECI_KELVIN_TO_CELSIUS(tz->temperature));
+		acpi_device_bid(device), deci_kelvin_to_celsius(tz->temperature));
 	goto end;
 
 free_memory:
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v4 03/12] platform/x86: asus-wmi: switch to use <linux/units.h> helpers
  2019-12-15  5:16 [PATCH v4 00/12] add header file for kelvin to/from Celsius conversion helpers Akinobu Mita
  2019-12-15  5:16 ` [PATCH v4 01/12] add helpers for kelvin to/from Celsius conversion Akinobu Mita
  2019-12-15  5:16 ` [PATCH v4 02/12] ACPI: thermal: switch to use <linux/units.h> helpers Akinobu Mita
@ 2019-12-15  5:16 ` Akinobu Mita
  2019-12-15  5:16 ` [PATCH v4 04/12] platform/x86: intel_menlow: " Akinobu Mita
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Akinobu Mita @ 2019-12-15  5:16 UTC (permalink / raw)
  To: linux-nvme, linux-hwmon, linux-pm, linux-wireless, linux-iio,
	linux-kernel, akpm
  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

The asus-wmi driver doesn't implement the thermal device functionality
directly, so including <linux/thermal.h> just for DECI_KELVIN_TO_CELSIUS()
is a bit odd.

This switches the asus-wmi driver to use deci_kelvin_to_millicelsius() in
<linux/units.h>.

The format string is changed from %d to %ld due to function returned type.

Cc: Sujith Thomas <sujith.thomas@intel.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Andy Shevchenko <andy@infradead.org>
Cc: Zhang Rui <rui.zhang@intel.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Amit Kucheria <amit.kucheria@verdurent.com>
Cc: Jean Delvare <jdelvare@suse.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Keith Busch <kbusch@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagi@grimberg.me>
Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
* v4
- change include order

 drivers/platform/x86/asus-wmi.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
index 821b08e..b254f9f 100644
--- a/drivers/platform/x86/asus-wmi.c
+++ b/drivers/platform/x86/asus-wmi.c
@@ -33,9 +33,9 @@
 #include <linux/seq_file.h>
 #include <linux/platform_data/x86/asus-wmi.h>
 #include <linux/platform_device.h>
-#include <linux/thermal.h>
 #include <linux/acpi.h>
 #include <linux/dmi.h>
+#include <linux/units.h>
 
 #include <acpi/battery.h>
 #include <acpi/video.h>
@@ -1512,9 +1512,8 @@ static ssize_t asus_hwmon_temp1(struct device *dev,
 	if (err < 0)
 		return err;
 
-	value = DECI_KELVIN_TO_CELSIUS((value & 0xFFFF)) * 1000;
-
-	return sprintf(buf, "%d\n", value);
+	return sprintf(buf, "%ld\n",
+		       deci_kelvin_to_millicelsius(value & 0xFFFF));
 }
 
 /* Fan1 */
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v4 04/12] platform/x86: intel_menlow: switch to use <linux/units.h> helpers
  2019-12-15  5:16 [PATCH v4 00/12] add header file for kelvin to/from Celsius conversion helpers Akinobu Mita
                   ` (2 preceding siblings ...)
  2019-12-15  5:16 ` [PATCH v4 03/12] platform/x86: asus-wmi: " Akinobu Mita
@ 2019-12-15  5:16 ` Akinobu Mita
  2019-12-15  5:16 ` [PATCH v4 05/12] thermal: int340x: " Akinobu Mita
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Akinobu Mita @ 2019-12-15  5:16 UTC (permalink / raw)
  To: linux-nvme, linux-hwmon, linux-pm, linux-wireless, linux-iio,
	linux-kernel, akpm
  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

This switches the intel_menlow driver to use deci_kelvin_to_celsius() and
celsius_to_deci_kelvin() in <linux/units.h> instead of helpers in
<linux/thermal.h>.

This is preparation for centralizing the kelvin to/from Celsius conversion
helpers in <linux/units.h>.

This also removes a trailing space, while we're at it.

Cc: Sujith Thomas <sujith.thomas@intel.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Andy Shevchenko <andy@infradead.org>
Cc: Zhang Rui <rui.zhang@intel.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Amit Kucheria <amit.kucheria@verdurent.com>
Cc: Jean Delvare <jdelvare@suse.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Keith Busch <kbusch@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
* No changes from v3

 drivers/platform/x86/intel_menlow.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/platform/x86/intel_menlow.c b/drivers/platform/x86/intel_menlow.c
index b102f6d..101d7e7 100644
--- a/drivers/platform/x86/intel_menlow.c
+++ b/drivers/platform/x86/intel_menlow.c
@@ -22,6 +22,7 @@
 #include <linux/slab.h>
 #include <linux/thermal.h>
 #include <linux/types.h>
+#include <linux/units.h>
 
 MODULE_AUTHOR("Thomas Sujith");
 MODULE_AUTHOR("Zhang Rui");
@@ -302,8 +303,10 @@ static ssize_t aux_show(struct device *dev, struct device_attribute *dev_attr,
 	int result;
 
 	result = sensor_get_auxtrip(attr->handle, idx, &value);
+	if (result)
+		return result;
 
-	return result ? result : sprintf(buf, "%lu", DECI_KELVIN_TO_CELSIUS(value));
+	return sprintf(buf, "%lu", deci_kelvin_to_celsius(value));
 }
 
 static ssize_t aux0_show(struct device *dev,
@@ -332,8 +335,8 @@ static ssize_t aux_store(struct device *dev, struct device_attribute *dev_attr,
 	if (value < 0)
 		return -EINVAL;
 
-	result = sensor_set_auxtrip(attr->handle, idx, 
-				    CELSIUS_TO_DECI_KELVIN(value));
+	result = sensor_set_auxtrip(attr->handle, idx,
+				    celsius_to_deci_kelvin(value));
 	return result ? result : count;
 }
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v4 05/12] thermal: int340x: switch to use <linux/units.h> helpers
  2019-12-15  5:16 [PATCH v4 00/12] add header file for kelvin to/from Celsius conversion helpers Akinobu Mita
                   ` (3 preceding siblings ...)
  2019-12-15  5:16 ` [PATCH v4 04/12] platform/x86: intel_menlow: " Akinobu Mita
@ 2019-12-15  5:16 ` Akinobu Mita
  2019-12-15  5:16 ` [PATCH v4 06/12] thermal: intel_pch: " Akinobu Mita
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Akinobu Mita @ 2019-12-15  5:16 UTC (permalink / raw)
  To: linux-nvme, linux-hwmon, linux-pm, linux-wireless, linux-iio,
	linux-kernel, akpm
  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

This switches the int340x thermal zone driver to use
deci_kelvin_to_millicelsius() and millicelsius_to_deci_kelvin() in
<linux/units.h> instead of helpers in <linux/thermal.h>.

This is preparation for centralizing the kelvin to/from Celsius conversion
helpers in <linux/units.h>.

Cc: Sujith Thomas <sujith.thomas@intel.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Andy Shevchenko <andy@infradead.org>
Cc: Zhang Rui <rui.zhang@intel.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Amit Kucheria <amit.kucheria@verdurent.com>
Cc: Jean Delvare <jdelvare@suse.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Keith Busch <kbusch@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
* v4
- add Reviewed-by tag

 drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c
index 75484d6..4322132 100644
--- a/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c
+++ b/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c
@@ -8,6 +8,7 @@
 #include <linux/init.h>
 #include <linux/acpi.h>
 #include <linux/thermal.h>
+#include <linux/units.h>
 #include "int340x_thermal_zone.h"
 
 static int int340x_thermal_get_zone_temp(struct thermal_zone_device *zone,
@@ -34,7 +35,7 @@ static int int340x_thermal_get_zone_temp(struct thermal_zone_device *zone,
 		*temp = (unsigned long)conv_temp * 10;
 	} else
 		/* _TMP returns the temperature in tenths of degrees Kelvin */
-		*temp = DECI_KELVIN_TO_MILLICELSIUS(tmp);
+		*temp = deci_kelvin_to_millicelsius(tmp);
 
 	return 0;
 }
@@ -116,7 +117,7 @@ static int int340x_thermal_set_trip_temp(struct thermal_zone_device *zone,
 
 	snprintf(name, sizeof(name), "PAT%d", trip);
 	status = acpi_execute_simple_method(d->adev->handle, name,
-			MILLICELSIUS_TO_DECI_KELVIN(temp));
+			millicelsius_to_deci_kelvin(temp));
 	if (ACPI_FAILURE(status))
 		return -EIO;
 
@@ -163,7 +164,7 @@ static int int340x_thermal_get_trip_config(acpi_handle handle, char *name,
 	if (ACPI_FAILURE(status))
 		return -EIO;
 
-	*temp = DECI_KELVIN_TO_MILLICELSIUS(r);
+	*temp = deci_kelvin_to_millicelsius(r);
 
 	return 0;
 }
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v4 06/12] thermal: intel_pch: switch to use <linux/units.h> helpers
  2019-12-15  5:16 [PATCH v4 00/12] add header file for kelvin to/from Celsius conversion helpers Akinobu Mita
                   ` (4 preceding siblings ...)
  2019-12-15  5:16 ` [PATCH v4 05/12] thermal: int340x: " Akinobu Mita
@ 2019-12-15  5:16 ` Akinobu Mita
  2019-12-15  5:16 ` [PATCH v4 07/12] nvme: hwmon: " Akinobu Mita
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Akinobu Mita @ 2019-12-15  5:16 UTC (permalink / raw)
  To: linux-nvme, linux-hwmon, linux-pm, linux-wireless, linux-iio,
	linux-kernel, akpm
  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

This switches the intel pch thermal driver to use
deci_kelvin_to_millicelsius() in <linux/units.h> instead of helpers in
<linux/thermal.h>.

This is preparation for centralizing the kelvin to/from Celsius conversion
helpers in <linux/units.h>.

Cc: Sujith Thomas <sujith.thomas@intel.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Andy Shevchenko <andy@infradead.org>
Cc: Zhang Rui <rui.zhang@intel.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Amit Kucheria <amit.kucheria@verdurent.com>
Cc: Jean Delvare <jdelvare@suse.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Keith Busch <kbusch@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
* v4
- add Reviewed-by tag

 drivers/thermal/intel/intel_pch_thermal.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/thermal/intel/intel_pch_thermal.c b/drivers/thermal/intel/intel_pch_thermal.c
index 4f0bb8f..b118611 100644
--- a/drivers/thermal/intel/intel_pch_thermal.c
+++ b/drivers/thermal/intel/intel_pch_thermal.c
@@ -13,6 +13,7 @@
 #include <linux/pci.h>
 #include <linux/acpi.h>
 #include <linux/thermal.h>
+#include <linux/units.h>
 #include <linux/pm.h>
 
 /* Intel PCH thermal Device IDs */
@@ -92,7 +93,7 @@ static void pch_wpt_add_acpi_psv_trip(struct pch_thermal_device *ptd,
 		if (ACPI_SUCCESS(status)) {
 			unsigned long trip_temp;
 
-			trip_temp = DECI_KELVIN_TO_MILLICELSIUS(r);
+			trip_temp = deci_kelvin_to_millicelsius(r);
 			if (trip_temp) {
 				ptd->psv_temp = trip_temp;
 				ptd->psv_trip_id = *nr_trips;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v4 07/12] nvme: hwmon: switch to use <linux/units.h> helpers
  2019-12-15  5:16 [PATCH v4 00/12] add header file for kelvin to/from Celsius conversion helpers Akinobu Mita
                   ` (5 preceding siblings ...)
  2019-12-15  5:16 ` [PATCH v4 06/12] thermal: intel_pch: " Akinobu Mita
@ 2019-12-15  5:16 ` Akinobu Mita
  2019-12-15  5:16 ` [PATCH v4 08/12] thermal: remove kelvin to/from Celsius conversion helpers from <linux/thermal.h> Akinobu Mita
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Akinobu Mita @ 2019-12-15  5:16 UTC (permalink / raw)
  To: linux-nvme, linux-hwmon, linux-pm, linux-wireless, linux-iio,
	linux-kernel, akpm
  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

This switches the nvme driver to use kelvin_to_millicelsius() and
millicelsius_to_kelvin() in <linux/units.h>.

Cc: Sujith Thomas <sujith.thomas@intel.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Andy Shevchenko <andy@infradead.org>
Cc: Zhang Rui <rui.zhang@intel.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Amit Kucheria <amit.kucheria@verdurent.com>
Cc: Jean Delvare <jdelvare@suse.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Keith Busch <kbusch@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Keith Busch <kbusch@kernel.org>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
* v4
- add Reviewed-by tags

 drivers/nvme/host/hwmon.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/nvme/host/hwmon.c b/drivers/nvme/host/hwmon.c
index a5af21f..2e6477e 100644
--- a/drivers/nvme/host/hwmon.c
+++ b/drivers/nvme/host/hwmon.c
@@ -5,14 +5,11 @@
  */
 
 #include <linux/hwmon.h>
+#include <linux/units.h>
 #include <asm/unaligned.h>
 
 #include "nvme.h"
 
-/* These macros should be moved to linux/temperature.h */
-#define MILLICELSIUS_TO_KELVIN(t) DIV_ROUND_CLOSEST((t) + 273150, 1000)
-#define KELVIN_TO_MILLICELSIUS(t) ((t) * 1000L - 273150)
-
 struct nvme_hwmon_data {
 	struct nvme_ctrl *ctrl;
 	struct nvme_smart_log log;
@@ -35,7 +32,7 @@ static int nvme_get_temp_thresh(struct nvme_ctrl *ctrl, int sensor, bool under,
 		return -EIO;
 	if (ret < 0)
 		return ret;
-	*temp = KELVIN_TO_MILLICELSIUS(status & NVME_TEMP_THRESH_MASK);
+	*temp = kelvin_to_millicelsius(status & NVME_TEMP_THRESH_MASK);
 
 	return 0;
 }
@@ -46,7 +43,7 @@ static int nvme_set_temp_thresh(struct nvme_ctrl *ctrl, int sensor, bool under,
 	unsigned int threshold = sensor << NVME_TEMP_THRESH_SELECT_SHIFT;
 	int ret;
 
-	temp = MILLICELSIUS_TO_KELVIN(temp);
+	temp = millicelsius_to_kelvin(temp);
 	threshold |= clamp_val(temp, 0, NVME_TEMP_THRESH_MASK);
 
 	if (under)
@@ -88,7 +85,7 @@ static int nvme_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
 	case hwmon_temp_min:
 		return nvme_get_temp_thresh(data->ctrl, channel, true, val);
 	case hwmon_temp_crit:
-		*val = KELVIN_TO_MILLICELSIUS(data->ctrl->cctemp);
+		*val = kelvin_to_millicelsius(data->ctrl->cctemp);
 		return 0;
 	default:
 		break;
@@ -105,7 +102,7 @@ static int nvme_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
 			temp = get_unaligned_le16(log->temperature);
 		else
 			temp = le16_to_cpu(log->temp_sensor[channel - 1]);
-		*val = KELVIN_TO_MILLICELSIUS(temp);
+		*val = kelvin_to_millicelsius(temp);
 		break;
 	case hwmon_temp_alarm:
 		*val = !!(log->critical_warning & NVME_SMART_CRIT_TEMPERATURE);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v4 08/12] thermal: remove kelvin to/from Celsius conversion helpers from <linux/thermal.h>
  2019-12-15  5:16 [PATCH v4 00/12] add header file for kelvin to/from Celsius conversion helpers Akinobu Mita
                   ` (6 preceding siblings ...)
  2019-12-15  5:16 ` [PATCH v4 07/12] nvme: hwmon: " Akinobu Mita
@ 2019-12-15  5:16 ` Akinobu Mita
  2019-12-15  5:16 ` [PATCH v4 09/12] iwlegacy: use <linux/units.h> helpers Akinobu Mita
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Akinobu Mita @ 2019-12-15  5:16 UTC (permalink / raw)
  To: linux-nvme, linux-hwmon, linux-pm, linux-wireless, linux-iio,
	linux-kernel, akpm
  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

This removes the kelvin to/from Celsius conversion helper macros in
<linux/thermal.h> which were switched to the inline helper functions
in <linux/units.h>.

Cc: Sujith Thomas <sujith.thomas@intel.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Andy Shevchenko <andy@infradead.org>
Cc: Zhang Rui <rui.zhang@intel.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Amit Kucheria <amit.kucheria@verdurent.com>
Cc: Jean Delvare <jdelvare@suse.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Keith Busch <kbusch@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
* v4
- add Reviewed-by tag

 include/linux/thermal.h | 11 -----------
 1 file changed, 11 deletions(-)

diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index d9111ae..126913c6 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -32,17 +32,6 @@
 /* use value, which < 0K, to indicate an invalid/uninitialized temperature */
 #define THERMAL_TEMP_INVALID	-274000
 
-/* Unit conversion macros */
-#define DECI_KELVIN_TO_CELSIUS(t)	({			\
-	long _t = (t);						\
-	((_t-2732 >= 0) ? (_t-2732+5)/10 : (_t-2732-5)/10);	\
-})
-#define CELSIUS_TO_DECI_KELVIN(t)	((t)*10+2732)
-#define DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET(t, off) (((t) - (off)) * 100)
-#define DECI_KELVIN_TO_MILLICELSIUS(t) DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET(t, 2732)
-#define MILLICELSIUS_TO_DECI_KELVIN_WITH_OFFSET(t, off) (((t) / 100) + (off))
-#define MILLICELSIUS_TO_DECI_KELVIN(t) MILLICELSIUS_TO_DECI_KELVIN_WITH_OFFSET(t, 2732)
-
 /* Default Thermal Governor */
 #if defined(CONFIG_THERMAL_DEFAULT_GOV_STEP_WISE)
 #define DEFAULT_THERMAL_GOVERNOR       "step_wise"
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v4 09/12] iwlegacy: use <linux/units.h> helpers
  2019-12-15  5:16 [PATCH v4 00/12] add header file for kelvin to/from Celsius conversion helpers Akinobu Mita
                   ` (7 preceding siblings ...)
  2019-12-15  5:16 ` [PATCH v4 08/12] thermal: remove kelvin to/from Celsius conversion helpers from <linux/thermal.h> Akinobu Mita
@ 2019-12-15  5:16 ` Akinobu Mita
  2019-12-15  5:16 ` [PATCH v4 10/12] iwlwifi: " Akinobu Mita
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Akinobu Mita @ 2019-12-15  5:16 UTC (permalink / raw)
  To: linux-nvme, linux-hwmon, linux-pm, linux-wireless, linux-iio,
	linux-kernel, akpm
  Cc: Akinobu Mita, Kalle Valo, Stanislaw Gruszka

This switches the iwlegacy driver to use celsius_to_kelvin() and
kelvin_to_celsius() in <linux/units.h>.

Cc: Kalle Valo <kvalo@codeaurora.org>
Cc: Stanislaw Gruszka <sgruszka@redhat.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Acked-by: Kalle Valo <kvalo@codeaurora.org>
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
* v4
- add Reviewed-by and Acked-by tags
- remove "wireless: " in the title

 drivers/net/wireless/intel/iwlegacy/4965-mac.c |  3 ++-
 drivers/net/wireless/intel/iwlegacy/4965.c     | 11 ++++++-----
 drivers/net/wireless/intel/iwlegacy/common.h   |  3 ---
 3 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlegacy/4965-mac.c b/drivers/net/wireless/intel/iwlegacy/4965-mac.c
index 3664f56..d6766eb 100644
--- a/drivers/net/wireless/intel/iwlegacy/4965-mac.c
+++ b/drivers/net/wireless/intel/iwlegacy/4965-mac.c
@@ -27,6 +27,7 @@
 #include <linux/firmware.h>
 #include <linux/etherdevice.h>
 #include <linux/if_arp.h>
+#include <linux/units.h>
 
 #include <net/mac80211.h>
 
@@ -6467,7 +6468,7 @@ il4965_set_hw_params(struct il_priv *il)
 	il->hw_params.valid_rx_ant = il->cfg->valid_rx_ant;
 
 	il->hw_params.ct_kill_threshold =
-	   CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD_LEGACY);
+	   celsius_to_kelvin(CT_KILL_THRESHOLD_LEGACY);
 
 	il->hw_params.sens = &il4965_sensitivity;
 	il->hw_params.beacon_time_tsf_bits = IL4965_EXT_BEACON_TIME_POS;
diff --git a/drivers/net/wireless/intel/iwlegacy/4965.c b/drivers/net/wireless/intel/iwlegacy/4965.c
index 32699b6..31b346c 100644
--- a/drivers/net/wireless/intel/iwlegacy/4965.c
+++ b/drivers/net/wireless/intel/iwlegacy/4965.c
@@ -17,6 +17,7 @@
 #include <linux/sched.h>
 #include <linux/skbuff.h>
 #include <linux/netdevice.h>
+#include <linux/units.h>
 #include <net/mac80211.h>
 #include <linux/etherdevice.h>
 #include <asm/unaligned.h>
@@ -1104,7 +1105,7 @@ il4965_fill_txpower_tbl(struct il_priv *il, u8 band, u16 channel, u8 is_ht40,
 	/* get current temperature (Celsius) */
 	current_temp = max(il->temperature, IL_TX_POWER_TEMPERATURE_MIN);
 	current_temp = min(il->temperature, IL_TX_POWER_TEMPERATURE_MAX);
-	current_temp = KELVIN_TO_CELSIUS(current_temp);
+	current_temp = kelvin_to_celsius(current_temp);
 
 	/* select thermal txpower adjustment params, based on channel group
 	 *   (same frequency group used for mimo txatten adjustment) */
@@ -1611,7 +1612,7 @@ il4965_hw_get_temperature(struct il_priv *il)
 	    (temperature * 97) / 100 + TEMPERATURE_CALIB_KELVIN_OFFSET;
 
 	D_TEMP("Calibrated temperature: %dK, %dC\n", temperature,
-	       KELVIN_TO_CELSIUS(temperature));
+	       kelvin_to_celsius(temperature));
 
 	return temperature;
 }
@@ -1671,11 +1672,11 @@ il4965_temperature_calib(struct il_priv *il)
 	if (il->temperature != temp) {
 		if (il->temperature)
 			D_TEMP("Temperature changed " "from %dC to %dC\n",
-			       KELVIN_TO_CELSIUS(il->temperature),
-			       KELVIN_TO_CELSIUS(temp));
+			       kelvin_to_celsius(il->temperature),
+			       kelvin_to_celsius(temp));
 		else
 			D_TEMP("Temperature " "initialized to %dC\n",
-			       KELVIN_TO_CELSIUS(temp));
+			       kelvin_to_celsius(temp));
 	}
 
 	il->temperature = temp;
diff --git a/drivers/net/wireless/intel/iwlegacy/common.h b/drivers/net/wireless/intel/iwlegacy/common.h
index e7fb8e6..bc9cd7e 100644
--- a/drivers/net/wireless/intel/iwlegacy/common.h
+++ b/drivers/net/wireless/intel/iwlegacy/common.h
@@ -779,9 +779,6 @@ struct il_sensitivity_ranges {
 	u16 nrg_th_cca;
 };
 
-#define KELVIN_TO_CELSIUS(x) ((x)-273)
-#define CELSIUS_TO_KELVIN(x) ((x)+273)
-
 /**
  * struct il_hw_params
  * @bcast_id: f/w broadcast station ID
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v4 10/12] iwlwifi: use <linux/units.h> helpers
  2019-12-15  5:16 [PATCH v4 00/12] add header file for kelvin to/from Celsius conversion helpers Akinobu Mita
                   ` (8 preceding siblings ...)
  2019-12-15  5:16 ` [PATCH v4 09/12] iwlegacy: use <linux/units.h> helpers Akinobu Mita
@ 2019-12-15  5:16 ` Akinobu Mita
  2019-12-15  5:16 ` [PATCH v4 11/12] thermal: armada: remove unused TO_MCELSIUS macro Akinobu Mita
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Akinobu Mita @ 2019-12-15  5:16 UTC (permalink / raw)
  To: linux-nvme, linux-hwmon, linux-pm, linux-wireless, linux-iio,
	linux-kernel, akpm
  Cc: Akinobu Mita, Kalle Valo, Johannes Berg, Emmanuel Grumbach,
	Luca Coelho, Intel Linux Wireless

This switches the iwlwifi driver to use celsius_to_kelvin() and
kelvin_to_celsius() in <linux/units.h>.

Cc: Kalle Valo <kvalo@codeaurora.org>
Cc: Johannes Berg <johannes.berg@intel.com>
Cc: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
Cc: Luca Coelho <luciano.coelho@intel.com>
Cc: Intel Linux Wireless <linuxwifi@intel.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Acked-by: Luca Coelho <luciano.coelho@intel.com>
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
* v4
- add Reviewed-by and Acked-by tags
- remove "wireless: " in the title

 drivers/net/wireless/intel/iwlwifi/dvm/dev.h     | 5 -----
 drivers/net/wireless/intel/iwlwifi/dvm/devices.c | 6 ++++--
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/dev.h b/drivers/net/wireless/intel/iwlwifi/dvm/dev.h
index be5ef4c..8d83800 100644
--- a/drivers/net/wireless/intel/iwlwifi/dvm/dev.h
+++ b/drivers/net/wireless/intel/iwlwifi/dvm/dev.h
@@ -237,11 +237,6 @@ struct iwl_sensitivity_ranges {
 	u16 nrg_th_cca;
 };
 
-
-#define KELVIN_TO_CELSIUS(x) ((x)-273)
-#define CELSIUS_TO_KELVIN(x) ((x)+273)
-
-
 /******************************************************************************
  *
  * Functions implemented in core module which are forward declared here
diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/devices.c b/drivers/net/wireless/intel/iwlwifi/dvm/devices.c
index dc3f197..d42bc46 100644
--- a/drivers/net/wireless/intel/iwlwifi/dvm/devices.c
+++ b/drivers/net/wireless/intel/iwlwifi/dvm/devices.c
@@ -10,6 +10,8 @@
  *
  *****************************************************************************/
 
+#include <linux/units.h>
+
 /*
  * DVM device-specific data & functions
  */
@@ -345,7 +347,7 @@ static s32 iwl_temp_calib_to_offset(struct iwl_priv *priv)
 static void iwl5150_set_ct_threshold(struct iwl_priv *priv)
 {
 	const s32 volt2temp_coef = IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF;
-	s32 threshold = (s32)CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD_LEGACY) -
+	s32 threshold = (s32)celsius_to_kelvin(CT_KILL_THRESHOLD_LEGACY) -
 			iwl_temp_calib_to_offset(priv);
 
 	priv->hw_params.ct_kill_threshold = threshold * volt2temp_coef;
@@ -381,7 +383,7 @@ static void iwl5150_temperature(struct iwl_priv *priv)
 	vt = le32_to_cpu(priv->statistics.common.temperature);
 	vt = vt / IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF + offset;
 	/* now vt hold the temperature in Kelvin */
-	priv->temperature = KELVIN_TO_CELSIUS(vt);
+	priv->temperature = kelvin_to_celsius(vt);
 	iwl_tt_handler(priv);
 }
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v4 11/12] thermal: armada: remove unused TO_MCELSIUS macro
  2019-12-15  5:16 [PATCH v4 00/12] add header file for kelvin to/from Celsius conversion helpers Akinobu Mita
                   ` (9 preceding siblings ...)
  2019-12-15  5:16 ` [PATCH v4 10/12] iwlwifi: " Akinobu Mita
@ 2019-12-15  5:16 ` Akinobu Mita
  2019-12-15  5:16 ` [PATCH v4 12/12] iio: adc: qcom-vadc-common: use <linux/units.h> helpers Akinobu Mita
  2019-12-23 13:07 ` [PATCH v4 00/12] add header file for kelvin to/from Celsius conversion helpers Akinobu Mita
  12 siblings, 0 replies; 15+ messages in thread
From: Akinobu Mita @ 2019-12-15  5:16 UTC (permalink / raw)
  To: linux-nvme, linux-hwmon, linux-pm, linux-wireless, linux-iio,
	linux-kernel, akpm
  Cc: Akinobu Mita, Zhang Rui, Daniel Lezcano, Amit Kucheria

This removes unused TO_MCELSIUS() macro.

Cc: Zhang Rui <rui.zhang@intel.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Amit Kucheria <amit.kucheria@verdurent.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
* v4
- add Reviewed-by tag

 drivers/thermal/armada_thermal.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/thermal/armada_thermal.c b/drivers/thermal/armada_thermal.c
index 709a22f..fc6dc10 100644
--- a/drivers/thermal/armada_thermal.c
+++ b/drivers/thermal/armada_thermal.c
@@ -21,8 +21,6 @@
 
 #include "thermal_core.h"
 
-#define TO_MCELSIUS(c)			((c) * 1000)
-
 /* Thermal Manager Control and Status Register */
 #define PMU_TDC0_SW_RST_MASK		(0x1 << 1)
 #define PMU_TM_DISABLE_OFFS		0
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v4 12/12] iio: adc: qcom-vadc-common: use <linux/units.h> helpers
  2019-12-15  5:16 [PATCH v4 00/12] add header file for kelvin to/from Celsius conversion helpers Akinobu Mita
                   ` (10 preceding siblings ...)
  2019-12-15  5:16 ` [PATCH v4 11/12] thermal: armada: remove unused TO_MCELSIUS macro Akinobu Mita
@ 2019-12-15  5:16 ` Akinobu Mita
  2019-12-15 12:29   ` Jonathan Cameron
  2019-12-23 13:07 ` [PATCH v4 00/12] add header file for kelvin to/from Celsius conversion helpers Akinobu Mita
  12 siblings, 1 reply; 15+ messages in thread
From: Akinobu Mita @ 2019-12-15  5:16 UTC (permalink / raw)
  To: linux-nvme, linux-hwmon, linux-pm, linux-wireless, linux-iio,
	linux-kernel, akpm
  Cc: Akinobu Mita, Jonathan Cameron, Hartmut Knaack,
	Lars-Peter Clausen, Peter Meerwald-Stadler

This switches the qcom-vadc-common to use milli_kelvin_to_millicelsius()
in <linux/units.h>.

Cc: Jonathan Cameron <jic23@kernel.org>
Cc: Hartmut Knaack <knaack.h@gmx.de>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
* v4
- add Reviewed-by tag

 drivers/iio/adc/qcom-vadc-common.c | 6 +++---
 drivers/iio/adc/qcom-vadc-common.h | 1 -
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/adc/qcom-vadc-common.c b/drivers/iio/adc/qcom-vadc-common.c
index dcd7fb5..2bb78d1 100644
--- a/drivers/iio/adc/qcom-vadc-common.c
+++ b/drivers/iio/adc/qcom-vadc-common.c
@@ -6,6 +6,7 @@
 #include <linux/log2.h>
 #include <linux/err.h>
 #include <linux/module.h>
+#include <linux/units.h>
 
 #include "qcom-vadc-common.h"
 
@@ -236,8 +237,7 @@ static int qcom_vadc_scale_die_temp(const struct vadc_linear_graph *calib_graph,
 		voltage = 0;
 	}
 
-	voltage -= KELVINMIL_CELSIUSMIL;
-	*result_mdec = voltage;
+	*result_mdec = milli_kelvin_to_millicelsius(voltage);
 
 	return 0;
 }
@@ -325,7 +325,7 @@ static int qcom_vadc_scale_hw_calib_die_temp(
 {
 	*result_mdec = qcom_vadc_scale_code_voltage_factor(adc_code,
 				prescale, data, 2);
-	*result_mdec -= KELVINMIL_CELSIUSMIL;
+	*result_mdec = milli_kelvin_to_millicelsius(*result_mdec);
 
 	return 0;
 }
diff --git a/drivers/iio/adc/qcom-vadc-common.h b/drivers/iio/adc/qcom-vadc-common.h
index bbb1fa0..e074902a 100644
--- a/drivers/iio/adc/qcom-vadc-common.h
+++ b/drivers/iio/adc/qcom-vadc-common.h
@@ -38,7 +38,6 @@
 #define VADC_AVG_SAMPLES_MAX			512
 #define ADC5_AVG_SAMPLES_MAX			16
 
-#define KELVINMIL_CELSIUSMIL			273150
 #define PMIC5_CHG_TEMP_SCALE_FACTOR		377500
 #define PMIC5_SMB_TEMP_CONSTANT			419400
 #define PMIC5_SMB_TEMP_SCALE_FACTOR		356
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH v4 12/12] iio: adc: qcom-vadc-common: use <linux/units.h> helpers
  2019-12-15  5:16 ` [PATCH v4 12/12] iio: adc: qcom-vadc-common: use <linux/units.h> helpers Akinobu Mita
@ 2019-12-15 12:29   ` Jonathan Cameron
  0 siblings, 0 replies; 15+ messages in thread
From: Jonathan Cameron @ 2019-12-15 12:29 UTC (permalink / raw)
  To: Akinobu Mita
  Cc: linux-nvme, linux-hwmon, linux-pm, linux-wireless, linux-iio,
	linux-kernel, akpm, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler

On Sun, 15 Dec 2019 14:16:15 +0900
Akinobu Mita <akinobu.mita@gmail.com> wrote:

> This switches the qcom-vadc-common to use milli_kelvin_to_millicelsius()
> in <linux/units.h>.
> 
> Cc: Jonathan Cameron <jic23@kernel.org>
> Cc: Hartmut Knaack <knaack.h@gmx.de>
> Cc: Lars-Peter Clausen <lars@metafoo.de>
> Cc: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>

Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Thanks,


> ---
> * v4
> - add Reviewed-by tag
> 
>  drivers/iio/adc/qcom-vadc-common.c | 6 +++---
>  drivers/iio/adc/qcom-vadc-common.h | 1 -
>  2 files changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/adc/qcom-vadc-common.c b/drivers/iio/adc/qcom-vadc-common.c
> index dcd7fb5..2bb78d1 100644
> --- a/drivers/iio/adc/qcom-vadc-common.c
> +++ b/drivers/iio/adc/qcom-vadc-common.c
> @@ -6,6 +6,7 @@
>  #include <linux/log2.h>
>  #include <linux/err.h>
>  #include <linux/module.h>
> +#include <linux/units.h>
>  
>  #include "qcom-vadc-common.h"
>  
> @@ -236,8 +237,7 @@ static int qcom_vadc_scale_die_temp(const struct vadc_linear_graph *calib_graph,
>  		voltage = 0;
>  	}
>  
> -	voltage -= KELVINMIL_CELSIUSMIL;
> -	*result_mdec = voltage;
> +	*result_mdec = milli_kelvin_to_millicelsius(voltage);
>  
>  	return 0;
>  }
> @@ -325,7 +325,7 @@ static int qcom_vadc_scale_hw_calib_die_temp(
>  {
>  	*result_mdec = qcom_vadc_scale_code_voltage_factor(adc_code,
>  				prescale, data, 2);
> -	*result_mdec -= KELVINMIL_CELSIUSMIL;
> +	*result_mdec = milli_kelvin_to_millicelsius(*result_mdec);
>  
>  	return 0;
>  }
> diff --git a/drivers/iio/adc/qcom-vadc-common.h b/drivers/iio/adc/qcom-vadc-common.h
> index bbb1fa0..e074902a 100644
> --- a/drivers/iio/adc/qcom-vadc-common.h
> +++ b/drivers/iio/adc/qcom-vadc-common.h
> @@ -38,7 +38,6 @@
>  #define VADC_AVG_SAMPLES_MAX			512
>  #define ADC5_AVG_SAMPLES_MAX			16
>  
> -#define KELVINMIL_CELSIUSMIL			273150
>  #define PMIC5_CHG_TEMP_SCALE_FACTOR		377500
>  #define PMIC5_SMB_TEMP_CONSTANT			419400
>  #define PMIC5_SMB_TEMP_SCALE_FACTOR		356


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v4 00/12] add header file for kelvin to/from Celsius conversion helpers
  2019-12-15  5:16 [PATCH v4 00/12] add header file for kelvin to/from Celsius conversion helpers Akinobu Mita
                   ` (11 preceding siblings ...)
  2019-12-15  5:16 ` [PATCH v4 12/12] iio: adc: qcom-vadc-common: use <linux/units.h> helpers Akinobu Mita
@ 2019-12-23 13:07 ` Akinobu Mita
  12 siblings, 0 replies; 15+ messages in thread
From: Akinobu Mita @ 2019-12-23 13:07 UTC (permalink / raw)
  To: Linux NVMe Mailinglist, linux-hwmon, Linux PM,
	open list:TI WILINK WIRELES...,
	linux-iio, LKML, Andrew Morton
  Cc: 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

Andrew,

Could you take a look at this series, and consider including into -mm tree?

2019年12月15日(日) 14:16 Akinobu Mita <akinobu.mita@gmail.com>:
>
> There are several helper macros to convert kelvin to/from Celsius in
> <linux/thermal.h> for thermal drivers.  These are useful for any other
> drivers or subsystems, but it's odd to include <linux/thermal.h> just for
> the helpers.
>
> This adds a new <linux/units.h> that provides the equivalent inline
> functions for any drivers or subsystems, and switches all the users of
> conversion helpers in <linux/thermal.h> to use <linux/units.h>
> helpers.

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2019-12-23 13:07 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-15  5:16 [PATCH v4 00/12] add header file for kelvin to/from Celsius conversion helpers Akinobu Mita
2019-12-15  5:16 ` [PATCH v4 01/12] add helpers for kelvin to/from Celsius conversion Akinobu Mita
2019-12-15  5:16 ` [PATCH v4 02/12] ACPI: thermal: switch to use <linux/units.h> helpers Akinobu Mita
2019-12-15  5:16 ` [PATCH v4 03/12] platform/x86: asus-wmi: " Akinobu Mita
2019-12-15  5:16 ` [PATCH v4 04/12] platform/x86: intel_menlow: " Akinobu Mita
2019-12-15  5:16 ` [PATCH v4 05/12] thermal: int340x: " Akinobu Mita
2019-12-15  5:16 ` [PATCH v4 06/12] thermal: intel_pch: " Akinobu Mita
2019-12-15  5:16 ` [PATCH v4 07/12] nvme: hwmon: " Akinobu Mita
2019-12-15  5:16 ` [PATCH v4 08/12] thermal: remove kelvin to/from Celsius conversion helpers from <linux/thermal.h> Akinobu Mita
2019-12-15  5:16 ` [PATCH v4 09/12] iwlegacy: use <linux/units.h> helpers Akinobu Mita
2019-12-15  5:16 ` [PATCH v4 10/12] iwlwifi: " Akinobu Mita
2019-12-15  5:16 ` [PATCH v4 11/12] thermal: armada: remove unused TO_MCELSIUS macro Akinobu Mita
2019-12-15  5:16 ` [PATCH v4 12/12] iio: adc: qcom-vadc-common: use <linux/units.h> helpers Akinobu Mita
2019-12-15 12:29   ` Jonathan Cameron
2019-12-23 13:07 ` [PATCH v4 00/12] add header file for kelvin to/from Celsius conversion helpers Akinobu Mita

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).