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

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

Pull hwmon updates from Guenter Roeck:
"New drivers:
- Inspur Power System power supply driver
- Synaptics AS370 PVT sensor driver

Chip support:
- support SHTC3 in shtc1 driver
- support NCT6116 in nct6775 driver
- support AMD family 17h, model 70h CPUs in k10temp driver
- support PCT2075 in lm75 driver

Removed drivers:
- ads1015 driver (now supported in iio)

Other changes:
- Convert drivers to use devm_i2c_new_dummy_device
- Substantial structural improvements in lm75 driver adding support
for writing sample interval for supported chips
- Add support for PSU version 2 to ibm-cffps driver
- Add support for power attribute to iio_hwmon bridge
- Add support for additional fan, voltage and temperature attributes
to nct7904 driver
- Convert adt7475 driver to use hwmon_device_register_with_groups()
- Convert k8temp driver to use hwmon_device_register_with_info()
- Various other improvements and minor fixes"

* tag 'hwmon-for-v5.4' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: (48 commits)
hwmon: submitting-patches: Add note on comment style
hwmon: submitting-patches: Point to with_info API
hwmon: (nct7904) Fix incorrect SMI status register setting of LTD temperature and fan.
hwmon: (shtc1) add support for the SHTC3 sensor
hwmon: (shtc1) fix shtc1 and shtw1 id mask
hwmon: (lm75) Aproximate sample times to data-sheet values
hwmon: (w83793d) convert to use devm_i2c_new_dummy_device
hwmon: (w83792d) convert to use devm_i2c_new_dummy_device
hwmon: (w83791d) convert to use devm_i2c_new_dummy_device
hwmon: (as370-hwmon) fix devm_platform_ioremap_resource.cocci warnings
hwmon: (lm75) Add support for writing sampling period on PCT2075
hwmon: (lm75) Add support for writing conversion time for TMP112
hwmon: (lm75) Move updating the sample interval to its own function
hwmon: (lm75) Support configuring the sample time for various chips
hwmon: (nct7904) Fix incorrect temperature limitation register setting of LTD.
hwmon: (as370-hwmon) Add DT bindings for Synaptics AS370 PVT
hwmon: Add Synaptics AS370 PVT sensor driver
pmbus: (ibm-cffps) Add support for version 2 of the PSU
dt-bindings: hwmon: Document ibm,cffps2 compatible string
hwmon: (iio_hwmon) Enable power exporting from IIO
...

+1816 -1022
Documentation/devicetree/bindings/hwmon/ads1015.txt Documentation/devicetree/bindings/iio/adc/ads1015.txt
+11
Documentation/devicetree/bindings/hwmon/as370.txt
··· 1 + Bindings for Synaptics AS370 PVT sensors 2 + 3 + Required properties: 4 + - compatible : "syna,as370-hwmon" 5 + - reg : address and length of the register set. 6 + 7 + Example: 8 + hwmon@ea0810 { 9 + compatible = "syna,as370-hwmon"; 10 + reg = <0xea0810 0xc>; 11 + };
+5 -3
Documentation/devicetree/bindings/hwmon/ibm,cffps1.txt
··· 1 - Device-tree bindings for IBM Common Form Factor Power Supply Version 1 2 - ---------------------------------------------------------------------- 1 + Device-tree bindings for IBM Common Form Factor Power Supply Versions 1 and 2 2 + ----------------------------------------------------------------------------- 3 3 4 4 Required properties: 5 - - compatible = "ibm,cffps1"; 5 + - compatible : Must be one of the following: 6 + "ibm,cffps1" 7 + "ibm,cffps2" 6 8 - reg = < I2C bus address >; : Address of the power supply on the 7 9 I2C bus. 8 10
+1
Documentation/devicetree/bindings/hwmon/lm75.txt
··· 15 15 "maxim,max31725", 16 16 "maxim,max31726", 17 17 "maxim,mcp980x", 18 + "nxp,pct2075", 18 19 "st,stds75", 19 20 "st,stlm75", 20 21 "microchip,tcn75",
+2
Documentation/devicetree/bindings/trivial-devices.yaml
··· 104 104 - infineon,slb9645tt 105 105 # Infineon TLV493D-A1B6 I2C 3D Magnetic Sensor 106 106 - infineon,tlv493d-a1b6 107 + # Inspur Power System power supply unit version 1 108 + - inspur,ipsps1 107 109 # Intersil ISL29028 Ambient Light and Proximity Sensor 108 110 - isil,isl29028 109 111 # Intersil ISL29030 Ambient Light and Proximity Sensor
-90
Documentation/hwmon/ads1015.rst
··· 1 - Kernel driver ads1015 2 - ===================== 3 - 4 - Supported chips: 5 - 6 - * Texas Instruments ADS1015 7 - 8 - Prefix: 'ads1015' 9 - 10 - Datasheet: Publicly available at the Texas Instruments website: 11 - 12 - http://focus.ti.com/lit/ds/symlink/ads1015.pdf 13 - 14 - * Texas Instruments ADS1115 15 - 16 - Prefix: 'ads1115' 17 - 18 - Datasheet: Publicly available at the Texas Instruments website: 19 - 20 - http://focus.ti.com/lit/ds/symlink/ads1115.pdf 21 - 22 - Authors: 23 - Dirk Eibach, Guntermann & Drunck GmbH <eibach@gdsys.de> 24 - 25 - Description 26 - ----------- 27 - 28 - This driver implements support for the Texas Instruments ADS1015/ADS1115. 29 - 30 - This device is a 12/16-bit A-D converter with 4 inputs. 31 - 32 - The inputs can be used single ended or in certain differential combinations. 33 - 34 - The inputs can be made available by 8 sysfs input files in0_input - in7_input: 35 - 36 - - in0: Voltage over AIN0 and AIN1. 37 - - in1: Voltage over AIN0 and AIN3. 38 - - in2: Voltage over AIN1 and AIN3. 39 - - in3: Voltage over AIN2 and AIN3. 40 - - in4: Voltage over AIN0 and GND. 41 - - in5: Voltage over AIN1 and GND. 42 - - in6: Voltage over AIN2 and GND. 43 - - in7: Voltage over AIN3 and GND. 44 - 45 - Which inputs are available can be configured using platform data or devicetree. 46 - 47 - By default all inputs are exported. 48 - 49 - Platform Data 50 - ------------- 51 - 52 - In linux/platform_data/ads1015.h platform data is defined, channel_data contains 53 - configuration data for the used input combinations: 54 - 55 - - pga is the programmable gain amplifier (values are full scale) 56 - 57 - - 0: +/- 6.144 V 58 - - 1: +/- 4.096 V 59 - - 2: +/- 2.048 V 60 - - 3: +/- 1.024 V 61 - - 4: +/- 0.512 V 62 - - 5: +/- 0.256 V 63 - 64 - - data_rate in samples per second 65 - 66 - - 0: 128 67 - - 1: 250 68 - - 2: 490 69 - - 3: 920 70 - - 4: 1600 71 - - 5: 2400 72 - - 6: 3300 73 - 74 - Example:: 75 - 76 - struct ads1015_platform_data data = { 77 - .channel_data = { 78 - [2] = { .enabled = true, .pga = 1, .data_rate = 0 }, 79 - [4] = { .enabled = true, .pga = 4, .data_rate = 5 }, 80 - } 81 - }; 82 - 83 - In this case only in2_input (FS +/- 4.096 V, 128 SPS) and in4_input 84 - (FS +/- 0.512 V, 2400 SPS) would be created. 85 - 86 - Devicetree 87 - ---------- 88 - 89 - Configuration is also possible via devicetree: 90 - Documentation/devicetree/bindings/hwmon/ads1015.txt
+1 -1
Documentation/hwmon/index.rst
··· 30 30 adm1031 31 31 adm1275 32 32 adm9240 33 - ads1015 34 33 ads7828 35 34 adt7410 36 35 adt7411 ··· 129 130 pcf8591 130 131 pmbus 131 132 powr1220 133 + pxe1610 132 134 pwm-fan 133 135 raspberrypi-hwmon 134 136 sch5627
+79
Documentation/hwmon/inspur-ipsps1.rst
··· 1 + Kernel driver inspur-ipsps1 2 + ======================= 3 + 4 + Supported chips: 5 + 6 + * Inspur Power System power supply unit 7 + 8 + Author: John Wang <wangzqbj@inspur.com> 9 + 10 + Description 11 + ----------- 12 + 13 + This driver supports Inspur Power System power supplies. This driver 14 + is a client to the core PMBus driver. 15 + 16 + Usage Notes 17 + ----------- 18 + 19 + This driver does not auto-detect devices. You will have to instantiate the 20 + devices explicitly. Please see Documentation/i2c/instantiating-devices for 21 + details. 22 + 23 + Sysfs entries 24 + ------------- 25 + 26 + The following attributes are supported: 27 + 28 + ======================= ====================================================== 29 + curr1_input Measured input current 30 + curr1_label "iin" 31 + curr1_max Maximum current 32 + curr1_max_alarm Current high alarm 33 + curr2_input Measured output current in mA. 34 + curr2_label "iout1" 35 + curr2_crit Critical maximum current 36 + curr2_crit_alarm Current critical high alarm 37 + curr2_max Maximum current 38 + curr2_max_alarm Current high alarm 39 + 40 + fan1_alarm Fan 1 warning. 41 + fan1_fault Fan 1 fault. 42 + fan1_input Fan 1 speed in RPM. 43 + 44 + in1_alarm Input voltage under-voltage alarm. 45 + in1_input Measured input voltage in mV. 46 + in1_label "vin" 47 + in2_input Measured output voltage in mV. 48 + in2_label "vout1" 49 + in2_lcrit Critical minimum output voltage 50 + in2_lcrit_alarm Output voltage critical low alarm 51 + in2_max Maximum output voltage 52 + in2_max_alarm Output voltage high alarm 53 + in2_min Minimum output voltage 54 + in2_min_alarm Output voltage low alarm 55 + 56 + power1_alarm Input fault or alarm. 57 + power1_input Measured input power in uW. 58 + power1_label "pin" 59 + power1_max Input power limit 60 + power2_max_alarm Output power high alarm 61 + power2_max Output power limit 62 + power2_input Measured output power in uW. 63 + power2_label "pout" 64 + 65 + temp[1-3]_input Measured temperature 66 + temp[1-2]_max Maximum temperature 67 + temp[1-3]_max_alarm Temperature high alarm 68 + 69 + vendor Manufacturer name 70 + model Product model 71 + part_number Product part number 72 + serial_number Product serial number 73 + fw_version Firmware version 74 + hw_version Hardware version 75 + mode Work mode. Can be set to active or 76 + standby, when set to standby, PSU will 77 + automatically switch between standby 78 + and redundancy mode. 79 + ======================= ======================================================
+4 -2
Documentation/hwmon/lm75.rst
··· 119 119 120 120 http://www.ti.com/product/tmp275 121 121 122 - * NXP LM75B 122 + * NXP LM75B, PCT2075 123 123 124 - Prefix: 'lm75b' 124 + Prefix: 'lm75b', 'pct2075' 125 125 126 126 Addresses scanned: none 127 127 128 128 Datasheet: Publicly available at the NXP website 129 129 130 130 http://www.nxp.com/documents/data_sheet/LM75B.pdf 131 + 132 + http://www.nxp.com/docs/en/data-sheet/PCT2075.pdf 131 133 132 134 Author: Frodo Looijaard <frodol@dds.nl> 133 135
+25 -8
Documentation/hwmon/pxe1610 Documentation/hwmon/pxe1610.rst
··· 2 2 ===================== 3 3 4 4 Supported chips: 5 + 5 6 * Infineon PXE1610 7 + 6 8 Prefix: 'pxe1610' 9 + 7 10 Addresses scanned: - 11 + 8 12 Datasheet: Datasheet is not publicly available. 9 13 10 14 * Infineon PXE1110 15 + 11 16 Prefix: 'pxe1110' 17 + 12 18 Addresses scanned: - 19 + 13 20 Datasheet: Datasheet is not publicly available. 14 21 15 22 * Infineon PXM1310 23 + 16 24 Prefix: 'pxm1310' 25 + 17 26 Addresses scanned: - 27 + 18 28 Datasheet: Datasheet is not publicly available. 19 29 20 30 Author: Vijay Khemka <vijaykhemka@fb.com> ··· 35 25 36 26 PXE1610/PXE1110 are Multi-rail/Multiphase Digital Controllers 37 27 and compliant to 38 - -- Intel VR13 DC-DC converter specifications. 39 - -- Intel SVID protocol. 28 + 29 + - Intel VR13 DC-DC converter specifications. 30 + - Intel SVID protocol. 31 + 40 32 Used for Vcore power regulation for Intel VR13 based microprocessors 41 - -- Servers, Workstations, and High-end desktops 33 + 34 + - Servers, Workstations, and High-end desktops 42 35 43 36 PXM1310 is a Multi-rail Controller and it is compliant to 44 - -- Intel VR13 DC-DC converter specifications. 45 - -- Intel SVID protocol. 37 + 38 + - Intel VR13 DC-DC converter specifications. 39 + - Intel SVID protocol. 40 + 46 41 Used for DDR3/DDR4 Memory power regulation for Intel VR13 and 47 42 IMVP8 based systems 48 43 ··· 59 44 to instantiate devices explicitly. 60 45 61 46 Example: the following commands will load the driver for an PXE1610 62 - at address 0x70 on I2C bus #4: 47 + at address 0x70 on I2C bus #4:: 63 48 64 - # modprobe pxe1610 65 - # echo pxe1610 0x70 > /sys/bus/i2c/devices/i2c-4/new_device 49 + # modprobe pxe1610 50 + # echo pxe1610 0x70 > /sys/bus/i2c/devices/i2c-4/new_device 66 51 67 52 It can also be instantiated by declaring in device tree 68 53 ··· 70 55 Sysfs attributes 71 56 ---------------- 72 57 58 + ====================== ==================================== 73 59 curr1_label "iin" 74 60 curr1_input Measured input current 75 61 curr1_alarm Current high alarm ··· 104 88 temp[1-3]_crit_alarm Chip temperature critical high alarm 105 89 temp[1-3]_max Maximum temperature 106 90 temp[1-3]_max_alarm Chip temperature high alarm 91 + ====================== ====================================
+14 -5
Documentation/hwmon/shtc1.rst
··· 19 19 20 20 Addresses scanned: none 21 21 22 - Datasheet: Not publicly available 22 + Datasheet: http://www.sensirion.com/file/datasheet_shtw1 23 + 24 + 25 + 26 + * Sensirion SHTC3 27 + 28 + Prefix: 'shtc3' 29 + 30 + Addresses scanned: none 31 + 32 + Datasheet: http://www.sensirion.com/file/datasheet_shtc3 23 33 24 34 25 35 ··· 40 30 Description 41 31 ----------- 42 32 43 - This driver implements support for the Sensirion SHTC1 chip, a humidity and 44 - temperature sensor. Temperature is measured in degrees celsius, relative 45 - humidity is expressed as a percentage. Driver can be used as well for SHTW1 46 - chip, which has the same electrical interface. 33 + This driver implements support for the Sensirion SHTC1, SHTW1, and SHTC3 34 + chips, a humidity and temperature sensor. Temperature is measured in degrees 35 + celsius, relative humidity is expressed as a percentage. 47 36 48 37 The device communicates with the I2C protocol. All sensors are set to I2C 49 38 address 0x70. See Documentation/i2c/instantiating-devices for methods to
+6 -2
Documentation/hwmon/submitting-patches.rst
··· 20 20 errors, no warnings, and few if any check messages. If there are any 21 21 messages, please be prepared to explain. 22 22 23 + * Please use the standard multi-line comment style. Do not mix C and C++ 24 + style comments in a single driver (with the exception of the SPDX license 25 + identifier). 26 + 23 27 * If your patch generates checkpatch errors, warnings, or check messages, 24 28 please refrain from explanations such as "I prefer that coding style". 25 29 Keep in mind that each unnecessary message helps hiding a real problem, ··· 124 120 completely initialize your chip and your driver first, then register with 125 121 the hwmon subsystem. 126 122 127 - * Use devm_hwmon_device_register_with_groups() or, if your driver needs a remove 128 - function, hwmon_device_register_with_groups() to register your driver with the 123 + * Use devm_hwmon_device_register_with_info() or, if your driver needs a remove 124 + function, hwmon_device_register_with_info() to register your driver with the 129 125 hwmon subsystem. Try using devm_add_action() instead of a remove function if 130 126 possible. Do not use hwmon_device_register(). 131 127
-8
MAINTAINERS
··· 517 517 S: Supported 518 518 F: drivers/video/backlight/adp8860_bl.c 519 519 520 - ADS1015 HARDWARE MONITOR DRIVER 521 - M: Dirk Eibach <eibach@gdsys.de> 522 - L: linux-hwmon@vger.kernel.org 523 - S: Maintained 524 - F: Documentation/hwmon/ads1015.rst 525 - F: drivers/hwmon/ads1015.c 526 - F: include/linux/platform_data/ads1015.h 527 - 528 520 ADT746X FAN DRIVER 529 521 M: Colin Leroy <colin@colino.net> 530 522 S: Maintained
+3
arch/x86/kernel/amd_nb.c
··· 21 21 #define PCI_DEVICE_ID_AMD_17H_DF_F4 0x1464 22 22 #define PCI_DEVICE_ID_AMD_17H_M10H_DF_F4 0x15ec 23 23 #define PCI_DEVICE_ID_AMD_17H_M30H_DF_F4 0x1494 24 + #define PCI_DEVICE_ID_AMD_17H_M70H_DF_F4 0x1444 24 25 25 26 /* Protect the PCI config register pairs used for SMN and DF indirect access. */ 26 27 static DEFINE_MUTEX(smn_mutex); ··· 51 50 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_M10H_DF_F3) }, 52 51 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_M30H_DF_F3) }, 53 52 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CNB17H_F3) }, 53 + { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_M70H_DF_F3) }, 54 54 {} 55 55 }; 56 56 EXPORT_SYMBOL_GPL(amd_nb_misc_ids); ··· 65 63 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_DF_F4) }, 66 64 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_M10H_DF_F4) }, 67 65 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_M30H_DF_F4) }, 66 + { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_M70H_DF_F4) }, 68 67 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CNB17H_F4) }, 69 68 {} 70 69 };
+13 -18
drivers/hwmon/Kconfig
··· 246 246 This driver can also be built as a module. If so, the module 247 247 will be called adt7475. 248 248 249 + config SENSORS_AS370 250 + tristate "Synaptics AS370 SoC hardware monitoring driver" 251 + help 252 + If you say yes here you get support for the PVT sensors of 253 + the Synaptics AS370 SoC 254 + 255 + This driver can also be built as a module. If so, the module 256 + will be called as370-hwmon. 257 + 258 + 249 259 config SENSORS_ASC7621 250 260 tristate "Andigilog aSC7621" 251 261 depends on I2C ··· 1392 1382 tristate "Sensiron humidity and temperature sensors. SHTC1 and compat." 1393 1383 depends on I2C 1394 1384 help 1395 - If you say yes here you get support for the Sensiron SHTC1 and SHTW1 1396 - humidity and temperature sensors. 1385 + If you say yes here you get support for the Sensiron SHTC1, SHTW1, 1386 + and SHTC3 humidity and temperature sensors. 1397 1387 1398 1388 This driver can also be built as a module. If so, the module 1399 1389 will be called shtc1. ··· 1579 1569 1580 1570 This driver can also be built as a module. If so, the module 1581 1571 will be called adc128d818. 1582 - 1583 - config SENSORS_ADS1015 1584 - tristate "Texas Instruments ADS1015" 1585 - depends on I2C 1586 - help 1587 - If you say yes here you get support for Texas Instruments 1588 - ADS1015/ADS1115 12/16-bit 4-input ADC device. 1589 - 1590 - This driver can also be built as a module. If so, the module 1591 - will be called ads1015. 1592 1572 1593 1573 config SENSORS_ADS7828 1594 1574 tristate "Texas Instruments ADS7828 and compatibles" ··· 1834 1834 will be called w83795. 1835 1835 1836 1836 config SENSORS_W83795_FANCTRL 1837 - bool "Include automatic fan control support (DANGEROUS)" 1837 + bool "Include automatic fan control support" 1838 1838 depends on SENSORS_W83795 1839 1839 help 1840 1840 If you say yes here, support for automatic fan speed control 1841 1841 will be included in the driver. 1842 - 1843 - This part of the code wasn't carefully reviewed and tested yet, 1844 - so enabling this option is strongly discouraged on production 1845 - servers. Only developers and testers should enable it for the 1846 - time being. 1847 1842 1848 1843 Please also note that this option will create sysfs attribute 1849 1844 files which may change in the future, so you shouldn't rely
+1 -1
drivers/hwmon/Makefile
··· 35 35 obj-$(CONFIG_SENSORS_ADM1029) += adm1029.o 36 36 obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o 37 37 obj-$(CONFIG_SENSORS_ADM9240) += adm9240.o 38 - obj-$(CONFIG_SENSORS_ADS1015) += ads1015.o 39 38 obj-$(CONFIG_SENSORS_ADS7828) += ads7828.o 40 39 obj-$(CONFIG_SENSORS_ADS7871) += ads7871.o 41 40 obj-$(CONFIG_SENSORS_ADT7X10) += adt7x10.o ··· 47 48 obj-$(CONFIG_SENSORS_APPLESMC) += applesmc.o 48 49 obj-$(CONFIG_SENSORS_ARM_SCMI) += scmi-hwmon.o 49 50 obj-$(CONFIG_SENSORS_ARM_SCPI) += scpi-hwmon.o 51 + obj-$(CONFIG_SENSORS_AS370) += as370-hwmon.o 50 52 obj-$(CONFIG_SENSORS_ASC7621) += asc7621.o 51 53 obj-$(CONFIG_SENSORS_ASPEED) += aspeed-pwm-tacho.o 52 54 obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o
+2 -2
drivers/hwmon/acpi_power_meter.c
··· 681 681 682 682 if (resource->caps.flags & POWER_METER_CAN_CAP) { 683 683 if (!can_cap_in_hardware()) { 684 - dev_err(&resource->acpi_dev->dev, 685 - "Ignoring unsafe software power cap!\n"); 684 + dev_warn(&resource->acpi_dev->dev, 685 + "Ignoring unsafe software power cap!\n"); 686 686 goto skip_unsafe_cap; 687 687 } 688 688
-324
drivers/hwmon/ads1015.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * ads1015.c - lm_sensors driver for ads1015 12-bit 4-input ADC 4 - * (C) Copyright 2010 5 - * Dirk Eibach, Guntermann & Drunck GmbH <eibach@gdsys.de> 6 - * 7 - * Based on the ads7828 driver by Steve Hardy. 8 - * 9 - * Datasheet available at: http://focus.ti.com/lit/ds/symlink/ads1015.pdf 10 - */ 11 - 12 - #include <linux/module.h> 13 - #include <linux/init.h> 14 - #include <linux/slab.h> 15 - #include <linux/delay.h> 16 - #include <linux/i2c.h> 17 - #include <linux/hwmon.h> 18 - #include <linux/hwmon-sysfs.h> 19 - #include <linux/err.h> 20 - #include <linux/mutex.h> 21 - #include <linux/of_device.h> 22 - #include <linux/of.h> 23 - 24 - #include <linux/platform_data/ads1015.h> 25 - 26 - /* ADS1015 registers */ 27 - enum { 28 - ADS1015_CONVERSION = 0, 29 - ADS1015_CONFIG = 1, 30 - }; 31 - 32 - /* PGA fullscale voltages in mV */ 33 - static const unsigned int fullscale_table[8] = { 34 - 6144, 4096, 2048, 1024, 512, 256, 256, 256 }; 35 - 36 - /* Data rates in samples per second */ 37 - static const unsigned int data_rate_table_1015[8] = { 38 - 128, 250, 490, 920, 1600, 2400, 3300, 3300 39 - }; 40 - 41 - static const unsigned int data_rate_table_1115[8] = { 42 - 8, 16, 32, 64, 128, 250, 475, 860 43 - }; 44 - 45 - #define ADS1015_DEFAULT_CHANNELS 0xff 46 - #define ADS1015_DEFAULT_PGA 2 47 - #define ADS1015_DEFAULT_DATA_RATE 4 48 - 49 - enum ads1015_chips { 50 - ads1015, 51 - ads1115, 52 - }; 53 - 54 - struct ads1015_data { 55 - struct device *hwmon_dev; 56 - struct mutex update_lock; /* mutex protect updates */ 57 - struct ads1015_channel_data channel_data[ADS1015_CHANNELS]; 58 - enum ads1015_chips id; 59 - }; 60 - 61 - static int ads1015_read_adc(struct i2c_client *client, unsigned int channel) 62 - { 63 - u16 config; 64 - struct ads1015_data *data = i2c_get_clientdata(client); 65 - unsigned int pga = data->channel_data[channel].pga; 66 - unsigned int data_rate = data->channel_data[channel].data_rate; 67 - unsigned int conversion_time_ms; 68 - const unsigned int * const rate_table = data->id == ads1115 ? 69 - data_rate_table_1115 : data_rate_table_1015; 70 - int res; 71 - 72 - mutex_lock(&data->update_lock); 73 - 74 - /* get channel parameters */ 75 - res = i2c_smbus_read_word_swapped(client, ADS1015_CONFIG); 76 - if (res < 0) 77 - goto err_unlock; 78 - config = res; 79 - conversion_time_ms = DIV_ROUND_UP(1000, rate_table[data_rate]); 80 - 81 - /* setup and start single conversion */ 82 - config &= 0x001f; 83 - config |= (1 << 15) | (1 << 8); 84 - config |= (channel & 0x0007) << 12; 85 - config |= (pga & 0x0007) << 9; 86 - config |= (data_rate & 0x0007) << 5; 87 - 88 - res = i2c_smbus_write_word_swapped(client, ADS1015_CONFIG, config); 89 - if (res < 0) 90 - goto err_unlock; 91 - 92 - /* wait until conversion finished */ 93 - msleep(conversion_time_ms); 94 - res = i2c_smbus_read_word_swapped(client, ADS1015_CONFIG); 95 - if (res < 0) 96 - goto err_unlock; 97 - config = res; 98 - if (!(config & (1 << 15))) { 99 - /* conversion not finished in time */ 100 - res = -EIO; 101 - goto err_unlock; 102 - } 103 - 104 - res = i2c_smbus_read_word_swapped(client, ADS1015_CONVERSION); 105 - 106 - err_unlock: 107 - mutex_unlock(&data->update_lock); 108 - return res; 109 - } 110 - 111 - static int ads1015_reg_to_mv(struct i2c_client *client, unsigned int channel, 112 - s16 reg) 113 - { 114 - struct ads1015_data *data = i2c_get_clientdata(client); 115 - unsigned int pga = data->channel_data[channel].pga; 116 - int fullscale = fullscale_table[pga]; 117 - const int mask = data->id == ads1115 ? 0x7fff : 0x7ff0; 118 - 119 - return DIV_ROUND_CLOSEST(reg * fullscale, mask); 120 - } 121 - 122 - /* sysfs callback function */ 123 - static ssize_t in_show(struct device *dev, struct device_attribute *da, 124 - char *buf) 125 - { 126 - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 127 - struct i2c_client *client = to_i2c_client(dev); 128 - int res; 129 - int index = attr->index; 130 - 131 - res = ads1015_read_adc(client, index); 132 - if (res < 0) 133 - return res; 134 - 135 - return sprintf(buf, "%d\n", ads1015_reg_to_mv(client, index, res)); 136 - } 137 - 138 - static const struct sensor_device_attribute ads1015_in[] = { 139 - SENSOR_ATTR_RO(in0_input, in, 0), 140 - SENSOR_ATTR_RO(in1_input, in, 1), 141 - SENSOR_ATTR_RO(in2_input, in, 2), 142 - SENSOR_ATTR_RO(in3_input, in, 3), 143 - SENSOR_ATTR_RO(in4_input, in, 4), 144 - SENSOR_ATTR_RO(in5_input, in, 5), 145 - SENSOR_ATTR_RO(in6_input, in, 6), 146 - SENSOR_ATTR_RO(in7_input, in, 7), 147 - }; 148 - 149 - /* 150 - * Driver interface 151 - */ 152 - 153 - static int ads1015_remove(struct i2c_client *client) 154 - { 155 - struct ads1015_data *data = i2c_get_clientdata(client); 156 - int k; 157 - 158 - hwmon_device_unregister(data->hwmon_dev); 159 - for (k = 0; k < ADS1015_CHANNELS; ++k) 160 - device_remove_file(&client->dev, &ads1015_in[k].dev_attr); 161 - return 0; 162 - } 163 - 164 - #ifdef CONFIG_OF 165 - static int ads1015_get_channels_config_of(struct i2c_client *client) 166 - { 167 - struct ads1015_data *data = i2c_get_clientdata(client); 168 - struct device_node *node; 169 - 170 - if (!client->dev.of_node 171 - || !of_get_next_child(client->dev.of_node, NULL)) 172 - return -EINVAL; 173 - 174 - for_each_child_of_node(client->dev.of_node, node) { 175 - u32 pval; 176 - unsigned int channel; 177 - unsigned int pga = ADS1015_DEFAULT_PGA; 178 - unsigned int data_rate = ADS1015_DEFAULT_DATA_RATE; 179 - 180 - if (of_property_read_u32(node, "reg", &pval)) { 181 - dev_err(&client->dev, "invalid reg on %pOF\n", node); 182 - continue; 183 - } 184 - 185 - channel = pval; 186 - if (channel >= ADS1015_CHANNELS) { 187 - dev_err(&client->dev, 188 - "invalid channel index %d on %pOF\n", 189 - channel, node); 190 - continue; 191 - } 192 - 193 - if (!of_property_read_u32(node, "ti,gain", &pval)) { 194 - pga = pval; 195 - if (pga > 6) { 196 - dev_err(&client->dev, "invalid gain on %pOF\n", 197 - node); 198 - return -EINVAL; 199 - } 200 - } 201 - 202 - if (!of_property_read_u32(node, "ti,datarate", &pval)) { 203 - data_rate = pval; 204 - if (data_rate > 7) { 205 - dev_err(&client->dev, 206 - "invalid data_rate on %pOF\n", node); 207 - return -EINVAL; 208 - } 209 - } 210 - 211 - data->channel_data[channel].enabled = true; 212 - data->channel_data[channel].pga = pga; 213 - data->channel_data[channel].data_rate = data_rate; 214 - } 215 - 216 - return 0; 217 - } 218 - #endif 219 - 220 - static void ads1015_get_channels_config(struct i2c_client *client) 221 - { 222 - unsigned int k; 223 - struct ads1015_data *data = i2c_get_clientdata(client); 224 - struct ads1015_platform_data *pdata = dev_get_platdata(&client->dev); 225 - 226 - /* prefer platform data */ 227 - if (pdata) { 228 - memcpy(data->channel_data, pdata->channel_data, 229 - sizeof(data->channel_data)); 230 - return; 231 - } 232 - 233 - #ifdef CONFIG_OF 234 - if (!ads1015_get_channels_config_of(client)) 235 - return; 236 - #endif 237 - 238 - /* fallback on default configuration */ 239 - for (k = 0; k < ADS1015_CHANNELS; ++k) { 240 - data->channel_data[k].enabled = true; 241 - data->channel_data[k].pga = ADS1015_DEFAULT_PGA; 242 - data->channel_data[k].data_rate = ADS1015_DEFAULT_DATA_RATE; 243 - } 244 - } 245 - 246 - static int ads1015_probe(struct i2c_client *client, 247 - const struct i2c_device_id *id) 248 - { 249 - struct ads1015_data *data; 250 - int err; 251 - unsigned int k; 252 - 253 - data = devm_kzalloc(&client->dev, sizeof(struct ads1015_data), 254 - GFP_KERNEL); 255 - if (!data) 256 - return -ENOMEM; 257 - 258 - if (client->dev.of_node) 259 - data->id = (enum ads1015_chips) 260 - of_device_get_match_data(&client->dev); 261 - else 262 - data->id = id->driver_data; 263 - i2c_set_clientdata(client, data); 264 - mutex_init(&data->update_lock); 265 - 266 - /* build sysfs attribute group */ 267 - ads1015_get_channels_config(client); 268 - for (k = 0; k < ADS1015_CHANNELS; ++k) { 269 - if (!data->channel_data[k].enabled) 270 - continue; 271 - err = device_create_file(&client->dev, &ads1015_in[k].dev_attr); 272 - if (err) 273 - goto exit_remove; 274 - } 275 - 276 - data->hwmon_dev = hwmon_device_register(&client->dev); 277 - if (IS_ERR(data->hwmon_dev)) { 278 - err = PTR_ERR(data->hwmon_dev); 279 - goto exit_remove; 280 - } 281 - 282 - return 0; 283 - 284 - exit_remove: 285 - for (k = 0; k < ADS1015_CHANNELS; ++k) 286 - device_remove_file(&client->dev, &ads1015_in[k].dev_attr); 287 - return err; 288 - } 289 - 290 - static const struct i2c_device_id ads1015_id[] = { 291 - { "ads1015", ads1015}, 292 - { "ads1115", ads1115}, 293 - { } 294 - }; 295 - MODULE_DEVICE_TABLE(i2c, ads1015_id); 296 - 297 - static const struct of_device_id __maybe_unused ads1015_of_match[] = { 298 - { 299 - .compatible = "ti,ads1015", 300 - .data = (void *)ads1015 301 - }, 302 - { 303 - .compatible = "ti,ads1115", 304 - .data = (void *)ads1115 305 - }, 306 - { }, 307 - }; 308 - MODULE_DEVICE_TABLE(of, ads1015_of_match); 309 - 310 - static struct i2c_driver ads1015_driver = { 311 - .driver = { 312 - .name = "ads1015", 313 - .of_match_table = of_match_ptr(ads1015_of_match), 314 - }, 315 - .probe = ads1015_probe, 316 - .remove = ads1015_remove, 317 - .id_table = ads1015_id, 318 - }; 319 - 320 - module_i2c_driver(ads1015_driver); 321 - 322 - MODULE_AUTHOR("Dirk Eibach <eibach@gdsys.de>"); 323 - MODULE_DESCRIPTION("ADS1015 driver"); 324 - MODULE_LICENSE("GPL");
+50 -96
drivers/hwmon/adt7475.c
··· 187 187 MODULE_DEVICE_TABLE(of, adt7475_of_match); 188 188 189 189 struct adt7475_data { 190 - struct device *hwmon_dev; 190 + struct i2c_client *client; 191 191 struct mutex lock; 192 192 193 193 unsigned long measure_updated; ··· 212 212 213 213 u8 vid; 214 214 u8 vrm; 215 + const struct attribute_group *groups[9]; 215 216 }; 216 217 217 218 static struct i2c_driver adt7475_driver; ··· 347 346 { 348 347 349 348 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); 350 - struct i2c_client *client = to_i2c_client(dev); 351 - struct adt7475_data *data = i2c_get_clientdata(client); 349 + struct adt7475_data *data = dev_get_drvdata(dev); 350 + struct i2c_client *client = data->client; 352 351 unsigned char reg; 353 352 long val; 354 353 ··· 441 440 const char *buf, size_t count) 442 441 { 443 442 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); 444 - struct i2c_client *client = to_i2c_client(dev); 445 - struct adt7475_data *data = i2c_get_clientdata(client); 443 + struct adt7475_data *data = dev_get_drvdata(dev); 444 + struct i2c_client *client = data->client; 446 445 unsigned char reg = 0; 447 446 u8 out; 448 447 int temp; ··· 543 542 char *buf) 544 543 { 545 544 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); 546 - struct i2c_client *client = to_i2c_client(dev); 547 - struct adt7475_data *data = i2c_get_clientdata(client); 545 + struct adt7475_data *data = dev_get_drvdata(dev); 548 546 long val; 549 547 550 548 switch (sattr->index) { ··· 570 570 size_t count) 571 571 { 572 572 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); 573 - struct i2c_client *client = to_i2c_client(dev); 574 - struct adt7475_data *data = i2c_get_clientdata(client); 573 + struct adt7475_data *data = dev_get_drvdata(dev); 574 + struct i2c_client *client = data->client; 575 575 unsigned char reg; 576 576 int shift, idx; 577 577 ulong val; ··· 647 647 static ssize_t point2_store(struct device *dev, struct device_attribute *attr, 648 648 const char *buf, size_t count) 649 649 { 650 - struct i2c_client *client = to_i2c_client(dev); 651 - struct adt7475_data *data = i2c_get_clientdata(client); 650 + struct adt7475_data *data = dev_get_drvdata(dev); 651 + struct i2c_client *client = data->client; 652 652 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); 653 653 int temp; 654 654 long val; ··· 710 710 { 711 711 712 712 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); 713 - struct i2c_client *client = to_i2c_client(dev); 714 - struct adt7475_data *data = i2c_get_clientdata(client); 713 + struct adt7475_data *data = dev_get_drvdata(dev); 714 + struct i2c_client *client = data->client; 715 715 unsigned long val; 716 716 717 717 if (kstrtoul(buf, 10, &val)) ··· 769 769 { 770 770 771 771 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); 772 - struct i2c_client *client = to_i2c_client(dev); 773 - struct adt7475_data *data = i2c_get_clientdata(client); 772 + struct adt7475_data *data = dev_get_drvdata(dev); 773 + struct i2c_client *client = data->client; 774 774 unsigned char reg = 0; 775 775 long val; 776 776 ··· 818 818 struct device_attribute *attr, char *buf) 819 819 { 820 820 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); 821 - struct i2c_client *client = to_i2c_client(dev); 822 - struct adt7475_data *data = i2c_get_clientdata(client); 821 + struct adt7475_data *data = dev_get_drvdata(dev); 822 + 823 823 u8 mask = BIT(5 + sattr->index); 824 824 825 825 return sprintf(buf, "%d\n", !!(data->enh_acoustics[0] & mask)); ··· 830 830 const char *buf, size_t count) 831 831 { 832 832 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); 833 - struct i2c_client *client = to_i2c_client(dev); 834 - struct adt7475_data *data = i2c_get_clientdata(client); 833 + struct adt7475_data *data = dev_get_drvdata(dev); 834 + struct i2c_client *client = data->client; 835 835 long val; 836 836 u8 mask = BIT(5 + sattr->index); 837 837 ··· 914 914 size_t count) 915 915 { 916 916 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); 917 - struct i2c_client *client = to_i2c_client(dev); 918 - struct adt7475_data *data = i2c_get_clientdata(client); 917 + struct adt7475_data *data = dev_get_drvdata(dev); 918 + struct i2c_client *client = data->client; 919 919 int r; 920 920 long val; 921 921 ··· 938 938 size_t count) 939 939 { 940 940 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); 941 - struct i2c_client *client = to_i2c_client(dev); 942 - struct adt7475_data *data = i2c_get_clientdata(client); 941 + struct adt7475_data *data = dev_get_drvdata(dev); 942 + struct i2c_client *client = data->client; 943 943 int r; 944 944 long val; 945 945 ··· 982 982 size_t count) 983 983 { 984 984 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); 985 - struct i2c_client *client = to_i2c_client(dev); 986 - struct adt7475_data *data = i2c_get_clientdata(client); 985 + struct adt7475_data *data = dev_get_drvdata(dev); 986 + struct i2c_client *client = data->client; 987 987 int out; 988 988 long val; 989 989 ··· 1022 1022 struct device_attribute *devattr, 1023 1023 const char *buf, size_t count) 1024 1024 { 1025 - struct i2c_client *client = to_i2c_client(dev); 1026 - struct adt7475_data *data = i2c_get_clientdata(client); 1025 + struct adt7475_data *data = dev_get_drvdata(dev); 1026 + struct i2c_client *client = data->client; 1027 1027 long val; 1028 1028 1029 1029 if (kstrtol(buf, 10, &val)) ··· 1342 1342 return 0; 1343 1343 } 1344 1344 1345 - static void adt7475_remove_files(struct i2c_client *client, 1346 - struct adt7475_data *data) 1347 - { 1348 - sysfs_remove_group(&client->dev.kobj, &adt7475_attr_group); 1349 - if (data->has_fan4) 1350 - sysfs_remove_group(&client->dev.kobj, &fan4_attr_group); 1351 - if (data->has_pwm2) 1352 - sysfs_remove_group(&client->dev.kobj, &pwm2_attr_group); 1353 - if (data->has_voltage & (1 << 0)) 1354 - sysfs_remove_group(&client->dev.kobj, &in0_attr_group); 1355 - if (data->has_voltage & (1 << 3)) 1356 - sysfs_remove_group(&client->dev.kobj, &in3_attr_group); 1357 - if (data->has_voltage & (1 << 4)) 1358 - sysfs_remove_group(&client->dev.kobj, &in4_attr_group); 1359 - if (data->has_voltage & (1 << 5)) 1360 - sysfs_remove_group(&client->dev.kobj, &in5_attr_group); 1361 - if (data->has_vid) 1362 - sysfs_remove_group(&client->dev.kobj, &vid_attr_group); 1363 - } 1364 - 1365 1345 static int adt7475_update_limits(struct i2c_client *client) 1366 1346 { 1367 1347 struct adt7475_data *data = i2c_get_clientdata(client); ··· 1469 1489 }; 1470 1490 1471 1491 struct adt7475_data *data; 1472 - int i, ret = 0, revision; 1492 + struct device *hwmon_dev; 1493 + int i, ret = 0, revision, group_num = 0; 1473 1494 u8 config2, config3; 1474 1495 1475 1496 data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); ··· 1478 1497 return -ENOMEM; 1479 1498 1480 1499 mutex_init(&data->lock); 1500 + data->client = client; 1481 1501 i2c_set_clientdata(client, data); 1482 1502 1483 1503 if (client->dev.of_node) ··· 1572 1590 break; 1573 1591 } 1574 1592 1575 - ret = sysfs_create_group(&client->dev.kobj, &adt7475_attr_group); 1576 - if (ret) 1577 - return ret; 1593 + data->groups[group_num++] = &adt7475_attr_group; 1578 1594 1579 1595 /* Features that can be disabled individually */ 1580 1596 if (data->has_fan4) { 1581 - ret = sysfs_create_group(&client->dev.kobj, &fan4_attr_group); 1582 - if (ret) 1583 - goto eremove; 1597 + data->groups[group_num++] = &fan4_attr_group; 1584 1598 } 1585 1599 if (data->has_pwm2) { 1586 - ret = sysfs_create_group(&client->dev.kobj, &pwm2_attr_group); 1587 - if (ret) 1588 - goto eremove; 1600 + data->groups[group_num++] = &pwm2_attr_group; 1589 1601 } 1590 1602 if (data->has_voltage & (1 << 0)) { 1591 - ret = sysfs_create_group(&client->dev.kobj, &in0_attr_group); 1592 - if (ret) 1593 - goto eremove; 1603 + data->groups[group_num++] = &in0_attr_group; 1594 1604 } 1595 1605 if (data->has_voltage & (1 << 3)) { 1596 - ret = sysfs_create_group(&client->dev.kobj, &in3_attr_group); 1597 - if (ret) 1598 - goto eremove; 1606 + data->groups[group_num++] = &in3_attr_group; 1599 1607 } 1600 1608 if (data->has_voltage & (1 << 4)) { 1601 - ret = sysfs_create_group(&client->dev.kobj, &in4_attr_group); 1602 - if (ret) 1603 - goto eremove; 1609 + data->groups[group_num++] = &in4_attr_group; 1604 1610 } 1605 1611 if (data->has_voltage & (1 << 5)) { 1606 - ret = sysfs_create_group(&client->dev.kobj, &in5_attr_group); 1607 - if (ret) 1608 - goto eremove; 1612 + data->groups[group_num++] = &in5_attr_group; 1609 1613 } 1610 1614 if (data->has_vid) { 1611 1615 data->vrm = vid_which_vrm(); 1612 - ret = sysfs_create_group(&client->dev.kobj, &vid_attr_group); 1613 - if (ret) 1614 - goto eremove; 1616 + data->groups[group_num] = &vid_attr_group; 1615 1617 } 1616 1618 1617 - data->hwmon_dev = hwmon_device_register(&client->dev); 1618 - if (IS_ERR(data->hwmon_dev)) { 1619 - ret = PTR_ERR(data->hwmon_dev); 1620 - goto eremove; 1619 + /* register device with all the acquired attributes */ 1620 + hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev, 1621 + client->name, data, 1622 + data->groups); 1623 + 1624 + if (IS_ERR(hwmon_dev)) { 1625 + ret = PTR_ERR(hwmon_dev); 1626 + return ret; 1621 1627 } 1622 1628 1623 1629 dev_info(&client->dev, "%s device, revision %d\n", ··· 1627 1657 /* Limits and settings, should never change update more than once */ 1628 1658 ret = adt7475_update_limits(client); 1629 1659 if (ret) 1630 - goto eremove; 1631 - 1632 - return 0; 1633 - 1634 - eremove: 1635 - adt7475_remove_files(client, data); 1636 - return ret; 1637 - } 1638 - 1639 - static int adt7475_remove(struct i2c_client *client) 1640 - { 1641 - struct adt7475_data *data = i2c_get_clientdata(client); 1642 - 1643 - hwmon_device_unregister(data->hwmon_dev); 1644 - adt7475_remove_files(client, data); 1660 + return ret; 1645 1661 1646 1662 return 0; 1647 1663 } ··· 1639 1683 .of_match_table = of_match_ptr(adt7475_of_match), 1640 1684 }, 1641 1685 .probe = adt7475_probe, 1642 - .remove = adt7475_remove, 1643 1686 .id_table = adt7475_id, 1644 1687 .detect = adt7475_detect, 1645 1688 .address_list = normal_i2c, ··· 1712 1757 1713 1758 static int adt7475_update_measure(struct device *dev) 1714 1759 { 1715 - struct i2c_client *client = to_i2c_client(dev); 1716 - struct adt7475_data *data = i2c_get_clientdata(client); 1760 + struct adt7475_data *data = dev_get_drvdata(dev); 1761 + struct i2c_client *client = data->client; 1717 1762 u16 ext; 1718 1763 int i; 1719 1764 int ret; ··· 1809 1854 1810 1855 static struct adt7475_data *adt7475_update_device(struct device *dev) 1811 1856 { 1812 - struct i2c_client *client = to_i2c_client(dev); 1813 - struct adt7475_data *data = i2c_get_clientdata(client); 1857 + struct adt7475_data *data = dev_get_drvdata(dev); 1814 1858 int ret; 1815 1859 1816 1860 mutex_lock(&data->lock);
+145
drivers/hwmon/as370-hwmon.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Synaptics AS370 SoC Hardware Monitoring Driver 4 + * 5 + * Copyright (C) 2018 Synaptics Incorporated 6 + * Author: Jisheng Zhang <jszhang@kernel.org> 7 + */ 8 + 9 + #include <linux/bitops.h> 10 + #include <linux/hwmon.h> 11 + #include <linux/init.h> 12 + #include <linux/io.h> 13 + #include <linux/module.h> 14 + #include <linux/of_device.h> 15 + 16 + #define CTRL 0x0 17 + #define PD BIT(0) 18 + #define EN BIT(1) 19 + #define T_SEL BIT(2) 20 + #define V_SEL BIT(3) 21 + #define NMOS_SEL BIT(8) 22 + #define PMOS_SEL BIT(9) 23 + #define STS 0x4 24 + #define BN_MASK GENMASK(11, 0) 25 + #define EOC BIT(12) 26 + 27 + struct as370_hwmon { 28 + void __iomem *base; 29 + }; 30 + 31 + static void init_pvt(struct as370_hwmon *hwmon) 32 + { 33 + u32 val; 34 + void __iomem *addr = hwmon->base + CTRL; 35 + 36 + val = PD; 37 + writel_relaxed(val, addr); 38 + val |= T_SEL; 39 + writel_relaxed(val, addr); 40 + val |= EN; 41 + writel_relaxed(val, addr); 42 + val &= ~PD; 43 + writel_relaxed(val, addr); 44 + } 45 + 46 + static int as370_hwmon_read(struct device *dev, enum hwmon_sensor_types type, 47 + u32 attr, int channel, long *temp) 48 + { 49 + int val; 50 + struct as370_hwmon *hwmon = dev_get_drvdata(dev); 51 + 52 + switch (attr) { 53 + case hwmon_temp_input: 54 + val = readl_relaxed(hwmon->base + STS) & BN_MASK; 55 + *temp = DIV_ROUND_CLOSEST(val * 251802, 4096) - 85525; 56 + break; 57 + default: 58 + return -EOPNOTSUPP; 59 + } 60 + 61 + return 0; 62 + } 63 + 64 + static umode_t 65 + as370_hwmon_is_visible(const void *data, enum hwmon_sensor_types type, 66 + u32 attr, int channel) 67 + { 68 + if (type != hwmon_temp) 69 + return 0; 70 + 71 + switch (attr) { 72 + case hwmon_temp_input: 73 + return 0444; 74 + default: 75 + return 0; 76 + } 77 + } 78 + 79 + static const u32 as370_hwmon_temp_config[] = { 80 + HWMON_T_INPUT, 81 + 0 82 + }; 83 + 84 + static const struct hwmon_channel_info as370_hwmon_temp = { 85 + .type = hwmon_temp, 86 + .config = as370_hwmon_temp_config, 87 + }; 88 + 89 + static const struct hwmon_channel_info *as370_hwmon_info[] = { 90 + &as370_hwmon_temp, 91 + NULL 92 + }; 93 + 94 + static const struct hwmon_ops as370_hwmon_ops = { 95 + .is_visible = as370_hwmon_is_visible, 96 + .read = as370_hwmon_read, 97 + }; 98 + 99 + static const struct hwmon_chip_info as370_chip_info = { 100 + .ops = &as370_hwmon_ops, 101 + .info = as370_hwmon_info, 102 + }; 103 + 104 + static int as370_hwmon_probe(struct platform_device *pdev) 105 + { 106 + struct device *hwmon_dev; 107 + struct as370_hwmon *hwmon; 108 + struct device *dev = &pdev->dev; 109 + 110 + hwmon = devm_kzalloc(dev, sizeof(*hwmon), GFP_KERNEL); 111 + if (!hwmon) 112 + return -ENOMEM; 113 + 114 + hwmon->base = devm_platform_ioremap_resource(pdev, 0); 115 + if (IS_ERR(hwmon->base)) 116 + return PTR_ERR(hwmon->base); 117 + 118 + init_pvt(hwmon); 119 + 120 + hwmon_dev = devm_hwmon_device_register_with_info(dev, 121 + "as370", 122 + hwmon, 123 + &as370_chip_info, 124 + NULL); 125 + return PTR_ERR_OR_ZERO(hwmon_dev); 126 + } 127 + 128 + static const struct of_device_id as370_hwmon_match[] = { 129 + { .compatible = "syna,as370-hwmon" }, 130 + {}, 131 + }; 132 + MODULE_DEVICE_TABLE(of, as370_hwmon_match); 133 + 134 + static struct platform_driver as370_hwmon_driver = { 135 + .probe = as370_hwmon_probe, 136 + .driver = { 137 + .name = "as370-hwmon", 138 + .of_match_table = as370_hwmon_match, 139 + }, 140 + }; 141 + module_platform_driver(as370_hwmon_driver); 142 + 143 + MODULE_AUTHOR("Jisheng Zhang<jszhang@kernel.org>"); 144 + MODULE_DESCRIPTION("Synaptics AS370 SoC hardware monitor"); 145 + MODULE_LICENSE("GPL v2");
+6 -6
drivers/hwmon/asb100.c
··· 706 706 goto ERROR_SC_2; 707 707 } 708 708 709 - data->lm75[0] = i2c_new_dummy(adapter, sc_addr[0]); 710 - if (!data->lm75[0]) { 709 + data->lm75[0] = i2c_new_dummy_device(adapter, sc_addr[0]); 710 + if (IS_ERR(data->lm75[0])) { 711 711 dev_err(&client->dev, 712 712 "subclient %d registration at address 0x%x failed.\n", 713 713 1, sc_addr[0]); 714 - err = -ENOMEM; 714 + err = PTR_ERR(data->lm75[0]); 715 715 goto ERROR_SC_2; 716 716 } 717 717 718 - data->lm75[1] = i2c_new_dummy(adapter, sc_addr[1]); 719 - if (!data->lm75[1]) { 718 + data->lm75[1] = i2c_new_dummy_device(adapter, sc_addr[1]); 719 + if (IS_ERR(data->lm75[1])) { 720 720 dev_err(&client->dev, 721 721 "subclient %d registration at address 0x%x failed.\n", 722 722 2, sc_addr[1]); 723 - err = -ENOMEM; 723 + err = PTR_ERR(data->lm75[1]); 724 724 goto ERROR_SC_3; 725 725 } 726 726
+2 -1
drivers/hwmon/coretemp.c
··· 736 736 737 737 err = platform_driver_register(&coretemp_driver); 738 738 if (err) 739 - return err; 739 + goto outzone; 740 740 741 741 err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "hwmon/coretemp:online", 742 742 coretemp_cpu_online, coretemp_cpu_offline); ··· 747 747 748 748 outdrv: 749 749 platform_driver_unregister(&coretemp_driver); 750 + outzone: 750 751 kfree(zone_devices); 751 752 return err; 752 753 }
+15 -3
drivers/hwmon/iio_hwmon.c
··· 44 44 int ret; 45 45 struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); 46 46 struct iio_hwmon_state *state = dev_get_drvdata(dev); 47 + struct iio_channel *chan = &state->channels[sattr->index]; 48 + enum iio_chan_type type; 47 49 48 - ret = iio_read_channel_processed(&state->channels[sattr->index], 49 - &result); 50 + ret = iio_read_channel_processed(chan, &result); 50 51 if (ret < 0) 51 52 return ret; 53 + 54 + ret = iio_get_channel_type(chan, &type); 55 + if (ret < 0) 56 + return ret; 57 + 58 + if (type == IIO_POWER) 59 + result *= 1000; /* mili-Watts to micro-Watts conversion */ 52 60 53 61 return sprintf(buf, "%d\n", result); 54 62 } ··· 67 59 struct iio_hwmon_state *st; 68 60 struct sensor_device_attribute *a; 69 61 int ret, i; 70 - int in_i = 1, temp_i = 1, curr_i = 1, humidity_i = 1; 62 + int in_i = 1, temp_i = 1, curr_i = 1, humidity_i = 1, power_i = 1; 71 63 enum iio_chan_type type; 72 64 struct iio_channel *channels; 73 65 struct device *hwmon_dev; ··· 121 113 case IIO_CURRENT: 122 114 n = curr_i++; 123 115 prefix = "curr"; 116 + break; 117 + case IIO_POWER: 118 + n = power_i++; 119 + prefix = "power"; 124 120 break; 125 121 case IIO_HUMIDITYRELATIVE: 126 122 n = humidity_i++;
+1
drivers/hwmon/k10temp.c
··· 349 349 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_17H_DF_F3) }, 350 350 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_17H_M10H_DF_F3) }, 351 351 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_17H_M30H_DF_F3) }, 352 + { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_17H_M70H_DF_F3) }, 352 353 { PCI_VDEVICE(HYGON, PCI_DEVICE_ID_AMD_17H_DF_F3) }, 353 354 {} 354 355 };
+69 -164
drivers/hwmon/k8temp.c
··· 10 10 #include <linux/module.h> 11 11 #include <linux/init.h> 12 12 #include <linux/slab.h> 13 - #include <linux/jiffies.h> 14 13 #include <linux/pci.h> 15 14 #include <linux/hwmon.h> 16 - #include <linux/hwmon-sysfs.h> 17 15 #include <linux/err.h> 18 16 #include <linux/mutex.h> 19 17 #include <asm/processor.h> ··· 22 24 #define SEL_CORE 0x04 23 25 24 26 struct k8temp_data { 25 - struct device *hwmon_dev; 26 27 struct mutex update_lock; 27 - const char *name; 28 - char valid; /* zero until following fields are valid */ 29 - unsigned long last_updated; /* in jiffies */ 30 28 31 29 /* registers values */ 32 30 u8 sensorsp; /* sensor presence bits - SEL_CORE, SEL_PLACE */ 33 - u32 temp[2][2]; /* core, place */ 34 31 u8 swap_core_select; /* meaning of SEL_CORE is inverted */ 35 32 u32 temp_offset; 36 33 }; 37 - 38 - static struct k8temp_data *k8temp_update_device(struct device *dev) 39 - { 40 - struct k8temp_data *data = dev_get_drvdata(dev); 41 - struct pci_dev *pdev = to_pci_dev(dev); 42 - u8 tmp; 43 - 44 - mutex_lock(&data->update_lock); 45 - 46 - if (!data->valid 47 - || time_after(jiffies, data->last_updated + HZ)) { 48 - pci_read_config_byte(pdev, REG_TEMP, &tmp); 49 - tmp &= ~(SEL_PLACE | SEL_CORE); /* Select sensor 0, core0 */ 50 - pci_write_config_byte(pdev, REG_TEMP, tmp); 51 - pci_read_config_dword(pdev, REG_TEMP, &data->temp[0][0]); 52 - 53 - if (data->sensorsp & SEL_PLACE) { 54 - tmp |= SEL_PLACE; /* Select sensor 1, core0 */ 55 - pci_write_config_byte(pdev, REG_TEMP, tmp); 56 - pci_read_config_dword(pdev, REG_TEMP, 57 - &data->temp[0][1]); 58 - } 59 - 60 - if (data->sensorsp & SEL_CORE) { 61 - tmp &= ~SEL_PLACE; /* Select sensor 0, core1 */ 62 - tmp |= SEL_CORE; 63 - pci_write_config_byte(pdev, REG_TEMP, tmp); 64 - pci_read_config_dword(pdev, REG_TEMP, 65 - &data->temp[1][0]); 66 - 67 - if (data->sensorsp & SEL_PLACE) { 68 - tmp |= SEL_PLACE; /* Select sensor 1, core1 */ 69 - pci_write_config_byte(pdev, REG_TEMP, tmp); 70 - pci_read_config_dword(pdev, REG_TEMP, 71 - &data->temp[1][1]); 72 - } 73 - } 74 - 75 - data->last_updated = jiffies; 76 - data->valid = 1; 77 - } 78 - 79 - mutex_unlock(&data->update_lock); 80 - return data; 81 - } 82 - 83 - /* 84 - * Sysfs stuff 85 - */ 86 - 87 - static ssize_t name_show(struct device *dev, struct device_attribute 88 - *devattr, char *buf) 89 - { 90 - struct k8temp_data *data = dev_get_drvdata(dev); 91 - 92 - return sprintf(buf, "%s\n", data->name); 93 - } 94 - 95 - 96 - static ssize_t temp_show(struct device *dev, struct device_attribute *devattr, 97 - char *buf) 98 - { 99 - struct sensor_device_attribute_2 *attr = 100 - to_sensor_dev_attr_2(devattr); 101 - int core = attr->nr; 102 - int place = attr->index; 103 - int temp; 104 - struct k8temp_data *data = k8temp_update_device(dev); 105 - 106 - if (data->swap_core_select && (data->sensorsp & SEL_CORE)) 107 - core = core ? 0 : 1; 108 - 109 - temp = TEMP_FROM_REG(data->temp[core][place]) + data->temp_offset; 110 - 111 - return sprintf(buf, "%d\n", temp); 112 - } 113 - 114 - /* core, place */ 115 - 116 - static SENSOR_DEVICE_ATTR_2_RO(temp1_input, temp, 0, 0); 117 - static SENSOR_DEVICE_ATTR_2_RO(temp2_input, temp, 0, 1); 118 - static SENSOR_DEVICE_ATTR_2_RO(temp3_input, temp, 1, 0); 119 - static SENSOR_DEVICE_ATTR_2_RO(temp4_input, temp, 1, 1); 120 - static DEVICE_ATTR_RO(name); 121 34 122 35 static const struct pci_device_id k8temp_ids[] = { 123 36 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MISC) }, 124 37 { 0 }, 125 38 }; 126 - 127 39 MODULE_DEVICE_TABLE(pci, k8temp_ids); 128 40 129 41 static int is_rev_g_desktop(u8 model) ··· 67 159 return 1; 68 160 } 69 161 162 + static umode_t 163 + k8temp_is_visible(const void *drvdata, enum hwmon_sensor_types type, 164 + u32 attr, int channel) 165 + { 166 + const struct k8temp_data *data = drvdata; 167 + 168 + if ((channel & 1) && !(data->sensorsp & SEL_PLACE)) 169 + return 0; 170 + 171 + if ((channel & 2) && !(data->sensorsp & SEL_CORE)) 172 + return 0; 173 + 174 + return 0444; 175 + } 176 + 177 + static int 178 + k8temp_read(struct device *dev, enum hwmon_sensor_types type, 179 + u32 attr, int channel, long *val) 180 + { 181 + struct k8temp_data *data = dev_get_drvdata(dev); 182 + struct pci_dev *pdev = to_pci_dev(dev->parent); 183 + int core, place; 184 + u32 temp; 185 + u8 tmp; 186 + 187 + core = (channel >> 1) & 1; 188 + place = channel & 1; 189 + 190 + core ^= data->swap_core_select; 191 + 192 + mutex_lock(&data->update_lock); 193 + pci_read_config_byte(pdev, REG_TEMP, &tmp); 194 + tmp &= ~(SEL_PLACE | SEL_CORE); 195 + if (core) 196 + tmp |= SEL_CORE; 197 + if (place) 198 + tmp |= SEL_PLACE; 199 + pci_write_config_byte(pdev, REG_TEMP, tmp); 200 + pci_read_config_dword(pdev, REG_TEMP, &temp); 201 + mutex_unlock(&data->update_lock); 202 + 203 + *val = TEMP_FROM_REG(temp) + data->temp_offset; 204 + 205 + return 0; 206 + } 207 + 208 + static const struct hwmon_ops k8temp_ops = { 209 + .is_visible = k8temp_is_visible, 210 + .read = k8temp_read, 211 + }; 212 + 213 + static const struct hwmon_channel_info *k8temp_info[] = { 214 + HWMON_CHANNEL_INFO(temp, 215 + HWMON_T_INPUT, HWMON_T_INPUT, HWMON_T_INPUT, HWMON_T_INPUT), 216 + NULL 217 + }; 218 + 219 + static const struct hwmon_chip_info k8temp_chip_info = { 220 + .ops = &k8temp_ops, 221 + .info = k8temp_info, 222 + }; 223 + 70 224 static int k8temp_probe(struct pci_dev *pdev, 71 225 const struct pci_device_id *id) 72 226 { 73 - int err; 74 227 u8 scfg; 75 228 u32 temp; 76 229 u8 model, stepping; 77 230 struct k8temp_data *data; 231 + struct device *hwmon_dev; 78 232 79 233 data = devm_kzalloc(&pdev->dev, sizeof(struct k8temp_data), GFP_KERNEL); 80 234 if (!data) ··· 201 231 data->sensorsp &= ~SEL_CORE; 202 232 } 203 233 204 - data->name = "k8temp"; 205 234 mutex_init(&data->update_lock); 206 - pci_set_drvdata(pdev, data); 207 235 208 - /* Register sysfs hooks */ 209 - err = device_create_file(&pdev->dev, 210 - &sensor_dev_attr_temp1_input.dev_attr); 211 - if (err) 212 - goto exit_remove; 236 + hwmon_dev = devm_hwmon_device_register_with_info(&pdev->dev, 237 + "k8temp", 238 + data, 239 + &k8temp_chip_info, 240 + NULL); 213 241 214 - /* sensor can be changed and reports something */ 215 - if (data->sensorsp & SEL_PLACE) { 216 - err = device_create_file(&pdev->dev, 217 - &sensor_dev_attr_temp2_input.dev_attr); 218 - if (err) 219 - goto exit_remove; 220 - } 221 - 222 - /* core can be changed and reports something */ 223 - if (data->sensorsp & SEL_CORE) { 224 - err = device_create_file(&pdev->dev, 225 - &sensor_dev_attr_temp3_input.dev_attr); 226 - if (err) 227 - goto exit_remove; 228 - if (data->sensorsp & SEL_PLACE) { 229 - err = device_create_file(&pdev->dev, 230 - &sensor_dev_attr_temp4_input. 231 - dev_attr); 232 - if (err) 233 - goto exit_remove; 234 - } 235 - } 236 - 237 - err = device_create_file(&pdev->dev, &dev_attr_name); 238 - if (err) 239 - goto exit_remove; 240 - 241 - data->hwmon_dev = hwmon_device_register(&pdev->dev); 242 - 243 - if (IS_ERR(data->hwmon_dev)) { 244 - err = PTR_ERR(data->hwmon_dev); 245 - goto exit_remove; 246 - } 247 - 248 - return 0; 249 - 250 - exit_remove: 251 - device_remove_file(&pdev->dev, 252 - &sensor_dev_attr_temp1_input.dev_attr); 253 - device_remove_file(&pdev->dev, 254 - &sensor_dev_attr_temp2_input.dev_attr); 255 - device_remove_file(&pdev->dev, 256 - &sensor_dev_attr_temp3_input.dev_attr); 257 - device_remove_file(&pdev->dev, 258 - &sensor_dev_attr_temp4_input.dev_attr); 259 - device_remove_file(&pdev->dev, &dev_attr_name); 260 - return err; 261 - } 262 - 263 - static void k8temp_remove(struct pci_dev *pdev) 264 - { 265 - struct k8temp_data *data = pci_get_drvdata(pdev); 266 - 267 - hwmon_device_unregister(data->hwmon_dev); 268 - device_remove_file(&pdev->dev, 269 - &sensor_dev_attr_temp1_input.dev_attr); 270 - device_remove_file(&pdev->dev, 271 - &sensor_dev_attr_temp2_input.dev_attr); 272 - device_remove_file(&pdev->dev, 273 - &sensor_dev_attr_temp3_input.dev_attr); 274 - device_remove_file(&pdev->dev, 275 - &sensor_dev_attr_temp4_input.dev_attr); 276 - device_remove_file(&pdev->dev, &dev_attr_name); 242 + return PTR_ERR_OR_ZERO(hwmon_dev); 277 243 } 278 244 279 245 static struct pci_driver k8temp_driver = { 280 246 .name = "k8temp", 281 247 .id_table = k8temp_ids, 282 248 .probe = k8temp_probe, 283 - .remove = k8temp_remove, 284 249 }; 285 250 286 251 module_pci_driver(k8temp_driver);
+346 -114
drivers/hwmon/lm75.c
··· 16 16 #include <linux/of_device.h> 17 17 #include <linux/of.h> 18 18 #include <linux/regmap.h> 19 + #include <linux/util_macros.h> 19 20 #include "lm75.h" 20 - 21 21 22 22 /* 23 23 * This driver handles the LM75 and compatible digital temperature sensors. ··· 36 36 max6626, 37 37 max31725, 38 38 mcp980x, 39 + pct2075, 39 40 stds75, 40 41 stlm75, 41 42 tcn75, ··· 51 50 tmp75c, 52 51 }; 53 52 53 + /** 54 + * struct lm75_params - lm75 configuration parameters. 55 + * @set_mask: Bits to set in configuration register when configuring 56 + * the chip. 57 + * @clr_mask: Bits to clear in configuration register when configuring 58 + * the chip. 59 + * @default_resolution: Default number of bits to represent the temperature 60 + * value. 61 + * @resolution_limits: Limit register resolution. Optional. Should be set if 62 + * the resolution of limit registers does not match the 63 + * resolution of the temperature register. 64 + * @resolutions: List of resolutions associated with sample times. 65 + * Optional. Should be set if num_sample_times is larger 66 + * than 1, and if the resolution changes with sample times. 67 + * If set, number of entries must match num_sample_times. 68 + * @default_sample_time:Sample time to be set by default. 69 + * @num_sample_times: Number of possible sample times to be set. Optional. 70 + * Should be set if the number of sample times is larger 71 + * than one. 72 + * @sample_times: All the possible sample times to be set. Mandatory if 73 + * num_sample_times is larger than 1. If set, number of 74 + * entries must match num_sample_times. 75 + */ 76 + 77 + struct lm75_params { 78 + u8 set_mask; 79 + u8 clr_mask; 80 + u8 default_resolution; 81 + u8 resolution_limits; 82 + const u8 *resolutions; 83 + unsigned int default_sample_time; 84 + u8 num_sample_times; 85 + const unsigned int *sample_times; 86 + }; 87 + 54 88 /* Addresses scanned */ 55 89 static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c, 56 90 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; ··· 95 59 #define LM75_REG_CONF 0x01 96 60 #define LM75_REG_HYST 0x02 97 61 #define LM75_REG_MAX 0x03 62 + #define PCT2075_REG_IDLE 0x04 98 63 99 64 /* Each client has this additional data */ 100 65 struct lm75_data { 101 - struct i2c_client *client; 102 - struct regmap *regmap; 103 - u8 orig_conf; 104 - u8 resolution; /* In bits, between 9 and 16 */ 105 - u8 resolution_limits; 106 - unsigned int sample_time; /* In ms */ 66 + struct i2c_client *client; 67 + struct regmap *regmap; 68 + u8 orig_conf; 69 + u8 current_conf; 70 + u8 resolution; /* In bits, 9 to 16 */ 71 + unsigned int sample_time; /* In ms */ 72 + enum lm75_type kind; 73 + const struct lm75_params *params; 107 74 }; 108 75 109 76 /*-----------------------------------------------------------------------*/ 110 77 78 + static const u8 lm75_sample_set_masks[] = { 0 << 5, 1 << 5, 2 << 5, 3 << 5 }; 79 + 80 + #define LM75_SAMPLE_CLEAR_MASK (3 << 5) 81 + 82 + /* The structure below stores the configuration values of the supported devices. 83 + * In case of being supported multiple configurations, the default one must 84 + * always be the first element of the array 85 + */ 86 + static const struct lm75_params device_params[] = { 87 + [adt75] = { 88 + .clr_mask = 1 << 5, /* not one-shot mode */ 89 + .default_resolution = 12, 90 + .default_sample_time = MSEC_PER_SEC / 10, 91 + }, 92 + [ds1775] = { 93 + .clr_mask = 3 << 5, 94 + .set_mask = 2 << 5, /* 11-bit mode */ 95 + .default_resolution = 11, 96 + .default_sample_time = 500, 97 + .num_sample_times = 4, 98 + .sample_times = (unsigned int []){ 125, 250, 500, 1000 }, 99 + .resolutions = (u8 []) {9, 10, 11, 12 }, 100 + }, 101 + [ds75] = { 102 + .clr_mask = 3 << 5, 103 + .set_mask = 2 << 5, /* 11-bit mode */ 104 + .default_resolution = 11, 105 + .default_sample_time = 600, 106 + .num_sample_times = 4, 107 + .sample_times = (unsigned int []){ 150, 300, 600, 1200 }, 108 + .resolutions = (u8 []) {9, 10, 11, 12 }, 109 + }, 110 + [stds75] = { 111 + .clr_mask = 3 << 5, 112 + .set_mask = 2 << 5, /* 11-bit mode */ 113 + .default_resolution = 11, 114 + .default_sample_time = 600, 115 + .num_sample_times = 4, 116 + .sample_times = (unsigned int []){ 150, 300, 600, 1200 }, 117 + .resolutions = (u8 []) {9, 10, 11, 12 }, 118 + }, 119 + [stlm75] = { 120 + .default_resolution = 9, 121 + .default_sample_time = MSEC_PER_SEC / 6, 122 + }, 123 + [ds7505] = { 124 + .set_mask = 3 << 5, /* 12-bit mode*/ 125 + .default_resolution = 12, 126 + .default_sample_time = 200, 127 + .num_sample_times = 4, 128 + .sample_times = (unsigned int []){ 25, 50, 100, 200 }, 129 + .resolutions = (u8 []) {9, 10, 11, 12 }, 130 + }, 131 + [g751] = { 132 + .default_resolution = 9, 133 + .default_sample_time = MSEC_PER_SEC / 10, 134 + }, 135 + [lm75] = { 136 + .default_resolution = 9, 137 + .default_sample_time = MSEC_PER_SEC / 10, 138 + }, 139 + [lm75a] = { 140 + .default_resolution = 9, 141 + .default_sample_time = MSEC_PER_SEC / 10, 142 + }, 143 + [lm75b] = { 144 + .default_resolution = 11, 145 + .default_sample_time = MSEC_PER_SEC / 10, 146 + }, 147 + [max6625] = { 148 + .default_resolution = 9, 149 + .default_sample_time = MSEC_PER_SEC / 7, 150 + }, 151 + [max6626] = { 152 + .default_resolution = 12, 153 + .default_sample_time = MSEC_PER_SEC / 7, 154 + .resolution_limits = 9, 155 + }, 156 + [max31725] = { 157 + .default_resolution = 16, 158 + .default_sample_time = MSEC_PER_SEC / 20, 159 + }, 160 + [tcn75] = { 161 + .default_resolution = 9, 162 + .default_sample_time = MSEC_PER_SEC / 18, 163 + }, 164 + [pct2075] = { 165 + .default_resolution = 11, 166 + .default_sample_time = MSEC_PER_SEC / 10, 167 + .num_sample_times = 31, 168 + .sample_times = (unsigned int []){ 100, 200, 300, 400, 500, 600, 169 + 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 170 + 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 171 + 2800, 2900, 3000, 3100 }, 172 + }, 173 + [mcp980x] = { 174 + .set_mask = 3 << 5, /* 12-bit mode */ 175 + .clr_mask = 1 << 7, /* not one-shot mode */ 176 + .default_resolution = 12, 177 + .resolution_limits = 9, 178 + .default_sample_time = 240, 179 + .num_sample_times = 4, 180 + .sample_times = (unsigned int []){ 30, 60, 120, 240 }, 181 + .resolutions = (u8 []) {9, 10, 11, 12 }, 182 + }, 183 + [tmp100] = { 184 + .set_mask = 3 << 5, /* 12-bit mode */ 185 + .clr_mask = 1 << 7, /* not one-shot mode */ 186 + .default_resolution = 12, 187 + .default_sample_time = 320, 188 + .num_sample_times = 4, 189 + .sample_times = (unsigned int []){ 40, 80, 160, 320 }, 190 + .resolutions = (u8 []) {9, 10, 11, 12 }, 191 + }, 192 + [tmp101] = { 193 + .set_mask = 3 << 5, /* 12-bit mode */ 194 + .clr_mask = 1 << 7, /* not one-shot mode */ 195 + .default_resolution = 12, 196 + .default_sample_time = 320, 197 + .num_sample_times = 4, 198 + .sample_times = (unsigned int []){ 40, 80, 160, 320 }, 199 + .resolutions = (u8 []) {9, 10, 11, 12 }, 200 + }, 201 + [tmp105] = { 202 + .set_mask = 3 << 5, /* 12-bit mode */ 203 + .clr_mask = 1 << 7, /* not one-shot mode*/ 204 + .default_resolution = 12, 205 + .default_sample_time = 220, 206 + .num_sample_times = 4, 207 + .sample_times = (unsigned int []){ 28, 55, 110, 220 }, 208 + .resolutions = (u8 []) {9, 10, 11, 12 }, 209 + }, 210 + [tmp112] = { 211 + .set_mask = 3 << 5, /* 8 samples / second */ 212 + .clr_mask = 1 << 7, /* no one-shot mode*/ 213 + .default_resolution = 12, 214 + .default_sample_time = 125, 215 + .num_sample_times = 4, 216 + .sample_times = (unsigned int []){ 125, 250, 1000, 4000 }, 217 + }, 218 + [tmp175] = { 219 + .set_mask = 3 << 5, /* 12-bit mode */ 220 + .clr_mask = 1 << 7, /* not one-shot mode*/ 221 + .default_resolution = 12, 222 + .default_sample_time = 220, 223 + .num_sample_times = 4, 224 + .sample_times = (unsigned int []){ 28, 55, 110, 220 }, 225 + .resolutions = (u8 []) {9, 10, 11, 12 }, 226 + }, 227 + [tmp275] = { 228 + .set_mask = 3 << 5, /* 12-bit mode */ 229 + .clr_mask = 1 << 7, /* not one-shot mode*/ 230 + .default_resolution = 12, 231 + .default_sample_time = 220, 232 + .num_sample_times = 4, 233 + .sample_times = (unsigned int []){ 28, 55, 110, 220 }, 234 + .resolutions = (u8 []) {9, 10, 11, 12 }, 235 + }, 236 + [tmp75] = { 237 + .set_mask = 3 << 5, /* 12-bit mode */ 238 + .clr_mask = 1 << 7, /* not one-shot mode*/ 239 + .default_resolution = 12, 240 + .default_sample_time = 220, 241 + .num_sample_times = 4, 242 + .sample_times = (unsigned int []){ 28, 55, 110, 220 }, 243 + .resolutions = (u8 []) {9, 10, 11, 12 }, 244 + }, 245 + [tmp75b] = { /* not one-shot mode, Conversion rate 37Hz */ 246 + .clr_mask = 1 << 7 | 3 << 5, 247 + .default_resolution = 12, 248 + .default_sample_time = MSEC_PER_SEC / 37, 249 + .sample_times = (unsigned int []){ MSEC_PER_SEC / 37, 250 + MSEC_PER_SEC / 18, 251 + MSEC_PER_SEC / 9, MSEC_PER_SEC / 4 }, 252 + .num_sample_times = 4, 253 + }, 254 + [tmp75c] = { 255 + .clr_mask = 1 << 5, /*not one-shot mode*/ 256 + .default_resolution = 12, 257 + .default_sample_time = MSEC_PER_SEC / 12, 258 + } 259 + }; 260 + 111 261 static inline long lm75_reg_to_mc(s16 temp, u8 resolution) 112 262 { 113 263 return ((temp >> (16 - resolution)) * 1000) >> (resolution - 8); 264 + } 265 + 266 + static int lm75_write_config(struct lm75_data *data, u8 set_mask, 267 + u8 clr_mask) 268 + { 269 + u8 value; 270 + 271 + clr_mask |= LM75_SHUTDOWN; 272 + value = data->current_conf & ~clr_mask; 273 + value |= set_mask; 274 + 275 + if (data->current_conf != value) { 276 + s32 err; 277 + 278 + err = i2c_smbus_write_byte_data(data->client, LM75_REG_CONF, 279 + value); 280 + if (err) 281 + return err; 282 + data->current_conf = value; 283 + } 284 + return 0; 114 285 } 115 286 116 287 static int lm75_read(struct device *dev, enum hwmon_sensor_types type, ··· 363 120 return 0; 364 121 } 365 122 366 - static int lm75_write(struct device *dev, enum hwmon_sensor_types type, 367 - u32 attr, int channel, long temp) 123 + static int lm75_write_temp(struct device *dev, u32 attr, long temp) 368 124 { 369 125 struct lm75_data *data = dev_get_drvdata(dev); 370 126 u8 resolution; 371 127 int reg; 372 - 373 - if (type != hwmon_temp) 374 - return -EINVAL; 375 128 376 129 switch (attr) { 377 130 case hwmon_temp_max: ··· 384 145 * Resolution of limit registers is assumed to be the same as the 385 146 * temperature input register resolution unless given explicitly. 386 147 */ 387 - if (data->resolution_limits) 388 - resolution = data->resolution_limits; 148 + if (data->params->resolution_limits) 149 + resolution = data->params->resolution_limits; 389 150 else 390 151 resolution = data->resolution; 391 152 ··· 393 154 temp = DIV_ROUND_CLOSEST(temp << (resolution - 8), 394 155 1000) << (16 - resolution); 395 156 396 - return regmap_write(data->regmap, reg, temp); 157 + return regmap_write(data->regmap, reg, (u16)temp); 158 + } 159 + 160 + static int lm75_update_interval(struct device *dev, long val) 161 + { 162 + struct lm75_data *data = dev_get_drvdata(dev); 163 + unsigned int reg; 164 + u8 index; 165 + s32 err; 166 + 167 + index = find_closest(val, data->params->sample_times, 168 + (int)data->params->num_sample_times); 169 + 170 + switch (data->kind) { 171 + default: 172 + err = lm75_write_config(data, lm75_sample_set_masks[index], 173 + LM75_SAMPLE_CLEAR_MASK); 174 + if (err) 175 + return err; 176 + 177 + data->sample_time = data->params->sample_times[index]; 178 + if (data->params->resolutions) 179 + data->resolution = data->params->resolutions[index]; 180 + break; 181 + case tmp112: 182 + err = regmap_read(data->regmap, LM75_REG_CONF, &reg); 183 + if (err < 0) 184 + return err; 185 + reg &= ~0x00c0; 186 + reg |= (3 - index) << 6; 187 + err = regmap_write(data->regmap, LM75_REG_CONF, reg); 188 + if (err < 0) 189 + return err; 190 + data->sample_time = data->params->sample_times[index]; 191 + break; 192 + case pct2075: 193 + err = i2c_smbus_write_byte_data(data->client, PCT2075_REG_IDLE, 194 + index + 1); 195 + if (err) 196 + return err; 197 + data->sample_time = data->params->sample_times[index]; 198 + break; 199 + } 200 + return 0; 201 + } 202 + 203 + static int lm75_write_chip(struct device *dev, u32 attr, long val) 204 + { 205 + switch (attr) { 206 + case hwmon_chip_update_interval: 207 + return lm75_update_interval(dev, val); 208 + default: 209 + return -EINVAL; 210 + } 211 + return 0; 212 + } 213 + 214 + static int lm75_write(struct device *dev, enum hwmon_sensor_types type, 215 + u32 attr, int channel, long val) 216 + { 217 + switch (type) { 218 + case hwmon_chip: 219 + return lm75_write_chip(dev, attr, val); 220 + case hwmon_temp: 221 + return lm75_write_temp(dev, attr, val); 222 + default: 223 + return -EINVAL; 224 + } 225 + return 0; 397 226 } 398 227 399 228 static umode_t lm75_is_visible(const void *data, enum hwmon_sensor_types type, 400 229 u32 attr, int channel) 401 230 { 231 + const struct lm75_data *config_data = data; 232 + 402 233 switch (type) { 403 234 case hwmon_chip: 404 235 switch (attr) { 405 236 case hwmon_chip_update_interval: 237 + if (config_data->params->num_sample_times > 1) 238 + return 0644; 406 239 return 0444; 407 240 } 408 241 break; ··· 519 208 520 209 static bool lm75_is_volatile_reg(struct device *dev, unsigned int reg) 521 210 { 522 - return reg == LM75_REG_TEMP; 211 + return reg == LM75_REG_TEMP || reg == LM75_REG_CONF; 523 212 } 524 213 525 214 static const struct regmap_config lm75_regmap_config = { 526 215 .reg_bits = 8, 527 216 .val_bits = 16, 528 - .max_register = LM75_REG_MAX, 217 + .max_register = PCT2075_REG_IDLE, 529 218 .writeable_reg = lm75_is_writeable_reg, 530 219 .volatile_reg = lm75_is_volatile_reg, 531 220 .val_format_endian = REGMAP_ENDIAN_BIG, ··· 549 238 struct device *hwmon_dev; 550 239 struct lm75_data *data; 551 240 int status, err; 552 - u8 set_mask, clr_mask; 553 - int new; 554 241 enum lm75_type kind; 555 242 556 243 if (client->dev.of_node) ··· 565 256 return -ENOMEM; 566 257 567 258 data->client = client; 259 + data->kind = kind; 568 260 569 261 data->regmap = devm_regmap_init_i2c(client, &lm75_regmap_config); 570 262 if (IS_ERR(data->regmap)) ··· 574 264 /* Set to LM75 resolution (9 bits, 1/2 degree C) and range. 575 265 * Then tweak to be more precise when appropriate. 576 266 */ 577 - set_mask = 0; 578 - clr_mask = LM75_SHUTDOWN; /* continuous conversions */ 579 267 580 - switch (kind) { 581 - case adt75: 582 - clr_mask |= 1 << 5; /* not one-shot mode */ 583 - data->resolution = 12; 584 - data->sample_time = MSEC_PER_SEC / 8; 585 - break; 586 - case ds1775: 587 - case ds75: 588 - case stds75: 589 - clr_mask |= 3 << 5; 590 - set_mask |= 2 << 5; /* 11-bit mode */ 591 - data->resolution = 11; 592 - data->sample_time = MSEC_PER_SEC; 593 - break; 594 - case stlm75: 595 - data->resolution = 9; 596 - data->sample_time = MSEC_PER_SEC / 5; 597 - break; 598 - case ds7505: 599 - set_mask |= 3 << 5; /* 12-bit mode */ 600 - data->resolution = 12; 601 - data->sample_time = MSEC_PER_SEC / 4; 602 - break; 603 - case g751: 604 - case lm75: 605 - case lm75a: 606 - data->resolution = 9; 607 - data->sample_time = MSEC_PER_SEC / 2; 608 - break; 609 - case lm75b: 610 - data->resolution = 11; 611 - data->sample_time = MSEC_PER_SEC / 4; 612 - break; 613 - case max6625: 614 - data->resolution = 9; 615 - data->sample_time = MSEC_PER_SEC / 4; 616 - break; 617 - case max6626: 618 - data->resolution = 12; 619 - data->resolution_limits = 9; 620 - data->sample_time = MSEC_PER_SEC / 4; 621 - break; 622 - case max31725: 623 - data->resolution = 16; 624 - data->sample_time = MSEC_PER_SEC / 8; 625 - break; 626 - case tcn75: 627 - data->resolution = 9; 628 - data->sample_time = MSEC_PER_SEC / 8; 629 - break; 630 - case mcp980x: 631 - data->resolution_limits = 9; 632 - /* fall through */ 633 - case tmp100: 634 - case tmp101: 635 - set_mask |= 3 << 5; /* 12-bit mode */ 636 - data->resolution = 12; 637 - data->sample_time = MSEC_PER_SEC; 638 - clr_mask |= 1 << 7; /* not one-shot mode */ 639 - break; 640 - case tmp112: 641 - set_mask |= 3 << 5; /* 12-bit mode */ 642 - clr_mask |= 1 << 7; /* not one-shot mode */ 643 - data->resolution = 12; 644 - data->sample_time = MSEC_PER_SEC / 4; 645 - break; 646 - case tmp105: 647 - case tmp175: 648 - case tmp275: 649 - case tmp75: 650 - set_mask |= 3 << 5; /* 12-bit mode */ 651 - clr_mask |= 1 << 7; /* not one-shot mode */ 652 - data->resolution = 12; 653 - data->sample_time = MSEC_PER_SEC / 2; 654 - break; 655 - case tmp75b: /* not one-shot mode, Conversion rate 37Hz */ 656 - clr_mask |= 1 << 7 | 0x3 << 5; 657 - data->resolution = 12; 658 - data->sample_time = MSEC_PER_SEC / 37; 659 - break; 660 - case tmp75c: 661 - clr_mask |= 1 << 5; /* not one-shot mode */ 662 - data->resolution = 12; 663 - data->sample_time = MSEC_PER_SEC / 4; 664 - break; 665 - } 268 + data->params = &device_params[data->kind]; 666 269 667 - /* configure as specified */ 270 + /* Save default sample time and resolution*/ 271 + data->sample_time = data->params->default_sample_time; 272 + data->resolution = data->params->default_resolution; 273 + 274 + /* Cache original configuration */ 668 275 status = i2c_smbus_read_byte_data(client, LM75_REG_CONF); 669 276 if (status < 0) { 670 277 dev_dbg(dev, "Can't read config? %d\n", status); 671 278 return status; 672 279 } 673 280 data->orig_conf = status; 674 - new = status & ~clr_mask; 675 - new |= set_mask; 676 - if (status != new) 677 - i2c_smbus_write_byte_data(client, LM75_REG_CONF, new); 281 + data->current_conf = status; 282 + 283 + err = lm75_write_config(data, data->params->set_mask, 284 + data->params->clr_mask); 285 + if (err) 286 + return err; 678 287 679 288 err = devm_add_action_or_reset(dev, lm75_remove, data); 680 289 if (err) 681 290 return err; 682 - 683 - dev_dbg(dev, "Config %02x\n", new); 684 291 685 292 hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, 686 293 data, &lm75_chip_info, ··· 624 397 { "max31725", max31725, }, 625 398 { "max31726", max31725, }, 626 399 { "mcp980x", mcp980x, }, 400 + { "pct2075", pct2075, }, 627 401 { "stds75", stds75, }, 628 402 { "stlm75", stlm75, }, 629 403 { "tcn75", tcn75, }, ··· 693 465 { 694 466 .compatible = "maxim,mcp980x", 695 467 .data = (void *)mcp980x 468 + }, 469 + { 470 + .compatible = "nxp,pct2075", 471 + .data = (void *)pct2075 696 472 }, 697 473 { 698 474 .compatible = "st,stds75",
+5 -5
drivers/hwmon/ltc2990.c
··· 13 13 #include <linux/i2c.h> 14 14 #include <linux/kernel.h> 15 15 #include <linux/module.h> 16 - #include <linux/of.h> 16 + #include <linux/property.h> 17 17 18 18 #define LTC2990_STATUS 0x00 19 19 #define LTC2990_CONTROL 0x01 ··· 206 206 int ret; 207 207 struct device *hwmon_dev; 208 208 struct ltc2990_data *data; 209 - struct device_node *of_node = i2c->dev.of_node; 210 209 211 210 if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA | 212 211 I2C_FUNC_SMBUS_WORD_DATA)) ··· 217 218 218 219 data->i2c = i2c; 219 220 220 - if (of_node) { 221 - ret = of_property_read_u32_array(of_node, "lltc,meas-mode", 222 - data->mode, 2); 221 + if (dev_fwnode(&i2c->dev)) { 222 + ret = device_property_read_u32_array(&i2c->dev, 223 + "lltc,meas-mode", 224 + data->mode, 2); 223 225 if (ret < 0) 224 226 return ret; 225 227
+174 -6
drivers/hwmon/nct6775.c
··· 20 20 * 21 21 * Chip #vin #fan #pwm #temp chip IDs man ID 22 22 * nct6106d 9 3 3 6+3 0xc450 0xc1 0x5ca3 23 + * nct6116d 9 5 5 3+3 0xd280 0xc1 0x5ca3 23 24 * nct6775f 9 4 3 6+3 0xb470 0xc1 0x5ca3 24 25 * nct6776f 9 5 3 6+3 0xc330 0xc1 0x5ca3 25 26 * nct6779d 15 5 5 2+6 0xc560 0xc1 0x5ca3 ··· 59 58 60 59 #define USE_ALTERNATE 61 60 62 - enum kinds { nct6106, nct6775, nct6776, nct6779, nct6791, nct6792, nct6793, 63 - nct6795, nct6796, nct6797, nct6798 }; 61 + enum kinds { nct6106, nct6116, nct6775, nct6776, nct6779, nct6791, nct6792, 62 + nct6793, nct6795, nct6796, nct6797, nct6798 }; 64 63 65 64 /* used to set data->name = nct6775_device_names[data->sio_kind] */ 66 65 static const char * const nct6775_device_names[] = { 67 66 "nct6106", 67 + "nct6116", 68 68 "nct6775", 69 69 "nct6776", 70 70 "nct6779", ··· 80 78 81 79 static const char * const nct6775_sio_names[] __initconst = { 82 80 "NCT6106D", 81 + "NCT6116D", 83 82 "NCT6775F", 84 83 "NCT6776D/F", 85 84 "NCT6779D", ··· 118 115 #define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */ 119 116 120 117 #define SIO_NCT6106_ID 0xc450 118 + #define SIO_NCT6116_ID 0xd280 121 119 #define SIO_NCT6775_ID 0xb470 122 120 #define SIO_NCT6776_ID 0xc330 123 121 #define SIO_NCT6779_ID 0xc560 ··· 829 825 830 826 static const u8 NCT6106_REG_PWM_MODE[] = { 0xf3, 0xf3, 0xf3 }; 831 827 static const u8 NCT6106_PWM_MODE_MASK[] = { 0x01, 0x02, 0x04 }; 832 - static const u16 NCT6106_REG_PWM[] = { 0x119, 0x129, 0x139 }; 833 828 static const u16 NCT6106_REG_PWM_READ[] = { 0x4a, 0x4b, 0x4c }; 834 829 static const u16 NCT6106_REG_FAN_MODE[] = { 0x113, 0x123, 0x133 }; 835 - static const u16 NCT6106_REG_TEMP_SEL[] = { 0x110, 0x120, 0x130 }; 836 830 static const u16 NCT6106_REG_TEMP_SOURCE[] = { 837 831 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5 }; 838 832 ··· 896 894 static const u16 NCT6106_REG_TEMP_CRIT[32] = { 897 895 [11] = 0x204, 898 896 [12] = 0x205, 897 + }; 898 + 899 + /* NCT6112D/NCT6114D/NCT6116D specific data */ 900 + 901 + static const u16 NCT6116_REG_FAN[] = { 0x20, 0x22, 0x24, 0x26, 0x28 }; 902 + static const u16 NCT6116_REG_FAN_MIN[] = { 0xe0, 0xe2, 0xe4, 0xe6, 0xe8 }; 903 + static const u16 NCT6116_REG_FAN_PULSES[] = { 0xf6, 0xf6, 0xf6, 0xf6, 0xf5 }; 904 + static const u16 NCT6116_FAN_PULSE_SHIFT[] = { 0, 2, 4, 6, 6 }; 905 + 906 + static const u16 NCT6116_REG_PWM[] = { 0x119, 0x129, 0x139, 0x199, 0x1a9 }; 907 + static const u16 NCT6116_REG_FAN_MODE[] = { 0x113, 0x123, 0x133, 0x193, 0x1a3 }; 908 + static const u16 NCT6116_REG_TEMP_SEL[] = { 0x110, 0x120, 0x130, 0x190, 0x1a0 }; 909 + static const u16 NCT6116_REG_TEMP_SOURCE[] = { 910 + 0xb0, 0xb1, 0xb2 }; 911 + 912 + static const u16 NCT6116_REG_CRITICAL_TEMP[] = { 913 + 0x11a, 0x12a, 0x13a, 0x19a, 0x1aa }; 914 + static const u16 NCT6116_REG_CRITICAL_TEMP_TOLERANCE[] = { 915 + 0x11b, 0x12b, 0x13b, 0x19b, 0x1ab }; 916 + 917 + static const u16 NCT6116_REG_CRITICAL_PWM_ENABLE[] = { 918 + 0x11c, 0x12c, 0x13c, 0x19c, 0x1ac }; 919 + static const u16 NCT6116_REG_CRITICAL_PWM[] = { 920 + 0x11d, 0x12d, 0x13d, 0x19d, 0x1ad }; 921 + 922 + static const u16 NCT6116_REG_FAN_STEP_UP_TIME[] = { 923 + 0x114, 0x124, 0x134, 0x194, 0x1a4 }; 924 + static const u16 NCT6116_REG_FAN_STEP_DOWN_TIME[] = { 925 + 0x115, 0x125, 0x135, 0x195, 0x1a5 }; 926 + static const u16 NCT6116_REG_FAN_STOP_OUTPUT[] = { 927 + 0x116, 0x126, 0x136, 0x196, 0x1a6 }; 928 + static const u16 NCT6116_REG_FAN_START_OUTPUT[] = { 929 + 0x117, 0x127, 0x137, 0x197, 0x1a7 }; 930 + static const u16 NCT6116_REG_FAN_STOP_TIME[] = { 931 + 0x118, 0x128, 0x138, 0x198, 0x1a8 }; 932 + static const u16 NCT6116_REG_TOLERANCE_H[] = { 933 + 0x112, 0x122, 0x132, 0x192, 0x1a2 }; 934 + 935 + static const u16 NCT6116_REG_TARGET[] = { 936 + 0x111, 0x121, 0x131, 0x191, 0x1a1 }; 937 + 938 + static const u16 NCT6116_REG_AUTO_TEMP[] = { 939 + 0x160, 0x170, 0x180, 0x1d0, 0x1e0 }; 940 + static const u16 NCT6116_REG_AUTO_PWM[] = { 941 + 0x164, 0x174, 0x184, 0x1d4, 0x1e4 }; 942 + 943 + static const s8 NCT6116_ALARM_BITS[] = { 944 + 0, 1, 2, 3, 4, 5, 7, 8, /* in0.. in7 */ 945 + 9, -1, -1, -1, -1, -1, -1, /* in8..in9 */ 946 + -1, /* unused */ 947 + 32, 33, 34, 35, 36, /* fan1..fan5 */ 948 + -1, -1, -1, /* unused */ 949 + 16, 17, 18, -1, -1, -1, /* temp1..temp6 */ 950 + 48, -1 /* intrusion0, intrusion1 */ 951 + }; 952 + 953 + static const s8 NCT6116_BEEP_BITS[] = { 954 + 0, 1, 2, 3, 4, 5, 7, 8, /* in0.. in7 */ 955 + 9, 10, 11, 12, -1, -1, -1, /* in8..in14 */ 956 + 32, /* global beep enable */ 957 + 24, 25, 26, 27, 28, /* fan1..fan5 */ 958 + -1, -1, -1, /* unused */ 959 + 16, 17, 18, -1, -1, -1, /* temp1..temp6 */ 960 + 34, -1 /* intrusion0, intrusion1 */ 899 961 }; 900 962 901 963 static enum pwm_enable reg_to_pwm_enable(int pwm, int mode) ··· 1360 1294 return reg == 0x20 || reg == 0x22 || reg == 0x24 || 1361 1295 reg == 0xe0 || reg == 0xe2 || reg == 0xe4 || 1362 1296 reg == 0x111 || reg == 0x121 || reg == 0x131; 1297 + case nct6116: 1298 + return reg == 0x20 || reg == 0x22 || reg == 0x24 || 1299 + reg == 0x26 || reg == 0x28 || reg == 0xe0 || reg == 0xe2 || 1300 + reg == 0xe4 || reg == 0xe6 || reg == 0xe8 || reg == 0x111 || 1301 + reg == 0x121 || reg == 0x131 || reg == 0x191 || reg == 0x1a1; 1363 1302 case nct6775: 1364 1303 return (((reg & 0xff00) == 0x100 || 1365 1304 (reg & 0xff00) == 0x200) && ··· 1744 1673 data->auto_pwm[i][data->auto_pwm_num] = 0xff; 1745 1674 break; 1746 1675 case nct6106: 1676 + case nct6116: 1747 1677 case nct6779: 1748 1678 case nct6791: 1749 1679 case nct6792: ··· 3181 3109 case nct6776: 3182 3110 break; /* always enabled, nothing to do */ 3183 3111 case nct6106: 3112 + case nct6116: 3184 3113 case nct6779: 3185 3114 case nct6791: 3186 3115 case nct6792: ··· 3608 3535 3609 3536 fan3pin = !(cr24 & 0x80); 3610 3537 pwm3pin = cr24 & 0x08; 3538 + } else if (data->kind == nct6116) { 3539 + int cr1a = superio_inb(sioreg, 0x1a); 3540 + int cr1b = superio_inb(sioreg, 0x1b); 3541 + int cr24 = superio_inb(sioreg, 0x24); 3542 + int cr2a = superio_inb(sioreg, 0x2a); 3543 + int cr2b = superio_inb(sioreg, 0x2b); 3544 + int cr2f = superio_inb(sioreg, 0x2f); 3545 + 3546 + fan3pin = !(cr2b & 0x10); 3547 + fan4pin = (cr2b & 0x80) || // pin 1(2) 3548 + (!(cr2f & 0x10) && (cr1a & 0x04)); // pin 65(66) 3549 + fan5pin = (cr2b & 0x80) || // pin 126(127) 3550 + (!(cr1b & 0x03) && (cr2a & 0x02)); // pin 94(96) 3551 + 3552 + pwm3pin = fan3pin && (cr24 & 0x08); 3553 + pwm4pin = fan4pin; 3554 + pwm5pin = fan5pin; 3611 3555 } else { 3612 3556 /* 3613 3557 * NCT6779D, NCT6791D, NCT6792D, NCT6793D, NCT6795D, NCT6796D, ··· 3855 3765 data->REG_FAN_TIME[1] = NCT6106_REG_FAN_STEP_UP_TIME; 3856 3766 data->REG_FAN_TIME[2] = NCT6106_REG_FAN_STEP_DOWN_TIME; 3857 3767 data->REG_TOLERANCE_H = NCT6106_REG_TOLERANCE_H; 3858 - data->REG_PWM[0] = NCT6106_REG_PWM; 3768 + data->REG_PWM[0] = NCT6116_REG_PWM; 3859 3769 data->REG_PWM[1] = NCT6106_REG_FAN_START_OUTPUT; 3860 3770 data->REG_PWM[2] = NCT6106_REG_FAN_STOP_OUTPUT; 3861 3771 data->REG_PWM[5] = NCT6106_REG_WEIGHT_DUTY_STEP; ··· 3874 3784 data->REG_CRITICAL_PWM = NCT6106_REG_CRITICAL_PWM; 3875 3785 data->REG_TEMP_OFFSET = NCT6106_REG_TEMP_OFFSET; 3876 3786 data->REG_TEMP_SOURCE = NCT6106_REG_TEMP_SOURCE; 3877 - data->REG_TEMP_SEL = NCT6106_REG_TEMP_SEL; 3787 + data->REG_TEMP_SEL = NCT6116_REG_TEMP_SEL; 3878 3788 data->REG_WEIGHT_TEMP_SEL = NCT6106_REG_WEIGHT_TEMP_SEL; 3879 3789 data->REG_WEIGHT_TEMP[0] = NCT6106_REG_WEIGHT_TEMP_STEP; 3880 3790 data->REG_WEIGHT_TEMP[1] = NCT6106_REG_WEIGHT_TEMP_STEP_TOL; ··· 3883 3793 data->ALARM_BITS = NCT6106_ALARM_BITS; 3884 3794 data->REG_BEEP = NCT6106_REG_BEEP; 3885 3795 data->BEEP_BITS = NCT6106_BEEP_BITS; 3796 + 3797 + reg_temp = NCT6106_REG_TEMP; 3798 + reg_temp_mon = NCT6106_REG_TEMP_MON; 3799 + num_reg_temp = ARRAY_SIZE(NCT6106_REG_TEMP); 3800 + num_reg_temp_mon = ARRAY_SIZE(NCT6106_REG_TEMP_MON); 3801 + reg_temp_over = NCT6106_REG_TEMP_OVER; 3802 + reg_temp_hyst = NCT6106_REG_TEMP_HYST; 3803 + reg_temp_config = NCT6106_REG_TEMP_CONFIG; 3804 + reg_temp_alternate = NCT6106_REG_TEMP_ALTERNATE; 3805 + reg_temp_crit = NCT6106_REG_TEMP_CRIT; 3806 + reg_temp_crit_l = NCT6106_REG_TEMP_CRIT_L; 3807 + reg_temp_crit_h = NCT6106_REG_TEMP_CRIT_H; 3808 + 3809 + break; 3810 + case nct6116: 3811 + data->in_num = 9; 3812 + data->pwm_num = 3; 3813 + data->auto_pwm_num = 4; 3814 + data->temp_fixed_num = 3; 3815 + data->num_temp_alarms = 3; 3816 + data->num_temp_beeps = 3; 3817 + 3818 + data->fan_from_reg = fan_from_reg13; 3819 + data->fan_from_reg_min = fan_from_reg13; 3820 + 3821 + data->temp_label = nct6776_temp_label; 3822 + data->temp_mask = NCT6776_TEMP_MASK; 3823 + data->virt_temp_mask = NCT6776_VIRT_TEMP_MASK; 3824 + 3825 + data->REG_VBAT = NCT6106_REG_VBAT; 3826 + data->REG_DIODE = NCT6106_REG_DIODE; 3827 + data->DIODE_MASK = NCT6106_DIODE_MASK; 3828 + data->REG_VIN = NCT6106_REG_IN; 3829 + data->REG_IN_MINMAX[0] = NCT6106_REG_IN_MIN; 3830 + data->REG_IN_MINMAX[1] = NCT6106_REG_IN_MAX; 3831 + data->REG_TARGET = NCT6116_REG_TARGET; 3832 + data->REG_FAN = NCT6116_REG_FAN; 3833 + data->REG_FAN_MODE = NCT6116_REG_FAN_MODE; 3834 + data->REG_FAN_MIN = NCT6116_REG_FAN_MIN; 3835 + data->REG_FAN_PULSES = NCT6116_REG_FAN_PULSES; 3836 + data->FAN_PULSE_SHIFT = NCT6116_FAN_PULSE_SHIFT; 3837 + data->REG_FAN_TIME[0] = NCT6116_REG_FAN_STOP_TIME; 3838 + data->REG_FAN_TIME[1] = NCT6116_REG_FAN_STEP_UP_TIME; 3839 + data->REG_FAN_TIME[2] = NCT6116_REG_FAN_STEP_DOWN_TIME; 3840 + data->REG_TOLERANCE_H = NCT6116_REG_TOLERANCE_H; 3841 + data->REG_PWM[0] = NCT6116_REG_PWM; 3842 + data->REG_PWM[1] = NCT6116_REG_FAN_START_OUTPUT; 3843 + data->REG_PWM[2] = NCT6116_REG_FAN_STOP_OUTPUT; 3844 + data->REG_PWM[5] = NCT6106_REG_WEIGHT_DUTY_STEP; 3845 + data->REG_PWM[6] = NCT6106_REG_WEIGHT_DUTY_BASE; 3846 + data->REG_PWM_READ = NCT6106_REG_PWM_READ; 3847 + data->REG_PWM_MODE = NCT6106_REG_PWM_MODE; 3848 + data->PWM_MODE_MASK = NCT6106_PWM_MODE_MASK; 3849 + data->REG_AUTO_TEMP = NCT6116_REG_AUTO_TEMP; 3850 + data->REG_AUTO_PWM = NCT6116_REG_AUTO_PWM; 3851 + data->REG_CRITICAL_TEMP = NCT6116_REG_CRITICAL_TEMP; 3852 + data->REG_CRITICAL_TEMP_TOLERANCE 3853 + = NCT6116_REG_CRITICAL_TEMP_TOLERANCE; 3854 + data->REG_CRITICAL_PWM_ENABLE = NCT6116_REG_CRITICAL_PWM_ENABLE; 3855 + data->CRITICAL_PWM_ENABLE_MASK 3856 + = NCT6106_CRITICAL_PWM_ENABLE_MASK; 3857 + data->REG_CRITICAL_PWM = NCT6116_REG_CRITICAL_PWM; 3858 + data->REG_TEMP_OFFSET = NCT6106_REG_TEMP_OFFSET; 3859 + data->REG_TEMP_SOURCE = NCT6116_REG_TEMP_SOURCE; 3860 + data->REG_TEMP_SEL = NCT6116_REG_TEMP_SEL; 3861 + data->REG_WEIGHT_TEMP_SEL = NCT6106_REG_WEIGHT_TEMP_SEL; 3862 + data->REG_WEIGHT_TEMP[0] = NCT6106_REG_WEIGHT_TEMP_STEP; 3863 + data->REG_WEIGHT_TEMP[1] = NCT6106_REG_WEIGHT_TEMP_STEP_TOL; 3864 + data->REG_WEIGHT_TEMP[2] = NCT6106_REG_WEIGHT_TEMP_BASE; 3865 + data->REG_ALARM = NCT6106_REG_ALARM; 3866 + data->ALARM_BITS = NCT6116_ALARM_BITS; 3867 + data->REG_BEEP = NCT6106_REG_BEEP; 3868 + data->BEEP_BITS = NCT6116_BEEP_BITS; 3886 3869 3887 3870 reg_temp = NCT6106_REG_TEMP; 3888 3871 reg_temp_mon = NCT6106_REG_TEMP_MON; ··· 4515 4352 data->have_vid = (cr2a & 0x60) == 0x40; 4516 4353 break; 4517 4354 case nct6106: 4355 + case nct6116: 4518 4356 case nct6779: 4519 4357 case nct6791: 4520 4358 case nct6792: ··· 4545 4381 NCT6775_REG_CR_FAN_DEBOUNCE); 4546 4382 switch (data->kind) { 4547 4383 case nct6106: 4384 + case nct6116: 4548 4385 tmp |= 0xe0; 4549 4386 break; 4550 4387 case nct6775: ··· 4740 4575 switch (val & SIO_ID_MASK) { 4741 4576 case SIO_NCT6106_ID: 4742 4577 sio_data->kind = nct6106; 4578 + break; 4579 + case SIO_NCT6116_ID: 4580 + sio_data->kind = nct6116; 4743 4581 break; 4744 4582 case SIO_NCT6775_ID: 4745 4583 sio_data->kind = nct6775;
+431 -45
drivers/hwmon/nct7904.c
··· 46 46 #define DTS_T_CTRL1_REG 0x27 47 47 #define VT_ADC_MD_REG 0x2E 48 48 49 + #define VSEN1_HV_LL_REG 0x02 /* Bank 1; 2 regs (HV/LV) per sensor */ 50 + #define VSEN1_LV_LL_REG 0x03 /* Bank 1; 2 regs (HV/LV) per sensor */ 51 + #define VSEN1_HV_HL_REG 0x00 /* Bank 1; 2 regs (HV/LV) per sensor */ 52 + #define VSEN1_LV_HL_REG 0x01 /* Bank 1; 2 regs (HV/LV) per sensor */ 53 + #define SMI_STS1_REG 0xC1 /* Bank 0; SMI Status Register */ 54 + #define SMI_STS3_REG 0xC3 /* Bank 0; SMI Status Register */ 55 + #define SMI_STS5_REG 0xC5 /* Bank 0; SMI Status Register */ 56 + #define SMI_STS7_REG 0xC7 /* Bank 0; SMI Status Register */ 57 + #define SMI_STS8_REG 0xC8 /* Bank 0; SMI Status Register */ 58 + 49 59 #define VSEN1_HV_REG 0x40 /* Bank 0; 2 regs (HV/LV) per sensor */ 50 60 #define TEMP_CH1_HV_REG 0x42 /* Bank 0; same as VSEN2_HV */ 51 61 #define LTD_HV_REG 0x62 /* Bank 0; 2 regs in VSEN range */ 62 + #define LTD_HV_HL_REG 0x44 /* Bank 1; 1 reg for LTD */ 63 + #define LTD_LV_HL_REG 0x45 /* Bank 1; 1 reg for LTD */ 64 + #define LTD_HV_LL_REG 0x46 /* Bank 1; 1 reg for LTD */ 65 + #define LTD_LV_LL_REG 0x47 /* Bank 1; 1 reg for LTD */ 66 + #define TEMP_CH1_CH_REG 0x05 /* Bank 1; 1 reg for LTD */ 67 + #define TEMP_CH1_W_REG 0x06 /* Bank 1; 1 reg for LTD */ 68 + #define TEMP_CH1_WH_REG 0x07 /* Bank 1; 1 reg for LTD */ 69 + #define TEMP_CH1_C_REG 0x04 /* Bank 1; 1 reg per sensor */ 70 + #define DTS_T_CPU1_C_REG 0x90 /* Bank 1; 1 reg per sensor */ 71 + #define DTS_T_CPU1_CH_REG 0x91 /* Bank 1; 1 reg per sensor */ 72 + #define DTS_T_CPU1_W_REG 0x92 /* Bank 1; 1 reg per sensor */ 73 + #define DTS_T_CPU1_WH_REG 0x93 /* Bank 1; 1 reg per sensor */ 52 74 #define FANIN1_HV_REG 0x80 /* Bank 0; 2 regs (HV/LV) per sensor */ 75 + #define FANIN1_HV_HL_REG 0x60 /* Bank 1; 2 regs (HV/LV) per sensor */ 76 + #define FANIN1_LV_HL_REG 0x61 /* Bank 1; 2 regs (HV/LV) per sensor */ 53 77 #define T_CPU1_HV_REG 0xA0 /* Bank 0; 2 regs (HV/LV) per sensor */ 54 78 55 79 #define PRTS_REG 0x03 /* Bank 2 */ ··· 81 57 #define TSI_CTRL_REG 0x50 /* Bank 2; TSI Control Register */ 82 58 #define FANCTL1_FMR_REG 0x00 /* Bank 3; 1 reg per channel */ 83 59 #define FANCTL1_OUT_REG 0x10 /* Bank 3; 1 reg per channel */ 60 + 61 + #define ENABLE_TSI BIT(1) 84 62 85 63 static const unsigned short normal_i2c[] = { 86 64 0x2d, 0x2e, I2C_CLIENT_END ··· 98 72 u8 fan_mode[FANCTL_MAX]; 99 73 u8 enable_dts; 100 74 u8 has_dts; 75 + u8 temp_mode; /* 0: TR mode, 1: TD mode */ 101 76 }; 102 77 103 78 /* Access functions */ ··· 197 170 rpm = 1350000 / cnt; 198 171 *val = rpm; 199 172 return 0; 173 + case hwmon_fan_min: 174 + ret = nct7904_read_reg16(data, BANK_1, 175 + FANIN1_HV_HL_REG + channel * 2); 176 + if (ret < 0) 177 + return ret; 178 + cnt = ((ret & 0xff00) >> 3) | (ret & 0x1f); 179 + if (cnt == 0x1fff) 180 + rpm = 0; 181 + else 182 + rpm = 1350000 / cnt; 183 + *val = rpm; 184 + return 0; 185 + case hwmon_fan_alarm: 186 + ret = nct7904_read_reg(data, BANK_0, 187 + SMI_STS5_REG + (channel >> 3)); 188 + if (ret < 0) 189 + return ret; 190 + *val = (ret >> (channel & 0x07)) & 1; 191 + return 0; 200 192 default: 201 193 return -EOPNOTSUPP; 202 194 } ··· 225 179 { 226 180 const struct nct7904_data *data = _data; 227 181 228 - if (attr == hwmon_fan_input && data->fanin_mask & (1 << channel)) 229 - return 0444; 182 + switch (attr) { 183 + case hwmon_fan_input: 184 + case hwmon_fan_alarm: 185 + if (data->fanin_mask & (1 << channel)) 186 + return 0444; 187 + break; 188 + case hwmon_fan_min: 189 + if (data->fanin_mask & (1 << channel)) 190 + return 0644; 191 + break; 192 + default: 193 + break; 194 + } 195 + 230 196 return 0; 231 197 } 232 198 ··· 269 211 volt *= 6; /* 0.006V scale */ 270 212 *val = volt; 271 213 return 0; 214 + case hwmon_in_min: 215 + ret = nct7904_read_reg16(data, BANK_1, 216 + VSEN1_HV_LL_REG + index * 4); 217 + if (ret < 0) 218 + return ret; 219 + volt = ((ret & 0xff00) >> 5) | (ret & 0x7); 220 + if (index < 14) 221 + volt *= 2; /* 0.002V scale */ 222 + else 223 + volt *= 6; /* 0.006V scale */ 224 + *val = volt; 225 + return 0; 226 + case hwmon_in_max: 227 + ret = nct7904_read_reg16(data, BANK_1, 228 + VSEN1_HV_HL_REG + index * 4); 229 + if (ret < 0) 230 + return ret; 231 + volt = ((ret & 0xff00) >> 5) | (ret & 0x7); 232 + if (index < 14) 233 + volt *= 2; /* 0.002V scale */ 234 + else 235 + volt *= 6; /* 0.006V scale */ 236 + *val = volt; 237 + return 0; 238 + case hwmon_in_alarm: 239 + ret = nct7904_read_reg(data, BANK_0, 240 + SMI_STS1_REG + (index >> 3)); 241 + if (ret < 0) 242 + return ret; 243 + *val = (ret >> (index & 0x07)) & 1; 244 + return 0; 272 245 default: 273 246 return -EOPNOTSUPP; 274 247 } ··· 310 221 const struct nct7904_data *data = _data; 311 222 int index = nct7904_chan_to_index[channel]; 312 223 313 - if (channel > 0 && attr == hwmon_in_input && 314 - (data->vsen_mask & BIT(index))) 315 - return 0444; 224 + switch (attr) { 225 + case hwmon_in_input: 226 + case hwmon_in_alarm: 227 + if (channel > 0 && (data->vsen_mask & BIT(index))) 228 + return 0444; 229 + break; 230 + case hwmon_in_min: 231 + case hwmon_in_max: 232 + if (channel > 0 && (data->vsen_mask & BIT(index))) 233 + return 0644; 234 + break; 235 + default: 236 + break; 237 + } 316 238 317 239 return 0; 318 240 } ··· 333 233 { 334 234 struct nct7904_data *data = dev_get_drvdata(dev); 335 235 int ret, temp; 236 + unsigned int reg1, reg2, reg3; 336 237 337 238 switch (attr) { 338 239 case hwmon_temp_input: ··· 351 250 temp = ((ret & 0xff00) >> 5) | (ret & 0x7); 352 251 *val = sign_extend32(temp, 10) * 125; 353 252 return 0; 253 + case hwmon_temp_alarm: 254 + if (channel == 4) { 255 + ret = nct7904_read_reg(data, BANK_0, 256 + SMI_STS3_REG); 257 + if (ret < 0) 258 + return ret; 259 + *val = (ret >> 1) & 1; 260 + } else if (channel < 4) { 261 + ret = nct7904_read_reg(data, BANK_0, 262 + SMI_STS1_REG); 263 + if (ret < 0) 264 + return ret; 265 + *val = (ret >> (((channel * 2) + 1) & 0x07)) & 1; 266 + } else { 267 + if ((channel - 5) < 4) { 268 + ret = nct7904_read_reg(data, BANK_0, 269 + SMI_STS7_REG + 270 + ((channel - 5) >> 3)); 271 + if (ret < 0) 272 + return ret; 273 + *val = (ret >> ((channel - 5) & 0x07)) & 1; 274 + } else { 275 + ret = nct7904_read_reg(data, BANK_0, 276 + SMI_STS8_REG + 277 + ((channel - 5) >> 3)); 278 + if (ret < 0) 279 + return ret; 280 + *val = (ret >> (((channel - 5) & 0x07) - 4)) 281 + & 1; 282 + } 283 + } 284 + return 0; 285 + case hwmon_temp_type: 286 + if (channel < 5) { 287 + if ((data->tcpu_mask >> channel) & 0x01) { 288 + if ((data->temp_mode >> channel) & 0x01) 289 + *val = 3; /* TD */ 290 + else 291 + *val = 4; /* TR */ 292 + } else { 293 + *val = 0; 294 + } 295 + } else { 296 + if ((data->has_dts >> (channel - 5)) & 0x01) { 297 + if (data->enable_dts & ENABLE_TSI) 298 + *val = 5; /* TSI */ 299 + else 300 + *val = 6; /* PECI */ 301 + } else { 302 + *val = 0; 303 + } 304 + } 305 + return 0; 306 + case hwmon_temp_max: 307 + reg1 = LTD_HV_LL_REG; 308 + reg2 = TEMP_CH1_W_REG; 309 + reg3 = DTS_T_CPU1_W_REG; 310 + break; 311 + case hwmon_temp_max_hyst: 312 + reg1 = LTD_LV_LL_REG; 313 + reg2 = TEMP_CH1_WH_REG; 314 + reg3 = DTS_T_CPU1_WH_REG; 315 + break; 316 + case hwmon_temp_crit: 317 + reg1 = LTD_HV_HL_REG; 318 + reg2 = TEMP_CH1_C_REG; 319 + reg3 = DTS_T_CPU1_C_REG; 320 + break; 321 + case hwmon_temp_crit_hyst: 322 + reg1 = LTD_LV_HL_REG; 323 + reg2 = TEMP_CH1_CH_REG; 324 + reg3 = DTS_T_CPU1_CH_REG; 325 + break; 354 326 default: 355 327 return -EOPNOTSUPP; 356 328 } 329 + 330 + if (channel == 4) 331 + ret = nct7904_read_reg(data, BANK_1, reg1); 332 + else if (channel < 5) 333 + ret = nct7904_read_reg(data, BANK_1, 334 + reg2 + channel * 8); 335 + else 336 + ret = nct7904_read_reg(data, BANK_1, 337 + reg3 + (channel - 5) * 4); 338 + 339 + if (ret < 0) 340 + return ret; 341 + *val = ret * 1000; 342 + return 0; 357 343 } 358 344 359 345 static umode_t nct7904_temp_is_visible(const void *_data, u32 attr, int channel) 360 346 { 361 347 const struct nct7904_data *data = _data; 362 348 363 - if (attr == hwmon_temp_input) { 349 + switch (attr) { 350 + case hwmon_temp_input: 351 + case hwmon_temp_alarm: 352 + case hwmon_temp_type: 364 353 if (channel < 5) { 365 354 if (data->tcpu_mask & BIT(channel)) 366 355 return 0444; ··· 458 267 if (data->has_dts & BIT(channel - 5)) 459 268 return 0444; 460 269 } 270 + break; 271 + case hwmon_temp_max: 272 + case hwmon_temp_max_hyst: 273 + case hwmon_temp_crit: 274 + case hwmon_temp_crit_hyst: 275 + if (channel < 5) { 276 + if (data->tcpu_mask & BIT(channel)) 277 + return 0644; 278 + } else { 279 + if (data->has_dts & BIT(channel - 5)) 280 + return 0644; 281 + } 282 + break; 283 + default: 284 + break; 461 285 } 462 286 463 287 return 0; ··· 498 292 499 293 *val = ret ? 2 : 1; 500 294 return 0; 295 + default: 296 + return -EOPNOTSUPP; 297 + } 298 + } 299 + 300 + static int nct7904_write_temp(struct device *dev, u32 attr, int channel, 301 + long val) 302 + { 303 + struct nct7904_data *data = dev_get_drvdata(dev); 304 + int ret; 305 + unsigned int reg1, reg2, reg3; 306 + 307 + val = clamp_val(val / 1000, -128, 127); 308 + 309 + switch (attr) { 310 + case hwmon_temp_max: 311 + reg1 = LTD_HV_LL_REG; 312 + reg2 = TEMP_CH1_W_REG; 313 + reg3 = DTS_T_CPU1_W_REG; 314 + break; 315 + case hwmon_temp_max_hyst: 316 + reg1 = LTD_LV_LL_REG; 317 + reg2 = TEMP_CH1_WH_REG; 318 + reg3 = DTS_T_CPU1_WH_REG; 319 + break; 320 + case hwmon_temp_crit: 321 + reg1 = LTD_HV_HL_REG; 322 + reg2 = TEMP_CH1_C_REG; 323 + reg3 = DTS_T_CPU1_C_REG; 324 + break; 325 + case hwmon_temp_crit_hyst: 326 + reg1 = LTD_LV_HL_REG; 327 + reg2 = TEMP_CH1_CH_REG; 328 + reg3 = DTS_T_CPU1_CH_REG; 329 + break; 330 + default: 331 + return -EOPNOTSUPP; 332 + } 333 + if (channel == 4) 334 + ret = nct7904_write_reg(data, BANK_1, reg1, val); 335 + else if (channel < 5) 336 + ret = nct7904_write_reg(data, BANK_1, 337 + reg2 + channel * 8, val); 338 + else 339 + ret = nct7904_write_reg(data, BANK_1, 340 + reg3 + (channel - 5) * 4, val); 341 + 342 + return ret; 343 + } 344 + 345 + static int nct7904_write_fan(struct device *dev, u32 attr, int channel, 346 + long val) 347 + { 348 + struct nct7904_data *data = dev_get_drvdata(dev); 349 + int ret; 350 + u8 tmp; 351 + 352 + switch (attr) { 353 + case hwmon_fan_min: 354 + if (val <= 0) 355 + return -EINVAL; 356 + 357 + val = clamp_val(DIV_ROUND_CLOSEST(1350000, val), 1, 0x1fff); 358 + tmp = (val >> 5) & 0xff; 359 + ret = nct7904_write_reg(data, BANK_1, 360 + FANIN1_HV_HL_REG + channel * 2, tmp); 361 + if (ret < 0) 362 + return ret; 363 + tmp = val & 0x1f; 364 + ret = nct7904_write_reg(data, BANK_1, 365 + FANIN1_LV_HL_REG + channel * 2, tmp); 366 + return ret; 367 + default: 368 + return -EOPNOTSUPP; 369 + } 370 + } 371 + 372 + static int nct7904_write_in(struct device *dev, u32 attr, int channel, 373 + long val) 374 + { 375 + struct nct7904_data *data = dev_get_drvdata(dev); 376 + int ret, index, tmp; 377 + 378 + index = nct7904_chan_to_index[channel]; 379 + 380 + if (index < 14) 381 + val = val / 2; /* 0.002V scale */ 382 + else 383 + val = val / 6; /* 0.006V scale */ 384 + 385 + val = clamp_val(val, 0, 0x7ff); 386 + 387 + switch (attr) { 388 + case hwmon_in_min: 389 + tmp = nct7904_read_reg(data, BANK_1, 390 + VSEN1_LV_LL_REG + index * 4); 391 + if (tmp < 0) 392 + return tmp; 393 + tmp &= ~0x7; 394 + tmp |= val & 0x7; 395 + ret = nct7904_write_reg(data, BANK_1, 396 + VSEN1_LV_LL_REG + index * 4, tmp); 397 + if (ret < 0) 398 + return ret; 399 + tmp = nct7904_read_reg(data, BANK_1, 400 + VSEN1_HV_LL_REG + index * 4); 401 + if (tmp < 0) 402 + return tmp; 403 + tmp = (val >> 3) & 0xff; 404 + ret = nct7904_write_reg(data, BANK_1, 405 + VSEN1_HV_LL_REG + index * 4, tmp); 406 + return ret; 407 + case hwmon_in_max: 408 + tmp = nct7904_read_reg(data, BANK_1, 409 + VSEN1_LV_HL_REG + index * 4); 410 + if (tmp < 0) 411 + return tmp; 412 + tmp &= ~0x7; 413 + tmp |= val & 0x7; 414 + ret = nct7904_write_reg(data, BANK_1, 415 + VSEN1_LV_HL_REG + index * 4, tmp); 416 + if (ret < 0) 417 + return ret; 418 + tmp = nct7904_read_reg(data, BANK_1, 419 + VSEN1_HV_HL_REG + index * 4); 420 + if (tmp < 0) 421 + return tmp; 422 + tmp = (val >> 3) & 0xff; 423 + ret = nct7904_write_reg(data, BANK_1, 424 + VSEN1_HV_HL_REG + index * 4, tmp); 425 + return ret; 501 426 default: 502 427 return -EOPNOTSUPP; 503 428 } ··· 691 354 u32 attr, int channel, long val) 692 355 { 693 356 switch (type) { 357 + case hwmon_in: 358 + return nct7904_write_in(dev, attr, channel, val); 359 + case hwmon_fan: 360 + return nct7904_write_fan(dev, attr, channel, val); 694 361 case hwmon_pwm: 695 362 return nct7904_write_pwm(dev, attr, channel, val); 363 + case hwmon_temp: 364 + return nct7904_write_temp(dev, attr, channel, val); 696 365 default: 697 366 return -EOPNOTSUPP; 698 367 } ··· 747 404 748 405 static const struct hwmon_channel_info *nct7904_info[] = { 749 406 HWMON_CHANNEL_INFO(in, 750 - HWMON_I_INPUT, /* dummy, skipped in is_visible */ 751 - HWMON_I_INPUT, 752 - HWMON_I_INPUT, 753 - HWMON_I_INPUT, 754 - HWMON_I_INPUT, 755 - HWMON_I_INPUT, 756 - HWMON_I_INPUT, 757 - HWMON_I_INPUT, 758 - HWMON_I_INPUT, 759 - HWMON_I_INPUT, 760 - HWMON_I_INPUT, 761 - HWMON_I_INPUT, 762 - HWMON_I_INPUT, 763 - HWMON_I_INPUT, 764 - HWMON_I_INPUT, 765 - HWMON_I_INPUT, 766 - HWMON_I_INPUT, 767 - HWMON_I_INPUT, 768 - HWMON_I_INPUT, 769 - HWMON_I_INPUT, 770 - HWMON_I_INPUT), 407 + /* dummy, skipped in is_visible */ 408 + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | 409 + HWMON_I_ALARM, 410 + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | 411 + HWMON_I_ALARM, 412 + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | 413 + HWMON_I_ALARM, 414 + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | 415 + HWMON_I_ALARM, 416 + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | 417 + HWMON_I_ALARM, 418 + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | 419 + HWMON_I_ALARM, 420 + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | 421 + HWMON_I_ALARM, 422 + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | 423 + HWMON_I_ALARM, 424 + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | 425 + HWMON_I_ALARM, 426 + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | 427 + HWMON_I_ALARM, 428 + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | 429 + HWMON_I_ALARM, 430 + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | 431 + HWMON_I_ALARM, 432 + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | 433 + HWMON_I_ALARM, 434 + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | 435 + HWMON_I_ALARM, 436 + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | 437 + HWMON_I_ALARM, 438 + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | 439 + HWMON_I_ALARM, 440 + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | 441 + HWMON_I_ALARM, 442 + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | 443 + HWMON_I_ALARM, 444 + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | 445 + HWMON_I_ALARM, 446 + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | 447 + HWMON_I_ALARM, 448 + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | 449 + HWMON_I_ALARM), 771 450 HWMON_CHANNEL_INFO(fan, 772 - HWMON_F_INPUT, 773 - HWMON_F_INPUT, 774 - HWMON_F_INPUT, 775 - HWMON_F_INPUT, 776 - HWMON_F_INPUT, 777 - HWMON_F_INPUT, 778 - HWMON_F_INPUT, 779 - HWMON_F_INPUT), 451 + HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM, 452 + HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM, 453 + HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM, 454 + HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM, 455 + HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM, 456 + HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM, 457 + HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM, 458 + HWMON_F_INPUT | HWMON_F_MIN | HWMON_F_ALARM), 780 459 HWMON_CHANNEL_INFO(pwm, 781 460 HWMON_PWM_INPUT | HWMON_PWM_ENABLE, 782 461 HWMON_PWM_INPUT | HWMON_PWM_ENABLE, 783 462 HWMON_PWM_INPUT | HWMON_PWM_ENABLE, 784 463 HWMON_PWM_INPUT | HWMON_PWM_ENABLE), 785 464 HWMON_CHANNEL_INFO(temp, 786 - HWMON_T_INPUT, 787 - HWMON_T_INPUT, 788 - HWMON_T_INPUT, 789 - HWMON_T_INPUT, 790 - HWMON_T_INPUT, 791 - HWMON_T_INPUT, 792 - HWMON_T_INPUT, 793 - HWMON_T_INPUT, 794 - HWMON_T_INPUT), 465 + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | 466 + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | 467 + HWMON_T_CRIT_HYST, 468 + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | 469 + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | 470 + HWMON_T_CRIT_HYST, 471 + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | 472 + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | 473 + HWMON_T_CRIT_HYST, 474 + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | 475 + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | 476 + HWMON_T_CRIT_HYST, 477 + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | 478 + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | 479 + HWMON_T_CRIT_HYST, 480 + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | 481 + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | 482 + HWMON_T_CRIT_HYST, 483 + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | 484 + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | 485 + HWMON_T_CRIT_HYST, 486 + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | 487 + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | 488 + HWMON_T_CRIT_HYST, 489 + HWMON_T_INPUT | HWMON_T_ALARM | HWMON_T_MAX | 490 + HWMON_T_MAX_HYST | HWMON_T_TYPE | HWMON_T_CRIT | 491 + HWMON_T_CRIT_HYST), 795 492 NULL 796 493 }; 797 494 ··· 913 530 if (ret < 0) 914 531 return ret; 915 532 533 + data->temp_mode = 0; 916 534 for (i = 0; i < 4; i++) { 917 535 val = (ret & (0x03 << i)) >> (i * 2); 918 536 bit = (1 << i); 919 537 if (val == 0) 920 538 data->tcpu_mask &= ~bit; 539 + else if (val == 0x1 || val == 0x2) 540 + data->temp_mode |= bit; 921 541 } 922 542 923 543 /* PECI */ ··· 943 557 if (ret < 0) 944 558 return ret; 945 559 data->has_dts = ret & 0xF; 946 - if (data->enable_dts & 0x2) { 560 + if (data->enable_dts & ENABLE_TSI) { 947 561 ret = nct7904_read_reg(data, BANK_0, DTS_T_CTRL1_REG); 948 562 if (ret < 0) 949 563 return ret;
+1 -3
drivers/hwmon/npcm750-pwm-fan.c
··· 967 967 spin_lock_init(&data->fan_lock[i]); 968 968 969 969 data->fan_irq[i] = platform_get_irq(pdev, i); 970 - if (data->fan_irq[i] < 0) { 971 - dev_err(dev, "get IRQ fan%d failed\n", i); 970 + if (data->fan_irq[i] < 0) 972 971 return data->fan_irq[i]; 973 - } 974 972 975 973 sprintf(name, "NPCM7XX-FAN-MD%d", i); 976 974 ret = devm_request_irq(dev, data->fan_irq[i], npcm7xx_fan_isr,
+9
drivers/hwmon/pmbus/Kconfig
··· 46 46 This driver can also be built as a module. If so, the module will 47 47 be called ibm-cffps. 48 48 49 + config SENSORS_INSPUR_IPSPS 50 + tristate "INSPUR Power System Power Supply" 51 + help 52 + If you say yes here you get hardware monitoring support for the INSPUR 53 + Power System power supply. 54 + 55 + This driver can also be built as a module. If so, the module will 56 + be called inspur-ipsps. 57 + 49 58 config SENSORS_IR35221 50 59 tristate "Infineon IR35221" 51 60 help
+1
drivers/hwmon/pmbus/Makefile
··· 7 7 obj-$(CONFIG_SENSORS_PMBUS) += pmbus.o 8 8 obj-$(CONFIG_SENSORS_ADM1275) += adm1275.o 9 9 obj-$(CONFIG_SENSORS_IBM_CFFPS) += ibm-cffps.o 10 + obj-$(CONFIG_SENSORS_INSPUR_IPSPS) += inspur-ipsps.o 10 11 obj-$(CONFIG_SENSORS_IR35221) += ir35221.o 11 12 obj-$(CONFIG_SENSORS_IR38064) += ir38064.o 12 13 obj-$(CONFIG_SENSORS_IRPS5401) += irps5401.o
+88 -22
drivers/hwmon/pmbus/ibm-cffps.c
··· 12 12 #include <linux/leds.h> 13 13 #include <linux/module.h> 14 14 #include <linux/mutex.h> 15 + #include <linux/of_device.h> 15 16 #include <linux/pmbus.h> 16 17 17 18 #include "pmbus.h" ··· 21 20 #define CFFPS_PN_CMD 0x9B 22 21 #define CFFPS_SN_CMD 0x9E 23 22 #define CFFPS_CCIN_CMD 0xBD 24 - #define CFFPS_FW_CMD_START 0xFA 25 - #define CFFPS_FW_NUM_BYTES 4 23 + #define CFFPS_FW_CMD 0xFA 24 + #define CFFPS1_FW_NUM_BYTES 4 25 + #define CFFPS2_FW_NUM_WORDS 3 26 26 #define CFFPS_SYS_CONFIG_CMD 0xDA 27 27 28 28 #define CFFPS_INPUT_HISTORY_CMD 0xD6 ··· 54 52 CFFPS_DEBUGFS_NUM_ENTRIES 55 53 }; 56 54 55 + enum versions { cffps1, cffps2 }; 56 + 57 57 struct ibm_cffps_input_history { 58 58 struct mutex update_lock; 59 59 unsigned long last_update; ··· 65 61 }; 66 62 67 63 struct ibm_cffps { 64 + enum versions version; 68 65 struct i2c_client *client; 69 66 70 67 struct ibm_cffps_input_history input_history; ··· 137 132 struct ibm_cffps *psu = to_psu(idxp, idx); 138 133 char data[I2C_SMBUS_BLOCK_MAX] = { 0 }; 139 134 135 + pmbus_set_page(psu->client, 0); 136 + 140 137 switch (idx) { 141 138 case CFFPS_DEBUGFS_INPUT_HISTORY: 142 139 return ibm_cffps_read_input_history(psu, buf, count, ppos); ··· 159 152 rc = snprintf(data, 5, "%04X", rc); 160 153 goto done; 161 154 case CFFPS_DEBUGFS_FW: 162 - for (i = 0; i < CFFPS_FW_NUM_BYTES; ++i) { 163 - rc = i2c_smbus_read_byte_data(psu->client, 164 - CFFPS_FW_CMD_START + i); 165 - if (rc < 0) 166 - return rc; 155 + switch (psu->version) { 156 + case cffps1: 157 + for (i = 0; i < CFFPS1_FW_NUM_BYTES; ++i) { 158 + rc = i2c_smbus_read_byte_data(psu->client, 159 + CFFPS_FW_CMD + 160 + i); 161 + if (rc < 0) 162 + return rc; 167 163 168 - snprintf(&data[i * 2], 3, "%02X", rc); 164 + snprintf(&data[i * 2], 3, "%02X", rc); 165 + } 166 + 167 + rc = i * 2; 168 + break; 169 + case cffps2: 170 + for (i = 0; i < CFFPS2_FW_NUM_WORDS; ++i) { 171 + rc = i2c_smbus_read_word_data(psu->client, 172 + CFFPS_FW_CMD + 173 + i); 174 + if (rc < 0) 175 + return rc; 176 + 177 + snprintf(&data[i * 4], 5, "%04X", rc); 178 + } 179 + 180 + rc = i * 4; 181 + break; 182 + default: 183 + return -EOPNOTSUPP; 169 184 } 170 - 171 - rc = i * 2; 172 185 goto done; 173 186 default: 174 187 return -EINVAL; ··· 306 279 psu->led_state = CFFPS_LED_ON; 307 280 } 308 281 282 + pmbus_set_page(psu->client, 0); 283 + 309 284 rc = i2c_smbus_write_byte_data(psu->client, CFFPS_SYS_CONFIG_CMD, 310 285 psu->led_state); 311 286 if (rc < 0) ··· 327 298 328 299 if (led_cdev->brightness == LED_OFF) 329 300 return 0; 301 + 302 + pmbus_set_page(psu->client, 0); 330 303 331 304 rc = i2c_smbus_write_byte_data(psu->client, CFFPS_SYS_CONFIG_CMD, 332 305 CFFPS_LED_BLINK); ··· 359 328 dev_warn(dev, "failed to register led class: %d\n", rc); 360 329 } 361 330 362 - static struct pmbus_driver_info ibm_cffps_info = { 363 - .pages = 1, 364 - .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_IOUT | 365 - PMBUS_HAVE_PIN | PMBUS_HAVE_FAN12 | PMBUS_HAVE_TEMP | 366 - PMBUS_HAVE_TEMP2 | PMBUS_HAVE_TEMP3 | PMBUS_HAVE_STATUS_VOUT | 367 - PMBUS_HAVE_STATUS_IOUT | PMBUS_HAVE_STATUS_INPUT | 368 - PMBUS_HAVE_STATUS_TEMP | PMBUS_HAVE_STATUS_FAN12, 369 - .read_byte_data = ibm_cffps_read_byte_data, 370 - .read_word_data = ibm_cffps_read_word_data, 331 + static struct pmbus_driver_info ibm_cffps_info[] = { 332 + [cffps1] = { 333 + .pages = 1, 334 + .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_IOUT | 335 + PMBUS_HAVE_PIN | PMBUS_HAVE_FAN12 | PMBUS_HAVE_TEMP | 336 + PMBUS_HAVE_TEMP2 | PMBUS_HAVE_TEMP3 | 337 + PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_IOUT | 338 + PMBUS_HAVE_STATUS_INPUT | PMBUS_HAVE_STATUS_TEMP | 339 + PMBUS_HAVE_STATUS_FAN12, 340 + .read_byte_data = ibm_cffps_read_byte_data, 341 + .read_word_data = ibm_cffps_read_word_data, 342 + }, 343 + [cffps2] = { 344 + .pages = 2, 345 + .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_IOUT | 346 + PMBUS_HAVE_PIN | PMBUS_HAVE_FAN12 | PMBUS_HAVE_TEMP | 347 + PMBUS_HAVE_TEMP2 | PMBUS_HAVE_TEMP3 | 348 + PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_IOUT | 349 + PMBUS_HAVE_STATUS_INPUT | PMBUS_HAVE_STATUS_TEMP | 350 + PMBUS_HAVE_STATUS_FAN12, 351 + .func[1] = PMBUS_HAVE_VOUT | PMBUS_HAVE_IOUT | 352 + PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 | PMBUS_HAVE_TEMP3 | 353 + PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_IOUT, 354 + .read_byte_data = ibm_cffps_read_byte_data, 355 + .read_word_data = ibm_cffps_read_word_data, 356 + }, 371 357 }; 372 358 373 359 static struct pmbus_platform_data ibm_cffps_pdata = { ··· 395 347 const struct i2c_device_id *id) 396 348 { 397 349 int i, rc; 350 + enum versions vs; 398 351 struct dentry *debugfs; 399 352 struct dentry *ibm_cffps_dir; 400 353 struct ibm_cffps *psu; 354 + const void *md = of_device_get_match_data(&client->dev); 355 + 356 + if (md) 357 + vs = (enum versions)md; 358 + else if (id) 359 + vs = (enum versions)id->driver_data; 360 + else 361 + vs = cffps1; 401 362 402 363 client->dev.platform_data = &ibm_cffps_pdata; 403 - rc = pmbus_do_probe(client, id, &ibm_cffps_info); 364 + rc = pmbus_do_probe(client, id, &ibm_cffps_info[vs]); 404 365 if (rc) 405 366 return rc; 406 367 ··· 421 364 if (!psu) 422 365 return 0; 423 366 367 + psu->version = vs; 424 368 psu->client = client; 425 369 mutex_init(&psu->input_history.update_lock); 426 370 psu->input_history.last_update = jiffies - HZ; ··· 463 405 } 464 406 465 407 static const struct i2c_device_id ibm_cffps_id[] = { 466 - { "ibm_cffps1", 1 }, 408 + { "ibm_cffps1", cffps1 }, 409 + { "ibm_cffps2", cffps2 }, 467 410 {} 468 411 }; 469 412 MODULE_DEVICE_TABLE(i2c, ibm_cffps_id); 470 413 471 414 static const struct of_device_id ibm_cffps_of_match[] = { 472 - { .compatible = "ibm,cffps1" }, 415 + { 416 + .compatible = "ibm,cffps1", 417 + .data = (void *)cffps1 418 + }, 419 + { 420 + .compatible = "ibm,cffps2", 421 + .data = (void *)cffps2 422 + }, 473 423 {} 474 424 }; 475 425 MODULE_DEVICE_TABLE(of, ibm_cffps_of_match);
+228
drivers/hwmon/pmbus/inspur-ipsps.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * Copyright 2019 Inspur Corp. 4 + */ 5 + 6 + #include <linux/debugfs.h> 7 + #include <linux/device.h> 8 + #include <linux/fs.h> 9 + #include <linux/i2c.h> 10 + #include <linux/module.h> 11 + #include <linux/pmbus.h> 12 + #include <linux/hwmon-sysfs.h> 13 + 14 + #include "pmbus.h" 15 + 16 + #define IPSPS_REG_VENDOR_ID 0x99 17 + #define IPSPS_REG_MODEL 0x9A 18 + #define IPSPS_REG_FW_VERSION 0x9B 19 + #define IPSPS_REG_PN 0x9C 20 + #define IPSPS_REG_SN 0x9E 21 + #define IPSPS_REG_HW_VERSION 0xB0 22 + #define IPSPS_REG_MODE 0xFC 23 + 24 + #define MODE_ACTIVE 0x55 25 + #define MODE_STANDBY 0x0E 26 + #define MODE_REDUNDANCY 0x00 27 + 28 + #define MODE_ACTIVE_STRING "active" 29 + #define MODE_STANDBY_STRING "standby" 30 + #define MODE_REDUNDANCY_STRING "redundancy" 31 + 32 + enum ipsps_index { 33 + vendor, 34 + model, 35 + fw_version, 36 + part_number, 37 + serial_number, 38 + hw_version, 39 + mode, 40 + num_regs, 41 + }; 42 + 43 + static const u8 ipsps_regs[num_regs] = { 44 + [vendor] = IPSPS_REG_VENDOR_ID, 45 + [model] = IPSPS_REG_MODEL, 46 + [fw_version] = IPSPS_REG_FW_VERSION, 47 + [part_number] = IPSPS_REG_PN, 48 + [serial_number] = IPSPS_REG_SN, 49 + [hw_version] = IPSPS_REG_HW_VERSION, 50 + [mode] = IPSPS_REG_MODE, 51 + }; 52 + 53 + static ssize_t ipsps_string_show(struct device *dev, 54 + struct device_attribute *devattr, 55 + char *buf) 56 + { 57 + u8 reg; 58 + int rc; 59 + char *p; 60 + char data[I2C_SMBUS_BLOCK_MAX + 1]; 61 + struct i2c_client *client = to_i2c_client(dev->parent); 62 + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 63 + 64 + reg = ipsps_regs[attr->index]; 65 + rc = i2c_smbus_read_block_data(client, reg, data); 66 + if (rc < 0) 67 + return rc; 68 + 69 + /* filled with printable characters, ending with # */ 70 + p = memscan(data, '#', rc); 71 + *p = '\0'; 72 + 73 + return snprintf(buf, PAGE_SIZE, "%s\n", data); 74 + } 75 + 76 + static ssize_t ipsps_fw_version_show(struct device *dev, 77 + struct device_attribute *devattr, 78 + char *buf) 79 + { 80 + u8 reg; 81 + int rc; 82 + u8 data[I2C_SMBUS_BLOCK_MAX] = { 0 }; 83 + struct i2c_client *client = to_i2c_client(dev->parent); 84 + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 85 + 86 + reg = ipsps_regs[attr->index]; 87 + rc = i2c_smbus_read_block_data(client, reg, data); 88 + if (rc < 0) 89 + return rc; 90 + 91 + if (rc != 6) 92 + return -EPROTO; 93 + 94 + return snprintf(buf, PAGE_SIZE, "%u.%02u%u-%u.%02u\n", 95 + data[1], data[2]/* < 100 */, data[3]/*< 10*/, 96 + data[4], data[5]/* < 100 */); 97 + } 98 + 99 + static ssize_t ipsps_mode_show(struct device *dev, 100 + struct device_attribute *devattr, char *buf) 101 + { 102 + u8 reg; 103 + int rc; 104 + struct i2c_client *client = to_i2c_client(dev->parent); 105 + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 106 + 107 + reg = ipsps_regs[attr->index]; 108 + rc = i2c_smbus_read_byte_data(client, reg); 109 + if (rc < 0) 110 + return rc; 111 + 112 + switch (rc) { 113 + case MODE_ACTIVE: 114 + return snprintf(buf, PAGE_SIZE, "[%s] %s %s\n", 115 + MODE_ACTIVE_STRING, 116 + MODE_STANDBY_STRING, MODE_REDUNDANCY_STRING); 117 + case MODE_STANDBY: 118 + return snprintf(buf, PAGE_SIZE, "%s [%s] %s\n", 119 + MODE_ACTIVE_STRING, 120 + MODE_STANDBY_STRING, MODE_REDUNDANCY_STRING); 121 + case MODE_REDUNDANCY: 122 + return snprintf(buf, PAGE_SIZE, "%s %s [%s]\n", 123 + MODE_ACTIVE_STRING, 124 + MODE_STANDBY_STRING, MODE_REDUNDANCY_STRING); 125 + default: 126 + return snprintf(buf, PAGE_SIZE, "unspecified\n"); 127 + } 128 + } 129 + 130 + static ssize_t ipsps_mode_store(struct device *dev, 131 + struct device_attribute *devattr, 132 + const char *buf, size_t count) 133 + { 134 + u8 reg; 135 + int rc; 136 + struct i2c_client *client = to_i2c_client(dev->parent); 137 + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 138 + 139 + reg = ipsps_regs[attr->index]; 140 + if (sysfs_streq(MODE_STANDBY_STRING, buf)) { 141 + rc = i2c_smbus_write_byte_data(client, reg, 142 + MODE_STANDBY); 143 + if (rc < 0) 144 + return rc; 145 + return count; 146 + } else if (sysfs_streq(MODE_ACTIVE_STRING, buf)) { 147 + rc = i2c_smbus_write_byte_data(client, reg, 148 + MODE_ACTIVE); 149 + if (rc < 0) 150 + return rc; 151 + return count; 152 + } 153 + 154 + return -EINVAL; 155 + } 156 + 157 + static SENSOR_DEVICE_ATTR_RO(vendor, ipsps_string, vendor); 158 + static SENSOR_DEVICE_ATTR_RO(model, ipsps_string, model); 159 + static SENSOR_DEVICE_ATTR_RO(part_number, ipsps_string, part_number); 160 + static SENSOR_DEVICE_ATTR_RO(serial_number, ipsps_string, serial_number); 161 + static SENSOR_DEVICE_ATTR_RO(hw_version, ipsps_string, hw_version); 162 + static SENSOR_DEVICE_ATTR_RO(fw_version, ipsps_fw_version, fw_version); 163 + static SENSOR_DEVICE_ATTR_RW(mode, ipsps_mode, mode); 164 + 165 + static struct attribute *ipsps_attrs[] = { 166 + &sensor_dev_attr_vendor.dev_attr.attr, 167 + &sensor_dev_attr_model.dev_attr.attr, 168 + &sensor_dev_attr_part_number.dev_attr.attr, 169 + &sensor_dev_attr_serial_number.dev_attr.attr, 170 + &sensor_dev_attr_hw_version.dev_attr.attr, 171 + &sensor_dev_attr_fw_version.dev_attr.attr, 172 + &sensor_dev_attr_mode.dev_attr.attr, 173 + NULL, 174 + }; 175 + 176 + ATTRIBUTE_GROUPS(ipsps); 177 + 178 + static struct pmbus_driver_info ipsps_info = { 179 + .pages = 1, 180 + .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_IOUT | 181 + PMBUS_HAVE_IIN | PMBUS_HAVE_POUT | PMBUS_HAVE_PIN | 182 + PMBUS_HAVE_FAN12 | PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 | 183 + PMBUS_HAVE_TEMP3 | PMBUS_HAVE_STATUS_VOUT | 184 + PMBUS_HAVE_STATUS_IOUT | PMBUS_HAVE_STATUS_INPUT | 185 + PMBUS_HAVE_STATUS_TEMP | PMBUS_HAVE_STATUS_FAN12, 186 + .groups = ipsps_groups, 187 + }; 188 + 189 + static struct pmbus_platform_data ipsps_pdata = { 190 + .flags = PMBUS_SKIP_STATUS_CHECK, 191 + }; 192 + 193 + static int ipsps_probe(struct i2c_client *client, 194 + const struct i2c_device_id *id) 195 + { 196 + client->dev.platform_data = &ipsps_pdata; 197 + return pmbus_do_probe(client, id, &ipsps_info); 198 + } 199 + 200 + static const struct i2c_device_id ipsps_id[] = { 201 + { "ipsps1", 0 }, 202 + {} 203 + }; 204 + MODULE_DEVICE_TABLE(i2c, ipsps_id); 205 + 206 + #ifdef CONFIG_OF 207 + static const struct of_device_id ipsps_of_match[] = { 208 + { .compatible = "inspur,ipsps1" }, 209 + {} 210 + }; 211 + MODULE_DEVICE_TABLE(of, ipsps_of_match); 212 + #endif 213 + 214 + static struct i2c_driver ipsps_driver = { 215 + .driver = { 216 + .name = "inspur-ipsps", 217 + .of_match_table = of_match_ptr(ipsps_of_match), 218 + }, 219 + .probe = ipsps_probe, 220 + .remove = pmbus_do_remove, 221 + .id_table = ipsps_id, 222 + }; 223 + 224 + module_i2c_driver(ipsps_driver); 225 + 226 + MODULE_AUTHOR("John Wang"); 227 + MODULE_DESCRIPTION("PMBus driver for Inspur Power System power supplies"); 228 + MODULE_LICENSE("GPL");
-2
drivers/hwmon/pmbus/max31785.c
··· 244 244 #define MAX31785_VOUT_FUNCS \ 245 245 (PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT) 246 246 247 - #define MAX37185_NUM_FAN_PAGES 6 248 - 249 247 static const struct pmbus_driver_info max31785_info = { 250 248 .pages = MAX31785_NR_PAGES, 251 249
-1
drivers/hwmon/pmbus/ucd9000.c
··· 15 15 #include <linux/slab.h> 16 16 #include <linux/i2c.h> 17 17 #include <linux/pmbus.h> 18 - #include <linux/gpio.h> 19 18 #include <linux/gpio/driver.h> 20 19 #include "pmbus.h" 21 20
+1 -1
drivers/hwmon/raspberrypi-hwmon.c
··· 146 146 }; 147 147 module_platform_driver(rpi_hwmon_driver); 148 148 149 - MODULE_AUTHOR("Stefan Wahren <stefan.wahren@i2se.com>"); 149 + MODULE_AUTHOR("Stefan Wahren <wahrenst@gmx.net>"); 150 150 MODULE_DESCRIPTION("Raspberry Pi voltage sensor driver"); 151 151 MODULE_LICENSE("GPL v2"); 152 152 MODULE_ALIAS("platform:raspberrypi-hwmon");
+43 -14
drivers/hwmon/shtc1.c
··· 24 24 static const unsigned char shtc1_cmd_measure_nonblocking_lpm[] = { 0x60, 0x9c }; 25 25 26 26 /* command for reading the ID register */ 27 - static const unsigned char shtc1_cmd_read_id_reg[] = { 0xef, 0xc8 }; 27 + static const unsigned char shtc1_cmd_read_id_reg[] = { 0xef, 0xc8 }; 28 28 29 - /* constants for reading the ID register */ 30 - #define SHTC1_ID 0x07 31 - #define SHTC1_ID_REG_MASK 0x1f 29 + /* 30 + * constants for reading the ID register 31 + * SHTC1: 0x0007 with mask 0x003f 32 + * SHTW1: 0x0007 with mask 0x003f 33 + * SHTC3: 0x0807 with mask 0x083f 34 + */ 35 + #define SHTC3_ID 0x0807 36 + #define SHTC3_ID_MASK 0x083f 37 + #define SHTC1_ID 0x0007 38 + #define SHTC1_ID_MASK 0x003f 32 39 33 40 /* delays for non-blocking i2c commands, both in us */ 34 41 #define SHTC1_NONBLOCKING_WAIT_TIME_HPM 14400 35 42 #define SHTC1_NONBLOCKING_WAIT_TIME_LPM 1000 43 + #define SHTC3_NONBLOCKING_WAIT_TIME_HPM 12100 44 + #define SHTC3_NONBLOCKING_WAIT_TIME_LPM 800 36 45 37 46 #define SHTC1_CMD_LENGTH 2 38 47 #define SHTC1_RESPONSE_LENGTH 6 48 + 49 + enum shtcx_chips { 50 + shtc1, 51 + shtc3, 52 + }; 39 53 40 54 struct shtc1_data { 41 55 struct i2c_client *client; ··· 61 47 unsigned int nonblocking_wait_time; /* in us */ 62 48 63 49 struct shtc1_platform_data setup; 50 + enum shtcx_chips chip; 64 51 65 52 int temperature; /* 1000 * temperature in dgr C */ 66 53 int humidity; /* 1000 * relative humidity in %RH */ ··· 172 157 data->command = data->setup.blocking_io ? 173 158 shtc1_cmd_measure_blocking_hpm : 174 159 shtc1_cmd_measure_nonblocking_hpm; 175 - data->nonblocking_wait_time = SHTC1_NONBLOCKING_WAIT_TIME_HPM; 176 - 160 + data->nonblocking_wait_time = (data->chip == shtc1) ? 161 + SHTC1_NONBLOCKING_WAIT_TIME_HPM : 162 + SHTC3_NONBLOCKING_WAIT_TIME_HPM; 177 163 } else { 178 164 data->command = data->setup.blocking_io ? 179 165 shtc1_cmd_measure_blocking_lpm : 180 166 shtc1_cmd_measure_nonblocking_lpm; 181 - data->nonblocking_wait_time = SHTC1_NONBLOCKING_WAIT_TIME_LPM; 167 + data->nonblocking_wait_time = (data->chip == shtc1) ? 168 + SHTC1_NONBLOCKING_WAIT_TIME_LPM : 169 + SHTC3_NONBLOCKING_WAIT_TIME_LPM; 182 170 } 183 171 } 184 172 ··· 189 171 const struct i2c_device_id *id) 190 172 { 191 173 int ret; 192 - char id_reg[2]; 174 + u16 id_reg; 175 + char id_reg_buf[2]; 193 176 struct shtc1_data *data; 194 177 struct device *hwmon_dev; 178 + enum shtcx_chips chip = id->driver_data; 195 179 struct i2c_adapter *adap = client->adapter; 196 180 struct device *dev = &client->dev; 197 181 ··· 207 187 dev_err(dev, "could not send read_id_reg command: %d\n", ret); 208 188 return ret < 0 ? ret : -ENODEV; 209 189 } 210 - ret = i2c_master_recv(client, id_reg, sizeof(id_reg)); 211 - if (ret != sizeof(id_reg)) { 190 + ret = i2c_master_recv(client, id_reg_buf, sizeof(id_reg_buf)); 191 + if (ret != sizeof(id_reg_buf)) { 212 192 dev_err(dev, "could not read ID register: %d\n", ret); 213 193 return -ENODEV; 214 194 } 215 - if ((id_reg[1] & SHTC1_ID_REG_MASK) != SHTC1_ID) { 216 - dev_err(dev, "ID register doesn't match\n"); 195 + 196 + id_reg = be16_to_cpup((__be16 *)id_reg_buf); 197 + if (chip == shtc3) { 198 + if ((id_reg & SHTC3_ID_MASK) != SHTC3_ID) { 199 + dev_err(dev, "SHTC3 ID register does not match\n"); 200 + return -ENODEV; 201 + } 202 + } else if ((id_reg & SHTC1_ID_MASK) != SHTC1_ID) { 203 + dev_err(dev, "SHTC1 ID register does not match\n"); 217 204 return -ENODEV; 218 205 } 219 206 ··· 231 204 data->setup.blocking_io = false; 232 205 data->setup.high_precision = true; 233 206 data->client = client; 207 + data->chip = chip; 234 208 235 209 if (client->dev.platform_data) 236 210 data->setup = *(struct shtc1_platform_data *)dev->platform_data; ··· 250 222 251 223 /* device ID table */ 252 224 static const struct i2c_device_id shtc1_id[] = { 253 - { "shtc1", 0 }, 254 - { "shtw1", 0 }, 225 + { "shtc1", shtc1 }, 226 + { "shtw1", shtc1 }, 227 + { "shtc3", shtc3 }, 255 228 { } 256 229 }; 257 230 MODULE_DEVICE_TABLE(i2c, shtc1_id);
+3 -3
drivers/hwmon/smm665.c
··· 586 586 587 587 data->client = client; 588 588 data->type = id->driver_data; 589 - data->cmdreg = i2c_new_dummy(adapter, (client->addr & ~SMM665_REGMASK) 589 + data->cmdreg = i2c_new_dummy_device(adapter, (client->addr & ~SMM665_REGMASK) 590 590 | SMM665_CMDREG_BASE); 591 - if (!data->cmdreg) 592 - return -ENOMEM; 591 + if (IS_ERR(data->cmdreg)) 592 + return PTR_ERR(data->cmdreg); 593 593 594 594 switch (data->type) { 595 595 case smm465:
+3 -3
drivers/hwmon/w83781d.c
··· 894 894 } 895 895 896 896 for (i = 0; i < num_sc; i++) { 897 - data->lm75[i] = i2c_new_dummy(adapter, sc_addr[i]); 898 - if (!data->lm75[i]) { 897 + data->lm75[i] = i2c_new_dummy_device(adapter, sc_addr[i]); 898 + if (IS_ERR(data->lm75[i])) { 899 899 dev_err(&new_client->dev, 900 900 "Subclient %d registration at address 0x%x failed.\n", 901 901 i, sc_addr[i]); 902 - err = -ENOMEM; 902 + err = PTR_ERR(data->lm75[i]); 903 903 if (i == 1) 904 904 goto ERROR_SC_3; 905 905 goto ERROR_SC_2;
+9 -23
drivers/hwmon/w83791d.c
··· 1260 1260 struct i2c_adapter *adapter = client->adapter; 1261 1261 struct w83791d_data *data = i2c_get_clientdata(client); 1262 1262 int address = client->addr; 1263 - int i, id, err; 1263 + int i, id; 1264 1264 u8 val; 1265 1265 1266 1266 id = i2c_adapter_id(adapter); ··· 1272 1272 "invalid subclient " 1273 1273 "address %d; must be 0x48-0x4f\n", 1274 1274 force_subclients[i]); 1275 - err = -ENODEV; 1276 - goto error_sc_0; 1275 + return -ENODEV; 1277 1276 } 1278 1277 } 1279 1278 w83791d_write(client, W83791D_REG_I2C_SUBADDR, ··· 1282 1283 1283 1284 val = w83791d_read(client, W83791D_REG_I2C_SUBADDR); 1284 1285 if (!(val & 0x08)) 1285 - data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (val & 0x7)); 1286 + data->lm75[0] = devm_i2c_new_dummy_device(&client->dev, adapter, 1287 + 0x48 + (val & 0x7)); 1286 1288 if (!(val & 0x80)) { 1287 - if ((data->lm75[0] != NULL) && 1289 + if (!IS_ERR(data->lm75[0]) && 1288 1290 ((val & 0x7) == ((val >> 4) & 0x7))) { 1289 1291 dev_err(&client->dev, 1290 1292 "duplicate addresses 0x%x, " 1291 1293 "use force_subclient\n", 1292 1294 data->lm75[0]->addr); 1293 - err = -ENODEV; 1294 - goto error_sc_1; 1295 + return -ENODEV; 1295 1296 } 1296 - data->lm75[1] = i2c_new_dummy(adapter, 1297 - 0x48 + ((val >> 4) & 0x7)); 1297 + data->lm75[1] = devm_i2c_new_dummy_device(&client->dev, adapter, 1298 + 0x48 + ((val >> 4) & 0x7)); 1298 1299 } 1299 1300 1300 1301 return 0; 1301 - 1302 - /* Undo inits in case of errors */ 1303 - 1304 - error_sc_1: 1305 - i2c_unregister_device(data->lm75[0]); 1306 - error_sc_0: 1307 - return err; 1308 1302 } 1309 1303 1310 1304 ··· 1386 1394 /* Register sysfs hooks */ 1387 1395 err = sysfs_create_group(&client->dev.kobj, &w83791d_group); 1388 1396 if (err) 1389 - goto error3; 1397 + return err; 1390 1398 1391 1399 /* Check if pins of fan/pwm 4-5 are in use as GPIO */ 1392 1400 has_fanpwm45 = w83791d_read(client, W83791D_REG_GPIO) & 0x10; ··· 1411 1419 sysfs_remove_group(&client->dev.kobj, &w83791d_group_fanpwm45); 1412 1420 error4: 1413 1421 sysfs_remove_group(&client->dev.kobj, &w83791d_group); 1414 - error3: 1415 - i2c_unregister_device(data->lm75[0]); 1416 - i2c_unregister_device(data->lm75[1]); 1417 1422 return err; 1418 1423 } 1419 1424 ··· 1420 1431 1421 1432 hwmon_device_unregister(data->hwmon_dev); 1422 1433 sysfs_remove_group(&client->dev.kobj, &w83791d_group); 1423 - 1424 - i2c_unregister_device(data->lm75[0]); 1425 - i2c_unregister_device(data->lm75[1]); 1426 1434 1427 1435 return 0; 1428 1436 }
+9 -23
drivers/hwmon/w83792d.c
··· 924 924 static int 925 925 w83792d_detect_subclients(struct i2c_client *new_client) 926 926 { 927 - int i, id, err; 927 + int i, id; 928 928 int address = new_client->addr; 929 929 u8 val; 930 930 struct i2c_adapter *adapter = new_client->adapter; ··· 938 938 dev_err(&new_client->dev, 939 939 "invalid subclient address %d; must be 0x48-0x4f\n", 940 940 force_subclients[i]); 941 - err = -ENODEV; 942 - goto ERROR_SC_0; 941 + return -ENODEV; 943 942 } 944 943 } 945 944 w83792d_write_value(new_client, W83792D_REG_I2C_SUBADDR, ··· 948 949 949 950 val = w83792d_read_value(new_client, W83792D_REG_I2C_SUBADDR); 950 951 if (!(val & 0x08)) 951 - data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (val & 0x7)); 952 + data->lm75[0] = devm_i2c_new_dummy_device(&new_client->dev, adapter, 953 + 0x48 + (val & 0x7)); 952 954 if (!(val & 0x80)) { 953 - if ((data->lm75[0] != NULL) && 955 + if (!IS_ERR(data->lm75[0]) && 954 956 ((val & 0x7) == ((val >> 4) & 0x7))) { 955 957 dev_err(&new_client->dev, 956 958 "duplicate addresses 0x%x, use force_subclient\n", 957 959 data->lm75[0]->addr); 958 - err = -ENODEV; 959 - goto ERROR_SC_1; 960 + return -ENODEV; 960 961 } 961 - data->lm75[1] = i2c_new_dummy(adapter, 962 - 0x48 + ((val >> 4) & 0x7)); 962 + data->lm75[1] = devm_i2c_new_dummy_device(&new_client->dev, adapter, 963 + 0x48 + ((val >> 4) & 0x7)); 963 964 } 964 965 965 966 return 0; 966 - 967 - /* Undo inits in case of errors */ 968 - 969 - ERROR_SC_1: 970 - i2c_unregister_device(data->lm75[0]); 971 - ERROR_SC_0: 972 - return err; 973 967 } 974 968 975 969 static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_in, NULL, 0); ··· 1388 1396 /* Register sysfs hooks */ 1389 1397 err = sysfs_create_group(&dev->kobj, &w83792d_group); 1390 1398 if (err) 1391 - goto exit_i2c_unregister; 1399 + return err; 1392 1400 1393 1401 /* 1394 1402 * Read GPIO enable register to check if pins for fan 4,5 are used as ··· 1433 1441 sysfs_remove_group(&dev->kobj, &w83792d_group); 1434 1442 for (i = 0; i < ARRAY_SIZE(w83792d_group_fan); i++) 1435 1443 sysfs_remove_group(&dev->kobj, &w83792d_group_fan[i]); 1436 - exit_i2c_unregister: 1437 - i2c_unregister_device(data->lm75[0]); 1438 - i2c_unregister_device(data->lm75[1]); 1439 1444 return err; 1440 1445 } 1441 1446 ··· 1447 1458 for (i = 0; i < ARRAY_SIZE(w83792d_group_fan); i++) 1448 1459 sysfs_remove_group(&client->dev.kobj, 1449 1460 &w83792d_group_fan[i]); 1450 - 1451 - i2c_unregister_device(data->lm75[0]); 1452 - i2c_unregister_device(data->lm75[1]); 1453 1461 1454 1462 return 0; 1455 1463 }
+8 -22
drivers/hwmon/w83793.c
··· 1551 1551 for (i = 0; i < ARRAY_SIZE(w83793_temp); i++) 1552 1552 device_remove_file(dev, &w83793_temp[i].dev_attr); 1553 1553 1554 - i2c_unregister_device(data->lm75[0]); 1555 - i2c_unregister_device(data->lm75[1]); 1556 - 1557 1554 /* Decrease data reference counter */ 1558 1555 mutex_lock(&watchdog_data_mutex); 1559 1556 kref_put(&data->kref, w83793_release_resources); ··· 1562 1565 static int 1563 1566 w83793_detect_subclients(struct i2c_client *client) 1564 1567 { 1565 - int i, id, err; 1568 + int i, id; 1566 1569 int address = client->addr; 1567 1570 u8 tmp; 1568 1571 struct i2c_adapter *adapter = client->adapter; ··· 1577 1580 "invalid subclient " 1578 1581 "address %d; must be 0x48-0x4f\n", 1579 1582 force_subclients[i]); 1580 - err = -EINVAL; 1581 - goto ERROR_SC_0; 1583 + return -EINVAL; 1582 1584 } 1583 1585 } 1584 1586 w83793_write_value(client, W83793_REG_I2C_SUBADDR, ··· 1587 1591 1588 1592 tmp = w83793_read_value(client, W83793_REG_I2C_SUBADDR); 1589 1593 if (!(tmp & 0x08)) 1590 - data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (tmp & 0x7)); 1594 + data->lm75[0] = devm_i2c_new_dummy_device(&client->dev, adapter, 1595 + 0x48 + (tmp & 0x7)); 1591 1596 if (!(tmp & 0x80)) { 1592 - if ((data->lm75[0] != NULL) 1597 + if (!IS_ERR(data->lm75[0]) 1593 1598 && ((tmp & 0x7) == ((tmp >> 4) & 0x7))) { 1594 1599 dev_err(&client->dev, 1595 1600 "duplicate addresses 0x%x, " 1596 1601 "use force_subclients\n", data->lm75[0]->addr); 1597 - err = -ENODEV; 1598 - goto ERROR_SC_1; 1602 + return -ENODEV; 1599 1603 } 1600 - data->lm75[1] = i2c_new_dummy(adapter, 1601 - 0x48 + ((tmp >> 4) & 0x7)); 1604 + data->lm75[1] = devm_i2c_new_dummy_device(&client->dev, adapter, 1605 + 0x48 + ((tmp >> 4) & 0x7)); 1602 1606 } 1603 1607 1604 1608 return 0; 1605 - 1606 - /* Undo inits in case of errors */ 1607 - 1608 - ERROR_SC_1: 1609 - i2c_unregister_device(data->lm75[0]); 1610 - ERROR_SC_0: 1611 - return err; 1612 1609 } 1613 1610 1614 1611 /* Return 0 if detection is successful, -ENODEV otherwise */ ··· 1934 1945 1935 1946 for (i = 0; i < ARRAY_SIZE(w83793_temp); i++) 1936 1947 device_remove_file(dev, &w83793_temp[i].dev_attr); 1937 - 1938 - i2c_unregister_device(data->lm75[0]); 1939 - i2c_unregister_device(data->lm75[1]); 1940 1948 free_mem: 1941 1949 kfree(data); 1942 1950 exit:
+1 -1
drivers/iio/adc/Kconfig
··· 958 958 959 959 config TI_ADS1015 960 960 tristate "Texas Instruments ADS1015 ADC" 961 - depends on I2C && !SENSORS_ADS1015 961 + depends on I2C 962 962 select REGMAP_I2C 963 963 select IIO_BUFFER 964 964 select IIO_TRIGGERED_BUFFER
+1
include/linux/pci_ids.h
··· 548 548 #define PCI_DEVICE_ID_AMD_17H_DF_F3 0x1463 549 549 #define PCI_DEVICE_ID_AMD_17H_M10H_DF_F3 0x15eb 550 550 #define PCI_DEVICE_ID_AMD_17H_M30H_DF_F3 0x1493 551 + #define PCI_DEVICE_ID_AMD_17H_M70H_DF_F3 0x1443 551 552 #define PCI_DEVICE_ID_AMD_CNB17H_F3 0x1703 552 553 #define PCI_DEVICE_ID_AMD_LANCE 0x2000 553 554 #define PCI_DEVICE_ID_AMD_LANCE_HOME 0x2001