Lines Matching +full:vref +full:- +full:p

1 // SPDX-License-Identifier: GPL-2.0-only
47 #define EXTRACT(val, dec, bits) (((val) >> (dec)) & ((1 << (bits)) - 1))
97 .shift = 12 - (bits), \
172 for_each_set_bit(i, active_scan_mask, indio_dev->num_channels - 1) { in ad7923_update_scan_mode()
175 st->settings; in ad7923_update_scan_mode()
177 st->tx_buf[len++] = cpu_to_be16(cmd); in ad7923_update_scan_mode()
180 st->ring_xfer[0].tx_buf = &st->tx_buf[0]; in ad7923_update_scan_mode()
181 st->ring_xfer[0].len = len; in ad7923_update_scan_mode()
182 st->ring_xfer[0].cs_change = 1; in ad7923_update_scan_mode()
184 spi_message_init(&st->ring_msg); in ad7923_update_scan_mode()
185 spi_message_add_tail(&st->ring_xfer[0], &st->ring_msg); in ad7923_update_scan_mode()
188 st->ring_xfer[i + 1].rx_buf = &st->rx_buf[i]; in ad7923_update_scan_mode()
189 st->ring_xfer[i + 1].len = 2; in ad7923_update_scan_mode()
190 st->ring_xfer[i + 1].cs_change = 1; in ad7923_update_scan_mode()
191 spi_message_add_tail(&st->ring_xfer[i + 1], &st->ring_msg); in ad7923_update_scan_mode()
194 st->ring_xfer[i + 1].cs_change = 0; in ad7923_update_scan_mode()
199 static irqreturn_t ad7923_trigger_handler(int irq, void *p) in ad7923_trigger_handler() argument
201 struct iio_poll_func *pf = p; in ad7923_trigger_handler()
202 struct iio_dev *indio_dev = pf->indio_dev; in ad7923_trigger_handler()
206 b_sent = spi_sync(st->spi, &st->ring_msg); in ad7923_trigger_handler()
210 iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf, in ad7923_trigger_handler()
214 iio_trigger_notify_done(indio_dev->trig); in ad7923_trigger_handler()
225 st->settings; in ad7923_scan_direct()
227 st->tx_buf[0] = cpu_to_be16(cmd); in ad7923_scan_direct()
229 ret = spi_sync(st->spi, &st->scan_single_msg); in ad7923_scan_direct()
233 return be16_to_cpu(st->rx_buf[0]); in ad7923_scan_direct()
238 int vref; in ad7923_get_range() local
240 vref = regulator_get_voltage(st->reg); in ad7923_get_range()
241 if (vref < 0) in ad7923_get_range()
242 return vref; in ad7923_get_range()
244 vref /= 1000; in ad7923_get_range()
246 if (!(st->settings & AD7923_RANGE)) in ad7923_get_range()
247 vref *= 2; in ad7923_get_range()
249 return vref; in ad7923_get_range()
266 ret = ad7923_scan_direct(st, chan->address); in ad7923_read_raw()
272 if (chan->address == EXTRACT(ret, 12, 4)) in ad7923_read_raw()
273 *val = EXTRACT(ret, chan->scan_type.shift, in ad7923_read_raw()
274 chan->scan_type.realbits); in ad7923_read_raw()
276 return -EIO; in ad7923_read_raw()
284 *val2 = chan->scan_type.realbits; in ad7923_read_raw()
287 return -EINVAL; in ad7923_read_raw()
299 regulator_disable(st->reg); in ad7923_regulator_disable()
310 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ad7923_probe()
312 return -ENOMEM; in ad7923_probe()
316 if (device_property_read_bool(&spi->dev, "adi,range-double")) in ad7923_probe()
319 st->spi = spi; in ad7923_probe()
320 st->settings = AD7923_CODING | ad7923_range | in ad7923_probe()
323 info = &ad7923_chip_info[spi_get_device_id(spi)->driver_data]; in ad7923_probe()
325 indio_dev->name = spi_get_device_id(spi)->name; in ad7923_probe()
326 indio_dev->modes = INDIO_DIRECT_MODE; in ad7923_probe()
327 indio_dev->channels = info->channels; in ad7923_probe()
328 indio_dev->num_channels = info->num_channels; in ad7923_probe()
329 indio_dev->info = &ad7923_info; in ad7923_probe()
333 st->scan_single_xfer[0].tx_buf = &st->tx_buf[0]; in ad7923_probe()
334 st->scan_single_xfer[0].len = 2; in ad7923_probe()
335 st->scan_single_xfer[0].cs_change = 1; in ad7923_probe()
336 st->scan_single_xfer[1].rx_buf = &st->rx_buf[0]; in ad7923_probe()
337 st->scan_single_xfer[1].len = 2; in ad7923_probe()
339 spi_message_init(&st->scan_single_msg); in ad7923_probe()
340 spi_message_add_tail(&st->scan_single_xfer[0], &st->scan_single_msg); in ad7923_probe()
341 spi_message_add_tail(&st->scan_single_xfer[1], &st->scan_single_msg); in ad7923_probe()
343 st->reg = devm_regulator_get(&spi->dev, "refin"); in ad7923_probe()
344 if (IS_ERR(st->reg)) in ad7923_probe()
345 return PTR_ERR(st->reg); in ad7923_probe()
347 ret = regulator_enable(st->reg); in ad7923_probe()
351 ret = devm_add_action_or_reset(&spi->dev, ad7923_regulator_disable, st); in ad7923_probe()
355 ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, NULL, in ad7923_probe()
360 return devm_iio_device_register(&spi->dev, indio_dev); in ad7923_probe()
398 MODULE_AUTHOR("Patrick Vasseur <patrick.vasseur@c-s.fr>");