Lines Matching refs:ad7949_adc
93 static int ad7949_spi_write_cfg(struct ad7949_adc_chip *ad7949_adc, u16 val, in ad7949_spi_write_cfg() argument
98 ad7949_adc->cfg = (val & mask) | (ad7949_adc->cfg & ~mask); in ad7949_spi_write_cfg()
100 switch (ad7949_adc->spi->bits_per_word) { in ad7949_spi_write_cfg()
102 ad7949_adc->buffer = ad7949_adc->cfg << 2; in ad7949_spi_write_cfg()
103 ret = spi_write(ad7949_adc->spi, &ad7949_adc->buffer, 2); in ad7949_spi_write_cfg()
106 ad7949_adc->buffer = ad7949_adc->cfg; in ad7949_spi_write_cfg()
107 ret = spi_write(ad7949_adc->spi, &ad7949_adc->buffer, 2); in ad7949_spi_write_cfg()
111 ad7949_adc->buf8b = cpu_to_be16(ad7949_adc->cfg << 2); in ad7949_spi_write_cfg()
112 ret = spi_write(ad7949_adc->spi, &ad7949_adc->buf8b, 2); in ad7949_spi_write_cfg()
115 dev_err(&ad7949_adc->indio_dev->dev, "unsupported BPW\n"); in ad7949_spi_write_cfg()
127 static int ad7949_spi_read_channel(struct ad7949_adc_chip *ad7949_adc, int *val, in ad7949_spi_read_channel() argument
140 ret = ad7949_spi_write_cfg(ad7949_adc, in ad7949_spi_read_channel()
145 if (channel == ad7949_adc->current_channel) in ad7949_spi_read_channel()
150 if (ad7949_adc->spi->bits_per_word == 8) in ad7949_spi_read_channel()
151 ret = spi_read(ad7949_adc->spi, &ad7949_adc->buf8b, 2); in ad7949_spi_read_channel()
153 ret = spi_read(ad7949_adc->spi, &ad7949_adc->buffer, 2); in ad7949_spi_read_channel()
164 ad7949_adc->current_channel = channel; in ad7949_spi_read_channel()
166 switch (ad7949_adc->spi->bits_per_word) { in ad7949_spi_read_channel()
168 *val = ad7949_adc->buffer; in ad7949_spi_read_channel()
170 *val >>= 16 - ad7949_adc->resolution; in ad7949_spi_read_channel()
173 *val = ad7949_adc->buffer & GENMASK(13, 0); in ad7949_spi_read_channel()
177 *val = be16_to_cpu(ad7949_adc->buf8b); in ad7949_spi_read_channel()
179 *val >>= 16 - ad7949_adc->resolution; in ad7949_spi_read_channel()
182 dev_err(&ad7949_adc->indio_dev->dev, "unsupported BPW\n"); in ad7949_spi_read_channel()
212 struct ad7949_adc_chip *ad7949_adc = iio_priv(indio_dev); in ad7949_spi_read_raw() local
220 mutex_lock(&ad7949_adc->lock); in ad7949_spi_read_raw()
221 ret = ad7949_spi_read_channel(ad7949_adc, val, chan->channel); in ad7949_spi_read_raw()
222 mutex_unlock(&ad7949_adc->lock); in ad7949_spi_read_raw()
230 switch (ad7949_adc->refsel) { in ad7949_spi_read_raw()
239 ret = regulator_get_voltage(ad7949_adc->vref); in ad7949_spi_read_raw()
248 *val2 = (1 << ad7949_adc->resolution) - 1; in ad7949_spi_read_raw()
259 struct ad7949_adc_chip *ad7949_adc = iio_priv(indio_dev); in ad7949_spi_reg_access() local
263 *readval = ad7949_adc->cfg; in ad7949_spi_reg_access()
265 ret = ad7949_spi_write_cfg(ad7949_adc, writeval, in ad7949_spi_reg_access()
276 static int ad7949_spi_init(struct ad7949_adc_chip *ad7949_adc) in ad7949_spi_init() argument
282 ad7949_adc->current_channel = 0; in ad7949_spi_init()
286 FIELD_PREP(AD7949_CFG_MASK_INX, ad7949_adc->current_channel) | in ad7949_spi_init()
288 FIELD_PREP(AD7949_CFG_MASK_REF, ad7949_adc->refsel) | in ad7949_spi_init()
292 ret = ad7949_spi_write_cfg(ad7949_adc, cfg, AD7949_CFG_MASK_TOTAL); in ad7949_spi_init()
298 ad7949_spi_read_channel(ad7949_adc, &val, ad7949_adc->current_channel); in ad7949_spi_init()
299 ad7949_spi_read_channel(ad7949_adc, &val, ad7949_adc->current_channel); in ad7949_spi_init()
314 struct ad7949_adc_chip *ad7949_adc; in ad7949_spi_probe() local
319 indio_dev = devm_iio_device_alloc(dev, sizeof(*ad7949_adc)); in ad7949_spi_probe()
331 ad7949_adc = iio_priv(indio_dev); in ad7949_spi_probe()
332 ad7949_adc->indio_dev = indio_dev; in ad7949_spi_probe()
333 ad7949_adc->spi = spi; in ad7949_spi_probe()
337 ad7949_adc->resolution = spec->resolution; in ad7949_spi_probe()
340 if (spi_ctrl_mask & SPI_BPW_MASK(ad7949_adc->resolution)) { in ad7949_spi_probe()
341 spi->bits_per_word = ad7949_adc->resolution; in ad7949_spi_probe()
357 ad7949_adc->refsel = AD7949_CFG_VAL_REF_INT_2500; in ad7949_spi_probe()
360 ad7949_adc->refsel = AD7949_CFG_VAL_REF_INT_4096; in ad7949_spi_probe()
368 ad7949_adc->vref = devm_regulator_get_optional(dev, "vrefin"); in ad7949_spi_probe()
369 if (IS_ERR(ad7949_adc->vref)) { in ad7949_spi_probe()
370 ret = PTR_ERR(ad7949_adc->vref); in ad7949_spi_probe()
374 ad7949_adc->vref = devm_regulator_get_optional(dev, "vref"); in ad7949_spi_probe()
375 if (IS_ERR(ad7949_adc->vref)) { in ad7949_spi_probe()
376 ret = PTR_ERR(ad7949_adc->vref); in ad7949_spi_probe()
380 ad7949_adc->refsel = AD7949_CFG_VAL_REF_EXT_TEMP; in ad7949_spi_probe()
383 ad7949_adc->refsel = AD7949_CFG_VAL_REF_EXT_TEMP_BUF; in ad7949_spi_probe()
386 if (ad7949_adc->refsel & AD7949_CFG_VAL_REF_EXTERNAL) { in ad7949_spi_probe()
387 ret = regulator_enable(ad7949_adc->vref); in ad7949_spi_probe()
394 ad7949_adc->vref); in ad7949_spi_probe()
399 mutex_init(&ad7949_adc->lock); in ad7949_spi_probe()
401 ret = ad7949_spi_init(ad7949_adc); in ad7949_spi_probe()