Lines Matching +full:vref +full:- +full:p +full:- +full:supply

1 // SPDX-License-Identifier: GPL-2.0
3 * Analog Devices AD7768-1 SPI ADC driver
156 struct regulator *vref; member
185 shift = 32 - (8 * len); in ad7768_spi_reg_read()
186 st->data.d8[0] = AD7768_RD_FLAG_MSK(addr); in ad7768_spi_reg_read()
188 ret = spi_write_then_read(st->spi, st->data.d8, 1, in ad7768_spi_reg_read()
189 &st->data.d32, len); in ad7768_spi_reg_read()
193 return (be32_to_cpu(st->data.d32) >> shift); in ad7768_spi_reg_read()
200 st->data.d8[0] = AD7768_WR_FLAG_MSK(addr); in ad7768_spi_reg_write()
201 st->data.d8[1] = val & 0xFF; in ad7768_spi_reg_write()
203 return spi_write(st->spi, st->data.d8, 2); in ad7768_spi_reg_write()
226 reinit_completion(&st->completion); in ad7768_scan_direct()
232 ret = wait_for_completion_timeout(&st->completion, in ad7768_scan_direct()
235 return -ETIMEDOUT; in ad7768_scan_direct()
241 * Any SPI configuration of the AD7768-1 can only be in ad7768_scan_direct()
259 mutex_lock(&st->lock); in ad7768_reg_access()
270 mutex_unlock(&st->lock); in ad7768_reg_access()
290 /* A sync-in pulse is required every time the filter dec rate changes */ in ad7768_set_dig_fil()
291 gpiod_set_value(st->gpio_sync_in, 1); in ad7768_set_dig_fil()
292 gpiod_set_value(st->gpio_sync_in, 0); in ad7768_set_dig_fil()
306 res = DIV_ROUND_CLOSEST(st->mclk_freq, freq); in ad7768_set_freq()
310 diff_new = abs(res - ad7768_clk_config[i].clk_div); in ad7768_set_freq()
331 st->samp_freq = DIV_ROUND_CLOSEST(st->mclk_freq, in ad7768_set_freq()
347 freq = DIV_ROUND_CLOSEST(st->mclk_freq, in ad7768_sampling_freq_avail()
349 len += scnprintf(buf + len, PAGE_SIZE - len, "%d ", freq); in ad7768_sampling_freq_avail()
352 buf[len - 1] = '\n'; in ad7768_sampling_freq_avail()
383 scale_uv = regulator_get_voltage(st->vref); in ad7768_read_raw()
388 *val2 = chan->scan_type.realbits; in ad7768_read_raw()
393 *val = st->samp_freq; in ad7768_read_raw()
398 return -EINVAL; in ad7768_read_raw()
411 return -EINVAL; in ad7768_write_raw()
420 return sprintf(label, "%s\n", st->labels[chan->channel]); in ad7768_read_label()
458 st->gpio_sync_in = devm_gpiod_get(&st->spi->dev, "adi,sync-in", in ad7768_setup()
460 if (IS_ERR(st->gpio_sync_in)) in ad7768_setup()
461 return PTR_ERR(st->gpio_sync_in); in ad7768_setup()
467 static irqreturn_t ad7768_trigger_handler(int irq, void *p) in ad7768_trigger_handler() argument
469 struct iio_poll_func *pf = p; in ad7768_trigger_handler()
470 struct iio_dev *indio_dev = pf->indio_dev; in ad7768_trigger_handler()
474 mutex_lock(&st->lock); in ad7768_trigger_handler()
476 ret = spi_read(st->spi, &st->data.scan.chan, 3); in ad7768_trigger_handler()
480 iio_push_to_buffers_with_timestamp(indio_dev, &st->data.scan, in ad7768_trigger_handler()
484 iio_trigger_notify_done(indio_dev->trig); in ad7768_trigger_handler()
485 mutex_unlock(&st->lock); in ad7768_trigger_handler()
496 iio_trigger_poll(st->trig); in ad7768_interrupt()
498 complete(&st->completion); in ad7768_interrupt()
510 * initial 8-bit write to query the ADC_DATA register. in ad7768_buffer_postenable()
539 regulator_disable(st->vref); in ad7768_regulator_disable()
546 struct device *device = indio_dev->dev.parent; in ad7768_set_channel_label()
560 st->labels[crt_ch] = label; in ad7768_set_channel_label()
572 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ad7768_probe()
574 return -ENOMEM; in ad7768_probe()
577 st->spi = spi; in ad7768_probe()
579 st->vref = devm_regulator_get(&spi->dev, "vref"); in ad7768_probe()
580 if (IS_ERR(st->vref)) in ad7768_probe()
581 return PTR_ERR(st->vref); in ad7768_probe()
583 ret = regulator_enable(st->vref); in ad7768_probe()
585 dev_err(&spi->dev, "Failed to enable specified vref supply\n"); in ad7768_probe()
589 ret = devm_add_action_or_reset(&spi->dev, ad7768_regulator_disable, st); in ad7768_probe()
593 st->mclk = devm_clk_get_enabled(&spi->dev, "mclk"); in ad7768_probe()
594 if (IS_ERR(st->mclk)) in ad7768_probe()
595 return PTR_ERR(st->mclk); in ad7768_probe()
597 st->mclk_freq = clk_get_rate(st->mclk); in ad7768_probe()
599 mutex_init(&st->lock); in ad7768_probe()
601 indio_dev->channels = ad7768_channels; in ad7768_probe()
602 indio_dev->num_channels = ARRAY_SIZE(ad7768_channels); in ad7768_probe()
603 indio_dev->name = spi_get_device_id(spi)->name; in ad7768_probe()
604 indio_dev->info = &ad7768_info; in ad7768_probe()
605 indio_dev->modes = INDIO_DIRECT_MODE; in ad7768_probe()
609 dev_err(&spi->dev, "AD7768 setup failed\n"); in ad7768_probe()
613 st->trig = devm_iio_trigger_alloc(&spi->dev, "%s-dev%d", in ad7768_probe()
614 indio_dev->name, in ad7768_probe()
616 if (!st->trig) in ad7768_probe()
617 return -ENOMEM; in ad7768_probe()
619 st->trig->ops = &ad7768_trigger_ops; in ad7768_probe()
620 iio_trigger_set_drvdata(st->trig, indio_dev); in ad7768_probe()
621 ret = devm_iio_trigger_register(&spi->dev, st->trig); in ad7768_probe()
625 indio_dev->trig = iio_trigger_get(st->trig); in ad7768_probe()
627 init_completion(&st->completion); in ad7768_probe()
633 ret = devm_request_irq(&spi->dev, spi->irq, in ad7768_probe()
636 indio_dev->name, indio_dev); in ad7768_probe()
640 ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, in ad7768_probe()
647 return devm_iio_device_register(&spi->dev, indio_dev); in ad7768_probe()
651 { "ad7768-1", 0 },
657 { .compatible = "adi,ad7768-1" },
664 .name = "ad7768-1",
673 MODULE_DESCRIPTION("Analog Devices AD7768-1 ADC driver");