Lines Matching +full:dual +full:- +full:mode
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 */
35 #define AD7887_PM_MODE4 3 /* standby mode */
44 * struct ad7887_chip_info - chip specifc information
48 * @dual_channels: channels specification in dual mode
49 * @num_dual_channels: number of channels in dual mode
86 switch (*indio_dev->active_scan_mask) { in ad7887_ring_preenable()
88 st->ring_msg = &st->msg[AD7887_CH0]; in ad7887_ring_preenable()
91 st->ring_msg = &st->msg[AD7887_CH1]; in ad7887_ring_preenable()
93 spi_sync(st->spi, st->ring_msg); in ad7887_ring_preenable()
96 st->ring_msg = &st->msg[AD7887_CH0_CH1]; in ad7887_ring_preenable()
108 return spi_sync(st->spi, &st->msg[AD7887_CH0]); in ad7887_ring_postdisable()
114 struct iio_dev *indio_dev = pf->indio_dev; in ad7887_trigger_handler()
118 b_sent = spi_sync(st->spi, st->ring_msg); in ad7887_trigger_handler()
122 iio_push_to_buffers_with_timestamp(indio_dev, st->data, in ad7887_trigger_handler()
125 iio_trigger_notify_done(indio_dev->trig); in ad7887_trigger_handler()
137 int ret = spi_sync(st->spi, &st->msg[ch]); in ad7887_scan_direct()
141 return (st->data[(ch * 2)] << 8) | st->data[(ch * 2) + 1]; in ad7887_scan_direct()
158 ret = ad7887_scan_direct(st, chan->address); in ad7887_read_raw()
163 *val = ret >> chan->scan_type.shift; in ad7887_read_raw()
164 *val &= GENMASK(chan->scan_type.realbits - 1, 0); in ad7887_read_raw()
167 if (st->reg) { in ad7887_read_raw()
168 *val = regulator_get_voltage(st->reg); in ad7887_read_raw()
173 *val = st->chip_info->int_vref_mv; in ad7887_read_raw()
176 *val2 = chan->scan_type.realbits; in ad7887_read_raw()
180 return -EINVAL; in ad7887_read_raw()
237 struct ad7887_platform_data *pdata = spi->dev.platform_data; in ad7887_probe()
240 uint8_t mode; in ad7887_probe() local
243 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in ad7887_probe()
245 return -ENOMEM; in ad7887_probe()
249 st->reg = devm_regulator_get_optional(&spi->dev, "vref"); in ad7887_probe()
250 if (IS_ERR(st->reg)) { in ad7887_probe()
251 if (PTR_ERR(st->reg) != -ENODEV) in ad7887_probe()
252 return PTR_ERR(st->reg); in ad7887_probe()
254 st->reg = NULL; in ad7887_probe()
257 if (st->reg) { in ad7887_probe()
258 ret = regulator_enable(st->reg); in ad7887_probe()
262 ret = devm_add_action_or_reset(&spi->dev, ad7887_reg_disable, st->reg); in ad7887_probe()
267 st->chip_info = in ad7887_probe()
268 &ad7887_chip_info_tbl[spi_get_device_id(spi)->driver_data]; in ad7887_probe()
270 st->spi = spi; in ad7887_probe()
272 indio_dev->name = spi_get_device_id(spi)->name; in ad7887_probe()
273 indio_dev->info = &ad7887_info; in ad7887_probe()
274 indio_dev->modes = INDIO_DIRECT_MODE; in ad7887_probe()
278 mode = AD7887_PM_MODE4; in ad7887_probe()
279 if (!st->reg) in ad7887_probe()
280 mode |= AD7887_REF_DIS; in ad7887_probe()
281 if (pdata && pdata->en_dual) in ad7887_probe()
282 mode |= AD7887_DUAL; in ad7887_probe()
284 st->tx_cmd_buf[0] = AD7887_CH_AIN0 | mode; in ad7887_probe()
286 st->xfer[0].rx_buf = &st->data[0]; in ad7887_probe()
287 st->xfer[0].tx_buf = &st->tx_cmd_buf[0]; in ad7887_probe()
288 st->xfer[0].len = 2; in ad7887_probe()
290 spi_message_init(&st->msg[AD7887_CH0]); in ad7887_probe()
291 spi_message_add_tail(&st->xfer[0], &st->msg[AD7887_CH0]); in ad7887_probe()
293 if (pdata && pdata->en_dual) { in ad7887_probe()
294 st->tx_cmd_buf[2] = AD7887_CH_AIN1 | mode; in ad7887_probe()
296 st->xfer[1].rx_buf = &st->data[0]; in ad7887_probe()
297 st->xfer[1].tx_buf = &st->tx_cmd_buf[2]; in ad7887_probe()
298 st->xfer[1].len = 2; in ad7887_probe()
300 st->xfer[2].rx_buf = &st->data[2]; in ad7887_probe()
301 st->xfer[2].tx_buf = &st->tx_cmd_buf[0]; in ad7887_probe()
302 st->xfer[2].len = 2; in ad7887_probe()
304 spi_message_init(&st->msg[AD7887_CH0_CH1]); in ad7887_probe()
305 spi_message_add_tail(&st->xfer[1], &st->msg[AD7887_CH0_CH1]); in ad7887_probe()
306 spi_message_add_tail(&st->xfer[2], &st->msg[AD7887_CH0_CH1]); in ad7887_probe()
308 st->xfer[3].rx_buf = &st->data[2]; in ad7887_probe()
309 st->xfer[3].tx_buf = &st->tx_cmd_buf[2]; in ad7887_probe()
310 st->xfer[3].len = 2; in ad7887_probe()
312 spi_message_init(&st->msg[AD7887_CH1]); in ad7887_probe()
313 spi_message_add_tail(&st->xfer[3], &st->msg[AD7887_CH1]); in ad7887_probe()
315 indio_dev->channels = st->chip_info->dual_channels; in ad7887_probe()
316 indio_dev->num_channels = st->chip_info->num_dual_channels; in ad7887_probe()
318 indio_dev->channels = st->chip_info->channels; in ad7887_probe()
319 indio_dev->num_channels = st->chip_info->num_channels; in ad7887_probe()
322 ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, in ad7887_probe()
328 return devm_iio_device_register(&spi->dev, indio_dev); in ad7887_probe()