aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorMichael Abbott <michael@araneidae.co.uk>2009-09-21 20:04:47 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-09-22 10:17:49 -0400
commit905ffdc35e50844ab45bbc59d5302238844f8526 (patch)
tree13f5fcb88fe9b8f049181234749ea715b509e34b /drivers/hwmon
parentf266889517252bc697e7103bcd6ed46bdf2c1579 (diff)
drivers/hwmon/adm1021.c: add low_power support for adm1021 driver
Occasionally it is helpful to be able to turn a temperature sensor off (for example if it's making unwanted electrical noise). This patch adds a sysfs node to put any adm1021 compatible device into low power mode. Signed-off-by: Michael Abbott <michael.abbott@diamond.ac.uk> Cc: Jean Delvare <khali@linux-fr.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/adm1021.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/drivers/hwmon/adm1021.c b/drivers/hwmon/adm1021.c
index de84398775b6..afc594318125 100644
--- a/drivers/hwmon/adm1021.c
+++ b/drivers/hwmon/adm1021.c
@@ -83,6 +83,7 @@ struct adm1021_data {
83 83
84 struct mutex update_lock; 84 struct mutex update_lock;
85 char valid; /* !=0 if following fields are valid */ 85 char valid; /* !=0 if following fields are valid */
86 char low_power; /* !=0 if device in low power mode */
86 unsigned long last_updated; /* In jiffies */ 87 unsigned long last_updated; /* In jiffies */
87 88
88 int temp_max[2]; /* Register values */ 89 int temp_max[2]; /* Register values */
@@ -213,6 +214,35 @@ static ssize_t set_temp_min(struct device *dev,
213 return count; 214 return count;
214} 215}
215 216
217static ssize_t show_low_power(struct device *dev,
218 struct device_attribute *devattr, char *buf)
219{
220 struct adm1021_data *data = adm1021_update_device(dev);
221 return sprintf(buf, "%d\n", data->low_power);
222}
223
224static ssize_t set_low_power(struct device *dev,
225 struct device_attribute *devattr,
226 const char *buf, size_t count)
227{
228 struct i2c_client *client = to_i2c_client(dev);
229 struct adm1021_data *data = i2c_get_clientdata(client);
230 int low_power = simple_strtol(buf, NULL, 10) != 0;
231
232 mutex_lock(&data->update_lock);
233 if (low_power != data->low_power) {
234 int config = i2c_smbus_read_byte_data(
235 client, ADM1021_REG_CONFIG_R);
236 data->low_power = low_power;
237 i2c_smbus_write_byte_data(client, ADM1021_REG_CONFIG_W,
238 (config & 0xBF) | (low_power << 6));
239 }
240 mutex_unlock(&data->update_lock);
241
242 return count;
243}
244
245
216static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); 246static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
217static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, 247static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max,
218 set_temp_max, 0); 248 set_temp_max, 0);
@@ -230,6 +260,7 @@ static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3);
230static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2); 260static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2);
231 261
232static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 262static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
263static DEVICE_ATTR(low_power, S_IWUSR | S_IRUGO, show_low_power, set_low_power);
233 264
234static struct attribute *adm1021_attributes[] = { 265static struct attribute *adm1021_attributes[] = {
235 &sensor_dev_attr_temp1_max.dev_attr.attr, 266 &sensor_dev_attr_temp1_max.dev_attr.attr,
@@ -244,6 +275,7 @@ static struct attribute *adm1021_attributes[] = {
244 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, 275 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
245 &sensor_dev_attr_temp2_fault.dev_attr.attr, 276 &sensor_dev_attr_temp2_fault.dev_attr.attr,
246 &dev_attr_alarms.attr, 277 &dev_attr_alarms.attr,
278 &dev_attr_low_power.attr,
247 NULL 279 NULL
248}; 280};
249 281