Lines Matching +full:no +full:- +full:ref +full:- +full:high +full:- +full:z

1 // SPDX-License-Identifier: GPL-2.0+
34 #define AD4000_CFG_HIGHZ BIT(2) /* High impedance mode */
56 .shift = _storage_bits - _real_bits, \
78 .shift = _storage_bits - _real_bits, \
98 /* maps adi,sdi-pin property value to enum */
101 [AD4000_SDI_VIO] = "high",
254 if (chan->scan_type.sign == 's') in ad4000_fill_scale_tbl()
255 scale_bits = chan->scan_type.realbits - 1; in ad4000_fill_scale_tbl()
257 scale_bits = chan->scan_type.realbits; in ad4000_fill_scale_tbl()
265 val = mult_frac(st->vref_mv, MICRO, st->gain_milli); in ad4000_fill_scale_tbl()
272 st->scale_tbl[0][0] = tmp0; /* Integer part */ in ad4000_fill_scale_tbl()
273 st->scale_tbl[0][1] = abs(tmp1); /* Fractional part */ in ad4000_fill_scale_tbl()
276 st->scale_tbl[1][0] = tmp0; in ad4000_fill_scale_tbl()
279 if (chan->differential) in ad4000_fill_scale_tbl()
280 st->scale_tbl[1][1] = DIV_ROUND_CLOSEST(abs(tmp1) * 4, 5); in ad4000_fill_scale_tbl()
282 st->scale_tbl[1][1] = DIV_ROUND_CLOSEST(abs(tmp1) * 9, 10); in ad4000_fill_scale_tbl()
287 st->tx_buf[0] = AD4000_WRITE_COMMAND; in ad4000_write_reg()
288 st->tx_buf[1] = val; in ad4000_write_reg()
289 return spi_write(st->spi, st->tx_buf, ARRAY_SIZE(st->tx_buf)); in ad4000_write_reg()
295 .tx_buf = st->tx_buf, in ad4000_read_reg()
296 .rx_buf = st->rx_buf, in ad4000_read_reg()
301 st->tx_buf[0] = AD4000_READ_COMMAND; in ad4000_read_reg()
302 ret = spi_sync_transfer(st->spi, &t, 1); in ad4000_read_reg()
306 *val = st->rx_buf[1]; in ad4000_read_reg()
315 * In 4-wire mode, the CNV line is held high for the entire conversion in ad4000_convert_and_acquire()
318 * gpiod_set_value_cansleep() has no effect. in ad4000_convert_and_acquire()
320 gpiod_set_value_cansleep(st->cnv_gpio, 1); in ad4000_convert_and_acquire()
321 ret = spi_sync(st->spi, &st->msg); in ad4000_convert_and_acquire()
322 gpiod_set_value_cansleep(st->cnv_gpio, 0); in ad4000_convert_and_acquire()
338 if (chan->scan_type.storagebits > 16) in ad4000_single_conversion()
339 sample = be32_to_cpu(st->scan.data.sample_buf32); in ad4000_single_conversion()
341 sample = be16_to_cpu(st->scan.data.sample_buf16); in ad4000_single_conversion()
343 sample >>= chan->scan_type.shift; in ad4000_single_conversion()
345 if (chan->scan_type.sign == 's') in ad4000_single_conversion()
346 *val = sign_extend32(sample, chan->scan_type.realbits - 1); in ad4000_single_conversion()
359 iio_device_claim_direct_scoped(return -EBUSY, indio_dev) in ad4000_read_raw()
363 *val = st->scale_tbl[st->span_comp][0]; in ad4000_read_raw()
364 *val2 = st->scale_tbl[st->span_comp][1]; in ad4000_read_raw()
368 if (st->span_comp) in ad4000_read_raw()
369 *val = mult_frac(st->vref_mv, 1, 10); in ad4000_read_raw()
373 return -EINVAL; in ad4000_read_raw()
386 *vals = (int *)st->scale_tbl; in ad4000_read_avail()
391 return -EINVAL; in ad4000_read_avail()
417 iio_device_claim_direct_scoped(return -EBUSY, indio_dev) { in ad4000_write_raw()
418 guard(mutex)(&st->lock); in ad4000_write_raw()
424 span_comp_en = val2 == st->scale_tbl[1][1]; in ad4000_write_raw()
432 st->span_comp = span_comp_en; in ad4000_write_raw()
437 return -EINVAL; in ad4000_write_raw()
444 struct iio_dev *indio_dev = pf->indio_dev; in ad4000_trigger_handler()
452 iio_push_to_buffers_with_timestamp(indio_dev, &st->scan, pf->timestamp); in ad4000_trigger_handler()
455 iio_trigger_notify_done(indio_dev->trig); in ad4000_trigger_handler()
472 * in "3-wire" mode, selected when the adi,sdi-pin device tree property is
473 * absent or set to "high". In this connection mode, the ADC SDI pin is
490 struct spi_transfer *xfers = st->xfers; in ad4000_prepare_3wire_mode_message()
496 xfers[1].rx_buf = &st->scan.data; in ad4000_prepare_3wire_mode_message()
497 xfers[1].len = BITS_TO_BYTES(chan->scan_type.storagebits); in ad4000_prepare_3wire_mode_message()
501 spi_message_init_with_transfers(&st->msg, st->xfers, 2); in ad4000_prepare_3wire_mode_message()
503 return devm_spi_optimize_message(&st->spi->dev, st->spi, &st->msg); in ad4000_prepare_3wire_mode_message()
508 * in "4-wire" mode, selected when the adi,sdi-pin device tree property is
517 struct spi_transfer *xfers = st->xfers; in ad4000_prepare_4wire_mode_message()
520 * Dummy transfer to cause enough delay between CNV going high and SDI in ad4000_prepare_4wire_mode_message()
527 xfers[1].rx_buf = &st->scan.data; in ad4000_prepare_4wire_mode_message()
528 xfers[1].len = BITS_TO_BYTES(chan->scan_type.storagebits); in ad4000_prepare_4wire_mode_message()
530 spi_message_init_with_transfers(&st->msg, st->xfers, 2); in ad4000_prepare_4wire_mode_message()
532 return devm_spi_optimize_message(&st->spi->dev, st->spi, &st->msg); in ad4000_prepare_4wire_mode_message()
539 if (device_property_present(&st->spi->dev, "adi,high-z-input")) in ad4000_config()
548 struct device *dev = &spi->dev; in ad4000_probe()
555 return -ENOMEM; in ad4000_probe()
559 return -EINVAL; in ad4000_probe()
562 st->spi = spi; in ad4000_probe()
569 ret = devm_regulator_get_enable_read_voltage(dev, "ref"); in ad4000_probe()
572 "Failed to get ref regulator reference\n"); in ad4000_probe()
573 st->vref_mv = ret / 1000; in ad4000_probe()
575 st->cnv_gpio = devm_gpiod_get_optional(dev, "cnv", GPIOD_OUT_HIGH); in ad4000_probe()
576 if (IS_ERR(st->cnv_gpio)) in ad4000_probe()
577 return dev_err_probe(dev, PTR_ERR(st->cnv_gpio), in ad4000_probe()
580 ret = device_property_match_property_string(dev, "adi,sdi-pin", in ad4000_probe()
583 if (ret < 0 && ret != -EINVAL) in ad4000_probe()
585 "getting adi,sdi-pin property failed\n"); in ad4000_probe()
588 st->sdi_pin = ret == -EINVAL ? AD4000_SDI_MOSI : ret; in ad4000_probe()
589 switch (st->sdi_pin) { in ad4000_probe()
591 indio_dev->info = &ad4000_reg_access_info; in ad4000_probe()
592 indio_dev->channels = &chip->reg_access_chan_spec; in ad4000_probe()
595 * In "3-wire mode", the ADC SDI line must be kept high when in ad4000_probe()
597 * Request the SPI controller to make MOSI idle high. in ad4000_probe()
599 spi->mode |= SPI_MOSI_IDLE_HIGH; in ad4000_probe()
604 ret = ad4000_prepare_3wire_mode_message(st, indio_dev->channels); in ad4000_probe()
614 indio_dev->info = &ad4000_info; in ad4000_probe()
615 indio_dev->channels = &chip->chan_spec; in ad4000_probe()
616 ret = ad4000_prepare_3wire_mode_message(st, indio_dev->channels); in ad4000_probe()
622 indio_dev->info = &ad4000_info; in ad4000_probe()
623 indio_dev->channels = &chip->chan_spec; in ad4000_probe()
624 ret = ad4000_prepare_4wire_mode_message(st, indio_dev->channels); in ad4000_probe()
630 return dev_err_probe(dev, -EPROTONOSUPPORT, in ad4000_probe()
634 return dev_err_probe(dev, -EINVAL, "Unrecognized connection mode\n"); in ad4000_probe()
637 indio_dev->name = chip->dev_name; in ad4000_probe()
638 indio_dev->num_channels = 1; in ad4000_probe()
640 devm_mutex_init(dev, &st->lock); in ad4000_probe()
642 st->gain_milli = 1000; in ad4000_probe()
643 if (chip->has_hardware_gain) { in ad4000_probe()
644 ret = device_property_read_u16(dev, "adi,gain-milli", in ad4000_probe()
645 &st->gain_milli); in ad4000_probe()
648 gain_idx = find_closest(st->gain_milli, ad4000_gains, in ad4000_probe()
650 st->gain_milli = ad4000_gains[gain_idx]; in ad4000_probe()
657 ad4000_fill_scale_tbl(st, indio_dev->channels); in ad4000_probe()