Lines Matching +full:vref +full:- +full:n +full:- +full:supply
1 // SPDX-License-Identifier: GPL-2.0-only
4 * multi-channel Digital to Analog Converters driver
35 * struct ad5380_chip_info - chip specific information
38 * @int_vref: internal vref in uV
47 * struct ad5380_state - driver instance specific data
50 * @vref_reg: vref supply regulator
51 * @vref: actual reference voltage used in uA
59 int vref; member
86 return sysfs_emit(buf, "%d\n", st->pwr_down); in ad5380_read_dac_powerdown()
101 mutex_lock(&st->lock); in ad5380_write_dac_powerdown()
104 ret = regmap_write(st->regmap, AD5380_REG_SF_PWR_DOWN, 0); in ad5380_write_dac_powerdown()
106 ret = regmap_write(st->regmap, AD5380_REG_SF_PWR_UP, 0); in ad5380_write_dac_powerdown()
108 st->pwr_down = pwr_down; in ad5380_write_dac_powerdown()
110 mutex_unlock(&st->lock); in ad5380_write_dac_powerdown()
127 ret = regmap_read(st->regmap, AD5380_REG_SF_CTRL, &mode); in ad5380_get_powerdown_mode()
142 ret = regmap_update_bits(st->regmap, AD5380_REG_SF_CTRL, in ad5380_set_powerdown_mode()
161 return AD5380_REG_DATA(chan->address); in ad5380_info_to_reg()
163 return AD5380_REG_OFFSET(chan->address); in ad5380_info_to_reg()
165 return AD5380_REG_GAIN(chan->address); in ad5380_info_to_reg()
176 const unsigned int max_val = (1 << chan->scan_type.realbits); in ad5380_write_raw()
183 return -EINVAL; in ad5380_write_raw()
185 return regmap_write(st->regmap, in ad5380_write_raw()
187 val << chan->scan_type.shift); in ad5380_write_raw()
189 val += (1 << chan->scan_type.realbits) / 2; in ad5380_write_raw()
191 return -EINVAL; in ad5380_write_raw()
193 return regmap_write(st->regmap, in ad5380_write_raw()
194 AD5380_REG_OFFSET(chan->address), in ad5380_write_raw()
195 val << chan->scan_type.shift); in ad5380_write_raw()
199 return -EINVAL; in ad5380_write_raw()
211 ret = regmap_read(st->regmap, ad5380_info_to_reg(chan, info), in ad5380_read_raw()
215 *val >>= chan->scan_type.shift; in ad5380_read_raw()
218 ret = regmap_read(st->regmap, AD5380_REG_OFFSET(chan->address), in ad5380_read_raw()
222 *val >>= chan->scan_type.shift; in ad5380_read_raw()
223 *val -= (1 << chan->scan_type.realbits) / 2; in ad5380_read_raw()
226 *val = 2 * st->vref; in ad5380_read_raw()
227 *val2 = chan->scan_type.realbits; in ad5380_read_raw()
233 return -EINVAL; in ad5380_read_raw()
266 .shift = 14 - (_bits), \
350 channels = kcalloc(st->chip_info->num_channels, in ad5380_alloc_channels()
354 return -ENOMEM; in ad5380_alloc_channels()
356 for (i = 0; i < st->chip_info->num_channels; ++i) { in ad5380_alloc_channels()
357 channels[i] = st->chip_info->channel_template; in ad5380_alloc_channels()
362 indio_dev->channels = channels; in ad5380_alloc_channels()
377 dev_err(dev, "Failed to allocate iio device\n"); in ad5380_probe()
378 return -ENOMEM; in ad5380_probe()
384 st->chip_info = &ad5380_chip_info_tbl[type]; in ad5380_probe()
385 st->regmap = regmap; in ad5380_probe()
387 indio_dev->name = name; in ad5380_probe()
388 indio_dev->info = &ad5380_info; in ad5380_probe()
389 indio_dev->modes = INDIO_DIRECT_MODE; in ad5380_probe()
390 indio_dev->num_channels = st->chip_info->num_channels; in ad5380_probe()
392 mutex_init(&st->lock); in ad5380_probe()
396 dev_err(dev, "Failed to allocate channel spec: %d\n", ret); in ad5380_probe()
400 if (st->chip_info->int_vref == 2500) in ad5380_probe()
403 st->vref_reg = devm_regulator_get(dev, "vref"); in ad5380_probe()
404 if (!IS_ERR(st->vref_reg)) { in ad5380_probe()
405 ret = regulator_enable(st->vref_reg); in ad5380_probe()
407 dev_err(dev, "Failed to enable vref regulators: %d\n", in ad5380_probe()
412 ret = regulator_get_voltage(st->vref_reg); in ad5380_probe()
416 st->vref = ret / 1000; in ad5380_probe()
418 st->vref = st->chip_info->int_vref; in ad5380_probe()
422 ret = regmap_write(st->regmap, AD5380_REG_SF_CTRL, ctrl); in ad5380_probe()
424 dev_err(dev, "Failed to write to device: %d\n", ret); in ad5380_probe()
430 dev_err(dev, "Failed to register iio device: %d\n", ret); in ad5380_probe()
437 if (!IS_ERR(st->vref_reg)) in ad5380_probe()
438 regulator_disable(st->vref_reg); in ad5380_probe()
440 kfree(indio_dev->channels); in ad5380_probe()
452 kfree(indio_dev->channels); in ad5380_remove()
454 if (!IS_ERR(st->vref_reg)) in ad5380_remove()
455 regulator_disable(st->vref_reg); in ad5380_remove()
486 return ad5380_probe(&spi->dev, regmap, id->driver_data, id->name); in ad5380_spi_probe()
491 ad5380_remove(&spi->dev); in ad5380_spi_remove()
495 { "ad5380-3", ID_AD5380_3 },
496 { "ad5380-5", ID_AD5380_5 },
497 { "ad5381-3", ID_AD5381_3 },
498 { "ad5381-5", ID_AD5381_5 },
499 { "ad5382-3", ID_AD5382_3 },
500 { "ad5382-5", ID_AD5382_5 },
501 { "ad5383-3", ID_AD5383_3 },
502 { "ad5383-5", ID_AD5383_5 },
503 { "ad5384-3", ID_AD5380_3 },
504 { "ad5384-5", ID_AD5380_5 },
505 { "ad5390-3", ID_AD5390_3 },
506 { "ad5390-5", ID_AD5390_5 },
507 { "ad5391-3", ID_AD5391_3 },
508 { "ad5391-5", ID_AD5391_5 },
509 { "ad5392-3", ID_AD5392_3 },
510 { "ad5392-5", ID_AD5392_5 },
559 return ad5380_probe(&i2c->dev, regmap, id->driver_data, id->name); in ad5380_i2c_probe()
564 ad5380_remove(&i2c->dev); in ad5380_i2c_remove()
568 { "ad5380-3", ID_AD5380_3 },
569 { "ad5380-5", ID_AD5380_5 },
570 { "ad5381-3", ID_AD5381_3 },
571 { "ad5381-5", ID_AD5381_5 },
572 { "ad5382-3", ID_AD5382_3 },
573 { "ad5382-5", ID_AD5382_5 },
574 { "ad5383-3", ID_AD5383_3 },
575 { "ad5383-5", ID_AD5383_5 },
576 { "ad5384-3", ID_AD5380_3 },
577 { "ad5384-5", ID_AD5380_5 },
578 { "ad5390-3", ID_AD5390_3 },
579 { "ad5390-5", ID_AD5390_5 },
580 { "ad5391-3", ID_AD5391_3 },
581 { "ad5391-5", ID_AD5391_5 },
582 { "ad5392-3", ID_AD5392_3 },
583 { "ad5392-5", ID_AD5392_5 },
646 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");