0001
0002 #ifndef _LINUX_UNITS_H
0003 #define _LINUX_UNITS_H
0004
0005 #include <linux/math.h>
0006
0007
0008 #define PETA 1000000000000000ULL
0009 #define TERA 1000000000000ULL
0010 #define GIGA 1000000000UL
0011 #define MEGA 1000000UL
0012 #define KILO 1000UL
0013 #define HECTO 100UL
0014 #define DECA 10UL
0015 #define DECI 10UL
0016 #define CENTI 100UL
0017 #define MILLI 1000UL
0018 #define MICRO 1000000UL
0019 #define NANO 1000000000UL
0020 #define PICO 1000000000000ULL
0021 #define FEMTO 1000000000000000ULL
0022
0023 #define HZ_PER_KHZ 1000UL
0024 #define KHZ_PER_MHZ 1000UL
0025 #define HZ_PER_MHZ 1000000UL
0026
0027 #define MILLIWATT_PER_WATT 1000UL
0028 #define MICROWATT_PER_MILLIWATT 1000UL
0029 #define MICROWATT_PER_WATT 1000000UL
0030
0031 #define ABSOLUTE_ZERO_MILLICELSIUS -273150
0032
0033 static inline long milli_kelvin_to_millicelsius(long t)
0034 {
0035 return t + ABSOLUTE_ZERO_MILLICELSIUS;
0036 }
0037
0038 static inline long millicelsius_to_milli_kelvin(long t)
0039 {
0040 return t - ABSOLUTE_ZERO_MILLICELSIUS;
0041 }
0042
0043 #define MILLIDEGREE_PER_DEGREE 1000
0044 #define MILLIDEGREE_PER_DECIDEGREE 100
0045
0046 static inline long kelvin_to_millicelsius(long t)
0047 {
0048 return milli_kelvin_to_millicelsius(t * MILLIDEGREE_PER_DEGREE);
0049 }
0050
0051 static inline long millicelsius_to_kelvin(long t)
0052 {
0053 t = millicelsius_to_milli_kelvin(t);
0054
0055 return DIV_ROUND_CLOSEST(t, MILLIDEGREE_PER_DEGREE);
0056 }
0057
0058 static inline long deci_kelvin_to_celsius(long t)
0059 {
0060 t = milli_kelvin_to_millicelsius(t * MILLIDEGREE_PER_DECIDEGREE);
0061
0062 return DIV_ROUND_CLOSEST(t, MILLIDEGREE_PER_DEGREE);
0063 }
0064
0065 static inline long celsius_to_deci_kelvin(long t)
0066 {
0067 t = millicelsius_to_milli_kelvin(t * MILLIDEGREE_PER_DEGREE);
0068
0069 return DIV_ROUND_CLOSEST(t, MILLIDEGREE_PER_DECIDEGREE);
0070 }
0071
0072
0073
0074
0075
0076
0077
0078
0079 static inline long deci_kelvin_to_millicelsius_with_offset(long t, long offset)
0080 {
0081 return t * MILLIDEGREE_PER_DECIDEGREE - offset;
0082 }
0083
0084 static inline long deci_kelvin_to_millicelsius(long t)
0085 {
0086 return milli_kelvin_to_millicelsius(t * MILLIDEGREE_PER_DECIDEGREE);
0087 }
0088
0089 static inline long millicelsius_to_deci_kelvin(long t)
0090 {
0091 t = millicelsius_to_milli_kelvin(t);
0092
0093 return DIV_ROUND_CLOSEST(t, MILLIDEGREE_PER_DECIDEGREE);
0094 }
0095
0096 static inline long kelvin_to_celsius(long t)
0097 {
0098 return t + DIV_ROUND_CLOSEST(ABSOLUTE_ZERO_MILLICELSIUS,
0099 MILLIDEGREE_PER_DEGREE);
0100 }
0101
0102 static inline long celsius_to_kelvin(long t)
0103 {
0104 return t - DIV_ROUND_CLOSEST(ABSOLUTE_ZERO_MILLICELSIUS,
0105 MILLIDEGREE_PER_DEGREE);
0106 }
0107
0108 #endif