Lines Matching +full:vref +full:- +full:out +full:- +full:en
1 // SPDX-License-Identifier: GPL-2.0
2 /* ad7949.c - Analog Devices ADC driver 14/16 bits 4/8 channels
6 * https://www.analog.com/media/en/technical-documentation/data-sheets/AD7949.pdf
39 * struct ad7949_adc_chip - AD ADC chip
41 * @vref: regulator generating Vref
51 struct regulator *vref; member
64 int bits_per_word = ad7949_adc->resolution; in ad7949_spi_write_cfg()
65 int shift = bits_per_word - AD7949_CFG_REG_SIZE_BITS; in ad7949_spi_write_cfg()
69 .tx_buf = &ad7949_adc->buffer, in ad7949_spi_write_cfg()
75 ad7949_adc->cfg = (val & mask) | (ad7949_adc->cfg & ~mask); in ad7949_spi_write_cfg()
76 ad7949_adc->buffer = ad7949_adc->cfg << shift; in ad7949_spi_write_cfg()
78 ret = spi_sync(ad7949_adc->spi, &msg); in ad7949_spi_write_cfg()
93 int bits_per_word = ad7949_adc->resolution; in ad7949_spi_read_channel()
94 int mask = GENMASK(ad7949_adc->resolution - 1, 0); in ad7949_spi_read_channel()
98 .rx_buf = &ad7949_adc->buffer, in ad7949_spi_read_channel()
105 * 1: write CFG for sample N and read old data (sample N-2) in ad7949_spi_read_channel()
106 * 2: if CFG was not changed since sample N-1 then we'll get good data in ad7949_spi_read_channel()
107 * at the next xfer, so we bail out now, otherwise we write something in ad7949_spi_read_channel()
108 * and we read garbage (sample N-1 configuration). in ad7949_spi_read_channel()
116 if (channel == ad7949_adc->current_channel) in ad7949_spi_read_channel()
121 ad7949_adc->buffer = 0; in ad7949_spi_read_channel()
123 ret = spi_sync(ad7949_adc->spi, &msg); in ad7949_spi_read_channel()
133 ad7949_adc->current_channel = channel; in ad7949_spi_read_channel()
135 *val = ad7949_adc->buffer & mask; in ad7949_spi_read_channel()
167 return -EINVAL; in ad7949_spi_read_raw()
171 mutex_lock(&ad7949_adc->lock); in ad7949_spi_read_raw()
172 ret = ad7949_spi_read_channel(ad7949_adc, val, chan->channel); in ad7949_spi_read_raw()
173 mutex_unlock(&ad7949_adc->lock); in ad7949_spi_read_raw()
181 ret = regulator_get_voltage(ad7949_adc->vref); in ad7949_spi_read_raw()
189 return -EINVAL; in ad7949_spi_read_raw()
200 *readval = ad7949_adc->cfg; in ad7949_spi_reg_access()
219 ad7949_adc->current_channel = 0; in ad7949_spi_init()
226 ad7949_spi_read_channel(ad7949_adc, &val, ad7949_adc->current_channel); in ad7949_spi_init()
227 ad7949_spi_read_channel(ad7949_adc, &val, ad7949_adc->current_channel); in ad7949_spi_init()
234 struct device *dev = &spi->dev; in ad7949_spi_probe()
243 return -ENOMEM; in ad7949_spi_probe()
246 indio_dev->info = &ad7949_spi_info; in ad7949_spi_probe()
247 indio_dev->name = spi_get_device_id(spi)->name; in ad7949_spi_probe()
248 indio_dev->modes = INDIO_DIRECT_MODE; in ad7949_spi_probe()
249 indio_dev->channels = ad7949_adc_channels; in ad7949_spi_probe()
253 ad7949_adc->indio_dev = indio_dev; in ad7949_spi_probe()
254 ad7949_adc->spi = spi; in ad7949_spi_probe()
256 spec = &ad7949_adc_spec[spi_get_device_id(spi)->driver_data]; in ad7949_spi_probe()
257 indio_dev->num_channels = spec->num_channels; in ad7949_spi_probe()
258 ad7949_adc->resolution = spec->resolution; in ad7949_spi_probe()
260 ad7949_adc->vref = devm_regulator_get(dev, "vref"); in ad7949_spi_probe()
261 if (IS_ERR(ad7949_adc->vref)) { in ad7949_spi_probe()
263 return PTR_ERR(ad7949_adc->vref); in ad7949_spi_probe()
266 ret = regulator_enable(ad7949_adc->vref); in ad7949_spi_probe()
272 mutex_init(&ad7949_adc->lock); in ad7949_spi_probe()
289 mutex_destroy(&ad7949_adc->lock); in ad7949_spi_probe()
290 regulator_disable(ad7949_adc->vref); in ad7949_spi_probe()
301 mutex_destroy(&ad7949_adc->lock); in ad7949_spi_remove()
302 regulator_disable(ad7949_adc->vref); in ad7949_spi_remove()
334 MODULE_AUTHOR("Charles-Antoine Couret <charles-antoine.couret@essensium.com>");
335 MODULE_DESCRIPTION("Analog Devices 14/16-bit 8-channel ADC driver");