Commit Graph

25 Commits

Author SHA1 Message Date
Marc Titinger 5aa4e83dd5 hwmon: (ina2xx) remove no longer used variable 'kind'
Signed-off-by: Marc Titinger <mtitinger@baylibre.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-10-31 08:46:01 -07:00
Marc Titinger 001e2e730c hwmon: (ina2xx) give precedence to DT over checking for platform data.
when checking for the value of the shunt resistor.

Signed-off-by: Marc Titinger <mtitinger@baylibre.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-10-28 21:53:15 -07:00
Marc Titinger a0de56c81f hwmon: (ina2xx) convert driver to using regmap
Any sysfs "show" read access from the client app will result in reading
all registers (8 with ina226). Depending on the host this can limit the
best achievable read rate.

This changeset allows for individual register accesses through regmap.

Tested with BeagleBone Black (Baylibre-ACME) and ina226.

Signed-off-by: Marc Titinger <mtitinger@baylibre.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-10-28 21:53:00 -07:00
Bartosz Golaszewski d38df34e3f hwmon: (ina2xx) replace ina226_avg_bits() with find_closest()
Use find_closest() to locate the closest average in ina226_avg_tab.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-04-17 09:03:54 -04:00
Kevin Hilman add513be1c hwmon: (ina2xx) Add ina231 compatible string
Add support for "ina231" as compatible string, and update
Documentation and Kconfig accordingly.

Tested with the Exynos5422-based odroid-xu3 board which has on-board
INA231 sensors.

Signed-off-by: Kevin Hilman <khilman@linaro.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-01-25 21:23:59 -08:00
Bartosz Golaszewski b721fe2a3a hwmon: (ina2xx) use DIV_ROUND_CLOSEST() to avoid rounding errors
Use DIV_ROUND_CLOSEST() when dealing with the calibration values to make the
calculations less error prone.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-01-25 21:23:59 -08:00
Bartosz Golaszewski 71eb7c4c7e hwmon: (ina2xx) remove an unnecessary dev_get_drvdata() result check
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-01-25 21:23:59 -08:00
Bartosz Golaszewski 72a87a47a8 hwmon: (ina2xx) implement update_interval attribute for ina226
This attribute allows to configure the update interval of ina226. Although
the bus and shunt voltage conversion times remain hardcoded to 1.1 ms, we can
now modify said interval by changing the averaging rate.

While we're at it - add an additional variable to ina2xx_data, which holds
the current configuration settings - this way we'll be able to restore the
configuration in case of an unexpected chip reset.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-01-25 21:23:59 -08:00
Bartosz Golaszewski 8a5fc79513 hwmon: (ina2xx) make shunt resistance configurable at run-time
The shunt resistance can only be set via platform_data or device tree. This
isn't suitable for devices in which the shunt resistance can change/isn't
known at boot-time.

Add a sysfs attribute that allows to read and set the shunt resistance.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-01-25 21:23:59 -08:00
Bartosz Golaszewski e794704000 hwmon: (ina2xx) don't accept shunt values greater than the calibration factor
Shunt resistance values greater than the chip's calibration factor make no
sense since the actual value written to the register equals:

	<calibration factor> / <shunt>

Bail-out from ina2xx_probe() if the configured value is greater than the
calibration factor.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-01-25 21:23:59 -08:00
Bartosz Golaszewski f4fe902717 hwmon: (ina2xx) remove a stray new line
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-01-25 21:23:59 -08:00
Bartosz Golaszewski 509416a8e7 hwmon: (ina2xx) reinitialize the chip in case it's been reset
Chips from the ina family don't like to be uninitialized. In case the power
is cut-off and restored again the calibration register will be reset
to 0 and both the power and current registers will remain at 0.

Check the calibration register in ina2xx_update_device() and reinitialize
the chip if needed.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-01-25 21:23:58 -08:00
Bartosz Golaszewski f975b3399c hwmon: (ina2xx) bail-out from ina2xx_probe() in case of configuration errors
The return value of i2c_smbus_write_word_swapped() isn't checked in
ina2xx_probe(). This leads to devices being registered even if they cannot
be physically detected (e.g. device is not powered-up at boot-time).

Even after restoring power to such device, it is left unconfigured as the
configuration has never been actually written to the register.

Error out in case of write errors in probe and notify the user.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
[Guenter Roeck: Fixed multi-line comment style]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2014-11-30 20:13:14 -08:00
Fabio Baltieri c0214f9894 hwmon: (ina2xx) Cast to s16 on shunt and current regs
All devices supported by ina2xx are bidirectional and report the
measured shunt voltage and power values as a signed 16 bit, but the
current driver implementation caches all registers as u16, leading
to an incorrect sign extension when reporting to userspace in
ina2xx_get_value().

This patch fixes the problem by casting the signed registers to s16.
Tested on an INA219.

Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
Cc: stable@vger.kernel.org # 3.10+
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2014-06-12 08:36:18 -07:00
Guenter Roeck 468bf0e395 hwmon: (ina2xx) Convert to use devm_hwmon_device_register_with_groups
Also introduce dev variable in probe function to simplify access
to client->dev, and use new macro ATTRIBUTE_GROUPS to declare
attribute groups.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2013-10-13 16:16:29 -07:00
Jingoo Han 8876dd78d9 hwmon: (ina2xx) Remove casting the return value which is a void pointer
Casting the return value which is a void pointer is redundant.
The conversion from void pointer to any other pointer type is
guaranteed by the C programming language.

Signed-off-by: Jingoo Han <jg1.han@samsung.com>
Acked-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2013-09-10 06:28:31 -07:00
Jingoo Han a8b3a3a53f hwmon: use dev_get_platdata()
Use the wrapper function for retrieving the platform data instead of
accessing dev->platform_data directly.

Signed-off-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2013-08-11 22:10:39 -07:00
Tang Yuantian 31e7ad74f6 hwmon: (ina2xx) Add device tree support to pass the shunt resistor
Adding another way that is device tree to pass the shunt resistor
value to driver except for platform data.

Signed-off-by: Tang Yuantian <Yuantian.Tang@freescale.com>
[Guenter Roeck: Added missing of.h include]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2013-06-27 10:31:42 -07:00
Guenter Roeck f0df0fd92d hwmon: (ina2xx) Fix 'Avoid unnecessary line continuations' checkpatch warning
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2013-04-07 21:16:40 -07:00
Wei Yongjun d835ca0fd2 hwmon: (ina2xx) use module_i2c_driver to simplify the code
Use the module_i2c_driver() macro to make the code smaller
and a bit simpler.

dpatch engine is used to auto generate this patch.
(https://github.com/weiyj/dpatch)

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2012-12-05 10:55:54 -08:00
Jean Delvare dcd8f39230 hwmon: Add missing inclusions of <linux/jiffies.h>
Many hwmon drivers use jiffies but omit the inclusion of the header
file. Fix that, and also fix one driver which was including the header
file but didn't need it.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Luca Tettamanti <kronos.it@gmail.com>
Cc: Marc Hulsman <m.hulsman@tudelft.nl>
Cc: Rudolf Marek <r.marek@assembler.cz>
2012-10-10 15:25:56 +02:00
Guenter Roeck dc92cd0c13 hwmon: (ina2xx) Add support for INA220 and INA230
INA220 is register compatible to INA219, and INA230 is register compatible to
INA226, so all we need to do is to add name aliases for those two chips.

Cc: Lothar Felten <l-felten@ti.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Jean Delvare <khali@linux-fr.org>
2012-09-23 21:08:35 -07:00
Guenter Roeck 6106db25c2 hwmon: (ina2xx) Use structure array to distinguish chip types
Replace per-device initialization and per-device calculation code with
per-device configuration data, which is then used to configure the chip and
perform calculations based on that data.

This patch reduces code size by more than 400 bytes on x86_64.

Cc: Lothar Felten <l-felten@ti.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Jean Delvare <khali@linux-fr.org>
2012-09-23 21:08:34 -07:00
Guenter Roeck 080b98e9ab hwmon: (ina2xx) Fix word size register read and write operations
The driver uses be16_to_cpu and cpu_to_be16 to convert data in SMBus word
operations from chip to host byte order. However, the data passed from and to
the SMBus word API functions is in host byte order, not in chip byte order.
Conversion should therefore use swab16 instead of be16 to change the byte order.

Replace driver internal word conversion functions with SMBus API functions to
solve the problem.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Cc: stable@vger.kernel.org # 3.5+
Acked-by: Jean Delvare <khali@linux-fr.org>
2012-09-12 06:42:11 -07:00
Felten, Lothar f7c2fe386a hwmon: INA219 and INA226 support
Add support for the Texas Instruments INA219 and INA226 power monitors.

Signed-off-by: Lothar Felten <l-felten@ti.com>
[guenter.roeck@ericsson.com: formatting cleanup; check for smbus word data;
 select PGA=8 for INA219]
Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
2012-05-22 06:48:02 -07:00