Blame view
drivers/hwmon/adt7470.c
41.3 KB
6f9703d0b hwmon: add suppor... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
/* * A hwmon driver for the Analog Devices ADT7470 * Copyright (C) 2007 IBM * * Author: Darrick J. Wong <djwong@us.ibm.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <linux/module.h> #include <linux/jiffies.h> #include <linux/i2c.h> #include <linux/hwmon.h> #include <linux/hwmon-sysfs.h> #include <linux/err.h> #include <linux/mutex.h> #include <linux/delay.h> #include <linux/log2.h> |
89fac11cb adt7470: make aut... |
31 |
#include <linux/kthread.h> |
5a0e3ad6a include cleanup: ... |
32 |
#include <linux/slab.h> |
6f9703d0b hwmon: add suppor... |
33 34 |
/* Addresses to scan */ |
25e9c86d5 hwmon: normal_i2c... |
35 |
static const unsigned short normal_i2c[] = { 0x2C, 0x2E, 0x2F, I2C_CLIENT_END }; |
6f9703d0b hwmon: add suppor... |
36 |
|
6f9703d0b hwmon: add suppor... |
37 38 39 40 41 42 43 44 45 46 47 48 49 |
/* ADT7470 registers */ #define ADT7470_REG_BASE_ADDR 0x20 #define ADT7470_REG_TEMP_BASE_ADDR 0x20 #define ADT7470_REG_TEMP_MAX_ADDR 0x29 #define ADT7470_REG_FAN_BASE_ADDR 0x2A #define ADT7470_REG_FAN_MAX_ADDR 0x31 #define ADT7470_REG_PWM_BASE_ADDR 0x32 #define ADT7470_REG_PWM_MAX_ADDR 0x35 #define ADT7470_REG_PWM_MAX_BASE_ADDR 0x38 #define ADT7470_REG_PWM_MAX_MAX_ADDR 0x3B #define ADT7470_REG_CFG 0x40 #define ADT7470_FSPD_MASK 0x04 #define ADT7470_REG_ALARM1 0x41 |
fe03f28cf hwmon: (adt7470) ... |
50 51 52 53 54 55 56 57 |
#define ADT7470_R1T_ALARM 0x01 #define ADT7470_R2T_ALARM 0x02 #define ADT7470_R3T_ALARM 0x04 #define ADT7470_R4T_ALARM 0x08 #define ADT7470_R5T_ALARM 0x10 #define ADT7470_R6T_ALARM 0x20 #define ADT7470_R7T_ALARM 0x40 #define ADT7470_OOL_ALARM 0x80 |
6f9703d0b hwmon: add suppor... |
58 |
#define ADT7470_REG_ALARM2 0x42 |
fe03f28cf hwmon: (adt7470) ... |
59 60 61 62 63 64 65 |
#define ADT7470_R8T_ALARM 0x01 #define ADT7470_R9T_ALARM 0x02 #define ADT7470_R10T_ALARM 0x04 #define ADT7470_FAN1_ALARM 0x10 #define ADT7470_FAN2_ALARM 0x20 #define ADT7470_FAN3_ALARM 0x40 #define ADT7470_FAN4_ALARM 0x80 |
6f9703d0b hwmon: add suppor... |
66 67 68 69 70 71 72 73 74 75 |
#define ADT7470_REG_TEMP_LIMITS_BASE_ADDR 0x44 #define ADT7470_REG_TEMP_LIMITS_MAX_ADDR 0x57 #define ADT7470_REG_FAN_MIN_BASE_ADDR 0x58 #define ADT7470_REG_FAN_MIN_MAX_ADDR 0x5F #define ADT7470_REG_FAN_MAX_BASE_ADDR 0x60 #define ADT7470_REG_FAN_MAX_MAX_ADDR 0x67 #define ADT7470_REG_PWM_CFG_BASE_ADDR 0x68 #define ADT7470_REG_PWM12_CFG 0x68 #define ADT7470_PWM2_AUTO_MASK 0x40 #define ADT7470_PWM1_AUTO_MASK 0x80 |
2e75a4b7a adt7470: fix pwm ... |
76 |
#define ADT7470_PWM_AUTO_MASK 0xC0 |
6f9703d0b hwmon: add suppor... |
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
#define ADT7470_REG_PWM34_CFG 0x69 #define ADT7470_PWM3_AUTO_MASK 0x40 #define ADT7470_PWM4_AUTO_MASK 0x80 #define ADT7470_REG_PWM_MIN_BASE_ADDR 0x6A #define ADT7470_REG_PWM_MIN_MAX_ADDR 0x6D #define ADT7470_REG_PWM_TEMP_MIN_BASE_ADDR 0x6E #define ADT7470_REG_PWM_TEMP_MIN_MAX_ADDR 0x71 #define ADT7470_REG_ACOUSTICS12 0x75 #define ADT7470_REG_ACOUSTICS34 0x76 #define ADT7470_REG_DEVICE 0x3D #define ADT7470_REG_VENDOR 0x3E #define ADT7470_REG_REVISION 0x3F #define ADT7470_REG_ALARM1_MASK 0x72 #define ADT7470_REG_ALARM2_MASK 0x73 #define ADT7470_REG_PWM_AUTO_TEMP_BASE_ADDR 0x7C #define ADT7470_REG_PWM_AUTO_TEMP_MAX_ADDR 0x7D #define ADT7470_REG_MAX_ADDR 0x81 #define ADT7470_TEMP_COUNT 10 #define ADT7470_TEMP_REG(x) (ADT7470_REG_TEMP_BASE_ADDR + (x)) #define ADT7470_TEMP_MIN_REG(x) (ADT7470_REG_TEMP_LIMITS_BASE_ADDR + ((x) * 2)) #define ADT7470_TEMP_MAX_REG(x) (ADT7470_REG_TEMP_LIMITS_BASE_ADDR + \ ((x) * 2) + 1) #define ADT7470_FAN_COUNT 4 #define ADT7470_REG_FAN(x) (ADT7470_REG_FAN_BASE_ADDR + ((x) * 2)) #define ADT7470_REG_FAN_MIN(x) (ADT7470_REG_FAN_MIN_BASE_ADDR + ((x) * 2)) #define ADT7470_REG_FAN_MAX(x) (ADT7470_REG_FAN_MAX_BASE_ADDR + ((x) * 2)) #define ADT7470_PWM_COUNT 4 #define ADT7470_REG_PWM(x) (ADT7470_REG_PWM_BASE_ADDR + (x)) #define ADT7470_REG_PWM_MAX(x) (ADT7470_REG_PWM_MAX_BASE_ADDR + (x)) #define ADT7470_REG_PWM_MIN(x) (ADT7470_REG_PWM_MIN_BASE_ADDR + (x)) #define ADT7470_REG_PWM_TMIN(x) (ADT7470_REG_PWM_TEMP_MIN_BASE_ADDR + (x)) #define ADT7470_REG_PWM_CFG(x) (ADT7470_REG_PWM_CFG_BASE_ADDR + ((x) / 2)) #define ADT7470_REG_PWM_AUTO_TEMP(x) (ADT7470_REG_PWM_AUTO_TEMP_BASE_ADDR + \ ((x) / 2)) |
fe03f28cf hwmon: (adt7470) ... |
114 |
#define ALARM2(x) ((x) << 8) |
6f9703d0b hwmon: add suppor... |
115 116 117 118 119 120 121 122 123 124 125 126 127 |
#define ADT7470_VENDOR 0x41 #define ADT7470_DEVICE 0x70 /* datasheet only mentions a revision 2 */ #define ADT7470_REVISION 0x02 /* "all temps" according to hwmon sysfs interface spec */ #define ADT7470_PWM_ALL_TEMPS 0x3FF /* How often do we reread sensors values? (In jiffies) */ #define SENSOR_REFRESH_INTERVAL (5 * HZ) /* How often do we reread sensor limit values? (In jiffies) */ #define LIMIT_REFRESH_INTERVAL (60 * HZ) |
2f22d5dff adt7470: observe ... |
128 129 |
/* Wait at least 200ms per sensor for 10 sensors */ #define TEMP_COLLECTION_TIME 2000 |
6f9703d0b hwmon: add suppor... |
130 |
|
89fac11cb adt7470: make aut... |
131 132 |
/* auto update thing won't fire more than every 2s */ #define AUTO_UPDATE_INTERVAL 2000 |
6f9703d0b hwmon: add suppor... |
133 134 135 136 137 138 139 |
/* datasheet says to divide this number by the fan reading to get fan rpm */ #define FAN_PERIOD_TO_RPM(x) ((90000 * 60) / (x)) #define FAN_RPM_TO_PERIOD FAN_PERIOD_TO_RPM #define FAN_PERIOD_INVALID 65535 #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) struct adt7470_data { |
1beeffe43 hwmon: Convert fr... |
140 |
struct device *hwmon_dev; |
6f9703d0b hwmon: add suppor... |
141 142 143 144 145 146 |
struct attribute_group attrs; struct mutex lock; char sensors_valid; char limits_valid; unsigned long sensors_last_updated; /* In jiffies */ unsigned long limits_last_updated; /* In jiffies */ |
2f22d5dff adt7470: observe ... |
147 |
int num_temp_sensors; /* -1 = probe */ |
89fac11cb adt7470: make aut... |
148 |
int temperatures_probed; |
2f22d5dff adt7470: observe ... |
149 |
|
6f9703d0b hwmon: add suppor... |
150 151 152 153 154 155 |
s8 temp[ADT7470_TEMP_COUNT]; s8 temp_min[ADT7470_TEMP_COUNT]; s8 temp_max[ADT7470_TEMP_COUNT]; u16 fan[ADT7470_FAN_COUNT]; u16 fan_min[ADT7470_FAN_COUNT]; u16 fan_max[ADT7470_FAN_COUNT]; |
fe03f28cf hwmon: (adt7470) ... |
156 157 |
u16 alarm; u16 alarms_mask; |
6f9703d0b hwmon: add suppor... |
158 159 160 161 162 163 164 |
u8 force_pwm_max; u8 pwm[ADT7470_PWM_COUNT]; u8 pwm_max[ADT7470_PWM_COUNT]; u8 pwm_automatic[ADT7470_PWM_COUNT]; u8 pwm_min[ADT7470_PWM_COUNT]; s8 pwm_tmin[ADT7470_PWM_COUNT]; u8 pwm_auto_temp[ADT7470_PWM_COUNT]; |
89fac11cb adt7470: make aut... |
165 166 167 168 |
struct task_struct *auto_update; struct completion auto_update_stop; unsigned int auto_update_interval; |
6f9703d0b hwmon: add suppor... |
169 |
}; |
008f1ca51 hwmon: (adt7470) ... |
170 171 |
static int adt7470_probe(struct i2c_client *client, const struct i2c_device_id *id); |
310ec7921 i2c: Drop the kin... |
172 |
static int adt7470_detect(struct i2c_client *client, |
008f1ca51 hwmon: (adt7470) ... |
173 174 175 176 |
struct i2c_board_info *info); static int adt7470_remove(struct i2c_client *client); static const struct i2c_device_id adt7470_id[] = { |
1f86df49d i2c: Drop I2C_CLI... |
177 |
{ "adt7470", 0 }, |
008f1ca51 hwmon: (adt7470) ... |
178 179 180 |
{ } }; MODULE_DEVICE_TABLE(i2c, adt7470_id); |
6f9703d0b hwmon: add suppor... |
181 182 |
static struct i2c_driver adt7470_driver = { |
008f1ca51 hwmon: (adt7470) ... |
183 |
.class = I2C_CLASS_HWMON, |
6f9703d0b hwmon: add suppor... |
184 185 186 |
.driver = { .name = "adt7470", }, |
008f1ca51 hwmon: (adt7470) ... |
187 188 189 190 |
.probe = adt7470_probe, .remove = adt7470_remove, .id_table = adt7470_id, .detect = adt7470_detect, |
c3813d6af i2c: Get rid of s... |
191 |
.address_list = normal_i2c, |
6f9703d0b hwmon: add suppor... |
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
}; /* * 16-bit registers on the ADT7470 are low-byte first. The data sheet says * that the low byte must be read before the high byte. */ static inline int adt7470_read_word_data(struct i2c_client *client, u8 reg) { u16 foo; foo = i2c_smbus_read_byte_data(client, reg); foo |= ((u16)i2c_smbus_read_byte_data(client, reg + 1) << 8); return foo; } static inline int adt7470_write_word_data(struct i2c_client *client, u8 reg, u16 value) { return i2c_smbus_write_byte_data(client, reg, value & 0xFF) && i2c_smbus_write_byte_data(client, reg + 1, value >> 8); } static void adt7470_init_client(struct i2c_client *client) { int reg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG); if (reg < 0) { dev_err(&client->dev, "cannot read configuration register "); } else { /* start monitoring (and do a self-test) */ i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, reg | 3); } } |
89fac11cb adt7470: make aut... |
225 226 227 |
/* Probe for temperature sensors. Assumes lock is held */ static int adt7470_read_temperatures(struct i2c_client *client, struct adt7470_data *data) |
6f9703d0b hwmon: add suppor... |
228 |
{ |
89fac11cb adt7470: make aut... |
229 |
unsigned long res; |
6f9703d0b hwmon: add suppor... |
230 |
int i; |
89fac11cb adt7470: make aut... |
231 |
u8 cfg, pwm[4], pwm_cfg[2]; |
6f9703d0b hwmon: add suppor... |
232 |
|
2e75a4b7a adt7470: fix pwm ... |
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
/* save pwm[1-4] config register */ pwm_cfg[0] = i2c_smbus_read_byte_data(client, ADT7470_REG_PWM_CFG(0)); pwm_cfg[1] = i2c_smbus_read_byte_data(client, ADT7470_REG_PWM_CFG(2)); /* set manual pwm to whatever it is set to now */ for (i = 0; i < ADT7470_FAN_COUNT; i++) pwm[i] = i2c_smbus_read_byte_data(client, ADT7470_REG_PWM(i)); /* put pwm in manual mode */ i2c_smbus_write_byte_data(client, ADT7470_REG_PWM_CFG(0), pwm_cfg[0] & ~(ADT7470_PWM_AUTO_MASK)); i2c_smbus_write_byte_data(client, ADT7470_REG_PWM_CFG(2), pwm_cfg[1] & ~(ADT7470_PWM_AUTO_MASK)); /* write pwm control to whatever it was */ for (i = 0; i < ADT7470_FAN_COUNT; i++) i2c_smbus_write_byte_data(client, ADT7470_REG_PWM(i), pwm[i]); |
6f9703d0b hwmon: add suppor... |
250 251 252 253 |
/* start reading temperature sensors */ cfg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG); cfg |= 0x80; i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, cfg); |
2f22d5dff adt7470: observe ... |
254 |
/* Delay is 200ms * number of temp sensors. */ |
89fac11cb adt7470: make aut... |
255 256 257 |
res = msleep_interruptible((data->num_temp_sensors >= 0 ? data->num_temp_sensors * 200 : TEMP_COLLECTION_TIME)); |
6f9703d0b hwmon: add suppor... |
258 259 260 261 262 |
/* done reading temperature sensors */ cfg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG); cfg &= ~0x80; i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, cfg); |
2e75a4b7a adt7470: fix pwm ... |
263 264 265 |
/* restore pwm[1-4] config registers */ i2c_smbus_write_byte_data(client, ADT7470_REG_PWM_CFG(0), pwm_cfg[0]); i2c_smbus_write_byte_data(client, ADT7470_REG_PWM_CFG(2), pwm_cfg[1]); |
89fac11cb adt7470: make aut... |
266 267 268 269 270 271 272 273 274 275 |
if (res) { printk(KERN_ERR "ha ha, interrupted"); return -EAGAIN; } /* Only count fans if we have to */ if (data->num_temp_sensors >= 0) return 0; for (i = 0; i < ADT7470_TEMP_COUNT; i++) { |
6f9703d0b hwmon: add suppor... |
276 277 |
data->temp[i] = i2c_smbus_read_byte_data(client, ADT7470_TEMP_REG(i)); |
89fac11cb adt7470: make aut... |
278 279 280 281 282 283 |
if (data->temp[i]) data->num_temp_sensors = i + 1; } data->temperatures_probed = 1; return 0; } |
6f9703d0b hwmon: add suppor... |
284 |
|
89fac11cb adt7470: make aut... |
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
static int adt7470_update_thread(void *p) { struct i2c_client *client = p; struct adt7470_data *data = i2c_get_clientdata(client); while (!kthread_should_stop()) { mutex_lock(&data->lock); adt7470_read_temperatures(client, data); mutex_unlock(&data->lock); if (kthread_should_stop()) break; msleep_interruptible(data->auto_update_interval); } complete_all(&data->auto_update_stop); return 0; } static struct adt7470_data *adt7470_update_device(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); struct adt7470_data *data = i2c_get_clientdata(client); unsigned long local_jiffies = jiffies; u8 cfg; int i; int need_sensors = 1; int need_limits = 1; /* * Figure out if we need to update the shadow registers. * Lockless means that we may occasionally report out of * date data. */ if (time_before(local_jiffies, data->sensors_last_updated + SENSOR_REFRESH_INTERVAL) && data->sensors_valid) need_sensors = 0; if (time_before(local_jiffies, data->limits_last_updated + LIMIT_REFRESH_INTERVAL) && data->limits_valid) need_limits = 0; if (!need_sensors && !need_limits) return data; mutex_lock(&data->lock); if (!need_sensors) goto no_sensor_update; if (!data->temperatures_probed) adt7470_read_temperatures(client, data); else |
2f22d5dff adt7470: observe ... |
338 |
for (i = 0; i < ADT7470_TEMP_COUNT; i++) |
89fac11cb adt7470: make aut... |
339 340 |
data->temp[i] = i2c_smbus_read_byte_data(client, ADT7470_TEMP_REG(i)); |
2f22d5dff adt7470: observe ... |
341 |
|
6f9703d0b hwmon: add suppor... |
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
for (i = 0; i < ADT7470_FAN_COUNT; i++) data->fan[i] = adt7470_read_word_data(client, ADT7470_REG_FAN(i)); for (i = 0; i < ADT7470_PWM_COUNT; i++) { int reg; int reg_mask; data->pwm[i] = i2c_smbus_read_byte_data(client, ADT7470_REG_PWM(i)); if (i % 2) reg_mask = ADT7470_PWM2_AUTO_MASK; else reg_mask = ADT7470_PWM1_AUTO_MASK; reg = ADT7470_REG_PWM_CFG(i); if (i2c_smbus_read_byte_data(client, reg) & reg_mask) data->pwm_automatic[i] = 1; else data->pwm_automatic[i] = 0; reg = ADT7470_REG_PWM_AUTO_TEMP(i); cfg = i2c_smbus_read_byte_data(client, reg); if (!(i % 2)) data->pwm_auto_temp[i] = cfg >> 4; else data->pwm_auto_temp[i] = cfg & 0xF; } if (i2c_smbus_read_byte_data(client, ADT7470_REG_CFG) & ADT7470_FSPD_MASK) data->force_pwm_max = 1; else data->force_pwm_max = 0; |
fe03f28cf hwmon: (adt7470) ... |
377 378 379 380 |
data->alarm = i2c_smbus_read_byte_data(client, ADT7470_REG_ALARM1); if (data->alarm & ADT7470_OOL_ALARM) data->alarm |= ALARM2(i2c_smbus_read_byte_data(client, ADT7470_REG_ALARM2)); |
6f9703d0b hwmon: add suppor... |
381 382 383 384 385 386 387 |
data->alarms_mask = adt7470_read_word_data(client, ADT7470_REG_ALARM1_MASK); data->sensors_last_updated = local_jiffies; data->sensors_valid = 1; no_sensor_update: |
89fac11cb adt7470: make aut... |
388 |
if (!need_limits) |
6f9703d0b hwmon: add suppor... |
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 |
goto out; for (i = 0; i < ADT7470_TEMP_COUNT; i++) { data->temp_min[i] = i2c_smbus_read_byte_data(client, ADT7470_TEMP_MIN_REG(i)); data->temp_max[i] = i2c_smbus_read_byte_data(client, ADT7470_TEMP_MAX_REG(i)); } for (i = 0; i < ADT7470_FAN_COUNT; i++) { data->fan_min[i] = adt7470_read_word_data(client, ADT7470_REG_FAN_MIN(i)); data->fan_max[i] = adt7470_read_word_data(client, ADT7470_REG_FAN_MAX(i)); } for (i = 0; i < ADT7470_PWM_COUNT; i++) { data->pwm_max[i] = i2c_smbus_read_byte_data(client, ADT7470_REG_PWM_MAX(i)); data->pwm_min[i] = i2c_smbus_read_byte_data(client, ADT7470_REG_PWM_MIN(i)); data->pwm_tmin[i] = i2c_smbus_read_byte_data(client, ADT7470_REG_PWM_TMIN(i)); } data->limits_last_updated = local_jiffies; data->limits_valid = 1; out: mutex_unlock(&data->lock); return data; } |
89fac11cb adt7470: make aut... |
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
static ssize_t show_auto_update_interval(struct device *dev, struct device_attribute *devattr, char *buf) { struct adt7470_data *data = adt7470_update_device(dev); return sprintf(buf, "%d ", data->auto_update_interval); } static ssize_t set_auto_update_interval(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct i2c_client *client = to_i2c_client(dev); struct adt7470_data *data = i2c_get_clientdata(client); long temp; if (strict_strtol(buf, 10, &temp)) return -EINVAL; temp = SENSORS_LIMIT(temp, 0, 60000); mutex_lock(&data->lock); data->auto_update_interval = temp; mutex_unlock(&data->lock); return count; } |
2f22d5dff adt7470: observe ... |
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 |
static ssize_t show_num_temp_sensors(struct device *dev, struct device_attribute *devattr, char *buf) { struct adt7470_data *data = adt7470_update_device(dev); return sprintf(buf, "%d ", data->num_temp_sensors); } static ssize_t set_num_temp_sensors(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct i2c_client *client = to_i2c_client(dev); struct adt7470_data *data = i2c_get_clientdata(client); long temp; if (strict_strtol(buf, 10, &temp)) return -EINVAL; temp = SENSORS_LIMIT(temp, -1, 10); mutex_lock(&data->lock); data->num_temp_sensors = temp; |
89fac11cb adt7470: make aut... |
475 476 |
if (temp < 0) data->temperatures_probed = 0; |
2f22d5dff adt7470: observe ... |
477 478 479 480 |
mutex_unlock(&data->lock); return count; } |
6f9703d0b hwmon: add suppor... |
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 |
static ssize_t show_temp_min(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adt7470_data *data = adt7470_update_device(dev); return sprintf(buf, "%d ", 1000 * data->temp_min[attr->index]); } static ssize_t set_temp_min(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct i2c_client *client = to_i2c_client(dev); struct adt7470_data *data = i2c_get_clientdata(client); |
05a9bd46e adt7470: check in... |
499 500 501 502 |
long temp; if (strict_strtol(buf, 10, &temp)) return -EINVAL; |
8f8c1fb0c adt74{62, 70, 73}... |
503 |
temp = DIV_ROUND_CLOSEST(temp, 1000); |
05a9bd46e adt7470: check in... |
504 |
temp = SENSORS_LIMIT(temp, 0, 255); |
6f9703d0b hwmon: add suppor... |
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 |
mutex_lock(&data->lock); data->temp_min[attr->index] = temp; i2c_smbus_write_byte_data(client, ADT7470_TEMP_MIN_REG(attr->index), temp); mutex_unlock(&data->lock); return count; } static ssize_t show_temp_max(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adt7470_data *data = adt7470_update_device(dev); return sprintf(buf, "%d ", 1000 * data->temp_max[attr->index]); } static ssize_t set_temp_max(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct i2c_client *client = to_i2c_client(dev); struct adt7470_data *data = i2c_get_clientdata(client); |
05a9bd46e adt7470: check in... |
533 534 535 536 |
long temp; if (strict_strtol(buf, 10, &temp)) return -EINVAL; |
8f8c1fb0c adt74{62, 70, 73}... |
537 |
temp = DIV_ROUND_CLOSEST(temp, 1000); |
05a9bd46e adt7470: check in... |
538 |
temp = SENSORS_LIMIT(temp, 0, 255); |
6f9703d0b hwmon: add suppor... |
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 |
mutex_lock(&data->lock); data->temp_max[attr->index] = temp; i2c_smbus_write_byte_data(client, ADT7470_TEMP_MAX_REG(attr->index), temp); mutex_unlock(&data->lock); return count; } static ssize_t show_temp(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adt7470_data *data = adt7470_update_device(dev); return sprintf(buf, "%d ", 1000 * data->temp[attr->index]); } |
fe03f28cf hwmon: (adt7470) ... |
557 |
static ssize_t show_alarm_mask(struct device *dev, |
6f9703d0b hwmon: add suppor... |
558 559 560 |
struct device_attribute *devattr, char *buf) { |
6f9703d0b hwmon: add suppor... |
561 |
struct adt7470_data *data = adt7470_update_device(dev); |
fe03f28cf hwmon: (adt7470) ... |
562 563 |
return sprintf(buf, "%x ", data->alarms_mask); |
6f9703d0b hwmon: add suppor... |
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 |
} static ssize_t show_fan_max(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adt7470_data *data = adt7470_update_device(dev); if (FAN_DATA_VALID(data->fan_max[attr->index])) return sprintf(buf, "%d ", FAN_PERIOD_TO_RPM(data->fan_max[attr->index])); else return sprintf(buf, "0 "); } static ssize_t set_fan_max(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct i2c_client *client = to_i2c_client(dev); struct adt7470_data *data = i2c_get_clientdata(client); |
05a9bd46e adt7470: check in... |
589 |
long temp; |
6f9703d0b hwmon: add suppor... |
590 |
|
05a9bd46e adt7470: check in... |
591 |
if (strict_strtol(buf, 10, &temp) || !temp) |
6f9703d0b hwmon: add suppor... |
592 |
return -EINVAL; |
05a9bd46e adt7470: check in... |
593 |
|
6f9703d0b hwmon: add suppor... |
594 |
temp = FAN_RPM_TO_PERIOD(temp); |
05a9bd46e adt7470: check in... |
595 |
temp = SENSORS_LIMIT(temp, 1, 65534); |
6f9703d0b hwmon: add suppor... |
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 |
mutex_lock(&data->lock); data->fan_max[attr->index] = temp; adt7470_write_word_data(client, ADT7470_REG_FAN_MAX(attr->index), temp); mutex_unlock(&data->lock); return count; } static ssize_t show_fan_min(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adt7470_data *data = adt7470_update_device(dev); if (FAN_DATA_VALID(data->fan_min[attr->index])) return sprintf(buf, "%d ", FAN_PERIOD_TO_RPM(data->fan_min[attr->index])); else return sprintf(buf, "0 "); } static ssize_t set_fan_min(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct i2c_client *client = to_i2c_client(dev); struct adt7470_data *data = i2c_get_clientdata(client); |
05a9bd46e adt7470: check in... |
628 |
long temp; |
6f9703d0b hwmon: add suppor... |
629 |
|
05a9bd46e adt7470: check in... |
630 |
if (strict_strtol(buf, 10, &temp) || !temp) |
6f9703d0b hwmon: add suppor... |
631 |
return -EINVAL; |
05a9bd46e adt7470: check in... |
632 |
|
6f9703d0b hwmon: add suppor... |
633 |
temp = FAN_RPM_TO_PERIOD(temp); |
05a9bd46e adt7470: check in... |
634 |
temp = SENSORS_LIMIT(temp, 1, 65534); |
6f9703d0b hwmon: add suppor... |
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 |
mutex_lock(&data->lock); data->fan_min[attr->index] = temp; adt7470_write_word_data(client, ADT7470_REG_FAN_MIN(attr->index), temp); mutex_unlock(&data->lock); return count; } static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adt7470_data *data = adt7470_update_device(dev); if (FAN_DATA_VALID(data->fan[attr->index])) return sprintf(buf, "%d ", FAN_PERIOD_TO_RPM(data->fan[attr->index])); else return sprintf(buf, "0 "); } static ssize_t show_force_pwm_max(struct device *dev, struct device_attribute *devattr, char *buf) { struct adt7470_data *data = adt7470_update_device(dev); return sprintf(buf, "%d ", data->force_pwm_max); } static ssize_t set_force_pwm_max(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct i2c_client *client = to_i2c_client(dev); struct adt7470_data *data = i2c_get_clientdata(client); |
05a9bd46e adt7470: check in... |
675 |
long temp; |
6f9703d0b hwmon: add suppor... |
676 |
u8 reg; |
05a9bd46e adt7470: check in... |
677 678 |
if (strict_strtol(buf, 10, &temp)) return -EINVAL; |
6f9703d0b hwmon: add suppor... |
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 |
mutex_lock(&data->lock); data->force_pwm_max = temp; reg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG); if (temp) reg |= ADT7470_FSPD_MASK; else reg &= ~ADT7470_FSPD_MASK; i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, reg); mutex_unlock(&data->lock); return count; } static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adt7470_data *data = adt7470_update_device(dev); return sprintf(buf, "%d ", data->pwm[attr->index]); } static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct i2c_client *client = to_i2c_client(dev); struct adt7470_data *data = i2c_get_clientdata(client); |
05a9bd46e adt7470: check in... |
707 708 709 710 711 712 |
long temp; if (strict_strtol(buf, 10, &temp)) return -EINVAL; temp = SENSORS_LIMIT(temp, 0, 255); |
6f9703d0b hwmon: add suppor... |
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 |
mutex_lock(&data->lock); data->pwm[attr->index] = temp; i2c_smbus_write_byte_data(client, ADT7470_REG_PWM(attr->index), temp); mutex_unlock(&data->lock); return count; } static ssize_t show_pwm_max(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adt7470_data *data = adt7470_update_device(dev); return sprintf(buf, "%d ", data->pwm_max[attr->index]); } static ssize_t set_pwm_max(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct i2c_client *client = to_i2c_client(dev); struct adt7470_data *data = i2c_get_clientdata(client); |
05a9bd46e adt7470: check in... |
740 741 742 743 744 745 |
long temp; if (strict_strtol(buf, 10, &temp)) return -EINVAL; temp = SENSORS_LIMIT(temp, 0, 255); |
6f9703d0b hwmon: add suppor... |
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 |
mutex_lock(&data->lock); data->pwm_max[attr->index] = temp; i2c_smbus_write_byte_data(client, ADT7470_REG_PWM_MAX(attr->index), temp); mutex_unlock(&data->lock); return count; } static ssize_t show_pwm_min(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adt7470_data *data = adt7470_update_device(dev); return sprintf(buf, "%d ", data->pwm_min[attr->index]); } static ssize_t set_pwm_min(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct i2c_client *client = to_i2c_client(dev); struct adt7470_data *data = i2c_get_clientdata(client); |
05a9bd46e adt7470: check in... |
774 775 776 777 778 779 |
long temp; if (strict_strtol(buf, 10, &temp)) return -EINVAL; temp = SENSORS_LIMIT(temp, 0, 255); |
6f9703d0b hwmon: add suppor... |
780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 |
mutex_lock(&data->lock); data->pwm_min[attr->index] = temp; i2c_smbus_write_byte_data(client, ADT7470_REG_PWM_MIN(attr->index), temp); mutex_unlock(&data->lock); return count; } static ssize_t show_pwm_tmax(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adt7470_data *data = adt7470_update_device(dev); /* the datasheet says that tmax = tmin + 20C */ return sprintf(buf, "%d ", 1000 * (20 + data->pwm_tmin[attr->index])); } static ssize_t show_pwm_tmin(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adt7470_data *data = adt7470_update_device(dev); return sprintf(buf, "%d ", 1000 * data->pwm_tmin[attr->index]); } static ssize_t set_pwm_tmin(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct i2c_client *client = to_i2c_client(dev); struct adt7470_data *data = i2c_get_clientdata(client); |
05a9bd46e adt7470: check in... |
819 820 821 822 |
long temp; if (strict_strtol(buf, 10, &temp)) return -EINVAL; |
8f8c1fb0c adt74{62, 70, 73}... |
823 |
temp = DIV_ROUND_CLOSEST(temp, 1000); |
05a9bd46e adt7470: check in... |
824 |
temp = SENSORS_LIMIT(temp, 0, 255); |
6f9703d0b hwmon: add suppor... |
825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 |
mutex_lock(&data->lock); data->pwm_tmin[attr->index] = temp; i2c_smbus_write_byte_data(client, ADT7470_REG_PWM_TMIN(attr->index), temp); mutex_unlock(&data->lock); return count; } static ssize_t show_pwm_auto(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adt7470_data *data = adt7470_update_device(dev); return sprintf(buf, "%d ", 1 + data->pwm_automatic[attr->index]); } static ssize_t set_pwm_auto(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct i2c_client *client = to_i2c_client(dev); struct adt7470_data *data = i2c_get_clientdata(client); |
6f9703d0b hwmon: add suppor... |
853 854 |
int pwm_auto_reg = ADT7470_REG_PWM_CFG(attr->index); int pwm_auto_reg_mask; |
05a9bd46e adt7470: check in... |
855 |
long temp; |
6f9703d0b hwmon: add suppor... |
856 |
u8 reg; |
05a9bd46e adt7470: check in... |
857 858 |
if (strict_strtol(buf, 10, &temp)) return -EINVAL; |
6f9703d0b hwmon: add suppor... |
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 |
if (attr->index % 2) pwm_auto_reg_mask = ADT7470_PWM2_AUTO_MASK; else pwm_auto_reg_mask = ADT7470_PWM1_AUTO_MASK; if (temp != 2 && temp != 1) return -EINVAL; temp--; mutex_lock(&data->lock); data->pwm_automatic[attr->index] = temp; reg = i2c_smbus_read_byte_data(client, pwm_auto_reg); if (temp) reg |= pwm_auto_reg_mask; else reg &= ~pwm_auto_reg_mask; i2c_smbus_write_byte_data(client, pwm_auto_reg, reg); mutex_unlock(&data->lock); return count; } static ssize_t show_pwm_auto_temp(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adt7470_data *data = adt7470_update_device(dev); u8 ctrl = data->pwm_auto_temp[attr->index]; if (ctrl) return sprintf(buf, "%d ", 1 << (ctrl - 1)); else return sprintf(buf, "%d ", ADT7470_PWM_ALL_TEMPS); } static int cvt_auto_temp(int input) { if (input == ADT7470_PWM_ALL_TEMPS) return 0; |
ce9c2f449 hwmon: (adt7470) ... |
901 |
if (input < 1 || !is_power_of_2(input)) |
6f9703d0b hwmon: add suppor... |
902 903 904 905 906 907 908 909 910 911 912 913 |
return -EINVAL; return ilog2(input) + 1; } static ssize_t set_pwm_auto_temp(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct i2c_client *client = to_i2c_client(dev); struct adt7470_data *data = i2c_get_clientdata(client); |
6f9703d0b hwmon: add suppor... |
914 |
int pwm_auto_reg = ADT7470_REG_PWM_AUTO_TEMP(attr->index); |
05a9bd46e adt7470: check in... |
915 |
long temp; |
6f9703d0b hwmon: add suppor... |
916 |
u8 reg; |
05a9bd46e adt7470: check in... |
917 918 919 920 |
if (strict_strtol(buf, 10, &temp)) return -EINVAL; temp = cvt_auto_temp(temp); |
6f9703d0b hwmon: add suppor... |
921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 |
if (temp < 0) return temp; mutex_lock(&data->lock); data->pwm_automatic[attr->index] = temp; reg = i2c_smbus_read_byte_data(client, pwm_auto_reg); if (!(attr->index % 2)) { reg &= 0xF; reg |= (temp << 4) & 0xF0; } else { reg &= 0xF0; reg |= temp & 0xF; } i2c_smbus_write_byte_data(client, pwm_auto_reg, reg); mutex_unlock(&data->lock); return count; } |
fe03f28cf hwmon: (adt7470) ... |
941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 |
static ssize_t show_alarm(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adt7470_data *data = adt7470_update_device(dev); if (data->alarm & attr->index) return sprintf(buf, "1 "); else return sprintf(buf, "0 "); } static DEVICE_ATTR(alarm_mask, S_IRUGO, show_alarm_mask, NULL); |
2f22d5dff adt7470: observe ... |
957 958 |
static DEVICE_ATTR(num_temp_sensors, S_IWUSR | S_IRUGO, show_num_temp_sensors, set_num_temp_sensors); |
89fac11cb adt7470: make aut... |
959 960 |
static DEVICE_ATTR(auto_update_interval, S_IWUSR | S_IRUGO, show_auto_update_interval, set_auto_update_interval); |
6f9703d0b hwmon: add suppor... |
961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 |
static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, set_temp_max, 0); static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_max, set_temp_max, 1); static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_temp_max, set_temp_max, 2); static SENSOR_DEVICE_ATTR(temp4_max, S_IWUSR | S_IRUGO, show_temp_max, set_temp_max, 3); static SENSOR_DEVICE_ATTR(temp5_max, S_IWUSR | S_IRUGO, show_temp_max, set_temp_max, 4); static SENSOR_DEVICE_ATTR(temp6_max, S_IWUSR | S_IRUGO, show_temp_max, set_temp_max, 5); static SENSOR_DEVICE_ATTR(temp7_max, S_IWUSR | S_IRUGO, show_temp_max, set_temp_max, 6); static SENSOR_DEVICE_ATTR(temp8_max, S_IWUSR | S_IRUGO, show_temp_max, set_temp_max, 7); static SENSOR_DEVICE_ATTR(temp9_max, S_IWUSR | S_IRUGO, show_temp_max, set_temp_max, 8); static SENSOR_DEVICE_ATTR(temp10_max, S_IWUSR | S_IRUGO, show_temp_max, set_temp_max, 9); static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp_min, set_temp_min, 0); static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp_min, set_temp_min, 1); static SENSOR_DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO, show_temp_min, set_temp_min, 2); static SENSOR_DEVICE_ATTR(temp4_min, S_IWUSR | S_IRUGO, show_temp_min, set_temp_min, 3); static SENSOR_DEVICE_ATTR(temp5_min, S_IWUSR | S_IRUGO, show_temp_min, set_temp_min, 4); static SENSOR_DEVICE_ATTR(temp6_min, S_IWUSR | S_IRUGO, show_temp_min, set_temp_min, 5); static SENSOR_DEVICE_ATTR(temp7_min, S_IWUSR | S_IRUGO, show_temp_min, set_temp_min, 6); static SENSOR_DEVICE_ATTR(temp8_min, S_IWUSR | S_IRUGO, show_temp_min, set_temp_min, 7); static SENSOR_DEVICE_ATTR(temp9_min, S_IWUSR | S_IRUGO, show_temp_min, set_temp_min, 8); static SENSOR_DEVICE_ATTR(temp10_min, S_IWUSR | S_IRUGO, show_temp_min, set_temp_min, 9); static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1); static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2); static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 3); static SENSOR_DEVICE_ATTR(temp5_input, S_IRUGO, show_temp, NULL, 4); static SENSOR_DEVICE_ATTR(temp6_input, S_IRUGO, show_temp, NULL, 5); static SENSOR_DEVICE_ATTR(temp7_input, S_IRUGO, show_temp, NULL, 6); static SENSOR_DEVICE_ATTR(temp8_input, S_IRUGO, show_temp, NULL, 7); static SENSOR_DEVICE_ATTR(temp9_input, S_IRUGO, show_temp, NULL, 8); static SENSOR_DEVICE_ATTR(temp10_input, S_IRUGO, show_temp, NULL, 9); |
fe03f28cf hwmon: (adt7470) ... |
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 |
static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, ADT7470_R1T_ALARM); static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, ADT7470_R2T_ALARM); static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, ADT7470_R3T_ALARM); static SENSOR_DEVICE_ATTR(temp4_alarm, S_IRUGO, show_alarm, NULL, ADT7470_R4T_ALARM); static SENSOR_DEVICE_ATTR(temp5_alarm, S_IRUGO, show_alarm, NULL, ADT7470_R5T_ALARM); static SENSOR_DEVICE_ATTR(temp6_alarm, S_IRUGO, show_alarm, NULL, ADT7470_R6T_ALARM); static SENSOR_DEVICE_ATTR(temp7_alarm, S_IRUGO, show_alarm, NULL, ADT7470_R7T_ALARM); static SENSOR_DEVICE_ATTR(temp8_alarm, S_IRUGO, show_alarm, NULL, ALARM2(ADT7470_R8T_ALARM)); static SENSOR_DEVICE_ATTR(temp9_alarm, S_IRUGO, show_alarm, NULL, ALARM2(ADT7470_R9T_ALARM)); static SENSOR_DEVICE_ATTR(temp10_alarm, S_IRUGO, show_alarm, NULL, ALARM2(ADT7470_R10T_ALARM)); |
6f9703d0b hwmon: add suppor... |
1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 |
static SENSOR_DEVICE_ATTR(fan1_max, S_IWUSR | S_IRUGO, show_fan_max, set_fan_max, 0); static SENSOR_DEVICE_ATTR(fan2_max, S_IWUSR | S_IRUGO, show_fan_max, set_fan_max, 1); static SENSOR_DEVICE_ATTR(fan3_max, S_IWUSR | S_IRUGO, show_fan_max, set_fan_max, 2); static SENSOR_DEVICE_ATTR(fan4_max, S_IWUSR | S_IRUGO, show_fan_max, set_fan_max, 3); static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min, set_fan_min, 0); static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min, set_fan_min, 1); static SENSOR_DEVICE_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min, set_fan_min, 2); static SENSOR_DEVICE_ATTR(fan4_min, S_IWUSR | S_IRUGO, show_fan_min, set_fan_min, 3); static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0); static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1); static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2); static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3); |
fe03f28cf hwmon: (adt7470) ... |
1056 1057 1058 1059 1060 1061 1062 1063 |
static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, ALARM2(ADT7470_FAN1_ALARM)); static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, ALARM2(ADT7470_FAN2_ALARM)); static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, ALARM2(ADT7470_FAN3_ALARM)); static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, ALARM2(ADT7470_FAN4_ALARM)); |
6f9703d0b hwmon: add suppor... |
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 |
static SENSOR_DEVICE_ATTR(force_pwm_max, S_IWUSR | S_IRUGO, show_force_pwm_max, set_force_pwm_max, 0); static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 0); static SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 1); static SENSOR_DEVICE_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2); static SENSOR_DEVICE_ATTR(pwm4, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 3); static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IWUSR | S_IRUGO, show_pwm_min, set_pwm_min, 0); static SENSOR_DEVICE_ATTR(pwm2_auto_point1_pwm, S_IWUSR | S_IRUGO, show_pwm_min, set_pwm_min, 1); static SENSOR_DEVICE_ATTR(pwm3_auto_point1_pwm, S_IWUSR | S_IRUGO, show_pwm_min, set_pwm_min, 2); static SENSOR_DEVICE_ATTR(pwm4_auto_point1_pwm, S_IWUSR | S_IRUGO, show_pwm_min, set_pwm_min, 3); static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IWUSR | S_IRUGO, show_pwm_max, set_pwm_max, 0); static SENSOR_DEVICE_ATTR(pwm2_auto_point2_pwm, S_IWUSR | S_IRUGO, show_pwm_max, set_pwm_max, 1); static SENSOR_DEVICE_ATTR(pwm3_auto_point2_pwm, S_IWUSR | S_IRUGO, show_pwm_max, set_pwm_max, 2); static SENSOR_DEVICE_ATTR(pwm4_auto_point2_pwm, S_IWUSR | S_IRUGO, show_pwm_max, set_pwm_max, 3); static SENSOR_DEVICE_ATTR(pwm1_auto_point1_temp, S_IWUSR | S_IRUGO, show_pwm_tmin, set_pwm_tmin, 0); static SENSOR_DEVICE_ATTR(pwm2_auto_point1_temp, S_IWUSR | S_IRUGO, show_pwm_tmin, set_pwm_tmin, 1); static SENSOR_DEVICE_ATTR(pwm3_auto_point1_temp, S_IWUSR | S_IRUGO, show_pwm_tmin, set_pwm_tmin, 2); static SENSOR_DEVICE_ATTR(pwm4_auto_point1_temp, S_IWUSR | S_IRUGO, show_pwm_tmin, set_pwm_tmin, 3); static SENSOR_DEVICE_ATTR(pwm1_auto_point2_temp, S_IRUGO, show_pwm_tmax, NULL, 0); static SENSOR_DEVICE_ATTR(pwm2_auto_point2_temp, S_IRUGO, show_pwm_tmax, NULL, 1); static SENSOR_DEVICE_ATTR(pwm3_auto_point2_temp, S_IRUGO, show_pwm_tmax, NULL, 2); static SENSOR_DEVICE_ATTR(pwm4_auto_point2_temp, S_IRUGO, show_pwm_tmax, NULL, 3); static SENSOR_DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, show_pwm_auto, set_pwm_auto, 0); static SENSOR_DEVICE_ATTR(pwm2_enable, S_IWUSR | S_IRUGO, show_pwm_auto, set_pwm_auto, 1); static SENSOR_DEVICE_ATTR(pwm3_enable, S_IWUSR | S_IRUGO, show_pwm_auto, set_pwm_auto, 2); static SENSOR_DEVICE_ATTR(pwm4_enable, S_IWUSR | S_IRUGO, show_pwm_auto, set_pwm_auto, 3); static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IWUSR | S_IRUGO, show_pwm_auto_temp, set_pwm_auto_temp, 0); static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IWUSR | S_IRUGO, show_pwm_auto_temp, set_pwm_auto_temp, 1); static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IWUSR | S_IRUGO, show_pwm_auto_temp, set_pwm_auto_temp, 2); static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO, show_pwm_auto_temp, set_pwm_auto_temp, 3); static struct attribute *adt7470_attr[] = { |
fe03f28cf hwmon: (adt7470) ... |
1128 |
&dev_attr_alarm_mask.attr, |
2f22d5dff adt7470: observe ... |
1129 |
&dev_attr_num_temp_sensors.attr, |
89fac11cb adt7470: make aut... |
1130 |
&dev_attr_auto_update_interval.attr, |
6f9703d0b hwmon: add suppor... |
1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 |
&sensor_dev_attr_temp1_max.dev_attr.attr, &sensor_dev_attr_temp2_max.dev_attr.attr, &sensor_dev_attr_temp3_max.dev_attr.attr, &sensor_dev_attr_temp4_max.dev_attr.attr, &sensor_dev_attr_temp5_max.dev_attr.attr, &sensor_dev_attr_temp6_max.dev_attr.attr, &sensor_dev_attr_temp7_max.dev_attr.attr, &sensor_dev_attr_temp8_max.dev_attr.attr, &sensor_dev_attr_temp9_max.dev_attr.attr, &sensor_dev_attr_temp10_max.dev_attr.attr, &sensor_dev_attr_temp1_min.dev_attr.attr, &sensor_dev_attr_temp2_min.dev_attr.attr, &sensor_dev_attr_temp3_min.dev_attr.attr, &sensor_dev_attr_temp4_min.dev_attr.attr, &sensor_dev_attr_temp5_min.dev_attr.attr, &sensor_dev_attr_temp6_min.dev_attr.attr, &sensor_dev_attr_temp7_min.dev_attr.attr, &sensor_dev_attr_temp8_min.dev_attr.attr, &sensor_dev_attr_temp9_min.dev_attr.attr, &sensor_dev_attr_temp10_min.dev_attr.attr, &sensor_dev_attr_temp1_input.dev_attr.attr, &sensor_dev_attr_temp2_input.dev_attr.attr, &sensor_dev_attr_temp3_input.dev_attr.attr, &sensor_dev_attr_temp4_input.dev_attr.attr, &sensor_dev_attr_temp5_input.dev_attr.attr, &sensor_dev_attr_temp6_input.dev_attr.attr, &sensor_dev_attr_temp7_input.dev_attr.attr, &sensor_dev_attr_temp8_input.dev_attr.attr, &sensor_dev_attr_temp9_input.dev_attr.attr, &sensor_dev_attr_temp10_input.dev_attr.attr, |
fe03f28cf hwmon: (adt7470) ... |
1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 |
&sensor_dev_attr_temp1_alarm.dev_attr.attr, &sensor_dev_attr_temp2_alarm.dev_attr.attr, &sensor_dev_attr_temp3_alarm.dev_attr.attr, &sensor_dev_attr_temp4_alarm.dev_attr.attr, &sensor_dev_attr_temp5_alarm.dev_attr.attr, &sensor_dev_attr_temp6_alarm.dev_attr.attr, &sensor_dev_attr_temp7_alarm.dev_attr.attr, &sensor_dev_attr_temp8_alarm.dev_attr.attr, &sensor_dev_attr_temp9_alarm.dev_attr.attr, &sensor_dev_attr_temp10_alarm.dev_attr.attr, |
6f9703d0b hwmon: add suppor... |
1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 |
&sensor_dev_attr_fan1_max.dev_attr.attr, &sensor_dev_attr_fan2_max.dev_attr.attr, &sensor_dev_attr_fan3_max.dev_attr.attr, &sensor_dev_attr_fan4_max.dev_attr.attr, &sensor_dev_attr_fan1_min.dev_attr.attr, &sensor_dev_attr_fan2_min.dev_attr.attr, &sensor_dev_attr_fan3_min.dev_attr.attr, &sensor_dev_attr_fan4_min.dev_attr.attr, &sensor_dev_attr_fan1_input.dev_attr.attr, &sensor_dev_attr_fan2_input.dev_attr.attr, &sensor_dev_attr_fan3_input.dev_attr.attr, &sensor_dev_attr_fan4_input.dev_attr.attr, |
fe03f28cf hwmon: (adt7470) ... |
1183 1184 1185 1186 |
&sensor_dev_attr_fan1_alarm.dev_attr.attr, &sensor_dev_attr_fan2_alarm.dev_attr.attr, &sensor_dev_attr_fan3_alarm.dev_attr.attr, &sensor_dev_attr_fan4_alarm.dev_attr.attr, |
6f9703d0b hwmon: add suppor... |
1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 |
&sensor_dev_attr_force_pwm_max.dev_attr.attr, &sensor_dev_attr_pwm1.dev_attr.attr, &sensor_dev_attr_pwm2.dev_attr.attr, &sensor_dev_attr_pwm3.dev_attr.attr, &sensor_dev_attr_pwm4.dev_attr.attr, &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr, &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr, &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr, &sensor_dev_attr_pwm4_auto_point1_pwm.dev_attr.attr, &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr, &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr, &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr, &sensor_dev_attr_pwm4_auto_point2_pwm.dev_attr.attr, &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr, &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr, &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr, &sensor_dev_attr_pwm4_auto_point1_temp.dev_attr.attr, &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr, &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr, &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr, &sensor_dev_attr_pwm4_auto_point2_temp.dev_attr.attr, &sensor_dev_attr_pwm1_enable.dev_attr.attr, &sensor_dev_attr_pwm2_enable.dev_attr.attr, &sensor_dev_attr_pwm3_enable.dev_attr.attr, &sensor_dev_attr_pwm4_enable.dev_attr.attr, &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr, &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr, &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr, &sensor_dev_attr_pwm4_auto_channels_temp.dev_attr.attr, NULL }; |
008f1ca51 hwmon: (adt7470) ... |
1218 |
/* Return 0 if detection is successful, -ENODEV otherwise */ |
310ec7921 i2c: Drop the kin... |
1219 |
static int adt7470_detect(struct i2c_client *client, |
008f1ca51 hwmon: (adt7470) ... |
1220 |
struct i2c_board_info *info) |
6f9703d0b hwmon: add suppor... |
1221 |
{ |
008f1ca51 hwmon: (adt7470) ... |
1222 |
struct i2c_adapter *adapter = client->adapter; |
52df6440a hwmon: Clean up d... |
1223 |
int vendor, device, revision; |
6f9703d0b hwmon: add suppor... |
1224 1225 |
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
008f1ca51 hwmon: (adt7470) ... |
1226 |
return -ENODEV; |
6f9703d0b hwmon: add suppor... |
1227 |
|
52df6440a hwmon: Clean up d... |
1228 1229 1230 |
vendor = i2c_smbus_read_byte_data(client, ADT7470_REG_VENDOR); if (vendor != ADT7470_VENDOR) return -ENODEV; |
6f9703d0b hwmon: add suppor... |
1231 |
|
52df6440a hwmon: Clean up d... |
1232 1233 1234 |
device = i2c_smbus_read_byte_data(client, ADT7470_REG_DEVICE); if (device != ADT7470_DEVICE) return -ENODEV; |
6f9703d0b hwmon: add suppor... |
1235 |
|
52df6440a hwmon: Clean up d... |
1236 1237 1238 |
revision = i2c_smbus_read_byte_data(client, ADT7470_REG_REVISION); if (revision != ADT7470_REVISION) return -ENODEV; |
6f9703d0b hwmon: add suppor... |
1239 |
|
008f1ca51 hwmon: (adt7470) ... |
1240 |
strlcpy(info->type, "adt7470", I2C_NAME_SIZE); |
6f9703d0b hwmon: add suppor... |
1241 |
|
008f1ca51 hwmon: (adt7470) ... |
1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 |
return 0; } static int adt7470_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct adt7470_data *data; int err; data = kzalloc(sizeof(struct adt7470_data), GFP_KERNEL); if (!data) { err = -ENOMEM; goto exit; } |
2f22d5dff adt7470: observe ... |
1256 |
data->num_temp_sensors = -1; |
89fac11cb adt7470: make aut... |
1257 |
data->auto_update_interval = AUTO_UPDATE_INTERVAL; |
2f22d5dff adt7470: observe ... |
1258 |
|
008f1ca51 hwmon: (adt7470) ... |
1259 1260 |
i2c_set_clientdata(client, data); mutex_init(&data->lock); |
6f9703d0b hwmon: add suppor... |
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 |
dev_info(&client->dev, "%s chip found ", client->name); /* Initialize the ADT7470 chip */ adt7470_init_client(client); /* Register sysfs hooks */ data->attrs.attrs = adt7470_attr; if ((err = sysfs_create_group(&client->dev.kobj, &data->attrs))) |
008f1ca51 hwmon: (adt7470) ... |
1271 |
goto exit_free; |
6f9703d0b hwmon: add suppor... |
1272 |
|
1beeffe43 hwmon: Convert fr... |
1273 1274 1275 |
data->hwmon_dev = hwmon_device_register(&client->dev); if (IS_ERR(data->hwmon_dev)) { err = PTR_ERR(data->hwmon_dev); |
6f9703d0b hwmon: add suppor... |
1276 1277 |
goto exit_remove; } |
89fac11cb adt7470: make aut... |
1278 1279 1280 1281 1282 |
init_completion(&data->auto_update_stop); data->auto_update = kthread_run(adt7470_update_thread, client, dev_name(data->hwmon_dev)); if (IS_ERR(data->auto_update)) goto exit_unregister; |
6f9703d0b hwmon: add suppor... |
1283 |
return 0; |
89fac11cb adt7470: make aut... |
1284 1285 |
exit_unregister: hwmon_device_unregister(data->hwmon_dev); |
6f9703d0b hwmon: add suppor... |
1286 1287 |
exit_remove: sysfs_remove_group(&client->dev.kobj, &data->attrs); |
6f9703d0b hwmon: add suppor... |
1288 1289 1290 1291 1292 |
exit_free: kfree(data); exit: return err; } |
008f1ca51 hwmon: (adt7470) ... |
1293 |
static int adt7470_remove(struct i2c_client *client) |
6f9703d0b hwmon: add suppor... |
1294 1295 |
{ struct adt7470_data *data = i2c_get_clientdata(client); |
89fac11cb adt7470: make aut... |
1296 1297 |
kthread_stop(data->auto_update); wait_for_completion(&data->auto_update_stop); |
1beeffe43 hwmon: Convert fr... |
1298 |
hwmon_device_unregister(data->hwmon_dev); |
6f9703d0b hwmon: add suppor... |
1299 |
sysfs_remove_group(&client->dev.kobj, &data->attrs); |
6f9703d0b hwmon: add suppor... |
1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 |
kfree(data); return 0; } static int __init adt7470_init(void) { return i2c_add_driver(&adt7470_driver); } static void __exit adt7470_exit(void) { i2c_del_driver(&adt7470_driver); } MODULE_AUTHOR("Darrick J. Wong <djwong@us.ibm.com>"); MODULE_DESCRIPTION("ADT7470 driver"); MODULE_LICENSE("GPL"); module_init(adt7470_init); module_exit(adt7470_exit); |