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

Merge tag 'hwmon-for-linus-v4.8' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging

Pull hwmon updates from Guenter Roeck:

- New drivers for FTS BMC "Teutates", TI INA3221, and Sensirion SHT3x.

- Added support for Microchip MCP9808 and TI TMP461.

- Cleanup and minor fixes in various drivers.

* tag 'hwmon-for-linus-v4.8' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: (37 commits)
Documentation: dtb: xgene: Add hwmon dts binding documentation
hwmon: (ftsteutates) Remove unused including <linux/version.h>
hwmon: (adt7411) set bit 3 in CFG1 register
hwmon: Add driver for FTS BMC chip "Teutates"
hwmon: (sht3x) add humidity heater element control
hwmon: (jc42) Add support for generic JC-42.4 devicetree binding
dt/bindings: Add bindings for JC-42.4 compatible temperature sensors
hwmon: (tmp102) Convert to use regmap, and drop local cache
hwmon: (tmp102) Rework chip configuration
hwmon: (tmp102) Improve handling of initial read delay
hwmon: (lm90) Drop unnecessary else statements
hwmon: (lm90) Use bool for valid flag
hwmon: (lm90) Read limit registers only once
hwmon: (lm90) Simplify read functions
hwmon: (lm90) Use devm_hwmon_device_register_with_groups
hwmon: (lm90) Use devm_add_action for cleanup
hwmon: (lm75) Convert to use regmap
hwmon: (lm75) Add update_interval attribute
hwmon: (lm75) Drop lm75_read_value and lm75_write_value
hwmon: (lm75) Handle cleanup with devm_add_action
...

+2965 -607
+14
Documentation/devicetree/bindings/hwmon/apm-xgene-hwmon.txt
··· 1 + APM X-Gene hwmon driver 2 + 3 + APM X-Gene SOC sensors are accessed over the "SLIMpro" mailbox. 4 + 5 + Required properties : 6 + - compatible : should be "apm,xgene-slimpro-hwmon" 7 + - mboxes : use the label reference for the mailbox as the first parameter. 8 + The second parameter is the channel number. 9 + 10 + Example : 11 + hwmonslimpro { 12 + compatible = "apm,xgene-slimpro-hwmon"; 13 + mboxes = <&mailbox 7>; 14 + };
+42
Documentation/devicetree/bindings/hwmon/jc42.txt
··· 1 + Properties for Jedec JC-42.4 compatible temperature sensors 2 + 3 + Required properties: 4 + - compatible: May include a device-specific string consisting of the 5 + manufacturer and the name of the chip. A list of supported 6 + chip names follows. 7 + Must include "jedec,jc-42.4-temp" for any Jedec JC-42.4 8 + compatible temperature sensor. 9 + 10 + Supported chip names: 11 + adi,adt7408 12 + atmel,at30ts00 13 + atmel,at30tse004 14 + onnn,cat6095 15 + onnn,cat34ts02 16 + maxim,max6604 17 + microchip,mcp9804 18 + microchip,mcp9805 19 + microchip,mcp9808 20 + microchip,mcp98243 21 + microchip,mcp98244 22 + microchip,mcp9843 23 + nxp,se97 24 + nxp,se98 25 + st,stts2002 26 + st,stts2004 27 + st,stts3000 28 + st,stts424 29 + st,stts424e 30 + idt,tse2002 31 + idt,tse2004 32 + idt,ts3000 33 + idt,ts3001 34 + 35 + - reg: I2C address 36 + 37 + Example: 38 + 39 + temp-sensor@1a { 40 + compatible = "jedec,jc-42.4-temp"; 41 + reg = <0x1a>; 42 + };
+1 -1
Documentation/hwmon/abituguru
··· 24 24 AW9D-MAX) (2) 25 25 1) For revisions 2 and 3 uGuru's the driver can autodetect the 26 26 sensortype (Volt or Temp) for bank1 sensors, for revision 1 uGuru's 27 - this doesnot always work. For these uGuru's the autodection can 27 + this does not always work. For these uGuru's the autodetection can 28 28 be overridden with the bank1_types module param. For all 3 known 29 29 revison 1 motherboards the correct use of this param is: 30 30 bank1_types=1,1,0,0,0,0,0,2,0,0,0,0,2,0,0,1
+23
Documentation/hwmon/ftsteutates
··· 1 + Kernel driver ftsteutates 2 + ===================== 3 + 4 + Supported chips: 5 + * FTS Teutates 6 + Prefix: 'ftsteutates' 7 + Addresses scanned: I2C 0x73 (7-Bit) 8 + 9 + Author: Thilo Cestonaro <thilo.cestonaro@ts.fujitsu.com> 10 + 11 + 12 + Description 13 + ----------- 14 + The BMC Teutates is the Eleventh generation of Superior System 15 + monitoring and thermal management solution. It is builds on the basic 16 + functionality of the BMC Theseus and contains several new features and 17 + enhancements. It can monitor up to 4 voltages, 16 temperatures and 18 + 8 fans. It also contains an integrated watchdog which is currently 19 + implemented in this driver. 20 + 21 + Specification of the chip can be found here: 22 + ftp:///pub/Mainboard-OEM-Sales/Services/Software&Tools/Linux_SystemMonitoring&Watchdog&GPIO/BMC-Teutates_Specification_V1.21.pdf 23 + ftp:///pub/Mainboard-OEM-Sales/Services/Software&Tools/Linux_SystemMonitoring&Watchdog&GPIO/Fujitsu_mainboards-1-Sensors_HowTo-en-US.pdf
+35
Documentation/hwmon/ina3221
··· 1 + Kernel driver ina3221 2 + ===================== 3 + 4 + Supported chips: 5 + * Texas Instruments INA3221 6 + Prefix: 'ina3221' 7 + Addresses: I2C 0x40 - 0x43 8 + Datasheet: Publicly available at the Texas Instruments website 9 + http://www.ti.com/ 10 + 11 + Author: Andrew F. Davis <afd@ti.com> 12 + 13 + Description 14 + ----------- 15 + 16 + The Texas Instruments INA3221 monitors voltage, current, and power on the high 17 + side of up to three D.C. power supplies. The INA3221 monitors both shunt drop 18 + and supply voltage, with programmable conversion times and averaging, current 19 + and power are calculated host-side from these. 20 + 21 + Sysfs entries 22 + ------------- 23 + 24 + in[123]_input Bus voltage(mV) channels 25 + curr[123]_input Current(mA) measurement channels 26 + shunt[123]_resistor Shunt resistance(uOhm) channels 27 + curr[123]_crit Critical alert current(mA) setting, activates the 28 + corresponding alarm when the respective current 29 + is above this value 30 + curr[123]_crit_alarm Critical alert current limit exceeded 31 + curr[123]_max Warning alert current(mA) setting, activates the 32 + corresponding alarm when the respective current 33 + average is above this value. 34 + curr[123]_max_alarm Warning alert current limit exceeded 35 + in[456]_input Shunt voltage(uV) for channels 1, 2, and 3 respectively
+2 -1
Documentation/hwmon/jc42
··· 18 18 * Maxim MAX6604 19 19 Datasheets: 20 20 http://datasheets.maxim-ic.com/en/ds/MAX6604.pdf 21 - * Microchip MCP9804, MCP9805, MCP98242, MCP98243, MCP98244, MCP9843 21 + * Microchip MCP9804, MCP9805, MCP9808, MCP98242, MCP98243, MCP98244, MCP9843 22 22 Datasheets: 23 23 http://ww1.microchip.com/downloads/en/DeviceDoc/22203C.pdf 24 24 http://ww1.microchip.com/downloads/en/DeviceDoc/21977b.pdf 25 + http://ww1.microchip.com/downloads/en/DeviceDoc/25095A.pdf 25 26 http://ww1.microchip.com/downloads/en/DeviceDoc/21996a.pdf 26 27 http://ww1.microchip.com/downloads/en/DeviceDoc/22153c.pdf 27 28 http://ww1.microchip.com/downloads/en/DeviceDoc/22327A.pdf
+1 -1
Documentation/hwmon/max1668
··· 17 17 chips. 18 18 19 19 The three devices are very similar, but the MAX1805 has a reduced feature 20 - set; only two remote temperature inputs vs the four avaible on the other 20 + set; only two remote temperature inputs vs the four available on the other 21 21 two ICs. 22 22 23 23 The driver is able to distinguish between the devices and creates sysfs
+76
Documentation/hwmon/sht3x
··· 1 + Kernel driver sht3x 2 + =================== 3 + 4 + Supported chips: 5 + * Sensirion SHT3x-DIS 6 + Prefix: 'sht3x' 7 + Addresses scanned: none 8 + Datasheet: http://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/Humidity/Sensirion_Humidity_Datasheet_SHT3x_DIS.pdf 9 + 10 + Author: 11 + David Frey <david.frey@sensirion.com> 12 + Pascal Sachs <pascal.sachs@sensirion.com> 13 + 14 + Description 15 + ----------- 16 + 17 + This driver implements support for the Sensirion SHT3x-DIS chip, a humidity 18 + and temperature sensor. Temperature is measured in degrees celsius, relative 19 + humidity is expressed as a percentage. In the sysfs interface, all values are 20 + scaled by 1000, i.e. the value for 31.5 degrees celsius is 31500. 21 + 22 + The device communicates with the I2C protocol. Sensors can have the I2C 23 + addresses 0x44 or 0x45, depending on the wiring. See 24 + Documentation/i2c/instantiating-devices for methods to instantiate the device. 25 + 26 + There are two options configurable by means of sht3x_platform_data: 27 + 1. blocking (pull the I2C clock line down while performing the measurement) or 28 + non-blocking mode. Blocking mode will guarantee the fastest result but 29 + the I2C bus will be busy during that time. By default, non-blocking mode 30 + is used. Make sure clock-stretching works properly on your device if you 31 + want to use blocking mode. 32 + 2. high or low accuracy. High accuracy is used by default and using it is 33 + strongly recommended. 34 + 35 + The sht3x sensor supports a single shot mode as well as 5 periodic measure 36 + modes, which can be controlled with the update_interval sysfs interface. 37 + The allowed update_interval in milliseconds are as follows: 38 + * 0 single shot mode 39 + * 2000 0.5 Hz periodic measurement 40 + * 1000 1 Hz periodic measurement 41 + * 500 2 Hz periodic measurement 42 + * 250 4 Hz periodic measurement 43 + * 100 10 Hz periodic measurement 44 + 45 + In the periodic measure mode, the sensor automatically triggers a measurement 46 + with the configured update interval on the chip. When a temperature or humidity 47 + reading exceeds the configured limits, the alert attribute is set to 1 and 48 + the alert pin on the sensor is set to high. 49 + When the temperature and humidity readings move back between the hysteresis 50 + values, the alert bit is set to 0 and the alert pin on the sensor is set to 51 + low. 52 + 53 + sysfs-Interface 54 + --------------- 55 + 56 + temp1_input: temperature input 57 + humidity1_input: humidity input 58 + temp1_max: temperature max value 59 + temp1_max_hyst: temperature hysteresis value for max limit 60 + humidity1_max: humidity max value 61 + humidity1_max_hyst: humidity hysteresis value for max limit 62 + temp1_min: temperature min value 63 + temp1_min_hyst: temperature hysteresis value for min limit 64 + humidity1_min: humidity min value 65 + humidity1_min_hyst: humidity hysteresis value for min limit 66 + temp1_alarm: alarm flag is set to 1 if the temperature is outside the 67 + configured limits. Alarm only works in periodic measure mode 68 + humidity1_alarm: alarm flag is set to 1 if the humidity is outside the 69 + configured limits. Alarm only works in periodic measure mode 70 + heater_enable: heater enable, heating element removes excess humidity from 71 + sensor 72 + 0: turned off 73 + 1: turned on 74 + update_interval: update interval, 0 for single shot, interval in msec 75 + for periodic measurement. If the interval is not supported 76 + by the sensor, the next faster interval is chosen
+34 -6
Documentation/hwmon/submitting-patches
··· 15 15 Documentation/SubmittingPatches 16 16 Documentation/CodingStyle 17 17 18 - * If your patch generates checkpatch warnings, please refrain from explanations 19 - such as "I don't like that coding style". Keep in mind that each unnecessary 20 - warning helps hiding a real problem. If you don't like the kernel coding 21 - style, don't write kernel drivers. 18 + * Please run your patch through 'checkpatch --strict'. There should be no 19 + errors, no warnings, and few if any check messages. If there are any 20 + messages, please be prepared to explain. 21 + 22 + * If your patch generates checkpatch errors, warnings, or check messages, 23 + please refrain from explanations such as "I prefer that coding style". 24 + Keep in mind that each unnecessary message helps hiding a real problem, 25 + and a consistent coding style makes it easier for others to understand 26 + and review the code. 22 27 23 28 * Please test your patch thoroughly. We are not your test group. 24 29 Sometimes a patch can not or not completely be tested because of missing ··· 66 61 67 62 * Make sure that all dependencies are listed in Kconfig. 68 63 64 + * Please list include files in alphabetic order. 65 + 66 + * Please align continuation lines with '(' on the previous line. 67 + 69 68 * Avoid forward declarations if you can. Rearrange the code if necessary. 69 + 70 + * Avoid macros to generate groups of sensor attributes. It not only confuses 71 + checkpatch, but also makes it more difficult to review the code. 70 72 71 73 * Avoid calculations in macros and macro-generated functions. While such macros 72 74 may save a line or so in the source, it obfuscates the code and makes code 73 75 review more difficult. It may also result in code which is more complicated 74 76 than necessary. Use inline functions or just regular functions instead. 75 77 78 + * Limit the number of kernel log messages. In general, your driver should not 79 + generate an error message just because a runtime operation failed. Report 80 + errors to user space instead, using an appropriate error code. Keep in mind 81 + that kernel error log messages not only fill up the kernel log, but also are 82 + printed synchronously, most likely with interrupt disabled, often to a serial 83 + console. Excessive logging can seriously affect system performance. 84 + 76 85 * Use devres functions whenever possible to allocate resources. For rationale 77 86 and supported functions, please see Documentation/driver-model/devres.txt. 87 + If a function is not supported by devres, consider using devm_add_action(). 78 88 79 89 * If the driver has a detect function, make sure it is silent. Debug messages 80 90 and messages printed after a successful detection are acceptable, but it ··· 116 96 writing to it might cause a bad misconfiguration. 117 97 118 98 * Make sure there are no race conditions in the probe function. Specifically, 119 - completely initialize your chip first, then create sysfs entries and register 120 - with the hwmon subsystem. 99 + completely initialize your chip and your driver first, then register with 100 + the hwmon subsystem. 101 + 102 + * Use devm_hwmon_device_register_with_groups() or, if your driver needs a remove 103 + function, hwmon_device_register_with_groups() to register your driver with the 104 + hwmon subsystem. Try using devm_add_action() instead of a remove function if 105 + possible. Do not use hwmon_device_register(). 106 + 107 + * Your driver should be buildable as module. If not, please be prepared to 108 + explain why it has to be built into the kernel. 121 109 122 110 * Do not provide support for deprecated sysfs attributes. 123 111
+12 -2
Documentation/hwmon/tmp401
··· 22 22 Prefix: 'tmp435' 23 23 Addresses scanned: I2C 0x48 - 0x4f 24 24 Datasheet: http://focus.ti.com/docs/prod/folders/print/tmp435.html 25 + * Texas Instruments TMP461 26 + Prefix: 'tmp461' 27 + Datasheet: http://www.ti.com/product/tmp461 25 28 26 29 Authors: 27 30 Hans de Goede <hdegoede@redhat.com> ··· 34 31 ----------- 35 32 36 33 This driver implements support for Texas Instruments TMP401, TMP411, 37 - TMP431, TMP432 and TMP435 chips. These chips implement one or two remote 38 - and one local temperature sensors. Temperature is measured in degrees 34 + TMP431, TMP432, TMP435, and TMP461 chips. These chips implement one or two 35 + remote and one local temperature sensors. Temperature is measured in degrees 39 36 Celsius. Resolution of the remote sensor is 0.0625 degree. Local 40 37 sensor resolution can be set to 0.5, 0.25, 0.125 or 0.0625 degree (not 41 38 supported by the driver so far, so using the default resolution of 0.5 ··· 58 55 59 56 TMP432 is compatible with TMP401 and TMP431. It supports two external 60 57 temperature sensors. 58 + 59 + TMP461 is compatible with TMP401. It supports offset correction 60 + that is applied to the remote sensor. 61 + 62 + * Sensor offset values are temperature values 63 + 64 + Exported via sysfs attribute tempX_offset
+39 -3
drivers/hwmon/Kconfig
··· 486 486 This driver can also be built as a module. If so, the module 487 487 will be called fschmd. 488 488 489 + config SENSORS_FTSTEUTATES 490 + tristate "Fujitsu Technology Solutions sensor chip Teutates" 491 + depends on I2C && WATCHDOG 492 + select WATCHDOG_CORE 493 + help 494 + If you say yes here you get support for the Fujitsu Technology 495 + Solutions (FTS) sensor chip "Teutates" including support for 496 + the integrated watchdog. 497 + 498 + This driver can also be built as a module. If so, the module 499 + will be called ftsteutates. 500 + 489 501 config SENSORS_GL518SM 490 502 tristate "Genesys Logic GL518SM" 491 503 depends on I2C ··· 657 645 temperature sensors, which are used on many DDR3 memory modules for 658 646 mobile devices and servers. Support will include, but not be limited 659 647 to, ADT7408, AT30TS00, CAT34TS02, CAT6095, MAX6604, MCP9804, MCP9805, 660 - MCP98242, MCP98243, MCP98244, MCP9843, SE97, SE98, STTS424(E), 661 - STTS2002, STTS3000, TSE2002, TSE2004, TS3000, and TS3001. 648 + MCP9808, MCP98242, MCP98243, MCP98244, MCP9843, SE97, SE98, 649 + STTS424(E), STTS2002, STTS3000, TSE2002, TSE2004, TS3000, and TS3001. 662 650 663 651 This driver can also be built as a module. If so, the module 664 652 will be called jc42. ··· 970 958 tristate "National Semiconductor LM75 and compatibles" 971 959 depends on I2C 972 960 depends on THERMAL || !THERMAL_OF 961 + select REGMAP_I2C 973 962 help 974 963 If you say yes here you get support for one common type of 975 964 temperature sensor chip, with models including: ··· 1278 1265 This driver can also be built as a module. If so, the module 1279 1266 will be called sht21. 1280 1267 1268 + config SENSORS_SHT3x 1269 + tristate "Sensiron humidity and temperature sensors. SHT3x and compat." 1270 + depends on I2C 1271 + select CRC8 1272 + help 1273 + If you say yes here you get support for the Sensiron SHT30 and SHT31 1274 + humidity and temperature sensors. 1275 + 1276 + This driver can also be built as a module. If so, the module 1277 + will be called sht3x. 1278 + 1281 1279 config SENSORS_SHTC1 1282 1280 tristate "Sensiron humidity and temperature sensors. SHTC1 and compat." 1283 1281 depends on I2C ··· 1538 1514 This driver can also be built as a module. If so, the module 1539 1515 will be called ina2xx. 1540 1516 1517 + config SENSORS_INA3221 1518 + tristate "Texas Instruments INA3221 Triple Power Monitor" 1519 + depends on I2C 1520 + select REGMAP_I2C 1521 + help 1522 + If you say yes here you get support for the TI INA3221 Triple Power 1523 + Monitor. 1524 + 1525 + This driver can also be built as a module. If so, the module 1526 + will be called ina3221. 1527 + 1541 1528 config SENSORS_TC74 1542 1529 tristate "Microchip TC74" 1543 1530 depends on I2C ··· 1573 1538 tristate "Texas Instruments TMP102" 1574 1539 depends on I2C 1575 1540 depends on THERMAL || !THERMAL_OF 1541 + select REGMAP_I2C 1576 1542 help 1577 1543 If you say yes here you get support for Texas Instruments TMP102 1578 1544 sensor chips. ··· 1597 1561 depends on I2C 1598 1562 help 1599 1563 If you say yes here you get support for Texas Instruments TMP401, 1600 - TMP411, TMP431, TMP432 and TMP435 temperature sensor chips. 1564 + TMP411, TMP431, TMP432, TMP435, and TMP461 temperature sensor chips. 1601 1565 1602 1566 This driver can also be built as a module. If so, the module 1603 1567 will be called tmp401.
+3
drivers/hwmon/Makefile
··· 62 62 obj-$(CONFIG_SENSORS_F75375S) += f75375s.o 63 63 obj-$(CONFIG_SENSORS_FAM15H_POWER) += fam15h_power.o 64 64 obj-$(CONFIG_SENSORS_FSCHMD) += fschmd.o 65 + obj-$(CONFIG_SENSORS_FTSTEUTATES) += ftsteutates.o 65 66 obj-$(CONFIG_SENSORS_G760A) += g760a.o 66 67 obj-$(CONFIG_SENSORS_G762) += g762.o 67 68 obj-$(CONFIG_SENSORS_GL518SM) += gl518sm.o ··· 78 77 obj-$(CONFIG_SENSORS_IIO_HWMON) += iio_hwmon.o 79 78 obj-$(CONFIG_SENSORS_INA209) += ina209.o 80 79 obj-$(CONFIG_SENSORS_INA2XX) += ina2xx.o 80 + obj-$(CONFIG_SENSORS_INA3221) += ina3221.o 81 81 obj-$(CONFIG_SENSORS_IT87) += it87.o 82 82 obj-$(CONFIG_SENSORS_JC42) += jc42.o 83 83 obj-$(CONFIG_SENSORS_JZ4740) += jz4740-hwmon.o ··· 140 138 obj-$(CONFIG_SENSORS_SCH5636) += sch5636.o 141 139 obj-$(CONFIG_SENSORS_SHT15) += sht15.o 142 140 obj-$(CONFIG_SENSORS_SHT21) += sht21.o 141 + obj-$(CONFIG_SENSORS_SHT3x) += sht3x.o 143 142 obj-$(CONFIG_SENSORS_SHTC1) += shtc1.o 144 143 obj-$(CONFIG_SENSORS_SIS5595) += sis5595.o 145 144 obj-$(CONFIG_SENSORS_SMM665) += smm665.o
+7 -41
drivers/hwmon/ad7314.c
··· 37 37 38 38 struct ad7314_data { 39 39 struct spi_device *spi_dev; 40 - struct device *hwmon_dev; 41 40 u16 rx ____cacheline_aligned; 42 41 }; 43 42 ··· 87 88 } 88 89 } 89 90 90 - static ssize_t ad7314_show_name(struct device *dev, 91 - struct device_attribute *devattr, char *buf) 92 - { 93 - return sprintf(buf, "%s\n", to_spi_device(dev)->modalias); 94 - } 95 - 96 - static DEVICE_ATTR(name, S_IRUGO, ad7314_show_name, NULL); 97 91 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, 98 92 ad7314_show_temperature, NULL, 0); 99 93 100 - static struct attribute *ad7314_attributes[] = { 101 - &dev_attr_name.attr, 94 + static struct attribute *ad7314_attrs[] = { 102 95 &sensor_dev_attr_temp1_input.dev_attr.attr, 103 96 NULL, 104 97 }; 105 98 106 - static const struct attribute_group ad7314_group = { 107 - .attrs = ad7314_attributes, 108 - }; 99 + ATTRIBUTE_GROUPS(ad7314); 109 100 110 101 static int ad7314_probe(struct spi_device *spi_dev) 111 102 { 112 - int ret; 113 103 struct ad7314_data *chip; 104 + struct device *hwmon_dev; 114 105 115 106 chip = devm_kzalloc(&spi_dev->dev, sizeof(*chip), GFP_KERNEL); 116 107 if (chip == NULL) 117 108 return -ENOMEM; 118 109 119 - spi_set_drvdata(spi_dev, chip); 120 - 121 - ret = sysfs_create_group(&spi_dev->dev.kobj, &ad7314_group); 122 - if (ret < 0) 123 - return ret; 124 - 125 - chip->hwmon_dev = hwmon_device_register(&spi_dev->dev); 126 - if (IS_ERR(chip->hwmon_dev)) { 127 - ret = PTR_ERR(chip->hwmon_dev); 128 - goto error_remove_group; 129 - } 130 110 chip->spi_dev = spi_dev; 131 - 132 - return 0; 133 - error_remove_group: 134 - sysfs_remove_group(&spi_dev->dev.kobj, &ad7314_group); 135 - return ret; 136 - } 137 - 138 - static int ad7314_remove(struct spi_device *spi_dev) 139 - { 140 - struct ad7314_data *chip = spi_get_drvdata(spi_dev); 141 - 142 - hwmon_device_unregister(chip->hwmon_dev); 143 - sysfs_remove_group(&spi_dev->dev.kobj, &ad7314_group); 144 - 145 - return 0; 111 + hwmon_dev = devm_hwmon_device_register_with_groups(&spi_dev->dev, 112 + spi_dev->modalias, 113 + chip, ad7314_groups); 114 + return PTR_ERR_OR_ZERO(hwmon_dev); 146 115 } 147 116 148 117 static const struct spi_device_id ad7314_id[] = { ··· 126 159 .name = "ad7314", 127 160 }, 128 161 .probe = ad7314_probe, 129 - .remove = ad7314_remove, 130 162 .id_table = ad7314_id, 131 163 }; 132 164
+15 -50
drivers/hwmon/ads7871.c
··· 66 66 #include <linux/hwmon.h> 67 67 #include <linux/hwmon-sysfs.h> 68 68 #include <linux/err.h> 69 - #include <linux/mutex.h> 70 69 #include <linux/delay.h> 71 70 72 71 #define DEVICE_NAME "ads7871" 73 72 74 73 struct ads7871_data { 75 - struct device *hwmon_dev; 76 - struct mutex update_lock; 74 + struct spi_device *spi; 77 75 }; 78 76 79 77 static int ads7871_read_reg8(struct spi_device *spi, int reg) ··· 99 101 static ssize_t show_voltage(struct device *dev, 100 102 struct device_attribute *da, char *buf) 101 103 { 102 - struct spi_device *spi = to_spi_device(dev); 104 + struct ads7871_data *pdata = dev_get_drvdata(dev); 105 + struct spi_device *spi = pdata->spi; 103 106 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 104 107 int ret, val, i = 0; 105 108 uint8_t channel, mux_cnv; ··· 138 139 } 139 140 } 140 141 141 - static ssize_t ads7871_show_name(struct device *dev, 142 - struct device_attribute *devattr, char *buf) 143 - { 144 - return sprintf(buf, "%s\n", to_spi_device(dev)->modalias); 145 - } 146 - 147 142 static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_voltage, NULL, 0); 148 143 static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_voltage, NULL, 1); 149 144 static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_voltage, NULL, 2); ··· 147 154 static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_voltage, NULL, 6); 148 155 static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_voltage, NULL, 7); 149 156 150 - static DEVICE_ATTR(name, S_IRUGO, ads7871_show_name, NULL); 151 - 152 - static struct attribute *ads7871_attributes[] = { 157 + static struct attribute *ads7871_attrs[] = { 153 158 &sensor_dev_attr_in0_input.dev_attr.attr, 154 159 &sensor_dev_attr_in1_input.dev_attr.attr, 155 160 &sensor_dev_attr_in2_input.dev_attr.attr, ··· 156 165 &sensor_dev_attr_in5_input.dev_attr.attr, 157 166 &sensor_dev_attr_in6_input.dev_attr.attr, 158 167 &sensor_dev_attr_in7_input.dev_attr.attr, 159 - &dev_attr_name.attr, 160 168 NULL 161 169 }; 162 170 163 - static const struct attribute_group ads7871_group = { 164 - .attrs = ads7871_attributes, 165 - }; 171 + ATTRIBUTE_GROUPS(ads7871); 166 172 167 173 static int ads7871_probe(struct spi_device *spi) 168 174 { 169 - int ret, err; 175 + struct device *dev = &spi->dev; 176 + int ret; 170 177 uint8_t val; 171 178 struct ads7871_data *pdata; 172 - 173 - dev_dbg(&spi->dev, "probe\n"); 179 + struct device *hwmon_dev; 174 180 175 181 /* Configure the SPI bus */ 176 182 spi->mode = (SPI_MODE_0); ··· 181 193 ads7871_write_reg8(spi, REG_OSC_CONTROL, val); 182 194 ret = ads7871_read_reg8(spi, REG_OSC_CONTROL); 183 195 184 - dev_dbg(&spi->dev, "REG_OSC_CONTROL write:%x, read:%x\n", val, ret); 196 + dev_dbg(dev, "REG_OSC_CONTROL write:%x, read:%x\n", val, ret); 185 197 /* 186 198 * because there is no other error checking on an SPI bus 187 199 * we need to make sure we really have a chip ··· 189 201 if (val != ret) 190 202 return -ENODEV; 191 203 192 - pdata = devm_kzalloc(&spi->dev, sizeof(struct ads7871_data), 193 - GFP_KERNEL); 204 + pdata = devm_kzalloc(dev, sizeof(struct ads7871_data), GFP_KERNEL); 194 205 if (!pdata) 195 206 return -ENOMEM; 196 207 197 - err = sysfs_create_group(&spi->dev.kobj, &ads7871_group); 198 - if (err < 0) 199 - return err; 208 + pdata->spi = spi; 200 209 201 - spi_set_drvdata(spi, pdata); 202 - 203 - pdata->hwmon_dev = hwmon_device_register(&spi->dev); 204 - if (IS_ERR(pdata->hwmon_dev)) { 205 - err = PTR_ERR(pdata->hwmon_dev); 206 - goto error_remove; 207 - } 208 - 209 - return 0; 210 - 211 - error_remove: 212 - sysfs_remove_group(&spi->dev.kobj, &ads7871_group); 213 - return err; 214 - } 215 - 216 - static int ads7871_remove(struct spi_device *spi) 217 - { 218 - struct ads7871_data *pdata = spi_get_drvdata(spi); 219 - 220 - hwmon_device_unregister(pdata->hwmon_dev); 221 - sysfs_remove_group(&spi->dev.kobj, &ads7871_group); 222 - return 0; 210 + hwmon_dev = devm_hwmon_device_register_with_groups(dev, spi->modalias, 211 + pdata, 212 + ads7871_groups); 213 + return PTR_ERR_OR_ZERO(hwmon_dev); 223 214 } 224 215 225 216 static struct spi_driver ads7871_driver = { 226 217 .driver = { 227 218 .name = DEVICE_NAME, 228 219 }, 229 - 230 220 .probe = ads7871_probe, 231 - .remove = ads7871_remove, 232 221 }; 233 222 234 223 module_spi_driver(ads7871_driver);
+4 -1
drivers/hwmon/adt7411.c
··· 30 30 31 31 #define ADT7411_REG_CFG1 0x18 32 32 #define ADT7411_CFG1_START_MONITOR (1 << 0) 33 + #define ADT7411_CFG1_RESERVED_BIT3 (1 << 3) 33 34 34 35 #define ADT7411_REG_CFG2 0x19 35 36 #define ADT7411_CFG2_DISABLE_AVG (1 << 5) ··· 297 296 mutex_init(&data->device_lock); 298 297 mutex_init(&data->update_lock); 299 298 299 + /* According to the datasheet, we must only write 1 to bit 3 */ 300 300 ret = adt7411_modify_bit(client, ADT7411_REG_CFG1, 301 - ADT7411_CFG1_START_MONITOR, 1); 301 + ADT7411_CFG1_RESERVED_BIT3 302 + | ADT7411_CFG1_START_MONITOR, 1); 302 303 if (ret < 0) 303 304 return ret; 304 305
+39 -2
drivers/hwmon/dell-smm-hwmon.c
··· 81 81 #define I8K_HWMON_HAVE_TEMP4 (1 << 3) 82 82 #define I8K_HWMON_HAVE_FAN1 (1 << 4) 83 83 #define I8K_HWMON_HAVE_FAN2 (1 << 5) 84 + #define I8K_HWMON_HAVE_FAN3 (1 << 6) 84 85 85 86 MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)"); 86 87 MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>"); ··· 139 138 int rc; 140 139 int eax = regs->eax; 141 140 cpumask_var_t old_mask; 141 + 142 + #ifdef DEBUG 143 + int ebx = regs->ebx; 144 + unsigned long duration; 145 + ktime_t calltime, delta, rettime; 146 + 147 + calltime = ktime_get(); 148 + #endif 142 149 143 150 /* SMM requires CPU 0 */ 144 151 if (!alloc_cpumask_var(&old_mask, GFP_KERNEL)) ··· 219 210 out: 220 211 set_cpus_allowed_ptr(current, old_mask); 221 212 free_cpumask_var(old_mask); 213 + 214 + #ifdef DEBUG 215 + rettime = ktime_get(); 216 + delta = ktime_sub(rettime, calltime); 217 + duration = ktime_to_ns(delta) >> 10; 218 + pr_debug("smm(0x%.4x 0x%.4x) = 0x%.4x (took %7lu usecs)\n", eax, ebx, 219 + (rc ? 0xffff : regs->eax & 0xffff), duration); 220 + #endif 221 + 222 222 return rc; 223 223 } 224 224 ··· 270 252 static int i8k_get_fan_type(int fan) 271 253 { 272 254 /* I8K_SMM_GET_FAN_TYPE SMM call is expensive, so cache values */ 273 - static int types[2] = { INT_MIN, INT_MIN }; 255 + static int types[3] = { INT_MIN, INT_MIN, INT_MIN }; 274 256 275 257 if (types[fan] == INT_MIN) 276 258 types[fan] = _i8k_get_fan_type(fan); ··· 737 719 1); 738 720 static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm, 739 721 i8k_hwmon_set_pwm, 1); 722 + static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, i8k_hwmon_show_fan, NULL, 723 + 2); 724 + static SENSOR_DEVICE_ATTR(fan3_label, S_IRUGO, i8k_hwmon_show_fan_label, NULL, 725 + 2); 726 + static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, i8k_hwmon_show_pwm, 727 + i8k_hwmon_set_pwm, 2); 740 728 741 729 static struct attribute *i8k_attrs[] = { 742 730 &sensor_dev_attr_temp1_input.dev_attr.attr, /* 0 */ ··· 759 735 &sensor_dev_attr_fan2_input.dev_attr.attr, /* 11 */ 760 736 &sensor_dev_attr_fan2_label.dev_attr.attr, /* 12 */ 761 737 &sensor_dev_attr_pwm2.dev_attr.attr, /* 13 */ 738 + &sensor_dev_attr_fan3_input.dev_attr.attr, /* 14 */ 739 + &sensor_dev_attr_fan3_label.dev_attr.attr, /* 15 */ 740 + &sensor_dev_attr_pwm3.dev_attr.attr, /* 16 */ 762 741 NULL 763 742 }; 764 743 ··· 769 742 int index) 770 743 { 771 744 if (disallow_fan_type_call && 772 - (index == 9 || index == 12)) 745 + (index == 9 || index == 12 || index == 15)) 773 746 return 0; 774 747 if (index >= 0 && index <= 1 && 775 748 !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1)) ··· 788 761 return 0; 789 762 if (index >= 11 && index <= 13 && 790 763 !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2)) 764 + return 0; 765 + if (index >= 14 && index <= 16 && 766 + !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN3)) 791 767 return 0; 792 768 793 769 return attr->mode; ··· 836 806 err = i8k_get_fan_type(1); 837 807 if (err >= 0) 838 808 i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN2; 809 + 810 + /* Third fan attributes, if fan status or type is OK */ 811 + err = i8k_get_fan_status(2); 812 + if (err < 0) 813 + err = i8k_get_fan_type(2); 814 + if (err >= 0) 815 + i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN3; 839 816 840 817 i8k_hwmon_dev = hwmon_device_register_with_groups(NULL, "dell_smm", 841 818 NULL, i8k_groups);
+1 -1
drivers/hwmon/emc6w201.c
··· 464 464 if (verstep < 0 || (verstep & 0xF0) != 0xB0) 465 465 return -ENODEV; 466 466 if ((verstep & 0x0F) > 2) { 467 - dev_dbg(&client->dev, "Unknwown EMC6W201 stepping %d\n", 467 + dev_dbg(&client->dev, "Unknown EMC6W201 stepping %d\n", 468 468 verstep & 0x0F); 469 469 return -ENODEV; 470 470 }
+819
drivers/hwmon/ftsteutates.c
··· 1 + /* 2 + * Support for the FTS Systemmonitoring Chip "Teutates" 3 + * 4 + * Copyright (C) 2016 Fujitsu Technology Solutions GmbH, 5 + * Thilo Cestonaro <thilo.cestonaro@ts.fujitsu.com> 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License as published by 9 + * the Free Software Foundation; either version 2 of the License, or 10 + * (at your option) any later version. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + * 17 + */ 18 + #include <linux/err.h> 19 + #include <linux/fs.h> 20 + #include <linux/hwmon.h> 21 + #include <linux/hwmon-sysfs.h> 22 + #include <linux/i2c.h> 23 + #include <linux/init.h> 24 + #include <linux/jiffies.h> 25 + #include <linux/module.h> 26 + #include <linux/mutex.h> 27 + #include <linux/slab.h> 28 + #include <linux/sysfs.h> 29 + #include <linux/uaccess.h> 30 + #include <linux/watchdog.h> 31 + 32 + #define FTS_DEVICE_ID_REG 0x0000 33 + #define FTS_DEVICE_REVISION_REG 0x0001 34 + #define FTS_DEVICE_STATUS_REG 0x0004 35 + #define FTS_SATELLITE_STATUS_REG 0x0005 36 + #define FTS_EVENT_STATUS_REG 0x0006 37 + #define FTS_GLOBAL_CONTROL_REG 0x0007 38 + 39 + #define FTS_SENSOR_EVENT_REG 0x0010 40 + 41 + #define FTS_FAN_EVENT_REG 0x0014 42 + #define FTS_FAN_PRESENT_REG 0x0015 43 + 44 + #define FTS_POWER_ON_TIME_COUNTER_A 0x007A 45 + #define FTS_POWER_ON_TIME_COUNTER_B 0x007B 46 + #define FTS_POWER_ON_TIME_COUNTER_C 0x007C 47 + 48 + #define FTS_PAGE_SELECT_REG 0x007F 49 + 50 + #define FTS_WATCHDOG_TIME_PRESET 0x000B 51 + #define FTS_WATCHDOG_CONTROL 0x5081 52 + 53 + #define FTS_NO_FAN_SENSORS 0x08 54 + #define FTS_NO_TEMP_SENSORS 0x10 55 + #define FTS_NO_VOLT_SENSORS 0x04 56 + 57 + static struct i2c_device_id fts_id[] = { 58 + { "ftsteutates", 0 }, 59 + { } 60 + }; 61 + MODULE_DEVICE_TABLE(i2c, fts_id); 62 + 63 + enum WATCHDOG_RESOLUTION { 64 + seconds = 1, 65 + minutes = 60 66 + }; 67 + 68 + struct fts_data { 69 + struct i2c_client *client; 70 + /* update sensor data lock */ 71 + struct mutex update_lock; 72 + /* read/write register lock */ 73 + struct mutex access_lock; 74 + unsigned long last_updated; /* in jiffies */ 75 + struct watchdog_device wdd; 76 + enum WATCHDOG_RESOLUTION resolution; 77 + bool valid; /* false until following fields are valid */ 78 + 79 + u8 volt[FTS_NO_VOLT_SENSORS]; 80 + 81 + u8 temp_input[FTS_NO_TEMP_SENSORS]; 82 + u8 temp_alarm; 83 + 84 + u8 fan_present; 85 + u8 fan_input[FTS_NO_FAN_SENSORS]; /* in rps */ 86 + u8 fan_source[FTS_NO_FAN_SENSORS]; 87 + u8 fan_alarm; 88 + }; 89 + 90 + #define FTS_REG_FAN_INPUT(idx) ((idx) + 0x20) 91 + #define FTS_REG_FAN_SOURCE(idx) ((idx) + 0x30) 92 + #define FTS_REG_FAN_CONTROL(idx) (((idx) << 16) + 0x4881) 93 + 94 + #define FTS_REG_TEMP_INPUT(idx) ((idx) + 0x40) 95 + #define FTS_REG_TEMP_CONTROL(idx) (((idx) << 16) + 0x0681) 96 + 97 + #define FTS_REG_VOLT(idx) ((idx) + 0x18) 98 + 99 + /*****************************************************************************/ 100 + /* I2C Helper functions */ 101 + /*****************************************************************************/ 102 + static int fts_read_byte(struct i2c_client *client, unsigned short reg) 103 + { 104 + int ret; 105 + unsigned char page = reg >> 8; 106 + struct fts_data *data = dev_get_drvdata(&client->dev); 107 + 108 + mutex_lock(&data->access_lock); 109 + 110 + dev_dbg(&client->dev, "page select - page: 0x%.02x\n", page); 111 + ret = i2c_smbus_write_byte_data(client, FTS_PAGE_SELECT_REG, page); 112 + if (ret < 0) 113 + goto error; 114 + 115 + reg &= 0xFF; 116 + ret = i2c_smbus_read_byte_data(client, reg); 117 + dev_dbg(&client->dev, "read - reg: 0x%.02x: val: 0x%.02x\n", reg, ret); 118 + 119 + error: 120 + mutex_unlock(&data->access_lock); 121 + return ret; 122 + } 123 + 124 + static int fts_write_byte(struct i2c_client *client, unsigned short reg, 125 + unsigned char value) 126 + { 127 + int ret; 128 + unsigned char page = reg >> 8; 129 + struct fts_data *data = dev_get_drvdata(&client->dev); 130 + 131 + mutex_lock(&data->access_lock); 132 + 133 + dev_dbg(&client->dev, "page select - page: 0x%.02x\n", page); 134 + ret = i2c_smbus_write_byte_data(client, FTS_PAGE_SELECT_REG, page); 135 + if (ret < 0) 136 + goto error; 137 + 138 + reg &= 0xFF; 139 + dev_dbg(&client->dev, 140 + "write - reg: 0x%.02x: val: 0x%.02x\n", reg, value); 141 + ret = i2c_smbus_write_byte_data(client, reg, value); 142 + 143 + error: 144 + mutex_unlock(&data->access_lock); 145 + return ret; 146 + } 147 + 148 + /*****************************************************************************/ 149 + /* Data Updater Helper function */ 150 + /*****************************************************************************/ 151 + static int fts_update_device(struct fts_data *data) 152 + { 153 + int i; 154 + int err = 0; 155 + 156 + mutex_lock(&data->update_lock); 157 + if (!time_after(jiffies, data->last_updated + 2 * HZ) && data->valid) 158 + goto exit; 159 + 160 + err = fts_read_byte(data->client, FTS_DEVICE_STATUS_REG); 161 + if (err < 0) 162 + goto exit; 163 + 164 + data->valid = !!(err & 0x02); /* Data not ready yet */ 165 + if (unlikely(!data->valid)) { 166 + err = -EAGAIN; 167 + goto exit; 168 + } 169 + 170 + err = fts_read_byte(data->client, FTS_FAN_PRESENT_REG); 171 + if (err < 0) 172 + goto exit; 173 + data->fan_present = err; 174 + 175 + err = fts_read_byte(data->client, FTS_FAN_EVENT_REG); 176 + if (err < 0) 177 + goto exit; 178 + data->fan_alarm = err; 179 + 180 + for (i = 0; i < FTS_NO_FAN_SENSORS; i++) { 181 + if (data->fan_present & BIT(i)) { 182 + err = fts_read_byte(data->client, FTS_REG_FAN_INPUT(i)); 183 + if (err < 0) 184 + goto exit; 185 + data->fan_input[i] = err; 186 + 187 + err = fts_read_byte(data->client, 188 + FTS_REG_FAN_SOURCE(i)); 189 + if (err < 0) 190 + goto exit; 191 + data->fan_source[i] = err; 192 + } else { 193 + data->fan_input[i] = 0; 194 + data->fan_source[i] = 0; 195 + } 196 + } 197 + 198 + err = fts_read_byte(data->client, FTS_SENSOR_EVENT_REG); 199 + if (err < 0) 200 + goto exit; 201 + data->temp_alarm = err; 202 + 203 + for (i = 0; i < FTS_NO_TEMP_SENSORS; i++) { 204 + err = fts_read_byte(data->client, FTS_REG_TEMP_INPUT(i)); 205 + if (err < 0) 206 + goto exit; 207 + data->temp_input[i] = err; 208 + } 209 + 210 + for (i = 0; i < FTS_NO_VOLT_SENSORS; i++) { 211 + err = fts_read_byte(data->client, FTS_REG_VOLT(i)); 212 + if (err < 0) 213 + goto exit; 214 + data->volt[i] = err; 215 + } 216 + data->last_updated = jiffies; 217 + err = 0; 218 + exit: 219 + mutex_unlock(&data->update_lock); 220 + return err; 221 + } 222 + 223 + /*****************************************************************************/ 224 + /* Watchdog functions */ 225 + /*****************************************************************************/ 226 + static int fts_wd_set_resolution(struct fts_data *data, 227 + enum WATCHDOG_RESOLUTION resolution) 228 + { 229 + int ret; 230 + 231 + if (data->resolution == resolution) 232 + return 0; 233 + 234 + ret = fts_read_byte(data->client, FTS_WATCHDOG_CONTROL); 235 + if (ret < 0) 236 + return ret; 237 + 238 + if ((resolution == seconds && ret & BIT(1)) || 239 + (resolution == minutes && (ret & BIT(1)) == 0)) { 240 + data->resolution = resolution; 241 + return 0; 242 + } 243 + 244 + if (resolution == seconds) 245 + set_bit(1, (unsigned long *)&ret); 246 + else 247 + ret &= ~BIT(1); 248 + 249 + ret = fts_write_byte(data->client, FTS_WATCHDOG_CONTROL, ret); 250 + if (ret < 0) 251 + return ret; 252 + 253 + data->resolution = resolution; 254 + return ret; 255 + } 256 + 257 + static int fts_wd_set_timeout(struct watchdog_device *wdd, unsigned int timeout) 258 + { 259 + struct fts_data *data; 260 + enum WATCHDOG_RESOLUTION resolution = seconds; 261 + int ret; 262 + 263 + data = watchdog_get_drvdata(wdd); 264 + /* switch watchdog resolution to minutes if timeout does not fit 265 + * into a byte 266 + */ 267 + if (timeout > 0xFF) { 268 + timeout = DIV_ROUND_UP(timeout, 60) * 60; 269 + resolution = minutes; 270 + } 271 + 272 + ret = fts_wd_set_resolution(data, resolution); 273 + if (ret < 0) 274 + return ret; 275 + 276 + wdd->timeout = timeout; 277 + return 0; 278 + } 279 + 280 + static int fts_wd_start(struct watchdog_device *wdd) 281 + { 282 + struct fts_data *data = watchdog_get_drvdata(wdd); 283 + 284 + return fts_write_byte(data->client, FTS_WATCHDOG_TIME_PRESET, 285 + wdd->timeout / (u8)data->resolution); 286 + } 287 + 288 + static int fts_wd_stop(struct watchdog_device *wdd) 289 + { 290 + struct fts_data *data; 291 + 292 + data = watchdog_get_drvdata(wdd); 293 + return fts_write_byte(data->client, FTS_WATCHDOG_TIME_PRESET, 0); 294 + } 295 + 296 + static const struct watchdog_info fts_wd_info = { 297 + .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE, 298 + .identity = "FTS Teutates Hardware Watchdog", 299 + }; 300 + 301 + static const struct watchdog_ops fts_wd_ops = { 302 + .owner = THIS_MODULE, 303 + .start = fts_wd_start, 304 + .stop = fts_wd_stop, 305 + .set_timeout = fts_wd_set_timeout, 306 + }; 307 + 308 + static int fts_watchdog_init(struct fts_data *data) 309 + { 310 + int timeout, ret; 311 + 312 + watchdog_set_drvdata(&data->wdd, data); 313 + 314 + timeout = fts_read_byte(data->client, FTS_WATCHDOG_TIME_PRESET); 315 + if (timeout < 0) 316 + return timeout; 317 + 318 + /* watchdog not running, set timeout to a default of 60 sec. */ 319 + if (timeout == 0) { 320 + ret = fts_wd_set_resolution(data, seconds); 321 + if (ret < 0) 322 + return ret; 323 + data->wdd.timeout = 60; 324 + } else { 325 + ret = fts_read_byte(data->client, FTS_WATCHDOG_CONTROL); 326 + if (ret < 0) 327 + return ret; 328 + 329 + data->resolution = ret & BIT(1) ? seconds : minutes; 330 + data->wdd.timeout = timeout * (u8)data->resolution; 331 + set_bit(WDOG_HW_RUNNING, &data->wdd.status); 332 + } 333 + 334 + /* Register our watchdog part */ 335 + data->wdd.info = &fts_wd_info; 336 + data->wdd.ops = &fts_wd_ops; 337 + data->wdd.parent = &data->client->dev; 338 + data->wdd.min_timeout = 1; 339 + 340 + /* max timeout 255 minutes. */ 341 + data->wdd.max_hw_heartbeat_ms = 0xFF * 60 * MSEC_PER_SEC; 342 + 343 + return watchdog_register_device(&data->wdd); 344 + } 345 + 346 + /*****************************************************************************/ 347 + /* SysFS handler functions */ 348 + /*****************************************************************************/ 349 + static ssize_t show_in_value(struct device *dev, 350 + struct device_attribute *devattr, char *buf) 351 + { 352 + struct fts_data *data = dev_get_drvdata(dev); 353 + int index = to_sensor_dev_attr(devattr)->index; 354 + int err; 355 + 356 + err = fts_update_device(data); 357 + if (err < 0) 358 + return err; 359 + 360 + return sprintf(buf, "%u\n", data->volt[index]); 361 + } 362 + 363 + static ssize_t show_temp_value(struct device *dev, 364 + struct device_attribute *devattr, char *buf) 365 + { 366 + struct fts_data *data = dev_get_drvdata(dev); 367 + int index = to_sensor_dev_attr(devattr)->index; 368 + int err; 369 + 370 + err = fts_update_device(data); 371 + if (err < 0) 372 + return err; 373 + 374 + return sprintf(buf, "%u\n", data->temp_input[index]); 375 + } 376 + 377 + static ssize_t show_temp_fault(struct device *dev, 378 + struct device_attribute *devattr, char *buf) 379 + { 380 + struct fts_data *data = dev_get_drvdata(dev); 381 + int index = to_sensor_dev_attr(devattr)->index; 382 + int err; 383 + 384 + err = fts_update_device(data); 385 + if (err < 0) 386 + return err; 387 + 388 + /* 00h Temperature = Sensor Error */ 389 + return sprintf(buf, "%d\n", data->temp_input[index] == 0); 390 + } 391 + 392 + static ssize_t show_temp_alarm(struct device *dev, 393 + struct device_attribute *devattr, char *buf) 394 + { 395 + struct fts_data *data = dev_get_drvdata(dev); 396 + int index = to_sensor_dev_attr(devattr)->index; 397 + int err; 398 + 399 + err = fts_update_device(data); 400 + if (err < 0) 401 + return err; 402 + 403 + return sprintf(buf, "%u\n", !!(data->temp_alarm & BIT(index))); 404 + } 405 + 406 + static ssize_t 407 + clear_temp_alarm(struct device *dev, struct device_attribute *devattr, 408 + const char *buf, size_t count) 409 + { 410 + struct fts_data *data = dev_get_drvdata(dev); 411 + int index = to_sensor_dev_attr(devattr)->index; 412 + long ret; 413 + 414 + ret = fts_update_device(data); 415 + if (ret < 0) 416 + return ret; 417 + 418 + if (kstrtoul(buf, 10, &ret) || ret != 0) 419 + return -EINVAL; 420 + 421 + mutex_lock(&data->update_lock); 422 + ret = fts_read_byte(data->client, FTS_REG_TEMP_CONTROL(index)); 423 + if (ret < 0) 424 + goto error; 425 + 426 + ret = fts_write_byte(data->client, FTS_REG_TEMP_CONTROL(index), 427 + ret | 0x1); 428 + if (ret < 0) 429 + goto error; 430 + 431 + data->valid = false; 432 + error: 433 + mutex_unlock(&data->update_lock); 434 + return ret; 435 + } 436 + 437 + static ssize_t show_fan_value(struct device *dev, 438 + struct device_attribute *devattr, char *buf) 439 + { 440 + struct fts_data *data = dev_get_drvdata(dev); 441 + int index = to_sensor_dev_attr(devattr)->index; 442 + int err; 443 + 444 + err = fts_update_device(data); 445 + if (err < 0) 446 + return err; 447 + 448 + return sprintf(buf, "%u\n", data->fan_input[index]); 449 + } 450 + 451 + static ssize_t show_fan_source(struct device *dev, 452 + struct device_attribute *devattr, char *buf) 453 + { 454 + struct fts_data *data = dev_get_drvdata(dev); 455 + int index = to_sensor_dev_attr(devattr)->index; 456 + int err; 457 + 458 + err = fts_update_device(data); 459 + if (err < 0) 460 + return err; 461 + 462 + return sprintf(buf, "%u\n", data->fan_source[index]); 463 + } 464 + 465 + static ssize_t show_fan_alarm(struct device *dev, 466 + struct device_attribute *devattr, char *buf) 467 + { 468 + struct fts_data *data = dev_get_drvdata(dev); 469 + int index = to_sensor_dev_attr(devattr)->index; 470 + int err; 471 + 472 + err = fts_update_device(data); 473 + if (err < 0) 474 + return err; 475 + 476 + return sprintf(buf, "%d\n", !!(data->fan_alarm & BIT(index))); 477 + } 478 + 479 + static ssize_t 480 + clear_fan_alarm(struct device *dev, struct device_attribute *devattr, 481 + const char *buf, size_t count) 482 + { 483 + struct fts_data *data = dev_get_drvdata(dev); 484 + int index = to_sensor_dev_attr(devattr)->index; 485 + long ret; 486 + 487 + ret = fts_update_device(data); 488 + if (ret < 0) 489 + return ret; 490 + 491 + if (kstrtoul(buf, 10, &ret) || ret != 0) 492 + return -EINVAL; 493 + 494 + mutex_lock(&data->update_lock); 495 + ret = fts_read_byte(data->client, FTS_REG_FAN_CONTROL(index)); 496 + if (ret < 0) 497 + goto error; 498 + 499 + ret = fts_write_byte(data->client, FTS_REG_FAN_CONTROL(index), 500 + ret | 0x1); 501 + if (ret < 0) 502 + goto error; 503 + 504 + data->valid = false; 505 + error: 506 + mutex_unlock(&data->update_lock); 507 + return ret; 508 + } 509 + 510 + /*****************************************************************************/ 511 + /* SysFS structs */ 512 + /*****************************************************************************/ 513 + 514 + /* Temprature sensors */ 515 + static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_value, NULL, 0); 516 + static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp_value, NULL, 1); 517 + static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp_value, NULL, 2); 518 + static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp_value, NULL, 3); 519 + static SENSOR_DEVICE_ATTR(temp5_input, S_IRUGO, show_temp_value, NULL, 4); 520 + static SENSOR_DEVICE_ATTR(temp6_input, S_IRUGO, show_temp_value, NULL, 5); 521 + static SENSOR_DEVICE_ATTR(temp7_input, S_IRUGO, show_temp_value, NULL, 6); 522 + static SENSOR_DEVICE_ATTR(temp8_input, S_IRUGO, show_temp_value, NULL, 7); 523 + static SENSOR_DEVICE_ATTR(temp9_input, S_IRUGO, show_temp_value, NULL, 8); 524 + static SENSOR_DEVICE_ATTR(temp10_input, S_IRUGO, show_temp_value, NULL, 9); 525 + static SENSOR_DEVICE_ATTR(temp11_input, S_IRUGO, show_temp_value, NULL, 10); 526 + static SENSOR_DEVICE_ATTR(temp12_input, S_IRUGO, show_temp_value, NULL, 11); 527 + static SENSOR_DEVICE_ATTR(temp13_input, S_IRUGO, show_temp_value, NULL, 12); 528 + static SENSOR_DEVICE_ATTR(temp14_input, S_IRUGO, show_temp_value, NULL, 13); 529 + static SENSOR_DEVICE_ATTR(temp15_input, S_IRUGO, show_temp_value, NULL, 14); 530 + static SENSOR_DEVICE_ATTR(temp16_input, S_IRUGO, show_temp_value, NULL, 15); 531 + 532 + static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0); 533 + static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_temp_fault, NULL, 1); 534 + static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_temp_fault, NULL, 2); 535 + static SENSOR_DEVICE_ATTR(temp4_fault, S_IRUGO, show_temp_fault, NULL, 3); 536 + static SENSOR_DEVICE_ATTR(temp5_fault, S_IRUGO, show_temp_fault, NULL, 4); 537 + static SENSOR_DEVICE_ATTR(temp6_fault, S_IRUGO, show_temp_fault, NULL, 5); 538 + static SENSOR_DEVICE_ATTR(temp7_fault, S_IRUGO, show_temp_fault, NULL, 6); 539 + static SENSOR_DEVICE_ATTR(temp8_fault, S_IRUGO, show_temp_fault, NULL, 7); 540 + static SENSOR_DEVICE_ATTR(temp9_fault, S_IRUGO, show_temp_fault, NULL, 8); 541 + static SENSOR_DEVICE_ATTR(temp10_fault, S_IRUGO, show_temp_fault, NULL, 9); 542 + static SENSOR_DEVICE_ATTR(temp11_fault, S_IRUGO, show_temp_fault, NULL, 10); 543 + static SENSOR_DEVICE_ATTR(temp12_fault, S_IRUGO, show_temp_fault, NULL, 11); 544 + static SENSOR_DEVICE_ATTR(temp13_fault, S_IRUGO, show_temp_fault, NULL, 12); 545 + static SENSOR_DEVICE_ATTR(temp14_fault, S_IRUGO, show_temp_fault, NULL, 13); 546 + static SENSOR_DEVICE_ATTR(temp15_fault, S_IRUGO, show_temp_fault, NULL, 14); 547 + static SENSOR_DEVICE_ATTR(temp16_fault, S_IRUGO, show_temp_fault, NULL, 15); 548 + 549 + static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO | S_IWUSR, show_temp_alarm, 550 + clear_temp_alarm, 0); 551 + static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO | S_IWUSR, show_temp_alarm, 552 + clear_temp_alarm, 1); 553 + static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO | S_IWUSR, show_temp_alarm, 554 + clear_temp_alarm, 2); 555 + static SENSOR_DEVICE_ATTR(temp4_alarm, S_IRUGO | S_IWUSR, show_temp_alarm, 556 + clear_temp_alarm, 3); 557 + static SENSOR_DEVICE_ATTR(temp5_alarm, S_IRUGO | S_IWUSR, show_temp_alarm, 558 + clear_temp_alarm, 4); 559 + static SENSOR_DEVICE_ATTR(temp6_alarm, S_IRUGO | S_IWUSR, show_temp_alarm, 560 + clear_temp_alarm, 5); 561 + static SENSOR_DEVICE_ATTR(temp7_alarm, S_IRUGO | S_IWUSR, show_temp_alarm, 562 + clear_temp_alarm, 6); 563 + static SENSOR_DEVICE_ATTR(temp8_alarm, S_IRUGO | S_IWUSR, show_temp_alarm, 564 + clear_temp_alarm, 7); 565 + static SENSOR_DEVICE_ATTR(temp9_alarm, S_IRUGO | S_IWUSR, show_temp_alarm, 566 + clear_temp_alarm, 8); 567 + static SENSOR_DEVICE_ATTR(temp10_alarm, S_IRUGO | S_IWUSR, show_temp_alarm, 568 + clear_temp_alarm, 9); 569 + static SENSOR_DEVICE_ATTR(temp11_alarm, S_IRUGO | S_IWUSR, show_temp_alarm, 570 + clear_temp_alarm, 10); 571 + static SENSOR_DEVICE_ATTR(temp12_alarm, S_IRUGO | S_IWUSR, show_temp_alarm, 572 + clear_temp_alarm, 11); 573 + static SENSOR_DEVICE_ATTR(temp13_alarm, S_IRUGO | S_IWUSR, show_temp_alarm, 574 + clear_temp_alarm, 12); 575 + static SENSOR_DEVICE_ATTR(temp14_alarm, S_IRUGO | S_IWUSR, show_temp_alarm, 576 + clear_temp_alarm, 13); 577 + static SENSOR_DEVICE_ATTR(temp15_alarm, S_IRUGO | S_IWUSR, show_temp_alarm, 578 + clear_temp_alarm, 14); 579 + static SENSOR_DEVICE_ATTR(temp16_alarm, S_IRUGO | S_IWUSR, show_temp_alarm, 580 + clear_temp_alarm, 15); 581 + 582 + static struct attribute *fts_temp_attrs[] = { 583 + &sensor_dev_attr_temp1_input.dev_attr.attr, 584 + &sensor_dev_attr_temp2_input.dev_attr.attr, 585 + &sensor_dev_attr_temp3_input.dev_attr.attr, 586 + &sensor_dev_attr_temp4_input.dev_attr.attr, 587 + &sensor_dev_attr_temp5_input.dev_attr.attr, 588 + &sensor_dev_attr_temp6_input.dev_attr.attr, 589 + &sensor_dev_attr_temp7_input.dev_attr.attr, 590 + &sensor_dev_attr_temp8_input.dev_attr.attr, 591 + &sensor_dev_attr_temp9_input.dev_attr.attr, 592 + &sensor_dev_attr_temp10_input.dev_attr.attr, 593 + &sensor_dev_attr_temp11_input.dev_attr.attr, 594 + &sensor_dev_attr_temp12_input.dev_attr.attr, 595 + &sensor_dev_attr_temp13_input.dev_attr.attr, 596 + &sensor_dev_attr_temp14_input.dev_attr.attr, 597 + &sensor_dev_attr_temp15_input.dev_attr.attr, 598 + &sensor_dev_attr_temp16_input.dev_attr.attr, 599 + 600 + &sensor_dev_attr_temp1_fault.dev_attr.attr, 601 + &sensor_dev_attr_temp2_fault.dev_attr.attr, 602 + &sensor_dev_attr_temp3_fault.dev_attr.attr, 603 + &sensor_dev_attr_temp4_fault.dev_attr.attr, 604 + &sensor_dev_attr_temp5_fault.dev_attr.attr, 605 + &sensor_dev_attr_temp6_fault.dev_attr.attr, 606 + &sensor_dev_attr_temp7_fault.dev_attr.attr, 607 + &sensor_dev_attr_temp8_fault.dev_attr.attr, 608 + &sensor_dev_attr_temp9_fault.dev_attr.attr, 609 + &sensor_dev_attr_temp10_fault.dev_attr.attr, 610 + &sensor_dev_attr_temp11_fault.dev_attr.attr, 611 + &sensor_dev_attr_temp12_fault.dev_attr.attr, 612 + &sensor_dev_attr_temp13_fault.dev_attr.attr, 613 + &sensor_dev_attr_temp14_fault.dev_attr.attr, 614 + &sensor_dev_attr_temp15_fault.dev_attr.attr, 615 + &sensor_dev_attr_temp16_fault.dev_attr.attr, 616 + 617 + &sensor_dev_attr_temp1_alarm.dev_attr.attr, 618 + &sensor_dev_attr_temp2_alarm.dev_attr.attr, 619 + &sensor_dev_attr_temp3_alarm.dev_attr.attr, 620 + &sensor_dev_attr_temp4_alarm.dev_attr.attr, 621 + &sensor_dev_attr_temp5_alarm.dev_attr.attr, 622 + &sensor_dev_attr_temp6_alarm.dev_attr.attr, 623 + &sensor_dev_attr_temp7_alarm.dev_attr.attr, 624 + &sensor_dev_attr_temp8_alarm.dev_attr.attr, 625 + &sensor_dev_attr_temp9_alarm.dev_attr.attr, 626 + &sensor_dev_attr_temp10_alarm.dev_attr.attr, 627 + &sensor_dev_attr_temp11_alarm.dev_attr.attr, 628 + &sensor_dev_attr_temp12_alarm.dev_attr.attr, 629 + &sensor_dev_attr_temp13_alarm.dev_attr.attr, 630 + &sensor_dev_attr_temp14_alarm.dev_attr.attr, 631 + &sensor_dev_attr_temp15_alarm.dev_attr.attr, 632 + &sensor_dev_attr_temp16_alarm.dev_attr.attr, 633 + NULL 634 + }; 635 + 636 + /* Fans */ 637 + static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_value, NULL, 0); 638 + static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_value, NULL, 1); 639 + static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan_value, NULL, 2); 640 + static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan_value, NULL, 3); 641 + static SENSOR_DEVICE_ATTR(fan5_input, S_IRUGO, show_fan_value, NULL, 4); 642 + static SENSOR_DEVICE_ATTR(fan6_input, S_IRUGO, show_fan_value, NULL, 5); 643 + static SENSOR_DEVICE_ATTR(fan7_input, S_IRUGO, show_fan_value, NULL, 6); 644 + static SENSOR_DEVICE_ATTR(fan8_input, S_IRUGO, show_fan_value, NULL, 7); 645 + 646 + static SENSOR_DEVICE_ATTR(fan1_source, S_IRUGO, show_fan_source, NULL, 0); 647 + static SENSOR_DEVICE_ATTR(fan2_source, S_IRUGO, show_fan_source, NULL, 1); 648 + static SENSOR_DEVICE_ATTR(fan3_source, S_IRUGO, show_fan_source, NULL, 2); 649 + static SENSOR_DEVICE_ATTR(fan4_source, S_IRUGO, show_fan_source, NULL, 3); 650 + static SENSOR_DEVICE_ATTR(fan5_source, S_IRUGO, show_fan_source, NULL, 4); 651 + static SENSOR_DEVICE_ATTR(fan6_source, S_IRUGO, show_fan_source, NULL, 5); 652 + static SENSOR_DEVICE_ATTR(fan7_source, S_IRUGO, show_fan_source, NULL, 6); 653 + static SENSOR_DEVICE_ATTR(fan8_source, S_IRUGO, show_fan_source, NULL, 7); 654 + 655 + static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO | S_IWUSR, 656 + show_fan_alarm, clear_fan_alarm, 0); 657 + static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO | S_IWUSR, 658 + show_fan_alarm, clear_fan_alarm, 1); 659 + static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO | S_IWUSR, 660 + show_fan_alarm, clear_fan_alarm, 2); 661 + static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO | S_IWUSR, 662 + show_fan_alarm, clear_fan_alarm, 3); 663 + static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO | S_IWUSR, 664 + show_fan_alarm, clear_fan_alarm, 4); 665 + static SENSOR_DEVICE_ATTR(fan6_alarm, S_IRUGO | S_IWUSR, 666 + show_fan_alarm, clear_fan_alarm, 5); 667 + static SENSOR_DEVICE_ATTR(fan7_alarm, S_IRUGO | S_IWUSR, 668 + show_fan_alarm, clear_fan_alarm, 6); 669 + static SENSOR_DEVICE_ATTR(fan8_alarm, S_IRUGO | S_IWUSR, 670 + show_fan_alarm, clear_fan_alarm, 7); 671 + 672 + static struct attribute *fts_fan_attrs[] = { 673 + &sensor_dev_attr_fan1_input.dev_attr.attr, 674 + &sensor_dev_attr_fan2_input.dev_attr.attr, 675 + &sensor_dev_attr_fan3_input.dev_attr.attr, 676 + &sensor_dev_attr_fan4_input.dev_attr.attr, 677 + &sensor_dev_attr_fan5_input.dev_attr.attr, 678 + &sensor_dev_attr_fan6_input.dev_attr.attr, 679 + &sensor_dev_attr_fan7_input.dev_attr.attr, 680 + &sensor_dev_attr_fan8_input.dev_attr.attr, 681 + 682 + &sensor_dev_attr_fan1_source.dev_attr.attr, 683 + &sensor_dev_attr_fan2_source.dev_attr.attr, 684 + &sensor_dev_attr_fan3_source.dev_attr.attr, 685 + &sensor_dev_attr_fan4_source.dev_attr.attr, 686 + &sensor_dev_attr_fan5_source.dev_attr.attr, 687 + &sensor_dev_attr_fan6_source.dev_attr.attr, 688 + &sensor_dev_attr_fan7_source.dev_attr.attr, 689 + &sensor_dev_attr_fan8_source.dev_attr.attr, 690 + 691 + &sensor_dev_attr_fan1_alarm.dev_attr.attr, 692 + &sensor_dev_attr_fan2_alarm.dev_attr.attr, 693 + &sensor_dev_attr_fan3_alarm.dev_attr.attr, 694 + &sensor_dev_attr_fan4_alarm.dev_attr.attr, 695 + &sensor_dev_attr_fan5_alarm.dev_attr.attr, 696 + &sensor_dev_attr_fan6_alarm.dev_attr.attr, 697 + &sensor_dev_attr_fan7_alarm.dev_attr.attr, 698 + &sensor_dev_attr_fan8_alarm.dev_attr.attr, 699 + NULL 700 + }; 701 + 702 + /* Voltages */ 703 + static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in_value, NULL, 0); 704 + static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_in_value, NULL, 1); 705 + static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_in_value, NULL, 2); 706 + static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_in_value, NULL, 3); 707 + static struct attribute *fts_voltage_attrs[] = { 708 + &sensor_dev_attr_in1_input.dev_attr.attr, 709 + &sensor_dev_attr_in2_input.dev_attr.attr, 710 + &sensor_dev_attr_in3_input.dev_attr.attr, 711 + &sensor_dev_attr_in4_input.dev_attr.attr, 712 + NULL 713 + }; 714 + 715 + static const struct attribute_group fts_voltage_attr_group = { 716 + .attrs = fts_voltage_attrs 717 + }; 718 + 719 + static const struct attribute_group fts_temp_attr_group = { 720 + .attrs = fts_temp_attrs 721 + }; 722 + 723 + static const struct attribute_group fts_fan_attr_group = { 724 + .attrs = fts_fan_attrs 725 + }; 726 + 727 + static const struct attribute_group *fts_attr_groups[] = { 728 + &fts_voltage_attr_group, 729 + &fts_temp_attr_group, 730 + &fts_fan_attr_group, 731 + NULL 732 + }; 733 + 734 + /*****************************************************************************/ 735 + /* Module initialization / remove functions */ 736 + /*****************************************************************************/ 737 + static int fts_remove(struct i2c_client *client) 738 + { 739 + struct fts_data *data = dev_get_drvdata(&client->dev); 740 + 741 + watchdog_unregister_device(&data->wdd); 742 + return 0; 743 + } 744 + 745 + static int fts_probe(struct i2c_client *client, const struct i2c_device_id *id) 746 + { 747 + u8 revision; 748 + struct fts_data *data; 749 + int err; 750 + s8 deviceid; 751 + struct device *hwmon_dev; 752 + 753 + if (client->addr != 0x73) 754 + return -ENODEV; 755 + 756 + /* Baseboard Management Controller check */ 757 + deviceid = i2c_smbus_read_byte_data(client, FTS_DEVICE_ID_REG); 758 + if (deviceid > 0 && (deviceid & 0xF0) == 0x10) { 759 + switch (deviceid & 0x0F) { 760 + case 0x01: 761 + break; 762 + default: 763 + dev_dbg(&client->dev, 764 + "No Baseboard Management Controller\n"); 765 + return -ENODEV; 766 + } 767 + } else { 768 + dev_dbg(&client->dev, "No fujitsu board\n"); 769 + return -ENODEV; 770 + } 771 + 772 + data = devm_kzalloc(&client->dev, sizeof(struct fts_data), 773 + GFP_KERNEL); 774 + if (!data) 775 + return -ENOMEM; 776 + 777 + mutex_init(&data->update_lock); 778 + mutex_init(&data->access_lock); 779 + data->client = client; 780 + dev_set_drvdata(&client->dev, data); 781 + 782 + err = i2c_smbus_read_byte_data(client, FTS_DEVICE_REVISION_REG); 783 + if (err < 0) 784 + return err; 785 + revision = err; 786 + 787 + hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev, 788 + "ftsteutates", 789 + data, 790 + fts_attr_groups); 791 + if (IS_ERR(hwmon_dev)) 792 + return PTR_ERR(hwmon_dev); 793 + 794 + err = fts_watchdog_init(data); 795 + if (err) 796 + return err; 797 + 798 + dev_info(&client->dev, "Detected FTS Teutates chip, revision: %d.%d\n", 799 + (revision & 0xF0) >> 4, revision & 0x0F); 800 + return 0; 801 + } 802 + 803 + /*****************************************************************************/ 804 + /* Module Details */ 805 + /*****************************************************************************/ 806 + static struct i2c_driver fts_driver = { 807 + .driver = { 808 + .name = "ftsteutates", 809 + }, 810 + .id_table = fts_id, 811 + .probe = fts_probe, 812 + .remove = fts_remove, 813 + }; 814 + 815 + module_i2c_driver(fts_driver); 816 + 817 + MODULE_AUTHOR("Thilo Cestonaro <thilo.cestonaro@ts.fujitsu.com>"); 818 + MODULE_DESCRIPTION("FTS Teutates driver"); 819 + MODULE_LICENSE("GPL");
+445
drivers/hwmon/ina3221.c
··· 1 + /* 2 + * INA3221 Triple Current/Voltage Monitor 3 + * 4 + * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/ 5 + * Andrew F. Davis <afd@ti.com> 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 as 9 + * published by the Free Software Foundation. 10 + * 11 + * This program is distributed in the hope that it will be useful, but 12 + * WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 + * General Public License for more details. 15 + */ 16 + 17 + #include <linux/hwmon.h> 18 + #include <linux/hwmon-sysfs.h> 19 + #include <linux/i2c.h> 20 + #include <linux/module.h> 21 + #include <linux/of.h> 22 + #include <linux/regmap.h> 23 + 24 + #define INA3221_DRIVER_NAME "ina3221" 25 + 26 + #define INA3221_CONFIG 0x00 27 + #define INA3221_SHUNT1 0x01 28 + #define INA3221_BUS1 0x02 29 + #define INA3221_SHUNT2 0x03 30 + #define INA3221_BUS2 0x04 31 + #define INA3221_SHUNT3 0x05 32 + #define INA3221_BUS3 0x06 33 + #define INA3221_CRIT1 0x07 34 + #define INA3221_WARN1 0x08 35 + #define INA3221_CRIT2 0x09 36 + #define INA3221_WARN2 0x0a 37 + #define INA3221_CRIT3 0x0b 38 + #define INA3221_WARN3 0x0c 39 + #define INA3221_MASK_ENABLE 0x0f 40 + 41 + #define INA3221_CONFIG_MODE_SHUNT BIT(1) 42 + #define INA3221_CONFIG_MODE_BUS BIT(2) 43 + #define INA3221_CONFIG_MODE_CONTINUOUS BIT(3) 44 + 45 + #define INA3221_RSHUNT_DEFAULT 10000 46 + 47 + enum ina3221_fields { 48 + /* Configuration */ 49 + F_RST, 50 + 51 + /* Alert Flags */ 52 + F_WF3, F_WF2, F_WF1, 53 + F_CF3, F_CF2, F_CF1, 54 + 55 + /* sentinel */ 56 + F_MAX_FIELDS 57 + }; 58 + 59 + static const struct reg_field ina3221_reg_fields[] = { 60 + [F_RST] = REG_FIELD(INA3221_CONFIG, 15, 15), 61 + 62 + [F_WF3] = REG_FIELD(INA3221_MASK_ENABLE, 3, 3), 63 + [F_WF2] = REG_FIELD(INA3221_MASK_ENABLE, 4, 4), 64 + [F_WF1] = REG_FIELD(INA3221_MASK_ENABLE, 5, 5), 65 + [F_CF3] = REG_FIELD(INA3221_MASK_ENABLE, 7, 7), 66 + [F_CF2] = REG_FIELD(INA3221_MASK_ENABLE, 8, 8), 67 + [F_CF1] = REG_FIELD(INA3221_MASK_ENABLE, 9, 9), 68 + }; 69 + 70 + enum ina3221_channels { 71 + INA3221_CHANNEL1, 72 + INA3221_CHANNEL2, 73 + INA3221_CHANNEL3, 74 + INA3221_NUM_CHANNELS 75 + }; 76 + 77 + static const unsigned int register_channel[] = { 78 + [INA3221_SHUNT1] = INA3221_CHANNEL1, 79 + [INA3221_SHUNT2] = INA3221_CHANNEL2, 80 + [INA3221_SHUNT3] = INA3221_CHANNEL3, 81 + [INA3221_CRIT1] = INA3221_CHANNEL1, 82 + [INA3221_CRIT2] = INA3221_CHANNEL2, 83 + [INA3221_CRIT3] = INA3221_CHANNEL3, 84 + [INA3221_WARN1] = INA3221_CHANNEL1, 85 + [INA3221_WARN2] = INA3221_CHANNEL2, 86 + [INA3221_WARN3] = INA3221_CHANNEL3, 87 + }; 88 + 89 + /** 90 + * struct ina3221_data - device specific information 91 + * @regmap: Register map of the device 92 + * @fields: Register fields of the device 93 + * @shunt_resistors: Array of resistor values per channel 94 + */ 95 + struct ina3221_data { 96 + struct regmap *regmap; 97 + struct regmap_field *fields[F_MAX_FIELDS]; 98 + int shunt_resistors[INA3221_NUM_CHANNELS]; 99 + }; 100 + 101 + static int ina3221_read_value(struct ina3221_data *ina, unsigned int reg, 102 + int *val) 103 + { 104 + unsigned int regval; 105 + int ret; 106 + 107 + ret = regmap_read(ina->regmap, reg, &regval); 108 + if (ret) 109 + return ret; 110 + 111 + *val = sign_extend32(regval >> 3, 12); 112 + 113 + return 0; 114 + } 115 + 116 + static ssize_t ina3221_show_bus_voltage(struct device *dev, 117 + struct device_attribute *attr, 118 + char *buf) 119 + { 120 + struct sensor_device_attribute *sd_attr = to_sensor_dev_attr(attr); 121 + struct ina3221_data *ina = dev_get_drvdata(dev); 122 + unsigned int reg = sd_attr->index; 123 + int val, voltage_mv, ret; 124 + 125 + ret = ina3221_read_value(ina, reg, &val); 126 + if (ret) 127 + return ret; 128 + 129 + voltage_mv = val * 8; 130 + 131 + return snprintf(buf, PAGE_SIZE, "%d\n", voltage_mv); 132 + } 133 + 134 + static ssize_t ina3221_show_shunt_voltage(struct device *dev, 135 + struct device_attribute *attr, 136 + char *buf) 137 + { 138 + struct sensor_device_attribute *sd_attr = to_sensor_dev_attr(attr); 139 + struct ina3221_data *ina = dev_get_drvdata(dev); 140 + unsigned int reg = sd_attr->index; 141 + int val, voltage_uv, ret; 142 + 143 + ret = ina3221_read_value(ina, reg, &val); 144 + if (ret) 145 + return ret; 146 + voltage_uv = val * 40; 147 + 148 + return snprintf(buf, PAGE_SIZE, "%d\n", voltage_uv); 149 + } 150 + 151 + static ssize_t ina3221_show_current(struct device *dev, 152 + struct device_attribute *attr, char *buf) 153 + { 154 + struct sensor_device_attribute *sd_attr = to_sensor_dev_attr(attr); 155 + struct ina3221_data *ina = dev_get_drvdata(dev); 156 + unsigned int reg = sd_attr->index; 157 + unsigned int channel = register_channel[reg]; 158 + int resistance_uo = ina->shunt_resistors[channel]; 159 + int val, current_ma, voltage_nv, ret; 160 + 161 + ret = ina3221_read_value(ina, reg, &val); 162 + if (ret) 163 + return ret; 164 + voltage_nv = val * 40000; 165 + 166 + current_ma = DIV_ROUND_CLOSEST(voltage_nv, resistance_uo); 167 + 168 + return snprintf(buf, PAGE_SIZE, "%d\n", current_ma); 169 + } 170 + 171 + static ssize_t ina3221_set_current(struct device *dev, 172 + struct device_attribute *attr, 173 + const char *buf, size_t count) 174 + { 175 + struct sensor_device_attribute *sd_attr = to_sensor_dev_attr(attr); 176 + struct ina3221_data *ina = dev_get_drvdata(dev); 177 + unsigned int reg = sd_attr->index; 178 + unsigned int channel = register_channel[reg]; 179 + int resistance_uo = ina->shunt_resistors[channel]; 180 + int val, current_ma, voltage_uv, ret; 181 + 182 + ret = kstrtoint(buf, 0, &current_ma); 183 + if (ret) 184 + return ret; 185 + 186 + /* clamp current */ 187 + current_ma = clamp_val(current_ma, 188 + INT_MIN / resistance_uo, 189 + INT_MAX / resistance_uo); 190 + 191 + voltage_uv = DIV_ROUND_CLOSEST(current_ma * resistance_uo, 1000); 192 + 193 + /* clamp voltage */ 194 + voltage_uv = clamp_val(voltage_uv, -163800, 163800); 195 + 196 + /* 1 / 40uV(scale) << 3(register shift) = 5 */ 197 + val = DIV_ROUND_CLOSEST(voltage_uv, 5) & 0xfff8; 198 + 199 + ret = regmap_write(ina->regmap, reg, val); 200 + if (ret) 201 + return ret; 202 + 203 + return count; 204 + } 205 + 206 + static ssize_t ina3221_show_shunt(struct device *dev, 207 + struct device_attribute *attr, char *buf) 208 + { 209 + struct sensor_device_attribute *sd_attr = to_sensor_dev_attr(attr); 210 + struct ina3221_data *ina = dev_get_drvdata(dev); 211 + unsigned int channel = sd_attr->index; 212 + unsigned int resistance_uo; 213 + 214 + resistance_uo = ina->shunt_resistors[channel]; 215 + 216 + return snprintf(buf, PAGE_SIZE, "%d\n", resistance_uo); 217 + } 218 + 219 + static ssize_t ina3221_set_shunt(struct device *dev, 220 + struct device_attribute *attr, 221 + const char *buf, size_t count) 222 + { 223 + struct sensor_device_attribute *sd_attr = to_sensor_dev_attr(attr); 224 + struct ina3221_data *ina = dev_get_drvdata(dev); 225 + unsigned int channel = sd_attr->index; 226 + int val; 227 + int ret; 228 + 229 + ret = kstrtoint(buf, 0, &val); 230 + if (ret) 231 + return ret; 232 + 233 + val = clamp_val(val, 1, INT_MAX); 234 + 235 + ina->shunt_resistors[channel] = val; 236 + 237 + return count; 238 + } 239 + 240 + static ssize_t ina3221_show_alert(struct device *dev, 241 + struct device_attribute *attr, char *buf) 242 + { 243 + struct sensor_device_attribute *sd_attr = to_sensor_dev_attr(attr); 244 + struct ina3221_data *ina = dev_get_drvdata(dev); 245 + unsigned int field = sd_attr->index; 246 + unsigned int regval; 247 + int ret; 248 + 249 + ret = regmap_field_read(ina->fields[field], &regval); 250 + if (ret) 251 + return ret; 252 + 253 + return snprintf(buf, PAGE_SIZE, "%d\n", regval); 254 + } 255 + 256 + /* bus voltage */ 257 + static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, 258 + ina3221_show_bus_voltage, NULL, INA3221_BUS1); 259 + static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, 260 + ina3221_show_bus_voltage, NULL, INA3221_BUS2); 261 + static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, 262 + ina3221_show_bus_voltage, NULL, INA3221_BUS3); 263 + 264 + /* calculated current */ 265 + static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, 266 + ina3221_show_current, NULL, INA3221_SHUNT1); 267 + static SENSOR_DEVICE_ATTR(curr2_input, S_IRUGO, 268 + ina3221_show_current, NULL, INA3221_SHUNT2); 269 + static SENSOR_DEVICE_ATTR(curr3_input, S_IRUGO, 270 + ina3221_show_current, NULL, INA3221_SHUNT3); 271 + 272 + /* shunt resistance */ 273 + static SENSOR_DEVICE_ATTR(shunt1_resistor, S_IRUGO | S_IWUSR, 274 + ina3221_show_shunt, ina3221_set_shunt, INA3221_CHANNEL1); 275 + static SENSOR_DEVICE_ATTR(shunt2_resistor, S_IRUGO | S_IWUSR, 276 + ina3221_show_shunt, ina3221_set_shunt, INA3221_CHANNEL2); 277 + static SENSOR_DEVICE_ATTR(shunt3_resistor, S_IRUGO | S_IWUSR, 278 + ina3221_show_shunt, ina3221_set_shunt, INA3221_CHANNEL3); 279 + 280 + /* critical current */ 281 + static SENSOR_DEVICE_ATTR(curr1_crit, S_IRUGO | S_IWUSR, 282 + ina3221_show_current, ina3221_set_current, INA3221_CRIT1); 283 + static SENSOR_DEVICE_ATTR(curr2_crit, S_IRUGO | S_IWUSR, 284 + ina3221_show_current, ina3221_set_current, INA3221_CRIT2); 285 + static SENSOR_DEVICE_ATTR(curr3_crit, S_IRUGO | S_IWUSR, 286 + ina3221_show_current, ina3221_set_current, INA3221_CRIT3); 287 + 288 + /* critical current alert */ 289 + static SENSOR_DEVICE_ATTR(curr1_crit_alarm, S_IRUGO, 290 + ina3221_show_alert, NULL, F_CF1); 291 + static SENSOR_DEVICE_ATTR(curr2_crit_alarm, S_IRUGO, 292 + ina3221_show_alert, NULL, F_CF2); 293 + static SENSOR_DEVICE_ATTR(curr3_crit_alarm, S_IRUGO, 294 + ina3221_show_alert, NULL, F_CF3); 295 + 296 + /* warning current */ 297 + static SENSOR_DEVICE_ATTR(curr1_max, S_IRUGO | S_IWUSR, 298 + ina3221_show_current, ina3221_set_current, INA3221_WARN1); 299 + static SENSOR_DEVICE_ATTR(curr2_max, S_IRUGO | S_IWUSR, 300 + ina3221_show_current, ina3221_set_current, INA3221_WARN2); 301 + static SENSOR_DEVICE_ATTR(curr3_max, S_IRUGO | S_IWUSR, 302 + ina3221_show_current, ina3221_set_current, INA3221_WARN3); 303 + 304 + /* warning current alert */ 305 + static SENSOR_DEVICE_ATTR(curr1_max_alarm, S_IRUGO, 306 + ina3221_show_alert, NULL, F_WF1); 307 + static SENSOR_DEVICE_ATTR(curr2_max_alarm, S_IRUGO, 308 + ina3221_show_alert, NULL, F_WF2); 309 + static SENSOR_DEVICE_ATTR(curr3_max_alarm, S_IRUGO, 310 + ina3221_show_alert, NULL, F_WF3); 311 + 312 + /* shunt voltage */ 313 + static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, 314 + ina3221_show_shunt_voltage, NULL, INA3221_SHUNT1); 315 + static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, 316 + ina3221_show_shunt_voltage, NULL, INA3221_SHUNT2); 317 + static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, 318 + ina3221_show_shunt_voltage, NULL, INA3221_SHUNT3); 319 + 320 + static struct attribute *ina3221_attrs[] = { 321 + /* channel 1 */ 322 + &sensor_dev_attr_in1_input.dev_attr.attr, 323 + &sensor_dev_attr_curr1_input.dev_attr.attr, 324 + &sensor_dev_attr_shunt1_resistor.dev_attr.attr, 325 + &sensor_dev_attr_curr1_crit.dev_attr.attr, 326 + &sensor_dev_attr_curr1_crit_alarm.dev_attr.attr, 327 + &sensor_dev_attr_curr1_max.dev_attr.attr, 328 + &sensor_dev_attr_curr1_max_alarm.dev_attr.attr, 329 + &sensor_dev_attr_in4_input.dev_attr.attr, 330 + 331 + /* channel 2 */ 332 + &sensor_dev_attr_in2_input.dev_attr.attr, 333 + &sensor_dev_attr_curr2_input.dev_attr.attr, 334 + &sensor_dev_attr_shunt2_resistor.dev_attr.attr, 335 + &sensor_dev_attr_curr2_crit.dev_attr.attr, 336 + &sensor_dev_attr_curr2_crit_alarm.dev_attr.attr, 337 + &sensor_dev_attr_curr2_max.dev_attr.attr, 338 + &sensor_dev_attr_curr2_max_alarm.dev_attr.attr, 339 + &sensor_dev_attr_in5_input.dev_attr.attr, 340 + 341 + /* channel 3 */ 342 + &sensor_dev_attr_in3_input.dev_attr.attr, 343 + &sensor_dev_attr_curr3_input.dev_attr.attr, 344 + &sensor_dev_attr_shunt3_resistor.dev_attr.attr, 345 + &sensor_dev_attr_curr3_crit.dev_attr.attr, 346 + &sensor_dev_attr_curr3_crit_alarm.dev_attr.attr, 347 + &sensor_dev_attr_curr3_max.dev_attr.attr, 348 + &sensor_dev_attr_curr3_max_alarm.dev_attr.attr, 349 + &sensor_dev_attr_in6_input.dev_attr.attr, 350 + 351 + NULL, 352 + }; 353 + ATTRIBUTE_GROUPS(ina3221); 354 + 355 + static const struct regmap_range ina3221_yes_ranges[] = { 356 + regmap_reg_range(INA3221_SHUNT1, INA3221_BUS3), 357 + regmap_reg_range(INA3221_MASK_ENABLE, INA3221_MASK_ENABLE), 358 + }; 359 + 360 + static const struct regmap_access_table ina3221_volatile_table = { 361 + .yes_ranges = ina3221_yes_ranges, 362 + .n_yes_ranges = ARRAY_SIZE(ina3221_yes_ranges), 363 + }; 364 + 365 + static const struct regmap_config ina3221_regmap_config = { 366 + .reg_bits = 8, 367 + .val_bits = 16, 368 + 369 + .cache_type = REGCACHE_RBTREE, 370 + .volatile_table = &ina3221_volatile_table, 371 + }; 372 + 373 + static int ina3221_probe(struct i2c_client *client, 374 + const struct i2c_device_id *id) 375 + { 376 + struct device *dev = &client->dev; 377 + struct ina3221_data *ina; 378 + struct device *hwmon_dev; 379 + int i, ret; 380 + 381 + ina = devm_kzalloc(dev, sizeof(*ina), GFP_KERNEL); 382 + if (!ina) 383 + return -ENOMEM; 384 + 385 + ina->regmap = devm_regmap_init_i2c(client, &ina3221_regmap_config); 386 + if (IS_ERR(ina->regmap)) { 387 + dev_err(dev, "Unable to allocate register map\n"); 388 + return PTR_ERR(ina->regmap); 389 + } 390 + 391 + for (i = 0; i < F_MAX_FIELDS; i++) { 392 + ina->fields[i] = devm_regmap_field_alloc(dev, 393 + ina->regmap, 394 + ina3221_reg_fields[i]); 395 + if (IS_ERR(ina->fields[i])) { 396 + dev_err(dev, "Unable to allocate regmap fields\n"); 397 + return PTR_ERR(ina->fields[i]); 398 + } 399 + } 400 + 401 + for (i = 0; i < INA3221_NUM_CHANNELS; i++) 402 + ina->shunt_resistors[i] = INA3221_RSHUNT_DEFAULT; 403 + 404 + ret = regmap_field_write(ina->fields[F_RST], true); 405 + if (ret) { 406 + dev_err(dev, "Unable to reset device\n"); 407 + return ret; 408 + } 409 + 410 + hwmon_dev = devm_hwmon_device_register_with_groups(dev, 411 + client->name, 412 + ina, ina3221_groups); 413 + if (IS_ERR(hwmon_dev)) { 414 + dev_err(dev, "Unable to register hwmon device\n"); 415 + return PTR_ERR(hwmon_dev); 416 + } 417 + 418 + return 0; 419 + } 420 + 421 + static const struct of_device_id ina3221_of_match_table[] = { 422 + { .compatible = "ti,ina3221", }, 423 + { /* sentinel */ } 424 + }; 425 + MODULE_DEVICE_TABLE(of, ina3221_of_match_table); 426 + 427 + static const struct i2c_device_id ina3221_ids[] = { 428 + { "ina3221", 0 }, 429 + { /* sentinel */ } 430 + }; 431 + MODULE_DEVICE_TABLE(i2c, ina3221_ids); 432 + 433 + static struct i2c_driver ina3221_i2c_driver = { 434 + .probe = ina3221_probe, 435 + .driver = { 436 + .name = INA3221_DRIVER_NAME, 437 + .of_match_table = ina3221_of_match_table, 438 + }, 439 + .id_table = ina3221_ids, 440 + }; 441 + module_i2c_driver(ina3221_i2c_driver); 442 + 443 + MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>"); 444 + MODULE_DESCRIPTION("Texas Instruments INA3221 HWMon Driver"); 445 + MODULE_LICENSE("GPL v2");
+15 -1
drivers/hwmon/jc42.c
··· 31 31 #include <linux/hwmon-sysfs.h> 32 32 #include <linux/err.h> 33 33 #include <linux/mutex.h> 34 + #include <linux/of.h> 34 35 35 36 /* Addresses to scan */ 36 37 static const unsigned short normal_i2c[] = { ··· 105 104 #define MCP9804_DEVID 0x0200 106 105 #define MCP9804_DEVID_MASK 0xfffc 107 106 107 + #define MCP9808_DEVID 0x0400 108 + #define MCP9808_DEVID_MASK 0xfffc 109 + 108 110 #define MCP98242_DEVID 0x2000 109 111 #define MCP98242_DEVID_MASK 0xfffc 110 112 ··· 164 160 { IDT_MANID, TS3001_DEVID, TS3001_DEVID_MASK }, 165 161 { MAX_MANID, MAX6604_DEVID, MAX6604_DEVID_MASK }, 166 162 { MCP_MANID, MCP9804_DEVID, MCP9804_DEVID_MASK }, 163 + { MCP_MANID, MCP9808_DEVID, MCP9808_DEVID_MASK }, 167 164 { MCP_MANID, MCP98242_DEVID, MCP98242_DEVID_MASK }, 168 165 { MCP_MANID, MCP98243_DEVID, MCP98243_DEVID_MASK }, 169 166 { MCP_MANID, MCP98244_DEVID, MCP98244_DEVID_MASK }, ··· 542 537 }; 543 538 MODULE_DEVICE_TABLE(i2c, jc42_id); 544 539 540 + #ifdef CONFIG_OF 541 + static const struct of_device_id jc42_of_ids[] = { 542 + { .compatible = "jedec,jc-42.4-temp", }, 543 + { } 544 + }; 545 + MODULE_DEVICE_TABLE(of, jc42_of_ids); 546 + #endif 547 + 545 548 static struct i2c_driver jc42_driver = { 546 - .class = I2C_CLASS_SPD, 549 + .class = I2C_CLASS_SPD | I2C_CLASS_HWMON, 547 550 .driver = { 548 551 .name = "jc42", 549 552 .pm = JC42_DEV_PM_OPS, 553 + .of_match_table = of_match_ptr(jc42_of_ids), 550 554 }, 551 555 .probe = jc42_probe, 552 556 .remove = jc42_remove,
+14 -51
drivers/hwmon/jz4740-hwmon.c
··· 29 29 30 30 struct jz4740_hwmon { 31 31 void __iomem *base; 32 - 33 32 int irq; 34 - 35 33 const struct mfd_cell *cell; 36 - struct device *hwmon; 37 - 34 + struct platform_device *pdev; 38 35 struct completion read_completion; 39 - 40 36 struct mutex lock; 41 37 }; 42 - 43 - static ssize_t jz4740_hwmon_show_name(struct device *dev, 44 - struct device_attribute *dev_attr, char *buf) 45 - { 46 - return sprintf(buf, "jz4740\n"); 47 - } 48 38 49 39 static irqreturn_t jz4740_hwmon_irq(int irq, void *data) 50 40 { ··· 48 58 struct device_attribute *dev_attr, char *buf) 49 59 { 50 60 struct jz4740_hwmon *hwmon = dev_get_drvdata(dev); 61 + struct platform_device *pdev = hwmon->pdev; 51 62 struct completion *completion = &hwmon->read_completion; 52 63 long t; 53 64 unsigned long val; ··· 59 68 reinit_completion(completion); 60 69 61 70 enable_irq(hwmon->irq); 62 - hwmon->cell->enable(to_platform_device(dev)); 71 + hwmon->cell->enable(pdev); 63 72 64 73 t = wait_for_completion_interruptible_timeout(completion, HZ); 65 74 ··· 71 80 ret = t ? t : -ETIMEDOUT; 72 81 } 73 82 74 - hwmon->cell->disable(to_platform_device(dev)); 83 + hwmon->cell->disable(pdev); 75 84 disable_irq(hwmon->irq); 76 85 77 86 mutex_unlock(&hwmon->lock); ··· 79 88 return ret; 80 89 } 81 90 82 - static DEVICE_ATTR(name, S_IRUGO, jz4740_hwmon_show_name, NULL); 83 91 static DEVICE_ATTR(in0_input, S_IRUGO, jz4740_hwmon_read_adcin, NULL); 84 92 85 - static struct attribute *jz4740_hwmon_attributes[] = { 86 - &dev_attr_name.attr, 93 + static struct attribute *jz4740_attrs[] = { 87 94 &dev_attr_in0_input.attr, 88 95 NULL 89 96 }; 90 97 91 - static const struct attribute_group jz4740_hwmon_attr_group = { 92 - .attrs = jz4740_hwmon_attributes, 93 - }; 98 + ATTRIBUTE_GROUPS(jz4740); 94 99 95 100 static int jz4740_hwmon_probe(struct platform_device *pdev) 96 101 { 97 102 int ret; 103 + struct device *dev = &pdev->dev; 98 104 struct jz4740_hwmon *hwmon; 105 + struct device *hwmon_dev; 99 106 struct resource *mem; 100 107 101 - hwmon = devm_kzalloc(&pdev->dev, sizeof(*hwmon), GFP_KERNEL); 108 + hwmon = devm_kzalloc(dev, sizeof(*hwmon), GFP_KERNEL); 102 109 if (!hwmon) 103 110 return -ENOMEM; 104 111 ··· 114 125 if (IS_ERR(hwmon->base)) 115 126 return PTR_ERR(hwmon->base); 116 127 128 + hwmon->pdev = pdev; 117 129 init_completion(&hwmon->read_completion); 118 130 mutex_init(&hwmon->lock); 119 131 120 - platform_set_drvdata(pdev, hwmon); 121 - 122 - ret = devm_request_irq(&pdev->dev, hwmon->irq, jz4740_hwmon_irq, 0, 132 + ret = devm_request_irq(dev, hwmon->irq, jz4740_hwmon_irq, 0, 123 133 pdev->name, hwmon); 124 134 if (ret) { 125 135 dev_err(&pdev->dev, "Failed to request irq: %d\n", ret); ··· 126 138 } 127 139 disable_irq(hwmon->irq); 128 140 129 - ret = sysfs_create_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group); 130 - if (ret) { 131 - dev_err(&pdev->dev, "Failed to create sysfs group: %d\n", ret); 132 - return ret; 133 - } 134 - 135 - hwmon->hwmon = hwmon_device_register(&pdev->dev); 136 - if (IS_ERR(hwmon->hwmon)) { 137 - ret = PTR_ERR(hwmon->hwmon); 138 - goto err_remove_file; 139 - } 140 - 141 - return 0; 142 - 143 - err_remove_file: 144 - sysfs_remove_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group); 145 - return ret; 146 - } 147 - 148 - static int jz4740_hwmon_remove(struct platform_device *pdev) 149 - { 150 - struct jz4740_hwmon *hwmon = platform_get_drvdata(pdev); 151 - 152 - hwmon_device_unregister(hwmon->hwmon); 153 - sysfs_remove_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group); 154 - 155 - return 0; 141 + hwmon_dev = devm_hwmon_device_register_with_groups(dev, "jz4740", hwmon, 142 + jz4740_groups); 143 + return PTR_ERR_OR_ZERO(hwmon_dev); 156 144 } 157 145 158 146 static struct platform_driver jz4740_hwmon_driver = { 159 147 .probe = jz4740_hwmon_probe, 160 - .remove = jz4740_hwmon_remove, 161 148 .driver = { 162 149 .name = "jz4740-hwmon", 163 150 },
+101 -138
drivers/hwmon/lm75.c
··· 26 26 #include <linux/hwmon.h> 27 27 #include <linux/hwmon-sysfs.h> 28 28 #include <linux/err.h> 29 - #include <linux/mutex.h> 30 29 #include <linux/of.h> 30 + #include <linux/regmap.h> 31 31 #include <linux/thermal.h> 32 32 #include "lm75.h" 33 33 ··· 66 66 67 67 68 68 /* The LM75 registers */ 69 + #define LM75_REG_TEMP 0x00 69 70 #define LM75_REG_CONF 0x01 70 - static const u8 LM75_REG_TEMP[3] = { 71 - 0x00, /* input */ 72 - 0x03, /* max */ 73 - 0x02, /* hyst */ 74 - }; 71 + #define LM75_REG_HYST 0x02 72 + #define LM75_REG_MAX 0x03 75 73 76 74 /* Each client has this additional data */ 77 75 struct lm75_data { 78 76 struct i2c_client *client; 79 - struct device *hwmon_dev; 80 - struct mutex update_lock; 77 + struct regmap *regmap; 81 78 u8 orig_conf; 82 79 u8 resolution; /* In bits, between 9 and 12 */ 83 80 u8 resolution_limits; 84 - char valid; /* !=0 if registers are valid */ 85 - unsigned long last_updated; /* In jiffies */ 86 - unsigned long sample_time; /* In jiffies */ 87 - s16 temp[3]; /* Register values, 88 - 0 = input 89 - 1 = max 90 - 2 = hyst */ 81 + unsigned int sample_time; /* In ms */ 91 82 }; 92 - 93 - static int lm75_read_value(struct i2c_client *client, u8 reg); 94 - static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value); 95 - static struct lm75_data *lm75_update_device(struct device *dev); 96 - 97 83 98 84 /*-----------------------------------------------------------------------*/ 99 85 ··· 92 106 93 107 static int lm75_read_temp(void *dev, int *temp) 94 108 { 95 - struct lm75_data *data = lm75_update_device(dev); 109 + struct lm75_data *data = dev_get_drvdata(dev); 110 + unsigned int _temp; 111 + int err; 96 112 97 - if (IS_ERR(data)) 98 - return PTR_ERR(data); 113 + err = regmap_read(data->regmap, LM75_REG_TEMP, &_temp); 114 + if (err < 0) 115 + return err; 99 116 100 - *temp = lm75_reg_to_mc(data->temp[0], data->resolution); 117 + *temp = lm75_reg_to_mc(_temp, data->resolution); 101 118 102 119 return 0; 103 120 } ··· 109 120 char *buf) 110 121 { 111 122 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 112 - struct lm75_data *data = lm75_update_device(dev); 123 + struct lm75_data *data = dev_get_drvdata(dev); 124 + unsigned int temp = 0; 125 + int err; 113 126 114 - if (IS_ERR(data)) 115 - return PTR_ERR(data); 127 + err = regmap_read(data->regmap, attr->index, &temp); 128 + if (err < 0) 129 + return err; 116 130 117 - return sprintf(buf, "%ld\n", lm75_reg_to_mc(data->temp[attr->index], 118 - data->resolution)); 131 + return sprintf(buf, "%ld\n", lm75_reg_to_mc(temp, data->resolution)); 119 132 } 120 133 121 134 static ssize_t set_temp(struct device *dev, struct device_attribute *da, ··· 125 134 { 126 135 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 127 136 struct lm75_data *data = dev_get_drvdata(dev); 128 - struct i2c_client *client = data->client; 129 - int nr = attr->index; 130 137 long temp; 131 138 int error; 132 139 u8 resolution; ··· 142 153 else 143 154 resolution = data->resolution; 144 155 145 - mutex_lock(&data->update_lock); 146 156 temp = clamp_val(temp, LM75_TEMP_MIN, LM75_TEMP_MAX); 147 - data->temp[nr] = DIV_ROUND_CLOSEST(temp << (resolution - 8), 148 - 1000) << (16 - resolution); 149 - lm75_write_value(client, LM75_REG_TEMP[nr], data->temp[nr]); 150 - mutex_unlock(&data->update_lock); 157 + temp = DIV_ROUND_CLOSEST(temp << (resolution - 8), 158 + 1000) << (16 - resolution); 159 + error = regmap_write(data->regmap, attr->index, temp); 160 + if (error < 0) 161 + return error; 162 + 151 163 return count; 152 164 } 153 165 166 + static ssize_t show_update_interval(struct device *dev, 167 + struct device_attribute *da, char *buf) 168 + { 169 + struct lm75_data *data = dev_get_drvdata(dev); 170 + 171 + return sprintf(buf, "%u\n", data->sample_time); 172 + } 173 + 154 174 static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, 155 - show_temp, set_temp, 1); 175 + show_temp, set_temp, LM75_REG_MAX); 156 176 static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO, 157 - show_temp, set_temp, 2); 158 - static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); 177 + show_temp, set_temp, LM75_REG_HYST); 178 + static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, LM75_REG_TEMP); 179 + static DEVICE_ATTR(update_interval, S_IRUGO, show_update_interval, NULL); 159 180 160 181 static struct attribute *lm75_attrs[] = { 161 182 &sensor_dev_attr_temp1_input.dev_attr.attr, 162 183 &sensor_dev_attr_temp1_max.dev_attr.attr, 163 184 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, 185 + &dev_attr_update_interval.attr, 164 186 165 187 NULL 166 188 }; ··· 185 185 186 186 /* device probe and removal */ 187 187 188 + static bool lm75_is_writeable_reg(struct device *dev, unsigned int reg) 189 + { 190 + return reg != LM75_REG_TEMP; 191 + } 192 + 193 + static bool lm75_is_volatile_reg(struct device *dev, unsigned int reg) 194 + { 195 + return reg == LM75_REG_TEMP; 196 + } 197 + 198 + static const struct regmap_config lm75_regmap_config = { 199 + .reg_bits = 8, 200 + .val_bits = 16, 201 + .max_register = LM75_REG_MAX, 202 + .writeable_reg = lm75_is_writeable_reg, 203 + .volatile_reg = lm75_is_volatile_reg, 204 + .val_format_endian = REGMAP_ENDIAN_BIG, 205 + .cache_type = REGCACHE_RBTREE, 206 + .use_single_rw = true, 207 + }; 208 + 209 + static void lm75_remove(void *data) 210 + { 211 + struct lm75_data *lm75 = data; 212 + struct i2c_client *client = lm75->client; 213 + 214 + i2c_smbus_write_byte_data(client, LM75_REG_CONF, lm75->orig_conf); 215 + } 216 + 188 217 static int 189 218 lm75_probe(struct i2c_client *client, const struct i2c_device_id *id) 190 219 { 191 220 struct device *dev = &client->dev; 221 + struct device *hwmon_dev; 192 222 struct lm75_data *data; 193 223 int status; 194 224 u8 set_mask, clr_mask; ··· 234 204 return -ENOMEM; 235 205 236 206 data->client = client; 237 - i2c_set_clientdata(client, data); 238 - mutex_init(&data->update_lock); 207 + 208 + data->regmap = devm_regmap_init_i2c(client, &lm75_regmap_config); 209 + if (IS_ERR(data->regmap)) 210 + return PTR_ERR(data->regmap); 239 211 240 212 /* Set to LM75 resolution (9 bits, 1/2 degree C) and range. 241 213 * Then tweak to be more precise when appropriate. ··· 249 217 case adt75: 250 218 clr_mask |= 1 << 5; /* not one-shot mode */ 251 219 data->resolution = 12; 252 - data->sample_time = HZ / 8; 220 + data->sample_time = MSEC_PER_SEC / 8; 253 221 break; 254 222 case ds1775: 255 223 case ds75: ··· 257 225 clr_mask |= 3 << 5; 258 226 set_mask |= 2 << 5; /* 11-bit mode */ 259 227 data->resolution = 11; 260 - data->sample_time = HZ; 228 + data->sample_time = MSEC_PER_SEC; 261 229 break; 262 230 case ds7505: 263 231 set_mask |= 3 << 5; /* 12-bit mode */ 264 232 data->resolution = 12; 265 - data->sample_time = HZ / 4; 233 + data->sample_time = MSEC_PER_SEC / 4; 266 234 break; 267 235 case g751: 268 236 case lm75: 269 237 case lm75a: 270 238 data->resolution = 9; 271 - data->sample_time = HZ / 2; 239 + data->sample_time = MSEC_PER_SEC / 2; 272 240 break; 273 241 case lm75b: 274 242 data->resolution = 11; 275 - data->sample_time = HZ / 4; 243 + data->sample_time = MSEC_PER_SEC / 4; 276 244 break; 277 245 case max6625: 278 246 data->resolution = 9; 279 - data->sample_time = HZ / 4; 247 + data->sample_time = MSEC_PER_SEC / 4; 280 248 break; 281 249 case max6626: 282 250 data->resolution = 12; 283 251 data->resolution_limits = 9; 284 - data->sample_time = HZ / 4; 252 + data->sample_time = MSEC_PER_SEC / 4; 285 253 break; 286 254 case tcn75: 287 255 data->resolution = 9; 288 - data->sample_time = HZ / 8; 256 + data->sample_time = MSEC_PER_SEC / 8; 289 257 break; 290 258 case mcp980x: 291 259 data->resolution_limits = 9; ··· 294 262 case tmp101: 295 263 set_mask |= 3 << 5; /* 12-bit mode */ 296 264 data->resolution = 12; 297 - data->sample_time = HZ; 265 + data->sample_time = MSEC_PER_SEC; 298 266 clr_mask |= 1 << 7; /* not one-shot mode */ 299 267 break; 300 268 case tmp112: 301 269 set_mask |= 3 << 5; /* 12-bit mode */ 302 270 clr_mask |= 1 << 7; /* not one-shot mode */ 303 271 data->resolution = 12; 304 - data->sample_time = HZ / 4; 272 + data->sample_time = MSEC_PER_SEC / 4; 305 273 break; 306 274 case tmp105: 307 275 case tmp175: ··· 310 278 set_mask |= 3 << 5; /* 12-bit mode */ 311 279 clr_mask |= 1 << 7; /* not one-shot mode */ 312 280 data->resolution = 12; 313 - data->sample_time = HZ / 2; 281 + data->sample_time = MSEC_PER_SEC / 2; 314 282 break; 315 283 case tmp75c: 316 284 clr_mask |= 1 << 5; /* not one-shot mode */ 317 285 data->resolution = 12; 318 - data->sample_time = HZ / 4; 286 + data->sample_time = MSEC_PER_SEC / 4; 319 287 break; 320 288 } 321 289 322 290 /* configure as specified */ 323 - status = lm75_read_value(client, LM75_REG_CONF); 291 + status = i2c_smbus_read_byte_data(client, LM75_REG_CONF); 324 292 if (status < 0) { 325 293 dev_dbg(dev, "Can't read config? %d\n", status); 326 294 return status; ··· 329 297 new = status & ~clr_mask; 330 298 new |= set_mask; 331 299 if (status != new) 332 - lm75_write_value(client, LM75_REG_CONF, new); 300 + i2c_smbus_write_byte_data(client, LM75_REG_CONF, new); 301 + 302 + devm_add_action(dev, lm75_remove, data); 303 + 333 304 dev_dbg(dev, "Config %02x\n", new); 334 305 335 - data->hwmon_dev = hwmon_device_register_with_groups(dev, client->name, 336 - data, lm75_groups); 337 - if (IS_ERR(data->hwmon_dev)) 338 - return PTR_ERR(data->hwmon_dev); 306 + hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, 307 + data, lm75_groups); 308 + if (IS_ERR(hwmon_dev)) 309 + return PTR_ERR(hwmon_dev); 339 310 340 - devm_thermal_zone_of_sensor_register(data->hwmon_dev, 0, 341 - data->hwmon_dev, 311 + devm_thermal_zone_of_sensor_register(hwmon_dev, 0, 312 + hwmon_dev, 342 313 &lm75_of_thermal_ops); 343 314 344 - dev_info(dev, "%s: sensor '%s'\n", 345 - dev_name(data->hwmon_dev), client->name); 315 + dev_info(dev, "%s: sensor '%s'\n", dev_name(hwmon_dev), client->name); 346 316 347 - return 0; 348 - } 349 - 350 - static int lm75_remove(struct i2c_client *client) 351 - { 352 - struct lm75_data *data = i2c_get_clientdata(client); 353 - 354 - hwmon_device_unregister(data->hwmon_dev); 355 - lm75_write_value(client, LM75_REG_CONF, data->orig_conf); 356 317 return 0; 357 318 } 358 319 ··· 474 449 { 475 450 int status; 476 451 struct i2c_client *client = to_i2c_client(dev); 477 - status = lm75_read_value(client, LM75_REG_CONF); 452 + status = i2c_smbus_read_byte_data(client, LM75_REG_CONF); 478 453 if (status < 0) { 479 454 dev_dbg(&client->dev, "Can't read config? %d\n", status); 480 455 return status; 481 456 } 482 457 status = status | LM75_SHUTDOWN; 483 - lm75_write_value(client, LM75_REG_CONF, status); 458 + i2c_smbus_write_byte_data(client, LM75_REG_CONF, status); 484 459 return 0; 485 460 } 486 461 ··· 488 463 { 489 464 int status; 490 465 struct i2c_client *client = to_i2c_client(dev); 491 - status = lm75_read_value(client, LM75_REG_CONF); 466 + status = i2c_smbus_read_byte_data(client, LM75_REG_CONF); 492 467 if (status < 0) { 493 468 dev_dbg(&client->dev, "Can't read config? %d\n", status); 494 469 return status; 495 470 } 496 471 status = status & ~LM75_SHUTDOWN; 497 - lm75_write_value(client, LM75_REG_CONF, status); 472 + i2c_smbus_write_byte_data(client, LM75_REG_CONF, status); 498 473 return 0; 499 474 } 500 475 ··· 514 489 .pm = LM75_DEV_PM_OPS, 515 490 }, 516 491 .probe = lm75_probe, 517 - .remove = lm75_remove, 518 492 .id_table = lm75_ids, 519 493 .detect = lm75_detect, 520 494 .address_list = normal_i2c, 521 495 }; 522 - 523 - /*-----------------------------------------------------------------------*/ 524 - 525 - /* register access */ 526 - 527 - /* 528 - * All registers are word-sized, except for the configuration register. 529 - * LM75 uses a high-byte first convention, which is exactly opposite to 530 - * the SMBus standard. 531 - */ 532 - static int lm75_read_value(struct i2c_client *client, u8 reg) 533 - { 534 - if (reg == LM75_REG_CONF) 535 - return i2c_smbus_read_byte_data(client, reg); 536 - else 537 - return i2c_smbus_read_word_swapped(client, reg); 538 - } 539 - 540 - static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value) 541 - { 542 - if (reg == LM75_REG_CONF) 543 - return i2c_smbus_write_byte_data(client, reg, value); 544 - else 545 - return i2c_smbus_write_word_swapped(client, reg, value); 546 - } 547 - 548 - static struct lm75_data *lm75_update_device(struct device *dev) 549 - { 550 - struct lm75_data *data = dev_get_drvdata(dev); 551 - struct i2c_client *client = data->client; 552 - struct lm75_data *ret = data; 553 - 554 - mutex_lock(&data->update_lock); 555 - 556 - if (time_after(jiffies, data->last_updated + data->sample_time) 557 - || !data->valid) { 558 - int i; 559 - dev_dbg(&client->dev, "Starting lm75 update\n"); 560 - 561 - for (i = 0; i < ARRAY_SIZE(data->temp); i++) { 562 - int status; 563 - 564 - status = lm75_read_value(client, LM75_REG_TEMP[i]); 565 - if (unlikely(status < 0)) { 566 - dev_dbg(dev, 567 - "LM75: Failed to read value: reg %d, error %d\n", 568 - LM75_REG_TEMP[i], status); 569 - ret = ERR_PTR(status); 570 - data->valid = 0; 571 - goto abort; 572 - } 573 - data->temp[i] = status; 574 - } 575 - data->last_updated = jiffies; 576 - data->valid = 1; 577 - } 578 - 579 - abort: 580 - mutex_unlock(&data->update_lock); 581 - return ret; 582 - } 583 496 584 497 module_i2c_driver(lm75_driver); 585 498
+272 -175
drivers/hwmon/lm90.c
··· 171 171 172 172 #define SA56004_REG_R_LOCAL_TEMPL 0x22 173 173 174 - #define LM90_DEF_CONVRATE_RVAL 6 /* Def conversion rate register value */ 175 174 #define LM90_MAX_CONVRATE_MS 16000 /* Maximum conversion rate in ms */ 176 175 177 176 /* TMP451 registers */ ··· 365 366 366 367 struct lm90_data { 367 368 struct i2c_client *client; 368 - struct device *hwmon_dev; 369 369 const struct attribute_group *groups[6]; 370 370 struct mutex update_lock; 371 - struct regulator *regulator; 372 - char valid; /* zero until following fields are valid */ 371 + bool valid; /* true if register values are valid */ 373 372 unsigned long last_updated; /* in jiffies */ 374 373 int kind; 375 374 u32 flags; ··· 409 412 * because we don't want the address pointer to change between the write 410 413 * byte and the read byte transactions. 411 414 */ 412 - static int lm90_read_reg(struct i2c_client *client, u8 reg, u8 *value) 415 + static int lm90_read_reg(struct i2c_client *client, u8 reg) 413 416 { 414 417 int err; 415 418 ··· 420 423 } else 421 424 err = i2c_smbus_read_byte_data(client, reg); 422 425 423 - if (err < 0) { 424 - dev_warn(&client->dev, "Register %#02x read failed (%d)\n", 425 - reg, err); 426 - return err; 427 - } 428 - *value = err; 429 - 430 - return 0; 426 + return err; 431 427 } 432 428 433 - static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value) 429 + static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl) 434 430 { 435 - int err; 436 - u8 oldh, newh, l; 431 + int oldh, newh, l; 437 432 438 433 /* 439 434 * There is a trick here. We have to read two registers to have the ··· 440 451 * we have to read the low byte again, and now we believe we have a 441 452 * correct reading. 442 453 */ 443 - if ((err = lm90_read_reg(client, regh, &oldh)) 444 - || (err = lm90_read_reg(client, regl, &l)) 445 - || (err = lm90_read_reg(client, regh, &newh))) 446 - return err; 454 + oldh = lm90_read_reg(client, regh); 455 + if (oldh < 0) 456 + return oldh; 457 + l = lm90_read_reg(client, regl); 458 + if (l < 0) 459 + return l; 460 + newh = lm90_read_reg(client, regh); 461 + if (newh < 0) 462 + return newh; 447 463 if (oldh != newh) { 448 - err = lm90_read_reg(client, regl, &l); 449 - if (err) 450 - return err; 464 + l = lm90_read_reg(client, regl); 465 + if (l < 0) 466 + return l; 451 467 } 452 - *value = (newh << 8) | l; 453 - 454 - return 0; 468 + return (newh << 8) | l; 455 469 } 456 470 457 471 /* ··· 465 473 * various registers have different meanings as a result of selecting a 466 474 * non-default remote channel. 467 475 */ 468 - static inline void lm90_select_remote_channel(struct i2c_client *client, 469 - struct lm90_data *data, 470 - int channel) 476 + static inline int lm90_select_remote_channel(struct i2c_client *client, 477 + struct lm90_data *data, 478 + int channel) 471 479 { 472 - u8 config; 480 + int config; 473 481 474 482 if (data->kind == max6696) { 475 - lm90_read_reg(client, LM90_REG_R_CONFIG1, &config); 483 + config = lm90_read_reg(client, LM90_REG_R_CONFIG1); 484 + if (config < 0) 485 + return config; 476 486 config &= ~0x08; 477 487 if (channel) 478 488 config |= 0x08; 479 489 i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, 480 490 config); 481 491 } 492 + return 0; 482 493 } 483 494 484 495 /* ··· 508 513 data->update_interval = DIV_ROUND_CLOSEST(update_interval, 64); 509 514 } 510 515 516 + static int lm90_update_limits(struct device *dev) 517 + { 518 + struct lm90_data *data = dev_get_drvdata(dev); 519 + struct i2c_client *client = data->client; 520 + int val; 521 + 522 + val = lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT); 523 + if (val < 0) 524 + return val; 525 + data->temp8[LOCAL_CRIT] = val; 526 + 527 + val = lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT); 528 + if (val < 0) 529 + return val; 530 + data->temp8[REMOTE_CRIT] = val; 531 + 532 + val = lm90_read_reg(client, LM90_REG_R_TCRIT_HYST); 533 + if (val < 0) 534 + return val; 535 + data->temp_hyst = val; 536 + 537 + lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH); 538 + if (val < 0) 539 + return val; 540 + data->temp11[REMOTE_LOW] = val << 8; 541 + 542 + if (data->flags & LM90_HAVE_REM_LIMIT_EXT) { 543 + val = lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL); 544 + if (val < 0) 545 + return val; 546 + data->temp11[REMOTE_LOW] |= val; 547 + } 548 + 549 + val = lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH); 550 + if (val < 0) 551 + return val; 552 + data->temp11[REMOTE_HIGH] = val << 8; 553 + 554 + if (data->flags & LM90_HAVE_REM_LIMIT_EXT) { 555 + val = lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL); 556 + if (val < 0) 557 + return val; 558 + data->temp11[REMOTE_HIGH] |= val; 559 + } 560 + 561 + if (data->flags & LM90_HAVE_OFFSET) { 562 + val = lm90_read16(client, LM90_REG_R_REMOTE_OFFSH, 563 + LM90_REG_R_REMOTE_OFFSL); 564 + if (val < 0) 565 + return val; 566 + data->temp11[REMOTE_OFFSET] = val; 567 + } 568 + 569 + if (data->flags & LM90_HAVE_EMERGENCY) { 570 + val = lm90_read_reg(client, MAX6659_REG_R_LOCAL_EMERG); 571 + if (val < 0) 572 + return val; 573 + data->temp8[LOCAL_EMERG] = val; 574 + 575 + val = lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG); 576 + if (val < 0) 577 + return val; 578 + data->temp8[REMOTE_EMERG] = val; 579 + } 580 + 581 + if (data->kind == max6696) { 582 + val = lm90_select_remote_channel(client, data, 1); 583 + if (val < 0) 584 + return val; 585 + 586 + val = lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT); 587 + if (val < 0) 588 + return val; 589 + data->temp8[REMOTE2_CRIT] = val; 590 + 591 + val = lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG); 592 + if (val < 0) 593 + return val; 594 + data->temp8[REMOTE2_EMERG] = val; 595 + 596 + val = lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH); 597 + if (val < 0) 598 + return val; 599 + data->temp11[REMOTE2_LOW] = val << 8; 600 + 601 + val = lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH); 602 + if (val < 0) 603 + return val; 604 + data->temp11[REMOTE2_HIGH] = val << 8; 605 + 606 + lm90_select_remote_channel(client, data, 0); 607 + } 608 + 609 + return 0; 610 + } 611 + 511 612 static struct lm90_data *lm90_update_device(struct device *dev) 512 613 { 513 614 struct lm90_data *data = dev_get_drvdata(dev); 514 615 struct i2c_client *client = data->client; 515 616 unsigned long next_update; 617 + int val = 0; 516 618 517 619 mutex_lock(&data->update_lock); 620 + 621 + if (!data->valid) { 622 + val = lm90_update_limits(dev); 623 + if (val < 0) 624 + goto error; 625 + } 518 626 519 627 next_update = data->last_updated + 520 628 msecs_to_jiffies(data->update_interval); 521 629 if (time_after(jiffies, next_update) || !data->valid) { 522 - u8 h, l; 523 - u8 alarms; 524 - 525 630 dev_dbg(&client->dev, "Updating lm90 data.\n"); 526 - lm90_read_reg(client, LM90_REG_R_LOCAL_LOW, 527 - &data->temp8[LOCAL_LOW]); 528 - lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH, 529 - &data->temp8[LOCAL_HIGH]); 530 - lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT, 531 - &data->temp8[LOCAL_CRIT]); 532 - lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, 533 - &data->temp8[REMOTE_CRIT]); 534 - lm90_read_reg(client, LM90_REG_R_TCRIT_HYST, &data->temp_hyst); 631 + 632 + data->valid = false; 633 + 634 + val = lm90_read_reg(client, LM90_REG_R_LOCAL_LOW); 635 + if (val < 0) 636 + goto error; 637 + data->temp8[LOCAL_LOW] = val; 638 + 639 + val = lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH); 640 + if (val < 0) 641 + goto error; 642 + data->temp8[LOCAL_HIGH] = val; 535 643 536 644 if (data->reg_local_ext) { 537 - lm90_read16(client, LM90_REG_R_LOCAL_TEMP, 538 - data->reg_local_ext, 539 - &data->temp11[LOCAL_TEMP]); 645 + val = lm90_read16(client, LM90_REG_R_LOCAL_TEMP, 646 + data->reg_local_ext); 647 + if (val < 0) 648 + goto error; 649 + data->temp11[LOCAL_TEMP] = val; 540 650 } else { 541 - if (lm90_read_reg(client, LM90_REG_R_LOCAL_TEMP, 542 - &h) == 0) 543 - data->temp11[LOCAL_TEMP] = h << 8; 651 + val = lm90_read_reg(client, LM90_REG_R_LOCAL_TEMP); 652 + if (val < 0) 653 + goto error; 654 + data->temp11[LOCAL_TEMP] = val << 8; 544 655 } 545 - lm90_read16(client, LM90_REG_R_REMOTE_TEMPH, 546 - LM90_REG_R_REMOTE_TEMPL, 547 - &data->temp11[REMOTE_TEMP]); 656 + val = lm90_read16(client, LM90_REG_R_REMOTE_TEMPH, 657 + LM90_REG_R_REMOTE_TEMPL); 658 + if (val < 0) 659 + goto error; 660 + data->temp11[REMOTE_TEMP] = val; 548 661 549 - if (lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h) == 0) { 550 - data->temp11[REMOTE_LOW] = h << 8; 551 - if ((data->flags & LM90_HAVE_REM_LIMIT_EXT) 552 - && lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL, 553 - &l) == 0) 554 - data->temp11[REMOTE_LOW] |= l; 555 - } 556 - if (lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h) == 0) { 557 - data->temp11[REMOTE_HIGH] = h << 8; 558 - if ((data->flags & LM90_HAVE_REM_LIMIT_EXT) 559 - && lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL, 560 - &l) == 0) 561 - data->temp11[REMOTE_HIGH] |= l; 562 - } 563 - 564 - if (data->flags & LM90_HAVE_OFFSET) { 565 - if (lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSH, 566 - &h) == 0 567 - && lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSL, 568 - &l) == 0) 569 - data->temp11[REMOTE_OFFSET] = (h << 8) | l; 570 - } 571 - if (data->flags & LM90_HAVE_EMERGENCY) { 572 - lm90_read_reg(client, MAX6659_REG_R_LOCAL_EMERG, 573 - &data->temp8[LOCAL_EMERG]); 574 - lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG, 575 - &data->temp8[REMOTE_EMERG]); 576 - } 577 - lm90_read_reg(client, LM90_REG_R_STATUS, &alarms); 578 - data->alarms = alarms; /* save as 16 bit value */ 662 + val = lm90_read_reg(client, LM90_REG_R_STATUS); 663 + if (val < 0) 664 + goto error; 665 + data->alarms = val; /* lower 8 bit of alarms */ 579 666 580 667 if (data->kind == max6696) { 581 - lm90_select_remote_channel(client, data, 1); 582 - lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, 583 - &data->temp8[REMOTE2_CRIT]); 584 - lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG, 585 - &data->temp8[REMOTE2_EMERG]); 586 - lm90_read16(client, LM90_REG_R_REMOTE_TEMPH, 587 - LM90_REG_R_REMOTE_TEMPL, 588 - &data->temp11[REMOTE2_TEMP]); 589 - if (!lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h)) 590 - data->temp11[REMOTE2_LOW] = h << 8; 591 - if (!lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h)) 592 - data->temp11[REMOTE2_HIGH] = h << 8; 668 + val = lm90_select_remote_channel(client, data, 1); 669 + if (val < 0) 670 + goto error; 671 + 672 + val = lm90_read16(client, LM90_REG_R_REMOTE_TEMPH, 673 + LM90_REG_R_REMOTE_TEMPL); 674 + if (val < 0) 675 + goto error; 676 + data->temp11[REMOTE2_TEMP] = val; 677 + 593 678 lm90_select_remote_channel(client, data, 0); 594 679 595 - if (!lm90_read_reg(client, MAX6696_REG_R_STATUS2, 596 - &alarms)) 597 - data->alarms |= alarms << 8; 680 + val = lm90_read_reg(client, MAX6696_REG_R_STATUS2); 681 + if (val < 0) 682 + goto error; 683 + data->alarms |= val << 8; 598 684 } 599 685 600 686 /* 601 687 * Re-enable ALERT# output if it was originally enabled and 602 688 * relevant alarms are all clear 603 689 */ 604 - if ((data->config_orig & 0x80) == 0 605 - && (data->alarms & data->alert_alarms) == 0) { 606 - u8 config; 690 + if (!(data->config_orig & 0x80) && 691 + !(data->alarms & data->alert_alarms)) { 692 + val = lm90_read_reg(client, LM90_REG_R_CONFIG1); 693 + if (val < 0) 694 + goto error; 607 695 608 - lm90_read_reg(client, LM90_REG_R_CONFIG1, &config); 609 - if (config & 0x80) { 696 + if (val & 0x80) { 610 697 dev_dbg(&client->dev, "Re-enabling ALERT#\n"); 611 698 i2c_smbus_write_byte_data(client, 612 699 LM90_REG_W_CONFIG1, 613 - config & ~0x80); 700 + val & ~0x80); 614 701 } 615 702 } 616 703 617 704 data->last_updated = jiffies; 618 - data->valid = 1; 705 + data->valid = true; 619 706 } 620 707 708 + error: 621 709 mutex_unlock(&data->update_lock); 710 + 711 + if (val < 0) 712 + return ERR_PTR(val); 622 713 623 714 return data; 624 715 } ··· 790 709 { 791 710 if (data->flags & LM90_FLAG_ADT7461_EXT) 792 711 return (val - 64) * 1000; 793 - else 794 - return temp_from_s8(val); 712 + return temp_from_s8(val); 795 713 } 796 714 797 715 static inline int temp_from_u16_adt7461(struct lm90_data *data, u16 val) 798 716 { 799 717 if (data->flags & LM90_FLAG_ADT7461_EXT) 800 718 return (val - 0x4000) / 64 * 250; 801 - else 802 - return temp_from_s16(val); 719 + return temp_from_s16(val); 803 720 } 804 721 805 722 static u8 temp_to_u8_adt7461(struct lm90_data *data, long val) ··· 808 729 if (val >= 191000) 809 730 return 0xFF; 810 731 return (val + 500 + 64000) / 1000; 811 - } else { 812 - if (val <= 0) 813 - return 0; 814 - if (val >= 127000) 815 - return 127; 816 - return (val + 500) / 1000; 817 732 } 733 + if (val <= 0) 734 + return 0; 735 + if (val >= 127000) 736 + return 127; 737 + return (val + 500) / 1000; 818 738 } 819 739 820 740 static u16 temp_to_u16_adt7461(struct lm90_data *data, long val) ··· 824 746 if (val >= 191750) 825 747 return 0xFFC0; 826 748 return (val + 64000 + 125) / 250 * 64; 827 - } else { 828 - if (val <= 0) 829 - return 0; 830 - if (val >= 127750) 831 - return 0x7FC0; 832 - return (val + 125) / 250 * 64; 833 749 } 750 + if (val <= 0) 751 + return 0; 752 + if (val >= 127750) 753 + return 0x7FC0; 754 + return (val + 125) / 250 * 64; 834 755 } 835 756 836 757 /* ··· 842 765 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 843 766 struct lm90_data *data = lm90_update_device(dev); 844 767 int temp; 768 + 769 + if (IS_ERR(data)) 770 + return PTR_ERR(data); 845 771 846 772 if (data->kind == adt7461 || data->kind == tmp451) 847 773 temp = temp_from_u8_adt7461(data, data->temp8[attr->index]); ··· 911 831 struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); 912 832 struct lm90_data *data = lm90_update_device(dev); 913 833 int temp; 834 + 835 + if (IS_ERR(data)) 836 + return PTR_ERR(data); 914 837 915 838 if (data->kind == adt7461 || data->kind == tmp451) 916 839 temp = temp_from_u16_adt7461(data, data->temp11[attr->index]); ··· 990 907 struct lm90_data *data = lm90_update_device(dev); 991 908 int temp; 992 909 910 + if (IS_ERR(data)) 911 + return PTR_ERR(data); 912 + 993 913 if (data->kind == adt7461 || data->kind == tmp451) 994 914 temp = temp_from_u8_adt7461(data, data->temp8[attr->index]); 995 915 else if (data->kind == max6646) ··· 1039 953 char *buf) 1040 954 { 1041 955 struct lm90_data *data = lm90_update_device(dev); 956 + 957 + if (IS_ERR(data)) 958 + return PTR_ERR(data); 959 + 1042 960 return sprintf(buf, "%d\n", data->alarms); 1043 961 } 1044 962 ··· 1052 962 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 1053 963 struct lm90_data *data = lm90_update_device(dev); 1054 964 int bitnr = attr->index; 965 + 966 + if (IS_ERR(data)) 967 + return PTR_ERR(data); 1055 968 1056 969 return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1); 1057 970 } ··· 1497 1404 return 0; 1498 1405 } 1499 1406 1500 - static void lm90_restore_conf(struct i2c_client *client, struct lm90_data *data) 1407 + static void lm90_restore_conf(void *_data) 1501 1408 { 1409 + struct lm90_data *data = _data; 1410 + struct i2c_client *client = data->client; 1411 + 1502 1412 /* Restore initial configuration */ 1503 1413 i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE, 1504 1414 data->convrate_orig); ··· 1509 1413 data->config_orig); 1510 1414 } 1511 1415 1512 - static void lm90_init_client(struct i2c_client *client, struct lm90_data *data) 1416 + static int lm90_init_client(struct i2c_client *client, struct lm90_data *data) 1513 1417 { 1514 - u8 config, convrate; 1418 + int config, convrate; 1515 1419 1516 - if (lm90_read_reg(client, LM90_REG_R_CONVRATE, &convrate) < 0) { 1517 - dev_warn(&client->dev, "Failed to read convrate register!\n"); 1518 - convrate = LM90_DEF_CONVRATE_RVAL; 1519 - } 1420 + convrate = lm90_read_reg(client, LM90_REG_R_CONVRATE); 1421 + if (convrate < 0) 1422 + return convrate; 1520 1423 data->convrate_orig = convrate; 1521 1424 1522 1425 /* 1523 1426 * Start the conversions. 1524 1427 */ 1525 1428 lm90_set_convrate(client, data, 500); /* 500ms; 2Hz conversion rate */ 1526 - if (lm90_read_reg(client, LM90_REG_R_CONFIG1, &config) < 0) { 1527 - dev_warn(&client->dev, "Initialization failed!\n"); 1528 - return; 1529 - } 1429 + config = lm90_read_reg(client, LM90_REG_R_CONFIG1); 1430 + if (config < 0) 1431 + return config; 1530 1432 data->config_orig = config; 1531 1433 1532 1434 /* Check Temperature Range Select */ ··· 1550 1456 config &= 0xBF; /* run */ 1551 1457 if (config != data->config_orig) /* Only write if changed */ 1552 1458 i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config); 1459 + 1460 + devm_add_action(&client->dev, lm90_restore_conf, data); 1461 + 1462 + return 0; 1553 1463 } 1554 1464 1555 1465 static bool lm90_is_tripped(struct i2c_client *client, u16 *status) 1556 1466 { 1557 1467 struct lm90_data *data = i2c_get_clientdata(client); 1558 - u8 st, st2 = 0; 1468 + int st, st2 = 0; 1559 1469 1560 - lm90_read_reg(client, LM90_REG_R_STATUS, &st); 1470 + st = lm90_read_reg(client, LM90_REG_R_STATUS); 1471 + if (st < 0) 1472 + return false; 1561 1473 1562 - if (data->kind == max6696) 1563 - lm90_read_reg(client, MAX6696_REG_R_STATUS2, &st2); 1474 + if (data->kind == max6696) { 1475 + st2 = lm90_read_reg(client, MAX6696_REG_R_STATUS2); 1476 + if (st2 < 0) 1477 + return false; 1478 + } 1564 1479 1565 1480 *status = st | (st2 << 8); 1566 1481 ··· 1609 1506 return IRQ_NONE; 1610 1507 } 1611 1508 1509 + static void lm90_remove_pec(void *dev) 1510 + { 1511 + device_remove_file(dev, &dev_attr_pec); 1512 + } 1513 + 1514 + static void lm90_regulator_disable(void *regulator) 1515 + { 1516 + regulator_disable(regulator); 1517 + } 1518 + 1612 1519 static int lm90_probe(struct i2c_client *client, 1613 1520 const struct i2c_device_id *id) 1614 1521 { ··· 1626 1513 struct i2c_adapter *adapter = to_i2c_adapter(dev->parent); 1627 1514 struct lm90_data *data; 1628 1515 struct regulator *regulator; 1516 + struct device *hwmon_dev; 1629 1517 int groups = 0; 1630 1518 int err; 1631 1519 ··· 1640 1526 return err; 1641 1527 } 1642 1528 1529 + devm_add_action(dev, lm90_regulator_disable, regulator); 1530 + 1643 1531 data = devm_kzalloc(dev, sizeof(struct lm90_data), GFP_KERNEL); 1644 1532 if (!data) 1645 1533 return -ENOMEM; ··· 1649 1533 data->client = client; 1650 1534 i2c_set_clientdata(client, data); 1651 1535 mutex_init(&data->update_lock); 1652 - 1653 - data->regulator = regulator; 1654 1536 1655 1537 /* Set the device type */ 1656 1538 data->kind = id->driver_data; ··· 1671 1557 data->max_convrate = lm90_params[data->kind].max_convrate; 1672 1558 1673 1559 /* Initialize the LM90 chip */ 1674 - lm90_init_client(client, data); 1560 + err = lm90_init_client(client, data); 1561 + if (err < 0) { 1562 + dev_err(dev, "Failed to initialize device\n"); 1563 + return err; 1564 + } 1675 1565 1676 1566 /* Register sysfs hooks */ 1677 1567 data->groups[groups++] = &lm90_group; ··· 1695 1577 if (client->flags & I2C_CLIENT_PEC) { 1696 1578 err = device_create_file(dev, &dev_attr_pec); 1697 1579 if (err) 1698 - goto exit_restore; 1580 + return err; 1581 + devm_add_action(dev, lm90_remove_pec, dev); 1699 1582 } 1700 1583 1701 - data->hwmon_dev = hwmon_device_register_with_groups(dev, client->name, 1702 - data, data->groups); 1703 - if (IS_ERR(data->hwmon_dev)) { 1704 - err = PTR_ERR(data->hwmon_dev); 1705 - goto exit_remove_pec; 1706 - } 1584 + hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, 1585 + data, data->groups); 1586 + if (IS_ERR(hwmon_dev)) 1587 + return PTR_ERR(hwmon_dev); 1707 1588 1708 1589 if (client->irq) { 1709 1590 dev_dbg(dev, "IRQ: %d\n", client->irq); ··· 1712 1595 "lm90", client); 1713 1596 if (err < 0) { 1714 1597 dev_err(dev, "cannot request IRQ %d\n", client->irq); 1715 - goto exit_unregister; 1598 + return err; 1716 1599 } 1717 1600 } 1718 - 1719 - return 0; 1720 - 1721 - exit_unregister: 1722 - hwmon_device_unregister(data->hwmon_dev); 1723 - exit_remove_pec: 1724 - device_remove_file(dev, &dev_attr_pec); 1725 - exit_restore: 1726 - lm90_restore_conf(client, data); 1727 - regulator_disable(data->regulator); 1728 - 1729 - return err; 1730 - } 1731 - 1732 - static int lm90_remove(struct i2c_client *client) 1733 - { 1734 - struct lm90_data *data = i2c_get_clientdata(client); 1735 - 1736 - hwmon_device_unregister(data->hwmon_dev); 1737 - device_remove_file(&client->dev, &dev_attr_pec); 1738 - lm90_restore_conf(client, data); 1739 - regulator_disable(data->regulator); 1740 1601 1741 1602 return 0; 1742 1603 } ··· 1731 1636 */ 1732 1637 struct lm90_data *data = i2c_get_clientdata(client); 1733 1638 1734 - if ((data->flags & LM90_HAVE_BROKEN_ALERT) 1735 - && (alarms & data->alert_alarms)) { 1736 - u8 config; 1639 + if ((data->flags & LM90_HAVE_BROKEN_ALERT) && 1640 + (alarms & data->alert_alarms)) { 1641 + int config; 1642 + 1737 1643 dev_dbg(&client->dev, "Disabling ALERT#\n"); 1738 - lm90_read_reg(client, LM90_REG_R_CONFIG1, &config); 1739 - i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, 1740 - config | 0x80); 1644 + config = lm90_read_reg(client, LM90_REG_R_CONFIG1); 1645 + if (config >= 0) 1646 + i2c_smbus_write_byte_data(client, 1647 + LM90_REG_W_CONFIG1, 1648 + config | 0x80); 1741 1649 } 1742 1650 } else { 1743 1651 dev_info(&client->dev, "Everything OK\n"); ··· 1753 1655 .name = "lm90", 1754 1656 }, 1755 1657 .probe = lm90_probe, 1756 - .remove = lm90_remove, 1757 1658 .alert = lm90_alert, 1758 1659 .id_table = lm90_id, 1759 1660 .detect = lm90_detect,
+775
drivers/hwmon/sht3x.c
··· 1 + /* Sensirion SHT3x-DIS humidity and temperature sensor driver. 2 + * The SHT3x comes in many different versions, this driver is for the 3 + * I2C version only. 4 + * 5 + * Copyright (C) 2016 Sensirion AG, Switzerland 6 + * Author: David Frey <david.frey@sensirion.com> 7 + * Author: Pascal Sachs <pascal.sachs@sensirion.com> 8 + * 9 + * This program is free software; you can redistribute it and/or modify 10 + * it under the terms of the GNU General Public License as published by 11 + * the Free Software Foundation; either version 2 of the License, or 12 + * (at your option) any later version. 13 + * 14 + * This program is distributed in the hope that it will be useful, 15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 + * GNU General Public License for more details. 18 + * 19 + */ 20 + 21 + #include <asm/page.h> 22 + #include <linux/crc8.h> 23 + #include <linux/delay.h> 24 + #include <linux/err.h> 25 + #include <linux/hwmon.h> 26 + #include <linux/hwmon-sysfs.h> 27 + #include <linux/i2c.h> 28 + #include <linux/init.h> 29 + #include <linux/kernel.h> 30 + #include <linux/module.h> 31 + #include <linux/slab.h> 32 + #include <linux/jiffies.h> 33 + #include <linux/platform_data/sht3x.h> 34 + 35 + /* commands (high precision mode) */ 36 + static const unsigned char sht3x_cmd_measure_blocking_hpm[] = { 0x2c, 0x06 }; 37 + static const unsigned char sht3x_cmd_measure_nonblocking_hpm[] = { 0x24, 0x00 }; 38 + 39 + /* commands (low power mode) */ 40 + static const unsigned char sht3x_cmd_measure_blocking_lpm[] = { 0x2c, 0x10 }; 41 + static const unsigned char sht3x_cmd_measure_nonblocking_lpm[] = { 0x24, 0x16 }; 42 + 43 + /* commands for periodic mode */ 44 + static const unsigned char sht3x_cmd_measure_periodic_mode[] = { 0xe0, 0x00 }; 45 + static const unsigned char sht3x_cmd_break[] = { 0x30, 0x93 }; 46 + 47 + /* commands for heater control */ 48 + static const unsigned char sht3x_cmd_heater_on[] = { 0x30, 0x6d }; 49 + static const unsigned char sht3x_cmd_heater_off[] = { 0x30, 0x66 }; 50 + 51 + /* other commands */ 52 + static const unsigned char sht3x_cmd_read_status_reg[] = { 0xf3, 0x2d }; 53 + static const unsigned char sht3x_cmd_clear_status_reg[] = { 0x30, 0x41 }; 54 + 55 + /* delays for non-blocking i2c commands, both in us */ 56 + #define SHT3X_NONBLOCKING_WAIT_TIME_HPM 15000 57 + #define SHT3X_NONBLOCKING_WAIT_TIME_LPM 4000 58 + 59 + #define SHT3X_WORD_LEN 2 60 + #define SHT3X_CMD_LENGTH 2 61 + #define SHT3X_CRC8_LEN 1 62 + #define SHT3X_RESPONSE_LENGTH 6 63 + #define SHT3X_CRC8_POLYNOMIAL 0x31 64 + #define SHT3X_CRC8_INIT 0xFF 65 + #define SHT3X_MIN_TEMPERATURE -45000 66 + #define SHT3X_MAX_TEMPERATURE 130000 67 + #define SHT3X_MIN_HUMIDITY 0 68 + #define SHT3X_MAX_HUMIDITY 100000 69 + 70 + enum sht3x_chips { 71 + sht3x, 72 + sts3x, 73 + }; 74 + 75 + enum sht3x_limits { 76 + limit_max = 0, 77 + limit_max_hyst, 78 + limit_min, 79 + limit_min_hyst, 80 + }; 81 + 82 + DECLARE_CRC8_TABLE(sht3x_crc8_table); 83 + 84 + /* periodic measure commands (high precision mode) */ 85 + static const char periodic_measure_commands_hpm[][SHT3X_CMD_LENGTH] = { 86 + /* 0.5 measurements per second */ 87 + {0x20, 0x32}, 88 + /* 1 measurements per second */ 89 + {0x21, 0x30}, 90 + /* 2 measurements per second */ 91 + {0x22, 0x36}, 92 + /* 4 measurements per second */ 93 + {0x23, 0x34}, 94 + /* 10 measurements per second */ 95 + {0x27, 0x37}, 96 + }; 97 + 98 + /* periodic measure commands (low power mode) */ 99 + static const char periodic_measure_commands_lpm[][SHT3X_CMD_LENGTH] = { 100 + /* 0.5 measurements per second */ 101 + {0x20, 0x2f}, 102 + /* 1 measurements per second */ 103 + {0x21, 0x2d}, 104 + /* 2 measurements per second */ 105 + {0x22, 0x2b}, 106 + /* 4 measurements per second */ 107 + {0x23, 0x29}, 108 + /* 10 measurements per second */ 109 + {0x27, 0x2a}, 110 + }; 111 + 112 + struct sht3x_limit_commands { 113 + const char read_command[SHT3X_CMD_LENGTH]; 114 + const char write_command[SHT3X_CMD_LENGTH]; 115 + }; 116 + 117 + static const struct sht3x_limit_commands limit_commands[] = { 118 + /* temp1_max, humidity1_max */ 119 + [limit_max] = { {0xe1, 0x1f}, {0x61, 0x1d} }, 120 + /* temp_1_max_hyst, humidity1_max_hyst */ 121 + [limit_max_hyst] = { {0xe1, 0x14}, {0x61, 0x16} }, 122 + /* temp1_min, humidity1_min */ 123 + [limit_min] = { {0xe1, 0x02}, {0x61, 0x00} }, 124 + /* temp_1_min_hyst, humidity1_min_hyst */ 125 + [limit_min_hyst] = { {0xe1, 0x09}, {0x61, 0x0B} }, 126 + }; 127 + 128 + #define SHT3X_NUM_LIMIT_CMD ARRAY_SIZE(limit_commands) 129 + 130 + static const u16 mode_to_update_interval[] = { 131 + 0, 132 + 2000, 133 + 1000, 134 + 500, 135 + 250, 136 + 100, 137 + }; 138 + 139 + struct sht3x_data { 140 + struct i2c_client *client; 141 + struct mutex i2c_lock; /* lock for sending i2c commands */ 142 + struct mutex data_lock; /* lock for updating driver data */ 143 + 144 + u8 mode; 145 + const unsigned char *command; 146 + u32 wait_time; /* in us*/ 147 + unsigned long last_update; /* last update in periodic mode*/ 148 + 149 + struct sht3x_platform_data setup; 150 + 151 + /* 152 + * cached values for temperature and humidity and limits 153 + * the limits arrays have the following order: 154 + * max, max_hyst, min, min_hyst 155 + */ 156 + int temperature; 157 + int temperature_limits[SHT3X_NUM_LIMIT_CMD]; 158 + u32 humidity; 159 + u32 humidity_limits[SHT3X_NUM_LIMIT_CMD]; 160 + }; 161 + 162 + static u8 get_mode_from_update_interval(u16 value) 163 + { 164 + size_t index; 165 + u8 number_of_modes = ARRAY_SIZE(mode_to_update_interval); 166 + 167 + if (value == 0) 168 + return 0; 169 + 170 + /* find next faster update interval */ 171 + for (index = 1; index < number_of_modes; index++) { 172 + if (mode_to_update_interval[index] <= value) 173 + return index; 174 + } 175 + 176 + return number_of_modes - 1; 177 + } 178 + 179 + static int sht3x_read_from_command(struct i2c_client *client, 180 + struct sht3x_data *data, 181 + const char *command, 182 + char *buf, int length, u32 wait_time) 183 + { 184 + int ret; 185 + 186 + mutex_lock(&data->i2c_lock); 187 + ret = i2c_master_send(client, command, SHT3X_CMD_LENGTH); 188 + 189 + if (ret != SHT3X_CMD_LENGTH) { 190 + ret = ret < 0 ? ret : -EIO; 191 + goto out; 192 + } 193 + 194 + if (wait_time) 195 + usleep_range(wait_time, wait_time + 1000); 196 + 197 + ret = i2c_master_recv(client, buf, length); 198 + if (ret != length) { 199 + ret = ret < 0 ? ret : -EIO; 200 + goto out; 201 + } 202 + 203 + ret = 0; 204 + out: 205 + mutex_unlock(&data->i2c_lock); 206 + return ret; 207 + } 208 + 209 + static int sht3x_extract_temperature(u16 raw) 210 + { 211 + /* 212 + * From datasheet: 213 + * T = -45 + 175 * ST / 2^16 214 + * Adapted for integer fixed point (3 digit) arithmetic. 215 + */ 216 + return ((21875 * (int)raw) >> 13) - 45000; 217 + } 218 + 219 + static u32 sht3x_extract_humidity(u16 raw) 220 + { 221 + /* 222 + * From datasheet: 223 + * RH = 100 * SRH / 2^16 224 + * Adapted for integer fixed point (3 digit) arithmetic. 225 + */ 226 + return (12500 * (u32)raw) >> 13; 227 + } 228 + 229 + static struct sht3x_data *sht3x_update_client(struct device *dev) 230 + { 231 + struct sht3x_data *data = dev_get_drvdata(dev); 232 + struct i2c_client *client = data->client; 233 + u16 interval_ms = mode_to_update_interval[data->mode]; 234 + unsigned long interval_jiffies = msecs_to_jiffies(interval_ms); 235 + unsigned char buf[SHT3X_RESPONSE_LENGTH]; 236 + u16 val; 237 + int ret = 0; 238 + 239 + mutex_lock(&data->data_lock); 240 + /* 241 + * Only update cached readings once per update interval in periodic 242 + * mode. In single shot mode the sensor measures values on demand, so 243 + * every time the sysfs interface is called, a measurement is triggered. 244 + * In periodic mode however, the measurement process is handled 245 + * internally by the sensor and reading out sensor values only makes 246 + * sense if a new reading is available. 247 + */ 248 + if (time_after(jiffies, data->last_update + interval_jiffies)) { 249 + ret = sht3x_read_from_command(client, data, data->command, buf, 250 + sizeof(buf), data->wait_time); 251 + if (ret) 252 + goto out; 253 + 254 + val = be16_to_cpup((__be16 *)buf); 255 + data->temperature = sht3x_extract_temperature(val); 256 + val = be16_to_cpup((__be16 *)(buf + 3)); 257 + data->humidity = sht3x_extract_humidity(val); 258 + data->last_update = jiffies; 259 + } 260 + 261 + out: 262 + mutex_unlock(&data->data_lock); 263 + if (ret) 264 + return ERR_PTR(ret); 265 + 266 + return data; 267 + } 268 + 269 + /* sysfs attributes */ 270 + static ssize_t temp1_input_show(struct device *dev, 271 + struct device_attribute *attr, char *buf) 272 + { 273 + struct sht3x_data *data = sht3x_update_client(dev); 274 + 275 + if (IS_ERR(data)) 276 + return PTR_ERR(data); 277 + 278 + return sprintf(buf, "%d\n", data->temperature); 279 + } 280 + 281 + static ssize_t humidity1_input_show(struct device *dev, 282 + struct device_attribute *attr, char *buf) 283 + { 284 + struct sht3x_data *data = sht3x_update_client(dev); 285 + 286 + if (IS_ERR(data)) 287 + return PTR_ERR(data); 288 + 289 + return sprintf(buf, "%u\n", data->humidity); 290 + } 291 + 292 + /* 293 + * limits_update must only be called from probe or with data_lock held 294 + */ 295 + static int limits_update(struct sht3x_data *data) 296 + { 297 + int ret; 298 + u8 index; 299 + int temperature; 300 + u32 humidity; 301 + u16 raw; 302 + char buffer[SHT3X_RESPONSE_LENGTH]; 303 + const struct sht3x_limit_commands *commands; 304 + struct i2c_client *client = data->client; 305 + 306 + for (index = 0; index < SHT3X_NUM_LIMIT_CMD; index++) { 307 + commands = &limit_commands[index]; 308 + ret = sht3x_read_from_command(client, data, 309 + commands->read_command, buffer, 310 + SHT3X_RESPONSE_LENGTH, 0); 311 + 312 + if (ret) 313 + return ret; 314 + 315 + raw = be16_to_cpup((__be16 *)buffer); 316 + temperature = sht3x_extract_temperature((raw & 0x01ff) << 7); 317 + humidity = sht3x_extract_humidity(raw & 0xfe00); 318 + data->temperature_limits[index] = temperature; 319 + data->humidity_limits[index] = humidity; 320 + } 321 + 322 + return ret; 323 + } 324 + 325 + static ssize_t temp1_limit_show(struct device *dev, 326 + struct device_attribute *attr, 327 + char *buf) 328 + { 329 + struct sht3x_data *data = dev_get_drvdata(dev); 330 + u8 index = to_sensor_dev_attr(attr)->index; 331 + int temperature_limit = data->temperature_limits[index]; 332 + 333 + return scnprintf(buf, PAGE_SIZE, "%d\n", temperature_limit); 334 + } 335 + 336 + static ssize_t humidity1_limit_show(struct device *dev, 337 + struct device_attribute *attr, 338 + char *buf) 339 + { 340 + struct sht3x_data *data = dev_get_drvdata(dev); 341 + u8 index = to_sensor_dev_attr(attr)->index; 342 + u32 humidity_limit = data->humidity_limits[index]; 343 + 344 + return scnprintf(buf, PAGE_SIZE, "%u\n", humidity_limit); 345 + } 346 + 347 + /* 348 + * limit_store must only be called with data_lock held 349 + */ 350 + static size_t limit_store(struct device *dev, 351 + size_t count, 352 + u8 index, 353 + int temperature, 354 + u32 humidity) 355 + { 356 + char buffer[SHT3X_CMD_LENGTH + SHT3X_WORD_LEN + SHT3X_CRC8_LEN]; 357 + char *position = buffer; 358 + int ret; 359 + u16 raw; 360 + struct sht3x_data *data = dev_get_drvdata(dev); 361 + struct i2c_client *client = data->client; 362 + const struct sht3x_limit_commands *commands; 363 + 364 + commands = &limit_commands[index]; 365 + 366 + memcpy(position, commands->write_command, SHT3X_CMD_LENGTH); 367 + position += SHT3X_CMD_LENGTH; 368 + /* 369 + * ST = (T + 45) / 175 * 2^16 370 + * SRH = RH / 100 * 2^16 371 + * adapted for fixed point arithmetic and packed the same as 372 + * in limit_show() 373 + */ 374 + raw = ((u32)(temperature + 45000) * 24543) >> (16 + 7); 375 + raw |= ((humidity * 42950) >> 16) & 0xfe00; 376 + 377 + *((__be16 *)position) = cpu_to_be16(raw); 378 + position += SHT3X_WORD_LEN; 379 + *position = crc8(sht3x_crc8_table, 380 + position - SHT3X_WORD_LEN, 381 + SHT3X_WORD_LEN, 382 + SHT3X_CRC8_INIT); 383 + 384 + mutex_lock(&data->i2c_lock); 385 + ret = i2c_master_send(client, buffer, sizeof(buffer)); 386 + mutex_unlock(&data->i2c_lock); 387 + 388 + if (ret != sizeof(buffer)) 389 + return ret < 0 ? ret : -EIO; 390 + 391 + data->temperature_limits[index] = temperature; 392 + data->humidity_limits[index] = humidity; 393 + return count; 394 + } 395 + 396 + static ssize_t temp1_limit_store(struct device *dev, 397 + struct device_attribute *attr, 398 + const char *buf, 399 + size_t count) 400 + { 401 + int temperature; 402 + int ret; 403 + struct sht3x_data *data = dev_get_drvdata(dev); 404 + u8 index = to_sensor_dev_attr(attr)->index; 405 + 406 + ret = kstrtoint(buf, 0, &temperature); 407 + if (ret) 408 + return ret; 409 + 410 + temperature = clamp_val(temperature, SHT3X_MIN_TEMPERATURE, 411 + SHT3X_MAX_TEMPERATURE); 412 + mutex_lock(&data->data_lock); 413 + ret = limit_store(dev, count, index, temperature, 414 + data->humidity_limits[index]); 415 + mutex_unlock(&data->data_lock); 416 + 417 + return ret; 418 + } 419 + 420 + static ssize_t humidity1_limit_store(struct device *dev, 421 + struct device_attribute *attr, 422 + const char *buf, 423 + size_t count) 424 + { 425 + u32 humidity; 426 + int ret; 427 + struct sht3x_data *data = dev_get_drvdata(dev); 428 + u8 index = to_sensor_dev_attr(attr)->index; 429 + 430 + ret = kstrtou32(buf, 0, &humidity); 431 + if (ret) 432 + return ret; 433 + 434 + humidity = clamp_val(humidity, SHT3X_MIN_HUMIDITY, SHT3X_MAX_HUMIDITY); 435 + mutex_lock(&data->data_lock); 436 + ret = limit_store(dev, count, index, data->temperature_limits[index], 437 + humidity); 438 + mutex_unlock(&data->data_lock); 439 + 440 + return ret; 441 + } 442 + 443 + static void sht3x_select_command(struct sht3x_data *data) 444 + { 445 + /* 446 + * In blocking mode (clock stretching mode) the I2C bus 447 + * is blocked for other traffic, thus the call to i2c_master_recv() 448 + * will wait until the data is ready. For non blocking mode, we 449 + * have to wait ourselves. 450 + */ 451 + if (data->mode > 0) { 452 + data->command = sht3x_cmd_measure_periodic_mode; 453 + data->wait_time = 0; 454 + } else if (data->setup.blocking_io) { 455 + data->command = data->setup.high_precision ? 456 + sht3x_cmd_measure_blocking_hpm : 457 + sht3x_cmd_measure_blocking_lpm; 458 + data->wait_time = 0; 459 + } else { 460 + if (data->setup.high_precision) { 461 + data->command = sht3x_cmd_measure_nonblocking_hpm; 462 + data->wait_time = SHT3X_NONBLOCKING_WAIT_TIME_HPM; 463 + } else { 464 + data->command = sht3x_cmd_measure_nonblocking_lpm; 465 + data->wait_time = SHT3X_NONBLOCKING_WAIT_TIME_LPM; 466 + } 467 + } 468 + } 469 + 470 + static int status_register_read(struct device *dev, 471 + struct device_attribute *attr, 472 + char *buffer, int length) 473 + { 474 + int ret; 475 + struct sht3x_data *data = dev_get_drvdata(dev); 476 + struct i2c_client *client = data->client; 477 + 478 + ret = sht3x_read_from_command(client, data, sht3x_cmd_read_status_reg, 479 + buffer, length, 0); 480 + 481 + return ret; 482 + } 483 + 484 + static ssize_t temp1_alarm_show(struct device *dev, 485 + struct device_attribute *attr, 486 + char *buf) 487 + { 488 + char buffer[SHT3X_WORD_LEN + SHT3X_CRC8_LEN]; 489 + int ret; 490 + 491 + ret = status_register_read(dev, attr, buffer, 492 + SHT3X_WORD_LEN + SHT3X_CRC8_LEN); 493 + if (ret) 494 + return ret; 495 + 496 + return scnprintf(buf, PAGE_SIZE, "%d\n", !!(buffer[0] & 0x04)); 497 + } 498 + 499 + static ssize_t humidity1_alarm_show(struct device *dev, 500 + struct device_attribute *attr, 501 + char *buf) 502 + { 503 + char buffer[SHT3X_WORD_LEN + SHT3X_CRC8_LEN]; 504 + int ret; 505 + 506 + ret = status_register_read(dev, attr, buffer, 507 + SHT3X_WORD_LEN + SHT3X_CRC8_LEN); 508 + if (ret) 509 + return ret; 510 + 511 + return scnprintf(buf, PAGE_SIZE, "%d\n", !!(buffer[0] & 0x08)); 512 + } 513 + 514 + static ssize_t heater_enable_show(struct device *dev, 515 + struct device_attribute *attr, 516 + char *buf) 517 + { 518 + char buffer[SHT3X_WORD_LEN + SHT3X_CRC8_LEN]; 519 + int ret; 520 + 521 + ret = status_register_read(dev, attr, buffer, 522 + SHT3X_WORD_LEN + SHT3X_CRC8_LEN); 523 + if (ret) 524 + return ret; 525 + 526 + return scnprintf(buf, PAGE_SIZE, "%d\n", !!(buffer[0] & 0x20)); 527 + } 528 + 529 + static ssize_t heater_enable_store(struct device *dev, 530 + struct device_attribute *attr, 531 + const char *buf, 532 + size_t count) 533 + { 534 + struct sht3x_data *data = dev_get_drvdata(dev); 535 + struct i2c_client *client = data->client; 536 + int ret; 537 + bool status; 538 + 539 + ret = kstrtobool(buf, &status); 540 + if (ret) 541 + return ret; 542 + 543 + mutex_lock(&data->i2c_lock); 544 + 545 + if (status) 546 + ret = i2c_master_send(client, (char *)&sht3x_cmd_heater_on, 547 + SHT3X_CMD_LENGTH); 548 + else 549 + ret = i2c_master_send(client, (char *)&sht3x_cmd_heater_off, 550 + SHT3X_CMD_LENGTH); 551 + 552 + mutex_unlock(&data->i2c_lock); 553 + 554 + return ret; 555 + } 556 + 557 + static ssize_t update_interval_show(struct device *dev, 558 + struct device_attribute *attr, 559 + char *buf) 560 + { 561 + struct sht3x_data *data = dev_get_drvdata(dev); 562 + 563 + return scnprintf(buf, PAGE_SIZE, "%u\n", 564 + mode_to_update_interval[data->mode]); 565 + } 566 + 567 + static ssize_t update_interval_store(struct device *dev, 568 + struct device_attribute *attr, 569 + const char *buf, 570 + size_t count) 571 + { 572 + u16 update_interval; 573 + u8 mode; 574 + int ret; 575 + const char *command; 576 + struct sht3x_data *data = dev_get_drvdata(dev); 577 + struct i2c_client *client = data->client; 578 + 579 + ret = kstrtou16(buf, 0, &update_interval); 580 + if (ret) 581 + return ret; 582 + 583 + mode = get_mode_from_update_interval(update_interval); 584 + 585 + mutex_lock(&data->data_lock); 586 + /* mode did not change */ 587 + if (mode == data->mode) { 588 + mutex_unlock(&data->data_lock); 589 + return count; 590 + } 591 + 592 + mutex_lock(&data->i2c_lock); 593 + /* 594 + * Abort periodic measure mode. 595 + * To do any changes to the configuration while in periodic mode, we 596 + * have to send a break command to the sensor, which then falls back 597 + * to single shot (mode = 0). 598 + */ 599 + if (data->mode > 0) { 600 + ret = i2c_master_send(client, sht3x_cmd_break, 601 + SHT3X_CMD_LENGTH); 602 + if (ret != SHT3X_CMD_LENGTH) 603 + goto out; 604 + data->mode = 0; 605 + } 606 + 607 + if (mode > 0) { 608 + if (data->setup.high_precision) 609 + command = periodic_measure_commands_hpm[mode - 1]; 610 + else 611 + command = periodic_measure_commands_lpm[mode - 1]; 612 + 613 + /* select mode */ 614 + ret = i2c_master_send(client, command, SHT3X_CMD_LENGTH); 615 + if (ret != SHT3X_CMD_LENGTH) 616 + goto out; 617 + } 618 + 619 + /* select mode and command */ 620 + data->mode = mode; 621 + sht3x_select_command(data); 622 + 623 + out: 624 + mutex_unlock(&data->i2c_lock); 625 + mutex_unlock(&data->data_lock); 626 + if (ret != SHT3X_CMD_LENGTH) 627 + return ret < 0 ? ret : -EIO; 628 + 629 + return count; 630 + } 631 + 632 + static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, temp1_input_show, NULL, 0); 633 + static SENSOR_DEVICE_ATTR(humidity1_input, S_IRUGO, humidity1_input_show, 634 + NULL, 0); 635 + static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, 636 + temp1_limit_show, temp1_limit_store, 637 + limit_max); 638 + static SENSOR_DEVICE_ATTR(humidity1_max, S_IRUGO | S_IWUSR, 639 + humidity1_limit_show, humidity1_limit_store, 640 + limit_max); 641 + static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, 642 + temp1_limit_show, temp1_limit_store, 643 + limit_max_hyst); 644 + static SENSOR_DEVICE_ATTR(humidity1_max_hyst, S_IRUGO | S_IWUSR, 645 + humidity1_limit_show, humidity1_limit_store, 646 + limit_max_hyst); 647 + static SENSOR_DEVICE_ATTR(temp1_min, S_IRUGO | S_IWUSR, 648 + temp1_limit_show, temp1_limit_store, 649 + limit_min); 650 + static SENSOR_DEVICE_ATTR(humidity1_min, S_IRUGO | S_IWUSR, 651 + humidity1_limit_show, humidity1_limit_store, 652 + limit_min); 653 + static SENSOR_DEVICE_ATTR(temp1_min_hyst, S_IRUGO | S_IWUSR, 654 + temp1_limit_show, temp1_limit_store, 655 + limit_min_hyst); 656 + static SENSOR_DEVICE_ATTR(humidity1_min_hyst, S_IRUGO | S_IWUSR, 657 + humidity1_limit_show, humidity1_limit_store, 658 + limit_min_hyst); 659 + static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, temp1_alarm_show, NULL, 0); 660 + static SENSOR_DEVICE_ATTR(humidity1_alarm, S_IRUGO, humidity1_alarm_show, 661 + NULL, 0); 662 + static SENSOR_DEVICE_ATTR(heater_enable, S_IRUGO | S_IWUSR, 663 + heater_enable_show, heater_enable_store, 0); 664 + static SENSOR_DEVICE_ATTR(update_interval, S_IRUGO | S_IWUSR, 665 + update_interval_show, update_interval_store, 0); 666 + 667 + static struct attribute *sht3x_attrs[] = { 668 + &sensor_dev_attr_temp1_input.dev_attr.attr, 669 + &sensor_dev_attr_humidity1_input.dev_attr.attr, 670 + &sensor_dev_attr_temp1_max.dev_attr.attr, 671 + &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, 672 + &sensor_dev_attr_humidity1_max.dev_attr.attr, 673 + &sensor_dev_attr_humidity1_max_hyst.dev_attr.attr, 674 + &sensor_dev_attr_temp1_min.dev_attr.attr, 675 + &sensor_dev_attr_temp1_min_hyst.dev_attr.attr, 676 + &sensor_dev_attr_humidity1_min.dev_attr.attr, 677 + &sensor_dev_attr_humidity1_min_hyst.dev_attr.attr, 678 + &sensor_dev_attr_temp1_alarm.dev_attr.attr, 679 + &sensor_dev_attr_humidity1_alarm.dev_attr.attr, 680 + &sensor_dev_attr_heater_enable.dev_attr.attr, 681 + &sensor_dev_attr_update_interval.dev_attr.attr, 682 + NULL 683 + }; 684 + 685 + static struct attribute *sts3x_attrs[] = { 686 + &sensor_dev_attr_temp1_input.dev_attr.attr, 687 + NULL 688 + }; 689 + 690 + ATTRIBUTE_GROUPS(sht3x); 691 + ATTRIBUTE_GROUPS(sts3x); 692 + 693 + static int sht3x_probe(struct i2c_client *client, 694 + const struct i2c_device_id *id) 695 + { 696 + int ret; 697 + struct sht3x_data *data; 698 + struct device *hwmon_dev; 699 + struct i2c_adapter *adap = client->adapter; 700 + struct device *dev = &client->dev; 701 + const struct attribute_group **attribute_groups; 702 + 703 + /* 704 + * we require full i2c support since the sht3x uses multi-byte read and 705 + * writes as well as multi-byte commands which are not supported by 706 + * the smbus protocol 707 + */ 708 + if (!i2c_check_functionality(adap, I2C_FUNC_I2C)) 709 + return -ENODEV; 710 + 711 + ret = i2c_master_send(client, sht3x_cmd_clear_status_reg, 712 + SHT3X_CMD_LENGTH); 713 + if (ret != SHT3X_CMD_LENGTH) 714 + return ret < 0 ? ret : -ENODEV; 715 + 716 + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); 717 + if (!data) 718 + return -ENOMEM; 719 + 720 + data->setup.blocking_io = false; 721 + data->setup.high_precision = true; 722 + data->mode = 0; 723 + data->last_update = 0; 724 + data->client = client; 725 + crc8_populate_msb(sht3x_crc8_table, SHT3X_CRC8_POLYNOMIAL); 726 + 727 + if (client->dev.platform_data) 728 + data->setup = *(struct sht3x_platform_data *)dev->platform_data; 729 + 730 + sht3x_select_command(data); 731 + 732 + mutex_init(&data->i2c_lock); 733 + mutex_init(&data->data_lock); 734 + 735 + ret = limits_update(data); 736 + if (ret) 737 + return ret; 738 + 739 + if (id->driver_data == sts3x) 740 + attribute_groups = sts3x_groups; 741 + else 742 + attribute_groups = sht3x_groups; 743 + 744 + hwmon_dev = devm_hwmon_device_register_with_groups(dev, 745 + client->name, 746 + data, 747 + attribute_groups); 748 + 749 + if (IS_ERR(hwmon_dev)) 750 + dev_dbg(dev, "unable to register hwmon device\n"); 751 + 752 + return PTR_ERR_OR_ZERO(hwmon_dev); 753 + } 754 + 755 + /* device ID table */ 756 + static const struct i2c_device_id sht3x_ids[] = { 757 + {"sht3x", sht3x}, 758 + {"sts3x", sts3x}, 759 + {} 760 + }; 761 + 762 + MODULE_DEVICE_TABLE(i2c, sht3x_ids); 763 + 764 + static struct i2c_driver sht3x_i2c_driver = { 765 + .driver.name = "sht3x", 766 + .probe = sht3x_probe, 767 + .id_table = sht3x_ids, 768 + }; 769 + 770 + module_i2c_driver(sht3x_i2c_driver); 771 + 772 + MODULE_AUTHOR("David Frey <david.frey@sensirion.com>"); 773 + MODULE_AUTHOR("Pascal Sachs <pascal.sachs@sensirion.com>"); 774 + MODULE_DESCRIPTION("Sensirion SHT3x humidity and temperature sensor driver"); 775 + MODULE_LICENSE("GPL");
+122 -127
drivers/hwmon/tmp102.c
··· 11 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 * GNU General Public License for more details. 14 - * 15 - * You should have received a copy of the GNU General Public License 16 - * along with this program; if not, write to the Free Software 17 - * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA 18 14 */ 19 15 16 + #include <linux/delay.h> 20 17 #include <linux/module.h> 21 18 #include <linux/init.h> 22 19 #include <linux/slab.h> ··· 24 27 #include <linux/mutex.h> 25 28 #include <linux/device.h> 26 29 #include <linux/jiffies.h> 30 + #include <linux/regmap.h> 27 31 #include <linux/thermal.h> 28 32 #include <linux/of.h> 29 33 ··· 48 50 #define TMP102_TLOW_REG 0x02 49 51 #define TMP102_THIGH_REG 0x03 50 52 53 + #define TMP102_CONFREG_MASK (TMP102_CONF_SD | TMP102_CONF_TM | \ 54 + TMP102_CONF_POL | TMP102_CONF_F0 | \ 55 + TMP102_CONF_F1 | TMP102_CONF_OS | \ 56 + TMP102_CONF_EM | TMP102_CONF_AL | \ 57 + TMP102_CONF_CR0 | TMP102_CONF_CR1) 58 + 59 + #define TMP102_CONFIG_CLEAR (TMP102_CONF_SD | TMP102_CONF_OS | \ 60 + TMP102_CONF_CR0) 61 + #define TMP102_CONFIG_SET (TMP102_CONF_TM | TMP102_CONF_EM | \ 62 + TMP102_CONF_CR1) 63 + 64 + #define CONVERSION_TIME_MS 35 /* in milli-seconds */ 65 + 51 66 struct tmp102 { 52 - struct i2c_client *client; 53 - struct device *hwmon_dev; 54 - struct mutex lock; 67 + struct regmap *regmap; 55 68 u16 config_orig; 56 - unsigned long last_update; 57 - int temp[3]; 58 - bool first_time; 69 + unsigned long ready_time; 59 70 }; 60 71 61 72 /* convert left adjusted 13-bit TMP102 register value to milliCelsius */ ··· 79 72 return (val * 128) / 1000; 80 73 } 81 74 82 - static const u8 tmp102_reg[] = { 83 - TMP102_TEMP_REG, 84 - TMP102_TLOW_REG, 85 - TMP102_THIGH_REG, 86 - }; 87 - 88 - static struct tmp102 *tmp102_update_device(struct device *dev) 89 - { 90 - struct tmp102 *tmp102 = dev_get_drvdata(dev); 91 - struct i2c_client *client = tmp102->client; 92 - 93 - mutex_lock(&tmp102->lock); 94 - if (time_after(jiffies, tmp102->last_update + HZ / 3)) { 95 - int i; 96 - for (i = 0; i < ARRAY_SIZE(tmp102->temp); ++i) { 97 - int status = i2c_smbus_read_word_swapped(client, 98 - tmp102_reg[i]); 99 - if (status > -1) 100 - tmp102->temp[i] = tmp102_reg_to_mC(status); 101 - } 102 - tmp102->last_update = jiffies; 103 - tmp102->first_time = false; 104 - } 105 - mutex_unlock(&tmp102->lock); 106 - return tmp102; 107 - } 108 - 109 75 static int tmp102_read_temp(void *dev, int *temp) 110 76 { 111 - struct tmp102 *tmp102 = tmp102_update_device(dev); 77 + struct tmp102 *tmp102 = dev_get_drvdata(dev); 78 + unsigned int reg; 79 + int ret; 112 80 113 - /* Is it too early even to return a conversion? */ 114 - if (tmp102->first_time) { 81 + if (time_before(jiffies, tmp102->ready_time)) { 115 82 dev_dbg(dev, "%s: Conversion not ready yet..\n", __func__); 116 83 return -EAGAIN; 117 84 } 118 85 119 - *temp = tmp102->temp[0]; 86 + ret = regmap_read(tmp102->regmap, TMP102_TEMP_REG, &reg); 87 + if (ret < 0) 88 + return ret; 89 + 90 + *temp = tmp102_reg_to_mC(reg); 120 91 121 92 return 0; 122 93 } ··· 104 119 char *buf) 105 120 { 106 121 struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); 107 - struct tmp102 *tmp102 = tmp102_update_device(dev); 122 + struct tmp102 *tmp102 = dev_get_drvdata(dev); 123 + int regaddr = sda->index; 124 + unsigned int reg; 125 + int err; 108 126 109 - /* Is it too early even to return a read? */ 110 - if (tmp102->first_time) 127 + if (regaddr == TMP102_TEMP_REG && 128 + time_before(jiffies, tmp102->ready_time)) 111 129 return -EAGAIN; 112 130 113 - return sprintf(buf, "%d\n", tmp102->temp[sda->index]); 131 + err = regmap_read(tmp102->regmap, regaddr, &reg); 132 + if (err < 0) 133 + return err; 134 + 135 + return sprintf(buf, "%d\n", tmp102_reg_to_mC(reg)); 114 136 } 115 137 116 138 static ssize_t tmp102_set_temp(struct device *dev, ··· 126 134 { 127 135 struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); 128 136 struct tmp102 *tmp102 = dev_get_drvdata(dev); 129 - struct i2c_client *client = tmp102->client; 137 + int reg = sda->index; 130 138 long val; 131 - int status; 139 + int err; 132 140 133 141 if (kstrtol(buf, 10, &val) < 0) 134 142 return -EINVAL; 135 143 val = clamp_val(val, -256000, 255000); 136 144 137 - mutex_lock(&tmp102->lock); 138 - tmp102->temp[sda->index] = val; 139 - status = i2c_smbus_write_word_swapped(client, tmp102_reg[sda->index], 140 - tmp102_mC_to_reg(val)); 141 - mutex_unlock(&tmp102->lock); 142 - return status ? : count; 145 + err = regmap_write(tmp102->regmap, reg, tmp102_mC_to_reg(val)); 146 + return err ? : count; 143 147 } 144 148 145 - static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, tmp102_show_temp, NULL , 0); 149 + static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, tmp102_show_temp, NULL, 150 + TMP102_TEMP_REG); 146 151 147 152 static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO, tmp102_show_temp, 148 - tmp102_set_temp, 1); 153 + tmp102_set_temp, TMP102_TLOW_REG); 149 154 150 155 static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, tmp102_show_temp, 151 - tmp102_set_temp, 2); 156 + tmp102_set_temp, TMP102_THIGH_REG); 152 157 153 158 static struct attribute *tmp102_attrs[] = { 154 159 &sensor_dev_attr_temp1_input.dev_attr.attr, ··· 155 166 }; 156 167 ATTRIBUTE_GROUPS(tmp102); 157 168 158 - #define TMP102_CONFIG (TMP102_CONF_TM | TMP102_CONF_EM | TMP102_CONF_CR1) 159 - #define TMP102_CONFIG_RD_ONLY (TMP102_CONF_R0 | TMP102_CONF_R1 | TMP102_CONF_AL) 160 - 161 169 static const struct thermal_zone_of_device_ops tmp102_of_thermal_ops = { 162 170 .get_temp = tmp102_read_temp, 171 + }; 172 + 173 + static void tmp102_restore_config(void *data) 174 + { 175 + struct tmp102 *tmp102 = data; 176 + 177 + regmap_write(tmp102->regmap, TMP102_CONF_REG, tmp102->config_orig); 178 + } 179 + 180 + static bool tmp102_is_writeable_reg(struct device *dev, unsigned int reg) 181 + { 182 + return reg != TMP102_TEMP_REG; 183 + } 184 + 185 + static bool tmp102_is_volatile_reg(struct device *dev, unsigned int reg) 186 + { 187 + return reg == TMP102_TEMP_REG; 188 + } 189 + 190 + static const struct regmap_config tmp102_regmap_config = { 191 + .reg_bits = 8, 192 + .val_bits = 16, 193 + .max_register = TMP102_THIGH_REG, 194 + .writeable_reg = tmp102_is_writeable_reg, 195 + .volatile_reg = tmp102_is_volatile_reg, 196 + .val_format_endian = REGMAP_ENDIAN_BIG, 197 + .cache_type = REGCACHE_RBTREE, 198 + .use_single_rw = true, 163 199 }; 164 200 165 201 static int tmp102_probe(struct i2c_client *client, ··· 193 179 struct device *dev = &client->dev; 194 180 struct device *hwmon_dev; 195 181 struct tmp102 *tmp102; 196 - int status; 182 + unsigned int regval; 183 + int err; 197 184 198 185 if (!i2c_check_functionality(client->adapter, 199 186 I2C_FUNC_SMBUS_WORD_DATA)) { ··· 208 193 return -ENOMEM; 209 194 210 195 i2c_set_clientdata(client, tmp102); 211 - tmp102->client = client; 212 196 213 - status = i2c_smbus_read_word_swapped(client, TMP102_CONF_REG); 214 - if (status < 0) { 197 + tmp102->regmap = devm_regmap_init_i2c(client, &tmp102_regmap_config); 198 + if (IS_ERR(tmp102->regmap)) 199 + return PTR_ERR(tmp102->regmap); 200 + 201 + err = regmap_read(tmp102->regmap, TMP102_CONF_REG, &regval); 202 + if (err < 0) { 215 203 dev_err(dev, "error reading config register\n"); 216 - return status; 204 + return err; 217 205 } 218 - tmp102->config_orig = status; 219 - status = i2c_smbus_write_word_swapped(client, TMP102_CONF_REG, 220 - TMP102_CONFIG); 221 - if (status < 0) { 206 + 207 + if ((regval & ~TMP102_CONFREG_MASK) != 208 + (TMP102_CONF_R0 | TMP102_CONF_R1)) { 209 + dev_err(dev, "unexpected config register value\n"); 210 + return -ENODEV; 211 + } 212 + 213 + tmp102->config_orig = regval; 214 + 215 + devm_add_action(dev, tmp102_restore_config, tmp102); 216 + 217 + regval &= ~TMP102_CONFIG_CLEAR; 218 + regval |= TMP102_CONFIG_SET; 219 + 220 + err = regmap_write(tmp102->regmap, TMP102_CONF_REG, regval); 221 + if (err < 0) { 222 222 dev_err(dev, "error writing config register\n"); 223 - goto fail_restore_config; 223 + return err; 224 224 } 225 - status = i2c_smbus_read_word_swapped(client, TMP102_CONF_REG); 226 - if (status < 0) { 227 - dev_err(dev, "error reading config register\n"); 228 - goto fail_restore_config; 229 - } 230 - status &= ~TMP102_CONFIG_RD_ONLY; 231 - if (status != TMP102_CONFIG) { 232 - dev_err(dev, "config settings did not stick\n"); 233 - status = -ENODEV; 234 - goto fail_restore_config; 235 - } 236 - tmp102->last_update = jiffies; 237 - /* Mark that we are not ready with data until conversion is complete */ 238 - tmp102->first_time = true; 239 - mutex_init(&tmp102->lock); 240 225 241 - hwmon_dev = hwmon_device_register_with_groups(dev, client->name, 242 - tmp102, tmp102_groups); 226 + tmp102->ready_time = jiffies; 227 + if (tmp102->config_orig & TMP102_CONF_SD) { 228 + /* 229 + * Mark that we are not ready with data until the first 230 + * conversion is complete 231 + */ 232 + tmp102->ready_time += msecs_to_jiffies(CONVERSION_TIME_MS); 233 + } 234 + 235 + hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, 236 + tmp102, 237 + tmp102_groups); 243 238 if (IS_ERR(hwmon_dev)) { 244 239 dev_dbg(dev, "unable to register hwmon device\n"); 245 - status = PTR_ERR(hwmon_dev); 246 - goto fail_restore_config; 240 + return PTR_ERR(hwmon_dev); 247 241 } 248 - tmp102->hwmon_dev = hwmon_dev; 249 242 devm_thermal_zone_of_sensor_register(hwmon_dev, 0, hwmon_dev, 250 243 &tmp102_of_thermal_ops); 251 244 252 245 dev_info(dev, "initialized\n"); 253 - 254 - return 0; 255 - 256 - fail_restore_config: 257 - i2c_smbus_write_word_swapped(client, TMP102_CONF_REG, 258 - tmp102->config_orig); 259 - return status; 260 - } 261 - 262 - static int tmp102_remove(struct i2c_client *client) 263 - { 264 - struct tmp102 *tmp102 = i2c_get_clientdata(client); 265 - 266 - hwmon_device_unregister(tmp102->hwmon_dev); 267 - 268 - /* Stop monitoring if device was stopped originally */ 269 - if (tmp102->config_orig & TMP102_CONF_SD) { 270 - int config; 271 - 272 - config = i2c_smbus_read_word_swapped(client, TMP102_CONF_REG); 273 - if (config >= 0) 274 - i2c_smbus_write_word_swapped(client, TMP102_CONF_REG, 275 - config | TMP102_CONF_SD); 276 - } 277 246 278 247 return 0; 279 248 } ··· 266 267 static int tmp102_suspend(struct device *dev) 267 268 { 268 269 struct i2c_client *client = to_i2c_client(dev); 269 - int config; 270 + struct tmp102 *tmp102 = i2c_get_clientdata(client); 270 271 271 - config = i2c_smbus_read_word_swapped(client, TMP102_CONF_REG); 272 - if (config < 0) 273 - return config; 274 - 275 - config |= TMP102_CONF_SD; 276 - return i2c_smbus_write_word_swapped(client, TMP102_CONF_REG, config); 272 + return regmap_update_bits(tmp102->regmap, TMP102_CONF_REG, 273 + TMP102_CONF_SD, TMP102_CONF_SD); 277 274 } 278 275 279 276 static int tmp102_resume(struct device *dev) 280 277 { 281 278 struct i2c_client *client = to_i2c_client(dev); 282 - int config; 279 + struct tmp102 *tmp102 = i2c_get_clientdata(client); 280 + int err; 283 281 284 - config = i2c_smbus_read_word_swapped(client, TMP102_CONF_REG); 285 - if (config < 0) 286 - return config; 282 + err = regmap_update_bits(tmp102->regmap, TMP102_CONF_REG, 283 + TMP102_CONF_SD, 0); 287 284 288 - config &= ~TMP102_CONF_SD; 289 - return i2c_smbus_write_word_swapped(client, TMP102_CONF_REG, config); 285 + tmp102->ready_time = jiffies + msecs_to_jiffies(CONVERSION_TIME_MS); 286 + 287 + return err; 290 288 } 291 289 #endif /* CONFIG_PM */ 292 290 ··· 299 303 .driver.name = DRIVER_NAME, 300 304 .driver.pm = &tmp102_dev_pm_ops, 301 305 .probe = tmp102_probe, 302 - .remove = tmp102_remove, 303 306 .id_table = tmp102_id, 304 307 }; 305 308
+29 -6
drivers/hwmon/tmp401.c
··· 47 47 static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4c, 0x4d, 48 48 0x4e, 0x4f, I2C_CLIENT_END }; 49 49 50 - enum chips { tmp401, tmp411, tmp431, tmp432, tmp435 }; 50 + enum chips { tmp401, tmp411, tmp431, tmp432, tmp435, tmp461 }; 51 51 52 52 /* 53 53 * The TMP401 registers, note some registers have different addresses for ··· 62 62 #define TMP401_MANUFACTURER_ID_REG 0xFE 63 63 #define TMP401_DEVICE_ID_REG 0xFF 64 64 65 - static const u8 TMP401_TEMP_MSB_READ[6][2] = { 65 + static const u8 TMP401_TEMP_MSB_READ[7][2] = { 66 66 { 0x00, 0x01 }, /* temp */ 67 67 { 0x06, 0x08 }, /* low limit */ 68 68 { 0x05, 0x07 }, /* high limit */ 69 69 { 0x20, 0x19 }, /* therm (crit) limit */ 70 70 { 0x30, 0x34 }, /* lowest */ 71 71 { 0x32, 0x36 }, /* highest */ 72 + { 0, 0x11 }, /* offset */ 72 73 }; 73 74 74 - static const u8 TMP401_TEMP_MSB_WRITE[6][2] = { 75 + static const u8 TMP401_TEMP_MSB_WRITE[7][2] = { 75 76 { 0, 0 }, /* temp (unused) */ 76 77 { 0x0C, 0x0E }, /* low limit */ 77 78 { 0x0B, 0x0D }, /* high limit */ 78 79 { 0x20, 0x19 }, /* therm (crit) limit */ 79 80 { 0x30, 0x34 }, /* lowest */ 80 81 { 0x32, 0x36 }, /* highest */ 82 + { 0, 0x11 }, /* offset */ 81 83 }; 82 84 83 - static const u8 TMP401_TEMP_LSB[6][2] = { 85 + static const u8 TMP401_TEMP_LSB[7][2] = { 84 86 { 0x15, 0x10 }, /* temp */ 85 87 { 0x17, 0x14 }, /* low limit */ 86 88 { 0x16, 0x13 }, /* high limit */ 87 89 { 0, 0 }, /* therm (crit) limit (unused) */ 88 90 { 0x31, 0x35 }, /* lowest */ 89 91 { 0x33, 0x37 }, /* highest */ 92 + { 0, 0x12 }, /* offset */ 90 93 }; 91 94 92 95 static const u8 TMP432_TEMP_MSB_READ[4][3] = { ··· 152 149 { "tmp431", tmp431 }, 153 150 { "tmp432", tmp432 }, 154 151 { "tmp435", tmp435 }, 152 + { "tmp461", tmp461 }, 155 153 { } 156 154 }; 157 155 MODULE_DEVICE_TABLE(i2c, tmp401_id); ··· 174 170 /* register values */ 175 171 u8 status[4]; 176 172 u8 config; 177 - u16 temp[6][3]; 173 + u16 temp[7][3]; 178 174 u8 temp_crit_hyst; 179 175 }; 180 176 ··· 617 613 }; 618 614 619 615 /* 616 + * Additional features of the TMP461 chip. 617 + * The TMP461 temperature offset for the remote channel. 618 + */ 619 + static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IWUSR | S_IRUGO, show_temp, 620 + store_temp, 6, 1); 621 + 622 + static struct attribute *tmp461_attributes[] = { 623 + &sensor_dev_attr_temp2_offset.dev_attr.attr, 624 + NULL 625 + }; 626 + 627 + static const struct attribute_group tmp461_group = { 628 + .attrs = tmp461_attributes, 629 + }; 630 + 631 + /* 620 632 * Begin non sysfs callback code (aka Real code) 621 633 */ 622 634 ··· 734 714 const struct i2c_device_id *id) 735 715 { 736 716 static const char * const names[] = { 737 - "TMP401", "TMP411", "TMP431", "TMP432", "TMP435" 717 + "TMP401", "TMP411", "TMP431", "TMP432", "TMP435", "TMP461" 738 718 }; 739 719 struct device *dev = &client->dev; 740 720 struct device *hwmon_dev; ··· 764 744 /* Register additional tmp432 sysfs hooks */ 765 745 if (data->kind == tmp432) 766 746 data->groups[groups++] = &tmp432_group; 747 + 748 + if (data->kind == tmp461) 749 + data->groups[groups++] = &tmp461_group; 767 750 768 751 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, 769 752 data, data->groups);
+25
include/linux/platform_data/sht3x.h
··· 1 + /* 2 + * Copyright (C) 2016 Sensirion AG, Switzerland 3 + * Author: David Frey <david.frey@sensirion.com> 4 + * Author: Pascal Sachs <pascal.sachs@sensirion.com> 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2 of the License, or 9 + * (at your option) any later version. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + * 16 + */ 17 + 18 + #ifndef __SHT3X_H_ 19 + #define __SHT3X_H_ 20 + 21 + struct sht3x_platform_data { 22 + bool blocking_io; 23 + bool high_precision; 24 + }; 25 + #endif /* __SHT3X_H_ */