Lines Matching +full:alert +full:- +full:polarity +full:- +full:active +full:- +full:high
1 // SPDX-License-Identifier: GPL-2.0-only
6 * Zero Drift Bi-Directional Current/Power Monitor with I2C Interface
10 * Bi-Directional Current/Power Monitor with I2C Interface
14 * Bi-Directional Current/Power Monitor with I2C Interface
18 * Bi-directional Current/Power Monitor with I2C Interface
56 /* settings - depend on use case */
74 /* bit number of alert functions in Mask/Enable Register */
81 /* bit mask for alert config bits of Mask/Enable Register */
218 val = DIV_ROUND_CLOSEST((s16)regval, data->config->shunt_div); in ina2xx_get_value()
221 val = (regval >> data->config->bus_voltage_shift) * in ina2xx_get_value()
222 data->config->bus_voltage_lsb; in ina2xx_get_value()
226 val = regval * data->power_lsb_uW; in ina2xx_get_value()
230 val = (s16)regval * data->current_lsb_uA; in ina2xx_get_value()
248 * check if the chip has been power cycled or reset. If so, re-initialize it.
253 struct regmap *regmap = data->regmap; in ina2xx_read_init()
257 for (retry = 5; retry; retry--) { in ina2xx_read_init()
302 return -ENODEV; in ina2xx_read_init()
306 * Turns alert limit values into register values.
313 val = clamp_val(val, 0, SHRT_MAX * data->config->shunt_div); in ina226_alert_to_reg()
314 val *= data->config->shunt_div; in ina226_alert_to_reg()
318 val = (val * 1000) << data->config->bus_voltage_shift; in ina226_alert_to_reg()
319 val = DIV_ROUND_CLOSEST(val, data->config->bus_voltage_lsb); in ina226_alert_to_reg()
322 val = clamp_val(val, 0, UINT_MAX - data->power_lsb_uW); in ina226_alert_to_reg()
323 val = DIV_ROUND_CLOSEST(val, data->power_lsb_uW); in ina226_alert_to_reg()
328 val = DIV_ROUND_CLOSEST(val * 1000, data->current_lsb_uA); in ina226_alert_to_reg()
339 struct regmap *regmap = data->regmap; in ina226_alert_limit_read()
343 mutex_lock(&data->config_lock); in ina226_alert_limit_read()
357 mutex_unlock(&data->config_lock); in ina226_alert_limit_read()
363 struct regmap *regmap = data->regmap; in ina226_alert_limit_write()
367 return -EINVAL; in ina226_alert_limit_write()
370 * Clear all alerts first to avoid accidentally triggering ALERT pin in ina226_alert_limit_write()
371 * due to register write sequence. Then, only enable the alert in ina226_alert_limit_write()
372 * if the value is non-zero. in ina226_alert_limit_write()
374 mutex_lock(&data->config_lock); in ina226_alert_limit_write()
389 mutex_unlock(&data->config_lock); in ina226_alert_limit_write()
401 ret = regmap_read(data->regmap, INA2XX_CONFIG, ®val); in ina2xx_chip_read()
408 return -EOPNOTSUPP; in ina2xx_chip_read()
435 struct regmap *regmap = data->regmap; in ina2xx_in_read()
457 return -EOPNOTSUPP; in ina2xx_in_read()
473 return ina226_alert_read(data->regmap, INA226_POWER_OVER_LIMIT_MASK, val); in ina2xx_power_read()
475 return -EOPNOTSUPP; in ina2xx_power_read()
482 struct regmap *regmap = data->regmap; in ina2xx_curr_read()
519 return -EOPNOTSUPP; in ina2xx_curr_read()
536 return -EOPNOTSUPP; in ina2xx_read()
546 return regmap_update_bits(data->regmap, INA2XX_CONFIG, in ina2xx_chip_write()
550 return -EOPNOTSUPP; in ina2xx_chip_write()
570 return -EOPNOTSUPP; in ina2xx_in_write()
584 return -EOPNOTSUPP; in ina2xx_power_write()
601 return -EOPNOTSUPP; in ina2xx_curr_write()
619 return -EOPNOTSUPP; in ina2xx_write()
627 enum ina2xx_ids chip = data->chip; in ina2xx_is_visible()
736 data->config->shunt_div); in ina2xx_set_shunt()
738 return -EINVAL; in ina2xx_set_shunt()
740 data->rshunt = val; in ina2xx_set_shunt()
741 data->current_lsb_uA = DIV_ROUND_CLOSEST(dividend, val); in ina2xx_set_shunt()
742 data->power_lsb_uW = data->config->power_lsb_factor * in ina2xx_set_shunt()
743 data->current_lsb_uA; in ina2xx_set_shunt()
753 return sysfs_emit(buf, "%li\n", data->rshunt); in shunt_resistor_show()
768 mutex_lock(&data->config_lock); in shunt_resistor_store()
770 mutex_unlock(&data->config_lock); in shunt_resistor_store()
790 struct regmap *regmap = data->regmap; in ina2xx_init()
794 if (device_property_read_u32(dev, "shunt-resistor", &shunt) < 0) in ina2xx_init()
801 ret = regmap_write(regmap, INA2XX_CONFIG, data->config->config_default); in ina2xx_init()
805 if (data->chip == ina226) { in ina2xx_init()
806 bool active_high = device_property_read_bool(dev, "ti,alert-polarity-active-high"); in ina2xx_init()
821 data->config->calibration_value); in ina2xx_init()
826 struct device *dev = &client->dev; in ina2xx_probe()
836 return -ENOMEM; in ina2xx_probe()
839 data->config = &ina2xx_config[chip]; in ina2xx_probe()
840 data->chip = chip; in ina2xx_probe()
841 mutex_init(&data->config_lock); in ina2xx_probe()
843 data->regmap = devm_regmap_init_i2c(client, &ina2xx_regmap_config); in ina2xx_probe()
844 if (IS_ERR(data->regmap)) { in ina2xx_probe()
846 return PTR_ERR(data->regmap); in ina2xx_probe()
857 hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, in ina2xx_probe()
864 client->name, data->rshunt); in ina2xx_probe()
915 MODULE_AUTHOR("Lothar Felten <l-felten@ti.com>");