14
14
#include <linux/property.h>
15
15
#include <linux/thermal.h>
16
16
#include <linux/units.h>
17
+
17
18
#include "thermal_hwmon.h"
18
19
19
- #define LOONGSON2_MAX_SENSOR_SEL_NUM 3
20
+ #define LOONGSON2_MAX_SENSOR_SEL_NUM 3
20
21
21
- #define LOONGSON2_THSENS_CTRL_HI_REG 0x0
22
- #define LOONGSON2_THSENS_CTRL_LOW_REG 0x8
23
- #define LOONGSON2_THSENS_STATUS_REG 0x10
24
- #define LOONGSON2_THSENS_OUT_REG 0x14
22
+ #define LOONGSON2_THSENS_CTRL_HI_REG 0x0
23
+ #define LOONGSON2_THSENS_CTRL_LOW_REG 0x8
24
+ #define LOONGSON2_THSENS_STATUS_REG 0x10
25
+ #define LOONGSON2_THSENS_OUT_REG 0x14
25
26
26
- #define LOONGSON2_THSENS_INT_LO BIT(0)
27
- #define LOONGSON2_THSENS_INT_HIGH BIT(1)
28
- #define LOONGSON2_THSENS_OUT_MASK 0xFF
27
+ #define LOONGSON2_THSENS_INT_LO BIT(0)
28
+ #define LOONGSON2_THSENS_INT_HIGH BIT(1)
29
+ #define LOONGSON2_THSENS_INT_EN (LOONGSON2_THSENS_INT_LO | \
30
+ LOONGSON2_THSENS_INT_HIGH)
31
+ #define LOONGSON2_THSENS_OUT_MASK 0xFF
29
32
30
33
struct loongson2_thermal_chip_data {
31
- unsigned int thermal_sensor_sel ;
34
+ unsigned int thermal_sensor_sel ;
32
35
};
33
36
34
37
struct loongson2_thermal_data {
35
- void __iomem * regs ;
38
+ void __iomem * regs ;
36
39
const struct loongson2_thermal_chip_data * chip_data ;
37
40
};
38
41
39
- static int loongson2_thermal_set (struct loongson2_thermal_data * data ,
40
- int low , int high , bool enable )
42
+ static void loongson2_set_ctrl_regs (struct loongson2_thermal_data * data ,
43
+ int ctrl_data , bool low , bool enable )
41
44
{
42
- u64 reg_ctrl = 0 ;
43
- int reg_off = data -> chip_data -> thermal_sensor_sel * 2 ;
44
-
45
- low = clamp (-40 , low , high );
46
- high = clamp (125 , low , high );
45
+ int reg_ctrl = 0 ;
46
+ int reg_off = data -> chip_data -> thermal_sensor_sel * 2 ;
47
+ int ctrl_reg = low ? LOONGSON2_THSENS_CTRL_LOW_REG : LOONGSON2_THSENS_CTRL_HI_REG ;
47
48
48
- low += HECTO ;
49
- high += HECTO ;
50
-
51
- reg_ctrl = low ;
49
+ reg_ctrl = ctrl_data + HECTO ;
52
50
reg_ctrl |= enable ? 0x100 : 0 ;
53
- writew (reg_ctrl , data -> regs + LOONGSON2_THSENS_CTRL_LOW_REG + reg_off );
51
+ writew (reg_ctrl , data -> regs + ctrl_reg + reg_off );
52
+ }
54
53
55
- reg_ctrl = high ;
56
- reg_ctrl |= enable ? 0x100 : 0 ;
57
- writew (reg_ctrl , data -> regs + LOONGSON2_THSENS_CTRL_HI_REG + reg_off );
54
+ static int loongson2_thermal_set (struct loongson2_thermal_data * data ,
55
+ int low , int high , bool enable )
56
+ {
57
+ /* Set low temperature threshold */
58
+ loongson2_set_ctrl_regs (data , clamp (-40 , low , high ), true, enable );
59
+
60
+ /* Set high temperature threshold */
61
+ loongson2_set_ctrl_regs (data , clamp (125 , low , high ), false, enable );
58
62
59
63
return 0 ;
60
64
}
@@ -75,8 +79,7 @@ static irqreturn_t loongson2_thermal_irq_thread(int irq, void *dev)
75
79
struct thermal_zone_device * tzd = dev ;
76
80
struct loongson2_thermal_data * data = thermal_zone_device_priv (tzd );
77
81
78
- writeb (LOONGSON2_THSENS_INT_LO | LOONGSON2_THSENS_INT_HIGH , data -> regs +
79
- LOONGSON2_THSENS_STATUS_REG );
82
+ writeb (LOONGSON2_THSENS_INT_EN , data -> regs + LOONGSON2_THSENS_STATUS_REG );
80
83
81
84
thermal_zone_device_update (tzd , THERMAL_EVENT_UNSPECIFIED );
82
85
@@ -116,14 +119,13 @@ static int loongson2_thermal_probe(struct platform_device *pdev)
116
119
if (irq < 0 )
117
120
return irq ;
118
121
119
- writeb (LOONGSON2_THSENS_INT_LO | LOONGSON2_THSENS_INT_HIGH , data -> regs +
120
- LOONGSON2_THSENS_STATUS_REG );
122
+ writeb (LOONGSON2_THSENS_INT_EN , data -> regs + LOONGSON2_THSENS_STATUS_REG );
121
123
122
124
loongson2_thermal_set (data , 0 , 0 , false);
123
125
124
126
for (i = 0 ; i <= LOONGSON2_MAX_SENSOR_SEL_NUM ; i ++ ) {
125
127
tzd = devm_thermal_of_zone_register (dev , i , data ,
126
- & loongson2_of_thermal_ops );
128
+ & loongson2_of_thermal_ops );
127
129
128
130
if (!IS_ERR (tzd ))
129
131
break ;
@@ -135,7 +137,7 @@ static int loongson2_thermal_probe(struct platform_device *pdev)
135
137
}
136
138
137
139
ret = devm_request_threaded_irq (dev , irq , NULL , loongson2_thermal_irq_thread ,
138
- IRQF_ONESHOT , "loongson2_thermal" , tzd );
140
+ IRQF_ONESHOT , "loongson2_thermal" , tzd );
139
141
if (ret < 0 )
140
142
return dev_err_probe (dev , ret , "failed to request alarm irq\n" );
141
143
@@ -167,4 +169,5 @@ static struct platform_driver loongson2_thermal_driver = {
167
169
module_platform_driver (loongson2_thermal_driver );
168
170
169
171
MODULE_DESCRIPTION ("Loongson2 thermal driver" );
172
+ MODULE_AUTHOR ("Loongson Technology Corporation Limited" );
170
173
MODULE_LICENSE ("GPL" );
0 commit comments