summaryrefslogtreecommitdiff
path: root/drivers/hwmon/lm90.c
AgeCommit message (Collapse)Author
2020-09-23hwmon: use simple i2c probe functionStephen Kitt
Many hwmon drivers don't use the id information provided by the old i2c probe function, and the remainder can easily be adapted to the new form ("probe_new") by calling i2c_match_id explicitly. This avoids scanning the identifier tables during probes. Drivers which didn't use the id are converted as-is; drivers which did are modified as follows: * if the information in i2c_client is sufficient, that's used instead (client->name); * anything else is handled by calling i2c_match_id() with the same level of error-handling (if any) as before. A few drivers aren't included in this patch because they have a different set of maintainers. They will be covered by other patches. Signed-off-by: Stephen Kitt <steve@sk2.org> Link: https://lore.kernel.org/r/20200813160222.1503401-1-steve@sk2.org Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2020-05-22hwmon: (lm90) Add max6654 support to lm90 driverJosh Lehan
Add support for the Maxim MAX6654 to the lm90 driver. The MAX6654 is a temperature sensor, similar to the others, but with some differences regarding the configuration register, and the sampling rate at which extended resolution becomes possible. Signed-off-by: Josh Lehan <krellan@google.com> Link: https://lore.kernel.org/r/20200513184248.145765-1-krellan@google.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2019-07-08hwmon: (lm90) Introduce function to update configuration registerGuenter Roeck
The code to update the configuration register is repeated several times. Move it into a separate function. At the same time, un-inline lm90_select_remote_channel() and leave it up to the compiler to decide what to do with it. Also remove the 'client' argument from lm90_select_remote_channel() and from lm90_write_convrate() and take it from struct lm90_data instead where needed. This patch reduces code size by more than 800 bytes on x86_64. Cc: Boyang Yu <byu@arista.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2019-07-08hwmon: (lm90) Cache configuration register valueGuenter Roeck
The configuration register does not change on its own. Yet, it is read in various locations, modified, and written back. Simplify and optimize the code by caching its value and by only writing it back when needed. Cc: Boyang Yu <byu@arista.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2019-07-08hwmon: (lm90) Fix max6658 sporadic wrong temperature readingBoyang Yu
max6658 may report unrealistically high temperature during the driver initialization, for which, its overtemp alarm pin also gets asserted. For certain devices implementing overtemp protection based on that pin, it may further trigger a reset to the device. By reproducing the problem, the wrong reading is found to be coincident with changing the conversion rate. To mitigate this issue, set the stop bit before changing the conversion rate and unset it thereafter. After such change, the wrong reading is not reproduced. Apply this change only to the max6657 kind for now, controlled by flag LM90_PAUSE_ON_CONFIG. Signed-off-by: Boyang Yu <byu@arista.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2019-06-23hwmon: (lm90) simplify getting the adapter of a clientWolfram Sang
We have a dedicated pointer for that, so use it. Much easier to read and less computation involved. Reported-by: Peter Rosin <peda@axentia.se> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2019-05-24treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 61Thomas Gleixner
Based on 1 normalized pattern(s): this program is free software you can redistribute it and or modify it under the terms of the gnu general public license as published by the free software foundation either version 2 of the license or at your option any later version this program is distributed in the hope that it will be useful but without any warranty without even the implied warranty of merchantability or fitness for a particular purpose see the gnu general public license for more details you should have received a copy of the gnu general public license along with this program if not write to the free software foundation inc 675 mass ave cambridge ma 02139 usa extracted by the scancode license scanner the SPDX license identifier GPL-2.0-or-later has been chosen to replace the boilerplate/reference in 441 file(s). Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc) Reviewed-by: Richard Fontana <rfontana@redhat.com> Reviewed-by: Allison Randal <allison@lohutok.net> Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org> Cc: linux-spdx@vger.kernel.org Link: https://lkml.kernel.org/r/20190520071858.739733335@linutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-04-15hwmon: (lm90) Fix build warningGuenter Roeck
If CONFIG_OF is not enabled, the following build warning is observed. drivers/hwmon/lm90.c:239:34: warning: ‘lm90_of_match’ defined but not used Mark lm90_of_match as __maybe_unused to fix the problem. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2019-04-15hwmon: (lm90) Use HWMON_CHANNEL_INFO macroGuenter Roeck
The HWMON_CHANNEL_INFO macro simplifies the code, reduces the likelihood of errors, and makes the code easier to read. The conversion was done automatically with coccinelle. The semantic patch used to make this change is as follows. @r@ initializer list elements; identifier i; @@ -u32 i[] = { - elements, - 0 -}; @s@ identifier r.i,j,ty; @@ -struct hwmon_channel_info j = { - .type = ty, - .config = i, -}; @script:ocaml t@ ty << s.ty; elements << r.elements; shorter; elems; @@ shorter := make_ident (List.hd(List.rev (Str.split (Str.regexp "_") ty))); elems := make_ident (String.concat "," (List.map (fun x -> Printf.sprintf "\n\t\t\t %s" x) (Str.split (Str.regexp " , ") elements))) @@ identifier s.j,t.shorter; identifier t.elems; @@ - &j + HWMON_CHANNEL_INFO(shorter,elems) This patch does not introduce functional changes. Many thanks to Julia Lawall for providing the semantic patch. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2019-02-18hwmon: (lm90) Replace S_<PERMS> with octal valuesGuenter Roeck
Replace S_<PERMS> with octal values. The conversion was done automatically with coccinelle. The semantic patches and the scripts used to generate this commit log are available at https://github.com/groeck/coccinelle-patches/hwmon/. This patch does not introduce functional changes. It was verified by compiling the old and new files and comparing text and data sizes. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2017-04-02hwmon: (lm90) Add OF device ID tableJavier Martinez Canillas
The driver doesn't have a struct of_device_id table but supported devices are registered via Device Trees. This is working on the assumption that a I2C device registered via OF will always match a legacy I2C device ID and that the MODALIAS reported will always be of the form i2c:<device>. But this could change in the future so the correct approach is to have an OF device ID table if the devices are registered via OF. Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2017-01-02hwmon: (lm90) use permission-specific DEVICE_ATTR variantsJulia Lawall
Use DEVICE_ATTR_RW for read/write attributes. This simplifies the source code, improves readbility, and reduces the chance of inconsistencies. The conversion was done automatically using coccinelle. It was validated by compiling both the old and the new source code and comparing its text, data, and bss size. Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr> [groeck: Updated description] Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2017-01-02hwmon: (lm90) fix temp1_max_alarm attributeMichael Walle
Since commit commit eb1c8f4325d5 ("hwmon: (lm90) Convert to use new hwmon registration API") the temp1_max_alarm and temp1_crit_alarm attributes are mapped to the same alarm bit. Fix the typo. Fixes: eb1c8f4325d5 ("hwmon: (lm90) Convert to use new hwmon registration API") Signed-off-by: Micehael Walle <michael@walle.cc> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2016-09-08hwmon: (lm90) Convert to use new hwmon registration APIGuenter Roeck
Reduce driver complexity and size by converting it to the new hwmon API. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2016-08-01Merge tag 'hwmon-for-linus-v4.8-2' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging Pull more hwmon updates from Guenter Roeck: - Improved error handling in tmp102, lm75, and lm90 drivers - Bug fixes in sht3x, ftsteutates, iio_hwmon, and adt7411 drivers * tag 'hwmon-for-linus-v4.8-2' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: hwmon: (adt7411) set sane values for CFG1 and CFG3 hwmon: (iio_hwmon) fix memory leak in name attribute hwmon: (ftsteutates) Fix potential memory access error hwmon: (tmp102) Improve error handling hwmon: (lm75) Improve error handling hwmon: (lm90) Improve error handling hwmon: (lm90) Add missing assignment hwmon: (sht3x) set initial jiffies to last_update
2016-07-31hwmon: (lm90) Improve error handlingGuenter Roeck
Replace devm_add_action() with devm_add_action_or_reset(), and check its return value. Reviewed-by: Jean Delvare <jdelvare@suse.de> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2016-07-31hwmon: (lm90) Add missing assignmentGuenter Roeck
Coverity reports the following error. >>> CID 1364474: Error handling issues (CHECKED_RETURN) >>> Calling "lm90_read_reg" without checking return value (as is done >>> elsewhere 28 out of 29 times). 532 lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH); 533 if (val < 0) 534 return val; Fixes: 10bfef47bd259 ("hwmon: (lm90) Read limit registers only once") Reviewed-by: Jean Delvare <jdelvare@suse.de> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2016-07-27Merge branch 'i2c/for-4.8' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux Pull i2c updates from Wolfram Sang: "Here is the I2C pull request for 4.8: - the core and i801 driver gained support for SMBus Host Notify - core support for more than one address in DT - i2c_add_adapter() has now better error messages. We can remove all error messages from drivers calling it as a next step. - bigger updates to rk3x driver to support rk3399 SoC - the at24 eeprom driver got refactored and can now read special variants with unique serials or fixed MAC addresses. The rest is regular driver updates and bugfixes" * 'i2c/for-4.8' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (66 commits) i2c: i801: use IS_ENABLED() instead of checking for built-in or module Documentation: i2c: slave: give proper example for pm usage Documentation: i2c: slave: describe buffer problems a bit better i2c: bcm2835: Don't complain on -EPROBE_DEFER from getting our clock i2c: i2c-smbus: drop useless stubs i2c: efm32: fix a failure path in efm32_i2c_probe() Revert "i2c: core: Cleanup I2C ACPI namespace" Revert "i2c: core: Add function for finding the bus speed from ACPI" i2c: Update the description of I2C_SMBUS i2c: i2c-smbus: fix i2c_handle_smbus_host_notify documentation eeprom: at24: tweak the loop_until_timeout() macro eeprom: at24: add support for at24mac series eeprom: at24: support reading the serial number for 24csxx eeprom: at24: platform_data: use BIT() macro eeprom: at24: split at24_eeprom_write() into specialized functions eeprom: at24: split at24_eeprom_read() into specialized functions eeprom: at24: hide the read/write loop behind a macro eeprom: at24: call read/write functions via function pointers eeprom: at24: coding style fixes eeprom: at24: move at24_read() below at24_eeprom_write() ...
2016-07-09hwmon: (lm90) Drop unnecessary else statementsGuenter Roeck
checkpatch rightfully complains that else after return is unnecessary. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2016-07-09hwmon: (lm90) Use bool for valid flagGuenter Roeck
Use bool for valid flag and leave it up to the compiler to find an optimal representation. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2016-07-09hwmon: (lm90) Read limit registers only onceGuenter Roeck
Read limit registers only once at startup or after errors to improve driver performance. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2016-07-09hwmon: (lm90) Simplify read functionsGuenter Roeck
Return both error code and register value as return code from read functions, and always check for errors. This reduces code size on x86_64 by more than 1k while at the same time improving error resiliency. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2016-07-09hwmon: (lm90) Use devm_hwmon_device_register_with_groupsGuenter Roeck
Since all other cleanup handled with devm_add_action, we can use devm_hwmon_device_register_with_groups() to register the hwmon device, and drop the remove function. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2016-07-09hwmon: (lm90) Use devm_add_action for cleanupGuenter Roeck
Use devm_add_action where possible to simplify error handling and cleanup on remove. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2016-06-17i2c: add a protocol parameter to the alert callbackBenjamin Tissoires
.alert() is meant to be generic, but there is currently no way for the device driver to know which protocol generated the alert. Add a parameter in .alert() to help the device driver to understand what is given in data. This patch is required to have the support of SMBus Host Notify protocol through .alert(). Tested-by: Andrew Duggan <aduggan@synaptics.com> For hwmon: Acked-by: Guenter Roeck <linux@roeck-us.net> For IPMI: Acked-by: Corey Minyard <cminyard@mvista.com> Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
2016-06-07hwmon: (lm90) use proper type for update_intervalWolfram Sang
The code handles this variable always as unsigned, so adapt the type. Signed-off-by: Wolfram Sang <wsa@the-dreams.de> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2014-04-04hwmon: (lm90) Convert to use hwmon_device_register_with_groupsGuenter Roeck
Simplify code, reduce code size, and attach hwmon attributes to hwmon device. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Jean Delvare <jdelvare@suse.de>
2014-04-04hwmon: (lm90) Create all sysfs groups in one callGuenter Roeck
Create all sysfs groups in one call by using sysfs_create_groups instead of calling sysfs_create_group individually for each group. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Jean Delvare <jdelvare@suse.de>
2014-04-04hwmon: (lm90) Always use the dev variable in the probe functionGuenter Roeck
Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Jean Delvare <jdelvare@suse.de>
2014-04-04hwmon: (lm90) Create most optional attributes with sysfs_create_groupGuenter Roeck
With the new hwmon API, all attributes have to be created as groups. Use sysfs_create_group and sysfs_remove_group instead of device_create_file and device_remove_file to prepare for the new API. Exception is the 'pec' attribute which will stay with the i2c device. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Jean Delvare <jdelvare@suse.de>
2014-01-29Update Jean Delvare's e-mail addressJean Delvare
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2013-12-12hwmon: (lm90) Unregister hwmon device if interrupt setup failsGuenter Roeck
Commit 109b1283fb (hwmon: (lm90) Add support to handle IRQ) introduced interrupt support. Its error handling code fails to unregister the already registered hwmon device. Fixes: 109b1283fb532ac773a076748ffccf76a7067cab Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2013-11-15hwmon: (lm90) Add power controlWei Ni
The device lm90 can be controlled by the vcc rail. Adding the regulator support to power on/off the vcc rail. Enable the "vcc" regulator before accessing the device. [JD: Rename variables to avoid confusion with registers.] Signed-off-by: Wei Ni <wni@nvidia.com> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2013-11-15hwmon: (lm90) Add support for TI TMP451Wei Ni
TI TMP451 is mostly compatible with ADT7461, except for local temperature low byte and max conversion rate. Add support to the LM90 driver. Signed-off-by: Wei Ni <wni@nvidia.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2013-11-15hwmon: (lm90) Use enums for the indexes of temp8 and temp11Wei Ni
Using enums for the indexes and nrs of temp8 and temp11. This make the code much more readable. Signed-off-by: Wei Ni <wni@nvidia.com> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2013-11-15hwmon: (lm90) Add support to handle IRQWei Ni
When the temperature exceed the limit range value, the driver can handle the interrupt. Signed-off-by: Wei Ni <wni@nvidia.com> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2013-11-15hwmon: (lm90) Define status bitsWei Ni
Add bit defines for the status register. And add a function lm90_is_tripped() which will read status register and return tripped or not, then lm90_alert can call it directly, and in the future the IRQ thread also can use it. [JD: Adjusted to include all the new MAX6696 status flags.] Signed-off-by: Wei Ni <wni@nvidia.com> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2013-11-15hwmon: (lm90) Fix max6696 alarm handlingGuenter Roeck
Bit 2 of status register 2 on MAX6696 (external diode 2 open) sets ALERT; the bit thus has to be listed in alert_alarms. Also display a message in the alert handler if the condition is encountered. Even though not all overtemperature conditions cause ALERT to be set, we should not ignore them in the alert handler. Display messages for all out-of-range conditions. Reported-by: Jean Delvare <khali@linux-fr.org> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Cc: stable@vger.kernel.org Signed-off-by: Jean Delvare <khali@linux-fr.org>
2013-07-08hwmon: (lm90) Drop redundant safety on cache lifetimeJean Delvare
time_after (as opposed to time_after_equal) already ensures that the cache lifetime is at least as much as requested. There is no point in manually adding another jiffy to that value, and this can confuse the reader into wrong interpretation. Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: Imre Deak <imre.deak@intel.com>
2013-01-25hwmon: Replace SENSORS_LIMIT with clamp_valGuenter Roeck
SENSORS_LIMIT and the generic clamp_val have the same functionality, and clamp_val is more efficient. This patch reduces text size by 9052 bytes and bss size by 11624 bytes for x86_64 builds. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Acked-by: George Joseph <george.joseph@fairview5.com> Acked-by: Jean Delvare <khali@linux-fr.org>
2012-07-21hwmon: (lm90) Convert to use devm_ functionsGuenter Roeck
Convert to use devm_ functions to reduce code size and simplify the code. Cc: Jean Delvare <khali@linux-fr.org> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Acked-by: Jean Delvare <khali@linux-fr.org>
2012-03-23hwmon: (lm90) Restore original configuration if probe function failsGuenter Roeck
The lm90 driver restores the original chip configuration in its exit function. However, the chip configuration is not restored if the probe function fails. Restore it there as well. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2012-03-23hwmon: (lm90) Add support for GMT G781Guenter Roeck
GMT G781 is a ADM1032-compatible temperature sensor chip. Add support to the LM90 driver. Cc: Mike Gorchak <lestat@i.com.ua> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2012-03-23hwmon: (lm90) Fix multi-line commentsGuenter Roeck
Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2012-03-18hwmon: convert drivers/hwmon/* to use module_i2c_driver()Axel Lin
This patch converts the drivers in drivers/hwmon/* to use the module_i2c_driver() macro which makes the code smaller and a bit simpler. Signed-off-by: Axel Lin <axel.lin@gmail.com> Cc: Corentin Labbe <corentin.labbe@geomatys.fr> Cc: Dirk Eibach <eibach@gdsys.de> Cc: "Mark M. Hoffman" <mhoffman@lightlink.com> Cc: Steve Glendinning <steve.glendinning@smsc.com> Cc: Riku Voipio <riku.voipio@iki.fi> Cc: Guillaume Ligneul <guillaume.ligneul@gmail.com> Cc: David George <david.george@ska.ac.za> Cc: "Hans J. Koch" <hjk@hansjkoch.de> Cc: Marc Hulsman <m.hulsman@tudelft.nl> Cc: Rudolf Marek <r.marek@assembler.cz> Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
2012-01-16hwmon: (lm90) Add range check to set_update_intervalGuenter Roeck
When writing the update_interval attribute, the parameter value was not range checked, which could cause an integer overflow and result in an arbitrary update interval. Fix by limiting the value range to <0, 100000>. Reported-by: Jean Delvare <khali@linux-fr.org> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>
2012-01-05hwmon: replaced strict_str* with kstr*Frans Meulenbroeks
replaced strict_strtol with kstrtol and replaced strict_strtuol with kstrtuol This satisfies checkpatch -f Compile tested only: no warnings or errors given Signed-off-by: Frans Meulenbroeks <fransmeulenbroeks@gmail.com> Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
2011-11-04hwmon: (lm90) Make code more readableJean Delvare
Clean up the code to make it more readable: * Remove reg_ and new_ prefixes from variable names, they made the names longer, causing extra line breaks, while not adding much value. * Introduce struct device dev* = &client->dev in two functions, to avoid repeating client->dev everywhere in these functions. Signed-off-by: Jean Delvare <khali@linux-fr.org> Acked-by: Guenter Roeck <guenter.roeck@ericsson.com>
2011-11-04hwmon: (lm90) Fix warningsJean Delvare
With some configuration option combinations, we get the following warnings: drivers/hwmon/lm90.c: In function 'lm90_detect': drivers/hwmon/lm90.c:1114: warning: 'chip_id' may be used uninitialized in this function drivers/hwmon/lm90.c:1114: warning: 'reg_config1' may be used uninitialized in this function drivers/hwmon/lm90.c:1114: warning: 'reg_convrate' may be used uninitialized in this function drivers/hwmon/lm90.c:1187: warning: 'reg_emerg2' may be used uninitialized in this function drivers/hwmon/lm90.c:1187: warning: 'reg_status2' may be used uninitialized in this function We can solve these easily by reading the register values first and checking for errors later. These errors should be very rare, even in the case of failed detection, so this change has no impact on performance. And this makes checkpatch.pl happier. Reported-by: Guenter Roeck <guenter.roeck@ericsson.com> Signed-off-by: Jean Delvare <khali@linux-fr.org> Acked-by: Guenter Roeck <guenter.roeck@ericsson.com>
2011-07-28hwmon: (lm90) Refactor reading of config2 registerJean Delvare
Several vendors implement a second configuration register, which we check during device detection. Refactor the code to avoid duplication. Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: Stijn Devriendt <sdevrien@cisco.com> Cc: Guenter Roeck <guenter.roeck@ericsson.com> Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>