Lines Matching refs:chip
185 struct ina2xx_chip_info *chip = iio_priv(indio_dev); in ina2xx_read_raw() local
190 ret = regmap_read(chip->regmap, chan->address, ®val); in ina2xx_read_raw()
200 *val >>= chip->config->bus_voltage_shift; in ina2xx_read_raw()
205 *val = chip->avg; in ina2xx_read_raw()
211 *val2 = chip->int_time_vshunt; in ina2xx_read_raw()
213 *val2 = chip->int_time_vbus; in ina2xx_read_raw()
222 *val = DIV_ROUND_CLOSEST(1000000, SAMPLING_PERIOD(chip)); in ina2xx_read_raw()
230 *val = chip->config->shunt_voltage_lsb; in ina2xx_read_raw()
236 *val = chip->config->bus_voltage_lsb; in ina2xx_read_raw()
246 *val = chip->config->shunt_voltage_lsb; in ina2xx_read_raw()
247 *val2 = chip->shunt_resistor_uohm; in ina2xx_read_raw()
256 *val = chip->config->power_lsb_factor * in ina2xx_read_raw()
257 chip->config->shunt_voltage_lsb; in ina2xx_read_raw()
258 *val2 = chip->shunt_resistor_uohm; in ina2xx_read_raw()
266 *val = chip->pga_gain_vshunt; in ina2xx_read_raw()
271 *val = chip->range_vbus == 32 ? 1 : 2; in ina2xx_read_raw()
288 static int ina226_set_average(struct ina2xx_chip_info *chip, unsigned int val, in ina226_set_average() argument
299 chip->avg = ina226_avg_tab[bits]; in ina226_set_average()
311 static int ina226_set_int_time_vbus(struct ina2xx_chip_info *chip, in ina226_set_int_time_vbus() argument
322 chip->int_time_vbus = ina226_conv_time_tab[bits]; in ina226_set_int_time_vbus()
330 static int ina226_set_int_time_vshunt(struct ina2xx_chip_info *chip, in ina226_set_int_time_vshunt() argument
341 chip->int_time_vshunt = ina226_conv_time_tab[bits]; in ina226_set_int_time_vshunt()
373 static int ina219_set_int_time_vbus(struct ina2xx_chip_info *chip, in ina219_set_int_time_vbus() argument
383 chip->int_time_vbus = val_us_best; in ina219_set_int_time_vbus()
391 static int ina219_set_int_time_vshunt(struct ina2xx_chip_info *chip, in ina219_set_int_time_vshunt() argument
401 chip->int_time_vshunt = val_us_best; in ina219_set_int_time_vshunt()
410 static int ina219_set_vbus_range_denom(struct ina2xx_chip_info *chip, in ina219_set_vbus_range_denom() argument
415 chip->range_vbus = 32; in ina219_set_vbus_range_denom()
417 chip->range_vbus = 16; in ina219_set_vbus_range_denom()
431 static int ina219_set_vshunt_pga_gain(struct ina2xx_chip_info *chip, in ina219_set_vshunt_pga_gain() argument
443 chip->pga_gain_vshunt = ina219_vshunt_gain_tab[bits]; in ina219_set_vshunt_pga_gain()
481 struct ina2xx_chip_info *chip = iio_priv(indio_dev); in ina2xx_write_raw() local
488 mutex_lock(&chip->state_lock); in ina2xx_write_raw()
490 ret = regmap_read(chip->regmap, INA2XX_CONFIG, &config); in ina2xx_write_raw()
498 ret = ina226_set_average(chip, val, &tmp); in ina2xx_write_raw()
502 if (chip->config->chip_id == ina226) { in ina2xx_write_raw()
504 ret = ina226_set_int_time_vshunt(chip, val2, in ina2xx_write_raw()
507 ret = ina226_set_int_time_vbus(chip, val2, in ina2xx_write_raw()
511 ret = ina219_set_int_time_vshunt(chip, val2, in ina2xx_write_raw()
514 ret = ina219_set_int_time_vbus(chip, val2, in ina2xx_write_raw()
521 ret = ina219_set_vshunt_pga_gain(chip, val * 1000 + in ina2xx_write_raw()
524 ret = ina219_set_vbus_range_denom(chip, val, &tmp); in ina2xx_write_raw()
532 ret = regmap_write(chip->regmap, INA2XX_CONFIG, tmp); in ina2xx_write_raw()
534 mutex_unlock(&chip->state_lock); in ina2xx_write_raw()
543 struct ina2xx_chip_info *chip = iio_priv(dev_to_iio_dev(dev)); in ina2xx_allow_async_readout_show() local
545 return sysfs_emit(buf, "%d\n", chip->allow_async_readout); in ina2xx_allow_async_readout_show()
552 struct ina2xx_chip_info *chip = iio_priv(dev_to_iio_dev(dev)); in ina2xx_allow_async_readout_store() local
560 chip->allow_async_readout = val; in ina2xx_allow_async_readout_store()
572 static int ina2xx_set_calibration(struct ina2xx_chip_info *chip) in ina2xx_set_calibration() argument
574 return regmap_write(chip->regmap, INA2XX_CALIBRATION, in ina2xx_set_calibration()
575 chip->config->calibration_value); in ina2xx_set_calibration()
578 static int set_shunt_resistor(struct ina2xx_chip_info *chip, unsigned int val) in set_shunt_resistor() argument
583 chip->shunt_resistor_uohm = val; in set_shunt_resistor()
592 struct ina2xx_chip_info *chip = iio_priv(dev_to_iio_dev(dev)); in ina2xx_shunt_resistor_show() local
593 int vals[2] = { chip->shunt_resistor_uohm, 1000000 }; in ina2xx_shunt_resistor_show()
602 struct ina2xx_chip_info *chip = iio_priv(dev_to_iio_dev(dev)); in ina2xx_shunt_resistor_store() local
609 ret = set_shunt_resistor(chip, val * 1000000 + val_fract); in ina2xx_shunt_resistor_store()
715 struct ina2xx_chip_info *chip = iio_priv(indio_dev); in ina2xx_conversion_ready() local
730 if (chip->config->chip_id == ina226) { in ina2xx_conversion_ready()
731 ret = regmap_read(chip->regmap, in ina2xx_conversion_ready()
735 ret = regmap_read(chip->regmap, in ina2xx_conversion_ready()
748 struct ina2xx_chip_info *chip = iio_priv(indio_dev); in ina2xx_work_buffer() local
762 ret = regmap_read(chip->regmap, in ina2xx_work_buffer()
767 chip->scan.chan[i++] = val; in ina2xx_work_buffer()
770 iio_push_to_buffers_with_timestamp(indio_dev, &chip->scan, time); in ina2xx_work_buffer()
778 struct ina2xx_chip_info *chip = iio_priv(indio_dev); in ina2xx_capture_thread() local
779 int sampling_us = SAMPLING_PERIOD(chip); in ina2xx_capture_thread()
788 if (!chip->allow_async_readout) in ina2xx_capture_thread()
794 while (!chip->allow_async_readout) { in ina2xx_capture_thread()
836 struct ina2xx_chip_info *chip = iio_priv(indio_dev); in ina2xx_buffer_enable() local
837 unsigned int sampling_us = SAMPLING_PERIOD(chip); in ina2xx_buffer_enable()
842 1000000 / sampling_us, chip->avg); in ina2xx_buffer_enable()
846 chip->allow_async_readout); in ina2xx_buffer_enable()
855 chip->task = task; in ina2xx_buffer_enable()
862 struct ina2xx_chip_info *chip = iio_priv(indio_dev); in ina2xx_buffer_disable() local
864 if (chip->task) { in ina2xx_buffer_disable()
865 kthread_stop(chip->task); in ina2xx_buffer_disable()
866 chip->task = NULL; in ina2xx_buffer_disable()
880 struct ina2xx_chip_info *chip = iio_priv(indio_dev); in ina2xx_debug_reg() local
883 return regmap_write(chip->regmap, reg, writeval); in ina2xx_debug_reg()
885 return regmap_read(chip->regmap, reg, readval); in ina2xx_debug_reg()
943 static int ina2xx_init(struct ina2xx_chip_info *chip, unsigned int config) in ina2xx_init() argument
945 int ret = regmap_write(chip->regmap, INA2XX_CONFIG, config); in ina2xx_init()
949 return ina2xx_set_calibration(chip); in ina2xx_init()
955 struct ina2xx_chip_info *chip; in ina2xx_probe() local
961 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); in ina2xx_probe()
965 chip = iio_priv(indio_dev); in ina2xx_probe()
970 chip->regmap = devm_regmap_init_i2c(client, &ina2xx_regmap_config); in ina2xx_probe()
971 if (IS_ERR(chip->regmap)) { in ina2xx_probe()
973 return PTR_ERR(chip->regmap); in ina2xx_probe()
980 chip->config = &ina2xx_config[type]; in ina2xx_probe()
982 mutex_init(&chip->state_lock); in ina2xx_probe()
995 ret = set_shunt_resistor(chip, val); in ina2xx_probe()
1000 val = chip->config->config_default; in ina2xx_probe()
1003 ina226_set_average(chip, INA226_DEFAULT_AVG, &val); in ina2xx_probe()
1004 ina226_set_int_time_vbus(chip, INA226_DEFAULT_IT, &val); in ina2xx_probe()
1005 ina226_set_int_time_vshunt(chip, INA226_DEFAULT_IT, &val); in ina2xx_probe()
1007 chip->avg = 1; in ina2xx_probe()
1008 ina219_set_int_time_vbus(chip, INA219_DEFAULT_IT, &val); in ina2xx_probe()
1009 ina219_set_int_time_vshunt(chip, INA219_DEFAULT_IT, &val); in ina2xx_probe()
1010 ina219_set_vbus_range_denom(chip, INA219_DEFAULT_BRNG, &val); in ina2xx_probe()
1011 ina219_set_vshunt_pga_gain(chip, INA219_DEFAULT_PGA, &val); in ina2xx_probe()
1014 ret = ina2xx_init(chip, val); in ina2xx_probe()
1030 indio_dev->name = id ? id->name : chip->config->name; in ina2xx_probe()
1043 struct ina2xx_chip_info *chip = iio_priv(indio_dev); in ina2xx_remove() local
1049 ret = regmap_update_bits(chip->regmap, INA2XX_CONFIG, in ina2xx_remove()