Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Darrick J. Wong and committed by
Linus Torvalds
2f22d5df 2e75a4b7

+48 -8
+48 -8
drivers/hwmon/adt7470.c
··· 129 129 /* How often do we reread sensor limit values? (In jiffies) */ 130 130 #define LIMIT_REFRESH_INTERVAL (60 * HZ) 131 131 132 - /* sleep 1s while gathering temperature data */ 133 - #define TEMP_COLLECTION_TIME 1000 132 + /* Wait at least 200ms per sensor for 10 sensors */ 133 + #define TEMP_COLLECTION_TIME 2000 134 134 135 135 /* datasheet says to divide this number by the fan reading to get fan rpm */ 136 136 #define FAN_PERIOD_TO_RPM(x) ((90000 * 60) / (x)) ··· 146 146 char limits_valid; 147 147 unsigned long sensors_last_updated; /* In jiffies */ 148 148 unsigned long limits_last_updated; /* In jiffies */ 149 + 150 + int num_temp_sensors; /* -1 = probe */ 149 151 150 152 s8 temp[ADT7470_TEMP_COUNT]; 151 153 s8 temp_min[ADT7470_TEMP_COUNT]; ··· 258 256 cfg |= 0x80; 259 257 i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, cfg); 260 258 261 - /* 262 - * Delay is 200ms * number of tmp05 sensors. Too bad 263 - * there's no way to figure out how many are connected. 264 - * For now, assume 1s will work. 265 - */ 266 - msleep(TEMP_COLLECTION_TIME); 259 + /* Delay is 200ms * number of temp sensors. */ 260 + msleep((data->num_temp_sensors >= 0 ? 261 + data->num_temp_sensors * 200 : 262 + TEMP_COLLECTION_TIME)); 267 263 268 264 /* done reading temperature sensors */ 269 265 cfg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG); ··· 275 275 for (i = 0; i < ADT7470_TEMP_COUNT; i++) 276 276 data->temp[i] = i2c_smbus_read_byte_data(client, 277 277 ADT7470_TEMP_REG(i)); 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; 278 284 279 285 for (i = 0; i < ADT7470_FAN_COUNT; i++) 280 286 data->fan[i] = adt7470_read_word_data(client, ··· 363 357 out: 364 358 mutex_unlock(&data->lock); 365 359 return data; 360 + } 361 + 362 + static ssize_t show_num_temp_sensors(struct device *dev, 363 + struct device_attribute *devattr, 364 + char *buf) 365 + { 366 + struct adt7470_data *data = adt7470_update_device(dev); 367 + return sprintf(buf, "%d\n", data->num_temp_sensors); 368 + } 369 + 370 + static ssize_t set_num_temp_sensors(struct device *dev, 371 + struct device_attribute *devattr, 372 + const char *buf, 373 + size_t count) 374 + { 375 + struct i2c_client *client = to_i2c_client(dev); 376 + struct adt7470_data *data = i2c_get_clientdata(client); 377 + long temp; 378 + 379 + if (strict_strtol(buf, 10, &temp)) 380 + return -EINVAL; 381 + 382 + temp = SENSORS_LIMIT(temp, -1, 10); 383 + 384 + mutex_lock(&data->lock); 385 + data->num_temp_sensors = temp; 386 + mutex_unlock(&data->lock); 387 + 388 + return count; 366 389 } 367 390 368 391 static ssize_t show_temp_min(struct device *dev, ··· 860 825 } 861 826 862 827 static DEVICE_ATTR(alarm_mask, S_IRUGO, show_alarm_mask, NULL); 828 + static DEVICE_ATTR(num_temp_sensors, S_IWUSR | S_IRUGO, show_num_temp_sensors, 829 + set_num_temp_sensors); 863 830 864 831 static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, 865 832 set_temp_max, 0); ··· 1034 997 static struct attribute *adt7470_attr[] = 1035 998 { 1036 999 &dev_attr_alarm_mask.attr, 1000 + &dev_attr_num_temp_sensors.attr, 1037 1001 &sensor_dev_attr_temp1_max.dev_attr.attr, 1038 1002 &sensor_dev_attr_temp2_max.dev_attr.attr, 1039 1003 &sensor_dev_attr_temp3_max.dev_attr.attr, ··· 1166 1128 err = -ENOMEM; 1167 1129 goto exit; 1168 1130 } 1131 + 1132 + data->num_temp_sensors = -1; 1169 1133 1170 1134 i2c_set_clientdata(client, data); 1171 1135 mutex_init(&data->lock);