Lines Matching +full:1 +full:st

51 static int ad7266_wakeup(struct ad7266_state *st)  in ad7266_wakeup()  argument
54 return spi_read(st->spi, &st->data.sample[0], 2); in ad7266_wakeup()
57 static int ad7266_powerdown(struct ad7266_state *st) in ad7266_powerdown() argument
60 return spi_read(st->spi, &st->data.sample[0], 1); in ad7266_powerdown()
65 struct ad7266_state *st = iio_priv(indio_dev); in ad7266_preenable() local
66 return ad7266_wakeup(st); in ad7266_preenable()
71 struct ad7266_state *st = iio_priv(indio_dev); in ad7266_postdisable() local
72 return ad7266_powerdown(st); in ad7266_postdisable()
84 struct ad7266_state *st = iio_priv(indio_dev); in ad7266_trigger_handler() local
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()
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()
124 struct ad7266_state *st = iio_priv(indio_dev); in ad7266_update_scan_mode() local
127 ad7266_select_input(st, nr); in ad7266_update_scan_mode()
132 static int ad7266_read_single(struct ad7266_state *st, int *val, in ad7266_read_single() argument
137 ad7266_select_input(st, address); in ad7266_read_single()
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()
148 struct ad7266_state *st = iio_priv(indio_dev); in ad7266_read_raw() local
157 ret = ad7266_read_single(st, val, chan->address); 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()
177 if (st->range == AD7266_RANGE_2VREF && in ad7266_read_raw()
178 st->mode != AD7266_MODE_DIFF) in ad7266_read_raw()
189 .indexed = 1, \
208 AD7266_CHAN(1, (_sign)), \
225 AD7266_CHAN(1, (_sign)), \
236 .indexed = 1, \
238 .channel2 = (_chan) * 2 + 1, \
251 .differential = 1, \
257 AD7266_CHAN_DIFF(1, (_sign)), \
271 AD7266_CHAN_DIFF(1, (_sign)), \
312 (((_differential) << 2) | ((_signed) << 1) | ((_fixed) << 0))
320 [AD7266_CHAN_INFO_INDEX(0, 0, 1)] = {
325 [AD7266_CHAN_INFO_INDEX(0, 1, 0)] = {
330 [AD7266_CHAN_INFO_INDEX(0, 1, 1)] = {
335 [AD7266_CHAN_INFO_INDEX(1, 0, 0)] = {
340 [AD7266_CHAN_INFO_INDEX(1, 0, 1)] = {
345 [AD7266_CHAN_INFO_INDEX(1, 1, 0)] = {
350 [AD7266_CHAN_INFO_INDEX(1, 1, 1)] = {
359 struct ad7266_state *st = iio_priv(indio_dev); in ad7266_init_channels() local
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()
374 indio_dev->masklength = chan_info->num_channels - 1; in ad7266_init_channels()
390 struct ad7266_state *st; in ad7266_probe() local
394 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ad7266_probe()
398 st = iio_priv(indio_dev); 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()
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()