Lines Matching +full:nr +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()
98 static void ad7266_select_input(struct ad7266_state *st, unsigned int nr) in ad7266_select_input() argument
102 if (st->fixed_addr) in ad7266_select_input()
105 switch (st->mode) { in ad7266_select_input()
107 nr >>= 1; in ad7266_select_input()
110 nr |= 1; in ad7266_select_input()
113 nr &= ~1; 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() local
127 ad7266_select_input(st, nr); 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()
166 scale_mv = st->vref_mv; in ad7266_read_raw()
167 if (st->mode == AD7266_MODE_DIFF) in ad7266_read_raw()
169 if (st->range == AD7266_RANGE_2VREF) in ad7266_read_raw()
173 *val2 = chan->scan_type.realbits; in ad7266_read_raw()
176 if (st->range == AD7266_RANGE_2VREF && in ad7266_read_raw()
177 st->mode != AD7266_MODE_DIFF) in ad7266_read_raw()
183 return -EINVAL; in ad7266_read_raw()
363 is_differential = st->mode != AD7266_MODE_SINGLE_ENDED; in ad7266_init_channels()
364 is_signed = (st->range == AD7266_RANGE_2VREF) | in ad7266_init_channels()
365 (st->mode == AD7266_MODE_DIFF); in ad7266_init_channels()
367 i = AD7266_CHAN_INFO_INDEX(is_differential, is_signed, st->fixed_addr); in ad7266_init_channels()
370 indio_dev->channels = chan_info->channels; in ad7266_init_channels()
371 indio_dev->num_channels = chan_info->num_channels; in ad7266_init_channels()
372 indio_dev->available_scan_masks = chan_info->scan_masks; in ad7266_init_channels()
373 indio_dev->masklength = chan_info->num_channels - 1; in ad7266_init_channels()
382 struct ad7266_platform_data *pdata = spi->dev.platform_data; in ad7266_probe()
388 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ad7266_probe()
390 return -ENOMEM; in ad7266_probe()
394 st->reg = devm_regulator_get_optional(&spi->dev, "vref"); in ad7266_probe()
395 if (!IS_ERR(st->reg)) { in ad7266_probe()
396 ret = regulator_enable(st->reg); in ad7266_probe()
400 ret = regulator_get_voltage(st->reg); in ad7266_probe()
404 st->vref_mv = ret / 1000; in ad7266_probe()
407 if (PTR_ERR(st->reg) != -ENODEV) in ad7266_probe()
408 return PTR_ERR(st->reg); in ad7266_probe()
410 st->vref_mv = 2500; in ad7266_probe()
414 st->fixed_addr = pdata->fixed_addr; in ad7266_probe()
415 st->mode = pdata->mode; in ad7266_probe()
416 st->range = pdata->range; in ad7266_probe()
418 if (!st->fixed_addr) { in ad7266_probe()
419 for (i = 0; i < ARRAY_SIZE(st->gpios); ++i) { in ad7266_probe()
420 st->gpios[i] = devm_gpiod_get(&spi->dev, in ad7266_probe()
423 if (IS_ERR(st->gpios[i])) { in ad7266_probe()
424 ret = PTR_ERR(st->gpios[i]); in ad7266_probe()
430 st->fixed_addr = true; in ad7266_probe()
431 st->range = AD7266_RANGE_VREF; in ad7266_probe()
432 st->mode = AD7266_MODE_DIFF; in ad7266_probe()
436 st->spi = spi; in ad7266_probe()
438 indio_dev->name = spi_get_device_id(spi)->name; in ad7266_probe()
439 indio_dev->modes = INDIO_DIRECT_MODE; in ad7266_probe()
440 indio_dev->info = &ad7266_info; in ad7266_probe()
445 st->single_xfer[0].rx_buf = &st->data.sample[0]; in ad7266_probe()
446 st->single_xfer[0].len = 2; in ad7266_probe()
447 st->single_xfer[0].cs_change = 1; in ad7266_probe()
449 st->single_xfer[1].rx_buf = st->data.sample; in ad7266_probe()
450 st->single_xfer[1].len = 4; in ad7266_probe()
451 st->single_xfer[1].cs_change = 1; in ad7266_probe()
453 st->single_xfer[2].tx_buf = &st->data.sample[0]; in ad7266_probe()
454 st->single_xfer[2].len = 1; in ad7266_probe()
456 spi_message_init(&st->single_msg); in ad7266_probe()
457 spi_message_add_tail(&st->single_xfer[0], &st->single_msg); in ad7266_probe()
458 spi_message_add_tail(&st->single_xfer[1], &st->single_msg); in ad7266_probe()
459 spi_message_add_tail(&st->single_xfer[2], &st->single_msg); in ad7266_probe()
475 if (!IS_ERR(st->reg)) in ad7266_probe()
476 regulator_disable(st->reg); in ad7266_probe()
488 if (!IS_ERR(st->reg)) in ad7266_remove()
489 regulator_disable(st->reg); in ad7266_remove()
511 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");