Lines Matching +full:vref +full:- +full:mv
1 // SPDX-License-Identifier: GPL-2.0-only
3 * ADC12130/ADC12132/ADC12138 12-bit plus sign ADC driver
132 .tx_buf = adc->tx_buf, in adc12138_mode_programming()
133 .rx_buf = adc->rx_buf, in adc12138_mode_programming()
139 if (adc->id != adc12138) in adc12138_mode_programming()
142 adc->tx_buf[0] = mode; in adc12138_mode_programming()
144 ret = spi_sync_transfer(adc->spi, &xfer, 1); in adc12138_mode_programming()
148 memcpy(rx_buf, adc->rx_buf, len); in adc12138_mode_programming()
172 u8 mode = (ch_to_mux[channel->channel] << 4) | in __adc12138_start_conv()
173 (channel->differential ? 0 : 0x80); in __adc12138_start_conv()
202 if (!wait_for_completion_timeout(&adc->complete, timeout)) in adc12138_wait_eoc()
203 return -ETIMEDOUT; in adc12138_wait_eoc()
214 reinit_completion(&adc->complete); in adc12138_adc_conversion()
237 mutex_lock(&adc->lock); in adc12138_read_raw()
239 mutex_unlock(&adc->lock); in adc12138_read_raw()
243 *value = sign_extend32(be16_to_cpu(data) >> channel->scan_type.shift, in adc12138_read_raw()
244 channel->scan_type.realbits - 1); in adc12138_read_raw()
248 ret = regulator_get_voltage(adc->vref_p); in adc12138_read_raw()
253 if (!IS_ERR(adc->vref_n)) { in adc12138_read_raw()
254 ret = regulator_get_voltage(adc->vref_n); in adc12138_read_raw()
257 *value -= ret; in adc12138_read_raw()
260 /* convert regulator output voltage to mV */ in adc12138_read_raw()
262 *shift = channel->scan_type.realbits - 1; in adc12138_read_raw()
266 if (!IS_ERR(adc->vref_n)) { in adc12138_read_raw()
267 *value = regulator_get_voltage(adc->vref_n); in adc12138_read_raw()
274 /* convert regulator output voltage to mV */ in adc12138_read_raw()
280 return -EINVAL; in adc12138_read_raw()
294 reinit_completion(&adc->complete); in adc12138_init()
309 dev_warn(&adc->spi->dev, in adc12138_init()
312 return -EIO; in adc12138_init()
315 switch (adc->acquisition_time) { in adc12138_init()
329 return -EINVAL; in adc12138_init()
338 struct iio_dev *indio_dev = pf->indio_dev; in adc12138_trigger_handler()
345 mutex_lock(&adc->lock); in adc12138_trigger_handler()
349 &indio_dev->channels[scan_index]; in adc12138_trigger_handler()
351 reinit_completion(&adc->complete); in adc12138_trigger_handler()
354 i ? &adc->data[i - 1] : &trash); in adc12138_trigger_handler()
356 dev_warn(&adc->spi->dev, in adc12138_trigger_handler()
363 dev_warn(&adc->spi->dev, "wait eoc timeout\n"); in adc12138_trigger_handler()
371 ret = adc12138_read_conv_data(adc, &adc->data[i - 1]); in adc12138_trigger_handler()
373 dev_warn(&adc->spi->dev, in adc12138_trigger_handler()
379 iio_push_to_buffers_with_timestamp(indio_dev, adc->data, in adc12138_trigger_handler()
382 mutex_unlock(&adc->lock); in adc12138_trigger_handler()
384 iio_trigger_notify_done(indio_dev->trig); in adc12138_trigger_handler()
394 complete(&adc->complete); in adc12138_eoc_handler()
405 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc)); in adc12138_probe()
407 return -ENOMEM; in adc12138_probe()
410 adc->spi = spi; in adc12138_probe()
411 adc->id = spi_get_device_id(spi)->driver_data; in adc12138_probe()
412 mutex_init(&adc->lock); in adc12138_probe()
413 init_completion(&adc->complete); in adc12138_probe()
415 indio_dev->name = spi_get_device_id(spi)->name; in adc12138_probe()
416 indio_dev->info = &adc12138_info; in adc12138_probe()
417 indio_dev->modes = INDIO_DIRECT_MODE; in adc12138_probe()
419 switch (adc->id) { in adc12138_probe()
422 indio_dev->channels = adc12132_channels; in adc12138_probe()
423 indio_dev->num_channels = ARRAY_SIZE(adc12132_channels); in adc12138_probe()
426 indio_dev->channels = adc12138_channels; in adc12138_probe()
427 indio_dev->num_channels = ARRAY_SIZE(adc12138_channels); in adc12138_probe()
430 return -EINVAL; in adc12138_probe()
433 ret = device_property_read_u32(&spi->dev, "ti,acquisition-time", in adc12138_probe()
434 &adc->acquisition_time); in adc12138_probe()
436 adc->acquisition_time = 10; in adc12138_probe()
438 adc->cclk = devm_clk_get(&spi->dev, NULL); in adc12138_probe()
439 if (IS_ERR(adc->cclk)) in adc12138_probe()
440 return PTR_ERR(adc->cclk); in adc12138_probe()
442 adc->vref_p = devm_regulator_get(&spi->dev, "vref-p"); in adc12138_probe()
443 if (IS_ERR(adc->vref_p)) in adc12138_probe()
444 return PTR_ERR(adc->vref_p); in adc12138_probe()
446 adc->vref_n = devm_regulator_get_optional(&spi->dev, "vref-n"); in adc12138_probe()
447 if (IS_ERR(adc->vref_n)) { in adc12138_probe()
452 ret = PTR_ERR(adc->vref_n); in adc12138_probe()
453 if (ret != -ENODEV) in adc12138_probe()
457 ret = devm_request_irq(&spi->dev, spi->irq, adc12138_eoc_handler, in adc12138_probe()
458 IRQF_TRIGGER_RISING, indio_dev->name, indio_dev); in adc12138_probe()
462 ret = clk_prepare_enable(adc->cclk); in adc12138_probe()
466 ret = regulator_enable(adc->vref_p); in adc12138_probe()
470 if (!IS_ERR(adc->vref_n)) { in adc12138_probe()
471 ret = regulator_enable(adc->vref_n); in adc12138_probe()
495 if (!IS_ERR(adc->vref_n)) in adc12138_probe()
496 regulator_disable(adc->vref_n); in adc12138_probe()
498 regulator_disable(adc->vref_p); in adc12138_probe()
500 clk_disable_unprepare(adc->cclk); in adc12138_probe()
512 if (!IS_ERR(adc->vref_n)) in adc12138_remove()
513 regulator_disable(adc->vref_n); in adc12138_remove()
514 regulator_disable(adc->vref_p); in adc12138_remove()
515 clk_disable_unprepare(adc->cclk); in adc12138_remove()