diff options
author | Daniel Lezcano <daniel.lezcano@linaro.org> | 2017-10-19 13:05:46 -0400 |
---|---|---|
committer | Eduardo Valentin <edubezval@gmail.com> | 2017-10-31 22:32:15 -0400 |
commit | 48880b979cdc9ef5a70af020f42b8ba1e51dbd34 (patch) | |
tree | e1318ec32d7d49f47db5b8612ff088e35c509e13 /drivers/thermal | |
parent | 2cb4de785c40d4a2132cfc13e63828f5a28c3351 (diff) |
thermal/drivers/hisi: Simplify the temperature/step computation
The step and the base temperature are fixed values, we can simplify the
computation by converting the base temperature to milli celsius and use a
pre-computed step value. That saves us a lot of mult + div for nothing at
runtime.
Take also the opportunity to change the function names to be consistent with
the rest of the code.
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Reviewed-by: Leo Yan <leo.yan@linaro.org>
Tested-by: Leo Yan <leo.yan@linaro.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
Diffstat (limited to 'drivers/thermal')
-rw-r--r-- | drivers/thermal/hisi_thermal.c | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index f69aea0b2fe3..583bc1934127 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c | |||
@@ -35,8 +35,9 @@ | |||
35 | #define TEMP0_RST_MSK (0x1C) | 35 | #define TEMP0_RST_MSK (0x1C) |
36 | #define TEMP0_VALUE (0x28) | 36 | #define TEMP0_VALUE (0x28) |
37 | 37 | ||
38 | #define HISI_TEMP_BASE (-60) | 38 | #define HISI_TEMP_BASE (-60000) |
39 | #define HISI_TEMP_RESET (100000) | 39 | #define HISI_TEMP_RESET (100000) |
40 | #define HISI_TEMP_STEP (784) | ||
40 | 41 | ||
41 | #define HISI_MAX_SENSORS 4 | 42 | #define HISI_MAX_SENSORS 4 |
42 | #define HISI_DEFAULT_SENSOR 2 | 43 | #define HISI_DEFAULT_SENSOR 2 |
@@ -61,19 +62,32 @@ struct hisi_thermal_data { | |||
61 | void __iomem *regs; | 62 | void __iomem *regs; |
62 | }; | 63 | }; |
63 | 64 | ||
64 | /* in millicelsius */ | 65 | /* |
65 | static inline int _step_to_temp(int step) | 66 | * The temperature computation on the tsensor is as follow: |
67 | * Unit: millidegree Celsius | ||
68 | * Step: 255/200 (0.7843) | ||
69 | * Temperature base: -60°C | ||
70 | * | ||
71 | * The register is programmed in temperature steps, every step is 784 | ||
72 | * millidegree and begins at -60 000 m°C | ||
73 | * | ||
74 | * The temperature from the steps: | ||
75 | * | ||
76 | * Temp = TempBase + (steps x 784) | ||
77 | * | ||
78 | * and the steps from the temperature: | ||
79 | * | ||
80 | * steps = (Temp - TempBase) / 784 | ||
81 | * | ||
82 | */ | ||
83 | static inline int hisi_thermal_step_to_temp(int step) | ||
66 | { | 84 | { |
67 | /* | 85 | return HISI_TEMP_BASE + (step * HISI_TEMP_STEP); |
68 | * Every step equals (1 * 200) / 255 celsius, and finally | ||
69 | * need convert to millicelsius. | ||
70 | */ | ||
71 | return (HISI_TEMP_BASE * 1000 + (step * 200000 / 255)); | ||
72 | } | 86 | } |
73 | 87 | ||
74 | static inline long _temp_to_step(long temp) | 88 | static inline long hisi_thermal_temp_to_step(long temp) |
75 | { | 89 | { |
76 | return ((temp - HISI_TEMP_BASE * 1000) * 255) / 200000; | 90 | return (temp - HISI_TEMP_BASE) / HISI_TEMP_STEP; |
77 | } | 91 | } |
78 | 92 | ||
79 | static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data, | 93 | static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data, |
@@ -99,7 +113,7 @@ static long hisi_thermal_get_sensor_temp(struct hisi_thermal_data *data, | |||
99 | usleep_range(3000, 5000); | 113 | usleep_range(3000, 5000); |
100 | 114 | ||
101 | val = readl(data->regs + TEMP0_VALUE); | 115 | val = readl(data->regs + TEMP0_VALUE); |
102 | val = _step_to_temp(val); | 116 | val = hisi_thermal_step_to_temp(val); |
103 | 117 | ||
104 | mutex_unlock(&data->thermal_lock); | 118 | mutex_unlock(&data->thermal_lock); |
105 | 119 | ||
@@ -126,10 +140,11 @@ static void hisi_thermal_enable_bind_irq_sensor | |||
126 | writel((sensor->id << 12), data->regs + TEMP0_CFG); | 140 | writel((sensor->id << 12), data->regs + TEMP0_CFG); |
127 | 141 | ||
128 | /* enable for interrupt */ | 142 | /* enable for interrupt */ |
129 | writel(_temp_to_step(sensor->thres_temp) | 0x0FFFFFF00, | 143 | writel(hisi_thermal_temp_to_step(sensor->thres_temp) | 0x0FFFFFF00, |
130 | data->regs + TEMP0_TH); | 144 | data->regs + TEMP0_TH); |
131 | 145 | ||
132 | writel(_temp_to_step(HISI_TEMP_RESET), data->regs + TEMP0_RST_TH); | 146 | writel(hisi_thermal_temp_to_step(HISI_TEMP_RESET), |
147 | data->regs + TEMP0_RST_TH); | ||
133 | 148 | ||
134 | /* enable module */ | 149 | /* enable module */ |
135 | writel(0x1, data->regs + TEMP0_RST_MSK); | 150 | writel(0x1, data->regs + TEMP0_RST_MSK); |