adt7470.c (2e75a4b7ae0dd4bf7b34e41c2c3be7ac23b8f1cc) | adt7470.c (2f22d5dff6f95d777c4cb217b99bfdf1fe306128) |
---|---|
1/* 2 * A hwmon driver for the Analog Devices ADT7470 3 * Copyright (C) 2007 IBM 4 * 5 * Author: Darrick J. Wong <djwong@us.ibm.com> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by --- 115 unchanged lines hidden (view full) --- 124#define ADT7470_PWM_ALL_TEMPS 0x3FF 125 126/* How often do we reread sensors values? (In jiffies) */ 127#define SENSOR_REFRESH_INTERVAL (5 * HZ) 128 129/* How often do we reread sensor limit values? (In jiffies) */ 130#define LIMIT_REFRESH_INTERVAL (60 * HZ) 131 | 1/* 2 * A hwmon driver for the Analog Devices ADT7470 3 * Copyright (C) 2007 IBM 4 * 5 * Author: Darrick J. Wong <djwong@us.ibm.com> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by --- 115 unchanged lines hidden (view full) --- 124#define ADT7470_PWM_ALL_TEMPS 0x3FF 125 126/* How often do we reread sensors values? (In jiffies) */ 127#define SENSOR_REFRESH_INTERVAL (5 * HZ) 128 129/* How often do we reread sensor limit values? (In jiffies) */ 130#define LIMIT_REFRESH_INTERVAL (60 * HZ) 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 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)) 137#define FAN_RPM_TO_PERIOD FAN_PERIOD_TO_RPM 138#define FAN_PERIOD_INVALID 65535 139#define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) 140 141struct adt7470_data { 142 struct device *hwmon_dev; 143 struct attribute_group attrs; 144 struct mutex lock; 145 char sensors_valid; 146 char limits_valid; 147 unsigned long sensors_last_updated; /* In jiffies */ 148 unsigned long limits_last_updated; /* In jiffies */ 149 | 134 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)) 137#define FAN_RPM_TO_PERIOD FAN_PERIOD_TO_RPM 138#define FAN_PERIOD_INVALID 65535 139#define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) 140 141struct adt7470_data { 142 struct device *hwmon_dev; 143 struct attribute_group attrs; 144 struct mutex lock; 145 char sensors_valid; 146 char limits_valid; 147 unsigned long sensors_last_updated; /* In jiffies */ 148 unsigned long limits_last_updated; /* In jiffies */ 149 |
150 int num_temp_sensors; /* -1 = probe */ 151 |
|
150 s8 temp[ADT7470_TEMP_COUNT]; 151 s8 temp_min[ADT7470_TEMP_COUNT]; 152 s8 temp_max[ADT7470_TEMP_COUNT]; 153 u16 fan[ADT7470_FAN_COUNT]; 154 u16 fan_min[ADT7470_FAN_COUNT]; 155 u16 fan_max[ADT7470_FAN_COUNT]; 156 u16 alarm; 157 u16 alarms_mask; --- 93 unchanged lines hidden (view full) --- 251 for (i = 0; i < ADT7470_FAN_COUNT; i++) 252 i2c_smbus_write_byte_data(client, ADT7470_REG_PWM(i), pwm[i]); 253 254 /* start reading temperature sensors */ 255 cfg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG); 256 cfg |= 0x80; 257 i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, cfg); 258 | 152 s8 temp[ADT7470_TEMP_COUNT]; 153 s8 temp_min[ADT7470_TEMP_COUNT]; 154 s8 temp_max[ADT7470_TEMP_COUNT]; 155 u16 fan[ADT7470_FAN_COUNT]; 156 u16 fan_min[ADT7470_FAN_COUNT]; 157 u16 fan_max[ADT7470_FAN_COUNT]; 158 u16 alarm; 159 u16 alarms_mask; --- 93 unchanged lines hidden (view full) --- 253 for (i = 0; i < ADT7470_FAN_COUNT; i++) 254 i2c_smbus_write_byte_data(client, ADT7470_REG_PWM(i), pwm[i]); 255 256 /* start reading temperature sensors */ 257 cfg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG); 258 cfg |= 0x80; 259 i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, cfg); 260 |
259 /* 260 * Delay is 200ms * number of tmp05 sensors. Too bad 261 * there's no way to figure out how many are connected. 262 * For now, assume 1s will work. 263 */ 264 msleep(TEMP_COLLECTION_TIME); | 261 /* Delay is 200ms * number of temp sensors. */ 262 msleep((data->num_temp_sensors >= 0 ? 263 data->num_temp_sensors * 200 : 264 TEMP_COLLECTION_TIME)); |
265 266 /* done reading temperature sensors */ 267 cfg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG); 268 cfg &= ~0x80; 269 i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, cfg); 270 271 /* restore pwm[1-4] config registers */ 272 i2c_smbus_write_byte_data(client, ADT7470_REG_PWM_CFG(0), pwm_cfg[0]); 273 i2c_smbus_write_byte_data(client, ADT7470_REG_PWM_CFG(2), pwm_cfg[1]); 274 275 for (i = 0; i < ADT7470_TEMP_COUNT; i++) 276 data->temp[i] = i2c_smbus_read_byte_data(client, 277 ADT7470_TEMP_REG(i)); 278 | 265 266 /* done reading temperature sensors */ 267 cfg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG); 268 cfg &= ~0x80; 269 i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, cfg); 270 271 /* restore pwm[1-4] config registers */ 272 i2c_smbus_write_byte_data(client, ADT7470_REG_PWM_CFG(0), pwm_cfg[0]); 273 i2c_smbus_write_byte_data(client, ADT7470_REG_PWM_CFG(2), pwm_cfg[1]); 274 275 for (i = 0; i < ADT7470_TEMP_COUNT; i++) 276 data->temp[i] = i2c_smbus_read_byte_data(client, 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; 284 |
|
279 for (i = 0; i < ADT7470_FAN_COUNT; i++) 280 data->fan[i] = adt7470_read_word_data(client, 281 ADT7470_REG_FAN(i)); 282 283 for (i = 0; i < ADT7470_PWM_COUNT; i++) { 284 int reg; 285 int reg_mask; 286 --- 67 unchanged lines hidden (view full) --- 354 data->limits_last_updated = local_jiffies; 355 data->limits_valid = 1; 356 357out: 358 mutex_unlock(&data->lock); 359 return data; 360} 361 | 285 for (i = 0; i < ADT7470_FAN_COUNT; i++) 286 data->fan[i] = adt7470_read_word_data(client, 287 ADT7470_REG_FAN(i)); 288 289 for (i = 0; i < ADT7470_PWM_COUNT; i++) { 290 int reg; 291 int reg_mask; 292 --- 67 unchanged lines hidden (view full) --- 360 data->limits_last_updated = local_jiffies; 361 data->limits_valid = 1; 362 363out: 364 mutex_unlock(&data->lock); 365 return data; 366} 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, 363 struct device_attribute *devattr, 364 char *buf) 365{ 366 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 367 struct adt7470_data *data = adt7470_update_device(dev); 368 return sprintf(buf, "%d\n", 1000 * data->temp_min[attr->index]); 369} --- 450 unchanged lines hidden (view full) --- 820 821 if (data->alarm & attr->index) 822 return sprintf(buf, "1\n"); 823 else 824 return sprintf(buf, "0\n"); 825} 826 827static DEVICE_ATTR(alarm_mask, S_IRUGO, show_alarm_mask, NULL); | 397static ssize_t show_temp_min(struct device *dev, 398 struct device_attribute *devattr, 399 char *buf) 400{ 401 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 402 struct adt7470_data *data = adt7470_update_device(dev); 403 return sprintf(buf, "%d\n", 1000 * data->temp_min[attr->index]); 404} --- 450 unchanged lines hidden (view full) --- 855 856 if (data->alarm & attr->index) 857 return sprintf(buf, "1\n"); 858 else 859 return sprintf(buf, "0\n"); 860} 861 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 829static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, 830 set_temp_max, 0); 831static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_max, 832 set_temp_max, 1); 833static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_temp_max, 834 set_temp_max, 2); 835static SENSOR_DEVICE_ATTR(temp4_max, S_IWUSR | S_IRUGO, show_temp_max, --- 156 unchanged lines hidden (view full) --- 992static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IWUSR | S_IRUGO, 993 show_pwm_auto_temp, set_pwm_auto_temp, 2); 994static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO, 995 show_pwm_auto_temp, set_pwm_auto_temp, 3); 996 997static struct attribute *adt7470_attr[] = 998{ 999 &dev_attr_alarm_mask.attr, | 865 866static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, 867 set_temp_max, 0); 868static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_max, 869 set_temp_max, 1); 870static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_temp_max, 871 set_temp_max, 2); 872static SENSOR_DEVICE_ATTR(temp4_max, S_IWUSR | S_IRUGO, show_temp_max, --- 156 unchanged lines hidden (view full) --- 1029static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IWUSR | S_IRUGO, 1030 show_pwm_auto_temp, set_pwm_auto_temp, 2); 1031static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO, 1032 show_pwm_auto_temp, set_pwm_auto_temp, 3); 1033 1034static struct attribute *adt7470_attr[] = 1035{ 1036 &dev_attr_alarm_mask.attr, |
1037 &dev_attr_num_temp_sensors.attr, |
|
1000 &sensor_dev_attr_temp1_max.dev_attr.attr, 1001 &sensor_dev_attr_temp2_max.dev_attr.attr, 1002 &sensor_dev_attr_temp3_max.dev_attr.attr, 1003 &sensor_dev_attr_temp4_max.dev_attr.attr, 1004 &sensor_dev_attr_temp5_max.dev_attr.attr, 1005 &sensor_dev_attr_temp6_max.dev_attr.attr, 1006 &sensor_dev_attr_temp7_max.dev_attr.attr, 1007 &sensor_dev_attr_temp8_max.dev_attr.attr, --- 116 unchanged lines hidden (view full) --- 1124 int err; 1125 1126 data = kzalloc(sizeof(struct adt7470_data), GFP_KERNEL); 1127 if (!data) { 1128 err = -ENOMEM; 1129 goto exit; 1130 } 1131 | 1038 &sensor_dev_attr_temp1_max.dev_attr.attr, 1039 &sensor_dev_attr_temp2_max.dev_attr.attr, 1040 &sensor_dev_attr_temp3_max.dev_attr.attr, 1041 &sensor_dev_attr_temp4_max.dev_attr.attr, 1042 &sensor_dev_attr_temp5_max.dev_attr.attr, 1043 &sensor_dev_attr_temp6_max.dev_attr.attr, 1044 &sensor_dev_attr_temp7_max.dev_attr.attr, 1045 &sensor_dev_attr_temp8_max.dev_attr.attr, --- 116 unchanged lines hidden (view full) --- 1162 int err; 1163 1164 data = kzalloc(sizeof(struct adt7470_data), GFP_KERNEL); 1165 if (!data) { 1166 err = -ENOMEM; 1167 goto exit; 1168 } 1169 |
1170 data->num_temp_sensors = -1; 1171 |
|
1132 i2c_set_clientdata(client, data); 1133 mutex_init(&data->lock); 1134 1135 dev_info(&client->dev, "%s chip found\n", client->name); 1136 1137 /* Initialize the ADT7470 chip */ 1138 adt7470_init_client(client); 1139 --- 47 unchanged lines hidden --- | 1172 i2c_set_clientdata(client, data); 1173 mutex_init(&data->lock); 1174 1175 dev_info(&client->dev, "%s chip found\n", client->name); 1176 1177 /* Initialize the ADT7470 chip */ 1178 adt7470_init_client(client); 1179 --- 47 unchanged lines hidden --- |