Lines Matching +full:convert +full:- +full:channels
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright 2010-2011 Analog Devices Inc.
28 #define AD7887_REF_DIS BIT(5) /* on-chip reference disable */
29 #define AD7887_DUAL BIT(4) /* dual-channel mode */
30 #define AD7887_CH_AIN1 BIT(3) /* convert on channel 1, DUAL=1 */
31 #define AD7887_CH_AIN0 0 /* convert on channel 0, DUAL=0,1 */
44 * struct ad7887_chip_info - chip specifc information
46 * @channels: channels specification
47 * @num_channels: number of channels
48 * @dual_channels: channels specification in dual mode
49 * @num_dual_channels: number of channels in dual mode
53 const struct iio_chan_spec *channels; member
87 switch (*indio_dev->active_scan_mask) { in ad7887_ring_preenable()
89 st->ring_msg = &st->msg[AD7887_CH0]; in ad7887_ring_preenable()
92 st->ring_msg = &st->msg[AD7887_CH1]; in ad7887_ring_preenable()
94 spi_sync(st->spi, st->ring_msg); in ad7887_ring_preenable()
97 st->ring_msg = &st->msg[AD7887_CH0_CH1]; in ad7887_ring_preenable()
109 return spi_sync(st->spi, &st->msg[AD7887_CH0]); in ad7887_ring_postdisable()
121 struct iio_dev *indio_dev = pf->indio_dev; in ad7887_trigger_handler()
125 b_sent = spi_sync(st->spi, st->ring_msg); in ad7887_trigger_handler()
129 iio_push_to_buffers_with_timestamp(indio_dev, st->data, in ad7887_trigger_handler()
132 iio_trigger_notify_done(indio_dev->trig); in ad7887_trigger_handler()
144 int ret = spi_sync(st->spi, &st->msg[ch]); in ad7887_scan_direct()
148 return (st->data[(ch * 2)] << 8) | st->data[(ch * 2) + 1]; in ad7887_scan_direct()
165 ret = ad7887_scan_direct(st, chan->address); in ad7887_read_raw()
170 *val = ret >> chan->scan_type.shift; in ad7887_read_raw()
171 *val &= GENMASK(chan->scan_type.realbits - 1, 0); in ad7887_read_raw()
174 if (st->reg) { in ad7887_read_raw()
175 *val = regulator_get_voltage(st->reg); in ad7887_read_raw()
180 *val = st->chip_info->int_vref_mv; in ad7887_read_raw()
183 *val2 = chan->scan_type.realbits; in ad7887_read_raw()
187 return -EINVAL; in ad7887_read_raw()
223 .channels = ad7887_channels,
237 struct ad7887_platform_data *pdata = spi->dev.platform_data; in ad7887_probe()
243 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ad7887_probe()
245 return -ENOMEM; in ad7887_probe()
249 if (!pdata || !pdata->use_onchip_ref) { in ad7887_probe()
250 st->reg = devm_regulator_get(&spi->dev, "vref"); in ad7887_probe()
251 if (IS_ERR(st->reg)) in ad7887_probe()
252 return PTR_ERR(st->reg); in ad7887_probe()
254 ret = regulator_enable(st->reg); in ad7887_probe()
259 st->chip_info = in ad7887_probe()
260 &ad7887_chip_info_tbl[spi_get_device_id(spi)->driver_data]; in ad7887_probe()
263 st->spi = spi; in ad7887_probe()
265 indio_dev->name = spi_get_device_id(spi)->name; in ad7887_probe()
266 indio_dev->info = &ad7887_info; in ad7887_probe()
267 indio_dev->modes = INDIO_DIRECT_MODE; in ad7887_probe()
272 if (!pdata || !pdata->use_onchip_ref) in ad7887_probe()
274 if (pdata && pdata->en_dual) in ad7887_probe()
277 st->tx_cmd_buf[0] = AD7887_CH_AIN0 | mode; in ad7887_probe()
279 st->xfer[0].rx_buf = &st->data[0]; in ad7887_probe()
280 st->xfer[0].tx_buf = &st->tx_cmd_buf[0]; in ad7887_probe()
281 st->xfer[0].len = 2; in ad7887_probe()
283 spi_message_init(&st->msg[AD7887_CH0]); in ad7887_probe()
284 spi_message_add_tail(&st->xfer[0], &st->msg[AD7887_CH0]); in ad7887_probe()
286 if (pdata && pdata->en_dual) { in ad7887_probe()
287 st->tx_cmd_buf[2] = AD7887_CH_AIN1 | mode; in ad7887_probe()
289 st->xfer[1].rx_buf = &st->data[0]; in ad7887_probe()
290 st->xfer[1].tx_buf = &st->tx_cmd_buf[2]; in ad7887_probe()
291 st->xfer[1].len = 2; in ad7887_probe()
293 st->xfer[2].rx_buf = &st->data[2]; in ad7887_probe()
294 st->xfer[2].tx_buf = &st->tx_cmd_buf[0]; in ad7887_probe()
295 st->xfer[2].len = 2; in ad7887_probe()
297 spi_message_init(&st->msg[AD7887_CH0_CH1]); in ad7887_probe()
298 spi_message_add_tail(&st->xfer[1], &st->msg[AD7887_CH0_CH1]); in ad7887_probe()
299 spi_message_add_tail(&st->xfer[2], &st->msg[AD7887_CH0_CH1]); in ad7887_probe()
301 st->xfer[3].rx_buf = &st->data[2]; in ad7887_probe()
302 st->xfer[3].tx_buf = &st->tx_cmd_buf[2]; in ad7887_probe()
303 st->xfer[3].len = 2; in ad7887_probe()
305 spi_message_init(&st->msg[AD7887_CH1]); in ad7887_probe()
306 spi_message_add_tail(&st->xfer[3], &st->msg[AD7887_CH1]); in ad7887_probe()
308 indio_dev->channels = st->chip_info->dual_channels; in ad7887_probe()
309 indio_dev->num_channels = st->chip_info->num_dual_channels; in ad7887_probe()
311 indio_dev->channels = st->chip_info->channels; in ad7887_probe()
312 indio_dev->num_channels = st->chip_info->num_channels; in ad7887_probe()
328 if (st->reg) in ad7887_probe()
329 regulator_disable(st->reg); in ad7887_probe()
341 if (st->reg) in ad7887_remove()
342 regulator_disable(st->reg); in ad7887_remove()