Ticket #2332: f71882fg-fanspeed.patch
| File f71882fg-fanspeed.patch, 8.1 kB (added by ticket, 6 months ago) |
|---|
-
drivers/hwmon/f71882fg.c
old new 57 57 #define F71882FG_REG_IN1_HIGH 0x32 58 58 59 59 #define F71882FG_REG_FAN(nr) (0xA0 + (16 * (nr))) 60 #define F71882FG_REG_FAN_SPEED(nr) (0xA2 + (16 * (nr))) 60 61 #define F71882FG_REG_FAN_STATUS 0x92 61 62 #define F71882FG_REG_FAN_BEEP 0x93 63 #define F71882FG_REG_FAN_TYPE 0x94 64 #define F71882FG_REG_FAN_MODE 0x96 62 65 63 66 #define F71882FG_REG_TEMP(nr) (0x72 + 2 * (nr)) 64 67 #define F71882FG_REG_TEMP_OVT(nr) (0x82 + 2 * (nr)) … … 102 105 u16 fan[4]; 103 106 u8 fan_status; 104 107 u8 fan_beep; 108 u8 fan_type; 109 u8 fan_mode; 110 u16 fan_speed[4]; 105 111 u8 temp[3]; 106 112 u8 temp_ovt[3]; 107 113 u8 temp_high[3]; … … 132 138 /* Sysfs Fan */ 133 139 static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, 134 140 char *buf); 141 static ssize_t show_fan_type(struct device *dev, struct device_attribute 142 *devattr, char *buf); 143 static ssize_t show_fan_mode(struct device *dev, struct device_attribute 144 *devattr, char *buf); 135 145 static ssize_t show_fan_beep(struct device *dev, struct device_attribute 136 146 *devattr, char *buf); 137 147 static ssize_t store_fan_beep(struct device *dev, struct device_attribute 138 148 *devattr, const char *buf, size_t count); 149 static ssize_t show_fan_speed(struct device *dev, struct device_attribute 150 *devattr, char *buf); 151 static ssize_t store_fan_speed(struct device *dev, struct device_attribute 152 *devattr, const char *buf, size_t count); 139 153 static ssize_t show_fan_alarm(struct device *dev, struct device_attribute 140 154 *devattr, char *buf); 155 /* Sysfs Fan PWM */ 156 static ssize_t show_pwm(struct device *dev, struct device_attribute 157 *devattr, char *buf); 158 static ssize_t store_pwm(struct device *dev, struct device_attribute 159 *devattr, const char *buf, size_t count); 141 160 /* Sysfs Temp */ 142 161 static ssize_t show_temp(struct device *dev, struct device_attribute 143 162 *devattr, char *buf); … … 251 270 SENSOR_ATTR(fan1_beep, S_IRUGO|S_IWUSR, show_fan_beep, 252 271 store_fan_beep, 0), 253 272 SENSOR_ATTR(fan1_alarm, S_IRUGO, show_fan_alarm, NULL, 0), 273 SENSOR_ATTR(fan1_type, S_IRUGO, show_fan_type, NULL, 0), 274 SENSOR_ATTR(fan1_mode, S_IRUGO, show_fan_mode, NULL, 0), 275 SENSOR_ATTR(fan1_speed, S_IRUGO|S_IWUSR, show_fan_speed, 276 store_fan_speed, 0), 277 SENSOR_ATTR(pwm1, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0), 254 278 SENSOR_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1), 255 279 SENSOR_ATTR(fan2_beep, S_IRUGO|S_IWUSR, show_fan_beep, 256 280 store_fan_beep, 1), 257 281 SENSOR_ATTR(fan2_alarm, S_IRUGO, show_fan_alarm, NULL, 1), 282 SENSOR_ATTR(fan2_type, S_IRUGO, show_fan_type, NULL, 1), 283 SENSOR_ATTR(fan2_mode, S_IRUGO, show_fan_mode, NULL, 1), 284 SENSOR_ATTR(fan2_speed, S_IRUGO|S_IWUSR, show_fan_speed, 285 store_fan_speed, 1), 286 SENSOR_ATTR(pwm2, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 1), 258 287 SENSOR_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2), 259 288 SENSOR_ATTR(fan3_beep, S_IRUGO|S_IWUSR, show_fan_beep, 260 289 store_fan_beep, 2), 261 290 SENSOR_ATTR(fan3_alarm, S_IRUGO, show_fan_alarm, NULL, 2), 291 SENSOR_ATTR(fan3_type, S_IRUGO, show_fan_type, NULL, 2), 292 SENSOR_ATTR(fan3_mode, S_IRUGO, show_fan_mode, NULL, 2), 293 SENSOR_ATTR(fan3_speed, S_IRUGO|S_IWUSR, show_fan_speed, 294 store_fan_speed, 2), 295 SENSOR_ATTR(pwm3, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 2), 262 296 SENSOR_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3), 263 297 SENSOR_ATTR(fan4_beep, S_IRUGO|S_IWUSR, show_fan_beep, 264 298 store_fan_beep, 3), 265 SENSOR_ATTR(fan4_alarm, S_IRUGO, show_fan_alarm, NULL, 3) 299 SENSOR_ATTR(fan4_alarm, S_IRUGO, show_fan_alarm, NULL, 3), 300 SENSOR_ATTR(fan4_type, S_IRUGO, show_fan_type, NULL, 3), 301 SENSOR_ATTR(fan4_mode, S_IRUGO, show_fan_mode, NULL, 3), 302 SENSOR_ATTR(fan4_speed, S_IRUGO|S_IWUSR, show_fan_speed, 303 store_fan_speed, 3), 304 SENSOR_ATTR(pwm4, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 3), 266 305 }; 267 306 268 307 … … 379 418 data->temp_beep = f71882fg_read8(data, F71882FG_REG_TEMP_BEEP); 380 419 381 420 data->fan_beep = f71882fg_read8(data, F71882FG_REG_FAN_BEEP); 421 data->fan_type = f71882fg_read8(data, F71882FG_REG_FAN_TYPE); 422 data->fan_mode = f71882fg_read8(data, F71882FG_REG_FAN_MODE); 382 423 383 424 data->last_limits = jiffies; 384 425 } … … 395 436 396 437 data->fan_status = f71882fg_read8(data, 397 438 F71882FG_REG_FAN_STATUS); 398 for (nr = 0; nr < 4; nr++) 439 for (nr = 0; nr < 4; nr++) { 399 440 data->fan[nr] = f71882fg_read16(data, 400 441 F71882FG_REG_FAN(nr)); 442 data->fan_speed[nr] = f71882fg_read16(data, 443 F71882FG_REG_FAN_SPEED(nr)); 444 } 401 445 402 446 data->in_status = f71882fg_read8(data, 403 447 F71882FG_REG_IN_STATUS); … … 471 515 return sprintf(buf, "0\n"); 472 516 } 473 517 518 static ssize_t show_fan_type(struct device *dev, struct device_attribute 519 *devattr, char *buf) 520 { 521 struct f71882fg_data *data = f71882fg_update_device(dev); 522 int nr = to_sensor_dev_attr(devattr)->index; 523 524 /* 2-bit values */ 525 switch(data->fan_type & (3 << (2*nr)) >> (2*nr)) { 526 case 0: 527 return sprintf(buf, "0 PWM (pushpull)\n"); 528 case 1: 529 return sprintf(buf, "1 linear\n"); 530 case 2: 531 return sprintf(buf, "2 PWM (open drain, 4-wire)\n"); 532 default: 533 return sprintf(buf, "3 invalid\n"); 534 } 535 } 536 537 static ssize_t show_fan_mode(struct device *dev, struct device_attribute 538 *devattr, char *buf) 539 { 540 struct f71882fg_data *data = f71882fg_update_device(dev); 541 int nr = to_sensor_dev_attr(devattr)->index; 542 543 /* 2-bit values */ 544 switch(data->fan_mode & (3 << (2*nr)) >> (2*nr)) { 545 case 0: 546 return sprintf(buf, "0 auto (RPM)\n"); 547 case 1: 548 return sprintf(buf, "1 auto (PWM)\n"); 549 case 2: 550 return sprintf(buf, "2 manual (RPM)\n"); 551 default: 552 return sprintf(buf, "3 manual (PWM)\n"); 553 } 554 } 555 556 static ssize_t show_fan_speed(struct device *dev, struct device_attribute 557 *devattr, char *buf) 558 { 559 struct f71882fg_data *data = f71882fg_update_device(dev); 560 int nr = to_sensor_dev_attr(devattr)->index; 561 562 /* 2-bit values */ 563 return sprintf(buf, "%hu\n", data->fan_speed[nr]); 564 } 565 566 static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, 567 char *buf) 568 { 569 struct f71882fg_data *data = f71882fg_update_device(dev); 570 int nr = to_sensor_dev_attr(devattr)->index; 571 int speed = fan_from_reg(data->fan[nr]); 572 573 u8 fan_mode = (data->fan_mode & (3 << (2*nr))) >> 2*nr; 574 575 if (speed == FAN_MIN_DETECT) 576 speed = 0; 577 578 if(fan_mode % 2 == 0) { 579 /* no PWM */ 580 return sprintf(buf, "0\n"); 581 } else { 582 return sprintf(buf, "%hu\n", data->fan_speed[nr]); 583 } 584 } 585 586 static ssize_t store_fan_speed(struct device *dev, struct device_attribute 587 *devattr, const char *buf, size_t count) 588 { 589 struct f71882fg_data *data = dev_get_drvdata(dev); 590 int nr = to_sensor_dev_attr(devattr)->index; 591 int val = (u16)simple_strtoul(buf, NULL, 10); 592 u8 msb, lsb; 593 594 u8 fan_mode = (data->fan_mode & (3 << (2*nr))) >> 2*nr; 595 if(fan_mode <= 1) { 596 /* auto mode, register is read-only */ 597 printk(KERN_INFO DRVNAME ": not setting speed of fan #%d: fan mode is auto\n", nr+1); 598 return count; 599 } 600 601 mutex_lock(&data->update_lock); 602 data->fan_speed[nr] = val; 603 msb = (u8)(data->fan_speed[nr] >> 8); 604 lsb = (u8)(data->fan_speed[nr] & 0xff); 605 if(fan_mode % 2 == 0) { 606 /* only write MSB in RPM mode */ 607 printk(KERN_INFO DRVNAME ": set speed of fan #%d: msb=%d\n", nr+1, (int)lsb); 608 f71882fg_write8(data, F71882FG_REG_FAN_SPEED(nr), msb); 609 } 610 printk(KERN_INFO DRVNAME ": set speed of fan #%d: lsb=%d\n", nr+1, (int)lsb); 611 f71882fg_write8(data, F71882FG_REG_FAN_SPEED(nr)+1, lsb); 612 mutex_unlock(&data->update_lock); 613 614 return count; 615 } 616 617 static ssize_t store_pwm(struct device *dev, struct device_attribute 618 *devattr, const char *buf, size_t count) 619 { 620 struct f71882fg_data *data = dev_get_drvdata(dev); 621 int nr = to_sensor_dev_attr(devattr)->index; 622 int val = (u16)simple_strtoul(buf, NULL, 10); 623 u8 lsb; 624 625 u8 fan_mode = (data->fan_mode & (3 << (2*nr))) >> 2*nr; 626 627 if(fan_mode != 3) { 628 /* no manual PWM */ 629 printk(KERN_INFO DRVNAME ": not setting speed of fan #%d: fan mode is auto or RPM\n", nr+1); 630 return count; 631 } 632 633 mutex_lock(&data->update_lock); 634 data->fan_speed[nr] = val; 635 lsb = (u8)(data->fan_speed[nr] & 0xff); 636 f71882fg_write8(data, F71882FG_REG_FAN_SPEED(nr)+1, lsb); 637 mutex_unlock(&data->update_lock); 638 639 return count; 640 } 641 474 642 static ssize_t show_in(struct device *dev, struct device_attribute *devattr, 475 643 char *buf) 476 644 {
