linux/thermal.h: rename KELVIN_TO_CELSIUS to DECI_KELVIN_TO_CELSIUS

The macros KELVIN_TO_CELSIUS and CELSIUS_TO_KELVIN actually convert
between deciKelvins and Celsius, so rename them to reflect that. While
at it, use a statement expression in DECI_KELVIN_TO_CELSIUS to prevent
expanding the argument multiple times and get rid of a few casts.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Acked-by: Darren Hart <dvhart@linux.intel.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
This commit is contained in:
Rasmus Villemoes 2015-10-01 23:45:31 +02:00 коммит произвёл Zhang Rui
Родитель a71544cd93
Коммит e866a2e395
4 изменённых файлов: 16 добавлений и 14 удалений

Просмотреть файл

@ -315,7 +315,7 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
if (crt == -1) { if (crt == -1) {
tz->trips.critical.flags.valid = 0; tz->trips.critical.flags.valid = 0;
} else if (crt > 0) { } else if (crt > 0) {
unsigned long crt_k = CELSIUS_TO_KELVIN(crt); unsigned long crt_k = CELSIUS_TO_DECI_KELVIN(crt);
/* /*
* Allow override critical threshold * Allow override critical threshold
*/ */
@ -351,7 +351,7 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
if (psv == -1) { if (psv == -1) {
status = AE_SUPPORT; status = AE_SUPPORT;
} else if (psv > 0) { } else if (psv > 0) {
tmp = CELSIUS_TO_KELVIN(psv); tmp = CELSIUS_TO_DECI_KELVIN(psv);
status = AE_OK; status = AE_OK;
} else { } else {
status = acpi_evaluate_integer(tz->device->handle, status = acpi_evaluate_integer(tz->device->handle,
@ -431,7 +431,7 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
break; break;
if (i == 1) if (i == 1)
tz->trips.active[0].temperature = tz->trips.active[0].temperature =
CELSIUS_TO_KELVIN(act); CELSIUS_TO_DECI_KELVIN(act);
else else
/* /*
* Don't allow override higher than * Don't allow override higher than
@ -439,9 +439,9 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
*/ */
tz->trips.active[i - 1].temperature = tz->trips.active[i - 1].temperature =
(tz->trips.active[i - 2].temperature < (tz->trips.active[i - 2].temperature <
CELSIUS_TO_KELVIN(act) ? CELSIUS_TO_DECI_KELVIN(act) ?
tz->trips.active[i - 2].temperature : tz->trips.active[i - 2].temperature :
CELSIUS_TO_KELVIN(act)); CELSIUS_TO_DECI_KELVIN(act));
break; break;
} else { } else {
tz->trips.active[i].temperature = tmp; tz->trips.active[i].temperature = tmp;
@ -1105,7 +1105,7 @@ static int acpi_thermal_add(struct acpi_device *device)
INIT_WORK(&tz->thermal_check_work, acpi_thermal_check_fn); INIT_WORK(&tz->thermal_check_work, acpi_thermal_check_fn);
pr_info(PREFIX "%s [%s] (%ld C)\n", acpi_device_name(device), pr_info(PREFIX "%s [%s] (%ld C)\n", acpi_device_name(device),
acpi_device_bid(device), KELVIN_TO_CELSIUS(tz->temperature)); acpi_device_bid(device), DECI_KELVIN_TO_CELSIUS(tz->temperature));
goto end; goto end;
free_memory: free_memory:

Просмотреть файл

@ -1318,7 +1318,7 @@ static ssize_t asus_hwmon_temp1(struct device *dev,
if (err < 0) if (err < 0)
return err; return err;
value = KELVIN_TO_CELSIUS((value & 0xFFFF)) * 1000; value = DECI_KELVIN_TO_CELSIUS((value & 0xFFFF)) * 1000;
return sprintf(buf, "%d\n", value); return sprintf(buf, "%d\n", value);
} }

Просмотреть файл

@ -315,7 +315,7 @@ static ssize_t aux0_show(struct device *dev,
result = sensor_get_auxtrip(attr->handle, 0, &value); result = sensor_get_auxtrip(attr->handle, 0, &value);
return result ? result : sprintf(buf, "%lu", KELVIN_TO_CELSIUS(value)); return result ? result : sprintf(buf, "%lu", DECI_KELVIN_TO_CELSIUS(value));
} }
static ssize_t aux1_show(struct device *dev, static ssize_t aux1_show(struct device *dev,
@ -327,7 +327,7 @@ static ssize_t aux1_show(struct device *dev,
result = sensor_get_auxtrip(attr->handle, 1, &value); result = sensor_get_auxtrip(attr->handle, 1, &value);
return result ? result : sprintf(buf, "%lu", KELVIN_TO_CELSIUS(value)); return result ? result : sprintf(buf, "%lu", DECI_KELVIN_TO_CELSIUS(value));
} }
static ssize_t aux0_store(struct device *dev, static ssize_t aux0_store(struct device *dev,
@ -345,7 +345,7 @@ static ssize_t aux0_store(struct device *dev,
if (value < 0) if (value < 0)
return -EINVAL; return -EINVAL;
result = sensor_set_auxtrip(attr->handle, 0, CELSIUS_TO_KELVIN(value)); result = sensor_set_auxtrip(attr->handle, 0, CELSIUS_TO_DECI_KELVIN(value));
return result ? result : count; return result ? result : count;
} }
@ -364,7 +364,7 @@ static ssize_t aux1_store(struct device *dev,
if (value < 0) if (value < 0)
return -EINVAL; return -EINVAL;
result = sensor_set_auxtrip(attr->handle, 1, CELSIUS_TO_KELVIN(value)); result = sensor_set_auxtrip(attr->handle, 1, CELSIUS_TO_DECI_KELVIN(value));
return result ? result : count; return result ? result : count;
} }

Просмотреть файл

@ -44,9 +44,11 @@
#define THERMAL_WEIGHT_DEFAULT 0 #define THERMAL_WEIGHT_DEFAULT 0
/* Unit conversion macros */ /* Unit conversion macros */
#define KELVIN_TO_CELSIUS(t) (long)(((long)t-2732 >= 0) ? \ #define DECI_KELVIN_TO_CELSIUS(t) ({ \
((long)t-2732+5)/10 : ((long)t-2732-5)/10) long _t = (t); \
#define CELSIUS_TO_KELVIN(t) ((t)*10+2732) ((_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_WITH_OFFSET(t, off) (((t) - (off)) * 100)
#define DECI_KELVIN_TO_MILLICELSIUS(t) DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET(t, 2732) #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_WITH_OFFSET(t, off) (((t) / 100) + (off))