2 * ST Thermal Sensor Driver for syscfg based sensors.
3 * Author: Ajit Pal Singh <ajitpal.singh@st.com>
5 * Copyright (C) 2003-2014 STMicroelectronics (R&D) Limited
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
14 #include <linux/module.h>
15 #include <linux/mfd/syscon.h>
17 #include "st_thermal.h"
20 #define STIH415_SYSCFG_FRONT(num) ((num - 100) * 4)
21 #define STIH415_SAS_THSENS_CONF STIH415_SYSCFG_FRONT(178)
22 #define STIH415_SAS_THSENS_STATUS STIH415_SYSCFG_FRONT(198)
23 #define STIH415_SYSCFG_MPE(num) ((num - 600) * 4)
24 #define STIH415_MPE_THSENS_CONF STIH415_SYSCFG_MPE(607)
25 #define STIH415_MPE_THSENS_STATUS STIH415_SYSCFG_MPE(667)
28 #define STIH416_SYSCFG_FRONT(num) ((num - 1000) * 4)
29 #define STIH416_SAS_THSENS_CONF STIH416_SYSCFG_FRONT(1552)
30 #define STIH416_SAS_THSENS_STATUS1 STIH416_SYSCFG_FRONT(1554)
31 #define STIH416_SAS_THSENS_STATUS2 STIH416_SYSCFG_FRONT(1594)
34 #define STID127_SYSCFG_CPU(num) ((num - 700) * 4)
35 #define STID127_THSENS_CONF STID127_SYSCFG_CPU(743)
36 #define STID127_THSENS_STATUS STID127_SYSCFG_CPU(767)
38 static const struct reg_field st_415sas_regfields
[MAX_REGFIELDS
] = {
39 [TEMP_PWR
] = REG_FIELD(STIH415_SAS_THSENS_CONF
, 9, 9),
40 [DCORRECT
] = REG_FIELD(STIH415_SAS_THSENS_CONF
, 4, 8),
41 [OVERFLOW
] = REG_FIELD(STIH415_SAS_THSENS_STATUS
, 8, 8),
42 [DATA
] = REG_FIELD(STIH415_SAS_THSENS_STATUS
, 10, 16),
45 static const struct reg_field st_415mpe_regfields
[MAX_REGFIELDS
] = {
46 [TEMP_PWR
] = REG_FIELD(STIH415_MPE_THSENS_CONF
, 8, 8),
47 [DCORRECT
] = REG_FIELD(STIH415_MPE_THSENS_CONF
, 3, 7),
48 [OVERFLOW
] = REG_FIELD(STIH415_MPE_THSENS_STATUS
, 9, 9),
49 [DATA
] = REG_FIELD(STIH415_MPE_THSENS_STATUS
, 11, 18),
52 static const struct reg_field st_416sas_regfields
[MAX_REGFIELDS
] = {
53 [TEMP_PWR
] = REG_FIELD(STIH416_SAS_THSENS_CONF
, 9, 9),
54 [DCORRECT
] = REG_FIELD(STIH416_SAS_THSENS_CONF
, 4, 8),
55 [OVERFLOW
] = REG_FIELD(STIH416_SAS_THSENS_STATUS1
, 8, 8),
56 [DATA
] = REG_FIELD(STIH416_SAS_THSENS_STATUS2
, 10, 16),
59 static const struct reg_field st_127_regfields
[MAX_REGFIELDS
] = {
60 [TEMP_PWR
] = REG_FIELD(STID127_THSENS_CONF
, 7, 7),
61 [DCORRECT
] = REG_FIELD(STID127_THSENS_CONF
, 2, 6),
62 [OVERFLOW
] = REG_FIELD(STID127_THSENS_STATUS
, 9, 9),
63 [DATA
] = REG_FIELD(STID127_THSENS_STATUS
, 11, 18),
66 /* Private OPs for System Configuration Register based thermal sensors */
67 static int st_syscfg_power_ctrl(struct st_thermal_sensor
*sensor
,
68 enum st_thermal_power_state power_state
)
70 return regmap_field_write(sensor
->pwr
, power_state
);
73 static int st_syscfg_alloc_regfields(struct st_thermal_sensor
*sensor
)
75 struct device
*dev
= sensor
->dev
;
77 sensor
->pwr
= devm_regmap_field_alloc(dev
, sensor
->regmap
,
78 sensor
->cdata
->reg_fields
[TEMP_PWR
]);
80 if (IS_ERR(sensor
->pwr
)) {
81 dev_err(dev
, "failed to alloc syscfg regfields\n");
82 return PTR_ERR(sensor
->pwr
);
88 static int st_syscfg_regmap_init(struct st_thermal_sensor
*sensor
)
91 syscon_regmap_lookup_by_compatible(sensor
->cdata
->sys_compat
);
92 if (IS_ERR(sensor
->regmap
)) {
93 dev_err(sensor
->dev
, "failed to find syscfg regmap\n");
94 return PTR_ERR(sensor
->regmap
);
100 static const struct st_thermal_sensor_ops st_syscfg_sensor_ops
= {
101 .power_ctrl
= st_syscfg_power_ctrl
,
102 .alloc_regfields
= st_syscfg_alloc_regfields
,
103 .regmap_init
= st_syscfg_regmap_init
,
106 /* Compatible device data for stih415 sas thermal sensor */
107 static const struct st_thermal_compat_data st_415sas_cdata
= {
108 .sys_compat
= "st,stih415-front-syscfg",
109 .reg_fields
= st_415sas_regfields
,
110 .ops
= &st_syscfg_sensor_ops
,
111 .calibration_val
= 16,
112 .temp_adjust_val
= 20,
116 /* Compatible device data for stih415 mpe thermal sensor */
117 static const struct st_thermal_compat_data st_415mpe_cdata
= {
118 .sys_compat
= "st,stih415-system-syscfg",
119 .reg_fields
= st_415mpe_regfields
,
120 .ops
= &st_syscfg_sensor_ops
,
121 .calibration_val
= 16,
122 .temp_adjust_val
= -103,
126 /* Compatible device data for stih416 sas thermal sensor */
127 static const struct st_thermal_compat_data st_416sas_cdata
= {
128 .sys_compat
= "st,stih416-front-syscfg",
129 .reg_fields
= st_416sas_regfields
,
130 .ops
= &st_syscfg_sensor_ops
,
131 .calibration_val
= 16,
132 .temp_adjust_val
= 20,
136 /* Compatible device data for stid127 thermal sensor */
137 static const struct st_thermal_compat_data st_127_cdata
= {
138 .sys_compat
= "st,stid127-cpu-syscfg",
139 .reg_fields
= st_127_regfields
,
140 .ops
= &st_syscfg_sensor_ops
,
141 .calibration_val
= 8,
142 .temp_adjust_val
= -103,
146 static const struct of_device_id st_syscfg_thermal_of_match
[] = {
147 { .compatible
= "st,stih415-sas-thermal", .data
= &st_415sas_cdata
},
148 { .compatible
= "st,stih415-mpe-thermal", .data
= &st_415mpe_cdata
},
149 { .compatible
= "st,stih416-sas-thermal", .data
= &st_416sas_cdata
},
150 { .compatible
= "st,stid127-thermal", .data
= &st_127_cdata
},
153 MODULE_DEVICE_TABLE(of
, st_syscfg_thermal_of_match
);
155 static int st_syscfg_probe(struct platform_device
*pdev
)
157 return st_thermal_register(pdev
, st_syscfg_thermal_of_match
);
160 static int st_syscfg_remove(struct platform_device
*pdev
)
162 return st_thermal_unregister(pdev
);
165 static struct platform_driver st_syscfg_thermal_driver
= {
167 .name
= "st_syscfg_thermal",
168 .pm
= &st_thermal_pm_ops
,
169 .of_match_table
= st_syscfg_thermal_of_match
,
171 .probe
= st_syscfg_probe
,
172 .remove
= st_syscfg_remove
,
174 module_platform_driver(st_syscfg_thermal_driver
);
176 MODULE_AUTHOR("STMicroelectronics (R&D) Limited <ajitpal.singh@st.com>");
177 MODULE_DESCRIPTION("STMicroelectronics STi SoC Thermal Sensor Driver");
178 MODULE_LICENSE("GPL v2");