diff options
Diffstat (limited to 'drivers/hwmon/adm9240.c')
| -rw-r--r-- | drivers/hwmon/adm9240.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c index 5ddc22fea4a3..43f6991b588c 100644 --- a/drivers/hwmon/adm9240.c +++ b/drivers/hwmon/adm9240.c | |||
| @@ -49,6 +49,7 @@ | |||
| 49 | #include <linux/hwmon.h> | 49 | #include <linux/hwmon.h> |
| 50 | #include <linux/hwmon-vid.h> | 50 | #include <linux/hwmon-vid.h> |
| 51 | #include <linux/err.h> | 51 | #include <linux/err.h> |
| 52 | #include <linux/mutex.h> | ||
| 52 | 53 | ||
| 53 | /* Addresses to scan */ | 54 | /* Addresses to scan */ |
| 54 | static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, | 55 | static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, |
| @@ -150,7 +151,7 @@ struct adm9240_data { | |||
| 150 | enum chips type; | 151 | enum chips type; |
| 151 | struct i2c_client client; | 152 | struct i2c_client client; |
| 152 | struct class_device *class_dev; | 153 | struct class_device *class_dev; |
| 153 | struct semaphore update_lock; | 154 | struct mutex update_lock; |
| 154 | char valid; | 155 | char valid; |
| 155 | unsigned long last_updated_measure; | 156 | unsigned long last_updated_measure; |
| 156 | unsigned long last_updated_config; | 157 | unsigned long last_updated_config; |
| @@ -195,11 +196,11 @@ static ssize_t set_max(struct device *dev, struct device_attribute *devattr, | |||
| 195 | struct adm9240_data *data = i2c_get_clientdata(client); | 196 | struct adm9240_data *data = i2c_get_clientdata(client); |
| 196 | long val = simple_strtol(buf, NULL, 10); | 197 | long val = simple_strtol(buf, NULL, 10); |
| 197 | 198 | ||
| 198 | down(&data->update_lock); | 199 | mutex_lock(&data->update_lock); |
| 199 | data->temp_max[attr->index] = TEMP_TO_REG(val); | 200 | data->temp_max[attr->index] = TEMP_TO_REG(val); |
| 200 | i2c_smbus_write_byte_data(client, ADM9240_REG_TEMP_MAX(attr->index), | 201 | i2c_smbus_write_byte_data(client, ADM9240_REG_TEMP_MAX(attr->index), |
| 201 | data->temp_max[attr->index]); | 202 | data->temp_max[attr->index]); |
| 202 | up(&data->update_lock); | 203 | mutex_unlock(&data->update_lock); |
| 203 | return count; | 204 | return count; |
| 204 | } | 205 | } |
| 205 | 206 | ||
| @@ -246,11 +247,11 @@ static ssize_t set_in_min(struct device *dev, | |||
| 246 | struct adm9240_data *data = i2c_get_clientdata(client); | 247 | struct adm9240_data *data = i2c_get_clientdata(client); |
| 247 | unsigned long val = simple_strtoul(buf, NULL, 10); | 248 | unsigned long val = simple_strtoul(buf, NULL, 10); |
| 248 | 249 | ||
| 249 | down(&data->update_lock); | 250 | mutex_lock(&data->update_lock); |
| 250 | data->in_min[attr->index] = IN_TO_REG(val, attr->index); | 251 | data->in_min[attr->index] = IN_TO_REG(val, attr->index); |
| 251 | i2c_smbus_write_byte_data(client, ADM9240_REG_IN_MIN(attr->index), | 252 | i2c_smbus_write_byte_data(client, ADM9240_REG_IN_MIN(attr->index), |
| 252 | data->in_min[attr->index]); | 253 | data->in_min[attr->index]); |
| 253 | up(&data->update_lock); | 254 | mutex_unlock(&data->update_lock); |
| 254 | return count; | 255 | return count; |
| 255 | } | 256 | } |
| 256 | 257 | ||
| @@ -263,11 +264,11 @@ static ssize_t set_in_max(struct device *dev, | |||
| 263 | struct adm9240_data *data = i2c_get_clientdata(client); | 264 | struct adm9240_data *data = i2c_get_clientdata(client); |
| 264 | unsigned long val = simple_strtoul(buf, NULL, 10); | 265 | unsigned long val = simple_strtoul(buf, NULL, 10); |
| 265 | 266 | ||
| 266 | down(&data->update_lock); | 267 | mutex_lock(&data->update_lock); |
| 267 | data->in_max[attr->index] = IN_TO_REG(val, attr->index); | 268 | data->in_max[attr->index] = IN_TO_REG(val, attr->index); |
| 268 | i2c_smbus_write_byte_data(client, ADM9240_REG_IN_MAX(attr->index), | 269 | i2c_smbus_write_byte_data(client, ADM9240_REG_IN_MAX(attr->index), |
| 269 | data->in_max[attr->index]); | 270 | data->in_max[attr->index]); |
| 270 | up(&data->update_lock); | 271 | mutex_unlock(&data->update_lock); |
| 271 | return count; | 272 | return count; |
| 272 | } | 273 | } |
| 273 | 274 | ||
| @@ -350,7 +351,7 @@ static ssize_t set_fan_min(struct device *dev, | |||
| 350 | int nr = attr->index; | 351 | int nr = attr->index; |
| 351 | u8 new_div; | 352 | u8 new_div; |
| 352 | 353 | ||
| 353 | down(&data->update_lock); | 354 | mutex_lock(&data->update_lock); |
| 354 | 355 | ||
| 355 | if (!val) { | 356 | if (!val) { |
| 356 | data->fan_min[nr] = 255; | 357 | data->fan_min[nr] = 255; |
| @@ -390,7 +391,7 @@ static ssize_t set_fan_min(struct device *dev, | |||
| 390 | i2c_smbus_write_byte_data(client, ADM9240_REG_FAN_MIN(nr), | 391 | i2c_smbus_write_byte_data(client, ADM9240_REG_FAN_MIN(nr), |
| 391 | data->fan_min[nr]); | 392 | data->fan_min[nr]); |
| 392 | 393 | ||
| 393 | up(&data->update_lock); | 394 | mutex_unlock(&data->update_lock); |
| 394 | return count; | 395 | return count; |
| 395 | } | 396 | } |
| 396 | 397 | ||
| @@ -439,10 +440,10 @@ static ssize_t set_aout(struct device *dev, | |||
| 439 | struct adm9240_data *data = i2c_get_clientdata(client); | 440 | struct adm9240_data *data = i2c_get_clientdata(client); |
| 440 | unsigned long val = simple_strtol(buf, NULL, 10); | 441 | unsigned long val = simple_strtol(buf, NULL, 10); |
| 441 | 442 | ||
| 442 | down(&data->update_lock); | 443 | mutex_lock(&data->update_lock); |
| 443 | data->aout = AOUT_TO_REG(val); | 444 | data->aout = AOUT_TO_REG(val); |
| 444 | i2c_smbus_write_byte_data(client, ADM9240_REG_ANALOG_OUT, data->aout); | 445 | i2c_smbus_write_byte_data(client, ADM9240_REG_ANALOG_OUT, data->aout); |
| 445 | up(&data->update_lock); | 446 | mutex_unlock(&data->update_lock); |
| 446 | return count; | 447 | return count; |
| 447 | } | 448 | } |
| 448 | static DEVICE_ATTR(aout_output, S_IRUGO | S_IWUSR, show_aout, set_aout); | 449 | static DEVICE_ATTR(aout_output, S_IRUGO | S_IWUSR, show_aout, set_aout); |
| @@ -539,7 +540,7 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind) | |||
| 539 | /* fill in the remaining client fields and attach */ | 540 | /* fill in the remaining client fields and attach */ |
| 540 | strlcpy(new_client->name, name, I2C_NAME_SIZE); | 541 | strlcpy(new_client->name, name, I2C_NAME_SIZE); |
| 541 | data->type = kind; | 542 | data->type = kind; |
| 542 | init_MUTEX(&data->update_lock); | 543 | mutex_init(&data->update_lock); |
| 543 | 544 | ||
| 544 | if ((err = i2c_attach_client(new_client))) | 545 | if ((err = i2c_attach_client(new_client))) |
| 545 | goto exit_free; | 546 | goto exit_free; |
| @@ -691,7 +692,7 @@ static struct adm9240_data *adm9240_update_device(struct device *dev) | |||
| 691 | struct adm9240_data *data = i2c_get_clientdata(client); | 692 | struct adm9240_data *data = i2c_get_clientdata(client); |
| 692 | int i; | 693 | int i; |
| 693 | 694 | ||
| 694 | down(&data->update_lock); | 695 | mutex_lock(&data->update_lock); |
| 695 | 696 | ||
| 696 | /* minimum measurement cycle: 1.75 seconds */ | 697 | /* minimum measurement cycle: 1.75 seconds */ |
| 697 | if (time_after(jiffies, data->last_updated_measure + (HZ * 7 / 4)) | 698 | if (time_after(jiffies, data->last_updated_measure + (HZ * 7 / 4)) |
| @@ -771,7 +772,7 @@ static struct adm9240_data *adm9240_update_device(struct device *dev) | |||
| 771 | data->last_updated_config = jiffies; | 772 | data->last_updated_config = jiffies; |
| 772 | data->valid = 1; | 773 | data->valid = 1; |
| 773 | } | 774 | } |
| 774 | up(&data->update_lock); | 775 | mutex_unlock(&data->update_lock); |
| 775 | return data; | 776 | return data; |
| 776 | } | 777 | } |
| 777 | 778 | ||
