Lines Matching refs:adc
128 static int adc12138_mode_programming(struct adc12138 *adc, u8 mode, in adc12138_mode_programming() argument
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()
153 static int adc12138_read_status(struct adc12138 *adc) in adc12138_read_status() argument
158 ret = adc12138_mode_programming(adc, ADC12138_MODE_READ_STATUS, in adc12138_read_status()
166 static int __adc12138_start_conv(struct adc12138 *adc, in __adc12138_start_conv() argument
175 return adc12138_mode_programming(adc, mode, data, len); in __adc12138_start_conv()
178 static int adc12138_start_conv(struct adc12138 *adc, in adc12138_start_conv() argument
183 return __adc12138_start_conv(adc, channel, &trash, 1); in adc12138_start_conv()
186 static int adc12138_start_and_read_conv(struct adc12138 *adc, in adc12138_start_and_read_conv() argument
190 return __adc12138_start_conv(adc, channel, data, 2); in adc12138_start_and_read_conv()
193 static int adc12138_read_conv_data(struct adc12138 *adc, __be16 *value) in adc12138_read_conv_data() argument
196 return adc12138_mode_programming(adc, ADC12138_MODE_READ_STATUS, in adc12138_read_conv_data()
200 static int adc12138_wait_eoc(struct adc12138 *adc, unsigned long timeout) in adc12138_wait_eoc() argument
202 if (!wait_for_completion_timeout(&adc->complete, timeout)) in adc12138_wait_eoc()
208 static int adc12138_adc_conversion(struct adc12138 *adc, in adc12138_adc_conversion() argument
214 reinit_completion(&adc->complete); in adc12138_adc_conversion()
216 ret = adc12138_start_conv(adc, channel); in adc12138_adc_conversion()
220 ret = adc12138_wait_eoc(adc, msecs_to_jiffies(100)); in adc12138_adc_conversion()
224 return adc12138_read_conv_data(adc, value); in adc12138_adc_conversion()
231 struct adc12138 *adc = iio_priv(iio); in adc12138_read_raw() local
237 mutex_lock(&adc->lock); in adc12138_read_raw()
238 ret = adc12138_adc_conversion(adc, channel, &data); in adc12138_read_raw()
239 mutex_unlock(&adc->lock); 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()
266 if (!IS_ERR(adc->vref_n)) { in adc12138_read_raw()
267 *value = regulator_get_voltage(adc->vref_n); in adc12138_read_raw()
287 static int adc12138_init(struct adc12138 *adc) in adc12138_init() argument
294 reinit_completion(&adc->complete); in adc12138_init()
296 ret = adc12138_mode_programming(adc, ADC12138_MODE_AUTO_CAL, &trash, 1); in adc12138_init()
301 status = adc12138_read_status(adc); in adc12138_init()
305 adc12138_wait_eoc(adc, msecs_to_jiffies(100)); in adc12138_init()
307 status = adc12138_read_status(adc); in adc12138_init()
309 dev_warn(&adc->spi->dev, in adc12138_init()
315 switch (adc->acquisition_time) { in adc12138_init()
332 return adc12138_mode_programming(adc, mode, &trash, 1); in adc12138_init()
339 struct adc12138 *adc = iio_priv(indio_dev); in adc12138_trigger_handler() local
345 mutex_lock(&adc->lock); in adc12138_trigger_handler()
352 reinit_completion(&adc->complete); in adc12138_trigger_handler()
354 ret = adc12138_start_and_read_conv(adc, scan_chan, 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()
362 ret = adc12138_wait_eoc(adc, msecs_to_jiffies(100)); 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()
393 struct adc12138 *adc = iio_priv(indio_dev); in adc12138_eoc_handler() local
395 complete(&adc->complete); in adc12138_eoc_handler()
403 struct adc12138 *adc; in adc12138_probe() local
406 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc)); in adc12138_probe()
410 adc = iio_priv(indio_dev); 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()
420 switch (adc->id) { 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()
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()
477 ret = adc12138_init(adc); 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()
509 struct adc12138 *adc = iio_priv(indio_dev); in adc12138_remove() local
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()