aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/adm1031.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/adm1031.c')
-rw-r--r--drivers/hwmon/adm1031.c501
1 files changed, 242 insertions, 259 deletions
diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c
index 37cfc101da5e..5aaad3636c98 100644
--- a/drivers/hwmon/adm1031.c
+++ b/drivers/hwmon/adm1031.c
@@ -5,7 +5,7 @@
5 Supports adm1030 / adm1031 5 Supports adm1030 / adm1031
6 Copyright (C) 2004 Alexandre d'Alton <alex@alexdalton.org> 6 Copyright (C) 2004 Alexandre d'Alton <alex@alexdalton.org>
7 Reworked by Jean Delvare <khali@linux-fr.org> 7 Reworked by Jean Delvare <khali@linux-fr.org>
8 8
9 This program is free software; you can redistribute it and/or modify 9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by 10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or 11 the Free Software Foundation; either version 2 of the License, or
@@ -27,27 +27,28 @@
27#include <linux/jiffies.h> 27#include <linux/jiffies.h>
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/hwmon.h> 29#include <linux/hwmon.h>
30#include <linux/hwmon-sysfs.h>
30#include <linux/err.h> 31#include <linux/err.h>
31#include <linux/mutex.h> 32#include <linux/mutex.h>
32 33
33/* Following macros takes channel parameter starting from 0 to 2 */ 34/* Following macros takes channel parameter starting from 0 to 2 */
34#define ADM1031_REG_FAN_SPEED(nr) (0x08 + (nr)) 35#define ADM1031_REG_FAN_SPEED(nr) (0x08 + (nr))
35#define ADM1031_REG_FAN_DIV(nr) (0x20 + (nr)) 36#define ADM1031_REG_FAN_DIV(nr) (0x20 + (nr))
36#define ADM1031_REG_PWM (0x22) 37#define ADM1031_REG_PWM (0x22)
37#define ADM1031_REG_FAN_MIN(nr) (0x10 + (nr)) 38#define ADM1031_REG_FAN_MIN(nr) (0x10 + (nr))
38 39
39#define ADM1031_REG_TEMP_MAX(nr) (0x14 + 4*(nr)) 40#define ADM1031_REG_TEMP_MAX(nr) (0x14 + 4 * (nr))
40#define ADM1031_REG_TEMP_MIN(nr) (0x15 + 4*(nr)) 41#define ADM1031_REG_TEMP_MIN(nr) (0x15 + 4 * (nr))
41#define ADM1031_REG_TEMP_CRIT(nr) (0x16 + 4*(nr)) 42#define ADM1031_REG_TEMP_CRIT(nr) (0x16 + 4 * (nr))
42 43
43#define ADM1031_REG_TEMP(nr) (0xa + (nr)) 44#define ADM1031_REG_TEMP(nr) (0x0a + (nr))
44#define ADM1031_REG_AUTO_TEMP(nr) (0x24 + (nr)) 45#define ADM1031_REG_AUTO_TEMP(nr) (0x24 + (nr))
45 46
46#define ADM1031_REG_STATUS(nr) (0x2 + (nr)) 47#define ADM1031_REG_STATUS(nr) (0x2 + (nr))
47 48
48#define ADM1031_REG_CONF1 0x0 49#define ADM1031_REG_CONF1 0x00
49#define ADM1031_REG_CONF2 0x1 50#define ADM1031_REG_CONF2 0x01
50#define ADM1031_REG_EXT_TEMP 0x6 51#define ADM1031_REG_EXT_TEMP 0x06
51 52
52#define ADM1031_CONF1_MONITOR_ENABLE 0x01 /* Monitoring enable */ 53#define ADM1031_CONF1_MONITOR_ENABLE 0x01 /* Monitoring enable */
53#define ADM1031_CONF1_PWM_INVERT 0x08 /* PWM Invert */ 54#define ADM1031_CONF1_PWM_INVERT 0x08 /* PWM Invert */
@@ -78,7 +79,7 @@ struct adm1031_data {
78 /* The chan_select_table contains the possible configurations for 79 /* The chan_select_table contains the possible configurations for
79 * auto fan control. 80 * auto fan control.
80 */ 81 */
81 auto_chan_table_t *chan_select_table; 82 const auto_chan_table_t *chan_select_table;
82 u16 alarm; 83 u16 alarm;
83 u8 conf1; 84 u8 conf1;
84 u8 conf2; 85 u8 conf2;
@@ -181,25 +182,25 @@ static int AUTO_TEMP_MAX_TO_REG(int val, int reg, int pwm)
181#define GET_FAN_AUTO_BITFIELD(data, idx) \ 182#define GET_FAN_AUTO_BITFIELD(data, idx) \
182 (*(data)->chan_select_table)[FAN_CHAN_FROM_REG((data)->conf1)][idx%2] 183 (*(data)->chan_select_table)[FAN_CHAN_FROM_REG((data)->conf1)][idx%2]
183 184
184/* The tables below contains the possible values for the auto fan 185/* The tables below contains the possible values for the auto fan
185 * control bitfields. the index in the table is the register value. 186 * control bitfields. the index in the table is the register value.
186 * MSb is the auto fan control enable bit, so the four first entries 187 * MSb is the auto fan control enable bit, so the four first entries
187 * in the table disables auto fan control when both bitfields are zero. 188 * in the table disables auto fan control when both bitfields are zero.
188 */ 189 */
189static auto_chan_table_t auto_channel_select_table_adm1031 = { 190static const auto_chan_table_t auto_channel_select_table_adm1031 = {
190 {0, 0}, {0, 0}, {0, 0}, {0, 0}, 191 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
191 {2 /*0b010 */ , 4 /*0b100 */ }, 192 { 2 /* 0b010 */ , 4 /* 0b100 */ },
192 {2 /*0b010 */ , 2 /*0b010 */ }, 193 { 2 /* 0b010 */ , 2 /* 0b010 */ },
193 {4 /*0b100 */ , 4 /*0b100 */ }, 194 { 4 /* 0b100 */ , 4 /* 0b100 */ },
194 {7 /*0b111 */ , 7 /*0b111 */ }, 195 { 7 /* 0b111 */ , 7 /* 0b111 */ },
195}; 196};
196 197
197static auto_chan_table_t auto_channel_select_table_adm1030 = { 198static const auto_chan_table_t auto_channel_select_table_adm1030 = {
198 {0, 0}, {0, 0}, {0, 0}, {0, 0}, 199 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
199 {2 /*0b10 */ , 0}, 200 { 2 /* 0b10 */ , 0 },
200 {0xff /*invalid */ , 0}, 201 { 0xff /* invalid */ , 0 },
201 {0xff /*invalid */ , 0}, 202 { 0xff /* invalid */ , 0 },
202 {3 /*0b11 */ , 0}, 203 { 3 /* 0b11 */ , 0 },
203}; 204};
204 205
205/* That function checks if a bitfield is valid and returns the other bitfield 206/* That function checks if a bitfield is valid and returns the other bitfield
@@ -228,8 +229,8 @@ get_fan_auto_nearest(struct adm1031_data *data,
228 break; 229 break;
229 } else if (val == (*data->chan_select_table)[i][chan] && 230 } else if (val == (*data->chan_select_table)[i][chan] &&
230 first_match == -1) { 231 first_match == -1) {
231 /* Save the first match in case of an exact match has not been 232 /* Save the first match in case of an exact match has
232 * found 233 * not been found
233 */ 234 */
234 first_match = i; 235 first_match = i;
235 } 236 }
@@ -245,17 +246,21 @@ get_fan_auto_nearest(struct adm1031_data *data,
245 return 0; 246 return 0;
246} 247}
247 248
248static ssize_t show_fan_auto_channel(struct device *dev, char *buf, int nr) 249static ssize_t show_fan_auto_channel(struct device *dev,
250 struct device_attribute *attr, char *buf)
249{ 251{
252 int nr = to_sensor_dev_attr(attr)->index;
250 struct adm1031_data *data = adm1031_update_device(dev); 253 struct adm1031_data *data = adm1031_update_device(dev);
251 return sprintf(buf, "%d\n", GET_FAN_AUTO_BITFIELD(data, nr)); 254 return sprintf(buf, "%d\n", GET_FAN_AUTO_BITFIELD(data, nr));
252} 255}
253 256
254static ssize_t 257static ssize_t
255set_fan_auto_channel(struct device *dev, const char *buf, size_t count, int nr) 258set_fan_auto_channel(struct device *dev, struct device_attribute *attr,
259 const char *buf, size_t count)
256{ 260{
257 struct i2c_client *client = to_i2c_client(dev); 261 struct i2c_client *client = to_i2c_client(dev);
258 struct adm1031_data *data = i2c_get_clientdata(client); 262 struct adm1031_data *data = i2c_get_clientdata(client);
263 int nr = to_sensor_dev_attr(attr)->index;
259 int val = simple_strtol(buf, NULL, 10); 264 int val = simple_strtol(buf, NULL, 10);
260 u8 reg; 265 u8 reg;
261 int ret; 266 int ret;
@@ -264,16 +269,17 @@ set_fan_auto_channel(struct device *dev, const char *buf, size_t count, int nr)
264 old_fan_mode = data->conf1; 269 old_fan_mode = data->conf1;
265 270
266 mutex_lock(&data->update_lock); 271 mutex_lock(&data->update_lock);
267 272
268 if ((ret = get_fan_auto_nearest(data, nr, val, data->conf1, &reg))) { 273 if ((ret = get_fan_auto_nearest(data, nr, val, data->conf1, &reg))) {
269 mutex_unlock(&data->update_lock); 274 mutex_unlock(&data->update_lock);
270 return ret; 275 return ret;
271 } 276 }
272 if (((data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1)) & ADM1031_CONF1_AUTO_MODE) ^ 277 data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1);
278 if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) ^
273 (old_fan_mode & ADM1031_CONF1_AUTO_MODE)) { 279 (old_fan_mode & ADM1031_CONF1_AUTO_MODE)) {
274 if (data->conf1 & ADM1031_CONF1_AUTO_MODE){ 280 if (data->conf1 & ADM1031_CONF1_AUTO_MODE){
275 /* Switch to Auto Fan Mode 281 /* Switch to Auto Fan Mode
276 * Save PWM registers 282 * Save PWM registers
277 * Set PWM registers to 33% Both */ 283 * Set PWM registers to 33% Both */
278 data->old_pwm[0] = data->pwm[0]; 284 data->old_pwm[0] = data->pwm[0];
279 data->old_pwm[1] = data->pwm[1]; 285 data->old_pwm[1] = data->pwm[1];
@@ -283,7 +289,7 @@ set_fan_auto_channel(struct device *dev, const char *buf, size_t count, int nr)
283 data->pwm[0] = data->old_pwm[0]; 289 data->pwm[0] = data->old_pwm[0];
284 data->pwm[1] = data->old_pwm[1]; 290 data->pwm[1] = data->old_pwm[1];
285 /* Restore PWM registers */ 291 /* Restore PWM registers */
286 adm1031_write_value(client, ADM1031_REG_PWM, 292 adm1031_write_value(client, ADM1031_REG_PWM,
287 data->pwm[0] | (data->pwm[1] << 4)); 293 data->pwm[0] | (data->pwm[1] << 4));
288 } 294 }
289 } 295 }
@@ -293,41 +299,35 @@ set_fan_auto_channel(struct device *dev, const char *buf, size_t count, int nr)
293 return count; 299 return count;
294} 300}
295 301
296#define fan_auto_channel_offset(offset) \ 302static SENSOR_DEVICE_ATTR(auto_fan1_channel, S_IRUGO | S_IWUSR,
297static ssize_t show_fan_auto_channel_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 303 show_fan_auto_channel, set_fan_auto_channel, 0);
298{ \ 304static SENSOR_DEVICE_ATTR(auto_fan2_channel, S_IRUGO | S_IWUSR,
299 return show_fan_auto_channel(dev, buf, offset - 1); \ 305 show_fan_auto_channel, set_fan_auto_channel, 1);
300} \
301static ssize_t set_fan_auto_channel_##offset (struct device *dev, struct device_attribute *attr, \
302 const char *buf, size_t count) \
303{ \
304 return set_fan_auto_channel(dev, buf, count, offset - 1); \
305} \
306static DEVICE_ATTR(auto_fan##offset##_channel, S_IRUGO | S_IWUSR, \
307 show_fan_auto_channel_##offset, \
308 set_fan_auto_channel_##offset)
309
310fan_auto_channel_offset(1);
311fan_auto_channel_offset(2);
312 306
313/* Auto Temps */ 307/* Auto Temps */
314static ssize_t show_auto_temp_off(struct device *dev, char *buf, int nr) 308static ssize_t show_auto_temp_off(struct device *dev,
309 struct device_attribute *attr, char *buf)
315{ 310{
311 int nr = to_sensor_dev_attr(attr)->index;
316 struct adm1031_data *data = adm1031_update_device(dev); 312 struct adm1031_data *data = adm1031_update_device(dev);
317 return sprintf(buf, "%d\n", 313 return sprintf(buf, "%d\n",
318 AUTO_TEMP_OFF_FROM_REG(data->auto_temp[nr])); 314 AUTO_TEMP_OFF_FROM_REG(data->auto_temp[nr]));
319} 315}
320static ssize_t show_auto_temp_min(struct device *dev, char *buf, int nr) 316static ssize_t show_auto_temp_min(struct device *dev,
317 struct device_attribute *attr, char *buf)
321{ 318{
319 int nr = to_sensor_dev_attr(attr)->index;
322 struct adm1031_data *data = adm1031_update_device(dev); 320 struct adm1031_data *data = adm1031_update_device(dev);
323 return sprintf(buf, "%d\n", 321 return sprintf(buf, "%d\n",
324 AUTO_TEMP_MIN_FROM_REG(data->auto_temp[nr])); 322 AUTO_TEMP_MIN_FROM_REG(data->auto_temp[nr]));
325} 323}
326static ssize_t 324static ssize_t
327set_auto_temp_min(struct device *dev, const char *buf, size_t count, int nr) 325set_auto_temp_min(struct device *dev, struct device_attribute *attr,
326 const char *buf, size_t count)
328{ 327{
329 struct i2c_client *client = to_i2c_client(dev); 328 struct i2c_client *client = to_i2c_client(dev);
330 struct adm1031_data *data = i2c_get_clientdata(client); 329 struct adm1031_data *data = i2c_get_clientdata(client);
330 int nr = to_sensor_dev_attr(attr)->index;
331 int val = simple_strtol(buf, NULL, 10); 331 int val = simple_strtol(buf, NULL, 10);
332 332
333 mutex_lock(&data->update_lock); 333 mutex_lock(&data->update_lock);
@@ -337,17 +337,21 @@ set_auto_temp_min(struct device *dev, const char *buf, size_t count, int nr)
337 mutex_unlock(&data->update_lock); 337 mutex_unlock(&data->update_lock);
338 return count; 338 return count;
339} 339}
340static ssize_t show_auto_temp_max(struct device *dev, char *buf, int nr) 340static ssize_t show_auto_temp_max(struct device *dev,
341 struct device_attribute *attr, char *buf)
341{ 342{
343 int nr = to_sensor_dev_attr(attr)->index;
342 struct adm1031_data *data = adm1031_update_device(dev); 344 struct adm1031_data *data = adm1031_update_device(dev);
343 return sprintf(buf, "%d\n", 345 return sprintf(buf, "%d\n",
344 AUTO_TEMP_MAX_FROM_REG(data->auto_temp[nr])); 346 AUTO_TEMP_MAX_FROM_REG(data->auto_temp[nr]));
345} 347}
346static ssize_t 348static ssize_t
347set_auto_temp_max(struct device *dev, const char *buf, size_t count, int nr) 349set_auto_temp_max(struct device *dev, struct device_attribute *attr,
350 const char *buf, size_t count)
348{ 351{
349 struct i2c_client *client = to_i2c_client(dev); 352 struct i2c_client *client = to_i2c_client(dev);
350 struct adm1031_data *data = i2c_get_clientdata(client); 353 struct adm1031_data *data = i2c_get_clientdata(client);
354 int nr = to_sensor_dev_attr(attr)->index;
351 int val = simple_strtol(buf, NULL, 10); 355 int val = simple_strtol(buf, NULL, 10);
352 356
353 mutex_lock(&data->update_lock); 357 mutex_lock(&data->update_lock);
@@ -358,56 +362,37 @@ set_auto_temp_max(struct device *dev, const char *buf, size_t count, int nr)
358 return count; 362 return count;
359} 363}
360 364
361#define auto_temp_reg(offset) \ 365#define auto_temp_reg(offset) \
362static ssize_t show_auto_temp_##offset##_off (struct device *dev, struct device_attribute *attr, char *buf) \ 366static SENSOR_DEVICE_ATTR(auto_temp##offset##_off, S_IRUGO, \
363{ \ 367 show_auto_temp_off, NULL, offset - 1); \
364 return show_auto_temp_off(dev, buf, offset - 1); \ 368static SENSOR_DEVICE_ATTR(auto_temp##offset##_min, S_IRUGO | S_IWUSR, \
365} \ 369 show_auto_temp_min, set_auto_temp_min, offset - 1); \
366static ssize_t show_auto_temp_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ 370static SENSOR_DEVICE_ATTR(auto_temp##offset##_max, S_IRUGO | S_IWUSR, \
367{ \ 371 show_auto_temp_max, set_auto_temp_max, offset - 1)
368 return show_auto_temp_min(dev, buf, offset - 1); \
369} \
370static ssize_t show_auto_temp_##offset##_max (struct device *dev, struct device_attribute *attr, char *buf) \
371{ \
372 return show_auto_temp_max(dev, buf, offset - 1); \
373} \
374static ssize_t set_auto_temp_##offset##_min (struct device *dev, struct device_attribute *attr, \
375 const char *buf, size_t count) \
376{ \
377 return set_auto_temp_min(dev, buf, count, offset - 1); \
378} \
379static ssize_t set_auto_temp_##offset##_max (struct device *dev, struct device_attribute *attr, \
380 const char *buf, size_t count) \
381{ \
382 return set_auto_temp_max(dev, buf, count, offset - 1); \
383} \
384static DEVICE_ATTR(auto_temp##offset##_off, S_IRUGO, \
385 show_auto_temp_##offset##_off, NULL); \
386static DEVICE_ATTR(auto_temp##offset##_min, S_IRUGO | S_IWUSR, \
387 show_auto_temp_##offset##_min, set_auto_temp_##offset##_min);\
388static DEVICE_ATTR(auto_temp##offset##_max, S_IRUGO | S_IWUSR, \
389 show_auto_temp_##offset##_max, set_auto_temp_##offset##_max)
390 372
391auto_temp_reg(1); 373auto_temp_reg(1);
392auto_temp_reg(2); 374auto_temp_reg(2);
393auto_temp_reg(3); 375auto_temp_reg(3);
394 376
395/* pwm */ 377/* pwm */
396static ssize_t show_pwm(struct device *dev, char *buf, int nr) 378static ssize_t show_pwm(struct device *dev,
379 struct device_attribute *attr, char *buf)
397{ 380{
381 int nr = to_sensor_dev_attr(attr)->index;
398 struct adm1031_data *data = adm1031_update_device(dev); 382 struct adm1031_data *data = adm1031_update_device(dev);
399 return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[nr])); 383 return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[nr]));
400} 384}
401static ssize_t 385static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
402set_pwm(struct device *dev, const char *buf, size_t count, int nr) 386 const char *buf, size_t count)
403{ 387{
404 struct i2c_client *client = to_i2c_client(dev); 388 struct i2c_client *client = to_i2c_client(dev);
405 struct adm1031_data *data = i2c_get_clientdata(client); 389 struct adm1031_data *data = i2c_get_clientdata(client);
390 int nr = to_sensor_dev_attr(attr)->index;
406 int val = simple_strtol(buf, NULL, 10); 391 int val = simple_strtol(buf, NULL, 10);
407 int reg; 392 int reg;
408 393
409 mutex_lock(&data->update_lock); 394 mutex_lock(&data->update_lock);
410 if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) && 395 if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) &&
411 (((val>>4) & 0xf) != 5)) { 396 (((val>>4) & 0xf) != 5)) {
412 /* In automatic mode, the only PWM accepted is 33% */ 397 /* In automatic mode, the only PWM accepted is 33% */
413 mutex_unlock(&data->update_lock); 398 mutex_unlock(&data->update_lock);
@@ -422,21 +407,12 @@ set_pwm(struct device *dev, const char *buf, size_t count, int nr)
422 return count; 407 return count;
423} 408}
424 409
425#define pwm_reg(offset) \ 410static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0);
426static ssize_t show_pwm_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 411static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 1);
427{ \ 412static SENSOR_DEVICE_ATTR(auto_fan1_min_pwm, S_IRUGO | S_IWUSR,
428 return show_pwm(dev, buf, offset - 1); \ 413 show_pwm, set_pwm, 0);
429} \ 414static SENSOR_DEVICE_ATTR(auto_fan2_min_pwm, S_IRUGO | S_IWUSR,
430static ssize_t set_pwm_##offset (struct device *dev, struct device_attribute *attr, \ 415 show_pwm, set_pwm, 1);
431 const char *buf, size_t count) \
432{ \
433 return set_pwm(dev, buf, count, offset - 1); \
434} \
435static DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
436 show_pwm_##offset, set_pwm_##offset)
437
438pwm_reg(1);
439pwm_reg(2);
440 416
441/* Fans */ 417/* Fans */
442 418
@@ -471,7 +447,7 @@ static int trust_fan_readings(struct adm1031_data *data, int chan)
471 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[0]) 447 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[0])
472 || data->temp[1] >= 448 || data->temp[1] >=
473 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[1]) 449 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[1])
474 || (data->chip_type == adm1031 450 || (data->chip_type == adm1031
475 && data->temp[2] >= 451 && data->temp[2] >=
476 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[2])); 452 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[2]));
477 break; 453 break;
@@ -483,8 +459,10 @@ static int trust_fan_readings(struct adm1031_data *data, int chan)
483} 459}
484 460
485 461
486static ssize_t show_fan(struct device *dev, char *buf, int nr) 462static ssize_t show_fan(struct device *dev,
463 struct device_attribute *attr, char *buf)
487{ 464{
465 int nr = to_sensor_dev_attr(attr)->index;
488 struct adm1031_data *data = adm1031_update_device(dev); 466 struct adm1031_data *data = adm1031_update_device(dev);
489 int value; 467 int value;
490 468
@@ -493,28 +471,33 @@ static ssize_t show_fan(struct device *dev, char *buf, int nr)
493 return sprintf(buf, "%d\n", value); 471 return sprintf(buf, "%d\n", value);
494} 472}
495 473
496static ssize_t show_fan_div(struct device *dev, char *buf, int nr) 474static ssize_t show_fan_div(struct device *dev,
475 struct device_attribute *attr, char *buf)
497{ 476{
477 int nr = to_sensor_dev_attr(attr)->index;
498 struct adm1031_data *data = adm1031_update_device(dev); 478 struct adm1031_data *data = adm1031_update_device(dev);
499 return sprintf(buf, "%d\n", FAN_DIV_FROM_REG(data->fan_div[nr])); 479 return sprintf(buf, "%d\n", FAN_DIV_FROM_REG(data->fan_div[nr]));
500} 480}
501static ssize_t show_fan_min(struct device *dev, char *buf, int nr) 481static ssize_t show_fan_min(struct device *dev,
482 struct device_attribute *attr, char *buf)
502{ 483{
484 int nr = to_sensor_dev_attr(attr)->index;
503 struct adm1031_data *data = adm1031_update_device(dev); 485 struct adm1031_data *data = adm1031_update_device(dev);
504 return sprintf(buf, "%d\n", 486 return sprintf(buf, "%d\n",
505 FAN_FROM_REG(data->fan_min[nr], 487 FAN_FROM_REG(data->fan_min[nr],
506 FAN_DIV_FROM_REG(data->fan_div[nr]))); 488 FAN_DIV_FROM_REG(data->fan_div[nr])));
507} 489}
508static ssize_t 490static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
509set_fan_min(struct device *dev, const char *buf, size_t count, int nr) 491 const char *buf, size_t count)
510{ 492{
511 struct i2c_client *client = to_i2c_client(dev); 493 struct i2c_client *client = to_i2c_client(dev);
512 struct adm1031_data *data = i2c_get_clientdata(client); 494 struct adm1031_data *data = i2c_get_clientdata(client);
495 int nr = to_sensor_dev_attr(attr)->index;
513 int val = simple_strtol(buf, NULL, 10); 496 int val = simple_strtol(buf, NULL, 10);
514 497
515 mutex_lock(&data->update_lock); 498 mutex_lock(&data->update_lock);
516 if (val) { 499 if (val) {
517 data->fan_min[nr] = 500 data->fan_min[nr] =
518 FAN_TO_REG(val, FAN_DIV_FROM_REG(data->fan_div[nr])); 501 FAN_TO_REG(val, FAN_DIV_FROM_REG(data->fan_div[nr]));
519 } else { 502 } else {
520 data->fan_min[nr] = 0xff; 503 data->fan_min[nr] = 0xff;
@@ -523,11 +506,12 @@ set_fan_min(struct device *dev, const char *buf, size_t count, int nr)
523 mutex_unlock(&data->update_lock); 506 mutex_unlock(&data->update_lock);
524 return count; 507 return count;
525} 508}
526static ssize_t 509static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
527set_fan_div(struct device *dev, const char *buf, size_t count, int nr) 510 const char *buf, size_t count)
528{ 511{
529 struct i2c_client *client = to_i2c_client(dev); 512 struct i2c_client *client = to_i2c_client(dev);
530 struct adm1031_data *data = i2c_get_clientdata(client); 513 struct adm1031_data *data = i2c_get_clientdata(client);
514 int nr = to_sensor_dev_attr(attr)->index;
531 int val = simple_strtol(buf, NULL, 10); 515 int val = simple_strtol(buf, NULL, 10);
532 u8 tmp; 516 u8 tmp;
533 int old_div; 517 int old_div;
@@ -535,68 +519,53 @@ set_fan_div(struct device *dev, const char *buf, size_t count, int nr)
535 519
536 tmp = val == 8 ? 0xc0 : 520 tmp = val == 8 ? 0xc0 :
537 val == 4 ? 0x80 : 521 val == 4 ? 0x80 :
538 val == 2 ? 0x40 : 522 val == 2 ? 0x40 :
539 val == 1 ? 0x00 : 523 val == 1 ? 0x00 :
540 0xff; 524 0xff;
541 if (tmp == 0xff) 525 if (tmp == 0xff)
542 return -EINVAL; 526 return -EINVAL;
543 527
544 mutex_lock(&data->update_lock); 528 mutex_lock(&data->update_lock);
529 /* Get fresh readings */
530 data->fan_div[nr] = adm1031_read_value(client,
531 ADM1031_REG_FAN_DIV(nr));
532 data->fan_min[nr] = adm1031_read_value(client,
533 ADM1031_REG_FAN_MIN(nr));
534
535 /* Write the new clock divider and fan min */
545 old_div = FAN_DIV_FROM_REG(data->fan_div[nr]); 536 old_div = FAN_DIV_FROM_REG(data->fan_div[nr]);
546 data->fan_div[nr] = (tmp & 0xC0) | (0x3f & data->fan_div[nr]); 537 data->fan_div[nr] = tmp | (0x3f & data->fan_div[nr]);
547 new_min = data->fan_min[nr] * old_div / 538 new_min = data->fan_min[nr] * old_div / val;
548 FAN_DIV_FROM_REG(data->fan_div[nr]);
549 data->fan_min[nr] = new_min > 0xff ? 0xff : new_min; 539 data->fan_min[nr] = new_min > 0xff ? 0xff : new_min;
550 data->fan[nr] = data->fan[nr] * old_div /
551 FAN_DIV_FROM_REG(data->fan_div[nr]);
552 540
553 adm1031_write_value(client, ADM1031_REG_FAN_DIV(nr), 541 adm1031_write_value(client, ADM1031_REG_FAN_DIV(nr),
554 data->fan_div[nr]); 542 data->fan_div[nr]);
555 adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr), 543 adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr),
556 data->fan_min[nr]); 544 data->fan_min[nr]);
545
546 /* Invalidate the cache: fan speed is no longer valid */
547 data->valid = 0;
557 mutex_unlock(&data->update_lock); 548 mutex_unlock(&data->update_lock);
558 return count; 549 return count;
559} 550}
560 551
561#define fan_offset(offset) \ 552#define fan_offset(offset) \
562static ssize_t show_fan_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 553static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
563{ \ 554 show_fan, NULL, offset - 1); \
564 return show_fan(dev, buf, offset - 1); \ 555static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
565} \ 556 show_fan_min, set_fan_min, offset - 1); \
566static ssize_t show_fan_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ 557static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
567{ \ 558 show_fan_div, set_fan_div, offset - 1)
568 return show_fan_min(dev, buf, offset - 1); \
569} \
570static ssize_t show_fan_##offset##_div (struct device *dev, struct device_attribute *attr, char *buf) \
571{ \
572 return show_fan_div(dev, buf, offset - 1); \
573} \
574static ssize_t set_fan_##offset##_min (struct device *dev, struct device_attribute *attr, \
575 const char *buf, size_t count) \
576{ \
577 return set_fan_min(dev, buf, count, offset - 1); \
578} \
579static ssize_t set_fan_##offset##_div (struct device *dev, struct device_attribute *attr, \
580 const char *buf, size_t count) \
581{ \
582 return set_fan_div(dev, buf, count, offset - 1); \
583} \
584static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, \
585 NULL); \
586static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
587 show_fan_##offset##_min, set_fan_##offset##_min); \
588static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
589 show_fan_##offset##_div, set_fan_##offset##_div); \
590static DEVICE_ATTR(auto_fan##offset##_min_pwm, S_IRUGO | S_IWUSR, \
591 show_pwm_##offset, set_pwm_##offset)
592 559
593fan_offset(1); 560fan_offset(1);
594fan_offset(2); 561fan_offset(2);
595 562
596 563
597/* Temps */ 564/* Temps */
598static ssize_t show_temp(struct device *dev, char *buf, int nr) 565static ssize_t show_temp(struct device *dev,
566 struct device_attribute *attr, char *buf)
599{ 567{
568 int nr = to_sensor_dev_attr(attr)->index;
600 struct adm1031_data *data = adm1031_update_device(dev); 569 struct adm1031_data *data = adm1031_update_device(dev);
601 int ext; 570 int ext;
602 ext = nr == 0 ? 571 ext = nr == 0 ?
@@ -604,26 +573,33 @@ static ssize_t show_temp(struct device *dev, char *buf, int nr)
604 (((data->ext_temp[nr] >> ((nr - 1) * 3)) & 7)); 573 (((data->ext_temp[nr] >> ((nr - 1) * 3)) & 7));
605 return sprintf(buf, "%d\n", TEMP_FROM_REG_EXT(data->temp[nr], ext)); 574 return sprintf(buf, "%d\n", TEMP_FROM_REG_EXT(data->temp[nr], ext));
606} 575}
607static ssize_t show_temp_min(struct device *dev, char *buf, int nr) 576static ssize_t show_temp_min(struct device *dev,
577 struct device_attribute *attr, char *buf)
608{ 578{
579 int nr = to_sensor_dev_attr(attr)->index;
609 struct adm1031_data *data = adm1031_update_device(dev); 580 struct adm1031_data *data = adm1031_update_device(dev);
610 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr])); 581 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr]));
611} 582}
612static ssize_t show_temp_max(struct device *dev, char *buf, int nr) 583static ssize_t show_temp_max(struct device *dev,
584 struct device_attribute *attr, char *buf)
613{ 585{
586 int nr = to_sensor_dev_attr(attr)->index;
614 struct adm1031_data *data = adm1031_update_device(dev); 587 struct adm1031_data *data = adm1031_update_device(dev);
615 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr])); 588 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr]));
616} 589}
617static ssize_t show_temp_crit(struct device *dev, char *buf, int nr) 590static ssize_t show_temp_crit(struct device *dev,
591 struct device_attribute *attr, char *buf)
618{ 592{
593 int nr = to_sensor_dev_attr(attr)->index;
619 struct adm1031_data *data = adm1031_update_device(dev); 594 struct adm1031_data *data = adm1031_update_device(dev);
620 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[nr])); 595 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[nr]));
621} 596}
622static ssize_t 597static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
623set_temp_min(struct device *dev, const char *buf, size_t count, int nr) 598 const char *buf, size_t count)
624{ 599{
625 struct i2c_client *client = to_i2c_client(dev); 600 struct i2c_client *client = to_i2c_client(dev);
626 struct adm1031_data *data = i2c_get_clientdata(client); 601 struct adm1031_data *data = i2c_get_clientdata(client);
602 int nr = to_sensor_dev_attr(attr)->index;
627 int val; 603 int val;
628 604
629 val = simple_strtol(buf, NULL, 10); 605 val = simple_strtol(buf, NULL, 10);
@@ -635,11 +611,12 @@ set_temp_min(struct device *dev, const char *buf, size_t count, int nr)
635 mutex_unlock(&data->update_lock); 611 mutex_unlock(&data->update_lock);
636 return count; 612 return count;
637} 613}
638static ssize_t 614static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
639set_temp_max(struct device *dev, const char *buf, size_t count, int nr) 615 const char *buf, size_t count)
640{ 616{
641 struct i2c_client *client = to_i2c_client(dev); 617 struct i2c_client *client = to_i2c_client(dev);
642 struct adm1031_data *data = i2c_get_clientdata(client); 618 struct adm1031_data *data = i2c_get_clientdata(client);
619 int nr = to_sensor_dev_attr(attr)->index;
643 int val; 620 int val;
644 621
645 val = simple_strtol(buf, NULL, 10); 622 val = simple_strtol(buf, NULL, 10);
@@ -651,11 +628,12 @@ set_temp_max(struct device *dev, const char *buf, size_t count, int nr)
651 mutex_unlock(&data->update_lock); 628 mutex_unlock(&data->update_lock);
652 return count; 629 return count;
653} 630}
654static ssize_t 631static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
655set_temp_crit(struct device *dev, const char *buf, size_t count, int nr) 632 const char *buf, size_t count)
656{ 633{
657 struct i2c_client *client = to_i2c_client(dev); 634 struct i2c_client *client = to_i2c_client(dev);
658 struct adm1031_data *data = i2c_get_clientdata(client); 635 struct adm1031_data *data = i2c_get_clientdata(client);
636 int nr = to_sensor_dev_attr(attr)->index;
659 int val; 637 int val;
660 638
661 val = simple_strtol(buf, NULL, 10); 639 val = simple_strtol(buf, NULL, 10);
@@ -668,46 +646,15 @@ set_temp_crit(struct device *dev, const char *buf, size_t count, int nr)
668 return count; 646 return count;
669} 647}
670 648
671#define temp_reg(offset) \ 649#define temp_reg(offset) \
672static ssize_t show_temp_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 650static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
673{ \ 651 show_temp, NULL, offset - 1); \
674 return show_temp(dev, buf, offset - 1); \ 652static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
675} \ 653 show_temp_min, set_temp_min, offset - 1); \
676static ssize_t show_temp_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ 654static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
677{ \ 655 show_temp_max, set_temp_max, offset - 1); \
678 return show_temp_min(dev, buf, offset - 1); \ 656static SENSOR_DEVICE_ATTR(temp##offset##_crit, S_IRUGO | S_IWUSR, \
679} \ 657 show_temp_crit, set_temp_crit, offset - 1)
680static ssize_t show_temp_##offset##_max (struct device *dev, struct device_attribute *attr, char *buf) \
681{ \
682 return show_temp_max(dev, buf, offset - 1); \
683} \
684static ssize_t show_temp_##offset##_crit (struct device *dev, struct device_attribute *attr, char *buf) \
685{ \
686 return show_temp_crit(dev, buf, offset - 1); \
687} \
688static ssize_t set_temp_##offset##_min (struct device *dev, struct device_attribute *attr, \
689 const char *buf, size_t count) \
690{ \
691 return set_temp_min(dev, buf, count, offset - 1); \
692} \
693static ssize_t set_temp_##offset##_max (struct device *dev, struct device_attribute *attr, \
694 const char *buf, size_t count) \
695{ \
696 return set_temp_max(dev, buf, count, offset - 1); \
697} \
698static ssize_t set_temp_##offset##_crit (struct device *dev, struct device_attribute *attr, \
699 const char *buf, size_t count) \
700{ \
701 return set_temp_crit(dev, buf, count, offset - 1); \
702} \
703static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, \
704 NULL); \
705static DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
706 show_temp_##offset##_min, set_temp_##offset##_min); \
707static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
708 show_temp_##offset##_max, set_temp_##offset##_max); \
709static DEVICE_ATTR(temp##offset##_crit, S_IRUGO | S_IWUSR, \
710 show_temp_##offset##_crit, set_temp_##offset##_crit)
711 658
712temp_reg(1); 659temp_reg(1);
713temp_reg(2); 660temp_reg(2);
@@ -722,6 +669,29 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, ch
722 669
723static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 670static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
724 671
672static ssize_t show_alarm(struct device *dev,
673 struct device_attribute *attr, char *buf)
674{
675 int bitnr = to_sensor_dev_attr(attr)->index;
676 struct adm1031_data *data = adm1031_update_device(dev);
677 return sprintf(buf, "%d\n", (data->alarm >> bitnr) & 1);
678}
679
680static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0);
681static SENSOR_DEVICE_ATTR(fan1_fault, S_IRUGO, show_alarm, NULL, 1);
682static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 2);
683static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3);
684static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 4);
685static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 5);
686static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6);
687static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 7);
688static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 8);
689static SENSOR_DEVICE_ATTR(fan2_fault, S_IRUGO, show_alarm, NULL, 9);
690static SENSOR_DEVICE_ATTR(temp3_max_alarm, S_IRUGO, show_alarm, NULL, 10);
691static SENSOR_DEVICE_ATTR(temp3_min_alarm, S_IRUGO, show_alarm, NULL, 11);
692static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 12);
693static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 13);
694static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 14);
725 695
726static int adm1031_attach_adapter(struct i2c_adapter *adapter) 696static int adm1031_attach_adapter(struct i2c_adapter *adapter)
727{ 697{
@@ -731,29 +701,38 @@ static int adm1031_attach_adapter(struct i2c_adapter *adapter)
731} 701}
732 702
733static struct attribute *adm1031_attributes[] = { 703static struct attribute *adm1031_attributes[] = {
734 &dev_attr_fan1_input.attr, 704 &sensor_dev_attr_fan1_input.dev_attr.attr,
735 &dev_attr_fan1_div.attr, 705 &sensor_dev_attr_fan1_div.dev_attr.attr,
736 &dev_attr_fan1_min.attr, 706 &sensor_dev_attr_fan1_min.dev_attr.attr,
737 &dev_attr_pwm1.attr, 707 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
738 &dev_attr_auto_fan1_channel.attr, 708 &sensor_dev_attr_fan1_fault.dev_attr.attr,
739 &dev_attr_temp1_input.attr, 709 &sensor_dev_attr_pwm1.dev_attr.attr,
740 &dev_attr_temp1_min.attr, 710 &sensor_dev_attr_auto_fan1_channel.dev_attr.attr,
741 &dev_attr_temp1_max.attr, 711 &sensor_dev_attr_temp1_input.dev_attr.attr,
742 &dev_attr_temp1_crit.attr, 712 &sensor_dev_attr_temp1_min.dev_attr.attr,
743 &dev_attr_temp2_input.attr, 713 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
744 &dev_attr_temp2_min.attr, 714 &sensor_dev_attr_temp1_max.dev_attr.attr,
745 &dev_attr_temp2_max.attr, 715 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
746 &dev_attr_temp2_crit.attr, 716 &sensor_dev_attr_temp1_crit.dev_attr.attr,
747 717 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
748 &dev_attr_auto_temp1_off.attr, 718 &sensor_dev_attr_temp2_input.dev_attr.attr,
749 &dev_attr_auto_temp1_min.attr, 719 &sensor_dev_attr_temp2_min.dev_attr.attr,
750 &dev_attr_auto_temp1_max.attr, 720 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
751 721 &sensor_dev_attr_temp2_max.dev_attr.attr,
752 &dev_attr_auto_temp2_off.attr, 722 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
753 &dev_attr_auto_temp2_min.attr, 723 &sensor_dev_attr_temp2_crit.dev_attr.attr,
754 &dev_attr_auto_temp2_max.attr, 724 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
755 725 &sensor_dev_attr_temp2_fault.dev_attr.attr,
756 &dev_attr_auto_fan1_min_pwm.attr, 726
727 &sensor_dev_attr_auto_temp1_off.dev_attr.attr,
728 &sensor_dev_attr_auto_temp1_min.dev_attr.attr,
729 &sensor_dev_attr_auto_temp1_max.dev_attr.attr,
730
731 &sensor_dev_attr_auto_temp2_off.dev_attr.attr,
732 &sensor_dev_attr_auto_temp2_min.dev_attr.attr,
733 &sensor_dev_attr_auto_temp2_max.dev_attr.attr,
734
735 &sensor_dev_attr_auto_fan1_min_pwm.dev_attr.attr,
757 736
758 &dev_attr_alarms.attr, 737 &dev_attr_alarms.attr,
759 738
@@ -765,19 +744,25 @@ static const struct attribute_group adm1031_group = {
765}; 744};
766 745
767static struct attribute *adm1031_attributes_opt[] = { 746static struct attribute *adm1031_attributes_opt[] = {
768 &dev_attr_fan2_input.attr, 747 &sensor_dev_attr_fan2_input.dev_attr.attr,
769 &dev_attr_fan2_div.attr, 748 &sensor_dev_attr_fan2_div.dev_attr.attr,
770 &dev_attr_fan2_min.attr, 749 &sensor_dev_attr_fan2_min.dev_attr.attr,
771 &dev_attr_pwm2.attr, 750 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
772 &dev_attr_auto_fan2_channel.attr, 751 &sensor_dev_attr_fan2_fault.dev_attr.attr,
773 &dev_attr_temp3_input.attr, 752 &sensor_dev_attr_pwm2.dev_attr.attr,
774 &dev_attr_temp3_min.attr, 753 &sensor_dev_attr_auto_fan2_channel.dev_attr.attr,
775 &dev_attr_temp3_max.attr, 754 &sensor_dev_attr_temp3_input.dev_attr.attr,
776 &dev_attr_temp3_crit.attr, 755 &sensor_dev_attr_temp3_min.dev_attr.attr,
777 &dev_attr_auto_temp3_off.attr, 756 &sensor_dev_attr_temp3_min_alarm.dev_attr.attr,
778 &dev_attr_auto_temp3_min.attr, 757 &sensor_dev_attr_temp3_max.dev_attr.attr,
779 &dev_attr_auto_temp3_max.attr, 758 &sensor_dev_attr_temp3_max_alarm.dev_attr.attr,
780 &dev_attr_auto_fan2_min_pwm.attr, 759 &sensor_dev_attr_temp3_crit.dev_attr.attr,
760 &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr,
761 &sensor_dev_attr_temp3_fault.dev_attr.attr,
762 &sensor_dev_attr_auto_temp3_off.dev_attr.attr,
763 &sensor_dev_attr_auto_temp3_min.dev_attr.attr,
764 &sensor_dev_attr_auto_temp3_max.dev_attr.attr,
765 &sensor_dev_attr_auto_fan2_min_pwm.dev_attr.attr,
781 NULL 766 NULL
782}; 767};
783 768
@@ -788,7 +773,7 @@ static const struct attribute_group adm1031_group_opt = {
788/* This function is called by i2c_probe */ 773/* This function is called by i2c_probe */
789static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind) 774static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
790{ 775{
791 struct i2c_client *new_client; 776 struct i2c_client *client;
792 struct adm1031_data *data; 777 struct adm1031_data *data;
793 int err = 0; 778 int err = 0;
794 const char *name = ""; 779 const char *name = "";
@@ -801,17 +786,16 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
801 goto exit; 786 goto exit;
802 } 787 }
803 788
804 new_client = &data->client; 789 client = &data->client;
805 i2c_set_clientdata(new_client, data); 790 i2c_set_clientdata(client, data);
806 new_client->addr = address; 791 client->addr = address;
807 new_client->adapter = adapter; 792 client->adapter = adapter;
808 new_client->driver = &adm1031_driver; 793 client->driver = &adm1031_driver;
809 new_client->flags = 0;
810 794
811 if (kind < 0) { 795 if (kind < 0) {
812 int id, co; 796 int id, co;
813 id = i2c_smbus_read_byte_data(new_client, 0x3d); 797 id = i2c_smbus_read_byte_data(client, 0x3d);
814 co = i2c_smbus_read_byte_data(new_client, 0x3e); 798 co = i2c_smbus_read_byte_data(client, 0x3e);
815 799
816 if (!((id == 0x31 || id == 0x30) && co == 0x41)) 800 if (!((id == 0x31 || id == 0x30) && co == 0x41))
817 goto exit_free; 801 goto exit_free;
@@ -832,28 +816,27 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
832 } 816 }
833 data->chip_type = kind; 817 data->chip_type = kind;
834 818
835 strlcpy(new_client->name, name, I2C_NAME_SIZE); 819 strlcpy(client->name, name, I2C_NAME_SIZE);
836 data->valid = 0;
837 mutex_init(&data->update_lock); 820 mutex_init(&data->update_lock);
838 821
839 /* Tell the I2C layer a new client has arrived */ 822 /* Tell the I2C layer a new client has arrived */
840 if ((err = i2c_attach_client(new_client))) 823 if ((err = i2c_attach_client(client)))
841 goto exit_free; 824 goto exit_free;
842 825
843 /* Initialize the ADM1031 chip */ 826 /* Initialize the ADM1031 chip */
844 adm1031_init_client(new_client); 827 adm1031_init_client(client);
845 828
846 /* Register sysfs hooks */ 829 /* Register sysfs hooks */
847 if ((err = sysfs_create_group(&new_client->dev.kobj, &adm1031_group))) 830 if ((err = sysfs_create_group(&client->dev.kobj, &adm1031_group)))
848 goto exit_detach; 831 goto exit_detach;
849 832
850 if (kind == adm1031) { 833 if (kind == adm1031) {
851 if ((err = sysfs_create_group(&new_client->dev.kobj, 834 if ((err = sysfs_create_group(&client->dev.kobj,
852 &adm1031_group_opt))) 835 &adm1031_group_opt)))
853 goto exit_remove; 836 goto exit_remove;
854 } 837 }
855 838
856 data->hwmon_dev = hwmon_device_register(&new_client->dev); 839 data->hwmon_dev = hwmon_device_register(&client->dev);
857 if (IS_ERR(data->hwmon_dev)) { 840 if (IS_ERR(data->hwmon_dev)) {
858 err = PTR_ERR(data->hwmon_dev); 841 err = PTR_ERR(data->hwmon_dev);
859 goto exit_remove; 842 goto exit_remove;
@@ -862,10 +845,10 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
862 return 0; 845 return 0;
863 846
864exit_remove: 847exit_remove:
865 sysfs_remove_group(&new_client->dev.kobj, &adm1031_group); 848 sysfs_remove_group(&client->dev.kobj, &adm1031_group);
866 sysfs_remove_group(&new_client->dev.kobj, &adm1031_group_opt); 849 sysfs_remove_group(&client->dev.kobj, &adm1031_group_opt);
867exit_detach: 850exit_detach:
868 i2c_detach_client(new_client); 851 i2c_detach_client(client);
869exit_free: 852exit_free:
870 kfree(data); 853 kfree(data);
871exit: 854exit:
@@ -897,7 +880,7 @@ static void adm1031_init_client(struct i2c_client *client)
897 if (data->chip_type == adm1031) { 880 if (data->chip_type == adm1031) {
898 mask |= (ADM1031_CONF2_PWM2_ENABLE | 881 mask |= (ADM1031_CONF2_PWM2_ENABLE |
899 ADM1031_CONF2_TACH2_ENABLE); 882 ADM1031_CONF2_TACH2_ENABLE);
900 } 883 }
901 /* Initialize the ADM1031 chip (enables fan speed reading ) */ 884 /* Initialize the ADM1031 chip (enables fan speed reading ) */
902 read_val = adm1031_read_value(client, ADM1031_REG_CONF2); 885 read_val = adm1031_read_value(client, ADM1031_REG_CONF2);
903 if ((read_val | mask) != read_val) { 886 if ((read_val | mask) != read_val) {
@@ -976,7 +959,7 @@ static struct adm1031_data *adm1031_update_device(struct device *dev)
976 if (data->chip_type == adm1030) { 959 if (data->chip_type == adm1030) {
977 data->alarm &= 0xc0ff; 960 data->alarm &= 0xc0ff;
978 } 961 }
979 962
980 for (chan=0; chan<(data->chip_type == adm1030 ? 1 : 2); chan++) { 963 for (chan=0; chan<(data->chip_type == adm1030 ? 1 : 2); chan++) {
981 data->fan_div[chan] = 964 data->fan_div[chan] =
982 adm1031_read_value(client, ADM1031_REG_FAN_DIV(chan)); 965 adm1031_read_value(client, ADM1031_REG_FAN_DIV(chan));
@@ -985,7 +968,7 @@ static struct adm1031_data *adm1031_update_device(struct device *dev)
985 data->fan[chan] = 968 data->fan[chan] =
986 adm1031_read_value(client, ADM1031_REG_FAN_SPEED(chan)); 969 adm1031_read_value(client, ADM1031_REG_FAN_SPEED(chan));
987 data->pwm[chan] = 970 data->pwm[chan] =
988 0xf & (adm1031_read_value(client, ADM1031_REG_PWM) >> 971 0xf & (adm1031_read_value(client, ADM1031_REG_PWM) >>
989 (4*chan)); 972 (4*chan));
990 } 973 }
991 data->last_updated = jiffies; 974 data->last_updated = jiffies;