Lines Matching +full:0 +full:- +full:127
1 // SPDX-License-Identifier: GPL-2.0-only
20 #define ADA4250_REG_GAIN_MUX 0x00
21 #define ADA4250_REG_REFBUF_EN 0x01
22 #define ADA4250_REG_RESET 0x02
23 #define ADA4250_REG_SNSR_CAL_VAL 0x04
24 #define ADA4250_REG_SNSR_CAL_CNFG 0x05
25 #define ADA4250_REG_DIE_REV 0x18
26 #define ADA4250_REG_CHIP_ID 0x19
29 #define ADA4250_GAIN_MUX_MSK GENMASK(2, 0)
32 #define ADA4250_REFBUF_MSK BIT(0)
35 #define ADA4250_RESET_MSK BIT(0)
38 #define ADA4250_CAL_CFG_BIAS_MSK GENMASK(7, 0)
42 #define ADA4250_RANGE_SET_MSK GENMASK(1, 0)
45 #define ADA4250_CHIP_ID 0x4250
46 #define ADA4250_RANGE1 0
69 static const int calibbias_table[] = {0, 1, 2};
78 .max_register = 0x1A,
87 int i, ret, x[8], max_vos, min_vos, voltage_v, vlsb = 0; in ada4250_set_offset_uv()
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()
98 x[0] = voltage_v; in ada4250_set_offset_uv()
100 x[0] = 5; in ada4250_set_offset_uv()
102 x[1] = 126 * (x[0] - 1); in ada4250_set_offset_uv()
104 for (i = 0; i < 6; i++) in ada4250_set_offset_uv()
107 if (st->gain == 0) in ada4250_set_offset_uv()
108 return -EINVAL; in ada4250_set_offset_uv()
115 * 2 | X1*127 | X1=0.126(AVDD-1) | X1*3*127 | X1*3 | in ada4250_set_offset_uv()
116 * 4 | X2*127 | X2=X1/1.3333 | X2*3*127 | X2*3 | in ada4250_set_offset_uv()
117 * 8 | X3*127 | X3=X1/2.301 | X3*3*127 | X3*3 | in ada4250_set_offset_uv()
118 * 16 | X4*127 | X4=X1/4.283 | X4*3*127 | X4*3 | in ada4250_set_offset_uv()
119 * 32 | X5*127 | X5=X1/8.289 | X5*3*127 | X5*3 | in ada4250_set_offset_uv()
120 * 64 | X6*127 | X6=X1/16.311 | X6*3*127 | X6*3 | in ada4250_set_offset_uv()
121 * 128 | X7*127 | X7=X1/31.599 | X7*3*127 | X7*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()
133 if (vlsb <= 0) 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()
152 if (offset_uv < 0) { 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()
285 .channel = 0,
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()
380 { "ada4250", 0 },