summaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/ina3221.c
Commit message (Collapse)AuthorAgeFilesLines
* hwmon: (ina3221) Convert to using %pOFn instead of device_node.nameRob Herring2018-12-161-4/+4
| | | | | | | | | | In preparation to remove the node name pointer from struct device_node, convert printf users to use the %pOFn format specifier. Cc: Jean Delvare <jdelvare@suse.com> Cc: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Rob Herring <robh@kernel.org> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
* hwmon: (ina3221) Add PM runtime supportNicolin Chen2018-12-161-19/+74
| | | | | | | | | | | | | | | | | | | | | | | | | | If all three channels are disabled via in[123]_enable ABI, the driver could suspend the chip for power saving purpose. So this patch adds the PM runtime support in order to gain more power control than system suspend and resume use case. For PM runtime, there are a few related changes happening: 1) Added a new pm_dev device pointer for all the PM runtime callbacks. This is because hwmon core registers a child device for each hwmon driver and passes it back to each driver. So there might be a mismatch between two device pointers in the driver if mixing using them. 2) Added a check in ina3221_is_enabled() to make sure that the chip is resumed. 3) Bypassed the unchanged status in ina3221_write_enable() in order to keep the PM runtime refcount being matched. 4) Removed the reset routine in the probe() by calling the resume() via pm_runtime_get_sync() instead, as they're similar. It's also necessary to do so to match initial PM refcount with the number of enabled channels. Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
* hwmon: (ina3221) Make sure data is ready before readingNicolin Chen2018-12-161-0/+42
| | | | | | | | | | | | | | | | | | | The data might need some time to get ready after channel enabling, although the data register is always readable. The CVRF bit is to indicate that data conversion is finished, so polling the CVRF bit before data reading could ensure the result being valid. An alternative way could be to wait for expected time between the channel enabling and the data reading. And this could avoid extra I2C communications. However, INA3221 seemly takes longer time than what's stated in the datasheet. Test results show that sometimes it couldn't finish data conversion in time. So this patch plays safe by adding a CVRF polling to make sure the data register is updated with the new data. Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
* hwmon: (ina3221) Serialize sysfs ABI accessesNicolin Chen2018-12-161-6/+45
| | | | | | | | | | | | | | | | This change adds a mutex to serialize accesses of sysfs attributes. This is required when polling CVRF bit of the MASK/ENABLE register because this bit is cleared on a read of this MASK/ENABLE register or a write to CONFIG register, which means that this bit might be accidentally cleared by reading other fields like alert flags. So this patch adds a mutex lock to protect the write() and read() callbacks. The read_string() callback won't need the lock since it just returns the label without touching any hardware register. Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
* hwmon: (ina3221) Check channel status for alarms attribute readNicolin Chen2018-12-161-0/+6
| | | | | | | | | | | There is nothing critically wrong to read these two attributes without having a is_enabled() check at this point. But reading the MASK_ENABLE register would clear the CVRF bit according to the datasheet. So it'd be safer to fence for disabled channels in order to add pm runtime feature. Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
* hwmon: (ina3221) Use _info API to register hwmon deviceNicolin Chen2018-10-101-283/+235
| | | | | | | | | | | | | | | The hwmon core has a newer API which abstracts most of common things in the core so as to simplify the hwmon device drivers. This patch implements this _info API to ina3221 hwmon driver. It also reduces the binary size: text data bss dec hex filename 5114 1712 0 6826 1aaa drivers/hwmon/ina3221_before.o 4456 440 0 4896 1320 drivers/hwmon/ina3221.o Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
* hwmon: (ina3221) Validate shunt resistor value from DTNicolin Chen2018-10-101-1/+7
| | | | | | | | | The input->shunt_resistor is int type while the value from DT is unsigned int. Meanwhile, a divide-by-zero error would happen if the value is 0. So this patch just simply validates the value. Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
* hwmon: (ina3221) mark PM functions as __maybe_unusedArnd Bergmann2018-10-101-4/+2
| | | | | | | | | | | | | | | | | | When CONFIG_PM_SLEEP is disabled, we get a warning about unused suspend/resume functions: drivers/hwmon/ina3221.c:451:12: error: 'ina3221_resume' defined but not used [-Werror=unused-function] static int ina3221_resume(struct device *dev) drivers/hwmon/ina3221.c:428:12: error: 'ina3221_suspend' defined but not used [-Werror=unused-function] static int ina3221_suspend(struct device *dev) Picking the correct #ifdef check is hard, so let's remove that check and instead mark the functions as __maybe_unused to let the compiler silently drop them instead. Fixes: 7de1ab9dac8e ("hwmon: (ina3221) Add suspend and resume functions") Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
* hwmon: (ina3221) Read channel input source info from DTNicolin Chen2018-10-101-14/+221
| | | | | | | | | | | | | | | | | | | | | | An ina3221 chip has three input ports. Each port is used to measure the voltage and current of its input source. The DT binding now has defined bindings for their input sources, so the driver should read these information and handle accordingly. This patch adds a new structure of input source specific information including input source label, shunt resistor value and its connection status. It exposes these labels via in[123]_label sysfs nodes upon available, and also disables those channels where there are no input source being connected. Meanwhile, it also adds in[123]_enable sysfs nodes for users to get control of three channels, and returns -ENODATA code for any sensor read according to hwmon ABI. Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
* hwmon: (ina3221) Add suspend and resume functionsNicolin Chen2018-10-101-0/+63
| | | | | | | | | | | Depending on the hardware design, an INA3221 chip might lose its power during system suspend/resume. So this patch adds a set of suspend and resume functions to cache the register values including config register value and limit settings. Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com> [groeck: Moved call to dev_set_drvdata()] Signed-off-by: Guenter Roeck <linux@roeck-us.net>
* hwmon: (ina3221) Fix INA3221_CONFIG_MODE macrosNicolin Chen2018-10-101-3/+3
| | | | | | | | | | | | The three INA3221_CONFIG_MODE macros are not correctly defined here. The MODE3-1 bits are located at BIT 2-0 according to the datasheet. So this patch just fixes them by shifting all of them with a correct offset. However, this isn't a crital bug fix as the driver does not use any of them at this point. Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
* hwmon: (ina3221) Add INA3221_CONFIG to volatile_tableNicolin Chen2018-10-101-1/+1
| | | | | | | | | | | | | | | The MSB (15th bit) of INA3221_CONFIG is a self-clear reset bit. So this register should be added to the volatile_table of the regmap_config. Otherwise, we will see this bit is sticky in the regcache which might accidentally reset the chip when an actual write happens to the register. This might not be a severe bug for the current code line since there's no second place touching the INA3221_CONFIG except the reset routine in the probe(). Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
* hwmon: (ina3221) Fix negative limitsGuenter Roeck2016-06-271-7/+6
| | | | | | | | | | | | | | The result of an integer divide by an unsigned is undefined. This causes unexpected results when writing negative values into the limit registers. Maintain the shunt_resistors variables as signed integer to avoid the problem. Also, for simplicity and ease of use, clamp shunt resistor value on writes instead of rejecting bad values. Cc: Andrew F. Davis <afd@ti.com> Acked-by: Andrew F. Davis <afd@ti.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
* hwmon: Add support for INA3221 Triple Current/Voltage MonitorsAndrew F. Davis2016-06-271-0/+446
Add support for the the INA3221 26v capable, Triple channel, Bi-Directional, Zero-Drift, Low-/High-Side, Current/Voltage Monitor with I2C interface. Signed-off-by: Andrew F. Davis <afd@ti.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
OpenPOWER on IntegriCloud