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

Merge tag 'hwmon-for-v5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging

Pull hwmon updates from Guenter Roeck:

- New drivers for Infineon PXE1610 and IRPS5401

- Minor improvements, cleanup, and fixes in several drivers

* tag 'hwmon-for-v5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: (33 commits)
hwmon: (ina3221) Add of_node_put() before return
hwmon: (gpio-fan) fix sysfs notifications and udev events for gpio-fan alarms
hwmon: (gpio-fan) move fan_alarm_init after devm_hwmon_device_register_with_groups
hwmon: (lm90) Introduce function to update configuration register
hwmon: (lm90) Cache configuration register value
hwmon: (lm90) Fix max6658 sporadic wrong temperature reading
hwmon: (nct7904) Changes comments in probe function.
hwmon: (nct7904) Add error handling in probe function.
hwmon: Convert remaining drivers to use SPDX identifier
hwmon: (max6650) Fix unused variable warning
hwmon: (pmbus/adm1275) Fix power sampling support
hwmon: (lm90) simplify getting the adapter of a client
hwmon: (asus_atk0110) no need to check return value of debugfs_create functions
hwmon: (max6650) Fix minor formatting issues
hwmon: (max6650) Improve error handling in max6650_update_device
hwmon: (max6650) Read non-volatile registers only once
hwmon: (max6650) Convert to use devm_hwmon_device_register_with_info
hwmon: (max6650) Simplify alarm handling
hwmon: (max6650) Cache alarm_en register
hwmon: (max6650) Declare valid as boolean
...

+954 -457
+90
Documentation/hwmon/pxe1610
··· 1 + Kernel driver pxe1610 2 + ===================== 3 + 4 + Supported chips: 5 + * Infineon PXE1610 6 + Prefix: 'pxe1610' 7 + Addresses scanned: - 8 + Datasheet: Datasheet is not publicly available. 9 + 10 + * Infineon PXE1110 11 + Prefix: 'pxe1110' 12 + Addresses scanned: - 13 + Datasheet: Datasheet is not publicly available. 14 + 15 + * Infineon PXM1310 16 + Prefix: 'pxm1310' 17 + Addresses scanned: - 18 + Datasheet: Datasheet is not publicly available. 19 + 20 + Author: Vijay Khemka <vijaykhemka@fb.com> 21 + 22 + 23 + Description 24 + ----------- 25 + 26 + PXE1610/PXE1110 are Multi-rail/Multiphase Digital Controllers 27 + and compliant to 28 + -- Intel VR13 DC-DC converter specifications. 29 + -- Intel SVID protocol. 30 + Used for Vcore power regulation for Intel VR13 based microprocessors 31 + -- Servers, Workstations, and High-end desktops 32 + 33 + PXM1310 is a Multi-rail Controller and it is compliant to 34 + -- Intel VR13 DC-DC converter specifications. 35 + -- Intel SVID protocol. 36 + Used for DDR3/DDR4 Memory power regulation for Intel VR13 and 37 + IMVP8 based systems 38 + 39 + 40 + Usage Notes 41 + ----------- 42 + 43 + This driver does not probe for PMBus devices. You will have 44 + to instantiate devices explicitly. 45 + 46 + Example: the following commands will load the driver for an PXE1610 47 + at address 0x70 on I2C bus #4: 48 + 49 + # modprobe pxe1610 50 + # echo pxe1610 0x70 > /sys/bus/i2c/devices/i2c-4/new_device 51 + 52 + It can also be instantiated by declaring in device tree 53 + 54 + 55 + Sysfs attributes 56 + ---------------- 57 + 58 + curr1_label "iin" 59 + curr1_input Measured input current 60 + curr1_alarm Current high alarm 61 + 62 + curr[2-4]_label "iout[1-3]" 63 + curr[2-4]_input Measured output current 64 + curr[2-4]_crit Critical maximum current 65 + curr[2-4]_crit_alarm Current critical high alarm 66 + 67 + in1_label "vin" 68 + in1_input Measured input voltage 69 + in1_crit Critical maximum input voltage 70 + in1_crit_alarm Input voltage critical high alarm 71 + 72 + in[2-4]_label "vout[1-3]" 73 + in[2-4]_input Measured output voltage 74 + in[2-4]_lcrit Critical minimum output voltage 75 + in[2-4]_lcrit_alarm Output voltage critical low alarm 76 + in[2-4]_crit Critical maximum output voltage 77 + in[2-4]_crit_alarm Output voltage critical high alarm 78 + 79 + power1_label "pin" 80 + power1_input Measured input power 81 + power1_alarm Input power high alarm 82 + 83 + power[2-4]_label "pout[1-3]" 84 + power[2-4]_input Measured output power 85 + 86 + temp[1-3]_input Measured temperature 87 + temp[1-3]_crit Critical high temperature 88 + temp[1-3]_crit_alarm Chip temperature critical high alarm 89 + temp[1-3]_max Maximum temperature 90 + temp[1-3]_max_alarm Chip temperature high alarm
-10
drivers/hwmon/adm1029.c
··· 10 10 * Very rare chip please let me know if you use it 11 11 * 12 12 * http://www.analog.com/UploadedFiles/Data_Sheets/ADM1029.pdf 13 - * 14 - * 15 - * This program is free software; you can redistribute it and/or modify 16 - * it under the terms of the GNU General Public License as published by 17 - * the Free Software Foundation version 2 of the License 18 - * 19 - * This program is distributed in the hope that it will be useful, 20 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 - * GNU General Public License for more details. 23 13 */ 24 14 25 15 #include <linux/module.h>
+3 -20
drivers/hwmon/asus_atk0110.c
··· 789 789 static void atk_debugfs_init(struct atk_data *data) 790 790 { 791 791 struct dentry *d; 792 - struct dentry *f; 793 792 794 793 data->debugfs.id = 0; 795 794 796 795 d = debugfs_create_dir("asus_atk0110", NULL); 797 - if (!d || IS_ERR(d)) 798 - return; 799 796 800 - f = debugfs_create_x32("id", 0600, d, &data->debugfs.id); 801 - if (!f || IS_ERR(f)) 802 - goto cleanup; 803 - 804 - f = debugfs_create_file_unsafe("gitm", 0400, d, data, 805 - &atk_debugfs_gitm); 806 - if (!f || IS_ERR(f)) 807 - goto cleanup; 808 - 809 - f = debugfs_create_file("ggrp", 0400, d, data, 810 - &atk_debugfs_ggrp_fops); 811 - if (!f || IS_ERR(f)) 812 - goto cleanup; 797 + debugfs_create_x32("id", 0600, d, &data->debugfs.id); 798 + debugfs_create_file_unsafe("gitm", 0400, d, data, &atk_debugfs_gitm); 799 + debugfs_create_file("ggrp", 0400, d, data, &atk_debugfs_ggrp_fops); 813 800 814 801 data->debugfs.root = d; 815 - 816 - return; 817 - cleanup: 818 - debugfs_remove_recursive(d); 819 802 } 820 803 821 804 static void atk_debugfs_cleanup(struct atk_data *data)
+12 -10
drivers/hwmon/gpio-fan.c
··· 54 54 struct gpio_fan_data *fan_data = 55 55 container_of(ws, struct gpio_fan_data, alarm_work); 56 56 57 - sysfs_notify(&fan_data->dev->kobj, NULL, "fan1_alarm"); 58 - kobject_uevent(&fan_data->dev->kobj, KOBJ_CHANGE); 57 + sysfs_notify(&fan_data->hwmon_dev->kobj, NULL, "fan1_alarm"); 58 + kobject_uevent(&fan_data->hwmon_dev->kobj, KOBJ_CHANGE); 59 59 } 60 60 61 61 static irqreturn_t fan_alarm_irq_handler(int irq, void *dev_id) ··· 510 510 platform_set_drvdata(pdev, fan_data); 511 511 mutex_init(&fan_data->lock); 512 512 513 - /* Configure alarm GPIO if available. */ 514 - if (fan_data->alarm_gpio) { 515 - err = fan_alarm_init(fan_data); 516 - if (err) 517 - return err; 518 - } 519 - 520 513 /* Configure control GPIOs if available. */ 521 514 if (fan_data->gpios && fan_data->num_gpios > 0) { 522 515 if (!fan_data->speed || fan_data->num_speed <= 1) ··· 517 524 err = fan_ctrl_init(fan_data); 518 525 if (err) 519 526 return err; 520 - devm_add_action_or_reset(dev, gpio_fan_stop, fan_data); 527 + err = devm_add_action_or_reset(dev, gpio_fan_stop, fan_data); 528 + if (err) 529 + return err; 521 530 } 522 531 523 532 /* Make this driver part of hwmon class. */ ··· 529 534 gpio_fan_groups); 530 535 if (IS_ERR(fan_data->hwmon_dev)) 531 536 return PTR_ERR(fan_data->hwmon_dev); 537 + 538 + /* Configure alarm GPIO if available. */ 539 + if (fan_data->alarm_gpio) { 540 + err = fan_alarm_init(fan_data); 541 + if (err) 542 + return err; 543 + } 532 544 533 545 /* Optional cooling device register for Device tree platforms */ 534 546 fan_data->cdev = devm_thermal_of_cooling_device_register(dev, np,
+6
drivers/hwmon/hwmon.c
··· 651 651 hwdev, j); 652 652 if (err) { 653 653 device_unregister(hdev); 654 + /* 655 + * Don't worry about hwdev; 656 + * hwmon_dev_release(), called 657 + * from device_unregister(), 658 + * will free it. 659 + */ 654 660 goto ida_remove; 655 661 } 656 662 }
+3 -1
drivers/hwmon/ina3221.c
··· 713 713 714 714 for_each_child_of_node(np, child) { 715 715 ret = ina3221_probe_child_from_dt(dev, child, ina); 716 - if (ret) 716 + if (ret) { 717 + of_node_put(child); 717 718 return ret; 719 + } 718 720 } 719 721 720 722 return 0;
+64 -42
drivers/hwmon/lm90.c
··· 174 174 #define LM90_HAVE_EMERGENCY_ALARM (1 << 5)/* emergency alarm */ 175 175 #define LM90_HAVE_TEMP3 (1 << 6) /* 3rd temperature sensor */ 176 176 #define LM90_HAVE_BROKEN_ALERT (1 << 7) /* Broken alert */ 177 + #define LM90_PAUSE_FOR_CONFIG (1 << 8) /* Pause conversion for config */ 177 178 178 179 /* LM90 status */ 179 180 #define LM90_STATUS_LTHRM (1 << 0) /* local THERM limit tripped */ ··· 368 367 .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL, 369 368 }, 370 369 [max6657] = { 370 + .flags = LM90_PAUSE_FOR_CONFIG, 371 371 .alert_alarms = 0x7c, 372 372 .max_convrate = 8, 373 373 .reg_local_ext = MAX6657_REG_R_LOCAL_TEMPL, ··· 459 457 460 458 unsigned int update_interval; /* in milliseconds */ 461 459 460 + u8 config; /* Current configuration register value */ 462 461 u8 config_orig; /* Original configuration register value */ 463 462 u8 convrate_orig; /* Original conversion rate register value */ 464 463 u16 alert_alarms; /* Which alarm bits trigger ALERT# */ ··· 543 540 return (newh << 8) | l; 544 541 } 545 542 543 + static int lm90_update_confreg(struct lm90_data *data, u8 config) 544 + { 545 + if (data->config != config) { 546 + int err; 547 + 548 + err = i2c_smbus_write_byte_data(data->client, 549 + LM90_REG_W_CONFIG1, 550 + config); 551 + if (err) 552 + return err; 553 + data->config = config; 554 + } 555 + return 0; 556 + } 557 + 546 558 /* 547 559 * client->update_lock must be held when calling this function (unless we are 548 560 * in detection or initialization steps), and while a remote channel other ··· 566 548 * various registers have different meanings as a result of selecting a 567 549 * non-default remote channel. 568 550 */ 569 - static inline int lm90_select_remote_channel(struct i2c_client *client, 570 - struct lm90_data *data, 571 - int channel) 551 + static int lm90_select_remote_channel(struct lm90_data *data, int channel) 572 552 { 573 - int config; 553 + int err = 0; 574 554 575 555 if (data->kind == max6696) { 576 - config = lm90_read_reg(client, LM90_REG_R_CONFIG1); 577 - if (config < 0) 578 - return config; 579 - config &= ~0x08; 556 + u8 config = data->config & ~0x08; 557 + 580 558 if (channel) 581 559 config |= 0x08; 582 - i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, 583 - config); 560 + err = lm90_update_confreg(data, config); 584 561 } 585 - return 0; 562 + return err; 563 + } 564 + 565 + static int lm90_write_convrate(struct lm90_data *data, int val) 566 + { 567 + u8 config = data->config; 568 + int err; 569 + 570 + /* Save config and pause conversion */ 571 + if (data->flags & LM90_PAUSE_FOR_CONFIG) { 572 + err = lm90_update_confreg(data, config | 0x40); 573 + if (err < 0) 574 + return err; 575 + } 576 + 577 + /* Set conv rate */ 578 + err = i2c_smbus_write_byte_data(data->client, LM90_REG_W_CONVRATE, val); 579 + 580 + /* Revert change to config */ 581 + lm90_update_confreg(data, config); 582 + 583 + return err; 586 584 } 587 585 588 586 /* ··· 621 587 if (interval >= update_interval * 3 / 4) 622 588 break; 623 589 624 - err = i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE, i); 590 + err = lm90_write_convrate(data, i); 625 591 data->update_interval = DIV_ROUND_CLOSEST(update_interval, 64); 626 592 return err; 627 593 } ··· 692 658 } 693 659 694 660 if (data->kind == max6696) { 695 - val = lm90_select_remote_channel(client, data, 1); 661 + val = lm90_select_remote_channel(data, 1); 696 662 if (val < 0) 697 663 return val; 698 664 ··· 716 682 return val; 717 683 data->temp11[REMOTE2_HIGH] = val << 8; 718 684 719 - lm90_select_remote_channel(client, data, 0); 685 + lm90_select_remote_channel(data, 0); 720 686 } 721 687 722 688 return 0; ··· 776 742 data->alarms = val; /* lower 8 bit of alarms */ 777 743 778 744 if (data->kind == max6696) { 779 - val = lm90_select_remote_channel(client, data, 1); 745 + val = lm90_select_remote_channel(data, 1); 780 746 if (val < 0) 781 747 return val; 782 748 783 749 val = lm90_read16(client, LM90_REG_R_REMOTE_TEMPH, 784 750 LM90_REG_R_REMOTE_TEMPL); 785 751 if (val < 0) { 786 - lm90_select_remote_channel(client, data, 0); 752 + lm90_select_remote_channel(data, 0); 787 753 return val; 788 754 } 789 755 data->temp11[REMOTE2_TEMP] = val; 790 756 791 - lm90_select_remote_channel(client, data, 0); 757 + lm90_select_remote_channel(data, 0); 792 758 793 759 val = lm90_read_reg(client, MAX6696_REG_R_STATUS2); 794 760 if (val < 0) ··· 802 768 */ 803 769 if (!(data->config_orig & 0x80) && 804 770 !(data->alarms & data->alert_alarms)) { 805 - val = lm90_read_reg(client, LM90_REG_R_CONFIG1); 806 - if (val < 0) 807 - return val; 808 - 809 - if (val & 0x80) { 771 + if (data->config & 0x80) { 810 772 dev_dbg(&client->dev, "Re-enabling ALERT#\n"); 811 - i2c_smbus_write_byte_data(client, 812 - LM90_REG_W_CONFIG1, 813 - val & ~0x80); 773 + lm90_update_confreg(data, data->config & ~0x80); 814 774 } 815 775 } 816 776 ··· 1022 994 else 1023 995 data->temp11[index] = temp_to_s8(val) << 8; 1024 996 1025 - lm90_select_remote_channel(client, data, index >= 3); 997 + lm90_select_remote_channel(data, index >= 3); 1026 998 err = i2c_smbus_write_byte_data(client, regp->high, 1027 999 data->temp11[index] >> 8); 1028 1000 if (err < 0) ··· 1031 1003 err = i2c_smbus_write_byte_data(client, regp->low, 1032 1004 data->temp11[index] & 0xff); 1033 1005 1034 - lm90_select_remote_channel(client, data, 0); 1006 + lm90_select_remote_channel(data, 0); 1035 1007 return err; 1036 1008 } 1037 1009 ··· 1080 1052 else 1081 1053 data->temp8[index] = temp_to_s8(val); 1082 1054 1083 - lm90_select_remote_channel(client, data, index >= 6); 1055 + lm90_select_remote_channel(data, index >= 6); 1084 1056 err = i2c_smbus_write_byte_data(client, reg[index], data->temp8[index]); 1085 - lm90_select_remote_channel(client, data, 0); 1057 + lm90_select_remote_channel(data, 0); 1086 1058 1087 1059 return err; 1088 1060 } ··· 1621 1593 struct i2c_client *client = data->client; 1622 1594 1623 1595 /* Restore initial configuration */ 1624 - i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE, 1625 - data->convrate_orig); 1596 + lm90_write_convrate(data, data->convrate_orig); 1626 1597 i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, 1627 1598 data->config_orig); 1628 1599 } ··· 1638 1611 /* 1639 1612 * Start the conversions. 1640 1613 */ 1641 - lm90_set_convrate(client, data, 500); /* 500ms; 2Hz conversion rate */ 1642 1614 config = lm90_read_reg(client, LM90_REG_R_CONFIG1); 1643 1615 if (config < 0) 1644 1616 return config; 1645 1617 data->config_orig = config; 1618 + data->config = config; 1619 + 1620 + lm90_set_convrate(client, data, 500); /* 500ms; 2Hz conversion rate */ 1646 1621 1647 1622 /* Check Temperature Range Select */ 1648 1623 if (data->kind == adt7461 || data->kind == tmp451) { ··· 1667 1638 config &= ~0x08; 1668 1639 1669 1640 config &= 0xBF; /* run */ 1670 - if (config != data->config_orig) /* Only write if changed */ 1671 - i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config); 1641 + lm90_update_confreg(data, config); 1672 1642 1673 1643 return devm_add_action_or_reset(&client->dev, lm90_restore_conf, data); 1674 1644 } ··· 1746 1718 const struct i2c_device_id *id) 1747 1719 { 1748 1720 struct device *dev = &client->dev; 1749 - struct i2c_adapter *adapter = to_i2c_adapter(dev->parent); 1721 + struct i2c_adapter *adapter = client->adapter; 1750 1722 struct hwmon_channel_info *info; 1751 1723 struct regulator *regulator; 1752 1724 struct device *hwmon_dev; ··· 1901 1873 1902 1874 if ((data->flags & LM90_HAVE_BROKEN_ALERT) && 1903 1875 (alarms & data->alert_alarms)) { 1904 - int config; 1905 - 1906 1876 dev_dbg(&client->dev, "Disabling ALERT#\n"); 1907 - config = lm90_read_reg(client, LM90_REG_R_CONFIG1); 1908 - if (config >= 0) 1909 - i2c_smbus_write_byte_data(client, 1910 - LM90_REG_W_CONFIG1, 1911 - config | 0x80); 1877 + lm90_update_confreg(data, data->config | 0x80); 1912 1878 } 1913 1879 } else { 1914 1880 dev_info(&client->dev, "Everything OK\n");
+356 -354
drivers/hwmon/max6650.c
··· 92 92 #define FAN_RPM_MIN 240 93 93 #define FAN_RPM_MAX 30000 94 94 95 - #define DIV_FROM_REG(reg) (1 << (reg & 7)) 95 + #define DIV_FROM_REG(reg) (1 << ((reg) & 7)) 96 + #define DAC_LIMIT(v12) ((v12) ? 180 : 76) 96 97 97 98 /* 98 99 * Client data (each client gets its own) ··· 101 100 102 101 struct max6650_data { 103 102 struct i2c_client *client; 104 - const struct attribute_group *groups[3]; 105 - struct thermal_cooling_device *cooling_dev; 106 - struct mutex update_lock; 103 + struct mutex update_lock; /* protect alarm register updates */ 107 104 int nr_fans; 108 - char valid; /* zero until following fields are valid */ 105 + bool valid; /* false until following fields are valid */ 109 106 unsigned long last_updated; /* in jiffies */ 110 107 111 108 /* register values */ ··· 113 114 u8 count; 114 115 u8 dac; 115 116 u8 alarm; 117 + u8 alarm_en; 116 118 unsigned long cooling_dev_state; 117 119 }; 118 120 ··· 137 137 }; 138 138 MODULE_DEVICE_TABLE(of, max6650_dt_match); 139 139 140 + static int dac_to_pwm(int dac, bool v12) 141 + { 142 + /* 143 + * Useful range for dac is 0-180 for 12V fans and 0-76 for 5V fans. 144 + * Lower DAC values mean higher speeds. 145 + */ 146 + return clamp_val(255 - (255 * dac) / DAC_LIMIT(v12), 0, 255); 147 + } 148 + 149 + static u8 pwm_to_dac(unsigned int pwm, bool v12) 150 + { 151 + int limit = DAC_LIMIT(v12); 152 + 153 + return limit - (limit * pwm) / 255; 154 + } 155 + 140 156 static struct max6650_data *max6650_update_device(struct device *dev) 141 157 { 142 158 struct max6650_data *data = dev_get_drvdata(dev); 143 159 struct i2c_client *client = data->client; 160 + int reg, err = 0; 144 161 int i; 145 162 146 163 mutex_lock(&data->update_lock); 147 164 148 165 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { 149 - data->speed = i2c_smbus_read_byte_data(client, 150 - MAX6650_REG_SPEED); 151 - data->config = i2c_smbus_read_byte_data(client, 152 - MAX6650_REG_CONFIG); 153 166 for (i = 0; i < data->nr_fans; i++) { 154 - data->tach[i] = i2c_smbus_read_byte_data(client, 155 - tach_reg[i]); 167 + reg = i2c_smbus_read_byte_data(client, tach_reg[i]); 168 + if (reg < 0) { 169 + err = reg; 170 + goto error; 171 + } 172 + data->tach[i] = reg; 156 173 } 157 - data->count = i2c_smbus_read_byte_data(client, 158 - MAX6650_REG_COUNT); 159 - data->dac = i2c_smbus_read_byte_data(client, MAX6650_REG_DAC); 160 174 161 175 /* 162 176 * Alarms are cleared on read in case the condition that 163 177 * caused the alarm is removed. Keep the value latched here 164 178 * for providing the register through different alarm files. 165 179 */ 166 - data->alarm |= i2c_smbus_read_byte_data(client, 167 - MAX6650_REG_ALARM); 168 - 180 + reg = i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM); 181 + if (reg < 0) { 182 + err = reg; 183 + goto error; 184 + } 185 + data->alarm |= reg; 169 186 data->last_updated = jiffies; 170 - data->valid = 1; 187 + data->valid = true; 171 188 } 172 189 190 + error: 173 191 mutex_unlock(&data->update_lock); 174 - 192 + if (err) 193 + data = ERR_PTR(err); 175 194 return data; 176 195 } 177 196 ··· 216 197 data->config = config; 217 198 218 199 return 0; 219 - } 220 - 221 - static ssize_t fan_show(struct device *dev, struct device_attribute *devattr, 222 - char *buf) 223 - { 224 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 225 - struct max6650_data *data = max6650_update_device(dev); 226 - int rpm; 227 - 228 - /* 229 - * Calculation details: 230 - * 231 - * Each tachometer counts over an interval given by the "count" 232 - * register (0.25, 0.5, 1 or 2 seconds). This module assumes 233 - * that the fans produce two pulses per revolution (this seems 234 - * to be the most common). 235 - */ 236 - 237 - rpm = ((data->tach[attr->index] * 120) / DIV_FROM_REG(data->count)); 238 - return sprintf(buf, "%d\n", rpm); 239 200 } 240 201 241 202 /* ··· 259 260 * controlled. 260 261 */ 261 262 262 - static ssize_t fan1_target_show(struct device *dev, 263 - struct device_attribute *devattr, char *buf) 264 - { 265 - struct max6650_data *data = max6650_update_device(dev); 266 - int kscale, ktach, rpm; 267 - 268 - /* 269 - * Use the datasheet equation: 270 - * 271 - * FanSpeed = KSCALE x fCLK / [256 x (KTACH + 1)] 272 - * 273 - * then multiply by 60 to give rpm. 274 - */ 275 - 276 - kscale = DIV_FROM_REG(data->config); 277 - ktach = data->speed; 278 - rpm = 60 * kscale * clock / (256 * (ktach + 1)); 279 - return sprintf(buf, "%d\n", rpm); 280 - } 281 - 282 263 static int max6650_set_target(struct max6650_data *data, unsigned long rpm) 283 264 { 284 265 int kscale, ktach; ··· 287 308 data->speed); 288 309 } 289 310 290 - static ssize_t fan1_target_store(struct device *dev, 291 - struct device_attribute *devattr, 292 - const char *buf, size_t count) 293 - { 294 - struct max6650_data *data = dev_get_drvdata(dev); 295 - unsigned long rpm; 296 - int err; 297 - 298 - err = kstrtoul(buf, 10, &rpm); 299 - if (err) 300 - return err; 301 - 302 - mutex_lock(&data->update_lock); 303 - 304 - err = max6650_set_target(data, rpm); 305 - 306 - mutex_unlock(&data->update_lock); 307 - 308 - if (err < 0) 309 - return err; 310 - 311 - return count; 312 - } 313 - 314 311 /* 315 - * Get/set the fan speed in open loop mode using pwm1 sysfs file. 316 - * Speed is given as a relative value from 0 to 255, where 255 is maximum 317 - * speed. Note that this is done by writing directly to the chip's DAC, 318 - * it won't change the closed loop speed set by fan1_target. 319 - * Also note that due to rounding errors it is possible that you don't read 320 - * back exactly the value you have set. 321 - */ 322 - 323 - static ssize_t pwm1_show(struct device *dev, struct device_attribute *devattr, 324 - char *buf) 325 - { 326 - int pwm; 327 - struct max6650_data *data = max6650_update_device(dev); 328 - 329 - /* 330 - * Useful range for dac is 0-180 for 12V fans and 0-76 for 5V fans. 331 - * Lower DAC values mean higher speeds. 332 - */ 333 - if (data->config & MAX6650_CFG_V12) 334 - pwm = 255 - (255 * (int)data->dac)/180; 335 - else 336 - pwm = 255 - (255 * (int)data->dac)/76; 337 - 338 - if (pwm < 0) 339 - pwm = 0; 340 - 341 - return sprintf(buf, "%d\n", pwm); 342 - } 343 - 344 - static ssize_t pwm1_store(struct device *dev, 345 - struct device_attribute *devattr, const char *buf, 346 - size_t count) 347 - { 348 - struct max6650_data *data = dev_get_drvdata(dev); 349 - struct i2c_client *client = data->client; 350 - unsigned long pwm; 351 - int err; 352 - 353 - err = kstrtoul(buf, 10, &pwm); 354 - if (err) 355 - return err; 356 - 357 - pwm = clamp_val(pwm, 0, 255); 358 - 359 - mutex_lock(&data->update_lock); 360 - 361 - if (data->config & MAX6650_CFG_V12) 362 - data->dac = 180 - (180 * pwm)/255; 363 - else 364 - data->dac = 76 - (76 * pwm)/255; 365 - err = i2c_smbus_write_byte_data(client, MAX6650_REG_DAC, data->dac); 366 - 367 - mutex_unlock(&data->update_lock); 368 - 369 - return err < 0 ? err : count; 370 - } 371 - 372 - /* 373 - * Get/Set controller mode: 374 - * Possible values: 375 - * 0 = Fan always on 376 - * 1 = Open loop, Voltage is set according to speed, not regulated. 377 - * 2 = Closed loop, RPM for all fans regulated by fan1 tachometer 378 - * 3 = Fan off 379 - */ 380 - static ssize_t pwm1_enable_show(struct device *dev, 381 - struct device_attribute *devattr, char *buf) 382 - { 383 - struct max6650_data *data = max6650_update_device(dev); 384 - int mode = (data->config & MAX6650_CFG_MODE_MASK) >> 4; 385 - int sysfs_modes[4] = {0, 3, 2, 1}; 386 - 387 - return sprintf(buf, "%d\n", sysfs_modes[mode]); 388 - } 389 - 390 - static ssize_t pwm1_enable_store(struct device *dev, 391 - struct device_attribute *devattr, 392 - const char *buf, size_t count) 393 - { 394 - struct max6650_data *data = dev_get_drvdata(dev); 395 - unsigned long mode; 396 - int err; 397 - const u8 max6650_modes[] = { 398 - MAX6650_CFG_MODE_ON, 399 - MAX6650_CFG_MODE_OPEN_LOOP, 400 - MAX6650_CFG_MODE_CLOSED_LOOP, 401 - MAX6650_CFG_MODE_OFF, 402 - }; 403 - 404 - err = kstrtoul(buf, 10, &mode); 405 - if (err) 406 - return err; 407 - 408 - if (mode >= ARRAY_SIZE(max6650_modes)) 409 - return -EINVAL; 410 - 411 - mutex_lock(&data->update_lock); 412 - 413 - max6650_set_operating_mode(data, max6650_modes[mode]); 414 - 415 - mutex_unlock(&data->update_lock); 416 - 417 - return count; 418 - } 419 - 420 - /* 421 - * Read/write functions for fan1_div sysfs file. The MAX6650 has no such 422 - * divider. We handle this by converting between divider and counttime: 423 - * 424 - * (counttime == k) <==> (divider == 2^k), k = 0, 1, 2, or 3 425 - * 426 - * Lower values of k allow to connect a faster fan without the risk of 427 - * counter overflow. The price is lower resolution. You can also set counttime 428 - * using the module parameter. Note that the module parameter "prescaler" also 429 - * influences the behaviour. Unfortunately, there's no sysfs attribute 430 - * defined for that. See the data sheet for details. 431 - */ 432 - 433 - static ssize_t fan1_div_show(struct device *dev, 434 - struct device_attribute *devattr, char *buf) 435 - { 436 - struct max6650_data *data = max6650_update_device(dev); 437 - 438 - return sprintf(buf, "%d\n", DIV_FROM_REG(data->count)); 439 - } 440 - 441 - static ssize_t fan1_div_store(struct device *dev, 442 - struct device_attribute *devattr, 443 - const char *buf, size_t count) 444 - { 445 - struct max6650_data *data = dev_get_drvdata(dev); 446 - struct i2c_client *client = data->client; 447 - unsigned long div; 448 - int err; 449 - 450 - err = kstrtoul(buf, 10, &div); 451 - if (err) 452 - return err; 453 - 454 - mutex_lock(&data->update_lock); 455 - switch (div) { 456 - case 1: 457 - data->count = 0; 458 - break; 459 - case 2: 460 - data->count = 1; 461 - break; 462 - case 4: 463 - data->count = 2; 464 - break; 465 - case 8: 466 - data->count = 3; 467 - break; 468 - default: 469 - mutex_unlock(&data->update_lock); 470 - return -EINVAL; 471 - } 472 - 473 - i2c_smbus_write_byte_data(client, MAX6650_REG_COUNT, data->count); 474 - mutex_unlock(&data->update_lock); 475 - 476 - return count; 477 - } 478 - 479 - /* 480 - * Get alarm stati: 312 + * Get gpio alarm status: 481 313 * Possible values: 482 314 * 0 = no alarm 483 315 * 1 = alarm ··· 299 509 { 300 510 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 301 511 struct max6650_data *data = max6650_update_device(dev); 302 - struct i2c_client *client = data->client; 303 - int alarm = 0; 512 + bool alarm; 304 513 305 - if (data->alarm & attr->index) { 514 + if (IS_ERR(data)) 515 + return PTR_ERR(data); 516 + 517 + alarm = data->alarm & attr->index; 518 + if (alarm) { 306 519 mutex_lock(&data->update_lock); 307 - alarm = 1; 308 520 data->alarm &= ~attr->index; 309 - data->alarm |= i2c_smbus_read_byte_data(client, 310 - MAX6650_REG_ALARM); 521 + data->valid = false; 311 522 mutex_unlock(&data->update_lock); 312 523 } 313 524 314 525 return sprintf(buf, "%d\n", alarm); 315 526 } 316 527 317 - static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, 0); 318 - static SENSOR_DEVICE_ATTR_RO(fan2_input, fan, 1); 319 - static SENSOR_DEVICE_ATTR_RO(fan3_input, fan, 2); 320 - static SENSOR_DEVICE_ATTR_RO(fan4_input, fan, 3); 321 - static DEVICE_ATTR_RW(fan1_target); 322 - static DEVICE_ATTR_RW(fan1_div); 323 - static DEVICE_ATTR_RW(pwm1_enable); 324 - static DEVICE_ATTR_RW(pwm1); 325 - static SENSOR_DEVICE_ATTR_RO(fan1_max_alarm, alarm, MAX6650_ALRM_MAX); 326 - static SENSOR_DEVICE_ATTR_RO(fan1_min_alarm, alarm, MAX6650_ALRM_MIN); 327 - static SENSOR_DEVICE_ATTR_RO(fan1_fault, alarm, MAX6650_ALRM_TACH); 328 528 static SENSOR_DEVICE_ATTR_RO(gpio1_alarm, alarm, MAX6650_ALRM_GPIO1); 329 529 static SENSOR_DEVICE_ATTR_RO(gpio2_alarm, alarm, MAX6650_ALRM_GPIO2); 330 530 331 531 static umode_t max6650_attrs_visible(struct kobject *kobj, struct attribute *a, 332 - int n) 532 + int n) 333 533 { 334 534 struct device *dev = container_of(kobj, struct device, kobj); 335 535 struct max6650_data *data = dev_get_drvdata(dev); 336 - struct i2c_client *client = data->client; 337 - u8 alarm_en = i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM_EN); 338 536 struct device_attribute *devattr; 339 537 340 538 /* ··· 330 552 */ 331 553 332 554 devattr = container_of(a, struct device_attribute, attr); 333 - if (devattr == &sensor_dev_attr_fan1_max_alarm.dev_attr 334 - || devattr == &sensor_dev_attr_fan1_min_alarm.dev_attr 335 - || devattr == &sensor_dev_attr_fan1_fault.dev_attr 336 - || devattr == &sensor_dev_attr_gpio1_alarm.dev_attr 337 - || devattr == &sensor_dev_attr_gpio2_alarm.dev_attr) { 338 - if (!(alarm_en & to_sensor_dev_attr(devattr)->index)) 555 + if (devattr == &sensor_dev_attr_gpio1_alarm.dev_attr || 556 + devattr == &sensor_dev_attr_gpio2_alarm.dev_attr) { 557 + if (!(data->alarm_en & to_sensor_dev_attr(devattr)->index)) 339 558 return 0; 340 559 } 341 560 ··· 340 565 } 341 566 342 567 static struct attribute *max6650_attrs[] = { 343 - &sensor_dev_attr_fan1_input.dev_attr.attr, 344 - &dev_attr_fan1_target.attr, 345 - &dev_attr_fan1_div.attr, 346 - &dev_attr_pwm1_enable.attr, 347 - &dev_attr_pwm1.attr, 348 - &sensor_dev_attr_fan1_max_alarm.dev_attr.attr, 349 - &sensor_dev_attr_fan1_min_alarm.dev_attr.attr, 350 - &sensor_dev_attr_fan1_fault.dev_attr.attr, 351 568 &sensor_dev_attr_gpio1_alarm.dev_attr.attr, 352 569 &sensor_dev_attr_gpio2_alarm.dev_attr.attr, 353 570 NULL ··· 350 583 .is_visible = max6650_attrs_visible, 351 584 }; 352 585 353 - static struct attribute *max6651_attrs[] = { 354 - &sensor_dev_attr_fan2_input.dev_attr.attr, 355 - &sensor_dev_attr_fan3_input.dev_attr.attr, 356 - &sensor_dev_attr_fan4_input.dev_attr.attr, 586 + static const struct attribute_group *max6650_groups[] = { 587 + &max6650_group, 357 588 NULL 358 589 }; 359 - 360 - static const struct attribute_group max6651_group = { 361 - .attrs = max6651_attrs, 362 - }; 363 - 364 - /* 365 - * Real code 366 - */ 367 590 368 591 static int max6650_init_client(struct max6650_data *data, 369 592 struct i2c_client *client) 370 593 { 371 594 struct device *dev = &client->dev; 372 - int config; 373 - int err = -EIO; 595 + int reg; 596 + int err; 374 597 u32 voltage; 375 598 u32 prescale; 376 599 u32 target_rpm; ··· 374 617 &prescale)) 375 618 prescale = prescaler; 376 619 377 - config = i2c_smbus_read_byte_data(client, MAX6650_REG_CONFIG); 378 - 379 - if (config < 0) { 380 - dev_err(dev, "Error reading config, aborting.\n"); 381 - return err; 620 + reg = i2c_smbus_read_byte_data(client, MAX6650_REG_CONFIG); 621 + if (reg < 0) { 622 + dev_err(dev, "Error reading config register, aborting.\n"); 623 + return reg; 382 624 } 383 625 384 626 switch (voltage) { 385 627 case 0: 386 628 break; 387 629 case 5: 388 - config &= ~MAX6650_CFG_V12; 630 + reg &= ~MAX6650_CFG_V12; 389 631 break; 390 632 case 12: 391 - config |= MAX6650_CFG_V12; 633 + reg |= MAX6650_CFG_V12; 392 634 break; 393 635 default: 394 636 dev_err(dev, "illegal value for fan_voltage (%d)\n", voltage); ··· 397 641 case 0: 398 642 break; 399 643 case 1: 400 - config &= ~MAX6650_CFG_PRESCALER_MASK; 644 + reg &= ~MAX6650_CFG_PRESCALER_MASK; 401 645 break; 402 646 case 2: 403 - config = (config & ~MAX6650_CFG_PRESCALER_MASK) 647 + reg = (reg & ~MAX6650_CFG_PRESCALER_MASK) 404 648 | MAX6650_CFG_PRESCALER_2; 405 649 break; 406 650 case 4: 407 - config = (config & ~MAX6650_CFG_PRESCALER_MASK) 651 + reg = (reg & ~MAX6650_CFG_PRESCALER_MASK) 408 652 | MAX6650_CFG_PRESCALER_4; 409 653 break; 410 654 case 8: 411 - config = (config & ~MAX6650_CFG_PRESCALER_MASK) 655 + reg = (reg & ~MAX6650_CFG_PRESCALER_MASK) 412 656 | MAX6650_CFG_PRESCALER_8; 413 657 break; 414 658 case 16: 415 - config = (config & ~MAX6650_CFG_PRESCALER_MASK) 659 + reg = (reg & ~MAX6650_CFG_PRESCALER_MASK) 416 660 | MAX6650_CFG_PRESCALER_16; 417 661 break; 418 662 default: ··· 420 664 } 421 665 422 666 dev_info(dev, "Fan voltage: %dV, prescaler: %d.\n", 423 - (config & MAX6650_CFG_V12) ? 12 : 5, 424 - 1 << (config & MAX6650_CFG_PRESCALER_MASK)); 667 + (reg & MAX6650_CFG_V12) ? 12 : 5, 668 + 1 << (reg & MAX6650_CFG_PRESCALER_MASK)); 425 669 426 - if (i2c_smbus_write_byte_data(client, MAX6650_REG_CONFIG, config)) { 670 + err = i2c_smbus_write_byte_data(client, MAX6650_REG_CONFIG, reg); 671 + if (err) { 427 672 dev_err(dev, "Config write error, aborting.\n"); 428 673 return err; 429 674 } 675 + data->config = reg; 430 676 431 - data->config = config; 432 - data->count = i2c_smbus_read_byte_data(client, MAX6650_REG_COUNT); 677 + reg = i2c_smbus_read_byte_data(client, MAX6650_REG_SPEED); 678 + if (reg < 0) { 679 + dev_err(dev, "Failed to read speed register, aborting.\n"); 680 + return reg; 681 + } 682 + data->speed = reg; 683 + 684 + reg = i2c_smbus_read_byte_data(client, MAX6650_REG_DAC); 685 + if (reg < 0) { 686 + dev_err(dev, "Failed to read DAC register, aborting.\n"); 687 + return reg; 688 + } 689 + data->dac = reg; 690 + 691 + reg = i2c_smbus_read_byte_data(client, MAX6650_REG_COUNT); 692 + if (reg < 0) { 693 + dev_err(dev, "Failed to read count register, aborting.\n"); 694 + return reg; 695 + } 696 + data->count = reg; 697 + 698 + reg = i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM_EN); 699 + if (reg < 0) { 700 + dev_err(dev, "Failed to read alarm configuration, aborting.\n"); 701 + return reg; 702 + } 703 + data->alarm_en = reg; 433 704 434 705 if (!of_property_read_u32(client->dev.of_node, "maxim,fan-target-rpm", 435 706 &target_rpm)) { ··· 466 683 467 684 return 0; 468 685 } 469 - 470 - #if IS_ENABLED(CONFIG_THERMAL) 471 686 472 687 static int max6650_get_max_state(struct thermal_cooling_device *cdev, 473 688 unsigned long *state) ··· 496 715 497 716 mutex_lock(&data->update_lock); 498 717 499 - if (data->config & MAX6650_CFG_V12) 500 - data->dac = 180 - (180 * state)/255; 501 - else 502 - data->dac = 76 - (76 * state)/255; 503 - 718 + data->dac = pwm_to_dac(state, data->config & MAX6650_CFG_V12); 504 719 err = i2c_smbus_write_byte_data(client, MAX6650_REG_DAC, data->dac); 505 - 506 720 if (!err) { 507 721 max6650_set_operating_mode(data, state ? 508 - MAX6650_CFG_MODE_OPEN_LOOP : 509 - MAX6650_CFG_MODE_OFF); 722 + MAX6650_CFG_MODE_OPEN_LOOP : 723 + MAX6650_CFG_MODE_OFF); 510 724 data->cooling_dev_state = state; 511 725 } 512 726 513 727 mutex_unlock(&data->update_lock); 514 728 515 - return err < 0 ? err : 0; 729 + return err; 516 730 } 517 731 518 732 static const struct thermal_cooling_device_ops max6650_cooling_ops = { ··· 515 739 .get_cur_state = max6650_get_cur_state, 516 740 .set_cur_state = max6650_set_cur_state, 517 741 }; 518 - #endif 742 + 743 + static int max6650_read(struct device *dev, enum hwmon_sensor_types type, 744 + u32 attr, int channel, long *val) 745 + { 746 + struct max6650_data *data = max6650_update_device(dev); 747 + int mode; 748 + 749 + if (IS_ERR(data)) 750 + return PTR_ERR(data); 751 + 752 + switch (type) { 753 + case hwmon_pwm: 754 + switch (attr) { 755 + case hwmon_pwm_input: 756 + *val = dac_to_pwm(data->dac, 757 + data->config & MAX6650_CFG_V12); 758 + break; 759 + case hwmon_pwm_enable: 760 + /* 761 + * Possible values: 762 + * 0 = Fan always on 763 + * 1 = Open loop, Voltage is set according to speed, 764 + * not regulated. 765 + * 2 = Closed loop, RPM for all fans regulated by fan1 766 + * tachometer 767 + * 3 = Fan off 768 + */ 769 + mode = (data->config & MAX6650_CFG_MODE_MASK) >> 4; 770 + *val = (4 - mode) & 3; /* {0 1 2 3} -> {0 3 2 1} */ 771 + break; 772 + default: 773 + return -EOPNOTSUPP; 774 + } 775 + break; 776 + case hwmon_fan: 777 + switch (attr) { 778 + case hwmon_fan_input: 779 + /* 780 + * Calculation details: 781 + * 782 + * Each tachometer counts over an interval given by the 783 + * "count" register (0.25, 0.5, 1 or 2 seconds). 784 + * The driver assumes that the fans produce two pulses 785 + * per revolution (this seems to be the most common). 786 + */ 787 + *val = DIV_ROUND_CLOSEST(data->tach[channel] * 120, 788 + DIV_FROM_REG(data->count)); 789 + break; 790 + case hwmon_fan_div: 791 + *val = DIV_FROM_REG(data->count); 792 + break; 793 + case hwmon_fan_target: 794 + /* 795 + * Use the datasheet equation: 796 + * FanSpeed = KSCALE x fCLK / [256 x (KTACH + 1)] 797 + * then multiply by 60 to give rpm. 798 + */ 799 + *val = 60 * DIV_FROM_REG(data->config) * clock / 800 + (256 * (data->speed + 1)); 801 + break; 802 + case hwmon_fan_min_alarm: 803 + *val = !!(data->alarm & MAX6650_ALRM_MIN); 804 + data->alarm &= ~MAX6650_ALRM_MIN; 805 + data->valid = false; 806 + break; 807 + case hwmon_fan_max_alarm: 808 + *val = !!(data->alarm & MAX6650_ALRM_MAX); 809 + data->alarm &= ~MAX6650_ALRM_MAX; 810 + data->valid = false; 811 + break; 812 + case hwmon_fan_fault: 813 + *val = !!(data->alarm & MAX6650_ALRM_TACH); 814 + data->alarm &= ~MAX6650_ALRM_TACH; 815 + data->valid = false; 816 + break; 817 + default: 818 + return -EOPNOTSUPP; 819 + } 820 + break; 821 + default: 822 + return -EOPNOTSUPP; 823 + } 824 + return 0; 825 + } 826 + 827 + static const u8 max6650_pwm_modes[] = { 828 + MAX6650_CFG_MODE_ON, 829 + MAX6650_CFG_MODE_OPEN_LOOP, 830 + MAX6650_CFG_MODE_CLOSED_LOOP, 831 + MAX6650_CFG_MODE_OFF, 832 + }; 833 + 834 + static int max6650_write(struct device *dev, enum hwmon_sensor_types type, 835 + u32 attr, int channel, long val) 836 + { 837 + struct max6650_data *data = dev_get_drvdata(dev); 838 + int ret = 0; 839 + u8 reg; 840 + 841 + mutex_lock(&data->update_lock); 842 + 843 + switch (type) { 844 + case hwmon_pwm: 845 + switch (attr) { 846 + case hwmon_pwm_input: 847 + reg = pwm_to_dac(clamp_val(val, 0, 255), 848 + data->config & MAX6650_CFG_V12); 849 + ret = i2c_smbus_write_byte_data(data->client, 850 + MAX6650_REG_DAC, reg); 851 + if (ret) 852 + break; 853 + data->dac = reg; 854 + break; 855 + case hwmon_pwm_enable: 856 + if (val < 0 || val >= ARRAY_SIZE(max6650_pwm_modes)) { 857 + ret = -EINVAL; 858 + break; 859 + } 860 + ret = max6650_set_operating_mode(data, 861 + max6650_pwm_modes[val]); 862 + break; 863 + default: 864 + ret = -EOPNOTSUPP; 865 + break; 866 + } 867 + break; 868 + case hwmon_fan: 869 + switch (attr) { 870 + case hwmon_fan_div: 871 + switch (val) { 872 + case 1: 873 + reg = 0; 874 + break; 875 + case 2: 876 + reg = 1; 877 + break; 878 + case 4: 879 + reg = 2; 880 + break; 881 + case 8: 882 + reg = 3; 883 + break; 884 + default: 885 + ret = -EINVAL; 886 + goto error; 887 + } 888 + ret = i2c_smbus_write_byte_data(data->client, 889 + MAX6650_REG_COUNT, reg); 890 + if (ret) 891 + break; 892 + data->count = reg; 893 + break; 894 + case hwmon_fan_target: 895 + if (val < 0) { 896 + ret = -EINVAL; 897 + break; 898 + } 899 + ret = max6650_set_target(data, val); 900 + break; 901 + default: 902 + ret = -EOPNOTSUPP; 903 + break; 904 + } 905 + break; 906 + default: 907 + ret = -EOPNOTSUPP; 908 + break; 909 + } 910 + 911 + error: 912 + mutex_unlock(&data->update_lock); 913 + return ret; 914 + } 915 + 916 + static umode_t max6650_is_visible(const void *_data, 917 + enum hwmon_sensor_types type, u32 attr, 918 + int channel) 919 + { 920 + const struct max6650_data *data = _data; 921 + 922 + if (channel && (channel >= data->nr_fans || type != hwmon_fan)) 923 + return 0; 924 + 925 + switch (type) { 926 + case hwmon_fan: 927 + switch (attr) { 928 + case hwmon_fan_input: 929 + return 0444; 930 + case hwmon_fan_target: 931 + case hwmon_fan_div: 932 + return 0644; 933 + case hwmon_fan_min_alarm: 934 + if (data->alarm_en & MAX6650_ALRM_MIN) 935 + return 0444; 936 + break; 937 + case hwmon_fan_max_alarm: 938 + if (data->alarm_en & MAX6650_ALRM_MAX) 939 + return 0444; 940 + break; 941 + case hwmon_fan_fault: 942 + if (data->alarm_en & MAX6650_ALRM_TACH) 943 + return 0444; 944 + break; 945 + default: 946 + break; 947 + } 948 + break; 949 + case hwmon_pwm: 950 + switch (attr) { 951 + case hwmon_pwm_input: 952 + case hwmon_pwm_enable: 953 + return 0644; 954 + default: 955 + break; 956 + } 957 + break; 958 + default: 959 + break; 960 + } 961 + return 0; 962 + } 963 + 964 + static const struct hwmon_channel_info *max6650_info[] = { 965 + HWMON_CHANNEL_INFO(fan, HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_DIV | 966 + HWMON_F_MIN_ALARM | HWMON_F_MAX_ALARM | 967 + HWMON_F_FAULT, 968 + HWMON_F_INPUT, HWMON_F_INPUT, HWMON_F_INPUT), 969 + HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT | HWMON_PWM_ENABLE), 970 + NULL 971 + }; 972 + 973 + static const struct hwmon_ops max6650_hwmon_ops = { 974 + .read = max6650_read, 975 + .write = max6650_write, 976 + .is_visible = max6650_is_visible, 977 + }; 978 + 979 + static const struct hwmon_chip_info max6650_chip_info = { 980 + .ops = &max6650_hwmon_ops, 981 + .info = max6650_info, 982 + }; 519 983 520 984 static int max6650_probe(struct i2c_client *client, 521 985 const struct i2c_device_id *id) 522 986 { 987 + struct thermal_cooling_device *cooling_dev; 523 988 struct device *dev = &client->dev; 524 989 const struct of_device_id *of_id = 525 990 of_match_device(of_match_ptr(max6650_dt_match), dev); ··· 784 767 if (err) 785 768 return err; 786 769 787 - data->groups[0] = &max6650_group; 788 - /* 3 additional fan inputs for the MAX6651 */ 789 - if (data->nr_fans == 4) 790 - data->groups[1] = &max6651_group; 791 - 792 - hwmon_dev = devm_hwmon_device_register_with_groups(dev, 793 - client->name, data, 794 - data->groups); 770 + hwmon_dev = devm_hwmon_device_register_with_info(dev, 771 + client->name, data, 772 + &max6650_chip_info, 773 + max6650_groups); 795 774 err = PTR_ERR_OR_ZERO(hwmon_dev); 796 775 if (err) 797 776 return err; 798 777 799 - #if IS_ENABLED(CONFIG_THERMAL) 800 - data->cooling_dev = 801 - thermal_of_cooling_device_register(client->dev.of_node, 802 - client->name, data, 803 - &max6650_cooling_ops); 804 - if (IS_ERR(data->cooling_dev)) 805 - dev_warn(&client->dev, 806 - "thermal cooling device register failed: %ld\n", 807 - PTR_ERR(data->cooling_dev)); 808 - #endif 809 - return 0; 810 - } 811 - 812 - static int max6650_remove(struct i2c_client *client) 813 - { 814 - struct max6650_data *data = i2c_get_clientdata(client); 815 - 816 - if (!IS_ERR(data->cooling_dev)) 817 - thermal_cooling_device_unregister(data->cooling_dev); 778 + if (IS_ENABLED(CONFIG_THERMAL)) { 779 + cooling_dev = devm_thermal_of_cooling_device_register(dev, 780 + dev->of_node, client->name, 781 + data, &max6650_cooling_ops); 782 + if (IS_ERR(cooling_dev)) { 783 + dev_warn(dev, "thermal cooling device register failed: %ld\n", 784 + PTR_ERR(cooling_dev)); 785 + } 786 + } 818 787 819 788 return 0; 820 789 } ··· 818 815 .of_match_table = of_match_ptr(max6650_dt_match), 819 816 }, 820 817 .probe = max6650_probe, 821 - .remove = max6650_remove, 822 818 .id_table = max6650_id, 823 819 }; 824 820
+74 -7
drivers/hwmon/nct7904.c
··· 4 4 * 5 5 * Copyright (c) 2015 Kontron 6 6 * Author: Vadim V. Vlasov <vvlasov@dev.rtsoft.ru> 7 + * 8 + * Copyright (c) 2019 Advantech 9 + * Author: Amy.Shih <amy.shih@advantech.com.tw> 7 10 */ 8 11 9 12 #include <linux/module.h> ··· 53 50 #define T_CPU1_HV_REG 0xA0 /* Bank 0; 2 regs (HV/LV) per sensor */ 54 51 55 52 #define PRTS_REG 0x03 /* Bank 2 */ 53 + #define PFE_REG 0x00 /* Bank 2; PECI Function Enable */ 54 + #define TSI_CTRL_REG 0x50 /* Bank 2; TSI Control Register */ 56 55 #define FANCTL1_FMR_REG 0x00 /* Bank 3; 1 reg per channel */ 57 56 #define FANCTL1_OUT_REG 0x10 /* Bank 3; 1 reg per channel */ 58 57 ··· 70 65 u32 vsen_mask; 71 66 u32 tcpu_mask; 72 67 u8 fan_mode[FANCTL_MAX]; 68 + u8 enable_dts; 69 + u8 has_dts; 73 70 }; 74 71 75 72 /* Access functions */ ··· 236 229 237 230 switch (attr) { 238 231 case hwmon_temp_input: 239 - if (channel == 0) 232 + if (channel == 4) 240 233 ret = nct7904_read_reg16(data, BANK_0, LTD_HV_REG); 234 + else if (channel < 5) 235 + ret = nct7904_read_reg16(data, BANK_0, 236 + TEMP_CH1_HV_REG + channel * 4); 241 237 else 242 238 ret = nct7904_read_reg16(data, BANK_0, 243 - T_CPU1_HV_REG + (channel - 1) * 2); 239 + T_CPU1_HV_REG + (channel - 5) 240 + * 2); 244 241 if (ret < 0) 245 242 return ret; 246 243 temp = ((ret & 0xff00) >> 5) | (ret & 0x7); ··· 260 249 const struct nct7904_data *data = _data; 261 250 262 251 if (attr == hwmon_temp_input) { 263 - if (channel == 0) { 264 - if (data->vsen_mask & BIT(17)) 252 + if (channel < 5) { 253 + if (data->tcpu_mask & BIT(channel)) 265 254 return 0444; 266 255 } else { 267 - if (data->tcpu_mask & BIT(channel - 1)) 256 + if (data->has_dts & BIT(channel - 5)) 268 257 return 0444; 269 258 } 270 259 } ··· 471 460 struct device *dev = &client->dev; 472 461 int ret, i; 473 462 u32 mask; 463 + u8 val, bit; 474 464 475 465 data = devm_kzalloc(dev, sizeof(struct nct7904_data), GFP_KERNEL); 476 466 if (!data) ··· 505 493 data->vsen_mask = mask; 506 494 507 495 /* CPU_TEMP attributes */ 508 - ret = nct7904_read_reg16(data, BANK_0, DTS_T_CTRL0_REG); 496 + ret = nct7904_read_reg(data, BANK_0, VT_ADC_CTRL0_REG); 509 497 if (ret < 0) 510 498 return ret; 511 - data->tcpu_mask = ((ret >> 8) & 0xf) | ((ret & 0xf) << 4); 499 + 500 + if ((ret & 0x6) == 0x6) 501 + data->tcpu_mask |= 1; /* TR1 */ 502 + if ((ret & 0x18) == 0x18) 503 + data->tcpu_mask |= 2; /* TR2 */ 504 + if ((ret & 0x20) == 0x20) 505 + data->tcpu_mask |= 4; /* TR3 */ 506 + if ((ret & 0x80) == 0x80) 507 + data->tcpu_mask |= 8; /* TR4 */ 508 + 509 + /* LTD */ 510 + ret = nct7904_read_reg(data, BANK_0, VT_ADC_CTRL2_REG); 511 + if (ret < 0) 512 + return ret; 513 + if ((ret & 0x02) == 0x02) 514 + data->tcpu_mask |= 0x10; 515 + 516 + /* Multi-Function detecting for Volt and TR/TD */ 517 + ret = nct7904_read_reg(data, BANK_0, VT_ADC_MD_REG); 518 + if (ret < 0) 519 + return ret; 520 + 521 + for (i = 0; i < 4; i++) { 522 + val = (ret & (0x03 << i)) >> (i * 2); 523 + bit = (1 << i); 524 + if (val == 0) 525 + data->tcpu_mask &= ~bit; 526 + } 527 + 528 + /* PECI */ 529 + ret = nct7904_read_reg(data, BANK_2, PFE_REG); 530 + if (ret < 0) 531 + return ret; 532 + if (ret & 0x80) { 533 + data->enable_dts = 1; /* Enable DTS & PECI */ 534 + } else { 535 + ret = nct7904_read_reg(data, BANK_2, TSI_CTRL_REG); 536 + if (ret < 0) 537 + return ret; 538 + if (ret & 0x80) 539 + data->enable_dts = 0x3; /* Enable DTS & TSI */ 540 + } 541 + 542 + /* Check DTS enable status */ 543 + if (data->enable_dts) { 544 + ret = nct7904_read_reg(data, BANK_0, DTS_T_CTRL0_REG); 545 + if (ret < 0) 546 + return ret; 547 + data->has_dts = ret & 0xF; 548 + if (data->enable_dts & 0x2) { 549 + ret = nct7904_read_reg(data, BANK_0, DTS_T_CTRL1_REG); 550 + if (ret < 0) 551 + return ret; 552 + data->has_dts |= (ret & 0xF) << 4; 553 + } 554 + } 512 555 513 556 for (i = 0; i < FANCTL_MAX; i++) { 514 557 ret = nct7904_read_reg(data, BANK_3, FANCTL1_FMR_REG + i);
+6
drivers/hwmon/occ/common.c
··· 241 241 val = get_unaligned_be16(&temp->sensor_id); 242 242 break; 243 243 case 1: 244 + /* 245 + * If a sensor reading has expired and couldn't be refreshed, 246 + * OCC returns 0xFFFF for that sensor. 247 + */ 248 + if (temp->value == 0xFFFF) 249 + return -EREMOTEIO; 244 250 val = get_unaligned_be16(&temp->value) * 1000; 245 251 break; 246 252 default:
+18
drivers/hwmon/pmbus/Kconfig
··· 64 64 This driver can also be built as a module. If so, the module will 65 65 be called ir38064. 66 66 67 + config SENSORS_IRPS5401 68 + tristate "Infineon IRPS5401" 69 + help 70 + If you say yes here you get hardware monitoring support for the 71 + Infineon IRPS5401 controller. 72 + 73 + This driver can also be built as a module. If so, the module will 74 + be called irps5401. 75 + 67 76 config SENSORS_ISL68137 68 77 tristate "Intersil ISL68137" 69 78 help ··· 162 153 163 154 This driver can also be built as a module. If so, the module will 164 155 be called max8688. 156 + 157 + config SENSORS_PXE1610 158 + tristate "Infineon PXE1610" 159 + help 160 + If you say yes here you get hardware monitoring support for Infineon 161 + PXE1610. 162 + 163 + This driver can also be built as a module. If so, the module will 164 + be called pxe1610. 165 165 166 166 config SENSORS_TPS40422 167 167 tristate "TI TPS40422"
+2
drivers/hwmon/pmbus/Makefile
··· 9 9 obj-$(CONFIG_SENSORS_IBM_CFFPS) += ibm-cffps.o 10 10 obj-$(CONFIG_SENSORS_IR35221) += ir35221.o 11 11 obj-$(CONFIG_SENSORS_IR38064) += ir38064.o 12 + obj-$(CONFIG_SENSORS_IRPS5401) += irps5401.o 12 13 obj-$(CONFIG_SENSORS_ISL68137) += isl68137.o 13 14 obj-$(CONFIG_SENSORS_LM25066) += lm25066.o 14 15 obj-$(CONFIG_SENSORS_LTC2978) += ltc2978.o ··· 19 18 obj-$(CONFIG_SENSORS_MAX31785) += max31785.o 20 19 obj-$(CONFIG_SENSORS_MAX34440) += max34440.o 21 20 obj-$(CONFIG_SENSORS_MAX8688) += max8688.o 21 + obj-$(CONFIG_SENSORS_PXE1610) += pxe1610.o 22 22 obj-$(CONFIG_SENSORS_TPS40422) += tps40422.o 23 23 obj-$(CONFIG_SENSORS_TPS53679) += tps53679.o 24 24 obj-$(CONFIG_SENSORS_UCD9000) += ucd9000.o
+104 -1
drivers/hwmon/pmbus/adm1275.c
··· 14 14 #include <linux/slab.h> 15 15 #include <linux/i2c.h> 16 16 #include <linux/bitops.h> 17 + #include <linux/bitfield.h> 18 + #include <linux/log2.h> 17 19 #include "pmbus.h" 18 20 19 21 enum chips { adm1075, adm1272, adm1275, adm1276, adm1278, adm1293, adm1294 }; ··· 71 69 #define ADM1075_VAUX_OV_WARN BIT(7) 72 70 #define ADM1075_VAUX_UV_WARN BIT(6) 73 71 72 + #define ADM1275_VI_AVG_SHIFT 0 73 + #define ADM1275_VI_AVG_MASK GENMASK(ADM1275_VI_AVG_SHIFT + 2, \ 74 + ADM1275_VI_AVG_SHIFT) 75 + #define ADM1275_SAMPLES_AVG_MAX 128 76 + 77 + #define ADM1278_PWR_AVG_SHIFT 11 78 + #define ADM1278_PWR_AVG_MASK GENMASK(ADM1278_PWR_AVG_SHIFT + 2, \ 79 + ADM1278_PWR_AVG_SHIFT) 80 + #define ADM1278_VI_AVG_SHIFT 8 81 + #define ADM1278_VI_AVG_MASK GENMASK(ADM1278_VI_AVG_SHIFT + 2, \ 82 + ADM1278_VI_AVG_SHIFT) 83 + 74 84 struct adm1275_data { 75 85 int id; 76 86 bool have_oc_fault; ··· 94 80 bool have_pin_min; 95 81 bool have_pin_max; 96 82 bool have_temp_max; 83 + bool have_power_sampling; 97 84 struct pmbus_driver_info info; 98 85 }; 99 86 ··· 169 154 [17] = { 15316, 0, -3 }, /* power, 21V, irange100 */ 170 155 [18] = { 7658, 0, -3 }, /* power, 21V, irange200 */ 171 156 }; 157 + 158 + static int adm1275_read_pmon_config(const struct adm1275_data *data, 159 + struct i2c_client *client, bool is_power) 160 + { 161 + int shift, ret; 162 + u16 mask; 163 + 164 + /* 165 + * The PMON configuration register is a 16-bit register only on chips 166 + * supporting power average sampling. On other chips it is an 8-bit 167 + * register. 168 + */ 169 + if (data->have_power_sampling) { 170 + ret = i2c_smbus_read_word_data(client, ADM1275_PMON_CONFIG); 171 + mask = is_power ? ADM1278_PWR_AVG_MASK : ADM1278_VI_AVG_MASK; 172 + shift = is_power ? ADM1278_PWR_AVG_SHIFT : ADM1278_VI_AVG_SHIFT; 173 + } else { 174 + ret = i2c_smbus_read_byte_data(client, ADM1275_PMON_CONFIG); 175 + mask = ADM1275_VI_AVG_MASK; 176 + shift = ADM1275_VI_AVG_SHIFT; 177 + } 178 + if (ret < 0) 179 + return ret; 180 + 181 + return (ret & mask) >> shift; 182 + } 183 + 184 + static int adm1275_write_pmon_config(const struct adm1275_data *data, 185 + struct i2c_client *client, 186 + bool is_power, u16 word) 187 + { 188 + int shift, ret; 189 + u16 mask; 190 + 191 + if (data->have_power_sampling) { 192 + ret = i2c_smbus_read_word_data(client, ADM1275_PMON_CONFIG); 193 + mask = is_power ? ADM1278_PWR_AVG_MASK : ADM1278_VI_AVG_MASK; 194 + shift = is_power ? ADM1278_PWR_AVG_SHIFT : ADM1278_VI_AVG_SHIFT; 195 + } else { 196 + ret = i2c_smbus_read_byte_data(client, ADM1275_PMON_CONFIG); 197 + mask = ADM1275_VI_AVG_MASK; 198 + shift = ADM1275_VI_AVG_SHIFT; 199 + } 200 + if (ret < 0) 201 + return ret; 202 + 203 + word = (ret & ~mask) | ((word << shift) & mask); 204 + if (data->have_power_sampling) 205 + ret = i2c_smbus_write_word_data(client, ADM1275_PMON_CONFIG, 206 + word); 207 + else 208 + ret = i2c_smbus_write_byte_data(client, ADM1275_PMON_CONFIG, 209 + word); 210 + 211 + return ret; 212 + } 172 213 173 214 static int adm1275_read_word_data(struct i2c_client *client, int page, int reg) 174 215 { ··· 304 233 if (!data->have_temp_max) 305 234 return -ENXIO; 306 235 break; 236 + case PMBUS_VIRT_POWER_SAMPLES: 237 + if (!data->have_power_sampling) 238 + return -ENXIO; 239 + ret = adm1275_read_pmon_config(data, client, true); 240 + if (ret < 0) 241 + break; 242 + ret = BIT(ret); 243 + break; 244 + case PMBUS_VIRT_IN_SAMPLES: 245 + case PMBUS_VIRT_CURR_SAMPLES: 246 + ret = adm1275_read_pmon_config(data, client, false); 247 + if (ret < 0) 248 + break; 249 + ret = BIT(ret); 250 + break; 307 251 default: 308 252 ret = -ENODATA; 309 253 break; ··· 362 276 break; 363 277 case PMBUS_VIRT_RESET_TEMP_HISTORY: 364 278 ret = pmbus_write_word_data(client, 0, ADM1278_PEAK_TEMP, 0); 279 + break; 280 + case PMBUS_VIRT_POWER_SAMPLES: 281 + if (!data->have_power_sampling) 282 + return -ENXIO; 283 + word = clamp_val(word, 1, ADM1275_SAMPLES_AVG_MAX); 284 + ret = adm1275_write_pmon_config(data, client, true, 285 + ilog2(word)); 286 + break; 287 + case PMBUS_VIRT_IN_SAMPLES: 288 + case PMBUS_VIRT_CURR_SAMPLES: 289 + word = clamp_val(word, 1, ADM1275_SAMPLES_AVG_MAX); 290 + ret = adm1275_write_pmon_config(data, client, false, 291 + ilog2(word)); 365 292 break; 366 293 default: 367 294 ret = -ENODATA; ··· 529 430 info->format[PSC_CURRENT_OUT] = direct; 530 431 info->format[PSC_POWER] = direct; 531 432 info->format[PSC_TEMPERATURE] = direct; 532 - info->func[0] = PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT; 433 + info->func[0] = PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | 434 + PMBUS_HAVE_SAMPLES; 533 435 534 436 info->read_word_data = adm1275_read_word_data; 535 437 info->read_byte_data = adm1275_read_byte_data; ··· 571 471 data->have_vout = true; 572 472 data->have_pin_max = true; 573 473 data->have_temp_max = true; 474 + data->have_power_sampling = true; 574 475 575 476 coefficients = adm1272_coefficients; 576 477 vindex = (config & ADM1275_VRANGE) ? 1 : 0; ··· 657 556 data->have_vout = true; 658 557 data->have_pin_max = true; 659 558 data->have_temp_max = true; 559 + data->have_power_sampling = true; 660 560 661 561 coefficients = adm1278_coefficients; 662 562 vindex = 0; ··· 693 591 data->have_pin_min = true; 694 592 data->have_pin_max = true; 695 593 data->have_mfr_vaux_status = true; 594 + data->have_power_sampling = true; 696 595 697 596 coefficients = adm1293_coefficients; 698 597
+67
drivers/hwmon/pmbus/irps5401.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * Hardware monitoring driver for the Infineon IRPS5401M PMIC. 4 + * 5 + * Copyright (c) 2019 SED Systems, a division of Calian Ltd. 6 + * 7 + * The device supports VOUT_PEAK, IOUT_PEAK, and TEMPERATURE_PEAK, however 8 + * this driver does not currently support them. 9 + */ 10 + 11 + #include <linux/err.h> 12 + #include <linux/i2c.h> 13 + #include <linux/init.h> 14 + #include <linux/kernel.h> 15 + #include <linux/module.h> 16 + #include "pmbus.h" 17 + 18 + #define IRPS5401_SW_FUNC (PMBUS_HAVE_VIN | PMBUS_HAVE_IIN | \ 19 + PMBUS_HAVE_STATUS_INPUT | \ 20 + PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | \ 21 + PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | \ 22 + PMBUS_HAVE_PIN | PMBUS_HAVE_POUT | \ 23 + PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP) 24 + 25 + #define IRPS5401_LDO_FUNC (PMBUS_HAVE_VIN | \ 26 + PMBUS_HAVE_STATUS_INPUT | \ 27 + PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | \ 28 + PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | \ 29 + PMBUS_HAVE_PIN | PMBUS_HAVE_POUT | \ 30 + PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP) 31 + 32 + static struct pmbus_driver_info irps5401_info = { 33 + .pages = 5, 34 + .func[0] = IRPS5401_SW_FUNC, 35 + .func[1] = IRPS5401_SW_FUNC, 36 + .func[2] = IRPS5401_SW_FUNC, 37 + .func[3] = IRPS5401_SW_FUNC, 38 + .func[4] = IRPS5401_LDO_FUNC, 39 + }; 40 + 41 + static int irps5401_probe(struct i2c_client *client, 42 + const struct i2c_device_id *id) 43 + { 44 + return pmbus_do_probe(client, id, &irps5401_info); 45 + } 46 + 47 + static const struct i2c_device_id irps5401_id[] = { 48 + {"irps5401", 0}, 49 + {} 50 + }; 51 + 52 + MODULE_DEVICE_TABLE(i2c, irps5401_id); 53 + 54 + static struct i2c_driver irps5401_driver = { 55 + .driver = { 56 + .name = "irps5401", 57 + }, 58 + .probe = irps5401_probe, 59 + .remove = pmbus_do_remove, 60 + .id_table = irps5401_id, 61 + }; 62 + 63 + module_i2c_driver(irps5401_driver); 64 + 65 + MODULE_AUTHOR("Robert Hancock"); 66 + MODULE_DESCRIPTION("PMBus driver for Infineon IRPS5401"); 67 + MODULE_LICENSE("GPL");
+139
drivers/hwmon/pmbus/pxe1610.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * Hardware monitoring driver for Infineon PXE1610 4 + * 5 + * Copyright (c) 2019 Facebook Inc 6 + * 7 + */ 8 + 9 + #include <linux/err.h> 10 + #include <linux/i2c.h> 11 + #include <linux/init.h> 12 + #include <linux/kernel.h> 13 + #include <linux/module.h> 14 + #include "pmbus.h" 15 + 16 + #define PXE1610_NUM_PAGES 3 17 + 18 + /* Identify chip parameters. */ 19 + static int pxe1610_identify(struct i2c_client *client, 20 + struct pmbus_driver_info *info) 21 + { 22 + if (pmbus_check_byte_register(client, 0, PMBUS_VOUT_MODE)) { 23 + u8 vout_mode; 24 + int ret; 25 + 26 + /* Read the register with VOUT scaling value.*/ 27 + ret = pmbus_read_byte_data(client, 0, PMBUS_VOUT_MODE); 28 + if (ret < 0) 29 + return ret; 30 + 31 + vout_mode = ret & GENMASK(4, 0); 32 + 33 + switch (vout_mode) { 34 + case 1: 35 + info->vrm_version = vr12; 36 + break; 37 + case 2: 38 + info->vrm_version = vr13; 39 + break; 40 + default: 41 + return -ENODEV; 42 + } 43 + } 44 + 45 + return 0; 46 + } 47 + 48 + static struct pmbus_driver_info pxe1610_info = { 49 + .pages = PXE1610_NUM_PAGES, 50 + .format[PSC_VOLTAGE_IN] = linear, 51 + .format[PSC_VOLTAGE_OUT] = vid, 52 + .format[PSC_CURRENT_IN] = linear, 53 + .format[PSC_CURRENT_OUT] = linear, 54 + .format[PSC_TEMPERATURE] = linear, 55 + .format[PSC_POWER] = linear, 56 + .func[0] = PMBUS_HAVE_VIN 57 + | PMBUS_HAVE_VOUT | PMBUS_HAVE_IIN 58 + | PMBUS_HAVE_IOUT | PMBUS_HAVE_PIN 59 + | PMBUS_HAVE_POUT | PMBUS_HAVE_TEMP 60 + | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_IOUT 61 + | PMBUS_HAVE_STATUS_INPUT | PMBUS_HAVE_STATUS_TEMP, 62 + .func[1] = PMBUS_HAVE_VIN 63 + | PMBUS_HAVE_VOUT | PMBUS_HAVE_IIN 64 + | PMBUS_HAVE_IOUT | PMBUS_HAVE_PIN 65 + | PMBUS_HAVE_POUT | PMBUS_HAVE_TEMP 66 + | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_IOUT 67 + | PMBUS_HAVE_STATUS_INPUT | PMBUS_HAVE_STATUS_TEMP, 68 + .func[2] = PMBUS_HAVE_VIN 69 + | PMBUS_HAVE_VOUT | PMBUS_HAVE_IIN 70 + | PMBUS_HAVE_IOUT | PMBUS_HAVE_PIN 71 + | PMBUS_HAVE_POUT | PMBUS_HAVE_TEMP 72 + | PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_IOUT 73 + | PMBUS_HAVE_STATUS_INPUT | PMBUS_HAVE_STATUS_TEMP, 74 + .identify = pxe1610_identify, 75 + }; 76 + 77 + static int pxe1610_probe(struct i2c_client *client, 78 + const struct i2c_device_id *id) 79 + { 80 + struct pmbus_driver_info *info; 81 + u8 buf[I2C_SMBUS_BLOCK_MAX]; 82 + int ret; 83 + 84 + if (!i2c_check_functionality( 85 + client->adapter, 86 + I2C_FUNC_SMBUS_READ_BYTE_DATA 87 + | I2C_FUNC_SMBUS_READ_WORD_DATA 88 + | I2C_FUNC_SMBUS_READ_BLOCK_DATA)) 89 + return -ENODEV; 90 + 91 + /* 92 + * By default this device doesn't boot to page 0, so set page 0 93 + * to access all pmbus registers. 94 + */ 95 + i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0); 96 + 97 + /* Read Manufacturer id */ 98 + ret = i2c_smbus_read_block_data(client, PMBUS_MFR_ID, buf); 99 + if (ret < 0) { 100 + dev_err(&client->dev, "Failed to read PMBUS_MFR_ID\n"); 101 + return ret; 102 + } 103 + if (ret != 2 || strncmp(buf, "XP", 2)) { 104 + dev_err(&client->dev, "MFR_ID unrecognized\n"); 105 + return -ENODEV; 106 + } 107 + 108 + info = devm_kmemdup(&client->dev, &pxe1610_info, 109 + sizeof(struct pmbus_driver_info), 110 + GFP_KERNEL); 111 + if (!info) 112 + return -ENOMEM; 113 + 114 + return pmbus_do_probe(client, id, info); 115 + } 116 + 117 + static const struct i2c_device_id pxe1610_id[] = { 118 + {"pxe1610", 0}, 119 + {"pxe1110", 0}, 120 + {"pxm1310", 0}, 121 + {} 122 + }; 123 + 124 + MODULE_DEVICE_TABLE(i2c, pxe1610_id); 125 + 126 + static struct i2c_driver pxe1610_driver = { 127 + .driver = { 128 + .name = "pxe1610", 129 + }, 130 + .probe = pxe1610_probe, 131 + .remove = pmbus_do_remove, 132 + .id_table = pxe1610_id, 133 + }; 134 + 135 + module_i2c_driver(pxe1610_driver); 136 + 137 + MODULE_AUTHOR("Vijay Khemka <vijaykhemka@fb.com>"); 138 + MODULE_DESCRIPTION("PMBus driver for Infineon PXE1610, PXE1110 and PXM1310"); 139 + MODULE_LICENSE("GPL");
+7 -3
drivers/hwmon/pwm-fan.c
··· 320 320 dev_err(dev, "Failed to enable fan supply: %d\n", ret); 321 321 return ret; 322 322 } 323 - devm_add_action_or_reset(dev, pwm_fan_regulator_disable, 324 - ctx->reg_en); 323 + ret = devm_add_action_or_reset(dev, pwm_fan_regulator_disable, 324 + ctx->reg_en); 325 + if (ret) 326 + return ret; 325 327 } 326 328 327 329 ctx->pwm_value = MAX_PWM; ··· 339 337 return ret; 340 338 } 341 339 timer_setup(&ctx->rpm_timer, sample_timer, 0); 342 - devm_add_action_or_reset(dev, pwm_fan_pwm_disable, ctx); 340 + ret = devm_add_action_or_reset(dev, pwm_fan_pwm_disable, ctx); 341 + if (ret) 342 + return ret; 343 343 344 344 of_property_read_u32(dev->of_node, "pulses-per-revolution", &ppr); 345 345 ctx->pulses_per_revolution = ppr;
+1 -9
drivers/hwmon/scpi-hwmon.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 1 2 /* 2 3 * System Control and Power Interface(SCPI) based hwmon sensor driver 3 4 * 4 5 * Copyright (C) 2015 ARM Ltd. 5 6 * Punit Agrawal <punit.agrawal@arm.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 version 2 as 9 - * published by the Free Software Foundation. 10 - * 11 - * This program is distributed "as is" WITHOUT ANY WARRANTY of any 12 - * kind, whether express or implied; without even the implied warranty 13 - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 - * GNU General Public License for more details. 15 7 */ 16 8 17 9 #include <linux/hwmon.h>
+2
drivers/hwmon/smsc47m1.c
··· 351 351 tmp |= data->fan_div[2] << 4; 352 352 smsc47m1_write_value(data, SMSC47M2_REG_FANDIV3, tmp); 353 353 break; 354 + default: 355 + BUG(); 354 356 } 355 357 356 358 /* Preserve fan min */