diff options
author | Guenter Roeck <linux@roeck-us.net> | 2012-01-14 15:51:15 -0500 |
---|---|---|
committer | Guenter Roeck <guenter.roeck@ericsson.com> | 2012-03-18 21:27:19 -0400 |
commit | 86aa3e22106be3d6338113ff5acd7a87c40056c4 (patch) | |
tree | 03ff36e6d527563324babb33f72ee28191e9b630 /drivers/hwmon/adm1026.c | |
parent | 21d2a8f17b7533d84acf659d4a3757115fad0356 (diff) |
hwmon: (adm1026) Fix checkpatch issues
Fixed:
ERROR: do not use assignment in if condition
ERROR: space prohibited after that '~' (ctx:WxW)
ERROR: space required after that ';' (ctx:VxO)
ERROR: space required after that ';' (ctx:VxV)
ERROR: spaces required around that '<' (ctx:VxV)
ERROR: spaces required around that '==' (ctx:VxV)
ERROR: spaces required around that '=' (ctx:VxV)
ERROR: spaces required around that ':' (ctx:VxV)
WARNING: braces {} are not necessary for any arm of this statement
WARNING: braces {} are not necessary for single statement blocks
WARNING: line over 80 characters
WARNING: simple_strtol is obsolete, use kstrtol instead
Modify multi-line comments to follow Documentation/CodingStyle.
Not fixed:
ERROR: Macros with multiple statements should be enclosed in a do - while loop
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/adm1026.c')
-rw-r--r-- | drivers/hwmon/adm1026.c | 491 |
1 files changed, 313 insertions, 178 deletions
diff --git a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c index be1708373ec5..1003219b9f90 100644 --- a/drivers/hwmon/adm1026.c +++ b/drivers/hwmon/adm1026.c | |||
@@ -1,27 +1,27 @@ | |||
1 | /* | 1 | /* |
2 | adm1026.c - Part of lm_sensors, Linux kernel modules for hardware | 2 | * adm1026.c - Part of lm_sensors, Linux kernel modules for hardware |
3 | monitoring | 3 | * monitoring |
4 | Copyright (C) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com> | 4 | * Copyright (C) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com> |
5 | Copyright (C) 2004 Justin Thiessen <jthiessen@penguincomputing.com> | 5 | * Copyright (C) 2004 Justin Thiessen <jthiessen@penguincomputing.com> |
6 | 6 | * | |
7 | Chip details at: | 7 | * Chip details at: |
8 | 8 | * | |
9 | <http://www.onsemi.com/PowerSolutions/product.do?id=ADM1026> | 9 | * <http://www.onsemi.com/PowerSolutions/product.do?id=ADM1026> |
10 | 10 | * | |
11 | This program is free software; you can redistribute it and/or modify | 11 | * This program is free software; you can redistribute it and/or modify |
12 | it under the terms of the GNU General Public License as published by | 12 | * it under the terms of the GNU General Public License as published by |
13 | the Free Software Foundation; either version 2 of the License, or | 13 | * the Free Software Foundation; either version 2 of the License, or |
14 | (at your option) any later version. | 14 | * (at your option) any later version. |
15 | 15 | * | |
16 | This program is distributed in the hope that it will be useful, | 16 | * This program is distributed in the hope that it will be useful, |
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 | GNU General Public License for more details. | 19 | * GNU General Public License for more details. |
20 | 20 | * | |
21 | You should have received a copy of the GNU General Public License | 21 | * You should have received a copy of the GNU General Public License |
22 | along with this program; if not, write to the Free Software | 22 | * along with this program; if not, write to the Free Software |
23 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include <linux/module.h> | 26 | #include <linux/module.h> |
27 | #include <linux/init.h> | 27 | #include <linux/init.h> |
@@ -90,7 +90,8 @@ MODULE_PARM_DESC(gpio_fan, "List of GPIO pins (0-7) to program as fan tachs"); | |||
90 | #define E2CFG_ROM 0x08 | 90 | #define E2CFG_ROM 0x08 |
91 | #define E2CFG_CLK_EXT 0x80 | 91 | #define E2CFG_CLK_EXT 0x80 |
92 | 92 | ||
93 | /* There are 10 general analog inputs and 7 dedicated inputs | 93 | /* |
94 | * There are 10 general analog inputs and 7 dedicated inputs | ||
94 | * They are: | 95 | * They are: |
95 | * 0 - 9 = AIN0 - AIN9 | 96 | * 0 - 9 = AIN0 - AIN9 |
96 | * 10 = Vbat | 97 | * 10 = Vbat |
@@ -117,7 +118,8 @@ static u16 ADM1026_REG_IN_MAX[] = { | |||
117 | 0x43, 0x44, 0x45, 0x46, 0x47 | 118 | 0x43, 0x44, 0x45, 0x46, 0x47 |
118 | }; | 119 | }; |
119 | 120 | ||
120 | /* Temperatures are: | 121 | /* |
122 | * Temperatures are: | ||
121 | * 0 - Internal | 123 | * 0 - Internal |
122 | * 1 - External 1 | 124 | * 1 - External 1 |
123 | * 2 - External 2 | 125 | * 2 - External 2 |
@@ -170,12 +172,14 @@ static u16 ADM1026_REG_TEMP_OFFSET[] = { 0x1e, 0x6e, 0x6f }; | |||
170 | #define ADM1026_FAN_CONTROL_TEMP_RANGE 20 | 172 | #define ADM1026_FAN_CONTROL_TEMP_RANGE 20 |
171 | #define ADM1026_PWM_MAX 255 | 173 | #define ADM1026_PWM_MAX 255 |
172 | 174 | ||
173 | /* Conversions. Rounding and limit checking is only done on the TO_REG | 175 | /* |
176 | * Conversions. Rounding and limit checking is only done on the TO_REG | ||
174 | * variants. Note that you should be a bit careful with which arguments | 177 | * variants. Note that you should be a bit careful with which arguments |
175 | * these macros are called: arguments may be evaluated more than once. | 178 | * these macros are called: arguments may be evaluated more than once. |
176 | */ | 179 | */ |
177 | 180 | ||
178 | /* IN are scaled according to built-in resistors. These are the | 181 | /* |
182 | * IN are scaled according to built-in resistors. These are the | ||
179 | * voltages corresponding to 3/4 of full scale (192 or 0xc0) | 183 | * voltages corresponding to 3/4 of full scale (192 or 0xc0) |
180 | * NOTE: The -12V input needs an additional factor to account | 184 | * NOTE: The -12V input needs an additional factor to account |
181 | * for the Vref pullup resistor. | 185 | * for the Vref pullup resistor. |
@@ -197,23 +201,25 @@ static int adm1026_scaling[] = { /* .001 Volts */ | |||
197 | 0, 255)) | 201 | 0, 255)) |
198 | #define INS_FROM_REG(n, val) (SCALE(val, 192, adm1026_scaling[n])) | 202 | #define INS_FROM_REG(n, val) (SCALE(val, 192, adm1026_scaling[n])) |
199 | 203 | ||
200 | /* FAN speed is measured using 22.5kHz clock and counts for 2 pulses | 204 | /* |
205 | * FAN speed is measured using 22.5kHz clock and counts for 2 pulses | ||
201 | * and we assume a 2 pulse-per-rev fan tach signal | 206 | * and we assume a 2 pulse-per-rev fan tach signal |
202 | * 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) == 1350000 | 207 | * 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) == 1350000 |
203 | */ | 208 | */ |
204 | #define FAN_TO_REG(val, div) ((val) <= 0 ? 0xff : \ | 209 | #define FAN_TO_REG(val, div) ((val) <= 0 ? 0xff : \ |
205 | SENSORS_LIMIT(1350000/((val)*(div)), 1, 254)) | 210 | SENSORS_LIMIT(1350000 / ((val) * (div)), \ |
206 | #define FAN_FROM_REG(val, div) ((val) == 0 ? -1:(val) == 0xff ? 0 : \ | 211 | 1, 254)) |
207 | 1350000/((val)*(div))) | 212 | #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 0xff ? 0 : \ |
208 | #define DIV_FROM_REG(val) (1<<(val)) | 213 | 1350000 / ((val) * (div))) |
214 | #define DIV_FROM_REG(val) (1 << (val)) | ||
209 | #define DIV_TO_REG(val) ((val) >= 8 ? 3 : (val) >= 4 ? 2 : (val) >= 2 ? 1 : 0) | 215 | #define DIV_TO_REG(val) ((val) >= 8 ? 3 : (val) >= 4 ? 2 : (val) >= 2 ? 1 : 0) |
210 | 216 | ||
211 | /* Temperature is reported in 1 degC increments */ | 217 | /* Temperature is reported in 1 degC increments */ |
212 | #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\ | 218 | #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) + ((val) < 0 ? -500 : 500)) \ |
213 | -127, 127)) | 219 | / 1000, -127, 127)) |
214 | #define TEMP_FROM_REG(val) ((val) * 1000) | 220 | #define TEMP_FROM_REG(val) ((val) * 1000) |
215 | #define OFFSET_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\ | 221 | #define OFFSET_TO_REG(val) (SENSORS_LIMIT(((val) + ((val) < 0 ? -500 : 500)) \ |
216 | -127, 127)) | 222 | / 1000, -127, 127)) |
217 | #define OFFSET_FROM_REG(val) ((val) * 1000) | 223 | #define OFFSET_FROM_REG(val) ((val) * 1000) |
218 | 224 | ||
219 | #define PWM_TO_REG(val) (SENSORS_LIMIT(val, 0, 255)) | 225 | #define PWM_TO_REG(val) (SENSORS_LIMIT(val, 0, 255)) |
@@ -222,14 +228,16 @@ static int adm1026_scaling[] = { /* .001 Volts */ | |||
222 | #define PWM_MIN_TO_REG(val) ((val) & 0xf0) | 228 | #define PWM_MIN_TO_REG(val) ((val) & 0xf0) |
223 | #define PWM_MIN_FROM_REG(val) (((val) & 0xf0) + ((val) >> 4)) | 229 | #define PWM_MIN_FROM_REG(val) (((val) & 0xf0) + ((val) >> 4)) |
224 | 230 | ||
225 | /* Analog output is a voltage, and scaled to millivolts. The datasheet | 231 | /* |
232 | * Analog output is a voltage, and scaled to millivolts. The datasheet | ||
226 | * indicates that the DAC could be used to drive the fans, but in our | 233 | * indicates that the DAC could be used to drive the fans, but in our |
227 | * example board (Arima HDAMA) it isn't connected to the fans at all. | 234 | * example board (Arima HDAMA) it isn't connected to the fans at all. |
228 | */ | 235 | */ |
229 | #define DAC_TO_REG(val) (SENSORS_LIMIT(((((val)*255)+500)/2500), 0, 255)) | 236 | #define DAC_TO_REG(val) (SENSORS_LIMIT(((((val) * 255) + 500) / 2500), 0, 255)) |
230 | #define DAC_FROM_REG(val) (((val)*2500)/255) | 237 | #define DAC_FROM_REG(val) (((val) * 2500) / 255) |
231 | 238 | ||
232 | /* Chip sampling rates | 239 | /* |
240 | * Chip sampling rates | ||
233 | * | 241 | * |
234 | * Some sensors are not updated more frequently than once per second | 242 | * Some sensors are not updated more frequently than once per second |
235 | * so it doesn't make sense to read them more often than that. | 243 | * so it doesn't make sense to read them more often than that. |
@@ -243,11 +251,13 @@ static int adm1026_scaling[] = { /* .001 Volts */ | |||
243 | #define ADM1026_DATA_INTERVAL (1 * HZ) | 251 | #define ADM1026_DATA_INTERVAL (1 * HZ) |
244 | #define ADM1026_CONFIG_INTERVAL (5 * 60 * HZ) | 252 | #define ADM1026_CONFIG_INTERVAL (5 * 60 * HZ) |
245 | 253 | ||
246 | /* We allow for multiple chips in a single system. | 254 | /* |
255 | * We allow for multiple chips in a single system. | ||
247 | * | 256 | * |
248 | * For each registered ADM1026, we need to keep state information | 257 | * For each registered ADM1026, we need to keep state information |
249 | * at client->data. The adm1026_data structure is dynamically | 258 | * at client->data. The adm1026_data structure is dynamically |
250 | * allocated, when a new client structure is allocated. */ | 259 | * allocated, when a new client structure is allocated. |
260 | */ | ||
251 | 261 | ||
252 | struct pwm_data { | 262 | struct pwm_data { |
253 | u8 pwm; | 263 | u8 pwm; |
@@ -388,17 +398,16 @@ static void adm1026_init_client(struct i2c_client *client) | |||
388 | dev_dbg(&client->dev, "THERM pin enabled. " | 398 | dev_dbg(&client->dev, "THERM pin enabled. " |
389 | "GPIO16 disabled.\n"); | 399 | "GPIO16 disabled.\n"); |
390 | } | 400 | } |
391 | if (data->config3 & CFG3_VREF_250) { | 401 | if (data->config3 & CFG3_VREF_250) |
392 | dev_dbg(&client->dev, "Vref is 2.50 Volts.\n"); | 402 | dev_dbg(&client->dev, "Vref is 2.50 Volts.\n"); |
393 | } else { | 403 | else |
394 | dev_dbg(&client->dev, "Vref is 1.82 Volts.\n"); | 404 | dev_dbg(&client->dev, "Vref is 1.82 Volts.\n"); |
395 | } | ||
396 | /* Read and pick apart the existing GPIO configuration */ | 405 | /* Read and pick apart the existing GPIO configuration */ |
397 | value = 0; | 406 | value = 0; |
398 | for (i = 0;i <= 15;++i) { | 407 | for (i = 0; i <= 15; ++i) { |
399 | if ((i & 0x03) == 0) { | 408 | if ((i & 0x03) == 0) { |
400 | value = adm1026_read_value(client, | 409 | value = adm1026_read_value(client, |
401 | ADM1026_REG_GPIO_CFG_0_3 + i/4); | 410 | ADM1026_REG_GPIO_CFG_0_3 + i / 4); |
402 | } | 411 | } |
403 | data->gpio_config[i] = value & 0x03; | 412 | data->gpio_config[i] = value & 0x03; |
404 | value >>= 2; | 413 | value >>= 2; |
@@ -408,7 +417,8 @@ static void adm1026_init_client(struct i2c_client *client) | |||
408 | /* ... and then print it */ | 417 | /* ... and then print it */ |
409 | adm1026_print_gpio(client); | 418 | adm1026_print_gpio(client); |
410 | 419 | ||
411 | /* If the user asks us to reprogram the GPIO config, then | 420 | /* |
421 | * If the user asks us to reprogram the GPIO config, then | ||
412 | * do it now. | 422 | * do it now. |
413 | */ | 423 | */ |
414 | if (gpio_input[0] != -1 || gpio_output[0] != -1 | 424 | if (gpio_input[0] != -1 || gpio_output[0] != -1 |
@@ -417,7 +427,8 @@ static void adm1026_init_client(struct i2c_client *client) | |||
417 | adm1026_fixup_gpio(client); | 427 | adm1026_fixup_gpio(client); |
418 | } | 428 | } |
419 | 429 | ||
420 | /* WE INTENTIONALLY make no changes to the limits, | 430 | /* |
431 | * WE INTENTIONALLY make no changes to the limits, | ||
421 | * offsets, pwms, fans and zones. If they were | 432 | * offsets, pwms, fans and zones. If they were |
422 | * configured, we don't want to mess with them. | 433 | * configured, we don't want to mess with them. |
423 | * If they weren't, the default is 100% PWM, no | 434 | * If they weren't, the default is 100% PWM, no |
@@ -428,7 +439,7 @@ static void adm1026_init_client(struct i2c_client *client) | |||
428 | * without first setting a value for pwm1.auto_pwm_min | 439 | * without first setting a value for pwm1.auto_pwm_min |
429 | * will not result in potentially dangerous fan speed decrease. | 440 | * will not result in potentially dangerous fan speed decrease. |
430 | */ | 441 | */ |
431 | data->pwm1.auto_pwm_min=255; | 442 | data->pwm1.auto_pwm_min = 255; |
432 | /* Start monitoring */ | 443 | /* Start monitoring */ |
433 | value = adm1026_read_value(client, ADM1026_REG_CONFIG1); | 444 | value = adm1026_read_value(client, ADM1026_REG_CONFIG1); |
434 | /* Set MONITOR, clear interrupt acknowledge and s/w reset */ | 445 | /* Set MONITOR, clear interrupt acknowledge and s/w reset */ |
@@ -440,7 +451,7 @@ static void adm1026_init_client(struct i2c_client *client) | |||
440 | /* initialize fan_div[] to hardware defaults */ | 451 | /* initialize fan_div[] to hardware defaults */ |
441 | value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3) | | 452 | value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3) | |
442 | (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7) << 8); | 453 | (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7) << 8); |
443 | for (i = 0;i <= 7;++i) { | 454 | for (i = 0; i <= 7; ++i) { |
444 | data->fan_div[i] = DIV_FROM_REG(value & 0x03); | 455 | data->fan_div[i] = DIV_FROM_REG(value & 0x03); |
445 | value >>= 2; | 456 | value >>= 2; |
446 | } | 457 | } |
@@ -452,7 +463,7 @@ static void adm1026_print_gpio(struct i2c_client *client) | |||
452 | int i; | 463 | int i; |
453 | 464 | ||
454 | dev_dbg(&client->dev, "GPIO config is:\n"); | 465 | dev_dbg(&client->dev, "GPIO config is:\n"); |
455 | for (i = 0;i <= 7;++i) { | 466 | for (i = 0; i <= 7; ++i) { |
456 | if (data->config2 & (1 << i)) { | 467 | if (data->config2 & (1 << i)) { |
457 | dev_dbg(&client->dev, "\t%sGP%s%d\n", | 468 | dev_dbg(&client->dev, "\t%sGP%s%d\n", |
458 | data->gpio_config[i] & 0x02 ? "" : "!", | 469 | data->gpio_config[i] & 0x02 ? "" : "!", |
@@ -462,7 +473,7 @@ static void adm1026_print_gpio(struct i2c_client *client) | |||
462 | dev_dbg(&client->dev, "\tFAN%d\n", i); | 473 | dev_dbg(&client->dev, "\tFAN%d\n", i); |
463 | } | 474 | } |
464 | } | 475 | } |
465 | for (i = 8;i <= 15;++i) { | 476 | for (i = 8; i <= 15; ++i) { |
466 | dev_dbg(&client->dev, "\t%sGP%s%d\n", | 477 | dev_dbg(&client->dev, "\t%sGP%s%d\n", |
467 | data->gpio_config[i] & 0x02 ? "" : "!", | 478 | data->gpio_config[i] & 0x02 ? "" : "!", |
468 | data->gpio_config[i] & 0x01 ? "OUT" : "IN", | 479 | data->gpio_config[i] & 0x01 ? "OUT" : "IN", |
@@ -485,52 +496,46 @@ static void adm1026_fixup_gpio(struct i2c_client *client) | |||
485 | int value; | 496 | int value; |
486 | 497 | ||
487 | /* Make the changes requested. */ | 498 | /* Make the changes requested. */ |
488 | /* We may need to unlock/stop monitoring or soft-reset the | 499 | /* |
500 | * We may need to unlock/stop monitoring or soft-reset the | ||
489 | * chip before we can make changes. This hasn't been | 501 | * chip before we can make changes. This hasn't been |
490 | * tested much. FIXME | 502 | * tested much. FIXME |
491 | */ | 503 | */ |
492 | 504 | ||
493 | /* Make outputs */ | 505 | /* Make outputs */ |
494 | for (i = 0;i <= 16;++i) { | 506 | for (i = 0; i <= 16; ++i) { |
495 | if (gpio_output[i] >= 0 && gpio_output[i] <= 16) { | 507 | if (gpio_output[i] >= 0 && gpio_output[i] <= 16) |
496 | data->gpio_config[gpio_output[i]] |= 0x01; | 508 | data->gpio_config[gpio_output[i]] |= 0x01; |
497 | } | ||
498 | /* if GPIO0-7 is output, it isn't a FAN tach */ | 509 | /* if GPIO0-7 is output, it isn't a FAN tach */ |
499 | if (gpio_output[i] >= 0 && gpio_output[i] <= 7) { | 510 | if (gpio_output[i] >= 0 && gpio_output[i] <= 7) |
500 | data->config2 |= 1 << gpio_output[i]; | 511 | data->config2 |= 1 << gpio_output[i]; |
501 | } | ||
502 | } | 512 | } |
503 | 513 | ||
504 | /* Input overrides output */ | 514 | /* Input overrides output */ |
505 | for (i = 0;i <= 16;++i) { | 515 | for (i = 0; i <= 16; ++i) { |
506 | if (gpio_input[i] >= 0 && gpio_input[i] <= 16) { | 516 | if (gpio_input[i] >= 0 && gpio_input[i] <= 16) |
507 | data->gpio_config[gpio_input[i]] &= ~ 0x01; | 517 | data->gpio_config[gpio_input[i]] &= ~0x01; |
508 | } | ||
509 | /* if GPIO0-7 is input, it isn't a FAN tach */ | 518 | /* if GPIO0-7 is input, it isn't a FAN tach */ |
510 | if (gpio_input[i] >= 0 && gpio_input[i] <= 7) { | 519 | if (gpio_input[i] >= 0 && gpio_input[i] <= 7) |
511 | data->config2 |= 1 << gpio_input[i]; | 520 | data->config2 |= 1 << gpio_input[i]; |
512 | } | ||
513 | } | 521 | } |
514 | 522 | ||
515 | /* Inverted */ | 523 | /* Inverted */ |
516 | for (i = 0;i <= 16;++i) { | 524 | for (i = 0; i <= 16; ++i) { |
517 | if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16) { | 525 | if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16) |
518 | data->gpio_config[gpio_inverted[i]] &= ~ 0x02; | 526 | data->gpio_config[gpio_inverted[i]] &= ~0x02; |
519 | } | ||
520 | } | 527 | } |
521 | 528 | ||
522 | /* Normal overrides inverted */ | 529 | /* Normal overrides inverted */ |
523 | for (i = 0;i <= 16;++i) { | 530 | for (i = 0; i <= 16; ++i) { |
524 | if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16) { | 531 | if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16) |
525 | data->gpio_config[gpio_normal[i]] |= 0x02; | 532 | data->gpio_config[gpio_normal[i]] |= 0x02; |
526 | } | ||
527 | } | 533 | } |
528 | 534 | ||
529 | /* Fan overrides input and output */ | 535 | /* Fan overrides input and output */ |
530 | for (i = 0;i <= 7;++i) { | 536 | for (i = 0; i <= 7; ++i) { |
531 | if (gpio_fan[i] >= 0 && gpio_fan[i] <= 7) { | 537 | if (gpio_fan[i] >= 0 && gpio_fan[i] <= 7) |
532 | data->config2 &= ~(1 << gpio_fan[i]); | 538 | data->config2 &= ~(1 << gpio_fan[i]); |
533 | } | ||
534 | } | 539 | } |
535 | 540 | ||
536 | /* Write new configs to registers */ | 541 | /* Write new configs to registers */ |
@@ -538,7 +543,7 @@ static void adm1026_fixup_gpio(struct i2c_client *client) | |||
538 | data->config3 = (data->config3 & 0x3f) | 543 | data->config3 = (data->config3 & 0x3f) |
539 | | ((data->gpio_config[16] & 0x03) << 6); | 544 | | ((data->gpio_config[16] & 0x03) << 6); |
540 | adm1026_write_value(client, ADM1026_REG_CONFIG3, data->config3); | 545 | adm1026_write_value(client, ADM1026_REG_CONFIG3, data->config3); |
541 | for (i = 15, value = 0;i >= 0;--i) { | 546 | for (i = 15, value = 0; i >= 0; --i) { |
542 | value <<= 2; | 547 | value <<= 2; |
543 | value |= data->gpio_config[i] & 0x03; | 548 | value |= data->gpio_config[i] & 0x03; |
544 | if ((i & 0x03) == 0) { | 549 | if ((i & 0x03) == 0) { |
@@ -563,22 +568,25 @@ static struct adm1026_data *adm1026_update_device(struct device *dev) | |||
563 | 568 | ||
564 | mutex_lock(&data->update_lock); | 569 | mutex_lock(&data->update_lock); |
565 | if (!data->valid | 570 | if (!data->valid |
566 | || time_after(jiffies, data->last_reading + ADM1026_DATA_INTERVAL)) { | 571 | || time_after(jiffies, |
572 | data->last_reading + ADM1026_DATA_INTERVAL)) { | ||
567 | /* Things that change quickly */ | 573 | /* Things that change quickly */ |
568 | dev_dbg(&client->dev, "Reading sensor values\n"); | 574 | dev_dbg(&client->dev, "Reading sensor values\n"); |
569 | for (i = 0;i <= 16;++i) { | 575 | for (i = 0; i <= 16; ++i) { |
570 | data->in[i] = | 576 | data->in[i] = |
571 | adm1026_read_value(client, ADM1026_REG_IN[i]); | 577 | adm1026_read_value(client, ADM1026_REG_IN[i]); |
572 | } | 578 | } |
573 | 579 | ||
574 | for (i = 0;i <= 7;++i) { | 580 | for (i = 0; i <= 7; ++i) { |
575 | data->fan[i] = | 581 | data->fan[i] = |
576 | adm1026_read_value(client, ADM1026_REG_FAN(i)); | 582 | adm1026_read_value(client, ADM1026_REG_FAN(i)); |
577 | } | 583 | } |
578 | 584 | ||
579 | for (i = 0;i <= 2;++i) { | 585 | for (i = 0; i <= 2; ++i) { |
580 | /* NOTE: temp[] is s8 and we assume 2's complement | 586 | /* |
581 | * "conversion" in the assignment */ | 587 | * NOTE: temp[] is s8 and we assume 2's complement |
588 | * "conversion" in the assignment | ||
589 | */ | ||
582 | data->temp[i] = | 590 | data->temp[i] = |
583 | adm1026_read_value(client, ADM1026_REG_TEMP[i]); | 591 | adm1026_read_value(client, ADM1026_REG_TEMP[i]); |
584 | } | 592 | } |
@@ -614,7 +622,7 @@ static struct adm1026_data *adm1026_update_device(struct device *dev) | |||
614 | time_after(jiffies, data->last_config + ADM1026_CONFIG_INTERVAL)) { | 622 | time_after(jiffies, data->last_config + ADM1026_CONFIG_INTERVAL)) { |
615 | /* Things that don't change often */ | 623 | /* Things that don't change often */ |
616 | dev_dbg(&client->dev, "Reading config values\n"); | 624 | dev_dbg(&client->dev, "Reading config values\n"); |
617 | for (i = 0;i <= 16;++i) { | 625 | for (i = 0; i <= 16; ++i) { |
618 | data->in_min[i] = adm1026_read_value(client, | 626 | data->in_min[i] = adm1026_read_value(client, |
619 | ADM1026_REG_IN_MIN[i]); | 627 | ADM1026_REG_IN_MIN[i]); |
620 | data->in_max[i] = adm1026_read_value(client, | 628 | data->in_max[i] = adm1026_read_value(client, |
@@ -624,7 +632,7 @@ static struct adm1026_data *adm1026_update_device(struct device *dev) | |||
624 | value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3) | 632 | value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3) |
625 | | (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7) | 633 | | (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7) |
626 | << 8); | 634 | << 8); |
627 | for (i = 0;i <= 7;++i) { | 635 | for (i = 0; i <= 7; ++i) { |
628 | data->fan_min[i] = adm1026_read_value(client, | 636 | data->fan_min[i] = adm1026_read_value(client, |
629 | ADM1026_REG_FAN_MIN(i)); | 637 | ADM1026_REG_FAN_MIN(i)); |
630 | data->fan_div[i] = DIV_FROM_REG(value & 0x03); | 638 | data->fan_div[i] = DIV_FROM_REG(value & 0x03); |
@@ -632,7 +640,8 @@ static struct adm1026_data *adm1026_update_device(struct device *dev) | |||
632 | } | 640 | } |
633 | 641 | ||
634 | for (i = 0; i <= 2; ++i) { | 642 | for (i = 0; i <= 2; ++i) { |
635 | /* NOTE: temp_xxx[] are s8 and we assume 2's | 643 | /* |
644 | * NOTE: temp_xxx[] are s8 and we assume 2's | ||
636 | * complement "conversion" in the assignment | 645 | * complement "conversion" in the assignment |
637 | */ | 646 | */ |
638 | data->temp_min[i] = adm1026_read_value(client, | 647 | data->temp_min[i] = adm1026_read_value(client, |
@@ -681,7 +690,7 @@ static struct adm1026_data *adm1026_update_device(struct device *dev) | |||
681 | data->gpio_config[16] = (data->config3 >> 6) & 0x03; | 690 | data->gpio_config[16] = (data->config3 >> 6) & 0x03; |
682 | 691 | ||
683 | value = 0; | 692 | value = 0; |
684 | for (i = 0;i <= 15;++i) { | 693 | for (i = 0; i <= 15; ++i) { |
685 | if ((i & 0x03) == 0) { | 694 | if ((i & 0x03) == 0) { |
686 | value = adm1026_read_value(client, | 695 | value = adm1026_read_value(client, |
687 | ADM1026_REG_GPIO_CFG_0_3 + i/4); | 696 | ADM1026_REG_GPIO_CFG_0_3 + i/4); |
@@ -721,7 +730,12 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, | |||
721 | int nr = sensor_attr->index; | 730 | int nr = sensor_attr->index; |
722 | struct i2c_client *client = to_i2c_client(dev); | 731 | struct i2c_client *client = to_i2c_client(dev); |
723 | struct adm1026_data *data = i2c_get_clientdata(client); | 732 | struct adm1026_data *data = i2c_get_clientdata(client); |
724 | int val = simple_strtol(buf, NULL, 10); | 733 | long val; |
734 | int err; | ||
735 | |||
736 | err = kstrtol(buf, 10, &val); | ||
737 | if (err) | ||
738 | return err; | ||
725 | 739 | ||
726 | mutex_lock(&data->update_lock); | 740 | mutex_lock(&data->update_lock); |
727 | data->in_min[nr] = INS_TO_REG(nr, val); | 741 | data->in_min[nr] = INS_TO_REG(nr, val); |
@@ -744,7 +758,12 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, | |||
744 | int nr = sensor_attr->index; | 758 | int nr = sensor_attr->index; |
745 | struct i2c_client *client = to_i2c_client(dev); | 759 | struct i2c_client *client = to_i2c_client(dev); |
746 | struct adm1026_data *data = i2c_get_clientdata(client); | 760 | struct adm1026_data *data = i2c_get_clientdata(client); |
747 | int val = simple_strtol(buf, NULL, 10); | 761 | long val; |
762 | int err; | ||
763 | |||
764 | err = kstrtol(buf, 10, &val); | ||
765 | if (err) | ||
766 | return err; | ||
748 | 767 | ||
749 | mutex_lock(&data->update_lock); | 768 | mutex_lock(&data->update_lock); |
750 | data->in_max[nr] = INS_TO_REG(nr, val); | 769 | data->in_max[nr] = INS_TO_REG(nr, val); |
@@ -779,23 +798,31 @@ in_reg(13); | |||
779 | in_reg(14); | 798 | in_reg(14); |
780 | in_reg(15); | 799 | in_reg(15); |
781 | 800 | ||
782 | static ssize_t show_in16(struct device *dev, struct device_attribute *attr, char *buf) | 801 | static ssize_t show_in16(struct device *dev, struct device_attribute *attr, |
802 | char *buf) | ||
783 | { | 803 | { |
784 | struct adm1026_data *data = adm1026_update_device(dev); | 804 | struct adm1026_data *data = adm1026_update_device(dev); |
785 | return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in[16]) - | 805 | return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in[16]) - |
786 | NEG12_OFFSET); | 806 | NEG12_OFFSET); |
787 | } | 807 | } |
788 | static ssize_t show_in16_min(struct device *dev, struct device_attribute *attr, char *buf) | 808 | static ssize_t show_in16_min(struct device *dev, struct device_attribute *attr, |
809 | char *buf) | ||
789 | { | 810 | { |
790 | struct adm1026_data *data = adm1026_update_device(dev); | 811 | struct adm1026_data *data = adm1026_update_device(dev); |
791 | return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in_min[16]) | 812 | return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in_min[16]) |
792 | - NEG12_OFFSET); | 813 | - NEG12_OFFSET); |
793 | } | 814 | } |
794 | static ssize_t set_in16_min(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 815 | static ssize_t set_in16_min(struct device *dev, struct device_attribute *attr, |
816 | const char *buf, size_t count) | ||
795 | { | 817 | { |
796 | struct i2c_client *client = to_i2c_client(dev); | 818 | struct i2c_client *client = to_i2c_client(dev); |
797 | struct adm1026_data *data = i2c_get_clientdata(client); | 819 | struct adm1026_data *data = i2c_get_clientdata(client); |
798 | int val = simple_strtol(buf, NULL, 10); | 820 | long val; |
821 | int err; | ||
822 | |||
823 | err = kstrtol(buf, 10, &val); | ||
824 | if (err) | ||
825 | return err; | ||
799 | 826 | ||
800 | mutex_lock(&data->update_lock); | 827 | mutex_lock(&data->update_lock); |
801 | data->in_min[16] = INS_TO_REG(16, val + NEG12_OFFSET); | 828 | data->in_min[16] = INS_TO_REG(16, val + NEG12_OFFSET); |
@@ -803,17 +830,24 @@ static ssize_t set_in16_min(struct device *dev, struct device_attribute *attr, c | |||
803 | mutex_unlock(&data->update_lock); | 830 | mutex_unlock(&data->update_lock); |
804 | return count; | 831 | return count; |
805 | } | 832 | } |
806 | static ssize_t show_in16_max(struct device *dev, struct device_attribute *attr, char *buf) | 833 | static ssize_t show_in16_max(struct device *dev, struct device_attribute *attr, |
834 | char *buf) | ||
807 | { | 835 | { |
808 | struct adm1026_data *data = adm1026_update_device(dev); | 836 | struct adm1026_data *data = adm1026_update_device(dev); |
809 | return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in_max[16]) | 837 | return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in_max[16]) |
810 | - NEG12_OFFSET); | 838 | - NEG12_OFFSET); |
811 | } | 839 | } |
812 | static ssize_t set_in16_max(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 840 | static ssize_t set_in16_max(struct device *dev, struct device_attribute *attr, |
841 | const char *buf, size_t count) | ||
813 | { | 842 | { |
814 | struct i2c_client *client = to_i2c_client(dev); | 843 | struct i2c_client *client = to_i2c_client(dev); |
815 | struct adm1026_data *data = i2c_get_clientdata(client); | 844 | struct adm1026_data *data = i2c_get_clientdata(client); |
816 | int val = simple_strtol(buf, NULL, 10); | 845 | long val; |
846 | int err; | ||
847 | |||
848 | err = kstrtol(buf, 10, &val); | ||
849 | if (err) | ||
850 | return err; | ||
817 | 851 | ||
818 | mutex_lock(&data->update_lock); | 852 | mutex_lock(&data->update_lock); |
819 | data->in_max[16] = INS_TO_REG(16, val+NEG12_OFFSET); | 853 | data->in_max[16] = INS_TO_REG(16, val+NEG12_OFFSET); |
@@ -823,10 +857,10 @@ static ssize_t set_in16_max(struct device *dev, struct device_attribute *attr, c | |||
823 | } | 857 | } |
824 | 858 | ||
825 | static SENSOR_DEVICE_ATTR(in16_input, S_IRUGO, show_in16, NULL, 16); | 859 | static SENSOR_DEVICE_ATTR(in16_input, S_IRUGO, show_in16, NULL, 16); |
826 | static SENSOR_DEVICE_ATTR(in16_min, S_IRUGO | S_IWUSR, show_in16_min, set_in16_min, 16); | 860 | static SENSOR_DEVICE_ATTR(in16_min, S_IRUGO | S_IWUSR, show_in16_min, |
827 | static SENSOR_DEVICE_ATTR(in16_max, S_IRUGO | S_IWUSR, show_in16_max, set_in16_max, 16); | 861 | set_in16_min, 16); |
828 | 862 | static SENSOR_DEVICE_ATTR(in16_max, S_IRUGO | S_IWUSR, show_in16_max, | |
829 | 863 | set_in16_max, 16); | |
830 | 864 | ||
831 | 865 | ||
832 | /* Now add fan read/write functions */ | 866 | /* Now add fan read/write functions */ |
@@ -856,7 +890,12 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | |||
856 | int nr = sensor_attr->index; | 890 | int nr = sensor_attr->index; |
857 | struct i2c_client *client = to_i2c_client(dev); | 891 | struct i2c_client *client = to_i2c_client(dev); |
858 | struct adm1026_data *data = i2c_get_clientdata(client); | 892 | struct adm1026_data *data = i2c_get_clientdata(client); |
859 | int val = simple_strtol(buf, NULL, 10); | 893 | long val; |
894 | int err; | ||
895 | |||
896 | err = kstrtol(buf, 10, &val); | ||
897 | if (err) | ||
898 | return err; | ||
860 | 899 | ||
861 | mutex_lock(&data->update_lock); | 900 | mutex_lock(&data->update_lock); |
862 | data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]); | 901 | data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]); |
@@ -890,9 +929,8 @@ static void fixup_fan_min(struct device *dev, int fan, int old_div) | |||
890 | int new_div = data->fan_div[fan]; | 929 | int new_div = data->fan_div[fan]; |
891 | 930 | ||
892 | /* 0 and 0xff are special. Don't adjust them */ | 931 | /* 0 and 0xff are special. Don't adjust them */ |
893 | if (data->fan_min[fan] == 0 || data->fan_min[fan] == 0xff) { | 932 | if (data->fan_min[fan] == 0 || data->fan_min[fan] == 0xff) |
894 | return; | 933 | return; |
895 | } | ||
896 | 934 | ||
897 | new_min = data->fan_min[fan] * old_div / new_div; | 935 | new_min = data->fan_min[fan] * old_div / new_div; |
898 | new_min = SENSORS_LIMIT(new_min, 1, 254); | 936 | new_min = SENSORS_LIMIT(new_min, 1, 254); |
@@ -916,9 +954,14 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | |||
916 | int nr = sensor_attr->index; | 954 | int nr = sensor_attr->index; |
917 | struct i2c_client *client = to_i2c_client(dev); | 955 | struct i2c_client *client = to_i2c_client(dev); |
918 | struct adm1026_data *data = i2c_get_clientdata(client); | 956 | struct adm1026_data *data = i2c_get_clientdata(client); |
919 | int val, orig_div, new_div; | 957 | long val; |
958 | int orig_div, new_div; | ||
959 | int err; | ||
960 | |||
961 | err = kstrtol(buf, 10, &val); | ||
962 | if (err) | ||
963 | return err; | ||
920 | 964 | ||
921 | val = simple_strtol(buf, NULL, 10); | ||
922 | new_div = DIV_TO_REG(val); | 965 | new_div = DIV_TO_REG(val); |
923 | 966 | ||
924 | mutex_lock(&data->update_lock); | 967 | mutex_lock(&data->update_lock); |
@@ -939,9 +982,9 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | |||
939 | (DIV_TO_REG(data->fan_div[7]) << 6)); | 982 | (DIV_TO_REG(data->fan_div[7]) << 6)); |
940 | } | 983 | } |
941 | 984 | ||
942 | if (data->fan_div[nr] != orig_div) { | 985 | if (data->fan_div[nr] != orig_div) |
943 | fixup_fan_min(dev, nr, orig_div); | 986 | fixup_fan_min(dev, nr, orig_div); |
944 | } | 987 | |
945 | mutex_unlock(&data->update_lock); | 988 | mutex_unlock(&data->update_lock); |
946 | return count; | 989 | return count; |
947 | } | 990 | } |
@@ -983,7 +1026,12 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | |||
983 | int nr = sensor_attr->index; | 1026 | int nr = sensor_attr->index; |
984 | struct i2c_client *client = to_i2c_client(dev); | 1027 | struct i2c_client *client = to_i2c_client(dev); |
985 | struct adm1026_data *data = i2c_get_clientdata(client); | 1028 | struct adm1026_data *data = i2c_get_clientdata(client); |
986 | int val = simple_strtol(buf, NULL, 10); | 1029 | long val; |
1030 | int err; | ||
1031 | |||
1032 | err = kstrtol(buf, 10, &val); | ||
1033 | if (err) | ||
1034 | return err; | ||
987 | 1035 | ||
988 | mutex_lock(&data->update_lock); | 1036 | mutex_lock(&data->update_lock); |
989 | data->temp_min[nr] = TEMP_TO_REG(val); | 1037 | data->temp_min[nr] = TEMP_TO_REG(val); |
@@ -1007,7 +1055,12 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | |||
1007 | int nr = sensor_attr->index; | 1055 | int nr = sensor_attr->index; |
1008 | struct i2c_client *client = to_i2c_client(dev); | 1056 | struct i2c_client *client = to_i2c_client(dev); |
1009 | struct adm1026_data *data = i2c_get_clientdata(client); | 1057 | struct adm1026_data *data = i2c_get_clientdata(client); |
1010 | int val = simple_strtol(buf, NULL, 10); | 1058 | long val; |
1059 | int err; | ||
1060 | |||
1061 | err = kstrtol(buf, 10, &val); | ||
1062 | if (err) | ||
1063 | return err; | ||
1011 | 1064 | ||
1012 | mutex_lock(&data->update_lock); | 1065 | mutex_lock(&data->update_lock); |
1013 | data->temp_max[nr] = TEMP_TO_REG(val); | 1066 | data->temp_max[nr] = TEMP_TO_REG(val); |
@@ -1046,7 +1099,12 @@ static ssize_t set_temp_offset(struct device *dev, | |||
1046 | int nr = sensor_attr->index; | 1099 | int nr = sensor_attr->index; |
1047 | struct i2c_client *client = to_i2c_client(dev); | 1100 | struct i2c_client *client = to_i2c_client(dev); |
1048 | struct adm1026_data *data = i2c_get_clientdata(client); | 1101 | struct adm1026_data *data = i2c_get_clientdata(client); |
1049 | int val = simple_strtol(buf, NULL, 10); | 1102 | long val; |
1103 | int err; | ||
1104 | |||
1105 | err = kstrtol(buf, 10, &val); | ||
1106 | if (err) | ||
1107 | return err; | ||
1050 | 1108 | ||
1051 | mutex_lock(&data->update_lock); | 1109 | mutex_lock(&data->update_lock); |
1052 | data->temp_offset[nr] = TEMP_TO_REG(val); | 1110 | data->temp_offset[nr] = TEMP_TO_REG(val); |
@@ -1056,8 +1114,8 @@ static ssize_t set_temp_offset(struct device *dev, | |||
1056 | return count; | 1114 | return count; |
1057 | } | 1115 | } |
1058 | 1116 | ||
1059 | #define temp_offset_reg(offset) \ | 1117 | #define temp_offset_reg(offset) \ |
1060 | static SENSOR_DEVICE_ATTR(temp##offset##_offset, S_IRUGO | S_IWUSR, \ | 1118 | static SENSOR_DEVICE_ATTR(temp##offset##_offset, S_IRUGO | S_IWUSR, \ |
1061 | show_temp_offset, set_temp_offset, offset - 1); | 1119 | show_temp_offset, set_temp_offset, offset - 1); |
1062 | 1120 | ||
1063 | temp_offset_reg(1); | 1121 | temp_offset_reg(1); |
@@ -1097,7 +1155,12 @@ static ssize_t set_temp_auto_point1_temp(struct device *dev, | |||
1097 | int nr = sensor_attr->index; | 1155 | int nr = sensor_attr->index; |
1098 | struct i2c_client *client = to_i2c_client(dev); | 1156 | struct i2c_client *client = to_i2c_client(dev); |
1099 | struct adm1026_data *data = i2c_get_clientdata(client); | 1157 | struct adm1026_data *data = i2c_get_clientdata(client); |
1100 | int val = simple_strtol(buf, NULL, 10); | 1158 | long val; |
1159 | int err; | ||
1160 | |||
1161 | err = kstrtol(buf, 10, &val); | ||
1162 | if (err) | ||
1163 | return err; | ||
1101 | 1164 | ||
1102 | mutex_lock(&data->update_lock); | 1165 | mutex_lock(&data->update_lock); |
1103 | data->temp_tmin[nr] = TEMP_TO_REG(val); | 1166 | data->temp_tmin[nr] = TEMP_TO_REG(val); |
@@ -1131,15 +1194,21 @@ static ssize_t set_temp_crit_enable(struct device *dev, | |||
1131 | { | 1194 | { |
1132 | struct i2c_client *client = to_i2c_client(dev); | 1195 | struct i2c_client *client = to_i2c_client(dev); |
1133 | struct adm1026_data *data = i2c_get_clientdata(client); | 1196 | struct adm1026_data *data = i2c_get_clientdata(client); |
1134 | int val = simple_strtol(buf, NULL, 10); | 1197 | unsigned long val; |
1198 | int err; | ||
1199 | |||
1200 | err = kstrtoul(buf, 10, &val); | ||
1201 | if (err) | ||
1202 | return err; | ||
1203 | |||
1204 | if (val > 1) | ||
1205 | return -EINVAL; | ||
1206 | |||
1207 | mutex_lock(&data->update_lock); | ||
1208 | data->config1 = (data->config1 & ~CFG1_THERM_HOT) | (val << 4); | ||
1209 | adm1026_write_value(client, ADM1026_REG_CONFIG1, data->config1); | ||
1210 | mutex_unlock(&data->update_lock); | ||
1135 | 1211 | ||
1136 | if ((val == 1) || (val==0)) { | ||
1137 | mutex_lock(&data->update_lock); | ||
1138 | data->config1 = (data->config1 & ~CFG1_THERM_HOT) | (val << 4); | ||
1139 | adm1026_write_value(client, ADM1026_REG_CONFIG1, | ||
1140 | data->config1); | ||
1141 | mutex_unlock(&data->update_lock); | ||
1142 | } | ||
1143 | return count; | 1212 | return count; |
1144 | } | 1213 | } |
1145 | 1214 | ||
@@ -1166,7 +1235,12 @@ static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr, | |||
1166 | int nr = sensor_attr->index; | 1235 | int nr = sensor_attr->index; |
1167 | struct i2c_client *client = to_i2c_client(dev); | 1236 | struct i2c_client *client = to_i2c_client(dev); |
1168 | struct adm1026_data *data = i2c_get_clientdata(client); | 1237 | struct adm1026_data *data = i2c_get_clientdata(client); |
1169 | int val = simple_strtol(buf, NULL, 10); | 1238 | long val; |
1239 | int err; | ||
1240 | |||
1241 | err = kstrtol(buf, 10, &val); | ||
1242 | if (err) | ||
1243 | return err; | ||
1170 | 1244 | ||
1171 | mutex_lock(&data->update_lock); | 1245 | mutex_lock(&data->update_lock); |
1172 | data->temp_crit[nr] = TEMP_TO_REG(val); | 1246 | data->temp_crit[nr] = TEMP_TO_REG(val); |
@@ -1184,17 +1258,24 @@ temp_crit_reg(1); | |||
1184 | temp_crit_reg(2); | 1258 | temp_crit_reg(2); |
1185 | temp_crit_reg(3); | 1259 | temp_crit_reg(3); |
1186 | 1260 | ||
1187 | static ssize_t show_analog_out_reg(struct device *dev, struct device_attribute *attr, char *buf) | 1261 | static ssize_t show_analog_out_reg(struct device *dev, |
1262 | struct device_attribute *attr, char *buf) | ||
1188 | { | 1263 | { |
1189 | struct adm1026_data *data = adm1026_update_device(dev); | 1264 | struct adm1026_data *data = adm1026_update_device(dev); |
1190 | return sprintf(buf, "%d\n", DAC_FROM_REG(data->analog_out)); | 1265 | return sprintf(buf, "%d\n", DAC_FROM_REG(data->analog_out)); |
1191 | } | 1266 | } |
1192 | static ssize_t set_analog_out_reg(struct device *dev, struct device_attribute *attr, const char *buf, | 1267 | static ssize_t set_analog_out_reg(struct device *dev, |
1193 | size_t count) | 1268 | struct device_attribute *attr, |
1269 | const char *buf, size_t count) | ||
1194 | { | 1270 | { |
1195 | struct i2c_client *client = to_i2c_client(dev); | 1271 | struct i2c_client *client = to_i2c_client(dev); |
1196 | struct adm1026_data *data = i2c_get_clientdata(client); | 1272 | struct adm1026_data *data = i2c_get_clientdata(client); |
1197 | int val = simple_strtol(buf, NULL, 10); | 1273 | long val; |
1274 | int err; | ||
1275 | |||
1276 | err = kstrtol(buf, 10, &val); | ||
1277 | if (err) | ||
1278 | return err; | ||
1198 | 1279 | ||
1199 | mutex_lock(&data->update_lock); | 1280 | mutex_lock(&data->update_lock); |
1200 | data->analog_out = DAC_TO_REG(val); | 1281 | data->analog_out = DAC_TO_REG(val); |
@@ -1206,7 +1287,8 @@ static ssize_t set_analog_out_reg(struct device *dev, struct device_attribute *a | |||
1206 | static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg, | 1287 | static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg, |
1207 | set_analog_out_reg); | 1288 | set_analog_out_reg); |
1208 | 1289 | ||
1209 | static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) | 1290 | static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, |
1291 | char *buf) | ||
1210 | { | 1292 | { |
1211 | struct adm1026_data *data = adm1026_update_device(dev); | 1293 | struct adm1026_data *data = adm1026_update_device(dev); |
1212 | int vid = (data->gpio >> 11) & 0x1f; | 1294 | int vid = (data->gpio >> 11) & 0x1f; |
@@ -1214,25 +1296,35 @@ static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, c | |||
1214 | dev_dbg(dev, "Setting VID from GPIO11-15.\n"); | 1296 | dev_dbg(dev, "Setting VID from GPIO11-15.\n"); |
1215 | return sprintf(buf, "%d\n", vid_from_reg(vid, data->vrm)); | 1297 | return sprintf(buf, "%d\n", vid_from_reg(vid, data->vrm)); |
1216 | } | 1298 | } |
1299 | |||
1217 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); | 1300 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); |
1218 | 1301 | ||
1219 | static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf) | 1302 | static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, |
1303 | char *buf) | ||
1220 | { | 1304 | { |
1221 | struct adm1026_data *data = dev_get_drvdata(dev); | 1305 | struct adm1026_data *data = dev_get_drvdata(dev); |
1222 | return sprintf(buf, "%d\n", data->vrm); | 1306 | return sprintf(buf, "%d\n", data->vrm); |
1223 | } | 1307 | } |
1224 | static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, | 1308 | |
1225 | size_t count) | 1309 | static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, |
1310 | const char *buf, size_t count) | ||
1226 | { | 1311 | { |
1227 | struct adm1026_data *data = dev_get_drvdata(dev); | 1312 | struct adm1026_data *data = dev_get_drvdata(dev); |
1313 | unsigned long val; | ||
1314 | int err; | ||
1315 | |||
1316 | err = kstrtoul(buf, 10, &val); | ||
1317 | if (err) | ||
1318 | return err; | ||
1228 | 1319 | ||
1229 | data->vrm = simple_strtol(buf, NULL, 10); | 1320 | data->vrm = val; |
1230 | return count; | 1321 | return count; |
1231 | } | 1322 | } |
1232 | 1323 | ||
1233 | static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); | 1324 | static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); |
1234 | 1325 | ||
1235 | static ssize_t show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf) | 1326 | static ssize_t show_alarms_reg(struct device *dev, |
1327 | struct device_attribute *attr, char *buf) | ||
1236 | { | 1328 | { |
1237 | struct adm1026_data *data = adm1026_update_device(dev); | 1329 | struct adm1026_data *data = adm1026_update_device(dev); |
1238 | return sprintf(buf, "%ld\n", data->alarms); | 1330 | return sprintf(buf, "%ld\n", data->alarms); |
@@ -1277,18 +1369,24 @@ static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 24); | |||
1277 | static SENSOR_DEVICE_ATTR(in10_alarm, S_IRUGO, show_alarm, NULL, 25); | 1369 | static SENSOR_DEVICE_ATTR(in10_alarm, S_IRUGO, show_alarm, NULL, 25); |
1278 | static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 26); | 1370 | static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 26); |
1279 | 1371 | ||
1280 | static ssize_t show_alarm_mask(struct device *dev, struct device_attribute *attr, char *buf) | 1372 | static ssize_t show_alarm_mask(struct device *dev, |
1373 | struct device_attribute *attr, char *buf) | ||
1281 | { | 1374 | { |
1282 | struct adm1026_data *data = adm1026_update_device(dev); | 1375 | struct adm1026_data *data = adm1026_update_device(dev); |
1283 | return sprintf(buf, "%ld\n", data->alarm_mask); | 1376 | return sprintf(buf, "%ld\n", data->alarm_mask); |
1284 | } | 1377 | } |
1285 | static ssize_t set_alarm_mask(struct device *dev, struct device_attribute *attr, const char *buf, | 1378 | static ssize_t set_alarm_mask(struct device *dev, struct device_attribute *attr, |
1286 | size_t count) | 1379 | const char *buf, size_t count) |
1287 | { | 1380 | { |
1288 | struct i2c_client *client = to_i2c_client(dev); | 1381 | struct i2c_client *client = to_i2c_client(dev); |
1289 | struct adm1026_data *data = i2c_get_clientdata(client); | 1382 | struct adm1026_data *data = i2c_get_clientdata(client); |
1290 | int val = simple_strtol(buf, NULL, 10); | ||
1291 | unsigned long mask; | 1383 | unsigned long mask; |
1384 | long val; | ||
1385 | int err; | ||
1386 | |||
1387 | err = kstrtol(buf, 10, &val); | ||
1388 | if (err) | ||
1389 | return err; | ||
1292 | 1390 | ||
1293 | mutex_lock(&data->update_lock); | 1391 | mutex_lock(&data->update_lock); |
1294 | data->alarm_mask = val & 0x7fffffff; | 1392 | data->alarm_mask = val & 0x7fffffff; |
@@ -1313,18 +1411,24 @@ static DEVICE_ATTR(alarm_mask, S_IRUGO | S_IWUSR, show_alarm_mask, | |||
1313 | set_alarm_mask); | 1411 | set_alarm_mask); |
1314 | 1412 | ||
1315 | 1413 | ||
1316 | static ssize_t show_gpio(struct device *dev, struct device_attribute *attr, char *buf) | 1414 | static ssize_t show_gpio(struct device *dev, struct device_attribute *attr, |
1415 | char *buf) | ||
1317 | { | 1416 | { |
1318 | struct adm1026_data *data = adm1026_update_device(dev); | 1417 | struct adm1026_data *data = adm1026_update_device(dev); |
1319 | return sprintf(buf, "%ld\n", data->gpio); | 1418 | return sprintf(buf, "%ld\n", data->gpio); |
1320 | } | 1419 | } |
1321 | static ssize_t set_gpio(struct device *dev, struct device_attribute *attr, const char *buf, | 1420 | static ssize_t set_gpio(struct device *dev, struct device_attribute *attr, |
1322 | size_t count) | 1421 | const char *buf, size_t count) |
1323 | { | 1422 | { |
1324 | struct i2c_client *client = to_i2c_client(dev); | 1423 | struct i2c_client *client = to_i2c_client(dev); |
1325 | struct adm1026_data *data = i2c_get_clientdata(client); | 1424 | struct adm1026_data *data = i2c_get_clientdata(client); |
1326 | int val = simple_strtol(buf, NULL, 10); | ||
1327 | long gpio; | 1425 | long gpio; |
1426 | long val; | ||
1427 | int err; | ||
1428 | |||
1429 | err = kstrtol(buf, 10, &val); | ||
1430 | if (err) | ||
1431 | return err; | ||
1328 | 1432 | ||
1329 | mutex_lock(&data->update_lock); | 1433 | mutex_lock(&data->update_lock); |
1330 | data->gpio = val & 0x1ffff; | 1434 | data->gpio = val & 0x1ffff; |
@@ -1340,19 +1444,24 @@ static ssize_t set_gpio(struct device *dev, struct device_attribute *attr, const | |||
1340 | 1444 | ||
1341 | static DEVICE_ATTR(gpio, S_IRUGO | S_IWUSR, show_gpio, set_gpio); | 1445 | static DEVICE_ATTR(gpio, S_IRUGO | S_IWUSR, show_gpio, set_gpio); |
1342 | 1446 | ||
1343 | 1447 | static ssize_t show_gpio_mask(struct device *dev, struct device_attribute *attr, | |
1344 | static ssize_t show_gpio_mask(struct device *dev, struct device_attribute *attr, char *buf) | 1448 | char *buf) |
1345 | { | 1449 | { |
1346 | struct adm1026_data *data = adm1026_update_device(dev); | 1450 | struct adm1026_data *data = adm1026_update_device(dev); |
1347 | return sprintf(buf, "%ld\n", data->gpio_mask); | 1451 | return sprintf(buf, "%ld\n", data->gpio_mask); |
1348 | } | 1452 | } |
1349 | static ssize_t set_gpio_mask(struct device *dev, struct device_attribute *attr, const char *buf, | 1453 | static ssize_t set_gpio_mask(struct device *dev, struct device_attribute *attr, |
1350 | size_t count) | 1454 | const char *buf, size_t count) |
1351 | { | 1455 | { |
1352 | struct i2c_client *client = to_i2c_client(dev); | 1456 | struct i2c_client *client = to_i2c_client(dev); |
1353 | struct adm1026_data *data = i2c_get_clientdata(client); | 1457 | struct adm1026_data *data = i2c_get_clientdata(client); |
1354 | int val = simple_strtol(buf, NULL, 10); | ||
1355 | long mask; | 1458 | long mask; |
1459 | long val; | ||
1460 | int err; | ||
1461 | |||
1462 | err = kstrtol(buf, 10, &val); | ||
1463 | if (err) | ||
1464 | return err; | ||
1356 | 1465 | ||
1357 | mutex_lock(&data->update_lock); | 1466 | mutex_lock(&data->update_lock); |
1358 | data->gpio_mask = val & 0x1ffff; | 1467 | data->gpio_mask = val & 0x1ffff; |
@@ -1368,19 +1477,26 @@ static ssize_t set_gpio_mask(struct device *dev, struct device_attribute *attr, | |||
1368 | 1477 | ||
1369 | static DEVICE_ATTR(gpio_mask, S_IRUGO | S_IWUSR, show_gpio_mask, set_gpio_mask); | 1478 | static DEVICE_ATTR(gpio_mask, S_IRUGO | S_IWUSR, show_gpio_mask, set_gpio_mask); |
1370 | 1479 | ||
1371 | static ssize_t show_pwm_reg(struct device *dev, struct device_attribute *attr, char *buf) | 1480 | static ssize_t show_pwm_reg(struct device *dev, struct device_attribute *attr, |
1481 | char *buf) | ||
1372 | { | 1482 | { |
1373 | struct adm1026_data *data = adm1026_update_device(dev); | 1483 | struct adm1026_data *data = adm1026_update_device(dev); |
1374 | return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm1.pwm)); | 1484 | return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm1.pwm)); |
1375 | } | 1485 | } |
1376 | static ssize_t set_pwm_reg(struct device *dev, struct device_attribute *attr, const char *buf, | 1486 | |
1377 | size_t count) | 1487 | static ssize_t set_pwm_reg(struct device *dev, struct device_attribute *attr, |
1488 | const char *buf, size_t count) | ||
1378 | { | 1489 | { |
1379 | struct i2c_client *client = to_i2c_client(dev); | 1490 | struct i2c_client *client = to_i2c_client(dev); |
1380 | struct adm1026_data *data = i2c_get_clientdata(client); | 1491 | struct adm1026_data *data = i2c_get_clientdata(client); |
1381 | 1492 | ||
1382 | if (data->pwm1.enable == 1) { | 1493 | if (data->pwm1.enable == 1) { |
1383 | int val = simple_strtol(buf, NULL, 10); | 1494 | long val; |
1495 | int err; | ||
1496 | |||
1497 | err = kstrtol(buf, 10, &val); | ||
1498 | if (err) | ||
1499 | return err; | ||
1384 | 1500 | ||
1385 | mutex_lock(&data->update_lock); | 1501 | mutex_lock(&data->update_lock); |
1386 | data->pwm1.pwm = PWM_TO_REG(val); | 1502 | data->pwm1.pwm = PWM_TO_REG(val); |
@@ -1389,17 +1505,26 @@ static ssize_t set_pwm_reg(struct device *dev, struct device_attribute *attr, co | |||
1389 | } | 1505 | } |
1390 | return count; | 1506 | return count; |
1391 | } | 1507 | } |
1392 | static ssize_t show_auto_pwm_min(struct device *dev, struct device_attribute *attr, char *buf) | 1508 | |
1509 | static ssize_t show_auto_pwm_min(struct device *dev, | ||
1510 | struct device_attribute *attr, char *buf) | ||
1393 | { | 1511 | { |
1394 | struct adm1026_data *data = adm1026_update_device(dev); | 1512 | struct adm1026_data *data = adm1026_update_device(dev); |
1395 | return sprintf(buf, "%d\n", data->pwm1.auto_pwm_min); | 1513 | return sprintf(buf, "%d\n", data->pwm1.auto_pwm_min); |
1396 | } | 1514 | } |
1397 | static ssize_t set_auto_pwm_min(struct device *dev, struct device_attribute *attr, const char *buf, | 1515 | |
1398 | size_t count) | 1516 | static ssize_t set_auto_pwm_min(struct device *dev, |
1517 | struct device_attribute *attr, const char *buf, | ||
1518 | size_t count) | ||
1399 | { | 1519 | { |
1400 | struct i2c_client *client = to_i2c_client(dev); | 1520 | struct i2c_client *client = to_i2c_client(dev); |
1401 | struct adm1026_data *data = i2c_get_clientdata(client); | 1521 | struct adm1026_data *data = i2c_get_clientdata(client); |
1402 | int val = simple_strtol(buf, NULL, 10); | 1522 | unsigned long val; |
1523 | int err; | ||
1524 | |||
1525 | err = kstrtoul(buf, 10, &val); | ||
1526 | if (err) | ||
1527 | return err; | ||
1403 | 1528 | ||
1404 | mutex_lock(&data->update_lock); | 1529 | mutex_lock(&data->update_lock); |
1405 | data->pwm1.auto_pwm_min = SENSORS_LIMIT(val, 0, 255); | 1530 | data->pwm1.auto_pwm_min = SENSORS_LIMIT(val, 0, 255); |
@@ -1411,44 +1536,53 @@ static ssize_t set_auto_pwm_min(struct device *dev, struct device_attribute *att | |||
1411 | mutex_unlock(&data->update_lock); | 1536 | mutex_unlock(&data->update_lock); |
1412 | return count; | 1537 | return count; |
1413 | } | 1538 | } |
1414 | static ssize_t show_auto_pwm_max(struct device *dev, struct device_attribute *attr, char *buf) | 1539 | |
1540 | static ssize_t show_auto_pwm_max(struct device *dev, | ||
1541 | struct device_attribute *attr, char *buf) | ||
1415 | { | 1542 | { |
1416 | return sprintf(buf, "%d\n", ADM1026_PWM_MAX); | 1543 | return sprintf(buf, "%d\n", ADM1026_PWM_MAX); |
1417 | } | 1544 | } |
1418 | static ssize_t show_pwm_enable(struct device *dev, struct device_attribute *attr, char *buf) | 1545 | |
1546 | static ssize_t show_pwm_enable(struct device *dev, | ||
1547 | struct device_attribute *attr, char *buf) | ||
1419 | { | 1548 | { |
1420 | struct adm1026_data *data = adm1026_update_device(dev); | 1549 | struct adm1026_data *data = adm1026_update_device(dev); |
1421 | return sprintf(buf, "%d\n", data->pwm1.enable); | 1550 | return sprintf(buf, "%d\n", data->pwm1.enable); |
1422 | } | 1551 | } |
1423 | static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr, const char *buf, | 1552 | |
1424 | size_t count) | 1553 | static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr, |
1554 | const char *buf, size_t count) | ||
1425 | { | 1555 | { |
1426 | struct i2c_client *client = to_i2c_client(dev); | 1556 | struct i2c_client *client = to_i2c_client(dev); |
1427 | struct adm1026_data *data = i2c_get_clientdata(client); | 1557 | struct adm1026_data *data = i2c_get_clientdata(client); |
1428 | int val = simple_strtol(buf, NULL, 10); | ||
1429 | int old_enable; | 1558 | int old_enable; |
1559 | unsigned long val; | ||
1560 | int err; | ||
1430 | 1561 | ||
1431 | if ((val >= 0) && (val < 3)) { | 1562 | err = kstrtoul(buf, 10, &val); |
1432 | mutex_lock(&data->update_lock); | 1563 | if (err) |
1433 | old_enable = data->pwm1.enable; | 1564 | return err; |
1434 | data->pwm1.enable = val; | 1565 | |
1435 | data->config1 = (data->config1 & ~CFG1_PWM_AFC) | 1566 | if (val >= 3) |
1436 | | ((val == 2) ? CFG1_PWM_AFC : 0); | 1567 | return -EINVAL; |
1437 | adm1026_write_value(client, ADM1026_REG_CONFIG1, | 1568 | |
1438 | data->config1); | 1569 | mutex_lock(&data->update_lock); |
1439 | if (val == 2) { /* apply pwm1_auto_pwm_min to pwm1 */ | 1570 | old_enable = data->pwm1.enable; |
1440 | data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) | | 1571 | data->pwm1.enable = val; |
1441 | PWM_MIN_TO_REG(data->pwm1.auto_pwm_min)); | 1572 | data->config1 = (data->config1 & ~CFG1_PWM_AFC) |
1442 | adm1026_write_value(client, ADM1026_REG_PWM, | 1573 | | ((val == 2) ? CFG1_PWM_AFC : 0); |
1443 | data->pwm1.pwm); | 1574 | adm1026_write_value(client, ADM1026_REG_CONFIG1, data->config1); |
1444 | } else if (!((old_enable == 1) && (val == 1))) { | 1575 | if (val == 2) { /* apply pwm1_auto_pwm_min to pwm1 */ |
1445 | /* set pwm to safe value */ | 1576 | data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) | |
1446 | data->pwm1.pwm = 255; | 1577 | PWM_MIN_TO_REG(data->pwm1.auto_pwm_min)); |
1447 | adm1026_write_value(client, ADM1026_REG_PWM, | 1578 | adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm); |
1448 | data->pwm1.pwm); | 1579 | } else if (!((old_enable == 1) && (val == 1))) { |
1449 | } | 1580 | /* set pwm to safe value */ |
1450 | mutex_unlock(&data->update_lock); | 1581 | data->pwm1.pwm = 255; |
1582 | adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm); | ||
1451 | } | 1583 | } |
1584 | mutex_unlock(&data->update_lock); | ||
1585 | |||
1452 | return count; | 1586 | return count; |
1453 | } | 1587 | } |
1454 | 1588 | ||
@@ -1716,7 +1850,8 @@ static int adm1026_probe(struct i2c_client *client, | |||
1716 | adm1026_init_client(client); | 1850 | adm1026_init_client(client); |
1717 | 1851 | ||
1718 | /* Register sysfs hooks */ | 1852 | /* Register sysfs hooks */ |
1719 | if ((err = sysfs_create_group(&client->dev.kobj, &adm1026_group))) | 1853 | err = sysfs_create_group(&client->dev.kobj, &adm1026_group); |
1854 | if (err) | ||
1720 | goto exitfree; | 1855 | goto exitfree; |
1721 | if (data->config1 & CFG1_AIN8_9) | 1856 | if (data->config1 & CFG1_AIN8_9) |
1722 | err = sysfs_create_group(&client->dev.kobj, | 1857 | err = sysfs_create_group(&client->dev.kobj, |