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

1 // SPDX-License-Identifier: GPL-2.0-only
29 #define AD7298_CH(x) BIT(13 - (x)) /* channel select */
82 .scan_index = -1,
115 command = AD7298_WRITE | st->ext_ref; in ad7298_update_scan_mode()
121 st->tx_buf[0] = cpu_to_be16(command); in ad7298_update_scan_mode()
124 st->ring_xfer[0].tx_buf = &st->tx_buf[0]; in ad7298_update_scan_mode()
125 st->ring_xfer[0].len = 2; in ad7298_update_scan_mode()
126 st->ring_xfer[0].cs_change = 1; in ad7298_update_scan_mode()
127 st->ring_xfer[1].tx_buf = &st->tx_buf[1]; in ad7298_update_scan_mode()
128 st->ring_xfer[1].len = 2; in ad7298_update_scan_mode()
129 st->ring_xfer[1].cs_change = 1; in ad7298_update_scan_mode()
131 spi_message_init(&st->ring_msg); in ad7298_update_scan_mode()
132 spi_message_add_tail(&st->ring_xfer[0], &st->ring_msg); in ad7298_update_scan_mode()
133 spi_message_add_tail(&st->ring_xfer[1], &st->ring_msg); in ad7298_update_scan_mode()
136 st->ring_xfer[i + 2].rx_buf = &st->rx_buf[i]; in ad7298_update_scan_mode()
137 st->ring_xfer[i + 2].len = 2; in ad7298_update_scan_mode()
138 st->ring_xfer[i + 2].cs_change = 1; in ad7298_update_scan_mode()
139 spi_message_add_tail(&st->ring_xfer[i + 2], &st->ring_msg); in ad7298_update_scan_mode()
142 st->ring_xfer[i + 1].cs_change = 0; in ad7298_update_scan_mode()
147 static irqreturn_t ad7298_trigger_handler(int irq, void *p) in ad7298_trigger_handler() argument
149 struct iio_poll_func *pf = p; in ad7298_trigger_handler()
150 struct iio_dev *indio_dev = pf->indio_dev; in ad7298_trigger_handler()
154 b_sent = spi_sync(st->spi, &st->ring_msg); in ad7298_trigger_handler()
158 iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf, in ad7298_trigger_handler()
162 iio_trigger_notify_done(indio_dev->trig); in ad7298_trigger_handler()
170 st->tx_buf[0] = cpu_to_be16(AD7298_WRITE | st->ext_ref | in ad7298_scan_direct()
173 ret = spi_sync(st->spi, &st->scan_single_msg); in ad7298_scan_direct()
177 return be16_to_cpu(st->rx_buf[0]); in ad7298_scan_direct()
186 AD7298_TAVG | st->ext_ref); in ad7298_scan_temp()
188 ret = spi_write(st->spi, (u8 *)&buf, 2); in ad7298_scan_temp()
194 ret = spi_write(st->spi, (u8 *)&buf, 2); in ad7298_scan_temp()
200 ret = spi_read(st->spi, (u8 *)&buf, 2); in ad7298_scan_temp()
211 int vref; in ad7298_get_ref_voltage() local
213 if (st->reg) { in ad7298_get_ref_voltage()
214 vref = regulator_get_voltage(st->reg); in ad7298_get_ref_voltage()
215 if (vref < 0) in ad7298_get_ref_voltage()
216 return vref; in ad7298_get_ref_voltage()
218 return vref / 1000; in ad7298_get_ref_voltage()
239 if (chan->address == AD7298_CH_TEMP) in ad7298_read_raw()
242 ret = ad7298_scan_direct(st, chan->address); in ad7298_read_raw()
249 if (chan->address != AD7298_CH_TEMP) in ad7298_read_raw()
250 *val = ret & GENMASK(chan->scan_type.realbits - 1, 0); in ad7298_read_raw()
254 switch (chan->type) { in ad7298_read_raw()
257 *val2 = chan->scan_type.realbits; in ad7298_read_raw()
264 return -EINVAL; in ad7298_read_raw()
267 *val = 1093 - 2732500 / ad7298_get_ref_voltage(st); in ad7298_read_raw()
270 return -EINVAL; in ad7298_read_raw()
291 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ad7298_probe()
293 return -ENOMEM; in ad7298_probe()
297 st->reg = devm_regulator_get_optional(&spi->dev, "vref"); in ad7298_probe()
298 if (!IS_ERR(st->reg)) { in ad7298_probe()
299 st->ext_ref = AD7298_EXTREF; in ad7298_probe()
301 ret = PTR_ERR(st->reg); in ad7298_probe()
302 if (ret != -ENODEV) in ad7298_probe()
305 st->reg = NULL; in ad7298_probe()
308 if (st->reg) { in ad7298_probe()
309 ret = regulator_enable(st->reg); in ad7298_probe()
313 ret = devm_add_action_or_reset(&spi->dev, ad7298_reg_disable, in ad7298_probe()
314 st->reg); in ad7298_probe()
319 st->spi = spi; in ad7298_probe()
321 indio_dev->name = spi_get_device_id(spi)->name; in ad7298_probe()
322 indio_dev->modes = INDIO_DIRECT_MODE; in ad7298_probe()
323 indio_dev->channels = ad7298_channels; in ad7298_probe()
324 indio_dev->num_channels = ARRAY_SIZE(ad7298_channels); in ad7298_probe()
325 indio_dev->info = &ad7298_info; in ad7298_probe()
329 st->scan_single_xfer[0].tx_buf = &st->tx_buf[0]; in ad7298_probe()
330 st->scan_single_xfer[0].len = 2; in ad7298_probe()
331 st->scan_single_xfer[0].cs_change = 1; in ad7298_probe()
332 st->scan_single_xfer[1].tx_buf = &st->tx_buf[1]; in ad7298_probe()
333 st->scan_single_xfer[1].len = 2; in ad7298_probe()
334 st->scan_single_xfer[1].cs_change = 1; in ad7298_probe()
335 st->scan_single_xfer[2].rx_buf = &st->rx_buf[0]; in ad7298_probe()
336 st->scan_single_xfer[2].len = 2; in ad7298_probe()
338 spi_message_init(&st->scan_single_msg); in ad7298_probe()
339 spi_message_add_tail(&st->scan_single_xfer[0], &st->scan_single_msg); in ad7298_probe()
340 spi_message_add_tail(&st->scan_single_xfer[1], &st->scan_single_msg); in ad7298_probe()
341 spi_message_add_tail(&st->scan_single_xfer[2], &st->scan_single_msg); in ad7298_probe()
343 ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, NULL, in ad7298_probe()
348 return devm_iio_device_register(&spi->dev, indio_dev); in ad7298_probe()