aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@us.ibm.com>2009-01-06 17:41:33 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-01-06 18:59:18 -0500
commit2f22d5dff6f95d777c4cb217b99bfdf1fe306128 (patch)
tree202dd8881df451ceba4be0aa43169049fa58a9eb /drivers/hwmon
parent2e75a4b7ae0dd4bf7b34e41c2c3be7ac23b8f1cc (diff)
adt7470: observe the number of temperature sensors to shorten update time
The adt7470 driver currently assumes that 1s is the proper time to wait to read all temperature sensors. However, the correct time is 200ms * number_of_sensors. This patch sets the default time to provide for 10 sensors and then lowers it based on the number of sensor inputs that have nozero values. Signed-off-by: Darrick J. Wong <djwong@us.ibm.com> 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/adt7470.c56
1 files changed, 48 insertions, 8 deletions
diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
index b7a442a80bde..ab8d5ebc9f75 100644
--- a/drivers/hwmon/adt7470.c
+++ b/drivers/hwmon/adt7470.c
@@ -129,8 +129,8 @@ I2C_CLIENT_INSMOD_1(adt7470);
129/* How often do we reread sensor limit values? (In jiffies) */ 129/* How often do we reread sensor limit values? (In jiffies) */
130#define LIMIT_REFRESH_INTERVAL (60 * HZ) 130#define LIMIT_REFRESH_INTERVAL (60 * HZ)
131 131
132/* sleep 1s while gathering temperature data */ 132/* Wait at least 200ms per sensor for 10 sensors */
133#define TEMP_COLLECTION_TIME 1000 133#define TEMP_COLLECTION_TIME 2000
134 134
135/* datasheet says to divide this number by the fan reading to get fan rpm */ 135/* datasheet says to divide this number by the fan reading to get fan rpm */
136#define FAN_PERIOD_TO_RPM(x) ((90000 * 60) / (x)) 136#define FAN_PERIOD_TO_RPM(x) ((90000 * 60) / (x))
@@ -147,6 +147,8 @@ struct adt7470_data {
147 unsigned long sensors_last_updated; /* In jiffies */ 147 unsigned long sensors_last_updated; /* In jiffies */
148 unsigned long limits_last_updated; /* In jiffies */ 148 unsigned long limits_last_updated; /* In jiffies */
149 149
150 int num_temp_sensors; /* -1 = probe */
151
150 s8 temp[ADT7470_TEMP_COUNT]; 152 s8 temp[ADT7470_TEMP_COUNT];
151 s8 temp_min[ADT7470_TEMP_COUNT]; 153 s8 temp_min[ADT7470_TEMP_COUNT];
152 s8 temp_max[ADT7470_TEMP_COUNT]; 154 s8 temp_max[ADT7470_TEMP_COUNT];
@@ -256,12 +258,10 @@ static struct adt7470_data *adt7470_update_device(struct device *dev)
256 cfg |= 0x80; 258 cfg |= 0x80;
257 i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, cfg); 259 i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, cfg);
258 260
259 /* 261 /* Delay is 200ms * number of temp sensors. */
260 * Delay is 200ms * number of tmp05 sensors. Too bad 262 msleep((data->num_temp_sensors >= 0 ?
261 * there's no way to figure out how many are connected. 263 data->num_temp_sensors * 200 :
262 * For now, assume 1s will work. 264 TEMP_COLLECTION_TIME));
263 */
264 msleep(TEMP_COLLECTION_TIME);
265 265
266 /* done reading temperature sensors */ 266 /* done reading temperature sensors */
267 cfg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG); 267 cfg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG);
@@ -276,6 +276,12 @@ static struct adt7470_data *adt7470_update_device(struct device *dev)
276 data->temp[i] = i2c_smbus_read_byte_data(client, 276 data->temp[i] = i2c_smbus_read_byte_data(client,
277 ADT7470_TEMP_REG(i)); 277 ADT7470_TEMP_REG(i));
278 278
279 /* Figure out the number of temp sensors */
280 if (data->num_temp_sensors < 0)
281 for (i = 0; i < ADT7470_TEMP_COUNT; i++)
282 if (data->temp[i])
283 data->num_temp_sensors = i + 1;
284
279 for (i = 0; i < ADT7470_FAN_COUNT; i++) 285 for (i = 0; i < ADT7470_FAN_COUNT; i++)
280 data->fan[i] = adt7470_read_word_data(client, 286 data->fan[i] = adt7470_read_word_data(client,
281 ADT7470_REG_FAN(i)); 287 ADT7470_REG_FAN(i));
@@ -359,6 +365,35 @@ out:
359 return data; 365 return data;
360} 366}
361 367
368static ssize_t show_num_temp_sensors(struct device *dev,
369 struct device_attribute *devattr,
370 char *buf)
371{
372 struct adt7470_data *data = adt7470_update_device(dev);
373 return sprintf(buf, "%d\n", data->num_temp_sensors);
374}
375
376static ssize_t set_num_temp_sensors(struct device *dev,
377 struct device_attribute *devattr,
378 const char *buf,
379 size_t count)
380{
381 struct i2c_client *client = to_i2c_client(dev);
382 struct adt7470_data *data = i2c_get_clientdata(client);
383 long temp;
384
385 if (strict_strtol(buf, 10, &temp))
386 return -EINVAL;
387
388 temp = SENSORS_LIMIT(temp, -1, 10);
389
390 mutex_lock(&data->lock);
391 data->num_temp_sensors = temp;
392 mutex_unlock(&data->lock);
393
394 return count;
395}
396
362static ssize_t show_temp_min(struct device *dev, 397static ssize_t show_temp_min(struct device *dev,
363 struct device_attribute *devattr, 398 struct device_attribute *devattr,
364 char *buf) 399 char *buf)
@@ -825,6 +860,8 @@ static ssize_t show_alarm(struct device *dev,
825} 860}
826 861
827static DEVICE_ATTR(alarm_mask, S_IRUGO, show_alarm_mask, NULL); 862static DEVICE_ATTR(alarm_mask, S_IRUGO, show_alarm_mask, NULL);
863static DEVICE_ATTR(num_temp_sensors, S_IWUSR | S_IRUGO, show_num_temp_sensors,
864 set_num_temp_sensors);
828 865
829static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, 866static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max,
830 set_temp_max, 0); 867 set_temp_max, 0);
@@ -997,6 +1034,7 @@ static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO,
997static struct attribute *adt7470_attr[] = 1034static struct attribute *adt7470_attr[] =
998{ 1035{
999 &dev_attr_alarm_mask.attr, 1036 &dev_attr_alarm_mask.attr,
1037 &dev_attr_num_temp_sensors.attr,
1000 &sensor_dev_attr_temp1_max.dev_attr.attr, 1038 &sensor_dev_attr_temp1_max.dev_attr.attr,
1001 &sensor_dev_attr_temp2_max.dev_attr.attr, 1039 &sensor_dev_attr_temp2_max.dev_attr.attr,
1002 &sensor_dev_attr_temp3_max.dev_attr.attr, 1040 &sensor_dev_attr_temp3_max.dev_attr.attr,
@@ -1129,6 +1167,8 @@ static int adt7470_probe(struct i2c_client *client,
1129 goto exit; 1167 goto exit;
1130 } 1168 }
1131 1169
1170 data->num_temp_sensors = -1;
1171
1132 i2c_set_clientdata(client, data); 1172 i2c_set_clientdata(client, data);
1133 mutex_init(&data->lock); 1173 mutex_init(&data->lock);
1134 1174