diff options
author | Amerigo Wang <amwang@redhat.com> | 2010-03-05 16:17:26 -0500 |
---|---|---|
committer | Jean Delvare <khali@linux-fr.org> | 2010-03-05 16:17:26 -0500 |
commit | a0a5e3488a51c46f383c5faa86b53828e30ce153 (patch) | |
tree | be2df675c0fb15d477591d946ef6200cfecdfe69 /drivers/hwmon | |
parent | dc71afe5ac7e8d049bb991330518e4c898a7d92e (diff) |
hwmon: Remove the deprecated adt7473 driver
adt7473 driver is obsoleted by adt7475 driver. And it is scheduled
to be removed in Feb 2010.
Signed-off-by: WANG Cong <amwang@redhat.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/Kconfig | 14 | ||||
-rw-r--r-- | drivers/hwmon/Makefile | 1 | ||||
-rw-r--r-- | drivers/hwmon/adt7473.c | 1180 |
3 files changed, 0 insertions, 1195 deletions
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index b6d65aa20825..e4595e6147b4 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig | |||
@@ -200,20 +200,6 @@ config SENSORS_ADT7470 | |||
200 | This driver can also be built as a module. If so, the module | 200 | This driver can also be built as a module. If so, the module |
201 | will be called adt7470. | 201 | will be called adt7470. |
202 | 202 | ||
203 | config SENSORS_ADT7473 | ||
204 | tristate "Analog Devices ADT7473 (DEPRECATED)" | ||
205 | depends on I2C && EXPERIMENTAL | ||
206 | select SENSORS_ADT7475 | ||
207 | help | ||
208 | If you say yes here you get support for the Analog Devices | ||
209 | ADT7473 temperature monitoring chips. | ||
210 | |||
211 | This driver is deprecated, you should use the adt7475 driver | ||
212 | instead. | ||
213 | |||
214 | This driver can also be built as a module. If so, the module | ||
215 | will be called adt7473. | ||
216 | |||
217 | config SENSORS_ADT7475 | 203 | config SENSORS_ADT7475 |
218 | tristate "Analog Devices ADT7473, ADT7475, ADT7476 and ADT7490" | 204 | tristate "Analog Devices ADT7473, ADT7475, ADT7476 and ADT7490" |
219 | depends on I2C && EXPERIMENTAL | 205 | depends on I2C && EXPERIMENTAL |
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index 865da80f2b90..4aa1a3d112ad 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile | |||
@@ -32,7 +32,6 @@ obj-$(CONFIG_SENSORS_ADS7828) += ads7828.o | |||
32 | obj-$(CONFIG_SENSORS_ADT7411) += adt7411.o | 32 | obj-$(CONFIG_SENSORS_ADT7411) += adt7411.o |
33 | obj-$(CONFIG_SENSORS_ADT7462) += adt7462.o | 33 | obj-$(CONFIG_SENSORS_ADT7462) += adt7462.o |
34 | obj-$(CONFIG_SENSORS_ADT7470) += adt7470.o | 34 | obj-$(CONFIG_SENSORS_ADT7470) += adt7470.o |
35 | obj-$(CONFIG_SENSORS_ADT7473) += adt7473.o | ||
36 | obj-$(CONFIG_SENSORS_ADT7475) += adt7475.o | 35 | obj-$(CONFIG_SENSORS_ADT7475) += adt7475.o |
37 | obj-$(CONFIG_SENSORS_APPLESMC) += applesmc.o | 36 | obj-$(CONFIG_SENSORS_APPLESMC) += applesmc.o |
38 | obj-$(CONFIG_SENSORS_AMS) += ams/ | 37 | obj-$(CONFIG_SENSORS_AMS) += ams/ |
diff --git a/drivers/hwmon/adt7473.c b/drivers/hwmon/adt7473.c deleted file mode 100644 index 434576f61c84..000000000000 --- a/drivers/hwmon/adt7473.c +++ /dev/null | |||
@@ -1,1180 +0,0 @@ | |||
1 | /* | ||
2 | * A hwmon driver for the Analog Devices ADT7473 | ||
3 | * Copyright (C) 2007 IBM | ||
4 | * | ||
5 | * Author: Darrick J. Wong <djwong@us.ibm.com> | ||
6 | * | ||
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. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | ||
21 | |||
22 | #include <linux/module.h> | ||
23 | #include <linux/jiffies.h> | ||
24 | #include <linux/i2c.h> | ||
25 | #include <linux/hwmon.h> | ||
26 | #include <linux/hwmon-sysfs.h> | ||
27 | #include <linux/err.h> | ||
28 | #include <linux/mutex.h> | ||
29 | #include <linux/delay.h> | ||
30 | #include <linux/log2.h> | ||
31 | |||
32 | /* Addresses to scan */ | ||
33 | static const unsigned short normal_i2c[] = { 0x2C, 0x2D, 0x2E, I2C_CLIENT_END }; | ||
34 | |||
35 | /* ADT7473 registers */ | ||
36 | #define ADT7473_REG_BASE_ADDR 0x20 | ||
37 | |||
38 | #define ADT7473_REG_VOLT_BASE_ADDR 0x21 | ||
39 | #define ADT7473_REG_VOLT_MIN_BASE_ADDR 0x46 | ||
40 | |||
41 | #define ADT7473_REG_TEMP_BASE_ADDR 0x25 | ||
42 | #define ADT7473_REG_TEMP_LIMITS_BASE_ADDR 0x4E | ||
43 | #define ADT7473_REG_TEMP_TMIN_BASE_ADDR 0x67 | ||
44 | #define ADT7473_REG_TEMP_TMAX_BASE_ADDR 0x6A | ||
45 | |||
46 | #define ADT7473_REG_FAN_BASE_ADDR 0x28 | ||
47 | #define ADT7473_REG_FAN_MIN_BASE_ADDR 0x54 | ||
48 | |||
49 | #define ADT7473_REG_PWM_BASE_ADDR 0x30 | ||
50 | #define ADT7473_REG_PWM_MIN_BASE_ADDR 0x64 | ||
51 | #define ADT7473_REG_PWM_MAX_BASE_ADDR 0x38 | ||
52 | #define ADT7473_REG_PWM_BHVR_BASE_ADDR 0x5C | ||
53 | #define ADT7473_PWM_BHVR_MASK 0xE0 | ||
54 | #define ADT7473_PWM_BHVR_SHIFT 5 | ||
55 | |||
56 | #define ADT7473_REG_CFG1 0x40 | ||
57 | #define ADT7473_CFG1_START 0x01 | ||
58 | #define ADT7473_CFG1_READY 0x04 | ||
59 | #define ADT7473_REG_CFG2 0x73 | ||
60 | #define ADT7473_REG_CFG3 0x78 | ||
61 | #define ADT7473_REG_CFG4 0x7D | ||
62 | #define ADT7473_CFG4_MAX_DUTY_AT_OVT 0x08 | ||
63 | #define ADT7473_REG_CFG5 0x7C | ||
64 | #define ADT7473_CFG5_TEMP_TWOS 0x01 | ||
65 | #define ADT7473_CFG5_TEMP_OFFSET 0x02 | ||
66 | |||
67 | #define ADT7473_REG_DEVICE 0x3D | ||
68 | #define ADT7473_VENDOR 0x41 | ||
69 | #define ADT7473_REG_VENDOR 0x3E | ||
70 | #define ADT7473_DEVICE 0x73 | ||
71 | #define ADT7473_REG_REVISION 0x3F | ||
72 | #define ADT7473_REV_68 0x68 | ||
73 | #define ADT7473_REV_69 0x69 | ||
74 | |||
75 | #define ADT7473_REG_ALARM1 0x41 | ||
76 | #define ADT7473_VCCP_ALARM 0x02 | ||
77 | #define ADT7473_VCC_ALARM 0x04 | ||
78 | #define ADT7473_R1T_ALARM 0x10 | ||
79 | #define ADT7473_LT_ALARM 0x20 | ||
80 | #define ADT7473_R2T_ALARM 0x40 | ||
81 | #define ADT7473_OOL 0x80 | ||
82 | #define ADT7473_REG_ALARM2 0x42 | ||
83 | #define ADT7473_OVT_ALARM 0x02 | ||
84 | #define ADT7473_FAN1_ALARM 0x04 | ||
85 | #define ADT7473_FAN2_ALARM 0x08 | ||
86 | #define ADT7473_FAN3_ALARM 0x10 | ||
87 | #define ADT7473_FAN4_ALARM 0x20 | ||
88 | #define ADT7473_R1T_SHORT 0x40 | ||
89 | #define ADT7473_R2T_SHORT 0x80 | ||
90 | |||
91 | #define ALARM2(x) ((x) << 8) | ||
92 | |||
93 | #define ADT7473_VOLT_COUNT 2 | ||
94 | #define ADT7473_REG_VOLT(x) (ADT7473_REG_VOLT_BASE_ADDR + (x)) | ||
95 | #define ADT7473_REG_VOLT_MIN(x) (ADT7473_REG_VOLT_MIN_BASE_ADDR + ((x) * 2)) | ||
96 | #define ADT7473_REG_VOLT_MAX(x) (ADT7473_REG_VOLT_MIN_BASE_ADDR + \ | ||
97 | ((x) * 2) + 1) | ||
98 | |||
99 | #define ADT7473_TEMP_COUNT 3 | ||
100 | #define ADT7473_REG_TEMP(x) (ADT7473_REG_TEMP_BASE_ADDR + (x)) | ||
101 | #define ADT7473_REG_TEMP_MIN(x) (ADT7473_REG_TEMP_LIMITS_BASE_ADDR + ((x) * 2)) | ||
102 | #define ADT7473_REG_TEMP_MAX(x) (ADT7473_REG_TEMP_LIMITS_BASE_ADDR + \ | ||
103 | ((x) * 2) + 1) | ||
104 | #define ADT7473_REG_TEMP_TMIN(x) (ADT7473_REG_TEMP_TMIN_BASE_ADDR + (x)) | ||
105 | #define ADT7473_REG_TEMP_TMAX(x) (ADT7473_REG_TEMP_TMAX_BASE_ADDR + (x)) | ||
106 | |||
107 | #define ADT7473_FAN_COUNT 4 | ||
108 | #define ADT7473_REG_FAN(x) (ADT7473_REG_FAN_BASE_ADDR + ((x) * 2)) | ||
109 | #define ADT7473_REG_FAN_MIN(x) (ADT7473_REG_FAN_MIN_BASE_ADDR + ((x) * 2)) | ||
110 | |||
111 | #define ADT7473_PWM_COUNT 3 | ||
112 | #define ADT7473_REG_PWM(x) (ADT7473_REG_PWM_BASE_ADDR + (x)) | ||
113 | #define ADT7473_REG_PWM_MAX(x) (ADT7473_REG_PWM_MAX_BASE_ADDR + (x)) | ||
114 | #define ADT7473_REG_PWM_MIN(x) (ADT7473_REG_PWM_MIN_BASE_ADDR + (x)) | ||
115 | #define ADT7473_REG_PWM_BHVR(x) (ADT7473_REG_PWM_BHVR_BASE_ADDR + (x)) | ||
116 | |||
117 | /* How often do we reread sensors values? (In jiffies) */ | ||
118 | #define SENSOR_REFRESH_INTERVAL (2 * HZ) | ||
119 | |||
120 | /* How often do we reread sensor limit values? (In jiffies) */ | ||
121 | #define LIMIT_REFRESH_INTERVAL (60 * HZ) | ||
122 | |||
123 | /* datasheet says to divide this number by the fan reading to get fan rpm */ | ||
124 | #define FAN_PERIOD_TO_RPM(x) ((90000 * 60) / (x)) | ||
125 | #define FAN_RPM_TO_PERIOD FAN_PERIOD_TO_RPM | ||
126 | #define FAN_PERIOD_INVALID 65535 | ||
127 | #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) | ||
128 | |||
129 | struct adt7473_data { | ||
130 | struct device *hwmon_dev; | ||
131 | struct attribute_group attrs; | ||
132 | struct mutex lock; | ||
133 | char sensors_valid; | ||
134 | char limits_valid; | ||
135 | unsigned long sensors_last_updated; /* In jiffies */ | ||
136 | unsigned long limits_last_updated; /* In jiffies */ | ||
137 | |||
138 | u8 volt[ADT7473_VOLT_COUNT]; | ||
139 | s8 volt_min[ADT7473_VOLT_COUNT]; | ||
140 | s8 volt_max[ADT7473_VOLT_COUNT]; | ||
141 | |||
142 | s8 temp[ADT7473_TEMP_COUNT]; | ||
143 | s8 temp_min[ADT7473_TEMP_COUNT]; | ||
144 | s8 temp_max[ADT7473_TEMP_COUNT]; | ||
145 | s8 temp_tmin[ADT7473_TEMP_COUNT]; | ||
146 | /* This is called the !THERM limit in the datasheet */ | ||
147 | s8 temp_tmax[ADT7473_TEMP_COUNT]; | ||
148 | |||
149 | u16 fan[ADT7473_FAN_COUNT]; | ||
150 | u16 fan_min[ADT7473_FAN_COUNT]; | ||
151 | |||
152 | u8 pwm[ADT7473_PWM_COUNT]; | ||
153 | u8 pwm_max[ADT7473_PWM_COUNT]; | ||
154 | u8 pwm_min[ADT7473_PWM_COUNT]; | ||
155 | u8 pwm_behavior[ADT7473_PWM_COUNT]; | ||
156 | |||
157 | u8 temp_twos_complement; | ||
158 | u8 temp_offset; | ||
159 | |||
160 | u16 alarm; | ||
161 | u8 max_duty_at_overheat; | ||
162 | }; | ||
163 | |||
164 | static int adt7473_probe(struct i2c_client *client, | ||
165 | const struct i2c_device_id *id); | ||
166 | static int adt7473_detect(struct i2c_client *client, | ||
167 | struct i2c_board_info *info); | ||
168 | static int adt7473_remove(struct i2c_client *client); | ||
169 | |||
170 | static const struct i2c_device_id adt7473_id[] = { | ||
171 | { "adt7473", 0 }, | ||
172 | { } | ||
173 | }; | ||
174 | |||
175 | static struct i2c_driver adt7473_driver = { | ||
176 | .class = I2C_CLASS_HWMON, | ||
177 | .driver = { | ||
178 | .name = "adt7473", | ||
179 | }, | ||
180 | .probe = adt7473_probe, | ||
181 | .remove = adt7473_remove, | ||
182 | .id_table = adt7473_id, | ||
183 | .detect = adt7473_detect, | ||
184 | .address_list = normal_i2c, | ||
185 | }; | ||
186 | |||
187 | /* | ||
188 | * 16-bit registers on the ADT7473 are low-byte first. The data sheet says | ||
189 | * that the low byte must be read before the high byte. | ||
190 | */ | ||
191 | static inline int adt7473_read_word_data(struct i2c_client *client, u8 reg) | ||
192 | { | ||
193 | u16 foo; | ||
194 | foo = i2c_smbus_read_byte_data(client, reg); | ||
195 | foo |= ((u16)i2c_smbus_read_byte_data(client, reg + 1) << 8); | ||
196 | return foo; | ||
197 | } | ||
198 | |||
199 | static inline int adt7473_write_word_data(struct i2c_client *client, u8 reg, | ||
200 | u16 value) | ||
201 | { | ||
202 | return i2c_smbus_write_byte_data(client, reg, value & 0xFF) | ||
203 | && i2c_smbus_write_byte_data(client, reg + 1, value >> 8); | ||
204 | } | ||
205 | |||
206 | static void adt7473_init_client(struct i2c_client *client) | ||
207 | { | ||
208 | int reg = i2c_smbus_read_byte_data(client, ADT7473_REG_CFG1); | ||
209 | |||
210 | if (!(reg & ADT7473_CFG1_READY)) { | ||
211 | dev_err(&client->dev, "Chip not ready.\n"); | ||
212 | } else { | ||
213 | /* start monitoring */ | ||
214 | i2c_smbus_write_byte_data(client, ADT7473_REG_CFG1, | ||
215 | reg | ADT7473_CFG1_START); | ||
216 | } | ||
217 | } | ||
218 | |||
219 | static struct adt7473_data *adt7473_update_device(struct device *dev) | ||
220 | { | ||
221 | struct i2c_client *client = to_i2c_client(dev); | ||
222 | struct adt7473_data *data = i2c_get_clientdata(client); | ||
223 | unsigned long local_jiffies = jiffies; | ||
224 | u8 cfg; | ||
225 | int i; | ||
226 | |||
227 | mutex_lock(&data->lock); | ||
228 | if (time_before(local_jiffies, data->sensors_last_updated + | ||
229 | SENSOR_REFRESH_INTERVAL) | ||
230 | && data->sensors_valid) | ||
231 | goto no_sensor_update; | ||
232 | |||
233 | for (i = 0; i < ADT7473_VOLT_COUNT; i++) | ||
234 | data->volt[i] = i2c_smbus_read_byte_data(client, | ||
235 | ADT7473_REG_VOLT(i)); | ||
236 | |||
237 | /* Determine temperature encoding */ | ||
238 | cfg = i2c_smbus_read_byte_data(client, ADT7473_REG_CFG5); | ||
239 | data->temp_twos_complement = (cfg & ADT7473_CFG5_TEMP_TWOS); | ||
240 | |||
241 | /* | ||
242 | * What does this do? it implies a variable temperature sensor | ||
243 | * offset, but the datasheet doesn't say anything about this bit | ||
244 | * and other parts of the datasheet imply that "offset64" mode | ||
245 | * means that you shift temp values by -64 if the above bit was set. | ||
246 | */ | ||
247 | data->temp_offset = (cfg & ADT7473_CFG5_TEMP_OFFSET); | ||
248 | |||
249 | for (i = 0; i < ADT7473_TEMP_COUNT; i++) | ||
250 | data->temp[i] = i2c_smbus_read_byte_data(client, | ||
251 | ADT7473_REG_TEMP(i)); | ||
252 | |||
253 | for (i = 0; i < ADT7473_FAN_COUNT; i++) | ||
254 | data->fan[i] = adt7473_read_word_data(client, | ||
255 | ADT7473_REG_FAN(i)); | ||
256 | |||
257 | for (i = 0; i < ADT7473_PWM_COUNT; i++) | ||
258 | data->pwm[i] = i2c_smbus_read_byte_data(client, | ||
259 | ADT7473_REG_PWM(i)); | ||
260 | |||
261 | data->alarm = i2c_smbus_read_byte_data(client, ADT7473_REG_ALARM1); | ||
262 | if (data->alarm & ADT7473_OOL) | ||
263 | data->alarm |= ALARM2(i2c_smbus_read_byte_data(client, | ||
264 | ADT7473_REG_ALARM2)); | ||
265 | |||
266 | data->sensors_last_updated = local_jiffies; | ||
267 | data->sensors_valid = 1; | ||
268 | |||
269 | no_sensor_update: | ||
270 | if (time_before(local_jiffies, data->limits_last_updated + | ||
271 | LIMIT_REFRESH_INTERVAL) | ||
272 | && data->limits_valid) | ||
273 | goto out; | ||
274 | |||
275 | for (i = 0; i < ADT7473_VOLT_COUNT; i++) { | ||
276 | data->volt_min[i] = i2c_smbus_read_byte_data(client, | ||
277 | ADT7473_REG_VOLT_MIN(i)); | ||
278 | data->volt_max[i] = i2c_smbus_read_byte_data(client, | ||
279 | ADT7473_REG_VOLT_MAX(i)); | ||
280 | } | ||
281 | |||
282 | for (i = 0; i < ADT7473_TEMP_COUNT; i++) { | ||
283 | data->temp_min[i] = i2c_smbus_read_byte_data(client, | ||
284 | ADT7473_REG_TEMP_MIN(i)); | ||
285 | data->temp_max[i] = i2c_smbus_read_byte_data(client, | ||
286 | ADT7473_REG_TEMP_MAX(i)); | ||
287 | data->temp_tmin[i] = i2c_smbus_read_byte_data(client, | ||
288 | ADT7473_REG_TEMP_TMIN(i)); | ||
289 | data->temp_tmax[i] = i2c_smbus_read_byte_data(client, | ||
290 | ADT7473_REG_TEMP_TMAX(i)); | ||
291 | } | ||
292 | |||
293 | for (i = 0; i < ADT7473_FAN_COUNT; i++) | ||
294 | data->fan_min[i] = adt7473_read_word_data(client, | ||
295 | ADT7473_REG_FAN_MIN(i)); | ||
296 | |||
297 | for (i = 0; i < ADT7473_PWM_COUNT; i++) { | ||
298 | data->pwm_max[i] = i2c_smbus_read_byte_data(client, | ||
299 | ADT7473_REG_PWM_MAX(i)); | ||
300 | data->pwm_min[i] = i2c_smbus_read_byte_data(client, | ||
301 | ADT7473_REG_PWM_MIN(i)); | ||
302 | data->pwm_behavior[i] = i2c_smbus_read_byte_data(client, | ||
303 | ADT7473_REG_PWM_BHVR(i)); | ||
304 | } | ||
305 | |||
306 | i = i2c_smbus_read_byte_data(client, ADT7473_REG_CFG4); | ||
307 | data->max_duty_at_overheat = !!(i & ADT7473_CFG4_MAX_DUTY_AT_OVT); | ||
308 | |||
309 | data->limits_last_updated = local_jiffies; | ||
310 | data->limits_valid = 1; | ||
311 | |||
312 | out: | ||
313 | mutex_unlock(&data->lock); | ||
314 | return data; | ||
315 | } | ||
316 | |||
317 | /* | ||
318 | * Conversions | ||
319 | */ | ||
320 | |||
321 | /* IN are scaled acording to built-in resistors */ | ||
322 | static const int adt7473_scaling[] = { /* .001 Volts */ | ||
323 | 2250, 3300 | ||
324 | }; | ||
325 | #define SCALE(val, from, to) (((val) * (to) + ((from) / 2)) / (from)) | ||
326 | |||
327 | static int decode_volt(int volt_index, u8 raw) | ||
328 | { | ||
329 | return SCALE(raw, 192, adt7473_scaling[volt_index]); | ||
330 | } | ||
331 | |||
332 | static u8 encode_volt(int volt_index, int cooked) | ||
333 | { | ||
334 | int raw = SCALE(cooked, adt7473_scaling[volt_index], 192); | ||
335 | return SENSORS_LIMIT(raw, 0, 255); | ||
336 | } | ||
337 | |||
338 | static ssize_t show_volt_min(struct device *dev, | ||
339 | struct device_attribute *devattr, | ||
340 | char *buf) | ||
341 | { | ||
342 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
343 | struct adt7473_data *data = adt7473_update_device(dev); | ||
344 | return sprintf(buf, "%d\n", | ||
345 | decode_volt(attr->index, data->volt_min[attr->index])); | ||
346 | } | ||
347 | |||
348 | static ssize_t set_volt_min(struct device *dev, | ||
349 | struct device_attribute *devattr, | ||
350 | const char *buf, | ||
351 | size_t count) | ||
352 | { | ||
353 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
354 | struct i2c_client *client = to_i2c_client(dev); | ||
355 | struct adt7473_data *data = i2c_get_clientdata(client); | ||
356 | long volt; | ||
357 | |||
358 | if (strict_strtol(buf, 10, &volt)) | ||
359 | return -EINVAL; | ||
360 | |||
361 | volt = encode_volt(attr->index, volt); | ||
362 | |||
363 | mutex_lock(&data->lock); | ||
364 | data->volt_min[attr->index] = volt; | ||
365 | i2c_smbus_write_byte_data(client, ADT7473_REG_VOLT_MIN(attr->index), | ||
366 | volt); | ||
367 | mutex_unlock(&data->lock); | ||
368 | |||
369 | return count; | ||
370 | } | ||
371 | |||
372 | static ssize_t show_volt_max(struct device *dev, | ||
373 | struct device_attribute *devattr, | ||
374 | char *buf) | ||
375 | { | ||
376 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
377 | struct adt7473_data *data = adt7473_update_device(dev); | ||
378 | return sprintf(buf, "%d\n", | ||
379 | decode_volt(attr->index, data->volt_max[attr->index])); | ||
380 | } | ||
381 | |||
382 | static ssize_t set_volt_max(struct device *dev, | ||
383 | struct device_attribute *devattr, | ||
384 | const char *buf, | ||
385 | size_t count) | ||
386 | { | ||
387 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
388 | struct i2c_client *client = to_i2c_client(dev); | ||
389 | struct adt7473_data *data = i2c_get_clientdata(client); | ||
390 | long volt; | ||
391 | |||
392 | if (strict_strtol(buf, 10, &volt)) | ||
393 | return -EINVAL; | ||
394 | |||
395 | volt = encode_volt(attr->index, volt); | ||
396 | |||
397 | mutex_lock(&data->lock); | ||
398 | data->volt_max[attr->index] = volt; | ||
399 | i2c_smbus_write_byte_data(client, ADT7473_REG_VOLT_MAX(attr->index), | ||
400 | volt); | ||
401 | mutex_unlock(&data->lock); | ||
402 | |||
403 | return count; | ||
404 | } | ||
405 | |||
406 | static ssize_t show_volt(struct device *dev, struct device_attribute *devattr, | ||
407 | char *buf) | ||
408 | { | ||
409 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
410 | struct adt7473_data *data = adt7473_update_device(dev); | ||
411 | |||
412 | return sprintf(buf, "%d\n", | ||
413 | decode_volt(attr->index, data->volt[attr->index])); | ||
414 | } | ||
415 | |||
416 | /* | ||
417 | * This chip can report temperature data either as a two's complement | ||
418 | * number in the range -128 to 127, or as an unsigned number that must | ||
419 | * be offset by 64. | ||
420 | */ | ||
421 | static int decode_temp(u8 twos_complement, u8 raw) | ||
422 | { | ||
423 | return twos_complement ? (s8)raw : raw - 64; | ||
424 | } | ||
425 | |||
426 | static u8 encode_temp(u8 twos_complement, int cooked) | ||
427 | { | ||
428 | u8 ret = twos_complement ? cooked & 0xFF : cooked + 64; | ||
429 | return SENSORS_LIMIT(ret, 0, 255); | ||
430 | } | ||
431 | |||
432 | static ssize_t show_temp_min(struct device *dev, | ||
433 | struct device_attribute *devattr, | ||
434 | char *buf) | ||
435 | { | ||
436 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
437 | struct adt7473_data *data = adt7473_update_device(dev); | ||
438 | return sprintf(buf, "%d\n", 1000 * decode_temp( | ||
439 | data->temp_twos_complement, | ||
440 | data->temp_min[attr->index])); | ||
441 | } | ||
442 | |||
443 | static ssize_t set_temp_min(struct device *dev, | ||
444 | struct device_attribute *devattr, | ||
445 | const char *buf, | ||
446 | size_t count) | ||
447 | { | ||
448 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
449 | struct i2c_client *client = to_i2c_client(dev); | ||
450 | struct adt7473_data *data = i2c_get_clientdata(client); | ||
451 | long temp; | ||
452 | |||
453 | if (strict_strtol(buf, 10, &temp)) | ||
454 | return -EINVAL; | ||
455 | |||
456 | temp = DIV_ROUND_CLOSEST(temp, 1000); | ||
457 | temp = encode_temp(data->temp_twos_complement, temp); | ||
458 | |||
459 | mutex_lock(&data->lock); | ||
460 | data->temp_min[attr->index] = temp; | ||
461 | i2c_smbus_write_byte_data(client, ADT7473_REG_TEMP_MIN(attr->index), | ||
462 | temp); | ||
463 | mutex_unlock(&data->lock); | ||
464 | |||
465 | return count; | ||
466 | } | ||
467 | |||
468 | static ssize_t show_temp_max(struct device *dev, | ||
469 | struct device_attribute *devattr, | ||
470 | char *buf) | ||
471 | { | ||
472 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
473 | struct adt7473_data *data = adt7473_update_device(dev); | ||
474 | return sprintf(buf, "%d\n", 1000 * decode_temp( | ||
475 | data->temp_twos_complement, | ||
476 | data->temp_max[attr->index])); | ||
477 | } | ||
478 | |||
479 | static ssize_t set_temp_max(struct device *dev, | ||
480 | struct device_attribute *devattr, | ||
481 | const char *buf, | ||
482 | size_t count) | ||
483 | { | ||
484 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
485 | struct i2c_client *client = to_i2c_client(dev); | ||
486 | struct adt7473_data *data = i2c_get_clientdata(client); | ||
487 | long temp; | ||
488 | |||
489 | if (strict_strtol(buf, 10, &temp)) | ||
490 | return -EINVAL; | ||
491 | |||
492 | temp = DIV_ROUND_CLOSEST(temp, 1000); | ||
493 | temp = encode_temp(data->temp_twos_complement, temp); | ||
494 | |||
495 | mutex_lock(&data->lock); | ||
496 | data->temp_max[attr->index] = temp; | ||
497 | i2c_smbus_write_byte_data(client, ADT7473_REG_TEMP_MAX(attr->index), | ||
498 | temp); | ||
499 | mutex_unlock(&data->lock); | ||
500 | |||
501 | return count; | ||
502 | } | ||
503 | |||
504 | static ssize_t show_temp(struct device *dev, struct device_attribute *devattr, | ||
505 | char *buf) | ||
506 | { | ||
507 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
508 | struct adt7473_data *data = adt7473_update_device(dev); | ||
509 | return sprintf(buf, "%d\n", 1000 * decode_temp( | ||
510 | data->temp_twos_complement, | ||
511 | data->temp[attr->index])); | ||
512 | } | ||
513 | |||
514 | static ssize_t show_fan_min(struct device *dev, | ||
515 | struct device_attribute *devattr, | ||
516 | char *buf) | ||
517 | { | ||
518 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
519 | struct adt7473_data *data = adt7473_update_device(dev); | ||
520 | |||
521 | if (FAN_DATA_VALID(data->fan_min[attr->index])) | ||
522 | return sprintf(buf, "%d\n", | ||
523 | FAN_PERIOD_TO_RPM(data->fan_min[attr->index])); | ||
524 | else | ||
525 | return sprintf(buf, "0\n"); | ||
526 | } | ||
527 | |||
528 | static ssize_t set_fan_min(struct device *dev, | ||
529 | struct device_attribute *devattr, | ||
530 | const char *buf, size_t count) | ||
531 | { | ||
532 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
533 | struct i2c_client *client = to_i2c_client(dev); | ||
534 | struct adt7473_data *data = i2c_get_clientdata(client); | ||
535 | long temp; | ||
536 | |||
537 | if (strict_strtol(buf, 10, &temp) || !temp) | ||
538 | return -EINVAL; | ||
539 | |||
540 | temp = FAN_RPM_TO_PERIOD(temp); | ||
541 | temp = SENSORS_LIMIT(temp, 1, 65534); | ||
542 | |||
543 | mutex_lock(&data->lock); | ||
544 | data->fan_min[attr->index] = temp; | ||
545 | adt7473_write_word_data(client, ADT7473_REG_FAN_MIN(attr->index), temp); | ||
546 | mutex_unlock(&data->lock); | ||
547 | |||
548 | return count; | ||
549 | } | ||
550 | |||
551 | static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, | ||
552 | char *buf) | ||
553 | { | ||
554 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
555 | struct adt7473_data *data = adt7473_update_device(dev); | ||
556 | |||
557 | if (FAN_DATA_VALID(data->fan[attr->index])) | ||
558 | return sprintf(buf, "%d\n", | ||
559 | FAN_PERIOD_TO_RPM(data->fan[attr->index])); | ||
560 | else | ||
561 | return sprintf(buf, "0\n"); | ||
562 | } | ||
563 | |||
564 | static ssize_t show_max_duty_at_crit(struct device *dev, | ||
565 | struct device_attribute *devattr, | ||
566 | char *buf) | ||
567 | { | ||
568 | struct adt7473_data *data = adt7473_update_device(dev); | ||
569 | return sprintf(buf, "%d\n", data->max_duty_at_overheat); | ||
570 | } | ||
571 | |||
572 | static ssize_t set_max_duty_at_crit(struct device *dev, | ||
573 | struct device_attribute *devattr, | ||
574 | const char *buf, | ||
575 | size_t count) | ||
576 | { | ||
577 | u8 reg; | ||
578 | struct i2c_client *client = to_i2c_client(dev); | ||
579 | struct adt7473_data *data = i2c_get_clientdata(client); | ||
580 | long temp; | ||
581 | |||
582 | if (strict_strtol(buf, 10, &temp)) | ||
583 | return -EINVAL; | ||
584 | |||
585 | mutex_lock(&data->lock); | ||
586 | data->max_duty_at_overheat = !!temp; | ||
587 | reg = i2c_smbus_read_byte_data(client, ADT7473_REG_CFG4); | ||
588 | if (temp) | ||
589 | reg |= ADT7473_CFG4_MAX_DUTY_AT_OVT; | ||
590 | else | ||
591 | reg &= ~ADT7473_CFG4_MAX_DUTY_AT_OVT; | ||
592 | i2c_smbus_write_byte_data(client, ADT7473_REG_CFG4, reg); | ||
593 | mutex_unlock(&data->lock); | ||
594 | |||
595 | return count; | ||
596 | } | ||
597 | |||
598 | static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, | ||
599 | char *buf) | ||
600 | { | ||
601 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
602 | struct adt7473_data *data = adt7473_update_device(dev); | ||
603 | return sprintf(buf, "%d\n", data->pwm[attr->index]); | ||
604 | } | ||
605 | |||
606 | static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, | ||
607 | const char *buf, size_t count) | ||
608 | { | ||
609 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
610 | struct i2c_client *client = to_i2c_client(dev); | ||
611 | struct adt7473_data *data = i2c_get_clientdata(client); | ||
612 | long temp; | ||
613 | |||
614 | if (strict_strtol(buf, 10, &temp)) | ||
615 | return -EINVAL; | ||
616 | |||
617 | temp = SENSORS_LIMIT(temp, 0, 255); | ||
618 | |||
619 | mutex_lock(&data->lock); | ||
620 | data->pwm[attr->index] = temp; | ||
621 | i2c_smbus_write_byte_data(client, ADT7473_REG_PWM(attr->index), temp); | ||
622 | mutex_unlock(&data->lock); | ||
623 | |||
624 | return count; | ||
625 | } | ||
626 | |||
627 | static ssize_t show_pwm_max(struct device *dev, | ||
628 | struct device_attribute *devattr, | ||
629 | char *buf) | ||
630 | { | ||
631 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
632 | struct adt7473_data *data = adt7473_update_device(dev); | ||
633 | return sprintf(buf, "%d\n", data->pwm_max[attr->index]); | ||
634 | } | ||
635 | |||
636 | static ssize_t set_pwm_max(struct device *dev, | ||
637 | struct device_attribute *devattr, | ||
638 | const char *buf, | ||
639 | size_t count) | ||
640 | { | ||
641 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
642 | struct i2c_client *client = to_i2c_client(dev); | ||
643 | struct adt7473_data *data = i2c_get_clientdata(client); | ||
644 | long temp; | ||
645 | |||
646 | if (strict_strtol(buf, 10, &temp)) | ||
647 | return -EINVAL; | ||
648 | |||
649 | temp = SENSORS_LIMIT(temp, 0, 255); | ||
650 | |||
651 | mutex_lock(&data->lock); | ||
652 | data->pwm_max[attr->index] = temp; | ||
653 | i2c_smbus_write_byte_data(client, ADT7473_REG_PWM_MAX(attr->index), | ||
654 | temp); | ||
655 | mutex_unlock(&data->lock); | ||
656 | |||
657 | return count; | ||
658 | } | ||
659 | |||
660 | static ssize_t show_pwm_min(struct device *dev, | ||
661 | struct device_attribute *devattr, | ||
662 | char *buf) | ||
663 | { | ||
664 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
665 | struct adt7473_data *data = adt7473_update_device(dev); | ||
666 | return sprintf(buf, "%d\n", data->pwm_min[attr->index]); | ||
667 | } | ||
668 | |||
669 | static ssize_t set_pwm_min(struct device *dev, | ||
670 | struct device_attribute *devattr, | ||
671 | const char *buf, | ||
672 | size_t count) | ||
673 | { | ||
674 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
675 | struct i2c_client *client = to_i2c_client(dev); | ||
676 | struct adt7473_data *data = i2c_get_clientdata(client); | ||
677 | long temp; | ||
678 | |||
679 | if (strict_strtol(buf, 10, &temp)) | ||
680 | return -EINVAL; | ||
681 | |||
682 | temp = SENSORS_LIMIT(temp, 0, 255); | ||
683 | |||
684 | mutex_lock(&data->lock); | ||
685 | data->pwm_min[attr->index] = temp; | ||
686 | i2c_smbus_write_byte_data(client, ADT7473_REG_PWM_MIN(attr->index), | ||
687 | temp); | ||
688 | mutex_unlock(&data->lock); | ||
689 | |||
690 | return count; | ||
691 | } | ||
692 | |||
693 | static ssize_t show_temp_tmax(struct device *dev, | ||
694 | struct device_attribute *devattr, | ||
695 | char *buf) | ||
696 | { | ||
697 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
698 | struct adt7473_data *data = adt7473_update_device(dev); | ||
699 | return sprintf(buf, "%d\n", 1000 * decode_temp( | ||
700 | data->temp_twos_complement, | ||
701 | data->temp_tmax[attr->index])); | ||
702 | } | ||
703 | |||
704 | static ssize_t set_temp_tmax(struct device *dev, | ||
705 | struct device_attribute *devattr, | ||
706 | const char *buf, | ||
707 | size_t count) | ||
708 | { | ||
709 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
710 | struct i2c_client *client = to_i2c_client(dev); | ||
711 | struct adt7473_data *data = i2c_get_clientdata(client); | ||
712 | long temp; | ||
713 | |||
714 | if (strict_strtol(buf, 10, &temp)) | ||
715 | return -EINVAL; | ||
716 | |||
717 | temp = DIV_ROUND_CLOSEST(temp, 1000); | ||
718 | temp = encode_temp(data->temp_twos_complement, temp); | ||
719 | |||
720 | mutex_lock(&data->lock); | ||
721 | data->temp_tmax[attr->index] = temp; | ||
722 | i2c_smbus_write_byte_data(client, ADT7473_REG_TEMP_TMAX(attr->index), | ||
723 | temp); | ||
724 | mutex_unlock(&data->lock); | ||
725 | |||
726 | return count; | ||
727 | } | ||
728 | |||
729 | static ssize_t show_temp_tmin(struct device *dev, | ||
730 | struct device_attribute *devattr, | ||
731 | char *buf) | ||
732 | { | ||
733 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
734 | struct adt7473_data *data = adt7473_update_device(dev); | ||
735 | return sprintf(buf, "%d\n", 1000 * decode_temp( | ||
736 | data->temp_twos_complement, | ||
737 | data->temp_tmin[attr->index])); | ||
738 | } | ||
739 | |||
740 | static ssize_t set_temp_tmin(struct device *dev, | ||
741 | struct device_attribute *devattr, | ||
742 | const char *buf, | ||
743 | size_t count) | ||
744 | { | ||
745 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
746 | struct i2c_client *client = to_i2c_client(dev); | ||
747 | struct adt7473_data *data = i2c_get_clientdata(client); | ||
748 | long temp; | ||
749 | |||
750 | if (strict_strtol(buf, 10, &temp)) | ||
751 | return -EINVAL; | ||
752 | |||
753 | temp = DIV_ROUND_CLOSEST(temp, 1000); | ||
754 | temp = encode_temp(data->temp_twos_complement, temp); | ||
755 | |||
756 | mutex_lock(&data->lock); | ||
757 | data->temp_tmin[attr->index] = temp; | ||
758 | i2c_smbus_write_byte_data(client, ADT7473_REG_TEMP_TMIN(attr->index), | ||
759 | temp); | ||
760 | mutex_unlock(&data->lock); | ||
761 | |||
762 | return count; | ||
763 | } | ||
764 | |||
765 | static ssize_t show_pwm_enable(struct device *dev, | ||
766 | struct device_attribute *devattr, | ||
767 | char *buf) | ||
768 | { | ||
769 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
770 | struct adt7473_data *data = adt7473_update_device(dev); | ||
771 | |||
772 | switch (data->pwm_behavior[attr->index] >> ADT7473_PWM_BHVR_SHIFT) { | ||
773 | case 3: | ||
774 | return sprintf(buf, "0\n"); | ||
775 | case 7: | ||
776 | return sprintf(buf, "1\n"); | ||
777 | default: | ||
778 | return sprintf(buf, "2\n"); | ||
779 | } | ||
780 | } | ||
781 | |||
782 | static ssize_t set_pwm_enable(struct device *dev, | ||
783 | struct device_attribute *devattr, | ||
784 | const char *buf, | ||
785 | size_t count) | ||
786 | { | ||
787 | u8 reg; | ||
788 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
789 | struct i2c_client *client = to_i2c_client(dev); | ||
790 | struct adt7473_data *data = i2c_get_clientdata(client); | ||
791 | long temp; | ||
792 | |||
793 | if (strict_strtol(buf, 10, &temp)) | ||
794 | return -EINVAL; | ||
795 | |||
796 | switch (temp) { | ||
797 | case 0: | ||
798 | temp = 3; | ||
799 | break; | ||
800 | case 1: | ||
801 | temp = 7; | ||
802 | break; | ||
803 | case 2: | ||
804 | /* Enter automatic mode with fans off */ | ||
805 | temp = 4; | ||
806 | break; | ||
807 | default: | ||
808 | return -EINVAL; | ||
809 | } | ||
810 | |||
811 | mutex_lock(&data->lock); | ||
812 | reg = i2c_smbus_read_byte_data(client, | ||
813 | ADT7473_REG_PWM_BHVR(attr->index)); | ||
814 | reg = (temp << ADT7473_PWM_BHVR_SHIFT) | | ||
815 | (reg & ~ADT7473_PWM_BHVR_MASK); | ||
816 | i2c_smbus_write_byte_data(client, ADT7473_REG_PWM_BHVR(attr->index), | ||
817 | reg); | ||
818 | data->pwm_behavior[attr->index] = reg; | ||
819 | mutex_unlock(&data->lock); | ||
820 | |||
821 | return count; | ||
822 | } | ||
823 | |||
824 | static ssize_t show_pwm_auto_temp(struct device *dev, | ||
825 | struct device_attribute *devattr, | ||
826 | char *buf) | ||
827 | { | ||
828 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
829 | struct adt7473_data *data = adt7473_update_device(dev); | ||
830 | int bhvr = data->pwm_behavior[attr->index] >> ADT7473_PWM_BHVR_SHIFT; | ||
831 | |||
832 | switch (bhvr) { | ||
833 | case 3: | ||
834 | case 4: | ||
835 | case 7: | ||
836 | return sprintf(buf, "0\n"); | ||
837 | case 0: | ||
838 | case 1: | ||
839 | case 5: | ||
840 | case 6: | ||
841 | return sprintf(buf, "%d\n", bhvr + 1); | ||
842 | case 2: | ||
843 | return sprintf(buf, "4\n"); | ||
844 | } | ||
845 | /* shouldn't ever get here */ | ||
846 | BUG(); | ||
847 | } | ||
848 | |||
849 | static ssize_t set_pwm_auto_temp(struct device *dev, | ||
850 | struct device_attribute *devattr, | ||
851 | const char *buf, | ||
852 | size_t count) | ||
853 | { | ||
854 | u8 reg; | ||
855 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
856 | struct i2c_client *client = to_i2c_client(dev); | ||
857 | struct adt7473_data *data = i2c_get_clientdata(client); | ||
858 | long temp; | ||
859 | |||
860 | if (strict_strtol(buf, 10, &temp)) | ||
861 | return -EINVAL; | ||
862 | |||
863 | switch (temp) { | ||
864 | case 1: | ||
865 | case 2: | ||
866 | case 6: | ||
867 | case 7: | ||
868 | temp--; | ||
869 | break; | ||
870 | case 0: | ||
871 | temp = 4; | ||
872 | break; | ||
873 | default: | ||
874 | return -EINVAL; | ||
875 | } | ||
876 | |||
877 | mutex_lock(&data->lock); | ||
878 | reg = i2c_smbus_read_byte_data(client, | ||
879 | ADT7473_REG_PWM_BHVR(attr->index)); | ||
880 | reg = (temp << ADT7473_PWM_BHVR_SHIFT) | | ||
881 | (reg & ~ADT7473_PWM_BHVR_MASK); | ||
882 | i2c_smbus_write_byte_data(client, ADT7473_REG_PWM_BHVR(attr->index), | ||
883 | reg); | ||
884 | data->pwm_behavior[attr->index] = reg; | ||
885 | mutex_unlock(&data->lock); | ||
886 | |||
887 | return count; | ||
888 | } | ||
889 | |||
890 | static ssize_t show_alarm(struct device *dev, | ||
891 | struct device_attribute *devattr, | ||
892 | char *buf) | ||
893 | { | ||
894 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
895 | struct adt7473_data *data = adt7473_update_device(dev); | ||
896 | |||
897 | if (data->alarm & attr->index) | ||
898 | return sprintf(buf, "1\n"); | ||
899 | else | ||
900 | return sprintf(buf, "0\n"); | ||
901 | } | ||
902 | |||
903 | |||
904 | static SENSOR_DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO, show_volt_max, | ||
905 | set_volt_max, 0); | ||
906 | static SENSOR_DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO, show_volt_max, | ||
907 | set_volt_max, 1); | ||
908 | |||
909 | static SENSOR_DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO, show_volt_min, | ||
910 | set_volt_min, 0); | ||
911 | static SENSOR_DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO, show_volt_min, | ||
912 | set_volt_min, 1); | ||
913 | |||
914 | static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_volt, NULL, 0); | ||
915 | static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_volt, NULL, 1); | ||
916 | |||
917 | static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, | ||
918 | ADT7473_VCCP_ALARM); | ||
919 | static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, | ||
920 | ADT7473_VCC_ALARM); | ||
921 | |||
922 | static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, | ||
923 | set_temp_max, 0); | ||
924 | static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_max, | ||
925 | set_temp_max, 1); | ||
926 | static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_temp_max, | ||
927 | set_temp_max, 2); | ||
928 | |||
929 | static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp_min, | ||
930 | set_temp_min, 0); | ||
931 | static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp_min, | ||
932 | set_temp_min, 1); | ||
933 | static SENSOR_DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO, show_temp_min, | ||
934 | set_temp_min, 2); | ||
935 | |||
936 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); | ||
937 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1); | ||
938 | static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2); | ||
939 | |||
940 | static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, | ||
941 | ADT7473_R1T_ALARM | ALARM2(ADT7473_R1T_SHORT)); | ||
942 | static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, | ||
943 | ADT7473_LT_ALARM); | ||
944 | static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, | ||
945 | ADT7473_R2T_ALARM | ALARM2(ADT7473_R2T_SHORT)); | ||
946 | |||
947 | static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min, | ||
948 | set_fan_min, 0); | ||
949 | static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min, | ||
950 | set_fan_min, 1); | ||
951 | static SENSOR_DEVICE_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min, | ||
952 | set_fan_min, 2); | ||
953 | static SENSOR_DEVICE_ATTR(fan4_min, S_IWUSR | S_IRUGO, show_fan_min, | ||
954 | set_fan_min, 3); | ||
955 | |||
956 | static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0); | ||
957 | static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1); | ||
958 | static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2); | ||
959 | static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3); | ||
960 | |||
961 | static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, | ||
962 | ALARM2(ADT7473_FAN1_ALARM)); | ||
963 | static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, | ||
964 | ALARM2(ADT7473_FAN2_ALARM)); | ||
965 | static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, | ||
966 | ALARM2(ADT7473_FAN3_ALARM)); | ||
967 | static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, | ||
968 | ALARM2(ADT7473_FAN4_ALARM)); | ||
969 | |||
970 | static SENSOR_DEVICE_ATTR(pwm_use_point2_pwm_at_crit, S_IWUSR | S_IRUGO, | ||
971 | show_max_duty_at_crit, set_max_duty_at_crit, 0); | ||
972 | |||
973 | static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 0); | ||
974 | static SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 1); | ||
975 | static SENSOR_DEVICE_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2); | ||
976 | |||
977 | static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IWUSR | S_IRUGO, | ||
978 | show_pwm_min, set_pwm_min, 0); | ||
979 | static SENSOR_DEVICE_ATTR(pwm2_auto_point1_pwm, S_IWUSR | S_IRUGO, | ||
980 | show_pwm_min, set_pwm_min, 1); | ||
981 | static SENSOR_DEVICE_ATTR(pwm3_auto_point1_pwm, S_IWUSR | S_IRUGO, | ||
982 | show_pwm_min, set_pwm_min, 2); | ||
983 | |||
984 | static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IWUSR | S_IRUGO, | ||
985 | show_pwm_max, set_pwm_max, 0); | ||
986 | static SENSOR_DEVICE_ATTR(pwm2_auto_point2_pwm, S_IWUSR | S_IRUGO, | ||
987 | show_pwm_max, set_pwm_max, 1); | ||
988 | static SENSOR_DEVICE_ATTR(pwm3_auto_point2_pwm, S_IWUSR | S_IRUGO, | ||
989 | show_pwm_max, set_pwm_max, 2); | ||
990 | |||
991 | static SENSOR_DEVICE_ATTR(temp1_auto_point1_temp, S_IWUSR | S_IRUGO, | ||
992 | show_temp_tmin, set_temp_tmin, 0); | ||
993 | static SENSOR_DEVICE_ATTR(temp2_auto_point1_temp, S_IWUSR | S_IRUGO, | ||
994 | show_temp_tmin, set_temp_tmin, 1); | ||
995 | static SENSOR_DEVICE_ATTR(temp3_auto_point1_temp, S_IWUSR | S_IRUGO, | ||
996 | show_temp_tmin, set_temp_tmin, 2); | ||
997 | |||
998 | static SENSOR_DEVICE_ATTR(temp1_auto_point2_temp, S_IWUSR | S_IRUGO, | ||
999 | show_temp_tmax, set_temp_tmax, 0); | ||
1000 | static SENSOR_DEVICE_ATTR(temp2_auto_point2_temp, S_IWUSR | S_IRUGO, | ||
1001 | show_temp_tmax, set_temp_tmax, 1); | ||
1002 | static SENSOR_DEVICE_ATTR(temp3_auto_point2_temp, S_IWUSR | S_IRUGO, | ||
1003 | show_temp_tmax, set_temp_tmax, 2); | ||
1004 | |||
1005 | static SENSOR_DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, show_pwm_enable, | ||
1006 | set_pwm_enable, 0); | ||
1007 | static SENSOR_DEVICE_ATTR(pwm2_enable, S_IWUSR | S_IRUGO, show_pwm_enable, | ||
1008 | set_pwm_enable, 1); | ||
1009 | static SENSOR_DEVICE_ATTR(pwm3_enable, S_IWUSR | S_IRUGO, show_pwm_enable, | ||
1010 | set_pwm_enable, 2); | ||
1011 | |||
1012 | static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IWUSR | S_IRUGO, | ||
1013 | show_pwm_auto_temp, set_pwm_auto_temp, 0); | ||
1014 | static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IWUSR | S_IRUGO, | ||
1015 | show_pwm_auto_temp, set_pwm_auto_temp, 1); | ||
1016 | static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IWUSR | S_IRUGO, | ||
1017 | show_pwm_auto_temp, set_pwm_auto_temp, 2); | ||
1018 | |||
1019 | static struct attribute *adt7473_attr[] = | ||
1020 | { | ||
1021 | &sensor_dev_attr_in1_max.dev_attr.attr, | ||
1022 | &sensor_dev_attr_in2_max.dev_attr.attr, | ||
1023 | &sensor_dev_attr_in1_min.dev_attr.attr, | ||
1024 | &sensor_dev_attr_in2_min.dev_attr.attr, | ||
1025 | &sensor_dev_attr_in1_input.dev_attr.attr, | ||
1026 | &sensor_dev_attr_in2_input.dev_attr.attr, | ||
1027 | &sensor_dev_attr_in1_alarm.dev_attr.attr, | ||
1028 | &sensor_dev_attr_in2_alarm.dev_attr.attr, | ||
1029 | |||
1030 | &sensor_dev_attr_temp1_max.dev_attr.attr, | ||
1031 | &sensor_dev_attr_temp2_max.dev_attr.attr, | ||
1032 | &sensor_dev_attr_temp3_max.dev_attr.attr, | ||
1033 | &sensor_dev_attr_temp1_min.dev_attr.attr, | ||
1034 | &sensor_dev_attr_temp2_min.dev_attr.attr, | ||
1035 | &sensor_dev_attr_temp3_min.dev_attr.attr, | ||
1036 | &sensor_dev_attr_temp1_input.dev_attr.attr, | ||
1037 | &sensor_dev_attr_temp2_input.dev_attr.attr, | ||
1038 | &sensor_dev_attr_temp3_input.dev_attr.attr, | ||
1039 | &sensor_dev_attr_temp1_alarm.dev_attr.attr, | ||
1040 | &sensor_dev_attr_temp2_alarm.dev_attr.attr, | ||
1041 | &sensor_dev_attr_temp3_alarm.dev_attr.attr, | ||
1042 | &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr, | ||
1043 | &sensor_dev_attr_temp2_auto_point1_temp.dev_attr.attr, | ||
1044 | &sensor_dev_attr_temp3_auto_point1_temp.dev_attr.attr, | ||
1045 | &sensor_dev_attr_temp1_auto_point2_temp.dev_attr.attr, | ||
1046 | &sensor_dev_attr_temp2_auto_point2_temp.dev_attr.attr, | ||
1047 | &sensor_dev_attr_temp3_auto_point2_temp.dev_attr.attr, | ||
1048 | |||
1049 | &sensor_dev_attr_fan1_min.dev_attr.attr, | ||
1050 | &sensor_dev_attr_fan2_min.dev_attr.attr, | ||
1051 | &sensor_dev_attr_fan3_min.dev_attr.attr, | ||
1052 | &sensor_dev_attr_fan4_min.dev_attr.attr, | ||
1053 | &sensor_dev_attr_fan1_input.dev_attr.attr, | ||
1054 | &sensor_dev_attr_fan2_input.dev_attr.attr, | ||
1055 | &sensor_dev_attr_fan3_input.dev_attr.attr, | ||
1056 | &sensor_dev_attr_fan4_input.dev_attr.attr, | ||
1057 | &sensor_dev_attr_fan1_alarm.dev_attr.attr, | ||
1058 | &sensor_dev_attr_fan2_alarm.dev_attr.attr, | ||
1059 | &sensor_dev_attr_fan3_alarm.dev_attr.attr, | ||
1060 | &sensor_dev_attr_fan4_alarm.dev_attr.attr, | ||
1061 | |||
1062 | &sensor_dev_attr_pwm_use_point2_pwm_at_crit.dev_attr.attr, | ||
1063 | |||
1064 | &sensor_dev_attr_pwm1.dev_attr.attr, | ||
1065 | &sensor_dev_attr_pwm2.dev_attr.attr, | ||
1066 | &sensor_dev_attr_pwm3.dev_attr.attr, | ||
1067 | &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr, | ||
1068 | &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr, | ||
1069 | &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr, | ||
1070 | &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr, | ||
1071 | &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr, | ||
1072 | &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr, | ||
1073 | |||
1074 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, | ||
1075 | &sensor_dev_attr_pwm2_enable.dev_attr.attr, | ||
1076 | &sensor_dev_attr_pwm3_enable.dev_attr.attr, | ||
1077 | &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr, | ||
1078 | &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr, | ||
1079 | &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr, | ||
1080 | |||
1081 | NULL | ||
1082 | }; | ||
1083 | |||
1084 | /* Return 0 if detection is successful, -ENODEV otherwise */ | ||
1085 | static int adt7473_detect(struct i2c_client *client, | ||
1086 | struct i2c_board_info *info) | ||
1087 | { | ||
1088 | struct i2c_adapter *adapter = client->adapter; | ||
1089 | int vendor, device, revision; | ||
1090 | |||
1091 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | ||
1092 | return -ENODEV; | ||
1093 | |||
1094 | vendor = i2c_smbus_read_byte_data(client, ADT7473_REG_VENDOR); | ||
1095 | if (vendor != ADT7473_VENDOR) | ||
1096 | return -ENODEV; | ||
1097 | |||
1098 | device = i2c_smbus_read_byte_data(client, ADT7473_REG_DEVICE); | ||
1099 | if (device != ADT7473_DEVICE) | ||
1100 | return -ENODEV; | ||
1101 | |||
1102 | revision = i2c_smbus_read_byte_data(client, ADT7473_REG_REVISION); | ||
1103 | if (revision != ADT7473_REV_68 && revision != ADT7473_REV_69) | ||
1104 | return -ENODEV; | ||
1105 | |||
1106 | strlcpy(info->type, "adt7473", I2C_NAME_SIZE); | ||
1107 | |||
1108 | return 0; | ||
1109 | } | ||
1110 | |||
1111 | static int adt7473_probe(struct i2c_client *client, | ||
1112 | const struct i2c_device_id *id) | ||
1113 | { | ||
1114 | struct adt7473_data *data; | ||
1115 | int err; | ||
1116 | |||
1117 | data = kzalloc(sizeof(struct adt7473_data), GFP_KERNEL); | ||
1118 | if (!data) { | ||
1119 | err = -ENOMEM; | ||
1120 | goto exit; | ||
1121 | } | ||
1122 | |||
1123 | i2c_set_clientdata(client, data); | ||
1124 | mutex_init(&data->lock); | ||
1125 | |||
1126 | dev_info(&client->dev, "%s chip found\n", client->name); | ||
1127 | |||
1128 | /* Initialize the ADT7473 chip */ | ||
1129 | adt7473_init_client(client); | ||
1130 | |||
1131 | /* Register sysfs hooks */ | ||
1132 | data->attrs.attrs = adt7473_attr; | ||
1133 | err = sysfs_create_group(&client->dev.kobj, &data->attrs); | ||
1134 | if (err) | ||
1135 | goto exit_free; | ||
1136 | |||
1137 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
1138 | if (IS_ERR(data->hwmon_dev)) { | ||
1139 | err = PTR_ERR(data->hwmon_dev); | ||
1140 | goto exit_remove; | ||
1141 | } | ||
1142 | |||
1143 | return 0; | ||
1144 | |||
1145 | exit_remove: | ||
1146 | sysfs_remove_group(&client->dev.kobj, &data->attrs); | ||
1147 | exit_free: | ||
1148 | kfree(data); | ||
1149 | exit: | ||
1150 | return err; | ||
1151 | } | ||
1152 | |||
1153 | static int adt7473_remove(struct i2c_client *client) | ||
1154 | { | ||
1155 | struct adt7473_data *data = i2c_get_clientdata(client); | ||
1156 | |||
1157 | hwmon_device_unregister(data->hwmon_dev); | ||
1158 | sysfs_remove_group(&client->dev.kobj, &data->attrs); | ||
1159 | kfree(data); | ||
1160 | return 0; | ||
1161 | } | ||
1162 | |||
1163 | static int __init adt7473_init(void) | ||
1164 | { | ||
1165 | pr_notice("The adt7473 driver is deprecated, please use the adt7475 " | ||
1166 | "driver instead\n"); | ||
1167 | return i2c_add_driver(&adt7473_driver); | ||
1168 | } | ||
1169 | |||
1170 | static void __exit adt7473_exit(void) | ||
1171 | { | ||
1172 | i2c_del_driver(&adt7473_driver); | ||
1173 | } | ||
1174 | |||
1175 | MODULE_AUTHOR("Darrick J. Wong <djwong@us.ibm.com>"); | ||
1176 | MODULE_DESCRIPTION("ADT7473 driver"); | ||
1177 | MODULE_LICENSE("GPL"); | ||
1178 | |||
1179 | module_init(adt7473_init); | ||
1180 | module_exit(adt7473_exit); | ||