summaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/ina2xx.c
Commit message (Collapse)AuthorAgeFilesLines
* hwmon: (ina2xx) Add OF device ID tableJavier Martinez Canillas2017-04-021-1/+34
| | | | | | | | | | | | | 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>
* hwmon: (ina2xx) remove no longer used variable 'kind'Marc Titinger2015-10-311-4/+2
| | | | | Signed-off-by: Marc Titinger <mtitinger@baylibre.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
* hwmon: (ina2xx) give precedence to DT over checking for platform data.Marc Titinger2015-10-281-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>
* hwmon: (ina2xx) convert driver to using regmapMarc Titinger2015-10-281-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>
* hwmon: (ina2xx) replace ina226_avg_bits() with find_closest()Bartosz Golaszewski2015-04-171-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>
* hwmon: (ina2xx) Add ina231 compatible stringKevin Hilman2015-01-251-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>
* hwmon: (ina2xx) use DIV_ROUND_CLOSEST() to avoid rounding errorsBartosz Golaszewski2015-01-251-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>
* hwmon: (ina2xx) remove an unnecessary dev_get_drvdata() result checkBartosz Golaszewski2015-01-251-3/+0
| | | | | Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
* hwmon: (ina2xx) implement update_interval attribute for ina226Bartosz Golaszewski2015-01-251-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>
* hwmon: (ina2xx) make shunt resistance configurable at run-timeBartosz Golaszewski2015-01-251-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>
* hwmon: (ina2xx) don't accept shunt values greater than the calibration factorBartosz Golaszewski2015-01-251-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>
* hwmon: (ina2xx) remove a stray new lineBartosz Golaszewski2015-01-251-1/+0
| | | | | Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
* hwmon: (ina2xx) reinitialize the chip in case it's been resetBartosz Golaszewski2015-01-251-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>
* hwmon: (ina2xx) bail-out from ina2xx_probe() in case of configuration errorsBartosz Golaszewski2014-11-301-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>
* hwmon: (ina2xx) Cast to s16 on shunt and current regsFabio Baltieri2014-06-121-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>
* hwmon: (ina2xx) Convert to use devm_hwmon_device_register_with_groupsGuenter Roeck2013-10-131-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>
* hwmon: (ina2xx) Remove casting the return value which is a void pointerJingoo Han2013-09-101-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>
* hwmon: use dev_get_platdata()Jingoo Han2013-08-111-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>
* hwmon: (ina2xx) Add device tree support to pass the shunt resistorTang Yuantian2013-06-271-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>
* hwmon: (ina2xx) Fix 'Avoid unnecessary line continuations' checkpatch warningGuenter Roeck2013-04-071-8/+8
| | | | Signed-off-by: Guenter Roeck <linux@roeck-us.net>
* hwmon: (ina2xx) use module_i2c_driver to simplify the codeWei Yongjun2012-12-051-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>
* hwmon: Add missing inclusions of <linux/jiffies.h>Jean Delvare2012-10-101-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>
* hwmon: (ina2xx) Add support for INA220 and INA230Guenter Roeck2012-09-231-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>
* hwmon: (ina2xx) Use structure array to distinguish chip typesGuenter Roeck2012-09-231-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>
* hwmon: (ina2xx) Fix word size register read and write operationsGuenter Roeck2012-09-121-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>
* hwmon: INA219 and INA226 supportFelten, Lothar2012-05-221-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>
OpenPOWER on IntegriCloud