Lines Matching +full:sample +full:- +full:gpios
1 // SPDX-License-Identifier: GPL-2.0-only
38 struct gpio_desc *gpios[3]; member
47 __be16 sample[2]; member
55 return spi_read(st->spi, &st->data.sample[0], 2); in ad7266_wakeup()
61 return spi_read(st->spi, &st->data.sample[0], 1); in ad7266_powerdown()
84 struct iio_dev *indio_dev = pf->indio_dev; in ad7266_trigger_handler()
88 ret = spi_read(st->spi, st->data.sample, 4); in ad7266_trigger_handler()
90 iio_push_to_buffers_with_timestamp(indio_dev, &st->data, in ad7266_trigger_handler()
91 pf->timestamp); in ad7266_trigger_handler()
94 iio_trigger_notify_done(indio_dev->trig); in ad7266_trigger_handler()
103 if (st->fixed_addr) in ad7266_select_input()
106 switch (st->mode) { in ad7266_select_input()
119 gpiod_set_value(st->gpios[i], (bool)(nr & BIT(i))); in ad7266_select_input()
141 ret = spi_sync(st->spi, &st->single_msg); in ad7266_read_single()
142 *val = be16_to_cpu(st->data.sample[address % 2]); in ad7266_read_single()
159 ret = ad7266_read_single(st, val, chan->address); in ad7266_read_raw()
165 if (chan->scan_type.sign == 's') in ad7266_read_raw()
167 chan->scan_type.realbits - 1); in ad7266_read_raw()
171 scale_mv = st->vref_mv; in ad7266_read_raw()
172 if (st->mode == AD7266_MODE_DIFF) in ad7266_read_raw()
174 if (st->range == AD7266_RANGE_2VREF) in ad7266_read_raw()
178 *val2 = chan->scan_type.realbits; in ad7266_read_raw()
181 if (st->range == AD7266_RANGE_2VREF && in ad7266_read_raw()
182 st->mode != AD7266_MODE_DIFF) in ad7266_read_raw()
188 return -EINVAL; in ad7266_read_raw()
368 is_differential = st->mode != AD7266_MODE_SINGLE_ENDED; in ad7266_init_channels()
369 is_signed = (st->range == AD7266_RANGE_2VREF) | in ad7266_init_channels()
370 (st->mode == AD7266_MODE_DIFF); in ad7266_init_channels()
372 i = AD7266_CHAN_INFO_INDEX(is_differential, is_signed, st->fixed_addr); in ad7266_init_channels()
375 indio_dev->channels = chan_info->channels; in ad7266_init_channels()
376 indio_dev->num_channels = chan_info->num_channels; in ad7266_init_channels()
377 indio_dev->available_scan_masks = chan_info->scan_masks; in ad7266_init_channels()
386 struct ad7266_platform_data *pdata = spi->dev.platform_data; in ad7266_probe()
392 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ad7266_probe()
394 return -ENOMEM; in ad7266_probe()
398 ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref"); in ad7266_probe()
399 if (ret < 0 && ret != -ENODEV) in ad7266_probe()
402 st->vref_mv = ret == -ENODEV ? AD7266_INTERNAL_REF_MV : ret / 1000; in ad7266_probe()
405 st->fixed_addr = pdata->fixed_addr; in ad7266_probe()
406 st->mode = pdata->mode; in ad7266_probe()
407 st->range = pdata->range; in ad7266_probe()
409 if (!st->fixed_addr) { in ad7266_probe()
410 for (i = 0; i < ARRAY_SIZE(st->gpios); ++i) { in ad7266_probe()
411 st->gpios[i] = devm_gpiod_get(&spi->dev, in ad7266_probe()
414 if (IS_ERR(st->gpios[i])) { in ad7266_probe()
415 ret = PTR_ERR(st->gpios[i]); in ad7266_probe()
421 st->fixed_addr = true; in ad7266_probe()
422 st->range = AD7266_RANGE_VREF; in ad7266_probe()
423 st->mode = AD7266_MODE_DIFF; in ad7266_probe()
426 st->spi = spi; in ad7266_probe()
428 indio_dev->name = spi_get_device_id(spi)->name; in ad7266_probe()
429 indio_dev->modes = INDIO_DIRECT_MODE; in ad7266_probe()
430 indio_dev->info = &ad7266_info; in ad7266_probe()
435 st->single_xfer[0].rx_buf = &st->data.sample[0]; in ad7266_probe()
436 st->single_xfer[0].len = 2; in ad7266_probe()
437 st->single_xfer[0].cs_change = 1; in ad7266_probe()
439 st->single_xfer[1].rx_buf = st->data.sample; in ad7266_probe()
440 st->single_xfer[1].len = 4; in ad7266_probe()
441 st->single_xfer[1].cs_change = 1; in ad7266_probe()
443 st->single_xfer[2].tx_buf = &st->data.sample[0]; in ad7266_probe()
444 st->single_xfer[2].len = 1; in ad7266_probe()
446 spi_message_init(&st->single_msg); in ad7266_probe()
447 spi_message_add_tail(&st->single_xfer[0], &st->single_msg); in ad7266_probe()
448 spi_message_add_tail(&st->single_xfer[1], &st->single_msg); in ad7266_probe()
449 spi_message_add_tail(&st->single_xfer[2], &st->single_msg); in ad7266_probe()
451 ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, &iio_pollfunc_store_time, in ad7266_probe()
456 return devm_iio_device_register(&spi->dev, indio_dev); in ad7266_probe()
475 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");