Lines Matching +full:spi +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.
12 #include <linux/spi/spi.h>
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
119 struct spi_device *spi; member
120 struct clk *clk; member
127 static int ad9467_spi_read(struct spi_device *spi, unsigned int reg) in ad9467_spi_read() argument
135 ret = spi_write_then_read(spi, in ad9467_spi_read()
145 static int ad9467_spi_write(struct spi_device *spi, unsigned int reg, in ad9467_spi_write() argument
154 return spi_write(spi, buf, ARRAY_SIZE(buf)); in ad9467_spi_write()
161 struct spi_device *spi = st->spi; in ad9467_reg_access() local
165 ret = ad9467_spi_write(spi, reg, writeval); in ad9467_reg_access()
166 ad9467_spi_write(spi, AN877_ADC_REG_TRANSFER, in ad9467_reg_access()
171 ret = ad9467_spi_read(spi, reg); 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()
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()
362 static int ad9467_outputmode_set(struct spi_device *spi, unsigned int mode) in ad9467_outputmode_set() argument
366 ret = ad9467_spi_write(spi, AN877_ADC_REG_OUTPUT_MODE, mode); in ad9467_outputmode_set()
370 return ad9467_spi_write(spi, AN877_ADC_REG_TRANSFER, in ad9467_outputmode_set()
378 return ad9467_outputmode_set(st->spi, st->output_mode); in ad9467_preenable_setup()
381 static int ad9467_probe(struct spi_device *spi) in ad9467_probe() argument
389 info = of_device_get_match_data(&spi->dev); in ad9467_probe()
391 return -ENODEV; in ad9467_probe()
393 conv = devm_adi_axi_adc_conv_register(&spi->dev, sizeof(*st)); in ad9467_probe()
398 st->spi = spi; in ad9467_probe()
400 st->clk = devm_clk_get_enabled(&spi->dev, "adc-clk"); in ad9467_probe()
401 if (IS_ERR(st->clk)) in ad9467_probe()
402 return PTR_ERR(st->clk); in ad9467_probe()
404 st->pwrdown_gpio = devm_gpiod_get_optional(&spi->dev, "powerdown", in ad9467_probe()
406 if (IS_ERR(st->pwrdown_gpio)) in ad9467_probe()
407 return PTR_ERR(st->pwrdown_gpio); in ad9467_probe()
409 st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset", in ad9467_probe()
411 if (IS_ERR(st->reset_gpio)) in ad9467_probe()
412 return PTR_ERR(st->reset_gpio); in ad9467_probe()
414 if (st->reset_gpio) { in ad9467_probe()
416 ret = gpiod_direction_output(st->reset_gpio, 1); in ad9467_probe()
422 conv->chip_info = &info->axi_adc_info; in ad9467_probe()
424 id = ad9467_spi_read(spi, AN877_ADC_REG_CHIP_ID); in ad9467_probe()
425 if (id != conv->chip_info->id) { in ad9467_probe()
426 dev_err(&spi->dev, "Mismatch CHIP_ID, got 0x%X, expected 0x%X\n", in ad9467_probe()
427 id, conv->chip_info->id); in ad9467_probe()
428 return -ENODEV; in ad9467_probe()
431 conv->reg_access = ad9467_reg_access; in ad9467_probe()
432 conv->write_raw = ad9467_write_raw; in ad9467_probe()
433 conv->read_raw = ad9467_read_raw; in ad9467_probe()
434 conv->preenable_setup = ad9467_preenable_setup; in ad9467_probe()
436 st->output_mode = info->default_output_mode | in ad9467_probe()