Lines Matching refs:ina
132 static inline bool ina3221_is_enabled(struct ina3221_data *ina, int channel) in ina3221_is_enabled() argument
136 return ina->summation_shunt_resistor != 0; in ina3221_is_enabled()
138 return pm_runtime_active(ina->pm_dev) && in ina3221_is_enabled()
139 (ina->reg_config & INA3221_CONFIG_CHx_EN(channel)); in ina3221_is_enabled()
151 static inline int ina3221_summation_shunt_resistor(struct ina3221_data *ina) in ina3221_summation_shunt_resistor() argument
153 struct ina3221_input *input = ina->inputs; in ina3221_summation_shunt_resistor()
208 static inline int ina3221_wait_for_data(struct ina3221_data *ina) in ina3221_wait_for_data() argument
212 wait = ina3221_reg_to_interval_us(ina->reg_config); in ina3221_wait_for_data()
215 return regmap_field_read_poll_timeout(ina->fields[F_CVRF], in ina3221_wait_for_data()
219 static int ina3221_read_value(struct ina3221_data *ina, unsigned int reg, in ina3221_read_value() argument
225 ret = regmap_read(ina->regmap, reg, ®val); in ina3221_read_value()
253 struct ina3221_data *ina = dev_get_drvdata(dev); in ina3221_read_chip() local
258 regval = INA3221_CONFIG_AVG(ina->reg_config); in ina3221_read_chip()
263 *val = ina3221_reg_to_interval_us(ina->reg_config); in ina3221_read_chip()
274 struct ina3221_data *ina = dev_get_drvdata(dev); in ina3221_read_in() local
287 if (!ina3221_is_enabled(ina, channel)) in ina3221_read_in()
291 if (ina->single_shot) in ina3221_read_in()
292 regmap_write(ina->regmap, INA3221_CONFIG, in ina3221_read_in()
293 ina->reg_config); in ina3221_read_in()
295 ret = ina3221_wait_for_data(ina); in ina3221_read_in()
299 ret = ina3221_read_value(ina, reg, ®val); in ina3221_read_in()
310 *val = ina3221_is_enabled(ina, channel); in ina3221_read_in()
330 struct ina3221_data *ina = dev_get_drvdata(dev); in ina3221_read_curr() local
331 struct ina3221_input *input = ina->inputs; in ina3221_read_curr()
337 resistance_uo = ina->summation_shunt_resistor; in ina3221_read_curr()
343 if (!ina3221_is_enabled(ina, channel)) in ina3221_read_curr()
347 if (ina->single_shot) in ina3221_read_curr()
348 regmap_write(ina->regmap, INA3221_CONFIG, in ina3221_read_curr()
349 ina->reg_config); in ina3221_read_curr()
351 ret = ina3221_wait_for_data(ina); in ina3221_read_curr()
361 ret = ina3221_read_value(ina, reg, ®val); in ina3221_read_curr()
373 if (!ina3221_is_enabled(ina, channel)) { in ina3221_read_curr()
378 ret = regmap_field_read(ina->fields[reg], ®val); in ina3221_read_curr()
390 struct ina3221_data *ina = dev_get_drvdata(dev); in ina3221_write_chip() local
399 tmp = (ina->reg_config & ~INA3221_CONFIG_AVG_MASK) | in ina3221_write_chip()
401 ret = regmap_write(ina->regmap, INA3221_CONFIG, tmp); in ina3221_write_chip()
406 ina->reg_config = tmp; in ina3221_write_chip()
409 tmp = ina3221_interval_ms_to_conv_time(ina->reg_config, val); in ina3221_write_chip()
415 tmp = (ina->reg_config & ~tmp) | in ina3221_write_chip()
418 ret = regmap_write(ina->regmap, INA3221_CONFIG, tmp); in ina3221_write_chip()
423 ina->reg_config = tmp; in ina3221_write_chip()
433 struct ina3221_data *ina = dev_get_drvdata(dev); in ina3221_write_curr() local
434 struct ina3221_input *input = ina->inputs; in ina3221_write_curr()
440 resistance_uo = ina->summation_shunt_resistor; in ina3221_write_curr()
473 return regmap_write(ina->regmap, reg, regval); in ina3221_write_curr()
478 struct ina3221_data *ina = dev_get_drvdata(dev); in ina3221_write_enable() local
480 u16 config_old = ina->reg_config & mask; in ina3221_write_enable()
492 ret = pm_runtime_get_sync(ina->pm_dev); in ina3221_write_enable()
500 tmp = (ina->reg_config & ~mask) | (config & mask); in ina3221_write_enable()
501 ret = regmap_write(ina->regmap, INA3221_CONFIG, tmp); in ina3221_write_enable()
506 ina->reg_config = tmp; in ina3221_write_enable()
510 pm_runtime_put_sync(ina->pm_dev); in ina3221_write_enable()
518 pm_runtime_put_sync(ina->pm_dev); in ina3221_write_enable()
527 struct ina3221_data *ina = dev_get_drvdata(dev); in ina3221_read() local
530 mutex_lock(&ina->lock); in ina3221_read()
548 mutex_unlock(&ina->lock); in ina3221_read()
556 struct ina3221_data *ina = dev_get_drvdata(dev); in ina3221_write() local
559 mutex_lock(&ina->lock); in ina3221_write()
577 mutex_unlock(&ina->lock); in ina3221_write()
585 struct ina3221_data *ina = dev_get_drvdata(dev); in ina3221_read_string() local
591 *str = ina->inputs[index].label; in ina3221_read_string()
600 const struct ina3221_data *ina = drvdata; in ina3221_is_visible() local
620 input = &ina->inputs[channel - 1]; in ina3221_is_visible()
697 struct ina3221_data *ina = dev_get_drvdata(dev); in ina3221_shunt_show() local
699 struct ina3221_input *input = &ina->inputs[channel]; in ina3221_shunt_show()
709 struct ina3221_data *ina = dev_get_drvdata(dev); in ina3221_shunt_store() local
711 struct ina3221_input *input = &ina->inputs[channel]; in ina3221_shunt_store()
724 ina->summation_shunt_resistor = ina3221_summation_shunt_resistor(ina); in ina3221_shunt_store()
763 struct ina3221_data *ina) in ina3221_probe_child_from_dt() argument
778 input = &ina->inputs[val]; in ina3221_probe_child_from_dt()
802 static int ina3221_probe_from_dt(struct device *dev, struct ina3221_data *ina) in ina3221_probe_from_dt() argument
812 ina->single_shot = of_property_read_bool(np, "ti,single-shot"); in ina3221_probe_from_dt()
815 ret = ina3221_probe_child_from_dt(dev, child, ina); in ina3221_probe_from_dt()
828 struct ina3221_data *ina; in ina3221_probe() local
832 ina = devm_kzalloc(dev, sizeof(*ina), GFP_KERNEL); in ina3221_probe()
833 if (!ina) in ina3221_probe()
836 ina->regmap = devm_regmap_init_i2c(client, &ina3221_regmap_config); in ina3221_probe()
837 if (IS_ERR(ina->regmap)) { in ina3221_probe()
839 return PTR_ERR(ina->regmap); in ina3221_probe()
843 ina->fields[i] = devm_regmap_field_alloc(dev, in ina3221_probe()
844 ina->regmap, in ina3221_probe()
846 if (IS_ERR(ina->fields[i])) { in ina3221_probe()
848 return PTR_ERR(ina->fields[i]); in ina3221_probe()
853 ina->inputs[i].shunt_resistor = INA3221_RSHUNT_DEFAULT; in ina3221_probe()
855 ret = ina3221_probe_from_dt(dev, ina); in ina3221_probe()
862 ina->reg_config = INA3221_CONFIG_DEFAULT; in ina3221_probe()
865 if (ina->single_shot) in ina3221_probe()
866 ina->reg_config &= ~INA3221_CONFIG_MODE_CONTINUOUS; in ina3221_probe()
870 if (ina->inputs[i].disconnected) in ina3221_probe()
871 ina->reg_config &= ~INA3221_CONFIG_CHx_EN(i); in ina3221_probe()
875 ina->summation_shunt_resistor = ina3221_summation_shunt_resistor(ina); in ina3221_probe()
877 ina->pm_dev = dev; in ina3221_probe()
878 mutex_init(&ina->lock); in ina3221_probe()
879 dev_set_drvdata(dev, ina); in ina3221_probe()
882 pm_runtime_enable(ina->pm_dev); in ina3221_probe()
886 if (ina->inputs[i].disconnected) in ina3221_probe()
889 ret = pm_runtime_get_sync(ina->pm_dev); in ina3221_probe()
894 hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, ina, in ina3221_probe()
906 pm_runtime_disable(ina->pm_dev); in ina3221_probe()
907 pm_runtime_set_suspended(ina->pm_dev); in ina3221_probe()
910 pm_runtime_put_noidle(ina->pm_dev); in ina3221_probe()
911 mutex_destroy(&ina->lock); in ina3221_probe()
918 struct ina3221_data *ina = dev_get_drvdata(&client->dev); in ina3221_remove() local
921 pm_runtime_disable(ina->pm_dev); in ina3221_remove()
922 pm_runtime_set_suspended(ina->pm_dev); in ina3221_remove()
926 pm_runtime_put_noidle(ina->pm_dev); in ina3221_remove()
928 mutex_destroy(&ina->lock); in ina3221_remove()
935 struct ina3221_data *ina = dev_get_drvdata(dev); in ina3221_suspend() local
939 ret = regmap_read(ina->regmap, INA3221_CONFIG, &ina->reg_config); in ina3221_suspend()
944 ret = regmap_update_bits(ina->regmap, INA3221_CONFIG, in ina3221_suspend()
950 regcache_cache_only(ina->regmap, true); in ina3221_suspend()
951 regcache_mark_dirty(ina->regmap); in ina3221_suspend()
958 struct ina3221_data *ina = dev_get_drvdata(dev); in ina3221_resume() local
961 regcache_cache_only(ina->regmap, false); in ina3221_resume()
964 ret = regmap_field_write(ina->fields[F_RST], true); in ina3221_resume()
971 ret = regcache_sync(ina->regmap); in ina3221_resume()
976 ret = regmap_write(ina->regmap, INA3221_CONFIG, ina->reg_config); in ina3221_resume()
981 if (ina->summation_shunt_resistor) { in ina3221_resume()
987 ret = regmap_update_bits(ina->regmap, INA3221_MASK_ENABLE, in ina3221_resume()