Lines Matching +full:trig +full:- +full:gpios

1 // SPDX-License-Identifier: GPL-2.0-only
37 struct gpio_desc *gpios[3]; member
54 return spi_read(st->spi, &st->data.sample[0], 2); in ad7266_wakeup()
60 return spi_read(st->spi, &st->data.sample[0], 1); in ad7266_powerdown()
83 struct iio_dev *indio_dev = pf->indio_dev; in ad7266_trigger_handler()
87 ret = spi_read(st->spi, st->data.sample, 4); in ad7266_trigger_handler()
89 iio_push_to_buffers_with_timestamp(indio_dev, &st->data, in ad7266_trigger_handler()
90 pf->timestamp); in ad7266_trigger_handler()
93 iio_trigger_notify_done(indio_dev->trig); in ad7266_trigger_handler()
102 if (st->fixed_addr) in ad7266_select_input()
105 switch (st->mode) { in ad7266_select_input()
118 gpiod_set_value(st->gpios[i], (bool)(nr & BIT(i))); in ad7266_select_input()
125 unsigned int nr = find_first_bit(scan_mask, indio_dev->masklength); in ad7266_update_scan_mode()
139 ret = spi_sync(st->spi, &st->single_msg); in ad7266_read_single()
140 *val = be16_to_cpu(st->data.sample[address % 2]); in ad7266_read_single()
157 ret = ad7266_read_single(st, val, chan->address); in ad7266_read_raw()
161 if (chan->scan_type.sign == 's') in ad7266_read_raw()
163 chan->scan_type.realbits - 1); in ad7266_read_raw()
167 scale_mv = st->vref_mv; in ad7266_read_raw()
168 if (st->mode == AD7266_MODE_DIFF) in ad7266_read_raw()
170 if (st->range == AD7266_RANGE_2VREF) in ad7266_read_raw()
174 *val2 = chan->scan_type.realbits; in ad7266_read_raw()
177 if (st->range == AD7266_RANGE_2VREF && in ad7266_read_raw()
178 st->mode != AD7266_MODE_DIFF) in ad7266_read_raw()
184 return -EINVAL; in ad7266_read_raw()
364 is_differential = st->mode != AD7266_MODE_SINGLE_ENDED; in ad7266_init_channels()
365 is_signed = (st->range == AD7266_RANGE_2VREF) | in ad7266_init_channels()
366 (st->mode == AD7266_MODE_DIFF); in ad7266_init_channels()
368 i = AD7266_CHAN_INFO_INDEX(is_differential, is_signed, st->fixed_addr); in ad7266_init_channels()
371 indio_dev->channels = chan_info->channels; in ad7266_init_channels()
372 indio_dev->num_channels = chan_info->num_channels; in ad7266_init_channels()
373 indio_dev->available_scan_masks = chan_info->scan_masks; in ad7266_init_channels()
374 indio_dev->masklength = chan_info->num_channels - 1; in ad7266_init_channels()
388 struct ad7266_platform_data *pdata = spi->dev.platform_data; in ad7266_probe()
394 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ad7266_probe()
396 return -ENOMEM; in ad7266_probe()
400 st->reg = devm_regulator_get_optional(&spi->dev, "vref"); in ad7266_probe()
401 if (!IS_ERR(st->reg)) { in ad7266_probe()
402 ret = regulator_enable(st->reg); in ad7266_probe()
406 ret = devm_add_action_or_reset(&spi->dev, ad7266_reg_disable, st->reg); in ad7266_probe()
410 ret = regulator_get_voltage(st->reg); in ad7266_probe()
414 st->vref_mv = ret / 1000; in ad7266_probe()
417 if (PTR_ERR(st->reg) != -ENODEV) in ad7266_probe()
418 return PTR_ERR(st->reg); in ad7266_probe()
420 st->vref_mv = 2500; in ad7266_probe()
424 st->fixed_addr = pdata->fixed_addr; in ad7266_probe()
425 st->mode = pdata->mode; in ad7266_probe()
426 st->range = pdata->range; in ad7266_probe()
428 if (!st->fixed_addr) { in ad7266_probe()
429 for (i = 0; i < ARRAY_SIZE(st->gpios); ++i) { in ad7266_probe()
430 st->gpios[i] = devm_gpiod_get(&spi->dev, in ad7266_probe()
433 if (IS_ERR(st->gpios[i])) { in ad7266_probe()
434 ret = PTR_ERR(st->gpios[i]); in ad7266_probe()
440 st->fixed_addr = true; in ad7266_probe()
441 st->range = AD7266_RANGE_VREF; in ad7266_probe()
442 st->mode = AD7266_MODE_DIFF; in ad7266_probe()
445 st->spi = spi; in ad7266_probe()
447 indio_dev->name = spi_get_device_id(spi)->name; in ad7266_probe()
448 indio_dev->modes = INDIO_DIRECT_MODE; in ad7266_probe()
449 indio_dev->info = &ad7266_info; in ad7266_probe()
454 st->single_xfer[0].rx_buf = &st->data.sample[0]; in ad7266_probe()
455 st->single_xfer[0].len = 2; in ad7266_probe()
456 st->single_xfer[0].cs_change = 1; in ad7266_probe()
458 st->single_xfer[1].rx_buf = st->data.sample; in ad7266_probe()
459 st->single_xfer[1].len = 4; in ad7266_probe()
460 st->single_xfer[1].cs_change = 1; in ad7266_probe()
462 st->single_xfer[2].tx_buf = &st->data.sample[0]; in ad7266_probe()
463 st->single_xfer[2].len = 1; in ad7266_probe()
465 spi_message_init(&st->single_msg); in ad7266_probe()
466 spi_message_add_tail(&st->single_xfer[0], &st->single_msg); in ad7266_probe()
467 spi_message_add_tail(&st->single_xfer[1], &st->single_msg); in ad7266_probe()
468 spi_message_add_tail(&st->single_xfer[2], &st->single_msg); in ad7266_probe()
470 ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, &iio_pollfunc_store_time, in ad7266_probe()
475 return devm_iio_device_register(&spi->dev, indio_dev); in ad7266_probe()
494 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");