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>
This commit is contained in:
Guenter Roeck 2012-01-14 12:51:15 -08:00 коммит произвёл Guenter Roeck
Родитель 21d2a8f17b
Коммит 86aa3e2210
1 изменённых файлов: 313 добавлений и 178 удалений

Просмотреть файл

@ -1,27 +1,27 @@
/* /*
adm1026.c - Part of lm_sensors, Linux kernel modules for hardware * adm1026.c - Part of lm_sensors, Linux kernel modules for hardware
monitoring * monitoring
Copyright (C) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com> * Copyright (C) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
Copyright (C) 2004 Justin Thiessen <jthiessen@penguincomputing.com> * Copyright (C) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
*
Chip details at: * Chip details at:
*
<http://www.onsemi.com/PowerSolutions/product.do?id=ADM1026> * <http://www.onsemi.com/PowerSolutions/product.do?id=ADM1026>
*
This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. * (at your option) any later version.
*
This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. * GNU General Public License for more details.
*
You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
@ -90,7 +90,8 @@ MODULE_PARM_DESC(gpio_fan, "List of GPIO pins (0-7) to program as fan tachs");
#define E2CFG_ROM 0x08 #define E2CFG_ROM 0x08
#define E2CFG_CLK_EXT 0x80 #define E2CFG_CLK_EXT 0x80
/* There are 10 general analog inputs and 7 dedicated inputs /*
* There are 10 general analog inputs and 7 dedicated inputs
* They are: * They are:
* 0 - 9 = AIN0 - AIN9 * 0 - 9 = AIN0 - AIN9
* 10 = Vbat * 10 = Vbat
@ -117,7 +118,8 @@ static u16 ADM1026_REG_IN_MAX[] = {
0x43, 0x44, 0x45, 0x46, 0x47 0x43, 0x44, 0x45, 0x46, 0x47
}; };
/* Temperatures are: /*
* Temperatures are:
* 0 - Internal * 0 - Internal
* 1 - External 1 * 1 - External 1
* 2 - External 2 * 2 - External 2
@ -170,12 +172,14 @@ static u16 ADM1026_REG_TEMP_OFFSET[] = { 0x1e, 0x6e, 0x6f };
#define ADM1026_FAN_CONTROL_TEMP_RANGE 20 #define ADM1026_FAN_CONTROL_TEMP_RANGE 20
#define ADM1026_PWM_MAX 255 #define ADM1026_PWM_MAX 255
/* Conversions. Rounding and limit checking is only done on the TO_REG /*
* Conversions. Rounding and limit checking is only done on the TO_REG
* variants. Note that you should be a bit careful with which arguments * variants. Note that you should be a bit careful with which arguments
* these macros are called: arguments may be evaluated more than once. * these macros are called: arguments may be evaluated more than once.
*/ */
/* IN are scaled according to built-in resistors. These are the /*
* IN are scaled according to built-in resistors. These are the
* voltages corresponding to 3/4 of full scale (192 or 0xc0) * voltages corresponding to 3/4 of full scale (192 or 0xc0)
* NOTE: The -12V input needs an additional factor to account * NOTE: The -12V input needs an additional factor to account
* for the Vref pullup resistor. * for the Vref pullup resistor.
@ -197,23 +201,25 @@ static int adm1026_scaling[] = { /* .001 Volts */
0, 255)) 0, 255))
#define INS_FROM_REG(n, val) (SCALE(val, 192, adm1026_scaling[n])) #define INS_FROM_REG(n, val) (SCALE(val, 192, adm1026_scaling[n]))
/* FAN speed is measured using 22.5kHz clock and counts for 2 pulses /*
* FAN speed is measured using 22.5kHz clock and counts for 2 pulses
* and we assume a 2 pulse-per-rev fan tach signal * and we assume a 2 pulse-per-rev fan tach signal
* 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) == 1350000 * 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) == 1350000
*/ */
#define FAN_TO_REG(val, div) ((val) <= 0 ? 0xff : \ #define FAN_TO_REG(val, div) ((val) <= 0 ? 0xff : \
SENSORS_LIMIT(1350000/((val)*(div)), 1, 254)) SENSORS_LIMIT(1350000 / ((val) * (div)), \
#define FAN_FROM_REG(val, div) ((val) == 0 ? -1:(val) == 0xff ? 0 : \ 1, 254))
1350000/((val)*(div))) #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 0xff ? 0 : \
#define DIV_FROM_REG(val) (1<<(val)) 1350000 / ((val) * (div)))
#define DIV_FROM_REG(val) (1 << (val))
#define DIV_TO_REG(val) ((val) >= 8 ? 3 : (val) >= 4 ? 2 : (val) >= 2 ? 1 : 0) #define DIV_TO_REG(val) ((val) >= 8 ? 3 : (val) >= 4 ? 2 : (val) >= 2 ? 1 : 0)
/* Temperature is reported in 1 degC increments */ /* Temperature is reported in 1 degC increments */
#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\ #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) + ((val) < 0 ? -500 : 500)) \
-127, 127)) / 1000, -127, 127))
#define TEMP_FROM_REG(val) ((val) * 1000) #define TEMP_FROM_REG(val) ((val) * 1000)
#define OFFSET_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\ #define OFFSET_TO_REG(val) (SENSORS_LIMIT(((val) + ((val) < 0 ? -500 : 500)) \
-127, 127)) / 1000, -127, 127))
#define OFFSET_FROM_REG(val) ((val) * 1000) #define OFFSET_FROM_REG(val) ((val) * 1000)
#define PWM_TO_REG(val) (SENSORS_LIMIT(val, 0, 255)) #define PWM_TO_REG(val) (SENSORS_LIMIT(val, 0, 255))
@ -222,14 +228,16 @@ static int adm1026_scaling[] = { /* .001 Volts */
#define PWM_MIN_TO_REG(val) ((val) & 0xf0) #define PWM_MIN_TO_REG(val) ((val) & 0xf0)
#define PWM_MIN_FROM_REG(val) (((val) & 0xf0) + ((val) >> 4)) #define PWM_MIN_FROM_REG(val) (((val) & 0xf0) + ((val) >> 4))
/* Analog output is a voltage, and scaled to millivolts. The datasheet /*
* Analog output is a voltage, and scaled to millivolts. The datasheet
* indicates that the DAC could be used to drive the fans, but in our * indicates that the DAC could be used to drive the fans, but in our
* example board (Arima HDAMA) it isn't connected to the fans at all. * example board (Arima HDAMA) it isn't connected to the fans at all.
*/ */
#define DAC_TO_REG(val) (SENSORS_LIMIT(((((val)*255)+500)/2500), 0, 255)) #define DAC_TO_REG(val) (SENSORS_LIMIT(((((val) * 255) + 500) / 2500), 0, 255))
#define DAC_FROM_REG(val) (((val)*2500)/255) #define DAC_FROM_REG(val) (((val) * 2500) / 255)
/* Chip sampling rates /*
* Chip sampling rates
* *
* Some sensors are not updated more frequently than once per second * Some sensors are not updated more frequently than once per second
* so it doesn't make sense to read them more often than that. * so it doesn't make sense to read them more often than that.
@ -243,11 +251,13 @@ static int adm1026_scaling[] = { /* .001 Volts */
#define ADM1026_DATA_INTERVAL (1 * HZ) #define ADM1026_DATA_INTERVAL (1 * HZ)
#define ADM1026_CONFIG_INTERVAL (5 * 60 * HZ) #define ADM1026_CONFIG_INTERVAL (5 * 60 * HZ)
/* We allow for multiple chips in a single system. /*
* We allow for multiple chips in a single system.
* *
* For each registered ADM1026, we need to keep state information * For each registered ADM1026, we need to keep state information
* at client->data. The adm1026_data structure is dynamically * at client->data. The adm1026_data structure is dynamically
* allocated, when a new client structure is allocated. */ * allocated, when a new client structure is allocated.
*/
struct pwm_data { struct pwm_data {
u8 pwm; u8 pwm;
@ -388,17 +398,16 @@ static void adm1026_init_client(struct i2c_client *client)
dev_dbg(&client->dev, "THERM pin enabled. " dev_dbg(&client->dev, "THERM pin enabled. "
"GPIO16 disabled.\n"); "GPIO16 disabled.\n");
} }
if (data->config3 & CFG3_VREF_250) { if (data->config3 & CFG3_VREF_250)
dev_dbg(&client->dev, "Vref is 2.50 Volts.\n"); dev_dbg(&client->dev, "Vref is 2.50 Volts.\n");
} else { else
dev_dbg(&client->dev, "Vref is 1.82 Volts.\n"); dev_dbg(&client->dev, "Vref is 1.82 Volts.\n");
}
/* Read and pick apart the existing GPIO configuration */ /* Read and pick apart the existing GPIO configuration */
value = 0; value = 0;
for (i = 0;i <= 15;++i) { for (i = 0; i <= 15; ++i) {
if ((i & 0x03) == 0) { if ((i & 0x03) == 0) {
value = adm1026_read_value(client, value = adm1026_read_value(client,
ADM1026_REG_GPIO_CFG_0_3 + i/4); ADM1026_REG_GPIO_CFG_0_3 + i / 4);
} }
data->gpio_config[i] = value & 0x03; data->gpio_config[i] = value & 0x03;
value >>= 2; value >>= 2;
@ -408,7 +417,8 @@ static void adm1026_init_client(struct i2c_client *client)
/* ... and then print it */ /* ... and then print it */
adm1026_print_gpio(client); adm1026_print_gpio(client);
/* If the user asks us to reprogram the GPIO config, then /*
* If the user asks us to reprogram the GPIO config, then
* do it now. * do it now.
*/ */
if (gpio_input[0] != -1 || gpio_output[0] != -1 if (gpio_input[0] != -1 || gpio_output[0] != -1
@ -417,7 +427,8 @@ static void adm1026_init_client(struct i2c_client *client)
adm1026_fixup_gpio(client); adm1026_fixup_gpio(client);
} }
/* WE INTENTIONALLY make no changes to the limits, /*
* WE INTENTIONALLY make no changes to the limits,
* offsets, pwms, fans and zones. If they were * offsets, pwms, fans and zones. If they were
* configured, we don't want to mess with them. * configured, we don't want to mess with them.
* If they weren't, the default is 100% PWM, no * If they weren't, the default is 100% PWM, no
@ -428,7 +439,7 @@ static void adm1026_init_client(struct i2c_client *client)
* without first setting a value for pwm1.auto_pwm_min * without first setting a value for pwm1.auto_pwm_min
* will not result in potentially dangerous fan speed decrease. * will not result in potentially dangerous fan speed decrease.
*/ */
data->pwm1.auto_pwm_min=255; data->pwm1.auto_pwm_min = 255;
/* Start monitoring */ /* Start monitoring */
value = adm1026_read_value(client, ADM1026_REG_CONFIG1); value = adm1026_read_value(client, ADM1026_REG_CONFIG1);
/* Set MONITOR, clear interrupt acknowledge and s/w reset */ /* Set MONITOR, clear interrupt acknowledge and s/w reset */
@ -440,7 +451,7 @@ static void adm1026_init_client(struct i2c_client *client)
/* initialize fan_div[] to hardware defaults */ /* initialize fan_div[] to hardware defaults */
value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3) | value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3) |
(adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7) << 8); (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7) << 8);
for (i = 0;i <= 7;++i) { for (i = 0; i <= 7; ++i) {
data->fan_div[i] = DIV_FROM_REG(value & 0x03); data->fan_div[i] = DIV_FROM_REG(value & 0x03);
value >>= 2; value >>= 2;
} }
@ -452,7 +463,7 @@ static void adm1026_print_gpio(struct i2c_client *client)
int i; int i;
dev_dbg(&client->dev, "GPIO config is:\n"); dev_dbg(&client->dev, "GPIO config is:\n");
for (i = 0;i <= 7;++i) { for (i = 0; i <= 7; ++i) {
if (data->config2 & (1 << i)) { if (data->config2 & (1 << i)) {
dev_dbg(&client->dev, "\t%sGP%s%d\n", dev_dbg(&client->dev, "\t%sGP%s%d\n",
data->gpio_config[i] & 0x02 ? "" : "!", data->gpio_config[i] & 0x02 ? "" : "!",
@ -462,7 +473,7 @@ static void adm1026_print_gpio(struct i2c_client *client)
dev_dbg(&client->dev, "\tFAN%d\n", i); dev_dbg(&client->dev, "\tFAN%d\n", i);
} }
} }
for (i = 8;i <= 15;++i) { for (i = 8; i <= 15; ++i) {
dev_dbg(&client->dev, "\t%sGP%s%d\n", dev_dbg(&client->dev, "\t%sGP%s%d\n",
data->gpio_config[i] & 0x02 ? "" : "!", data->gpio_config[i] & 0x02 ? "" : "!",
data->gpio_config[i] & 0x01 ? "OUT" : "IN", data->gpio_config[i] & 0x01 ? "OUT" : "IN",
@ -485,52 +496,46 @@ static void adm1026_fixup_gpio(struct i2c_client *client)
int value; int value;
/* Make the changes requested. */ /* Make the changes requested. */
/* We may need to unlock/stop monitoring or soft-reset the /*
* We may need to unlock/stop monitoring or soft-reset the
* chip before we can make changes. This hasn't been * chip before we can make changes. This hasn't been
* tested much. FIXME * tested much. FIXME
*/ */
/* Make outputs */ /* Make outputs */
for (i = 0;i <= 16;++i) { for (i = 0; i <= 16; ++i) {
if (gpio_output[i] >= 0 && gpio_output[i] <= 16) { if (gpio_output[i] >= 0 && gpio_output[i] <= 16)
data->gpio_config[gpio_output[i]] |= 0x01; data->gpio_config[gpio_output[i]] |= 0x01;
}
/* if GPIO0-7 is output, it isn't a FAN tach */ /* if GPIO0-7 is output, it isn't a FAN tach */
if (gpio_output[i] >= 0 && gpio_output[i] <= 7) { if (gpio_output[i] >= 0 && gpio_output[i] <= 7)
data->config2 |= 1 << gpio_output[i]; data->config2 |= 1 << gpio_output[i];
}
} }
/* Input overrides output */ /* Input overrides output */
for (i = 0;i <= 16;++i) { for (i = 0; i <= 16; ++i) {
if (gpio_input[i] >= 0 && gpio_input[i] <= 16) { if (gpio_input[i] >= 0 && gpio_input[i] <= 16)
data->gpio_config[gpio_input[i]] &= ~ 0x01; data->gpio_config[gpio_input[i]] &= ~0x01;
}
/* if GPIO0-7 is input, it isn't a FAN tach */ /* if GPIO0-7 is input, it isn't a FAN tach */
if (gpio_input[i] >= 0 && gpio_input[i] <= 7) { if (gpio_input[i] >= 0 && gpio_input[i] <= 7)
data->config2 |= 1 << gpio_input[i]; data->config2 |= 1 << gpio_input[i];
}
} }
/* Inverted */ /* Inverted */
for (i = 0;i <= 16;++i) { for (i = 0; i <= 16; ++i) {
if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16) { if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16)
data->gpio_config[gpio_inverted[i]] &= ~ 0x02; data->gpio_config[gpio_inverted[i]] &= ~0x02;
}
} }
/* Normal overrides inverted */ /* Normal overrides inverted */
for (i = 0;i <= 16;++i) { for (i = 0; i <= 16; ++i) {
if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16) { if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16)
data->gpio_config[gpio_normal[i]] |= 0x02; data->gpio_config[gpio_normal[i]] |= 0x02;
}
} }
/* Fan overrides input and output */ /* Fan overrides input and output */
for (i = 0;i <= 7;++i) { for (i = 0; i <= 7; ++i) {
if (gpio_fan[i] >= 0 && gpio_fan[i] <= 7) { if (gpio_fan[i] >= 0 && gpio_fan[i] <= 7)
data->config2 &= ~(1 << gpio_fan[i]); data->config2 &= ~(1 << gpio_fan[i]);
}
} }
/* Write new configs to registers */ /* Write new configs to registers */
@ -538,7 +543,7 @@ static void adm1026_fixup_gpio(struct i2c_client *client)
data->config3 = (data->config3 & 0x3f) data->config3 = (data->config3 & 0x3f)
| ((data->gpio_config[16] & 0x03) << 6); | ((data->gpio_config[16] & 0x03) << 6);
adm1026_write_value(client, ADM1026_REG_CONFIG3, data->config3); adm1026_write_value(client, ADM1026_REG_CONFIG3, data->config3);
for (i = 15, value = 0;i >= 0;--i) { for (i = 15, value = 0; i >= 0; --i) {
value <<= 2; value <<= 2;
value |= data->gpio_config[i] & 0x03; value |= data->gpio_config[i] & 0x03;
if ((i & 0x03) == 0) { if ((i & 0x03) == 0) {
@ -563,22 +568,25 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
if (!data->valid if (!data->valid
|| time_after(jiffies, data->last_reading + ADM1026_DATA_INTERVAL)) { || time_after(jiffies,
data->last_reading + ADM1026_DATA_INTERVAL)) {
/* Things that change quickly */ /* Things that change quickly */
dev_dbg(&client->dev, "Reading sensor values\n"); dev_dbg(&client->dev, "Reading sensor values\n");
for (i = 0;i <= 16;++i) { for (i = 0; i <= 16; ++i) {
data->in[i] = data->in[i] =
adm1026_read_value(client, ADM1026_REG_IN[i]); adm1026_read_value(client, ADM1026_REG_IN[i]);
} }
for (i = 0;i <= 7;++i) { for (i = 0; i <= 7; ++i) {
data->fan[i] = data->fan[i] =
adm1026_read_value(client, ADM1026_REG_FAN(i)); adm1026_read_value(client, ADM1026_REG_FAN(i));
} }
for (i = 0;i <= 2;++i) { for (i = 0; i <= 2; ++i) {
/* NOTE: temp[] is s8 and we assume 2's complement /*
* "conversion" in the assignment */ * NOTE: temp[] is s8 and we assume 2's complement
* "conversion" in the assignment
*/
data->temp[i] = data->temp[i] =
adm1026_read_value(client, ADM1026_REG_TEMP[i]); adm1026_read_value(client, ADM1026_REG_TEMP[i]);
} }
@ -614,7 +622,7 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
time_after(jiffies, data->last_config + ADM1026_CONFIG_INTERVAL)) { time_after(jiffies, data->last_config + ADM1026_CONFIG_INTERVAL)) {
/* Things that don't change often */ /* Things that don't change often */
dev_dbg(&client->dev, "Reading config values\n"); dev_dbg(&client->dev, "Reading config values\n");
for (i = 0;i <= 16;++i) { for (i = 0; i <= 16; ++i) {
data->in_min[i] = adm1026_read_value(client, data->in_min[i] = adm1026_read_value(client,
ADM1026_REG_IN_MIN[i]); ADM1026_REG_IN_MIN[i]);
data->in_max[i] = adm1026_read_value(client, data->in_max[i] = adm1026_read_value(client,
@ -624,7 +632,7 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3) value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3)
| (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7) | (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7)
<< 8); << 8);
for (i = 0;i <= 7;++i) { for (i = 0; i <= 7; ++i) {
data->fan_min[i] = adm1026_read_value(client, data->fan_min[i] = adm1026_read_value(client,
ADM1026_REG_FAN_MIN(i)); ADM1026_REG_FAN_MIN(i));
data->fan_div[i] = DIV_FROM_REG(value & 0x03); data->fan_div[i] = DIV_FROM_REG(value & 0x03);
@ -632,7 +640,8 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
} }
for (i = 0; i <= 2; ++i) { for (i = 0; i <= 2; ++i) {
/* NOTE: temp_xxx[] are s8 and we assume 2's /*
* NOTE: temp_xxx[] are s8 and we assume 2's
* complement "conversion" in the assignment * complement "conversion" in the assignment
*/ */
data->temp_min[i] = adm1026_read_value(client, data->temp_min[i] = adm1026_read_value(client,
@ -681,7 +690,7 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
data->gpio_config[16] = (data->config3 >> 6) & 0x03; data->gpio_config[16] = (data->config3 >> 6) & 0x03;
value = 0; value = 0;
for (i = 0;i <= 15;++i) { for (i = 0; i <= 15; ++i) {
if ((i & 0x03) == 0) { if ((i & 0x03) == 0) {
value = adm1026_read_value(client, value = adm1026_read_value(client,
ADM1026_REG_GPIO_CFG_0_3 + i/4); 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,
int nr = sensor_attr->index; int nr = sensor_attr->index;
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client); struct adm1026_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); long val;
int err;
err = kstrtol(buf, 10, &val);
if (err)
return err;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
data->in_min[nr] = INS_TO_REG(nr, val); 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,
int nr = sensor_attr->index; int nr = sensor_attr->index;
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client); struct adm1026_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); long val;
int err;
err = kstrtol(buf, 10, &val);
if (err)
return err;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
data->in_max[nr] = INS_TO_REG(nr, val); data->in_max[nr] = INS_TO_REG(nr, val);
@ -779,23 +798,31 @@ in_reg(13);
in_reg(14); in_reg(14);
in_reg(15); in_reg(15);
static ssize_t show_in16(struct device *dev, struct device_attribute *attr, char *buf) static ssize_t show_in16(struct device *dev, struct device_attribute *attr,
char *buf)
{ {
struct adm1026_data *data = adm1026_update_device(dev); struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in[16]) - return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in[16]) -
NEG12_OFFSET); NEG12_OFFSET);
} }
static ssize_t show_in16_min(struct device *dev, struct device_attribute *attr, char *buf) static ssize_t show_in16_min(struct device *dev, struct device_attribute *attr,
char *buf)
{ {
struct adm1026_data *data = adm1026_update_device(dev); struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in_min[16]) return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in_min[16])
- NEG12_OFFSET); - NEG12_OFFSET);
} }
static ssize_t set_in16_min(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) static ssize_t set_in16_min(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client); struct adm1026_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); long val;
int err;
err = kstrtol(buf, 10, &val);
if (err)
return err;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
data->in_min[16] = INS_TO_REG(16, val + NEG12_OFFSET); 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
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t show_in16_max(struct device *dev, struct device_attribute *attr, char *buf) static ssize_t show_in16_max(struct device *dev, struct device_attribute *attr,
char *buf)
{ {
struct adm1026_data *data = adm1026_update_device(dev); struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in_max[16]) return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in_max[16])
- NEG12_OFFSET); - NEG12_OFFSET);
} }
static ssize_t set_in16_max(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) static ssize_t set_in16_max(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client); struct adm1026_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); long val;
int err;
err = kstrtol(buf, 10, &val);
if (err)
return err;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
data->in_max[16] = INS_TO_REG(16, val+NEG12_OFFSET); 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
} }
static SENSOR_DEVICE_ATTR(in16_input, S_IRUGO, show_in16, NULL, 16); static SENSOR_DEVICE_ATTR(in16_input, S_IRUGO, show_in16, NULL, 16);
static SENSOR_DEVICE_ATTR(in16_min, S_IRUGO | S_IWUSR, show_in16_min, set_in16_min, 16); static SENSOR_DEVICE_ATTR(in16_min, S_IRUGO | S_IWUSR, show_in16_min,
static SENSOR_DEVICE_ATTR(in16_max, S_IRUGO | S_IWUSR, show_in16_max, set_in16_max, 16); set_in16_min, 16);
static SENSOR_DEVICE_ATTR(in16_max, S_IRUGO | S_IWUSR, show_in16_max,
set_in16_max, 16);
/* Now add fan read/write functions */ /* Now add fan read/write functions */
@ -856,7 +890,12 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
int nr = sensor_attr->index; int nr = sensor_attr->index;
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client); struct adm1026_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); long val;
int err;
err = kstrtol(buf, 10, &val);
if (err)
return err;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]); 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)
int new_div = data->fan_div[fan]; int new_div = data->fan_div[fan];
/* 0 and 0xff are special. Don't adjust them */ /* 0 and 0xff are special. Don't adjust them */
if (data->fan_min[fan] == 0 || data->fan_min[fan] == 0xff) { if (data->fan_min[fan] == 0 || data->fan_min[fan] == 0xff)
return; return;
}
new_min = data->fan_min[fan] * old_div / new_div; new_min = data->fan_min[fan] * old_div / new_div;
new_min = SENSORS_LIMIT(new_min, 1, 254); 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,
int nr = sensor_attr->index; int nr = sensor_attr->index;
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client); struct adm1026_data *data = i2c_get_clientdata(client);
int val, orig_div, new_div; long val;
int orig_div, new_div;
int err;
err = kstrtol(buf, 10, &val);
if (err)
return err;
val = simple_strtol(buf, NULL, 10);
new_div = DIV_TO_REG(val); new_div = DIV_TO_REG(val);
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
@ -939,9 +982,9 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
(DIV_TO_REG(data->fan_div[7]) << 6)); (DIV_TO_REG(data->fan_div[7]) << 6));
} }
if (data->fan_div[nr] != orig_div) { if (data->fan_div[nr] != orig_div)
fixup_fan_min(dev, nr, orig_div); fixup_fan_min(dev, nr, orig_div);
}
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
@ -983,7 +1026,12 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
int nr = sensor_attr->index; int nr = sensor_attr->index;
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client); struct adm1026_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); long val;
int err;
err = kstrtol(buf, 10, &val);
if (err)
return err;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_min[nr] = TEMP_TO_REG(val); 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,
int nr = sensor_attr->index; int nr = sensor_attr->index;
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client); struct adm1026_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); long val;
int err;
err = kstrtol(buf, 10, &val);
if (err)
return err;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_max[nr] = TEMP_TO_REG(val); data->temp_max[nr] = TEMP_TO_REG(val);
@ -1046,7 +1099,12 @@ static ssize_t set_temp_offset(struct device *dev,
int nr = sensor_attr->index; int nr = sensor_attr->index;
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client); struct adm1026_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); long val;
int err;
err = kstrtol(buf, 10, &val);
if (err)
return err;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_offset[nr] = TEMP_TO_REG(val); data->temp_offset[nr] = TEMP_TO_REG(val);
@ -1056,8 +1114,8 @@ static ssize_t set_temp_offset(struct device *dev,
return count; return count;
} }
#define temp_offset_reg(offset) \ #define temp_offset_reg(offset) \
static SENSOR_DEVICE_ATTR(temp##offset##_offset, S_IRUGO | S_IWUSR, \ static SENSOR_DEVICE_ATTR(temp##offset##_offset, S_IRUGO | S_IWUSR, \
show_temp_offset, set_temp_offset, offset - 1); show_temp_offset, set_temp_offset, offset - 1);
temp_offset_reg(1); temp_offset_reg(1);
@ -1097,7 +1155,12 @@ static ssize_t set_temp_auto_point1_temp(struct device *dev,
int nr = sensor_attr->index; int nr = sensor_attr->index;
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client); struct adm1026_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); long val;
int err;
err = kstrtol(buf, 10, &val);
if (err)
return err;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_tmin[nr] = TEMP_TO_REG(val); data->temp_tmin[nr] = TEMP_TO_REG(val);
@ -1131,15 +1194,21 @@ static ssize_t set_temp_crit_enable(struct device *dev,
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client); struct adm1026_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); unsigned long val;
int err;
err = kstrtoul(buf, 10, &val);
if (err)
return err;
if (val > 1)
return -EINVAL;
mutex_lock(&data->update_lock);
data->config1 = (data->config1 & ~CFG1_THERM_HOT) | (val << 4);
adm1026_write_value(client, ADM1026_REG_CONFIG1, data->config1);
mutex_unlock(&data->update_lock);
if ((val == 1) || (val==0)) {
mutex_lock(&data->update_lock);
data->config1 = (data->config1 & ~CFG1_THERM_HOT) | (val << 4);
adm1026_write_value(client, ADM1026_REG_CONFIG1,
data->config1);
mutex_unlock(&data->update_lock);
}
return count; return count;
} }
@ -1166,7 +1235,12 @@ static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
int nr = sensor_attr->index; int nr = sensor_attr->index;
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client); struct adm1026_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); long val;
int err;
err = kstrtol(buf, 10, &val);
if (err)
return err;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_crit[nr] = TEMP_TO_REG(val); data->temp_crit[nr] = TEMP_TO_REG(val);
@ -1184,17 +1258,24 @@ temp_crit_reg(1);
temp_crit_reg(2); temp_crit_reg(2);
temp_crit_reg(3); temp_crit_reg(3);
static ssize_t show_analog_out_reg(struct device *dev, struct device_attribute *attr, char *buf) static ssize_t show_analog_out_reg(struct device *dev,
struct device_attribute *attr, char *buf)
{ {
struct adm1026_data *data = adm1026_update_device(dev); struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf, "%d\n", DAC_FROM_REG(data->analog_out)); return sprintf(buf, "%d\n", DAC_FROM_REG(data->analog_out));
} }
static ssize_t set_analog_out_reg(struct device *dev, struct device_attribute *attr, const char *buf, static ssize_t set_analog_out_reg(struct device *dev,
size_t count) struct device_attribute *attr,
const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client); struct adm1026_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); long val;
int err;
err = kstrtol(buf, 10, &val);
if (err)
return err;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
data->analog_out = DAC_TO_REG(val); 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
static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg, static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg,
set_analog_out_reg); set_analog_out_reg);
static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
char *buf)
{ {
struct adm1026_data *data = adm1026_update_device(dev); struct adm1026_data *data = adm1026_update_device(dev);
int vid = (data->gpio >> 11) & 0x1f; int vid = (data->gpio >> 11) & 0x1f;
@ -1214,25 +1296,35 @@ static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, c
dev_dbg(dev, "Setting VID from GPIO11-15.\n"); dev_dbg(dev, "Setting VID from GPIO11-15.\n");
return sprintf(buf, "%d\n", vid_from_reg(vid, data->vrm)); return sprintf(buf, "%d\n", vid_from_reg(vid, data->vrm));
} }
static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf) static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
char *buf)
{ {
struct adm1026_data *data = dev_get_drvdata(dev); struct adm1026_data *data = dev_get_drvdata(dev);
return sprintf(buf, "%d\n", data->vrm); return sprintf(buf, "%d\n", data->vrm);
} }
static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf,
size_t count) static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{ {
struct adm1026_data *data = dev_get_drvdata(dev); struct adm1026_data *data = dev_get_drvdata(dev);
unsigned long val;
int err;
data->vrm = simple_strtol(buf, NULL, 10); err = kstrtoul(buf, 10, &val);
if (err)
return err;
data->vrm = val;
return count; return count;
} }
static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
static ssize_t show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf) static ssize_t show_alarms_reg(struct device *dev,
struct device_attribute *attr, char *buf)
{ {
struct adm1026_data *data = adm1026_update_device(dev); struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf, "%ld\n", data->alarms); return sprintf(buf, "%ld\n", data->alarms);
@ -1277,18 +1369,24 @@ static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 24);
static SENSOR_DEVICE_ATTR(in10_alarm, S_IRUGO, show_alarm, NULL, 25); static SENSOR_DEVICE_ATTR(in10_alarm, S_IRUGO, show_alarm, NULL, 25);
static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 26); static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 26);
static ssize_t show_alarm_mask(struct device *dev, struct device_attribute *attr, char *buf) static ssize_t show_alarm_mask(struct device *dev,
struct device_attribute *attr, char *buf)
{ {
struct adm1026_data *data = adm1026_update_device(dev); struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf, "%ld\n", data->alarm_mask); return sprintf(buf, "%ld\n", data->alarm_mask);
} }
static ssize_t set_alarm_mask(struct device *dev, struct device_attribute *attr, const char *buf, static ssize_t set_alarm_mask(struct device *dev, struct device_attribute *attr,
size_t count) const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client); struct adm1026_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10);
unsigned long mask; unsigned long mask;
long val;
int err;
err = kstrtol(buf, 10, &val);
if (err)
return err;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
data->alarm_mask = val & 0x7fffffff; data->alarm_mask = val & 0x7fffffff;
@ -1313,18 +1411,24 @@ static DEVICE_ATTR(alarm_mask, S_IRUGO | S_IWUSR, show_alarm_mask,
set_alarm_mask); set_alarm_mask);
static ssize_t show_gpio(struct device *dev, struct device_attribute *attr, char *buf) static ssize_t show_gpio(struct device *dev, struct device_attribute *attr,
char *buf)
{ {
struct adm1026_data *data = adm1026_update_device(dev); struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf, "%ld\n", data->gpio); return sprintf(buf, "%ld\n", data->gpio);
} }
static ssize_t set_gpio(struct device *dev, struct device_attribute *attr, const char *buf, static ssize_t set_gpio(struct device *dev, struct device_attribute *attr,
size_t count) const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client); struct adm1026_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10);
long gpio; long gpio;
long val;
int err;
err = kstrtol(buf, 10, &val);
if (err)
return err;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
data->gpio = val & 0x1ffff; data->gpio = val & 0x1ffff;
@ -1340,19 +1444,24 @@ static ssize_t set_gpio(struct device *dev, struct device_attribute *attr, const
static DEVICE_ATTR(gpio, S_IRUGO | S_IWUSR, show_gpio, set_gpio); static DEVICE_ATTR(gpio, S_IRUGO | S_IWUSR, show_gpio, set_gpio);
static ssize_t show_gpio_mask(struct device *dev, struct device_attribute *attr,
static ssize_t show_gpio_mask(struct device *dev, struct device_attribute *attr, char *buf) char *buf)
{ {
struct adm1026_data *data = adm1026_update_device(dev); struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf, "%ld\n", data->gpio_mask); return sprintf(buf, "%ld\n", data->gpio_mask);
} }
static ssize_t set_gpio_mask(struct device *dev, struct device_attribute *attr, const char *buf, static ssize_t set_gpio_mask(struct device *dev, struct device_attribute *attr,
size_t count) const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client); struct adm1026_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10);
long mask; long mask;
long val;
int err;
err = kstrtol(buf, 10, &val);
if (err)
return err;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
data->gpio_mask = val & 0x1ffff; data->gpio_mask = val & 0x1ffff;
@ -1368,19 +1477,26 @@ static ssize_t set_gpio_mask(struct device *dev, struct device_attribute *attr,
static DEVICE_ATTR(gpio_mask, S_IRUGO | S_IWUSR, show_gpio_mask, set_gpio_mask); static DEVICE_ATTR(gpio_mask, S_IRUGO | S_IWUSR, show_gpio_mask, set_gpio_mask);
static ssize_t show_pwm_reg(struct device *dev, struct device_attribute *attr, char *buf) static ssize_t show_pwm_reg(struct device *dev, struct device_attribute *attr,
char *buf)
{ {
struct adm1026_data *data = adm1026_update_device(dev); struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm1.pwm)); return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm1.pwm));
} }
static ssize_t set_pwm_reg(struct device *dev, struct device_attribute *attr, const char *buf,
size_t count) static ssize_t set_pwm_reg(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client); struct adm1026_data *data = i2c_get_clientdata(client);
if (data->pwm1.enable == 1) { if (data->pwm1.enable == 1) {
int val = simple_strtol(buf, NULL, 10); long val;
int err;
err = kstrtol(buf, 10, &val);
if (err)
return err;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
data->pwm1.pwm = PWM_TO_REG(val); 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
} }
return count; return count;
} }
static ssize_t show_auto_pwm_min(struct device *dev, struct device_attribute *attr, char *buf)
static ssize_t show_auto_pwm_min(struct device *dev,
struct device_attribute *attr, char *buf)
{ {
struct adm1026_data *data = adm1026_update_device(dev); struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf, "%d\n", data->pwm1.auto_pwm_min); return sprintf(buf, "%d\n", data->pwm1.auto_pwm_min);
} }
static ssize_t set_auto_pwm_min(struct device *dev, struct device_attribute *attr, const char *buf,
size_t count) static ssize_t set_auto_pwm_min(struct device *dev,
struct device_attribute *attr, const char *buf,
size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client); struct adm1026_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10); unsigned long val;
int err;
err = kstrtoul(buf, 10, &val);
if (err)
return err;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
data->pwm1.auto_pwm_min = SENSORS_LIMIT(val, 0, 255); 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
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
static ssize_t show_auto_pwm_max(struct device *dev, struct device_attribute *attr, char *buf)
static ssize_t show_auto_pwm_max(struct device *dev,
struct device_attribute *attr, char *buf)
{ {
return sprintf(buf, "%d\n", ADM1026_PWM_MAX); return sprintf(buf, "%d\n", ADM1026_PWM_MAX);
} }
static ssize_t show_pwm_enable(struct device *dev, struct device_attribute *attr, char *buf)
static ssize_t show_pwm_enable(struct device *dev,
struct device_attribute *attr, char *buf)
{ {
struct adm1026_data *data = adm1026_update_device(dev); struct adm1026_data *data = adm1026_update_device(dev);
return sprintf(buf, "%d\n", data->pwm1.enable); return sprintf(buf, "%d\n", data->pwm1.enable);
} }
static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr, const char *buf,
size_t count) static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client); struct adm1026_data *data = i2c_get_clientdata(client);
int val = simple_strtol(buf, NULL, 10);
int old_enable; int old_enable;
unsigned long val;
int err;
if ((val >= 0) && (val < 3)) { err = kstrtoul(buf, 10, &val);
mutex_lock(&data->update_lock); if (err)
old_enable = data->pwm1.enable; return err;
data->pwm1.enable = val;
data->config1 = (data->config1 & ~CFG1_PWM_AFC) if (val >= 3)
| ((val == 2) ? CFG1_PWM_AFC : 0); return -EINVAL;
adm1026_write_value(client, ADM1026_REG_CONFIG1,
data->config1); mutex_lock(&data->update_lock);
if (val == 2) { /* apply pwm1_auto_pwm_min to pwm1 */ old_enable = data->pwm1.enable;
data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) | data->pwm1.enable = val;
PWM_MIN_TO_REG(data->pwm1.auto_pwm_min)); data->config1 = (data->config1 & ~CFG1_PWM_AFC)
adm1026_write_value(client, ADM1026_REG_PWM, | ((val == 2) ? CFG1_PWM_AFC : 0);
data->pwm1.pwm); adm1026_write_value(client, ADM1026_REG_CONFIG1, data->config1);
} else if (!((old_enable == 1) && (val == 1))) { if (val == 2) { /* apply pwm1_auto_pwm_min to pwm1 */
/* set pwm to safe value */ data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
data->pwm1.pwm = 255; PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
adm1026_write_value(client, ADM1026_REG_PWM, adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
data->pwm1.pwm); } else if (!((old_enable == 1) && (val == 1))) {
} /* set pwm to safe value */
mutex_unlock(&data->update_lock); data->pwm1.pwm = 255;
adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
} }
mutex_unlock(&data->update_lock);
return count; return count;
} }
@ -1716,7 +1850,8 @@ static int adm1026_probe(struct i2c_client *client,
adm1026_init_client(client); adm1026_init_client(client);
/* Register sysfs hooks */ /* Register sysfs hooks */
if ((err = sysfs_create_group(&client->dev.kobj, &adm1026_group))) err = sysfs_create_group(&client->dev.kobj, &adm1026_group);
if (err)
goto exitfree; goto exitfree;
if (data->config1 & CFG1_AIN8_9) if (data->config1 & CFG1_AIN8_9)
err = sysfs_create_group(&client->dev.kobj, err = sysfs_create_group(&client->dev.kobj,