Lines Matching +full:axi +full:- +full:adc
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Analog Devices AD9467 SPI ADC driver
5 * Copyright 2012-2020 Analog Devices Inc.
24 #include <linux/iio/adc/adi-axi-adc.h>
27 * ADI High-Speed ADC common spi interface registers
28 * See Application-Note AN-877:
29 * https://www.analog.com/media/en/technical-documentation/application-notes/AN-877.pdf
80 * Analog Devices AD9265 16-Bit, 125/105/80 MSPS ADC
88 * Analog Devices AD9434 12-Bit, 370/500 MSPS ADC
96 * Analog Devices AD9467 16-Bit, 200/250 MSPS ADC
161 struct spi_device *spi = st->spi; in ad9467_reg_access()
199 const struct adi_axi_adc_chip_info *info = conv->chip_info; in __ad9467_get_scale()
200 const struct iio_chan_spec *chan = &info->channels[0]; in __ad9467_get_scale()
203 tmp = (info->scale_table[index][0] * 1000000ULL) >> in __ad9467_get_scale()
204 chan->scan_type.realbits; in __ad9467_get_scale()
274 const struct adi_axi_adc_chip_info *info = conv->chip_info; in ad9467_get_scale()
280 ret = ad9467_spi_read(st->spi, AN877_ADC_REG_VREF); in ad9467_get_scale()
284 vref_val = ret & info1->vref_mask; in ad9467_get_scale()
286 for (i = 0; i < info->num_scales; i++) { in ad9467_get_scale()
287 if (vref_val == info->scale_table[i][1]) in ad9467_get_scale()
291 if (i == info->num_scales) in ad9467_get_scale()
292 return -ERANGE; in ad9467_get_scale()
301 const struct adi_axi_adc_chip_info *info = conv->chip_info; in ad9467_set_scale()
308 return -EINVAL; in ad9467_set_scale()
310 for (i = 0; i < info->num_scales; i++) { in ad9467_set_scale()
315 ret = ad9467_spi_write(st->spi, AN877_ADC_REG_VREF, in ad9467_set_scale()
316 info->scale_table[i][1]); in ad9467_set_scale()
320 return ad9467_spi_write(st->spi, AN877_ADC_REG_TRANSFER, in ad9467_set_scale()
324 return -EINVAL; in ad9467_set_scale()
337 *val = clk_get_rate(st->clk); in ad9467_read_raw()
341 return -EINVAL; in ad9467_read_raw()
349 const struct adi_axi_adc_chip_info *info = conv->chip_info; in ad9467_write_raw()
357 r_clk = clk_round_rate(st->clk, val); in ad9467_write_raw()
358 if (r_clk < 0 || r_clk > info->max_rate) { in ad9467_write_raw()
359 dev_warn(&st->spi->dev, in ad9467_write_raw()
360 "Error setting ADC sample rate %ld", r_clk); in ad9467_write_raw()
361 return -EINVAL; in ad9467_write_raw()
364 return clk_set_rate(st->clk, r_clk); in ad9467_write_raw()
366 return -EINVAL; in ad9467_write_raw()
375 const struct adi_axi_adc_chip_info *info = conv->chip_info; in ad9467_read_avail()
380 *vals = (const int *)st->scales; in ad9467_read_avail()
383 *length = info->num_scales * 2; in ad9467_read_avail()
386 return -EINVAL; in ad9467_read_avail()
404 const struct adi_axi_adc_chip_info *info = conv->chip_info; in ad9467_scale_fill()
408 st->scales = devm_kmalloc_array(&st->spi->dev, info->num_scales, in ad9467_scale_fill()
409 sizeof(*st->scales), GFP_KERNEL); in ad9467_scale_fill()
410 if (!st->scales) in ad9467_scale_fill()
411 return -ENOMEM; in ad9467_scale_fill()
413 for (i = 0; i < info->num_scales; i++) { in ad9467_scale_fill()
415 st->scales[i][0] = val1; in ad9467_scale_fill()
416 st->scales[i][1] = val2; in ad9467_scale_fill()
426 return ad9467_outputmode_set(st->spi, st->output_mode); in ad9467_preenable_setup()
452 info = of_device_get_match_data(&spi->dev); in ad9467_probe()
454 return -ENODEV; in ad9467_probe()
456 conv = devm_adi_axi_adc_conv_register(&spi->dev, sizeof(*st)); in ad9467_probe()
461 st->spi = spi; in ad9467_probe()
463 st->clk = devm_clk_get_enabled(&spi->dev, "adc-clk"); in ad9467_probe()
464 if (IS_ERR(st->clk)) in ad9467_probe()
465 return PTR_ERR(st->clk); in ad9467_probe()
467 st->pwrdown_gpio = devm_gpiod_get_optional(&spi->dev, "powerdown", in ad9467_probe()
469 if (IS_ERR(st->pwrdown_gpio)) in ad9467_probe()
470 return PTR_ERR(st->pwrdown_gpio); in ad9467_probe()
472 ret = ad9467_reset(&spi->dev); in ad9467_probe()
478 conv->chip_info = &info->axi_adc_info; in ad9467_probe()
485 if (id != conv->chip_info->id) { in ad9467_probe()
486 dev_err(&spi->dev, "Mismatch CHIP_ID, got 0x%X, expected 0x%X\n", in ad9467_probe()
487 id, conv->chip_info->id); in ad9467_probe()
488 return -ENODEV; in ad9467_probe()
491 conv->reg_access = ad9467_reg_access; in ad9467_probe()
492 conv->write_raw = ad9467_write_raw; in ad9467_probe()
493 conv->read_raw = ad9467_read_raw; in ad9467_probe()
494 conv->read_avail = ad9467_read_avail; in ad9467_probe()
495 conv->preenable_setup = ad9467_preenable_setup; in ad9467_probe()
497 st->output_mode = info->default_output_mode | in ad9467_probe()
521 MODULE_DESCRIPTION("Analog Devices AD9467 ADC driver");