Lines Matching +full:spi +full:- +full:lsb +full:- +full:first
1 // SPDX-License-Identifier: GPL-2.0
3 * Analog Devices AD7768-1 SPI ADC driver
17 #include <linux/spi/spi.h>
155 struct spi_device *spi; member
184 shift = 32 - (8 * len); in ad7768_spi_reg_read()
185 st->data.d8[0] = AD7768_RD_FLAG_MSK(addr); in ad7768_spi_reg_read()
187 ret = spi_write_then_read(st->spi, st->data.d8, 1, in ad7768_spi_reg_read()
188 &st->data.d32, len); in ad7768_spi_reg_read()
192 return (be32_to_cpu(st->data.d32) >> shift); in ad7768_spi_reg_read()
199 st->data.d8[0] = AD7768_WR_FLAG_MSK(addr); in ad7768_spi_reg_write()
200 st->data.d8[1] = val & 0xFF; in ad7768_spi_reg_write()
202 return spi_write(st->spi, st->data.d8, 2); in ad7768_spi_reg_write()
225 reinit_completion(&st->completion); in ad7768_scan_direct()
231 ret = wait_for_completion_timeout(&st->completion, in ad7768_scan_direct()
234 return -ETIMEDOUT; in ad7768_scan_direct()
240 * Any SPI configuration of the AD7768-1 can only be in ad7768_scan_direct()
259 return -EBUSY; in ad7768_reg_access()
291 /* A sync-in pulse is required every time the filter dec rate changes */ in ad7768_set_dig_fil()
292 gpiod_set_value(st->gpio_sync_in, 1); in ad7768_set_dig_fil()
293 gpiod_set_value(st->gpio_sync_in, 0); in ad7768_set_dig_fil()
307 res = DIV_ROUND_CLOSEST(st->mclk_freq, freq); in ad7768_set_freq()
311 diff_new = abs(res - ad7768_clk_config[i].clk_div); in ad7768_set_freq()
332 st->samp_freq = DIV_ROUND_CLOSEST(st->mclk_freq, in ad7768_set_freq()
348 freq = DIV_ROUND_CLOSEST(st->mclk_freq, in ad7768_sampling_freq_avail()
350 len += scnprintf(buf + len, PAGE_SIZE - len, "%d ", freq); in ad7768_sampling_freq_avail()
353 buf[len - 1] = '\n'; in ad7768_sampling_freq_avail()
370 return -EBUSY; in ad7768_read_raw()
377 *val = sign_extend32(ret, chan->scan_type.realbits - 1); in ad7768_read_raw()
382 scale_uv = regulator_get_voltage(st->vref); in ad7768_read_raw()
387 *val2 = chan->scan_type.realbits; in ad7768_read_raw()
392 *val = st->samp_freq; in ad7768_read_raw()
397 return -EINVAL; in ad7768_read_raw()
410 return -EINVAL; in ad7768_write_raw()
419 return sprintf(label, "%s\n", st->labels[chan->channel]); in ad7768_read_label()
445 * a software reset. The bits must first be set to 11, and then in ad7768_setup()
457 st->gpio_sync_in = devm_gpiod_get(&st->spi->dev, "adi,sync-in", in ad7768_setup()
459 if (IS_ERR(st->gpio_sync_in)) in ad7768_setup()
460 return PTR_ERR(st->gpio_sync_in); in ad7768_setup()
469 struct iio_dev *indio_dev = pf->indio_dev; in ad7768_trigger_handler()
473 ret = spi_read(st->spi, &st->data.scan.chan, 3); in ad7768_trigger_handler()
477 iio_push_to_buffers_with_timestamp(indio_dev, &st->data.scan, in ad7768_trigger_handler()
481 iio_trigger_notify_done(indio_dev->trig); in ad7768_trigger_handler()
492 iio_trigger_poll(st->trig); in ad7768_interrupt()
494 complete(&st->completion); in ad7768_interrupt()
504 * Write a 1 to the LSB of the INTERFACE_FORMAT register to enter in ad7768_buffer_postenable()
506 * initial 8-bit write to query the ADC_DATA register. in ad7768_buffer_postenable()
535 regulator_disable(st->vref); in ad7768_regulator_disable()
542 struct device *device = indio_dev->dev.parent; in ad7768_set_channel_label()
556 st->labels[crt_ch] = label; in ad7768_set_channel_label()
562 static int ad7768_probe(struct spi_device *spi) in ad7768_probe() argument
568 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ad7768_probe()
570 return -ENOMEM; in ad7768_probe()
575 * clocked out of the controller and the spi clock is free running, in ad7768_probe()
581 if (spi->controller->mode_bits & SPI_MOSI_IDLE_HIGH) { in ad7768_probe()
582 spi->mode |= SPI_MOSI_IDLE_HIGH; in ad7768_probe()
583 ret = spi_setup(spi); in ad7768_probe()
588 st->spi = spi; in ad7768_probe()
590 st->vref = devm_regulator_get(&spi->dev, "vref"); in ad7768_probe()
591 if (IS_ERR(st->vref)) in ad7768_probe()
592 return PTR_ERR(st->vref); in ad7768_probe()
594 ret = regulator_enable(st->vref); in ad7768_probe()
596 dev_err(&spi->dev, "Failed to enable specified vref supply\n"); in ad7768_probe()
600 ret = devm_add_action_or_reset(&spi->dev, ad7768_regulator_disable, st); in ad7768_probe()
604 st->mclk = devm_clk_get_enabled(&spi->dev, "mclk"); in ad7768_probe()
605 if (IS_ERR(st->mclk)) in ad7768_probe()
606 return PTR_ERR(st->mclk); in ad7768_probe()
608 st->mclk_freq = clk_get_rate(st->mclk); in ad7768_probe()
610 indio_dev->channels = ad7768_channels; in ad7768_probe()
611 indio_dev->num_channels = ARRAY_SIZE(ad7768_channels); in ad7768_probe()
612 indio_dev->name = spi_get_device_id(spi)->name; in ad7768_probe()
613 indio_dev->info = &ad7768_info; in ad7768_probe()
614 indio_dev->modes = INDIO_DIRECT_MODE; in ad7768_probe()
618 dev_err(&spi->dev, "AD7768 setup failed\n"); in ad7768_probe()
622 st->trig = devm_iio_trigger_alloc(&spi->dev, "%s-dev%d", in ad7768_probe()
623 indio_dev->name, in ad7768_probe()
625 if (!st->trig) in ad7768_probe()
626 return -ENOMEM; in ad7768_probe()
628 st->trig->ops = &ad7768_trigger_ops; in ad7768_probe()
629 iio_trigger_set_drvdata(st->trig, indio_dev); in ad7768_probe()
630 ret = devm_iio_trigger_register(&spi->dev, st->trig); in ad7768_probe()
634 indio_dev->trig = iio_trigger_get(st->trig); in ad7768_probe()
636 init_completion(&st->completion); in ad7768_probe()
642 ret = devm_request_irq(&spi->dev, spi->irq, in ad7768_probe()
645 indio_dev->name, indio_dev); in ad7768_probe()
649 ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, in ad7768_probe()
656 return devm_iio_device_register(&spi->dev, indio_dev); in ad7768_probe()
660 { "ad7768-1", 0 },
663 MODULE_DEVICE_TABLE(spi, ad7768_id_table);
666 { .compatible = "adi,ad7768-1" },
673 .name = "ad7768-1",
682 MODULE_DESCRIPTION("Analog Devices AD7768-1 ADC driver");