Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (ina2xx) Add device tree support to pass alert polarity

The INA230 has an Alert pin which is asserted when the alert
function selected in the Mask/Enable register exceeds the
value programmed into the Alert Limit register. Assertion is based
on the Alert Polarity Bit (APOL, bit 1 of the Mask/Enable register).
It is default set to value 0 i.e Normal (active-low open collector).
However, hardware can be designed in such a way that expects Alert pin
to become active high if a user-defined threshold in Alert limit
register has been exceeded. This patch adds a way to pass alert polarity
value to the driver via device tree.

Signed-off-by: Amna Waseem <Amna.Waseem@axis.com>
Link: https://lore.kernel.org/r/20240611-apol-ina2xx-fix-v4-2-8df1d2282fc5@axis.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Amna Waseem and committed by
Guenter Roeck
ec5d234f 94e33109

+32
+32
drivers/hwmon/ina2xx.c
··· 73 73 #define INA226_READ_AVG(reg) (((reg) & INA226_AVG_RD_MASK) >> 9) 74 74 #define INA226_SHIFT_AVG(val) ((val) << 9) 75 75 76 + #define INA226_ALERT_POLARITY_MASK 0x0002 77 + #define INA226_SHIFT_ALERT_POLARITY(val) ((val) << 1) 78 + #define INA226_ALERT_POL_LOW 0 79 + #define INA226_ALERT_POL_HIGH 1 80 + 76 81 /* bit number of alert functions in Mask/Enable Register */ 77 82 #define INA226_SHUNT_OVER_VOLTAGE_BIT 15 78 83 #define INA226_SHUNT_UNDER_VOLTAGE_BIT 14 ··· 181 176 ARRAY_SIZE(ina226_avg_tab)); 182 177 183 178 return INA226_SHIFT_AVG(avg_bits); 179 + } 180 + 181 + static int ina2xx_set_alert_polarity(struct ina2xx_data *data, 182 + unsigned long val) 183 + { 184 + return regmap_update_bits(data->regmap, INA226_MASK_ENABLE, 185 + INA226_ALERT_POLARITY_MASK, 186 + INA226_SHIFT_ALERT_POLARITY(val)); 184 187 } 185 188 186 189 /* ··· 666 653 ret = devm_regulator_get_enable(dev, "vs"); 667 654 if (ret) 668 655 return dev_err_probe(dev, ret, "failed to enable vs regulator\n"); 656 + 657 + if (chip == ina226) { 658 + if (of_property_read_bool(dev->of_node, "ti,alert-polarity-active-high")) { 659 + ret = ina2xx_set_alert_polarity(data, 660 + INA226_ALERT_POL_HIGH); 661 + if (ret < 0) { 662 + return dev_err_probe(dev, ret, 663 + "failed to set alert polarity active high\n"); 664 + } 665 + } else { 666 + /* Set default value i.e active low */ 667 + ret = ina2xx_set_alert_polarity(data, 668 + INA226_ALERT_POL_LOW); 669 + if (ret < 0) { 670 + return dev_err_probe(dev, ret, 671 + "failed to set alert polarity active low\n"); 672 + } 673 + } 674 + } 669 675 670 676 ret = ina2xx_init(data); 671 677 if (ret < 0) {