Lines Matching +full:current +full:- +full:sense +full:- +full:shunt

1 // SPDX-License-Identifier: GPL-2.0
5 * Maxim max9611/max9612 high side current sense amplifier with
6 * 12-bit ADC interface.
12 * This driver supports input common-mode voltage, current-sense
16 * Op-amp, analog comparator, and watchdog functionalities are not
50 * max9611 current sense amplifier voltage output:
58 * The complete formula to calculate current sense voltage is:
59 * (((adc_read >> 4) - offset) / ((1 / LSB) * 10^-3)
73 * (((adc_read >> 4) * 1000) - offset) / (1 / 14 * 1000)
115 * max9611_mux_conf - associate ADC mux configuration with register address
138 * max9611_csa_gain_conf - associate gain multiplier with LSB and
142 * on current sense amplifier path to ADC interface.
143 * Current sense read routine adjusts gain until it gets a meaningful
196 * max9611_read_single() - read a single value from ADC interface
203 * Data are transmitted with big-endian ordering: MSB arrives first.
219 * Keep mutex lock held during read-write to avoid mux register in max9611_read_single()
220 * (CTRL1) re-configuration. in max9611_read_single()
222 mutex_lock(&max9611->lock); in max9611_read_single()
223 ret = i2c_smbus_write_byte_data(max9611->i2c_client, in max9611_read_single()
226 dev_err(max9611->dev, "i2c write byte failed: 0x%2x - 0x%2x\n", in max9611_read_single()
228 mutex_unlock(&max9611->lock); in max9611_read_single()
236 ret = i2c_smbus_read_word_swapped(max9611->i2c_client, reg_addr); in max9611_read_single()
238 dev_err(max9611->dev, "i2c read word from 0x%2x failed\n", in max9611_read_single()
240 mutex_unlock(&max9611->lock); in max9611_read_single()
245 mutex_unlock(&max9611->lock); in max9611_read_single()
251 * max9611_read_csa_voltage() - read current sense amplifier output voltage
253 * Current sense amplifier output voltage is read through a configurable
285 return -EIO; in max9611_read_csa_voltage()
301 switch (chan->address) { in max9611_read_raw()
306 return -EINVAL; in max9611_read_raw()
315 return -EINVAL; in max9611_read_raw()
331 switch (chan->address) { in max9611_read_raw()
348 switch (chan->address) { in max9611_read_raw()
351 * processed (mV): (raw - offset) * LSB (nV) / 10^6 in max9611_read_raw()
359 return -EINVAL; in max9611_read_raw()
363 adc_data -= csa_gain[CSA_GAIN_OFFS_RAW]; in max9611_read_raw()
375 return -EINVAL; in max9611_read_raw()
379 adc_data -= csa_gain[CSA_GAIN_OFFS_RAW]; in max9611_read_raw()
382 *val2 = dev->shunt_resistor_uohm; in max9611_read_raw()
394 return -EINVAL; in max9611_read_raw()
396 adc_data -= MAX9611_CIM_OFFSET_RAW; in max9611_read_raw()
403 return -EINVAL; in max9611_read_raw()
408 adc_data -= csa_gain[CSA_GAIN_OFFS_RAW]; in max9611_read_raw()
411 *val2 = dev->shunt_resistor_uohm; in max9611_read_raw()
419 return -EINVAL; in max9611_read_raw()
429 i = max9611->shunt_resistor_uohm / 1000000; in max9611_shunt_resistor_show()
430 r = max9611->shunt_resistor_uohm % 1000000; in max9611_shunt_resistor_show()
457 struct i2c_client *client = max9611->i2c_client; in max9611_init()
461 if (!i2c_check_functionality(client->adapter, in max9611_init()
464 dev_err(max9611->dev, in max9611_init()
466 return -EINVAL; in max9611_init()
479 dev_err(max9611->dev, in max9611_init()
482 return -EIO; in max9611_init()
486 ret = i2c_smbus_write_byte_data(max9611->i2c_client, in max9611_init()
489 dev_err(max9611->dev, "i2c write byte failed: 0x%2x - 0x%2x\n", in max9611_init()
494 ret = i2c_smbus_write_byte_data(max9611->i2c_client, in max9611_init()
497 dev_err(max9611->dev, "i2c write byte failed: 0x%2x - 0x%2x\n", in max9611_init()
515 const char * const shunt_res_prop = "shunt-resistor-micro-ohms"; in max9611_probe()
518 struct device *dev = &client->dev; in max9611_probe()
522 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*max9611)); in max9611_probe()
524 return -ENOMEM; in max9611_probe()
529 max9611->dev = dev; in max9611_probe()
530 max9611->i2c_client = client; in max9611_probe()
531 mutex_init(&max9611->lock); in max9611_probe()
539 max9611->shunt_resistor_uohm = of_shunt; in max9611_probe()
545 indio_dev->name = device_get_match_data(dev); in max9611_probe()
546 indio_dev->modes = INDIO_DIRECT_MODE; in max9611_probe()
547 indio_dev->info = &indio_info; in max9611_probe()
548 indio_dev->channels = max9611_channels; in max9611_probe()
549 indio_dev->num_channels = ARRAY_SIZE(max9611_channels); in max9611_probe()
564 MODULE_DESCRIPTION("Maxim max9611/12 current sense amplifier with 12bit ADC");