Lines Matching +full:vref +full:- +full:p
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()
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()
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()
335 static irqreturn_t adc12138_trigger_handler(int irq, void *p) in adc12138_trigger_handler() argument
337 struct iio_poll_func *pf = p; in adc12138_trigger_handler()
338 struct iio_dev *indio_dev = pf->indio_dev; in adc12138_trigger_handler()
345 mutex_lock(&adc->lock); in adc12138_trigger_handler()
347 for_each_set_bit(scan_index, indio_dev->active_scan_mask, in adc12138_trigger_handler()
348 indio_dev->masklength) { in adc12138_trigger_handler()
350 &indio_dev->channels[scan_index]; in adc12138_trigger_handler()
352 reinit_completion(&adc->complete); in adc12138_trigger_handler()
355 i ? &adc->data[i - 1] : &trash); in adc12138_trigger_handler()
357 dev_warn(&adc->spi->dev, in adc12138_trigger_handler()
364 dev_warn(&adc->spi->dev, "wait eoc timeout\n"); in adc12138_trigger_handler()
372 ret = adc12138_read_conv_data(adc, &adc->data[i - 1]); in adc12138_trigger_handler()
374 dev_warn(&adc->spi->dev, in adc12138_trigger_handler()
380 iio_push_to_buffers_with_timestamp(indio_dev, adc->data, in adc12138_trigger_handler()
383 mutex_unlock(&adc->lock); in adc12138_trigger_handler()
385 iio_trigger_notify_done(indio_dev->trig); in adc12138_trigger_handler()
390 static irqreturn_t adc12138_eoc_handler(int irq, void *p) in adc12138_eoc_handler() argument
392 struct iio_dev *indio_dev = p; in adc12138_eoc_handler()
395 complete(&adc->complete); in adc12138_eoc_handler()
406 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc)); in adc12138_probe()
408 return -ENOMEM; in adc12138_probe()
411 adc->spi = spi; in adc12138_probe()
412 adc->id = spi_get_device_id(spi)->driver_data; in adc12138_probe()
413 mutex_init(&adc->lock); in adc12138_probe()
414 init_completion(&adc->complete); in adc12138_probe()
416 indio_dev->name = spi_get_device_id(spi)->name; in adc12138_probe()
417 indio_dev->info = &adc12138_info; in adc12138_probe()
418 indio_dev->modes = INDIO_DIRECT_MODE; in adc12138_probe()
420 switch (adc->id) { in adc12138_probe()
423 indio_dev->channels = adc12132_channels; in adc12138_probe()
424 indio_dev->num_channels = ARRAY_SIZE(adc12132_channels); in adc12138_probe()
427 indio_dev->channels = adc12138_channels; in adc12138_probe()
428 indio_dev->num_channels = ARRAY_SIZE(adc12138_channels); in adc12138_probe()
431 return -EINVAL; in adc12138_probe()
434 ret = device_property_read_u32(&spi->dev, "ti,acquisition-time", in adc12138_probe()
435 &adc->acquisition_time); in adc12138_probe()
437 adc->acquisition_time = 10; in adc12138_probe()
439 adc->cclk = devm_clk_get(&spi->dev, NULL); in adc12138_probe()
440 if (IS_ERR(adc->cclk)) in adc12138_probe()
441 return PTR_ERR(adc->cclk); in adc12138_probe()
443 adc->vref_p = devm_regulator_get(&spi->dev, "vref-p"); in adc12138_probe()
444 if (IS_ERR(adc->vref_p)) in adc12138_probe()
445 return PTR_ERR(adc->vref_p); in adc12138_probe()
447 adc->vref_n = devm_regulator_get_optional(&spi->dev, "vref-n"); in adc12138_probe()
448 if (IS_ERR(adc->vref_n)) { in adc12138_probe()
453 ret = PTR_ERR(adc->vref_n); in adc12138_probe()
454 if (ret != -ENODEV) in adc12138_probe()
458 ret = devm_request_irq(&spi->dev, spi->irq, adc12138_eoc_handler, in adc12138_probe()
459 IRQF_TRIGGER_RISING, indio_dev->name, indio_dev); in adc12138_probe()
463 ret = clk_prepare_enable(adc->cclk); in adc12138_probe()
467 ret = regulator_enable(adc->vref_p); in adc12138_probe()
471 if (!IS_ERR(adc->vref_n)) { in adc12138_probe()
472 ret = regulator_enable(adc->vref_n); in adc12138_probe()
496 if (!IS_ERR(adc->vref_n)) in adc12138_probe()
497 regulator_disable(adc->vref_n); in adc12138_probe()
499 regulator_disable(adc->vref_p); in adc12138_probe()
501 clk_disable_unprepare(adc->cclk); in adc12138_probe()
513 if (!IS_ERR(adc->vref_n)) in adc12138_remove()
514 regulator_disable(adc->vref_n); in adc12138_remove()
515 regulator_disable(adc->vref_p); in adc12138_remove()
516 clk_disable_unprepare(adc->cclk); in adc12138_remove()