aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/thermal/hisi_thermal.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c
index 373bb6d094a1..65f9e5c80741 100644
--- a/drivers/thermal/hisi_thermal.c
+++ b/drivers/thermal/hisi_thermal.c
@@ -40,7 +40,7 @@
40 40
41#define HISI_TEMP_BASE (-60000) 41#define HISI_TEMP_BASE (-60000)
42#define HISI_TEMP_RESET (100000) 42#define HISI_TEMP_RESET (100000)
43#define HISI_TEMP_STEP (784) 43#define HISI_TEMP_STEP (785)
44#define HISI_TEMP_LAG (3500) 44#define HISI_TEMP_LAG (3500)
45 45
46#define HISI_MAX_SENSORS 4 46#define HISI_MAX_SENSORS 4
@@ -63,19 +63,19 @@ struct hisi_thermal_data {
63/* 63/*
64 * The temperature computation on the tsensor is as follow: 64 * The temperature computation on the tsensor is as follow:
65 * Unit: millidegree Celsius 65 * Unit: millidegree Celsius
66 * Step: 255/200 (0.7843) 66 * Step: 200/255 (0.7843)
67 * Temperature base: -60°C 67 * Temperature base: -60°C
68 * 68 *
69 * The register is programmed in temperature steps, every step is 784 69 * The register is programmed in temperature steps, every step is 785
70 * millidegree and begins at -60 000 m°C 70 * millidegree and begins at -60 000 m°C
71 * 71 *
72 * The temperature from the steps: 72 * The temperature from the steps:
73 * 73 *
74 * Temp = TempBase + (steps x 784) 74 * Temp = TempBase + (steps x 785)
75 * 75 *
76 * and the steps from the temperature: 76 * and the steps from the temperature:
77 * 77 *
78 * steps = (Temp - TempBase) / 784 78 * steps = (Temp - TempBase) / 785
79 * 79 *
80 */ 80 */
81static inline int hisi_thermal_step_to_temp(int step) 81static inline int hisi_thermal_step_to_temp(int step)
@@ -85,13 +85,7 @@ static inline int hisi_thermal_step_to_temp(int step)
85 85
86static inline int hisi_thermal_temp_to_step(int temp) 86static inline int hisi_thermal_temp_to_step(int temp)
87{ 87{
88 return (temp - HISI_TEMP_BASE) / HISI_TEMP_STEP; 88 return DIV_ROUND_UP(temp - HISI_TEMP_BASE, HISI_TEMP_STEP);
89}
90
91static inline int hisi_thermal_round_temp(int temp)
92{
93 return hisi_thermal_step_to_temp(
94 hisi_thermal_temp_to_step(temp));
95} 89}
96 90
97/* 91/*
@@ -127,7 +121,7 @@ static inline int hisi_thermal_round_temp(int temp)
127 */ 121 */
128static inline void hisi_thermal_set_lag(void __iomem *addr, int value) 122static inline void hisi_thermal_set_lag(void __iomem *addr, int value)
129{ 123{
130 writel((value / HISI_TEMP_STEP) & 0x1F, addr + TEMP0_LAG); 124 writel(DIV_ROUND_UP(value, HISI_TEMP_STEP) & 0x1F, addr + TEMP0_LAG);
131} 125}
132 126
133static inline void hisi_thermal_alarm_clear(void __iomem *addr, int value) 127static inline void hisi_thermal_alarm_clear(void __iomem *addr, int value)
@@ -274,7 +268,7 @@ static int hisi_thermal_register_sensor(struct platform_device *pdev,
274 268
275 for (i = 0; i < of_thermal_get_ntrips(sensor->tzd); i++) { 269 for (i = 0; i < of_thermal_get_ntrips(sensor->tzd); i++) {
276 if (trip[i].type == THERMAL_TRIP_PASSIVE) { 270 if (trip[i].type == THERMAL_TRIP_PASSIVE) {
277 sensor->thres_temp = hisi_thermal_round_temp(trip[i].temperature); 271 sensor->thres_temp = trip[i].temperature;
278 break; 272 break;
279 } 273 }
280 } 274 }