Lines Matching +full:gain +full:- +full:offset
1 // SPDX-License-Identifier: GPL-2.0-only
63 u8 gain; member
71 /* ADA4250 Gain (V/V) values: 1, 2, 4, 8, 16, 32, 64, 128 */
91 if (st->bias == 0 || st->bias == 3) in ada4250_set_offset_uv()
92 return -EINVAL; in ada4250_set_offset_uv()
94 voltage_v = regulator_get_voltage(st->reg); in ada4250_set_offset_uv()
97 if (st->bias == ADA4250_BIAS_AVDD) in ada4250_set_offset_uv()
102 x[1] = 126 * (x[0] - 1); in ada4250_set_offset_uv()
107 if (st->gain == 0) in ada4250_set_offset_uv()
108 return -EINVAL; in ada4250_set_offset_uv()
111 * Compute Range and Voltage per LSB for the Sensor Offset Calibration in ada4250_set_offset_uv()
114 * Gain | Max Vos(mV) | LSB(mV) | Max Vos(mV) | LSB(mV) | in ada4250_set_offset_uv()
115 * 2 | X1*127 | X1=0.126(AVDD-1) | X1*3*127 | X1*3 | in ada4250_set_offset_uv()
124 max_vos = x[st->gain] * 127 * ((1 << (i + 1)) - 1); in ada4250_set_offset_uv()
125 min_vos = -1 * max_vos; in ada4250_set_offset_uv()
128 vlsb = x[st->gain] * ((1 << (i + 1)) - 1); in ada4250_set_offset_uv()
134 return -EINVAL; in ada4250_set_offset_uv()
138 mutex_lock(&st->lock); in ada4250_set_offset_uv()
139 ret = regmap_update_bits(st->regmap, ADA4250_REG_SNSR_CAL_CNFG, in ada4250_set_offset_uv()
145 st->offset_uv = offset_raw * vlsb; in ada4250_set_offset_uv()
148 * To set the offset calibration value, use bits [6:0] and bit 7 as the in ada4250_set_offset_uv()
149 * polarity bit (set to "0" for a negative offset and "1" for a positive in ada4250_set_offset_uv()
150 * offset). in ada4250_set_offset_uv()
154 st->offset_uv *= (-1); in ada4250_set_offset_uv()
157 ret = regmap_write(st->regmap, ADA4250_REG_SNSR_CAL_VAL, offset_raw); in ada4250_set_offset_uv()
160 mutex_unlock(&st->lock); in ada4250_set_offset_uv()
174 ret = regmap_read(st->regmap, ADA4250_REG_GAIN_MUX, val); in ada4250_read_raw()
182 *val = st->offset_uv; in ada4250_read_raw()
186 ret = regmap_read(st->regmap, ADA4250_REG_SNSR_CAL_CNFG, val); in ada4250_read_raw()
199 return -EINVAL; in ada4250_read_raw()
212 ret = regmap_write(st->regmap, ADA4250_REG_GAIN_MUX, in ada4250_write_raw()
217 st->gain = ilog2(val); in ada4250_write_raw()
223 ret = regmap_update_bits(st->regmap, ADA4250_REG_SNSR_CAL_CNFG, in ada4250_write_raw()
229 st->bias = val; in ada4250_write_raw()
233 return -EINVAL; in ada4250_write_raw()
256 return -EINVAL; in ada4250_read_avail()
268 return regmap_read(st->regmap, reg, read_val); in ada4250_reg_access()
270 return regmap_write(st->regmap, reg, write_val); in ada4250_reg_access()
305 struct spi_device *spi = st->spi; in ada4250_init()
307 st->refbuf_en = device_property_read_bool(&spi->dev, "adi,refbuf-enable"); in ada4250_init()
309 st->reg = devm_regulator_get(&spi->dev, "avdd"); in ada4250_init()
310 if (IS_ERR(st->reg)) in ada4250_init()
311 return dev_err_probe(&spi->dev, PTR_ERR(st->reg), in ada4250_init()
314 ret = regulator_enable(st->reg); in ada4250_init()
316 dev_err(&spi->dev, "Failed to enable specified AVDD supply\n"); in ada4250_init()
320 ret = devm_add_action_or_reset(&spi->dev, ada4250_reg_disable, st->reg); in ada4250_init()
324 ret = regmap_write(st->regmap, ADA4250_REG_RESET, in ada4250_init()
329 ret = regmap_bulk_read(st->regmap, ADA4250_REG_CHIP_ID, data, 2); in ada4250_init()
336 dev_err(&spi->dev, "Invalid chip ID.\n"); in ada4250_init()
337 return -EINVAL; in ada4250_init()
340 return regmap_write(st->regmap, ADA4250_REG_REFBUF_EN, in ada4250_init()
341 FIELD_PREP(ADA4250_REFBUF_MSK, st->refbuf_en)); in ada4250_init()
351 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ada4250_probe()
353 return -ENOMEM; in ada4250_probe()
360 st->regmap = regmap; in ada4250_probe()
361 st->spi = spi; in ada4250_probe()
363 indio_dev->info = &ada4250_info; in ada4250_probe()
364 indio_dev->name = "ada4250"; in ada4250_probe()
365 indio_dev->channels = ada4250_channels; in ada4250_probe()
366 indio_dev->num_channels = ARRAY_SIZE(ada4250_channels); in ada4250_probe()
368 mutex_init(&st->lock); in ada4250_probe()
372 dev_err(&spi->dev, "ADA4250 init failed\n"); in ada4250_probe()
376 return devm_iio_device_register(&spi->dev, indio_dev); in ada4250_probe()