Lines Matching refs:adc
127 static int adc12138_mode_programming(struct adc12138 *adc, u8 mode, in adc12138_mode_programming() argument
131 .tx_buf = adc->tx_buf, in adc12138_mode_programming()
132 .rx_buf = adc->rx_buf, in adc12138_mode_programming()
138 if (adc->id != adc12138) in adc12138_mode_programming()
141 adc->tx_buf[0] = mode; in adc12138_mode_programming()
143 ret = spi_sync_transfer(adc->spi, &xfer, 1); in adc12138_mode_programming()
147 memcpy(rx_buf, adc->rx_buf, len); in adc12138_mode_programming()
152 static int adc12138_read_status(struct adc12138 *adc) in adc12138_read_status() argument
157 ret = adc12138_mode_programming(adc, ADC12138_MODE_READ_STATUS, in adc12138_read_status()
165 static int __adc12138_start_conv(struct adc12138 *adc, in __adc12138_start_conv() argument
174 return adc12138_mode_programming(adc, mode, data, len); in __adc12138_start_conv()
177 static int adc12138_start_conv(struct adc12138 *adc, in adc12138_start_conv() argument
182 return __adc12138_start_conv(adc, channel, &trash, 1); in adc12138_start_conv()
185 static int adc12138_start_and_read_conv(struct adc12138 *adc, in adc12138_start_and_read_conv() argument
189 return __adc12138_start_conv(adc, channel, data, 2); in adc12138_start_and_read_conv()
192 static int adc12138_read_conv_data(struct adc12138 *adc, __be16 *value) in adc12138_read_conv_data() argument
195 return adc12138_mode_programming(adc, ADC12138_MODE_READ_STATUS, in adc12138_read_conv_data()
199 static int adc12138_wait_eoc(struct adc12138 *adc, unsigned long timeout) in adc12138_wait_eoc() argument
201 if (!wait_for_completion_timeout(&adc->complete, timeout)) in adc12138_wait_eoc()
207 static int adc12138_adc_conversion(struct adc12138 *adc, in adc12138_adc_conversion() argument
213 reinit_completion(&adc->complete); in adc12138_adc_conversion()
215 ret = adc12138_start_conv(adc, channel); in adc12138_adc_conversion()
219 ret = adc12138_wait_eoc(adc, msecs_to_jiffies(100)); in adc12138_adc_conversion()
223 return adc12138_read_conv_data(adc, value); in adc12138_adc_conversion()
230 struct adc12138 *adc = iio_priv(iio); in adc12138_read_raw() local
236 mutex_lock(&adc->lock); in adc12138_read_raw()
237 ret = adc12138_adc_conversion(adc, channel, &data); in adc12138_read_raw()
238 mutex_unlock(&adc->lock); in adc12138_read_raw()
246 ret = regulator_get_voltage(adc->vref_p); in adc12138_read_raw()
251 if (!IS_ERR(adc->vref_n)) { in adc12138_read_raw()
252 ret = regulator_get_voltage(adc->vref_n); in adc12138_read_raw()
264 if (!IS_ERR(adc->vref_n)) { in adc12138_read_raw()
265 *value = regulator_get_voltage(adc->vref_n); in adc12138_read_raw()
285 static int adc12138_init(struct adc12138 *adc) in adc12138_init() argument
292 reinit_completion(&adc->complete); in adc12138_init()
294 ret = adc12138_mode_programming(adc, ADC12138_MODE_AUTO_CAL, &trash, 1); in adc12138_init()
299 status = adc12138_read_status(adc); in adc12138_init()
303 adc12138_wait_eoc(adc, msecs_to_jiffies(100)); in adc12138_init()
305 status = adc12138_read_status(adc); in adc12138_init()
307 dev_warn(&adc->spi->dev, in adc12138_init()
313 switch (adc->acquisition_time) { in adc12138_init()
330 return adc12138_mode_programming(adc, mode, &trash, 1); in adc12138_init()
337 struct adc12138 *adc = iio_priv(indio_dev); in adc12138_trigger_handler() local
343 mutex_lock(&adc->lock); in adc12138_trigger_handler()
350 reinit_completion(&adc->complete); in adc12138_trigger_handler()
352 ret = adc12138_start_and_read_conv(adc, scan_chan, in adc12138_trigger_handler()
353 i ? &adc->data[i - 1] : &trash); in adc12138_trigger_handler()
355 dev_warn(&adc->spi->dev, in adc12138_trigger_handler()
360 ret = adc12138_wait_eoc(adc, msecs_to_jiffies(100)); in adc12138_trigger_handler()
362 dev_warn(&adc->spi->dev, "wait eoc timeout\n"); in adc12138_trigger_handler()
370 ret = adc12138_read_conv_data(adc, &adc->data[i - 1]); in adc12138_trigger_handler()
372 dev_warn(&adc->spi->dev, in adc12138_trigger_handler()
378 iio_push_to_buffers_with_timestamp(indio_dev, adc->data, in adc12138_trigger_handler()
381 mutex_unlock(&adc->lock); in adc12138_trigger_handler()
391 struct adc12138 *adc = iio_priv(indio_dev); in adc12138_eoc_handler() local
393 complete(&adc->complete); in adc12138_eoc_handler()
401 struct adc12138 *adc; in adc12138_probe() local
404 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc)); in adc12138_probe()
408 adc = iio_priv(indio_dev); in adc12138_probe()
409 adc->spi = spi; in adc12138_probe()
410 adc->id = spi_get_device_id(spi)->driver_data; in adc12138_probe()
411 mutex_init(&adc->lock); in adc12138_probe()
412 init_completion(&adc->complete); in adc12138_probe()
418 switch (adc->id) { in adc12138_probe()
433 &adc->acquisition_time); in adc12138_probe()
435 adc->acquisition_time = 10; in adc12138_probe()
437 adc->cclk = devm_clk_get(&spi->dev, NULL); in adc12138_probe()
438 if (IS_ERR(adc->cclk)) in adc12138_probe()
439 return PTR_ERR(adc->cclk); in adc12138_probe()
441 adc->vref_p = devm_regulator_get(&spi->dev, "vref-p"); in adc12138_probe()
442 if (IS_ERR(adc->vref_p)) in adc12138_probe()
443 return PTR_ERR(adc->vref_p); in adc12138_probe()
445 adc->vref_n = devm_regulator_get_optional(&spi->dev, "vref-n"); in adc12138_probe()
446 if (IS_ERR(adc->vref_n)) { in adc12138_probe()
451 ret = PTR_ERR(adc->vref_n); in adc12138_probe()
461 ret = clk_prepare_enable(adc->cclk); in adc12138_probe()
465 ret = regulator_enable(adc->vref_p); in adc12138_probe()
469 if (!IS_ERR(adc->vref_n)) { in adc12138_probe()
470 ret = regulator_enable(adc->vref_n); in adc12138_probe()
475 ret = adc12138_init(adc); in adc12138_probe()
494 if (!IS_ERR(adc->vref_n)) in adc12138_probe()
495 regulator_disable(adc->vref_n); in adc12138_probe()
497 regulator_disable(adc->vref_p); in adc12138_probe()
499 clk_disable_unprepare(adc->cclk); in adc12138_probe()
507 struct adc12138 *adc = iio_priv(indio_dev); in adc12138_remove() local
511 if (!IS_ERR(adc->vref_n)) in adc12138_remove()
512 regulator_disable(adc->vref_n); in adc12138_remove()
513 regulator_disable(adc->vref_p); in adc12138_remove()
514 clk_disable_unprepare(adc->cclk); in adc12138_remove()