• Home
  • Raw
  • Download

Lines Matching +full:adc +full:- +full:clk

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Analog Devices AD9467 SPI ADC driver
5 * Copyright 2012-2020 Analog Devices Inc.
22 #include <linux/clk.h>
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
120 struct clk *clk; member
161 struct spi_device *spi = st->spi; in ad9467_reg_access()
198 const struct adi_axi_adc_chip_info *info = conv->chip_info; in __ad9467_get_scale()
199 const struct iio_chan_spec *chan = &info->channels[0]; in __ad9467_get_scale()
202 tmp = (info->scale_table[index][0] * 1000000ULL) >> in __ad9467_get_scale()
203 chan->scan_type.realbits; in __ad9467_get_scale()
272 const struct adi_axi_adc_chip_info *info = conv->chip_info; in ad9467_get_scale()
277 vref_val = ad9467_spi_read(st->spi, AN877_ADC_REG_VREF); in ad9467_get_scale()
279 vref_val &= info1->vref_mask; in ad9467_get_scale()
281 for (i = 0; i < info->num_scales; i++) { in ad9467_get_scale()
282 if (vref_val == info->scale_table[i][1]) in ad9467_get_scale()
286 if (i == info->num_scales) in ad9467_get_scale()
287 return -ERANGE; in ad9467_get_scale()
296 const struct adi_axi_adc_chip_info *info = conv->chip_info; in ad9467_set_scale()
302 return -EINVAL; in ad9467_set_scale()
304 for (i = 0; i < info->num_scales; i++) { in ad9467_set_scale()
309 ad9467_spi_write(st->spi, AN877_ADC_REG_VREF, in ad9467_set_scale()
310 info->scale_table[i][1]); in ad9467_set_scale()
311 ad9467_spi_write(st->spi, AN877_ADC_REG_TRANSFER, in ad9467_set_scale()
316 return -EINVAL; in ad9467_set_scale()
329 *val = clk_get_rate(st->clk); in ad9467_read_raw()
333 return -EINVAL; in ad9467_read_raw()
341 const struct adi_axi_adc_chip_info *info = conv->chip_info; in ad9467_write_raw()
349 r_clk = clk_round_rate(st->clk, val); in ad9467_write_raw()
350 if (r_clk < 0 || r_clk > info->max_rate) { in ad9467_write_raw()
351 dev_warn(&st->spi->dev, in ad9467_write_raw()
352 "Error setting ADC sample rate %ld", r_clk); in ad9467_write_raw()
353 return -EINVAL; in ad9467_write_raw()
356 return clk_set_rate(st->clk, r_clk); in ad9467_write_raw()
358 return -EINVAL; in ad9467_write_raw()
378 return ad9467_outputmode_set(st->spi, st->output_mode); in ad9467_preenable_setup()
385 clk_disable_unprepare(st->clk); in ad9467_clk_disable()
396 info = of_device_get_match_data(&spi->dev); in ad9467_probe()
398 return -ENODEV; in ad9467_probe()
400 conv = devm_adi_axi_adc_conv_register(&spi->dev, sizeof(*st)); in ad9467_probe()
405 st->spi = spi; in ad9467_probe()
407 st->clk = devm_clk_get(&spi->dev, "adc-clk"); in ad9467_probe()
408 if (IS_ERR(st->clk)) in ad9467_probe()
409 return PTR_ERR(st->clk); in ad9467_probe()
411 ret = clk_prepare_enable(st->clk); in ad9467_probe()
415 ret = devm_add_action_or_reset(&spi->dev, ad9467_clk_disable, st); in ad9467_probe()
419 st->pwrdown_gpio = devm_gpiod_get_optional(&spi->dev, "powerdown", in ad9467_probe()
421 if (IS_ERR(st->pwrdown_gpio)) in ad9467_probe()
422 return PTR_ERR(st->pwrdown_gpio); in ad9467_probe()
424 st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset", in ad9467_probe()
426 if (IS_ERR(st->reset_gpio)) in ad9467_probe()
427 return PTR_ERR(st->reset_gpio); in ad9467_probe()
429 if (st->reset_gpio) { in ad9467_probe()
431 ret = gpiod_direction_output(st->reset_gpio, 1); in ad9467_probe()
439 conv->chip_info = &info->axi_adc_info; in ad9467_probe()
442 if (id != conv->chip_info->id) { in ad9467_probe()
443 dev_err(&spi->dev, "Mismatch CHIP_ID, got 0x%X, expected 0x%X\n", in ad9467_probe()
444 id, conv->chip_info->id); in ad9467_probe()
445 return -ENODEV; in ad9467_probe()
448 conv->reg_access = ad9467_reg_access; in ad9467_probe()
449 conv->write_raw = ad9467_write_raw; in ad9467_probe()
450 conv->read_raw = ad9467_read_raw; in ad9467_probe()
451 conv->preenable_setup = ad9467_preenable_setup; in ad9467_probe()
453 st->output_mode = info->default_output_mode | in ad9467_probe()
477 MODULE_DESCRIPTION("Analog Devices AD9467 ADC driver");