aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/ina2xx.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
2015-10-31hwmon: (ina2xx) remove no longer used variable 'kind'Marc Titinger1-4/+2
Signed-off-by: Marc Titinger <mtitinger@baylibre.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-10-28hwmon: (ina2xx) give precedence to DT over checking for platform data.Marc Titinger1-13/+12
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-28hwmon: (ina2xx) convert driver to using regmapMarc Titinger1-128/+86
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-04-17hwmon: (ina2xx) replace ina226_avg_bits() with find_closest()Bartosz Golaszewski1-14/+3
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-01-25hwmon: (ina2xx) Add ina231 compatible stringKevin Hilman1-0/+1
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-25hwmon: (ina2xx) use DIV_ROUND_CLOSEST() to avoid rounding errorsBartosz Golaszewski1-3/+7
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-25hwmon: (ina2xx) remove an unnecessary dev_get_drvdata() result checkBartosz Golaszewski1-3/+0
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-01-25hwmon: (ina2xx) implement update_interval attribute for ina226Bartosz Golaszewski1-6/+158
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-25hwmon: (ina2xx) make shunt resistance configurable at run-timeBartosz Golaszewski1-2/+46
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-25hwmon: (ina2xx) don't accept shunt values greater than the calibration factorBartosz Golaszewski1-1/+2
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-25hwmon: (ina2xx) remove a stray new lineBartosz Golaszewski1-1/+0
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-01-25hwmon: (ina2xx) reinitialize the chip in case it's been resetBartosz Golaszewski1-37/+91
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>
2014-11-30hwmon: (ina2xx) bail-out from ina2xx_probe() in case of configuration errorsBartosz Golaszewski1-6/+20
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-06-12hwmon: (ina2xx) Cast to s16 on shunt and current regsFabio Baltieri1-3/+4
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>
2013-10-13hwmon: (ina2xx) Convert to use devm_hwmon_device_register_with_groupsGuenter Roeck1-43/+21
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-09-10hwmon: (ina2xx) Remove casting the return value which is a void pointerJingoo Han1-2/+1
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-08-11hwmon: use dev_get_platdata()Jingoo Han1-2/+2
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-06-27hwmon: (ina2xx) Add device tree support to pass the shunt resistorTang Yuantian1-0/+5
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-04-07hwmon: (ina2xx) Fix 'Avoid unnecessary line continuations' checkpatch warningGuenter Roeck1-8/+8
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2012-12-05hwmon: (ina2xx) use module_i2c_driver to simplify the codeWei Yongjun1-12/+1
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-10-10hwmon: Add missing inclusions of <linux/jiffies.h>Jean Delvare1-0/+1
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-09-23hwmon: (ina2xx) Add support for INA220 and INA230Guenter Roeck1-0/+10
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-23hwmon: (ina2xx) Use structure array to distinguish chip typesGuenter Roeck1-103/+56
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-12hwmon: (ina2xx) Fix word size register read and write operationsGuenter Roeck1-21/+9
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-05-22hwmon: INA219 and INA226 supportFelten, Lothar1-0/+368
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>