Commit Graph

111 Commits

Author SHA1 Message Date
Guenter Roeck 7a1d220ccb hwmon: (lm90) Introduce function to update configuration register
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-08 18:11:31 -07:00
Guenter Roeck b849e5d18c hwmon: (lm90) Cache configuration register value
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-08 18:11:30 -07:00
Boyang Yu 62456189f3 hwmon: (lm90) Fix max6658 sporadic wrong temperature reading
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-07-08 18:11:30 -07:00
Wolfram Sang e67776cc30 hwmon: (lm90) simplify getting the adapter of a client
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-06-23 18:33:01 -07:00
Thomas Gleixner 74ba9207e1 treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 61
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-05-24 17:36:45 +02:00
Guenter Roeck 787afaa30f hwmon: (lm90) Fix build warning
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-15 17:19:53 -07:00
Guenter Roeck a4d41e6730 hwmon: (lm90) Use HWMON_CHANNEL_INFO macro
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-04-15 17:19:53 -07:00
Guenter Roeck 3334851dca hwmon: (lm90) Replace S_<PERMS> with octal values
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>
2019-02-18 14:23:29 -08:00
Javier Martinez Canillas df8d57bf8a hwmon: (lm90) Add OF device ID table
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-04-02 07:01:53 -07:00
Julia Lawall e57959a6d5 hwmon: (lm90) use permission-specific DEVICE_ATTR variants
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-02 10:19:45 -08:00
Michael Walle e9572fdd13 hwmon: (lm90) fix temp1_max_alarm attribute
Since commit commit eb1c8f4325 ("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: eb1c8f4325 ("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>
2017-01-02 10:15:28 -08:00
Guenter Roeck eb1c8f4325 hwmon: (lm90) Convert to use new hwmon registration API
Reduce driver complexity and size by converting it to
the new hwmon API.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2016-09-08 21:34:17 -07:00
Linus Torvalds 2790aed095 hwmon updates for v4.8 (take 2)
Improved error handling in  tmp102, lm75, and lm90 drivers
 Bug fixes in sht3x, ftsteutates, iio_hwmon, and adt7411 drivers
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1
 
 iQIcBAABAgAGBQJXnnZHAAoJEMsfJm/On5mBIgsQAK1o7j1ODYlvA4MONJ1MtBpq
 ojO7iELtpqeR2EIB1vHE3bNvIpwH7gdYcPAnXKeWj5OKCnliAYlYhC1RptZpyvaX
 6/GQrn93G2KHkkktbtlrs2pSzuzt8eFLrgzrvkPzNFjMEAa73hi7yO1Tt67urS0H
 t3crr0rbX4448l1taqjiB8vMKvBK6pL9Nq61oPks0FVaBewRQKnmHqyZsKd6CtcN
 Wlqy0D0ZASs0xWI1MlVVOqvBHXEAHb0UGpBlHtUeU+oTDpX7EMPbhev5vZYlBa95
 ot7PfGo+gh5f/oiFoIJ1m96+zdvujT+apAHZrquFzlBn0WhkQRMZlItoXqOkw/cn
 W+ybTgDbxvU/vmldPZk5eSej8RCK8omA0wx9d1zNWpRERUiUjwjetFZAnNltQarN
 twMor52GM1L7frLeno0gYyo3VqrCWQspmE4UDqhsLln0Z1k7aMKxW61Ev4xRKEMX
 MNaBAG83J7TPDpFKV3A/yT0nOgfmz915QQ9MFFa0RpY5ob439tC/wRsOib09AsNm
 hbCbyzNH3WnSxB7hZ1iaj9QpymmKt7G1BuKob2gA4S5VS1UtWXx9SHOYS3rmCgwV
 CGY3EpocTtjDkmx0v7aYoDmebLj117CXXFOK73tGmcK48CWjLt4RduR28Q5RyEgz
 1wSA31hiF++O+g+SvKlT
 =cv+q
 -----END PGP SIGNATURE-----

Merge tag 'hwmon-for-linus-v4.8-2' of 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-08-01 16:49:13 -04:00
Guenter Roeck c5fcf01bcf hwmon: (lm90) Improve error handling
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-31 15:02:51 -07:00
Guenter Roeck be9d6374a7 hwmon: (lm90) Add missing assignment
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: 10bfef47bd ("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-31 15:01:06 -07:00
Linus Torvalds 66304207cd Merge branch 'i2c/for-4.8' of 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-27 14:19:25 -07:00
Guenter Roeck 589f707c72 hwmon: (lm90) Drop unnecessary else statements
checkpatch rightfully complains that else after return is unnecessary.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2016-07-09 08:35:41 -07:00
Guenter Roeck 2f83ab77b4 hwmon: (lm90) Use bool for valid flag
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-09 08:35:40 -07:00
Guenter Roeck 10bfef47bd hwmon: (lm90) Read limit registers only once
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-09 08:35:40 -07:00
Guenter Roeck 37ad04d7a9 hwmon: (lm90) Simplify read functions
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-09 08:35:40 -07:00
Guenter Roeck 6e5f62b9e3 hwmon: (lm90) Use devm_hwmon_device_register_with_groups
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-09 08:35:40 -07:00
Guenter Roeck 1f17a444b4 hwmon: (lm90) Use devm_add_action for cleanup
Use devm_add_action where possible to simplify error handling and
cleanup on remove.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2016-07-09 08:35:39 -07:00
Benjamin Tissoires b4f210541f i2c: add a protocol parameter to the alert callback
.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-17 12:41:25 +02:00
Wolfram Sang 38bab98a8d hwmon: (lm90) use proper type for update_interval
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>
2016-06-07 20:13:05 -07:00
Guenter Roeck 1de8b250f6 hwmon: (lm90) Convert to use hwmon_device_register_with_groups
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-04 18:01:35 +02:00
Guenter Roeck 084489e64c hwmon: (lm90) Create all sysfs groups in one call
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-04 18:01:35 +02:00
Guenter Roeck d89fa6867d hwmon: (lm90) Always use the dev variable in the probe function
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Jean Delvare <jdelvare@suse.de>
2014-04-04 18:01:35 +02:00
Guenter Roeck 742192f546 hwmon: (lm90) Create most optional attributes with sysfs_create_group
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-04-04 18:01:34 +02:00
Jean Delvare 7c81c60f37 Update Jean Delvare's e-mail address
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2014-01-29 20:40:08 +01:00
Guenter Roeck 3d489ac07e hwmon: (lm90) Unregister hwmon device if interrupt setup fails
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: 109b1283fb
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2013-12-12 08:05:32 +01:00
Wei Ni 3e0f964f2a hwmon: (lm90) Add power control
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-15 10:40:39 +01:00
Wei Ni 1daaceb26d hwmon: (lm90) Add support for TI TMP451
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-15 10:40:39 +01:00
Wei Ni 40465d9424 hwmon: (lm90) Use enums for the indexes of temp8 and temp11
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-15 10:40:39 +01:00
Wei Ni 109b1283fb hwmon: (lm90) Add support to handle IRQ
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-15 10:40:39 +01:00
Wei Ni 072de4969f hwmon: (lm90) Define status bits
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-15 10:40:38 +01:00
Guenter Roeck e41fae2b1e hwmon: (lm90) Fix max6696 alarm handling
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-11-15 10:40:38 +01:00
Jean Delvare 78c2c2fe59 hwmon: (lm90) Drop redundant safety on cache lifetime
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-07-08 14:18:24 +02:00
Guenter Roeck 2a844c148e hwmon: Replace SENSORS_LIMIT with clamp_val
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>
2013-01-25 21:03:54 -08:00
Guenter Roeck 20f426ff02 hwmon: (lm90) Convert to use devm_ functions
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-07-21 21:48:38 -07:00
Guenter Roeck f7001bb063 hwmon: (lm90) Restore original configuration if probe function fails
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-23 10:02:18 +01:00
Guenter Roeck ae544f64cc hwmon: (lm90) Add support for GMT G781
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-23 10:02:18 +01:00
Guenter Roeck f36ffeab0a hwmon: (lm90) Fix multi-line comments
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2012-03-23 10:02:18 +01:00
Axel Lin f0967eea80 hwmon: convert drivers/hwmon/* to use module_i2c_driver()
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-03-18 18:26:50 -07:00
Guenter Roeck 6b101116ae hwmon: (lm90) Add range check to set_update_interval
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-16 22:51:47 +01:00
Frans Meulenbroeks 179c4fdb56 hwmon: replaced strict_str* with kstr*
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>
2012-01-05 08:19:34 -08:00
Jean Delvare b2589ab02b hwmon: (lm90) Make code more readable
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-04 12:00:47 +01:00
Jean Delvare 8dc089d68b hwmon: (lm90) Fix warnings
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-11-04 12:00:46 +01:00
Jean Delvare f90be42fb3 hwmon: (lm90) Refactor reading of config2 register
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>
2011-07-28 20:16:36 -07:00
Jean Delvare 6d101c588f hwmon: (lm90) Make SA56004 detection more robust
With a device ID register value of 0, the SA56004 detection is rather
weak. Check several other register too to confirm the detection, as we
do for other supported devices.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Stijn Devriendt <sdevrien@cisco.com>
Cc: Guenter Roeck <guenter.roeck@ericsson.com>
Acked-by: Stijn Devriendt <sdevrien@cisco.com>
Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
2011-07-28 20:16:36 -07:00
Jean Delvare a095f687f1 hwmon: (lm90) Simplify handling of extended local temp register
The optional extended local temperature register can never have
address 0, as this address is already used by another register. Thus
we can get rid of flag LM90_HAVE_LOCAL_EXT and simply rely on
reg_local_ext being non-zero to determine if a given chip has this
extension or not. This makes the code more simple.

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>
2011-07-28 20:16:35 -07:00