Lines Matching refs:adc
137 static int ad7944_3wire_cs_mode_init_msg(struct device *dev, struct ad7944_adc *adc, in ad7944_3wire_cs_mode_init_msg() argument
140 unsigned int t_conv_ns = adc->always_turbo ? adc->timing_spec->turbo_conv_ns in ad7944_3wire_cs_mode_init_msg()
141 : adc->timing_spec->conv_ns; in ad7944_3wire_cs_mode_init_msg()
142 struct spi_transfer *xfers = adc->xfers; in ad7944_3wire_cs_mode_init_msg()
166 xfers[2].rx_buf = &adc->sample.raw; in ad7944_3wire_cs_mode_init_msg()
170 spi_message_init_with_transfers(&adc->msg, xfers, 3); in ad7944_3wire_cs_mode_init_msg()
172 return devm_spi_optimize_message(dev, adc->spi, &adc->msg); in ad7944_3wire_cs_mode_init_msg()
175 static int ad7944_4wire_mode_init_msg(struct device *dev, struct ad7944_adc *adc, in ad7944_4wire_mode_init_msg() argument
178 unsigned int t_conv_ns = adc->always_turbo ? adc->timing_spec->turbo_conv_ns in ad7944_4wire_mode_init_msg()
179 : adc->timing_spec->conv_ns; in ad7944_4wire_mode_init_msg()
180 struct spi_transfer *xfers = adc->xfers; in ad7944_4wire_mode_init_msg()
195 xfers[1].rx_buf = &adc->sample.raw; in ad7944_4wire_mode_init_msg()
199 spi_message_init_with_transfers(&adc->msg, xfers, 2); in ad7944_4wire_mode_init_msg()
201 return devm_spi_optimize_message(dev, adc->spi, &adc->msg); in ad7944_4wire_mode_init_msg()
204 static int ad7944_chain_mode_init_msg(struct device *dev, struct ad7944_adc *adc, in ad7944_chain_mode_init_msg() argument
208 struct spi_transfer *xfers = adc->xfers; in ad7944_chain_mode_init_msg()
214 if (adc->spi->mode & SPI_CPOL) in ad7944_chain_mode_init_msg()
222 if (!(adc->spi->mode & SPI_CS_HIGH)) in ad7944_chain_mode_init_msg()
227 xfers[0].delay.value = adc->timing_spec->conv_ns; in ad7944_chain_mode_init_msg()
230 xfers[1].rx_buf = adc->chain_mode_buf; in ad7944_chain_mode_init_msg()
234 spi_message_init_with_transfers(&adc->msg, xfers, 2); in ad7944_chain_mode_init_msg()
236 return devm_spi_optimize_message(dev, adc->spi, &adc->msg); in ad7944_chain_mode_init_msg()
250 static int ad7944_convert_and_acquire(struct ad7944_adc *adc) in ad7944_convert_and_acquire() argument
259 gpiod_set_value_cansleep(adc->cnv, 1); in ad7944_convert_and_acquire()
260 ret = spi_sync(adc->spi, &adc->msg); in ad7944_convert_and_acquire()
261 gpiod_set_value_cansleep(adc->cnv, 0); in ad7944_convert_and_acquire()
266 static int ad7944_single_conversion(struct ad7944_adc *adc, in ad7944_single_conversion() argument
272 ret = ad7944_convert_and_acquire(adc); in ad7944_single_conversion()
276 if (adc->spi_mode == AD7944_SPI_MODE_CHAIN) { in ad7944_single_conversion()
278 *val = ((u32 *)adc->chain_mode_buf)[chan->scan_index]; in ad7944_single_conversion()
280 *val = ((u16 *)adc->chain_mode_buf)[chan->scan_index]; in ad7944_single_conversion()
283 *val = adc->sample.raw.u32; in ad7944_single_conversion()
285 *val = adc->sample.raw.u16; in ad7944_single_conversion()
298 struct ad7944_adc *adc = iio_priv(indio_dev); in ad7944_read_raw() local
307 ret = ad7944_single_conversion(adc, chan, val); in ad7944_read_raw()
314 *val = adc->ref_mv; in ad7944_read_raw()
339 struct ad7944_adc *adc = iio_priv(indio_dev); in ad7944_trigger_handler() local
342 ret = ad7944_convert_and_acquire(adc); in ad7944_trigger_handler()
346 if (adc->spi_mode == AD7944_SPI_MODE_CHAIN) in ad7944_trigger_handler()
347 iio_push_to_buffers_with_timestamp(indio_dev, adc->chain_mode_buf, in ad7944_trigger_handler()
350 iio_push_to_buffers_with_timestamp(indio_dev, &adc->sample.raw, in ad7944_trigger_handler()
452 struct ad7944_adc *adc; in ad7944_probe() local
459 indio_dev = devm_iio_device_alloc(dev, sizeof(*adc)); in ad7944_probe()
463 adc = iio_priv(indio_dev); in ad7944_probe()
464 adc->spi = spi; in ad7944_probe()
470 adc->timing_spec = chip_info->timing_spec; in ad7944_probe()
477 adc->spi_mode = AD7944_SPI_MODE_DEFAULT; in ad7944_probe()
482 adc->spi_mode = ret; in ad7944_probe()
524 adc->ref_mv = ref_mv ?: AD7944_INTERNAL_REF_MV; in ad7944_probe()
526 adc->cnv = devm_gpiod_get_optional(dev, "cnv", GPIOD_OUT_LOW); in ad7944_probe()
527 if (IS_ERR(adc->cnv)) in ad7944_probe()
528 return dev_err_probe(dev, PTR_ERR(adc->cnv), in ad7944_probe()
531 if (!adc->cnv && adc->spi_mode == AD7944_SPI_MODE_DEFAULT) in ad7944_probe()
533 if (adc->cnv && adc->spi_mode != AD7944_SPI_MODE_DEFAULT) in ad7944_probe()
537 adc->turbo = devm_gpiod_get_optional(dev, "turbo", GPIOD_OUT_LOW); in ad7944_probe()
538 if (IS_ERR(adc->turbo)) in ad7944_probe()
539 return dev_err_probe(dev, PTR_ERR(adc->turbo), in ad7944_probe()
542 adc->always_turbo = device_property_present(dev, "adi,always-turbo"); in ad7944_probe()
544 if (adc->turbo && adc->always_turbo) in ad7944_probe()
548 if (adc->spi_mode == AD7944_SPI_MODE_CHAIN && adc->always_turbo) in ad7944_probe()
552 switch (adc->spi_mode) { in ad7944_probe()
554 ret = ad7944_4wire_mode_init_msg(dev, adc, &chip_info->channels[0]); in ad7944_probe()
560 ret = ad7944_3wire_cs_mode_init_msg(dev, adc, &chip_info->channels[0]); in ad7944_probe()
574 &adc->chain_mode_buf, in ad7944_probe()
579 ret = ad7944_chain_mode_init_msg(dev, adc, &chain_chan[0], in ad7944_probe()
591 if (adc->spi_mode == AD7944_SPI_MODE_CHAIN) { in ad7944_probe()